my-durable 0.0.79 → 0.0.81
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/apps/dpi-backend/src/store.ts +89 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-CGMattPL.js → index-CqQCh8Ch.js} +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/git-rules.ts +6 -2
- package/apps/dpi-sdk/src/api.ts +4 -0
- package/package.json +1 -1
|
@@ -965,6 +965,11 @@ export class Store {
|
|
|
965
965
|
return d;
|
|
966
966
|
}
|
|
967
967
|
}),
|
|
968
|
+
// run-8 (live): folders this device will serve git/files for — the start
|
|
969
|
+
// dirs PLUS the folders that already host a session (a narrowed
|
|
970
|
+
// DPI_START_DIRS must not strand a live session's panels). Clients
|
|
971
|
+
// pre-check with THIS set, not with startDirs.
|
|
972
|
+
gitDirs: this.servedRootsSync(),
|
|
968
973
|
models: this.modelList,
|
|
969
974
|
defaultModel: this.defaultModel(),
|
|
970
975
|
provider: this.options.provider,
|
|
@@ -1161,6 +1166,85 @@ export class Store {
|
|
|
1161
1166
|
return roots;
|
|
1162
1167
|
}
|
|
1163
1168
|
|
|
1169
|
+
/** Folder names that must never become a served root on their own. */
|
|
1170
|
+
private static isFilesystemRoot(p: string): boolean {
|
|
1171
|
+
return p === "/" || /^[A-Za-z]:[\\/]?$/.test(p) || /^\\{2}[^\\]+[\\/]?$/.test(p);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* The roots the READ surface (git + file browse) may serve: the start dirs
|
|
1176
|
+
* PLUS every folder that already hosts a session.
|
|
1177
|
+
*
|
|
1178
|
+
* Why the union: the operator created those sessions, so that folder was
|
|
1179
|
+
* served by intent — narrowing DPI_START_DIRS later must not strand a live
|
|
1180
|
+
* session's git/files panels (the agent itself keeps running there, it is
|
|
1181
|
+
* unsandboxed by design). Folder CREATION stays start-dirs-only
|
|
1182
|
+
* (assertSessionCwdAllowed), so this cannot be used to widen the sandbox:
|
|
1183
|
+
* it only re-states what the device already served.
|
|
1184
|
+
*
|
|
1185
|
+
* Cached: one realpath per session cwd, invalidated whenever the session set
|
|
1186
|
+
* or cwds change. Filesystem roots are skipped so a session created at "/" or
|
|
1187
|
+
* "D:\" can never expose a whole volume.
|
|
1188
|
+
*/
|
|
1189
|
+
private servedCwds: { dirs: string[]; at: number } | null = null;
|
|
1190
|
+
private servedCwdsStale(): void {
|
|
1191
|
+
this.servedCwds = null;
|
|
1192
|
+
}
|
|
1193
|
+
async servedRoots(): Promise<string[]> {
|
|
1194
|
+
const starts = await this.startDirRoots();
|
|
1195
|
+
if (!this.servedCwds || Date.now() - this.servedCwds.at > 30_000) {
|
|
1196
|
+
const dirs: string[] = [];
|
|
1197
|
+
const seen = new Set(starts);
|
|
1198
|
+
for (const row of this.list()) {
|
|
1199
|
+
if (dirs.length >= 500) break;
|
|
1200
|
+
let real: string;
|
|
1201
|
+
try {
|
|
1202
|
+
real = await realpath(row.cwd);
|
|
1203
|
+
} catch {
|
|
1204
|
+
continue; // offline mount / deleted folder: nothing to serve
|
|
1205
|
+
}
|
|
1206
|
+
if (Store.isFilesystemRoot(real) || seen.has(real)) continue;
|
|
1207
|
+
seen.add(real);
|
|
1208
|
+
dirs.push(real);
|
|
1209
|
+
}
|
|
1210
|
+
this.servedCwds = { dirs, at: Date.now() };
|
|
1211
|
+
}
|
|
1212
|
+
return [...new Set([...starts, ...this.servedCwds.dirs])];
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/** Sync view of servedRoots() for deviceInfo(): start dirs (realpath'd where
|
|
1216
|
+
* possible) plus the session cwds already resolved by the last async call. */
|
|
1217
|
+
private servedRootsSync(): string[] {
|
|
1218
|
+
const dirs = this.startDirs.map((d) => {
|
|
1219
|
+
try {
|
|
1220
|
+
return realpathSync(d);
|
|
1221
|
+
} catch {
|
|
1222
|
+
return d;
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
if (!this.servedCwds) {
|
|
1226
|
+
// Cold cache (a rejected create just invalidated it): build it here so
|
|
1227
|
+
// deviceInfo never under-reports the served set the enforcer uses.
|
|
1228
|
+
const cwds: string[] = [];
|
|
1229
|
+
const seen = new Set(dirs);
|
|
1230
|
+
for (const row of this.list()) {
|
|
1231
|
+
if (cwds.length >= 500) break;
|
|
1232
|
+
let real: string;
|
|
1233
|
+
try {
|
|
1234
|
+
real = realpathSync(row.cwd);
|
|
1235
|
+
} catch {
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
if (Store.isFilesystemRoot(real) || seen.has(real)) continue;
|
|
1239
|
+
seen.add(real);
|
|
1240
|
+
cwds.push(real);
|
|
1241
|
+
}
|
|
1242
|
+
this.servedCwds = { dirs: cwds, at: Date.now() };
|
|
1243
|
+
}
|
|
1244
|
+
for (const d of this.servedCwds.dirs) if (!dirs.includes(d)) dirs.push(d);
|
|
1245
|
+
return dirs;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1164
1248
|
/** A resolved path IS a start dir root or lives under one. */
|
|
1165
1249
|
private underRoots(candidate: string, roots: string[]): boolean {
|
|
1166
1250
|
return roots.some((root) => candidate === root || candidate.startsWith(root + sep) || candidate.startsWith(root + "/"));
|
|
@@ -1224,7 +1308,7 @@ export class Store {
|
|
|
1224
1308
|
}
|
|
1225
1309
|
candidate = walked;
|
|
1226
1310
|
}
|
|
1227
|
-
if (!this.underRoots(candidate, await this.
|
|
1311
|
+
if (!this.underRoots(candidate, await this.servedRoots())) throw invalid("path must live under a start dir");
|
|
1228
1312
|
return candidate;
|
|
1229
1313
|
}
|
|
1230
1314
|
|
|
@@ -1280,7 +1364,7 @@ export class Store {
|
|
|
1280
1364
|
}
|
|
1281
1365
|
// Containment: only the start dirs and their subdirectories are listable —
|
|
1282
1366
|
// `~` and ".." traversal count only when they land inside one.
|
|
1283
|
-
const roots = await this.
|
|
1367
|
+
const roots = await this.servedRoots();
|
|
1284
1368
|
if (!this.underRoots(real, roots)) throw invalid("path must live under a start dir");
|
|
1285
1369
|
const dirs: { name: string; path: string }[] = [];
|
|
1286
1370
|
try {
|
|
@@ -1600,6 +1684,7 @@ export class Store {
|
|
|
1600
1684
|
|
|
1601
1685
|
/** `spawnKey` records which tool call created the session, in the same transaction as the session row. */
|
|
1602
1686
|
async create(body: CreateSessionBody, spawnKey?: string): Promise<SessionSummary> {
|
|
1687
|
+
this.servedCwdsStale(); // a new session cwd joins the served set
|
|
1603
1688
|
if (typeof body?.name !== "string") throw invalid("name is required");
|
|
1604
1689
|
if (typeof body.cwd !== "string" || !body.cwd.trim()) throw invalid("cwd is required");
|
|
1605
1690
|
// One name rule for create and rename (assertSessionName, module scope): the old
|
|
@@ -1705,6 +1790,7 @@ export class Store {
|
|
|
1705
1790
|
|
|
1706
1791
|
/** Stop all work, close the harness and move its files to archive/. Nothing is deleted. */
|
|
1707
1792
|
async archive(row: SessionRow) {
|
|
1793
|
+
this.servedCwdsStale();
|
|
1708
1794
|
// FIRST act, before any await: reopens racing the window below compare
|
|
1709
1795
|
// against this epoch and fail like any dead row (run-7 B1-A).
|
|
1710
1796
|
this.archiveEpoch.set(row.id, (this.archiveEpoch.get(row.id) ?? 0) + 1);
|
|
@@ -1792,6 +1878,7 @@ export class Store {
|
|
|
1792
1878
|
}
|
|
1793
1879
|
|
|
1794
1880
|
async restoreArchivedSession(sessionId: string): Promise<SessionSummary> {
|
|
1881
|
+
this.servedCwdsStale();
|
|
1795
1882
|
// R19 (run-5 h4 hardening): normalize ONCE — the live-check used to be
|
|
1796
1883
|
// case-sensitive while the pin was case-normalized and the move target
|
|
1797
1884
|
// raw, so an uppercase-hex id could bypass the live-session refusal and
|
|
@@ -12,7 +12,7 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],en
|
|
|
12
12
|
|
|
13
13
|
`))>=0;){let e=f.slice(0,p),t=hu(e);if(t>n)throw a();f=f.slice(p+2),s-=t+2;let r=_u(e);r&&(yield r)}if(s>n)throw a();o=f?[f]:[],c=f.slice(-1)}}finally{r.cancel().catch(()=>{})}}function _u(e){let t=`message`,n,r=[];for(let i of e.split(`
|
|
14
14
|
`)){if(!i||i.startsWith(`:`))continue;let e=i.indexOf(`:`),a=e<0?i:i.slice(0,e),o=e<0?``:i.slice(e+1).replace(/^ /,``);a===`event`?t=o:a===`data`?r.push(o):a===`id`&&(n=o)}return r.length?{event:t,data:r.join(`
|
|
15
|
-
`),id:n}:void 0}var vu=encodeURIComponent,yu=()=>globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random().toString(36).slice(2)}`,bu=e=>e.normalize(`NFKD`).replace(/[^\w.-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,60).toLowerCase()||`session`,xu=class{token;hooks;baseUrl;constructor(e,t,n={}){this.token=t,this.hooks=n,this.baseUrl=e.replace(/\/+$/,``)}headers(e,t={}){return{...this.token?{authorization:`Bearer ${this.token}`,"x-dpi-token":this.token}:{},...e?{"content-type":`application/json`}:{},...t}}async request(e,t,n,r={}){let i=AbortSignal.timeout(r.timeoutMs??2e4),a=r.signal?AbortSignal.any([r.signal,i]):i,o;try{o=await fetch(this.baseUrl+t,{method:e,signal:a,headers:this.headers(n!==void 0,r.idempotencyKey?{"idempotency-key":r.idempotencyKey}:{}),body:n===void 0?void 0:JSON.stringify(n)})}catch(e){throw r.signal?.aborted?e:new Cl(`offline`,`Cannot reach ${this.baseUrl}`,0,{cause:e})}let s=await o.text(),c;try{c=s?JSON.parse(s):void 0}catch{c=void 0}if(!o.ok){let e=c?.error;throw new Cl(e?.code??(o.status===401?`unauthorized`:o.status===404?`not_found`:`internal`),e?.message??`${o.status} ${o.statusText}`,o.status)}return o.headers.get(`idempotent-replay`)===`true`&&this.hooks.onIdempotentReplay?.(t),c}async*stream(e,t,n){let r;try{r=await fetch(this.baseUrl+e,{headers:{...this.headers(!1),accept:`text/event-stream`},signal:t})}catch(e){if(t.aborted)return;throw new Cl(`offline`,`Cannot reach ${this.baseUrl}`,0,{cause:e})}if(!r.ok||!r.body){let e=await r.json().catch(()=>void 0);throw new Cl(e?.error?.code??(r.status===401?`unauthorized`:`unavailable`),e?.error?.message??`Stream failed (${r.status})`,r.status)}try{for await(let e of gu(r.body,n))yield JSON.parse(e.data)}catch(e){if(t.aborted)return;throw e}}device(e){return this.request(`GET`,`/v1/device`,void 0,e)}vitals(){return this.request(`GET`,`/v1/device/vitals`)}tree(){return this.request(`GET`,`/v1/tree`)}projects(e=!1){return this.request(`GET`,`/v1/projects${e?`?includeArchived=1`:``}`)}updateProject(e,t){return this.request(`PATCH`,`/v1/projects/${vu(e)}`,t)}archiveProject(e){return this.request(`POST`,`/v1/projects/${vu(e)}/archive`,{})}unarchiveProject(e){return this.request(`POST`,`/v1/projects/${vu(e)}/unarchive`,{})}notifySinks(){return this.request(`GET`,`/v1/notify/sinks`)}createNotifySink(e){return this.request(`POST`,`/v1/notify/sinks`,e)}updateNotifySink(e,t){return this.request(`PATCH`,`/v1/notify/sinks/${vu(e)}`,t)}removeNotifySink(e){return this.request(`DELETE`,`/v1/notify/sinks/${vu(e)}`)}testNotifySinks(){return this.request(`POST`,`/v1/notify/test`,{})}envView(){return this.request(`GET`,`/v1/device/env`)}setEnvVar(e,t){return this.request(`POST`,`/v1/device/env`,{key:e,value:t})}removeEnvVar(e){return this.request(`DELETE`,`/v1/device/env/${vu(e)}`)}piAuth(){return this.request(`GET`,`/v1/device/pi-auth`)}setPiApiKey(e,t){return this.request(`PUT`,`/v1/device/pi-auth/${vu(e)}`,{key:t})}removePiApiKey(e){return this.request(`DELETE`,`/v1/device/pi-auth/${vu(e)}`)}graphs(){return this.request(`GET`,`/v1/graphs`)}graph(e){return this.request(`GET`,`/v1/graphs/${vu(e)}`)}createGraph(e){return this.request(`POST`,`/v1/graphs`,e)}runGraph(e){return this.request(`POST`,`/v1/graphs/${vu(e)}/run`,{})}removeGraph(e){return this.request(`DELETE`,`/v1/graphs/${vu(e)}`)}schedules(){return this.request(`GET`,`/v1/schedules`)}createSchedule(e){return this.request(`POST`,`/v1/schedules`,e)}updateSchedule(e,t){return this.request(`PATCH`,`/v1/schedules/${vu(e)}`,t)}removeSchedule(e){return this.request(`DELETE`,`/v1/schedules/${vu(e)}`)}runSchedule(e){return this.request(`POST`,`/v1/schedules/${vu(e)}/run`,{})}deviceUsage(){return this.request(`GET`,`/v1/device/usage`)}searchSessions(e,t){return this.request(`GET`,`/v1/sessions/search?q=${vu(e)}${t===`all`?`&scope=all`:``}`)}dirs(e=``){return this.request(`GET`,`/v1/fs/dirs?path=${vu(e)}`)}deviceDoc(e){return this.request(`GET`,`/v1/docs/${vu(e)}`)}deviceEvents(e,t=[]){return this.stream(`/v1/events${t.length?`?docs=${t.map(vu).join(`,`)}`:``}`,e)}gitStatus(e,t={}){return this.request(`GET`,`/v1/git/status?path=${vu(e)}`,void 0,t)}gitOp(e,t,n={}){return this.request(`POST`,`/v1/git`,{path:e,op:t,...n})}async exportSession(e,t={}){let n=AbortSignal.timeout(t.timeoutMs??6e4),r=t.signal?AbortSignal.any([t.signal,n]):n,i;try{i=await fetch(this.baseUrl+`/v1/sessions/${vu(e)}/export`,{headers:this.headers(!1),signal:r})}catch(e){throw t.signal?.aborted?e:new Cl(`offline`,`Cannot reach ${this.baseUrl}`,0,{cause:e})}if(!i.ok){let e=await i.text().catch(()=>``),t;try{t=e?JSON.parse(e):void 0}catch{t=void 0}throw new Cl(t?.error?.code??(i.status===401?`unauthorized`:i.status===404?`not_found`:`internal`),t?.error?.message??`${i.status} ${i.statusText}`,i.status)}let a=new Uint8Array(await i.arrayBuffer()),o=i.headers.get(`content-disposition`)??``,s=/filename="((?:[^"\\]|\\.)*)"/i.exec(o)?.[1],c=/filename=([^;\s]+)/i.exec(o)?.[1];return{filename:(s===void 0?c:s.replace(/\\(.)/g,`$1`))||`${bu(e)}.bundle.zip`,mime:i.headers.get(`content-type`)??`application/zip`,bytes:a}}sessionGitFiles(e){return this.request(`GET`,`/v1/sessions/${vu(e)}/git-files`)}sessionGitTurns(e){return this.request(`GET`,`/v1/sessions/${vu(e)}/git-turns`)}gitStatusBatch(e,t={}){return this.request(`POST`,`/v1/git/status-batch`,{paths:e},t)}sessions(){return this.request(`GET`,`/v1/sessions`)}archived(){return this.request(`GET`,`/v1/archive`)}archivedTranscript(e,t=`markdown`){return this.request(`GET`,`/v1/archive/${vu(e)}/transcript?format=${t}`)}restoreArchived(e){return this.request(`POST`,`/v1/archive/${vu(e)}/restore`,{})}createSession(e,t=yu()){return this.request(`POST`,`/v1/sessions`,e,{idempotencyKey:t})}session(e){return new Su(this,e)}agent(e,t){return new Cu(this,e,String(t))}},Su=class{client;ref;constructor(e,t){this.client=e,this.ref=t}get base(){return`/v1/sessions/${vu(this.ref)}`}get(){return this.client.request(`GET`,this.base)}rename(e){return this.client.request(`PATCH`,this.base,{name:e})}archive(){return this.client.request(`DELETE`,this.base)}agents(){return this.client.request(`GET`,`${this.base}/agents`)}createAgent(e={},t=yu()){return this.client.request(`POST`,`${this.base}/agents`,e,{idempotencyKey:t})}tasks(e=`terminal`,t=20){return this.client.request(`GET`,`${this.base}/tasks?status=${e}&limit=${t}`)}abortTask(e){return this.client.request(`POST`,`${this.base}/tasks/${e}/abort`,{})}inspect(){return this.client.request(`GET`,`${this.base}/inspect`)}compaction(){return this.client.request(`GET`,`${this.base}/compaction`)}setCompaction(e){return this.client.request(`PATCH`,`${this.base}/compaction`,e)}submission(e,t=0){return this.client.request(`GET`,`${this.base}/submissions/${e}?waitMs=${t}`,void 0,{timeoutMs:t+2e4})}events(e){return this.client.stream(`${this.base}/events`,e)}},Cu=class{client;session;agent;constructor(e,t,n){this.client=e,this.session=t,this.agent=n}get base(){return`/v1/sessions/${vu(this.session)}/agents/${vu(this.agent)}`}get(){return this.client.request(`GET`,this.base)}rename(e){return this.client.request(`PATCH`,this.base,{name:e})}send(e,t=`followUp`,n=yu(),r){return this.client.request(`POST`,`${this.base}/messages`,{content:e,whenBusy:t,requestId:n,waitMs:r},{timeoutMs:(r??0)+2e4})}withdraw(e){return this.client.request(`DELETE`,`${this.base}/inbox/${e}`)}abort(e=!1){return this.client.request(`POST`,`${this.base}/abort`,{background:e})}fork(e,t=yu()){return this.client.request(`POST`,`${this.base}/fork`,e,{idempotencyKey:t})}config(){return this.client.request(`GET`,`${this.base}/config`)}configure(e){return this.client.request(`PATCH`,`${this.base}/config`,e)}compact(e){return this.client.request(`POST`,`${this.base}/compact`,{instructions:e})}reset(e){return this.client.request(`POST`,`${this.base}/reset`,{note:e})}entries(e={}){let t=new URLSearchParams({scope:e.scope??`all`,limit:String(e.limit??500),...e.cursor?{cursor:e.cursor}:{}});return this.client.request(`GET`,`${this.base}/entries?${t}`)}transcript(e=`json`){return this.client.request(`GET`,`${this.base}/transcript?format=${e}`)}doc(e){return this.client.request(`GET`,`${this.base}/docs/${vu(e)}`)}extensions(){return this.client.request(`GET`,`${this.base}/extensions`)}setExtension(e){return this.client.request(`PATCH`,`${this.base}/extensions`,e)}demo(e,t,n=`POST`){return this.client.request(n,`${this.base}/demo/${e}`,t)}events(e,t=[]){return this.client.stream(`${this.base}/events${t.length?`?docs=${t.map(vu).join(`,`)}`:``}`,e)}};function wu(e,t){let n=String(e??``).trim();return t?n.replace(/\//g,`\\`).replace(/\\+$/,``).toLowerCase():n.replace(/\/+$/,``)}function Tu(e,t){let n=e?.startDirs;if(!Array.isArray(n)||n.length===0)return!0;let r=String(e?.platform??``).startsWith(`win32`),i=wu(t,r);return n.some(e=>{let t=wu(String(e),r);return!!t&&(i===t||i.startsWith(r?`${t}\\`:`${t}/`))})}function Eu(e){let t=Array.isArray(e?.startDirs)?e.startDirs.map(String):[];return t.length?`outside the device's start dirs (it serves: ${t.join(`, `)})`:`outside the device's start dirs`}var Du=0,Ou=e=>new xu(`/api/devices/${encodeURIComponent(e)}`,void 0,{onIdempotentReplay:e=>{Date.now()-Du<3e4||(Du=Date.now(),J(`Replayed an earlier identical request (${e}) — send a custom idempotency key for deliberate repeats.`))}}),W=e=>{let t=Ou(e),n=()=>Hu.devices.value.find(t=>t.id===e)?.info,r=t.gitOp.bind(t);return t.gitOp=((e,t,i)=>{let a=n();return a&&e&&!Tu(a,e)?Promise.reject(new Cl(`invalid`,`git ${t} skipped: ${Eu(a)}`,400)):r(e,t,i)}),t};async function ku(e,t,n){let r=await fetch(`/api${t}`,{method:e,headers:n===void 0?{}:{"content-type":`application/json`},body:n===void 0?void 0:JSON.stringify(n)}),i=await r.json().catch(()=>void 0);if(!r.ok){let e=i?.error;throw new Cl(e?.code??`internal`,e?.message??`${r.status} ${r.statusText}`,r.status)}return i}var Au={network:()=>ku(`GET`,`/network`),version:()=>ku(`GET`,`/version`),check:e=>ku(`POST`,`/devices/${encodeURIComponent(e)}/check`,{}),createShare:e=>ku(`POST`,`/shares`,e),async uiGet(e){return(await ku(`GET`,`/ui-state/${encodeURIComponent(e)}`)).value??void 0},uiSet:(e,t)=>ku(`PUT`,`/ui-state/${encodeURIComponent(e)}`,{value:t})},G=e=>e instanceof Error?e.message:String(e),ju=[`demo.job-runs`,`demo.workspace`],Mu=e=>`${e.deviceId}/agent/${e.sessionId}/${e.agentId}?docs=${ju.join(`,`)}`,Nu=e=>`${e.deviceId}/session/${e.sessionId}`,Pu=e=>`${e}/device?docs=app.shared-state`;function Fu(e,t,n,r=`hello`){let i=O(`idle`),a=O(``);return e.route(t,e=>{e.type===`hello`?(i.value=r===`hello`?`live`:`connecting`,r===`hello`&&(a.value=``)):e.type===`disconnected`?i.value=`reconnecting`:e.type===`fault`?(i.value=`fault`,a.value=e.error.message):(n(e),e.type===r&&(a.value=``,i.value=`live`))}),{status:i,fault:a,select:n=>{a.value=``,i.value=n?`connecting`:`idle`,e.set(t,n)},retry:()=>{i.value=`connecting`,e.reopen(t)}}}function Iu(e){let t=new nu,n=O(0);return t.subscribe(()=>n.value++),e.onNetwork(e=>t.apply({type:`network`,devices:e})),{model:t,devices:H(()=>(n.value,t.devices)),tree:H(()=>(n.value,t.tree()))}}function Lu(e,t){let n=an(),r=an([]),{status:i,select:a}=Fu(e,`device`,e=>{e.type===`doc`&&e.kind===`app.shared-state`?n.value={value:e.value,revision:e.revision??0}:e.type===`activity`&&(r.value=[...r.value,...e.items].slice(-50))});return j(t,e=>{n.value=void 0,a(e?Pu(e):void 0)},{immediate:!0}),{sharedState:n,activity:r,status:i}}function Ru(e,t){let n=new Yl,r=O(0);n.subscribe(()=>r.value++);let{status:i,fault:a,select:o}=Fu(e,`session`,e=>n.apply(e));return j(()=>t.value?Nu(t.value):void 0,e=>{n.clear(),o(e)},{immediate:!0}),{model:n,state:H(()=>(r.value,n.state)),status:i,fault:a}}function zu(e,t){let n=new Jl,r=O(0);n.subscribe(()=>r.value++);let{status:i,fault:a,select:o,retry:s}=Fu(e,`agent`,e=>n.apply(e),`snapshot`);return j(()=>t.value?Mu(t.value):void 0,e=>{n.clear(),o(e)},{immediate:!0}),{model:n,state:H(()=>(r.value,{...n.state})),status:i,fault:a,version:r,retry:s}}var Bu=new cu,Vu=O(Bu.state);Bu.onState(e=>Vu.value=e);var Hu=Iu(Bu),Uu=O(),Wu=O(),K=O(),Gu=O(new Set),Ku=O(300),qu=Gt({tree:!0,inspector:!0}),Ju=O(!1),Yu=H(()=>K.value?.deviceId),Xu=H(()=>Hu.devices.value.find(e=>e.id===Yu.value)),Zu=H(()=>Xu.value?.status===`online`),Qu=Ru(Bu,H(()=>K.value?{deviceId:K.value.deviceId,sessionId:K.value.sessionId}:void 0)),$u=zu(Bu,K),ed=Lu(Bu,Yu),td=H(()=>Xu.value?.tree?.sessions.find(e=>e.id===K.value?.sessionId)),nd=H(()=>Yu.value?W(Yu.value):void 0),rd=H(()=>K.value&&nd.value?nd.value.agent(K.value.sessionId,K.value.agentId):void 0),id=H(()=>K.value&&nd.value?nd.value.session(K.value.sessionId):void 0);function ad(e){K.value=e,q.drawer=!1,od=!!e,sd()}var od=!1;function sd(){let e=K.value;if(!od||!e)return;let t=Hu.devices.value.find(t=>t.id===e.deviceId)?.tree?.sessions.find(t=>t.id===e.sessionId)?.agents,n=new Map((t??[]).map(e=>[e.id,e])),r=[e.deviceId,`${e.deviceId}/s/${e.sessionId}`,`${e.deviceId}/s/${e.sessionId}/a/${e.agentId}`],i=n.get(e.agentId),a=new Set;for(;i&&!a.has(i.id);){a.add(i.id);let t=i.parentId??i.ownerAgentId;if(t===void 0)break;r.push(`${e.deviceId}/s/${e.sessionId}/a/${t}`),i=n.get(t)}r.some(e=>!Gu.value.has(e))&&(Gu.value=new Set([...Gu.value,...r])),n.has(e.agentId)&&(od=!1)}j(()=>Hu.devices.value,sd);function cd(e,t){let n=new Set(Gu.value);t??!n.has(e)?n.add(e):n.delete(e),Gu.value=n}var ld=(()=>{let e=new Map;return(t,n)=>{clearTimeout(e.get(t)),e.set(t,setTimeout(()=>void Au.uiSet(t,n).catch(()=>{}),300))}})();j(K,e=>Ju.value&&void Au.uiSet(`tree.selected`,e??null).catch(()=>{})),j(Ku,e=>Ju.value&&ld(`tree.width`,e)),j(qu,e=>Ju.value&&ld(`layout.panels`,{...e}));async function ud(){let e;try{e=await Au.network()}catch(e){e instanceof Cl&&e.status===401||Bu.start(),q.error=G(e),Ju.value=!0;return}Bu.start();try{let[t,n,r]=await Promise.all([Au.uiGet(`tree.selected`),Au.uiGet(`tree.width`),Au.uiGet(`layout.panels`)]);r&&Object.assign(qu,r),Au.version().then(e=>Wu.value=e.version).catch(()=>{}),Uu.value=e.configFile,Hu.model.devices.length||Hu.model.apply({type:`network`,devices:e.devices}),Gu.value=new Set,n&&(Ku.value=n),t&&e.devices.some(e=>e.id===t.deviceId)?ad(t):dd(e.devices)}catch(e){q.error=G(e)}finally{Ju.value=!0}}function dd(e){for(let t of e){let e=t.status===`online`?t.tree?.sessions[0]:void 0,n=e?.agents.find(e=>e.kind===`root`)??e?.agents[0];if(e&&n)return ad({deviceId:t.id,sessionId:e.id,agentId:n.id})}}j(()=>[$u.status.value,td.value],([e,t])=>{e===`fault`&&!t&&Zu.value&&(J(`That session was archived on its device.`),ad(void 0))});var fd=H(()=>Xu.value?.info?.models??[]),pd=$u.state,md=H(()=>Qu.state.value.agents.length?Qu.state.value.agents:td.value?.agents??[]),hd=H(()=>K.value?Xl(md.value,K.value.agentId):[]),gd=H(()=>{let e=K.value?.agentId;if(e===void 0)return[];let t=md.value,n=new Set([e]);for(let e=!0;e;){e=!1;for(let r of t)r.ownerAgentId!==void 0&&n.has(r.ownerAgentId)&&!n.has(r.id)&&(n.add(r.id),e=!0)}let r=Qu.state.value.tasks,i=new Map(r.map(e=>[e.id,e])),a=new Map(t.map(e=>[e.id,e.ownerTaskId]));return r.filter(e=>n.has(e.conversationId)).map(e=>{let t=e,n=!1,r=new Set;for(;t&&!r.has(t.id);){if(r.add(t.id),t.background){n=!0;break}let e=t.owner??a.get(t.conversationId);t=e===void 0?void 0:i.get(e)}return{...e,effectiveBackground:n}})}),_d=H(()=>pd.value.running||gd.value.some(e=>!e.effectiveBackground&&e.conversationId===K.value?.agentId)),vd=H(()=>jl(pd.value.usage)),yd=H(()=>{let e=pd.value.agent.model;return fd.value.find(t=>t.provider===e?.provider&&t.id===e?.modelId)}),bd=H(()=>{let e=pd.value.agent.model;if(e?.modelId)return e;let t=td.value;return t?.model?{provider:t.provider??``,modelId:t.model}:void 0}),xd=H(()=>{let e=bd.value;return e?fd.value.find(t=>t.provider===e.provider&&t.id===e.modelId):void 0}),Sd=an(),Cd=0;async function wd(){let e=rd.value,t=++Cd;if(!e||!Zu.value)return void(Sd.value=void 0);try{let n=await e.get();t===Cd&&(Sd.value=n)}catch{t===Cd&&(Sd.value=void 0)}}j([rd,Zu],()=>void wd(),{immediate:!0});var q=Gt({error:``,toast:``,drawer:!1,inspectorOverlay:!1,tab:`session`,composer:``,dialog:void 0}),Td,Ed=Gt([]),Dd=1;function Od(){for(let e of Ed)e.read=!0}function J(e){q.toast=e,e&&(Ed.unshift({id:Dd++,text:e,at:Date.now(),read:!1}),Ed.length>50&&(Ed.length=50)),clearTimeout(Td),Td=setTimeout(()=>q.toast=``,4500)}async function kd(e){q.error=``;try{return await e()}catch(e){q.error=G(e);return}}function Ad(e){q.composer=e,setTimeout(()=>document.querySelector(`.composer textarea`)?.focus())}var jd=e=>Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1}).format(e),Md=e=>JSON.stringify(e,null,2),Nd=(e=``)=>uu(fd.value.find(t=>t.id===e)?.icon);function Pd(e){if(!e)return`never`;let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`${t}s ago`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}var Fd=O(!1);async function Id(){_d.value&&!Fd.value&&rd.value&&(Fd.value=!0,await kd(()=>rd.value.abort(!1))&&J(`Foreground work interrupted. Background jobs continue.`),Fd.value=!1)}var Ld=window.matchMedia(`(max-width: 1100px)`),Rd=O(Ld.matches);Ld.addEventListener(`change`,e=>Rd.value=e.matches);var zd=H(()=>Rd.value?q.inspectorOverlay:qu.inspector);function Bd(e){e&&(q.tab=e),Rd.value?(q.drawer=!1,q.inspectorOverlay=!0):qu.inspector=!0}function Vd(){Rd.value?q.inspectorOverlay=!1:qu.inspector=!1}function Hd(){Rd.value?(q.drawer=!q.drawer)&&(q.inspectorOverlay=!1,qu.tree=!0):qu.tree=!qu.tree}function Ud(){zd.value?Vd():Bd()}var Wd=/Mac|iPhone|iPad/.test(navigator.userAgent),Gd=Wd?{tree:`Ctrl+N`,inspector:`Ctrl+T`}:{tree:`Alt+Shift+N`,inspector:`Alt+Shift+T`};function Kd(e){if(!(!(Wd?e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey:e.altKey&&e.shiftKey&&!e.ctrlKey&&!e.metaKey)||e.repeat||e.isComposing)){if(e.code===`KeyN`)return`tree`;if(e.code===`KeyT`)return`inspector`}}var qd={class:`topbar`},Jd={class:`brand`},Yd={class:`daemon`,"data-testid":`topbar-stats`},Xd=[`title`],Zd={class:`top-actions`},Qd={key:0,class:`usage-chip`,title:`This session's token usage and cost`},$d=[`aria-label`,`title`],ef={key:0,class:`bell-dot`},tf={key:0,class:`hint`},nf={class:`when`},rf=[`disabled`],af=[`disabled`],of=M({__name:`TopBar`,emits:[`newSession`],setup(e,{emit:t}){let n=O(!1),r=H(()=>Ed.filter(e=>!e.read).length),i=()=>{n.value=!n.value,n.value&&Od()},a=e=>{let t=Math.round((Date.now()-e)/1e3);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`},o=H(()=>vd.value.input+vd.value.output+vd.value.cacheRead+vd.value.cacheWrite),s=H(()=>(vd.value.inputCost??0)+(vd.value.outputCost??0)+(vd.value.cacheReadCost??0)+(vd.value.cacheWriteCost??0)),c=H(()=>Hu.devices.value.filter(e=>e.status===`online`).length),l=H(()=>Hu.devices.value.reduce((e,t)=>e+(t.tree?.sessions.length??0),0)),u=H(()=>Hu.devices.value.reduce((e,t)=>e+(t.tree?.sessions.reduce((e,t)=>e+t.agents.length,0)??0),0)),d=O(!1);async function f(){let e=id.value,t=K.value;if(!e||!t||d.value)return;d.value=!0;let n=await kd(()=>e.createAgent({name:`Agent ${md.value.length+1}`}));d.value=!1,n&&(ad({...t,agentId:n.id}),J(`New agent. Same session, same shared App State.`))}let p=t;return(e,t)=>(F(),I(`header`,qd,[R(`div`,Jd,[R(`button`,{class:`icon-button tree-toggle`,"aria-label":`Toggle network`,title:`Network`,onClick:t[0]||=e=>k(q).drawer=!k(q).drawer},[z(k(Kc),{size:19})]),t[6]||=R(`img`,{class:`brandmark`,src:`/icons/durable-pi.svg`,alt:`Durable Pi`},null,-1),t[7]||=R(`strong`,null,`Durable Pi`,-1)]),t[15]||=R(`span`,{class:`topbar-sep`,"aria-hidden":`true`},null,-1),R(`div`,Yd,[R(`span`,{class:E([`dot`,{off:!c.value}]),"aria-hidden":`true`},null,2),R(`span`,{class:`network-summary`,title:`${c.value} of ${k(Hu).devices.value.length} devices online`},[z(k(Vc),{size:16}),B(D(c.value)+` of `+D(k(Hu).devices.value.length)+` online`,1)],8,Xd),t[10]||=R(`span`,{class:`sep`,"aria-hidden":`true`},`·`,-1),R(`span`,null,[R(`b`,null,D(l.value),1),t[8]||=B(` sessions`,-1)]),t[11]||=R(`span`,{class:`sep`,"aria-hidden":`true`},`·`,-1),R(`span`,null,[R(`b`,null,D(u.value),1),t[9]||=B(` agents`,-1)])]),R(`div`,Zd,[R(`span`,{class:E([`chip connection`,{accent:k(Vu)===`live`}])},[R(`span`,{class:E([`dot`,{off:k(Vu)!==`live`}]),"aria-hidden":`true`},null,2),B(D(k(Vu)===`live`?`Connected`:`Reconnecting`),1)],2),o.value?(F(),I(`span`,Qd,D(o.value.toLocaleString())+` tok · $`+D(s.value.toFixed(3)),1)):V(``,!0),R(`button`,{class:`icon-button`,"aria-label":`Notifications${r.value?` (${r.value} unread)`:``}`,title:`Notification center${r.value?` — ${r.value} unread`:``}`,onClick:i},[z(k(Zs),{size:18}),r.value?(F(),I(`i`,ef,D(r.value>9?`9+`:r.value),1)):V(``,!0)],8,$d),n.value?(F(),I(`div`,{key:1,class:`notif-panel`,onClick:t[2]||=As(()=>{},[`stop`])},[R(`header`,null,[t[12]||=R(`b`,null,`Notifications`,-1),R(`button`,{class:`icon-button`,"aria-label":`Close notifications`,onClick:t[1]||=e=>n.value=!1},`✕`)]),k(Ed).length?V(``,!0):(F(),I(`p`,tf,`Nothing yet — events land here as they happen.`)),R(`ul`,null,[(F(!0),I(P,null,N(k(Ed),e=>(F(),I(`li`,{key:e.id,class:E({unread:!e.read})},[R(`span`,nf,D(a(e.at)),1),R(`span`,null,D(e.text),1)],2))),128))])])):V(``,!0),R(`button`,{class:`icon-button`,title:`How this works`,"aria-label":`How this works`,onClick:t[3]||=e=>k(q).dialog={kind:`help`}},[z(k(oc),{size:19})]),R(`button`,{class:`secondary small new-agent-button`,disabled:!k(K)||!k(Zu)||d.value,title:`Start a fresh agent in this session`,onClick:f},[z(k(Zc),{size:18}),t[13]||=B(`New agent `,-1)],8,rf),R(`button`,{class:`primary small`,onClick:t[4]||=e=>p(`newSession`)},[z(k(Zc),{size:18}),t[14]||=B(`New session `,-1)]),R(`button`,{class:`icon-button inspector-toggle`,"aria-label":`Toggle inspector`,title:`Inspector`,disabled:!k(K)||!k(Zu),onClick:t[5]||=e=>k(q).inspectorOverlay?k(Vd)():k(Bd)()},[z(k(qc),{size:19})],8,af)])]))}}),sf=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},cf=sf(of,[[`__scopeId`,`data-v-de526f26`]]),lf={class:`mnav`,"aria-label":`Panels`},uf={key:0,class:`badge`},df=M({__name:`MobileNav`,setup(e){function t(){q.drawer=!1,q.inspectorOverlay=!1}return(e,n)=>(F(),I(`nav`,lf,[R(`button`,{type:`button`,class:E({"is-on":!k(q).drawer&&!k(zd)}),onClick:t},[z(k(Rc),{size:18}),n[2]||=B(`Chat `,-1)],2),R(`button`,{type:`button`,class:E({"is-on":k(zd)}),onClick:n[0]||=e=>k(zd)?k(Vd)():k(Bd)()},[z(k(qc),{size:18}),n[3]||=B(`Details`,-1),k(gd).length?(F(),I(`span`,uf,D(k(gd).length),1)):V(``,!0)],2),R(`button`,{type:`button`,class:E({"is-on":k(q).drawer}),onClick:n[1]||=e=>k(Hd)()},[z(k(_l),{size:18}),n[4]||=B(`Network `,-1)],2)]))}}),ff=[`width`,`height`,`aria-label`],pf=[`width`,`height`,`aria-label`],mf=M({__name:`DeviceIcon`,props:{device:{},size:{default:16}},setup(e){let t=e,n=H(()=>{let e=t.device;return e?.kind===`exe-dev`||e?.url?.includes(`.exe.xyz`)?`exe`:e?.info?.platform.startsWith(`darwin`)?`apple`:e?.kind===`local`?`laptop`:`server`}),r=H(()=>{let e={exe:`exe.dev VM`,apple:`macOS`,laptop:`This computer`,server:`Server`}[n.value];return t.device?.transport===`tunnel`?`${e} (tunnel)`:e});return(t,i)=>n.value===`exe`?(F(),I(`svg`,{key:0,class:`device-icon exe`,viewBox:`0 0 512 512`,width:e.size,height:e.size,role:`img`,"aria-label":r.value},[R(`title`,null,D(r.value),1),i[0]||=R(`path`,{fill:`currentColor`,"fill-rule":`evenodd`,d:`M8 332.2l.9 1.4 1.5 .5 38.5-4.1 3.1 .4 2.7 2.2 8.8 13.2 10.1 12.8 1.1 2.6-.3 3.2-16.4 35.6 0 1.7 1 1.2 2.2 0 33.8-18.2 3.1-.8 3.4 1 12.4 8.7 15.3 9.4 1.5 2.1 .5 2.5-3.1 38.9 .4 1.5 1.3 .9 2.3-.7 25.9-29.2 2.1-1.3 2.8-.4 16.3 4.4 15.7 3.2 3 1.8 1.6 2.8 9.8 37.1 1.5 1.6 1.7-.1 1.1-1.1 14.5-35.6 1.8-2.5 3.4-1.5 15.7-1.1 16.1-2.4 3.2 .5 2.3 1.8 22.4 32 2.2 .9 1.4-.7 .6-1.5 1.4-39 1-2.7 2.4-2.2 14.7-6.8 13.8-7.8 3.4-.7 3 1 32.4 21 2.3 0 1.1-1.1 0-1.6-13.4-36.6-.3-2.5 .7-2.4 12.2-13.9 8.8-12.1 2.8-2 3.1-.3 38.4 5.4 2.1-.9 .5-1.5-.6-1.4-27.5-27.4-1.6-2.7-.2-3.1 4.6-15.8 2.9-15.8 1.3-2.6 2.5-1.9 37.3-12.2 1.6-1.9-.3-1.5-1.1-1-36.8-12.5-2.4-1.4-1.8-3.3-3.1-17.7 0-2.2 .9-2.4 3.1-2.9 10.6-15.3 3.3-1.8 3.4 .3 3.8 3 4.5 6.8 8.9 11.2 12.5 12.5 6.2 4.8 7.3 4.3 6.3 2.4 3.8 .3 4-.3 5.1-2.4 6.5-7 4.8-10.6 3.3-11.9 2-14.1 1.3-3.4 0-66.6-.8-2.6-2-13.6-3.8-14.6-7.5-18.7-4.7-9.4-4-6-7.2-7.1-5-2.1-6.5 0-2.2 .7-6 3.5-12 12-13.1 17.8-11.7 18.2-3.7 1.6-11.8-.1-3.1-1.6-1.8-2.9-.3-8.8-2.8-12.7-1.5-4-7.1-13.3-5.9-7.8-10.7-9.3-8.6-4.7-5.9-2-4.1-.5-6.7-.5-4.1 .5-7 2-7.3 3.8-7.5 7-2.2 3.2-2.5 5.5-2.8 10.5-.5 3.6 .1 17.1-.3 2.2-1.1 1.9-1.7 1.5-3.7 1.5-2.6 .3-27.5-10.5-14.5-4-15.7-3.2-2.6-1.3-1.9-3-9.9-37.5-.9-1.2-1.4-.4-1.3 .4-.8 1-14.7 36.1-1.8 2.1-2.2 1.2-17.8 1.4-15 2.2-3.4-.7-2.4-2.1-22-31.5-2-.9-1.5 .5-.7 1.5-1.4 38.6-.9 3-2.5 2.5-14.7 6.8-13.8 7.8-2.8 .7-3.1-.7-32.9-21.3-2.3 0-1.1 1.1-.1 1.6 13.6 36.9 0 3.1-1.2 2.6-10.8 12-9.5 12.9-2.8 2-3.2 .3-38.4-5.4-1.5 .4-.9 1.4 .6 2.1 27.6 27.6 1.2 1.8 .5 2.2-3 10.6-1.5 2.4-2.4 1.6-5.8 1-4.4 1.8-3.8 3-3 3.8-1.7 4-.7 4.7 .4 4.7 1.5 4.2 .3 .5 30.7 0 1.7 .6 1.4 1.1 1.1 3-1.1 2.9-2.7 1.6-31.1 .1-.6 1.1-1.2 3.6-.4 4.1 .4 4.2 1.2 3.5 2.5 4 3.2 3.1 4.1 2.3 5.6 1.8 2.4 2.1 .9 2.1 5.1 21.2-.6 2.1-1.2 1.9-28.5 26.5zM283.6 189.4l6.6 .5 5.6 1.2 6.2 2.2 5.9 3.1 4.6 3.4 4.8 4.5 3.5 4.4 3.4 5.8 2.6 6.2 1.6 6.4 .6 5.6-.2 6.7-1.1 6.5-1.7 5.4-2.9 6-3.6 5.5-7.1 7.3-8.4 5.4-9.4 3.5-9.9 1.3-11-1-40.4-10.4-2.8-1.1-3.1-2.4-1.7-.6-.9-1.1-.1-2.2-1.4-2.2 1.6-6.3 18.1-38.5 4.7-7.5 7.1-7.3 8.4-5.4 9.4-3.5zM173.9 198l-1.1 5.9-2.3 5.5-3.4 5-4.2 4.3-5 3.3-5.5 2.3-5.9 1.2-6 0-5.9-1.2-5.6-2.3-5-3.3-4.2-4.3-3.3-5-2.3-5.5-1.2-5.9 0-6 1.2-5.9 2.3-5.5 3.3-5 4.2-4.3 5-3.3 5.6-2.3 5.9-1.2 6 0 5.9 1.2 5.5 2.3 5 3.3 4.2 4.3 3.4 5 2.3 5.5 1.1 5.9zM315.1 213.5l-63.1 37.7 69.5-12.9 0-6.2-1-6.5-2.1-6.1zM237.3 260l-2.6 1.5 40.6 10.5 7.4 .9 7.4-.5 5.4-1.4 5.2-2.1 8.5-5.8 3.8-4.1 3.2-4.5 2.6-5 1.6-4.9zM284.5 196.9l-7.4 .5-8.1 2.3-7.3 4.1-6.3 5.5-5.8 8.5-17.4 37.1 3-.6 76.1-45.5-5.8-5-6.5-3.7-7.1-2.3zM141.1 183.6l-1.1-2.9-2-2.3-2.8-1.3-3.1-.1-2.9 1-2.3 2.1-1.3 2.8-.1 3 1 2.9 2.1 2.3 2.7 1.3 3.1 .2 2.9-1.1 2.3-2 1.3-2.8z`},null,-1)],8,ff)):n.value===`apple`?(F(),I(`svg`,{key:1,class:`device-icon apple`,viewBox:`0 0 384 512`,width:e.size,height:e.size,role:`img`,"aria-label":r.value},[R(`title`,null,D(r.value),1),i[1]||=R(`path`,{fill:`currentColor`,d:`M318.7 268.7c-.2-36.7 16.4-64.4 50-84.8-18.8-26.9-47.2-41.7-84.7-44.6-35.5-2.8-74.3 20.7-88.5 20.7-15 0-49.4-19.7-76.4-19.7C63.3 141.2 4 184.8 4 273.5q0 39.3 14.4 81.2c12.8 36.7 59 126.7 107.2 125.2 25.2-.6 43-17.9 75.8-17.9 31.8 0 48.3 17.9 76.4 17.9 48.6-.7 90.4-82.5 102.6-119.3-65.2-30.7-61.7-90-61.7-91.9zm-56.6-164.2c27.3-32.4 24.8-61.9 24-72.5-24.1 1.4-52 16.4-67.9 34.9-17.5 19.8-27.8 44.3-25.6 71.9 26.1 2 49.9-11.4 69.5-34.3z`},null,-1)],8,pf)):n.value===`laptop`?(F(),L(k(jc),{key:2,class:`device-icon`,size:e.size,"aria-label":r.value},null,8,[`size`,`aria-label`])):(F(),L(k(al),{key:3,class:`device-icon`,size:e.size,"aria-label":r.value},null,8,[`size`,`aria-label`]))}}),hf=new Map,gf=new Map,_f=2e3;function vf(){for(;hf.size>_f;){let e=hf.keys().next().value;if(e===void 0)break;hf.delete(e)}}function yf(e,t){return Tu(Hu.devices.value.find(t=>t.id===e)?.info,t)}function bf(e,t){if(!yf(e,t))return{ok:!1,reason:`outside the device's start dirs`};let n=Df(e,t);return n.status&&n.status.repo===!1&&Date.now()-n.at<5e3?{ok:!1,reason:`not a git repository`}:{ok:!0}}function xf(e,t){t&&typeof t.error==`string`?(e.status=null,e.error=t.error):(e.status=t??null,e.error=``),e.at=Date.now()}async function Sf(e,t){let n=t.filter(t=>!Of(Df(e,t),Cf)&&yf(e,t));if(n.length){for(let t=0;t<n.length&&t<500;t+=50){let r=n.slice(t,t+50);try{let t=await W(e).gitStatusBatch(r,{timeoutMs:6e4});for(let n of r){let r=t[n];r!==void 0&&xf(Df(e,n),r)}}catch{}}vf()}}var Cf=6e4,wf=!1;function Tf(){wf||(wf=!0,j(()=>Hu.devices.value,e=>{let t=Date.now();for(let n of e){let e=(n.tree?.git??[]).filter(e=>t-e.at<6e4);if(e.length)for(let r of[...hf.keys()]){let i=r.indexOf(`::`),a=r.slice(0,i),o=r.slice(i+2);if(i<0||!a||a!==n.id||!o)continue;let s=hf.get(r);e.some(e=>o===e.root||o.startsWith(e.root+`/`)||o.startsWith(e.root+`\\`))&&(s.loading||t-s.at<4e3||kf(a,o,{force:!0}))}}}))}var Ef=(e,t)=>`${e}::${t}`;function Df(e,t){let n=Ef(e,t),r=hf.get(n);return r||(r=Gt({at:0,status:null,error:``,loading:!1,refreshing:!1}),hf.set(n,r)),r}var Of=(e,t)=>e.at>0&&Date.now()-e.at<t&&(e.status!==null||e.error);async function kf(e,t,n={}){let{staleMs:r=6e4,force:i=!1,timeoutMs:a=6e4}=n;if(!e||!t)return;let o=Ef(e,t),s=Df(e,t);if(!i&&Of(s,r))return;if(!yf(e,t)){xf(s,{error:`outside the device's start dirs`});return}vf();let c=gf.get(o);if(c)return c;s.status===null&&!s.error?s.loading=!0:s.refreshing=!0,s.error=``;let l=(async()=>{try{s.status=await W(e).gitStatus(t,{timeoutMs:a}),s.at=Date.now()}catch(e){let t=e.message??``;s.error=/fetch failed|Cannot reach|Failed to fetch|NetworkError|abort/i.test(t)?`device unreachable — check that it is online, then retry (${t.slice(0,80)})`:t.slice(0,160),s.at=Date.now()}finally{s.loading=!1,s.refreshing=!1,gf.delete(o)}})();return gf.set(o,l),l}var Af=new Map;function jf(){j(()=>Hu.devices.value.map(e=>`${e.id}:${e.status}:${e.tree?.sessions.length??0}:${e.tree?.sessions.map(e=>e.cwd).join(`|`)}`).join(`;`),()=>{for(let e of Hu.devices.value){if(e.status!==`online`||!e.tree?.sessions.length)continue;let t=Date.now();t-(Af.get(e.id)??0)<6e4||(Af.set(e.id,t),Sf(e.id,e.tree.sessions.map(e=>e.cwd)))}},{immediate:!0})}var Mf=(e,t)=>Df(e,t).status?.branch,Nf=[`aria-level`,`aria-expanded`,`aria-selected`,`data-key`,`title`],Pf=[`aria-label`],Ff={key:1,class:`chev`},If={class:`name`},Lf={class:`badge`},Rf=[`title`],zf=[`aria-label`],Bf=[`disabled`,`aria-label`],Vf=[`aria-label`],Hf=[`checked`,`aria-label`],Uf={class:`name`},Wf={class:`path`},Gf=[`title`],Kf=[`title`],qf={key:3,class:`dot work`,title:`Working`},Jf=[`title`],Yf=[`disabled`,`aria-label`],Xf=[`disabled`,`aria-label`],Zf=[`disabled`,`aria-label`],Qf=[`disabled`,`aria-label`],$f={class:`name`},ep={key:3,class:`meta`},tp={key:4,class:`dot work`,title:`Working`},np=[`title`],rp=[`disabled`,`aria-label`],ip=sf(M({__name:`TreeRow`,props:{node:{},depth:{},open:{type:Boolean},selected:{type:Boolean},focused:{type:Boolean},online:{type:Boolean},checkbox:{type:Boolean},checked:{type:Boolean}},emits:[`toggle`,`activate`,`action`,`check`],setup(e,{emit:t}){let n=e,r=t,i=H(()=>n.node.children.length>0),a=H(()=>n.node.type===`device`?n.node.device:void 0),o=H(()=>n.node.type===`session`?n.node.session:void 0),s=H(()=>n.node.type===`agent`?n.node.agent:void 0),c=H(()=>o.value?o.value.agents.reduce((e,t)=>e+t.background,0):s.value?.background??0),l=H(()=>o.value?.busy||s.value?.busy),u=H(()=>{let e=a.value?.info,t=e?.packageVersion??e?.durableVersion,n=Wu.value;return!!(t&&n&&n!==`unknown`&&t!==n)}),d=H(()=>{let e=a.value?.info;return e?.packageVersion??e?.durableVersion??`?`}),f=H(()=>{let e=a.value;if(!e)return``;let t=e.tree?.sessions.length??0;switch(e.status){case`online`:return`${t} session${t===1?``:`s`}`;case`checking`:return`checking…`;case`unauthorized`:return e.hasToken?`token rejected`:`no token`;case`mismatch`:return`identity changed`;case`incompatible`:return`incompatible`;default:return`offline · ${Pd(e.lastSeenAt)}`}}),p=H(()=>{let e=a.value?.status;return e===`online`?`on`:e===`checking`?`chk`:e===`offline`?`off`:`err`}),m=H(()=>{let e=n.node;return e.type===`session`?Mf(e.deviceId,e.session.cwd):void 0}),h=H(()=>a.value?.name??a.value?.id??o.value?.name??s.value?.name??``),g=H(()=>{if(a.value){let e=a.value;return`${e.name}${e.url?` · ${e.url}`:``}${e.error?`\n${e.error}`:``}`}if(o.value)return`${o.value.name}\n${o.value.cwd}`;let e=s.value;return e.kind===`fork`?`Fork of agent #${e.parentId} at entry #${e.forkedAt}`:e.kind===`subagent`?`Subagent owned by agent #${e.ownerAgentId}`:`Root agent`});return(t,n)=>(F(),I(`div`,{class:E([`tree-row`,[e.node.type,{sel:e.selected,focus:e.focused,stale:e.node.stale}]]),style:ge({"--depth":e.depth}),role:`treeitem`,"aria-level":e.depth+1,"aria-expanded":i.value?e.open:void 0,"aria-selected":e.selected,"data-key":e.node.key,title:g.value,onClick:n[14]||=e=>r(`activate`)},[i.value?(F(),I(`button`,{key:0,class:`chev`,tabindex:`-1`,"aria-label":e.open?`Collapse ${h.value}`:`Expand ${h.value}`,onClick:n[0]||=As(e=>r(`toggle`),[`stop`])},[e.open?(F(),L(k(rc),{key:0,size:16})):(F(),L(k(ic),{key:1,size:16}))],8,Pf)):(F(),I(`span`,Ff)),a.value?(F(),I(P,{key:2},[R(`i`,{class:E([`dot`,p.value])},null,2),z(mf,{device:a.value,size:16},null,8,[`device`]),R(`b`,If,D(h.value),1),R(`span`,Lf,D(a.value.kind),1),u.value?(F(),I(`span`,{key:0,class:`tag update`,title:`device runs ${d.value}; hub runs ${k(Wu)}. Devices self-update: dpi update`},`update`,8,Rf)):V(``,!0),R(`span`,{class:E([`meta`,{err:p.value===`err`}])},D(f.value),3),R(`span`,{class:`acts`,onClick:n[4]||=As(()=>{},[`stop`])},[a.value.pairing?(F(),I(`button`,{key:0,class:`icon-button`,"aria-label":`Manage credentials for ${h.value}`,title:`Manage device credentials, including while offline`,onClick:n[1]||=e=>r(`action`,`credentials`)},[z(k(Ac),{size:16})],8,zf)):V(``,!0),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`New session on ${h.value}`,title:`New session on this device`,onClick:n[2]||=e=>r(`action`,`new-session`)},[z(k(Zc),{size:16})],8,Bf),R(`button`,{class:`icon-button`,"aria-label":`Check ${h.value}`,title:`Check connection now`,onClick:n[3]||=e=>r(`action`,`check`)},[z(k(el),{size:16})],8,Vf)])],64)):o.value?(F(),I(P,{key:3},[e.checkbox?(F(),I(`input`,{key:0,type:`checkbox`,class:`bulk-check`,checked:e.checked,"aria-label":`Select ${h.value}`,tabindex:`-1`,onClick:n[5]||=As(()=>{},[`stop`]),onChange:n[6]||=e=>r(`check`)},null,40,Hf)):V(``,!0),z(k(bc),{class:`ico`,size:16}),R(`b`,Uf,D(h.value),1),R(`span`,Wf,`…/`+D(o.value.cwd.split(`/`).filter(Boolean).at(-1)),1),m.value?(F(),I(`span`,{key:1,class:`branch`,title:`git branch of ${o.value.cwd}`},`⎇ `+D(m.value),9,Gf)):V(``,!0),o.value.model?(F(),I(`span`,{key:2,class:`tag`,title:o.value.provider?`${o.value.provider} / ${o.value.model}`:o.value.model},D(o.value.model),9,Kf)):V(``,!0),l.value?(F(),I(`i`,qf)):V(``,!0),c.value?(F(),I(`span`,{key:4,class:`bg-count`,title:`${c.value} background task(s)`},[n[15]||=R(`i`,{class:`dot bg`},null,-1),B(D(c.value)+` bg`,1)],8,Jf)):V(``,!0),R(`span`,{class:`acts`,onClick:n[11]||=As(()=>{},[`stop`])},[R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`New agent in ${h.value}`,title:`New agent in this session`,onClick:n[7]||=e=>r(`action`,`new-agent`)},[z(k(Zc),{size:16})],8,Yf),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`Rename session ${h.value}`,title:`Rename session`,onClick:n[8]||=e=>r(`action`,`rename`)},[z(k(Jc),{size:16})],8,Xf),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`New worktree session from ${h.value}`,title:`New worktree session: branch this folder's repo and open a session in the sibling checkout`,onClick:n[9]||=e=>r(`action`,`worktree`)},[z(k(dl),{size:16})],8,Zf),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`Archive session ${h.value}`,title:`Archive session`,onClick:n[10]||=e=>r(`action`,`archive`)},[z(k(Ws),{size:16})],8,Qf)])],64)):s.value?(F(),I(P,{key:4},[s.value.kind===`fork`?(F(),L(k(wc),{key:0,class:`ico`,size:16})):s.value.kind===`subagent`?(F(),L(k(lc),{key:1,class:`ico`,size:16})):(F(),L(k(Rc),{key:2,class:`ico root`,size:16})),R(`span`,$f,D(h.value),1),s.value.kind===`fork`&&s.value.forkedAt!==void 0?(F(),I(`span`,ep,`@ #`+D(s.value.forkedAt),1)):V(``,!0),l.value?(F(),I(`i`,tp)):V(``,!0),c.value?(F(),I(`span`,{key:5,class:`bg-count`,title:`${c.value} background task(s)`},[n[16]||=R(`i`,{class:`dot bg`},null,-1),B(D(c.value),1)],8,np)):V(``,!0),R(`span`,{class:`acts`,onClick:n[13]||=As(()=>{},[`stop`])},[R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`Rename agent ${h.value}`,title:`Rename agent`,onClick:n[12]||=e=>r(`action`,`rename`)},[z(k(Jc),{size:16})],8,rp)])],64)):V(``,!0)],14,Nf))}}),[[`__scopeId`,`data-v-ec99cf9d`]]),ap={class:`project-bar`,"aria-label":`Projects`},op={class:`project-head`},sp={class:`project-title`},cp=[`aria-label`,`title`],lp={key:0,class:`project-hint`},up={key:0,class:`chips`},dp=[`title`,`onClick`,`onDblclick`],fp={class:`chip-name`},pp={class:`chip-count`},mp={key:1,class:`project-hint`},hp={key:2,class:`project-actions`},gp=[`onClick`],_p=[`onClick`],vp=[`onClick`],yp=[`onClick`],bp={key:3,class:`message-error`},xp={key:4,class:`project-hint labels-hint`},Sp=sf(M({__name:`ProjectBar`,props:{active:{},activeModifiers:{}},emits:[`update:active`],setup(e,{expose:t}){let n=Oi(e,`active`),r=O([]),i=O(!1),a=O(``),o=O(!1),s=H(()=>Hu.devices.value.filter(e=>e.status===`online`).map(e=>e.id));async function c(){i.value=!0,a.value=``;let e=[],t=[];for(let n of s.value){let r=Hu.devices.value.find(e=>e.id===n),i=await W(n).projects(o.value).catch(e=>{let r=G(e);e.code===`not_found`||/allowlist|not found/i.test(r)||t.push(`${n}: ${r.slice(0,60)}`)});for(let t of i?.projects??[]){let i=(r?.tree?.sessions??[]).filter(e=>e.cwd===t.rootPath||e.cwd.startsWith(`${t.rootPath}/`)).length;e.push({deviceId:n,project:t,sessions:i})}}r.value=e.sort((e,t)=>l(e.project).localeCompare(l(t.project))),t.length&&(a.value=t.join(` · `)),i.value=!1}j([s,o],c,{immediate:!0});let l=e=>e.customName??e.name,u=e=>n.value?.deviceId===e.deviceId&&n.value.rootPath===e.project.rootPath;function d(e){n.value=u(e)?void 0:{deviceId:e.deviceId,rootPath:e.project.rootPath}}function f(e){let t=e.project;q.dialog={kind:`prompt`,title:`Rename ${l(t)}`,label:`Project name`,hint:`Shown in the tree and in usage rollups. Leave empty to use the folder name.`,value:t.customName??``,placeholder:t.name,submit:`Save name`,run:async n=>{let r=await W(e.deviceId).updateProject(t.id,{customName:n});J(`Project renamed to ${r.customName??r.name}.`),await c()}}}function p(e){let t=e.project;q.dialog={kind:`prompt`,title:`Labels for ${l(t)}`,label:`Labels (comma separated)`,hint:`Lowercase, up to 12 labels of 32 characters. Used to filter projects.`,value:t.labels.join(`, `),submit:`Save labels`,run:async n=>{let r=await W(e.deviceId).updateProject(t.id,{labels:n.split(`,`).map(e=>e.trim()).filter(Boolean)});J(r.labels.length?`Labels: ${r.labels.join(`, `)}.`:`Labels cleared on ${l(r)}.`),await c()}}}function m(e){let t=e.project,n=Hu.devices.value.find(t=>t.id===e.deviceId)?.info?.models??[];q.dialog={kind:`prompt`,title:`Default model for ${l(t)}`,label:`Model (provider/modelId)`,hint:n.length?`New sessions in this project start on this model instead of the device default. Leave empty to use the device default. E.g. ${n[0].provider}/${n[0].id}`:`New sessions in this project start on this model. Leave empty to use the device default.`,value:t.model?`${t.model.provider}/${t.model.modelId}`:``,placeholder:`device default`,submit:`Save default model`,run:async r=>{if(!r.trim()){await W(e.deviceId).updateProject(t.id,{model:``}),J(`Default model cleared on ${l(t)}.`),await c();return}let[i,...a]=r.trim().split(`/`),o=a.join(`/`),s=n.some(e=>e.provider===i&&e.id===o);if(!i||!o)throw Error(`Format: provider/modelId`);if(!s)throw Error(`${r.trim()} is not in this device's catalog`);await W(e.deviceId).updateProject(t.id,{model:{provider:i,modelId:o}}),J(`New sessions in ${l(t)} start on ${o}.`),await c()}}}function h(e){let t=e.project,r=t.archivedAt!==null;q.dialog={kind:`prompt`,title:`${r?`Restore`:`Archive`} ${l(t)}?`,hint:r?`The project returns to the tree. Its sessions were never touched.`:`Bookkeeping only: the project leaves the list, its sessions keep running. Nothing is deleted.`,submit:r?`Restore project`:`Archive project`,danger:!r,run:async()=>{let i=W(e.deviceId);r?await i.unarchiveProject(t.id):await g(i,t.id),!r&&u(e)&&(n.value=void 0),await c()}}}let g=(e,t)=>e.archiveProject(t);return t({reload:c}),(e,t)=>(F(),I(`div`,ap,[R(`div`,op,[R(`span`,sp,[z(k(yc),{size:13}),t[2]||=B(`PROJECTS`,-1)]),R(`button`,{class:E([`icon-button tiny`,{on:o.value}]),"aria-label":o.value?`Hide archived projects`:`Show archived projects`,title:o.value?`Hide archived projects`:`Show archived projects`,onClick:t[0]||=e=>o.value=!o.value},[z(k(Ws),{size:12})],10,cp),i.value?(F(),I(`span`,lp,`…`)):V(``,!0)]),r.value.length?(F(),I(`div`,up,[(F(!0),I(P,null,N(r.value,e=>(F(),I(`button`,{key:`${e.deviceId}-${e.project.id}`,class:E([`chip`,{on:u(e),archived:e.project.archivedAt}]),title:`${e.project.rootPath} — ${e.sessions} session${e.sessions===1?``:`s`}`,onClick:t=>d(e),onDblclick:t=>f(e)},[e.project.kind===`plain`?(F(),L(k(xc),{key:0,size:11})):(F(),L(k(yc),{key:1,size:11})),R(`span`,fp,D(l(e.project)),1),R(`em`,pp,D(e.sessions),1),(F(!0),I(P,null,N(e.project.labels.slice(0,2),e=>(F(),I(`span`,{key:e,class:`chip-label`},D(e),1))),128))],42,dp))),128))])):i.value?V(``,!0):(F(),I(`p`,mp,` No projects yet — a project appears when a session starts in a folder. `)),n.value?(F(),I(`div`,hp,[t[5]||=R(`span`,{class:`project-hint`},`filtering`,-1),(F(!0),I(P,null,N(r.value.filter(u),e=>(F(),I(P,{key:e.project.id},[R(`button`,{class:`small`,onClick:t=>f(e)},[z(k(Jc),{size:12}),t[3]||=B(`name`,-1)],8,gp),R(`button`,{class:`small`,onClick:t=>p(e)},[z(k(pl),{size:12}),t[4]||=B(`labels`,-1)],8,_p),R(`button`,{class:`small`,onClick:t=>m(e),title:`Default model for new sessions in this project`},[z(k(fc),{size:12}),B(D(e.project.model?`model ✓`:`model`),1)],8,vp),R(`button`,{class:`small`,onClick:t=>h(e)},[e.project.archivedAt?(F(),L(k(Us),{key:0,size:12})):(F(),L(k(Ws),{key:1,size:12})),B(` `+D(e.project.archivedAt?`restore`:`archive`),1)],8,yp),R(`button`,{class:`icon-button tiny`,"aria-label":`Clear project filter`,onClick:t[1]||=e=>n.value=void 0},[z(k(Sl),{size:12})])],64))),128))])):V(``,!0),a.value?(F(),I(`p`,bp,D(a.value),1)):V(``,!0),r.value.some(e=>e.project.labels.length)?(F(),I(`p`,xp,[z(k(pl),{size:11}),B(`labels: `+D([...new Set(r.value.flatMap(e=>e.project.labels))].join(` · `)),1)])):V(``,!0)]))}}),[[`__scopeId`,`data-v-77864963`]]);function Cp(e,t){return`${e.slice(0,e.lastIndexOf(`/`))}/${e.slice(e.lastIndexOf(`/`)+1)}-${t.replace(/[/\\]+/g,`-`)}`}async function wp(e,t,n,r){let i=Cp(n,r);return{target:i,text:(await e.gitOp(t,`worktree-add`,{branch:r,target:i})).text.split(`
|
|
15
|
+
`),id:n}:void 0}var vu=encodeURIComponent,yu=()=>globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random().toString(36).slice(2)}`,bu=e=>e.normalize(`NFKD`).replace(/[^\w.-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,60).toLowerCase()||`session`,xu=class{token;hooks;baseUrl;constructor(e,t,n={}){this.token=t,this.hooks=n,this.baseUrl=e.replace(/\/+$/,``)}headers(e,t={}){return{...this.token?{authorization:`Bearer ${this.token}`,"x-dpi-token":this.token}:{},...e?{"content-type":`application/json`}:{},...t}}async request(e,t,n,r={}){let i=AbortSignal.timeout(r.timeoutMs??2e4),a=r.signal?AbortSignal.any([r.signal,i]):i,o;try{o=await fetch(this.baseUrl+t,{method:e,signal:a,headers:this.headers(n!==void 0,r.idempotencyKey?{"idempotency-key":r.idempotencyKey}:{}),body:n===void 0?void 0:JSON.stringify(n)})}catch(e){throw r.signal?.aborted?e:new Cl(`offline`,`Cannot reach ${this.baseUrl}`,0,{cause:e})}let s=await o.text(),c;try{c=s?JSON.parse(s):void 0}catch{c=void 0}if(!o.ok){let e=c?.error;throw new Cl(e?.code??(o.status===401?`unauthorized`:o.status===404?`not_found`:`internal`),e?.message??`${o.status} ${o.statusText}`,o.status)}return o.headers.get(`idempotent-replay`)===`true`&&this.hooks.onIdempotentReplay?.(t),c}async*stream(e,t,n){let r;try{r=await fetch(this.baseUrl+e,{headers:{...this.headers(!1),accept:`text/event-stream`},signal:t})}catch(e){if(t.aborted)return;throw new Cl(`offline`,`Cannot reach ${this.baseUrl}`,0,{cause:e})}if(!r.ok||!r.body){let e=await r.json().catch(()=>void 0);throw new Cl(e?.error?.code??(r.status===401?`unauthorized`:`unavailable`),e?.error?.message??`Stream failed (${r.status})`,r.status)}try{for await(let e of gu(r.body,n))yield JSON.parse(e.data)}catch(e){if(t.aborted)return;throw e}}device(e){return this.request(`GET`,`/v1/device`,void 0,e)}vitals(){return this.request(`GET`,`/v1/device/vitals`)}tree(){return this.request(`GET`,`/v1/tree`)}projects(e=!1){return this.request(`GET`,`/v1/projects${e?`?includeArchived=1`:``}`)}updateProject(e,t){return this.request(`PATCH`,`/v1/projects/${vu(e)}`,t)}archiveProject(e){return this.request(`POST`,`/v1/projects/${vu(e)}/archive`,{})}unarchiveProject(e){return this.request(`POST`,`/v1/projects/${vu(e)}/unarchive`,{})}notifySinks(){return this.request(`GET`,`/v1/notify/sinks`)}createNotifySink(e){return this.request(`POST`,`/v1/notify/sinks`,e)}updateNotifySink(e,t){return this.request(`PATCH`,`/v1/notify/sinks/${vu(e)}`,t)}removeNotifySink(e){return this.request(`DELETE`,`/v1/notify/sinks/${vu(e)}`)}testNotifySinks(){return this.request(`POST`,`/v1/notify/test`,{})}envView(){return this.request(`GET`,`/v1/device/env`)}setEnvVar(e,t){return this.request(`POST`,`/v1/device/env`,{key:e,value:t})}removeEnvVar(e){return this.request(`DELETE`,`/v1/device/env/${vu(e)}`)}piAuth(){return this.request(`GET`,`/v1/device/pi-auth`)}setPiApiKey(e,t){return this.request(`PUT`,`/v1/device/pi-auth/${vu(e)}`,{key:t})}removePiApiKey(e){return this.request(`DELETE`,`/v1/device/pi-auth/${vu(e)}`)}graphs(){return this.request(`GET`,`/v1/graphs`)}graph(e){return this.request(`GET`,`/v1/graphs/${vu(e)}`)}createGraph(e){return this.request(`POST`,`/v1/graphs`,e)}runGraph(e){return this.request(`POST`,`/v1/graphs/${vu(e)}/run`,{})}removeGraph(e){return this.request(`DELETE`,`/v1/graphs/${vu(e)}`)}schedules(){return this.request(`GET`,`/v1/schedules`)}createSchedule(e){return this.request(`POST`,`/v1/schedules`,e)}updateSchedule(e,t){return this.request(`PATCH`,`/v1/schedules/${vu(e)}`,t)}removeSchedule(e){return this.request(`DELETE`,`/v1/schedules/${vu(e)}`)}runSchedule(e){return this.request(`POST`,`/v1/schedules/${vu(e)}/run`,{})}deviceUsage(){return this.request(`GET`,`/v1/device/usage`)}searchSessions(e,t){return this.request(`GET`,`/v1/sessions/search?q=${vu(e)}${t===`all`?`&scope=all`:``}`)}dirs(e=``){return this.request(`GET`,`/v1/fs/dirs?path=${vu(e)}`)}deviceDoc(e){return this.request(`GET`,`/v1/docs/${vu(e)}`)}deviceEvents(e,t=[]){return this.stream(`/v1/events${t.length?`?docs=${t.map(vu).join(`,`)}`:``}`,e)}gitStatus(e,t={}){return this.request(`GET`,`/v1/git/status?path=${vu(e)}`,void 0,t)}gitOp(e,t,n={}){return this.request(`POST`,`/v1/git`,{path:e,op:t,...n})}async exportSession(e,t={}){let n=AbortSignal.timeout(t.timeoutMs??6e4),r=t.signal?AbortSignal.any([t.signal,n]):n,i;try{i=await fetch(this.baseUrl+`/v1/sessions/${vu(e)}/export`,{headers:this.headers(!1),signal:r})}catch(e){throw t.signal?.aborted?e:new Cl(`offline`,`Cannot reach ${this.baseUrl}`,0,{cause:e})}if(!i.ok){let e=await i.text().catch(()=>``),t;try{t=e?JSON.parse(e):void 0}catch{t=void 0}throw new Cl(t?.error?.code??(i.status===401?`unauthorized`:i.status===404?`not_found`:`internal`),t?.error?.message??`${i.status} ${i.statusText}`,i.status)}let a=new Uint8Array(await i.arrayBuffer()),o=i.headers.get(`content-disposition`)??``,s=/filename="((?:[^"\\]|\\.)*)"/i.exec(o)?.[1],c=/filename=([^;\s]+)/i.exec(o)?.[1];return{filename:(s===void 0?c:s.replace(/\\(.)/g,`$1`))||`${bu(e)}.bundle.zip`,mime:i.headers.get(`content-type`)??`application/zip`,bytes:a}}sessionGitFiles(e){return this.request(`GET`,`/v1/sessions/${vu(e)}/git-files`)}sessionGitTurns(e){return this.request(`GET`,`/v1/sessions/${vu(e)}/git-turns`)}gitStatusBatch(e,t={}){return this.request(`POST`,`/v1/git/status-batch`,{paths:e},t)}sessions(){return this.request(`GET`,`/v1/sessions`)}archived(){return this.request(`GET`,`/v1/archive`)}archivedTranscript(e,t=`markdown`){return this.request(`GET`,`/v1/archive/${vu(e)}/transcript?format=${t}`)}restoreArchived(e){return this.request(`POST`,`/v1/archive/${vu(e)}/restore`,{})}createSession(e,t=yu()){return this.request(`POST`,`/v1/sessions`,e,{idempotencyKey:t})}session(e){return new Su(this,e)}agent(e,t){return new Cu(this,e,String(t))}},Su=class{client;ref;constructor(e,t){this.client=e,this.ref=t}get base(){return`/v1/sessions/${vu(this.ref)}`}get(){return this.client.request(`GET`,this.base)}rename(e){return this.client.request(`PATCH`,this.base,{name:e})}archive(){return this.client.request(`DELETE`,this.base)}agents(){return this.client.request(`GET`,`${this.base}/agents`)}createAgent(e={},t=yu()){return this.client.request(`POST`,`${this.base}/agents`,e,{idempotencyKey:t})}tasks(e=`terminal`,t=20){return this.client.request(`GET`,`${this.base}/tasks?status=${e}&limit=${t}`)}abortTask(e){return this.client.request(`POST`,`${this.base}/tasks/${e}/abort`,{})}inspect(){return this.client.request(`GET`,`${this.base}/inspect`)}compaction(){return this.client.request(`GET`,`${this.base}/compaction`)}setCompaction(e){return this.client.request(`PATCH`,`${this.base}/compaction`,e)}submission(e,t=0){return this.client.request(`GET`,`${this.base}/submissions/${e}?waitMs=${t}`,void 0,{timeoutMs:t+2e4})}events(e){return this.client.stream(`${this.base}/events`,e)}},Cu=class{client;session;agent;constructor(e,t,n){this.client=e,this.session=t,this.agent=n}get base(){return`/v1/sessions/${vu(this.session)}/agents/${vu(this.agent)}`}get(){return this.client.request(`GET`,this.base)}rename(e){return this.client.request(`PATCH`,this.base,{name:e})}send(e,t=`followUp`,n=yu(),r){return this.client.request(`POST`,`${this.base}/messages`,{content:e,whenBusy:t,requestId:n,waitMs:r},{timeoutMs:(r??0)+2e4})}withdraw(e){return this.client.request(`DELETE`,`${this.base}/inbox/${e}`)}abort(e=!1){return this.client.request(`POST`,`${this.base}/abort`,{background:e})}fork(e,t=yu()){return this.client.request(`POST`,`${this.base}/fork`,e,{idempotencyKey:t})}config(){return this.client.request(`GET`,`${this.base}/config`)}configure(e){return this.client.request(`PATCH`,`${this.base}/config`,e)}compact(e){return this.client.request(`POST`,`${this.base}/compact`,{instructions:e})}reset(e){return this.client.request(`POST`,`${this.base}/reset`,{note:e})}entries(e={}){let t=new URLSearchParams({scope:e.scope??`all`,limit:String(e.limit??500),...e.cursor?{cursor:e.cursor}:{}});return this.client.request(`GET`,`${this.base}/entries?${t}`)}transcript(e=`json`){return this.client.request(`GET`,`${this.base}/transcript?format=${e}`)}doc(e){return this.client.request(`GET`,`${this.base}/docs/${vu(e)}`)}extensions(){return this.client.request(`GET`,`${this.base}/extensions`)}setExtension(e){return this.client.request(`PATCH`,`${this.base}/extensions`,e)}demo(e,t,n=`POST`){return this.client.request(n,`${this.base}/demo/${e}`,t)}events(e,t=[]){return this.client.stream(`${this.base}/events${t.length?`?docs=${t.map(vu).join(`,`)}`:``}`,e)}};function wu(e,t){let n=String(e??``).trim();return t?n.replace(/\//g,`\\`).replace(/\\+$/,``).toLowerCase():n.replace(/\/+$/,``)}function Tu(e,t){let n=Array.isArray(e?.gitDirs)&&e.gitDirs.length?e.gitDirs:e?.startDirs;if(!Array.isArray(n)||n.length===0)return!0;let r=String(e?.platform??``).startsWith(`win32`),i=wu(t,r);return n.some(e=>{let t=wu(String(e),r);return!!t&&(i===t||i.startsWith(r?`${t}\\`:`${t}/`))})}function Eu(e){let t=Array.isArray(e?.gitDirs)&&e.gitDirs.length?e.gitDirs:e?.startDirs,n=Array.isArray(t)?t.map(String):[];return n.length?`outside the device's start dirs (it serves: ${n.join(`, `)})`:`outside the device's start dirs`}var Du=0,Ou=e=>new xu(`/api/devices/${encodeURIComponent(e)}`,void 0,{onIdempotentReplay:e=>{Date.now()-Du<3e4||(Du=Date.now(),J(`Replayed an earlier identical request (${e}) — send a custom idempotency key for deliberate repeats.`))}}),W=e=>{let t=Ou(e),n=()=>Hu.devices.value.find(t=>t.id===e)?.info,r=t.gitOp.bind(t);return t.gitOp=((e,t,i)=>{let a=n();return a&&e&&!Tu(a,e)?Promise.reject(new Cl(`invalid`,`git ${t} skipped: ${Eu(a)}`,400)):r(e,t,i)}),t};async function ku(e,t,n){let r=await fetch(`/api${t}`,{method:e,headers:n===void 0?{}:{"content-type":`application/json`},body:n===void 0?void 0:JSON.stringify(n)}),i=await r.json().catch(()=>void 0);if(!r.ok){let e=i?.error;throw new Cl(e?.code??`internal`,e?.message??`${r.status} ${r.statusText}`,r.status)}return i}var Au={network:()=>ku(`GET`,`/network`),version:()=>ku(`GET`,`/version`),check:e=>ku(`POST`,`/devices/${encodeURIComponent(e)}/check`,{}),createShare:e=>ku(`POST`,`/shares`,e),async uiGet(e){return(await ku(`GET`,`/ui-state/${encodeURIComponent(e)}`)).value??void 0},uiSet:(e,t)=>ku(`PUT`,`/ui-state/${encodeURIComponent(e)}`,{value:t})},G=e=>e instanceof Error?e.message:String(e),ju=[`demo.job-runs`,`demo.workspace`],Mu=e=>`${e.deviceId}/agent/${e.sessionId}/${e.agentId}?docs=${ju.join(`,`)}`,Nu=e=>`${e.deviceId}/session/${e.sessionId}`,Pu=e=>`${e}/device?docs=app.shared-state`;function Fu(e,t,n,r=`hello`){let i=O(`idle`),a=O(``);return e.route(t,e=>{e.type===`hello`?(i.value=r===`hello`?`live`:`connecting`,r===`hello`&&(a.value=``)):e.type===`disconnected`?i.value=`reconnecting`:e.type===`fault`?(i.value=`fault`,a.value=e.error.message):(n(e),e.type===r&&(a.value=``,i.value=`live`))}),{status:i,fault:a,select:n=>{a.value=``,i.value=n?`connecting`:`idle`,e.set(t,n)},retry:()=>{i.value=`connecting`,e.reopen(t)}}}function Iu(e){let t=new nu,n=O(0);return t.subscribe(()=>n.value++),e.onNetwork(e=>t.apply({type:`network`,devices:e})),{model:t,devices:H(()=>(n.value,t.devices)),tree:H(()=>(n.value,t.tree()))}}function Lu(e,t){let n=an(),r=an([]),{status:i,select:a}=Fu(e,`device`,e=>{e.type===`doc`&&e.kind===`app.shared-state`?n.value={value:e.value,revision:e.revision??0}:e.type===`activity`&&(r.value=[...r.value,...e.items].slice(-50))});return j(t,e=>{n.value=void 0,a(e?Pu(e):void 0)},{immediate:!0}),{sharedState:n,activity:r,status:i}}function Ru(e,t){let n=new Yl,r=O(0);n.subscribe(()=>r.value++);let{status:i,fault:a,select:o}=Fu(e,`session`,e=>n.apply(e));return j(()=>t.value?Nu(t.value):void 0,e=>{n.clear(),o(e)},{immediate:!0}),{model:n,state:H(()=>(r.value,n.state)),status:i,fault:a}}function zu(e,t){let n=new Jl,r=O(0);n.subscribe(()=>r.value++);let{status:i,fault:a,select:o,retry:s}=Fu(e,`agent`,e=>n.apply(e),`snapshot`);return j(()=>t.value?Mu(t.value):void 0,e=>{n.clear(),o(e)},{immediate:!0}),{model:n,state:H(()=>(r.value,{...n.state})),status:i,fault:a,version:r,retry:s}}var Bu=new cu,Vu=O(Bu.state);Bu.onState(e=>Vu.value=e);var Hu=Iu(Bu),Uu=O(),Wu=O(),K=O(),Gu=O(new Set),Ku=O(300),qu=Gt({tree:!0,inspector:!0}),Ju=O(!1),Yu=H(()=>K.value?.deviceId),Xu=H(()=>Hu.devices.value.find(e=>e.id===Yu.value)),Zu=H(()=>Xu.value?.status===`online`),Qu=Ru(Bu,H(()=>K.value?{deviceId:K.value.deviceId,sessionId:K.value.sessionId}:void 0)),$u=zu(Bu,K),ed=Lu(Bu,Yu),td=H(()=>Xu.value?.tree?.sessions.find(e=>e.id===K.value?.sessionId)),nd=H(()=>Yu.value?W(Yu.value):void 0),rd=H(()=>K.value&&nd.value?nd.value.agent(K.value.sessionId,K.value.agentId):void 0),id=H(()=>K.value&&nd.value?nd.value.session(K.value.sessionId):void 0);function ad(e){K.value=e,q.drawer=!1,od=!!e,sd()}var od=!1;function sd(){let e=K.value;if(!od||!e)return;let t=Hu.devices.value.find(t=>t.id===e.deviceId)?.tree?.sessions.find(t=>t.id===e.sessionId)?.agents,n=new Map((t??[]).map(e=>[e.id,e])),r=[e.deviceId,`${e.deviceId}/s/${e.sessionId}`,`${e.deviceId}/s/${e.sessionId}/a/${e.agentId}`],i=n.get(e.agentId),a=new Set;for(;i&&!a.has(i.id);){a.add(i.id);let t=i.parentId??i.ownerAgentId;if(t===void 0)break;r.push(`${e.deviceId}/s/${e.sessionId}/a/${t}`),i=n.get(t)}r.some(e=>!Gu.value.has(e))&&(Gu.value=new Set([...Gu.value,...r])),n.has(e.agentId)&&(od=!1)}j(()=>Hu.devices.value,sd);function cd(e,t){let n=new Set(Gu.value);t??!n.has(e)?n.add(e):n.delete(e),Gu.value=n}var ld=(()=>{let e=new Map;return(t,n)=>{clearTimeout(e.get(t)),e.set(t,setTimeout(()=>void Au.uiSet(t,n).catch(()=>{}),300))}})();j(K,e=>Ju.value&&void Au.uiSet(`tree.selected`,e??null).catch(()=>{})),j(Ku,e=>Ju.value&&ld(`tree.width`,e)),j(qu,e=>Ju.value&&ld(`layout.panels`,{...e}));async function ud(){let e;try{e=await Au.network()}catch(e){e instanceof Cl&&e.status===401||Bu.start(),q.error=G(e),Ju.value=!0;return}Bu.start();try{let[t,n,r]=await Promise.all([Au.uiGet(`tree.selected`),Au.uiGet(`tree.width`),Au.uiGet(`layout.panels`)]);r&&Object.assign(qu,r),Au.version().then(e=>Wu.value=e.version).catch(()=>{}),Uu.value=e.configFile,Hu.model.devices.length||Hu.model.apply({type:`network`,devices:e.devices}),Gu.value=new Set,n&&(Ku.value=n),t&&e.devices.some(e=>e.id===t.deviceId)?ad(t):dd(e.devices)}catch(e){q.error=G(e)}finally{Ju.value=!0}}function dd(e){for(let t of e){let e=t.status===`online`?t.tree?.sessions[0]:void 0,n=e?.agents.find(e=>e.kind===`root`)??e?.agents[0];if(e&&n)return ad({deviceId:t.id,sessionId:e.id,agentId:n.id})}}j(()=>[$u.status.value,td.value],([e,t])=>{e===`fault`&&!t&&Zu.value&&(J(`That session was archived on its device.`),ad(void 0))});var fd=H(()=>Xu.value?.info?.models??[]),pd=$u.state,md=H(()=>Qu.state.value.agents.length?Qu.state.value.agents:td.value?.agents??[]),hd=H(()=>K.value?Xl(md.value,K.value.agentId):[]),gd=H(()=>{let e=K.value?.agentId;if(e===void 0)return[];let t=md.value,n=new Set([e]);for(let e=!0;e;){e=!1;for(let r of t)r.ownerAgentId!==void 0&&n.has(r.ownerAgentId)&&!n.has(r.id)&&(n.add(r.id),e=!0)}let r=Qu.state.value.tasks,i=new Map(r.map(e=>[e.id,e])),a=new Map(t.map(e=>[e.id,e.ownerTaskId]));return r.filter(e=>n.has(e.conversationId)).map(e=>{let t=e,n=!1,r=new Set;for(;t&&!r.has(t.id);){if(r.add(t.id),t.background){n=!0;break}let e=t.owner??a.get(t.conversationId);t=e===void 0?void 0:i.get(e)}return{...e,effectiveBackground:n}})}),_d=H(()=>pd.value.running||gd.value.some(e=>!e.effectiveBackground&&e.conversationId===K.value?.agentId)),vd=H(()=>jl(pd.value.usage)),yd=H(()=>{let e=pd.value.agent.model;return fd.value.find(t=>t.provider===e?.provider&&t.id===e?.modelId)}),bd=H(()=>{let e=pd.value.agent.model;if(e?.modelId)return e;let t=td.value;return t?.model?{provider:t.provider??``,modelId:t.model}:void 0}),xd=H(()=>{let e=bd.value;return e?fd.value.find(t=>t.provider===e.provider&&t.id===e.modelId):void 0}),Sd=an(),Cd=0;async function wd(){let e=rd.value,t=++Cd;if(!e||!Zu.value)return void(Sd.value=void 0);try{let n=await e.get();t===Cd&&(Sd.value=n)}catch{t===Cd&&(Sd.value=void 0)}}j([rd,Zu],()=>void wd(),{immediate:!0});var q=Gt({error:``,toast:``,drawer:!1,inspectorOverlay:!1,tab:`session`,composer:``,dialog:void 0}),Td,Ed=Gt([]),Dd=1;function Od(){for(let e of Ed)e.read=!0}function J(e){q.toast=e,e&&(Ed.unshift({id:Dd++,text:e,at:Date.now(),read:!1}),Ed.length>50&&(Ed.length=50)),clearTimeout(Td),Td=setTimeout(()=>q.toast=``,4500)}async function kd(e){q.error=``;try{return await e()}catch(e){q.error=G(e);return}}function Ad(e){q.composer=e,setTimeout(()=>document.querySelector(`.composer textarea`)?.focus())}var jd=e=>Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1}).format(e),Md=e=>JSON.stringify(e,null,2),Nd=(e=``)=>uu(fd.value.find(t=>t.id===e)?.icon);function Pd(e){if(!e)return`never`;let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`${t}s ago`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}var Fd=O(!1);async function Id(){_d.value&&!Fd.value&&rd.value&&(Fd.value=!0,await kd(()=>rd.value.abort(!1))&&J(`Foreground work interrupted. Background jobs continue.`),Fd.value=!1)}var Ld=window.matchMedia(`(max-width: 1100px)`),Rd=O(Ld.matches);Ld.addEventListener(`change`,e=>Rd.value=e.matches);var zd=H(()=>Rd.value?q.inspectorOverlay:qu.inspector);function Bd(e){e&&(q.tab=e),Rd.value?(q.drawer=!1,q.inspectorOverlay=!0):qu.inspector=!0}function Vd(){Rd.value?q.inspectorOverlay=!1:qu.inspector=!1}function Hd(){Rd.value?(q.drawer=!q.drawer)&&(q.inspectorOverlay=!1,qu.tree=!0):qu.tree=!qu.tree}function Ud(){zd.value?Vd():Bd()}var Wd=/Mac|iPhone|iPad/.test(navigator.userAgent),Gd=Wd?{tree:`Ctrl+N`,inspector:`Ctrl+T`}:{tree:`Alt+Shift+N`,inspector:`Alt+Shift+T`};function Kd(e){if(!(!(Wd?e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey:e.altKey&&e.shiftKey&&!e.ctrlKey&&!e.metaKey)||e.repeat||e.isComposing)){if(e.code===`KeyN`)return`tree`;if(e.code===`KeyT`)return`inspector`}}var qd={class:`topbar`},Jd={class:`brand`},Yd={class:`daemon`,"data-testid":`topbar-stats`},Xd=[`title`],Zd={class:`top-actions`},Qd={key:0,class:`usage-chip`,title:`This session's token usage and cost`},$d=[`aria-label`,`title`],ef={key:0,class:`bell-dot`},tf={key:0,class:`hint`},nf={class:`when`},rf=[`disabled`],af=[`disabled`],of=M({__name:`TopBar`,emits:[`newSession`],setup(e,{emit:t}){let n=O(!1),r=H(()=>Ed.filter(e=>!e.read).length),i=()=>{n.value=!n.value,n.value&&Od()},a=e=>{let t=Math.round((Date.now()-e)/1e3);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`},o=H(()=>vd.value.input+vd.value.output+vd.value.cacheRead+vd.value.cacheWrite),s=H(()=>(vd.value.inputCost??0)+(vd.value.outputCost??0)+(vd.value.cacheReadCost??0)+(vd.value.cacheWriteCost??0)),c=H(()=>Hu.devices.value.filter(e=>e.status===`online`).length),l=H(()=>Hu.devices.value.reduce((e,t)=>e+(t.tree?.sessions.length??0),0)),u=H(()=>Hu.devices.value.reduce((e,t)=>e+(t.tree?.sessions.reduce((e,t)=>e+t.agents.length,0)??0),0)),d=O(!1);async function f(){let e=id.value,t=K.value;if(!e||!t||d.value)return;d.value=!0;let n=await kd(()=>e.createAgent({name:`Agent ${md.value.length+1}`}));d.value=!1,n&&(ad({...t,agentId:n.id}),J(`New agent. Same session, same shared App State.`))}let p=t;return(e,t)=>(F(),I(`header`,qd,[R(`div`,Jd,[R(`button`,{class:`icon-button tree-toggle`,"aria-label":`Toggle network`,title:`Network`,onClick:t[0]||=e=>k(q).drawer=!k(q).drawer},[z(k(Kc),{size:19})]),t[6]||=R(`img`,{class:`brandmark`,src:`/icons/durable-pi.svg`,alt:`Durable Pi`},null,-1),t[7]||=R(`strong`,null,`Durable Pi`,-1)]),t[15]||=R(`span`,{class:`topbar-sep`,"aria-hidden":`true`},null,-1),R(`div`,Yd,[R(`span`,{class:E([`dot`,{off:!c.value}]),"aria-hidden":`true`},null,2),R(`span`,{class:`network-summary`,title:`${c.value} of ${k(Hu).devices.value.length} devices online`},[z(k(Vc),{size:16}),B(D(c.value)+` of `+D(k(Hu).devices.value.length)+` online`,1)],8,Xd),t[10]||=R(`span`,{class:`sep`,"aria-hidden":`true`},`·`,-1),R(`span`,null,[R(`b`,null,D(l.value),1),t[8]||=B(` sessions`,-1)]),t[11]||=R(`span`,{class:`sep`,"aria-hidden":`true`},`·`,-1),R(`span`,null,[R(`b`,null,D(u.value),1),t[9]||=B(` agents`,-1)])]),R(`div`,Zd,[R(`span`,{class:E([`chip connection`,{accent:k(Vu)===`live`}])},[R(`span`,{class:E([`dot`,{off:k(Vu)!==`live`}]),"aria-hidden":`true`},null,2),B(D(k(Vu)===`live`?`Connected`:`Reconnecting`),1)],2),o.value?(F(),I(`span`,Qd,D(o.value.toLocaleString())+` tok · $`+D(s.value.toFixed(3)),1)):V(``,!0),R(`button`,{class:`icon-button`,"aria-label":`Notifications${r.value?` (${r.value} unread)`:``}`,title:`Notification center${r.value?` — ${r.value} unread`:``}`,onClick:i},[z(k(Zs),{size:18}),r.value?(F(),I(`i`,ef,D(r.value>9?`9+`:r.value),1)):V(``,!0)],8,$d),n.value?(F(),I(`div`,{key:1,class:`notif-panel`,onClick:t[2]||=As(()=>{},[`stop`])},[R(`header`,null,[t[12]||=R(`b`,null,`Notifications`,-1),R(`button`,{class:`icon-button`,"aria-label":`Close notifications`,onClick:t[1]||=e=>n.value=!1},`✕`)]),k(Ed).length?V(``,!0):(F(),I(`p`,tf,`Nothing yet — events land here as they happen.`)),R(`ul`,null,[(F(!0),I(P,null,N(k(Ed),e=>(F(),I(`li`,{key:e.id,class:E({unread:!e.read})},[R(`span`,nf,D(a(e.at)),1),R(`span`,null,D(e.text),1)],2))),128))])])):V(``,!0),R(`button`,{class:`icon-button`,title:`How this works`,"aria-label":`How this works`,onClick:t[3]||=e=>k(q).dialog={kind:`help`}},[z(k(oc),{size:19})]),R(`button`,{class:`secondary small new-agent-button`,disabled:!k(K)||!k(Zu)||d.value,title:`Start a fresh agent in this session`,onClick:f},[z(k(Zc),{size:18}),t[13]||=B(`New agent `,-1)],8,rf),R(`button`,{class:`primary small`,onClick:t[4]||=e=>p(`newSession`)},[z(k(Zc),{size:18}),t[14]||=B(`New session `,-1)]),R(`button`,{class:`icon-button inspector-toggle`,"aria-label":`Toggle inspector`,title:`Inspector`,disabled:!k(K)||!k(Zu),onClick:t[5]||=e=>k(q).inspectorOverlay?k(Vd)():k(Bd)()},[z(k(qc),{size:19})],8,af)])]))}}),sf=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},cf=sf(of,[[`__scopeId`,`data-v-de526f26`]]),lf={class:`mnav`,"aria-label":`Panels`},uf={key:0,class:`badge`},df=M({__name:`MobileNav`,setup(e){function t(){q.drawer=!1,q.inspectorOverlay=!1}return(e,n)=>(F(),I(`nav`,lf,[R(`button`,{type:`button`,class:E({"is-on":!k(q).drawer&&!k(zd)}),onClick:t},[z(k(Rc),{size:18}),n[2]||=B(`Chat `,-1)],2),R(`button`,{type:`button`,class:E({"is-on":k(zd)}),onClick:n[0]||=e=>k(zd)?k(Vd)():k(Bd)()},[z(k(qc),{size:18}),n[3]||=B(`Details`,-1),k(gd).length?(F(),I(`span`,uf,D(k(gd).length),1)):V(``,!0)],2),R(`button`,{type:`button`,class:E({"is-on":k(q).drawer}),onClick:n[1]||=e=>k(Hd)()},[z(k(_l),{size:18}),n[4]||=B(`Network `,-1)],2)]))}}),ff=[`width`,`height`,`aria-label`],pf=[`width`,`height`,`aria-label`],mf=M({__name:`DeviceIcon`,props:{device:{},size:{default:16}},setup(e){let t=e,n=H(()=>{let e=t.device;return e?.kind===`exe-dev`||e?.url?.includes(`.exe.xyz`)?`exe`:e?.info?.platform.startsWith(`darwin`)?`apple`:e?.kind===`local`?`laptop`:`server`}),r=H(()=>{let e={exe:`exe.dev VM`,apple:`macOS`,laptop:`This computer`,server:`Server`}[n.value];return t.device?.transport===`tunnel`?`${e} (tunnel)`:e});return(t,i)=>n.value===`exe`?(F(),I(`svg`,{key:0,class:`device-icon exe`,viewBox:`0 0 512 512`,width:e.size,height:e.size,role:`img`,"aria-label":r.value},[R(`title`,null,D(r.value),1),i[0]||=R(`path`,{fill:`currentColor`,"fill-rule":`evenodd`,d:`M8 332.2l.9 1.4 1.5 .5 38.5-4.1 3.1 .4 2.7 2.2 8.8 13.2 10.1 12.8 1.1 2.6-.3 3.2-16.4 35.6 0 1.7 1 1.2 2.2 0 33.8-18.2 3.1-.8 3.4 1 12.4 8.7 15.3 9.4 1.5 2.1 .5 2.5-3.1 38.9 .4 1.5 1.3 .9 2.3-.7 25.9-29.2 2.1-1.3 2.8-.4 16.3 4.4 15.7 3.2 3 1.8 1.6 2.8 9.8 37.1 1.5 1.6 1.7-.1 1.1-1.1 14.5-35.6 1.8-2.5 3.4-1.5 15.7-1.1 16.1-2.4 3.2 .5 2.3 1.8 22.4 32 2.2 .9 1.4-.7 .6-1.5 1.4-39 1-2.7 2.4-2.2 14.7-6.8 13.8-7.8 3.4-.7 3 1 32.4 21 2.3 0 1.1-1.1 0-1.6-13.4-36.6-.3-2.5 .7-2.4 12.2-13.9 8.8-12.1 2.8-2 3.1-.3 38.4 5.4 2.1-.9 .5-1.5-.6-1.4-27.5-27.4-1.6-2.7-.2-3.1 4.6-15.8 2.9-15.8 1.3-2.6 2.5-1.9 37.3-12.2 1.6-1.9-.3-1.5-1.1-1-36.8-12.5-2.4-1.4-1.8-3.3-3.1-17.7 0-2.2 .9-2.4 3.1-2.9 10.6-15.3 3.3-1.8 3.4 .3 3.8 3 4.5 6.8 8.9 11.2 12.5 12.5 6.2 4.8 7.3 4.3 6.3 2.4 3.8 .3 4-.3 5.1-2.4 6.5-7 4.8-10.6 3.3-11.9 2-14.1 1.3-3.4 0-66.6-.8-2.6-2-13.6-3.8-14.6-7.5-18.7-4.7-9.4-4-6-7.2-7.1-5-2.1-6.5 0-2.2 .7-6 3.5-12 12-13.1 17.8-11.7 18.2-3.7 1.6-11.8-.1-3.1-1.6-1.8-2.9-.3-8.8-2.8-12.7-1.5-4-7.1-13.3-5.9-7.8-10.7-9.3-8.6-4.7-5.9-2-4.1-.5-6.7-.5-4.1 .5-7 2-7.3 3.8-7.5 7-2.2 3.2-2.5 5.5-2.8 10.5-.5 3.6 .1 17.1-.3 2.2-1.1 1.9-1.7 1.5-3.7 1.5-2.6 .3-27.5-10.5-14.5-4-15.7-3.2-2.6-1.3-1.9-3-9.9-37.5-.9-1.2-1.4-.4-1.3 .4-.8 1-14.7 36.1-1.8 2.1-2.2 1.2-17.8 1.4-15 2.2-3.4-.7-2.4-2.1-22-31.5-2-.9-1.5 .5-.7 1.5-1.4 38.6-.9 3-2.5 2.5-14.7 6.8-13.8 7.8-2.8 .7-3.1-.7-32.9-21.3-2.3 0-1.1 1.1-.1 1.6 13.6 36.9 0 3.1-1.2 2.6-10.8 12-9.5 12.9-2.8 2-3.2 .3-38.4-5.4-1.5 .4-.9 1.4 .6 2.1 27.6 27.6 1.2 1.8 .5 2.2-3 10.6-1.5 2.4-2.4 1.6-5.8 1-4.4 1.8-3.8 3-3 3.8-1.7 4-.7 4.7 .4 4.7 1.5 4.2 .3 .5 30.7 0 1.7 .6 1.4 1.1 1.1 3-1.1 2.9-2.7 1.6-31.1 .1-.6 1.1-1.2 3.6-.4 4.1 .4 4.2 1.2 3.5 2.5 4 3.2 3.1 4.1 2.3 5.6 1.8 2.4 2.1 .9 2.1 5.1 21.2-.6 2.1-1.2 1.9-28.5 26.5zM283.6 189.4l6.6 .5 5.6 1.2 6.2 2.2 5.9 3.1 4.6 3.4 4.8 4.5 3.5 4.4 3.4 5.8 2.6 6.2 1.6 6.4 .6 5.6-.2 6.7-1.1 6.5-1.7 5.4-2.9 6-3.6 5.5-7.1 7.3-8.4 5.4-9.4 3.5-9.9 1.3-11-1-40.4-10.4-2.8-1.1-3.1-2.4-1.7-.6-.9-1.1-.1-2.2-1.4-2.2 1.6-6.3 18.1-38.5 4.7-7.5 7.1-7.3 8.4-5.4 9.4-3.5zM173.9 198l-1.1 5.9-2.3 5.5-3.4 5-4.2 4.3-5 3.3-5.5 2.3-5.9 1.2-6 0-5.9-1.2-5.6-2.3-5-3.3-4.2-4.3-3.3-5-2.3-5.5-1.2-5.9 0-6 1.2-5.9 2.3-5.5 3.3-5 4.2-4.3 5-3.3 5.6-2.3 5.9-1.2 6 0 5.9 1.2 5.5 2.3 5 3.3 4.2 4.3 3.4 5 2.3 5.5 1.1 5.9zM315.1 213.5l-63.1 37.7 69.5-12.9 0-6.2-1-6.5-2.1-6.1zM237.3 260l-2.6 1.5 40.6 10.5 7.4 .9 7.4-.5 5.4-1.4 5.2-2.1 8.5-5.8 3.8-4.1 3.2-4.5 2.6-5 1.6-4.9zM284.5 196.9l-7.4 .5-8.1 2.3-7.3 4.1-6.3 5.5-5.8 8.5-17.4 37.1 3-.6 76.1-45.5-5.8-5-6.5-3.7-7.1-2.3zM141.1 183.6l-1.1-2.9-2-2.3-2.8-1.3-3.1-.1-2.9 1-2.3 2.1-1.3 2.8-.1 3 1 2.9 2.1 2.3 2.7 1.3 3.1 .2 2.9-1.1 2.3-2 1.3-2.8z`},null,-1)],8,ff)):n.value===`apple`?(F(),I(`svg`,{key:1,class:`device-icon apple`,viewBox:`0 0 384 512`,width:e.size,height:e.size,role:`img`,"aria-label":r.value},[R(`title`,null,D(r.value),1),i[1]||=R(`path`,{fill:`currentColor`,d:`M318.7 268.7c-.2-36.7 16.4-64.4 50-84.8-18.8-26.9-47.2-41.7-84.7-44.6-35.5-2.8-74.3 20.7-88.5 20.7-15 0-49.4-19.7-76.4-19.7C63.3 141.2 4 184.8 4 273.5q0 39.3 14.4 81.2c12.8 36.7 59 126.7 107.2 125.2 25.2-.6 43-17.9 75.8-17.9 31.8 0 48.3 17.9 76.4 17.9 48.6-.7 90.4-82.5 102.6-119.3-65.2-30.7-61.7-90-61.7-91.9zm-56.6-164.2c27.3-32.4 24.8-61.9 24-72.5-24.1 1.4-52 16.4-67.9 34.9-17.5 19.8-27.8 44.3-25.6 71.9 26.1 2 49.9-11.4 69.5-34.3z`},null,-1)],8,pf)):n.value===`laptop`?(F(),L(k(jc),{key:2,class:`device-icon`,size:e.size,"aria-label":r.value},null,8,[`size`,`aria-label`])):(F(),L(k(al),{key:3,class:`device-icon`,size:e.size,"aria-label":r.value},null,8,[`size`,`aria-label`]))}}),hf=new Map,gf=new Map,_f=2e3;function vf(){for(;hf.size>_f;){let e=hf.keys().next().value;if(e===void 0)break;hf.delete(e)}}function yf(e,t){return Tu(Hu.devices.value.find(t=>t.id===e)?.info,t)}function bf(e,t){if(!yf(e,t))return{ok:!1,reason:`outside the device's start dirs`};let n=Df(e,t);return n.status&&n.status.repo===!1&&Date.now()-n.at<5e3?{ok:!1,reason:`not a git repository`}:{ok:!0}}function xf(e,t){t&&typeof t.error==`string`?(e.status=null,e.error=t.error):(e.status=t??null,e.error=``),e.at=Date.now()}async function Sf(e,t){let n=t.filter(t=>!Of(Df(e,t),Cf)&&yf(e,t));if(n.length){for(let t=0;t<n.length&&t<500;t+=50){let r=n.slice(t,t+50);try{let t=await W(e).gitStatusBatch(r,{timeoutMs:6e4});for(let n of r){let r=t[n];r!==void 0&&xf(Df(e,n),r)}}catch{}}vf()}}var Cf=6e4,wf=!1;function Tf(){wf||(wf=!0,j(()=>Hu.devices.value,e=>{let t=Date.now();for(let n of e){let e=(n.tree?.git??[]).filter(e=>t-e.at<6e4);if(e.length)for(let r of[...hf.keys()]){let i=r.indexOf(`::`),a=r.slice(0,i),o=r.slice(i+2);if(i<0||!a||a!==n.id||!o)continue;let s=hf.get(r);e.some(e=>o===e.root||o.startsWith(e.root+`/`)||o.startsWith(e.root+`\\`))&&(s.loading||t-s.at<4e3||kf(a,o,{force:!0}))}}}))}var Ef=(e,t)=>`${e}::${t}`;function Df(e,t){let n=Ef(e,t),r=hf.get(n);return r||(r=Gt({at:0,status:null,error:``,loading:!1,refreshing:!1}),hf.set(n,r)),r}var Of=(e,t)=>e.at>0&&Date.now()-e.at<t&&(e.status!==null||e.error);async function kf(e,t,n={}){let{staleMs:r=6e4,force:i=!1,timeoutMs:a=6e4}=n;if(!e||!t)return;let o=Ef(e,t),s=Df(e,t);if(!i&&Of(s,r))return;if(!yf(e,t)){xf(s,{error:`outside the device's start dirs`});return}vf();let c=gf.get(o);if(c)return c;s.status===null&&!s.error?s.loading=!0:s.refreshing=!0,s.error=``;let l=(async()=>{try{s.status=await W(e).gitStatus(t,{timeoutMs:a}),s.at=Date.now()}catch(e){let t=e.message??``;s.error=/fetch failed|Cannot reach|Failed to fetch|NetworkError|abort/i.test(t)?`device unreachable — check that it is online, then retry (${t.slice(0,80)})`:t.slice(0,160),s.at=Date.now()}finally{s.loading=!1,s.refreshing=!1,gf.delete(o)}})();return gf.set(o,l),l}var Af=new Map;function jf(){j(()=>Hu.devices.value.map(e=>`${e.id}:${e.status}:${e.tree?.sessions.length??0}:${e.tree?.sessions.map(e=>e.cwd).join(`|`)}`).join(`;`),()=>{for(let e of Hu.devices.value){if(e.status!==`online`||!e.tree?.sessions.length)continue;let t=Date.now();t-(Af.get(e.id)??0)<6e4||(Af.set(e.id,t),Sf(e.id,e.tree.sessions.map(e=>e.cwd)))}},{immediate:!0})}var Mf=(e,t)=>Df(e,t).status?.branch,Nf=[`aria-level`,`aria-expanded`,`aria-selected`,`data-key`,`title`],Pf=[`aria-label`],Ff={key:1,class:`chev`},If={class:`name`},Lf={class:`badge`},Rf=[`title`],zf=[`aria-label`],Bf=[`disabled`,`aria-label`],Vf=[`aria-label`],Hf=[`checked`,`aria-label`],Uf={class:`name`},Wf={class:`path`},Gf=[`title`],Kf=[`title`],qf={key:3,class:`dot work`,title:`Working`},Jf=[`title`],Yf=[`disabled`,`aria-label`],Xf=[`disabled`,`aria-label`],Zf=[`disabled`,`aria-label`],Qf=[`disabled`,`aria-label`],$f={class:`name`},ep={key:3,class:`meta`},tp={key:4,class:`dot work`,title:`Working`},np=[`title`],rp=[`disabled`,`aria-label`],ip=sf(M({__name:`TreeRow`,props:{node:{},depth:{},open:{type:Boolean},selected:{type:Boolean},focused:{type:Boolean},online:{type:Boolean},checkbox:{type:Boolean},checked:{type:Boolean}},emits:[`toggle`,`activate`,`action`,`check`],setup(e,{emit:t}){let n=e,r=t,i=H(()=>n.node.children.length>0),a=H(()=>n.node.type===`device`?n.node.device:void 0),o=H(()=>n.node.type===`session`?n.node.session:void 0),s=H(()=>n.node.type===`agent`?n.node.agent:void 0),c=H(()=>o.value?o.value.agents.reduce((e,t)=>e+t.background,0):s.value?.background??0),l=H(()=>o.value?.busy||s.value?.busy),u=H(()=>{let e=a.value?.info,t=e?.packageVersion??e?.durableVersion,n=Wu.value;return!!(t&&n&&n!==`unknown`&&t!==n)}),d=H(()=>{let e=a.value?.info;return e?.packageVersion??e?.durableVersion??`?`}),f=H(()=>{let e=a.value;if(!e)return``;let t=e.tree?.sessions.length??0;switch(e.status){case`online`:return`${t} session${t===1?``:`s`}`;case`checking`:return`checking…`;case`unauthorized`:return e.hasToken?`token rejected`:`no token`;case`mismatch`:return`identity changed`;case`incompatible`:return`incompatible`;default:return`offline · ${Pd(e.lastSeenAt)}`}}),p=H(()=>{let e=a.value?.status;return e===`online`?`on`:e===`checking`?`chk`:e===`offline`?`off`:`err`}),m=H(()=>{let e=n.node;return e.type===`session`?Mf(e.deviceId,e.session.cwd):void 0}),h=H(()=>a.value?.name??a.value?.id??o.value?.name??s.value?.name??``),g=H(()=>{if(a.value){let e=a.value;return`${e.name}${e.url?` · ${e.url}`:``}${e.error?`\n${e.error}`:``}`}if(o.value)return`${o.value.name}\n${o.value.cwd}`;let e=s.value;return e.kind===`fork`?`Fork of agent #${e.parentId} at entry #${e.forkedAt}`:e.kind===`subagent`?`Subagent owned by agent #${e.ownerAgentId}`:`Root agent`});return(t,n)=>(F(),I(`div`,{class:E([`tree-row`,[e.node.type,{sel:e.selected,focus:e.focused,stale:e.node.stale}]]),style:ge({"--depth":e.depth}),role:`treeitem`,"aria-level":e.depth+1,"aria-expanded":i.value?e.open:void 0,"aria-selected":e.selected,"data-key":e.node.key,title:g.value,onClick:n[14]||=e=>r(`activate`)},[i.value?(F(),I(`button`,{key:0,class:`chev`,tabindex:`-1`,"aria-label":e.open?`Collapse ${h.value}`:`Expand ${h.value}`,onClick:n[0]||=As(e=>r(`toggle`),[`stop`])},[e.open?(F(),L(k(rc),{key:0,size:16})):(F(),L(k(ic),{key:1,size:16}))],8,Pf)):(F(),I(`span`,Ff)),a.value?(F(),I(P,{key:2},[R(`i`,{class:E([`dot`,p.value])},null,2),z(mf,{device:a.value,size:16},null,8,[`device`]),R(`b`,If,D(h.value),1),R(`span`,Lf,D(a.value.kind),1),u.value?(F(),I(`span`,{key:0,class:`tag update`,title:`device runs ${d.value}; hub runs ${k(Wu)}. Devices self-update: dpi update`},`update`,8,Rf)):V(``,!0),R(`span`,{class:E([`meta`,{err:p.value===`err`}])},D(f.value),3),R(`span`,{class:`acts`,onClick:n[4]||=As(()=>{},[`stop`])},[a.value.pairing?(F(),I(`button`,{key:0,class:`icon-button`,"aria-label":`Manage credentials for ${h.value}`,title:`Manage device credentials, including while offline`,onClick:n[1]||=e=>r(`action`,`credentials`)},[z(k(Ac),{size:16})],8,zf)):V(``,!0),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`New session on ${h.value}`,title:`New session on this device`,onClick:n[2]||=e=>r(`action`,`new-session`)},[z(k(Zc),{size:16})],8,Bf),R(`button`,{class:`icon-button`,"aria-label":`Check ${h.value}`,title:`Check connection now`,onClick:n[3]||=e=>r(`action`,`check`)},[z(k(el),{size:16})],8,Vf)])],64)):o.value?(F(),I(P,{key:3},[e.checkbox?(F(),I(`input`,{key:0,type:`checkbox`,class:`bulk-check`,checked:e.checked,"aria-label":`Select ${h.value}`,tabindex:`-1`,onClick:n[5]||=As(()=>{},[`stop`]),onChange:n[6]||=e=>r(`check`)},null,40,Hf)):V(``,!0),z(k(bc),{class:`ico`,size:16}),R(`b`,Uf,D(h.value),1),R(`span`,Wf,`…/`+D(o.value.cwd.split(`/`).filter(Boolean).at(-1)),1),m.value?(F(),I(`span`,{key:1,class:`branch`,title:`git branch of ${o.value.cwd}`},`⎇ `+D(m.value),9,Gf)):V(``,!0),o.value.model?(F(),I(`span`,{key:2,class:`tag`,title:o.value.provider?`${o.value.provider} / ${o.value.model}`:o.value.model},D(o.value.model),9,Kf)):V(``,!0),l.value?(F(),I(`i`,qf)):V(``,!0),c.value?(F(),I(`span`,{key:4,class:`bg-count`,title:`${c.value} background task(s)`},[n[15]||=R(`i`,{class:`dot bg`},null,-1),B(D(c.value)+` bg`,1)],8,Jf)):V(``,!0),R(`span`,{class:`acts`,onClick:n[11]||=As(()=>{},[`stop`])},[R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`New agent in ${h.value}`,title:`New agent in this session`,onClick:n[7]||=e=>r(`action`,`new-agent`)},[z(k(Zc),{size:16})],8,Yf),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`Rename session ${h.value}`,title:`Rename session`,onClick:n[8]||=e=>r(`action`,`rename`)},[z(k(Jc),{size:16})],8,Xf),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`New worktree session from ${h.value}`,title:`New worktree session: branch this folder's repo and open a session in the sibling checkout`,onClick:n[9]||=e=>r(`action`,`worktree`)},[z(k(dl),{size:16})],8,Zf),R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`Archive session ${h.value}`,title:`Archive session`,onClick:n[10]||=e=>r(`action`,`archive`)},[z(k(Ws),{size:16})],8,Qf)])],64)):s.value?(F(),I(P,{key:4},[s.value.kind===`fork`?(F(),L(k(wc),{key:0,class:`ico`,size:16})):s.value.kind===`subagent`?(F(),L(k(lc),{key:1,class:`ico`,size:16})):(F(),L(k(Rc),{key:2,class:`ico root`,size:16})),R(`span`,$f,D(h.value),1),s.value.kind===`fork`&&s.value.forkedAt!==void 0?(F(),I(`span`,ep,`@ #`+D(s.value.forkedAt),1)):V(``,!0),l.value?(F(),I(`i`,tp)):V(``,!0),c.value?(F(),I(`span`,{key:5,class:`bg-count`,title:`${c.value} background task(s)`},[n[16]||=R(`i`,{class:`dot bg`},null,-1),B(D(c.value),1)],8,np)):V(``,!0),R(`span`,{class:`acts`,onClick:n[13]||=As(()=>{},[`stop`])},[R(`button`,{class:`icon-button`,disabled:!e.online,"aria-label":`Rename agent ${h.value}`,title:`Rename agent`,onClick:n[12]||=e=>r(`action`,`rename`)},[z(k(Jc),{size:16})],8,rp)])],64)):V(``,!0)],14,Nf))}}),[[`__scopeId`,`data-v-ec99cf9d`]]),ap={class:`project-bar`,"aria-label":`Projects`},op={class:`project-head`},sp={class:`project-title`},cp=[`aria-label`,`title`],lp={key:0,class:`project-hint`},up={key:0,class:`chips`},dp=[`title`,`onClick`,`onDblclick`],fp={class:`chip-name`},pp={class:`chip-count`},mp={key:1,class:`project-hint`},hp={key:2,class:`project-actions`},gp=[`onClick`],_p=[`onClick`],vp=[`onClick`],yp=[`onClick`],bp={key:3,class:`message-error`},xp={key:4,class:`project-hint labels-hint`},Sp=sf(M({__name:`ProjectBar`,props:{active:{},activeModifiers:{}},emits:[`update:active`],setup(e,{expose:t}){let n=Oi(e,`active`),r=O([]),i=O(!1),a=O(``),o=O(!1),s=H(()=>Hu.devices.value.filter(e=>e.status===`online`).map(e=>e.id));async function c(){i.value=!0,a.value=``;let e=[],t=[];for(let n of s.value){let r=Hu.devices.value.find(e=>e.id===n),i=await W(n).projects(o.value).catch(e=>{let r=G(e);e.code===`not_found`||/allowlist|not found/i.test(r)||t.push(`${n}: ${r.slice(0,60)}`)});for(let t of i?.projects??[]){let i=(r?.tree?.sessions??[]).filter(e=>e.cwd===t.rootPath||e.cwd.startsWith(`${t.rootPath}/`)).length;e.push({deviceId:n,project:t,sessions:i})}}r.value=e.sort((e,t)=>l(e.project).localeCompare(l(t.project))),t.length&&(a.value=t.join(` · `)),i.value=!1}j([s,o],c,{immediate:!0});let l=e=>e.customName??e.name,u=e=>n.value?.deviceId===e.deviceId&&n.value.rootPath===e.project.rootPath;function d(e){n.value=u(e)?void 0:{deviceId:e.deviceId,rootPath:e.project.rootPath}}function f(e){let t=e.project;q.dialog={kind:`prompt`,title:`Rename ${l(t)}`,label:`Project name`,hint:`Shown in the tree and in usage rollups. Leave empty to use the folder name.`,value:t.customName??``,placeholder:t.name,submit:`Save name`,run:async n=>{let r=await W(e.deviceId).updateProject(t.id,{customName:n});J(`Project renamed to ${r.customName??r.name}.`),await c()}}}function p(e){let t=e.project;q.dialog={kind:`prompt`,title:`Labels for ${l(t)}`,label:`Labels (comma separated)`,hint:`Lowercase, up to 12 labels of 32 characters. Used to filter projects.`,value:t.labels.join(`, `),submit:`Save labels`,run:async n=>{let r=await W(e.deviceId).updateProject(t.id,{labels:n.split(`,`).map(e=>e.trim()).filter(Boolean)});J(r.labels.length?`Labels: ${r.labels.join(`, `)}.`:`Labels cleared on ${l(r)}.`),await c()}}}function m(e){let t=e.project,n=Hu.devices.value.find(t=>t.id===e.deviceId)?.info?.models??[];q.dialog={kind:`prompt`,title:`Default model for ${l(t)}`,label:`Model (provider/modelId)`,hint:n.length?`New sessions in this project start on this model instead of the device default. Leave empty to use the device default. E.g. ${n[0].provider}/${n[0].id}`:`New sessions in this project start on this model. Leave empty to use the device default.`,value:t.model?`${t.model.provider}/${t.model.modelId}`:``,placeholder:`device default`,submit:`Save default model`,run:async r=>{if(!r.trim()){await W(e.deviceId).updateProject(t.id,{model:``}),J(`Default model cleared on ${l(t)}.`),await c();return}let[i,...a]=r.trim().split(`/`),o=a.join(`/`),s=n.some(e=>e.provider===i&&e.id===o);if(!i||!o)throw Error(`Format: provider/modelId`);if(!s)throw Error(`${r.trim()} is not in this device's catalog`);await W(e.deviceId).updateProject(t.id,{model:{provider:i,modelId:o}}),J(`New sessions in ${l(t)} start on ${o}.`),await c()}}}function h(e){let t=e.project,r=t.archivedAt!==null;q.dialog={kind:`prompt`,title:`${r?`Restore`:`Archive`} ${l(t)}?`,hint:r?`The project returns to the tree. Its sessions were never touched.`:`Bookkeeping only: the project leaves the list, its sessions keep running. Nothing is deleted.`,submit:r?`Restore project`:`Archive project`,danger:!r,run:async()=>{let i=W(e.deviceId);r?await i.unarchiveProject(t.id):await g(i,t.id),!r&&u(e)&&(n.value=void 0),await c()}}}let g=(e,t)=>e.archiveProject(t);return t({reload:c}),(e,t)=>(F(),I(`div`,ap,[R(`div`,op,[R(`span`,sp,[z(k(yc),{size:13}),t[2]||=B(`PROJECTS`,-1)]),R(`button`,{class:E([`icon-button tiny`,{on:o.value}]),"aria-label":o.value?`Hide archived projects`:`Show archived projects`,title:o.value?`Hide archived projects`:`Show archived projects`,onClick:t[0]||=e=>o.value=!o.value},[z(k(Ws),{size:12})],10,cp),i.value?(F(),I(`span`,lp,`…`)):V(``,!0)]),r.value.length?(F(),I(`div`,up,[(F(!0),I(P,null,N(r.value,e=>(F(),I(`button`,{key:`${e.deviceId}-${e.project.id}`,class:E([`chip`,{on:u(e),archived:e.project.archivedAt}]),title:`${e.project.rootPath} — ${e.sessions} session${e.sessions===1?``:`s`}`,onClick:t=>d(e),onDblclick:t=>f(e)},[e.project.kind===`plain`?(F(),L(k(xc),{key:0,size:11})):(F(),L(k(yc),{key:1,size:11})),R(`span`,fp,D(l(e.project)),1),R(`em`,pp,D(e.sessions),1),(F(!0),I(P,null,N(e.project.labels.slice(0,2),e=>(F(),I(`span`,{key:e,class:`chip-label`},D(e),1))),128))],42,dp))),128))])):i.value?V(``,!0):(F(),I(`p`,mp,` No projects yet — a project appears when a session starts in a folder. `)),n.value?(F(),I(`div`,hp,[t[5]||=R(`span`,{class:`project-hint`},`filtering`,-1),(F(!0),I(P,null,N(r.value.filter(u),e=>(F(),I(P,{key:e.project.id},[R(`button`,{class:`small`,onClick:t=>f(e)},[z(k(Jc),{size:12}),t[3]||=B(`name`,-1)],8,gp),R(`button`,{class:`small`,onClick:t=>p(e)},[z(k(pl),{size:12}),t[4]||=B(`labels`,-1)],8,_p),R(`button`,{class:`small`,onClick:t=>m(e),title:`Default model for new sessions in this project`},[z(k(fc),{size:12}),B(D(e.project.model?`model ✓`:`model`),1)],8,vp),R(`button`,{class:`small`,onClick:t=>h(e)},[e.project.archivedAt?(F(),L(k(Us),{key:0,size:12})):(F(),L(k(Ws),{key:1,size:12})),B(` `+D(e.project.archivedAt?`restore`:`archive`),1)],8,yp),R(`button`,{class:`icon-button tiny`,"aria-label":`Clear project filter`,onClick:t[1]||=e=>n.value=void 0},[z(k(Sl),{size:12})])],64))),128))])):V(``,!0),a.value?(F(),I(`p`,bp,D(a.value),1)):V(``,!0),r.value.some(e=>e.project.labels.length)?(F(),I(`p`,xp,[z(k(pl),{size:11}),B(`labels: `+D([...new Set(r.value.flatMap(e=>e.project.labels))].join(` · `)),1)])):V(``,!0)]))}}),[[`__scopeId`,`data-v-77864963`]]);function Cp(e,t){return`${e.slice(0,e.lastIndexOf(`/`))}/${e.slice(e.lastIndexOf(`/`)+1)}-${t.replace(/[/\\]+/g,`-`)}`}async function wp(e,t,n,r){let i=Cp(n,r);return{target:i,text:(await e.gitOp(t,`worktree-add`,{branch:r,target:i})).text.split(`
|
|
16
16
|
`)[0]??`worktree ${i}`}}async function Tp(e,t,n,r){return e.createSession(r?{name:n,cwd:t,model:r}:{name:n,cwd:t})}async function Ep({deviceApi:e,cwd:t,sessionName:n,branch:r,root:i,source:a,catalog:o,defaultModel:s}){let c=i;if(!c){let n=await e.gitStatus(t);if(!n.repo||!n.root)throw Error(`${t} is not a git repository`);c=n.root}let{target:l}=await wp(e,t,c,r),{model:u,provider:d}=a??{},f=u&&d&&(!o||o.some(e=>e.provider===d&&e.id===u))?{provider:d,modelId:u}:void 0,p=o?.length?o.find(e=>`${e.provider}/${e.id}`===s)??o[0]:void 0;return Tp(e,l,n,f??(p?{provider:p.provider,modelId:p.id}:void 0))}var Dp={class:`tree-head`},Op=[`aria-label`,`title`],kp=[`title`],Ap={class:`tree-search`},jp={key:1,class:`searching`,"aria-label":`Searching devices`},Mp={key:0,class:`bulk-bar`},Np=[`disabled`],Pp=[`disabled`],Fp={class:`hit-head hint`},Ip=[`title`,`onClick`],Lp={class:`hit-name`},Rp={class:`hit-cwd`},zp={key:0,class:`hit-where`},Bp=[`title`],Vp={key:2,class:`hint tree-empty`},Hp={key:3,class:`hint tree-empty`,"data-testid":`tree-empty`},Up={key:1,class:`panel-rail`,"aria-label":`Network (collapsed)`},Wp=[`title`],Gp=[`title`,`aria-label`,`onClick`],Kp=sf(M({__name:`NetworkSidebar`,setup(e){let t=H(()=>{let e=[],t=(n,r,i)=>{for(let a of n)e.push({node:a,depth:r,parent:i}),a.children.length&&Gu.value.has(a.key)&&t(a.children,r+1,a.key)};return t(Hu.tree.value,0),e}),n=O(),r=O(),i=O(``),a=O([]),o=O(!1),s=H(()=>i.value.trim().toLowerCase()),c=H(()=>s.value.length>=2),l=H(()=>{let e=new Set;if(!c.value)return e;for(let t of Hu.devices.value)for(let n of t.tree?.sessions??[])`${n.name}\n${n.cwd}`.toLowerCase().includes(s.value)&&e.add(n.id);return e}),u=O(),d=(e,t)=>!u.value||u.value.deviceId===e&&(t===u.value.rootPath||t.startsWith(`${u.value.rootPath}/`)),f=H(()=>{if(!c.value&&!u.value)return t.value;let e=e=>{if(u.value){let t=e.type===`device`?e.device.id:e.deviceId;if(e.type===`session`&&!d(t,e.session.cwd))return!1;if(e.type===`agent`){let t=Hu.devices.value.find(t=>t.id===e.deviceId)?.tree?.sessions.find(t=>t.id===e.sessionId);if(t&&!d(e.deviceId,t.cwd))return!1}if(e.type===`device`)return(e.device.tree?.sessions??[]).some(t=>d(e.device.id,t.cwd))}return c.value?e.type===`session`?l.value.has(e.session.id):e.type===`agent`?l.value.has(e.sessionId)||e.agent.name.toLowerCase().includes(s.value):(e.device.tree?.sessions??[]).some(e=>l.value.has(e.id)):!0},n=new Set(t.value.filter(t=>e(t.node)).map(e=>e.node.key));return t.value.filter(e=>n.has(e.node.key))}),p=H(()=>a.value.filter(e=>!t.value.some(t=>t.node.type===`session`&&t.node.session.id===e.id))),m,h=0;j(i,e=>{clearTimeout(m);let t=e.trim();if(t.length<2){++h,a.value=[],o.value=!1;return}m=setTimeout(async()=>{o.value=!0;let e=++h,n=[];for(let r of Hu.devices.value.filter(e=>e.status===`online`)){let i=await W(r.id).searchSessions(t,`all`).catch(()=>void 0);if(e!==h)return;for(let e of i?.matches??[])n.push({deviceId:r.id,id:e.id,name:e.name,cwd:e.cwd,where:e.where,hits:e.hits??[]})}a.value=n,o.value=!1},250)});let g=()=>(i.value=``,++h,a.value=[]),_=O(!1),v=O(new Set),y=O(``),b=e=>{if(e.type!==`session`)return;let t=new Set(v.value);t.has(e.session.id)?t.delete(e.session.id):t.add(e.session.id),v.value=t},x=async e=>{y.value=e;let n=0,r=[];for(let i of t.value.map(e=>e.node)){if(i.type!==`session`||!v.value.has(i.session.id))continue;let t=S(i);if(!t)continue;let a=W(t.id);try{e===`archive`?await a.session(i.session.id).archive():await a.agent(i.session.id,1).abort(!0),n++,e===`archive`&&K.value?.sessionId===i.session.id&&ad(void 0)}catch{r.push(i.session.name)}}J(`${e}: ${n} done${r.length?`, ${r.length} failed (${r.slice(0,3).join(`, `)})`:``}`),v.value=new Set,y.value=``},S=e=>Hu.devices.value.find(t=>t.id===(e.type===`device`?e.device.id:e.deviceId)),C=e=>S(e)?.status===`online`,ee=e=>e.type===`agent`&&K.value?.deviceId===e.deviceId&&K.value.sessionId===e.sessionId&&K.value.agentId===e.agent.id;function w(e){if(n.value=e.key,_.value&&e.type===`session`)return b(e);if(e.type===`device`)return cd(e.key);if(e.type===`agent`)return ad({deviceId:e.deviceId,sessionId:e.sessionId,agentId:e.agent.id});let t=e.session.agents.find(e=>e.kind===`root`)??e.session.agents[0];cd(e.key,!0),t&&ad({deviceId:e.deviceId,sessionId:e.session.id,agentId:t.id})}async function te(e,t){let n=S(e);if(!n)return;let r=W(n.id);if(e.type===`device`){t===`new-session`?q.dialog={kind:`new-session`,deviceId:n.id}:t===`check`?await kd(()=>Au.check(n.id)):t===`credentials`&&(q.dialog={kind:`credentials`,deviceId:n.id});return}if(e.type===`session`){let i=e.session;if(t===`new-agent`){let e=await kd(()=>r.session(i.id).createAgent({name:`Agent ${i.agents.length+1}`}));e&&(ad({deviceId:n.id,sessionId:i.id,agentId:e.id}),J(`New agent. Same session, same shared App State.`))}else t===`rename`?q.dialog={kind:`prompt`,title:`Rename session`,label:`Session name`,value:i.name,submit:`Save name`,run:e=>r.session(i.id).rename(e)}:t===`worktree`?q.dialog={kind:`prompt`,title:`New worktree session`,label:`Branch name`,value:i.name.replace(/[/\\]+/g,`-`),hint:`Adds a sibling checkout of ${i.cwd} on the branch (git worktree add) and opens a session in it.`,submit:`Create worktree session`,run:async e=>{let t=await Ep({deviceApi:r,cwd:i.cwd,sessionName:e,branch:e,source:i,catalog:n.info?.models,defaultModel:n.info?.defaultModel}),a=t.agents.find(e=>e.kind===`root`)??t.agents[0];ad({deviceId:n.id,sessionId:t.id,agentId:a?.id??1}),J(`session "${t.name}" on ${t.cwd}`)}}:t===`archive`&&(q.dialog={kind:`prompt`,title:`Archive ${i.name}?`,hint:`Stops all of its work and moves its files to archive/ on ${n.id}. Nothing is deleted.`,submit:`Archive session`,danger:!0,run:async()=>{await r.session(i.id).archive(),K.value?.sessionId===i.id&&ad(void 0)}});return}let i=e.agent;t===`rename`&&(q.dialog={kind:`prompt`,title:`Rename agent`,label:`Agent name`,value:i.named?i.name:``,placeholder:i.name,submit:`Save name`,run:t=>r.agent(e.sessionId,i.id).rename(t)})}function ne(e){let i=t.value.findIndex(e=>e.node.key===n.value),a=t.value[Math.max(0,Math.min(t.value.length-1,(i<0?0:i)+e))];a&&(n.value=a.node.key,jn(()=>r.value?.querySelector(`[data-key="${CSS.escape(a.node.key)}"]`)?.scrollIntoView({block:`nearest`})))}function re(){n.value??=t.value[0]?.node.key}function ie(e){let r=t.value.find(e=>e.node.key===n.value);if(e.key===`ArrowDown`)ne(1);else if(e.key===`ArrowUp`)ne(-1);else if(e.key===`ArrowRight`&&r){if(!r.node.children.length)return;Gu.value.has(r.node.key)?ne(1):cd(r.node.key,!0)}else if(e.key===`ArrowLeft`&&r)r.node.children.length&&Gu.value.has(r.node.key)?cd(r.node.key,!1):r.parent&&(n.value=r.parent);else if((e.key===`Enter`||e.key===` `)&&r)w(r.node);else return;e.preventDefault()}return(e,a)=>(F(),I(`aside`,{class:E([`network-sidebar`,{open:k(q).drawer,collapsed:!k(qu).tree&&!k(q).drawer}]),"aria-label":`Network`},[k(qu).tree||k(q).drawer?(F(),I(P,{key:0},[R(`header`,Dp,[R(`span`,null,[z(k(Vc),{size:16}),a[8]||=B(`NETWORK`,-1)]),R(`button`,{class:E([`icon-button`,{on:_.value}]),"aria-label":_.value?`Exit bulk select`:`Bulk manage sessions`,title:_.value?`Exit bulk select`:`Bulk manage sessions (select → archive / abort)`,onClick:a[0]||=e=>(_.value=!_.value,v.value=new Set)},[z(k(Fc),{size:15})],10,Op),R(`button`,{class:`icon-button`,"aria-label":`Pair a device`,title:`Pair a device`,onClick:a[1]||=e=>k(q).dialog={kind:`pair`}},[z(k(Pc),{size:15})]),R(`button`,{class:`icon-button panel-toggle`,"aria-label":`Collapse network`,title:`Collapse network (${k(Gd).tree})`,onClick:a[2]||=e=>(k(qu).tree=!1,k(q).drawer=!1)},[z(k(Wc),{size:18})],8,kp)]),R(`div`,Ap,[z(k(rl),{size:14,class:`search-icon`}),A(R(`input`,{"onUpdate:modelValue":a[3]||=e=>i.value=e,type:`search`,class:`search-input`,placeholder:`Search sessions…`,"aria-label":`Search sessions`,spellcheck:`false`},null,512),[[bs,i.value]]),i.value?(F(),I(`button`,{key:0,class:`icon-button clear`,"aria-label":`Clear search`,onClick:g},[z(k(Sl),{size:13})])):V(``,!0),o.value?(F(),I(`span`,jp,`…`)):V(``,!0)]),z(Sp,{active:u.value,"onUpdate:active":a[4]||=e=>u.value=e},null,8,[`active`]),R(`div`,{ref_key:`list`,ref:r,class:`tree-list`,role:`tree`,tabindex:`0`,"aria-label":`Devices, sessions and agents`,onKeydown:ie,onFocus:re},[_.value&&v.value.size?(F(),I(`div`,Mp,[R(`span`,null,D(v.value.size)+` selected`,1),R(`button`,{class:`small`,disabled:!!y.value,onClick:a[5]||=e=>x(`abort`)},`abort work`,8,Np),R(`button`,{class:`small danger`,disabled:!!y.value,onClick:a[6]||=e=>x(`archive`)},D(y.value===`archive`?`archiving…`:`archive`),9,Pp)])):V(``,!0),(F(!0),I(P,null,N(f.value,e=>(F(),L(ip,{key:e.node.key,node:e.node,depth:e.depth,open:k(Gu).has(e.node.key),selected:ee(e.node),focused:n.value===e.node.key,online:C(e.node),checkbox:_.value&&e.node.type===`session`,checked:e.node.type===`session`&&v.value.has(e.node.session.id),onToggle:t=>k(cd)(e.node.key),onActivate:t=>w(e.node),onAction:t=>te(e.node,t),onCheck:t=>b(e.node)},null,8,[`node`,`depth`,`open`,`selected`,`focused`,`online`,`checkbox`,`checked`,`onToggle`,`onActivate`,`onAction`,`onCheck`]))),128)),c.value&&p.value.length?(F(),I(P,{key:1},[R(`div`,Fp,D(p.value.length)+` more on device`,1),(F(!0),I(P,null,N(p.value,e=>(F(),I(`button`,{key:`${e.deviceId}-${e.id}`,class:`hit`,title:e.cwd,onClick:t=>k(ad)({deviceId:e.deviceId,sessionId:e.id,agentId:1})},[R(`span`,Lp,D(e.name),1),R(`code`,Rp,D(e.cwd),1),e.where.length?(F(),I(`em`,zp,D(e.where.join(` · `)),1)):V(``,!0),e.hits.length?(F(),I(`em`,{key:1,class:`hit-line`,title:e.hits.map(e=>`${e.agent} #${e.entry}: ${e.text}`).join(`
|
|
17
17
|
`)},D(e.hits[0].agent)+` #`+D(e.hits[0].entry)+` · `+D(e.hits[0].text.slice(0,90)),9,Bp)):V(``,!0)],8,Ip))),128))],64)):V(``,!0),c.value&&!f.value.length&&!p.value.length?(F(),I(`p`,Vp,` No session matches “`+D(i.value.trim())+`”. `,1)):V(``,!0),!t.value.length&&!c.value?(F(),I(`p`,Hp,[...a[9]||=[B(` No devices yet. Declare them in `,-1),R(`code`,null,`dpi-network.yaml`,-1),B(` (start from `,-1),R(`code`,null,`dpi-network.example.yaml`,-1),B(`), then run `,-1),R(`code`,null,`just net up <id>`,-1),B(`. `,-1)]])):V(``,!0)],544)],64)):(F(),I(`div`,Up,[R(`button`,{class:`icon-button panel-toggle`,"aria-label":`Expand network`,title:`Expand network (${k(Gd).tree})`,onClick:a[7]||=e=>k(qu).tree=!0},[z(k(Gc),{size:18})],8,Wp),(F(!0),I(P,null,N(k(Hu).devices.value,e=>(F(),I(`button`,{key:e.id,class:`rail-device`,title:`${e.id} · ${e.status}`,"aria-label":`Show ${e.id}`,onClick:t=>(k(qu).tree=!0,k(cd)(e.id,!0))},[z(mf,{device:e,size:20},null,8,[`device`]),R(`i`,{class:E([`dot`,e.status===`online`?`on`:e.status===`checking`?`chk`:e.status===`offline`?`off`:`err`])},null,2)],8,Gp))),128))]))],2))}}),[[`__scopeId`,`data-v-f78dbc9c`]]);function qp(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Jp=qp();function Yp(e){Jp=e}var Xp={exec:()=>null};function Zp(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace($p.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Qp=(()=>{try{return!0}catch{return!1}})(),$p={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`),blockquoteBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}>`)},em=/^(?:[ \t]*(?:\n|$))+/,tm=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,nm=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,rm=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,im=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,am=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,om=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,sm=Zp(om).replace(/bull/g,am).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),cm=Zp(om).replace(/bull/g,am).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),lm=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,um=/^[^\n]+/,dm=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,fm=Zp(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,dm).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),pm=Zp(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,am).getRegex(),mm=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,hm=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,gm=Zp(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,hm).replace(`tag`,mm).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),_m=Zp(lm).replace(`hr`,rm).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,mm).getRegex(),vm={blockquote:Zp(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,_m).getRegex(),code:tm,def:fm,fences:nm,heading:im,hr:rm,html:gm,lheading:sm,list:pm,newline:em,paragraph:_m,table:Xp,text:um},ym=Zp(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,rm).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,mm).getRegex(),bm={...vm,lheading:cm,table:ym,paragraph:Zp(lm).replace(`hr`,rm).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,ym).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,mm).getRegex()},xm={...vm,html:Zp(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,hm).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Xp,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Zp(lm).replace(`hr`,rm).replace(`heading`,` *#{1,6} *[^
|
|
18
18
|
]`).replace(`lheading`,sm).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},Sm=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Cm=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,wm=/^( {2,}|\\)\n(?!\s*$)/,Tm=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Em=/[\p{P}\p{S}]/u,Dm=/[\s\p{P}\p{S}]/u,Om=/[^\s\p{P}\p{S}]/u,km=Zp(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,Dm).getRegex(),Am=/(?!~)[\p{P}\p{S}]/u,jm=/(?!~)[\s\p{P}\p{S}]/u,Mm=/(?:[^\s\p{P}\p{S}]|~)/u,Nm=Zp(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,Qp?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),Pm=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Fm=Zp(Pm,`u`).replace(/punct/g,Em).getRegex(),Im=Zp(Pm,`u`).replace(/punct/g,Am).getRegex(),Lm=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Rm=Zp(Lm,`gu`).replace(/notPunctSpace/g,Om).replace(/punctSpace/g,Dm).replace(/punct/g,Em).getRegex(),zm=Zp(Lm,`gu`).replace(/notPunctSpace/g,Mm).replace(/punctSpace/g,jm).replace(/punct/g,Am).getRegex(),Bm=Zp(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,Om).replace(/punctSpace/g,Dm).replace(/punct/g,Em).getRegex(),Vm=Zp(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,Em).getRegex(),Hm=Zp(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Om).replace(/punctSpace/g,Dm).replace(/punct/g,Em).getRegex(),Um=Zp(/\\(punct)/,`gu`).replace(/punct/g,Em).getRegex(),Wm=Zp(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Gm=Zp(hm).replace(`(?:-->|$)`,`-->`).getRegex(),Km=Zp(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,Gm).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),qm=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Jm=Zp(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,qm).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ym=Zp(/^!?\[(label)\]\[(ref)\]/).replace(`label`,qm).replace(`ref`,dm).getRegex(),Xm=Zp(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,dm).getRegex(),Zm=Zp(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Ym).replace(`nolink`,Xm).getRegex(),Qm=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,$m={_backpedal:Xp,anyPunctuation:Um,autolink:Wm,blockSkip:Nm,br:wm,code:Cm,del:Xp,delLDelim:Xp,delRDelim:Xp,emStrongLDelim:Fm,emStrongRDelimAst:Rm,emStrongRDelimUnd:Bm,escape:Sm,link:Jm,nolink:Xm,punctuation:km,reflink:Ym,reflinkSearch:Zm,tag:Km,text:Tm,url:Xp},eh={...$m,link:Zp(/^!?\[(label)\]\((.*?)\)/).replace(`label`,qm).getRegex(),reflink:Zp(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,qm).getRegex()},th={...$m,emStrongRDelimAst:zm,emStrongLDelim:Im,delLDelim:Vm,delRDelim:Hm,url:Zp(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,Qm).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:Zp(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,Qm).getRegex()},nh={...th,br:Zp(wm).replace(`{2,}`,`*`).getRegex(),text:Zp(th.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},rh={normal:vm,gfm:bm,pedantic:xm},ih={normal:$m,gfm:th,breaks:nh,pedantic:eh},ah={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},oh=e=>ah[e];function sh(e,t){if(t){if($p.escapeTest.test(e))return e.replace($p.escapeReplace,oh)}else if($p.escapeTestNoEncode.test(e))return e.replace($p.escapeReplaceNoEncode,oh);return e}function ch(e){try{e=encodeURI(e).replace($p.percentDecode,`%`)}catch{return null}return e}function lh(e,t){let n=e.replace($p.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split($p.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``)}for(;r<n.length;r++)n[r]=n[r].trim().replace($p.slashPipe,`|`);return n}function uh(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function dh(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function fh(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function ph(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function mh(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<meta name="referrer" content="no-referrer" />
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="/icons/durable-pi.svg" />
|
|
9
9
|
<title>Durable Pi | Network</title>
|
|
10
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
+
<script type="module" crossorigin src="/assets/index-CqQCh8Ch.js"></script>
|
|
11
11
|
<link rel="stylesheet" crossorigin href="/assets/index-CkTw4GSI.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
// it without a cycle.
|
|
6
6
|
export interface GitDeviceFacts {
|
|
7
7
|
startDirs?: unknown;
|
|
8
|
+
/** run-8: the device's own served set (start dirs + session folders). Preferred
|
|
9
|
+
* when present — the FE must judge with the same list the enforcer uses. */
|
|
10
|
+
gitDirs?: unknown;
|
|
8
11
|
platform?: unknown;
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -19,7 +22,7 @@ export function normGitPath(p: string, win: boolean): string {
|
|
|
19
22
|
/** True when the device's start dirs are unknown (allow: the device decides) or
|
|
20
23
|
* `path` IS a start dir / lives under one. */
|
|
21
24
|
export function pathUnderStartDirs(info: GitDeviceFacts | undefined, path: string): boolean {
|
|
22
|
-
const dirs = info?.startDirs;
|
|
25
|
+
const dirs = Array.isArray(info?.gitDirs) && info.gitDirs.length ? info.gitDirs : info?.startDirs;
|
|
23
26
|
if (!Array.isArray(dirs) || dirs.length === 0) return true;
|
|
24
27
|
const win = String(info?.platform ?? "").startsWith("win32");
|
|
25
28
|
const a = normGitPath(path, win);
|
|
@@ -31,7 +34,8 @@ export function pathUnderStartDirs(info: GitDeviceFacts | undefined, path: strin
|
|
|
31
34
|
|
|
32
35
|
/** Operator-facing sentence naming the roots the device actually serves. */
|
|
33
36
|
export function outsideStartDirsReason(info: GitDeviceFacts | undefined): string {
|
|
34
|
-
const
|
|
37
|
+
const source = Array.isArray(info?.gitDirs) && info.gitDirs.length ? info.gitDirs : info?.startDirs;
|
|
38
|
+
const dirs = Array.isArray(source) ? (source as unknown[]).map(String) : [];
|
|
35
39
|
return dirs.length
|
|
36
40
|
? `outside the device's start dirs (it serves: ${dirs.join(", ")})`
|
|
37
41
|
: "outside the device's start dirs";
|
package/apps/dpi-sdk/src/api.ts
CHANGED
|
@@ -99,6 +99,10 @@ export interface DeviceInfo {
|
|
|
99
99
|
startedAt: number;
|
|
100
100
|
/** Where new sessions start: the directory browser opens here, relative cwds resolve against the first. */
|
|
101
101
|
startDirs: string[];
|
|
102
|
+
/** Folders this device will serve git/files for: the start dirs plus the
|
|
103
|
+
* folders that already host a session (a narrowed start-dir list must not
|
|
104
|
+
* strand a live session's panels). Clients pre-check with this when present. */
|
|
105
|
+
gitDirs?: string[];
|
|
102
106
|
models: ModelInfo[];
|
|
103
107
|
defaultModel: string;
|
|
104
108
|
/** Provider id of this device ("openrouter" | "faux"); FE model fallback. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-durable",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.81",
|
|
4
4
|
"description": "Durable Pi — the durable agent network: hub web UI, device backend daemon, TUI admin and the shared SDK, packaged as one runnable monorepo install",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|