@cortexkit/common-auth 0.42.0 → 0.44.0
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/cachekeep/manager.d.ts +12 -0
- package/dist/cachekeep/manager.js +28 -0
- package/dist/claustrum/availability.d.ts +7 -1
- package/dist/claustrum/availability.js +9 -1
- package/dist/claustrum/custody.d.ts +11 -2
- package/dist/claustrum/custody.js +89 -31
- package/dist/claustrum/enrollment.d.ts +29 -4
- package/dist/claustrum/enrollment.js +110 -2
- package/dist/claustrum/host.js +11 -7
- package/dist/claustrum/index.d.ts +1 -1
- package/dist/claustrum/index.js +1 -1
- package/dist/fs/lock-record.d.ts +19 -0
- package/dist/fs/lock-record.js +55 -0
- package/dist/fs/refresh-file-lock.js +148 -92
- package/dist/fs/with-lock.js +19 -13
- package/dist/quota-sidebar/index.d.ts +2 -36
- package/dist/quota-sidebar/index.jsx +28 -344
- package/dist/routing-accessor/cache-policy.d.ts +3 -0
- package/dist/routing-accessor/cache-policy.js +11 -0
- package/dist/routing-accessor/index.d.ts +48 -5
- package/dist/routing-accessor/index.js +136 -5
- package/dist/setup/command-error.d.ts +1 -1
- package/dist/setup/command-error.js +3 -2
- package/dist/setup/command.js +18 -5
- package/dist/setup/enroll.d.ts +2 -2
- package/dist/setup/enroll.js +14 -3
- package/dist/setup/enrollment-access.d.ts +7 -0
- package/dist/setup/enrollment-access.js +77 -0
- package/dist/setup/index.d.ts +1 -1
- package/dist/setup/types.d.ts +13 -1
- package/dist/tui-build/build-tui.js +26 -23
- package/package.json +8 -3
- package/src/quota-sidebar/index.tsx +49 -607
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { redact } from '../logger/redact.js';
|
|
2
2
|
import { STDERR_TAIL_MAX_BYTES } from './command-runner.js';
|
|
3
|
+
import { enrollmentAccessLines } from './enrollment-access.js';
|
|
3
4
|
const PI_INSTALL_ERROR_MESSAGE = 'Pi install failed; run pi install after checking your npm connection.';
|
|
4
5
|
function utf8Tail(value) {
|
|
5
6
|
const bytes = Buffer.from(value, 'utf8');
|
|
@@ -47,8 +48,8 @@ const OUTCOME_TEXT = {
|
|
|
47
48
|
unknown: 'unknown, check with ck auth status',
|
|
48
49
|
};
|
|
49
50
|
/** The line setup prints for one host's outcome, e.g. `Pi: not connected`. */
|
|
50
|
-
export function setupEnrollmentLine({ host, outcome, }) {
|
|
51
|
-
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
|
|
51
|
+
export function setupEnrollmentLine({ host, outcome, access, }) {
|
|
52
|
+
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}${access ? ` — ${enrollmentAccessLines(access).join('\n')}` : ''}`;
|
|
52
53
|
}
|
|
53
54
|
// Outcomes recorded against the value a failed `runSetup` threw. A WeakMap
|
|
54
55
|
// keeps the thrown value itself untouched: setup never reads, rewrites or
|
package/dist/setup/command.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { select } from '../auth-menu/select.js';
|
|
2
2
|
import { isInteractive, printLine, processTerminal, } from '../auth-menu/terminal.js';
|
|
3
|
-
import { hostEnrollmentPaths, vaultAuthority } from '../claustrum/enrollment.js';
|
|
3
|
+
import { hostEnrollmentPaths, readClaustrumEnrollmentStatus, validEnrollmentRequestedGrants, vaultAuthority, } from '../claustrum/enrollment.js';
|
|
4
4
|
import { hasVaultHost, VAULT_HOST_CONNECT_REFUSAL } from '../claustrum/host.js';
|
|
5
5
|
import { recordSetupEnrollment, setupEnrollmentLine } from './command-error.js';
|
|
6
6
|
import { defaultCommandRunner } from './command-runner.js';
|
|
7
7
|
import { detectHosts } from './detect.js';
|
|
8
8
|
import { connectSetupHost, HostNotEnrolledError } from './enroll.js';
|
|
9
|
+
import { confirmEnrollmentAccess } from './enrollment-access.js';
|
|
9
10
|
import { parseSetupFlags, UNAVAILABLE_HOST_MESSAGE } from './flags.js';
|
|
10
11
|
import { setupPaths } from './paths.js';
|
|
11
12
|
import { assertHostsStopped, createProcessFence, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
|
|
@@ -22,6 +23,9 @@ function validatePlugin(plugin) {
|
|
|
22
23
|
for (const host of Object.values(plugin.vault.hosts)) {
|
|
23
24
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(host.name))
|
|
24
25
|
throw new Error('Setup requires lowercase vault names containing only letters, digits and dashes.');
|
|
26
|
+
if (host.requestedGrants !== undefined &&
|
|
27
|
+
!validEnrollmentRequestedGrants(host.requestedGrants))
|
|
28
|
+
throw new Error('invalid Claustrum enrollment requested grants');
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
@@ -31,10 +35,11 @@ function validatePlugin(plugin) {
|
|
|
31
35
|
* authority once with `vaultAuthority`; if that read fails it stays
|
|
32
36
|
* `unknown`.
|
|
33
37
|
*/
|
|
34
|
-
async function enrollmentReport(plugin, hosts, recorded) {
|
|
38
|
+
async function enrollmentReport(plugin, hosts, recorded, recordedAccess) {
|
|
35
39
|
const report = [];
|
|
36
40
|
for (const host of hosts) {
|
|
37
41
|
let outcome = recorded.get(host) ?? 'not-enrolled';
|
|
42
|
+
let access = recordedAccess.get(host);
|
|
38
43
|
if (outcome === 'unknown') {
|
|
39
44
|
const { name, paths } = plugin.vault.hosts[host];
|
|
40
45
|
const authority = await vaultAuthority(hostEnrollmentPaths(paths), name).catch(() => 'unreadable');
|
|
@@ -42,8 +47,13 @@ async function enrollmentReport(plugin, hosts, recorded) {
|
|
|
42
47
|
outcome = 'enrolled';
|
|
43
48
|
else if (authority === 'local')
|
|
44
49
|
outcome = 'not-enrolled';
|
|
50
|
+
if (outcome === 'enrolled') {
|
|
51
|
+
const status = await readClaustrumEnrollmentStatus(hostEnrollmentPaths(paths), name).catch(() => undefined);
|
|
52
|
+
if (status?.state === 'approved')
|
|
53
|
+
access = await confirmEnrollmentAccess({}, status, hostEnrollmentPaths(paths).tokenPath, plugin.vault.hosts[host].requestedGrants);
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
|
-
report.push({ host, outcome });
|
|
56
|
+
report.push({ host, outcome, ...(access && { access }) });
|
|
47
57
|
}
|
|
48
58
|
return report;
|
|
49
59
|
}
|
|
@@ -207,6 +217,7 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
207
217
|
// Each host's vault enrollment as it happens. A host the operator approved
|
|
208
218
|
// stays enrolled if a later step fails, so a failure reports this record.
|
|
209
219
|
const enrollment = new Map();
|
|
220
|
+
const enrollmentAccess = new Map();
|
|
210
221
|
try {
|
|
211
222
|
for (const host of hosts) {
|
|
212
223
|
await stopped();
|
|
@@ -215,7 +226,9 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
215
226
|
if (useVault) {
|
|
216
227
|
enrollment.set(host, 'unknown');
|
|
217
228
|
try {
|
|
218
|
-
await connectSetupHost(plugin, host, io, terminal, stopped);
|
|
229
|
+
const access = await connectSetupHost(plugin, host, io, terminal, stopped);
|
|
230
|
+
if (access)
|
|
231
|
+
enrollmentAccess.set(host, access);
|
|
219
232
|
}
|
|
220
233
|
catch (error) {
|
|
221
234
|
if (error instanceof HostNotEnrolledError)
|
|
@@ -248,7 +261,7 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
248
261
|
// then rethrow the original value untouched. Reporting must never
|
|
249
262
|
// replace the failure, so its own errors are ignored.
|
|
250
263
|
try {
|
|
251
|
-
const report = await enrollmentReport(plugin, hosts, enrollment);
|
|
264
|
+
const report = await enrollmentReport(plugin, hosts, enrollment, enrollmentAccess);
|
|
252
265
|
recordSetupEnrollment(error, report);
|
|
253
266
|
for (const entry of report)
|
|
254
267
|
printLine(terminal, setupEnrollmentLine(entry));
|
package/dist/setup/enroll.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MenuTerminal } from '../auth-menu/terminal.js';
|
|
2
|
-
import type { SetupHost, SetupIO, SetupPlugin } from './types.js';
|
|
2
|
+
import type { SetupEnrollmentAccess, SetupHost, SetupIO, SetupPlugin } from './types.js';
|
|
3
3
|
/** Fixed text: no version, host or account detail, so it is safe to print anywhere. */
|
|
4
4
|
export declare const UNSUPPORTED_VAULT_MESSAGE = "This Claustrum vault is too old to connect plugins. Run ck upgrade to move to Claustrum v0.2.0 or newer (read \"Upgrading from v0.1.3\" in its release notes first), or run setup without --claustrum to use local accounts.";
|
|
5
5
|
/**
|
|
@@ -31,4 +31,4 @@ export declare class HostNotEnrolledError extends Error {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
/** Enroll an independently revocable host; plugin callbacks choose its credential store and account permissions. */
|
|
34
|
-
export declare function connectSetupHost(plugin: SetupPlugin, host: SetupHost, io: SetupIO, terminal: MenuTerminal, fence: () => Promise<void>): Promise<
|
|
34
|
+
export declare function connectSetupHost(plugin: SetupPlugin, host: SetupHost, io: SetupIO, terminal: MenuTerminal, fence: () => Promise<void>): Promise<SetupEnrollmentAccess | undefined>;
|
package/dist/setup/enroll.js
CHANGED
|
@@ -3,6 +3,7 @@ import { writeEnrollmentTokenFile } from '@cortexkit/claustrum-client';
|
|
|
3
3
|
import { printLine } from '../auth-menu/terminal.js';
|
|
4
4
|
import { ClaustrumEnrollmentManager, connectClaustrumEnrollmentClient, hostEnrollmentPaths, UNSUPPORTED_ENROLLMENT_CODE, } from '../claustrum/enrollment.js';
|
|
5
5
|
import { hasVaultHost, VAULT_HOST_CONNECT_REFUSAL } from '../claustrum/host.js';
|
|
6
|
+
import { confirmEnrollmentAccess, enrollmentAccessLines, } from './enrollment-access.js';
|
|
6
7
|
import { ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
|
|
7
8
|
const ENROLLMENT_INCOMPLETE_MESSAGE = 'Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.';
|
|
8
9
|
/** Fixed text: no version, host or account detail, so it is safe to print anywhere. */
|
|
@@ -54,7 +55,7 @@ function approveCommand(requestId, name) {
|
|
|
54
55
|
export async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
55
56
|
if (hasVaultHost())
|
|
56
57
|
throw new Error(VAULT_HOST_CONNECT_REFUSAL);
|
|
57
|
-
const { name, paths: input } = plugin.vault.hosts[host];
|
|
58
|
+
const { name, displayName, requestedGrants, paths: input, } = plugin.vault.hosts[host];
|
|
58
59
|
const paths = hostEnrollmentPaths(input);
|
|
59
60
|
await fence();
|
|
60
61
|
const client = await (io.connect ?? connectClaustrumEnrollmentClient)({
|
|
@@ -68,6 +69,8 @@ export async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
68
69
|
try {
|
|
69
70
|
const manager = new ClaustrumEnrollmentManager({
|
|
70
71
|
proposedName: name,
|
|
72
|
+
displayName,
|
|
73
|
+
requestedGrants,
|
|
71
74
|
paths,
|
|
72
75
|
// Each tick of the wait below checks the fence once, just before
|
|
73
76
|
// reconcile proposes or polls. Checking again inside every vault call
|
|
@@ -84,7 +87,11 @@ export async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
84
87
|
const initial = await manager.status();
|
|
85
88
|
if (initial.state === 'approved') {
|
|
86
89
|
printLine(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
|
|
87
|
-
|
|
90
|
+
const access = await confirmEnrollmentAccess(client, initial, paths.tokenPath, requestedGrants);
|
|
91
|
+
if (access)
|
|
92
|
+
for (const line of enrollmentAccessLines(access))
|
|
93
|
+
printLine(terminal, line);
|
|
94
|
+
return access;
|
|
88
95
|
}
|
|
89
96
|
printLine(terminal, `Asking the vault to connect ${name}…`);
|
|
90
97
|
const deadline = now() + ENROLLMENT_WAIT_MS;
|
|
@@ -96,7 +103,11 @@ export async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
96
103
|
const status = await manager.reconcile();
|
|
97
104
|
if (status.state === 'approved') {
|
|
98
105
|
printLine(terminal, `Connected ${host} to Claustrum.`);
|
|
99
|
-
|
|
106
|
+
const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
|
|
107
|
+
if (access)
|
|
108
|
+
for (const line of enrollmentAccessLines(access))
|
|
109
|
+
printLine(terminal, line);
|
|
110
|
+
return access;
|
|
100
111
|
}
|
|
101
112
|
if (status.state === 'unavailable' &&
|
|
102
113
|
status.code === UNSUPPORTED_ENROLLMENT_CODE)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ClaustrumEnrollmentConnection, ClaustrumEnrollmentStatus, ClaustrumRequestedGrant } from '../claustrum/enrollment.js';
|
|
2
|
+
import type { SetupEnrollmentAccess } from './types.js';
|
|
3
|
+
/** Check access on the enrollment connection, after the token has reached disk. */
|
|
4
|
+
export declare function confirmEnrollmentAccess(client: Pick<ClaustrumEnrollmentConnection, 'listScoped'>, status: Extract<ClaustrumEnrollmentStatus, {
|
|
5
|
+
state: 'approved';
|
|
6
|
+
}>, tokenPath: string, configuredGrants: ReadonlyArray<ClaustrumRequestedGrant> | undefined): Promise<SetupEnrollmentAccess | undefined>;
|
|
7
|
+
export declare function enrollmentAccessLines(access: SetupEnrollmentAccess): string[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { readClaustrumEnrollmentToken } from '../claustrum/enrollment.js';
|
|
2
|
+
function shellArgument(value) {
|
|
3
|
+
if (/^[a-zA-Z0-9_:@./-]+$/.test(value))
|
|
4
|
+
return value;
|
|
5
|
+
return process.platform === 'win32'
|
|
6
|
+
? `'${value.replaceAll("'", "''")}'`
|
|
7
|
+
: `'${value.replaceAll("'", "'\\''")}'`;
|
|
8
|
+
}
|
|
9
|
+
/** Check access on the enrollment connection, after the token has reached disk. */
|
|
10
|
+
export async function confirmEnrollmentAccess(client, status, tokenPath, configuredGrants) {
|
|
11
|
+
const requestedGrants = status.requestedGrants ?? configuredGrants;
|
|
12
|
+
if (!requestedGrants)
|
|
13
|
+
return undefined;
|
|
14
|
+
const grants = requestedGrants.map((grant) => ({
|
|
15
|
+
grant,
|
|
16
|
+
...(status.approvedName !== undefined && {
|
|
17
|
+
grantCommand: `ck auth grant --principal ${shellArgument(`enrolled:${status.approvedName}`)} --selector-kind ${grant.selector.exact === undefined ? 'category' : 'exact'} --selector ${shellArgument(grant.selector.exact ?? grant.selector.category)} --operation ${grant.operation}`,
|
|
18
|
+
}),
|
|
19
|
+
}));
|
|
20
|
+
if (status.requestedGrantsStatus === 'dropped')
|
|
21
|
+
return { state: 'older-vault', grants };
|
|
22
|
+
try {
|
|
23
|
+
if (!client.listScoped)
|
|
24
|
+
return { state: 'unconfirmed', grants };
|
|
25
|
+
const { token } = await readClaustrumEnrollmentToken(tokenPath);
|
|
26
|
+
const inventory = await client.listScoped(token);
|
|
27
|
+
const confirmed = grants.map((entry) => ({
|
|
28
|
+
...entry,
|
|
29
|
+
reachableLogins: inventory.rows.filter((row) => row.operations.includes(entry.grant.operation) &&
|
|
30
|
+
(entry.grant.selector.exact !== undefined
|
|
31
|
+
? row.id === entry.grant.selector.exact
|
|
32
|
+
: row.categories.includes(entry.grant.selector.category))).length,
|
|
33
|
+
}));
|
|
34
|
+
return {
|
|
35
|
+
state: confirmed.every((entry) => entry.reachableLogins > 0)
|
|
36
|
+
? 'reachable'
|
|
37
|
+
: confirmed.some((entry) => entry.reachableLogins > 0)
|
|
38
|
+
? 'partial'
|
|
39
|
+
: 'no-logins',
|
|
40
|
+
grants: confirmed.map((entry) => {
|
|
41
|
+
if (entry.reachableLogins === 0)
|
|
42
|
+
return entry;
|
|
43
|
+
const { grantCommand: _, ...reachable } = entry;
|
|
44
|
+
return reachable;
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// A listing failure cannot undo approval, and its error may contain secrets.
|
|
50
|
+
return { state: 'unconfirmed', grants };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function enrollmentAccessLines(access) {
|
|
54
|
+
const lines = [];
|
|
55
|
+
const remedy = access.grants.some((entry) => entry.grantCommand)
|
|
56
|
+
? 'run:'
|
|
57
|
+
: 'check ck auth status for the approved name before granting access.';
|
|
58
|
+
if (access.state === 'older-vault')
|
|
59
|
+
lines.push(`Approved. This vault is too old to grant access with the approval; ${remedy}`);
|
|
60
|
+
else if (access.state === 'no-logins')
|
|
61
|
+
lines.push(`Approved, but no logins are reachable yet; ${remedy}`);
|
|
62
|
+
else if (access.state === 'partial')
|
|
63
|
+
lines.push(`Approved, but some requested access has no reachable logins yet; ${remedy}`);
|
|
64
|
+
else if (access.state === 'unconfirmed')
|
|
65
|
+
lines.push(`Approved, but access could not be confirmed; ${access.grants.some((entry) => entry.grantCommand) ? 'check ck auth status or run:' : remedy}`);
|
|
66
|
+
for (const { grant, reachableLogins, grantCommand } of access.grants) {
|
|
67
|
+
if (reachableLogins !== undefined && reachableLogins > 0) {
|
|
68
|
+
const target = grant.selector.exact === undefined
|
|
69
|
+
? `the vault's ${JSON.stringify(grant.selector.category)} accounts`
|
|
70
|
+
: `credential ${JSON.stringify(grant.selector.exact)}`;
|
|
71
|
+
lines.push(`Confirmed ${grant.operation} access to ${target} (${reachableLogins} reachable ${reachableLogins === 1 ? 'login' : 'logins'}).`);
|
|
72
|
+
}
|
|
73
|
+
if (grantCommand)
|
|
74
|
+
lines.push(` ${grantCommand}`);
|
|
75
|
+
}
|
|
76
|
+
return lines;
|
|
77
|
+
}
|
package/dist/setup/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { ENROLLMENT_WAIT_MS, HostNotEnrolledError, type HostNotEnrolledReason, U
|
|
|
5
5
|
export { setupUsage } from './flags.js';
|
|
6
6
|
export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, type ProcessInspectionStep, } from './process-fence.js';
|
|
7
7
|
export { type PlannedWrite, planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
|
|
8
|
-
export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnrollmentOutcome, SetupEnvironment, SetupFileSystem, SetupHost, SetupHostEnrollment, SetupIO, SetupPlugin, SetupResult, } from './types.js';
|
|
8
|
+
export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnrollmentAccess, SetupEnrollmentOutcome, SetupEnvironment, SetupFileSystem, SetupHost, SetupHostEnrollment, SetupIO, SetupPlugin, SetupResult, } from './types.js';
|
package/dist/setup/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MenuTerminal } from '../auth-menu/terminal.js';
|
|
2
|
-
import type { ClaustrumEnrollmentConnection, hostEnrollmentPaths } from '../claustrum/index.js';
|
|
2
|
+
import type { ClaustrumEnrollmentConnection, ClaustrumRequestedGrant, hostEnrollmentPaths } from '../claustrum/index.js';
|
|
3
3
|
export type SetupHost = 'opencode' | 'pi';
|
|
4
4
|
export type OpenCodeGeneration = '1' | '2' | 'both';
|
|
5
5
|
export type SetupEnvironment = Record<string, string | undefined>;
|
|
@@ -11,9 +11,19 @@ export type SetupEnvironment = Record<string, string | undefined>;
|
|
|
11
11
|
* flight and the host's token file could not settle it.
|
|
12
12
|
*/
|
|
13
13
|
export type SetupEnrollmentOutcome = 'enrolled' | 'not-enrolled' | 'unknown';
|
|
14
|
+
export interface SetupEnrollmentAccess {
|
|
15
|
+
state: 'reachable' | 'no-logins' | 'partial' | 'older-vault' | 'unconfirmed';
|
|
16
|
+
/** One result per requested grant, in proposal order. No count means unknown. */
|
|
17
|
+
grants: readonly {
|
|
18
|
+
grant: ClaustrumRequestedGrant;
|
|
19
|
+
reachableLogins?: number;
|
|
20
|
+
grantCommand?: string;
|
|
21
|
+
}[];
|
|
22
|
+
}
|
|
14
23
|
export interface SetupHostEnrollment {
|
|
15
24
|
host: SetupHost;
|
|
16
25
|
outcome: SetupEnrollmentOutcome;
|
|
26
|
+
access?: SetupEnrollmentAccess;
|
|
17
27
|
}
|
|
18
28
|
/**
|
|
19
29
|
* What setup decided before calling a plugin callback. The OpenCode generation
|
|
@@ -50,6 +60,8 @@ export interface SetupPlugin {
|
|
|
50
60
|
connectionFile: string;
|
|
51
61
|
hosts: Record<SetupHost, {
|
|
52
62
|
name: string;
|
|
63
|
+
displayName?: string;
|
|
64
|
+
requestedGrants?: ReadonlyArray<ClaustrumRequestedGrant>;
|
|
53
65
|
paths: Parameters<typeof hostEnrollmentPaths>[0];
|
|
54
66
|
}>;
|
|
55
67
|
};
|
|
@@ -48,29 +48,28 @@ export async function buildTui(entryFile, variant, destinationDir, options = {})
|
|
|
48
48
|
const entry = resolve(entryFile);
|
|
49
49
|
const destination = resolve(destinationDir);
|
|
50
50
|
const roots = new Map();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
const installed = join(directory, 'node_modules', item);
|
|
64
|
-
if (existsSync(join(installed, 'package.json'))) {
|
|
65
|
-
roots.set(item, realpathSync(installed));
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
const parent = dirname(directory);
|
|
69
|
-
if (parent === directory)
|
|
70
|
-
throw new Error(`Cannot locate package root for ${item} from ${entry}`);
|
|
71
|
-
directory = parent;
|
|
51
|
+
const packageRoot = async (name, from) => {
|
|
52
|
+
let directory = dirname(from);
|
|
53
|
+
for (;;) {
|
|
54
|
+
const manifest = join(directory, 'package.json');
|
|
55
|
+
if (existsSync(manifest) &&
|
|
56
|
+
JSON.parse(await readFile(manifest, 'utf8')).name === name) {
|
|
57
|
+
return realpathSync(directory);
|
|
58
|
+
}
|
|
59
|
+
const installed = join(directory, 'node_modules', name);
|
|
60
|
+
if (existsSync(join(installed, 'package.json'))) {
|
|
61
|
+
return realpathSync(installed);
|
|
72
62
|
}
|
|
63
|
+
const parent = dirname(directory);
|
|
64
|
+
if (parent === directory)
|
|
65
|
+
throw new Error(`Cannot locate package root for ${name} from ${from}`);
|
|
66
|
+
directory = parent;
|
|
73
67
|
}
|
|
68
|
+
};
|
|
69
|
+
for (const item of options.inline ?? ['@cortexkit/common-auth']) {
|
|
70
|
+
roots.set(typeof item === 'string' ? item : item.name, typeof item === 'string'
|
|
71
|
+
? await packageRoot(item, entry)
|
|
72
|
+
: resolve(item.root));
|
|
74
73
|
}
|
|
75
74
|
const resolveExport = async (specifier, root, name) => {
|
|
76
75
|
const manifest = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
|
|
@@ -123,14 +122,14 @@ export async function buildTui(entryFile, variant, destinationDir, options = {})
|
|
|
123
122
|
// relative paths, and distinct prefixes for the two kinds. The guard in
|
|
124
123
|
// `visit` turns the remaining risk, two keys sharing a truncated hash, into
|
|
125
124
|
// an error instead of one copy silently overwriting another.
|
|
126
|
-
const namingRoots = [...roots]
|
|
125
|
+
const namingRoots = () => [...roots]
|
|
127
126
|
.map(([name, root]) => ({
|
|
128
127
|
name,
|
|
129
128
|
root: existsSync(root) ? realpathSync(root) : root,
|
|
130
129
|
}))
|
|
131
130
|
.sort((a, b) => b.root.length - a.root.length);
|
|
132
131
|
const sharedKey = (source) => {
|
|
133
|
-
for (const { name, root } of namingRoots) {
|
|
132
|
+
for (const { name, root } of namingRoots()) {
|
|
134
133
|
const path = relative(root, source);
|
|
135
134
|
if (path && !path.startsWith(`..${sep}`) && !isAbsolute(path))
|
|
136
135
|
return `package:${name}/${portable(path)}`;
|
|
@@ -174,6 +173,10 @@ export async function buildTui(entryFile, variant, destinationDir, options = {})
|
|
|
174
173
|
const replacements = [];
|
|
175
174
|
for (const reference of references) {
|
|
176
175
|
let specifier = reference.specifier;
|
|
176
|
+
// The frame ships TSX: leaving it external skips the host's Solid transform.
|
|
177
|
+
// Resolve only when reached so non-sidebar builds need no optional UI peer.
|
|
178
|
+
if (specifier === '@cortexkit/opencode-sidebar' && !roots.has(specifier))
|
|
179
|
+
roots.set(specifier, await packageRoot(specifier, source));
|
|
177
180
|
const inline = [...roots].find(([name]) => specifier === name || specifier.startsWith(`${name}/`));
|
|
178
181
|
if (inline)
|
|
179
182
|
specifier = relativeImport(name, await visit(await resolveExport(specifier, inline[1], inline[0]), true));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/common-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
},
|
|
112
112
|
"files": [
|
|
113
113
|
"dist/",
|
|
114
|
-
"src/quota-sidebar/",
|
|
114
|
+
"src/quota-sidebar/index.tsx",
|
|
115
115
|
"src/quota/format.ts",
|
|
116
116
|
"src/quota/map.ts",
|
|
117
117
|
"src/quota/projection.ts"
|
|
@@ -137,6 +137,7 @@
|
|
|
137
137
|
},
|
|
138
138
|
"peerDependencies": {
|
|
139
139
|
"@cortexkit/claustrum-client": ">=0.6.2",
|
|
140
|
+
"@cortexkit/opencode-sidebar": "~0.1.0",
|
|
140
141
|
"@cortexkit/subc-client": "^0.16.0 || ^0.22.0 || ^0.24.0",
|
|
141
142
|
"@opencode/plugin": ">=2.0.21",
|
|
142
143
|
"@opentui/core": ">=0.4.5",
|
|
@@ -144,6 +145,9 @@
|
|
|
144
145
|
"solid-js": ">=1.9.12 <2"
|
|
145
146
|
},
|
|
146
147
|
"peerDependenciesMeta": {
|
|
148
|
+
"@cortexkit/opencode-sidebar": {
|
|
149
|
+
"optional": true
|
|
150
|
+
},
|
|
147
151
|
"@opentui/core": {
|
|
148
152
|
"optional": true
|
|
149
153
|
},
|
|
@@ -165,7 +169,8 @@
|
|
|
165
169
|
},
|
|
166
170
|
"devDependencies": {
|
|
167
171
|
"@biomejs/biome": "2.5.14",
|
|
168
|
-
"@cortexkit/claustrum-client": "^0.
|
|
172
|
+
"@cortexkit/claustrum-client": "^0.18.0",
|
|
173
|
+
"@cortexkit/opencode-sidebar": "0.1.0",
|
|
169
174
|
"@cortexkit/subc-client": "0.24.0",
|
|
170
175
|
"@earendil-works/pi-coding-agent": "1.0.4",
|
|
171
176
|
"@opencode/plugin": "2.0.21",
|