@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
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Email via SMTP (R12, KTD5): plain-text mail through the user's own SMTP
3
+ * account. The host's client (`packages/cli/src/channels/smtp.ts`) sends
4
+ * the spec; this file holds the fields, the provider presets and the
5
+ * where-to-get-it steps. TLS is always verified; security `none` (no TLS at
6
+ * all) is allowed only to a mail server on this computer.
7
+ *
8
+ * Outlook.com and Hotmail personal accounts are not supported: Microsoft
9
+ * turned off password SMTP for them on 2024-09-16 and they need OAuth,
10
+ * which would need a Tidegap-owned client id (R20).
11
+ */
12
+ /** A plain `local@domain` address: no spaces, CR, LF, `<`, `>`, quotes, commas or semicolons. */
13
+ export const EMAIL_ADDRESS = String.raw `[^\s<>@,;"]{1,64}@[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+`;
14
+ const WHOLE_ADDRESS = new RegExp(`^(?:${EMAIL_ADDRESS})$`);
15
+ /** An SMTP login: usually an address, but relays use a user name or `apikey` (SendGrid, SES). No whitespace (so no CR or LF). Not a secret: it is shown in full. */
16
+ const SMTP_LOGIN = String.raw `\S{1,255}`;
17
+ /** A host name or an IPv4 address (no scheme, no port). */
18
+ const HOST = String.raw `[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?`;
19
+ /** Hosts that never leave this computer: `none` (no TLS) is allowed only to these. */
20
+ export function isLoopbackSmtpHost(host) {
21
+ return /^(localhost|127(?:\.\d{1,3}){3}|::1|\[::1\])$/i.test(host.trim());
22
+ }
23
+ /** Microsoft's personal mail domains and SMTP host: password SMTP is off for them. */
24
+ const OUTLOOK_PERSONAL = /@(outlook|hotmail|live|msn)\.[a-z.]+$/i;
25
+ const OUTLOOK_HOST = /^smtp-mail\.outlook\.com$/i;
26
+ const OUTLOOK_TEXT = "Outlook.com and Hotmail accounts cannot send through SMTP with a password since September 2024. Use another mail account, or a Microsoft 365 work account whose admin allows SMTP AUTH.";
27
+ const SECURITY = ["tls", "starttls", "none"];
28
+ /** Gmail shows app passwords in groups of four ("abcd efgh ijkl mnop"); the spaces are not part of it. */
29
+ function passwordFor(host, password) {
30
+ if (!password)
31
+ return undefined;
32
+ return /^smtp\.gmail\.com$/i.test(host) ? password.replace(/\s+/g, "") : password;
33
+ }
34
+ /** One line for a header: CR, LF and other control characters become spaces. */
35
+ export function headerLine(text) {
36
+ return text.replace(/[\u0000-\u001f\u007f\u2028\u2029]+/g, " ").trim();
37
+ }
38
+ export const email = {
39
+ kind: "email",
40
+ label: "Email",
41
+ description: "Mail through your own SMTP account: Gmail, iCloud, Fastmail or any provider.",
42
+ ready: true,
43
+ fields: [
44
+ {
45
+ name: "user",
46
+ label: "Email address",
47
+ input: "text",
48
+ required: true,
49
+ pattern: SMTP_LOGIN,
50
+ maxLength: 255,
51
+ placeholder: "you@example.com",
52
+ invalid: "Type the login with no spaces, usually your email address.",
53
+ help: "Usually your email address; some relays use a username or 'apikey'. It signs in to the mail server, and it is the sender and the recipient unless you change them below.",
54
+ },
55
+ {
56
+ name: "password",
57
+ label: "App password",
58
+ input: "password",
59
+ secret: true,
60
+ keepWith: "host",
61
+ help: "An app password, not your normal password. Leave empty only for a server that needs no login.",
62
+ },
63
+ { name: "host", label: "SMTP server", input: "text", required: true, advanced: true, pattern: HOST, placeholder: "smtp.example.com", invalid: "Type the server name only, like smtp.example.com, with no https:// and no port." },
64
+ { name: "port", label: "Port", input: "number", required: true, advanced: true, default: 465, min: 1, max: 65535 },
65
+ {
66
+ name: "security",
67
+ label: "Security",
68
+ input: "select",
69
+ advanced: true,
70
+ default: "tls",
71
+ options: [
72
+ { value: "tls", label: "SSL/TLS (usually port 465)" },
73
+ { value: "starttls", label: "STARTTLS (usually port 587)" },
74
+ { value: "none", label: "None (only a mail server on this computer)" },
75
+ ],
76
+ },
77
+ { name: "from", label: "From", input: "text", advanced: true, pattern: EMAIL_ADDRESS, placeholder: "Same as the email address", invalid: "Type one plain address, like you@example.com." },
78
+ { name: "to", label: "Send to", input: "text", advanced: true, pattern: EMAIL_ADDRESS, placeholder: "Same as From", invalid: "Type one plain address, like you@example.com." },
79
+ ],
80
+ presets: [
81
+ {
82
+ id: "gmail",
83
+ label: "Gmail",
84
+ values: { host: "smtp.gmail.com", port: 465, security: "tls" },
85
+ note: "Turn on 2-Step Verification, then create an app password at myaccount.google.com/apppasswords. Spaces in it are fine.",
86
+ },
87
+ {
88
+ id: "icloud",
89
+ label: "iCloud Mail",
90
+ values: { host: "smtp.mail.me.com", port: 587, security: "starttls" },
91
+ note: "At account.apple.com: Sign-In and Security → App-Specific Passwords → Generate. Use your full iCloud address.",
92
+ },
93
+ {
94
+ id: "fastmail",
95
+ label: "Fastmail",
96
+ values: { host: "smtp.fastmail.com", port: 465, security: "tls" },
97
+ note: "Settings → Privacy & Security → App passwords → New, with SMTP access.",
98
+ },
99
+ {
100
+ id: "m365",
101
+ label: "Microsoft 365 (work)",
102
+ values: { host: "smtp.office365.com", port: 587, security: "starttls" },
103
+ note: "Works only if your admin allows SMTP AUTH. Outlook.com and Hotmail personal accounts are not supported.",
104
+ },
105
+ ],
106
+ steps: [
107
+ { text: "Gmail: turn on 2-Step Verification, then create an app password named Tidegap.", link: "https://myaccount.google.com/apppasswords" },
108
+ { text: "iCloud: Sign-In and Security → App-Specific Passwords → Generate.", link: "https://account.apple.com/" },
109
+ { text: "Fastmail: Settings → Privacy & Security → App passwords → New, with SMTP access.", link: "https://www.fastmail.com/help/clients/apppassword.html" },
110
+ { text: "Other providers: find the SMTP server, port and security on their help pages. Outlook.com and Hotmail personal accounts are not supported." },
111
+ ],
112
+ defaultEvents: ["task_failed", "not_ready", "digest"],
113
+ docsAnchor: "notify-email",
114
+ target: (values) => String(values.to || values.from || values.user || "Email"),
115
+ errors: {
116
+ auth: { text: "The mail server refused the user name or password. Gmail, iCloud and Fastmail need an app password.", field: "password" },
117
+ auth_required: { text: "The mail server needs a login. Type the app password.", field: "password" },
118
+ auth_unsupported: { text: "The mail server offers no login method Tidegap knows (PLAIN or LOGIN). Check the server and the security setting.", field: "security" },
119
+ starttls_unsupported: { text: "The mail server does not offer STARTTLS on this port. Pick SSL/TLS, or check the port.", field: "security" },
120
+ tls: { text: "The mail server's certificate is not trusted. Check the server name and the security setting.", field: "host" },
121
+ network: { text: "Tidegap could not reach the mail server. Check the server name and the port.", field: "host" },
122
+ timeout: { text: "The mail server did not answer in time. Check the port and the security setting.", field: "port" },
123
+ smtp_sender: { text: "The mail server refused the sender address. Use your own address in From.", field: "from" },
124
+ smtp_recipient: { text: "The mail server refused the recipient address. Check Send to.", field: "to" },
125
+ smtp_policy: { text: "The mail server refused the mail by policy. Check that the account may send mail through SMTP." },
126
+ },
127
+ validate(values) {
128
+ const host = String(values.host ?? "");
129
+ if (values.security === "none" && !isLoopbackSmtpHost(host)) {
130
+ return { field: "security", text: "Security None works only with a mail server on this computer. Pick SSL/TLS or STARTTLS." };
131
+ }
132
+ if (OUTLOOK_HOST.test(host))
133
+ return { field: "host", text: OUTLOOK_TEXT };
134
+ const user = String(values.user ?? "");
135
+ if (OUTLOOK_PERSONAL.test(user))
136
+ return { field: "user", text: OUTLOOK_TEXT };
137
+ // A login that is not an address cannot be the sender.
138
+ if (!values.from && !WHOLE_ADDRESS.test(user)) {
139
+ return { field: "from", text: "This login is not an email address. Type the sender address in From." };
140
+ }
141
+ return undefined;
142
+ },
143
+ format(payload, values) {
144
+ const host = String(values.host);
145
+ const user = String(values.user);
146
+ const from = String(values.from || user);
147
+ const password = passwordFor(host, values.password === undefined ? undefined : String(values.password));
148
+ const security = SECURITY.find((s) => s === values.security) ?? "tls";
149
+ return {
150
+ type: "smtp",
151
+ host,
152
+ port: Number(values.port),
153
+ security,
154
+ ...(password ? { user, password } : {}),
155
+ from,
156
+ to: String(values.to || from),
157
+ subject: headerLine(`Tidegap: ${payload.title}`),
158
+ text: payload.text,
159
+ };
160
+ },
161
+ };
162
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1,8 @@
1
+ /** Every registry kind (KTD1). Each channel stream edits only its own `kinds/<kind>.ts`. */
2
+ import type { KindDescriptor } from "../registry.js";
3
+ import type { ChannelKind, RegistryKind } from "../types.js";
4
+ /** One descriptor per registry kind, in card order. */
5
+ export declare const KIND_DESCRIPTORS: Readonly<Record<RegistryKind, KindDescriptor>>;
6
+ /** True for `os` and every registry kind; the ledger skips any other row kind. */
7
+ export declare function isChannelKind(kind: string): kind is ChannelKind;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ /** Every registry kind (KTD1). Each channel stream edits only its own `kinds/<kind>.ts`. */
2
+ import { command } from "./command.js";
3
+ import { discord } from "./discord.js";
4
+ import { email } from "./email.js";
5
+ import { ntfy } from "./ntfy.js";
6
+ import { pushover } from "./pushover.js";
7
+ import { shortcuts } from "./shortcuts.js";
8
+ import { slack } from "./slack.js";
9
+ import { telegram } from "./telegram.js";
10
+ import { webhook } from "./webhook.js";
11
+ /** One descriptor per registry kind, in card order. */
12
+ export const KIND_DESCRIPTORS = { telegram, email, slack, discord, ntfy, pushover, webhook, shortcuts, command };
13
+ /** True for `os` and every registry kind; the ledger skips any other row kind. */
14
+ export function isChannelKind(kind) {
15
+ return kind === "os" || Object.hasOwn(KIND_DESCRIPTORS, kind);
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * ntfy (R12, R20): phone push through the public `https://ntfy.sh` or the
3
+ * user's own server. The message is a POST to `<server>/<topic>` with the
4
+ * text as the body and `Title`, `Priority` and `Tags` headers. A title with
5
+ * characters outside printable ASCII goes as an RFC 2047 encoded word, which
6
+ * ntfy decodes. The optional access token is a Bearer header; it belongs to
7
+ * its server (`keepWith`), so a new server never gets the old token.
8
+ */
9
+ import type { KindDescriptor } from "../registry.js";
10
+ import type { NotificationPayload } from "../payload.js";
11
+ export declare const NTFY_DEFAULT_SERVER = "https://ntfy.sh";
12
+ /** ntfy turns a longer body into an attachment; stay under its 4,096-byte message limit. */
13
+ export declare const NTFY_MAX_BODY_BYTES = 4000;
14
+ /** The header value of `text`: as is when printable ASCII, else an RFC 2047 base64 encoded word. */
15
+ export declare function headerText(text: string): string;
16
+ /** At most `max` UTF-8 bytes, cut on a character boundary, with an ellipsis when cut. */
17
+ export declare function clipBytes(text: string, max: number): string;
18
+ /**
19
+ * The publish URL: the server (any path prefix kept, any query or fragment
20
+ * dropped) plus the topic as one more path segment.
21
+ */
22
+ export declare function ntfyUrl(server: string, topic: string): string;
23
+ export declare function ntfyPriority(payload: NotificationPayload, override: string | number | undefined): number;
24
+ export declare const ntfy: KindDescriptor;
25
+ //# sourceMappingURL=ntfy.d.ts.map
@@ -0,0 +1,163 @@
1
+ /**
2
+ * ntfy (R12, R20): phone push through the public `https://ntfy.sh` or the
3
+ * user's own server. The message is a POST to `<server>/<topic>` with the
4
+ * text as the body and `Title`, `Priority` and `Tags` headers. A title with
5
+ * characters outside printable ASCII goes as an RFC 2047 encoded word, which
6
+ * ntfy decodes. The optional access token is a Bearer header; it belongs to
7
+ * its server (`keepWith`), so a new server never gets the old token.
8
+ */
9
+ import { optString } from "./shared.js";
10
+ export const NTFY_DEFAULT_SERVER = "https://ntfy.sh";
11
+ /** ntfy turns a longer body into an attachment; stay under its 4,096-byte message limit. */
12
+ export const NTFY_MAX_BODY_BYTES = 4000;
13
+ /** Priority per event when the field is `auto`: failures high, summaries low. */
14
+ const PRIORITY = { task_failed: 4, not_ready: 4, task_done: 3, test: 3, clean_window: 2, digest: 2 };
15
+ /** ntfy emoji tags per level (`x` shows ❌). */
16
+ const TAGS = { success: "white_check_mark", error: "x", warning: "warning", info: "information_source" };
17
+ /** The header value of `text`: as is when printable ASCII, else an RFC 2047 base64 encoded word. */
18
+ export function headerText(text) {
19
+ if (/^[\x20-\x7e]*$/.test(text))
20
+ return text;
21
+ return `=?UTF-8?B?${Buffer.from(text, "utf8").toString("base64")}?=`;
22
+ }
23
+ const ELLIPSIS_BYTES = Buffer.byteLength("…", "utf8");
24
+ /** At most `max` UTF-8 bytes, cut on a character boundary, with an ellipsis when cut. */
25
+ export function clipBytes(text, max) {
26
+ if (Buffer.byteLength(text, "utf8") <= max)
27
+ return text;
28
+ let out = "";
29
+ let size = ELLIPSIS_BYTES;
30
+ for (const ch of text) {
31
+ size += Buffer.byteLength(ch, "utf8");
32
+ if (size > max)
33
+ break;
34
+ out += ch;
35
+ }
36
+ return `${out}…`;
37
+ }
38
+ /**
39
+ * The publish URL: the server (any path prefix kept, any query or fragment
40
+ * dropped) plus the topic as one more path segment.
41
+ */
42
+ export function ntfyUrl(server, topic) {
43
+ let url;
44
+ try {
45
+ url = new URL(server);
46
+ }
47
+ catch {
48
+ // validateFields and the URL policy refuse such a server before any send.
49
+ return `${server}/${encodeURIComponent(topic)}`;
50
+ }
51
+ url.search = "";
52
+ url.hash = "";
53
+ let path = url.pathname;
54
+ let end = path.length;
55
+ // A loop, not /\/+$/: that regex is quadratic on a long run of slashes.
56
+ while (end > 0 && path[end - 1] === "/")
57
+ end--;
58
+ path = path.slice(0, end);
59
+ url.pathname = `${path}/${encodeURIComponent(topic)}`;
60
+ return url.href;
61
+ }
62
+ export function ntfyPriority(payload, override) {
63
+ const n = Number(override);
64
+ if (Number.isInteger(n) && n >= 1 && n <= 5)
65
+ return n;
66
+ // "Running again" is good news: the task_done priority, not the alert's.
67
+ return payload.recovered && payload.level === "success" ? PRIORITY.task_done : PRIORITY[payload.event];
68
+ }
69
+ export const ntfy = {
70
+ kind: "ntfy",
71
+ label: "ntfy",
72
+ description: "Push notifications to your phone through ntfy, on ntfy.sh or your own server.",
73
+ ready: true,
74
+ fields: [
75
+ {
76
+ name: "server",
77
+ label: "Server",
78
+ input: "url",
79
+ required: true,
80
+ default: NTFY_DEFAULT_SERVER,
81
+ help: "Keep https://ntfy.sh, or type the address of your own ntfy server.",
82
+ },
83
+ {
84
+ name: "topic",
85
+ label: "Topic",
86
+ input: "text",
87
+ required: true,
88
+ secret: true,
89
+ pattern: "[-_A-Za-z0-9]{1,64}",
90
+ invalid: "Use 1 to 64 letters, digits, - or _ for the topic.",
91
+ help: "Anyone who knows the topic can read it on a public server. Keep the random name.",
92
+ },
93
+ {
94
+ name: "token",
95
+ label: "Access token",
96
+ input: "password",
97
+ secret: true,
98
+ keepWith: "server",
99
+ pattern: "[!-~]+",
100
+ invalid: "Paste the access token as ntfy shows it, with no spaces.",
101
+ placeholder: "tk_…",
102
+ help: "Only for a server or topic that needs login. Leave empty for ntfy.sh.",
103
+ },
104
+ {
105
+ name: "priority",
106
+ label: "Priority",
107
+ input: "select",
108
+ default: "auto",
109
+ advanced: true,
110
+ options: [
111
+ { value: "auto", label: "Automatic (failures high, summaries low)" },
112
+ { value: "5", label: "5: urgent" },
113
+ { value: "4", label: "4: high" },
114
+ { value: "3", label: "3: default" },
115
+ { value: "2", label: "2: low" },
116
+ { value: "1", label: "1: min" },
117
+ ],
118
+ },
119
+ ],
120
+ steps: [
121
+ { text: "Install the ntfy app (App Store or Google Play), or open the ntfy web app.", link: "https://ntfy.sh/app" },
122
+ { text: "In the app, subscribe to the topic shown here. Copy it with the Copy button." },
123
+ { text: "Press Connect. A test notification arrives on your phone." },
124
+ { text: "Own server: change the server address, and add an access token if it needs login.", link: "https://docs.ntfy.sh/config/#access-tokens" },
125
+ ],
126
+ defaultEvents: ["task_done", "task_failed", "not_ready"],
127
+ docsAnchor: "notify-ntfy",
128
+ target(values, hints) {
129
+ let host = String(values.server ?? NTFY_DEFAULT_SERVER);
130
+ try {
131
+ host = new URL(host).host;
132
+ }
133
+ catch {
134
+ // keep the raw value
135
+ }
136
+ return hints.topic ? `${host} topic ${hints.topic}` : host;
137
+ },
138
+ errors: {
139
+ auth: { text: "The token was refused. Create a new access token in your ntfy account and paste it here.", field: "token" },
140
+ ntfy_token_needed: { text: "This topic needs a token. Create an access token in your ntfy account and paste it here.", field: "token" },
141
+ http_404: { text: "This address is not an ntfy server. Check the server address.", field: "server" },
142
+ http_400: { text: "The ntfy server refused the topic or the message. Check the topic.", field: "topic" },
143
+ rate_limited: { text: "The ntfy server limits messages. Wait a few minutes, or use an account token or your own server." },
144
+ http_507: { text: "The ntfy server is out of space for this topic. Try again tomorrow, or use your own server." },
145
+ },
146
+ format(payload, values) {
147
+ const token = optString(values.token);
148
+ return {
149
+ type: "http",
150
+ method: "POST",
151
+ url: ntfyUrl(String(values.server ?? NTFY_DEFAULT_SERVER), String(values.topic)),
152
+ headers: {
153
+ "Content-Type": "text/plain; charset=utf-8",
154
+ Title: headerText(payload.title),
155
+ Priority: String(ntfyPriority(payload, values.priority)),
156
+ Tags: TAGS[payload.level],
157
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
158
+ },
159
+ body: clipBytes(payload.text, NTFY_MAX_BODY_BYTES),
160
+ };
161
+ },
162
+ };
163
+ //# sourceMappingURL=ntfy.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Pushover (R12, R20): phone push through the user's own Pushover
3
+ * application token. The message is a form-encoded POST to the fixed
4
+ * `https://api.pushover.net/1/messages.json`; the host may point it at a
5
+ * loopback test server (`TIDEGAP_PUSHOVER_API_BASE`, KTD8), never anywhere
6
+ * else. Pushover shows plain text, so nothing is escaped.
7
+ */
8
+ import type { KindDescriptor } from "../registry.js";
9
+ export declare const PUSHOVER_MESSAGES_PATH = "/1/messages.json";
10
+ export declare const pushover: KindDescriptor;
11
+ //# sourceMappingURL=pushover.d.ts.map
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Pushover (R12, R20): phone push through the user's own Pushover
3
+ * application token. The message is a form-encoded POST to the fixed
4
+ * `https://api.pushover.net/1/messages.json`; the host may point it at a
5
+ * loopback test server (`TIDEGAP_PUSHOVER_API_BASE`, KTD8), never anywhere
6
+ * else. Pushover shows plain text, so nothing is escaped.
7
+ */
8
+ const PUSHOVER_API_BASE = "https://api.pushover.net";
9
+ export const PUSHOVER_MESSAGES_PATH = "/1/messages.json";
10
+ /** Pushover's limits: message 1,024 characters, title 250. */
11
+ const PUSHOVER_MAX_MESSAGE = 1024;
12
+ const PUSHOVER_MAX_TITLE = 250;
13
+ /** Priority per event: summaries and clean windows quiet (-1), the rest normal (0). */
14
+ const PRIORITY = { task_failed: 0, not_ready: 0, task_done: 0, test: 0, clean_window: -1, digest: -1 };
15
+ const clip = (s, n) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
16
+ /** Pushover user keys and application tokens: 30 letters and digits. */
17
+ const KEY = "[A-Za-z0-9]{30}";
18
+ export const pushover = {
19
+ kind: "pushover",
20
+ label: "Pushover",
21
+ description: "Push notifications to your phone through your own Pushover account.",
22
+ ready: true,
23
+ fields: [
24
+ {
25
+ name: "user_key",
26
+ label: "User key",
27
+ input: "password",
28
+ required: true,
29
+ secret: true,
30
+ pattern: KEY,
31
+ invalid: "Paste the 30-character user key from the top of your Pushover dashboard.",
32
+ },
33
+ {
34
+ name: "app_token",
35
+ label: "API token",
36
+ input: "password",
37
+ required: true,
38
+ secret: true,
39
+ pattern: KEY,
40
+ invalid: "Paste the 30-character API token of the application you created for Tidegap.",
41
+ },
42
+ ],
43
+ steps: [
44
+ { text: "Log in at pushover.net and copy Your User Key from the dashboard.", link: "https://pushover.net/" },
45
+ { text: "Create an Application/API Token. Name it Tidegap.", link: "https://pushover.net/apps/build" },
46
+ { text: "Copy the API token of that application." },
47
+ { text: "Paste both here and press Connect. Pushover is a one-time purchase per platform after a 30-day trial." },
48
+ ],
49
+ defaultEvents: ["task_done", "task_failed", "not_ready"],
50
+ docsAnchor: "notify-pushover",
51
+ target: (_values, hints) => (hints.user_key ? `user ${hints.user_key}` : "Pushover"),
52
+ errors: {
53
+ pushover_user: { text: "Pushover does not know this user key. Copy it again from your Pushover dashboard.", field: "user_key" },
54
+ pushover_token: { text: "Pushover refused the API token. Copy it again from the application page, or create a new one.", field: "app_token" },
55
+ http_400: { text: "Pushover refused the message. Check the user key and the API token." },
56
+ rate_limited: { text: "Your Pushover application reached its monthly message limit. Wait for the next month, or upgrade it in Pushover." },
57
+ },
58
+ format(payload, values) {
59
+ const at = Math.floor(Date.parse(payload.at) / 1000);
60
+ const body = new URLSearchParams({
61
+ token: String(values.app_token),
62
+ user: String(values.user_key),
63
+ title: clip(payload.title, PUSHOVER_MAX_TITLE),
64
+ message: clip(payload.text, PUSHOVER_MAX_MESSAGE),
65
+ priority: String(PRIORITY[payload.event]),
66
+ ...(Number.isFinite(at) ? { timestamp: String(at) } : {}),
67
+ });
68
+ return {
69
+ type: "http",
70
+ method: "POST",
71
+ url: `${PUSHOVER_API_BASE}${PUSHOVER_MESSAGES_PATH}`,
72
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
73
+ body: body.toString(),
74
+ };
75
+ },
76
+ };
77
+ //# sourceMappingURL=pushover.js.map
@@ -0,0 +1,25 @@
1
+ /** Helpers the chat kinds share: the loopback URL the test sinks use, escaping of untrusted text (KTD2). */
2
+ /**
3
+ * Pattern source of a loopback http(s) URL. Kinds with a fixed official host
4
+ * (Slack, Discord) also accept it, so the fake sinks of the tests and the QA
5
+ * harness can stand in for the provider (KTD8).
6
+ */
7
+ export declare const LOOPBACK_URL: string;
8
+ /** `&`, `<` and `>` as entities: Slack mrkdwn and the plain `{"text"}` receivers read `<…>` as links and mentions. */
9
+ export declare function escapeAngle(text: string): string;
10
+ /** A zero-width space after `@` in the group mentions of Slack, Discord, Teams, Mattermost and Matrix, so none of them pings. */
11
+ export declare function defuseMentions(text: string): string;
12
+ /** A backslash before every character in `specials`. */
13
+ export declare function escapeChars(text: string, specials: string): string;
14
+ /** At most `max` characters, the last one an ellipsis when cut; never ends in half an escape (`\`). */
15
+ export declare function clipEscaped(text: string, max: number): string;
16
+ /** Hex color per level for embeds and cards. */
17
+ export declare const LEVEL_COLOR: {
18
+ readonly success: 3046706;
19
+ readonly error: 12986408;
20
+ readonly warning: 16361509;
21
+ readonly info: 1402304;
22
+ };
23
+ /** A non-empty string field value, else undefined (optional secrets such as tokens). */
24
+ export declare function optString(v: unknown): string | undefined;
25
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1,39 @@
1
+ /** Helpers the chat kinds share: the loopback URL the test sinks use, escaping of untrusted text (KTD2). */
2
+ /**
3
+ * Pattern source of a loopback http(s) URL. Kinds with a fixed official host
4
+ * (Slack, Discord) also accept it, so the fake sinks of the tests and the QA
5
+ * harness can stand in for the provider (KTD8).
6
+ */
7
+ export const LOOPBACK_URL = String.raw `https?://(?:127\.0\.0\.1|localhost|\[::1\])(?::\d{1,5})?/\S*`;
8
+ /** `&`, `<` and `>` as entities: Slack mrkdwn and the plain `{"text"}` receivers read `<…>` as links and mentions. */
9
+ export function escapeAngle(text) {
10
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
11
+ }
12
+ /** A zero-width space after `@` in the group mentions of Slack, Discord, Teams, Mattermost and Matrix, so none of them pings. */
13
+ export function defuseMentions(text) {
14
+ return text.replace(/@(channel|all|here|everyone|room)\b/gi, "@​$1");
15
+ }
16
+ /** A backslash before every character in `specials`. */
17
+ export function escapeChars(text, specials) {
18
+ return text.replace(new RegExp(`[${specials.replace(/[\\\]^-]/g, "\\$&")}]`, "g"), "\\$&");
19
+ }
20
+ /** At most `max` characters, the last one an ellipsis when cut; never ends in half an escape (`\`). */
21
+ export function clipEscaped(text, max) {
22
+ if (text.length <= max)
23
+ return text;
24
+ let cut = text.slice(0, max - 1);
25
+ // An odd run of trailing backslashes would escape the ellipsis. A loop, not /\\+$/: that regex is quadratic on a long run.
26
+ let run = 0;
27
+ while (run < cut.length && cut[cut.length - 1 - run] === "\\")
28
+ run++;
29
+ if (run % 2 === 1)
30
+ cut = cut.slice(0, -1);
31
+ return `${cut}…`;
32
+ }
33
+ /** Hex color per level for embeds and cards. */
34
+ export const LEVEL_COLOR = { success: 0x2e7d32, error: 0xc62828, warning: 0xf9a825, info: 0x1565c0 };
35
+ /** A non-empty string field value, else undefined (optional secrets such as tokens). */
36
+ export function optString(v) {
37
+ return typeof v === "string" && v ? v : undefined;
38
+ }
39
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * macOS Shortcuts (R12, KTD16): the host runs `shortcuts run <name>` with
3
+ * the message text as the Shortcut Input, on macOS only. The name is the
4
+ * only field; it may not start with "-", so it can never read as an option
5
+ * of the `shortcuts` tool.
6
+ */
7
+ import type { KindDescriptor } from "../registry.js";
8
+ export declare const shortcuts: KindDescriptor;
9
+ //# sourceMappingURL=shortcuts.d.ts.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * macOS Shortcuts (R12, KTD16): the host runs `shortcuts run <name>` with
3
+ * the message text as the Shortcut Input, on macOS only. The name is the
4
+ * only field; it may not start with "-", so it can never read as an option
5
+ * of the `shortcuts` tool.
6
+ */
7
+ const SHORTCUT_NAME_MAX = 100;
8
+ export const shortcuts = {
9
+ kind: "shortcuts",
10
+ label: "Shortcuts",
11
+ description: "Runs a macOS Shortcut with the message as its input: send an iMessage, add a reminder, turn on a light.",
12
+ platforms: ["darwin"],
13
+ ready: true,
14
+ fields: [
15
+ {
16
+ name: "name",
17
+ label: "Shortcut name",
18
+ input: "text",
19
+ required: true,
20
+ placeholder: "Tidegap",
21
+ maxLength: SHORTCUT_NAME_MAX,
22
+ pattern: "[^-][\\s\\S]*",
23
+ invalid: "Type the shortcut name exactly as the Shortcuts app shows it. It cannot start with -.",
24
+ },
25
+ ],
26
+ steps: [
27
+ { text: "Open the Shortcuts app and create a new shortcut.", link: "https://support.apple.com/guide/shortcuts-mac/create-a-custom-shortcut-apd84c576f8c/mac" },
28
+ { text: "Add an action that uses Shortcut Input, for example Send Message or Add New Reminder." },
29
+ { text: "Name the shortcut Tidegap." },
30
+ { text: "Type the name here and press Connect. The shortcut runs once with a test message." },
31
+ ],
32
+ defaultEvents: ["task_done", "task_failed", "not_ready"],
33
+ docsAnchor: "notify-shortcuts",
34
+ target: (values) => `Shortcut "${String(values.name ?? "")}"`,
35
+ errors: {
36
+ not_found: { text: "The Shortcuts app has no shortcut with this name. Check the spelling and the capital letters.", field: "name" },
37
+ no_shortcuts: { text: "The shortcuts tool was not found. Shortcuts needs macOS 12 or later." },
38
+ timeout: { text: "The shortcut did not finish in 20 seconds. Remove actions that wait for you, such as Ask for Input.", field: "name" },
39
+ shortcut_failed: { text: "The shortcut stopped with an error. Run it once in the Shortcuts app to see the error.", field: "name" },
40
+ },
41
+ format(payload, values) {
42
+ return { type: "shortcut", name: String(values.name), input: payload.text };
43
+ },
44
+ };
45
+ //# sourceMappingURL=shortcuts.js.map
@@ -0,0 +1,8 @@
1
+ /** Slack (R12): an Incoming Webhook of a Slack app. `text` plus one mrkdwn section block; `&<>` escaped (KTD2). */
2
+ import type { KindDescriptor } from "../registry.js";
3
+ import type { NotificationPayload } from "../payload.js";
4
+ /** Slack's cap on a section block's text. */
5
+ export declare const SLACK_SECTION_MAX = 3000;
6
+ export declare function slackBody(payload: NotificationPayload): string;
7
+ export declare const slack: KindDescriptor;
8
+ //# sourceMappingURL=slack.d.ts.map