@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/resolve.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
const fs = require('node:fs')
|
|
18
18
|
const path = require('node:path')
|
|
19
|
+
const { primaryAnchor, repoRootOf, prefixOf, projectIn } = require('./project.js')
|
|
19
20
|
|
|
20
21
|
const BUCKETS = ['backlog', 'in-progress', 'complete', 'cancelled']
|
|
21
22
|
|
|
@@ -524,17 +525,20 @@ function newestMatch(config, git, pattern) {
|
|
|
524
525
|
}
|
|
525
526
|
|
|
526
527
|
/**
|
|
527
|
-
* Resolve `dir` to the
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
528
|
+
* Resolve `dir` to the PROJECT FOLDER in the primary checkout — the primary root
|
|
529
|
+
* (the parent of the shared git dir) joined with the project's prefix, which is
|
|
530
|
+
* `''` when the project is the repo. From the primary checkout
|
|
531
|
+
* `git rev-parse --git-common-dir` is `.git` (relative), so the root is `dir`;
|
|
532
|
+
* from a linked worktree it's the absolute `<main>/.git`, so the root is
|
|
533
|
+
* `<main>`. Anchoring every `spec-env` command here means they read the config
|
|
534
|
+
* and registry identically whether run from `main` or a worktree.
|
|
535
|
+
* `git(args)` returns trimmed stdout or `null` (not a repo) — injected for
|
|
536
|
+
* testability; a `null` degrades to `dir` (today's behaviour). `env/project.js`
|
|
537
|
+
* carries how the prefix is found; `{repo}` and the worktree layout resolve
|
|
538
|
+
* against the root, which a loaded config carries (`attachProject`).
|
|
534
539
|
*/
|
|
535
540
|
function resolvePrimaryCheckout(dir, git) {
|
|
536
|
-
|
|
537
|
-
return common ? path.dirname(path.resolve(dir, common)) : dir
|
|
541
|
+
return primaryAnchor(dir, git).dir
|
|
538
542
|
}
|
|
539
543
|
|
|
540
544
|
/**
|
|
@@ -601,7 +605,8 @@ function assertPrimaryOnMain(config, git) {
|
|
|
601
605
|
* Pure but for `repoInfo`, like `resolveSpec`.
|
|
602
606
|
*/
|
|
603
607
|
function resolveSpecless(name, dir, config, entry = {}) {
|
|
604
|
-
const
|
|
608
|
+
const root = repoRootOf(dir, config)
|
|
609
|
+
const { repo, repoSlug } = repoInfo(root)
|
|
605
610
|
// AN AUTHORING RECORD RESOLVES AS THE SPEC IT WILL BE. `spec: true` marks a
|
|
606
611
|
// record written by `up --docs` for a spec not written yet (the `/spec`
|
|
607
612
|
// authoring lane), so type and slug come from the name's own prefix — the
|
|
@@ -634,14 +639,19 @@ function resolveSpecless(name, dir, config, entry = {}) {
|
|
|
634
639
|
branch,
|
|
635
640
|
worktreeRoot,
|
|
636
641
|
worktreeFolder,
|
|
637
|
-
worktreePath: path.resolve(
|
|
642
|
+
worktreePath: path.resolve(root, worktreeRoot, worktreeFolder),
|
|
643
|
+
projectPath: projectIn(path.resolve(root, worktreeRoot, worktreeFolder), prefixOf(config)),
|
|
644
|
+
prefix: prefixOf(config),
|
|
638
645
|
projectName: expandTokens(config.docker.projectNamePattern, tokens),
|
|
639
646
|
}
|
|
640
647
|
}
|
|
641
648
|
|
|
642
649
|
function resolveSpec(specArg, dir, config, opts = {}) {
|
|
643
|
-
|
|
644
|
-
|
|
650
|
+
// Both are CHECKOUT ROOTS (worktrees, from `git worktree list` or the config's
|
|
651
|
+
// layout); a spec lives in the project folder inside each one.
|
|
652
|
+
const prefix = prefixOf(config)
|
|
653
|
+
const searchDirs = (opts.searchDirs || []).map((d) => projectIn(d, prefix))
|
|
654
|
+
const preferDirs = (opts.preferDirs || []).map((d) => projectIn(d, prefix))
|
|
645
655
|
const found = findSpecFolder(specArg, dir, searchDirs, preferDirs)
|
|
646
656
|
if (!found) {
|
|
647
657
|
// A SPECLESS BRANCH, but only on the registry's word. `/no-spec` work has a
|
|
@@ -667,7 +677,10 @@ function resolveSpec(specArg, dir, config, opts = {}) {
|
|
|
667
677
|
}
|
|
668
678
|
|
|
669
679
|
const { type, slug } = splitPrefix(found.folder)
|
|
670
|
-
|
|
680
|
+
// The repo's root, not the project folder: `{repo}` names the repo and the
|
|
681
|
+
// worktree layout sits beside it (spec feat-subfolder-project, decision 4).
|
|
682
|
+
const root = repoRootOf(dir, config)
|
|
683
|
+
const { repo, repoSlug } = repoInfo(root)
|
|
671
684
|
const tokens = { repo, repoSlug, slug }
|
|
672
685
|
|
|
673
686
|
const stack = readStackField(found.path, config)
|
|
@@ -693,7 +706,10 @@ function resolveSpec(specArg, dir, config, opts = {}) {
|
|
|
693
706
|
|
|
694
707
|
const worktreeRoot = expandTokens(config.worktree.root, tokens)
|
|
695
708
|
const worktreeFolder = expandTokens(config.worktree.folderPattern, tokens)
|
|
696
|
-
const worktreePath = path.resolve(
|
|
709
|
+
const worktreePath = path.resolve(root, worktreeRoot, worktreeFolder)
|
|
710
|
+
// Where the project sits inside the worktree — what a session stands in and
|
|
711
|
+
// what project-scoped steps run in. The worktree itself when the prefix is ''.
|
|
712
|
+
const projectPath = projectIn(worktreePath, prefixOf(config))
|
|
697
713
|
const projectName = expandTokens(config.docker.projectNamePattern, tokens)
|
|
698
714
|
|
|
699
715
|
return {
|
|
@@ -704,6 +720,10 @@ function resolveSpec(specArg, dir, config, opts = {}) {
|
|
|
704
720
|
worktreeRoot,
|
|
705
721
|
worktreeFolder,
|
|
706
722
|
worktreePath,
|
|
723
|
+
projectPath,
|
|
724
|
+
// The project's folder within the repo, as a repo path ('' at the root) —
|
|
725
|
+
// what turns a git path into a project path (env/project.js).
|
|
726
|
+
prefix: prefixOf(config),
|
|
707
727
|
projectName,
|
|
708
728
|
}
|
|
709
729
|
}
|
|
@@ -755,13 +775,15 @@ function collectSpecFolders(roots) {
|
|
|
755
775
|
function allSpecs(dir, config, worktreePaths, specless = {}) {
|
|
756
776
|
const searchDirs = [...worktreePaths]
|
|
757
777
|
const specs = []
|
|
758
|
-
|
|
778
|
+
const projects = searchDirs.map((d) => projectIn(d, prefixOf(config)))
|
|
779
|
+
for (const folder of collectSpecFolders([dir, ...projects])) {
|
|
759
780
|
try {
|
|
760
781
|
const spec = resolveSpec(folder, dir, config, { searchDirs })
|
|
761
782
|
specs.push({
|
|
762
783
|
folder: spec.folder,
|
|
763
784
|
slug: spec.slug,
|
|
764
785
|
worktreePath: spec.worktreePath,
|
|
786
|
+
projectPath: spec.projectPath,
|
|
765
787
|
specless: false,
|
|
766
788
|
})
|
|
767
789
|
} catch {
|
|
@@ -786,6 +808,7 @@ function allSpecs(dir, config, worktreePaths, specless = {}) {
|
|
|
786
808
|
folder: spec.folder,
|
|
787
809
|
slug: spec.slug,
|
|
788
810
|
worktreePath: spec.worktreePath,
|
|
811
|
+
projectPath: spec.projectPath,
|
|
789
812
|
specless: true,
|
|
790
813
|
})
|
|
791
814
|
}
|
package/src/env/review.js
CHANGED
|
@@ -19,6 +19,7 @@ const fs = require('node:fs')
|
|
|
19
19
|
const path = require('node:path')
|
|
20
20
|
const crypto = require('node:crypto')
|
|
21
21
|
const { readPhases, readOverview } = require('./resolve.js')
|
|
22
|
+
const { fromRepoPath, projectIn } = require('./project.js')
|
|
22
23
|
const { execFileSync } = require('node:child_process')
|
|
23
24
|
|
|
24
25
|
// `-U` large enough that a file's patch IS the file. Reviewing a changed line
|
|
@@ -40,8 +41,13 @@ const REVIEW_DIR = path.join('.spec-env', 'reviews')
|
|
|
40
41
|
// push snapshot that lives among them. The ENGINE decides this, because it knows
|
|
41
42
|
// the spec's own paths — a viewer guessing from regexes would get it wrong the
|
|
42
43
|
// first time someone's product code lived under a folder called `specs`.
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
//
|
|
45
|
+
// `relPath` is a REPO path, and only the project's own `specs/` and `.spec-env/`
|
|
46
|
+
// are bookkeeping: a project in a subfolder of its repo (`prefix`) owns neither
|
|
47
|
+
// folder at the root, and a change beside it — `Sql/` — is code.
|
|
48
|
+
function isNoise(relPath, prefix = '') {
|
|
49
|
+
const rel = fromRepoPath(relPath, prefix)
|
|
50
|
+
return rel !== null && (rel.startsWith('specs/') || rel.startsWith('.spec-env/'))
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -57,8 +63,10 @@ function isNoise(relPath) {
|
|
|
57
63
|
* On a page whose SUBJECT is the spec, applying it folds away every file and
|
|
58
64
|
* renders a page with nothing open on it.
|
|
59
65
|
*/
|
|
60
|
-
function isSpecDocOf(relPath, folder) {
|
|
61
|
-
const
|
|
66
|
+
function isSpecDocOf(relPath, folder, prefix = '') {
|
|
67
|
+
const rel = fromRepoPath(String(relPath), prefix)
|
|
68
|
+
if (rel === null) return false
|
|
69
|
+
const parts = rel.split('/')
|
|
62
70
|
return parts.length > 3 && parts[0] === 'specs' && parts[2] === folder
|
|
63
71
|
}
|
|
64
72
|
|
|
@@ -266,7 +274,10 @@ function collectReview({ spec, git, mode = 'working', ref, base = null, now, not
|
|
|
266
274
|
// reads the spec's worktree, and for those the two are the same path — so
|
|
267
275
|
// `treePath` left null keeps the existing behaviour exactly. The `docs` mode
|
|
268
276
|
// has no worktree to read, which is the whole reason it exists.
|
|
269
|
-
|
|
277
|
+
//
|
|
278
|
+
// `treePath` is a git ROOT, like every tree the readers are bound to — the
|
|
279
|
+
// spec's documents are in the project folder inside it.
|
|
280
|
+
const root = treePath ? projectIn(treePath, spec.prefix || '') : spec.projectPath || spec.worktreePath
|
|
270
281
|
|
|
271
282
|
// AN EXPLICIT FILE SET, or every changed file. `only` is a whitelist of
|
|
272
283
|
// repo-relative paths, and it exists because the `docs` mode reads a tree
|
|
@@ -280,7 +291,8 @@ function collectReview({ spec, git, mode = 'working', ref, base = null, now, not
|
|
|
280
291
|
// else the spec's own documents are the bookkeeping beside the code; on a
|
|
281
292
|
// docs page they are the code, and the companions the project declared (a
|
|
282
293
|
// tracker snapshot, say) are what belongs folded away.
|
|
283
|
-
const
|
|
294
|
+
const prefix = spec.prefix || ''
|
|
295
|
+
const noiseOf = (p) => (mode === 'docs' ? !isSpecDocOf(p, spec.folder, prefix) : isNoise(p, prefix))
|
|
284
296
|
|
|
285
297
|
// THE SURFACES BLOCK, built here so the page never has to know which tiers
|
|
286
298
|
// exist or which of them can be turned on. `null` when the caller passed
|
|
@@ -2579,7 +2591,9 @@ function reviewFileUrl(outPath) {
|
|
|
2579
2591
|
const encoded = path
|
|
2580
2592
|
.resolve(outPath)
|
|
2581
2593
|
.split(path.sep)
|
|
2582
|
-
|
|
2594
|
+
// A Windows drive (`C:`) stays as it is: encoded, `file:///C%3A/…` is a
|
|
2595
|
+
// link no browser opens (chore-windows-ci).
|
|
2596
|
+
.map((seg, i) => (i === 0 && /^[A-Za-z]:$/.test(seg) ? seg : encodeURIComponent(seg)))
|
|
2583
2597
|
.join('/')
|
|
2584
2598
|
return `file://${encoded.startsWith('/') ? '' : '/'}${encoded}`
|
|
2585
2599
|
}
|
package/src/env/reviewers.js
CHANGED
|
@@ -32,6 +32,7 @@ const fs = require('node:fs')
|
|
|
32
32
|
const path = require('node:path')
|
|
33
33
|
const crypto = require('node:crypto')
|
|
34
34
|
const { spawn } = require('node:child_process')
|
|
35
|
+
const { signalGroup } = require('./supervise.js')
|
|
35
36
|
|
|
36
37
|
const BUNDLED_ADAPTERS = { coderabbit: require('./reviewers/coderabbit.js') }
|
|
37
38
|
|
|
@@ -287,7 +288,9 @@ function runReviewer(entry, ctx) {
|
|
|
287
288
|
// Through a shell, deliberately: the config holds a command LINE, with
|
|
288
289
|
// pipes and quoting the project chose. It is read from a committed config
|
|
289
290
|
// in the project's own repo — the same trust level as a package script.
|
|
290
|
-
|
|
291
|
+
// `sh` from PATH on Windows — Git for Windows' — where `/bin/sh` does not
|
|
292
|
+
// exist and no reviewer could run at all (chore-windows-ci).
|
|
293
|
+
child = spawnFn(process.platform === 'win32' ? 'sh' : '/bin/sh', ['-c', rendered], {
|
|
291
294
|
cwd: worktree,
|
|
292
295
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
293
296
|
// THE CHILD LEADS ITS OWN PROCESS GROUP, and the timeout below depends
|
|
@@ -314,15 +317,9 @@ function runReviewer(entry, ctx) {
|
|
|
314
317
|
timedOut = true
|
|
315
318
|
// The group, not the shell: `/bin/sh -c "cr review"` killed on its own
|
|
316
319
|
// leaves the reviewer running and holding the port/rate-limit slot.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
try {
|
|
321
|
-
child.kill('SIGKILL')
|
|
322
|
-
} catch {
|
|
323
|
-
/* already gone */
|
|
324
|
-
}
|
|
325
|
-
}
|
|
320
|
+
// `signalGroup` is the group on POSIX and the process tree on Windows,
|
|
321
|
+
// which has no groups (env/supervise.js).
|
|
322
|
+
signalGroup(child.pid, 'SIGKILL')
|
|
326
323
|
}, entry.timeout * 1000)
|
|
327
324
|
|
|
328
325
|
const settle = (spawnError) => {
|
package/src/env/serve.js
CHANGED
|
@@ -38,6 +38,7 @@ const {
|
|
|
38
38
|
} = require('./resolve.js')
|
|
39
39
|
const { readRegistry } = require('./registry.js')
|
|
40
40
|
const { loadEnvConfig } = require('./config.js')
|
|
41
|
+
const { primaryAnchor, attachProject, repoRootOf, prefixOf, fromRepoPath, toRepoPath } = require('./project.js')
|
|
41
42
|
const { specDocsIn, classifyDirtyTree, dirtyPaths } = require('./classify.js')
|
|
42
43
|
const { liveStateFor } = require('./live.js')
|
|
43
44
|
const { preferRemoteBase } = require('./host.js')
|
|
@@ -219,8 +220,11 @@ ${body}
|
|
|
219
220
|
* file in the tree IS evidence that the tree is being used for something else,
|
|
220
221
|
* and that answer must stay unchanged — see the stays-silent test.
|
|
221
222
|
*/
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
//
|
|
224
|
+
// `p` is a repo path; the project's `specs/.core/` is under its prefix.
|
|
225
|
+
function isProjectBookkeeping(p, prefix = '') {
|
|
226
|
+
const rel = fromRepoPath(String(p), prefix)
|
|
227
|
+
return rel !== null && rel.startsWith('specs/.core/')
|
|
224
228
|
}
|
|
225
229
|
|
|
226
230
|
function docsWorktree(wt, spec, config) {
|
|
@@ -246,18 +250,22 @@ function docsWorktree(wt, spec, config) {
|
|
|
246
250
|
// which is what `--docs` showed from the CLI — a served page that listed a
|
|
247
251
|
// file the run's own report did not would be a different page from the one
|
|
248
252
|
// the reader was told about.
|
|
249
|
-
const intruders = foreign.filter((p) => !isProjectBookkeeping(p))
|
|
253
|
+
const intruders = foreign.filter((p) => !isProjectBookkeeping(p, prefixOf(config)))
|
|
250
254
|
if (!owned.length || intruders.length) return null
|
|
251
255
|
return { owned }
|
|
252
256
|
}
|
|
253
257
|
|
|
254
258
|
function viewFor(dir, config, spec, git, { fallback = false } = {}) {
|
|
255
259
|
if (!spec) return null
|
|
260
|
+
// Every tree a view names is a git ROOT, so the reader bound to it prints
|
|
261
|
+
// root-relative paths and takes root-relative pathspecs. `dir` is the project
|
|
262
|
+
// folder, which is the root unless the project sits in a subfolder.
|
|
263
|
+
const root = repoRootOf(dir, config)
|
|
256
264
|
// LIVE COMES FIRST, because while a spec is live its worktree still exists —
|
|
257
265
|
// detached — and would win the check below while holding none of the work.
|
|
258
266
|
// `live take` checks the branch out HERE, and a fix made while live is made
|
|
259
267
|
// here too, so this checkout is the tree that answers.
|
|
260
|
-
if (spec.branch && headBranchOf(git) === spec.branch) return { kind: 'live', tree:
|
|
268
|
+
if (spec.branch && headBranchOf(git) === spec.branch) return { kind: 'live', tree: root }
|
|
261
269
|
const wt = spec.worktreePath
|
|
262
270
|
if (wt && wt !== dir && fs.existsSync(wt)) {
|
|
263
271
|
// A DOCS WORKTREE IS NOT A CODE WORKTREE, and this used to be unreachable.
|
|
@@ -287,7 +295,7 @@ function viewFor(dir, config, spec, git, { fallback = false } = {}) {
|
|
|
287
295
|
if (docs) return { kind: 'docs', tree: wt, owned: docs.owned }
|
|
288
296
|
return { kind: 'worktree', tree: wt }
|
|
289
297
|
}
|
|
290
|
-
const found = specDocsIn(
|
|
298
|
+
const found = specDocsIn(root, spec, config, trimmedGitReader(root))
|
|
291
299
|
// `error` is cannot-tell — not a page, and not an error page either (rule 4:
|
|
292
300
|
// the harmless branch).
|
|
293
301
|
if (found.error) return null
|
|
@@ -310,9 +318,9 @@ function viewFor(dir, config, spec, git, { fallback = false } = {}) {
|
|
|
310
318
|
// omits them in the first place. A direct request is someone opening an
|
|
311
319
|
// address they were given, and that has to keep resolving.
|
|
312
320
|
if (!fallback) return null
|
|
313
|
-
const committed = committedDocsFor(
|
|
321
|
+
const committed = committedDocsFor(root, config, spec)
|
|
314
322
|
if (!committed) return null
|
|
315
|
-
return { kind: 'docs-committed', tree:
|
|
323
|
+
return { kind: 'docs-committed', tree: root, owned: committed }
|
|
316
324
|
}
|
|
317
325
|
|
|
318
326
|
/**
|
|
@@ -322,9 +330,9 @@ function viewFor(dir, config, spec, git, { fallback = false } = {}) {
|
|
|
322
330
|
* that is no spec at all must stay a 404 rather than render an empty page with
|
|
323
331
|
* a commit button on it.
|
|
324
332
|
*/
|
|
325
|
-
function committedDocsFor(
|
|
326
|
-
const git = trimmedGitReader(
|
|
327
|
-
const out = git(['ls-files', '--', `specs/*/${spec.folder}
|
|
333
|
+
function committedDocsFor(root, config, spec) {
|
|
334
|
+
const git = trimmedGitReader(root)
|
|
335
|
+
const out = git(['ls-files', '--', toRepoPath(`specs/*/${spec.folder}/*`, prefixOf(config))])
|
|
328
336
|
if (out == null) return null
|
|
329
337
|
const paths = String(out)
|
|
330
338
|
.split('\n')
|
|
@@ -1035,6 +1043,9 @@ if (require.main === module) {
|
|
|
1035
1043
|
}
|
|
1036
1044
|
const { dir, port, host, token } = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'))
|
|
1037
1045
|
const { config } = loadEnvConfig(dir)
|
|
1046
|
+
// `dir` is the project folder the CLI anchored on; re-derive where it sits in
|
|
1047
|
+
// its repo so worktree paths resolve beside the repo, as the CLI's do.
|
|
1048
|
+
attachProject(config, primaryAnchor(dir, trimmedGitReader(dir)))
|
|
1038
1049
|
const server = createReviewServer({ ...serverHooks(dir, config), token })
|
|
1039
1050
|
startReviewServer(server, { port, host }).then(
|
|
1040
1051
|
() => {},
|
package/src/env/supervise.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
const fs = require('node:fs')
|
|
14
14
|
const path = require('node:path')
|
|
15
|
-
const { spawn } = require('node:child_process')
|
|
15
|
+
const { spawn, spawnSync } = require('node:child_process')
|
|
16
16
|
|
|
17
17
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
18
18
|
|
|
@@ -34,7 +34,18 @@ function isAlive(pid) {
|
|
|
34
34
|
// Signal a detached process's whole group (its leader pid is `pid`, so the group
|
|
35
35
|
// id is `-pid`) — reaches children like vite/tsc that a bare `pnpm dev` spawns.
|
|
36
36
|
// Falls back to signalling just the leader if the group send fails.
|
|
37
|
-
|
|
37
|
+
//
|
|
38
|
+
// WINDOWS HAS NO PROCESS GROUPS: `-pid` throws, the fallback kills only the
|
|
39
|
+
// `sh` wrapper, and the server it started survives — holding its port and its
|
|
40
|
+
// worktree, which then cannot be removed (chore-windows-ci). `taskkill /T` walks
|
|
41
|
+
// the tree instead; `/F` for both signals, because a console process ignores
|
|
42
|
+
// the polite close a bare `taskkill` sends. Run with an argument list, never a
|
|
43
|
+
// shell. `opts` is injectable for tests.
|
|
44
|
+
function signalGroup(pid, sig, { platform = process.platform, run = spawnSync } = {}) {
|
|
45
|
+
if (platform === 'win32') {
|
|
46
|
+
run('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
|
|
47
|
+
return
|
|
48
|
+
}
|
|
38
49
|
try {
|
|
39
50
|
process.kill(-pid, sig)
|
|
40
51
|
} catch {
|
|
@@ -81,6 +92,8 @@ function startProcess(proc, { cwd, rootDir, spawnImpl = spawn }) {
|
|
|
81
92
|
cwd,
|
|
82
93
|
env: { ...process.env, ...proc.env },
|
|
83
94
|
detached: true,
|
|
95
|
+
// No console window per dev server on Windows; nothing anywhere else.
|
|
96
|
+
windowsHide: true,
|
|
84
97
|
stdio: ['ignore', out, out],
|
|
85
98
|
})
|
|
86
99
|
child.unref()
|
package/src/env/teardown.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
const { expandTokens } = require('./resolve.js')
|
|
25
25
|
const { composeFileArg } = require('./provision.js')
|
|
26
|
+
const { shellPath } = require('./project.js')
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* @param {object} spec resolved spec: { slug, branch, worktreePath, projectName, ... }
|
|
@@ -131,7 +132,7 @@ function planDown(spec, config, flags, ctx) {
|
|
|
131
132
|
commands.push(
|
|
132
133
|
force
|
|
133
134
|
? `git worktree remove --force ${spec.worktreePath}`
|
|
134
|
-
: `git worktree remove ${spec.worktreePath}`,
|
|
135
|
+
: `git worktree remove ${shellPath(spec.worktreePath)}`,
|
|
135
136
|
)
|
|
136
137
|
|
|
137
138
|
// --- delete the branch ---
|
|
@@ -282,8 +283,8 @@ function planDownCheckout(spec, config, flags, ctx) {
|
|
|
282
283
|
}
|
|
283
284
|
|
|
284
285
|
const commands = []
|
|
285
|
-
if (onBranch !== false) commands.push(`git -C ${checkoutPath} switch ${base}`)
|
|
286
|
-
commands.push(`git -C ${checkoutPath} branch ${landed ? '-D' : '-d'} ${spec.branch}`)
|
|
286
|
+
if (onBranch !== false) commands.push(`git -C ${shellPath(checkoutPath)} switch ${base}`)
|
|
287
|
+
commands.push(`git -C ${shellPath(checkoutPath)} branch ${landed ? '-D' : '-d'} ${spec.branch}`)
|
|
287
288
|
return { ...result, commands }
|
|
288
289
|
}
|
|
289
290
|
|
package/src/init.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
const fs = require('fs')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const crypto = require('crypto')
|
|
6
|
+
const { execFileSync } = require('child_process')
|
|
6
7
|
|
|
7
8
|
const { ensureWorktreeDirTrusted } = require('./env/trust.js')
|
|
8
9
|
const { ensureHooks } = require('./env/hooks.js')
|
|
9
10
|
const { repoInfo, expandTokens } = require('./env/resolve.js')
|
|
11
|
+
const { primaryAnchor } = require('./env/project.js')
|
|
10
12
|
|
|
11
13
|
const ASSETS = path.join(__dirname, '..', 'assets')
|
|
12
14
|
|
|
@@ -286,8 +288,11 @@ const RETIRED_FILES = [
|
|
|
286
288
|
path.join('specs', 'complete', '00-index.md'),
|
|
287
289
|
]
|
|
288
290
|
|
|
291
|
+
// `/`-separated on every platform: these are the manifest's keys and the
|
|
292
|
+
// report's lines, and a Windows install recording `specs\\.core\\…` would read
|
|
293
|
+
// as a different file to every other machine (chore-windows-ci).
|
|
289
294
|
function rel(dir, p) {
|
|
290
|
-
return path.relative(dir, p) || '.'
|
|
295
|
+
return path.relative(dir, p).split(path.sep).join('/') || '.'
|
|
291
296
|
}
|
|
292
297
|
|
|
293
298
|
function ensureDir(p) {
|
|
@@ -310,8 +315,22 @@ const MANIFEST_VERSION = 1
|
|
|
310
315
|
// reset each init() alongside `report`.
|
|
311
316
|
const writtenHashes = {}
|
|
312
317
|
|
|
318
|
+
// Every judgement about a managed file compares content with its line endings
|
|
319
|
+
// normalised. On Windows with `core.autocrlf=true` a checkout rewrites LF to
|
|
320
|
+
// CRLF, and an exact compare read that conversion as the user's edit: every
|
|
321
|
+
// skill, command and rule became "your edit — kept" and stopped updating.
|
|
322
|
+
// Assets ship LF, so hashes of LF files — every manifest already written — are
|
|
323
|
+
// unchanged by this.
|
|
324
|
+
function normalizeEol(content) {
|
|
325
|
+
return content.replace(/\r\n/g, '\n')
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function sameContent(a, b) {
|
|
329
|
+
return normalizeEol(a) === normalizeEol(b)
|
|
330
|
+
}
|
|
331
|
+
|
|
313
332
|
function sha1(content) {
|
|
314
|
-
return crypto.createHash('sha1').update(content).digest('hex')
|
|
333
|
+
return crypto.createHash('sha1').update(normalizeEol(content)).digest('hex')
|
|
315
334
|
}
|
|
316
335
|
|
|
317
336
|
// The full managed set for a target dir: repo-relative path, absolute path, and
|
|
@@ -349,10 +368,18 @@ function readManifest(dir) {
|
|
|
349
368
|
try {
|
|
350
369
|
const parsed = JSON.parse(fs.readFileSync(path.join(dir, MANIFEST_FILE), 'utf8'))
|
|
351
370
|
if (parsed && typeof parsed === 'object' && parsed.files && typeof parsed.files === 'object') {
|
|
371
|
+
// KEYS ARE `/`-SEPARATED ON READ, whoever wrote them. A Windows install
|
|
372
|
+
// before chore-windows-ci recorded `.claude\\skills\\…`; looked up by the
|
|
373
|
+
// `/` paths every caller now uses, its records went missing — and a
|
|
374
|
+
// missing record is what turns a user's edited retired file into one
|
|
375
|
+
// that gets deleted. No managed path contains a backslash, so this
|
|
376
|
+
// cannot merge two genuine entries.
|
|
377
|
+
const files = {}
|
|
378
|
+
for (const [key, hash] of Object.entries(parsed.files)) files[key.replace(/\\/g, '/')] = hash
|
|
352
379
|
return {
|
|
353
380
|
version: parsed.version || MANIFEST_VERSION,
|
|
354
|
-
files
|
|
355
|
-
baselined: Object.keys(
|
|
381
|
+
files,
|
|
382
|
+
baselined: Object.keys(files).length > 0,
|
|
356
383
|
}
|
|
357
384
|
}
|
|
358
385
|
} catch {
|
|
@@ -406,10 +433,13 @@ function writeManifest(dir, files) {
|
|
|
406
433
|
// `pruneRetiredManaged` passes no `bundled` on purpose: the package no longer
|
|
407
434
|
// ships that file, so there is nothing to compare it against.
|
|
408
435
|
function managedState(dir, relPath, manifest, bundled) {
|
|
436
|
+
// Manifest keys are `/`-separated; a caller holding an OS path still finds
|
|
437
|
+
// its file's record (chore-windows-ci).
|
|
438
|
+
relPath = String(relPath).split(path.sep).join('/')
|
|
409
439
|
const abs = path.join(dir, relPath)
|
|
410
440
|
if (!fs.existsSync(abs)) return 'missing'
|
|
411
441
|
const onDisk = fs.readFileSync(abs, 'utf8')
|
|
412
|
-
if (bundled !== undefined && onDisk
|
|
442
|
+
if (bundled !== undefined && sameContent(onDisk, bundled)) return 'pristine'
|
|
413
443
|
const known = manifest.files[relPath]
|
|
414
444
|
if (known) return sha1(onDisk) === known ? 'pristine' : 'customized'
|
|
415
445
|
return manifest.baselined ? 'adopted' : 'customized'
|
|
@@ -715,8 +745,18 @@ function trustWorktreeRoot(dir) {
|
|
|
715
745
|
report.warnings.push('could not read worktree.root — skipped trusting the worktree dir')
|
|
716
746
|
return
|
|
717
747
|
}
|
|
718
|
-
|
|
719
|
-
|
|
748
|
+
// Resolved against the REPO's root, and named for it, exactly as `spec-env`
|
|
749
|
+
// resolves it — `dir` is the project folder, which is a subfolder of the repo
|
|
750
|
+
// for some projects (feat-subfolder-project). Not a repo → `dir`, as before.
|
|
751
|
+
const anchor = primaryAnchor(dir, (args) => {
|
|
752
|
+
try {
|
|
753
|
+
return execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
|
|
754
|
+
} catch {
|
|
755
|
+
return null
|
|
756
|
+
}
|
|
757
|
+
})
|
|
758
|
+
const { repo, repoSlug } = repoInfo(anchor.root)
|
|
759
|
+
const rootAbs = path.resolve(anchor.root, expandTokens(root, { repo, repoSlug }))
|
|
720
760
|
const res = ensureWorktreeDirTrusted(dir, rootAbs)
|
|
721
761
|
const label = '.claude/settings.local.json (trusted worktree root)'
|
|
722
762
|
if (res.reason === 'malformed') {
|
|
@@ -777,7 +817,7 @@ function checkSync(dir, { claudeMd = true, log = console.log } = {}) {
|
|
|
777
817
|
else if (state === 'customized') rows.push([relPath, 'your edit — kept (--force overwrites)'])
|
|
778
818
|
else if (state === 'adopted')
|
|
779
819
|
rows.push([relPath, 'adopted upstream — yours kept, theirs not installed (--force takes theirs)'])
|
|
780
|
-
else if (fs.readFileSync(abs, 'utf8')
|
|
820
|
+
else if (!sameContent(fs.readFileSync(abs, 'utf8'), bundled)) rows.push([relPath, 'out of date — would be updated'])
|
|
781
821
|
}
|
|
782
822
|
const section = claudeMd ? claudeMdSectionState(dir) : 'fresh'
|
|
783
823
|
// A healthy area says NOTHING. A report that lists what is already fine is a
|
|
@@ -876,7 +916,7 @@ function resyncManagedFile(dir, target, manifest, force) {
|
|
|
876
916
|
return report[state].push({ relPath, added, removed, hunks })
|
|
877
917
|
}
|
|
878
918
|
// pristine — update only if the bundled content actually changed
|
|
879
|
-
if (fs.readFileSync(abs, 'utf8')
|
|
919
|
+
if (sameContent(fs.readFileSync(abs, 'utf8'), bundled)) {
|
|
880
920
|
// The file is ours and current, but the manifest disagreed — record the
|
|
881
921
|
// repair rather than healing in silence: a file that quietly starts
|
|
882
922
|
// updating again is as opaque as one that quietly stopped.
|
|
@@ -473,7 +473,7 @@ function specSyncRecord(dir, config, specArg, out) {
|
|
|
473
473
|
const snapshotDir = resolveOrExit(specArg, dir, out)
|
|
474
474
|
if (!snapshotDir) return 1
|
|
475
475
|
const file = recordPush({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config })
|
|
476
|
-
out.write(`${PROGRAM} record: snapshot written — ${path.relative(dir, file)}\n`)
|
|
476
|
+
out.write(`${PROGRAM} record: snapshot written — ${path.relative(dir, file).split(path.sep).join('/')}\n`)
|
|
477
477
|
return 0
|
|
478
478
|
}
|
|
479
479
|
|
|
@@ -813,6 +813,8 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
|
|
|
813
813
|
}
|
|
814
814
|
const report = kit.ticketsInRange(read.commits, {
|
|
815
815
|
ignorePaths: (config.release && config.release.ignorePaths) || [],
|
|
816
|
+
// A nested project's commits carry its folder in every path (feat-subfolder-project).
|
|
817
|
+
prefix: kit.projectPrefixOf(dir),
|
|
816
818
|
})
|
|
817
819
|
report.tickets = kit.nameTickets(report.tickets, listSpecs(dir, config, { urls: true }))
|
|
818
820
|
if (flags.json) {
|
|
@@ -83,6 +83,9 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
83
83
|
const identifier = helpers.linkedIdentifier(path.join(snapshotDir, overviewFile), config)
|
|
84
84
|
const lines = []
|
|
85
85
|
const result = { issue: null, subIssues: {} }
|
|
86
|
+
// Which items this apply carried a state for — the snapshot records today's
|
|
87
|
+
// state name for these and only these (`recordPush`).
|
|
88
|
+
const sent = { issue: !!(plan.issue && plan.issue.state != null), subIssues: new Set() }
|
|
86
89
|
// Handed out immediately, so a throw from anywhere below still reports what
|
|
87
90
|
// had been stamped by the time it happened.
|
|
88
91
|
if (progress) progress.result = result
|
|
@@ -167,6 +170,7 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
167
170
|
const file = resolvePhaseFileIn(snapshotDir, sub.ref)
|
|
168
171
|
if (!file) throw new Error(`no phase file for ref ${sub.ref}`)
|
|
169
172
|
stampSubIssueId(snapshotDir, file, created.identifier, config)
|
|
173
|
+
if (sub.state != null) sent.subIssues.add(String(created.identifier))
|
|
170
174
|
result.subIssues[sub.ref] = created.identifier
|
|
171
175
|
lines.push(` sub-issue created: ${sub.ref} → ${created.identifier}`)
|
|
172
176
|
}
|
|
@@ -193,6 +197,7 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
193
197
|
sub = spliced(sub, 'goal', before, config, sub.id, lines)
|
|
194
198
|
}
|
|
195
199
|
await ops.updateSubIssue(sub)
|
|
200
|
+
if (sub.state != null) sent.subIssues.add(String(sub.id))
|
|
196
201
|
result.subIssues[sub.ref || refById.get(String(sub.id)) || sub.id] = sub.id
|
|
197
202
|
lines.push(` sub-issue updated: ${sub.id}`)
|
|
198
203
|
}
|
|
@@ -212,8 +217,10 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
212
217
|
const lost = verify.some((l) => l.includes('!!') || l.includes('??'))
|
|
213
218
|
|
|
214
219
|
// 7. Record the snapshot from the now-stamped files, so the next push is empty.
|
|
215
|
-
const file = recordPush({ dir, snapshotDir, identifier: helpers.specIdentifier(snapshotDir, config), config })
|
|
216
|
-
|
|
220
|
+
const file = recordPush({ dir, snapshotDir, identifier: helpers.specIdentifier(snapshotDir, config), config, sent })
|
|
221
|
+
// A repo path, `/`-separated on every platform — the form every other
|
|
222
|
+
// spec path in this output takes.
|
|
223
|
+
lines.push(` snapshot: ${path.relative(dir, file).split(path.sep).join('/')}`)
|
|
217
224
|
return { result, lines, lost }
|
|
218
225
|
}
|
|
219
226
|
|
|
@@ -63,7 +63,7 @@ function storePath(env = process.env, homedir = os.homedir) {
|
|
|
63
63
|
* `absent` (no file — the normal default, not a problem), `permissions`
|
|
64
64
|
* (group/world readable), `unreadable`, `malformed`.
|
|
65
65
|
*/
|
|
66
|
-
function readStore(file, { stat = fs.statSync, read = fs.readFileSync } = {}) {
|
|
66
|
+
function readStore(file, { stat = fs.statSync, read = fs.readFileSync, platform = process.platform } = {}) {
|
|
67
67
|
let info
|
|
68
68
|
try {
|
|
69
69
|
info = stat(file)
|
|
@@ -74,7 +74,12 @@ function readStore(file, { stat = fs.statSync, read = fs.readFileSync } = {}) {
|
|
|
74
74
|
return { ok: false, code: 'unreadable', path: file, reason: `cannot read ${file}: ${err.message}` }
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
// ON WINDOWS THE MODE BITS SAY NOTHING. Node reports every file there as
|
|
78
|
+
// 0o666, so this check refused every store on Windows and no stored
|
|
79
|
+
// credential could ever be read (chore-windows-ci). Access there is the
|
|
80
|
+
// profile directory's ACL, which these bits do not describe — cannot tell,
|
|
81
|
+
// and cannot-tell does not accuse (`.claude/rules/negative-checks.md`).
|
|
82
|
+
if (platform !== 'win32' && info.mode & GROUP_OR_WORLD) {
|
|
78
83
|
const mode = (info.mode & 0o777).toString(8)
|
|
79
84
|
return {
|
|
80
85
|
ok: false,
|