@tidegap/core 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) 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 +138 -0
  11. package/dist/channels/format.js +425 -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 +84 -0
  51. package/dist/energy.js +138 -0
  52. package/dist/grid.d.ts +17 -2
  53. package/dist/grid.js +43 -4
  54. package/dist/handoff.d.ts +171 -0
  55. package/dist/handoff.js +482 -0
  56. package/dist/history.d.ts +17 -0
  57. package/dist/history.js +14 -1
  58. package/dist/index.d.ts +49 -15
  59. package/dist/index.js +36 -8
  60. package/dist/job-cadence.d.ts +76 -0
  61. package/dist/job-cadence.js +240 -0
  62. package/dist/jobs.d.ts +183 -0
  63. package/dist/jobs.js +917 -0
  64. package/dist/notify.d.ts +11 -0
  65. package/dist/notify.js +19 -4
  66. package/dist/postpone.d.ts +113 -0
  67. package/dist/postpone.js +185 -0
  68. package/dist/providers/anthropic.js +14 -8
  69. package/dist/providers/base.d.ts +145 -2
  70. package/dist/providers/base.js +41 -1
  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 +4 -0
  77. package/dist/providers/gemini.js +34 -24
  78. package/dist/providers/http.d.ts +40 -0
  79. package/dist/providers/http.js +82 -0
  80. package/dist/providers/index.d.ts +2 -2
  81. package/dist/providers/index.js +1 -1
  82. package/dist/providers/ollama.d.ts +4 -0
  83. package/dist/providers/ollama.js +32 -25
  84. package/dist/providers/openai.js +11 -9
  85. package/dist/providers/timeout.d.ts +36 -0
  86. package/dist/providers/timeout.js +71 -0
  87. package/dist/quota.d.ts +7 -2
  88. package/dist/quota.js +12 -27
  89. package/dist/readiness.d.ts +205 -0
  90. package/dist/readiness.js +326 -0
  91. package/dist/redact.d.ts +42 -0
  92. package/dist/redact.js +110 -0
  93. package/dist/region-host.d.ts +30 -0
  94. package/dist/region-host.js +69 -0
  95. package/dist/region.d.ts +102 -20
  96. package/dist/region.js +175 -23
  97. package/dist/run-limits.d.ts +268 -0
  98. package/dist/run-limits.js +572 -0
  99. package/dist/run-session.d.ts +36 -0
  100. package/dist/run-session.js +72 -0
  101. package/dist/schedule-job.d.ts +118 -0
  102. package/dist/schedule-job.js +243 -0
  103. package/dist/scheduler.d.ts +391 -18
  104. package/dist/scheduler.js +1341 -177
  105. package/dist/sign.d.ts +8 -1
  106. package/dist/sign.js +49 -3
  107. package/dist/storage/sqlite.d.ts +183 -5
  108. package/dist/storage/sqlite.js +720 -19
  109. package/dist/task-events.d.ts +117 -0
  110. package/dist/task-events.js +345 -0
  111. package/dist/tool-surface.d.ts +31 -2
  112. package/dist/tool-surface.js +390 -65
  113. package/dist/types.d.ts +267 -3
  114. package/dist/types.js +6 -1
  115. package/dist/zone-time.d.ts +22 -0
  116. package/dist/zone-time.js +76 -0
  117. package/package.json +13 -5
  118. package/dist/aggregator.d.ts.map +0 -1
  119. package/dist/aggregator.js.map +0 -1
  120. package/dist/budget.d.ts.map +0 -1
  121. package/dist/budget.js.map +0 -1
  122. package/dist/data/tables.generated.d.ts.map +0 -1
  123. package/dist/data/tables.generated.js.map +0 -1
  124. package/dist/energy.d.ts.map +0 -1
  125. package/dist/energy.js.map +0 -1
  126. package/dist/grid.d.ts.map +0 -1
  127. package/dist/grid.js.map +0 -1
  128. package/dist/history.d.ts.map +0 -1
  129. package/dist/history.js.map +0 -1
  130. package/dist/index.d.ts.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/notify.d.ts.map +0 -1
  133. package/dist/notify.js.map +0 -1
  134. package/dist/paths.d.ts.map +0 -1
  135. package/dist/paths.js.map +0 -1
  136. package/dist/providers/anthropic.d.ts.map +0 -1
  137. package/dist/providers/anthropic.js.map +0 -1
  138. package/dist/providers/base.d.ts.map +0 -1
  139. package/dist/providers/base.js.map +0 -1
  140. package/dist/providers/defaults.d.ts.map +0 -1
  141. package/dist/providers/defaults.js.map +0 -1
  142. package/dist/providers/gemini.d.ts.map +0 -1
  143. package/dist/providers/gemini.js.map +0 -1
  144. package/dist/providers/index.d.ts.map +0 -1
  145. package/dist/providers/index.js.map +0 -1
  146. package/dist/providers/ollama.d.ts.map +0 -1
  147. package/dist/providers/ollama.js.map +0 -1
  148. package/dist/providers/openai.d.ts.map +0 -1
  149. package/dist/providers/openai.js.map +0 -1
  150. package/dist/quota.d.ts.map +0 -1
  151. package/dist/quota.js.map +0 -1
  152. package/dist/recommend.d.ts.map +0 -1
  153. package/dist/recommend.js.map +0 -1
  154. package/dist/redact.d.ts.map +0 -1
  155. package/dist/redact.js.map +0 -1
  156. package/dist/region.d.ts.map +0 -1
  157. package/dist/region.js.map +0 -1
  158. package/dist/routing.d.ts.map +0 -1
  159. package/dist/routing.js.map +0 -1
  160. package/dist/scheduler.d.ts.map +0 -1
  161. package/dist/scheduler.js.map +0 -1
  162. package/dist/select-window.d.ts.map +0 -1
  163. package/dist/select-window.js.map +0 -1
  164. package/dist/sign.d.ts.map +0 -1
  165. package/dist/sign.js.map +0 -1
  166. package/dist/storage/sqlite.d.ts.map +0 -1
  167. package/dist/storage/sqlite.js.map +0 -1
  168. package/dist/tool-surface.d.ts.map +0 -1
  169. package/dist/tool-surface.js.map +0 -1
  170. package/dist/types.d.ts.map +0 -1
  171. package/dist/types.js.map +0 -1
@@ -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` /
@@ -35,8 +37,14 @@
35
37
  * modelled with `optionalPerHost` rather than dropped.
36
38
  */
37
39
  import { DEFAULT_MODEL_BY_PROVIDER } from "./providers/defaults.js";
40
+ import { formatDuration, RUN_LIMITS } from "./run-limits.js";
38
41
  /** Every host, in a stable order (used by the divergence-canary snapshot). */
39
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);
40
48
  // ── Reusable parameter descriptors ──────────────────────────────────────────
41
49
  // Defined once so a description or shape can never drift between the two
42
50
  // tools/hosts that share it.
@@ -44,7 +52,7 @@ const deadlineParam = {
44
52
  name: "deadline",
45
53
  kind: "string",
46
54
  format: "date-time",
47
- description: "ISO-8601 timestamp (e.g. '2026-05-13T08:00:00-04:00') by which the task must have completed. Must be in the future. Required.",
55
+ description: "When the task must be finished: ISO-8601 with a UTC offset, in the future. Convert the user's words, e.g. \"by 8am tomorrow\" in New York becomes '2026-05-13T08:00:00-04:00'.",
48
56
  };
49
57
  const regionParam = (opts) => ({
50
58
  name: "region",
@@ -58,31 +66,44 @@ const carbonBudgetParam = {
58
66
  kind: "number",
59
67
  positive: true,
60
68
  optional: true,
61
- description: "Optional hard cap on estimated grams CO2-equivalent for this task. Windows above the cap are dropped before the cleanest is chosen; if none inside the deadline meets the cap the task fails rather than dispatching to a dirty window.",
62
- };
63
- const providerParam = {
64
- name: "provider",
65
- kind: "enum",
66
- values: ["anthropic", "openai", "gemini", "ollama"],
67
- optional: true,
68
- description: "Which provider to dispatch this task through: 'anthropic', 'openai', 'gemini', or 'ollama' (local). Defaults to 'anthropic'. 'anthropic' and 'openai' can auto-route through a 50%-cheaper Batch API when the deadline allows; 'gemini' and 'ollama' always dispatch synchronously.",
69
+ description: "Hard cap on the task's estimated grams CO2e, e.g. 5. Windows above it are skipped; if no window before the deadline fits, the task fails instead of running on a dirty grid. Omit for no cap.",
69
70
  };
71
+ // `claude-code` runs only in `tidegap tick` (the CLI host spawns the local
72
+ // Claude Code CLI), so it is offered on MCP and not on OpenClaw.
73
+ const providerParams = [
74
+ {
75
+ name: "provider",
76
+ kind: "enum",
77
+ hosts: ["mcp"],
78
+ values: ["anthropic", "openai", "gemini", "ollama", "claude-code"],
79
+ optional: true,
80
+ description: "Where the task runs. 'claude-code' uses the local Claude Code login on the next `tidegap tick`, with no API key (see tools); 'ollama' is a local model; the others need their API key. Defaults to 'claude-code' when queued from a Claude Code session (it then runs in a copy of that session, in its project directory), else 'anthropic'; an explicit 'anthropic' never resumes a session. 'anthropic' and 'openai' can use the 50%-cheaper Batch API when the deadline allows; the others always run synchronously.",
81
+ },
82
+ {
83
+ name: "provider",
84
+ kind: "enum",
85
+ hosts: ["openclaw"],
86
+ values: ["anthropic", "openai", "gemini", "ollama"],
87
+ optional: true,
88
+ description: "Where the task runs; 'ollama' is a local model, the others need their key in the plugin config. Defaults to the provider the model name implies ('gpt-…' is openai, 'gemini-…' is gemini, a configured Ollama model is ollama), else 'anthropic'. The gateway runs every task synchronously.",
89
+ },
90
+ ];
70
91
  const candidatesParam = {
71
92
  name: "candidates",
72
93
  kind: "array",
73
94
  itemKind: "string",
74
95
  optional: true,
75
- description: "Optional cross-provider routing candidates: 'provider:model' strings (e.g. ['anthropic:claude-haiku-4-5','openai:gpt-6-luna','ollama:llama-3-1-8b']) the caller EXPLICITLY allows. With >= 2 entries the scheduler scores them at the chosen dispatch window on a weighted blend of carbon, cost and latency and dispatches the winner (recording the full scored list on the signed receipt). No silent model swaps — routing only ever picks from this list. Absent or a single entry leaves the provider/model behavior unchanged. Every candidate model must exist in the price table or the task is rejected loudly.",
96
+ description: "'provider:model' pairs the user allows, e.g. ['anthropic:claude-haiku-4-5','ollama:llama-3-1-8b']. With 2 or more, the scheduler scores each at the chosen window on carbon, cost and latency (see route_weights), runs the winner and records the scores on the receipt; it never picks a model outside this list. Omit, or pass one entry, to keep provider and model as given. A model missing from the price table is rejected.",
76
97
  };
77
98
  const routeWeightsParam = {
78
99
  name: "route_weights",
79
100
  kind: "object",
80
101
  optional: true,
81
- description: "Optional routing weights {carbon, cost, latency}, non-negative and normalized internally. Default {carbon:0.6, cost:0.3, latency:0.1}. Only used when 'candidates' has >= 2 entries.",
102
+ description: "How to rank candidates, e.g. {\"carbon\": 1} for carbon only. Weights are relative and normalized; a key left out counts as 0. Omit for the default {carbon: 0.6, cost: 0.3, latency: 0.1}. Ignored unless candidates has 2 or more entries.",
82
103
  properties: [
83
- { name: "carbon", kind: "number", min: 0, optional: true, description: "Weight on estimated grams CO2e at the chosen window (non-negative)." },
84
- { name: "cost", kind: "number", min: 0, optional: true, description: "Weight on estimated USD list cost, batch discount applied when eligible (non-negative)." },
85
- { name: "latency", kind: "number", min: 0, optional: true, description: "Weight on the static latency tier: local < hosted-sync < hosted-batch (non-negative)." },
104
+ { name: "carbon", kind: "number", min: 0, optional: true, description: "Relative weight on the estimated grams CO2e at the chosen window. Omit to weight it 0 when route_weights is given." },
105
+ { name: "cost", kind: "number", min: 0, optional: true, description: "Relative weight on the estimated USD list cost, batch discount included when eligible. Omit to weight it 0 when route_weights is given." },
106
+ { name: "latency", kind: "number", min: 0, optional: true, description: "Relative weight on speed: local beats hosted sync, which beats hosted batch. Omit to weight it 0 when route_weights is given." },
86
107
  ],
87
108
  };
88
109
  const modelParam = (opts) => ({
@@ -92,12 +113,12 @@ const modelParam = (opts) => ({
92
113
  hosts: opts.hosts,
93
114
  description: opts.description,
94
115
  });
95
- const scheduleModelDescription = (anthropicOverride) => `Model to dispatch with (e.g. 'claude-sonnet-5' for Anthropic, 'gpt-6-sol' for OpenAI). Defaults per provider: anthropic '${DEFAULT_MODEL_BY_PROVIDER.anthropic}'${anthropicOverride}, openai '${DEFAULT_MODEL_BY_PROVIDER.openai}', gemini '${DEFAULT_MODEL_BY_PROVIDER.gemini}', ollama '${DEFAULT_MODEL_BY_PROVIDER.ollama}'. When >= 2 'candidates' are supplied, routing may overwrite this with the winning candidate.`;
116
+ const scheduleModelDescription = (anthropicOverride) => `Model id for the chosen provider, e.g. 'claude-sonnet-5' (anthropic) or 'gpt-6-sol' (openai). Omit for the provider default: anthropic '${DEFAULT_MODEL_BY_PROVIDER.anthropic}'${anthropicOverride}, openai '${DEFAULT_MODEL_BY_PROVIDER.openai}', gemini '${DEFAULT_MODEL_BY_PROVIDER.gemini}', ollama '${DEFAULT_MODEL_BY_PROVIDER.ollama}'. With 2 or more candidates, routing may pick another model from that list.`;
96
117
  const taskIdRequired = {
97
118
  name: "task_id",
98
119
  kind: "string",
99
120
  minLength: 1,
100
- description: "Task identifier returned by schedule_task.",
121
+ description: "The task's id, e.g. 't-3f2a…', from the schedule_task reply or the check_queue_status list.",
101
122
  };
102
123
  const deliverModes = ["chat", "telegram", "webhook", "file", "queue", "os"];
103
124
  const reportFormats = ["md", "html", "txt", "json", "pdf"];
@@ -108,21 +129,21 @@ const deliverParam = (optional) => ({
108
129
  values: deliverModes,
109
130
  optional,
110
131
  hosts: ["openclaw"],
111
- description: "How to deliver the result when the task completes — one or more of: chat (the user's active OpenClaw chat), telegram, webhook, file, queue, os (a native desktop notification on the gateway host). Default: chat.",
132
+ description: "Where the result goes when the task completes, one or more modes, e.g. ['chat','file']. chat is the user's active OpenClaw chat; os is a desktop notification on the gateway host; queue sends nothing. Default: chat. Ask the user first; set_delivery can change it later.",
112
133
  });
113
134
  const webhookUrlParam = {
114
135
  name: "webhook_url",
115
136
  kind: "string",
116
137
  optional: true,
117
138
  hosts: ["openclaw"],
118
- description: "Target URL when deliver includes 'webhook'.",
139
+ description: "URL that receives the full result as a POST, e.g. 'https://example.com/hooks/tidegap'. Needed when deliver includes 'webhook'; omit otherwise.",
119
140
  };
120
141
  const filePathParam = {
121
142
  name: "file_path",
122
143
  kind: "string",
123
144
  optional: true,
124
145
  hosts: ["openclaw"],
125
- description: "Output path when deliver includes 'file'.",
146
+ description: "Path on the gateway host to write the report to, e.g. '/var/reports/digest.md'. Needed when deliver includes 'file'; omit otherwise.",
126
147
  };
127
148
  const fileFormatParam = {
128
149
  name: "file_format",
@@ -130,20 +151,30 @@ const fileFormatParam = {
130
151
  values: reportFormats,
131
152
  optional: true,
132
153
  hosts: ["openclaw"],
133
- description: "Report format for 'file' delivery: md, html, txt, json, or pdf (pdf renders the HTML report via puppeteer if installed on the gateway). Default: md.",
154
+ description: "Report format for 'file' delivery, e.g. 'html'. Default: md. 'pdf' renders the HTML report and needs puppeteer on the gateway.",
134
155
  };
135
156
  // ── The canonical surface ───────────────────────────────────────────────────
136
157
  export const TOOL_SURFACE = [
137
158
  {
138
159
  name: "get_grid_forecast",
139
160
  hosts: ["mcp", "openclaw"],
140
- description: "Return the projected electricity-grid carbon intensity for a region, hour by hour. Use this when deciding whether to run an expensive AI task now or defer it — intensity is reported in grams CO2-equivalent per kWh with a categorical band (very_clean / clean / average / dirty / very_dirty). Read-only; does not touch the task queue.",
161
+ description: "Return the hour-by-hour grid carbon intensity forecast for one region, up to 72 hours ahead. Use when: the user asks how clean the grid is now or later, or wants the raw curve. Do not use to pick a run time for a task (use recommend_window) or to queue work (use schedule_task). Behavior: writes nothing; reads one grid feed, no login; GB is live without a key, other zones need a feed key or get synthetic data (Source: mock). Returns: region, source, generated time, one row per hour (gCO2/kWh and band), and the cleanest and dirtiest hour. Rejects an unknown zone and lists the closest zones.",
162
+ descriptionPerHost: {
163
+ openclaw: "Return the hour-by-hour grid carbon intensity forecast for one region, up to 72 hours ahead. Use when: the user asks how clean the grid is now or later, or wants the raw curve. Do not use to pick a run time for a task (use recommend_window) or to queue work (use schedule_task). Behavior: writes nothing; reads one grid feed; GB is live without a key, other zones need a feed key in the plugin config or get synthetic data (source: mock). Returns: region, source, generatedAt and entries (datetime, carbonIntensityGCo2PerKwh, band). Throws on an unknown zone, naming the closest ones.",
164
+ },
165
+ annotations: {
166
+ title: "Grid carbon forecast",
167
+ readOnlyHint: true,
168
+ destructiveHint: false,
169
+ idempotentHint: true,
170
+ openWorldHint: true,
171
+ },
141
172
  params: [
142
173
  regionParam({
143
174
  // Required on the MCP server; optional on OpenClaw, which defaults a
144
175
  // missing region from its config / the host timezone (else GB).
145
176
  optionalPerHost: { mcp: false, openclaw: true },
146
- description: "Electricity Maps grid zone code (e.g. 'US-CAL-CISO', 'US-TEX-ERCO', 'GB', 'FR', 'DE'). On hosts that allow omitting it, defaults to the configured region, else a host-timezone guess, else GB.",
177
+ description: "Grid zone code, e.g. 'US-CAL-CISO', 'GB' or 'DE'; take it from the user's location or the data center they name. `tidegap region list` prints the supported zones; any zone works with an Electricity Maps key. Defaults, where the host lets it be omitted, to the configured region, else the stored setting (`tidegap region set`), else a time-zone guess, else GB.",
147
178
  }),
148
179
  {
149
180
  name: "hours",
@@ -152,14 +183,24 @@ export const TOOL_SURFACE = [
152
183
  min: 1,
153
184
  max: 72,
154
185
  optional: true,
155
- description: "Forecast horizon in hours (1-72). Defaults to 24.",
186
+ description: "How many hours ahead to forecast, e.g. 12 to cover \"tonight\". Defaults to 24; 72 is the most.",
156
187
  },
157
188
  ],
158
189
  },
159
190
  {
160
191
  name: "recommend_window",
161
192
  hosts: ["mcp", "openclaw"],
162
- description: "Return the optimal carbon-aware execution window for a task WITHOUT scheduling it. Use this for non-committal planning — to see when the cleanest grid moment falls inside the deadline (and the savings vs running now) before deciding whether to commit via schedule_task. Returns the chosen window, top alternatives, a batch_eligible flag, the grid_source (which feed produced the forecast — 'mock' means synthetic data), and a one-line reasoning string. Read-only; does not touch the task queue.",
193
+ description: "Preview the cleanest run window before a task's deadline, without queuing it. Use when: the user asks when a task would run or what waiting saves. Do not use to queue the task (use schedule_task) or for the raw hourly curve (use get_grid_forecast). Behavior: writes nothing; reads the grid forecast; no login or key. Returns: scheduled_for, intensity, band, estimated_carbon_g_co2, estimated_savings_vs_now_pct, batch_eligible, grid_source (mock = synthetic), alternatives, reasoning; routing_preview with 2+ candidates. Rejects a past deadline, an unknown zone, or a carbon_budget_g no window meets.",
194
+ descriptionPerHost: {
195
+ openclaw: "Preview the cleanest run window before a task's deadline, without queuing it. Use when: the user asks when a task would run or what waiting saves. Do not use to queue the task (use schedule_task) or for the raw hourly curve (use get_grid_forecast). Behavior: writes nothing; reads the grid forecast; no key needed. Returns: scheduledFor, intensityGCo2PerKwh, band, estimatedCarbonGCo2, estimatedSavingsVsNowPct, batchEligible, gridSource (mock = synthetic), alternatives, reasoning, routingPreview with 2+ candidates. Throws on a past deadline, an unknown zone, or a carbon_budget_g no window meets.",
196
+ },
197
+ annotations: {
198
+ title: "Preview cleanest window",
199
+ readOnlyHint: true,
200
+ destructiveHint: false,
201
+ idempotentHint: true,
202
+ openWorldHint: true,
203
+ },
163
204
  params: [
164
205
  deadlineParam,
165
206
  regionParam({
@@ -167,14 +208,14 @@ export const TOOL_SURFACE = [
167
208
  // historically made it optional — kept as-is.
168
209
  optionalPerHost: { mcp: false, openclaw: true },
169
210
  minLength: 1,
170
- description: "Electricity Maps grid zone code (e.g. 'US-CAL-CISO', 'FR') the recommendation reasons over. On hosts that allow omitting it, defaults to the configured region, else a host-timezone guess, else GB.",
211
+ description: "Grid zone the task would run against, e.g. 'US-CAL-CISO' or 'FR'. `tidegap region list` prints the supported zones; any zone works with an Electricity Maps key. Defaults, where the host lets it be omitted, to the configured region, else the stored setting (`tidegap region set`), else a time-zone guess, else GB.",
171
212
  }),
172
213
  carbonBudgetParam,
173
214
  modelParam({
174
215
  // MCP-only: affects the reasoning string. OpenClaw's recommend_window
175
216
  // never exposed a model parameter.
176
217
  hosts: ["mcp"],
177
- description: "Optional vendor model name (e.g. 'claude-sonnet-5'). Affects the reasoning string only.",
218
+ description: "Model name to mention in the reasoning text, e.g. 'claude-sonnet-5'; it does not change the window. Omit to leave it out.",
178
219
  }),
179
220
  candidatesParam,
180
221
  routeWeightsParam,
@@ -183,13 +224,31 @@ export const TOOL_SURFACE = [
183
224
  {
184
225
  name: "schedule_task",
185
226
  hosts: ["mcp", "openclaw"],
186
- description: "Queue an AI task to run during off-peak hours inside the given deadline. Three parallel wins: (1) lighter on the electricity grid — deferring non-urgent tasks smooths projected AI compute demand; (2) 50% of sync list price (projected) — auto-routes through Anthropic/OpenAI Batch APIs when the deadline allows; (3) lower carbon — dispatch at the cleanest electricity-grid hour. Invoke this tool whenever the user phrases a request with deferral language: \"do this later\", \"by tomorrow\", \"tonight\", \"overnight\", \"by EOD\", \"sometime this week\", \"when you have a moment\", \"remind me to\", \"queue this up\", \"schedule this\", \"no rush\", \"not urgent\". Convert the user's wording to an ISO-8601 deadline and pass the task as the prompt. Returns a task_id you can later check with check_queue_status. Good fits: nightly digests, batch summaries, research sweeps, evaluator runs, multi-step report generation — anything the user is fine waiting on. Do NOT use for live chat, interactive code edits, or any task the user is actively waiting to see complete.",
227
+ description: "Queue an AI task or recurring job to run at the cleanest grid hour before its deadline; long deadlines may use the provider Batch API. Use when: the user defers work (\"tonight\", \"no rush\", \"before my limit resets\") or wants it repeated (\"every night\", \"daily\", a cron); map that to deadline or repeat. Do not use for work the user waits on (do it now), to preview only (use recommend_window or dry_run) or for limits (use tidegap_usage). Behavior: adds one task, one run of one runner (dry_run writes nothing), or with repeat a job of such tasks; `tidegap tick` runs it; reads the grid forecast; no login; the result stays in the queue (check_queue_status). Returns: task_id, status, scheduled_for, deadline, provider, model, runs_in, estimated_carbon_g_co2, a readiness line; a job adds job_id and its guarantee. Rejects a past deadline, an unknown zone, disallowed tools and shell commands.",
228
+ descriptionPerHost: {
229
+ openclaw: "Queue an AI task or recurring job to run at the cleanest grid hour before its deadline. Use when: the user defers work (\"tonight\", \"no rush\") or wants it repeated (\"every night\", \"daily\", a cron); map that to deadline or repeat. Do not use for work the user waits on (do it now) or to preview only (use recommend_window). Behavior: adds one task, one LLM call (never several agents), or with repeat a job of such tasks with chat delivery; the gateway runs it synchronously with a plugin provider key or the OpenClaw runtime; reads the grid forecast. Returns: task_id, status, scheduled_for, region, provider, model, estimated_carbon_g_co2, grid_source, dispatch, delivery_options, next_step (ask, then call set_delivery); a job returns job_id, guarantee, first_task_id. Throws on a past deadline, an unknown zone, a provider with no key, or shell commands.",
230
+ },
231
+ annotations: {
232
+ title: "Schedule task at cleanest hour",
233
+ readOnlyHint: false,
234
+ destructiveHint: false,
235
+ idempotentHint: false,
236
+ openWorldHint: true,
237
+ },
187
238
  params: [
188
239
  {
189
240
  name: "prompt",
190
241
  kind: "string",
191
242
  minLength: 1,
192
- description: "The prompt or task description to dispatch when the chosen window arrives.",
243
+ hosts: ["openclaw"],
244
+ description: "The full instruction the model receives when the window arrives, e.g. 'Summarize today's AI policy news in 5 bullets'. Include every fact the run needs.",
245
+ },
246
+ {
247
+ name: "prompt",
248
+ kind: "string",
249
+ minLength: 1,
250
+ hosts: ["mcp"],
251
+ description: "The full instruction the model receives when the window arrives, e.g. 'Summarize today's AI policy news in 5 bullets'. The run may start in a fresh session without this conversation (the reply's runs_in line says which), so name the files, decisions and constraints it needs.",
193
252
  },
194
253
  // OpenClaw keeps `deadline` required. On MCP it is optional because a
195
254
  // `deadline_kind: "quota_reset"` task has its deadline resolved by the
@@ -199,12 +258,12 @@ export const TOOL_SURFACE = [
199
258
  ...deadlineParam,
200
259
  hosts: ["mcp"],
201
260
  optional: true,
202
- description: "ISO-8601 timestamp (e.g. '2026-05-13T08:00:00-04:00') by which the task must have completed. Must be in the future. Required unless deadline_kind is 'quota_reset', in which case it is ignored.",
261
+ description: "When the task must be finished: ISO-8601 with a UTC offset, in the future. Convert the user's words, e.g. \"by 8am tomorrow\" in New York becomes '2026-05-13T08:00:00-04:00'. Omit with deadline_kind 'quota_reset', which sets it (a value is then ignored), or with a job repeat, whose first run then follows the cadence.",
203
262
  },
204
263
  regionParam({
205
264
  // Optional on BOTH hosts for schedule_task.
206
265
  optionalPerHost: { mcp: true, openclaw: true },
207
- description: "Grid-region override (Electricity Maps zone code such as 'US-CAL-CISO'). Defaults to the host's configured region, else a host-timezone guess, else GB.",
266
+ description: "Grid zone to plan against, e.g. 'US-CAL-CISO' or 'FR'; pass it only when the user names a place. `tidegap region list` prints the supported zones; any zone works with an Electricity Maps key. Defaults to the host's configured region (MCP: TIDEGAP_DEFAULT_REGION; OpenClaw: defaultRegion), else the stored setting (`tidegap region set`), else a time-zone guess, else GB. The reply's region_source names the rule that applied.",
208
267
  }),
209
268
  carbonBudgetParam,
210
269
  // The TIDEGAP_DEFAULT_MODEL override is read only by the MCP server, so the
@@ -217,30 +276,75 @@ export const TOOL_SURFACE = [
217
276
  hosts: ["openclaw"],
218
277
  description: scheduleModelDescription(""),
219
278
  }),
220
- providerParam,
279
+ ...providerParams,
221
280
  candidatesParam,
222
281
  routeWeightsParam,
223
282
  // ── MCP-only parameters ──
283
+ {
284
+ name: "tools",
285
+ kind: "array",
286
+ itemKind: "string",
287
+ optional: true,
288
+ hosts: ["mcp"],
289
+ description: "Claude Code tools for a 'claude-code' run, e.g. ['WebSearch','WebFetch'] for a research task; [] means none. Allowed: WebSearch, WebFetch, Read, Grep, Glob. Omit for the default: Read, Grep and Glob in the session's project directory for a task queued from a Claude Code session, else WebSearch and WebFetch (TIDEGAP_CLAUDE_TOOLS overrides that one). A web tool makes a task from a session run fresh, without its context. Rejected: any other name (Bash, Write, Edit, ...) and a set that mixes a file tool with a web tool, because web content is untrusted. A job keeps the whole group: any file tool means Read, Grep and Glob; any web tool means WebSearch and WebFetch. A job stores its tools when created and ignores TIDEGAP_CLAUDE_TOOLS.",
290
+ },
291
+ {
292
+ name: "runner",
293
+ kind: "enum",
294
+ values: ["anthropic", "openai", "gemini", "ollama", "claude-code"],
295
+ optional: true,
296
+ hosts: ["mcp"],
297
+ description: "Another name for provider, e.g. 'claude-code'; pass one of the two, or both with the same value. Omit it to follow provider and its default. 'command' is rejected: a shell command task is the user's call, queued with `tidegap queue add --runner command`.",
298
+ },
299
+ {
300
+ name: "cwd",
301
+ kind: "string",
302
+ optional: true,
303
+ hosts: ["mcp"],
304
+ description: "Absolute folder a 'claude-code' run works in, e.g. a worktree '/work/app/.worktrees/fix-login'. This session's project folder keeps the run in a copy of this session; another folder runs fresh there, told where the task came from. Rejected: '/', the home folder, a folder another user owns, home dot folders, ~/Library and .git folders. Omit to run in the session's project folder, or a temporary folder without a session.",
305
+ },
306
+ {
307
+ name: "permission_profile",
308
+ kind: "enum",
309
+ values: ["read", "web", "none"],
310
+ optional: true,
311
+ hosts: ["mcp"],
312
+ description: "Tool set of a 'claude-code' run: 'read' is Read, Grep and Glob in its folder; 'web' is WebSearch and WebFetch in a fresh temporary folder (no cwd); 'none' is no tools. Runs never get Bash, Write or Edit. Defaults to 'read' when cwd is given; omit both for tools or its default. Rejected when tools names another set.",
313
+ },
314
+ {
315
+ name: "result_path",
316
+ kind: "string",
317
+ optional: true,
318
+ hosts: ["mcp"],
319
+ description: "Absolute path of a new file, e.g. '/tmp/review.md'. When the task completes, Tidegap (never the run) writes the result text there with mode 0600, and the session's notice names it. It must be inside cwd, this session's project folder or the temp folder; rejected: an existing file, a name starting with '.', ~/.ssh, ~/.config, ~/Library and similar folders. Omit to keep the result in the queue only (check_queue_status).",
320
+ },
321
+ {
322
+ name: "wake_session",
323
+ kind: "boolean",
324
+ optional: true,
325
+ hosts: ["mcp"],
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.",
327
+ },
224
328
  {
225
329
  name: "dry_run",
226
330
  kind: "boolean",
227
331
  optional: true,
228
332
  hosts: ["mcp"],
229
- description: "If true, return the planned dispatch (recommended window + carbon estimate) WITHOUT persisting anything. Useful for confirmation flows.",
333
+ description: "true previews the plan (window, carbon estimate, provider, model, runs_in) and queues nothing, e.g. to confirm with the user first. Defaults to false.",
230
334
  },
231
335
  {
232
336
  name: "dispatch",
233
337
  kind: "boolean",
234
338
  optional: true,
235
339
  hosts: ["mcp"],
236
- description: "If true (default), persist a provider_call task body that `tidegap tick` (CLI) or scheduler.tick (library) can dispatch. Set to false only to enqueue a placeholder prompt without a dispatchable body (legacy in-memory mode).",
340
+ description: "Defaults to true: store a task that `tidegap tick` runs. false queues an in-memory placeholder that never calls a model (tests only) and cannot combine with not_before or after_limit_reset. Omit it in normal use.",
237
341
  },
238
342
  {
239
343
  name: "output_path",
240
344
  kind: "string",
241
345
  optional: true,
242
346
  hosts: ["mcp"],
243
- description: "Optional absolute file path. When the task completes, Tidegap writes { taskId, result, receipt } as JSON to this path.",
347
+ description: "Absolute file path inside cwd, this session's project folder or the temp folder, e.g. '/tmp/digest.json'; when the task completes, { taskId, result, receipt } is written there as JSON, replacing a regular file you own. Its folder must exist; a name starting with '.', ~/.ssh, ~/.config, ~/Library and similar folders are rejected. Omit to keep the result only in the queue (check_queue_status).",
244
348
  },
245
349
  {
246
350
  name: "redact_in_receipt",
@@ -248,14 +352,14 @@ export const TOOL_SURFACE = [
248
352
  itemKind: "string",
249
353
  optional: true,
250
354
  hosts: ["mcp"],
251
- description: "Optional regex patterns to strip from the prompt before storing it on the receipt. Omit to use the default redaction of API-key-looking strings.",
355
+ description: "Regex patterns removed from the prompt before it is stored on the receipt, e.g. ['customer-[0-9]+'] for customer ids. Omit for the default, which strips API-key-looking strings.",
252
356
  },
253
357
  {
254
358
  name: "title",
255
359
  kind: "string",
256
360
  optional: true,
257
361
  hosts: ["mcp"],
258
- description: "Optional short title for the task (shown in queue lists). Defaults to the first line of the prompt, cut to 80 characters. API-key-looking strings are redacted.",
362
+ description: "Short label for queue lists, e.g. 'Weekly digest'. Defaults to the prompt's first line, cut to 80 characters; API-key-looking strings are redacted.",
259
363
  },
260
364
  {
261
365
  name: "deadline_kind",
@@ -263,29 +367,106 @@ export const TOOL_SURFACE = [
263
367
  values: ["absolute", "quota_reset"],
264
368
  optional: true,
265
369
  hosts: ["mcp"],
266
- description: "How the deadline is chosen. 'absolute' (default): use 'deadline'. 'quota_reset': run before the next weekly subscription-quota reset, minus a safety margin, as configured in ~/.tidegap/config (TIDEGAP_QUOTA_RESET_<LABEL>=<weekday> <HH:MM> [<IANA zone>], optional TIDEGAP_QUOTA_MARGIN_H_<LABEL>=<hours>, default 2). Use it when the user says 'before my weekly limit resets' or similar. A deadline more than 24 hours away can route the task through the provider Batch API.",
370
+ description: "Defaults to 'absolute': the deadline parameter sets the due time. 'quota_reset' sets it to the next weekly subscription-quota reset minus a margin, from ~/.tidegap/config (TIDEGAP_QUOTA_RESET_<LABEL>=<weekday> <HH:MM> [<IANA zone>]; margin TIDEGAP_QUOTA_MARGIN_H_<LABEL>, default 2 hours). Use it when the user says \"before my weekly limit resets\". A due time more than 24 hours away can use the provider Batch API.",
267
371
  },
268
372
  {
269
373
  name: "quota_provider",
270
374
  kind: "string",
271
375
  optional: true,
272
376
  hosts: ["mcp"],
273
- description: "Quota label for deadline_kind 'quota_reset' (e.g. 'claude', 'codex'). Optional when exactly one label is configured.",
377
+ description: "Which configured quota to follow with deadline_kind 'quota_reset', e.g. 'claude' or 'codex'. Omit when exactly one label is configured; rejected with any other deadline_kind.",
274
378
  },
275
379
  {
276
380
  name: "repeat",
277
381
  kind: "enum",
278
- values: ["none", "daily", "weekly", "quota_reset"],
382
+ values: ["none", "daily", "weekdays", "weekly", "every_n_hours", "quota_reset"],
279
383
  optional: true,
280
384
  hosts: ["mcp"],
281
- description: "Repeat rule. Defaults to 'none' (a one-off), also for deadline_kind 'quota_reset'; pass 'weekly' (or 'daily') to repeat. 'quota_reset' follows the weekly quota reset and needs deadline_kind 'quota_reset'. When an occurrence finishes (or is cancelled as a skip), the next one is queued automatically with the same prompt; each occurrence costs one provider call. Stop the series with cancel_task series=true.",
385
+ description: "Defaults to 'none', a one-off. 'daily', 'weekdays', 'weekly' and 'every_n_hours' create a job: each run is a new task with this prompt, started fresh (never a copy of this session) in this project at the cleanest hour of its period, e.g. \"every night\" is 'daily' with window '22:00-08:00'. A job rejects per-task options (region, carbon_budget_g, candidates, not_before, dry_run and the like). With deadline_kind 'quota_reset', 'daily', 'weekly' and 'quota_reset' start the older series instead, which follows the quota reset; 'weekdays' and 'every_n_hours' are rejected there. End a job or series with cancel_task series=true.",
386
+ },
387
+ {
388
+ name: "repeat",
389
+ kind: "enum",
390
+ values: ["none", "daily", "weekdays", "weekly", "every_n_hours"],
391
+ optional: true,
392
+ hosts: ["openclaw"],
393
+ description: "Defaults to 'none', a one-off. 'daily', 'weekdays', 'weekly' and 'every_n_hours' create a job: each run is a new task with this prompt at the cleanest hour of its period, e.g. \"every night\" is 'daily' with window '22:00-08:00'; deadline then bounds only the first run. A job rejects per-task options (region, carbon_budget_g, candidates, route_weights, deliver, webhook_url, file_path, file_format). End the job with cancel_task series=true.",
394
+ },
395
+ {
396
+ name: "every_hours",
397
+ kind: "number",
398
+ integer: true,
399
+ min: 2,
400
+ max: 168,
401
+ optional: true,
402
+ description: "Hours between runs for repeat 'every_n_hours', e.g. 6 for \"every 6 hours\". Each run comes at most this long after the previous start and not sooner than half of it. Required with 'every_n_hours'; omit for any other repeat.",
403
+ },
404
+ {
405
+ name: "days",
406
+ kind: "array",
407
+ itemKind: "enum",
408
+ values: ["mon", "tue", "wed", "thu", "fri", "sat", "sun"],
409
+ optional: true,
410
+ description: "Weekdays for repeat 'weekly', e.g. ['mon','thu'] for \"Mondays and Thursdays\". Defaults to today's weekday in time_zone; omit for any other repeat.",
411
+ },
412
+ {
413
+ name: "window",
414
+ kind: "string",
415
+ optional: true,
416
+ description: "Local hours a job may run in, 'HH:MM-HH:MM', e.g. '22:00-08:00' for \"at night\"; '22:00-06:00' crosses midnight. Each run then picks its cleanest hour inside that day's window. Only with repeat 'daily', 'weekdays' or 'weekly'; omit to allow any hour.",
417
+ },
418
+ {
419
+ name: "time_zone",
420
+ kind: "string",
421
+ optional: true,
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.",
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}.`,
282
448
  },
283
449
  {
284
450
  name: "origin_session_id",
285
451
  kind: "string",
286
452
  optional: true,
287
453
  hosts: ["mcp"],
288
- description: "Claude Code session id of the conversation that queued the task, so the task detail can show `claude --resume <id>`. Pass it only when the host substitutes it (e.g. ${CLAUDE_SESSION_ID} in a slash command); values that are not 8-128 letters, digits, '-' or '_' are ignored.",
454
+ description: "Claude Code session id of the conversation that queued the task. Omit it: the server finds the current session itself when the Tidegap plugin is installed. Pass it only when the host substitutes it (e.g. ${CLAUDE_SESSION_ID} in a slash command); it then wins. Values that are not 8-128 letters, digits, '-' or '_' are ignored.",
455
+ },
456
+ {
457
+ name: "after_limit_reset",
458
+ kind: "boolean",
459
+ optional: true,
460
+ hosts: ["mcp"],
461
+ description: "true when the user says \"after my limit resets\": the task starts no earlier than the Claude subscription limit reset (the latest reset of an exhausted 5-hour or weekly window, else the fuller window's reset; see tidegap_usage), then runs at the cleanest hour after it. The deadline rises to at least two hours after the reset. Fails, queuing nothing, when no limit reading exists. Defaults to false; cannot combine with not_before.",
462
+ },
463
+ {
464
+ name: "not_before",
465
+ kind: "string",
466
+ format: "date-time",
467
+ optional: true,
468
+ hosts: ["mcp"],
469
+ description: "Earliest start, ISO-8601 with offset, e.g. '2026-05-12T18:00:00+02:00' for \"not before 6pm\" or \"after lunch\". The task then runs at the cleanest hour between it and the deadline; it must be in the future and not after the deadline. It is a bound, not a run time: with not_before 70 minutes away and a 3-hour deadline, the task can run near the end. Omit to allow any time up to the deadline; cannot combine with after_limit_reset.",
289
470
  },
290
471
  // ── OpenClaw-only parameters (result delivery) ──
291
472
  deliverParam(true),
@@ -297,81 +478,213 @@ export const TOOL_SURFACE = [
297
478
  {
298
479
  name: "check_queue_status",
299
480
  hosts: ["mcp", "openclaw"],
300
- description: "Report on the Tidegap task queue. With no arguments, returns a summary of all known tasks (including tasks persisted by previous sessions — the queue survives host restarts). With task_id, returns full detail for one task, including its title, prompt, result and any carbon receipt (estimated vs actual grams, grid_source, energy_source); viewing a completed or failed task marks it read. Never changes a task's status.",
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.",
482
+ descriptionPerHost: {
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.",
484
+ },
485
+ annotations: {
486
+ title: "Show task queue",
487
+ readOnlyHint: false,
488
+ destructiveHint: false,
489
+ idempotentHint: true,
490
+ openWorldHint: false,
491
+ },
301
492
  params: [
302
493
  {
303
494
  name: "task_id",
304
495
  kind: "string",
305
496
  optional: true,
306
- description: "If present, return only this task. If omitted, return a queue summary.",
497
+ description: "One task's id, e.g. 't-3f2a…', from schedule_task or this tool's summary, to get its full record. Omit for the summary of all tasks.",
498
+ },
499
+ ],
500
+ },
501
+ {
502
+ name: "tidegap_usage",
503
+ hosts: ["mcp"],
504
+ description: "Report this machine's Claude Code limits: 5-hour and weekly percent used, reset times, and Codex limits if present. Use when: the user asks how much quota is left, or before heavy Claude Code work; at 90% or more, pass after_limit_reset to schedule_task. Do not use for task state (use check_queue_status). Behavior: reads the statusline reading, no API key; TIDEGAP_USAGE_OAUTH=1 calls the usage endpoint with the Claude Code login and caches it in ~/.tidegap/usage.json; never writes tasks or settings. Returns: a summary line and the usage/v1 JSON (windows, reading age, after_limit_reset wait).",
505
+ annotations: {
506
+ title: "Claude usage limits",
507
+ readOnlyHint: false,
508
+ destructiveHint: false,
509
+ idempotentHint: true,
510
+ openWorldHint: true,
511
+ },
512
+ params: [
513
+ {
514
+ name: "include_spend",
515
+ kind: "boolean",
516
+ optional: true,
517
+ description: "true adds claude_spend: tokens and an API list-price cost estimate for the current 5-hour window from the local Claude Code logs (total, by model, the five latest sessions), plus the tokens of recent Codex sessions. Use it when the user asks what their usage would cost; the scan takes a few seconds. Defaults to false.",
307
518
  },
308
519
  ],
309
520
  },
310
521
  {
311
522
  name: "cancel_task",
312
523
  hosts: ["mcp", "openclaw"],
313
- description: "Cancel a queued or scheduled task. Idempotent — if the task is already completed/failed/cancelled this returns the existing status without error. Throws only if task_id is unknown. Cancelling one occurrence of a repeating task skips it and queues the next one; pass series=true to end the series.",
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.",
525
+ descriptionPerHost: {
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.",
527
+ },
528
+ annotations: {
529
+ title: "Cancel one task",
530
+ readOnlyHint: false,
531
+ destructiveHint: true,
532
+ idempotentHint: true,
533
+ openWorldHint: false,
534
+ },
314
535
  params: [
315
- { ...taskIdRequired, description: "The id of the task to cancel." },
536
+ { ...taskIdRequired, description: "Id of the task to cancel, e.g. 't-3f2a…', from the schedule_task reply or the check_queue_status list." },
316
537
  {
317
538
  name: "series",
318
539
  kind: "boolean",
319
540
  optional: true,
320
- description: "If true and the task repeats, also end its series: no further occurrence is queued. Default false (skip only this occurrence).",
541
+ description: "true also ends the job or series this task is a run of, so no further run is queued; use it for \"stop this for good\". Defaults to false: skip only this run; a job then plans its next one. No effect on a one-off task.",
321
542
  },
322
543
  ],
323
544
  },
324
545
  {
325
546
  name: "expedite_task",
326
547
  hosts: ["mcp", "openclaw"],
327
- description: "Dispatch a queued or scheduled provider-call task immediately, bypassing the scheduler's chosen carbon window. The resulting receipt records intensitySource='expedited'. Only provider-call tasks still queued/scheduled can be expedited; running, submitted (awaiting Batch API results), or terminal (completed/failed/cancelled) tasks are rejected with an explanatory error.",
328
- params: [{ ...taskIdRequired, description: "The id of the task to dispatch now." }],
548
+ description: "Run one queued or scheduled task now, skipping its clean window. Use when: the user wants the result now. Do not use for a failed task (use retry_task), to pick a new deadline (use update_deadline), or for a claude-code task (run `tidegap queue run-now <id>`). Behavior: drops its earliest start and makes one provider call at the current grid intensity; needs the task provider's key in the server env (and ANTHROPIC_API_KEY or OPENAI_API_KEY); the receipt records intensitySource=expedited. Returns: status and error on failure. Rejects running, submitted, finished and unknown tasks.",
549
+ descriptionPerHost: {
550
+ openclaw: "Run one queued or scheduled task now, skipping its clean-grid window. Use when: the user wants the result now (\"do it now\", \"don't wait\"). Do not use for a failed task (use retry_task) or to pick a new deadline (use update_deadline). Behavior: drops its earliest start and makes one provider call at the current grid intensity, through the OpenClaw runtime or a provider key in the plugin config, then delivers the result; the receipt records intensitySource=expedited. Returns: status, error on failure, result, receipt and delivery. Throws on running, submitted, finished and unknown tasks.",
551
+ },
552
+ annotations: {
553
+ title: "Run task now",
554
+ readOnlyHint: false,
555
+ destructiveHint: false,
556
+ idempotentHint: false,
557
+ openWorldHint: true,
558
+ },
559
+ params: [{ ...taskIdRequired, description: "Id of the queued or scheduled task to run now, e.g. 't-3f2a…', from the schedule_task reply or the check_queue_status list." }],
329
560
  },
330
561
  {
331
562
  name: "update_deadline",
332
563
  hosts: ["mcp", "openclaw"],
333
- description: "Re-score and reschedule a queued or scheduled task against a new deadline; the scheduler re-picks the cleanest window inside it. Throws if the task is already running or terminal, or if the new deadline is invalid or in the past.",
564
+ description: "Change the deadline of one queued or scheduled task and re-pick its cleanest window inside it. Use when: the user moves the due time, earlier or later (\"by 6pm instead\"). Do not use to delay the start inside the same deadline (use postpone_task), to run now (use expedite_task) or to stop it (use cancel_task). Behavior: rewrites only this task in the local queue, clears its earliest start and quota rule, re-reads the grid forecast; no login. A repeat call only re-picks the hour. Returns: status, scheduled_for, new_deadline. Rejects running, finished or unknown tasks and a past deadline.",
565
+ descriptionPerHost: {
566
+ openclaw: "Change the deadline of one queued or scheduled task and re-pick its cleanest window inside it. Use when: the user moves the due time, earlier or later (\"by 6pm instead\"). Do not use to run now (use expedite_task) or to stop it (use cancel_task). Behavior: rewrites only this task in the local queue, clears its quota rule and re-reads the grid forecast; no login or key. A repeat call only re-picks the hour. Returns: task_id, status, scheduled_for, new_deadline. Throws on running, finished or unknown tasks and a past deadline.",
567
+ },
568
+ annotations: {
569
+ title: "Change task deadline",
570
+ readOnlyHint: false,
571
+ destructiveHint: false,
572
+ idempotentHint: true,
573
+ openWorldHint: true,
574
+ },
334
575
  params: [
335
- { ...taskIdRequired, description: "The id of the task to reschedule." },
336
- { ...deadlineParam, description: "New ISO-8601 deadline. Must be in the future." },
576
+ { ...taskIdRequired, description: "Id of the queued or scheduled task to move, e.g. 't-3f2a…', from the schedule_task reply or the check_queue_status list." },
577
+ { ...deadlineParam, description: "The new due time, ISO-8601 with offset, earlier or later than the current one and in the future, e.g. '2026-05-12T18:00:00+02:00' for \"by 6pm instead\"." },
578
+ ],
579
+ },
580
+ {
581
+ name: "postpone_task",
582
+ hosts: ["mcp"],
583
+ description: "Move one queued or scheduled task later; it never runs earlier than planned. Use when: the user says \"tonight\" or \"after my limit resets\"; pass exactly one of preset, until or delay_minutes. Do not use to set a new due time (use update_deadline) or to stop it (use cancel_task). Behavior: rewrites this task's earliest start in the local queue and re-picks the cleanest hour after it, but an until time is kept exactly; after_limit_reset reads the Claude limits. Returns: status, not_before, scheduled_for, deadline. Rejects a target at or before the planned start, finished and unknown tasks.",
584
+ annotations: {
585
+ title: "Postpone task",
586
+ readOnlyHint: false,
587
+ destructiveHint: false,
588
+ idempotentHint: false,
589
+ openWorldHint: true,
590
+ },
591
+ params: [
592
+ { ...taskIdRequired, description: "Id of the queued or scheduled task to move later, e.g. 't-3f2a…', from the schedule_task reply or the check_queue_status list." },
593
+ {
594
+ name: "preset",
595
+ kind: "enum",
596
+ values: ["1h", "tonight", "tomorrow_morning", "after_limit_reset"],
597
+ optional: true,
598
+ description: "A named later time, in this machine's local time: '1h' is one hour after the planned start; 'tonight' is 22:00 to 06:00 (after midnight: now to 06:00); 'tomorrow_morning' is 09:00 to 12:00 tomorrow; 'after_limit_reset' is 5 minutes after the Claude limit reset (needs reset_at, this machine's limit reading or a reset time given before). Omit when passing until or delay_minutes.",
599
+ },
600
+ {
601
+ name: "until",
602
+ kind: "string",
603
+ format: "date-time",
604
+ optional: true,
605
+ description: "The exact time the user picked, ISO-8601 with offset, after the planned start, e.g. '2026-05-12T21:30:00+02:00'. Omit when passing preset or delay_minutes.",
606
+ },
607
+ {
608
+ name: "delay_minutes",
609
+ kind: "number",
610
+ integer: true,
611
+ min: 1,
612
+ max: 10080,
613
+ optional: true,
614
+ description: "Minutes to add to the planned start, e.g. 90 for \"an hour and a half later\"; at most 10080 (7 days). Omit when passing preset or until.",
615
+ },
616
+ {
617
+ name: "reset_at",
618
+ kind: "string",
619
+ format: "date-time",
620
+ optional: true,
621
+ description: "When the Claude limit resets, ISO-8601 with offset, if the user says it (\"my limit resets at 15:00\"). Only with preset 'after_limit_reset'; must be in the future and is remembered for later tasks. Omit to use this machine's limit reading.",
622
+ },
337
623
  ],
338
624
  },
339
625
  {
340
626
  name: "reply_task",
341
627
  hosts: ["mcp", "openclaw"],
342
- description: "Continue a completed task's conversation: creates a NEW task that sends the earlier prompt, the model's reply and this text to the same provider and model, and runs at the next clean window before its deadline (default one hour). Costs one provider call. Only completed tasks accept a reply; failed or cancelled tasks are rejected. Returns the new task id and its scheduled time.",
628
+ description: "Send a follow-up message in a completed task's conversation, as a new queued task. Use when: the user follows up on a finished task's result. Do not use for a failed task (use retry_task) or for an unrelated new task (use schedule_task). Behavior: each call adds one task to the local queue with earlier turns as history, the same provider and model, and its own clean window; no login now; it runs later as one provider call with the original's credentials. Returns: task_id, parent_task_id, status, scheduled_for, deadline. Rejects non-completed and unknown tasks and text over 32000 characters.",
629
+ annotations: {
630
+ title: "Reply to a completed task",
631
+ readOnlyHint: false,
632
+ destructiveHint: false,
633
+ idempotentHint: false,
634
+ openWorldHint: true,
635
+ },
343
636
  params: [
344
- { ...taskIdRequired, description: "The id of the completed task to reply to." },
637
+ { ...taskIdRequired, description: "Id of the completed task to continue, e.g. 't-3f2a…', from the check_queue_status list (status completed)." },
345
638
  {
346
639
  name: "text",
347
640
  kind: "string",
348
641
  minLength: 1,
349
- description: "The follow-up message (1 to 32000 characters).",
642
+ description: "The user's follow-up, sent as the next turn after the task's earlier reply, e.g. 'Now cut it to 3 bullets'. Up to 32000 characters.",
350
643
  },
351
644
  {
352
645
  ...deadlineParam,
353
646
  optional: true,
354
- description: "Optional ISO-8601 deadline for the reply. Defaults to one hour from now.",
647
+ description: "When the reply must be finished, ISO-8601 with offset, e.g. '2026-05-12T20:00:00Z'. Defaults to one hour from now.",
355
648
  },
356
649
  ],
357
650
  },
358
651
  {
359
652
  name: "retry_task",
360
653
  hosts: ["mcp", "openclaw"],
361
- description: "Re-dispatch a failed provider-call task. Only valid when the task's current status is 'failed' — queued/scheduled/running/submitted/completed tasks are rejected with an explanatory error. The new run's receipt overwrites the old.",
362
- params: [{ ...taskIdRequired, description: "The id of the failed task to retry." }],
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.",
655
+ descriptionPerHost: {
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.",
657
+ },
658
+ annotations: {
659
+ title: "Retry a failed task",
660
+ readOnlyHint: false,
661
+ destructiveHint: true,
662
+ idempotentHint: false,
663
+ openWorldHint: true,
664
+ },
665
+ params: [{ ...taskIdRequired, description: "Id of the failed task to run again, e.g. 't-3f2a…', from the check_queue_status list (status failed)." }],
363
666
  },
364
667
  {
365
668
  name: "cancel_all",
366
669
  hosts: ["mcp", "openclaw"],
367
- description: "Bulk-cancel every task in the queue that is still cancellable (status queued or scheduled). Running/completed/failed/cancelled tasks are left untouched. Optionally filter by status. Returns the number of tasks cancelled.",
670
+ description: "Cancel every queued and scheduled task in the local queue at once; for a single task use cancel_task. Use when: the user says \"cancel everything\" or \"clear the queue\". Do not use to drop one task or to end a repeating series (use cancel_task, with series=true for a series). Behavior: marks each pending task cancelled; running, submitted and finished tasks stay as they are; no network or login. A repeating task skips this occurrence and its next one is queued, so a second call cancels that one too. Returns: \"Cancelled N of M task(s).\" and one error line per task that could not be cancelled.",
671
+ descriptionPerHost: {
672
+ openclaw: "Cancel every queued and scheduled task in the local queue at once; for a single task use cancel_task. Use when: the user says \"cancel everything\" or \"clear the queue\". Do not use to drop one task or to end a repeating series (use cancel_task, with series=true for a series). Behavior: marks each pending task cancelled; running, submitted and finished tasks stay as they are; no network or login. A repeating task skips this occurrence and its next one is queued, so a second call cancels that one too. Returns: matched, cancelled, and errors (task_id and error per task that could not be cancelled).",
673
+ },
674
+ annotations: {
675
+ title: "Cancel all pending tasks",
676
+ readOnlyHint: false,
677
+ destructiveHint: true,
678
+ idempotentHint: false,
679
+ openWorldHint: false,
680
+ },
368
681
  params: [
369
682
  {
370
683
  name: "status",
371
684
  kind: "enum",
372
685
  values: ["queued", "scheduled"],
373
686
  optional: true,
374
- description: "Optional. If set, cancel only tasks in this status. Valid: 'queued', 'scheduled'. Defaults to both.",
687
+ description: "Cancel only tasks in one state: 'queued' (no window picked yet) or 'scheduled' (window picked). Omit to cancel both.",
375
688
  },
376
689
  ],
377
690
  },
@@ -379,10 +692,10 @@ export const TOOL_SURFACE = [
379
692
  // OpenClaw-only: the MCP server has no result-delivery subsystem.
380
693
  name: "set_delivery",
381
694
  hosts: ["openclaw"],
382
- description: "Set or change how a scheduled task's result is delivered when it completes. Call this right after schedule_task, once you have ASKED the user how they want the result. The user may pick several modes. Modes: chat (their active OpenClaw chat), telegram, webhook (needs webhook_url), file (needs file_path; format md/html/txt/json/pdf), queue (no push — retrievable via check_queue_status), os (a native desktop notification on the gateway host). PRIVACY BOUNDARY — queue is the only mode that transmits nothing (the result stays in the local ledger; read it back with check_queue_status). chat delivers through the gateway's configured chat channel, which on a Telegram-backed gateway is the SAME Telegram Bot API path as the telegram mode — do not describe chat to the user as staying inside OpenClaw. telegram sends the FULL result to a third-party service, webhook POSTs the FULL result to whatever URL is supplied (Tidegap does not restrict or inspect that destination), and file writes it to any path on the gateway host. Never pick telegram, webhook or file on the user's behalf: confirm the destination with them first, and for sensitive tasks prefer queue. Default if the user is unsure: chat.",
695
+ description: "Set how a scheduled task's result is delivered when it completes; several modes allowed. Use when: right after schedule_task, once the user has chosen. Do not use to read a result (use check_queue_status). Behavior: saves the setting locally, without checking the task exists; sends nothing now. queue transmits nothing; chat may route through Telegram; telegram, webhook and file send or write the FULL result, so confirm those destinations first. Default: chat. Returns: task_id and the saved delivery. Throws on a missing webhook_url or file_path.",
383
696
  params: [
384
- { ...taskIdRequired, description: "The id returned by schedule_task." },
385
- { ...deliverParam(false), description: "One or more delivery modes the user chose." },
697
+ { ...taskIdRequired, description: "Id of the task, e.g. 't-3f2a…', from the schedule_task reply or the check_queue_status list." },
698
+ { ...deliverParam(false), description: "The modes the user chose, e.g. ['telegram'] or ['chat','file']. webhook needs webhook_url; file needs file_path. Confirm telegram, webhook and file destinations with the user first." },
386
699
  webhookUrlParam,
387
700
  filePathParam,
388
701
  fileFormatParam,
@@ -402,10 +715,21 @@ export function getToolDefOrThrow(name) {
402
715
  throw new Error(`unknown Tidegap tool: ${name}`);
403
716
  return def;
404
717
  }
405
- /** The tools a given host registers, in canonical order. */
718
+ /** A tool's description as one host shows it (its override, else the base). */
719
+ export function descriptionForHost(def, host) {
720
+ return def.descriptionPerHost?.[host] ?? def.description;
721
+ }
722
+ /** The tools a given host registers, in canonical order, each carrying the
723
+ * description resolved for that host. */
406
724
  export function toolsForHost(host) {
407
- return TOOL_SURFACE.filter((t) => t.hosts.includes(host));
725
+ return TOOL_SURFACE.filter((t) => t.hosts.includes(host)).map((t) => ({
726
+ ...t,
727
+ description: descriptionForHost(t, host),
728
+ }));
408
729
  }
730
+ /** Tool counts per host; the site derives its "N tools" copy from these. */
731
+ export const MCP_TOOL_COUNT = toolsForHost("mcp").length;
732
+ export const OPENCLAW_TOOL_COUNT = toolsForHost("openclaw").length;
409
733
  /** Which hosts expose a given parameter (defaults to the tool's hosts). */
410
734
  export function paramHosts(param, def) {
411
735
  return param.hosts ?? def.hosts;
@@ -443,6 +767,7 @@ export function neutralSurfaceForHost(host) {
443
767
  return toolsForHost(host).map((def) => ({
444
768
  name: def.name,
445
769
  description: def.description,
770
+ ...(def.annotations ? { annotations: def.annotations } : {}),
446
771
  params: paramsForHost(def, host).map((p) => neutralParam(p, host)),
447
772
  }));
448
773
  }