@tidegap/core 0.21.0 → 0.23.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.d.ts +4 -1
- package/dist/channels/digest.js +7 -3
- package/dist/channels/format.d.ts +61 -19
- package/dist/channels/format.js +181 -51
- package/dist/channels/index.d.ts +1 -0
- package/dist/channels/index.js +1 -0
- package/dist/channels/kinds/discord.js +2 -2
- package/dist/channels/kinds/email.js +2 -1
- package/dist/channels/kinds/ntfy.js +9 -1
- package/dist/channels/kinds/pushover.js +4 -3
- package/dist/channels/kinds/shared.d.ts +4 -1
- package/dist/channels/kinds/shared.js +6 -1
- package/dist/channels/kinds/slack.js +2 -2
- package/dist/channels/notice.d.ts +42 -0
- package/dist/channels/notice.js +142 -0
- package/dist/channels/payload.d.ts +3 -0
- package/dist/channels/payload.js +19 -6
- package/dist/channels/plan.js +3 -2
- package/dist/channels/telegram.d.ts +18 -0
- package/dist/channels/telegram.js +23 -9
- package/dist/channels/types.d.ts +17 -1
- package/dist/grid.d.ts +10 -2
- package/dist/grid.js +14 -5
- package/dist/handoff.d.ts +66 -3
- package/dist/handoff.js +108 -3
- package/dist/history.d.ts +105 -0
- package/dist/history.js +108 -1
- package/dist/index.d.ts +15 -11
- package/dist/index.js +10 -6
- 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 +54 -2
- package/dist/jobs.js +258 -14
- package/dist/notice-language.d.ts +37 -0
- package/dist/notice-language.js +67 -0
- package/dist/providers/base.d.ts +14 -0
- package/dist/schedule-job.d.ts +18 -2
- package/dist/schedule-job.js +22 -2
- package/dist/scheduler.d.ts +2 -0
- package/dist/scheduler.js +5 -1
- package/dist/storage/sqlite.d.ts +24 -3
- package/dist/storage/sqlite.js +135 -28
- package/dist/task-events.d.ts +1 -1
- package/dist/task-events.js +9 -0
- package/dist/tool-surface.js +25 -1
- package/dist/types.d.ts +41 -1
- package/package.json +2 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wake rules of a job bound to a Claude Code session (KTD7, KTD9): the rule
|
|
3
|
+
* text the hosts take, the pattern checks on add and edit, and the bounded
|
|
4
|
+
* match the job sweep runs on a completed run's result text.
|
|
5
|
+
*
|
|
6
|
+
* The pattern is a JavaScript regular expression with the `m` flag (`^`
|
|
7
|
+
* and `$` match at each line). The match reads at most
|
|
8
|
+
* {@link JOB_WAKE_TEXT_MAX_CHARS} of the text and runs inside `vm` with a
|
|
9
|
+
* {@link JOB_WAKE_MATCH_TIMEOUT_MS} limit, so a pattern that backtracks
|
|
10
|
+
* without end cannot hold the tick. A match that times out counts as
|
|
11
|
+
* matched: a broken pattern wakes once rather than missing an alert.
|
|
12
|
+
*/
|
|
13
|
+
/** The longest wake pattern. */
|
|
14
|
+
export declare const JOB_WAKE_PATTERN_MAX_CHARS = 200;
|
|
15
|
+
/** How much of a run's result text the pattern reads (64 KiB of characters). */
|
|
16
|
+
export declare const JOB_WAKE_TEXT_MAX_CHARS: number;
|
|
17
|
+
/** How long one match may run. */
|
|
18
|
+
export declare const JOB_WAKE_MATCH_TIMEOUT_MS = 50;
|
|
19
|
+
/** A wake rule as a host gives it: `never` unbinds the job. */
|
|
20
|
+
export type JobWakeRule = {
|
|
21
|
+
on: "never";
|
|
22
|
+
} | {
|
|
23
|
+
on: "failures";
|
|
24
|
+
} | {
|
|
25
|
+
on: "match";
|
|
26
|
+
pattern: string;
|
|
27
|
+
};
|
|
28
|
+
/** Why a wake rule or pattern was refused. */
|
|
29
|
+
export declare class JobWakeError extends Error {
|
|
30
|
+
constructor(message: string);
|
|
31
|
+
}
|
|
32
|
+
/** What `--wake` takes. */
|
|
33
|
+
export declare const JOB_WAKE_FORMS = "never, failures or match=<pattern>";
|
|
34
|
+
/**
|
|
35
|
+
* Why a wake pattern is refused, or undefined when it is fine: it must be
|
|
36
|
+
* a string of 1 to {@link JOB_WAKE_PATTERN_MAX_CHARS} characters that
|
|
37
|
+
* compiles with the `m` flag and does not match the empty string (it would
|
|
38
|
+
* wake on every run).
|
|
39
|
+
*/
|
|
40
|
+
export declare function wakePatternError(pattern: unknown): string | undefined;
|
|
41
|
+
/** The rule `--wake never|failures|match=<pattern>` names. Throws {@link JobWakeError}. */
|
|
42
|
+
export declare function parseWakeRule(text: string): JobWakeRule;
|
|
43
|
+
/** What one bounded match found: `timedOut` (or `broken`, a stored pattern that no longer compiles) counts as matched. */
|
|
44
|
+
export interface WakeMatch {
|
|
45
|
+
matched: boolean;
|
|
46
|
+
timedOut?: boolean;
|
|
47
|
+
broken?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Test `pattern` (flag `m`) against the first {@link JOB_WAKE_TEXT_MAX_CHARS}
|
|
51
|
+
* of `text`, in a fresh `vm` context with a {@link JOB_WAKE_MATCH_TIMEOUT_MS}
|
|
52
|
+
* limit. Never throws.
|
|
53
|
+
*/
|
|
54
|
+
export declare function matchWake(pattern: string, text: string, timeoutMs?: number): WakeMatch;
|
|
55
|
+
//# sourceMappingURL=job-wake.d.ts.map
|
package/dist/job-wake.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wake rules of a job bound to a Claude Code session (KTD7, KTD9): the rule
|
|
3
|
+
* text the hosts take, the pattern checks on add and edit, and the bounded
|
|
4
|
+
* match the job sweep runs on a completed run's result text.
|
|
5
|
+
*
|
|
6
|
+
* The pattern is a JavaScript regular expression with the `m` flag (`^`
|
|
7
|
+
* and `$` match at each line). The match reads at most
|
|
8
|
+
* {@link JOB_WAKE_TEXT_MAX_CHARS} of the text and runs inside `vm` with a
|
|
9
|
+
* {@link JOB_WAKE_MATCH_TIMEOUT_MS} limit, so a pattern that backtracks
|
|
10
|
+
* without end cannot hold the tick. A match that times out counts as
|
|
11
|
+
* matched: a broken pattern wakes once rather than missing an alert.
|
|
12
|
+
*/
|
|
13
|
+
import { createContext, runInContext } from "node:vm";
|
|
14
|
+
/** The longest wake pattern. */
|
|
15
|
+
export const JOB_WAKE_PATTERN_MAX_CHARS = 200;
|
|
16
|
+
/** How much of a run's result text the pattern reads (64 KiB of characters). */
|
|
17
|
+
export const JOB_WAKE_TEXT_MAX_CHARS = 64 * 1024;
|
|
18
|
+
/** How long one match may run. */
|
|
19
|
+
export const JOB_WAKE_MATCH_TIMEOUT_MS = 50;
|
|
20
|
+
/** Why a wake rule or pattern was refused. */
|
|
21
|
+
export class JobWakeError extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "JobWakeError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** What `--wake` takes. */
|
|
28
|
+
export const JOB_WAKE_FORMS = "never, failures or match=<pattern>";
|
|
29
|
+
/**
|
|
30
|
+
* Why a wake pattern is refused, or undefined when it is fine: it must be
|
|
31
|
+
* a string of 1 to {@link JOB_WAKE_PATTERN_MAX_CHARS} characters that
|
|
32
|
+
* compiles with the `m` flag and does not match the empty string (it would
|
|
33
|
+
* wake on every run).
|
|
34
|
+
*/
|
|
35
|
+
export function wakePatternError(pattern) {
|
|
36
|
+
if (typeof pattern !== "string" || pattern === "")
|
|
37
|
+
return "the wake pattern must be a non-empty string";
|
|
38
|
+
if (pattern.length > JOB_WAKE_PATTERN_MAX_CHARS)
|
|
39
|
+
return `the wake pattern is longer than ${JOB_WAKE_PATTERN_MAX_CHARS} characters`;
|
|
40
|
+
// The pattern is the user's own text: it compiles and runs only inside the bounded vm match.
|
|
41
|
+
const empty = boundedTest(pattern, "", JOB_WAKE_MATCH_TIMEOUT_MS);
|
|
42
|
+
if (empty.error !== undefined)
|
|
43
|
+
return `the wake pattern is not a valid regular expression: ${empty.error}`;
|
|
44
|
+
if (empty.timedOut)
|
|
45
|
+
return `the wake pattern takes longer than ${JOB_WAKE_MATCH_TIMEOUT_MS} ms on an empty output; make it simpler`;
|
|
46
|
+
if (empty.matched)
|
|
47
|
+
return "the wake pattern matches an empty output, so it would wake on every run; make it name what to look for";
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/** Compile `pattern` (flag `m`) and test it on `text` in a fresh `vm` context with a time limit. Never throws. */
|
|
51
|
+
function boundedTest(pattern, text, timeoutMs) {
|
|
52
|
+
const context = createContext({ pattern, text });
|
|
53
|
+
try {
|
|
54
|
+
return { matched: runInContext(`new RegExp(pattern, "m").test(text)`, context, { timeout: timeoutMs }) === true };
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (err?.code === "ERR_SCRIPT_EXECUTION_TIMEOUT")
|
|
58
|
+
return { matched: false, timedOut: true };
|
|
59
|
+
// An error from inside the context is not an instance of this realm's Error.
|
|
60
|
+
const message = err?.message;
|
|
61
|
+
return { matched: false, error: typeof message === "string" ? message : String(err) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The rule `--wake never|failures|match=<pattern>` names. Throws {@link JobWakeError}. */
|
|
65
|
+
export function parseWakeRule(text) {
|
|
66
|
+
const value = text.trim();
|
|
67
|
+
if (value === "never" || value === "failures")
|
|
68
|
+
return { on: value };
|
|
69
|
+
if (value.startsWith("match=")) {
|
|
70
|
+
const pattern = value.slice("match=".length);
|
|
71
|
+
const error = wakePatternError(pattern);
|
|
72
|
+
if (error)
|
|
73
|
+
throw new JobWakeError(error);
|
|
74
|
+
return { on: "match", pattern };
|
|
75
|
+
}
|
|
76
|
+
throw new JobWakeError(`--wake must be ${JOB_WAKE_FORMS}`);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Test `pattern` (flag `m`) against the first {@link JOB_WAKE_TEXT_MAX_CHARS}
|
|
80
|
+
* of `text`, in a fresh `vm` context with a {@link JOB_WAKE_MATCH_TIMEOUT_MS}
|
|
81
|
+
* limit. Never throws.
|
|
82
|
+
*/
|
|
83
|
+
export function matchWake(pattern, text, timeoutMs = JOB_WAKE_MATCH_TIMEOUT_MS) {
|
|
84
|
+
const r = boundedTest(pattern, text.slice(0, JOB_WAKE_TEXT_MAX_CHARS), timeoutMs);
|
|
85
|
+
if (r.timedOut)
|
|
86
|
+
return { matched: true, timedOut: true };
|
|
87
|
+
if (r.error !== undefined)
|
|
88
|
+
return { matched: true, broken: true };
|
|
89
|
+
return { matched: r.matched };
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=job-wake.js.map
|
package/dist/jobs.d.ts
CHANGED
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
* rule). The sweep never throws.
|
|
28
28
|
*/
|
|
29
29
|
import { BATCH_SUBMIT_INTERRUPTED_ERROR } from "./history.js";
|
|
30
|
+
import { type JobWakeRule } from "./job-wake.js";
|
|
30
31
|
import { type SleepReading } from "./readiness.js";
|
|
31
32
|
import type { Scheduler } from "./scheduler.js";
|
|
32
33
|
import { type ResolvedRunLimits } from "./run-limits.js";
|
|
33
|
-
import { type JobCadence, type JobCaps, type JobNotify, type JobRecord, type JobTemplate, type JobWindow, type TaskRecord, type TaskStatus } from "./types.js";
|
|
34
|
+
import { type JobCadence, type JobCaps, type JobEndReason, type JobNotify, type JobRecord, type JobTemplate, type JobWindow, type TaskRecord, type TaskStatus } from "./types.js";
|
|
34
35
|
/** Why a job action was refused; `code` maps to an HTTP status in the hosts. */
|
|
35
36
|
export declare class JobActionError extends Error {
|
|
36
37
|
/** `invalid` = bad input (400), `not_found` (404), `conflict` = the state forbids it (409). */
|
|
@@ -68,7 +69,26 @@ export interface JobInput {
|
|
|
68
69
|
* AS9): it may run from now until then. Later ones follow the cadence.
|
|
69
70
|
*/
|
|
70
71
|
deadline?: string | Date;
|
|
72
|
+
/**
|
|
73
|
+
* The end date: `YYYY-MM-DD` (the last local day a slot may start,
|
|
74
|
+
* inclusive) or an ISO instant (a slot must start before it).
|
|
75
|
+
*/
|
|
76
|
+
until?: string | null;
|
|
77
|
+
/** Runs from now before the job ends, 1 to {@link JOB_MAX_COUNT}. */
|
|
78
|
+
count?: number | null;
|
|
79
|
+
/**
|
|
80
|
+
* Bind the job to the Claude Code session that sets it (KTD8). Never read
|
|
81
|
+
* from the job JSON: only a host that runs in the session sets it.
|
|
82
|
+
*/
|
|
83
|
+
wake?: JobWakeInput;
|
|
71
84
|
}
|
|
85
|
+
/** A wake rule with the session that sets it; `never` unbinds the job and needs no session. */
|
|
86
|
+
export type JobWakeInput = JobWakeRule & {
|
|
87
|
+
/** The session to wake. */
|
|
88
|
+
sessionId?: string;
|
|
89
|
+
/** The origin's agent: a wake needs `claude-code`. */
|
|
90
|
+
agent?: string;
|
|
91
|
+
};
|
|
72
92
|
/** The fields {@link updateJob} can change; `window: null` removes the window. */
|
|
73
93
|
export interface JobPatch {
|
|
74
94
|
title?: string;
|
|
@@ -78,6 +98,12 @@ export interface JobPatch {
|
|
|
78
98
|
template?: JobTemplate;
|
|
79
99
|
caps?: JobCapsPatch;
|
|
80
100
|
notify?: JobNotify;
|
|
101
|
+
/** A new end date; `null` clears it. */
|
|
102
|
+
until?: string | null;
|
|
103
|
+
/** Runs left from now; `null` clears the bound. */
|
|
104
|
+
count?: number | null;
|
|
105
|
+
/** A new wake binding (to the session that sets it), or `never` to unbind. */
|
|
106
|
+
wake?: JobWakeInput;
|
|
81
107
|
}
|
|
82
108
|
/**
|
|
83
109
|
* Caps a caller sets: a value sets the key. `null` removes a time limit, so
|
|
@@ -129,9 +155,26 @@ export interface JobSweepResult {
|
|
|
129
155
|
autoPaused: string[];
|
|
130
156
|
/** Running occurrences failed as interrupted this pass. */
|
|
131
157
|
interrupted: string[];
|
|
158
|
+
/** Jobs that reached their end date or ran their runs this pass. */
|
|
159
|
+
ended: string[];
|
|
160
|
+
/** Runs of bound jobs that became session notices this pass. */
|
|
161
|
+
sessionNotices: string[];
|
|
132
162
|
}
|
|
133
163
|
/** A job secret name: what the command sees as an environment variable. */
|
|
134
164
|
export declare const JOB_SECRET_NAME: RegExp;
|
|
165
|
+
/**
|
|
166
|
+
* The prompt `tidegap jobs add --summarize` stores when the user gives none.
|
|
167
|
+
* It is stored as text on the job; a job whose stored text is this or an
|
|
168
|
+
* earlier default runs with the current one ({@link effectiveSummarizePrompt}),
|
|
169
|
+
* and a job's own prompt is never changed.
|
|
170
|
+
*/
|
|
171
|
+
export declare const DEFAULT_SUMMARIZE_PROMPT: string;
|
|
172
|
+
/** True for the current default summarize prompt and every earlier one, with CRLF line ends or surrounding whitespace too. */
|
|
173
|
+
export declare function isDefaultSummarizePrompt(text: string): boolean;
|
|
174
|
+
/** The prompt a summarize step runs with: the current default for any default text, else the stored prompt. */
|
|
175
|
+
export declare function effectiveSummarizePrompt(stored: string): string;
|
|
176
|
+
/** The most runs a job's `count` may ask for. */
|
|
177
|
+
export declare const JOB_MAX_COUNT = 1000;
|
|
135
178
|
/** Failed slots in a row that pause a job. */
|
|
136
179
|
export declare const JOB_AUTO_PAUSE_FAILURES = 3;
|
|
137
180
|
/** How `pauseReason` starts when the third failed slot paused the job: `auto: <first error line>`. */
|
|
@@ -140,6 +183,15 @@ export declare const JOB_AUTO_PAUSE_PREFIX = "auto: ";
|
|
|
140
183
|
export declare function jobAutoPauseReason(pauseReason: string | undefined): string | undefined;
|
|
141
184
|
export declare const JOB_INTERRUPTED_ERROR = "interrupted: the tick stopped during the run";
|
|
142
185
|
export { BATCH_SUBMIT_INTERRUPTED_ERROR };
|
|
186
|
+
/** What an end reason says: `its end date (<until>) passed` or `its runs are done`. */
|
|
187
|
+
export declare function jobEndText(reason: JobEndReason | undefined, until?: string): string;
|
|
188
|
+
/**
|
|
189
|
+
* A job's end condition in words, or undefined for a job with none:
|
|
190
|
+
* `ends after 2026-11-17 (Europe/Berlin)`, `3 runs left`, or both joined by `; `.
|
|
191
|
+
*/
|
|
192
|
+
export declare function jobEndsText(job: Pick<JobRecord, "until" | "runsLeft" | "timeZone">): string | undefined;
|
|
193
|
+
/** The session a job wakes, or undefined when it is not bound. */
|
|
194
|
+
export declare function jobWakeSession(job: Pick<JobRecord, "wake" | "originSessionId">): string | undefined;
|
|
143
195
|
/**
|
|
144
196
|
* The time limits a run of `job` gets if it starts now, with their sources:
|
|
145
197
|
* the scheduler's settings reader, or without one the settings file.
|
|
@@ -174,7 +226,7 @@ export declare function runJobNow(scheduler: Scheduler, jobId: string, opts?: Jo
|
|
|
174
226
|
export declare function removeJob(scheduler: Scheduler, jobId: string, opts?: JobActionOptions): Promise<JobRecord>;
|
|
175
227
|
/** One job, removed ones included; undefined when the id is unknown. */
|
|
176
228
|
export declare function getJob(scheduler: Scheduler, jobId: string): JobRecord | undefined;
|
|
177
|
-
/** Jobs, oldest first; removed jobs are hidden unless asked for. */
|
|
229
|
+
/** Jobs, oldest first; removed and ended jobs are hidden unless asked for. */
|
|
178
230
|
export declare function listJobs(scheduler: Scheduler, opts?: {
|
|
179
231
|
includeRemoved?: boolean;
|
|
180
232
|
}): JobRecord[];
|