@tidegap/core 0.20.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/dist/channels/digest.js +3 -3
- package/dist/channels/format.d.ts +11 -0
- package/dist/channels/format.js +26 -8
- package/dist/energy.d.ts +7 -0
- package/dist/energy.js +7 -0
- package/dist/handoff.d.ts +22 -3
- package/dist/handoff.js +69 -17
- package/dist/history.d.ts +15 -0
- package/dist/history.js +11 -0
- package/dist/index.d.ts +17 -13
- package/dist/index.js +12 -10
- package/dist/jobs.d.ts +25 -15
- package/dist/jobs.js +186 -63
- 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 +40 -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 +23 -0
- package/dist/schedule-job.js +48 -0
- package/dist/scheduler.d.ts +159 -17
- package/dist/scheduler.js +482 -128
- package/dist/storage/sqlite.d.ts +28 -2
- package/dist/storage/sqlite.js +65 -5
- package/dist/task-events.d.ts +19 -4
- package/dist/task-events.js +42 -5
- package/dist/tool-surface.js +38 -7
- package/dist/types.d.ts +31 -10
- package/dist/types.js +1 -3
- package/package.json +5 -2
package/dist/storage/sqlite.d.ts
CHANGED
|
@@ -147,8 +147,27 @@ export declare class TaskStore {
|
|
|
147
147
|
* transaction, and only when the update hit.
|
|
148
148
|
*/
|
|
149
149
|
transitionIf(record: TaskRecord<unknown>, expectedStatuses: readonly TaskStatus[], unchangedSince?: TaskRecord<unknown>, event?: TaskEventInput): boolean;
|
|
150
|
-
/**
|
|
151
|
-
|
|
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;
|
|
152
171
|
/**
|
|
153
172
|
* A task's events, oldest first. `limit` keeps the newest `limit` rows.
|
|
154
173
|
* Rows with an unknown kind (a newer writer) are skipped.
|
|
@@ -255,6 +274,13 @@ export declare class TaskStore {
|
|
|
255
274
|
setMeta(key: string, value: string): void;
|
|
256
275
|
/** Remove one meta value; a missing key is a no-op. */
|
|
257
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;
|
|
258
284
|
/** Every channel row, oldest first; a row with an unknown kind or bad JSON is skipped. */
|
|
259
285
|
listChannels(): Channel[];
|
|
260
286
|
/** Insert or replace a channel row (pairing the same chat again replaces it). */
|
package/dist/storage/sqlite.js
CHANGED
|
@@ -591,9 +591,47 @@ export class TaskStore {
|
|
|
591
591
|
return hit;
|
|
592
592
|
});
|
|
593
593
|
}
|
|
594
|
-
/**
|
|
595
|
-
|
|
596
|
-
|
|
594
|
+
/**
|
|
595
|
+
* Append one event to a task's log in its own transaction. `busyMs` bounds
|
|
596
|
+
* the wait for another writer's lock for this write only (a progress line
|
|
597
|
+
* of a running command must not hold the tick for seconds): past it the
|
|
598
|
+
* write throws SQLITE_BUSY. The connection's own busy timeout is restored
|
|
599
|
+
* in `finally`, so no other write gets the short wait. It only shortens
|
|
600
|
+
* the wait: a connection whose own timeout is already shorter (or cannot
|
|
601
|
+
* be read) keeps it.
|
|
602
|
+
*/
|
|
603
|
+
recordEvent(taskId, event, opts = {}) {
|
|
604
|
+
const bound = opts.busyMs === undefined || this.txDepth > 0 ? undefined : Math.max(0, Math.floor(opts.busyMs));
|
|
605
|
+
const own = bound === undefined ? NaN : Number(this.db.prepare("PRAGMA busy_timeout").get()?.["timeout"]);
|
|
606
|
+
if (bound === undefined || !Number.isFinite(own) || own <= bound) {
|
|
607
|
+
this.tx(() => this.insertEvent(taskId, event));
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
this.db.exec(`PRAGMA busy_timeout = ${bound}`);
|
|
611
|
+
try {
|
|
612
|
+
this.tx(() => this.insertEvent(taskId, event));
|
|
613
|
+
}
|
|
614
|
+
finally {
|
|
615
|
+
this.db.exec(`PRAGMA busy_timeout = ${own}`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
/** How many events of `kind` a task has: one `COUNT(*)`, no rows read. */
|
|
619
|
+
countTaskEvents(taskId, kind) {
|
|
620
|
+
const row = this.db.prepare("SELECT COUNT(*) AS n FROM task_events WHERE task_id = ? AND kind = ?").get(taskId, kind);
|
|
621
|
+
return Number(row?.["n"] ?? 0);
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Merge `details` into the newest `kind` event of a task: a fact learned
|
|
625
|
+
* after another writer recorded the event (the tick that stopped a
|
|
626
|
+
* cancelled run adds `stopped_run`). Returns false when the task has no
|
|
627
|
+
* such event.
|
|
628
|
+
*/
|
|
629
|
+
annotateEvent(taskId, kind, details) {
|
|
630
|
+
const res = this.db
|
|
631
|
+
.prepare(`UPDATE task_events SET details = json_patch(details, ?)
|
|
632
|
+
WHERE id = (SELECT id FROM task_events WHERE task_id = ? AND kind = ? ORDER BY id DESC LIMIT 1)`)
|
|
633
|
+
.run(safeStringify(details) ?? "{}", taskId, kind);
|
|
634
|
+
return Number(res.changes) === 1;
|
|
597
635
|
}
|
|
598
636
|
/**
|
|
599
637
|
* A task's events, oldest first. `limit` keeps the newest `limit` rows.
|
|
@@ -930,6 +968,23 @@ export class TaskStore {
|
|
|
930
968
|
deleteMeta(key) {
|
|
931
969
|
this.db.prepare(`DELETE FROM meta WHERE key = ?`).run(key);
|
|
932
970
|
}
|
|
971
|
+
/**
|
|
972
|
+
* Compare-and-set one meta value across processes: write `next` (delete
|
|
973
|
+
* the key when `next` is undefined) only while the stored value is still
|
|
974
|
+
* `expected` (undefined: the key is absent). Returns whether it wrote. Two
|
|
975
|
+
* processes that read the same value cannot both win.
|
|
976
|
+
*/
|
|
977
|
+
setMetaIf(key, expected, next) {
|
|
978
|
+
return this.tx(() => {
|
|
979
|
+
if (this.getMeta(key) !== expected)
|
|
980
|
+
return false;
|
|
981
|
+
if (next === undefined)
|
|
982
|
+
this.deleteMeta(key);
|
|
983
|
+
else
|
|
984
|
+
this.setMeta(key, next);
|
|
985
|
+
return true;
|
|
986
|
+
});
|
|
987
|
+
}
|
|
933
988
|
/** Every channel row, oldest first; a row with an unknown kind or bad JSON is skipped. */
|
|
934
989
|
listChannels() {
|
|
935
990
|
const rows = this.db.prepare(`SELECT * FROM channels ORDER BY created_at, id`).all();
|
|
@@ -1132,7 +1187,7 @@ function jobParams(job) {
|
|
|
1132
1187
|
last_run_started_at: job.lastRunStartedAt ?? null,
|
|
1133
1188
|
last_outcome: job.lastOutcome ?? null,
|
|
1134
1189
|
consecutive_failures: job.consecutiveFailures,
|
|
1135
|
-
retry_used: job.retryUsed
|
|
1190
|
+
retry_used: job.retryUsed,
|
|
1136
1191
|
pause_reason: job.pauseReason ?? null,
|
|
1137
1192
|
paused_at: job.pausedAt ?? null,
|
|
1138
1193
|
pause_notified_at: job.pauseNotifiedAt ?? null,
|
|
@@ -1168,6 +1223,11 @@ function rowToCadence(row) {
|
|
|
1168
1223
|
return undefined;
|
|
1169
1224
|
}
|
|
1170
1225
|
}
|
|
1226
|
+
/** The `retry_used` column as a count: a row from before held 0 or 1 (true), which reads as that many retries. */
|
|
1227
|
+
function retryCount(raw) {
|
|
1228
|
+
const n = Number(raw ?? 0);
|
|
1229
|
+
return Number.isInteger(n) && n > 0 ? n : 0;
|
|
1230
|
+
}
|
|
1171
1231
|
/**
|
|
1172
1232
|
* A job row as a record. A row whose template (or cadence) does not parse
|
|
1173
1233
|
* reads as `paused` with reason `corrupt template` instead of throwing, so
|
|
@@ -1205,7 +1265,7 @@ function rowToJob(row) {
|
|
|
1205
1265
|
lastRunStartedAt: str(row.last_run_started_at),
|
|
1206
1266
|
lastOutcome: JOB_OUTCOMES.has(row.last_outcome) ? row.last_outcome : undefined,
|
|
1207
1267
|
consecutiveFailures: Number(row.consecutive_failures ?? 0),
|
|
1208
|
-
retryUsed:
|
|
1268
|
+
retryUsed: retryCount(row.retry_used),
|
|
1209
1269
|
pauseReason: str(row.pause_reason),
|
|
1210
1270
|
pausedAt: str(row.paused_at),
|
|
1211
1271
|
pauseNotifiedAt: str(row.pause_notified_at),
|
package/dist/task-events.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Task events (audit trail): one row per change of a task, in the ledger's
|
|
3
3
|
* `task_events` table, written in the same transaction as the task write.
|
|
4
4
|
* Shared by both cores; the Python core writes `dispatched`, `completed`,
|
|
5
|
-
* `failed` and `cancelled` rows with the same shape.
|
|
5
|
+
* `failed`, `attempt_failed` and `cancelled` rows with the same shape.
|
|
6
6
|
*/
|
|
7
7
|
import type { TaskRecord } from "./types.js";
|
|
8
|
-
export declare const TASK_EVENT_KINDS: readonly ["created", "rescheduled", "postponed", "expedited", "cancelled", "dispatched", "completed", "failed", "deferred", "replied", "notified", "result_file", "progress"];
|
|
8
|
+
export declare const TASK_EVENT_KINDS: readonly ["created", "rescheduled", "postponed", "expedited", "cancelled", "dispatched", "completed", "failed", "attempt_failed", "deferred", "replied", "notified", "result_file", "progress"];
|
|
9
9
|
export type TaskEventKind = (typeof TASK_EVENT_KINDS)[number];
|
|
10
10
|
/**
|
|
11
11
|
* Who made the change: `agent:<host>`, `page`, `client:<name>`, `cli`,
|
|
@@ -37,14 +37,24 @@ export declare function normalizeActor(actor: unknown): TaskEventActor;
|
|
|
37
37
|
export declare function isTaskEventKind(kind: unknown): kind is TaskEventKind;
|
|
38
38
|
/**
|
|
39
39
|
* The details of one event: `from` / `to` timing for moves and run-now,
|
|
40
|
-
* provider and model for created / dispatched / completed / failed
|
|
41
|
-
* first line of the error for failed, then `extra`.
|
|
40
|
+
* provider and model for created / dispatched / completed / failed /
|
|
41
|
+
* attempt_failed, the first line of the error for failed, then `extra`.
|
|
42
42
|
*/
|
|
43
43
|
export declare function eventDetails(kind: TaskEventKind, prev: TaskRecord<unknown> | undefined, next: TaskRecord<unknown>, extra?: Record<string, unknown>): Record<string, unknown>;
|
|
44
44
|
/** The kind a status change implies when the writer named none (terminal moves only). */
|
|
45
45
|
export declare function impliedEventKind(prevStatus: string, nextStatus: string): TaskEventKind | undefined;
|
|
46
46
|
/** A one-line summary of the details, or "". */
|
|
47
47
|
export declare function eventSummary(e: Pick<TaskEvent, "kind" | "details">): string;
|
|
48
|
+
/**
|
|
49
|
+
* One line per failed attempt the retry policy queued again, since the
|
|
50
|
+
* newest `created` event or manual retry, for the text views: key
|
|
51
|
+
* `attempt_<n>`, text `failed <at> (<class>): <error>; next attempt from
|
|
52
|
+
* <retry_at>`. `events` are oldest first.
|
|
53
|
+
*/
|
|
54
|
+
export declare function attemptLines(events: readonly Pick<TaskEvent, "at" | "kind" | "details">[]): {
|
|
55
|
+
key: string;
|
|
56
|
+
text: string;
|
|
57
|
+
}[];
|
|
48
58
|
/** `<at> <kind> by <actor>[ - <summary>]`, one line. */
|
|
49
59
|
export declare function formatTaskEvent(e: Pick<TaskEvent, "at" | "kind" | "actor" | "details">): string;
|
|
50
60
|
/** The API / JSON shape of one event. */
|
|
@@ -62,6 +72,11 @@ export declare const PROGRESS_GAP_MS = 15000;
|
|
|
62
72
|
export declare const PROGRESS_MAX_EVENTS = 24;
|
|
63
73
|
/** Longest progress line. */
|
|
64
74
|
export declare const PROGRESS_LINE_MAX_CHARS = 200;
|
|
75
|
+
/**
|
|
76
|
+
* Longest wait of one progress write for another writer's lock, in ms. The
|
|
77
|
+
* tick writes progress on its event loop; past this the line is dropped.
|
|
78
|
+
*/
|
|
79
|
+
export declare const PROGRESS_BUSY_MS = 100;
|
|
65
80
|
/**
|
|
66
81
|
* Untrusted output text without terminal escape sequences, control
|
|
67
82
|
* characters (a tab becomes a space), line separators or bidirectional
|
package/dist/task-events.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Task events (audit trail): one row per change of a task, in the ledger's
|
|
3
3
|
* `task_events` table, written in the same transaction as the task write.
|
|
4
4
|
* Shared by both cores; the Python core writes `dispatched`, `completed`,
|
|
5
|
-
* `failed` and `cancelled` rows with the same shape.
|
|
5
|
+
* `failed`, `attempt_failed` and `cancelled` rows with the same shape.
|
|
6
6
|
*/
|
|
7
7
|
import { includesWebTool } from "./claude-tools.js";
|
|
8
8
|
import { stripControlChars } from "./history.js";
|
|
@@ -15,6 +15,11 @@ export const TASK_EVENT_KINDS = [
|
|
|
15
15
|
"dispatched",
|
|
16
16
|
"completed",
|
|
17
17
|
"failed",
|
|
18
|
+
// A run failed and the retry policy queued another attempt: the task is
|
|
19
|
+
// `scheduled` again. Not terminal: no notice, wake, result file or series
|
|
20
|
+
// roll. Details: `attempt`, `failure_class`, `error` (first line),
|
|
21
|
+
// `retry_at`, and the run's own keys (`steps`, `stopped_by`).
|
|
22
|
+
"attempt_failed",
|
|
18
23
|
"deferred",
|
|
19
24
|
"replied",
|
|
20
25
|
// A Claude Code session was told the task finished (its prompt hook, a
|
|
@@ -104,11 +109,11 @@ function providerModel(bodyJson) {
|
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
const MOVE_KINDS = new Set(["rescheduled", "postponed", "expedited"]);
|
|
107
|
-
const SPEC_KINDS = new Set(["created", "dispatched", "completed", "failed"]);
|
|
112
|
+
const SPEC_KINDS = new Set(["created", "dispatched", "completed", "failed", "attempt_failed"]);
|
|
108
113
|
/**
|
|
109
114
|
* The details of one event: `from` / `to` timing for moves and run-now,
|
|
110
|
-
* provider and model for created / dispatched / completed / failed
|
|
111
|
-
* first line of the error for failed, then `extra`.
|
|
115
|
+
* provider and model for created / dispatched / completed / failed /
|
|
116
|
+
* attempt_failed, the first line of the error for failed, then `extra`.
|
|
112
117
|
*/
|
|
113
118
|
export function eventDetails(kind, prev, next, extra = {}) {
|
|
114
119
|
const out = {};
|
|
@@ -164,6 +169,11 @@ export function eventSummary(e) {
|
|
|
164
169
|
case "deferred":
|
|
165
170
|
parts.push(`retry at ${short(d.retry_at)}`);
|
|
166
171
|
break;
|
|
172
|
+
case "attempt_failed":
|
|
173
|
+
parts.push(`attempt ${typeof d.attempt === "number" ? d.attempt : "?"} (${short(d.failure_class)})`, `retry at ${short(d.retry_at)}`);
|
|
174
|
+
if (typeof d.error === "string")
|
|
175
|
+
parts.push(d.error);
|
|
176
|
+
break;
|
|
167
177
|
case "replied":
|
|
168
178
|
parts.push(`reply ${short(d.child_task_id)}`);
|
|
169
179
|
break;
|
|
@@ -189,6 +199,28 @@ export function eventSummary(e) {
|
|
|
189
199
|
parts.push(d.reason);
|
|
190
200
|
return parts.join("; ");
|
|
191
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* One line per failed attempt the retry policy queued again, since the
|
|
204
|
+
* newest `created` event or manual retry, for the text views: key
|
|
205
|
+
* `attempt_<n>`, text `failed <at> (<class>): <error>; next attempt from
|
|
206
|
+
* <retry_at>`. `events` are oldest first.
|
|
207
|
+
*/
|
|
208
|
+
export function attemptLines(events) {
|
|
209
|
+
const out = [];
|
|
210
|
+
for (const e of events) {
|
|
211
|
+
if (e.kind === "created" || (e.kind === "rescheduled" && e.details?.reason === "retry"))
|
|
212
|
+
out.length = 0;
|
|
213
|
+
if (e.kind !== "attempt_failed")
|
|
214
|
+
continue;
|
|
215
|
+
const d = e.details ?? {};
|
|
216
|
+
const n = typeof d.attempt === "number" ? d.attempt : out.length + 1;
|
|
217
|
+
const cls = typeof d.failure_class === "string" ? ` (${d.failure_class})` : "";
|
|
218
|
+
const error = typeof d.error === "string" ? `: ${d.error}` : "";
|
|
219
|
+
const next = typeof d.retry_at === "string" ? `; next attempt from ${d.retry_at}` : "";
|
|
220
|
+
out.push({ key: `attempt_${n}`, text: `failed ${e.at}${cls}${error}${next}` });
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
192
224
|
/** `<at> <kind> by <actor>[ - <summary>]`, one line. */
|
|
193
225
|
export function formatTaskEvent(e) {
|
|
194
226
|
const summary = eventSummary(e);
|
|
@@ -206,6 +238,11 @@ export const PROGRESS_GAP_MS = 15_000;
|
|
|
206
238
|
export const PROGRESS_MAX_EVENTS = 24;
|
|
207
239
|
/** Longest progress line. */
|
|
208
240
|
export const PROGRESS_LINE_MAX_CHARS = 200;
|
|
241
|
+
/**
|
|
242
|
+
* Longest wait of one progress write for another writer's lock, in ms. The
|
|
243
|
+
* tick writes progress on its event loop; past this the line is dropped.
|
|
244
|
+
*/
|
|
245
|
+
export const PROGRESS_BUSY_MS = 100;
|
|
209
246
|
/** Terminal escape sequences (CSI, OSC and two-character escapes): removed whole, not only their ESC. */
|
|
210
247
|
const TERMINAL_ESCAPES = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?|\u001b[@-Z\\-_]/g;
|
|
211
248
|
/** Line and paragraph separators (become a space) and bidirectional controls (removed). */
|
|
@@ -276,7 +313,7 @@ export function createProgressRecorder(write, opts = {}) {
|
|
|
276
313
|
write({ line, seq });
|
|
277
314
|
}
|
|
278
315
|
catch {
|
|
279
|
-
// A busy ledger costs this line, not the run.
|
|
316
|
+
// A busy ledger costs this line (at most PROGRESS_BUSY_MS of waiting), not the run.
|
|
280
317
|
}
|
|
281
318
|
};
|
|
282
319
|
return {
|
package/dist/tool-surface.js
CHANGED
|
@@ -37,8 +37,14 @@
|
|
|
37
37
|
* modelled with `optionalPerHost` rather than dropped.
|
|
38
38
|
*/
|
|
39
39
|
import { DEFAULT_MODEL_BY_PROVIDER } from "./providers/defaults.js";
|
|
40
|
+
import { formatDuration, RUN_LIMITS } from "./run-limits.js";
|
|
40
41
|
/** Every host, in a stable order (used by the divergence-canary snapshot). */
|
|
41
42
|
export const ALL_TOOL_HOSTS = ["mcp", "openclaw"];
|
|
43
|
+
/** The built-in LLM time limits per runner, as the tool text prints them (`30m`). */
|
|
44
|
+
const LLM_DEFAULTS = Object.fromEntries(Object.entries(RUN_LIMITS.find((d) => d.name === "llm_timeout").defaults).map(([runner, ms]) => [runner, formatDuration(ms)]));
|
|
45
|
+
/** The built-in retries and retry delay, the same for every runner, as the tool text prints them. */
|
|
46
|
+
const RETRIES_DEFAULT = String(RUN_LIMITS.find((d) => d.name === "retries").defaults.command);
|
|
47
|
+
const RETRY_DELAY_DEFAULT = formatDuration(RUN_LIMITS.find((d) => d.name === "retry_delay").defaults.command);
|
|
42
48
|
// ── Reusable parameter descriptors ──────────────────────────────────────────
|
|
43
49
|
// Defined once so a description or shape can never drift between the two
|
|
44
50
|
// tools/hosts that share it.
|
|
@@ -317,7 +323,7 @@ export const TOOL_SURFACE = [
|
|
|
317
323
|
kind: "boolean",
|
|
318
324
|
optional: true,
|
|
319
325
|
hosts: ["mcp"],
|
|
320
|
-
description: "true wakes this Claude Code session when the task finishes, if it sits idle, within 12 hours after its last turn ended: the session starts a turn by itself with the notice. A wake spends a model turn while nobody may be watching, so set it only when the user wants the result acted on at once. Rejected outside a Claude Code session. Omit (default false) to get the notice with the next prompt.",
|
|
326
|
+
description: "true wakes this Claude Code session when the task finishes, if it sits idle, within 12 hours after its last turn ended: the session starts a turn by itself with the notice. A wake spends a model turn while nobody may be watching, so set it only when the user wants the result acted on at once. Rejected outside a Claude Code session, and when this server's ledger is not the default ~/.tidegap/queue.db (TIDEGAP_DB_PATH set elsewhere): the plugin's hooks read only that one. Omit (default false) to get the notice with the next prompt.",
|
|
321
327
|
},
|
|
322
328
|
{
|
|
323
329
|
name: "dry_run",
|
|
@@ -415,6 +421,31 @@ export const TOOL_SURFACE = [
|
|
|
415
421
|
optional: true,
|
|
416
422
|
description: "IANA zone that window and days are read in, e.g. 'Europe/Berlin'; take it from the user's location. Defaults to the host's system zone. Only with a job repeat.",
|
|
417
423
|
},
|
|
424
|
+
{
|
|
425
|
+
name: "llm_timeout",
|
|
426
|
+
kind: "string",
|
|
427
|
+
optional: true,
|
|
428
|
+
description: "Time limit of the run, or of each job run: a duration from 1s to 7d, e.g. '45m' or '2h', or 'none' for no limit; '0' is rejected. A run stopped at the limit fails. " +
|
|
429
|
+
`Omit to use the user's setting (\`tidegap limits\`), else ${LLM_DEFAULTS["claude-code"]} for claude-code and ${LLM_DEFAULTS.anthropic} for an API provider. ` +
|
|
430
|
+
"Raise it for a long task; 'none' holds other due tasks while it runs.",
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
name: "retries",
|
|
434
|
+
kind: "number",
|
|
435
|
+
integer: true,
|
|
436
|
+
min: 0,
|
|
437
|
+
max: 10,
|
|
438
|
+
optional: true,
|
|
439
|
+
description: "Automatic retries of a failed run, or of each job run: 0 to 10; 0 runs it once, e.g. for a task that must not run twice. " +
|
|
440
|
+
`Omit to use the user's setting (\`tidegap limits\`), else ${RETRIES_DEFAULT}. ` +
|
|
441
|
+
"A retry starts no later than the deadline; a permanent error (a rejected request, missing setup) never retries, and only the final outcome sends a notice.",
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
name: "retry_delay",
|
|
445
|
+
kind: "string",
|
|
446
|
+
optional: true,
|
|
447
|
+
description: `Wait before the first retry: a duration from 1s to 7d, e.g. '10m'; each later retry waits twice as long. '0' and 'none' are rejected. Omit to use the user's setting, else ${RETRY_DELAY_DEFAULT}.`,
|
|
448
|
+
},
|
|
418
449
|
{
|
|
419
450
|
name: "origin_session_id",
|
|
420
451
|
kind: "string",
|
|
@@ -447,9 +478,9 @@ export const TOOL_SURFACE = [
|
|
|
447
478
|
{
|
|
448
479
|
name: "check_queue_status",
|
|
449
480
|
hosts: ["mcp", "openclaw"],
|
|
450
|
-
description: "Show the local
|
|
481
|
+
description: "Show the local queue and jobs: every task in brief or one in full. Use when: the user asks what is queued or repeats, whether a task finished, or its result. Do not use to change a task (use cancel_task, postpone_task, update_deadline or retry_task) or for usage limits (tidegap_usage). Behavior: no network or login; marks a shown completed or failed task read; changes no status. Returns: without task_id, status counts, last_tick_at, a line per task and job (guarantee, next run and id, last result); with task_id, its prompt, time limits, result, receipt and events. Rejects an unknown task_id.",
|
|
451
482
|
descriptionPerHost: {
|
|
452
|
-
openclaw: "Show the local task queue and jobs: every task in brief
|
|
483
|
+
openclaw: "Show the local task queue and jobs: every task in brief or one in full. Use when: the user asks what is queued or repeats, whether a task finished, or its result. Do not use to change a task (use cancel_task, update_deadline or retry_task) or to set delivery (use set_delivery). Behavior: no network or login; marks a shown completed or failed task read; never changes a status. Returns: without task_id, total, last_tick_at, tasks (task_id, title, status, scheduled_for, job_id) and jobs (guarantee, next_run, last_outcome); with task_id, its record and time limits. Throws on an unknown task_id.",
|
|
453
484
|
},
|
|
454
485
|
annotations: {
|
|
455
486
|
title: "Show task queue",
|
|
@@ -490,9 +521,9 @@ export const TOOL_SURFACE = [
|
|
|
490
521
|
{
|
|
491
522
|
name: "cancel_task",
|
|
492
523
|
hosts: ["mcp", "openclaw"],
|
|
493
|
-
description: "Cancel one
|
|
524
|
+
description: "Cancel one task by task_id; for all pending, use cancel_all. Use when: the user drops one task. Do not use to delay it (use postpone_task) or rerun a failed one (use retry_task). Behavior: marks it cancelled (no network) and redacts its prompt; a running command, Claude Code run or API call then stops, and a submitted Batch call may still bill. A job or series skips this run; series=true ends it, even from a finished run. A finished task or repeat call is unchanged. Returns: \"Task <id> status: <status>\", terminated_at, and a job or series line when ended. Rejects an unknown task_id.",
|
|
494
525
|
descriptionPerHost: {
|
|
495
|
-
openclaw: "Cancel one
|
|
526
|
+
openclaw: "Cancel one task by task_id; for all pending, use cancel_all. Use when: the user drops a task. Do not use to delay it (use update_deadline) or rerun a failed one (use retry_task). Behavior: marks it cancelled (no network) and redacts its prompt; a running command, Claude Code run or API call then stops, and a submitted Batch call may still bill. A job or series skips this run; series=true ends it, even from a finished run. A finished task or repeat call is unchanged. Returns: task_id, status, completed_at, job_id and job_ended or series_id and series_ended. Throws on an unknown task_id.",
|
|
496
527
|
},
|
|
497
528
|
annotations: {
|
|
498
529
|
title: "Cancel one task",
|
|
@@ -620,9 +651,9 @@ export const TOOL_SURFACE = [
|
|
|
620
651
|
{
|
|
621
652
|
name: "retry_task",
|
|
622
653
|
hosts: ["mcp", "openclaw"],
|
|
623
|
-
description: "Run a failed task again
|
|
654
|
+
description: "Run a failed task again, a command or claude-code task included, as attempt 1 of a new count. Use when: a task failed and should run again. Do not use for a task that did not fail (use expedite_task or update_deadline). Behavior: with the provider's key in the server env, one call now; its result and signed receipt replace the old ones. A command or claude-code task, or one with no key here, is due now and the next tidegap tick runs it. The deadline does not block it. Returns: status (completed, failed, retrying or scheduled), error on failure. Rejects non-failed, unknown and job-run tasks.",
|
|
624
655
|
descriptionPerHost: {
|
|
625
|
-
openclaw: "Run a failed task again
|
|
656
|
+
openclaw: "Run a failed task again, as attempt 1 of a new count. Use when: a task failed and the user wants it redone. Do not use for a task that did not fail (use expedite_task to run it now, update_deadline to move it). Behavior: one provider call now, through the OpenClaw runtime or a provider key in the plugin config; the new result and signed receipt replace the old ones, then the result is delivered. A command or claude-code task is due now and the next tidegap tick runs it. Returns: status, error on failure, result, receipt and delivery. Throws on tasks that are not failed and unknown task_ids.",
|
|
626
657
|
},
|
|
627
658
|
annotations: {
|
|
628
659
|
title: "Retry a failed task",
|
package/dist/types.d.ts
CHANGED
|
@@ -469,8 +469,11 @@ export interface ProviderCallSpec {
|
|
|
469
469
|
provider: ProviderName;
|
|
470
470
|
model?: string;
|
|
471
471
|
};
|
|
472
|
-
/**
|
|
473
|
-
|
|
472
|
+
/**
|
|
473
|
+
* Per-run caps: a job occurrence's, or the time limits a one-off task
|
|
474
|
+
* was queued with (only the keys the caller set, with `capsVersion`).
|
|
475
|
+
*/
|
|
476
|
+
caps?: Partial<JobCaps>;
|
|
474
477
|
}
|
|
475
478
|
/** {@link ProviderCallSpec.origin}. */
|
|
476
479
|
export interface ProviderCallOrigin {
|
|
@@ -493,10 +496,12 @@ export interface TickResultEntry {
|
|
|
493
496
|
* "completed" or "failed". "completed"/"failed" are terminal.
|
|
494
497
|
* "deferred": the provider asked to wait (a usage limit); the task is
|
|
495
498
|
* `scheduled` again with `notBefore = retryAt`.
|
|
499
|
+
* "retrying": the run failed and the retry policy queued another attempt;
|
|
500
|
+
* the task is `scheduled` again with `notBefore = retryAt`. Not terminal.
|
|
496
501
|
*/
|
|
497
|
-
status: "completed" | "failed" | "submitted" | "deferred";
|
|
502
|
+
status: "completed" | "failed" | "submitted" | "deferred" | "retrying";
|
|
498
503
|
error?: string;
|
|
499
|
-
/** ISO-8601 earliest
|
|
504
|
+
/** ISO-8601 earliest start of the next attempt of a `deferred` or `retrying` entry. */
|
|
500
505
|
retryAt?: string;
|
|
501
506
|
}
|
|
502
507
|
/** Aggregate result of one call to `Scheduler.tick`. */
|
|
@@ -516,6 +521,8 @@ export interface TickResult {
|
|
|
516
521
|
batchPolled: number;
|
|
517
522
|
/** Tasks a provider deferred this tick (back to `scheduled` with a `notBefore`). */
|
|
518
523
|
deferred: number;
|
|
524
|
+
/** Tasks whose run failed and that the retry policy queued again this tick (back to `scheduled` with a `notBefore`). */
|
|
525
|
+
retrying: number;
|
|
519
526
|
}
|
|
520
527
|
/** Function the user hands to `defer`. */
|
|
521
528
|
export type DeferrableTask<T> = () => Promise<T> | T;
|
|
@@ -670,15 +677,29 @@ export type JobTemplate = {
|
|
|
670
677
|
model?: string;
|
|
671
678
|
};
|
|
672
679
|
};
|
|
673
|
-
/**
|
|
680
|
+
/**
|
|
681
|
+
* Per-run caps of a job. The two time limits, retries and the retry delay
|
|
682
|
+
* are stored only when the caller set them (ms, or `"none"` for no time
|
|
683
|
+
* limit; retries 0 to 10); unset, the run gets the setting or the built-in
|
|
684
|
+
* default when it starts (`run-limits.ts`).
|
|
685
|
+
*/
|
|
674
686
|
export interface JobCaps {
|
|
675
|
-
commandTimeoutMs
|
|
676
|
-
llmTimeoutMs
|
|
687
|
+
commandTimeoutMs?: number | "none";
|
|
688
|
+
llmTimeoutMs?: number | "none";
|
|
689
|
+
/** Automatic retries of a failed run, 0 to 10. */
|
|
690
|
+
retries?: number;
|
|
691
|
+
/** The wait before the first retry, in ms; each later retry waits twice the one before. */
|
|
692
|
+
retryDelayMs?: number;
|
|
677
693
|
maxBudgetUsd: number;
|
|
678
694
|
outputCapBytes: number;
|
|
679
695
|
summarizeInputCapBytes: number;
|
|
696
|
+
/**
|
|
697
|
+
* `2` on caps that hold only the time limits a caller set. On caps without
|
|
698
|
+
* it, a stored time limit equal to the old default counts as unset.
|
|
699
|
+
*/
|
|
700
|
+
capsVersion?: number;
|
|
680
701
|
}
|
|
681
|
-
/** The caps a job gets when it names none. */
|
|
702
|
+
/** The budget and output caps a job gets when it names none; the time limits come from the run-limits registry. */
|
|
682
703
|
export declare const DEFAULT_JOB_CAPS: Readonly<JobCaps>;
|
|
683
704
|
/** Which runs of a job notify: every run, failures only, or the digest only. */
|
|
684
705
|
export type JobNotify = "every_run" | "failures" | "summary";
|
|
@@ -714,8 +735,8 @@ export interface JobRecord {
|
|
|
714
735
|
lastRunStartedAt?: string;
|
|
715
736
|
lastOutcome?: JobOutcome;
|
|
716
737
|
consecutiveFailures: number;
|
|
717
|
-
/**
|
|
718
|
-
retryUsed:
|
|
738
|
+
/** The retries the current slot used, 0 to the job's retries (`retry_used`; a row from before held 0 or 1). */
|
|
739
|
+
retryUsed: number;
|
|
719
740
|
/** `manual`, `auto: <first error line>` or `corrupt template`. */
|
|
720
741
|
pauseReason?: string;
|
|
721
742
|
pausedAt?: string;
|
package/dist/types.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public + internal types for @tidegap/core.
|
|
3
3
|
*/
|
|
4
|
-
/** The caps a job gets when it names none. */
|
|
4
|
+
/** The budget and output caps a job gets when it names none; the time limits come from the run-limits registry. */
|
|
5
5
|
export const DEFAULT_JOB_CAPS = Object.freeze({
|
|
6
|
-
commandTimeoutMs: 300_000,
|
|
7
|
-
llmTimeoutMs: 600_000,
|
|
8
6
|
maxBudgetUsd: 1,
|
|
9
7
|
outputCapBytes: 10 * 1024 * 1024,
|
|
10
8
|
summarizeInputCapBytes: 200 * 1024,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidegap/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Carbon-aware scheduling for agentic AI workflows — core TypeScript library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Vitalii Borovyk",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@anthropic-ai/sdk": "^0.137.0",
|
|
56
56
|
"@types/better-sqlite3": "^7.6.13",
|
|
57
57
|
"@types/node": "^22.20.5",
|
|
58
|
-
"openai": "^7.
|
|
58
|
+
"openai": "^7.51.0",
|
|
59
59
|
"typescript": "^5.6.3",
|
|
60
60
|
"vitest": "^4.1.12"
|
|
61
61
|
},
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"undici": "7.30.2"
|
|
72
|
+
},
|
|
70
73
|
"scripts": {
|
|
71
74
|
"build": "tsc -p tsconfig.json",
|
|
72
75
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json",
|