@ouro.bot/cli 0.1.0-alpha.665 → 0.1.0-alpha.666
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/changelog.json +6 -0
- package/dist/arc/flight-recorder.js +267 -4
- package/dist/heart/core.js +167 -4
- package/dist/heart/cross-chat-delivery.js +3 -2
- package/dist/heart/daemon/cli-exec.js +50 -1
- package/dist/heart/daemon/cli-help.js +1 -1
- package/dist/heart/daemon/cli-parse.js +36 -2
- package/dist/heart/daemon/daemon-entry.js +24 -5
- package/dist/heart/daemon/daemon.js +10 -1
- package/dist/heart/habits/habit-scheduler.js +24 -5
- package/dist/heart/habits/habit-session.js +563 -0
- package/dist/heart/mailbox/mailbox-http-hooks.js +2 -0
- package/dist/heart/mailbox/mailbox-http-routes.js +40 -0
- package/dist/heart/mailbox/mailbox-read.js +3 -1
- package/dist/heart/mailbox/readers/runtime-readers.js +56 -0
- package/dist/mailbox-ui/assets/index-CaTIFDmv.js +1 -0
- package/dist/mailbox-ui/assets/index-Du_9G9WO.css +1 -0
- package/dist/mailbox-ui/assets/vendor-CcN1XpQ9.js +61 -0
- package/dist/mailbox-ui/index.html +3 -2
- package/dist/repertoire/tools-notes.js +50 -0
- package/dist/repertoire/tools-record.js +13 -0
- package/dist/repertoire/tools-session.js +14 -0
- package/dist/repertoire/tools-surface.js +11 -0
- package/dist/repertoire/tools.js +7 -0
- package/dist/senses/inner-dialog-worker.js +153 -69
- package/dist/senses/inner-dialog.js +5 -3
- package/dist/senses/pipeline.js +0 -9
- package/dist/senses/surface-tool.js +2 -1
- package/package.json +1 -1
- package/dist/mailbox-ui/assets/index-BZ60na8O.js +0 -61
- package/dist/mailbox-ui/assets/index-DG6Xf5uL.css +0 -1
|
@@ -41,6 +41,8 @@ exports.readNotesView = readNotesView;
|
|
|
41
41
|
exports.readFriendView = readFriendView;
|
|
42
42
|
exports.readLogView = readLogView;
|
|
43
43
|
exports.readHabitView = readHabitView;
|
|
44
|
+
exports.readHabitRunView = readHabitRunView;
|
|
45
|
+
exports.readHabitRunReceiptView = readHabitRunReceiptView;
|
|
44
46
|
exports.readNeedsMeView = readNeedsMeView;
|
|
45
47
|
exports.readDeskPrefs = readDeskPrefs;
|
|
46
48
|
const fs = __importStar(require("fs"));
|
|
@@ -50,11 +52,14 @@ const habit_parser_1 = require("../../habits/habit-parser");
|
|
|
50
52
|
const habit_runtime_state_1 = require("../../habits/habit-runtime-state");
|
|
51
53
|
const identity_1 = require("../../identity");
|
|
52
54
|
const daemon_health_1 = require("../../daemon/daemon-health");
|
|
55
|
+
const flight_recorder_1 = require("../../../arc/flight-recorder");
|
|
53
56
|
const shared_1 = require("./shared");
|
|
54
57
|
const agent_machine_1 = require("./agent-machine");
|
|
55
58
|
const sessions_1 = require("./sessions");
|
|
56
59
|
const record_paths_1 = require("../../../mind/record-paths");
|
|
57
60
|
const NOTES_VIEW_LIMIT = 20;
|
|
61
|
+
const DEFAULT_HABIT_RUN_LIMIT = 20;
|
|
62
|
+
const MAX_HABIT_RUN_LIMIT = 100;
|
|
58
63
|
/* v8 ignore start — defensive parsing of on-disk JSON, fallback branches are safety nets */
|
|
59
64
|
function readCodingDeep(agentRoot) {
|
|
60
65
|
const stateFilePath = path.join(agentRoot, "state", "coding", "sessions.json");
|
|
@@ -600,6 +605,57 @@ function readHabitView(agentRoot, options = {}) {
|
|
|
600
605
|
items,
|
|
601
606
|
};
|
|
602
607
|
}
|
|
608
|
+
function normalizeHabitRunLimit(limit) {
|
|
609
|
+
if (limit === undefined || !Number.isInteger(limit))
|
|
610
|
+
return DEFAULT_HABIT_RUN_LIMIT;
|
|
611
|
+
return Math.min(MAX_HABIT_RUN_LIMIT, Math.max(1, limit));
|
|
612
|
+
}
|
|
613
|
+
function summarizeHabitRunReceipt(receipt) {
|
|
614
|
+
return {
|
|
615
|
+
runId: receipt.runId,
|
|
616
|
+
habitName: receipt.habitName,
|
|
617
|
+
trigger: receipt.trigger,
|
|
618
|
+
startedAt: receipt.startedAt,
|
|
619
|
+
endedAt: receipt.endedAt,
|
|
620
|
+
outcome: receipt.outcome,
|
|
621
|
+
nextRunAt: receipt.nextRunAt,
|
|
622
|
+
permissionEnvelope: receipt.permissionEnvelope,
|
|
623
|
+
toolPolicy: receipt.toolPolicy,
|
|
624
|
+
producedRefs: receipt.producedRefs,
|
|
625
|
+
surfaceAttempts: receipt.surfaceAttempts,
|
|
626
|
+
errorCount: receipt.errors.length,
|
|
627
|
+
errors: receipt.errors,
|
|
628
|
+
receiptLocator: receipt.receiptLocator,
|
|
629
|
+
sessionLocator: receipt.sessionLocator,
|
|
630
|
+
runtimeStateLocator: receipt.runtimeStateLocator,
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function readHabitRunView(agentRoot, options = {}) {
|
|
634
|
+
const limit = normalizeHabitRunLimit(options.limit);
|
|
635
|
+
const receipts = (0, flight_recorder_1.listHabitRunReceipts)(agentRoot);
|
|
636
|
+
const items = receipts.slice(0, limit).map(summarizeHabitRunReceipt);
|
|
637
|
+
(0, runtime_1.emitNervesEvent)({
|
|
638
|
+
component: "heart",
|
|
639
|
+
event: "heart.mailbox_habit_runs_read",
|
|
640
|
+
message: "reading mailbox habit run receipts",
|
|
641
|
+
meta: { agentRoot, totalCount: receipts.length, limit, itemCount: items.length },
|
|
642
|
+
});
|
|
643
|
+
return {
|
|
644
|
+
totalCount: receipts.length,
|
|
645
|
+
limit,
|
|
646
|
+
items,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function readHabitRunReceiptView(agentRoot, runId) {
|
|
650
|
+
const receipt = (0, flight_recorder_1.readHabitRunReceipt)(agentRoot, runId);
|
|
651
|
+
(0, runtime_1.emitNervesEvent)({
|
|
652
|
+
component: "heart",
|
|
653
|
+
event: "heart.mailbox_habit_run_receipt_read",
|
|
654
|
+
message: "reading mailbox habit run receipt",
|
|
655
|
+
meta: { agentRoot, runId, found: receipt !== null },
|
|
656
|
+
});
|
|
657
|
+
return receipt ? { receipt } : null;
|
|
658
|
+
}
|
|
603
659
|
function readNeedsMeView(agentName, options = {}) {
|
|
604
660
|
const bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
605
661
|
const now = options.now?.() ?? new Date();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as u,j as e,b as Ue,c as E,L as ee,m as Ne,a as ye,h as He,d as _e,z as qe,y as ke,e as Be}from"./vendor-CcN1XpQ9.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))a(o);new MutationObserver(o=>{for(const r of o)if(r.type==="childList")for(const l of r.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&a(l)}).observe(document,{childList:!0,subtree:!0});function n(o){const r={};return o.integrity&&(r.integrity=o.integrity),o.referrerPolicy&&(r.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?r.credentials="include":o.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function a(o){if(o.ep)return;o.ep=!0;const r=n(o);fetch(o.href,r)}})();const Ce="/api";async function z(t){const s=await fetch(`${Ce}${t}`,{headers:{accept:"application/json"}});if(!s.ok)throw new Error(`${s.status} ${s.statusText}`);return s.json()}function De(t){const s=new EventSource(`${Ce}/events`);return s.addEventListener("state-changed",n=>{try{const a=JSON.parse(n.data);t("state-changed",a)}catch{t("state-changed",{})}}),s.onerror=()=>{},()=>s.close()}function T(t){if(!t)return"unknown";const s=Date.now()-new Date(t).getTime();return s<0||s<6e4?"just now":s<36e5?`${Math.floor(s/6e4)}m ago`:s<864e5?`${Math.floor(s/36e5)}h ago`:`${Math.floor(s/864e5)}d ago`}function U(t,s){if(!t)return"";if(t.length<=s)return t;const n=t.lastIndexOf(" ",s);return(n>s*.6?t.slice(0,n):t.slice(0,s))+"…"}const Se=u.createContext(()=>{});function D(){return u.useContext(Se)}const Fe=new Set(["overview","mail","sessions","work","connections","inner","notes","runtime"]);function $e(t){const s=t.replace(/^#\/?/,"");if(!s.startsWith("agent/"))return null;const n=s.split("/"),a=n[1]?decodeURIComponent(n[1]):"";if(!a)return null;const o=n[2]??"overview",r=Fe.has(o)?o:"overview",l=n.slice(3),f=l.length>0?l.map(decodeURIComponent).join("/"):void 0;return{agent:a,tab:r,focus:f}}function le(t){let s=`#/agent/${encodeURIComponent(t.agent)}`;return(t.tab!=="overview"||t.focus)&&(s+=`/${t.tab}`),t.focus&&(s+=`/${t.focus.split("/").map(encodeURIComponent).join("/")}`),s}const te=u.forwardRef(function(s,n){return e.jsx(Ue,{children:e.jsx("a",{...s,ref:n})})}),F={base:["relative isolate inline-flex items-baseline justify-center gap-x-2 rounded-lg border text-base/6 font-semibold","px-[calc(--spacing(3.5)-1px)] py-[calc(--spacing(2.5)-1px)] sm:px-[calc(--spacing(3)-1px)] sm:py-[calc(--spacing(1.5)-1px)] sm:text-sm/6","focus:not-data-focus:outline-hidden data-focus:outline-2 data-focus:outline-offset-2 data-focus:outline-blue-500","data-disabled:opacity-50","*:data-[slot=icon]:-mx-0.5 *:data-[slot=icon]:my-0.5 *:data-[slot=icon]:size-5 *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:self-center *:data-[slot=icon]:text-(--btn-icon) sm:*:data-[slot=icon]:my-1 sm:*:data-[slot=icon]:size-4 forced-colors:[--btn-icon:ButtonText] forced-colors:data-hover:[--btn-icon:ButtonText]"],solid:["border-transparent bg-(--btn-border)","dark:bg-(--btn-bg)","before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-lg)-1px)] before:bg-(--btn-bg)","before:shadow-sm","dark:before:hidden","dark:border-white/5","after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-lg)-1px)]","after:shadow-[inset_0_1px_--theme(--color-white/15%)]","data-active:after:bg-(--btn-hover-overlay) data-hover:after:bg-(--btn-hover-overlay)","dark:after:-inset-px dark:after:rounded-lg","data-disabled:before:shadow-none data-disabled:after:shadow-none"],outline:["border-zinc-950/10 text-zinc-950 data-active:bg-zinc-950/2.5 data-hover:bg-zinc-950/2.5","dark:border-white/15 dark:text-white dark:[--btn-bg:transparent] dark:data-active:bg-white/5 dark:data-hover:bg-white/5","[--btn-icon:var(--color-zinc-500)] data-active:[--btn-icon:var(--color-zinc-700)] data-hover:[--btn-icon:var(--color-zinc-700)] dark:data-active:[--btn-icon:var(--color-zinc-400)] dark:data-hover:[--btn-icon:var(--color-zinc-400)]"],plain:["border-transparent text-zinc-950 data-active:bg-zinc-950/5 data-hover:bg-zinc-950/5","dark:text-white dark:data-active:bg-white/10 dark:data-hover:bg-white/10","[--btn-icon:var(--color-zinc-500)] data-active:[--btn-icon:var(--color-zinc-700)] data-hover:[--btn-icon:var(--color-zinc-700)] dark:[--btn-icon:var(--color-zinc-500)] dark:data-active:[--btn-icon:var(--color-zinc-400)] dark:data-hover:[--btn-icon:var(--color-zinc-400)]"],colors:{"dark/zinc":["text-white [--btn-bg:var(--color-zinc-900)] [--btn-border:var(--color-zinc-950)]/90 [--btn-hover-overlay:var(--color-white)]/10","dark:text-white dark:[--btn-bg:var(--color-zinc-600)] dark:[--btn-hover-overlay:var(--color-white)]/5","[--btn-icon:var(--color-zinc-400)] data-active:[--btn-icon:var(--color-zinc-300)] data-hover:[--btn-icon:var(--color-zinc-300)]"],light:["text-zinc-950 [--btn-bg:white] [--btn-border:var(--color-zinc-950)]/10 [--btn-hover-overlay:var(--color-zinc-950)]/2.5 data-active:[--btn-border:var(--color-zinc-950)]/15 data-hover:[--btn-border:var(--color-zinc-950)]/15","dark:text-white dark:[--btn-hover-overlay:var(--color-white)]/5 dark:[--btn-bg:var(--color-zinc-800)]","[--btn-icon:var(--color-zinc-500)] data-active:[--btn-icon:var(--color-zinc-700)] data-hover:[--btn-icon:var(--color-zinc-700)] dark:[--btn-icon:var(--color-zinc-500)] dark:data-active:[--btn-icon:var(--color-zinc-400)] dark:data-hover:[--btn-icon:var(--color-zinc-400)]"],"dark/white":["text-white [--btn-bg:var(--color-zinc-900)] [--btn-border:var(--color-zinc-950)]/90 [--btn-hover-overlay:var(--color-white)]/10","dark:text-zinc-950 dark:[--btn-bg:white] dark:[--btn-hover-overlay:var(--color-zinc-950)]/5","[--btn-icon:var(--color-zinc-400)] data-active:[--btn-icon:var(--color-zinc-300)] data-hover:[--btn-icon:var(--color-zinc-300)] dark:[--btn-icon:var(--color-zinc-500)] dark:data-active:[--btn-icon:var(--color-zinc-400)] dark:data-hover:[--btn-icon:var(--color-zinc-400)]"],dark:["text-white [--btn-bg:var(--color-zinc-900)] [--btn-border:var(--color-zinc-950)]/90 [--btn-hover-overlay:var(--color-white)]/10","dark:[--btn-hover-overlay:var(--color-white)]/5 dark:[--btn-bg:var(--color-zinc-800)]","[--btn-icon:var(--color-zinc-400)] data-active:[--btn-icon:var(--color-zinc-300)] data-hover:[--btn-icon:var(--color-zinc-300)]"],white:["text-zinc-950 [--btn-bg:white] [--btn-border:var(--color-zinc-950)]/10 [--btn-hover-overlay:var(--color-zinc-950)]/2.5 data-active:[--btn-border:var(--color-zinc-950)]/15 data-hover:[--btn-border:var(--color-zinc-950)]/15","dark:[--btn-hover-overlay:var(--color-zinc-950)]/5","[--btn-icon:var(--color-zinc-400)] data-active:[--btn-icon:var(--color-zinc-500)] data-hover:[--btn-icon:var(--color-zinc-500)]"],zinc:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-zinc-600)] [--btn-border:var(--color-zinc-700)]/90","dark:[--btn-hover-overlay:var(--color-white)]/5","[--btn-icon:var(--color-zinc-400)] data-active:[--btn-icon:var(--color-zinc-300)] data-hover:[--btn-icon:var(--color-zinc-300)]"],indigo:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-indigo-500)] [--btn-border:var(--color-indigo-600)]/90","[--btn-icon:var(--color-indigo-300)] data-active:[--btn-icon:var(--color-indigo-200)] data-hover:[--btn-icon:var(--color-indigo-200)]"],cyan:["text-cyan-950 [--btn-bg:var(--color-cyan-300)] [--btn-border:var(--color-cyan-400)]/80 [--btn-hover-overlay:var(--color-white)]/25","[--btn-icon:var(--color-cyan-500)]"],red:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-red-600)] [--btn-border:var(--color-red-700)]/90","[--btn-icon:var(--color-red-300)] data-active:[--btn-icon:var(--color-red-200)] data-hover:[--btn-icon:var(--color-red-200)]"],orange:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-orange-500)] [--btn-border:var(--color-orange-600)]/90","[--btn-icon:var(--color-orange-300)] data-active:[--btn-icon:var(--color-orange-200)] data-hover:[--btn-icon:var(--color-orange-200)]"],amber:["text-amber-950 [--btn-hover-overlay:var(--color-white)]/25 [--btn-bg:var(--color-amber-400)] [--btn-border:var(--color-amber-500)]/80","[--btn-icon:var(--color-amber-600)]"],yellow:["text-yellow-950 [--btn-hover-overlay:var(--color-white)]/25 [--btn-bg:var(--color-yellow-300)] [--btn-border:var(--color-yellow-400)]/80","[--btn-icon:var(--color-yellow-600)] data-active:[--btn-icon:var(--color-yellow-700)] data-hover:[--btn-icon:var(--color-yellow-700)]"],lime:["text-lime-950 [--btn-hover-overlay:var(--color-white)]/25 [--btn-bg:var(--color-lime-300)] [--btn-border:var(--color-lime-400)]/80","[--btn-icon:var(--color-lime-600)] data-active:[--btn-icon:var(--color-lime-700)] data-hover:[--btn-icon:var(--color-lime-700)]"],green:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-green-600)] [--btn-border:var(--color-green-700)]/90","[--btn-icon:var(--color-white)]/60 data-active:[--btn-icon:var(--color-white)]/80 data-hover:[--btn-icon:var(--color-white)]/80"],emerald:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-emerald-600)] [--btn-border:var(--color-emerald-700)]/90","[--btn-icon:var(--color-white)]/60 data-active:[--btn-icon:var(--color-white)]/80 data-hover:[--btn-icon:var(--color-white)]/80"],teal:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-teal-600)] [--btn-border:var(--color-teal-700)]/90","[--btn-icon:var(--color-white)]/60 data-active:[--btn-icon:var(--color-white)]/80 data-hover:[--btn-icon:var(--color-white)]/80"],sky:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-sky-500)] [--btn-border:var(--color-sky-600)]/80","[--btn-icon:var(--color-white)]/60 data-active:[--btn-icon:var(--color-white)]/80 data-hover:[--btn-icon:var(--color-white)]/80"],blue:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-blue-600)] [--btn-border:var(--color-blue-700)]/90","[--btn-icon:var(--color-blue-400)] data-active:[--btn-icon:var(--color-blue-300)] data-hover:[--btn-icon:var(--color-blue-300)]"],violet:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-violet-500)] [--btn-border:var(--color-violet-600)]/90","[--btn-icon:var(--color-violet-300)] data-active:[--btn-icon:var(--color-violet-200)] data-hover:[--btn-icon:var(--color-violet-200)]"],purple:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-purple-500)] [--btn-border:var(--color-purple-600)]/90","[--btn-icon:var(--color-purple-300)] data-active:[--btn-icon:var(--color-purple-200)] data-hover:[--btn-icon:var(--color-purple-200)]"],fuchsia:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-fuchsia-500)] [--btn-border:var(--color-fuchsia-600)]/90","[--btn-icon:var(--color-fuchsia-300)] data-active:[--btn-icon:var(--color-fuchsia-200)] data-hover:[--btn-icon:var(--color-fuchsia-200)]"],pink:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-pink-500)] [--btn-border:var(--color-pink-600)]/90","[--btn-icon:var(--color-pink-300)] data-active:[--btn-icon:var(--color-pink-200)] data-hover:[--btn-icon:var(--color-pink-200)]"],rose:["text-white [--btn-hover-overlay:var(--color-white)]/10 [--btn-bg:var(--color-rose-500)] [--btn-border:var(--color-rose-600)]/90","[--btn-icon:var(--color-rose-300)] data-active:[--btn-icon:var(--color-rose-200)] data-hover:[--btn-icon:var(--color-rose-200)]"]}};u.forwardRef(function({color:s,outline:n,plain:a,className:o,children:r,...l},f){let i=E(o,F.base,n?F.outline:a?F.plain:E(F.solid,F.colors[s??"dark/zinc"]));return typeof l.href=="string"?e.jsx(te,{...l,className:i,ref:f,children:e.jsx(H,{children:r})}):e.jsx(ee,{...l,className:E(i,"cursor-default"),ref:f,children:e.jsx(H,{children:r})})});function H({children:t}){return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-1/2 left-1/2 size-[max(100%,2.75rem)] -translate-x-1/2 -translate-y-1/2 pointer-fine:hidden","aria-hidden":"true"}),t]})}function Pe({className:t,...s}){return e.jsx("nav",{...s,className:E(t,"flex flex-1 items-center gap-4 py-2.5")})}function We({className:t,...s}){let n=u.useId();return e.jsx(ye,{id:n,children:e.jsx("div",{...s,className:E(t,"flex items-center gap-3")})})}function Ve({className:t,...s}){return e.jsx("div",{"aria-hidden":"true",...s,className:E(t,"-ml-4 flex-1")})}const de=u.forwardRef(function({current:s,className:n,children:a,...o},r){let l=E("relative flex min-w-0 items-center gap-3 rounded-lg p-2 text-left text-base/6 font-medium text-zinc-950 sm:text-sm/5","*:data-[slot=icon]:size-6 *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:fill-zinc-500 sm:*:data-[slot=icon]:size-5","*:not-nth-2:last:data-[slot=icon]:ml-auto *:not-nth-2:last:data-[slot=icon]:size-5 sm:*:not-nth-2:last:data-[slot=icon]:size-4","*:data-[slot=avatar]:-m-0.5 *:data-[slot=avatar]:size-7 *:data-[slot=avatar]:[--avatar-radius:var(--radius-md)] sm:*:data-[slot=avatar]:size-6","data-hover:bg-zinc-950/5 data-hover:*:data-[slot=icon]:fill-zinc-950","data-active:bg-zinc-950/5 data-active:*:data-[slot=icon]:fill-zinc-950","dark:text-white dark:*:data-[slot=icon]:fill-zinc-400","dark:data-hover:bg-white/5 dark:data-hover:*:data-[slot=icon]:fill-white","dark:data-active:bg-white/5 dark:data-active:*:data-[slot=icon]:fill-white");return e.jsxs("span",{className:E(n,"relative"),children:[s&&e.jsx(Ne.span,{layoutId:"current-indicator",className:"absolute inset-x-2 -bottom-2.5 h-0.5 rounded-full bg-zinc-950 dark:bg-white"}),typeof o.href=="string"?e.jsx(te,{...o,className:l,"data-current":s?"true":void 0,ref:r,children:e.jsx(H,{children:a})}):e.jsx(ee,{...o,className:E("cursor-default",l),"data-current":s?"true":void 0,ref:r,children:e.jsx(H,{children:a})})]})});function Ke(){return e.jsx("svg",{"data-slot":"icon",viewBox:"0 0 20 20","aria-hidden":"true",children:e.jsx("path",{d:"M2 6.75C2 6.33579 2.33579 6 2.75 6H17.25C17.6642 6 18 6.33579 18 6.75C18 7.16421 17.6642 7.5 17.25 7.5H2.75C2.33579 7.5 2 7.16421 2 6.75ZM2 13.25C2 12.8358 2.33579 12.5 2.75 12.5H17.25C17.6642 12.5 18 12.8358 18 13.25C18 13.6642 17.6642 14 17.25 14H2.75C2.33579 14 2 13.6642 2 13.25Z"})})}function Qe(){return e.jsx("svg",{"data-slot":"icon",viewBox:"0 0 20 20","aria-hidden":"true",children:e.jsx("path",{d:"M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z"})})}function Je({open:t,close:s,children:n}){return e.jsxs(He,{open:t,onClose:s,className:"lg:hidden",children:[e.jsx(_e,{transition:!0,className:"fixed inset-0 bg-black/30 transition data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in"}),e.jsx(qe,{transition:!0,className:"fixed inset-y-0 w-full max-w-80 p-2 transition duration-300 ease-in-out data-closed:-translate-x-full",children:e.jsxs("div",{className:"flex h-full flex-col rounded-lg bg-ouro-deep shadow-xl ring-1 ring-ouro-moss/40",children:[e.jsx("div",{className:"-mb-3 px-4 pt-3",children:e.jsx(ke,{as:de,"aria-label":"Close navigation",children:e.jsx(Qe,{})})}),n]})})]})}function Ye({navbar:t,sidebar:s,children:n}){let[a,o]=u.useState(!1);return e.jsxs("div",{className:"relative isolate flex min-h-svh w-full bg-ouro-void max-lg:flex-col",children:[e.jsx("div",{className:"fixed inset-y-0 left-0 w-64 max-lg:hidden border-r border-zinc-200 dark:border-ouro-moss/30",children:s}),e.jsx(Je,{open:a,close:()=>o(!1),children:s}),e.jsxs("header",{className:"flex items-center px-4 lg:hidden",children:[e.jsx("div",{className:"py-2.5",children:e.jsx(de,{onClick:()=>o(!0),"aria-label":"Open navigation",children:e.jsx(Ke,{})})}),e.jsx("div",{className:"min-w-0 flex-1",children:t})]}),e.jsx("main",{className:"flex flex-1 flex-col lg:min-w-0 lg:pl-64",children:e.jsx("div",{className:"grow bg-ouro-deep p-4 lg:p-8",children:e.jsx("div",{className:"mx-auto max-w-6xl",children:n})})})]})}function Ze({className:t,...s}){return e.jsx("nav",{...s,className:E(t,"flex h-full min-h-0 flex-col")})}function Xe({className:t,...s}){return e.jsx("div",{...s,className:E(t,"flex flex-col border-b border-zinc-950/5 p-4 dark:border-white/5 [&>[data-slot=section]+[data-slot=section]]:mt-2.5")})}function Ge({className:t,...s}){return e.jsx("div",{...s,className:E(t,"flex flex-1 flex-col overflow-y-auto p-4 [&>[data-slot=section]+[data-slot=section]]:mt-8")})}function et({className:t,...s}){return e.jsx("div",{...s,className:E(t,"flex flex-col border-t border-zinc-950/5 p-4 dark:border-white/5 [&>[data-slot=section]+[data-slot=section]]:mt-2.5")})}function ue({className:t,...s}){let n=u.useId();return e.jsx(ye,{id:n,children:e.jsx("div",{...s,"data-slot":"section",className:E(t,"flex flex-col gap-0.5")})})}function me({className:t,...s}){return e.jsx("h3",{...s,className:E(t,"mb-1 px-2 text-xs/6 font-medium text-zinc-500 dark:text-zinc-400")})}const tt=u.forwardRef(function({current:s,className:n,children:a,...o},r){let l=E("flex w-full items-center gap-3 rounded-lg px-2 py-2.5 text-left text-base/6 font-medium text-zinc-950 sm:py-2 sm:text-sm/5","*:data-[slot=icon]:size-6 *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:fill-zinc-500 sm:*:data-[slot=icon]:size-5","*:last:data-[slot=icon]:ml-auto *:last:data-[slot=icon]:size-5 sm:*:last:data-[slot=icon]:size-4","*:data-[slot=avatar]:-m-0.5 *:data-[slot=avatar]:size-7 sm:*:data-[slot=avatar]:size-6","data-hover:bg-zinc-950/5 data-hover:*:data-[slot=icon]:fill-zinc-950","data-active:bg-zinc-950/5 data-active:*:data-[slot=icon]:fill-zinc-950","data-current:*:data-[slot=icon]:fill-zinc-950","dark:text-white dark:*:data-[slot=icon]:fill-zinc-400","dark:data-hover:bg-white/5 dark:data-hover:*:data-[slot=icon]:fill-white","dark:data-active:bg-white/5 dark:data-active:*:data-[slot=icon]:fill-white","dark:data-current:*:data-[slot=icon]:fill-white");return e.jsxs("span",{className:E(n,"relative"),children:[s&&e.jsx(Ne.span,{layoutId:"current-indicator",className:"absolute inset-y-2 -left-4 w-0.5 rounded-full bg-zinc-950 dark:bg-white"}),typeof o.href=="string"?e.jsx(ke,{as:te,...o,className:l,"data-current":s?"true":void 0,ref:r,children:e.jsx(H,{children:a})}):e.jsx(ee,{...o,className:E("cursor-default",l),"data-current":s?"true":void 0,ref:r,children:e.jsx(H,{children:a})})]})});function st({className:t,...s}){return e.jsx("span",{...s,className:E(t,"truncate")})}const nt={red:"bg-red-500/15 text-red-700 group-data-hover:bg-red-500/25 dark:bg-red-500/10 dark:text-red-400 dark:group-data-hover:bg-red-500/20",orange:"bg-orange-500/15 text-orange-700 group-data-hover:bg-orange-500/25 dark:bg-orange-500/10 dark:text-orange-400 dark:group-data-hover:bg-orange-500/20",amber:"bg-amber-400/20 text-amber-700 group-data-hover:bg-amber-400/30 dark:bg-amber-400/10 dark:text-amber-400 dark:group-data-hover:bg-amber-400/15",yellow:"bg-yellow-400/20 text-yellow-700 group-data-hover:bg-yellow-400/30 dark:bg-yellow-400/10 dark:text-yellow-300 dark:group-data-hover:bg-yellow-400/15",lime:"bg-lime-400/20 text-lime-700 group-data-hover:bg-lime-400/30 dark:bg-lime-400/10 dark:text-lime-300 dark:group-data-hover:bg-lime-400/15",green:"bg-green-500/15 text-green-700 group-data-hover:bg-green-500/25 dark:bg-green-500/10 dark:text-green-400 dark:group-data-hover:bg-green-500/20",emerald:"bg-emerald-500/15 text-emerald-700 group-data-hover:bg-emerald-500/25 dark:bg-emerald-500/10 dark:text-emerald-400 dark:group-data-hover:bg-emerald-500/20",teal:"bg-teal-500/15 text-teal-700 group-data-hover:bg-teal-500/25 dark:bg-teal-500/10 dark:text-teal-300 dark:group-data-hover:bg-teal-500/20",cyan:"bg-cyan-400/20 text-cyan-700 group-data-hover:bg-cyan-400/30 dark:bg-cyan-400/10 dark:text-cyan-300 dark:group-data-hover:bg-cyan-400/15",sky:"bg-sky-500/15 text-sky-700 group-data-hover:bg-sky-500/25 dark:bg-sky-500/10 dark:text-sky-300 dark:group-data-hover:bg-sky-500/20",blue:"bg-blue-500/15 text-blue-700 group-data-hover:bg-blue-500/25 dark:text-blue-400 dark:group-data-hover:bg-blue-500/25",indigo:"bg-indigo-500/15 text-indigo-700 group-data-hover:bg-indigo-500/25 dark:text-indigo-400 dark:group-data-hover:bg-indigo-500/20",violet:"bg-violet-500/15 text-violet-700 group-data-hover:bg-violet-500/25 dark:text-violet-400 dark:group-data-hover:bg-violet-500/20",purple:"bg-purple-500/15 text-purple-700 group-data-hover:bg-purple-500/25 dark:text-purple-400 dark:group-data-hover:bg-purple-500/20",fuchsia:"bg-fuchsia-400/15 text-fuchsia-700 group-data-hover:bg-fuchsia-400/25 dark:bg-fuchsia-400/10 dark:text-fuchsia-400 dark:group-data-hover:bg-fuchsia-400/20",pink:"bg-pink-400/15 text-pink-700 group-data-hover:bg-pink-400/25 dark:bg-pink-400/10 dark:text-pink-400 dark:group-data-hover:bg-pink-400/20",rose:"bg-rose-400/15 text-rose-700 group-data-hover:bg-rose-400/25 dark:bg-rose-400/10 dark:text-rose-400 dark:group-data-hover:bg-rose-400/20",zinc:"bg-zinc-600/10 text-zinc-700 group-data-hover:bg-zinc-600/20 dark:bg-white/5 dark:text-zinc-400 dark:group-data-hover:bg-white/10"};function y({color:t="zinc",className:s,...n}){return e.jsx("span",{...n,className:E(s,"inline-flex items-center gap-x-1.5 rounded-md px-1.5 py-0.5 text-sm/5 font-medium sm:text-xs/5 forced-colors:outline",nt[t])})}u.forwardRef(function({color:s="zinc",className:n,children:a,...o},r){let l=E(n,"group relative inline-flex rounded-md focus:not-data-focus:outline-hidden data-focus:outline-2 data-focus:outline-offset-2 data-focus:outline-blue-500");return typeof o.href=="string"?e.jsx(te,{...o,className:l,ref:r,children:e.jsx(H,{children:e.jsx(y,{color:s,children:a})})}):e.jsx(ee,{...o,className:l,ref:r,children:e.jsx(H,{children:e.jsx(y,{color:s,children:a})})})});function ot(t){u.useEffect(()=>{if(!t)return;const s=t;function n(a){if(!(a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement))switch(a.key){case"1":s({tab:"overview"});break;case"2":s({tab:"mail"});break;case"3":s({tab:"sessions"});break;case"4":s({tab:"work"});break;case"5":s({tab:"connections"});break;case"6":s({tab:"inner"});break;case"7":s({tab:"notes"});break;case"8":s({tab:"runtime"});break;case"Escape":{document.activeElement instanceof HTMLElement&&document.activeElement.blur();break}}}return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[t])}const rt={"owed-reply":"red","blocking-obligation":"red","broken-return":"red","stale-delegation":"yellow","return-ready":"lime","overdue-habit":"yellow"},at={"owed-reply":"owed reply","blocking-obligation":"blocking","broken-return":"broken return","stale-delegation":"stale","return-ready":"ready to return","overdue-habit":"overdue"},it={"owed-reply":"Someone spoke last and is waiting for your response","blocking-obligation":"This obligation is open and blocking forward progress","broken-return":"Work was done but the result was never returned to the requester","stale-delegation":"This was delegated to you and hasn't been addressed","return-ready":"The result is ready — deliver it to close the loop","overdue-habit":"This routine is past its scheduled cadence"},lt=new Set(["stale-delegation"]),ct=new Set(["owed-reply","blocking-obligation","broken-return","return-ready","overdue-habit"]),dt=new Set(["spawning","running","waiting_input","stalled"]);function xt({view:t,deskPrefs:s,refreshGeneration:n}){const a=D(),[o,r]=u.useState(null),[l,f]=u.useState(null),[i,v]=u.useState(null),[c,k]=u.useState(null),[S,g]=u.useState(null),p=t.agent,d=t.work,b=t.inner,C=t.activity,h=p.degraded,N=p.attention,j=d.tasks,A=d.obligations,R=d.sessions,M=d.coding,O=p.senses,m=d.bridges;return u.useEffect(()=>{z(`/agents/${encodeURIComponent(p.agentName)}/needs-me`).then(r),z(`/agents/${encodeURIComponent(p.agentName)}/coding`).then(f),z(`/agents/${encodeURIComponent(p.agentName)}/continuity`).then(v).catch(()=>{}),z(`/agents/${encodeURIComponent(p.agentName)}/orientation`).then(k).catch(()=>{}),z(`/agents/${encodeURIComponent(p.agentName)}/changes`).then(g).catch(()=>{})},[p.agentName,n]),e.jsxs("div",{className:"space-y-6",children:[o&&o.items.length>0&&(()=>{const x=o.items.filter(I=>ct.has(I.urgency)),w=o.items.filter(I=>lt.has(I.urgency));return e.jsxs("div",{className:"space-y-3",children:[x.length>0&&e.jsxs("div",{className:"rounded-xl bg-ouro-fang/5 p-4 ring-1 ring-ouro-fang/15",children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-fang",children:["Action now (",x.length,")"]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:x.map((I,$)=>e.jsx(he,{item:I,nav:a,agentName:p.agentName,onDismiss:()=>{r(L=>L&&{items:L.items.filter((_,Me)=>o.items.indexOf(I)!==Me)})}},`action-${$}`))})]}),w.length>0&&e.jsxs("div",{className:"rounded-xl bg-ouro-gold/5 p-4 ring-1 ring-ouro-gold/15",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-gold",children:["Stale (",w.length,")"]}),e.jsx("button",{onClick:async()=>{var I;for(const $ of w)(I=$.ref)!=null&&I.focus&&await fetch(`/api/agents/${encodeURIComponent(p.agentName)}/dismiss-obligation`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({obligationId:$.ref.focus})});z(`/agents/${encodeURIComponent(p.agentName)}/needs-me`).then(r)},className:"text-xs text-ouro-gold underline underline-offset-2 hover:text-ouro-bone transition-colors",children:"Clear all stale"})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:w.map((I,$)=>e.jsx(he,{item:I,nav:a,agentName:p.agentName,onDismiss:()=>{z(`/agents/${encodeURIComponent(p.agentName)}/needs-me`).then(r)}},`stale-${$}`))})]})]})})(),(s==null?void 0:s.carrying)&&e.jsxs("div",{className:"rounded-xl bg-ouro-moss/10 p-4 ring-1 ring-ouro-glow/8",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-glow",children:"What I'm carrying"}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-ouro-bone",children:s.carrying})]}),(()=>{const x=(s==null?void 0:s.pinnedConstellations)??[];return x.length===0?null:e.jsxs("div",{children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:"Pinned threads"}),e.jsx("div",{className:"mt-2 space-y-2",children:x.map((w,I)=>e.jsxs("div",{className:"rounded-lg bg-ouro-void/40 px-3 py-2.5 ring-1 ring-ouro-moss/15",children:[e.jsx("p",{className:"font-medium text-ouro-bone",children:w.label}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5",children:[w.friendIds.map($=>e.jsxs("button",{onClick:()=>a({tab:"sessions"}),className:"text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2",children:["friend:",$.slice(0,8),"…"]},$)),w.taskRefs.map($=>e.jsxs("button",{onClick:()=>a({tab:"work"}),className:"text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2",children:["task:",$]},$)),w.bridgeIds.map($=>e.jsxs("button",{onClick:()=>a({tab:"connections",focus:$}),className:"text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2",children:["bridge:",$.slice(0,8),"…"]},$))]})]},I))})]})})(),e.jsxs("div",{className:"rounded-xl bg-ouro-moss/15 p-4 ring-1 ring-ouro-glow/10 sm:p-5",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-glow",children:"Center of gravity"}),e.jsx("p",{className:"mt-1 font-display text-xl italic font-semibold text-ouro-bone sm:text-2xl",children:N.label}),e.jsxs("p",{className:"mt-2 text-sm leading-relaxed text-ouro-mist",children:[p.agentName," has"," ",e.jsxs(Z,{tab:"work",children:[j.liveCount," live tasks"]}),","," ",e.jsxs(Z,{tab:"work",children:[A.openCount," obligations"]}),","," ",e.jsxs(Z,{tab:"work",children:[M.activeCount," coding lanes"]}),", and"," ",e.jsxs(Z,{tab:"sessions",children:[R.liveCount," live sessions"]}),"."]}),h.status==="degraded"&&h.issues.length>0&&e.jsxs("div",{className:"mt-3 space-y-1",children:[h.issues.slice(0,5).map((x,w)=>e.jsxs("button",{onClick:()=>a({tab:"runtime"}),className:"flex w-full items-start gap-2 rounded-lg bg-ouro-fang/5 px-3 py-2 text-left text-sm ring-1 ring-ouro-fang/10 hover:ring-ouro-fang/25 transition-colors",children:[e.jsx("span",{className:"mt-0.5 h-2 w-2 shrink-0 rounded-full bg-ouro-fang"}),e.jsxs("span",{className:"text-ouro-mist",children:[e.jsx("span",{className:"font-semibold text-ouro-fang",children:x.code}),e.jsxs("span",{className:"text-ouro-shadow",children:[" — ",U(x.detail,80)]})]})]},w)),h.issues.length>5&&e.jsxs("button",{onClick:()=>a({tab:"runtime"}),className:"text-xs text-ouro-glow underline underline-offset-2",children:["+",h.issues.length-5," more issues"]})]})]}),c&&e.jsxs("div",{className:"rounded-xl bg-ouro-moss/10 p-4 ring-1 ring-ouro-glow/8",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-glow",children:"Orientation"}),(()=>{const x=c.currentSession;return x?e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx(y,{color:"lime",children:"active session"}),e.jsxs("button",{onClick:()=>a({tab:"sessions",focus:`${x.friendId}/${x.channel}/${x.key}`}),className:"text-sm text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2",children:[x.channel,"/",x.key]}),x.lastActivityAt&&e.jsx("span",{className:"text-xs text-ouro-shadow",children:T(x.lastActivityAt)})]}):null})(),c.primaryObligation&&e.jsxs("div",{className:"mt-2 rounded-lg bg-ouro-void/40 px-3 py-2 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{color:"yellow",children:c.primaryObligation.status}),e.jsx("span",{className:"text-sm font-medium text-ouro-bone",children:U(c.primaryObligation.content,80)})]}),c.primaryObligation.nextAction&&e.jsxs("p",{className:"mt-1 text-xs text-ouro-mist",children:["Next: ",c.primaryObligation.nextAction]}),c.primaryObligation.waitingOn&&e.jsxs("p",{className:"mt-0.5 text-xs text-ouro-shadow",children:["Waiting on: ",c.primaryObligation.waitingOn]})]}),c.resumeHandle&&e.jsxs("div",{className:"mt-2 rounded-lg bg-ouro-void/40 px-3 py-2 ring-1 ring-ouro-moss/15",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:"Resume handle"}),e.jsxs("div",{className:"mt-1 space-y-0.5 text-sm",children:[c.resumeHandle.lane&&e.jsxs("p",{className:"text-ouro-bone",children:["Lane: ",c.resumeHandle.lane]}),c.resumeHandle.artifact&&e.jsxs("p",{className:"text-ouro-mist",children:["Artifact: ",c.resumeHandle.artifact]}),c.resumeHandle.nextAction&&e.jsxs("p",{className:"text-ouro-mist",children:["Next: ",c.resumeHandle.nextAction]}),c.resumeHandle.blockerOrWaitingOn&&e.jsxs("p",{className:"text-ouro-shadow",children:["Blocked: ",c.resumeHandle.blockerOrWaitingOn]}),e.jsxs(y,{color:c.resumeHandle.confidence==="high"?"lime":c.resumeHandle.confidence==="medium"?"yellow":"zinc",children:[c.resumeHandle.confidence," confidence"]})]})]}),c.otherActiveSessions.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-wider text-ouro-shadow",children:["Other sessions (",c.otherActiveSessions.length,")"]}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:c.otherActiveSessions.slice(0,5).map(x=>e.jsx("button",{onClick:()=>a({tab:"sessions",focus:`${x.friendId}/${x.channel}/${x.key}`}),className:"text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2",children:x.friendName},`${x.friendId}/${x.channel}/${x.key}`))})]})]}),S&&S.changeCount>0&&e.jsxs("div",{className:"rounded-xl bg-ouro-gold/5 p-4 ring-1 ring-ouro-gold/15",children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-gold",children:["What changed (",S.changeCount,")"]}),S.snapshotAge&&e.jsxs("p",{className:"mt-0.5 text-xs text-ouro-shadow",children:["Since ",T(S.snapshotAge)]}),e.jsxs("div",{className:"mt-2 space-y-1",children:[S.items.slice(0,8).map((x,w)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(y,{color:x.kind.includes("status")?"yellow":"zinc",children:x.kind.replace(/_/g," ")}),e.jsx("span",{className:"truncate text-ouro-mist",children:x.summary})]},w)),S.items.length>8&&e.jsxs("p",{className:"text-xs text-ouro-shadow",children:["+",S.items.length-8," more changes"]})]})]}),i&&e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl bg-ouro-void/50 p-4 ring-1 ring-ouro-moss/20",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-glow",children:"Presence"}),i.presence.self?e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-ouro-bone",children:i.presence.self.availability}),i.presence.self.lane&&e.jsxs("p",{className:"text-xs text-ouro-shadow",children:["Lane: ",i.presence.self.lane]}),i.presence.self.tempo&&e.jsxs("p",{className:"text-xs text-ouro-shadow",children:["Tempo: ",i.presence.self.tempo]})]}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No presence data"}),i.presence.peers.length>0&&e.jsxs("div",{className:"mt-2 border-t border-ouro-moss/20 pt-2",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-ouro-shadow",children:"Peers"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:i.presence.peers.map(x=>e.jsx(y,{color:x.availability==="active"?"lime":"zinc",children:x.agentName},x.agentName))})]})]}),e.jsxs("div",{className:"rounded-xl bg-ouro-void/50 p-4 ring-1 ring-ouro-moss/20",children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-glow",children:["Cares (",i.cares.activeCount,")"]}),i.cares.items.length>0?e.jsx("div",{className:"mt-2 space-y-1.5",children:i.cares.items.slice(0,5).map(x=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{color:x.salience==="high"?"red":x.salience==="medium"?"yellow":"zinc",children:x.salience}),e.jsx("p",{className:"truncate text-sm text-ouro-bone",children:x.label})]},x.id))}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No active cares"})]}),e.jsxs("div",{className:"rounded-xl bg-ouro-void/50 p-4 ring-1 ring-ouro-moss/20",children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-glow",children:["Episodes (",i.episodes.recentCount,")"]}),i.episodes.items.length>0?e.jsx("div",{className:"mt-2 space-y-1.5",children:i.episodes.items.slice(0,5).map(x=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(y,{color:"zinc",children:x.kind}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm text-ouro-bone",children:x.summary}),e.jsx("p",{className:"text-xs text-ouro-shadow",children:T(x.timestamp)})]})]},x.id))}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No recent episodes"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsx(X,{label:"Tasks",value:j.liveCount,sub:`${j.blockedCount} blocked`,onClick:()=>a({tab:"work"})}),e.jsx(X,{label:"Obligations",value:A.openCount,sub:`${R.liveCount} sessions`,onClick:()=>a({tab:"work"})}),e.jsx(X,{label:"Coding",value:M.activeCount,sub:`${M.blockedCount} blocked`,onClick:()=>a({tab:"work"})}),e.jsx(X,{label:"Inner",value:b.status,sub:U(b.summary??"",30),onClick:()=>a({tab:"inner"})})]}),l&&l.items.length>0&&(()=>{const x=l.items.filter(w=>dt.has(w.status));return x.length===0?null:e.jsx(P,{title:`Active coding (${x.length})`,children:e.jsx("div",{className:"space-y-1.5",children:x.map(w=>e.jsxs("button",{onClick:()=>a({tab:"work"}),className:"flex w-full items-center gap-2 rounded-lg bg-ouro-void/40 px-3 py-2 text-left ring-1 ring-ouro-moss/15 hover:ring-ouro-glow/20 transition-colors",children:[e.jsx(y,{color:w.status==="running"?"lime":w.status==="waiting_input"?"yellow":"zinc",children:w.status}),e.jsxs("span",{className:"truncate text-sm text-ouro-bone",children:[w.runner," — ",U(w.workdir,40)]}),e.jsx("span",{className:"shrink-0 text-xs text-ouro-shadow",children:T(w.lastActivityAt)})]},w.id))})})})(),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(P,{title:"Senses",children:O.length>0?e.jsx(ut,{items:O}):e.jsx(se,{children:"No active senses"})}),e.jsx(P,{title:"Bridges",children:m.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:m.map(x=>e.jsx("button",{onClick:()=>a({tab:"connections",focus:x}),children:e.jsx(y,{color:"lime",children:x})},x))}):e.jsx(se,{children:"No active bridges"})})]}),(()=>{const x=A.items.filter(w=>w.status==="fulfilled");return x.length===0?null:e.jsx(P,{title:"Recently closed",children:e.jsx("div",{className:"space-y-1",children:x.slice(0,3).map((w,I)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg px-3 py-2 bg-ouro-glow/5 ring-1 ring-ouro-glow/10",children:[e.jsx(y,{color:"lime",children:"closed"}),e.jsx("p",{className:"text-sm text-ouro-mist truncate",children:U(w.content,80)}),e.jsx("span",{className:"shrink-0 text-xs text-ouro-shadow",children:T(w.updatedAt)})]},I))})})})(),e.jsx(P,{title:"Recent activity",children:C.recent.length>0?e.jsx("div",{className:"space-y-1",children:C.recent.map((x,w)=>{const I=x.kind==="coding"||x.kind==="obligation"?"work":x.kind==="session"?"sessions":"inner";return e.jsxs("button",{onClick:()=>a({tab:I}),className:"flex w-full flex-col gap-0.5 rounded-lg px-3 py-2.5 text-left hover:bg-ouro-moss/10 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{children:x.kind}),e.jsx("span",{className:"text-xs text-ouro-shadow",children:T(x.at)})]}),e.jsx("p",{className:"truncate text-sm font-medium text-ouro-bone",children:U(x.label,100)}),e.jsx("p",{className:"truncate text-xs text-ouro-shadow",children:U(x.detail,80)})]},w)})}):e.jsx(se,{children:"No recent activity yet."})})]})}function he({item:t,nav:s,agentName:n,onDismiss:a}){var l;const o=t.urgency==="return-ready",r=(l=t.ref)==null?void 0:l.focus;return e.jsxs("div",{className:`flex w-full items-start gap-2.5 rounded-lg px-3 py-2.5 text-left ring-1 transition-colors ${o?"bg-ouro-glow/5 ring-ouro-glow/15":"bg-ouro-void/40 ring-ouro-moss/10"}`,children:[e.jsxs("button",{onClick:()=>t.ref&&s({tab:t.ref.tab,focus:t.ref.focus}),className:"flex min-w-0 flex-1 items-start gap-2.5",children:[e.jsx(y,{color:rt[t.urgency]??"zinc",children:at[t.urgency]??t.urgency}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-sm font-medium ${o?"text-ouro-glow":"text-ouro-bone"}`,children:t.label}),e.jsx("p",{className:"text-xs text-ouro-shadow truncate",children:t.detail}),e.jsx("p",{className:"text-[10px] italic text-ouro-shadow/60 mt-0.5",children:it[t.urgency]??""})]}),t.ageMs!=null&&e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-ouro-shadow",children:t.ageMs<36e5?`${Math.floor(t.ageMs/6e4)}m`:t.ageMs<864e5?`${Math.floor(t.ageMs/36e5)}h`:`${Math.floor(t.ageMs/864e5)}d`})]}),r&&e.jsx("button",{onClick:async f=>{f.stopPropagation(),await fetch(`/api/agents/${encodeURIComponent(n)}/dismiss-obligation`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({obligationId:r})}),a()},className:"shrink-0 text-xs text-ouro-shadow hover:text-ouro-fang transition-colors",title:"Dismiss",children:"✕"})]})}function Z({tab:t,children:s}){const n=D();return e.jsx("button",{onClick:()=>n({tab:t}),className:"text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow transition-colors",children:s})}function X({label:t,value:s,sub:n,onClick:a}){return e.jsxs("button",{onClick:a,className:"rounded-xl bg-ouro-void/50 p-3 text-left ring-1 ring-ouro-moss/20 hover:ring-ouro-glow/20 transition-all",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-ouro-shadow",children:t}),e.jsx("p",{className:"mt-1 text-xl font-semibold tabular-nums text-ouro-bone",children:s}),e.jsx("p",{className:"mt-0.5 truncate text-xs text-ouro-shadow",children:n})]})}function P({title:t,children:s}){return e.jsxs("div",{children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:t}),e.jsx("div",{className:"mt-2",children:s})]})}function ut({items:t}){return e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(s=>e.jsx(y,{color:"lime",children:s},s))})}function se({children:t}){return e.jsx("p",{className:"text-sm text-ouro-shadow",children:t})}function J(t){return t.length>0?t.join(", "):"(unknown)"}function mt(t,s){if(s==="all")return!0;if(["imbox","screener","discarded","quarantine"].includes(s))return t.placement===s;if(s==="native"||s==="delegated")return t.compartmentKind===s;if(s.startsWith("source:")){const n=s.slice(7),a=n.indexOf(":");if(a===-1)return t.source===n;const o=n.slice(0,a),r=n.slice(a+1);return t.source===o&&(t.ownerEmail??"unknown-owner")===r}return!1}function ze(t){return t.subject||"(no subject)"}function ht(t,s){return{status:"error",agentName:t,mailboxAddress:null,generatedAt:new Date().toISOString(),store:null,folders:[],messages:[],screener:[],outbound:[],recovery:{discardedCount:0,quarantineCount:0,undecryptableCount:0,missingKeyIds:[]},accessLog:[],error:s}}function pt(t,s,n){return{status:"error",agentName:t,mailboxAddress:s,generatedAt:new Date().toISOString(),message:null,accessLog:[],error:n}}function Ie(t){return t.provenance.compartmentKind==="delegated"?`delegated human mailbox · ${t.provenance.ownerEmail??"unknown owner"} / ${t.provenance.source??"unknown source"}`:"native agent mailbox"}function gt(t){return t.mailboxRole==="delegated-human-mailbox"?`delegated human mailbox · ${t.ownerEmail??"unknown owner"} / ${t.source??"unknown source"}`:t.mailboxRole==="agent-native-mailbox"?"native agent mailbox":"mailbox"}function bt(t){return t.sendAuthority==="agent-native"?"native agent mailbox":t.mailboxRole}function ft(t){return t.transport??t.provider??"not sent"}function vt(t){return t.deliveredAt??t.failedAt??t.acceptedAt??t.sentAt??t.submittedAt??t.updatedAt}function xe(t){return t==="screener"?"bg-[#fff7d6] text-[#6f5200] ring-[#e7c85c]":t==="discarded"||t==="quarantine"?"bg-[#ffe8e2] text-[#8a2f1f] ring-[#ef9a84]":t==="sent"?"bg-[#dff7ea] text-[#17613a] ring-[#82caa1]":t==="draft"?"bg-[#e7ecff] text-[#263f95] ring-[#a7b5f5]":"bg-[#e9f3ef] text-[#1e5840] ring-[#9fc7b5]"}function jt(t){return(t==null?void 0:t.messages.length)??0}function wt({agentName:t,focus:s,onFocusConsumed:n,refreshGeneration:a}){var C;const[o,r]=u.useState(null),[l,f]=u.useState("all"),[i,v]=u.useState(s??null),[c,k]=u.useState(null),[S,g]=u.useState(!1);u.useEffect(()=>{f("all"),v(s??null),k(null)},[t]),u.useEffect(()=>{r(null),z(`/agents/${encodeURIComponent(t)}/mail`).then(r).catch(()=>r(ht(t,"mail unavailable")))},[t,a]),u.useEffect(()=>{s&&(v(s),n==null||n())},[s,n]),u.useEffect(()=>{if(!i){k(null);return}g(!0),z(`/agents/${encodeURIComponent(t)}/mail/${encodeURIComponent(i)}`).then(k).catch(()=>k(pt(t,(o==null?void 0:o.mailboxAddress)??null,"message unavailable"))).finally(()=>g(!1))},[t,i,a]);const p=u.useMemo(()=>{const h=(o==null?void 0:o.folders)??[];return[{id:"all",label:"All",count:jt(o)},...h]},[o]),d=u.useMemo(()=>((o==null?void 0:o.messages)??[]).filter(h=>mt(h,l)),[l,o]),b=u.useMemo(()=>l!=="draft"&&l!=="sent"?[]:((o==null?void 0:o.outbound)??[]).filter(h=>l==="draft"?h.status==="draft":h.status!=="draft"),[l,o]);return o?o.status!=="ready"?e.jsx("div",{className:"mailbox-shell grid min-h-[58vh] place-items-center rounded-md bg-[#f2f6ef] p-8 text-[#1f2720] ring-1 ring-black/10",children:e.jsxs("div",{className:"max-w-lg text-center",children:[e.jsx("p",{className:"text-sm font-semibold text-[#667067]",children:"Mailbox"}),e.jsx("h2",{className:"mt-2 text-2xl font-semibold",children:o.status==="auth-required"?"Locked":"Unavailable"}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-[#59645c]",children:o.error})]})}):e.jsxs("div",{className:"mailbox-shell overflow-hidden rounded-md bg-[#f2f6ef] text-[#172018] ring-1 ring-black/10",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[#cbd8c8] bg-[#e4ecdf] px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold text-[#687062]",children:"Agent mailbox"}),e.jsx("p",{className:"truncate text-sm text-[#2d3a30]",children:o.mailboxAddress})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{color:"zinc",children:"read-only"}),e.jsxs("span",{className:"text-xs tabular-nums text-[#687062]",children:[o.messages.length," messages"]}),e.jsxs("span",{className:"text-xs tabular-nums text-[#687062]",children:[o.outbound.length," outbound"]})]})]}),e.jsxs("div",{className:"grid min-h-[66vh] grid-cols-1 lg:grid-cols-[14.5rem_minmax(19rem,25rem)_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"border-b border-[#cbd8c8] bg-[#e4ecdf] p-3 lg:border-b-0 lg:border-r",children:[e.jsx(Nt,{folders:p,activeFolder:l,setActiveFolder:f}),e.jsx(yt,{discarded:o.recovery.discardedCount,quarantine:o.recovery.quarantineCount,undecryptable:o.recovery.undecryptableCount,missingKeyIds:o.recovery.missingKeyIds}),e.jsx(kt,{candidates:o.screener,onOpen:h=>{f("screener"),v(h)}}),e.jsx(Ct,{entries:o.accessLog})]}),e.jsxs("section",{className:"border-b border-[#cbd8c8] bg-[#fbfdf8] lg:border-b-0 lg:border-r",children:[e.jsxs("div",{className:"border-b border-[#d8e2d4] px-4 py-3",children:[e.jsx("p",{className:"text-sm font-semibold text-[#172018]",children:((C=p.find(h=>h.id===l))==null?void 0:C.label)??"All"}),e.jsx("p",{className:"text-xs text-[#687062]",children:b.length>0?`${b.length} outbound records`:`${d.length} messages`})]}),e.jsxs("div",{className:"max-h-[66vh] overflow-y-auto",children:[b.map(h=>e.jsx($t,{record:h},h.id)),b.length===0&&d.map(h=>e.jsx(St,{message:h,selected:i===h.id,onSelect:()=>v(h.id)},h.id)),b.length===0&&d.length===0&&e.jsx("div",{className:"px-4 py-10 text-center text-sm text-[#687062]",children:"No records here."})]})]}),e.jsxs("main",{className:"min-w-0 bg-[#fbfdf8]",children:[!i&&e.jsx(It,{}),i&&S&&e.jsx(pe,{label:"Opening message"}),i&&!S&&(c==null?void 0:c.status)!=="ready"&&e.jsx("div",{className:"grid min-h-[54vh] place-items-center p-8 text-center",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-[#172018]",children:"Message unavailable"}),e.jsx("p",{className:"mt-2 text-sm text-[#687062]",children:c==null?void 0:c.error})]})}),(c==null?void 0:c.status)==="ready"&&c.message&&e.jsx(zt,{detail:c})]})]})]}):e.jsx(pe,{label:"Opening mailbox"})}function Nt({folders:t,activeFolder:s,setActiveFolder:n}){return e.jsx("div",{className:"space-y-1",children:t.map(a=>e.jsxs("button",{type:"button",onClick:()=>n(a.id),className:`flex h-9 w-full items-center justify-between rounded px-3 text-left text-sm transition-colors ${s===a.id?"bg-[#fbfdf8] text-[#172018] shadow-sm":"text-[#536157] hover:bg-[#fbfdf8]/65"}`,children:[e.jsx("span",{className:"truncate",children:a.label}),e.jsx("span",{className:"text-xs tabular-nums text-[#687062]",children:a.count})]},a.id))})}function yt({discarded:t,quarantine:s,undecryptable:n,missingKeyIds:a}){return e.jsxs("div",{className:"mt-5 border-t border-[#cbd8c8] pt-4",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#687062]",children:"Recovery drawers"}),e.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"rounded border border-[#cbd8c8] bg-[#fbfdf8] px-3 py-2",children:[e.jsx("p",{className:"text-xs text-[#687062]",children:"Discarded"}),e.jsx("p",{className:"text-lg font-semibold tabular-nums text-[#172018]",children:t})]}),e.jsxs("div",{className:"rounded border border-[#cbd8c8] bg-[#fbfdf8] px-3 py-2",children:[e.jsx("p",{className:"text-xs text-[#687062]",children:"Quarantine"}),e.jsx("p",{className:"text-lg font-semibold tabular-nums text-[#172018]",children:s})]}),e.jsxs("div",{className:"rounded border border-[#cbd8c8] bg-[#fbfdf8] px-3 py-2",children:[e.jsx("p",{className:"text-xs text-[#687062]",children:"Undecryptable"}),e.jsx("p",{className:"text-lg font-semibold tabular-nums text-[#172018]",children:n})]})]}),n>0&&e.jsxs("p",{className:"mt-2 text-[11px] leading-4 text-[#687062]",children:["missing key ",a[0],a.length>1?` +${a.length-1} more`:""]})]})}function kt({candidates:t,onOpen:s}){return e.jsxs("div",{className:"mt-5 border-t border-[#cbd8c8] pt-4",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#687062]",children:"Screener"}),e.jsxs("div",{className:"mt-2 space-y-2",children:[t.slice(0,5).map(n=>e.jsxs("button",{type:"button",onClick:()=>s(n.messageId),className:"block w-full rounded border border-[#cbd8c8] bg-[#fbfdf8] px-3 py-2 text-left hover:border-[#9fb8a7]",children:[e.jsx("p",{className:"truncate text-xs font-semibold text-[#172018]",children:n.senderEmail}),e.jsx("p",{className:"mt-1 truncate text-xs text-[#687062]",children:n.trustReason})]},n.id)),t.length===0&&e.jsx("p",{className:"text-xs text-[#687062]",children:"No pending senders."})]})]})}function Ct({entries:t}){return e.jsxs("div",{className:"mt-5 border-t border-[#cbd8c8] pt-4",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#687062]",children:"Access audit"}),e.jsxs("div",{className:"mt-2 space-y-2",children:[t.slice(0,4).map(s=>e.jsxs("div",{className:"text-xs leading-4 text-[#687062]",children:[e.jsx("p",{className:"truncate font-medium text-[#3f4b42]",children:s.tool}),e.jsx("p",{className:"truncate",children:gt(s)}),e.jsx("p",{className:"truncate",children:s.reason})]},s.id)),t.length===0&&e.jsx("p",{className:"text-xs text-[#687062]",children:"No reads yet."})]})]})}function St({message:t,selected:s,onSelect:n}){return e.jsxs("button",{type:"button",onClick:n,className:`block w-full border-b border-[#d8e2d4] px-4 py-3 text-left transition-colors ${s?"bg-[#eaf4ee]":"hover:bg-[#eef4ec]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("p",{className:"min-w-0 truncate text-sm font-semibold text-[#172018]",children:J(t.from)}),e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-[#687062]",children:T(t.receivedAt)})]}),e.jsx("p",{className:"mt-1 truncate text-sm text-[#26352a]",children:ze(t)}),e.jsx("p",{className:"mt-1 line-clamp-2 text-xs leading-5 text-[#687062]",children:U(t.snippet,150)}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`rounded px-2 py-0.5 text-[11px] ring-1 ${xe(t.placement)}`,children:t.placement}),e.jsx("span",{className:"truncate text-[11px] text-[#687062]",children:Ie(t)})]})]})}function $t({record:t}){const s=t.deliveryEvents[t.deliveryEvents.length-1];return e.jsxs("div",{className:"border-b border-[#d8e2d4] px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("p",{className:"min-w-0 truncate text-sm font-semibold text-[#172018]",children:t.subject||"(no subject)"}),e.jsx("span",{className:`shrink-0 rounded px-2 py-0.5 text-[11px] ring-1 ${xe(t.status)}`,children:t.status})]}),e.jsxs("p",{className:"mt-1 truncate text-xs text-[#536157]",children:["to ",J(t.to)]}),e.jsxs("p",{className:"mt-1 text-xs text-[#687062]",children:[ft(t)," · ",T(vt(t))]}),e.jsxs("p",{className:"mt-1 truncate text-xs text-[#687062]",children:[bt(t)," · ",t.sendMode??"mode unknown",t.policyDecision?` · policy ${t.policyDecision.code} / ${t.policyDecision.fallback}`:""]}),(t.providerMessageId||t.providerRequestId)&&e.jsxs("p",{className:"mt-1 truncate text-xs text-[#687062]",children:["provider ",t.providerMessageId??"unknown",t.providerRequestId?` · request ${t.providerRequestId}`:""]}),s&&e.jsx("p",{className:"mt-1 line-clamp-2 text-xs leading-5 text-[#687062]",children:s.bodySafeSummary})]})}function zt({detail:t}){const s=t.message;return e.jsxs("article",{className:"min-h-[66vh]",children:[e.jsxs("header",{className:"border-b border-[#cbd8c8] bg-[#fbfdf8] px-6 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsx("h2",{className:"min-w-0 text-xl font-semibold leading-tight text-[#172018]",children:ze(s)}),e.jsx("span",{className:`rounded px-2 py-0.5 text-xs ring-1 ${xe(s.placement)}`,children:s.placement})]}),e.jsxs("div",{className:"mt-4 grid gap-1 text-sm text-[#536157]",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-[#172018]",children:"From:"})," ",J(s.from)]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-[#172018]",children:"To:"})," ",J(s.to)]}),s.cc.length>0&&e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-[#172018]",children:"Cc:"})," ",J(s.cc)]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-[#172018]",children:"Received:"})," ",new Date(s.receivedAt).toLocaleString()]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-[#172018]",children:"Provenance:"})," ",Ie(s)]})]})]}),e.jsx("div",{className:"border-b border-[#f0d0bd] bg-[#fff4e4] px-6 py-3 text-sm text-[#8a4a18]",children:s.untrustedContentWarning}),e.jsxs("div",{className:"px-6 py-6",children:[e.jsx("pre",{className:"whitespace-pre-wrap break-words font-body text-sm leading-7 text-[#26352a]",children:s.text||"(no text body)"}),s.bodyTruncated&&e.jsx("p",{className:"mt-4 text-xs text-[#687062]",children:"Body truncated in Mailbox."}),e.jsxs("div",{className:"mt-6 grid gap-3 border-t border-[#cbd8c8] pt-4 text-xs text-[#687062] md:grid-cols-2",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-[#172018]",children:"Read reason:"})," ",s.access.reason]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-[#172018]",children:"Read at:"})," ",new Date(s.access.accessedAt).toLocaleString()]})]}),s.attachments.length>0&&e.jsxs("div",{className:"mt-6 border-t border-[#cbd8c8] pt-4",children:[e.jsx("p",{className:"text-xs font-semibold text-[#687062]",children:"Attachments"}),e.jsx("div",{className:"mt-2 space-y-2",children:s.attachments.map(n=>e.jsxs("div",{className:"rounded border border-[#cbd8c8] bg-[#fbfdf8] px-3 py-2 text-sm text-[#3f4b42]",children:[n.filename," · ",n.contentType," · ",n.size.toLocaleString()," bytes"]},`${n.filename}-${n.size}`))})]})]})]})}function It(){return e.jsx("div",{className:"grid min-h-[54vh] place-items-center p-8 text-center",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-[#172018]",children:"No message selected"}),e.jsx("p",{className:"mt-2 text-sm text-[#687062]",children:"Reading pane idle."})]})})}function pe({label:t}){return e.jsxs("div",{className:"flex items-center gap-2 p-6",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-[#2f8f4e]"}),e.jsxs("span",{className:"text-xs text-[#687062]",children:[t,"..."]})]})}function ce(t){const s=t.function.name,n=At(t.function.arguments);return s==="settle"?{kind:"response",name:s,id:t.id,deliveredText:n.answer??null,delegatedThought:null,metadata:n.intent??null,rawArgs:null}:s==="ponder"?{kind:"delegation",name:s,id:t.id,deliveredText:n.say??null,delegatedThought:n.thought??null,metadata:null,rawArgs:null}:s==="rest"?{kind:"rest",name:s,id:t.id,deliveredText:null,delegatedThought:null,metadata:null,rawArgs:null}:s==="observe"?{kind:"observe",name:s,id:t.id,deliveredText:null,delegatedThought:null,metadata:n.reason??null,rawArgs:null}:s==="surface"?{kind:"surface",name:s,id:t.id,deliveredText:n.content??null,delegatedThought:null,metadata:n.delegationId??n.friendId??null,rawArgs:null}:{kind:"action",name:s,id:t.id,deliveredText:null,delegatedThought:null,metadata:null,rawArgs:t.function.arguments}}function At(t){try{const s=JSON.parse(t);if(s&&typeof s=="object")return s}catch{}return{}}const Tt=48;function Rt(t){return t.scrollHeight-t.scrollTop-t.clientHeight<=Tt}function Ae(t){const s=u.useRef(null),n=u.useRef(!0),a=u.useCallback(()=>{const r=s.current;r&&(n.current=Rt(r))},[]),o=u.useCallback(()=>{n.current=!1},[]);return u.useEffect(()=>{const r=s.current;!r||!n.current||(r.scrollTop=r.scrollHeight)},[t]),{ref:s,onScroll:a,preserveScroll:o}}function Et(t){return typeof t=="string"?t:Array.isArray(t)?t.map(s=>s.type==="text"&&typeof s.text=="string"?s.text:"").filter(s=>s.length>0).join(""):""}function Y(t){return Et(t.content)}function Te(t){return t.time.authoredAt??t.time.observedAt??t.time.recordedAt}const ge={"needs-reply":{color:"red",label:"needs reply"},"on-hold":{color:"yellow",label:"on hold"},monitoring:{color:"zinc",label:"monitoring"},idle:{color:"zinc",label:"idle"}};function Re(t){return t==="bluebubbles"?"iMessage":t==="teams"?"Teams":t==="cli"?"CLI":t==="mail"?"Mail":t==="voice"?"Voice":t}function Lt(t){return t==="bluebubbles"?"imessage":t==="teams"?"teams":t==="cli"?"terminal":"default"}function Ot(t){return t==="imessage"?"overflow-hidden rounded-xl bg-[#f5f5f7] text-[#1d1d1f] ring-1 ring-black/10":t==="teams"?"overflow-hidden rounded-xl bg-[#f7f5ff] text-[#242424] ring-1 ring-[#d8d1ff]":t==="terminal"?"overflow-hidden rounded-lg bg-[#050807] font-mono text-[#d1fae5] ring-1 ring-[#1f3a2c]":"overflow-hidden rounded-lg bg-ouro-void/60 text-ouro-bone ring-1 ring-ouro-moss/15"}function Mt(t){return t==="imessage"?"border-b border-black/10 bg-[#fbfbfd] px-4 py-3 text-center":t==="teams"?"border-b border-[#d8d1ff] bg-[#4f3bb3] px-4 py-3 text-white":t==="terminal"?"border-b border-[#1f3a2c] bg-[#101815] px-4 py-2 text-[#86efac]":"border-b border-ouro-moss/15 px-4 py-3"}function Ut(t){return t==="imessage"?"max-w-[85%] sm:max-w-[75%] rounded-2xl rounded-bl-md bg-[#e9e9eb] px-3.5 py-2 text-[#1d1d1f]":t==="teams"?"max-w-[85%] sm:max-w-[75%] rounded-md bg-white px-3.5 py-2 text-[#242424] shadow-sm ring-1 ring-[#e5e5e5]":t==="terminal"?"max-w-full rounded-none border-l-2 border-[#60a5fa] bg-transparent px-3 py-2 text-[#dbeafe]":"max-w-[85%] sm:max-w-[75%] rounded-2xl rounded-bl-sm bg-ouro-moss/25 px-3.5 py-2 ring-1 ring-ouro-moss/15"}function G(t,s="normal"){return t==="imessage"?"max-w-[85%] sm:max-w-[75%] rounded-2xl rounded-br-md bg-[#0a84ff] px-3.5 py-2 text-white":t==="teams"?"max-w-[85%] sm:max-w-[75%] rounded-md bg-[#ede9fe] px-3.5 py-2 text-[#242424] shadow-sm ring-1 ring-[#c4b5fd]":t==="terminal"?"max-w-full rounded-none border-l-2 border-[#22c55e] bg-transparent px-3 py-2 text-[#bbf7d0]":s==="surface"?"max-w-[85%] sm:max-w-[75%] rounded-2xl rounded-br-sm bg-ouro-scale/12 px-3.5 py-2 ring-1 ring-ouro-scale/15":"max-w-[85%] sm:max-w-[75%] rounded-2xl rounded-br-sm bg-ouro-glow/8 px-3.5 py-2 ring-1 ring-ouro-glow/12"}function K(t,s){return t==="imessage"?s==="agent"?"font-mono text-[9px] text-white/70":"font-mono text-[9px] text-[#6b7280]":t==="teams"?"font-mono text-[9px] uppercase tracking-wider text-[#5b5fc7]":t==="terminal"?s==="agent"?"font-mono text-[11px] text-[#22c55e]":"font-mono text-[11px] text-[#60a5fa]":s==="surface"||s==="agent"?"font-mono text-[9px] uppercase tracking-wider text-ouro-glow/70":"font-mono text-[9px] uppercase tracking-wider text-ouro-gold/70"}function Q(t,s="agent"){return t==="imessage"?"text-sm leading-relaxed whitespace-pre-wrap break-words":t==="teams"?"text-sm leading-relaxed text-[#242424] whitespace-pre-wrap break-words":t==="terminal"?`font-mono text-[12px] leading-6 whitespace-pre-wrap break-words ${s==="agent"?"text-[#bbf7d0]":"text-[#dbeafe]"}`:"text-sm leading-relaxed text-ouro-bone whitespace-pre-wrap break-words"}function Ht(t){return Te(t)}function B(t){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(Ht(t)))}function _t({agentName:t,focus:s,onFocusConsumed:n,deskPrefs:a,refreshGeneration:o}){D();const[r,l]=u.useState(null),[f,i]=u.useState(null),[v,c]=u.useState(null),[k,S]=u.useState(!1),g=u.useRef(null);u.useEffect(()=>{z(`/agents/${encodeURIComponent(t)}/sessions`).then(l)},[t,o]),u.useEffect(()=>{s&&(g.current=null,i(s),c(null),S(!0),n==null||n())},[t,s,n]),u.useEffect(()=>{if(!f)return;const j=`${f}:${o}`;if(g.current===j)return;g.current=j,S(!0);const[A,R,M]=f.split("/");z(`/agents/${encodeURIComponent(t)}/sessions/${encodeURIComponent(A)}/${encodeURIComponent(R)}/${encodeURIComponent(M)}`).then(c).catch(()=>c(null)).finally(()=>S(!1))},[t,f,o,s]);function p(j){if(f===j){i(null),c(null),g.current=null;return}i(j),c(null),S(!0)}const d=new Set((a==null?void 0:a.starredFriends)??[]);if(!r)return e.jsx(Ee,{label:"Loading sessions"});const b=new Map;for(const j of r.items)b.has(j.friendId)||b.set(j.friendId,[]),b.get(j.friendId).push(j);const C=[...b.entries()].sort((j,A)=>{const R=d.has(j[0])?0:1,M=d.has(A[0])?0:1;return R!==M?R-M:A[1].length-j[1].length}),h=[],N=new Map;for(const[j,A]of C)N.set(h.length,{name:A[0].friendName,channels:A.length,starred:d.has(j)}),h.push(...A);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:[r.totalCount," sessions · ",r.activeCount," active · ",r.staleCount," stale"]}),e.jsx("div",{className:"space-y-1.5",children:h.map((j,A)=>{var L;const R=N.get(A),M=d.has(j.friendId),O=`${j.friendId}/${j.channel}/${j.key}`,m=f===O,x=ge[j.replyState]??ge.idle,w=((L=j.lastUsage)==null?void 0:L.total_tokens)??j.estimatedTokens??0,$=w>0?Math.min(100,Math.round(w/8e4*100)):0;return e.jsxs("div",{children:[R&&R.channels>1&&e.jsxs("div",{className:"flex items-center gap-2 pt-3 pb-1",children:[R.starred&&e.jsx("span",{className:"text-ouro-gold text-sm",children:"★"}),e.jsx("span",{className:"font-medium text-ouro-bone text-sm",children:R.name}),e.jsxs("span",{className:"text-xs text-ouro-shadow",children:[R.channels," channels"]})]}),e.jsxs("button",{onClick:()=>p(O),className:`flex w-full flex-col gap-1.5 rounded-lg px-3 py-3 text-left transition-colors ring-1 ${m?"bg-ouro-moss/15 ring-ouro-glow/20":"ring-ouro-moss/15 hover:bg-ouro-moss/8"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[M&&e.jsx("span",{className:"text-ouro-gold",title:"Starred",children:"★"}),e.jsx("span",{className:"truncate font-medium text-ouro-bone",children:j.friendName}),e.jsxs("span",{className:"shrink-0 text-xs text-ouro-shadow",children:["via ",Re(j.channel)]}),e.jsx(y,{color:x.color,children:x.label})]}),e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-ouro-shadow",children:T(j.lastActivityAt)})]}),j.latestUserExcerpt&&e.jsxs("p",{className:"truncate text-xs text-ouro-gold/70",children:[e.jsx("span",{className:"font-mono text-[9px] uppercase tracking-wider",children:"in:"})," ",U(j.latestUserExcerpt,100)]}),j.latestAssistantExcerpt&&e.jsxs("p",{className:"truncate text-xs text-ouro-glow/60",children:[e.jsx("span",{className:"font-mono text-[9px] uppercase tracking-wider",children:"out:"})," ",U(j.latestAssistantExcerpt,100)]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-ouro-shadow",children:[e.jsxs("span",{className:"tabular-nums",children:[j.messageCount," msgs"]}),j.lastUsage&&e.jsxs("span",{className:"tabular-nums",children:[j.lastUsage.total_tokens.toLocaleString()," tok"]}),$>0&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-1 max-w-32",title:"Context pressure — steady state oscillates between 80-100%",children:[e.jsx("div",{className:"h-1 flex-1 rounded-full bg-ouro-moss/20",children:e.jsx("div",{className:`h-1 rounded-full transition-all ${$>100?"bg-ouro-fang":$>80?"bg-ouro-gold":"bg-ouro-glow"}`,style:{width:`${Math.min(100,$)}%`}})}),e.jsxs("span",{className:"tabular-nums text-[10px]",children:[$,"%"]})]})]})]}),m&&e.jsx(qt,{loading:k,transcript:v})]},O)})})]})}function qt({loading:t,transcript:s}){var r;const n=((r=s==null?void 0:s.messages[s.messages.length-1])==null?void 0:r.id)??null,{ref:a,onScroll:o}=Ae(n);return e.jsxs("div",{ref:a,"data-testid":"session-transcript-scroll",onScroll:o,className:"mt-1 max-h-[70vh] overflow-y-auto rounded-lg",children:[t&&!s&&e.jsx(Ee,{label:"Loading transcript"}),s&&e.jsx(Bt,{transcript:s})]})}function Bt({transcript:t}){const{messages:s,lastUsage:n}=t,a=Lt(t.channel),o=s.filter(v=>v.role==="system"),r=s.filter(v=>v.role!=="system"),[l,f]=u.useState(!1),i=new Map;for(const v of r)v.role==="tool"&&v.toolCallId&&i.set(v.toolCallId,v);return e.jsxs("div",{className:Ot(a),children:[e.jsxs("div",{className:Mt(a),children:[e.jsx("p",{className:a==="terminal"?"font-mono text-xs":"text-sm font-semibold",children:Re(t.channel)}),e.jsxs("p",{className:a==="terminal"?"mt-0.5 font-mono text-[10px] text-[#6ee7b7]":"mt-0.5 text-xs opacity-70",children:[t.friendName," · ",t.messageCount," messages"]})]}),e.jsxs("div",{className:"space-y-0.5 p-3",children:[n&&e.jsxs("p",{className:a==="terminal"?"pb-2 font-mono text-[10px] text-[#6ee7b7]":"pb-2 font-mono text-[10px] opacity-60",children:[n.input_tokens.toLocaleString()," in · ",n.output_tokens.toLocaleString()," out · ",n.total_tokens.toLocaleString()," total"]}),t.truncatedHistory&&e.jsx("p",{className:a==="terminal"?"pb-2 font-mono text-[10px] text-[#facc15]":"pb-2 font-mono text-[10px] text-ouro-gold/80",children:"older context not available; the agent's curated record is in Desk record"}),o.length>0&&e.jsxs("div",{className:"pb-2 mb-2 border-b border-current/10",children:[e.jsxs("button",{onClick:()=>f(!l),className:"font-mono text-[10px] uppercase tracking-wider opacity-60 transition-opacity hover:opacity-90",children:[l?"▼":"▶"," system context (",o.length,")"]}),l&&o.map(v=>e.jsxs("div",{className:"mt-2 max-h-60 overflow-y-auto rounded bg-black/5 p-2 text-xs opacity-75 whitespace-pre-wrap break-words",children:[e.jsx("p",{className:"mb-1 font-mono text-[9px] opacity-70",children:B(v)}),Y(v)]},v.id))]}),r.map(v=>v.role==="tool"?null:v.role==="user"?e.jsx(Dt,{msg:v,surface:a},v.id):v.role==="assistant"?e.jsx(Ft,{msg:v,toolResults:i,surface:a},v.id):null)]})]})}function Dt({msg:t,surface:s}){const n=Y(t);return e.jsx("div",{className:"flex justify-start py-1",children:e.jsxs("div",{className:Ut(s),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("p",{className:K(s,"user"),children:s==="terminal"?"human $":"user"}),e.jsxs("span",{className:"font-mono text-[9px] text-ouro-shadow/40",children:["#",t.sequence]}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:B(t)})]}),e.jsx("p",{className:Q(s,"user"),children:n})]})})}function Ft({msg:t,toolResults:s,surface:n}){const a=Y(t),o=(t.toolCalls??[]).map(ce),r=o.filter(i=>i.kind!=="action"),l=o.filter(i=>i.kind==="action"),f=[];for(const i of r)i.kind==="response"?f.push(e.jsx("div",{className:"flex justify-end py-1",children:e.jsxs("div",{className:G(n),children:[e.jsxs("div",{className:"mb-0.5 flex items-center gap-2",children:[e.jsx("p",{className:K(n,"agent"),children:n==="terminal"?"agent >":"agent"}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:B(t)})]}),e.jsx("p",{className:Q(n),children:i.deliveredText}),i.metadata&&i.metadata!=="complete"&&e.jsxs("p",{className:"mt-1 font-mono text-[9px] text-ouro-shadow",children:["intent: ",i.metadata]})]})},i.id)):i.kind==="delegation"?f.push(e.jsx("div",{className:"flex justify-end py-1",children:e.jsxs("div",{className:G(n),children:[e.jsxs("div",{className:"mb-0.5 flex items-center gap-2",children:[e.jsx("p",{className:K(n,"agent"),children:n==="terminal"?"agent >":"agent"}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:B(t)})]}),i.deliveredText&&e.jsx("p",{className:Q(n),children:i.deliveredText}),i.delegatedThought&&e.jsxs("div",{className:"mt-2 rounded bg-black/10 px-2.5 py-1.5 ring-1 ring-current/10",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider opacity-70",children:"→ inner dialog"}),e.jsx("p",{className:"mt-0.5 text-xs opacity-80",children:i.delegatedThought})]})]})},i.id)):i.kind==="surface"?f.push(e.jsx("div",{className:"flex justify-end py-1",children:e.jsxs("div",{className:G(n,"surface"),children:[e.jsxs("div",{className:"mb-0.5 flex items-center gap-2",children:[e.jsx("p",{className:K(n,"surface"),children:"surfaced"}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:B(t)})]}),e.jsx("p",{className:Q(n),children:i.deliveredText}),i.metadata&&e.jsxs("p",{className:"mt-1 font-mono text-[9px] text-ouro-shadow",children:["→ ",i.metadata]})]})},i.id)):i.kind==="rest"?f.push(e.jsx("div",{className:"py-1 text-center font-mono text-[10px] text-ouro-shadow/50",children:"— resting —"},i.id)):i.kind==="observe"&&f.push(e.jsxs("div",{className:"py-1 text-center font-mono text-[10px] text-ouro-shadow/50",children:["— observed",i.metadata?`: ${i.metadata}`:""," —"]},i.id));return a&&r.length===0&&f.push(e.jsx("div",{className:"flex justify-end py-1",children:e.jsxs("div",{className:G(n),children:[e.jsxs("div",{className:"mb-0.5 flex items-center gap-2",children:[e.jsx("p",{className:K(n,"agent"),children:n==="terminal"?"agent >":"agent"}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:B(t)})]}),e.jsx("p",{className:Q(n),children:a})]})},`${t.id}-content`)),l.length>0&&f.push(e.jsx("div",{className:"flex justify-end py-1",children:e.jsx("div",{className:"max-w-[85%] sm:max-w-[75%] space-y-1",children:l.map(i=>e.jsx(Pt,{call:i,result:s.get(i.id),surface:n},i.id))})},`${t.id}-tools`)),e.jsx(e.Fragment,{children:f})}function Pt({call:t,result:s,surface:n}){const[a,o]=u.useState(!1),r=s?Y(s):null;return e.jsxs("button",{onClick:()=>o(!a),className:`w-full text-left rounded px-2.5 py-1.5 text-sm transition-colors ${n==="terminal"?"bg-[#0f1a15] font-mono text-[#bbf7d0] ring-1 ring-[#1f3a2c] hover:ring-[#22c55e]/40":n==="teams"?"bg-white text-[#242424] ring-1 ring-[#d8d1ff] hover:ring-[#5b5fc7]/40":n==="imessage"?"bg-white text-[#1d1d1f] ring-1 ring-black/10 hover:ring-[#0a84ff]/30":"bg-ouro-moss/10 ring-1 ring-ouro-moss/12 hover:ring-ouro-glow/15"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-ouro-glow",children:t.name}),!a&&e.jsx("span",{className:"text-[10px] text-ouro-shadow",children:"tap to inspect"})]}),a&&e.jsxs(e.Fragment,{children:[t.rawArgs&&e.jsx("pre",{className:"mt-1.5 max-h-24 overflow-y-auto rounded bg-ouro-void/40 p-1.5 font-mono text-[11px] text-ouro-shadow whitespace-pre-wrap break-words",children:t.rawArgs}),s&&e.jsxs("div",{className:"mt-1.5 border-t border-ouro-moss/15 pt-1.5",children:[e.jsx(y,{children:"result"}),e.jsx("pre",{className:"mt-1 max-h-32 overflow-y-auto rounded bg-ouro-void/40 p-1.5 font-mono text-[11px] text-ouro-mist whitespace-pre-wrap break-words",children:r})]})]})]})}function Ee({label:t}){return e.jsxs("div",{className:"flex items-center gap-2 py-6",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-ouro-glow"}),e.jsxs("span",{className:"font-mono text-xs text-ouro-shadow",children:[t,"…"]})]})}function Wt({agentName:t,view:s,focus:n,onFocusConsumed:a,refreshGeneration:o}){var M,O;const r=D(),[l,f]=u.useState(null),[i,v]=u.useState(null),[c,k]=u.useState(null),[S,g]=u.useState(null),[p,d]=u.useState(null),b=s.work,C=b.obligations,h=b.tasks;u.useEffect(()=>{let m=!1;return f(null),v(null),k(null),g(null),d(null),z(`/agents/${encodeURIComponent(t)}/coding`).then(x=>{m||f(x)}).catch(()=>{}),z(`/agents/${encodeURIComponent(t)}/obligations`).then(x=>{m||v(x)}).catch(()=>{}),z(`/agents/${encodeURIComponent(t)}/self-fix`).then(x=>{m||k(x)}).catch(()=>{}),z(`/agents/${encodeURIComponent(t)}/sentinel`).then(x=>{m||(g(x),d(null))}).catch(x=>{m||(g(null),d(x instanceof Error?x.message:"sentinel unavailable"))}),()=>{m=!0}},[t,o]);const N=(i==null?void 0:i.items)??C.items,j=(i==null?void 0:i.openCount)??C.openCount,A=(l==null?void 0:l.items)??[],R=new Map;for(const m of A){const x=m.obligationId;if(x){const w=R.get(x);w?w.push(m):R.set(x,[m])}}return e.jsxs("div",{className:"space-y-8",children:[(S||p)&&e.jsxs("section",{children:[e.jsx(W,{label:"Recovery Sentinel"}),e.jsx(Vt,{view:S,error:p})]}),e.jsxs("section",{children:[e.jsx(W,{label:`Obligations (${j} open)`}),(i==null?void 0:i.primarySelectionReason)&&e.jsxs("p",{className:"mt-1 text-xs text-ouro-shadow",children:["Primary: ",i.primarySelectionReason]}),N.length>0?e.jsx("div",{className:"mt-3 space-y-3",children:N.map(m=>{const x=R.get(m.id)??[],w=Yt(m)?m:null,I=(w==null?void 0:w.isPrimary)??!1,$=(w==null?void 0:w.meaning)??null,L=m.origin;return e.jsxs("div",{className:`rounded-lg px-3 py-3 ring-1 ${I?"bg-ouro-glow/5 ring-ouro-glow/20":"bg-ouro-void/40 ring-ouro-moss/15"}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[I&&e.jsx(y,{color:"lime",children:"primary"}),e.jsx(y,{color:m.status==="pending"?"yellow":m.status==="fulfilled"?"lime":"zinc",children:m.status}),e.jsx("span",{className:"text-sm font-medium text-ouro-bone",children:U(m.content,120)})]}),L&&e.jsxs("button",{onClick:()=>r({tab:"sessions",focus:`${L.friendId}/${L.channel}/${L.key}`}),className:"mt-2 flex w-full items-center gap-2 rounded-md bg-ouro-moss/8 px-2.5 py-1.5 text-left text-xs ring-1 ring-ouro-moss/10 hover:ring-ouro-glow/20 transition-colors",children:[e.jsx("span",{className:"text-ouro-shadow",children:"from"}),e.jsx("span",{className:"font-medium text-ouro-glow",children:L.channel}),e.jsx("span",{className:"text-ouro-shadow",children:"→"}),e.jsx("span",{className:"text-ouro-mist truncate",children:L.key}),e.jsx("span",{className:"ml-auto text-ouro-shadow",children:"open session →"})]}),m.currentSurface&&e.jsxs("div",{className:"mt-1 text-xs text-ouro-mist",children:["surface: ",e.jsx("span",{className:"text-ouro-bone",children:m.currentSurface.kind})," — ",m.currentSurface.label]}),($==null?void 0:$.waitingOn)&&e.jsxs("p",{className:"mt-1 text-xs text-ouro-shadow",children:["Waiting on: ",$.waitingOn]}),x.length>0&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:"Linked coding"}),x.map(_=>e.jsxs("div",{className:"flex items-center gap-2 rounded bg-ouro-moss/10 px-2 py-1 text-xs",children:[e.jsx(y,{color:_.status==="failed"?"red":_.status==="running"?"lime":"zinc",children:_.status}),e.jsxs("span",{className:"text-ouro-mist truncate",children:[_.runner," — ",_.workdir]})]},_.id))]}),m.nextAction&&e.jsxs("p",{className:"mt-1.5 text-xs text-ouro-mist",children:["Next: ",m.nextAction]}),e.jsx("p",{className:"mt-1 text-xs text-ouro-shadow",children:T(m.updatedAt)})]},m.id)})}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No open obligations."})]}),c&&c.steps.length>0&&e.jsxs("section",{children:[e.jsx(W,{label:`Self-fix ${c.active?"(active)":"(inactive)"}`}),c.currentStep&&e.jsxs("p",{className:"mt-1 text-xs text-ouro-glow",children:["Current: ",c.currentStep]}),e.jsx("div",{className:"mt-3 space-y-1.5",children:c.steps.map((m,x)=>e.jsxs("div",{className:`flex items-center gap-2.5 rounded-lg px-3 py-2 ring-1 ${m.status==="active"?"bg-ouro-glow/5 ring-ouro-glow/20":m.status==="done"?"bg-ouro-void/40 ring-ouro-glow/10":"bg-ouro-void/40 ring-ouro-moss/10"}`,children:[e.jsx(y,{color:m.status==="done"?"lime":m.status==="active"?"yellow":(m.status==="skipped","zinc"),children:m.status}),e.jsx("span",{className:`text-sm ${m.status==="active"?"font-medium text-ouro-bone":"text-ouro-mist"}`,children:m.label}),m.detail&&e.jsx("span",{className:"ml-auto text-xs text-ouro-shadow",children:m.detail})]},x))})]}),e.jsxs("section",{children:[e.jsx(W,{label:`Coding lanes (${A.length})`}),A.length>0?e.jsx("div",{className:"mt-3 space-y-2",children:A.map(m=>{const x=m.status,w=x==="failed",I=m.failure,$=m.obligationId,L=m.originSession;return e.jsxs("div",{className:"rounded-lg bg-ouro-void/40 px-3 py-3 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{color:w?"red":x==="running"?"lime":x==="completed"?"zinc":"yellow",children:x}),e.jsx("span",{className:"text-sm font-medium text-ouro-bone",children:m.runner}),e.jsx("span",{className:"truncate text-xs text-ouro-shadow",children:m.workdir})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-2",children:[$&&e.jsxs("button",{onClick:()=>r({tab:"work",focus:$}),className:"text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow",children:["obligation: ",$.slice(0,20),"…"]}),m.taskRef&&e.jsxs("span",{className:"text-xs text-ouro-glow",children:["task: ",m.taskRef]}),L&&e.jsx("button",{onClick:()=>{r({tab:"sessions",focus:`${L.friendId}/${L.channel}/${L.key}`})},className:"text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow",children:"origin session"})]}),m.checkpoint&&e.jsx("p",{className:"mt-1.5 text-xs text-ouro-mist",children:U(m.checkpoint,100)}),e.jsxs("p",{className:"mt-1 text-xs text-ouro-shadow",children:["pid ",m.pid??"–"," · restarts ",m.restartCount," · ",T(m.lastActivityAt)]}),w&&I&&e.jsxs("div",{className:"mt-2 rounded bg-ouro-fang/5 p-2 text-xs ring-1 ring-ouro-fang/15",children:[e.jsx("span",{className:"font-semibold text-ouro-fang",children:"FAILURE:"})," ",e.jsxs("span",{className:"text-ouro-mist",children:[I.command," exited ",String(I.code??I.signal)]}),I.stderrTail&&e.jsx("pre",{className:"mt-1 max-h-20 overflow-y-auto font-mono text-[11px] text-ouro-shadow whitespace-pre-wrap",children:I.stderrTail})]})]},m.id)})}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No coding sessions."})]}),e.jsxs("section",{children:[e.jsx(W,{label:`Tasks (${h.liveCount} live, ${h.blockedCount} blocked)`}),((M=h.liveTaskNames)==null?void 0:M.length)>0?e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:h.liveTaskNames.map(m=>e.jsx(y,{children:m},m))}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No live tasks."}),((O=h.actionRequired)==null?void 0:O.length)>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-ouro-fang",children:"Action required"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:h.actionRequired.map(m=>e.jsx(y,{color:"red",children:m},m))})]})]})]})}function W({label:t}){return e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:t})}function Vt({view:t,error:s}){const n=(t==null?void 0:t.latest)??null,a=(t==null?void 0:t.latestReady)??null,o=new Set([n,a].filter(l=>!!l).map(ne)),r=((t==null?void 0:t.history)??[]).filter(l=>!o.has(ne(l)));return e.jsx("div",{className:"mt-3 rounded-lg bg-ouro-void/40 px-3 py-3 ring-1 ring-ouro-moss/15",children:s&&!t?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(y,{color:"red",children:"unavailable"}),e.jsx("span",{className:"min-w-0 flex-1 break-words text-sm text-ouro-mist",children:s})]}):t?e.jsxs(e.Fragment,{children:[s&&e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2 border-b border-ouro-moss/10 pb-2",children:[e.jsx(y,{color:"red",children:"unavailable"}),e.jsx("span",{className:"min-w-0 flex-1 break-words text-xs text-ouro-mist",children:s})]}),n?e.jsx(be,{label:"Latest",receipt:n,prominent:!0}):e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(y,{children:"missing"}),e.jsx("span",{className:"text-sm text-ouro-shadow",children:"Latest"})]}),a&&e.jsx("div",{className:"mt-3 border-t border-ouro-moss/10 pt-3",children:e.jsx(be,{label:"Latest ready",receipt:a})}),r.length>0&&e.jsxs("div",{className:"mt-3 border-t border-ouro-moss/10 pt-3",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:"History"}),e.jsx("div",{className:"mt-2 divide-y divide-ouro-moss/10",children:r.map(l=>e.jsx(Qt,{receipt:l},ne(l)))})]}),t.degraded.issues.length>0&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 border-t border-ouro-moss/10 pt-3",children:[e.jsx(y,{color:"yellow",children:"degraded"}),t.degraded.issues.map(l=>e.jsx("span",{className:"break-words text-xs text-ouro-shadow",children:l},l))]})]}):null})}function be({label:t,receipt:s,prominent:n=!1}){return e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:t}),e.jsx(y,{color:Le(s.verdict),children:s.verdict}),e.jsx("span",{className:"font-mono text-xs text-ouro-bone",children:Oe(s.trigger)}),e.jsxs("span",{className:"text-xs text-ouro-shadow",children:["updated ",T(s.generatedAt)]})]}),e.jsx("p",{className:`${n?"mt-2 text-sm font-medium text-ouro-bone":"mt-1.5 text-sm text-ouro-mist"} break-words`,children:s.summary}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsx(fe,{label:"Current ask",value:s.recoveryAnchor.currentAsk}),e.jsx(fe,{label:"Next safe action",value:s.recoveryAnchor.nextSafeAction})]}),s.signals.length>0&&e.jsx("div",{className:"mt-3 divide-y divide-ouro-moss/10 border-t border-ouro-moss/10 pt-1",children:s.signals.map(a=>e.jsx(Kt,{signal:a},a.id))}),ve(s.sourceLocators).length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1",children:[e.jsx("span",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:"Sources"}),ve(s.sourceLocators).map(a=>e.jsx("span",{className:"max-w-full truncate font-mono text-[10px] text-ouro-moss",children:a},a))]})]})}function fe({label:t,value:s}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:t}),e.jsx("p",{className:"mt-1 break-words text-sm text-ouro-bone",children:s?U(s,140):"unknown"})]})}function Kt({signal:t}){return e.jsxs("div",{className:"grid gap-2 py-2 md:grid-cols-[150px_1fr] md:items-start",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(y,{color:Jt(t),children:t.status}),e.jsx("span",{className:"font-mono text-[10px] text-ouro-shadow",children:t.kind.replace(/_/g," ")})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words text-xs text-ouro-mist",children:t.summary}),e.jsx("p",{className:"mt-1 truncate font-mono text-[10px] text-ouro-moss",children:t.source.locator}),t.repair&&e.jsxs("p",{className:"mt-1 break-words text-xs text-ouro-shadow",children:[t.repair.actor,": ",t.repair.command??t.repair.detail]})]})]})}function Qt({receipt:t}){var n;const s=((n=t.signals[0])==null?void 0:n.summary)??null;return e.jsxs("div",{className:"grid gap-2 py-2 md:grid-cols-[120px_110px_1fr] md:items-start",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(y,{color:Le(t.verdict),children:t.verdict})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-xs text-ouro-bone",children:Oe(t.trigger)}),e.jsx("p",{className:"text-[10px] text-ouro-shadow",children:T(t.generatedAt)})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words text-xs text-ouro-mist",children:t.summary}),s&&e.jsx("p",{className:"mt-1 break-words text-xs text-ouro-shadow",children:s}),e.jsx("p",{className:"mt-1 truncate font-mono text-[10px] text-ouro-moss",children:t.receiptLocator})]})]})}function Le(t){return t==="ready"?"lime":t==="watch"?"yellow":"red"}function Jt(t){return t.status==="fail"||t.severity==="critical"?"red":t.status==="warn"||t.severity==="warn"?"yellow":"lime"}function ne(t){return t.receiptLocator||t.id}function ve(t){return Array.from(new Set(t.filter(Boolean)))}function Oe(t){return t.replace(/_/g," ")}function Yt(t){return"isPrimary"in t}function Zt({agentName:t,focus:s,onFocusConsumed:n,refreshGeneration:a}){const o=D(),[r,l]=u.useState(null),[f,i]=u.useState(null),[v,c]=u.useState(null);u.useEffect(()=>{const p=`/agents/${encodeURIComponent(t)}`;Promise.all([z(`${p}/attention`).then(l),z(`${p}/bridges`).then(i),z(`${p}/friends`).then(c)])},[t,a]);const k=(r==null?void 0:r.queueItems)??[],S=(f==null?void 0:f.items)??[],g=(v==null?void 0:v.friends)??[];return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{children:[e.jsx(oe,{label:`Who is waiting (${(r==null?void 0:r.queueLength)??0})`}),k.length>0?e.jsx("div",{className:"mt-3 space-y-2",children:k.map((p,d)=>{const b=p.bridgeId,C=p.obligationId;return e.jsxs("div",{className:"rounded-lg bg-ouro-void/40 px-3 py-3 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>o({tab:"sessions"}),className:"font-medium text-ouro-bone hover:text-ouro-glow transition-colors",children:p.friendName}),e.jsxs("span",{className:"text-xs text-ouro-shadow",children:["via ",p.channel]}),e.jsxs(y,{color:"yellow",children:["waiting ",T(new Date(p.timestamp).toISOString())]})]}),e.jsx("p",{className:"mt-1 text-sm text-ouro-mist",children:U(p.delegatedContent,140)}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-2 text-xs",children:[b&&e.jsxs("button",{onClick:()=>o({tab:"connections",focus:b}),className:"text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow",children:["bridge: ",b.slice(0,12),"…"]}),C&&e.jsxs("button",{onClick:()=>o({tab:"work",focus:C}),className:"text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow",children:["obligation: ",C.slice(0,16),"…"]})]})]},d)})}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"Nobody waiting."})]}),e.jsxs("section",{children:[e.jsx(oe,{label:`Bridges (${(f==null?void 0:f.totalCount)??0})`}),S.length>0?e.jsx("div",{className:"mt-3 space-y-3",children:S.map(p=>{const d=p.attachedSessions,b=p.task,C=p.lifecycle==="active";return e.jsxs("div",{className:`rounded-lg px-3 py-3 ring-1 ${C?"bg-ouro-moss/10 ring-ouro-glow/12":"bg-ouro-void/40 ring-ouro-moss/15"}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(y,{color:C?"lime":"zinc",children:p.lifecycle}),e.jsx("p",{className:"font-medium text-ouro-bone",children:p.objective})]}),p.summary&&e.jsx("p",{className:"mt-1 text-sm text-ouro-mist",children:U(p.summary,160)}),d.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:d.map((h,N)=>e.jsxs("button",{onClick:()=>o({tab:"sessions",focus:`${h.friendId}/${h.channel}/${h.key}`}),className:"rounded-md bg-ouro-moss/10 px-2 py-0.5 font-mono text-[11px] text-ouro-glow ring-1 ring-ouro-moss/12 hover:ring-ouro-glow/25 transition-colors",children:[h.friendId,"/",h.channel,"/",h.key]},N))}),b&&e.jsxs("p",{className:"mt-1.5 text-xs",children:[e.jsxs("button",{onClick:()=>o({tab:"work"}),className:"text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow",children:["task: ",b.taskName]}),e.jsxs("span",{className:"text-ouro-shadow",children:[" (",b.mode,")"]})]}),e.jsx("p",{className:"mt-1 text-xs text-ouro-shadow",children:T(p.updatedAt)})]},p.id)})}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No bridges."})]}),e.jsxs("section",{children:[e.jsx(oe,{label:`Friends (${(v==null?void 0:v.totalFriends)??0})`}),g.length>0?e.jsx("div",{className:"mt-3 space-y-1.5",children:g.map(p=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-ouro-void/40 px-3 py-2.5 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("button",{onClick:()=>o({tab:"sessions"}),className:"font-medium text-ouro-bone hover:text-ouro-glow transition-colors",children:p.friendName}),e.jsxs("p",{className:"text-xs text-ouro-shadow",children:[p.channels.join(", ")," · ",p.sessionCount," sessions",p.lastActivityAt&&e.jsxs(e.Fragment,{children:[" · ",T(p.lastActivityAt)]})]})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("p",{className:"tabular-nums text-sm font-medium text-ouro-bone",children:p.totalTokens.toLocaleString()}),e.jsx("p",{className:"text-[10px] text-ouro-shadow",children:"tokens"})]})]},p.friendId))}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No friends."})]})]})}function oe({label:t}){return e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:t})}function Xt(t){return Te(t)}function V(t){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(Xt(t)))}function Gt({agentName:t,view:s,refreshGeneration:n}){const a=D(),[o,r]=u.useState(null),[l,f]=u.useState(null),[i,v]=u.useState(!1),[c,k]=u.useState(null),[S,g]=u.useState(!1),p=u.useRef(null),d=s.inner;u.useEffect(()=>{z(`/agents/${encodeURIComponent(t)}/habits`).then(r)},[t,n]),u.useEffect(()=>{let m=!1;return v(!1),f(null),z(`/agents/${encodeURIComponent(t)}/habit-runs`).then(x=>{m||f(x)}).catch(()=>{m||v(!0)}),()=>{m=!0}},[t,n]),u.useEffect(()=>{c&&p.current!==n&&(p.current=n,z(`/agents/${encodeURIComponent(t)}/inner-transcript`).then(k))},[t,n,c!==null]);function b(){if(c){g(!S);return}z(`/agents/${encodeURIComponent(t)}/inner-transcript`).then(m=>{p.current=n,k(m),g(!0)})}const C=(o==null?void 0:o.items)??[],h=(l==null?void 0:l.items)??[],N=C.filter(m=>m.isOverdue),j=C.filter(m=>m.status==="active"&&!m.isOverdue),A=C.filter(m=>m.status==="paused"),R=d.mode==="deep"?d.origin:null,M=d.mode==="deep"?d.obligationStatus:null,O=C.find(m=>m.name.toLowerCase()==="heartbeat");return e.jsxs("div",{className:"space-y-8",children:[O&&e.jsxs("section",{children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:"Heartbeat"}),e.jsx("div",{className:`mt-2 rounded-xl p-4 ring-1 ${O.isOverdue?"bg-ouro-fang/5 ring-ouro-fang/15":"bg-ouro-moss/10 ring-ouro-glow/10"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`h-2.5 w-2.5 rounded-full ${O.isOverdue?"bg-ouro-fang animate-pulse":"bg-ouro-glow"}`}),e.jsx("span",{className:"font-medium text-ouro-bone",children:O.isOverdue?"Overdue":"Healthy"}),e.jsxs("span",{className:"text-xs text-ouro-shadow",children:["every ",O.cadence??"unknown"," · last ",O.lastRun?T(O.lastRun):"never"]})]})})]}),e.jsx("section",{children:e.jsxs("div",{className:"rounded-xl bg-ouro-moss/15 p-4 ring-1 ring-ouro-glow/10",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-ouro-glow",children:"Inner work"}),e.jsx("p",{className:"mt-1 font-display text-xl italic font-semibold text-ouro-bone",children:d.status}),d.summary&&e.jsx("p",{className:"mt-2 text-sm leading-relaxed text-ouro-mist",children:d.summary}),e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:d.hasPending?"Pending inner work queued.":"No pending inner work."}),(d.returnObligationQueue.queuedCount>0||d.returnObligationQueue.runningCount>0)&&e.jsxs("p",{className:"mt-1 text-sm text-ouro-mist",children:["Held work items:"," ",e.jsx("span",{className:"font-medium text-ouro-bone",children:d.returnObligationQueue.queuedCount+d.returnObligationQueue.runningCount})," ","(",d.returnObligationQueue.queuedCount," queued",d.returnObligationQueue.runningCount>0?`, ${d.returnObligationQueue.runningCount} running`:"",")",d.returnObligationQueue.oldestActiveAt!==null&&e.jsxs("span",{className:"text-ouro-shadow",children:[" · oldest ",T(new Date(d.returnObligationQueue.oldestActiveAt).toISOString())]})]}),R&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:"Triggered from"}),e.jsxs("button",{onClick:()=>{a({tab:"sessions",focus:`${R.friendId}/${R.channel}/${R.key}`})},className:"mt-1 text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow",children:[R.friendId.slice(0,8),"…/",R.channel,"/",R.key]}),M&&e.jsxs("button",{onClick:()=>a({tab:"work"}),className:"ml-2 text-xs text-ouro-glow underline decoration-ouro-glow/30 underline-offset-2 hover:decoration-ouro-glow",children:["obligation: ",M]})]})]})}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:"Habit sessions"}),e.jsx("p",{className:"mt-1 text-xs text-ouro-shadow",children:l?`${l.totalCount} recorded`:i?"Run history unavailable":"Loading runs"})]}),l&&l.totalCount>h.length&&e.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-ouro-shadow",children:["showing ",h.length,"/",l.totalCount]})]}),l?h.length>0?e.jsx("div",{className:"mt-3 space-y-2",children:h.map(m=>e.jsx(ss,{run:m},m.runId))}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No habit sessions recorded."}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:i?"Habit sessions unavailable.":"Loading habit sessions."})]}),e.jsxs("section",{children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:["Inner dialog ",c?`(${c.messages.length} total)`:""]}),c?e.jsx(ns,{messages:c.messages}):e.jsx("button",{onClick:b,className:"mt-2 w-full rounded-lg px-3 py-2.5 text-left font-mono text-xs text-ouro-glow ring-1 ring-ouro-moss/15 hover:ring-ouro-glow/20 transition-colors",children:"Load inner dialog"})]}),e.jsxs("section",{children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:["Habits (",(o==null?void 0:o.totalCount)??0,")"]}),N.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-fang mb-1.5",children:["Overdue (",N.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:N.map(m=>e.jsx(ae,{h:m},m.name))})]}),j.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-glow mb-1.5",children:["Running fine (",j.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:j.map(m=>e.jsx(ae,{h:m},m.name))})]}),A.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-shadow mb-1.5",children:["Paused (",A.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:A.map(m=>e.jsx(ae,{h:m},m.name))})]}),C.length===0&&e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No habits configured."})]})]})}function es(t){return t==="error"||t==="blocked"?"bad":t==="surfaced"||t==="wrote_arc"||t==="updated_desk"||t==="wrote_record"?"good":t==="no_change"?"quiet":"warn"}function ts(t){const s=es(t);return s==="bad"?"bg-ouro-fang/10 text-ouro-fang ring-ouro-fang/20":s==="good"?"bg-ouro-scale/10 text-ouro-glow ring-ouro-scale/20":s==="warn"?"bg-ouro-gold/10 text-ouro-gold ring-ouro-gold/20":"bg-ouro-void/60 text-ouro-shadow ring-ouro-moss/15"}function ss({run:t}){const s=t.permissionEnvelope.returnRoutes,n=t.surfaceAttempts,a=t.errors??[],o=Array.from(new Set([...t.permissionEnvelope.deniedTools,...t.toolPolicy.deniedTools]));return e.jsxs("article",{className:"rounded-lg bg-ouro-void/45 px-3 py-3 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`rounded-md px-2 py-0.5 font-mono text-[10px] font-medium uppercase tracking-wider ring-1 ${ts(t.outcome)}`,children:t.outcome}),e.jsx("span",{className:"min-w-0 break-all font-medium text-ouro-bone",children:t.habitName}),e.jsx("span",{className:"font-mono text-[10px] uppercase tracking-wider text-ouro-shadow",children:t.trigger})]}),e.jsx("p",{className:"mt-1 font-mono text-[11px] text-ouro-shadow break-all",children:t.runId})]}),e.jsxs("div",{className:"shrink-0 text-left sm:text-right",children:[e.jsx("p",{className:"font-mono text-[10px] text-ouro-shadow",children:T(t.endedAt)}),t.nextRunAt&&e.jsxs("p",{className:"font-mono text-[10px] text-ouro-glow",children:["next ",T(t.nextRunAt)]})]})]}),e.jsxs("div",{className:"mt-3 grid gap-2 lg:grid-cols-3",children:[e.jsxs(re,{label:"routes",children:[s.length>0?e.jsx("div",{className:"space-y-1.5",children:s.map((r,l)=>e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("span",{className:"max-w-full break-all rounded bg-ouro-moss/20 px-1.5 py-0.5 font-mono text-[10px] text-ouro-mist ring-1 ring-ouro-moss/20",children:r.kind}),e.jsx("span",{className:"max-w-full break-all rounded bg-ouro-void/60 px-1.5 py-0.5 font-mono text-[10px] text-ouro-shadow ring-1 ring-ouro-moss/15",children:r.status})]}),e.jsx("p",{className:"mt-0.5 font-mono text-[10px] text-ouro-shadow break-all",children:r.recipient}),(r.friendId||r.channel||r.key)&&[r.friendId,r.channel,r.key].filter(Boolean).join("/")!==r.recipient&&e.jsx("p",{className:"mt-0.5 font-mono text-[10px] text-ouro-shadow/70 break-all",children:[r.friendId,r.channel,r.key].filter(Boolean).join("/")}),r.reason&&e.jsx("p",{className:"mt-0.5 text-[11px] text-ouro-shadow break-words",children:r.reason})]},`${r.kind}-${r.recipient}-${l}`))}):e.jsx("span",{className:"text-ouro-shadow",children:"none"}),e.jsxs("p",{className:"mt-1 text-[11px] text-ouro-shadow",children:["outward ",t.permissionEnvelope.canMessageOutward?"allowed":"closed"]}),t.permissionEnvelope.warnings.length>0&&e.jsx("div",{className:"mt-1.5 space-y-1",children:t.permissionEnvelope.warnings.map((r,l)=>e.jsx("p",{className:"text-[11px] text-ouro-gold break-words",children:r},`${r}-${l}`))})]}),e.jsx(re,{label:"attempts",children:n.length>0?e.jsx("div",{className:"space-y-1",children:n.map((r,l)=>e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-ouro-moss/20 px-1.5 py-0.5 font-mono text-[10px] text-ouro-bone ring-1 ring-ouro-moss/20",children:r.result}),e.jsx("span",{className:"text-[11px] text-ouro-shadow",children:r.reason})]}),e.jsxs("p",{className:"mt-0.5 font-mono text-[10px] text-ouro-shadow break-all",children:[r.recipient,"/",r.channel,r.error?` - ${r.error}`:""]})]},`${r.recipient}-${r.channel}-${l}`))}):e.jsx("span",{className:"text-ouro-shadow",children:"none"})}),e.jsxs(re,{label:"tools",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.toolPolicy.grantedTools.map(r=>e.jsx("span",{className:"max-w-full break-all rounded bg-ouro-scale/10 px-1.5 py-0.5 font-mono text-[10px] text-ouro-glow ring-1 ring-ouro-scale/15",children:r},`granted-${r}`)),o.map(r=>e.jsx("span",{className:"max-w-full break-all rounded bg-ouro-fang/8 px-1.5 py-0.5 font-mono text-[10px] text-ouro-fang ring-1 ring-ouro-fang/15",children:r},`denied-${r}`)),t.toolPolicy.grantedTools.length===0&&o.length===0&&e.jsx("span",{className:"text-ouro-shadow",children:"none"})]}),t.errorCount>0&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] text-ouro-fang",children:[t.errorCount," error",t.errorCount===1?"":"s"]}),a.length>0&&e.jsx("div",{className:"mt-1 space-y-1",children:a.map((r,l)=>e.jsx("p",{className:"max-w-full break-words font-mono text-[10px] text-ouro-fang",children:r},`${t.runId}-error-${l}`))})]})]}),(t.producedRefs.length>0||t.receiptLocator)&&e.jsxs("div",{className:"mt-3 border-t border-ouro-moss/15 pt-2",children:[t.producedRefs.length>0&&e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-1.5",children:t.producedRefs.map((r,l)=>e.jsxs("span",{className:"max-w-full break-all rounded bg-ouro-void/60 px-1.5 py-0.5 font-mono text-[10px] text-ouro-shadow ring-1 ring-ouro-moss/10",children:[r.kind,": ",r.locator]},`${r.kind}-${r.locator}-${l}`))}),e.jsx("p",{className:"font-mono text-[10px] text-ouro-shadow break-all",children:t.receiptLocator})]})]})}function re({label:t,children:s}){return e.jsxs("div",{className:"min-w-0 border-l border-ouro-moss/15 pl-2.5",children:[e.jsx("p",{className:"mb-1 font-mono text-[9px] uppercase tracking-wider text-ouro-shadow",children:t}),e.jsx("div",{className:"min-w-0 text-xs text-ouro-mist",children:s})]})}function ns({messages:t}){var S;const s=t.filter(g=>g.role!=="system"&&g.role!=="tool"),[n,a]=u.useState(!1),o=n?s:s.slice(-30),r=s.length-o.length,l=((S=o[o.length-1])==null?void 0:S.id)??null,{ref:f,onScroll:i,preserveScroll:v}=Ae(l),c=[];for(const g of s){if(g.role!=="assistant")continue;const p=(g.toolCalls??[]).map(ce);for(const d of p)d.kind==="surface"&&c.push({index:g.sequence,kind:"surfaced",label:U(d.deliveredText??"",40)}),d.kind==="rest"&&c.push({index:g.sequence,kind:"resting",label:"resting"}),d.kind==="delegation"&&c.push({index:g.sequence,kind:"delegated",label:"continued thinking"})}function k(g){var d;const p=(d=f.current)==null?void 0:d.querySelector(`[data-msg-index="${g}"]`);p&&p.scrollIntoView({behavior:"smooth",block:"center"})}return e.jsxs("div",{children:[c.length>0&&e.jsx("div",{className:"mt-2 mb-1 flex flex-wrap gap-1",children:c.map((g,p)=>e.jsxs("button",{onClick:()=>{v(),a(!0),setTimeout(()=>k(g.index),100)},className:`rounded-md px-2 py-0.5 text-[10px] font-mono ring-1 transition-colors ${g.kind==="surfaced"?"bg-ouro-scale/10 text-ouro-glow ring-ouro-scale/20 hover:ring-ouro-glow/30":g.kind==="resting"?"bg-ouro-void/40 text-ouro-shadow ring-ouro-moss/10":"bg-ouro-gold/5 text-ouro-gold ring-ouro-gold/10"}`,children:[g.kind==="surfaced"?"★":g.kind==="resting"?"—":"→"," #",g.index]},p))}),e.jsxs("div",{ref:f,"data-testid":"inner-transcript-scroll",onScroll:i,className:"max-h-[60vh] overflow-y-auto rounded-lg bg-ouro-void/60 p-3 ring-1 ring-ouro-moss/15 space-y-1",children:[r>0&&e.jsxs("button",{onClick:()=>{v(),a(!0)},className:"w-full rounded-lg px-3 py-2 text-center font-mono text-xs text-ouro-shadow hover:text-ouro-mist ring-1 ring-ouro-moss/10 hover:ring-ouro-moss/20 transition-colors mb-2",children:["Load ",r," earlier messages"]}),o.map(g=>{const p=Y(g);if(g.role==="user"){const d=p.includes("[pending from")||p.includes("[delegated"),b=p.includes("waking up")||p.includes("world-state checkpoint");return e.jsx("div",{"data-msg-index":g.sequence,className:"flex justify-start py-1",children:e.jsxs("div",{className:`max-w-[85%] rounded-2xl rounded-bl-sm px-3 py-2 ring-1 ${d?"bg-ouro-gold/8 ring-ouro-gold/15":b?"bg-ouro-moss/20 ring-ouro-moss/15":"bg-ouro-moss/25 ring-ouro-moss/15"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider",style:{color:d?"var(--color-ouro-gold)":"var(--color-ouro-shadow)"},children:d?"★ delegated":b?"heartbeat":"prompt"}),e.jsxs("span",{className:"font-mono text-[9px] text-ouro-shadow/40",children:["#",g.sequence]}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:V(g)})]}),e.jsx("p",{className:"text-sm leading-relaxed text-ouro-bone whitespace-pre-wrap break-words",children:p})]})},g.id)}if(g.role==="assistant"){const d=(g.toolCalls??[]).map(ce),b=d.filter(N=>N.kind==="surface"),C=d.filter(N=>N.kind==="rest"),h=d.filter(N=>N.kind==="delegation");return e.jsxs("div",{"data-msg-index":g.sequence,children:[b.map(N=>e.jsx("div",{className:"flex justify-end py-1",children:e.jsxs("div",{className:"max-w-[85%] rounded-2xl rounded-br-sm bg-ouro-scale/15 px-3 py-2 ring-1 ring-ouro-scale/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-glow",children:"★ surfaced outward"}),e.jsxs("span",{className:"font-mono text-[9px] text-ouro-shadow/40",children:["#",g.sequence]}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:V(g)})]}),e.jsx("p",{className:"text-sm leading-relaxed text-ouro-bone whitespace-pre-wrap break-words",children:N.deliveredText}),N.metadata&&e.jsxs("p",{className:"mt-1 font-mono text-[9px] text-ouro-shadow",children:["→ ",N.metadata]})]})},N.id)),h.length>0&&e.jsxs("div",{className:"py-1 text-center font-mono text-[10px] text-ouro-gold/50",children:["— still thinking — #",g.sequence," · ",V(g)]}),C.length>0&&e.jsxs("div",{className:"py-1 text-center font-mono text-[10px] text-ouro-shadow/40",children:["— resting — #",g.sequence," · ",V(g)]}),b.length===0&&C.length===0&&h.length===0&&p&&e.jsx("div",{className:"flex justify-end py-1",children:e.jsxs("div",{className:"max-w-[85%] rounded-2xl rounded-br-sm bg-ouro-glow/6 px-3 py-2 ring-1 ring-ouro-glow/8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("p",{className:"font-mono text-[9px] uppercase tracking-wider text-ouro-glow/50",children:"thinking"}),e.jsxs("span",{className:"font-mono text-[9px] text-ouro-shadow/40",children:["#",g.sequence]}),e.jsx("span",{className:"font-mono text-[9px] text-ouro-shadow/60",children:V(g)})]}),e.jsx("p",{className:"text-sm leading-relaxed text-ouro-mist whitespace-pre-wrap break-words",children:p})]})})]},g.id)}return null})]})]})}function ae({h:t}){const s=t.isOverdue,n=t.isDegraded,a=t.status;return e.jsxs("div",{className:`rounded-lg px-3 py-2.5 ring-1 ${s?"bg-ouro-fang/5 ring-ouro-fang/15":n?"bg-ouro-gold/5 ring-ouro-gold/15":a==="paused"?"bg-ouro-void/30 ring-ouro-moss/10":"bg-ouro-void/40 ring-ouro-moss/15"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{color:s?"red":n?"yellow":a==="active"?"lime":"zinc",children:s?"overdue":n?"degraded":a}),e.jsx("span",{className:"font-medium text-ouro-bone",children:t.title})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-3 text-xs text-ouro-shadow",children:[t.cadence&&e.jsxs("span",{children:["every ",t.cadence]}),e.jsx("span",{children:t.lastRun?`last ${T(t.lastRun)}`:"never run"}),n&&t.degradedReason&&e.jsx("span",{className:"text-ouro-gold",children:t.degradedReason}),!s&&!n&&a==="active"&&t.lastRun&&e.jsx("span",{className:"text-ouro-glow",children:"on schedule"}),s&&t.overdueMs&&e.jsxs("span",{className:"text-ouro-fang",children:[Math.floor(t.overdueMs/6e4),"m overdue"]}),!t.lastRun&&a==="active"&&e.jsx("span",{className:"text-ouro-gold",children:"never fired — may be misconfigured"})]}),t.bodyExcerpt&&e.jsx("p",{className:"mt-1 text-xs text-ouro-shadow/70",children:t.bodyExcerpt})]})}function os({agentName:t,refreshGeneration:s}){const[n,a]=u.useState(null),[o,r]=u.useState(null),[l,f]=u.useState("diary");if(u.useEffect(()=>{z(`/agents/${encodeURIComponent(t)}/notes`).then(a),z(`/agents/${encodeURIComponent(t)}/note-decisions`).then(r).catch(()=>{})},[t,s]),!n)return e.jsxs("div",{className:"flex items-center gap-2 py-6",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-ouro-glow"}),e.jsx("span",{className:"font-mono text-xs text-ouro-shadow",children:"Loading…"})]});const i=n.recentDiaryEntries,v=n.recentCanonicalNotes;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>f("diary"),className:`font-mono text-xs uppercase tracking-wider transition-colors ${l==="diary"?"text-ouro-glow":"text-ouro-shadow hover:text-ouro-mist"}`,children:["Diary (",n.diaryEntryCount,")"]}),e.jsx("span",{className:"text-ouro-shadow/30",children:"|"}),e.jsxs("button",{onClick:()=>f("notes"),className:`font-mono text-xs uppercase tracking-wider transition-colors ${l==="notes"?"text-ouro-glow":"text-ouro-shadow hover:text-ouro-mist"}`,children:["Notes (",n.canonicalNoteCount,")"]}),e.jsx("span",{className:"text-ouro-shadow/30",children:"|"}),e.jsxs("button",{onClick:()=>f("decisions"),className:`font-mono text-xs uppercase tracking-wider transition-colors ${l==="decisions"?"text-ouro-glow":"text-ouro-shadow hover:text-ouro-mist"}`,children:["Decisions (",(o==null?void 0:o.totalCount)??0,")"]})]}),l==="diary"&&e.jsx("div",{children:i.length>0?e.jsx("div",{className:"space-y-3",children:i.map(c=>e.jsxs("article",{className:"rounded-xl bg-ouro-void/40 px-4 py-3.5 ring-1 ring-ouro-moss/15",children:[e.jsx("p",{className:"text-sm leading-relaxed text-ouro-bone",children:c.text}),e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-ouro-shadow",children:[e.jsx(y,{children:c.source}),e.jsx("span",{children:T(c.createdAt)})]})]},c.id))}):e.jsx("p",{className:"text-sm text-ouro-shadow italic",children:"No diary entries yet. The agent hasn't written anything down."})}),l==="notes"&&e.jsx("div",{children:v.length>0?e.jsx("div",{className:"space-y-3",children:v.map(c=>e.jsxs("article",{className:"rounded-xl bg-ouro-void/40 px-4 py-3.5 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"font-medium text-ouro-bone",children:c.title}),e.jsx("span",{className:"text-xs text-ouro-shadow",children:T(c.writtenAt)})]}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-ouro-mist",children:c.preview}),c.tags.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:c.tags.map(k=>e.jsx(y,{children:k},k))})]},c.filename))}):e.jsx("p",{className:"text-sm text-ouro-shadow italic",children:"No canonical notes yet."})}),l==="decisions"&&e.jsx("div",{children:o&&o.items.length>0?e.jsx("div",{className:"space-y-2",children:o.items.map((c,k)=>e.jsxs("div",{className:"rounded-xl bg-ouro-void/40 px-4 py-3 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{color:c.decision==="saved"?"lime":"zinc",children:c.decision}),e.jsx(y,{children:c.kind.replace(/_/g," ")}),e.jsx("span",{className:"text-xs text-ouro-shadow",children:T(c.timestamp)})]}),c.reason&&e.jsx("p",{className:"mt-1 text-sm text-ouro-mist",children:c.reason}),c.excerpt&&e.jsx("p",{className:"mt-0.5 text-xs text-ouro-shadow italic truncate",children:c.excerpt})]},k))}):e.jsx("p",{className:"text-sm text-ouro-shadow italic",children:"No note decisions logged yet."})})]})}function rs({agentName:t,view:s,refreshGeneration:n}){var p;const[a,o]=u.useState(null),[r,l]=u.useState(null),f=s.agent,i=f.degraded,v=f.freshness,c=((p=f.providers)==null?void 0:p.lanes)??[];u.useEffect(()=>{Promise.all([z("/machine/health").then(o).catch(()=>null),z("/machine/logs").then(l).catch(()=>null)])},[t,n]);const k=ms(a)?a:null,S=(k==null?void 0:k.degradedComponents)??[],g=(r==null?void 0:r.entries)??[];return e.jsxs("div",{className:"space-y-8",children:[i.status==="degraded"&&i.issues.length>0&&e.jsxs("section",{children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-fang",children:["Agent issues (",i.issues.length,")"]}),e.jsx("div",{className:"mt-3 space-y-1.5",children:i.issues.map((d,b)=>e.jsxs("div",{className:"rounded-lg bg-ouro-fang/5 px-3 py-2.5 ring-1 ring-ouro-fang/15",children:[e.jsx("p",{className:"font-mono text-xs font-semibold text-ouro-fang",children:d.code}),e.jsx("p",{className:"mt-0.5 text-xs text-ouro-mist break-all",children:d.detail})]},b))})]}),e.jsxs("section",{children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:"Agent config"}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(q,{label:"Provider lanes",value:as(c)}),e.jsx(q,{label:"Enabled",value:f.enabled?"yes":"no"}),e.jsx(q,{label:"Freshness",value:`${v.status}${v.ageMs!=null?` (${Math.floor(v.ageMs/6e4)}m)`:""}`})]})]}),e.jsxs("section",{children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:"Provider lanes"}),c.length>0?e.jsx("div",{className:"mt-3 grid gap-2 lg:grid-cols-2",children:c.map(d=>{const b=ds(d);return e.jsxs("div",{className:"rounded-lg bg-ouro-void/40 px-3 py-3 ring-1 ring-ouro-moss/15",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"font-mono text-xs font-semibold uppercase tracking-wider text-ouro-bone",children:d.lane}),e.jsx(y,{color:xs(d),children:d.status}),e.jsx(y,{color:us(d.readiness.status),children:d.readiness.status})]}),e.jsx("p",{className:"mt-2 text-sm font-medium text-ouro-bone",children:is(d)}),e.jsxs("div",{className:"mt-2 space-y-1 text-xs text-ouro-mist",children:[e.jsxs("p",{children:["source: ",d.source]}),e.jsxs("p",{children:["readiness: ",ls(d.readiness)]}),d.readiness.attempts!==void 0&&e.jsxs("p",{children:["attempts: ",d.readiness.attempts]}),d.readiness.checkedAt&&e.jsxs("p",{children:["checked: ",T(d.readiness.checkedAt)]}),e.jsxs("p",{children:["credentials: ",cs(d.credential)]}),d.credential.revision&&e.jsxs("p",{children:["revision: ",d.credential.revision]}),je(d)&&e.jsxs("p",{children:["reason: ",je(d)]}),b&&e.jsxs("p",{className:"break-all text-ouro-fang",children:["repair: ",b]}),d.warnings.map((C,h)=>e.jsxs("p",{className:"break-words text-ouro-gold",children:["warning: ",C]},h))]})]},d.lane)})}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No provider lane data loaded."})]}),e.jsxs("section",{children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:"Daemon health"}),k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(q,{label:"Status",value:k.status}),e.jsx(q,{label:"Mode",value:k.mode}),e.jsx(q,{label:"Uptime",value:`${Math.floor(k.uptimeSeconds/60)}m`})]}),S.length>0&&e.jsxs("div",{className:"mt-3 space-y-1.5",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-ouro-fang",children:"Degraded components"}),S.map((d,b)=>e.jsxs("div",{className:"rounded-lg bg-ouro-fang/5 px-3 py-2 ring-1 ring-ouro-fang/15",children:[e.jsx("p",{className:"text-xs font-semibold text-ouro-fang",children:d.component}),e.jsx("p",{className:"text-xs text-ouro-mist",children:d.reason})]},b))]})]}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No health file found. This is normal when not running under the daemon."})]}),e.jsxs("section",{children:[e.jsxs("p",{className:"font-mono text-[10px] uppercase tracking-[0.15em] text-ouro-glow",children:["Recent logs (",(r==null?void 0:r.totalLines)??0," total)"]}),g.length>0?e.jsx("div",{className:"mt-3 max-h-96 overflow-y-auto rounded-lg bg-ouro-void/40 ring-1 ring-ouro-moss/15",children:[...g].reverse().slice(0,50).map((d,b)=>{const C=d.level;return e.jsxs("div",{className:"border-b border-ouro-moss/10 px-3 py-1.5 last:border-b-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(y,{color:C==="error"?"red":C==="warn"?"yellow":"zinc",children:C}),e.jsx("span",{className:"text-ouro-shadow",children:T(d.ts)}),e.jsx("span",{className:"font-mono text-ouro-glow",children:d.event})]}),e.jsx("p",{className:"truncate text-xs text-ouro-mist",children:d.message})]},b)})}):e.jsx("p",{className:"mt-2 text-sm text-ouro-shadow",children:"No log entries."})]})]})}function q({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg bg-ouro-void/40 px-3 py-2.5 ring-1 ring-ouro-moss/15",children:[e.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-ouro-shadow",children:t}),e.jsx("p",{className:"mt-1 text-sm font-medium text-ouro-bone",children:s})]})}function as(t){return t.length===0?"none":`${t.filter(n=>n.status==="configured").length}/${t.length} configured`}function is(t){return t.status==="unconfigured"?"unconfigured":`${t.provider} / ${t.model}`}function ls(t){return t.status==="failed"?t.error?`failed: ${t.error}`:"failed":t.status==="stale"?t.reason?`stale: ${t.reason}`:"stale":t.status==="unknown"?t.reason?`unknown: ${t.reason}`:"unknown":t.status}function cs(t){return t.status==="present"?t.source??"vault":t.status==="invalid-pool"?"vault unavailable":"missing"}function ds(t){return t.status==="unconfigured"?t.repairCommand:t.credential.repairCommand}function je(t){return t.status==="unconfigured"?t.reason:t.readiness.reason}function xs(t){return t.status==="configured"?"green":"yellow"}function us(t){return t==="ready"?"green":t==="failed"?"red":t==="stale"?"amber":"zinc"}function ms(t){return!!(t&&"degradedComponents"in t)}const ie=[{id:"overview",label:"Overview"},{id:"mail",label:"Mailbox"},{id:"sessions",label:"Sessions"},{id:"work",label:"Work"},{id:"connections",label:"Connections"},{id:"inner",label:"Inner"},{id:"notes",label:"Desk Record"},{id:"runtime",label:"Runtime"}];function hs(t){return t==="degraded"||t==="blocked"?"red":t==="stale"?"yellow":t==="active"?"lime":"zinc"}function ps({agentName:t,view:s,deskPrefs:n,refreshGeneration:a,initialRoute:o}){const[r,l]=u.useState((o==null?void 0:o.tab)??"overview"),[f,i]=u.useState(o==null?void 0:o.focus),v=u.useRef(!1),c=u.useRef(t);u.useEffect(()=>{const b=c.current!==t;if(c.current=t,(o==null?void 0:o.agent)===t&&!v.current){v.current=!0,l(o.tab),i(o.focus);return}b&&(l("overview"),i(void 0))},[t,o==null?void 0:o.agent,o==null?void 0:o.focus,o==null?void 0:o.tab]);const k=u.useCallback(b=>{l(b.tab),i(b.focus),window.history.pushState(null,"",le({agent:t,tab:b.tab,focus:b.focus}))},[t]),S=u.useCallback(b=>{l(b),i(void 0),window.history.pushState(null,"",le({agent:t,tab:b,focus:void 0}))},[t]),g=u.useCallback(()=>i(void 0),[]);if(ot(k),!s||!t)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[e.jsx("p",{className:"font-display text-2xl italic text-ouro-bone",children:"Choose an agent"}),e.jsx("p",{className:"mt-2 text-sm text-ouro-mist",children:"Select an agent from the sidebar to inspect its state."})]});const d=s.agent.attention;return e.jsx(Se.Provider,{value:k,children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 pb-4 border-b border-ouro-moss/30",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("h1",{className:"font-display text-2xl italic font-semibold text-ouro-bone sm:text-3xl",children:t})}),e.jsx(y,{color:hs(d.level),children:d.label})]}),e.jsx("nav",{className:"mt-4 flex gap-0.5 overflow-x-auto border-b border-ouro-moss/20 -mx-1",children:(()=>{const b=n==null?void 0:n.tabOrder;if(!b)return ie;const C=b.map(N=>ie.find(j=>j.id===N)).filter(N=>N!==void 0),h=ie.filter(N=>!b.includes(N.id));return[...C,...h]})().map(b=>e.jsx("button",{type:"button",onClick:()=>S(b.id),className:`shrink-0 px-3 py-2 text-xs font-mono uppercase tracking-wider transition-colors rounded-t-md ${r===b.id?"bg-ouro-moss/20 text-ouro-glow border-b-2 border-ouro-glow":"text-ouro-shadow hover:text-ouro-mist hover:bg-ouro-moss/10"}`,children:b.label},b.id))}),e.jsxs("div",{className:"mt-6",children:[r==="overview"&&e.jsx(xt,{view:s,deskPrefs:n,refreshGeneration:a}),r==="mail"&&e.jsx(wt,{agentName:t,focus:f,onFocusConsumed:g,refreshGeneration:a}),r==="sessions"&&e.jsx(_t,{agentName:t,focus:f,onFocusConsumed:g,deskPrefs:n,refreshGeneration:a}),r==="work"&&e.jsx(Wt,{agentName:t,view:s,focus:f,onFocusConsumed:g,refreshGeneration:a}),r==="connections"&&e.jsx(Zt,{agentName:t,focus:f,onFocusConsumed:g,refreshGeneration:a}),r==="inner"&&e.jsx(Gt,{agentName:t,view:s,refreshGeneration:a}),r==="notes"&&e.jsx(os,{agentName:t,refreshGeneration:a}),r==="runtime"&&e.jsx(rs,{agentName:t,view:s,refreshGeneration:a})]})]})})}function we(){return $e(window.location.hash)}function gs(t){return t==="degraded"||t==="blocked"?"red":t==="stale"?"yellow":t==="active"?"lime":"zinc"}function bs(){var b,C;const[t,s]=u.useState(null),[n,a]=u.useState(((b=we())==null?void 0:b.agent)??""),[o,r]=u.useState(null),[l,f]=u.useState(0),i=u.useRef(0),v=u.useRef(we()),c=u.useCallback(async()=>{var h;try{const N=await z("/machine");if(s(N),!n&&N.agents.length>0){const j=((h=v.current)==null?void 0:h.agent)??N.agents[0].agentName;a(j)}}catch{}},[n]),[k,S]=u.useState(null),g=u.useCallback(async h=>{if(!h){r(null),S(null);return}try{const[N,j]=await Promise.all([z(`/agents/${encodeURIComponent(h)}`),z(`/agents/${encodeURIComponent(h)}/desk-prefs`)]);r(N),S(j)}catch{r(null),S(null)}},[]);u.useEffect(()=>{c()},[c]),u.useEffect(()=>{n&&g(n)},[n,g]),u.useEffect(()=>De(()=>{const N=++i.current;c().then(async()=>{i.current===N&&(n&&(await g(n),i.current!==N)||f(j=>j+1))})}),[c,g,n]),u.useEffect(()=>{const h=()=>{const N=$e(window.location.hash);N&&a(N.agent)};return window.addEventListener("hashchange",h),()=>window.removeEventListener("hashchange",h)},[]);const p=u.useCallback(h=>{a(h),window.history.pushState(null,"",le({agent:h,tab:"overview",focus:void 0}))},[]);if(!t)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-ouro-void",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 h-4 w-4 animate-pulse rounded-full bg-ouro-glow shadow-[0_0_20px_theme(--color-ouro-glow)]"}),e.jsx("p",{className:"font-mono text-sm text-ouro-mist",children:"Connecting to Mailbox…"})]})});const d=t.overview.totals;return e.jsx(Ye,{navbar:e.jsxs(Pe,{children:[e.jsx(Ve,{}),e.jsx(We,{children:e.jsx(de,{children:e.jsx(y,{color:t.overview.daemon.mode==="dev"?"yellow":"lime",children:t.overview.daemon.mode})})})]}),sidebar:e.jsxs(Ze,{className:"bg-ouro-deep",children:[e.jsx(Xe,{className:"border-ouro-moss/30",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-3 w-3 shrink-0 rounded-full bg-ouro-glow shadow-[0_0_16px_theme(--color-ouro-glow)]"}),e.jsx("div",{className:"min-w-0",children:e.jsx("p",{className:"truncate font-display text-lg italic font-semibold text-ouro-bone",children:"Ouro Mailbox"})})]})}),e.jsxs(Ge,{className:"[&>[data-slot=section]+[data-slot=section]]:mt-4",children:[e.jsxs(ue,{children:[e.jsx(me,{className:"text-ouro-mist/60",children:"Machine"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5 px-2",children:[{v:d.liveTasks??0,l:"Tasks",alert:(d.blockedTasks??0)>0},{v:d.openObligations??0,l:"Oblig."},{v:d.activeCodingAgents??0,l:"Coding"}].map(h=>e.jsxs("div",{className:"rounded-md bg-ouro-void/60 px-2 py-1.5 text-center ring-1 ring-ouro-moss/20",children:[e.jsx("div",{className:`text-base font-semibold tabular-nums ${h.alert?"text-ouro-fang":"text-ouro-bone"}`,children:h.v}),e.jsx("div",{className:"text-[9px] uppercase tracking-widest text-ouro-shadow",children:h.l})]},h.l))})]}),e.jsxs(ue,{children:[e.jsx(me,{className:"text-ouro-mist/60",children:"Agents"}),t.agents.map(h=>e.jsx(tt,{current:h.agentName===n,onClick:()=>p(h.agentName),children:e.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(st,{className:"text-ouro-bone",children:h.agentName}),e.jsxs("p",{className:"truncate text-xs text-ouro-shadow",children:[h.tasks.liveCount,"t · ",h.obligations.openCount,"o · ",h.coding.activeCount,"c"]})]}),e.jsx(y,{color:gs(h.attention.level),children:h.attention.label})]})},h.agentName))]})]}),e.jsx(et,{className:"border-ouro-moss/30",children:e.jsxs("div",{className:"px-2 text-xs text-ouro-shadow",children:[e.jsx("p",{className:"font-mono",children:t.overview.runtime.version}),e.jsxs("p",{className:"mt-0.5",children:[t.overview.daemon.mode," · ",t.overview.freshness.status]})]})}),n&&o&&e.jsx("div",{className:"px-4 py-2 border-t border-ouro-moss/20",children:e.jsx("p",{className:"text-xs italic text-ouro-shadow/70",children:(()=>{const h=k==null?void 0:k.statusLine;if(h)return h;const N=o.inner;if(N.status==="running"||N.hasPending)return"thinking through something privately";const A=o.work.obligations.openCount;return A>2?"a few loose ends":A>0?"carrying something":"steady"})()})})]}),children:e.jsx(ps,{agentName:n,view:o,deskPrefs:k,refreshGeneration:l,initialRoute:((C=v.current)==null?void 0:C.agent)===n?v.current:void 0})})}Be.createRoot(document.getElementById("app")).render(e.jsx(u.StrictMode,{children:e.jsx(bs,{})}));
|