@ygrishajev/jig 1.0.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/adapters/git/remote-ref.js +125 -0
- package/dist/adapters/git/run-code.js +66 -0
- package/dist/adapters/git/run-history.js +79 -0
- package/dist/adapters/local-store/run-artefacts.js +2 -1
- package/dist/adapters/run-store/composite-run-store.js +68 -14
- package/dist/adapters/run-store/git-remote-run-store.js +34 -129
- package/dist/app/run-jig.js +28 -7
- package/dist/app/run-stores.js +4 -3
- package/dist/cli/commands/run.js +20 -7
- package/dist/cli/commands/status.js +3 -0
- package/dist/cli/main.js +3 -15
- package/dist/domain/apply-outcome.js +30 -13
- package/dist/domain/diagnostics.js +104 -0
- package/dist/domain/errors.js +8 -0
- package/dist/domain/final-check.js +21 -1
- package/dist/domain/run-id.js +4 -1
- package/dist/domain/run-state.js +51 -2
- package/dist/domain/slice.js +8 -2
- package/dist/flow/engine.js +4 -0
- package/dist/flow/run-flow.js +6 -2
- package/dist/integrations/github/cli.js +20 -0
- package/dist/integrations/github/command.js +68 -0
- package/dist/integrations/github/errors.js +19 -0
- package/dist/integrations/github/findings-comment.js +53 -0
- package/dist/integrations/github/github-port.js +1 -0
- package/dist/integrations/github/implement-issue.js +281 -0
- package/dist/integrations/github/octokit-github.js +101 -0
- package/dist/integrations/github/orchestration-state.js +132 -0
- package/dist/integrations/github/orchestration-store.js +109 -0
- package/dist/integrations/github/repository-identity.js +27 -0
- package/dist/integrations/github/request-snapshot.js +3 -0
- package/dist/integrations/github/run-branch-publication.js +102 -0
- package/dist/ports/run-code.js +1 -0
- package/dist/prompts/design-review.js +2 -0
- package/dist/prompts/planning.js +5 -1
- package/dist/prompts/pull-request.js +4 -1
- package/dist/prompts/slice.js +11 -0
- package/dist/steps/pull-request-description.js +1 -1
- package/dist/steps/slice.js +1 -0
- package/package.json +5 -4
package/dist/domain/errors.js
CHANGED
|
@@ -61,6 +61,13 @@ export class SetupCommandFailed extends TaggedError('SetupCommandFailed') {
|
|
|
61
61
|
export class RunStateConflict extends TaggedError('RunStateConflict') {
|
|
62
62
|
kind = 'block';
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* A saved run names a code checkpoint this machine cannot produce: the commit is neither kept here
|
|
66
|
+
* nor published on the remote, so resuming would continue from code the state does not describe.
|
|
67
|
+
*/
|
|
68
|
+
export class RunCodeUnavailable extends TaggedError('RunCodeUnavailable') {
|
|
69
|
+
kind = 'block';
|
|
70
|
+
}
|
|
64
71
|
export class MergeFailed extends TaggedError('MergeFailed') {
|
|
65
72
|
kind = 'block';
|
|
66
73
|
}
|
|
@@ -124,6 +131,7 @@ const jigErrorClasses = [
|
|
|
124
131
|
SandboxUnavailable,
|
|
125
132
|
SetupCommandFailed,
|
|
126
133
|
RunStateConflict,
|
|
134
|
+
RunCodeUnavailable,
|
|
127
135
|
MergeFailed,
|
|
128
136
|
GitCommandFailed,
|
|
129
137
|
CommitImportRefused,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { captureOutput, retainedFinalVerificationFailure, } from './diagnostics.js';
|
|
2
3
|
import { sliceFromPlan } from './slice.js';
|
|
3
4
|
/** What the whole-run reviewer reports: whether the run fulfils its request, and every gap. */
|
|
4
5
|
export const fulfillmentVerdictSchema = z.object({
|
|
@@ -12,8 +13,14 @@ export const fulfillmentVerdictSchema = z.object({
|
|
|
12
13
|
*/
|
|
13
14
|
export function recordFinalCheck(state, checked) {
|
|
14
15
|
const round = state.finalCheck === undefined ? 1 : 2;
|
|
16
|
+
const at = state.diagnosticSequence + 1;
|
|
15
17
|
const repaired = repairOwed(checked, round) ? withRepairSlice(state, checked) : state;
|
|
16
|
-
return {
|
|
18
|
+
return {
|
|
19
|
+
...repaired,
|
|
20
|
+
finalCheck: completedCheck(checked, round),
|
|
21
|
+
failedFinalVerification: lastFailedVerification(state, checked, { round, at }),
|
|
22
|
+
diagnosticSequence: at,
|
|
23
|
+
};
|
|
17
24
|
}
|
|
18
25
|
function repairOwed(checked, round) {
|
|
19
26
|
return round === 1 && checkFailed(checked);
|
|
@@ -97,6 +104,19 @@ function completedCheck(checked, round) {
|
|
|
97
104
|
round,
|
|
98
105
|
};
|
|
99
106
|
}
|
|
107
|
+
/** The verification this check failed, or the earlier failure it passed since. */
|
|
108
|
+
function lastFailedVerification(state, checked, { round, at }) {
|
|
109
|
+
const earlier = retainedFinalVerificationFailure(state);
|
|
110
|
+
if (checked.verified)
|
|
111
|
+
return earlier && { ...earlier, passedSince: true };
|
|
112
|
+
return {
|
|
113
|
+
command: checked.command,
|
|
114
|
+
output: captureOutput(checked.output),
|
|
115
|
+
round,
|
|
116
|
+
at,
|
|
117
|
+
passedSince: false,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
100
120
|
/** A failed check still owes the slices its one repair: a failure on the first round. */
|
|
101
121
|
export function finalCheckNeedsRepair(state) {
|
|
102
122
|
const result = state.finalCheck;
|
package/dist/domain/run-id.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto';
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
/**
|
|
@@ -40,3 +40,6 @@ export const runIdSchema = z
|
|
|
40
40
|
.string()
|
|
41
41
|
.regex(/^[a-z0-9-]+$/, 'a run id is lowercase letters, digits and hyphens')
|
|
42
42
|
.brand();
|
|
43
|
+
export function runIdFor({ name, key }) {
|
|
44
|
+
return runIdSchema.parse(`${slugOf(name) || 'request'}-${createHash('sha256').update(key).digest('hex').slice(0, 8)}`);
|
|
45
|
+
}
|
package/dist/domain/run-state.js
CHANGED
|
@@ -3,12 +3,20 @@ import { z } from 'zod';
|
|
|
3
3
|
import { completionEvidenceSchema } from './completion-reuse.js';
|
|
4
4
|
import { designDocsSchema } from './design-docs.js';
|
|
5
5
|
import { designReviewProgressAt, designReviewProgressSchema } from './design-review.js';
|
|
6
|
+
import { failedFinalVerificationSchema } from './diagnostics.js';
|
|
6
7
|
import { finalCheckFailed } from './final-check.js';
|
|
7
8
|
import { runIdSchema } from './run-id.js';
|
|
8
9
|
import { sliceStopReason } from './settings.js';
|
|
9
10
|
import { sliceSchema, slicesInOrder } from './slice.js';
|
|
10
11
|
export function startRun(input) {
|
|
11
|
-
return {
|
|
12
|
+
return {
|
|
13
|
+
...input,
|
|
14
|
+
merge: input.merge ?? true,
|
|
15
|
+
revision: 0,
|
|
16
|
+
diagnosticSequence: 0,
|
|
17
|
+
phase: 'context',
|
|
18
|
+
slices: [],
|
|
19
|
+
};
|
|
12
20
|
}
|
|
13
21
|
/** Moves a run into `phase`, checking it carries everything `phase` guarantees. */
|
|
14
22
|
export function enterPhase(state, phase) {
|
|
@@ -18,6 +26,7 @@ export function enterPhase(state, phase) {
|
|
|
18
26
|
}
|
|
19
27
|
return entered.data;
|
|
20
28
|
}
|
|
29
|
+
export const codePublicationSchema = z.enum(['deferred']);
|
|
21
30
|
export const runContextSchema = z.object({ classification: z.string(), repoSummary: z.string() });
|
|
22
31
|
export const featurePlanSchema = z.object({
|
|
23
32
|
summary: z.string(),
|
|
@@ -43,12 +52,26 @@ const runFields = z.object({
|
|
|
43
52
|
revision: z.number().int().nonnegative().default(0),
|
|
44
53
|
baseBranch: z.string().min(1),
|
|
45
54
|
request: z.string(),
|
|
55
|
+
/** Whether the run merges its branch when it finishes; a run saved before the choice existed merges. */
|
|
56
|
+
merge: z.boolean().default(true),
|
|
57
|
+
/**
|
|
58
|
+
* `deferred` keeps the run's code off the remote: saves publish state only, recording the
|
|
59
|
+
* commit the run branch held as `codeRevision`, and the code is published by whoever owns it.
|
|
60
|
+
*/
|
|
61
|
+
codePublication: codePublicationSchema.optional(),
|
|
62
|
+
/** The commit the run started from; absent on runs saved before it was recorded. */
|
|
63
|
+
startingCommit: z.string().min(1).optional(),
|
|
64
|
+
/** The run branch's commit at the last deferred save: the checkpoint a resume restores. */
|
|
65
|
+
codeRevision: z.string().min(1).optional(),
|
|
46
66
|
context: runContextSchema.optional(),
|
|
47
67
|
plan: featurePlanSchema.optional(),
|
|
48
68
|
docs: designDocsSchema.optional(),
|
|
49
69
|
designReview: designReviewProgressSchema.optional(),
|
|
50
70
|
slices: z.array(sliceSchema),
|
|
51
71
|
finalCheck: finalCheckResultSchema.optional(),
|
|
72
|
+
failedFinalVerification: failedFinalVerificationSchema.optional(),
|
|
73
|
+
/** Counts the send-backs and final checks the run recorded; each failure takes its count as `at`. */
|
|
74
|
+
diagnosticSequence: z.number().int().nonnegative().default(0),
|
|
52
75
|
/**
|
|
53
76
|
* What an eligible slice review recorded about the whole request, bound to the work it saw.
|
|
54
77
|
* Evidence saved before it carried its review scope loads as none, so the run declines reuse.
|
|
@@ -79,6 +102,7 @@ export const runPhaseSchema = z.enum([
|
|
|
79
102
|
'describing',
|
|
80
103
|
'merging',
|
|
81
104
|
'awaitingMerge',
|
|
105
|
+
'completed',
|
|
82
106
|
'done',
|
|
83
107
|
'stuck',
|
|
84
108
|
]);
|
|
@@ -121,7 +145,7 @@ export const runStateSchema = z.discriminatedUnion('phase', [
|
|
|
121
145
|
]),
|
|
122
146
|
}),
|
|
123
147
|
withDescription.extend({
|
|
124
|
-
phase: runPhaseSchema.extract(['merging', 'awaitingMerge', 'done', 'stuck']),
|
|
148
|
+
phase: runPhaseSchema.extract(['merging', 'awaitingMerge', 'completed', 'done', 'stuck']),
|
|
125
149
|
}),
|
|
126
150
|
]);
|
|
127
151
|
/** Every slice commits onto this one branch, so the whole feature lands as one merge. */
|
|
@@ -132,6 +156,14 @@ export function runBranchFor(runId) {
|
|
|
132
156
|
export function currentSlice(state) {
|
|
133
157
|
return slicesInOrder(state.slices).find((slice) => slice.status !== 'approved');
|
|
134
158
|
}
|
|
159
|
+
/** Whether the run merges its branch once it is described. */
|
|
160
|
+
export function runMerges(state) {
|
|
161
|
+
return state.merge;
|
|
162
|
+
}
|
|
163
|
+
/** Whether saves keep the run's code off the remote, leaving its publication to the caller. */
|
|
164
|
+
export function defersCodePublication(state) {
|
|
165
|
+
return state.codePublication === 'deferred';
|
|
166
|
+
}
|
|
135
167
|
export function runStopReason(state) {
|
|
136
168
|
const slice = stuckSlice(state);
|
|
137
169
|
if (slice)
|
|
@@ -145,3 +177,20 @@ export function runStopReason(state) {
|
|
|
145
177
|
export function stuckSlice(state) {
|
|
146
178
|
return state.slices.find((slice) => slice.status === 'stuck');
|
|
147
179
|
}
|
|
180
|
+
export function canRecoverInitialCheckpoint(state) {
|
|
181
|
+
return (state.phase === 'context' &&
|
|
182
|
+
state.slices.length === 0 &&
|
|
183
|
+
state.diagnosticSequence === 0 &&
|
|
184
|
+
[
|
|
185
|
+
state.context,
|
|
186
|
+
state.plan,
|
|
187
|
+
state.docs,
|
|
188
|
+
state.designReview,
|
|
189
|
+
state.finalCheck,
|
|
190
|
+
state.failedFinalVerification,
|
|
191
|
+
state.completionReuse,
|
|
192
|
+
state.completionReuseAuthorized,
|
|
193
|
+
state.prDescription,
|
|
194
|
+
state.blockedReason,
|
|
195
|
+
].every((evidence) => evidence === undefined));
|
|
196
|
+
}
|
package/dist/domain/slice.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { capturedOutputSchema, diagnosticOrderSchema, OUTPUT_UNAVAILABLE, rejectedReviewSchema, } from './diagnostics.js';
|
|
2
3
|
import { workObservationsSchema } from './work-facts.js';
|
|
3
4
|
/** Slice ids become lookup keys in state and log lines, so they are restricted to safe characters. */
|
|
4
5
|
export const SLICE_ID_PATTERN = /^[a-z0-9-]+$/;
|
|
@@ -15,12 +16,16 @@ export const verificationRecordSchema = z.object({
|
|
|
15
16
|
observed: workObservationsSchema.optional(),
|
|
16
17
|
});
|
|
17
18
|
/**
|
|
18
|
-
* What a slice's last failed verification ran and left behind: a failing command can
|
|
19
|
-
* work it failed on, so the facts around it are recorded for the audit.
|
|
19
|
+
* What a slice's last failed verification ran, reported and left behind: a failing command can
|
|
20
|
+
* change the work it failed on, so the facts around it are recorded for the audit. It stays after
|
|
21
|
+
* a later verification passes, marked `passedSince`; one saved before output was kept has none.
|
|
20
22
|
*/
|
|
21
23
|
export const failedVerificationSchema = z.object({
|
|
22
24
|
command: z.string().min(1),
|
|
23
25
|
observed: workObservationsSchema,
|
|
26
|
+
output: capturedOutputSchema.default(OUTPUT_UNAVAILABLE),
|
|
27
|
+
at: diagnosticOrderSchema,
|
|
28
|
+
passedSince: z.boolean().default(false),
|
|
24
29
|
});
|
|
25
30
|
export const sliceSchema = plannedSliceSchema.extend({
|
|
26
31
|
order: z.number().int().nonnegative(),
|
|
@@ -35,6 +40,7 @@ export const sliceSchema = plannedSliceSchema.extend({
|
|
|
35
40
|
commit: z.string().optional(),
|
|
36
41
|
verification: verificationRecordSchema.optional(),
|
|
37
42
|
failedVerification: failedVerificationSchema.optional(),
|
|
43
|
+
rejectedReview: rejectedReviewSchema.optional(),
|
|
38
44
|
});
|
|
39
45
|
export function sliceFromPlan(planned, order) {
|
|
40
46
|
return {
|
package/dist/flow/engine.js
CHANGED
|
@@ -3,6 +3,10 @@ import { applyOutcome, updateCurrentSlice } from '../domain/apply-outcome.js';
|
|
|
3
3
|
import { isTransient, messageOf, rootCause } from '../domain/errors.js';
|
|
4
4
|
import { retryResult, transientRetryPolicy } from '../domain/retry.js';
|
|
5
5
|
import { currentSlice, enterPhase, } from '../domain/run-state.js';
|
|
6
|
+
/** Whether an invocation that ended in `status` finished the run's work, merged or not. */
|
|
7
|
+
export function outcomeIsComplete(status) {
|
|
8
|
+
return status === 'done' || status === 'completed';
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
11
|
* Drives a run through `flow` from its saved phase until it finishes, halts, or blocks. A `fatal`
|
|
8
12
|
* failure, or one saving the run, ends the invocation as an `Err`.
|
package/dist/flow/run-flow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { designApproved, designNeedsRevision } from '../domain/design-review.js';
|
|
2
2
|
import { finalCheckFailed, finalCheckNeedsRepair } from '../domain/final-check.js';
|
|
3
|
-
import { stuckSlice } from '../domain/run-state.js';
|
|
3
|
+
import { runMerges, stuckSlice } from '../domain/run-state.js';
|
|
4
4
|
import { emptyAttemptCapReached, hookFailureCapReached, reviewCapReached, ruleFixCapReached, sliceNeedsVerification, verificationFailureCapReached, } from '../domain/settings.js';
|
|
5
5
|
import { decideCompletionReuse } from '../steps/completion-reuse.js';
|
|
6
6
|
import { resolveDesign, reviewDesign, reviseDesign } from '../steps/design-review.js';
|
|
@@ -63,10 +63,12 @@ export const sliceFlow = defineSliceFlow({
|
|
|
63
63
|
const repairStillOwed = ({ state }) => finalCheckNeedsRepair(state);
|
|
64
64
|
const someSliceStuck = ({ state }) => stuckSlice(state) !== undefined;
|
|
65
65
|
const theFinalCheckFailed = ({ state }) => finalCheckFailed(state);
|
|
66
|
+
const runSkipsMerge = ({ state }) => !runMerges(state);
|
|
66
67
|
/**
|
|
67
68
|
* A whole run: plan the work, have the design reviewed — with one revision and one re-review
|
|
68
69
|
* when the review finds problems, blocking on any left standing — then deliver it slice by
|
|
69
|
-
* slice, check the whole request is fulfilled, describe it, merge it
|
|
70
|
+
* slice, check the whole request is fulfilled, describe it, merge it — or, for a run that skips
|
|
71
|
+
* the merge, finish as `completed` with its branch left for review. A stuck slice bypasses the final check; a failed one sends its one
|
|
70
72
|
* repair back through the slices before the run is described and, still failing, stops for a
|
|
71
73
|
* person — so the feedback reaches whoever picks it up. A single-slice run whose combined review
|
|
72
74
|
* still vouches for its work finishes on that review instead of a final check; should the
|
|
@@ -111,6 +113,7 @@ export const runFlow = defineRunFlow({
|
|
|
111
113
|
described: [
|
|
112
114
|
{ to: 'stuck', when: someSliceStuck },
|
|
113
115
|
{ to: 'stuck', when: theFinalCheckFailed },
|
|
116
|
+
{ to: 'completed', when: runSkipsMerge },
|
|
114
117
|
{ to: 'merging' },
|
|
115
118
|
],
|
|
116
119
|
},
|
|
@@ -124,6 +127,7 @@ export const runFlow = defineRunFlow({
|
|
|
124
127
|
},
|
|
125
128
|
},
|
|
126
129
|
awaitingMerge: { halt: true, resumeAt: 'merging' },
|
|
130
|
+
completed: { final: 'completed' },
|
|
127
131
|
done: { final: 'done' },
|
|
128
132
|
stuck: { final: 'stuck' },
|
|
129
133
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { exitWhenDone } from '../../cli/exit-when-done.js';
|
|
5
|
+
import { buildCli } from '../../cli/main.js';
|
|
6
|
+
import { registerGithubCommands } from './command.js';
|
|
7
|
+
export function buildJigCli(io, githubFor) {
|
|
8
|
+
const program = buildCli();
|
|
9
|
+
registerGithubCommands(program, io, githubFor);
|
|
10
|
+
return program;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A globally installed CLI is invoked through a symlink, so the invoked path is resolved
|
|
14
|
+
* before comparing it with this module's own path.
|
|
15
|
+
*/
|
|
16
|
+
const isMainModule = process.argv[1] !== undefined && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
17
|
+
if (isMainModule) {
|
|
18
|
+
await buildJigCli().parseAsync(process.argv);
|
|
19
|
+
await exitWhenDone();
|
|
20
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Result } from 'better-result';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { appAction } from '../../cli/app-action.js';
|
|
4
|
+
import { configInputSchema, configOption, presetInputSchema, presetOption, } from '../../cli/config-option.js';
|
|
5
|
+
import { logFormatInputSchema, logFormatOption } from '../../cli/log-format-option.js';
|
|
6
|
+
import { GithubSetupInvalid } from './errors.js';
|
|
7
|
+
import { implementIssue } from './implement-issue.js';
|
|
8
|
+
import { OctokitGithub } from './octokit-github.js';
|
|
9
|
+
import { repositoryIdentity } from './repository-identity.js';
|
|
10
|
+
export function registerGithubCommands(program, io, githubFor = OctokitGithub.authenticated) {
|
|
11
|
+
program
|
|
12
|
+
.command('github')
|
|
13
|
+
.description('Implement GitHub issues as pull requests')
|
|
14
|
+
.command('implement')
|
|
15
|
+
.description('Implement an issue and open a pull request')
|
|
16
|
+
.option('--issue <number>', 'issue number')
|
|
17
|
+
.addOption(configOption())
|
|
18
|
+
.addOption(presetOption())
|
|
19
|
+
.addOption(logFormatOption())
|
|
20
|
+
.action(appAction(githubInputSchema, async ({ issue }, app, { token, repository }) => {
|
|
21
|
+
const result = await implementIssue(app, githubFor(token), repository, issue);
|
|
22
|
+
return result.map((outcome) => {
|
|
23
|
+
console.log(describeIssueOutcome(outcome));
|
|
24
|
+
});
|
|
25
|
+
}, io, prepare));
|
|
26
|
+
}
|
|
27
|
+
const githubInputSchema = logFormatInputSchema
|
|
28
|
+
.merge(configInputSchema)
|
|
29
|
+
.merge(presetInputSchema)
|
|
30
|
+
.extend({ issue: z.coerce.number().int().positive() });
|
|
31
|
+
export function describeIssueOutcome(outcome) {
|
|
32
|
+
if (outcome.kind === 'commented')
|
|
33
|
+
return `${outcome.outcome}: ${outcome.url}`;
|
|
34
|
+
if (outcome.kind === 'refused')
|
|
35
|
+
return `Refused, changes workflows (${outcome.paths.join(', ')}): ${outcome.url}`;
|
|
36
|
+
if (outcome.kind === 'draftPullRequest')
|
|
37
|
+
return `${outcome.reused ? 'Reused draft PR' : 'Draft PR'} (stuck): ${outcome.url}, findings: ${outcome.findingsUrl}`;
|
|
38
|
+
return `${outcome.reused ? 'Reused PR' : 'PR'}: ${outcome.url}`;
|
|
39
|
+
}
|
|
40
|
+
function prepare(_input, { cwd, environment }) {
|
|
41
|
+
return Result.gen(async function* () {
|
|
42
|
+
const parsed = githubEnvironmentSchema.safeParse(environment);
|
|
43
|
+
if (!parsed.success)
|
|
44
|
+
return Result.err(new GithubSetupInvalid({
|
|
45
|
+
message: parsed.error.issues.map(({ message }) => message).join('; '),
|
|
46
|
+
}));
|
|
47
|
+
const { token, ...identity } = parsed.data;
|
|
48
|
+
const repository = yield* Result.await(repositoryIdentity(cwd, identity));
|
|
49
|
+
return Result.ok({ token, repository });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const githubEnvironmentSchema = z
|
|
53
|
+
.object({
|
|
54
|
+
GITHUB_TOKEN: z.string().min(1).optional(),
|
|
55
|
+
GH_TOKEN: z.string().min(1).optional(),
|
|
56
|
+
GITHUB_REPOSITORY: z.string().optional(),
|
|
57
|
+
})
|
|
58
|
+
.transform(({ GITHUB_TOKEN, GH_TOKEN, GITHUB_REPOSITORY }, context) => {
|
|
59
|
+
const token = GITHUB_TOKEN ?? GH_TOKEN;
|
|
60
|
+
if (!token) {
|
|
61
|
+
context.addIssue({
|
|
62
|
+
code: z.ZodIssueCode.custom,
|
|
63
|
+
message: 'Set GITHUB_TOKEN or GH_TOKEN to implement a GitHub issue.',
|
|
64
|
+
});
|
|
65
|
+
return z.NEVER;
|
|
66
|
+
}
|
|
67
|
+
return { token, GITHUB_REPOSITORY };
|
|
68
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TaggedError } from 'better-result';
|
|
2
|
+
export class GithubUnavailable extends TaggedError('GithubUnavailable') {
|
|
3
|
+
}
|
|
4
|
+
export class GithubRefused extends TaggedError('GithubRefused') {
|
|
5
|
+
}
|
|
6
|
+
export class GithubNotFound extends TaggedError('GithubNotFound') {
|
|
7
|
+
}
|
|
8
|
+
export class GithubSetupInvalid extends TaggedError('GithubSetupInvalid') {
|
|
9
|
+
}
|
|
10
|
+
export class BaseBranchMismatch extends TaggedError('BaseBranchMismatch') {
|
|
11
|
+
}
|
|
12
|
+
export class OrchestrationStateInvalid extends TaggedError('OrchestrationStateInvalid') {
|
|
13
|
+
}
|
|
14
|
+
/** Another job holds the lease to publish the same accepted request. */
|
|
15
|
+
export class PublicationInProgress extends TaggedError('PublicationInProgress') {
|
|
16
|
+
}
|
|
17
|
+
/** The run branch could not be inspected, or moved away from what was inspected, so nothing was pushed. */
|
|
18
|
+
export class RunBranchUnpublishable extends TaggedError('RunBranchUnpublishable') {
|
|
19
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { runDiagnostics, } from '../../domain/diagnostics.js';
|
|
2
|
+
import { runStopReason } from '../../domain/run-state.js';
|
|
3
|
+
/**
|
|
4
|
+
* The single PR-level comment a draft PR carries: why the run stopped and what is still
|
|
5
|
+
* unresolved, with command output kept verbatim so the file and line references in it survive.
|
|
6
|
+
*/
|
|
7
|
+
export function findingsCommentBody(state, revision) {
|
|
8
|
+
const diagnostics = runDiagnostics(state);
|
|
9
|
+
return [
|
|
10
|
+
`Run ${state.runId} stopped as ${state.phase} at ${revision}: ${stuckReason(state)}`,
|
|
11
|
+
...unresolvedReviewSections(diagnostics),
|
|
12
|
+
...outstandingGapSection(diagnostics),
|
|
13
|
+
...verificationFailureSection(diagnostics.lastVerificationFailure),
|
|
14
|
+
].join('\n\n');
|
|
15
|
+
}
|
|
16
|
+
/** Why a stuck run stopped, for a run saved before the reason could be told. */
|
|
17
|
+
export function stuckReason(state) {
|
|
18
|
+
return runStopReason(state) ?? 'The run exhausted its attempts.';
|
|
19
|
+
}
|
|
20
|
+
function unresolvedReviewSections({ unresolvedReviews }) {
|
|
21
|
+
return unresolvedReviews.map(({ sliceId, feedback }) => `### Unresolved review of slice \`${sliceId}\`\n\n${feedback}`);
|
|
22
|
+
}
|
|
23
|
+
function outstandingGapSection({ outstandingGaps }) {
|
|
24
|
+
if (outstandingGaps.length === 0)
|
|
25
|
+
return [];
|
|
26
|
+
return [`### Outstanding gaps\n\n${outstandingGaps.map((gap) => `- ${gap}`).join('\n')}`];
|
|
27
|
+
}
|
|
28
|
+
function verificationFailureSection(failure) {
|
|
29
|
+
if (!failure)
|
|
30
|
+
return [];
|
|
31
|
+
const status = failure.current ? 'still failing' : 'passed since';
|
|
32
|
+
const command = failure.command ? `\`${failure.command}\`` : 'The verify command';
|
|
33
|
+
return [
|
|
34
|
+
`### Last verification failure (${status})\n\n${command} failed in ${scopeOf(failure)}.\n\n${outputOf(failure.output)}`,
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
function scopeOf({ scope }) {
|
|
38
|
+
return scope.kind === 'slice'
|
|
39
|
+
? `slice \`${scope.sliceId}\``
|
|
40
|
+
: `round ${scope.round} of the final check`;
|
|
41
|
+
}
|
|
42
|
+
function outputOf(output) {
|
|
43
|
+
if (!output.captured)
|
|
44
|
+
return 'Its output was not kept by the version of jig that ran it.';
|
|
45
|
+
const lead = output.truncated ? 'The end of its output:' : 'Its output:';
|
|
46
|
+
return `${lead}\n\n${fenced(output.tail)}`;
|
|
47
|
+
}
|
|
48
|
+
/** Fences `text` with more backticks than any run inside it, so the output cannot close the block. */
|
|
49
|
+
function fenced(text) {
|
|
50
|
+
const longestRun = Math.max(0, ...Array.from(text.matchAll(/`+/g), ([run]) => run.length));
|
|
51
|
+
const fence = '`'.repeat(Math.max(3, longestRun + 1));
|
|
52
|
+
return `${fence}text\n${text}\n${fence}`;
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|