teapot-coding-agent 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,14 +9,17 @@ import { spawn } from "node:child_process";
9
9
  import { promises as fs } from "node:fs";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { parseSchedule } from "../scheduler/cron.js";
12
+ import { SUB_PERSONAS } from "../master.js";
13
+ import { ConfigPatchSchema, formatZodError } from "../config-schema.js";
12
14
  import path from "node:path";
13
15
  import { bus } from "../bus.js";
14
16
  import { readEvents } from "../log/events.js";
15
17
  export function buildApp(master) {
16
18
  const app = new Hono();
17
- // Optional bearer auth for LAN exposure — set TEAPOT_API_TOKEN to enable.
18
- // WebSocket handshakes can't send headers, so they accept ?token= instead.
19
- const apiToken = process.env.TEAPOT_API_TOKEN || "";
19
+ // Optional bearer auth for LAN exposure — TEAPOT_API_TOKEN env wins, else
20
+ // the config's `password` field. Static files stay public; only /api/* is
21
+ // gated. WebSocket handshakes can't send headers → they accept ?token=.
22
+ const apiToken = process.env.TEAPOT_API_TOKEN || master.config.password || "";
20
23
  if (apiToken)
21
24
  app.use("/api/*", async (c, next) => {
22
25
  const h = c.req.header("authorization");
@@ -221,9 +224,14 @@ export function buildApp(master) {
221
224
  ]));
222
225
  return c.json({
223
226
  configPath: master.configPath,
227
+ needsSetup: !master.configFileExists,
224
228
  providers: mask(master.config.providers),
225
229
  defaultProvider: master.config.defaultProvider,
226
230
  progressIntervalMs: master.config.progressIntervalMs,
231
+ progressMinChars: master.config.progressMinChars,
232
+ contextTokenBudget: master.config.contextTokenBudget,
233
+ contextWindowTokens: master.config.contextWindowTokens,
234
+ maxSpawnDepth: master.config.maxSpawnDepth,
227
235
  tasks: master.config.tasks,
228
236
  agents: master.config.agents.map((a) => ({ id: a.id, workspace: a.workspace, provider: a.provider, model: a.model })),
229
237
  });
@@ -232,26 +240,33 @@ export function buildApp(master) {
232
240
  const body = await c.req.json().catch(() => null);
233
241
  if (!body)
234
242
  return c.json({ error: "invalid JSON" }, 400);
243
+ // schema gate first: reject malformed edits with actionable messages
244
+ const parsed = ConfigPatchSchema.safeParse(body);
245
+ if (!parsed.success)
246
+ return c.json({ error: formatZodError(parsed.error) }, 400);
247
+ const patch = parsed.data;
235
248
  try {
236
- // validate schedules before applying anything
237
- for (const t of body.tasks ?? [])
249
+ for (const t of patch.tasks ?? [])
238
250
  parseSchedule(t.schedule);
239
251
  // keep masked keys intact: "•••1234" means "unchanged"
240
252
  const prev = master.config.providers ?? {};
241
253
  const providers = {};
242
- for (const [name, p] of Object.entries(body.providers ?? {})) {
254
+ for (const [name, p] of Object.entries(patch.providers ?? {})) {
243
255
  const masked = !p.apiKey || p.apiKey.startsWith("•••");
244
256
  providers[name] = {
245
- baseUrl: p.baseUrl,
257
+ baseUrl: p.baseUrl ?? "",
246
258
  apiKey: masked ? prev[name]?.apiKey : p.apiKey,
247
259
  ...(p.model ? { model: p.model } : {}),
248
260
  };
249
261
  }
250
262
  master.updateConfig({
251
263
  providers,
252
- defaultProvider: body.defaultProvider,
253
- progressIntervalMs: body.progressIntervalMs,
254
- tasks: body.tasks,
264
+ defaultProvider: patch.defaultProvider,
265
+ progressIntervalMs: patch.progressIntervalMs,
266
+ progressMinChars: patch.progressMinChars,
267
+ contextTokenBudget: patch.contextTokenBudget,
268
+ maxSpawnDepth: patch.maxSpawnDepth,
269
+ tasks: patch.tasks,
255
270
  });
256
271
  return c.json({ ok: true });
257
272
  }
@@ -315,8 +330,22 @@ export function buildApp(master) {
315
330
  });
316
331
  if (!res.ok)
317
332
  return c.json({ error: `upstream ${res.status}` }, 502);
333
+ // OpenRouter-style entries carry context_length + per-token pricing —
334
+ // surface them so the model switcher can show what each model offers
318
335
  const j = (await res.json());
319
- const models = (j.data ?? []).map((m) => m.id).filter((x) => !!x).sort();
336
+ const models = (j.data ?? [])
337
+ .map((m) => ({
338
+ id: typeof m.id === "string" ? m.id : "",
339
+ contextLength: typeof m.context_length === "number" ? m.context_length : undefined,
340
+ pricing: m.pricing && (m.pricing.prompt !== undefined || m.pricing.completion !== undefined)
341
+ ? {
342
+ prompt: Number(m.pricing.prompt ?? 0),
343
+ completion: Number(m.pricing.completion ?? 0),
344
+ }
345
+ : undefined,
346
+ }))
347
+ .filter((m) => m.id)
348
+ .sort((a, b) => a.id.localeCompare(b.id));
320
349
  return c.json({ provider: provName, models });
321
350
  }
322
351
  catch (err) {
@@ -361,6 +390,75 @@ export function buildApp(master) {
361
390
  return c.json({ error: "text or status required" }, 400);
362
391
  return c.json({ ok: true });
363
392
  });
393
+ // force a context compaction pass (slash command /compact)
394
+ app.post("/api/agents/:id/compact", async (c) => {
395
+ const a = master.agents.get(c.req.param("id"));
396
+ if (!a)
397
+ return c.json({ error: "not found" }, 404);
398
+ try {
399
+ return c.json({ ok: true, ...(await a.compactNow()) });
400
+ }
401
+ catch (err) {
402
+ return c.json({ error: err.message }, 409);
403
+ }
404
+ });
405
+ // first-run wizard bootstrap — only while no config file exists
406
+ app.post("/api/setup", async (c) => {
407
+ if (master.configFileExists)
408
+ return c.json({ error: "setup already completed" }, 409);
409
+ const body = await c.req
410
+ .json()
411
+ .catch(() => null);
412
+ if (!body?.baseUrl || !body.model)
413
+ return c.json({ error: "baseUrl and model are required" }, 400);
414
+ try {
415
+ return c.json(await master.applySetup(body));
416
+ }
417
+ catch (err) {
418
+ return c.json({ error: err.message }, 400);
419
+ }
420
+ });
421
+ // default sub-agent personas for @mentions and spawn_agent
422
+ app.get("/api/personas", (c) => c.json({
423
+ personas: Object.entries(SUB_PERSONAS).map(([key, p]) => ({ key, label: p.label, directive: p.directive })),
424
+ }));
425
+ // spawn a sub-agent from the UI (@mention flow / manual)
426
+ app.post("/api/agents/:id/spawn", async (c) => {
427
+ const a = master.agents.get(c.req.param("id"));
428
+ if (!a)
429
+ return c.json({ error: "not found" }, 404);
430
+ const body = await c.req
431
+ .json()
432
+ .catch(() => null);
433
+ if (!body?.task?.trim())
434
+ return c.json({ error: "task required" }, 400);
435
+ try {
436
+ const r = await master.spawnChildFor(a, {
437
+ task: body.task,
438
+ context: body.context === "fork" ? "fork" : "none",
439
+ name: body.name,
440
+ persona: body.persona,
441
+ });
442
+ return c.json({ ok: true, ...r });
443
+ }
444
+ catch (err) {
445
+ return c.json({ error: err.message }, 400);
446
+ }
447
+ });
448
+ // bulk-stop a parent's sub-agents (descendants included by default)
449
+ app.post("/api/agents/:id/stop-children", async (c) => {
450
+ const a = master.agents.get(c.req.param("id"));
451
+ if (!a)
452
+ return c.json({ error: "not found" }, 404);
453
+ const body = await c.req.json().catch(() => ({ ids: undefined }));
454
+ try {
455
+ const r = await master.stopChildrenFor(c.req.param("id"), body.ids);
456
+ return c.json({ ok: true, ...r });
457
+ }
458
+ catch (err) {
459
+ return c.json({ error: err.message }, 400);
460
+ }
461
+ });
364
462
  // operator-maintained task list (todo.md) with optional agent notification
365
463
  app.post("/api/agents/:id/todo", async (c) => {
366
464
  const a = master.agents.get(c.req.param("id"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",
@@ -26,6 +26,7 @@
26
26
  "files": [
27
27
  "dist",
28
28
  "public",
29
+ "skills",
29
30
  "README.md"
30
31
  ],
31
32
  "scripts": {
@@ -43,7 +44,8 @@
43
44
  "happy-dom": "^20.11.6",
44
45
  "hono": "^4.7.0",
45
46
  "openai": "^5.0.0",
46
- "ws": "^8.21.3"
47
+ "ws": "^8.21.3",
48
+ "zod": "^4.4.3"
47
49
  },
48
50
  "devDependencies": {
49
51
  "@types/node": "^24.0.0",
@@ -1 +1,2 @@
1
- var e=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(2,Math.floor(u/e.css.cell.width)),rows:Math.max(1,Math.floor(l/e.css.cell.height))}}};export{e as FitAddon};
1
+ var e=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(2,Math.floor(u/e.css.cell.width)),rows:Math.max(1,Math.floor(l/e.css.cell.height))}}};export{e as FitAddon};
2
+ //# sourceMappingURL=addon-fit-DIOBYJe3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addon-fit-DIOBYJe3.js","names":[],"sources":["../../node_modules/.pnpm/@xterm+addon-fit@0.11.0/node_modules/@xterm/addon-fit/lib/addon-fit.mjs"],"sourcesContent":["/**\n * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.\n * @license MIT\n *\n * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)\n * @license MIT\n *\n * Originally forked from (with the author's permission):\n * Fabrice Bellard's javascript vt100 for jslinux:\n * http://bellard.org/jslinux/\n * Copyright (c) 2011 Fabrice Bellard\n */\n/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\nvar h=2,_=1,o=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let t=this._terminal._core._renderService.dimensions;if(t.css.cell.width===0||t.css.cell.height===0)return;let s=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,r=window.getComputedStyle(this._terminal.element.parentElement),l=parseInt(r.getPropertyValue(\"height\")),a=Math.max(0,parseInt(r.getPropertyValue(\"width\"))),i=window.getComputedStyle(this._terminal.element),n={top:parseInt(i.getPropertyValue(\"padding-top\")),bottom:parseInt(i.getPropertyValue(\"padding-bottom\")),right:parseInt(i.getPropertyValue(\"padding-right\")),left:parseInt(i.getPropertyValue(\"padding-left\"))},m=n.top+n.bottom,d=n.right+n.left,c=l-m,p=a-d-s;return{cols:Math.max(h,Math.floor(p/t.css.cell.width)),rows:Math.max(_,Math.floor(c/t.css.cell.height))}}};export{o as FitAddon};\n//# sourceMappingURL=addon-fit.mjs.map\n"],"x_google_ignoreList":[0],"mappings":"AAgBA,IAAY,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,kBAAkB,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,WAAW,MAAM,EAAE,IAAI,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,IAAI,EAAE,KAAK,UAAU,OAAO,KAAK,UAAU,OAAO,EAAE,MAAM,KAAK,UAAU,OAAO,EAAE,QAAQ,EAAE,eAAe,MAAM,EAAE,KAAK,UAAU,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,KAAK,UAAU,SAAS,CAAC,KAAK,UAAU,QAAQ,cAAc,OAAO,IAAI,EAAE,KAAK,UAAU,MAAM,eAAe,WAAW,GAAG,EAAE,IAAI,KAAK,QAAQ,GAAG,EAAE,IAAI,KAAK,SAAS,EAAE,OAAO,IAAI,EAAE,KAAK,UAAU,QAAQ,aAAa,EAAE,EAAE,KAAK,UAAU,QAAQ,eAAe,OAAO,GAAG,EAAE,OAAO,iBAAiB,KAAK,UAAU,QAAQ,aAAa,EAAE,EAAE,SAAS,EAAE,iBAAiB,QAAQ,CAAC,EAAE,EAAE,KAAK,IAAI,EAAE,SAAS,EAAE,iBAAiB,OAAO,CAAC,CAAC,EAAE,EAAE,OAAO,iBAAiB,KAAK,UAAU,OAAO,EAAE,EAAE,CAAC,IAAI,SAAS,EAAE,iBAAiB,aAAa,CAAC,EAAE,OAAO,SAAS,EAAE,iBAAiB,gBAAgB,CAAC,EAAE,MAAM,SAAS,EAAE,iBAAiB,eAAe,CAAC,EAAE,KAAK,SAAS,EAAE,iBAAiB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,EAAE,IAAI,KAAK,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return t(this.context.count)},getNextContextId(){return t(this.context.count++)}};function t(t){let n=String(t),r=n.length-1;return e.context.id+(r?String.fromCharCode(96+r):``)+n}function n(t){e.context=t}var r=(e,t)=>e===t,i=Symbol(`solid-track`),a={equals:r},o=null,s=ie,c=1,l=2,u={owned:null,cleanups:null,context:null,owner:null},d=null,f=null,p=null,m=null,h=null,g=0;function _(e,t){let n=p,r=d,i=e.length===0,a=t===void 0?r:t,o=i?u:{owned:null,cleanups:null,context:a?a.context:null,owner:a},s=i?e:()=>e(()=>S(()=>N(o)));d=o,p=null;try{return M(s,!0)}finally{p=n,d=r}}function v(e,t){t=t?Object.assign({},a,t):a;let n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0};return[k.bind(n),e=>(typeof e==`function`&&(e=f&&f.running&&f.sources.has(n)?e(n.tValue):e(n.value)),A(n,e))]}function y(e,t,n){j(te(e,t,!1,c))}function b(e,t,n){s=ae;let r=te(e,t,!1,c),i=O&&D(O);i&&(r.suspense=i),(!n||!n.render)&&(r.user=!0),h?h.push(r):j(r)}function x(e,t,n){n=n?Object.assign({},a,n):a;let r=te(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,j(r),k.bind(r)}function S(e){if(p===null)return e();let t=p;p=null;try{return e()}finally{p=t}}function C(e){b(()=>S(e))}function w(e){return d===null||(d.cleanups===null?d.cleanups=[e]:d.cleanups.push(e)),e}var[T,E]=v(!1);function D(e){let t;return d&&d.context&&(t=d.context[e.id])!==void 0?t:e.defaultValue}var O;function k(){let e=f&&f.running;if(this.sources&&(e?this.tState:this.state)){if((e?this.tState:this.state)===c)j(this);else{let e=m;m=null,M(()=>oe(this),!1),m=e}}if(p){let e=this.observers;if(!e||e[e.length-1]!==p){let t=e?e.length:0;p.sources?(p.sources.push(this),p.sourceSlots.push(t)):(p.sources=[this],p.sourceSlots=[t]),e?(e.push(p),this.observerSlots.push(p.sources.length-1)):(this.observers=[p],this.observerSlots=[p.sources.length-1])}}return e&&f.sources.has(this)?this.tValue:this.value}function A(e,t,n){let r=f&&f.running&&f.sources.has(e)?e.tValue:e.value;if(!e.comparator||!e.comparator(r,t)){if(f){let r=f.running;(r||!n&&f.sources.has(e))&&(f.sources.add(e),e.tValue=t),r||(e.value=t)}else e.value=t;e.observers&&e.observers.length&&M(()=>{for(let t=0;t<e.observers.length;t+=1){let n=e.observers[t],r=f&&f.running;r&&f.disposed.has(n)||((r?!n.tState:!n.state)&&(n.pure?m.push(n):h.push(n),n.observers&&se(n)),r?n.tState=c:n.state=c)}if(m.length>1e6)throw m=[],Error()},!1)}return t}function j(e){if(!e.fn)return;N(e);let t=g;ee(e,f&&f.running&&f.sources.has(e)?e.tValue:e.value,t),f&&!f.running&&f.sources.has(e)&&queueMicrotask(()=>{M(()=>{f&&(f.running=!0),p=d=e,ee(e,e.tValue,t),p=d=null},!1)})}function ee(e,t,n){let r,i=d,a=p;p=d=e;try{r=e.fn(t)}catch(t){return e.pure&&(f&&f.running?(e.tState=c,e.tOwned&&e.tOwned.forEach(N),e.tOwned=void 0):(e.state=c,e.owned&&e.owned.forEach(N),e.owned=null)),e.updatedAt=n+1,F(t)}finally{p=a,d=i}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&`observers`in e?A(e,r,!0):f&&f.running&&e.pure?(f.sources.has(e)||(e.value=r),f.sources.add(e),e.tValue=r):e.value=r,e.updatedAt=n)}function te(e,t,n,r=c,i){let a={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:d,context:d?d.context:null,pure:n};return f&&f.running&&(a.state=0,a.tState=r),d===null||d!==u&&(f&&f.running&&d.pure?d.tOwned?d.tOwned.push(a):d.tOwned=[a]:d.owned?d.owned.push(a):d.owned=[a]),a}function ne(e){let t=f&&f.running;if((t?e.tState:e.state)===0)return;if((t?e.tState:e.state)===l)return oe(e);if(e.suspense&&S(e.suspense.inFallback))return e.suspense.effects.push(e);let n=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<g);){if(t&&f.disposed.has(e))return;(t?e.tState:e.state)&&n.push(e)}for(let r=n.length-1;r>=0;r--){if(e=n[r],t){let t=e,i=n[r+1];for(;(t=t.owner)&&t!==i;)if(f.disposed.has(t))return}if((t?e.tState:e.state)===c)j(e);else if((t?e.tState:e.state)===l){let t=m;m=null,M(()=>oe(e,n[0]),!1),m=t}}}function M(e,t){if(m)return e();let n=!1;t||(m=[]),h?n=!0:h=[],g++;try{let t=e();return re(n),t}catch(e){n||(h=null),m=null,F(e)}}function re(e){if(m&&=(ie(m),null),e)return;let t;if(f){if(!f.promises.size&&!f.queue.size){let e=f.sources,n=f.disposed;h.push.apply(h,f.effects),t=f.resolve;for(let e of h)`tState`in e&&(e.state=e.tState),delete e.tState;f=null,M(()=>{for(let e of n)N(e);for(let t of e){if(t.value=t.tValue,t.owned)for(let e=0,n=t.owned.length;e<n;e++)N(t.owned[e]);t.tOwned&&(t.owned=t.tOwned),delete t.tValue,delete t.tOwned,t.tState=0}E(!1)},!1)}else if(f.running){f.running=!1,f.effects.push.apply(f.effects,h),h=null,E(!0);return}}let n=h;h=null,n.length&&M(()=>s(n),!1),t&&t()}function ie(e){for(let t=0;t<e.length;t++)ne(e[t])}function ae(t){let r,i=0;for(r=0;r<t.length;r++){let e=t[r];e.user?t[i++]=e:ne(e)}if(e.context){if(e.count){e.effects||=[],e.effects.push(...t.slice(0,i));return}n()}for(e.effects&&(e.done||!e.count)&&(t=[...e.effects,...t],i+=e.effects.length,delete e.effects),r=0;r<i;r++)ne(t[r])}function oe(e,t){let n=f&&f.running;n?e.tState=0:e.state=0;for(let r=0;r<e.sources.length;r+=1){let i=e.sources[r];if(i.sources){let e=n?i.tState:i.state;e===c?i!==t&&(!i.updatedAt||i.updatedAt<g)&&ne(i):e===l&&oe(i,t)}}}function se(e){let t=f&&f.running;for(let n=0;n<e.observers.length;n+=1){let r=e.observers[n];(t?!r.tState:!r.state)&&(t?r.tState=l:r.state=l,r.pure?m.push(r):h.push(r),r.observers&&se(r))}}function N(e){let t;if(e.sources)for(;e.sources.length;){let t=e.sources.pop(),n=e.sourceSlots.pop(),r=t.observers;if(r&&r.length){let e=r.pop(),i=t.observerSlots.pop();n<r.length&&(e.sourceSlots[i]=n,r[n]=e,t.observerSlots[n]=i)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)N(e.tOwned[t]);delete e.tOwned}if(f&&f.running&&e.pure)ce(e,!0);else if(e.owned){for(t=e.owned.length-1;t>=0;t--)N(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}f&&f.running?e.tState=0:e.state=0}function ce(e,t){if(t||(e.tState=0,f.disposed.add(e)),e.owned)for(let t=0;t<e.owned.length;t++)ce(e.owned[t])}function P(e){return e instanceof Error?e:Error(typeof e==`string`?e:`Unknown error`,{cause:e})}function le(e,t,n){try{for(let n of t)n(e)}catch(e){F(e,n&&n.owner||null)}}function F(e,t=d){let n=o&&t&&t.context&&t.context[o],r=P(e);if(!n)throw r;h?h.push({fn(){le(r,n,t)},state:c}):le(r,n,t)}var ue=Symbol(`fallback`);function de(e){for(let t=0;t<e.length;t++)e[t]()}function fe(e,t,n={}){let r=[],a=[],o=[],s=0,c=t.length>1?[]:null;return w(()=>de(o)),()=>{let l=e()||[],u=l.length,d,f;return l[i],S(()=>{let e,t,i,m,h,g,v,y,b;if(u===0)s!==0&&(de(o),o=[],r=[],a=[],s=0,c&&=[]),n.fallback&&(r=[ue],a[0]=_(e=>(o[0]=e,n.fallback())),s=1);else if(s===0){for(a=Array(u),f=0;f<u;f++)r[f]=l[f],a[f]=_(p);s=u}else{for(i=Array(u),m=Array(u),c&&(h=Array(u)),g=0,v=Math.min(s,u);g<v&&r[g]===l[g];g++);for(v=s-1,y=u-1;v>=g&&y>=g&&r[v]===l[y];v--,y--)i[y]=a[v],m[y]=o[v],c&&(h[y]=c[v]);for(e=new Map,t=Array(y+1),f=y;f>=g;f--)b=l[f],d=e.get(b),t[f]=d===void 0?-1:d,e.set(b,f);for(d=g;d<=v;d++)b=r[d],f=e.get(b),f!==void 0&&f!==-1?(i[f]=a[d],m[f]=o[d],c&&(h[f]=c[d]),f=t[f],e.set(b,f)):o[d]();for(f=g;f<u;f++)f in i?(a[f]=i[f],o[f]=m[f],c&&(c[f]=h[f],c[f](f))):a[f]=_(p);a=a.slice(0,s=u),r=l.slice(0)}return a});function p(e){if(o[f]=e,c){let[e,n]=v(f);return c[f]=n,t(l[f],e)}return t(l[f])}}}function I(e,t){return S(()=>e(t||{}))}var pe=e=>`Stale read from <${e}>.`;function L(e){let t=`fallback`in e&&{fallback:()=>e.fallback};return x(fe(()=>e.each,e.children,t||void 0))}function R(e){let t=e.keyed,n=x(()=>e.when,void 0,void 0),r=t?n:x(n,void 0,{equals:(e,t)=>!e==!t});return x(()=>{let i=r();if(i){let a=e.children;return typeof a==`function`&&a.length>0?S(()=>a(t?i:()=>{if(!S(r))throw pe(`Show`);return n()})):a}return e.fallback},void 0,void 0)}var z=e=>x(()=>e());function B(e,t,n){let r=n.length,i=t.length,a=r,o=0,s=0,c=t[i-1].nextSibling,l=null;for(;o<i||s<a;){if(t[o]===n[s]){o++,s++;continue}for(;t[i-1]===n[a-1];)i--,a--;if(i===o){let t=a<r?s?n[s-1].nextSibling:n[a-s]:c;for(;s<a;)e.insertBefore(n[s++],t)}else if(a===s)for(;o<i;)(!l||!l.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[a-1]&&n[s]===t[i-1]){let r=t[--i].nextSibling;e.insertBefore(n[s++],t[o++].nextSibling),e.insertBefore(n[--a],r),t[i]=n[a]}else{if(!l){l=new Map;let e=s;for(;e<a;)l.set(n[e],e++)}let r=l.get(t[o]);if(r!=null){if(s<r&&r<a){let c=o,u=1,d;for(;++c<i&&c<a&&(d=l.get(t[c]))!=null&&d===r+u;)u++;if(u>r-s){let i=t[o];for(;s<r;)e.insertBefore(n[s++],i)}else e.replaceChild(n[s++],t[o++])}else o++}else t[o++].remove()}}}var me=`_$DX_DELEGATE`;function he(e,t,n,r={}){let i;return _(r=>{i=r,t===document?e():W(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=``}}function V(e,t,n,r){let i,a=()=>{let t=r?document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`template`):document.createElement(`template`);return t.innerHTML=e,n?t.content.firstChild.firstChild:r?t.firstChild:t.content.firstChild},o=t?()=>S(()=>document.importNode(i||=a(),!0)):()=>(i||=a()).cloneNode(!0);return o.cloneNode=o,o}function ge(e,t=window.document){let n=t[me]||(t[me]=new Set);for(let r=0,i=e.length;r<i;r++){let i=e[r];n.has(i)||(n.add(i),t.addEventListener(i,xe))}}function H(e,t,n){be(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function U(e,t){be(e)||(t==null?e.removeAttribute(`class`):e.className=t)}function _e(e,t,n,r){if(r)Array.isArray(n)?(e[`$$${t}`]=n[0],e[`$$${t}Data`]=n[1]):e[`$$${t}`]=n;else if(Array.isArray(n)){let r=n[0];e.addEventListener(t,n[0]=t=>r.call(e,n[1],t))}else e.addEventListener(t,n,typeof n!=`function`&&n)}function ve(e,t,n){n==null?e.style.removeProperty(t):e.style.setProperty(t,n)}function ye(e,t,n){return S(()=>e(t,n))}function W(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!=`function`)return Se(e,t,r,n);y(r=>Se(e,t(),r,n),r)}function be(t){return!!e.context&&!e.done&&(!t||t.isConnected)}function xe(t){if(e.registry&&e.events&&e.events.find(([e,n])=>n===t))return;let n=t.target,r=`$$${t.type}`,i=t.target,a=t.currentTarget,o=e=>Object.defineProperty(t,"target",{configurable:!0,value:e}),s=()=>{let e=n[r];if(e&&!n.disabled){let i=n[`${r}Data`];if(i===void 0?e.call(n,t):e.call(n,i,t),t.cancelBubble)return}return n.host&&typeof n.host!=`string`&&!n.host._$host&&n.contains(t.target)&&o(n.host),!0},c=()=>{for(;s()&&(n=n._$host||n.parentNode||n.host););};if(Object.defineProperty(t,"currentTarget",{configurable:!0,get(){return n||document}}),e.registry&&!e.done&&(e.done=_$HY.done=!0),t.composedPath){let e=t.composedPath();o(e[0]);for(let t=0;t<e.length-2&&(n=e[t],s());t++){if(n._$host){n=n._$host,c();break}if(n.parentNode===a)break}}else c();o(i)}function Se(e,t,n,r,i){let a=be(e);if(a){!n&&(n=[...e.childNodes]);let t=[];for(let e=0;e<n.length;e++){let r=n[e];r.nodeType===8&&r.data.slice(0,2)===`!$`?r.remove():t.push(r)}n=t}for(;typeof n==`function`;)n=n();if(t===n)return n;let o=typeof t,s=r!==void 0;if(e=s&&n[0]&&n[0].parentNode||e,o===`string`||o===`number`){if(a||o===`number`&&(t=t.toString(),t===n))return n;if(s){let i=n[0];i&&i.nodeType===3?i.data!==t&&(i.data=t):i=document.createTextNode(t),n=G(e,n,r,i)}else n=n!==``&&typeof n==`string`?e.firstChild.data=t:e.textContent=t}else if(t==null||o===`boolean`){if(a)return n;n=G(e,n,r)}else if(o===`function`)return y(()=>{let i=t();for(;typeof i==`function`;)i=i();n=Se(e,i,n,r)}),()=>n;else if(Array.isArray(t)){let o=[],c=n&&Array.isArray(n);if(Ce(o,t,n,i))return y(()=>n=Se(e,o,n,r,!0)),()=>n;if(a){if(!o.length)return n;if(r===void 0)return n=[...e.childNodes];let t=o[0];if(t.parentNode!==e)return n;let i=[t];for(;(t=t.nextSibling)!==r;)i.push(t);return n=i}if(o.length===0){if(n=G(e,n,r),s)return n}else c?n.length===0?we(e,o,r):B(e,n,o):(n&&G(e),we(e,o));n=o}else if(t.nodeType){if(a&&t.parentNode)return n=s?[t]:t;if(Array.isArray(n)){if(s)return n=G(e,n,r,t);G(e,n,null,t)}else n==null||n===``||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}return n}function Ce(e,t,n,r){let i=!1;for(let a=0,o=t.length;a<o;a++){let o=t[a],s=n&&n[e.length],c;if(o!=null&&o!==!0&&o!==!1){if((c=typeof o)==`object`&&o.nodeType)e.push(o);else if(Array.isArray(o))i=Ce(e,o,s)||i;else if(c===`function`){if(r){for(;typeof o==`function`;)o=o();i=Ce(e,Array.isArray(o)?o:[o],Array.isArray(s)?s:[s])||i}else e.push(o),i=!0}else{let t=String(o);s&&s.nodeType===3&&s.data===t?e.push(s):e.push(document.createTextNode(t))}}}return i}function we(e,t,n=null){for(let r=0,i=t.length;r<i;r++)e.insertBefore(t[r],n)}function G(e,t,n,r){if(n===void 0)return e.textContent=``;let i=r||document.createTextNode(``);if(t.length){let r=!1;for(let a=t.length-1;a>=0;a--){let o=t[a];if(i!==o){let t=o.parentNode===e;!r&&!a?t?e.replaceChild(i,o):e.insertBefore(i,n):t&&o.remove()}else r=!0}}else e.insertBefore(i,n);return[i]}var Te=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/;function Ee(e){return De(K(e.replace(/\r\n/g,`
2
+ `)).split(`
3
+ `))}function De(e){let t=[],n=0;for(;n<e.length;){let o=e[n];if(/^```\w*\s*$/.test(o)){let r=[];for(n++;n<e.length&&!/^```\s*$/.test(e[n]);)r.push(e[n++]);n++,t.push(`<pre><code>${r.join(`
4
+ `)}</code></pre>`);continue}if(/^ {0,3}(?:-{3,}|\*{3,}|_{3,})\s*$/.test(o)){t.push(`<hr>`),n++;continue}let s=o.match(/^(#{1,6})\s+(.*)$/);if(s){t.push(`<h${s[1].length}>${a(s[2])}</h${s[1].length}>`),n++;continue}if(/^\s*&gt;/.test(o)){let r=[];for(;n<e.length&&/^\s*&gt;/.test(e[n]);)r.push(e[n++].replace(/^\s*&gt;\s?/,``));t.push(`<blockquote>${De(r)}</blockquote>`);continue}if(o.includes(`|`)&&n+1<e.length&&ke(e[n+1])){let r=Oe(e[n+1]).map(e=>e.startsWith(`:`)&&e.endsWith(`:`)?`center`:e.endsWith(`:`)?`right`:`left`),i=Oe(o);n+=2;let s=[];for(;n<e.length&&/\S/.test(e[n])&&e[n].includes(`|`);)s.push(Oe(e[n])),n++;let c=(e,t,n)=>{let i=r[t];return`<${n}${i&&i!==`left`?` style="text-align:${i}"`:``}>${a(e)}</${n}>`};t.push(`<div class="tbl"><table><thead><tr>${i.map((e,t)=>c(e,t,`th`)).join(``)}</tr></thead><tbody>${s.map(e=>`<tr>${e.map((e,t)=>c(e,t,`td`)).join(``)}</tr>`).join(``)}</tbody></table></div>`);continue}if(Te.test(o)){t.push(i(r(o.match(Te)[1])));continue}if(/^\s*$/.test(o)){n++;continue}let c=[];for(;n<e.length&&!/^\s*$/.test(e[n])&&!/^#{1,6}\s/.test(e[n])&&!/^```/.test(e[n])&&!/^ {0,3}(?:-{3,}|\*{3,}|_{3,})\s*$/.test(e[n])&&!/^\s*&gt;/.test(e[n])&&!Te.test(e[n])&&!(e[n].includes(`|`)&&n+1<e.length&&ke(e[n+1]));)c.push(e[n++]);t.push(`<p>${c.map(a).join(`<br>`)}</p>`)}return t.join(`
5
+ `);function r(e){return e.replace(/\t/g,` `).length}function i(t){let o=null,s=[];for(;n<e.length;){let c=e[n].match(Te);if(!c)break;let l=r(c[1]);if(l<t)break;let u=/^\d/.test(c[2]);if(o===null)o=u;else if(u!==o)break;n++;let d=c[3];for(;n<e.length&&/\S/.test(e[n])&&!Te.test(e[n])&&!/^#{1,6}\s/.test(e[n])&&!/^```/.test(e[n])&&!/^\s*&gt;/.test(e[n]);)d+=` `+e[n].trim(),n++;let f=``,p=e[n]?.match(Te);p&&r(p[1])>l&&(f=i(r(p[1])));let m=d.match(/^\[( |x|X)\]\s+(.*)$/),h=m?`<input type="checkbox" disabled${m[1].toLowerCase()===`x`?` checked`:``}> `:``;s.push(`<li>${h}${a(m?m[2]:d)}${f}</li>`)}return o?`<ol>${s.join(``)}</ol>`:`<ul>${s.join(``)}</ul>`}function a(e){let t=[];return e=e.replace(/`([^`]+)`/g,(e,n)=>(t.push(`<code>${n}</code>`),`\u0000${t.length-1}\u0000`)),e=e.replace(/!\[([^\]]*)\]\((https?:\/\/[^)\s]+)(?:\s+&quot;[^)]*&quot;)?\)/g,`<img src="$2" alt="$1" loading="lazy">`),e=e.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)(?:\s+&quot;[^)]*&quot;)?\)/g,`<a href="$2" rel="noopener noreferrer" target="_blank">$1</a>`),e=e.replace(/(?<!["'=\w])(https?:\/\/[^\s<>"')\]]*[^\s<>"')\].,;:!?"')\]])/g,`<a href="$1">$1</a>`),e=e.replace(/\*\*\*([\s\S]+?)\*\*\*/g,`<strong><em>$1</em></strong>`),e=e.replace(/\*\*([\s\S]+?)\*\*/g,`<strong>$1</strong>`),e=e.replace(/(^|[^\w])__(?=\S)([\s\S]*?\S)__(?!\w)/g,`$1<strong>$2</strong>`),e=e.replace(/(^|[^\w*])\*(?!\s)([^*\n]+?)\*(?![\w*])/g,`$1<em>$2</em>`),e=e.replace(/(^|[^\w])_(?!\s)([^_\n]+?)_(?!\w)/g,`$1<em>$2</em>`),e=e.replace(/~~([\s\S]+?)~~/g,`<del>$1</del>`),e.replace(/\u0000(\d+)\u0000/g,(e,n)=>t[+n])}}function Oe(e){let t=e.trim();t.startsWith(`|`)&&(t=t.slice(1));let n=[],r=``;for(let e=0;e<t.length;e++){if(t[e]===`\\`&&t[e+1]===`|`){r+=`|`,e++;continue}if(t[e]===`|`&&e===t.length-1)break;if(t[e]===`|`){n.push(r.trim()),r=``;continue}r+=t[e]}return n.push(r.trim()),n.filter((e,r)=>!(e===``&&r===n.length-1&&t.endsWith(`|`)))}function ke(e){let t=e.trim();if(!t.includes(`|`)||!t.includes(`-`))return!1;let n=Oe(t);return n.every(e=>/^:?-+:?$/.test(e))&&n.some(e=>e!==``)}function K(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}var Ae=`modulepreload`,je=function(e){return`/`+e},Me={},Ne=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=je(t,n),t=s(t),t in Me)return;Me[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Ae,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Pe=V(`<div class=overlay><div class=modal style=max-width:360px><div class=modal-head><b>🔒 sign in</b><span></span></div><form style=display:flex;flex-direction:column;gap:10px><input id=pw-input type=password placeholder=password autofocus><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:7px 12px;cursor:pointer">unlock</button><span class=muted style=font-size:11px>the token is stored locally and sent as Bearer to this server only`),Fe=V(`<br>`),Ie=V(`<span class="badge queued">⏳ <!> queued`),Le=V(`<span class="badge cron">⏰ `),Re=V(`<span class=sub>ℹ`),ze=V(`<header class=chan-head><span class=hash>#</span><span class=title></span><span></span><span class=sub> · <!>/<!> · turns <!> · tools </span><span style=margin-left:auto;display:flex;gap:4px><button class=iconbtn title="terminal (t)">⌨</button><button class=iconbtn title="toggle details panel (d)">▤`),Be=V(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),Ve=V(`<div class=content>`),He=V(`<div class="msg live"><div class=avatar style="background:#5865f233;border:1px solid #5865f266">🫖</div><div class=msg-body><div class=msg-head><span class=author style=color:var(--acc)>agent</span><span class=ts>streaming…`),Ue=V(`<div class=feed>`),We=V(`<button class=jump>↓ `),Ge=V(`<div class=termdrawer><div class=termbar><span>⌨ terminal — <span class=mono></span></span><button class=iconbtn title="close terminal (t)">✕</button></div><div class=termhost>`),Ke=V(`<div class=cmds>`),qe=V(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),Je=V(`<div class=composer><form><textarea rows=1></textarea><button type=submit>send</button></form><div class=hint>`),Ye=V(`<h3>🎛 session`),Xe=V(`<div class="card sesscard"><div class=sessrow><span class=k>agent</span><b></b><span></span></div><div class=sessrow><span class=k>workspace</span><span class="mono ellip"></span></div><div class=sessrow><span class=k>session</span><span class=mono>/`),Ze=V(`<h3>🧦 model`),Qe=V(`<div class=meta style=color:var(--fg)>`),$e=V(`<div class=modelbox><select title="provider (OpenAI-compatible endpoint)"></select><div style=display:flex;gap:4px><input type=text list=model-list style=flex:1;min-width:0><datalist id=model-list></datalist><button title="apply to this session — takes effect from the agent's next turn">apply</button></div><div class=meta>current: `),et=V(`<h3>⏯ controls`),tt=V(`<button class=danger title="interrupt: aborts the current LLM call; the running tool finishes first">■ stop`),nt=V(`<button title="stop every sub-agent this agent spawned (descendants included)">⏹ subs`),rt=V(`<div class=btnrow><button title="branch off the conversation here — try things without disturbing the main line">⑂ fork</button><button title="remove agent from teapot (session log stays on disk)">🗑 remove`),it=V(`<div class=ctrlrow><label title="after each round the agent keeps working toward its goal without waiting for input; sending a prompt also starts an idle agent"><input type=checkbox>auto-continue</label><span class=muted>loops while the goal is active`),at=V(`<h3>🎯 goal <span>`),ot=V(`<form style=display:flex;flex-direction:column;gap:6px;margin-bottom:6px><textarea id=goal-input rows=3 placeholder="set new goal…"style="background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;width:100%;resize:vertical"></textarea><div style=display:flex;justify-content:flex-end;align-items:center;gap:10px><label class=muted title="queue a harness prompt telling the agent about the new goal at its next turn boundary"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=goal-notify type=checkbox checked> notify agent</label><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save`),st=V(`<div class=card>`),ct=V(`<div class=muted style=font-size:11px;margin-top:4px>stored with the session · the model reads it via get_goal() ·`),lt=V(`<h3>✅ tasks <span class=muted style=text-transform:none;letter-spacing:0>· todo.md, editable by you and the agent`),ut=V(`<textarea id=todo-input class=mono rows=5 placeholder="- task one
6
+ - task two"title="shared with the agent — it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),dt=V(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button style="background:var(--ok);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save tasks`),ft=V(`<h3>📈 progress`),pt=V(`<h3>📊 runtime`),mt=V(`<div class="card muted">turns <!> · tools <!> · compacted <!>
7
+ tokens in/out <!>/`),ht=V(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),gt=V(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),_t=V(`<div><nav class=sidebar><h1>🫖 teapot<span></span><span style=float:right;display:flex;gap:4px><button class=iconbtn title="new agent">+</button><button class=iconbtn title=settings>⚙</button></span></h1><div class=agent-list></div><div class=metrics></div></nav><section class=channel></section><aside>`),vt=V(`<span class=mini-cron>⏰`),yt=V(`<span title="goal done">✓`),bt=V(`<div><span></span><span>`),xt=V(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),St=V(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),Ct=V(`<div class="content muted">thinking…`),wt=V(`<div class=cmdrow><b></b><span class=muted>`),Tt=V(`<div class=cmdrow><b>@</b><span class=muted>`),Et=V(`<option>`),Dt=V(`<button class=runbtn title="run toward the goal (starts the loop)">▶ start`),Ot=V(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),kt=V(`<div class=progrow><b>recent</b><span>`),At=V(`<div class="progrow warn"><b>⚠ problems</b><span>`),jt=V(`<div class=progrow><b>next</b><span>`),Mt=V(`<div class=progrow><b>goal</b><span>`),Nt=V(`<div class="card prog"><div class=progrow><b>doing</b><span></span></div><div class="meta muted">`),Pt=V(`<div><span></span><span> events`),Ft=V(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),It=V(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),Lt=V(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),Rt=V(`<div><div style=font-size:12.5px;margin-bottom:4px> event(s) came after this prompt — what should happen to them on the new branch?</div><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>summarize them into a note the agent can still read</label><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>discard them entirely (clean timeline)`),zt=V(`<form style=display:flex;flex-direction:column;gap:10px><textarea id=edit-text class="mono w100"rows=6></textarea><div style=display:flex;justify-content:flex-end;gap:8px><button type=button>cancel</button><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 12px;cursor:pointer">⑂ fork & resend`),Bt=V(`<div class=mono>`),Vt=V(`<pre class="mono toolbody">`),Ht=V(`<div class=meta>ms`),Ut=V(`<div class=meta>waiting for output…`),q=V(`<div class=meta>`),Wt=V(`<div class=meta>writing…`),Gt=V(`<pre class="mono toolbody del">`),Kt=V(`<pre class="mono toolbody add">`),qt=V(`<div class=meta> · <!>ms`),Jt=V(`<div class=meta>applying…`),J=V(`<pre class="mono toolbody patch">`),Yt=V(`<div>`),Xt=V(`<div class=meta>validating…`),Y=V(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Zt=V(`<span class=muted>`),Qt=V(`<div class=meta>loading…`),$t=V(`<div class=meta>bundled: `),en=V(`<div class=meta>saving…`),tn=V(`<span class=actor>@`),nn=V(`<details><summary><b>⚙ </b><span class=meta>`),rn=V(`<div class=divider-msg>⑂ forked from <!> → `),an=V(`<div class=divider-msg>🎯 goal <!>: `),on=V(`<div class=divider-msg>✅ tasks updated (<!>)`),sn=V(`<div> → `),cn=V(`<div class=avatar>`),ln=V(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),un=V(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),dn=V(`<div><div class=msg-body>`),fn=V(`<span style=width:38px>`),pn=V(`<div class=interrupted>⚠ interrupted — partial output kept`),mn=V(`<div class=msgfoot><span>copy summary`),hn=V(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),X=V(`<div class="content muted">Rejected: `),gn=V(`<details class="embed decision"><summary><b>📌 </b><span class=meta>decision logged</span></summary><div class=content><b>Why:`),_n=V(`<div class=qopts>`),vn=V(`<div class="embed question"><div>❓ </div><div class=meta>the agent is waiting for your reply — answer below or tap an option`),yn=V(`<button class=qopt>`),bn=V(`<div class=meta>⚠ `),xn=V(`<div class=meta>→ `),Sn=V(`<div class=embed style=border-color:var(--ok)><div>📈 `),Cn=V(`<div class="embed fail"><div class=mono>⚠ `),wn=V(`<div class="content muted">`),Tn=V(`<button class=copybtn title="copy to clipboard">`),En=V(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),Dn=V(`<span style=color:var(--err);font-size:13px>`),On=V(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button>↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label>provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create & start`),kn=V(`<div class=direntry>📁 `),An=V(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px></div><label>base url<input type=text class="w100 mono"></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model <input type=text class="w100 mono"></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),jn=V(`<button type=button>`),Mn=V(`<label><input type=number min=0>`),Nn=V(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add provider</button><div><label style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<input type=text></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid></div></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><button type=submit style="align-self:flex-end;background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">save settings`),Pn=V(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),Fn=V(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),In=V(`<span class=muted>🧩 sub of @`),Ln=V(`<div class=cfgrow><b></b><span class=muted>`),Rn={prompt:{name:`you`,icon:`🟧`,color:`#faa81a`},user:{name:`you`,icon:`🟧`,color:`#faa81a`},message:{name:`agent`,icon:`🫖`,color:`#5865f2`},progress:{name:`progress`,icon:`📈`,color:`#3ba55d`},question:{name:`agent`,icon:`❓`,color:`#5865f2`}},zn={name:`harness`,icon:`📣`,color:`#3ba55d`},Bn=e=>{if(e.data?.actor)return{name:`@${String(e.data.actor)}`,icon:`🧩`,color:`#3ba0c9`};if(e.type===`tool_call`||e.type===`tool_result`)return{name:String(e.data?.name??`tool`),icon:`⚙`,color:`#3ba0c9`};if(e.type===`prompt`){let t=String(e.data?.source??`user`);return t===`user`?Rn.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:zn}return Rn[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},Vn=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`]),Hn=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function Z(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=``;try{t=(await i.json())?.error??``}catch{}throw Error(t||`${e}: HTTP ${i.status}`)}return i.json()}var Un=location.hash.match(/[#&]token=([^&]+)/);Un&&(localStorage.setItem(`teapot.token`,decodeURIComponent(Un[1])),history.replaceState(null,``,location.pathname+location.search));var Wn=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function Gn(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v([]),[o,s]=v(0),[c,l]=v([]),[u,d]=v(null),[f,p]=v(``),[m,h]=v(localStorage.getItem(`teapot.autostart`)!==`0`),g=e=>{h(e),localStorage.setItem(`teapot.autostart`,e?`1`:`0`)},[_,S]=v({providers:{}}),[T,E]=v(!1),[D,O]=v(!1),[k,A]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),j=()=>{let e=!k();A(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[ee,te]=v(``),[ne,M]=v(``),[re,ie]=v([]),ae=()=>Object.keys(_().providers??{});async function oe(e){if(e)try{let t=await Z(`/api/models?provider=${encodeURIComponent(e)}`);ie(t.models??[])}catch{ie([])}}let se=()=>{let e=ne().trim()||B()?.model||``;if(!e)return``;let t=re().find(t=>t.id===e);if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Q(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)};b(()=>{let e=B();e&&(te(e.provider||_().defaultProvider||ae()[0]||``),M(``),oe(ee()))});let[N,ce]=v(!0),[P,le]=v(0),[F,ue]=v(null),[de,fe]=v(``),pe;b(()=>{if(!F()){clearTimeout(pe),pe=void 0,fe(``);return}pe||=setTimeout(()=>{pe=void 0,fe(F()?.text??``)},60)}),w(()=>clearTimeout(pe));let B=x(()=>e().find(e=>e.id===n())),[me,he]=v(null),[V,ge]=v([]),ve=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(Vn.has(r.type)){if(r.type===`tool_call`){let e=n.get(r.data.callId)??[];e.push(r),n.set(r.data.callId,e)}else if(r.type===`tool_result`){let i=n.get(r.data.callId)?.shift();i&&(e.set(i.id,r),t.add(r.id))}}return{resFor:e,consumed:t}}),be=x(()=>{let{consumed:e}=ve(),t=i().filter(t=>Vn.has(t.type)?t.type===`tool_result`?!e.has(t.id):t.type!==`message`||String(t.data?.content??``).trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final:!1),n=[];for(let e of t)if(e.type===`sub`){let t=e.data,r=String(t?.type??`message`);if(r===`state`)continue;n.push({...e,type:r,data:{...t?.data??{},actor:t?.sub}})}else n.push(e);let r=V().filter(e=>!n.some(t=>t.type===`prompt`&&t.data?.source===`user`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)).map(e=>({id:e.id,seq:0,ts:new Date(e.at).toISOString(),session:B()?.session??``,branch:B()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!0}}));return[...n,...r]}),xe=()=>Z(`/api/config`).then(S).catch(()=>{}),[Se,Ce]=v(!1);C(()=>{let e=()=>Ce(!0);window.addEventListener(`teapot:unauthorized`,e),w(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[we,G]=v(``),[Te,De]=v(!1),Oe=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==Oe?(Oe=t,De(!1),G(r)):t&&!Te()&&G(r)});let ke=async()=>{let e=document.getElementById(`todo-notify`)?.checked??!0;if(n())try{await Z(`/api/agents/${n()}/todo`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:we(),notify:e})}),De(!1),X(`tasks saved${e&&we().trim()?` & notification queued`:``}`),K()}catch(e){X(`save failed: ${e.message}`)}},K=()=>Z(`/api/agents`).then(e=>t(e.agents)).catch(()=>{}),Ae=()=>Z(`/api/metrics`).then(d).catch(()=>{}),[je,Me]=v([]),Bt=()=>Z(`/api/tasks`).then(e=>Me(e.tasks)).catch(()=>{}),Vt=e=>je().filter(t=>t.agent===e),[Ht,Ut]=v(null),q=new Map;function Wt(e){let t=Array(e.length);for(let n=0;n<e.length;n++){let r=e[n],i=q.get(r.id);if(t[n]=i??r,!i&&(q.set(r.id,r),q.size>3e3)){let e=q.keys().next().value;e!==void 0&&q.delete(e)}}return t}async function Gt(e){try{let t=Ht(),[n,r]=await Promise.all([Z(`/api/agents/${e}/events?limit=300${t?`&branch=${encodeURIComponent(t)}`:``}`),Z(`/api/agents/${e}/branches`)]);a(Wt(n.events)),s(n.total??n.events.length),l(r.branches)}catch{}}function Kt(){return document.querySelector(`.feed`)}function qt(){let e=Kt();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<80}function Jt(e=!1){let t=Kt();t&&(e||N())&&(t.scrollTop=t.scrollHeight,le(0))}async function J(e,t=!0){r(e),ue(null),Ut(null),ge([]),localStorage.setItem(`teapot.session`,e),en(e,t),Z(`/api/agents/${e}/load`,{method:`POST`}).then(K).catch(()=>{}),await Gt(e),requestAnimationFrame(()=>Jt(!0))}let[Yt,Xt]=v(!1),Y=null,Zt=null;w(()=>Y?.close());function Qt(){let e=location.protocol===`https:`?`wss://`:`ws://`;Y=new WebSocket(`${e}${location.host}/api/ws${Wn()}`),Y.onopen=()=>Xt(!0),Y.onclose=()=>{Xt(!1),setTimeout(Qt,1500)},Y.onerror=()=>Y?.close();let t=new Set([`state`,`usage`,`session_start`]),r=null;Y.onmessage=e=>{let a=JSON.parse(e.data);if(a.kind!==`ping`&&a.kind!==`pong`){if(a.kind===`llm-delta`){r={id:a.agentId,at:Date.now()},a.agentId===n()&&ue({text:a.text??``,reasoning:a.reasoning??``});return}a.kind===`event`&&t.has(a.event?.type)||(Zt||=setTimeout(async()=>{if(Zt=null,await K(),await Ae(),n()){let e=i().at(-1)?.id,t=o(),a=Date.now();await Gt(n()),i().at(-1)?.id!==e&&(r?.id===n()&&r.at>=a||ue(null),qt()?Jt(!0):le(P()+Math.max(0,o()-t))),ge(e=>e.filter(e=>!i().some(t=>t.type===`prompt`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)))}},400))}}}let $t=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function en(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=$t();t&&e().some(e=>e.id===t)&&t!==n()&&J(t,!1)}),b(()=>{let e=B();document.title=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`}),window.addEventListener(`keydown`,t=>{let r=t.target;if(r&&(r.tagName===`INPUT`||r.tagName===`TEXTAREA`||r.isContentEditable)){t.key===`Escape`&&r.blur();return}if(t.key===`Escape`){if(T()){E(!1);return}if(D()){O(!1);return}let e=B();if(e?.status===`running`){Z(`/api/agents/${e.id}/stop`,{method:`POST`}).then(K);return}k()&&window.innerWidth<=1100&&A(!1);return}if(!(T()||D())){if(t.key===`/`)t.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(t.key===`d`)j();else if(t.key===`t`)rn();else if(t.key===`ArrowDown`||t.key===`ArrowUp`){let r=e();if(r.length===0)return;t.preventDefault();let i=r.findIndex(e=>e.id===n()),a=t.key===`ArrowDown`?Math.min(i+1,r.length-1):Math.max(i-1,0);a!==i&&J(r[a].id)}}});let[tn,nn]=v(localStorage.getItem(`teapot.term`)===`1`),rn=()=>{let e=!tn();nn(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},an=null,on=null,sn=null,cn=null,ln={cols:0,rows:0},un=null;function dn(){cn?.disconnect(),cn=null,sn?.close(),sn=null,on?.dispose(),on=null}function fn(e){dn(),an&&Promise.all([Ne(()=>import(`./xterm-C3BHN0de.js`),[]),Ne(()=>import(`./addon-fit-DIOBYJe3.js`),[])]).then(([{Terminal:t},{FitAddon:n}])=>{let r=new t({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:{background:`#0d0e12`,foreground:`#dcdee4`}}),i=new n;r.loadAddon(i),r.open(an),i.fit(),on=r;let a=location.protocol===`https:`?`wss://`:`ws://`,o=new WebSocket(`${a}${location.host}/api/agents/${e}/term${Wn()}`);sn=o,o.onmessage=e=>{let t=JSON.parse(e.data);t.kind===`data`?r.write(t.data):t.kind===`exit`&&r.write(`\r\n\x1b[2m[terminal exited ${t.code??``}]\x1b[0m\r\n`)},r.onData(e=>{o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({kind:`input`,data:e}))});let s=()=>{try{i.fit()}catch{}let{cols:e,rows:t}=r;(e!==ln.cols||t!==ln.rows)&&o.readyState===WebSocket.OPEN&&(ln={cols:e,rows:t},o.send(JSON.stringify({kind:`resize`,cols:e,rows:t})))};cn=new ResizeObserver(()=>{un&&clearTimeout(un),un=setTimeout(s,300)}),cn.observe(an),setTimeout(s,50)})}b(()=>{let e=n();!tn()||!e?dn():requestAnimationFrame(()=>e&&fn(e))}),w(dn),C(()=>{xe(),K().then(()=>{let t=$t()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&J(n.id,!1)}),Ae(),Bt(),yn(),Qt();let t=setInterval(()=>{Ae(),Bt()},3e4);w(()=>clearInterval(t))});let[pn,mn]=v(``),hn,X=e=>{mn(e),clearTimeout(hn),hn=setTimeout(()=>mn(``),3200)},gn=[{cmd:`/start`,desc:`start working toward the goal`},{cmd:`/stop`,desc:`interrupt the running agent`},{cmd:`/fork`,desc:`branch the conversation here`},{cmd:`/goal`,desc:`/goal <text> — set goal & notify the agent`},{cmd:`/compact`,desc:`force a context compaction now`}],[_n,vn]=v([]),yn=()=>Z(`/api/personas`).then(e=>vn(e.personas)).catch(()=>{}),[bn,xn]=v(!1),Sn=()=>{let e=f().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Cn=()=>{let t=Sn();return t===null?[]:[..._n().map(e=>({key:e.key,label:`${e.label} — spawns a sub-agent`,kind:`persona`})),...e().filter(e=>e.id!==n()).map(e=>({key:e.id,label:`${e.status} — send directly`,kind:`agent`}))].filter(e=>e.key.toLowerCase().startsWith(t))},wn=()=>{let e=f();return!e.startsWith(`/`)||e.includes(` `)||e.includes(`
8
+ `)?[]:gn.filter(t=>t.cmd.slice(1).startsWith(e.slice(1).toLowerCase()))},Tn,En=()=>{Tn&&(Tn.style.height=`auto`,Tn.style.height=`${Math.min(Tn.scrollHeight,160)}px`)};b(()=>{f(),En()});let Dn=async e=>{let t=n();if(t)try{await Z(`/api/agents/${t}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:m()})}),ge(t=>[...t,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now()}])}catch(t){p(e),console.error(`send failed:`,t)}},On=async t=>{t.preventDefault();let r=n(),i=f().trim();if(!(!r||!i)){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=_n().some(e=>e.key.toLowerCase()===r),s=e().some(e=>e.id.toLowerCase()===r);try{if(o){if(!a){X(`usage: @${r} <task>`);return}let e=await Z(`/api/agents/${n()}/spawn`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({persona:r,task:a,context:bn()?`fork`:`none`})});X(`🧩 spawned ${e.id}${bn()?` (forked context)`:``}`),K(),p(``)}else if(s){if(!a){X(`usage: @${r} <message>`);return}await Z(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:m()})}),X(`→ delivered to @${r}`),p(``)}else{X(`unknown @${r} — personas: ${_n().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){X(`@${r} failed: ${e.message}`)}return}if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim(),a=(e,t)=>Z(`/api/agents/${r}${e}`,{method:`POST`,headers:{"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}}).then(K);try{if(t===`start`)await a(`/start`);else if(t===`stop`)await a(`/stop`);else if(t===`fork`)await a(`/fork`,{}),await J(r);else if(t===`compact`){let e=await a(`/compact`);X(e?.ran?`context compacted`:`nothing to compact yet`)}else if(t===`goal`){if(!n){X(`usage: /goal <text>`);return}await a(`/goal`,{text:n,notify:!0}),X(`goal saved & notification queued`)}else{X(`unknown command "${t}" — /start /stop /fork /goal /compact`);return}p(``)}catch(e){X(`/${t} failed: ${e.message}`)}return}p(``),await Dn(i)}},kn=e=>()=>n()&&Z(`/api/agents/${n()}${e}`,{method:`POST`}).then(K),An=async e=>{e.preventDefault();let t=document.getElementById(`goal-input`),r=document.getElementById(`goal-notify`)?.checked??!0;!n()||!t.value.trim()||(await Z(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t.value,notify:r})}),t.value=``,K())};return[I(R,{get when(){return _()?.needsSetup},fallback:null,get children(){return I(tr,{onDone:()=>location.reload()})}}),I(R,{get when(){return Se()},get children(){var e=Pe();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),I(R,{get when(){return!_()?.needsSetup},get children(){var i=_t(),o=i.firstChild,s=o.firstChild,l=s.firstChild.nextSibling,d=l.nextSibling.firstChild,h=d.nextSibling,v=s.nextSibling,b=v.nextSibling,x=o.nextSibling,S=x.nextSibling;return d.$$click=()=>{xe(),E(!0)},h.$$click=()=>{xe(),O(!0)},W(v,I(L,{get each(){return e()},children:e=>(()=>{var t=bt(),r=t.firstChild,i=r.nextSibling;return t.$$click=()=>J(e.id),W(i,()=>e.id),W(t,I(R,{get when(){return Vt(e.id).length>0},get children(){var t=vt();return y(()=>H(t,`title`,Vt(e.id).map(e=>`${e.id}: ${e.schedule}`).join(`
9
+ `))),t}}),null),W(t,I(R,{get when(){return e.goal.status===`done`},get children(){return yt()}}),null),y(i=>{var a=`agent-item`+(e.id===n()?` sel`:``),o=`dot ${e.status}`;return a!==i.e&&U(t,i.e=a),o!==i.t&&U(r,i.t=o),i},{e:void 0,t:void 0}),t})()})),W(b,I(R,{get when(){return u()},get children(){return[`master rss `,z(()=>u().rssMb),`MB · heap `,z(()=>u().heapUsedMb),`MB`,Fe(),`load1 `,z(()=>u().loadavg1),` · up `,z(()=>Math.floor(u().uptimeSec/60)),`m`]}})),W(x,I(R,{get when(){return B()},get fallback(){return xt()},get children(){return[(()=>{var e=ze(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling,l=c.firstChild,u=l.nextSibling;return W(t,()=>B().id),W(n,()=>B().status),W(e,I(R,{get when(){return(B().pendingPrompts??0)>0},get children(){var e=Ie(),t=e.firstChild.nextSibling;return t.nextSibling,W(e,()=>B().pendingPrompts,t),y(()=>H(e,`title`,`${B().pendingPrompts} prompt(s) waiting — the agent picks them up at the next turn boundary`)),e}}),r),W(e,I(R,{get when(){return Vt(B().id).length>0},get children(){var e=Le();return e.firstChild,W(e,()=>Vt(B().id).length,null),y(()=>H(e,`title`,`scheduled tasks:\n${Vt(B().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
10
+ `)}`)),e}}),r),W(r,()=>B().model,i),W(r,()=>B().session,a),W(r,()=>B().branch,o),W(r,()=>B().stats.turns,s),W(r,()=>B().stats.toolCalls,null),W(c,I(R,{get when(){return B().statusReason},get children(){var e=Re();return y(()=>H(e,`title`,B().statusReason)),e}}),l),l.$$click=rn,u.$$click=j,y(()=>U(n,`badge ${B().status}`)),e})(),(()=>{var e=Ue();return e.addEventListener(`scroll`,()=>{let e=qt();e&&P()&&le(0),ce(e)}),W(e,I(R,{get when(){return be().length>0},get fallback(){return St()},get children(){return[I(L,{get each(){return be()},children:(e,t)=>I(qn,{e,get prev(){return be()[t()-1]},get res(){return ve().resFor.get(e.id)},onOption:e=>void Dn(e),get onEdit(){return e.type===`prompt`&&e.data?.source===`user`?()=>he({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),I(R,{get when(){return F()},get children(){var e=He(),t=e.firstChild.nextSibling;return t.firstChild,W(t,I(R,{get when(){return F().reasoning},get children(){var e=Be(),t=e.firstChild.nextSibling;return W(t,()=>F().reasoning),e}}),null),W(t,I(R,{get when(){return de()},get fallback(){return Ct()},get children(){var e=Ve();return y(()=>e.innerHTML=Ee(de()+`▍`)),e}}),null),e}})]}})),e})(),I(R,{get when(){return!N()||P()>0},get children(){var e=We();return e.firstChild,e.$$click=()=>Jt(!0),W(e,(()=>{var e=z(()=>P()>0);return()=>e()?`${P()} new message${P()>1?`s`:``}`:`jump to present`})(),null),e}}),I(R,{get when(){return z(()=>!!tn())()&&B()},get children(){var e=Ge(),t=e.firstChild,n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling,a=t.nextSibling;return W(r,()=>B().workspace),i.$$click=rn,ye(e=>an=e,a),e}}),(()=>{var e=Je(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=t.nextSibling;W(e,I(R,{get when(){return wn().length>0},get children(){var e=Ke();return W(e,I(L,{get each(){return wn()},children:e=>(()=>{var t=wt(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>p(e.cmd+` `),W(n,()=>e.cmd),W(r,()=>e.desc),y(()=>H(t,`title`,e.desc)),t})()})),e}}),t),W(e,I(R,{get when(){return Cn().length>0},get children(){var e=Ke();return W(e,I(L,{get each(){return Cn()},children:e=>(()=>{var t=Tt(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>p(`@${e.key} `),W(n,()=>e.key,null),W(r,()=>e.label),y(()=>H(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,On),n.$$keydown=e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),On(e))},n.$$input=e=>{p(e.currentTarget.value),En()};var a=Tn;return typeof a==`function`?ye(a,n):Tn=n,W(t,I(R,{get when(){return z(()=>!!f().startsWith(`@`))()&&f().includes(` `)},get children(){var e=qe(),t=e.firstChild;return t.addEventListener(`change`,e=>xn(e.currentTarget.checked)),y(()=>t.checked=bn()),e}}),r),W(i,()=>pn()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(()=>H(n,`placeholder`,`message #${B().id} — / for commands`)),y(()=>n.value=f()),e})()]}})),W(S,I(R,{get when(){return B()},get children(){return[Ye(),(()=>{var e=Xe(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return W(n,()=>B().id),W(r,()=>B().status),W(a,()=>B().workspace),W(o,()=>B().session,s),W(o,()=>B().branch,null),y(e=>{var t=`badge ${B().status}`,n=B().workspace;return t!==e.e&&U(r,e.e=t),n!==e.t&&H(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),Ze(),(()=>{var e=$e(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{te(e.currentTarget.value),oe(e.currentTarget.value)}),W(t,I(L,{get each(){return ae()},children:e=>(()=>{var t=Et();return t.value=e,W(t,e,null),W(t,()=>e===_().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>M(e.currentTarget.value),W(a,I(L,{get each(){return re()},children:e=>(()=>{var t=Et();return y(()=>t.value=e.id),t})()})),o.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await Z(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:ee(),model:ne().trim()||void 0})}),t.textContent=`✓ applied`,K()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},W(s,()=>B().model,null),W(s,I(R,{get when(){return re().length},get children(){return[` · `,z(()=>re().length),` models loaded`]}}),null),W(e,I(R,{get when(){return se()},get children(){var e=Qe();return W(e,se),e}}),null),y(()=>H(i,`placeholder`,B().model)),y(()=>t.value=ee()),y(()=>i.value=ne()),e})(),et(),(()=>{var i=rt(),o=i.firstChild,s=o.nextSibling;return W(i,I(R,{get when(){return B().status===`running`},get fallback(){return(()=>{var e=Dt();return _e(e,`click`,kn(`/start`),!0),e})()},get children(){var e=tt();return _e(e,`click`,kn(`/stop`),!0),e}}),o),o.$$click=()=>Z(`/api/agents/${B().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>J(B().id)),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await Z(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let o=e().filter(e=>e.id!==i);t(o),o[0]?J(o[0].id):(r(null),a([]))},W(i,I(R,{get when(){return e().some(e=>e.parent===n())},get children(){var e=nt();return e.$$click=async()=>{if(!n())return;let e=await Z(`/api/agents/${n()}/stop-children`,{method:`POST`});X(`stopped: ${(e.stopped??[]).join(`, `)||`(none)`}`),K()},e}}),null),i})(),(()=>{var e=it(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>g(e.currentTarget.checked)),y(()=>t.checked=m()),e})(),(()=>{var e=at(),t=e.firstChild.nextSibling;return W(t,()=>B().goal.status),y(()=>U(t,`badge ${B().goal.status===`done`?`done`:``}`)),e})(),(()=>{var e=ot();return e.addEventListener(`submit`,An),e})(),(()=>{var e=st();return W(e,()=>B().goal.text||`no goal set — the agent has nothing to auto-continue toward`),e})(),(()=>{var e=ct();return e.firstChild,W(e,I(R,{get when(){return z(()=>!!B().goal.text)()&&B().goal.status===`active`},children:` auto-continue keeps it working until this is done`}),null),W(e,I(R,{get when(){return!B().goal.text},children:` set one and tick ▶ start to begin`}),null),e})(),lt(),(()=>{var e=ut();return e.$$input=e=>{G(e.currentTarget.value),De(!0)},y(()=>e.value=we()),e})(),(()=>{var e=dt(),t=e.firstChild.nextSibling;return t.$$click=ke,e})(),ft(),I(R,{get when(){return B().latestProgress},get fallback(){return Ot()},children:e=>(()=>{var t=Nt(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return W(r,()=>e().doing),W(t,I(R,{get when(){return e().recent},get children(){var t=kt(),n=t.firstChild.nextSibling;return W(n,()=>e().recent),t}}),i),W(t,I(R,{get when(){return e().problems},get children(){var t=At(),n=t.firstChild.nextSibling;return W(n,()=>e().problems),t}}),i),W(t,I(R,{get when(){return e().next},get children(){var t=jt(),n=t.firstChild.nextSibling;return W(n,()=>e().next),t}}),i),W(t,I(R,{get when(){return e().goalStatus},get children(){var t=Mt(),n=t.firstChild.nextSibling;return W(n,()=>e().goalStatus),t}}),i),W(i,()=>Xn(e().ts)),t})()}),pt(),(()=>{var e=mt(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,W(e,()=>B().stats.turns,t),W(e,()=>B().stats.toolCalls,n),W(e,()=>B().stats.compactions??0,r),W(e,()=>Q(B().stats.inputTokens),i),W(e,()=>Q(B().stats.outputTokens),null),W(e,I(R,{get when(){return B().stats.cachedInputTokens>0},get children(){return[` · `,`cached `,z(()=>Math.round(B().stats.cachedInputTokens/Math.max(1,B().stats.inputTokens)*100)),`% (`,z(()=>Q(B().stats.cachedInputTokens)),`)`]}}),null),W(e,I(R,{get when(){return B().ctx},children:e=>[`
11
+ `,`context ~`,z(()=>Q(e().usedTokens)),` tok`,I(R,{get when(){return e().window},get children(){return[` · `,z(()=>Math.min(999,Math.round(e().usedTokens/e().window*100))),`% of `,z(()=>Q(e().window))]}}),`
12
+ `,`compaction at ~`,z(()=>Q(e().compactAt)),` tok (older turns summarized)`]}),null),e})(),ht(),I(L,{get each(){return c()},children:e=>(()=>{var t=Pt(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Ht()===e.branch?null:e.branch;Ut(t),n()&&Gt(n())},W(r,()=>e.branch,null),W(r,()=>e.branch===B().branch?` (current)`:``,null),W(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===B().branch||e.branch===Ht()?` cur`:``),i=e.branch===Ht()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&U(t,n.e=r),i!==n.t&&H(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),gt(),I(R,{get when(){return je().length>0},get fallback(){return Ft()},get children(){return I(L,{get each(){return je()},children:e=>(()=>{var t=Lt(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>J(e.agent),W(i,()=>e.id),W(a,()=>e.agent,null),W(r,I(R,{get when(){return e.forked},get children(){return It()}}),null),W(o,()=>e.schedule,s),W(o,(()=>{var t=z(()=>!!e.next);return()=>t()?Xn(e.next):`—`})(),null),W(o,(()=>{var t=z(()=>!!e.last);return()=>t()?` · last ${Xn(e.last)}`:` · never ran`})(),null),W(c,()=>$(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${$(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&U(t,r.e=i),a!==r.t&&H(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(k()?``:` right-hidden`),n=`conn`+(Yt()?` ok`:``),r=Yt()?`live (websocket)`:`reconnecting…`,a=`rightbar`+(k()?` open`:``);return t!==e.e&&U(i,e.e=t),n!==e.t&&U(l,e.t=n),r!==e.a&&H(l,`title`,e.a=r),a!==e.o&&U(S,e.o=a),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i}}),I(R,{get when(){return T()},get children(){return I($n,{get providers(){return Object.keys(_().providers??{})},onClose:()=>E(!1),onCreated:e=>{E(!1),K(),J(e)}})}}),I(R,{get when(){return D()},get children(){return I(nr,{get cfg(){return _()},onClose:()=>O(!1),onSaved:()=>{xe(),Bt()}})}}),I(R,{get when(){return me()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return I(Qn,{title:`edit prompt — forks the conversation`,onClose:()=>he(null),get children(){var t=zt(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await Z(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),he(null),K(),n()&&await J(n())}catch(e){alert(`edit failed: ${e.message}`)}}),W(t,I(R,{get when(){return r()>0},get children(){var e=Rt(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return W(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>he(null),y(()=>i.value=e().text),t}})}})]}function Kn(e){let t=e.e,n=e.res,r=t.data??{},i=String(r.name??`tool`),a=()=>n?String(n.data?.result??``):``,o=i,s=``,c=(()=>{var e=Bt();return W(e,()=>Yn(JSON.stringify(r.args??{},null,1),2e3)),e})(),l=e=>String(r.args?.[e]??``),u=(e,t=1500)=>(()=>{var n=Vt();return W(n,()=>Yn(e,t)),n})(),d=(e=4e3)=>n?[z(()=>u(a(),e)),(()=>{var e=Ht(),t=e.firstChild;return W(e,()=>n.data?.durationMs,t),W(e,()=>n.data?.ok===!1?` · FAILED`:``,null),W(e,I(Zn,{get text(){return a()}}),null),e})()]:Ut();try{switch(i){case`bash`:{let e=l(`command`);o=`$ `+$(e,96),s=l(`timeout_ms`)?`timeout ${Math.round(Number(l(`timeout_ms`))/1e3)}s`:``,c=[z(()=>z(()=>e!==o.slice(2))()?u(e,800):null),z(()=>d(6e3))];break}case`read_file`:{o=l(`path`)||`(no path)`;let e=[];l(`pattern`)&&e.push(`grep /${$(l(`pattern`),40)}/`),Number(r.args?.offset)<0?e.push(`last ${-Number(r.args.offset)} lines`):r.args?.offset&&e.push(`from L${r.args.offset}`),r.args?.limit&&e.push(`≤${r.args.limit} lines`),s=e.join(` · `),c=d(6e3);break}case`write_file`:{let e=String(r.args?.content??``);o=l(`path`)||`(no path)`,s=`${e.length} bytes`,c=[z(()=>u(e)),n?(()=>{var e=q();return W(e,()=>$(a(),160)),e})():Wt()];break}case`edit_file`:o=l(`path`)||`(no path)`,s=r.args?.replace_all===!0?`replace all`:`unique spot`,c=[(()=>{var e=Gt();return W(e,()=>Yn(`- `+l(`old_text`),900)),e})(),(()=>{var e=Kt();return W(e,()=>`+ `+Yn(l(`new_text`),900)),e})(),n?(()=>{var e=qt(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,W(e,()=>$(a(),120),t),W(e,()=>n.data?.durationMs,r),e})():Jt()];break;case`apply_patch`:{let e=l(`patch`).split(`
13
+ `).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);o=t.length?`${t.length} file${t.length>1?`s`:``}: ${$(t.join(`, `),80)}`:`patch`,c=[(()=>{var t=J();return W(t,()=>e.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Yt();return U(n,`pline`+t),W(n,(()=>{var t=z(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()})),t})(),n?(()=>{var e=q();return W(e,()=>$(a().split(`
14
+ `)[0]??``,140),null),W(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Xt()];break}case`list_dir`:o=l(`path`)||`.`,c=d(4e3);break;case`read_url`:{let e=l(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}o=$(e,70),s=`web`,c=[(()=>{var e=q();return W(e,I(R,{get when(){return/^https?:/i.test(l(`url`))},get fallback(){return(()=>{var e=Zt();return W(e,()=>$(l(`url`),80)),e})()},get children(){var e=Y();return y(()=>H(e,`href`,l(`url`))),e}})),e})(),z(()=>d(3e3))];break}case`load_skill`:{o=`skill: ${l(`name`)}`;let e=a().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);c=n?[(()=>{var t=Ve();return y(()=>t.innerHTML=Ee(e)),t})(),(()=>{var e=Ht(),t=e.firstChild;return W(e,()=>n.data?.durationMs,t),e})()]:Qt();break}case`save_skill`:{o=`skill: ${l(`name`)}`,s=$(l(`description`),60);let e=Array.isArray(r.args?.files)?r.args.files.map(e=>e?.name).filter(Boolean):[];c=[z(()=>z(()=>!!e.length)()?(()=>{var t=$t();return t.firstChild,W(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=qt(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,W(e,()=>$(a(),160),t),W(e,()=>n.data?.durationMs,r),e})():en()];break}}}catch{}return(()=>{var e=nn(),r=e.firstChild,a=r.firstChild;a.firstChild;var l=a.nextSibling;return H(e,`title`,`${i}${s?` — `+s:``}`),W(a,o,null),W(r,I(R,{get when(){return t.data?.actor},get children(){var e=tn();return e.firstChild,W(e,()=>String(t.data.actor),null),e}}),l),W(l,n?s||``:`running…`),W(e,c,null),y(()=>U(e,`embed`+(n?n.data?.ok===!1?` fail`:` done`:` running`))),e})()}function qn(e){let t=e.e,n=Bn(t),r=e.prev&&e.prev.type===t.type&&Bn(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=rn(),r=n.firstChild.nextSibling;return r.nextSibling,W(n,()=>String(e.fromBranch??`?`),r),W(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:$(String(e.text??``),80);return(()=>{var t=an(),r=t.firstChild.nextSibling;return r.nextSibling,W(t,()=>String(e.event??``),r),W(t,n,null),t})()}return t.type===`todo`?(()=>{var e=on(),n=e.firstChild.nextSibling;return n.nextSibling,W(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=sn(),n=e.firstChild;return W(e,()=>t.data.from,n),W(e,()=>t.data.to,null),W(e,(()=>{var e=z(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>U(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var i=dn(),a=i.firstChild;return W(i,I(R,{when:!r,get fallback(){return fn()},get children(){var e=cn();return W(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&ve(e,`background`,t.e=r),i!==t.t&&ve(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),W(a,I(R,{when:!r,get children(){var r=un(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return W(i,()=>n.name),W(r,I(R,{get when(){return t.data?.actor},get children(){var e=tn();return e.firstChild,W(e,()=>String(t.data.actor),null),e}}),a),W(a,(()=>{var e=z(()=>!!t.data?.pending);return()=>e()?`pending…`:Hn(t.ts)})()),W(o,()=>t.branch),W(r,I(R,{get when(){return e.onEdit},get children(){var t=ln();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>ve(i,`color`,n.color)),r}}),null),W(a,I(Jn,{e:t,get res(){return e.res},get onOption(){return e.onOption}}),null),y(()=>U(i,`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``))),i})()}function Jn(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=Ve();return y(()=>e.innerHTML=Ee(String(t.data.text??``))),e})();case`message`:return[I(R,{get when(){return z(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Be(),n=e.firstChild.nextSibling;return W(n,()=>String(t.data.reasoning)),e}}),(()=>{var e=Ve();return y(()=>e.innerHTML=Ee(String(t.data.content??``))),e})(),I(R,{get when(){return t.data.interrupted},get children(){return pn()}}),I(R,{get when(){return t.data.final},get children(){var e=mn(),n=e.firstChild;return W(e,I(Zn,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return I(Kn,{e:t,get res(){return e.res}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=hn(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return W(i,()=>$(e,120)),W(r,I(Zn,{text:e}),null),W(a,()=>Yn(e,4e3)),W(o,()=>t.data.durationMs,s),W(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>U(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=gn(),r=n.firstChild,i=r.firstChild;i.firstChild;var a=r.nextSibling;return a.firstChild,W(i,()=>$(String(t.data?.decision??``),90),null),W(a,()=>String(t.data?.rationale??``),null),W(n,I(R,{get when(){return e.length},get children(){var t=X();return t.firstChild,W(t,()=>e.join(` / `),null),t}}),null),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[];return(()=>{var r=vn(),i=r.firstChild;i.firstChild;var a=i.nextSibling;return W(i,()=>String(t.data?.question??``),null),W(r,I(R,{get when(){return n.length>0},get children(){var t=_n();return W(t,I(L,{each:n,children:t=>(()=>{var n=yn();return n.$$click=()=>e.onOption?.(t),W(n,t),n})()})),t}}),a),r})()}case`progress`:return(()=>{var e=Sn(),n=e.firstChild;return n.firstChild,W(n,()=>String(t.data.doing??``),null),W(e,I(R,{get when(){return t.data.recent},get children(){var e=q();return W(e,()=>String(t.data.recent)),e}}),null),W(e,I(R,{get when(){return t.data.problems},get children(){var e=bn();return e.firstChild,W(e,()=>String(t.data.problems),null),e}}),null),W(e,I(R,{get when(){return t.data.next},get children(){var e=xn();return e.firstChild,W(e,()=>String(t.data.next),null),e}}),null),e})();case`error`:return(()=>{var e=Cn(),n=e.firstChild;return n.firstChild,W(n,()=>String(t.data.message??``),null),e})();default:return(()=>{var e=wn();return W(e,()=>Yn(JSON.stringify(t.data),200)),e})()}}function Yn(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Xn(e){let t=new Date(e).getTime()-Date.now(),n=Math.abs(t),r=n<9e4?`${Math.round(n/1e3)}s`:n<54e5?`${Math.round(n/6e4)}m`:`${(n/36e5).toFixed(1)}h`;return t>=0?`in ${r}`:`${r} ago`}function Q(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function $(e,t){return Yn(e.replace(/\s+/g,` `).trim(),t)}function Zn(e){let[t,n]=v(!1);return(()=>{var r=Tn();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},W(r,()=>t()?`✓`:`⧉`),r})()}function Qn(e){return(()=>{var t=En(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),W(r,()=>e.title),_e(i,`click`,e.onClose,!0),W(n,()=>e.children,null),t})()}function $n(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let t=await Z(`/api/fs${e?`?path=${encodeURIComponent(e)}`:``}`);n(t.path),i(t.entries)}C(()=>p(t()));let m=async n=>{n.preventDefault(),f(``);try{let n=await Z(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return I(Qn,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=On(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,g=h.nextSibling,_=g.nextSibling,v=f.nextSibling,b=v.nextSibling,x=b.firstChild,S=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=b.nextSibling;return i.addEventListener(`submit`,m),h.$$input=e=>n(e.currentTarget.value),g.$$click=()=>p(t()),_.$$click=()=>p(`..`),W(v,I(L,{get each(){return r()},children:e=>(()=>{var n=kn();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),W(n,e,null),n})()})),S.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),W(w,I(L,{get each(){return e.providers},children:e=>(()=>{var t=Et();return W(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),W(i,I(R,{get when(){return d()},get children(){var e=Dn();return W(e,d),e}}),E),y(()=>h.value=t()),y(()=>S.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var er=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:`anthropic/claude-sonnet-4`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:`gpt-4o-mini`},{key:`ollama`,label:`Ollama (local)`,url:`http://localhost:11434/v1`,model:`qwen3-coder`}];function tr(e){let[t,n]=v(er[0]),[r,i]=v(er[0].url),[a,o]=v(``),[s,c]=v(er[0].model),[l,u]=v(`~/teapot-workspace`),[d,f]=v(``),[p,m]=v(!1),[h,g]=v(``),_=e=>{n(e),e.url&&(i(e.url),c(e.model))},b=async t=>{t.preventDefault(),g(``),m(!0);try{await Z(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:l(),...d()?{password:d()}:{}})}),e.onDone()}catch(e){g(e.message),m(!1)}};return(()=>{var e=An(),n=e.firstChild.firstChild.nextSibling.nextSibling,m=n.firstChild,g=m.nextSibling,v=g.firstChild.nextSibling,x=g.nextSibling,S=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling,E=T.firstChild.nextSibling,D=E.firstChild.nextSibling,O=E.nextSibling.firstChild.nextSibling,k=T.nextSibling;return n.addEventListener(`submit`,b),W(m,I(L,{each:er,children:e=>(()=>{var n=jn();return n.$$click=()=>_(e),W(n,()=>e.label),y(()=>U(n,`presetbtn`+(t().key===e.key?` active`:``))),n})()})),v.$$input=e=>i(e.currentTarget.value),S.$$input=e=>o(e.currentTarget.value),w.$$input=e=>c(e.currentTarget.value),D.$$input=e=>u(e.currentTarget.value),O.$$input=e=>f(e.currentTarget.value),W(n,I(R,{get when(){return h()},get children(){var e=Dn();return W(e,h),e}}),k),W(k,()=>p()?`saving…`:`finish setup`),y(()=>k.disabled=p()),y(()=>v.value=r()),y(()=>S.value=a()),y(()=>w.value=s()),y(()=>D.value=l()),y(()=>O.value=d()),e})()}function nr(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),[a,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(Math.round((e.cfg.contextTokenBudget??96e3)/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},C=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`task "${e.id}": schedule is required`);return}}try{await Z(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,a())*6e4,progressMinChars:Math.max(100,s()),contextTokenBudget:Math.max(1e3,l())*1e3,...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},w=(e,t,n,r)=>(()=>{var i=Mn(),a=i.firstChild;return H(i,`title`,r),W(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return I(Qn,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Nn(),b=v.firstChild,S=b.firstChild.nextSibling,T=S.nextSibling.firstChild.firstChild.nextSibling,E=b.nextSibling,D=E.firstChild.nextSibling,O=E.nextSibling,k=O.firstChild.nextSibling,A=O.nextSibling;A.firstChild;var j=A.nextSibling;return v.addEventListener(`submit`,C),W(b,I(L,{get each(){return t()},children:(e,r)=>(()=>{var i=Pn(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r()?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r()?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r()?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r()?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r())),y(()=>a.value=e.name),y(()=>o.value=e.baseUrl),y(()=>s.value=e.apiKey),y(()=>c.value=e.model),i})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),T.$$input=e=>i(e.currentTarget.value),W(D,()=>w(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),null),W(D,()=>w(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),null),W(D,()=>w(`compact budget (k tok)`,l(),e=>u(e),`auto-compact when estimated context exceeds this`),null),W(D,()=>w(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),W(D,()=>w(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),W(O,I(R,{get when(){return h().length>0},get children(){return I(L,{get each(){return h()},children:(e,t)=>(()=>{var n=Fn(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),k),k.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),W(A,I(L,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Ln(),n=t.firstChild,r=n.nextSibling;return W(n,()=>e.id),W(r,()=>e.workspace),W(t,I(R,{get when(){return e.parent},get children(){var t=In();return t.firstChild,W(t,()=>e.parent,null),t}}),null),t})()}),null),W(v,I(R,{get when(){return _()},get children(){var e=Dn();return W(e,_),e}}),j),y(()=>T.value=r()),v}})}ge([`click`,`input`,`keydown`]),he(()=>I(Gn,{}),document.getElementById(`root`));
15
+ //# sourceMappingURL=index-4DOCB8Mz.js.map