@telora/daemon 0.15.26 → 0.15.28

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 (75) hide show
  1. package/build-info.json +2 -2
  2. package/dist/assembly-resolvers.d.ts.map +1 -1
  3. package/dist/assembly-resolvers.js +210 -0
  4. package/dist/assembly-resolvers.js.map +1 -1
  5. package/dist/audit-phase.d.ts +85 -0
  6. package/dist/audit-phase.d.ts.map +1 -0
  7. package/dist/audit-phase.js +271 -0
  8. package/dist/audit-phase.js.map +1 -0
  9. package/dist/cli/session-state.d.ts +54 -0
  10. package/dist/cli/session-state.d.ts.map +1 -0
  11. package/dist/cli/session-state.js +177 -0
  12. package/dist/cli/session-state.js.map +1 -0
  13. package/dist/focus-completion.d.ts +63 -4
  14. package/dist/focus-completion.d.ts.map +1 -1
  15. package/dist/focus-completion.js +119 -47
  16. package/dist/focus-completion.js.map +1 -1
  17. package/dist/focus-engine.d.ts.map +1 -1
  18. package/dist/focus-engine.js +19 -0
  19. package/dist/focus-engine.js.map +1 -1
  20. package/dist/focus-loop.d.ts +2 -0
  21. package/dist/focus-loop.d.ts.map +1 -1
  22. package/dist/focus-loop.js +15 -11
  23. package/dist/focus-loop.js.map +1 -1
  24. package/dist/focus-merge.d.ts +5 -1
  25. package/dist/focus-merge.d.ts.map +1 -1
  26. package/dist/focus-merge.js +13 -9
  27. package/dist/focus-merge.js.map +1 -1
  28. package/dist/index.js +16 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/merge-back-loop.d.ts +103 -0
  31. package/dist/merge-back-loop.d.ts.map +1 -0
  32. package/dist/merge-back-loop.js +449 -0
  33. package/dist/merge-back-loop.js.map +1 -0
  34. package/dist/queries/audit-runs.d.ts +38 -0
  35. package/dist/queries/audit-runs.d.ts.map +1 -0
  36. package/dist/queries/audit-runs.js +39 -0
  37. package/dist/queries/audit-runs.js.map +1 -0
  38. package/dist/queries/focuses.d.ts.map +1 -1
  39. package/dist/queries/focuses.js +1 -0
  40. package/dist/queries/focuses.js.map +1 -1
  41. package/dist/queries/issues.d.ts +41 -0
  42. package/dist/queries/issues.d.ts.map +1 -1
  43. package/dist/queries/issues.js +39 -0
  44. package/dist/queries/issues.js.map +1 -1
  45. package/dist/queries/schemas.d.ts +2 -0
  46. package/dist/queries/schemas.d.ts.map +1 -1
  47. package/dist/queries/schemas.js +1 -0
  48. package/dist/queries/schemas.js.map +1 -1
  49. package/dist/queries/sessions.d.ts +11 -0
  50. package/dist/queries/sessions.d.ts.map +1 -1
  51. package/dist/queries/sessions.js +28 -0
  52. package/dist/queries/sessions.js.map +1 -1
  53. package/dist/spawner-lifecycle.d.ts +29 -0
  54. package/dist/spawner-lifecycle.d.ts.map +1 -1
  55. package/dist/spawner-lifecycle.js +67 -0
  56. package/dist/spawner-lifecycle.js.map +1 -1
  57. package/dist/spawner.d.ts +3 -0
  58. package/dist/spawner.d.ts.map +1 -1
  59. package/dist/spawner.js +2 -0
  60. package/dist/spawner.js.map +1 -1
  61. package/dist/stage-classifier.d.ts +1 -1
  62. package/dist/stage-classifier.d.ts.map +1 -1
  63. package/dist/stage-classifier.js +3 -3
  64. package/dist/stage-classifier.js.map +1 -1
  65. package/dist/types/focus.d.ts +1 -0
  66. package/dist/types/focus.d.ts.map +1 -1
  67. package/dist/verification-engine.d.ts +3 -2
  68. package/dist/verification-engine.d.ts.map +1 -1
  69. package/dist/verification-engine.js +3 -2
  70. package/dist/verification-engine.js.map +1 -1
  71. package/dist/worktree-state.d.ts +58 -0
  72. package/dist/worktree-state.d.ts.map +1 -0
  73. package/dist/worktree-state.js +135 -0
  74. package/dist/worktree-state.js.map +1 -0
  75. package/package.json +1 -1
@@ -0,0 +1,449 @@
1
+ /**
2
+ * Continuous merge-back loop tick.
3
+ *
4
+ * Observes focus-branch state and merges to integration when safe.
5
+ * Adds a state-driven recovery path on top of the existing event-driven
6
+ * merge-back in focus-completion.handleTeamCompletion: any branch that
7
+ * ends up ahead of integration -- whether because the team-exit event
8
+ * was missed, the agent role was cleared mid-flight, the daemon
9
+ * restarted, or any other reason -- eventually gets merged here.
10
+ *
11
+ * Per product, per focus-branch ahead of integration:
12
+ * - Skip if isWorktreeBeingWritten reports active.
13
+ * - Skip if the worktree has uncommitted changes (covered by primitive,
14
+ * but checked explicitly so the skip reason is logged at debug).
15
+ * - Skip if a pending merge-conflict escalation exists for this branch.
16
+ * - Otherwise: call mergeFocusBranch with a minimal synthetic teamState
17
+ * and let the existing escalateMergeConflict path fire on failure.
18
+ *
19
+ * Stuck-branch escalation (Delivery 4) extends this tick with per-branch
20
+ * attempt tracking and creates 'stuck_focus_branch' escalations when a
21
+ * branch sits ahead of integration past a configurable threshold.
22
+ *
23
+ * @module merge-back-loop
24
+ */
25
+ import { branchHasUnmergedCommits, worktreeHasUncommittedChanges } from './worktree-safety.js';
26
+ import { runGitSync } from './git-types.js';
27
+ import { configForProduct } from './config.js';
28
+ import { mergeFocusBranch as defaultMergeFocusBranch } from './focus-merge.js';
29
+ import { getActiveFocuses } from './queries/deliveries.js';
30
+ import { getFocusDeliveries as defaultGetFocusDeliveries } from './queries/focuses.js';
31
+ import { listPendingEscalations as defaultListPendingEscalations, markEscalationResolved as defaultMarkEscalationResolved, createEscalation as defaultCreateEscalation } from './queries/issues.js';
32
+ import { getAllFocusWorktrees } from './focus-worktree-state.js';
33
+ import { isWorktreeBeingWritten as defaultIsWorktreeBeingWritten } from './worktree-state.js';
34
+ import { ESCALATION_REASONS } from '@telora/daemon-core';
35
+ // ── Stuck-branch escalation kind (Delivery 4) ─────────────────────────
36
+ export const STUCK_FOCUS_BRANCH_KIND = 'stuck_focus_branch';
37
+ const branchAttempts = new Map();
38
+ /** Reset attempt tracking — tests use this to start from a clean slate. */
39
+ export function __resetMergeBackAttemptsForTesting() {
40
+ branchAttempts.clear();
41
+ }
42
+ /** Read the attempt state for a branch (for tests / introspection). */
43
+ export function getBranchAttemptState(branchName) {
44
+ return branchAttempts.get(branchName);
45
+ }
46
+ function recordSuccess(branchName, now) {
47
+ const existing = branchAttempts.get(branchName) ?? {
48
+ lastSuccessAt: null,
49
+ lastFailureAt: null,
50
+ lastFailureReason: null,
51
+ };
52
+ branchAttempts.set(branchName, { ...existing, lastSuccessAt: now });
53
+ }
54
+ function recordFailure(branchName, now, reason) {
55
+ const existing = branchAttempts.get(branchName) ?? {
56
+ lastSuccessAt: null,
57
+ lastFailureAt: null,
58
+ lastFailureReason: null,
59
+ };
60
+ branchAttempts.set(branchName, { ...existing, lastFailureAt: now, lastFailureReason: reason });
61
+ }
62
+ const STUCK_BRANCH_DEFAULT_THRESHOLD_HOURS = 24;
63
+ function readStuckBranchThresholdMs(env = process.env) {
64
+ const raw = env.TELORA_STUCK_BRANCH_THRESHOLD_HOURS;
65
+ if (!raw)
66
+ return STUCK_BRANCH_DEFAULT_THRESHOLD_HOURS * 3_600_000;
67
+ const n = Number.parseFloat(raw);
68
+ if (!Number.isFinite(n) || n <= 0)
69
+ return STUCK_BRANCH_DEFAULT_THRESHOLD_HOURS * 3_600_000;
70
+ return n * 3_600_000;
71
+ }
72
+ /**
73
+ * Read the unix-epoch milliseconds timestamp of the oldest commit on
74
+ * `branchName` not yet present on `targetBranch`. Returns null if there
75
+ * are no unmerged commits or the git invocation fails.
76
+ */
77
+ export function getOldestUnmergedCommitMs(branchName, targetBranch, repoPath) {
78
+ const result = runGitSync(['log', '--format=%ct', `${targetBranch}..${branchName}`], repoPath);
79
+ if (!result.success)
80
+ return null;
81
+ const lines = result.output.trim().split('\n').filter(Boolean);
82
+ if (lines.length === 0)
83
+ return null;
84
+ // git log lists newest-first; the last line is the oldest commit.
85
+ const seconds = Number.parseInt(lines[lines.length - 1], 10);
86
+ if (!Number.isFinite(seconds) || Number.isNaN(seconds))
87
+ return null;
88
+ return seconds * 1000;
89
+ }
90
+ /**
91
+ * Enumerate focus branches with commits ahead of integration.
92
+ *
93
+ * Combines getActiveFocuses (for org/name/readOnly context) with the
94
+ * in-memory worktree state (for branchName + worktreePath). Returns one
95
+ * entry per focus whose branch has unmerged commits.
96
+ */
97
+ export async function defaultEnumerateFocusBranchesAhead(config) {
98
+ const out = [];
99
+ const worktrees = getAllFocusWorktrees();
100
+ for (const product of config.products) {
101
+ const pc = configForProduct(config, product);
102
+ let focuses;
103
+ try {
104
+ focuses = await getActiveFocuses(pc.organizationId, product.id);
105
+ }
106
+ catch (err) {
107
+ console.warn(`[merge-back-loop] getActiveFocuses failed for product ${product.id}:`, err.message);
108
+ continue;
109
+ }
110
+ for (const focus of focuses) {
111
+ const wt = worktrees.get(focus.focus_id);
112
+ if (!wt)
113
+ continue;
114
+ const ahead = branchHasUnmergedCommits(wt.branchName, pc.integrationBranch, pc.repoPath);
115
+ if (!ahead)
116
+ continue;
117
+ out.push({
118
+ focusId: focus.focus_id,
119
+ focusName: focus.focus_name,
120
+ organizationId: pc.organizationId,
121
+ productId: product.id,
122
+ branchName: wt.branchName,
123
+ worktreePath: wt.worktreePath,
124
+ repoPath: pc.repoPath,
125
+ pipelineConfig: focus.pipeline_config ?? null,
126
+ readOnly: focus.read_only,
127
+ });
128
+ }
129
+ }
130
+ return out;
131
+ }
132
+ function defaultDeps() {
133
+ return {
134
+ enumerateFocusBranchesAhead: defaultEnumerateFocusBranchesAhead,
135
+ isWorktreeBeingWritten: defaultIsWorktreeBeingWritten,
136
+ worktreeHasUncommittedChanges,
137
+ listPendingEscalations: defaultListPendingEscalations,
138
+ markEscalationResolved: defaultMarkEscalationResolved,
139
+ createEscalation: defaultCreateEscalation,
140
+ mergeFocusBranch: defaultMergeFocusBranch,
141
+ getFocusDeliveries: defaultGetFocusDeliveries,
142
+ getOldestUnmergedCommitMs,
143
+ now: () => Date.now(),
144
+ };
145
+ }
146
+ /**
147
+ * Find a pending escalation matching a kind and branch name.
148
+ * Uses the new metadata.branch_name field when present; falls back to
149
+ * scanning description strings for backward compatibility with rows
150
+ * created before the metadata column existed.
151
+ */
152
+ function findPendingEscalationForBranch(pending, kind, branchName) {
153
+ for (const e of pending) {
154
+ const md = e.metadata ?? null;
155
+ const branchFromMd = md && typeof md === 'object' ? md.branch_name : undefined;
156
+ if (e.escalationKind === kind && branchFromMd === branchName) {
157
+ return { id: e.id };
158
+ }
159
+ // Fallback for legacy rows without escalationKind/metadata.
160
+ if (e.escalationKind == null &&
161
+ kind === STUCK_FOCUS_BRANCH_KIND &&
162
+ e.description.includes(`Branch: ${branchName}`)) {
163
+ return { id: e.id };
164
+ }
165
+ }
166
+ return null;
167
+ }
168
+ /**
169
+ * Find any pending merge-conflict escalation for this branch.
170
+ * Old-style rows do not carry escalationKind; they're detected via the
171
+ * description prefix used by escalateMergeConflict (focus-merge.ts:69).
172
+ */
173
+ function findPendingConflictForBranch(pending, branchName) {
174
+ for (const e of pending) {
175
+ if (e.reasonType === ESCALATION_REASONS.ERROR_ENCOUNTERED &&
176
+ e.description.includes(`Source branch:** ${branchName}`)) {
177
+ return { id: e.id };
178
+ }
179
+ }
180
+ return null;
181
+ }
182
+ /**
183
+ * Build a minimal FocusTeamState shape that mergeFocusBranch can consume.
184
+ * Many fields are unused by mergeFocusBranch's read-path; they default to
185
+ * empty/null so the synthetic state stays observably distinct from real
186
+ * in-flight teams.
187
+ */
188
+ function buildSyntheticTeamState(info, knownDeliveryIds) {
189
+ return {
190
+ focusId: info.focusId,
191
+ focusName: info.focusName,
192
+ roleId: '',
193
+ roleName: 'merge-back-loop',
194
+ organizationId: info.organizationId,
195
+ productId: info.productId,
196
+ executionConfig: { maxWorkers: 0, idlePollIntervalMs: 0, activePollIntervalMs: 0 },
197
+ pipelineConfig: info.pipelineConfig,
198
+ startedAt: new Date(),
199
+ phase: 'terminated',
200
+ knownDeliveryIds,
201
+ mergedDeliveryIds: new Set(),
202
+ planningPhase: false,
203
+ leadSessionId: null,
204
+ leadPid: null,
205
+ leadStdin: null,
206
+ branchName: info.branchName,
207
+ worktreePath: info.worktreePath,
208
+ deliveryStageIds: new Map(),
209
+ resolvingMergeConflict: false,
210
+ shutdownReason: null,
211
+ readOnly: info.readOnly,
212
+ sessionType: 'coding',
213
+ completionDetector: null,
214
+ claudeSessionId: null,
215
+ lastProgressSnapshot: null,
216
+ noProgressCycles: 0,
217
+ lastConsumedDirectiveHash: null,
218
+ };
219
+ }
220
+ /**
221
+ * Statuses that mark deliveries as worked-on (ready for git state reporting).
222
+ *
223
+ * 'done' is included so focuses whose deliveries all reached done before the
224
+ * branch was merged still get propagated. Without 'done' the merge-back loop
225
+ * skips the focus with "no worked deliveries" and the branch stays stranded.
226
+ */
227
+ const WORKED_STATUSES = new Set(['coding', 'verify', 'in_review', 'done']);
228
+ /**
229
+ * Build a `whatWasTried` summary string for stuck-branch escalations.
230
+ */
231
+ function summarizeAttempts(state) {
232
+ if (!state)
233
+ return 'No merge attempts recorded since daemon startup.';
234
+ const parts = [];
235
+ if (state.lastSuccessAt) {
236
+ parts.push(`last success at ${new Date(state.lastSuccessAt).toISOString()}`);
237
+ }
238
+ if (state.lastFailureAt) {
239
+ parts.push(`last failure at ${new Date(state.lastFailureAt).toISOString()}: ${state.lastFailureReason ?? 'unknown'}`);
240
+ }
241
+ if (parts.length === 0)
242
+ return 'No merge attempts recorded since daemon startup.';
243
+ return parts.join('; ');
244
+ }
245
+ /**
246
+ * Decide whether to file a stuck-branch escalation for this branch.
247
+ *
248
+ * Conditions (all must hold):
249
+ * - branch has at least one unmerged commit (already guaranteed by enumerate)
250
+ * - oldest unmerged commit is older than threshold
251
+ * - worktree is NOT being written
252
+ * - no successful merge attempt has been recorded within the threshold window
253
+ * - no open stuck_focus_branch escalation already exists for this branch
254
+ */
255
+ async function maybeFileStuckBranchEscalation(info, oldestUnmergedMs, worktreeActive, pending, thresholdMs, now, createEscalation) {
256
+ if (worktreeActive)
257
+ return;
258
+ if (oldestUnmergedMs == null)
259
+ return;
260
+ if (now - oldestUnmergedMs <= thresholdMs)
261
+ return;
262
+ const state = branchAttempts.get(info.branchName);
263
+ if (state?.lastSuccessAt && now - state.lastSuccessAt <= thresholdMs)
264
+ return;
265
+ if (findPendingEscalationForBranch(pending, STUCK_FOCUS_BRANCH_KIND, info.branchName)) {
266
+ return;
267
+ }
268
+ const ageHours = Math.floor((now - oldestUnmergedMs) / 3_600_000);
269
+ const description = `Focus branch sat ahead of integration for ~${ageHours}h with no successful merge.\n\n` +
270
+ `**Focus:** ${info.focusName}\n` +
271
+ `**Branch:** ${info.branchName}\n` +
272
+ `**Oldest unmerged commit:** ${new Date(oldestUnmergedMs).toISOString()}\n` +
273
+ `**Recent attempts:** ${summarizeAttempts(state)}`;
274
+ try {
275
+ await createEscalation({
276
+ organizationId: info.organizationId,
277
+ sessionId: '',
278
+ issueId: null,
279
+ reasonType: ESCALATION_REASONS.ERROR_ENCOUNTERED,
280
+ description,
281
+ whatWasTried: summarizeAttempts(state),
282
+ helpNeeded: `Inspect the branch (${info.branchName}) and integration history. ` +
283
+ `Either rebase/merge manually, mark the focus complete, or clear the branch ` +
284
+ `if its commits are no longer wanted.`,
285
+ escalationKind: STUCK_FOCUS_BRANCH_KIND,
286
+ metadata: {
287
+ branch_name: info.branchName,
288
+ focus_id: info.focusId,
289
+ oldest_commit_ts: oldestUnmergedMs,
290
+ last_failure_reason: state?.lastFailureReason ?? null,
291
+ },
292
+ });
293
+ console.log(`[merge-back-loop] Filed stuck_focus_branch escalation for ${info.branchName} (${ageHours}h old)`);
294
+ }
295
+ catch (err) {
296
+ console.warn(`[merge-back-loop] createEscalation failed for ${info.branchName}:`, err.message);
297
+ }
298
+ }
299
+ /**
300
+ * Auto-resolve any open stuck-branch escalations for a branch we just merged.
301
+ */
302
+ async function resolveStuckBranchEscalations(branchName, pending, markResolved) {
303
+ const match = findPendingEscalationForBranch(pending, STUCK_FOCUS_BRANCH_KIND, branchName);
304
+ if (!match)
305
+ return;
306
+ try {
307
+ await markResolved(match.id, 'Branch merged automatically by merge-back-loop');
308
+ console.log(`[merge-back-loop] Auto-resolved stuck_focus_branch escalation ${match.id} for ${branchName}`);
309
+ }
310
+ catch (err) {
311
+ console.warn(`[merge-back-loop] markEscalationResolved failed for ${match.id}:`, err.message);
312
+ }
313
+ }
314
+ /**
315
+ * Run one merge-back tick across all products in the daemon config.
316
+ *
317
+ * Idempotent: when no branches are ahead of integration, the tick is a
318
+ * no-op (no info-level log, debug only). When work happens, logs a
319
+ * single info-level summary line.
320
+ */
321
+ export async function runMergeBackTick(config, depOverrides = {}) {
322
+ const deps = { ...defaultDeps(), ...depOverrides };
323
+ const counts = { scanned: 0, merged: 0, skipped: 0, conflicts: 0 };
324
+ const thresholdMs = readStuckBranchThresholdMs();
325
+ let branches;
326
+ try {
327
+ branches = await deps.enumerateFocusBranchesAhead(config);
328
+ }
329
+ catch (err) {
330
+ console.warn('[merge-back-loop] enumerate failed:', err.message);
331
+ return counts;
332
+ }
333
+ // Pull pending escalations once per tick — used for both conflict-skip and
334
+ // stuck-branch dedup checks. Empty list on error so the tick continues.
335
+ let pending;
336
+ try {
337
+ pending = await deps.listPendingEscalations();
338
+ }
339
+ catch (err) {
340
+ console.warn('[merge-back-loop] listPendingEscalations failed:', err.message);
341
+ pending = [];
342
+ }
343
+ counts.scanned = branches.length;
344
+ if (branches.length === 0) {
345
+ console.debug('[merge-back-loop] tick: 0 branches ahead of integration');
346
+ return counts;
347
+ }
348
+ for (const info of branches) {
349
+ const now = deps.now();
350
+ // Gate 0: read-only audit focuses never merge to integration. The
351
+ // event-driven path enforces this via shouldAttemptMerge's readOnly
352
+ // check; mirror that here so a violating audit team (one that
353
+ // committed in violation of its constraint) can't bypass the guard
354
+ // through the state-driven loop.
355
+ if (info.readOnly) {
356
+ counts.skipped += 1;
357
+ console.debug(`[merge-back-loop] skip ${info.branchName}: read-only focus`);
358
+ continue;
359
+ }
360
+ // Gate 1: in-memory writer / active session / recent commit / dirty
361
+ let writeSignal;
362
+ try {
363
+ writeSignal = await deps.isWorktreeBeingWritten(info.focusId);
364
+ }
365
+ catch (err) {
366
+ console.warn(`[merge-back-loop] isWorktreeBeingWritten failed for ${info.focusId}:`, err.message);
367
+ counts.skipped += 1;
368
+ continue;
369
+ }
370
+ if (writeSignal.active) {
371
+ counts.skipped += 1;
372
+ console.debug(`[merge-back-loop] skip ${info.branchName}: ${writeSignal.reason?.code ?? 'unknown'} -- ${writeSignal.reason?.message ?? ''}`);
373
+ continue;
374
+ }
375
+ // Gate 2: explicit dirty-worktree skip (redundant w/ isWorktreeBeingWritten,
376
+ // but logged separately so the skip is easy to read in the log).
377
+ if (deps.worktreeHasUncommittedChanges(info.worktreePath)) {
378
+ counts.skipped += 1;
379
+ console.debug(`[merge-back-loop] skip ${info.branchName}: dirty worktree`);
380
+ continue;
381
+ }
382
+ // Gate 3: existing pending merge-conflict escalation for this branch
383
+ if (findPendingConflictForBranch(pending, info.branchName)) {
384
+ counts.skipped += 1;
385
+ console.debug(`[merge-back-loop] skip ${info.branchName}: pending merge-conflict escalation`);
386
+ // Even when we skip the merge, the stuck-branch escalation may still
387
+ // need to fire if the branch has aged out. Skip that here too —
388
+ // a stuck conflict already has an escalation surface.
389
+ continue;
390
+ }
391
+ // Gather worked deliveries (see WORKED_STATUSES).
392
+ let deliveries = [];
393
+ try {
394
+ deliveries = await deps.getFocusDeliveries(info.focusId);
395
+ }
396
+ catch (err) {
397
+ console.warn(`[merge-back-loop] getFocusDeliveries failed for ${info.focusId}:`, err.message);
398
+ }
399
+ const allDeliveryIds = deliveries.map((d) => d.id);
400
+ const workedDeliveryIds = deliveries
401
+ .filter((d) => WORKED_STATUSES.has(d.executionStatus ?? ''))
402
+ .map((d) => d.id);
403
+ if (allDeliveryIds.length === 0) {
404
+ // Degenerate case: branch is ahead but the focus has no deliveries
405
+ // (e.g., orphaned branch with no focus row). Skip and consider the
406
+ // stuck-branch surface — operators decide whether to keep or clean up.
407
+ counts.skipped += 1;
408
+ console.debug(`[merge-back-loop] skip ${info.branchName}: focus has no deliveries`);
409
+ const oldestMs = deps.getOldestUnmergedCommitMs(info.branchName, config.integrationBranch, info.repoPath);
410
+ await maybeFileStuckBranchEscalation(info, oldestMs, writeSignal.active, pending, thresholdMs, now, deps.createEscalation);
411
+ continue;
412
+ }
413
+ // Pass ALL delivery IDs as knownDeliveryIds so mergeFocusBranch's
414
+ // representative fallback can find a delivery even when workedDeliveryIds
415
+ // is empty (e.g., done-only focus). workedDeliveryIds still drives
416
+ // per-delivery git-state telemetry inside mergeFocusBranch.
417
+ const teamState = buildSyntheticTeamState(info, new Set(allDeliveryIds));
418
+ // Pass a product-scoped config so mergeFocusBranch's downstream git
419
+ // operations (mergeToIntegration, etc.) run against the correct repo.
420
+ const productConfig = { ...config, repoPath: info.repoPath, productId: info.productId };
421
+ let mergeResult;
422
+ try {
423
+ mergeResult = await deps.mergeFocusBranch(productConfig, teamState,
424
+ /* sessionId */ '', info.branchName, workedDeliveryIds);
425
+ }
426
+ catch (err) {
427
+ counts.conflicts += 1;
428
+ recordFailure(info.branchName, now, err.message);
429
+ console.warn(`[merge-back-loop] mergeFocusBranch threw for ${info.branchName}:`, err.message);
430
+ continue;
431
+ }
432
+ if (mergeResult.mergeSucceeded) {
433
+ counts.merged += 1;
434
+ recordSuccess(info.branchName, now);
435
+ await resolveStuckBranchEscalations(info.branchName, pending, deps.markEscalationResolved);
436
+ }
437
+ else {
438
+ counts.conflicts += 1;
439
+ recordFailure(info.branchName, now, mergeResult.exitReason);
440
+ // Re-evaluate stuck-branch escalation: a persistent failure should
441
+ // surface as 'stuck' once the branch ages out.
442
+ const oldestMs = deps.getOldestUnmergedCommitMs(info.branchName, config.integrationBranch, info.repoPath);
443
+ await maybeFileStuckBranchEscalation(info, oldestMs, writeSignal.active, pending, thresholdMs, now, deps.createEscalation);
444
+ }
445
+ }
446
+ console.log(`[merge-back-loop] tick: ${counts.scanned} branches scanned, ${counts.merged} merged, ${counts.skipped} skipped, ${counts.conflicts} conflicts`);
447
+ return counts;
448
+ }
449
+ //# sourceMappingURL=merge-back-loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-back-loop.js","sourceRoot":"","sources":["../src/merge-back-loop.ts"],"names":[],"m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CAAC,CAAC;YAC1G,MAAM,8BAA8B,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7H,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CACT,2BAA2B,MAAM,CAAC,OAAO,sBAAsB,MAAM,CAAC,MAAM,YAAY,MAAM,CAAC,OAAO,aAAa,MAAM,CAAC,SAAS,YAAY,CAChJ,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * audit_runs queries.
3
+ *
4
+ * Records one row per autonomous audit cycle. The daemon's audit phase
5
+ * inserts a row when the assessor session starts and updates it with
6
+ * summary_md plus advisory counters when the session terminates.
7
+ */
8
+ export interface AuditRunRow {
9
+ id: string;
10
+ cycleNumber: number;
11
+ startedAt: string;
12
+ completedAt?: string | null;
13
+ summaryMd?: string | null;
14
+ nodesTouched?: number;
15
+ edgesTouched?: number;
16
+ model?: string | null;
17
+ }
18
+ export interface InsertAuditRunInput {
19
+ focusId: string;
20
+ cycleNumber: number;
21
+ model?: string | null;
22
+ sessionId?: string | null;
23
+ }
24
+ export interface UpdateAuditRunInput {
25
+ auditRunId: string;
26
+ summaryMd?: string | null;
27
+ nodesTouched?: number;
28
+ edgesTouched?: number;
29
+ sessionId?: string | null;
30
+ }
31
+ /**
32
+ * Insert a new audit_runs row at session start. The daemon writes the row
33
+ * even when summary parsing later fails so the cycle is recorded.
34
+ */
35
+ export declare function insertAuditRun(input: InsertAuditRunInput): Promise<AuditRunRow>;
36
+ /** Update an existing audit_runs row with summary, counters, and completed_at. */
37
+ export declare function updateAuditRun(input: UpdateAuditRunInput): Promise<AuditRunRow>;
38
+ //# sourceMappingURL=audit-runs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-runs.d.ts","sourceRoot":"","sources":["../../src/queries/audit-runs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CASrF;AAED,kFAAkF;AAClF,wBAAsB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CAQrF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * audit_runs queries.
3
+ *
4
+ * Records one row per autonomous audit cycle. The daemon's audit phase
5
+ * inserts a row when the assessor session starts and updates it with
6
+ * summary_md plus advisory counters when the session terminates.
7
+ */
8
+ import { callApi } from './shared.js';
9
+ /**
10
+ * Insert a new audit_runs row at session start. The daemon writes the row
11
+ * even when summary parsing later fails so the cycle is recorded.
12
+ */
13
+ export async function insertAuditRun(input) {
14
+ const params = {
15
+ focusId: input.focusId,
16
+ cycleNumber: input.cycleNumber,
17
+ };
18
+ if (input.model)
19
+ params.model = input.model;
20
+ if (input.sessionId)
21
+ params.sessionId = input.sessionId;
22
+ const response = await callApi('daemon_insert_audit_run', params);
23
+ return response.auditRun;
24
+ }
25
+ /** Update an existing audit_runs row with summary, counters, and completed_at. */
26
+ export async function updateAuditRun(input) {
27
+ const params = { auditRunId: input.auditRunId };
28
+ if (input.summaryMd !== undefined)
29
+ params.summaryMd = input.summaryMd;
30
+ if (input.nodesTouched !== undefined)
31
+ params.nodesTouched = input.nodesTouched;
32
+ if (input.edgesTouched !== undefined)
33
+ params.edgesTouched = input.edgesTouched;
34
+ if (input.sessionId !== undefined)
35
+ params.sessionId = input.sessionId;
36
+ const response = await callApi('daemon_update_audit_run', params);
37
+ return response.auditRun;
38
+ }
39
+ //# sourceMappingURL=audit-runs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-runs.js","sourceRoot":"","sources":["../../src/queries/audit-runs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AA4BtC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,KAA0B;IAC7D,MAAM,MAAM,GAA4B;QACtC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC;IACF,IAAI,KAAK,CAAC,KAAK;QAAE,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC5C,IAAI,KAAK,CAAC,SAAS;QAAE,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;IACxD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAA4B,yBAAyB,EAAE,MAAM,CAAC,CAAC;IAC7F,OAAO,QAAQ,CAAC,QAAQ,CAAC;AAC3B,CAAC;AAED,k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OAAO,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;IACnD,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,0BAA0B,EAAE,CAAC;CACtC;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAiCzF;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8C1F"}
@@ -24,6 +24,7 @@ export async function getFocusDeliveries(focusId) {
24
24
  gitState: d.gitState ?? null,
25
25
  injectionId: d.injectionId ?? null,
26
26
  stageDescription: d.stageDescription ?? null,
27
+ updatedAt: d.updatedAt ?? null,
27
28
  }));
28
29
  }
29
30
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"focuses.js","sourceRoot":"","sources":["../../src/queries/focuses.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAatB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAe;IACtD,MAAM,MAAM,GAAG,MAAM,gBAAgB,CACnC,6BAA6B,EAC7B,6BAA6B,EAC7B,EAAE,OAAO,EAAE,CACZ,CAAC;IAEF,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACnC,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,WAAW,EAA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,CAAC;AACJ,CAAC"}
@@ -28,11 +28,52 @@ export interface CreateEscalationParams {
28
28
  description: string;
29
29
  whatWasTried?: string;
30
30
  helpNeeded?: string;
31
+ /**
32
+ * Optional discriminator for the kind of escalation (e.g. 'stuck_focus_branch').
33
+ * Persisted on `agent_escalations.escalation_kind` when present.
34
+ */
35
+ escalationKind?: string;
36
+ /**
37
+ * Optional structured metadata (e.g. { branch_name, focus_id }).
38
+ * Persisted on `agent_escalations.metadata` when present.
39
+ */
40
+ metadata?: Record<string, unknown>;
31
41
  }
32
42
  /**
33
43
  * Create an escalation request.
34
44
  */
35
45
  export declare function createEscalation(params: CreateEscalationParams): Promise<void>;
46
+ /**
47
+ * Minimal shape of an escalation row returned by listPendingEscalations.
48
+ * Only includes the fields needed by the merge-back loop.
49
+ */
50
+ export interface PendingEscalation {
51
+ id: string;
52
+ reasonType: string;
53
+ description: string;
54
+ whatWasTried: string | null;
55
+ helpNeeded: string | null;
56
+ escalationKind?: string | null;
57
+ metadata?: Record<string, unknown> | null;
58
+ }
59
+ /**
60
+ * List open (not-yet-resolved) escalations for the organization.
61
+ *
62
+ * Returns rows with status in `('pending', 'in_review')` -- both are
63
+ * "open" from a dedup perspective. An operator may move a stuck-branch
64
+ * escalation to `in_review` while triaging; the merge-back loop must
65
+ * still treat it as suppressing duplicates so it does not file a second
66
+ * `pending` row for the same branch.
67
+ *
68
+ * Used by the merge-back loop to detect when a branch already has an
69
+ * unresolved merge-conflict escalation, and to find existing stuck-branch
70
+ * escalations for dedup / auto-resolution.
71
+ */
72
+ export declare function listPendingEscalations(): Promise<PendingEscalation[]>;
73
+ /**
74
+ * Mark an escalation as resolved with optional notes.
75
+ */
76
+ export declare function markEscalationResolved(escalationId: string, resolutionNotes?: string): Promise<void>;
36
77
  /**
37
78
  * Create an issue on a delivery (for create_issue trigger action).
38
79
  */