@oakgreencc/graft 0.2.21 → 0.2.22
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/package.json +1 -1
- package/skills/graft/SKILL.md +1 -1
- package/src/cli/publish.mjs +22 -0
- package/src/gates/scope.mjs +4 -4
- package/src/gates/stacked-base.mjs +35 -0
- package/src/maintainer.mjs +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oakgreencc/graft",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.22",
|
|
4
4
|
"description": "Let an agent work a GitHub project without the local git CLI's write path: Verified commits created by a GitHub App, the repo's git hooks run at the right moments, CODEOWNERS as the manifest of what needs a human, and a scoped maintainer mode for when one says yes.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
package/skills/graft/SKILL.md
CHANGED
|
@@ -17,7 +17,7 @@ Every verb takes `-C <dir>` and `--repo <owner/repo>` (default: the `origin` rem
|
|
|
17
17
|
|
|
18
18
|
## Publishing work
|
|
19
19
|
|
|
20
|
-
1. **Branch.** Pick a fresh branch name (`agent/<topic>`). The base comes from `.graft.json` `baseBranch`, else the repo's default branch; `--base <b>`
|
|
20
|
+
1. **Branch.** Pick a fresh branch name (`agent/<topic>`). The base comes from `.graft.json` `baseBranch`, else the repo's default branch; `--base <b>` picks another base, but only one in `mergeableBases`: graft refuses to cut a branch from, or open a PR against, any other (stacked PRs cannot land). Staged work is two issues, the second blocked by the first.
|
|
21
21
|
2. **Validate.** `graft validate` runs the project's check and records the base it was green on. Done when it exits 0.
|
|
22
22
|
3. **Publish.** Uncommitted changes in the worktree → one Verified commit:
|
|
23
23
|
|
package/src/cli/publish.mjs
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* 1. scope --paths or --all, named — before any credential is read
|
|
9
9
|
* 2. no-verify skipping the repo's hooks needs a `no-verify` grant
|
|
10
10
|
* 3. validated base the green you are relying on is about THIS base
|
|
11
|
+
* 3b. stacked base a new branch or PR only on a base agents may merge into
|
|
12
|
+
* (gates/stacked-base.mjs); a `merge` grant lifts it
|
|
11
13
|
* 4. the tree built locally; the pre-commit hook runs here, and what it
|
|
12
14
|
* stages ships
|
|
13
15
|
* 5. the candidate protection → displacement → payload, judged on the tree
|
|
@@ -25,9 +27,11 @@
|
|
|
25
27
|
import { readFileSync } from 'node:fs'
|
|
26
28
|
import { resolve } from 'node:path'
|
|
27
29
|
import { withClosingTrailers } from '../closing-refs.mjs'
|
|
30
|
+
import { mergeableBases } from '../config.mjs'
|
|
28
31
|
import { flag, has, positionals } from '../context.mjs'
|
|
29
32
|
import { PublishError } from '../errors.mjs'
|
|
30
33
|
import { BOTH_SCOPES_MESSAGE, noPrNote, sweepMessage } from '../gates/scope.mjs'
|
|
34
|
+
import { stackedBaseRefusal } from '../gates/stacked-base.mjs'
|
|
31
35
|
import { checkValidatedBase, readReceipt } from '../gates/validated-base.mjs'
|
|
32
36
|
import { hookRunner } from '../git-hooks.mjs'
|
|
33
37
|
import { allows, grantAdvice } from '../maintainer.mjs'
|
|
@@ -96,6 +100,23 @@ function noVerifyGate({ ctx, argv }) {
|
|
|
96
100
|
return true
|
|
97
101
|
}
|
|
98
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Stacked-base gate. See gates/stacked-base.mjs. A `merge` grant lifts it: the PR it makes needs that grant to
|
|
105
|
+
* merge anyway.
|
|
106
|
+
*/
|
|
107
|
+
async function stackedBaseGate({ ctx, base, newBranch, newPr }) {
|
|
108
|
+
const refusal = stackedBaseRefusal({
|
|
109
|
+
base,
|
|
110
|
+
allowedBases: mergeableBases(ctx.config, await ctx.baseBranch()),
|
|
111
|
+
newBranch,
|
|
112
|
+
newPr,
|
|
113
|
+
})
|
|
114
|
+
if (!refusal) return
|
|
115
|
+
const view = ctx.grant()
|
|
116
|
+
if (!allows(view, 'merge')) throw new PublishError(`${refusal}\n\n${grantAdvice(view, 'merge')}`)
|
|
117
|
+
console.log(`stacked base \`${base}\` under maintainer grant (merge): "${/** @type {any} */ (view).grant.reason}"`)
|
|
118
|
+
}
|
|
119
|
+
|
|
99
120
|
/** Validated-base gate. See gates/validated-base.mjs. */
|
|
100
121
|
function validatedBaseGate({ ctx, base, argv }) {
|
|
101
122
|
const receipt = readReceipt({ gitDir: ctx.gitDir() })
|
|
@@ -285,6 +306,7 @@ export async function runPublish(argv, { client: given = null } = {}) {
|
|
|
285
306
|
// Read before the write, said after the commit line: a branch nobody opened
|
|
286
307
|
// a PR for is a branch CI never runs on.
|
|
287
308
|
const existing = head ? await openPr({ client, owner, repo, branch }) : null
|
|
309
|
+
await stackedBaseGate({ ctx, base, newBranch: !head, newPr: Boolean(prTitle && !existing) })
|
|
288
310
|
|
|
289
311
|
const { runner, hooks } = publishHooks({ ctx, skip: skipHooks, branch, remoteSha: head?.sha ?? null })
|
|
290
312
|
const out = await publishWorktree({
|
package/src/gates/scope.mjs
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* refused at any size, and any path that gains more than
|
|
25
25
|
* {@link ADDED_BYTES_CEILING} in one publish is refused.
|
|
26
26
|
* - A publish without `--pr` lands a branch nothing ever runs on. That is
|
|
27
|
-
* legitimate —
|
|
27
|
+
* legitimate — a second commit to an open PR — so it is a note
|
|
28
28
|
* on stdout, not a refusal: see {@link noPrNote}.
|
|
29
29
|
*
|
|
30
30
|
* The branch-name half (`--api` as a ref) belongs to a branch-name ruleset
|
|
@@ -243,8 +243,8 @@ export function sweepMessage(wouldSweep, { usage } = {}) {
|
|
|
243
243
|
|
|
244
244
|
/**
|
|
245
245
|
* The note a publish without `--pr` prints when the branch has no open PR
|
|
246
|
-
* either. Not a refusal — a
|
|
247
|
-
*
|
|
246
|
+
* either. Not a refusal — a second commit to a branch whose PR is already
|
|
247
|
+
* open is exactly this shape — but a branch with no PR is
|
|
248
248
|
* a branch CI typically never runs on (most workflows trigger on `pull_request` and
|
|
249
249
|
* `merge_group` only), and that silence is how the incident's commit sat
|
|
250
250
|
* unexamined.
|
|
@@ -254,6 +254,6 @@ export function sweepMessage(wouldSweep, { usage } = {}) {
|
|
|
254
254
|
export function noPrNote({ branch, base }) {
|
|
255
255
|
return (
|
|
256
256
|
`note: ${branch} has no open pull request, so no CI runs on it. ` +
|
|
257
|
-
`Open one with --pr "<title>" (targets ${base})
|
|
257
|
+
`Open one with --pr "<title>" (targets ${base}).`
|
|
258
258
|
)
|
|
259
259
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Stacked-base gate: an agent builds only on a base it may merge into.
|
|
4
|
+
*
|
|
5
|
+
* `graft pr merge` refuses a PR whose base is outside `mergeableBases`
|
|
6
|
+
* (pr-policy.mjs). A publish that cuts a NEW branch from such a base, or opens
|
|
7
|
+
* a PR against one, makes exactly that PR: work that no agent can land, and
|
|
8
|
+
* that lands at all only if the PR beneath it merges first. Orchestrators that
|
|
9
|
+
* track one PR per issue (cambium) read the two layers as duplicates and close
|
|
10
|
+
* the lower one, stranding the upper. So the refusal moves forward to publish
|
|
11
|
+
* time, before anything is written.
|
|
12
|
+
*
|
|
13
|
+
* Staged work is two issues, the second blocked by the first, each with its own
|
|
14
|
+
* PR into a mergeable base. A human who wants a stack anyway grants `merge`.
|
|
15
|
+
*
|
|
16
|
+
* Publishing to an EXISTING branch is left alone: the branch, and any PR on
|
|
17
|
+
* it, already exist, and refusing a fix to them helps nobody.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {{ base: string, allowedBases: string[], newBranch: boolean, newPr: boolean }} input
|
|
22
|
+
* `newBranch`: the publish creates the branch from `base`. `newPr`: it opens a PR against `base`.
|
|
23
|
+
* @returns {string | null} the refusal, or null to go ahead
|
|
24
|
+
*/
|
|
25
|
+
export function stackedBaseRefusal({ base, allowedBases, newBranch, newPr }) {
|
|
26
|
+
if (allowedBases.includes(base) || (!newBranch && !newPr)) return null
|
|
27
|
+
const bases = allowedBases.length ? allowedBases.map((b) => `\`${b}\``).join(', ') : 'no branch'
|
|
28
|
+
const what = newPr ? `open a PR against \`${base}\`` : `cut a new branch from \`${base}\``
|
|
29
|
+
return (
|
|
30
|
+
`refusing to publish: this would ${what}, and agents merge only into ${bases} (mergeableBases in .graft.json). ` +
|
|
31
|
+
'A PR stacked on another branch cannot land until the one beneath it merges, and no agent can merge it.\n\n' +
|
|
32
|
+
'Publish onto a mergeable base instead. Work that must be reviewed in stages is two issues, the second blocked ' +
|
|
33
|
+
'by the first, each with its own PR.'
|
|
34
|
+
)
|
|
35
|
+
}
|
package/src/maintainer.mjs
CHANGED
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
* merge `graft pr merge` past the local merge policy: a base outside
|
|
31
31
|
* `mergeableBases`, protected paths in the diff, a red base.
|
|
32
32
|
* GitHub's rulesets still apply; this lifts graft's opinion only.
|
|
33
|
+
* Also `graft publish` cutting a branch from, or opening a PR
|
|
34
|
+
* against, a base outside `mergeableBases` (a stacked PR).
|
|
33
35
|
*
|
|
34
36
|
* `impossible` paths have no scope. No grant makes the App hold a permission
|
|
35
37
|
* it does not have.
|