@cortexkit/opencode-antigravity-auth 3.0.40 → 3.0.42
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/cli.js +1277 -1073
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +122 -112
- package/dist/index.js +7472 -4214
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +1494 -509
- package/dist/server.js +5990 -2678
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/commands/builtins.d.ts +20 -1
- package/dist/src/common-auth-embedded/commands/builtins.js +28 -12
- package/dist/src/common-auth-embedded/commands/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/commands/menu.d.ts +6 -1
- package/dist/src/common-auth-embedded/commands/menu.js +1 -0
- package/dist/src/common-auth-embedded/fs/file-read-cache.js +9 -5
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +159 -11
- package/dist/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
- package/dist/src/common-auth-embedded/fs/with-lock.js +1 -1
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
- package/dist/src/common-auth-embedded/routing-accessor/index.js +49 -7
- package/dist/src/common-auth-embedded/settings/define.d.ts +35 -0
- package/dist/src/common-auth-embedded/settings/define.js +52 -0
- package/dist/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
- package/dist/src/common-auth-embedded/settings/descriptors.js +81 -0
- package/dist/src/common-auth-embedded/settings/edit.d.ts +24 -0
- package/dist/src/common-auth-embedded/settings/edit.js +229 -0
- package/dist/src/common-auth-embedded/settings/fs.js +19 -0
- package/dist/src/common-auth-embedded/settings/handle.d.ts +30 -0
- package/dist/src/common-auth-embedded/settings/handle.js +228 -0
- package/dist/src/common-auth-embedded/settings/index.d.ts +10 -0
- package/dist/src/common-auth-embedded/settings/index.js +7 -0
- package/dist/src/common-auth-embedded/settings/lock-errors.js +15 -0
- package/dist/src/common-auth-embedded/settings/move.d.ts +76 -0
- package/dist/src/common-auth-embedded/settings/move.js +351 -0
- package/dist/src/common-auth-embedded/settings/parse.d.ts +24 -0
- package/dist/src/common-auth-embedded/settings/parse.js +65 -0
- package/dist/src/common-auth-embedded/settings/paths.d.ts +12 -0
- package/dist/src/common-auth-embedded/settings/paths.js +48 -0
- package/dist/src/common-auth-embedded/settings/refusal.d.ts +7 -0
- package/dist/src/common-auth-embedded/settings/refusal.js +15 -0
- package/dist/src/common-auth-embedded/settings/resolve.d.ts +15 -0
- package/dist/src/common-auth-embedded/settings/resolve.js +51 -0
- package/dist/src/common-auth-embedded/settings/schema.d.ts +29 -0
- package/dist/src/common-auth-embedded/settings/schema.js +81 -0
- package/dist/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
- package/dist/src/common-auth-embedded/settings/snapshot.js +150 -0
- package/dist/src/common-auth-embedded/settings/update.js +139 -0
- package/dist/src/common-auth-embedded/settings/write.js +88 -0
- package/dist/src/common-auth-embedded/setup/command-error.d.ts +1 -1
- package/dist/src/common-auth-embedded/setup/command-error.js +3 -2
- package/dist/src/common-auth-embedded/setup/command.js +5 -1
- package/dist/src/common-auth-embedded/setup/enroll.js +3 -3
- package/dist/src/common-auth-embedded/setup/enrollment-access.js +13 -4
- package/dist/src/common-auth-embedded/setup/types.d.ts +4 -0
- package/dist/src/common-auth-embedded/source-output.json +297 -61
- package/dist/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
- package/dist/src/ga/tui/host-ga.js +1 -1
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/command-apply.d.ts +43 -3
- package/dist/src/plugin/command-apply.d.ts.map +1 -1
- package/dist/src/plugin/command-apply.js +92 -12
- package/dist/src/plugin/command-apply.js.map +1 -1
- package/dist/src/plugin/commands.d.ts +5 -1
- package/dist/src/plugin/commands.d.ts.map +1 -1
- package/dist/src/plugin/commands.js +4 -3
- package/dist/src/plugin/commands.js.map +1 -1
- package/dist/src/plugin/config/writer.d.ts +10 -3
- package/dist/src/plugin/config/writer.d.ts.map +1 -1
- package/dist/src/plugin/config/writer.js +30 -22
- package/dist/src/plugin/config/writer.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts +8 -3
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +1 -0
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts +3 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +35 -5
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +65 -15
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/killswitch.d.ts +20 -0
- package/dist/src/plugin/killswitch.d.ts.map +1 -1
- package/dist/src/plugin/killswitch.js +14 -4
- package/dist/src/plugin/killswitch.js.map +1 -1
- package/dist/src/plugin/operator-settings.d.ts +6 -0
- package/dist/src/plugin/operator-settings.d.ts.map +1 -1
- package/dist/src/plugin/operator-settings.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts +15 -0
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +17 -2
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +18 -2
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +130 -13
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/runtime.d.ts +15 -0
- package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
- package/dist/src/plugin/shared/runtime.js +43 -11
- package/dist/src/plugin/shared/runtime.js.map +1 -1
- package/dist/src/plugin/shared/vault-menu.d.ts +11 -1
- package/dist/src/plugin/shared/vault-menu.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-menu.js +33 -7
- package/dist/src/plugin/shared/vault-menu.js.map +1 -1
- package/dist/src/settings/core-settings.d.ts +7 -0
- package/dist/src/settings/core-settings.d.ts.map +1 -0
- package/dist/src/settings/core-settings.js +7 -0
- package/dist/src/settings/core-settings.js.map +1 -0
- package/dist/src/settings/legacy.d.ts +89 -0
- package/dist/src/settings/legacy.d.ts.map +1 -0
- package/dist/src/settings/legacy.js +184 -0
- package/dist/src/settings/legacy.js.map +1 -0
- package/dist/src/settings/location.d.ts +22 -0
- package/dist/src/settings/location.d.ts.map +1 -0
- package/dist/src/settings/location.js +49 -0
- package/dist/src/settings/location.js.map +1 -0
- package/dist/src/settings/move.d.ts +38 -0
- package/dist/src/settings/move.d.ts.map +1 -0
- package/dist/src/settings/move.js +83 -0
- package/dist/src/settings/move.js.map +1 -0
- package/dist/src/settings/protection.d.ts +11 -0
- package/dist/src/settings/protection.d.ts.map +1 -0
- package/dist/src/settings/protection.js +17 -0
- package/dist/src/settings/protection.js.map +1 -0
- package/dist/src/settings/report.d.ts +33 -0
- package/dist/src/settings/report.d.ts.map +1 -0
- package/dist/src/settings/report.js +103 -0
- package/dist/src/settings/report.js.map +1 -0
- package/dist/src/settings/runtime.d.ts +145 -0
- package/dist/src/settings/runtime.d.ts.map +1 -0
- package/dist/src/settings/runtime.js +697 -0
- package/dist/src/settings/runtime.js.map +1 -0
- package/dist/tui-build-map.json +1 -1
- package/dist/tui-ga-build-map.json +5 -5
- package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +20 -1
- package/dist/types/src/common-auth-embedded/commands/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/commands/menu.d.ts +6 -1
- package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
- package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +4 -0
- package/dist/types/src/plugin/command-apply.d.ts +43 -3
- package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
- package/dist/types/src/plugin/commands.d.ts +5 -1
- package/dist/types/src/plugin/commands.d.ts.map +1 -1
- package/dist/types/src/plugin/config/writer.d.ts +10 -3
- package/dist/types/src/plugin/config/writer.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts +8 -3
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts +3 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/killswitch.d.ts +20 -0
- package/dist/types/src/plugin/killswitch.d.ts.map +1 -1
- package/dist/types/src/plugin/operator-settings.d.ts +6 -0
- package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
- package/dist/types/src/plugin/request-helpers.d.ts +15 -0
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +18 -2
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/runtime.d.ts +15 -0
- package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-menu.d.ts +11 -1
- package/dist/types/src/plugin/shared/vault-menu.d.ts.map +1 -1
- package/dist/types/src/settings/core-settings.d.ts +7 -0
- package/dist/types/src/settings/core-settings.d.ts.map +1 -0
- package/dist/types/src/settings/legacy.d.ts +89 -0
- package/dist/types/src/settings/legacy.d.ts.map +1 -0
- package/dist/types/src/settings/location.d.ts +22 -0
- package/dist/types/src/settings/location.d.ts.map +1 -0
- package/dist/types/src/settings/move.d.ts +38 -0
- package/dist/types/src/settings/move.d.ts.map +1 -0
- package/dist/types/src/settings/protection.d.ts +11 -0
- package/dist/types/src/settings/protection.d.ts.map +1 -0
- package/dist/types/src/settings/report.d.ts +33 -0
- package/dist/types/src/settings/report.d.ts.map +1 -0
- package/dist/types/src/settings/runtime.d.ts +145 -0
- package/dist/types/src/settings/runtime.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/common-auth-embedded/commands/builtins.d.ts +20 -1
- package/src/common-auth-embedded/commands/builtins.js +28 -12
- package/src/common-auth-embedded/commands/index.d.ts +1 -1
- package/src/common-auth-embedded/commands/menu.d.ts +6 -1
- package/src/common-auth-embedded/commands/menu.js +1 -0
- package/src/common-auth-embedded/fs/file-read-cache.js +9 -5
- package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +159 -11
- package/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
- package/src/common-auth-embedded/fs/with-lock.js +1 -1
- package/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
- package/src/common-auth-embedded/routing-accessor/index.js +49 -7
- package/src/common-auth-embedded/settings/define.d.ts +35 -0
- package/src/common-auth-embedded/settings/define.js +52 -0
- package/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
- package/src/common-auth-embedded/settings/descriptors.js +81 -0
- package/src/common-auth-embedded/settings/edit.d.ts +24 -0
- package/src/common-auth-embedded/settings/edit.js +229 -0
- package/src/common-auth-embedded/settings/fs.js +19 -0
- package/src/common-auth-embedded/settings/handle.d.ts +30 -0
- package/src/common-auth-embedded/settings/handle.js +228 -0
- package/src/common-auth-embedded/settings/index.d.ts +10 -0
- package/src/common-auth-embedded/settings/index.js +7 -0
- package/src/common-auth-embedded/settings/lock-errors.js +15 -0
- package/src/common-auth-embedded/settings/move.d.ts +76 -0
- package/src/common-auth-embedded/settings/move.js +351 -0
- package/src/common-auth-embedded/settings/parse.d.ts +24 -0
- package/src/common-auth-embedded/settings/parse.js +65 -0
- package/src/common-auth-embedded/settings/paths.d.ts +12 -0
- package/src/common-auth-embedded/settings/paths.js +48 -0
- package/src/common-auth-embedded/settings/refusal.d.ts +7 -0
- package/src/common-auth-embedded/settings/refusal.js +15 -0
- package/src/common-auth-embedded/settings/resolve.d.ts +15 -0
- package/src/common-auth-embedded/settings/resolve.js +51 -0
- package/src/common-auth-embedded/settings/schema.d.ts +29 -0
- package/src/common-auth-embedded/settings/schema.js +81 -0
- package/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
- package/src/common-auth-embedded/settings/snapshot.js +150 -0
- package/src/common-auth-embedded/settings/update.js +139 -0
- package/src/common-auth-embedded/settings/write.js +88 -0
- package/src/common-auth-embedded/setup/command-error.d.ts +1 -1
- package/src/common-auth-embedded/setup/command-error.js +3 -2
- package/src/common-auth-embedded/setup/command.js +5 -1
- package/src/common-auth-embedded/setup/enroll.js +3 -3
- package/src/common-auth-embedded/setup/enrollment-access.js +13 -4
- package/src/common-auth-embedded/setup/types.d.ts +4 -0
- package/src/common-auth-embedded/source-output.json +297 -61
- package/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
- package/src/tui-ga-compiled/host-ga.js +1 -1
- package/src/tui-ga-raw/host-ga.tsx +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One process's view of `antigravity-auth.jsonc`, shared by every OpenCode
|
|
3
|
+
* location in the process that uses the same settings file.
|
|
4
|
+
*
|
|
5
|
+
* - **Separate install** (`location.ts`): today's readers and writers stay in
|
|
6
|
+
* force for the life of the process; the shared file is never opened.
|
|
7
|
+
* - **Legacy, waiting for the move:** while the shared file is missing, the
|
|
8
|
+
* process keeps reading and writing `antigravity.json` and retries the
|
|
9
|
+
* one-time move in the background on a backoff.
|
|
10
|
+
* - **Shared:** once the shared file exists (moved here, by another
|
|
11
|
+
* process, or created by hand) every location reads it through one
|
|
12
|
+
* settings handle and menu writes go through `handle.update`.
|
|
13
|
+
*
|
|
14
|
+
* Requests never read a file: each location holds a live
|
|
15
|
+
* `AntigravityConfig` object, and the operator controller and model-access
|
|
16
|
+
* policy serve values resolved in memory. They are rebuilt when the
|
|
17
|
+
* handle's watcher fires, when a menu opens and after a menu write.
|
|
18
|
+
*/
|
|
19
|
+
import { type moveSettingsOnce, openSettings } from '@cortexkit/antigravity-auth-core/common-auth/settings';
|
|
20
|
+
import { type OperatorSettings } from '../plugin/config/operator-settings-schema.js';
|
|
21
|
+
import { type AntigravityConfig } from '../plugin/config/schema.js';
|
|
22
|
+
import type { FloorKeying } from '../plugin/killswitch.js';
|
|
23
|
+
import { type OperatorSettingsController } from '../plugin/operator-settings.js';
|
|
24
|
+
import { type AccountModels, type ModelAccessPolicy } from './core-settings.js';
|
|
25
|
+
import { type FloorKeyTable } from './legacy.js';
|
|
26
|
+
import { type ProtectionStore } from './protection.js';
|
|
27
|
+
type Values = Record<string, unknown>;
|
|
28
|
+
/** Build today's configuration shape from resolved setting values. */
|
|
29
|
+
export declare function toAntigravityConfig(values: Values, operator: OperatorSettings): AntigravityConfig;
|
|
30
|
+
export interface SettingsLog {
|
|
31
|
+
warn(message: string, data?: unknown): void;
|
|
32
|
+
info(message: string, data?: unknown): void;
|
|
33
|
+
}
|
|
34
|
+
export interface SettingsRuntimeOptions {
|
|
35
|
+
/** The shared settings file and whether this install keeps the old files. */
|
|
36
|
+
readonly file: string;
|
|
37
|
+
readonly separateInstall: boolean;
|
|
38
|
+
/** `<OpenCode config folder>/antigravity.json`. */
|
|
39
|
+
readonly legacyUserFile: string;
|
|
40
|
+
readonly log: SettingsLog;
|
|
41
|
+
/** Open only when no older plugin version runs; defaults to the version fence. */
|
|
42
|
+
readonly fence?: () => Promise<boolean>;
|
|
43
|
+
/** Floor keys of the local account rows, for re-keying old floors. */
|
|
44
|
+
readonly floorKeys?: () => Promise<FloorKeyTable | null>;
|
|
45
|
+
/** Test seams: the library calls and the state files. */
|
|
46
|
+
readonly open?: typeof openSettings;
|
|
47
|
+
readonly move?: typeof moveSettingsOnce;
|
|
48
|
+
readonly protection?: ProtectionStore;
|
|
49
|
+
readonly moveReportPath?: string;
|
|
50
|
+
/** Delays between move attempts; the last one repeats. */
|
|
51
|
+
readonly retryDelaysMs?: readonly number[];
|
|
52
|
+
}
|
|
53
|
+
/** Today's readers for one project, used while the shared file is not in force. */
|
|
54
|
+
export interface LegacyProjectReaders {
|
|
55
|
+
config(): AntigravityConfig;
|
|
56
|
+
operator(): OperatorSettingsController & {
|
|
57
|
+
sourcePath?(): string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface SettingsOperatorController extends OperatorSettingsController {
|
|
61
|
+
floorKeying(): FloorKeying;
|
|
62
|
+
/** The file this location's operator values come from. */
|
|
63
|
+
sourcePath(): string;
|
|
64
|
+
}
|
|
65
|
+
/** One location's settings. */
|
|
66
|
+
export interface ProjectSettings {
|
|
67
|
+
/** Live configuration; hot values are replaced in place on refresh. */
|
|
68
|
+
readonly config: AntigravityConfig;
|
|
69
|
+
readonly operator: SettingsOperatorController;
|
|
70
|
+
mode(): 'legacy' | 'shared';
|
|
71
|
+
/** The file the user edits: `antigravity-auth.jsonc` or `antigravity.json`. */
|
|
72
|
+
configuredIn(): string;
|
|
73
|
+
/** The per-account model policy in force, resolved in memory. */
|
|
74
|
+
modelAccess(): ModelAccessPolicy;
|
|
75
|
+
/**
|
|
76
|
+
* The per-account model lists in force, for the menu: a key maps to its
|
|
77
|
+
* list and a missing key serves every model; `deny-all` means the setting
|
|
78
|
+
* can't be used and nothing earlier is known. Undefined while this install
|
|
79
|
+
* does not read the shared settings file.
|
|
80
|
+
*/
|
|
81
|
+
accountModels(): AccountModels | 'deny-all' | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Sets (or, with null, removes) one account's list in the user file,
|
|
84
|
+
* keeping its comments. The key is the account's stable id. Refuses with
|
|
85
|
+
* `AntigravityMenuRefusal` and fixed text when nothing can be saved: the
|
|
86
|
+
* shared file is not in use, the list is empty or names no known model, or
|
|
87
|
+
* the library refuses the edit.
|
|
88
|
+
*/
|
|
89
|
+
updateAccountModels(accountKey: string, models: readonly string[] | null): Promise<void>;
|
|
90
|
+
/** Lines for the Limits section. */
|
|
91
|
+
limitsNotices(): readonly string[];
|
|
92
|
+
/** Lines for the Diagnostics section; reads files, so call it from menus only. */
|
|
93
|
+
diagnosticsNotices(): Promise<readonly string[]>;
|
|
94
|
+
readonly moveReport: {
|
|
95
|
+
present(): Promise<boolean>;
|
|
96
|
+
dismiss(): Promise<void>;
|
|
97
|
+
};
|
|
98
|
+
/** On menu open: switch to the shared file if it appeared and re-read files. */
|
|
99
|
+
refresh(): Promise<void>;
|
|
100
|
+
/** Called after each refresh that may have changed values. */
|
|
101
|
+
onChange(listener: () => void): () => void;
|
|
102
|
+
release(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
export interface AntigravitySettingsRuntime {
|
|
105
|
+
mode(): 'legacy' | 'shared';
|
|
106
|
+
openProject(project: string, legacy: LegacyProjectReaders): Promise<ProjectSettings>;
|
|
107
|
+
/** Start the background move; does nothing once it has started or finished. */
|
|
108
|
+
startMove(): void;
|
|
109
|
+
/** Settle once the current move attempt and refresh have finished (tests). */
|
|
110
|
+
settled(): Promise<void>;
|
|
111
|
+
dispose(): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
export declare function createSettingsRuntime(options: SettingsRuntimeOptions): AntigravitySettingsRuntime;
|
|
114
|
+
export interface SettingsRuntimeLease {
|
|
115
|
+
readonly runtime: AntigravitySettingsRuntime;
|
|
116
|
+
release(): Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
export interface SettingsRuntimeRegistry {
|
|
119
|
+
acquire(options: SettingsRuntimeOptions): SettingsRuntimeLease;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* One runtime per settings file in a process, so every OpenCode location
|
|
123
|
+
* on that file shares one handle, one watcher and one move. Options other
|
|
124
|
+
* than the paths come from the first caller.
|
|
125
|
+
*/
|
|
126
|
+
export declare function createSettingsRuntimeRegistry(): SettingsRuntimeRegistry;
|
|
127
|
+
export declare const processSettingsRuntimes: SettingsRuntimeRegistry;
|
|
128
|
+
/** The settings file and separate-install decision for this OpenCode process. */
|
|
129
|
+
export declare function openCodeSettingsPaths(project: string): Promise<{
|
|
130
|
+
readonly file: string;
|
|
131
|
+
readonly separateInstall: boolean;
|
|
132
|
+
readonly legacyUserFile: string;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* Resolve one project's configuration once, the way a starting OpenCode
|
|
136
|
+
* process would, without moving anything or watching the file. Tools and
|
|
137
|
+
* test harnesses use it to check which values a location would get.
|
|
138
|
+
*/
|
|
139
|
+
export declare function loadSettingsSnapshot(directory: string): Promise<{
|
|
140
|
+
readonly config: AntigravityConfig;
|
|
141
|
+
readonly mode: 'legacy' | 'shared';
|
|
142
|
+
readonly file: string;
|
|
143
|
+
}>;
|
|
144
|
+
export {};
|
|
145
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/settings/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,OAAO,EACL,KAAK,gBAAgB,EACrB,YAAY,EAKb,MAAM,uDAAuD,CAAA;AAO9D,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,2CAA2C,CAAA;AAClD,OAAO,EAAE,KAAK,iBAAiB,EAAkB,MAAM,yBAAyB,CAAA;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,6BAA6B,CAAA;AAGpC,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EAEvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,UAAU,CAAA;AAGjB,OAAO,EAGL,KAAK,eAAe,EAIrB,MAAM,cAAc,CAAA;AAarB,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAmCrC,sEAAsE;AACtE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,GACzB,iBAAiB,CAcnB;AAaD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IAC3C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CAC5C;AAED,MAAM,WAAW,sBAAsB;IACrC,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAA;IACjC,mDAAmD;IACnD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;IACzB,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IACvC,sEAAsE;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACxD,yDAAyD;IACzD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,YAAY,CAAA;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,gBAAgB,CAAA;IACvC,QAAQ,CAAC,UAAU,CAAC,EAAE,eAAe,CAAA;IACrC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,0DAA0D;IAC1D,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC3C;AAED,mFAAmF;AACnF,MAAM,WAAW,oBAAoB;IACnC,MAAM,IAAI,iBAAiB,CAAA;IAC3B,QAAQ,IAAI,0BAA0B,GAAG;QAAE,UAAU,CAAC,IAAI,MAAM,CAAA;KAAE,CAAA;CACnE;AAED,MAAM,WAAW,0BAA2B,SAAQ,0BAA0B;IAC5E,WAAW,IAAI,WAAW,CAAA;IAC1B,0DAA0D;IAC1D,UAAU,IAAI,MAAM,CAAA;CACrB;AAED,+BAA+B;AAC/B,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;IAClC,QAAQ,CAAC,QAAQ,EAAE,0BAA0B,CAAA;IAC7C,IAAI,IAAI,QAAQ,GAAG,QAAQ,CAAA;IAC3B,+EAA+E;IAC/E,YAAY,IAAI,MAAM,CAAA;IACtB,iEAAiE;IACjE,WAAW,IAAI,iBAAiB,CAAA;IAChC;;;;;OAKG;IACH,aAAa,IAAI,aAAa,GAAG,UAAU,GAAG,SAAS,CAAA;IACvD;;;;;;OAMG;IACH,mBAAmB,CACjB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GAC/B,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB,oCAAoC;IACpC,aAAa,IAAI,SAAS,MAAM,EAAE,CAAA;IAClC,kFAAkF;IAClF,kBAAkB,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAA;IAChD,QAAQ,CAAC,UAAU,EAAE;QACnB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;KACzB,CAAA;IACD,gFAAgF;IAChF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACxB,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;IAC1C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,IAAI,QAAQ,GAAG,QAAQ,CAAA;IAC3B,WAAW,CACT,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,eAAe,CAAC,CAAA;IAC3B,+EAA+E;IAC/E,SAAS,IAAI,IAAI,CAAA;IACjB,8EAA8E;IAC9E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;AA0BD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,0BAA0B,CAihB5B;AAMD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAA;IAC5C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,OAAO,EAAE,sBAAsB,GAAG,oBAAoB,CAAA;CAC/D;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,uBAAuB,CAiCvE;AAED,eAAO,MAAM,uBAAuB,EAAE,uBACL,CAAA;AAEjC,iFAAiF;AACjF,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAA;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAChC,CAAC,CAaD;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACrE,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;IAClC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB,CAAC,CAyBD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/opencode-antigravity-auth",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.42",
|
|
4
4
|
"description": "Google Antigravity OAuth auth plugin for OpenCode - access Gemini and Claude models using Google credentials",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"build": "bun run embed:check && bun scripts/build-tui.ts --library && esbuild src/server.ts --bundle --platform=node --format=esm --external:zod --external:jsonc-parser --external:@cortexkit/private-files --external:@cortexkit/claustrum-client --external:@cortexkit/subc-client --outfile=dist/server.js --sourcemap --metafile=dist/server.meta.json --log-level=warning && tsc -p tsconfig.ga.emit.json && bun ../../scripts/finalize-declaration-specifiers.ts dist/types .",
|
|
74
74
|
"build:tui": "bun run embed:check && bun scripts/build-tui.ts",
|
|
75
75
|
"build:schema": "bun script/build-schema.ts",
|
|
76
|
+
"build:settings-schema": "bun script/build-settings-schema.ts",
|
|
76
77
|
"smoke:tui": "bun run embed:check && bun scripts/smoke-tui-pack-install.ts",
|
|
77
78
|
"typecheck": "bun run embed:check && bun scripts/build-tui.ts --types && tsc --noEmit && tsc -p tsconfig.ga.json",
|
|
78
79
|
"test": "bun run embed:check && bun test --isolate ./src ./scripts/build-tui.test.ts",
|
|
@@ -131,7 +132,7 @@
|
|
|
131
132
|
"dependencies": {
|
|
132
133
|
"@cortexkit/claustrum-client": "0.18.0",
|
|
133
134
|
"@cortexkit/subc-client": "0.24.0",
|
|
134
|
-
"@cortexkit/antigravity-auth-core": "3.0.
|
|
135
|
+
"@cortexkit/antigravity-auth-core": "3.0.42",
|
|
135
136
|
"@cortexkit/private-files": "0.2.2",
|
|
136
137
|
"jsonc-parser": "^3.3.1",
|
|
137
138
|
"xdg-basedir": "^5.1.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AddInput, PoolLockSpec, PoolRow, PoolStore, RemoveOptions } from '../store/index.js';
|
|
1
|
+
import type { AddInput, PoolLockSpec, PoolRow, PoolSettings, PoolStore, RemoveOptions, SettingsMutator } from '../store/index.js';
|
|
2
2
|
import type { CommandInvocation, KnobValues, MenuChoice, MenuKnob } from './model.js';
|
|
3
3
|
import { type ResolvedSection } from './seam.js';
|
|
4
4
|
/**
|
|
@@ -98,9 +98,28 @@ export interface LimitsSectionOptions {
|
|
|
98
98
|
*/
|
|
99
99
|
labels?: readonly string[];
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Where the Routing and Limits sections read and write the settings they show
|
|
103
|
+
* (`routing.mode`, `routing.maxSameAccountWait`, `killswitch.enabled`,
|
|
104
|
+
* `killswitch.accounts`). Without a port they use the account store's own
|
|
105
|
+
* settings through `readSettings` and `updateSettings`. A plugin that moved
|
|
106
|
+
* its settings to its own file (`./settings`) passes a port that translates
|
|
107
|
+
* this store-shaped view to that file.
|
|
108
|
+
*/
|
|
109
|
+
export interface BuiltinSettingsPort {
|
|
110
|
+
/** The current settings, in the store's settings shape. */
|
|
111
|
+
read(): Promise<PoolSettings>;
|
|
112
|
+
/**
|
|
113
|
+
* Apply one menu change. `mutator` gets a private copy in the store's shape
|
|
114
|
+
* and edits it in place or returns the whole next object, as with
|
|
115
|
+
* `updateSettings`. A refusal is thrown and shown as the action's failure.
|
|
116
|
+
*/
|
|
117
|
+
update(mutator: SettingsMutator): Promise<void>;
|
|
118
|
+
}
|
|
101
119
|
export interface BuiltinOptions {
|
|
102
120
|
store: PoolStore;
|
|
103
121
|
extraLocks?: readonly PoolLockSpec[];
|
|
122
|
+
settings?: BuiltinSettingsPort;
|
|
104
123
|
now: () => number;
|
|
105
124
|
accounts?: AccountsSectionOptions;
|
|
106
125
|
quota?: QuotaSectionOptions;
|
|
@@ -65,15 +65,31 @@ function addedText(name, result) {
|
|
|
65
65
|
function failureMessage(error) {
|
|
66
66
|
return projectFailure(error).text;
|
|
67
67
|
}
|
|
68
|
+
/** The plugin's settings port, or one over the account store's own settings. */
|
|
69
|
+
function settingsPort(options) {
|
|
70
|
+
if (options.settings)
|
|
71
|
+
return options.settings;
|
|
72
|
+
const { store, extraLocks } = options;
|
|
73
|
+
const locks = extraLocks ? { extraLocks } : {};
|
|
74
|
+
return {
|
|
75
|
+
async read() {
|
|
76
|
+
const read = await store.readSettings();
|
|
77
|
+
return read.status === 'error' ? {} : read.settings;
|
|
78
|
+
},
|
|
79
|
+
async update(mutator) {
|
|
80
|
+
await store.updateSettings(mutator, locks);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
68
84
|
async function snapshot(options) {
|
|
69
85
|
const { store } = options;
|
|
70
86
|
const load = await store.read();
|
|
71
|
-
const
|
|
87
|
+
const settings = await settingsPort(options).read();
|
|
72
88
|
const vault = await options.routing?.vaultOrder?.();
|
|
73
89
|
return {
|
|
74
90
|
load,
|
|
75
91
|
rows: distinctRows(load),
|
|
76
|
-
settings
|
|
92
|
+
settings,
|
|
77
93
|
...(vault ? { vault } : {}),
|
|
78
94
|
};
|
|
79
95
|
}
|
|
@@ -396,6 +412,7 @@ function vaultNames(vault) {
|
|
|
396
412
|
function routingSection(options, snap) {
|
|
397
413
|
const { store, extraLocks } = options;
|
|
398
414
|
const locks = extraLocks ? { extraLocks } : {};
|
|
415
|
+
const port = settingsPort(options);
|
|
399
416
|
const choices = [
|
|
400
417
|
{ value: 'ordered', label: 'Ordered (roster order)' },
|
|
401
418
|
...(options.routing?.orderedVariants ?? []),
|
|
@@ -428,10 +445,10 @@ function routingSection(options, snap) {
|
|
|
428
445
|
],
|
|
429
446
|
run: async ({ values }) => {
|
|
430
447
|
const mode = String(values.mode);
|
|
431
|
-
await
|
|
448
|
+
await port.update((settings) => {
|
|
432
449
|
settings.routing = { ...record(settings.routing), mode };
|
|
433
450
|
return undefined;
|
|
434
|
-
}
|
|
451
|
+
});
|
|
435
452
|
return `Routing mode set to ${choices.find((choice) => choice.value === mode)?.label ?? mode}.`;
|
|
436
453
|
},
|
|
437
454
|
},
|
|
@@ -495,13 +512,13 @@ function routingSection(options, snap) {
|
|
|
495
512
|
run: async ({ values }) => {
|
|
496
513
|
const value = String(values.maxSameAccountWait);
|
|
497
514
|
const maxSameAccountWait = value === 'max' ? 'max' : Number(value);
|
|
498
|
-
await
|
|
515
|
+
await port.update((settings) => {
|
|
499
516
|
settings.routing = {
|
|
500
517
|
...record(settings.routing),
|
|
501
518
|
maxSameAccountWait,
|
|
502
519
|
};
|
|
503
520
|
return undefined;
|
|
504
|
-
}
|
|
521
|
+
});
|
|
505
522
|
return `${waitLabel} set to ${waitName(value)}.`;
|
|
506
523
|
},
|
|
507
524
|
});
|
|
@@ -541,8 +558,7 @@ function floorNames(options, snap) {
|
|
|
541
558
|
return (label) => names.get(label) ?? label;
|
|
542
559
|
}
|
|
543
560
|
function limitsSection(options, snap) {
|
|
544
|
-
const
|
|
545
|
-
const locks = extraLocks ? { extraLocks } : {};
|
|
561
|
+
const port = settingsPort(options);
|
|
546
562
|
const killswitch = record(snap.settings.killswitch);
|
|
547
563
|
const enabled = killswitch.enabled === true;
|
|
548
564
|
const floors = record(killswitch.accounts);
|
|
@@ -577,7 +593,7 @@ function limitsSection(options, snap) {
|
|
|
577
593
|
: {}),
|
|
578
594
|
})),
|
|
579
595
|
run: async ({ values }) => {
|
|
580
|
-
await
|
|
596
|
+
await port.update((settings) => {
|
|
581
597
|
const next = record(settings.killswitch);
|
|
582
598
|
const accounts = record(next.accounts);
|
|
583
599
|
const mine = record(accounts[row.id]);
|
|
@@ -598,7 +614,7 @@ function limitsSection(options, snap) {
|
|
|
598
614
|
delete next.accounts;
|
|
599
615
|
settings.killswitch = next;
|
|
600
616
|
return undefined;
|
|
601
|
-
}
|
|
617
|
+
});
|
|
602
618
|
return `Floors updated for ${name}.`;
|
|
603
619
|
},
|
|
604
620
|
},
|
|
@@ -628,13 +644,13 @@ function limitsSection(options, snap) {
|
|
|
628
644
|
],
|
|
629
645
|
run: async ({ values }) => {
|
|
630
646
|
const on = values.enabled === true;
|
|
631
|
-
await
|
|
647
|
+
await port.update((settings) => {
|
|
632
648
|
settings.killswitch = {
|
|
633
649
|
...record(settings.killswitch),
|
|
634
650
|
enabled: on,
|
|
635
651
|
};
|
|
636
652
|
return undefined;
|
|
637
|
-
}
|
|
653
|
+
});
|
|
638
654
|
return `Killswitch ${on ? 'on' : 'off'}.`;
|
|
639
655
|
},
|
|
640
656
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AccountsSectionOptions, LimitsSectionOptions, LoginOutcome, QuotaSectionOptions, RoutingSectionOptions, VaultRoutingOrder, } from './builtins.js';
|
|
1
|
+
export type { AccountsSectionOptions, BuiltinSettingsPort, LimitsSectionOptions, LoginOutcome, QuotaSectionOptions, RoutingSectionOptions, VaultRoutingOrder, } from './builtins.js';
|
|
2
2
|
export { MENU_DISABLED_REASON } from './builtins.js';
|
|
3
3
|
export type { CommandMenu, CommandMenuOptions, StoreSectionSlot, } from './menu.js';
|
|
4
4
|
export { createCommandMenu, parseApplyRequest } from './menu.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RedactionOptions } from '../logger/index.js';
|
|
2
2
|
import type { PoolLockSpec, PoolStore } from '../store/index.js';
|
|
3
|
-
import { type AccountsSectionOptions, type LimitsSectionOptions, type QuotaSectionOptions, type RoutingSectionOptions } from './builtins.js';
|
|
3
|
+
import { type AccountsSectionOptions, type BuiltinSettingsPort, type LimitsSectionOptions, type QuotaSectionOptions, type RoutingSectionOptions } from './builtins.js';
|
|
4
4
|
import type { CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, PluginExtraSection, PluginSection } from './model.js';
|
|
5
5
|
import { type SeamLogger } from './seam.js';
|
|
6
6
|
/** The four slots the library can build from a pool store. */
|
|
@@ -25,6 +25,11 @@ export interface CommandMenuOptions {
|
|
|
25
25
|
replace?: Partial<Record<StoreSectionSlot, PluginSection>>;
|
|
26
26
|
/** The plugin's legacy locks, passed to every store write the menu makes. */
|
|
27
27
|
extraLocks?: readonly PoolLockSpec[];
|
|
28
|
+
/**
|
|
29
|
+
* Where the Routing and Limits sections read and write their settings. Omit
|
|
30
|
+
* it to use the store's own settings, as before.
|
|
31
|
+
*/
|
|
32
|
+
settings?: BuiltinSettingsPort;
|
|
28
33
|
accounts?: AccountsSectionOptions;
|
|
29
34
|
quota?: QuotaSectionOptions;
|
|
30
35
|
routing?: RoutingSectionOptions;
|
|
@@ -156,6 +156,7 @@ export function createCommandMenu(options) {
|
|
|
156
156
|
store,
|
|
157
157
|
now,
|
|
158
158
|
...(options.extraLocks ? { extraLocks: options.extraLocks } : {}),
|
|
159
|
+
...(options.settings ? { settings: options.settings } : {}),
|
|
159
160
|
...(options.accounts ? { accounts: options.accounts } : {}),
|
|
160
161
|
...(options.quota ? { quota: options.quota } : {}),
|
|
161
162
|
...(options.routing ? { routing: options.routing } : {}),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { lstat, stat } from 'node:fs/promises';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
async function identity(path,
|
|
3
|
+
async function identity(path, probe) {
|
|
4
4
|
try {
|
|
5
5
|
// Match the reader: private readers reject links, while readFile follows
|
|
6
6
|
// them and needs the target's identity, not the link's identity.
|
|
7
|
-
const metadata = await (
|
|
7
|
+
const metadata = await probe(path);
|
|
8
8
|
return metadata.isFile() ? metadata : undefined;
|
|
9
9
|
}
|
|
10
10
|
catch (error) {
|
|
@@ -24,15 +24,19 @@ function sameIdentity(left, right) {
|
|
|
24
24
|
}
|
|
25
25
|
/** Process-local reads, capped at 64 path sets with one value per resolved set. */
|
|
26
26
|
export class FileReadCache {
|
|
27
|
-
#
|
|
27
|
+
#probe;
|
|
28
28
|
#entries = new Map();
|
|
29
29
|
constructor(options = {}) {
|
|
30
|
-
|
|
30
|
+
// Look the probe up on every call, not once here: tests replace the
|
|
31
|
+
// node:fs/promises functions (and SettingsFs methods) after caches exist.
|
|
32
|
+
this.#probe = options.followSymlinks
|
|
33
|
+
? (path) => (options.stat ?? stat)(path)
|
|
34
|
+
: (path) => (options.lstat ?? lstat)(path);
|
|
31
35
|
}
|
|
32
36
|
async read(paths, read, validateHit) {
|
|
33
37
|
const resolvedPaths = paths.map((path) => resolve(path));
|
|
34
38
|
const key = JSON.stringify(resolvedPaths);
|
|
35
|
-
const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#
|
|
39
|
+
const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#probe)));
|
|
36
40
|
const identities = probed.every((entry) => entry !== undefined)
|
|
37
41
|
? probed
|
|
38
42
|
: undefined;
|
|
@@ -4,6 +4,17 @@ type LeaseCreationTestHooks = {
|
|
|
4
4
|
};
|
|
5
5
|
/** Test-only creation faults; not re-exported from the public fs entry point. */
|
|
6
6
|
export declare function setLeaseCreationTestHooksForTest(hooks?: LeaseCreationTestHooks): void;
|
|
7
|
+
type StagingSweepTestHooks = {
|
|
8
|
+
readdir?: (directory: string) => Promise<string[]>;
|
|
9
|
+
beforeUnlink?: (path: string) => void | Promise<void>;
|
|
10
|
+
unlink?: (path: string) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/** Test-only sweep faults; not re-exported from the public fs entry point. */
|
|
13
|
+
export declare function setStagingSweepTestHooksForTest(hooks?: StagingSweepTestHooks): void;
|
|
14
|
+
/** Tests only: wait for every staging sweep started so far to finish. */
|
|
15
|
+
export declare function settleStagingSweepsForTest(): Promise<void>;
|
|
16
|
+
/** Tests only: let the next acquisition of every lock path sweep again. */
|
|
17
|
+
export declare function forgetStagingSweepsForTest(): void;
|
|
7
18
|
export declare function isLostMarkerRaceError(error: unknown): boolean;
|
|
8
19
|
/** Test-only fault injection between marker mkdir and owner.json write. */
|
|
9
20
|
export interface EvictionMarkerTestHooks {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { link, lstat, mkdir, open, readFile, rename, rm, stat, } from 'node:fs/promises';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
2
|
+
import { link, lstat, mkdir, open, readdir, readFile, rename, rm, stat, unlink, } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { createLogger } from '../logger/index.js';
|
|
4
5
|
import { DisappearedLockRecordError, isWindowsAccessDeniedCreate, isWindowsAccessDeniedRead, readLockRecord, } from './lock-record.js';
|
|
5
6
|
import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, isWindowsSharingViolation, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from './private-files.js';
|
|
6
7
|
import { LockOwnershipError, lockPathFor } from './with-lock.js';
|
|
@@ -91,6 +92,149 @@ async function writeExclusiveText(path, text) {
|
|
|
91
92
|
await handle.close();
|
|
92
93
|
}
|
|
93
94
|
}
|
|
95
|
+
// Lease owner records are staged in sibling files named
|
|
96
|
+
// `<lock file name>.<random UUID>.tmp` before they are linked or renamed into
|
|
97
|
+
// place: by createExclusiveText and by renewal, whose Windows branch uses
|
|
98
|
+
// writePrivateAtomic's default staging name of the same shape. Each writer
|
|
99
|
+
// removes its staging file when it finishes, but a process killed between
|
|
100
|
+
// creating the file and that cleanup leaves it behind for good, since nothing
|
|
101
|
+
// else ever reads that name. The sweep below removes only such leftovers.
|
|
102
|
+
const STAGING_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
103
|
+
// A staging file records the expiry of the lease it was about to publish,
|
|
104
|
+
// which is always in the future while its writer is alive. Requiring the
|
|
105
|
+
// expiry to be at least a lease TTL in the past, and never less than this
|
|
106
|
+
// floor, keeps a live writer's file safe even if wall clocks disagree.
|
|
107
|
+
const STAGING_SWEEP_MIN_AGE_MS = 10 * 60_000;
|
|
108
|
+
// Bounds the work one sweep does; any remainder is left for a later process.
|
|
109
|
+
const STAGING_SWEEP_MAX_CANDIDATES = 256;
|
|
110
|
+
// A complete owner record is under 100 bytes; anything far larger is not one.
|
|
111
|
+
const STAGING_SWEEP_MAX_BYTES = 4_096;
|
|
112
|
+
// Lock paths already swept by this process. Sweeping once per process keeps
|
|
113
|
+
// the directory listing off the hot path of every later acquisition.
|
|
114
|
+
const sweptLockPaths = new Set();
|
|
115
|
+
const pendingStagingSweeps = new Set();
|
|
116
|
+
let stagingSweepTestHooks;
|
|
117
|
+
/** Test-only sweep faults; not re-exported from the public fs entry point. */
|
|
118
|
+
export function setStagingSweepTestHooksForTest(hooks) {
|
|
119
|
+
stagingSweepTestHooks = hooks;
|
|
120
|
+
}
|
|
121
|
+
/** Tests only: wait for every staging sweep started so far to finish. */
|
|
122
|
+
export async function settleStagingSweepsForTest() {
|
|
123
|
+
while (pendingStagingSweeps.size > 0)
|
|
124
|
+
await Promise.all([...pendingStagingSweeps]);
|
|
125
|
+
}
|
|
126
|
+
/** Tests only: let the next acquisition of every lock path sweep again. */
|
|
127
|
+
export function forgetStagingSweepsForTest() {
|
|
128
|
+
sweptLockPaths.clear();
|
|
129
|
+
}
|
|
130
|
+
function isStagingName(name, lockName) {
|
|
131
|
+
const prefix = `${lockName}.`;
|
|
132
|
+
const suffix = '.tmp';
|
|
133
|
+
if (!name.startsWith(prefix) || !name.endsWith(suffix))
|
|
134
|
+
return false;
|
|
135
|
+
return STAGING_UUID.test(name.slice(prefix.length, -suffix.length));
|
|
136
|
+
}
|
|
137
|
+
function sameStagingFile(a, b) {
|
|
138
|
+
return (a.dev === b.dev &&
|
|
139
|
+
a.ino === b.ino &&
|
|
140
|
+
a.size === b.size &&
|
|
141
|
+
a.mtimeMs === b.mtimeMs &&
|
|
142
|
+
a.birthtimeMs === b.birthtimeMs);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Read the owner record a staging file holds, or undefined when the path is
|
|
146
|
+
* not a plain file holding exactly a complete `{ownerId, expiresAt}` record.
|
|
147
|
+
* Returns the lstat identity the record was read from, for the unlink fence.
|
|
148
|
+
*/
|
|
149
|
+
async function readStagedOwner(path) {
|
|
150
|
+
const before = await lstat(path);
|
|
151
|
+
if (!before.isFile() || before.isSymbolicLink())
|
|
152
|
+
return undefined;
|
|
153
|
+
if (before.size > STAGING_SWEEP_MAX_BYTES)
|
|
154
|
+
return undefined;
|
|
155
|
+
const handle = await open(path, 'r');
|
|
156
|
+
let text;
|
|
157
|
+
try {
|
|
158
|
+
// The path could be swapped between the lstat and the open; read only
|
|
159
|
+
// when the opened file is the one the lstat described.
|
|
160
|
+
if (!sameStagingFile(before, await handle.stat()))
|
|
161
|
+
return undefined;
|
|
162
|
+
text = await handle.readFile('utf8');
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
await handle.close();
|
|
166
|
+
}
|
|
167
|
+
let record;
|
|
168
|
+
try {
|
|
169
|
+
record = JSON.parse(text);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
if (!record || typeof record !== 'object' || Array.isArray(record))
|
|
175
|
+
return undefined;
|
|
176
|
+
const keys = Object.keys(record).sort();
|
|
177
|
+
if (keys.length !== 2 || keys[0] !== 'expiresAt' || keys[1] !== 'ownerId')
|
|
178
|
+
return undefined;
|
|
179
|
+
const { ownerId, expiresAt } = record;
|
|
180
|
+
if (typeof ownerId !== 'string' || !STAGING_UUID.test(ownerId))
|
|
181
|
+
return undefined;
|
|
182
|
+
if (typeof expiresAt !== 'number' || !Number.isFinite(expiresAt))
|
|
183
|
+
return undefined;
|
|
184
|
+
return { identity: before, expiresAt };
|
|
185
|
+
}
|
|
186
|
+
async function sweepAbandonedStaging(lockPath, ttlMs, now) {
|
|
187
|
+
const directory = dirname(lockPath);
|
|
188
|
+
const lockName = basename(lockPath);
|
|
189
|
+
const hooks = stagingSweepTestHooks;
|
|
190
|
+
const names = await (hooks?.readdir ?? readdir)(directory);
|
|
191
|
+
const candidates = names
|
|
192
|
+
.filter((name) => isStagingName(name, lockName))
|
|
193
|
+
.slice(0, STAGING_SWEEP_MAX_CANDIDATES);
|
|
194
|
+
const marginMs = Math.max(Number.isFinite(ttlMs) ? ttlMs : 0, STAGING_SWEEP_MIN_AGE_MS);
|
|
195
|
+
for (const name of candidates) {
|
|
196
|
+
const path = join(directory, name);
|
|
197
|
+
try {
|
|
198
|
+
// A file written within the margin belongs to a writer that may be
|
|
199
|
+
// alive, so don't even open it; the record's expiry still decides.
|
|
200
|
+
if (now() - (await lstat(path)).mtimeMs < marginMs)
|
|
201
|
+
continue;
|
|
202
|
+
const staged = await readStagedOwner(path);
|
|
203
|
+
if (!staged || !(staged.expiresAt < now() - marginMs))
|
|
204
|
+
continue;
|
|
205
|
+
if (hooks?.beforeUnlink)
|
|
206
|
+
await hooks.beforeUnlink(path);
|
|
207
|
+
// Remove only the file that was read: a name reused since then keeps
|
|
208
|
+
// its new contents. Inode numbers can be reused at once after an
|
|
209
|
+
// unlink, so the record is read again as well as the identity compared.
|
|
210
|
+
const current = await readStagedOwner(path);
|
|
211
|
+
if (!current ||
|
|
212
|
+
!sameStagingFile(staged.identity, current.identity) ||
|
|
213
|
+
!(current.expiresAt < now() - marginMs))
|
|
214
|
+
continue;
|
|
215
|
+
await (hooks?.unlink ?? unlink)(path);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// Each leftover is independent; a vanished or unreadable one is skipped.
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Start a background sweep of abandoned staging files beside `lockPath`, at
|
|
224
|
+
* most once per process per lock path. Called after this process acquires the
|
|
225
|
+
* lock, so no other cooperating process sweeps the same name at that moment.
|
|
226
|
+
* The sweep never delays or fails the acquisition: every error is ignored.
|
|
227
|
+
*/
|
|
228
|
+
function startStagingSweep(lockPath, ttlMs, now) {
|
|
229
|
+
if (sweptLockPaths.has(lockPath))
|
|
230
|
+
return;
|
|
231
|
+
sweptLockPaths.add(lockPath);
|
|
232
|
+
const sweep = Promise.resolve()
|
|
233
|
+
.then(() => sweepAbandonedStaging(lockPath, ttlMs, now))
|
|
234
|
+
.catch(() => { });
|
|
235
|
+
pendingStagingSweeps.add(sweep);
|
|
236
|
+
void sweep.finally(() => pendingStagingSweeps.delete(sweep));
|
|
237
|
+
}
|
|
94
238
|
const setRefreshLockRenewalTimeout = globalThis.setTimeout.bind(globalThis);
|
|
95
239
|
const clearRefreshLockRenewalTimeout = globalThis.clearTimeout.bind(globalThis);
|
|
96
240
|
// A concurrent contender renaming the freshly-created eviction-marker directory
|
|
@@ -970,6 +1114,7 @@ export async function acquireRefreshFileLockWithClock(options) {
|
|
|
970
1114
|
return null;
|
|
971
1115
|
}
|
|
972
1116
|
scheduleRenewal();
|
|
1117
|
+
startStagingSweep(lockPath, options.ttlMs, now);
|
|
973
1118
|
return {
|
|
974
1119
|
ownerId,
|
|
975
1120
|
whenLost: () => lostPromise,
|
|
@@ -1047,17 +1192,17 @@ export async function acquireRefreshFileLockWithClock(options) {
|
|
|
1047
1192
|
removalConfirmed = true;
|
|
1048
1193
|
}, deadline);
|
|
1049
1194
|
changingRecordError = undefined;
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
});
|
|
1055
|
-
releaseConfirmed = removalConfirmed;
|
|
1195
|
+
// Acquiring the marker does not confirm removal: stale-marker
|
|
1196
|
+
// recovery can take it away after the lease owner was checked.
|
|
1197
|
+
if (markerAcquired && removalConfirmed) {
|
|
1198
|
+
releaseConfirmed = true;
|
|
1056
1199
|
return;
|
|
1057
1200
|
}
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1060
|
-
|
|
1201
|
+
if (!markerAcquired) {
|
|
1202
|
+
if (signal?.aborted)
|
|
1203
|
+
return;
|
|
1204
|
+
await recoverStaleEvictionMarker(deadline);
|
|
1205
|
+
}
|
|
1061
1206
|
}
|
|
1062
1207
|
catch (error) {
|
|
1063
1208
|
const changingRecord = windowsPrivateFiles &&
|
|
@@ -1098,6 +1243,9 @@ export async function acquireRefreshFileLockWithClock(options) {
|
|
|
1098
1243
|
new PrivateFileError(lockPath, 'release-not-confirmed', {
|
|
1099
1244
|
code: 'ETIMEDOUT',
|
|
1100
1245
|
}));
|
|
1246
|
+
createLogger('fs').warn('File lock release deadline expired', {
|
|
1247
|
+
lockPath,
|
|
1248
|
+
});
|
|
1101
1249
|
},
|
|
1102
1250
|
};
|
|
1103
1251
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PrivateFileError } from './private-files.js';
|
|
1
2
|
import { acquireRefreshFileLock } from './refresh-file-lock.js';
|
|
2
3
|
export declare function lockPathFor(target: string, name: string): string;
|
|
3
4
|
export declare class LockContentionError extends Error {
|
|
@@ -32,6 +33,7 @@ export interface LockOptions {
|
|
|
32
33
|
onStep?: Parameters<typeof acquireRefreshFileLock>[0]['onStep'];
|
|
33
34
|
onRenewalTimer?: Parameters<typeof acquireRefreshFileLock>[0]['onRenewalTimer'];
|
|
34
35
|
}
|
|
36
|
+
export declare function isChangingLockRecord(error: unknown, target: string, name: string): error is PrivateFileError;
|
|
35
37
|
export declare function withLock<T>(target: string, options: LockOptions, fn: (lock: {
|
|
36
38
|
assertOwned(): Promise<void>;
|
|
37
39
|
}) => Promise<T>): Promise<T>;
|
|
@@ -21,7 +21,7 @@ export class LockOwnershipError extends Error {
|
|
|
21
21
|
this.details = details;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function isChangingLockRecord(error, target, name) {
|
|
24
|
+
export function isChangingLockRecord(error, target, name) {
|
|
25
25
|
const path = resolve(lockPathFor(target, name));
|
|
26
26
|
const paths = [path, join(path, 'owner.json')];
|
|
27
27
|
return (((isWindowsSharingViolation(error) ||
|