@cortexkit/opencode-antigravity-auth 3.0.40 → 3.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/dist/cli.js +1277 -1073
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +122 -112
  4. package/dist/index.js +7472 -4214
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +1494 -509
  7. package/dist/server.js +5990 -2678
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  11. package/dist/src/common-auth-embedded/commands/builtins.js +28 -12
  12. package/dist/src/common-auth-embedded/commands/index.d.ts +1 -1
  13. package/dist/src/common-auth-embedded/commands/menu.d.ts +6 -1
  14. package/dist/src/common-auth-embedded/commands/menu.js +1 -0
  15. package/dist/src/common-auth-embedded/fs/file-read-cache.js +9 -5
  16. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  17. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +159 -11
  18. package/dist/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
  19. package/dist/src/common-auth-embedded/fs/with-lock.js +1 -1
  20. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
  21. package/dist/src/common-auth-embedded/routing-accessor/index.js +49 -7
  22. package/dist/src/common-auth-embedded/settings/define.d.ts +35 -0
  23. package/dist/src/common-auth-embedded/settings/define.js +52 -0
  24. package/dist/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
  25. package/dist/src/common-auth-embedded/settings/descriptors.js +81 -0
  26. package/dist/src/common-auth-embedded/settings/edit.d.ts +24 -0
  27. package/dist/src/common-auth-embedded/settings/edit.js +229 -0
  28. package/dist/src/common-auth-embedded/settings/fs.js +19 -0
  29. package/dist/src/common-auth-embedded/settings/handle.d.ts +30 -0
  30. package/dist/src/common-auth-embedded/settings/handle.js +228 -0
  31. package/dist/src/common-auth-embedded/settings/index.d.ts +10 -0
  32. package/dist/src/common-auth-embedded/settings/index.js +7 -0
  33. package/dist/src/common-auth-embedded/settings/lock-errors.js +15 -0
  34. package/dist/src/common-auth-embedded/settings/move.d.ts +76 -0
  35. package/dist/src/common-auth-embedded/settings/move.js +351 -0
  36. package/dist/src/common-auth-embedded/settings/parse.d.ts +24 -0
  37. package/dist/src/common-auth-embedded/settings/parse.js +65 -0
  38. package/dist/src/common-auth-embedded/settings/paths.d.ts +12 -0
  39. package/dist/src/common-auth-embedded/settings/paths.js +48 -0
  40. package/dist/src/common-auth-embedded/settings/refusal.d.ts +7 -0
  41. package/dist/src/common-auth-embedded/settings/refusal.js +15 -0
  42. package/dist/src/common-auth-embedded/settings/resolve.d.ts +15 -0
  43. package/dist/src/common-auth-embedded/settings/resolve.js +51 -0
  44. package/dist/src/common-auth-embedded/settings/schema.d.ts +29 -0
  45. package/dist/src/common-auth-embedded/settings/schema.js +81 -0
  46. package/dist/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
  47. package/dist/src/common-auth-embedded/settings/snapshot.js +150 -0
  48. package/dist/src/common-auth-embedded/settings/update.js +139 -0
  49. package/dist/src/common-auth-embedded/settings/write.js +88 -0
  50. package/dist/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  51. package/dist/src/common-auth-embedded/setup/command-error.js +3 -2
  52. package/dist/src/common-auth-embedded/setup/command.js +5 -1
  53. package/dist/src/common-auth-embedded/setup/enroll.js +3 -3
  54. package/dist/src/common-auth-embedded/setup/enrollment-access.js +13 -4
  55. package/dist/src/common-auth-embedded/setup/types.d.ts +4 -0
  56. package/dist/src/common-auth-embedded/source-output.json +297 -61
  57. package/dist/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
  58. package/dist/src/ga/tui/host-ga.js +1 -1
  59. package/dist/src/ga/tui/host-ga.js.map +1 -1
  60. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  61. package/dist/src/plugin/command-apply.d.ts +43 -3
  62. package/dist/src/plugin/command-apply.d.ts.map +1 -1
  63. package/dist/src/plugin/command-apply.js +92 -12
  64. package/dist/src/plugin/command-apply.js.map +1 -1
  65. package/dist/src/plugin/commands.d.ts +5 -1
  66. package/dist/src/plugin/commands.d.ts.map +1 -1
  67. package/dist/src/plugin/commands.js +4 -3
  68. package/dist/src/plugin/commands.js.map +1 -1
  69. package/dist/src/plugin/config/writer.d.ts +10 -3
  70. package/dist/src/plugin/config/writer.d.ts.map +1 -1
  71. package/dist/src/plugin/config/writer.js +30 -22
  72. package/dist/src/plugin/config/writer.js.map +1 -1
  73. package/dist/src/plugin/fetch-interceptor.d.ts +8 -3
  74. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  75. package/dist/src/plugin/fetch-interceptor.js +1 -0
  76. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  77. package/dist/src/plugin/ga-location-services.d.ts +3 -1
  78. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  79. package/dist/src/plugin/ga-location-services.js +35 -5
  80. package/dist/src/plugin/ga-location-services.js.map +1 -1
  81. package/dist/src/plugin/index.d.ts.map +1 -1
  82. package/dist/src/plugin/index.js +65 -15
  83. package/dist/src/plugin/index.js.map +1 -1
  84. package/dist/src/plugin/killswitch.d.ts +20 -0
  85. package/dist/src/plugin/killswitch.d.ts.map +1 -1
  86. package/dist/src/plugin/killswitch.js +14 -4
  87. package/dist/src/plugin/killswitch.js.map +1 -1
  88. package/dist/src/plugin/operator-settings.d.ts +6 -0
  89. package/dist/src/plugin/operator-settings.d.ts.map +1 -1
  90. package/dist/src/plugin/operator-settings.js.map +1 -1
  91. package/dist/src/plugin/request-helpers.d.ts +15 -0
  92. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  93. package/dist/src/plugin/request-helpers.js +17 -2
  94. package/dist/src/plugin/request-helpers.js.map +1 -1
  95. package/dist/src/plugin/shared/request-services.d.ts +18 -2
  96. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  97. package/dist/src/plugin/shared/request-services.js +130 -13
  98. package/dist/src/plugin/shared/request-services.js.map +1 -1
  99. package/dist/src/plugin/shared/runtime.d.ts +15 -0
  100. package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
  101. package/dist/src/plugin/shared/runtime.js +43 -11
  102. package/dist/src/plugin/shared/runtime.js.map +1 -1
  103. package/dist/src/plugin/shared/vault-menu.d.ts +11 -1
  104. package/dist/src/plugin/shared/vault-menu.d.ts.map +1 -1
  105. package/dist/src/plugin/shared/vault-menu.js +33 -7
  106. package/dist/src/plugin/shared/vault-menu.js.map +1 -1
  107. package/dist/src/settings/core-settings.d.ts +7 -0
  108. package/dist/src/settings/core-settings.d.ts.map +1 -0
  109. package/dist/src/settings/core-settings.js +7 -0
  110. package/dist/src/settings/core-settings.js.map +1 -0
  111. package/dist/src/settings/legacy.d.ts +89 -0
  112. package/dist/src/settings/legacy.d.ts.map +1 -0
  113. package/dist/src/settings/legacy.js +184 -0
  114. package/dist/src/settings/legacy.js.map +1 -0
  115. package/dist/src/settings/location.d.ts +22 -0
  116. package/dist/src/settings/location.d.ts.map +1 -0
  117. package/dist/src/settings/location.js +49 -0
  118. package/dist/src/settings/location.js.map +1 -0
  119. package/dist/src/settings/move.d.ts +38 -0
  120. package/dist/src/settings/move.d.ts.map +1 -0
  121. package/dist/src/settings/move.js +83 -0
  122. package/dist/src/settings/move.js.map +1 -0
  123. package/dist/src/settings/protection.d.ts +11 -0
  124. package/dist/src/settings/protection.d.ts.map +1 -0
  125. package/dist/src/settings/protection.js +17 -0
  126. package/dist/src/settings/protection.js.map +1 -0
  127. package/dist/src/settings/report.d.ts +33 -0
  128. package/dist/src/settings/report.d.ts.map +1 -0
  129. package/dist/src/settings/report.js +103 -0
  130. package/dist/src/settings/report.js.map +1 -0
  131. package/dist/src/settings/runtime.d.ts +145 -0
  132. package/dist/src/settings/runtime.d.ts.map +1 -0
  133. package/dist/src/settings/runtime.js +697 -0
  134. package/dist/src/settings/runtime.js.map +1 -0
  135. package/dist/tui-build-map.json +1 -1
  136. package/dist/tui-ga-build-map.json +5 -5
  137. package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  138. package/dist/types/src/common-auth-embedded/commands/index.d.ts +1 -1
  139. package/dist/types/src/common-auth-embedded/commands/menu.d.ts +6 -1
  140. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  141. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
  142. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  143. package/dist/types/src/common-auth-embedded/setup/types.d.ts +4 -0
  144. package/dist/types/src/plugin/command-apply.d.ts +43 -3
  145. package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
  146. package/dist/types/src/plugin/commands.d.ts +5 -1
  147. package/dist/types/src/plugin/commands.d.ts.map +1 -1
  148. package/dist/types/src/plugin/config/writer.d.ts +10 -3
  149. package/dist/types/src/plugin/config/writer.d.ts.map +1 -1
  150. package/dist/types/src/plugin/fetch-interceptor.d.ts +8 -3
  151. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  152. package/dist/types/src/plugin/ga-location-services.d.ts +3 -1
  153. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  154. package/dist/types/src/plugin/index.d.ts.map +1 -1
  155. package/dist/types/src/plugin/killswitch.d.ts +20 -0
  156. package/dist/types/src/plugin/killswitch.d.ts.map +1 -1
  157. package/dist/types/src/plugin/operator-settings.d.ts +6 -0
  158. package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
  159. package/dist/types/src/plugin/request-helpers.d.ts +15 -0
  160. package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
  161. package/dist/types/src/plugin/shared/request-services.d.ts +18 -2
  162. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  163. package/dist/types/src/plugin/shared/runtime.d.ts +15 -0
  164. package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
  165. package/dist/types/src/plugin/shared/vault-menu.d.ts +11 -1
  166. package/dist/types/src/plugin/shared/vault-menu.d.ts.map +1 -1
  167. package/dist/types/src/settings/core-settings.d.ts +7 -0
  168. package/dist/types/src/settings/core-settings.d.ts.map +1 -0
  169. package/dist/types/src/settings/legacy.d.ts +89 -0
  170. package/dist/types/src/settings/legacy.d.ts.map +1 -0
  171. package/dist/types/src/settings/location.d.ts +22 -0
  172. package/dist/types/src/settings/location.d.ts.map +1 -0
  173. package/dist/types/src/settings/move.d.ts +38 -0
  174. package/dist/types/src/settings/move.d.ts.map +1 -0
  175. package/dist/types/src/settings/protection.d.ts +11 -0
  176. package/dist/types/src/settings/protection.d.ts.map +1 -0
  177. package/dist/types/src/settings/report.d.ts +33 -0
  178. package/dist/types/src/settings/report.d.ts.map +1 -0
  179. package/dist/types/src/settings/runtime.d.ts +145 -0
  180. package/dist/types/src/settings/runtime.d.ts.map +1 -0
  181. package/package.json +3 -2
  182. package/src/common-auth-embedded/commands/builtins.d.ts +20 -1
  183. package/src/common-auth-embedded/commands/builtins.js +28 -12
  184. package/src/common-auth-embedded/commands/index.d.ts +1 -1
  185. package/src/common-auth-embedded/commands/menu.d.ts +6 -1
  186. package/src/common-auth-embedded/commands/menu.js +1 -0
  187. package/src/common-auth-embedded/fs/file-read-cache.js +9 -5
  188. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +11 -0
  189. package/src/common-auth-embedded/fs/refresh-file-lock.js +159 -11
  190. package/src/common-auth-embedded/fs/with-lock.d.ts +2 -0
  191. package/src/common-auth-embedded/fs/with-lock.js +1 -1
  192. package/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
  193. package/src/common-auth-embedded/routing-accessor/index.js +49 -7
  194. package/src/common-auth-embedded/settings/define.d.ts +35 -0
  195. package/src/common-auth-embedded/settings/define.js +52 -0
  196. package/src/common-auth-embedded/settings/descriptors.d.ts +97 -0
  197. package/src/common-auth-embedded/settings/descriptors.js +81 -0
  198. package/src/common-auth-embedded/settings/edit.d.ts +24 -0
  199. package/src/common-auth-embedded/settings/edit.js +229 -0
  200. package/src/common-auth-embedded/settings/fs.js +19 -0
  201. package/src/common-auth-embedded/settings/handle.d.ts +30 -0
  202. package/src/common-auth-embedded/settings/handle.js +228 -0
  203. package/src/common-auth-embedded/settings/index.d.ts +10 -0
  204. package/src/common-auth-embedded/settings/index.js +7 -0
  205. package/src/common-auth-embedded/settings/lock-errors.js +15 -0
  206. package/src/common-auth-embedded/settings/move.d.ts +76 -0
  207. package/src/common-auth-embedded/settings/move.js +351 -0
  208. package/src/common-auth-embedded/settings/parse.d.ts +24 -0
  209. package/src/common-auth-embedded/settings/parse.js +65 -0
  210. package/src/common-auth-embedded/settings/paths.d.ts +12 -0
  211. package/src/common-auth-embedded/settings/paths.js +48 -0
  212. package/src/common-auth-embedded/settings/refusal.d.ts +7 -0
  213. package/src/common-auth-embedded/settings/refusal.js +15 -0
  214. package/src/common-auth-embedded/settings/resolve.d.ts +15 -0
  215. package/src/common-auth-embedded/settings/resolve.js +51 -0
  216. package/src/common-auth-embedded/settings/schema.d.ts +29 -0
  217. package/src/common-auth-embedded/settings/schema.js +81 -0
  218. package/src/common-auth-embedded/settings/snapshot.d.ts +24 -0
  219. package/src/common-auth-embedded/settings/snapshot.js +150 -0
  220. package/src/common-auth-embedded/settings/update.js +139 -0
  221. package/src/common-auth-embedded/settings/write.js +88 -0
  222. package/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  223. package/src/common-auth-embedded/setup/command-error.js +3 -2
  224. package/src/common-auth-embedded/setup/command.js +5 -1
  225. package/src/common-auth-embedded/setup/enroll.js +3 -3
  226. package/src/common-auth-embedded/setup/enrollment-access.js +13 -4
  227. package/src/common-auth-embedded/setup/types.d.ts +4 -0
  228. package/src/common-auth-embedded/source-output.json +297 -61
  229. package/src/common-auth-embedded/tui-prefs/watcher.js +196 -0
  230. package/src/tui-ga-compiled/host-ga.js +1 -1
  231. package/src/tui-ga-raw/host-ga.tsx +1 -1
@@ -1,4 +1,4 @@
1
- import type { AddInput, PoolLockSpec, PoolRow, PoolStore, RemoveOptions } from '../store/index.js';
1
+ import type { AddInput, PoolLockSpec, PoolRow, PoolSettings, PoolStore, RemoveOptions, SettingsMutator } from '../store/index.js';
2
2
  import type { CommandInvocation, KnobValues, MenuChoice, MenuKnob } from './model.js';
3
3
  import { type ResolvedSection } from './seam.js';
4
4
  /**
@@ -98,9 +98,28 @@ export interface LimitsSectionOptions {
98
98
  */
99
99
  labels?: readonly string[];
100
100
  }
101
+ /**
102
+ * Where the Routing and Limits sections read and write the settings they show
103
+ * (`routing.mode`, `routing.maxSameAccountWait`, `killswitch.enabled`,
104
+ * `killswitch.accounts`). Without a port they use the account store's own
105
+ * settings through `readSettings` and `updateSettings`. A plugin that moved
106
+ * its settings to its own file (`./settings`) passes a port that translates
107
+ * this store-shaped view to that file.
108
+ */
109
+ export interface BuiltinSettingsPort {
110
+ /** The current settings, in the store's settings shape. */
111
+ read(): Promise<PoolSettings>;
112
+ /**
113
+ * Apply one menu change. `mutator` gets a private copy in the store's shape
114
+ * and edits it in place or returns the whole next object, as with
115
+ * `updateSettings`. A refusal is thrown and shown as the action's failure.
116
+ */
117
+ update(mutator: SettingsMutator): Promise<void>;
118
+ }
101
119
  export interface BuiltinOptions {
102
120
  store: PoolStore;
103
121
  extraLocks?: readonly PoolLockSpec[];
122
+ settings?: BuiltinSettingsPort;
104
123
  now: () => number;
105
124
  accounts?: AccountsSectionOptions;
106
125
  quota?: QuotaSectionOptions;
@@ -65,15 +65,31 @@ function addedText(name, result) {
65
65
  function failureMessage(error) {
66
66
  return projectFailure(error).text;
67
67
  }
68
+ /** The plugin's settings port, or one over the account store's own settings. */
69
+ function settingsPort(options) {
70
+ if (options.settings)
71
+ return options.settings;
72
+ const { store, extraLocks } = options;
73
+ const locks = extraLocks ? { extraLocks } : {};
74
+ return {
75
+ async read() {
76
+ const read = await store.readSettings();
77
+ return read.status === 'error' ? {} : read.settings;
78
+ },
79
+ async update(mutator) {
80
+ await store.updateSettings(mutator, locks);
81
+ },
82
+ };
83
+ }
68
84
  async function snapshot(options) {
69
85
  const { store } = options;
70
86
  const load = await store.read();
71
- const read = await store.readSettings();
87
+ const settings = await settingsPort(options).read();
72
88
  const vault = await options.routing?.vaultOrder?.();
73
89
  return {
74
90
  load,
75
91
  rows: distinctRows(load),
76
- settings: read.status === 'error' ? {} : read.settings,
92
+ settings,
77
93
  ...(vault ? { vault } : {}),
78
94
  };
79
95
  }
@@ -396,6 +412,7 @@ function vaultNames(vault) {
396
412
  function routingSection(options, snap) {
397
413
  const { store, extraLocks } = options;
398
414
  const locks = extraLocks ? { extraLocks } : {};
415
+ const port = settingsPort(options);
399
416
  const choices = [
400
417
  { value: 'ordered', label: 'Ordered (roster order)' },
401
418
  ...(options.routing?.orderedVariants ?? []),
@@ -428,10 +445,10 @@ function routingSection(options, snap) {
428
445
  ],
429
446
  run: async ({ values }) => {
430
447
  const mode = String(values.mode);
431
- await store.updateSettings((settings) => {
448
+ await port.update((settings) => {
432
449
  settings.routing = { ...record(settings.routing), mode };
433
450
  return undefined;
434
- }, locks);
451
+ });
435
452
  return `Routing mode set to ${choices.find((choice) => choice.value === mode)?.label ?? mode}.`;
436
453
  },
437
454
  },
@@ -495,13 +512,13 @@ function routingSection(options, snap) {
495
512
  run: async ({ values }) => {
496
513
  const value = String(values.maxSameAccountWait);
497
514
  const maxSameAccountWait = value === 'max' ? 'max' : Number(value);
498
- await store.updateSettings((settings) => {
515
+ await port.update((settings) => {
499
516
  settings.routing = {
500
517
  ...record(settings.routing),
501
518
  maxSameAccountWait,
502
519
  };
503
520
  return undefined;
504
- }, locks);
521
+ });
505
522
  return `${waitLabel} set to ${waitName(value)}.`;
506
523
  },
507
524
  });
@@ -541,8 +558,7 @@ function floorNames(options, snap) {
541
558
  return (label) => names.get(label) ?? label;
542
559
  }
543
560
  function limitsSection(options, snap) {
544
- const { store, extraLocks } = options;
545
- const locks = extraLocks ? { extraLocks } : {};
561
+ const port = settingsPort(options);
546
562
  const killswitch = record(snap.settings.killswitch);
547
563
  const enabled = killswitch.enabled === true;
548
564
  const floors = record(killswitch.accounts);
@@ -577,7 +593,7 @@ function limitsSection(options, snap) {
577
593
  : {}),
578
594
  })),
579
595
  run: async ({ values }) => {
580
- await store.updateSettings((settings) => {
596
+ await port.update((settings) => {
581
597
  const next = record(settings.killswitch);
582
598
  const accounts = record(next.accounts);
583
599
  const mine = record(accounts[row.id]);
@@ -598,7 +614,7 @@ function limitsSection(options, snap) {
598
614
  delete next.accounts;
599
615
  settings.killswitch = next;
600
616
  return undefined;
601
- }, locks);
617
+ });
602
618
  return `Floors updated for ${name}.`;
603
619
  },
604
620
  },
@@ -628,13 +644,13 @@ function limitsSection(options, snap) {
628
644
  ],
629
645
  run: async ({ values }) => {
630
646
  const on = values.enabled === true;
631
- await store.updateSettings((settings) => {
647
+ await port.update((settings) => {
632
648
  settings.killswitch = {
633
649
  ...record(settings.killswitch),
634
650
  enabled: on,
635
651
  };
636
652
  return undefined;
637
- }, locks);
653
+ });
638
654
  return `Killswitch ${on ? 'on' : 'off'}.`;
639
655
  },
640
656
  },
@@ -1,4 +1,4 @@
1
- export type { AccountsSectionOptions, LimitsSectionOptions, LoginOutcome, QuotaSectionOptions, RoutingSectionOptions, VaultRoutingOrder, } from './builtins.js';
1
+ export type { AccountsSectionOptions, BuiltinSettingsPort, LimitsSectionOptions, LoginOutcome, QuotaSectionOptions, RoutingSectionOptions, VaultRoutingOrder, } from './builtins.js';
2
2
  export { MENU_DISABLED_REASON } from './builtins.js';
3
3
  export type { CommandMenu, CommandMenuOptions, StoreSectionSlot, } from './menu.js';
4
4
  export { createCommandMenu, parseApplyRequest } from './menu.js';
@@ -1,6 +1,6 @@
1
1
  import { type RedactionOptions } from '../logger/index.js';
2
2
  import type { PoolLockSpec, PoolStore } from '../store/index.js';
3
- import { type AccountsSectionOptions, type LimitsSectionOptions, type QuotaSectionOptions, type RoutingSectionOptions } from './builtins.js';
3
+ import { type AccountsSectionOptions, type BuiltinSettingsPort, type LimitsSectionOptions, type QuotaSectionOptions, type RoutingSectionOptions } from './builtins.js';
4
4
  import type { CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, PluginExtraSection, PluginSection } from './model.js';
5
5
  import { type SeamLogger } from './seam.js';
6
6
  /** The four slots the library can build from a pool store. */
@@ -25,6 +25,11 @@ export interface CommandMenuOptions {
25
25
  replace?: Partial<Record<StoreSectionSlot, PluginSection>>;
26
26
  /** The plugin's legacy locks, passed to every store write the menu makes. */
27
27
  extraLocks?: readonly PoolLockSpec[];
28
+ /**
29
+ * Where the Routing and Limits sections read and write their settings. Omit
30
+ * it to use the store's own settings, as before.
31
+ */
32
+ settings?: BuiltinSettingsPort;
28
33
  accounts?: AccountsSectionOptions;
29
34
  quota?: QuotaSectionOptions;
30
35
  routing?: RoutingSectionOptions;
@@ -156,6 +156,7 @@ export function createCommandMenu(options) {
156
156
  store,
157
157
  now,
158
158
  ...(options.extraLocks ? { extraLocks: options.extraLocks } : {}),
159
+ ...(options.settings ? { settings: options.settings } : {}),
159
160
  ...(options.accounts ? { accounts: options.accounts } : {}),
160
161
  ...(options.quota ? { quota: options.quota } : {}),
161
162
  ...(options.routing ? { routing: options.routing } : {}),
@@ -1,10 +1,10 @@
1
1
  import { lstat, stat } from 'node:fs/promises';
2
2
  import { resolve } from 'node:path';
3
- async function identity(path, followSymlinks) {
3
+ async function identity(path, probe) {
4
4
  try {
5
5
  // Match the reader: private readers reject links, while readFile follows
6
6
  // them and needs the target's identity, not the link's identity.
7
- const metadata = await (followSymlinks ? stat(path) : lstat(path));
7
+ const metadata = await probe(path);
8
8
  return metadata.isFile() ? metadata : undefined;
9
9
  }
10
10
  catch (error) {
@@ -24,15 +24,19 @@ function sameIdentity(left, right) {
24
24
  }
25
25
  /** Process-local reads, capped at 64 path sets with one value per resolved set. */
26
26
  export class FileReadCache {
27
- #followSymlinks;
27
+ #probe;
28
28
  #entries = new Map();
29
29
  constructor(options = {}) {
30
- this.#followSymlinks = options.followSymlinks ?? false;
30
+ // Look the probe up on every call, not once here: tests replace the
31
+ // node:fs/promises functions (and SettingsFs methods) after caches exist.
32
+ this.#probe = options.followSymlinks
33
+ ? (path) => (options.stat ?? stat)(path)
34
+ : (path) => (options.lstat ?? lstat)(path);
31
35
  }
32
36
  async read(paths, read, validateHit) {
33
37
  const resolvedPaths = paths.map((path) => resolve(path));
34
38
  const key = JSON.stringify(resolvedPaths);
35
- const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#followSymlinks)));
39
+ const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#probe)));
36
40
  const identities = probed.every((entry) => entry !== undefined)
37
41
  ? probed
38
42
  : undefined;
@@ -4,6 +4,17 @@ type LeaseCreationTestHooks = {
4
4
  };
5
5
  /** Test-only creation faults; not re-exported from the public fs entry point. */
6
6
  export declare function setLeaseCreationTestHooksForTest(hooks?: LeaseCreationTestHooks): void;
7
+ type StagingSweepTestHooks = {
8
+ readdir?: (directory: string) => Promise<string[]>;
9
+ beforeUnlink?: (path: string) => void | Promise<void>;
10
+ unlink?: (path: string) => Promise<void>;
11
+ };
12
+ /** Test-only sweep faults; not re-exported from the public fs entry point. */
13
+ export declare function setStagingSweepTestHooksForTest(hooks?: StagingSweepTestHooks): void;
14
+ /** Tests only: wait for every staging sweep started so far to finish. */
15
+ export declare function settleStagingSweepsForTest(): Promise<void>;
16
+ /** Tests only: let the next acquisition of every lock path sweep again. */
17
+ export declare function forgetStagingSweepsForTest(): void;
7
18
  export declare function isLostMarkerRaceError(error: unknown): boolean;
8
19
  /** Test-only fault injection between marker mkdir and owner.json write. */
9
20
  export interface EvictionMarkerTestHooks {
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { link, lstat, mkdir, open, readFile, rename, rm, stat, } from 'node:fs/promises';
3
- import { dirname, join } from 'node:path';
2
+ import { link, lstat, mkdir, open, readdir, readFile, rename, rm, stat, unlink, } from 'node:fs/promises';
3
+ import { basename, dirname, join } from 'node:path';
4
+ import { createLogger } from '../logger/index.js';
4
5
  import { DisappearedLockRecordError, isWindowsAccessDeniedCreate, isWindowsAccessDeniedRead, readLockRecord, } from './lock-record.js';
5
6
  import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, isWindowsSharingViolation, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from './private-files.js';
6
7
  import { LockOwnershipError, lockPathFor } from './with-lock.js';
@@ -91,6 +92,149 @@ async function writeExclusiveText(path, text) {
91
92
  await handle.close();
92
93
  }
93
94
  }
95
+ // Lease owner records are staged in sibling files named
96
+ // `<lock file name>.<random UUID>.tmp` before they are linked or renamed into
97
+ // place: by createExclusiveText and by renewal, whose Windows branch uses
98
+ // writePrivateAtomic's default staging name of the same shape. Each writer
99
+ // removes its staging file when it finishes, but a process killed between
100
+ // creating the file and that cleanup leaves it behind for good, since nothing
101
+ // else ever reads that name. The sweep below removes only such leftovers.
102
+ const STAGING_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
103
+ // A staging file records the expiry of the lease it was about to publish,
104
+ // which is always in the future while its writer is alive. Requiring the
105
+ // expiry to be at least a lease TTL in the past, and never less than this
106
+ // floor, keeps a live writer's file safe even if wall clocks disagree.
107
+ const STAGING_SWEEP_MIN_AGE_MS = 10 * 60_000;
108
+ // Bounds the work one sweep does; any remainder is left for a later process.
109
+ const STAGING_SWEEP_MAX_CANDIDATES = 256;
110
+ // A complete owner record is under 100 bytes; anything far larger is not one.
111
+ const STAGING_SWEEP_MAX_BYTES = 4_096;
112
+ // Lock paths already swept by this process. Sweeping once per process keeps
113
+ // the directory listing off the hot path of every later acquisition.
114
+ const sweptLockPaths = new Set();
115
+ const pendingStagingSweeps = new Set();
116
+ let stagingSweepTestHooks;
117
+ /** Test-only sweep faults; not re-exported from the public fs entry point. */
118
+ export function setStagingSweepTestHooksForTest(hooks) {
119
+ stagingSweepTestHooks = hooks;
120
+ }
121
+ /** Tests only: wait for every staging sweep started so far to finish. */
122
+ export async function settleStagingSweepsForTest() {
123
+ while (pendingStagingSweeps.size > 0)
124
+ await Promise.all([...pendingStagingSweeps]);
125
+ }
126
+ /** Tests only: let the next acquisition of every lock path sweep again. */
127
+ export function forgetStagingSweepsForTest() {
128
+ sweptLockPaths.clear();
129
+ }
130
+ function isStagingName(name, lockName) {
131
+ const prefix = `${lockName}.`;
132
+ const suffix = '.tmp';
133
+ if (!name.startsWith(prefix) || !name.endsWith(suffix))
134
+ return false;
135
+ return STAGING_UUID.test(name.slice(prefix.length, -suffix.length));
136
+ }
137
+ function sameStagingFile(a, b) {
138
+ return (a.dev === b.dev &&
139
+ a.ino === b.ino &&
140
+ a.size === b.size &&
141
+ a.mtimeMs === b.mtimeMs &&
142
+ a.birthtimeMs === b.birthtimeMs);
143
+ }
144
+ /**
145
+ * Read the owner record a staging file holds, or undefined when the path is
146
+ * not a plain file holding exactly a complete `{ownerId, expiresAt}` record.
147
+ * Returns the lstat identity the record was read from, for the unlink fence.
148
+ */
149
+ async function readStagedOwner(path) {
150
+ const before = await lstat(path);
151
+ if (!before.isFile() || before.isSymbolicLink())
152
+ return undefined;
153
+ if (before.size > STAGING_SWEEP_MAX_BYTES)
154
+ return undefined;
155
+ const handle = await open(path, 'r');
156
+ let text;
157
+ try {
158
+ // The path could be swapped between the lstat and the open; read only
159
+ // when the opened file is the one the lstat described.
160
+ if (!sameStagingFile(before, await handle.stat()))
161
+ return undefined;
162
+ text = await handle.readFile('utf8');
163
+ }
164
+ finally {
165
+ await handle.close();
166
+ }
167
+ let record;
168
+ try {
169
+ record = JSON.parse(text);
170
+ }
171
+ catch {
172
+ return undefined;
173
+ }
174
+ if (!record || typeof record !== 'object' || Array.isArray(record))
175
+ return undefined;
176
+ const keys = Object.keys(record).sort();
177
+ if (keys.length !== 2 || keys[0] !== 'expiresAt' || keys[1] !== 'ownerId')
178
+ return undefined;
179
+ const { ownerId, expiresAt } = record;
180
+ if (typeof ownerId !== 'string' || !STAGING_UUID.test(ownerId))
181
+ return undefined;
182
+ if (typeof expiresAt !== 'number' || !Number.isFinite(expiresAt))
183
+ return undefined;
184
+ return { identity: before, expiresAt };
185
+ }
186
+ async function sweepAbandonedStaging(lockPath, ttlMs, now) {
187
+ const directory = dirname(lockPath);
188
+ const lockName = basename(lockPath);
189
+ const hooks = stagingSweepTestHooks;
190
+ const names = await (hooks?.readdir ?? readdir)(directory);
191
+ const candidates = names
192
+ .filter((name) => isStagingName(name, lockName))
193
+ .slice(0, STAGING_SWEEP_MAX_CANDIDATES);
194
+ const marginMs = Math.max(Number.isFinite(ttlMs) ? ttlMs : 0, STAGING_SWEEP_MIN_AGE_MS);
195
+ for (const name of candidates) {
196
+ const path = join(directory, name);
197
+ try {
198
+ // A file written within the margin belongs to a writer that may be
199
+ // alive, so don't even open it; the record's expiry still decides.
200
+ if (now() - (await lstat(path)).mtimeMs < marginMs)
201
+ continue;
202
+ const staged = await readStagedOwner(path);
203
+ if (!staged || !(staged.expiresAt < now() - marginMs))
204
+ continue;
205
+ if (hooks?.beforeUnlink)
206
+ await hooks.beforeUnlink(path);
207
+ // Remove only the file that was read: a name reused since then keeps
208
+ // its new contents. Inode numbers can be reused at once after an
209
+ // unlink, so the record is read again as well as the identity compared.
210
+ const current = await readStagedOwner(path);
211
+ if (!current ||
212
+ !sameStagingFile(staged.identity, current.identity) ||
213
+ !(current.expiresAt < now() - marginMs))
214
+ continue;
215
+ await (hooks?.unlink ?? unlink)(path);
216
+ }
217
+ catch {
218
+ // Each leftover is independent; a vanished or unreadable one is skipped.
219
+ }
220
+ }
221
+ }
222
+ /**
223
+ * Start a background sweep of abandoned staging files beside `lockPath`, at
224
+ * most once per process per lock path. Called after this process acquires the
225
+ * lock, so no other cooperating process sweeps the same name at that moment.
226
+ * The sweep never delays or fails the acquisition: every error is ignored.
227
+ */
228
+ function startStagingSweep(lockPath, ttlMs, now) {
229
+ if (sweptLockPaths.has(lockPath))
230
+ return;
231
+ sweptLockPaths.add(lockPath);
232
+ const sweep = Promise.resolve()
233
+ .then(() => sweepAbandonedStaging(lockPath, ttlMs, now))
234
+ .catch(() => { });
235
+ pendingStagingSweeps.add(sweep);
236
+ void sweep.finally(() => pendingStagingSweeps.delete(sweep));
237
+ }
94
238
  const setRefreshLockRenewalTimeout = globalThis.setTimeout.bind(globalThis);
95
239
  const clearRefreshLockRenewalTimeout = globalThis.clearTimeout.bind(globalThis);
96
240
  // A concurrent contender renaming the freshly-created eviction-marker directory
@@ -970,6 +1114,7 @@ export async function acquireRefreshFileLockWithClock(options) {
970
1114
  return null;
971
1115
  }
972
1116
  scheduleRenewal();
1117
+ startStagingSweep(lockPath, options.ttlMs, now);
973
1118
  return {
974
1119
  ownerId,
975
1120
  whenLost: () => lostPromise,
@@ -1047,17 +1192,17 @@ export async function acquireRefreshFileLockWithClock(options) {
1047
1192
  removalConfirmed = true;
1048
1193
  }, deadline);
1049
1194
  changingRecordError = undefined;
1050
- if (markerAcquired) {
1051
- if (windowsPrivateFiles && !removalConfirmed)
1052
- throw new PrivateFileError(lockPath, 'release-not-confirmed', {
1053
- code: 'EIO',
1054
- });
1055
- releaseConfirmed = removalConfirmed;
1195
+ // Acquiring the marker does not confirm removal: stale-marker
1196
+ // recovery can take it away after the lease owner was checked.
1197
+ if (markerAcquired && removalConfirmed) {
1198
+ releaseConfirmed = true;
1056
1199
  return;
1057
1200
  }
1058
- if (signal?.aborted)
1059
- return;
1060
- await recoverStaleEvictionMarker(deadline);
1201
+ if (!markerAcquired) {
1202
+ if (signal?.aborted)
1203
+ return;
1204
+ await recoverStaleEvictionMarker(deadline);
1205
+ }
1061
1206
  }
1062
1207
  catch (error) {
1063
1208
  const changingRecord = windowsPrivateFiles &&
@@ -1098,6 +1243,9 @@ export async function acquireRefreshFileLockWithClock(options) {
1098
1243
  new PrivateFileError(lockPath, 'release-not-confirmed', {
1099
1244
  code: 'ETIMEDOUT',
1100
1245
  }));
1246
+ createLogger('fs').warn('File lock release deadline expired', {
1247
+ lockPath,
1248
+ });
1101
1249
  },
1102
1250
  };
1103
1251
  }
@@ -1,3 +1,4 @@
1
+ import { type PrivateFileError } from './private-files.js';
1
2
  import { acquireRefreshFileLock } from './refresh-file-lock.js';
2
3
  export declare function lockPathFor(target: string, name: string): string;
3
4
  export declare class LockContentionError extends Error {
@@ -32,6 +33,7 @@ export interface LockOptions {
32
33
  onStep?: Parameters<typeof acquireRefreshFileLock>[0]['onStep'];
33
34
  onRenewalTimer?: Parameters<typeof acquireRefreshFileLock>[0]['onRenewalTimer'];
34
35
  }
36
+ export declare function isChangingLockRecord(error: unknown, target: string, name: string): error is PrivateFileError;
35
37
  export declare function withLock<T>(target: string, options: LockOptions, fn: (lock: {
36
38
  assertOwned(): Promise<void>;
37
39
  }) => Promise<T>): Promise<T>;
@@ -21,7 +21,7 @@ export class LockOwnershipError extends Error {
21
21
  this.details = details;
22
22
  }
23
23
  }
24
- function isChangingLockRecord(error, target, name) {
24
+ export function isChangingLockRecord(error, target, name) {
25
25
  const path = resolve(lockPathFor(target, name));
26
26
  const paths = [path, join(path, 'owner.json')];
27
27
  return (((isWindowsSharingViolation(error) ||
@@ -12,14 +12,16 @@ export interface RoutingCandidate {
12
12
  accountId: string;
13
13
  credentialId: string;
14
14
  }
15
- export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidate> {
15
+ export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidate, Refusals extends boolean = false> {
16
16
  sessionId: string;
17
17
  provider: string;
18
18
  modelId: string;
19
19
  /** Only routes already eligible under the plugin's vault and killswitch rules. */
20
20
  candidates: readonly Candidate[];
21
- /** Defaults to 500 ms, clamped to 1–2000 ms. */
21
+ /** Defaults to 1500 ms, above routing's normal tail; clamped to 1–2000 ms. */
22
22
  deadlineMs?: number;
23
+ /** Opt in to refusals, which stop the request instead of using a local choice. */
24
+ refusals?: Refusals;
23
25
  /**
24
26
  * Longest same-account hold, in seconds, that routing may advise. The
25
27
  * holdWaitMaxS helper from `./limits` caps it by the setting and the current
@@ -38,6 +40,14 @@ export interface RoutingSelection<Candidate extends RoutingCandidate = RoutingCa
38
40
  candidate: Candidate;
39
41
  hold?: RoutingHold;
40
42
  }
43
+ export type RoutingRefusal = {
44
+ refused: {
45
+ code: 'account_limit_exhausted' | 'account_selection_refused' | 'account_selection_final';
46
+ routingCode?: string;
47
+ retryAfterSecs?: number;
48
+ resetsAtMs?: number;
49
+ };
50
+ };
41
51
  interface RoutingReportIdentity {
42
52
  sessionId: string;
43
53
  accountId: string;
@@ -77,6 +87,23 @@ export type ReportRoutingInput = (RoutingReportIdentity & ({
77
87
  pool?: string;
78
88
  /** Optional reset time in epoch milliseconds. */
79
89
  resetsAt?: number;
90
+ } | {
91
+ /**
92
+ * A provider's typed refusal that condemns the API key until it is
93
+ * topped up, such as an exhausted prepaid balance. Never use for
94
+ * 401, 403 or short rate limits.
95
+ */
96
+ outcome: 'credential_refused';
97
+ credentialId: string;
98
+ /**
99
+ * What the provider actually sent: its own code from the structured
100
+ * error (OpenRouter's `openrouter_credits`). When the body carries
101
+ * no code, `http_<status>`, but only for a status the provider
102
+ * documents with a single balance meaning (DeepSeek's `http_402`).
103
+ * Never message text, and never a status with several meanings such
104
+ * as 403 or 429. Must match `^[a-z0-9._-]{1,64}$`.
105
+ */
106
+ providerCode: string;
80
107
  })) | {
81
108
  sessionId: string;
82
109
  kind: 'turn_notes_supported';
@@ -128,10 +155,11 @@ export declare function turnNotes(sessionId: string): readonly {
128
155
  }[];
129
156
  /**
130
157
  * Ask routing for an eligible vault route. Any failure or unfamiliar answer
131
- * yields undefined so the plugin can keep its own choice. This does not admit
132
- * routes: callers must exclude vault refusals and killswitch-blocked accounts.
158
+ * yields undefined so the plugin can keep its own choice. Opted-in routing
159
+ * refusals instead stop the request. This does not admit routes: callers must
160
+ * exclude vault refusals and killswitch-blocked accounts.
133
161
  */
134
- export declare function askRouting<Candidate extends RoutingCandidate>(input: AskRoutingInput<Candidate>): Promise<RoutingSelection<Candidate> | undefined>;
162
+ export declare function askRouting<Candidate extends RoutingCandidate, Refusals extends boolean = false>(input: AskRoutingInput<Candidate, Refusals>): Promise<RoutingSelection<Candidate> | (Refusals extends true ? RoutingRefusal : never) | undefined>;
135
163
  /**
136
164
  * Report a vault request, billing result or turn-note event without waiting for
137
165
  * routing. Only contract fields are sent, and all accessor failures are ignored.
@@ -136,11 +136,35 @@ function selectionFor(answer, candidates) {
136
136
  }
137
137
  return { candidate };
138
138
  }
139
- /**
140
- * Ask routing for an eligible vault route. Any failure or unfamiliar answer
141
- * yields undefined so the plugin can keep its own choice. This does not admit
142
- * routes: callers must exclude vault refusals and killswitch-blocked accounts.
143
- */
139
+ function refusalFor(value) {
140
+ if (!isObject(value))
141
+ return undefined;
142
+ const code = value.code;
143
+ if (code !== 'account_limit_exhausted' &&
144
+ code !== 'account_selection_refused' &&
145
+ code !== 'account_selection_final') {
146
+ return undefined;
147
+ }
148
+ const refused = { code };
149
+ const routingCode = value.routing_code;
150
+ if (typeof routingCode === 'string' &&
151
+ /^[a-z0-9._-]{1,64}$/.test(routingCode)) {
152
+ refused.routingCode = routingCode;
153
+ }
154
+ const retryAfterSecs = value.retry_after_secs;
155
+ if (typeof retryAfterSecs === 'number' &&
156
+ Number.isFinite(retryAfterSecs) &&
157
+ retryAfterSecs >= 0) {
158
+ refused.retryAfterSecs = retryAfterSecs;
159
+ }
160
+ const resetsAtMs = value.resets_at_ms;
161
+ if (typeof resetsAtMs === 'number' &&
162
+ Number.isSafeInteger(resetsAtMs) &&
163
+ resetsAtMs > 0) {
164
+ refused.resetsAtMs = resetsAtMs;
165
+ }
166
+ return { refused };
167
+ }
144
168
  export async function askRouting(input) {
145
169
  let timer;
146
170
  try {
@@ -150,9 +174,9 @@ export async function askRouting(input) {
150
174
  const accountFor = handle.accountFor;
151
175
  if (typeof accountFor !== 'function')
152
176
  return undefined;
153
- const requested = input.deadlineMs ?? 500;
177
+ const requested = input.deadlineMs ?? 1500;
154
178
  const deadlineMs = Number.isNaN(requested)
155
- ? 500
179
+ ? 1500
156
180
  : Math.min(2000, Math.max(1, requested));
157
181
  const expired = new Promise((resolve) => {
158
182
  timer = setTimeout(() => resolve(undefined), deadlineMs);
@@ -166,10 +190,15 @@ export async function askRouting(input) {
166
190
  if (typeof cap === 'number' && Number.isFinite(cap)) {
167
191
  request.hold_wait_max_s = Math.max(0, Math.floor(cap));
168
192
  }
193
+ if (input.refusals === true)
194
+ request.refusals = true;
169
195
  const pending = accountFor.call(handle, request, { deadlineMs });
170
196
  if (!isObject(pending) || typeof pending.then !== 'function')
171
197
  return undefined;
172
198
  const answer = await Promise.race([pending, expired]);
199
+ if (input.refusals === true && isObject(answer) && 'refused' in answer) {
200
+ return refusalFor(answer.refused);
201
+ }
173
202
  return selectionFor(answer, input.candidates);
174
203
  }
175
204
  catch {
@@ -334,6 +363,19 @@ export function reportRouting(input) {
334
363
  };
335
364
  break;
336
365
  }
366
+ case 'credential_refused': {
367
+ const { credentialId, providerCode } = input;
368
+ if (!isNonEmptyString(credentialId) ||
369
+ typeof providerCode !== 'string' ||
370
+ !/^[a-z0-9._-]{1,64}$/.test(providerCode))
371
+ return;
372
+ payload = {
373
+ ...identity,
374
+ outcome: 'credential_refused',
375
+ provider_code: providerCode,
376
+ };
377
+ break;
378
+ }
337
379
  default:
338
380
  return;
339
381
  }
@@ -0,0 +1,35 @@
1
+ import { type ValueDescriptor, type ValueOf, type ValueValidationOptions } from './descriptors.js';
2
+ export interface SettingDeclaration<D extends ValueDescriptor = ValueDescriptor> {
3
+ readonly value: D;
4
+ readonly default: ValueDescriptor extends D ? unknown : ValueOf<D>;
5
+ readonly hosts: 'both' | 'opencode' | 'pi' | string;
6
+ readonly overrides?: {
7
+ readonly host?: true;
8
+ readonly model?: true;
9
+ };
10
+ readonly project?: 'user-only' | 'allowed';
11
+ readonly legacy?: readonly {
12
+ readonly source: string;
13
+ readonly path: readonly string[];
14
+ }[];
15
+ }
16
+ type Declarations = Readonly<Record<string, SettingDeclaration>>;
17
+ export interface SettingsDefinition<S extends Declarations = Declarations> {
18
+ readonly plugin: string;
19
+ readonly settings: {
20
+ readonly [K in keyof S]: S[K] & {
21
+ readonly project: S[K] extends {
22
+ readonly project: infer P;
23
+ } ? P : 'project' extends keyof S[K] ? Exclude<S[K]['project'], undefined> | 'user-only' : 'user-only';
24
+ };
25
+ };
26
+ }
27
+ export declare function defineSettings<const S extends Declarations>(definition: {
28
+ readonly plugin: string;
29
+ readonly settings: S;
30
+ }): SettingsDefinition<S>;
31
+ /** Internal helper: host names are reserved and never count as model ids. */
32
+ export declare function isOverrideKeyAllowed(overrides: NonNullable<SettingDeclaration['overrides']>, key: string): boolean;
33
+ /** Validate a file, update or map value, including any permitted override object. */
34
+ export declare function validateSettingValue(declaration: Pick<SettingDeclaration, 'value' | 'overrides'>, value: unknown, options?: ValueValidationOptions): boolean;
35
+ export {};