@tidegap/core 0.20.0 → 0.22.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/dist/channels/digest.js +4 -4
- package/dist/channels/format.d.ts +30 -4
- package/dist/channels/format.js +125 -22
- package/dist/channels/payload.js +8 -6
- package/dist/channels/plan.js +3 -2
- package/dist/channels/types.d.ts +17 -1
- package/dist/energy.d.ts +7 -0
- package/dist/energy.js +7 -0
- package/dist/grid.d.ts +10 -2
- package/dist/grid.js +14 -5
- package/dist/handoff.d.ts +88 -6
- package/dist/handoff.js +177 -20
- package/dist/history.d.ts +19 -0
- package/dist/history.js +24 -1
- package/dist/index.d.ts +24 -18
- package/dist/index.js +16 -12
- package/dist/job-cadence.d.ts +10 -0
- package/dist/job-cadence.js +34 -0
- package/dist/job-wake.d.ts +55 -0
- package/dist/job-wake.js +91 -0
- package/dist/jobs.d.ts +74 -17
- package/dist/jobs.js +420 -75
- package/dist/notify.d.ts +9 -0
- package/dist/notify.js +17 -3
- package/dist/providers/anthropic.js +8 -6
- package/dist/providers/base.d.ts +47 -9
- package/dist/providers/base.js +29 -4
- package/dist/providers/gemini.d.ts +3 -0
- package/dist/providers/gemini.js +9 -6
- package/dist/providers/http.d.ts +40 -0
- package/dist/providers/http.js +82 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/ollama.d.ts +3 -0
- package/dist/providers/ollama.js +8 -5
- package/dist/providers/openai.js +7 -5
- package/dist/providers/timeout.d.ts +26 -8
- package/dist/providers/timeout.js +53 -15
- package/dist/readiness.d.ts +39 -3
- package/dist/readiness.js +73 -1
- package/dist/run-limits.d.ts +268 -0
- package/dist/run-limits.js +572 -0
- package/dist/schedule-job.d.ts +41 -2
- package/dist/schedule-job.js +70 -2
- package/dist/scheduler.d.ts +161 -17
- package/dist/scheduler.js +485 -128
- package/dist/storage/sqlite.d.ts +52 -5
- package/dist/storage/sqlite.js +200 -33
- package/dist/task-events.d.ts +19 -4
- package/dist/task-events.js +51 -5
- package/dist/tool-surface.js +62 -7
- package/dist/types.d.ts +72 -11
- package/dist/types.js +1 -3
- package/package.json +5 -2
package/dist/channels/digest.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { localTimeLabel, MORNING_START_H } from "../postpone.js";
|
|
11
11
|
import { problemLine } from "../readiness.js";
|
|
12
|
-
import { messageTitle } from "./format.js";
|
|
12
|
+
import { cutPreview, messageTitle } from "./format.js";
|
|
13
13
|
/**
|
|
14
14
|
* Ledger meta key: ISO-8601 end of the last summary window. An empty day
|
|
15
15
|
* moves it too, so it is not proof of a send; see {@link DIGEST_SENT_META_KEY}.
|
|
@@ -55,14 +55,14 @@ export function digestDue(now, lastIso, at = DEFAULT_DIGEST_AT) {
|
|
|
55
55
|
const due = now.getTime() >= today.getTime() && !(Number.isFinite(last) && last >= midnight);
|
|
56
56
|
return { due, since };
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
const JOB_PREVIEW_CHARS =
|
|
58
|
+
/** Most characters (code points, ellipsis included) of a run preview a job line quotes. */
|
|
59
|
+
const JOB_PREVIEW_CHARS = 100;
|
|
60
60
|
/** `Mail triage: ok 03:12, "3 messages need a reply..." - next Fri 02:00` (KTD11). */
|
|
61
61
|
export function jobDigestText(job) {
|
|
62
62
|
const { last } = job;
|
|
63
63
|
const when = last.late ? `ran late at ${last.at}` : `${last.outcome} ${last.at}`;
|
|
64
64
|
const preview = last.preview?.replace(/\s+/g, " ").trim();
|
|
65
|
-
const quoted = preview ? `"${preview
|
|
65
|
+
const quoted = preview ? `"${cutPreview(preview, JOB_PREVIEW_CHARS)}"` : "";
|
|
66
66
|
const next = job.next ? ` - next ${job.next}` : "";
|
|
67
67
|
if (job.runs <= 1) {
|
|
68
68
|
const late = last.late && last.outcome === "failed" ? ` (${last.outcome})` : "";
|
|
@@ -22,7 +22,7 @@ import { type PostponeOption, type PostponePreset } from "../postpone.js";
|
|
|
22
22
|
import { type ReadinessProblem } from "../readiness.js";
|
|
23
23
|
import type { JobRecord, TaskRecord } from "../types.js";
|
|
24
24
|
import { type InlineKeyboard } from "./telegram.js";
|
|
25
|
-
import type { ChannelEvent, CleanWindowEvent, JobPausedNotice } from "./types.js";
|
|
25
|
+
import type { ChannelEvent, CleanWindowEvent, JobEndedNotice, JobPausedNotice } from "./types.js";
|
|
26
26
|
/** Characters of result text a done message previews (Q4). */
|
|
27
27
|
export declare const TELEGRAM_PREVIEW_CHARS = 600;
|
|
28
28
|
/** Most messages one `/result` sends before pointing to `tidegap queue show`. */
|
|
@@ -51,16 +51,36 @@ export declare const CALLBACK_ACTIONS: Readonly<Record<string, CallbackActionNam
|
|
|
51
51
|
export declare const CALLBACK_PRESETS: Readonly<Record<string, PostponePreset>>;
|
|
52
52
|
/** True when the task asked for receipt redaction (`redactInReceipt` with patterns): no result text leaves the machine. */
|
|
53
53
|
export declare function isRedactedTask(record: TaskRecord<unknown>): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The one-line preview of a run, the same on the jobs page and in the
|
|
56
|
+
* digest (KTD6): a failed task's first error line with visible text, a
|
|
57
|
+
* completed task's summary, or its result text without one, unless it
|
|
58
|
+
* redacts its receipt, else undefined. Default-redacted, control characters
|
|
59
|
+
* removed, whitespace runs joined; a longer text is cut to `maxChars - 1`
|
|
60
|
+
* code points plus "…", so the result never exceeds `maxChars`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function runPreview(record: TaskRecord<unknown>, maxChars: number): string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* A run's verdict, the one line a person reads first: for a completed run
|
|
65
|
+
* that does not redact its receipt, the first line of its summary, else of
|
|
66
|
+
* its result text; for a failed run, its first error line. Cut to
|
|
67
|
+
* `maxChars`; undefined when there is no such line.
|
|
68
|
+
*/
|
|
69
|
+
export declare function runVerdict(record: TaskRecord<unknown>, maxChars?: number): string | undefined;
|
|
70
|
+
/** `text` cut to `maxChars - 1` code points plus "…" when longer, so it never exceeds `maxChars` (KTD6). */
|
|
71
|
+
export declare function cutPreview(text: string, maxChars: number): string;
|
|
54
72
|
/** The title a message shows: `displayTitle`, one line, at most 80 characters, else the task id. */
|
|
55
73
|
export declare function messageTitle(record: TaskRecord<unknown>): string;
|
|
56
74
|
/** The title a task event's message shows: the job's title for a job occurrence, else {@link messageTitle}. */
|
|
57
75
|
export declare function eventTitle(record: TaskRecord<unknown>, jobTitle?: string): string;
|
|
58
76
|
/**
|
|
59
77
|
* Task done (R26): title, time, where it ran, the preview or the redaction
|
|
60
|
-
* note, and a [Result] button. A job occurrence
|
|
61
|
-
* `<job title
|
|
78
|
+
* note, and a [Result] button with the raw result. A job occurrence
|
|
79
|
+
* (`jobTitle`) leads with `<job title> — <verdict>`, adds the job's next run
|
|
80
|
+
* (`jobNext`) to the time line, a `No summary` line when its summarize step
|
|
81
|
+
* failed, and shows its summary in place of the raw preview.
|
|
62
82
|
*/
|
|
63
|
-
export declare function taskDoneMessage(record: TaskRecord<unknown>, now?: Date, jobTitle?: string): OutgoingMessage;
|
|
83
|
+
export declare function taskDoneMessage(record: TaskRecord<unknown>, now?: Date, jobTitle?: string, jobNext?: string): OutgoingMessage;
|
|
64
84
|
/**
|
|
65
85
|
* Task failed: title, time, the first error line, the show command. No
|
|
66
86
|
* buttons. A job occurrence (`jobTitle`) leads with `<job title>: failed`.
|
|
@@ -70,6 +90,12 @@ export declare function taskFailedMessage(record: TaskRecord<unknown>, now?: Dat
|
|
|
70
90
|
export declare function jobPausedTitle(notice: JobPausedNotice): string;
|
|
71
91
|
/** The auto-pause notice: the sentence, then how to resume. No buttons. */
|
|
72
92
|
export declare function jobPausedMessage(notice: JobPausedNotice): OutgoingMessage;
|
|
93
|
+
/** The first line of a job's final notice: `Job ended: "<title>"`. */
|
|
94
|
+
export declare function jobEndedTitle(notice: JobEndedNotice): string;
|
|
95
|
+
/** The body of a job's final notice: why it ended, then its last run with its verdict, or its first error line. */
|
|
96
|
+
export declare function jobEndedBody(notice: JobEndedNotice, last: TaskRecord<unknown>): string;
|
|
97
|
+
/** A job's final notice: the title line and the body. No buttons. */
|
|
98
|
+
export declare function jobEndedMessage(notice: JobEndedNotice, last: TaskRecord<unknown>): OutgoingMessage;
|
|
73
99
|
/** A clean window starting. No buttons. */
|
|
74
100
|
export declare function cleanWindowMessage(window: CleanWindowEvent, now?: Date): OutgoingMessage;
|
|
75
101
|
/**
|
package/dist/channels/format.js
CHANGED
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
* | not ready | none |
|
|
19
19
|
* | replies and `/result` | none |
|
|
20
20
|
*/
|
|
21
|
-
import { displayTitle, stripControlChars, taskActions, taskResultText } from "../history.js";
|
|
22
|
-
import { JOB_AUTO_PAUSE_FAILURES, jobAutoPauseReason } from "../jobs.js";
|
|
23
|
-
import { clip } from "../notify.js";
|
|
21
|
+
import { displayTitle, stripControlChars, taskActions, taskResultText, taskSummaryError, taskSummaryText } from "../history.js";
|
|
22
|
+
import { JOB_AUTO_PAUSE_FAILURES, jobAutoPauseReason, jobEndText } from "../jobs.js";
|
|
23
|
+
import { clip, firstErrorLine, oneLine } from "../notify.js";
|
|
24
24
|
import { localTimeLabel } from "../postpone.js";
|
|
25
25
|
import { problemLine, TICKER_CODES } from "../readiness.js";
|
|
26
26
|
import { isValidTimeZone } from "../zone-time.js";
|
|
@@ -29,6 +29,8 @@ import { freshReasonText, shortSessionId } from "../run-session.js";
|
|
|
29
29
|
import { TELEGRAM_CALLBACK_MAX_BYTES, TELEGRAM_MESSAGE_MAX } from "./telegram.js";
|
|
30
30
|
/** Characters of result text a done message previews (Q4). */
|
|
31
31
|
export const TELEGRAM_PREVIEW_CHARS = 600;
|
|
32
|
+
/** Most characters of the verdict a job's notice leads with. */
|
|
33
|
+
const VERDICT_CHARS = 120;
|
|
32
34
|
/** Most messages one `/result` sends before pointing to `tidegap queue show`. */
|
|
33
35
|
export const RESULT_MAX_PARTS = 4;
|
|
34
36
|
/** Tasks one `/queue` lists. */
|
|
@@ -62,14 +64,62 @@ export function isRedactedTask(record) {
|
|
|
62
64
|
return false;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* The one-line preview of a run, the same on the jobs page and in the
|
|
69
|
+
* digest (KTD6): a failed task's first error line with visible text, a
|
|
70
|
+
* completed task's summary, or its result text without one, unless it
|
|
71
|
+
* redacts its receipt, else undefined. Default-redacted, control characters
|
|
72
|
+
* removed, whitespace runs joined; a longer text is cut to `maxChars - 1`
|
|
73
|
+
* code points plus "…", so the result never exceeds `maxChars`.
|
|
74
|
+
*/
|
|
75
|
+
export function runPreview(record, maxChars) {
|
|
76
|
+
let text;
|
|
77
|
+
if (record.status === "failed")
|
|
78
|
+
text = firstErrorLine(record.error, Infinity);
|
|
79
|
+
else if (record.status === "completed" && !isRedactedTask(record))
|
|
80
|
+
text = oneLine(taskSummaryText(record) ?? taskResultText(record) ?? "");
|
|
81
|
+
return text ? cutPreview(text, maxChars) : undefined;
|
|
82
|
+
}
|
|
83
|
+
/** The first line of `text` with visible text, made one line (default-redacted), or undefined. */
|
|
84
|
+
function firstVisibleLine(text) {
|
|
85
|
+
for (const line of (text ?? "").split(/\r?\n/)) {
|
|
86
|
+
const one = oneLine(line);
|
|
87
|
+
if (one)
|
|
88
|
+
return one;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A run's verdict, the one line a person reads first: for a completed run
|
|
94
|
+
* that does not redact its receipt, the first line of its summary, else of
|
|
95
|
+
* its result text; for a failed run, its first error line. Cut to
|
|
96
|
+
* `maxChars`; undefined when there is no such line.
|
|
97
|
+
*/
|
|
98
|
+
export function runVerdict(record, maxChars = VERDICT_CHARS) {
|
|
99
|
+
let line;
|
|
100
|
+
if (record.status === "failed")
|
|
101
|
+
line = firstErrorLine(record.error, Infinity);
|
|
102
|
+
else if (record.status === "completed" && !isRedactedTask(record))
|
|
103
|
+
line = firstVisibleLine(taskSummaryText(record) ?? taskResultText(record));
|
|
104
|
+
return line ? cutPreview(line, maxChars) : undefined;
|
|
105
|
+
}
|
|
106
|
+
/** `text` cut to `maxChars - 1` code points plus "…" when longer, so it never exceeds `maxChars` (KTD6). */
|
|
107
|
+
export function cutPreview(text, maxChars) {
|
|
108
|
+
const chars = Array.from(text);
|
|
109
|
+
return chars.length > maxChars ? `${chars.slice(0, maxChars - 1).join("")}…` : text;
|
|
110
|
+
}
|
|
65
111
|
/** The title a message shows: `displayTitle`, one line, at most 80 characters, else the task id. */
|
|
66
112
|
export function messageTitle(record) {
|
|
67
113
|
const t = stripControlChars(displayTitle(record) ?? "").trim();
|
|
68
114
|
return t ? clip(t, 80) : record.taskId;
|
|
69
115
|
}
|
|
70
|
-
/**
|
|
116
|
+
/** Text safe to send: default-redacted, control characters removed, newlines kept. */
|
|
117
|
+
function safeText(text) {
|
|
118
|
+
return stripControlChars(redactPrompt(text ?? "", undefined), { multiline: true }).trim();
|
|
119
|
+
}
|
|
120
|
+
/** Result text safe to send. */
|
|
71
121
|
function safeResult(record) {
|
|
72
|
-
return
|
|
122
|
+
return safeText(taskResultText(record));
|
|
73
123
|
}
|
|
74
124
|
function showCommand(record) {
|
|
75
125
|
return `tidegap queue show ${record.taskId}`;
|
|
@@ -104,36 +154,71 @@ function cleanJobTitle(title) {
|
|
|
104
154
|
export function eventTitle(record, jobTitle) {
|
|
105
155
|
return cleanJobTitle(jobTitle) ?? messageTitle(record);
|
|
106
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* The body of a job run's notice: the summary without its verdict line (the
|
|
159
|
+
* whole summary when that line was cut), else the raw preview when the
|
|
160
|
+
* output has more than its verdict line; "" when there is nothing more.
|
|
161
|
+
*/
|
|
162
|
+
function jobDoneBody(record) {
|
|
163
|
+
const summary = safeText(taskSummaryText(record));
|
|
164
|
+
const result = summary ? "" : safeResult(record);
|
|
165
|
+
const verdict = firstVisibleLine(summary || result);
|
|
166
|
+
const cut = verdict !== undefined && Array.from(verdict).length > VERDICT_CHARS;
|
|
167
|
+
if (summary) {
|
|
168
|
+
const rest = cut ? summary : summary.replace(/^\s*[^\n]*\n?/, "").trim();
|
|
169
|
+
return clip(rest, TELEGRAM_PREVIEW_CHARS);
|
|
170
|
+
}
|
|
171
|
+
const preview = clip(result, TELEGRAM_PREVIEW_CHARS);
|
|
172
|
+
return cut || /\n/.test(preview) ? preview : "";
|
|
173
|
+
}
|
|
107
174
|
/**
|
|
108
175
|
* Task done (R26): title, time, where it ran, the preview or the redaction
|
|
109
|
-
* note, and a [Result] button. A job occurrence
|
|
110
|
-
* `<job title
|
|
176
|
+
* note, and a [Result] button with the raw result. A job occurrence
|
|
177
|
+
* (`jobTitle`) leads with `<job title> — <verdict>`, adds the job's next run
|
|
178
|
+
* (`jobNext`) to the time line, a `No summary` line when its summarize step
|
|
179
|
+
* failed, and shows its summary in place of the raw preview.
|
|
111
180
|
*/
|
|
112
|
-
export function taskDoneMessage(record, now = new Date(), jobTitle) {
|
|
181
|
+
export function taskDoneMessage(record, now = new Date(), jobTitle, jobNext) {
|
|
113
182
|
const job = cleanJobTitle(jobTitle);
|
|
114
183
|
const redacted = isRedactedTask(record);
|
|
115
|
-
const preview = redacted ? "" : clip(safeResult(record), TELEGRAM_PREVIEW_CHARS);
|
|
116
|
-
const lines = [job ? `${job}: ${preview ? clip(preview.replace(/\s+/g, " "), 200) : "done"}` : `Done: ${messageTitle(record)}`];
|
|
117
184
|
const at = when(record.completedAt, now);
|
|
118
|
-
|
|
119
|
-
|
|
185
|
+
const lines = [];
|
|
186
|
+
let body = "";
|
|
187
|
+
if (job) {
|
|
188
|
+
lines.push(`${job} — ${runVerdict(record) ?? "done"}`);
|
|
189
|
+
const next = jobNext && jobNext !== JOB_RUNNING_NOW ? `next ${jobNext}` : undefined;
|
|
190
|
+
const time = [at && `Finished ${at}`, next].filter(Boolean).join(" · ");
|
|
191
|
+
if (time)
|
|
192
|
+
lines.push(time);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
lines.push(`Done: ${messageTitle(record)}`);
|
|
196
|
+
if (at)
|
|
197
|
+
lines.push(`Finished ${at}`);
|
|
198
|
+
}
|
|
120
199
|
const ran = runSessionLine(record);
|
|
121
200
|
if (ran)
|
|
122
201
|
lines.push(ran);
|
|
202
|
+
if (job && !redacted) {
|
|
203
|
+
const failed = firstErrorLine(taskSummaryError(record), Infinity);
|
|
204
|
+
if (failed)
|
|
205
|
+
lines.push(`No summary: ${cutPreview(failed, VERDICT_CHARS)}`);
|
|
206
|
+
body = jobDoneBody(record);
|
|
207
|
+
}
|
|
208
|
+
else if (!redacted) {
|
|
209
|
+
body = clip(safeResult(record), TELEGRAM_PREVIEW_CHARS);
|
|
210
|
+
}
|
|
123
211
|
if (redacted) {
|
|
124
212
|
lines.push("", `The result is not sent here: this task redacts its receipt. Run \`${showCommand(record)}\`.`);
|
|
125
213
|
}
|
|
126
|
-
else if (
|
|
127
|
-
lines.push("",
|
|
214
|
+
else if (body) {
|
|
215
|
+
lines.push("", body);
|
|
128
216
|
}
|
|
129
217
|
const buttons = callbackFits(record.taskId) ? [[{ text: "Result", data: encodeCallback("result", record.taskId) }]] : undefined;
|
|
130
218
|
return { text: lines.join("\n"), ...(buttons ? { buttons } : {}) };
|
|
131
219
|
}
|
|
132
|
-
/** The first
|
|
133
|
-
|
|
134
|
-
const line = (error ?? "").split(/\r?\n/).find((l) => l.trim()) ?? "unknown error";
|
|
135
|
-
return clip(stripControlChars(redactPrompt(line, undefined)).trim(), max);
|
|
136
|
-
}
|
|
220
|
+
/** The first error line with visible text (notify's firstErrorLine), at most `max` characters, or "unknown error". */
|
|
221
|
+
const errorLine = (error, max = 300) => firstErrorLine(error, max) ?? "unknown error";
|
|
137
222
|
/**
|
|
138
223
|
* Task failed: title, time, the first error line, the show command. No
|
|
139
224
|
* buttons. A job occurrence (`jobTitle`) leads with `<job title>: failed`.
|
|
@@ -144,19 +229,33 @@ export function taskFailedMessage(record, now = new Date(), jobTitle) {
|
|
|
144
229
|
const at = when(record.completedAt, now);
|
|
145
230
|
if (at)
|
|
146
231
|
lines.push(`Failed ${at}`);
|
|
147
|
-
lines.push(
|
|
232
|
+
lines.push(errorLine(record.error));
|
|
148
233
|
lines.push(`Run \`${showCommand(record)}\`.`);
|
|
149
234
|
return { text: lines.join("\n") };
|
|
150
235
|
}
|
|
151
236
|
/** The first line of an auto-pause notice (jobs KTD10): `job '<title>' paused after 3 failures: <reason>`. */
|
|
152
237
|
export function jobPausedTitle(notice) {
|
|
153
238
|
const title = cleanJobTitle(notice.title) ?? notice.jobId;
|
|
154
|
-
return `job '${title}' paused after ${JOB_AUTO_PAUSE_FAILURES} failures: ${
|
|
239
|
+
return `job '${title}' paused after ${JOB_AUTO_PAUSE_FAILURES} failures: ${errorLine(notice.reason, 200)}`;
|
|
155
240
|
}
|
|
156
241
|
/** The auto-pause notice: the sentence, then how to resume. No buttons. */
|
|
157
242
|
export function jobPausedMessage(notice) {
|
|
158
243
|
return { text: `${jobPausedTitle(notice)}\nResume it: tidegap jobs resume ${notice.jobId}` };
|
|
159
244
|
}
|
|
245
|
+
/** The first line of a job's final notice: `Job ended: "<title>"`. */
|
|
246
|
+
export function jobEndedTitle(notice) {
|
|
247
|
+
return `Job ended: "${cleanJobTitle(notice.title) ?? notice.jobId}"`;
|
|
248
|
+
}
|
|
249
|
+
/** The body of a job's final notice: why it ended, then its last run with its verdict, or its first error line. */
|
|
250
|
+
export function jobEndedBody(notice, last) {
|
|
251
|
+
const title = cleanJobTitle(notice.title) ?? notice.jobId;
|
|
252
|
+
const verdict = runVerdict(last);
|
|
253
|
+
return `"${title}" ended: ${jobEndText(notice.reason, notice.until)}.\nLast run: ${last.taskId} ${notice.lastOutcome}${verdict ? `: ${verdict}` : "."}`;
|
|
254
|
+
}
|
|
255
|
+
/** A job's final notice: the title line and the body. No buttons. */
|
|
256
|
+
export function jobEndedMessage(notice, last) {
|
|
257
|
+
return { text: `${jobEndedTitle(notice)}\n${jobEndedBody(notice, last)}` };
|
|
258
|
+
}
|
|
160
259
|
/** A clean window starting. No buttons. */
|
|
161
260
|
export function cleanWindowMessage(window, now = new Date()) {
|
|
162
261
|
const start = when(window.start, now) ?? window.start;
|
|
@@ -181,8 +280,12 @@ export function notReadyMessage(problems, recovered = false) {
|
|
|
181
280
|
export function eventMessage(event, now = new Date()) {
|
|
182
281
|
switch (event.kind) {
|
|
183
282
|
case "task_done":
|
|
184
|
-
|
|
283
|
+
if (event.jobEnded)
|
|
284
|
+
return jobEndedMessage(event.jobEnded, event.task);
|
|
285
|
+
return taskDoneMessage(event.task, now, event.jobTitle, event.jobNext);
|
|
185
286
|
case "task_failed":
|
|
287
|
+
if (event.jobEnded)
|
|
288
|
+
return jobEndedMessage(event.jobEnded, event.task);
|
|
186
289
|
return event.jobPaused ? jobPausedMessage(event.jobPaused) : taskFailedMessage(event.task, now, event.jobTitle);
|
|
187
290
|
case "clean_window":
|
|
188
291
|
return cleanWindowMessage(event.window, now);
|
package/dist/channels/payload.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* redaction and the 600-character preview. Title and text are untrusted
|
|
5
5
|
* plain text: a `format` for a receiver that renders markup escapes them.
|
|
6
6
|
*/
|
|
7
|
-
import { eventMessage, eventTitle, jobPausedTitle } from "./format.js";
|
|
7
|
+
import { eventMessage, eventTitle, jobEndedTitle, jobPausedTitle } from "./format.js";
|
|
8
8
|
const LEVEL = {
|
|
9
9
|
task_done: "success",
|
|
10
10
|
task_failed: "error",
|
|
@@ -38,11 +38,13 @@ export function payloadFor(event, now = new Date()) {
|
|
|
38
38
|
const title = eventTitle(record, event.jobTitle);
|
|
39
39
|
const grams = record.receipt?.actualCarbonGCo2 ?? record.receipt?.estimatedCarbonGCo2;
|
|
40
40
|
const done = event.kind === "task_done";
|
|
41
|
-
const head = event.
|
|
42
|
-
?
|
|
43
|
-
: event.
|
|
44
|
-
?
|
|
45
|
-
:
|
|
41
|
+
const head = event.jobEnded
|
|
42
|
+
? jobEndedTitle(event.jobEnded)
|
|
43
|
+
: event.kind === "task_failed" && event.jobPaused
|
|
44
|
+
? jobPausedTitle(event.jobPaused)
|
|
45
|
+
: event.jobTitle
|
|
46
|
+
? `${title}: ${done ? "done" : "failed"}`
|
|
47
|
+
: `${done ? "Done" : "Failed"}: ${title}`;
|
|
46
48
|
return {
|
|
47
49
|
...base,
|
|
48
50
|
title: head,
|
package/dist/channels/plan.js
CHANGED
|
@@ -29,10 +29,11 @@ export function planNotifications(events, channels, now = new Date()) {
|
|
|
29
29
|
function coveredBy(event, covers) {
|
|
30
30
|
switch (event.kind) {
|
|
31
31
|
case "task_done":
|
|
32
|
-
|
|
32
|
+
// A job's final notice is sent on its own, even when the summary lists its last run.
|
|
33
|
+
return !event.jobEnded && covers.taskIds.includes(event.task.taskId);
|
|
33
34
|
case "task_failed":
|
|
34
35
|
// An auto-pause notice is sent on its own, even when the summary lists the failed run.
|
|
35
|
-
return !event.jobPaused && covers.taskIds.includes(event.task.taskId);
|
|
36
|
+
return !event.jobPaused && !event.jobEnded && covers.taskIds.includes(event.task.taskId);
|
|
36
37
|
case "not_ready":
|
|
37
38
|
// The summary does not say the daemon runs again, so a recovery is never folded.
|
|
38
39
|
return covers.notReady && !event.recovered;
|
package/dist/channels/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* every side effect (spawning the toast, calling the Bot API, sending HTTP).
|
|
7
7
|
*/
|
|
8
8
|
import type { ReadinessProblem } from "../readiness.js";
|
|
9
|
-
import type { TaskRecord } from "../types.js";
|
|
9
|
+
import type { JobEndReason, TaskRecord } from "../types.js";
|
|
10
10
|
/** Every kind a channel row can have: `os` plus the registry kinds (`kinds/index.ts` lists one descriptor per registry kind). */
|
|
11
11
|
export declare const CHANNEL_KINDS: readonly ["os", "telegram", "webhook", "slack", "discord", "ntfy", "pushover", "email", "shortcuts", "command"];
|
|
12
12
|
export type ChannelKind = (typeof CHANNEL_KINDS)[number];
|
|
@@ -52,6 +52,17 @@ export interface JobPausedNotice {
|
|
|
52
52
|
title: string;
|
|
53
53
|
reason: string;
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* What a job's final notice names: the job, why it ended, its end date for
|
|
57
|
+
* `until`, and the outcome of its last run (`task` of the event).
|
|
58
|
+
*/
|
|
59
|
+
export interface JobEndedNotice {
|
|
60
|
+
jobId: string;
|
|
61
|
+
title: string;
|
|
62
|
+
reason: JobEndReason;
|
|
63
|
+
until?: string;
|
|
64
|
+
lastOutcome: "ok" | "failed";
|
|
65
|
+
}
|
|
55
66
|
/** A task event a channel can receive. A `digest` carries its finished text; the host builds it from the ledger. */
|
|
56
67
|
export type ChannelEvent =
|
|
57
68
|
/** `jobTitle`: the task is an occurrence of this job; messages lead with the job's current title. */
|
|
@@ -59,6 +70,10 @@ export type ChannelEvent =
|
|
|
59
70
|
kind: "task_done";
|
|
60
71
|
task: TaskRecord<unknown>;
|
|
61
72
|
jobTitle?: string;
|
|
73
|
+
/** The job's next run as a label (`Sun 10:05`, `~Sun 10:05`), set when the event was built. */
|
|
74
|
+
jobNext?: string;
|
|
75
|
+
/** The job ended after this run; the message is its final notice. */
|
|
76
|
+
jobEnded?: JobEndedNotice;
|
|
62
77
|
}
|
|
63
78
|
/**
|
|
64
79
|
* `jobPaused`: the job paused itself after its third failed slot (jobs
|
|
@@ -69,6 +84,7 @@ export type ChannelEvent =
|
|
|
69
84
|
task: TaskRecord<unknown>;
|
|
70
85
|
jobTitle?: string;
|
|
71
86
|
jobPaused?: JobPausedNotice;
|
|
87
|
+
jobEnded?: JobEndedNotice;
|
|
72
88
|
} | {
|
|
73
89
|
kind: "clean_window";
|
|
74
90
|
window: CleanWindowEvent;
|
package/dist/energy.d.ts
CHANGED
|
@@ -195,6 +195,13 @@ export interface ModelUsageBill {
|
|
|
195
195
|
/** The receipt's `tokenCounts` over every billed count; absent when each was reported. */
|
|
196
196
|
tokenCounts?: TokenCounts;
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* The words every surface prints for a receipt's `tokenCounts` (batch 27, R6):
|
|
200
|
+
* `tidegap verify`, the MCP receipt text and the page (`ui/detail.js`, which
|
|
201
|
+
* cannot import the core; a CLI test holds its copy to these).
|
|
202
|
+
*/
|
|
203
|
+
export declare const TOKEN_COUNTS_PARTIAL_TEXT = "partial (a token count was not reported; billed at the typical count)";
|
|
204
|
+
export declare const TOKEN_COUNTS_TYPICAL_TEXT = "typical (no token count reported; billed as a typical call)";
|
|
198
205
|
/** A single-model run's raw counts, as an adapter or a Batch result reports them. */
|
|
199
206
|
export interface RunUsage {
|
|
200
207
|
inputTokens?: unknown;
|
package/dist/energy.js
CHANGED
|
@@ -216,6 +216,13 @@ function counted(u) {
|
|
|
216
216
|
* otherwise undefined, which `estimateEnergyKwh` bills at the typical count.
|
|
217
217
|
*/
|
|
218
218
|
const billedInput = (c) => c.inputTokens ?? (c.partialInputTokens !== undefined ? Math.max(c.partialInputTokens, TYPICAL_INPUT_TOKENS) : undefined);
|
|
219
|
+
/**
|
|
220
|
+
* The words every surface prints for a receipt's `tokenCounts` (batch 27, R6):
|
|
221
|
+
* `tidegap verify`, the MCP receipt text and the page (`ui/detail.js`, which
|
|
222
|
+
* cannot import the core; a CLI test holds its copy to these).
|
|
223
|
+
*/
|
|
224
|
+
export const TOKEN_COUNTS_PARTIAL_TEXT = "partial (a token count was not reported; billed at the typical count)";
|
|
225
|
+
export const TOKEN_COUNTS_TYPICAL_TEXT = "typical (no token count reported; billed as a typical call)";
|
|
219
226
|
/**
|
|
220
227
|
* The receipt's `tokenCounts` over the counts a bill used (KTD1): undefined
|
|
221
228
|
* when every count was reported in full, "typical" when no count and no
|
package/dist/grid.d.ts
CHANGED
|
@@ -75,6 +75,8 @@ export declare function electricityMapsFeed(apiKey?: string): GridFeed;
|
|
|
75
75
|
* Docs: https://carbon-intensity.github.io/api-definitions/#carbon-intensity
|
|
76
76
|
*/
|
|
77
77
|
export declare function ukCarbonIntensityFeed(): GridFeed;
|
|
78
|
+
/** The line a keyless EIA feed prints, at most once per process. */
|
|
79
|
+
export declare const EIA_NO_KEY_WARNING = "[tidegap/grid] no EIA API key configured \u2014 using mock data for EIA-eligible zones";
|
|
78
80
|
/**
|
|
79
81
|
* Carbon-intensity feed backed by the US Energy Information Administration's
|
|
80
82
|
* v2 Open Data API. Returns a synthesized hourly forecast from the most
|
|
@@ -83,7 +85,9 @@ export declare function ukCarbonIntensityFeed(): GridFeed;
|
|
|
83
85
|
* The key is always passed in by the host (CLI/MCP read `TIDEGAP_EIA_API_KEY`;
|
|
84
86
|
* the OpenClaw plugin reads `eiaApiKey` from plugin config).
|
|
85
87
|
*/
|
|
86
|
-
export declare function eiaFeed(apiKey?: string
|
|
88
|
+
export declare function eiaFeed(apiKey?: string, opts?: {
|
|
89
|
+
quiet?: boolean;
|
|
90
|
+
}): GridFeed;
|
|
87
91
|
/** One `<Period>` inside an ENTSO-E TimeSeries. */
|
|
88
92
|
export interface EntsoePeriod {
|
|
89
93
|
/** ISO-8601 start of the period's time interval. */
|
|
@@ -245,5 +249,9 @@ export declare function regionDataSource(zone: string, credentials?: GridFeedCre
|
|
|
245
249
|
* `buildDefaultGridFeed()` with no argument is exactly the "no keys
|
|
246
250
|
* configured" case: free UK feed for GB, deterministic mock everywhere else.
|
|
247
251
|
*/
|
|
248
|
-
export declare function buildDefaultGridFeed(credentials?: GridFeedCredentials
|
|
252
|
+
export declare function buildDefaultGridFeed(credentials?: GridFeedCredentials,
|
|
253
|
+
/** `quiet`: no "no EIA API key" line (a one-off CLI command; a receipt still says mock). */
|
|
254
|
+
opts?: {
|
|
255
|
+
quiet?: boolean;
|
|
256
|
+
}): GridFeed;
|
|
249
257
|
//# sourceMappingURL=grid.d.ts.map
|
package/dist/grid.js
CHANGED
|
@@ -380,6 +380,9 @@ const EIA_FUEL_FACTORS = {
|
|
|
380
380
|
* window left 11–15 hours-of-day and sent every US ISO to the mock.
|
|
381
381
|
*/
|
|
382
382
|
const EIA_HISTORY_HOURS = 72;
|
|
383
|
+
/** The line a keyless EIA feed prints, at most once per process. */
|
|
384
|
+
export const EIA_NO_KEY_WARNING = "[tidegap/grid] no EIA API key configured — using mock data for EIA-eligible zones";
|
|
385
|
+
let eiaKeyWarned = false;
|
|
383
386
|
/**
|
|
384
387
|
* Carbon-intensity feed backed by the US Energy Information Administration's
|
|
385
388
|
* v2 Open Data API. Returns a synthesized hourly forecast from the most
|
|
@@ -388,15 +391,19 @@ const EIA_HISTORY_HOURS = 72;
|
|
|
388
391
|
* The key is always passed in by the host (CLI/MCP read `TIDEGAP_EIA_API_KEY`;
|
|
389
392
|
* the OpenClaw plugin reads `eiaApiKey` from plugin config).
|
|
390
393
|
*/
|
|
391
|
-
export function eiaFeed(apiKey) {
|
|
394
|
+
export function eiaFeed(apiKey, opts = {}) {
|
|
392
395
|
const key = apiKey;
|
|
393
396
|
const mock = mockGridFeed();
|
|
394
397
|
if (!key) {
|
|
395
398
|
return {
|
|
396
399
|
source: "mock",
|
|
397
400
|
async fetchForecast(region, hours) {
|
|
398
|
-
//
|
|
399
|
-
|
|
401
|
+
// Once per process, across every keyless feed; a quiet feed (a one-off CLI command) never prints it.
|
|
402
|
+
if (!opts.quiet && !eiaKeyWarned) {
|
|
403
|
+
eiaKeyWarned = true;
|
|
404
|
+
// eslint-disable-next-line no-console
|
|
405
|
+
console.warn(EIA_NO_KEY_WARNING);
|
|
406
|
+
}
|
|
400
407
|
return mock.fetchForecast(region, hours);
|
|
401
408
|
},
|
|
402
409
|
};
|
|
@@ -1060,7 +1067,9 @@ export function regionDataSource(zone, credentials = {}) {
|
|
|
1060
1067
|
* `buildDefaultGridFeed()` with no argument is exactly the "no keys
|
|
1061
1068
|
* configured" case: free UK feed for GB, deterministic mock everywhere else.
|
|
1062
1069
|
*/
|
|
1063
|
-
export function buildDefaultGridFeed(credentials = {}
|
|
1070
|
+
export function buildDefaultGridFeed(credentials = {},
|
|
1071
|
+
/** `quiet`: no "no EIA API key" line (a one-off CLI command; a receipt still says mock). */
|
|
1072
|
+
opts = {}) {
|
|
1064
1073
|
const feeds = {
|
|
1065
1074
|
GB: ukCarbonIntensityFeed(),
|
|
1066
1075
|
};
|
|
@@ -1074,7 +1083,7 @@ export function buildDefaultGridFeed(credentials = {}) {
|
|
|
1074
1083
|
feeds[zone] = wattTimeFeed({
|
|
1075
1084
|
username: credentials.wattTimeUsername,
|
|
1076
1085
|
password: credentials.wattTimePassword,
|
|
1077
|
-
fallback: eiaFeed(credentials.eiaApiKey),
|
|
1086
|
+
fallback: eiaFeed(credentials.eiaApiKey, { quiet: opts.quiet }),
|
|
1078
1087
|
});
|
|
1079
1088
|
}
|
|
1080
1089
|
for (const zone of Object.keys(ENTSOE_BIDDING_ZONE_BY_REGION)) {
|
package/dist/handoff.d.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* and only Tidegap writes a result file, as a new file, never through a
|
|
10
10
|
* link.
|
|
11
11
|
*/
|
|
12
|
+
import { type SessionNotice, type TaskStore } from "./storage/sqlite.js";
|
|
13
|
+
import type { TaskRecord } from "./types.js";
|
|
12
14
|
/** A tool profile: a name for one of the existing tool sets. */
|
|
13
15
|
export type HandoffProfile = "read" | "web" | "none";
|
|
14
16
|
export declare const HANDOFF_PROFILES: readonly HandoffProfile[];
|
|
@@ -110,8 +112,13 @@ export interface TaskWorkShape {
|
|
|
110
112
|
profile?: string;
|
|
111
113
|
tools?: string[];
|
|
112
114
|
resultPath?: string;
|
|
113
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* True when the task wakes its idle origin session when it finishes; on
|
|
117
|
+
* a run of a bound job, when the job sweep's decision says so.
|
|
118
|
+
*/
|
|
114
119
|
wake?: boolean;
|
|
120
|
+
/** On a run of a bound job: the job's wake rule, which decides whether this run wakes. */
|
|
121
|
+
wakeRule?: "failures" | "match";
|
|
115
122
|
/** The shell command of a one-off command task. */
|
|
116
123
|
command?: string;
|
|
117
124
|
}
|
|
@@ -134,19 +141,94 @@ export declare function resultFileText(details: Record<string, unknown> | undefi
|
|
|
134
141
|
export declare function wakeError(wake: unknown, origin: {
|
|
135
142
|
agent?: unknown;
|
|
136
143
|
} | undefined, sessionId: unknown): string | undefined;
|
|
137
|
-
/**
|
|
138
|
-
|
|
144
|
+
/**
|
|
145
|
+
* The default ledger, `~/.tidegap/queue.db`: the one the CLI, the tick
|
|
146
|
+
* and the plugin's hooks read when no path is given. When only the legacy
|
|
147
|
+
* `~/.ebb/queue.sqlite` exists, that file is returned, so its data stays
|
|
148
|
+
* visible. The MCP server's own default is `queue.db` with no legacy
|
|
149
|
+
* fallback; it creates that file at start, so the two agree from then on.
|
|
150
|
+
*/
|
|
151
|
+
export declare function defaultDbPath(): string;
|
|
152
|
+
/**
|
|
153
|
+
* The `wake:` line of a task's work shape, or undefined when it does not
|
|
154
|
+
* wake: a one-off wake task wakes when it finishes; a run of a bound job
|
|
155
|
+
* says the job's rule, since most of its runs do not wake.
|
|
156
|
+
*/
|
|
157
|
+
export declare function wakeShapeText(shape: Pick<TaskWorkShape, "wake" | "wakeRule">): string | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* True when `dbPath` is the default ledger. The session notice and wake
|
|
160
|
+
* markers under `~/.tidegap/sessions` belong to it: the plugin's hooks
|
|
161
|
+
* read that ledger only, so a pass over another ledger must neither
|
|
162
|
+
* create nor remove them, and a wake for a task in another ledger could
|
|
163
|
+
* never fire. Compares real paths; a missing file compares by
|
|
164
|
+
* its folder's real path and its name.
|
|
165
|
+
*/
|
|
166
|
+
export declare function isDefaultLedger(dbPath: string): boolean;
|
|
139
167
|
/** `~/.tidegap/sessions/wake`: one marker per session with a task to wake it for. */
|
|
140
168
|
export declare function wakeMarkersDir(home?: string): string;
|
|
141
169
|
/** The wake marker of one session, or undefined for an id that fails the id rule. */
|
|
142
170
|
export declare function wakeMarkerPath(sessionId: string, dir?: string): string | undefined;
|
|
143
171
|
/**
|
|
144
172
|
* Create or refresh a session's wake marker (file `0600`, folder `0700`),
|
|
145
|
-
* so the plugin's Stop hook starts its waiter
|
|
146
|
-
* or undefined. Something other than a regular file at
|
|
147
|
-
* alone and reported.
|
|
173
|
+
* so the plugin's Stop hook starts its waiter; its time is `now`. Returns
|
|
174
|
+
* the error message, or undefined. Something other than a regular file at
|
|
175
|
+
* the path is left alone and reported. A waiter or the sweep may remove
|
|
176
|
+
* or write the marker at the same moment: a refresh that finds it gone
|
|
177
|
+
* creates it, and a create that finds one there refreshes it.
|
|
148
178
|
*/
|
|
149
179
|
export declare function writeWakeMarker(sessionId: string, dir?: string, now?: Date): string | undefined;
|
|
150
180
|
/** Remove a session's wake marker; a missing one is fine. */
|
|
151
181
|
export declare function removeWakeMarker(sessionId: string, dir?: string): void;
|
|
182
|
+
/** True for a task queued with wake, and for a run of a job bound to a session. */
|
|
183
|
+
export declare function isWakeTask(record: Pick<TaskRecord<unknown>, "bodyJson">): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* True when a session notice wakes its session: a run of a bound job when
|
|
186
|
+
* the job sweep's decision says so, any other completed or failed wake
|
|
187
|
+
* task. A cancel is someone's own act: it never spends a turn.
|
|
188
|
+
*/
|
|
189
|
+
export declare function noticeWakes(n: SessionNotice): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* The wake tasks still to come of one session, or of every session when
|
|
192
|
+
* `sessionId` is undefined: not finished yet, or completed and waiting for
|
|
193
|
+
* its result file (its notice comes once the file is). A row that completed
|
|
194
|
+
* more than {@link SESSION_NOTICE_MAX_AGE_MS} ago no longer counts: it can
|
|
195
|
+
* never be a notice.
|
|
196
|
+
*/
|
|
197
|
+
export declare function wakeTasksToCome(store: TaskStore, sessionId: string | undefined, now: Date): TaskRecord<unknown>[];
|
|
198
|
+
/**
|
|
199
|
+
* True when a session has something left to wait for (KTD11): an open wake
|
|
200
|
+
* task, a wake task waiting for its result file, an unclaimed notice that
|
|
201
|
+
* wakes, or an active job bound to it. The bound job counts so a waiter
|
|
202
|
+
* does not stop between a run's finish and the sweep's decision. With
|
|
203
|
+
* `since`, only a task queued after it and a job bound after it count (a
|
|
204
|
+
* second look after a removal); a run of a bound job counts through its
|
|
205
|
+
* job's bind time only, since every run is a fresh row and would keep the
|
|
206
|
+
* 7-day rule from ever ending the marker. An unclaimed wake notice counts
|
|
207
|
+
* whatever its time. The reads go against the job sweep's write order
|
|
208
|
+
* (run, then notice, then job): the job first, so a run that finishes
|
|
209
|
+
* between two reads is seen by one of them. `notices` is the session's
|
|
210
|
+
* notice list when the caller has just read it. Throws when the ledger
|
|
211
|
+
* cannot be read.
|
|
212
|
+
*/
|
|
213
|
+
export declare function sessionHasWaitWork(store: TaskStore, sessionId: string, now?: Date, opts?: {
|
|
214
|
+
since?: number;
|
|
215
|
+
notices?: readonly SessionNotice[];
|
|
216
|
+
}): boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Remove a session's wake marker, then look once more
|
|
219
|
+
* ({@link sessionHasWaitWork}, from `since` when given), and write the
|
|
220
|
+
* marker again when the session has something left or the read fails. A
|
|
221
|
+
* writer commits its row (or job) before it writes the marker, so work
|
|
222
|
+
* added while the caller decided is either seen here or writes its marker
|
|
223
|
+
* after the removal. Returns "removed", "kept" or "unread" (the read
|
|
224
|
+
* failed). Never throws.
|
|
225
|
+
*/
|
|
226
|
+
export declare function removeWakeMarkerUnlessPending(store: TaskStore, sessionId: string, dir?: string, now?: Date, since?: number): "removed" | "kept" | "unread";
|
|
227
|
+
/**
|
|
228
|
+
* The agent's own act ended something a session waited for (a cancel, a
|
|
229
|
+
* job removed, paused or unbound): drop the session's marker now unless
|
|
230
|
+
* it has something left (KTD12). Only on the default ledger, whose markers
|
|
231
|
+
* these are; `sessionId` undefined does nothing. Never throws.
|
|
232
|
+
*/
|
|
233
|
+
export declare function releaseWakeMarker(store: TaskStore | undefined, dbPath: string | undefined, sessionId: string | undefined): void;
|
|
152
234
|
//# sourceMappingURL=handoff.d.ts.map
|