@tidegap/core 0.19.0 → 0.21.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 +1 -1
  2. package/dist/agent-snippet.d.ts +30 -0
  3. package/dist/agent-snippet.js +120 -0
  4. package/dist/channels/commands.d.ts +137 -0
  5. package/dist/channels/commands.js +377 -0
  6. package/dist/channels/delivery-codes.d.ts +9 -0
  7. package/dist/channels/delivery-codes.js +53 -0
  8. package/dist/channels/digest.d.ts +102 -0
  9. package/dist/channels/digest.js +146 -0
  10. package/dist/channels/format.d.ts +138 -0
  11. package/dist/channels/format.js +425 -0
  12. package/dist/channels/index.d.ts +15 -0
  13. package/dist/channels/index.js +15 -0
  14. package/dist/channels/kinds/command.d.ts +13 -0
  15. package/dist/channels/kinds/command.js +65 -0
  16. package/dist/channels/kinds/discord.d.ts +16 -0
  17. package/dist/channels/kinds/discord.js +67 -0
  18. package/dist/channels/kinds/email.d.ts +20 -0
  19. package/dist/channels/kinds/email.js +162 -0
  20. package/dist/channels/kinds/index.d.ts +8 -0
  21. package/dist/channels/kinds/index.js +17 -0
  22. package/dist/channels/kinds/ntfy.d.ts +25 -0
  23. package/dist/channels/kinds/ntfy.js +163 -0
  24. package/dist/channels/kinds/pushover.d.ts +11 -0
  25. package/dist/channels/kinds/pushover.js +77 -0
  26. package/dist/channels/kinds/shared.d.ts +25 -0
  27. package/dist/channels/kinds/shared.js +39 -0
  28. package/dist/channels/kinds/shortcuts.d.ts +9 -0
  29. package/dist/channels/kinds/shortcuts.js +45 -0
  30. package/dist/channels/kinds/slack.d.ts +8 -0
  31. package/dist/channels/kinds/slack.js +57 -0
  32. package/dist/channels/kinds/telegram.d.ts +4 -0
  33. package/dist/channels/kinds/telegram.js +26 -0
  34. package/dist/channels/kinds/webhook.d.ts +30 -0
  35. package/dist/channels/kinds/webhook.js +177 -0
  36. package/dist/channels/payload.d.ts +36 -0
  37. package/dist/channels/payload.js +61 -0
  38. package/dist/channels/plan.d.ts +24 -0
  39. package/dist/channels/plan.js +66 -0
  40. package/dist/channels/registry.d.ts +191 -0
  41. package/dist/channels/registry.js +125 -0
  42. package/dist/channels/telegram.d.ts +110 -0
  43. package/dist/channels/telegram.js +168 -0
  44. package/dist/channels/types.d.ts +107 -0
  45. package/dist/channels/types.js +26 -0
  46. package/dist/claude-tools.d.ts +29 -0
  47. package/dist/claude-tools.js +49 -0
  48. package/dist/data/tables.generated.d.ts +6 -0
  49. package/dist/data/tables.generated.js +37 -0
  50. package/dist/energy.d.ts +84 -0
  51. package/dist/energy.js +138 -0
  52. package/dist/grid.d.ts +17 -2
  53. package/dist/grid.js +43 -4
  54. package/dist/handoff.d.ts +171 -0
  55. package/dist/handoff.js +482 -0
  56. package/dist/history.d.ts +17 -0
  57. package/dist/history.js +14 -1
  58. package/dist/index.d.ts +49 -15
  59. package/dist/index.js +36 -8
  60. package/dist/job-cadence.d.ts +76 -0
  61. package/dist/job-cadence.js +240 -0
  62. package/dist/jobs.d.ts +183 -0
  63. package/dist/jobs.js +917 -0
  64. package/dist/notify.d.ts +11 -0
  65. package/dist/notify.js +19 -4
  66. package/dist/postpone.d.ts +113 -0
  67. package/dist/postpone.js +185 -0
  68. package/dist/providers/anthropic.js +14 -8
  69. package/dist/providers/base.d.ts +145 -2
  70. package/dist/providers/base.js +41 -1
  71. package/dist/providers/budget.d.ts +25 -0
  72. package/dist/providers/budget.js +57 -0
  73. package/dist/providers/defaults.js +4 -0
  74. package/dist/providers/defer.d.ts +16 -0
  75. package/dist/providers/defer.js +31 -0
  76. package/dist/providers/gemini.d.ts +4 -0
  77. package/dist/providers/gemini.js +34 -24
  78. package/dist/providers/http.d.ts +40 -0
  79. package/dist/providers/http.js +82 -0
  80. package/dist/providers/index.d.ts +2 -2
  81. package/dist/providers/index.js +1 -1
  82. package/dist/providers/ollama.d.ts +4 -0
  83. package/dist/providers/ollama.js +32 -25
  84. package/dist/providers/openai.js +11 -9
  85. package/dist/providers/timeout.d.ts +36 -0
  86. package/dist/providers/timeout.js +71 -0
  87. package/dist/quota.d.ts +7 -2
  88. package/dist/quota.js +12 -27
  89. package/dist/readiness.d.ts +205 -0
  90. package/dist/readiness.js +326 -0
  91. package/dist/redact.d.ts +42 -0
  92. package/dist/redact.js +110 -0
  93. package/dist/region-host.d.ts +30 -0
  94. package/dist/region-host.js +69 -0
  95. package/dist/region.d.ts +102 -20
  96. package/dist/region.js +175 -23
  97. package/dist/run-limits.d.ts +268 -0
  98. package/dist/run-limits.js +572 -0
  99. package/dist/run-session.d.ts +36 -0
  100. package/dist/run-session.js +72 -0
  101. package/dist/schedule-job.d.ts +118 -0
  102. package/dist/schedule-job.js +243 -0
  103. package/dist/scheduler.d.ts +391 -18
  104. package/dist/scheduler.js +1341 -177
  105. package/dist/sign.d.ts +8 -1
  106. package/dist/sign.js +49 -3
  107. package/dist/storage/sqlite.d.ts +183 -5
  108. package/dist/storage/sqlite.js +720 -19
  109. package/dist/task-events.d.ts +117 -0
  110. package/dist/task-events.js +345 -0
  111. package/dist/tool-surface.d.ts +31 -2
  112. package/dist/tool-surface.js +390 -65
  113. package/dist/types.d.ts +267 -3
  114. package/dist/types.js +6 -1
  115. package/dist/zone-time.d.ts +22 -0
  116. package/dist/zone-time.js +76 -0
  117. package/package.json +13 -5
  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/jobs.d.ts ADDED
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Floating recurring jobs: the job store actions and the job sweep.
3
+ *
4
+ * A job ("at least once a day, check my mail") keeps exactly one live
5
+ * occurrence in the ledger: an ordinary provider-call task with `job_id`
6
+ * set, `repeat = none` and no series. The id is derived, `<job_id>~<seq>`
7
+ * (a retry is `<job_id>~<seq>r`), and inserted once (`insertIfAbsent`).
8
+ *
9
+ * {@link sweepJobs} owns every transition the daemon makes (KTD2). It runs
10
+ * inside `prepareTick`, so every ticker gets it. For each job it reads the
11
+ * tracked occurrence and:
12
+ *
13
+ * - live occurrence: nothing (R17), except a `running` one whose tick is
14
+ * gone or whose dispatch is older than its time limits allow, which
15
+ * fails as interrupted (a Batch row with a batch id goes back to
16
+ * `submitted` instead);
17
+ * - finished occurrence: records the outcome (KTD9: ok, a failure with
18
+ * the retries of the job's retry policy per slot and auto-pause after
19
+ * three failed slots, or a skip), then materializes the next
20
+ * occurrence;
21
+ * - no occurrence on an active job: materializes one.
22
+ *
23
+ * Every job write is a compare-and-set on `revision`. Pause, edit and
24
+ * remove write the job row first, then cancel the tracked occurrence; a
25
+ * sweep whose job write misses leaves its insert to the next pass, which
26
+ * adopts it on an active job and cancels it otherwise (the stop-flag-first
27
+ * rule). The sweep never throws.
28
+ */
29
+ import { BATCH_SUBMIT_INTERRUPTED_ERROR } from "./history.js";
30
+ import { type SleepReading } from "./readiness.js";
31
+ import type { Scheduler } from "./scheduler.js";
32
+ import { type ResolvedRunLimits } from "./run-limits.js";
33
+ import { type JobCadence, type JobCaps, type JobNotify, type JobRecord, type JobTemplate, type JobWindow, type TaskRecord, type TaskStatus } from "./types.js";
34
+ /** Why a job action was refused; `code` maps to an HTTP status in the hosts. */
35
+ export declare class JobActionError extends Error {
36
+ /** `invalid` = bad input (400), `not_found` (404), `conflict` = the state forbids it (409). */
37
+ readonly code: "invalid" | "not_found" | "conflict";
38
+ /**
39
+ * A finer cause for a host that answers it: `stale_revision` = the caller
40
+ * holds an older revision than the stored job ({@link updateJob}).
41
+ */
42
+ readonly reason?: "stale_revision" | undefined;
43
+ constructor(message: string,
44
+ /** `invalid` = bad input (400), `not_found` (404), `conflict` = the state forbids it (409). */
45
+ code?: "invalid" | "not_found" | "conflict",
46
+ /**
47
+ * A finer cause for a host that answers it: `stale_revision` = the caller
48
+ * holds an older revision than the stored job ({@link updateJob}).
49
+ */
50
+ reason?: "stale_revision" | undefined);
51
+ }
52
+ /** What a caller gives to create a job. */
53
+ export interface JobInput {
54
+ title: string;
55
+ cadence: JobCadence;
56
+ window?: JobWindow;
57
+ /** IANA zone; default the system zone. */
58
+ timeZone?: string;
59
+ template: JobTemplate;
60
+ caps?: JobCapsPatch;
61
+ /** Default `every_run`. */
62
+ notify?: JobNotify;
63
+ /** `page`, `cli`, `mcp` or `openclaw`. */
64
+ originHost?: string;
65
+ originCwd?: string;
66
+ /**
67
+ * Deadline of the first occurrence (an agent's `schedule_task` deadline,
68
+ * AS9): it may run from now until then. Later ones follow the cadence.
69
+ */
70
+ deadline?: string | Date;
71
+ }
72
+ /** The fields {@link updateJob} can change; `window: null` removes the window. */
73
+ export interface JobPatch {
74
+ title?: string;
75
+ cadence?: JobCadence;
76
+ window?: JobWindow | null;
77
+ timeZone?: string;
78
+ template?: JobTemplate;
79
+ caps?: JobCapsPatch;
80
+ notify?: JobNotify;
81
+ }
82
+ /**
83
+ * Caps a caller sets: a value sets the key. `null` removes a time limit, so
84
+ * the setting or the default applies at each run, and puts any other cap
85
+ * back to its default.
86
+ */
87
+ export type JobCapsPatch = {
88
+ [K in Exclude<keyof JobCaps, "capsVersion">]?: JobCaps[K] | null;
89
+ };
90
+ /** Every caps key a caller may set. */
91
+ export declare const JOB_CAPS_KEYS: ReadonlySet<string>;
92
+ /** Per-call options of the job actions. */
93
+ export interface JobActionOptions {
94
+ /** Who the change is recorded as on occurrence events; default `system`. */
95
+ actor?: string;
96
+ }
97
+ /** Options of {@link updateJob}. */
98
+ export interface JobUpdateOptions extends JobActionOptions {
99
+ /**
100
+ * The revision the caller edited. A stored job with another revision
101
+ * refuses the edit with reason `stale_revision`; omitted = last writer wins.
102
+ */
103
+ expectedRevision?: number;
104
+ }
105
+ /** One occurrence in {@link jobHistory}, newest first. */
106
+ export interface JobHistoryEntry {
107
+ taskId: string;
108
+ status: TaskStatus;
109
+ enqueuedAt: string;
110
+ scheduledFor?: string;
111
+ deadline?: string;
112
+ completedAt?: string;
113
+ /** True when the occurrence has a carbon receipt. */
114
+ hasReceipt: boolean;
115
+ /** Actual grams on the receipt, else the schedule-time estimate. */
116
+ carbonG?: number;
117
+ /** First line of the error, for a failed occurrence. */
118
+ error?: string;
119
+ }
120
+ /** What one {@link sweepJobs} pass did. */
121
+ export interface JobSweepResult {
122
+ /** One line per change and per failure, for the tick log. */
123
+ messages: string[];
124
+ /** Occurrence ids inserted this pass (retries included). */
125
+ materialized: string[];
126
+ /** Retry occurrence ids inserted this pass. */
127
+ retried: string[];
128
+ /** Jobs paused after their third failed slot this pass. */
129
+ autoPaused: string[];
130
+ /** Running occurrences failed as interrupted this pass. */
131
+ interrupted: string[];
132
+ }
133
+ /** A job secret name: what the command sees as an environment variable. */
134
+ export declare const JOB_SECRET_NAME: RegExp;
135
+ /** Failed slots in a row that pause a job. */
136
+ export declare const JOB_AUTO_PAUSE_FAILURES = 3;
137
+ /** How `pauseReason` starts when the third failed slot paused the job: `auto: <first error line>`. */
138
+ export declare const JOB_AUTO_PAUSE_PREFIX = "auto: ";
139
+ /** The error line of an auto-pause reason, or undefined when the job was not paused by its failures. */
140
+ export declare function jobAutoPauseReason(pauseReason: string | undefined): string | undefined;
141
+ export declare const JOB_INTERRUPTED_ERROR = "interrupted: the tick stopped during the run";
142
+ export { BATCH_SUBMIT_INTERRUPTED_ERROR };
143
+ /**
144
+ * The time limits a run of `job` gets if it starts now, with their sources:
145
+ * the scheduler's settings reader, or without one the settings file.
146
+ */
147
+ export declare function jobRunLimits(job: JobRecord, scheduler?: Scheduler): ResolvedRunLimits;
148
+ /**
149
+ * The job sweep (KTD2): for every job, record the outcome of its finished
150
+ * occurrence and keep one live occurrence per active job. Never throws.
151
+ */
152
+ export declare function sweepJobs(scheduler: Scheduler, now?: Date, opts?: {
153
+ sleepNow?: SleepReading | null;
154
+ }): Promise<JobSweepResult>;
155
+ /** Create a job and its first occurrence. Throws {@link JobActionError} on bad input. */
156
+ export declare function createJob(scheduler: Scheduler, input: JobInput, opts?: JobActionOptions): Promise<JobRecord>;
157
+ /**
158
+ * Change a job; the pending occurrence is replaced by one on the new rule (a
159
+ * running one keeps its template). With `expectedRevision`, a job another
160
+ * writer changed since is refused with reason `stale_revision`.
161
+ */
162
+ export declare function updateJob(scheduler: Scheduler, jobId: string, patch: JobPatch, opts?: JobUpdateOptions): Promise<JobRecord>;
163
+ /** Pause an active job; its pending occurrence is cancelled, a running one finishes with no successor. */
164
+ export declare function pauseJob(scheduler: Scheduler, jobId: string, opts?: JobActionOptions): Promise<JobRecord>;
165
+ /** Resume a paused job: counter reset, one occurrence from now, no backfill (R8). */
166
+ export declare function resumeJob(scheduler: Scheduler, jobId: string, opts?: JobActionOptions): Promise<JobRecord>;
167
+ /**
168
+ * Run a job at the next tick (AS10): its pending occurrence is expedited
169
+ * (no second row). Refused while an occurrence runs or the job is paused.
170
+ * Returns the expedited occurrence.
171
+ */
172
+ export declare function runJobNow(scheduler: Scheduler, jobId: string, opts?: JobActionOptions): Promise<TaskRecord<unknown>>;
173
+ /** Remove a job: it stops and is hidden; its rows and history stay (AS11). */
174
+ export declare function removeJob(scheduler: Scheduler, jobId: string, opts?: JobActionOptions): Promise<JobRecord>;
175
+ /** One job, removed ones included; undefined when the id is unknown. */
176
+ export declare function getJob(scheduler: Scheduler, jobId: string): JobRecord | undefined;
177
+ /** Jobs, oldest first; removed jobs are hidden unless asked for. */
178
+ export declare function listJobs(scheduler: Scheduler, opts?: {
179
+ includeRemoved?: boolean;
180
+ }): JobRecord[];
181
+ /** A job's occurrences, newest first. */
182
+ export declare function jobHistory(scheduler: Scheduler, jobId: string, limit?: number): JobHistoryEntry[];
183
+ //# sourceMappingURL=jobs.d.ts.map