@cortexkit/opencode-antigravity-auth 3.0.12 → 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 +9839 -6706
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +722 -175
- package/dist/index.js +4902 -1443
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +756 -190
- package/dist/server.js +8671 -4993
- 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 +26 -0
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +44 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +77 -2
- package/dist/src/common-auth-embedded/claustrum/consumer.js +320 -35
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +36 -1
- package/dist/src/common-auth-embedded/claustrum/custody.js +95 -11
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +52 -20
- package/dist/src/common-auth-embedded/claustrum/hub.d.ts +195 -0
- package/dist/src/common-auth-embedded/claustrum/hub.js +1032 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +13 -3
- package/dist/src/common-auth-embedded/claustrum/index.js +37 -4
- package/dist/src/common-auth-embedded/claustrum/quota-writer.d.ts +8 -1
- package/dist/src/common-auth-embedded/claustrum/quota-writer.js +34 -12
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +49 -1
- package/dist/src/common-auth-embedded/claustrum/roster.js +187 -12
- package/dist/src/common-auth-embedded/claustrum/shutdown.js +42 -0
- package/dist/src/common-auth-embedded/fs/file-read-cache.js +57 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +1 -1
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +36 -14
- package/dist/src/common-auth-embedded/opencode2/errors.d.ts +4 -1
- package/dist/src/common-auth-embedded/opencode2/index.d.ts +2 -2
- package/dist/src/common-auth-embedded/opencode2/index.js +1 -1
- package/dist/src/common-auth-embedded/opencode2/install.d.ts +7 -5
- package/dist/src/common-auth-embedded/opencode2/install.js +139 -13
- package/dist/src/common-auth-embedded/opencode2/types.d.ts +42 -10
- package/dist/src/common-auth-embedded/quota/commit-interval.d.ts +9 -0
- package/dist/src/common-auth-embedded/quota/commit-interval.js +18 -0
- package/dist/src/common-auth-embedded/rpc/rpc-server.js +29 -19
- package/dist/src/common-auth-embedded/setup/command.js +40 -47
- 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/register.d.ts +2 -0
- package/dist/src/common-auth-embedded/setup/register.js +90 -11
- package/dist/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/dist/src/common-auth-embedded/source-output.json +173 -109
- package/dist/src/common-auth-embedded/store/mutate.d.ts +2 -0
- package/dist/src/common-auth-embedded/store/mutate.js +4 -0
- package/dist/src/common-auth-embedded/store/pool.d.ts +6 -1
- package/dist/src/common-auth-embedded/store/pool.js +1 -1
- package/dist/src/common-auth-embedded/store/quota-writer.js +27 -13
- package/dist/src/common-auth-embedded/store/settings.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/settings.js +16 -6
- package/dist/src/ga/rpc/protocol.d.ts +2 -0
- package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
- package/dist/src/ga/rpc/protocol.js +2 -2
- package/dist/src/ga/rpc/protocol.js.map +1 -1
- 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 +25 -0
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +2 -1
- package/dist/src/ga/tui/host-ga.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/background-vault-quota-refresh.d.ts +10 -0
- package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js +33 -5
- package/dist/src/plugin/background-vault-quota-refresh.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/command-data.d.ts +2 -2
- package/dist/src/plugin/command-data.d.ts.map +1 -1
- package/dist/src/plugin/command-data.js +2 -0
- package/dist/src/plugin/command-data.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/operator-settings-schema.d.ts +1 -1
- package/dist/src/plugin/config/schema.d.ts +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 +28 -2
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +118 -31
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/ga-shared-vault-custody.d.ts +78 -0
- package/dist/src/plugin/ga-shared-vault-custody.d.ts.map +1 -0
- package/dist/src/plugin/ga-shared-vault-custody.js +177 -0
- package/dist/src/plugin/ga-shared-vault-custody.js.map +1 -0
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +38 -6
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/killswitch.d.ts.map +1 -1
- package/dist/src/plugin/killswitch.js +13 -7
- package/dist/src/plugin/killswitch.js.map +1 -1
- package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
- package/dist/src/plugin/oauth-methods.js +3 -0
- package/dist/src/plugin/oauth-methods.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +2 -3
- package/dist/src/plugin/shared/request-services.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/shared/vault-request-credentials.d.ts +8 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +38 -5
- package/dist/src/plugin/shared/vault-request-credentials.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/ui/auth-menu.d.ts.map +1 -1
- package/dist/src/plugin/ui/auth-menu.js +3 -0
- package/dist/src/plugin/ui/auth-menu.js.map +1 -1
- package/dist/src/plugin/ui/quota-status.d.ts.map +1 -1
- package/dist/src/plugin/ui/quota-status.js +4 -2
- package/dist/src/plugin/ui/quota-status.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +57 -15
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +259 -45
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/plugin/vault-insula-quota.d.ts.map +1 -1
- package/dist/src/plugin/vault-insula-quota.js +4 -0
- package/dist/src/plugin/vault-insula-quota.js.map +1 -1
- package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
- package/dist/src/process-heartbeat.d.ts +96 -0
- package/dist/src/process-heartbeat.d.ts.map +1 -0
- package/dist/src/process-heartbeat.js +285 -0
- package/dist/src/process-heartbeat.js.map +1 -0
- 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 +31 -5
- package/dist/src/setup.js.map +1 -1
- package/dist/src/sidebar-projection.d.ts +3 -1
- package/dist/src/sidebar-projection.d.ts.map +1 -1
- package/dist/src/sidebar-projection.js +10 -1
- package/dist/src/sidebar-projection.js.map +1 -1
- package/dist/src/sidebar-state.d.ts +10 -1
- package/dist/src/sidebar-state.d.ts.map +1 -1
- package/dist/src/sidebar-state.js +12 -2
- package/dist/src/sidebar-state.js.map +1 -1
- package/dist/src/tui/quota-layout.d.ts +3 -1
- package/dist/src/tui/quota-layout.d.ts.map +1 -1
- package/dist/src/tui/quota-layout.js +6 -1
- package/dist/src/tui/quota-layout.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 +9 -9
- package/dist/tui-ga-build-map.json +13 -13
- package/dist/types/src/cli.d.ts +26 -0
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +77 -2
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +36 -1
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +195 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +13 -3
- package/dist/types/src/common-auth-embedded/claustrum/quota-writer.d.ts +8 -1
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +49 -1
- package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/opencode2/errors.d.ts +4 -1
- package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +2 -2
- package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +7 -5
- package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +42 -10
- package/dist/types/src/common-auth-embedded/quota/commit-interval.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/register.d.ts +2 -0
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/dist/types/src/common-auth-embedded/store/mutate.d.ts +2 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +6 -1
- package/dist/types/src/common-auth-embedded/store/settings.d.ts +1 -1
- package/dist/types/src/ga/rpc/protocol.d.ts +2 -0
- package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -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/background-vault-quota-refresh.d.ts +10 -0
- package/dist/types/src/plugin/background-vault-quota-refresh.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/command-data.d.ts +2 -2
- package/dist/types/src/plugin/command-data.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 +28 -2
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-shared-vault-custody.d.ts +78 -0
- package/dist/types/src/plugin/ga-shared-vault-custody.d.ts.map +1 -0
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/killswitch.d.ts.map +1 -1
- package/dist/types/src/plugin/oauth-methods.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.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/shared/vault-request-credentials.d.ts +8 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.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/ui/auth-menu.d.ts.map +1 -1
- package/dist/types/src/plugin/ui/quota-status.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +57 -15
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-insula-quota.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
- package/dist/types/src/process-heartbeat.d.ts +96 -0
- package/dist/types/src/process-heartbeat.d.ts.map +1 -0
- 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/sidebar-state.d.ts +10 -1
- package/dist/types/src/sidebar-state.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/consumer.d.ts +77 -2
- package/src/common-auth-embedded/claustrum/consumer.js +320 -35
- package/src/common-auth-embedded/claustrum/custody.d.ts +36 -1
- package/src/common-auth-embedded/claustrum/custody.js +95 -11
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +9 -0
- package/src/common-auth-embedded/claustrum/enrollment.js +52 -20
- package/src/common-auth-embedded/claustrum/hub.d.ts +195 -0
- package/src/common-auth-embedded/claustrum/hub.js +1032 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +13 -3
- package/src/common-auth-embedded/claustrum/index.js +37 -4
- package/src/common-auth-embedded/claustrum/quota-writer.d.ts +8 -1
- package/src/common-auth-embedded/claustrum/quota-writer.js +34 -12
- package/src/common-auth-embedded/claustrum/roster.d.ts +49 -1
- package/src/common-auth-embedded/claustrum/roster.js +187 -12
- package/src/common-auth-embedded/claustrum/shutdown.js +42 -0
- package/src/common-auth-embedded/fs/file-read-cache.js +57 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +1 -1
- package/src/common-auth-embedded/fs/refresh-file-lock.js +36 -14
- package/src/common-auth-embedded/opencode2/errors.d.ts +4 -1
- package/src/common-auth-embedded/opencode2/index.d.ts +2 -2
- package/src/common-auth-embedded/opencode2/index.js +1 -1
- package/src/common-auth-embedded/opencode2/install.d.ts +7 -5
- package/src/common-auth-embedded/opencode2/install.js +139 -13
- package/src/common-auth-embedded/opencode2/types.d.ts +42 -10
- package/src/common-auth-embedded/quota/commit-interval.d.ts +9 -0
- package/src/common-auth-embedded/quota/commit-interval.js +18 -0
- package/src/common-auth-embedded/rpc/rpc-server.js +29 -19
- package/src/common-auth-embedded/setup/command.js +40 -47
- 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/register.d.ts +2 -0
- package/src/common-auth-embedded/setup/register.js +90 -11
- package/src/common-auth-embedded/setup/types.d.ts +7 -1
- package/src/common-auth-embedded/source-output.json +173 -109
- package/src/common-auth-embedded/store/mutate.d.ts +2 -0
- package/src/common-auth-embedded/store/mutate.js +4 -0
- package/src/common-auth-embedded/store/pool.d.ts +6 -1
- package/src/common-auth-embedded/store/pool.js +1 -1
- package/src/common-auth-embedded/store/quota-writer.js +27 -13
- package/src/common-auth-embedded/store/settings.d.ts +1 -1
- package/src/common-auth-embedded/store/settings.js +16 -6
- package/src/plugin/command-data.ts +4 -2
- package/src/sidebar-state.ts +23 -3
- package/src/tui-compiled/sidebar-state.js +4 -3
- package/src/tui-compiled/tui/quota-layout.js +3 -2
- package/src/tui-ga-compiled/host-ga.js +2 -1
- package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +9 -2
- package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +3 -2
- package/src/tui-ga-raw/host-ga.tsx +12 -1
- package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +9 -2
- package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +9 -2
- package/src/tui-raw/sidebar-state.js +4 -3
- package/src/tui-raw/tui/quota-layout.tsx +9 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Atomic quota commits create locks, markers and a renamed temp file. Keep
|
|
2
|
+
// those filesystem events at least 30 s apart under normal load; routing sees
|
|
3
|
+
// pending readings immediately, while other processes may lag by one interval.
|
|
4
|
+
// Shutdown drains and a full bounded pool queue can commit sooner.
|
|
5
|
+
// The vault shares one gate per resolved path; each pool handle has its own.
|
|
6
|
+
// N pool handles on one file can therefore make N normal commits per interval
|
|
7
|
+
// in one process. These gates do not coordinate with other processes.
|
|
8
|
+
export const QUOTA_COMMIT_INTERVAL_MS = 30_000;
|
|
9
|
+
export const quotaCommitTimer = {
|
|
10
|
+
now: () => performance.now(),
|
|
11
|
+
schedule(delayMs, run) {
|
|
12
|
+
const timer = setTimeout(() => void run(), delayMs);
|
|
13
|
+
return {
|
|
14
|
+
cancel: () => clearTimeout(timer),
|
|
15
|
+
unref: () => timer.unref?.(),
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -34,12 +34,8 @@ class BodyTooLargeError extends Error {
|
|
|
34
34
|
function readBody(req) {
|
|
35
35
|
return new Promise((resolve, reject) => {
|
|
36
36
|
const tooLarge = (declaredOversize = false) => {
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
// half-closes after the 413: Bun 1.3.14 reused refused fetch connections
|
|
40
|
-
// despite Connection: close. Half-close preserved complete 413 JSON for
|
|
41
|
-
// tested fetch and slow declared-length uploaders on both runtimes (see
|
|
42
|
-
// research/load-probe/RPC-413-CLOSE.md for the delivery/lifecycle samples).
|
|
37
|
+
// Keep draining refused uploads so the client can finish sending after
|
|
38
|
+
// receiving the 413. The response path controls when the socket closes.
|
|
43
39
|
req.removeAllListeners('data');
|
|
44
40
|
req.on('data', () => { });
|
|
45
41
|
req.resume();
|
|
@@ -143,20 +139,34 @@ export async function startRpcServer(options) {
|
|
|
143
139
|
catch (error) {
|
|
144
140
|
if (!(error instanceof BodyTooLargeError))
|
|
145
141
|
throw error;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
142
|
+
const socket = req.socket;
|
|
143
|
+
res.once('finish', () => {
|
|
144
|
+
socket.end();
|
|
145
|
+
// Bound an abandoned declared upload to two seconds, matching the
|
|
146
|
+
// default request-delivery timeout. On Bun 1.3.14, end() alone left
|
|
147
|
+
// the connection open while the client was still uploading.
|
|
148
|
+
const timer = setTimeout(() => socket.destroy(), 2_000);
|
|
149
|
+
timer.unref();
|
|
150
|
+
req.once('end', () => socket.destroy());
|
|
151
|
+
socket.once('close', () => clearTimeout(timer));
|
|
152
|
+
if (req.complete)
|
|
153
|
+
socket.destroy();
|
|
154
|
+
});
|
|
155
|
+
if (!error.declaredOversize && !req.complete) {
|
|
156
|
+
if (res.headersSent || res.writableEnded || res.destroyed)
|
|
157
|
+
return;
|
|
158
|
+
// Bun 1.4.4 closes Connection: close sockets at response finish even
|
|
159
|
+
// while an upload is in flight. Content-Length delivers complete 413
|
|
160
|
+
// JSON now; defer finish (and socket closure) until the body drains.
|
|
161
|
+
const body = JSON.stringify({ error: 'body too large' });
|
|
162
|
+
res.writeHead(413, {
|
|
163
|
+
'content-type': 'application/json',
|
|
164
|
+
'content-length': Buffer.byteLength(body),
|
|
165
|
+
connection: 'close',
|
|
159
166
|
});
|
|
167
|
+
res.write(body);
|
|
168
|
+
req.once('end', () => res.end());
|
|
169
|
+
return;
|
|
160
170
|
}
|
|
161
171
|
return json(413, { error: 'body too large' }, { connection: 'close' });
|
|
162
172
|
}
|
|
@@ -5,42 +5,12 @@ import { recordSetupEnrollment, setupEnrollmentLine } from './command-error.js';
|
|
|
5
5
|
import { defaultCommandRunner } from './command-runner.js';
|
|
6
6
|
import { detectHosts } from './detect.js';
|
|
7
7
|
import { connectSetupHost, HostNotEnrolledError } from './enroll.js';
|
|
8
|
+
import { parseSetupFlags, UNAVAILABLE_HOST_MESSAGE } from './flags.js';
|
|
8
9
|
import { setupPaths } from './paths.js';
|
|
9
10
|
import { assertHostsStopped, createProcessFence, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
|
|
10
11
|
import { selectSetupHosts } from './prompts.js';
|
|
11
12
|
import { planOpenCodeRegistration, registerOpenCode, registerPi, } from './register.js';
|
|
12
13
|
export const AMBIGUOUS_OPENCODE_MESSAGE = 'Multiple OpenCode generations found. Choose --opencode=1|2|both before running noninteractive setup.';
|
|
13
|
-
function flags(argv) {
|
|
14
|
-
const result = {
|
|
15
|
-
yes: false,
|
|
16
|
-
dryRun: false,
|
|
17
|
-
claustrum: false,
|
|
18
|
-
noClaustrum: false,
|
|
19
|
-
login: false,
|
|
20
|
-
opencode: undefined,
|
|
21
|
-
};
|
|
22
|
-
for (const arg of argv) {
|
|
23
|
-
if (arg === '--yes')
|
|
24
|
-
result.yes = true;
|
|
25
|
-
else if (arg === '--dry-run')
|
|
26
|
-
result.dryRun = true;
|
|
27
|
-
else if (arg === '--claustrum')
|
|
28
|
-
result.claustrum = true;
|
|
29
|
-
else if (arg === '--no-claustrum')
|
|
30
|
-
result.noClaustrum = true;
|
|
31
|
-
else if (arg === '--login')
|
|
32
|
-
result.login = true;
|
|
33
|
-
else if (/^--opencode=(1|2|both)$/.test(arg))
|
|
34
|
-
result.opencode = arg.slice('--opencode='.length);
|
|
35
|
-
else
|
|
36
|
-
throw new Error(`Unknown setup argument: ${arg}`);
|
|
37
|
-
}
|
|
38
|
-
if (result.claustrum && result.noClaustrum)
|
|
39
|
-
throw new Error('--claustrum and --no-claustrum cannot be used together.');
|
|
40
|
-
if (result.login && result.claustrum)
|
|
41
|
-
throw new Error('--login and --claustrum cannot be used together.');
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
14
|
function validatePlugin(plugin) {
|
|
45
15
|
for (const pkg of Object.values(plugin.packages)) {
|
|
46
16
|
if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(pkg))
|
|
@@ -77,7 +47,7 @@ async function enrollmentReport(plugin, hosts, recorded) {
|
|
|
77
47
|
return report;
|
|
78
48
|
}
|
|
79
49
|
export async function runSetup(plugin, argv = [], io = {}) {
|
|
80
|
-
const options =
|
|
50
|
+
const options = parseSetupFlags(argv);
|
|
81
51
|
validatePlugin(plugin);
|
|
82
52
|
const terminal = io.terminal ?? processTerminal();
|
|
83
53
|
const detection = await detectHosts(plugin, io);
|
|
@@ -96,14 +66,18 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
96
66
|
if (piWithoutCli)
|
|
97
67
|
printLine(terminal, 'Pi: skipped, because its folder exists but pi is not on PATH. Install the Pi CLI and rerun setup to add it.');
|
|
98
68
|
const found = ['opencode', 'pi'].filter((host) => detection[host].installed && !(host === 'pi' && piWithoutCli));
|
|
69
|
+
if (options.hosts.some((host) => !found.includes(host)))
|
|
70
|
+
throw new Error(UNAVAILABLE_HOST_MESSAGE);
|
|
99
71
|
// A dry run changes nothing, so without a terminal it plans the --yes path
|
|
100
72
|
// instead of refusing; scripts and CI can preview setup with --dry-run alone.
|
|
101
73
|
const assumeYes = options.yes || (options.dryRun && !isInteractive(terminal));
|
|
102
74
|
if (!assumeYes && !isInteractive(terminal))
|
|
103
75
|
throw new Error('Setup requires a TTY or --yes.');
|
|
104
|
-
const hosts =
|
|
105
|
-
? found
|
|
106
|
-
:
|
|
76
|
+
const hosts = options.hosts.length
|
|
77
|
+
? found.filter((host) => options.hosts.includes(host))
|
|
78
|
+
: assumeYes
|
|
79
|
+
? found
|
|
80
|
+
: ((await selectSetupHosts(terminal, found)) ?? []);
|
|
107
81
|
let generation = options.opencode ??
|
|
108
82
|
(detection.opencode.generation === 'ambiguous'
|
|
109
83
|
? '1'
|
|
@@ -160,9 +134,10 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
160
134
|
}
|
|
161
135
|
else
|
|
162
136
|
await stopped();
|
|
163
|
-
if (options.claustrum
|
|
164
|
-
|
|
165
|
-
|
|
137
|
+
if ((options.claustrum || options.enrollOnly) &&
|
|
138
|
+
!detection.claustrum.available)
|
|
139
|
+
throw new Error('Claustrum is not available. Start ck, or omit vault-only flags and use --no-claustrum for local sign-in.');
|
|
140
|
+
let useVault = options.claustrum || options.enrollOnly;
|
|
166
141
|
if (!useVault &&
|
|
167
142
|
!options.login &&
|
|
168
143
|
!options.noClaustrum &&
|
|
@@ -182,10 +157,20 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
182
157
|
useVault = choice === true;
|
|
183
158
|
}
|
|
184
159
|
const mode = useVault ? 'claustrum' : 'local';
|
|
185
|
-
// Validate
|
|
186
|
-
const writes = hosts.includes('opencode')
|
|
160
|
+
// Validate configs before changing credentials; enrollment-only needs no registration plan.
|
|
161
|
+
const writes = !options.enrollOnly && hosts.includes('opencode')
|
|
187
162
|
? planOpenCodeRegistration(plugin, generation, io)
|
|
188
163
|
: [];
|
|
164
|
+
for (const write of writes) {
|
|
165
|
+
for (const entry of write.existingLocalEntries ?? [])
|
|
166
|
+
printLine(terminal, `OpenCode: already registered from ${entry} in ${write.path}.`);
|
|
167
|
+
const entries = [
|
|
168
|
+
...(write.existingLocalEntries ?? []),
|
|
169
|
+
...(write.existingNpmEntries ?? []),
|
|
170
|
+
];
|
|
171
|
+
if (entries.length > 1)
|
|
172
|
+
printLine(terminal, `Warning: ${plugin.displayName} may load twice in ${write.path}: ${entries.join(', ')}. Entries were left unchanged.`);
|
|
173
|
+
}
|
|
189
174
|
if (options.dryRun) {
|
|
190
175
|
printLine(terminal, 'Dry run: no registrations, enrollment, sign-in or migration will be performed.');
|
|
191
176
|
for (const host of hosts) {
|
|
@@ -197,15 +182,16 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
197
182
|
}
|
|
198
183
|
else
|
|
199
184
|
printLine(terminal, `Would sign in locally for ${host}.`);
|
|
200
|
-
if (plugin.beforeRegister)
|
|
185
|
+
if (!options.enrollOnly && plugin.beforeRegister)
|
|
201
186
|
printLine(terminal, `Would run beforeRegister(${host}, ${mode}).`);
|
|
202
187
|
}
|
|
203
188
|
for (const write of writes)
|
|
204
189
|
printLine(terminal, `${write.changed ? 'Would write' : 'Unchanged'} ${write.path}:\n${write.content}`);
|
|
205
|
-
if (hosts.includes('pi'))
|
|
190
|
+
if (!options.enrollOnly && hosts.includes('pi'))
|
|
206
191
|
printLine(terminal, `Would run ${detection.pi.executable} install npm:${plugin.packages.pi}@${plugin.version}`);
|
|
207
|
-
|
|
208
|
-
|
|
192
|
+
if (!options.enrollOnly && plugin.migrate)
|
|
193
|
+
for (const host of hosts)
|
|
194
|
+
printLine(terminal, `Would migrate ${host} using the plugin callback (provider-specific writes).`);
|
|
209
195
|
}
|
|
210
196
|
else {
|
|
211
197
|
const context = {
|
|
@@ -237,6 +223,8 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
237
223
|
else
|
|
238
224
|
await plugin.signInLocal(host, context);
|
|
239
225
|
await stopped();
|
|
226
|
+
if (options.enrollOnly)
|
|
227
|
+
continue;
|
|
240
228
|
await plugin.beforeRegister?.(host, mode, context);
|
|
241
229
|
await stopped();
|
|
242
230
|
if (host === 'opencode')
|
|
@@ -244,7 +232,7 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
244
232
|
else
|
|
245
233
|
await registerPi(plugin, detection.pi.executable, io);
|
|
246
234
|
await stopped();
|
|
247
|
-
await plugin.migrate(host, context);
|
|
235
|
+
await plugin.migrate?.(host, context);
|
|
248
236
|
}
|
|
249
237
|
}
|
|
250
238
|
catch (error) {
|
|
@@ -265,7 +253,12 @@ export async function runSetup(plugin, argv = [], io = {}) {
|
|
|
265
253
|
throw error;
|
|
266
254
|
}
|
|
267
255
|
}
|
|
268
|
-
printLine(terminal, `${options.dryRun ? 'Planned' : 'Configured'} ${plugin.displayName} for ${hosts.join(', ')} (${mode}).`);
|
|
269
|
-
|
|
256
|
+
printLine(terminal, `${options.dryRun ? 'Planned' : options.enrollOnly ? 'Enrolled' : 'Configured'} ${plugin.displayName} for ${hosts.join(', ')} (${mode}).`);
|
|
257
|
+
if (options.enrollOnly) {
|
|
258
|
+
printLine(terminal, `Enroll-only: no host config or plugin registration ${options.dryRun ? 'will be' : 'was'} written.`);
|
|
259
|
+
printLine(terminal, 'Next: register the plugin yourself in each selected host and enable vault access as required by the plugin.');
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
printLine(terminal, `Next: ${hosts.includes('opencode') ? 'start OpenCode' : 'start Pi'} and run ${plugin.slashCommand}.`);
|
|
270
263
|
return { hosts, dryRun: options.dryRun, mode, detection };
|
|
271
264
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { OpenCodeGeneration, SetupHost } from './types.js';
|
|
2
|
+
export declare const UNAVAILABLE_HOST_MESSAGE = "Requested setup host is unknown or unavailable. Use --host=opencode or --host=pi with a detected host.";
|
|
3
|
+
type SwitchKey = 'yes' | 'dryRun' | 'claustrum' | 'noClaustrum' | 'login' | 'enrollOnly';
|
|
4
|
+
/**
|
|
5
|
+
* One flag the shared setup parser accepts. A switch sets `key` to true; a
|
|
6
|
+
* value flag takes one of `values` as `--name=value`, and also as the next
|
|
7
|
+
* argument (`--name value`) when `spaceForm` is set. `invalid` replaces the
|
|
8
|
+
* unknown-argument refusal when a value flag gets a value it does not accept.
|
|
9
|
+
*/
|
|
10
|
+
export type SetupFlag = {
|
|
11
|
+
name: string;
|
|
12
|
+
key: SwitchKey;
|
|
13
|
+
description: string;
|
|
14
|
+
} | {
|
|
15
|
+
name: string;
|
|
16
|
+
key: 'hosts' | 'opencode';
|
|
17
|
+
values: readonly string[];
|
|
18
|
+
spaceForm?: boolean;
|
|
19
|
+
invalid?: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Every flag `runSetup` accepts. The parser and `setupUsage` both read this
|
|
24
|
+
* table, so the help a plugin prints cannot list a flag the parser refuses or
|
|
25
|
+
* leave out one it accepts.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SETUP_FLAGS: readonly SetupFlag[];
|
|
28
|
+
export interface SetupFlags {
|
|
29
|
+
yes: boolean;
|
|
30
|
+
dryRun: boolean;
|
|
31
|
+
claustrum: boolean;
|
|
32
|
+
noClaustrum: boolean;
|
|
33
|
+
login: boolean;
|
|
34
|
+
enrollOnly: boolean;
|
|
35
|
+
hosts: SetupHost[];
|
|
36
|
+
opencode: OpenCodeGeneration | undefined;
|
|
37
|
+
}
|
|
38
|
+
/** Parse setup's arguments against `SETUP_FLAGS`, refusing anything else. */
|
|
39
|
+
export declare function parseSetupFlags(argv: readonly string[]): SetupFlags;
|
|
40
|
+
/**
|
|
41
|
+
* The flags `runSetup` accepts, one per line, for a plugin's `setup --help`.
|
|
42
|
+
* The shared parser has no `--help` of its own: the plugin's bin checks for
|
|
43
|
+
* `--help` or `-h` before calling `runSetup`, prints this text and any lines of
|
|
44
|
+
* its own, and exits 0. With `command` the text starts with a usage line, such
|
|
45
|
+
* as `Usage: example-auth setup [flags]`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function setupUsage(options?: {
|
|
48
|
+
command?: string;
|
|
49
|
+
}): string;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export const UNAVAILABLE_HOST_MESSAGE = 'Requested setup host is unknown or unavailable. Use --host=opencode or --host=pi with a detected host.';
|
|
2
|
+
/**
|
|
3
|
+
* Every flag `runSetup` accepts. The parser and `setupUsage` both read this
|
|
4
|
+
* table, so the help a plugin prints cannot list a flag the parser refuses or
|
|
5
|
+
* leave out one it accepts.
|
|
6
|
+
*/
|
|
7
|
+
export const SETUP_FLAGS = [
|
|
8
|
+
{
|
|
9
|
+
name: '--yes',
|
|
10
|
+
key: 'yes',
|
|
11
|
+
description: 'Run without questions and set up every found host. Does not choose the vault.',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: '--dry-run',
|
|
15
|
+
key: 'dryRun',
|
|
16
|
+
description: 'Print what setup would do without changing anything.',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: '--host',
|
|
20
|
+
key: 'hosts',
|
|
21
|
+
values: ['opencode', 'pi'],
|
|
22
|
+
spaceForm: true,
|
|
23
|
+
invalid: UNAVAILABLE_HOST_MESSAGE,
|
|
24
|
+
description: 'Set up only this host; repeat the flag for both. Also written --host=<host>.',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: '--opencode',
|
|
28
|
+
key: 'opencode',
|
|
29
|
+
values: ['1', '2', 'both'],
|
|
30
|
+
description: 'Register for this OpenCode generation.',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: '--claustrum',
|
|
34
|
+
key: 'claustrum',
|
|
35
|
+
description: 'Connect the hosts to the Claustrum vault.',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: '--no-claustrum',
|
|
39
|
+
key: 'noClaustrum',
|
|
40
|
+
description: 'Do not offer the Claustrum vault; sign in locally.',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: '--login',
|
|
44
|
+
key: 'login',
|
|
45
|
+
description: 'Sign in locally instead of using the Claustrum vault.',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: '--enroll-only',
|
|
49
|
+
key: 'enrollOnly',
|
|
50
|
+
description: 'Only connect the hosts to the Claustrum vault; register nothing and migrate nothing.',
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
function unknownArgument(arg) {
|
|
54
|
+
return new Error(`Unknown setup argument: ${arg}. Run the plugin's own setup --help to list the flags setup accepts.`);
|
|
55
|
+
}
|
|
56
|
+
/** Parse setup's arguments against `SETUP_FLAGS`, refusing anything else. */
|
|
57
|
+
export function parseSetupFlags(argv) {
|
|
58
|
+
const result = {
|
|
59
|
+
yes: false,
|
|
60
|
+
dryRun: false,
|
|
61
|
+
claustrum: false,
|
|
62
|
+
noClaustrum: false,
|
|
63
|
+
login: false,
|
|
64
|
+
enrollOnly: false,
|
|
65
|
+
hosts: [],
|
|
66
|
+
opencode: undefined,
|
|
67
|
+
};
|
|
68
|
+
for (let index = 0; index < argv.length; index++) {
|
|
69
|
+
const arg = argv[index];
|
|
70
|
+
const equals = arg.indexOf('=');
|
|
71
|
+
const name = equals === -1 ? arg : arg.slice(0, equals);
|
|
72
|
+
const flag = SETUP_FLAGS.find((entry) => entry.name === name);
|
|
73
|
+
if (!flag)
|
|
74
|
+
throw unknownArgument(arg);
|
|
75
|
+
if (!('values' in flag)) {
|
|
76
|
+
if (equals !== -1)
|
|
77
|
+
throw unknownArgument(arg);
|
|
78
|
+
result[flag.key] = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
let value;
|
|
82
|
+
if (equals !== -1)
|
|
83
|
+
value = arg.slice(equals + 1);
|
|
84
|
+
else if (flag.spaceForm)
|
|
85
|
+
value = argv[++index];
|
|
86
|
+
else
|
|
87
|
+
throw unknownArgument(arg);
|
|
88
|
+
if (value === undefined || !flag.values.includes(value))
|
|
89
|
+
throw flag.invalid ? new Error(flag.invalid) : unknownArgument(arg);
|
|
90
|
+
if (flag.key === 'hosts')
|
|
91
|
+
result.hosts.push(value);
|
|
92
|
+
else
|
|
93
|
+
result.opencode = value;
|
|
94
|
+
}
|
|
95
|
+
if (result.claustrum && result.noClaustrum)
|
|
96
|
+
throw new Error('--claustrum and --no-claustrum cannot be used together.');
|
|
97
|
+
if (result.login && result.claustrum)
|
|
98
|
+
throw new Error('--login and --claustrum cannot be used together.');
|
|
99
|
+
if (result.enrollOnly && result.login)
|
|
100
|
+
throw new Error('--enroll-only and --login cannot be used together.');
|
|
101
|
+
if (result.enrollOnly && result.noClaustrum)
|
|
102
|
+
throw new Error('--enroll-only and --no-claustrum cannot be used together.');
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The flags `runSetup` accepts, one per line, for a plugin's `setup --help`.
|
|
107
|
+
* The shared parser has no `--help` of its own: the plugin's bin checks for
|
|
108
|
+
* `--help` or `-h` before calling `runSetup`, prints this text and any lines of
|
|
109
|
+
* its own, and exits 0. With `command` the text starts with a usage line, such
|
|
110
|
+
* as `Usage: example-auth setup [flags]`.
|
|
111
|
+
*/
|
|
112
|
+
export function setupUsage(options = {}) {
|
|
113
|
+
const labels = SETUP_FLAGS.map((flag) => 'values' in flag
|
|
114
|
+
? `${flag.name}${flag.spaceForm ? ' ' : '='}${flag.values.join('|')}`
|
|
115
|
+
: flag.name);
|
|
116
|
+
const width = Math.max(...labels.map((label) => label.length));
|
|
117
|
+
const lines = SETUP_FLAGS.map((flag, index) => ` ${labels[index].padEnd(width)} ${flag.description}`);
|
|
118
|
+
return [
|
|
119
|
+
...(options.command ? [`Usage: ${options.command} [flags]`, ''] : []),
|
|
120
|
+
'Flags:',
|
|
121
|
+
...lines,
|
|
122
|
+
].join('\n');
|
|
123
|
+
}
|
|
@@ -2,6 +2,7 @@ export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
|
|
|
2
2
|
export { SetupCommandError, setupEnrollment } from './command-error.js';
|
|
3
3
|
export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
|
|
4
4
|
export { ENROLLMENT_WAIT_MS, HostNotEnrolledError, type HostNotEnrolledReason, UNSUPPORTED_VAULT_MESSAGE, } from './enroll.js';
|
|
5
|
+
export { setupUsage } from './flags.js';
|
|
5
6
|
export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, type ProcessInspectionStep, } from './process-fence.js';
|
|
6
7
|
export { type PlannedWrite, planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
|
|
7
8
|
export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnrollmentOutcome, SetupEnvironment, SetupFileSystem, SetupHost, SetupHostEnrollment, SetupIO, SetupPlugin, SetupResult, } from './types.js';
|
|
@@ -2,5 +2,6 @@ export { AMBIGUOUS_OPENCODE_MESSAGE, runSetup } from './command.js';
|
|
|
2
2
|
export { SetupCommandError, setupEnrollment } from './command-error.js';
|
|
3
3
|
export { detectHosts, detectOpenCodeGeneration, findExecutableOnPath, openCodeDesktopMarkers, } from './detect.js';
|
|
4
4
|
export { ENROLLMENT_WAIT_MS, HostNotEnrolledError, UNSUPPORTED_VAULT_MESSAGE, } from './enroll.js';
|
|
5
|
+
export { setupUsage } from './flags.js';
|
|
5
6
|
export { assertHostsStopped, createProcessFence, listSetupProcesses, ProcessFenceViolationError, ProcessInspectionError, } from './process-fence.js';
|
|
6
7
|
export { planOpenCodeRegistration, registerOpenCode, registerPi, updatePluginConfig, } from './register.js';
|
|
@@ -3,6 +3,8 @@ export interface PlannedWrite {
|
|
|
3
3
|
path: string;
|
|
4
4
|
content: string;
|
|
5
5
|
changed: boolean;
|
|
6
|
+
existingLocalEntries?: string[];
|
|
7
|
+
existingNpmEntries?: string[];
|
|
6
8
|
}
|
|
7
9
|
/** Edit only array entries so unrelated JSONC text, including comments, survives. */
|
|
8
10
|
export declare function updatePluginConfig(text: string, key: 'plugin' | 'plugins', pkg: string, version: string): string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { domainToUnicode } from 'node:url';
|
|
1
2
|
import { applyEdits, createScanner, findNodeAtLocation, modify, parse, parseTree, } from 'jsonc-parser';
|
|
2
3
|
import { SetupCommandError } from './command-error.js';
|
|
3
4
|
import { defaultCommandRunner, runResolvedCommand } from './command-runner.js';
|
|
4
5
|
import { writeHostConfigAtomic } from './config-write.js';
|
|
5
6
|
import { defaultSetupFileSystem } from './detect.js';
|
|
6
7
|
import { setupPaths } from './paths.js';
|
|
7
|
-
function
|
|
8
|
+
function specifierOf(value) {
|
|
8
9
|
const entry = typeof value === 'string'
|
|
9
10
|
? value
|
|
10
11
|
: Array.isArray(value)
|
|
@@ -12,11 +13,72 @@ function packageOf(value) {
|
|
|
12
13
|
: value && typeof value === 'object' && 'package' in value
|
|
13
14
|
? value.package
|
|
14
15
|
: null;
|
|
15
|
-
|
|
16
|
+
return typeof entry === 'string' ? entry : null;
|
|
17
|
+
}
|
|
18
|
+
function packageOf(value) {
|
|
19
|
+
const entry = specifierOf(value);
|
|
20
|
+
if (entry === null)
|
|
16
21
|
return null;
|
|
17
22
|
const at = entry.indexOf('@', entry.startsWith('@') ? 1 : 0);
|
|
18
23
|
return at < 0 ? entry : entry.slice(0, at);
|
|
19
24
|
}
|
|
25
|
+
function localFileURL(entry, windows) {
|
|
26
|
+
const url = new URL(entry);
|
|
27
|
+
if (/%2f/i.test(url.pathname) || (windows && /%5c/i.test(url.pathname)))
|
|
28
|
+
throw new Error('Encoded path separators are not valid in a file URL.');
|
|
29
|
+
const decoded = decodeURIComponent(url.pathname);
|
|
30
|
+
if (!windows) {
|
|
31
|
+
if (url.hostname)
|
|
32
|
+
throw new Error('A POSIX file URL must be local.');
|
|
33
|
+
return decoded;
|
|
34
|
+
}
|
|
35
|
+
const pathname = decoded.replaceAll('/', '\\');
|
|
36
|
+
if (url.hostname)
|
|
37
|
+
return `\\\\${domainToUnicode(url.hostname)}${pathname}`;
|
|
38
|
+
if (!/^\\[a-z]:/i.test(pathname))
|
|
39
|
+
throw new Error('A Windows file URL must have an absolute drive path.');
|
|
40
|
+
return pathname.slice(1);
|
|
41
|
+
}
|
|
42
|
+
function localPackageOf(entry, configFile, io) {
|
|
43
|
+
const { path, platform } = setupPaths(io);
|
|
44
|
+
try {
|
|
45
|
+
// Relative paths use the declaring config's directory, not setup's working directory:
|
|
46
|
+
// https://github.com/anomalyco/opencode/blob/b6478dce/packages/opencode/src/config/plugin.ts#L40-L60
|
|
47
|
+
// https://github.com/anomalyco/opencode/blob/v2.0.22/packages/core/src/config/plugin/source.ts#L139-L145
|
|
48
|
+
// Decode file URLs explicitly: Bun 1.3 ignores fileURLToPath's Windows override.
|
|
49
|
+
// The requested platform, not the OS running setup's tests, determines path rules.
|
|
50
|
+
const directory = /^file:\/\//i.test(entry)
|
|
51
|
+
? localFileURL(entry, platform === 'win32')
|
|
52
|
+
: path.isAbsolute(entry) || entry.startsWith('.')
|
|
53
|
+
? path.resolve(path.dirname(configFile), entry)
|
|
54
|
+
: null;
|
|
55
|
+
if (directory === null)
|
|
56
|
+
return null;
|
|
57
|
+
const manifest = JSON.parse((io.fs ?? defaultSetupFileSystem).readText(path.join(directory, 'package.json')));
|
|
58
|
+
return manifest &&
|
|
59
|
+
typeof manifest === 'object' &&
|
|
60
|
+
'name' in manifest &&
|
|
61
|
+
typeof manifest.name === 'string'
|
|
62
|
+
? manifest.name
|
|
63
|
+
: null;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// A missing, unreadable or invalid local package is not a registration of this plugin.
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function pluginConfig(text, key) {
|
|
71
|
+
const errors = [];
|
|
72
|
+
const value = parse(text, errors, { allowTrailingComma: true });
|
|
73
|
+
if (errors.length ||
|
|
74
|
+
!value ||
|
|
75
|
+
typeof value !== 'object' ||
|
|
76
|
+
Array.isArray(value))
|
|
77
|
+
throw new Error('Invalid OpenCode config; refusing to overwrite it.');
|
|
78
|
+
if (value[key] !== undefined && !Array.isArray(value[key]))
|
|
79
|
+
throw new Error(`OpenCode ${key} must be an array.`);
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
20
82
|
function removeArrayEntry(text, key, index) {
|
|
21
83
|
const tree = parseTree(text);
|
|
22
84
|
const array = tree && findNodeAtLocation(tree, [key]);
|
|
@@ -48,13 +110,7 @@ function removeArrayEntry(text, key, index) {
|
|
|
48
110
|
}
|
|
49
111
|
/** Edit only array entries so unrelated JSONC text, including comments, survives. */
|
|
50
112
|
export function updatePluginConfig(text, key, pkg, version) {
|
|
51
|
-
const
|
|
52
|
-
const value = parse(text, errors, { allowTrailingComma: true });
|
|
53
|
-
if (errors.length ||
|
|
54
|
-
!value ||
|
|
55
|
-
typeof value !== 'object' ||
|
|
56
|
-
Array.isArray(value))
|
|
57
|
-
throw new Error('Invalid OpenCode config; refusing to overwrite it.');
|
|
113
|
+
const value = pluginConfig(text, key);
|
|
58
114
|
const options = {
|
|
59
115
|
formattingOptions: {
|
|
60
116
|
insertSpaces: !/^\t+/m.test(text),
|
|
@@ -64,8 +120,6 @@ export function updatePluginConfig(text, key, pkg, version) {
|
|
|
64
120
|
};
|
|
65
121
|
let output = text;
|
|
66
122
|
const array = value[key];
|
|
67
|
-
if (array !== undefined && !Array.isArray(array))
|
|
68
|
-
throw new Error(`OpenCode ${key} must be an array.`);
|
|
69
123
|
const entries = Array.isArray(array) ? [...array] : [];
|
|
70
124
|
const matches = entries.flatMap((entry, index) => packageOf(entry) === pkg ? [index] : []);
|
|
71
125
|
const entry = `${pkg}@${version}`;
|
|
@@ -109,6 +163,31 @@ export function planOpenCodeRegistration(plugin, generation, io = {}) {
|
|
|
109
163
|
const before = exists
|
|
110
164
|
? fs.readText(file)
|
|
111
165
|
: `${JSON.stringify({ $schema: `https://opencode.ai/${name === 'tui' ? 'tui' : 'config'}.json` }, null, 2)}\n`;
|
|
166
|
+
const config = pluginConfig(before, key);
|
|
167
|
+
const existingLocalEntries = [];
|
|
168
|
+
const existingNpmEntries = [];
|
|
169
|
+
for (const field of ['plugin', 'plugins']) {
|
|
170
|
+
if (!Array.isArray(config[field]))
|
|
171
|
+
continue;
|
|
172
|
+
for (const entry of config[field]) {
|
|
173
|
+
const spec = specifierOf(entry);
|
|
174
|
+
if (spec === null)
|
|
175
|
+
continue;
|
|
176
|
+
if (localPackageOf(spec, file, io) === plugin.packages.opencode)
|
|
177
|
+
existingLocalEntries.push(JSON.stringify(entry));
|
|
178
|
+
else if (packageOf(entry) === plugin.packages.opencode)
|
|
179
|
+
existingNpmEntries.push(JSON.stringify(entry));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// A local build is deliberate: do not replace it, deduplicate it or migrate its key.
|
|
183
|
+
if (existingLocalEntries.length > 0)
|
|
184
|
+
return {
|
|
185
|
+
path: file,
|
|
186
|
+
content: before,
|
|
187
|
+
changed: false,
|
|
188
|
+
existingLocalEntries,
|
|
189
|
+
existingNpmEntries,
|
|
190
|
+
};
|
|
112
191
|
const content = updatePluginConfig(before, key, plugin.packages.opencode, plugin.version);
|
|
113
192
|
return { path: file, content, changed: !exists || content !== before };
|
|
114
193
|
});
|
|
@@ -61,7 +61,13 @@ export interface SetupPlugin {
|
|
|
61
61
|
*/
|
|
62
62
|
beforeSignIn?(host: SetupHost, context: SetupCallbackContext): Promise<void>;
|
|
63
63
|
signInLocal(host: SetupHost, context: SetupCallbackContext): Promise<void>;
|
|
64
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Moves the host's existing provider credentials into place after the host
|
|
66
|
+
* is registered. Optional: a plugin with nothing to migrate (one that only
|
|
67
|
+
* reads credentials from the vault) leaves it out, and setup then neither
|
|
68
|
+
* calls it nor mentions migration in its dry-run plan.
|
|
69
|
+
*/
|
|
70
|
+
migrate?(host: SetupHost, context: SetupCallbackContext): Promise<void>;
|
|
65
71
|
/** Reject mixed local/vault credentials and activate provider-specific vault access before registration. */
|
|
66
72
|
beforeRegister?(host: SetupHost, mode: 'local' | 'claustrum', context: SetupCallbackContext): Promise<void>;
|
|
67
73
|
}
|