@tidegap/core 0.18.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 (171) hide show
  1. package/README.md +3 -1
  2. package/dist/agent-snippet.d.ts +30 -0
  3. package/dist/agent-snippet.js +120 -0
  4. package/dist/budget.d.ts +0 -12
  5. package/dist/budget.js +2 -24
  6. package/dist/channels/commands.d.ts +137 -0
  7. package/dist/channels/commands.js +377 -0
  8. package/dist/channels/delivery-codes.d.ts +9 -0
  9. package/dist/channels/delivery-codes.js +53 -0
  10. package/dist/channels/digest.d.ts +102 -0
  11. package/dist/channels/digest.js +146 -0
  12. package/dist/channels/format.d.ts +127 -0
  13. package/dist/channels/format.js +407 -0
  14. package/dist/channels/index.d.ts +15 -0
  15. package/dist/channels/index.js +15 -0
  16. package/dist/channels/kinds/command.d.ts +13 -0
  17. package/dist/channels/kinds/command.js +65 -0
  18. package/dist/channels/kinds/discord.d.ts +16 -0
  19. package/dist/channels/kinds/discord.js +67 -0
  20. package/dist/channels/kinds/email.d.ts +20 -0
  21. package/dist/channels/kinds/email.js +162 -0
  22. package/dist/channels/kinds/index.d.ts +8 -0
  23. package/dist/channels/kinds/index.js +17 -0
  24. package/dist/channels/kinds/ntfy.d.ts +25 -0
  25. package/dist/channels/kinds/ntfy.js +163 -0
  26. package/dist/channels/kinds/pushover.d.ts +11 -0
  27. package/dist/channels/kinds/pushover.js +77 -0
  28. package/dist/channels/kinds/shared.d.ts +25 -0
  29. package/dist/channels/kinds/shared.js +39 -0
  30. package/dist/channels/kinds/shortcuts.d.ts +9 -0
  31. package/dist/channels/kinds/shortcuts.js +45 -0
  32. package/dist/channels/kinds/slack.d.ts +8 -0
  33. package/dist/channels/kinds/slack.js +57 -0
  34. package/dist/channels/kinds/telegram.d.ts +4 -0
  35. package/dist/channels/kinds/telegram.js +26 -0
  36. package/dist/channels/kinds/webhook.d.ts +30 -0
  37. package/dist/channels/kinds/webhook.js +177 -0
  38. package/dist/channels/payload.d.ts +36 -0
  39. package/dist/channels/payload.js +61 -0
  40. package/dist/channels/plan.d.ts +24 -0
  41. package/dist/channels/plan.js +66 -0
  42. package/dist/channels/registry.d.ts +191 -0
  43. package/dist/channels/registry.js +125 -0
  44. package/dist/channels/telegram.d.ts +110 -0
  45. package/dist/channels/telegram.js +168 -0
  46. package/dist/channels/types.d.ts +107 -0
  47. package/dist/channels/types.js +26 -0
  48. package/dist/claude-tools.d.ts +29 -0
  49. package/dist/claude-tools.js +49 -0
  50. package/dist/data/tables.generated.d.ts +6 -0
  51. package/dist/data/tables.generated.js +37 -0
  52. package/dist/energy.d.ts +77 -0
  53. package/dist/energy.js +131 -0
  54. package/dist/grid.d.ts +19 -2
  55. package/dist/grid.js +84 -28
  56. package/dist/handoff.d.ts +152 -0
  57. package/dist/handoff.js +430 -0
  58. package/dist/history.d.ts +2 -0
  59. package/dist/history.js +3 -1
  60. package/dist/index.d.ts +46 -16
  61. package/dist/index.js +34 -8
  62. package/dist/job-cadence.d.ts +76 -0
  63. package/dist/job-cadence.js +240 -0
  64. package/dist/jobs.d.ts +173 -0
  65. package/dist/jobs.js +794 -0
  66. package/dist/notify.d.ts +2 -0
  67. package/dist/notify.js +2 -1
  68. package/dist/paths.d.ts +13 -46
  69. package/dist/paths.js +51 -219
  70. package/dist/postpone.d.ts +113 -0
  71. package/dist/postpone.js +185 -0
  72. package/dist/providers/anthropic.js +7 -3
  73. package/dist/providers/base.d.ts +113 -1
  74. package/dist/providers/base.js +15 -0
  75. package/dist/providers/budget.d.ts +25 -0
  76. package/dist/providers/budget.js +57 -0
  77. package/dist/providers/defaults.js +4 -0
  78. package/dist/providers/defer.d.ts +16 -0
  79. package/dist/providers/defer.js +31 -0
  80. package/dist/providers/gemini.d.ts +1 -0
  81. package/dist/providers/gemini.js +27 -20
  82. package/dist/providers/index.d.ts +2 -2
  83. package/dist/providers/index.js +1 -1
  84. package/dist/providers/ollama.d.ts +1 -0
  85. package/dist/providers/ollama.js +26 -22
  86. package/dist/providers/openai.js +5 -5
  87. package/dist/providers/timeout.d.ts +18 -0
  88. package/dist/providers/timeout.js +33 -0
  89. package/dist/quota.d.ts +7 -2
  90. package/dist/quota.js +13 -29
  91. package/dist/readiness.d.ts +169 -0
  92. package/dist/readiness.js +254 -0
  93. package/dist/redact.d.ts +42 -0
  94. package/dist/redact.js +110 -0
  95. package/dist/region-host.d.ts +30 -0
  96. package/dist/region-host.js +69 -0
  97. package/dist/region.d.ts +102 -20
  98. package/dist/region.js +175 -23
  99. package/dist/run-session.d.ts +36 -0
  100. package/dist/run-session.js +72 -0
  101. package/dist/schedule-job.d.ts +95 -0
  102. package/dist/schedule-job.js +195 -0
  103. package/dist/scheduler.d.ts +245 -14
  104. package/dist/scheduler.js +925 -110
  105. package/dist/sign.d.ts +8 -1
  106. package/dist/sign.js +49 -3
  107. package/dist/storage/sqlite.d.ts +157 -5
  108. package/dist/storage/sqlite.js +661 -20
  109. package/dist/task-events.d.ts +102 -0
  110. package/dist/task-events.js +308 -0
  111. package/dist/tool-surface.d.ts +31 -2
  112. package/dist/tool-surface.js +359 -65
  113. package/dist/types.d.ts +246 -3
  114. package/dist/types.js +8 -1
  115. package/dist/zone-time.d.ts +22 -0
  116. package/dist/zone-time.js +76 -0
  117. package/package.json +11 -6
  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
package/dist/grid.js CHANGED
@@ -24,6 +24,15 @@
24
24
  * auditor, from credential harvesting.
25
25
  */
26
26
  import { BAND_THRESHOLDS, DEFAULT_BAND, DEFAULT_REGION_FLOOR, REGION_FLOORS, REGION_UTC_OFFSETS, SYNTHETIC_AMPLITUDE, } from "./data/tables.generated.js";
27
+ /**
28
+ * Floor a date to the top of its UTC hour. A local-time floor lands an hour
29
+ * early in a DST fall-back hour and on :30 in a half-hour zone.
30
+ */
31
+ function floorToUtcHour(d) {
32
+ const out = new Date(d.getTime());
33
+ out.setUTCMinutes(0, 0, 0);
34
+ return out;
35
+ }
27
36
  function classify(g) {
28
37
  for (const t of BAND_THRESHOLDS) {
29
38
  if (g < t.maxExclusive)
@@ -71,8 +80,7 @@ export function mockGridFeed(clock) {
71
80
  source: "mock",
72
81
  async fetchForecast(region, hours) {
73
82
  const baseNow = clock ? clock() : new Date();
74
- const now = new Date(baseNow.getTime());
75
- now.setMinutes(0, 0, 0);
83
+ const now = floorToUtcHour(baseNow);
76
84
  const entries = [];
77
85
  for (let i = 0; i < hours; i++) {
78
86
  const t = new Date(now.getTime() + i * 60 * 60 * 1000);
@@ -196,9 +204,7 @@ export function ukCarbonIntensityFeed() {
196
204
  return mock.fetchForecast(region, hours);
197
205
  }
198
206
  try {
199
- const now = new Date();
200
- now.setMinutes(0, 0, 0);
201
- now.setSeconds(0, 0);
207
+ const now = floorToUtcHour(new Date());
202
208
  const fetchPage = async (from) => {
203
209
  // API wants YYYY-MM-DDTHH:MMZ (no seconds).
204
210
  const fromStr = `${from.toISOString().slice(0, 16)}Z`;
@@ -367,10 +373,17 @@ const EIA_FUEL_FACTORS = {
367
373
  WAT: EMISSION_FACTORS_G_CO2_PER_KWH.hydro,
368
374
  OTH: EMISSION_FACTORS_G_CO2_PER_KWH.other,
369
375
  };
376
+ /**
377
+ * How far back the EIA request reaches. EIA-930 fuel-type data is published
378
+ * with a lag of up to a day (19h observed on 2026-10-17), and the feed needs
379
+ * all 24 hours-of-day, so the window must be 24h plus the worst lag. A 30h
380
+ * window left 11–15 hours-of-day and sent every US ISO to the mock.
381
+ */
382
+ const EIA_HISTORY_HOURS = 72;
370
383
  /**
371
384
  * Carbon-intensity feed backed by the US Energy Information Administration's
372
- * v2 Open Data API. Returns a synthesized hourly forecast from the last
373
- * 24 hours of realized fuel mix.
385
+ * v2 Open Data API. Returns a synthesized hourly forecast from the most
386
+ * recent 24 hours-of-day of realized fuel mix.
374
387
  *
375
388
  * The key is always passed in by the host (CLI/MCP read `TIDEGAP_EIA_API_KEY`;
376
389
  * the OpenClaw plugin reads `eiaApiKey` from plugin config).
@@ -398,13 +411,10 @@ export function eiaFeed(apiKey) {
398
411
  return mock.fetchForecast(region, hours);
399
412
  }
400
413
  try {
401
- // Pull the last 30 hours so we have a buffer of completed hours.
402
414
  // EIA timestamps are UTC, no offset; the "period" field is "YYYY-MM-DDTHH".
403
415
  const now = new Date();
404
- const endHour = new Date(now);
405
- endHour.setMinutes(0, 0, 0);
406
- endHour.setSeconds(0, 0);
407
- const startHour = new Date(endHour.getTime() - 30 * 60 * 60 * 1000);
416
+ const endHour = floorToUtcHour(now);
417
+ const startHour = new Date(endHour.getTime() - EIA_HISTORY_HOURS * 60 * 60 * 1000);
408
418
  const fmt = (d) => d.toISOString().slice(0, 13); // "YYYY-MM-DDTHH"
409
419
  const params = new URLSearchParams({
410
420
  api_key: key,
@@ -476,9 +486,7 @@ export function eiaFeed(apiKey) {
476
486
  // realized observation whose UTC hour-of-day matches H. This is
477
487
  // phase-correct regardless of EIA's publication lag.
478
488
  const forecast = [];
479
- const startTs = new Date(now);
480
- startTs.setMinutes(0, 0, 0);
481
- startTs.setSeconds(0, 0);
489
+ const startTs = floorToUtcHour(now);
482
490
  for (let i = 0; i < hours; i++) {
483
491
  const t = new Date(startTs.getTime() + i * 60 * 60 * 1000);
484
492
  const g = byHourOfDay.get(t.getUTCHours());
@@ -555,6 +563,27 @@ const ENTSOE_PSR_FACTORS = {
555
563
  B19: EMISSION_FACTORS_G_CO2_PER_KWH.wind_onshore,
556
564
  B20: EMISSION_FACTORS_G_CO2_PER_KWH.other,
557
565
  };
566
+ /**
567
+ * Yields the inner text of each `<tag>…</tag>` in order, pairing every
568
+ * open with the nearest close after it — what `/<tag>([\s\S]*?)<\/tag>/g`
569
+ * matches, in linear time. When one open has no close, no later open has
570
+ * one either, so the scan stops.
571
+ */
572
+ function* blocks(xml, tag) {
573
+ const open = `<${tag}>`;
574
+ const close = `</${tag}>`;
575
+ let from = 0;
576
+ for (;;) {
577
+ const start = xml.indexOf(open, from);
578
+ if (start === -1)
579
+ return;
580
+ const end = xml.indexOf(close, start + open.length);
581
+ if (end === -1)
582
+ return;
583
+ yield xml.slice(start + open.length, end);
584
+ from = end + close.length;
585
+ }
586
+ }
558
587
  /**
559
588
  * Minimal ENTSO-E XML extractor. Returns, for each *generation*
560
589
  * TimeSeries block, the psrType plus every `<Period>` (each with its own
@@ -575,18 +604,17 @@ const ENTSOE_PSR_FACTORS = {
575
604
  * Why regex rather than a real parser: ENTSO-E's response shape is
576
605
  * stable, the fields we read are well-namespaced, and adding a 30KB
577
606
  * XML dep to `@tidegap/core` for one adapter is bad cost-benefit.
607
+ * Blocks are cut by `blocks()`, not by a lazy regex, so unclosed tags in
608
+ * hostile feed text cost linear time.
578
609
  * Exported for parse-level fixture tests.
579
610
  */
580
611
  export function parseEntsoeXml(xml) {
581
612
  if (/<Acknowledgement_MarketDocument[\s>]/.test(xml)) {
582
- const reason = xml.match(/<text>([\s\S]*?)<\/text>/)?.[1]?.trim() ??
583
- "no reason text in document";
613
+ const reason = blocks(xml, "text").next().value?.trim() ?? "no reason text in document";
584
614
  throw new Error(`ENTSO-E returned an Acknowledgement document: ${reason}`);
585
615
  }
586
616
  const out = [];
587
- const tsRe = /<TimeSeries>([\s\S]*?)<\/TimeSeries>/g;
588
- for (const m of xml.matchAll(tsRe)) {
589
- const block = m[1] ?? "";
617
+ for (const block of blocks(xml, "TimeSeries")) {
590
618
  // outBiddingZone_Domain.mRID marks a consumption series (energy
591
619
  // taken OFF the grid, e.g. pumped-storage pumping). Counting it as
592
620
  // generation would systematically drag intensity down.
@@ -596,8 +624,7 @@ export function parseEntsoeXml(xml) {
596
624
  if (!psr)
597
625
  continue;
598
626
  const periods = [];
599
- for (const pm of block.matchAll(/<Period>([\s\S]*?)<\/Period>/g)) {
600
- const pBlock = pm[1] ?? "";
627
+ for (const pBlock of blocks(block, "Period")) {
601
628
  const start = pBlock.match(/<start>([0-9TZ:+-]+)<\/start>/)?.[1];
602
629
  const res = pBlock.match(/<resolution>PT(\d+)M<\/resolution>/)?.[1];
603
630
  if (!start || !res)
@@ -661,9 +688,7 @@ export function entsoeFeed(securityToken) {
661
688
  // Realised generation per type (A75) — most recent hour with data.
662
689
  // ENTSO-E expects period in YYYYMMDDhhmm UTC.
663
690
  const now = new Date();
664
- const endHour = new Date(now);
665
- endHour.setMinutes(0, 0, 0);
666
- endHour.setSeconds(0, 0);
691
+ const endHour = floorToUtcHour(now);
667
692
  const startHour = new Date(endHour.getTime() - 24 * 60 * 60 * 1000);
668
693
  const fmt = (d) => d.toISOString().replace(/[-:T]/g, "").slice(0, 12);
669
694
  const params = new URLSearchParams({
@@ -741,9 +766,7 @@ export function entsoeFeed(securityToken) {
741
766
  // Persistence forecast: future hour H gets the most recent
742
767
  // realized observation whose UTC hour-of-day matches H —
743
768
  // phase-correct regardless of publication lag.
744
- const startTs = new Date(now);
745
- startTs.setMinutes(0, 0, 0);
746
- startTs.setSeconds(0, 0);
769
+ const startTs = floorToUtcHour(now);
747
770
  const forecast = [];
748
771
  for (let i = 0; i < hours; i++) {
749
772
  const t = new Date(startTs.getTime() + i * 60 * 60 * 1000);
@@ -978,6 +1001,39 @@ export function multiSourceGridFeed(options) {
978
1001
  },
979
1002
  };
980
1003
  }
1004
+ /**
1005
+ * The feed `buildDefaultGridFeed` routes `zone` to, derived from the same
1006
+ * zone maps so the label cannot drift from routing. `live` reflects the
1007
+ * credentials the host passes in (none → only GB is live).
1008
+ */
1009
+ export function regionDataSource(zone, credentials = {}) {
1010
+ if (zone === "GB") {
1011
+ return { id: "neso", label: "NESO Carbon Intensity API", live: true };
1012
+ }
1013
+ if (Object.hasOwn(EIA_RESPONDENT_BY_ZONE, zone)) {
1014
+ const wattTime = Boolean(credentials.wattTimeUsername && credentials.wattTimePassword);
1015
+ return {
1016
+ id: "watttime-eia",
1017
+ label: "WattTime or US EIA",
1018
+ keyVar: "TIDEGAP_EIA_API_KEY",
1019
+ live: wattTime || Boolean(credentials.eiaApiKey),
1020
+ };
1021
+ }
1022
+ if (Object.hasOwn(ENTSOE_BIDDING_ZONE_BY_REGION, zone)) {
1023
+ return {
1024
+ id: "entsoe",
1025
+ label: "ENTSO-E",
1026
+ keyVar: "TIDEGAP_ENTSOE_SECURITY_TOKEN",
1027
+ live: Boolean(credentials.entsoeSecurityToken),
1028
+ };
1029
+ }
1030
+ return {
1031
+ id: "electricitymaps",
1032
+ label: "Electricity Maps",
1033
+ keyVar: "TIDEGAP_ELECTRICITY_MAPS_API_KEY",
1034
+ live: Boolean(credentials.electricityMapsApiKey),
1035
+ };
1036
+ }
981
1037
  /**
982
1038
  * Auto-build the best free grid feed for every supported zone.
983
1039
  *
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Handoff fields of a task queued from an agent session: the folder a run
3
+ * works in (`cwd`), its tool profile and the result file Tidegap writes when
4
+ * it completes. Pure rules with injected file-system reads, so the MCP
5
+ * server, the CLI and the tick apply the same checks, at enqueue and again
6
+ * before a run or a write.
7
+ *
8
+ * Runs stay read-only: a profile only names one of the existing tool sets,
9
+ * and only Tidegap writes a result file, as a new file, never through a
10
+ * link.
11
+ */
12
+ /** A tool profile: a name for one of the existing tool sets. */
13
+ export type HandoffProfile = "read" | "web" | "none";
14
+ export declare const HANDOFF_PROFILES: readonly HandoffProfile[];
15
+ /** The tools of each profile. `read` is scoped to the run's folder by the adapter. */
16
+ export declare const PROFILE_TOOLS: Readonly<Record<HandoffProfile, readonly string[]>>;
17
+ /** The handoff fields of a task body (`ProviderCallSpec.handoff`). */
18
+ export interface HandoffSpec {
19
+ /** The folder a `claude-code` run works in. */
20
+ cwd?: string;
21
+ /** The tool profile; `read` when only `cwd` is given. */
22
+ profile?: HandoffProfile;
23
+ /** The new file Tidegap writes the result text to when the task completes. */
24
+ resultPath?: string;
25
+ /**
26
+ * Wake the idle Claude Code session that queued the task when it
27
+ * finishes (the plugin's Stop hook). Needs a checked session origin.
28
+ */
29
+ wake?: boolean;
30
+ }
31
+ /** Longest result or output path. */
32
+ export declare const HANDOFF_PATH_MAX_CHARS = 1024;
33
+ /** What the rules need to know about one path; no link is followed. */
34
+ export interface HandoffFsEntry {
35
+ kind: "file" | "dir" | "symlink" | "other";
36
+ uid: number;
37
+ }
38
+ /** The file-system reads of the rules. Tests inject their own. */
39
+ export interface HandoffFs {
40
+ /** The real path (links resolved), or undefined when the path does not resolve. */
41
+ realpath(path: string): string | undefined;
42
+ /** What is at `path` itself (a link is not followed), or undefined when nothing is. */
43
+ lstat(path: string): HandoffFsEntry | undefined;
44
+ /**
45
+ * The identity of the folder or file at `path` (links followed), such as
46
+ * `<dev>:<ino>`, or undefined when nothing is there. Two spellings of one
47
+ * folder (another letter case, a firmlink such as `/System/Volumes/Data`)
48
+ * have the same identity. Optional: without it, only the spelling counts.
49
+ */
50
+ identity?(path: string): string | undefined;
51
+ }
52
+ export declare const nodeHandoffFs: HandoffFs;
53
+ /** Where a result or output file may go, and how the rules read the disk. */
54
+ export interface HandoffPathContext {
55
+ /** The task's own folder (`handoff.cwd`, or the command's `cwd`). */
56
+ cwd?: string;
57
+ /** The origin session's project folder (the `origin_cwd` column). */
58
+ originCwd?: string;
59
+ /** Default: this user's home folder. */
60
+ home?: string;
61
+ /** Default: the system temp folder and `/tmp`. */
62
+ tmpDirs?: readonly string[];
63
+ fs?: HandoffFs;
64
+ /** Default: this process's user id. */
65
+ uid?: number;
66
+ }
67
+ /**
68
+ * Folders under the home folder that no handoff file or `claude-code` folder
69
+ * may be in. The handoff and tools pages list them; docs-drift compares.
70
+ */
71
+ export declare const PROTECTED_HOME_DIRS: readonly string[];
72
+ /**
73
+ * Check a result path: the location rules, and create-only (nothing may be
74
+ * at the path yet, not even a link). Returns the error message, or
75
+ * undefined when the path is allowed.
76
+ */
77
+ export declare function resultPathError(path: unknown, ctx?: HandoffPathContext): string | undefined;
78
+ /**
79
+ * Check an `output_path`: the location rules; a file already there must be
80
+ * a regular file (not a link) that this user owns, which the JSON then
81
+ * replaces. Returns the error message, or undefined when the path is allowed.
82
+ */
83
+ export declare function outputPathError(path: unknown, ctx?: HandoffPathContext): string | undefined;
84
+ /**
85
+ * Check the folder of a handed-off run. Every runner: an absolute path in
86
+ * its `path.resolve` form to an existing folder. `claude-code` also: not
87
+ * `/` or the home folder, owned by this user, and not inside a dot folder
88
+ * of the home folder, `~/Library` or a `.git` folder (links resolved too).
89
+ * Returns the error message, or undefined.
90
+ */
91
+ export declare function handoffCwdError(cwd: unknown, runner: "claude-code" | "command", ctx?: Pick<HandoffPathContext, "home" | "fs" | "uid">): string | undefined;
92
+ /** The profile and tools a handoff asks for, or the reason it is refused. */
93
+ export interface ProfileChoice {
94
+ profile?: HandoffProfile;
95
+ tools?: string[];
96
+ error?: string;
97
+ }
98
+ /**
99
+ * The tool set of a profile. A `cwd` with no profile means `read`; `web`
100
+ * runs in a fresh temporary folder, so it refuses a `cwd`. Neither given:
101
+ * no profile (the runner's default tools apply).
102
+ */
103
+ export declare function profileTools(profile: unknown, cwd: string | undefined): ProfileChoice;
104
+ /** True when two tool lists name the same tools. */
105
+ export declare function sameTools(a: readonly string[], b: readonly string[]): boolean;
106
+ /** What a task runs and where (the handed-off work shape), from its body. */
107
+ export interface TaskWorkShape {
108
+ runner?: string;
109
+ cwd?: string;
110
+ profile?: string;
111
+ tools?: string[];
112
+ resultPath?: string;
113
+ /** True when the task wakes its idle origin session when it finishes. */
114
+ wake?: boolean;
115
+ /** The shell command of a one-off command task. */
116
+ command?: string;
117
+ }
118
+ /** {@link TaskWorkShape} of a task; empty for a closure task or a corrupt body. */
119
+ export declare function taskWorkShape(record: {
120
+ bodyJson?: string;
121
+ }): TaskWorkShape;
122
+ /** The details of a task's newest `result_file` event, or undefined. */
123
+ export declare function latestResultFile(events: ReadonlyArray<{
124
+ kind: string;
125
+ details: Record<string, unknown>;
126
+ }> | undefined): Record<string, unknown> | undefined;
127
+ /** A result file's state in words: `written, 12 bytes`, `not written: <error>`, or `not written yet`. */
128
+ export declare function resultFileText(details: Record<string, unknown> | undefined): string;
129
+ /**
130
+ * Why a task may not ask for a wake, or undefined when it may: a wake is
131
+ * `true` or absent, and `true` needs a checked Claude Code session origin
132
+ * (the body's `origin` and a valid session id), so the right session wakes.
133
+ */
134
+ export declare function wakeError(wake: unknown, origin: {
135
+ agent?: unknown;
136
+ } | undefined, sessionId: unknown): string | undefined;
137
+ /** A wake marker with no wake task left to wait for goes this long after its last refresh (the waiter refreshes it at every Stop). */
138
+ export declare const WAKE_MARKER_MAX_AGE_MS: number;
139
+ /** `~/.tidegap/sessions/wake`: one marker per session with a task to wake it for. */
140
+ export declare function wakeMarkersDir(home?: string): string;
141
+ /** The wake marker of one session, or undefined for an id that fails the id rule. */
142
+ export declare function wakeMarkerPath(sessionId: string, dir?: string): string | undefined;
143
+ /**
144
+ * Create or refresh a session's wake marker (file `0600`, folder `0700`),
145
+ * so the plugin's Stop hook starts its waiter. Returns the error message,
146
+ * or undefined. Something other than a regular file at the path is left
147
+ * alone and reported.
148
+ */
149
+ export declare function writeWakeMarker(sessionId: string, dir?: string, now?: Date): string | undefined;
150
+ /** Remove a session's wake marker; a missing one is fine. */
151
+ export declare function removeWakeMarker(sessionId: string, dir?: string): void;
152
+ //# sourceMappingURL=handoff.d.ts.map