@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.
Files changed (41) hide show
  1. package/README.md +16 -0
  2. package/dist/adapters/git/remote-ref.js +125 -0
  3. package/dist/adapters/git/run-code.js +66 -0
  4. package/dist/adapters/git/run-history.js +79 -0
  5. package/dist/adapters/local-store/run-artefacts.js +2 -1
  6. package/dist/adapters/run-store/composite-run-store.js +68 -14
  7. package/dist/adapters/run-store/git-remote-run-store.js +34 -129
  8. package/dist/app/run-jig.js +28 -7
  9. package/dist/app/run-stores.js +4 -3
  10. package/dist/cli/commands/run.js +20 -7
  11. package/dist/cli/commands/status.js +3 -0
  12. package/dist/cli/main.js +3 -15
  13. package/dist/domain/apply-outcome.js +30 -13
  14. package/dist/domain/diagnostics.js +104 -0
  15. package/dist/domain/errors.js +8 -0
  16. package/dist/domain/final-check.js +21 -1
  17. package/dist/domain/run-id.js +4 -1
  18. package/dist/domain/run-state.js +51 -2
  19. package/dist/domain/slice.js +8 -2
  20. package/dist/flow/engine.js +4 -0
  21. package/dist/flow/run-flow.js +6 -2
  22. package/dist/integrations/github/cli.js +20 -0
  23. package/dist/integrations/github/command.js +68 -0
  24. package/dist/integrations/github/errors.js +19 -0
  25. package/dist/integrations/github/findings-comment.js +53 -0
  26. package/dist/integrations/github/github-port.js +1 -0
  27. package/dist/integrations/github/implement-issue.js +281 -0
  28. package/dist/integrations/github/octokit-github.js +101 -0
  29. package/dist/integrations/github/orchestration-state.js +132 -0
  30. package/dist/integrations/github/orchestration-store.js +109 -0
  31. package/dist/integrations/github/repository-identity.js +27 -0
  32. package/dist/integrations/github/request-snapshot.js +3 -0
  33. package/dist/integrations/github/run-branch-publication.js +102 -0
  34. package/dist/ports/run-code.js +1 -0
  35. package/dist/prompts/design-review.js +2 -0
  36. package/dist/prompts/planning.js +5 -1
  37. package/dist/prompts/pull-request.js +4 -1
  38. package/dist/prompts/slice.js +11 -0
  39. package/dist/steps/pull-request-description.js +1 -1
  40. package/dist/steps/slice.js +1 -0
  41. package/package.json +5 -4
@@ -0,0 +1,102 @@
1
+ import { Result } from 'better-result';
2
+ import { RemoteRef } from '../../adapters/git/remote-ref.js';
3
+ import { isAncestor } from '../../adapters/git/repository.js';
4
+ import { changedPaths, commitsBeyond, exactHead, hasCommit, mergeBaseWith, } from '../../adapters/git/run-history.js';
5
+ import { runBranchFor } from '../../domain/run-state.js';
6
+ import { RunBranchUnpublishable } from './errors.js';
7
+ /**
8
+ * The only way an issue run's code reaches the remote. It inspects exactly `revision`, refuses it
9
+ * when it changes a workflow, skips it when it changes nothing unless `pushUnchanged` asks for its
10
+ * commits anyway, and otherwise pushes that object ID under a lease on the remote branch. Any
11
+ * failure to inspect publishes nothing.
12
+ */
13
+ export function publishRunBranch(repoRoot, { pushUnchanged = false, ...inspected }) {
14
+ return Result.gen(async function* () {
15
+ const { runId, revision } = inspected;
16
+ const head = yield* Result.await(exactHead(repoRoot, branchRef(runId)));
17
+ if (head !== revision)
18
+ return Result.err(new RunBranchUnpublishable({
19
+ message: `Run branch ${runBranchFor(runId)} is at ${head ?? 'nothing'}, not the checkpoint ${revision} its state records; move it back to the checkpoint or start a new run.`,
20
+ }));
21
+ const inspection = yield* Result.await(inspectRunBranch(repoRoot, inspected));
22
+ if (inspection.kind === 'refused')
23
+ return Result.ok(inspection);
24
+ const { changesFiles } = inspection;
25
+ if (!changesFiles && !pushUnchanged)
26
+ return Result.ok({ kind: 'unchanged' });
27
+ yield* Result.await(pushLeased(repoRoot, new RemoteRef(repoRoot), runId, revision));
28
+ return Result.ok({ kind: 'published', changesFiles });
29
+ });
30
+ }
31
+ function branchRef(runId) {
32
+ return `refs/heads/${runBranchFor(runId)}`;
33
+ }
34
+ /**
35
+ * Publication and receipt reuse must not bypass workflow refusal: a prior receipt does not prove
36
+ * that the run's code is safe to publish.
37
+ */
38
+ export function inspectRunBranch(repoRoot, { runId, revision, defaultBranch }) {
39
+ return Result.gen(async function* () {
40
+ const defaultHead = yield* Result.await(fetchedHead(new RemoteRef(repoRoot), defaultBranch));
41
+ const forkPoint = yield* Result.await(mergeBaseWith(repoRoot, defaultHead, revision));
42
+ if (!forkPoint)
43
+ return Result.err(new RunBranchUnpublishable({
44
+ message: `Run branch ${runBranchFor(runId)} shares no history with ${defaultBranch}.`,
45
+ }));
46
+ const paths = yield* Result.await(changedPaths(repoRoot, forkPoint, revision));
47
+ const workflows = paths.filter(isWorkflowPath);
48
+ if (workflows.length > 0)
49
+ return Result.ok({ kind: 'refused', paths: workflows });
50
+ return Result.ok({ kind: 'clean', changesFiles: paths.length > 0 });
51
+ });
52
+ }
53
+ function fetchedHead(refs, branch) {
54
+ return Result.gen(async function* () {
55
+ const ref = `refs/heads/${branch}`;
56
+ const listed = yield* Result.await(refs.list([ref]));
57
+ const head = listed.get(ref);
58
+ if (!head)
59
+ return Result.err(new RunBranchUnpublishable({ message: `Default branch ${branch} is missing on origin.` }));
60
+ yield* Result.await(refs.fetch([`+${ref}:refs/remotes/origin/${branch}`]));
61
+ return Result.ok(head);
62
+ });
63
+ }
64
+ function isWorkflowPath(path) {
65
+ return path.startsWith(WORKFLOW_DIRECTORY);
66
+ }
67
+ /** GitHub runs workflows from this directory only; a pushed branch would let them run unreviewed. */
68
+ const WORKFLOW_DIRECTORY = '.github/workflows/';
69
+ /** Pushes `revision` only over what the remote branch holds now, and only as a fast-forward of it. */
70
+ function pushLeased(repoRoot, refs, runId, revision) {
71
+ return Result.gen(async function* () {
72
+ const ref = branchRef(runId);
73
+ const listed = yield* Result.await(refs.list([ref]));
74
+ const published = listed.get(ref);
75
+ if (published === revision)
76
+ return Result.ok();
77
+ if (published)
78
+ yield* Result.await(ensureFastForward(repoRoot, refs, runId, published, revision));
79
+ return refs.pushLeased([{ ref, source: revision, expected: published }]);
80
+ });
81
+ }
82
+ function ensureFastForward(repoRoot, refs, runId, published, revision) {
83
+ return Result.gen(async function* () {
84
+ if (!(yield* Result.await(hasCommit(repoRoot, published))))
85
+ yield* Result.await(refs.fetch([`+${branchRef(runId)}:refs/remotes/origin/${runBranchFor(runId)}`]));
86
+ if (yield* Result.await(isAncestor(repoRoot, published, revision)))
87
+ return Result.ok();
88
+ return Result.err(new RunBranchUnpublishable({
89
+ message: `Run branch ${runBranchFor(runId)} on origin moved to ${published}, which ${revision} does not build on; nothing was pushed.`,
90
+ }));
91
+ });
92
+ }
93
+ /**
94
+ * Whether a stuck run committed anything past where it started. A run saved before its starting
95
+ * commit was recorded has no known start, so it is never taken to have work.
96
+ */
97
+ export async function hasWorkBeyondStart(repoRoot, { startingCommit, codeRevision }) {
98
+ if (!startingCommit || !codeRevision)
99
+ return Result.ok(false);
100
+ const commits = await commitsBeyond(repoRoot, startingCommit, codeRevision);
101
+ return commits.map((beyond) => beyond.length > 0);
102
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -42,6 +42,8 @@ function documentsSection(label, docs) {
42
42
  function reviewRules() {
43
43
  return [
44
44
  'Explore the repository as much as you need to check the documents against it.',
45
+ 'Check that the design maps each requested behaviour to the module that owns it in this',
46
+ 'repository. Raise a consequential mismatch with a concrete failure scenario and evidence.',
45
47
  '',
46
48
  'Raise a finding only for a consequential decision: one that, wrong or missing, would',
47
49
  'materially change behaviour the request requires, violate a constraint of this repository',
@@ -25,7 +25,9 @@ export function featurePlanPrompt(request, repoSummary) {
25
25
  repoSummary,
26
26
  '',
27
27
  'Produce a plan: a summary of what will change, the overall approach, and the list of',
28
- 'affected areas of the codebase.',
28
+ "affected areas of the codebase. Compare the request's intended architecture with the",
29
+ 'existing module boundaries and ownership. Name any mismatch in the approach so the design',
30
+ 'step can resolve it before implementation.',
29
31
  '',
30
32
  'Respond with JSON matching: { "summary": string, "approach": string, "affectedAreas": string[] }.',
31
33
  ].join('\n');
@@ -51,6 +53,8 @@ export function designPrompt(request, repoSummary, plan) {
51
53
  'Write two markdown documents. Do not create any files — return them in your response:',
52
54
  '1. "design" with sections: Goal; Context; Chosen approach; Alternatives considered (each',
53
55
  ' with why it was rejected); Assumptions; Non-goals; Affected areas.',
56
+ ' In Context, map requested behaviour to the modules and rules that own it today.',
57
+ ' Explain any mismatch with the requested architecture in Chosen approach.',
54
58
  '2. "plan" — the overall implementation plan as numbered steps, each under a',
55
59
  ' `## Step N — <title>` heading. Steps describe the work, not slice boundaries:',
56
60
  ' related steps may belong to one slice. Keep a coherent feature or refactor together',
@@ -28,7 +28,10 @@ export function pullRequestPrompt(input) {
28
28
  ' HTML comments with real content.',
29
29
  '- Write the sections that describe the result and the motivation in plain words for',
30
30
  ' someone who has not seen the code: no file paths, identifiers or technical terms.',
31
- '- Keep "how" or approach sections to a few lines on the approach and notable decisions.',
31
+ '- Keep "how" or approach sections short. When a flow changed, show concise before/after',
32
+ ' pseudocode of the decision or sequence. Explain in plain words what the new flow does',
33
+ ' differently, when that difference matters, and why it was chosen. Base both versions',
34
+ ' on the actual code; skip pseudocode when it adds no clarity.',
32
35
  ...verificationRule(verifyCommand),
33
36
  '- The final-check section records what the whole-run final check decided: state that',
34
37
  ' record as fact too. Put everything it reports unmet in the section for deviations.',
@@ -10,6 +10,8 @@ export function implementPrompt(slice, verifyCommand) {
10
10
  ...houseRulesFirst(),
11
11
  '',
12
12
  'Make the necessary code changes in this repository to complete this slice.',
13
+ 'Preserve lint, test and verification settings. Change them only when this slice explicitly',
14
+ 'requires the change; never relax a check to make the implementation pass.',
13
15
  'Do not rebase, amend or otherwise rewrite the commits already on this branch.',
14
16
  '',
15
17
  ...checkAgainstHouseRulesLast(),
@@ -33,6 +35,10 @@ function previousFeedback(slice) {
33
35
  'A previous attempt at this slice was sent back with changes requested, by its review or by a failed check.',
34
36
  'Address this feedback specifically:',
35
37
  slice.lastFeedback,
38
+ 'If a requested change is wrong or outside this slice, check the relevant code and request',
39
+ 'before disputing it. Record the evidence in your commit message body so the reviewer can',
40
+ 'verify it from the commit history.',
41
+ 'Do not leave a supported finding unresolved because you disagree with its wording.',
36
42
  ...earlierRounds(slice),
37
43
  ];
38
44
  }
@@ -171,6 +177,11 @@ function sliceReviewSections(slice, range, protectedChanges) {
171
177
  'the most serious: each rejection costs the slice one of a few attempts, so a problem you',
172
178
  'leave for the next round may be the one it runs out on. On a later round, check the whole',
173
179
  'range again, not only what the last feedback named.',
180
+ 'For a missing edge case, name the reachable input or state, the wrong result, and why',
181
+ 'existing checks do not cover it. Do not request coverage for a speculative case that',
182
+ 'the slice cannot reach.',
183
+ "If an earlier finding was disputed, check the implementer's evidence against the code.",
184
+ 'Drop the finding when that evidence holds; otherwise explain the remaining failure case.',
174
185
  ];
175
186
  }
176
187
  function protectedChangesSection(changes) {
@@ -13,7 +13,7 @@ export const DEFAULT_PR_TEMPLATE = [
13
13
  '',
14
14
  '## How',
15
15
  '',
16
- '<!-- For reviewers: the approach and the notable decisions, a few lines. -->',
16
+ '<!-- For reviewers: show a short before/after flow in pseudocode when behaviour changed. Explain what differs, when it matters, and why. -->',
17
17
  '',
18
18
  '## Verification',
19
19
  '',
@@ -141,6 +141,7 @@ export const verifySlice = ({ settings, ports }) => {
141
141
  type: 'verificationFailed',
142
142
  feedback: verifyFailedFeedback(command, output),
143
143
  command,
144
+ output,
144
145
  observed,
145
146
  });
146
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ygrishajev/jig",
3
- "version": "1.0.5",
3
+ "version": "1.2.0",
4
4
  "description": "Agentic SDLC pipeline orchestrator",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,9 +8,9 @@
8
8
  "node": ">=20.17"
9
9
  },
10
10
  "bin": {
11
- "jig": "./dist/cli/main.js"
11
+ "jig": "./dist/integrations/github/cli.js"
12
12
  },
13
- "main": "./dist/cli/main.js",
13
+ "main": "./dist/integrations/github/cli.js",
14
14
  "files": [
15
15
  "dist",
16
16
  "presets"
@@ -27,7 +27,7 @@
27
27
  "validate": "node --import tsx scripts/validate.ts",
28
28
  "build": "tsc -p tsconfig.build.json",
29
29
  "install:local": "npm run build && T=$(npm pack --silent | tail -1) && trap 'rm -f \"$T\"' EXIT && env -u _VOLTA_TOOL_RECURSION \"${VOLTA_HOME:+$VOLTA_HOME/bin/}npm\" i -g \"$PWD/$T\"",
30
- "dev": "tsx src/cli/main.ts",
30
+ "dev": "tsx src/integrations/github/cli.ts",
31
31
  "lint": "eslint .",
32
32
  "lint:duplication": "jscpd",
33
33
  "format": "prettier --write .",
@@ -44,6 +44,7 @@
44
44
  "dependencies": {
45
45
  "@ai-hero/sandcastle": "^0.14.0",
46
46
  "@inquirer/prompts": "^8.7.5",
47
+ "@octokit/rest": "^22.0.1",
47
48
  "@opentelemetry/api": "^1.9.1",
48
49
  "@opentelemetry/exporter-trace-otlp-http": "^0.223.0",
49
50
  "@opentelemetry/sdk-node": "^0.223.0",