@cortexkit/opencode-antigravity-auth 3.1.9 → 3.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/cli.js +502 -160
- package/dist/cli.js.map +3 -3
- package/dist/cli.meta.json +52 -42
- package/dist/index.js +1306 -656
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +102 -74
- package/dist/server.js +1437 -767
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/cli.d.ts +3 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +19 -6
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +32 -0
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
- package/dist/src/common-auth-embedded/claustrum/custody.js +176 -22
- package/dist/src/common-auth-embedded/claustrum/host.js +8 -0
- package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/dist/src/common-auth-embedded/claustrum/hub.js +10 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
- package/dist/src/common-auth-embedded/routing-accessor/index.js +5 -3
- package/dist/src/common-auth-embedded/setup/process-fence.js +20 -3
- package/dist/src/common-auth-embedded/source-output.json +41 -41
- package/dist/src/ga/rpc/protocol.d.ts +11 -5
- package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
- package/dist/src/ga/rpc/protocol.js +11 -3
- package/dist/src/ga/rpc/protocol.js.map +1 -1
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +30 -14
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/ga/tui/host-ga.d.ts +2 -1
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +9 -4
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/account-access.d.ts +1 -0
- package/dist/src/plugin/account-access.d.ts.map +1 -1
- package/dist/src/plugin/account-access.js +28 -0
- package/dist/src/plugin/account-access.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +21 -12
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/background-quota-refresh.d.ts +11 -24
- package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-quota-refresh.js +54 -60
- package/dist/src/plugin/background-quota-refresh.js.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js +6 -3
- package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
- package/dist/src/plugin/cache/signature-cache.d.ts +3 -0
- package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/src/plugin/cache/signature-cache.js +73 -46
- package/dist/src/plugin/cache/signature-cache.js.map +1 -1
- package/dist/src/plugin/cache.d.ts.map +1 -1
- package/dist/src/plugin/cache.js +17 -7
- package/dist/src/plugin/cache.js.map +1 -1
- package/dist/src/plugin/config/models.d.ts +1 -1
- package/dist/src/plugin/config/models.d.ts.map +1 -1
- package/dist/src/plugin/config/models.js +10 -5
- package/dist/src/plugin/config/models.js.map +1 -1
- package/dist/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
- package/dist/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
- package/dist/src/plugin/core/streaming/displayed-thinking.js +58 -0
- package/dist/src/plugin/core/streaming/displayed-thinking.js.map +1 -0
- package/dist/src/plugin/fetch/warmup.d.ts +9 -2
- package/dist/src/plugin/fetch/warmup.d.ts.map +1 -1
- package/dist/src/plugin/fetch/warmup.js +22 -14
- package/dist/src/plugin/fetch/warmup.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +10 -2
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +38 -10
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +51 -19
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/request.d.ts +12 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +34 -49
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +4 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +142 -24
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/runtime.d.ts +3 -4
- package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
- package/dist/src/plugin/shared/runtime.js +2 -2
- package/dist/src/plugin/shared/runtime.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +13 -7
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +24 -18
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
- package/dist/src/setup.d.ts +3 -0
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +18 -6
- package/dist/src/setup.js.map +1 -1
- package/dist/src/sidebar-state.d.ts +20 -7
- package/dist/src/sidebar-state.d.ts.map +1 -1
- package/dist/src/sidebar-state.js +57 -8
- package/dist/src/sidebar-state.js.map +1 -1
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +43 -23
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +9 -9
- package/dist/tui-ga-build-map.json +5 -5
- package/dist/types/src/cli.d.ts +3 -1
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
- package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
- package/dist/types/src/ga/rpc/protocol.d.ts +11 -5
- package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/account-access.d.ts +1 -0
- package/dist/types/src/plugin/account-access.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/background-quota-refresh.d.ts +11 -24
- package/dist/types/src/plugin/background-quota-refresh.d.ts.map +1 -1
- package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/types/src/plugin/cache/signature-cache.d.ts +3 -0
- package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/types/src/plugin/cache.d.ts.map +1 -1
- package/dist/types/src/plugin/config/models.d.ts +1 -1
- package/dist/types/src/plugin/config/models.d.ts.map +1 -1
- package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
- package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
- package/dist/types/src/plugin/fetch/warmup.d.ts +9 -2
- package/dist/types/src/plugin/fetch/warmup.d.ts.map +1 -1
- package/dist/types/src/plugin/quota.d.ts +10 -2
- package/dist/types/src/plugin/quota.d.ts.map +1 -1
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts +12 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +4 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/runtime.d.ts +3 -4
- package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +13 -7
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts +3 -0
- package/dist/types/src/setup.d.ts.map +1 -1
- package/dist/types/src/sidebar-state.d.ts +20 -7
- package/dist/types/src/sidebar-state.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
- package/src/common-auth-embedded/claustrum/consumer.js +32 -0
- package/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
- package/src/common-auth-embedded/claustrum/custody.js +176 -22
- package/src/common-auth-embedded/claustrum/host.js +8 -0
- package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/src/common-auth-embedded/claustrum/hub.js +10 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
- package/src/common-auth-embedded/routing-accessor/index.js +5 -3
- package/src/common-auth-embedded/setup/process-fence.js +20 -3
- package/src/common-auth-embedded/source-output.json +41 -41
- package/src/sidebar-state.ts +77 -8
- package/src/tui-compiled/sidebar-state.js +40 -1
- package/src/tui-compiled/tui.js +49 -24
- package/src/tui-ga-compiled/host-ga.js +11 -5
- package/src/tui-ga-raw/host-ga.tsx +17 -6
- package/src/tui-raw/sidebar-state.js +40 -1
- package/src/tui-raw/tui.tsx +40 -24
- package/src/tui.tsx +40 -24
package/src/sidebar-state.ts
CHANGED
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
* 100 entries within 24h.
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
|
-
import { chmodSync, mkdirSync, readFileSync } from 'node:fs'
|
|
42
|
+
import { chmodSync, mkdirSync, readFileSync, statSync } from 'node:fs'
|
|
43
|
+
import { readFile, stat } from 'node:fs/promises'
|
|
43
44
|
import { homedir } from 'node:os'
|
|
44
45
|
import { dirname, join } from 'node:path'
|
|
45
46
|
// Subpath imports (not the barrel): this file ships into the TUI's
|
|
@@ -230,13 +231,7 @@ export function getSidebarStateFile(): string {
|
|
|
230
231
|
|
|
231
232
|
/**
|
|
232
233
|
* Read and normalize the sidebar state file. Returns the default state when
|
|
233
|
-
* the file is missing, unreadable, malformed, or schema-incompatible
|
|
234
|
-
* must never throw out of `readSidebarState()`, the panel just shows
|
|
235
|
-
* "Awaiting Antigravity state" and the next poll retries.
|
|
236
|
-
*
|
|
237
|
-
* The read is sync on purpose: the TUI polls on a 2-second timer and the file
|
|
238
|
-
* is tiny (a handful of accounts); an async read here would just add race
|
|
239
|
-
* surface area against Solid's reactive render cycle.
|
|
234
|
+
* the file is missing, unreadable, malformed, or schema-incompatible.
|
|
240
235
|
*/
|
|
241
236
|
export function readSidebarState(
|
|
242
237
|
path: string = getSidebarStateFile(),
|
|
@@ -247,6 +242,80 @@ export function readSidebarState(
|
|
|
247
242
|
} catch {
|
|
248
243
|
return { ...DEFAULT_SIDEBAR_STATE }
|
|
249
244
|
}
|
|
245
|
+
return parseSidebarState(raw)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Identifies one version of the state file; see `fileSignature`. */
|
|
249
|
+
export interface SidebarStateBaseline {
|
|
250
|
+
path: string
|
|
251
|
+
signature: string | null
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Atomic replacement can leave size and mtime unchanged; inode identifies
|
|
255
|
+
// the new file, and ctime invalidates the read on permission changes.
|
|
256
|
+
function fileSignature(info: {
|
|
257
|
+
dev: bigint
|
|
258
|
+
ino: bigint
|
|
259
|
+
size: bigint
|
|
260
|
+
mtimeNs: bigint
|
|
261
|
+
ctimeNs: bigint
|
|
262
|
+
}): string {
|
|
263
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Read the state file synchronously with the signature of the version read.
|
|
268
|
+
* The sidebar uses it once at mount, so the very first frame already has the
|
|
269
|
+
* quota bars; the later polls go through `createSidebarStateReader`.
|
|
270
|
+
*/
|
|
271
|
+
export function readSidebarStateWithBaseline(
|
|
272
|
+
path: string = getSidebarStateFile(),
|
|
273
|
+
): { state: SidebarStateV1; baseline: SidebarStateBaseline } {
|
|
274
|
+
try {
|
|
275
|
+
const signature = fileSignature(statSync(path, { bigint: true }))
|
|
276
|
+
const raw = readFileSync(path, 'utf-8')
|
|
277
|
+
return { state: parseSidebarState(raw), baseline: { path, signature } }
|
|
278
|
+
} catch {
|
|
279
|
+
return {
|
|
280
|
+
state: { ...DEFAULT_SIDEBAR_STATE },
|
|
281
|
+
baseline: { path, signature: null },
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Create a reader for one polling consumer. Polls must not overlap. A reader
|
|
288
|
+
* started from a `baseline` returns nothing until the file changes from it.
|
|
289
|
+
*/
|
|
290
|
+
export function createSidebarStateReader(
|
|
291
|
+
baseline?: SidebarStateBaseline,
|
|
292
|
+
): (path?: string) => Promise<SidebarStateV1 | undefined> {
|
|
293
|
+
let previousPath: string | undefined = baseline?.path
|
|
294
|
+
let previousSignature: string | null = baseline?.signature ?? null
|
|
295
|
+
|
|
296
|
+
return async (path = getSidebarStateFile()) => {
|
|
297
|
+
let raw: string
|
|
298
|
+
let signature: string
|
|
299
|
+
try {
|
|
300
|
+
signature = fileSignature(await stat(path, { bigint: true }))
|
|
301
|
+
if (path === previousPath && signature === previousSignature) return
|
|
302
|
+
raw = await readFile(path, 'utf-8')
|
|
303
|
+
} catch {
|
|
304
|
+
const alreadyUnavailable =
|
|
305
|
+
path === previousPath && previousSignature === null
|
|
306
|
+
previousPath = path
|
|
307
|
+
previousSignature = null
|
|
308
|
+
return alreadyUnavailable ? undefined : { ...DEFAULT_SIDEBAR_STATE }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const loaded = parseSidebarState(raw)
|
|
312
|
+
previousPath = path
|
|
313
|
+
previousSignature = signature
|
|
314
|
+
return loaded
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function parseSidebarState(raw: string): SidebarStateV1 {
|
|
250
319
|
let parsed: unknown
|
|
251
320
|
try {
|
|
252
321
|
parsed = JSON.parse(raw)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { chmodSync, mkdirSync, readFileSync } from "node:fs";
|
|
1
|
+
import { chmodSync, mkdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { writeJsonAtomic } from "@cortexkit/antigravity-auth-core/atomic-write";
|
|
@@ -44,6 +45,44 @@ export function readSidebarState(path = getSidebarStateFile()) {
|
|
|
44
45
|
} catch {
|
|
45
46
|
return { ...DEFAULT_SIDEBAR_STATE };
|
|
46
47
|
}
|
|
48
|
+
return parseSidebarState(raw);
|
|
49
|
+
}
|
|
50
|
+
function fileSignature(info) {
|
|
51
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
52
|
+
}
|
|
53
|
+
export function readSidebarStateWithBaseline(path = getSidebarStateFile()) {
|
|
54
|
+
try {
|
|
55
|
+
const signature = fileSignature(statSync(path, { bigint: !0 })), raw = readFileSync(path, "utf-8");
|
|
56
|
+
return { state: parseSidebarState(raw), baseline: { path, signature } };
|
|
57
|
+
} catch {
|
|
58
|
+
return {
|
|
59
|
+
state: { ...DEFAULT_SIDEBAR_STATE },
|
|
60
|
+
baseline: { path, signature: null }
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function createSidebarStateReader(baseline) {
|
|
65
|
+
let previousPath = baseline?.path, previousSignature = baseline?.signature ?? null;
|
|
66
|
+
return async (path = getSidebarStateFile()) => {
|
|
67
|
+
let raw, signature;
|
|
68
|
+
try {
|
|
69
|
+
signature = fileSignature(await stat(path, { bigint: !0 }));
|
|
70
|
+
if (path === previousPath && signature === previousSignature)
|
|
71
|
+
return;
|
|
72
|
+
raw = await readFile(path, "utf-8");
|
|
73
|
+
} catch {
|
|
74
|
+
const alreadyUnavailable = path === previousPath && previousSignature === null;
|
|
75
|
+
previousPath = path;
|
|
76
|
+
previousSignature = null;
|
|
77
|
+
return alreadyUnavailable ? void 0 : { ...DEFAULT_SIDEBAR_STATE };
|
|
78
|
+
}
|
|
79
|
+
const loaded = parseSidebarState(raw);
|
|
80
|
+
previousPath = path;
|
|
81
|
+
previousSignature = signature;
|
|
82
|
+
return loaded;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function parseSidebarState(raw) {
|
|
47
86
|
let parsed;
|
|
48
87
|
try {
|
|
49
88
|
parsed = JSON.parse(raw);
|
package/src/tui-compiled/tui.js
CHANGED
|
@@ -48,7 +48,7 @@ import { fileURLToPath } from "node:url";
|
|
|
48
48
|
import { createSlot } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
49
49
|
import { createSignal, onCleanup, onMount } from "opentui:runtime-module:solid-js";
|
|
50
50
|
import { getRpcDir } from "./rpc/rpc-dir.js";
|
|
51
|
-
import {
|
|
51
|
+
import { createSidebarStateReader, readSidebarStateWithBaseline } from "./sidebar-state.js";
|
|
52
52
|
import { createTuiFileLogger } from "./tui/file-logger.js";
|
|
53
53
|
import { createV1MenuTransport, dispatchV1Notification } from "./tui/host-v1.js";
|
|
54
54
|
import { AntigravitySidebar } from "./tui/sidebar-frame.js";
|
|
@@ -276,7 +276,8 @@ function formatError(value) {
|
|
|
276
276
|
|
|
277
277
|
export function SidebarPanel(props) {
|
|
278
278
|
const logger = resolveLogger(props.logger);
|
|
279
|
-
const
|
|
279
|
+
const clock = props.now ?? Date.now;
|
|
280
|
+
const [now, setNow] = createSignal(clock());
|
|
280
281
|
const pollMs = props.pollIntervalMs ?? POLL_INTERVAL_MS;
|
|
281
282
|
const controller = props.controller ?? getSidebarController();
|
|
282
283
|
const collapsed = controller.collapsed;
|
|
@@ -287,32 +288,56 @@ export function SidebarPanel(props) {
|
|
|
287
288
|
const theme = () => props.theme?.() ?? FALLBACK_THEME;
|
|
288
289
|
const [state, setState] = createSignal({
|
|
289
290
|
loaded: EMPTY_STATE,
|
|
290
|
-
lastReadAt: 0,
|
|
291
291
|
lastError: null
|
|
292
292
|
});
|
|
293
|
-
const refresh = () => {
|
|
294
|
-
try {
|
|
295
|
-
const loaded = readSidebarState(props.stateFile);
|
|
296
|
-
setState({
|
|
297
|
-
loaded,
|
|
298
|
-
lastReadAt: now(),
|
|
299
|
-
lastError: null
|
|
300
|
-
});
|
|
301
|
-
} catch (error) {
|
|
302
|
-
logger.warn('sidebar-poll-failed', {
|
|
303
|
-
error: formatError(error)
|
|
304
|
-
});
|
|
305
|
-
setState(prev => ({
|
|
306
|
-
...prev,
|
|
307
|
-
lastReadAt: now(),
|
|
308
|
-
lastError: formatError(error)
|
|
309
|
-
}));
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
293
|
onMount(() => {
|
|
313
|
-
|
|
294
|
+
// Read synchronously once so the first frame already draws the quota bars;
|
|
295
|
+
// the polls below reread only when the file has changed since.
|
|
296
|
+
const first = readSidebarStateWithBaseline(props.stateFile);
|
|
297
|
+
setState({
|
|
298
|
+
loaded: first.state,
|
|
299
|
+
lastError: null
|
|
300
|
+
});
|
|
301
|
+
const readChanged = createSidebarStateReader(first.baseline);
|
|
302
|
+
let mounted = true;
|
|
303
|
+
let reading = false;
|
|
304
|
+
const refresh = async () => {
|
|
305
|
+
if (!mounted) return;
|
|
306
|
+
setNow(clock());
|
|
307
|
+
if (reading) return;
|
|
308
|
+
reading = true;
|
|
309
|
+
try {
|
|
310
|
+
const loaded = await readChanged(props.stateFile);
|
|
311
|
+
if (!mounted) return;
|
|
312
|
+
if (loaded) setState({
|
|
313
|
+
loaded,
|
|
314
|
+
lastError: null
|
|
315
|
+
});else if (state().lastError !== null) {
|
|
316
|
+
setState(prev => ({
|
|
317
|
+
...prev,
|
|
318
|
+
lastError: null
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
} catch (error) {
|
|
322
|
+
if (!mounted) return;
|
|
323
|
+
const message = formatError(error);
|
|
324
|
+
logger.warn('sidebar-poll-failed', {
|
|
325
|
+
error: message
|
|
326
|
+
});
|
|
327
|
+
setState(prev => ({
|
|
328
|
+
...prev,
|
|
329
|
+
lastError: message
|
|
330
|
+
}));
|
|
331
|
+
} finally {
|
|
332
|
+
reading = false;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
void refresh();
|
|
314
336
|
const interval = setInterval(refresh, pollMs);
|
|
315
|
-
onCleanup(() =>
|
|
337
|
+
onCleanup(() => {
|
|
338
|
+
mounted = false;
|
|
339
|
+
clearInterval(interval);
|
|
340
|
+
});
|
|
316
341
|
});
|
|
317
342
|
const lastError = () => state().lastError ?? state().loaded.lastError;
|
|
318
343
|
const currentRoute = () => {
|
|
@@ -358,14 +358,15 @@ export function parseGaStateAnswer(raw) {
|
|
|
358
358
|
issues: ['output.kind: unknown answer']
|
|
359
359
|
};
|
|
360
360
|
}
|
|
361
|
-
keys(output, ['version', 'kind', 'generation', 'scope', 'reset', 'cursor', 'dropped', 'more', 'notifications', 'readSeq', 'accountsStatus', 'accounts', 'route', 'status', 'settings'], ['vaultHostStatus'], 'output', issues);
|
|
361
|
+
keys(output, ['version', 'kind', 'generation', 'scope', 'reset', 'cursor', 'dropped', 'more', 'notifications', 'readSeq', 'accountsStatus', 'accounts', 'route', 'status', 'settings'], ['vaultHostStatus', 'queueID'], 'output', issues);
|
|
362
362
|
if (!isCursor(output.readSeq)) issues.push('output.readSeq: expected a count');
|
|
363
363
|
if (Object.hasOwn(output, 'vaultHostStatus') && output.vaultHostStatus !== 'Served by Thalamus') issues.push('output.vaultHostStatus: expected the hosted vault status');
|
|
364
364
|
checkAccountsStatus(output.accountsStatus, 'output.accountsStatus', issues);
|
|
365
365
|
checkSettings(output.settings, 'output.settings', issues);
|
|
366
366
|
checkGeneration(output.generation, 'output.generation', issues);
|
|
367
|
+
if (Object.hasOwn(output, 'queueID')) checkGeneration(output.queueID, 'output.queueID', issues);
|
|
367
368
|
checkScope(output.scope, 'output.scope', issues);
|
|
368
|
-
if (output.reset !== null && output.reset !== 'initial' && output.reset !== 'generation-changed' && output.reset !== 'cursor-ahead') {
|
|
369
|
+
if (output.reset !== null && output.reset !== 'initial' && output.reset !== 'generation-changed' && output.reset !== 'queue-changed' && output.reset !== 'cursor-ahead') {
|
|
369
370
|
issues.push('output.reset: unknown reset');
|
|
370
371
|
}
|
|
371
372
|
if (!isCursor(output.cursor)) issues.push('output.cursor: expected a cursor');
|
|
@@ -472,11 +473,13 @@ export function createGaLocationClient(options) {
|
|
|
472
473
|
if (isDisposed) throw new GaClientDisposedError();
|
|
473
474
|
const sentEpoch = epoch;
|
|
474
475
|
const key = scopeKey(scope);
|
|
476
|
+
const previous = cursors.get(key);
|
|
475
477
|
const raw = await call('state', {
|
|
476
478
|
version: GA_RPC_VERSION,
|
|
477
479
|
generation,
|
|
478
480
|
scope,
|
|
479
|
-
cursor:
|
|
481
|
+
cursor: previous?.cursor ?? 0,
|
|
482
|
+
queueID: previous?.queueID ?? null
|
|
480
483
|
});
|
|
481
484
|
if (isDisposed || sentEpoch !== epoch) return {
|
|
482
485
|
kind: 'dropped'
|
|
@@ -504,7 +507,10 @@ export function createGaLocationClient(options) {
|
|
|
504
507
|
if (output.generation !== generation) {
|
|
505
508
|
rebind(output.generation);
|
|
506
509
|
}
|
|
507
|
-
cursors.set(key,
|
|
510
|
+
cursors.set(key, {
|
|
511
|
+
cursor: output.cursor,
|
|
512
|
+
queueID: output.queueID ?? null
|
|
513
|
+
});
|
|
508
514
|
return {
|
|
509
515
|
kind: 'snapshot',
|
|
510
516
|
snapshot: output
|
|
@@ -512,7 +518,7 @@ export function createGaLocationClient(options) {
|
|
|
512
518
|
};
|
|
513
519
|
return {
|
|
514
520
|
generation: () => generation,
|
|
515
|
-
cursor: scope => cursors.get(scopeKey(scope)) ?? 0,
|
|
521
|
+
cursor: scope => cursors.get(scopeKey(scope))?.cursor ?? 0,
|
|
516
522
|
disposed: () => isDisposed,
|
|
517
523
|
dispose() {
|
|
518
524
|
isDisposed = true;
|
|
@@ -235,8 +235,14 @@ export interface GaSnapshot {
|
|
|
235
235
|
readonly kind: 'snapshot'
|
|
236
236
|
readonly generation: string
|
|
237
237
|
readonly scope: GaScope
|
|
238
|
-
readonly reset:
|
|
238
|
+
readonly reset:
|
|
239
|
+
| 'initial'
|
|
240
|
+
| 'generation-changed'
|
|
241
|
+
| 'queue-changed'
|
|
242
|
+
| 'cursor-ahead'
|
|
243
|
+
| null
|
|
239
244
|
readonly cursor: number
|
|
245
|
+
readonly queueID?: string
|
|
240
246
|
readonly dropped: number
|
|
241
247
|
readonly more: boolean
|
|
242
248
|
readonly notifications: readonly GaNotification[]
|
|
@@ -684,7 +690,7 @@ export function parseGaStateAnswer(
|
|
|
684
690
|
'status',
|
|
685
691
|
'settings',
|
|
686
692
|
],
|
|
687
|
-
['vaultHostStatus'],
|
|
693
|
+
['vaultHostStatus', 'queueID'],
|
|
688
694
|
'output',
|
|
689
695
|
issues,
|
|
690
696
|
)
|
|
@@ -697,11 +703,14 @@ export function parseGaStateAnswer(
|
|
|
697
703
|
checkAccountsStatus(output.accountsStatus, 'output.accountsStatus', issues)
|
|
698
704
|
checkSettings(output.settings, 'output.settings', issues)
|
|
699
705
|
checkGeneration(output.generation, 'output.generation', issues)
|
|
706
|
+
if (Object.hasOwn(output, 'queueID'))
|
|
707
|
+
checkGeneration(output.queueID, 'output.queueID', issues)
|
|
700
708
|
checkScope(output.scope, 'output.scope', issues)
|
|
701
709
|
if (
|
|
702
710
|
output.reset !== null &&
|
|
703
711
|
output.reset !== 'initial' &&
|
|
704
712
|
output.reset !== 'generation-changed' &&
|
|
713
|
+
output.reset !== 'queue-changed' &&
|
|
705
714
|
output.reset !== 'cursor-ahead'
|
|
706
715
|
) {
|
|
707
716
|
issues.push('output.reset: unknown reset')
|
|
@@ -813,7 +822,7 @@ export function createGaLocationClient(options: {
|
|
|
813
822
|
readonly logger?: GaLogger
|
|
814
823
|
}): GaLocationClient {
|
|
815
824
|
let generation: string | null = null
|
|
816
|
-
const cursors = new Map<string, number>()
|
|
825
|
+
const cursors = new Map<string, { cursor: number; queueID: string | null }>()
|
|
817
826
|
let isDisposed = false
|
|
818
827
|
// Bumped on every rebind and on disposal. A request remembers the epoch
|
|
819
828
|
// it was sent in; an answer from an older epoch is dropped unread.
|
|
@@ -842,11 +851,13 @@ export function createGaLocationClient(options: {
|
|
|
842
851
|
if (isDisposed) throw new GaClientDisposedError()
|
|
843
852
|
const sentEpoch = epoch
|
|
844
853
|
const key = scopeKey(scope)
|
|
854
|
+
const previous = cursors.get(key)
|
|
845
855
|
const raw = await call('state', {
|
|
846
856
|
version: GA_RPC_VERSION,
|
|
847
857
|
generation,
|
|
848
858
|
scope,
|
|
849
|
-
cursor:
|
|
859
|
+
cursor: previous?.cursor ?? 0,
|
|
860
|
+
queueID: previous?.queueID ?? null,
|
|
850
861
|
})
|
|
851
862
|
if (isDisposed || sentEpoch !== epoch) return { kind: 'dropped' }
|
|
852
863
|
const parsed = parseGaStateAnswer(raw)
|
|
@@ -868,13 +879,13 @@ export function createGaLocationClient(options: {
|
|
|
868
879
|
if (output.generation !== generation) {
|
|
869
880
|
rebind(output.generation)
|
|
870
881
|
}
|
|
871
|
-
cursors.set(key, output.cursor)
|
|
882
|
+
cursors.set(key, { cursor: output.cursor, queueID: output.queueID ?? null })
|
|
872
883
|
return { kind: 'snapshot', snapshot: output }
|
|
873
884
|
}
|
|
874
885
|
|
|
875
886
|
return {
|
|
876
887
|
generation: () => generation,
|
|
877
|
-
cursor: (scope) => cursors.get(scopeKey(scope)) ?? 0,
|
|
888
|
+
cursor: (scope) => cursors.get(scopeKey(scope))?.cursor ?? 0,
|
|
878
889
|
disposed: () => isDisposed,
|
|
879
890
|
dispose() {
|
|
880
891
|
isDisposed = true
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { chmodSync, mkdirSync, readFileSync } from "node:fs";
|
|
1
|
+
import { chmodSync, mkdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { writeJsonAtomic } from "@cortexkit/antigravity-auth-core/atomic-write";
|
|
@@ -44,6 +45,44 @@ export function readSidebarState(path = getSidebarStateFile()) {
|
|
|
44
45
|
} catch {
|
|
45
46
|
return { ...DEFAULT_SIDEBAR_STATE };
|
|
46
47
|
}
|
|
48
|
+
return parseSidebarState(raw);
|
|
49
|
+
}
|
|
50
|
+
function fileSignature(info) {
|
|
51
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
52
|
+
}
|
|
53
|
+
export function readSidebarStateWithBaseline(path = getSidebarStateFile()) {
|
|
54
|
+
try {
|
|
55
|
+
const signature = fileSignature(statSync(path, { bigint: !0 })), raw = readFileSync(path, "utf-8");
|
|
56
|
+
return { state: parseSidebarState(raw), baseline: { path, signature } };
|
|
57
|
+
} catch {
|
|
58
|
+
return {
|
|
59
|
+
state: { ...DEFAULT_SIDEBAR_STATE },
|
|
60
|
+
baseline: { path, signature: null }
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function createSidebarStateReader(baseline) {
|
|
65
|
+
let previousPath = baseline?.path, previousSignature = baseline?.signature ?? null;
|
|
66
|
+
return async (path = getSidebarStateFile()) => {
|
|
67
|
+
let raw, signature;
|
|
68
|
+
try {
|
|
69
|
+
signature = fileSignature(await stat(path, { bigint: !0 }));
|
|
70
|
+
if (path === previousPath && signature === previousSignature)
|
|
71
|
+
return;
|
|
72
|
+
raw = await readFile(path, "utf-8");
|
|
73
|
+
} catch {
|
|
74
|
+
const alreadyUnavailable = path === previousPath && previousSignature === null;
|
|
75
|
+
previousPath = path;
|
|
76
|
+
previousSignature = null;
|
|
77
|
+
return alreadyUnavailable ? void 0 : { ...DEFAULT_SIDEBAR_STATE };
|
|
78
|
+
}
|
|
79
|
+
const loaded = parseSidebarState(raw);
|
|
80
|
+
previousPath = path;
|
|
81
|
+
previousSignature = signature;
|
|
82
|
+
return loaded;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function parseSidebarState(raw) {
|
|
47
86
|
let parsed;
|
|
48
87
|
try {
|
|
49
88
|
parsed = JSON.parse(raw);
|
package/src/tui-raw/tui.tsx
CHANGED
|
@@ -53,7 +53,11 @@ import { createSlot } from "@opentui/solid"
|
|
|
53
53
|
import { createSignal, type JSX, onCleanup, onMount } from "solid-js"
|
|
54
54
|
|
|
55
55
|
import { getRpcDir } from "./rpc/rpc-dir.js"
|
|
56
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
createSidebarStateReader,
|
|
58
|
+
readSidebarStateWithBaseline,
|
|
59
|
+
type SidebarStateV1,
|
|
60
|
+
} from "./sidebar-state.js"
|
|
57
61
|
import { createTuiFileLogger, type TuiLogger } from "./tui/file-logger.js"
|
|
58
62
|
import {
|
|
59
63
|
createV1MenuTransport,
|
|
@@ -219,7 +223,6 @@ export interface SidebarController {
|
|
|
219
223
|
|
|
220
224
|
interface InternalState {
|
|
221
225
|
loaded: SidebarStateV1
|
|
222
|
-
lastReadAt: number
|
|
223
226
|
lastError: string | null
|
|
224
227
|
}
|
|
225
228
|
|
|
@@ -347,7 +350,8 @@ function formatError(value: unknown): string {
|
|
|
347
350
|
|
|
348
351
|
export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
349
352
|
const logger = resolveLogger(props.logger)
|
|
350
|
-
const
|
|
353
|
+
const clock = props.now ?? Date.now
|
|
354
|
+
const [now, setNow] = createSignal(clock())
|
|
351
355
|
const pollMs = props.pollIntervalMs ?? POLL_INTERVAL_MS
|
|
352
356
|
const controller = props.controller ?? getSidebarController()
|
|
353
357
|
const collapsed = controller.collapsed
|
|
@@ -359,32 +363,44 @@ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
|
359
363
|
|
|
360
364
|
const [state, setState] = createSignal<InternalState>({
|
|
361
365
|
loaded: EMPTY_STATE,
|
|
362
|
-
lastReadAt: 0,
|
|
363
366
|
lastError: null,
|
|
364
367
|
})
|
|
365
368
|
|
|
366
|
-
const refresh = (): void => {
|
|
367
|
-
try {
|
|
368
|
-
const loaded = readSidebarState(props.stateFile)
|
|
369
|
-
setState({
|
|
370
|
-
loaded,
|
|
371
|
-
lastReadAt: now(),
|
|
372
|
-
lastError: null,
|
|
373
|
-
})
|
|
374
|
-
} catch (error) {
|
|
375
|
-
logger.warn('sidebar-poll-failed', { error: formatError(error) })
|
|
376
|
-
setState((prev) => ({
|
|
377
|
-
...prev,
|
|
378
|
-
lastReadAt: now(),
|
|
379
|
-
lastError: formatError(error),
|
|
380
|
-
}))
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
369
|
onMount(() => {
|
|
385
|
-
|
|
370
|
+
// Read synchronously once so the first frame already draws the quota bars;
|
|
371
|
+
// the polls below reread only when the file has changed since.
|
|
372
|
+
const first = readSidebarStateWithBaseline(props.stateFile)
|
|
373
|
+
setState({ loaded: first.state, lastError: null })
|
|
374
|
+
const readChanged = createSidebarStateReader(first.baseline)
|
|
375
|
+
let mounted = true
|
|
376
|
+
let reading = false
|
|
377
|
+
const refresh = async (): Promise<void> => {
|
|
378
|
+
if (!mounted) return
|
|
379
|
+
setNow(clock())
|
|
380
|
+
if (reading) return
|
|
381
|
+
reading = true
|
|
382
|
+
try {
|
|
383
|
+
const loaded = await readChanged(props.stateFile)
|
|
384
|
+
if (!mounted) return
|
|
385
|
+
if (loaded) setState({ loaded, lastError: null })
|
|
386
|
+
else if (state().lastError !== null) {
|
|
387
|
+
setState((prev) => ({ ...prev, lastError: null }))
|
|
388
|
+
}
|
|
389
|
+
} catch (error) {
|
|
390
|
+
if (!mounted) return
|
|
391
|
+
const message = formatError(error)
|
|
392
|
+
logger.warn('sidebar-poll-failed', { error: message })
|
|
393
|
+
setState((prev) => ({ ...prev, lastError: message }))
|
|
394
|
+
} finally {
|
|
395
|
+
reading = false
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
void refresh()
|
|
386
399
|
const interval = setInterval(refresh, pollMs)
|
|
387
|
-
onCleanup(() =>
|
|
400
|
+
onCleanup(() => {
|
|
401
|
+
mounted = false
|
|
402
|
+
clearInterval(interval)
|
|
403
|
+
})
|
|
388
404
|
})
|
|
389
405
|
|
|
390
406
|
const lastError = () => state().lastError ?? state().loaded.lastError
|
package/src/tui.tsx
CHANGED
|
@@ -53,7 +53,11 @@ import { createSlot } from '@opentui/solid'
|
|
|
53
53
|
import { createSignal, type JSX, onCleanup, onMount } from 'solid-js'
|
|
54
54
|
|
|
55
55
|
import { getRpcDir } from './rpc/rpc-dir'
|
|
56
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
createSidebarStateReader,
|
|
58
|
+
readSidebarStateWithBaseline,
|
|
59
|
+
type SidebarStateV1,
|
|
60
|
+
} from './sidebar-state'
|
|
57
61
|
import { createTuiFileLogger, type TuiLogger } from './tui/file-logger'
|
|
58
62
|
import {
|
|
59
63
|
createV1MenuTransport,
|
|
@@ -219,7 +223,6 @@ export interface SidebarController {
|
|
|
219
223
|
|
|
220
224
|
interface InternalState {
|
|
221
225
|
loaded: SidebarStateV1
|
|
222
|
-
lastReadAt: number
|
|
223
226
|
lastError: string | null
|
|
224
227
|
}
|
|
225
228
|
|
|
@@ -347,7 +350,8 @@ function formatError(value: unknown): string {
|
|
|
347
350
|
|
|
348
351
|
export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
349
352
|
const logger = resolveLogger(props.logger)
|
|
350
|
-
const
|
|
353
|
+
const clock = props.now ?? Date.now
|
|
354
|
+
const [now, setNow] = createSignal(clock())
|
|
351
355
|
const pollMs = props.pollIntervalMs ?? POLL_INTERVAL_MS
|
|
352
356
|
const controller = props.controller ?? getSidebarController()
|
|
353
357
|
const collapsed = controller.collapsed
|
|
@@ -359,32 +363,44 @@ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
|
359
363
|
|
|
360
364
|
const [state, setState] = createSignal<InternalState>({
|
|
361
365
|
loaded: EMPTY_STATE,
|
|
362
|
-
lastReadAt: 0,
|
|
363
366
|
lastError: null,
|
|
364
367
|
})
|
|
365
368
|
|
|
366
|
-
const refresh = (): void => {
|
|
367
|
-
try {
|
|
368
|
-
const loaded = readSidebarState(props.stateFile)
|
|
369
|
-
setState({
|
|
370
|
-
loaded,
|
|
371
|
-
lastReadAt: now(),
|
|
372
|
-
lastError: null,
|
|
373
|
-
})
|
|
374
|
-
} catch (error) {
|
|
375
|
-
logger.warn('sidebar-poll-failed', { error: formatError(error) })
|
|
376
|
-
setState((prev) => ({
|
|
377
|
-
...prev,
|
|
378
|
-
lastReadAt: now(),
|
|
379
|
-
lastError: formatError(error),
|
|
380
|
-
}))
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
369
|
onMount(() => {
|
|
385
|
-
|
|
370
|
+
// Read synchronously once so the first frame already draws the quota bars;
|
|
371
|
+
// the polls below reread only when the file has changed since.
|
|
372
|
+
const first = readSidebarStateWithBaseline(props.stateFile)
|
|
373
|
+
setState({ loaded: first.state, lastError: null })
|
|
374
|
+
const readChanged = createSidebarStateReader(first.baseline)
|
|
375
|
+
let mounted = true
|
|
376
|
+
let reading = false
|
|
377
|
+
const refresh = async (): Promise<void> => {
|
|
378
|
+
if (!mounted) return
|
|
379
|
+
setNow(clock())
|
|
380
|
+
if (reading) return
|
|
381
|
+
reading = true
|
|
382
|
+
try {
|
|
383
|
+
const loaded = await readChanged(props.stateFile)
|
|
384
|
+
if (!mounted) return
|
|
385
|
+
if (loaded) setState({ loaded, lastError: null })
|
|
386
|
+
else if (state().lastError !== null) {
|
|
387
|
+
setState((prev) => ({ ...prev, lastError: null }))
|
|
388
|
+
}
|
|
389
|
+
} catch (error) {
|
|
390
|
+
if (!mounted) return
|
|
391
|
+
const message = formatError(error)
|
|
392
|
+
logger.warn('sidebar-poll-failed', { error: message })
|
|
393
|
+
setState((prev) => ({ ...prev, lastError: message }))
|
|
394
|
+
} finally {
|
|
395
|
+
reading = false
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
void refresh()
|
|
386
399
|
const interval = setInterval(refresh, pollMs)
|
|
387
|
-
onCleanup(() =>
|
|
400
|
+
onCleanup(() => {
|
|
401
|
+
mounted = false
|
|
402
|
+
clearInterval(interval)
|
|
403
|
+
})
|
|
388
404
|
})
|
|
389
405
|
|
|
390
406
|
const lastError = () => state().lastError ?? state().loaded.lastError
|