@aviaratech/ai-delivery 0.3.35 → 0.3.37
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/CONTRIBUTING.md +12 -206
- package/README.md +56 -554
- package/dist/agent.d.ts +1 -3
- package/dist/agent.js +74 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1651 -1590
- package/dist/boardReconcile.test.js.map +7 -1
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +91 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +389 -517
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -45
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +424 -369
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +288 -14
- package/dist/config/deliveryConfig.js +472 -390
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +773 -649
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -479
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +16 -11
- package/dist/dispatch.js +316 -354
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +103 -96
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +63 -23
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.d.ts +0 -3
- package/dist/git.js +59 -76
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +42 -52
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +1 -0
- package/dist/github/discovery.js +197 -215
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +18 -2
- package/dist/github/projectDelivery.js +615 -557
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.js +433 -389
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +40 -9
- package/dist/issue.js +2102 -1742
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +989 -885
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1938 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1059 -989
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -94
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +252 -310
- package/dist/mcp/tools.js +235 -342
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1229
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1842 -1423
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +417 -413
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +114 -131
- package/dist/pr.js +1314 -1327
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +967 -653
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +123 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +184 -0
- package/dist/readView.js +218 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +146 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +125 -125
- package/dist/services/boardReconcileService.js +1295 -1421
- package/dist/services/boardReconcileService.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +321 -358
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +274 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +451 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.d.ts +0 -2
- package/dist/utils/atomicJson.js +81 -77
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.d.ts +0 -8
- package/dist/utils/filesystem.js +5 -19
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -54
- package/dist/verification.js +976 -1941
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.js +45 -24
- package/dist/version.js.map +7 -1
- package/package.json +9 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
- package/plugins/ai-delivery/runtime/dist/cli.js +351 -115
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/services/deliveryAdmission.d.ts +0 -49
- package/dist/services/deliveryAdmission.js +0 -165
- package/dist/services/deliveryAdmission.js.map +0 -1
- package/dist/services/worktreeRegistry.d.ts +0 -434
- package/dist/services/worktreeRegistry.js +0 -1248
- package/dist/services/worktreeRegistry.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3329
- package/dist/setup.test.js.map +0 -1
- package/dist/worktree.d.ts +0 -28
- package/dist/worktree.js +0 -188
- package/dist/worktree.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
import { loadDeliverySettings } from "./config/deliveryConfig.js";
|
|
2
|
+
import { digestValue } from "./delivery/common.js";
|
|
3
|
+
import { DeliveryError } from "./errors.js";
|
|
4
|
+
import { createDeliveryGitHubClients } from "./github/client.js";
|
|
5
|
+
import { evaluateCommandIdentityPolicy } from "./github/commandIdentityPolicy.js";
|
|
6
|
+
import {
|
|
7
|
+
getProjectDeliveryConfiguration,
|
|
8
|
+
projectSettingsFromDeliveryConfig,
|
|
9
|
+
readProjectDeliveryItems
|
|
10
|
+
} from "./github/projectDelivery.js";
|
|
11
|
+
import { loadDeliveryContext } from "./issue.js";
|
|
12
|
+
import { parseJournalAttention } from "./issueJournal.js";
|
|
13
|
+
import { hasDeliveryMergeTrailer, hasDeliveryPrMarker, readPrBoardFacts } from "./pr.js";
|
|
14
|
+
const boardSections = [
|
|
15
|
+
["humanAttention", "Human attention"],
|
|
16
|
+
["readyPrs", "Ready PRs"],
|
|
17
|
+
["blockedPrs", "Blocked PRs"],
|
|
18
|
+
["staleIssues", "Stale In Progress issues (72h)"]
|
|
19
|
+
];
|
|
20
|
+
function singleLine(value) {
|
|
21
|
+
return value.replace(/[\p{Cc}\s]+/gu, " ").replace(/[\\`*_[\]<>]/gu, "\\$&");
|
|
22
|
+
}
|
|
23
|
+
function metricText(value) {
|
|
24
|
+
const fraction = `${value.marked}/${value.total}`;
|
|
25
|
+
return value.complete ? `${fraction} (${value.percentage === null ? "n/a" : `${Math.round(value.percentage)}%`})` : `${fraction} observed; unknown ${value.unknown}; incomplete`;
|
|
26
|
+
}
|
|
27
|
+
function renderDeliveryBoard(result) {
|
|
28
|
+
const groups = boardSections.map(([section, heading2]) => ({
|
|
29
|
+
section,
|
|
30
|
+
heading: heading2,
|
|
31
|
+
repositories: result.repositories.map((repo) => ({
|
|
32
|
+
repo,
|
|
33
|
+
rows: [...repo[section]].sort((a, b) => a.number - b.number).map((row2) => {
|
|
34
|
+
const url = row2.url.replace(/[\\<>()[\]\s]/gu, (character) => encodeURIComponent(character));
|
|
35
|
+
const reason = row2.reasons.length ? ` ${row2.reasons[0]}${row2.reasons.length > 1 ? ` +${row2.reasons.length - 1}` : ""}` : "";
|
|
36
|
+
return {
|
|
37
|
+
link: `[#${row2.number}](${url})${reason}`,
|
|
38
|
+
title: singleLine(row2.title).slice(0, 80)
|
|
39
|
+
};
|
|
40
|
+
})
|
|
41
|
+
}))
|
|
42
|
+
}));
|
|
43
|
+
const count = groups.reduce(
|
|
44
|
+
(total, group) => total + group.repositories.reduce((n, repo) => n + repo.rows.length, 0),
|
|
45
|
+
0
|
|
46
|
+
);
|
|
47
|
+
const heading = `Delivery board @ ${result.collection.asOf} (${result.complete ? "complete" : "partial"})`;
|
|
48
|
+
const metadata = result.repositories.map((repo) => {
|
|
49
|
+
const gaps = boardSections.flatMap(([section]) => {
|
|
50
|
+
const scope = repo.coverage[section];
|
|
51
|
+
return scope.status === "complete" ? [] : [
|
|
52
|
+
`${section}:${scope.status}, unknown ${scope.unknownRows.length}${scope.reasons[0] ? `, ${scope.reasons[0]}` : ""}`
|
|
53
|
+
];
|
|
54
|
+
});
|
|
55
|
+
return `${repo.repository}: ${repo.access}; 7d opened ${metricText(repo.metrics.opened)}, merged ${metricText(repo.metrics.merged)}${gaps.length ? `; ${gaps.join("; ")}` : "; coverage complete"}`;
|
|
56
|
+
});
|
|
57
|
+
function render(titles, visible) {
|
|
58
|
+
let remaining = visible;
|
|
59
|
+
return [
|
|
60
|
+
heading,
|
|
61
|
+
...metadata,
|
|
62
|
+
...groups.map((group) => {
|
|
63
|
+
const lines = group.repositories.flatMap(({ repo, rows }) => {
|
|
64
|
+
if (!rows.length) return [];
|
|
65
|
+
const shown = rows.slice(0, remaining);
|
|
66
|
+
remaining -= shown.length;
|
|
67
|
+
return [
|
|
68
|
+
`${repo.repository}:`,
|
|
69
|
+
...shown.map((row2) => `${row2.link}${titles && row2.title ? ` ${row2.title}` : ""}`),
|
|
70
|
+
...shown.length < rows.length ? [`${rows.length - shown.length} rows omitted`] : []
|
|
71
|
+
];
|
|
72
|
+
});
|
|
73
|
+
return `${group.heading}
|
|
74
|
+
${lines.length ? lines.join("\n") : "None observed"}`;
|
|
75
|
+
})
|
|
76
|
+
].join("\n");
|
|
77
|
+
}
|
|
78
|
+
function fits(value) {
|
|
79
|
+
return Math.max(value.length + 1, JSON.stringify(value).length) <= 3999;
|
|
80
|
+
}
|
|
81
|
+
const titled = render(true, count);
|
|
82
|
+
if (fits(titled)) return titled;
|
|
83
|
+
const links = render(false, count);
|
|
84
|
+
if (fits(links)) return links;
|
|
85
|
+
if (fits(render(false, 0))) {
|
|
86
|
+
let lower = 0, upper = count;
|
|
87
|
+
while (lower < upper) {
|
|
88
|
+
const middle = Math.ceil((lower + upper) / 2);
|
|
89
|
+
if (fits(render(false, middle))) lower = middle;
|
|
90
|
+
else upper = middle - 1;
|
|
91
|
+
}
|
|
92
|
+
return render(false, lower);
|
|
93
|
+
}
|
|
94
|
+
return [
|
|
95
|
+
heading,
|
|
96
|
+
`${result.repositories.length} repository details omitted; readable ${result.repositories.filter((repo) => repo.access === "readable").length}, unreadable ${result.repositories.filter((repo) => repo.access === "unreadable").length}, unknown ${result.repositories.filter((repo) => repo.access === "unknown").length}. Per-repository metrics/reasons remain in full JSON.`,
|
|
97
|
+
...groups.map((group) => {
|
|
98
|
+
const rows = group.repositories.reduce((n, repo) => n + repo.rows.length, 0);
|
|
99
|
+
const scopes = result.repositories.map((repo) => repo.coverage[group.section]);
|
|
100
|
+
return `${group.heading}
|
|
101
|
+
${rows ? `${rows} rows omitted` : "None observed"}; coverage unavailable ${scopes.filter((scope) => scope.status === "unavailable").length}, partial ${scopes.filter((scope) => scope.status === "partial").length}; unknown rows ${scopes.reduce((n, scope) => n + scope.unknownRows.length, 0)}`;
|
|
102
|
+
})
|
|
103
|
+
].join("\n");
|
|
104
|
+
}
|
|
105
|
+
const repositoryPattern = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u;
|
|
106
|
+
const pageLimit = 20;
|
|
107
|
+
const retainedLimit = 16 * 1024 * 1024;
|
|
108
|
+
const day = 24 * 60 * 60 * 1e3;
|
|
109
|
+
const retainedDataLimit = new DeliveryError("Board retained-data limit reached.");
|
|
110
|
+
function record(value) {
|
|
111
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
112
|
+
throw new DeliveryError("Board observation is incomplete.");
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
function text(value) {
|
|
116
|
+
if (typeof value !== "string" || !value || new RegExp("\\p{Cc}", "u").test(value))
|
|
117
|
+
throw new DeliveryError("Board identity is incomplete.");
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
function number(value) {
|
|
121
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0)
|
|
122
|
+
throw new DeliveryError("Board number is incomplete.");
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
function timestamp(value) {
|
|
126
|
+
const parsed = typeof value === "string" ? Date.parse(value) : NaN;
|
|
127
|
+
if (!Number.isFinite(parsed)) throw new DeliveryError("Board timestamp is incomplete.");
|
|
128
|
+
return parsed;
|
|
129
|
+
}
|
|
130
|
+
function array(value) {
|
|
131
|
+
if (!Array.isArray(value)) throw new DeliveryError("Board connection is incomplete.");
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
function code(error) {
|
|
135
|
+
if (error === retainedDataLimit) return "retained-data-limit";
|
|
136
|
+
const status = typeof error === "object" && error !== null ? Reflect.get(error, "status") : void 0;
|
|
137
|
+
return status === 401 || status === 403 ? "access-denied" : status === 404 ? "not-readable" : "read-incomplete";
|
|
138
|
+
}
|
|
139
|
+
function parseDeliveryBoardRequest(raw) {
|
|
140
|
+
const input = record(raw), repos = [], decisionLabels = [];
|
|
141
|
+
for (const value of array(input.repos)) {
|
|
142
|
+
if (typeof value !== "string" || !repositoryPattern.test(value))
|
|
143
|
+
throw new DeliveryError("Board repos must contain explicit owner/name selectors.");
|
|
144
|
+
const repository = value.toLowerCase();
|
|
145
|
+
if (!repos.includes(repository)) repos.push(repository);
|
|
146
|
+
}
|
|
147
|
+
if (!repos.length) throw new DeliveryError("Board repos must not be empty.");
|
|
148
|
+
const labels = /* @__PURE__ */ new Set();
|
|
149
|
+
for (const value of input.decisionLabels === void 0 ? [] : array(input.decisionLabels)) {
|
|
150
|
+
if (typeof value !== "string" || !value.trim() || new RegExp("\\p{Cc}", "u").test(value))
|
|
151
|
+
throw new DeliveryError("Board decision labels must be nonempty single-line strings.");
|
|
152
|
+
if (!labels.has(value.trim().toLowerCase())) decisionLabels.push(value.trim());
|
|
153
|
+
labels.add(value.trim().toLowerCase());
|
|
154
|
+
}
|
|
155
|
+
return { repos, decisionLabels };
|
|
156
|
+
}
|
|
157
|
+
function coverage() {
|
|
158
|
+
return { status: "complete", observed: 0, unknownRows: [], reasons: [] };
|
|
159
|
+
}
|
|
160
|
+
function metric() {
|
|
161
|
+
return { marked: 0, total: 0, unknown: 0, complete: true, percentage: null, reasons: [] };
|
|
162
|
+
}
|
|
163
|
+
function emptyRepository(repository) {
|
|
164
|
+
return {
|
|
165
|
+
repository,
|
|
166
|
+
access: "unknown",
|
|
167
|
+
humanAttention: [],
|
|
168
|
+
readyPrs: [],
|
|
169
|
+
blockedPrs: [],
|
|
170
|
+
staleIssues: [],
|
|
171
|
+
coverage: {
|
|
172
|
+
humanAttention: coverage(),
|
|
173
|
+
readyPrs: coverage(),
|
|
174
|
+
blockedPrs: coverage(),
|
|
175
|
+
staleIssues: coverage()
|
|
176
|
+
},
|
|
177
|
+
diagnostics: [],
|
|
178
|
+
metrics: { opened: metric(), merged: metric() }
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function gap(result, retain, section, reason, row2, unavailable = false) {
|
|
182
|
+
const at = result.coverage[section];
|
|
183
|
+
if (unavailable || at.status === "unavailable") at.status = "unavailable";
|
|
184
|
+
else at.status = "partial";
|
|
185
|
+
if (!at.reasons.includes(reason)) at.reasons.push(reason);
|
|
186
|
+
if (row2) {
|
|
187
|
+
const bounded = {
|
|
188
|
+
repository: row2.repository,
|
|
189
|
+
id: row2.id,
|
|
190
|
+
number: row2.number,
|
|
191
|
+
url: row2.url,
|
|
192
|
+
title: "",
|
|
193
|
+
reasons: [reason]
|
|
194
|
+
};
|
|
195
|
+
try {
|
|
196
|
+
retain(bounded);
|
|
197
|
+
at.unknownRows.push(bounded);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (error !== retainedDataLimit) throw error;
|
|
200
|
+
if (!at.reasons.includes("unknown-rows-omitted")) at.reasons.push("unknown-rows-omitted");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function resultRow(result, retain, section, row2) {
|
|
205
|
+
try {
|
|
206
|
+
retain(row2);
|
|
207
|
+
return row2;
|
|
208
|
+
} catch (error) {
|
|
209
|
+
if (error !== retainedDataLimit) throw error;
|
|
210
|
+
gap(result, retain, section, "retained-data-limit");
|
|
211
|
+
const bounded = { ...row2, title: "" };
|
|
212
|
+
try {
|
|
213
|
+
retain(bounded);
|
|
214
|
+
return bounded;
|
|
215
|
+
} catch (fallbackError) {
|
|
216
|
+
if (fallbackError !== retainedDataLimit) throw fallbackError;
|
|
217
|
+
gap(result, retain, section, "retained-data-limit", row2);
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function row(repository, raw, kind) {
|
|
223
|
+
const value = record(raw), n = number(value.number), url = text(value.html_url);
|
|
224
|
+
if (url.toLowerCase() !== `https://github.com/${repository}/${kind}/${n}`)
|
|
225
|
+
throw new DeliveryError("Board row repository identity is inconsistent.");
|
|
226
|
+
return {
|
|
227
|
+
repository,
|
|
228
|
+
id: text(value.node_id),
|
|
229
|
+
number: n,
|
|
230
|
+
url,
|
|
231
|
+
title: typeof value.title === "string" ? value.title : "",
|
|
232
|
+
reasons: []
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async function issues(context, result, retain, signal) {
|
|
236
|
+
const found = [], ids = /* @__PURE__ */ new Set();
|
|
237
|
+
try {
|
|
238
|
+
for (let page = 1; page <= pageLimit; page++) {
|
|
239
|
+
signal?.throwIfAborted();
|
|
240
|
+
const response = await context.clients.rest.issues.listForRepo({
|
|
241
|
+
...context.repo,
|
|
242
|
+
state: "open",
|
|
243
|
+
per_page: 100,
|
|
244
|
+
page
|
|
245
|
+
});
|
|
246
|
+
signal?.throwIfAborted();
|
|
247
|
+
for (const value of response.data) {
|
|
248
|
+
if (value.pull_request !== void 0) continue;
|
|
249
|
+
const item = row(result.repository, value, "issues");
|
|
250
|
+
if (value.state !== "open" || ids.has(item.id)) throw new DeliveryError("Issue inventory identity changed.");
|
|
251
|
+
const labels = value.labels.map((label) => typeof label === "string" ? label : text(label.name));
|
|
252
|
+
const updatedAt = timestamp(value.updated_at);
|
|
253
|
+
const observation = { row: { ...item, updatedAt: value.updated_at }, labels, updatedAt };
|
|
254
|
+
retain(observation);
|
|
255
|
+
ids.add(item.id);
|
|
256
|
+
found.push(observation);
|
|
257
|
+
}
|
|
258
|
+
if (response.data.length < 100 && !response.headers.link?.includes('rel="next"')) return found;
|
|
259
|
+
}
|
|
260
|
+
throw new DeliveryError("Issue inventory reached its page limit.");
|
|
261
|
+
} catch (error) {
|
|
262
|
+
signal?.throwIfAborted();
|
|
263
|
+
gap(result, retain, "humanAttention", code(error));
|
|
264
|
+
gap(result, retain, "staleIssues", code(error));
|
|
265
|
+
return found;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async function attention(context, repositoryId, issue, retain, signal) {
|
|
269
|
+
let cursor = null, retained = 0;
|
|
270
|
+
const cursors = /* @__PURE__ */ new Set(), ids = /* @__PURE__ */ new Set();
|
|
271
|
+
let latest = null;
|
|
272
|
+
for (let page = 0; page < pageLimit; page++) {
|
|
273
|
+
signal?.throwIfAborted();
|
|
274
|
+
const response = await context.clients.graphql(
|
|
275
|
+
`query DeliveryBoardJournal($owner: String!, $repo: String!, $number: Int!, $cursor: String) {
|
|
276
|
+
repository(owner: $owner, name: $repo) { id nameWithOwner issue(number: $number) { id number
|
|
277
|
+
comments(last: 100, before: $cursor) { nodes { id fullDatabaseId createdAt url body } pageInfo { hasPreviousPage startCursor } }
|
|
278
|
+
} }
|
|
279
|
+
}`,
|
|
280
|
+
{ ...context.repo, number: issue.row.number, cursor }
|
|
281
|
+
);
|
|
282
|
+
signal?.throwIfAborted();
|
|
283
|
+
const parent = record(record(response).repository), native = record(parent.issue), connection = record(native.comments);
|
|
284
|
+
if (parent.id !== repositoryId || text(parent.nameWithOwner).toLowerCase() !== issue.row.repository || native.id !== issue.row.id || native.number !== issue.row.number)
|
|
285
|
+
throw new DeliveryError("Journal parent identity is inconsistent.");
|
|
286
|
+
for (const raw of array(connection.nodes)) {
|
|
287
|
+
const comment = record(raw), id = text(comment.id);
|
|
288
|
+
if (ids.has(id)) throw new DeliveryError("Journal comment identity repeated.");
|
|
289
|
+
ids.add(id);
|
|
290
|
+
if (typeof comment.body !== "string") throw new DeliveryError("Journal body is incomplete.");
|
|
291
|
+
retained += Buffer.byteLength(JSON.stringify(comment));
|
|
292
|
+
if (retained > retainedLimit) throw retainedDataLimit;
|
|
293
|
+
retain(id);
|
|
294
|
+
if (!/<!--\s*ai-delivery:journal@/u.test(comment.body)) continue;
|
|
295
|
+
const created = timestamp(comment.createdAt), nativeId = comment.fullDatabaseId;
|
|
296
|
+
if ((typeof nativeId !== "string" || !/^[1-9]\d*$/u.test(nativeId)) && (typeof nativeId !== "number" || !Number.isSafeInteger(nativeId) || nativeId <= 0))
|
|
297
|
+
throw new DeliveryError("Journal numeric identity is incomplete.");
|
|
298
|
+
const numeric = BigInt(nativeId), url = text(comment.url);
|
|
299
|
+
if (latest && latest.created === created && latest.numeric === numeric)
|
|
300
|
+
throw new DeliveryError("Journal ordering identity repeated.");
|
|
301
|
+
if (!latest || created > latest.created || created === latest.created && numeric > latest.numeric)
|
|
302
|
+
latest = { created, numeric, body: comment.body, id, url };
|
|
303
|
+
}
|
|
304
|
+
const info = record(connection.pageInfo);
|
|
305
|
+
if (info.hasPreviousPage === false) {
|
|
306
|
+
const result = latest ? { ...parseJournalAttention(latest.body), commentId: latest.id, url: latest.url } : { kind: null, state: "clear", request: null, reason: null, commentId: null, url: null };
|
|
307
|
+
retain(result);
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
if (info.hasPreviousPage !== true) throw new DeliveryError("Journal pagination is incomplete.");
|
|
311
|
+
cursor = text(info.startCursor);
|
|
312
|
+
if (cursors.has(cursor)) throw new DeliveryError("Journal cursor repeated.");
|
|
313
|
+
cursors.add(cursor);
|
|
314
|
+
}
|
|
315
|
+
throw new DeliveryError("Journal page limit reached.");
|
|
316
|
+
}
|
|
317
|
+
async function projectItems(context, cache, principal, retain, signal) {
|
|
318
|
+
const routing = context.configuration?.routing;
|
|
319
|
+
if (!routing) throw new DeliveryError("Project routing is unavailable.");
|
|
320
|
+
const key = `${principal}:${routing.projectId}`;
|
|
321
|
+
const expected = digestValue({
|
|
322
|
+
projectId: routing.projectId,
|
|
323
|
+
statusFieldId: routing.statusFieldId,
|
|
324
|
+
statusOptionIds: routing.statusOptionIds,
|
|
325
|
+
pointsFieldId: routing.pointsFieldId,
|
|
326
|
+
priorityFieldId: routing.priorityFieldId,
|
|
327
|
+
organization: context.config.native.organization,
|
|
328
|
+
settings: projectSettingsFromDeliveryConfig(context.config)
|
|
329
|
+
});
|
|
330
|
+
const prior = cache.get(key);
|
|
331
|
+
if (prior) {
|
|
332
|
+
if (prior.identity !== expected || !prior.items)
|
|
333
|
+
throw new DeliveryError("Shared Project mapping or inventory is incomplete.");
|
|
334
|
+
return prior.items;
|
|
335
|
+
}
|
|
336
|
+
cache.set(key, { identity: expected, items: null });
|
|
337
|
+
signal?.throwIfAborted();
|
|
338
|
+
const configuration = await getProjectDeliveryConfiguration({
|
|
339
|
+
graphql: context.clients.graphql,
|
|
340
|
+
org: context.config.native.organization,
|
|
341
|
+
settings: projectSettingsFromDeliveryConfig(context.config),
|
|
342
|
+
requireWritable: false,
|
|
343
|
+
maxPages: pageLimit
|
|
344
|
+
});
|
|
345
|
+
if (routing.projectId !== configuration.projectId || routing.statusFieldId !== configuration.statusFieldId || digestValue(routing.statusOptionIds) !== digestValue(configuration.statusOptionIds) || routing.pointsFieldId !== configuration.pointsFieldId || routing.priorityFieldId !== configuration.priorityFieldId)
|
|
346
|
+
throw new DeliveryError("Project routing changed during collection.");
|
|
347
|
+
signal?.throwIfAborted();
|
|
348
|
+
const items = await readProjectDeliveryItems({
|
|
349
|
+
graphql: context.clients.graphql,
|
|
350
|
+
org: context.config.native.organization,
|
|
351
|
+
configuration,
|
|
352
|
+
maxPages: pageLimit
|
|
353
|
+
});
|
|
354
|
+
signal?.throwIfAborted();
|
|
355
|
+
retain(items);
|
|
356
|
+
cache.set(key, { identity: expected, items });
|
|
357
|
+
return items;
|
|
358
|
+
}
|
|
359
|
+
async function prs(context, repositoryId, result, retain, signal) {
|
|
360
|
+
const ids = /* @__PURE__ */ new Set();
|
|
361
|
+
try {
|
|
362
|
+
for (let page = 1; page <= pageLimit; page++) {
|
|
363
|
+
signal?.throwIfAborted();
|
|
364
|
+
const response = await context.clients.rest.pulls.list({ ...context.repo, state: "open", per_page: 100, page });
|
|
365
|
+
signal?.throwIfAborted();
|
|
366
|
+
for (const value of response.data) {
|
|
367
|
+
const item = row(result.repository, value, "pull");
|
|
368
|
+
if (ids.has(item.id) || value.state !== "open") throw new DeliveryError("PR inventory identity changed.");
|
|
369
|
+
retain(item.id);
|
|
370
|
+
ids.add(item.id);
|
|
371
|
+
try {
|
|
372
|
+
signal?.throwIfAborted();
|
|
373
|
+
const facts = await readPrBoardFacts(context, item.number);
|
|
374
|
+
signal?.throwIfAborted();
|
|
375
|
+
if (facts.repository.id !== repositoryId) throw new DeliveryError("PR repository identity changed.");
|
|
376
|
+
retain(facts);
|
|
377
|
+
(facts.ready ? result.readyPrs : result.blockedPrs).push(facts);
|
|
378
|
+
result.coverage.readyPrs.observed++;
|
|
379
|
+
result.coverage.blockedPrs.observed++;
|
|
380
|
+
if (!facts.stable || !facts.review.observed || !facts.closingLinks.complete || facts.currentBaseSha !== facts.baseSha || facts.mergeable === null || facts.mergeable === "UNKNOWN" || facts.mergeStateStatus === null || facts.mergeStateStatus === "UNKNOWN" || facts.reasons.includes("checks-unproven")) {
|
|
381
|
+
gap(result, retain, "readyPrs", "pr-evidence-unknown");
|
|
382
|
+
gap(result, retain, "blockedPrs", "pr-evidence-unknown");
|
|
383
|
+
}
|
|
384
|
+
} catch (error) {
|
|
385
|
+
signal?.throwIfAborted();
|
|
386
|
+
gap(result, retain, "readyPrs", code(error), item);
|
|
387
|
+
gap(result, retain, "blockedPrs", code(error), item);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (response.data.length < 100 && !response.headers.link?.includes('rel="next"')) return;
|
|
391
|
+
}
|
|
392
|
+
throw new DeliveryError("PR inventory page limit reached.");
|
|
393
|
+
} catch (error) {
|
|
394
|
+
signal?.throwIfAborted();
|
|
395
|
+
gap(result, retain, "readyPrs", code(error));
|
|
396
|
+
gap(result, retain, "blockedPrs", code(error));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
async function usage(context, repositoryId, repository, kind, asOf, retain, signal) {
|
|
400
|
+
const result = metric(), ids = /* @__PURE__ */ new Set(), cursors = /* @__PURE__ */ new Set();
|
|
401
|
+
const from = asOf - 7 * day, qualifier = kind === "opened" ? "created" : "merged";
|
|
402
|
+
const query = `repo:${repository} is:pr ${qualifier}:>=${new Date(Math.floor(from / 1e3) * 1e3).toISOString()} ${qualifier}:<${new Date(Math.ceil(asOf / 1e3) * 1e3).toISOString()}`;
|
|
403
|
+
let cursor = null, retained = 0, count = null;
|
|
404
|
+
try {
|
|
405
|
+
for (let page = 0; page < pageLimit; page++) {
|
|
406
|
+
signal?.throwIfAborted();
|
|
407
|
+
const response = await context.clients.graphql(
|
|
408
|
+
`query DeliveryBoardSearch($q: String!, $cursor: String) {
|
|
409
|
+
search(query: $q, type: ISSUE, first: 100, after: $cursor) { issueCount nodes {
|
|
410
|
+
__typename ... on PullRequest { id number url repository { id nameWithOwner } createdAt mergedAt body mergeCommit { oid message } }
|
|
411
|
+
} pageInfo { hasNextPage endCursor } }
|
|
412
|
+
}`,
|
|
413
|
+
{ q: query, cursor }
|
|
414
|
+
);
|
|
415
|
+
signal?.throwIfAborted();
|
|
416
|
+
const search = record(record(response).search);
|
|
417
|
+
if (typeof search.issueCount !== "number" || !Number.isSafeInteger(search.issueCount) || search.issueCount < 0 || search.issueCount > 1e3)
|
|
418
|
+
throw new DeliveryError("Search count is incomplete or exceeds the native ceiling.");
|
|
419
|
+
if (count !== null && count !== search.issueCount) throw new DeliveryError("Search count changed.");
|
|
420
|
+
count = search.issueCount;
|
|
421
|
+
for (const raw of array(search.nodes)) {
|
|
422
|
+
const pr = record(raw), parent = record(pr.repository);
|
|
423
|
+
retained += Buffer.byteLength(JSON.stringify(pr));
|
|
424
|
+
if (retained > retainedLimit) throw retainedDataLimit;
|
|
425
|
+
const id = text(pr.id);
|
|
426
|
+
if (pr.__typename !== "PullRequest" || parent.id !== repositoryId || text(parent.nameWithOwner).toLowerCase() !== repository || text(pr.url).toLowerCase() !== `https://github.com/${repository}/pull/${number(pr.number)}`)
|
|
427
|
+
throw new DeliveryError("Search PR identity is incomplete.");
|
|
428
|
+
if (ids.has(id)) {
|
|
429
|
+
result.complete = false;
|
|
430
|
+
if (!result.reasons.includes("duplicate-search-id")) result.reasons.push("duplicate-search-id");
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
retain(id);
|
|
434
|
+
ids.add(id);
|
|
435
|
+
const event = timestamp(kind === "opened" ? pr.createdAt : pr.mergedAt);
|
|
436
|
+
if (event < from || event >= asOf) continue;
|
|
437
|
+
result.total++;
|
|
438
|
+
if (kind === "opened") {
|
|
439
|
+
if (typeof pr.body !== "string") {
|
|
440
|
+
result.unknown++;
|
|
441
|
+
result.complete = false;
|
|
442
|
+
} else if (hasDeliveryPrMarker(pr.body)) result.marked++;
|
|
443
|
+
} else {
|
|
444
|
+
const commit = pr.mergeCommit;
|
|
445
|
+
if (typeof commit !== "object" || commit === null || !/^[a-f0-9]{40}$/u.test(String(Reflect.get(commit, "oid"))) || typeof Reflect.get(commit, "message") !== "string") {
|
|
446
|
+
result.unknown++;
|
|
447
|
+
result.complete = false;
|
|
448
|
+
} else if (hasDeliveryMergeTrailer(Reflect.get(commit, "message"))) result.marked++;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const info = record(search.pageInfo);
|
|
452
|
+
if (info.hasNextPage === false) {
|
|
453
|
+
if (ids.size !== count) {
|
|
454
|
+
result.complete = false;
|
|
455
|
+
result.reasons.push("search-count-mismatch");
|
|
456
|
+
}
|
|
457
|
+
if (result.unknown) result.reasons.push("marker-source-unknown");
|
|
458
|
+
result.percentage = result.complete && result.total > 0 ? 100 * result.marked / result.total : null;
|
|
459
|
+
return result;
|
|
460
|
+
}
|
|
461
|
+
if (info.hasNextPage !== true) throw new DeliveryError("Search pagination is incomplete.");
|
|
462
|
+
cursor = text(info.endCursor);
|
|
463
|
+
if (cursors.has(cursor)) throw new DeliveryError("Search cursor repeated.");
|
|
464
|
+
cursors.add(cursor);
|
|
465
|
+
}
|
|
466
|
+
throw new DeliveryError("Search page limit reached.");
|
|
467
|
+
} catch (error) {
|
|
468
|
+
signal?.throwIfAborted();
|
|
469
|
+
result.complete = false;
|
|
470
|
+
result.percentage = null;
|
|
471
|
+
result.reasons.push(code(error));
|
|
472
|
+
return result;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
async function collectDeliveryBoard(raw, execution) {
|
|
476
|
+
const request = parseDeliveryBoardRequest(raw), signal = execution.signal;
|
|
477
|
+
if (execution.repo !== void 0 && (request.repos.length !== 1 || request.repos[0] !== execution.repo.trim().toLowerCase()))
|
|
478
|
+
throw new DeliveryError("Board and execution repo selectors disagree.");
|
|
479
|
+
signal?.throwIfAborted();
|
|
480
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString(), asOf = Date.parse(startedAt);
|
|
481
|
+
let retained = Buffer.byteLength(JSON.stringify(request.repos.map(emptyRepository))) + request.repos.length * 4096;
|
|
482
|
+
if (retained > retainedLimit) throw new DeliveryError("Board selectors exceed the retained-data bound.");
|
|
483
|
+
const retain = (projection) => {
|
|
484
|
+
const bytes = Buffer.byteLength(JSON.stringify(projection)) + 4;
|
|
485
|
+
if (retained + bytes > retainedLimit) throw retainedDataLimit;
|
|
486
|
+
retained += bytes;
|
|
487
|
+
};
|
|
488
|
+
const settings = execution.settings ?? await loadDeliverySettings();
|
|
489
|
+
signal?.throwIfAborted();
|
|
490
|
+
const identity = execution.identity ?? settings.roles.author.identity;
|
|
491
|
+
const policy = evaluateCommandIdentityPolicy({
|
|
492
|
+
commandName: "board:reconcile",
|
|
493
|
+
deliveryConfig: settings,
|
|
494
|
+
identity,
|
|
495
|
+
...execution.personalAuth === void 0 ? {} : { personalAuth: execution.personalAuth }
|
|
496
|
+
});
|
|
497
|
+
if (policy.error) throw new DeliveryError(policy.error);
|
|
498
|
+
const clients = await createDeliveryGitHubClients({
|
|
499
|
+
config: settings,
|
|
500
|
+
identity,
|
|
501
|
+
role: "author",
|
|
502
|
+
...settings.environment === void 0 ? {} : { env: settings.environment },
|
|
503
|
+
...execution.personalAuth === true ? { personalAuth: { enabled: true } } : {},
|
|
504
|
+
...signal === void 0 ? {} : { signal }
|
|
505
|
+
});
|
|
506
|
+
const projects = /* @__PURE__ */ new Map(), repositories = [];
|
|
507
|
+
let principal = null;
|
|
508
|
+
try {
|
|
509
|
+
principal = await principalIdentity(clients, signal);
|
|
510
|
+
} catch {
|
|
511
|
+
signal?.throwIfAborted();
|
|
512
|
+
}
|
|
513
|
+
for (const repository of request.repos) {
|
|
514
|
+
signal?.throwIfAborted();
|
|
515
|
+
const result = emptyRepository(repository);
|
|
516
|
+
repositories.push(result);
|
|
517
|
+
const [owner, name] = repository.split("/"), readContext = { clients, repo: { owner, repo: name } };
|
|
518
|
+
let repositoryId;
|
|
519
|
+
try {
|
|
520
|
+
const native = (await clients.rest.repos.get(readContext.repo)).data;
|
|
521
|
+
signal?.throwIfAborted();
|
|
522
|
+
repositoryId = text(native.node_id);
|
|
523
|
+
if (text(native.full_name).toLowerCase() !== repository) throw new DeliveryError("Repository identity changed.");
|
|
524
|
+
result.access = "readable";
|
|
525
|
+
} catch (error) {
|
|
526
|
+
signal?.throwIfAborted();
|
|
527
|
+
result.access = "unreadable";
|
|
528
|
+
for (const section of Object.keys(result.coverage))
|
|
529
|
+
gap(result, retain, section, code(error), void 0, true);
|
|
530
|
+
for (const at of Object.values(result.metrics)) {
|
|
531
|
+
at.complete = false;
|
|
532
|
+
at.reasons.push(code(error));
|
|
533
|
+
}
|
|
534
|
+
result.diagnostics.push({ scope: "repository", code: code(error) });
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
const nativeIssues = await issues(readContext, result, retain, signal);
|
|
538
|
+
for (const issue of nativeIssues) {
|
|
539
|
+
signal?.throwIfAborted();
|
|
540
|
+
const labels = issue.labels.filter(
|
|
541
|
+
(label) => request.decisionLabels.some((selected) => selected.toLowerCase() === label.toLowerCase())
|
|
542
|
+
);
|
|
543
|
+
let journal;
|
|
544
|
+
try {
|
|
545
|
+
journal = await attention(readContext, repositoryId, issue, retain, signal);
|
|
546
|
+
if (journal.state === "unknown") gap(result, retain, "humanAttention", "journal-ambiguous", issue.row);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
signal?.throwIfAborted();
|
|
549
|
+
journal = { kind: null, state: "unknown", request: null, reason: code(error), commentId: null, url: null };
|
|
550
|
+
gap(result, retain, "humanAttention", code(error), issue.row);
|
|
551
|
+
}
|
|
552
|
+
result.coverage.humanAttention.observed++;
|
|
553
|
+
if (labels.length || journal.state === "pending") {
|
|
554
|
+
const item = resultRow(result, retain, "humanAttention", {
|
|
555
|
+
...issue.row,
|
|
556
|
+
labels,
|
|
557
|
+
journal,
|
|
558
|
+
request: journal.request,
|
|
559
|
+
reasons: [
|
|
560
|
+
...labels.length ? ["decision-label"] : [],
|
|
561
|
+
...journal.state === "pending" ? ["journal-request"] : []
|
|
562
|
+
]
|
|
563
|
+
});
|
|
564
|
+
if (item) result.humanAttention.push(item);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
await prs(readContext, repositoryId, result, retain, signal);
|
|
568
|
+
let context = null;
|
|
569
|
+
try {
|
|
570
|
+
signal?.throwIfAborted();
|
|
571
|
+
const candidate = await loadDeliveryContext({
|
|
572
|
+
settings,
|
|
573
|
+
identity,
|
|
574
|
+
role: "author",
|
|
575
|
+
repoRoot: execution.repoRoot,
|
|
576
|
+
repository,
|
|
577
|
+
readPageLimit: pageLimit,
|
|
578
|
+
requireWritableProject: false,
|
|
579
|
+
...settings.environment === void 0 ? {} : { env: settings.environment },
|
|
580
|
+
...execution.personalAuth === void 0 ? {} : { personalAuth: execution.personalAuth },
|
|
581
|
+
...signal === void 0 ? {} : { signal }
|
|
582
|
+
});
|
|
583
|
+
signal?.throwIfAborted();
|
|
584
|
+
if (candidate.config.repository.toLowerCase() !== repository || `${candidate.repo.owner}/${candidate.repo.repo}`.toLowerCase() !== repository || candidate.clients.role !== "author" || candidate.configuration?.routing.repositoryId !== repositoryId || principal === null || await principalIdentity(candidate.clients, signal) !== principal)
|
|
585
|
+
throw new DeliveryError("Configured context identity changed.");
|
|
586
|
+
context = candidate;
|
|
587
|
+
const items = await projectItems(context, projects, principal, retain, signal);
|
|
588
|
+
const index = /* @__PURE__ */ new Map();
|
|
589
|
+
for (const item of items) {
|
|
590
|
+
if (item.archived || item.contentKind !== "issue" || item.repository?.toLowerCase() !== repository) continue;
|
|
591
|
+
const key = `${item.contentId}:${item.issueNumber}`;
|
|
592
|
+
index.set(key, [...index.get(key) ?? [], item]);
|
|
593
|
+
}
|
|
594
|
+
for (const issue of nativeIssues) {
|
|
595
|
+
const matches = index.get(`${issue.row.id}:${issue.row.number}`), item = matches?.[0];
|
|
596
|
+
if (matches?.length !== 1 || !item || item.statusRead !== "verified" || item.status === null)
|
|
597
|
+
gap(result, retain, "staleIssues", "project-status-unknown", issue.row);
|
|
598
|
+
else {
|
|
599
|
+
result.coverage.staleIssues.observed++;
|
|
600
|
+
if (item.status === "In Progress" && issue.updatedAt <= asOf - 3 * day) {
|
|
601
|
+
const stale = resultRow(result, retain, "staleIssues", {
|
|
602
|
+
...issue.row,
|
|
603
|
+
state: item.status,
|
|
604
|
+
reasons: ["stale-72h"]
|
|
605
|
+
});
|
|
606
|
+
if (stale) result.staleIssues.push(stale);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
} catch (error) {
|
|
611
|
+
signal?.throwIfAborted();
|
|
612
|
+
gap(result, retain, "staleIssues", code(error), void 0, true);
|
|
613
|
+
for (const issue of nativeIssues) gap(result, retain, "staleIssues", code(error), issue.row, true);
|
|
614
|
+
result.diagnostics.push({ scope: "project", code: code(error) });
|
|
615
|
+
}
|
|
616
|
+
result.metrics.opened = await usage(readContext, repositoryId, repository, "opened", asOf, retain, signal);
|
|
617
|
+
result.metrics.merged = await usage(readContext, repositoryId, repository, "merged", asOf, retain, signal);
|
|
618
|
+
for (const rows of [result.humanAttention, result.readyPrs, result.blockedPrs, result.staleIssues])
|
|
619
|
+
rows.sort((a, b) => a.number - b.number);
|
|
620
|
+
}
|
|
621
|
+
signal?.throwIfAborted();
|
|
622
|
+
return {
|
|
623
|
+
schemaVersion: "ai-delivery.board@1",
|
|
624
|
+
collection: { startedAt, completedAt: (/* @__PURE__ */ new Date()).toISOString(), asOf: startedAt },
|
|
625
|
+
complete: repositories.every(
|
|
626
|
+
(result) => result.access === "readable" && Object.values(result.coverage).every((at) => at.status === "complete") && Object.values(result.metrics).every((at) => at.complete)
|
|
627
|
+
),
|
|
628
|
+
repositories
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
async function principalIdentity(clients, signal) {
|
|
632
|
+
signal?.throwIfAborted();
|
|
633
|
+
if (clients.role !== "author" || !clients.authenticatedAuthor)
|
|
634
|
+
throw new DeliveryError("Selected author identity is unavailable.");
|
|
635
|
+
const actor = await clients.authenticatedAuthor(signal);
|
|
636
|
+
signal?.throwIfAborted();
|
|
637
|
+
return digestValue({ actor: text(actor.actorLogin).toLowerCase(), credential: text(actor.credentialIdentity) });
|
|
638
|
+
}
|
|
639
|
+
export {
|
|
640
|
+
collectDeliveryBoard,
|
|
641
|
+
parseDeliveryBoardRequest,
|
|
642
|
+
renderDeliveryBoard
|
|
643
|
+
};
|
|
644
|
+
//# sourceMappingURL=deliveryBoard.js.map
|