@cortexkit/opencode-antigravity-auth 3.0.13 → 3.0.14
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 +1865 -571
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +291 -52
- package/dist/index.js +2166 -751
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +326 -72
- package/dist/server.js +3898 -2452
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/__fixtures__/runtime-layout-process.d.ts +2 -0
- package/dist/src/__fixtures__/runtime-layout-process.d.ts.map +1 -0
- package/dist/src/__fixtures__/runtime-layout-process.js +88 -0
- package/dist/src/__fixtures__/runtime-layout-process.js.map +1 -0
- package/dist/src/cli.d.ts +17 -6
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +26 -9
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +15 -8
- package/dist/src/common-auth-embedded/claustrum/hub.js +86 -42
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +16 -3
- package/dist/src/common-auth-embedded/setup/command.js +4 -49
- package/dist/src/common-auth-embedded/setup/flags.d.ts +50 -0
- package/dist/src/common-auth-embedded/setup/flags.js +123 -0
- package/dist/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/setup/index.js +1 -0
- package/dist/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/dist/src/common-auth-embedded/source-output.json +47 -31
- package/dist/src/ga/server/auth.d.ts.map +1 -1
- package/dist/src/ga/server/auth.js +7 -2
- package/dist/src/ga/server/auth.js.map +1 -1
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +18 -4
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/plugin/__fixtures__/controlled-timeouts.d.ts +7 -0
- package/dist/src/plugin/__fixtures__/controlled-timeouts.d.ts.map +1 -0
- package/dist/src/plugin/__fixtures__/controlled-timeouts.js +41 -0
- package/dist/src/plugin/__fixtures__/controlled-timeouts.js.map +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts +2 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js +11 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -0
- package/dist/src/plugin/__fixtures__/verified-store.d.ts +3 -0
- package/dist/src/plugin/__fixtures__/verified-store.d.ts.map +1 -0
- package/dist/src/plugin/__fixtures__/verified-store.js +50 -0
- package/dist/src/plugin/__fixtures__/verified-store.js.map +1 -0
- package/dist/src/plugin/auth-loader.d.ts +7 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +4 -4
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/cache/signature-cache.d.ts +7 -1
- package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/src/plugin/cache/signature-cache.js +10 -13
- package/dist/src/plugin/cache/signature-cache.js.map +1 -1
- package/dist/src/plugin/config/loader.d.ts +2 -1
- package/dist/src/plugin/config/loader.d.ts.map +1 -1
- package/dist/src/plugin/config/loader.js +4 -2
- package/dist/src/plugin/config/loader.js.map +1 -1
- package/dist/src/plugin/config/schema.js +1 -1
- package/dist/src/plugin/debug.d.ts.map +1 -1
- package/dist/src/plugin/debug.js +18 -19
- package/dist/src/plugin/debug.js.map +1 -1
- package/dist/src/plugin/errors.js +1 -1
- package/dist/src/plugin/errors.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +50 -27
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/ga-shared-vault-custody.d.ts +19 -5
- package/dist/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/ga-shared-vault-custody.js +12 -4
- package/dist/src/plugin/ga-shared-vault-custody.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +31 -9
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/shared/source-sidebar.d.ts +6 -0
- package/dist/src/plugin/shared/source-sidebar.d.ts.map +1 -1
- package/dist/src/plugin/shared/source-sidebar.js +1 -1
- package/dist/src/plugin/shared/source-sidebar.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +5 -2
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +5 -4
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +29 -8
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +61 -10
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/process-heartbeat.d.ts +22 -2
- package/dist/src/process-heartbeat.d.ts.map +1 -1
- package/dist/src/process-heartbeat.js +47 -10
- package/dist/src/process-heartbeat.js.map +1 -1
- package/dist/src/rpc/rpc-server.d.ts +8 -0
- package/dist/src/rpc/rpc-server.d.ts.map +1 -1
- package/dist/src/rpc/rpc-server.js +26 -1
- package/dist/src/rpc/rpc-server.js.map +1 -1
- package/dist/src/runtime-layout.d.ts +100 -0
- package/dist/src/runtime-layout.d.ts.map +1 -0
- package/dist/src/runtime-layout.js +1242 -0
- package/dist/src/runtime-layout.js.map +1 -0
- package/dist/src/runtime-paths.d.ts +132 -0
- package/dist/src/runtime-paths.d.ts.map +1 -0
- package/dist/src/runtime-paths.js +214 -0
- package/dist/src/runtime-paths.js.map +1 -0
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +30 -7
- package/dist/src/setup.js.map +1 -1
- package/dist/src/vault-folder.d.ts +38 -0
- package/dist/src/vault-folder.d.ts.map +1 -0
- package/dist/src/vault-folder.js +91 -0
- package/dist/src/vault-folder.js.map +1 -0
- package/dist/src/version-fence.d.ts +54 -0
- package/dist/src/version-fence.d.ts.map +1 -0
- package/dist/src/version-fence.js +254 -0
- package/dist/src/version-fence.js.map +1 -0
- package/dist/tui-build-map.json +1 -1
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/cli.d.ts +17 -6
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/dist/types/src/common-auth-embedded/setup/flags.d.ts +50 -0
- package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/dist/types/src/ga/server/auth.d.ts.map +1 -1
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts +7 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/cache/signature-cache.d.ts +7 -1
- package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/types/src/plugin/config/loader.d.ts +2 -1
- package/dist/types/src/plugin/config/loader.d.ts.map +1 -1
- package/dist/types/src/plugin/debug.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-shared-vault-custody.d.ts +19 -5
- package/dist/types/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/source-sidebar.d.ts +6 -0
- package/dist/types/src/plugin/shared/source-sidebar.d.ts.map +1 -1
- package/dist/types/src/plugin/storage.d.ts +5 -2
- package/dist/types/src/plugin/storage.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +29 -8
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/types/src/process-heartbeat.d.ts +22 -2
- package/dist/types/src/process-heartbeat.d.ts.map +1 -1
- package/dist/types/src/rpc/rpc-server.d.ts +8 -0
- package/dist/types/src/rpc/rpc-server.d.ts.map +1 -1
- package/dist/types/src/runtime-layout.d.ts +100 -0
- package/dist/types/src/runtime-layout.d.ts.map +1 -0
- package/dist/types/src/runtime-paths.d.ts +132 -0
- package/dist/types/src/runtime-paths.d.ts.map +1 -0
- package/dist/types/src/setup.d.ts.map +1 -1
- package/dist/types/src/vault-folder.d.ts +38 -0
- package/dist/types/src/vault-folder.d.ts.map +1 -0
- package/dist/types/src/version-fence.d.ts +54 -0
- package/dist/types/src/version-fence.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/src/common-auth-embedded/claustrum/enrollment.js +15 -8
- package/src/common-auth-embedded/claustrum/hub.js +86 -42
- package/src/common-auth-embedded/fs/refresh-file-lock.js +16 -3
- package/src/common-auth-embedded/setup/command.js +4 -49
- package/src/common-auth-embedded/setup/flags.d.ts +50 -0
- package/src/common-auth-embedded/setup/flags.js +123 -0
- package/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/src/common-auth-embedded/setup/index.js +1 -0
- package/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/src/common-auth-embedded/source-output.json +47 -31
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type RuntimeLayout } from './runtime-paths.js';
|
|
2
|
+
import { type VersionFenceResult } from './version-fence.js';
|
|
3
|
+
export type { RuntimeLayout };
|
|
4
|
+
/** Name of the lock held while a process decides or moves the layout. */
|
|
5
|
+
export declare const RUNTIME_LAYOUT_LOCK_NAME = "runtime-layout";
|
|
6
|
+
/** Lists the copies an unfinished move has put in the state-home folder. */
|
|
7
|
+
export declare const RUNTIME_LAYOUT_MANIFEST_FILE = "layout-moving.json";
|
|
8
|
+
/**
|
|
9
|
+
* The enrollment state file. A move leaves it in the old folder when it keeps
|
|
10
|
+
* the host in vault mode without its token (approved, or blocked because the
|
|
11
|
+
* token is missing).
|
|
12
|
+
*/
|
|
13
|
+
export declare const VAULT_ENROLLMENT_STATE_FILE = "opencode-enrollment-state.json";
|
|
14
|
+
/**
|
|
15
|
+
* The vault files that move, and the only ones the move ever reads, copies,
|
|
16
|
+
* compares or removes in either vault folder. Anything else there (Pi's
|
|
17
|
+
* files, when Pi's account file points into OpenCode's config folder, or a
|
|
18
|
+
* file a later library version adds) is left alone; a new vault file has to
|
|
19
|
+
* be added here on purpose.
|
|
20
|
+
*/
|
|
21
|
+
export declare const VAULT_FILE_NAMES: readonly ["opencode-enrollment.json", "opencode-enrollment-state.json", "opencode-roster.json", "opencode-state.json", "opencode-mode.json"];
|
|
22
|
+
/** The message logged once by a process that keeps the legacy layout. */
|
|
23
|
+
export declare const RUNTIME_LAYOUT_DEFERRED_MESSAGE = "antigravity-auth keeps its vault files in OpenCode's config folder until every running OpenCode using it has restarted on this version.";
|
|
24
|
+
/**
|
|
25
|
+
* Plugin start stops when it cannot settle a safe layout: it could not take
|
|
26
|
+
* the layout lock or write its heartbeat (so other processes could not see
|
|
27
|
+
* which files it uses), could not trust the marker, found conflicting vault
|
|
28
|
+
* files, or found a state-home folder owned by another config folder.
|
|
29
|
+
*/
|
|
30
|
+
export declare class RuntimeLayoutRefusal extends Error {
|
|
31
|
+
readonly stateDir: string;
|
|
32
|
+
readonly errorClass: string;
|
|
33
|
+
constructor(stateDir: string, errorClass: string, message?: string);
|
|
34
|
+
}
|
|
35
|
+
export interface RuntimeLayoutLogger {
|
|
36
|
+
info(message: string, meta?: Record<string, unknown>): unknown;
|
|
37
|
+
warn(message: string, meta?: Record<string, unknown>): unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface RuntimeLayoutOptions {
|
|
40
|
+
/** This build's version, for the version fence. */
|
|
41
|
+
version: string;
|
|
42
|
+
log?: RuntimeLayoutLogger;
|
|
43
|
+
/**
|
|
44
|
+
* The account file a legacy-layout process of this config folder uses;
|
|
45
|
+
* the old vault folder is beside it. Defaults to `legacyAccountFile()`.
|
|
46
|
+
*/
|
|
47
|
+
accountFile?: string;
|
|
48
|
+
/** Defaults to `versionFenceOpen` for `version`, with the layout checks. */
|
|
49
|
+
fence?: () => Promise<VersionFenceResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Whether an existing destination vault folder may be written into.
|
|
52
|
+
* Defaults to the private-files check on Windows (a folder this module did
|
|
53
|
+
* not create is never repaired) and to true elsewhere, where the move sets
|
|
54
|
+
* the folder to 0700 itself.
|
|
55
|
+
*/
|
|
56
|
+
destinationPrivate?: (dir: string) => Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Test seams, run at one step of the move. A step that throws stands in for
|
|
59
|
+
* a crash there: nothing after it runs.
|
|
60
|
+
*/
|
|
61
|
+
steps?: {
|
|
62
|
+
afterManifest?: () => void | Promise<void>;
|
|
63
|
+
afterCopy?: () => void | Promise<void>;
|
|
64
|
+
afterMarker?: () => void | Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Runs right before each removal of an old file, of the move's
|
|
67
|
+
* `layout-moving.json` and of the old vault folder, ahead of the lease
|
|
68
|
+
* check that guards it.
|
|
69
|
+
*/
|
|
70
|
+
beforeRemove?: (path: string) => void | Promise<void>;
|
|
71
|
+
};
|
|
72
|
+
/** Test seam: how long to wait for the layout lock. */
|
|
73
|
+
layoutLockWaitMs?: number;
|
|
74
|
+
/**
|
|
75
|
+
* The signature cache file older versions wrote in OpenCode's config
|
|
76
|
+
* folder. Defaults to `legacySignatureCacheFile()`.
|
|
77
|
+
*/
|
|
78
|
+
oldSignatureCacheFile?: string;
|
|
79
|
+
}
|
|
80
|
+
/** Test seam: forget this process's runs and log lines. */
|
|
81
|
+
export declare function __resetRuntimeLayoutRunsForTest(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Decide, once per process, where this config folder's vault files live,
|
|
84
|
+
* moving them first when that is safe. Call at plugin start before anything
|
|
85
|
+
* resolves a vault path. Resolves to the layout `getVaultDir()` in
|
|
86
|
+
* `runtime-paths.ts` now uses; rejects with `RuntimeLayoutRefusal` when the
|
|
87
|
+
* plugin must not start.
|
|
88
|
+
*/
|
|
89
|
+
export declare function prepareRuntimeLayout(options: RuntimeLayoutOptions): Promise<RuntimeLayout>;
|
|
90
|
+
/**
|
|
91
|
+
* After Disconnect, remove the enrollment state file a move left in the old
|
|
92
|
+
* vault folder, so an older version no longer reads this host as enrolled.
|
|
93
|
+
* Acts only for this config folder's state-home vault folder (`vaultDir`), and
|
|
94
|
+
* only on a vault-shaped leftover of this plugin's enrollment
|
|
95
|
+
* (`isVaultShapedKeptState`); any other file there stays. The emptied old
|
|
96
|
+
* vault folder goes too. `accountFile` is the one the move was given
|
|
97
|
+
* (`RuntimeLayoutOptions.accountFile`).
|
|
98
|
+
*/
|
|
99
|
+
export declare function removeMovedVaultStateLeftover(vaultDir: string, accountFile?: string): Promise<void>;
|
|
100
|
+
//# sourceMappingURL=runtime-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-layout.d.ts","sourceRoot":"","sources":["../../../src/runtime-layout.ts"],"names":[],"mappings":"AAqHA,OAAO,EAOL,KAAK,aAAa,EAKnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,kBAAkB,EAAoB,MAAM,iBAAiB,CAAA;AAE3E,YAAY,EAAE,aAAa,EAAE,CAAA;AAM7B,yEAAyE;AACzE,eAAO,MAAM,wBAAwB,mBAAmB,CAAA;AACxD,4EAA4E;AAC5E,eAAO,MAAM,4BAA4B,uBAAuB,CAAA;AAEhE;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,mCAAmC,CAAA;AAK3E;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,8IAMnB,CAAA;AA8CV,yEAAyE;AACzE,eAAO,MAAM,+BAA+B,4IAC+F,CAAA;AAE3I;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM;gBADlB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAC3B,OAAO,SAAuC;CAKjD;AAiDD,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAA;IAC9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAA;CAC/D;AAED,MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,mBAAmB,CAAA;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACzC;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACtD;;;OAGG;IACH,KAAK,CAAC,EAAE;QACN,aAAa,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QAC1C,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QACtC,WAAW,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QACxC;;;;WAIG;QACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KACtD,CAAA;IACD,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AA4CD,2DAA2D;AAC3D,wBAAgB,+BAA+B,IAAI,IAAI,CAGtD;AAsED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,aAAa,CAAC,CAmBxB;AAynBD;;;;;;;;GAQG;AACH,wBAAsB,6BAA6B,CACjD,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAmBf"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the plugin's vault folder lives for one OpenCode config folder, and
|
|
3
|
+
* the per-process decision about it.
|
|
4
|
+
*
|
|
5
|
+
* The vault folder (`antigravity-auth-vault/`: the enrollment token and
|
|
6
|
+
* state, the vault roster, the vault provider state and the mode file) lives
|
|
7
|
+
* in one of two places:
|
|
8
|
+
* - the legacy layout: beside the account file, in OpenCode's config folder,
|
|
9
|
+
* where versions before the move kept it;
|
|
10
|
+
* - the state-home layout: `<state home>/cortexkit/antigravity-auth/opencode/`
|
|
11
|
+
* for the config folder `<home>/.config/opencode`, and
|
|
12
|
+
* `<state home>/cortexkit/antigravity-auth/opencode-<hash>/` for any other
|
|
13
|
+
* one, so two config folders never share a file.
|
|
14
|
+
* `runtime-layout.ts` decides which one, once per process, and moves the
|
|
15
|
+
* files once; until a process has decided, the layout marker alone tells.
|
|
16
|
+
*
|
|
17
|
+
* The account store (`antigravity-accounts.json`, its pointer and its
|
|
18
|
+
* generation folders) stays in OpenCode's config folder in both layouts: it
|
|
19
|
+
* records its own absolute paths and refuses to open anywhere else.
|
|
20
|
+
*
|
|
21
|
+
* So `state-home` in a heartbeat's `layouts` means "vault in the state home,
|
|
22
|
+
* account store in the config folder". A later release that moves the account
|
|
23
|
+
* store must not read a `state-home` heartbeat as "this process no longer
|
|
24
|
+
* uses the config folder": it has to fence on version (every live process at
|
|
25
|
+
* that release or newer), not on this layout value.
|
|
26
|
+
*/
|
|
27
|
+
/** In the state-home folder: present once that folder is authoritative. */
|
|
28
|
+
export declare const RUNTIME_LAYOUT_MARKER_FILE = "layout.json";
|
|
29
|
+
/** In every state-home runtime folder: names the config folder it belongs to. */
|
|
30
|
+
export declare const RUNTIME_CONFIG_DIR_NOTE_FILE = "config-dir.json";
|
|
31
|
+
/**
|
|
32
|
+
* The vault folder's name in both layouts. The same value as
|
|
33
|
+
* `OPENCODE_VAULT_DIR_NAME` in `plugin/vault-custody.ts`; kept here so this
|
|
34
|
+
* module does not load the vault code.
|
|
35
|
+
*/
|
|
36
|
+
export declare const VAULT_DIR_NAME = "antigravity-auth-vault";
|
|
37
|
+
/** The account file's name in OpenCode's config folder. */
|
|
38
|
+
export declare const ACCOUNT_FILE_NAME = "antigravity-accounts.json";
|
|
39
|
+
/**
|
|
40
|
+
* A config folder's identity: its real path as the file system spells it
|
|
41
|
+
* (symlinks resolved, on-disk case), or the resolved path when the folder
|
|
42
|
+
* does not exist. Nothing else is normalized: case folding would merge two
|
|
43
|
+
* distinct folders on a case-sensitive volume. This is the same string
|
|
44
|
+
* `processConfigFolderKey()` in `process-heartbeat.ts` writes, so a key
|
|
45
|
+
* recorded by 3.0.13 names the same folder.
|
|
46
|
+
*/
|
|
47
|
+
export declare function configDirIdentity(path: string): string;
|
|
48
|
+
/** Both places a config folder's vault folder can live in. */
|
|
49
|
+
export interface RuntimeLayoutLocation {
|
|
50
|
+
/** The config folder's identity (`configDirIdentity`). */
|
|
51
|
+
key: string;
|
|
52
|
+
/** OpenCode's config folder, as `getConfigDir()` returns it. */
|
|
53
|
+
configDir: string;
|
|
54
|
+
/** The state-home runtime folder for this config folder. */
|
|
55
|
+
stateHomeDir: string;
|
|
56
|
+
/** True when the config folder is `<home>/.config/opencode`. */
|
|
57
|
+
isDefaultConfigDir: boolean;
|
|
58
|
+
}
|
|
59
|
+
export type RuntimeLayout = 'legacy' | 'state-home';
|
|
60
|
+
/**
|
|
61
|
+
* Where this config folder's vault folder lives in the state home. Only the
|
|
62
|
+
* folder `<home>/.config/opencode` gets the plain `opencode/` folder; that is
|
|
63
|
+
* decided from the home directory, not from XDG_CONFIG_HOME, so two
|
|
64
|
+
* processes with different XDG_CONFIG_HOME values never share one. Every
|
|
65
|
+
* other config folder gets `opencode-<first 16 hex of sha256(identity)>/`.
|
|
66
|
+
*
|
|
67
|
+
* `configDir` defaults to `getConfigDir()` from `plugin/storage.ts`, used
|
|
68
|
+
* untrimmed, exactly as the account file and the 3.0.13 heartbeat use it.
|
|
69
|
+
*/
|
|
70
|
+
export declare function runtimeLayoutLocation(configDir?: string): RuntimeLayoutLocation;
|
|
71
|
+
/**
|
|
72
|
+
* Fix this process's layout for a config folder. Only `runtime-layout.ts`
|
|
73
|
+
* calls this, once per folder, while it holds the layout lock.
|
|
74
|
+
*/
|
|
75
|
+
export declare function setRuntimeLayout(location: RuntimeLayoutLocation, layout: RuntimeLayout): void;
|
|
76
|
+
/** The layout this process fixed for a config folder, if any. */
|
|
77
|
+
export declare function decidedRuntimeLayout(location: RuntimeLayoutLocation): RuntimeLayout | undefined;
|
|
78
|
+
/** Test seam: forget every decided layout and cached location. */
|
|
79
|
+
export declare function __resetRuntimeLayoutsForTest(): void;
|
|
80
|
+
/**
|
|
81
|
+
* The layout a config folder's vault folder is in for this process: the one
|
|
82
|
+
* it decided, or, for a process that never decided (a tool that never
|
|
83
|
+
* started the plugin), the marker read without taking any lock: the
|
|
84
|
+
* state-home layout once the state-home folder holds the marker, the legacy
|
|
85
|
+
* layout until then.
|
|
86
|
+
*/
|
|
87
|
+
export declare function currentRuntimeLayout(location?: RuntimeLayoutLocation): RuntimeLayout;
|
|
88
|
+
/**
|
|
89
|
+
* The plugin's own folder in the state home,
|
|
90
|
+
* `<state home>/cortexkit/antigravity-auth`, on every OS. It holds the
|
|
91
|
+
* per-config-folder runtime folders, the signature cache and the default
|
|
92
|
+
* debug log folder.
|
|
93
|
+
*/
|
|
94
|
+
export declare function pluginStateDir(): string;
|
|
95
|
+
/** The signature cache file's name, in both its old and its new folder. */
|
|
96
|
+
export declare const SIGNATURE_CACHE_FILE_NAME = "antigravity-signature-cache.json";
|
|
97
|
+
/**
|
|
98
|
+
* Where the signature cache lives by default: one file in the plugin's state
|
|
99
|
+
* folder, shared by every config folder OpenCode uses.
|
|
100
|
+
*/
|
|
101
|
+
export declare function stateHomeSignatureCacheFile(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Where versions before the move kept the signature cache: `%APPDATA%\opencode`
|
|
104
|
+
* on Windows, `$XDG_CONFIG_HOME/opencode` or `~/.config/opencode` elsewhere.
|
|
105
|
+
* That folder never followed OPENCODE_CONFIG_DIR. Nothing writes this file
|
|
106
|
+
* any more; the move removes it once (`runtime-layout.ts`).
|
|
107
|
+
*/
|
|
108
|
+
export declare function legacySignatureCacheFile(): string;
|
|
109
|
+
/**
|
|
110
|
+
* The default debug log folder, used when neither OPENCODE_ANTIGRAVITY_LOG_DIR
|
|
111
|
+
* nor the `log_dir` setting names one.
|
|
112
|
+
*/
|
|
113
|
+
export declare function stateHomeLogsDir(): string;
|
|
114
|
+
/**
|
|
115
|
+
* The account file a legacy-layout process uses for this config folder,
|
|
116
|
+
* without changing anything on disk: `<config>/antigravity-accounts.json`,
|
|
117
|
+
* except on Windows when that file is missing and one exists in
|
|
118
|
+
* `%APPDATA%\opencode`. This is the choice `getStoragePath()` in
|
|
119
|
+
* `plugin/storage.ts` makes, minus its attempt to move the Windows file.
|
|
120
|
+
*/
|
|
121
|
+
export declare function legacyAccountFile(configDir?: string): string;
|
|
122
|
+
/** The vault folder of the legacy layout: beside the account file. */
|
|
123
|
+
export declare function legacyVaultDir(accountFile: string): string;
|
|
124
|
+
/** The vault folder of the state-home layout for one config folder. */
|
|
125
|
+
export declare function stateHomeVaultDir(location: RuntimeLayoutLocation): string;
|
|
126
|
+
/**
|
|
127
|
+
* The folder holding this config folder's vault files, for this process:
|
|
128
|
+
* the state-home vault folder in the state-home layout, and the folder beside
|
|
129
|
+
* `accountFile` in the legacy layout.
|
|
130
|
+
*/
|
|
131
|
+
export declare function getVaultDir(accountFile?: string, configDir?: string): string;
|
|
132
|
+
//# sourceMappingURL=runtime-paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-paths.d.ts","sourceRoot":"","sources":["../../../src/runtime-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AASH,2EAA2E;AAC3E,eAAO,MAAM,0BAA0B,gBAAgB,CAAA;AACvD,iFAAiF;AACjF,eAAO,MAAM,4BAA4B,oBAAoB,CAAA;AAC7D;;;;GAIG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAA;AACtD,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB,8BAA8B,CAAA;AAE5D;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAA;IACX,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,YAAY,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,kBAAkB,EAAE,OAAO,CAAA;CAC5B;AAED,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,YAAY,CAAA;AAuBnD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,GAAE,MAAuB,GACjC,qBAAqB,CA0BvB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,aAAa,GACpB,IAAI,CAEN;AAED,iEAAiE;AACjE,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,qBAAqB,GAC9B,aAAa,GAAG,SAAS,CAE3B;AAED,kEAAkE;AAClE,wBAAgB,4BAA4B,IAAI,IAAI,CAGnD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,GAAE,qBAA+C,GACxD,aAAa,CAOf;AAUD;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,2EAA2E;AAC3E,eAAO,MAAM,yBAAyB,qCAAqC,CAAA;AAE3E;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CASjD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,GAAE,MAAuB,GAAG,MAAM,CAK5E;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,WAAW,CAAC,EAAE,MAAM,EACpB,SAAS,GAAE,MAAuB,GACjC,MAAM,CAKR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/setup.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAIL,KAAK,oBAAoB,EAEzB,KAAK,OAAO,EACZ,KAAK,WAAW,EACjB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/setup.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAIL,KAAK,oBAAoB,EAEzB,KAAK,OAAO,EACZ,KAAK,WAAW,EACjB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAA;AA0D9E;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,oBAAoB,CAAC,oBAAoB,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7D;AA4CD,2EAA2E;AAC3E,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,+BAA+B,EACvC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAWf;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,eAAe,EACrB,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACtC,UAAU,UAAQ,GACjB,OAAO,CAAC,WAAW,CAAC,CAwStB;AAED,2FAA2F;AAC3F,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,eAAe,EACrB,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACtC,EAAE,GAAE,OAAY,GACf,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type RuntimeLayoutLogger, RuntimeLayoutRefusal } from './runtime-layout.js';
|
|
2
|
+
/** The vault folder an entry point uses, or why it has none. */
|
|
3
|
+
export interface VaultFolder {
|
|
4
|
+
/** The account file the folder was settled against (`getStoragePath()`). */
|
|
5
|
+
readonly accountFile: string;
|
|
6
|
+
/**
|
|
7
|
+
* The folder holding the vault files for this process. With a refusal it
|
|
8
|
+
* is only where the files would be read from without a decision; nothing
|
|
9
|
+
* may read or write it.
|
|
10
|
+
*/
|
|
11
|
+
readonly vaultDir: string;
|
|
12
|
+
/** Set when the start could not settle where the vault files live. */
|
|
13
|
+
readonly refusal?: RuntimeLayoutRefusal;
|
|
14
|
+
}
|
|
15
|
+
/** Test seam: forget every refusal this process kept. */
|
|
16
|
+
export declare function __resetVaultFoldersForTest(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Settle this process's vault folder for the config folder `accountFile`
|
|
19
|
+
* belongs to, moving the vault files first when that is safe. Resolves with
|
|
20
|
+
* the refusal rather than rejecting when the layout cannot be settled.
|
|
21
|
+
* `version` defaults to this package's own version (`unknown` when its
|
|
22
|
+
* manifest cannot be read, which other processes' version checks treat as
|
|
23
|
+
* blocking).
|
|
24
|
+
*/
|
|
25
|
+
export declare function prepareVaultFolder(options: {
|
|
26
|
+
accountFile: string;
|
|
27
|
+
version?: string;
|
|
28
|
+
log?: RuntimeLayoutLogger;
|
|
29
|
+
/** Test seam: how long to wait for the layout lock. */
|
|
30
|
+
layoutLockWaitMs?: number;
|
|
31
|
+
}): Promise<VaultFolder>;
|
|
32
|
+
/**
|
|
33
|
+
* The vault folder for code that runs after its entry point prepared: the
|
|
34
|
+
* kept refusal, or the folder of the decided layout. A process that never
|
|
35
|
+
* prepared follows the layout marker without taking a lock.
|
|
36
|
+
*/
|
|
37
|
+
export declare function currentVaultFolder(accountFile: string): VaultFolder;
|
|
38
|
+
//# sourceMappingURL=vault-folder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault-folder.d.ts","sourceRoot":"","sources":["../../../src/vault-folder.ts"],"names":[],"mappings":"AAoBA,OAAO,EAEL,KAAK,mBAAmB,EACxB,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AAGzB,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,sEAAsE;IACtE,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAA;CACxC;AAmBD,yDAAyD;AACzD,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,mBAAmB,CAAA;IACzB,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,GAAG,OAAO,CAAC,WAAW,CAAC,CAmCvB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,CAKnE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** One live process that keeps the fence shut. */
|
|
2
|
+
export interface VersionFenceBlocker {
|
|
3
|
+
/** `'unknown'` when a whole directory could not be read. */
|
|
4
|
+
pid: number | 'unknown';
|
|
5
|
+
/** The version its heartbeat or port file names, or `'unknown'`. */
|
|
6
|
+
version: string;
|
|
7
|
+
/** The file or directory that showed it. */
|
|
8
|
+
detail: string;
|
|
9
|
+
}
|
|
10
|
+
export type VersionFenceResult = {
|
|
11
|
+
open: true;
|
|
12
|
+
} | {
|
|
13
|
+
open: false;
|
|
14
|
+
blockers: VersionFenceBlocker[];
|
|
15
|
+
};
|
|
16
|
+
export interface VersionFenceOptions {
|
|
17
|
+
/** The XDG state base; defaults to `$XDG_STATE_HOME` or `~/.local/state`. */
|
|
18
|
+
stateHome?: string;
|
|
19
|
+
/** Root holding the per-project RPC directories; defaults under the base. */
|
|
20
|
+
rpcDir?: string;
|
|
21
|
+
/** The version that wants to act. */
|
|
22
|
+
currentVersion: string;
|
|
23
|
+
isAlive?: (pid: number) => boolean;
|
|
24
|
+
/** This process, which never blocks itself. Defaults to `process.pid`. */
|
|
25
|
+
selfPid?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Set when the vault files are about to move: a live process that uses the
|
|
28
|
+
* legacy layout for any config folder, or that writes no layouts at all,
|
|
29
|
+
* also keeps the fence shut.
|
|
30
|
+
*/
|
|
31
|
+
layoutMove?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The XDG state base every state-home file of the plugin lives under:
|
|
35
|
+
* `$XDG_STATE_HOME`, else `~/.local/state`, on every OS. An empty
|
|
36
|
+
* XDG_STATE_HOME counts as unset, as it does for the heartbeat.
|
|
37
|
+
*/
|
|
38
|
+
export declare function defaultStateHome(): string;
|
|
39
|
+
/** Where a plugin process writes its heartbeat, `<pid>.json`. */
|
|
40
|
+
export declare function processHeartbeatDir(stateHome?: string): string;
|
|
41
|
+
/** The root of the plugin's per-project RPC directories. */
|
|
42
|
+
export declare function rpcStateRoot(stateHome?: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Semver precedence of `a` against `b` (negative, zero, positive), or
|
|
45
|
+
* undefined when either is not a version. A pre-release sorts below its
|
|
46
|
+
* release; build metadata is ignored.
|
|
47
|
+
*/
|
|
48
|
+
export declare function compareVersions(a: string, b: string): number | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Whether no other live process keeps the fence shut. Never throws: anything
|
|
51
|
+
* it cannot establish counts as a blocker.
|
|
52
|
+
*/
|
|
53
|
+
export declare function versionFenceOpen(options: VersionFenceOptions): Promise<VersionFenceResult>;
|
|
54
|
+
//# sourceMappingURL=version-fence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-fence.d.ts","sourceRoot":"","sources":["../../../src/version-fence.ts"],"names":[],"mappings":"AAoCA,kDAAkD;AAClD,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IACvB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAA;IACf,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,mBAAmB,EAAE,CAAA;CAAE,CAAA;AAEpD,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qCAAqC;IACrC,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;IAClC,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,CAAC,SAAS,SAAqB,GAAG,MAAM,CAE1E;AAED,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,SAAS,SAAqB,GAAG,MAAM,CAEnE;AA+BD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA2BxE;AA0DD;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAwF7B"}
|
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.14",
|
|
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",
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"dependencies": {
|
|
131
131
|
"@cortexkit/claustrum-client": "0.12.0",
|
|
132
132
|
"@cortexkit/subc-client": "0.22.5",
|
|
133
|
-
"@cortexkit/antigravity-auth-core": "3.0.
|
|
133
|
+
"@cortexkit/antigravity-auth-core": "3.0.14",
|
|
134
134
|
"@cortexkit/private-files": "0.2.1",
|
|
135
135
|
"jsonc-parser": "^3.3.1",
|
|
136
136
|
"xdg-basedir": "^5.1.0",
|
|
@@ -107,6 +107,15 @@ export interface EnrollmentAncestorOptions {
|
|
|
107
107
|
* sticky ancestors are accepted. Windows uses the shared safe-parent policy.
|
|
108
108
|
*/
|
|
109
109
|
export declare function refuseWritableAncestor(parent: string, options?: EnrollmentAncestorOptions): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Create `directory` owner-only, or make an existing one owner-only. POSIX:
|
|
112
|
+
* every component it creates gets mode 0700, a directory another user owns is
|
|
113
|
+
* refused, and one that group or others can reach is tightened to 0700.
|
|
114
|
+
* Windows: private-files creates missing components owner-only and verifies
|
|
115
|
+
* existing ones without modifying them. `what` names the directory in the
|
|
116
|
+
* ownership refusal.
|
|
117
|
+
*/
|
|
118
|
+
export declare function ensureClaustrumPrivateDirectory(directory: string, options?: EnrollmentAncestorOptions, what?: string): Promise<void>;
|
|
110
119
|
export declare function readClaustrumEnrollmentStatus(paths: ClaustrumEnrollmentPaths, proposedName: string): Promise<ClaustrumEnrollmentStatus>;
|
|
111
120
|
/**
|
|
112
121
|
* Resolve the host's account mode from its enrollment files. It never changes
|
|
@@ -358,8 +358,15 @@ export async function refuseWritableAncestor(parent, options = {}) {
|
|
|
358
358
|
throw new ClaustrumConsumerError('unsafe-file', `Claustrum enrollment parent refused: ${error.path} (${error.reason ?? error.code}). Use a folder that other users cannot write or replace.`);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
/**
|
|
362
|
-
|
|
361
|
+
/**
|
|
362
|
+
* Create `directory` owner-only, or make an existing one owner-only. POSIX:
|
|
363
|
+
* every component it creates gets mode 0700, a directory another user owns is
|
|
364
|
+
* refused, and one that group or others can reach is tightened to 0700.
|
|
365
|
+
* Windows: private-files creates missing components owner-only and verifies
|
|
366
|
+
* existing ones without modifying them. `what` names the directory in the
|
|
367
|
+
* ownership refusal.
|
|
368
|
+
*/
|
|
369
|
+
export async function ensureClaustrumPrivateDirectory(directory, options = {}, what = 'enrollment directory') {
|
|
363
370
|
if (windowsPrivateFiles) {
|
|
364
371
|
await ensureWindowsDirectory(directory, false, ancestorPolicyOptions(options));
|
|
365
372
|
return;
|
|
@@ -368,14 +375,14 @@ async function ensurePrivateDirectory(directory, options = {}) {
|
|
|
368
375
|
const metadata = await stat(directory);
|
|
369
376
|
const uid = process.geteuid?.();
|
|
370
377
|
if (uid !== undefined && metadata.uid !== uid) {
|
|
371
|
-
throw new ClaustrumConsumerError('unsafe-file',
|
|
378
|
+
throw new ClaustrumConsumerError('unsafe-file', `Claustrum ${what} must be owned by the current user`);
|
|
372
379
|
}
|
|
373
380
|
if ((metadata.mode & 0o077) !== 0)
|
|
374
381
|
await chmod(directory, 0o700);
|
|
375
382
|
}
|
|
376
383
|
async function writeStateAtomic(path, state, ancestorOptions = {}) {
|
|
377
384
|
const parent = dirname(path);
|
|
378
|
-
await
|
|
385
|
+
await ensureClaustrumPrivateDirectory(parent, ancestorOptions);
|
|
379
386
|
await refuseWritableAncestor(parent, ancestorOptions);
|
|
380
387
|
const bytes = `${JSON.stringify(state)}\n`;
|
|
381
388
|
if (Buffer.byteLength(bytes) > ENROLLMENT_FILE_MAX_BYTES) {
|
|
@@ -578,7 +585,7 @@ export class ClaustrumEnrollmentManager {
|
|
|
578
585
|
return statusFromState(blocked);
|
|
579
586
|
}
|
|
580
587
|
async reconcile() {
|
|
581
|
-
await
|
|
588
|
+
await ensureClaustrumPrivateDirectory(dirname(this.#paths.statePath), this.#ancestorOptions);
|
|
582
589
|
const lock = await acquireRefreshFileLock({
|
|
583
590
|
name: 'ceremony',
|
|
584
591
|
path: this.#paths.statePath,
|
|
@@ -715,7 +722,7 @@ export class ClaustrumEnrollmentManager {
|
|
|
715
722
|
}
|
|
716
723
|
// The vault returns the token exactly once: it reaches disk before the
|
|
717
724
|
// pending metadata (and its secret) is replaced.
|
|
718
|
-
await
|
|
725
|
+
await ensureClaustrumPrivateDirectory(dirname(this.#paths.tokenPath), this.#ancestorOptions);
|
|
719
726
|
await refuseWritableAncestor(dirname(this.#paths.tokenPath), this.#ancestorOptions);
|
|
720
727
|
await this.#writeTokenFile(this.#paths.tokenPath, {
|
|
721
728
|
token: outcome.token,
|
|
@@ -754,7 +761,7 @@ export class ClaustrumEnrollmentManager {
|
|
|
754
761
|
}
|
|
755
762
|
/** Reset local terminal metadata without connecting to the credential daemon. */
|
|
756
763
|
export async function resetClaustrumEnrollmentState(paths, proposedName) {
|
|
757
|
-
await
|
|
764
|
+
await ensureClaustrumPrivateDirectory(dirname(paths.statePath));
|
|
758
765
|
const lock = await acquireRefreshFileLock({
|
|
759
766
|
name: 'ceremony',
|
|
760
767
|
path: paths.statePath,
|
|
@@ -817,7 +824,7 @@ async function removeIfPresent(path) {
|
|
|
817
824
|
* wrong owner, not owner-only) refuses with `unsafe-file` and both files stay.
|
|
818
825
|
*/
|
|
819
826
|
export async function disconnectClaustrumEnrollment(paths, proposedName) {
|
|
820
|
-
await
|
|
827
|
+
await ensureClaustrumPrivateDirectory(dirname(paths.statePath));
|
|
821
828
|
const lock = await acquireRefreshFileLock({
|
|
822
829
|
// The same lock as the ceremony, so a token written by a concurrent
|
|
823
830
|
// reconcile() can never land after this removes the files.
|
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
// never replaces a view another process committed after this hub listed.
|
|
13
13
|
import { createHash } from 'node:crypto';
|
|
14
14
|
import { readdir, stat } from 'node:fs/promises';
|
|
15
|
-
import { join } from 'node:path';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
16
|
import { createLogger } from '../logger/index.js';
|
|
17
17
|
import { combineAbortSignals } from '../util/any-signal.js';
|
|
18
18
|
import { ClaustrumUnreachableError } from './availability.js';
|
|
19
19
|
import { createHubMember, DEFAULT_CONNECT_TIMEOUT_MS, } from './consumer.js';
|
|
20
20
|
import { ClaustrumScopedCustody, } from './custody.js';
|
|
21
|
+
import { ensureClaustrumPrivateDirectory } from './enrollment.js';
|
|
21
22
|
import { ClaustrumConsumerError } from './errors.js';
|
|
22
23
|
import { DEFAULT_ROUTE_PREFIX, decodedVaultRoster, forgetPendingVaultDiscovery, isVaultRosterLockRefusal, readVaultRoster, refreshVaultRoster, vaultRosterSeed, } from './roster.js';
|
|
23
24
|
import { drainShutdown, shutdownWarning } from './shutdown.js';
|
|
@@ -585,10 +586,11 @@ export class ClaustrumDiscoveryHub {
|
|
|
585
586
|
}
|
|
586
587
|
/**
|
|
587
588
|
* Read each member's base view, list once, then commit each member's share
|
|
588
|
-
* of the listing to its roster
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
589
|
+
* of the listing to its roster (all members at once, each under its own
|
|
590
|
+
* roster's locks), push it into the member, and retain the union. Each
|
|
591
|
+
* publication step checks first that the generation it started in is
|
|
592
|
+
* still current. A member that this list did not commit is marked pending,
|
|
593
|
+
* so a later tick lists again.
|
|
592
594
|
*/
|
|
593
595
|
async #discover(run) {
|
|
594
596
|
if (!(await this.#readAuthority()))
|
|
@@ -598,12 +600,17 @@ export class ClaustrumDiscoveryHub {
|
|
|
598
600
|
run.generation = generation;
|
|
599
601
|
if (!this.#live(generation))
|
|
600
602
|
return undefined;
|
|
603
|
+
// Folders that could not be made owner-only fail every member's commit,
|
|
604
|
+
// as an unreadable base fails its member's: each is marked pending.
|
|
605
|
+
const folders = await this.#ensureRosterDirectories().then(() => undefined, (error) => error instanceof Error ? error : new Error(String(error)));
|
|
601
606
|
// What each member's file held before the list. Another process may
|
|
602
607
|
// commit while this list runs; the base-view rule then keeps its newer
|
|
603
|
-
// roster rather than replacing it with this older listing.
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
608
|
+
// roster rather than replacing it with this older listing. Each file is
|
|
609
|
+
// read on its own, so the reads run together.
|
|
610
|
+
const bases = new Map(await Promise.all([...this.#members.values()].map(async (entry) => [
|
|
611
|
+
entry,
|
|
612
|
+
await readVaultRoster(entry.path).then((file) => (file ? { file } : {}), (error) => error instanceof Error ? error : new Error(String(error))),
|
|
613
|
+
])));
|
|
607
614
|
if (!this.#live(generation))
|
|
608
615
|
return undefined;
|
|
609
616
|
let inventory;
|
|
@@ -619,43 +626,28 @@ export class ClaustrumDiscoveryHub {
|
|
|
619
626
|
this.#markPending(entry);
|
|
620
627
|
throw error;
|
|
621
628
|
}
|
|
629
|
+
if (!this.#live(generation))
|
|
630
|
+
return undefined;
|
|
631
|
+
// Every member's commit starts at once and none waits for another: each
|
|
632
|
+
// touches only its own roster file and takes only that file's locks (its
|
|
633
|
+
// discovery lease, then its write lock, as `refreshVaultRoster` always
|
|
634
|
+
// does), so no commit ever holds two members' locks and no order between
|
|
635
|
+
// members is needed. The results are then published in member order.
|
|
636
|
+
const members = this.#open();
|
|
637
|
+
const commits = await Promise.all(members.map((entry) => entry.hooks && !entry.closed
|
|
638
|
+
? this.#commit(entry, entry.hooks, inventory, folders ?? bases.get(entry), generation)
|
|
639
|
+
: undefined));
|
|
640
|
+
if (!this.#live(generation))
|
|
641
|
+
return undefined;
|
|
622
642
|
const errors = new Map();
|
|
623
643
|
let complete = true;
|
|
624
|
-
for (const entry of
|
|
625
|
-
if (!this.#live(generation))
|
|
626
|
-
return undefined;
|
|
644
|
+
for (const [index, entry] of members.entries()) {
|
|
627
645
|
const hooks = entry.hooks;
|
|
628
|
-
|
|
646
|
+
const commit = commits[index];
|
|
647
|
+
if (!hooks || !commit)
|
|
629
648
|
continue;
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
credentials: inventory.credentials.filter((credential) => credential.member === entry.provider),
|
|
633
|
-
skipped: inventory.skipped.filter((record) => record.member === entry.provider),
|
|
634
|
-
};
|
|
635
|
-
const base = bases.get(entry);
|
|
636
|
-
let roster;
|
|
637
|
-
try {
|
|
638
|
-
if (!base)
|
|
639
|
-
throw closed('Claustrum hub member has no base view');
|
|
640
|
-
if (base instanceof Error)
|
|
641
|
-
throw base;
|
|
642
|
-
// A member's first roster under this key carries the declines and
|
|
643
|
-
// order of its newest roster under an older key.
|
|
644
|
-
const seed = base.file ? undefined : await this.#seed(entry);
|
|
645
|
-
roster = await refreshVaultRoster({
|
|
646
|
-
path: entry.path,
|
|
647
|
-
custody: { discover: async () => share },
|
|
648
|
-
// Generation g's commit checks that g is still current, not only
|
|
649
|
-
// that vault mode is on, so off-then-on cannot let it into g+1.
|
|
650
|
-
isActive: () => this.#live(generation) && this.#active === true,
|
|
651
|
-
signal: generation.controller.signal,
|
|
652
|
-
projection: () => ({ ...hooks.projection(), ...(seed && { seed }) }),
|
|
653
|
-
listedOver: { view: base.file?.view },
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
catch (error) {
|
|
657
|
-
if (!this.#live(generation))
|
|
658
|
-
return undefined;
|
|
649
|
+
if ('error' in commit) {
|
|
650
|
+
const { error } = commit;
|
|
659
651
|
complete = false;
|
|
660
652
|
this.#markPending(entry);
|
|
661
653
|
// Another writer holding or taking this roster's locks is not this
|
|
@@ -668,6 +660,7 @@ export class ClaustrumDiscoveryHub {
|
|
|
668
660
|
errors.set(entry.provider, error);
|
|
669
661
|
continue;
|
|
670
662
|
}
|
|
663
|
+
const { roster } = commit;
|
|
671
664
|
if (!this.#live(generation))
|
|
672
665
|
return undefined;
|
|
673
666
|
// Not this list's roster: vault mode went off, the file was removed
|
|
@@ -707,6 +700,57 @@ export class ClaustrumDiscoveryHub {
|
|
|
707
700
|
this.#discoveredAt = (this.#options.now ?? Date.now)();
|
|
708
701
|
return { errors };
|
|
709
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
* Commit one member's share of `inventory` to its roster file over the
|
|
705
|
+
* base view read before the list. Every failure is returned, not thrown,
|
|
706
|
+
* so one member's failure leaves the other members' commits running.
|
|
707
|
+
*/
|
|
708
|
+
async #commit(entry, hooks, inventory, base, generation) {
|
|
709
|
+
const share = {
|
|
710
|
+
...inventory,
|
|
711
|
+
credentials: inventory.credentials.filter((credential) => credential.member === entry.provider),
|
|
712
|
+
skipped: inventory.skipped.filter((record) => record.member === entry.provider),
|
|
713
|
+
};
|
|
714
|
+
try {
|
|
715
|
+
if (!base)
|
|
716
|
+
throw closed('Claustrum hub member has no base view');
|
|
717
|
+
if (base instanceof Error)
|
|
718
|
+
throw base;
|
|
719
|
+
// A member's first roster under this key carries the declines and
|
|
720
|
+
// order of its newest roster under an older key.
|
|
721
|
+
const seed = base.file ? undefined : await this.#seed(entry);
|
|
722
|
+
const roster = await refreshVaultRoster({
|
|
723
|
+
path: entry.path,
|
|
724
|
+
custody: { discover: async () => share },
|
|
725
|
+
// Generation g's commit checks that g is still current, not only
|
|
726
|
+
// that vault mode is on, so off-then-on cannot let it into g+1.
|
|
727
|
+
isActive: () => this.#live(generation) && this.#active === true,
|
|
728
|
+
signal: generation.controller.signal,
|
|
729
|
+
projection: () => ({ ...hooks.projection(), ...(seed && { seed }) }),
|
|
730
|
+
listedOver: { view: base.file?.view },
|
|
731
|
+
});
|
|
732
|
+
return { roster };
|
|
733
|
+
}
|
|
734
|
+
catch (error) {
|
|
735
|
+
return { error };
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Create the roster folders under the state folder (`rosters`, this host
|
|
740
|
+
* generation and this key) owner-only, as every other Claustrum private
|
|
741
|
+
* folder is: 0700 on POSIX, tightening a folder an earlier release left
|
|
742
|
+
* open, and private-files on Windows. Each is handled on its own so an
|
|
743
|
+
* existing open parent is tightened too. Without this, the first roster
|
|
744
|
+
* lock would create them with the process umask, usually 0755.
|
|
745
|
+
*/
|
|
746
|
+
async #ensureRosterDirectories() {
|
|
747
|
+
for (const directory of [
|
|
748
|
+
dirname(this.#generationDirectory),
|
|
749
|
+
this.#generationDirectory,
|
|
750
|
+
join(this.#generationDirectory, this.#key),
|
|
751
|
+
])
|
|
752
|
+
await ensureClaustrumPrivateDirectory(directory, {}, 'roster directory');
|
|
753
|
+
}
|
|
710
754
|
/**
|
|
711
755
|
* The preferences a member's first roster under this key starts from: the
|
|
712
756
|
* declines and order of the newest roster of the same host generation and
|