@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
|
@@ -1,413 +1,495 @@
|
|
|
1
|
-
import { lstatSync, readFileSync, realpathSync } from
|
|
2
|
-
import { homedir } from
|
|
3
|
-
import { isAbsolute, join, relative } from
|
|
4
|
-
import { z } from
|
|
5
|
-
import { git } from
|
|
6
|
-
import { DeliveryError } from
|
|
7
|
-
import { digestValue } from
|
|
8
|
-
import { createDeliveryGitHubClients, retainMachineAuthorForConfiguration } from
|
|
9
|
-
import { resolveRepoFromRemote } from
|
|
10
|
-
import { discoverDeliveryRouting } from
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { git } from "../git.js";
|
|
6
|
+
import { DeliveryError } from "../errors.js";
|
|
7
|
+
import { digestValue } from "../delivery/common.js";
|
|
8
|
+
import { createDeliveryGitHubClients, retainMachineAuthorForConfiguration } from "../github/client.js";
|
|
9
|
+
import { resolveRepoFromRemote } from "../github/repo.js";
|
|
10
|
+
import { discoverDeliveryRouting } from "../github/discovery.js";
|
|
11
|
+
import { MACHINE_AUTH_ENV_NAMES } from "../github/machineAuth.js";
|
|
12
|
+
const DELIVERY_CONFIG_FILE = "ai-delivery.config.json";
|
|
13
|
+
const DELIVERY_POLICY_CONTRACT = "RepositoryDeliveryPolicy@1";
|
|
14
|
+
function configurationIssueMessages(issues, root, prefix = []) {
|
|
15
|
+
return issues.flatMap((issue) => {
|
|
16
|
+
const path = [...prefix, ...issue.path];
|
|
17
|
+
return issue.code === "invalid_union" ? issue.errors.flatMap((branch) => configurationIssueMessages(branch, root, path)) : [`${path.join(".") || root}: ${issue.message}`];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
13
20
|
const Name = z.string().trim().min(1);
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
const WipLimits = z.array(
|
|
22
|
+
z.strictObject({
|
|
16
23
|
repository: z.string().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u),
|
|
17
24
|
name: Name,
|
|
18
25
|
match: z.union([
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
z.strictObject({ label: Name }),
|
|
27
|
+
z.strictObject({ field: Name, value: z.union([z.string().min(1), z.number().finite()]) })
|
|
21
28
|
]),
|
|
22
|
-
limit: z.number().int().nonnegative().safe()
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
limit: z.number().int().nonnegative().safe()
|
|
30
|
+
})
|
|
31
|
+
).superRefine((lanes, context) => {
|
|
32
|
+
const identities = lanes.map((lane) => JSON.stringify([lane.repository.toLowerCase(), lane.name]));
|
|
33
|
+
if (new Set(identities).size !== identities.length)
|
|
34
|
+
context.addIssue({ code: "custom", message: "WIP lane names must be unique within each repository." });
|
|
28
35
|
});
|
|
29
36
|
const EnvName = z.string().regex(/^[A-Z][A-Z0-9_]*$/u);
|
|
30
37
|
const PositiveInteger = z.number().int().positive();
|
|
31
|
-
const NativeFieldId = z
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
.array(Name)
|
|
37
|
-
.min(1)
|
|
38
|
-
.superRefine((values, context) => {
|
|
39
|
-
if (new Set(values).size !== values.length) {
|
|
40
|
-
context.addIssue({ code: 'custom', message: 'Values must be unique.' });
|
|
41
|
-
}
|
|
38
|
+
const NativeFieldId = z.string().regex(/^[1-9]\d*$/u).refine((value) => Number.isSafeInteger(Number(value)));
|
|
39
|
+
const UniqueNames = z.array(Name).min(1).superRefine((values, context) => {
|
|
40
|
+
if (new Set(values).size !== values.length) {
|
|
41
|
+
context.addIssue({ code: "custom", message: "Values must be unique." });
|
|
42
|
+
}
|
|
42
43
|
});
|
|
43
|
-
const NativeField = z
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
|
|
44
|
+
const NativeField = z.object({
|
|
45
|
+
databaseId: NativeFieldId,
|
|
46
|
+
name: Name,
|
|
47
|
+
values: UniqueNames
|
|
48
|
+
}).strict();
|
|
49
|
+
const LegacyAppRole = z.object({
|
|
50
|
+
authSource: z.literal("app").optional(),
|
|
51
|
+
credentialEnv: z.object({
|
|
52
|
+
appId: EnvName,
|
|
53
|
+
installationId: EnvName,
|
|
54
|
+
privateKeyPath: EnvName
|
|
55
|
+
}).strict(),
|
|
56
|
+
identity: Name
|
|
57
|
+
}).strict();
|
|
58
|
+
const ReviewProvider = z.enum(["openai", "anthropic", "google", "qwen"]);
|
|
59
|
+
const Encoding = z.enum(["pem", "base64"]).optional();
|
|
60
|
+
const CredentialSource = z.union([
|
|
61
|
+
z.strictObject({ type: z.literal("env"), variable: EnvName.optional(), encoding: Encoding }),
|
|
62
|
+
z.strictObject({ type: z.literal("file"), path: Name.refine(isAbsolute, "Key path must be absolute.") }),
|
|
63
|
+
z.strictObject({
|
|
64
|
+
type: z.literal("command"),
|
|
65
|
+
argv: z.array(z.string().max(4096)).min(1).max(64).refine(
|
|
66
|
+
(argv) => isAbsolute(argv[0]) && argv.every((part) => !part.includes("\0")),
|
|
67
|
+
"Command requires an absolute executable and literal argv without NUL."
|
|
68
|
+
),
|
|
69
|
+
encoding: Encoding,
|
|
70
|
+
env: z.array(EnvName).max(32).optional()
|
|
71
|
+
})
|
|
72
|
+
]);
|
|
73
|
+
const ConfiguredAppRole = z.strictObject({
|
|
74
|
+
authSource: z.literal("app"),
|
|
75
|
+
identity: z.string().regex(/^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u),
|
|
76
|
+
appId: PositiveInteger.safe(),
|
|
77
|
+
installationId: PositiveInteger.safe(),
|
|
78
|
+
actorLogin: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9-]{0,99}\[bot\]$/u),
|
|
79
|
+
provider: ReviewProvider,
|
|
80
|
+
credentialSource: CredentialSource.optional()
|
|
81
|
+
});
|
|
82
|
+
const AppRole = z.union([LegacyAppRole, ConfiguredAppRole]);
|
|
83
|
+
function appCredentialSource(role) {
|
|
84
|
+
return role.credentialSource ?? { type: "env" };
|
|
85
|
+
}
|
|
86
|
+
function privateKeyVariable(role) {
|
|
87
|
+
const source = appCredentialSource(role);
|
|
88
|
+
return source.type === "env" && source.variable !== void 0 ? source.variable : `GH_PRIVATE_KEY_${role.identity.toUpperCase().replace(/[^A-Z0-9]/gu, "_")}`;
|
|
89
|
+
}
|
|
90
|
+
function credentialReferenceNames(role) {
|
|
91
|
+
if ("credentialEnv" in role) return Object.values(role.credentialEnv);
|
|
92
|
+
const source = appCredentialSource(role);
|
|
93
|
+
return source.type === "env" ? [privateKeyVariable(role)] : source.type === "command" ? source.env ?? [] : [];
|
|
94
|
+
}
|
|
63
95
|
const AuthorRole = z.union([
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
})
|
|
71
|
-
.strict(),
|
|
96
|
+
AppRole,
|
|
97
|
+
z.object({
|
|
98
|
+
authSource: z.literal("personal"),
|
|
99
|
+
credentialEnv: z.object({ token: EnvName }).strict(),
|
|
100
|
+
identity: Name
|
|
101
|
+
}).strict()
|
|
72
102
|
]);
|
|
73
|
-
const DeliveryConfigSchema = z
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (value.native.points.values.some((point) => !/^[1-9]\d*$/u.test(point) || !Number.isSafeInteger(Number(point)))) {
|
|
176
|
-
context.addIssue({
|
|
177
|
-
code: 'custom',
|
|
178
|
-
message: 'Point values must be positive safe integers.',
|
|
179
|
-
path: ['native', 'points', 'values'],
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
if (value.native.points.name === value.native.priority.name) {
|
|
183
|
-
context.addIssue({ code: 'custom', message: 'Points and priority fields must be distinct.', path: ['native'] });
|
|
184
|
-
}
|
|
185
|
-
if (value.native.points.databaseId === value.native.priority.databaseId) {
|
|
186
|
-
context.addIssue({
|
|
187
|
-
code: 'custom',
|
|
188
|
-
message: 'Points and priority field IDs must be distinct.',
|
|
189
|
-
path: ['native'],
|
|
190
|
-
});
|
|
191
|
-
}
|
|
103
|
+
const DeliveryConfigSchema = z.object({
|
|
104
|
+
wipLimits: WipLimits.optional(),
|
|
105
|
+
commandPolicy: z.object({
|
|
106
|
+
checks: z.object({
|
|
107
|
+
format: z.enum(["REQUIRED", "OPTIONAL", "SKIP"]),
|
|
108
|
+
gitClean: z.enum(["REQUIRED", "OPTIONAL", "SKIP"]),
|
|
109
|
+
lint: z.enum(["REQUIRED", "OPTIONAL", "SKIP"]),
|
|
110
|
+
test: z.enum(["REQUIRED", "OPTIONAL", "SKIP"]),
|
|
111
|
+
typecheck: z.enum(["REQUIRED", "OPTIONAL", "SKIP"])
|
|
112
|
+
}).strict(),
|
|
113
|
+
timeoutsMs: z.object({
|
|
114
|
+
lint: PositiveInteger,
|
|
115
|
+
test: PositiveInteger,
|
|
116
|
+
typecheck: PositiveInteger
|
|
117
|
+
}).strict()
|
|
118
|
+
}).strict(),
|
|
119
|
+
native: z.object({
|
|
120
|
+
issueTypes: UniqueNames,
|
|
121
|
+
milestones: z.literal("repository"),
|
|
122
|
+
organization: Name,
|
|
123
|
+
points: NativeField,
|
|
124
|
+
priority: NativeField,
|
|
125
|
+
project: z.object({
|
|
126
|
+
number: PositiveInteger,
|
|
127
|
+
statuses: z.object({
|
|
128
|
+
blocked: Name,
|
|
129
|
+
done: Name,
|
|
130
|
+
inProgress: Name,
|
|
131
|
+
todo: Name
|
|
132
|
+
}).strict(),
|
|
133
|
+
statusField: Name,
|
|
134
|
+
title: Name
|
|
135
|
+
}).strict(),
|
|
136
|
+
relationships: z.object({
|
|
137
|
+
blockedBy: z.literal("native"),
|
|
138
|
+
parent: z.literal("native")
|
|
139
|
+
}).strict()
|
|
140
|
+
}).strict(),
|
|
141
|
+
policy: z.object({
|
|
142
|
+
contract: z.enum([DELIVERY_POLICY_CONTRACT, "RepositoryDeliveryPolicy@2"]),
|
|
143
|
+
module: z.string().regex(/^\.\/(?!.*(?:^|\/)\.\.(?:\/|$))[^\s]+\.(?:mjs|js)$/u)
|
|
144
|
+
}).strict(),
|
|
145
|
+
repository: z.string().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u),
|
|
146
|
+
roles: z.object({ author: AuthorRole, reviewer: AppRole }).strict(),
|
|
147
|
+
schemaVersion: z.literal("ai-delivery.config@2")
|
|
148
|
+
}).strict().superRefine((value, context) => {
|
|
149
|
+
if (value.repository.split("/")[0]?.toLowerCase() !== value.native.organization.toLowerCase()) {
|
|
150
|
+
context.addIssue({
|
|
151
|
+
code: "custom",
|
|
152
|
+
message: "Organization must match repository owner.",
|
|
153
|
+
path: ["native", "organization"]
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (value.roles.author.identity.toLowerCase() === value.roles.reviewer.identity.toLowerCase()) {
|
|
157
|
+
context.addIssue({
|
|
158
|
+
code: "custom",
|
|
159
|
+
message: "Author and reviewer identities must be distinct.",
|
|
160
|
+
path: ["roles"]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if ([value.roles.author, value.roles.reviewer].some(
|
|
164
|
+
(role) => role.authSource !== "personal" && /^personal(?:$|[-_])/iu.test(role.identity)
|
|
165
|
+
)) {
|
|
166
|
+
context.addIssue({
|
|
167
|
+
code: "custom",
|
|
168
|
+
message: "App role identities cannot be personal identities.",
|
|
169
|
+
path: ["roles"]
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const authorEnv = credentialReferenceNames(value.roles.author);
|
|
173
|
+
const reviewerEnv = credentialReferenceNames(value.roles.reviewer);
|
|
174
|
+
if ((/* @__PURE__ */ new Set([...authorEnv, ...reviewerEnv])).size !== authorEnv.length + reviewerEnv.length) {
|
|
175
|
+
context.addIssue({
|
|
176
|
+
code: "custom",
|
|
177
|
+
message: "Author and reviewer credential environment names must be distinct.",
|
|
178
|
+
path: ["roles"]
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (new Set(Object.values(value.native.project.statuses)).size !== 4) {
|
|
182
|
+
context.addIssue({
|
|
183
|
+
code: "custom",
|
|
184
|
+
message: "Project statuses must be distinct.",
|
|
185
|
+
path: ["native", "project", "statuses"]
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (value.native.points.values.some((point) => !/^[1-9]\d*$/u.test(point) || !Number.isSafeInteger(Number(point)))) {
|
|
189
|
+
context.addIssue({
|
|
190
|
+
code: "custom",
|
|
191
|
+
message: "Point values must be positive safe integers.",
|
|
192
|
+
path: ["native", "points", "values"]
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (value.native.points.name === value.native.priority.name) {
|
|
196
|
+
context.addIssue({ code: "custom", message: "Points and priority fields must be distinct.", path: ["native"] });
|
|
197
|
+
}
|
|
198
|
+
if (value.native.points.databaseId === value.native.priority.databaseId) {
|
|
199
|
+
context.addIssue({
|
|
200
|
+
code: "custom",
|
|
201
|
+
message: "Points and priority field IDs must be distinct.",
|
|
202
|
+
path: ["native"]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
192
205
|
});
|
|
193
|
-
|
|
206
|
+
const NativeDeliveryConfigSchema = DeliveryConfigSchema.shape.native;
|
|
194
207
|
const ModulePath = z.string().regex(/^\.\/(?!.*(?:^|\/)\.\.(?:\/|$))[^\s]+\.(?:mjs|js)$/u);
|
|
195
|
-
const OverridesSchema = z
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
208
|
+
const OverridesSchema = z.object({
|
|
209
|
+
schemaVersion: z.literal("ai-delivery.config@2").optional(),
|
|
210
|
+
repository: z.string().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u).optional(),
|
|
211
|
+
remote: Name.optional(),
|
|
212
|
+
policy: z.object({ module: ModulePath }).strict().optional(),
|
|
213
|
+
project: PositiveInteger.optional(),
|
|
214
|
+
pointsField: Name.optional(),
|
|
215
|
+
priorityField: Name.optional(),
|
|
216
|
+
statusField: Name.optional(),
|
|
217
|
+
statuses: z.object({ blocked: Name, done: Name, inProgress: Name, todo: Name }).strict().optional(),
|
|
218
|
+
issueTypes: UniqueNames.optional()
|
|
219
|
+
}).strict();
|
|
220
|
+
const UserSettingsSchema = z.strictObject({
|
|
221
|
+
wipLimits: WipLimits.optional(),
|
|
222
|
+
schemaVersion: z.literal("ai-delivery.user@1"),
|
|
223
|
+
roles: z.strictObject({
|
|
224
|
+
author: AuthorRole,
|
|
225
|
+
reviewer: AppRole
|
|
226
|
+
}),
|
|
227
|
+
reviewerProfiles: z.record(z.string().regex(/^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u), ConfiguredAppRole).optional(),
|
|
228
|
+
project: PositiveInteger,
|
|
229
|
+
checkoutRoots: z.array(z.string().min(1).refine(isAbsolute, "Checkout roots must be absolute.")),
|
|
230
|
+
pointsField: Name.optional(),
|
|
231
|
+
priorityField: Name.optional(),
|
|
232
|
+
statusField: Name.optional(),
|
|
233
|
+
statuses: OverridesSchema.shape.statuses,
|
|
234
|
+
issueTypes: UniqueNames.optional()
|
|
235
|
+
}).superRefine((value, context) => {
|
|
236
|
+
const roles = value.roles;
|
|
237
|
+
if (roles.author.identity.toLowerCase() === roles.reviewer.identity.toLowerCase())
|
|
238
|
+
context.addIssue({
|
|
239
|
+
code: "custom",
|
|
240
|
+
path: ["roles"],
|
|
241
|
+
message: "Author and reviewer identities must be distinct."
|
|
242
|
+
});
|
|
243
|
+
if ([roles.author, roles.reviewer].some(
|
|
244
|
+
(role) => role.authSource !== "personal" && /^personal(?:$|[-_])/iu.test(role.identity)
|
|
245
|
+
))
|
|
246
|
+
context.addIssue({
|
|
247
|
+
code: "custom",
|
|
248
|
+
path: ["roles"],
|
|
249
|
+
message: "App role identities cannot be personal identities."
|
|
250
|
+
});
|
|
251
|
+
if (value.statuses && new Set(Object.values(value.statuses)).size !== 4)
|
|
252
|
+
context.addIssue({ code: "custom", path: ["statuses"], message: "Project statuses must be distinct." });
|
|
253
|
+
const profiles = [roles.reviewer, ...Object.values(value.reviewerProfiles ?? {})];
|
|
254
|
+
if (new Set(profiles.map((profile) => profile.identity.toLowerCase())).size !== profiles.length)
|
|
255
|
+
context.addIssue({
|
|
256
|
+
code: "custom",
|
|
257
|
+
path: ["reviewerProfiles"],
|
|
258
|
+
message: "Reviewer profile identities must be distinct; ambiguous selection is refused."
|
|
259
|
+
});
|
|
260
|
+
for (const [name, profile] of Object.entries(value.reviewerProfiles ?? {})) {
|
|
261
|
+
if (name !== profile.identity || profile.identity.toLowerCase() === roles.author.identity.toLowerCase() || /^personal(?:$|[-_])/iu.test(profile.identity))
|
|
262
|
+
context.addIssue({
|
|
263
|
+
code: "custom",
|
|
264
|
+
path: ["reviewerProfiles", name],
|
|
265
|
+
message: "Profile key must equal its distinct reviewer identity."
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
for (const profile of profiles) {
|
|
269
|
+
const names = [...credentialReferenceNames(roles.author), ...credentialReferenceNames(profile)];
|
|
245
270
|
if (new Set(names).size !== names.length)
|
|
246
|
-
|
|
271
|
+
context.addIssue({
|
|
272
|
+
code: "custom",
|
|
273
|
+
path: ["roles"],
|
|
274
|
+
message: "Credential environment names must be distinct."
|
|
275
|
+
});
|
|
276
|
+
}
|
|
247
277
|
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
throw new DeliveryError(`Invalid ${DELIVERY_CONFIG_FILE}; expected optional ai-delivery.config@2 routing overrides. Migrate authentication and command settings to the policy module's deliverySettings export.`);
|
|
275
|
-
}
|
|
278
|
+
function readDeliveryOverrides(repositoryRoot) {
|
|
279
|
+
const root = realpathSync(repositoryRoot);
|
|
280
|
+
const path = join(root, DELIVERY_CONFIG_FILE);
|
|
281
|
+
try {
|
|
282
|
+
lstatSync(path);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (error.code === "ENOENT")
|
|
285
|
+
return { overrides: {}, bytes: Buffer.alloc(0), path: null };
|
|
286
|
+
throw new DeliveryError(`Unable to read ${DELIVERY_CONFIG_FILE}.`);
|
|
287
|
+
}
|
|
288
|
+
if (!isWithin(root, realpathSync(path)))
|
|
289
|
+
throw new DeliveryError(`${DELIVERY_CONFIG_FILE} must stay within the repository root.`);
|
|
290
|
+
try {
|
|
291
|
+
git(root, "ls-files", "--error-unmatch", "--", DELIVERY_CONFIG_FILE);
|
|
292
|
+
} catch {
|
|
293
|
+
throw new DeliveryError(`${DELIVERY_CONFIG_FILE} must be source-controlled for historical parsing.`);
|
|
294
|
+
}
|
|
295
|
+
const bytes = readFileSync(path);
|
|
296
|
+
try {
|
|
297
|
+
const raw = JSON.parse(bytes.toString("utf8"));
|
|
298
|
+
return { overrides: OverridesSchema.parse(raw), bytes, path };
|
|
299
|
+
} catch {
|
|
300
|
+
throw new DeliveryError(
|
|
301
|
+
`Invalid ${DELIVERY_CONFIG_FILE}; expected optional ai-delivery.config@2 routing overrides. Migrate authentication and command settings to the policy module's deliverySettings export.`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
276
304
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
305
|
+
async function loadDeliverySettings(_repositoryRoot, options = {}) {
|
|
306
|
+
const inherited = options.env ?? process.env;
|
|
307
|
+
const path = inherited.AI_DELIVERY_CONFIG ?? join(homedir(), ".config", "aviaratech-ai", "ai-delivery.json");
|
|
308
|
+
if (!isAbsolute(path)) throw new DeliveryError("AI_DELIVERY_CONFIG must be an absolute user configuration path.");
|
|
309
|
+
let bytes;
|
|
310
|
+
try {
|
|
311
|
+
bytes = readFileSync(path);
|
|
312
|
+
} catch {
|
|
313
|
+
throw new DeliveryError(
|
|
314
|
+
`Missing user configuration ${path}; configure roles.author, roles.reviewer, project and checkoutRoots.`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
let raw;
|
|
318
|
+
try {
|
|
319
|
+
raw = JSON.parse(bytes.toString("utf8"));
|
|
320
|
+
} catch {
|
|
321
|
+
throw new DeliveryError(`Invalid user configuration JSON at ${path}.`);
|
|
322
|
+
}
|
|
323
|
+
const result = UserSettingsSchema.safeParse(raw);
|
|
324
|
+
if (!result.success) {
|
|
325
|
+
const details = configurationIssueMessages(result.error.issues, "configuration").join("; ");
|
|
326
|
+
throw new DeliveryError(`Invalid user configuration ${path}: ${details}`);
|
|
327
|
+
}
|
|
328
|
+
const sourceDigest = digestValue(result.data);
|
|
329
|
+
const { roles, reviewerProfiles, checkoutRoots, wipLimits, schemaVersion: _schema, ...overrides } = result.data;
|
|
330
|
+
const credentialKeyReferences = [
|
|
331
|
+
...new Set(
|
|
332
|
+
[roles.author, roles.reviewer, ...Object.values(reviewerProfiles ?? {})].flatMap(
|
|
333
|
+
(role) => "credentialEnv" in role ? role.authSource === "personal" ? [role.credentialEnv.token] : [role.credentialEnv.privateKeyPath] : appCredentialSource(role).type === "env" ? [privateKeyVariable(role)] : []
|
|
334
|
+
)
|
|
335
|
+
)
|
|
336
|
+
];
|
|
337
|
+
if (options.reviewerIdentity !== void 0) {
|
|
338
|
+
const identity = options.reviewerIdentity;
|
|
339
|
+
const selected = identity === roles.reviewer.identity ? roles.reviewer : reviewerProfiles?.[identity];
|
|
340
|
+
if (!selected || !("appId" in selected) || identity === roles.author.identity)
|
|
341
|
+
throw new DeliveryError(
|
|
342
|
+
"identity: Select an explicit configured reviewer profile with provider, App ID and actorLogin."
|
|
343
|
+
);
|
|
344
|
+
roles.reviewer = selected;
|
|
345
|
+
}
|
|
346
|
+
const environment = {};
|
|
347
|
+
if (options.prepareEnvironment) {
|
|
348
|
+
const selectors = [...MACHINE_AUTH_ENV_NAMES, "TMPDIR", "TEMP", "TMP"];
|
|
349
|
+
if (credentialKeyReferences.some((name) => selectors.includes(name)))
|
|
350
|
+
throw new DeliveryError("Credential reference conflicts with an implicit execution selector.");
|
|
351
|
+
const reviewerSource = "appId" in roles.reviewer ? appCredentialSource(roles.reviewer) : void 0;
|
|
352
|
+
if (reviewerSource?.type === "command" && reviewerSource.env?.some((name) => credentialKeyReferences.includes(name)))
|
|
353
|
+
throw new DeliveryError(
|
|
354
|
+
"Selected helper environment cannot include an author or configured private-key reference."
|
|
355
|
+
);
|
|
356
|
+
const names = /* @__PURE__ */ new Set([
|
|
357
|
+
...MACHINE_AUTH_ENV_NAMES,
|
|
358
|
+
"TMPDIR",
|
|
359
|
+
"TEMP",
|
|
360
|
+
"TMP",
|
|
361
|
+
...Object.values(roles).flatMap(credentialReferenceNames)
|
|
362
|
+
]);
|
|
363
|
+
for (const name of names) {
|
|
364
|
+
if (/^(?:NODE_|NPM_|DYLD_|LD_|BASH_|GIT_)/u.test(name) || ["ENV", "BASH_ENV", "SHELLOPTS", "CDPATH"].includes(name))
|
|
365
|
+
throw new DeliveryError("Credential environment reference conflicts with an execution selector.");
|
|
366
|
+
if (inherited[name] !== void 0) environment[name] = inherited[name];
|
|
302
367
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
368
|
+
environment.AI_DELIVERY_CONFIG = path;
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
credentialKeyReferences,
|
|
372
|
+
...options.prepareEnvironment ? { environment } : {},
|
|
373
|
+
roles,
|
|
374
|
+
checkoutRoots,
|
|
375
|
+
...wipLimits === void 0 ? {} : { wipLimits },
|
|
376
|
+
configPath: path,
|
|
377
|
+
overrides,
|
|
378
|
+
sourceDigest
|
|
379
|
+
};
|
|
312
380
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
configDigest: digestValue({ sourceDigest: settings.sourceDigest, routing, roles: config.roles }),
|
|
367
|
-
configPath: settings.configPath,
|
|
368
|
-
routing,
|
|
369
|
-
};
|
|
381
|
+
async function loadDeliveryConfig(repositoryRoot, options = {}) {
|
|
382
|
+
options.signal?.throwIfAborted();
|
|
383
|
+
const settings = options.settings ?? await loadDeliverySettings();
|
|
384
|
+
const repository = options.repository ?? (() => {
|
|
385
|
+
const coordinates = resolveRepoFromRemote(repositoryRoot, "origin");
|
|
386
|
+
return `${coordinates.owner}/${coordinates.repo}`;
|
|
387
|
+
})();
|
|
388
|
+
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(repository))
|
|
389
|
+
throw new DeliveryError("Repository must be owner/name.");
|
|
390
|
+
const clients = options.clients ?? await createDeliveryGitHubClients({
|
|
391
|
+
config: settings,
|
|
392
|
+
...options.env === void 0 ? {} : { env: options.env },
|
|
393
|
+
identity: options.personalAuth === true && settings.roles.author.authSource !== "personal" ? "personal" : settings.roles.author.identity,
|
|
394
|
+
role: "author",
|
|
395
|
+
...options.personalAuth === true ? { personalAuth: { enabled: true } } : {},
|
|
396
|
+
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
397
|
+
});
|
|
398
|
+
let routing;
|
|
399
|
+
try {
|
|
400
|
+
routing = await discoverDeliveryRouting({
|
|
401
|
+
clients,
|
|
402
|
+
repository,
|
|
403
|
+
overrides: settings.overrides,
|
|
404
|
+
repositorySelected: options.repository !== void 0,
|
|
405
|
+
...options.readPageLimit === void 0 ? {} : { maxPages: options.readPageLimit },
|
|
406
|
+
...options.requireWritableProject === void 0 ? {} : { requireWritableProject: options.requireWritableProject }
|
|
407
|
+
});
|
|
408
|
+
} catch (error) {
|
|
409
|
+
if (error instanceof DeliveryError) throw error;
|
|
410
|
+
if (options.clients === void 0 && settings.roles.author.authSource === "personal" && error.status === 401)
|
|
411
|
+
throw new DeliveryError("Configured personal author token is invalid or expired; refresh the selected token.");
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
const config = {
|
|
415
|
+
...settings.credentialKeyReferences === void 0 ? {} : { credentialKeyReferences: settings.credentialKeyReferences },
|
|
416
|
+
...settings.wipLimits === void 0 ? {} : { wipLimits: settings.wipLimits },
|
|
417
|
+
schemaVersion: "ai-delivery.github@1",
|
|
418
|
+
repository: routing.repository,
|
|
419
|
+
roles: settings.roles,
|
|
420
|
+
native: routing.native
|
|
421
|
+
};
|
|
422
|
+
if (options.clients === void 0)
|
|
423
|
+
retainMachineAuthorForConfiguration(
|
|
424
|
+
config,
|
|
425
|
+
clients,
|
|
426
|
+
options.signal
|
|
427
|
+
);
|
|
428
|
+
return {
|
|
429
|
+
config,
|
|
430
|
+
configDigest: digestValue({ sourceDigest: settings.sourceDigest, routing, roles: config.roles }),
|
|
431
|
+
configPath: settings.configPath,
|
|
432
|
+
routing
|
|
433
|
+
};
|
|
370
434
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
return result.data;
|
|
435
|
+
function parseDeliveryConfig(input) {
|
|
436
|
+
const result = DeliveryConfigSchema.safeParse(input);
|
|
437
|
+
if (!result.success) {
|
|
438
|
+
const details = configurationIssueMessages(result.error.issues, "config").join("; ");
|
|
439
|
+
throw new DeliveryError(`Invalid ${DELIVERY_CONFIG_FILE}: ${details}`);
|
|
440
|
+
}
|
|
441
|
+
return result.data;
|
|
380
442
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
443
|
+
function resolveDeliveryRoleCredentials(input) {
|
|
444
|
+
const { config, role } = input;
|
|
445
|
+
if (config.roles[role].authSource === "personal") {
|
|
446
|
+
throw new DeliveryError("Personal author credentials use the configured token environment variable.");
|
|
447
|
+
}
|
|
448
|
+
const env = input.env ?? process.env;
|
|
449
|
+
const selected = config.roles[role];
|
|
450
|
+
if ("appId" in selected)
|
|
451
|
+
return { appId: String(selected.appId), installationId: selected.installationId, profile: selected };
|
|
452
|
+
const names = selected.credentialEnv;
|
|
453
|
+
const values = {
|
|
454
|
+
appId: env[names.appId]?.trim(),
|
|
455
|
+
installationId: env[names.installationId]?.trim(),
|
|
456
|
+
privateKeyPath: env[names.privateKeyPath]?.trim()
|
|
457
|
+
};
|
|
458
|
+
if (!values.appId || !values.installationId || !values.privateKeyPath) {
|
|
459
|
+
throw new DeliveryError(
|
|
460
|
+
`Missing GitHub App credentials for ${role} role. Set ${names.appId}, ${names.installationId} and ${names.privateKeyPath}.`
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
if (!isAbsolute(values.privateKeyPath)) {
|
|
464
|
+
throw new DeliveryError(`GitHub App private-key path for ${role} role (${names.privateKeyPath}) must be absolute.`);
|
|
465
|
+
}
|
|
466
|
+
const installationId = Number(values.installationId);
|
|
467
|
+
if (!Number.isSafeInteger(installationId) || installationId <= 0) {
|
|
468
|
+
throw new DeliveryError(`Invalid GitHub App installation ID for ${role} role (${names.installationId}).`);
|
|
469
|
+
}
|
|
470
|
+
const appId = Number(values.appId);
|
|
471
|
+
if (!Number.isSafeInteger(appId) || appId <= 0) {
|
|
472
|
+
throw new DeliveryError(`Invalid GitHub App ID for ${role} role (${names.appId}).`);
|
|
473
|
+
}
|
|
474
|
+
return { appId: values.appId, installationId, privateKeyPath: values.privateKeyPath };
|
|
408
475
|
}
|
|
409
476
|
function isWithin(root, path) {
|
|
410
|
-
|
|
411
|
-
|
|
477
|
+
const relation = relative(root, path);
|
|
478
|
+
return relation !== ".." && !relation.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) && !isAbsolute(relation);
|
|
412
479
|
}
|
|
413
|
-
|
|
480
|
+
export {
|
|
481
|
+
DELIVERY_CONFIG_FILE,
|
|
482
|
+
DELIVERY_POLICY_CONTRACT,
|
|
483
|
+
NativeDeliveryConfigSchema,
|
|
484
|
+
ReviewProvider,
|
|
485
|
+
WipLimits,
|
|
486
|
+
appCredentialSource,
|
|
487
|
+
credentialReferenceNames,
|
|
488
|
+
loadDeliveryConfig,
|
|
489
|
+
loadDeliverySettings,
|
|
490
|
+
parseDeliveryConfig,
|
|
491
|
+
privateKeyVariable,
|
|
492
|
+
readDeliveryOverrides,
|
|
493
|
+
resolveDeliveryRoleCredentials
|
|
494
|
+
};
|
|
495
|
+
//# sourceMappingURL=deliveryConfig.js.map
|