@telora/daemon 0.15.4 → 0.15.5
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.
- package/build-info.json +2 -2
- package/dist/focus-completion.js +12 -12
- package/dist/focus-completion.js.map +1 -1
- package/dist/focus-team-state.d.ts +6 -0
- package/dist/focus-team-state.d.ts.map +1 -1
- package/dist/focus-team-state.js +13 -0
- package/dist/focus-team-state.js.map +1 -1
- package/dist/listener.d.ts.map +1 -1
- package/dist/listener.js +0 -5
- package/dist/listener.js.map +1 -1
- package/dist/queries/focuses.d.ts +2 -0
- package/dist/queries/focuses.d.ts.map +1 -1
- package/dist/queries/focuses.js +7 -0
- package/dist/queries/focuses.js.map +1 -1
- package/dist/review-defect-detector.d.ts +16 -95
- package/dist/review-defect-detector.d.ts.map +1 -1
- package/dist/review-defect-detector.js +19 -211
- package/dist/review-defect-detector.js.map +1 -1
- package/dist/state-cascade.d.ts +45 -41
- package/dist/state-cascade.d.ts.map +1 -1
- package/dist/state-cascade.js +123 -215
- package/dist/state-cascade.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,37 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Review-defect
|
|
2
|
+
* Review-defect classification utilities.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* during the most recent review pass, and transitions them back to
|
|
11
|
-
* `building` so the executor spawns a remediation team.
|
|
12
|
-
* * Re-entry -- when all review-filed issues for a focus are Done
|
|
13
|
-
* (and the focus is back in `building`), transitions the focus
|
|
14
|
-
* to `verify` so the existing review subsystem can pass it through to
|
|
15
|
-
* `in_review` for a fresh review pass.
|
|
16
|
-
* * Bound -- tracks per-focus remediation cycle count. After N
|
|
17
|
-
* consecutive cycles, escalates to humans via `agent_escalations`.
|
|
4
|
+
* The state-cascade engine drives review re-engagement off the focus
|
|
5
|
+
* execution phase (verifying / reviewing) -- the older detector that
|
|
6
|
+
* mutated focus.status (in_review/building/verify) was retired with the
|
|
7
|
+
* focus_status enum trim. What remains here is the issue classifier used
|
|
8
|
+
* by focus-executor and the per-focus remediation cycle counter, which
|
|
9
|
+
* may be folded into a future bounded-iteration check.
|
|
18
10
|
*
|
|
19
11
|
* Identifying review-filed issues:
|
|
20
12
|
* We use `created_by_role_id` (filters out human/UI-filed issues, which
|
|
21
13
|
* leave the column NULL) AND timing -- the issue was created after the
|
|
22
|
-
* focus's most recent `review_requested_at
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
14
|
+
* focus's most recent `review_requested_at`. A single role is often
|
|
15
|
+
* shared across team and review sessions, so role alone is insufficient;
|
|
16
|
+
* the timing-plus-role combination is what reliably identifies
|
|
17
|
+
* "filed during a review pass".
|
|
26
18
|
*/
|
|
27
|
-
import { withRetry, ESCALATION_REASONS } from '@telora/daemon-core';
|
|
28
|
-
import { getActiveFocuses } from './supabase.js';
|
|
29
|
-
import { getFocusDeliveries, getFocusIssues, updateFocusStatus, fetchFocusWorkflowWithTransitions, } from './queries/focuses.js';
|
|
30
|
-
import { createEscalation as defaultCreateEscalation } from './queries/issues.js';
|
|
31
19
|
import { OPEN_ISSUE_STATUSES } from './constants.js';
|
|
32
20
|
// ── Configuration ────────────────────────────────────────────────────────
|
|
33
|
-
/** Reason string emitted when remediation cycles exceed the bound. */
|
|
34
|
-
export const REVIEW_REMEDIATION_ESCALATION_REASON = 'review-defect remediation exceeded N cycles';
|
|
35
21
|
/** Default cap on remediation cycles before escalation. Configurable via env. */
|
|
36
22
|
export const REVIEW_REMEDIATION_LIMIT = (() => {
|
|
37
23
|
const raw = process.env.TELORA_REVIEW_REMEDIATION_LIMIT;
|
|
@@ -43,11 +29,9 @@ export const REVIEW_REMEDIATION_LIMIT = (() => {
|
|
|
43
29
|
// ── Per-focus cycle counter ──────────────────────────────────────────
|
|
44
30
|
/**
|
|
45
31
|
* In-memory map of focus ID -> consecutive remediation cycles. Cycle
|
|
46
|
-
* counts are not persisted
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* Exported for testability.
|
|
32
|
+
* counts are not persisted -- a daemon restart resets the counter, which
|
|
33
|
+
* is acceptable because the bound exists to prevent runaway loops within
|
|
34
|
+
* a single daemon lifetime, not across restarts.
|
|
51
35
|
*/
|
|
52
36
|
const remediationCycles = new Map();
|
|
53
37
|
export function getRemediationCycles(focusId) {
|
|
@@ -67,14 +51,11 @@ export function _resetAllRemediationCyclesForTest() {
|
|
|
67
51
|
}
|
|
68
52
|
// ── Issue classification ────────────────────────────────────────────────
|
|
69
53
|
/**
|
|
70
|
-
* Returns true when an issue was filed during the most recent review pass
|
|
71
|
-
* on the given focus.
|
|
54
|
+
* Returns true when an issue was filed during the most recent review pass.
|
|
72
55
|
*
|
|
73
56
|
* An issue is "review-filed" when ALL of:
|
|
74
57
|
* - It has a non-null created_by_role_id (excludes human/UI creates).
|
|
75
|
-
* - Its created_at is later than the focus's review_requested_at
|
|
76
|
-
* (or the focus is in `in_review` with no recorded request time --
|
|
77
|
-
* covers manual review trigger).
|
|
58
|
+
* - Its created_at is later than the focus's review_requested_at.
|
|
78
59
|
* - Its status is open (To Do / In Progress / Blocked).
|
|
79
60
|
*/
|
|
80
61
|
export function isReviewFiledIssue(issue, reviewRequestedAt) {
|
|
@@ -82,28 +63,22 @@ export function isReviewFiledIssue(issue, reviewRequestedAt) {
|
|
|
82
63
|
return false;
|
|
83
64
|
if (!OPEN_ISSUE_STATUSES.has(issue.status))
|
|
84
65
|
return false;
|
|
85
|
-
if (!reviewRequestedAt)
|
|
86
|
-
// No review timestamp -- conservative: do not treat as review-filed.
|
|
66
|
+
if (!reviewRequestedAt)
|
|
87
67
|
return false;
|
|
88
|
-
}
|
|
89
68
|
if (!issue.createdAt)
|
|
90
69
|
return false;
|
|
91
70
|
return new Date(issue.createdAt).getTime() >= new Date(reviewRequestedAt).getTime();
|
|
92
71
|
}
|
|
93
72
|
/**
|
|
94
73
|
* Filter a focus's issues to only those that were filed during the most
|
|
95
|
-
* recent review pass and are still open.
|
|
96
|
-
* (transition to building) and the re-entry check (return to in_review when
|
|
97
|
-
* all are Done).
|
|
74
|
+
* recent review pass and are still open.
|
|
98
75
|
*/
|
|
99
76
|
export function filterReviewFiledIssues(issues, reviewRequestedAt) {
|
|
100
77
|
return issues.filter(i => isReviewFiledIssue(i, reviewRequestedAt));
|
|
101
78
|
}
|
|
102
79
|
/**
|
|
103
80
|
* Returns true when there are any review-filed issues (open or closed)
|
|
104
|
-
* since the most recent review pass.
|
|
105
|
-
* were review-filed issues AND all of them are Done, the focus is
|
|
106
|
-
* eligible to return to in_review.
|
|
81
|
+
* since the most recent review pass.
|
|
107
82
|
*/
|
|
108
83
|
export function reviewFiledIssueExists(issues, reviewRequestedAt) {
|
|
109
84
|
if (!reviewRequestedAt)
|
|
@@ -119,171 +94,4 @@ export function reviewFiledIssueExists(issues, reviewRequestedAt) {
|
|
|
119
94
|
}
|
|
120
95
|
return false;
|
|
121
96
|
}
|
|
122
|
-
const defaultDeps = {
|
|
123
|
-
getActiveFocuses,
|
|
124
|
-
getFocusDeliveries,
|
|
125
|
-
getFocusIssues,
|
|
126
|
-
updateFocusStatus,
|
|
127
|
-
fetchFocusWorkflowWithTransitions,
|
|
128
|
-
createEscalation: defaultCreateEscalation,
|
|
129
|
-
};
|
|
130
|
-
// ── Detector and re-entry ───────────────────────────────────────────────
|
|
131
|
-
/**
|
|
132
|
-
* For each active focus in `in_review` status, check whether any
|
|
133
|
-
* review-filed issues remain open. If so, transition the focus back to
|
|
134
|
-
* `building` and bump the remediation counter. When the counter exceeds
|
|
135
|
-
* the bound, escalate instead of transitioning -- the team has been
|
|
136
|
-
* stuck in a remediation loop and a human needs to intervene.
|
|
137
|
-
*
|
|
138
|
-
* Designed to be called from the daemon poll loop on every tick; it is
|
|
139
|
-
* a no-op for strategies that don't satisfy the trigger conditions.
|
|
140
|
-
*/
|
|
141
|
-
export async function detectAndHandleReviewDefects(config, deps = defaultDeps) {
|
|
142
|
-
let strategies;
|
|
143
|
-
try {
|
|
144
|
-
strategies = await deps.getActiveFocuses(config.organizationId, config.productId);
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
console.warn('[review-defect-detector] Failed to fetch active strategies:', err.message);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
for (const s of strategies) {
|
|
151
|
-
if (s.status !== 'in_review')
|
|
152
|
-
continue;
|
|
153
|
-
try {
|
|
154
|
-
const issues = await deps.getFocusIssues(s.focus_id);
|
|
155
|
-
const reviewOpen = filterReviewFiledIssues(issues, s.review_requested_at ?? null);
|
|
156
|
-
if (reviewOpen.length === 0)
|
|
157
|
-
continue;
|
|
158
|
-
const cycles = incrementRemediationCycles(s.focus_id);
|
|
159
|
-
if (cycles > REVIEW_REMEDIATION_LIMIT) {
|
|
160
|
-
console.warn(`[review-defect-detector] Remediation bound exceeded for "${s.focus_name}" ` +
|
|
161
|
-
`(cycle ${cycles}/${REVIEW_REMEDIATION_LIMIT}); escalating`);
|
|
162
|
-
await escalateReviewRemediation({
|
|
163
|
-
organizationId: config.organizationId,
|
|
164
|
-
focusId: s.focus_id,
|
|
165
|
-
focusName: s.focus_name,
|
|
166
|
-
cycles,
|
|
167
|
-
openIssues: reviewOpen,
|
|
168
|
-
}, deps);
|
|
169
|
-
// Reset so a future review pass starts fresh after human intervention.
|
|
170
|
-
resetRemediationCycles(s.focus_id);
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
// Transition the focus from in_review back to building so the
|
|
174
|
-
// focus executor's poll loop spawns a remediation team.
|
|
175
|
-
const workflow = await deps.fetchFocusWorkflowWithTransitions(s.focus_id);
|
|
176
|
-
const buildingStage = workflow.stages.find(st => st.name === 'building');
|
|
177
|
-
try {
|
|
178
|
-
await deps.updateFocusStatus(s.focus_id, 'building', buildingStage?.id ?? null);
|
|
179
|
-
console.log(`[review-defect-detector] Focus "${s.focus_name}" -> building ` +
|
|
180
|
-
`(${reviewOpen.length} review-filed issue(s) open, remediation cycle ${cycles}/${REVIEW_REMEDIATION_LIMIT})`);
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
console.warn(`[review-defect-detector] Failed to move "${s.focus_name}" to building: ${err.message}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (err) {
|
|
187
|
-
console.warn(`[review-defect-detector] Error checking focus "${s.focus_name}":`, err.message);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* For each active focus in `building` status that has had a review pass
|
|
193
|
-
* (review_requested_at set) and review-filed issues since, check whether
|
|
194
|
-
* all of those issues are now Done. If so, transition the focus back to
|
|
195
|
-
* `verify` so the existing review pipeline can re-run and either close it
|
|
196
|
-
* out or file new defects.
|
|
197
|
-
*
|
|
198
|
-
* Called alongside the detector; safe to invoke on every poll tick.
|
|
199
|
-
*/
|
|
200
|
-
export async function detectAndHandleRemediationComplete(config, deps = defaultDeps) {
|
|
201
|
-
let strategies;
|
|
202
|
-
try {
|
|
203
|
-
strategies = await deps.getActiveFocuses(config.organizationId, config.productId);
|
|
204
|
-
}
|
|
205
|
-
catch (err) {
|
|
206
|
-
console.warn('[review-defect-detector] Failed to fetch active strategies:', err.message);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
for (const s of strategies) {
|
|
210
|
-
// Only act on strategies that were just remediating: status='building'
|
|
211
|
-
// with a recorded review request.
|
|
212
|
-
if (s.status !== 'building')
|
|
213
|
-
continue;
|
|
214
|
-
if (!s.review_requested_at)
|
|
215
|
-
continue;
|
|
216
|
-
try {
|
|
217
|
-
const issues = await deps.getFocusIssues(s.focus_id);
|
|
218
|
-
const allReviewFiled = issues.filter(i => i.createdByRoleId && i.createdAt &&
|
|
219
|
-
new Date(i.createdAt).getTime() >= new Date(s.review_requested_at).getTime());
|
|
220
|
-
if (allReviewFiled.length === 0)
|
|
221
|
-
continue; // no remediation in progress
|
|
222
|
-
const stillOpen = allReviewFiled.filter(i => OPEN_ISSUE_STATUSES.has(i.status));
|
|
223
|
-
if (stillOpen.length > 0)
|
|
224
|
-
continue; // still remediating
|
|
225
|
-
// All review-filed issues are Done -- transition to verify so the
|
|
226
|
-
// review pipeline re-runs.
|
|
227
|
-
const workflow = await deps.fetchFocusWorkflowWithTransitions(s.focus_id);
|
|
228
|
-
const verifyStage = workflow.stages.find(st => st.name === 'verify');
|
|
229
|
-
await deps.updateFocusStatus(s.focus_id, 'verify', verifyStage?.id ?? null);
|
|
230
|
-
console.log(`[review-defect-detector] Focus "${s.focus_name}" -> verify ` +
|
|
231
|
-
`(${allReviewFiled.length} review-filed issue(s) all Done, remediation cycle complete)`);
|
|
232
|
-
}
|
|
233
|
-
catch (err) {
|
|
234
|
-
console.warn(`[review-defect-detector] Error checking remediation completion for "${s.focus_name}":`, err.message);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Escalate when remediation cycles exceed the configured bound. Surfaces
|
|
240
|
-
* the issue list and a clear call to action so the human reviewer can
|
|
241
|
-
* unblock the loop.
|
|
242
|
-
*/
|
|
243
|
-
export async function escalateReviewRemediation(params, deps = defaultDeps) {
|
|
244
|
-
const issueList = params.openIssues
|
|
245
|
-
.slice(0, 25)
|
|
246
|
-
.map(i => `- [${i.status}] ${i.key}: ${i.title}`)
|
|
247
|
-
.join('\n');
|
|
248
|
-
const overflow = params.openIssues.length > 25
|
|
249
|
-
? `\n(... and ${params.openIssues.length - 25} more)`
|
|
250
|
-
: '';
|
|
251
|
-
try {
|
|
252
|
-
await withRetry(() => deps.createEscalation({
|
|
253
|
-
organizationId: params.organizationId,
|
|
254
|
-
sessionId: '',
|
|
255
|
-
issueId: null,
|
|
256
|
-
reasonType: ESCALATION_REASONS.BLOCKED_BY_EXTERNAL,
|
|
257
|
-
description: `Focus "${params.focusName}" has cycled through review-defect remediation ` +
|
|
258
|
-
`${params.cycles} time(s). Reason: ${REVIEW_REMEDIATION_ESCALATION_REASON}.\n\n` +
|
|
259
|
-
`**Focus:** ${params.focusName}\n` +
|
|
260
|
-
`**Focus ID:** ${params.focusId}\n` +
|
|
261
|
-
`**Cycles:** ${params.cycles} (limit: ${REVIEW_REMEDIATION_LIMIT})\n\n` +
|
|
262
|
-
`**Open review-filed issues (${params.openIssues.length}):**\n${issueList}${overflow}`,
|
|
263
|
-
whatWasTried: `The daemon respawned remediation teams ${params.cycles} time(s) and the team ` +
|
|
264
|
-
`was unable to close all review-filed defects between review passes.`,
|
|
265
|
-
helpNeeded: `Review the open issues above. Either close out genuinely-blocked items, ` +
|
|
266
|
-
`clarify acceptance criteria so the next remediation cycle can succeed, or ` +
|
|
267
|
-
`cancel the focus if it is no longer viable.`,
|
|
268
|
-
}), { maxAttempts: 3, label: `escalation-review-remediation-${params.focusId}` });
|
|
269
|
-
console.log(`[review-defect-detector] Created remediation escalation for "${params.focusName}" ` +
|
|
270
|
-
`(reason: ${REVIEW_REMEDIATION_ESCALATION_REASON})`);
|
|
271
|
-
}
|
|
272
|
-
catch (err) {
|
|
273
|
-
console.error(`[review-defect-detector] Failed to create remediation escalation for "${params.focusName}": ${err.message}`);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Combined entry point: call both halves of the loop on each poll tick.
|
|
278
|
-
*
|
|
279
|
-
* Order matters slightly: handle remediation completion first (returns
|
|
280
|
-
* Done strategies to verify) before the defect detector (kicks fresh
|
|
281
|
-
* defects to building). Doing it in this order means a focus can flow
|
|
282
|
-
* verify -> in_review -> building -> verify in a single cycle when work
|
|
283
|
-
* is fast.
|
|
284
|
-
*/
|
|
285
|
-
export async function tickReviewDefectLoop(config, deps = defaultDeps) {
|
|
286
|
-
await detectAndHandleRemediationComplete(config, deps);
|
|
287
|
-
await detectAndHandleReviewDefects(config, deps);
|
|
288
|
-
}
|
|
289
97
|
//# sourceMappingURL=review-defect-detector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-defect-detector.js","sourceRoot":"","sources":["../src/review-defect-detector.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"review-defect-detector.js","sourceRoot":"","sources":["../src/review-defect-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,4EAA4E;AAE5E,iFAAiF;AACjF,MAAM,CAAC,MAAM,wBAAwB,GAAW,CAAC,GAAG,EAAE;IACpD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC;IACxD,IAAI,CAAC,GAAG;QAAE,OAAO,CAAC,CAAC;IACnB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC,EAAE,CAAC;AAEL,wEAAwE;AAExE;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEpD,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAe;IACxD,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACvD,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,iBAAiB,CAAC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AC7E,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/state-cascade.d.ts
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Deterministic
|
|
2
|
+
* Deterministic state cascade engine.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Operates on the focus EXECUTION PHASE axis (derived from delivery
|
|
5
|
+
* aggregate via deriveFocusPhase). Three behaviors live here:
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* 1. Auto-review: phase === 'verifying' + pipelineConfig.review.enabled
|
|
8
|
+
* -> set review_requested_at and transition verify deliveries to
|
|
9
|
+
* in_review. The phase will become 'reviewing' on the next
|
|
10
|
+
* syncFocusPhase poll.
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
+
* 2. Review completion: phase === 'reviewing' + no team running +
|
|
13
|
+
* all in_review deliveries pass (no open work issues)
|
|
14
|
+
* -> deliveries -> done, clear review_requested_at.
|
|
12
15
|
*
|
|
13
|
-
*
|
|
16
|
+
* 3. Stale review clearing: review_requested_at set but a delivery has
|
|
17
|
+
* regressed back to active work -> clear review_requested_at so the
|
|
18
|
+
* user can request a fresh review when verify is reached again.
|
|
19
|
+
*
|
|
20
|
+
* The "deliveries all reach verify -> focus advances" cascade and focus
|
|
21
|
+
* phase regression are handled by syncFocusPhase in directive-executor.ts;
|
|
22
|
+
* they no longer live here.
|
|
14
23
|
*/
|
|
15
24
|
import type { DaemonConfig, PipelineConfig, Workflow } from './types.js';
|
|
16
25
|
import type { FocusDeliveryInfo } from './types.js';
|
|
26
|
+
import { type FocusExecutionPhase } from './focus-phase.js';
|
|
17
27
|
/** Injectable dependencies for cascade functions (testing). */
|
|
18
28
|
export interface CascadeDeps {
|
|
19
29
|
getFocusDeliveries: (focusId: string) => Promise<FocusDeliveryInfo[]>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}) => Promise<void>;
|
|
23
|
-
fetchFocusWorkflowWithTransitions: (focusId: string) => Promise<Workflow>;
|
|
30
|
+
setReviewRequestedAt: (focusId: string, isoTimestamp: string) => Promise<void>;
|
|
31
|
+
clearReviewRequestedAt: (focusId: string) => Promise<void>;
|
|
24
32
|
fetchEffectiveWorkflow: (deliveryId: string) => Promise<Workflow>;
|
|
25
33
|
updateDeliveryStatus: (deliveryId: string, status: string, stageId?: string | null) => Promise<void>;
|
|
26
34
|
getDeliveryIssues: (deliveryId: string) => Promise<Array<{
|
|
@@ -31,41 +39,37 @@ export interface CascadeDeps {
|
|
|
31
39
|
}>>;
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* If a focus is in verify/in_review but a delivery has reverted to a
|
|
40
|
-
* non-complete status, regress the focus back to building.
|
|
42
|
+
* When a focus reaches the verifying phase and pipelineConfig.review is
|
|
43
|
+
* enabled, set review_requested_at and transition verify deliveries to
|
|
44
|
+
* in_review. The phase derivation will pick up review_requested_at on the
|
|
45
|
+
* next poll and emit phase = 'reviewing', firing the reviewing-stage
|
|
46
|
+
* directive.
|
|
41
47
|
*/
|
|
42
|
-
export declare function
|
|
48
|
+
export declare function checkAutoReview(focusId: string, phase: FocusExecutionPhase, pipelineConfig: PipelineConfig | null, reviewRequestedAt: string | null, deliveries: FocusDeliveryInfo[], deps?: CascadeDeps): Promise<void>;
|
|
43
49
|
/**
|
|
44
|
-
* When a focus
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
50
|
+
* When a focus is in the reviewing phase but no review team is running,
|
|
51
|
+
* route each in_review delivery to its outcome and clear
|
|
52
|
+
* review_requested_at:
|
|
53
|
+
* - delivery has open work issues -> iterating (a team will pick it up)
|
|
54
|
+
* - delivery has none -> done
|
|
55
|
+
*
|
|
56
|
+
* Without this, a focus is stuck in reviewing forever if the review team
|
|
57
|
+
* exits without the focus-completion exit handler running (e.g., manual
|
|
58
|
+
* Review request without an in-flight team) or if review never spawned
|
|
59
|
+
* (no agent_directive on the reviewing stage).
|
|
48
60
|
*/
|
|
49
|
-
export declare function
|
|
61
|
+
export declare function checkReviewCompletion(focusId: string, phase: FocusExecutionPhase, deliveries: FocusDeliveryInfo[], deps?: CascadeDeps): Promise<void>;
|
|
50
62
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* This handles the case where auto-review triggers but no review team spawns
|
|
56
|
-
* (e.g., no agent_directive on the in_review stage, or no active team to
|
|
57
|
-
* receive an inject directive). Without this, the focus is stuck in
|
|
58
|
-
* in_review forever.
|
|
63
|
+
* If a focus has review_requested_at set but a delivery has reverted to
|
|
64
|
+
* active work, the prior review request is stale -- clear it so the user
|
|
65
|
+
* can request a fresh review once verify is reached again. Phase
|
|
66
|
+
* regression itself is handled by syncFocusPhase.
|
|
59
67
|
*/
|
|
60
|
-
export declare function
|
|
68
|
+
export declare function clearStaleReviewRequest(focusId: string, phase: FocusExecutionPhase, reviewRequestedAt: string | null, deps?: CascadeDeps): Promise<void>;
|
|
61
69
|
/**
|
|
62
|
-
* Run
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* 1. Check delivery->focus cascade (all deliveries verify => focus verify)
|
|
66
|
-
* 2. Check auto-review (focus in verify + review.enabled)
|
|
67
|
-
* 3. Complete stuck reviews (focus in_review + no team running + all pass)
|
|
68
|
-
* 4. Check for focus regression (delivery reverted => focus back to building)
|
|
70
|
+
* Run cascade checks for active focuses across all configured products.
|
|
71
|
+
* Called from the daemon poll loop after syncFocusPhase has updated
|
|
72
|
+
* current_workflow_stage_id, so the derived phase is authoritative.
|
|
69
73
|
*/
|
|
70
74
|
export declare function runCascadeChecks(config: DaemonConfig): Promise<void>;
|
|
71
75
|
//# sourceMappingURL=state-cascade.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-cascade.d.ts","sourceRoot":"","sources":["../src/state-cascade.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"state-cascade.d.ts","sourceRoot":"","sources":["../src/state-cascade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAgBpD,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,+DAA+D;AAC/D,MAAM,WAAW,WAAW;IAC1B,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACtE,oBAAoB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,sBAAsB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,sBAAsB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClE,oBAAoB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrG,iBAAiB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAC7H;AAWD;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,O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