@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.
- package/README.md +1 -1
- package/dist/agent-snippet.d.ts +30 -0
- package/dist/agent-snippet.js +120 -0
- package/dist/channels/commands.d.ts +137 -0
- package/dist/channels/commands.js +377 -0
- package/dist/channels/delivery-codes.d.ts +9 -0
- package/dist/channels/delivery-codes.js +53 -0
- package/dist/channels/digest.d.ts +102 -0
- package/dist/channels/digest.js +146 -0
- package/dist/channels/format.d.ts +138 -0
- package/dist/channels/format.js +425 -0
- package/dist/channels/index.d.ts +15 -0
- package/dist/channels/index.js +15 -0
- package/dist/channels/kinds/command.d.ts +13 -0
- package/dist/channels/kinds/command.js +65 -0
- package/dist/channels/kinds/discord.d.ts +16 -0
- package/dist/channels/kinds/discord.js +67 -0
- package/dist/channels/kinds/email.d.ts +20 -0
- package/dist/channels/kinds/email.js +162 -0
- package/dist/channels/kinds/index.d.ts +8 -0
- package/dist/channels/kinds/index.js +17 -0
- package/dist/channels/kinds/ntfy.d.ts +25 -0
- package/dist/channels/kinds/ntfy.js +163 -0
- package/dist/channels/kinds/pushover.d.ts +11 -0
- package/dist/channels/kinds/pushover.js +77 -0
- package/dist/channels/kinds/shared.d.ts +25 -0
- package/dist/channels/kinds/shared.js +39 -0
- package/dist/channels/kinds/shortcuts.d.ts +9 -0
- package/dist/channels/kinds/shortcuts.js +45 -0
- package/dist/channels/kinds/slack.d.ts +8 -0
- package/dist/channels/kinds/slack.js +57 -0
- package/dist/channels/kinds/telegram.d.ts +4 -0
- package/dist/channels/kinds/telegram.js +26 -0
- package/dist/channels/kinds/webhook.d.ts +30 -0
- package/dist/channels/kinds/webhook.js +177 -0
- package/dist/channels/payload.d.ts +36 -0
- package/dist/channels/payload.js +61 -0
- package/dist/channels/plan.d.ts +24 -0
- package/dist/channels/plan.js +66 -0
- package/dist/channels/registry.d.ts +191 -0
- package/dist/channels/registry.js +125 -0
- package/dist/channels/telegram.d.ts +110 -0
- package/dist/channels/telegram.js +168 -0
- package/dist/channels/types.d.ts +107 -0
- package/dist/channels/types.js +26 -0
- package/dist/claude-tools.d.ts +29 -0
- package/dist/claude-tools.js +49 -0
- package/dist/data/tables.generated.d.ts +6 -0
- package/dist/data/tables.generated.js +37 -0
- package/dist/energy.d.ts +84 -0
- package/dist/energy.js +138 -0
- package/dist/grid.d.ts +17 -2
- package/dist/grid.js +43 -4
- package/dist/handoff.d.ts +171 -0
- package/dist/handoff.js +482 -0
- package/dist/history.d.ts +17 -0
- package/dist/history.js +14 -1
- package/dist/index.d.ts +49 -15
- package/dist/index.js +36 -8
- package/dist/job-cadence.d.ts +76 -0
- package/dist/job-cadence.js +240 -0
- package/dist/jobs.d.ts +183 -0
- package/dist/jobs.js +917 -0
- package/dist/notify.d.ts +11 -0
- package/dist/notify.js +19 -4
- package/dist/postpone.d.ts +113 -0
- package/dist/postpone.js +185 -0
- package/dist/providers/anthropic.js +14 -8
- package/dist/providers/base.d.ts +145 -2
- package/dist/providers/base.js +41 -1
- package/dist/providers/budget.d.ts +25 -0
- package/dist/providers/budget.js +57 -0
- package/dist/providers/defaults.js +4 -0
- package/dist/providers/defer.d.ts +16 -0
- package/dist/providers/defer.js +31 -0
- package/dist/providers/gemini.d.ts +4 -0
- package/dist/providers/gemini.js +34 -24
- package/dist/providers/http.d.ts +40 -0
- package/dist/providers/http.js +82 -0
- package/dist/providers/index.d.ts +2 -2
- package/dist/providers/index.js +1 -1
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +32 -25
- package/dist/providers/openai.js +11 -9
- package/dist/providers/timeout.d.ts +36 -0
- package/dist/providers/timeout.js +71 -0
- package/dist/quota.d.ts +7 -2
- package/dist/quota.js +12 -27
- package/dist/readiness.d.ts +205 -0
- package/dist/readiness.js +326 -0
- package/dist/redact.d.ts +42 -0
- package/dist/redact.js +110 -0
- package/dist/region-host.d.ts +30 -0
- package/dist/region-host.js +69 -0
- package/dist/region.d.ts +102 -20
- package/dist/region.js +175 -23
- package/dist/run-limits.d.ts +268 -0
- package/dist/run-limits.js +572 -0
- package/dist/run-session.d.ts +36 -0
- package/dist/run-session.js +72 -0
- package/dist/schedule-job.d.ts +118 -0
- package/dist/schedule-job.js +243 -0
- package/dist/scheduler.d.ts +391 -18
- package/dist/scheduler.js +1341 -177
- package/dist/sign.d.ts +8 -1
- package/dist/sign.js +49 -3
- package/dist/storage/sqlite.d.ts +183 -5
- package/dist/storage/sqlite.js +720 -19
- package/dist/task-events.d.ts +117 -0
- package/dist/task-events.js +345 -0
- package/dist/tool-surface.d.ts +31 -2
- package/dist/tool-surface.js +390 -65
- package/dist/types.d.ts +267 -3
- package/dist/types.js +6 -1
- package/dist/zone-time.d.ts +22 -0
- package/dist/zone-time.js +76 -0
- package/package.json +13 -5
- package/dist/aggregator.d.ts.map +0 -1
- package/dist/aggregator.js.map +0 -1
- package/dist/budget.d.ts.map +0 -1
- package/dist/budget.js.map +0 -1
- package/dist/data/tables.generated.d.ts.map +0 -1
- package/dist/data/tables.generated.js.map +0 -1
- package/dist/energy.d.ts.map +0 -1
- package/dist/energy.js.map +0 -1
- package/dist/grid.d.ts.map +0 -1
- package/dist/grid.js.map +0 -1
- package/dist/history.d.ts.map +0 -1
- package/dist/history.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/notify.d.ts.map +0 -1
- package/dist/notify.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/base.d.ts.map +0 -1
- package/dist/providers/base.js.map +0 -1
- package/dist/providers/defaults.d.ts.map +0 -1
- package/dist/providers/defaults.js.map +0 -1
- package/dist/providers/gemini.d.ts.map +0 -1
- package/dist/providers/gemini.js.map +0 -1
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/ollama.d.ts.map +0 -1
- package/dist/providers/ollama.js.map +0 -1
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js.map +0 -1
- package/dist/quota.d.ts.map +0 -1
- package/dist/quota.js.map +0 -1
- package/dist/recommend.d.ts.map +0 -1
- package/dist/recommend.js.map +0 -1
- package/dist/redact.d.ts.map +0 -1
- package/dist/redact.js.map +0 -1
- package/dist/region.d.ts.map +0 -1
- package/dist/region.js.map +0 -1
- package/dist/routing.d.ts.map +0 -1
- package/dist/routing.js.map +0 -1
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js.map +0 -1
- package/dist/select-window.d.ts.map +0 -1
- package/dist/select-window.js.map +0 -1
- package/dist/sign.d.ts.map +0 -1
- package/dist/sign.js.map +0 -1
- package/dist/storage/sqlite.d.ts.map +0 -1
- package/dist/storage/sqlite.js.map +0 -1
- package/dist/tool-surface.d.ts.map +0 -1
- package/dist/tool-surface.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/sign.d.ts
CHANGED
|
@@ -82,6 +82,12 @@ export declare function loadOrCreateSigningKey(opts?: SigningKeyOptions): Signin
|
|
|
82
82
|
* canonical form is total.
|
|
83
83
|
*/
|
|
84
84
|
export declare function canonicalize(value: unknown): string;
|
|
85
|
+
/**
|
|
86
|
+
* `snake_case` → `camelCase`; already-camel keys pass through unchanged.
|
|
87
|
+
* The ledger reader (`storage/sqlite.ts`) renames a Python receipt's keys
|
|
88
|
+
* by this rule too, so the copy it shows and the payload checked here agree.
|
|
89
|
+
*/
|
|
90
|
+
export declare function snakeToCamelKey(key: string): string;
|
|
85
91
|
/**
|
|
86
92
|
* The exact canonical byte string a receipt's signature covers:
|
|
87
93
|
* camelCase-normalized payload minus `signature`/`signerPublicKey`,
|
|
@@ -120,7 +126,8 @@ export interface VerifyResult {
|
|
|
120
126
|
* (v0.12 form with `signedAt` covered, or the
|
|
121
127
|
* legacy v0.11 form — the reason says which).
|
|
122
128
|
* - `tampered` — receipt is signed but the signature matches
|
|
123
|
-
* none of the canonical forms of its fields
|
|
129
|
+
* none of the canonical forms of its fields, or
|
|
130
|
+
* it carries two renderings of one field.
|
|
124
131
|
* - `key-mismatch` — caller supplied a `trustedPublicKey` that
|
|
125
132
|
* differs from the one bundled on the receipt.
|
|
126
133
|
* - `legacy-unsigned` — pre-v0.11 receipt (no signature). The
|
package/dist/sign.js
CHANGED
|
@@ -161,8 +161,12 @@ const SIGNATURE_FIELDS_ANY_RENDERING = new Set([
|
|
|
161
161
|
"signedAt",
|
|
162
162
|
"signed_at",
|
|
163
163
|
]);
|
|
164
|
-
/**
|
|
165
|
-
|
|
164
|
+
/**
|
|
165
|
+
* `snake_case` → `camelCase`; already-camel keys pass through unchanged.
|
|
166
|
+
* The ledger reader (`storage/sqlite.ts`) renames a Python receipt's keys
|
|
167
|
+
* by this rule too, so the copy it shows and the payload checked here agree.
|
|
168
|
+
*/
|
|
169
|
+
export function snakeToCamelKey(key) {
|
|
166
170
|
return key.replace(/_([a-z0-9])/g, (_m, c) => c.toUpperCase());
|
|
167
171
|
}
|
|
168
172
|
/**
|
|
@@ -186,6 +190,39 @@ function normalizeReceiptKeys(value) {
|
|
|
186
190
|
}
|
|
187
191
|
return value;
|
|
188
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* The camelCase name that two keys of one object normalize to, at any
|
|
195
|
+
* depth, or undefined. No signer writes two renderings of one field
|
|
196
|
+
* (`actualCarbonGCo2` and `actual_carbon_g_co2`), and normalization keeps
|
|
197
|
+
* only the last of them, so a receipt that carries both could show one
|
|
198
|
+
* value and verify against the other. Null and undefined values do not
|
|
199
|
+
* count: normalization drops them.
|
|
200
|
+
*/
|
|
201
|
+
function duplicateRendering(value) {
|
|
202
|
+
if (Array.isArray(value)) {
|
|
203
|
+
for (const v of value) {
|
|
204
|
+
const name = duplicateRendering(v);
|
|
205
|
+
if (name !== undefined)
|
|
206
|
+
return name;
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
if (value === null || typeof value !== "object")
|
|
211
|
+
return undefined;
|
|
212
|
+
const seen = new Set();
|
|
213
|
+
for (const [k, v] of Object.entries(value)) {
|
|
214
|
+
if (v === undefined || v === null)
|
|
215
|
+
continue;
|
|
216
|
+
const name = snakeToCamelKey(k);
|
|
217
|
+
if (seen.has(name))
|
|
218
|
+
return name;
|
|
219
|
+
seen.add(name);
|
|
220
|
+
const nested = duplicateRendering(v);
|
|
221
|
+
if (nested !== undefined)
|
|
222
|
+
return nested;
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
189
226
|
/**
|
|
190
227
|
* The exact canonical byte string a receipt's signature covers:
|
|
191
228
|
* camelCase-normalized payload minus `signature`/`signerPublicKey`,
|
|
@@ -258,7 +295,8 @@ export function signReceipt(receipt, keyPair, now = () => new Date()) {
|
|
|
258
295
|
* (v0.12 form with `signedAt` covered, or the
|
|
259
296
|
* legacy v0.11 form — the reason says which).
|
|
260
297
|
* - `tampered` — receipt is signed but the signature matches
|
|
261
|
-
* none of the canonical forms of its fields
|
|
298
|
+
* none of the canonical forms of its fields, or
|
|
299
|
+
* it carries two renderings of one field.
|
|
262
300
|
* - `key-mismatch` — caller supplied a `trustedPublicKey` that
|
|
263
301
|
* differs from the one bundled on the receipt.
|
|
264
302
|
* - `legacy-unsigned` — pre-v0.11 receipt (no signature). The
|
|
@@ -275,6 +313,14 @@ export function verifyReceipt(receipt, opts = {}) {
|
|
|
275
313
|
reason: "receipt has no `signature` / `signerPublicKey` fields (pre-v0.11 or unsigned by configuration)",
|
|
276
314
|
};
|
|
277
315
|
}
|
|
316
|
+
const duplicate = duplicateRendering(raw);
|
|
317
|
+
if (duplicate !== undefined) {
|
|
318
|
+
return {
|
|
319
|
+
outcome: "tampered",
|
|
320
|
+
signerPublicKey,
|
|
321
|
+
reason: `receipt carries two renderings of \`${duplicate}\`; no signer writes both, so one was added after signing`,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
278
324
|
if (opts.trustedPublicKey && opts.trustedPublicKey !== signerPublicKey) {
|
|
279
325
|
return {
|
|
280
326
|
outcome: "key-mismatch",
|
package/dist/storage/sqlite.d.ts
CHANGED
|
@@ -40,6 +40,12 @@
|
|
|
40
40
|
* (nullable = none, ui v2); written at insert and
|
|
41
41
|
* afterwards only by transitionIf ("stop series")
|
|
42
42
|
* - not_before ISO-8601 earliest dispatch time (nullable, ui v2)
|
|
43
|
+
* - job_id the job this row is an occurrence of (nullable,
|
|
44
|
+
* written once at insert)
|
|
45
|
+
*
|
|
46
|
+
* The `jobs` table (TS-only; the Python core never reads it) holds floating
|
|
47
|
+
* recurring jobs. Every job write after the insert is a compare-and-set on
|
|
48
|
+
* `revision` (`updateJobIf`).
|
|
43
49
|
*
|
|
44
50
|
* Writes from separate processes (the UI server, the CLI, a ticker) use
|
|
45
51
|
* compare-and-set: `transitionIf` updates a row only while its status is in
|
|
@@ -49,7 +55,9 @@
|
|
|
49
55
|
* JSON-serializable are stored as `{ "_repr": "<toString>" }` so audit
|
|
50
56
|
* trails survive odd values without crashing the store.
|
|
51
57
|
*/
|
|
52
|
-
import type
|
|
58
|
+
import { type DeadlineKind, type JobRecord, type JobStatus, type TaskRecord, type TaskStatus } from "../types.js";
|
|
59
|
+
import { type Channel } from "../channels/types.js";
|
|
60
|
+
import { type TaskEvent, type TaskEventActor, type TaskEventInput, type TaskEventKind } from "../task-events.js";
|
|
53
61
|
interface SqliteDatabase {
|
|
54
62
|
exec(sql: string): void;
|
|
55
63
|
prepare(sql: string): SqlitePreparedStatement;
|
|
@@ -65,31 +73,63 @@ interface SqlitePreparedStatement {
|
|
|
65
73
|
}
|
|
66
74
|
/** Filters for {@link TaskStore.list}; all given filters must match. */
|
|
67
75
|
export interface TaskListFilter {
|
|
68
|
-
status
|
|
76
|
+
/** One status, or any of several. */
|
|
77
|
+
status?: TaskStatus | readonly TaskStatus[];
|
|
69
78
|
/** Only finished (`completed` / `failed`) tasks with no read marker. */
|
|
70
79
|
unread?: boolean;
|
|
71
80
|
/** `absolute` also matches legacy rows with no stored kind. */
|
|
72
81
|
deadlineKind?: DeadlineKind;
|
|
73
82
|
/** Only occurrences of this series (ui v2). */
|
|
74
83
|
seriesId?: string;
|
|
84
|
+
/** Only occurrences of this job. */
|
|
85
|
+
jobId?: string;
|
|
86
|
+
/** Only the tasks queued from this Claude Code session (`origin_session_id`). */
|
|
87
|
+
originSessionId?: string;
|
|
88
|
+
/** Newest first (default oldest first). */
|
|
89
|
+
newestFirst?: boolean;
|
|
90
|
+
/** At most this many rows. */
|
|
91
|
+
limit?: number;
|
|
75
92
|
}
|
|
76
93
|
export interface TaskStoreOptions {
|
|
77
94
|
/** Absolute path to a SQLite file. Use ":memory:" for ephemeral storage (tests). */
|
|
78
95
|
dbPath: string;
|
|
79
96
|
/** Inject a pre-opened SQLite database — node:sqlite or better-sqlite3 (useful for tests). */
|
|
80
97
|
db?: SqliteDatabase;
|
|
98
|
+
/**
|
|
99
|
+
* How long a write waits for another writer before it fails, in ms.
|
|
100
|
+
* Default 5000. A prompt hook passes a short one, so a busy daemon cannot
|
|
101
|
+
* hold the user's prompt.
|
|
102
|
+
*/
|
|
103
|
+
busyTimeoutMs?: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Ledger meta key: a session notice covers only tasks that finished at or
|
|
107
|
+
* after this ISO time. Set once, by the first notice query, so an upgrade
|
|
108
|
+
* does not replay the history of every session.
|
|
109
|
+
*/
|
|
110
|
+
export declare const SESSION_NOTICES_SINCE_META_KEY = "session_notices_since";
|
|
111
|
+
/** A finished task stays a session notice for this long. */
|
|
112
|
+
export declare const SESSION_NOTICE_MAX_AGE_MS: number;
|
|
113
|
+
/** One finished task a Claude Code session has not been told about. */
|
|
114
|
+
export interface SessionNotice {
|
|
115
|
+
record: TaskRecord<unknown>;
|
|
116
|
+
/** The result file the task asked for (`handoff.resultPath` of its body). */
|
|
117
|
+
resultPath?: string;
|
|
118
|
+
/** Details of the newest `result_file` event, when one was recorded. */
|
|
119
|
+
resultFile?: Record<string, unknown>;
|
|
81
120
|
}
|
|
82
121
|
export declare class TaskStore {
|
|
83
122
|
private readonly db;
|
|
123
|
+
private txDepth;
|
|
84
124
|
constructor(opts: TaskStoreOptions);
|
|
85
|
-
upsert(record: TaskRecord<unknown
|
|
125
|
+
upsert(record: TaskRecord<unknown>, event?: TaskEventInput): void;
|
|
86
126
|
/**
|
|
87
127
|
* Insert a row only if no row with this id exists (ui v2). Returns true iff
|
|
88
128
|
* this call inserted it. Series rollover uses it with a deterministic
|
|
89
129
|
* successor id, so two dispatchers finishing the same occurrence create
|
|
90
130
|
* exactly one successor.
|
|
91
131
|
*/
|
|
92
|
-
insertIfAbsent(record: TaskRecord<unknown
|
|
132
|
+
insertIfAbsent(record: TaskRecord<unknown>, event?: TaskEventInput): boolean;
|
|
93
133
|
/**
|
|
94
134
|
* Compare-and-set write (ui v2): store the mutable columns of `record`, but
|
|
95
135
|
* only while the row's status is one of `expectedStatuses`. Returns false,
|
|
@@ -102,8 +142,117 @@ export declare class TaskStore {
|
|
|
102
142
|
* that earlier read: a write computed from a stale read (a forecast fetch
|
|
103
143
|
* that awaited while the UI ran a task now or pinned it) then misses
|
|
104
144
|
* instead of overwriting the newer timing.
|
|
145
|
+
*
|
|
146
|
+
* `event`, when given, is written to `task_events` in the same
|
|
147
|
+
* transaction, and only when the update hit.
|
|
148
|
+
*/
|
|
149
|
+
transitionIf(record: TaskRecord<unknown>, expectedStatuses: readonly TaskStatus[], unchangedSince?: TaskRecord<unknown>, event?: TaskEventInput): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Append one event to a task's log in its own transaction. `busyMs` bounds
|
|
152
|
+
* the wait for another writer's lock for this write only (a progress line
|
|
153
|
+
* of a running command must not hold the tick for seconds): past it the
|
|
154
|
+
* write throws SQLITE_BUSY. The connection's own busy timeout is restored
|
|
155
|
+
* in `finally`, so no other write gets the short wait. It only shortens
|
|
156
|
+
* the wait: a connection whose own timeout is already shorter (or cannot
|
|
157
|
+
* be read) keeps it.
|
|
158
|
+
*/
|
|
159
|
+
recordEvent(taskId: string, event: TaskEventInput, opts?: {
|
|
160
|
+
busyMs?: number;
|
|
161
|
+
}): void;
|
|
162
|
+
/** How many events of `kind` a task has: one `COUNT(*)`, no rows read. */
|
|
163
|
+
countTaskEvents(taskId: string, kind: TaskEventKind): number;
|
|
164
|
+
/**
|
|
165
|
+
* Merge `details` into the newest `kind` event of a task: a fact learned
|
|
166
|
+
* after another writer recorded the event (the tick that stopped a
|
|
167
|
+
* cancelled run adds `stopped_run`). Returns false when the task has no
|
|
168
|
+
* such event.
|
|
169
|
+
*/
|
|
170
|
+
annotateEvent(taskId: string, kind: TaskEventKind, details: Record<string, unknown>): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* A task's events, oldest first. `limit` keeps the newest `limit` rows.
|
|
173
|
+
* Rows with an unknown kind (a newer writer) are skipped.
|
|
174
|
+
*/
|
|
175
|
+
listTaskEvents(taskId: string, opts?: {
|
|
176
|
+
limit?: number;
|
|
177
|
+
}): TaskEvent[];
|
|
178
|
+
/**
|
|
179
|
+
* Events of every task with `at` in (`since`, `until`], oldest first,
|
|
180
|
+
* optionally of the given kinds only. Rows with an unknown kind are skipped.
|
|
181
|
+
*/
|
|
182
|
+
listEventsSince(since: string, until: string, kinds?: readonly TaskEventKind[]): TaskEvent[];
|
|
183
|
+
/**
|
|
184
|
+
* A task's events with an `id` greater than `afterId`, oldest first: the
|
|
185
|
+
* cursor of `queue events --after`, since `id` grows with each insert.
|
|
186
|
+
* Rows with an unknown kind are skipped.
|
|
187
|
+
*/
|
|
188
|
+
listTaskEventsAfter(taskId: string, afterId: number): TaskEvent[];
|
|
189
|
+
/**
|
|
190
|
+
* Finished tasks a Claude Code session has not been told about, oldest
|
|
191
|
+
* first: `completed`, `failed` or `cancelled`, queued from `sessionId`
|
|
192
|
+
* (every session when absent) with a checked origin in the body, no
|
|
193
|
+
* `notified` event for this finish (its `completed_at`; a retried task
|
|
194
|
+
* that finishes again is a new notice), and finished at or after
|
|
195
|
+
* {@link SESSION_NOTICES_SINCE_META_KEY} and within
|
|
196
|
+
* {@link SESSION_NOTICE_MAX_AGE_MS}. A completed task that asked for a
|
|
197
|
+
* result file waits until its `result_file` event exists. A person's read
|
|
198
|
+
* marker does not matter here.
|
|
105
199
|
*/
|
|
106
|
-
|
|
200
|
+
listSessionNotices(opts?: {
|
|
201
|
+
sessionId?: string;
|
|
202
|
+
now?: Date;
|
|
203
|
+
}): SessionNotice[];
|
|
204
|
+
/**
|
|
205
|
+
* Record that a session was told about a task's current finish: a
|
|
206
|
+
* `notified` event whose details carry the task's `completed_at`, written
|
|
207
|
+
* only when no `notified` event has that `completed_at` yet. Returns true
|
|
208
|
+
* iff this call wrote it, so the prompt hook, `queue wait` and a wake never
|
|
209
|
+
* claim the same finish twice, and a retried task that finishes again is
|
|
210
|
+
* claimed again. A task that does not exist is never claimed.
|
|
211
|
+
*/
|
|
212
|
+
claimNotice(taskId: string, details: {
|
|
213
|
+
via: string;
|
|
214
|
+
session_id: string;
|
|
215
|
+
}, actor?: TaskEventActor): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Completed tasks that asked for a result file (`handoff.resultPath` in
|
|
218
|
+
* the body) and have no `result_file` event yet, oldest first, whichever
|
|
219
|
+
* core finished them. A body that is not valid JSON is skipped.
|
|
220
|
+
*/
|
|
221
|
+
listResultFilesDue(): TaskRecord<unknown>[];
|
|
222
|
+
/**
|
|
223
|
+
* Record the outcome of a task's result file: a `result_file` event
|
|
224
|
+
* (actor `tick`), written only when the task has none yet. Returns true
|
|
225
|
+
* iff this call wrote it.
|
|
226
|
+
*/
|
|
227
|
+
recordResultFile(taskId: string, details: Record<string, unknown>): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Set {@link SESSION_NOTICES_SINCE_META_KEY} to `at` unless it is set. The
|
|
230
|
+
* scheduler calls it when it queues a task from a session, so that task's
|
|
231
|
+
* notice is not lost when the first notice query runs only after it
|
|
232
|
+
* finished. Best-effort: a read-only ledger is left alone.
|
|
233
|
+
*/
|
|
234
|
+
startSessionNotices(at?: Date): void;
|
|
235
|
+
/**
|
|
236
|
+
* {@link SESSION_NOTICES_SINCE_META_KEY}, set to `now` on first use; `now`
|
|
237
|
+
* when the ledger cannot be written. Read first, so a set key costs no
|
|
238
|
+
* write lock (the prompt hook runs this on every delivery).
|
|
239
|
+
*/
|
|
240
|
+
private noticesSince;
|
|
241
|
+
/** Completed and failed tasks with `completed_at` in (`since`, `until`], oldest first (both cores write `completed_at`). */
|
|
242
|
+
listFinishedSince(since: string, until: string): TaskRecord<unknown>[];
|
|
243
|
+
private insertEvent;
|
|
244
|
+
/**
|
|
245
|
+
* Run `fn` in one write transaction (`BEGIN IMMEDIATE`), rolled back when
|
|
246
|
+
* it throws. Re-entrant: a nested call joins the open transaction.
|
|
247
|
+
*/
|
|
248
|
+
private tx;
|
|
249
|
+
/**
|
|
250
|
+
* The receipt of `taskId` exactly as stored, in either key rendering, or
|
|
251
|
+
* undefined. Signature checks read it: a Python receipt signed by v0.11 or
|
|
252
|
+
* older verifies only against its original snake_case keys, which
|
|
253
|
+
* {@link get} renames.
|
|
254
|
+
*/
|
|
255
|
+
storedReceipt(taskId: string): Record<string, unknown> | undefined;
|
|
107
256
|
get(taskId: string): TaskRecord<unknown> | undefined;
|
|
108
257
|
list(filter?: TaskListFilter): TaskRecord<unknown>[];
|
|
109
258
|
/**
|
|
@@ -123,6 +272,21 @@ export declare class TaskStore {
|
|
|
123
272
|
getMeta(key: string): string | undefined;
|
|
124
273
|
/** Write one ledger-wide meta value. */
|
|
125
274
|
setMeta(key: string, value: string): void;
|
|
275
|
+
/** Remove one meta value; a missing key is a no-op. */
|
|
276
|
+
deleteMeta(key: string): void;
|
|
277
|
+
/**
|
|
278
|
+
* Compare-and-set one meta value across processes: write `next` (delete
|
|
279
|
+
* the key when `next` is undefined) only while the stored value is still
|
|
280
|
+
* `expected` (undefined: the key is absent). Returns whether it wrote. Two
|
|
281
|
+
* processes that read the same value cannot both win.
|
|
282
|
+
*/
|
|
283
|
+
setMetaIf(key: string, expected: string | undefined, next: string | undefined): boolean;
|
|
284
|
+
/** Every channel row, oldest first; a row with an unknown kind or bad JSON is skipped. */
|
|
285
|
+
listChannels(): Channel[];
|
|
286
|
+
/** Insert or replace a channel row (pairing the same chat again replaces it). */
|
|
287
|
+
insertChannel(channel: Channel): void;
|
|
288
|
+
/** Remove a channel; false when no row had that id. */
|
|
289
|
+
removeChannel(id: string): boolean;
|
|
126
290
|
/**
|
|
127
291
|
* Conditional write for the quota sweep: store the columns a reschedule
|
|
128
292
|
* (or a budget failure) changes, but only while the row is still pending
|
|
@@ -163,6 +327,20 @@ export declare class TaskStore {
|
|
|
163
327
|
recordBudgetAlert(windowKind: string, windowStart: string, thresholdG: number, actualG: number, taskId: string | undefined, alertedAt: string): boolean;
|
|
164
328
|
/** True if an alert has already fired for this (windowKind, windowStart, thresholdG). */
|
|
165
329
|
hasBudgetAlert(windowKind: string, windowStart: string, thresholdG: number): boolean;
|
|
330
|
+
/** Insert a new job row. Throws when the id exists. */
|
|
331
|
+
insertJob(job: JobRecord): void;
|
|
332
|
+
getJob(jobId: string): JobRecord | undefined;
|
|
333
|
+
/** Jobs, oldest first; `status` limits the list to one or several statuses. */
|
|
334
|
+
listJobs(filter?: {
|
|
335
|
+
status?: JobStatus | readonly JobStatus[];
|
|
336
|
+
}): JobRecord[];
|
|
337
|
+
/**
|
|
338
|
+
* Compare-and-set job write: store the mutable columns of `next` only while
|
|
339
|
+
* the row's revision is `expectedRevision`, and add one to the revision.
|
|
340
|
+
* Returns false, writing nothing, when another writer got there first.
|
|
341
|
+
* `job_id`, `created_at`, `created_by` and the origin columns never change.
|
|
342
|
+
*/
|
|
343
|
+
updateJobIf(next: JobRecord, expectedRevision: number): boolean;
|
|
166
344
|
close(): void;
|
|
167
345
|
}
|
|
168
346
|
export {};
|