@aviaratech/ai-delivery 0.3.25 → 0.3.27
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/README.md +115 -14
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +1 -0
- package/dist/agent.js.map +1 -1
- package/dist/agentReadiness.test.js +61 -123
- package/dist/agentReadiness.test.js.map +1 -1
- package/dist/cli.js +121 -32
- package/dist/cli.js.map +1 -1
- package/dist/cliResult.js +1 -1
- package/dist/cliResult.js.map +1 -1
- package/dist/cliResult.test.js +18 -0
- package/dist/cliResult.test.js.map +1 -1
- package/dist/config/deliveryConfig.js +5 -1
- package/dist/config/deliveryConfig.js.map +1 -1
- package/dist/deliveryHealth.test.d.ts +1 -0
- package/dist/deliveryHealth.test.js +167 -0
- package/dist/deliveryHealth.test.js.map +1 -0
- package/dist/dispatch.d.ts +26 -2
- package/dist/dispatch.js +78 -7
- package/dist/dispatch.js.map +1 -1
- package/dist/fixtures/inertEntrypointChild.d.ts +1 -0
- package/dist/fixtures/inertEntrypointChild.js +62 -0
- package/dist/fixtures/inertEntrypointChild.js.map +1 -0
- package/dist/fixtures/inertEntrypoints.d.ts +49 -0
- package/dist/fixtures/inertEntrypoints.js +276 -0
- package/dist/fixtures/inertEntrypoints.js.map +1 -0
- package/dist/fixtures/inertTarget.d.ts +643 -0
- package/dist/fixtures/inertTarget.js +713 -0
- package/dist/fixtures/inertTarget.js.map +1 -0
- package/dist/fixtures/issue63.d.ts +68 -0
- package/dist/fixtures/issue63.js +272 -0
- package/dist/fixtures/issue63.js.map +1 -0
- package/dist/github/client.d.ts +2 -0
- package/dist/github/client.js +94 -12
- package/dist/github/client.js.map +1 -1
- package/dist/github/issueHistory.d.ts +40 -0
- package/dist/github/issueHistory.js +144 -0
- package/dist/github/issueHistory.js.map +1 -0
- package/dist/github/machineAuth.d.ts +9 -0
- package/dist/github/machineAuth.js +135 -0
- package/dist/github/machineAuth.js.map +1 -0
- package/dist/github/machineAuth.test.d.ts +1 -0
- package/dist/github/machineAuth.test.js +409 -0
- package/dist/github/machineAuth.test.js.map +1 -0
- package/dist/github/projectDelivery.d.ts +2 -0
- package/dist/github/projectDelivery.js +6 -0
- package/dist/github/projectDelivery.js.map +1 -1
- package/dist/github/relationships.d.ts +9 -2
- package/dist/github/relationships.js +6 -2
- package/dist/github/relationships.js.map +1 -1
- package/dist/investigationCompletion.test.d.ts +1 -0
- package/dist/investigationCompletion.test.js +728 -0
- package/dist/investigationCompletion.test.js.map +1 -0
- package/dist/issue.d.ts +24 -6
- package/dist/issue.js +169 -21
- package/dist/issue.js.map +1 -1
- package/dist/issue63History.test.d.ts +1 -0
- package/dist/issue63History.test.js +45 -0
- package/dist/issue63History.test.js.map +1 -0
- package/dist/issue63Routes.test.d.ts +1 -0
- package/dist/issue63Routes.test.js +153 -0
- package/dist/issue63Routes.test.js.map +1 -0
- package/dist/issueBlockerGuard.test.d.ts +1 -0
- package/dist/issueBlockerGuard.test.js +162 -0
- package/dist/issueBlockerGuard.test.js.map +1 -0
- package/dist/issueContract.d.ts +230 -0
- package/dist/issueContract.js +341 -0
- package/dist/issueContract.js.map +1 -0
- package/dist/issueContract.test.d.ts +27 -0
- package/dist/issueContract.test.js +314 -0
- package/dist/issueContract.test.js.map +1 -0
- package/dist/issueIntake.test.d.ts +1 -0
- package/dist/issueIntake.test.js +994 -0
- package/dist/issueIntake.test.js.map +1 -0
- package/dist/issueJournal.d.ts +1 -1
- package/dist/issueTracking.test.js +16 -8
- package/dist/issueTracking.test.js.map +1 -1
- package/dist/mcp/tools.d.ts +135 -11
- package/dist/mcp/tools.js +85 -33
- package/dist/mcp/tools.js.map +1 -1
- package/dist/pluginAuthProbe.d.ts +6 -0
- package/dist/pluginAuthProbe.js +53 -0
- package/dist/pluginAuthProbe.js.map +1 -0
- package/dist/pluginAuthProbe.test.d.ts +1 -0
- package/dist/pluginAuthProbe.test.js +66 -0
- package/dist/pluginAuthProbe.test.js.map +1 -0
- package/dist/pluginCredentials.test.d.ts +1 -0
- package/dist/pluginCredentials.test.js +277 -0
- package/dist/pluginCredentials.test.js.map +1 -0
- package/dist/pluginDoctor.test.d.ts +1 -0
- package/dist/pluginDoctor.test.js +627 -0
- package/dist/pluginDoctor.test.js.map +1 -0
- package/dist/pluginInstaller.d.ts +36 -0
- package/dist/pluginInstaller.js +231 -10
- package/dist/pluginInstaller.js.map +1 -1
- package/dist/pluginInstaller.test.js +29 -0
- package/dist/pluginInstaller.test.js.map +1 -1
- package/dist/pluginPackaging.test.js +23 -3
- package/dist/pluginPackaging.test.js.map +1 -1
- package/dist/pr.d.ts +70 -0
- package/dist/pr.js +290 -3
- package/dist/pr.js.map +1 -1
- package/dist/prAssociation.test.js +31 -0
- package/dist/prAssociation.test.js.map +1 -1
- package/dist/review.test.js +133 -0
- package/dist/review.test.js.map +1 -1
- package/dist/services/agentReadinessService.d.ts +9 -8
- package/dist/services/agentReadinessService.js +32 -224
- package/dist/services/agentReadinessService.js.map +1 -1
- package/dist/services/blockerGuardService.d.ts +17 -0
- package/dist/services/blockerGuardService.js +194 -0
- package/dist/services/blockerGuardService.js.map +1 -0
- package/dist/services/deliveryAdmission.js +22 -19
- package/dist/services/deliveryAdmission.js.map +1 -1
- package/dist/services/deliveryHealthService.d.ts +84 -0
- package/dist/services/deliveryHealthService.js +206 -0
- package/dist/services/deliveryHealthService.js.map +1 -0
- package/dist/services/worktreeRegistry.d.ts +84 -0
- package/dist/services/worktreeRegistry.js +265 -1
- package/dist/services/worktreeRegistry.js.map +1 -1
- package/dist/setup.test.js +97 -3
- package/dist/setup.test.js.map +1 -1
- package/dist/start.test.js +31 -3
- package/dist/start.test.js.map +1 -1
- package/dist/stdoutRegression.test.js +38 -8
- package/dist/stdoutRegression.test.js.map +1 -1
- package/dist/targetPolicyDiscovery.test.d.ts +1 -0
- package/dist/targetPolicyDiscovery.test.js +150 -0
- package/dist/targetPolicyDiscovery.test.js.map +1 -0
- package/dist/targetPolicyEntrypoints.test.d.ts +1 -0
- package/dist/targetPolicyEntrypoints.test.js +275 -0
- package/dist/targetPolicyEntrypoints.test.js.map +1 -0
- package/dist/targetPolicyLocal.test.d.ts +1 -0
- package/dist/targetPolicyLocal.test.js +707 -0
- package/dist/targetPolicyLocal.test.js.map +1 -0
- package/dist/targetPolicyRoutes.test.d.ts +1 -0
- package/dist/targetPolicyRoutes.test.js +298 -0
- package/dist/targetPolicyRoutes.test.js.map +1 -0
- package/dist/verification.js +48 -12
- package/dist/verification.js.map +1 -1
- package/dist/verificationGate.test.d.ts +1 -0
- package/dist/verificationGate.test.js +106 -0
- package/dist/verificationGate.test.js.map +1 -0
- package/dist/worktree.d.ts +6 -1
- package/dist/worktree.js +90 -3
- package/dist/worktree.js.map +1 -1
- package/dist/worktreeTransition.test.js +1 -1
- package/dist/worktreeTransition.test.js.map +1 -1
- package/package.json +1 -1
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +160 -1
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/cli.js +83 -49
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +45 -30
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +20 -0
package/dist/pr.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type GitHubClients } from './github/client.js';
|
|
2
2
|
import { startIssueBranch, type DeliveryContext } from './issue.js';
|
|
3
|
+
import { type InvestigationPreparation } from './services/worktreeRegistry.js';
|
|
3
4
|
export declare function prInfo(context: DeliveryContext, input: {
|
|
4
5
|
issueNumber?: number;
|
|
5
6
|
prNumber?: number;
|
|
@@ -148,3 +149,72 @@ export declare function finishIssue(context: DeliveryContext, input: {
|
|
|
148
149
|
reused: boolean;
|
|
149
150
|
}>;
|
|
150
151
|
export { startIssueBranch };
|
|
152
|
+
export declare function investigationPreparationBody(preparation: InvestigationPreparation): string;
|
|
153
|
+
export declare function investigationAuthorityBody(preparation: InvestigationPreparation, resultDigest: string): string;
|
|
154
|
+
export declare function investigationAcceptanceBody(preparation: InvestigationPreparation, resultDigest: string, authorityCommentId: number): string;
|
|
155
|
+
/** Explicit author mode for a host-created worktree; ordinary start remains remote-only. */
|
|
156
|
+
export declare function registerInvestigation(context: DeliveryContext, input: {
|
|
157
|
+
issueNumber: number;
|
|
158
|
+
investigationWorktree: string;
|
|
159
|
+
expectedHeadSha: string;
|
|
160
|
+
}): Promise<{
|
|
161
|
+
preparation: {
|
|
162
|
+
schemaVersion: "ai-delivery.investigation-preparation@1";
|
|
163
|
+
preparationId: string;
|
|
164
|
+
repository: string;
|
|
165
|
+
repoRoot: string;
|
|
166
|
+
row: {
|
|
167
|
+
prNumber?: number;
|
|
168
|
+
branch: string;
|
|
169
|
+
createdAt: string;
|
|
170
|
+
identity: string;
|
|
171
|
+
issueNumber: number;
|
|
172
|
+
path: string;
|
|
173
|
+
status: "error" | "active" | "stale" | "merged" | "pr-published";
|
|
174
|
+
type: "issue";
|
|
175
|
+
updatedAt: string;
|
|
176
|
+
};
|
|
177
|
+
head: {
|
|
178
|
+
sha: string;
|
|
179
|
+
tree: string;
|
|
180
|
+
};
|
|
181
|
+
physical: {
|
|
182
|
+
device: number;
|
|
183
|
+
inode: number;
|
|
184
|
+
gitDirectory: string;
|
|
185
|
+
gitDevice: number;
|
|
186
|
+
gitInode: number;
|
|
187
|
+
};
|
|
188
|
+
operator: {
|
|
189
|
+
actorLogin: string;
|
|
190
|
+
credentialIdentity: string;
|
|
191
|
+
};
|
|
192
|
+
reviewerActor: string;
|
|
193
|
+
};
|
|
194
|
+
acknowledgement: {
|
|
195
|
+
commentId: number;
|
|
196
|
+
url: string;
|
|
197
|
+
body: string;
|
|
198
|
+
};
|
|
199
|
+
registered: boolean;
|
|
200
|
+
}>;
|
|
201
|
+
/** One non-mergeable completion path. No PR, issue close, reviewer submission or branch deletion occurs. */
|
|
202
|
+
export declare function finishInvestigation(context: DeliveryContext, input: {
|
|
203
|
+
issueNumber: number;
|
|
204
|
+
resultPath: string;
|
|
205
|
+
authorityCommentId?: number;
|
|
206
|
+
acceptanceCommentId?: number;
|
|
207
|
+
dryRun?: boolean;
|
|
208
|
+
}): Promise<{
|
|
209
|
+
completed: boolean;
|
|
210
|
+
replayed: boolean;
|
|
211
|
+
receiptPath?: string;
|
|
212
|
+
} | {
|
|
213
|
+
missingEvidence: string;
|
|
214
|
+
acceptanceBody?: string;
|
|
215
|
+
completed: boolean;
|
|
216
|
+
ready: boolean;
|
|
217
|
+
preparationId: string;
|
|
218
|
+
resultDigest: `sha256:${string}`;
|
|
219
|
+
authorityBody: string;
|
|
220
|
+
}>;
|
package/dist/pr.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { DeliveryError } from './errors.js';
|
|
2
2
|
import { createDeliveryGitHubClients } from './github/client.js';
|
|
3
3
|
import { getNativeBlockerRelationships } from './github/relationships.js';
|
|
4
|
-
import { issueBranch, linkedIssueBranches, startIssueBranch } from './issue.js';
|
|
4
|
+
import { commentIssue, issueBranch, linkedIssueBranches, readIssueClosure, startIssueBranch, } from './issue.js';
|
|
5
|
+
import { existsSync, lstatSync, realpathSync } from 'node:fs';
|
|
6
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import { assertPrivateFile, digestBytes, digestValue, stableJson } from './delivery/common.js';
|
|
8
|
+
import { gitCommonDir, primaryGitRoot } from './git.js';
|
|
9
|
+
import { ensurePrivateDirectoryDurably } from './utils/atomicJson.js';
|
|
10
|
+
import { resolveRepoFromRemote } from './github/repo.js';
|
|
11
|
+
import { authenticatedWorktreeActors, assertNativeWorktreeAcceptance } from './worktreeTransition.js';
|
|
12
|
+
import { withWorktreeTransitionWriterAbsent } from './verification.js';
|
|
13
|
+
import { assertInvestigationSource, investigationSourceIdentity, removeInvestigationSource } from './worktree.js';
|
|
14
|
+
import { InvestigationPreparationSchema, completeInvestigationCustody, readInvestigationAcknowledgement, readInvestigationPreparation, registerInvestigationCustody, } from './services/worktreeRegistry.js';
|
|
5
15
|
import { parseGitHubReviewArtifact, parseReviewArtifact, readGitHubPrScopeHash, readRequiredReviewState, submitReview, } from './review.js';
|
|
6
16
|
const Sha = /^[a-f0-9]{40}$/u;
|
|
7
17
|
const Branch = /^(?!.*(?:\.\.|@\{|\/\/))[A-Za-z0-9._/-]+$/u;
|
|
@@ -504,6 +514,15 @@ function requiredApprovalCount(value) {
|
|
|
504
514
|
const count = value.required_approving_review_count;
|
|
505
515
|
return typeof count === 'number' && Number.isSafeInteger(count) && count >= 0 ? count : null;
|
|
506
516
|
}
|
|
517
|
+
/** Absence is proved only by an empty successful first page with no continuation evidence. */
|
|
518
|
+
function emptyRulePage(response) {
|
|
519
|
+
return (response.status === 200 &&
|
|
520
|
+
Array.isArray(response.data) &&
|
|
521
|
+
response.data.length === 0 &&
|
|
522
|
+
response.headers !== undefined &&
|
|
523
|
+
response.headers !== null &&
|
|
524
|
+
(response.headers.link === undefined || response.headers.link === ''));
|
|
525
|
+
}
|
|
507
526
|
/** Check selected actors and rule evidence; publication also requires the configured author source. */
|
|
508
527
|
export async function preflightReviewRoute(context, base, selectedReviewer, purpose = 'publication', control) {
|
|
509
528
|
if (base === undefined) {
|
|
@@ -582,6 +601,44 @@ export async function preflightReviewRoute(context, base, selectedReviewer, purp
|
|
|
582
601
|
}),
|
|
583
602
|
]);
|
|
584
603
|
await check();
|
|
604
|
+
let confirmedUnprotected = false;
|
|
605
|
+
const protectionError = protectionResult.status === 'rejected'
|
|
606
|
+
? protectionResult.reason
|
|
607
|
+
: null;
|
|
608
|
+
if (rulesetResult.status === 'fulfilled' &&
|
|
609
|
+
emptyRulePage(rulesetResult.value) &&
|
|
610
|
+
protectionError?.status === 404 &&
|
|
611
|
+
protectionError.response?.status === 404 &&
|
|
612
|
+
protectionError.response.data?.message === 'Branch not protected') {
|
|
613
|
+
// A generic/permission 404 is never absence. Corroborate the named branch,
|
|
614
|
+
// selected author's write access, and all repository/parent rulesets.
|
|
615
|
+
const parameters = { ...context.repo, ...(control === undefined ? {} : { request: { signal: control.signal } }) };
|
|
616
|
+
const [repository, branch, rulesets] = await Promise.allSettled([
|
|
617
|
+
context.clients.rest.request('GET /repos/{owner}/{repo}', parameters),
|
|
618
|
+
context.clients.rest.request('GET /repos/{owner}/{repo}/branches/{branch}', { ...parameters, branch: base }),
|
|
619
|
+
context.clients.rest.request('GET /repos/{owner}/{repo}/rulesets', {
|
|
620
|
+
...parameters,
|
|
621
|
+
includes_parents: true,
|
|
622
|
+
per_page: 100,
|
|
623
|
+
page: 1,
|
|
624
|
+
}),
|
|
625
|
+
]);
|
|
626
|
+
await check();
|
|
627
|
+
if (repository.status === 'fulfilled' && branch.status === 'fulfilled' && rulesets.status === 'fulfilled') {
|
|
628
|
+
const repoData = repository.value.data;
|
|
629
|
+
const branchData = branch.value.data;
|
|
630
|
+
confirmedUnprotected =
|
|
631
|
+
repository.value.status === 200 &&
|
|
632
|
+
branch.value.status === 200 &&
|
|
633
|
+
typeof repoData?.full_name === 'string' &&
|
|
634
|
+
repoData.full_name.toLowerCase() === `${context.repo.owner}/${context.repo.repo}`.toLowerCase() &&
|
|
635
|
+
(repoData.permissions?.push === true || repoData.permissions?.admin === true) &&
|
|
636
|
+
branchData?.name === base &&
|
|
637
|
+
branchData.protected === false &&
|
|
638
|
+
branchData.protection?.enabled === false &&
|
|
639
|
+
emptyRulePage(rulesets.value);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
585
642
|
const counts = [];
|
|
586
643
|
if (rulesetResult.status === 'fulfilled' && Array.isArray(rulesetResult.value.data)) {
|
|
587
644
|
for (const rule of rulesetResult.value.data) {
|
|
@@ -598,9 +655,12 @@ export async function preflightReviewRoute(context, base, selectedReviewer, purp
|
|
|
598
655
|
if (count !== null)
|
|
599
656
|
counts.push(count);
|
|
600
657
|
}
|
|
601
|
-
const
|
|
658
|
+
const rulesVisible = rulesetResult.status === 'fulfilled' &&
|
|
659
|
+
Array.isArray(rulesetResult.value.data) &&
|
|
660
|
+
(rulesetResult.value.headers?.link === undefined || rulesetResult.value.headers.link === '');
|
|
661
|
+
const visible = Number(rulesVisible) + Number(protectionResult.status === 'fulfilled' || confirmedUnprotected);
|
|
602
662
|
const visibility = visible === 2 ? 'complete' : visible === 1 ? 'partial' : 'unknown';
|
|
603
|
-
const observedRequiredApprovals = counts.length > 0 ? Math.max(...counts) : null;
|
|
663
|
+
const observedRequiredApprovals = counts.length > 0 ? Math.max(...counts) : confirmedUnprotected ? 0 : null;
|
|
604
664
|
const insufficientPermission = observedRequiredApprovals !== null &&
|
|
605
665
|
observedRequiredApprovals > 0 &&
|
|
606
666
|
reviewer.effectiveContentsPermission === 'read';
|
|
@@ -1057,4 +1117,231 @@ export async function finishIssue(context, input) {
|
|
|
1057
1117
|
return { ...result, issueClosed: true };
|
|
1058
1118
|
}
|
|
1059
1119
|
export { startIssueBranch };
|
|
1120
|
+
function investigationRoot(context) {
|
|
1121
|
+
const root = primaryGitRoot(context.root);
|
|
1122
|
+
const repo = resolveRepoFromRemote(root, 'origin');
|
|
1123
|
+
if (`${repo.owner}/${repo.repo}`.toLowerCase() !== context.config.repository.toLowerCase() ||
|
|
1124
|
+
`${context.repo.owner}/${context.repo.repo}`.toLowerCase() !== context.config.repository.toLowerCase())
|
|
1125
|
+
throw new DeliveryError('Investigation repository identity disagrees.');
|
|
1126
|
+
return root;
|
|
1127
|
+
}
|
|
1128
|
+
async function withInvestigationExclusion(root, target, operation) {
|
|
1129
|
+
const common = gitCommonDir(root);
|
|
1130
|
+
for (const directory of [join(common, 'ai-delivery'), join(common, 'ai-delivery', 'writers@1')]) {
|
|
1131
|
+
try {
|
|
1132
|
+
const metadata = lstatSync(directory);
|
|
1133
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink())
|
|
1134
|
+
throw new DeliveryError('Investigation writer namespace is unsafe.');
|
|
1135
|
+
}
|
|
1136
|
+
catch (error) {
|
|
1137
|
+
if (error.code !== 'ENOENT')
|
|
1138
|
+
throw error;
|
|
1139
|
+
}
|
|
1140
|
+
ensurePrivateDirectoryDurably(directory);
|
|
1141
|
+
}
|
|
1142
|
+
return withWorktreeTransitionWriterAbsent(root, target, operation);
|
|
1143
|
+
}
|
|
1144
|
+
async function investigationNativeSource(context, issueNumber, headSha, state) {
|
|
1145
|
+
const issue = (await context.clients.rest.issues.get({ ...context.repo, issue_number: issueNumber })).data;
|
|
1146
|
+
if (issue.number !== issueNumber ||
|
|
1147
|
+
'pull_request' in issue ||
|
|
1148
|
+
issue.state !== state ||
|
|
1149
|
+
new URL(issue.html_url).pathname.toLowerCase() !==
|
|
1150
|
+
`/${context.config.repository}/issues/${String(issueNumber)}`.toLowerCase())
|
|
1151
|
+
throw new DeliveryError('Investigation requires the exact native issue and expected state.');
|
|
1152
|
+
const branches = await linkedIssueBranches(context, issueNumber);
|
|
1153
|
+
if (branches.length !== 1 || branches[0].name !== `issue/${String(issueNumber)}` || branches[0].sha !== headSha)
|
|
1154
|
+
throw new DeliveryError('Investigation requires one exact unchanged native linked branch.');
|
|
1155
|
+
const prs = (await context.clients.rest.pulls.list({
|
|
1156
|
+
...context.repo,
|
|
1157
|
+
state: 'all',
|
|
1158
|
+
head: `${context.repo.owner}:${branches[0].name}`,
|
|
1159
|
+
per_page: 100,
|
|
1160
|
+
})).data;
|
|
1161
|
+
if (prs.length !== 0)
|
|
1162
|
+
throw new DeliveryError('Investigation completion cannot substitute for PR delivery.');
|
|
1163
|
+
}
|
|
1164
|
+
export function investigationPreparationBody(preparation) {
|
|
1165
|
+
return stableJson({
|
|
1166
|
+
schemaVersion: 'ai-delivery.investigation-preparation-acknowledgement@1',
|
|
1167
|
+
preparation,
|
|
1168
|
+
authority: 'prospective-registration-before-investigation-no-legacy-adoption',
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
export function investigationAuthorityBody(preparation, resultDigest) {
|
|
1172
|
+
return stableJson({
|
|
1173
|
+
schemaVersion: 'ai-delivery.investigation-removal-authority@1',
|
|
1174
|
+
preparationId: preparation.preparationId,
|
|
1175
|
+
repository: preparation.repository,
|
|
1176
|
+
issueNumber: preparation.row.issueNumber,
|
|
1177
|
+
head: preparation.head,
|
|
1178
|
+
worktree: preparation.row.path,
|
|
1179
|
+
branch: preparation.row.branch,
|
|
1180
|
+
resultDigest,
|
|
1181
|
+
disposition: 'remove-only-this-unchanged-investigation-worktree-retain-branch-and-evidence',
|
|
1182
|
+
operationalClosure: 'all-investigation-producers-quiescent-and-excluded-through-completion-and-resume-no-outstanding-holds',
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
export function investigationAcceptanceBody(preparation, resultDigest, authorityCommentId) {
|
|
1186
|
+
return stableJson({
|
|
1187
|
+
schemaVersion: 'ai-delivery.investigation-result-acceptance@1',
|
|
1188
|
+
authority: JSON.parse(investigationAuthorityBody(preparation, resultDigest)),
|
|
1189
|
+
authorityCommentId,
|
|
1190
|
+
verdict: 'approved',
|
|
1191
|
+
independentlyReviewed: 'complete-durable-result-exact-source-and-removal-scope',
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
/** Explicit author mode for a host-created worktree; ordinary start remains remote-only. */
|
|
1195
|
+
export async function registerInvestigation(context, input) {
|
|
1196
|
+
if (!Number.isSafeInteger(input.issueNumber) || input.issueNumber <= 0 || !Sha.test(input.expectedHeadSha))
|
|
1197
|
+
throw new DeliveryError('Investigation preparation requires a positive issue and expected commit.');
|
|
1198
|
+
const root = investigationRoot(context);
|
|
1199
|
+
const target = join(root, '.worktrees', `issue-${String(input.issueNumber)}`);
|
|
1200
|
+
if (input.investigationWorktree !== target || realpathSync(target) !== target)
|
|
1201
|
+
throw new DeliveryError('Investigation worktree must be the exact canonical .worktrees/issue-N path.');
|
|
1202
|
+
if (existsSync(join(root, '.issue-cli', 'issues', String(input.issueNumber))))
|
|
1203
|
+
throw new DeliveryError('Historical issue custody remains preservation-only; investigation cannot adopt it.');
|
|
1204
|
+
const actors = await authenticatedWorktreeActors(context);
|
|
1205
|
+
const observed = investigationSourceIdentity(root, input.issueNumber);
|
|
1206
|
+
const prior = readInvestigationPreparation(root, input.issueNumber);
|
|
1207
|
+
await investigationNativeSource(context, input.issueNumber, observed.head.sha, 'open');
|
|
1208
|
+
if (observed.head.sha !== input.expectedHeadSha)
|
|
1209
|
+
throw new DeliveryError('Investigation preparation source drifted from the expected head.');
|
|
1210
|
+
if (prior === undefined) {
|
|
1211
|
+
const repository = (await context.clients.rest.repos.get({ ...context.repo })).data;
|
|
1212
|
+
if (repository.full_name.toLowerCase() !== context.config.repository.toLowerCase() || !repository.default_branch)
|
|
1213
|
+
throw new DeliveryError('Investigation native repository identity is incomplete.');
|
|
1214
|
+
const base = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${repository.default_branch}` }))
|
|
1215
|
+
.data;
|
|
1216
|
+
if (base.object.sha !== observed.head.sha)
|
|
1217
|
+
throw new DeliveryError('Prospective investigation must begin at the current native default commit.');
|
|
1218
|
+
}
|
|
1219
|
+
const date = new Date().toISOString();
|
|
1220
|
+
const content = {
|
|
1221
|
+
schemaVersion: 'ai-delivery.investigation-preparation@1',
|
|
1222
|
+
repository: context.config.repository,
|
|
1223
|
+
repoRoot: root,
|
|
1224
|
+
row: prior?.row ?? {
|
|
1225
|
+
branch: `issue/${String(input.issueNumber)}`,
|
|
1226
|
+
createdAt: date,
|
|
1227
|
+
identity: context.config.roles.author.identity,
|
|
1228
|
+
issueNumber: input.issueNumber,
|
|
1229
|
+
path: target,
|
|
1230
|
+
status: 'active',
|
|
1231
|
+
type: 'issue',
|
|
1232
|
+
updatedAt: date,
|
|
1233
|
+
},
|
|
1234
|
+
...observed,
|
|
1235
|
+
operator: { actorLogin: actors.operator.actorLogin, credentialIdentity: actors.operator.credentialIdentity },
|
|
1236
|
+
reviewerActor: actors.reviewerActor,
|
|
1237
|
+
};
|
|
1238
|
+
const preparation = InvestigationPreparationSchema.parse({ ...content, preparationId: digestValue(content) });
|
|
1239
|
+
await withInvestigationExclusion(root, target, () => registerInvestigationCustody(preparation, async () => {
|
|
1240
|
+
if (stableJson(investigationSourceIdentity(root, input.issueNumber)) !== stableJson(observed))
|
|
1241
|
+
throw new DeliveryError('Investigation source changed before preparation acknowledgement.');
|
|
1242
|
+
await investigationNativeSource(context, input.issueNumber, observed.head.sha, 'open');
|
|
1243
|
+
const { commentId, url, body } = await commentIssue(context, {
|
|
1244
|
+
issueNumber: input.issueNumber,
|
|
1245
|
+
body: investigationPreparationBody(preparation),
|
|
1246
|
+
});
|
|
1247
|
+
if (stableJson(investigationSourceIdentity(root, input.issueNumber)) !== stableJson(observed))
|
|
1248
|
+
throw new DeliveryError('Investigation source changed during preparation acknowledgement.');
|
|
1249
|
+
return { commentId, url, body };
|
|
1250
|
+
}));
|
|
1251
|
+
return { preparation, acknowledgement: readInvestigationAcknowledgement(root, input.issueNumber), registered: true };
|
|
1252
|
+
}
|
|
1253
|
+
/** One non-mergeable completion path. No PR, issue close, reviewer submission or branch deletion occurs. */
|
|
1254
|
+
export async function finishInvestigation(context, input) {
|
|
1255
|
+
if (['prNumber', 'strategy', 'reviewedHeadSha', 'nonClosing'].some((key) => key in input))
|
|
1256
|
+
throw new DeliveryError('Investigation completion refuses PR or merge options.');
|
|
1257
|
+
const root = investigationRoot(context);
|
|
1258
|
+
const preparation = readInvestigationPreparation(root, input.issueNumber);
|
|
1259
|
+
if (!preparation)
|
|
1260
|
+
throw new DeliveryError('No prospective investigation preparation; historical custody cannot be reconstructed.');
|
|
1261
|
+
const resultPath = resolve(input.resultPath);
|
|
1262
|
+
const resultRelative = relative(preparation.row.path, resultPath);
|
|
1263
|
+
const resultOutside = resultRelative === '..' || resultRelative.startsWith(`..${sep}`) || isAbsolute(resultRelative);
|
|
1264
|
+
if (realpathSync(resultPath) !== resultPath || !resultOutside)
|
|
1265
|
+
throw new DeliveryError('Durable investigation result must be canonical and outside the removable worktree.');
|
|
1266
|
+
const result = assertPrivateFile(resultPath, { maxBytes: 512 * 1024 });
|
|
1267
|
+
if (result.length === 0)
|
|
1268
|
+
throw new DeliveryError('Investigation result must contain durable evidence.');
|
|
1269
|
+
const resultDigest = digestBytes(result);
|
|
1270
|
+
const authorityBody = investigationAuthorityBody(preparation, resultDigest);
|
|
1271
|
+
const acceptanceBody = input.authorityCommentId === undefined
|
|
1272
|
+
? undefined
|
|
1273
|
+
: investigationAcceptanceBody(preparation, resultDigest, input.authorityCommentId);
|
|
1274
|
+
const authorize = async () => {
|
|
1275
|
+
await investigationNativeSource(context, input.issueNumber, preparation.head.sha, 'closed');
|
|
1276
|
+
const closure = await readIssueClosure(context, input.issueNumber);
|
|
1277
|
+
if (closure.state !== 'closed' || closure.closeReason !== 'completed' || closure.duplicateOf !== null)
|
|
1278
|
+
throw new DeliveryError('Investigation requires native completed closed-issue authority.');
|
|
1279
|
+
const acknowledgement = readInvestigationAcknowledgement(root, input.issueNumber);
|
|
1280
|
+
const native = (await context.clients.rest.issues.getComment({ ...context.repo, comment_id: acknowledgement.commentId })).data;
|
|
1281
|
+
if (native.id !== acknowledgement.commentId ||
|
|
1282
|
+
native.body !== investigationPreparationBody(preparation) ||
|
|
1283
|
+
native.body !== acknowledgement.body ||
|
|
1284
|
+
native.issue_url.toLowerCase() !==
|
|
1285
|
+
`https://api.github.com/repos/${preparation.repository}/issues/${String(input.issueNumber)}`.toLowerCase() ||
|
|
1286
|
+
native.user?.type !== 'User' ||
|
|
1287
|
+
native.user.login.toLowerCase() !== preparation.operator.actorLogin.toLowerCase() ||
|
|
1288
|
+
`user:${String(native.user.id)}` !== preparation.operator.credentialIdentity)
|
|
1289
|
+
throw new DeliveryError('Native prospective preparation acknowledgement changed.');
|
|
1290
|
+
if (input.authorityCommentId === undefined ||
|
|
1291
|
+
input.acceptanceCommentId === undefined ||
|
|
1292
|
+
acceptanceBody === undefined)
|
|
1293
|
+
throw new DeliveryError('Existing authentic operator and independent App acceptance comments are required.');
|
|
1294
|
+
const authority = await assertNativeWorktreeAcceptance(context, {
|
|
1295
|
+
repository: preparation.repository,
|
|
1296
|
+
subject: input.issueNumber,
|
|
1297
|
+
operator: preparation.operator,
|
|
1298
|
+
reviewerActor: preparation.reviewerActor,
|
|
1299
|
+
authorityCommentId: input.authorityCommentId,
|
|
1300
|
+
acceptanceCommentId: input.acceptanceCommentId,
|
|
1301
|
+
operatorBody: authorityBody,
|
|
1302
|
+
reviewerBody: acceptanceBody,
|
|
1303
|
+
revokedBody: stableJson({
|
|
1304
|
+
schemaVersion: 'ai-delivery.investigation-removal-revocation@1',
|
|
1305
|
+
preparationId: preparation.preparationId,
|
|
1306
|
+
resultDigest,
|
|
1307
|
+
authorityCommentId: input.authorityCommentId,
|
|
1308
|
+
}),
|
|
1309
|
+
});
|
|
1310
|
+
const preparedAt = Date.parse(native.created_at);
|
|
1311
|
+
for (const value of [authority.relinquishment, authority.acceptance]) {
|
|
1312
|
+
const createdAt = Date.parse(value.created_at);
|
|
1313
|
+
if (!Number.isFinite(preparedAt) || !Number.isFinite(createdAt) || createdAt < preparedAt)
|
|
1314
|
+
throw new DeliveryError('Investigation acceptance must follow its prospective preparation.');
|
|
1315
|
+
}
|
|
1316
|
+
return { acknowledgement: native, closure, ...authority };
|
|
1317
|
+
};
|
|
1318
|
+
if (input.dryRun && (input.authorityCommentId === undefined || input.acceptanceCommentId === undefined)) {
|
|
1319
|
+
assertInvestigationSource(preparation, context.root);
|
|
1320
|
+
await investigationNativeSource(context, input.issueNumber, preparation.head.sha, 'closed');
|
|
1321
|
+
return {
|
|
1322
|
+
completed: false,
|
|
1323
|
+
ready: false,
|
|
1324
|
+
preparationId: preparation.preparationId,
|
|
1325
|
+
resultDigest,
|
|
1326
|
+
authorityBody,
|
|
1327
|
+
...(acceptanceBody === undefined ? {} : { acceptanceBody }),
|
|
1328
|
+
missingEvidence: 'Existing authentic operator and configured-App exact-result acceptance are prerequisites; no submission route is supplied.',
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
if (!Number.isSafeInteger(input.authorityCommentId) ||
|
|
1332
|
+
!Number.isSafeInteger(input.acceptanceCommentId) ||
|
|
1333
|
+
input.authorityCommentId <= 0 ||
|
|
1334
|
+
input.acceptanceCommentId <= 0)
|
|
1335
|
+
throw new DeliveryError('Investigation evidence requires positive native comment IDs.');
|
|
1336
|
+
return withInvestigationExclusion(root, preparation.row.path, () => completeInvestigationCustody({
|
|
1337
|
+
preparation,
|
|
1338
|
+
result,
|
|
1339
|
+
authorityCommentId: input.authorityCommentId,
|
|
1340
|
+
acceptanceCommentId: input.acceptanceCommentId,
|
|
1341
|
+
dryRun: input.dryRun === true,
|
|
1342
|
+
authorize,
|
|
1343
|
+
assertSource: (allowAbsent) => assertInvestigationSource(preparation, context.root, allowAbsent),
|
|
1344
|
+
removeSource: () => removeInvestigationSource(preparation, context.root),
|
|
1345
|
+
}));
|
|
1346
|
+
}
|
|
1060
1347
|
//# sourceMappingURL=pr.js.map
|