@rubytech/create-maxy-code 0.1.200 → 0.1.204
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/package.json +2 -2
- package/payload/platform/scripts/check-no-esm-require.mjs +3 -0
- package/payload/platform/scripts/check-specialist-tool-surface.mjs +323 -0
- package/payload/platform/services/claude-session-manager/dist/fs-watcher.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/fs-watcher.js +7 -7
- package/payload/platform/services/claude-session-manager/dist/fs-watcher.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts +13 -0
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +73 -10
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.js +17 -2
- package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/jsonl-enumerator.d.ts +2 -12
- package/payload/platform/services/claude-session-manager/dist/jsonl-enumerator.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/jsonl-enumerator.js +14 -67
- package/payload/platform/services/claude-session-manager/dist/jsonl-enumerator.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/jsonl-path.d.ts +6 -0
- package/payload/platform/services/claude-session-manager/dist/jsonl-path.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/jsonl-path.js +30 -0
- package/payload/platform/services/claude-session-manager/dist/jsonl-path.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +4 -0
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts +15 -3
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +66 -45
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.d.ts +19 -0
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.js +42 -0
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/systemd-scope.d.ts +15 -0
- package/payload/platform/services/claude-session-manager/dist/systemd-scope.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/systemd-scope.js +34 -0
- package/payload/platform/services/claude-session-manager/dist/systemd-scope.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/systemd-spawn.d.ts +68 -0
- package/payload/platform/services/claude-session-manager/dist/systemd-spawn.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/systemd-spawn.js +277 -0
- package/payload/platform/services/claude-session-manager/dist/systemd-spawn.js.map +1 -0
- package/payload/platform/templates/specialists/agents/coding-assistant.md +73 -0
- package/payload/server/public/assets/{AdminShell-OJlDJakR.js → AdminShell-BcxEZnpu.js} +1 -1
- package/payload/server/public/assets/{Checkbox-DE_tsDq_.js → Checkbox-DL-HdT29.js} +1 -1
- package/payload/server/public/assets/{admin-DbQw1TyC.js → admin-DMo5DWKH.js} +1 -1
- package/payload/server/public/assets/{architectureDiagram-Q4EWVU46-DfZVWJVr.js → architectureDiagram-Q4EWVU46-BoUw4oYz.js} +1 -1
- package/payload/server/public/assets/{blockDiagram-DXYQGD6D-Cd9vcTYg.js → blockDiagram-DXYQGD6D-DOscnO3m.js} +1 -1
- package/payload/server/public/assets/{brand-Ed5R2W5J.css → brand-SZW-27T7.css} +1 -1
- package/payload/server/public/assets/{c4Diagram-AHTNJAMY-zmNCfJ5F.js → c4Diagram-AHTNJAMY-aZ1IuZ_F.js} +1 -1
- package/payload/server/public/assets/channel-CzcSNxDm.js +1 -0
- package/payload/server/public/assets/{chunk-336JU56O-DvHeoV7B.js → chunk-336JU56O-DS3ksXBG.js} +2 -2
- package/payload/server/public/assets/{chunk-426QAEUC-IZknbXMM.js → chunk-426QAEUC-BLRn2STO.js} +1 -1
- package/payload/server/public/assets/{chunk-4TB4RGXK-DN_qw6Oi.js → chunk-4TB4RGXK-BrhOvJ01.js} +1 -1
- package/payload/server/public/assets/{chunk-5FUZZQ4R-tt-46Rcq.js → chunk-5FUZZQ4R-BZZwZX5Q.js} +1 -1
- package/payload/server/public/assets/{chunk-5PVQY5BW-Bl0mxmQP.js → chunk-5PVQY5BW-YXZKnPCz.js} +1 -1
- package/payload/server/public/assets/{chunk-EDXVE4YY-v31HwKDb.js → chunk-EDXVE4YY-DAMCJHKQ.js} +1 -1
- package/payload/server/public/assets/{chunk-ENJZ2VHE-D6T1RStj.js → chunk-ENJZ2VHE-DsD95Bqn.js} +1 -1
- package/payload/server/public/assets/{chunk-ICPOFSXX-DVnIs_5A.js → chunk-ICPOFSXX-DxtrRClx.js} +1 -1
- package/payload/server/public/assets/{chunk-OYMX7WX6-DiZNprr1.js → chunk-OYMX7WX6-CN4kLK-H.js} +1 -1
- package/payload/server/public/assets/{chunk-U2HBQHQK-Cy0qH3H0.js → chunk-U2HBQHQK-BPTv3Oj1.js} +1 -1
- package/payload/server/public/assets/{chunk-X2U36JSP-wR3wBPyu.js → chunk-X2U36JSP-DxBry33v.js} +1 -1
- package/payload/server/public/assets/{chunk-YZCP3GAM-BGOVJLky.js → chunk-YZCP3GAM-BZ4N75oy.js} +1 -1
- package/payload/server/public/assets/{chunk-ZZ45TVLE-14vtIjRh.js → chunk-ZZ45TVLE-Dqr161Q1.js} +1 -1
- package/payload/server/public/assets/classDiagram-6PBFFD2Q-DFOM3vCn.js +1 -0
- package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-HplDfaL1.js +1 -0
- package/payload/server/public/assets/clone-G-2rqnSR.js +1 -0
- package/payload/server/public/assets/{dagre-CG1l6rfK.js → dagre-DtZ0wKkH.js} +1 -1
- package/payload/server/public/assets/{dagre-KV5264BT-DKFDl1Nz.js → dagre-KV5264BT-BPKhT-ZX.js} +1 -1
- package/payload/server/public/assets/{data-b1v7Pjly.js → data-D6IQdm0R.js} +1 -1
- package/payload/server/public/assets/{diagram-5BDNPKRD-PJd29fkg.js → diagram-5BDNPKRD-CATnafi7.js} +1 -1
- package/payload/server/public/assets/{diagram-G4DWMVQ6-Bz7_SWJH.js → diagram-G4DWMVQ6-ChZYQfji.js} +1 -1
- package/payload/server/public/assets/{diagram-MMDJMWI5-CmWknm9v.js → diagram-MMDJMWI5-DHW6kYd3.js} +1 -1
- package/payload/server/public/assets/{diagram-TYMM5635-CLYRluM2.js → diagram-TYMM5635-CnS4Zci8.js} +1 -1
- package/payload/server/public/assets/{erDiagram-SMLLAGMA-EWVKGrgT.js → erDiagram-SMLLAGMA-DKYv2YWp.js} +1 -1
- package/payload/server/public/assets/{flowDiagram-DWJPFMVM-CNtfJIG7.js → flowDiagram-DWJPFMVM-BWvoZWlh.js} +1 -1
- package/payload/server/public/assets/{ganttDiagram-T4ZO3ILL-SIlymJ6A.js → ganttDiagram-T4ZO3ILL-CpCb-xKy.js} +1 -1
- package/payload/server/public/assets/{gitGraphDiagram-UUTBAWPF-DWVl6CUl.js → gitGraphDiagram-UUTBAWPF-CvHrDKQ-.js} +1 -1
- package/payload/server/public/assets/{graph-BOcblKu9.js → graph-PkZKVkWD.js} +1 -1
- package/payload/server/public/assets/{graph-labels-CH-Tffon.js → graph-labels-CWJy0O4w.js} +1 -1
- package/payload/server/public/assets/{graphlib-i-qJjJM7.js → graphlib-DjnyHqGy.js} +1 -1
- package/payload/server/public/assets/{infoDiagram-42DDH7IO-D66Yr_7b.js → infoDiagram-42DDH7IO-D_MywcVn.js} +1 -1
- package/payload/server/public/assets/{ishikawaDiagram-UXIWVN3A-C4mQi7AB.js → ishikawaDiagram-UXIWVN3A-N9m-f-Eb.js} +1 -1
- package/payload/server/public/assets/{journeyDiagram-VCZTEJTY-7Vp2UBlF.js → journeyDiagram-VCZTEJTY-DE0q7uSM.js} +1 -1
- package/payload/server/public/assets/{kanban-definition-6JOO6SKY-nEDANSe9.js → kanban-definition-6JOO6SKY-Dj5hb9Bq.js} +1 -1
- package/payload/server/public/assets/{line-BxGbTwly.js → line-C6ph0i4M.js} +1 -1
- package/payload/server/public/assets/{mermaid-parser.core-CAG4AdDd.js → mermaid-parser.core-BrfmEvCA.js} +1 -1
- package/payload/server/public/assets/{mermaid.core-prtUaAsI.js → mermaid.core-DYnHKfDv.js} +3 -3
- package/payload/server/public/assets/{mindmap-definition-QFDTVHPH-Dvcph8zi.js → mindmap-definition-QFDTVHPH-DaSaZfhR.js} +1 -1
- package/payload/server/public/assets/{pieDiagram-DEJITSTG-C4qHs6Vb.js → pieDiagram-DEJITSTG-BAu9Ezbv.js} +1 -1
- package/payload/server/public/assets/{public-DIyn-De4.js → public-UKgkJxKv.js} +3 -3
- package/payload/server/public/assets/{quadrantDiagram-34T5L4WZ-I9Et2l2H.js → quadrantDiagram-34T5L4WZ-DRsbL1Xd.js} +1 -1
- package/payload/server/public/assets/{requirementDiagram-MS252O5E-DLKlY81v.js → requirementDiagram-MS252O5E-B9QcsXV6.js} +1 -1
- package/payload/server/public/assets/{sankeyDiagram-XADWPNL6-dX3pgMv_.js → sankeyDiagram-XADWPNL6-DsZbvIlD.js} +1 -1
- package/payload/server/public/assets/{sequenceDiagram-FGHM5R23-C4qTAl3F.js → sequenceDiagram-FGHM5R23-BlT4O2N8.js} +1 -1
- package/payload/server/public/assets/{stateDiagram-FHFEXIEX-DzA0NObk.js → stateDiagram-FHFEXIEX-JFgk1K3Y.js} +1 -1
- package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-NXz27DaV.js +1 -0
- package/payload/server/public/assets/{timeline-definition-GMOUNBTQ-D-DPUQCU.js → timeline-definition-GMOUNBTQ-DOsHw1ip.js} +1 -1
- package/payload/server/public/assets/{useSelectionMode-C4HDuwDT.js → useSelectionMode-JDGvwvIk.js} +1 -1
- package/payload/server/public/assets/{vennDiagram-DHZGUBPP-C_RwTsUi.js → vennDiagram-DHZGUBPP-CQWIhqZY.js} +1 -1
- package/payload/server/public/assets/{wardleyDiagram-NUSXRM2D-BAftlsC2.js → wardleyDiagram-NUSXRM2D-D5Fh7YVL.js} +1 -1
- package/payload/server/public/assets/{xychartDiagram-5P7HB3ND-C_tKMCMd.js → xychartDiagram-5P7HB3ND-C-tINQEs.js} +1 -1
- package/payload/server/public/data.html +5 -5
- package/payload/server/public/graph.html +6 -6
- package/payload/server/public/index.html +6 -6
- package/payload/server/public/public.html +5 -5
- package/payload/server/server.js +235 -79
- package/payload/server/public/assets/channel-DCJza6li.js +0 -1
- package/payload/server/public/assets/classDiagram-6PBFFD2Q-DEo4goqG.js +0 -1
- package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-CoAVCeH7.js +0 -1
- package/payload/server/public/assets/clone-CLnBlH9n.js +0 -1
- package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-Dsgd5hEe.js +0 -1
- /package/payload/server/public/assets/{brand-CCOPpjM4.js → brand-SzZmKKjz.js} +0 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// Task 552 — non-PTY spawn primitive for claude scope units.
|
|
2
|
+
//
|
|
3
|
+
// Wraps `child_process.spawn` around `systemd-run --user --scope ...` so
|
|
4
|
+
// the manager allocates ZERO file descriptors per spawn (stdio: 'ignore',
|
|
5
|
+
// detached + unref). The previous `spawnPty` adapter wrapped node-pty
|
|
6
|
+
// around the same systemd-run argv, which opened a master pty fd in the
|
|
7
|
+
// manager process — one fd leaked per /rc-spawn click and one per
|
|
8
|
+
// rc-daemon respawn until V8 GC fired.
|
|
9
|
+
//
|
|
10
|
+
// This primitive is for spawns the manager never talks to: `/rc-spawn`
|
|
11
|
+
// (fire-and-forget, the route never writes back to the child) and the
|
|
12
|
+
// rc-daemon supervisor (stdout via journal, exit detection via
|
|
13
|
+
// systemctl). Channel-bridge spawns (`/spawn`, `:sessionId/input`,
|
|
14
|
+
// WhatsApp / public-agent / channel-pty-bridge) keep node-pty because
|
|
15
|
+
// they genuinely need bidirectional IO with the manager.
|
|
16
|
+
//
|
|
17
|
+
// Argv composition reuses `buildSystemdRunArgv` from systemd-scope.ts so
|
|
18
|
+
// the SIGHUP wrap, per-spawn unit token, slice membership, and
|
|
19
|
+
// `--setenv=KEY=VAL` env block are byte-identical with the PTY spawn
|
|
20
|
+
// path.
|
|
21
|
+
//
|
|
22
|
+
// Task 554 — activation gate reads ActiveState + ControlGroup + cgroup.procs,
|
|
23
|
+
// NOT MainPID. `systemctl show -p MainPID` returns nothing for transient
|
|
24
|
+
// scope units on systemd 255 (Ubuntu 24.04), so the prior MainPID poll
|
|
25
|
+
// timed out at 5 s even though the scope was already live. The new gate:
|
|
26
|
+
//
|
|
27
|
+
// - One `systemctl show -p ActiveState -p ControlGroup` call per poll
|
|
28
|
+
// iteration.
|
|
29
|
+
// - The pid is read from `cgroup.procs` under the path systemd reports
|
|
30
|
+
// in `ControlGroup`. The minimum pid wins — the in-place exec chain
|
|
31
|
+
// `systemd-run → /bin/sh → claude` preserves the original pid, which
|
|
32
|
+
// is the lowest in the cgroup.
|
|
33
|
+
// - Three terminal outcomes distinguish how a spawn failed:
|
|
34
|
+
// systemd-start-failure — ActiveState terminated and cgroup.procs
|
|
35
|
+
// was never populated (bad cwd, missing binary, slice not loaded).
|
|
36
|
+
// boot-crash — cgroup.procs was populated then emptied
|
|
37
|
+
// before ActiveState reached `active`. Claude itself crashed at
|
|
38
|
+
// init; observed pid is captured in the error message.
|
|
39
|
+
// activation-timeout — deadline reached without ActiveState ever
|
|
40
|
+
// leaving the activating set. Reserved for genuine systemd hangs;
|
|
41
|
+
// the terminal ActiveState value is logged.
|
|
42
|
+
// - Before any terminal reject, `stopScopeUnit` is called against the
|
|
43
|
+
// unit so a partially-registered scope cannot leak. The eight
|
|
44
|
+
// `claude-session-rc-daemon-*.scope` units leaked on the laptop by
|
|
45
|
+
// the prior bug are reaped at session-manager startup via
|
|
46
|
+
// `reapOrphanNonPtyScopes` (systemd-scope.ts).
|
|
47
|
+
import { spawn } from 'node:child_process';
|
|
48
|
+
import { readFileSync } from 'node:fs';
|
|
49
|
+
import { buildSystemdRunArgv, defaultSystemctlRunner, scopeUnitName, stopScopeUnit, } from './systemd-scope.js';
|
|
50
|
+
const ACTIVE_STATES = new Set(['active', 'activating', 'reloading']);
|
|
51
|
+
/** Spawn `systemd-run --user --scope ... <claudeBin> <claudeArgs>` so the
|
|
52
|
+
* manager holds no file descriptors for the resulting claude process.
|
|
53
|
+
* Returns once cgroup.procs is non-empty AND ActiveState is `active`.
|
|
54
|
+
* On terminal failure, stops the partially-registered scope and rejects
|
|
55
|
+
* with one of three distinct error tokens. */
|
|
56
|
+
export async function systemdSpawn(p) {
|
|
57
|
+
const run = p.runSystemctl ?? defaultSystemctlRunner;
|
|
58
|
+
const readCgroupProcs = p.readCgroupProcs ?? defaultReadCgroupProcs;
|
|
59
|
+
const spawnChild = p.spawnChild ?? defaultSpawnChild;
|
|
60
|
+
const activationTimeoutMs = p.activationTimeoutMs ?? 5_000;
|
|
61
|
+
const pollIntervalMs = p.activationPollIntervalMs ?? 50;
|
|
62
|
+
const wrapped = buildSystemdRunArgv({
|
|
63
|
+
unitToken: p.unitToken,
|
|
64
|
+
claudeBin: p.claudeBin,
|
|
65
|
+
claudeArgs: p.claudeArgs,
|
|
66
|
+
env: p.env,
|
|
67
|
+
cwd: p.cwd,
|
|
68
|
+
});
|
|
69
|
+
// Spawn systemd-run as a detached child with stdio:'ignore'. The manager
|
|
70
|
+
// process holds zero fds to it; user systemd owns the scope cgroup's
|
|
71
|
+
// lifetime. `detached: true` puts the child in its own process group so
|
|
72
|
+
// it survives manager exit (systemd already owns it once registered, but
|
|
73
|
+
// the detach is belt-and-braces against PG signal forwarding).
|
|
74
|
+
let child;
|
|
75
|
+
const errorBox = { err: null };
|
|
76
|
+
try {
|
|
77
|
+
child = spawnChild(wrapped.cmd, wrapped.args, {
|
|
78
|
+
cwd: p.cwd,
|
|
79
|
+
env: process.env,
|
|
80
|
+
stdio: 'ignore',
|
|
81
|
+
detached: true,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
throw new Error(`[systemd-spawn] spawn-failed unitToken=${p.unitToken} err=${err instanceof Error ? err.message : String(err)}`);
|
|
86
|
+
}
|
|
87
|
+
child.on('error', (err) => {
|
|
88
|
+
errorBox.err = err;
|
|
89
|
+
});
|
|
90
|
+
child.unref();
|
|
91
|
+
const unit = scopeUnitName(p.unitToken);
|
|
92
|
+
const deadline = Date.now() + activationTimeoutMs;
|
|
93
|
+
let seenPid = null;
|
|
94
|
+
let lastControlGroup = '';
|
|
95
|
+
let lastActiveState = '';
|
|
96
|
+
while (Date.now() < deadline) {
|
|
97
|
+
if (errorBox.err) {
|
|
98
|
+
// Pair with stop so the scope (if it managed to register before the
|
|
99
|
+
// child errored on the manager side) doesn't leak. systemctl's stop
|
|
100
|
+
// is harmless when the unit was never loaded.
|
|
101
|
+
await safeStop(run, p.unitToken);
|
|
102
|
+
throw new Error(`[systemd-spawn] child-error unitToken=${p.unitToken} err=${errorBox.err.message}`);
|
|
103
|
+
}
|
|
104
|
+
const show = run([
|
|
105
|
+
'--user', 'show',
|
|
106
|
+
'-p', 'ActiveState',
|
|
107
|
+
'-p', 'ControlGroup',
|
|
108
|
+
unit,
|
|
109
|
+
]);
|
|
110
|
+
const fields = show.exitCode === 0 ? parseShowFields(show.stdout) : {};
|
|
111
|
+
const activeState = fields.ActiveState ?? '';
|
|
112
|
+
const controlGroup = fields.ControlGroup ?? '';
|
|
113
|
+
if (activeState)
|
|
114
|
+
lastActiveState = activeState;
|
|
115
|
+
if (controlGroup)
|
|
116
|
+
lastControlGroup = controlGroup;
|
|
117
|
+
if (controlGroup) {
|
|
118
|
+
const pids = readCgroupProcs(controlGroup);
|
|
119
|
+
if (pids.length > 0) {
|
|
120
|
+
seenPid = Math.min(...pids);
|
|
121
|
+
if (activeState === 'active') {
|
|
122
|
+
return buildHandle(seenPid, p.unitToken, run);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Terminal non-active state — classify by whether a pid was ever
|
|
127
|
+
// observed. systemd's lifecycle: scope → activating → active → … OR
|
|
128
|
+
// scope → activating → failed/inactive if start fails or claude exits
|
|
129
|
+
// during init.
|
|
130
|
+
if (activeState && !ACTIVE_STATES.has(activeState)) {
|
|
131
|
+
await safeStop(run, p.unitToken, seenPid);
|
|
132
|
+
if (seenPid !== null) {
|
|
133
|
+
throw new Error(`[systemd-spawn] boot-crash unitToken=${p.unitToken} observedPid=${seenPid} controlGroup=${lastControlGroup} activeState=${activeState}`);
|
|
134
|
+
}
|
|
135
|
+
throw new Error(`[systemd-spawn] systemd-start-failure unitToken=${p.unitToken} activeState=${activeState}`);
|
|
136
|
+
}
|
|
137
|
+
await sleep(pollIntervalMs);
|
|
138
|
+
}
|
|
139
|
+
// Deadline hit while still activating (or no controlGroup ever
|
|
140
|
+
// reported). Stop the scope to avoid leaking it, then reject.
|
|
141
|
+
await safeStop(run, p.unitToken, seenPid);
|
|
142
|
+
throw new Error(`[systemd-spawn] activation-timeout unitToken=${p.unitToken} activeState=${lastActiveState || 'unknown'} timeoutMs=${activationTimeoutMs}`);
|
|
143
|
+
}
|
|
144
|
+
function parseShowFields(stdout) {
|
|
145
|
+
const out = {};
|
|
146
|
+
for (const line of stdout.split('\n')) {
|
|
147
|
+
const eq = line.indexOf('=');
|
|
148
|
+
if (eq < 0)
|
|
149
|
+
continue;
|
|
150
|
+
out[line.slice(0, eq)] = line.slice(eq + 1).trim();
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
/** Read /sys/fs/cgroup<controlGroup>/cgroup.procs. Returns the parsed pids
|
|
155
|
+
* (one per line). Empty list on ENOENT / parse failure — the caller treats
|
|
156
|
+
* empty as "scope not yet populated", which is the truthful default. */
|
|
157
|
+
function defaultReadCgroupProcs(controlGroup) {
|
|
158
|
+
if (!controlGroup)
|
|
159
|
+
return [];
|
|
160
|
+
// ControlGroup is the systemd-relative path (e.g.
|
|
161
|
+
// `/user.slice/user-1000.slice/.../foo.scope`). Concatenate with
|
|
162
|
+
// /sys/fs/cgroup for the unified hierarchy.
|
|
163
|
+
const path = `/sys/fs/cgroup${controlGroup}/cgroup.procs`;
|
|
164
|
+
try {
|
|
165
|
+
const raw = readFileSync(path, 'utf8');
|
|
166
|
+
const pids = [];
|
|
167
|
+
for (const line of raw.split('\n')) {
|
|
168
|
+
const trimmed = line.trim();
|
|
169
|
+
if (!trimmed)
|
|
170
|
+
continue;
|
|
171
|
+
const n = Number.parseInt(trimmed, 10);
|
|
172
|
+
if (Number.isFinite(n) && n > 0)
|
|
173
|
+
pids.push(n);
|
|
174
|
+
}
|
|
175
|
+
return pids;
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** Best-effort cleanup of a partially-registered scope on terminal
|
|
182
|
+
* failure. Swallows stop errors — the caller is already about to reject
|
|
183
|
+
* with the original cause; surfacing a secondary stop failure would mask
|
|
184
|
+
* it. */
|
|
185
|
+
async function safeStop(run, unitToken, pid = null) {
|
|
186
|
+
try {
|
|
187
|
+
await stopScopeUnit(run, unitToken, { pid: pid ?? undefined });
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
/* deliberately swallow — original failure is what the caller needs */
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function buildHandle(pid, unitToken, run) {
|
|
194
|
+
const unit = scopeUnitName(unitToken);
|
|
195
|
+
return {
|
|
196
|
+
pid,
|
|
197
|
+
unitToken,
|
|
198
|
+
async waitForExit(opts) {
|
|
199
|
+
const interval = opts?.pollIntervalMs ?? 250;
|
|
200
|
+
while (true) {
|
|
201
|
+
const r = run(['--user', 'show', '-p', 'ActiveState', '--value', unit]);
|
|
202
|
+
const state = r.exitCode === 0 ? r.stdout.trim() : '';
|
|
203
|
+
// Empty state OR exit code 4 (unit not loaded) means the transient
|
|
204
|
+
// unit has been collected — treat as exited.
|
|
205
|
+
if (!state || !ACTIVE_STATES.has(state)) {
|
|
206
|
+
return readScopeExit(run, unit);
|
|
207
|
+
}
|
|
208
|
+
await sleep(interval);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
async readJournalTail(maxBytes) {
|
|
212
|
+
return readJournal(unit, maxBytes);
|
|
213
|
+
},
|
|
214
|
+
async stop() {
|
|
215
|
+
await stopScopeUnit(run, unitToken, { pid });
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function readScopeExit(run, unit) {
|
|
220
|
+
const r = run([
|
|
221
|
+
'--user',
|
|
222
|
+
'show',
|
|
223
|
+
'-p', 'Result',
|
|
224
|
+
'-p', 'ExecMainStatus',
|
|
225
|
+
'-p', 'ExecMainCode',
|
|
226
|
+
unit,
|
|
227
|
+
]);
|
|
228
|
+
if (r.exitCode !== 0) {
|
|
229
|
+
return { result: 'unknown', exitCode: null, code: null };
|
|
230
|
+
}
|
|
231
|
+
const fields = {};
|
|
232
|
+
for (const line of r.stdout.split('\n')) {
|
|
233
|
+
const eq = line.indexOf('=');
|
|
234
|
+
if (eq < 0)
|
|
235
|
+
continue;
|
|
236
|
+
fields[line.slice(0, eq)] = line.slice(eq + 1);
|
|
237
|
+
}
|
|
238
|
+
const statusRaw = fields.ExecMainStatus ?? '';
|
|
239
|
+
const status = statusRaw === '' ? null : Number.parseInt(statusRaw, 10);
|
|
240
|
+
return {
|
|
241
|
+
result: fields.Result || 'unknown',
|
|
242
|
+
exitCode: Number.isFinite(status) ? status : null,
|
|
243
|
+
code: fields.ExecMainCode || null,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
async function readJournal(unit, maxBytes) {
|
|
247
|
+
return new Promise((resolve) => {
|
|
248
|
+
let buf = '';
|
|
249
|
+
try {
|
|
250
|
+
const child = spawn('journalctl', ['--user', '-u', unit, '-n', '200', '--no-pager', '--output=cat'], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
251
|
+
child.stdout?.on('data', (chunk) => {
|
|
252
|
+
buf += chunk.toString('utf8');
|
|
253
|
+
if (buf.length > maxBytes * 2)
|
|
254
|
+
buf = buf.slice(buf.length - maxBytes);
|
|
255
|
+
});
|
|
256
|
+
child.on('error', () => resolve(''));
|
|
257
|
+
child.on('close', () => {
|
|
258
|
+
resolve(buf.length > maxBytes ? buf.slice(buf.length - maxBytes) : buf);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
resolve('');
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function defaultSpawnChild(cmd, args, opts) {
|
|
267
|
+
const child = spawn(cmd, [...args], opts);
|
|
268
|
+
return {
|
|
269
|
+
pid: child.pid,
|
|
270
|
+
unref: () => child.unref(),
|
|
271
|
+
on: (event, cb) => { child.on(event, cb); },
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function sleep(ms) {
|
|
275
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=systemd-spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemd-spawn.js","sourceRoot":"","sources":["../src/systemd-spawn.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,sEAAsE;AACtE,wEAAwE;AACxE,kEAAkE;AAClE,uCAAuC;AACvC,EAAE;AACF,uEAAuE;AACvE,sEAAsE;AACtE,+DAA+D;AAC/D,mEAAmE;AACnE,sEAAsE;AACtE,yDAAyD;AACzD,EAAE;AACF,yEAAyE;AACzE,+DAA+D;AAC/D,qEAAqE;AACrE,QAAQ;AACR,EAAE;AACF,8EAA8E;AAC9E,yEAAyE;AAC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AAG,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAA;YACvE,CAAC,CAAC,CAAA;YACF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;YACpC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACrB,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;YACzE,CAAC,CAAC,CAAA;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,EAAE,CAAC,CAAA;QACb,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW,EAAE,IAAuB,EAAE,IAAe;IAC9E,MAAM,KAAK,GAAiB,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;IACvD,OAAO;QACL,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE;QAC1B,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA,CAAC,CAAC;KAC3C,CAAA;AACH,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-assistant
|
|
3
|
+
description: "Shell commands, git operations, code repositories, file reads and edits, running tests and builds, and developer tooling. Delegate when the work needs a shell, touches a git repository, reads or edits source files on disk, runs tests or builds, or otherwise belongs in a developer terminal."
|
|
4
|
+
summary: "Runs shell commands, drives git repositories, and reads or edits code on your behalf — the specialist you reach for when the work belongs in a developer terminal."
|
|
5
|
+
model: claude-opus-4-8[1m]
|
|
6
|
+
tools: Bash, Read, Edit, Write, Skill, Grep, Glob, mcp__plugin_memory_memory__memory-search
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Coding Assistant
|
|
10
|
+
|
|
11
|
+
You execute shell, git, and code-editing work on the operator's device. Admin delegates each task to you with a concrete brief; you run the commands, return the results, and stop.
|
|
12
|
+
|
|
13
|
+
## Three rules
|
|
14
|
+
|
|
15
|
+
These three rules win when anything else in this prompt conflicts with them.
|
|
16
|
+
|
|
17
|
+
1. **Be precise.** Every claim has a source: a tool result, a log line, a file you read. No "likely", no "appears to".
|
|
18
|
+
2. **Be concise.** Three sentences or fewer. If you cannot answer in three, ask in five words.
|
|
19
|
+
3. **Show your evidence.** Gather evidence before forming a hypothesis. One measurement beats three guesses.
|
|
20
|
+
|
|
21
|
+
## Scope
|
|
22
|
+
|
|
23
|
+
You handle work that belongs in a developer terminal: shell commands, git operations (clone, pull, fetch, status, log, diff, branch, checkout, commit, push when admin explicitly asks), reading and editing source files on disk, running tests and builds, grepping codebases, and inspecting developer tooling output. Admin routes shell and code work here because the admin seat blocks `Bash`, `Write`, `Edit`, and `MultiEdit` directly.
|
|
24
|
+
|
|
25
|
+
The operator's machine is the surface — paths admin gives you resolve against the filesystem you are running on. If a brief names a path that does not exist, report the absence with the path admin gave you; do not search for a "close match".
|
|
26
|
+
|
|
27
|
+
## Out of scope
|
|
28
|
+
|
|
29
|
+
- Document authoring, PDF rendering, image generation, website publishing — those route to `content-producer`.
|
|
30
|
+
- Graph writes (memory-write, contact-create, work-create, schedule-event) — those route to `database-operator` or `personal-assistant`.
|
|
31
|
+
- Ingestion of documents, transcripts, or archives into the graph — that routes to `database-operator` or `archive-ingest-operator`.
|
|
32
|
+
- Web research and external lookups — those route to `research-assistant`.
|
|
33
|
+
- Messaging, scheduling, browser automation, tunnel and domain setup — those route to `personal-assistant`.
|
|
34
|
+
|
|
35
|
+
When a brief mixes coding work with one of the above (for example, "clone the repo and write a brochure from its README"), do the coding portion and hand the rest back to admin so it can dispatch the right specialist.
|
|
36
|
+
|
|
37
|
+
## Brain-first read before action
|
|
38
|
+
|
|
39
|
+
Before running a destructive or state-changing command (anything that writes to disk, mutates a git ref, installs packages, or removes files), confirm the target with one read — `git status`, `ls`, `Read`, or `Grep`. The admin's brief names the outcome; the read confirms you are acting on the right tree.
|
|
40
|
+
|
|
41
|
+
For lookups admin may have already saved (a repo path, a service name, a frequently-used directory), `memory-search` is available — search the graph before assuming the brief's path is the only one. The graph is the canonical store; the filesystem is the execution surface.
|
|
42
|
+
|
|
43
|
+
## Git operations
|
|
44
|
+
|
|
45
|
+
- Read-only commands (`status`, `log`, `diff`, `branch`, `show`, `ls-files`) are safe; run them without further confirmation.
|
|
46
|
+
- State-changing commands (`pull`, `fetch`, `merge`, `rebase`, `checkout`, `commit`, `reset`, `stash`) require the brief to name the repository and the desired outcome. Run them from inside the repository directory; never with `cd <repo> && git <cmd>` chained, since the chain forces a permission prompt.
|
|
47
|
+
- `push` is run only when admin explicitly asks. Never `push --force` unless admin's brief names that flag with reason.
|
|
48
|
+
- Never amend a commit unless admin asks. New commits are the default.
|
|
49
|
+
- Never run `git config` to mutate user identity or repo config.
|
|
50
|
+
|
|
51
|
+
## Editing files
|
|
52
|
+
|
|
53
|
+
`Read` the file before `Edit`. Edits target the file the operator names; do not refactor surrounding code, do not delete comments you did not author, do not add error handling or fallbacks the brief did not request. The doctrine is in this repo's `CLAUDE.md` files at every level above the file you are editing — read them when an edit touches a file you have not edited before in this session.
|
|
54
|
+
|
|
55
|
+
## Running commands
|
|
56
|
+
|
|
57
|
+
Use `Bash` for one command at a time when possible. Long pipelines and chained commands are fine when the chain expresses one logical operation; do not chain unrelated commands to "save a turn". When a command is long-running (a build, a test suite, a `git clone` of a large repo), run it in the foreground and report the result when it completes; the admin agent waits.
|
|
58
|
+
|
|
59
|
+
When a command exits non-zero, return the exit code and the relevant stderr verbatim. Do not retry the same command unless admin asks. Do not present a fallback as if the original request succeeded.
|
|
60
|
+
|
|
61
|
+
## Output contract
|
|
62
|
+
|
|
63
|
+
Return to the admin agent: what you ran (the commands, in order), the outcome (success or failure with the exit code), the relevant output (trimmed to what answers the brief), and any blockers. When the brief was "git pull", the outcome line is the `git pull` summary (`Already up to date.` or the fast-forward range). When the brief was a test run, the outcome line names how many tests passed, failed, and skipped.
|
|
64
|
+
|
|
65
|
+
Never include credentials, tokens, or `.env` contents in the response. If a command would print them, run a variant that does not.
|
|
66
|
+
|
|
67
|
+
## When a tool returns an error
|
|
68
|
+
|
|
69
|
+
Name the tool, what you tried, and what the error said. Do not retry the same tool on the same target inside one turn. If switching to another tool is the right move, say why the alternative should succeed where the first did not.
|
|
70
|
+
|
|
71
|
+
## Plain English
|
|
72
|
+
|
|
73
|
+
**The first tool call MUST be `Skill plainly`. Any prose tool call before the skill content is loaded into context is a contract violation.** Load `skill-load skillName=plainly` on the first turn and apply it to the prose payload returned to admin (the "what you did" line, the summary, the blocker description). It does not apply to command output you are quoting verbatim — those are byte-faithful relays, not prose.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-DD-I1_y5.js";import{c as t,d as n,i as r,l as i,o as a,s as o,t as s}from"./brand-CCOPpjM4.js";var c=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),l=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),u=i(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),d=i(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),f=i(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),p=i(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),m=i(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),h=i(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),g=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),_=i(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),v=i(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),y=i(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),b=i(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),x=i(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),S=i(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),C=i(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),ee=i(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),w=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),T=i(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),E=e(n(),1),D=a(),O=`maxy-shell-side-px`;function k(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function A(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-k());return Math.min(Math.max(e,248),n)}function j(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(O);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return A(t)}catch{}return 264}function te({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>j()),i=(0,E.useRef)(n);(0,E.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,E.useCallback)(()=>{r(e=>{let t=A(e);return t===e?e:t})},[]);(0,E.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(A(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(O,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=A(264);r(e);try{window.localStorage.removeItem(O)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,D.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var M=`maxy-admin-session`,N=typeof BroadcastChannel<`u`;function P(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function F(e){if(!N)return()=>{};let t=new BroadcastChannel(M),n=t=>{if(!P(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var I=`maxy-admin-session-key`;function L(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function R(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`?n:`unknown-401`}function z(){try{return sessionStorage.getItem(I)}catch{return null}}function B(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,E.useState)(t),a=(0,E.useRef)(t);(0,E.useEffect)(()=>{a.current=r},[r]),(0,E.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,E.useState)(0),[c,l]=(0,E.useState)(null);(0,E.useEffect)(()=>F(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1),l(null))}),[n]);let u=(0,E.useCallback)(()=>{try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,E.useCallback)(async(e,t)=>{let r=a.current,o=L(e,r),c=await fetch(o,t);if(c.status!==401)return c;let d=await R(c);if(d===`session-missing`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),u(),c;if(d!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:d}),c;let f=z();if(!f||f===r)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),l({message:`Your admin session was renewed in another tab. Click to reload.`,reason:`session-not-registered`}),c;i(f),a.current=f,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${f.slice(0,8)} surface=${n} path=${e}`);let p=L(e,f),m=await fetch(p,t);return m.status===401&&(console.warn(`[useAdminFetch] outcome=redirect-to-login reason=second-401-after-retry surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:`session-not-registered`})),m},[u,n]),cacheKey:r,sessionRefetchNonce:o,banner:c,reloadToLogin:u}}var V=(0,E.createContext)(null);function H({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,E.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=L(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await R(o),c=e.slice(-8);if(s===`session-not-registered`){let a=z();if(a&&a!==e){let e=L(r,a),o=await fetch(e,i);return o.status===401?(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,D.jsx)(V.Provider,{value:i,children:r})}function ne(){return(0,E.useContext)(V)}function re(e){let t=ne();return(0,E.useMemo)(()=>t||(async(t,n)=>fetch(e?L(t,e):t,n)),[t,e])}function U(e){let{businessName:t,onNavigate:n,onToggleSidebar:i,sidebarOpen:a,onLogout:c}=e,[l,f]=(0,E.useState)(!1),m=(0,E.useRef)(null),g=(0,E.useRef)(null),S=re(null),[C,w]=(0,E.useState)(null),[O,k]=(0,E.useState)(!1),[A,j]=(0,E.useState)(null),[te,M]=(0,E.useState)(null),[N,P]=(0,E.useState)(null),[F,I]=(0,E.useState)(``);(0,E.useEffect)(()=>{I(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{m.current&&!m.current.contains(e.target)&&f(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&f(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]),(0,E.useEffect)(()=>{l&&g.current?.focus()},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=!1;return S(`/api/admin/version`).then(e=>e.json()).then(t=>{e||P(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[l,S]);let L=(0,E.useCallback)(()=>{f(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),R=(0,E.useCallback)(e=>{f(!1),n(e)},[n]),z=(0,E.useCallback)(async()=>{if(C!==null){w(null),M(null);return}k(!0),j(null);try{let e=await S(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);w((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),j(e instanceof Error?e.message:String(e)),w([])}finally{k(!1)}},[C,S]),B=(0,E.useCallback)(e=>{M(null),w(t=>t?.filter(t=>t.slug!==e)??null),S(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[S]),V=(0,E.useCallback)(()=>{f(!1),c()},[c]),H=t||s.productName;return(0,D.jsxs)(`header`,{className:`admin-header`,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":a?`Hide sidebar`:`Show sidebar`,title:a?`Hide sidebar`:`Show sidebar`,"aria-expanded":a,onClick:i,children:a?(0,D.jsx)(b,{size:20,strokeWidth:1.5}):(0,D.jsx)(x,{size:20,strokeWidth:1.5})}),(0,D.jsxs)(`div`,{className:`chat-header-label`,children:[(0,D.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,D.jsx)(`img`,{src:r,alt:``,className:`chat-logo`})}),(0,D.jsx)(`h1`,{className:`chat-tagline`,children:H})]}),(0,D.jsxs)(`div`,{className:`chat-burger-wrap`,ref:m,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:L,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":l,children:(0,D.jsx)(y,{size:20})}),l&&(0,D.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,D.jsxs)(`button`,{ref:g,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>R(`data`),children:[(0,D.jsx)(d,{size:14}),` Data`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>R(`graph`),children:[(0,D.jsx)(ee,{size:14}),` Graph`]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:z,children:[(0,D.jsx)(p,{size:14}),` Public`,O&&(0,D.jsx)(_,{size:12,className:`spin`})]}),C!==null&&(0,D.jsxs)(`div`,{className:`chat-menu-agents`,children:[A&&(0,D.jsx)(`span`,{className:`chat-menu-agent-error`,children:A}),C.length===0&&!A&&(0,D.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),C.map(e=>(0,D.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,D.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,D.jsxs)(`span`,{className:`agent-text`,children:[(0,D.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,D.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),te===e.slug?(0,D.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>B(e.slug),children:(0,D.jsx)(u,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>M(null),children:(0,D.jsx)(T,{size:12})})]}):(0,D.jsxs)(`span`,{className:`agent-actions`,children:[(0,D.jsx)(`a`,{href:`${F}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>f(!1),children:(0,D.jsx)(p,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>M(e.slug),children:(0,D.jsx)(o,{size:12})})]})]},e.slug))]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,D.jsx)(h,{size:14}),(0,D.jsxs)(`span`,{className:`version-installed`,children:[N?`v${N.installed}`:`…`,N&&!N.updateAvailable&&(0,D.jsx)(`span`,{className:`version-uptodate-dot`}),N?.updateAvailable&&(0,D.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:V,children:[(0,D.jsx)(v,{size:14}),` Log out`]})]})]})]})}function ie(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}var ae=`https://claude.ai/code`;function oe(e){let{businessName:n,cacheKey:r,role:i,userName:a,userAvatar:u,onSelectProjects:d,onSelectPeople:h,onSelectTasks:_,onSelectAgents:v,onCloseMobileDrawer:y,collapsed:b}=e,x=re(r),ee=s.productName,T=typeof a==`string`?a:a===null?`name unavailable`:n||ee,O=(T.trim().charAt(0)||`?`).toUpperCase(),[k,A]=(0,E.useState)(`artefacts`),[j,te]=(0,E.useState)([]),[M,N]=(0,E.useState)(!1),[P,F]=(0,E.useState)(null),[I,L]=(0,E.useState)(!1),[R,z]=(0,E.useState)(`all`),[B,V]=(0,E.useState)(null),[H,ne]=(0,E.useState)([]),[U,oe]=(0,E.useState)(!1),[W,G]=(0,E.useState)(null),[K,ce]=(0,E.useState)(!1),[q,le]=(0,E.useState)(!1),[ue,J]=(0,E.useState)(null),[Y,de]=(0,E.useState)(new Set),[fe,pe]=(0,E.useState)(new Set),[X,me]=(0,E.useState)(!1),he=(0,E.useCallback)(e=>{if(y(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),V({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),V({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),ie(r,e.downloadPath,e.downloadRoot??`data`),V({message:`Downloading ${e.name}`,failed:!1})},[r,y]);(0,E.useEffect)(()=>{if(!B)return;let e=setTimeout(()=>V(null),2500);return()=>clearTimeout(e)},[B]);let Z=(0,E.useCallback)(async()=>{if(r){L(!0),F(null);try{let e=await x(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);te((await e.json()).artefacts??[]),N(!0)}catch(e){let t=e instanceof Error?e.message:String(e);F(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{L(!1)}}},[r,x]);(0,E.useEffect)(()=>{!r||M||Z()},[r,M,Z]);let ge=()=>{A(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${M?j.length:0} collapsed=${b}`),M||Z()},Q=1.5,_e=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),Z()},$=(0,E.useCallback)(async()=>{if(r){ce(!0),G(null);try{let e=await x(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json();ne(t.sessions??[]),J(t.accountId??null),oe(!0)}catch(e){let t=e instanceof Error?e.message:String(e);G(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`)}finally{ce(!1)}}},[r,x]),ve=()=>{A(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${U?H.length:0} collapsed=${b}`),U||$()},ye=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),$()},be=(0,E.useCallback)(async e=>{if(!fe.has(e.sessionId)){pe(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await x(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})});if(!t.ok){let n=await t.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),V({message:`Resume failed: ${n.error??`status ${t.status}`}`,failed:!0});return}let n=await t.json();console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} spawnedPid=${n.spawnedPid??`?`}`),y(),window.open(ae,`_blank`,`noopener,noreferrer`)}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${n}`),V({message:`Resume failed: ${n}`,failed:!0})}finally{pe(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}}},[x,y,fe]),xe=(0,E.useCallback)(async()=>{if(!X){me(!0);try{let e=await x(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})});if(!e.ok){let t=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-new-session-failed status=${e.status} error=${t.error??`unknown`}`),V({message:`New session failed: ${t.error??`status ${e.status}`}`,failed:!0});return}let t=await e.json();console.info(`[admin-ui] sidebar-new-session-spawned spawnedPid=${t.spawnedPid??`?`}`),window.open(ae,`_blank`,`noopener,noreferrer`)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),V({message:`New session failed: ${t}`,failed:!0})}finally{me(!1)}}},[x,X]),Se=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Y.has(t.sessionId)){de(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await x(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,projectDir:t.projectDir})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),V({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),ne(e=>e.filter(e=>e.sessionId!==t.sessionId)),$()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),V({message:`Delete failed: ${n}`,failed:!0})}finally{de(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[x,Y,$]);return(0,D.jsxs)(`aside`,{className:`side`,children:[(0,D.jsx)(`div`,{className:`side-new-session-row`,children:(0,D.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:xe,disabled:X,"aria-busy":X,children:[(0,D.jsx)(S,{size:14}),(0,D.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,D.jsxs)(`nav`,{className:`side-nav`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),h(),y()},children:[(0,D.jsx)(w,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`People`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),v(),y()},children:[(0,D.jsx)(c,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Agents`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),d(),y()},children:[(0,D.jsx)(l,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Projects`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),_(),y()},children:[(0,D.jsx)(g,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`artefacts`?` active`:``}`,onClick:ge,children:[(0,D.jsx)(t,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`sessions`?` active`:``}`,onClick:ve,children:[(0,D.jsx)(m,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,D.jsx)(`span`,{className:`kbd`})]})]}),k===`artefacts`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Artefacts`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:_e,disabled:I,children:(0,D.jsx)(C,{size:12,className:I?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:I?`…`:String(j.length)})]})]}),P&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:P}),M&&!P&&j.length>0&&(()=>{let e=j.filter(e=>e.kind===`agent-template`).length,t=j.length-e;return(0,D.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:j.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${R===e.key?` active`:``}`,onClick:()=>z(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,D.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),M&&!P&&j.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),j.filter(e=>R===`all`?!0:R===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let n=e.kind===`agent-template`,r=n?c:t,i=Date.parse(e.updatedAt),a=Number.isFinite(i)?new Date(i).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,o=e.downloadPath!==null;return(0,D.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>he(e),disabled:!o,style:o?void 0:{cursor:`default`},title:o?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,D.jsx)(r,{size:14,className:`conv-icon`,"data-kind":n?`agent`:`file`,"aria-label":n?`agent template`:`file`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.name})}),a&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:a})]}),o&&(0,D.jsx)(f,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),k===`sessions`&&(()=>{let e=q?H:H.filter(e=>!e.isSubagent),t=H.some(e=>e.isSubagent);return(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Sessions`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:ye,disabled:K,children:(0,D.jsx)(C,{size:12,className:K?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:K?`…`:String(e.length)})]})]}),ue&&(0,D.jsx)(`div`,{className:`side-account-id`,title:`This install's accountId. The first 8 characters match the truncated UUID label on the live Remote Control daemon entry in claude.ai/code.`,children:(0,D.jsx)(`code`,{children:ue})}),t&&(0,D.jsx)(`div`,{className:`artefact-filter-chips`,children:(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${q?` active`:``}`,onClick:()=>le(e=>!e),title:q?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`})}),W&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:W}),U&&!W&&e.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=Date.parse(e.startedAt),n=Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,r=fe.has(e.sessionId),i=Y.has(e.sessionId);return(0,D.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`conv-main`,onClick:()=>{be(e)},disabled:r||i,"aria-busy":r,title:`Resume in a fresh local Remote Control PTY`,children:[(0,D.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsxs)(`span`,{className:`conv-name-line`,children:[(0,D.jsx)(`span`,{className:`conv-name`,children:e.title}),(0,D.jsx)(p,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]}),n&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:n})]})]}),(0,D.jsx)(`button`,{type:`button`,className:`conv-delete`,onClick:t=>{Se(t,e)},disabled:r||i,"aria-busy":i,"aria-label":`Delete session ${e.title}`,title:`Delete session (kills PID if live, removes JSONL)`,children:(0,D.jsx)(o,{size:12})})]},e.sessionId)})]})})(),(0,D.jsx)(se,{}),(0,D.jsxs)(`div`,{className:`side-foot`,children:[(0,D.jsx)(`div`,{className:`avatar`,children:u?(0,D.jsx)(`img`,{src:u,alt:T}):O}),(0,D.jsxs)(`div`,{className:`who`,children:[(0,D.jsx)(`span`,{className:`name`,children:T}),(0,D.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),B&&(0,D.jsx)(`div`,{className:`copy-toast${B.failed?` copy-toast-failed`:``}`,role:`status`,children:B.message})]})}var W=5e3;function se(){let[e,t]=(0,E.useState)(null);if((0,E.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},W))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,D.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var G=`admin-sidebar-collapsed`,K=`admin-sidebar-drawer-open`;function ce(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(G)===`1`}catch{return!1}}function q(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(G,`1`):window.sessionStorage.removeItem(G)}catch{}}function le(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function ue(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}var J=720;function Y(e){let{cacheKey:t,businessName:n,onLogout:r,userName:i,userAvatar:a,role:o,children:s,footer:c}=e,[l,u]=(0,E.useState)(()=>ce()),[d,f]=(0,E.useState)(()=>le()),[p,m]=(0,E.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${J}px)`).matches);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${J}px)`),t=e=>m(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let h=(0,E.useCallback)(e=>{q(e),u(e)},[]),g=(0,E.useCallback)(e=>{ue(e),f(e)},[]);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${l} drawer=${d}`)},[]);let _=p?d:!l,v=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${J}px)`).matches){let e=d;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),g(!e)}else{let e=l;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),h(!e)}},[l,d,h,g]),y=(0,E.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`),window.location.href=e===`data`?`/data`:`/graph`},[]),b={collapsed:l,mobileDrawerOpen:d,sidebarOpen:_,onToggleSidebar:v,setMobileDrawerOpen:g};return(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsx)(U,{businessName:n,onNavigate:y,onToggleSidebar:v,sidebarOpen:_,onLogout:r}),(0,D.jsxs)(`div`,{className:`platform${d?` menu-open`:``}${l?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,D.jsx)(oe,{businessName:n,cacheKey:t,role:o??null,userName:i,userAvatar:a??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>g(!1),collapsed:l,mobileDrawerOpen:d}),typeof s==`function`?s(b):s]}),d&&(0,D.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>g(!1)}),c]})}export{te as a,C as c,f as d,d as f,B as i,S as l,ie as n,T as o,H as r,ee as s,Y as t,_ as u};
|
|
1
|
+
import{o as e}from"./chunk-DD-I1_y5.js";import{c as t,d as n,i as r,l as i,o as a,s as o,t as s}from"./brand-SzZmKKjz.js";var c=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),l=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),u=i(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),d=i(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),f=i(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),p=i(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),m=i(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),h=i(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),g=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),_=i(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),v=i(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),y=i(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),b=i(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),x=i(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),S=i(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),C=i(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),ee=i(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),w=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),T=i(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),E=e(n(),1),D=a(),O=`maxy-shell-side-px`;function k(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function A(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-k());return Math.min(Math.max(e,248),n)}function j(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(O);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return A(t)}catch{}return 264}function te({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>j()),i=(0,E.useRef)(n);(0,E.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,E.useCallback)(()=>{r(e=>{let t=A(e);return t===e?e:t})},[]);(0,E.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(A(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(O,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=A(264);r(e);try{window.localStorage.removeItem(O)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,D.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var M=`maxy-admin-session`,N=typeof BroadcastChannel<`u`;function P(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function F(e){if(!N)return()=>{};let t=new BroadcastChannel(M),n=t=>{if(!P(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var I=`maxy-admin-session-key`;function L(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function R(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`?n:`unknown-401`}function z(){try{return sessionStorage.getItem(I)}catch{return null}}function B(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,E.useState)(t),a=(0,E.useRef)(t);(0,E.useEffect)(()=>{a.current=r},[r]),(0,E.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,E.useState)(0),[c,l]=(0,E.useState)(null);(0,E.useEffect)(()=>F(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1),l(null))}),[n]);let u=(0,E.useCallback)(()=>{try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,E.useCallback)(async(e,t)=>{let r=a.current,o=L(e,r),c=await fetch(o,t);if(c.status!==401)return c;let d=await R(c);if(d===`session-missing`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),u(),c;if(d!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:d}),c;let f=z();if(!f||f===r)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),l({message:`Your admin session was renewed in another tab. Click to reload.`,reason:`session-not-registered`}),c;i(f),a.current=f,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${f.slice(0,8)} surface=${n} path=${e}`);let p=L(e,f),m=await fetch(p,t);return m.status===401&&(console.warn(`[useAdminFetch] outcome=redirect-to-login reason=second-401-after-retry surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:`session-not-registered`})),m},[u,n]),cacheKey:r,sessionRefetchNonce:o,banner:c,reloadToLogin:u}}var V=(0,E.createContext)(null);function H({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,E.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=L(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await R(o),c=e.slice(-8);if(s===`session-not-registered`){let a=z();if(a&&a!==e){let e=L(r,a),o=await fetch(e,i);return o.status===401?(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,D.jsx)(V.Provider,{value:i,children:r})}function ne(){return(0,E.useContext)(V)}function re(e){let t=ne();return(0,E.useMemo)(()=>t||(async(t,n)=>fetch(e?L(t,e):t,n)),[t,e])}function U(e){let{businessName:t,onNavigate:n,onToggleSidebar:i,sidebarOpen:a,onLogout:c}=e,[l,f]=(0,E.useState)(!1),m=(0,E.useRef)(null),g=(0,E.useRef)(null),S=re(null),[C,w]=(0,E.useState)(null),[O,k]=(0,E.useState)(!1),[A,j]=(0,E.useState)(null),[te,M]=(0,E.useState)(null),[N,P]=(0,E.useState)(null),[F,I]=(0,E.useState)(``);(0,E.useEffect)(()=>{I(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{m.current&&!m.current.contains(e.target)&&f(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&f(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]),(0,E.useEffect)(()=>{l&&g.current?.focus()},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=!1;return S(`/api/admin/version`).then(e=>e.json()).then(t=>{e||P(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[l,S]);let L=(0,E.useCallback)(()=>{f(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),R=(0,E.useCallback)(e=>{f(!1),n(e)},[n]),z=(0,E.useCallback)(async()=>{if(C!==null){w(null),M(null);return}k(!0),j(null);try{let e=await S(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);w((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),j(e instanceof Error?e.message:String(e)),w([])}finally{k(!1)}},[C,S]),B=(0,E.useCallback)(e=>{M(null),w(t=>t?.filter(t=>t.slug!==e)??null),S(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[S]),V=(0,E.useCallback)(()=>{f(!1),c()},[c]),H=t||s.productName;return(0,D.jsxs)(`header`,{className:`admin-header`,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":a?`Hide sidebar`:`Show sidebar`,title:a?`Hide sidebar`:`Show sidebar`,"aria-expanded":a,onClick:i,children:a?(0,D.jsx)(b,{size:20,strokeWidth:1.5}):(0,D.jsx)(x,{size:20,strokeWidth:1.5})}),(0,D.jsxs)(`div`,{className:`chat-header-label`,children:[(0,D.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,D.jsx)(`img`,{src:r,alt:``,className:`chat-logo`})}),(0,D.jsx)(`h1`,{className:`chat-tagline`,children:H})]}),(0,D.jsxs)(`div`,{className:`chat-burger-wrap`,ref:m,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:L,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":l,children:(0,D.jsx)(y,{size:20})}),l&&(0,D.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,D.jsxs)(`button`,{ref:g,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>R(`data`),children:[(0,D.jsx)(d,{size:14}),` Data`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>R(`graph`),children:[(0,D.jsx)(ee,{size:14}),` Graph`]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:z,children:[(0,D.jsx)(p,{size:14}),` Public`,O&&(0,D.jsx)(_,{size:12,className:`spin`})]}),C!==null&&(0,D.jsxs)(`div`,{className:`chat-menu-agents`,children:[A&&(0,D.jsx)(`span`,{className:`chat-menu-agent-error`,children:A}),C.length===0&&!A&&(0,D.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),C.map(e=>(0,D.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,D.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,D.jsxs)(`span`,{className:`agent-text`,children:[(0,D.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,D.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),te===e.slug?(0,D.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>B(e.slug),children:(0,D.jsx)(u,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>M(null),children:(0,D.jsx)(T,{size:12})})]}):(0,D.jsxs)(`span`,{className:`agent-actions`,children:[(0,D.jsx)(`a`,{href:`${F}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>f(!1),children:(0,D.jsx)(p,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>M(e.slug),children:(0,D.jsx)(o,{size:12})})]})]},e.slug))]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,D.jsx)(h,{size:14}),(0,D.jsxs)(`span`,{className:`version-installed`,children:[N?`v${N.installed}`:`…`,N&&!N.updateAvailable&&(0,D.jsx)(`span`,{className:`version-uptodate-dot`}),N?.updateAvailable&&(0,D.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:V,children:[(0,D.jsx)(v,{size:14}),` Log out`]})]})]})]})}function ie(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}var ae=`https://claude.ai/code`;function oe(e){let{businessName:n,cacheKey:r,role:i,userName:a,userAvatar:u,onSelectProjects:d,onSelectPeople:h,onSelectTasks:_,onSelectAgents:v,onCloseMobileDrawer:y,collapsed:b}=e,x=re(r),ee=s.productName,T=typeof a==`string`?a:a===null?`name unavailable`:n||ee,O=(T.trim().charAt(0)||`?`).toUpperCase(),[k,A]=(0,E.useState)(`artefacts`),[j,te]=(0,E.useState)([]),[M,N]=(0,E.useState)(!1),[P,F]=(0,E.useState)(null),[I,L]=(0,E.useState)(!1),[R,z]=(0,E.useState)(`all`),[B,V]=(0,E.useState)(null),[H,ne]=(0,E.useState)([]),[U,oe]=(0,E.useState)(!1),[W,G]=(0,E.useState)(null),[K,ce]=(0,E.useState)(!1),[q,le]=(0,E.useState)(!1),[ue,J]=(0,E.useState)(null),[Y,de]=(0,E.useState)(new Set),[fe,pe]=(0,E.useState)(new Set),[X,me]=(0,E.useState)(!1),he=(0,E.useCallback)(e=>{if(y(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),V({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),V({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),ie(r,e.downloadPath,e.downloadRoot??`data`),V({message:`Downloading ${e.name}`,failed:!1})},[r,y]);(0,E.useEffect)(()=>{if(!B)return;let e=setTimeout(()=>V(null),2500);return()=>clearTimeout(e)},[B]);let Z=(0,E.useCallback)(async()=>{if(r){L(!0),F(null);try{let e=await x(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);te((await e.json()).artefacts??[]),N(!0)}catch(e){let t=e instanceof Error?e.message:String(e);F(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{L(!1)}}},[r,x]);(0,E.useEffect)(()=>{!r||M||Z()},[r,M,Z]);let ge=()=>{A(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${M?j.length:0} collapsed=${b}`),M||Z()},Q=1.5,_e=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),Z()},$=(0,E.useCallback)(async()=>{if(r){ce(!0),G(null);try{let e=await x(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json();ne(t.sessions??[]),J(t.accountId??null),oe(!0)}catch(e){let t=e instanceof Error?e.message:String(e);G(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`)}finally{ce(!1)}}},[r,x]),ve=()=>{A(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${U?H.length:0} collapsed=${b}`),U||$()},ye=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),$()},be=(0,E.useCallback)(async e=>{if(!fe.has(e.sessionId)){pe(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await x(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})});if(!t.ok){let n=await t.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),V({message:`Resume failed: ${n.error??`status ${t.status}`}`,failed:!0});return}let n=await t.json();console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} spawnedPid=${n.spawnedPid??`?`}`),y(),window.open(ae,`_blank`,`noopener,noreferrer`)}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${n}`),V({message:`Resume failed: ${n}`,failed:!0})}finally{pe(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}}},[x,y,fe]),xe=(0,E.useCallback)(async()=>{if(!X){me(!0);try{let e=await x(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})});if(!e.ok){let t=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-new-session-failed status=${e.status} error=${t.error??`unknown`}`),V({message:`New session failed: ${t.error??`status ${e.status}`}`,failed:!0});return}let t=await e.json();console.info(`[admin-ui] sidebar-new-session-spawned spawnedPid=${t.spawnedPid??`?`}`),window.open(ae,`_blank`,`noopener,noreferrer`)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),V({message:`New session failed: ${t}`,failed:!0})}finally{me(!1)}}},[x,X]),Se=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Y.has(t.sessionId)){de(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await x(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,projectDir:t.projectDir})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),V({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),ne(e=>e.filter(e=>e.sessionId!==t.sessionId)),$()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),V({message:`Delete failed: ${n}`,failed:!0})}finally{de(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[x,Y,$]);return(0,D.jsxs)(`aside`,{className:`side`,children:[(0,D.jsx)(`div`,{className:`side-new-session-row`,children:(0,D.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:xe,disabled:X,"aria-busy":X,children:[(0,D.jsx)(S,{size:14}),(0,D.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,D.jsxs)(`nav`,{className:`side-nav`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),h(),y()},children:[(0,D.jsx)(w,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`People`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),v(),y()},children:[(0,D.jsx)(c,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Agents`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),d(),y()},children:[(0,D.jsx)(l,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Projects`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),_(),y()},children:[(0,D.jsx)(g,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`artefacts`?` active`:``}`,onClick:ge,children:[(0,D.jsx)(t,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`sessions`?` active`:``}`,onClick:ve,children:[(0,D.jsx)(m,{size:20,strokeWidth:Q}),(0,D.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,D.jsx)(`span`,{className:`kbd`})]})]}),k===`artefacts`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Artefacts`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:_e,disabled:I,children:(0,D.jsx)(C,{size:12,className:I?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:I?`…`:String(j.length)})]})]}),P&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:P}),M&&!P&&j.length>0&&(()=>{let e=j.filter(e=>e.kind===`agent-template`).length,t=j.length-e;return(0,D.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:j.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${R===e.key?` active`:``}`,onClick:()=>z(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,D.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),M&&!P&&j.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),j.filter(e=>R===`all`?!0:R===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let n=e.kind===`agent-template`,r=n?c:t,i=Date.parse(e.updatedAt),a=Number.isFinite(i)?new Date(i).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,o=e.downloadPath!==null;return(0,D.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>he(e),disabled:!o,style:o?void 0:{cursor:`default`},title:o?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,D.jsx)(r,{size:14,className:`conv-icon`,"data-kind":n?`agent`:`file`,"aria-label":n?`agent template`:`file`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.name})}),a&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:a})]}),o&&(0,D.jsx)(f,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),k===`sessions`&&(()=>{let e=q?H:H.filter(e=>!e.isSubagent),t=H.some(e=>e.isSubagent);return(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Sessions`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:ye,disabled:K,children:(0,D.jsx)(C,{size:12,className:K?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:K?`…`:String(e.length)})]})]}),ue&&(0,D.jsx)(`div`,{className:`side-account-id`,title:`This install's accountId. The first 8 characters match the truncated UUID label on the live Remote Control daemon entry in claude.ai/code.`,children:(0,D.jsx)(`code`,{children:ue})}),t&&(0,D.jsx)(`div`,{className:`artefact-filter-chips`,children:(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${q?` active`:``}`,onClick:()=>le(e=>!e),title:q?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`})}),W&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:W}),U&&!W&&e.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=Date.parse(e.startedAt),n=Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,r=fe.has(e.sessionId),i=Y.has(e.sessionId);return(0,D.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,D.jsxs)(`div`,{className:`conv-main-static`,children:[(0,D.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.title})}),n&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:n})]})]}),(0,D.jsxs)(`div`,{className:`conv-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{be(e)},disabled:r||i,"aria-busy":r,"aria-label":`Resume session ${e.title} in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,children:(0,D.jsx)(p,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`conv-action conv-action-danger`,onClick:t=>{Se(t,e)},disabled:r||i,"aria-busy":i,"aria-label":`Delete session ${e.title}`,title:`Delete session (kills PID if live, removes JSONL)`,children:(0,D.jsx)(o,{size:12})})]})]},e.sessionId)})]})})(),(0,D.jsx)(se,{}),(0,D.jsxs)(`div`,{className:`side-foot`,children:[(0,D.jsx)(`div`,{className:`avatar`,children:u?(0,D.jsx)(`img`,{src:u,alt:T}):O}),(0,D.jsxs)(`div`,{className:`who`,children:[(0,D.jsx)(`span`,{className:`name`,children:T}),(0,D.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),B&&(0,D.jsx)(`div`,{className:`copy-toast${B.failed?` copy-toast-failed`:``}`,role:`status`,children:B.message})]})}var W=5e3;function se(){let[e,t]=(0,E.useState)(null);if((0,E.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},W))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,D.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var G=`admin-sidebar-collapsed`,K=`admin-sidebar-drawer-open`;function ce(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(G)===`1`}catch{return!1}}function q(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(G,`1`):window.sessionStorage.removeItem(G)}catch{}}function le(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function ue(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}var J=720;function Y(e){let{cacheKey:t,businessName:n,onLogout:r,userName:i,userAvatar:a,role:o,children:s,footer:c}=e,[l,u]=(0,E.useState)(()=>ce()),[d,f]=(0,E.useState)(()=>le()),[p,m]=(0,E.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${J}px)`).matches);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${J}px)`),t=e=>m(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let h=(0,E.useCallback)(e=>{q(e),u(e)},[]),g=(0,E.useCallback)(e=>{ue(e),f(e)},[]);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${l} drawer=${d}`)},[]);let _=p?d:!l,v=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${J}px)`).matches){let e=d;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),g(!e)}else{let e=l;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),h(!e)}},[l,d,h,g]),y=(0,E.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`),window.location.href=e===`data`?`/data`:`/graph`},[]),b={collapsed:l,mobileDrawerOpen:d,sidebarOpen:_,onToggleSidebar:v,setMobileDrawerOpen:g};return(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsx)(U,{businessName:n,onNavigate:y,onToggleSidebar:v,sidebarOpen:_,onLogout:r}),(0,D.jsxs)(`div`,{className:`platform${d?` menu-open`:``}${l?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,D.jsx)(oe,{businessName:n,cacheKey:t,role:o??null,userName:i,userAvatar:a??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>g(!1),collapsed:l,mobileDrawerOpen:d}),typeof s==`function`?s(b):s]}),d&&(0,D.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>g(!1)}),c]})}export{te as a,C as c,f as d,d as f,B as i,S as l,ie as n,T as o,H as r,ee as s,Y as t,_ as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./brand-
|
|
1
|
+
import{o as e}from"./brand-SzZmKKjz.js";var t=e();function n({checked:e,onChange:n,label:r,disabled:i}){return(0,t.jsxs)(`label`,{className:`maxy-checkbox${i?` maxy-checkbox--disabled`:``}`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>n(e.target.checked),disabled:i}),(0,t.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),r&&(0,t.jsx)(`span`,{className:`maxy-checkbox__label`,children:r})]})}export{n as t};
|