@attalabs/vinaya 0.33.0 → 0.34.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.
- package/aeg-root/enforcement.md +1 -1
- package/aeg-root/glossary.md +4 -0
- package/aeg-root/roles/developer.md +3 -0
- package/aeg-root/roles/operator.md +30 -10
- package/aeg-root/roles/planner/reference.md +2 -1
- package/aeg-root/roles/planner.md +3 -1
- package/aeg-root/templates/brief-template.md +9 -7
- package/aeg-root/templates/pr-report-template.md +3 -1
- package/dist/checks/bin/check-body-bare-digits.js +102 -26
- package/dist/checks/bin/check-branch-topology.js +81 -25
- package/dist/checks/bin/check-brief-shape.js +108 -31
- package/dist/checks/bin/check-changeset-coverage.js +331 -87
- package/dist/checks/bin/check-closes-n.js +81 -25
- package/dist/checks/bin/check-coherence.js +108 -27
- package/dist/checks/bin/check-dead-branch-push.js +77 -25
- package/dist/checks/bin/check-dispatch-readiness.js +106 -26
- package/dist/checks/bin/check-doc-coverage-push.js +327 -83
- package/dist/checks/bin/check-doc-coverage.js +329 -85
- package/dist/checks/bin/check-doctrine-no-procedures.js +102 -26
- package/dist/checks/bin/check-doctrine-portability.js +328 -84
- package/dist/checks/bin/check-evidence-fresh.js +300 -56
- package/dist/checks/bin/check-exec-bits.js +325 -81
- package/dist/checks/bin/check-first-push-dispatch.js +106 -26
- package/dist/checks/bin/check-issue-assignment.js +81 -25
- package/dist/checks/bin/check-issue-milestone-attach.js +77 -25
- package/dist/checks/bin/check-issue-objectives-numbering.js +603 -26
- package/dist/checks/bin/check-issue-parts-coverage.js +77 -25
- package/dist/checks/bin/check-issue-surface-globs.js +146 -32
- package/dist/checks/bin/check-issue-title-grammar.js +77 -25
- package/dist/checks/bin/check-issue-tranche-label.js +77 -25
- package/dist/checks/bin/check-main-branch-refusal.js +77 -25
- package/dist/checks/bin/check-no-disk-state.js +77 -25
- package/dist/checks/bin/check-pr-premise-reassert.js +102 -26
- package/dist/checks/bin/check-pr-report-density.js +77 -25
- package/dist/checks/bin/check-principal-test-plan-wait.js +77 -25
- package/dist/checks/bin/check-quoted-command.js +244 -34
- package/dist/checks/bin/check-reader-resolvable-prose.js +295 -42
- package/dist/checks/bin/check-registry-gates.js +77 -25
- package/dist/checks/bin/check-retired-vocabulary.js +244 -34
- package/dist/checks/bin/check-review-gate.js +106 -29
- package/dist/checks/bin/check-single-plan-pr.js +77 -25
- package/dist/checks/bin/check-surface-scope.js +81 -25
- package/dist/checks/bin/check-test-plan.js +77 -25
- package/dist/checks/bin/check-token-collection-wired.js +77 -25
- package/dist/checks/bin/check-token-report.js +77 -25
- package/dist/checks/bin/check-workspace-escape.js +326 -82
- package/dist/index.js +2862 -1953
- package/dist/lib/pre-push-cache-test-run.js +190 -11
- package/dist/lib/pre-push-select-tests.js +45 -3
- package/package.json +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +13 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +5 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +116 -20
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +72 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +48 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +18 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +24 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +15 -10
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +16 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +194 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +276 -52
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +62 -8
- package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +4 -4
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/1q96_modules_@clerk_nextjs_dist_esm_app-router_client_keyless-creator-reader_0lom2js.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__18paley._.js → [root-of-the-server]__07uhu5z._.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_@clerk_nextjs_dist_esm_app-router_server-actions_1x7vfhn.js +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0ko698wh8xx2g.css +1 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1ce2dj27_cgbj.js → 0q9p7c6vn-x2w.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{22s44f5k3ecmj.js → 2174nz5he_oc4.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{34hhdtbp20krb.js → 3xnma0-359j17.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bm4nrrzwc7zi.css +0 -1
- /package/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/{aeg-core → vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → HmoeqXdX1E4drt7GReFOO}/_buildManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → HmoeqXdX1E4drt7GReFOO}/_clientMiddlewareManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → HmoeqXdX1E4drt7GReFOO}/_ssgManifest.js +0 -0
package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts
CHANGED
|
@@ -8,9 +8,21 @@
|
|
|
8
8
|
import { SUMMARY_TABLE_HEADER } from './journal-reconstruction'
|
|
9
9
|
import { SEVERITY_COLUMNS, type Confidence, type Journal, type RoundRecord } from './types'
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The two non-numeric cells this table writes, named once so the parser below
|
|
13
|
+
* reads the same literals the renderer wrote. They are DIFFERENT facts: the
|
|
14
|
+
* loop never asked this round for a confidence at all (round 1 never is), or
|
|
15
|
+
* it asked and the developer stated nothing readable.
|
|
16
|
+
*/
|
|
17
|
+
export const CONFIDENCE_NOT_ASKED_CELL = '—'
|
|
18
|
+
export const CONFIDENCE_ABSENT_CELL = 'absent'
|
|
19
|
+
|
|
20
|
+
/** The highest percentage this table ever records — the same ceiling `CONFIDENCE_LINE`'s own `0-100` grammar accepts, named here because the parser below refuses a row that exceeds it. */
|
|
21
|
+
export const CONFIDENCE_MAX_PERCENT = 100
|
|
22
|
+
|
|
11
23
|
function confidenceCell(confidence: Confidence | null): string {
|
|
12
|
-
if (confidence === null) return
|
|
13
|
-
if (confidence === 'absent') return
|
|
24
|
+
if (confidence === null) return CONFIDENCE_NOT_ASKED_CELL
|
|
25
|
+
if (confidence === 'absent') return CONFIDENCE_ABSENT_CELL
|
|
14
26
|
return `${confidence.value}%`
|
|
15
27
|
}
|
|
16
28
|
|
|
@@ -25,3 +37,61 @@ export function renderSummary(journal: Journal): string {
|
|
|
25
37
|
const rows = journal.rounds.map(row)
|
|
26
38
|
return [header, divider, ...rows].join('\n')
|
|
27
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* One round's confidence as this table records it, in three distinguishable
|
|
43
|
+
* states rather than two:
|
|
44
|
+
*
|
|
45
|
+
* - `asked: true` with a `percent` — the developer stated that figure;
|
|
46
|
+
* - `asked: true`, `percent: null` — the round WAS asked and the statement
|
|
47
|
+
* was missing or unreadable (the table's own `absent` cell);
|
|
48
|
+
* - `asked: false`, `percent: null` — the loop never asked this round at all
|
|
49
|
+
* (its `—` cell; round 1 is never asked), so the round has no confidence
|
|
50
|
+
* to report and a reader must not be told the developer skipped one.
|
|
51
|
+
*/
|
|
52
|
+
export type SummaryConfidenceRow = { round: number; percent: number | null; asked: boolean }
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The inverse of `row` above — the confidence column read back out of a
|
|
56
|
+
* posted summary table. Kept here, beside the renderer, so the column's
|
|
57
|
+
* position is written down once: a reader elsewhere would have to hand-copy
|
|
58
|
+
* the table's shape and would drift the first time a column moved.
|
|
59
|
+
*
|
|
60
|
+
* Only rows this renderer could have produced are read: a leading round
|
|
61
|
+
* number, then one cell per severity column, then the confidence cell, then
|
|
62
|
+
* the outcome. Anything else in the comment — prose above or below the table,
|
|
63
|
+
* a differently-shaped table — yields no row at all rather than a guess.
|
|
64
|
+
*
|
|
65
|
+
* This function is the boundary between pull-request comment text (which
|
|
66
|
+
* anybody with write access to a fork's branch can shape) and the confidence
|
|
67
|
+
* figure a tool result publishes, so the percentage is bounded HERE: a cell
|
|
68
|
+
* claiming more than `CONFIDENCE_MAX_PERCENT` is dropped rather than carried
|
|
69
|
+
* out of range into a caller that declares `0-100`.
|
|
70
|
+
*/
|
|
71
|
+
export function parseSummaryConfidenceRows(body: string): SummaryConfidenceRow[] {
|
|
72
|
+
const cellCount = SEVERITY_COLUMNS.length + 3
|
|
73
|
+
const rows: SummaryConfidenceRow[] = []
|
|
74
|
+
for (const line of body.split('\n')) {
|
|
75
|
+
const trimmed = line.trim()
|
|
76
|
+
if (!trimmed.startsWith('|') || !trimmed.endsWith('|')) continue
|
|
77
|
+
const cells = trimmed.slice(1, -1).split('|')
|
|
78
|
+
if (cells.length !== cellCount) continue
|
|
79
|
+
const round = Number((cells[0] as string).trim())
|
|
80
|
+
if (!Number.isInteger(round) || round <= 0) continue
|
|
81
|
+
const confidenceCellText = (cells[cellCount - 2] as string).trim()
|
|
82
|
+
if (confidenceCellText === CONFIDENCE_NOT_ASKED_CELL) {
|
|
83
|
+
rows.push({ round, percent: null, asked: false })
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
if (confidenceCellText === CONFIDENCE_ABSENT_CELL) {
|
|
87
|
+
rows.push({ round, percent: null, asked: true })
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
const percentMatch = /^(\d{1,3})%$/.exec(confidenceCellText)
|
|
91
|
+
if (!percentMatch) continue
|
|
92
|
+
const percent = Number(percentMatch[1])
|
|
93
|
+
if (percent > CONFIDENCE_MAX_PERCENT) continue
|
|
94
|
+
rows.push({ round, percent, asked: true })
|
|
95
|
+
}
|
|
96
|
+
return rows
|
|
97
|
+
}
|
|
@@ -23,6 +23,24 @@ export { aggregateTaskTokenRows, parseTokenReportEntries, parseTokensLines } fro
|
|
|
23
23
|
export type { TokenSourcePr } from './parse-token-report'
|
|
24
24
|
export { deriveReviewStatus, parseDeveloperRoundMarker, renderReviewStatus } from './review-status'
|
|
25
25
|
export type { ReviewStatus, ReviewStatusInput } from './review-status'
|
|
26
|
+
export {
|
|
27
|
+
emptyPhaseSamples,
|
|
28
|
+
isRecordedLoopPhase,
|
|
29
|
+
medianOf,
|
|
30
|
+
MIN_PHASE_HISTORY_SAMPLES,
|
|
31
|
+
phaseHistoryClassFor,
|
|
32
|
+
phaseSamplesFromPrComments,
|
|
33
|
+
summarizePhaseSamples,
|
|
34
|
+
TASK_PHASE_LABELS,
|
|
35
|
+
taskPhaseLabel
|
|
36
|
+
} from './task-phase-history'
|
|
37
|
+
export type {
|
|
38
|
+
HistoryComment,
|
|
39
|
+
PhaseHistoryClass,
|
|
40
|
+
PhaseSamples,
|
|
41
|
+
RecordedLoopPhase,
|
|
42
|
+
TaskPhaseLabel
|
|
43
|
+
} from './task-phase-history'
|
|
26
44
|
export { formatBreakdown, formatTokenReportRow, formatTokensLine } from './report-tokens'
|
|
27
45
|
export type { TokenReportRowInput, TokensLineInput, TranscriptSummary, UsageComponents } from './report-tokens'
|
|
28
46
|
// The Claude Code collection adapter (`tranche-model.md` §12 layer 2) — one
|
|
@@ -65,10 +83,12 @@ export {
|
|
|
65
83
|
blockingSeverities,
|
|
66
84
|
CODE_REVIEW_SEVERITY_ORDER,
|
|
67
85
|
codeReviewBlockingSeverities,
|
|
86
|
+
consequentialFindings,
|
|
68
87
|
DEFAULT_REVIEW_POLICY,
|
|
69
88
|
evaluateCodeReview,
|
|
70
89
|
evaluateReviewFindings,
|
|
71
90
|
evaluateSecurityReview,
|
|
91
|
+
isConsequentialFinding,
|
|
72
92
|
isKnownSeverity,
|
|
73
93
|
isProseLocation,
|
|
74
94
|
PROSE_CAP_SEVERITY,
|
|
@@ -190,7 +210,12 @@ export {
|
|
|
190
210
|
taskRefFromBranch
|
|
191
211
|
} from './archive-task'
|
|
192
212
|
export type { MergedPrFacts } from './archive-task'
|
|
193
|
-
export {
|
|
213
|
+
export {
|
|
214
|
+
extractCodeReviewVerdict,
|
|
215
|
+
extractSecurityReviewVerdict,
|
|
216
|
+
parseFindingState,
|
|
217
|
+
VERDICT_MARKER_SOURCE
|
|
218
|
+
} from './verdict-extraction'
|
|
194
219
|
export type { VerdictExtraction } from './verdict-extraction'
|
|
195
220
|
export {
|
|
196
221
|
CHANGESET_RELEASE_BRANCH,
|
|
@@ -200,7 +225,7 @@ export {
|
|
|
200
225
|
isReviewGateExemptBranch
|
|
201
226
|
} from './review-gate'
|
|
202
227
|
export type { ReviewGateComment, ReviewGateInput, ReviewGateResult, ReviewGateVerdict } from './review-gate'
|
|
203
|
-
export { newestPrincipalRulingAuthor, newestPrincipalRulingOrdinal } from './ruling-ordinal'
|
|
228
|
+
export { newestPrincipalRulingAuthor, newestPrincipalRulingOrdinal, principalRulingMarker } from './ruling-ordinal'
|
|
204
229
|
export type { RulingComment } from './ruling-ordinal'
|
|
205
230
|
export {
|
|
206
231
|
briefHash,
|
|
@@ -393,6 +418,7 @@ export {
|
|
|
393
418
|
OPERATOR_TOOL_GRANT,
|
|
394
419
|
TASK_CANCEL_TOOL,
|
|
395
420
|
TASK_ESCALATION_READ_TOOL,
|
|
421
|
+
TASK_PR_READ_TOOL,
|
|
396
422
|
TASK_RESUME_TOOL,
|
|
397
423
|
TASK_START_TOOL,
|
|
398
424
|
TASK_STATUS_TOOL,
|
|
@@ -417,10 +443,19 @@ export {
|
|
|
417
443
|
TaskEscalationPacketSchema,
|
|
418
444
|
TaskEscalationReadInputSchema,
|
|
419
445
|
TaskEscalationReadResultSchema,
|
|
446
|
+
MAX_RETURNED_TEXT_CHARS,
|
|
447
|
+
TaskPrCheckSchema,
|
|
448
|
+
TaskPrPauseSchema,
|
|
449
|
+
TaskPrReadInputSchema,
|
|
450
|
+
TaskPrReadResultSchema,
|
|
451
|
+
TaskPrReviewRecordSchema,
|
|
452
|
+
TaskPrVerdictSchema,
|
|
420
453
|
TaskToolRefSchema,
|
|
421
454
|
TaskResumeInputSchema,
|
|
422
455
|
TaskResumeResultSchema,
|
|
423
456
|
TaskStartInputSchema,
|
|
457
|
+
TaskConfidenceSchema,
|
|
458
|
+
TaskPhaseHistorySchema,
|
|
424
459
|
TaskStatusInputSchema,
|
|
425
460
|
TaskStatusItemSchema,
|
|
426
461
|
TaskStatusResultSchema,
|
|
@@ -437,10 +472,17 @@ export type {
|
|
|
437
472
|
TaskEscalationPacket,
|
|
438
473
|
TaskEscalationReadInput,
|
|
439
474
|
TaskEscalationReadResult,
|
|
475
|
+
TaskPrCheck,
|
|
476
|
+
TaskPrReadInput,
|
|
477
|
+
TaskPrReadResult,
|
|
478
|
+
TaskPrReviewRecord,
|
|
479
|
+
TaskPrVerdict,
|
|
440
480
|
TaskResumeInput,
|
|
441
481
|
TaskResumeResult,
|
|
442
482
|
TaskStartInput,
|
|
443
483
|
TaskStartRequestInput,
|
|
484
|
+
TaskConfidence,
|
|
485
|
+
TaskPhaseHistory,
|
|
444
486
|
TaskStartResult,
|
|
445
487
|
TaskStatusInput,
|
|
446
488
|
TaskStatusResult,
|
|
@@ -519,9 +561,12 @@ export {
|
|
|
519
561
|
export type { Objective, ObjectivesSource, ParsedObjectives } from './objectives'
|
|
520
562
|
export {
|
|
521
563
|
assessRound,
|
|
564
|
+
concludedLoopRefusal,
|
|
522
565
|
initialLoopState,
|
|
566
|
+
isConcludedJournal,
|
|
523
567
|
isPublishedSummaryComment,
|
|
524
568
|
nextRoundNumber,
|
|
569
|
+
parseSummaryConfidenceRows,
|
|
525
570
|
reconstructRounds,
|
|
526
571
|
renderSummary,
|
|
527
572
|
SUMMARY_TABLE_HEADER
|
|
@@ -540,6 +585,7 @@ export type {
|
|
|
540
585
|
PendingRound,
|
|
541
586
|
ReconstructedJournal,
|
|
542
587
|
ReconstructionInput,
|
|
588
|
+
ReviewGateFact,
|
|
543
589
|
RoundOutcome,
|
|
544
590
|
RoundRecord,
|
|
545
591
|
RoundStats,
|
|
@@ -75,7 +75,13 @@
|
|
|
75
75
|
|
|
76
76
|
import { isPrincipal, isWaiverLabelActorVerified, PRINCIPAL_ALLOWLIST, WAIVER_LABEL_REVIEW } from './waiver-label'
|
|
77
77
|
import { extractCodeReviewVerdict, extractSecurityReviewVerdict } from './verdict-extraction'
|
|
78
|
-
import {
|
|
78
|
+
import {
|
|
79
|
+
consequentialFindings,
|
|
80
|
+
DEFAULT_REVIEW_POLICY,
|
|
81
|
+
evaluateCodeReview,
|
|
82
|
+
evaluateSecurityReview,
|
|
83
|
+
type ReviewPolicy
|
|
84
|
+
} from './review-policy'
|
|
79
85
|
import {
|
|
80
86
|
compareManifest,
|
|
81
87
|
policyDigest as computePolicyDigest,
|
|
@@ -311,11 +317,20 @@ export function checkReviewGate(input: ReviewGateInput): ReviewGateResult {
|
|
|
311
317
|
// returns a named `fail` result; an uncaught throw here would crash the
|
|
312
318
|
// check-run instead, on nothing worse than a typo in a manually-posted
|
|
313
319
|
// comment. Caught and failed closed the same way.
|
|
320
|
+
//
|
|
321
|
+
// O1/O4: only CONSEQUENTIAL findings are evaluated — a finding the reviewer
|
|
322
|
+
// marked `resolved` keeps its severity in the record but no longer blocks,
|
|
323
|
+
// the SAME `consequentialFindings` filter `deriveCodeReviewVerdict` applies
|
|
324
|
+
// before it derives APPROVE/PASS, so an APPROVE whose only blocking findings
|
|
325
|
+
// are `resolved` passes the gate exactly as it made derivation approve. A
|
|
326
|
+
// finding at or above the threshold in any other state — `open`,
|
|
327
|
+
// `fix-claimed`, `reproduced`, or no state token — is untouched by the
|
|
328
|
+
// filter and still blocks (O2).
|
|
314
329
|
let codeReviewPolicyEvaluation: ReturnType<typeof evaluateCodeReview>
|
|
315
330
|
let securityPolicyEvaluation: ReturnType<typeof evaluateSecurityReview>
|
|
316
331
|
try {
|
|
317
|
-
codeReviewPolicyEvaluation = evaluateCodeReview(codeReview.findingSeverities, policy)
|
|
318
|
-
securityPolicyEvaluation = evaluateSecurityReview(security.findingSeverities, policy)
|
|
332
|
+
codeReviewPolicyEvaluation = evaluateCodeReview(consequentialFindings(codeReview.findingSeverities), policy)
|
|
333
|
+
securityPolicyEvaluation = evaluateSecurityReview(consequentialFindings(security.findingSeverities), policy)
|
|
319
334
|
} catch (err) {
|
|
320
335
|
return {
|
|
321
336
|
verdict: 'fail',
|
|
@@ -146,6 +146,30 @@ export function evaluateReviewFindings<F extends PolicyFinding>(
|
|
|
146
146
|
return { outcome: blockingFindings.length > 0 ? 'blocked' : 'clean', blockingFindings }
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
* O4: the SINGLE definition of "does this finding count toward policy." A
|
|
151
|
+
* finding is consequential — evaluated by `evaluateReviewFindings` and able to
|
|
152
|
+
* block — unless the reviewer marked it `resolved`. Any other state (`open`,
|
|
153
|
+
* `fix-claimed`, `reproduced`) and a finding carrying no state token at all
|
|
154
|
+
* stay consequential and still block (O2, fail-closed): only an explicit
|
|
155
|
+
* `resolved` clears a finding from the gate, so a reviewer cannot clear a real
|
|
156
|
+
* blocker by relabelling it anything else. Imported by verdict derivation
|
|
157
|
+
* (`deriveCodeReviewVerdict`/`deriveSecurityVerdict`), the merge gate
|
|
158
|
+
* (`checkReviewGate`), and the loop's publication self-check (`publishRound`)
|
|
159
|
+
* alike, so the three can never disagree about the same verdict comment. The
|
|
160
|
+
* re-review-state grammar itself is parsed once, by `parseFindingState`
|
|
161
|
+
* (`verdict-extraction.ts`); this rule only decides what a parsed state means
|
|
162
|
+
* for policy.
|
|
163
|
+
*/
|
|
164
|
+
export function isConsequentialFinding(finding: { state?: string | null }): boolean {
|
|
165
|
+
return finding.state !== 'resolved'
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Every consequential finding (see `isConsequentialFinding`), preserving order and element type. */
|
|
169
|
+
export function consequentialFindings<F extends { state?: string | null }>(findings: readonly F[]): F[] {
|
|
170
|
+
return findings.filter((f) => isConsequentialFinding(f))
|
|
171
|
+
}
|
|
172
|
+
|
|
149
173
|
/** `evaluateReviewFindings` fixed to the code-review scale and `policy.codeReviewThreshold`. */
|
|
150
174
|
export function evaluateCodeReview<F extends PolicyFinding>(
|
|
151
175
|
findings: readonly F[],
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* head it judged. There is no second `Judged head:` regex in this file.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { extractCodeReviewVerdict, extractSecurityReviewVerdict } from './verdict-extraction'
|
|
21
|
+
import { extractCodeReviewVerdict, extractSecurityReviewVerdict, parseFindingState } from './verdict-extraction'
|
|
22
22
|
import { isPrincipal } from './waiver-label'
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -31,14 +31,16 @@ const DEVELOPER_ROUND_MARKER = /<!--\s*aeg:developer:round-(\d+)\s*-->/i
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* A rendered finding line as `review-post.ts`'s `renderFindingsSection`
|
|
34
|
-
* writes it — `<n>. [SEVERITY] <location> —
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
34
|
+
* writes it — `<n>. [SEVERITY] <location> — <description>` — matched only far
|
|
35
|
+
* enough to isolate the DESCRIPTION after the ` — ` separator; the id and
|
|
36
|
+
* re-review state are then read from that description by the shared
|
|
37
|
+
* `parseFindingState` (`verdict-extraction.ts`), the single definition of the
|
|
38
|
+
* `F<n> <class>[ <state>]:` state grammar this package carries (Traps to
|
|
39
|
+
* avoid — no second copy of the state token list). The `\S+` location match
|
|
40
|
+
* is unchanged from before this shared-parse refactor, so which lines this
|
|
41
|
+
* loop tracks is byte-for-byte what it tracked before.
|
|
39
42
|
*/
|
|
40
|
-
const FINDING_LINE =
|
|
41
|
-
/^\d+\.\s+\[[A-Z]+\]\s+\S+\s+—\s+F(\d+)(?:\s+\S+)?(?:\s+(open|fix-claimed|reproduced|resolved))?:/gm
|
|
43
|
+
const FINDING_LINE = /^\d+\.\s+\[[A-Z]+\]\s+\S+\s+—\s+(.*)$/gm
|
|
42
44
|
|
|
43
45
|
export type ReviewStatus =
|
|
44
46
|
| { state: 'CONTINUE' }
|
|
@@ -87,8 +89,11 @@ export type VerdictComment = {
|
|
|
87
89
|
export function findingStates(body: string): Map<string, string | null> {
|
|
88
90
|
const out = new Map<string, string | null>()
|
|
89
91
|
for (const m of body.matchAll(FINDING_LINE)) {
|
|
90
|
-
const id =
|
|
91
|
-
|
|
92
|
+
const { id, state } = parseFindingState(m[1] as string)
|
|
93
|
+
// A description with no `F<n>` head is not a tracked finding — the prior
|
|
94
|
+
// regex required `F(\d+)` on the line, so a line without one was never
|
|
95
|
+
// matched at all; skipping it here keeps that behaviour exactly.
|
|
96
|
+
if (id === null) continue
|
|
92
97
|
// A round that lists the same id twice keeps the first state it declared;
|
|
93
98
|
// a later id-less repeat must never erase a real `resolved`/`reproduced`.
|
|
94
99
|
if (!out.has(id) || out.get(id) === null) out.set(id, state)
|
|
@@ -18,6 +18,22 @@ import { isPrincipal } from './waiver-label'
|
|
|
18
18
|
/** The marker `apps/cli/src/commands/pr-rule.ts` posts: `<!-- aeg:principal:ruling:<pr>-<k> -->`, one line, nothing else on it. */
|
|
19
19
|
const RULING_MARKER_ORDINAL = /^<!-- aeg:principal:ruling:\d+-(\d+) -->$/
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The marker line a principal ruling carries, built from the two numbers it
|
|
23
|
+
* encodes — `<ref>-<ordinal>`, where `ref` is the pull request or Issue the
|
|
24
|
+
* ruling is about and `ordinal` is the strictly-increasing `k` every reader
|
|
25
|
+
* here compares. It lives beside `RULING_MARKER_ORDINAL` because the two
|
|
26
|
+
* cannot be allowed to disagree about which slot the ordinal sits in: a
|
|
27
|
+
* renderer that swapped them emitted a marker that parsed as ordinal `1`
|
|
28
|
+
* forever, so a ruling written exactly as instructed failed the very
|
|
29
|
+
* freshness gate it was posted to satisfy. Any caller that WRITES a marker a
|
|
30
|
+
* reader here will parse should build it with this rather than by
|
|
31
|
+
* interpolating its own template.
|
|
32
|
+
*/
|
|
33
|
+
export function principalRulingMarker(ref: number, ordinal: number): string {
|
|
34
|
+
return `<!-- aeg:principal:ruling:${ref}-${ordinal} -->`
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
export type RulingComment = {
|
|
22
38
|
body: string
|
|
23
39
|
/** The comment author's GitHub login, or `null` when the caller could not resolve one. */
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a run is, and what that place usually takes in this repository.
|
|
3
|
+
*
|
|
4
|
+
* Two pure concerns, both read by the task-status reader and the `task_status`
|
|
5
|
+
* tool:
|
|
6
|
+
*
|
|
7
|
+
* - **The phase vocabulary.** The dev-review-loop's own recovery record
|
|
8
|
+
* (`loop_state`) carries a `phase` string mirroring the driver's own
|
|
9
|
+
* `Decision['type']`. `TASK_PHASE_LABELS` maps each recorded phase to the
|
|
10
|
+
* one word a reader sees, one-to-one — never a phase invented from a
|
|
11
|
+
* second source, and never one recorded phase split into two.
|
|
12
|
+
* - **Typical phase times, from history.** `phaseSamplesFromPrComments`
|
|
13
|
+
* reads durations off a merged task pull request's own principal-authored
|
|
14
|
+
* comments: a developer round marker, then that round's verdict comments,
|
|
15
|
+
* then the next round's marker. The interval marker → verdicts is time
|
|
16
|
+
* spent reviewing; verdicts → next marker is time spent developing.
|
|
17
|
+
* `summarizePhaseSamples` reduces a set of those to a MEDIAN and a sample
|
|
18
|
+
* count, and refuses to answer at all below `MIN_PHASE_HISTORY_SAMPLES`.
|
|
19
|
+
*
|
|
20
|
+
* Every figure this module produces is history — what already happened, on
|
|
21
|
+
* merged work — and is named that way (`typicalPhaseMinutes`, never an ETA,
|
|
22
|
+
* never a remaining time, never a deadline). Nothing here predicts when a run
|
|
23
|
+
* in flight will finish.
|
|
24
|
+
*
|
|
25
|
+
* Only principal-authored comments contribute a sample: the same trust
|
|
26
|
+
* boundary every other forge read in this loop applies, so a non-principal
|
|
27
|
+
* commenter cannot post a round-marker- or verdict-shaped comment and shift
|
|
28
|
+
* what the repository reports as typical.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { parseDeveloperRoundMarker } from './review-status'
|
|
32
|
+
import type { TaskPhaseHistory } from './task-tools'
|
|
33
|
+
import { extractCodeReviewVerdict, extractSecurityReviewVerdict } from './verdict-extraction'
|
|
34
|
+
import { isPrincipal } from './waiver-label'
|
|
35
|
+
|
|
36
|
+
// --- the phase vocabulary ---------------------------------------------------
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The phases the loop actually records, and the word each reads as. One entry
|
|
40
|
+
* per `Decision['type']` the driver persists into `loop_state.phase`:
|
|
41
|
+
*
|
|
42
|
+
* | recorded phase | shown as |
|
|
43
|
+
* | -------------------- | -------------------- |
|
|
44
|
+
* | `dispatch_developer` | `developing` |
|
|
45
|
+
* | `ask_confidence` | `awaiting confidence`|
|
|
46
|
+
* | `dispatch_reviewers` | `reviewing` |
|
|
47
|
+
* | `publish` | `publishing` |
|
|
48
|
+
* | `pause` | `paused` |
|
|
49
|
+
*
|
|
50
|
+
* There is deliberately no separate `waiting for CI` phase: the driver polls
|
|
51
|
+
* the head's checks while the record still reads `dispatch_developer`, so a
|
|
52
|
+
* distinct CI-wait row would have to be inferred from a second source rather
|
|
53
|
+
* than read from the record. `developing` therefore spans the developer's own
|
|
54
|
+
* turn AND the gate wait that follows its push — stated here rather than left
|
|
55
|
+
* for a reader to assume.
|
|
56
|
+
*/
|
|
57
|
+
export const TASK_PHASE_LABELS = {
|
|
58
|
+
dispatch_developer: 'developing',
|
|
59
|
+
ask_confidence: 'awaiting confidence',
|
|
60
|
+
dispatch_reviewers: 'reviewing',
|
|
61
|
+
publish: 'publishing',
|
|
62
|
+
pause: 'paused'
|
|
63
|
+
} as const
|
|
64
|
+
|
|
65
|
+
export type RecordedLoopPhase = keyof typeof TASK_PHASE_LABELS
|
|
66
|
+
export type TaskPhaseLabel = (typeof TASK_PHASE_LABELS)[RecordedLoopPhase]
|
|
67
|
+
|
|
68
|
+
export function isRecordedLoopPhase(phase: string): phase is RecordedLoopPhase {
|
|
69
|
+
return Object.hasOwn(TASK_PHASE_LABELS, phase)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The shown phase for a recorded one. A phase this vocabulary does not know (a decision type added after this mapping) reads back VERBATIM — the record's own word, never a guess at which known phase it resembles. */
|
|
73
|
+
export function taskPhaseLabel(phase: string): string {
|
|
74
|
+
return isRecordedLoopPhase(phase) ? TASK_PHASE_LABELS[phase] : phase
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Which history class a recorded phase compares against — `null` for a phase
|
|
79
|
+
* the pull-request record carries no interval for. `publish` and `pause` have
|
|
80
|
+
* none by nature (publishing is one comment post; a pause ends when a person
|
|
81
|
+
* acts), and `ask_confidence` has none because it is not separable from the
|
|
82
|
+
* developer turn it interrupts.
|
|
83
|
+
*/
|
|
84
|
+
export type PhaseHistoryClass = 'developing' | 'reviewing'
|
|
85
|
+
|
|
86
|
+
export function phaseHistoryClassFor(phase: string): PhaseHistoryClass | null {
|
|
87
|
+
if (phase === 'dispatch_developer') return 'developing'
|
|
88
|
+
if (phase === 'dispatch_reviewers') return 'reviewing'
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// --- typical phase times, from merged pull requests -------------------------
|
|
93
|
+
|
|
94
|
+
/** One comment as a history read sees it: its body, its author, and the forge's own creation timestamp. */
|
|
95
|
+
export type HistoryComment = { body: string; author: string | null; createdAt: string }
|
|
96
|
+
|
|
97
|
+
/** Minutes, one entry per interval the record actually carried — never a filled-in or interpolated value. */
|
|
98
|
+
export type PhaseSamples = { [K in PhaseHistoryClass]: number[] }
|
|
99
|
+
|
|
100
|
+
export function emptyPhaseSamples(): PhaseSamples {
|
|
101
|
+
return { developing: [], reviewing: [] }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A verdict comment is one either merge-gate extractor parses clean — the same "did this cast a verdict" test the gate itself applies, so this read can never disagree with it about which comment ended a round. */
|
|
105
|
+
function isVerdictComment(body: string): boolean {
|
|
106
|
+
return (
|
|
107
|
+
extractCodeReviewVerdict([body]).danglingNote === null || extractSecurityReviewVerdict([body]).danglingNote === null
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type PhaseEvent = { kind: 'marker'; at: number } | { kind: 'verdict'; at: number }
|
|
112
|
+
|
|
113
|
+
function minutesBetween(fromMs: number, toMs: number): number | null {
|
|
114
|
+
const ms = toMs - fromMs
|
|
115
|
+
return ms >= 0 ? ms / 60_000 : null
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The phase intervals one pull request's comments record. Ordered by the
|
|
120
|
+
* forge's own timestamps rather than by the order the read returned them, so
|
|
121
|
+
* a paginated or re-ordered read measures the same intervals.
|
|
122
|
+
*
|
|
123
|
+
* A round whose verdicts were never posted as comments contributes NOTHING —
|
|
124
|
+
* neither a reviewing nor a developing sample — because the record does not
|
|
125
|
+
* say where that round's time went. Today the driver posts a round's verdict
|
|
126
|
+
* comments when it publishes, so a pull request that took several rounds
|
|
127
|
+
* carries one reviewing interval and no developing interval at all; that is
|
|
128
|
+
* a thin history, and `summarizePhaseSamples` below refuses to turn a thin
|
|
129
|
+
* history into a number.
|
|
130
|
+
*/
|
|
131
|
+
export function phaseSamplesFromPrComments(
|
|
132
|
+
comments: readonly HistoryComment[],
|
|
133
|
+
allowlist: readonly string[]
|
|
134
|
+
): PhaseSamples {
|
|
135
|
+
const events: PhaseEvent[] = []
|
|
136
|
+
for (const comment of comments) {
|
|
137
|
+
if (!isPrincipal(comment.author, allowlist as string[])) continue
|
|
138
|
+
const at = Date.parse(comment.createdAt)
|
|
139
|
+
if (!Number.isFinite(at)) continue
|
|
140
|
+
if (parseDeveloperRoundMarker(comment.body) !== null) events.push({ kind: 'marker', at })
|
|
141
|
+
else if (isVerdictComment(comment.body)) events.push({ kind: 'verdict', at })
|
|
142
|
+
}
|
|
143
|
+
events.sort((a, b) => a.at - b.at)
|
|
144
|
+
|
|
145
|
+
const samples = emptyPhaseSamples()
|
|
146
|
+
let markerAt: number | null = null
|
|
147
|
+
let lastVerdictAt: number | null = null
|
|
148
|
+
const closeRound = (): void => {
|
|
149
|
+
if (markerAt === null || lastVerdictAt === null) return
|
|
150
|
+
const minutes = minutesBetween(markerAt, lastVerdictAt)
|
|
151
|
+
if (minutes !== null) samples.reviewing.push(minutes)
|
|
152
|
+
}
|
|
153
|
+
for (const event of events) {
|
|
154
|
+
if (event.kind === 'marker') {
|
|
155
|
+
closeRound()
|
|
156
|
+
if (lastVerdictAt !== null) {
|
|
157
|
+
const minutes = minutesBetween(lastVerdictAt, event.at)
|
|
158
|
+
if (minutes !== null) samples.developing.push(minutes)
|
|
159
|
+
}
|
|
160
|
+
markerAt = event.at
|
|
161
|
+
lastVerdictAt = null
|
|
162
|
+
continue
|
|
163
|
+
}
|
|
164
|
+
// A round posts more than one verdict (a code review and a security
|
|
165
|
+
// pass); the round's review ends at the LAST of them.
|
|
166
|
+
if (markerAt !== null) lastVerdictAt = lastVerdictAt === null ? event.at : Math.max(lastVerdictAt, event.at)
|
|
167
|
+
}
|
|
168
|
+
closeRound()
|
|
169
|
+
return samples
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Below this many past intervals, a phase reports no typical time at all: two samples from two pull requests describe those two pull requests, not this repository. */
|
|
173
|
+
export const MIN_PHASE_HISTORY_SAMPLES = 3
|
|
174
|
+
|
|
175
|
+
// The median of a phase's past intervals, with the count it was computed
|
|
176
|
+
// from, is `TaskPhaseHistory` (`task-tools.ts`) — the shape the `task_status`
|
|
177
|
+
// result schema declares. One name for the fact, derived from the schema
|
|
178
|
+
// itself, so the reader and the published contract cannot drift apart.
|
|
179
|
+
|
|
180
|
+
export function medianOf(values: readonly number[]): number | null {
|
|
181
|
+
if (values.length === 0) return null
|
|
182
|
+
const sorted = [...values].sort((a, b) => a - b)
|
|
183
|
+
const mid = Math.floor(sorted.length / 2)
|
|
184
|
+
if (sorted.length % 2 === 1) return sorted[mid] as number
|
|
185
|
+
return ((sorted[mid - 1] as number) + (sorted[mid] as number)) / 2
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** `null` — no typical time, never an invented one — for a phase with fewer than `MIN_PHASE_HISTORY_SAMPLES` past intervals, and for one with none at all. */
|
|
189
|
+
export function summarizePhaseSamples(minutes: readonly number[]): TaskPhaseHistory | null {
|
|
190
|
+
if (minutes.length < MIN_PHASE_HISTORY_SAMPLES) return null
|
|
191
|
+
const median = medianOf(minutes)
|
|
192
|
+
if (median === null) return null
|
|
193
|
+
return { typicalPhaseMinutes: Math.round(median), typicalPhaseSamples: minutes.length }
|
|
194
|
+
}
|