@hyperwindmill/caretaker-cli 0.20.0 → 0.22.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 (42) hide show
  1. package/dist/cli/mcp.js +5 -5
  2. package/dist/cli/web/mcp_bridge.d.ts +1 -1
  3. package/dist/cli/web/mcp_bridge.d.ts.map +1 -1
  4. package/dist/cli/web/mcp_bridge.js +23 -7
  5. package/dist/cli/web/scheduler/heartbeat.d.ts +2 -2
  6. package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -1
  7. package/dist/cli/web/scheduler/strategy.d.ts +3 -3
  8. package/dist/cli/web/scheduler/strategy.d.ts.map +1 -1
  9. package/dist/cli/web/scheduler/task_roles.d.ts +0 -4
  10. package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -1
  11. package/dist/cli/web/scheduler/task_roles.js +12 -2
  12. package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
  13. package/dist/cli/web/scheduler/task_strategy.js +4 -1
  14. package/dist/cli/web/scheduler/telegram.d.ts.map +1 -1
  15. package/dist/cli/web/scheduler/telegram.js +4 -1
  16. package/dist/cli/web/server.d.ts.map +1 -1
  17. package/dist/cli/web/server.js +10 -4
  18. package/dist/harness/claude_code_runner.d.ts.map +1 -1
  19. package/dist/harness/claude_code_runner.js +5 -1
  20. package/dist/harness/tools/builtin/email_tools.d.ts +5 -0
  21. package/dist/harness/tools/builtin/email_tools.d.ts.map +1 -0
  22. package/dist/harness/tools/builtin/email_tools.js +210 -0
  23. package/dist/harness/tools/builtin/index.d.ts +2 -1
  24. package/dist/harness/tools/builtin/index.d.ts.map +1 -1
  25. package/dist/harness/tools/builtin/index.js +7 -1
  26. package/dist/harness/tools/resolve.d.ts.map +1 -1
  27. package/dist/harness/tools/resolve.js +9 -4
  28. package/dist/lib/email.d.ts +148 -0
  29. package/dist/lib/email.d.ts.map +1 -0
  30. package/dist/lib/email.js +328 -0
  31. package/dist/mcp/builtin_server.d.ts +13 -0
  32. package/dist/mcp/builtin_server.d.ts.map +1 -0
  33. package/dist/mcp/builtin_server.js +65 -0
  34. package/dist/store/json.d.ts.map +1 -1
  35. package/dist/store/json.js +6 -0
  36. package/dist/tui/agents.js +36 -14
  37. package/dist/webview/standalone.js +340 -35
  38. package/dist/webview/standalone.js.map +3 -3
  39. package/package.json +9 -3
  40. package/dist/mcp/task_server.d.ts +0 -9
  41. package/dist/mcp/task_server.d.ts.map +0 -1
  42. package/dist/mcp/task_server.js +0 -48
@@ -0,0 +1,148 @@
1
+ import type { ServiceConfig } from '../types.js';
2
+ /**
3
+ * Ceiling on one mail network operation, and the same reasoning as
4
+ * `NET_TIMEOUT_MS` in lib/task_git.ts: an unattended run must not hang forever
5
+ * on a wedged server. The abort also carries `ctx.signal`, so Pause and the
6
+ * task's wall-clock budget reach *inside* an in-flight connection — the loop
7
+ * only checks the signal between turns, and would otherwise sit awaiting this
8
+ * tool call.
9
+ */
10
+ export declare const NET_TIMEOUT_MS = 60000;
11
+ /** An email account with its secrets decrypted and its defaults applied. */
12
+ export type EmailAccount = {
13
+ name: string;
14
+ from: string;
15
+ smtpHost: string;
16
+ smtpPort: number;
17
+ smtpSecure: boolean;
18
+ smtpUser: string;
19
+ smtpPassword: string;
20
+ imapHost: string;
21
+ imapPort: number;
22
+ imapSecure: boolean;
23
+ imapUser: string;
24
+ imapPassword: string;
25
+ /** Outbound: who this account may send to. Enforced by email_send. */
26
+ allowedRecipients: string[];
27
+ /** Inbound: whose mail this account may hand to an agent. Enforced by fetchInbox. */
28
+ allowedSenders: string[];
29
+ /** Agent ids this account is restricted to. Empty = every agent. */
30
+ allowedAgents: string[];
31
+ };
32
+ /** An account can send only if it has somewhere to send through. */
33
+ export declare function canSend(a: EmailAccount): boolean;
34
+ /** …and can be read only if it has a mailbox to read. */
35
+ export declare function canRead(a: EmailAccount): boolean;
36
+ /** Split a comma/newline-separated allowlist into patterns. */
37
+ export declare function parsePatterns(raw: string | undefined): string[];
38
+ /**
39
+ * Does `address` match any of `patterns`? `*` is the only wildcard and matches
40
+ * any run of characters, so `*@example.com` and a bare `*` both work; anything
41
+ * else is compared literally. Case-insensitive.
42
+ *
43
+ * An empty pattern list means "no allowlist configured" and allows everything —
44
+ * the restriction is opt-in, see the design doc.
45
+ */
46
+ export declare function matchesAllowlist(address: string, patterns: string[]): boolean;
47
+ /**
48
+ * Pull the bare address out of a recipient string, so a display-name form
49
+ * ("Ada <ada@example.com>") is checked against the allowlist by its address and
50
+ * not by the whole label.
51
+ */
52
+ export declare function bareAddress(recipient: string): string;
53
+ /** Every enabled `email` service, with defaults applied and secrets revealed.
54
+ * Direction is not filtered here — ask canSend()/canRead(). */
55
+ export declare function emailAccounts(services: ServiceConfig[]): EmailAccount[];
56
+ /**
57
+ * Narrow a list to the accounts one agent may use. A scoped account is removed
58
+ * outright rather than refused later: the agent never sees a mailbox it cannot
59
+ * touch, so it cannot name it, be tricked into naming it, or report that it
60
+ * exists.
61
+ *
62
+ * `agentId` undefined means the caller has no agent identity, and that only
63
+ * happens for callers that already hold full access to CARETAKER_HOME — the
64
+ * `caretaker-cli mcp` stdio server (whose trust boundary IS local process
65
+ * access) and direct in-process calls. Those see everything. Any new surface
66
+ * that executes these tools on behalf of an agent MUST set `ctx.callerAgent`,
67
+ * or it silently opts out of scoping.
68
+ */
69
+ export declare function visibleAccounts(accounts: EmailAccount[], agentId?: string): EmailAccount[];
70
+ /** Configured accounts visible to `agentId`, read from the live config. */
71
+ export declare function listEmailAccounts(agentId?: string): Promise<EmailAccount[]>;
72
+ /** Look an account up by service name, case-insensitively. */
73
+ export declare function findAccount(accounts: EmailAccount[], name: string): EmailAccount | undefined;
74
+ /**
75
+ * Render the markdown an agent already wrote as `body` into the HTML part, so a
76
+ * formatted mail costs one copy of the content instead of two. The wrapper is
77
+ * the whole styling story: `marked` emits bare `<p>`/`<h2>`, and mail clients
78
+ * have no sensible default for those. Inline styles only — clients strip
79
+ * `<style>` blocks and never fetch anything external.
80
+ *
81
+ * ponytail: no sanitizer. This is outbound mail written by the agent, which can
82
+ * already send arbitrary HTML through `email_send`'s `html` argument; the
83
+ * recipient's client is what sanitizes on render.
84
+ */
85
+ export declare function markdownToHtml(markdown: string): string;
86
+ export type OutgoingMail = {
87
+ to: string[];
88
+ cc?: string[];
89
+ bcc?: string[];
90
+ subject: string;
91
+ /** Plain-text part. Always sent — the fallback when `html` is set. */
92
+ body: string;
93
+ /** Optional HTML part. Set together with `body` it makes a multipart/alternative. */
94
+ html?: string;
95
+ };
96
+ /** Send one message (plain text, plus an HTML alternative when given).
97
+ * Returns the SMTP message id. */
98
+ export declare function sendEmail(account: EmailAccount, mail: OutgoingMail, signal?: AbortSignal): Promise<string>;
99
+ /** Hard ceiling on messages per call, whatever the caller asks for. */
100
+ export declare const MAX_FETCH = 50;
101
+ /** How many unread messages we are willing to look at to fill one window.
102
+ * Only matters with a sender allowlist: unlisted mail is skipped and left
103
+ * unread, so without a bound a mailbox full of junk would be re-scanned
104
+ * forever. The scan itself is one cheap ENVELOPE fetch, not a download. */
105
+ export declare const MAX_SCAN = 200;
106
+ /** Hard ceiling on the body text handed to the model, per message. */
107
+ export declare const MAX_BODY_CHARS = 8000;
108
+ export type InboundMessage = {
109
+ uid: number;
110
+ from: string;
111
+ to: string;
112
+ subject: string;
113
+ date: string;
114
+ body: string;
115
+ /** Set when the body hit MAX_BODY_CHARS. */
116
+ truncated?: boolean;
117
+ attachments: string[];
118
+ };
119
+ /** ISO-8601 for whatever the parser or the server gave us; '' when unusable. */
120
+ export declare function isoDate(value: Date | string | undefined): string;
121
+ export declare function clampLimit(limit: unknown): number;
122
+ export declare function truncateBody(text: string): {
123
+ body: string;
124
+ truncated: boolean;
125
+ };
126
+ /** Best-effort plain text for a message: the text/plain part, else the HTML converted. */
127
+ export declare function messageText(parsed: {
128
+ text?: string;
129
+ html?: string | false;
130
+ }): string;
131
+ export type FetchOptions = {
132
+ limit?: number;
133
+ /** Unread only (default true) — the whole point of the \Seen convention. */
134
+ unreadOnly?: boolean;
135
+ /** Server-side subject substring filter. */
136
+ subject?: string;
137
+ /** Mark the delivered messages \Seen (default true), so the next run skips them. */
138
+ markSeen?: boolean;
139
+ /** Run-level abort (ctx.signal): closes the connection mid-flight. */
140
+ signal?: AbortSignal;
141
+ };
142
+ /** Read the oldest matching messages from INBOX. */
143
+ export declare function fetchInbox(account: EmailAccount, opts?: FetchOptions): Promise<{
144
+ messages: InboundMessage[];
145
+ refused: number;
146
+ scanTruncated?: boolean;
147
+ }>;
148
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/lib/email.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,QAAS,CAAC;AAarC,4EAA4E;AAC5E,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,qFAAqF;IACrF,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,oEAAoE;IACpE,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,oEAAoE;AACpE,wBAAgB,OAAO,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAEhD;AAED,yDAAyD;AACzD,wBAAgB,OAAO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,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,oDAAoD;AACpD,wBAAsB,UAAU,CAC9B,OAAO,EAAE,YAAY,EACrB,IAAI,GAAE,YAAiB,GACtB,OAAO,CAAC;IAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CA0FnF"}
@@ -0,0 +1,328 @@
1
+ // Email accounts for the agent-facing email tools.
2
+ //
3
+ // An account is a `type: 'email'` entry in the Services collection
4
+ // (`caretaker.json` → `scheduler.tasks`, see store/json.ts). The record holds
5
+ // both halves of a mailbox: IMAP for reading and SMTP for sending, each
6
+ // independently optional — an account with no `smtpHost` cannot send, one with
7
+ // no `imapHost` cannot read. The SMTP credentials default to the IMAP ones —
8
+ // one mailbox, one login, in the common case — and only need their own fields
9
+ // when the provider splits them.
10
+ //
11
+ // This module owns account resolution, the address allowlists, and the two
12
+ // network operations. Everything except sendEmail()/fetchInbox() is pure, which
13
+ // is where the tests live.
14
+ import nodemailer from 'nodemailer';
15
+ import { ImapFlow } from 'imapflow';
16
+ import { simpleParser } from 'mailparser';
17
+ import TurndownService from 'turndown';
18
+ import { marked } from 'marked';
19
+ import { loadConfig } from '../store/json.js';
20
+ import { decrypt, isEncrypted } from './encryption.js';
21
+ /**
22
+ * Ceiling on one mail network operation, and the same reasoning as
23
+ * `NET_TIMEOUT_MS` in lib/task_git.ts: an unattended run must not hang forever
24
+ * on a wedged server. The abort also carries `ctx.signal`, so Pause and the
25
+ * task's wall-clock budget reach *inside* an in-flight connection — the loop
26
+ * only checks the signal between turns, and would otherwise sit awaiting this
27
+ * tool call.
28
+ */
29
+ export const NET_TIMEOUT_MS = 60_000;
30
+ /** Arm `close` on abort or timeout; returns the disarm to call in a finally. */
31
+ function armAbort(close, signal) {
32
+ const timer = setTimeout(close, NET_TIMEOUT_MS);
33
+ const onAbort = () => close();
34
+ signal?.addEventListener('abort', onAbort, { once: true });
35
+ return () => {
36
+ clearTimeout(timer);
37
+ signal?.removeEventListener('abort', onAbort);
38
+ };
39
+ }
40
+ /** An account can send only if it has somewhere to send through. */
41
+ export function canSend(a) {
42
+ return !!a.smtpHost;
43
+ }
44
+ /** …and can be read only if it has a mailbox to read. */
45
+ export function canRead(a) {
46
+ return !!a.imapHost;
47
+ }
48
+ function reveal(value) {
49
+ if (!value)
50
+ return '';
51
+ return isEncrypted(value) ? decrypt(value) : value;
52
+ }
53
+ /** Split a comma/newline-separated allowlist into patterns. */
54
+ export function parsePatterns(raw) {
55
+ return (raw ?? '')
56
+ .split(/[,\n;]/)
57
+ .map((p) => p.trim())
58
+ .filter(Boolean);
59
+ }
60
+ /**
61
+ * Does `address` match any of `patterns`? `*` is the only wildcard and matches
62
+ * any run of characters, so `*@example.com` and a bare `*` both work; anything
63
+ * else is compared literally. Case-insensitive.
64
+ *
65
+ * An empty pattern list means "no allowlist configured" and allows everything —
66
+ * the restriction is opt-in, see the design doc.
67
+ */
68
+ export function matchesAllowlist(address, patterns) {
69
+ if (patterns.length === 0)
70
+ return true;
71
+ const addr = address.trim().toLowerCase();
72
+ return patterns.some((pattern) => {
73
+ const rx = new RegExp('^' +
74
+ pattern
75
+ .toLowerCase()
76
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
77
+ .replace(/\\\*/g, '.*') +
78
+ '$');
79
+ return rx.test(addr);
80
+ });
81
+ }
82
+ /**
83
+ * Pull the bare address out of a recipient string, so a display-name form
84
+ * ("Ada <ada@example.com>") is checked against the allowlist by its address and
85
+ * not by the whole label.
86
+ */
87
+ export function bareAddress(recipient) {
88
+ const angled = recipient.match(/<([^>]*)>/);
89
+ return (angled ? angled[1] : recipient).trim();
90
+ }
91
+ /** Every enabled `email` service, with defaults applied and secrets revealed.
92
+ * Direction is not filtered here — ask canSend()/canRead(). */
93
+ export function emailAccounts(services) {
94
+ return services
95
+ .filter((s) => s.type === 'email' && s.enabled)
96
+ .map((s) => ({
97
+ name: s.name,
98
+ from: (s.smtpFrom || s.imapUser || '').trim(),
99
+ smtpHost: (s.smtpHost ?? '').trim(),
100
+ // ponytail: 587 covers plaintext-or-STARTTLS, which is what smtpSecure
101
+ // false means; a 465 account has to say so via the port anyway.
102
+ smtpPort: s.smtpPort || (s.smtpSecure ? 465 : 587),
103
+ smtpSecure: s.smtpSecure ?? false,
104
+ smtpUser: (s.smtpUser || s.imapUser || '').trim(),
105
+ smtpPassword: reveal(s.smtpPassword || s.imapPassword),
106
+ imapHost: (s.imapHost ?? '').trim(),
107
+ imapPort: s.imapPort || (s.imapSecure === false ? 143 : 993),
108
+ imapSecure: s.imapSecure !== false,
109
+ imapUser: (s.imapUser ?? '').trim(),
110
+ imapPassword: reveal(s.imapPassword),
111
+ allowedRecipients: parsePatterns(s.allowedRecipients),
112
+ allowedSenders: parsePatterns(s.allowedSenders),
113
+ allowedAgents: (s.allowedAgents ?? []).filter(Boolean),
114
+ }));
115
+ }
116
+ /**
117
+ * Narrow a list to the accounts one agent may use. A scoped account is removed
118
+ * outright rather than refused later: the agent never sees a mailbox it cannot
119
+ * touch, so it cannot name it, be tricked into naming it, or report that it
120
+ * exists.
121
+ *
122
+ * `agentId` undefined means the caller has no agent identity, and that only
123
+ * happens for callers that already hold full access to CARETAKER_HOME — the
124
+ * `caretaker-cli mcp` stdio server (whose trust boundary IS local process
125
+ * access) and direct in-process calls. Those see everything. Any new surface
126
+ * that executes these tools on behalf of an agent MUST set `ctx.callerAgent`,
127
+ * or it silently opts out of scoping.
128
+ */
129
+ export function visibleAccounts(accounts, agentId) {
130
+ if (!agentId)
131
+ return accounts;
132
+ return accounts.filter((a) => a.allowedAgents.length === 0 || a.allowedAgents.includes(agentId));
133
+ }
134
+ /** Configured accounts visible to `agentId`, read from the live config. */
135
+ export async function listEmailAccounts(agentId) {
136
+ const config = await loadConfig();
137
+ return visibleAccounts(emailAccounts(config.scheduler?.tasks ?? []), agentId);
138
+ }
139
+ /** Look an account up by service name, case-insensitively. */
140
+ export function findAccount(accounts, name) {
141
+ const wanted = name.trim().toLowerCase();
142
+ return accounts.find((a) => a.name.trim().toLowerCase() === wanted);
143
+ }
144
+ /**
145
+ * Render the markdown an agent already wrote as `body` into the HTML part, so a
146
+ * formatted mail costs one copy of the content instead of two. The wrapper is
147
+ * the whole styling story: `marked` emits bare `<p>`/`<h2>`, and mail clients
148
+ * have no sensible default for those. Inline styles only — clients strip
149
+ * `<style>` blocks and never fetch anything external.
150
+ *
151
+ * ponytail: no sanitizer. This is outbound mail written by the agent, which can
152
+ * already send arbitrary HTML through `email_send`'s `html` argument; the
153
+ * recipient's client is what sanitizes on render.
154
+ */
155
+ export function markdownToHtml(markdown) {
156
+ const body = marked.parse(markdown, { async: false, gfm: true });
157
+ return ('<div style="font-family:-apple-system,Segoe UI,Helvetica,Arial,sans-serif;' +
158
+ 'font-size:14px;line-height:1.5;color:#1a1a1a;max-width:40em">' +
159
+ body +
160
+ '</div>');
161
+ }
162
+ /** Send one message (plain text, plus an HTML alternative when given).
163
+ * Returns the SMTP message id. */
164
+ export async function sendEmail(account, mail, signal) {
165
+ if (signal?.aborted)
166
+ throw new Error('aborted before connecting');
167
+ const transport = nodemailer.createTransport({
168
+ host: account.smtpHost,
169
+ port: account.smtpPort,
170
+ secure: account.smtpSecure,
171
+ // A server with auth disabled (the GreenMail fixture) rejects an AUTH
172
+ // command outright, so omit the credentials rather than send empty ones.
173
+ auth: account.smtpUser ? { user: account.smtpUser, pass: account.smtpPassword } : undefined,
174
+ });
175
+ const disarm = armAbort(() => transport.close(), signal);
176
+ try {
177
+ const info = await transport.sendMail({
178
+ from: account.from,
179
+ to: mail.to,
180
+ cc: mail.cc,
181
+ bcc: mail.bcc,
182
+ subject: mail.subject,
183
+ text: mail.body,
184
+ // Both parts → nodemailer builds multipart/alternative on its own.
185
+ ...(mail.html ? { html: mail.html } : {}),
186
+ });
187
+ return info.messageId;
188
+ }
189
+ finally {
190
+ disarm();
191
+ transport.close();
192
+ }
193
+ }
194
+ // ─── Inbound ──────────────────────────────────────────────────────────────
195
+ //
196
+ // There is no `email` scheduler strategy and no stored UID cursor: an inbound
197
+ // workflow is a `heartbeat` service whose prompt tells the agent to call
198
+ // email_fetch, and "already handled" is the IMAP `\Seen` flag — server state,
199
+ // shared with the user's own mail client. Two behaviours on one account are two
200
+ // heartbeats, which is also how a per-subject triage is expressed.
201
+ /** Hard ceiling on messages per call, whatever the caller asks for. */
202
+ export const MAX_FETCH = 50;
203
+ /** How many unread messages we are willing to look at to fill one window.
204
+ * Only matters with a sender allowlist: unlisted mail is skipped and left
205
+ * unread, so without a bound a mailbox full of junk would be re-scanned
206
+ * forever. The scan itself is one cheap ENVELOPE fetch, not a download. */
207
+ export const MAX_SCAN = 200;
208
+ /** Hard ceiling on the body text handed to the model, per message. */
209
+ export const MAX_BODY_CHARS = 8000;
210
+ /** ISO-8601 for whatever the parser or the server gave us; '' when unusable. */
211
+ export function isoDate(value) {
212
+ if (!value)
213
+ return '';
214
+ const d = value instanceof Date ? value : new Date(value);
215
+ return Number.isNaN(d.getTime()) ? '' : d.toISOString();
216
+ }
217
+ export function clampLimit(limit) {
218
+ const n = Math.trunc(Number(limit));
219
+ if (!Number.isFinite(n) || n < 1)
220
+ return 10;
221
+ return Math.min(n, MAX_FETCH);
222
+ }
223
+ export function truncateBody(text) {
224
+ const clean = text.replace(/\r\n/g, '\n').trim();
225
+ if (clean.length <= MAX_BODY_CHARS)
226
+ return { body: clean, truncated: false };
227
+ return { body: clean.slice(0, MAX_BODY_CHARS) + '\n[…truncated]', truncated: true };
228
+ }
229
+ const turndown = new TurndownService();
230
+ /** Best-effort plain text for a message: the text/plain part, else the HTML converted. */
231
+ export function messageText(parsed) {
232
+ if (parsed.text?.trim())
233
+ return parsed.text;
234
+ if (typeof parsed.html === 'string' && parsed.html.trim())
235
+ return turndown.turndown(parsed.html);
236
+ return '';
237
+ }
238
+ /** Read the oldest matching messages from INBOX. */
239
+ export async function fetchInbox(account, opts = {}) {
240
+ const limit = clampLimit(opts.limit);
241
+ const markSeen = opts.markSeen !== false;
242
+ if (opts.signal?.aborted)
243
+ throw new Error('aborted before connecting');
244
+ const client = new ImapFlow({
245
+ host: account.imapHost,
246
+ port: account.imapPort,
247
+ secure: account.imapSecure,
248
+ auth: { user: account.imapUser, pass: account.imapPassword },
249
+ logger: false,
250
+ });
251
+ const disarm = armAbort(() => client.close(), opts.signal);
252
+ try {
253
+ await client.connect();
254
+ }
255
+ catch (err) {
256
+ disarm();
257
+ throw err;
258
+ }
259
+ const lock = await client.getMailboxLock('INBOX');
260
+ try {
261
+ // Only the two criteria every server implements the same way. The sender
262
+ // allowlist is applied below, host-side: IMAP `SEARCH FROM` is substring by
263
+ // spec but not in practice (GreenMail matches whole addresses only and
264
+ // errors on a leading `@`), and `OR` is just as uneven — a filter that
265
+ // silently returns nothing on some servers is worse than no filter.
266
+ const criteria = {};
267
+ if (opts.unreadOnly !== false)
268
+ criteria.seen = false;
269
+ if (opts.subject?.trim())
270
+ criteria.subject = opts.subject.trim();
271
+ const uids = (await client.search(Object.keys(criteria).length ? criteria : { all: true }, {
272
+ uid: true,
273
+ }));
274
+ if (!uids || uids.length === 0)
275
+ return { messages: [], refused: 0 };
276
+ // Oldest first: a queue is processed from the front, never sampled.
277
+ const window = uids.slice(0, MAX_SCAN);
278
+ const scanTruncated = uids.length > window.length;
279
+ // One cheap pass over envelopes decides who is allowed, so mail we may not
280
+ // read is never downloaded.
281
+ const allowed = [];
282
+ let refused = 0;
283
+ for await (const msg of client.fetch(window.join(','), { envelope: true, uid: true }, { uid: true })) {
284
+ const address = msg.envelope?.from?.[0]?.address ?? '';
285
+ if (matchesAllowlist(address, account.allowedSenders)) {
286
+ if (allowed.length < limit)
287
+ allowed.push(msg.uid);
288
+ }
289
+ else {
290
+ refused++;
291
+ }
292
+ if (allowed.length >= limit)
293
+ break;
294
+ }
295
+ const messages = [];
296
+ for (const uid of allowed) {
297
+ const msg = await client.fetchOne(String(uid), { source: true, internalDate: true }, { uid: true });
298
+ if (!msg || !msg.source)
299
+ continue;
300
+ const parsed = await simpleParser(msg.source);
301
+ const { body, truncated } = truncateBody(messageText(parsed));
302
+ messages.push({
303
+ uid,
304
+ from: parsed.from?.text ?? '',
305
+ to: parsed.to?.text ?? '',
306
+ subject: parsed.subject ?? '',
307
+ // The server's INTERNALDATE always exists; a Date header may be absent
308
+ // or malformed, and mailparser then leaves the field undefined. (imapflow
309
+ // types internalDate as string | Date depending on the fetch shape.)
310
+ date: isoDate(parsed.date ?? msg.internalDate),
311
+ body,
312
+ ...(truncated ? { truncated } : {}),
313
+ attachments: (parsed.attachments ?? []).map((a) => a.filename ?? '(unnamed)'),
314
+ });
315
+ }
316
+ // Only what the agent actually received is marked read — a refused message
317
+ // is left untouched for the human.
318
+ if (markSeen && messages.length) {
319
+ await client.messageFlagsAdd(messages.map((m) => m.uid).join(','), ['\\Seen'], { uid: true });
320
+ }
321
+ return { messages, refused, ...(scanTruncated ? { scanTruncated } : {}) };
322
+ }
323
+ finally {
324
+ disarm();
325
+ lock.release();
326
+ await client.logout().catch(() => client.close());
327
+ }
328
+ }
@@ -0,0 +1,13 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import type { Tool } from '../harness/tools/index.js';
3
+ import type { AgentConfig } from '../types.js';
4
+ export declare const TASK_PREFIX = "mcp__task__";
5
+ export declare const EMAIL_PREFIX = "mcp__email__";
6
+ export declare function builtinMcpTools(): Tool[];
7
+ export declare function buildBuiltinMcpServer(info?: {
8
+ name: string;
9
+ version: string;
10
+ }, opts?: {
11
+ callerAgent?: AgentConfig;
12
+ }): Server;
13
+ //# sourceMappingURL=builtin_server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtin_server.d.ts","sourceRoot":"","sources":["../../src/mcp/builtin_server.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAQ3C,wBAAgB,eAAe,IAAI,IAAI,EAAE,CAExC;AAED,wBAAgB,qBAAqB,CACnC,IAAI,GAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAiD,EACtF,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,WAAW,CAAA;CAAO,GACvC,MAAM,CAoCR"}
@@ -0,0 +1,65 @@
1
+ // Shared builder: wraps the built-in `mcp__<ns>__*` registry tools as an MCP
2
+ // Server. Used by BOTH the per-task HTTP bridge (cli/web/mcp_bridge.ts) and the
3
+ // general stdio subcommand (cli/mcp.ts) so this surface has one definition and
4
+ // one wrapping. Two namespaces today — `task` (drive the autonomous task state
5
+ // machine) and `email` (send mail through a configured account); a new tool in
6
+ // either is picked up by both consumers through the prefix filter, never a
7
+ // second allowlist.
8
+ //
9
+ // The tools are context-free (they take task_id / account by argument), so a
10
+ // stub ToolContext is sufficient — except for the caller's identity, which the
11
+ // email tools use to scope which accounts exist for this agent. The HTTP bridge
12
+ // passes it (resolved from the per-run token); the stdio server does not have
13
+ // one and is unscoped by design, its trust boundary being local process access
14
+ // to CARETAKER_HOME.
15
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
16
+ import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
17
+ import { tools as registry } from '../harness/tools/instance.js';
18
+ export const TASK_PREFIX = 'mcp__task__';
19
+ export const EMAIL_PREFIX = 'mcp__email__';
20
+ const SERVED_PREFIXES = [TASK_PREFIX, EMAIL_PREFIX];
21
+ /** `mcp__task__task_complete` → `task_complete`, `mcp__email__email_send` → `email_send`. */
22
+ function externalName(name) {
23
+ return name.replace(/^mcp__[a-z]+__/, '');
24
+ }
25
+ export function builtinMcpTools() {
26
+ return registry.list().filter((t) => SERVED_PREFIXES.some((p) => t.name.startsWith(p)));
27
+ }
28
+ export function buildBuiltinMcpServer(info = { name: 'caretaker-task', version: '0.0.0' }, opts = {}) {
29
+ const server = new Server(info, { capabilities: { tools: {} } });
30
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
31
+ tools: builtinMcpTools().map((t) => ({
32
+ name: externalName(t.name),
33
+ description: t.description,
34
+ inputSchema: t.parameters,
35
+ })),
36
+ }));
37
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
38
+ const tool = builtinMcpTools().find((t) => externalName(t.name) === req.params.name);
39
+ if (!tool) {
40
+ return {
41
+ content: [{ type: 'text', text: `Error: unknown tool "${req.params.name}"` }],
42
+ isError: true,
43
+ };
44
+ }
45
+ // ponytail: the task tools ignore ctx entirely; the email tools read only
46
+ // callerAgent. A stub covers the rest.
47
+ const ctx = {
48
+ workingDir: process.cwd(),
49
+ signal: new AbortController().signal,
50
+ readPaths: new Set(),
51
+ callerAgent: opts.callerAgent,
52
+ };
53
+ try {
54
+ const result = await tool.execute(req.params.arguments ?? {}, ctx);
55
+ return { content: [{ type: 'text', text: result.content }] };
56
+ }
57
+ catch (err) {
58
+ return {
59
+ content: [{ type: 'text', text: `Error: ${err?.message ?? String(err)}` }],
60
+ isError: true,
61
+ };
62
+ }
63
+ });
64
+ return server;
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/store/json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM7F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAI3D,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AACD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AACD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AACD,wBAAgB,WAAW,IAAI,MAAM,CA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AAqDF,wBAAsB,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,CAE3D;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA4BlE;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAEzD;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CASxD;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElE;AAMD,wBAAsB,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC,CAO9D;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAExE;AAID;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO5E"}
@@ -90,6 +90,12 @@ export async function saveConfig(c) {
90
90
  task.telegramBotToken = encrypt(task.telegramBotToken);
91
91
  }
92
92
  }
93
+ if (task.type === 'email' && task.imapPassword && !isEncrypted(task.imapPassword)) {
94
+ task.imapPassword = encrypt(task.imapPassword);
95
+ }
96
+ if (task.type === 'email' && task.smtpPassword && !isEncrypted(task.smtpPassword)) {
97
+ task.smtpPassword = encrypt(task.smtpPassword);
98
+ }
93
99
  }
94
100
  }
95
101
  for (const project of c.projects || []) {
@@ -252,6 +252,26 @@ const CLAUDE_CODE_PERMISSION_MODES = [
252
252
  'dontAsk',
253
253
  'plan',
254
254
  ];
255
+ const NAMESPACE_DESCRIPTIONS = {
256
+ mcp__task__: 'Manage autonomous tasks & checklists',
257
+ mcp__email__: 'List the configured email accounts and send mail',
258
+ };
259
+ /** The picker's tool list: one synthetic entry per `mcp__<ns>__` namespace in
260
+ * place of its individual tools, everything else as-is. */
261
+ function namespacedToolList(tools) {
262
+ const namespaces = [
263
+ ...new Set(tools.map((t) => /^mcp__[a-z]+__/.exec(t.name)?.[0]).filter((p) => !!p)),
264
+ ];
265
+ return [
266
+ ...tools.filter((t) => !namespaces.some((p) => t.name.startsWith(p))),
267
+ ...namespaces.map((p) => ({
268
+ name: `${p}*`,
269
+ description: `${NAMESPACE_DESCRIPTIONS[p] ?? p} (enables all ${p}* tools)`,
270
+ parameters: { type: 'object', properties: {} },
271
+ execute: async () => ({ content: '' }),
272
+ })),
273
+ ];
274
+ }
255
275
  // Computes the step sequence for a given form flavor, so claude-code's
256
276
  // skip-tools/plugins/maxTurns + insert-permissionMode branching lives in one
257
277
  // place instead of scattered across every transition.
@@ -283,12 +303,22 @@ function AgentForm({ providers, existingNames, initial, onSave, onCancel, }) {
283
303
  const [systemPrompt, setSystemPrompt] = useState(initial?.systemPrompt ?? '');
284
304
  const [permissionMode, setPermissionMode] = useState(initial?.permissionMode ?? '');
285
305
  const [strictMcp, setStrictMcp] = useState(initial?.strictMcp ?? false);
306
+ // The picker offers one entry per `mcp__<ns>__` namespace (task, email, …),
307
+ // not the individual tools, so a stored per-tool selection is collapsed onto
308
+ // the wildcard. resolveAgentTools expands it back at run time.
286
309
  const normalizeTools = (tools) => {
287
- const hasTaskTools = tools.some((t) => t.startsWith('mcp__task__'));
288
- if (hasTaskTools) {
289
- return [...tools.filter((t) => !t.startsWith('mcp__task__')), 'mcp__task__*'];
290
- }
291
- return tools;
310
+ const wildcards = new Set();
311
+ const rest = tools.filter((t) => {
312
+ const ns = /^mcp__[a-z]+__/.exec(t);
313
+ if (!ns || t.endsWith('*'))
314
+ return !ns;
315
+ wildcards.add(`${ns[0]}*`);
316
+ return false;
317
+ });
318
+ for (const t of tools)
319
+ if (t.endsWith('*') && t.startsWith('mcp__'))
320
+ wildcards.add(t);
321
+ return [...rest, ...wildcards];
292
322
  };
293
323
  const [allowedTools, setAllowedTools] = useState(normalizeTools(initial?.allowedTools ?? []));
294
324
  const [confirmTools, setConfirmTools] = useState(normalizeTools(initial?.confirmTools ?? []));
@@ -387,15 +417,7 @@ function AgentForm({ providers, existingNames, initial, onSave, onCancel, }) {
387
417
  setModel(id);
388
418
  setError(null);
389
419
  setStep(nextAfter('model'));
390
- } })) : ['name', 'provider'].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: model }))] }), _jsxs(Box, { children: [_jsx(Text, { children: "prompt: " }), managed ? (_jsxs(Text, { children: [_jsxs(Text, { children: [(systemPrompt || '(empty)').slice(0, 80), systemPrompt.length > 80 ? '…' : ''] }), _jsx(Text, { dimColor: true, children: ' (managed by plugin)' })] })) : step === 'systemPrompt' ? (_jsx(TextInput, { value: systemPrompt, onChange: setSystemPrompt, onSubmit: advance, placeholder: isEdit ? '(enter to keep current)' : '(optional system prompt)' })) : ['name', 'provider', 'model'].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: systemPrompt || '(empty)' }))] }), !isClaudeCode && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "tools:" }), step === 'tools' ? (_jsx(ToolPicker, { tools: [
391
- ...toolRegistry.list().filter((t) => !t.name.startsWith('mcp__task__')),
392
- {
393
- name: 'mcp__task__*',
394
- description: 'Manage autonomous tasks & checklists (enables all mcp__task__* tools)',
395
- parameters: { type: 'object', properties: {} },
396
- execute: async () => ({ content: '' }),
397
- },
398
- ], allowed: allowedTools, confirm: confirmTools, onChange: (a, c) => {
420
+ } })) : ['name', 'provider'].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: model }))] }), _jsxs(Box, { children: [_jsx(Text, { children: "prompt: " }), managed ? (_jsxs(Text, { children: [_jsxs(Text, { children: [(systemPrompt || '(empty)').slice(0, 80), systemPrompt.length > 80 ? '…' : ''] }), _jsx(Text, { dimColor: true, children: ' (managed by plugin)' })] })) : step === 'systemPrompt' ? (_jsx(TextInput, { value: systemPrompt, onChange: setSystemPrompt, onSubmit: advance, placeholder: isEdit ? '(enter to keep current)' : '(optional system prompt)' })) : ['name', 'provider', 'model'].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: systemPrompt || '(empty)' }))] }), !isClaudeCode && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "tools:" }), step === 'tools' ? (_jsx(ToolPicker, { tools: namespacedToolList(toolRegistry.list()), allowed: allowedTools, confirm: confirmTools, onChange: (a, c) => {
399
421
  setAllowedTools(a);
400
422
  setConfirmTools(c);
401
423
  }, onSubmit: advance })) : ['name', 'provider', 'model', 'systemPrompt'].includes(step) ? (_jsx(Text, { dimColor: true, children: " (pending)" })) : (_jsx(Text, { children: ` ${allowedTools.length === 0 ? '(none)' : formatToolsForDetail(allowedTools, confirmTools)}` }))] })), !isClaudeCode && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "plugins:" }), step === 'plugins' ? (_jsx(PluginPicker, { plugins: discoveredPlugins, value: activePlugins, onChange: setActivePlugins, onSubmit: advance })) : ['name', 'provider', 'model', 'systemPrompt', 'tools'].includes(step) ? (_jsx(Text, { dimColor: true, children: " (pending)" })) : (_jsx(Text, { children: ` ${activePlugins.length === 0 ? '(none)' : activePlugins.join(', ')}` }))] })), _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "mcp:" }), step === 'mcpServers' ? (_jsx(McpPicker, { servers: mcpServers, value: activeMcp, onChange: setActiveMcp, onSubmit: advance })) : ['name', 'provider', 'model', 'systemPrompt', 'tools', 'plugins'].includes(step) ? (_jsx(Text, { dimColor: true, children: " (pending)" })) : (_jsx(Text, { children: ` ${activeMcp.length === 0