@ygrishajev/jig 1.0.5 → 1.1.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/dist/adapters/local-store/run-artefacts.js +2 -1
- package/dist/app/run-jig.js +5 -5
- package/dist/cli/commands/run.js +20 -7
- package/dist/cli/commands/status.js +3 -0
- package/dist/domain/run-state.js +9 -2
- package/dist/flow/engine.js +4 -0
- package/dist/flow/run-flow.js +6 -2
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import writeFileAtomic from 'write-file-atomic';
|
|
5
5
|
import { designReviewReport } from '../../domain/design-review-report.js';
|
|
6
6
|
import { runStopReason } from '../../domain/run-state.js';
|
|
7
|
+
import { outcomeIsComplete } from '../../flow/engine.js';
|
|
7
8
|
import { formatSummary } from '../../observers/metrics.js';
|
|
8
9
|
import { onLocalState } from './local-state.js';
|
|
9
10
|
import { makeRunDirectory, stateDirectory } from './run-paths.js';
|
|
@@ -53,7 +54,7 @@ function resultFor(state, status, metrics) {
|
|
|
53
54
|
runId: state.runId,
|
|
54
55
|
status,
|
|
55
56
|
phase: state.phase,
|
|
56
|
-
complete: status
|
|
57
|
+
complete: outcomeIsComplete(status),
|
|
57
58
|
blockedReason: state.blockedReason ?? runStopReason(state),
|
|
58
59
|
metrics,
|
|
59
60
|
};
|
package/dist/app/run-jig.js
CHANGED
|
@@ -35,7 +35,7 @@ function targetOf(input) {
|
|
|
35
35
|
if ('resume' in input)
|
|
36
36
|
return { runId: input.resume };
|
|
37
37
|
const { start } = input;
|
|
38
|
-
return { request: start.text, runId: input.runId ?? newRunId(start) };
|
|
38
|
+
return { request: start.text, merge: start.merge, runId: input.runId ?? newRunId(start) };
|
|
39
39
|
}
|
|
40
40
|
function runLocked(app, target) {
|
|
41
41
|
return Result.gen(async function* () {
|
|
@@ -51,7 +51,7 @@ function runLocked(app, target) {
|
|
|
51
51
|
return Result.ok(report);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
async function startOrResume(cradle, store, { runId, request }) {
|
|
54
|
+
async function startOrResume(cradle, store, { runId, request, merge }) {
|
|
55
55
|
const existing = await store.load(runId);
|
|
56
56
|
if (existing.isErr())
|
|
57
57
|
return Result.err(existing.error);
|
|
@@ -61,7 +61,7 @@ async function startOrResume(cradle, store, { runId, request }) {
|
|
|
61
61
|
: Result.err(new RunRequestInvalid({ message: `No run found with id "${runId}".` }));
|
|
62
62
|
}
|
|
63
63
|
if (!existing.value)
|
|
64
|
-
return startNewRun(cradle, store, runId, request);
|
|
64
|
+
return startNewRun(cradle, store, { runId, request, merge });
|
|
65
65
|
if (request !== existing.value.request) {
|
|
66
66
|
return Result.err(new RunRequestInvalid({
|
|
67
67
|
message: `Run "${runId}" was started from a different request — pass a new --id to start a new run.`,
|
|
@@ -69,11 +69,11 @@ async function startOrResume(cradle, store, { runId, request }) {
|
|
|
69
69
|
}
|
|
70
70
|
return Result.ok(existing.value);
|
|
71
71
|
}
|
|
72
|
-
async function startNewRun(cradle, store, runId, request) {
|
|
72
|
+
async function startNewRun(cradle, store, { runId, request, merge }) {
|
|
73
73
|
const baseBranch = await getCurrentBranch(cradle.repoRoot);
|
|
74
74
|
if (baseBranch.isErr())
|
|
75
75
|
return Result.err(baseBranch.error);
|
|
76
|
-
const started = startRun({ runId, baseBranch: baseBranch.value, request });
|
|
76
|
+
const started = startRun({ runId, baseBranch: baseBranch.value, request, merge });
|
|
77
77
|
const saved = await store.save(started);
|
|
78
78
|
return saved.isErr() ? Result.err(saved.error) : Result.ok(started);
|
|
79
79
|
}
|
package/dist/cli/commands/run.js
CHANGED
|
@@ -13,6 +13,7 @@ export function registerRunCommand(program, io) {
|
|
|
13
13
|
.description('Start a run from a request file (or - for standard input), or resume one with --id')
|
|
14
14
|
.argument('[request]', 'markdown file describing what to build, or - to read it from standard input')
|
|
15
15
|
.option('--id <id>', 'run id: resumes that run if it exists, otherwise names the new one')
|
|
16
|
+
.option('--no-merge', 'describe the result and stop without merging; the run ends "completed" (ignored when resuming an existing run)')
|
|
16
17
|
.addOption(configOption())
|
|
17
18
|
.addOption(presetOption())
|
|
18
19
|
.addOption(logFormatOption())
|
|
@@ -33,9 +34,13 @@ const STANDARD_INPUT_ARGUMENT = '-';
|
|
|
33
34
|
export const runInputSchema = logFormatInputSchema
|
|
34
35
|
.merge(configInputSchema)
|
|
35
36
|
.merge(presetInputSchema)
|
|
36
|
-
.extend({
|
|
37
|
-
.
|
|
38
|
-
|
|
37
|
+
.extend({
|
|
38
|
+
request: z.string().optional(),
|
|
39
|
+
id: runIdSchema.optional(),
|
|
40
|
+
merge: z.boolean().default(true),
|
|
41
|
+
})
|
|
42
|
+
.transform(({ request, id, merge, ...options }, context) => {
|
|
43
|
+
const run = runToDo(request, id, merge);
|
|
39
44
|
if (run)
|
|
40
45
|
return { run, ...options };
|
|
41
46
|
context.addIssue({
|
|
@@ -44,10 +49,10 @@ export const runInputSchema = logFormatInputSchema
|
|
|
44
49
|
});
|
|
45
50
|
return z.NEVER;
|
|
46
51
|
});
|
|
47
|
-
function runToDo(request, id) {
|
|
52
|
+
function runToDo(request, id, merge) {
|
|
48
53
|
if (request !== undefined) {
|
|
49
54
|
const start = request === STANDARD_INPUT_ARGUMENT ? { stdin: true } : { file: request };
|
|
50
|
-
return id ? { start, runId: id } : { start };
|
|
55
|
+
return id ? { start, runId: id, merge } : { start, merge };
|
|
51
56
|
}
|
|
52
57
|
if (id)
|
|
53
58
|
return { resume: id };
|
|
@@ -59,6 +64,8 @@ export function nextStep(report) {
|
|
|
59
64
|
switch (report.status) {
|
|
60
65
|
case 'done':
|
|
61
66
|
return 'Run complete.';
|
|
67
|
+
case 'completed':
|
|
68
|
+
return `Run finished without merging — review and merge "${runBranchFor(state.runId)}" yourself (its pull request description is in ${prDescriptionPath(state)}).`;
|
|
62
69
|
case 'halted':
|
|
63
70
|
return state.phase === 'paused'
|
|
64
71
|
? `Planning done — review the design and plan, then resume with: jig run --id ${state.runId}`
|
|
@@ -69,14 +76,20 @@ export function nextStep(report) {
|
|
|
69
76
|
return stuckMessage(state);
|
|
70
77
|
}
|
|
71
78
|
}
|
|
79
|
+
function prDescriptionPath(state) {
|
|
80
|
+
return `.jig/${state.runId}/state/PR_DESCRIPTION.md`;
|
|
81
|
+
}
|
|
72
82
|
function stuckMessage(state) {
|
|
73
83
|
return (`Stuck: ${runStopReason(state) ?? 'the run exhausted its attempts'}, so jig has ended this run and will not resume it. ` +
|
|
74
|
-
`Finish that slice and the rest by hand on "${runBranchFor(state.runId)}" (its pull request description is in
|
|
84
|
+
`Finish that slice and the rest by hand on "${runBranchFor(state.runId)}" (its pull request description is in ${prDescriptionPath(state)}), ` +
|
|
75
85
|
`or start a new run with a sharper request. The failure feedback: jig status ${state.runId}`);
|
|
76
86
|
}
|
|
77
87
|
async function prepareRun({ run }, { cwd, standardInput }) {
|
|
78
88
|
if ('resume' in run)
|
|
79
89
|
return Result.ok(run);
|
|
80
90
|
const start = await readRequest(run.start, { cwd, standardInput });
|
|
81
|
-
return start.map((request) =>
|
|
91
|
+
return start.map((request) => {
|
|
92
|
+
const started = { ...request, merge: run.merge };
|
|
93
|
+
return run.runId ? { start: started, runId: run.runId } : { start: started };
|
|
94
|
+
});
|
|
82
95
|
}
|
|
@@ -33,6 +33,9 @@ export function describeRun({ state, documents, metrics }) {
|
|
|
33
33
|
return [
|
|
34
34
|
`Run ${state.runId} — ${state.phase} (base: ${state.baseBranch})`,
|
|
35
35
|
...(state.blockedReason ? [`Blocked: ${state.blockedReason}`] : []),
|
|
36
|
+
...(state.phase === 'completed'
|
|
37
|
+
? [`Finished without merging — "${runBranchFor(state.runId)}" is ready for review.`]
|
|
38
|
+
: []),
|
|
36
39
|
`${'branch'.padEnd(18)} ${runBranchFor(state.runId)}`,
|
|
37
40
|
...documents.map((document) => `${document.name.padEnd(18)} ${document.path}`),
|
|
38
41
|
...(slices.length > 0 ? ['Slices:', ...slices] : []),
|
package/dist/domain/run-state.js
CHANGED
|
@@ -8,7 +8,7 @@ import { runIdSchema } from './run-id.js';
|
|
|
8
8
|
import { sliceStopReason } from './settings.js';
|
|
9
9
|
import { sliceSchema, slicesInOrder } from './slice.js';
|
|
10
10
|
export function startRun(input) {
|
|
11
|
-
return { ...input, revision: 0, phase: 'context', slices: [] };
|
|
11
|
+
return { ...input, merge: input.merge ?? true, revision: 0, phase: 'context', slices: [] };
|
|
12
12
|
}
|
|
13
13
|
/** Moves a run into `phase`, checking it carries everything `phase` guarantees. */
|
|
14
14
|
export function enterPhase(state, phase) {
|
|
@@ -43,6 +43,8 @@ const runFields = z.object({
|
|
|
43
43
|
revision: z.number().int().nonnegative().default(0),
|
|
44
44
|
baseBranch: z.string().min(1),
|
|
45
45
|
request: z.string(),
|
|
46
|
+
/** Whether the run merges its branch when it finishes; a run saved before the choice existed merges. */
|
|
47
|
+
merge: z.boolean().default(true),
|
|
46
48
|
context: runContextSchema.optional(),
|
|
47
49
|
plan: featurePlanSchema.optional(),
|
|
48
50
|
docs: designDocsSchema.optional(),
|
|
@@ -79,6 +81,7 @@ export const runPhaseSchema = z.enum([
|
|
|
79
81
|
'describing',
|
|
80
82
|
'merging',
|
|
81
83
|
'awaitingMerge',
|
|
84
|
+
'completed',
|
|
82
85
|
'done',
|
|
83
86
|
'stuck',
|
|
84
87
|
]);
|
|
@@ -121,7 +124,7 @@ export const runStateSchema = z.discriminatedUnion('phase', [
|
|
|
121
124
|
]),
|
|
122
125
|
}),
|
|
123
126
|
withDescription.extend({
|
|
124
|
-
phase: runPhaseSchema.extract(['merging', 'awaitingMerge', 'done', 'stuck']),
|
|
127
|
+
phase: runPhaseSchema.extract(['merging', 'awaitingMerge', 'completed', 'done', 'stuck']),
|
|
125
128
|
}),
|
|
126
129
|
]);
|
|
127
130
|
/** Every slice commits onto this one branch, so the whole feature lands as one merge. */
|
|
@@ -132,6 +135,10 @@ export function runBranchFor(runId) {
|
|
|
132
135
|
export function currentSlice(state) {
|
|
133
136
|
return slicesInOrder(state.slices).find((slice) => slice.status !== 'approved');
|
|
134
137
|
}
|
|
138
|
+
/** Whether the run merges its branch once it is described. */
|
|
139
|
+
export function runMerges(state) {
|
|
140
|
+
return state.merge;
|
|
141
|
+
}
|
|
135
142
|
export function runStopReason(state) {
|
|
136
143
|
const slice = stuckSlice(state);
|
|
137
144
|
if (slice)
|
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
|
});
|