@timqi/pier 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/agent/config-sync.js +124 -92
  2. package/dist/db.js +5 -3
  3. package/dist/main.js +11 -4
  4. package/dist/service.js +17 -7
  5. package/dist/tasks/definitions.js +4 -0
  6. package/dist/tasks/tool.js +70 -13
  7. package/dist/web/instance.js +3 -3
  8. package/dist/web/public/assets/activity-Bv8fc5Wj.js +5 -0
  9. package/dist/web/public/assets/activity-Bv8fc5Wj.js.br +0 -0
  10. package/dist/web/public/assets/activity-Bv8fc5Wj.js.gz +0 -0
  11. package/dist/web/public/assets/boards-BRKjgEYX.js +1 -0
  12. package/dist/web/public/assets/boards-BRKjgEYX.js.br +0 -0
  13. package/dist/web/public/assets/boards-BRKjgEYX.js.gz +0 -0
  14. package/dist/web/public/assets/{code-C86xKk2k.js → code-BgAXjUH3.js} +1 -1
  15. package/dist/web/public/assets/{explorer-DTvsy5Rs.js → explorer-Cq_Ertso.js} +3 -3
  16. package/dist/web/public/assets/explorer-Cq_Ertso.js.br +0 -0
  17. package/dist/web/public/assets/explorer-Cq_Ertso.js.gz +0 -0
  18. package/dist/web/public/assets/{ghostty-web-CvSZragH.js → ghostty-web-CZHJ0YFi.js} +1 -1
  19. package/dist/web/public/assets/ghostty-web-CZHJ0YFi.js.br +0 -0
  20. package/dist/web/public/assets/ghostty-web-CZHJ0YFi.js.gz +0 -0
  21. package/dist/web/public/assets/index-BH7ir5I4.css +2 -0
  22. package/dist/web/public/assets/index-BH7ir5I4.css.br +0 -0
  23. package/dist/web/public/assets/index-BH7ir5I4.css.gz +0 -0
  24. package/dist/web/public/assets/index-BrBNzaid.js +79 -0
  25. package/dist/web/public/assets/index-BrBNzaid.js.br +0 -0
  26. package/dist/web/public/assets/index-BrBNzaid.js.gz +0 -0
  27. package/dist/web/public/assets/runs-CvdNDaw8.js +1 -0
  28. package/dist/web/public/assets/runs-CvdNDaw8.js.br +0 -0
  29. package/dist/web/public/assets/runs-CvdNDaw8.js.gz +0 -0
  30. package/dist/web/public/assets/settings-BaVwkUUD.js +6 -0
  31. package/dist/web/public/assets/settings-BaVwkUUD.js.br +0 -0
  32. package/dist/web/public/assets/settings-BaVwkUUD.js.gz +0 -0
  33. package/dist/web/public/assets/task-runs-B-eoldcU.js +3 -0
  34. package/dist/web/public/assets/task-runs-B-eoldcU.js.br +0 -0
  35. package/dist/web/public/assets/task-runs-B-eoldcU.js.gz +0 -0
  36. package/dist/web/public/assets/tasks-CT4LECPQ.js +4 -0
  37. package/dist/web/public/assets/tasks-CT4LECPQ.js.br +0 -0
  38. package/dist/web/public/assets/tasks-CT4LECPQ.js.gz +0 -0
  39. package/dist/web/public/assets/terminal-C0qFDFou.js +2 -0
  40. package/dist/web/public/assets/terminal-C0qFDFou.js.br +0 -0
  41. package/dist/web/public/assets/terminal-C0qFDFou.js.gz +0 -0
  42. package/dist/web/public/index.html +16 -16
  43. package/dist/web/public/index.html.br +0 -0
  44. package/dist/web/public/index.html.gz +0 -0
  45. package/docs/deploy.md +20 -8
  46. package/package.json +1 -1
  47. package/skills/pier-tasks/SKILL.md +20 -11
  48. package/dist/web/public/assets/activity-Cw0LRVNI.js +0 -5
  49. package/dist/web/public/assets/activity-Cw0LRVNI.js.br +0 -0
  50. package/dist/web/public/assets/activity-Cw0LRVNI.js.gz +0 -0
  51. package/dist/web/public/assets/boards-DMVbV84c.js +0 -1
  52. package/dist/web/public/assets/boards-DMVbV84c.js.br +0 -0
  53. package/dist/web/public/assets/boards-DMVbV84c.js.gz +0 -0
  54. package/dist/web/public/assets/explorer-DTvsy5Rs.js.br +0 -0
  55. package/dist/web/public/assets/explorer-DTvsy5Rs.js.gz +0 -0
  56. package/dist/web/public/assets/ghostty-web-CvSZragH.js.br +0 -0
  57. package/dist/web/public/assets/ghostty-web-CvSZragH.js.gz +0 -0
  58. package/dist/web/public/assets/index-DHxoYoeq.js +0 -79
  59. package/dist/web/public/assets/index-DHxoYoeq.js.br +0 -0
  60. package/dist/web/public/assets/index-DHxoYoeq.js.gz +0 -0
  61. package/dist/web/public/assets/index-DuZ2vERd.css +0 -2
  62. package/dist/web/public/assets/index-DuZ2vERd.css.br +0 -0
  63. package/dist/web/public/assets/index-DuZ2vERd.css.gz +0 -0
  64. package/dist/web/public/assets/runs-jY40JBP-.js +0 -1
  65. package/dist/web/public/assets/runs-jY40JBP-.js.br +0 -0
  66. package/dist/web/public/assets/runs-jY40JBP-.js.gz +0 -0
  67. package/dist/web/public/assets/settings-Dux7PIKF.js +0 -6
  68. package/dist/web/public/assets/settings-Dux7PIKF.js.br +0 -0
  69. package/dist/web/public/assets/settings-Dux7PIKF.js.gz +0 -0
  70. package/dist/web/public/assets/task-runs-DKvtBVxS.js +0 -3
  71. package/dist/web/public/assets/task-runs-DKvtBVxS.js.br +0 -0
  72. package/dist/web/public/assets/task-runs-DKvtBVxS.js.gz +0 -0
  73. package/dist/web/public/assets/tasks-CqfrOVIt.js +0 -4
  74. package/dist/web/public/assets/tasks-CqfrOVIt.js.br +0 -0
  75. package/dist/web/public/assets/tasks-CqfrOVIt.js.gz +0 -0
  76. package/dist/web/public/assets/terminal-DL_0yEy7.js +0 -2
  77. package/dist/web/public/assets/terminal-DL_0yEy7.js.br +0 -0
  78. package/dist/web/public/assets/terminal-DL_0yEy7.js.gz +0 -0
@@ -0,0 +1,6 @@
1
+ import{A as e,D as t,E as n,H as r,J as i,K as a,L as o,M as s,N as c,O as l,P as u,S as d,T as f,V as p,_ as m,b as h,c as g,f as _,g as v,h as y,j as b,l as x,m as S,o as C,p as w,r as T,t as E,v as D,w as O,x as k,y as A}from"./index-BrBNzaid.js";import{n as j,t as M}from"./code-BgAXjUH3.js";var N={display_information:{name:`Pier`,description:`Coding agent sessions in Slack threads`,background_color:`#262626`},features:{bot_user:{display_name:`Pier`,always_online:!1},app_home:{messages_tab_enabled:!0,messages_tab_read_only_enabled:!1}},oauth_config:{scopes:{bot:[`chat:write`,`reactions:write`,`channels:history`,`channels:read`,`groups:history`,`groups:read`,`im:history`,`im:write`,`mpim:history`,`mpim:read`,`mpim:write`,`users:read`,`files:read`,`files:write`]}},settings:{event_subscriptions:{bot_events:[`message.channels`,`message.groups`,`message.im`,`message.mpim`]},interactivity:{is_enabled:!0},socket_mode_enabled:!0,token_rotation_enabled:!1}},P=()=>`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(JSON.stringify(N))}`,F=()=>h(`Getting a bot token`,[`Open [@BotFather](https://t.me/BotFather) in Telegram.`,"Send `/newbot`, pick a display name, then a username ending in `bot`.","Copy the token it prints (`123456789:AA…`) and paste it here.","Send `/setprivacy` → `Disable` if the bot should see plain group messages. Left enabled it only ever receives mentions, replies and commands — the usual reason a bot looks dead in a group.","Send `/setjoingroups` → `Enable`, then add the bot to your group or forum."]),I=(e=`left`)=>h(`Enabling topics on a group`,["In Telegram open the group → `Edit` → turn on `Topics`. Owner only; group size no longer matters.","The group becomes a forum supergroup and the existing chat becomes its `General` topic.","Make the bot an admin with `Manage Topics`. That is the one right topic creation needs — without it Pier logs the failure and answers in General instead.","Send one message in the group so Pier discovers it, then enable it under `Chats` below.","After that, a message in General opens its own topic with its own session. A reply, or anything starting with `/`, stays where it was sent."],e);function L(){let t=v(`Create Slack app ↗`,!0);t.classList.add(`mt-1`,`w-fit`),t.onclick=()=>window.open(P(),`_blank`,`noreferrer`);let n=u(`btn w-fit text-[12.5px]`,()=>JSON.stringify(N,null,2));return h(`Creating a Slack app`,[e(`Opens Slack with every scope, event and Socket Mode already filled in. Pick your workspace → Create.`,t),"`Install to Workspace` → allow. Then `OAuth & Permissions` → copy the bot token (`xoxb-…`) into the field above.","`Basic Information` → `App-Level Tokens` → `Generate` with scope `connections:write`. Paste that `xapp-…` token below. The manifest cannot mint this one for you.","In Slack, invite the bot where you want it: `/invite @Pier`. It answers in threads only, so it never adds noise to the channel.",e(`Prefer to paste it yourself? Create the app from a manifest and use this:`,n)])}var R=()=>h(`What agent access allows`,["Gives agent sessions a `slack` tool: read a channel's history for a time range, read one thread, and post, edit or delete a message.",`Editing and deleting reach only what Pier's own bot posted — Slack refuses either on anyone else's message.`,`Pier performs every call itself — the bot token is never given to the agent, and Slack's own membership rules still apply, so the bot reaches only channels it was invited to.`,`Every read fetches live from Slack — Pier keeps no message archive.`,`This includes sessions started by tasks and subagents. Switch it off if an agent should never post to your workspace on its own.`,`The tool is only given to sessions opened while Slack is connected and this is on, so an unused tool costs no context. A session opened earlier keeps it, and a call made after you switch it off is refused with the reason.`]),z=(e=`left`)=>h(`How Slack threads work here`,[`Pier never posts in a channel's main flow. A message in the channel is answered in *its own thread*; a message in a thread is answered in that thread.`,`Each thread is its own Pi session, so one channel hosts many parallel sessions.`,`The same applies in a DM: every new message you send there starts its own thread and its own session. Reply *inside* a thread to continue that conversation.`,"Inside a thread Pier already owns, no `@mention` is needed — continuing that thread is addressing it.","Commands are bare words after a mention: `@bot settings`, `@bot stop`, `@bot bind <code>`. Slack's client swallows an unregistered `/command` before it ever reaches an app."],e),ee=()=>h(`Creating a Feishu app`,["On [open.feishu.cn](https://open.feishu.cn/app) create a 企业自建应用 (custom app). `Credentials & Basic Info` shows the App ID (`cli_…`) and App Secret — paste both here.","`Add Features` → enable **Bot** (机器人).","`Permissions` (权限管理), add: `im:message` (read messages), `im:message:send_as_bot` (send), `im:resource` (attachments, both directions), `im:message.reactions:create` + `:read` + `:delete` (the 👀 receipt), `im:chat:readonly` (chat names for this page), `contact:user.base:readonly` (speaker names).","`Events & Callbacks` → set the mode to **长连接 (long connection)** — no public URL needed. Under Events subscribe `im.message.receive_v1` (接收消息); Callbacks gain `card.action.trigger` automatically once cards are sent, add it if listed.",`**Publish a version** (版本管理与发布 → 创建版本 → 申请发布). Nothing above takes effect until this is approved — the usual reason a configured bot stays silent.`,`Add the bot to a group (群设置 → 群机器人), or DM it directly.`]),B=(e=`left`)=>h(`How Lark topics work here`,[`Pier never posts in a chat's main flow. A message in the chat is answered in *its own topic* (话题); a message inside a topic is answered there.`,`Each topic is its own Pi session, so one group hosts many parallel sessions.`,`The same applies in a DM: every new message starts its own topic and its own session. Reply *inside* a topic to continue that conversation.`,`Inside a topic Pier already owns, no @mention is needed — continuing that topic is addressing it.`,"Commands are slash words: `/stop`, `/settings`, `/bind <code>`. A bare @mention with nothing else also opens the settings panel."],e),V=[[`telegram`,`Telegram`],[`slack`,`Slack`],[`lark`,`Lark`]],H=(e,t)=>o(`span`,`flex items-center gap-1.5 text-[13px] text-neutral-400`,o(`span`,``,e),t),te={dm:`bg-sky-50 text-sky-700 ring-sky-200`,group:`bg-neutral-100 text-neutral-600 ring-neutral-200`,forum:`bg-violet-50 text-violet-700 ring-violet-200`},U=`pier.channelsPlatform`;function ne(e){let t=localStorage.getItem(U),i=V.some(([e])=>e===t)?t:`telegram`,s=null,u=[],f=o(`div`,`ml-auto flex items-center gap-1.5 text-[11.5px]`),p=o(`div`,`sticky top-0 z-30 flex items-center gap-1 border-b border-neutral-200 bg-white px-4 py-2`,f),h=o(`div`,`px-4 py-5`);e.append(o(`div`,`min-h-0 flex-1 overflow-y-auto bg-neutral-50/60`,p,h));function g(){p.replaceChildren(...V.map(([e,t])=>d(t,e===i,()=>{_&&M(),i=e,localStorage.setItem(U,e),N()})),f)}let _,b=!1,x=null;function C(e){if(f.replaceChildren(),e!==`clean`){if(f.className=`ml-auto flex items-center gap-1.5 text-[11.5px] ${w[e]}`,e===`saving`)f.append(o(`span`,`spinner`),o(`span`,``,`Saving…`));else if(e===`saved`)f.append(o(`span`,``,`✓`),o(`span`,``,`Saved`)),setTimeout(()=>{f.textContent?.includes(`Saved`)&&C(`clean`)},2e3);else{let e=y(`Retry`,`cursor-pointer underline`);e.onclick=M,f.append(o(`span`,``,`⚠`),o(`span`,``,`Save failed`),e)}}}function O(){C(`saving`),clearTimeout(_),_=setTimeout(M,500)}let k=e=>t=>{e(t),O()};async function j(e){b=!0,C(`saving`);try{C((await a(`/api/channels/${e.platform}`,e.config,`PUT`)).ok?`saved`:`failed`)}catch{C(`failed`)}finally{b=!1;let e=x;x=null,e&&j(e)}}function M(){if(clearTimeout(_),_=void 0,!s)return;let e={platform:i,config:s};b?x=e:j(e)}async function N(){if(!u.length){let e=await r(`/api/models`,`Could not load the model catalog`);e.ok&&(u=e.value)}let e=await r(`/api/channels/${i}`,`Failed to load`);if(!e.ok){s=null,g(),h.replaceChildren(D(e.error));return}s=e.value,C(`clean`),W()}function P(e){let t=i===`slack`,r=i===`lark`,a=n(e.token,t?`xoxb-…`:r?`cli_…`:`123456789:AA…`,k(t=>e.token=t),!0),o=n(e.appToken,r?``:`xapp-…`,k(t=>e.appToken=t),!0),s=E(e.cwd,`(pier process cwd)`,k(t=>e.cwd=t));return m(`Connection`,t?`Pier connects over Socket Mode; no public URL or webhook needed.`:r?`Pier connects over Feishu's WebSocket long connection; no public URL or webhook needed.`:`Pier polls Telegram for updates; no public URL or webhook needed.`,l(`Enabled`,`Start the adapter when Pier boots.`,e.enabled,k(t=>{e.enabled=t,g()})),A(r?`App ID`:`Bot token`,a,{hint:`Stored locally, shown masked once saved.`,help:i===`telegram`?F():t?L():ee()}),...t?[A(`App-level token`,o,{hint:`Opens the Socket Mode connection. Needs connections:write.`}),l(`Agent access`,`Let agent sessions read channel history and post through the slack tool. Off makes the tool refuse; inbound messages are unaffected.`,e.agentTool,k(t=>e.agentTool=t),R())]:[],...r?[A(`App Secret`,o,{hint:`From Credentials & Basic Info, beside the App ID.`})]:[],A(`Default working directory`,s.el,{hint:`Where sessions this channel opens start.`}))}function ne(e){return m(`Defaults for new chats`,`Copied into a group the first time the bot sees it; changing them here never touches a group that already exists. DMs are always bound-users-only.`,l(`Require mention in groups`,`Ignore group messages that do not @mention or reply to the bot.`,e.requireMention,k(t=>e.requireMention=t)),l(`Require bound user`,`Only users bound with a code below can drive the agent.`,e.requireBind,k(t=>e.requireBind=t)),...i===`slack`?[H(`Thread mode: always on`,z())]:i===`lark`?[H(`Thread mode: always on`,B())]:[l(`Topic mode`,`In a forum group, each new request opens its own topic and its own session.`,e.topicMode,k(t=>e.topicMode=t),I())],T(`Model & reasoning`,e,u,k(t=>{e.model=t.model,e.thinking=t.thinking,W()})))}function re(e){let t=o(`span`,`font-mono text-[15px] font-semibold tracking-widest`),n=o(`div`,`hidden items-center gap-2 rounded-lg bg-indigo-50 px-3 py-2 text-[12.5px] text-indigo-800`,t,o(`span`,`text-[11.5px] text-indigo-500`,`DM the bot /bind <code> · expires in 10 min`)),r=v(`Generate bind code`);r.onclick=async()=>{let e=await fetch(`/api/channels/${i}/bind-code`,{method:`POST`});if(!e.ok)return;let{code:r}=await e.json();t.textContent=r,n.classList.replace(`hidden`,`flex`)};let a=o(`div`,`flex flex-col`);e.users.length||a.append(D(`No bound users yet.`));for(let t of e.users){let e=y(`Remove`,`cursor-pointer text-[11.5px] text-neutral-400 opacity-0 transition-opacity hover:text-red-600 group-hover:opacity-100`);e.onclick=async()=>{await fetch(`/api/channels/${i}/users/${encodeURIComponent(t.id)}`,{method:`DELETE`}),await N()},a.append(o(`div`,`group flex items-center gap-2.5 border-b border-neutral-100 py-2 last:border-0`,o(`span`,`flex h-6 w-6 flex-none items-center justify-center rounded-full bg-neutral-100 text-[11px] font-semibold text-neutral-500`,(t.name[0]??`?`).toUpperCase()),o(`span`,`min-w-0 flex-1 truncate text-[13px] text-neutral-700`,t.name),o(`span`,`flex-none font-mono text-[11.5px] text-neutral-400`,t.id),e))}return m(`Bound users`,`A code is single-use and expires; redeeming it in a DM binds that account.`,a,o(`div`,`flex flex-col gap-2`,r,n))}function ie(e,t){let n=o(`div`,`rounded-xl border px-3.5 py-3 transition-colors ${t.enabled?`border-neutral-200 bg-white`:`border-neutral-200 bg-neutral-50/60`}`),r=o(`div`,`flex items-center gap-2`,o(`span`,`min-w-0 flex-1 truncate text-[13px] font-medium ${t.enabled?`text-neutral-800`:`text-neutral-400`}`,t.name||t.id),S(t.kind,te[t.kind]),o(`span`,`flex-none font-mono text-[11px] text-neutral-400`,t.id)),a=l(``,``,t.enabled,k(e=>{t.enabled=e,W()}));a.classList.add(`flex-none`,`items-center`),r.append(a);let s=o(`div`,`mt-3 flex flex-wrap items-center gap-x-6 gap-y-2`);t.kind===`dm`?s.append(o(`span`,`text-[13px] text-neutral-400`,i===`telegram`?`Direct message · bound users only, mention and topics not applicable`:`Direct message · bound users only, mention not applicable`)):s.append(l(`Require mention`,``,t.requireMention,k(e=>t.requireMention=e)),l(`Require bind`,``,t.requireBind,k(e=>t.requireBind=e)),i===`slack`?H(`Thread mode: always on`,z(`right`)):i===`lark`?H(`Thread mode: always on`,B(`right`)):t.kind===`forum`?l(`Topic mode`,``,t.topicMode,k(e=>t.topicMode=e),I(`right`)):H(`Topic mode: forum groups only`,I(`right`)));let c=E(t.cwd,``,k(e=>t.cwd=e)),d=o(`div`,`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2`,A(`Working directory`,c.el),T(`Model & reasoning`,t,u,k(e=>{t.model=e.model,t.thinking=e.thinking,W()})));return n.append(r,s,d),n}function ae(e){let t=o(`div`,`flex flex-col gap-2.5`);return e.chats.length?t.append(...e.chats.map(t=>ie(e,t))):t.append(D(`None yet. Chats appear here after the bot sees a message in them.`)),m(i===`slack`?`Channels`:`Chats`,`Discovered from inbound traffic — no platform reliably lists every chat a bot is in.`,t)}function W(){if(!s)return;g();let e=o(`div`,`mx-auto flex max-w-3xl flex-col gap-4`);e.append(P(s),ne(s),re(s),ae(s)),h.replaceChildren(e)}return c(e,()=>void N(),()=>{_&&M()})}function re(){let e=o(`div`,`min-h-0 min-w-0 flex-1 overflow-y-auto p-4`),t=o(`div`,`mx-auto flex max-w-3xl min-w-0 flex-col gap-4`),i=o(`p`,`text-[12px] break-words`),s=o(`section`,`flex min-w-0 flex-col gap-3 border-b border-neutral-200 pb-4`),c=o(`section`,`flex min-w-0 flex-col gap-3`);t.append(o(`h2`,`text-[14px] font-semibold text-neutral-700`,`Configuration sync`),i,s,c),e.append(t);let d=null,m=!1,h=!1,g=0,_=``,y=!1,b=e=>e?new Date(e).toLocaleString():`Never`;async function x(){let e=g,t=await r(`/api/config-sync`,`Could not load configuration sync`,{cache:`no-store`});if(!(h||e!==g)){if(!t.ok){f(i,`failed`,t.error);return}d=t.value,y||(_=d.sourceUrl),w()}}async function S(e){if(!m){++g,m=!0,w(),f(i,`saving`,`Working...`);try{let t=await a(`/api/config-sync`,{action:e,...e===`subscribe`?{url:_}:{}});if(!t.ok)throw Error(await p(t,`Configuration sync failed`));let n=await t.json();d=n,y=!1,_=n.sourceUrl,f(i,`saved`,n.result??`Saved`)}catch(e){f(i,`failed`,e instanceof Error?e.message:`Configuration sync failed`),await x()}finally{m=!1,h||w()}}}function C(e,t){let n=v(e);return n.disabled=m,n.onclick=()=>{S(t)},n}function w(){if(!d||h)return;if(s.replaceChildren(o(`h3`,`text-[13px] font-medium text-neutral-700`,`Publish`)),d.publishedPath){let e=`${d.publicUrl||window.location.origin}${d.publishedPath}`,t=n(e,``,()=>{},!0);t.readOnly=!0,t.setAttribute(`aria-label`,`Sharing URL`),s.append(t,o(`div`,`flex flex-wrap items-center gap-2`,u(`btn text-[12px]`,()=>e),C(`Revoke link`,`revoke`)))}else s.append(o(`div`,``,C(`Generate link`,`publish`)));s.append(o(`p`,`text-[12px] text-neutral-500`,`Anyone with the link can read shared prompts and model definitions. API keys, headers and endpoints stay private.`));let e=n(_,`https://example.com/config-sync/...`,e=>{_=e,y=!0},!0);e.type=`url`,e.setAttribute(`aria-label`,`Configuration source URL`),e.disabled=m||d.enabled;let t=l(`Automatic sync`,``,d.enabled,e=>{S(e?`subscribe`:`pause`)});t.querySelector(`input`).disabled=m;let r=o(`div`,`flex flex-wrap items-center gap-3`,t);d.enabled&&r.append(C(`Sync now`,`sync`)),c.replaceChildren(o(`h3`,`text-[13px] font-medium text-neutral-700`,`Source`),A(`Source URL`,e),r);let i=o(`dl`,`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1 text-[12px]`);for(let[e,t]of[[`Last checked`,b(d.lastChecked)],[`Last applied`,b(d.lastApplied)],[`Next check`,d.enabled?b(d.nextRunAt):`Paused`]])i.append(o(`dt`,`text-neutral-500`,e),o(`dd`,`min-w-0 break-words text-neutral-700`,t));if(c.append(i),d.error&&c.append(o(`p`,`text-[12px] break-words text-red-600`,d.error)),d.needsReload&&c.append(o(`p`,`text-[12px] text-amber-700`,`Reload pending; retry synchronization.`)),d.taskId){let e=o(`a`,`text-[12px] text-indigo-600 hover:underline`,`Sync task history`);e.href=`#/tasks/${encodeURIComponent(d.taskId)}`,c.append(e)}}x();let T=setInterval(()=>{!m&&!y&&x()},15e3);return{el:e,dispose:()=>{h=!0,clearInterval(T)}}}async function ie(e,t){let n;try{n=await a(`/api/settings`,e,`PUT`)}catch(e){return{outcome:{state:`failed`,text:`Could not save: ${String(e)}`}}}if(!n.ok)return{outcome:{state:`failed`,text:await p(n,`could not save`)}};let r;try{r=await n.json()}catch(e){return{outcome:{state:`failed`,text:`Saved, but the answer could not be read: ${String(e)}`}}}return r.toolsSync?.state===`refused`?{outcome:{state:`failed`,text:`Saved, but nothing will install it: ${r.toolsSync.reason}`},answer:r}:r.toolsSync?.state===`waiting`?{outcome:{state:`saved`,text:`Saved — a sync is already running; this change goes in the run right after it.`},answer:r}:{outcome:{state:`saved`,text:t},answer:r}}function ae(e,t){return e.enabled?{body:{tool:{name:e.name,on:!1}},saved:`Switched ${e.name} off — the next run uninstalls it. Remove it again once its binary is gone.`}:{body:{customTools:t.filter(t=>t.name!==e.name)},saved:`Removed ${e.name}.`}}function W(e,t){let i=`global`,u=null,d=0,m=0,h=``,g=null,v=[],y=``,b=null,C=null,w=()=>{C?.dispose(),C=null},T=()=>{w(),++m,C=re(),L.replaceChildren(C.el)},E=[],D=()=>v.filter(e=>e.kind===`extension`),O=e=>e.source===`binary`&&e.custom===!0,k=()=>v.filter(e=>e.kind===`tool`),N=document.createElement(`select`);N.className=`select w-full rounded-md border border-neutral-300 px-2 py-1 text-[12.5px] focus:border-indigo-400 focus:outline-none`,N.onchange=()=>{w(),i=N.value,u=null,K.clear(),te()};let P=o(`div`,`flex flex-none flex-col gap-1 border-b border-neutral-200 px-3 pb-2.5 pt-2`);P.append(o(`span`,`text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,`Scope`),N);let F=o(`div`,`min-h-0 flex-1 overflow-y-auto py-1`),I=o(`nav`,`flex w-64 flex-none flex-col border-r border-neutral-200 text-[13px] max-md:max-h-48 max-md:w-full max-md:border-r-0 max-md:border-b`);I.append(P,F);let L=o(`div`,`flex min-w-0 flex-1 flex-col`),R=o(`div`,`flex min-h-0 flex-1 max-md:flex-col`);R.append(I,L),e.append(R);let z=(e=``)=>`?scope=${encodeURIComponent(i)}${e}`;async function ee(){if(i!==`global`){v=[],y=``;return}let e=await r(`/api/settings`,`could not be loaded`,{cache:`no-store`});if(!e.ok){v=[],y=e.error;return}B(e.value),y=``}function B(e){v=e.catalog,E=e.customTools,b=e.toolsTaskId}async function V(e,t){let{outcome:n,answer:r}=await ie(e,t);return r&&(B(r),J(g)),n}function H(e,t){let n={name:e,on:t};return v.find(t=>t.name===e)?.source===`binary`?{tool:n}:{extension:n}}async function te(){let e=++d;m++;let[t]=await Promise.all([r(`/api/config${z()}`,`failed to load config`,{cache:`no-store`}),ee()]);if(e!==d)return;if(!t.ok){J(null),Y(t.error);return}let n=t.value;i===`global`&&n.dir&&(h=n.dir,pe()),g=n,J(n),u?u.type===`sync`&&T():se()}function U(e){return o(`div`,`px-3 pb-0.5 pt-2.5 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e)}let ne=()=>{let e=o(`span`,`flex-none rounded bg-neutral-100 px-1 text-[10px] font-semibold uppercase tracking-wide text-neutral-500`,`link`);return e.title=`Reached through a symlink`,e},W=()=>o(`span`,`flex-none rounded bg-emerald-50 px-1 text-[10px] font-semibold uppercase tracking-wide text-emerald-700`,`on`);function G(e,t,n,r,i=0,a){let s=o(`button`,`flex w-full cursor-pointer items-center gap-1.5 py-1 pr-3 text-left hover:bg-neutral-100 ${t?`bg-indigo-50 hover:bg-indigo-50`:``} ${n?`text-neutral-400`:``}`);return s.append(o(`span`,`truncate`,e)),a&&s.append(a),s.style.paddingLeft=`${20+i*14}px`,s.title=e,s.onclick=r,s}function oe(e){let t={files:[],dirs:new Map,link:!0};for(let n of e){let e=n.name.split(`/`),r=t;for(let t of e.slice(0,-1)){let e=r.dirs.get(t);e||r.dirs.set(t,e={files:[],dirs:new Map,link:!0}),e.link&&=n.link,r=e}r.files.push({name:e[e.length-1],link:n.link})}return t}let K=new Set;function q(e,t,n,r,i,a){let s=[];for(let[c,l]of t.dirs){let t=n?`${n}/${c}`:c,u=`${e}:${t}`,d=document.createElement(`details`);d.open=K.has(u),d.ontoggle=()=>d.open?K.add(u):K.delete(u);let f=o(`summary`,`flex cursor-pointer select-none items-center gap-1 truncate py-1 pr-3 hover:bg-neutral-100`);f.style.paddingLeft=`${20+r*14}px`,f.title=t,f.append(o(`span`,`chev`,`▶`),o(`span`,`truncate text-neutral-600`,c)),l.link&&f.append(ne()),d.append(f,...q(e,l,t,r+1,i,a)),s.push(d)}for(let o of t.files){let t={type:`resource`,kind:e,name:n?`${n}/${o.name}`:o.name};s.push(G(o.name,i(t),!1,()=>a(t),r,o.link?ne():void 0))}return s}function J(e){if(!e){F.replaceChildren();return}let t=e=>JSON.stringify(e)===JSON.stringify(u),n=t=>{w(),u=t,J(e),t.type===`file`?ce(t.name):t.type===`bundled`?ue(t.name):t.type===`tools`?$():t.type===`sync`?T():fe(t.kind,t.name)},r=[];if(i===`global`){let e={type:`sync`};r.push(U(`Instance`),G(`Configuration sync`,t(e),!1,()=>n(e)))}r.push(U(`Files`));for(let i of e.files){let e={type:`file`,name:i.name};r.push(G(i.name,t(e),!i.exists,()=>n(e)))}if(i===`global`){r.push(U(`bundled with Pier`)),y?r.push(o(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-red-600`,y)):D().length||r.push(o(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-neutral-400`,`none`));for(let e of D()){let i={type:`bundled`,name:e.name};r.push(G(e.name,t(i),!1,()=>n(i),0,e.enabled?W():void 0))}if(!y){let e={type:`tools`},i=k().filter(e=>e.enabled).length;r.push(G(`command-line tools`,t(e),!1,()=>n(e),0,i?W():void 0))}}for(let i of[`extensions`,`skills`]){r.push(U(`${i} (read-only)`));let a=e.resources[i];a.length||r.push(o(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-neutral-400`,`none`)),r.push(...q(i,oe(a),``,0,t,n))}F.replaceChildren(...r)}function se(){L.replaceChildren(o(`p`,`px-4 py-3 text-[13px] text-neutral-400`,`Select a file to edit, or browse extensions and skills.`))}function Y(e){L.replaceChildren(o(`p`,`px-4 py-3 text-[13px] text-red-600`,e))}let X=(e,...t)=>o(`div`,`flex flex-none items-center gap-3 border-b border-neutral-200 px-4 py-2`,o(`span`,`font-mono text-[12.5px] text-neutral-500`,e),...t);async function ce(e){let t=++m,n=await r(`/api/config/files/${encodeURIComponent(e)}${z()}`,`failed to load ${e}`,{cache:`no-store`});if(!n.ok){t===m&&Y(n.error);return}if(t!==m)return;let{content:i}=n.value,s=i,c=o(`span`,`text-[11.5px] text-neutral-400`,``),l=o(`button`,`btn btn-primary ml-auto text-[12.5px]`,`Save`),u=document.createElement(`textarea`);u.className=`block min-h-0 flex-1 resize-none bg-white p-4 font-mono text-[13px] leading-relaxed focus:outline-none`,u.spellcheck=!1,u.value=i;let d=async()=>{if(l.disabled)return;let t=u.value;l.disabled=!0,f(c,`saving`,`saving…`);try{let n=await a(`/api/config/files/${encodeURIComponent(e)}${z()}`,{content:t,expected:s},`PUT`);if(!n.ok)return f(c,`failed`,await p(n,`save failed`));let r=await n.json();s=r.content,u.value===t?(u.value=r.content,f(c,`saved`,`saved — applies to new sessions`)):f(c,`idle`,`saved; newer changes are unsaved`)}catch(e){f(c,`failed`,`save failed: ${String(e)}`)}finally{l.disabled=!1}};l.onclick=()=>void d(),u.onkeydown=e=>{(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),d())},u.oninput=()=>{f(c,`idle`,`unsaved changes`)},L.replaceChildren(X(e,c,l),u),u.focus()}function le(e){if(!b)return null;let t=o(`a`,`text-indigo-600 hover:underline`,e);return t.href=`#/tasks/${encodeURIComponent(b)}`,t}let Z=()=>{let e=o(`a`,`text-indigo-600 hover:underline`,`ubix`);return e.href=`https://github.com/timqi/ubix`,e.target=`_blank`,e.rel=`noreferrer`,e};function Q(e){if(e.source!==`binary`)return``;let{spec:t,error:n,installed:r,version:i,path:a}=e.binary;return n?`${t} — ${n}`:r?`${t} — ${i??`unknown version`} at ${a??`an unknown path`}`:`${t} — not installed`}function ue(e,t){m++;let n=v.find(t=>t.name===e&&t.kind===`extension`);if(!n)return Y(`unknown extension: ${e}`);let r=o(`span`,`text-[11.5px] text-neutral-400`,``);t&&f(r,t.state,t.text);let i=le(`every run of the update task`);L.replaceChildren(X(n.name,o(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,n.source===`binary`?`installed by Pier`:`ships with Pier`)),o(`div`,`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4`,o(`p`,`max-w-2xl text-[13px] leading-relaxed text-neutral-600`,n.summary),o(`dl`,`flex max-w-2xl flex-col gap-1.5`,...(n.source===`bundled`?n.adds:[]).flatMap(e=>[o(`dt`,`font-mono text-[12px] text-neutral-700`,e.name),o(`dd`,`text-[12px] leading-snug text-neutral-500`,`needs ${e.needs}`)]),...n.source===`binary`?[o(`dt`,`font-mono text-[12px] text-neutral-700`,`binary`),o(`dd`,`font-mono text-[12px] leading-snug ${n.binary.error?`text-red-600`:`text-neutral-500`}`,Q(n))]:[]),l(`Enabled`,n.source===`binary`?`Installed into Pier's own bin directory, first on the PATH every session, task and terminal inherits; it registers its own Pi extension. Switching it off uninstalls both.`:`Loaded from inside Pier — nothing is installed and no update touches your own extensions. A session mid-turn keeps the tools it started with; the next message picks this up.`,n.enabled,t=>void de(n.name,t,t=>ue(e,t))),o(`p`,`max-w-2xl text-[12px] leading-snug text-neutral-400`,...n.source===`binary`?i?[`A daily task installs and updates it — its history is `,i,`.`]:[`Its installs run as the daily update task.`]:[`An extension of your own that registers the same tool wins: this copy stands down and says so in the log.`]),r))}function $(e,t={name:``,toml:``}){m++;let r=o(`span`,`text-[11.5px] text-neutral-400`,``);e&&f(r,e.state,e.text);let i=k(),a=le(`the update task`),s=e=>{let t=o(`div`,`flex min-w-0 flex-1 flex-col gap-0.5`,o(`span`,`flex items-center gap-2 text-[13px] text-neutral-700`,o(`span`,`font-mono`,e.name),...O(e)?[S(`yours`,`bg-neutral-50 text-neutral-500 ring-neutral-200`)]:[]),o(`span`,`text-[11.5px] leading-snug text-neutral-400`,e.summary||Q(e)),...e.summary?[o(`span`,`font-mono text-[11px] leading-snug ${e.source===`binary`&&e.binary.error?`text-red-600`:`text-neutral-400`}`,Q(e))]:[]),n=l(``,``,e.enabled,t=>void de(e.name,t,e=>$(e))),r=o(`button`,`btn text-[12px] text-neutral-500 hover:text-red-600`,`Remove`);return r.onclick=()=>{r.disabled=!0;let t=ae(e,E);V(t.body,t.saved).then(e=>$(e))},o(`div`,`flex max-w-2xl items-start gap-3 border-b border-neutral-100 py-2.5 last:border-0`,t,...O(e)?[r]:[],n)},c={...t},u=o(`span`,`font-mono text-[12px] text-neutral-500`,`[tools.<name>]`),d=n(c.name,`claude`,e=>{c.name=e,u.textContent=`[tools.${e.trim()||`<name>`}]`},!0),p=document.createElement(`textarea`);p.className=`${_} h-24 resize-y font-mono leading-snug`,p.spellcheck=!1,p.value=c.toml,p.placeholder=`spec = "github:owner/repo"
2
+ exe = "tool"`,p.oninput=()=>c.toml=p.value;let h=o(`button`,`btn btn-primary text-[12.5px]`,`Add`);h.onclick=()=>{let e={name:c.name.trim(),toml:c.toml.trim()};if(!e.name||!e.toml)return f(r,`failed`,`A custom tool needs a name and a block with a spec line.`);h.disabled=!0,V({customTools:[...E,e],tool:{name:e.name,on:!0}},`Added ${e.name} — installing now.`).then(e=>$(e,e.state===`failed`?c:void 0))},L.replaceChildren(X(`command-line tools`,o(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,`installed by Pier`)),o(`div`,`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4`,o(`p`,`max-w-2xl text-[12.5px] leading-relaxed text-neutral-500`,`Pier writes no downloader: `,Z(),` does the work — a declarative installer that resolves a spec like `,o(`span`,`font-mono text-[11.5px]`,`github:owner/repo`),` to the right release asset for this machine, verifies it, and upgrades in place. Pier bootstraps it, generates its config from the switches below, and keeps its files under Pier's own directory — your own ubix setup is untouched.`),y?o(`p`,`max-w-2xl text-[12.5px] text-red-600`,y):o(`div`,`flex max-w-2xl flex-col`,...i.map(s)),o(`div`,`flex max-w-2xl flex-col gap-2 border-t border-neutral-200 pt-4`,o(`span`,`text-[12.5px] font-medium text-neutral-600`,`Add one of your own`),A(`Name`,d),A(`The block Pier writes under the header`,p,{hint:`A line that opens a section of its own is refused, because it could rewrite the rest of the file.`}),o(`div`,`flex items-center gap-3`,u,h)),o(`p`,`max-w-2xl text-[12px] leading-snug text-neutral-400`,...a?[`Installs and daily updates run as `,a,` — output, failures and all.`]:[`Switching one on creates the daily task that installs it and keeps it current.`]),r))}async function de(e,t,n){let r=v.find(t=>t.name===e);n(await V(H(e,t),r?.source===`binary`?t?`Saved — installing now; watch the run.`:`Saved — uninstalling in the next run.`:`Saved — sessions take it on their next message.`))}async function fe(e,t){let n=++m,i=await r(`/api/config/resource${z(`&kind=${e}&name=${encodeURIComponent(t)}`)}`,`failed to load ${t}`,{cache:`no-store`});if(!i.ok){n===m&&Y(i.error);return}if(n!==m)return;let{content:a}=i.value,s=a.split(`
3
+ `);s.at(-1)===``&&s.pop();let c=await x(t);n===m&&L.replaceChildren(X(t,o(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,`read-only`)),o(`div`,`min-h-0 flex-1 overflow-auto`,M(j(s),c)))}function pe(){N.replaceChildren(new Option(h?`Global (${h})`:`Global`,`global`),...t().map(e=>new Option(`${s(e)} — ${e}`,e))),[...N.options].some(e=>e.value===i)||(i=`global`),N.value=i}return c(e,()=>{pe(),te()},w)}var G=e=>`${e.provider}/${e.id}`,oe=[`hardest reasoning — architecture, gnarly debugging`,`long autonomous implementation runs`,`balanced default — implementation, review`,`cheap & fast — listings, extraction, simple checks`,`cross-vendor second opinion`];function K(){let e=[],t=[],n=!1,s=o(`span`,`text-[11.5px]`,``),c=v(`Save menu`,!0),l=o(`div`,`flex min-w-0 flex-col gap-2`),u=o(`div`,`flex items-center gap-2`),d=o(`div`,`mx-auto flex w-full max-w-3xl min-w-0 flex-col gap-6`);function h(){n=!0,f(s,`idle`,`unsaved changes`)}function _(t){let n=k(t.note??``);n.classList.remove(`w-full`),n.classList.add(`min-w-0`,`flex-1`),n.placeholder=`why this one — pick a preset or write your own`,n.setAttribute(`list`,`model-menu-notes`),n.oninput=()=>{t.note=n.value,h()};let r=O([[`thinking: model default`,``],...g.map(e=>[`thinking: ${i(e)}`,e])],t.thinking??``);r.classList.replace(`w-full`,`w-44`),r.classList.add(`flex-none`),r.onchange=()=>{r.value?t.thinking=r.value:delete t.thinking,h()};let a=v(`Remove`);a.classList.add(`flex-none`),a.onclick=()=>{e=e.filter(e=>e!==t),h(),b()};let s=o(`span`,`w-52 flex-none truncate font-mono text-[12px] text-neutral-700`,G(t));return s.title=G(t),o(`div`,`flex min-w-0 items-center gap-2 rounded-lg border border-neutral-200 bg-white px-3 py-2 shadow-2xs max-md:flex-wrap`,s,r,n,a)}function y(){let n=t.filter(t=>!e.some(e=>G(e)===G(t))),r=O(n.map(e=>[G(e),G(e)]),n[0]?G(n[0]):``);r.classList.replace(`w-full`,`flex-1`),r.classList.add(`min-w-0`);let i=v(`+ Pin model`);i.classList.add(`flex-none`,`whitespace-nowrap`),i.disabled=n.length===0,i.onclick=()=>{let t=n.find(e=>G(e)===r.value);t&&(e.push({...t}),h(),b())},u.replaceChildren(r,i)}function b(){l.replaceChildren(...e.length?e.map(_):[D(`Nothing pinned — every picker shows the curated catalog as is.`)]),y()}async function x(){f(s,`saving`,`saving…`);let t=e.map(({provider:e,id:t,thinking:n,note:r})=>({provider:e,id:t,...n?{thinking:n}:{},...r?.trim()?{note:r.trim()}:{}})),r=await a(`/api/settings`,{modelMenu:t},`PUT`);if(!r.ok)return f(s,`failed`,await p(r,`Could not save`));e=(await r.json()).modelMenu,n=!1,f(s,`saved`,`Saved — agents see it on their next models call.`),b()}c.onclick=()=>void x();function S(){n||(async()=>{let[n,i]=await Promise.all([r(`/api/settings`,`Could not load the menu`),r(`/api/models`,`Could not load the model catalog`)]);if(!n.ok)return f(s,`failed`,n.error);e=n.value.modelMenu,t=i.ok?i.value:[],s.textContent=``,b()})()}let C=o(`datalist`,``);return C.id=`model-menu-notes`,C.append(...oe.map(e=>new Option(e))),d.append(m(`Model menu`,`Which few models this deployment favors, each with a usual reasoning level and one line of intent. Pinned entries lead every model picker, and agents delegating work match your notes against the task instead of guessing ids.`,A(`Pinned models`,l,{hint:`The note is what an agent matches a task against — say when to reach for it, not what it is.`}),A(`Add`,u,{hint:`The list is the live catalog — only models that exist right now can be pinned.`}),o(`div`,`flex items-center gap-3`,c,s),C)),{el:d,load:S}}var q=(e,t)=>{let n;try{n=new URL(e)}catch{return null}if(n.protocol!==`http:`&&n.protocol!==`https:`)return null;let r=o(`a`,`text-indigo-600 hover:underline`,t);return r.href=n.href,r.target=`_blank`,r.rel=`noreferrer`,r};function J(e,t,n,r){let i=document.createElement(`dialog`);i.className=`m-auto w-[min(32rem,92vw)] rounded-lg border border-neutral-200 bg-white p-0 shadow-xl backdrop:bg-black/30`;let s=o(`div`,`flex flex-col gap-2`),c=o(`div`,`flex flex-col gap-2`),l=o(`p`,`text-[12.5px] text-neutral-400`,`Starting…`),d=v(`Cancel`),f=(e,t)=>{l.className=`text-[12.5px] ${w[e]}`,l.textContent=t};i.append(o(`div`,`border-b border-neutral-200 px-4 py-2.5 text-[14px] font-semibold`,t),o(`div`,`flex max-h-[65vh] flex-col gap-3 overflow-y-auto px-4 py-3`,s,c,l),o(`div`,`flex justify-end border-t border-neutral-200 px-4 py-2.5`,d)),document.body.append(i),i.showModal();let m=e.id,h=e.state,g,_,y=new Set,b=!1,x=!1,S=async e=>{if(!x){if(e&&h===`running`){x=!0,d.disabled=!0;try{let e=await a(`/api/providers/flows/${m}/cancel`,{});if(!e.ok&&e.status!==404){f(`failed`,await p(e,`Could not cancel authentication flow`));return}}catch(e){f(`failed`,`Could not cancel authentication flow: ${String(e)}`);return}finally{x=!1,d.disabled=!1}}clearTimeout(g),i.close()}};d.onclick=()=>void S(!0),i.oncancel=e=>{e.preventDefault(),S(!0)},i.onclose=()=>{b=!0,clearTimeout(g),i.remove()};let C=e=>{if(e.type===`auth_url`){let t=o(`div`,`flex flex-col gap-1 text-[12.5px] text-neutral-600`);return e.instructions&&t.append(o(`p`,``,e.instructions)),t.append(q(e.url,`Open authorization page`)??o(`span`,`text-red-600`,`Invalid authorization URL`)),t}if(e.type===`device_code`){let t=o(`div`,`flex flex-col gap-2 text-[12.5px] text-neutral-600`);return t.append(o(`div`,`flex items-center gap-2`,o(`code`,`font-mono text-[17px] font-semibold text-neutral-800`,e.userCode),u(`btn text-[11px]`,()=>e.userCode))),t.append(q(e.verificationUri,`Open verification page`)??o(`span`,`text-red-600`,`Invalid verification URL`)),t}let t=o(`div`,`text-[12.5px] text-neutral-600`,e.message);if(e.type===`info`)for(let n of e.links??[]){let e=q(n.url,n.label??n.url);e&&t.append(` `,e)}return t},T=(e,t)=>{_=t.id;let n;if(t.type===`select`){let e=document.createElement(`select`);e.append(...t.options.map(e=>new Option(e.description?`${e.label} — ${e.description}`:e.label,e.id))),n=e}else{let e=k(``,t.type===`secret`?`password`:`text`);e.placeholder=t.placeholder??``,e.autocomplete=`off`,n=e}n.className=`${n.tagName===`SELECT`?`select `:``}w-full rounded-lg border border-neutral-300 bg-white px-2.5 py-1.5 text-[12.5px] focus:border-indigo-400 focus:outline-none`;let r=v(`Continue`,!0);r.type=`submit`;let i=o(`form`,`flex flex-col gap-2`,o(`label`,`text-[12.5px] font-medium text-neutral-700`,t.message),n,o(`div`,`flex justify-end`,r));i.onsubmit=i=>{i.preventDefault(),r.disabled=!0,(async()=>{try{let r=await a(`/api/providers/flows/${e.id}/respond`,{promptId:t.id,value:n.value});if(b)return;if(!r.ok){f(`failed`,await p(r,`Could not submit response`));return}y.add(t.id),_=void 0,c.replaceChildren(),f(`saving`,`Waiting for provider…`)}catch(e){b||f(`failed`,`Could not submit response: ${String(e)}`)}finally{r.disabled=!1}})()},c.replaceChildren(i),n.focus()},E=e=>{h=e.state,s.replaceChildren(...e.events.map(C));let t=e.prompt&&!y.has(e.prompt.id)?e.prompt:void 0;if(t?.id!==_&&(t?T(e,t):(_=void 0,c.replaceChildren())),e.state===`running`){f(`saving`,t?`Waiting for your response.`:`Waiting for provider…`);return}clearTimeout(g),c.replaceChildren(),e.state===`succeeded`?f(`saved`,`${n} configured.`):f(`failed`,e.state===`cancelled`?`Cancelled.`:e.error??`Authentication failed.`),d.textContent=`Close`,d.onclick=()=>void S(!1),e.state===`succeeded`&&r()},D=async()=>{if(!(b||h!==`running`))try{let e=await fetch(`/api/providers/flows/${m}`,{cache:`no-store`});if(b)return;if(!e.ok){f(`failed`,await p(e,`Authentication status unavailable`)),e.status===404?h=`failed`:g=setTimeout(()=>void D(),1e3);return}E(await e.json()),h===`running`&&(g=setTimeout(()=>void D(),500))}catch(e){if(b)return;f(`failed`,`Authentication status unavailable: ${String(e)}`),g=setTimeout(()=>void D(),1e3)}};E(e),h===`running`&&(g=setTimeout(()=>void D(),500))}var se=[`anthropic`,`openai`,`openai-codex`,`google`,`openrouter`,`deepseek`],Y=[[`OpenAI Chat Completions`,`openai-completions`],[`OpenAI Responses`,`openai-responses`],[`Anthropic Messages`,`anthropic-messages`],[`Google Generative AI`,`google-generative-ai`]],X=`__custom__`;async function ce(e){let t=v(`Add provider`,!0);t.classList.add(`ml-auto`);let n=o(`div`,`flex flex-none items-center gap-3 rounded-t-xl border-b border-neutral-200/70 bg-neutral-50/70 px-4 py-2`,o(`h2`,`text-[13px] font-semibold text-neutral-700`,`Providers`),t),i=o(`div`,`min-h-0 flex-1 overflow-y-auto`);e.replaceChildren(n,i);let s=[],c=``,l=async()=>{i.replaceChildren(o(`p`,`px-4 py-3 text-[13px] text-neutral-400`,`Loading…`));try{let[e,n]=await Promise.all([r(`/api/providers`,`Could not load providers`,{cache:`no-store`}),r(`/api/models`,`the model catalog could not be read`,{cache:`no-store`})]);if(s=n.ok?n.value:[],c=n.ok?``:n.error,!e.ok){i.replaceChildren(D(e.error));return}let a=e.value;t.onclick=()=>Z(a,void 0,l),g(a)}catch(e){i.replaceChildren(D(`Could not load providers: ${String(e)}`))}},u=async e=>{if(window.confirm(`Remove the stored credential for ${e.name}?`))try{let t=await a(`/api/providers/${encodeURIComponent(e.id)}/logout`,{});if(!t.ok){window.alert(await p(t,`Could not remove credential`));return}await l()}catch(e){window.alert(`Could not remove credential: ${String(e)}`)}},d=e=>[...new Set([...(e.models??[]).map(e=>e.id),...s.filter(t=>t.provider===e.id).map(e=>e.id)])],m=(e,t)=>o(`div`,`flex flex-col gap-1`,o(`span`,`text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),o(`pre`,`max-h-56 overflow-auto whitespace-pre-wrap break-all rounded-md bg-neutral-50 p-2 font-mono text-[11.5px] leading-relaxed text-neutral-600`,t)),h=async(e,t)=>{try{let n=await a(`/api/providers/${encodeURIComponent(e)}/check`,{model:t});return n.ok?await n.json():await p(n,`Could not test`)}catch(e){return`Could not test: ${String(e)}`}},g=e=>{let t=e.filter(e=>e.configured);if(!t.length){i.replaceChildren(D(`No providers configured.`));return}i.replaceChildren(...t.map(t=>{let n=o(`div`,`min-w-0 flex-1`,o(`div`,`truncate text-[13px] font-medium text-neutral-700`,t.name),o(`div`,`truncate font-mono text-[11px] text-neutral-400`,t.id)),r=t.stored===`api_key`?`API key`:t.stored===`oauth`?`OAuth`:t.source??`configured`,i=t.endpoint??`Default endpoint`,a=o(`div`,`flex min-w-32 flex-col items-start gap-1`,S(`configured`,`bg-emerald-50 text-emerald-700 ring-emerald-200`),o(`span`,`max-w-48 truncate text-[11px] text-neutral-500`,r),o(`span`,`max-w-48 truncate text-[11px] text-neutral-400`,i));a.title=i;let s=o(`span`,`text-[11.5px]`,``),p=o(`div`,`hidden flex-col gap-2 px-4 pb-3`,s),g=o(`div`,`flex flex-wrap justify-end gap-1.5`),_=d(t);if(!_.length)f(s,`idle`,c||`No models to test: none are configured here.`),p.classList.replace(`hidden`,`flex`);else{let e=O([[`Model to test…`,``],..._.map(e=>[e,e])],``);e.classList.add(`max-w-52`,`text-[12px]`);let n=v(`Test`);n.disabled=!0,e.onchange=()=>n.disabled=!e.value,n.onclick=()=>{let r=e.value;n.disabled=!0,p.replaceChildren(s),p.classList.replace(`hidden`,`flex`),f(s,`saving`,`asking ${r}…`),h(t.id,r).then(e=>{if(n.disabled=!1,typeof e==`string`)return f(s,`failed`,e);f(s,e.ok?`saved`:`failed`,`${e.model} ${e.ok?`answered`:`did not answer`} in ${e.ms} ms`),p.append(m(`sent`,e.request||`(the request was never made)`),m(e.ok?`answered`:`replied`,e.response))})},g.append(e,n)}if(t.builtin||t.api&&t.models){let n=v(`Edit`);n.onclick=()=>Z(e,t,l),g.append(n)}if(t.stored){let e=v(`Remove credential`);e.onclick=()=>void u(t),g.append(e)}return o(`div`,`border-b border-neutral-100`,o(`div`,`grid grid-cols-[minmax(8rem,1fr)_minmax(8rem,auto)_minmax(9rem,auto)] items-center gap-3 px-4 py-2.5 max-sm:grid-cols-[1fr_auto]`,n,a,g),p)}))};await l()}function le(e,t){let n=t.filter(e=>!e.configured&&e.methods.length&&(e.builtin||e.api!==void 0&&e.models!==void 0)),r=(t,n)=>{if(!n.length)return;let r=document.createElement(`optgroup`);r.label=t,r.append(...n.map(e=>new Option(e.name,e.id))),e.append(r)};r(`Common`,se.flatMap(e=>n.filter(t=>t.id===e))),r(`More providers`,n.filter(e=>e.builtin&&!se.includes(e.id)).sort((e,t)=>e.name.localeCompare(t.name))),r(`Custom providers`,n.filter(e=>!e.builtin).sort((e,t)=>e.name.localeCompare(t.name))),e.append(new Option(`Custom provider…`,X))}function Z(e,n,r){let i=document.createElement(`dialog`);i.className=`m-auto w-[min(32rem,92vw)] rounded-lg border border-neutral-200 bg-white p-0 shadow-xl backdrop:bg-black/30`;let s=document.createElement(`select`);s.className=`${_} select`,n||le(s,e);let c=k(),l=k(),u=k(),d=document.createElement(`select`);d.className=`${_} select`,d.append(...Y.map(([e,t])=>new Option(e,t)));let f=t(``,4);f.placeholder=`model-id
4
+ another-model-id`;let m=document.createElement(`input`);m.type=`checkbox`;let h=document.createElement(`select`);h.className=`${_} select`;let g=o(`div`,`flex flex-col gap-4`),y=o(`span`,`text-[11.5px] text-red-600`,``),b=v(`Cancel`),x=v(n?`Save`:`Add`,!0);x.type=`submit`;let S=()=>n??e.find(e=>e.id===s.value),C=()=>{let e=S(),t=e?!e.builtin:s.value===X;c.value=e?.id??``,c.disabled=n!==void 0,l.value=e?.name??``,u.value=e?.endpoint??``,d.value=e?.api??`openai-completions`,f.value=e?.models?.map(e=>e.id).join(`
5
+ `)??``;let r=e?.models?.map(e=>e.reasoning)??[];m.checked=r.length?r.every(Boolean):!e,m.indeterminate=r.some(Boolean)&&!r.every(Boolean);let i=[];e?.configured&&i.push(new Option(`Keep current authentication`,``));let a=e?.methods??[{type:`api_key`,name:`API key`}];for(let t of a.filter(t=>e?.builtin!==!1||t.type===`api_key`))i.push(new Option(t.name,t.type));h.replaceChildren(...i);let p=[];n||p.push(A(`Provider`,s)),t?p.push(A(`Provider ID`,c),A(`Display name`,l),A(`Endpoint`,u),A(`API format`,d),A(`Models`,f),A(`Model capabilities`,o(`label`,`flex items-center gap-2 text-[12.5px] text-neutral-600`,m,o(`span`,``,`Reasoning`)))):(u.placeholder=`Provider default`,p.push(A(`Endpoint`,u))),p.push(A(`Authentication`,h)),g.replaceChildren(...p)};s.onchange=C,C();let w=o(`form`,`flex flex-col gap-4 px-4 py-3`,g,o(`div`,`flex items-center justify-end gap-2`,y,b,x)),T=!1;b.onclick=()=>{T||i.close()},i.oncancel=e=>{T&&e.preventDefault()},w.onsubmit=e=>{if(e.preventDefault(),T)return;y.textContent=``;let t=S(),n=(t?!t.builtin:s.value===X)?{kind:`custom`,id:c.value.trim(),...l.value.trim()?{name:l.value.trim()}:{},endpoint:u.value.trim(),api:d.value,models:[...new Set(f.value.split(`
6
+ `).map(e=>e.trim()).filter(Boolean))].map(e=>({id:e,reasoning:m.indeterminate?t?.models?.find(t=>t.id===e)?.reasoning??m.checked:m.checked}))}:{kind:`builtin`,id:t.id,...u.value.trim()?{endpoint:u.value.trim()}:{}},o=h.value||null;T=!0,x.disabled=!0,b.disabled=!0,(async()=>{try{let e=await a(`/api/providers/setup`,{setup:n,authType:o});if(!e.ok){y.textContent=await p(e,`Could not configure provider`);return}if(i.close(),e.status===202){let t=h.selectedOptions[0]?.textContent??`Authentication`;J(await e.json(),n.id,t,()=>void r())}else await r()}catch(e){y.textContent=`Could not configure provider: ${String(e)}`}finally{T=!1,x.disabled=!1,b.disabled=!1}})()},i.append(o(`div`,`border-b border-neutral-200 px-4 py-2.5 text-[14px] font-semibold`,n?`Edit ${n.name}`:`Add provider`),w),i.onclose=()=>i.remove(),document.body.append(i),i.showModal(),(n?u:s).focus()}var Q=[[`models`,`Models`],[`files`,`Agent`],[`channels`,`Channels`],[`instance`,`Instance`],[`security`,`Security`]],ue=e=>Q.some(([t])=>t===e),$=`pier.settingsTopic`;function de(e){return[/\bEdg\//.test(e)?`Edge`:/\b(Firefox|Chrome|Safari)\/[\d.]+/.exec(e)?.[1],/\(([^;)]+)/.exec(e)?.[1]?.trim()].filter(Boolean).join(` · `)||e||`unknown client`}function fe(e,t,n){let i=localStorage.getItem($)??void 0,s=ue(i)?i:`models`,l=o(`header`,`flex h-10 flex-none items-center gap-3 border-b border-neutral-200 bg-white px-4 max-md:hidden`,o(`span`,`font-medium`,`Settings`)),u=o(`div`,`tabstrip bg-white`);function h(){u.replaceChildren(...Q.map(([e,t])=>d(t,e===s,()=>n(e))))}let g=k();g.placeholder=`https://pier.example.com`,g.autocomplete=`off`;let _=o(`span`,`text-[11.5px]`,``),y=v(`Save`,!0);async function x(){f(_,`saving`,`saving…`);let e=await a(`/api/settings`,{publicUrl:g.value},`PUT`);if(!e.ok)return f(_,`failed`,await p(e,`Could not save`));let{publicUrl:t}=await e.json();g.value=t,f(_,`saved`,t?`Saved — boards link as ${t}/p/<slug>-<token>/`:`Cleared.`)}y.onclick=()=>void x(),g.onkeydown=e=>{e.key===`Enter`&&x()};let w=m(`Public URL`,`Where this Pier is reached from outside — the proxy's address, not the port it listens on.`,A(`Base URL`,g,{hint:`Agents read it to hand you a clickable board link instead of a path. Nothing here changes what Pier serves; leave it empty if Pier is only reachable locally.`}),o(`div`,`flex items-center gap-3`,y,_)),T=k(``,`password`),E=k(``,`password`),O=k(``,`password`);for(let e of[T,E,O])e.autocomplete=`off`;let j=o(`span`,`text-[11.5px]`,``),M=v(`Change password`,!0);async function N(){if(E.value!==O.value)return f(j,`failed`,`The two new passwords differ.`);f(j,`saving`,`changing…`);let e=await a(`/api/password`,{current:T.value,next:E.value});if(!e.ok)return f(j,`failed`,await p(e,`Could not change the password`));for(let e of[T,E,O])e.value=``;f(j,`saved`,`Changed. Sign in again with the new password.`),location.href=`/login`}M.onclick=()=>void N(),O.onkeydown=e=>{e.key===`Enter`&&N()};let P=m(`Password`,`One shared password guards every page and API route. Changing it signs out every signed-in browser, this one included.`,A(`Current password`,T),A(`New password`,E,{hint:`At least 10 characters.`}),A(`Repeat new password`,O),o(`div`,`flex items-center gap-3`,M,j)),F=v(`Reload`,!0),I=o(`span`,`text-[11.5px]`,``);F.onclick=()=>{F.disabled=!0,f(I,`saving`,`reloading…`),(async()=>{let e=await a(`/api/reload`,{});if(F.disabled=!1,!e.ok)return f(I,`failed`,await p(e,`Could not reload`));let{recycled:t,busy:n}=await e.json(),r=t?`Recycled ${t} session(s).`:`No idle session needed it.`,i=n?` ${n} still mid-turn — they take it when the turn ends.`:``;f(I,n?`idle`:`saved`,r+i)})()};let L=m(`Reload configuration`,`Re-reads channel configuration and lets go of idle sessions, so the next message opens them with the current agent files, skills and credentials. Saving here does this on its own — use it after something outside the Console changed a file.`,o(`div`,`flex items-center gap-3`,F,I)),R=o(`div`,`flex flex-col gap-2`),z=o(`span`,`text-[11.5px]`,``);async function ee(e,t){f(z,`saving`,`signing out…`);try{let n=await a(e,{});if(n.ok)return!0;f(z,`failed`,await p(n,t))}catch(e){f(z,`failed`,`${t}: ${String(e)}`)}return!1}let B=v(`Sign out`);B.onclick=()=>{B.disabled=!0,ee(`/logout`,`Could not sign out`).then(e=>{e?location.href=`/login`:B.disabled=!1})};function V(e){R.replaceChildren(...e.map(e=>{let t=v(e.current?`This browser`:`Sign out`);t.disabled=e.current,t.onclick=()=>{t.disabled=!0,ee(`/api/devices/${encodeURIComponent(e.id)}/signout`,`Could not sign it out`).then(e=>{if(!e)return void(t.disabled=!1);f(z,`saved`,`Signed out.`),H()})};let n=o(`div`,`flex min-w-0 flex-col`,o(`span`,`truncate text-[12.5px] text-neutral-700`,de(e.agent)));return n.title=e.agent,n.append(o(`span`,`truncate text-[11.5px] text-neutral-400`,`${e.ip} · seen ${b(e.seenAt)} · signed in ${b(e.createdAt)}`)),o(`div`,`flex items-center justify-between gap-3 rounded-lg border border-neutral-200 px-3 py-2`,n,t)}))}async function H(){let e=await r(`/api/devices`,`Could not load signed-in devices`);if(!e.ok){R.replaceChildren(D(e.error));return}V(e.value)}let te=m(`Signed-in devices`,`One row per browser holding a session. Signing one out invalidates its cookie immediately; sessions expire on their own 7 days after last use.`,R,o(`div`,`flex items-center gap-3`,B,z)),U=o(`div`,`mx-auto flex max-w-2xl flex-col gap-6`,w,C(),L),re=e=>o(`div`,`hidden min-h-0 flex-1 overflow-y-auto bg-neutral-50/60`,o(`div`,`px-4 py-5`,e)),ie=K(),ae=o(`div`,`mx-auto flex w-full min-w-0 max-w-3xl flex-col rounded-xl border border-neutral-200 bg-white shadow-xs`),G=o(`section`,`hidden min-h-0 flex-1 flex-col`),oe=ne(G),q=o(`section`,`hidden min-h-0 flex-1 flex-col`),J=W(q,t);function se(){(async()=>{let e=await r(`/api/settings`,`Could not load settings`);if(!e.ok)return f(_,`failed`,e.error);g.value=e.value.publicUrl,_.textContent=``})()}let Y=o(`div`,`mx-auto flex max-w-2xl flex-col gap-6`),X=e=>Y.replaceChildren(e,P,te);async function le(){j.textContent=``,z.textContent=``,H();let e=await r(`/api/secrets`,`Could not load key status`);if(!e.ok){X(D(e.error));return}Z(e.value)}function Z(e,t){let n=e.state===`locked`,i=o(`span`,`text-[11.5px]`,``);t&&f(i,`saved`,t);let s=o(`div`,`flex items-center gap-2`,S(e.state,n?`bg-red-50 text-red-700 ring-red-200`:`bg-emerald-50 text-emerald-700 ring-emerald-200`),o(`span`,`text-[12.5px] text-neutral-600`,n?`Stored credentials cannot be read until the key is unlocked.`:e.mode===`vt`?`Key mode: vt:// — unlocking takes one vt approval per process start.`:`Key mode: file — the key sits raw in master.key; switch to vt:// to require an approval.`)),c=o(`a`,`text-indigo-600 hover:underline`,`vt`);c.href=`https://github.com/timqi/vt`,c.target=`_blank`,c.rel=`noreferrer`;let l=[s,o(`p`,`text-[12px] leading-snug text-neutral-500`,c,` is a small local KMS: it keeps the key wrapped and releases it only on an explicit approval — Touch ID on a Mac, a phone passkey on a headless host. Pier only stores the vt:// record, so master.key alone unlocks nothing.`)];if(n){l.push(o(`p`,`text-[12.5px] leading-snug text-red-600`,e.reason??`No reason reported.`));let t=v(`Unlock`,!0);t.onclick=()=>{f(i,`saving`,`unlocking… (vt mode waits on your approval)`),(async()=>{let e=await a(`/api/secrets/unlock`,{});if(!e.ok)return f(i,`failed`,await p(e,`Could not unlock`));Z(await e.json(),`Unlocked — channels are starting.`)})()},l.push(o(`div`,`flex items-center gap-3`,t,i))}else{let t=async(e,t,n)=>{if(!window.confirm(t))return;f(i,`saving`,e===`vt`?`rotating… (vt asks for an approval)`:`rotating…`);let r=await a(`/api/secrets/rotate`,{mode:e});if(!r.ok)return f(i,`failed`,await p(r,`Could not rotate`));Z(await r.json(),n)},n=e.mode??`file`,r=v(`Rotate key`,!0);r.onclick=()=>void t(n,`Generate a new master key? Stored credentials stay valid; the old key stops working.`,`Rotated.`);let s=n===`vt`?`file`:`vt`,c=v(s===`vt`?`Switch to vt://`:`Switch to file`);c.onclick=()=>void t(s,s===`vt`?`Move the master key into vt? Every process start will then wait on a vt approval.`:`Store the master key raw in master.key? Anyone who can read the file can read every credential.`,s===`vt`?`Switched to vt:// mode.`:`Switched to file mode.`),l.push(o(`div`,`flex items-center gap-3`,r,c,i))}if(n||e.mode===`vt`){let e=o(`pre`,`hidden overflow-x-auto rounded-lg bg-neutral-50 p-3 text-[11.5px] leading-snug text-neutral-700`),t=v(`vt doctor`);t.onclick=()=>{t.disabled=!0,e.classList.remove(`hidden`),e.textContent=`running vt doctor…`,(async()=>{let n=await r(`/api/secrets/doctor`,`Could not run vt doctor`);e.textContent=n.ok?n.value.report:n.error,t.disabled=!1})()},l.push(o(`div`,`flex items-center gap-3`,t),e)}X(m(`Master key`,`Seals every credential Pier stores (channel tokens, API keys). Rotating rewraps the key file; no stored data is rewritten.`,...l))}let fe=re(U),pe=re(o(`div`,`flex flex-col gap-6`,ae,ie.el)),me=re(Y),he=[[`instance`,fe,se],[`models`,pe,()=>{ce(ae),ie.load()}],[`security`,me,()=>void le()]];e.append(l,u,fe,pe,G,q,me);function ge(e){ue(e)&&(s=e),localStorage.setItem($,s),h();for(let[e,t,n]of he){let r=e===s;t.classList.toggle(`hidden`,!r),r&&n()}s===`channels`?oe.show():oe.hide(),s===`files`?J.show():J.hide()}return c(e,ge)}export{fe as createSettingsView};
@@ -0,0 +1,3 @@
1
+ import{H as e,I as t,L as n,W as r,g as i,k as a,m as o,v as s}from"./index-BrBNzaid.js";var c=e=>e===null?`-`:new Date(e).toLocaleString(),l=e=>e.startedAt===null?`-`:t((e.finishedAt??Date.now())-e.startedAt),u=e=>e.state===`succeeded`&&e.matched===!1?`No match`:e.state,d={queued:`bg-neutral-100 text-neutral-600 ring-neutral-200`,running:`bg-sky-50 text-sky-700 ring-sky-200`,succeeded:`bg-emerald-50 text-emerald-700 ring-emerald-200`,failed:`bg-red-50 text-red-700 ring-red-200`,cancelled:`bg-amber-50 text-amber-700 ring-amber-200`,interrupted:`bg-amber-50 text-amber-700 ring-amber-200`,skipped:`bg-neutral-100 text-neutral-600 ring-neutral-200`};function f(e){let t=u(e);return o(t,t===`No match`?d.skipped:d[e.state],e.state===`running`?`animate-pulse bg-sky-500`:void 0)}function p(e){return e.archived?o(`Archived`,`bg-neutral-50 text-neutral-400 ring-neutral-200`):e.trigger.type===`manual`?o(`Manual`,`bg-neutral-100 text-neutral-600 ring-neutral-200`):e.enabled?o(`Enabled`,`bg-emerald-50 text-emerald-700 ring-emerald-200`):o(`Paused`,`bg-amber-50 text-amber-700 ring-amber-200`)}var m=`px-4 pt-4 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,h=`m-4 mt-2 whitespace-pre-wrap break-words rounded-lg border border-black/[0.06] bg-black/[0.025] px-3 py-2 font-mono text-[12px] leading-snug dark:border-neutral-200 dark:bg-neutral-100`,g=e=>e.trigger.type===`manual`?`Manual`:e.trigger.type===`cron`?`${e.trigger.expression} (${e.trigger.timezone})`:`Every ${e.trigger.intervalSeconds}s · ${e.trigger.mode}`,_=e=>e.action.type===`agent`?`Agent · ${e.action.session.mode}`:e.action.type===`bash`?`Bash`:e.action.type===`system`?`System`:`Task`;function v(e,t){let r=n(`div`,`grid max-w-4xl grid-cols-[6rem_minmax(0,1fr)] gap-x-5 gap-y-3.5 p-4 text-[13px] md:grid-cols-[9.375rem_minmax(0,1fr)]`),a=[[`Status`,e.archived?`Archived`:e.trigger.type===`manual`?`Manual`:e.enabled?`Enabled`:`Paused`],[`Trigger`,g(e)],[`Action`,_(e)],[`Timeout`,`${e.timeoutSeconds}s`],[`Next run`,c(e.nextRunAt)],[`Revision`,String(e.revision)],[`Created by`,e.createdBySessionId??e.creator],[`Callback`,e.callback.type===`session`?e.callback.sessionId:e.callback.type],[`Description`,e.description||`-`]];e.action.type===`agent`&&(a.push([`Session policy`,e.action.session.mode]),e.action.session.mode===`reuse`&&a.push([`Session`,e.action.session.sessionId]),`cwd`in e.action.session&&a.push([`Directory`,e.action.session.cwd]),e.action.launch?.model&&a.push([`Model`,`${e.action.launch.model.provider}/${e.action.launch.model.id}`]),e.action.launch?.thinking&&a.push([`Thinking`,e.action.launch.thinking]),a.push([`Prompt`,e.action.prompt])),e.action.type===`bash`&&a.push([`Directory`,e.action.cwd],[`Script`,e.action.script]),e.action.type===`task`&&a.push([`Target task`,e.action.taskId]),e.action.type===`system`&&a.push([`System action`,e.action.name]),e.trigger.type===`watch`&&a.push([`Probe`,e.trigger.script]);for(let[e,t]of a)r.append(n(`span`,`pt-px text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),n(`pre`,`whitespace-pre-wrap break-words font-mono text-[12.5px] leading-snug`,t));if(e.action.type===`agent`&&e.action.session.mode===`reuse`){let{sessionId:a}=e.action.session,o=i(`Open session`);o.onclick=()=>t(a),r.append(n(`span`,``,``),o)}return r}function y(e){return[e.pendingDecisionId?`Awaiting decision`:``,e.callbackState&&e.callbackState!==`delivered`?`Callback not delivered (${e.callbackState})`:``,e.groupCallbackState&&e.groupCallbackState!==`delivered`?`Group callback not delivered (${e.groupCallbackState})`:``].filter(Boolean).join(` · `)}function b(e,t,r,i){let a=n(`div`,`divide-y divide-neutral-100`);for(let e of t){let t=n(`button`,`grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 px-4 py-2.5 text-left text-[12.5px] transition-colors hover:bg-neutral-50 md:grid-cols-[7.5rem_minmax(0,1fr)_7.5rem_6.25rem]`);t.setAttribute(`type`,`button`),t.append(n(`span`,`flex`,f(e)),n(`span`,`truncate text-neutral-500`,c(e.queuedAt)),n(`span`,`text-neutral-500`,e.triggerSource),n(`span`,`text-right font-mono text-[11.5px] text-neutral-400`,l(e))),t.onclick=()=>r(e.id),a.append(t)}t.length||a.append(n(`div`,`p-4`,s(`No runs yet.`))),e.replaceChildren(a),e.scrollTop=i.top,e.onscroll=()=>{i.top=e.scrollTop}}var x=e=>`Exit code: ${e.exitCode??`-`}\nstdout:\n${e.stdout}${e.stdoutTruncated?`
2
+ [stdout truncated]`:``}\nstderr:\n${e.stderr}${e.stderrTruncated?`
3
+ [stderr truncated]`:``}`;async function S(t,o,s,u,d){let p=String(Number(t.dataset.runRequest??0)+1);t.dataset.runRequest=p,t.onscroll=()=>{d.scrollTop=t.scrollTop};let g=i(`Runs`);g.className=`cursor-pointer text-neutral-500 hover:text-neutral-800 hover:underline`,g.onclick=()=>{d.selectedId=null,d.scrollTop=0,s()};let _=a(g,n(`span`,`text-neutral-400`,`›`),n(`span`,`min-w-0 truncate font-mono text-[12px] text-neutral-500`,o)),b=t.dataset.runId!==o;b&&(t.dataset.runId=o,t.replaceChildren(_,n(`p`,`p-4 text-[13px] text-neutral-500`,`Loading run...`)));let[S,w]=await Promise.all([e(`/api/task-runs/${o}`,`Could not load the run`),e(`/api/task-runs/${o}/messages`,`Could not load the run's messages`)]);if(!t.isConnected||t.dataset.runRequest!==p||d.selectedId!==o)return;if(!S.ok){d.drawn=``,t.replaceChildren(_,n(`p`,`p-4 text-[13px] text-red-600`,S.error));return}let T=S.value,E=w.ok?w.value:[],D=JSON.stringify([T,w]);if(!b&&d.drawn===D)return;if(d.drawn=D,T.targetSessionId){let e=i(`Open session`);e.classList.add(`ml-auto`),e.onclick=()=>u.openSession(T.targetSessionId),_.append(e)}if(T.state===`queued`||T.state===`running`){if(T.context.definition.action.type===`agent`){let e=i(`Steer`);e.onclick=()=>void C(r(`Steer run`,`/api/task-runs/${T.id}/steer`,{mode:`steer`,sourceSessionId:u.currentSessionId()},`Run control failed`),u),_.append(e)}let e=i(`Stop run`);e.onclick=()=>void u.mutate(`/api/task-runs/${T.id}/cancel`),_.append(e)}else if(T.context.definition.action.type===`agent`&&T.targetSessionId){let e=i(`Continue`);e.onclick=()=>void C(r(`Continue run`,`/api/task-runs/${T.id}/resume`,{sourceSessionId:u.currentSessionId()},`Run control failed`),u,!0),_.append(e)}let O=E.find(e=>e.id===T.pendingDecisionId);if(O&&O.toSessionId===u.currentSessionId()){let e=i(`Reply to decision`);e.onclick=()=>void C(r(`Reply to decision`,`/api/task-messages/${O.id}/reply`,{sourceSessionId:u.currentSessionId()},`Reply failed`),u),_.append(e)}let k=n(`div`,`min-w-0`),A=y(T);k.append(n(`div`,`flex flex-wrap items-center gap-x-5 gap-y-2 border-b border-neutral-100 bg-neutral-50/60 px-4 py-3 text-[12.5px]`,n(`span`,`flex items-center gap-2`,f(T),n(`span`,`font-medium`,T.context.definition.name)),...A?[n(`span`,`rounded-md bg-amber-50 px-2 py-0.5 text-[12px] text-amber-700 ring-1 ring-amber-200`,A)]:[],n(`span`,`text-neutral-500`,c(T.queuedAt)),n(`span`,`text-neutral-500`,T.triggerSource),n(`span`,`font-mono text-[11.5px] text-neutral-400`,l(T))));let j=n(`div`,`flex flex-wrap items-center gap-2 border-b border-neutral-100 px-4 py-3 text-[12px]`),M=(e,t)=>{let n=i(e);n.classList.add(`max-w-full`,`break-all`,`!whitespace-normal`),n.onclick=t,j.append(n)};if(T.context.definition.kind===`task`&&M(`Task: ${T.context.definition.name}`,()=>u.openTask(T.taskId)),T.parentRunId&&M(`Parent: ${T.parentRunId}`,()=>u.openRun(T.parentRunId)),T.resumedFromRunId&&M(`Resumed from: ${T.resumedFromRunId}`,()=>u.openRun(T.resumedFromRunId)),T.result?.type===`task`){let e=T.result.runId;M(`Child result: ${e}`,()=>u.openRun(e))}T.groupId&&j.append(n(`span`,`break-all font-mono text-[11.5px] text-neutral-500`,`Group: ${T.groupId}`)),k.append(j);for(let e of[T.error,T.skipReason,T.callbackError])e&&k.append(n(`p`,`m-4 whitespace-pre-wrap break-words rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-[12.5px] text-red-700`,e));if(T.result){let e=T.result,t=e.type===`agent`||e.type===`system`?e.text:e.type===`bash`?x(e):e.type===`task`?`Child run: ${e.runId}`:`Watch did not match.`;k.append(n(`h3`,m,`Result`),n(`pre`,h,t||`No output.`))}T.probe&&k.append(n(`h3`,m,`Watch probe: ${T.matched===null?`not evaluated`:T.matched?`matched`:`not matched`}`),n(`pre`,h,x(T.probe)));let N=n(`details`,`border-t border-neutral-200`);if(N.append(n(`summary`,`flex cursor-pointer items-center gap-1.5 px-4 py-3 text-[12px] text-neutral-500 hover:text-neutral-800`,n(`span`,`chev`,`▶`),`Configuration snapshot (revision ${T.taskRevision})`),v(T.context.definition,u.openSession)),k.append(N),w.ok||k.append(n(`p`,`m-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-[12.5px] text-red-700`,w.error)),E.length){let e=n(`div`,`mt-2 divide-y divide-neutral-100 border-t border-neutral-100`);for(let t of E){let r=n(`div`,`grid grid-cols-[auto_1fr] gap-3 px-4 py-2 text-[12px] md:grid-cols-[6.25rem_6.25rem_minmax(0,1fr)]`);r.append(n(`span`,`font-medium`,t.kind),n(`span`,`text-neutral-500`,t.state),n(`span`,`col-span-2 whitespace-pre-wrap break-words md:col-span-1`,t.content)),t.error&&r.append(n(`span`,`col-span-2 break-words text-red-600 md:col-span-3`,t.error)),e.append(r)}k.append(n(`div`,`border-t border-neutral-200`,n(`div`,m,`Messages`),e))}let P=n(`details`,`border-t border-neutral-200`);P.open=d.rawOpen,P.ontoggle=()=>{P.isConnected&&(d.rawOpen=P.open)},P.append(n(`summary`,`flex cursor-pointer items-center gap-1.5 px-4 py-3 text-[12px] text-neutral-500 hover:text-neutral-800`,n(`span`,`chev`,`▶`),`Raw record`),n(`pre`,h,JSON.stringify(T,null,2))),k.append(P),t.replaceChildren(_,k),t.scrollTop=d.scrollTop,t.onscroll=()=>{d.scrollTop=t.scrollTop}}async function C(e,t,n=!1){let r=await e;if(r.sent){if(r.error)t.onError(r.error);else if(n&&r.response)try{let e=await r.response.json();t.openRun(e.id)}catch(e){t.onError(`Could not open continuation: ${String(e)}`)}else await t.reload()}}export{b as a,l as c,S as i,p as l,c as n,y as o,v as r,f as s,_ as t,g as u};
@@ -0,0 +1,4 @@
1
+ import{B as e,C as t,D as n,G as r,H as i,K as a,L as o,N as s,V as c,f as l,g as u,k as d,v as f,w as p,x as m,y as h}from"./index-BrBNzaid.js";import{a as g,c as _,l as v,n as y,r as b,s as x,t as S,u as C}from"./task-runs-B-eoldcU.js";function w(e,t){let n=e.map(e=>[`${e.title??`Untitled`} · ${e.cwd}`,e.id]);return t&&!n.some(([,e])=>e===t)&&n.push([`Current session · ${t}`,t]),n}function T(e,t){let r=document.createElement(`dialog`);r.className=`m-auto w-[38.75rem] max-w-[94vw] rounded-lg border border-neutral-200 p-0 shadow-xl backdrop:bg-black/20`;let i=document.createElement(`form`);i.className=`flex max-h-[88vh] flex-col`;let a=o(`span`,`mr-auto text-[12px] text-red-600`),s=o(`header`,`flex h-11 flex-none items-center border-b border-neutral-200 px-4 font-medium`,t?`Edit task`:`New task`),c=o(`div`,`grid min-h-0 flex-1 grid-cols-2 gap-3 overflow-y-auto p-4`),l=m(t?.name??``);l.required=!0;let d=m(t?.description??``),f=m(String(t?.timeoutSeconds??900),`number`);f.min=`1`,f.max=`86400`;let g=p([[`Manual`,`manual`],[`Scheduled`,`cron`],[`Watch`,`watch`]],t?.trigger.type??`manual`),_=p([[`Bash`,`bash`],[`Agent`,`agent`],[`Task`,`task`]],t?.action.type??`bash`),v=p([[`No callback`,`none`],[`Invoking session`,`origin`],[`Specific session`,`session`]],t?.callback.type??`none`),y=t?.callback.type===`session`?t.callback.sessionId:null,b=p(w(e.sessions(),y),y??``),x=h(`Callback session`,b);x.classList.toggle(`hidden`,v.value!==`session`),v.onchange=()=>x.classList.toggle(`hidden`,v.value!==`session`),c.append(h(`Name`,l),h(`Description`,d),h(`Trigger`,g),h(`Action`,_),h(`Callback`,v),x,h(`Timeout (seconds)`,f));let S=o(`div`,`col-span-2 grid grid-cols-2 gap-3 border-t border-neutral-200 pt-3`);c.append(S);let C=()=>{S.replaceChildren();let s,c,u,y,x,C;if(g.value===`cron`)s=m(t?.trigger.type===`cron`?t.trigger.expression:`0 9 * * *`),c=m(t?.trigger.type===`cron`?t.trigger.timezone:Intl.DateTimeFormat().resolvedOptions().timeZone),S.append(h(`Cron`,s),h(`Timezone`,c));else if(g.value===`watch`){u=n(t?.trigger.type===`watch`?t.trigger.script:``,4),C=m(t?.trigger.type===`watch`?t.trigger.cwd:e.sessions()[0]?.cwd??``),y=m(String(t?.trigger.type===`watch`?t.trigger.intervalSeconds:60),`number`),x=p([[`Continue after matches`,`repeat`],[`Stop after first match`,`once`]],t?.trigger.type===`watch`?t.trigger.mode:`repeat`);let r=h(`Probe script (0=match, 1=no match)`,u);r.classList.add(`col-span-2`),S.append(r,h(`Probe directory`,C),h(`Interval (seconds)`,y),h(`Mode`,x))}let T,D,O,k,A,j,M,N,P,F;if(_.value===`bash`){D=m(t?.action.type===`bash`?t.action.cwd:e.sessions()[0]?.cwd??``),T=n(t?.action.type===`bash`?t.action.script:``,6);let r=h(`Bash script`,T);r.classList.add(`col-span-2`),S.append(h(`Working directory`,D),o(`span`,``),r)}else if(_.value===`agent`){let r=e.sessions(),i=t?.action.type===`agent`?t.action:null,a=i?.session.mode===`reuse`?i.session.sessionId:``,o=w(r,a||null);O=p([[`Reuse session`,`reuse`],[`Fresh child per run`,`fresh`]],i?.session.mode===`reuse`?`reuse`:`fresh`),k=p(o,a||o[0]?.[1]||``);let s=i&&`cwd`in i.session?i.session.cwd??``:``;A=m(s||r[0]?.cwd||``),j=n(i?.prompt??``,6),M=p([[`Project default`,``],[`Off`,`off`],[`Low`,`low`],[`Medium`,`medium`],[`High`,`high`],[`Extra high`,`xhigh`]],i?.launch?.thinking??``),N=m(i?.launch?.model?.provider??``),P=m(i?.launch?.model?.id??``);let c=h(`Session`,k),l=h(`Child directory`,A),u=[h(`Thinking`,M),h(`Model provider (optional)`,N),h(`Model id (optional)`,P)],d=()=>{let e=O?.value===`reuse`;c.classList.toggle(`hidden`,!e),l.classList.toggle(`hidden`,e);for(let t of u)t.classList.toggle(`hidden`,e)};O.onchange=d,d();let f=h(`Prompt`,j);f.classList.add(`col-span-2`),S.append(h(`Session policy`,O),c,l,...u,f)}else F=p(e.tasks().filter(e=>e.id!==t?.id&&!e.archived).map(e=>[e.name,e.id]),t?.action.type===`task`?t.action.taskId:``),S.append(h(`Target task`,F));i.onsubmit=n=>{n.preventDefault();let i=g.value===`manual`?{type:`manual`}:g.value===`cron`?{type:`cron`,expression:s.value,timezone:c.value}:{type:`watch`,script:u.value,cwd:C.value,intervalSeconds:Number(y.value),mode:x.value},o=_.value===`agent`&&O.value!==`reuse`?{...M.value?{thinking:M.value}:{},...N.value.trim()&&P.value.trim()?{model:{provider:N.value.trim(),id:P.value.trim()}}:{}}:void 0,p=_.value===`bash`?{type:`bash`,cwd:D.value,script:T.value}:_.value===`agent`?{type:`agent`,prompt:j.value,session:O.value===`reuse`?{mode:`reuse`,sessionId:k.value}:{mode:`fresh`,cwd:A.value},...o?{launch:o}:{}}:{type:`task`,taskId:F.value},m=v.value===`origin`?{type:`origin`}:v.value===`session`?{type:`session`,sessionId:b.value}:{type:`none`},h={name:l.value,description:d.value,trigger:i,action:p,callback:m,timeoutSeconds:Number(f.value)};a.textContent=``,E(t?.id,h,r,a,e.onSaved)}};g.onchange=C,_.onchange=C,C();let T=u(`Cancel`);T.onclick=()=>r.close();let D=u(`Save`,!0);D.type=`submit`;let O=o(`footer`,`flex flex-none justify-end gap-2 border-t border-neutral-200 px-4 py-3`);O.append(a,T,D),i.append(s,c,O),r.append(i),r.addEventListener(`close`,()=>r.remove()),document.body.append(r),r.showModal(),l.focus()}async function E(e,t,n,r,i){let o=await a(e?`/api/tasks/${e}`:`/api/tasks`,t,e?`PATCH`:`POST`);if(!o.ok){r.textContent=(await o.json()).error??`Task save failed`;return}let s=await o.json(),c=`task`in s?s.task:s;n.close(),i(c.id)}function D(n,m,h,w,E,D,O){let k=[],A=[],j=null,M=`active`,N=`all`,P=``,F=`runs`,I={top:0},L=0,R=0,z=``,B=e(async()=>{let e=`${M}:${N}`,t=await i(`/api/tasks?state=${M}&kind=task`,`Failed to load tasks`);if(!t.ok)return z=``,V(t.error);if(e!==`${M}:${N}`)return;let n=JSON.stringify(t.value);e+n===z&&!j||(z=e+n,k=t.value,A=M===`archived`?await H():k,e===`${M}:${N}`&&(N!==`all`&&(k=k.filter(e=>e.trigger.type===N)),j?await Y(j):q()))});function V(e){n.querySelector(`[role=alert]`)?.remove();let t=o(`p`,`flex-none p-4 text-[13px] text-red-600`,e);t.setAttribute(`role`,`alert`),n.append(t)}async function H(){let e=await i(`/api/tasks?state=active`,`Failed to load tasks`);return e.ok?e.value:A}let U={sessions:m,tasks:()=>A,onSaved:e=>{G(e),F=`definition`,O(e)}},W=(e,t)=>d(...e,o(`div`,`ml-auto flex flex-wrap items-center gap-2 max-md:w-full`,...t));function G(e){j=e,F=`runs`,I.top=0}function K(){j=null,L++,q()}function q(){let e=u(`New task`,!0);e.onclick=()=>void h().then(()=>T(U));let t=[],r=(e,n,r,i)=>{let a=p(n,r);a.setAttribute(`aria-label`,e),a.classList.add(`!w-auto`,`pr-8`),a.onchange=()=>{i(a.value),R=0,B()},t.push(a)},i=o(`input`,`${l} !w-48 max-md:!w-full`);i.type=`search`,i.placeholder=`Search tasks`,i.setAttribute(`aria-label`,`Search tasks`),i.value=P,i.oninput=()=>{P=i.value,c()},t.push(i),r(`Status`,[[`Current`,`active`],[`Archived`,`archived`]],M,e=>{M=e}),r(`Trigger`,[[`All triggers`,`all`],[`Manual`,`manual`],[`Scheduled`,`cron`],[`Watching`,`watch`]],N,e=>{N=e});let a=document.createElement(`table`);a.className=`w-full table-fixed text-left text-[12.5px]`,a.innerHTML=`<thead class="sticky top-0 bg-neutral-50 text-[10.5px] uppercase tracking-wide text-neutral-400 shadow-[inset_0_-1px_0_var(--color-neutral-200)]"><tr>
2
+ <th class="w-[42%] px-4 py-2 font-semibold md:w-[24%]">Name</th><th class="hidden w-[10%] px-2 py-2 font-semibold md:table-cell">Action</th>
3
+ <th class="hidden w-[23%] px-2 py-2 font-semibold md:table-cell">Trigger</th><th class="hidden w-[17%] px-2 py-2 font-semibold md:table-cell">Next</th>
4
+ <th class="px-2 py-2 font-semibold md:w-[14%]">Last result</th><th class="w-[6rem] px-2 py-2 font-semibold"></th></tr></thead>`;let s=document.createElement(`tbody`),c=()=>{let e=k.filter(e=>`${e.name} ${e.description??``}`.toLowerCase().includes(P.toLowerCase()));s.replaceChildren(...e.map(J)),d.classList.toggle(`hidden`,e.length>0)};a.append(s);let d=o(`div`,`p-4`,f(`No matching tasks.`)),m=o(`div`,`min-h-0 flex-1 overflow-auto`,a,d);c(),m.onscroll=()=>{R=m.scrollTop},n.replaceChildren(W(t,[e]),m),m.scrollTop=R}function J(e){let t=document.createElement(`tr`);t.className=`cursor-pointer border-b border-neutral-100 transition-colors hover:bg-neutral-50`,t.onclick=()=>O(e.id);let n=u(e.name);n.className=`min-w-0 cursor-pointer truncate text-left font-medium text-neutral-800`,n.title=e.name,t.append(o(`td`,`py-2.5 pl-4 pr-2`,o(`div`,`flex flex-wrap items-center gap-x-2 gap-y-1`,n,v(e)),o(`div`,`truncate text-[11px] text-neutral-400`,e.description||``),o(`div`,`truncate text-[11px] text-neutral-400 md:hidden`,C(e))));for(let n of[S(e),C(e),y(e.nextRunAt)]){let e=o(`td`,`hidden truncate px-2 py-2.5 text-neutral-600 md:table-cell`,n);e.title=n,t.append(e)}t.append(o(`td`,`px-2 py-2.5`,e.lastRun?o(`div`,`flex`,x(e.lastRun)):o(`div`,`text-neutral-400`,`–`),o(`div`,`mt-0.5 font-mono text-[11px] text-neutral-400`,e.lastRun?_(e.lastRun):``)));let r=u(`Run now`);return r.disabled=e.archived,r.onclick=t=>{t.stopPropagation(),X(e.id)},t.append(o(`td`,`px-2 py-1 text-right`,r)),t}async function Y(e){let r=++L,a=n.querySelector(`[data-task-detail]`),[s,c]=await Promise.all([i(`/api/tasks/${e}`,`Failed to load task`),i(`/api/tasks/${e}/runs`,`Failed to load the task's runs`)]);if(r!==L||j!==e)return;if(!s.ok)return V(s.error);if(!c.ok)return V(c.error);let l=s.value,f=c.value,p=u(`Tasks`);p.className=`cursor-pointer text-neutral-500 hover:text-neutral-800 hover:underline`,p.onclick=()=>O();let m=o(`span`,`flex min-w-0 items-center gap-2`,p,o(`span`,`text-neutral-400`,`›`),o(`span`,`truncate font-medium`,l.name),v(l)),_=u(`Run now`,!0);_.disabled=l.archived,_.onclick=()=>void X(l.id);let y=u(l.enabled?`Pause schedule`:`Resume schedule`);y.disabled=l.archived||l.action.type===`system`||l.trigger.type===`manual`,y.onclick=()=>void Z(`/api/tasks/${l.id}/${l.enabled?`pause`:`resume`}`);let x=u(`Edit`);x.disabled=l.archived||l.action.type===`system`,x.onclick=()=>void h().then(()=>T(U,l));let S=u(`Archive`);S.disabled=l.archived||l.action.type===`system`,S.onclick=()=>void Z(`/api/tasks/${l.id}/archive`);let C=d(),E=o(`div`,`min-h-0 flex-1 overflow-auto`);E.dataset.taskDetail=e;let k=u(`All runs`);k.onclick=()=>D({taskId:l.id});let A=()=>{C.replaceChildren(t([[`Recent runs (${f.length})`,`runs`],[`Definition`,`definition`]],F,e=>{F=e,A()}),o(`span`,`ml-auto`,k)),F===`runs`?g(E,f,e=>D({},e),I):(E.onscroll=null,E.replaceChildren(b(l,w)))},M=a?.scrollTop??0;n.replaceChildren(W([m],[_,...l.trigger.type===`manual`?[]:[y],x,S]),C,E),A(),E.scrollTop=M}async function X(e){try{let t=await a(`/api/tasks/${e}/run`,{sourceSessionId:E()});if(!t.ok)return V(await c(t,`Failed to run task`));D({},(await t.json()).runId)}catch(e){V(`Failed to run task: ${String(e)}`)}}async function Z(e){let t=await r(e,`POST`,`Task update failed`);if(t)return V(t);await B()}let Q=s(n,e=>{e&&e!==j&&G(e),e||K(),n.childElementCount||q(),B()});return Object.assign(Q,{refresh(e){Q.visible&&(!j||!e||j===e)&&B()}})}export{D as createTasksView};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ghostty-web-CZHJ0YFi.js","assets/index-BrBNzaid.js","assets/index-BH7ir5I4.css"])))=>i.map(i=>d[i]);
2
+ import{K as e,L as t,N as n,T as r,U as i,V as a,a as o,d as s,i as c,n as l}from"./index-BrBNzaid.js";var u=`pier.terminalPrefs`,d={fontFamily:`monospace`,fontSize:14,cursorBlink:!0},f=()=>{try{let e=JSON.parse(localStorage.getItem(u)??`null`),t=typeof e?.fontSize==`number`?e.fontSize:d.fontSize;return{fontFamily:typeof e?.fontFamily==`string`&&e.fontFamily.trim()?e.fontFamily.slice(0,200):d.fontFamily,fontSize:Math.round(Math.max(10,Math.min(24,t))),cursorBlink:typeof e?.cursorBlink==`boolean`?e.cursorBlink:d.cursorBlink}}catch{return{...d}}},p=e=>localStorage.setItem(u,JSON.stringify(e)),m=null,h=()=>(m||=s(()=>import(`./ghostty-web-CZHJ0YFi.js`).then(async e=>(await e.init(),e)),__vite__mapDeps([0,1,2])).catch(e=>{throw m=null,e}),m),g=()=>{let e=()=>void h().catch(e=>{console.warn(`terminal: emulator warm-up failed`,e)});`requestIdleCallback`in window?requestIdleCallback(e,{timeout:1e4}):setTimeout(e,3e3)},_={background:`#1a1b26`,foreground:`#a9b1d6`,cursor:`#c0caf5`};function v(e){let t=e.renderer,n=document.createElement(`canvas`).getContext(`2d`);if(!n||typeof t?.remeasureFont!=`function`){console.warn(`terminal: could not correct cell metrics — rows will render tight`);return}t.measureFont=()=>{let{fontSize:t,fontFamily:r}=e.options;n.font=`${t}px ${r}`;let i=n.measureText(`M`),a=i.fontBoundingBoxAscent||i.actualBoundingBoxAscent||t*.8,o=i.fontBoundingBoxDescent||i.actualBoundingBoxDescent||t*.25;return{width:Math.ceil(i.width),height:Math.ceil(a+o),baseline:Math.ceil(a)}},t.remeasureFont()}var y=`w-full rounded border border-neutral-300 px-2 py-1.5 font-mono text-[12px] outline-none focus:border-indigo-400`;function b(s,u,m,b,x,S){g();let C=``,w=null,T=null,E=null,D=!1,O=0,k=!1,A=f(),j=t(`div`,`ml-auto flex min-w-0 flex-none items-center gap-2`),M=t(`header`,`flex h-10 flex-none items-center gap-2 border-b border-neutral-200 bg-white px-3`),N=t(`div`,`min-h-0 flex-1 overflow-hidden p-1`);N.style.background=_.background,N.setAttribute(`data-owns-keyboard`,``),N.addEventListener(`keydown`,e=>{e.metaKey&&!e.defaultPrevented&&e.stopImmediatePropagation()},!0),N.addEventListener(`scroll`,()=>{N.scrollTop=0,N.scrollLeft=0}),N.addEventListener(`compositionend`,()=>{for(let e=N.childNodes.length-1;e>=0;e--){let t=N.childNodes[e];t&&t.nodeName!==`CANVAS`&&t.nodeName!==`TEXTAREA`&&t.remove()}}),s.append(M,N);let P=e=>{let n=t(`button`,`min-w-0 max-w-72 cursor-pointer truncate rounded-md bg-neutral-100 px-2 py-0.5 text-left font-mono text-[11.5px] text-neutral-600 hover:bg-neutral-200`,e);return n.type=`button`,n};function F(e,n){if(j.replaceChildren(),e&&j.append(t(`span`,`min-w-0 truncate text-[11.5px] text-neutral-400`,e)),n){let e=P(n.label);e.className=e.className.replace(`bg-neutral-100`,`bg-indigo-50 font-medium text-indigo-700 hover:bg-indigo-100`),e.onclick=n.run,j.append(e)}}function I(){w&&(w.options.fontFamily=A.fontFamily,w.options.fontSize=A.fontSize,w.options.cursorBlink=A.cursorBlink,requestAnimationFrame(H))}function L(){let n=document.createElement(`input`);n.type=`text`,n.placeholder=`tmux new -As "$(basename $PWD)"`,n.spellcheck=!1,n.autocomplete=`off`,n.autocapitalize=`off`,n.disabled=!0,n.className=`${y} disabled:bg-neutral-50`;let o=t(`span`,`block text-[11.5px] text-neutral-400`,`loading…`),s=(e,t)=>{o.isConnected?r(o,e,t):e===`failed`&&F(t)},c=``;(async()=>{try{c=(await i(`/api/settings`,`Could not load the startup command`)).terminalInitCommand??``,n.value=c,n.disabled=!1,s(`idle`,`Runs when a shell starts — Restart applies it here.`)}catch(e){s(`failed`,String(e))}})();let l=async()=>{let t=n.value.trim();if(!(n.disabled||t===c)){s(`saving`,`saving…`);try{let r=await e(`/api/settings`,{terminalInitCommand:t},`PUT`);if(!r.ok)return s(`failed`,await a(r,`Could not save the startup command`));c=(await r.json()).terminalInitCommand,n.value=c,s(`saved`,c?`Saved — the next shell runs it.`:`Cleared.`)}catch(e){s(`failed`,`Could not save the startup command: ${String(e)}`)}}};return n.onblur=()=>void l(),n.onkeydown=e=>{e.key===`Enter`&&l()},t(`div`,`space-y-1.5 border-t border-neutral-200 pt-2.5`,t(`div`,``,t(`span`,`text-[12px] font-semibold text-neutral-700`,`Startup command`),t(`span`,`block text-[11px] text-neutral-400`,`This Pier, every shell — not only this browser.`)),n,o)}function R(e){let n=document.createElement(`input`);n.type=`text`,n.value=A.fontFamily,n.setAttribute(`list`,`terminal-font-presets`),n.className=y;let r=document.createElement(`datalist`);r.id=`terminal-font-presets`;for(let e of[`monospace`,`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace`,`JetBrains Mono, monospace`,`Cascadia Mono, monospace`,`Fira Code, monospace`]){let t=document.createElement(`option`);t.value=e,r.append(t)}let i=document.createElement(`input`);i.type=`number`,i.min=`10`,i.max=`24`,i.step=`1`,i.value=String(A.fontSize),i.className=`w-20 rounded border border-neutral-300 px-2 py-1.5 text-[12px] outline-none focus:border-indigo-400`;let a=document.createElement(`input`);a.type=`checkbox`,a.checked=A.cursorBlink,a.className=`h-4 w-4 accent-indigo-600`;let s=()=>{let e=n.value.trim(),t=Number(i.value);!e||!Number.isFinite(t)||(A={fontFamily:e.slice(0,200),fontSize:Math.round(Math.max(10,Math.min(24,t))),cursorBlink:a.checked},i.value=String(A.fontSize),p(A),I())};n.oninput=s,i.oninput=s,a.onchange=s;let c=t(`button`,`cursor-pointer text-[12px] text-neutral-500 hover:text-indigo-700`,`Reset`);c.type=`button`,c.onclick=()=>{A={...d},n.value=A.fontFamily,i.value=String(A.fontSize),a.checked=A.cursorBlink,p(A),I()},o(e,t(`div`,`w-72 space-y-3 px-3 py-2.5`,t(`div`,`flex items-center`,t(`span`,`text-[12px] font-semibold text-neutral-700`,`Terminal`),t(`span`,`ml-auto`,c)),t(`label`,`block space-y-1 text-[11.5px] text-neutral-500`,t(`span`,``,`Font family`),n,r),t(`label`,`flex items-center justify-between text-[11.5px] text-neutral-500`,t(`span`,``,`Font size`),i),t(`label`,`flex cursor-pointer items-center justify-between text-[11.5px] text-neutral-500`,t(`span`,``,`Blinking cursor`),a),L()))}function z(){let e=P(C||`Choose a folder…`);e.title=`Switch folder`,e.onclick=()=>l(e,u().map(e=>({path:e})),C||void 0,e=>e===C?void 0:b(e));let n=P(`Files`);n.title=`Browse this folder`,n.onclick=()=>x(C);let r=P(`Fit`);r.title=`Resize the shell to this window`,r.onclick=()=>{H(),w?.focus()};let i=P(`Restart`);i.title=`End this shell and start a new one`,i.onclick=()=>void V();let a=t(`button`,`icon-btn text-[15px]`,`⚙`);a.type=`button`,a.title=`Terminal settings`,a.setAttribute(`aria-label`,`Terminal settings`),a.onclick=()=>R(a);let o=t(`button`,`icon-btn`,`✕`);o.type=`button`,o.title=`Close Terminal`,o.setAttribute(`aria-label`,`Close Terminal`),o.onclick=S,M.replaceChildren(e,j,...C?[n]:[],r,i,a,o)}let B=()=>{w&&E?.readyState===WebSocket.OPEN&&E.send(JSON.stringify({t:`resize`,cols:w.cols,rows:w.rows}))};async function V(){if(E?.readyState!==WebSocket.OPEN){await W();return}window.confirm(`Restart the shell in ${C}? Anything running in it stops.`)&&(k=!0,F(`restarting…`),E.send(JSON.stringify({t:`restart`})))}function H(){!w||N.clientHeight===0||(T?.fit(),B())}window.addEventListener(`focus`,H),document.addEventListener(`visibilitychange`,()=>{document.hidden||H()});function U(){E?.close(),E=null,T=null,w?.dispose(),w=null,N.replaceChildren()}async function W(){let e=++O;U(),D=!1,k=!1,F(`connecting…`);let t;try{t=await h()}catch(e){F(`could not load the terminal: ${String(e)}`,{label:`Retry`,run:()=>void W()});return}if(e!==O)return;w=new t.Terminal({fontFamily:A.fontFamily,fontSize:A.fontSize,cursorBlink:A.cursorBlink,scrollback:2e3,theme:_}),w.open(N),v(w),T=new t.FitAddon,w.loadAddon(T),T.observeResize(),T.fit();let n=new WebSocket(`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/api/terminal?cwd=${encodeURIComponent(C)}`);n.binaryType=`arraybuffer`,E=n,n.onopen=()=>{e===O&&(F(``),B(),w?.focus())},n.onmessage=t=>{if(e!==O)return;if(typeof t.data!=`string`){w?.write(new Uint8Array(t.data));return}let r;try{r=JSON.parse(t.data)}catch{D=!0,F(`invalid terminal response`,{label:`Reconnect`,run:()=>void W()}),n.close();return}if(r.t===`exit`){if(k){k=!1,W();return}D=!0,F(`shell exited (${r.code??`?`})`,{label:`Restart`,run:()=>void W()})}else r.t===`error`&&(D=!0,F(r.message??`terminal error`,{label:`Retry`,run:()=>void W()}))},n.onclose=()=>{e!==O||D||F(`disconnected`,{label:`Reconnect`,run:()=>void W()})},w.onData(e=>{n.readyState===WebSocket.OPEN&&n.send(JSON.stringify({t:`in`,d:e}))}),w.onResize(({cols:e,rows:t})=>{n.readyState===WebSocket.OPEN&&n.send(JSON.stringify({t:`resize`,cols:e,rows:t}))})}return n(s,e=>{let t=e?.startsWith(`/`)?e:C||m()||u()[0]||``;if(t===C&&w){z(),!D&&E&&E.readyState>WebSocket.OPEN?W():(H(),w.focus());return}if(C=t,z(),!C){F(`No project yet — pick a folder from the chip.`);return}W()},c)}export{b as createTerminalView};
@@ -33,8 +33,8 @@
33
33
  which style.css pays for with the safe-area inset. -->
34
34
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
35
35
  <title>Pier</title>
36
- <script type="module" crossorigin src="/assets/index-DHxoYoeq.js"></script>
37
- <link rel="stylesheet" crossorigin href="/assets/index-DuZ2vERd.css">
36
+ <script type="module" crossorigin src="/assets/index-BrBNzaid.js"></script>
37
+ <link rel="stylesheet" crossorigin href="/assets/index-BH7ir5I4.css">
38
38
  </head>
39
39
  <!-- The document never scrolls: this is a fixed-viewport workbench, and every
40
40
  scrollable region is an inner pane. h-dvh, not h-screen, because 100vh can
@@ -79,21 +79,13 @@
79
79
  <span class="chev">▶</span>Console
80
80
  </summary>
81
81
  <ul class="pb-1 text-[13.5px]">
82
+ <!-- One row for the tasks area: Tasks, Runs and Activity are tabs of
83
+ the Automation page (views.ts), not three sidebar entries. -->
82
84
  <li><button type="button" id="open-tasks"
83
85
  class="flex w-full cursor-pointer items-center gap-2 py-1.5 pl-6 pr-3 text-left hover:bg-neutral-100">
84
86
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5 flex-none text-neutral-400">
85
87
  <path d="M6 3h8M6 8h8M6 13h8M2 3h1M2 8h1M2 13h1" />
86
- </svg>Tasks</button></li>
87
- <li><button type="button" id="open-runs"
88
- class="flex w-full cursor-pointer items-center gap-2 py-1.5 pl-6 pr-3 text-left hover:bg-neutral-100">
89
- <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5 flex-none text-neutral-400">
90
- <path d="m5 3 7 5-7 5z" stroke-linejoin="round" />
91
- </svg>Runs</button></li>
92
- <li><button type="button" id="open-activity"
93
- class="flex w-full cursor-pointer items-center gap-2 py-1.5 pl-6 pr-3 text-left hover:bg-neutral-100">
94
- <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5 flex-none text-neutral-400">
95
- <path d="M1.5 8h3l2-4.5 3 9L11.5 8h3" stroke-linecap="round" stroke-linejoin="round" />
96
- </svg>Activity</button></li>
88
+ </svg>Automation</button></li>
97
89
  <li><button type="button" id="open-boards"
98
90
  class="flex w-full cursor-pointer items-center gap-2 py-1.5 pl-6 pr-3 text-left hover:bg-neutral-100">
99
91
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5 flex-none text-neutral-400">
@@ -148,9 +140,17 @@
148
140
  <button type="button" id="mobile-menu" aria-label="Session actions"
149
141
  class="hidden h-10 w-10 flex-none cursor-pointer items-center justify-center rounded-md text-[20px] leading-none text-neutral-500 active:bg-neutral-200">⋯</button>
150
142
  </header>
151
- <section id="activity-view" class="hidden min-h-0 flex-1 flex-col"></section>
152
- <section id="runs-view" class="hidden min-h-0 flex-1 flex-col"></section>
153
- <section id="tasks-view" class="hidden min-h-0 flex-1 flex-col"></section>
143
+ <!-- Automation hosts three views under one title and tab strip; the
144
+ strip's active pill tracks the route (#/tasks, #/runs, #/activity). -->
145
+ <section id="automation-view" class="hidden min-h-0 flex-1 flex-col">
146
+ <header class="flex h-10 flex-none items-center gap-3 border-b border-neutral-200 bg-white px-4 max-md:hidden">
147
+ <span class="font-medium">Automation</span>
148
+ </header>
149
+ <div id="automation-tabs" class="tabstrip bg-white"></div>
150
+ <section id="tasks-view" class="hidden min-h-0 flex-1 flex-col"></section>
151
+ <section id="runs-view" class="hidden min-h-0 flex-1 flex-col"></section>
152
+ <section id="activity-view" class="hidden min-h-0 flex-1 flex-col"></section>
153
+ </section>
154
154
  <section id="boards-view" class="hidden min-h-0 flex-1 flex-col"></section>
155
155
  <section id="settings-view" class="hidden min-h-0 flex-1 flex-col"></section>
156
156
  <section id="files-view" class="hidden min-h-0 flex-1 flex-col"></section>
Binary file
Binary file
package/docs/deploy.md CHANGED
@@ -280,7 +280,7 @@ hard-stop paths. Let active work finish first when using either one.
280
280
  ## Updating
281
281
 
282
282
  ```sh
283
- pier update # installs the latest release; hard-stops/restarts Pier
283
+ pier update # installs the latest release, then hard-stops/restarts Pier
284
284
  pier update --check # only says whether one exists
285
285
  ```
286
286
 
@@ -300,7 +300,7 @@ npm ci && npm run build
300
300
  systemctl --user start pier
301
301
  ```
302
302
 
303
- For a service install, `pier update` stops Pier first; it does not use the
303
+ For a service install, `pier update` hard-stops Pier; it does not use the
304
304
  graceful `pier restart` path. The Console's **Update now** and the automatic
305
305
  path do: both drain (new work refused, running turns finished, the rest
306
306
  ledgered for the next boot to report) before the updater unit is started.
@@ -309,9 +309,19 @@ Either way the updater snapshots the database to
309
309
  `~/.pier/db/backups/pier.db.release-<version>.bak` before npm touches the
310
310
  package — `<version>` being the Pier that is being replaced, i.e. the release to
311
311
  reinstall if that copy is ever restored. This happens for every release,
312
- including releases with no schema change. If installation or backup fails, the
313
- updater unit still tries to start the previously installed service and reports
314
- the failure in its journal.
312
+ including releases with no schema change.
313
+
314
+ Both of those steps run while Pier is still serving: the snapshot is taken
315
+ through a read-only connection, so it is consistent on a live database, and npm
316
+ writes into the global prefix rather than into the running process. Only the
317
+ stop and the start that follow them are downtime — a second or two instead of
318
+ the ten to twenty an install takes. A backup or install that fails therefore
319
+ never stops anything; the failure is in the updater's journal and the running
320
+ Pier keeps serving the version it already loaded. (For those seconds the live
321
+ process is running code whose files on disk have already been replaced: a
322
+ browser left open on the old page can see a lazily loaded asset 404 until it
323
+ reloads. On the drained paths nothing else is running by then; `pier update`
324
+ does not drain, which is the same reason to let active work finish first.)
315
325
 
316
326
  ### Automatic updates
317
327
 
@@ -380,9 +390,10 @@ Type=oneshot
380
390
  # recorded PATH as pier.service, and recorded rather than sourced from a login
381
391
  # shell at run time: a dotfile must not get to decide which node npm uses.
382
392
  Environment="PATH=/path/to/node/bin:/your/shell/PATH:/usr/local/bin:/usr/bin:/bin"
383
- ExecStart=systemctl --user stop pier.service
384
393
  ExecStart=/path/to/node /path/to/pier/dist/cli.js backup
385
394
  ExecStart=/path/to/node /recorded/path/to/npm install -g @timqi/pier@latest
395
+ # Last: everything above it runs with Pier still up, so the stop is the downtime.
396
+ ExecStart=systemctl --user stop pier.service
386
397
  ExecStopPost=systemctl --user start pier.service
387
398
  ```
388
399
 
@@ -394,8 +405,9 @@ Deliberately **not** a `systemd.timer`. An unattended update is a machine that
394
405
  rewrites its own code from the network while holding your API keys, and its hard
395
406
  stop interrupts whatever session was mid-turn. Pier notices a newer release
396
407
  and says so in the workbench footer; starting the update stays a decision someone
397
- makes. The updater's `ExecStopPost` is what brings the service back after both
398
- success and failure.
408
+ makes. The updater's `ExecStopPost` is what brings the service back: after a
409
+ successful stop, and — as a no-op, since nothing was stopped — after a backup or
410
+ install that failed.
399
411
 
400
412
  ## Remote access
401
413
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timqi/pier",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "A self-hosted workspace for coding agents: web workbench and IM channels in front of Pi sessions",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": "github:timqi/pier",
@@ -7,9 +7,10 @@ description: Delegate work to Pier subagents with the task tool — one-shot, pa
7
7
 
8
8
  ## Core model
9
9
 
10
- - Every run executes a persisted task definition. An inline `task` draft
11
- (`operation:"run"` without `task_id`) creates and runs a one-shot subagent
12
- atomically; it is tagged `kind:"subagent"` and hidden from task lists.
10
+ - Every run executes a persisted task definition. A `run` without `task_id`
11
+ — a bare `prompt`, or a full `task` draft — creates and runs a one-shot
12
+ subagent atomically; it is tagged `kind:"subagent"` and hidden from task
13
+ lists. You never name or file it: the name is the prompt's first line.
13
14
  - **Nothing blocks.** Every operation returns immediately; results, group
14
15
  joins, and decision replies arrive later as system follow-up messages in
15
16
  your session. Your only waiting primitive is ending your turn.
@@ -20,11 +21,17 @@ description: Delegate work to Pier subagents with the task tool — one-shot, pa
20
21
  ## Single delegation (the common case)
21
22
 
22
23
  ```json
23
- {"operation":"run","task":{"name":"review-auth","action":{
24
- "type":"agent","session":{"mode":"fresh","cwd":"/abs/project"},
25
- "prompt":"Review src/auth/*.ts for injection risks. Output: file:line + issue + fix."}}}
24
+ {"operation":"run","prompt":"Review src/auth/*.ts for injection risks. Output: file:line + issue + fix."}
26
25
  ```
27
26
 
27
+ That is the whole call: a fresh session in **your own directory**. Add `cwd`
28
+ to place it elsewhere — absolute, or relative to your directory
29
+ (`"cwd":"../pier.feature-x"` for a sibling worktree); it must already exist.
30
+ `launch` picks a model/thinking level, `name` overrides the label. The full
31
+ `task` draft form (`{"name","action":{"type":"agent","session":{...},"prompt"}}`)
32
+ is for what the shorthand cannot say: `reuse` a session, `timeoutSeconds`,
33
+ `callback`.
34
+
28
35
  Returns a run summary (`runId`, `state:"queued"`, ids). Finish your turn; the
29
36
  result arrives as a follow-up. `callback:"none"` silences it.
30
37
 
@@ -32,7 +39,8 @@ A summary's `triggerSource` is who fired that run (`agent` when you did, plus
32
39
  `manual` / `cron` / `watch` / `task`); a definition's `trigger` is only its
33
40
  schedule policy, where `manual` means on-demand — by a human or by you.
34
41
 
35
- - `fresh`: clean context, requires `cwd` — how a child normally starts.
42
+ - `fresh`: clean context in a `cwd` (yours when omitted) — how a child
43
+ normally starts.
36
44
  `reuse`: sends work to an existing session by id, continuing its history.
37
45
  There is no way to copy your context into a child: what the child needs, you
38
46
  write down.
@@ -50,13 +58,14 @@ schedule policy, where `manual` means on-demand — by a human or by you.
50
58
 
51
59
  ## Parallel fan-out (core-joined)
52
60
 
53
- Pass `tasks[]` (each entry a draft or `{"task_id":"..."}`) and Pier joins the
54
- group in core — you never track run ids across turns:
61
+ Pass `tasks[]` (each entry a prompt string, `{"prompt","cwd"?}`, a full
62
+ draft, or `{"task_id":"..."}`) and Pier joins the group in core — you never
63
+ track run ids across turns:
55
64
 
56
65
  ```json
57
66
  {"operation":"run","join":"all","tasks":[
58
- {"name":"review-correctness","action":{...}},
59
- {"name":"review-tests","action":{...}}]}
67
+ "Review src/ for correctness bugs. Output: file:line + issue.",
68
+ {"prompt":"Review the tests for gaps. Output: missing case + file.","cwd":"packages/web"}]}
60
69
  ```
61
70
 
62
71
  - `join:"all"` (default): one aggregated follow-up when every member
@@ -1,5 +0,0 @@
1
- import{F as e,I as t,K as n,M as r,R as i,T as a,V as o,z as s}from"./index-DHxoYoeq.js";var c=(e,t={})=>{let n=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);return n},l=t=>t===null?`-`:e(Date.now()-t),u={light:{edge:`#a3a3a3`,callback:`#0891b2`,message:`#d97706`,scheduler:{fill:`#f5f3ff`,stroke:`#a78bfa`,text:`#5b21b6`},console:{fill:`#eff6ff`,stroke:`#93c5fd`,text:`#1d4ed8`},task:{fill:`#fffbeb`,stroke:`#fbbf24`,text:`#92400e`},process:{fill:`#f5f5f5`,stroke:`#a3a3a3`,text:`#525252`,dash:`4 3`},streaming:{fill:`#ffffff`,stroke:`#10b981`,text:`#262626`},idle:{fill:`#fafafa`,stroke:`#d4d4d4`,text:`#737373`}},dark:{edge:`#7a7a7a`,callback:`#3fc3dd`,message:`#e0a13a`,scheduler:{fill:`#2b2440`,stroke:`#7d63c9`,text:`#c9b8f5`},console:{fill:`#1f2a3d`,stroke:`#4a7fbf`,text:`#a8c8f0`},task:{fill:`#3a2f1c`,stroke:`#b8862a`,text:`#f0d49a`},process:{fill:`#262626`,stroke:`#5c5c5c`,text:`#a3a3a3`,dash:`4 3`},streaming:{fill:`#22302a`,stroke:`#10b981`,text:`#e5e5e5`},idle:{fill:`#212121`,stroke:`#4a4a4a`,text:`#9a9a9a`}}},d=()=>u[document.documentElement.dataset.theme===`dark`?`dark`:`light`];function f(e,u,f){let p=`sessions`,m=`active`,h={sessions:[],runs:[],messages:[]},g=``,_=s(async()=>{let r=m,i=await o(`/api/activity?scope=${r}`,`Failed to load activity`);if(!i.ok){g=``,e.replaceChildren(t(`p`,`p-4 text-[13px] text-red-600`,i.error));return}if(r!==m)return;let a=JSON.stringify(i.value);if(`${r}:${a}`===g)return;g=`${r}:${a}`;let s=i.value;h={...s,sessions:s.sessions.map(e=>({...e,title:n(e.title)}))},v()});function v(){let n=t(`header`,`flex h-10 flex-none items-center gap-2 border-b border-neutral-200 px-4 max-md:hidden`,t(`span`,`font-medium`,`Activity`)),r=t(`div`,`tabstrip`);r.append(a(`Sessions`,p===`sessions`,()=>{p=`sessions`,v()}),a(`Relationships`,p===`dependencies`,()=>{p=`dependencies`,v()}));let i=t(`div`,`flex flex-none gap-1 border-b border-neutral-200 px-4 py-2`),o=e=>()=>{m=e,v(),_()};i.append(a(`Current`,m===`active`,o(`active`)),a(`Last 24h`,m===`recent`,o(`recent`)));let s=t(`div`,`min-h-0 flex-1 overflow-auto`);p===`sessions`?y(s):b(s),e.replaceChildren(n,r,i,s)}function y(e){let n=document.createElement(`table`);n.className=`w-full table-fixed text-left text-[12.5px]`,n.innerHTML=`<thead class="bg-neutral-50 text-[10.5px] uppercase text-neutral-400"><tr>
2
- <th class="w-[50%] px-4 py-2 font-semibold md:w-[34%]">Session</th>
3
- <th class="hidden w-[38%] px-2 py-2 font-semibold md:table-cell">Project</th>
4
- <th class="px-2 py-2 font-semibold md:w-[14%]">State</th>
5
- <th class="px-2 py-2 font-semibold">In state</th></tr></thead>`;let r=document.createElement(`tbody`);for(let e of h.sessions){let n=document.createElement(`tr`);n.className=`cursor-pointer border-b border-neutral-100 hover:bg-neutral-50`,n.onclick=()=>u(e.id);let a=t(`button`,`block w-full cursor-pointer truncate text-left font-medium`,e.title??i(e.cwd));a.setAttribute(`type`,`button`),a.title=`${e.id}\n${e.cwd}`,a.onclick=t=>{t.stopPropagation(),u(e.id)},n.append(t(`td`,`px-4 py-2.5`,a,t(`div`,`truncate font-mono text-[11px] text-neutral-400 md:hidden`,e.cwd||`-`)),t(`td`,`hidden truncate px-2 py-2.5 font-mono text-[11.5px] md:table-cell`,e.cwd||`-`),t(`td`,`px-2 py-2.5`,t(`span`,`inline-flex items-center gap-1.5 whitespace-nowrap`,t(`span`,`inline-block h-2 w-2 flex-none rounded-full ${e.state===`streaming`?`animate-pulse bg-green-500`:`bg-neutral-300`}`),e.state)),t(`td`,`px-2 py-2.5 text-neutral-500`,l(e.stateSince))),r.append(n)}n.append(r),e.append(n),h.sessions.length||e.append(t(`p`,`p-4 text-[13px] text-neutral-400`,m===`active`?`No active sessions.`:`No sessions in the last 24 hours.`))}function b(e){let n=new Map,r=[],i=(e,t,r,i)=>{n.has(e)||n.set(e,{id:e,label:t,kind:r,state:i})};for(let e of h.sessions)i(e.id,e.title??e.id.slice(0,10),`session`,e.state);for(let e of h.runs){let t=e.invokedBySessionId??`scheduler`,n=e.targetSessionId??(e.context.definition.action.type===`bash`?`process:${e.id}`:`task:${e.id}`);i(t,t===`scheduler`?`Scheduler`:t.slice(0,10),t===`scheduler`?`scheduler`:`session`),i(n,e.targetSessionId?e.targetSessionId.slice(0,10):e.context.definition.action.type===`bash`?`Bash process`:`Task`,e.targetSessionId?`session`:e.context.definition.action.type===`bash`?`process`:`task`),r.push({from:t,to:n,run:e,kind:`invocation`}),e.callbackSessionId&&(i(e.callbackSessionId,e.callbackSessionId.slice(0,10),`session`),r.push({from:n,to:e.callbackSessionId,run:e,kind:`callback`}))}for(let e of h.messages){if(!e.fromSessionId||!e.toSessionId||e.fromSessionId===e.toSessionId)continue;let t=h.runs.find(t=>t.id===e.runId);if(t){for(let t of[e.fromSessionId,e.toSessionId])i(t,t===`console`?`Console`:t.slice(0,10),t===`console`?`console`:`session`);r.push({from:e.fromSessionId,to:e.toSessionId,run:t,kind:`message`})}}if(!n.size){e.append(t(`p`,`p-4 text-[13px] text-neutral-400`,m===`active`?`No active dependencies.`:`No dependencies in the last 24 hours.`));return}let a=[...n.values()],o=new Set(r.map(e=>e.to)),s=new Map,l=a.filter(e=>!o.has(e.id)).map(e=>e.id);l.length||l.push(a[0].id);for(let e of l)s.set(e,0);for(;l.length;){let e=l.shift();for(let t of r)t.from!==e||s.has(t.to)||(s.set(t.to,s.get(e)+1),l.push(t.to))}for(let e of a)s.has(e.id)||s.set(e.id,0);let p=new Map;for(let e of a){let t=s.get(e.id);p.set(t,[...p.get(t)??[],e])}let g=Math.max(...p.keys())+1,_=Math.max(...[...p.values()].map(e=>e.length)),v=r.some(e=>e.from!==e.to&&s.get(e.from)===s.get(e.to))?40:0,y=56+g*180+(g-1)*110+v,b=56+_*46+(_-1)*30,x=new Map;for(let[e,t]of p)t.forEach((t,n)=>x.set(t.id,{x:28+e*290+90,y:28+n*76+23}));let S=c(`svg`,{width:String(y),height:String(b),viewBox:`0 0 ${y} ${b}`,class:`block`}),C=c(`defs`),w=d();for(let[e,t]of[[`activity-arrow`,w.edge],[`activity-arrow-cb`,w.callback],[`activity-arrow-msg`,w.message]]){let n=c(`marker`,{id:e,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`});n.append(c(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,fill:t})),C.append(n)}S.append(C);let T=new Set;for(let e of r){let t=`${e.from}→${e.to}:${e.kind}`;if(T.has(t))continue;T.add(t);let n=x.get(e.from),r=x.get(e.to),i=c(`path`,{d:n.x===r.x?`M ${n.x+90} ${n.y} C ${n.x+90+46} ${n.y}, ${r.x+90+46} ${r.y}, ${r.x+90} ${r.y}`:(()=>{let e=r.x>n.x,t=n.x+(e?90:-90),i=r.x+(e?-90:90),a=Math.max(36,Math.abs(i-t)*.45)*(e?1:-1);return`M ${t} ${n.y} C ${t+a} ${n.y}, ${i-a} ${r.y}, ${i} ${r.y}`})(),fill:`none`,stroke:e.kind===`callback`?w.callback:e.kind===`message`?w.message:w.edge,"stroke-width":`1.5`,"marker-end":e.kind===`callback`?`url(#activity-arrow-cb)`:e.kind===`message`?`url(#activity-arrow-msg)`:`url(#activity-arrow)`});e.kind===`callback`&&i.setAttribute(`stroke-dasharray`,`6 5`),e.kind===`message`&&i.setAttribute(`stroke-dasharray`,`2 5`),i.classList.add(`cursor-pointer`),i.onclick=()=>f(e.run.id),S.append(i)}let E=/[\u1100-\u11FF\u2E80-\uA4CF\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6]/,D=(e,t)=>{let n=0;for(let r=0;r<e.length;r++)if(n+=E.test(e[r])?2:1,n>t)return`${e.slice(0,r)}…`;return e};for(let e of a){let t=x.get(e.id),n=e.kind===`session`?e.state===`streaming`?w.streaming:w.idle:w[e.kind],r=c(`g`,{transform:`translate(${t.x},${t.y})`});e.kind===`session`&&r.classList.add(`cursor-pointer`),r.onclick=()=>{e.kind===`session`&&u(e.id)};let i=c(`rect`,{x:`-90`,y:`-23`,width:`180`,height:`46`,rx:`8`,fill:n.fill,stroke:n.stroke,"stroke-width":e.kind===`session`&&e.state===`streaming`?`1.5`:`1`});n.dash&&i.setAttribute(`stroke-dasharray`,n.dash),r.append(i);let a=-78;if(e.kind===`session`){let t=c(`circle`,{cx:`-75`,cy:`0`,r:`3.5`,fill:n.stroke});if(e.state===`streaming`){let e=c(`animate`,{attributeName:`opacity`,values:`1;0.3;1`,dur:`1.6s`,repeatCount:`indefinite`});t.append(e)}r.append(t),a=-64}let o=c(`text`,{x:String(a),"text-anchor":`start`,"dominant-baseline":`middle`,"font-size":`11.5`,"font-weight":e.kind===`session`?`500`:`400`,fill:n.text});o.textContent=D(e.label,e.kind===`session`?22:25);let s=c(`title`);s.textContent=e.label===e.id?e.id:`${e.label}\n${e.id}`,r.append(o,s),S.append(r)}let O=e=>t(`span`,`inline-block h-2 w-2 rounded-full ${e}`);e.append(t(`div`,`w-max p-4`,S),t(`div`,`flex flex-wrap gap-x-5 gap-y-1 border-t border-neutral-200 px-4 py-2 text-[11px] text-neutral-500`,t(`span`,``,`Solid: task invocation`),t(`span`,`text-cyan-700`,`Dashed: callback`),t(`span`,`text-amber-700`,`Dotted: supervisor/control`),t(`span`,`inline-flex items-center gap-1.5`,O(`bg-emerald-500`),`streaming`),t(`span`,`inline-flex items-center gap-1.5`,O(`bg-neutral-300`),`idle`)))}let x=r(e,e=>{e===`dependencies`?p=`dependencies`:e===`sessions`&&(p=`sessions`),_()},()=>{e.replaceChildren(),h={sessions:[],runs:[],messages:[]},g=``});return window.addEventListener(`pier:theme`,()=>{x.visible&&v()}),Object.assign(x,{refresh(){x.visible&&_()}})}export{f as createActivityView};
@@ -1 +0,0 @@
1
- import{B as e,G as t,I as n,L as r,M as i,N as a,O as o,V as s,W as c,h as l}from"./index-DHxoYoeq.js";var u=e=>e.public&&e.token?`/p/${e.slug}-${e.token}/`:`/boards/${e.slug}/`;function d(d,f){let p=[],m=``,h=n(`header`,`sticky top-0 z-30 flex h-10 items-center gap-3 border-b border-neutral-200 bg-white px-4`,n(`span`,`font-medium max-md:hidden`,`Boards`)),g=n(`div`,`px-4 py-5`);d.append(n(`div`,`min-h-0 flex-1 overflow-y-auto`,h,g));async function _(n,r){let i=await t(`/api/boards/${n.slug}`,{public:r},`PATCH`);if(i.ok)return n.token=(await i.json().catch(()=>({}))).token??``,x();m=await e(i,`Could not change ${n.slug}`),await S()}async function v(e){m=await c(`/api/boards/${e}`,`DELETE`,`Could not delete ${e}`)??``,await S()}function y(e){let t=n(`div`,`group flex flex-col gap-1 border-b border-neutral-200/70 px-1 py-2.5 last:border-b-0`),i=document.createElement(`a`);i.className=`truncate font-medium text-neutral-800 hover:text-indigo-700`,i.href=u(e),i.target=`_blank`,i.rel=`noreferrer`,i.textContent=e.title;let s=n(`div`,`flex items-center gap-2`,i,n(`span`,`flex-none font-mono text-[11.5px] text-neutral-400`,e.slug)),c=o(``,``,e.public,t=>{e.public=t,_(e,t)});c.className=`ml-auto flex flex-none cursor-pointer items-center gap-1.5 text-[11.5px] text-neutral-500`,c.append(n(`span`,``,`Public`));let d=l(`Delete`,`flex-none cursor-pointer text-[11.5px] text-neutral-400 opacity-0 transition-opacity hover:text-red-600 group-hover:opacity-100`);d.title=`Renames the folder on disk; nothing is erased`,d.onclick=()=>void v(e.slug);let p=a(`flex-none cursor-pointer text-[11.5px] text-neutral-400 opacity-0 transition-opacity hover:text-indigo-600 group-hover:opacity-100`,()=>`${location.origin}${u(e)}`);p.title=`Copy the board's link`,s.append(c,p,d),t.append(s);let m=n(`div`,`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11.5px] text-neutral-500`);e.description&&m.append(n(`span`,`min-w-0 truncate`,e.description)),m.append(n(`span`,`flex-none text-neutral-400`,r(Date.parse(e.updatedAt))));for(let t of e.sessions){let e=l(t.slice(0,8),`flex-none cursor-pointer font-mono text-indigo-600 hover:underline`);e.title=`Open session ${t}`,e.onclick=()=>f(t),m.append(e)}if(e.public&&e.token){let t=n(`span`,`flex-none font-mono text-neutral-400`,u(e));t.title=`Public URL — anyone holding this link can read the board, no password`,m.append(t)}return t.append(m),t}let b=[{title:`Public`,hint:`Readable at /p/<slug>-<token>/ by anyone holding the link.`,wanted:!0},{title:`Private`,hint:`Reachable from the Console only.`,wanted:!1}];function x(){let e=n(`div`,`mx-auto flex max-w-3xl flex-col`);p.length===0&&e.append(n(`p`,`rounded-xl border border-dashed border-neutral-300 px-4 py-6 text-center text-[12.5px] text-neutral-500`,`No boards yet. Ask an agent to build one — it writes a folder under ~/.pier/boards.`));for(let{title:t,hint:r,wanted:i}of b){let a=p.filter(e=>e.public===i);if(a.length===0)continue;let o=n(`section`,`mb-6`);o.append(n(`h2`,`text-[13px] font-semibold text-neutral-700`,t)),o.append(n(`p`,`mb-1 text-[11.5px] leading-snug text-neutral-500`,r));let s=n(`div`,`rounded-xl border border-neutral-200 bg-white px-3`);s.append(...a.map(y)),o.append(s),e.append(o)}g.replaceChildren(...m?[n(`p`,`mb-3 text-[13px] text-red-600`,m)]:[],e)}async function S(){let e=await s(`/api/boards`,`Could not load boards`);if(!e.ok)return m=e.error,x();p=e.value,x(),m=``}let C=i(d,()=>void S());return window.addEventListener(`focus`,()=>{C.visible&&S()}),C}export{d as createBoardsView};