@cortexkit/opencode-antigravity-auth 3.0.12 → 3.0.13

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.
Files changed (225) hide show
  1. package/dist/cli.js +2846 -1007
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +435 -127
  4. package/dist/index.js +3312 -1268
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +472 -160
  7. package/dist/server.js +12703 -10471
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/cli.d.ts +15 -0
  11. package/dist/src/cli.d.ts.map +1 -1
  12. package/dist/src/cli.js +27 -1
  13. package/dist/src/cli.js.map +1 -1
  14. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +77 -2
  15. package/dist/src/common-auth-embedded/claustrum/consumer.js +320 -35
  16. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +36 -1
  17. package/dist/src/common-auth-embedded/claustrum/custody.js +95 -11
  18. package/dist/src/common-auth-embedded/claustrum/enrollment.js +37 -12
  19. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +195 -0
  20. package/dist/src/common-auth-embedded/claustrum/hub.js +988 -0
  21. package/dist/src/common-auth-embedded/claustrum/index.d.ts +13 -3
  22. package/dist/src/common-auth-embedded/claustrum/index.js +37 -4
  23. package/dist/src/common-auth-embedded/claustrum/quota-writer.d.ts +8 -1
  24. package/dist/src/common-auth-embedded/claustrum/quota-writer.js +34 -12
  25. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +49 -1
  26. package/dist/src/common-auth-embedded/claustrum/roster.js +187 -12
  27. package/dist/src/common-auth-embedded/claustrum/shutdown.js +42 -0
  28. package/dist/src/common-auth-embedded/fs/file-read-cache.js +57 -0
  29. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +1 -1
  30. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +20 -11
  31. package/dist/src/common-auth-embedded/opencode2/errors.d.ts +4 -1
  32. package/dist/src/common-auth-embedded/opencode2/index.d.ts +2 -2
  33. package/dist/src/common-auth-embedded/opencode2/index.js +1 -1
  34. package/dist/src/common-auth-embedded/opencode2/install.d.ts +7 -5
  35. package/dist/src/common-auth-embedded/opencode2/install.js +139 -13
  36. package/dist/src/common-auth-embedded/opencode2/types.d.ts +42 -10
  37. package/dist/src/common-auth-embedded/quota/commit-interval.d.ts +9 -0
  38. package/dist/src/common-auth-embedded/quota/commit-interval.js +18 -0
  39. package/dist/src/common-auth-embedded/rpc/rpc-server.js +29 -19
  40. package/dist/src/common-auth-embedded/setup/command.js +52 -14
  41. package/dist/src/common-auth-embedded/setup/register.d.ts +2 -0
  42. package/dist/src/common-auth-embedded/setup/register.js +90 -11
  43. package/dist/src/common-auth-embedded/source-output.json +145 -97
  44. package/dist/src/common-auth-embedded/store/mutate.d.ts +2 -0
  45. package/dist/src/common-auth-embedded/store/mutate.js +4 -0
  46. package/dist/src/common-auth-embedded/store/pool.d.ts +6 -1
  47. package/dist/src/common-auth-embedded/store/pool.js +1 -1
  48. package/dist/src/common-auth-embedded/store/quota-writer.js +27 -13
  49. package/dist/src/common-auth-embedded/store/settings.d.ts +1 -1
  50. package/dist/src/common-auth-embedded/store/settings.js +16 -6
  51. package/dist/src/ga/rpc/protocol.d.ts +2 -0
  52. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  53. package/dist/src/ga/rpc/protocol.js +2 -2
  54. package/dist/src/ga/rpc/protocol.js.map +1 -1
  55. package/dist/src/ga/server/index.d.ts.map +1 -1
  56. package/dist/src/ga/server/index.js +11 -0
  57. package/dist/src/ga/server/index.js.map +1 -1
  58. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  59. package/dist/src/ga/tui/host-ga.js +2 -1
  60. package/dist/src/ga/tui/host-ga.js.map +1 -1
  61. package/dist/src/plugin/background-vault-quota-refresh.d.ts +10 -0
  62. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  63. package/dist/src/plugin/background-vault-quota-refresh.js +33 -5
  64. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  65. package/dist/src/plugin/command-data.d.ts +2 -2
  66. package/dist/src/plugin/command-data.d.ts.map +1 -1
  67. package/dist/src/plugin/command-data.js +2 -0
  68. package/dist/src/plugin/command-data.js.map +1 -1
  69. package/dist/src/plugin/config/operator-settings-schema.d.ts +1 -1
  70. package/dist/src/plugin/config/schema.d.ts +1 -1
  71. package/dist/src/plugin/ga-location-services.d.ts +28 -2
  72. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  73. package/dist/src/plugin/ga-location-services.js +80 -16
  74. package/dist/src/plugin/ga-location-services.js.map +1 -1
  75. package/dist/src/plugin/ga-shared-vault-custody.d.ts +64 -0
  76. package/dist/src/plugin/ga-shared-vault-custody.d.ts.map +1 -0
  77. package/dist/src/plugin/ga-shared-vault-custody.js +169 -0
  78. package/dist/src/plugin/ga-shared-vault-custody.js.map +1 -0
  79. package/dist/src/plugin/index.d.ts.map +1 -1
  80. package/dist/src/plugin/index.js +11 -1
  81. package/dist/src/plugin/index.js.map +1 -1
  82. package/dist/src/plugin/killswitch.d.ts.map +1 -1
  83. package/dist/src/plugin/killswitch.js +13 -7
  84. package/dist/src/plugin/killswitch.js.map +1 -1
  85. package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
  86. package/dist/src/plugin/oauth-methods.js +3 -0
  87. package/dist/src/plugin/oauth-methods.js.map +1 -1
  88. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  89. package/dist/src/plugin/shared/request-services.js +2 -3
  90. package/dist/src/plugin/shared/request-services.js.map +1 -1
  91. package/dist/src/plugin/shared/vault-request-credentials.d.ts +8 -1
  92. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  93. package/dist/src/plugin/shared/vault-request-credentials.js +38 -5
  94. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  95. package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -1
  96. package/dist/src/plugin/ui/auth-menu.js +3 -0
  97. package/dist/src/plugin/ui/auth-menu.js.map +1 -1
  98. package/dist/src/plugin/ui/quota-status.d.ts.map +1 -1
  99. package/dist/src/plugin/ui/quota-status.js +4 -2
  100. package/dist/src/plugin/ui/quota-status.js.map +1 -1
  101. package/dist/src/plugin/vault-custody.d.ts +28 -7
  102. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  103. package/dist/src/plugin/vault-custody.js +198 -35
  104. package/dist/src/plugin/vault-custody.js.map +1 -1
  105. package/dist/src/plugin/vault-insula-quota.d.ts.map +1 -1
  106. package/dist/src/plugin/vault-insula-quota.js +4 -0
  107. package/dist/src/plugin/vault-insula-quota.js.map +1 -1
  108. package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  109. package/dist/src/process-heartbeat.d.ts +76 -0
  110. package/dist/src/process-heartbeat.d.ts.map +1 -0
  111. package/dist/src/process-heartbeat.js +248 -0
  112. package/dist/src/process-heartbeat.js.map +1 -0
  113. package/dist/src/setup.d.ts.map +1 -1
  114. package/dist/src/setup.js +3 -0
  115. package/dist/src/setup.js.map +1 -1
  116. package/dist/src/sidebar-projection.d.ts +3 -1
  117. package/dist/src/sidebar-projection.d.ts.map +1 -1
  118. package/dist/src/sidebar-projection.js +10 -1
  119. package/dist/src/sidebar-projection.js.map +1 -1
  120. package/dist/src/sidebar-state.d.ts +10 -1
  121. package/dist/src/sidebar-state.d.ts.map +1 -1
  122. package/dist/src/sidebar-state.js +12 -2
  123. package/dist/src/sidebar-state.js.map +1 -1
  124. package/dist/src/tui/quota-layout.d.ts +3 -1
  125. package/dist/src/tui/quota-layout.d.ts.map +1 -1
  126. package/dist/src/tui/quota-layout.js +6 -1
  127. package/dist/src/tui/quota-layout.js.map +1 -1
  128. package/dist/tui-build-map.json +9 -9
  129. package/dist/tui-ga-build-map.json +13 -13
  130. package/dist/types/src/cli.d.ts +15 -0
  131. package/dist/types/src/cli.d.ts.map +1 -1
  132. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +77 -2
  133. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +36 -1
  134. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +195 -0
  135. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +13 -3
  136. package/dist/types/src/common-auth-embedded/claustrum/quota-writer.d.ts +8 -1
  137. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +49 -1
  138. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +1 -1
  139. package/dist/types/src/common-auth-embedded/opencode2/errors.d.ts +4 -1
  140. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +2 -2
  141. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +7 -5
  142. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +42 -10
  143. package/dist/types/src/common-auth-embedded/quota/commit-interval.d.ts +9 -0
  144. package/dist/types/src/common-auth-embedded/setup/register.d.ts +2 -0
  145. package/dist/types/src/common-auth-embedded/store/mutate.d.ts +2 -0
  146. package/dist/types/src/common-auth-embedded/store/pool.d.ts +6 -1
  147. package/dist/types/src/common-auth-embedded/store/settings.d.ts +1 -1
  148. package/dist/types/src/ga/rpc/protocol.d.ts +2 -0
  149. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  150. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  151. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts +10 -0
  152. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  153. package/dist/types/src/plugin/command-data.d.ts +2 -2
  154. package/dist/types/src/plugin/command-data.d.ts.map +1 -1
  155. package/dist/types/src/plugin/ga-location-services.d.ts +28 -2
  156. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  157. package/dist/types/src/plugin/ga-shared-vault-custody.d.ts +64 -0
  158. package/dist/types/src/plugin/ga-shared-vault-custody.d.ts.map +1 -0
  159. package/dist/types/src/plugin/index.d.ts.map +1 -1
  160. package/dist/types/src/plugin/killswitch.d.ts.map +1 -1
  161. package/dist/types/src/plugin/oauth-methods.d.ts.map +1 -1
  162. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  163. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +8 -1
  164. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  165. package/dist/types/src/plugin/ui/auth-menu.d.ts.map +1 -1
  166. package/dist/types/src/plugin/ui/quota-status.d.ts.map +1 -1
  167. package/dist/types/src/plugin/vault-custody.d.ts +28 -7
  168. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  169. package/dist/types/src/plugin/vault-insula-quota.d.ts.map +1 -1
  170. package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  171. package/dist/types/src/process-heartbeat.d.ts +76 -0
  172. package/dist/types/src/process-heartbeat.d.ts.map +1 -0
  173. package/dist/types/src/setup.d.ts.map +1 -1
  174. package/dist/types/src/sidebar-state.d.ts +10 -1
  175. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  176. package/package.json +2 -2
  177. package/src/common-auth-embedded/claustrum/consumer.d.ts +77 -2
  178. package/src/common-auth-embedded/claustrum/consumer.js +320 -35
  179. package/src/common-auth-embedded/claustrum/custody.d.ts +36 -1
  180. package/src/common-auth-embedded/claustrum/custody.js +95 -11
  181. package/src/common-auth-embedded/claustrum/enrollment.js +37 -12
  182. package/src/common-auth-embedded/claustrum/hub.d.ts +195 -0
  183. package/src/common-auth-embedded/claustrum/hub.js +988 -0
  184. package/src/common-auth-embedded/claustrum/index.d.ts +13 -3
  185. package/src/common-auth-embedded/claustrum/index.js +37 -4
  186. package/src/common-auth-embedded/claustrum/quota-writer.d.ts +8 -1
  187. package/src/common-auth-embedded/claustrum/quota-writer.js +34 -12
  188. package/src/common-auth-embedded/claustrum/roster.d.ts +49 -1
  189. package/src/common-auth-embedded/claustrum/roster.js +187 -12
  190. package/src/common-auth-embedded/claustrum/shutdown.js +42 -0
  191. package/src/common-auth-embedded/fs/file-read-cache.js +57 -0
  192. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +1 -1
  193. package/src/common-auth-embedded/fs/refresh-file-lock.js +20 -11
  194. package/src/common-auth-embedded/opencode2/errors.d.ts +4 -1
  195. package/src/common-auth-embedded/opencode2/index.d.ts +2 -2
  196. package/src/common-auth-embedded/opencode2/index.js +1 -1
  197. package/src/common-auth-embedded/opencode2/install.d.ts +7 -5
  198. package/src/common-auth-embedded/opencode2/install.js +139 -13
  199. package/src/common-auth-embedded/opencode2/types.d.ts +42 -10
  200. package/src/common-auth-embedded/quota/commit-interval.d.ts +9 -0
  201. package/src/common-auth-embedded/quota/commit-interval.js +18 -0
  202. package/src/common-auth-embedded/rpc/rpc-server.js +29 -19
  203. package/src/common-auth-embedded/setup/command.js +52 -14
  204. package/src/common-auth-embedded/setup/register.d.ts +2 -0
  205. package/src/common-auth-embedded/setup/register.js +90 -11
  206. package/src/common-auth-embedded/source-output.json +145 -97
  207. package/src/common-auth-embedded/store/mutate.d.ts +2 -0
  208. package/src/common-auth-embedded/store/mutate.js +4 -0
  209. package/src/common-auth-embedded/store/pool.d.ts +6 -1
  210. package/src/common-auth-embedded/store/pool.js +1 -1
  211. package/src/common-auth-embedded/store/quota-writer.js +27 -13
  212. package/src/common-auth-embedded/store/settings.d.ts +1 -1
  213. package/src/common-auth-embedded/store/settings.js +16 -6
  214. package/src/plugin/command-data.ts +4 -2
  215. package/src/sidebar-state.ts +23 -3
  216. package/src/tui-compiled/sidebar-state.js +4 -3
  217. package/src/tui-compiled/tui/quota-layout.js +3 -2
  218. package/src/tui-ga-compiled/host-ga.js +2 -1
  219. package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +9 -2
  220. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +3 -2
  221. package/src/tui-ga-raw/host-ga.tsx +12 -1
  222. package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +9 -2
  223. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +9 -2
  224. package/src/tui-raw/sidebar-state.js +4 -3
  225. package/src/tui-raw/tui/quota-layout.tsx +9 -2
@@ -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
- // Streamed overflow drains without closing at response finish: doing so
38
- // caused EPIPE on a Bun 1.4.2 uploader. Declared oversize also drains, but
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
- if (error.declaredOversize) {
147
- const socket = req.socket;
148
- res.once('finish', () => {
149
- socket.end();
150
- // Bound an abandoned upload to two seconds, matching the server's
151
- // default request-delivery timeout. end() alone left Bun 1.3.14
152
- // compatibility sockets open.
153
- const timer = setTimeout(() => socket.destroy(), 2_000);
154
- timer.unref();
155
- req.once('end', () => socket.destroy());
156
- socket.once('close', () => clearTimeout(timer));
157
- if (req.complete)
158
- socket.destroy();
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
  }
@@ -10,6 +10,7 @@ import { assertHostsStopped, createProcessFence, ProcessFenceViolationError, Pro
10
10
  import { selectSetupHosts } from './prompts.js';
11
11
  import { planOpenCodeRegistration, registerOpenCode, registerPi, } from './register.js';
12
12
  export const AMBIGUOUS_OPENCODE_MESSAGE = 'Multiple OpenCode generations found. Choose --opencode=1|2|both before running noninteractive setup.';
13
+ const UNAVAILABLE_HOST_MESSAGE = 'Requested setup host is unknown or unavailable. Use --host=opencode or --host=pi with a detected host.';
13
14
  function flags(argv) {
14
15
  const result = {
15
16
  yes: false,
@@ -17,6 +18,8 @@ function flags(argv) {
17
18
  claustrum: false,
18
19
  noClaustrum: false,
19
20
  login: false,
21
+ enrollOnly: false,
22
+ hosts: [],
20
23
  opencode: undefined,
21
24
  };
22
25
  for (const arg of argv) {
@@ -30,6 +33,14 @@ function flags(argv) {
30
33
  result.noClaustrum = true;
31
34
  else if (arg === '--login')
32
35
  result.login = true;
36
+ else if (arg === '--enroll-only')
37
+ result.enrollOnly = true;
38
+ else if (arg.startsWith('--host=')) {
39
+ const host = arg.slice('--host='.length);
40
+ if (host !== 'opencode' && host !== 'pi')
41
+ throw new Error(UNAVAILABLE_HOST_MESSAGE);
42
+ result.hosts.push(host);
43
+ }
33
44
  else if (/^--opencode=(1|2|both)$/.test(arg))
34
45
  result.opencode = arg.slice('--opencode='.length);
35
46
  else
@@ -39,6 +50,10 @@ function flags(argv) {
39
50
  throw new Error('--claustrum and --no-claustrum cannot be used together.');
40
51
  if (result.login && result.claustrum)
41
52
  throw new Error('--login and --claustrum cannot be used together.');
53
+ if (result.enrollOnly && result.login)
54
+ throw new Error('--enroll-only and --login cannot be used together.');
55
+ if (result.enrollOnly && result.noClaustrum)
56
+ throw new Error('--enroll-only and --no-claustrum cannot be used together.');
42
57
  return result;
43
58
  }
44
59
  function validatePlugin(plugin) {
@@ -96,14 +111,18 @@ export async function runSetup(plugin, argv = [], io = {}) {
96
111
  if (piWithoutCli)
97
112
  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
113
  const found = ['opencode', 'pi'].filter((host) => detection[host].installed && !(host === 'pi' && piWithoutCli));
114
+ if (options.hosts.some((host) => !found.includes(host)))
115
+ throw new Error(UNAVAILABLE_HOST_MESSAGE);
99
116
  // A dry run changes nothing, so without a terminal it plans the --yes path
100
117
  // instead of refusing; scripts and CI can preview setup with --dry-run alone.
101
118
  const assumeYes = options.yes || (options.dryRun && !isInteractive(terminal));
102
119
  if (!assumeYes && !isInteractive(terminal))
103
120
  throw new Error('Setup requires a TTY or --yes.');
104
- const hosts = assumeYes
105
- ? found
106
- : ((await selectSetupHosts(terminal, found)) ?? []);
121
+ const hosts = options.hosts.length
122
+ ? found.filter((host) => options.hosts.includes(host))
123
+ : assumeYes
124
+ ? found
125
+ : ((await selectSetupHosts(terminal, found)) ?? []);
107
126
  let generation = options.opencode ??
108
127
  (detection.opencode.generation === 'ambiguous'
109
128
  ? '1'
@@ -160,9 +179,10 @@ export async function runSetup(plugin, argv = [], io = {}) {
160
179
  }
161
180
  else
162
181
  await stopped();
163
- if (options.claustrum && !detection.claustrum.available)
164
- throw new Error('Claustrum is not available. Start ck or use --no-claustrum for local sign-in.');
165
- let useVault = Boolean(options.claustrum);
182
+ if ((options.claustrum || options.enrollOnly) &&
183
+ !detection.claustrum.available)
184
+ throw new Error('Claustrum is not available. Start ck, or omit vault-only flags and use --no-claustrum for local sign-in.');
185
+ let useVault = options.claustrum || options.enrollOnly;
166
186
  if (!useVault &&
167
187
  !options.login &&
168
188
  !options.noClaustrum &&
@@ -182,10 +202,20 @@ export async function runSetup(plugin, argv = [], io = {}) {
182
202
  useVault = choice === true;
183
203
  }
184
204
  const mode = useVault ? 'claustrum' : 'local';
185
- // Validate every config before login or enrollment can change credential state.
186
- const writes = hosts.includes('opencode')
205
+ // Validate configs before changing credentials; enrollment-only needs no registration plan.
206
+ const writes = !options.enrollOnly && hosts.includes('opencode')
187
207
  ? planOpenCodeRegistration(plugin, generation, io)
188
208
  : [];
209
+ for (const write of writes) {
210
+ for (const entry of write.existingLocalEntries ?? [])
211
+ printLine(terminal, `OpenCode: already registered from ${entry} in ${write.path}.`);
212
+ const entries = [
213
+ ...(write.existingLocalEntries ?? []),
214
+ ...(write.existingNpmEntries ?? []),
215
+ ];
216
+ if (entries.length > 1)
217
+ printLine(terminal, `Warning: ${plugin.displayName} may load twice in ${write.path}: ${entries.join(', ')}. Entries were left unchanged.`);
218
+ }
189
219
  if (options.dryRun) {
190
220
  printLine(terminal, 'Dry run: no registrations, enrollment, sign-in or migration will be performed.');
191
221
  for (const host of hosts) {
@@ -197,15 +227,16 @@ export async function runSetup(plugin, argv = [], io = {}) {
197
227
  }
198
228
  else
199
229
  printLine(terminal, `Would sign in locally for ${host}.`);
200
- if (plugin.beforeRegister)
230
+ if (!options.enrollOnly && plugin.beforeRegister)
201
231
  printLine(terminal, `Would run beforeRegister(${host}, ${mode}).`);
202
232
  }
203
233
  for (const write of writes)
204
234
  printLine(terminal, `${write.changed ? 'Would write' : 'Unchanged'} ${write.path}:\n${write.content}`);
205
- if (hosts.includes('pi'))
235
+ if (!options.enrollOnly && hosts.includes('pi'))
206
236
  printLine(terminal, `Would run ${detection.pi.executable} install npm:${plugin.packages.pi}@${plugin.version}`);
207
- for (const host of hosts)
208
- printLine(terminal, `Would migrate ${host} using the plugin callback (provider-specific writes).`);
237
+ if (!options.enrollOnly)
238
+ for (const host of hosts)
239
+ printLine(terminal, `Would migrate ${host} using the plugin callback (provider-specific writes).`);
209
240
  }
210
241
  else {
211
242
  const context = {
@@ -237,6 +268,8 @@ export async function runSetup(plugin, argv = [], io = {}) {
237
268
  else
238
269
  await plugin.signInLocal(host, context);
239
270
  await stopped();
271
+ if (options.enrollOnly)
272
+ continue;
240
273
  await plugin.beforeRegister?.(host, mode, context);
241
274
  await stopped();
242
275
  if (host === 'opencode')
@@ -265,7 +298,12 @@ export async function runSetup(plugin, argv = [], io = {}) {
265
298
  throw error;
266
299
  }
267
300
  }
268
- printLine(terminal, `${options.dryRun ? 'Planned' : 'Configured'} ${plugin.displayName} for ${hosts.join(', ')} (${mode}).`);
269
- printLine(terminal, `Next: ${hosts.includes('opencode') ? 'start OpenCode' : 'start Pi'} and run ${plugin.slashCommand}.`);
301
+ printLine(terminal, `${options.dryRun ? 'Planned' : options.enrollOnly ? 'Enrolled' : 'Configured'} ${plugin.displayName} for ${hosts.join(', ')} (${mode}).`);
302
+ if (options.enrollOnly) {
303
+ printLine(terminal, `Enroll-only: no host config or plugin registration ${options.dryRun ? 'will be' : 'was'} written.`);
304
+ printLine(terminal, 'Next: register the plugin yourself in each selected host and enable vault access as required by the plugin.');
305
+ }
306
+ else
307
+ printLine(terminal, `Next: ${hosts.includes('opencode') ? 'start OpenCode' : 'start Pi'} and run ${plugin.slashCommand}.`);
270
308
  return { hosts, dryRun: options.dryRun, mode, detection };
271
309
  }
@@ -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 packageOf(value) {
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
- if (typeof entry !== 'string')
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 errors = [];
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
  });