@skitterbyte/skitterspec-jira 2.4.0 → 2.5.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/assets/core/SETUP.md +5 -0
- package/assets/core/env.config.md +53 -2
- package/assets/hooks/main-guard.cjs +23 -5
- package/assets/hooks/review-gate.cjs +24 -6
- package/package.json +1 -1
- package/src/cli.js +106 -49
- package/src/env/bootstrap.js +22 -3
- package/src/env/classify.js +12 -4
- package/src/env/config.js +2 -2
- package/src/env/handoff.js +2 -1
- package/src/env/hotfix.js +12 -9
- package/src/env/hotfixland.js +2 -1
- package/src/env/inflight.js +8 -5
- package/src/env/integrate.js +13 -12
- package/src/env/live.js +8 -7
- package/src/env/mainguard.js +14 -5
- package/src/env/project.js +223 -0
- package/src/env/provision.js +15 -5
- package/src/env/resolve.js +39 -16
- package/src/env/review.js +21 -7
- package/src/env/reviewers.js +7 -10
- package/src/env/serve.js +21 -10
- package/src/env/supervise.js +15 -2
- package/src/env/teardown.js +4 -3
- package/src/init.js +49 -9
- package/src/vendor/jira/cli-sync.js +3 -1
- package/src/vendor/provider-kit/src/apply.js +9 -2
- package/src/vendor/provider-kit/src/credentials.js +7 -2
- package/src/vendor/provider-kit/src/released.js +34 -3
- package/src/vendor/provider-kit/src/specs.js +14 -5
- package/src/vendor/sync-core/src/compare.js +64 -1
- package/src/vendor/sync-core/src/push.js +39 -3
package/src/env/bootstrap.js
CHANGED
|
@@ -61,7 +61,7 @@ function lstatOrNull(fs, p) {
|
|
|
61
61
|
* The target is tested with `lstat`, which does not: an existing link, even a
|
|
62
62
|
* dangling one, is somebody's deliberate state and is left alone.
|
|
63
63
|
*/
|
|
64
|
-
function runSeed(step, { cwd, mainRoot, fs }) {
|
|
64
|
+
function runSeed(step, { cwd, mainRoot, fs, platform = process.platform }) {
|
|
65
65
|
const src = path.join(mainRoot, step.file)
|
|
66
66
|
const dst = path.join(cwd, step.file)
|
|
67
67
|
if (!fs.existsSync(src)) {
|
|
@@ -71,8 +71,26 @@ function runSeed(step, { cwd, mainRoot, fs }) {
|
|
|
71
71
|
return { outcome: 'skipped', line: `seed ${step.file}: exists — skipped` }
|
|
72
72
|
}
|
|
73
73
|
fs.mkdirSync(path.dirname(dst), { recursive: true })
|
|
74
|
-
if (step.mode === 'copy')
|
|
75
|
-
|
|
74
|
+
if (step.mode === 'copy') {
|
|
75
|
+
fs.copyFileSync(src, dst)
|
|
76
|
+
return { outcome: 'seeded', line: `seeded ${step.file} → ${src}` }
|
|
77
|
+
}
|
|
78
|
+
// WINDOWS WITHOUT DEVELOPER MODE CANNOT CREATE A SYMLINK (EPERM), and a
|
|
79
|
+
// seed is what makes a fresh worktree runnable at all (chore-windows-ci). A
|
|
80
|
+
// directory takes a junction there, which needs no privilege; a file that
|
|
81
|
+
// still cannot be linked is copied — said, because a copy does not follow
|
|
82
|
+
// later edits to the primary checkout's file the way a link would.
|
|
83
|
+
const dir = fs.statSync(src).isDirectory()
|
|
84
|
+
try {
|
|
85
|
+
fs.symlinkSync(src, dst, dir && platform === 'win32' ? 'junction' : undefined)
|
|
86
|
+
} catch (err) {
|
|
87
|
+
if (dir || !(err && (err.code === 'EPERM' || err.code === 'EACCES'))) throw err
|
|
88
|
+
fs.copyFileSync(src, dst)
|
|
89
|
+
return {
|
|
90
|
+
outcome: 'seeded',
|
|
91
|
+
line: `seeded ${step.file} → ${src} (copied — this machine cannot create symlinks)`,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
76
94
|
return { outcome: 'seeded', line: `seeded ${step.file} → ${src}` }
|
|
77
95
|
}
|
|
78
96
|
|
|
@@ -157,6 +175,7 @@ function runBootstrap(steps, io) {
|
|
|
157
175
|
cwd: io.cwd,
|
|
158
176
|
mainRoot: io.mainRoot,
|
|
159
177
|
fs: io.fs || realFs,
|
|
178
|
+
platform: io.platform || process.platform,
|
|
160
179
|
spawn: io.spawn || spawnSync,
|
|
161
180
|
childStdout: io.childStdout || 'inherit',
|
|
162
181
|
}
|
package/src/env/classify.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
const path = require('node:path')
|
|
19
19
|
const { BUCKETS, expandTokens, readFrontmatterField } = require('./resolve.js')
|
|
20
|
+
const { fromRepoPath, prefixOf } = require('./project.js')
|
|
20
21
|
|
|
21
22
|
// git reports repo-relative, forward-slashed paths; an untracked directory comes
|
|
22
23
|
// back with a trailing slash. Normalise both away so comparisons are exact.
|
|
@@ -66,7 +67,9 @@ function expandCompanion(pattern, spec, config) {
|
|
|
66
67
|
/**
|
|
67
68
|
* Split `dirtyPaths` into the ones that belong to `spec` and the ones that do
|
|
68
69
|
* not. Repo-relative paths in, repo-relative paths out; nothing is read from git
|
|
69
|
-
* and nothing is written.
|
|
70
|
+
* and nothing is written. The spec's folders and companion paths are
|
|
71
|
+
* PROJECT-relative, so each path is converted with the config's prefix before it
|
|
72
|
+
* is compared — a path outside a subfolder project is never the spec's.
|
|
70
73
|
*
|
|
71
74
|
* Owned:
|
|
72
75
|
* - anything inside `specs/<bucket>/<folder>/` for ANY bucket. Every bucket is
|
|
@@ -89,11 +92,13 @@ function classifyDirtyTree(spec, dirtyPaths, config) {
|
|
|
89
92
|
if (expanded) companions.add(expanded)
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
const prefix = prefixOf(config)
|
|
92
96
|
for (const raw of dirtyPaths || []) {
|
|
93
97
|
const p = normalize(raw)
|
|
94
98
|
if (!p) continue
|
|
95
|
-
const
|
|
96
|
-
|
|
99
|
+
const rel = fromRepoPath(p, prefix)
|
|
100
|
+
const inFolder = rel !== null && folders.some((f) => rel === f || rel.startsWith(`${f}/`))
|
|
101
|
+
if (inFolder || (rel !== null && companions.has(rel))) owned.push(p)
|
|
97
102
|
else foreign.push(p)
|
|
98
103
|
}
|
|
99
104
|
return { owned, foreign }
|
|
@@ -129,7 +134,10 @@ function unquotePath(p) {
|
|
|
129
134
|
function dirtyPaths(git) {
|
|
130
135
|
const lists = [
|
|
131
136
|
git(['diff', '--name-only', 'HEAD']),
|
|
132
|
-
|
|
137
|
+
// `--full-name`: `ls-files` answers relative to its cwd, `diff` from the repo
|
|
138
|
+
// root. Read from a subfolder project they disagreed, and every untracked
|
|
139
|
+
// spec document was classified as somebody else's.
|
|
140
|
+
git(['ls-files', '--others', '--exclude-standard', '--full-name']),
|
|
133
141
|
]
|
|
134
142
|
if (lists.every((l) => l === null)) return null
|
|
135
143
|
const out = []
|
package/src/env/config.js
CHANGED
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
|
|
62
62
|
const { createHash } = require('node:crypto')
|
|
63
63
|
const { readFileSync, realpathSync } = require('node:fs')
|
|
64
|
-
const { join, resolve } = require('node:path')
|
|
64
|
+
const { join, resolve, sep } = require('node:path')
|
|
65
65
|
|
|
66
66
|
const CONFIG_FILE = join('specs', '.core', 'env.config.json')
|
|
67
67
|
|
|
@@ -891,7 +891,7 @@ function loadEnvConfig(dir = process.cwd()) {
|
|
|
891
891
|
try {
|
|
892
892
|
parsed = JSON.parse(raw)
|
|
893
893
|
} catch (error) {
|
|
894
|
-
throw new Error(`Invalid ${CONFIG_FILE}: ${error.message}`)
|
|
894
|
+
throw new Error(`Invalid ${CONFIG_FILE.split(sep).join('/')}: ${error.message}`)
|
|
895
895
|
}
|
|
896
896
|
|
|
897
897
|
return {
|
package/src/env/handoff.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
const { phaseProgress, progressText } = require('./phases.js')
|
|
18
|
+
const { shellPath } = require('./project.js')
|
|
18
19
|
|
|
19
20
|
// Uncommitted work cannot travel with a push, so a hand-over would silently
|
|
20
21
|
// leave it behind in the old worktree. The engine declares the way out rather
|
|
@@ -55,7 +56,7 @@ function planHandoff(f) {
|
|
|
55
56
|
// unpublished branch and a stale one both need it, and a remote that could
|
|
56
57
|
// not be asked is planned as if it does (a redundant push is harmless).
|
|
57
58
|
const published = Boolean(f.headSha && f.remoteSha && f.remoteSha === f.headSha)
|
|
58
|
-
const commands = published ? [] : [`git -C ${spec.worktreePath} push -u ${f.remote} ${spec.branch}`]
|
|
59
|
+
const commands = published ? [] : [`git -C ${shellPath(spec.worktreePath)} push -u ${f.remote} ${spec.branch}`]
|
|
59
60
|
const sha = (f.headSha || '').slice(0, 12)
|
|
60
61
|
const note = [
|
|
61
62
|
`**Handed over** — the work is on \`${spec.branch}\` at \`${sha}\` (${f.remote}), ${progressText(progress)}.`,
|
package/src/env/hotfix.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
const path = require('node:path')
|
|
24
24
|
const { afterLandFor, rangeOf } = require('./integrate.js')
|
|
25
|
+
const { shellPath } = require('./project.js')
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Parse a semver-ish tag and return it with its PATCH bumped by one. Preserves any
|
|
@@ -227,15 +228,17 @@ function planHotfixLand(spec, config, ctx) {
|
|
|
227
228
|
// The tag is the command's to choose and is unknown until it has run, so
|
|
228
229
|
// there is nothing to check a collision against here — the command refuses
|
|
229
230
|
// a tag that exists, and the runner refuses one a target also planned.
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
// The release command is the project's, so it runs in the project folder.
|
|
232
|
+
const releaseCwd = spec.projectPath || spec.worktreePath
|
|
233
|
+
commands.push(`(cd ${shellPath(releaseCwd)} && ${releaseWith})`)
|
|
234
|
+
steps.push({ kind: 'release', via: 'command', command: releaseWith, cwd: releaseCwd })
|
|
232
235
|
} else {
|
|
233
236
|
prodTag = nextTag(baseRef, c.existingTags, bump)
|
|
234
237
|
if (taken.has(prodTag)) {
|
|
235
238
|
return block(`tag ${prodTag} already exists${freeTagHint(baseRef, c.existingTags, bump)}`)
|
|
236
239
|
}
|
|
237
240
|
taken.add(prodTag)
|
|
238
|
-
commands.push(`git -C ${spec.worktreePath} tag ${prodTag}`)
|
|
241
|
+
commands.push(`git -C ${shellPath(spec.worktreePath)} tag ${prodTag}`)
|
|
239
242
|
steps.push({
|
|
240
243
|
kind: 'release',
|
|
241
244
|
via: 'tag',
|
|
@@ -281,10 +284,10 @@ function planHotfixLand(spec, config, ctx) {
|
|
|
281
284
|
const tmpBranch = `hotfix/${slug}`
|
|
282
285
|
const tmpPath = path.join(wtRoot, slug)
|
|
283
286
|
commands.push(
|
|
284
|
-
`git worktree add ${tmpPath} -b ${tmpBranch} ${t}`,
|
|
285
|
-
`git -C ${tmpPath} cherry-pick ${fixPick.join(' ')}`,
|
|
286
|
-
`git -C ${tmpPath} tag ${tag}`,
|
|
287
|
-
`git worktree remove ${tmpPath}`,
|
|
287
|
+
`git worktree add ${shellPath(tmpPath)} -b ${tmpBranch} ${t}`,
|
|
288
|
+
`git -C ${shellPath(tmpPath)} cherry-pick ${fixPick.join(' ')}`,
|
|
289
|
+
`git -C ${shellPath(tmpPath)} tag ${tag}`,
|
|
290
|
+
`git worktree remove ${shellPath(tmpPath)}`,
|
|
288
291
|
`git branch -D ${tmpBranch}`,
|
|
289
292
|
)
|
|
290
293
|
const root = c.mainRepoPath
|
|
@@ -320,8 +323,8 @@ function planHotfixLand(spec, config, ctx) {
|
|
|
320
323
|
const picks = carry.commits || [fixRange]
|
|
321
324
|
commands.push(
|
|
322
325
|
carry.strategy === 'worktree'
|
|
323
|
-
? `git worktree add ${carry.tmpPath} ${c.base} && git -C ${carry.tmpPath} cherry-pick ${picks.join(' ')}`
|
|
324
|
-
: `git -C ${carry.path} cherry-pick ${picks.join(' ')}`,
|
|
326
|
+
? `git worktree add ${shellPath(carry.tmpPath)} ${c.base} && git -C ${shellPath(carry.tmpPath)} cherry-pick ${picks.join(' ')}`
|
|
327
|
+
: `git -C ${shellPath(carry.path)} cherry-pick ${picks.join(' ')}`,
|
|
325
328
|
)
|
|
326
329
|
steps.push({
|
|
327
330
|
kind: 'carry',
|
package/src/env/hotfixland.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
const { spawnSync } = require('node:child_process')
|
|
24
|
+
const { shellPath } = require('./project.js')
|
|
24
25
|
|
|
25
26
|
// The fields skittership's `release-hotfix.cjs --json` prints, and their types.
|
|
26
27
|
// `versionCommit` is null only on its `--dry-run`, which skitterspec never
|
|
@@ -219,7 +220,7 @@ function runCarry(step, release, ctx) {
|
|
|
219
220
|
outcome: 'refused',
|
|
220
221
|
line:
|
|
221
222
|
`carry: ${step.cwd} has uncommitted changes on ${step.base} — commit or stash them, ` +
|
|
222
|
-
`then run: git -C ${step.cwd} cherry-pick ${commits.join(' ')}`,
|
|
223
|
+
`then run: git -C ${shellPath(step.cwd)} cherry-pick ${commits.join(' ')}`,
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
const git = (argv) =>
|
package/src/env/inflight.js
CHANGED
|
@@ -22,19 +22,22 @@ const { progressText } = require('./phases.js')
|
|
|
22
22
|
/**
|
|
23
23
|
* @param {object} a
|
|
24
24
|
* - `dir` the checkout the command was run from
|
|
25
|
-
* - `provisioned` `[{ folder, wt, specless }]`, from the worktree
|
|
25
|
+
* - `provisioned` `[{ folder, wt, project, specless }]`, from the worktree
|
|
26
|
+
* list — `project` is the project folder inside `wt`, the
|
|
27
|
+
* same path unless the project sits in a subfolder
|
|
26
28
|
* - `read` `readSpecState`, injectable
|
|
27
29
|
*/
|
|
28
30
|
function collectInFlight({ dir, provisioned, read = readSpecState }) {
|
|
29
|
-
return provisioned.map(({ folder, wt, specless }) => {
|
|
31
|
+
return provisioned.map(({ folder, wt, project, specless }) => {
|
|
32
|
+
const at = project || wt
|
|
30
33
|
// A `/no-spec` record has a branch and no document BY DESIGN (Decision 6).
|
|
31
34
|
// It is listed, and never read, so it can never be called unknown.
|
|
32
|
-
if (specless) return { spec: folder, worktree:
|
|
33
|
-
const there = read(
|
|
35
|
+
if (specless) return { spec: folder, worktree: at, specless: true }
|
|
36
|
+
const there = read(at, folder)
|
|
34
37
|
const here = read(dir, folder)
|
|
35
38
|
return {
|
|
36
39
|
spec: folder,
|
|
37
|
-
worktree:
|
|
40
|
+
worktree: at,
|
|
38
41
|
specless: false,
|
|
39
42
|
...there,
|
|
40
43
|
// Where this checkout files it: a bucket, or null when it is not on this
|
package/src/env/integrate.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { globToRegExp } = require('./glob.js')
|
|
4
|
+
const { shellPath } = require('./project.js')
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Pure integrate planner for `spec-env integrate`.
|
|
@@ -69,8 +70,8 @@ function planIntegrate(spec, config, ctx) {
|
|
|
69
70
|
...result,
|
|
70
71
|
commands: [
|
|
71
72
|
...(primarySwitch ? [switchCommand(mainRepoPath, base, primarySwitch)] : []),
|
|
72
|
-
`git -C ${spec.worktreePath} rebase ${base}`,
|
|
73
|
-
`git -C ${mainRepoPath} merge --ff-only ${branch}`,
|
|
73
|
+
`git -C ${shellPath(spec.worktreePath)} rebase ${base}`,
|
|
74
|
+
`git -C ${shellPath(mainRepoPath)} merge --ff-only ${branch}`,
|
|
74
75
|
],
|
|
75
76
|
afterLand: afterLandFor(config, mainRepoPath, rangeOf(ctx)),
|
|
76
77
|
}
|
|
@@ -80,8 +81,8 @@ function planIntegrate(spec, config, ctx) {
|
|
|
80
81
|
// when this clone has never had it (a release candidate cut since).
|
|
81
82
|
function switchCommand(repo, base, { create, remote }) {
|
|
82
83
|
return create
|
|
83
|
-
? `git -C ${repo} switch -c ${base} --track ${remote || 'origin'}/${base}`
|
|
84
|
-
: `git -C ${repo} switch ${base}`
|
|
84
|
+
? `git -C ${shellPath(repo)} switch -c ${base} --track ${remote || 'origin'}/${base}`
|
|
85
|
+
: `git -C ${shellPath(repo)} switch ${base}`
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
/**
|
|
@@ -134,9 +135,9 @@ function planIntegrateCheckout(spec, config, ctx) {
|
|
|
134
135
|
return {
|
|
135
136
|
...result,
|
|
136
137
|
commands: [
|
|
137
|
-
`git -C ${checkoutPath} rebase ${base}`,
|
|
138
|
-
`git -C ${checkoutPath} switch ${base}`,
|
|
139
|
-
`git -C ${checkoutPath} merge --ff-only ${branch}`,
|
|
138
|
+
`git -C ${shellPath(checkoutPath)} rebase ${base}`,
|
|
139
|
+
`git -C ${shellPath(checkoutPath)} switch ${base}`,
|
|
140
|
+
`git -C ${shellPath(checkoutPath)} merge --ff-only ${branch}`,
|
|
140
141
|
],
|
|
141
142
|
afterLand: afterLandFor(config, checkoutPath, rangeOf(ctx)),
|
|
142
143
|
}
|
|
@@ -196,8 +197,8 @@ function planIntegratePr(spec, config, ctx) {
|
|
|
196
197
|
const finish = {
|
|
197
198
|
commands: ctx.primaryPath
|
|
198
199
|
? [
|
|
199
|
-
`git -C ${ctx.primaryPath} fetch ${remote} ${base}`,
|
|
200
|
-
`git -C ${ctx.primaryPath} merge --ff-only ${remote}/${base}`,
|
|
200
|
+
`git -C ${shellPath(ctx.primaryPath)} fetch ${remote} ${base}`,
|
|
201
|
+
`git -C ${shellPath(ctx.primaryPath)} merge --ff-only ${remote}/${base}`,
|
|
201
202
|
]
|
|
202
203
|
: [],
|
|
203
204
|
afterLand: afterLandFor(config, ctx.primaryPath || null, rangeOf(ctx)),
|
|
@@ -212,12 +213,12 @@ function planIntegratePr(spec, config, ctx) {
|
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
const commands = [
|
|
215
|
-
`git -C ${treePath} fetch ${remote} ${base}`,
|
|
216
|
-
`git -C ${treePath} rebase ${remote}/${base}`,
|
|
216
|
+
`git -C ${shellPath(treePath)} fetch ${remote} ${base}`,
|
|
217
|
+
`git -C ${shellPath(treePath)} rebase ${remote}/${base}`,
|
|
217
218
|
]
|
|
218
219
|
// --force-with-lease because the rebase rewrites; -u so the first push sets
|
|
219
220
|
// the upstream the unpushed guard reads.
|
|
220
|
-
const pushCommand = `git -C ${treePath} push --force-with-lease -u ${remote} ${branch}`
|
|
221
|
+
const pushCommand = `git -C ${shellPath(treePath)} push --force-with-lease -u ${remote} ${branch}`
|
|
221
222
|
// Composed by the host adapter where one exists; until the caller supplies
|
|
222
223
|
// one, a comment line that cannot be run by accident.
|
|
223
224
|
const prCommand = (ctx && ctx.prCreateCommand)
|
package/src/env/live.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
const fs = require('node:fs')
|
|
20
20
|
const path = require('node:path')
|
|
21
21
|
const { globToRegExp } = require('./glob.js')
|
|
22
|
+
const { shellPath } = require('./project.js')
|
|
22
23
|
|
|
23
24
|
const REQUIRED = ['spec', 'branch', 'holder', 'heldSince', 'baseMainCommit']
|
|
24
25
|
|
|
@@ -341,9 +342,9 @@ function planTake(spec, config, ctx) {
|
|
|
341
342
|
return {
|
|
342
343
|
...result,
|
|
343
344
|
commands: [
|
|
344
|
-
`git -C ${spec.worktreePath} rebase ${base}`,
|
|
345
|
-
`git -C ${spec.worktreePath} switch --detach`,
|
|
346
|
-
`git -C ${c.primaryPath} checkout ${branch}`,
|
|
345
|
+
`git -C ${shellPath(spec.worktreePath)} rebase ${base}`,
|
|
346
|
+
`git -C ${shellPath(spec.worktreePath)} switch --detach`,
|
|
347
|
+
`git -C ${shellPath(c.primaryPath)} checkout ${branch}`,
|
|
347
348
|
],
|
|
348
349
|
warnings,
|
|
349
350
|
receipt: {
|
|
@@ -405,8 +406,8 @@ function planRelease(spec, config, ctx) {
|
|
|
405
406
|
}
|
|
406
407
|
}
|
|
407
408
|
|
|
408
|
-
const commands = [`git -C ${c.primaryPath} checkout ${base}`]
|
|
409
|
-
if (c.worktreeExists) commands.push(`git -C ${spec.worktreePath} switch ${branch}`)
|
|
409
|
+
const commands = [`git -C ${shellPath(c.primaryPath)} checkout ${base}`]
|
|
410
|
+
if (c.worktreeExists) commands.push(`git -C ${shellPath(spec.worktreePath)} switch ${branch}`)
|
|
410
411
|
return { ...result, commands, clears: true }
|
|
411
412
|
}
|
|
412
413
|
|
|
@@ -457,8 +458,8 @@ function planAbort(config, ctx) {
|
|
|
457
458
|
|
|
458
459
|
const branch = c.receipt.branch
|
|
459
460
|
const commands = []
|
|
460
|
-
if (!(c.primary && c.primary.onBase)) commands.push(`git -C ${c.primaryPath} checkout ${base}`)
|
|
461
|
-
if (c.worktreeExists) commands.push(`git -C ${c.worktreePath} switch ${branch}`)
|
|
461
|
+
if (!(c.primary && c.primary.onBase)) commands.push(`git -C ${shellPath(c.primaryPath)} checkout ${base}`)
|
|
462
|
+
if (c.worktreeExists) commands.push(`git -C ${shellPath(c.worktreePath)} switch ${branch}`)
|
|
462
463
|
return { ...result, commands, clears: true, branch }
|
|
463
464
|
}
|
|
464
465
|
|
package/src/env/mainguard.js
CHANGED
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
const fs = require('node:fs')
|
|
34
34
|
const path = require('node:path')
|
|
35
35
|
|
|
36
|
-
const { assertPrimaryOnMain
|
|
36
|
+
const { assertPrimaryOnMain } = require('./resolve.js')
|
|
37
|
+
const { primaryAnchor } = require('./project.js')
|
|
37
38
|
|
|
38
39
|
// Where the allow lives. Gitignored, machine-local and beside the registry —
|
|
39
40
|
// this is one person's decision about one session, never the project's policy.
|
|
@@ -169,7 +170,7 @@ function checkoutOf(target, gitAt) {
|
|
|
169
170
|
// the same directory. Cannot-tell is "not the same", the branch that allows.
|
|
170
171
|
function sameDir(a, b) {
|
|
171
172
|
try {
|
|
172
|
-
return fs.realpathSync(a) === fs.realpathSync(b)
|
|
173
|
+
return fs.realpathSync.native(a) === fs.realpathSync.native(b)
|
|
173
174
|
} catch {
|
|
174
175
|
return false
|
|
175
176
|
}
|
|
@@ -218,12 +219,20 @@ function checkMainWrite(dir, config, git, opts = {}) {
|
|
|
218
219
|
// the primary checkout's own, wherever the session is standing.
|
|
219
220
|
let branchGit = git
|
|
220
221
|
try {
|
|
221
|
-
primary
|
|
222
|
+
// `primary` is the PROJECT folder in the primary checkout — where the allow
|
|
223
|
+
// file lives. The question "is this write in the primary checkout?" is
|
|
224
|
+
// asked of its ROOT: `--show-toplevel` answers with the root, and a project
|
|
225
|
+
// in a subfolder of its repo compared the two, never matched, and let every
|
|
226
|
+
// write through. The whole primary checkout is guarded, not only the
|
|
227
|
+
// project folder: a write to `Sql/` on the base branch is unreviewed work
|
|
228
|
+
// too (feat-subfolder-project, decision 6).
|
|
229
|
+
const anchor = primaryAnchor(dir, git)
|
|
230
|
+
primary = anchor.dir
|
|
222
231
|
if (opts.target && typeof opts.gitAt === 'function') {
|
|
223
232
|
const top = checkoutOf(opts.target, opts.gitAt)
|
|
224
|
-
isPrimary = Boolean(top) && Boolean(
|
|
233
|
+
isPrimary = Boolean(top) && Boolean(anchor.root) && sameDir(top, anchor.root)
|
|
225
234
|
if (!isPrimary) return ALLOWS
|
|
226
|
-
branchGit = opts.gitAt(
|
|
235
|
+
branchGit = opts.gitAt(anchor.root)
|
|
227
236
|
} else {
|
|
228
237
|
isPrimary = Boolean(primary) && path.resolve(primary) === path.resolve(dir)
|
|
229
238
|
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where the skitterspec project sits inside its git repo.
|
|
5
|
+
*
|
|
6
|
+
* Most projects ARE the repo: `specs/` and `.claude/` live at the git root and
|
|
7
|
+
* the prefix is `''`. Some live in a subfolder — a .NET solution folder beside
|
|
8
|
+
* `Sql/` and a prototype or two, where sessions start in the solution folder and
|
|
9
|
+
* that is where `specs/` has to be. This module is the one place that knows the
|
|
10
|
+
* difference, so every other site asks it rather than assuming `specs/` is at
|
|
11
|
+
* the root.
|
|
12
|
+
*
|
|
13
|
+
* Two kinds of path, kept apart on purpose:
|
|
14
|
+
*
|
|
15
|
+
* - a **repo path** is what git prints: relative to the git root, `/`-separated
|
|
16
|
+
* on every platform (git emits forward slashes on Windows too).
|
|
17
|
+
* - an **OS path** is what `fs` and `spawn` take, built with `path`.
|
|
18
|
+
*
|
|
19
|
+
* `fromRepoPath` / `toRepoPath` convert between a repo path and a
|
|
20
|
+
* project-relative one; `projectIn` turns a checkout root into the project's OS
|
|
21
|
+
* folder within it.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const fs = require('node:fs')
|
|
25
|
+
const path = require('node:path')
|
|
26
|
+
|
|
27
|
+
// What marks a project folder: the config folder the installer always writes
|
|
28
|
+
// into. A positive signal (`.claude/rules/negative-checks.md` rule 1) — not
|
|
29
|
+
// "the lifecycle folders are there", which git drops whenever one empties.
|
|
30
|
+
const MARKER = path.join('specs', '.core')
|
|
31
|
+
|
|
32
|
+
function isDir(p) {
|
|
33
|
+
try {
|
|
34
|
+
return fs.statSync(p).isDirectory()
|
|
35
|
+
} catch {
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// `.native`, never the JS `realpathSync`: on Windows only the native call
|
|
41
|
+
// expands an 8.3 short name (`C:\Users\RUNNER~1\…`), and git always reports the
|
|
42
|
+
// long one. Compared un-expanded, every folder under a short-named temp dir
|
|
43
|
+
// looked outside its own repo, and the project was never found.
|
|
44
|
+
function real(p) {
|
|
45
|
+
try {
|
|
46
|
+
return fs.realpathSync.native(p)
|
|
47
|
+
} catch {
|
|
48
|
+
return path.resolve(p)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** An OS-relative path as a repo path: `/`-separated, no leading `./`. */
|
|
53
|
+
function toPosix(p) {
|
|
54
|
+
return String(p).split(path.sep).join('/').replace(/^\.\/?/, '')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The project's prefix within `toplevel`, found by walking up from `from` to the
|
|
59
|
+
* nearest folder holding `specs/.core/`, stopping at `toplevel`. `''` when the
|
|
60
|
+
* project is the root, and `''` when nothing is found — today's behaviour.
|
|
61
|
+
*
|
|
62
|
+
* WHAT WOULD FOOL THIS: a `specs/.core/` that is not a project's — a fixture
|
|
63
|
+
* folder checked into the repo, say — between `from` and the real project. The
|
|
64
|
+
* walk takes the nearest, so a command run from inside such a folder anchors
|
|
65
|
+
* there. Several projects in one repo are out of scope, and nothing here
|
|
66
|
+
* arbitrates between two. Run from the root's own subfolders (the ordinary
|
|
67
|
+
* case for a root-layout repo) the walk reaches the root and answers `''`.
|
|
68
|
+
*
|
|
69
|
+
* Paths are compared as REAL paths: git reports the toplevel resolved through
|
|
70
|
+
* symlinks (macOS `/var` → `/private/var`) where a caller's cwd may not be.
|
|
71
|
+
*/
|
|
72
|
+
function findPrefix(from, toplevel) {
|
|
73
|
+
const top = real(toplevel)
|
|
74
|
+
let at = real(from)
|
|
75
|
+
const rel = path.relative(top, at)
|
|
76
|
+
// `from` outside the toplevel is cannot-tell, and cannot-tell is `''`.
|
|
77
|
+
if (rel.startsWith('..') || path.isAbsolute(rel)) return ''
|
|
78
|
+
for (;;) {
|
|
79
|
+
if (isDir(path.join(at, MARKER))) return toPosix(path.relative(top, at))
|
|
80
|
+
if (at === top) return ''
|
|
81
|
+
const up = path.dirname(at)
|
|
82
|
+
if (up === at) return ''
|
|
83
|
+
at = up
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Locate the project from `from` in the primary checkout.
|
|
89
|
+
*
|
|
90
|
+
* `git(args)` is a reader bound to `from`, returning trimmed stdout or `null`
|
|
91
|
+
* (not a repo) — injected, as everywhere in `env/`. Returns
|
|
92
|
+
* `{ root, prefix, dir }`: the primary checkout's root, the project's prefix
|
|
93
|
+
* within it, and the project folder there (`root` itself when the prefix is
|
|
94
|
+
* `''`). Not a repo → `{ root: from, prefix: '', dir: from }`.
|
|
95
|
+
*
|
|
96
|
+
* The primary root is the parent of the shared git dir — `.git` relative from
|
|
97
|
+
* the primary checkout, `../../.git` from a subfolder of it, an absolute
|
|
98
|
+
* `<main>/.git` from a linked worktree. The prefix is found in the tree you are
|
|
99
|
+
* standing in and applied to the primary, which holds because a worktree is a
|
|
100
|
+
* checkout of the same repo: the project is at the same place in both.
|
|
101
|
+
*/
|
|
102
|
+
function primaryAnchor(from, git) {
|
|
103
|
+
const common = git(['rev-parse', '--git-common-dir'])
|
|
104
|
+
if (!common) return { root: from, prefix: '', dir: from }
|
|
105
|
+
// Canonical, so one folder prints one way wherever the command was run from.
|
|
106
|
+
// From the primary checkout `common` is relative (`.git`) and the root came
|
|
107
|
+
// out spelled as `from` was; from a worktree git hands back an absolute,
|
|
108
|
+
// long-form path — on Windows `RUNNER~1` against `runneradmin` for the same
|
|
109
|
+
// folder, and `integrate` printed two different plans (chore-windows-ci).
|
|
110
|
+
const root = real(path.dirname(path.resolve(from, common)))
|
|
111
|
+
const toplevel = git(['rev-parse', '--show-toplevel'])
|
|
112
|
+
const prefix = toplevel ? findPrefix(from, toplevel) : ''
|
|
113
|
+
return { root, prefix, dir: projectIn(root, prefix) }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The project's OS folder within a checkout root (the root when prefix is `''`). */
|
|
117
|
+
function projectIn(root, prefix) {
|
|
118
|
+
return prefix ? path.join(root, ...prefix.split('/')) : root
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A repo path as a project-relative path, or `null` when it is outside the
|
|
123
|
+
* project. Prefix `''` returns the path unchanged.
|
|
124
|
+
*/
|
|
125
|
+
function fromRepoPath(rel, prefix) {
|
|
126
|
+
if (!prefix) return rel
|
|
127
|
+
if (rel === prefix) return ''
|
|
128
|
+
return rel.startsWith(`${prefix}/`) ? rel.slice(prefix.length + 1) : null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A repo path as seen from the project folder: `fromRepoPath` inside the
|
|
133
|
+
* project, `../…` outside it — the form a pathspec takes when it is run from the
|
|
134
|
+
* project folder, which is where a session stands. Prefix `''` returns it
|
|
135
|
+
* unchanged.
|
|
136
|
+
*/
|
|
137
|
+
function projectRelative(rel, prefix) {
|
|
138
|
+
if (!prefix) return rel
|
|
139
|
+
const inside = fromRepoPath(rel, prefix)
|
|
140
|
+
return inside !== null ? inside : path.posix.relative(prefix, rel)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** A project-relative path as a repo path. Prefix `''` returns it unchanged. */
|
|
144
|
+
function toRepoPath(rel, prefix) {
|
|
145
|
+
if (!prefix) return rel
|
|
146
|
+
return rel ? `${prefix}/${rel}` : prefix
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Record where the project sits on a loaded config, for the code that needs the
|
|
151
|
+
* repo's root rather than the project folder — the worktree layout and `{repo}`
|
|
152
|
+
* resolve against the root, so worktrees land beside the repo rather than
|
|
153
|
+
* inside it. Non-enumerable, so it never reaches a JSON dump or a hash of the
|
|
154
|
+
* config.
|
|
155
|
+
*/
|
|
156
|
+
function attachProject(config, anchor) {
|
|
157
|
+
Object.defineProperty(config, 'project', {
|
|
158
|
+
value: Object.freeze({ root: anchor.root, prefix: anchor.prefix }),
|
|
159
|
+
enumerable: false,
|
|
160
|
+
configurable: true,
|
|
161
|
+
})
|
|
162
|
+
return config
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A path as one shell word, for the commands the engine PRINTS for a person or
|
|
167
|
+
* a skill to run. Quoted only when it has to be, so a path without spaces or
|
|
168
|
+
* shell characters prints byte-identically to before. Double quotes, because
|
|
169
|
+
* they mean the same in bash, zsh, Git Bash and cmd for an ordinary path; the
|
|
170
|
+
* three characters bash still expands inside them are escaped.
|
|
171
|
+
*
|
|
172
|
+
* A WINDOWS DRIVE PATH PRINTS WITH FORWARD SLASHES (`C:/Users/x/wt`): git, Git
|
|
173
|
+
* Bash, cmd and PowerShell all take that form unquoted, where `C:\Users` loses
|
|
174
|
+
* its backslashes in Git Bash (`C:Users`) unless quoted (chore-windows-ci).
|
|
175
|
+
*
|
|
176
|
+
* WHY QUOTING AT ALL: a repo at `C:\Code\LSC App` lays its worktrees out at
|
|
177
|
+
* `LSC App-wt`, and `git worktree add C:/Code/LSC App-wt/x -b …` is two
|
|
178
|
+
* arguments.
|
|
179
|
+
*/
|
|
180
|
+
function shellPath(p, platform = process.platform) {
|
|
181
|
+
let s = String(p)
|
|
182
|
+
// A drive path anywhere; on Windows every backslash, which is always a
|
|
183
|
+
// separator there — `\\wt\\x` from a rooted path is no different.
|
|
184
|
+
if (platform === 'win32' || /^[A-Za-z]:[\\/]/.test(s)) s = s.replace(/\\/g, '/')
|
|
185
|
+
// `~` only where bash expands it — at the start; `RUNNER~1` needs no quotes.
|
|
186
|
+
if (!/[\s"'$`!&|;<>()*?[\]{}#\\]/.test(s) && !s.startsWith('~')) return s
|
|
187
|
+
return `"${s.replace(/(["$`])/g, '\\$1')}"`
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The repo root a config was loaded for, else `dir` — today's behaviour. */
|
|
191
|
+
function repoRootOf(dir, config) {
|
|
192
|
+
return (config && config.project && config.project.root) || dir
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The project prefix a config was loaded for, else `''`. */
|
|
196
|
+
function prefixOf(config) {
|
|
197
|
+
return (config && config.project && config.project.prefix) || ''
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The one line that says where the project is, or `''` at the root — a root
|
|
202
|
+
* layout prints nothing new.
|
|
203
|
+
*/
|
|
204
|
+
function projectLine(anchor) {
|
|
205
|
+
if (!anchor || !anchor.prefix) return ''
|
|
206
|
+
return `subfolder: ${anchor.prefix}/ (in repo ${anchor.root})\n`
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
module.exports = {
|
|
210
|
+
MARKER,
|
|
211
|
+
findPrefix,
|
|
212
|
+
primaryAnchor,
|
|
213
|
+
projectIn,
|
|
214
|
+
fromRepoPath,
|
|
215
|
+
projectRelative,
|
|
216
|
+
toRepoPath,
|
|
217
|
+
toPosix,
|
|
218
|
+
shellPath,
|
|
219
|
+
attachProject,
|
|
220
|
+
repoRootOf,
|
|
221
|
+
prefixOf,
|
|
222
|
+
projectLine,
|
|
223
|
+
}
|
package/src/env/provision.js
CHANGED
|
@@ -15,6 +15,7 @@ const { classifyDirtyTree } = require('./classify.js')
|
|
|
15
15
|
const { portOffset } = require('./registry.js')
|
|
16
16
|
const { renderEnvFile } = require('./render.js')
|
|
17
17
|
const { expandTokens } = require('./resolve.js')
|
|
18
|
+
const { shellPath, prefixOf, projectRelative } = require('./project.js')
|
|
18
19
|
|
|
19
20
|
// Cap a path list in a message: enough to recognise, not a wall of text.
|
|
20
21
|
function listPaths(paths) {
|
|
@@ -90,7 +91,13 @@ function planSpecCommit(spec, ctx, config, { carriesChanges = false } = {}) {
|
|
|
90
91
|
return ok
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
// Git paths in, PROJECT paths out: the planned `git add -- …` runs from the
|
|
95
|
+
// project folder, and a project in a subfolder of its repo must not name
|
|
96
|
+
// `<prefix>/specs/…` from inside `<prefix>` (feat-subfolder-project).
|
|
97
|
+
const split = classifyDirtyTree(spec, c.dirtyPaths, config)
|
|
98
|
+
const prefix = prefixOf(config)
|
|
99
|
+
const owned = split.owned.map((p) => projectRelative(p, prefix))
|
|
100
|
+
const foreign = split.foreign.map((p) => projectRelative(p, prefix))
|
|
94
101
|
|
|
95
102
|
// FOREIGN DIRT REFUSES ONLY WHERE IT CAN REACH THE BRANCH, which is checkout
|
|
96
103
|
// mode and nowhere else. `git switch -c` carries the working tree onto the new
|
|
@@ -252,7 +259,9 @@ function worktreeSteps(spec, offset, config, opts = {}) {
|
|
|
252
259
|
const seed = config.seedFiles || { mode: 'symlink', files: [] }
|
|
253
260
|
const mode = seed.mode === 'copy' ? 'copy' : 'symlink'
|
|
254
261
|
const tokens = {
|
|
255
|
-
|
|
262
|
+
// The step's own cwd — the project folder inside the worktree — so the
|
|
263
|
+
// documented "{worktreePath} is the cwd" stays true for a subfolder project.
|
|
264
|
+
worktreePath: spec.projectPath || spec.worktreePath,
|
|
256
265
|
slug: spec.slug,
|
|
257
266
|
branch: spec.branch,
|
|
258
267
|
projectName: spec.projectName,
|
|
@@ -361,12 +370,12 @@ function planUp(spec, alloc, config, ctx, opts = {}) {
|
|
|
361
370
|
const resume = !attached && spec.resumeFrom ? spec.resumeFrom : null
|
|
362
371
|
if (resume) {
|
|
363
372
|
commands.push(`git fetch ${resume.remote} ${spec.branch}`)
|
|
364
|
-
commands.push(`git worktree add ${spec.worktreePath} -b ${spec.branch} --track ${resume.remote}/${spec.branch}`)
|
|
373
|
+
commands.push(`git worktree add ${shellPath(spec.worktreePath)} -b ${spec.branch} --track ${resume.remote}/${spec.branch}`)
|
|
365
374
|
} else {
|
|
366
375
|
commands.push(
|
|
367
376
|
attached
|
|
368
|
-
? `git worktree add ${spec.worktreePath} ${spec.branch}`
|
|
369
|
-
: `git worktree add ${spec.worktreePath} -b ${spec.branch}${forkPoint}`,
|
|
377
|
+
? `git worktree add ${shellPath(spec.worktreePath)} ${spec.branch}`
|
|
378
|
+
: `git worktree add ${shellPath(spec.worktreePath)} -b ${spec.branch}${forkPoint}`,
|
|
370
379
|
)
|
|
371
380
|
}
|
|
372
381
|
// The tree gate. A worktree forks from the base branch's tree, so an
|
|
@@ -386,6 +395,7 @@ function planUp(spec, alloc, config, ctx, opts = {}) {
|
|
|
386
395
|
// report from "provisioned", and the caller cannot reconstruct it.
|
|
387
396
|
untouched: gate.foreign || [],
|
|
388
397
|
worktreePath: spec.worktreePath,
|
|
398
|
+
projectPath: spec.projectPath || spec.worktreePath,
|
|
389
399
|
branch: spec.branch,
|
|
390
400
|
projectName: spec.projectName,
|
|
391
401
|
slot: wantsDocker ? slot : null,
|