@hyperwindmill/caretaker-cli 0.35.0 → 0.37.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.
@@ -29,6 +29,8 @@ export interface DemoOrchestrator {
29
29
  export declare function createDemoOrchestrator(opts: {
30
30
  token: string;
31
31
  name?: string;
32
+ /** Called when a result is first recorded, before the poll response is built. */
33
+ onResult?: (instanceId: string, result: DemoResult) => void;
32
34
  }): DemoOrchestrator;
33
35
  export declare function startDemoOrchestrator(opts: {
34
36
  port: number;
@@ -1 +1 @@
1
- {"version":3,"file":"orchestrator_demo.d.ts","sourceRoot":"","sources":["../../src/cli/orchestrator_demo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC;IAC3F,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,EAAE,CAAC;IAC1C,SAAS,IAAI,YAAY,EAA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AED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CAC7D,GAAG,gBAAgB,CA2GnB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,IAAI,CAYP"}
@@ -65,7 +65,9 @@ export function createDemoOrchestrator(opts) {
65
65
  }
66
66
  for (const r of body.results ?? []) {
67
67
  if (r && typeof r.id === 'string' && !instResults.has(r.id)) {
68
- instResults.set(r.id, { id: r.id, status: r.status, body: r.body ?? null });
68
+ const recorded = { id: r.id, status: r.status, body: r.body ?? null };
69
+ instResults.set(r.id, recorded);
70
+ opts.onResult?.(instanceId, recorded);
69
71
  }
70
72
  }
71
73
  const pending = (queues.get(instanceId) ?? []).filter((m) => !instResults.has(m.id));
@@ -1 +1 @@
1
- {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/cli/web/openapi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA2cjC,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBxE;AAED;6EAC6E;AAC7E,eAAO,MAAM,oBAAoB,UAAqC,CAAC;AAmCvE,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAI/C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CA2B3E"}
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/cli/web/openapi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAifjC,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBxE;AAED;6EAC6E;AAC7E,eAAO,MAAM,oBAAoB,UAAqC,CAAC;AAmCvE,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAI/C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CA2B3E"}
@@ -230,7 +230,7 @@ const paths = {
230
230
  get: {
231
231
  tags: ['Tasks'],
232
232
  summary: 'List the tasks of a project',
233
- description: 'An unknown project answers an empty list.',
233
+ description: 'An unknown project answers an empty list. Without `after` and `limit` every task comes back, in storage order. With either, tasks come ordered by `seq`: page with `limit` and pass the `seq` of the last task received as `after`; a page shorter than `limit` is the end.',
234
234
  parameters: [
235
235
  ...project,
236
236
  {
@@ -239,8 +239,25 @@ const paths = {
239
239
  description: 'true includes archived tasks.',
240
240
  schema: { type: 'string', enum: ['true'] },
241
241
  },
242
+ {
243
+ name: 'after',
244
+ in: 'query',
245
+ required: false,
246
+ description: 'Return only tasks with a seq greater than this one.',
247
+ schema: { type: 'integer', minimum: 0 },
248
+ },
249
+ {
250
+ name: 'limit',
251
+ in: 'query',
252
+ required: false,
253
+ description: 'At most this many tasks.',
254
+ schema: { type: 'integer', minimum: 1, maximum: 500 },
255
+ },
242
256
  ],
243
- responses: { 200: res('Tasks, with status, checklist and blockedReason.', { type: 'array', items: ref('Task') }) },
257
+ responses: {
258
+ 200: res('Tasks, with status, checklist and blockedReason.', { type: 'array', items: ref('Task') }),
259
+ 400: errorRes('`after` or `limit` is not a valid integer, or `limit` is outside 1..500.'),
260
+ },
244
261
  },
245
262
  post: {
246
263
  tags: ['Tasks'],
@@ -290,9 +307,28 @@ const paths = {
290
307
  get: {
291
308
  tags: ['Tasks'],
292
309
  summary: 'Read the task thread',
293
- description: 'Oldest first. An unknown task answers an empty list.',
294
- parameters: task,
295
- responses: { 200: res('Messages.', { type: 'array', items: ref('TaskMessage') }) },
310
+ description: 'Oldest first (by message id). An unknown task answers an empty list. Without `after` and `limit` the whole thread comes back. To read a long thread in bounded responses, page with `limit` and pass the id of the last message received as `after`; a page shorter than `limit` is the end. To follow a thread, keep the last id and ask only for what came `after` it.',
311
+ parameters: [
312
+ ...task,
313
+ {
314
+ name: 'after',
315
+ in: 'query',
316
+ required: false,
317
+ description: 'Return only messages with an id greater than this one.',
318
+ schema: { type: 'integer', minimum: 0 },
319
+ },
320
+ {
321
+ name: 'limit',
322
+ in: 'query',
323
+ required: false,
324
+ description: 'At most this many messages.',
325
+ schema: { type: 'integer', minimum: 1, maximum: 500 },
326
+ },
327
+ ],
328
+ responses: {
329
+ 200: res('Messages.', { type: 'array', items: ref('TaskMessage') }),
330
+ 400: errorRes('`after` or `limit` is not a valid integer, or `limit` is outside 1..500.'),
331
+ },
296
332
  },
297
333
  post: {
298
334
  tags: ['Tasks'],
@@ -14,6 +14,8 @@ export interface OrchestratorStatus {
14
14
  lastPollAt?: string;
15
15
  lastError?: string;
16
16
  }
17
+ /** Floor between two cycles while results wait; pollSeconds is the maximum gap. */
18
+ export declare const EARLY_POLL_MS = 250;
17
19
  /**
18
20
  * Runs one request against the in-process Hono app. Never throws.
19
21
  * Refuses (404) when the normalized pathname is not documented in OpenAPI.
@@ -25,8 +27,9 @@ export declare function applyMessage(app: AppLike, msg: RemoteMessage): Promise<
25
27
  }>;
26
28
  /**
27
29
  * One register-if-needed + poll cycle. Never throws; failures land in status.
30
+ * Resolves true when the poll round-trip succeeded.
28
31
  */
29
- export declare function runCycle(deps: CycleDeps): Promise<void>;
32
+ export declare function runCycle(deps: CycleDeps): Promise<boolean>;
30
33
  /**
31
34
  * Approves or rejects a pending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E,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CA2C5C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAO1D;AAgRD;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAC7B,OAAO,CAAC,IAAI,GAAG,WAAW,GAAG,aAAa,CAAC,CA4C7C;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC;AAED,mEAAmE;AACnE,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAQvC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,GAAE,OAAO,KAAa,GAAG,IAAI,CAkCrF;AAqBD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,GAAE,OAAO,KAAa,GAAG,IAAI,CAqGrF"}
@@ -2,14 +2,20 @@ import { readFileSync } from 'node:fs';
2
2
  import { decrypt, encrypt } from '../../lib/encryption.js';
3
3
  import { loadLedger, loadOrchestrator, saveLedger, saveOrchestrator, } from '../../store/orchestrator.js';
4
4
  import { isDocumentedRoute } from './openapi.js';
5
- import { endpointUrl, MAX_BODY_BYTES, mergeConfigSave, needsApproval, parseMessage, PROTOCOL_VERSION, recoverLedger, summarizeLedger, trimLedger, validateEndpoint, } from './orchestrator_core.js';
5
+ import { endpointUrl, isUndeliveredResult, MAX_BODY_BYTES, mergeConfigSave, needsApproval, parseMessage, PROTOCOL_VERSION, recoverLedger, summarizeLedger, trimLedger, validateEndpoint, } from './orchestrator_core.js';
6
6
  import { sameHost } from './voice_proxy.js';
7
7
  const OUTBOUND_TIMEOUT_MS = 30_000;
8
+ /** Floor between two cycles while results wait; pollSeconds is the maximum gap. */
9
+ export const EARLY_POLL_MS = 250;
8
10
  let status = { state: 'off' };
9
11
  let registered = false;
10
12
  let recoveredThisProcess = false;
11
13
  let ledgerMutex = Promise.resolve();
12
14
  let loopTimer = null;
15
+ /** The running loop's tick, for pollSoon(); null when no loop runs. */
16
+ let loopTick = null;
17
+ /** A result was produced outside the loop (approve/reject) while a cycle ran. */
18
+ let wakeRequested = false;
13
19
  let loopGen = 0;
14
20
  /** Bumped by every config save. A cycle that started under an older generation
15
21
  * stops touching the ledger, the registration and the status: after a host
@@ -104,10 +110,11 @@ export async function applyMessage(app, msg) {
104
110
  }
105
111
  /**
106
112
  * One register-if-needed + poll cycle. Never throws; failures land in status.
113
+ * Resolves true when the poll round-trip succeeded.
107
114
  */
108
115
  export function runCycle(deps) {
109
116
  const run = cycleChain.then(() => cycleOnce(deps));
110
- cycleChain = run.catch(() => undefined);
117
+ cycleChain = run.then(() => undefined, () => undefined);
111
118
  return run;
112
119
  }
113
120
  async function cycleOnce(deps) {
@@ -118,17 +125,17 @@ async function cycleOnce(deps) {
118
125
  await ensureRecovered(now);
119
126
  const cfg = await loadOrchestrator();
120
127
  if (stale())
121
- return;
128
+ return false;
122
129
  if (!cfg.enabled) {
123
130
  registered = false;
124
131
  status = { state: 'off' };
125
- return;
132
+ return false;
126
133
  }
127
134
  const token = cfg.token ? decrypt(cfg.token) : '';
128
135
  if (!cfg.endpoint || !token) {
129
136
  registered = false;
130
137
  status = { state: 'error', lastError: 'Endpoint and token are required.' };
131
- return;
138
+ return false;
132
139
  }
133
140
  const headers = {
134
141
  authorization: `Bearer ${token}`,
@@ -152,10 +159,10 @@ async function cycleOnce(deps) {
152
159
  signal: AbortSignal.timeout(OUTBOUND_TIMEOUT_MS),
153
160
  });
154
161
  if (stale())
155
- return;
162
+ return false;
156
163
  if (!regRes.ok) {
157
164
  status = { ...status, state: 'error', lastError: `Register failed: HTTP ${regRes.status}` };
158
- return;
165
+ return false;
159
166
  }
160
167
  let regData;
161
168
  try {
@@ -163,15 +170,15 @@ async function cycleOnce(deps) {
163
170
  }
164
171
  catch {
165
172
  if (stale())
166
- return;
173
+ return false;
167
174
  status = { ...status, state: 'error', lastError: 'Register returned non-JSON response.' };
168
- return;
175
+ return false;
169
176
  }
170
177
  if (stale())
171
- return;
178
+ return false;
172
179
  if (!regData || typeof regData !== 'object' || regData.ok !== true) {
173
180
  status = { ...status, state: 'error', lastError: 'Register response did not confirm ok.' };
174
- return;
181
+ return false;
175
182
  }
176
183
  const orchName = typeof regData.name === 'string'
177
184
  ? regData.name
@@ -186,7 +193,7 @@ async function cycleOnce(deps) {
186
193
  const pendingResults = await withLedgerLock(async () => {
187
194
  const records = await loadLedger();
188
195
  return records
189
- .filter((r) => r.state === 'done' && !r.delivered && r.result)
196
+ .filter(isUndeliveredResult)
190
197
  .map((r) => ({
191
198
  id: r.id,
192
199
  status: r.result.status,
@@ -203,18 +210,18 @@ async function cycleOnce(deps) {
203
210
  signal: AbortSignal.timeout(OUTBOUND_TIMEOUT_MS),
204
211
  });
205
212
  if (stale())
206
- return;
213
+ return false;
207
214
  if (pollRes.status === 401 ||
208
215
  pollRes.status === 403 ||
209
216
  pollRes.status === 404 ||
210
217
  pollRes.status === 409) {
211
218
  registered = false;
212
219
  status = { ...status, state: 'error', lastError: `Poll rejected: HTTP ${pollRes.status}` };
213
- return;
220
+ return false;
214
221
  }
215
222
  if (!pollRes.ok) {
216
223
  status = { ...status, state: 'error', lastError: `Poll failed: HTTP ${pollRes.status}` };
217
- return;
224
+ return false;
218
225
  }
219
226
  let pollData;
220
227
  try {
@@ -222,18 +229,18 @@ async function cycleOnce(deps) {
222
229
  }
223
230
  catch {
224
231
  if (stale())
225
- return;
232
+ return false;
226
233
  status = { ...status, state: 'error', lastError: 'Poll returned non-JSON response.' };
227
- return;
234
+ return false;
228
235
  }
229
236
  if (stale())
230
- return;
237
+ return false;
231
238
  if (!pollData ||
232
239
  typeof pollData !== 'object' ||
233
240
  Array.isArray(pollData) ||
234
241
  !Array.isArray(pollData.messages)) {
235
242
  status = { ...status, state: 'error', lastError: 'Poll response missing messages array.' };
236
- return;
243
+ return false;
237
244
  }
238
245
  if (pendingResults.length > 0) {
239
246
  const deliveredIds = new Set(pendingResults.map((r) => r.id));
@@ -261,7 +268,7 @@ async function cycleOnce(deps) {
261
268
  const messages = pollData.messages;
262
269
  for (const raw of messages) {
263
270
  if (stale())
264
- return;
271
+ return false;
265
272
  const parsed = parseMessage(raw);
266
273
  if (parsed === null) {
267
274
  status = { ...status, lastError: 'The orchestrator sent a message without an id.' };
@@ -356,10 +363,23 @@ async function cycleOnce(deps) {
356
363
  await saveLedger(trimLedger(records));
357
364
  });
358
365
  }
366
+ return true;
359
367
  }
360
368
  catch (err) {
361
369
  if (!stale())
362
370
  status = { ...status, state: 'error', lastError: oneLineError(err) };
371
+ return false;
372
+ }
373
+ }
374
+ async function hasUndeliveredResults() {
375
+ return withLedgerLock(async () => (await loadLedger()).some(isUndeliveredResult));
376
+ }
377
+ /** Brings the next poll forward to EARLY_POLL_MS. A cycle in flight reads the flag when it reschedules. */
378
+ function pollSoon() {
379
+ wakeRequested = true;
380
+ if (loopTimer !== null && loopTick !== null) {
381
+ clearTimeout(loopTimer);
382
+ loopTimer = setTimeout(loopTick, EARLY_POLL_MS);
363
383
  }
364
384
  }
365
385
  /**
@@ -391,6 +411,8 @@ export async function resolvePending(app, id, decision) {
391
411
  await saveLedger(trimLedger(records));
392
412
  return { status: 'apply', msg };
393
413
  });
414
+ if (step.status === 'ok')
415
+ pollSoon();
394
416
  if (step.status !== 'apply')
395
417
  return step.status;
396
418
  const applied = await applyMessage(app, step.msg);
@@ -406,6 +428,7 @@ export async function resolvePending(app, id, decision) {
406
428
  rec.result = { status: applied.status, body: encryptJson(applied.body) };
407
429
  await saveLedger(trimLedger(records));
408
430
  });
431
+ pollSoon();
409
432
  return 'ok';
410
433
  }
411
434
  export function orchestratorStatus() {
@@ -433,6 +456,8 @@ export function stopOrchestrator() {
433
456
  clearTimeout(loopTimer);
434
457
  loopTimer = null;
435
458
  }
459
+ loopTick = null;
460
+ wakeRequested = false;
436
461
  }
437
462
  /**
438
463
  * (Re)starts the self-rescheduling poll loop from the saved config.
@@ -444,9 +469,12 @@ export function startOrchestrator(app, fetchImpl = fetch) {
444
469
  const tick = async () => {
445
470
  if (gen !== loopGen)
446
471
  return;
472
+ loopTimer = null; // a wake during this cycle must not start a second chain
473
+ wakeRequested = false; // this cycle delivers whatever already exists
474
+ let ok = false;
447
475
  try {
448
476
  await ensureRecovered(new Date());
449
- await runCycle({ app, fetch: fetchImpl });
477
+ ok = await runCycle({ app, fetch: fetchImpl });
450
478
  }
451
479
  catch (err) {
452
480
  console.error('[orchestrator]', err);
@@ -454,21 +482,26 @@ export function startOrchestrator(app, fetchImpl = fetch) {
454
482
  if (gen !== loopGen)
455
483
  return;
456
484
  let delayMs = 15_000;
485
+ let waiting = false;
457
486
  try {
458
487
  const cfg = await loadOrchestrator();
459
488
  if (!cfg.enabled)
460
489
  return;
461
490
  delayMs = cfg.pollSeconds * 1000;
491
+ if (ok)
492
+ waiting = await hasUndeliveredResults();
462
493
  }
463
494
  catch (err) {
464
495
  console.error('[orchestrator]', err);
465
496
  }
466
497
  if (gen !== loopGen)
467
498
  return;
468
- loopTimer = setTimeout(() => {
469
- void tick();
470
- }, delayMs);
499
+ // No await below this line: a wake landing during the checks above is read here.
500
+ if (ok && (waiting || wakeRequested))
501
+ delayMs = EARLY_POLL_MS;
502
+ loopTimer = setTimeout(() => void tick(), delayMs);
471
503
  };
504
+ loopTick = () => void tick();
472
505
  void tick();
473
506
  }
474
507
  async function buildView() {
@@ -80,4 +80,6 @@ export declare function mergeConfigSave(saved: OrchestratorConfig, input: Config
80
80
  * Request body is included only for `pending` records, with `repositoryToken` masked.
81
81
  */
82
82
  export declare function summarizeLedger(records: LedgerRecord[]): MessageSummary[];
83
+ /** A result recorded and not yet acknowledged by a 2xx /poll. */
84
+ export declare function isUndeliveredResult(r: LedgerRecord): boolean;
83
85
  //# sourceMappingURL=orchestrator_core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"orchestrator_core.d.ts","sourceRoot":"","sources":["../../../src/cli/web/orchestrator_core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGxG,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,cAAc,UAAY,CAAC;AACxC,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBhE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,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E,MAAM,GAAG,OAAO,CAEjF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,YAAY,EAAE,CAahF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CAmBlE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,kBAAkB,EACzB,KAAK,EAAE,WAAW,GACjB;IAAE,MAAM,EAAE,kBAAkB,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAyB1E;AAgBD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,cAAc,EAAE,CAwBzE;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAE5D"}
@@ -217,3 +217,7 @@ export function summarizeLedger(records) {
217
217
  }
218
218
  return out;
219
219
  }
220
+ /** A result recorded and not yet acknowledged by a 2xx /poll. */
221
+ export function isUndeliveredResult(r) {
222
+ return r.state === 'done' && !r.delivered && r.result !== undefined;
223
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAuC,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAQ/F,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;AAuC9F,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IA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E,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GACzC,OAAO,CAAC,IAAI,CAAC,CAwnBf"}
@@ -157,6 +157,18 @@ export class WebSessionController {
157
157
  this.inflight?.abort();
158
158
  }
159
159
  }
160
+ /** `after` + `limit` query parameters of the paged list routes, so a list of
161
+ * any length can be read in bounded responses (an orchestrator caps a result
162
+ * at 1 MB). Absent = no bound, which keeps the unpaged answer unchanged. */
163
+ function parsePaging(after, limit) {
164
+ const a = after === undefined ? 0 : /^\d+$/.test(after) ? Number(after) : NaN;
165
+ const l = limit === undefined ? Infinity : /^\d+$/.test(limit) ? Number(limit) : NaN;
166
+ if (Number.isNaN(a))
167
+ return { error: 'after must be a non-negative integer.' };
168
+ if (Number.isNaN(l) || l < 1 || (l !== Infinity && l > 500))
169
+ return { error: 'limit must be an integer between 1 and 500.' };
170
+ return { after: a, limit: l };
171
+ }
160
172
  export function createApp(apiListener, fetchImpl) {
161
173
  const app = new Hono();
162
174
  registerApiAccess(app, apiListener);
@@ -405,10 +417,22 @@ export function createApp(apiListener, fetchImpl) {
405
417
  if (!/^[a-z0-9][a-z0-9-]*$/.test(id))
406
418
  return c.json({ error: 'Invalid id' }, 400);
407
419
  const includeArchived = c.req.query('archived') === 'true';
420
+ const afterRaw = c.req.query('after');
421
+ const limitRaw = c.req.query('limit');
422
+ const paging = parsePaging(afterRaw, limitRaw);
423
+ if ('error' in paging)
424
+ return c.json({ error: paging.error }, 400);
408
425
  try {
409
426
  const rows = (await runQuery(`SELECT * FROM tasks WHERE projectId = '${id}'`));
410
427
  const filtered = includeArchived ? rows : rows.filter((t) => !t.archived);
411
- return c.json(filtered);
428
+ // Unpaged: store order, unchanged for the GUI. Paged: by seq, the cursor
429
+ // (per project, never reused).
430
+ if (afterRaw === undefined && limitRaw === undefined)
431
+ return c.json(filtered);
432
+ return c.json(filtered
433
+ .filter((t) => t.seq > paging.after)
434
+ .sort((a, b) => a.seq - b.seq)
435
+ .slice(0, paging.limit));
412
436
  }
413
437
  catch (err) {
414
438
  return c.json([], 200);
@@ -462,12 +486,21 @@ export function createApp(apiListener, fetchImpl) {
462
486
  });
463
487
  app.get('/api/tasks/:id/messages', async (c) => {
464
488
  const taskId = c.req.param('id');
489
+ // Paging, so a thread of any length can be read in bounded responses (an
490
+ // orchestrator caps a response at 1 MB): `after` is a message id, `limit`
491
+ // 1..500. Ids are the store's max+1 under a serialized writer, so a new
492
+ // message always sorts after every message already in its thread.
493
+ const paging = parsePaging(c.req.query('after'), c.req.query('limit'));
494
+ if ('error' in paging)
495
+ return c.json({ error: paging.error }, 400);
496
+ const { after, limit } = paging;
465
497
  if (!/^[a-z0-9][a-z0-9-]*$/.test(taskId))
466
498
  return c.json([], 200);
467
499
  try {
468
500
  const rows = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${taskId}'`));
469
- rows.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
470
- return c.json(rows);
501
+ // By id, not createdAt: ids follow insertion order, and createdAt ties.
502
+ rows.sort((a, b) => a.id - b.id);
503
+ return c.json(rows.filter((m) => m.id > after).slice(0, limit));
471
504
  }
472
505
  catch (err) {
473
506
  return c.json([], 200);
@@ -91,6 +91,11 @@ export declare function runQuery(sql: string): Promise<any>;
91
91
  export declare function getTaskById(id: string): Promise<Task | null>;
92
92
  export declare function saveTask(task: Task): Promise<void>;
93
93
  export declare function createTask(task: Omit<Task, 'id' | 'seq' | 'createdAt' | 'updatedAt'>): Promise<Task>;
94
+ /** Longest message content stored. Keeps one message well under the 1 MB an
95
+ * orchestrator accepts per result even fully JSON-escaped (6 bytes a char), so
96
+ * a paged thread can never stall on a single message. Applied at the one
97
+ * insert path, for every writer (agents, people, the host). */
98
+ export declare const MAX_MESSAGE_CHARS = 100000;
94
99
  export declare function addTaskMessage(msg: Omit<TaskMessage, 'id' | 'createdAt'>): Promise<TaskMessage>;
95
100
  export declare function updateTaskMessageContent(id: number, content: string, type?: TaskMessage['messageType']): Promise<void>;
96
101
  /** Close a `cycle` message with its outcome. Only the outcome changes. */
@@ -1 +1 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/store/db.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAKvC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;IACvD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACjC,aAAa,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,UAAU,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,IAAI;IACnB;;kFAE8E;IAC9E,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,MAAM,EAAE,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;IACtF,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;I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ACtC,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAGnB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,eAAe,EAAE,MAAM,CAAC;IACxB;4BACwB;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIzD;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAMtD;AAED,wBAAsB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5D;AAED;;kEAEkE;AAClE,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAahE"}
package/dist/store/db.js CHANGED
@@ -152,11 +152,23 @@ export async function createTask(task) {
152
152
  }
153
153
  return record;
154
154
  }
155
+ /** Longest message content stored. Keeps one message well under the 1 MB an
156
+ * orchestrator accepts per result even fully JSON-escaped (6 bytes a char), so
157
+ * a paged thread can never stall on a single message. Applied at the one
158
+ * insert path, for every writer (agents, people, the host). */
159
+ export const MAX_MESSAGE_CHARS = 100_000;
160
+ function capContent(content) {
161
+ if (typeof content !== 'string' || content.length <= MAX_MESSAGE_CHARS)
162
+ return content;
163
+ const omitted = content.length - MAX_MESSAGE_CHARS;
164
+ return `${content.slice(0, MAX_MESSAGE_CHARS)}\n\n[truncated: ${omitted} characters omitted]`;
165
+ }
155
166
  export async function addTaskMessage(msg) {
156
167
  if (!safeId(msg.taskId))
157
168
  throw new Error(`Invalid task id: ${msg.taskId}`);
158
169
  const payload = {
159
170
  ...msg,
171
+ content: capContent(msg.content),
160
172
  id: '$auto',
161
173
  createdAt: new Date().toISOString(),
162
174
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperwindmill/caretaker-cli",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "type": "module",
5
5
  "description": "Caretaker — in-process agent harness, TUI, file-based state.",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -89,8 +89,8 @@
89
89
  "typescript": "^5.9.3",
90
90
  "typescript-eslint": "^8.72.1",
91
91
  "zod": "^4.6.7",
92
- "caretaker-types": "0.35.0",
93
- "webview-ui": "0.35.0"
92
+ "caretaker-types": "0.37.0",
93
+ "webview-ui": "0.37.0"
94
94
  },
95
95
  "dependencies": {
96
96
  "@agentclientprotocol/sdk": "^2.1.0",