@cortexkit/opencode-antigravity-auth 3.1.8 → 3.1.10

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 (118) hide show
  1. package/README.md +4 -0
  2. package/dist/cli.js +256 -179
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +88 -44
  5. package/dist/index.js +5466 -4823
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +333 -269
  8. package/dist/server.js +1321 -608
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +16 -5
  12. package/dist/src/common-auth-embedded/claustrum/custody.js +31 -14
  13. package/dist/src/common-auth-embedded/fs/private-files.js +8 -3
  14. package/dist/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  15. package/dist/src/common-auth-embedded/opencode2/index.js +1 -1
  16. package/dist/src/common-auth-embedded/opencode2/install.d.ts +6 -1
  17. package/dist/src/common-auth-embedded/opencode2/install.js +14 -4
  18. package/dist/src/common-auth-embedded/opencode2/types.d.ts +10 -7
  19. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +71 -16
  20. package/dist/src/common-auth-embedded/routing-accessor/index.js +123 -17
  21. package/dist/src/common-auth-embedded/setup/process-fence.js +20 -3
  22. package/dist/src/common-auth-embedded/source-output.json +44 -44
  23. package/dist/src/common-auth-embedded/store/mutate.js +34 -13
  24. package/dist/src/ga/server/index.d.ts +1 -1
  25. package/dist/src/ga/server/index.d.ts.map +1 -1
  26. package/dist/src/ga/server/index.js +58 -19
  27. package/dist/src/ga/server/index.js.map +1 -1
  28. package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
  29. package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
  30. package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
  31. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  32. package/dist/src/plugin/auth-loader.d.ts.map +1 -1
  33. package/dist/src/plugin/auth-loader.js +102 -80
  34. package/dist/src/plugin/auth-loader.js.map +1 -1
  35. package/dist/src/plugin/config/models.d.ts +1 -1
  36. package/dist/src/plugin/config/models.d.ts.map +1 -1
  37. package/dist/src/plugin/config/models.js +10 -5
  38. package/dist/src/plugin/config/models.js.map +1 -1
  39. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  40. package/dist/src/plugin/fetch-interceptor.js +27 -13
  41. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  42. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  43. package/dist/src/plugin/ga-location-services.js +21 -11
  44. package/dist/src/plugin/ga-location-services.js.map +1 -1
  45. package/dist/src/plugin/index.d.ts.map +1 -1
  46. package/dist/src/plugin/index.js +13 -5
  47. package/dist/src/plugin/index.js.map +1 -1
  48. package/dist/src/plugin/request.d.ts.map +1 -1
  49. package/dist/src/plugin/request.js +8 -8
  50. package/dist/src/plugin/request.js.map +1 -1
  51. package/dist/src/plugin/shared/opencode-retry-hints.d.ts +2 -0
  52. package/dist/src/plugin/shared/opencode-retry-hints.d.ts.map +1 -0
  53. package/dist/src/plugin/shared/opencode-retry-hints.js +22 -0
  54. package/dist/src/plugin/shared/opencode-retry-hints.js.map +1 -0
  55. package/dist/src/plugin/shared/request-services.d.ts +2 -0
  56. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  57. package/dist/src/plugin/shared/request-services.js +410 -112
  58. package/dist/src/plugin/shared/request-services.js.map +1 -1
  59. package/dist/src/plugin/shared/vault-routing-purpose.d.ts +6 -2
  60. package/dist/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -1
  61. package/dist/src/plugin/shared/vault-routing-purpose.js +13 -7
  62. package/dist/src/plugin/shared/vault-routing-purpose.js.map +1 -1
  63. package/dist/src/plugin/shared/vault-routing.d.ts +8 -1
  64. package/dist/src/plugin/shared/vault-routing.d.ts.map +1 -1
  65. package/dist/src/plugin/shared/vault-routing.js +12 -4
  66. package/dist/src/plugin/shared/vault-routing.js.map +1 -1
  67. package/dist/src/plugin/storage.d.ts +1 -0
  68. package/dist/src/plugin/storage.d.ts.map +1 -1
  69. package/dist/src/plugin/storage.js +3 -3
  70. package/dist/src/plugin/storage.js.map +1 -1
  71. package/dist/src/plugin/vault-custody.d.ts +6 -13
  72. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  73. package/dist/src/plugin/vault-custody.js +19 -16
  74. package/dist/src/plugin/vault-custody.js.map +1 -1
  75. package/dist/tui-build-map.json +5 -5
  76. package/dist/tui-ga-build-map.json +1 -1
  77. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +16 -5
  78. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  79. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +6 -1
  80. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +10 -7
  81. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +71 -16
  82. package/dist/types/src/ga/server/index.d.ts +1 -1
  83. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  84. package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
  85. package/dist/types/src/plugin/config/models.d.ts +1 -1
  86. package/dist/types/src/plugin/config/models.d.ts.map +1 -1
  87. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  88. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  89. package/dist/types/src/plugin/index.d.ts.map +1 -1
  90. package/dist/types/src/plugin/request.d.ts.map +1 -1
  91. package/dist/types/src/plugin/shared/opencode-retry-hints.d.ts +2 -0
  92. package/dist/types/src/plugin/shared/opencode-retry-hints.d.ts.map +1 -0
  93. package/dist/types/src/plugin/shared/request-services.d.ts +2 -0
  94. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  95. package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts +6 -2
  96. package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -1
  97. package/dist/types/src/plugin/shared/vault-routing.d.ts +8 -1
  98. package/dist/types/src/plugin/shared/vault-routing.d.ts.map +1 -1
  99. package/dist/types/src/plugin/storage.d.ts +1 -0
  100. package/dist/types/src/plugin/storage.d.ts.map +1 -1
  101. package/dist/types/src/plugin/vault-custody.d.ts +6 -13
  102. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  103. package/package.json +2 -2
  104. package/src/common-auth-embedded/claustrum/custody.d.ts +16 -5
  105. package/src/common-auth-embedded/claustrum/custody.js +31 -14
  106. package/src/common-auth-embedded/fs/private-files.js +8 -3
  107. package/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  108. package/src/common-auth-embedded/opencode2/index.js +1 -1
  109. package/src/common-auth-embedded/opencode2/install.d.ts +6 -1
  110. package/src/common-auth-embedded/opencode2/install.js +14 -4
  111. package/src/common-auth-embedded/opencode2/types.d.ts +10 -7
  112. package/src/common-auth-embedded/routing-accessor/index.d.ts +71 -16
  113. package/src/common-auth-embedded/routing-accessor/index.js +123 -17
  114. package/src/common-auth-embedded/setup/process-fence.js +20 -3
  115. package/src/common-auth-embedded/source-output.json +44 -44
  116. package/src/common-auth-embedded/store/mutate.js +34 -13
  117. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +8 -3
  118. package/src/tui-raw/common-auth-embedded/fs/private-files.js +8 -3
@@ -1,7 +1,9 @@
1
1
  import { statSync } from 'node:fs';
2
2
  import { win32 } from 'node:path';
3
+ import { createLogger } from '../logger/index.js';
3
4
  import { defaultCommandRunner } from './command-runner.js';
4
5
  const WINDOWS_CIM_TIMEOUT_MS = 45_000;
6
+ const log = createLogger('setup-process-fence');
5
7
  // Native Windows PowerShell 5.1 on ARM took 22–44 s per process query, with
6
8
  // one cold CIM timeout at 45.8 s; pwsh took less than a second. See
7
9
  // .cortexkit/internal-docs/investigations/windows-arm-process-fence/report.md.
@@ -207,7 +209,7 @@ export async function listSetupProcesses(runner = defaultCommandRunner, options
207
209
  options.onStep?.({ ...inspection });
208
210
  }
209
211
  };
210
- const inspectCim = (args) => {
212
+ const inspectCim = async (args) => {
211
213
  const pwsh = win32.resolve(windowsEnv(env, 'ProgramFiles') ?? 'C:\\Program Files', 'PowerShell', '7', 'pwsh.exe');
212
214
  const program = (options.isFile ?? isFile)(pwsh) ? 'pwsh' : 'powershell';
213
215
  const arm64 = (windowsEnv(env, 'PROCESSOR_ARCHITEW6432') ??
@@ -215,9 +217,24 @@ export async function listSetupProcesses(runner = defaultCommandRunner, options
215
217
  const slow = program === 'powershell' && arm64;
216
218
  if (slow)
217
219
  options.onProgress?.('Checking that OpenCode and Pi are not running. Without PowerShell 7 this can take up to a minute on Windows ARM; installing PowerShell 7 makes it fast.');
218
- return inspect('CIM', program === 'pwsh'
220
+ const file = program === 'pwsh'
219
221
  ? pwsh
220
- : win32.resolve(system32, 'WindowsPowerShell', 'v1.0', 'powershell.exe'), args, slow ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS : WINDOWS_CIM_TIMEOUT_MS, program);
222
+ : win32.resolve(system32, 'WindowsPowerShell', 'v1.0', 'powershell.exe');
223
+ const timeoutMs = slow
224
+ ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS
225
+ : WINDOWS_CIM_TIMEOUT_MS;
226
+ const started = performance.now();
227
+ const result = await inspect('CIM', file, args, timeoutMs, program);
228
+ const remaining = Math.floor(timeoutMs - (performance.now() - started));
229
+ if ((result.exitCode === 3221225477 || result.exitCode === -1073741819) &&
230
+ !result.timedOut &&
231
+ !result.signal &&
232
+ !result.spawnError &&
233
+ remaining > 0) {
234
+ log.warn('Windows process query crashed with an access violation; retrying once');
235
+ return inspect('CIM', file, args, remaining, program);
236
+ }
237
+ return result;
221
238
  };
222
239
  try {
223
240
  if (windows && options.hostImagesOnly) {
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "package": "@cortexkit/common-auth",
4
- "version": "0.53.0",
4
+ "version": "0.55.1",
5
5
  "artifactStatus": "published",
6
- "archiveBytes": 500371,
6
+ "archiveBytes": 503150,
7
7
  "publicRoots": {
8
8
  "./rpc": {
9
9
  "types": "./dist/rpc/index.d.ts",
@@ -74,16 +74,16 @@
74
74
  "import": "./src/quota-sidebar/index.tsx"
75
75
  }
76
76
  },
77
- "input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.53.0.tgz",
78
- "tarballSha256": "f9ffedd0b1fdfbb689c6eb1cae27561228b6e80a52d26ec5e6fa4dd1fe47e7ab",
79
- "sri": "sha512-WwIae25lpa6W07Rw0JTS45eZohHj9ZSa9Yyc62Z9098lP+ztzEt4zJjDsz5KgbX8Ew/SEfRT4s4buXAnoUrA5Q==",
80
- "shasum": "0198ecd60e908146221ea5ab1436ea47077fc212",
77
+ "input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.55.1.tgz",
78
+ "tarballSha256": "80a78298cecc98c5b3b7eb3534e2eb77353d582d997962efe9df27a79ef12589",
79
+ "sri": "sha512-koCwml7Kbf2u6fIIaNmHbDOp2B15hGQ/9kZUB3VSYlBtvyp9ldDUJU1yVGUmin5gzwTzAF9c7g/OWPlWNqgMPw==",
80
+ "shasum": "703dd80358754aa4c3d1b9d6a0d3b9d150860daa",
81
81
  "canonicalFiles": 257,
82
- "canonicalBytes": 1514096,
82
+ "canonicalBytes": 1524660,
83
83
  "generator": {
84
84
  "path": "packages/opencode/scripts/embed-common-auth.ts",
85
85
  "version": 4,
86
- "sha256": "f54aa9e14e1cac3ba0f2158002f58f50ef592638e507fbc4d6302ad4322757da"
86
+ "sha256": "53208174ea6d4a497b8ea378bcb8712971742272d2fd766ea4617866dea60f4b"
87
87
  },
88
88
  "files": [
89
89
  {
@@ -281,17 +281,17 @@
281
281
  {
282
282
  "source": "package/dist/claustrum/custody.d.ts",
283
283
  "output": "claustrum/custody.d.ts",
284
- "bytes": 18127,
285
- "sourceSha256": "8c4cb2f52551ae36a32c4e68201767df0d19ba396302ed6c2d723d0e066166f6",
286
- "outputSha256": "8c4cb2f52551ae36a32c4e68201767df0d19ba396302ed6c2d723d0e066166f6",
284
+ "bytes": 18601,
285
+ "sourceSha256": "9c34f311ef87563256138b5aa070216d9dd027c6ddf4110aba630ba14157bc16",
286
+ "outputSha256": "9c34f311ef87563256138b5aa070216d9dd027c6ddf4110aba630ba14157bc16",
287
287
  "transform": "verbatim"
288
288
  },
289
289
  {
290
290
  "source": "package/dist/claustrum/custody.js",
291
291
  "output": "claustrum/custody.js",
292
- "bytes": 43686,
293
- "sourceSha256": "174adfdaa909149453a34666fdf656aff90c7357e0000338c5a0a2a29d7c1e90",
294
- "outputSha256": "174adfdaa909149453a34666fdf656aff90c7357e0000338c5a0a2a29d7c1e90",
292
+ "bytes": 44266,
293
+ "sourceSha256": "72d08a16f7fb27c26813501b0e89cddfdf640b9aeac8b89e9c7f9c92663db59c",
294
+ "outputSha256": "72d08a16f7fb27c26813501b0e89cddfdf640b9aeac8b89e9c7f9c92663db59c",
295
295
  "transform": "verbatim"
296
296
  },
297
297
  {
@@ -681,9 +681,9 @@
681
681
  {
682
682
  "source": "package/dist/fs/private-files.js",
683
683
  "output": "fs/private-files.js",
684
- "bytes": 15235,
685
- "sourceSha256": "4fd7ca5b40dbdcc27044be3d73eaf6910dd75572cf199aea049fd658bcadf64c",
686
- "outputSha256": "4fd7ca5b40dbdcc27044be3d73eaf6910dd75572cf199aea049fd658bcadf64c",
684
+ "bytes": 15526,
685
+ "sourceSha256": "8456644c921d76d1946c9c04a6784308dfbc4c22be19d88d5b15bf629d5f4226",
686
+ "outputSha256": "8456644c921d76d1946c9c04a6784308dfbc4c22be19d88d5b15bf629d5f4226",
687
687
  "transform": "verbatim"
688
688
  },
689
689
  {
@@ -897,33 +897,33 @@
897
897
  {
898
898
  "source": "package/dist/opencode2/index.d.ts",
899
899
  "output": "opencode2/index.d.ts",
900
- "bytes": 1303,
901
- "sourceSha256": "50f4352606062af68347bc73ae0765ba44537928cb49db3b739d6e76daeebd53",
902
- "outputSha256": "50f4352606062af68347bc73ae0765ba44537928cb49db3b739d6e76daeebd53",
900
+ "bytes": 1325,
901
+ "sourceSha256": "03baf6a3ea7b26545ec20a03588ac7f30830c84e15f4bbde51d268218ff3e284",
902
+ "outputSha256": "03baf6a3ea7b26545ec20a03588ac7f30830c84e15f4bbde51d268218ff3e284",
903
903
  "transform": "verbatim"
904
904
  },
905
905
  {
906
906
  "source": "package/dist/opencode2/index.js",
907
907
  "output": "opencode2/index.js",
908
- "bytes": 463,
909
- "sourceSha256": "a626e6a4f3511e07f1e52a0969b855884bd521f0f1382ad28ed35ca83b46fc1e",
910
- "outputSha256": "a626e6a4f3511e07f1e52a0969b855884bd521f0f1382ad28ed35ca83b46fc1e",
908
+ "bytes": 485,
909
+ "sourceSha256": "0a68a5e9af890954e96172fd475ea20e6e137ad20feb0c5ad014d4ea33dfd198",
910
+ "outputSha256": "0a68a5e9af890954e96172fd475ea20e6e137ad20feb0c5ad014d4ea33dfd198",
911
911
  "transform": "verbatim"
912
912
  },
913
913
  {
914
914
  "source": "package/dist/opencode2/install.d.ts",
915
915
  "output": "opencode2/install.d.ts",
916
- "bytes": 3995,
917
- "sourceSha256": "484ac235de953920bc30164f2b4e814d565b1fe0beca6847c0f65e1d1d42ec08",
918
- "outputSha256": "484ac235de953920bc30164f2b4e814d565b1fe0beca6847c0f65e1d1d42ec08",
916
+ "bytes": 4212,
917
+ "sourceSha256": "edb14a4f60ef24c85b5e4f41f94b66b5594f38628c65145841fa4bcf1bf319f6",
918
+ "outputSha256": "edb14a4f60ef24c85b5e4f41f94b66b5594f38628c65145841fa4bcf1bf319f6",
919
919
  "transform": "verbatim"
920
920
  },
921
921
  {
922
922
  "source": "package/dist/opencode2/install.js",
923
923
  "output": "opencode2/install.js",
924
- "bytes": 65057,
925
- "sourceSha256": "823040b7d0fc4b0199fdbaa68583180338b040ea1200d611c645ba9a3b22538d",
926
- "outputSha256": "823040b7d0fc4b0199fdbaa68583180338b040ea1200d611c645ba9a3b22538d",
924
+ "bytes": 65592,
925
+ "sourceSha256": "fc98e6bd26a6835d118666b1f27fc0598dbe9f929d793b2fe619d3be7375b988",
926
+ "outputSha256": "fc98e6bd26a6835d118666b1f27fc0598dbe9f929d793b2fe619d3be7375b988",
927
927
  "transform": "verbatim"
928
928
  },
929
929
  {
@@ -961,9 +961,9 @@
961
961
  {
962
962
  "source": "package/dist/opencode2/types.d.ts",
963
963
  "output": "opencode2/types.d.ts",
964
- "bytes": 32757,
965
- "sourceSha256": "d9e94ff62857ad062770ad64e30456c39fafbea57c488099cf06dade301120e1",
966
- "outputSha256": "d9e94ff62857ad062770ad64e30456c39fafbea57c488099cf06dade301120e1",
964
+ "bytes": 32971,
965
+ "sourceSha256": "955be769b8aacbc13f51d16a94639658424b3e02e29c2a252b4b872bfde9096f",
966
+ "outputSha256": "955be769b8aacbc13f51d16a94639658424b3e02e29c2a252b4b872bfde9096f",
967
967
  "transform": "verbatim"
968
968
  },
969
969
  {
@@ -1697,9 +1697,9 @@
1697
1697
  {
1698
1698
  "source": "package/dist/setup/process-fence.js",
1699
1699
  "output": "setup/process-fence.js",
1700
- "bytes": 15880,
1701
- "sourceSha256": "1d7ee431c9b63aec37e1868df53f0f9c776ccd45d7935282493d1f1d3d6c6127",
1702
- "outputSha256": "1d7ee431c9b63aec37e1868df53f0f9c776ccd45d7935282493d1f1d3d6c6127",
1700
+ "bytes": 16615,
1701
+ "sourceSha256": "008c119bd1cbac550370933093c89c0c8020010239b71d9407dacbb8d6125cd7",
1702
+ "outputSha256": "008c119bd1cbac550370933093c89c0c8020010239b71d9407dacbb8d6125cd7",
1703
1703
  "transform": "verbatim"
1704
1704
  },
1705
1705
  {
@@ -1857,9 +1857,9 @@
1857
1857
  {
1858
1858
  "source": "package/dist/store/mutate.js",
1859
1859
  "output": "store/mutate.js",
1860
- "bytes": 20171,
1861
- "sourceSha256": "d61d08f2caed6d7a803ca4c67511e5133d28f21a90a7417f76e23b49ed00591d",
1862
- "outputSha256": "d61d08f2caed6d7a803ca4c67511e5133d28f21a90a7417f76e23b49ed00591d",
1860
+ "bytes": 21075,
1861
+ "sourceSha256": "e2b69c850dface416ff3ebc54e2f57fd5c36b5346055b90195493cada75b6901",
1862
+ "outputSha256": "e2b69c850dface416ff3ebc54e2f57fd5c36b5346055b90195493cada75b6901",
1863
1863
  "transform": "verbatim"
1864
1864
  },
1865
1865
  {
@@ -2129,17 +2129,17 @@
2129
2129
  {
2130
2130
  "source": "package/dist/routing-accessor/index.d.ts",
2131
2131
  "output": "routing-accessor/index.d.ts",
2132
- "bytes": 8159,
2133
- "sourceSha256": "be4ee94f1f7ebcc587388df1c4c7744d2f15d6f1cabe08734fdec91012b0946f",
2134
- "outputSha256": "be4ee94f1f7ebcc587388df1c4c7744d2f15d6f1cabe08734fdec91012b0946f",
2132
+ "bytes": 10377,
2133
+ "sourceSha256": "9273612fe071bfdf502d38cc07f5eeca8ecc60d082fa5f578788c7e856a1b15e",
2134
+ "outputSha256": "9273612fe071bfdf502d38cc07f5eeca8ecc60d082fa5f578788c7e856a1b15e",
2135
2135
  "transform": "verbatim"
2136
2136
  },
2137
2137
  {
2138
2138
  "source": "package/dist/routing-accessor/index.js",
2139
2139
  "output": "routing-accessor/index.js",
2140
- "bytes": 18496,
2141
- "sourceSha256": "e4b90716dfc490aa2abca9062b46f2da30b49d8478d101888efbb6b93de63662",
2142
- "outputSha256": "e4b90716dfc490aa2abca9062b46f2da30b49d8478d101888efbb6b93de63662",
2140
+ "bytes": 22848,
2141
+ "sourceSha256": "13f13701391958c2e1f52d614a78da8d276594a90ee54b4f6af33bf81b4ca669",
2142
+ "outputSha256": "13f13701391958c2e1f52d614a78da8d276594a90ee54b4f6af33bf81b4ca669",
2143
2143
  "transform": "verbatim"
2144
2144
  }
2145
2145
  ],
@@ -1,6 +1,6 @@
1
- import { setTimeout as snapshotDelay } from 'node:timers/promises';
1
+ import { setTimeout as delay } from 'node:timers/promises';
2
2
  import { AtomicSyncError, syncJsonFile, writeJsonAtomic, writeJsonAtomicTracked, } from '../fs/atomic-write.js';
3
- import { readPrivateText, windowsPrivateFiles } from '../fs/private-files.js';
3
+ import { isWindowsSharingViolation, readPrivateText, windowsPrivateFiles, } from '../fs/private-files.js';
4
4
  import { LockContentionError, LockOwnershipError } from '../fs/with-lock.js';
5
5
  import { PoolOperationError, } from './errors.js';
6
6
  import { callFailureHook } from './hooks.js';
@@ -8,14 +8,25 @@ import { LockStack, } from './refresh-lock.js';
8
8
  import { assertNotReserved } from './reserved.js';
9
9
  import { CREDENTIAL_STAMP_KEY, classifyConfig, classifyState, ensureEntries, entryIn, isRecord, LEGACY_STORE_VERSION, POOL_KEY, POOL_ROWS_KEY, POOL_SCHEMA_VERSION, retireEpochsIn, rosterOf, rosterRowIn, setEntryIn, } from './schema.js';
10
10
  import { completeTornRows, loadRows } from './torn.js';
11
+ // About 1 s in total. A replace usually clears in milliseconds, but an
12
+ // OpenCode 2 turn ends if the first pool read of a request fails, and a
13
+ // scanner opening the new file can hold it longer.
14
+ const sharingRetryDelays = [5, 10, 20, 40, 80, 160, 320, 400];
11
15
  async function readText(path) {
12
- try {
13
- return await readPrivateText(path, windowsPrivateFiles);
14
- }
15
- catch (error) {
16
- if (error.code === 'ENOENT')
17
- return undefined;
18
- throw error;
16
+ for (let attempt = 0;; attempt++) {
17
+ try {
18
+ return await readPrivateText(path, windowsPrivateFiles);
19
+ }
20
+ catch (error) {
21
+ if (error.code === 'ENOENT')
22
+ return undefined;
23
+ const wait = sharingRetryDelays[attempt];
24
+ // An atomic replace can briefly block a Windows read. Permission
25
+ // refusals are not evidence of a replace and must still surface at once.
26
+ if (wait === undefined || !isWindowsSharingViolation(error))
27
+ throw error;
28
+ await delay(wait);
29
+ }
19
30
  }
20
31
  }
21
32
  function parseFile(text) {
@@ -39,12 +50,22 @@ export async function readPoolConfig(path) {
39
50
  */
40
51
  export async function readPool(ctx) {
41
52
  for (let attempt = 0; attempt < 3; attempt++) {
42
- const configText = await readText(ctx.configPath);
43
- const stateText = await readText(ctx.statePath);
44
- const checkedConfigText = await readText(ctx.configPath);
53
+ let configText;
54
+ let stateText;
55
+ let checkedConfigText;
56
+ try {
57
+ configText = await readText(ctx.configPath);
58
+ stateText = await readText(ctx.statePath);
59
+ checkedConfigText = await readText(ctx.configPath);
60
+ }
61
+ catch (error) {
62
+ if (isWindowsSharingViolation(error))
63
+ break;
64
+ throw error;
65
+ }
45
66
  if (configText !== checkedConfigText) {
46
67
  if (attempt < 2)
47
- await snapshotDelay(2 + Math.floor(Math.random() * 4));
68
+ await delay(2 + Math.floor(Math.random() * 4));
48
69
  continue;
49
70
  }
50
71
  const config = classifyConfig(parseFile(configText));
@@ -70,6 +70,10 @@ function loadBackend() {
70
70
  });
71
71
  return backend;
72
72
  }
73
+ function isSharingIoError(detail) {
74
+ return (detail?.reason === 'io-error' &&
75
+ (detail.win32Code === 32 || detail.win32Code === 303));
76
+ }
73
77
  export class PrivateFileError extends Error {
74
78
  path;
75
79
  stage;
@@ -88,7 +92,9 @@ export class PrivateFileError extends Error {
88
92
  ? // The reason stays on `.reason`: its word "unavailable" would make
89
93
  // OpenCode 1 retry a plain error carrying this message.
90
94
  `Private file refused at ${stage}: ${path}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.`
91
- : `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? 'io-error'}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
95
+ : isSharingIoError(detail)
96
+ ? `Private file busy at ${stage}: ${path}. Another process was replacing or deleting this file at the same moment (Windows error ${detail.win32Code}).`
97
+ : `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? 'io-error'}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
92
98
  this.path = path;
93
99
  this.stage = stage;
94
100
  this.name = 'PrivateFileError';
@@ -101,8 +107,7 @@ export class PrivateFileError extends Error {
101
107
  export function isWindowsSharingViolation(error) {
102
108
  return (windowsPrivateFiles &&
103
109
  error instanceof PrivateFileError &&
104
- error.reason === 'io-error' &&
105
- (error.win32Code === 32 || error.win32Code === 303));
110
+ isSharingIoError(error));
106
111
  }
107
112
  export async function privateOperation(path, stage, operation) {
108
113
  try {
@@ -70,6 +70,10 @@ function loadBackend() {
70
70
  });
71
71
  return backend;
72
72
  }
73
+ function isSharingIoError(detail) {
74
+ return (detail?.reason === 'io-error' &&
75
+ (detail.win32Code === 32 || detail.win32Code === 303));
76
+ }
73
77
  export class PrivateFileError extends Error {
74
78
  path;
75
79
  stage;
@@ -88,7 +92,9 @@ export class PrivateFileError extends Error {
88
92
  ? // The reason stays on `.reason`: its word "unavailable" would make
89
93
  // OpenCode 1 retry a plain error carrying this message.
90
94
  `Private file refused at ${stage}: ${path}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.`
91
- : `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? 'io-error'}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
95
+ : isSharingIoError(detail)
96
+ ? `Private file busy at ${stage}: ${path}. Another process was replacing or deleting this file at the same moment (Windows error ${detail.win32Code}).`
97
+ : `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? 'io-error'}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
92
98
  this.path = path;
93
99
  this.stage = stage;
94
100
  this.name = 'PrivateFileError';
@@ -101,8 +107,7 @@ export class PrivateFileError extends Error {
101
107
  export function isWindowsSharingViolation(error) {
102
108
  return (windowsPrivateFiles &&
103
109
  error instanceof PrivateFileError &&
104
- error.reason === 'io-error' &&
105
- (error.win32Code === 32 || error.win32Code === 303));
110
+ isSharingIoError(error));
106
111
  }
107
112
  export async function privateOperation(path, stage, operation) {
108
113
  try {