@tidegap/core 0.18.0 → 0.20.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 (171) hide show
  1. package/README.md +3 -1
  2. package/dist/agent-snippet.d.ts +30 -0
  3. package/dist/agent-snippet.js +120 -0
  4. package/dist/budget.d.ts +0 -12
  5. package/dist/budget.js +2 -24
  6. package/dist/channels/commands.d.ts +137 -0
  7. package/dist/channels/commands.js +377 -0
  8. package/dist/channels/delivery-codes.d.ts +9 -0
  9. package/dist/channels/delivery-codes.js +53 -0
  10. package/dist/channels/digest.d.ts +102 -0
  11. package/dist/channels/digest.js +146 -0
  12. package/dist/channels/format.d.ts +127 -0
  13. package/dist/channels/format.js +407 -0
  14. package/dist/channels/index.d.ts +15 -0
  15. package/dist/channels/index.js +15 -0
  16. package/dist/channels/kinds/command.d.ts +13 -0
  17. package/dist/channels/kinds/command.js +65 -0
  18. package/dist/channels/kinds/discord.d.ts +16 -0
  19. package/dist/channels/kinds/discord.js +67 -0
  20. package/dist/channels/kinds/email.d.ts +20 -0
  21. package/dist/channels/kinds/email.js +162 -0
  22. package/dist/channels/kinds/index.d.ts +8 -0
  23. package/dist/channels/kinds/index.js +17 -0
  24. package/dist/channels/kinds/ntfy.d.ts +25 -0
  25. package/dist/channels/kinds/ntfy.js +163 -0
  26. package/dist/channels/kinds/pushover.d.ts +11 -0
  27. package/dist/channels/kinds/pushover.js +77 -0
  28. package/dist/channels/kinds/shared.d.ts +25 -0
  29. package/dist/channels/kinds/shared.js +39 -0
  30. package/dist/channels/kinds/shortcuts.d.ts +9 -0
  31. package/dist/channels/kinds/shortcuts.js +45 -0
  32. package/dist/channels/kinds/slack.d.ts +8 -0
  33. package/dist/channels/kinds/slack.js +57 -0
  34. package/dist/channels/kinds/telegram.d.ts +4 -0
  35. package/dist/channels/kinds/telegram.js +26 -0
  36. package/dist/channels/kinds/webhook.d.ts +30 -0
  37. package/dist/channels/kinds/webhook.js +177 -0
  38. package/dist/channels/payload.d.ts +36 -0
  39. package/dist/channels/payload.js +61 -0
  40. package/dist/channels/plan.d.ts +24 -0
  41. package/dist/channels/plan.js +66 -0
  42. package/dist/channels/registry.d.ts +191 -0
  43. package/dist/channels/registry.js +125 -0
  44. package/dist/channels/telegram.d.ts +110 -0
  45. package/dist/channels/telegram.js +168 -0
  46. package/dist/channels/types.d.ts +107 -0
  47. package/dist/channels/types.js +26 -0
  48. package/dist/claude-tools.d.ts +29 -0
  49. package/dist/claude-tools.js +49 -0
  50. package/dist/data/tables.generated.d.ts +6 -0
  51. package/dist/data/tables.generated.js +37 -0
  52. package/dist/energy.d.ts +77 -0
  53. package/dist/energy.js +131 -0
  54. package/dist/grid.d.ts +19 -2
  55. package/dist/grid.js +84 -28
  56. package/dist/handoff.d.ts +152 -0
  57. package/dist/handoff.js +430 -0
  58. package/dist/history.d.ts +2 -0
  59. package/dist/history.js +3 -1
  60. package/dist/index.d.ts +46 -16
  61. package/dist/index.js +34 -8
  62. package/dist/job-cadence.d.ts +76 -0
  63. package/dist/job-cadence.js +240 -0
  64. package/dist/jobs.d.ts +173 -0
  65. package/dist/jobs.js +794 -0
  66. package/dist/notify.d.ts +2 -0
  67. package/dist/notify.js +2 -1
  68. package/dist/paths.d.ts +13 -46
  69. package/dist/paths.js +51 -219
  70. package/dist/postpone.d.ts +113 -0
  71. package/dist/postpone.js +185 -0
  72. package/dist/providers/anthropic.js +7 -3
  73. package/dist/providers/base.d.ts +113 -1
  74. package/dist/providers/base.js +15 -0
  75. package/dist/providers/budget.d.ts +25 -0
  76. package/dist/providers/budget.js +57 -0
  77. package/dist/providers/defaults.js +4 -0
  78. package/dist/providers/defer.d.ts +16 -0
  79. package/dist/providers/defer.js +31 -0
  80. package/dist/providers/gemini.d.ts +1 -0
  81. package/dist/providers/gemini.js +27 -20
  82. package/dist/providers/index.d.ts +2 -2
  83. package/dist/providers/index.js +1 -1
  84. package/dist/providers/ollama.d.ts +1 -0
  85. package/dist/providers/ollama.js +26 -22
  86. package/dist/providers/openai.js +5 -5
  87. package/dist/providers/timeout.d.ts +18 -0
  88. package/dist/providers/timeout.js +33 -0
  89. package/dist/quota.d.ts +7 -2
  90. package/dist/quota.js +13 -29
  91. package/dist/readiness.d.ts +169 -0
  92. package/dist/readiness.js +254 -0
  93. package/dist/redact.d.ts +42 -0
  94. package/dist/redact.js +110 -0
  95. package/dist/region-host.d.ts +30 -0
  96. package/dist/region-host.js +69 -0
  97. package/dist/region.d.ts +102 -20
  98. package/dist/region.js +175 -23
  99. package/dist/run-session.d.ts +36 -0
  100. package/dist/run-session.js +72 -0
  101. package/dist/schedule-job.d.ts +95 -0
  102. package/dist/schedule-job.js +195 -0
  103. package/dist/scheduler.d.ts +245 -14
  104. package/dist/scheduler.js +925 -110
  105. package/dist/sign.d.ts +8 -1
  106. package/dist/sign.js +49 -3
  107. package/dist/storage/sqlite.d.ts +157 -5
  108. package/dist/storage/sqlite.js +661 -20
  109. package/dist/task-events.d.ts +102 -0
  110. package/dist/task-events.js +308 -0
  111. package/dist/tool-surface.d.ts +31 -2
  112. package/dist/tool-surface.js +359 -65
  113. package/dist/types.d.ts +246 -3
  114. package/dist/types.js +8 -1
  115. package/dist/zone-time.d.ts +22 -0
  116. package/dist/zone-time.js +76 -0
  117. package/package.json +11 -6
  118. package/dist/aggregator.d.ts.map +0 -1
  119. package/dist/aggregator.js.map +0 -1
  120. package/dist/budget.d.ts.map +0 -1
  121. package/dist/budget.js.map +0 -1
  122. package/dist/data/tables.generated.d.ts.map +0 -1
  123. package/dist/data/tables.generated.js.map +0 -1
  124. package/dist/energy.d.ts.map +0 -1
  125. package/dist/energy.js.map +0 -1
  126. package/dist/grid.d.ts.map +0 -1
  127. package/dist/grid.js.map +0 -1
  128. package/dist/history.d.ts.map +0 -1
  129. package/dist/history.js.map +0 -1
  130. package/dist/index.d.ts.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/notify.d.ts.map +0 -1
  133. package/dist/notify.js.map +0 -1
  134. package/dist/paths.d.ts.map +0 -1
  135. package/dist/paths.js.map +0 -1
  136. package/dist/providers/anthropic.d.ts.map +0 -1
  137. package/dist/providers/anthropic.js.map +0 -1
  138. package/dist/providers/base.d.ts.map +0 -1
  139. package/dist/providers/base.js.map +0 -1
  140. package/dist/providers/defaults.d.ts.map +0 -1
  141. package/dist/providers/defaults.js.map +0 -1
  142. package/dist/providers/gemini.d.ts.map +0 -1
  143. package/dist/providers/gemini.js.map +0 -1
  144. package/dist/providers/index.d.ts.map +0 -1
  145. package/dist/providers/index.js.map +0 -1
  146. package/dist/providers/ollama.d.ts.map +0 -1
  147. package/dist/providers/ollama.js.map +0 -1
  148. package/dist/providers/openai.d.ts.map +0 -1
  149. package/dist/providers/openai.js.map +0 -1
  150. package/dist/quota.d.ts.map +0 -1
  151. package/dist/quota.js.map +0 -1
  152. package/dist/recommend.d.ts.map +0 -1
  153. package/dist/recommend.js.map +0 -1
  154. package/dist/redact.d.ts.map +0 -1
  155. package/dist/redact.js.map +0 -1
  156. package/dist/region.d.ts.map +0 -1
  157. package/dist/region.js.map +0 -1
  158. package/dist/routing.d.ts.map +0 -1
  159. package/dist/routing.js.map +0 -1
  160. package/dist/scheduler.d.ts.map +0 -1
  161. package/dist/scheduler.js.map +0 -1
  162. package/dist/select-window.d.ts.map +0 -1
  163. package/dist/select-window.js.map +0 -1
  164. package/dist/sign.d.ts.map +0 -1
  165. package/dist/sign.js.map +0 -1
  166. package/dist/storage/sqlite.d.ts.map +0 -1
  167. package/dist/storage/sqlite.js.map +0 -1
  168. package/dist/tool-surface.d.ts.map +0 -1
  169. package/dist/tool-surface.js.map +0 -1
  170. package/dist/types.d.ts.map +0 -1
  171. package/dist/types.js.map +0 -1
package/dist/notify.d.ts CHANGED
@@ -39,6 +39,8 @@ export interface OsNotifyOptions {
39
39
  export declare function osNotifyCommand(platform: NodeJS.Platform, title: string, body: string, opts?: OsNotifyOptions): OsNotifyCommand | null;
40
40
  /** Characters of result text shown in a notification body. */
41
41
  export declare const NOTIFY_PREVIEW_CHARS = 140;
42
+ /** `text` cut to `max` characters (code points) plus an ellipsis. */
43
+ export declare function clip(text: string, max: number): string;
42
44
  /**
43
45
  * Notification title and body for a finished task: the task title (or id),
44
46
  * a redacted one-line preview of the result (completed) or the first line
package/dist/notify.js CHANGED
@@ -77,7 +77,8 @@ function oneLine(text) {
77
77
  .replace(/\s+/g, " ")
78
78
  .trim();
79
79
  }
80
- function clip(text, max) {
80
+ /** `text` cut to `max` characters (code points) plus an ellipsis. */
81
+ export function clip(text, max) {
81
82
  const chars = Array.from(text);
82
83
  return chars.length > max ? `${chars.slice(0, max).join("")}…` : text;
83
84
  }
package/dist/paths.d.ts CHANGED
@@ -1,64 +1,31 @@
1
1
  /**
2
- * The Tidegap data directory and the one-time move from the 0.17 name.
2
+ * The Tidegap data directory, `~/.tidegap`.
3
3
  *
4
4
  * 0.17 kept its state (queue.db, signing.key, config, delivery.db, logs) in
5
- * `~/.ebb-ai`. 0.18 uses `~/.tidegap`. The first 0.18 process that needs the
6
- * directory moves the old one and leaves `~/.ebb-ai` as a link to the new one,
7
- * so a 0.17 process (or a 0.17 daemon unit pinning `--db ~/.ebb-ai/queue.db`)
8
- * keeps reading and writing the same ledger.
9
- *
10
- * Rules, decided by the state of `~/.ebb-ai` (0.18 code may create
11
- * `~/.tidegap` first, for example the daemon log dir):
12
- * - `~/.ebb-ai` absent, or a link to `~/.tidegap`: use `~/.tidegap`.
13
- * - `~/.ebb-ai` a link somewhere else (a user's own link, for example to
14
- * another disk): follow it and use `~/.ebb-ai`, with one line, unless
15
- * `~/.tidegap` already holds a queue.db or signing.key.
16
- * - `~/.ebb-ai` a real dir, `~/.tidegap` absent: rename, then link back.
17
- * - `~/.ebb-ai` a real dir, `~/.tidegap` present without queue.db and
18
- * signing.key: move each entry in (directories merge), remove the empty
19
- * `~/.ebb-ai`, link back. A file present in both stops the move.
20
- * - Both hold a queue.db or a signing.key: change nothing, use `~/.tidegap`.
21
- * - The link cannot be made: move the data back, use `~/.ebb-ai` in place.
22
- * Rename and link succeed or fail together, because SQLite refuses writes
23
- * once an open path stops resolving to the same file.
24
- * - A rename that loses a race (source gone, target appeared): re-check.
25
- * - Any other rename failure: use `~/.ebb-ai` in place.
26
- * Nothing is ever deleted except the emptied `~/.ebb-ai` directory itself.
5
+ * `~/.ebb-ai`. 0.18 moved it to `~/.tidegap` on first use and left a link
6
+ * back. 0.19 removed that move: `~/.ebb-ai` is never read. When it still
7
+ * holds data (a real directory, or a user's own link to a directory other
8
+ * than `~/.tidegap`), the process prints one stderr line naming it, so a
9
+ * 0.17 install that skipped 0.18 does not silently start an empty ledger. A
10
+ * `~/.ebb-ai` link back to `~/.tidegap`, left by 0.18, is ignored without a
11
+ * line.
27
12
  *
28
13
  * Environment-pure: the home directory comes from `os.homedir()`, never from
29
- * an environment variable. The Python core mirrors these rules in
14
+ * an environment variable. The Python core mirrors this in
30
15
  * `tidegap/paths.py`.
31
16
  */
32
- import * as nodeFs from "node:fs";
33
17
  /** Name of the data directory under the home directory. */
34
18
  export declare const TIDEGAP_HOME_DIR = ".tidegap";
35
- /** The 0.17 name, kept as a link to {@link TIDEGAP_HOME_DIR} until 0.19. */
36
- export declare const LEGACY_HOME_DIR = ".ebb-ai";
37
- /** The filesystem calls the resolver makes; tests replace single calls. */
38
- export interface HomeFs {
39
- lstatSync(path: string): nodeFs.Stats;
40
- readdirSync(path: string): string[];
41
- renameSync(from: string, to: string): void;
42
- rmdirSync(path: string): void;
43
- mkdirSync(path: string): void;
44
- symlinkSync(target: string, path: string, type?: "dir" | "junction"): void;
45
- realpathSync(path: string): string;
46
- }
47
19
  export interface ResolveHomeOptions {
48
20
  /** Home directory; default `os.homedir()`. */
49
21
  home?: string;
50
- /** Replace single filesystem calls (tests). */
51
- fs?: Partial<HomeFs>;
52
- /** Where the one-line notices go; default stderr. */
22
+ /** Where the one-line notice goes; default stderr, once per process. */
53
23
  warn?: (line: string) => void;
54
- /** Platform for the link type; default `process.platform`. */
55
- platform?: NodeJS.Platform;
56
24
  }
57
25
  /**
58
- * The Tidegap data directory (`~/.tidegap`), after moving a 0.17
59
- * `~/.ebb-ai` into it when needed. Returns `~/.ebb-ai` only when the move
60
- * could not be completed safely; callers then keep using the old directory.
61
- * Creates nothing when neither directory exists.
26
+ * The Tidegap data directory (`~/.tidegap`). Creates nothing. Prints one line
27
+ * when a 0.17 `~/.ebb-ai` still holds data (once per process and home,
28
+ * unless `opts.warn` is given).
62
29
  */
63
30
  export declare function resolveTidegapHome(opts?: ResolveHomeOptions): string;
64
31
  /** A path inside the Tidegap data directory, e.g. `tidegapPath("queue.db")`. */
package/dist/paths.js CHANGED
@@ -1,253 +1,85 @@
1
1
  /**
2
- * The Tidegap data directory and the one-time move from the 0.17 name.
2
+ * The Tidegap data directory, `~/.tidegap`.
3
3
  *
4
4
  * 0.17 kept its state (queue.db, signing.key, config, delivery.db, logs) in
5
- * `~/.ebb-ai`. 0.18 uses `~/.tidegap`. The first 0.18 process that needs the
6
- * directory moves the old one and leaves `~/.ebb-ai` as a link to the new one,
7
- * so a 0.17 process (or a 0.17 daemon unit pinning `--db ~/.ebb-ai/queue.db`)
8
- * keeps reading and writing the same ledger.
9
- *
10
- * Rules, decided by the state of `~/.ebb-ai` (0.18 code may create
11
- * `~/.tidegap` first, for example the daemon log dir):
12
- * - `~/.ebb-ai` absent, or a link to `~/.tidegap`: use `~/.tidegap`.
13
- * - `~/.ebb-ai` a link somewhere else (a user's own link, for example to
14
- * another disk): follow it and use `~/.ebb-ai`, with one line, unless
15
- * `~/.tidegap` already holds a queue.db or signing.key.
16
- * - `~/.ebb-ai` a real dir, `~/.tidegap` absent: rename, then link back.
17
- * - `~/.ebb-ai` a real dir, `~/.tidegap` present without queue.db and
18
- * signing.key: move each entry in (directories merge), remove the empty
19
- * `~/.ebb-ai`, link back. A file present in both stops the move.
20
- * - Both hold a queue.db or a signing.key: change nothing, use `~/.tidegap`.
21
- * - The link cannot be made: move the data back, use `~/.ebb-ai` in place.
22
- * Rename and link succeed or fail together, because SQLite refuses writes
23
- * once an open path stops resolving to the same file.
24
- * - A rename that loses a race (source gone, target appeared): re-check.
25
- * - Any other rename failure: use `~/.ebb-ai` in place.
26
- * Nothing is ever deleted except the emptied `~/.ebb-ai` directory itself.
5
+ * `~/.ebb-ai`. 0.18 moved it to `~/.tidegap` on first use and left a link
6
+ * back. 0.19 removed that move: `~/.ebb-ai` is never read. When it still
7
+ * holds data (a real directory, or a user's own link to a directory other
8
+ * than `~/.tidegap`), the process prints one stderr line naming it, so a
9
+ * 0.17 install that skipped 0.18 does not silently start an empty ledger. A
10
+ * `~/.ebb-ai` link back to `~/.tidegap`, left by 0.18, is ignored without a
11
+ * line.
27
12
  *
28
13
  * Environment-pure: the home directory comes from `os.homedir()`, never from
29
- * an environment variable. The Python core mirrors these rules in
14
+ * an environment variable. The Python core mirrors this in
30
15
  * `tidegap/paths.py`.
31
16
  */
32
- import * as nodeFs from "node:fs";
17
+ import { lstatSync, realpathSync, statSync } from "node:fs";
33
18
  import { homedir } from "node:os";
34
19
  import { join } from "node:path";
35
20
  /** Name of the data directory under the home directory. */
36
21
  export const TIDEGAP_HOME_DIR = ".tidegap";
37
- /** The 0.17 name, kept as a link to {@link TIDEGAP_HOME_DIR} until 0.19. */
38
- export const LEGACY_HOME_DIR = ".ebb-ai";
39
- const realFs = {
40
- lstatSync: (p) => nodeFs.lstatSync(p),
41
- readdirSync: (p) => nodeFs.readdirSync(p),
42
- renameSync: (a, b) => nodeFs.renameSync(a, b),
43
- rmdirSync: (p) => nodeFs.rmdirSync(p),
44
- mkdirSync: (p) => nodeFs.mkdirSync(p),
45
- symlinkSync: (t, p, type) => nodeFs.symlinkSync(t, p, type),
46
- realpathSync: (p) => nodeFs.realpathSync(p),
47
- };
48
- const DATA_FILES = ["queue.db", "signing.key"];
49
- const RACE_CODES = new Set(["ENOENT", "EEXIST", "ENOTEMPTY"]);
50
- const MAX_ATTEMPTS = 3;
51
- /** Resolved home per home path, so each process migrates and warns once. */
52
- const resolved = new Map();
53
- function errCode(err) {
54
- return err?.code;
55
- }
22
+ /** The 0.17 directory name; only checked to print the notice. */
23
+ const OLD_HOME_DIR = ".ebb-ai";
24
+ /** Homes already checked for a 0.17 directory, so each process warns once. */
25
+ const checked = new Set();
56
26
  function defaultWarn(line) {
57
27
  // stderr only: on the MCP server stdout is the protocol channel.
58
28
  process.stderr.write(`${line}\n`);
59
29
  }
60
30
  /**
61
- * The Tidegap data directory (`~/.tidegap`), after moving a 0.17
62
- * `~/.ebb-ai` into it when needed. Returns `~/.ebb-ai` only when the move
63
- * could not be completed safely; callers then keep using the old directory.
64
- * Creates nothing when neither directory exists.
31
+ * Where a 0.17 `~/.ebb-ai` still holds data: `old` itself when it is a real
32
+ * directory, the directory it links to when that is not `target`, else
33
+ * `undefined` (absent, a 0.18 link back to `target`, or a dangling link).
34
+ * Node reports a Windows junction as a symbolic link.
65
35
  */
66
- export function resolveTidegapHome(opts = {}) {
67
- const home = opts.home ?? homedir();
68
- const cacheable = opts.fs === undefined && opts.warn === undefined;
69
- if (cacheable) {
70
- const hit = resolved.get(home);
71
- if (hit)
72
- return hit;
73
- }
74
- const fs = { ...realFs, ...opts.fs };
75
- const warn = opts.warn ?? defaultWarn;
76
- const platform = opts.platform ?? process.platform;
77
- const result = migrate(home, fs, warn, platform);
78
- if (cacheable)
79
- resolved.set(home, result);
80
- return result;
81
- }
82
- /** A path inside the Tidegap data directory, e.g. `tidegapPath("queue.db")`. */
83
- export function tidegapPath(...segments) {
84
- return join(resolveTidegapHome(), ...segments);
85
- }
86
- function lstat(fs, path) {
36
+ function oldHomeData(old, target) {
37
+ let points;
87
38
  try {
88
- return fs.lstatSync(path);
39
+ const st = lstatSync(old);
40
+ if (!st.isSymbolicLink())
41
+ return st.isDirectory() ? old : undefined;
42
+ points = realpathSync(old);
43
+ if (!statSync(points).isDirectory())
44
+ return undefined;
89
45
  }
90
46
  catch {
91
47
  return undefined;
92
48
  }
93
- }
94
- function realpath(fs, path) {
95
49
  try {
96
- return fs.realpathSync(path);
50
+ if (realpathSync(target) === points)
51
+ return undefined;
97
52
  }
98
53
  catch {
99
- return undefined;
100
- }
101
- }
102
- /** Recreate directories a merge removed, parents first. Best effort. */
103
- function restoreDirs(fs, emptied) {
104
- for (const dir of [...emptied].reverse()) {
105
- try {
106
- if (!lstat(fs, dir))
107
- fs.mkdirSync(dir);
108
- }
109
- catch {
110
- // The warning that follows names both directories.
111
- }
54
+ // No ~/.tidegap yet: the link points somewhere else.
112
55
  }
56
+ return points;
113
57
  }
114
- function migrate(home, fs, warn, platform) {
115
- const legacy = join(home, LEGACY_HOME_DIR);
58
+ /**
59
+ * The Tidegap data directory (`~/.tidegap`). Creates nothing. Prints one line
60
+ * when a 0.17 `~/.ebb-ai` still holds data (once per process and home,
61
+ * unless `opts.warn` is given).
62
+ */
63
+ export function resolveTidegapHome(opts = {}) {
64
+ const home = opts.home ?? homedir();
116
65
  const target = join(home, TIDEGAP_HOME_DIR);
117
- const inPlace = (why) => {
118
- warn(`tidegap: could not move ${legacy} to ${target} (${why}); using ${legacy} for now.`);
119
- return legacy;
120
- };
121
- const link = () => {
122
- try {
123
- fs.symlinkSync(target, legacy, platform === "win32" ? "junction" : "dir");
124
- return true;
125
- }
126
- catch {
127
- return false;
128
- }
129
- };
130
- for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
131
- const old = lstat(fs, legacy);
132
- if (old?.isSymbolicLink()) {
133
- // Junctions on Windows report as links too.
134
- const points = realpath(fs, legacy);
135
- if (!points || points === realpath(fs, target))
136
- return target;
137
- if (DATA_FILES.some((f) => lstat(fs, join(target, f)))) {
138
- warn(`tidegap: ${legacy} links to ${points} and ${target} holds data; using ${target}. Move anything you need from ${points} by hand.`);
139
- return target;
140
- }
141
- warn(`tidegap: ${legacy} links to ${points}, not to ${target}; using ${legacy}. Move it to ${target} by hand.`);
142
- return legacy;
143
- }
144
- if (!old || !old.isDirectory())
66
+ if (opts.warn === undefined) {
67
+ if (checked.has(home))
145
68
  return target;
146
- if (!lstat(fs, target)) {
147
- try {
148
- fs.renameSync(legacy, target);
149
- }
150
- catch (err) {
151
- if (RACE_CODES.has(errCode(err) ?? ""))
152
- continue;
153
- return inPlace(errCode(err) ?? String(err));
154
- }
155
- if (link())
156
- return target;
157
- try {
158
- fs.renameSync(target, legacy);
159
- }
160
- catch (err) {
161
- warn(`tidegap: moved ${legacy} to ${target} but could not link it back or undo the move (${errCode(err) ?? String(err)}).`);
162
- return target;
163
- }
164
- return inPlace("cannot create the link");
165
- }
166
- if (DATA_FILES.some((f) => lstat(fs, join(target, f)))) {
167
- warn(`tidegap: both ${legacy} and ${target} hold data; using ${target}. Move anything you need from ${legacy} by hand.`);
168
- return target;
169
- }
170
- const plan = planMerge(fs, legacy, target);
171
- if (typeof plan === "string")
172
- return inPlace(plan);
173
- const done = [];
174
- const undo = () => {
175
- for (const [from, to] of done.reverse()) {
176
- try {
177
- fs.renameSync(to, from);
178
- }
179
- catch {
180
- // Best effort; the warning below names both directories.
181
- }
182
- }
183
- };
184
- try {
185
- for (const [from, to] of plan) {
186
- fs.renameSync(from, to);
187
- done.push([from, to]);
188
- }
189
- }
190
- catch (err) {
191
- undo();
192
- if (RACE_CODES.has(errCode(err) ?? ""))
193
- continue;
194
- return inPlace(errCode(err) ?? String(err));
195
- }
196
- const emptied = emptyDirs(fs, legacy);
197
- try {
198
- for (const dir of emptied)
199
- fs.rmdirSync(dir);
200
- }
201
- catch (err) {
202
- // Something new appeared in ~/.ebb-ai meanwhile: put everything back.
203
- restoreDirs(fs, emptied);
204
- undo();
205
- return inPlace(errCode(err) ?? String(err));
206
- }
207
- if (link())
208
- return target;
209
- restoreDirs(fs, emptied);
210
- undo();
211
- return inPlace("cannot create the link");
69
+ checked.add(home);
212
70
  }
213
- return inPlace("the directory kept changing");
214
- }
215
- /**
216
- * The renames that move every entry of `from` into `to`, merging directories
217
- * present in both. Returns a reason string when a non-directory exists on
218
- * both sides, so nothing would be overwritten.
219
- */
220
- function planMerge(fs, from, to) {
221
- const out = [];
222
- for (const name of fs.readdirSync(from)) {
223
- const src = join(from, name);
224
- const dst = join(to, name);
225
- const there = lstat(fs, dst);
226
- if (!there) {
227
- out.push([src, dst]);
228
- continue;
229
- }
230
- const here = lstat(fs, src);
231
- if (here?.isDirectory() && !here.isSymbolicLink() && there.isDirectory() && !there.isSymbolicLink()) {
232
- const inner = planMerge(fs, src, dst);
233
- if (typeof inner === "string")
234
- return inner;
235
- out.push(...inner);
236
- continue;
237
- }
238
- return `${name} exists in both`;
71
+ const old = join(home, OLD_HOME_DIR);
72
+ const data = oldHomeData(old, target);
73
+ if (data !== undefined) {
74
+ const label = data === old ? old : `${old} (a link to ${data})`;
75
+ (opts.warn ?? defaultWarn)(`tidegap: ${label} is no longer read (removed in 0.19); tidegap uses ${target}. ` +
76
+ `To keep its data, stop tidegap (daemon and MCP hosts), move ${target} aside, then rename ${old} to ${target}. ` +
77
+ `Otherwise move ${old} out of your home directory to hide this line.`);
239
78
  }
240
- return out;
79
+ return target;
241
80
  }
242
- /** `dir` and the directories under it that a merge left empty, deepest first. */
243
- function emptyDirs(fs, dir) {
244
- const out = [];
245
- for (const name of fs.readdirSync(dir)) {
246
- const sub = join(dir, name);
247
- if (lstat(fs, sub)?.isDirectory())
248
- out.push(...emptyDirs(fs, sub));
249
- }
250
- out.push(dir);
251
- return out;
81
+ /** A path inside the Tidegap data directory, e.g. `tidegapPath("queue.db")`. */
82
+ export function tidegapPath(...segments) {
83
+ return join(resolveTidegapHome(), ...segments);
252
84
  }
253
85
  //# sourceMappingURL=paths.js.map
@@ -0,0 +1,113 @@
1
+ /**
2
+ * "Later" (coherence KTD4 to KTD6): move a pending task so it never runs
3
+ * earlier than its current planned start. One preset vocabulary for every
4
+ * surface (KTD15), resolved in the process's local time zone. Pure apart
5
+ * from the limit-reset hint, which the helpers read and write through the
6
+ * store's meta table.
7
+ *
8
+ * `Scheduler.postponeTask` turns a resolved target into a reschedule: delay
9
+ * presets and `after_limit_reset` become `{notBefore}` (the scheduler's
10
+ * `startFields` rule: the deadline rises to at least `notBefore + 2 h` and
11
+ * a later one is kept), day presets become `{dayStart, dayEnd}` (the
12
+ * deadline is the window end), and a pin becomes `{at}`.
13
+ */
14
+ import type { RescheduleTarget } from "./scheduler.js";
15
+ import type { TaskRecord } from "./types.js";
16
+ /** Preset ids every surface maps to (KTD15). */
17
+ export type PostponePreset = "1h" | "tonight" | "tomorrow_morning" | "after_limit_reset";
18
+ /** Presets in display order. */
19
+ export declare const POSTPONE_PRESETS: readonly PostponePreset[];
20
+ /** Display labels of the presets (KTD15). */
21
+ export declare const POSTPONE_LABELS: Readonly<Record<PostponePreset, string>>;
22
+ /** Target of {@link Scheduler.postponeTask}: a preset, a delay or an exact pin. */
23
+ export type PostponeTarget =
24
+ /** `resetAt` applies to `after_limit_reset` only and wins over every other reset source. */
25
+ {
26
+ preset: PostponePreset;
27
+ resetAt?: string | Date;
28
+ }
29
+ /** Not before the planned start plus `delayMs` (the CLI's `+<dur>`). */
30
+ | {
31
+ delayMs: number;
32
+ }
33
+ /** An exact time (a picked time). */
34
+ | {
35
+ until: string | Date;
36
+ };
37
+ /** A known limit reset and where it came from (`caller`, `hint`, or the source's own name). */
38
+ export interface LimitReset {
39
+ at: Date;
40
+ source: string;
41
+ }
42
+ /**
43
+ * The plugged-in reset source (KTD5), for example the CLI usage module's
44
+ * Claude limit reset. Returns null when it knows no reset for `task`.
45
+ */
46
+ export type LimitResetSource = (task: TaskRecord<unknown>, now: Date) => LimitReset | null | Promise<LimitReset | null>;
47
+ /** One entry of {@link postponeOptions}; `not_before` is ISO-8601, null when unavailable. */
48
+ export interface PostponeOption {
49
+ preset: PostponePreset;
50
+ label: string;
51
+ not_before: string | null;
52
+ available: boolean;
53
+ reason?: string;
54
+ }
55
+ /** Ledger meta key of the last reset time a caller gave (`{at, provider}`). */
56
+ export declare const LIMIT_RESET_HINT_META_KEY = "limit_reset_hint";
57
+ /** The meta part of a `TaskStore` the hint helpers need. */
58
+ export interface MetaStore {
59
+ getMeta(key: string): string | undefined;
60
+ setMeta(key: string, value: string): void;
61
+ }
62
+ /** Local hour the `tonight` preset starts; also the start of a channel's quiet hours (KTD10). */
63
+ export declare const TONIGHT_START_H = 22;
64
+ /** Local hour the `tomorrow_morning` preset starts; also the end of a channel's quiet hours (KTD10). */
65
+ export declare const MORNING_START_H = 9;
66
+ export declare const NEEDS_RESET_TIME = "needs the reset time";
67
+ /** The stored hint, when it is still in the future. */
68
+ export declare function readLimitResetHint(store: MetaStore | undefined, now: Date): LimitReset | null;
69
+ /** Store a caller-given reset as the hint for later tasks. */
70
+ export declare function writeLimitResetHint(store: MetaStore | undefined, at: Date, provider: string | undefined): void;
71
+ /**
72
+ * The reset `after_limit_reset` waits for (R14): the plugged-in source,
73
+ * else a still-future stored hint. A caller-given `reset_at` is handled by
74
+ * the caller before this, because it wins over both.
75
+ */
76
+ export declare function resolveLimitReset(record: TaskRecord<unknown>, now: Date, source: LimitResetSource | undefined, store: MetaStore | undefined): Promise<LimitReset | null>;
77
+ /** The provider of a provider-call task, if the body parses. */
78
+ export declare function taskProvider(record: TaskRecord<unknown>): string | undefined;
79
+ /**
80
+ * The planned start (KTD4): `scheduledFor` if in the future, else a future
81
+ * `notBefore`, else now. `future` is false for "now", where any target at
82
+ * or after now is later.
83
+ */
84
+ export declare function plannedStart(record: TaskRecord<unknown>, now: Date): {
85
+ at: Date;
86
+ future: boolean;
87
+ };
88
+ /** "23:00" on the local day of `now`, else "2026-10-23 23:00". */
89
+ export declare function localTimeLabel(at: Date, now: Date): string;
90
+ /** A resolved postpone: the earliest start and the reschedule that writes it. */
91
+ export type ResolvedPostpone = {
92
+ ok: true;
93
+ notBefore: Date;
94
+ reschedule: RescheduleTarget;
95
+ } | {
96
+ ok: false;
97
+ reason: string;
98
+ };
99
+ /**
100
+ * Resolve `target` for `record` at `now` (KTD4). `reset` is the reset an
101
+ * `after_limit_reset` target uses (already resolved by precedence); a
102
+ * target's own `resetAt` wins over it. Refuses a task that is not movable,
103
+ * a window with less than one hour left, a missing reset, and any start at
104
+ * or before the planned start.
105
+ */
106
+ export declare function resolvePostpone(record: TaskRecord<unknown>, target: PostponeTarget, now: Date, reset: LimitReset | null): ResolvedPostpone;
107
+ /**
108
+ * The presets for `record` with their resolved earliest start (KTD6), for
109
+ * every surface: the API's `later_options`, the page menu, the clients and
110
+ * the Telegram buttons. `reset` is the known limit reset, or null.
111
+ */
112
+ export declare function postponeOptions(record: TaskRecord<unknown>, now: Date, reset: LimitReset | null): PostponeOption[];
113
+ //# sourceMappingURL=postpone.d.ts.map