@hyperwindmill/caretaker-cli 0.34.0 → 0.36.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 (38) hide show
  1. package/dist/cli/index.d.ts.map +1 -1
  2. package/dist/cli/index.js +16 -0
  3. package/dist/cli/orchestrator_demo.d.ts +39 -0
  4. package/dist/cli/orchestrator_demo.d.ts.map +1 -0
  5. package/dist/cli/orchestrator_demo.js +98 -0
  6. package/dist/cli/web/api_access.d.ts.map +1 -1
  7. package/dist/cli/web/api_access.js +1 -1
  8. package/dist/cli/web/openapi.d.ts +5 -0
  9. package/dist/cli/web/openapi.d.ts.map +1 -1
  10. package/dist/cli/web/openapi.js +78 -5
  11. package/dist/cli/web/orchestrator.d.ts +51 -0
  12. package/dist/cli/web/orchestrator.d.ts.map +1 -0
  13. package/dist/cli/web/orchestrator.js +596 -0
  14. package/dist/cli/web/orchestrator_core.d.ts +83 -0
  15. package/dist/cli/web/orchestrator_core.d.ts.map +1 -0
  16. package/dist/cli/web/orchestrator_core.js +219 -0
  17. package/dist/cli/web/save_config.d.ts +8 -0
  18. package/dist/cli/web/save_config.d.ts.map +1 -0
  19. package/dist/cli/web/save_config.js +9 -0
  20. package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
  21. package/dist/cli/web/scheduler/task_strategy.js +21 -2
  22. package/dist/cli/web/server.d.ts +3 -0
  23. package/dist/cli/web/server.d.ts.map +1 -1
  24. package/dist/cli/web/server.js +50 -19
  25. package/dist/lib/task_git.d.ts +3 -0
  26. package/dist/lib/task_git.d.ts.map +1 -1
  27. package/dist/lib/task_git.js +29 -0
  28. package/dist/store/db.d.ts +5 -0
  29. package/dist/store/db.d.ts.map +1 -1
  30. package/dist/store/db.js +12 -0
  31. package/dist/store/orchestrator.d.ts +50 -0
  32. package/dist/store/orchestrator.d.ts.map +1 -0
  33. package/dist/store/orchestrator.js +127 -0
  34. package/dist/webview/standalone.css +159 -1
  35. package/dist/webview/standalone.css.map +2 -2
  36. package/dist/webview/standalone.js +784 -504
  37. package/dist/webview/standalone.js.map +4 -4
  38. package/package.json +3 -3
@@ -0,0 +1,219 @@
1
+ import { decrypt, encrypt } from '../../lib/encryption.js';
2
+ import { sameHost } from './voice_proxy.js';
3
+ export const PROTOCOL_VERSION = 1;
4
+ export const MAX_BODY_BYTES = 1_048_576;
5
+ export const LEDGER_SIZE = 500;
6
+ const ALLOWED_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']);
7
+ function isLoopbackHost(hostname) {
8
+ const h = hostname.toLowerCase();
9
+ return h === '127.0.0.1' || h === 'localhost' || h === '[::1]' || h === '::1';
10
+ }
11
+ /**
12
+ * Validates an orchestrator base URL: `https` anywhere, `http` only on loopback,
13
+ * and never with embedded userinfo. Returns null when valid, or an error string.
14
+ */
15
+ export function validateEndpoint(endpoint) {
16
+ let url;
17
+ try {
18
+ url = new URL(endpoint);
19
+ }
20
+ catch {
21
+ return 'Endpoint must be a valid URL.';
22
+ }
23
+ if (url.username || url.password) {
24
+ return 'Endpoint URL must not contain credentials.';
25
+ }
26
+ if (url.protocol === 'https:')
27
+ return null;
28
+ if (url.protocol === 'http:') {
29
+ return isLoopbackHost(url.hostname)
30
+ ? null
31
+ : 'Only https:// endpoints are allowed (http:// is allowed only for localhost, 127.0.0.1, or [::1]).';
32
+ }
33
+ return 'Endpoint must use https:// (or http:// on loopback).';
34
+ }
35
+ /**
36
+ * Clamps poll interval in seconds to 5..3600, defaulting to 15.
37
+ */
38
+ export function clampPollSeconds(value) {
39
+ const n = typeof value === 'number'
40
+ ? value
41
+ : typeof value === 'string' && value.trim() !== ''
42
+ ? Number(value)
43
+ : NaN;
44
+ if (!Number.isFinite(n))
45
+ return 15;
46
+ return Math.min(3600, Math.max(5, Math.round(n)));
47
+ }
48
+ /**
49
+ * Builds `${endpoint without trailing slashes}/${call}`.
50
+ */
51
+ export function endpointUrl(endpoint, call) {
52
+ return `${endpoint.replace(/\/+$/, '')}/${call}`;
53
+ }
54
+ /**
55
+ * Parses and normalizes an incoming orchestrator message.
56
+ * - `null`: no usable id (drop, not ledgered).
57
+ * - `{ id, error }`: ledger a 400 result.
58
+ * - `RemoteMessage`: `path` rewritten to normalized pathname + query.
59
+ */
60
+ export function parseMessage(raw) {
61
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
62
+ return null;
63
+ const r = raw;
64
+ if (typeof r.id !== 'string' || r.id.length === 0)
65
+ return null;
66
+ const id = r.id;
67
+ if (typeof r.method !== 'string') {
68
+ return { id, error: 'Message method must be a string.' };
69
+ }
70
+ const method = r.method.toUpperCase();
71
+ if (!ALLOWED_METHODS.has(method)) {
72
+ return { id, error: `Unsupported HTTP method: ${method}` };
73
+ }
74
+ if (typeof r.path !== 'string' || !r.path.startsWith('/') || r.path.startsWith('//')) {
75
+ return { id, error: 'Message path must start with a single /.' };
76
+ }
77
+ let normalized;
78
+ try {
79
+ normalized = new URL(r.path, 'http://x');
80
+ }
81
+ catch {
82
+ return { id, error: 'Invalid message path.' };
83
+ }
84
+ if (normalized.origin !== 'http://x' || !normalized.pathname.startsWith('/')) {
85
+ return { id, error: 'Invalid message path.' };
86
+ }
87
+ const msg = {
88
+ id,
89
+ method,
90
+ path: `${normalized.pathname}${normalized.search}`,
91
+ };
92
+ if ('body' in r && r.body !== undefined) {
93
+ msg.body = r.body;
94
+ }
95
+ return msg;
96
+ }
97
+ /**
98
+ * True when the policy requires manual approval for this HTTP method.
99
+ */
100
+ export function needsApproval(policy, method) {
101
+ return policy === 'approve' && method.toUpperCase() !== 'GET';
102
+ }
103
+ /**
104
+ * Boot recovery: every `applying` record becomes `done` with a 500 result
105
+ * and its request body removed.
106
+ */
107
+ export function recoverLedger(records, now) {
108
+ const interruptedBody = encrypt(JSON.stringify({ error: 'Interrupted by a restart; outcome unknown.' }));
109
+ const resolvedAt = now.toISOString();
110
+ return records.map((r) => {
111
+ if (r.state !== 'applying')
112
+ return r;
113
+ const { body: _removed, ...rest } = r;
114
+ return {
115
+ ...rest,
116
+ state: 'done',
117
+ result: { status: 500, body: interruptedBody },
118
+ resolvedAt,
119
+ };
120
+ });
121
+ }
122
+ /**
123
+ * Keeps every record that is not (done && delivered), then the newest
124
+ * done+delivered ones until the total is LEDGER_SIZE. Order preserved.
125
+ */
126
+ export function trimLedger(records) {
127
+ if (records.length <= LEDGER_SIZE)
128
+ return records;
129
+ let pinned = 0;
130
+ let deliveredTotal = 0;
131
+ for (const r of records) {
132
+ if (r.state === 'done' && r.delivered)
133
+ deliveredTotal++;
134
+ else
135
+ pinned++;
136
+ }
137
+ const keepDelivered = Math.max(0, LEDGER_SIZE - pinned);
138
+ let toDrop = Math.max(0, deliveredTotal - keepDelivered);
139
+ if (toDrop === 0)
140
+ return records;
141
+ return records.filter((r) => {
142
+ if (r.state === 'done' && r.delivered && toDrop > 0) {
143
+ toDrop--;
144
+ return false;
145
+ }
146
+ return true;
147
+ });
148
+ }
149
+ /**
150
+ * Applies settings-save rules. A blank token keeps the stored blob unless the
151
+ * endpoint host changed (in which case the token is dropped and `purgeLedger` is true).
152
+ */
153
+ export function mergeConfigSave(saved, input) {
154
+ const endpoint = typeof input.endpoint === 'string' ? input.endpoint.trim() : '';
155
+ if (endpoint !== '') {
156
+ const err = validateEndpoint(endpoint);
157
+ if (err)
158
+ return { error: err };
159
+ }
160
+ const hostChanged = saved.endpoint !== endpoint && !sameHost(saved.endpoint, endpoint);
161
+ const typedToken = typeof input.token === 'string' ? input.token.trim() : '';
162
+ const token = typedToken !== '' ? typedToken : hostChanged ? '' : saved.token;
163
+ const policy = input.policy === 'auto' || input.policy === 'approve' ? input.policy : 'approve';
164
+ return {
165
+ config: {
166
+ enabled: Boolean(input.enabled),
167
+ name: typeof input.name === 'string' ? input.name.trim() : '',
168
+ endpoint,
169
+ token,
170
+ pollSeconds: clampPollSeconds(input.pollSeconds),
171
+ policy,
172
+ instanceId: saved.instanceId,
173
+ },
174
+ purgeLedger: hostChanged,
175
+ };
176
+ }
177
+ function maskSecrets(value) {
178
+ if (Array.isArray(value)) {
179
+ return value.map(maskSecrets);
180
+ }
181
+ if (value && typeof value === 'object') {
182
+ const out = {};
183
+ for (const [k, v] of Object.entries(value)) {
184
+ out[k] = k === 'repositoryToken' ? '••••' : maskSecrets(v);
185
+ }
186
+ return out;
187
+ }
188
+ return value;
189
+ }
190
+ /**
191
+ * Returns ledger records as view summaries (newest first).
192
+ * Request body is included only for `pending` records, with `repositoryToken` masked.
193
+ */
194
+ export function summarizeLedger(records) {
195
+ const out = [];
196
+ for (let i = records.length - 1; i >= 0; i--) {
197
+ const r = records[i];
198
+ const summary = {
199
+ id: r.id,
200
+ method: r.method,
201
+ path: r.path,
202
+ receivedAt: r.receivedAt,
203
+ state: r.state,
204
+ ...(r.result ? { status: r.result.status } : {}),
205
+ ...(r.resolvedAt ? { resolvedAt: r.resolvedAt } : {}),
206
+ delivered: r.delivered,
207
+ };
208
+ if (r.state === 'pending' && r.body !== undefined) {
209
+ try {
210
+ summary.body = maskSecrets(JSON.parse(decrypt(r.body)));
211
+ }
212
+ catch {
213
+ // Ignore unreadable body
214
+ }
215
+ }
216
+ out.push(summary);
217
+ }
218
+ return out;
219
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Keeps any project present on disk and absent from an incoming settings save,
3
+ * appended after the incoming list so incoming edits win.
4
+ */
5
+ export declare function keepMissingProjects<T extends {
6
+ id: string;
7
+ }>(onDisk: T[], incoming: T[]): T[];
8
+ //# sourceMappingURL=save_config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"save_config.d.ts","sourceRoot":"","sources":["../../../src/cli/web/save_config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAI7F"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Keeps any project present on disk and absent from an incoming settings save,
3
+ * appended after the incoming list so incoming edits win.
4
+ */
5
+ export function keepMissingProjects(onDisk, incoming) {
6
+ const incomingIds = new Set(incoming.map((p) => p.id));
7
+ const missing = onDisk.filter((p) => !incomingIds.has(p.id));
8
+ return [...incoming, ...missing];
9
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"AA8HA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAidnE"}
1
+ {"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"AA8HA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAkenE"}
@@ -3,7 +3,7 @@ import * as harness from '../../../harness/index.js';
3
3
  import { loadAgents, loadConfig } from '../../../store/json.js';
4
4
  import { getTaskById, saveTask, addTaskMessage, runQuery } from '../../../store/db.js';
5
5
  import { runningTasks, runningTaskControllers, syncingProjects } from './locks.js';
6
- import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone, runBootstrap, gitCommonDir, syncProjectRepo, projectWorkingDir, pushBranch } from '../../../lib/task_git.js';
6
+ import { isGitRepo, ensureWorktree, BranchDivergedError, agentDirIn, commitWip, finalizeDone, runBootstrap, gitCommonDir, syncProjectRepo, projectWorkingDir, pushBranch } from '../../../lib/task_git.js';
7
7
  import { runDoneReview, MAX_REVIEW_ROUNDS, reviewTransition, reviewRoundLabel } from './task_review.js';
8
8
  import { openCycle, filterHandoffMessages, resolveCycleOutcome } from './task_cycle.js';
9
9
  import { claudeCodeTaskExtras } from '../../../harness/claude_code_runner.js';
@@ -177,7 +177,26 @@ export async function runTaskHeartbeatTick(now) {
177
177
  mountRoot = task.worktreePath;
178
178
  }
179
179
  else if (await isGitRepo(baseWorkingDir)) {
180
- const wt = await ensureWorktree(baseWorkingDir, task.id, task.title, task.branch);
180
+ let wt;
181
+ try {
182
+ wt = await ensureWorktree(baseWorkingDir, task.id, task.title, task.branch);
183
+ }
184
+ catch (wtErr) {
185
+ if (!(wtErr instanceof BranchDivergedError))
186
+ throw wtErr;
187
+ task.status = 'blocked';
188
+ task.blockedReason = wtErr.message;
189
+ task.updatedAt = new Date().toISOString();
190
+ await saveTask(task);
191
+ await addTaskMessage({
192
+ taskId: task.id,
193
+ role: 'assistant',
194
+ messageType: 'block',
195
+ content: `Task branch diverged from the remote — task blocked.\n\n${wtErr.message}`,
196
+ });
197
+ console.error(`[task_heartbeat] Task #${task.id} branch diverged, blocked:`, wtErr.message);
198
+ return;
199
+ }
181
200
  task.branch = wt.branch;
182
201
  task.worktreePath = wt.worktreePath;
183
202
  await saveTask(task);
@@ -1,3 +1,5 @@
1
+ import { Hono } from 'hono';
2
+ import { type ApiListenerOptions } from './api_access.js';
1
3
  import * as harness from '../../harness/index.js';
2
4
  import type { AgentConfig, ProviderConfig } from '../../types.js';
3
5
  import type { ConfirmDecision } from 'webview-ui/bridge';
@@ -34,6 +36,7 @@ export declare class WebSessionController {
34
36
  }>, voiceConversation?: boolean): Promise<void>;
35
37
  abort(): void;
36
38
  }
39
+ export declare function createApp(apiListener: ApiListenerOptions, fetchImpl?: typeof fetch): Hono;
37
40
  export declare function startServer(port: number, host: string, api?: {
38
41
  port?: number;
39
42
  host?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAWA,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,a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A;CAAO,GACzC,OAAO,CAAC,IAAI,CAAC,CAwnBf"}
@@ -5,6 +5,8 @@ import { watch, existsSync, mkdirSync } from 'node:fs';
5
5
  import { Hono } from 'hono';
6
6
  import { applyApiListener, registerApiAccess } from './api_access.js';
7
7
  import { registerOpenApi } from './openapi.js';
8
+ import { registerOrchestrator, startOrchestrator } from './orchestrator.js';
9
+ import { keepMissingProjects } from './save_config.js';
8
10
  import { stream } from 'hono/streaming';
9
11
  import { serve } from '@hono/node-server';
10
12
  import { WebSocketServer, WebSocket } from 'ws';
@@ -155,10 +157,20 @@ export class WebSessionController {
155
157
  this.inflight?.abort();
156
158
  }
157
159
  }
158
- export async function startServer(port, host, api = {}) {
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
+ }
172
+ export function createApp(apiListener, fetchImpl) {
159
173
  const app = new Hono();
160
- // Token-authenticated listener for clients outside the browser (api_access.ts).
161
- const apiListener = { webPort: port, host: api.host ?? host, portOverride: api.port };
162
174
  registerApiAccess(app, apiListener);
163
175
  registerOpenApi(app);
164
176
  app.route('/api/fs', fsRouter);
@@ -166,6 +178,7 @@ export async function startServer(port, host, api = {}) {
166
178
  registerVoiceProxy(app);
167
179
  registerVoiceBackend(app);
168
180
  registerVoiceBuiltin(app);
181
+ registerOrchestrator(app, fetchImpl);
169
182
  // Pure-Node static serving with absolute path validation and fallback
170
183
  app.get('/', (c) => {
171
184
  try {
@@ -404,10 +417,22 @@ export async function startServer(port, host, api = {}) {
404
417
  if (!/^[a-z0-9][a-z0-9-]*$/.test(id))
405
418
  return c.json({ error: 'Invalid id' }, 400);
406
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);
407
425
  try {
408
426
  const rows = (await runQuery(`SELECT * FROM tasks WHERE projectId = '${id}'`));
409
427
  const filtered = includeArchived ? rows : rows.filter((t) => !t.archived);
410
- 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));
411
436
  }
412
437
  catch (err) {
413
438
  return c.json([], 200);
@@ -461,12 +486,21 @@ export async function startServer(port, host, api = {}) {
461
486
  });
462
487
  app.get('/api/tasks/:id/messages', async (c) => {
463
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;
464
497
  if (!/^[a-z0-9][a-z0-9-]*$/.test(taskId))
465
498
  return c.json([], 200);
466
499
  try {
467
500
  const rows = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${taskId}'`));
468
- rows.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
469
- 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));
470
504
  }
471
505
  catch (err) {
472
506
  return c.json([], 200);
@@ -780,6 +814,12 @@ export async function startServer(port, host, api = {}) {
780
814
  }
781
815
  return c.json({ ok: true, title: task.title, objective: task.objective });
782
816
  });
817
+ return app;
818
+ }
819
+ export async function startServer(port, host, api = {}) {
820
+ // Token-authenticated listener for clients outside the browser (api_access.ts).
821
+ const apiListener = { webPort: port, host: api.host ?? host, portOverride: api.port };
822
+ const app = createApp(apiListener);
783
823
  const nodeServer = serve({
784
824
  fetch: app.fetch,
785
825
  port,
@@ -804,6 +844,7 @@ export async function startServer(port, host, api = {}) {
804
844
  console.log(`\n🚀 Caretaker Server running at http://${host}:${port}\n`);
805
845
  // Start the background scheduler trigger daemon
806
846
  startBackgroundScheduler();
847
+ startOrchestrator(app);
807
848
  // Opt-in: start the managed local speech backend if configured to. Never
808
849
  // awaited — a first run pulls 2.08 GB and must not hang server boot.
809
850
  maybeAutoStartBackend();
@@ -1121,20 +1162,10 @@ export async function startServer(port, host, api = {}) {
1121
1162
  post({ type: 'error', message: idError });
1122
1163
  return;
1123
1164
  }
1124
- // A project that still has tasks must be deleted through DELETE /api/projects/:id
1125
- // (which removes tasks, worktrees and the managed clone) — not silently dropped
1126
- // from a config save. Also blocks id "renames", which arrive as drop+add.
1165
+ // Project deletion goes only through DELETE /api/projects/:id: a stale
1166
+ // settings form copy must not delete a project created over REST.
1127
1167
  const prev = await loadConfig();
1128
- const incomingIds = new Set((msg.config.projects || []).map((p) => p.id));
1129
- for (const old of prev.projects || []) {
1130
- if (incomingIds.has(old.id))
1131
- continue;
1132
- const remaining = (await runQuery(`SELECT * FROM tasks WHERE projectId = '${old.id}'`));
1133
- if (remaining.length > 0) {
1134
- post({ type: 'error', message: `Project "${old.name}" still has ${remaining.length} task(s) — delete it from the Projects panel instead.` });
1135
- return;
1136
- }
1137
- }
1168
+ msg.config.projects = keepMissingProjects(prev.projects || [], msg.config.projects || []);
1138
1169
  // The settings form saves the whole config through here, so this
1139
1170
  // — not POST /api/projects — is the write path that actually
1140
1171
  // needs to enforce the repository-URL rules.
@@ -56,6 +56,9 @@ export declare function syncProjectRepo(project: {
56
56
  */
57
57
  export declare function gitCommonDir(worktreePath: string): Promise<string | null>;
58
58
  export declare function agentDirIn(worktreePath: string, projectWorkingDir: string): Promise<string>;
59
+ export declare class BranchDivergedError extends Error {
60
+ constructor(branch: string);
61
+ }
59
62
  export declare function ensureWorktree(projectWorkingDir: string, taskId: string, title: string, existingBranch?: string | null): Promise<{
60
63
  branch: string;
61
64
  worktreePath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"task_git.d.ts","sourceRoot":"","sources":["../../src/lib/task_git.ts"],"names":[],"mappings":"AA2BA,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAM7D;AAOD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAKvD;AAED,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMxE;AA8CD,wBAAsB,UAAU,CAC9B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC3C,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,GAAG,MAAM,CAOT;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,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AC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC5D,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -242,6 +242,21 @@ export async function agentDirIn(worktreePath, projectWorkingDir) {
242
242
  const rel = relative(repoRoot, projectWorkingDir);
243
243
  return rel ? join(worktreePath, rel) : worktreePath;
244
244
  }
245
+ export class BranchDivergedError extends Error {
246
+ constructor(branch) {
247
+ super(`Task branch "${branch}" diverged from origin/${branch}: it has local commits the remote lacks and the remote has commits the local branch lacks. Reconcile the branch by hand, then unblock the task.`);
248
+ this.name = 'BranchDivergedError';
249
+ }
250
+ }
251
+ async function isAncestor(cwd, a, b) {
252
+ try {
253
+ await git(cwd, ['merge-base', '--is-ancestor', a, b]);
254
+ return true;
255
+ }
256
+ catch {
257
+ return false;
258
+ }
259
+ }
245
260
  export async function ensureWorktree(projectWorkingDir, taskId, title, existingBranch) {
246
261
  const repoRoot = await git(projectWorkingDir, ['rev-parse', '--show-toplevel']);
247
262
  // The persisted branch is authoritative: re-deriving under the new id scheme
@@ -254,6 +269,20 @@ export async function ensureWorktree(projectWorkingDir, taskId, title, existingB
254
269
  catch {
255
270
  // Branch may already exist from a previous run whose path field was lost — reuse it.
256
271
  await git(repoRoot, ['worktree', 'add', worktreePath, branch]);
272
+ // Reused branch: catch up with a remote that moved while the task was finished.
273
+ // No fetch here — syncProjectRepo already refreshed origin/<branch>.
274
+ const remoteRef = `refs/remotes/origin/${branch}`;
275
+ const hasRemote = await git(worktreePath, ['rev-parse', '--verify', '--quiet', remoteRef]).then(() => true, () => false);
276
+ if (hasRemote && !(await isAncestor(worktreePath, remoteRef, 'HEAD'))) {
277
+ if (await isAncestor(worktreePath, 'HEAD', remoteRef)) {
278
+ await git(worktreePath, ['merge', '--ff-only', remoteRef]);
279
+ }
280
+ else {
281
+ // Leave nothing behind: the next attempt must find the path free and the branch unlocked.
282
+ await git(repoRoot, ['worktree', 'remove', '--force', worktreePath]);
283
+ throw new BranchDivergedError(branch);
284
+ }
285
+ }
257
286
  }
258
287
  const rel = relative(repoRoot, projectWorkingDir);
259
288
  const agentWorkingDir = rel ? join(worktreePath, rel) : worktreePath;
@@ -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,IA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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
  };
@@ -0,0 +1,50 @@
1
+ export type OrchestratorPolicy = 'auto' | 'approve';
2
+ export interface OrchestratorConfig {
3
+ enabled: boolean;
4
+ name: string;
5
+ endpoint: string;
6
+ /** Encrypted blob, or '' when none. */
7
+ token: string;
8
+ pollSeconds: number;
9
+ policy: OrchestratorPolicy;
10
+ instanceId: string;
11
+ }
12
+ export interface LedgerRecord {
13
+ id: string;
14
+ method: string;
15
+ path: string;
16
+ /** encrypt(JSON.stringify(body)); removed when state becomes 'done'. */
17
+ body?: string;
18
+ receivedAt: string;
19
+ state: 'pending' | 'applying' | 'done';
20
+ /** body encrypted the same way; removed on delivery. */
21
+ result?: {
22
+ status: number;
23
+ body?: string;
24
+ };
25
+ resolvedAt?: string;
26
+ delivered: boolean;
27
+ }
28
+ export declare function orchestratorPath(): string;
29
+ export declare function orchestratorLedgerPath(): string;
30
+ /**
31
+ * Loads orchestrator.json with defaults (disabled, '', '', '', 15, 'approve').
32
+ * Generates and persists `instanceId` (randomUUID) when missing.
33
+ * Always returns a fresh object.
34
+ */
35
+ export declare function loadOrchestrator(): Promise<OrchestratorConfig>;
36
+ /**
37
+ * Persists orchestrator.json atomically. Encrypts `token` when it is not
38
+ * already an encrypted blob.
39
+ */
40
+ export declare function saveOrchestrator(c: OrchestratorConfig): Promise<void>;
41
+ /**
42
+ * Loads orchestrator-ledger.json. Unreadable or non-array file returns [].
43
+ * Malformed records are dropped.
44
+ */
45
+ export declare function loadLedger(): Promise<LedgerRecord[]>;
46
+ /**
47
+ * Persists orchestrator-ledger.json atomically.
48
+ */
49
+ export declare function saveLedger(records: LedgerRecord[]): Promise<void>;
50
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/store/orchestrator.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC;AAEpD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC;IACvC,wDAAwD;IACxD,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA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