@hearsay-tools/squawk 0.18.0-dev.8435 → 0.18.0-dev.8440
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/dist/contract/index.js +5 -2
- package/dist/contract/live-coordination.d.ts +30 -12
- package/dist/contract/live.d.ts +29 -0
- package/dist/server/live-routes.d.ts +7 -0
- package/dist/server/live-routes.js +1 -0
- package/dist/server/live-routes.js.map +1 -1
- package/dist/server/project-settings-routes.js +1 -0
- package/dist/server/project-settings-routes.js.map +1 -1
- package/dist/server/run-event-feed.d.ts +7 -1
- package/dist/server/run-event-feed.js +58 -9
- package/dist/server/run-event-feed.js.map +1 -1
- package/dist/server/server.d.ts +7 -0
- package/dist/server/workspace-live-routes.d.ts +7 -0
- package/package.json +4 -4
- package/scripts/measure-transcript-facts-health.mjs +41 -4
- package/scripts/measure-transcript-facts-lag.mjs +3 -3
- package/scripts/transcript-facts-timing.mjs +133 -9
- package/web/dist/assets/{accounts-section-DPb768q9.js → accounts-section-DbBWy1h-.js} +1 -1
- package/web/dist/assets/{activity-motion-D3CzGjrR.js → activity-motion--OtBLAG2.js} +1 -1
- package/web/dist/assets/{activity-route-DFJlsU13.js → activity-route-DhPIkMRQ.js} +1 -1
- package/web/dist/assets/{agent-config-section-2esq_SCK.js → agent-config-section-DmHFEfLn.js} +1 -1
- package/web/dist/assets/{agent-defaults-section-DykQGFoV.js → agent-defaults-section-BSM4exrC.js} +1 -1
- package/web/dist/assets/{appearance-CEhpCQZS.js → appearance-DDZh2js5.js} +1 -1
- package/web/dist/assets/{archive-on-merge-field-BlGo3o7a.js → archive-on-merge-field-BQXdK50c.js} +1 -1
- package/web/dist/assets/attention-DShuKoMT.js +1 -0
- package/web/dist/assets/{automation-format-CUP262Tk.js → automation-format-DB34jUyF.js} +1 -1
- package/web/dist/assets/{automations-route-C6e7440u.js → automations-route-5SrHa_fk.js} +1 -1
- package/web/dist/assets/{cez-idle-CQtDz5jk.js → cez-idle-CdswdDRd.js} +1 -1
- package/web/dist/assets/{commit-diff-panel-CloSSaTz.js → commit-diff-panel-DAblJOWW.js} +1 -1
- package/web/dist/assets/{diff-DVDzDVOV.js → diff-D6dgppr7.js} +2 -2
- package/web/dist/assets/{diff-view-isM51Pgu.js → diff-view-DA0QN32e.js} +1 -1
- package/web/dist/assets/{file-preview-BZA9e981.js → file-preview-BqpyguUL.js} +1 -1
- package/web/dist/assets/{folder-browser-CffyHz8w.js → folder-browser-Bv_vTEU3.js} +1 -1
- package/web/dist/assets/{git-toolbar-DHAavjba.js → git-toolbar-CTWmcYLa.js} +1 -1
- package/web/dist/assets/{github-MN8flcF0.js → github-B-xnHpoW.js} +1 -1
- package/web/dist/assets/{global-activity-route-CAXyZ8LF.js → global-activity-route-gYuCqamk.js} +1 -1
- package/web/dist/assets/{index-CHIFhfha.js → index-DCIRYVqB.js} +5 -5
- package/web/dist/assets/{label-6PgIe3Ny.js → label-DRrVct19.js} +1 -1
- package/web/dist/assets/{live-protocol-DteqtbyN.js → live-protocol-DMhTnCmf.js} +1 -1
- package/web/dist/assets/{live-reads-BxjlQXfN.js → live-reads-BuThrTt7.js} +1 -1
- package/web/dist/assets/{markdown-DhdLkyGx.js → markdown-d2-nofJ3.js} +1 -1
- package/web/dist/assets/{notifications-section-Yiyd4TEk.js → notifications-section-BNrYh6dQ.js} +1 -1
- package/web/dist/assets/{open-in-menu-AZMtej8C.js → open-in-menu-DpJFqH3v.js} +1 -1
- package/web/dist/assets/{preview-pane-connected-BnNucXbg.js → preview-pane-connected-BwTG5ZIm.js} +1 -1
- package/web/dist/assets/{project-location-DzOgHfcA.js → project-location-DNdux3-n.js} +1 -1
- package/web/dist/assets/{project-router-CDPfL2Jz.js → project-router-GVIIqwXL.js} +1 -1
- package/web/dist/assets/{project-scope-context-D9axDY18.js → project-scope-context-blU6DPq1.js} +1 -1
- package/web/dist/assets/{projects-section-CYnMlFyZ.js → projects-section-DfZ6ledr.js} +1 -1
- package/web/dist/assets/{prompt-templates-section-BaaI89Ej.js → prompt-templates-section-C2_9c8s-.js} +1 -1
- package/web/dist/assets/{queries-DzwCG927.js → queries-CihFAzQA.js} +1 -1
- package/web/dist/assets/{reference-chip-BnIoiMgY.js → reference-chip-DDmY2Wa2.js} +1 -1
- package/web/dist/assets/{remote-settings-notice-Drbpb7K4.js → remote-settings-notice-BEn0VAfk.js} +1 -1
- package/web/dist/assets/{repo-git-UR__WAGI.js → repo-git-kS-kyHgg.js} +1 -1
- package/web/dist/assets/{report-reader-DydKaDxP.js → report-reader-BcVFsRsD.js} +1 -1
- package/web/dist/assets/{reports-FE9fPBLK.js → reports-DqYF_Hlr.js} +1 -1
- package/web/dist/assets/{resources-section-BAz7yc3V.js → resources-section-B2o8ytO4.js} +1 -1
- package/web/dist/assets/{run-header-DsyPfNlS.js → run-header-BstZeaqM.js} +1 -1
- package/web/dist/assets/{settings-agent-picker-i4wCYEex.js → settings-agent-picker-rNyNJEU2.js} +1 -1
- package/web/dist/assets/{settings-shell-C1RbQ--s.js → settings-shell-BAmJvzuG.js} +1 -1
- package/web/dist/assets/{sidebar-section-CdvgsziI.js → sidebar-section-BTf_4d6s.js} +1 -1
- package/web/dist/assets/{skills-Cx1c72fB.js → skills-Cbg8WPDT.js} +1 -1
- package/web/dist/assets/{tab-link-BaKE6KnE.js → tab-link-Bwm_Gn01.js} +1 -1
- package/web/dist/assets/{task-changes-CJCU26Rn.js → task-changes-Ck289AHW.js} +1 -1
- package/web/dist/assets/{task-commits-BvDHw2z3.js → task-commits-Ze6RgzC8.js} +1 -1
- package/web/dist/assets/{task-files-BtEb73_A.js → task-files-D28yguBF.js} +1 -1
- package/web/dist/assets/{task-github-item-DguvLtyn.js → task-github-item-BvS_N-Rv.js} +1 -1
- package/web/dist/assets/{task-groups-DoiPFEfM.js → task-groups-AQ1zMByj.js} +1 -1
- package/web/dist/assets/{task-thread-DiiErUqw.js → task-thread-DhHHmYnk.js} +1 -1
- package/web/dist/assets/{tasks-table-CmESFng9.js → tasks-table-BGoadobM.js} +1 -1
- package/web/dist/assets/{thread-state-XrQOGOYN.js → thread-state-CNAlLytB.js} +1 -1
- package/web/dist/assets/{use-hand-to-agent-state-CDqXR3F2.js → use-hand-to-agent-state-B8mS8z45.js} +1 -1
- package/web/dist/assets/{useInfiniteQuery-GZp9laKm.js → useInfiniteQuery-CS_BO-SK.js} +1 -1
- package/web/dist/assets/useQuery-Ys0_fBIg.js +1 -0
- package/web/dist/assets/{workflows-C8Wu6BrK.js → workflows-Ck02MIW2.js} +1 -1
- package/web/dist/assets/{workspace-tools-DG99Pw_m.js → workspace-tools-KELtYCoO.js} +1 -1
- package/web/dist/assets/{worktrees-section-BtDBsA-d.js → worktrees-section-DhPBqflI.js} +1 -1
- package/web/dist/index.html +16 -16
- package/web/dist/live-worker.js +2 -2
- package/web/dist/assets/attention-CvHM4cjG.js +0 -1
- package/web/dist/assets/useQuery-CzVHT8UE.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hearsay-tools/squawk",
|
|
3
|
-
"version": "0.18.0-dev.
|
|
3
|
+
"version": "0.18.0-dev.8440",
|
|
4
4
|
"description": "Local cockpit for running and tracking AI agent tasks in your repo. Uses your logged-in `claude` CLI and `gh` — zero config, zero database.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@babel/parser": "^8.0.8",
|
|
70
70
|
"@babel/types": "^8.0.8",
|
|
71
|
-
"@open-mercato/cezar-api-client": "0.18.0-dev.
|
|
72
|
-
"@open-mercato/cezar-contract": "0.18.0-dev.
|
|
71
|
+
"@open-mercato/cezar-api-client": "0.18.0-dev.8440",
|
|
72
|
+
"@open-mercato/cezar-contract": "0.18.0-dev.8440",
|
|
73
73
|
"@types/node": "^24.19.1",
|
|
74
74
|
"@types/ws": "^8.18.1",
|
|
75
75
|
"esbuild": "^0.28.1",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "2e178d482f2895cf5ded0ff2ef3b449f8832e4b6"
|
|
90
90
|
}
|
|
@@ -8,7 +8,8 @@ import { mkdtempSync, readdirSync, rmSync } from 'node:fs';
|
|
|
8
8
|
import { tmpdir } from 'node:os';
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
11
|
-
import {
|
|
11
|
+
import { PerformanceObserver } from 'node:perf_hooks';
|
|
12
|
+
import { timingSnapshot, timingDelta, blockingBudget, prepareOpenTiming, hookCalls, callsWithin, startThreadWatch, summarizeWaits } from './transcript-facts-timing.mjs';
|
|
12
13
|
import { seedColdHistories, verifyFacts } from './transcript-facts-fixture.mjs';
|
|
13
14
|
|
|
14
15
|
const root = mkdtempSync(join(process.platform === 'win32' ? tmpdir() : '/tmp', 'cez-facts-health-'));
|
|
@@ -23,6 +24,9 @@ let dataDir;
|
|
|
23
24
|
let store;
|
|
24
25
|
let bootStore;
|
|
25
26
|
let server;
|
|
27
|
+
let unhookCalls;
|
|
28
|
+
let gcObserver;
|
|
29
|
+
let threadWatch;
|
|
26
30
|
const watchdog = setTimeout(() => { console.error('health measurement exceeded 30s'); process.exitCode = 1; server?.closeAllConnections(); server?.close(); store?.close(); bootStore?.close(); }, 30_000);
|
|
27
31
|
try {
|
|
28
32
|
const { RunStore } = await import(new URL('runs/store.js', runtime.url));
|
|
@@ -79,18 +83,32 @@ try {
|
|
|
79
83
|
assert.equal((await prime.json()).version, 'task4-measurement');
|
|
80
84
|
const primingLatencyMs = performance.now() - primingStart;
|
|
81
85
|
assert.equal(readdirSync(join(dataDir, 'runs')).filter(name => name.endsWith('.facts.json')).length, 0);
|
|
86
|
+
// Diagnostics only: name the main-thread calls and GC pauses inside each sample.
|
|
87
|
+
const { TranscriptFactsIndex } = await import(new URL('runs/transcript-facts.js', runtime.url));
|
|
88
|
+
const { TranscriptFactsQueue } = await import(new URL('runs/transcript-facts-queue.js', runtime.url));
|
|
89
|
+
const { RunQueriesTopic } = await import(new URL('runs/run-queries.js', runtime.url));
|
|
90
|
+
const calls = [];
|
|
91
|
+
unhookCalls = hookCalls([[RunQueriesTopic.prototype, 'listConversationRootIds'], [RunQueriesTopic.prototype, 'listFamilyRunIds'],
|
|
92
|
+
[RunQueriesTopic.prototype, 'listRunIds'], [TranscriptFactsIndex.prototype, 'warm'], [TranscriptFactsIndex.prototype, 'peek'],
|
|
93
|
+
[TranscriptFactsIndex.prototype, 'accept'], [TranscriptFactsIndex.prototype, 'persist'],
|
|
94
|
+
[TranscriptFactsQueue.prototype, 'start'], [TranscriptFactsQueue.prototype, 'createWorker']], calls);
|
|
95
|
+
const gcPauses = [];
|
|
96
|
+
gcObserver = new PerformanceObserver(list => { for (const entry of list.getEntries()) gcPauses.push(entry); });
|
|
97
|
+
gcObserver.observe({ entryTypes: ['gc'] });
|
|
98
|
+
threadWatch = await startThreadWatch();
|
|
82
99
|
const start = performance.now();
|
|
83
100
|
let end;
|
|
84
101
|
let warming;
|
|
85
102
|
const samples = [];
|
|
86
103
|
const pauseMs = 5;
|
|
87
104
|
// Each sample after the first also covers the pause before its request, so blocking
|
|
88
|
-
// between requests is measured too;
|
|
105
|
+
// between requests is measured too; the pause is loop idle time, which blockingBudget excludes.
|
|
89
106
|
let pauseStart;
|
|
90
107
|
for (;;) {
|
|
91
108
|
const measurementStart = pauseStart ?? timingSnapshot();
|
|
92
109
|
const plannedMs = pauseStart ? pauseMs : 0;
|
|
93
110
|
const requestStart = performance.now();
|
|
111
|
+
if (!store) threadWatch?.watch(true);
|
|
94
112
|
const pendingResponse = fetch(endpoint, { signal: AbortSignal.timeout(2_000) });
|
|
95
113
|
// The first request includes synchronous project-open work too.
|
|
96
114
|
if (!store) {
|
|
@@ -103,13 +121,26 @@ try {
|
|
|
103
121
|
const requestEnd = performance.now();
|
|
104
122
|
// Include EVERY request begun while cold warm-up was active, even one ending after it.
|
|
105
123
|
const measurement = timingDelta(measurementStart, timingSnapshot());
|
|
124
|
+
threadWatch?.watch(false);
|
|
106
125
|
samples.push({ fromMs: measurementStart.at - start, startMs: requestStart - start, endMs: requestEnd - start,
|
|
107
|
-
latencyMs: requestEnd - requestStart, plannedMs, ...measurement, ...blockingBudget(measurement
|
|
126
|
+
latencyMs: requestEnd - requestStart, plannedMs, ...measurement, ...blockingBudget(measurement) });
|
|
108
127
|
if (end !== undefined) break;
|
|
109
128
|
pauseStart = timingSnapshot();
|
|
110
129
|
await delay(pauseMs);
|
|
111
130
|
}
|
|
112
131
|
await warming;
|
|
132
|
+
unhookCalls();
|
|
133
|
+
const firstSampleWaits = (await threadWatch?.stop()) ?? [];
|
|
134
|
+
threadWatch = undefined;
|
|
135
|
+
for (const entry of gcObserver.takeRecords()) gcPauses.push(entry);
|
|
136
|
+
gcObserver.disconnect();
|
|
137
|
+
for (const sample of samples) {
|
|
138
|
+
const from = start + sample.fromMs;
|
|
139
|
+
const to = from + sample.elapsedMs;
|
|
140
|
+
const gc = gcPauses.filter(entry => entry.startTime >= from && entry.startTime < to);
|
|
141
|
+
Object.assign(sample, { calls: callsWithin(calls, from, to),
|
|
142
|
+
gc: { count: gc.length, durationMs: gc.reduce((sum, entry) => sum + entry.duration, 0) } });
|
|
143
|
+
}
|
|
113
144
|
assert.ok(samples.length > 0, 'health requests must overlap cold warming');
|
|
114
145
|
assert.ok(samples.every(sample => sample.fromMs < end - start && sample.endMs > 0));
|
|
115
146
|
// Keep first-open and repeated-open costs separate. Reopening must not rescan clean history.
|
|
@@ -124,12 +155,18 @@ try {
|
|
|
124
155
|
...verifyFacts(dataDir, fixtures, store), durationMs: end - start,
|
|
125
156
|
maxBlockingMs: Math.max(...samples.map(sample => sample.blockingMs)),
|
|
126
157
|
maxMainThreadCpuMs: Math.max(...samples.map(sample => sample.mainThreadCpuMs)),
|
|
158
|
+
maxLoopIdleMs: Math.max(...samples.map(sample => sample.loopIdleMs)),
|
|
159
|
+
firstSampleWaits: summarizeWaits(firstSampleWaits), firstSampleWaitTrace: firstSampleWaits.slice(0, 300),
|
|
127
160
|
sampleCount: samples.length, maxLatencyMs: Math.max(...samples.map(sample => sample.latencyMs)), samples };
|
|
128
161
|
console.log(JSON.stringify(result));
|
|
129
|
-
// Exclude run-queue delay
|
|
162
|
+
// Exclude run-queue delay and loop idle time: a response that waits on the thread pool, a worker
|
|
163
|
+
// or the kernel is latency (kept in maxLatencyMs), not main-thread blocking. Synchronous work counts.
|
|
130
164
|
assert.ok(result.maxBlockingMs < 50, `max health blocking ${result.maxBlockingMs.toFixed(3)}ms must be <50ms`);
|
|
131
165
|
} finally {
|
|
132
166
|
clearTimeout(watchdog);
|
|
167
|
+
unhookCalls?.();
|
|
168
|
+
gcObserver?.disconnect();
|
|
169
|
+
await threadWatch?.stop();
|
|
133
170
|
let cleanupTimer;
|
|
134
171
|
try {
|
|
135
172
|
if (server) await Promise.race([server.shutdownForRestart(), new Promise((_, reject) => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* node --expose-gc --import tsx packages/cezar/scripts/measure-transcript-facts-lag.mjs
|
|
3
3
|
* Built runtime: pass an absolute dist directory. Baseline source: pass its src directory and ts.
|
|
4
4
|
* A separate process removes test-runner loop work, NOT unrelated host CPU scheduling.
|
|
5
|
-
* Gate loop CPU and blocking time; exclude host run-queue delay.
|
|
5
|
+
* Gate loop CPU and blocking time; exclude loop idle time and host run-queue delay.
|
|
6
6
|
*/
|
|
7
7
|
import assert from 'node:assert/strict';
|
|
8
8
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
@@ -30,7 +30,7 @@ try {
|
|
|
30
30
|
timer = setInterval(() => {
|
|
31
31
|
const current = timingSnapshot();
|
|
32
32
|
const sample = timingDelta(previous, current);
|
|
33
|
-
ticks.push({ at: current.at, lagMs: Math.max(0, sample.elapsedMs - periodMs), ...sample, ...blockingBudget(sample
|
|
33
|
+
ticks.push({ at: current.at, lagMs: Math.max(0, sample.elapsedMs - periodMs), ...sample, ...blockingBudget(sample) });
|
|
34
34
|
previous = current;
|
|
35
35
|
}, periodMs);
|
|
36
36
|
// Establish a real interval before starting; retain the first tick after completion too.
|
|
@@ -69,7 +69,7 @@ try {
|
|
|
69
69
|
assert.ok(result.trailingTicks > 0, 'must retain a trailing tick after warming');
|
|
70
70
|
assert.ok(overlapping.length > 0, 'must sample during cold warm-up');
|
|
71
71
|
assert.ok(result.durationMs > 0);
|
|
72
|
-
// Exclude planned timer sleep and run-queue delay, but retain synchronous blocking.
|
|
72
|
+
// Exclude loop idle time (the planned timer sleep) and run-queue delay, but retain synchronous blocking.
|
|
73
73
|
assert.ok(result.maxBlockingMs < 20, `max interval blocking ${result.maxBlockingMs.toFixed(3)}ms must be <20ms`);
|
|
74
74
|
} finally {
|
|
75
75
|
clearInterval(timer);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Main-thread measurements only: worker CPU does not count as loop blocking. */
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { once } from 'node:events';
|
|
4
|
+
import { Worker } from 'node:worker_threads';
|
|
3
5
|
|
|
4
6
|
export function readQueueWaitMs({ read = readFileSync, platform = process.platform } = {}) {
|
|
5
7
|
// Linux schedstat field 2 is cumulative run-queue wait in nanoseconds.
|
|
@@ -11,34 +13,156 @@ export function readQueueWaitMs({ read = readFileSync, platform = process.platfo
|
|
|
11
13
|
catch { return null; /* Optional diagnostic on restricted procfs mounts. */ }
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
/** Linux per-thread major page faults and voluntary context switches: optional diagnostics
|
|
17
|
+
* that tell a disk page-in from a lock or I/O wait. Null where procfs cannot answer. */
|
|
18
|
+
export function readThreadStats({ read = readFileSync, platform = process.platform } = {}) {
|
|
19
|
+
if (platform !== 'linux') return null;
|
|
20
|
+
try {
|
|
21
|
+
const stat = read('/proc/thread-self/stat', 'utf8');
|
|
22
|
+
// Field 12 (majflt); the command name in field 2 may contain spaces, so count after ')'.
|
|
23
|
+
const majorFaults = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[9]);
|
|
24
|
+
const switches = /^voluntary_ctxt_switches:\s*(\d+)$/m.exec(read('/proc/thread-self/status', 'utf8'));
|
|
25
|
+
return Number.isFinite(majorFaults) && switches ? { majorFaults, voluntarySwitches: Number(switches[1]) } : null;
|
|
26
|
+
}
|
|
27
|
+
catch { return null; /* Optional diagnostic on restricted procfs mounts. */ }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** libuv idle time: the loop waited in its poll phase for I/O, a timer or another thread. */
|
|
31
|
+
export function readLoopIdleMs() {
|
|
32
|
+
return performance.eventLoopUtilization().idle;
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
export function timingSnapshot({ now = () => performance.now(), readQueue = readQueueWaitMs,
|
|
15
|
-
readCpu = () => process.threadCpuUsage() } = {}) {
|
|
36
|
+
readCpu = () => process.threadCpuUsage(), readLoopIdle = readLoopIdleMs, readThread = readThreadStats } = {}) {
|
|
37
|
+
const thread = readThread();
|
|
16
38
|
const cpu = readCpu();
|
|
39
|
+
const loopIdleMs = readLoopIdle();
|
|
17
40
|
const queueBeforeMs = readQueue();
|
|
18
41
|
const at = now();
|
|
19
42
|
const queueAfterMs = readQueue();
|
|
20
|
-
return { at, cpuMs: (cpu.user + cpu.system) / 1000, queueBeforeMs, queueAfterMs };
|
|
43
|
+
return { at, cpuMs: (cpu.user + cpu.system) / 1000, loopIdleMs, queueBeforeMs, queueAfterMs, thread };
|
|
21
44
|
}
|
|
22
45
|
|
|
23
46
|
export function timingDelta(start, end) {
|
|
24
47
|
const elapsedMs = end.at - start.at;
|
|
25
48
|
const mainThreadCpuMs = end.cpuMs - start.cpuMs;
|
|
49
|
+
// Snapshots run JavaScript, never inside the poll phase, so the idle delta lies in the interval.
|
|
50
|
+
const loopIdleMs = Math.max(0, Math.min(elapsedMs, end.loopIdleMs - start.loopIdleMs));
|
|
26
51
|
// Previous AFTER -> next BEFORE is contained in the wall-clock interval.
|
|
27
52
|
// Subtract only this inner queue-wait delta. A pause between a scheduler
|
|
28
53
|
// read and the clock must never credit wait from outside the interval.
|
|
29
54
|
const queueWaitMs = start.queueAfterMs === null || end.queueBeforeMs === null ? null
|
|
30
55
|
: Math.max(0, Math.min(elapsedMs, end.queueBeforeMs - start.queueAfterMs));
|
|
31
|
-
// Residual
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
// Residual: off-CPU time outside the poll phase (synchronous disk I/O, locks, Atomics.wait)
|
|
57
|
+
// plus measurement overhead. See blockingBudget for why the larger wait is subtracted once.
|
|
58
|
+
return { elapsedMs, mainThreadCpuMs, loopIdleMs, queueWaitMs,
|
|
59
|
+
blockedMs: queueWaitMs === null ? null : Math.max(0, elapsedMs - mainThreadCpuMs - Math.max(loopIdleMs, queueWaitMs)),
|
|
60
|
+
...(start.thread && end.thread ? { majorFaults: end.thread.majorFaults - start.thread.majorFaults,
|
|
61
|
+
voluntarySwitches: end.thread.voluntarySwitches - start.thread.voluntarySwitches } : {}) };
|
|
34
62
|
}
|
|
35
63
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
64
|
+
/** Main-thread blocking is loop-active time without run-queue wait. Loop idle time is excluded:
|
|
65
|
+
* a planned timer sleep, and a request waiting on the thread pool, a worker or the kernel, are
|
|
66
|
+
* latency but do not block the loop. CPU, synchronous disk I/O and Atomics.wait still count.
|
|
67
|
+
* libuv counts a run-queue wait after a poll wake-up as idle time too, and the two cannot be
|
|
68
|
+
* told apart, so only the larger of idle and run-queue wait is subtracted. Subtracting both
|
|
69
|
+
* could hide a synchronous stall; this choice can only over-count, never above elapsed minus
|
|
70
|
+
* run-queue wait. It never drops below main-thread CPU. */
|
|
71
|
+
export function blockingBudget(sample) {
|
|
38
72
|
const mode = sample.queueWaitMs === null ? 'cpu-only' : 'scheduler-adjusted';
|
|
39
73
|
const blockingMs = sample.queueWaitMs === null ? sample.mainThreadCpuMs
|
|
40
|
-
: Math.max(
|
|
41
|
-
return { mode, blockingMs: Math.max(0,
|
|
74
|
+
: Math.max(sample.mainThreadCpuMs, sample.elapsedMs - Math.max(sample.loopIdleMs, sample.queueWaitMs));
|
|
75
|
+
return { mode, blockingMs: Math.max(0, blockingMs) };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Light per-call timing (clock and thread CPU only), so many hooked calls add little loop time.
|
|
79
|
+
* Each call records its start; nested hooked calls are recorded too, under their own phase. */
|
|
80
|
+
export function hookCalls(hooks, calls) {
|
|
81
|
+
const restore = hooks.map(([target, name]) => {
|
|
82
|
+
const original = target[name];
|
|
83
|
+
target[name] = function (...args) {
|
|
84
|
+
const at = performance.now();
|
|
85
|
+
const cpu = process.threadCpuUsage();
|
|
86
|
+
try { return original.apply(this, args); }
|
|
87
|
+
finally {
|
|
88
|
+
const used = process.threadCpuUsage(cpu);
|
|
89
|
+
calls.push({ phase: name, at, elapsedMs: performance.now() - at, mainThreadCpuMs: (used.user + used.system) / 1000 });
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return () => { target[name] = original; };
|
|
93
|
+
});
|
|
94
|
+
return () => { for (const undo of restore) undo(); };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Per-phase totals of the calls that started in [from, to). */
|
|
98
|
+
export function callsWithin(calls, from, to) {
|
|
99
|
+
const phases = {};
|
|
100
|
+
for (const call of calls) {
|
|
101
|
+
if (call.at < from || call.at >= to) continue;
|
|
102
|
+
const total = phases[call.phase] ??= { count: 0, elapsedMs: 0, mainThreadCpuMs: 0, maxElapsedMs: 0 };
|
|
103
|
+
total.count++;
|
|
104
|
+
total.elapsedMs += call.elapsedMs;
|
|
105
|
+
total.mainThreadCpuMs += call.mainThreadCpuMs;
|
|
106
|
+
total.maxElapsedMs = Math.max(total.maxElapsedMs, call.elapsedMs);
|
|
107
|
+
}
|
|
108
|
+
return phases;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Polls the main thread's kernel state from another thread; records it whenever it is not running.
|
|
112
|
+
const WATCH_SOURCE = `
|
|
113
|
+
const { workerData, parentPort } = require('node:worker_threads');
|
|
114
|
+
const { readFileSync } = require('node:fs');
|
|
115
|
+
const flag = new Int32Array(workerData.flag);
|
|
116
|
+
const base = '/proc/' + workerData.pid + '/task/' + workerData.pid + '/';
|
|
117
|
+
const read = name => { try { return readFileSync(base + name, 'utf8').trim(); } catch { return null; } };
|
|
118
|
+
const seen = [];
|
|
119
|
+
parentPort.postMessage('ready');
|
|
120
|
+
for (let mode; (mode = Atomics.load(flag, 0)) !== 2;) {
|
|
121
|
+
if (mode === 0) { Atomics.wait(flag, 0, 0); continue; }
|
|
122
|
+
const stat = read('stat');
|
|
123
|
+
const state = stat === null ? '?' : stat.charAt(stat.lastIndexOf(')') + 2);
|
|
124
|
+
if (state !== 'R') {
|
|
125
|
+
seen.push({ at: performance.timeOrigin + performance.now(), state, wchan: read('wchan'),
|
|
126
|
+
syscall: read('syscall')?.split(' ')[0] ?? null });
|
|
127
|
+
Atomics.add(flag, 1, 1);
|
|
128
|
+
Atomics.notify(flag, 1);
|
|
129
|
+
}
|
|
130
|
+
Atomics.wait(flag, 0, 1, 1);
|
|
131
|
+
}
|
|
132
|
+
parentPort.postMessage(seen);
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
/** Diagnostics only (Linux): name what the main thread waits in, such as a futex, a sleep, a
|
|
136
|
+
* child process or a page fault, about once a millisecond while watching is on. */
|
|
137
|
+
export async function startThreadWatch() {
|
|
138
|
+
if (process.platform !== 'linux') return null;
|
|
139
|
+
// [0]: 0 paused, 1 watching, 2 stop. [1]: samples recorded so far.
|
|
140
|
+
const flag = new Int32Array(new SharedArrayBuffer(8));
|
|
141
|
+
const worker = new Worker(WATCH_SOURCE, { eval: true, workerData: { flag: flag.buffer, pid: process.pid } });
|
|
142
|
+
await once(worker, 'message');
|
|
143
|
+
const set = mode => { Atomics.store(flag, 0, mode); Atomics.notify(flag, 0); };
|
|
144
|
+
return {
|
|
145
|
+
watch: on => set(on ? 1 : 0),
|
|
146
|
+
/** Block the main thread until the watcher records one more sample: 'ok' or 'timed-out'. */
|
|
147
|
+
awaitRecord: timeoutMs => Atomics.wait(flag, 1, Atomics.load(flag, 1), timeoutMs) === 'timed-out' ? 'timed-out' : 'ok',
|
|
148
|
+
async stop() {
|
|
149
|
+
const reply = once(worker, 'message');
|
|
150
|
+
set(2);
|
|
151
|
+
const [seen] = await reply;
|
|
152
|
+
await worker.terminate();
|
|
153
|
+
return seen.map(entry => ({ ...entry, at: entry.at - performance.timeOrigin }));
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Counts of watched waits by state, syscall number and kernel wait channel. */
|
|
159
|
+
export function summarizeWaits(seen) {
|
|
160
|
+
const counts = {};
|
|
161
|
+
for (const entry of seen) {
|
|
162
|
+
const key = `${entry.state} syscall=${entry.syscall} ${entry.wchan}`;
|
|
163
|
+
counts[key] = (counts[key] ?? 0) + 1;
|
|
164
|
+
}
|
|
165
|
+
return counts;
|
|
42
166
|
}
|
|
43
167
|
|
|
44
168
|
/** Instrument only the synchronous open call. Imports and hook setup are outside its budget.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{An as r,Ar as i,Pn as a,ci as o,jn as s,nn as c}from"./project-scope-context-D9axDY18.js";import{$t as l,Ct as u,Gt as d,Ht as f,Kt as p,Mt as m,Rt as h,Ut as g,Xt as _,bt as v,ht as y,in as b,kt as x,lt as S,ot as C,st as w,ut as ee,yt as te}from"./queries-DzwCG927.js";import{t as ne}from"./useQuery-CzVHT8UE.js";import{f as T}from"./chunk-KS7C4IRE-Cg8l-LDN.js";import{n as E}from"./toaster-Bo5vCbz-.js";import{y as D}from"./design-icons-CzEoMH9c.js";import{t as O}from"./createLucideIcon-BHp8sXmF.js";import{t as k}from"./folder-browser-CffyHz8w.js";import{t as A}from"./button-BQ2y4XRB.js";import{t as j}from"./badge-D9JrXe0o.js";import{a as M,i as N,o as P,r as F,s as I,t as L}from"./dialog-BVF6dIeS.js";import{t as R}from"./status-dot-DtAOFiIi.js";import{n as z}from"./agents-settings-path-7X6_cvUg.js";import{t as B}from"./centered-state-V15AR_qo.js";import{Gt as V,Ht as H,Jt as U,Kt as W,N as G,Ut as K,Vt as q,Wt as J,j as re,qt as Y}from"./index-CHIFhfha.js";import{n as X,r as ie,t as ae}from"./settings-agent-picker-i4wCYEex.js";import{n as oe,r as se,t as ce}from"./remote-settings-notice-Drbpb7K4.js";var le=O(`id-card`,[[`path`,{d:`M16 10h2`,key:`8sgtl7`}],[`path`,{d:`M16 14h2`,key:`epxaof`}],[`path`,{d:`M6.17 15a3 3 0 0 1 5.66 0`,key:`n6f512`}],[`circle`,{cx:`9`,cy:`11`,r:`2`,key:`yxgjnd`}],[`rect`,{x:`2`,y:`5`,width:`20`,height:`14`,rx:`2`,key:`qneu4z`}]]),Z=e(t(),1),Q=n(),ue=`~/.claude-second`;function de({open:e,onOpenChange:t,providers:n,initialProvider:r}){let i=_().data,[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(r??n[0]??`claude`),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,v]=(0,Z.useState)(!1),y=ee(),b=m.trim();return(0,Q.jsx)(L,{open:e,onOpenChange:t,children:(0,Q.jsxs)(F,{"data-slot":`add-account-dialog`,className:`sm:max-w-lg`,children:[(0,Q.jsxs)(P,{children:[(0,Q.jsx)(I,{children:`Add agent account`}),(0,Q.jsx)(N,{children:`The config folder this account uses. It does not have to exist yet — Connect signs in and the CLI creates it.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Agent`}),(0,Q.jsx)(`select`,{"aria-label":`Agent`,"data-slot":`add-account-provider`,value:l,onChange:e=>u(e.target.value),className:`rounded-md border border-input bg-card px-2 py-1 text-[13px] outline-none focus-visible:border-ring`,children:n.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))})]}),(0,Q.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`Name`}),(0,Q.jsx)(`input`,{type:`text`,"aria-label":`Account name`,"data-slot":`add-account-label`,value:f,placeholder:`Work`,onChange:e=>p(e.target.value),className:`min-w-0 flex-1 rounded-md border border-input bg-card px-2 py-1 text-[13px] outline-none focus-visible:border-ring`})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsxs)(`label`,{className:`flex min-w-0 items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`Folder`}),(0,Q.jsx)(`input`,{type:`text`,spellCheck:!1,autoComplete:`off`,"aria-label":`Config folder`,"data-slot":`add-account-dir`,value:m,placeholder:d(i,l)?.accountFolderExample??ue,onChange:e=>{h(e.target.value),c(null),y.reset()},className:`min-w-0 flex-1 rounded-md border border-input bg-card px-2 py-1 font-mono text-[13px] outline-none focus-visible:border-ring`}),(0,Q.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,"data-action":`add-account-browse`,"aria-expanded":g,onClick:()=>v(e=>!e),children:g?`Hide folders`:`Browse…`})]}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-soft-foreground`,children:[`A `,(0,Q.jsx)(`code`,{children:`~`}),` is kept as written and expanded when the agent runs.`]})]}),g?(0,Q.jsx)(k,{path:a,selected:s,onSelect:e=>{c(e),h(e.path),y.reset()},onEnter:e=>{o(e),c(null),y.reset()},showHidden:!0,emptyHint:`No subfolders here — pick this folder by typing its path above.`}):null,y.isError?(0,Q.jsx)(`p`,{"data-slot":`add-account-error`,className:`min-w-0 break-words text-[13px] text-danger`,children:y.error instanceof Error?y.error.message:`could not add that folder`}):null,(0,Q.jsxs)(M,{className:`min-w-0 sm:items-center sm:justify-end`,children:[(0,Q.jsx)(A,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(A,{"data-slot":`add-account-confirm`,disabled:b===``||y.isPending,onClick:()=>{b===``||y.isPending||y.mutate({provider:l,configDir:b,...f.trim()?{label:f.trim()}:{}},{onSuccess:()=>{t(!1),p(``),h(``),c(null),v(!1),E(`Account added — use Connect to sign in`)}})},children:y.isPending?`Adding…`:`Add account`})]})]})})}async function fe(e){return a(await s.api.v1[`runner-install`][`:runner`].$get({param:{runner:e}}),`/runner-install/:runner`)}async function pe(e,t){return a(await s.api.v1[`runner-install`][`:runner`].$post({param:{runner:e},json:{action:t}}),`/runner-install/:runner`)}var me={idle:``,checking:`Checking for updates…`,downloading:`Downloading CLI…`,verifying:`Verifying CLI…`,extracting:`Extracting CLI…`,activating:`Activating CLI…`,removing:`Removing CLI…`,failed:``};function he(e){let t=y().data?.capabilities?.settingsAdmin===!0,n=o(),r=[`runner-install`,e],i=ne({queryKey:r,queryFn:()=>fe(e),enabled:t,retry:!1,refetchInterval:e=>{if(e.state.error)return!1;let t=e.state.data?.phase;return t&&t!==`idle`&&t!==`failed`?1e3:6e4}}),a=b({mutationFn:t=>pe(e,t),retry:!1,onSuccess:e=>{n.setQueryData(r,e)}}),s=i.data;return{allowed:t,data:s,busy:a.isPending||!!s&&s.phase!==`idle`&&s.phase!==`failed`,error:a.error?.message??i.error?.message??s?.error,action:a,status:i}}function ge({state:e}){let{data:t,busy:n,action:r,status:i}=e;if(t?.supported===!1)return(0,Q.jsx)(`p`,{children:`This host is not supported by the CLI installer.`});let a=!!t?.installedVersion;return(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(A,{className:`min-h-11 active:opacity-80`,disabled:n||!t,onClick:()=>r.mutate(a?`update`:`install`),children:a?`Update CLI`:`Install CLI`}),a?(0,Q.jsx)(A,{className:`min-h-11 active:opacity-80`,variant:`outline`,disabled:n,onClick:()=>r.mutate(`remove`),children:`Remove CLI`}):null,(0,Q.jsx)(A,{className:`min-h-11 active:opacity-80`,variant:`outline`,disabled:n,onClick:()=>{i.isError?i.refetch():r.mutate(`check`)},children:`Check for updates`})]})}function _e({runner:e}){let t=he(e),{allowed:n,data:r,busy:i,error:a}=t;return n?(0,Q.jsxs)(`section`,{"aria-label":`CLI installation`,className:`grid gap-3`,children:[(0,Q.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[r?.installedVersion?`Installed CLI ${r.installedVersion}`:`CLI not installed`,r?.latestVersion?` · Latest ${r.latestVersion}`:``,i&&r?` · ${me[r.phase]}`:``]}),a?(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:a}):null,(0,Q.jsx)(ge,{state:t}),r?.installedVersion?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Removing the CLI keeps account data and lets running tasks finish.`}):null]}):null}var ve={connected:{label:`Connected`,tone:`success`},disconnected:{label:`Not connected`,tone:`pending`},"not-installed":{label:`Not installed`,tone:`neutral`},unknown:{label:`Could not verify`,tone:`danger`}};function ye(){let e=w(),t=_();if(e.isPending||t.isPending)return(0,Q.jsx)(`p`,{"data-slot":`accounts-loading`,className:`p-4 text-[13px] text-soft-foreground md:p-6`,children:`Loading agents…`});let n=e.error??t.error;return n?(0,Q.jsx)(B,{icon:(0,Q.jsx)(le,{}),tone:`danger`,title:`Agents did not load`,subtitle:n.message,heading:`h2`}):(0,Q.jsx)($,{data:e.data,runners:t.data})}function be(){let{hash:e}=T();(0,Z.useEffect)(()=>{if(!e)return;let t=document.getElementById(decodeURIComponent(e.slice(1)));t&&(t.scrollIntoView?.({block:`start`}),t.focus({preventScroll:!0}))},[e])}function $({data:e,runners:t}){let n=y(),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(null),s=u();return be(),se(),(0,Q.jsxs)(`div`,{"data-slot":`accounts-section`,className:`mx-auto flex w-full max-w-2xl flex-col gap-5 p-4 pb-[calc(90px+env(safe-area-inset-bottom))] md:p-6 md:pb-6`,children:[(0,Q.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`Install, update and sign in to each agent, and set what a project runs when it has not chosen.`}),(0,Q.jsx)(oe,{risk:`Agent accounts run each CLI with the configured host folder`}),e.editable?null:(0,Q.jsxs)(`p`,{"data-slot":`accounts-hosted`,className:`text-[13px] text-soft-foreground`,children:[`Agent accounts are read-only on this remote cockpit. Run`,` `,(0,Q.jsx)(`code`,{children:ce}),` on the host to add, edit, or sign in to accounts here.`]}),(0,Q.jsx)(`div`,{"data-slot":`agent-cards`,className:`flex flex-col gap-4`,children:t.runners.map(r=>(0,Q.jsx)(Se,{entry:r,check:n.data?.checks?.find(e=>e.name===r.id),settingsAdmin:n.data?.capabilities?.settingsAdmin===!0,runners:t,editable:e.editable,accounts:e.profiles.filter(e=>e.provider===r.id),canCarryAccounts:e.profileCapableProviders.includes(r.id),onAdd:()=>i(r.id),onRemove:o},r.id))}),(0,Q.jsx)(Ce,{runners:t}),r===null?null:(0,Q.jsx)(de,{open:!0,onOpenChange:e=>!e&&i(null),providers:e.profileCapableProviders,initialProvider:r},r),(0,Q.jsx)(q,{open:a!==null,onOpenChange:e=>!e&&o(null),children:(0,Q.jsxs)(J,{"data-slot":`accounts-remove-confirm`,children:[(0,Q.jsxs)(Y,{children:[(0,Q.jsxs)(U,{children:[`Remove “`,a?.label,`”?`]}),(0,Q.jsxs)(V,{children:[`This only forgets the account. Nothing in `,a?.configDir??`this account’s folder`,` is deleted — not your login, not your sessions. Projects using it fall back to the default account, and tasks that ran under it can no longer be resumed from here.`]})]}),(0,Q.jsxs)(W,{children:[(0,Q.jsx)(K,{children:`Cancel`}),(0,Q.jsx)(H,{"data-action":`accounts-remove-confirm`,disabled:s.isPending,onClick:()=>{let e=a;e&&s.mutate(e.id,{onSuccess:()=>{o(null),E(`Removed ${e.label}`)},onError:e=>E(e.message,{tone:`danger`})})},children:`Remove`})]})]})})]})}function xe({entry:e,check:t}){return t===void 0?(0,Q.jsx)(`span`,{"data-slot":`agent-installed`,children:`Checking…`}):t.available?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"data-slot":`agent-installed`,children:`Installed`}),t.version?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:` · `}),(0,Q.jsx)(`span`,{"data-slot":`agent-version`,children:t.version})]}):null]}):(0,Q.jsxs)(`span`,{"data-slot":`agent-installed`,children:[`Not installed`,e.installHint?(0,Q.jsxs)(Q.Fragment,{children:[` — `,(0,Q.jsx)(`code`,{className:`break-all`,children:e.installHint})]}):null]})}function Se({entry:e,check:t,settingsAdmin:n,runners:r,editable:i,accounts:a,canCarryAccounts:o,onAdd:s,onRemove:c}){let l=e.id,u=e.managedInstall===!0&&n,d=a.filter(e=>e.isDefault).length,f=`${z(l)}-title`;return(0,Q.jsxs)(`section`,{id:z(l),tabIndex:-1,"aria-labelledby":f,"data-slot":`accounts-provider`,"data-provider":l,className:`settings-agent-card flex flex-col gap-4 rounded-lg border border-border bg-card p-4`,children:[(0,Q.jsx)(`h3`,{id:f,className:`settings-account-provider-title`,children:e.displayName}),u?(0,Q.jsx)(_e,{runner:l}):null,(0,Q.jsxs)(`div`,{className:`settings-account-installation settings-readout`,children:[u?null:(0,Q.jsx)(xe,{entry:e,check:t}),i||a.length>0?(0,Q.jsxs)(`span`,{className:`settings-account-count`,children:[a.length,` `,a.length===1?`account`:`accounts`,` (`,d,` discovered, `,a.length-d,` added)`]}):null]}),a.length>0?(0,Q.jsx)(`ul`,{children:a.map(e=>(0,Q.jsx)(De,{account:e,runners:r,editable:i,onRemove:()=>c(e)},e.id))}):null,i?o?(0,Q.jsx)(`div`,{className:`settings-account-add-row`,children:(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`accounts-add`,"data-provider":l,onClick:s,children:`Add account`})}):(0,Q.jsxs)(`p`,{"data-slot":`accounts-single-only`,className:`text-[11px] text-soft-foreground`,children:[e.displayName,` can only hold one account here: it keeps its credentials outside its config folder, so a second folder would change settings without changing the login — which would say “work account” while billing the other one.`]}):a.length===0&&e.browserLogin?(0,Q.jsxs)(`div`,{"data-slot":`hosted-sign-in`,className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`Discovered account`}),(0,Q.jsx)(X,{provider:l,label:e.displayName})]}):null]})}function Ce({runners:e}){let[t,n]=(0,Z.useState)(null),r=o(),i=m(),a=te(),s=l(p(e)),u=b({mutationFn:e=>c(e),onSuccess:e=>r.setQueryData(h.config,e),onError:e=>E(e.message,{tone:`danger`})});if(i.data===void 0)return null;let d=ie([],e),g=i.data.agentDefaults.runner??`claude`,_=f(t??g,p(e))??t??g,v=i.data.agentDefaults.models??{};return(0,Q.jsxs)(`section`,{"data-slot":`accounts-defaults`,className:`flex flex-col gap-3 rounded-lg border border-border bg-card/40 p-3.5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-[13px] font-semibold text-foreground`,children:`Defaults for new projects`}),(0,Q.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`What a project runs when it has not chosen for itself — set once instead of per repository. A project that has chosen keeps its own.`})]}),(0,Q.jsx)(ae,{rows:d,runner:g,accountFor:()=>null,providerStatus:a,disabled:u.isPending,onPick:e=>{e!==g&&u.mutate({agentDefaults:{runner:e}})}}),(0,Q.jsxs)(`div`,{className:`settings-account-models flex flex-col gap-2`,children:[(0,Q.jsxs)(`label`,{className:`settings-model-agent-choice`,children:[(0,Q.jsx)(`span`,{children:`Default model for`}),(0,Q.jsx)(`select`,{"aria-label":`Model agent`,value:_,onChange:e=>n(e.target.value),children:e.runners.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.displayName},e.id))})]}),e.runners.filter(e=>e.id===_).map(t=>(0,Q.jsxs)(`label`,{className:`settings-account-model flex items-center gap-3`,children:[(0,Q.jsx)(D,{className:`size-4 text-accent-icon shrink-0`}),(0,Q.jsx)(`span`,{className:`w-24 shrink-0 text-xs text-muted-foreground`,children:t.displayName}),(0,Q.jsxs)(`select`,{"aria-label":`Default model for ${t.pickerLabel}`,"data-slot":`accounts-default-model`,"data-runner":t.id,value:v[t.id]??``,disabled:u.isPending,onChange:e=>u.mutate({agentDefaults:{models:{[t.id]:e.target.value||null}}}),className:`block w-full max-w-xs rounded-md border border-input bg-card px-3 py-1.5 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50`,children:[G(t.id,e,s[t.id]?.data,[v[t.id]]).map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.id===``?`Native default`:e.label},e.id)),(0,Q.jsx)(we,{runner:t.id,runners:e,catalog:s[t.id]})]})]},t.id))]})]})}function we({runner:e,runners:t,catalog:n}){let r=re(e,t,n);return r?(0,Q.jsx)(`option`,{disabled:!0,children:r}):null}function Te({account:e,runners:t,status:n,editable:i}){let a=S();return(0,Q.jsxs)(Q.Fragment,{children:[n&&n.status!==`connected`&&d(t,e.provider)?.browserLogin?(0,Q.jsx)(X,{provider:e.provider,...e.isDefault?{}:{profileId:e.id},label:e.label}):null,i&&n&&n.status!==`connected`&&d(t,e.provider)?.terminalLogin!==!1?(0,Q.jsx)(A,{type:`button`,size:`sm`,"data-action":`account-connect`,disabled:a.isPending,onClick:()=>a.mutate({provider:e.provider,...e.isDefault?{}:{profileId:e.id}},{onSuccess:e=>E(e.opened?`Finish signing in in the terminal, then Check again.`:`This account is already connected.`),onError:e=>E(e instanceof r&&e.command?`${e.message} — run: ${e.command}`:e.message,{tone:`danger`})}),children:`Connect`}):null]})}function Ee({account:e,runners:t,status:n,editable:r}){return!n||n.requiresAccountHome===!1?null:e.exists?!e.looksValid&&e.configDir?(0,Q.jsxs)(`span`,{"data-slot":`account-unrecognised`,children:[`— this folder does not look like `,g(t,e.provider),` config yet`]}):null:(0,Q.jsx)(`span`,{"data-slot":`account-missing`,children:r?`— folder not created yet; Connect will make it`:`— not initialized on host yet`})}function De({account:e,runners:t,editable:n,onRemove:r}){let a=i(e),o=v(),s=C(a,e.status===void 0),c=e.status??s.data?.status,l=c?ve[c.status]:void 0;return(0,Q.jsx)(`li`,{"data-slot":`account-row`,"data-account":e.id,className:`flex flex-col gap-2 px-3.5 py-3`,children:(0,Q.jsxs)(`div`,{className:`settings-account-card`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:e.label}),e.isDefault?(0,Q.jsx)(j,{variant:`ghost`,className:`shrink-0 text-[12px] text-muted-foreground`,children:`discovered`}):null]}),(0,Q.jsxs)(`div`,{className:`settings-account-readout settings-readout`,children:[e.configDir?(0,Q.jsx)(`p`,{"data-slot":`account-path`,className:`mt-0.5 truncate font-mono text-[11px] text-soft-foreground`,title:e.path,children:e.configDir}):null,(0,Q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(R,{tone:l?.tone??`neutral`,pulse:l===void 0}),(0,Q.jsx)(`span`,{"data-slot":`account-status`,children:l?.label??`Checking…`}),(0,Q.jsx)(Ee,{account:e,runners:t,status:c,editable:n})]}),c?.hint?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c.hint}):null]})]}),(0,Q.jsxs)(`div`,{className:`settings-account-actions`,children:[(0,Q.jsx)(Te,{account:e,runners:t,status:c,editable:n}),(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`account-recheck`,disabled:o.isPending,title:`Re-probe this account's login now, instead of waiting for the cached answer`,onClick:()=>o.mutate(a,{onError:e=>E(e.message,{tone:`danger`})}),children:`Check again`}),n?(0,Q.jsx)(Oe,{account:e,onRemove:r}):null]})]})})}function Oe({account:e,onRemove:t}){let[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(e.label),o=x();return(0,Q.jsx)(Q.Fragment,{children:e.isDefault?null:(0,Q.jsx)(`div`,{"data-slot":`account-manage`,className:`settings-account-management`,children:n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{type:`text`,autoFocus:!0,"aria-label":`Name for ${e.label}`,"data-slot":`account-rename-input`,value:i,onChange:e=>a(e.target.value),className:`w-48 rounded-md border border-input bg-card px-2 py-1 text-xs outline-none focus-visible:border-ring`}),(0,Q.jsx)(A,{type:`button`,size:`sm`,"data-action":`account-rename-save`,disabled:o.isPending||i.trim()===``||i.trim()===e.label,onClick:()=>o.mutate({id:e.id,label:i.trim()},{onSuccess:()=>r(!1),onError:e=>E(e.message,{tone:`danger`})}),children:`Save`}),(0,Q.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{a(e.label),r(!1)},children:`Cancel`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`account-rename`,onClick:()=>r(!0),children:`Rename`}),(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`account-remove`,onClick:t,children:`Remove account`}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Renaming changes what Squawk calls this account, not its folder.`})]})})})}export{ye as GlobalAgentsSection};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{An as r,Ar as i,Pn as a,ci as o,jn as s,nn as c}from"./project-scope-context-blU6DPq1.js";import{$t as l,Ct as u,Gt as d,Ht as f,Kt as p,Mt as m,Rt as h,Ut as g,Xt as _,bt as v,ht as y,in as b,kt as x,lt as S,ot as C,st as w,ut as ee,yt as te}from"./queries-CihFAzQA.js";import{t as ne}from"./useQuery-Ys0_fBIg.js";import{f as T}from"./chunk-KS7C4IRE-Cg8l-LDN.js";import{n as E}from"./toaster-Bo5vCbz-.js";import{y as D}from"./design-icons-CzEoMH9c.js";import{t as O}from"./createLucideIcon-BHp8sXmF.js";import{t as k}from"./folder-browser-Bv_vTEU3.js";import{t as A}from"./button-BQ2y4XRB.js";import{t as j}from"./badge-D9JrXe0o.js";import{a as M,i as N,o as P,r as F,s as I,t as L}from"./dialog-BVF6dIeS.js";import{t as R}from"./status-dot-DtAOFiIi.js";import{n as z}from"./agents-settings-path-7X6_cvUg.js";import{t as B}from"./centered-state-V15AR_qo.js";import{Gt as V,Ht as H,Jt as U,Kt as W,N as G,Ut as K,Vt as q,Wt as J,j as re,qt as Y}from"./index-DCIRYVqB.js";import{n as X,r as ie,t as ae}from"./settings-agent-picker-rNyNJEU2.js";import{n as oe,r as se,t as ce}from"./remote-settings-notice-BEn0VAfk.js";var le=O(`id-card`,[[`path`,{d:`M16 10h2`,key:`8sgtl7`}],[`path`,{d:`M16 14h2`,key:`epxaof`}],[`path`,{d:`M6.17 15a3 3 0 0 1 5.66 0`,key:`n6f512`}],[`circle`,{cx:`9`,cy:`11`,r:`2`,key:`yxgjnd`}],[`rect`,{x:`2`,y:`5`,width:`20`,height:`14`,rx:`2`,key:`qneu4z`}]]),Z=e(t(),1),Q=n(),ue=`~/.claude-second`;function de({open:e,onOpenChange:t,providers:n,initialProvider:r}){let i=_().data,[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(r??n[0]??`claude`),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,v]=(0,Z.useState)(!1),y=ee(),b=m.trim();return(0,Q.jsx)(L,{open:e,onOpenChange:t,children:(0,Q.jsxs)(F,{"data-slot":`add-account-dialog`,className:`sm:max-w-lg`,children:[(0,Q.jsxs)(P,{children:[(0,Q.jsx)(I,{children:`Add agent account`}),(0,Q.jsx)(N,{children:`The config folder this account uses. It does not have to exist yet — Connect signs in and the CLI creates it.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Agent`}),(0,Q.jsx)(`select`,{"aria-label":`Agent`,"data-slot":`add-account-provider`,value:l,onChange:e=>u(e.target.value),className:`rounded-md border border-input bg-card px-2 py-1 text-[13px] outline-none focus-visible:border-ring`,children:n.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))})]}),(0,Q.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`Name`}),(0,Q.jsx)(`input`,{type:`text`,"aria-label":`Account name`,"data-slot":`add-account-label`,value:f,placeholder:`Work`,onChange:e=>p(e.target.value),className:`min-w-0 flex-1 rounded-md border border-input bg-card px-2 py-1 text-[13px] outline-none focus-visible:border-ring`})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsxs)(`label`,{className:`flex min-w-0 items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`Folder`}),(0,Q.jsx)(`input`,{type:`text`,spellCheck:!1,autoComplete:`off`,"aria-label":`Config folder`,"data-slot":`add-account-dir`,value:m,placeholder:d(i,l)?.accountFolderExample??ue,onChange:e=>{h(e.target.value),c(null),y.reset()},className:`min-w-0 flex-1 rounded-md border border-input bg-card px-2 py-1 font-mono text-[13px] outline-none focus-visible:border-ring`}),(0,Q.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,"data-action":`add-account-browse`,"aria-expanded":g,onClick:()=>v(e=>!e),children:g?`Hide folders`:`Browse…`})]}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-soft-foreground`,children:[`A `,(0,Q.jsx)(`code`,{children:`~`}),` is kept as written and expanded when the agent runs.`]})]}),g?(0,Q.jsx)(k,{path:a,selected:s,onSelect:e=>{c(e),h(e.path),y.reset()},onEnter:e=>{o(e),c(null),y.reset()},showHidden:!0,emptyHint:`No subfolders here — pick this folder by typing its path above.`}):null,y.isError?(0,Q.jsx)(`p`,{"data-slot":`add-account-error`,className:`min-w-0 break-words text-[13px] text-danger`,children:y.error instanceof Error?y.error.message:`could not add that folder`}):null,(0,Q.jsxs)(M,{className:`min-w-0 sm:items-center sm:justify-end`,children:[(0,Q.jsx)(A,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(A,{"data-slot":`add-account-confirm`,disabled:b===``||y.isPending,onClick:()=>{b===``||y.isPending||y.mutate({provider:l,configDir:b,...f.trim()?{label:f.trim()}:{}},{onSuccess:()=>{t(!1),p(``),h(``),c(null),v(!1),E(`Account added — use Connect to sign in`)}})},children:y.isPending?`Adding…`:`Add account`})]})]})})}async function fe(e){return a(await s.api.v1[`runner-install`][`:runner`].$get({param:{runner:e}}),`/runner-install/:runner`)}async function pe(e,t){return a(await s.api.v1[`runner-install`][`:runner`].$post({param:{runner:e},json:{action:t}}),`/runner-install/:runner`)}var me={idle:``,checking:`Checking for updates…`,downloading:`Downloading CLI…`,verifying:`Verifying CLI…`,extracting:`Extracting CLI…`,activating:`Activating CLI…`,removing:`Removing CLI…`,failed:``};function he(e){let t=y().data?.capabilities?.settingsAdmin===!0,n=o(),r=[`runner-install`,e],i=ne({queryKey:r,queryFn:()=>fe(e),enabled:t,retry:!1,refetchInterval:e=>{if(e.state.error)return!1;let t=e.state.data?.phase;return t&&t!==`idle`&&t!==`failed`?1e3:6e4}}),a=b({mutationFn:t=>pe(e,t),retry:!1,onSuccess:e=>{n.setQueryData(r,e)}}),s=i.data;return{allowed:t,data:s,busy:a.isPending||!!s&&s.phase!==`idle`&&s.phase!==`failed`,error:a.error?.message??i.error?.message??s?.error,action:a,status:i}}function ge({state:e}){let{data:t,busy:n,action:r,status:i}=e;if(t?.supported===!1)return(0,Q.jsx)(`p`,{children:`This host is not supported by the CLI installer.`});let a=!!t?.installedVersion;return(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(A,{className:`min-h-11 active:opacity-80`,disabled:n||!t,onClick:()=>r.mutate(a?`update`:`install`),children:a?`Update CLI`:`Install CLI`}),a?(0,Q.jsx)(A,{className:`min-h-11 active:opacity-80`,variant:`outline`,disabled:n,onClick:()=>r.mutate(`remove`),children:`Remove CLI`}):null,(0,Q.jsx)(A,{className:`min-h-11 active:opacity-80`,variant:`outline`,disabled:n,onClick:()=>{i.isError?i.refetch():r.mutate(`check`)},children:`Check for updates`})]})}function _e({runner:e}){let t=he(e),{allowed:n,data:r,busy:i,error:a}=t;return n?(0,Q.jsxs)(`section`,{"aria-label":`CLI installation`,className:`grid gap-3`,children:[(0,Q.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[r?.installedVersion?`Installed CLI ${r.installedVersion}`:`CLI not installed`,r?.latestVersion?` · Latest ${r.latestVersion}`:``,i&&r?` · ${me[r.phase]}`:``]}),a?(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:a}):null,(0,Q.jsx)(ge,{state:t}),r?.installedVersion?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Removing the CLI keeps account data and lets running tasks finish.`}):null]}):null}var ve={connected:{label:`Connected`,tone:`success`},disconnected:{label:`Not connected`,tone:`pending`},"not-installed":{label:`Not installed`,tone:`neutral`},unknown:{label:`Could not verify`,tone:`danger`}};function ye(){let e=w(),t=_();if(e.isPending||t.isPending)return(0,Q.jsx)(`p`,{"data-slot":`accounts-loading`,className:`p-4 text-[13px] text-soft-foreground md:p-6`,children:`Loading agents…`});let n=e.error??t.error;return n?(0,Q.jsx)(B,{icon:(0,Q.jsx)(le,{}),tone:`danger`,title:`Agents did not load`,subtitle:n.message,heading:`h2`}):(0,Q.jsx)($,{data:e.data,runners:t.data})}function be(){let{hash:e}=T();(0,Z.useEffect)(()=>{if(!e)return;let t=document.getElementById(decodeURIComponent(e.slice(1)));t&&(t.scrollIntoView?.({block:`start`}),t.focus({preventScroll:!0}))},[e])}function $({data:e,runners:t}){let n=y(),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(null),s=u();return be(),se(),(0,Q.jsxs)(`div`,{"data-slot":`accounts-section`,className:`mx-auto flex w-full max-w-2xl flex-col gap-5 p-4 pb-[calc(90px+env(safe-area-inset-bottom))] md:p-6 md:pb-6`,children:[(0,Q.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`Install, update and sign in to each agent, and set what a project runs when it has not chosen.`}),(0,Q.jsx)(oe,{risk:`Agent accounts run each CLI with the configured host folder`}),e.editable?null:(0,Q.jsxs)(`p`,{"data-slot":`accounts-hosted`,className:`text-[13px] text-soft-foreground`,children:[`Agent accounts are read-only on this remote cockpit. Run`,` `,(0,Q.jsx)(`code`,{children:ce}),` on the host to add, edit, or sign in to accounts here.`]}),(0,Q.jsx)(`div`,{"data-slot":`agent-cards`,className:`flex flex-col gap-4`,children:t.runners.map(r=>(0,Q.jsx)(Se,{entry:r,check:n.data?.checks?.find(e=>e.name===r.id),settingsAdmin:n.data?.capabilities?.settingsAdmin===!0,runners:t,editable:e.editable,accounts:e.profiles.filter(e=>e.provider===r.id),canCarryAccounts:e.profileCapableProviders.includes(r.id),onAdd:()=>i(r.id),onRemove:o},r.id))}),(0,Q.jsx)(Ce,{runners:t}),r===null?null:(0,Q.jsx)(de,{open:!0,onOpenChange:e=>!e&&i(null),providers:e.profileCapableProviders,initialProvider:r},r),(0,Q.jsx)(q,{open:a!==null,onOpenChange:e=>!e&&o(null),children:(0,Q.jsxs)(J,{"data-slot":`accounts-remove-confirm`,children:[(0,Q.jsxs)(Y,{children:[(0,Q.jsxs)(U,{children:[`Remove “`,a?.label,`”?`]}),(0,Q.jsxs)(V,{children:[`This only forgets the account. Nothing in `,a?.configDir??`this account’s folder`,` is deleted — not your login, not your sessions. Projects using it fall back to the default account, and tasks that ran under it can no longer be resumed from here.`]})]}),(0,Q.jsxs)(W,{children:[(0,Q.jsx)(K,{children:`Cancel`}),(0,Q.jsx)(H,{"data-action":`accounts-remove-confirm`,disabled:s.isPending,onClick:()=>{let e=a;e&&s.mutate(e.id,{onSuccess:()=>{o(null),E(`Removed ${e.label}`)},onError:e=>E(e.message,{tone:`danger`})})},children:`Remove`})]})]})})]})}function xe({entry:e,check:t}){return t===void 0?(0,Q.jsx)(`span`,{"data-slot":`agent-installed`,children:`Checking…`}):t.available?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"data-slot":`agent-installed`,children:`Installed`}),t.version?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:` · `}),(0,Q.jsx)(`span`,{"data-slot":`agent-version`,children:t.version})]}):null]}):(0,Q.jsxs)(`span`,{"data-slot":`agent-installed`,children:[`Not installed`,e.installHint?(0,Q.jsxs)(Q.Fragment,{children:[` — `,(0,Q.jsx)(`code`,{className:`break-all`,children:e.installHint})]}):null]})}function Se({entry:e,check:t,settingsAdmin:n,runners:r,editable:i,accounts:a,canCarryAccounts:o,onAdd:s,onRemove:c}){let l=e.id,u=e.managedInstall===!0&&n,d=a.filter(e=>e.isDefault).length,f=`${z(l)}-title`;return(0,Q.jsxs)(`section`,{id:z(l),tabIndex:-1,"aria-labelledby":f,"data-slot":`accounts-provider`,"data-provider":l,className:`settings-agent-card flex flex-col gap-4 rounded-lg border border-border bg-card p-4`,children:[(0,Q.jsx)(`h3`,{id:f,className:`settings-account-provider-title`,children:e.displayName}),u?(0,Q.jsx)(_e,{runner:l}):null,(0,Q.jsxs)(`div`,{className:`settings-account-installation settings-readout`,children:[u?null:(0,Q.jsx)(xe,{entry:e,check:t}),i||a.length>0?(0,Q.jsxs)(`span`,{className:`settings-account-count`,children:[a.length,` `,a.length===1?`account`:`accounts`,` (`,d,` discovered, `,a.length-d,` added)`]}):null]}),a.length>0?(0,Q.jsx)(`ul`,{children:a.map(e=>(0,Q.jsx)(De,{account:e,runners:r,editable:i,onRemove:()=>c(e)},e.id))}):null,i?o?(0,Q.jsx)(`div`,{className:`settings-account-add-row`,children:(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`accounts-add`,"data-provider":l,onClick:s,children:`Add account`})}):(0,Q.jsxs)(`p`,{"data-slot":`accounts-single-only`,className:`text-[11px] text-soft-foreground`,children:[e.displayName,` can only hold one account here: it keeps its credentials outside its config folder, so a second folder would change settings without changing the login — which would say “work account” while billing the other one.`]}):a.length===0&&e.browserLogin?(0,Q.jsxs)(`div`,{"data-slot":`hosted-sign-in`,className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`Discovered account`}),(0,Q.jsx)(X,{provider:l,label:e.displayName})]}):null]})}function Ce({runners:e}){let[t,n]=(0,Z.useState)(null),r=o(),i=m(),a=te(),s=l(p(e)),u=b({mutationFn:e=>c(e),onSuccess:e=>r.setQueryData(h.config,e),onError:e=>E(e.message,{tone:`danger`})});if(i.data===void 0)return null;let d=ie([],e),g=i.data.agentDefaults.runner??`claude`,_=f(t??g,p(e))??t??g,v=i.data.agentDefaults.models??{};return(0,Q.jsxs)(`section`,{"data-slot":`accounts-defaults`,className:`flex flex-col gap-3 rounded-lg border border-border bg-card/40 p-3.5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-[13px] font-semibold text-foreground`,children:`Defaults for new projects`}),(0,Q.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`What a project runs when it has not chosen for itself — set once instead of per repository. A project that has chosen keeps its own.`})]}),(0,Q.jsx)(ae,{rows:d,runner:g,accountFor:()=>null,providerStatus:a,disabled:u.isPending,onPick:e=>{e!==g&&u.mutate({agentDefaults:{runner:e}})}}),(0,Q.jsxs)(`div`,{className:`settings-account-models flex flex-col gap-2`,children:[(0,Q.jsxs)(`label`,{className:`settings-model-agent-choice`,children:[(0,Q.jsx)(`span`,{children:`Default model for`}),(0,Q.jsx)(`select`,{"aria-label":`Model agent`,value:_,onChange:e=>n(e.target.value),children:e.runners.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.displayName},e.id))})]}),e.runners.filter(e=>e.id===_).map(t=>(0,Q.jsxs)(`label`,{className:`settings-account-model flex items-center gap-3`,children:[(0,Q.jsx)(D,{className:`size-4 text-accent-icon shrink-0`}),(0,Q.jsx)(`span`,{className:`w-24 shrink-0 text-xs text-muted-foreground`,children:t.displayName}),(0,Q.jsxs)(`select`,{"aria-label":`Default model for ${t.pickerLabel}`,"data-slot":`accounts-default-model`,"data-runner":t.id,value:v[t.id]??``,disabled:u.isPending,onChange:e=>u.mutate({agentDefaults:{models:{[t.id]:e.target.value||null}}}),className:`block w-full max-w-xs rounded-md border border-input bg-card px-3 py-1.5 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50`,children:[G(t.id,e,s[t.id]?.data,[v[t.id]]).map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.id===``?`Native default`:e.label},e.id)),(0,Q.jsx)(we,{runner:t.id,runners:e,catalog:s[t.id]})]})]},t.id))]})]})}function we({runner:e,runners:t,catalog:n}){let r=re(e,t,n);return r?(0,Q.jsx)(`option`,{disabled:!0,children:r}):null}function Te({account:e,runners:t,status:n,editable:i}){let a=S();return(0,Q.jsxs)(Q.Fragment,{children:[n&&n.status!==`connected`&&d(t,e.provider)?.browserLogin?(0,Q.jsx)(X,{provider:e.provider,...e.isDefault?{}:{profileId:e.id},label:e.label}):null,i&&n&&n.status!==`connected`&&d(t,e.provider)?.terminalLogin!==!1?(0,Q.jsx)(A,{type:`button`,size:`sm`,"data-action":`account-connect`,disabled:a.isPending,onClick:()=>a.mutate({provider:e.provider,...e.isDefault?{}:{profileId:e.id}},{onSuccess:e=>E(e.opened?`Finish signing in in the terminal, then Check again.`:`This account is already connected.`),onError:e=>E(e instanceof r&&e.command?`${e.message} — run: ${e.command}`:e.message,{tone:`danger`})}),children:`Connect`}):null]})}function Ee({account:e,runners:t,status:n,editable:r}){return!n||n.requiresAccountHome===!1?null:e.exists?!e.looksValid&&e.configDir?(0,Q.jsxs)(`span`,{"data-slot":`account-unrecognised`,children:[`— this folder does not look like `,g(t,e.provider),` config yet`]}):null:(0,Q.jsx)(`span`,{"data-slot":`account-missing`,children:r?`— folder not created yet; Connect will make it`:`— not initialized on host yet`})}function De({account:e,runners:t,editable:n,onRemove:r}){let a=i(e),o=v(),s=C(a,e.status===void 0),c=e.status??s.data?.status,l=c?ve[c.status]:void 0;return(0,Q.jsx)(`li`,{"data-slot":`account-row`,"data-account":e.id,className:`flex flex-col gap-2 px-3.5 py-3`,children:(0,Q.jsxs)(`div`,{className:`settings-account-card`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:e.label}),e.isDefault?(0,Q.jsx)(j,{variant:`ghost`,className:`shrink-0 text-[12px] text-muted-foreground`,children:`discovered`}):null]}),(0,Q.jsxs)(`div`,{className:`settings-account-readout settings-readout`,children:[e.configDir?(0,Q.jsx)(`p`,{"data-slot":`account-path`,className:`mt-0.5 truncate font-mono text-[11px] text-soft-foreground`,title:e.path,children:e.configDir}):null,(0,Q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(R,{tone:l?.tone??`neutral`,pulse:l===void 0}),(0,Q.jsx)(`span`,{"data-slot":`account-status`,children:l?.label??`Checking…`}),(0,Q.jsx)(Ee,{account:e,runners:t,status:c,editable:n})]}),c?.hint?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c.hint}):null]})]}),(0,Q.jsxs)(`div`,{className:`settings-account-actions`,children:[(0,Q.jsx)(Te,{account:e,runners:t,status:c,editable:n}),(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`account-recheck`,disabled:o.isPending,title:`Re-probe this account's login now, instead of waiting for the cached answer`,onClick:()=>o.mutate(a,{onError:e=>E(e.message,{tone:`danger`})}),children:`Check again`}),n?(0,Q.jsx)(Oe,{account:e,onRemove:r}):null]})]})})}function Oe({account:e,onRemove:t}){let[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(e.label),o=x();return(0,Q.jsx)(Q.Fragment,{children:e.isDefault?null:(0,Q.jsx)(`div`,{"data-slot":`account-manage`,className:`settings-account-management`,children:n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{type:`text`,autoFocus:!0,"aria-label":`Name for ${e.label}`,"data-slot":`account-rename-input`,value:i,onChange:e=>a(e.target.value),className:`w-48 rounded-md border border-input bg-card px-2 py-1 text-xs outline-none focus-visible:border-ring`}),(0,Q.jsx)(A,{type:`button`,size:`sm`,"data-action":`account-rename-save`,disabled:o.isPending||i.trim()===``||i.trim()===e.label,onClick:()=>o.mutate({id:e.id,label:i.trim()},{onSuccess:()=>r(!1),onError:e=>E(e.message,{tone:`danger`})}),children:`Save`}),(0,Q.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{a(e.label),r(!1)},children:`Cancel`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`account-rename`,onClick:()=>r(!0),children:`Rename`}),(0,Q.jsx)(A,{type:`button`,variant:`outline`,size:`sm`,"data-action":`account-remove`,onClick:t,children:`Remove account`}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Renaming changes what Squawk calls this account, not its folder.`})]})})})}export{ye as GlobalAgentsSection};
|