sideby 0.35.8 → 0.36.0

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 (71) hide show
  1. package/dist/build.json +1 -1
  2. package/dist/src/cli/commands.d.ts +12 -0
  3. package/dist/src/cli/commands.js +480 -6
  4. package/dist/src/cli/format.d.ts +12 -1
  5. package/dist/src/cli/format.js +23 -3
  6. package/dist/src/cli/json-schemas.js +166 -1
  7. package/dist/src/cli/main.js +18 -4
  8. package/dist/src/core/advisor.d.ts +176 -0
  9. package/dist/src/core/advisor.js +472 -0
  10. package/dist/src/core/after-install.js +11 -4
  11. package/dist/src/core/ask.d.ts +6 -1
  12. package/dist/src/core/ask.js +16 -5
  13. package/dist/src/core/browser-profiles.d.ts +16 -0
  14. package/dist/src/core/browser-profiles.js +45 -0
  15. package/dist/src/core/cli-commands.js +25 -1
  16. package/dist/src/core/config.d.ts +29 -0
  17. package/dist/src/core/config.js +25 -0
  18. package/dist/src/core/handoff-select.d.ts +13 -2
  19. package/dist/src/core/handoff-select.js +6 -2
  20. package/dist/src/core/launch.d.ts +4 -0
  21. package/dist/src/core/launch.js +7 -0
  22. package/dist/src/core/limit-reset.d.ts +198 -0
  23. package/dist/src/core/limit-reset.js +299 -0
  24. package/dist/src/core/local-build.d.ts +4 -3
  25. package/dist/src/core/local-build.js +6 -4
  26. package/dist/src/core/quota-fetch.d.ts +57 -2
  27. package/dist/src/core/quota-fetch.js +291 -13
  28. package/dist/src/core/quota-levels.d.ts +70 -0
  29. package/dist/src/core/quota-levels.js +80 -0
  30. package/dist/src/core/quota-store.d.ts +15 -1
  31. package/dist/src/core/quota-store.js +26 -1
  32. package/dist/src/core/same-login.d.ts +8 -0
  33. package/dist/src/core/same-login.js +39 -2
  34. package/dist/src/core/search-catalog.js +38 -0
  35. package/dist/src/families/claude/index.js +2 -0
  36. package/dist/src/families/codex/index.js +3 -1
  37. package/dist/src/families/codex/quota.d.ts +23 -1
  38. package/dist/src/families/codex/quota.js +122 -21
  39. package/dist/src/families/grok/quota-log.d.ts +1 -0
  40. package/dist/src/menubar/script.js +70 -18
  41. package/dist/src/menubar/snapshot.d.ts +33 -1
  42. package/dist/src/menubar/snapshot.js +79 -11
  43. package/dist/src/menubar/strings.d.ts +16 -0
  44. package/dist/src/menubar/strings.js +16 -0
  45. package/dist/src/panel/handler.d.ts +21 -0
  46. package/dist/src/panel/handler.js +111 -9
  47. package/dist/src/panel/i18n.d.ts +87 -0
  48. package/dist/src/panel/i18n.js +174 -0
  49. package/dist/src/panel/page-logic.d.ts +17 -0
  50. package/dist/src/panel/page-logic.js +23 -0
  51. package/dist/src/panel/page-script.js +440 -19
  52. package/dist/src/panel/page-styles.js +38 -2
  53. package/dist/src/plugins/loader.d.ts +2 -0
  54. package/dist/src/plugins/loader.js +27 -0
  55. package/dist/src/runtime.d.ts +63 -1
  56. package/dist/src/runtime.js +529 -9
  57. package/dist/src/types.d.ts +67 -0
  58. package/package.json +1 -1
  59. package/schemas/advisor.json +332 -0
  60. package/schemas/config.json +22 -0
  61. package/schemas/error.json +4 -0
  62. package/schemas/menubar-reset.json +93 -0
  63. package/schemas/menubar-snapshot.json +70 -2
  64. package/schemas/quota-reset.json +369 -0
  65. package/schemas/quota.json +30 -0
  66. package/schemas/update.json +4 -0
  67. package/skills/sideby/SKILL.md +6 -2
  68. package/skills/sideby/references/ai-tasks.md +1 -1
  69. package/skills/sideby/references/panel.md +14 -0
  70. package/skills/sideby/references/quota.md +27 -0
  71. package/skills/sideby/references/update.md +1 -1
@@ -87,6 +87,18 @@ export const CLI_COMMANDS = [
87
87
  },
88
88
  example: 'sideby model claude:work',
89
89
  },
90
+ {
91
+ id: 'advisor',
92
+ group: 'accounts',
93
+ usage: 'sideby advisor [fable|opus|sonnet|off|undo] [--account <account>] [--yes]',
94
+ help: "let Claude ask a stronger model for advice at key moments: sets Claude Code's advisor in every Claude settings file and unlocks /advisor in sessions sideby starts (shows the change first; unlock on|off toggles only the unlocking)",
95
+ summary: {
96
+ en: 'Let Claude ask a stronger model for advice at key moments',
97
+ zh: '让 Claude 在关键时刻请教更强的模型',
98
+ },
99
+ example: 'sideby advisor opus',
100
+ feature: 'setting.advisor',
101
+ },
90
102
  {
91
103
  id: 'edit',
92
104
  group: 'accounts',
@@ -331,6 +343,18 @@ export const CLI_COMMANDS = [
331
343
  help: 'undo it, restoring the original file',
332
344
  summary: { en: 'Undo the Claude quota setup', zh: '撤销 Claude 额度设置,恢复原文件' },
333
345
  },
346
+ {
347
+ id: 'quota.reset',
348
+ group: 'quota',
349
+ usage: 'sideby quota reset <account> [--yes] [--operation <id>] [--open]',
350
+ help: 'use a limit reset: shows the plan first, --yes uses one (cannot be undone); for Claude Code it names the page on claude.ai and --open opens it',
351
+ summary: {
352
+ en: 'Use a limit reset (shows the plan first; cannot be undone)',
353
+ zh: '使用一次重置(先给你看计划;用了不能撤销)',
354
+ },
355
+ example: 'sideby quota reset codex:main',
356
+ feature: 'action.limit-reset',
357
+ },
334
358
  {
335
359
  id: 'quota.check',
336
360
  group: 'quota',
@@ -828,7 +852,7 @@ export function cliHelp(list = CLI_COMMANDS) {
828
852
  return parts.join('\n');
829
853
  }
830
854
  const HELP_TAIL = `Options:
831
- --json machine-readable output (list, new, next, alias, doctor, quota, tune, model, remote-control, handoff,
855
+ --json machine-readable output (list, new, next, alias, doctor, quota, tune, model, advisor, remote-control, handoff,
832
856
  families, commands, plugins, app, desktop, sessions, history, send, messages, edit, browser, update, local, ask,
833
857
  terminal, key, try, autostart, menubar, config, network, unattended)
834
858
  -h, --help show this help; \`sideby <command> --help\` for new, alias, login, doctor, families, commands, desktop, edit, browser,
@@ -118,6 +118,12 @@ export declare const ConfigSchema: Type.TObject<{
118
118
  guard: Type.TOptional<Type.TBoolean>;
119
119
  allow: Type.TOptional<Type.TArray<Type.TString>>;
120
120
  }>>;
121
+ advisor: Type.TOptional<Type.TObject<{
122
+ unlock: Type.TOptional<Type.TBoolean>;
123
+ }>>;
124
+ claude: Type.TOptional<Type.TObject<{
125
+ apiBetasOff: Type.TOptional<Type.TBoolean>;
126
+ }>>;
121
127
  unattended: Type.TOptional<Type.TObject<{
122
128
  schedule: Type.TOptional<Type.TArray<Type.TObject<{
123
129
  name: Type.TOptional<Type.TString>;
@@ -187,6 +193,29 @@ export declare function editConfigNetwork(file: string, edit: (current: NetworkC
187
193
  before: NetworkConfig | undefined;
188
194
  after: NetworkConfig | undefined;
189
195
  }>;
196
+ export type AdvisorConfig = NonNullable<Config['advisor']>;
197
+ /**
198
+ * `sideby advisor` and the Panel's Advisor dialog (spec §3.41): changes the config `advisor` key with `edit` (see
199
+ * `editConfigKey` for how the file is written); `edit` returns undefined to remove the section. With `dryRun`, shows
200
+ * the change without writing.
201
+ */
202
+ export declare function editConfigAdvisor(file: string, edit: (current: AdvisorConfig) => AdvisorConfig | undefined, opts?: {
203
+ dryRun?: boolean;
204
+ }): Promise<{
205
+ changed: boolean;
206
+ before: AdvisorConfig | undefined;
207
+ after: AdvisorConfig | undefined;
208
+ }>;
209
+ export type ClaudeConfig = NonNullable<Config['claude']>;
210
+ /**
211
+ * The config `claude` key (spec §3.41): changed with `edit` (see `editConfigKey` for how the file is written); `edit`
212
+ * returns undefined to remove the section, or null to leave the file as it is.
213
+ */
214
+ export declare function editConfigClaude(file: string, edit: (current: ClaudeConfig) => ClaudeConfig | undefined | null): Promise<{
215
+ changed: boolean;
216
+ before: ClaudeConfig | undefined;
217
+ after: ClaudeConfig | undefined;
218
+ }>;
190
219
  export type UnattendedConfig = NonNullable<Config['unattended']>;
191
220
  /**
192
221
  * `sideby unattended on|schedule …` (spec §3.37): changes the config `unattended` key with `edit` (see `editConfigKey`
@@ -241,6 +241,16 @@ export const ConfigSchema = Type.Object({
241
241
  description: 'Countries (ISO 3166-1 alpha-2, such as `US` or `JP`) a Host may send requests from. Network Guard cannot be turned on while it is empty.',
242
242
  })),
243
243
  }, { additionalProperties: false, description: 'Network Guard (spec §3.35, ADR-0053).' })),
244
+ advisor: Type.Optional(Type.Object({
245
+ unlock: Type.Optional(Type.Boolean({
246
+ description: "Unlock Claude Code's advisor (`/advisor`) in the sessions sideby starts for Claude subscription accounts, by setting `CLAUDE_CODE_ENABLE_EXPERIMENTAL_ADVISOR_TOOL=1` at launch (never when `CLAUDE_CODE_DISABLE_ADVISOR_TOOL` is set). Off by default; choosing a model with `sideby advisor <model>` turns it on.",
247
+ })),
248
+ }, { additionalProperties: false, description: 'Advisor (spec §3.41, ADR-0074).' })),
249
+ claude: Type.Optional(Type.Object({
250
+ apiBetasOff: Type.Optional(Type.Boolean({
251
+ description: "Give Claude API accounts `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` when sideby starts them, for gateways that reject Claude Code's `anthropic-beta` headers. The account's own proxy.env and a value already in the environment win. Off by default; `sideby advisor <model>` turns it on when it removes that variable from a settings file API accounts share.",
252
+ })),
253
+ }, { additionalProperties: false, description: 'Claude Code launches (spec §3.41, ADR-0074).' })),
244
254
  unattended: Type.Optional(Type.Object({
245
255
  schedule: Type.Optional(Type.Array(UnattendedSlotSchema, {
246
256
  description: "Slots that turn Unattended Mode on and off by themselves, in this computer's time zone. Empty by default.",
@@ -467,6 +477,21 @@ export function editConfigUpdate(file, edit, opts = {}) {
467
477
  export function editConfigNetwork(file, edit, opts = {}) {
468
478
  return editConfigKey(file, 'network', 'change the setting', (current) => edit(current ?? {}), opts);
469
479
  }
480
+ /**
481
+ * `sideby advisor` and the Panel's Advisor dialog (spec §3.41): changes the config `advisor` key with `edit` (see
482
+ * `editConfigKey` for how the file is written); `edit` returns undefined to remove the section. With `dryRun`, shows
483
+ * the change without writing.
484
+ */
485
+ export function editConfigAdvisor(file, edit, opts = {}) {
486
+ return editConfigKey(file, 'advisor', 'change the setting', (current) => edit(current ?? {}), opts);
487
+ }
488
+ /**
489
+ * The config `claude` key (spec §3.41): changed with `edit` (see `editConfigKey` for how the file is written); `edit`
490
+ * returns undefined to remove the section, or null to leave the file as it is.
491
+ */
492
+ export function editConfigClaude(file, edit) {
493
+ return editConfigKey(file, 'claude', 'change the setting', (current) => edit(current ?? {}));
494
+ }
470
495
  /**
471
496
  * `sideby unattended on|schedule …` (spec §3.37): changes the config `unattended` key with `edit` (see `editConfigKey`
472
497
  * for how the file is written); `edit` gets `undefined` while the section is missing and returns null to leave it.
@@ -50,17 +50,28 @@ export type UsedAccount = string | {
50
50
  window?: {
51
51
  resetsAt: string;
52
52
  };
53
+ /** When the hop began, as `chain.json` keeps it. */
54
+ startedAt?: string;
55
+ /**
56
+ * Set by the Runtime: a Limit Reset the user confirmed was spent for this Account after the hop began, and the
57
+ * Quota read that followed it is kept (ADR-0072, amending ADR-0060).
58
+ */
59
+ resetUsed?: boolean;
53
60
  };
54
61
  /** What an automatic handoff does with the Accounts this chain already used (spec §3.17 "选号" 3, ADR-0060). */
55
62
  export interface UsedRule {
56
63
  /** Left out: the origin, a bare ref, and an Account whose latest hop handed over for a window that has not reset. */
57
64
  out: Set<string>;
58
- /** Back only when its own Quota data shows it ready: its latest hop recorded no window (a manual handoff, an older chain). */
65
+ /**
66
+ * Back only when its own Quota data shows it ready: its latest hop recorded no window (a manual handoff, an older
67
+ * chain), or it handed over for a window that has not reset by itself but a Limit Reset was spent for it since.
68
+ */
59
69
  ifReady: Set<string>;
60
70
  }
61
71
  /**
62
72
  * Sorts the Accounts this chain used by their latest hop: one that handed over for a Quota window that has reset by
63
- * `now` may take over again like any other, one with no recorded window only when it is `ready`, the rest stay out.
73
+ * `now` may take over again like any other, one with no recorded window, or one a Limit Reset was spent for since
74
+ * (`resetUsed`), only when it is `ready`, the rest stay out.
64
75
  * A bare ref stays out, and so does the origin.
65
76
  */
66
77
  export declare function stillUsed(origin: string, used: readonly UsedAccount[], now: Date): UsedRule;
@@ -2,7 +2,8 @@ import { planHandoff } from './handoff.js';
2
2
  import { takeoverLimits, windowReset } from './quota-levels.js';
3
3
  /**
4
4
  * Sorts the Accounts this chain used by their latest hop: one that handed over for a Quota window that has reset by
5
- * `now` may take over again like any other, one with no recorded window only when it is `ready`, the rest stay out.
5
+ * `now` may take over again like any other, one with no recorded window, or one a Limit Reset was spent for since
6
+ * (`resetUsed`), only when it is `ready`, the rest stay out.
6
7
  * A bare ref stays out, and so does the origin.
7
8
  */
8
9
  export function stillUsed(origin, used, now) {
@@ -12,8 +13,11 @@ export function stillUsed(origin, used, now) {
12
13
  latest.set(u, 'out');
13
14
  else if (u.window === undefined)
14
15
  latest.set(u.ref, 'ifReady');
16
+ else if (windowReset(u.window.resetsAt, now))
17
+ latest.set(u.ref, 'back');
18
+ // A confirmed Limit Reset may have emptied the window early: its Quota, read after the spend, decides.
15
19
  else
16
- latest.set(u.ref, windowReset(u.window.resetsAt, now) ? 'back' : 'out');
20
+ latest.set(u.ref, u.resetUsed ? 'ifReady' : 'out');
17
21
  }
18
22
  latest.set(origin, 'out');
19
23
  const refs = (k) => new Set([...latest].flatMap(([ref, v]) => (v === k ? [ref] : [])));
@@ -79,6 +79,10 @@ export declare function prepareLaunch(opts: LaunchCommandOptions & {
79
79
  bus: HookBus;
80
80
  /** What the Host may show as the Account (`SIDEBY_LABEL`): the short command, else the ref. */
81
81
  label?: string;
82
+ /** Config `advisor.unlock` (spec §3.41, ADR-0074): unlock Claude Code's advisor in a Claude subscription session. */
83
+ advisorUnlock?: boolean;
84
+ /** Config `claude.apiBetasOff` (spec §3.41, ADR-0074): a Claude API Account gets `BETAS_VAR=1`. */
85
+ apiBetasOff?: boolean;
82
86
  }): Promise<PreparedLaunch>;
83
87
  /**
84
88
  * Runs the Host with the terminal attached and returns sideby's exit code (spec §3.5):
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import { access, constants } from 'node:fs/promises';
3
3
  import { constants as osConstants } from 'node:os';
4
4
  import { delimiter, join } from 'node:path';
5
+ import { apiBetasEnv, unlockAdvisorEnv } from './advisor.js';
5
6
  import { lstatOrNull, realpathOrNull } from './fs-safe.js';
6
7
  import { readSecretFile } from './secret-file.js';
7
8
  /**
@@ -110,6 +111,9 @@ function aiTaskArgs(family, args) {
110
111
  export async function prepareLaunch(opts) {
111
112
  const { account, family } = opts;
112
113
  const env = accountEnv(family, account, opts.baseEnv);
114
+ // Before the Secret File, so the Account's own proxy.env still decides; a value already in the environment stays.
115
+ if (opts.apiBetasOff)
116
+ apiBetasEnv(env, family.id, account);
113
117
  if (account.secretFile)
114
118
  Object.assign(env, await readSecretFile(account.secretFile, opts.baseEnv));
115
119
  // The Secret File may not move the Account: its directory always wins.
@@ -119,6 +123,9 @@ export async function prepareLaunch(opts) {
119
123
  // inherited from another sideby Launch never leaks through.
120
124
  env.SIDEBY_ACCOUNT = account.ref;
121
125
  env.SIDEBY_LABEL = opts.label || account.ref;
126
+ // Before the Plugins' `launch.before`, so a Plugin sees it and may take it out again.
127
+ if (opts.advisorUnlock && opts.command === 'run')
128
+ unlockAdvisorEnv(env, family.id, account);
122
129
  const { args, notice } = launchCommand(opts);
123
130
  await opts.bus.run('launch.before', family.id, {
124
131
  account,
@@ -0,0 +1,198 @@
1
+ import type { LimitResetOutcome, LimitResets, QuotaResult } from '../types.ts';
2
+ import { UserError } from './errors.ts';
3
+ import { type ReleaseLock } from './lock.ts';
4
+ /**
5
+ * `planned`: shown, not confirmed. `pending`: a request was (or is about to be) sent and no final outcome came back.
6
+ * An outcome: the Host answered. `not-sent`: the request never left this computer, so nothing was spent. `stopped`:
7
+ * written by an older sideby only, for an operation it gave up on; it is read as ended and never written now, because
8
+ * an operation whose outcome is unknown stays `pending` until the Host answers its own key.
9
+ */
10
+ export type LimitResetState = 'planned' | 'pending' | LimitResetOutcome | 'not-sent' | 'stopped';
11
+ /**
12
+ * A salted digest of a login's comparison key (`loginComparisonKey`, core/same-login.ts): `sha256(salt + key)` with a
13
+ * salt of its own. It can only tell that the login of one operation is unchanged; it is never the Login Key or the
14
+ * Identity, and two records of one login do not share it.
15
+ */
16
+ export interface LoginDigest {
17
+ salt: string;
18
+ digest: string;
19
+ }
20
+ /** What the record of one operation holds. Never a Login Key, an Identity, a credit id or a credential. */
21
+ export interface LimitResetRecord {
22
+ version: 1;
23
+ operationId: string;
24
+ /**
25
+ * The refs of every Account of the Same Login when the operation was made, sorted. While it is unresolved, the
26
+ * Accounts that resumed it are added; with its outcome, they are the Accounts of the login then.
27
+ */
28
+ accounts: string[];
29
+ /**
30
+ * The login the operation was made for, as a digest to compare only. A record without one (written by an older
31
+ * sideby) cannot be shown to belong to any login, so it is never sent.
32
+ */
33
+ login?: LoginDigest;
34
+ /** Sent with every attempt of this operation, and with no other. */
35
+ idempotencyKey: string;
36
+ state: LimitResetState;
37
+ createdAt: string;
38
+ /** When each request was about to be sent (ISO), written before sending. */
39
+ attempts: string[];
40
+ /** When the operation reached a state that is not `planned` or `pending`. */
41
+ finishedAt?: string;
42
+ /** When the Quota read that followed a spend was kept. */
43
+ quotaReadAt?: string;
44
+ }
45
+ /** What a user is shown before confirming one spend (ADR-0072). It promises nothing about which windows refill. */
46
+ export interface LimitResetPlan {
47
+ /** The Account the user named. */
48
+ account: string;
49
+ /** The Account whose Host sends the request: the first signed-in Account of the Same Login. */
50
+ via: string;
51
+ /** The other Accounts of its Same Login; a spend applies to all of them. */
52
+ sameLogin: string[];
53
+ /** Pass it back to confirm this plan; left out when the plan cannot be confirmed (`canUse` false). */
54
+ operationId?: string;
55
+ /**
56
+ * An earlier attempt for this login got no final answer. Confirming asks the Host again with the same request, so
57
+ * it spends nothing more when that attempt already went through.
58
+ */
59
+ unresolved?: true;
60
+ /** The Quota as it was read for this plan: each window's used percent and own reset time. */
61
+ quota: QuotaResult;
62
+ /** The Limit Resets the login holds now; left out when the Host did not tell. */
63
+ limitResets?: LimitResets;
64
+ /** The count expected after one spend; left out when the count is unknown or zero. */
65
+ expectedAfter?: number;
66
+ /** False when the plan cannot be confirmed; `blocked` then says why and what to do. */
67
+ canUse: boolean;
68
+ blocked?: string;
69
+ /** In plain words: what confirming does, and that it cannot be undone. */
70
+ message: string;
71
+ }
72
+ /** What one confirmed spend ended as. */
73
+ export interface LimitResetResult {
74
+ account: string;
75
+ via: string;
76
+ sameLogin: string[];
77
+ operationId: string;
78
+ outcome: LimitResetOutcome;
79
+ /** This confirmation finished an earlier attempt instead of making a new request of its own. */
80
+ resumed?: true;
81
+ /** The outcome was already known for this operation; no request to use one was sent now. */
82
+ replayed?: true;
83
+ /**
84
+ * The Quota for the Account the user named. After a spend, only numbers whose read began after it; left out when
85
+ * that read failed.
86
+ */
87
+ quota?: QuotaResult;
88
+ /** The reset was used but the Quota could not be read afterwards: the numbers on show are still the old ones. */
89
+ quotaPending?: true;
90
+ message: string;
91
+ }
92
+ /** A refused or unfinished spend. `operationId` names the operation to retry, when there is one. */
93
+ export declare class LimitResetError extends UserError {
94
+ readonly operationId?: string;
95
+ constructor(message: string, opts: {
96
+ code: string;
97
+ operationId?: string;
98
+ });
99
+ }
100
+ /** States a Host's answer ends an operation in. */
101
+ export declare const LIMIT_RESET_OUTCOMES: readonly LimitResetOutcome[];
102
+ /** A finished or never-confirmed record is removed this long after it was finished or made. */
103
+ export declare const RECORD_KEEP_MS: number;
104
+ export declare const limitResetDir: (stateDir: string) => string;
105
+ /** Whether `id` has the shape of an operation id, so it is safe as a file name. */
106
+ export declare const isOperationId: (id: unknown) => id is string;
107
+ export declare function newOperationId(): string;
108
+ /** Whether a Host answered this operation: a spend happened (`reset`, `already-done`) or the Host said why not. */
109
+ export declare const isOutcome: (s: LimitResetState) => s is LimitResetOutcome;
110
+ /** Whether the operation spent a Limit Reset. */
111
+ export declare const spent: (s: LimitResetState) => boolean;
112
+ /** A new digest for the login whose comparison key is `key`, with a salt no other record has. */
113
+ export declare function newLoginDigest(key: string): LoginDigest;
114
+ /**
115
+ * Whether `key`, the comparison key of the login that would send the request now, is the one `record` was made for.
116
+ * False when either is unknown: a record without a digest, or a login that cannot be read now (signed out, an
117
+ * unreadable sign-in). False always means "do not send".
118
+ */
119
+ export declare function loginUnchanged(record: LimitResetRecord, key: string | undefined): boolean;
120
+ /** Where the record of `operationId` is kept. */
121
+ export declare const limitResetFile: (stateDir: string, operationId: string) => string;
122
+ /**
123
+ * Why nothing may be sent while `paths` (operation files, or the folder itself) cannot be read, and what to do.
124
+ * Names the paths, never their contents.
125
+ */
126
+ export declare function unreadableRecordsMessage(stateDir: string, paths: readonly string[]): string;
127
+ /**
128
+ * The record of `operationId`, or null when there is none. Throws a `LimitResetError` (`records-unreadable`) when
129
+ * its file is there but cannot be read or is not a record sideby wrote.
130
+ */
131
+ export declare function readLimitResetRecord(stateDir: string, operationId: string): Promise<LimitResetRecord | null>;
132
+ /** Keeps `record` (folder 700, file 600, written through a temp file and a rename). */
133
+ export declare function writeLimitResetRecord(stateDir: string, record: LimitResetRecord): Promise<void>;
134
+ /**
135
+ * A new operation for the Accounts of one login, not yet confirmed. `loginKey` is that login's comparison key; only
136
+ * its salted digest is kept.
137
+ */
138
+ export declare function newLimitResetRecord(accounts: readonly string[], now: Date, loginKey: string): LimitResetRecord;
139
+ /** What the folder of operations holds: the records that can be read, and what is there but cannot be. */
140
+ export interface LimitResetScan {
141
+ /** Every record that can be read, oldest first. */
142
+ records: LimitResetRecord[];
143
+ /**
144
+ * Paths that are there but cannot be read: an operation file (no permission, damaged, not a record sideby wrote),
145
+ * or the folder itself when it cannot be listed. Any of them may hide an unresolved spend, so while this is not
146
+ * empty no new operation is made and nothing is sent.
147
+ */
148
+ unreadable: string[];
149
+ }
150
+ /** Reads every operation file. A folder that is not there yet holds nothing; any other failure is `unreadable`. */
151
+ export declare function scanLimitResetRecords(stateDir: string): Promise<LimitResetScan>;
152
+ /**
153
+ * Every record that can be read, oldest first. For readers that spend nothing (pruning, Auto Handoff's look at
154
+ * confirmed spends); a spend goes through `scanLimitResetRecords`, which also tells what could not be read.
155
+ */
156
+ export declare function listLimitResetRecords(stateDir: string): Promise<LimitResetRecord[]>;
157
+ /** Whether a plan was made too long ago to confirm: its numbers are a day old, and pruning may remove it. */
158
+ export declare const planExpired: (record: LimitResetRecord, now: Date) => boolean;
159
+ /**
160
+ * Removes records nobody needs any more: a finished one 24 hours after it finished, a plan nobody confirmed 24 hours
161
+ * after it was made. An unresolved one (`pending`) is never removed: only its own key may ask the Host again. Nor is
162
+ * a file that cannot be read: it may be one.
163
+ *
164
+ * A record is removed only under the spend lock of its Accounts, the one a confirmation holds from before it writes
165
+ * `pending` until it has its answer, and only after it was read again there: a plan confirmed since this looked is
166
+ * unresolved now, and its key must stay. A lock that is held is not waited for; the next pruning looks again.
167
+ * `seam` is for tests: it runs after a record was read as removable and before its lock is taken.
168
+ */
169
+ export declare function pruneLimitResetRecords(stateDir: string, now: Date, seam?: {
170
+ afterRead?: (record: LimitResetRecord) => Promise<void>;
171
+ }): Promise<void>;
172
+ /**
173
+ * The unresolved operation of a login, the oldest first; undefined when there is none. `loginKey` is the comparison
174
+ * key of the login that asks now: an operation made for that login comes first, whichever Accounts it names, so an
175
+ * Account that signed in as the login since finds it too. Then one that names one of `accounts`: it may be another
176
+ * login's by now, which `loginUnchanged` tells, but no new operation is made beside it.
177
+ */
178
+ export declare function unresolvedFor(records: readonly LimitResetRecord[], accounts: readonly string[], loginKey?: string): LimitResetRecord | undefined;
179
+ /**
180
+ * Whether a record's Accounts are exactly `accounts`: the group the operation was made for has not changed. Equal
181
+ * refs do not show that the login behind them is the same; `loginUnchanged` does.
182
+ */
183
+ export declare function sameAccounts(record: LimitResetRecord, accounts: readonly string[]): boolean;
184
+ /**
185
+ * Spends that went through and whose following Quota read is kept (ADR-0072, amending ADR-0060): the Accounts they
186
+ * were for and when that read landed. Auto Handoff may take such an Account back before its window's old reset time.
187
+ */
188
+ export declare function confirmedSpends(stateDir: string): Promise<{
189
+ accounts: string[];
190
+ quotaReadAt: string;
191
+ }[]>;
192
+ /**
193
+ * The spend lock of one login, across processes: one lock file per Account of the Same Login, taken in sorted order
194
+ * so two takers never wait on each other. Null when another sideby keeps it for longer than `waitMs`.
195
+ */
196
+ export declare function takeLimitResetLock(stateDir: string, accounts: readonly string[], waitMs: number): Promise<ReleaseLock | null>;
197
+ /** What each outcome means for the user, in plain words. */
198
+ export declare function outcomeMessage(outcome: LimitResetOutcome, ref: string): string;