@hyperwindmill/caretaker-cli 0.32.0 → 0.33.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.
@@ -1,5 +1,10 @@
1
1
  import type { MessageRecord } from '../../../session/types.js';
2
- export type CycleEvent = {
2
+ export type CycleEvent =
3
+ /** A user turn known only mid-run (the triage prompt is built after listing mail). */
4
+ {
5
+ type: 'user';
6
+ text: string;
7
+ } | {
3
8
  type: 'chunk';
4
9
  text: string;
5
10
  } | {
@@ -20,12 +25,12 @@ export type CycleEvent = {
20
25
  type: 'error';
21
26
  message: string;
22
27
  };
23
- export declare function beginCycleStream(sessionId: string, prompt: MessageRecord): void;
28
+ export declare function beginCycleStream(sessionId: string, prompt: MessageRecord | null): void;
24
29
  export declare function emitCycleEvent(sessionId: string, ev: CycleEvent): void;
25
30
  /** Attach to a running cycle. Snapshot and attach happen synchronously, so no
26
31
  * event can fall between them. `null` when the cycle is not running. */
27
32
  export declare function watchCycleStream(sessionId: string, listener: (ev: CycleEvent) => void): {
28
- prompt: MessageRecord;
33
+ prompt: MessageRecord | null;
29
34
  events: CycleEvent[];
30
35
  unwatch: () => void;
31
36
  } | null;
@@ -1 +1 @@
1
- {"version":3,"file":"cycle_events.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/cycle_events.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE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AC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAWvC,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAEtF;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,GAAG,IAAI,CAgBtE;AAED;yEACyE;AACzE,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,EAAE,EAAE,UAAU,KAAK,IAAI,GACjC;IAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG,IAAI,CAWpF"}
@@ -2,6 +2,8 @@
2
2
  // the chat's own stream events keyed by session id; WebSocket watchers attach
3
3
  // to a running cycle and replay what has happened so far, then follow it.
4
4
  // Finished cycles are dropped from the map — watchers then load from disk.
5
+ // Service runs (heartbeat, email triage) use the same channel keyed by run id;
6
+ // see service_runs.ts.
5
7
  const running = new Map();
6
8
  export function beginCycleStream(sessionId, prompt) {
7
9
  running.set(sessionId, { prompt, events: [], listeners: new Set() });
@@ -1,6 +1,7 @@
1
1
  import { type EmailAccount, type OutgoingMail, type TriageEnvelope, type listUnseenEnvelopes } from '../../../lib/email.js';
2
2
  import type { MessageRecord } from '../../../session/types.js';
3
3
  import type { AgentConfig, CaretakerConfig, ProviderConfig, ServiceConfig } from '../../../types.js';
4
+ import { serviceRunCallbacks } from './service_runs.js';
4
5
  export declare const TRIAGE_INSTRUCTIONS = "You are triaging an inbox. Classify every unread email below into exactly one bucket:\n\n- IMPORTANT: needs action soon: outages, blocked users or customers, failures, direct requests with a deadline.\n- INFORMATION: worth knowing, no immediate action.\n- TRASH: noise: automated notifications without a decision, time tracking, routine bot chatter. Count only, never list.\n\nYour final message must contain only the report, in exactly this shape, starting with \"## IMPORTANT\". Every bucket header is always present; when a table would be empty, write \"_No important emails._\" or \"_No information emails._\" instead of it.\n\n## IMPORTANT\n| From | Subject | Category | Summary | Suggested Action |\n\n## INFORMATION\n| From | Subject | Category | Summary | Suggested Action |\n\n## TRASH\nN emails classified as trash (not listed).\n\nHeaders, bucket names and the table header row are literal and must never be translated, whatever language the rest of the report is written in.\n\nGuidelines:\n- Work from the envelopes (From, Subject, Date). Open a body with email_read only when the subject is not enough.\n- Cluster related notifications into one row.\n- Other tools you have (for example an issue tracker) may be used to understand a reference in an email.\n- Do not send mail: your final message is delivered automatically.";
5
6
  export type TriageStop = 'done' | 'max_turns' | 'aborted';
6
7
  export declare function buildTriagePrompt(p: {
@@ -12,6 +13,10 @@ export declare function buildTriagePrompt(p: {
12
13
  * line on. A truncated run (max_turns/aborted) never yields one: its last
13
14
  * message may be a half-finished "let me read uid 42". */
14
15
  export declare function extractReport(messages: MessageRecord[], stop: TriageStop): string | null;
16
+ /** Envelopes per run: unset → 50; otherwise 1..MAX_SCAN. Only envelopes reach
17
+ * the prompt (one line each), so the cap is the scan window, not email_fetch's
18
+ * MAX_FETCH, which bounds full bodies. */
19
+ export declare function triageLimit(max: number | undefined): number;
15
20
  export declare function triageSubject(prefix: string, count: number, now: Date): string;
16
21
  export declare function parseRecipients(raw: string | undefined): string[];
17
22
  /** Preflight: everything that can be checked before touching IMAP. Looks the
@@ -30,6 +35,8 @@ export type TriageAgentInput = {
30
35
  account: EmailAccount;
31
36
  workingDir: string;
32
37
  signal: AbortSignal;
38
+ /** Live-stream hooks for the log viewer; spread into the run's callbacks. */
39
+ stream: ReturnType<typeof serviceRunCallbacks>;
33
40
  };
34
41
  export type TriageDeps = {
35
42
  load(): Promise<{
@@ -59,5 +66,5 @@ export type TriageOutcome = {
59
66
  marked: boolean;
60
67
  warning?: string;
61
68
  };
62
- export declare function executeTriageRun(service: ServiceConfig, deps: TriageDeps): Promise<TriageOutcome>;
69
+ export declare function executeTriageRun(service: ServiceConfig, deps: TriageDeps, runId?: string): Promise<TriageOutcome>;
63
70
  //# sourceMappingURL=email_triage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"email_triage.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/email_triage.ts"],"names":[],"mappings":"AAQA,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMrG,eAAO,MAAM,mBAAmB,8zCAuBmC,CAAC;AAIpE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;AAE1D,wBAAgB,iBAAiB,CAAC,CAAC,EAAE;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B,GAAG,MAAM,CAST;AAED;;2DAE2D;AAC3D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAkBxF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,GAAG,MAAM,CAI9E;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAEjE;AAED;;;wCAGwC;AACxC,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,aAAa,EAAE,EACzB,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE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,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvF,QAAQ,CACN,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,GAAG,qBAAqB,CAAC,CAAC;IAC7C,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,GAAG,IAAI,IAAI,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAoB9F,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,MAAmB,GACzB,OAAO,CAAC,aAAa,CAAC,CAoJxB"}
@@ -5,8 +5,9 @@
5
5
  // store, IMAP/SMTP wiring) and the scheduler strategy live in
6
6
  // email_triage_agent.ts, so this file is testable with plain fakes.
7
7
  import { randomUUID } from 'node:crypto';
8
- import { canRead, canSend, MAX_FETCH, MAX_SCAN, clampLimit, emailAccounts, markdownToHtml, parsePatterns, } from '../../../lib/email.js';
8
+ import { canRead, canSend, MAX_SCAN, emailAccounts, markdownToHtml, parsePatterns, } from '../../../lib/email.js';
9
9
  import { runningTasks } from './locks.js';
10
+ import { beginServiceRun, emitServiceRunEvent, endServiceRun, newRunId, serviceRunCallbacks, } from './service_runs.js';
10
11
  import { CLAUDE_CODE_DEFAULT_RUN_SECONDS } from './task_roles.js';
11
12
  const DEFAULT_PREFIX = '[Email Triage]';
12
13
  export const TRIAGE_INSTRUCTIONS = `You are triaging an inbox. Classify every unread email below into exactly one bucket:
@@ -68,6 +69,15 @@ export function extractReport(messages, stop) {
68
69
  const m = /^## IMPORTANT\b.*$/m.exec(text);
69
70
  return m ? text.slice(m.index).trim() : null;
70
71
  }
72
+ /** Envelopes per run: unset → 50; otherwise 1..MAX_SCAN. Only envelopes reach
73
+ * the prompt (one line each), so the cap is the scan window, not email_fetch's
74
+ * MAX_FETCH, which bounds full bodies. */
75
+ export function triageLimit(max) {
76
+ if (max == null)
77
+ return 50;
78
+ const n = Math.trunc(Number(max));
79
+ return Number.isFinite(n) && n >= 1 ? Math.min(n, MAX_SCAN) : 50;
80
+ }
71
81
  export function triageSubject(prefix, count, now) {
72
82
  const p = (n) => String(n).padStart(2, '0');
73
83
  const stamp = `${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())} ${p(now.getHours())}:${p(now.getMinutes())}`;
@@ -116,13 +126,14 @@ const assistantNote = (content) => ({
116
126
  content,
117
127
  createdAt: new Date().toISOString(),
118
128
  });
119
- export async function executeTriageRun(service, deps) {
129
+ export async function executeTriageRun(service, deps, runId = newRunId()) {
120
130
  if (runningTasks.has(service.id)) {
121
131
  console.log(`[scheduler] Triage "${service.name}" is already running — skipping.`);
122
132
  return { kind: 'skipped' };
123
133
  }
124
134
  runningTasks.add(service.id);
125
- const runId = `run_${randomUUID().slice(0, 8)}`;
135
+ // Same synchronous block as the lock. No prompt yet: it needs the mail listing.
136
+ beginServiceRun(service.id, runId, null);
126
137
  const ctrl = new AbortController();
127
138
  const timer = setTimeout(() => ctrl.abort(), CLAUDE_CODE_DEFAULT_RUN_SECONDS * 1000);
128
139
  const messages = [];
@@ -157,7 +168,7 @@ export async function executeTriageRun(service, deps) {
157
168
  return await fail(`Triage service "${service.name}" has no report recipients.`);
158
169
  let listing;
159
170
  try {
160
- listing = await deps.listEnvelopes(account, service.triageMaxEmails == null ? MAX_FETCH : clampLimit(service.triageMaxEmails), ctrl.signal);
171
+ listing = await deps.listEnvelopes(account, triageLimit(service.triageMaxEmails), ctrl.signal);
161
172
  }
162
173
  catch (e) {
163
174
  return await fail(`Listing unread mail failed: ${errText(e)}`);
@@ -167,6 +178,7 @@ export async function executeTriageRun(service, deps) {
167
178
  if (scanTruncated) {
168
179
  return await fail(`The oldest ${MAX_SCAN} unread messages are all from senders outside the account's allowedSenders, so triage cannot see newer mail. Read, move or delete them (or widen the allowlist).`);
169
180
  }
181
+ emitServiceRunEvent(runId, 'No unread mail to triage.', 'chunk');
170
182
  return { kind: 'skipped' };
171
183
  }
172
184
  const prompt = buildTriagePrompt({
@@ -180,6 +192,7 @@ export async function executeTriageRun(service, deps) {
180
192
  content: prompt,
181
193
  createdAt: new Date().toISOString(),
182
194
  });
195
+ emitServiceRunEvent(runId, prompt, 'user');
183
196
  let result;
184
197
  try {
185
198
  result = await deps.runAgent({
@@ -189,6 +202,7 @@ export async function executeTriageRun(service, deps) {
189
202
  account,
190
203
  workingDir: service.workingDir || agent.workingDir || process.cwd(),
191
204
  signal: ctrl.signal,
205
+ stream: serviceRunCallbacks(runId),
192
206
  });
193
207
  }
194
208
  catch (e) {
@@ -243,5 +257,6 @@ export async function executeTriageRun(service, deps) {
243
257
  finally {
244
258
  clearTimeout(timer);
245
259
  runningTasks.delete(service.id);
260
+ endServiceRun(service.id, runId);
246
261
  }
247
262
  }
@@ -1 +1 @@
1
- {"version":3,"file":"email_triage_agent.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/email_triage_agent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,E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,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAA;CAAE,CAAC,CA4ChF;AAED,eAAO,MAAM,cAAc,EAAE,UAW5B,CAAC;AAIF,eAAO,MAAM,mBAAmB,EAAE,iBAWjC,CAAC"}
@@ -52,6 +52,7 @@ export async function runTriageAgent(i) {
52
52
  acp,
53
53
  signal: i.signal,
54
54
  }, {
55
+ ...i.stream,
55
56
  onMessage: async (msg) => {
56
57
  messages.push(msg);
57
58
  },
@@ -11,6 +11,6 @@ export declare function matchesCron(cronStr: string, date: Date): boolean;
11
11
  * Runs completely in background, automatically approving tool runs.
12
12
  * Guards against concurrent execution: if the task is already running, skips.
13
13
  */
14
- export declare function executeTaskRun(task: ServiceConfig): Promise<void>;
14
+ export declare function executeTaskRun(task: ServiceConfig, runId?: string): Promise<void>;
15
15
  export declare const HeartbeatStrategy: SchedulerStrategy;
16
16
  //# sourceMappingURL=heartbeat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA2DhE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAgHvE;AAID,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAC"}
1
+ {"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA2DhE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,GAAE,MAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkHnG;AAID,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAC"}
@@ -4,6 +4,7 @@ import { loadAgents, loadConfig } from '../../../store/json.js';
4
4
  import { userMessage } from '../../../session/store.js';
5
5
  import { saveTaskRun } from './logs.js';
6
6
  import { runningTasks } from './locks.js';
7
+ import { beginServiceRun, endServiceRun, newRunId, serviceRunCallbacks } from './service_runs.js';
7
8
  /**
8
9
  * Parses and evaluates a cron expression string against a given Date.
9
10
  * Supports standard syntax fields: minute, hour, day of month, month, day of week.
@@ -66,13 +67,17 @@ export function matchesCron(cronStr, date) {
66
67
  * Runs completely in background, automatically approving tool runs.
67
68
  * Guards against concurrent execution: if the task is already running, skips.
68
69
  */
69
- export async function executeTaskRun(task) {
70
+ export async function executeTaskRun(task, runId = newRunId()) {
70
71
  if (runningTasks.has(task.id)) {
71
72
  console.log(`[scheduler] Task "${task.name}" is already running — skipping.`);
72
73
  return;
73
74
  }
74
75
  runningTasks.add(task.id);
75
- const runId = `run_${randomUUID().slice(0, 8)}`;
76
+ const unattendedNotice = `[UNATTENDED RUN] Note: You are running as an unattended scheduled task. No human is supervising this execution. Act autonomously and complete the task to the best of your ability.`;
77
+ const effectivePrompt = `${unattendedNotice}\n\n${task.prompt}`;
78
+ const startMsg = userMessage(effectivePrompt);
79
+ // Same synchronous block as the lock: the live stream exists as soon as the run does.
80
+ beginServiceRun(task.id, runId, startMsg);
76
81
  console.log(`[scheduler] Starting execution run ${runId} for task: "${task.name}"`);
77
82
  const runMessages = [];
78
83
  try {
@@ -87,10 +92,7 @@ export async function executeTaskRun(task) {
87
92
  }
88
93
  const tools = await harness.resolveAgentTools(agent, harness.tools);
89
94
  const workingDir = task.workingDir || agent.workingDir || process.cwd();
90
- const unattendedNotice = `[UNATTENDED RUN] Note: You are running as an unattended scheduled task. No human is supervising this execution. Act autonomously and complete the task to the best of your ability.`;
91
- const effectivePrompt = `${unattendedNotice}\n\n${task.prompt}`;
92
95
  // Track the initial user prompt inside run history
93
- const startMsg = userMessage(effectivePrompt);
94
96
  runMessages.push(startMsg);
95
97
  // Invoke headless loop run
96
98
  await harness.run({
@@ -101,6 +103,7 @@ export async function executeTaskRun(task) {
101
103
  history: [],
102
104
  workingDir,
103
105
  }, {
106
+ ...serviceRunCallbacks(runId),
104
107
  onMessage: async (msg) => {
105
108
  runMessages.push(msg);
106
109
  },
@@ -161,6 +164,7 @@ export async function executeTaskRun(task) {
161
164
  finally {
162
165
  // Always release the lock so future ticks can re-schedule this task
163
166
  runningTasks.delete(task.id);
167
+ endServiceRun(task.id, runId);
164
168
  }
165
169
  }
166
170
  const lastCheckedMinutes = new Map();
@@ -0,0 +1,12 @@
1
+ import type { RunCallbacks } from '../../../harness/loop.js';
2
+ import type { MessageRecord } from '../../../session/types.js';
3
+ export declare function newRunId(): string;
4
+ /** Must be called in the same synchronous block that takes the service's
5
+ * `runningTasks` lock, so the two can never disagree. */
6
+ export declare function beginServiceRun(serviceId: string, runId: string, prompt: MessageRecord | null): void;
7
+ /** Call only after the run's log is persisted: a watcher reloads the run list on `done`. */
8
+ export declare function endServiceRun(serviceId: string, runId: string): void;
9
+ export declare function activeServiceRun(serviceId: string): string | undefined;
10
+ export declare function emitServiceRunEvent(runId: string, text: string, type: 'user' | 'chunk'): void;
11
+ export declare function serviceRunCallbacks(runId: string): Pick<RunCallbacks, 'onChunk' | 'onThinking' | 'onToolCall' | 'onToolResult'>;
12
+ //# sourceMappingURL=service_runs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service_runs.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/service_runs.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D,wBAAgB,QAAQ,IAAI,MAAM,CAEjC;AAED;0DAC0D;AAC1D,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAGpG;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAGpE;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEtE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAE7F;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,cAAc,CAAC,CAO9E"}
@@ -0,0 +1,39 @@
1
+ // Live channel for service runs (heartbeat, email triage): the run in flight per
2
+ // service, streamed through the task-cycle buffer keyed by run id, so the log
3
+ // viewer can follow a run whether it was started by its cron or by hand.
4
+ //
5
+ // Harness-free on purpose: email_triage.ts imports it and must stay testable
6
+ // with plain fakes.
7
+ import { randomUUID } from 'node:crypto';
8
+ import { beginCycleStream, emitCycleEvent } from './cycle_events.js';
9
+ /** serviceId → runId of the run in flight. */
10
+ const active = new Map();
11
+ export function newRunId() {
12
+ return `run_${randomUUID().slice(0, 8)}`;
13
+ }
14
+ /** Must be called in the same synchronous block that takes the service's
15
+ * `runningTasks` lock, so the two can never disagree. */
16
+ export function beginServiceRun(serviceId, runId, prompt) {
17
+ active.set(serviceId, runId);
18
+ beginCycleStream(runId, prompt);
19
+ }
20
+ /** Call only after the run's log is persisted: a watcher reloads the run list on `done`. */
21
+ export function endServiceRun(serviceId, runId) {
22
+ if (active.get(serviceId) === runId)
23
+ active.delete(serviceId);
24
+ emitCycleEvent(runId, { type: 'done' });
25
+ }
26
+ export function activeServiceRun(serviceId) {
27
+ return active.get(serviceId);
28
+ }
29
+ export function emitServiceRunEvent(runId, text, type) {
30
+ emitCycleEvent(runId, { type, text });
31
+ }
32
+ export function serviceRunCallbacks(runId) {
33
+ return {
34
+ onChunk: (text) => emitCycleEvent(runId, { type: 'chunk', text }),
35
+ onThinking: (text) => emitCycleEvent(runId, { type: 'thinking', text }),
36
+ onToolCall: (id, name, args) => emitCycleEvent(runId, { type: 'tool_call', id, name, args }),
37
+ onToolResult: (id, content) => emitCycleEvent(runId, { type: 'tool_result', id, content }),
38
+ };
39
+ }
@@ -1,9 +1,18 @@
1
+ import type { ServiceConfig } from '../../types.js';
1
2
  export { schedulerLogsDir, schedulerLogPath, ensureSchedulerLogsDir, loadTaskRuns, saveTaskRun, } from './scheduler/logs.js';
2
3
  export { runningTasks } from './scheduler/locks.js';
3
4
  /**
4
5
  * Evaluates all scheduled tasks and triggers execution loops for matching ones.
5
6
  */
6
7
  export declare function runSchedulerTick(): Promise<void>;
8
+ /** Service types a user can run by hand: the cron-driven ones. */
9
+ export declare function isRunnableService(service: ServiceConfig): boolean;
10
+ /**
11
+ * Starts a run of a cron-driven service now, regardless of its schedule or
12
+ * enabled flag, and returns its run id. A run already in flight is not
13
+ * duplicated: its id is returned instead, so the caller can follow it.
14
+ */
15
+ export declare function runServiceNow(service: ServiceConfig): string;
7
16
  /**
8
17
  * Starts the in-process background scheduler loop.
9
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BtD;AAKD;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAQ/C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAM9C"}
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAUpD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BtD;AAGD,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAU5D;AAID;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAQ/C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAM9C"}
@@ -1,7 +1,9 @@
1
1
  import { loadConfig } from '../../store/json.js';
2
- import { HeartbeatStrategy } from './scheduler/heartbeat.js';
2
+ import { HeartbeatStrategy, executeTaskRun } from './scheduler/heartbeat.js';
3
3
  import { TelegramStrategy } from './scheduler/telegram.js';
4
- import { EmailTriageStrategy } from './scheduler/email_triage_agent.js';
4
+ import { EmailTriageStrategy, realTriageDeps } from './scheduler/email_triage_agent.js';
5
+ import { executeTriageRun } from './scheduler/email_triage.js';
6
+ import { activeServiceRun, newRunId } from './scheduler/service_runs.js';
5
7
  import { runTaskHeartbeatTick } from './scheduler/task_strategy.js';
6
8
  import { runMemorySweepTick } from './scheduler/memory_sweep.js';
7
9
  // Re-exported for backwards compatibility with existing consumers (server.ts, tests).
@@ -42,6 +44,26 @@ export async function runSchedulerTick() {
42
44
  console.error('[scheduler] Error evaluating scheduler tasks tick:', err);
43
45
  }
44
46
  }
47
+ /** Service types a user can run by hand: the cron-driven ones. */
48
+ export function isRunnableService(service) {
49
+ return service.type === 'heartbeat' || service.type === 'email_triage';
50
+ }
51
+ /**
52
+ * Starts a run of a cron-driven service now, regardless of its schedule or
53
+ * enabled flag, and returns its run id. A run already in flight is not
54
+ * duplicated: its id is returned instead, so the caller can follow it.
55
+ */
56
+ export function runServiceNow(service) {
57
+ const inFlight = activeServiceRun(service.id);
58
+ if (inFlight)
59
+ return inFlight;
60
+ const runId = newRunId();
61
+ const run = service.type === 'email_triage'
62
+ ? executeTriageRun(service, realTriageDeps, runId)
63
+ : executeTaskRun(service, runId);
64
+ void run.catch((err) => console.error(`[scheduler] Manual run of "${service.name}" failed:`, err));
65
+ return runId;
66
+ }
45
67
  let schedulerIntervalRef = null;
46
68
  /**
47
69
  * Starts the in-process background scheduler loop.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA8ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAe,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAsC9F,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,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C,SAAS,CAAC,CAAS;gBAGjB,IAAI,EAAE;QACrB,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,cAAc,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAMH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,eAAe,IAAI,GAAG;IAIhB,KAAK,CACT,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAsFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqvC3E"}
@@ -23,7 +23,8 @@ import { listForAgent, readSession, deleteSession, computeContextUsage, createSe
23
23
  import { sessionRunScope } from './session_scope.js';
24
24
  import { guardTurnCallbacks } from './turn_guard.js';
25
25
  import { watchCycleStream } from './scheduler/cycle_events.js';
26
- import { startBackgroundScheduler, loadTaskRuns } from './scheduler.js';
26
+ import { startBackgroundScheduler, loadTaskRuns, isRunnableService, runServiceNow } from './scheduler.js';
27
+ import { activeServiceRun } from './scheduler/service_runs.js';
27
28
  import { fsRouter } from './fs.js';
28
29
  import { activationStatus, resolvePlanningEnabled } from './scheduler/task_roles.js';
29
30
  import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog, formKeyFor, KEY_WITHHELD_HINT, } from './voice_proxy.js';
@@ -1336,10 +1337,42 @@ export async function startServer(port, host) {
1336
1337
  if (/^[A-Za-z0-9_-]+$/.test(msg.sessionId))
1337
1338
  unwatchCycle(msg.sessionId);
1338
1339
  return;
1340
+ case 'runService': {
1341
+ const service = (await loadConfig()).scheduler?.tasks?.find((t) => t.id === msg.serviceId);
1342
+ if (!service || !isRunnableService(service)) {
1343
+ post({ type: 'error', message: `Service "${msg.serviceId}" cannot be run manually` });
1344
+ return;
1345
+ }
1346
+ post({ type: 'serviceRunActive', serviceId: service.id, runId: runServiceNow(service) });
1347
+ return;
1348
+ }
1349
+ case 'watchServiceRun': {
1350
+ // A service run lives only in memory while running; its log is on disk after.
1351
+ const { runId } = msg;
1352
+ unwatchCycle(runId);
1353
+ const live = watchCycleStream(runId, (event) => post({ type: 'cycleEvent', sessionId: runId, event }));
1354
+ if (!live) {
1355
+ post({ type: 'cycleEvent', sessionId: runId, event: { type: 'done' } });
1356
+ return;
1357
+ }
1358
+ cycleWatchers.set(runId, live.unwatch);
1359
+ post({
1360
+ type: 'cycleLoaded',
1361
+ sessionId: runId,
1362
+ messages: live.prompt ? [toChatMessage(live.prompt)] : [],
1363
+ running: true,
1364
+ });
1365
+ for (const event of live.events)
1366
+ post({ type: 'cycleEvent', sessionId: runId, event });
1367
+ return;
1368
+ }
1339
1369
  case 'getTaskRuns':
1340
1370
  try {
1341
1371
  const runs = await loadTaskRuns(msg.taskId);
1342
1372
  post({ type: 'taskRunsLoaded', taskId: msg.taskId, runs });
1373
+ const runId = activeServiceRun(msg.taskId);
1374
+ if (runId)
1375
+ post({ type: 'serviceRunActive', serviceId: msg.taskId, runId });
1343
1376
  }
1344
1377
  catch (err) {
1345
1378
  console.error('[web] failed to load task runs:', err);
@@ -1 +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,6BAA6B;IA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Q,GAAG,qBAAqB,CAAC,CAO3C"}
package/dist/lib/email.js CHANGED
@@ -346,7 +346,8 @@ export async function fetchInbox(account, opts = {}) {
346
346
  }
347
347
  /** Oldest unseen envelopes the account may read; no bodies, no flag changes. */
348
348
  export async function listUnseenEnvelopes(account, max, signal) {
349
- const limit = clampLimit(max);
349
+ // ponytail: no clamp beyond >= 1, the MAX_SCAN window already bounds it.
350
+ const limit = Math.max(1, Math.trunc(max) || 1);
350
351
  return withInbox(account, signal, async (client) => {
351
352
  const uidValidity = String(client.mailbox.uidValidity ?? '');
352
353
  const uids = (await client.search({ seen: false }, { uid: true }));