@tidegap/core 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +1 -1
  2. package/dist/agent-snippet.d.ts +30 -0
  3. package/dist/agent-snippet.js +120 -0
  4. package/dist/channels/commands.d.ts +137 -0
  5. package/dist/channels/commands.js +377 -0
  6. package/dist/channels/delivery-codes.d.ts +9 -0
  7. package/dist/channels/delivery-codes.js +53 -0
  8. package/dist/channels/digest.d.ts +102 -0
  9. package/dist/channels/digest.js +146 -0
  10. package/dist/channels/format.d.ts +127 -0
  11. package/dist/channels/format.js +407 -0
  12. package/dist/channels/index.d.ts +15 -0
  13. package/dist/channels/index.js +15 -0
  14. package/dist/channels/kinds/command.d.ts +13 -0
  15. package/dist/channels/kinds/command.js +65 -0
  16. package/dist/channels/kinds/discord.d.ts +16 -0
  17. package/dist/channels/kinds/discord.js +67 -0
  18. package/dist/channels/kinds/email.d.ts +20 -0
  19. package/dist/channels/kinds/email.js +162 -0
  20. package/dist/channels/kinds/index.d.ts +8 -0
  21. package/dist/channels/kinds/index.js +17 -0
  22. package/dist/channels/kinds/ntfy.d.ts +25 -0
  23. package/dist/channels/kinds/ntfy.js +163 -0
  24. package/dist/channels/kinds/pushover.d.ts +11 -0
  25. package/dist/channels/kinds/pushover.js +77 -0
  26. package/dist/channels/kinds/shared.d.ts +25 -0
  27. package/dist/channels/kinds/shared.js +39 -0
  28. package/dist/channels/kinds/shortcuts.d.ts +9 -0
  29. package/dist/channels/kinds/shortcuts.js +45 -0
  30. package/dist/channels/kinds/slack.d.ts +8 -0
  31. package/dist/channels/kinds/slack.js +57 -0
  32. package/dist/channels/kinds/telegram.d.ts +4 -0
  33. package/dist/channels/kinds/telegram.js +26 -0
  34. package/dist/channels/kinds/webhook.d.ts +30 -0
  35. package/dist/channels/kinds/webhook.js +177 -0
  36. package/dist/channels/payload.d.ts +36 -0
  37. package/dist/channels/payload.js +61 -0
  38. package/dist/channels/plan.d.ts +24 -0
  39. package/dist/channels/plan.js +66 -0
  40. package/dist/channels/registry.d.ts +191 -0
  41. package/dist/channels/registry.js +125 -0
  42. package/dist/channels/telegram.d.ts +110 -0
  43. package/dist/channels/telegram.js +168 -0
  44. package/dist/channels/types.d.ts +107 -0
  45. package/dist/channels/types.js +26 -0
  46. package/dist/claude-tools.d.ts +29 -0
  47. package/dist/claude-tools.js +49 -0
  48. package/dist/data/tables.generated.d.ts +6 -0
  49. package/dist/data/tables.generated.js +37 -0
  50. package/dist/energy.d.ts +77 -0
  51. package/dist/energy.js +131 -0
  52. package/dist/grid.d.ts +17 -2
  53. package/dist/grid.js +43 -4
  54. package/dist/handoff.d.ts +152 -0
  55. package/dist/handoff.js +430 -0
  56. package/dist/history.d.ts +2 -0
  57. package/dist/history.js +3 -1
  58. package/dist/index.d.ts +43 -13
  59. package/dist/index.js +32 -6
  60. package/dist/job-cadence.d.ts +76 -0
  61. package/dist/job-cadence.js +240 -0
  62. package/dist/jobs.d.ts +173 -0
  63. package/dist/jobs.js +794 -0
  64. package/dist/notify.d.ts +2 -0
  65. package/dist/notify.js +2 -1
  66. package/dist/postpone.d.ts +113 -0
  67. package/dist/postpone.js +185 -0
  68. package/dist/providers/anthropic.js +7 -3
  69. package/dist/providers/base.d.ts +113 -1
  70. package/dist/providers/base.js +15 -0
  71. package/dist/providers/budget.d.ts +25 -0
  72. package/dist/providers/budget.js +57 -0
  73. package/dist/providers/defaults.js +4 -0
  74. package/dist/providers/defer.d.ts +16 -0
  75. package/dist/providers/defer.js +31 -0
  76. package/dist/providers/gemini.d.ts +1 -0
  77. package/dist/providers/gemini.js +27 -20
  78. package/dist/providers/index.d.ts +2 -2
  79. package/dist/providers/index.js +1 -1
  80. package/dist/providers/ollama.d.ts +1 -0
  81. package/dist/providers/ollama.js +26 -22
  82. package/dist/providers/openai.js +5 -5
  83. package/dist/providers/timeout.d.ts +18 -0
  84. package/dist/providers/timeout.js +33 -0
  85. package/dist/quota.d.ts +7 -2
  86. package/dist/quota.js +12 -27
  87. package/dist/readiness.d.ts +169 -0
  88. package/dist/readiness.js +254 -0
  89. package/dist/redact.d.ts +42 -0
  90. package/dist/redact.js +110 -0
  91. package/dist/region-host.d.ts +30 -0
  92. package/dist/region-host.js +69 -0
  93. package/dist/region.d.ts +102 -20
  94. package/dist/region.js +175 -23
  95. package/dist/run-session.d.ts +36 -0
  96. package/dist/run-session.js +72 -0
  97. package/dist/schedule-job.d.ts +95 -0
  98. package/dist/schedule-job.js +195 -0
  99. package/dist/scheduler.d.ts +245 -14
  100. package/dist/scheduler.js +919 -109
  101. package/dist/sign.d.ts +8 -1
  102. package/dist/sign.js +49 -3
  103. package/dist/storage/sqlite.d.ts +157 -5
  104. package/dist/storage/sqlite.js +661 -20
  105. package/dist/task-events.d.ts +102 -0
  106. package/dist/task-events.js +308 -0
  107. package/dist/tool-surface.d.ts +31 -2
  108. package/dist/tool-surface.js +359 -65
  109. package/dist/types.d.ts +246 -3
  110. package/dist/types.js +8 -1
  111. package/dist/zone-time.d.ts +22 -0
  112. package/dist/zone-time.js +76 -0
  113. package/package.json +10 -5
  114. package/dist/aggregator.d.ts.map +0 -1
  115. package/dist/aggregator.js.map +0 -1
  116. package/dist/budget.d.ts.map +0 -1
  117. package/dist/budget.js.map +0 -1
  118. package/dist/data/tables.generated.d.ts.map +0 -1
  119. package/dist/data/tables.generated.js.map +0 -1
  120. package/dist/energy.d.ts.map +0 -1
  121. package/dist/energy.js.map +0 -1
  122. package/dist/grid.d.ts.map +0 -1
  123. package/dist/grid.js.map +0 -1
  124. package/dist/history.d.ts.map +0 -1
  125. package/dist/history.js.map +0 -1
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/index.js.map +0 -1
  128. package/dist/notify.d.ts.map +0 -1
  129. package/dist/notify.js.map +0 -1
  130. package/dist/paths.d.ts.map +0 -1
  131. package/dist/paths.js.map +0 -1
  132. package/dist/providers/anthropic.d.ts.map +0 -1
  133. package/dist/providers/anthropic.js.map +0 -1
  134. package/dist/providers/base.d.ts.map +0 -1
  135. package/dist/providers/base.js.map +0 -1
  136. package/dist/providers/defaults.d.ts.map +0 -1
  137. package/dist/providers/defaults.js.map +0 -1
  138. package/dist/providers/gemini.d.ts.map +0 -1
  139. package/dist/providers/gemini.js.map +0 -1
  140. package/dist/providers/index.d.ts.map +0 -1
  141. package/dist/providers/index.js.map +0 -1
  142. package/dist/providers/ollama.d.ts.map +0 -1
  143. package/dist/providers/ollama.js.map +0 -1
  144. package/dist/providers/openai.d.ts.map +0 -1
  145. package/dist/providers/openai.js.map +0 -1
  146. package/dist/quota.d.ts.map +0 -1
  147. package/dist/quota.js.map +0 -1
  148. package/dist/recommend.d.ts.map +0 -1
  149. package/dist/recommend.js.map +0 -1
  150. package/dist/redact.d.ts.map +0 -1
  151. package/dist/redact.js.map +0 -1
  152. package/dist/region.d.ts.map +0 -1
  153. package/dist/region.js.map +0 -1
  154. package/dist/routing.d.ts.map +0 -1
  155. package/dist/routing.js.map +0 -1
  156. package/dist/scheduler.d.ts.map +0 -1
  157. package/dist/scheduler.js.map +0 -1
  158. package/dist/select-window.d.ts.map +0 -1
  159. package/dist/select-window.js.map +0 -1
  160. package/dist/sign.d.ts.map +0 -1
  161. package/dist/sign.js.map +0 -1
  162. package/dist/storage/sqlite.d.ts.map +0 -1
  163. package/dist/storage/sqlite.js.map +0 -1
  164. package/dist/tool-surface.d.ts.map +0 -1
  165. package/dist/tool-surface.js.map +0 -1
  166. package/dist/types.d.ts.map +0 -1
  167. package/dist/types.js.map +0 -1
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Task events (audit trail): one row per change of a task, in the ledger's
3
+ * `task_events` table, written in the same transaction as the task write.
4
+ * Shared by both cores; the Python core writes `dispatched`, `completed`,
5
+ * `failed` and `cancelled` rows with the same shape.
6
+ */
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"];
9
+ export type TaskEventKind = (typeof TASK_EVENT_KINDS)[number];
10
+ /**
11
+ * Who made the change: `agent:<host>`, `page`, `client:<name>`, `cli`,
12
+ * `tick`, `telegram`, `openclaw` or `system`.
13
+ */
14
+ export type TaskEventActor = string;
15
+ export interface TaskEvent {
16
+ id: number;
17
+ taskId: string;
18
+ /** ISO-8601. */
19
+ at: string;
20
+ kind: TaskEventKind;
21
+ actor: TaskEventActor;
22
+ /** snake_case keys: `from` / `to` timing, `reason`, `preset`, `provider`, `model`, `error`… */
23
+ details: Record<string, unknown>;
24
+ }
25
+ /** An event to write with a task change; `taskId` and `at` come from the write. */
26
+ export interface TaskEventInput {
27
+ kind: TaskEventKind;
28
+ actor?: TaskEventActor;
29
+ details?: Record<string, unknown>;
30
+ }
31
+ /**
32
+ * A valid actor string, or `system`. `agent:` and `client:` names lose
33
+ * control characters and are cut to 64 characters. Never throws: an audit
34
+ * write must not block a task action.
35
+ */
36
+ export declare function normalizeActor(actor: unknown): TaskEventActor;
37
+ export declare function isTaskEventKind(kind: unknown): kind is TaskEventKind;
38
+ /**
39
+ * The details of one event: `from` / `to` timing for moves and run-now,
40
+ * provider and model for created / dispatched / completed / failed, the
41
+ * first line of the error for failed, then `extra`.
42
+ */
43
+ export declare function eventDetails(kind: TaskEventKind, prev: TaskRecord<unknown> | undefined, next: TaskRecord<unknown>, extra?: Record<string, unknown>): Record<string, unknown>;
44
+ /** The kind a status change implies when the writer named none (terminal moves only). */
45
+ export declare function impliedEventKind(prevStatus: string, nextStatus: string): TaskEventKind | undefined;
46
+ /** A one-line summary of the details, or "". */
47
+ export declare function eventSummary(e: Pick<TaskEvent, "kind" | "details">): string;
48
+ /** `<at> <kind> by <actor>[ - <summary>]`, one line. */
49
+ export declare function formatTaskEvent(e: Pick<TaskEvent, "at" | "kind" | "actor" | "details">): string;
50
+ /** The API / JSON shape of one event. */
51
+ export declare function taskEventJson(e: TaskEvent): {
52
+ at: string;
53
+ kind: TaskEventKind;
54
+ actor: string;
55
+ details: Record<string, unknown>;
56
+ };
57
+ /** A run reports no progress in its first 5 seconds: a fast run writes none. */
58
+ export declare const PROGRESS_QUIET_MS = 5000;
59
+ /** At most one progress event per 15 seconds. */
60
+ export declare const PROGRESS_GAP_MS = 15000;
61
+ /** At most 24 progress events per task, so its `created` event stays inside a page of 50. */
62
+ export declare const PROGRESS_MAX_EVENTS = 24;
63
+ /** Longest progress line. */
64
+ export declare const PROGRESS_LINE_MAX_CHARS = 200;
65
+ /**
66
+ * Untrusted output text without terminal escape sequences, control
67
+ * characters (a tab becomes a space), line separators or bidirectional
68
+ * controls. An adapter cleans a line with this before it scrubs secrets, so
69
+ * a removed character cannot join a secret after the scrub.
70
+ */
71
+ export declare function cleanProgressText(raw: string): string;
72
+ /**
73
+ * One progress line as it is stored: cleaned by {@link cleanProgressText},
74
+ * trailing space trimmed, cut to {@link PROGRESS_LINE_MAX_CHARS}
75
+ * characters. Undefined for a blank line.
76
+ */
77
+ export declare function progressLine(raw: string): string | undefined;
78
+ /** The `progress` callback of one run and its end. */
79
+ export interface ProgressRecorder {
80
+ /** A line the run printed. Lines that come while no slot is open replace each other; the newest is written when one opens. */
81
+ onLine(line: string): void;
82
+ /** The run ended: a line still waiting for its slot is dropped, and nothing is written after this. */
83
+ close(): void;
84
+ }
85
+ /**
86
+ * The caps of a run's progress events, for every adapter: nothing in the
87
+ * first {@link PROGRESS_QUIET_MS}, then at most one event per
88
+ * {@link PROGRESS_GAP_MS} and {@link PROGRESS_MAX_EVENTS} per task, each line
89
+ * cleaned by {@link progressLine}. A line that comes before its slot waits
90
+ * for it, and a newer line takes its place, so the event shows the newest
91
+ * line. `write` gets the details of each event (`line`, `seq`); `seq`
92
+ * counts the task's progress events from 1, after the `existing` ones (read
93
+ * once, when the first event is due). The caller scrubs secrets from each
94
+ * line first. Never throws.
95
+ */
96
+ export declare function createProgressRecorder(write: (details: {
97
+ line: string;
98
+ seq: number;
99
+ }) => void, opts?: {
100
+ existing?: () => number;
101
+ }): ProgressRecorder;
102
+ //# sourceMappingURL=task-events.d.ts.map
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Task events (audit trail): one row per change of a task, in the ledger's
3
+ * `task_events` table, written in the same transaction as the task write.
4
+ * Shared by both cores; the Python core writes `dispatched`, `completed`,
5
+ * `failed` and `cancelled` rows with the same shape.
6
+ */
7
+ import { includesWebTool } from "./claude-tools.js";
8
+ import { stripControlChars } from "./history.js";
9
+ export const TASK_EVENT_KINDS = [
10
+ "created",
11
+ "rescheduled",
12
+ "postponed",
13
+ "expedited",
14
+ "cancelled",
15
+ "dispatched",
16
+ "completed",
17
+ "failed",
18
+ "deferred",
19
+ "replied",
20
+ // A Claude Code session was told the task finished (its prompt hook, a
21
+ // `queue wait` that printed the result, or a wake). At most one per finish:
22
+ // details carry the task's `completed_at`.
23
+ "notified",
24
+ // The tick wrote the task's result file, or could not (`written: false`
25
+ // with the error). At most one per task.
26
+ "result_file",
27
+ // A line a long `command` run printed while it ran (`line`, `seq`), within
28
+ // the caps of `createProgressRecorder`.
29
+ "progress",
30
+ ];
31
+ const FIXED_ACTORS = new Set(["page", "cli", "tick", "telegram", "openclaw", "system"]);
32
+ const NAME_MAX = 64;
33
+ /**
34
+ * A valid actor string, or `system`. `agent:` and `client:` names lose
35
+ * control characters and are cut to 64 characters. Never throws: an audit
36
+ * write must not block a task action.
37
+ */
38
+ export function normalizeActor(actor) {
39
+ if (typeof actor !== "string")
40
+ return "system";
41
+ if (FIXED_ACTORS.has(actor))
42
+ return actor;
43
+ const m = /^(agent|client):(.*)$/s.exec(actor);
44
+ if (!m)
45
+ return "system";
46
+ // eslint-disable-next-line no-control-regex
47
+ const name = m[2].replace(/[\u0000-\u001f\u007f]/g, "").trim().slice(0, NAME_MAX);
48
+ return name ? `${m[1]}:${name}` : "system";
49
+ }
50
+ export function isTaskEventKind(kind) {
51
+ return typeof kind === "string" && TASK_EVENT_KINDS.includes(kind);
52
+ }
53
+ function timing(r) {
54
+ return { scheduled_for: r.scheduledFor ?? null, not_before: r.notBefore ?? null, deadline: r.deadline ?? null };
55
+ }
56
+ /**
57
+ * The run facts of a `created` or `dispatched` event. Every `claude-code`
58
+ * row gets its planned mode: `fork` when it can run in a copy of its origin
59
+ * session (a checked origin, which a job occurrence never has, no web
60
+ * tool, and its folder is the session's), else `fresh`; the receipt's `session` records
61
+ * what the run did. A `claude-code` row with handoff fields also gets its
62
+ * profile, tools and folder, and a one-off command its folder. Empty for
63
+ * every other row.
64
+ */
65
+ function handoffDetails(r) {
66
+ if (!r.bodyJson)
67
+ return {};
68
+ let spec;
69
+ try {
70
+ spec = JSON.parse(r.bodyJson);
71
+ }
72
+ catch {
73
+ return {};
74
+ }
75
+ if (spec?.provider === "command" && spec.command?.origin === "cli")
76
+ return { cwd: spec.command.cwd ?? null };
77
+ if (spec?.provider !== "claude-code")
78
+ return {};
79
+ const handoff = spec.handoff && typeof spec.handoff === "object" ? spec.handoff : undefined;
80
+ const tools = Array.isArray(spec.tools) ? spec.tools : null;
81
+ const cwd = typeof handoff?.cwd === "string" ? handoff.cwd : null;
82
+ const fork = spec.origin?.agent === "claude-code" &&
83
+ !!r.originSessionId &&
84
+ !!r.originCwd &&
85
+ !(tools && includesWebTool(tools)) &&
86
+ (cwd === null || cwd === r.originCwd);
87
+ const planned_mode = fork ? "fork" : "fresh";
88
+ if (!handoff)
89
+ return { planned_mode };
90
+ return { profile: handoff.profile ?? null, tools, cwd, planned_mode };
91
+ }
92
+ function providerModel(bodyJson) {
93
+ if (!bodyJson)
94
+ return {};
95
+ try {
96
+ const spec = JSON.parse(bodyJson);
97
+ return {
98
+ ...(typeof spec.provider === "string" ? { provider: spec.provider } : {}),
99
+ ...(typeof spec.model === "string" ? { model: spec.model } : {}),
100
+ };
101
+ }
102
+ catch {
103
+ return {};
104
+ }
105
+ }
106
+ const MOVE_KINDS = new Set(["rescheduled", "postponed", "expedited"]);
107
+ const SPEC_KINDS = new Set(["created", "dispatched", "completed", "failed"]);
108
+ /**
109
+ * The details of one event: `from` / `to` timing for moves and run-now,
110
+ * provider and model for created / dispatched / completed / failed, the
111
+ * first line of the error for failed, then `extra`.
112
+ */
113
+ export function eventDetails(kind, prev, next, extra = {}) {
114
+ const out = {};
115
+ if (MOVE_KINDS.has(kind)) {
116
+ if (prev)
117
+ out.from = timing(prev);
118
+ out.to = timing(next);
119
+ }
120
+ if (kind === "created") {
121
+ const t = timing(next);
122
+ if (t.deadline)
123
+ out.deadline = t.deadline;
124
+ if (t.not_before)
125
+ out.not_before = t.not_before;
126
+ }
127
+ if (SPEC_KINDS.has(kind))
128
+ Object.assign(out, providerModel(next.bodyJson));
129
+ if (kind === "created" || kind === "dispatched")
130
+ Object.assign(out, handoffDetails(next));
131
+ if (kind === "failed" && next.error)
132
+ out.error = next.error.split("\n")[0].slice(0, 300);
133
+ return { ...out, ...extra };
134
+ }
135
+ /** The kind a status change implies when the writer named none (terminal moves only). */
136
+ export function impliedEventKind(prevStatus, nextStatus) {
137
+ if (prevStatus === nextStatus)
138
+ return undefined;
139
+ if (nextStatus === "completed" || nextStatus === "failed" || nextStatus === "cancelled")
140
+ return nextStatus;
141
+ return undefined;
142
+ }
143
+ function short(iso) {
144
+ return typeof iso === "string" ? iso : "none";
145
+ }
146
+ /** A one-line summary of the details, or "". */
147
+ export function eventSummary(e) {
148
+ const d = e.details ?? {};
149
+ const from = (d.from ?? {});
150
+ const to = (d.to ?? {});
151
+ const parts = [];
152
+ switch (e.kind) {
153
+ case "expedited":
154
+ parts.push(`not_before was ${short(from.not_before)}`, `scheduled_for ${short(from.scheduled_for)} -> ${short(to.scheduled_for)}`);
155
+ break;
156
+ case "rescheduled":
157
+ case "postponed":
158
+ if (typeof d.preset === "string")
159
+ parts.push(`preset ${d.preset}`);
160
+ parts.push(`scheduled_for ${short(from.scheduled_for)} -> ${short(to.scheduled_for)}`);
161
+ if (from.not_before !== to.not_before)
162
+ parts.push(`not_before ${short(from.not_before)} -> ${short(to.not_before)}`);
163
+ break;
164
+ case "deferred":
165
+ parts.push(`retry at ${short(d.retry_at)}`);
166
+ break;
167
+ case "replied":
168
+ parts.push(`reply ${short(d.child_task_id)}`);
169
+ break;
170
+ case "notified":
171
+ parts.push(`via ${short(d.via)}`);
172
+ break;
173
+ case "result_file":
174
+ parts.push(d.written === true ? `written ${short(d.path)}` : `not written: ${short(d.error)}`);
175
+ break;
176
+ case "progress":
177
+ if (typeof d.line === "string")
178
+ parts.push(d.line);
179
+ break;
180
+ case "failed":
181
+ if (typeof d.error === "string")
182
+ parts.push(d.error);
183
+ break;
184
+ default:
185
+ if (typeof d.provider === "string")
186
+ parts.push(`${d.provider}${typeof d.model === "string" ? `/${d.model}` : ""}`);
187
+ }
188
+ if (typeof d.reason === "string")
189
+ parts.push(d.reason);
190
+ return parts.join("; ");
191
+ }
192
+ /** `<at> <kind> by <actor>[ - <summary>]`, one line. */
193
+ export function formatTaskEvent(e) {
194
+ const summary = eventSummary(e);
195
+ return `${e.at} ${e.kind} by ${e.actor}${summary ? ` - ${summary}` : ""}`;
196
+ }
197
+ /** The API / JSON shape of one event. */
198
+ export function taskEventJson(e) {
199
+ return { at: e.at, kind: e.kind, actor: e.actor, details: e.details };
200
+ }
201
+ /** A run reports no progress in its first 5 seconds: a fast run writes none. */
202
+ export const PROGRESS_QUIET_MS = 5_000;
203
+ /** At most one progress event per 15 seconds. */
204
+ export const PROGRESS_GAP_MS = 15_000;
205
+ /** At most 24 progress events per task, so its `created` event stays inside a page of 50. */
206
+ export const PROGRESS_MAX_EVENTS = 24;
207
+ /** Longest progress line. */
208
+ export const PROGRESS_LINE_MAX_CHARS = 200;
209
+ /** Terminal escape sequences (CSI, OSC and two-character escapes): removed whole, not only their ESC. */
210
+ const TERMINAL_ESCAPES = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?|\u001b[@-Z\\-_]/g;
211
+ /** Line and paragraph separators (become a space) and bidirectional controls (removed). */
212
+ const LINE_SEPARATORS = /[\u2028\u2029]/g;
213
+ const BIDI_CONTROLS = /[\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
214
+ /** The most of a raw line {@link progressLine} reads, so a huge line costs no more than this. */
215
+ const PROGRESS_SCAN_CHARS = 8_192;
216
+ /**
217
+ * Untrusted output text without terminal escape sequences, control
218
+ * characters (a tab becomes a space), line separators or bidirectional
219
+ * controls. An adapter cleans a line with this before it scrubs secrets, so
220
+ * a removed character cannot join a secret after the scrub.
221
+ */
222
+ export function cleanProgressText(raw) {
223
+ return stripControlChars(raw.replace(TERMINAL_ESCAPES, "").replace(LINE_SEPARATORS, " ").replace(BIDI_CONTROLS, ""));
224
+ }
225
+ /**
226
+ * One progress line as it is stored: cleaned by {@link cleanProgressText},
227
+ * trailing space trimmed, cut to {@link PROGRESS_LINE_MAX_CHARS}
228
+ * characters. Undefined for a blank line.
229
+ */
230
+ export function progressLine(raw) {
231
+ const clean = cleanProgressText(raw.length > PROGRESS_SCAN_CHARS ? raw.slice(0, PROGRESS_SCAN_CHARS) : raw).trimEnd();
232
+ if (clean.trim() === "")
233
+ return undefined;
234
+ const chars = Array.from(clean);
235
+ return chars.length > PROGRESS_LINE_MAX_CHARS ? chars.slice(0, PROGRESS_LINE_MAX_CHARS).join("") : clean;
236
+ }
237
+ /**
238
+ * The caps of a run's progress events, for every adapter: nothing in the
239
+ * first {@link PROGRESS_QUIET_MS}, then at most one event per
240
+ * {@link PROGRESS_GAP_MS} and {@link PROGRESS_MAX_EVENTS} per task, each line
241
+ * cleaned by {@link progressLine}. A line that comes before its slot waits
242
+ * for it, and a newer line takes its place, so the event shows the newest
243
+ * line. `write` gets the details of each event (`line`, `seq`); `seq`
244
+ * counts the task's progress events from 1, after the `existing` ones (read
245
+ * once, when the first event is due). The caller scrubs secrets from each
246
+ * line first. Never throws.
247
+ */
248
+ export function createProgressRecorder(write, opts = {}) {
249
+ const started = Date.now();
250
+ let count;
251
+ let lastAt;
252
+ let pending;
253
+ let timer;
254
+ let closed = false;
255
+ const written = () => {
256
+ if (count === undefined) {
257
+ try {
258
+ count = Math.max(0, Math.floor(opts.existing?.() ?? 0));
259
+ }
260
+ catch {
261
+ count = 0;
262
+ }
263
+ }
264
+ return count;
265
+ };
266
+ const flush = () => {
267
+ timer = undefined;
268
+ const line = pending;
269
+ pending = undefined;
270
+ if (closed || line === undefined || written() >= PROGRESS_MAX_EVENTS)
271
+ return;
272
+ const seq = written() + 1;
273
+ count = seq;
274
+ lastAt = Date.now();
275
+ try {
276
+ write({ line, seq });
277
+ }
278
+ catch {
279
+ // A busy ledger costs this line, not the run.
280
+ }
281
+ };
282
+ return {
283
+ onLine(raw) {
284
+ if (closed || (count !== undefined && count >= PROGRESS_MAX_EVENTS))
285
+ return;
286
+ const line = progressLine(raw);
287
+ if (line === undefined)
288
+ return;
289
+ pending = line;
290
+ if (timer !== undefined)
291
+ return;
292
+ const due = Math.max(started + PROGRESS_QUIET_MS, lastAt !== undefined ? lastAt + PROGRESS_GAP_MS : 0);
293
+ const wait = due - Date.now();
294
+ if (wait <= 0)
295
+ return flush();
296
+ timer = setTimeout(flush, wait);
297
+ timer.unref?.();
298
+ },
299
+ close() {
300
+ closed = true;
301
+ pending = undefined;
302
+ if (timer !== undefined)
303
+ clearTimeout(timer);
304
+ timer = undefined;
305
+ },
306
+ };
307
+ }
308
+ //# sourceMappingURL=task-events.js.map
@@ -23,7 +23,9 @@
23
23
  * the MCP renderer validates strictly (it `.parse()`s incoming arguments),
24
24
  * the OpenClaw renderer advertises the looser shapes it always has — so the
25
25
  * observable wire contract on each host is preserved while the surface
26
- * (names, parameter sets, requiredness, descriptions) is unified.
26
+ * (names, parameter sets, requiredness, descriptions) is unified. A tool
27
+ * whose handler differs per host carries a `descriptionPerHost` override;
28
+ * resolve the text with `descriptionForHost`.
27
29
  *
28
30
  * Host applicability is first-class: `set_delivery` is OpenClaw-only, and a
29
31
  * handful of parameters are host-scoped (MCP's `dry_run` / `dispatch` /
@@ -66,11 +68,31 @@ export interface ToolParam {
66
68
  itemKind?: "string" | "enum";
67
69
  properties?: readonly ToolParam[];
68
70
  }
71
+ /**
72
+ * MCP tool annotations (the four behavior hints plus a display title).
73
+ * Neutral data: the MCP server advertises them in `tools/list`; OpenClaw has
74
+ * no analogue and ignores them. A description must never contradict them.
75
+ */
76
+ export interface ToolAnnotations {
77
+ title: string;
78
+ /** Writes no file and no row. */
79
+ readOnlyHint: boolean;
80
+ /** Deletes or irreversibly replaces existing data. */
81
+ destructiveHint: boolean;
82
+ /** A second identical call changes nothing more. */
83
+ idempotentHint: boolean;
84
+ /** The call reaches a provider API, a grid feed or a usage endpoint. */
85
+ openWorldHint: boolean;
86
+ }
69
87
  /** One tool: its wire name, canonical description, host applicability, and
70
88
  * the ordered parameter descriptors. */
71
89
  export interface CanonicalToolDef {
72
90
  name: string;
91
+ /** The MCP text; also used on any host without an override. */
73
92
  description: string;
93
+ /** Per-host description, for a host whose handler differs from the MCP one. */
94
+ descriptionPerHost?: Partial<Record<ToolHost, string>>;
95
+ annotations?: ToolAnnotations;
74
96
  hosts: readonly ToolHost[];
75
97
  params: readonly ToolParam[];
76
98
  }
@@ -79,8 +101,14 @@ export declare const TOOL_SURFACE: readonly CanonicalToolDef[];
79
101
  export declare function getToolDef(name: string): CanonicalToolDef | undefined;
80
102
  /** Like {@link getToolDef} but throws when the name is unknown. */
81
103
  export declare function getToolDefOrThrow(name: string): CanonicalToolDef;
82
- /** The tools a given host registers, in canonical order. */
104
+ /** A tool's description as one host shows it (its override, else the base). */
105
+ export declare function descriptionForHost(def: CanonicalToolDef, host: ToolHost): string;
106
+ /** The tools a given host registers, in canonical order, each carrying the
107
+ * description resolved for that host. */
83
108
  export declare function toolsForHost(host: ToolHost): CanonicalToolDef[];
109
+ /** Tool counts per host; the site derives its "N tools" copy from these. */
110
+ export declare const MCP_TOOL_COUNT: number;
111
+ export declare const OPENCLAW_TOOL_COUNT: number;
84
112
  /** Which hosts expose a given parameter (defaults to the tool's hosts). */
85
113
  export declare function paramHosts(param: ToolParam, def: CanonicalToolDef): readonly ToolHost[];
86
114
  /** Whether a parameter is exposed on a given host. */
@@ -114,6 +142,7 @@ export interface NeutralParamSnapshot {
114
142
  export declare function neutralSurfaceForHost(host: ToolHost): Array<{
115
143
  name: string;
116
144
  description: string;
145
+ annotations?: ToolAnnotations;
117
146
  params: NeutralParamSnapshot[];
118
147
  }>;
119
148
  //# sourceMappingURL=tool-surface.d.ts.map