@timqi/pier 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/dist/agent/config-sync.js +124 -92
- package/dist/boards/boards.js +6 -2
- package/dist/db.js +12 -3
- package/dist/main.js +14 -14
- package/dist/service.js +17 -7
- package/dist/settings.js +0 -26
- package/dist/tasks/callbacks.js +1 -1
- package/dist/tasks/definitions.js +4 -0
- package/dist/tasks/groups.js +2 -1
- package/dist/tasks/service.js +14 -4
- package/dist/tasks/tool.js +70 -13
- package/dist/web/auth.js +1 -22
- package/dist/web/fs.js +2 -2
- package/dist/web/instance.js +6 -12
- package/dist/web/public/assets/activity-atEIVnGA.js +5 -0
- package/dist/web/public/assets/activity-atEIVnGA.js.br +0 -0
- package/dist/web/public/assets/activity-atEIVnGA.js.gz +0 -0
- package/dist/web/public/assets/{boards-DMVbV84c.js → boards-DSkfMEvN.js} +1 -1
- package/dist/web/public/assets/boards-DSkfMEvN.js.br +0 -0
- package/dist/web/public/assets/boards-DSkfMEvN.js.gz +0 -0
- package/dist/web/public/assets/{code-C86xKk2k.js → code-1nUOCxAb.js} +1 -1
- package/dist/web/public/assets/explorer-CS1kLPMl.js +5 -0
- package/dist/web/public/assets/explorer-CS1kLPMl.js.br +0 -0
- package/dist/web/public/assets/explorer-CS1kLPMl.js.gz +0 -0
- package/dist/web/public/assets/index-DP1-BW-q.css +2 -0
- package/dist/web/public/assets/index-DP1-BW-q.css.br +0 -0
- package/dist/web/public/assets/index-DP1-BW-q.css.gz +0 -0
- package/dist/web/public/assets/index-a7A8xfoi.js +83 -0
- package/dist/web/public/assets/index-a7A8xfoi.js.br +0 -0
- package/dist/web/public/assets/index-a7A8xfoi.js.gz +0 -0
- package/dist/web/public/assets/runs-bHSlJwXk.js +1 -0
- package/dist/web/public/assets/runs-bHSlJwXk.js.br +0 -0
- package/dist/web/public/assets/runs-bHSlJwXk.js.gz +0 -0
- package/dist/web/public/assets/settings-CrC-yuXh.js +6 -0
- package/dist/web/public/assets/settings-CrC-yuXh.js.br +0 -0
- package/dist/web/public/assets/settings-CrC-yuXh.js.gz +0 -0
- package/dist/web/public/assets/task-runs-C2PHAhAf.js +3 -0
- package/dist/web/public/assets/task-runs-C2PHAhAf.js.br +0 -0
- package/dist/web/public/assets/task-runs-C2PHAhAf.js.gz +0 -0
- package/dist/web/public/assets/tasks-7S90iYr1.js +4 -0
- package/dist/web/public/assets/tasks-7S90iYr1.js.br +0 -0
- package/dist/web/public/assets/tasks-7S90iYr1.js.gz +0 -0
- package/dist/web/public/index.html +16 -24
- package/dist/web/public/index.html.br +0 -0
- package/dist/web/public/index.html.gz +0 -0
- package/dist/web/server.js +4 -4
- package/docs/deploy.md +23 -15
- package/package.json +2 -9
- package/skills/pier-tasks/SKILL.md +24 -13
- package/dist/web/public/assets/__vite-browser-external-2447137e-BvRk9kiK.js +0 -0
- package/dist/web/public/assets/activity-Cw0LRVNI.js +0 -5
- package/dist/web/public/assets/activity-Cw0LRVNI.js.br +0 -0
- package/dist/web/public/assets/activity-Cw0LRVNI.js.gz +0 -0
- package/dist/web/public/assets/boards-DMVbV84c.js.br +0 -0
- package/dist/web/public/assets/boards-DMVbV84c.js.gz +0 -0
- package/dist/web/public/assets/explorer-DTvsy5Rs.js +0 -5
- package/dist/web/public/assets/explorer-DTvsy5Rs.js.br +0 -0
- package/dist/web/public/assets/explorer-DTvsy5Rs.js.gz +0 -0
- package/dist/web/public/assets/ghostty-web-CvSZragH.js +0 -13
- package/dist/web/public/assets/ghostty-web-CvSZragH.js.br +0 -0
- package/dist/web/public/assets/ghostty-web-CvSZragH.js.gz +0 -0
- package/dist/web/public/assets/index-DHxoYoeq.js +0 -79
- package/dist/web/public/assets/index-DHxoYoeq.js.br +0 -0
- package/dist/web/public/assets/index-DHxoYoeq.js.gz +0 -0
- package/dist/web/public/assets/index-DuZ2vERd.css +0 -2
- package/dist/web/public/assets/index-DuZ2vERd.css.br +0 -0
- package/dist/web/public/assets/index-DuZ2vERd.css.gz +0 -0
- package/dist/web/public/assets/runs-jY40JBP-.js +0 -1
- package/dist/web/public/assets/runs-jY40JBP-.js.br +0 -0
- package/dist/web/public/assets/runs-jY40JBP-.js.gz +0 -0
- package/dist/web/public/assets/settings-Dux7PIKF.js +0 -6
- package/dist/web/public/assets/settings-Dux7PIKF.js.br +0 -0
- package/dist/web/public/assets/settings-Dux7PIKF.js.gz +0 -0
- package/dist/web/public/assets/task-runs-DKvtBVxS.js +0 -3
- package/dist/web/public/assets/task-runs-DKvtBVxS.js.br +0 -0
- package/dist/web/public/assets/task-runs-DKvtBVxS.js.gz +0 -0
- package/dist/web/public/assets/tasks-CqfrOVIt.js +0 -4
- package/dist/web/public/assets/tasks-CqfrOVIt.js.br +0 -0
- package/dist/web/public/assets/tasks-CqfrOVIt.js.gz +0 -0
- package/dist/web/public/assets/terminal-DL_0yEy7.js +0 -2
- package/dist/web/public/assets/terminal-DL_0yEy7.js.br +0 -0
- package/dist/web/public/assets/terminal-DL_0yEy7.js.gz +0 -0
- package/dist/web/terminal.js +0 -369
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{A as e,B as t,C as n,D as r,E as i,I as a,K as o,M as s,N as c,T as l,V as u,W as d,_ as f,b as p,c as m,d as h,f as g,g as _,h as v,j as y,k 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 ee,y as k}from"./index-a7A8xfoi.js";import{n as A,t as j}from"./code-1nUOCxAb.js";var M={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}},N=()=>`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(JSON.stringify(M))}`,P=()=>k(`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."]),F=(e=`left`)=>k(`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 I(){let e=v(`Create Slack app ↗`,!0);e.classList.add(`mt-1`,`w-fit`),e.onclick=()=>window.open(N(),`_blank`,`noreferrer`);let t=c(`btn w-fit text-[12.5px]`,()=>JSON.stringify(M,null,2));return k(`Creating a Slack app`,[b(`Opens Slack with every scope, event and Socket Mode already filled in. Pick your workspace → Create.`,e),"`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.",b(`Prefer to paste it yourself? Create the app from a manifest and use this:`,t)])}var L=()=>k(`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.`]),R=(e=`left`)=>k(`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),te=()=>k(`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.`]),z=(e=`left`)=>k(`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),B=[[`telegram`,`Telegram`],[`slack`,`Slack`],[`lark`,`Lark`]],V=(e,t)=>a(`span`,`flex items-center gap-1.5 text-[13px] text-neutral-400`,a(`span`,``,e),t),ne={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`},H=`pier.channelsPlatform`;function re(e){let t=localStorage.getItem(H),n=B.some(([e])=>e===t)?t:`telegram`,i=null,o=[],c=a(`div`,`ml-auto flex items-center gap-1.5 text-[11.5px]`),p=a(`div`,`sticky top-0 z-30 flex items-center gap-1 border-b border-neutral-200 bg-white px-4 py-2`,c),m=a(`div`,`px-4 py-5`);e.append(a(`div`,`min-h-0 flex-1 overflow-y-auto bg-neutral-50/60`,p,m));function h(){p.replaceChildren(...B.map(([e,t])=>ee(t,e===n,()=>{y&&j(),n=e,localStorage.setItem(H,e),M()})),c)}let y,b=!1,x=null;function C(e){if(c.replaceChildren(),e!==`clean`){if(c.className=`ml-auto flex items-center gap-1.5 text-[11.5px] ${g[e]}`,e===`saving`)c.append(a(`span`,`spinner`),a(`span`,``,`Saving…`));else if(e===`saved`)c.append(a(`span`,``,`✓`),a(`span`,``,`Saved`)),setTimeout(()=>{c.textContent?.includes(`Saved`)&&C(`clean`)},2e3);else{let e=S(`Retry`,`cursor-pointer underline`);e.onclick=j,c.append(a(`span`,``,`⚠`),a(`span`,``,`Save failed`),e)}}}function O(){C(`saving`),clearTimeout(y),y=setTimeout(j,500)}let k=e=>t=>{e(t),O()};async function A(e){b=!0,C(`saving`);try{C((await d(`/api/channels/${e.platform}`,e.config,`PUT`)).ok?`saved`:`failed`)}catch{C(`failed`)}finally{b=!1;let e=x;x=null,e&&A(e)}}function j(){if(clearTimeout(y),y=void 0,!i)return;let e={platform:n,config:i};b?x=e:A(e)}async function M(){if(!o.length){let e=await u(`/api/models`,`Could not load the model catalog`);e.ok&&(o=e.value)}let e=await u(`/api/channels/${n}`,`Failed to load`);if(!e.ok){i=null,h(),m.replaceChildren(f(e.error));return}i=e.value,C(`clean`),W()}function N(e){let t=n===`slack`,i=n===`lark`,a=l(e.token,t?`xoxb-…`:i?`cli_…`:`123456789:AA…`,k(t=>e.token=t),!0),o=l(e.appToken,i?``:`xapp-…`,k(t=>e.appToken=t),!0),s=E(e.cwd,`(pier process cwd)`,k(t=>e.cwd=t));return _(`Connection`,t?`Pier connects over Socket Mode; no public URL or webhook needed.`:i?`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.`,r(`Enabled`,`Start the adapter when Pier boots.`,e.enabled,k(t=>{e.enabled=t,h()})),D(i?`App ID`:`Bot token`,a,{hint:`Stored locally, shown masked once saved.`,help:n===`telegram`?P():t?I():te()}),...t?[D(`App-level token`,o,{hint:`Opens the Socket Mode connection. Needs connections:write.`}),r(`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),L())]:[],...i?[D(`App Secret`,o,{hint:`From Credentials & Basic Info, beside the App ID.`})]:[],D(`Default working directory`,s.el,{hint:`Where sessions this channel opens start.`}))}function re(e){return _(`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.`,r(`Require mention in groups`,`Ignore group messages that do not @mention or reply to the bot.`,e.requireMention,k(t=>e.requireMention=t)),r(`Require bound user`,`Only users bound with a code below can drive the agent.`,e.requireBind,k(t=>e.requireBind=t)),...n===`slack`?[V(`Thread mode: always on`,R())]:n===`lark`?[V(`Thread mode: always on`,z())]:[r(`Topic mode`,`In a forum group, each new request opens its own topic and its own session.`,e.topicMode,k(t=>e.topicMode=t),F())],T(`Model & reasoning`,e,o,k(t=>{e.model=t.model,e.thinking=t.thinking,W()})))}function U(e){let t=a(`span`,`font-mono text-[15px] font-semibold tracking-widest`),r=a(`div`,`hidden items-center gap-2 rounded-lg bg-indigo-50 px-3 py-2 text-[12.5px] text-indigo-800`,t,a(`span`,`text-[11.5px] text-indigo-500`,`DM the bot /bind <code> · expires in 10 min`)),i=v(`Generate bind code`);i.onclick=async()=>{let e=await fetch(`/api/channels/${n}/bind-code`,{method:`POST`});if(!e.ok)return;let{code:i}=await e.json();t.textContent=i,r.classList.replace(`hidden`,`flex`)};let o=a(`div`,`flex flex-col`);e.users.length||o.append(f(`No bound users yet.`));for(let t of e.users){let e=S(`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/${n}/users/${encodeURIComponent(t.id)}`,{method:`DELETE`}),await M()},o.append(a(`div`,`group flex items-center gap-2.5 border-b border-neutral-100 py-2 last:border-0`,a(`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()),a(`span`,`min-w-0 flex-1 truncate text-[13px] text-neutral-700`,t.name),a(`span`,`flex-none font-mono text-[11.5px] text-neutral-400`,t.id),e))}return _(`Bound users`,`A code is single-use and expires; redeeming it in a DM binds that account.`,o,a(`div`,`flex flex-col gap-2`,i,r))}function ie(e,t){let i=a(`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`}`),s=a(`div`,`flex items-center gap-2`,a(`span`,`min-w-0 flex-1 truncate text-[13px] font-medium ${t.enabled?`text-neutral-800`:`text-neutral-400`}`,t.name||t.id),w(t.kind,ne[t.kind]),a(`span`,`flex-none font-mono text-[11px] text-neutral-400`,t.id)),c=r(``,``,t.enabled,k(e=>{t.enabled=e,W()}));c.classList.add(`flex-none`,`items-center`),s.append(c);let l=a(`div`,`mt-3 flex flex-wrap items-center gap-x-6 gap-y-2`);t.kind===`dm`?l.append(a(`span`,`text-[13px] text-neutral-400`,n===`telegram`?`Direct message · bound users only, mention and topics not applicable`:`Direct message · bound users only, mention not applicable`)):l.append(r(`Require mention`,``,t.requireMention,k(e=>t.requireMention=e)),r(`Require bind`,``,t.requireBind,k(e=>t.requireBind=e)),n===`slack`?V(`Thread mode: always on`,R(`right`)):n===`lark`?V(`Thread mode: always on`,z(`right`)):t.kind===`forum`?r(`Topic mode`,``,t.topicMode,k(e=>t.topicMode=e),F(`right`)):V(`Topic mode: forum groups only`,F(`right`)));let u=E(t.cwd,``,k(e=>t.cwd=e)),d=a(`div`,`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2`,D(`Working directory`,u.el),T(`Model & reasoning`,t,o,k(e=>{t.model=e.model,t.thinking=e.thinking,W()})));return i.append(s,l,d),i}function ae(e){let t=a(`div`,`flex flex-col gap-2.5`);return e.chats.length?t.append(...e.chats.map(t=>ie(e,t))):t.append(f(`None yet. Chats appear here after the bot sees a message in them.`)),_(n===`slack`?`Channels`:`Chats`,`Discovered from inbound traffic — no platform reliably lists every chat a bot is in.`,t)}function W(){if(!i)return;h();let e=a(`div`,`mx-auto flex max-w-3xl flex-col gap-4`);e.append(N(i),re(i),U(i),ae(i)),m.replaceChildren(e)}return s(e,()=>void M(),()=>{y&&j()})}function U(){let e=a(`div`,`min-h-0 min-w-0 flex-1 overflow-y-auto p-4`),n=a(`div`,`mx-auto flex max-w-3xl min-w-0 flex-col gap-4`),i=a(`p`,`text-[12px] break-words`),o=a(`section`,`flex min-w-0 flex-col gap-3 border-b border-neutral-200 pb-4`),s=a(`section`,`flex min-w-0 flex-col gap-3`);n.append(a(`h2`,`text-[14px] font-semibold text-neutral-700`,`Configuration sync`),i,o,s),e.append(n);let f=null,p=!1,m=!1,h=0,g=``,_=!1,y=e=>e?new Date(e).toLocaleString():`Never`;async function b(){let e=h,t=await u(`/api/config-sync`,`Could not load configuration sync`,{cache:`no-store`});if(!(m||e!==h)){if(!t.ok){O(i,`failed`,t.error);return}f=t.value,_||(g=f.sourceUrl),C()}}async function x(e){if(!p){++h,p=!0,C(),O(i,`saving`,`Working...`);try{let n=await d(`/api/config-sync`,{action:e,...e===`subscribe`?{url:g}:{}});if(!n.ok)throw Error(await t(n,`Configuration sync failed`));let r=await n.json();f=r,_=!1,g=r.sourceUrl,O(i,`saved`,r.result??`Saved`)}catch(e){O(i,`failed`,e instanceof Error?e.message:`Configuration sync failed`),await b()}finally{p=!1,m||C()}}}function S(e,t){let n=v(e);return n.disabled=p,n.onclick=()=>{x(t)},n}function C(){if(!f||m)return;if(o.replaceChildren(a(`h3`,`text-[13px] font-medium text-neutral-700`,`Publish`)),f.publishedPath){let e=`${f.publicUrl||window.location.origin}${f.publishedPath}`,t=l(e,``,()=>{},!0);t.readOnly=!0,t.setAttribute(`aria-label`,`Sharing URL`),o.append(t,a(`div`,`flex flex-wrap items-center gap-2`,c(`btn text-[12px]`,()=>e),S(`Revoke link`,`revoke`)))}else o.append(a(`div`,``,S(`Generate link`,`publish`)));o.append(a(`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=l(g,`https://example.com/config-sync/...`,e=>{g=e,_=!0},!0);e.type=`url`,e.setAttribute(`aria-label`,`Configuration source URL`),e.disabled=p||f.enabled;let t=r(`Automatic sync`,``,f.enabled,e=>{x(e?`subscribe`:`pause`)});t.querySelector(`input`).disabled=p;let n=a(`div`,`flex flex-wrap items-center gap-3`,t);f.enabled&&n.append(S(`Sync now`,`sync`)),s.replaceChildren(a(`h3`,`text-[13px] font-medium text-neutral-700`,`Source`),D(`Source URL`,e),n);let i=a(`dl`,`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1 text-[12px]`);for(let[e,t]of[[`Last checked`,y(f.lastChecked)],[`Last applied`,y(f.lastApplied)],[`Next check`,f.enabled?y(f.nextRunAt):`Paused`]])i.append(a(`dt`,`text-neutral-500`,e),a(`dd`,`min-w-0 break-words text-neutral-700`,t));if(s.append(i),f.error&&s.append(a(`p`,`text-[12px] break-words text-red-600`,f.error)),f.needsReload&&s.append(a(`p`,`text-[12px] text-amber-700`,`Reload pending; retry synchronization.`)),f.taskId){let e=a(`a`,`text-[12px] text-indigo-600 hover:underline`,`Sync task history`);e.href=`#/tasks/${encodeURIComponent(f.taskId)}`,s.append(e)}}b();let w=setInterval(()=>{!p&&!_&&b()},15e3);return{el:e,dispose:()=>{m=!0,clearInterval(w)}}}async function ie(e,n){let r;try{r=await d(`/api/settings`,e,`PUT`)}catch(e){return{outcome:{state:`failed`,text:`Could not save: ${String(e)}`}}}if(!r.ok)return{outcome:{state:`failed`,text:await t(r,`could not save`)}};let i;try{i=await r.json()}catch(e){return{outcome:{state:`failed`,text:`Saved, but the answer could not be read: ${String(e)}`}}}return i.toolsSync?.state===`refused`?{outcome:{state:`failed`,text:`Saved, but nothing will install it: ${i.toolsSync.reason}`},answer:i}:i.toolsSync?.state===`waiting`?{outcome:{state:`saved`,text:`Saved — a sync is already running; this change goes in the run right after it.`},answer:i}:{outcome:{state:`saved`,text:n},answer:i}}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,n){let i=`global`,o=null,c=0,f=0,p=``,m=null,g=[],_=``,v=null,b=null,S=()=>{b?.dispose(),b=null},C=()=>{S(),++f,b=U(),I.replaceChildren(b.el)},T=[],E=()=>g.filter(e=>e.kind===`extension`),ee=e=>e.source===`binary`&&e.custom===!0,k=()=>g.filter(e=>e.kind===`tool`),M=document.createElement(`select`);M.className=`select w-full rounded-md border border-neutral-300 px-2 py-1 text-[12.5px] focus:border-indigo-400 focus:outline-none`,M.onchange=()=>{S(),i=M.value,o=null,K.clear(),ne()};let N=a(`div`,`flex flex-none flex-col gap-1 border-b border-neutral-200 px-3 pb-2.5 pt-2`);N.append(a(`span`,`text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,`Scope`),M);let P=a(`div`,`min-h-0 flex-1 overflow-y-auto py-1`),F=a(`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`);F.append(N,P);let I=a(`div`,`flex min-w-0 flex-1 flex-col`),L=a(`div`,`flex min-h-0 flex-1 max-md:flex-col`);L.append(F,I),e.append(L);let R=(e=``)=>`?scope=${encodeURIComponent(i)}${e}`;async function te(){if(i!==`global`){g=[],_=``;return}let e=await u(`/api/settings`,`could not be loaded`,{cache:`no-store`});if(!e.ok){g=[],_=e.error;return}z(e.value),_=``}function z(e){g=e.catalog,T=e.customTools,v=e.toolsTaskId}async function B(e,t){let{outcome:n,answer:r}=await ie(e,t);return r&&(z(r),J(m)),n}function V(e,t){let n={name:e,on:t};return g.find(t=>t.name===e)?.source===`binary`?{tool:n}:{extension:n}}async function ne(){let e=++c;f++;let[t]=await Promise.all([u(`/api/config${R()}`,`failed to load config`,{cache:`no-store`}),te()]);if(e!==c)return;if(!t.ok){J(null),Y(t.error);return}let n=t.value;i===`global`&&n.dir&&(p=n.dir,pe()),m=n,J(n),o?o.type===`sync`&&C():se()}function H(e){return a(`div`,`px-3 pb-0.5 pt-2.5 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e)}let re=()=>{let e=a(`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=()=>a(`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,o){let s=a(`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(a(`span`,`truncate`,e)),o&&s.append(o),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,o){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=a(`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(a(`span`,`chev`,`▶`),a(`span`,`truncate text-neutral-600`,c)),l.link&&f.append(re()),d.append(f,...q(e,l,t,r+1,i,o)),s.push(d)}for(let a of t.files){let t={type:`resource`,kind:e,name:n?`${n}/${a.name}`:a.name};s.push(G(a.name,i(t),!1,()=>o(t),r,a.link?re():void 0))}return s}function J(e){if(!e){P.replaceChildren();return}let t=e=>JSON.stringify(e)===JSON.stringify(o),n=t=>{S(),o=t,J(e),t.type===`file`?ce(t.name):t.type===`bundled`?ue(t.name):t.type===`tools`?$():t.type===`sync`?C():fe(t.kind,t.name)},r=[];if(i===`global`){let e={type:`sync`};r.push(H(`Instance`),G(`Configuration sync`,t(e),!1,()=>n(e)))}r.push(H(`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(H(`bundled with Pier`)),_?r.push(a(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-red-600`,_)):E().length||r.push(a(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-neutral-400`,`none`));for(let e of E()){let i={type:`bundled`,name:e.name};r.push(G(e.name,t(i),!1,()=>n(i),0,e.enabled?W():void 0))}if(!_){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(H(`${i} (read-only)`));let o=e.resources[i];o.length||r.push(a(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-neutral-400`,`none`)),r.push(...q(i,oe(o),``,0,t,n))}P.replaceChildren(...r)}function se(){I.replaceChildren(a(`p`,`px-4 py-3 text-[13px] text-neutral-400`,`Select a file to edit, or browse extensions and skills.`))}function Y(e){I.replaceChildren(a(`p`,`px-4 py-3 text-[13px] text-red-600`,e))}let X=(e,...t)=>a(`div`,`flex flex-none items-center gap-3 border-b border-neutral-200 px-4 py-2`,a(`span`,`font-mono text-[12.5px] text-neutral-500`,e),...t);async function ce(e){let n=++f,r=await u(`/api/config/files/${encodeURIComponent(e)}${R()}`,`failed to load ${e}`,{cache:`no-store`});if(!r.ok){n===f&&Y(r.error);return}if(n!==f)return;let{content:i}=r.value,o=i,s=a(`span`,`text-[11.5px] text-neutral-400`,``),c=a(`button`,`btn btn-primary ml-auto text-[12.5px]`,`Save`),l=document.createElement(`textarea`);l.className=`block min-h-0 flex-1 resize-none bg-white p-4 font-mono text-[13px] leading-relaxed focus:outline-none`,l.spellcheck=!1,l.value=i;let p=async()=>{if(c.disabled)return;let n=l.value;c.disabled=!0,O(s,`saving`,`saving…`);try{let r=await d(`/api/config/files/${encodeURIComponent(e)}${R()}`,{content:n,expected:o},`PUT`);if(!r.ok)return O(s,`failed`,await t(r,`save failed`));let i=await r.json();o=i.content,l.value===n?(l.value=i.content,O(s,`saved`,`saved — applies to new sessions`)):O(s,`idle`,`saved; newer changes are unsaved`)}catch(e){O(s,`failed`,`save failed: ${String(e)}`)}finally{c.disabled=!1}};c.onclick=()=>void p(),l.onkeydown=e=>{(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),p())},l.oninput=()=>{O(s,`idle`,`unsaved changes`)},I.replaceChildren(X(e,s,c),l),l.focus()}function le(e){if(!v)return null;let t=a(`a`,`text-indigo-600 hover:underline`,e);return t.href=`#/tasks/${encodeURIComponent(v)}`,t}let Z=()=>{let e=a(`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){f++;let n=g.find(t=>t.name===e&&t.kind===`extension`);if(!n)return Y(`unknown extension: ${e}`);let i=a(`span`,`text-[11.5px] text-neutral-400`,``);t&&O(i,t.state,t.text);let o=le(`every run of the update task`);I.replaceChildren(X(n.name,a(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,n.source===`binary`?`installed by Pier`:`ships with Pier`)),a(`div`,`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4`,a(`p`,`max-w-2xl text-[13px] leading-relaxed text-neutral-600`,n.summary),a(`dl`,`flex max-w-2xl flex-col gap-1.5`,...(n.source===`bundled`?n.adds:[]).flatMap(e=>[a(`dt`,`font-mono text-[12px] text-neutral-700`,e.name),a(`dd`,`text-[12px] leading-snug text-neutral-500`,`needs ${e.needs}`)]),...n.source===`binary`?[a(`dt`,`font-mono text-[12px] text-neutral-700`,`binary`),a(`dd`,`font-mono text-[12px] leading-snug ${n.binary.error?`text-red-600`:`text-neutral-500`}`,Q(n))]:[]),r(`Enabled`,n.source===`binary`?`Installed into Pier's own bin directory, first on the PATH every session and task 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))),a(`p`,`max-w-2xl text-[12px] leading-snug text-neutral-400`,...n.source===`binary`?o?[`A daily task installs and updates it — its history is `,o,`.`]:[`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.`]),i))}function $(e,t={name:``,toml:``}){f++;let n=a(`span`,`text-[11.5px] text-neutral-400`,``);e&&O(n,e.state,e.text);let i=k(),o=le(`the update task`),s=e=>{let t=a(`div`,`flex min-w-0 flex-1 flex-col gap-0.5`,a(`span`,`flex items-center gap-2 text-[13px] text-neutral-700`,a(`span`,`font-mono`,e.name),...ee(e)?[w(`yours`,`bg-neutral-50 text-neutral-500 ring-neutral-200`)]:[]),a(`span`,`text-[11.5px] leading-snug text-neutral-400`,e.summary||Q(e)),...e.summary?[a(`span`,`font-mono text-[11px] leading-snug ${e.source===`binary`&&e.binary.error?`text-red-600`:`text-neutral-400`}`,Q(e))]:[]),n=r(``,``,e.enabled,t=>void de(e.name,t,e=>$(e))),i=a(`button`,`btn text-[12px] text-neutral-500 hover:text-red-600`,`Remove`);return i.onclick=()=>{i.disabled=!0;let t=ae(e,T);B(t.body,t.saved).then(e=>$(e))},a(`div`,`flex max-w-2xl items-start gap-3 border-b border-neutral-100 py-2.5 last:border-0`,t,...ee(e)?[i]:[],n)},c={...t},u=a(`span`,`font-mono text-[12px] text-neutral-500`,`[tools.<name>]`),d=l(c.name,`claude`,e=>{c.name=e,u.textContent=`[tools.${e.trim()||`<name>`}]`},!0),p=document.createElement(`textarea`);p.className=`${h} 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 m=a(`button`,`btn btn-primary text-[12.5px]`,`Add`);m.onclick=()=>{let e={name:c.name.trim(),toml:c.toml.trim()};if(!e.name||!e.toml)return O(n,`failed`,`A custom tool needs a name and a block with a spec line.`);m.disabled=!0,B({customTools:[...T,e],tool:{name:e.name,on:!0}},`Added ${e.name} — installing now.`).then(e=>$(e,e.state===`failed`?c:void 0))},I.replaceChildren(X(`command-line tools`,a(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,`installed by Pier`)),a(`div`,`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4`,a(`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 `,a(`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.`),_?a(`p`,`max-w-2xl text-[12.5px] text-red-600`,_):a(`div`,`flex max-w-2xl flex-col`,...i.map(s)),a(`div`,`flex max-w-2xl flex-col gap-2 border-t border-neutral-200 pt-4`,a(`span`,`text-[12.5px] font-medium text-neutral-600`,`Add one of your own`),D(`Name`,d),D(`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.`}),a(`div`,`flex items-center gap-3`,u,m)),a(`p`,`max-w-2xl text-[12px] leading-snug text-neutral-400`,...o?[`Installs and daily updates run as `,o,` — output, failures and all.`]:[`Switching one on creates the daily task that installs it and keeps it current.`]),n))}async function de(e,t,n){let r=g.find(t=>t.name===e);n(await B(V(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=++f,r=await u(`/api/config/resource${R(`&kind=${e}&name=${encodeURIComponent(t)}`)}`,`failed to load ${t}`,{cache:`no-store`});if(!r.ok){n===f&&Y(r.error);return}if(n!==f)return;let{content:i}=r.value,o=i.split(`
|
|
3
|
+
`);o.at(-1)===``&&o.pop();let s=await x(t);n===f&&I.replaceChildren(X(t,a(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,`read-only`)),a(`div`,`min-h-0 flex-1 overflow-auto`,j(A(o),s)))}function pe(){M.replaceChildren(new Option(p?`Global (${p})`:`Global`,`global`),...n().map(e=>new Option(`${y(e)} — ${e}`,e))),[...M.options].some(e=>e.value===i)||(i=`global`),M.value=i}return s(e,()=>{pe(),ne()},S)}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=[],r=[],i=!1,s=a(`span`,`text-[11.5px]`,``),c=v(`Save menu`,!0),l=a(`div`,`flex min-w-0 flex-col gap-2`),h=a(`div`,`flex items-center gap-2`),g=a(`div`,`mx-auto flex w-full max-w-3xl min-w-0 flex-col gap-6`);function y(){i=!0,O(s,`idle`,`unsaved changes`)}function b(t){let r=p(t.note??``);r.classList.remove(`w-full`),r.classList.add(`min-w-0`,`flex-1`),r.placeholder=`why this one — pick a preset or write your own`,r.setAttribute(`list`,`model-menu-notes`),r.oninput=()=>{t.note=r.value,y()};let i=n([[`thinking: model default`,``],...m.map(e=>[`thinking: ${o(e)}`,e])],t.thinking??``);i.classList.replace(`w-full`,`w-44`),i.classList.add(`flex-none`),i.onchange=()=>{i.value?t.thinking=i.value:delete t.thinking,y()};let s=v(`Remove`);s.classList.add(`flex-none`),s.onclick=()=>{e=e.filter(e=>e!==t),y(),S()};let c=a(`span`,`w-52 flex-none truncate font-mono text-[12px] text-neutral-700`,G(t));return c.title=G(t),a(`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`,c,i,r,s)}function x(){let t=r.filter(t=>!e.some(e=>G(e)===G(t))),i=n(t.map(e=>[G(e),G(e)]),t[0]?G(t[0]):``);i.classList.replace(`w-full`,`flex-1`),i.classList.add(`min-w-0`);let a=v(`+ Pin model`);a.classList.add(`flex-none`,`whitespace-nowrap`),a.disabled=t.length===0,a.onclick=()=>{let n=t.find(e=>G(e)===i.value);n&&(e.push({...n}),y(),S())},h.replaceChildren(i,a)}function S(){l.replaceChildren(...e.length?e.map(b):[f(`Nothing pinned — every picker shows the curated catalog as is.`)]),x()}async function C(){O(s,`saving`,`saving…`);let n=e.map(({provider:e,id:t,thinking:n,note:r})=>({provider:e,id:t,...n?{thinking:n}:{},...r?.trim()?{note:r.trim()}:{}})),r=await d(`/api/settings`,{modelMenu:n},`PUT`);if(!r.ok)return O(s,`failed`,await t(r,`Could not save`));e=(await r.json()).modelMenu,i=!1,O(s,`saved`,`Saved — agents see it on their next models call.`),S()}c.onclick=()=>void C();function w(){i||(async()=>{let[t,n]=await Promise.all([u(`/api/settings`,`Could not load the menu`),u(`/api/models`,`Could not load the model catalog`)]);if(!t.ok)return O(s,`failed`,t.error);e=t.value.modelMenu,r=n.ok?n.value:[],s.textContent=``,S()})()}let T=a(`datalist`,``);return T.id=`model-menu-notes`,T.append(...oe.map(e=>new Option(e))),g.append(_(`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.`,D(`Pinned models`,l,{hint:`The note is what an agent matches a task against — say when to reach for it, not what it is.`}),D(`Add`,h,{hint:`The list is the live catalog — only models that exist right now can be pinned.`}),a(`div`,`flex items-center gap-3`,c,s),T)),{el:g,load:w}}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=a(`a`,`text-indigo-600 hover:underline`,t);return r.href=n.href,r.target=`_blank`,r.rel=`noreferrer`,r};function J(e,n,r,i){let o=document.createElement(`dialog`);o.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=a(`div`,`flex flex-col gap-2`),l=a(`div`,`flex flex-col gap-2`),u=a(`p`,`text-[12.5px] text-neutral-400`,`Starting…`),f=v(`Cancel`),m=(e,t)=>{u.className=`text-[12.5px] ${g[e]}`,u.textContent=t};o.append(a(`div`,`border-b border-neutral-200 px-4 py-2.5 text-[14px] font-semibold`,n),a(`div`,`flex max-h-[65vh] flex-col gap-3 overflow-y-auto px-4 py-3`,s,l,u),a(`div`,`flex justify-end border-t border-neutral-200 px-4 py-2.5`,f)),document.body.append(o),o.showModal();let h=e.id,_=e.state,y,b,x=new Set,S=!1,C=!1,w=async e=>{if(!C){if(e&&_===`running`){C=!0,f.disabled=!0;try{let e=await d(`/api/providers/flows/${h}/cancel`,{});if(!e.ok&&e.status!==404){m(`failed`,await t(e,`Could not cancel authentication flow`));return}}catch(e){m(`failed`,`Could not cancel authentication flow: ${String(e)}`);return}finally{C=!1,f.disabled=!1}}clearTimeout(y),o.close()}};f.onclick=()=>void w(!0),o.oncancel=e=>{e.preventDefault(),w(!0)},o.onclose=()=>{S=!0,clearTimeout(y),o.remove()};let T=e=>{if(e.type===`auth_url`){let t=a(`div`,`flex flex-col gap-1 text-[12.5px] text-neutral-600`);return e.instructions&&t.append(a(`p`,``,e.instructions)),t.append(q(e.url,`Open authorization page`)??a(`span`,`text-red-600`,`Invalid authorization URL`)),t}if(e.type===`device_code`){let t=a(`div`,`flex flex-col gap-2 text-[12.5px] text-neutral-600`);return t.append(a(`div`,`flex items-center gap-2`,a(`code`,`font-mono text-[17px] font-semibold text-neutral-800`,e.userCode),c(`btn text-[11px]`,()=>e.userCode))),t.append(q(e.verificationUri,`Open verification page`)??a(`span`,`text-red-600`,`Invalid verification URL`)),t}let t=a(`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},E=(e,n)=>{b=n.id;let r;if(n.type===`select`){let e=document.createElement(`select`);e.append(...n.options.map(e=>new Option(e.description?`${e.label} — ${e.description}`:e.label,e.id))),r=e}else{let e=p(``,n.type===`secret`?`password`:`text`);e.placeholder=n.placeholder??``,e.autocomplete=`off`,r=e}r.className=`${r.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 i=v(`Continue`,!0);i.type=`submit`;let o=a(`form`,`flex flex-col gap-2`,a(`label`,`text-[12.5px] font-medium text-neutral-700`,n.message),r,a(`div`,`flex justify-end`,i));o.onsubmit=a=>{a.preventDefault(),i.disabled=!0,(async()=>{try{let i=await d(`/api/providers/flows/${e.id}/respond`,{promptId:n.id,value:r.value});if(S)return;if(!i.ok){m(`failed`,await t(i,`Could not submit response`));return}x.add(n.id),b=void 0,l.replaceChildren(),m(`saving`,`Waiting for provider…`)}catch(e){S||m(`failed`,`Could not submit response: ${String(e)}`)}finally{i.disabled=!1}})()},l.replaceChildren(o),r.focus()},D=e=>{_=e.state,s.replaceChildren(...e.events.map(T));let t=e.prompt&&!x.has(e.prompt.id)?e.prompt:void 0;if(t?.id!==b&&(t?E(e,t):(b=void 0,l.replaceChildren())),e.state===`running`){m(`saving`,t?`Waiting for your response.`:`Waiting for provider…`);return}clearTimeout(y),l.replaceChildren(),e.state===`succeeded`?m(`saved`,`${r} configured.`):m(`failed`,e.state===`cancelled`?`Cancelled.`:e.error??`Authentication failed.`),f.textContent=`Close`,f.onclick=()=>void w(!1),e.state===`succeeded`&&i()},O=async()=>{if(!(S||_!==`running`))try{let e=await fetch(`/api/providers/flows/${h}`,{cache:`no-store`});if(S)return;if(!e.ok){m(`failed`,await t(e,`Authentication status unavailable`)),e.status===404?_=`failed`:y=setTimeout(()=>void O(),1e3);return}D(await e.json()),_===`running`&&(y=setTimeout(()=>void O(),500))}catch(e){if(S)return;m(`failed`,`Authentication status unavailable: ${String(e)}`),y=setTimeout(()=>void O(),1e3)}};D(e),_===`running`&&(y=setTimeout(()=>void O(),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 r=v(`Add provider`,!0);r.classList.add(`ml-auto`);let i=a(`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`,a(`h2`,`text-[13px] font-semibold text-neutral-700`,`Providers`),r),o=a(`div`,`min-h-0 flex-1 overflow-y-auto`);e.replaceChildren(i,o);let s=[],c=``,l=async()=>{o.replaceChildren(a(`p`,`px-4 py-3 text-[13px] text-neutral-400`,`Loading…`));try{let[e,t]=await Promise.all([u(`/api/providers`,`Could not load providers`,{cache:`no-store`}),u(`/api/models`,`the model catalog could not be read`,{cache:`no-store`})]);if(s=t.ok?t.value:[],c=t.ok?``:t.error,!e.ok){o.replaceChildren(f(e.error));return}let n=e.value;r.onclick=()=>Z(n,void 0,l),_(n)}catch(e){o.replaceChildren(f(`Could not load providers: ${String(e)}`))}},p=async e=>{if(window.confirm(`Remove the stored credential for ${e.name}?`))try{let n=await d(`/api/providers/${encodeURIComponent(e.id)}/logout`,{});if(!n.ok){window.alert(await t(n,`Could not remove credential`));return}await l()}catch(e){window.alert(`Could not remove credential: ${String(e)}`)}},m=e=>[...new Set([...(e.models??[]).map(e=>e.id),...s.filter(t=>t.provider===e.id).map(e=>e.id)])],h=(e,t)=>a(`div`,`flex flex-col gap-1`,a(`span`,`text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),a(`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)),g=async(e,n)=>{try{let r=await d(`/api/providers/${encodeURIComponent(e)}/check`,{model:n});return r.ok?await r.json():await t(r,`Could not test`)}catch(e){return`Could not test: ${String(e)}`}},_=e=>{let t=e.filter(e=>e.configured);if(!t.length){o.replaceChildren(f(`No providers configured.`));return}o.replaceChildren(...t.map(t=>{let r=a(`div`,`min-w-0 flex-1`,a(`div`,`truncate text-[13px] font-medium text-neutral-700`,t.name),a(`div`,`truncate font-mono text-[11px] text-neutral-400`,t.id)),i=t.stored===`api_key`?`API key`:t.stored===`oauth`?`OAuth`:t.source??`configured`,o=t.endpoint??`Default endpoint`,s=a(`div`,`flex min-w-32 flex-col items-start gap-1`,w(`configured`,`bg-emerald-50 text-emerald-700 ring-emerald-200`),a(`span`,`max-w-48 truncate text-[11px] text-neutral-500`,i),a(`span`,`max-w-48 truncate text-[11px] text-neutral-400`,o));s.title=o;let u=a(`span`,`text-[11.5px]`,``),d=a(`div`,`hidden flex-col gap-2 px-4 pb-3`,u),f=a(`div`,`flex flex-wrap justify-end gap-1.5`),_=m(t);if(!_.length)O(u,`idle`,c||`No models to test: none are configured here.`),d.classList.replace(`hidden`,`flex`);else{let e=n([[`Model to test…`,``],..._.map(e=>[e,e])],``);e.classList.add(`max-w-52`,`text-[12px]`);let r=v(`Test`);r.disabled=!0,e.onchange=()=>r.disabled=!e.value,r.onclick=()=>{let n=e.value;r.disabled=!0,d.replaceChildren(u),d.classList.replace(`hidden`,`flex`),O(u,`saving`,`asking ${n}…`),g(t.id,n).then(e=>{if(r.disabled=!1,typeof e==`string`)return O(u,`failed`,e);O(u,e.ok?`saved`:`failed`,`${e.model} ${e.ok?`answered`:`did not answer`} in ${e.ms} ms`),d.append(h(`sent`,e.request||`(the request was never made)`),h(e.ok?`answered`:`replied`,e.response))})},f.append(e,r)}if(t.builtin||t.api&&t.models){let n=v(`Edit`);n.onclick=()=>Z(e,t,l),f.append(n)}if(t.stored){let e=v(`Remove credential`);e.onclick=()=>void p(t),f.append(e)}return a(`div`,`border-b border-neutral-100`,a(`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]`,r,s,f),d)}))};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 o=document.createElement(`dialog`);o.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=`${h} select`,n||le(s,e);let c=p(),l=p(),u=p(),f=document.createElement(`select`);f.className=`${h} select`,f.append(...Y.map(([e,t])=>new Option(e,t)));let m=i(``,4);m.placeholder=`model-id
|
|
4
|
+
another-model-id`;let g=document.createElement(`input`);g.type=`checkbox`;let _=document.createElement(`select`);_.className=`${h} select`;let y=a(`div`,`flex flex-col gap-4`),b=a(`span`,`text-[11.5px] text-red-600`,``),x=v(`Cancel`),S=v(n?`Save`:`Add`,!0);S.type=`submit`;let C=()=>n??e.find(e=>e.id===s.value),w=()=>{let e=C(),t=e?!e.builtin:s.value===X;c.value=e?.id??``,c.disabled=n!==void 0,l.value=e?.name??``,u.value=e?.endpoint??``,f.value=e?.api??`openai-completions`,m.value=e?.models?.map(e=>e.id).join(`
|
|
5
|
+
`)??``;let r=e?.models?.map(e=>e.reasoning)??[];g.checked=r.length?r.every(Boolean):!e,g.indeterminate=r.some(Boolean)&&!r.every(Boolean);let i=[];e?.configured&&i.push(new Option(`Keep current authentication`,``));let o=e?.methods??[{type:`api_key`,name:`API key`}];for(let t of o.filter(t=>e?.builtin!==!1||t.type===`api_key`))i.push(new Option(t.name,t.type));_.replaceChildren(...i);let d=[];n||d.push(D(`Provider`,s)),t?d.push(D(`Provider ID`,c),D(`Display name`,l),D(`Endpoint`,u),D(`API format`,f),D(`Models`,m),D(`Model capabilities`,a(`label`,`flex items-center gap-2 text-[12.5px] text-neutral-600`,g,a(`span`,``,`Reasoning`)))):(u.placeholder=`Provider default`,d.push(D(`Endpoint`,u))),d.push(D(`Authentication`,_)),y.replaceChildren(...d)};s.onchange=w,w();let T=a(`form`,`flex flex-col gap-4 px-4 py-3`,y,a(`div`,`flex items-center justify-end gap-2`,b,x,S)),E=!1;x.onclick=()=>{E||o.close()},o.oncancel=e=>{E&&e.preventDefault()},T.onsubmit=e=>{if(e.preventDefault(),E)return;b.textContent=``;let n=C(),i=(n?!n.builtin:s.value===X)?{kind:`custom`,id:c.value.trim(),...l.value.trim()?{name:l.value.trim()}:{},endpoint:u.value.trim(),api:f.value,models:[...new Set(m.value.split(`
|
|
6
|
+
`).map(e=>e.trim()).filter(Boolean))].map(e=>({id:e,reasoning:g.indeterminate?n?.models?.find(t=>t.id===e)?.reasoning??g.checked:g.checked}))}:{kind:`builtin`,id:n.id,...u.value.trim()?{endpoint:u.value.trim()}:{}},a=_.value||null;E=!0,S.disabled=!0,x.disabled=!0,(async()=>{try{let e=await d(`/api/providers/setup`,{setup:i,authType:a});if(!e.ok){b.textContent=await t(e,`Could not configure provider`);return}if(o.close(),e.status===202){let t=_.selectedOptions[0]?.textContent??`Authentication`;J(await e.json(),i.id,t,()=>void r())}else await r()}catch(e){b.textContent=`Could not configure provider: ${String(e)}`}finally{E=!1,S.disabled=!1,x.disabled=!1}})()},o.append(a(`div`,`border-b border-neutral-200 px-4 py-2.5 text-[14px] font-semibold`,n?`Edit ${n.name}`:`Add provider`),T),o.onclose=()=>o.remove(),document.body.append(o),o.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(n,r,i){let o=localStorage.getItem($)??void 0,c=ue(o)?o:`models`,l=a(`header`,`flex h-10 flex-none items-center gap-3 border-b border-neutral-200 bg-white px-4 max-md:hidden`,a(`span`,`font-medium`,`Settings`)),m=a(`div`,`tabstrip bg-white`);function h(){m.replaceChildren(...Q.map(([e,t])=>ee(t,e===c,()=>i(e))))}let g=p();g.placeholder=`https://pier.example.com`,g.autocomplete=`off`;let y=a(`span`,`text-[11.5px]`,``),b=v(`Save`,!0);async function x(){O(y,`saving`,`saving…`);let e=await d(`/api/settings`,{publicUrl:g.value},`PUT`);if(!e.ok)return O(y,`failed`,await t(e,`Could not save`));let{publicUrl:n}=await e.json();g.value=n,O(y,`saved`,n?`Saved — boards link as ${n}/p/<slug>-<token>/`:`Cleared.`)}b.onclick=()=>void x(),g.onkeydown=e=>{e.key===`Enter`&&x()};let S=_(`Public URL`,`Where this Pier is reached from outside — the proxy's address, not the port it listens on.`,D(`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.`}),a(`div`,`flex items-center gap-3`,b,y)),T=p(``,`password`),E=p(``,`password`),k=p(``,`password`);for(let e of[T,E,k])e.autocomplete=`off`;let A=a(`span`,`text-[11.5px]`,``),j=v(`Change password`,!0);async function M(){if(E.value!==k.value)return O(A,`failed`,`The two new passwords differ.`);O(A,`saving`,`changing…`);let e=await d(`/api/password`,{current:T.value,next:E.value});if(!e.ok)return O(A,`failed`,await t(e,`Could not change the password`));for(let e of[T,E,k])e.value=``;O(A,`saved`,`Changed. Sign in again with the new password.`),location.href=`/login`}j.onclick=()=>void M(),k.onkeydown=e=>{e.key===`Enter`&&M()};let N=_(`Password`,`One shared password guards every page and API route. Changing it signs out every signed-in browser, this one included.`,D(`Current password`,T),D(`New password`,E,{hint:`At least 10 characters.`}),D(`Repeat new password`,k),a(`div`,`flex items-center gap-3`,j,A)),P=v(`Reload`,!0),F=a(`span`,`text-[11.5px]`,``);P.onclick=()=>{P.disabled=!0,O(F,`saving`,`reloading…`),(async()=>{let e=await d(`/api/reload`,{});if(P.disabled=!1,!e.ok)return O(F,`failed`,await t(e,`Could not reload`));let{recycled:n,busy:r}=await e.json(),i=n?`Recycled ${n} session(s).`:`No idle session needed it.`,a=r?` ${r} still mid-turn — they take it when the turn ends.`:``;O(F,r?`idle`:`saved`,i+a)})()};let I=_(`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.`,a(`div`,`flex items-center gap-3`,P,F)),L=a(`div`,`flex flex-col gap-2`),R=a(`span`,`text-[11.5px]`,``);async function te(e,n){O(R,`saving`,`signing out…`);try{let r=await d(e,{});if(r.ok)return!0;O(R,`failed`,await t(r,n))}catch(e){O(R,`failed`,`${n}: ${String(e)}`)}return!1}let z=v(`Sign out`);z.onclick=()=>{z.disabled=!0,te(`/logout`,`Could not sign out`).then(e=>{e?location.href=`/login`:z.disabled=!1})};function B(t){L.replaceChildren(...t.map(t=>{let n=v(t.current?`This browser`:`Sign out`);n.disabled=t.current,n.onclick=()=>{n.disabled=!0,te(`/api/devices/${encodeURIComponent(t.id)}/signout`,`Could not sign it out`).then(e=>{if(!e)return void(n.disabled=!1);O(R,`saved`,`Signed out.`),V()})};let r=a(`div`,`flex min-w-0 flex-col`,a(`span`,`truncate text-[12.5px] text-neutral-700`,de(t.agent)));return r.title=t.agent,r.append(a(`span`,`truncate text-[11.5px] text-neutral-400`,`${t.ip} · seen ${e(t.seenAt)} · signed in ${e(t.createdAt)}`)),a(`div`,`flex items-center justify-between gap-3 rounded-lg border border-neutral-200 px-3 py-2`,r,n)}))}async function V(){let e=await u(`/api/devices`,`Could not load signed-in devices`);if(!e.ok){L.replaceChildren(f(e.error));return}B(e.value)}let ne=_(`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.`,L,a(`div`,`flex items-center gap-3`,z,R)),H=a(`div`,`mx-auto flex max-w-2xl flex-col gap-6`,S,C(),I),U=e=>a(`div`,`hidden min-h-0 flex-1 overflow-y-auto bg-neutral-50/60`,a(`div`,`px-4 py-5`,e)),ie=K(),ae=a(`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=a(`section`,`hidden min-h-0 flex-1 flex-col`),oe=re(G),q=a(`section`,`hidden min-h-0 flex-1 flex-col`),J=W(q,r);function se(){(async()=>{let e=await u(`/api/settings`,`Could not load settings`);if(!e.ok)return O(y,`failed`,e.error);g.value=e.value.publicUrl,y.textContent=``})()}let Y=a(`div`,`mx-auto flex max-w-2xl flex-col gap-6`),X=e=>Y.replaceChildren(e,N,ne);async function le(){A.textContent=``,R.textContent=``,V();let e=await u(`/api/secrets`,`Could not load key status`);if(!e.ok){X(f(e.error));return}Z(e.value)}function Z(e,n){let r=e.state===`locked`,i=a(`span`,`text-[11.5px]`,``);n&&O(i,`saved`,n);let o=a(`div`,`flex items-center gap-2`,w(e.state,r?`bg-red-50 text-red-700 ring-red-200`:`bg-emerald-50 text-emerald-700 ring-emerald-200`),a(`span`,`text-[12.5px] text-neutral-600`,r?`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.`)),s=a(`a`,`text-indigo-600 hover:underline`,`vt`);s.href=`https://github.com/timqi/vt`,s.target=`_blank`,s.rel=`noreferrer`;let c=[o,a(`p`,`text-[12px] leading-snug text-neutral-500`,s,` 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(r){c.push(a(`p`,`text-[12.5px] leading-snug text-red-600`,e.reason??`No reason reported.`));let n=v(`Unlock`,!0);n.onclick=()=>{O(i,`saving`,`unlocking… (vt mode waits on your approval)`),(async()=>{let e=await d(`/api/secrets/unlock`,{});if(!e.ok)return O(i,`failed`,await t(e,`Could not unlock`));Z(await e.json(),`Unlocked — channels are starting.`)})()},c.push(a(`div`,`flex items-center gap-3`,n,i))}else{let n=async(e,n,r)=>{if(!window.confirm(n))return;O(i,`saving`,e===`vt`?`rotating… (vt asks for an approval)`:`rotating…`);let a=await d(`/api/secrets/rotate`,{mode:e});if(!a.ok)return O(i,`failed`,await t(a,`Could not rotate`));Z(await a.json(),r)},r=e.mode??`file`,o=v(`Rotate key`,!0);o.onclick=()=>void n(r,`Generate a new master key? Stored credentials stay valid; the old key stops working.`,`Rotated.`);let s=r===`vt`?`file`:`vt`,l=v(s===`vt`?`Switch to vt://`:`Switch to file`);l.onclick=()=>void n(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.`),c.push(a(`div`,`flex items-center gap-3`,o,l,i))}if(r||e.mode===`vt`){let e=a(`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 u(`/api/secrets/doctor`,`Could not run vt doctor`);e.textContent=n.ok?n.value.report:n.error,t.disabled=!1})()},c.push(a(`div`,`flex items-center gap-3`,t),e)}X(_(`Master key`,`Seals every credential Pier stores (channel tokens, API keys). Rotating rewraps the key file; no stored data is rewritten.`,...c))}let fe=U(H),pe=U(a(`div`,`flex flex-col gap-6`,ae,ie.el)),me=U(Y),he=[[`instance`,fe,se],[`models`,pe,()=>{ce(ae),ie.load()}],[`security`,me,()=>void le()]];n.append(l,m,fe,pe,G,q,me);function ge(e){ue(e)&&(c=e),localStorage.setItem($,c),h();for(let[e,t,n]of he){let r=e===c;t.classList.toggle(`hidden`,!r),r&&n()}c===`channels`?oe.show():oe.hide(),c===`files`?J.show():J.hide()}return s(n,ge)}export{fe as createSettingsView};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{F as e,I as t,O as n,V as r,_ as i,h as a,p as o}from"./index-a7A8xfoi.js";var s=e=>e===null?`-`:new Date(e).toLocaleString(),c=t=>t.startedAt===null?`-`:e((t.finishedAt??Date.now())-t.startedAt),l=e=>e.state===`succeeded`&&e.matched===!1?`No match`:e.state,u={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 d(e){let t=l(e);return o(t,t===`No match`?u.skipped:u[e.state],e.state===`running`?`animate-pulse bg-sky-500`:void 0)}function f(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 p=`px-4 pt-4 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,m=`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`,h=e=>e.trigger.type===`manual`?`Manual`:e.trigger.type===`cron`?`${e.trigger.expression} (${e.trigger.timezone})`:`Every ${e.trigger.intervalSeconds}s · ${e.trigger.mode}`,g=e=>e.action.type===`agent`?`Agent · ${e.action.session.mode}`:e.action.type===`bash`?`Bash`:e.action.type===`system`?`System`:`Task`;function _(e,n){let r=t(`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)]`),i=[[`Status`,e.archived?`Archived`:e.trigger.type===`manual`?`Manual`:e.enabled?`Enabled`:`Paused`],[`Trigger`,h(e)],[`Action`,g(e)],[`Timeout`,`${e.timeoutSeconds}s`],[`Next run`,s(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`&&(i.push([`Session policy`,e.action.session.mode]),e.action.session.mode===`reuse`&&i.push([`Session`,e.action.session.sessionId]),`cwd`in e.action.session&&i.push([`Directory`,e.action.session.cwd]),e.action.launch?.model&&i.push([`Model`,`${e.action.launch.model.provider}/${e.action.launch.model.id}`]),e.action.launch?.thinking&&i.push([`Thinking`,e.action.launch.thinking]),i.push([`Prompt`,e.action.prompt])),e.action.type===`bash`&&i.push([`Directory`,e.action.cwd],[`Script`,e.action.script]),e.action.type===`task`&&i.push([`Target task`,e.action.taskId]),e.action.type===`system`&&i.push([`System action`,e.action.name]),e.trigger.type===`watch`&&i.push([`Probe`,e.trigger.script]);for(let[e,n]of i)r.append(t(`span`,`pt-px text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),t(`pre`,`whitespace-pre-wrap break-words font-mono text-[12.5px] leading-snug`,n));if(e.action.type===`agent`&&e.action.session.mode===`reuse`){let{sessionId:i}=e.action.session,o=a(`Open session`);o.onclick=()=>n(i),r.append(t(`span`,``,``),o)}return r}function v(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 y(e,n,r,a){let o=t(`div`,`divide-y divide-neutral-100`);for(let e of n){let n=t(`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]`);n.setAttribute(`type`,`button`),n.append(t(`span`,`flex`,d(e)),t(`span`,`truncate text-neutral-500`,s(e.queuedAt)),t(`span`,`text-neutral-500`,e.triggerSource),t(`span`,`text-right font-mono text-[11.5px] text-neutral-400`,c(e))),n.onclick=()=>r(e.id),o.append(n)}n.length||o.append(t(`div`,`p-4`,i(`No runs yet.`))),e.replaceChildren(o),e.scrollTop=a.top,e.onscroll=()=>{a.top=e.scrollTop}}var b=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 x(e,i,o,l,u){let f=String(Number(e.dataset.runRequest??0)+1);e.dataset.runRequest=f,e.onscroll=()=>{u.scrollTop=e.scrollTop};let h=a(`Runs`);h.className=`cursor-pointer text-neutral-500 hover:text-neutral-800 hover:underline`,h.onclick=()=>{u.selectedId=null,u.scrollTop=0,o()};let g=n(h,t(`span`,`text-neutral-400`,`›`),t(`span`,`min-w-0 truncate font-mono text-[12px] text-neutral-500`,i)),x=e.dataset.runId!==i;x&&(e.dataset.runId=i,e.replaceChildren(g,t(`p`,`p-4 text-[13px] text-neutral-500`,`Loading run...`)));let[S,C]=await Promise.all([r(`/api/task-runs/${i}`,`Could not load the run`),r(`/api/task-runs/${i}/messages`,`Could not load the run's messages`)]);if(!e.isConnected||e.dataset.runRequest!==f||u.selectedId!==i)return;if(!S.ok){let n=await r(`/api/task-groups/${i}`,S.error);if(!e.isConnected||e.dataset.runRequest!==f||u.selectedId!==i)return;if(u.drawn=``,!n.ok){e.replaceChildren(g,t(`p`,`p-4 text-[13px] text-red-600`,S.error));return}let{group:a,members:o}=n.value,s=t(`div`,`min-w-0`);e.replaceChildren(g,t(`div`,`border-b border-neutral-100 bg-neutral-50/60 px-4 py-3 text-[12.5px] text-neutral-600`,[`Task group \u00b7 join ${a.join}`,`${String(o.length)} runs`,a.callbackState?`callback ${a.callbackState}`:``].filter(Boolean).join(` · `)),s),y(s,o,l.openRun,{top:0});return}let w=S.value,T=C.ok?C.value:[],E=JSON.stringify([w,C]);if(!x&&u.drawn===E)return;if(u.drawn=E,w.targetSessionId){let e=a(`Open session`);e.classList.add(`ml-auto`),e.onclick=()=>l.openSession(w.targetSessionId),g.append(e)}if(w.state===`queued`||w.state===`running`){let e=a(`Stop run`);e.onclick=()=>{window.confirm(`Stop this run of "${w.context.definition.name}"?`)&&l.mutate(`/api/task-runs/${w.id}/cancel`)},g.append(e)}let D=t(`div`,`min-w-0`),O=v(w);D.append(t(`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]`,t(`span`,`flex items-center gap-2`,d(w),t(`span`,`font-medium`,w.context.definition.name)),...O?[t(`span`,`rounded-md bg-amber-50 px-2 py-0.5 text-[12px] text-amber-700 ring-1 ring-amber-200`,O)]:[],t(`span`,`text-neutral-500`,s(w.queuedAt)),t(`span`,`text-neutral-500`,w.triggerSource),t(`span`,`font-mono text-[11.5px] text-neutral-400`,c(w))));let k=t(`div`,`flex flex-wrap items-center gap-2 border-b border-neutral-100 px-4 py-3 text-[12px]`),A=(e,t)=>{let n=a(e);n.classList.add(`max-w-full`,`break-all`,`!whitespace-normal`),n.onclick=t,k.append(n)};if(w.context.definition.kind===`task`&&A(`Task: ${w.context.definition.name}`,()=>l.openTask(w.taskId)),w.parentRunId&&A(`Parent: ${w.parentRunId}`,()=>l.openRun(w.parentRunId)),w.resumedFromRunId&&A(`Resumed from: ${w.resumedFromRunId}`,()=>l.openRun(w.resumedFromRunId)),w.result?.type===`task`){let e=w.result.runId;A(`Child result: ${e}`,()=>l.openRun(e))}w.groupId&&k.append(t(`span`,`break-all font-mono text-[11.5px] text-neutral-500`,`Group: ${w.groupId}`)),D.append(k);for(let e of[w.error,w.skipReason,w.callbackError])e&&D.append(t(`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(w.result){let e=w.result,n=e.type===`agent`||e.type===`system`?e.text:e.type===`bash`?b(e):e.type===`task`?`Child run: ${e.runId}`:`Watch did not match.`;D.append(t(`h3`,p,`Result`),t(`pre`,m,n||`No output.`))}w.probe&&D.append(t(`h3`,p,`Watch probe: ${w.matched===null?`not evaluated`:w.matched?`matched`:`not matched`}`),t(`pre`,m,b(w.probe)));let j=t(`details`,`border-t border-neutral-200`);if(j.append(t(`summary`,`flex cursor-pointer items-center gap-1.5 px-4 py-3 text-[12px] text-neutral-500 hover:text-neutral-800`,t(`span`,`chev`,`▶`),`Configuration snapshot (revision ${w.taskRevision})`),_(w.context.definition,l.openSession)),D.append(j),C.ok||D.append(t(`p`,`m-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-[12.5px] text-red-700`,C.error)),T.length){let e=t(`div`,`mt-2 divide-y divide-neutral-100 border-t border-neutral-100`);for(let n of T){let r=t(`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(t(`span`,`font-medium`,n.kind),t(`span`,`text-neutral-500`,n.state),t(`span`,`col-span-2 whitespace-pre-wrap break-words md:col-span-1`,n.content)),n.error&&r.append(t(`span`,`col-span-2 break-words text-red-600 md:col-span-3`,n.error)),e.append(r)}D.append(t(`div`,`border-t border-neutral-200`,t(`div`,p,`Messages`),e))}let M=t(`details`,`border-t border-neutral-200`);M.open=u.rawOpen,M.ontoggle=()=>{M.isConnected&&(u.rawOpen=M.open)},M.append(t(`summary`,`flex cursor-pointer items-center gap-1.5 px-4 py-3 text-[12px] text-neutral-500 hover:text-neutral-800`,t(`span`,`chev`,`▶`),`Raw record`),t(`pre`,m,JSON.stringify(w,null,2))),D.append(M),e.replaceChildren(g,D),e.scrollTop=u.scrollTop,e.onscroll=()=>{u.scrollTop=e.scrollTop}}export{y as a,c,x as i,f as l,s as n,v as o,_ as r,d as s,g as t,h as u};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{B as e,C as t,E as n,I as r,M as i,O as a,S as o,U as s,V as c,W as l,_ as u,b as d,d as f,h as p,p as m,v as h,z as g}from"./index-a7A8xfoi.js";import{a as _,c as v,l as y,n as b,r as x,s as S,t as C,u as w}from"./task-runs-C2PHAhAf.js";function T(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 E(e,i){let a=document.createElement(`dialog`);a.className=`m-auto w-[38.75rem] max-w-[94vw] rounded-lg border border-neutral-200 p-0 shadow-xl backdrop:bg-black/20`;let o=document.createElement(`form`);o.className=`flex max-h-[88vh] flex-col`;let s=r(`span`,`mr-auto text-[12px] text-red-600`),c=r(`header`,`flex h-11 flex-none items-center border-b border-neutral-200 px-4 font-medium`,i?`Edit task`:`New task`),l=r(`div`,`grid min-h-0 flex-1 grid-cols-2 gap-3 overflow-y-auto p-4`),u=d(i?.name??``);u.required=!0;let f=d(i?.description??``),m=d(String(i?.timeoutSeconds??900),`number`);m.min=`1`,m.max=`86400`;let g=t([[`Manual`,`manual`],[`Scheduled`,`cron`],[`Watch`,`watch`]],i?.trigger.type??`manual`),_=t([[`Bash`,`bash`],[`Agent`,`agent`],[`Task`,`task`]],i?.action.type??`bash`),v=t([[`No callback`,`none`],[`Invoking session`,`origin`],[`Specific session`,`session`]],i?.callback.type??`none`),y=i?.callback.type===`session`?i.callback.sessionId:null,b=t(T(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`),l.append(h(`Name`,u),h(`Description`,f),h(`Trigger`,g),h(`Action`,_),h(`Callback`,v),x,h(`Timeout (seconds)`,m));let S=r(`div`,`col-span-2 grid grid-cols-2 gap-3 border-t border-neutral-200 pt-3`);l.append(S);let C=()=>{S.replaceChildren();let c,l,p,y,x,C;if(g.value===`cron`)c=d(i?.trigger.type===`cron`?i.trigger.expression:`0 9 * * *`),l=d(i?.trigger.type===`cron`?i.trigger.timezone:Intl.DateTimeFormat().resolvedOptions().timeZone),S.append(h(`Cron`,c),h(`Timezone`,l));else if(g.value===`watch`){p=n(i?.trigger.type===`watch`?i.trigger.script:``,4),C=d(i?.trigger.type===`watch`?i.trigger.cwd:e.sessions()[0]?.cwd??``),y=d(String(i?.trigger.type===`watch`?i.trigger.intervalSeconds:60),`number`),x=t([[`Continue after matches`,`repeat`],[`Stop after first match`,`once`]],i?.trigger.type===`watch`?i.trigger.mode:`repeat`);let r=h(`Probe script (0=match, 1=no match)`,p);r.classList.add(`col-span-2`),S.append(r,h(`Probe directory`,C),h(`Interval (seconds)`,y),h(`Mode`,x))}let w,E,O,k,A,j,M,N,P,F;if(_.value===`bash`){E=d(i?.action.type===`bash`?i.action.cwd:e.sessions()[0]?.cwd??``),w=n(i?.action.type===`bash`?i.action.script:``,6);let t=h(`Bash script`,w);t.classList.add(`col-span-2`),S.append(h(`Working directory`,E),r(`span`,``),t)}else if(_.value===`agent`){let r=e.sessions(),a=i?.action.type===`agent`?i.action:null,o=a?.session.mode===`reuse`?a.session.sessionId:``,s=T(r,o||null);O=t([[`Reuse session`,`reuse`],[`Fresh child per run`,`fresh`]],a?.session.mode===`reuse`?`reuse`:`fresh`),k=t(s,o||s[0]?.[1]||``);let c=a&&`cwd`in a.session?a.session.cwd??``:``;A=d(c||r[0]?.cwd||``),j=n(a?.prompt??``,6),M=t([[`Project default`,``],[`Off`,`off`],[`Low`,`low`],[`Medium`,`medium`],[`High`,`high`],[`Extra high`,`xhigh`]],a?.launch?.thinking??``),N=d(a?.launch?.model?.provider??``),P=d(a?.launch?.model?.id??``);let l=h(`Session`,k),u=h(`Child directory`,A),f=[h(`Thinking`,M),h(`Model provider (optional)`,N),h(`Model id (optional)`,P)],p=()=>{let e=O?.value===`reuse`;l.classList.toggle(`hidden`,!e),u.classList.toggle(`hidden`,e);for(let t of f)t.classList.toggle(`hidden`,e)};O.onchange=p,p();let m=h(`Prompt`,j);m.classList.add(`col-span-2`),S.append(h(`Session policy`,O),l,u,...f,m)}else F=t(e.tasks().filter(e=>e.id!==i?.id&&!e.archived).map(e=>[e.name,e.id]),i?.action.type===`task`?i.action.taskId:``),S.append(h(`Target task`,F));o.onsubmit=t=>{t.preventDefault();let n=g.value===`manual`?{type:`manual`}:g.value===`cron`?{type:`cron`,expression:c.value,timezone:l.value}:{type:`watch`,script:p.value,cwd:C.value,intervalSeconds:Number(y.value),mode:x.value},r=_.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,o=_.value===`bash`?{type:`bash`,cwd:E.value,script:w.value}:_.value===`agent`?{type:`agent`,prompt:j.value,session:O.value===`reuse`?{mode:`reuse`,sessionId:k.value}:{mode:`fresh`,cwd:A.value},...r?{launch:r}:{}}:{type:`task`,taskId:F.value},d=v.value===`origin`?{type:`origin`}:v.value===`session`?{type:`session`,sessionId:b.value}:{type:`none`},h={name:u.value,description:f.value,trigger:n,action:o,callback:d,timeoutSeconds:Number(m.value)};s.textContent=``,D(i?.id,h,a,s,e.onSaved)}};g.onchange=C,_.onchange=C,C();let w=p(`Cancel`);w.onclick=()=>a.close();let E=p(`Save`,!0);E.type=`submit`;let O=r(`footer`,`flex flex-none justify-end gap-2 border-t border-neutral-200 px-4 py-3`);O.append(s,w,E),o.append(c,l,O),a.append(o),a.addEventListener(`close`,()=>a.remove()),document.body.append(a),a.showModal(),u.focus()}async function D(e,t,n,r,i){let a=await l(e?`/api/tasks/${e}`:`/api/tasks`,t,e?`PATCH`:`POST`);if(!a.ok){r.textContent=(await a.json()).error??`Task save failed`;return}let o=await a.json(),s=`task`in o?o.task:o;n.close(),i(s.id)}function O(n,d,h,T,D,O,k){let A=[],j=[],M=null,N=`active`,P=`all`,F=``,I=`runs`,L={top:0},R=0,z=0,B=``,V=g(async()=>{let e=`${N}:${P}`,t=await c(`/api/tasks?state=${N}&kind=task`,`Failed to load tasks`);if(!t.ok)return B=``,H(t.error);if(e!==`${N}:${P}`)return;let n=JSON.stringify(t.value);e+n===B&&!M||(B=e+n,A=t.value,j=N===`archived`?await U():A,e===`${N}:${P}`&&(P!==`all`&&(A=A.filter(e=>e.trigger.type===P)),M?await ee(M):J()))});function H(e){n.querySelector(`[role=alert]`)?.remove();let t=r(`p`,`flex-none p-4 text-[13px] text-red-600`,e);t.setAttribute(`role`,`alert`),n.append(t)}async function U(){let e=await c(`/api/tasks?state=active`,`Failed to load tasks`);return e.ok?e.value:j}let W={sessions:d,tasks:()=>j,onSaved:e=>{K(e),I=`definition`,k(e)}},G=(e,t)=>a(...e,r(`div`,`ml-auto flex flex-wrap items-center gap-2 max-md:w-full`,...t));function K(e){M=e,I=`runs`,L.top=0}function q(){M=null,R++,J()}function J(){let e=p(`New task`,!0);e.onclick=()=>void h().then(()=>E(W));let i=[],a=(e,n,r,a)=>{let o=t(n,r);o.setAttribute(`aria-label`,e),o.classList.add(`!w-auto`,`pr-8`),o.onchange=()=>{a(o.value),z=0,V()},i.push(o)},o=r(`input`,`${f} !w-48 max-md:!w-full`);o.type=`search`,o.placeholder=`Search tasks`,o.setAttribute(`aria-label`,`Search tasks`),o.value=F,o.oninput=()=>{F=o.value,l()},i.push(o),a(`Status`,[[`Current`,`active`],[`Archived`,`archived`]],N,e=>{N=e}),a(`Trigger`,[[`All triggers`,`all`],[`Manual`,`manual`],[`Scheduled`,`cron`],[`Watching`,`watch`]],P,e=>{P=e});let s=document.createElement(`table`);s.className=`w-full table-fixed text-left text-[12.5px]`,s.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 c=document.createElement(`tbody`),l=()=>{let e=A.filter(e=>`${e.name} ${e.description??``}`.toLowerCase().includes(F.toLowerCase()));c.replaceChildren(...e.map(Y)),d.classList.toggle(`hidden`,e.length>0)};s.append(c);let d=r(`div`,`p-4`,u(`No matching tasks.`)),m=r(`div`,`min-h-0 flex-1 overflow-auto`,s,d);l(),m.onscroll=()=>{z=m.scrollTop},n.replaceChildren(G(i,[e]),m),m.scrollTop=z}function Y(e){let t=document.createElement(`tr`);t.className=`cursor-pointer border-b border-neutral-100 transition-colors hover:bg-neutral-50`,t.onclick=()=>k(e.id);let n=p(e.name);n.className=`min-w-0 cursor-pointer truncate text-left font-medium text-neutral-800`,n.title=e.name,t.append(r(`td`,`py-2.5 pl-4 pr-2`,r(`div`,`flex flex-wrap items-center gap-x-2 gap-y-1`,n,y(e),...X(e)),r(`div`,`truncate text-[11px] text-neutral-400`,e.description||``),r(`div`,`truncate text-[11px] text-neutral-400 md:hidden`,w(e))));for(let n of[C(e),w(e),b(e.nextRunAt)]){let e=r(`td`,`hidden truncate px-2 py-2.5 text-neutral-600 md:table-cell`,n);e.title=n,t.append(e)}t.append(r(`td`,`px-2 py-2.5`,e.lastRun?r(`div`,`flex`,S(e.lastRun)):r(`div`,`text-neutral-400`,`–`),r(`div`,`mt-0.5 font-mono text-[11px] text-neutral-400`,e.lastRun?v(e.lastRun):``)));let i=p(`Run now`);return i.disabled=e.archived,i.onclick=t=>{t.stopPropagation(),Z(e.id)},t.append(r(`td`,`px-2 py-1 text-right`,i)),t}function X(e){if(!e.createdBySessionId)return[];let t=m(`agent`,`bg-violet-50 text-violet-700 ring-violet-200`);return t.title=`Created by session ${e.createdBySessionId}`,[t]}async function ee(e){let t=++R,i=n.querySelector(`[data-task-detail]`),[s,l]=await Promise.all([c(`/api/tasks/${e}`,`Failed to load task`),c(`/api/tasks/${e}/runs`,`Failed to load the task's runs`)]);if(t!==R||M!==e)return;if(!s.ok)return H(s.error);if(!l.ok)return H(l.error);let u=s.value,d=l.value,f=p(`Tasks`);f.className=`cursor-pointer text-neutral-500 hover:text-neutral-800 hover:underline`,f.onclick=()=>k();let m=r(`span`,`flex min-w-0 items-center gap-2`,f,r(`span`,`text-neutral-400`,`›`),r(`span`,`truncate font-medium`,u.name),y(u)),g=p(`Run now`,!0);g.disabled=u.archived,g.onclick=()=>void Z(u.id);let v=p(u.enabled?`Pause schedule`:`Resume schedule`);v.disabled=u.archived||u.action.type===`system`||u.trigger.type===`manual`,v.onclick=()=>void Q(`/api/tasks/${u.id}/${u.enabled?`pause`:`resume`}`);let b=p(`Edit`);b.disabled=u.archived||u.action.type===`system`,b.onclick=()=>void h().then(()=>E(W,u));let S=p(`Archive`);S.disabled=u.archived||u.action.type===`system`,S.onclick=()=>void Q(`/api/tasks/${u.id}/archive`);let C=a(),w=r(`div`,`min-h-0 flex-1 overflow-auto`);w.dataset.taskDetail=e;let D=p(`All runs`);D.onclick=()=>O({taskId:u.id});let A=()=>{C.replaceChildren(o([[`Recent runs (${d.length})`,`runs`],[`Definition`,`definition`]],I,e=>{I=e,A()}),r(`span`,`ml-auto`,D)),I===`runs`?_(w,d,e=>O({},e),L):(w.onscroll=null,w.replaceChildren(x(u,T)))},j=i?.scrollTop??0;n.replaceChildren(G([m],[g,...u.trigger.type===`manual`?[]:[v],b,S]),C,w),A(),w.scrollTop=j}async function Z(t){try{let n=await l(`/api/tasks/${t}/run`,{sourceSessionId:D()});if(!n.ok)return H(await e(n,`Failed to run task`));O({},(await n.json()).runId)}catch(e){H(`Failed to run task: ${String(e)}`)}}async function Q(e){let t=await s(e,`POST`,`Task update failed`);if(t)return H(t);await V()}let $=i(n,e=>{e&&e!==M&&K(e),e||q(),n.childElementCount||J(),V()});return Object.assign($,{refresh(e){$.visible&&(!M||!e||M===e)&&V()}})}export{O as createTasksView};
|
|
Binary file
|
|
Binary file
|
|
@@ -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-
|
|
37
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
36
|
+
<script type="module" crossorigin src="/assets/index-a7A8xfoi.js"></script>
|
|
37
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DP1-BW-q.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>
|
|
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">
|
|
@@ -123,13 +115,6 @@
|
|
|
123
115
|
<path d="M8 5.5v5M5.5 8h5" stroke-linecap="round" />
|
|
124
116
|
</svg>
|
|
125
117
|
</button>
|
|
126
|
-
<button type="button" id="open-terminal"
|
|
127
|
-
class="icon-btn" aria-label="Terminal">
|
|
128
|
-
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5">
|
|
129
|
-
<rect x="2.25" y="2.25" width="11.5" height="11.5" rx="2.5" />
|
|
130
|
-
<path d="M4.75 5.75 7 8l-2.25 2.25M8.25 10.75h3" stroke-linecap="round" stroke-linejoin="round" />
|
|
131
|
-
</svg>
|
|
132
|
-
</button>
|
|
133
118
|
</div>
|
|
134
119
|
<div id="project-tree" class="flex-1 overflow-y-auto text-[13.5px]"></div>
|
|
135
120
|
</aside>
|
|
@@ -148,13 +133,20 @@
|
|
|
148
133
|
<button type="button" id="mobile-menu" aria-label="Session actions"
|
|
149
134
|
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
135
|
</header>
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
<section id="
|
|
136
|
+
<!-- Automation hosts three views under one title and tab strip; the
|
|
137
|
+
strip's active pill tracks the route (#/tasks, #/runs, #/activity). -->
|
|
138
|
+
<section id="automation-view" class="hidden min-h-0 flex-1 flex-col">
|
|
139
|
+
<header class="flex h-10 flex-none items-center gap-3 border-b border-neutral-200 bg-white px-4 max-md:hidden">
|
|
140
|
+
<span class="font-medium">Automation</span>
|
|
141
|
+
</header>
|
|
142
|
+
<div id="automation-tabs" class="tabstrip bg-white"></div>
|
|
143
|
+
<section id="tasks-view" class="hidden min-h-0 flex-1 flex-col"></section>
|
|
144
|
+
<section id="runs-view" class="hidden min-h-0 flex-1 flex-col"></section>
|
|
145
|
+
<section id="activity-view" class="hidden min-h-0 flex-1 flex-col"></section>
|
|
146
|
+
</section>
|
|
154
147
|
<section id="boards-view" class="hidden min-h-0 flex-1 flex-col"></section>
|
|
155
148
|
<section id="settings-view" class="hidden min-h-0 flex-1 flex-col"></section>
|
|
156
149
|
<section id="files-view" class="hidden min-h-0 flex-1 flex-col"></section>
|
|
157
|
-
<section id="terminal-view" class="hidden min-h-0 flex-1 flex-col"></section>
|
|
158
150
|
<header id="chat-header" class="flex h-10 flex-none items-center gap-2 border-b border-neutral-200 px-4 max-md:hidden">
|
|
159
151
|
<span id="chat-title" class="truncate font-medium"></span>
|
|
160
152
|
<!-- Right cluster: meta chips sit flush against the ⋯ button. Two
|
|
Binary file
|
|
Binary file
|
package/dist/web/server.js
CHANGED
|
@@ -633,16 +633,16 @@ export function createServer({ factory, router, hub, sessions: state, config, pr
|
|
|
633
633
|
// Hashed bundles never change under their name — a release writes new names,
|
|
634
634
|
// and the shell above is what re-points at them. Without this they carry only
|
|
635
635
|
// the auth layer's bare `private`, so a browser revalidates each one before it
|
|
636
|
-
// may reuse it:
|
|
637
|
-
//
|
|
636
|
+
// may reuse it: a round trip per bundle on a remote instance, every time the
|
|
637
|
+
// workbench is opened.
|
|
638
638
|
app.get("/assets/*", async (c, next) => {
|
|
639
639
|
c.header("cache-control", "private, max-age=31536000, immutable");
|
|
640
640
|
await next();
|
|
641
641
|
});
|
|
642
642
|
// `precompressed` looks for a `.br`/`.gz` sibling of the file it is about to
|
|
643
643
|
// serve and hands that over when the request accepts the encoding; the build
|
|
644
|
-
// writes them (vite.config.ts). Without it the 325 kB bundle
|
|
645
|
-
// stylesheet
|
|
644
|
+
// writes them (vite.config.ts). Without it the 325 kB bundle and the 87 kB
|
|
645
|
+
// stylesheet go out verbatim.
|
|
646
646
|
// serveStatic only sets Vary when it selects a sibling. Identity must carry
|
|
647
647
|
// it too, or a cache can reuse that response for a later Brotli request.
|
|
648
648
|
app.use("/*", async (c, next) => {
|
package/docs/deploy.md
CHANGED
|
@@ -24,8 +24,6 @@ you want the unit to say something different.
|
|
|
24
24
|
## Prerequisites
|
|
25
25
|
|
|
26
26
|
- Node 24 or newer (`node:sqlite` is used unflagged).
|
|
27
|
-
- Python 3, `make` and a C/C++ compiler for Microsoft's `node-pty`; its npm
|
|
28
|
-
package has no Linux prebuild (`apt install python3 build-essential` on Debian/Ubuntu).
|
|
29
27
|
- A user-writable global npm prefix. The updater runs as you, so an initial
|
|
30
28
|
install that needed `sudo npm install -g` cannot later update itself.
|
|
31
29
|
- The `sqlite3` CLI is optional, for the off-machine backup and password steps
|
|
@@ -178,7 +176,7 @@ journalctl --user -u pier --since -1h | grep 'tasks:' # one area
|
|
|
178
176
|
|
|
179
177
|
Every line is `area: message` — `core`, `agent`, `tasks`, `slack`, `telegram`,
|
|
180
178
|
`lark`, `channels`, `slack.tool`, `auth`, `boards`, `client`, `db`, `drain`,
|
|
181
|
-
`secrets`, `settings`, `credentials`, `update`, `tools`, `
|
|
179
|
+
`secrets`, `settings`, `credentials`, `update`, `tools`, `push`,
|
|
182
180
|
`web`, `web.providers`, `pier` — so an area is a grep
|
|
183
181
|
and a level is a `-p`. The level reaches journald as a syslog priority prefix, which Pier
|
|
184
182
|
emits only when systemd says the output is a journal (`$JOURNAL_STREAM`); run
|
|
@@ -257,7 +255,7 @@ has one shared 10-second bound regardless of how many sessions are stuck.
|
|
|
257
255
|
|
|
258
256
|
`pier tools sync` converges the command-line tools switched on in Console →
|
|
259
257
|
Settings — they install into `~/.pier/tools/bin`, which the service puts first
|
|
260
|
-
on the PATH every session
|
|
258
|
+
on the PATH every session and task inherits. Normally a switch runs
|
|
261
259
|
it for you as a task; typing it is for a machine that was offline when one was
|
|
262
260
|
flipped. One sync runs at a time per machine: an overlapping one waits for the
|
|
263
261
|
lock (and converges on the switches as they stand when its turn comes) instead
|
|
@@ -280,7 +278,7 @@ hard-stop paths. Let active work finish first when using either one.
|
|
|
280
278
|
## Updating
|
|
281
279
|
|
|
282
280
|
```sh
|
|
283
|
-
pier update # installs the latest release
|
|
281
|
+
pier update # installs the latest release, then hard-stops/restarts Pier
|
|
284
282
|
pier update --check # only says whether one exists
|
|
285
283
|
```
|
|
286
284
|
|
|
@@ -300,7 +298,7 @@ npm ci && npm run build
|
|
|
300
298
|
systemctl --user start pier
|
|
301
299
|
```
|
|
302
300
|
|
|
303
|
-
For a service install, `pier update` stops Pier
|
|
301
|
+
For a service install, `pier update` hard-stops Pier; it does not use the
|
|
304
302
|
graceful `pier restart` path. The Console's **Update now** and the automatic
|
|
305
303
|
path do: both drain (new work refused, running turns finished, the rest
|
|
306
304
|
ledgered for the next boot to report) before the updater unit is started.
|
|
@@ -309,9 +307,19 @@ Either way the updater snapshots the database to
|
|
|
309
307
|
`~/.pier/db/backups/pier.db.release-<version>.bak` before npm touches the
|
|
310
308
|
package — `<version>` being the Pier that is being replaced, i.e. the release to
|
|
311
309
|
reinstall if that copy is ever restored. This happens for every release,
|
|
312
|
-
including releases with no schema change.
|
|
313
|
-
|
|
314
|
-
the
|
|
310
|
+
including releases with no schema change.
|
|
311
|
+
|
|
312
|
+
Both of those steps run while Pier is still serving: the snapshot is taken
|
|
313
|
+
through a read-only connection, so it is consistent on a live database, and npm
|
|
314
|
+
writes into the global prefix rather than into the running process. Only the
|
|
315
|
+
stop and the start that follow them are downtime — a second or two instead of
|
|
316
|
+
the ten to twenty an install takes. A backup or install that fails therefore
|
|
317
|
+
never stops anything; the failure is in the updater's journal and the running
|
|
318
|
+
Pier keeps serving the version it already loaded. (For those seconds the live
|
|
319
|
+
process is running code whose files on disk have already been replaced: a
|
|
320
|
+
browser left open on the old page can see a lazily loaded asset 404 until it
|
|
321
|
+
reloads. On the drained paths nothing else is running by then; `pier update`
|
|
322
|
+
does not drain, which is the same reason to let active work finish first.)
|
|
315
323
|
|
|
316
324
|
### Automatic updates
|
|
317
325
|
|
|
@@ -380,9 +388,10 @@ Type=oneshot
|
|
|
380
388
|
# recorded PATH as pier.service, and recorded rather than sourced from a login
|
|
381
389
|
# shell at run time: a dotfile must not get to decide which node npm uses.
|
|
382
390
|
Environment="PATH=/path/to/node/bin:/your/shell/PATH:/usr/local/bin:/usr/bin:/bin"
|
|
383
|
-
ExecStart=systemctl --user stop pier.service
|
|
384
391
|
ExecStart=/path/to/node /path/to/pier/dist/cli.js backup
|
|
385
392
|
ExecStart=/path/to/node /recorded/path/to/npm install -g @timqi/pier@latest
|
|
393
|
+
# Last: everything above it runs with Pier still up, so the stop is the downtime.
|
|
394
|
+
ExecStart=systemctl --user stop pier.service
|
|
386
395
|
ExecStopPost=systemctl --user start pier.service
|
|
387
396
|
```
|
|
388
397
|
|
|
@@ -394,8 +403,9 @@ Deliberately **not** a `systemd.timer`. An unattended update is a machine that
|
|
|
394
403
|
rewrites its own code from the network while holding your API keys, and its hard
|
|
395
404
|
stop interrupts whatever session was mid-turn. Pier notices a newer release
|
|
396
405
|
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
|
|
398
|
-
|
|
406
|
+
makes. The updater's `ExecStopPost` is what brings the service back: after a
|
|
407
|
+
successful stop, and — as a no-op, since nothing was stopped — after a backup or
|
|
408
|
+
install that failed.
|
|
399
409
|
|
|
400
410
|
## Remote access
|
|
401
411
|
|
|
@@ -409,9 +419,7 @@ elsewhere, pick a tunnel rather than a wider bind:
|
|
|
409
419
|
`X-Forwarded-For`; Pier uses the external host for write-origin checks and
|
|
410
420
|
counts login failures per forwarded client. Its session cookie is marked
|
|
411
421
|
`Secure` when a loopback proxy reports `X-Forwarded-Proto: https` (the header
|
|
412
|
-
is ignored from anywhere else, where it is a header the client wrote).
|
|
413
|
-
pass WebSocket upgrades for `/api/terminal` (Caddy does automatically;
|
|
414
|
-
nginx needs its usual HTTP/1.1 `Upgrade`/`Connection` forwarding).
|
|
422
|
+
is ignored from anywhere else, where it is a header the client wrote).
|
|
415
423
|
|
|
416
424
|
## Backups
|
|
417
425
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timqi/pier",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
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",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@tailwindcss/typography": "^0.5.20",
|
|
37
37
|
"@tailwindcss/vite": "^4.3.3",
|
|
38
|
-
"@types/ws": "^8.18.1",
|
|
39
38
|
"oxlint": "^1.79.0",
|
|
40
39
|
"tailwindcss": "^4.3.3",
|
|
41
40
|
"tsx": "^4.23.12",
|
|
@@ -49,15 +48,9 @@
|
|
|
49
48
|
"@larksuiteoapi/node-sdk": "^1.73.0",
|
|
50
49
|
"croner": "^10.0.1",
|
|
51
50
|
"dompurify": "^3.4.14",
|
|
52
|
-
"ghostty-web": "^0.4.0",
|
|
53
51
|
"highlight.js": "^11.12.0",
|
|
54
52
|
"hono": "^4.13.3",
|
|
55
53
|
"marked": "^18.0.10",
|
|
56
|
-
"
|
|
57
|
-
"typebox": "^1.3.7",
|
|
58
|
-
"ws": "^8.21.3"
|
|
59
|
-
},
|
|
60
|
-
"allowScripts": {
|
|
61
|
-
"node-pty@1.1.0": true
|
|
54
|
+
"typebox": "^1.3.7"
|
|
62
55
|
}
|
|
63
56
|
}
|
|
@@ -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.
|
|
11
|
-
|
|
12
|
-
atomically; it is tagged `kind:"subagent"` and hidden from task
|
|
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","
|
|
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
|
|
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
|
|
54
|
-
group in core — you never
|
|
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
|
-
|
|
59
|
-
{"
|
|
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
|
|
@@ -125,8 +134,10 @@ sends no completion callback — the question is the notification.
|
|
|
125
134
|
|
|
126
135
|
- One concern per child. For fan-out, let core join via `tasks[]` — never
|
|
127
136
|
hand-aggregate run ids across turns.
|
|
128
|
-
-
|
|
129
|
-
|
|
137
|
+
- `create` is for definitions that outlive one job: a schedule (`cron` /
|
|
138
|
+
`watch`), or a role you will run by `task_id` again and again. It files a
|
|
139
|
+
task the operator sees and has to archive by hand — never use it for a
|
|
140
|
+
one-off; that is `run` with a prompt.
|
|
130
141
|
- Inline drafts must use `action.type:"agent"`; triggers are forced manual;
|
|
131
142
|
do not target another session with `reuse` from an inline draft.
|
|
132
143
|
- After launching work, end your turn. The callback starts your next one.
|
|
File without changes
|
|
@@ -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};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{H as e,I as t,L as n,M as r,P as i,a,i as o,j as s,l as c,n as l,s as u}from"./index-DHxoYoeq.js";import{n as d,t as f}from"./code-C86xKk2k.js";var p=e=>{let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`},m=e=>[e.subject,e.body,[[e.author,e.email?`<${e.email}>`:``].filter(Boolean).join(` `),e.at?p(e.at):``].filter(Boolean).join(` · `)].filter(Boolean).join(`
|
|
2
|
-
|
|
3
|
-
`),h=null;function g(){h&&(h.remove(),h=null,document.removeEventListener(`pointerdown`,g,!0),window.removeEventListener(`scroll`,g,!0))}function _(e,n){e.onmouseenter=()=>{g();let r=n();if(!r)return;h=t(`div`,`pointer-events-none fixed z-50 max-w-96 whitespace-pre-wrap rounded-lg bg-neutral-800/95 px-3 py-2 font-sans text-[11.5px] leading-snug text-neutral-100 shadow-lg`),h.textContent=r,document.body.append(h),document.addEventListener(`pointerdown`,g,!0),window.addEventListener(`scroll`,g,!0);let i=e.getBoundingClientRect();h.style.left=`${Math.max(8,Math.min(i.left,window.innerWidth-h.offsetWidth-8))}px`,h.style.top=i.bottom+6+h.offsetHeight>window.innerHeight?`${i.top-h.offsetHeight-6}px`:`${i.bottom+6}px`},e.onmouseleave=g}function v(e,r,i){let a=t(`button`,`flex w-full cursor-pointer items-center gap-1.5 px-2 py-1 text-left hover:bg-neutral-100`,t(`span`,`w-3 flex-none text-indigo-600`,e.value===r?`✓`:``),t(`span`,`flex-none font-mono text-[11.5px] text-neutral-800`,e.label??e.value));return e.subject&&a.append(t(`span`,`min-w-0 truncate text-[11px] text-neutral-400`,e.subject)),e.author&&a.append(t(`span`,`ml-auto flex-none pl-1.5 text-[10.5px] text-neutral-400`,`${e.author} · ${e.at?n(e.at):``}`)),_(a,()=>m(e)),a.onclick=()=>i(e.value),a}function ee(e,n,r,i,s){let{base:c,head:l}=r,u=()=>l&&c===`${l}~1`?l:``,d=u()?`commit`:`compare`,f=n.commits[0],p=e=>[...e?[{value:``,label:`Working tree`,subject:`the files on disk, uncommitted changes included`}]:[],{...f,value:`HEAD`},...n.refs.map(e=>({value:e.name,subject:e.subject})),...n.commits.map(e=>({...e,value:e.hash}))],m=t(`div`,`flex w-[38rem] max-w-full flex-col`);function h(){let e=(e,n)=>{let r=t(`button`,`cursor-pointer rounded-full px-2.5 py-0.5 text-[11.5px] ${d===n?`bg-indigo-50 font-medium text-indigo-700`:`text-neutral-500 hover:bg-neutral-100`}`,e);return r.onclick=()=>{d=n,h()},r},r=(e,n,r,i)=>t(`div`,`flex min-w-0 flex-1 flex-col`,t(`div`,`flex-none px-2 pb-0.5 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),t(`div`,`min-h-0 flex-1 overflow-y-auto`,...n.map(e=>v(e,r,i)))),a=d===`compare`?t(`div`,`flex h-72 min-h-0 divide-x divide-neutral-200 pb-1`,r(`base`,p(!1),c,e=>{c=e,h(),i(c,l)}),r(`to`,p(!0),l,e=>{l=e,h(),i(c,l)})):t(`div`,`flex h-72 min-h-0 flex-col overflow-y-auto pb-1`,...n.commits.map(e=>v({value:e.hash,...e},u(),e=>{c=`${e}~1`,l=e,o(),i(c,l)}))),f=t(`div`,`flex-none border-t border-neutral-200`,v({value:s,label:`↺ ${s} ↔ Working tree`,subject:`back to the default: the main line's tip vs the files on disk`},c===s&&l===``?s:``,()=>{c=s,l=``,h(),i(c,l)}));m.replaceChildren(t(`div`,`flex flex-none items-center gap-1 border-b border-neutral-200 px-2 py-1.5`,e(`Compare two points`,`compare`),e(`One commit`,`commit`)),a,...d===`compare`?[f]:[])}h(),a(e,m)}var te=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,y={A:`text-emerald-600`,M:`text-amber-600`,D:`text-red-600`},ne=30,b=`pier.filesPrefs`,x=50,S=()=>{try{let e=JSON.parse(localStorage.getItem(b)??`{}`);return e&&typeof e==`object`?e:{}}catch{return{}}},re=e=>{let t=e?S()[e]:void 0;return typeof t?.cwd==`string`&&typeof t.base==`string`&&typeof t.head==`string`?{cwd:t.cwd,base:t.base,head:t.head}:null},ie=(e,t)=>{let n=S();delete n[e],n[e]=t;let r=Object.keys(n);for(let e of r.slice(0,Math.max(0,r.length-x)))delete n[e];try{localStorage.setItem(b,JSON.stringify(n))}catch(e){console.warn(`Files: could not remember this folder`,e)}},C=(e,n=`indigo`)=>{let r=t(`button`,`min-w-0 cursor-pointer truncate rounded-md px-2 py-0.5 text-left font-mono text-[11.5px] ${n===`indigo`?`bg-indigo-50 font-medium text-indigo-700 hover:bg-indigo-100`:`bg-neutral-100 text-neutral-600 hover:bg-neutral-200`}`,e);return r.type=`button`,r};function w(n,a,o,p,h){let g=``,v=``,b={branch:null,refs:[],commits:[],worktrees:[]},x=`HEAD`,S=``,w=new Map,T=!0,E=!1,D=[],O=new Set,k=null,A=null,ae=t(`header`,`flex h-10 flex-none items-center gap-2 border-b border-neutral-200 bg-white px-3`),j=t(`div`,`flex-none border-b border-neutral-200`),M=t(`div`,`min-h-0 flex-1 overflow-y-auto py-1`),oe=t(`aside`,`flex w-64 flex-none flex-col border-r border-neutral-200 text-[12.5px] max-md:h-2/5 max-md:w-full max-md:border-b max-md:border-r-0`,j,M),N=t(`div`,`h-full min-w-0 overflow-auto`),P=t(`div`,`pointer-events-none absolute inset-y-0 right-0 z-20 hidden w-2`),se=t(`section`,`relative min-h-0 min-w-0 flex-1`,N,P);n.append(ae,t(`div`,`flex min-h-0 flex-1 max-md:flex-col`,oe,se));let F=(e,t)=>`/api/explorer/${e}?${new URLSearchParams({root:g,...t})}`,I=(e,t)=>`/api/fs/${e}?${new URLSearchParams({root:g,...t})}`,L=(e,n=`text-neutral-400`)=>t(`p`,`px-4 py-3 text-[12.5px] ${n}`,e),R=e=>{let t=0;for(let n of w.keys())n.startsWith(`${e}/`)&&t++;return t};function z(e,t){let n=new Set(t.map(e=>e.name)),r=e?`${e}/`:``;for(let[e,i]of w){if(i.status!==`D`||!e.startsWith(r))continue;let a=e.slice(r.length).split(`/`)[0];n.has(a)||(n.add(a),t.push({name:a,dir:e.slice(r.length).includes(`/`)}))}let i=t;return T&&b.branch&&(i=t.filter(e=>e.dir?R(`${r}${e.name}`)>0:w.has(`${r}${e.name}`))),i.sort((e,t)=>Number(t.dir)-Number(e.dir)||e.name.localeCompare(t.name)),i.map(e=>e.dir?ce(`${r}${e.name}`,e.name):le(`${r}${e.name}`,e.name))}async function B(t,n){try{let{entries:r}=await e(I(`ls`,{path:n}),`could not list this folder`);t.replaceChildren(...z(n,r)),t.childElementCount||t.append(L(T?`No changes.`:`Empty.`))}catch(e){let r=z(n,[]);r.length?t.replaceChildren(...r):t.replaceChildren(L(String(e),`text-red-600`))}}function ce(e,n){let r=R(e),a=[t(`span`,`truncate`,n)];r&&a.push(t(`span`,`ml-auto flex-none rounded bg-amber-100/80 px-1 font-mono text-[10px] text-amber-700`,String(r)));let{el:o,summary:s}=i(``,a);s.className+=` px-2 py-0.5 hover:bg-neutral-100`;let c=t(`div`,`pl-3`);o.append(c);let l=!1,u=()=>{l||(l=!0,c.append(L(`…`)),B(c,e))};return o.ontoggle=()=>{O[o.open?`add`:`delete`](e),o.open&&u()},(T&&b.branch&&!E||O.has(e))&&(o.open=!0,u()),o}function V(e){A?.classList.remove(`bg-indigo-50`,`text-indigo-700`),A=e,e.classList.add(`bg-indigo-50`,`text-indigo-700`)}function le(e,n){let r=w.get(e)?.status,i=t(`button`,`flex w-full cursor-pointer items-center gap-1.5 px-2 py-0.5 pl-6 text-left hover:bg-neutral-100`,t(`span`,`truncate`,n));return r&&i.append(t(`span`,`ml-auto flex-none font-mono text-[10.5px] font-semibold ${y[r]??`text-neutral-500`}`,r)),i.title=e,e===k&&V(i),i.onclick=()=>{V(i),k=e,Y(e)},i}let H=()=>void B(M,``),U=(e,n)=>[...e?[t(`span`,`flex-none font-mono text-[10.5px] font-semibold text-emerald-600`,`+${e}`)]:[],...n?[t(`span`,`flex-none font-mono text-[10.5px] font-semibold text-red-600`,`−${n}`)]:[]];function W(e,n,r){let i=w.get(e),a=t(`div`,`sticky top-0 z-10 flex items-center gap-2 border-b border-neutral-200 bg-white px-4 py-1.5 font-mono text-[11.5px] text-neutral-500`,t(`span`,`truncate`,e));i&&(a.append(t(`span`,`flex-none font-semibold ${y[i.status]??``}`,i.status)),a.append(...U(i.add,i.del)));let o=t(`div`,`ml-auto flex flex-none items-center gap-2`);if(r&&o.append(r),n){let t=document.createElement(`a`);t.className=`flex-none text-neutral-400 hover:text-indigo-700 hover:underline`,t.href=I(`file`,{path:e}),t.download=s(e),t.textContent=`Download`,o.append(t)}return a.append(o),a}function ue(e){let t=0;for(;t<e.length;){if(e[t].tone!==`del`){t++;continue}let n=t;for(;t<e.length&&e[t].tone===`del`;)t++;let r=t;for(;t<e.length&&e[t].tone===`add`;)t++;let i=Math.min(r-n,t-r);for(let t=0;t<i;t++){let i=e[n+t],a=e[r+t],o=Math.min(i.text.length,a.text.length),s=0;for(;s<o&&i.text[s]===a.text[s];)s++;let c=0;for(;c<o-s&&i.text[i.text.length-1-c]===a.text[a.text.length-1-c];)c++;s+c!==0&&(i.mark=[s,i.text.length-c],a.mark=[s,a.text.length-c])}}}let G=_e();function K(){P.classList.add(`hidden`),P.replaceChildren(),G.set([],[])}let q=0,J=e=>e===q;function Y(e){let t=++q;return w.has(e)?ve(e,t):de(e,t)}async function de(e,n){if(!J(n))return;K();let r=I(`file`,{path:e}),i=t(`div`,`min-w-0`);if(N.classList.remove(`flex`,`flex-col`),N.replaceChildren(W(e,!0),i),te.test(e)){let e=t(`img`,`max-w-full p-4`);e.src=r,e.onerror=()=>i.replaceChildren(L(`Could not load image.`,`text-red-600`)),i.append(e);return}if(e.toLowerCase().endsWith(`.pdf`)){let t=document.createElement(`iframe`);t.className=`h-full w-full`,t.src=r,N.replaceChildren(W(e,!0),t),N.classList.add(`flex`,`flex-col`);return}i.append(L(`…`));let a=await fetch(r);if(!J(n))return;if(!a.ok){let{error:e}=await a.json().catch(()=>({}));i.replaceChildren(L(e??`HTTP ${a.status}`,`text-red-600`));return}if(!(a.headers.get(`content-type`)??``).startsWith(`text/plain`)){i.replaceChildren(L(`Binary file — use Download.`));return}let o=(await a.text()).split(`
|
|
4
|
-
`);if(!J(n))return;o.at(-1)===``&&o.pop();let s=await c(e);J(n)&&i.replaceChildren(f(d(o),s))}function fe(e){let t=[],n=0,r=0,i=!1,a=e.split(`
|
|
5
|
-
`);a.at(-1)===``&&a.pop();for(let e of a){let a=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e);if(a){i&&t.push({nums:[``,``],text:`⋯`,tone:``}),[n,r]=[Number(a[1]),Number(a[2])],i=!0;continue}!i||e.startsWith(`\\`)||(e.startsWith(`+`)?t.push({nums:[``,r++],text:e.slice(1),tone:`add`}):e.startsWith(`-`)?t.push({nums:[n++,``],text:e.slice(1),tone:`del`}):t.push({nums:[n++,r++],text:e.slice(1),tone:``}))}return t}function pe(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n].tone;if(!r)continue;let i=t.at(-1);i&&i.end===n-1?(i.end=n,(r===`add`&&i.tone===`del`||r===`del`&&i.tone===`add`)&&(i.tone=`mixed`)):t.push({start:n,end:n,tone:r})}return t}let me={add:`bg-emerald-400`,del:`bg-red-400`,mixed:`bg-amber-400`};function he(e,n,r){P.replaceChildren(...e.map(e=>{let i=t(`button`,`pointer-events-auto absolute w-full cursor-pointer ${me[e.tone]}`);return i.style.top=`${e.start/n*100}%`,i.style.height=`${Math.max(.4,(e.end-e.start+1)/n*100)}%`,i.title=`line ${ge(r,e.start)}`,i.onclick=()=>r[e.start].scrollIntoView({block:`center`}),i})),P.classList.remove(`hidden`)}let ge=(e,t)=>e[t]?.querySelector(`span`)?.textContent?.trim()||String(t+1);function _e(){let e=[],r=[],i=-1,a=t(`span`,`flex-none text-[10.5px] text-neutral-400`),o=t=>{e.length&&(i=(i+t+e.length)%e.length,r[e[i].start].scrollIntoView({block:`center`}),a.textContent=`${i+1}/${e.length}`)},s=()=>e.length>0&&!n.classList.contains(`hidden`),c=(e,n,r,i)=>{let a=t(`button`,`icon-btn flex-none`,e);return a.onclick=()=>o(n),u(a,i,r,()=>o(n),s),a};return{el:t(`div`,`flex flex-none items-center gap-1`,a,c(`↑`,-1,`Previous change`,[`p`,`k`]),c(`↓`,1,`Next change`,[`n`,`j`])),set(t,n){e=t,r=n,i=-1,a.textContent=`${t.length} change${t.length===1?``:`s`}`}}}async function ve(t,n){K(),N.classList.remove(`flex`,`flex-col`);let r=w.get(t)?.status!==`D`;N.replaceChildren(W(t,r),L(`…`));try{let{diff:i}=await e(F(`diff`,{base:x,head:S,file:t,context:`99999`}),`could not read this diff`);if(!J(n))return;if(!i||/^Binary files /m.test(i))return de(t,n);let a=fe(i);ue(a);let o=await c(t);if(!J(n))return;let s=f(a,o),l=[...s.children],u=pe(a);G.set(u,l),N.replaceChildren(W(t,r,G.el),s),he(u,a.length,l)}catch(e){J(n)&&N.replaceChildren(W(t,!1),L(String(e),`text-red-600`))}}let X=()=>S&&x===`${S}~1`?S:``,ye=()=>b.commits.find(e=>e.hash===X())?.subject??``,be=()=>X()?`${X()} — ${ye()||`commit`}`:`${x} ↔ ${S||`working tree`}`,xe=(e,n,r,i)=>{let a=t(`button`,`flex h-6 w-6 flex-none cursor-pointer items-center justify-center rounded-md ${r?`bg-indigo-50 text-indigo-700`:`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-700`}`);return a.innerHTML=e,a.title=n,a.onclick=i,a};function Z(){let e=xe(`<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5"><path d="M2.5 3h11l-4.25 5v4.5l-2.5 1.25V8L2.5 3z" stroke-linejoin="round"/></svg>`,`Show only files that differ`,T,()=>{T=!T,Z(),H()}),n=xe(`<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5"><path d="m4.5 2.5 3.5 3 3.5-3M4.5 13.5l3.5-3 3.5 3" stroke-linecap="round" stroke-linejoin="round"/></svg>`,E?`Restore folders`:`Collapse all folders`,E,()=>{if(E=!E,E)D=[...O],O.clear();else for(let e of D)O.add(e);Z(),H()});if(!b.branch){j.replaceChildren(t(`div`,`flex items-center justify-end gap-1 p-1.5`,n));return}let r=C(be());if(X()){let e=b.commits.find(e=>e.hash===X());_(r,()=>e?m(e):``)}else r.title=`Choose what to diff`;r.onclick=async()=>{await Te(),ee(r,b,{base:x,head:S},(e,t)=>{x=e,S=t,Q()},Ee())};let[i,a]=[0,0];for(let e of w.values())i+=e.add,a+=e.del;j.replaceChildren(t(`div`,`flex flex-col gap-1 p-2`,r,t(`div`,`flex items-center gap-1.5 pl-1`,t(`span`,`text-[11px] text-neutral-400`,`${w.size} changed file${w.size===1?``:`s`}`),...U(i,a),t(`span`,`ml-auto`),e,n)))}let Se=()=>{v&&g&&ie(v,{cwd:g,base:x,head:S})},Ce=e=>{let t=e.replace(/~\d+$/,``);return!t||t===`HEAD`||b.refs.some(e=>e.name===t)||b.commits.some(e=>e.hash===t)};async function we(){if(w=new Map,!b.branch)return;let{files:t}=await e(F(`diff`,{base:x,head:S}),`could not read what changed`);for(let e of t)w.set(e.path,{status:e.status,add:e.add,del:e.del});if(w.size<=ne)for(let e of w.keys()){let t=e.split(`/`);for(let e=1;e<t.length;e++)O.add(t.slice(0,e).join(`/`))}}async function Q(){Se();try{await we()}catch(e){Z(),M.replaceChildren(L(String(e),`text-red-600`));return}Z(),H(),k&&Y(k)}function $(){let e=C(g||`Choose a folder…`,`neutral`);e.className+=` max-w-72`,e.title=`Switch folder`,e.onclick=()=>l(e,b.worktrees.map(e=>({path:e.path,...e.branch?{hint:e.branch}:{}})),g||void 0,o);let n=C(`Terminal`,`neutral`);n.title=`Open a shell in this folder`,n.onclick=()=>p(g);let r=t(`button`,`icon-btn`,`✕`);r.type=`button`,r.title=`Close Files`,r.setAttribute(`aria-label`,`Close Files`),r.onclick=h;let i=g?[n,r]:[r];i[0].classList.add(`ml-auto`),ae.replaceChildren(e,t(`span`,`truncate font-mono text-[11.5px] text-neutral-400`,b.branch?`⎇ ${b.branch}`:`no git`),...i)}async function Te(){if(g)try{b=await e(F(`git`,{}),`could not read this repository`),$()}catch(e){N.replaceChildren(L(String(e),`text-red-600`))}}let Ee=()=>b.refs.some(e=>e.name===`main`)?`main`:b.refs.some(e=>e.name===`master`)?`master`:`HEAD`;async function De(){if($(),k=null,A=null,O.clear(),K(),N.classList.remove(`flex`,`flex-col`),N.replaceChildren(L(`Select a file.`)),!g){j.replaceChildren(),M.replaceChildren(),N.replaceChildren(L(`No folder yet — pick one from the chip above.`));return}try{b=await e(F(`git`,{}),`could not read this repository`)}catch(e){b={branch:null,refs:[],commits:[],worktrees:[]},N.replaceChildren(L(String(e),`text-red-600`))}let t=re(v),n=t&&t.cwd===g&&Ce(t.base)&&Ce(t.head)?t:null;x=n?.base??Ee(),S=n?.head??``,$(),await Q()}return r(n,e=>{let t=a(),n=t?.id??``,r=e?.startsWith(`/`)?e:(n===v?g:``)||re(n)?.cwd||t?.cwd||``;if(r===g&&n===v&&M.childElementCount){$(),Te().then(Q);return}v=n,g=r,De()},()=>{K(),N.classList.remove(`flex`,`flex-col`),N.replaceChildren(L(`Select a file.`))})}export{w as createExplorerView};
|
|
Binary file
|
|
Binary file
|