@skitterbyte/skitterspec 23.14.0 → 23.16.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/README.md +1 -0
- package/assets/core/env.config.md +5 -0
- package/assets/rules/spec-planning.md +12 -0
- package/assets/rules/spec-reports.md +15 -0
- package/assets/skills/spec/SKILL.md +30 -0
- package/assets/skills/spec-complete/SKILL.md +12 -2
- package/assets/skills/spec-idea/SKILL.md +115 -0
- package/assets/skills/spec-init/SKILL.md +3 -2
- package/assets/skills/spec-todo/SKILL.md +3 -0
- package/package.json +1 -1
- package/src/cli.js +81 -27
- package/src/env/config.js +7 -0
- package/src/env/projectguard.js +1 -1
- package/src/env/review.js +66 -1
- package/src/env/reviewers.js +5 -4
- package/src/env/supervise.js +71 -9
- package/src/idea.js +190 -0
- package/src/ideacmd.js +242 -0
- package/src/tada/todo.js +6 -1
package/README.md
CHANGED
|
@@ -31,6 +31,7 @@ demand, host dev servers on reserved ports — and everything below.
|
|
|
31
31
|
| `/spec-cancel` | Record why, stamp the header, tear down |
|
|
32
32
|
| `/spec-tada` | A ta-da list: what you did today, by project and by spec, plus a standup |
|
|
33
33
|
| `/spec-todo` | Where you left off on your last working day, what is open and what is waiting on you |
|
|
34
|
+
| `/spec-idea` | Capture an idea without specing it — in the tracker or `specs/ideas.md` — and list or drop the ones waiting |
|
|
34
35
|
| `/spec-init` | Bootstrap or repair the workflow in a project |
|
|
35
36
|
| `/spec-connect` | Point your canonical `localhost` ports at one spec's stack |
|
|
36
37
|
| `/spec-live` | Check one spec out in the primary checkout, so your running server reloads it |
|
|
@@ -514,6 +514,11 @@ through to a documented conservative default; see the field notes below.
|
|
|
514
514
|
// "local" — you are at the machine holding the page; it binds 127.0.0.1.
|
|
515
515
|
// "remote" — you are not; it binds every interface so the page opens.
|
|
516
516
|
// "detect" — work it out (the default); cannot-tell binds 127.0.0.1.
|
|
517
|
+
// SKITTERSPEC_READER=local|remote in the environment outranks this key: a
|
|
518
|
+
// wrapper that runs the engine on another machine (a VM's `prlctl exec`)
|
|
519
|
+
// speaks for that machine alone. A reader on another machine — this key or
|
|
520
|
+
// that variable set to "remote", or ssh — gets no `local` tier while
|
|
521
|
+
// `network` has a URL, since 127.0.0.1 is the engine's machine.
|
|
517
522
|
// An explicit "local"/"remote" is BELIEVED WITHOUT SNIFFING: you know where
|
|
518
523
|
// you are reading, and no signal outranks being told. Detection is only the
|
|
519
524
|
// default, and it has three outcomes rather than two — local, remote, and
|
|
@@ -12,6 +12,7 @@ and lifecycle stay consistent. Each sets a status on the spec header
|
|
|
12
12
|
| `/spec-hotfix` | (Hotfix) Fork a worktree from a release tag, red→green, land by tag + cherry-pick | `In Progress` | `specs/in-progress/` |
|
|
13
13
|
| `/spec-incident` | (Incident) Capture a live outage as a record written during it — grill, write in flight, fixes as separate linked specs | `In Progress` | `specs/in-progress/` |
|
|
14
14
|
| `/no-spec` | Work that genuinely has no spec — its own branch, worktree, page and land. Writes no spec and moves nothing through the lifecycle | `—` | (none) |
|
|
15
|
+
| `/spec-idea` | Capture an idea without specing it — in the tracker when the provider holds ideas, else `specs/ideas.md` on the base branch; bare lists, `--drop` discards. `/spec idea:<id>` or `/spec #N` promotes one | `—` | (none) |
|
|
15
16
|
| `/spec-review` | Re-validate a spec against the codebase; refresh stale parts | `—` | (unchanged) |
|
|
16
17
|
| `/spec-start` | Put a spec in flight — provision its branch, then build phase 1 | `In Progress` | `specs/in-progress/` |
|
|
17
18
|
| `/spec-next` | Build the next phase of the spec this session is in (re-run per phase) | `In Progress` (unchanged) | (unchanged) |
|
|
@@ -74,6 +75,17 @@ branch. Beneath it, `skitterspec spec-env nospec <name>` records the branch —
|
|
|
74
75
|
and that record is what makes a name with nothing under `specs/**` resolvable by
|
|
75
76
|
`review`, `integrate`, `down` and a bare `resolve`.
|
|
76
77
|
|
|
78
|
+
**`/spec-idea` is the door before `/spec`.** `/spec` grills until there is a
|
|
79
|
+
spec, which is right for work and wrong for a passing thought. This skill files
|
|
80
|
+
the thought as it stands, somewhere the team can see. An idea is not a spec,
|
|
81
|
+
so it has no folder, no status and no branch. It lives in the tracker when the
|
|
82
|
+
provider can hold ideas (an issue kept off the board, which `/spec #N` already
|
|
83
|
+
adopts), and otherwise in `specs/ideas.md`. That file is committed straight
|
|
84
|
+
onto the base branch by `skitterspec idea`, using plumbing, so no checkout is
|
|
85
|
+
switched or left dirty, and it is never pushed for you. A configured provider
|
|
86
|
+
that does not declare an idea store is cannot-tell: capture refuses and hands
|
|
87
|
+
the text back, rather than putting one idea in each store.
|
|
88
|
+
|
|
77
89
|
**`/spec-tada` reads, and moves nothing.** It is in the table because it
|
|
78
90
|
reports in the unit the table is about — a spec — but it changes no status,
|
|
79
91
|
writes no file and commits nothing. `skitterspec tada` reads Claude Code's own
|
|
@@ -164,6 +164,21 @@ on. Dropping the line is what left a reader who had walked out of the house with
|
|
|
164
164
|
nothing on screen to tell them a remote page was even possible — they could not
|
|
165
165
|
ask for what they could not see.
|
|
166
166
|
|
|
167
|
+
**One exception: a reader on another machine sees no `local` line.** This is
|
|
168
|
+
the third amendment, and it argues from the rule's own reason. The rule keeps a
|
|
169
|
+
line so the reader can see a door they could ask to have opened. But when the
|
|
170
|
+
engine runs on one machine and the reader is on another — a wrapper running it
|
|
171
|
+
inside a VM, or an ssh session — `127.0.0.1` is the engine's machine, not the
|
|
172
|
+
reader's. That door never opens, whatever anyone asks. It was also first in the
|
|
173
|
+
stack, the link habit reaches for, and it cost a timeout on every review. So the
|
|
174
|
+
engine hides it, on a signal someone set on purpose: `SKITTERSPEC_READER=remote`
|
|
175
|
+
(`local` outranks ssh), the committed `review.reader`, or ssh. It hides it only
|
|
176
|
+
when `network` has a URL to take its place; otherwise the line stays and says
|
|
177
|
+
it is unreachable. Detection decides nothing here, and nor does the skill. A
|
|
178
|
+
tier marked `hidden` in `--json` is absent from the printed stack, so copying
|
|
179
|
+
the stack still produces the right banner. The holding line names the engine's
|
|
180
|
+
`covers` — *the wait covers network* — never a door the stack did not show.
|
|
181
|
+
|
|
167
182
|
**The `network` tier may carry alternates, and they are part of it — not a fourth tier.**
|
|
168
183
|
The engine offers the other addresses this machine has (a
|
|
169
184
|
tailnet one, for a reader off the wifi) as `also:` lines under `network`, each
|
|
@@ -21,6 +21,36 @@ separate grooming command — `/spec` grills to a Ready spec directly.)
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
## Phase 0b — start from an idea (only when asked)
|
|
25
|
+
|
|
26
|
+
**Only when the invocation names an idea** with `idea:<id>`, a handle that
|
|
27
|
+
`/spec-idea` lists for an idea kept in `specs/ideas.md`. An idea kept in the
|
|
28
|
+
tracker is an ordinary issue, so `/spec #N` adopts it through Phase 0 above,
|
|
29
|
+
and nothing here applies to it.
|
|
30
|
+
|
|
31
|
+
1. **Read it.** Run `skitterspec idea list --json` and find the entry whose
|
|
32
|
+
`id` matches. If none does, **stop** and say so: an id that matches nothing
|
|
33
|
+
is never stood in for by the nearest one.
|
|
34
|
+
2. **Seed, don't skip, the grill.** The idea's title becomes the working spec
|
|
35
|
+
title, and its body becomes the starting material for **Problem**. Quote it
|
|
36
|
+
rather than paraphrasing it away. An idea is a thought, not a groomed
|
|
37
|
+
requirement, so grill it as hard as anything else.
|
|
38
|
+
3. **Retire it once the spec exists — never before.** The idea is dropped
|
|
39
|
+
after the spec reaches somewhere it can be found. With isolation, that is
|
|
40
|
+
once a committing verdict has committed it (and landed it, under
|
|
41
|
+
`"trunk"`). Without isolation, it is once the spec is written. Run:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
skitterspec idea drop <id> --reason "promoted to <spec-name>"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
It commits onto the base branch by itself, so it needs no pathspec and has
|
|
48
|
+
no part in the spec's own commit. A drop that is refused leaves the idea
|
|
49
|
+
listed. Say so in `Notes` and carry on: a stale idea is a nuisance, but a
|
|
50
|
+
lost one is the failure this exists to prevent.
|
|
51
|
+
**A run that writes no spec drops nothing** — a `⏸` grill and a
|
|
52
|
+
`discuss` verdict both leave the idea where it was.
|
|
53
|
+
|
|
24
54
|
## Phase A — reach a clear shared understanding (grill first)
|
|
25
55
|
|
|
26
56
|
Interview the user until requirement AND proposed solution are unambiguous. Do
|
|
@@ -408,6 +408,10 @@ person happens before the ready, in this order:
|
|
|
408
408
|
— run 2 moves it on base after the merge; under `branch` commit the move on
|
|
409
409
|
the branch *before* step 3 so it rides the PR. Either way
|
|
410
410
|
**the tracker's Done waits for run 2**: a ready PR is not a merged one.
|
|
411
|
+
Under `branch` the §4 tracker step still runs here, but holding the state
|
|
412
|
+
(`--hold-state`, as the step says), so the snapshot run 2 would write is in
|
|
413
|
+
the commit that rides the PR. Otherwise run 2 leaves it modified on the base
|
|
414
|
+
branch, where nothing is left to commit it to.
|
|
411
415
|
5. **Stop, keeping the worktree.** Report
|
|
412
416
|
`Landed: PR #N opened — finish after merge` (or `ready`), spec
|
|
413
417
|
`In Progress`, worktree standing. No afterLand runs — the plan deferred it
|
|
@@ -417,13 +421,19 @@ person happens before the ready, in this order:
|
|
|
417
421
|
**Run 2 — after the host merges.** `integrate` recognises the landed branch
|
|
418
422
|
(ancestry or the host's answer) and prints the finish: catch local base up and
|
|
419
423
|
the deferred `afterLand` with the land's own range. Run those, then do what run
|
|
420
|
-
1 deferred — the §4 move (trunk lane) with its State log row and commit,
|
|
421
|
-
|
|
424
|
+
1 deferred — the §4 move (trunk lane) with its State log row and commit, or
|
|
425
|
+
under `branch` the held state alone (`--send-held`, which writes nothing to the
|
|
426
|
+
tree), the §5 report — then **§7 teardown runs as normal**:
|
|
422
427
|
a host-merged branch counts as landed (squash and rebase
|
|
423
428
|
merges included), and a host that auto-deleted the branch makes the remote
|
|
424
429
|
delete an already-gone no-op, never a failure. Re-test on base before calling
|
|
425
430
|
it done, exactly as 6-feature/bug step 4.
|
|
426
431
|
|
|
432
|
+
Where `--send-held` reports that nothing was held — a run 1 from before the
|
|
433
|
+
hold existed — it has sent the whole plan, and its line names the snapshot it
|
|
434
|
+
left modified on base. Put that in the report's `Notes`: only the operator can
|
|
435
|
+
choose where that file goes.
|
|
436
|
+
|
|
427
437
|
## 7. Tear down the environment (opt-in, only if configured)
|
|
428
438
|
|
|
429
439
|
**A hotfix is torn down later, by `hotfix finish`.**
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spec-idea
|
|
3
|
+
description: Capture an idea for a future spec without specing it — one step, no grilling — somewhere the team can see it (the tracker when a provider holds ideas, else specs/ideas.md on the base branch). Bare, it lists the ideas waiting; --drop discards one. Use when the user says "/spec-idea", "note this idea", "park this for later", "add to the ideas list", "what ideas do we have", or wants to get a thought down without writing a spec.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /spec-idea — capture now, spec later
|
|
7
|
+
|
|
8
|
+
> Stay silent while this runs — speak only to ask something you cannot answer
|
|
9
|
+
> yourself, or to report a failure at the moment it happens. Read
|
|
10
|
+
> `.claude/rules/spec-reports.md` before reporting; it defines the block this
|
|
11
|
+
> skill ends with.
|
|
12
|
+
|
|
13
|
+
`/spec` grills until there is a spec. That is right for work and wrong for a
|
|
14
|
+
passing thought, which then gets specced too early or not written down at all.
|
|
15
|
+
This skill is the other door: it files the thought as it stands, and the grill
|
|
16
|
+
happens later, when someone promotes it with `/spec`.
|
|
17
|
+
|
|
18
|
+
**The engine decides where an idea lives — never you.** `skitterspec idea`
|
|
19
|
+
uses the tracker when the installed provider holds ideas (an issue kept off the
|
|
20
|
+
board), and `specs/ideas.md` on the base branch when there is no provider or
|
|
21
|
+
the provider says it cannot. A configured provider that says nothing is
|
|
22
|
+
cannot-tell, and the engine refuses rather than splitting ideas across two
|
|
23
|
+
stores. Relay what it decided; do not second-guess it.
|
|
24
|
+
|
|
25
|
+
## 1. Pick the mode from the arguments
|
|
26
|
+
|
|
27
|
+
| Invocation | Mode |
|
|
28
|
+
|------------|------|
|
|
29
|
+
| `/spec-idea <text>` | capture |
|
|
30
|
+
| `/spec-idea` (bare), "what ideas do we have" | list |
|
|
31
|
+
| `/spec-idea --drop <ref> [reason]` | drop |
|
|
32
|
+
|
|
33
|
+
## 2. Capture
|
|
34
|
+
|
|
35
|
+
**Ask nothing by default.** Getting the thought out of someone's head is the
|
|
36
|
+
whole point, and every question is a reason not to bother.
|
|
37
|
+
|
|
38
|
+
**One judgement, made once.** Read the text. If it is asking for design rather
|
|
39
|
+
than recording a thought — questions addressed to you, "suggestions welcome",
|
|
40
|
+
several alternatives left open for someone to weigh — it wants the grill now.
|
|
41
|
+
Offer the choice once, with a picker:
|
|
42
|
+
|
|
43
|
+
- **Grill it now with `/spec`.** Invoke `/spec` and seed it with the text. The
|
|
44
|
+
idea is not filed, because the spec will record it.
|
|
45
|
+
- **File it as an idea.** File it exactly as typed.
|
|
46
|
+
|
|
47
|
+
A short or rough thought is not a design question. When in doubt, file it: an
|
|
48
|
+
idea can always be promoted, but a grill that nobody asked for is the cost this
|
|
49
|
+
skill exists to remove.
|
|
50
|
+
|
|
51
|
+
To file it, pass the text as **one argument**, newlines included. The first
|
|
52
|
+
line becomes the title and the rest becomes the body:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
skitterspec idea add "<text>" --json
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Never push.** On the file store the engine commits onto the base branch and
|
|
59
|
+
prints the push instead of running it, because a push publishes the base
|
|
60
|
+
branch and that is always the operator's call.
|
|
61
|
+
|
|
62
|
+
**A refused capture loses nothing.** The engine prints the text back. Put it in
|
|
63
|
+
the `Why` row verbatim so the user can copy it.
|
|
64
|
+
|
|
65
|
+
## 3. List
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
skitterspec idea list
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Relay the ideas as a table in the body of the message, one row per idea:
|
|
72
|
+
title, date, and the handle that promotes it. That is `/spec idea:<id>` for a
|
|
73
|
+
file idea, and `/spec #N` (or the provider's own reference) for a tracker idea.
|
|
74
|
+
An empty list is an answer, so say it is empty.
|
|
75
|
+
|
|
76
|
+
## 4. Drop
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
skitterspec idea drop <ref> --reason "<reason>"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Pass the reason when one was given. **Do not ask for one** — dropping a
|
|
83
|
+
thought should cost no more than having it. On the tracker the idea is closed
|
|
84
|
+
as not planned. In the file the entry is removed and the reason goes in the
|
|
85
|
+
commit, where git keeps it.
|
|
86
|
+
|
|
87
|
+
## Promotion is `/spec`'s, not this skill's
|
|
88
|
+
|
|
89
|
+
`/spec idea:<id>` or `/spec #N` turns an idea into a spec. It seeds the grill
|
|
90
|
+
from the idea and retires the idea once the spec exists. This skill never
|
|
91
|
+
writes a spec.
|
|
92
|
+
|
|
93
|
+
## Report
|
|
94
|
+
|
|
95
|
+
End with the block defined in `.claude/rules/spec-reports.md`. That file carries
|
|
96
|
+
the shape; this section carries only what is specific here. In list mode the
|
|
97
|
+
table of ideas is the body of the message, and the block follows it.
|
|
98
|
+
|
|
99
|
+
**Verdicts**
|
|
100
|
+
|
|
101
|
+
- `✅` — an idea was filed or dropped, or the list was read (an empty list
|
|
102
|
+
included).
|
|
103
|
+
- `⏸` — the engine refused, so nothing was written. Name the reason in `Why`,
|
|
104
|
+
with the text when it was a capture.
|
|
105
|
+
- Handing off to `/spec` emits no block here: that skill ends with its own.
|
|
106
|
+
|
|
107
|
+
**Fields:** `Tracker` · `Built` · `Landed` · `Follow-ups` · `Next`
|
|
108
|
+
|
|
109
|
+
`Tracker` is the idea's issue, when the provider holds it. `Built` is what
|
|
110
|
+
happened: the idea's id and title, where it went, or the count listed.
|
|
111
|
+
`Landed` covers the file store only: the commit on the base branch and
|
|
112
|
+
`not pushed · <the push it printed> publishes it`. `Next` is the handle that
|
|
113
|
+
promotes the idea (`/spec idea:<id>`, `/spec #N`), or `none` after a drop.
|
|
114
|
+
|
|
115
|
+
**`Follow-ups` is always `none` here.** An idea is the follow-up.
|
|
@@ -27,7 +27,7 @@ clobber customised content. Finish with a summary of created vs already-present.
|
|
|
27
27
|
> **Leave alone**. Non-interactively it only adds what's missing; `--resync` /
|
|
28
28
|
> `--reset` (reset needs `--yes`) drive the stronger actions.
|
|
29
29
|
|
|
30
|
-
The system is **
|
|
30
|
+
The system is **eighteen skills**: `spec` (feature, chore or issue), `spec-bug` (bug),
|
|
31
31
|
`spec-hotfix` (a bug fixed on a released tag),
|
|
32
32
|
`spec-incident` (a live outage, recorded as it happens),
|
|
33
33
|
`no-spec` (work that genuinely has none — off the base branch all the same),
|
|
@@ -36,7 +36,8 @@ The system is **seventeen skills**: `spec` (feature, chore or issue), `spec-bug`
|
|
|
36
36
|
`spec-reviewed` (pick up a review you approved on that page),
|
|
37
37
|
`spec-epic-next` (name the epic member that can start now), `spec-to-main`,
|
|
38
38
|
`spec-complete`, `spec-cancel`, `spec-tada` (a ta-da list of what got done),
|
|
39
|
-
`spec-todo` (where you left off, and what is ahead),
|
|
39
|
+
`spec-todo` (where you left off, and what is ahead), `spec-idea` (an idea
|
|
40
|
+
parked without a spec),
|
|
40
41
|
and this `spec-init`. The lifecycle is `backlog → in-progress → complete / cancelled`,
|
|
41
42
|
with `.core` holding always-apply project rules.
|
|
42
43
|
|
|
@@ -46,6 +46,9 @@ What the lines mean:
|
|
|
46
46
|
- `finished:` — the specs that day completed or cancelled, by name.
|
|
47
47
|
- `blocked:` — a review verdict waiting, or a gate armed by a phase that ended
|
|
48
48
|
and still owes an answer. Read only for specs in flight.
|
|
49
|
+
- `ideas:` — how many ideas are waiting for the `(here)` project. It is a count,
|
|
50
|
+
never the next action: `/spec-idea` lists them, and the line is absent when
|
|
51
|
+
there are none or the count could not be read.
|
|
49
52
|
- `today:` — commits and moves since midnight, when there are any.
|
|
50
53
|
|
|
51
54
|
## 2. Write the recap
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skitterbyte/skitterspec",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.16.0",
|
|
4
4
|
"description": "Spec-driven development for Claude Code \u2014 a tracker-free filesystem workflow: lifecycle skills and per-spec isolation. For Linear sync, install @skitterbyte/skitterspec-linear instead.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
package/src/cli.js
CHANGED
|
@@ -114,6 +114,8 @@ const {
|
|
|
114
114
|
collectReview,
|
|
115
115
|
reviewTierStack,
|
|
116
116
|
reviewTierLine,
|
|
117
|
+
reviewStackText,
|
|
118
|
+
waitCovers,
|
|
117
119
|
isTailnetAddress,
|
|
118
120
|
tailnetLabel,
|
|
119
121
|
renderReviewPage,
|
|
@@ -377,6 +379,13 @@ Usage:
|
|
|
377
379
|
waiting and gates armed, and today so far. Same
|
|
378
380
|
scope as tada (--here, --all-projects), --json,
|
|
379
381
|
--page [--summary <recap.md>].
|
|
382
|
+
skitterspec idea <cmd> Ideas not specced yet, where the team can see them:
|
|
383
|
+
in the tracker when the provider holds ideas, else
|
|
384
|
+
specs/ideas.md landed on the base branch (never
|
|
385
|
+
pushed — it prints the push). Subcommands:
|
|
386
|
+
add <text> capture one; first line is the title
|
|
387
|
+
list what is waiting (--count, --json)
|
|
388
|
+
drop <id> discard one (--reason <why>)
|
|
380
389
|
skitterspec gating <cmd> Release-gating check (opt-in; needs
|
|
381
390
|
specs/.core/gating.config.json). Subcommands:
|
|
382
391
|
check [spec] report specs with no recorded gating
|
|
@@ -905,6 +914,26 @@ function repoBlockers(repo, specs) {
|
|
|
905
914
|
return readBlockers(reviewsDirFor(repo, config), specs, config.review && config.review.required)
|
|
906
915
|
}
|
|
907
916
|
|
|
917
|
+
/**
|
|
918
|
+
* The home project's waiting ideas, or null when that cannot be told. A
|
|
919
|
+
* provider store asks the network, so the answer is bounded: a slow, failed or
|
|
920
|
+
* refused count is null, and null prints nothing — an idea count is never a
|
|
921
|
+
* reason for the morning report to fail or stall.
|
|
922
|
+
*/
|
|
923
|
+
async function ideaCount(repo) {
|
|
924
|
+
let text = ''
|
|
925
|
+
const sink = { write: (s) => (text += s) }
|
|
926
|
+
try {
|
|
927
|
+
const counted = require('./ideacmd.js').ideaCommand(['list', '--count', '--json'], { cwd: repo, out: sink })
|
|
928
|
+
const timeout = new Promise((resolve) => setTimeout(() => resolve('timeout'), 5000).unref())
|
|
929
|
+
if ((await Promise.race([counted, timeout])) !== 0) return null
|
|
930
|
+
const n = JSON.parse(text).count
|
|
931
|
+
return Number.isInteger(n) ? n : null
|
|
932
|
+
} catch {
|
|
933
|
+
return null
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
|
|
908
937
|
/**
|
|
909
938
|
* `skitterspec todo` — the morning half of the ta-da list: where each project
|
|
910
939
|
* was left on the last day with any activity, what is ahead, and what is in
|
|
@@ -931,7 +960,7 @@ async function todoCommand(argv) {
|
|
|
931
960
|
} catch {
|
|
932
961
|
// the folder name stands in, as it does everywhere else
|
|
933
962
|
}
|
|
934
|
-
home = { repo: homeRepo, name, groups: openSpecsIn(homeRepo).map((row) => ({ spec: row.spec, inFlight: row })) }
|
|
963
|
+
home = { repo: homeRepo, name, groups: openSpecsIn(homeRepo).map((row) => ({ spec: row.spec, inFlight: row })), ideas: await ideaCount(homeRepo) }
|
|
935
964
|
}
|
|
936
965
|
|
|
937
966
|
const todo = buildTodo({ leftOff, leftOffDay: day, today: todaySoFar, home, blockersFor: repoBlockers })
|
|
@@ -1000,8 +1029,9 @@ async function serveTadaPage({ window, flags, recap }) {
|
|
|
1000
1029
|
const q = tadaQuery({ ...flags, on: flags.on || (flags.since ? null : localDay(window.since)) })
|
|
1001
1030
|
const withQ = (u) => (u ? `${u}${q}` : u)
|
|
1002
1031
|
const page = { ...served, loopbackUrl: withQ(served.loopbackUrl), url: withQ(served.url), alternates: (served.alternates || []).map(withQ) }
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1032
|
+
const reader = resolveReader(config, process.env)
|
|
1033
|
+
const tiers = reviewTierStack({ served: page, fileUrl: null, publishedUrl: null, config, reader })
|
|
1034
|
+
process.stdout.write(`page: ${humanLabel(window)}\n${reviewStackText(tiers)}`)
|
|
1005
1035
|
return true
|
|
1006
1036
|
}
|
|
1007
1037
|
|
|
@@ -1105,13 +1135,14 @@ function epicPageTiers(inputs, up, epic) {
|
|
|
1105
1135
|
if (!inputs.config) return null
|
|
1106
1136
|
if (!up) return { off: true, start: 'skitterspec spec-env review serve --host 0.0.0.0' }
|
|
1107
1137
|
const served = reviewServedUrls(up, offerableLanAddresses(), epic)
|
|
1108
|
-
|
|
1138
|
+
const reader = resolveReader(inputs.config, process.env)
|
|
1139
|
+
return { tiers: reviewTierStack({ served, fileUrl: null, publishedUrl: null, config: inputs.config, reader }) }
|
|
1109
1140
|
}
|
|
1110
1141
|
|
|
1111
1142
|
function epicPageLines(page) {
|
|
1112
1143
|
if (!page) return ''
|
|
1113
1144
|
if (page.off) return `epic page: no review server running — start it with: ${page.start}\n`
|
|
1114
|
-
return `epic page:\n${page.tiers
|
|
1145
|
+
return `epic page:\n${reviewStackText(page.tiers)}`
|
|
1115
1146
|
}
|
|
1116
1147
|
|
|
1117
1148
|
// The working tree `--here` reads: the project folder of the checkout this
|
|
@@ -4847,7 +4878,8 @@ function reshowStack(dir, config, spec, out) {
|
|
|
4847
4878
|
const cfg = withSpecRemote(config, out)
|
|
4848
4879
|
const up = readRunningReviewServer(dir, cfg)
|
|
4849
4880
|
const served = up ? reviewServedUrls(up, offerableLanAddresses(), spec.folder) : null
|
|
4850
|
-
const
|
|
4881
|
+
const reader = resolveReader(cfg, process.env)
|
|
4882
|
+
const tiers = reviewTierStack({ served, fileUrl: reviewFileUrl(out), publishedUrl: readReviewUrl(out), config: cfg, reader })
|
|
4851
4883
|
let live = null
|
|
4852
4884
|
try {
|
|
4853
4885
|
const primaryState = assertPrimaryOnMain(cfg, gitReader(dir))
|
|
@@ -4914,7 +4946,7 @@ async function specEnvReviewWait(dir, config, specArg, flags) {
|
|
|
4914
4946
|
`${rearm ? ` (re-arm ${rearm})` : ''}\n` +
|
|
4915
4947
|
(stack
|
|
4916
4948
|
? ` re-show: banner (re-arm ${rearm})\n` +
|
|
4917
|
-
stack.tiers
|
|
4949
|
+
reviewStackText(stack.tiers) +
|
|
4918
4950
|
(liveStateLine(stack.live) ? `${liveStateLine(stack.live)}\n` : '')
|
|
4919
4951
|
: ''),
|
|
4920
4952
|
)
|
|
@@ -6252,6 +6284,10 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
|
|
|
6252
6284
|
}
|
|
6253
6285
|
}
|
|
6254
6286
|
|
|
6287
|
+
// ONE STACK for both outputs, so `--json` and the text cannot disagree about
|
|
6288
|
+
// which tiers exist — or which one is hidden.
|
|
6289
|
+
const stackTiers = reviewTierStack({ served, fileUrl: reviewFileUrl(out), publishedUrl: url, config, reader })
|
|
6290
|
+
|
|
6255
6291
|
if (flags.json) {
|
|
6256
6292
|
process.stdout.write(
|
|
6257
6293
|
JSON.stringify(
|
|
@@ -6278,12 +6314,10 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
|
|
|
6278
6314
|
// The same stack the text prints, so a skill reads the tiers rather
|
|
6279
6315
|
// than parsing prose — and the two can never disagree, because both
|
|
6280
6316
|
// come from `reviewTierStack`.
|
|
6281
|
-
tiers:
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
config,
|
|
6286
|
-
}),
|
|
6317
|
+
tiers: stackTiers,
|
|
6318
|
+
// Which served tiers one wait covers — the holding line's tiers, so a
|
|
6319
|
+
// banner never names a door the stack did not show.
|
|
6320
|
+
covers: waitCovers(stackTiers),
|
|
6287
6321
|
// The same answer `live status --json` gives, from the same function,
|
|
6288
6322
|
// so the page and the command cannot disagree. Always present, unlike
|
|
6289
6323
|
// the tiers' optional keys: `unavailable` is a state a consumer needs
|
|
@@ -6405,19 +6439,12 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
|
|
|
6405
6439
|
// rendering — `reviewTierLine` carries them, which is what puts them
|
|
6406
6440
|
// under `network:` rather than dangling after the stack (they used to
|
|
6407
6441
|
// print below `remote:`, against the comment that placed them).
|
|
6408
|
-
|
|
6409
|
-
served,
|
|
6410
|
-
fileUrl: reviewFileUrl(out),
|
|
6411
|
-
publishedUrl: url,
|
|
6412
|
-
config,
|
|
6413
|
-
})
|
|
6414
|
-
.map((t) => reviewTierLine(t) + '\n')
|
|
6415
|
-
.join('') +
|
|
6442
|
+
reviewStackText(stackTiers) +
|
|
6416
6443
|
// WHICH TIERS THE WAIT COVERS, once, next to the stack. `local` and
|
|
6417
6444
|
// `network` are two doors into one room — the page POSTs to
|
|
6418
6445
|
// `location.pathname`, so both reach this server and this pending store.
|
|
6419
6446
|
// `remote` writes to the artifact's own store, which nothing here can see.
|
|
6420
|
-
|
|
6447
|
+
` the wait covers ${waitCovers(stackTiers).join(' + ')}; a remote verdict needs /spec-reviewed.\n` +
|
|
6421
6448
|
// WHETHER IT IS ALSO RUNNING SOMEWHERE, which is the other way to judge a
|
|
6422
6449
|
// change. `unavailable` prints nothing — see `liveStateLine`.
|
|
6423
6450
|
(liveStateLine(live) ? `${liveStateLine(live)}\n` : '') +
|
|
@@ -6479,6 +6506,10 @@ async function specEnvDev(dir, config, positional) {
|
|
|
6479
6506
|
const out = [`spec-env dev up: ${spec.folder} slot ${slot} (ports from ${plan.portOffset})`]
|
|
6480
6507
|
for (const proc of plan.procs) {
|
|
6481
6508
|
const res = startProcess(proc, { cwd: spec.projectPath, rootDir: dir })
|
|
6509
|
+
if (res.error) {
|
|
6510
|
+
out.push(` ${proc.name}: port ${proc.port} NOT STARTED — ${res.error}`)
|
|
6511
|
+
continue
|
|
6512
|
+
}
|
|
6482
6513
|
let health = ''
|
|
6483
6514
|
if (proc.health) {
|
|
6484
6515
|
health = (await waitHealthy(proc.health)) ? ' health: ok' : ' health: TIMEOUT'
|
|
@@ -6566,8 +6597,9 @@ function proxyProcFor(config, routesFileAbs) {
|
|
|
6566
6597
|
const sdir = stateDirLabel(config)
|
|
6567
6598
|
return {
|
|
6568
6599
|
name: 'proxy',
|
|
6569
|
-
//
|
|
6570
|
-
//
|
|
6600
|
+
// `argv` is what runs — node itself, no shell (bug-review-serve-spawn-sh).
|
|
6601
|
+
// `command` is the same thing for a person to read.
|
|
6602
|
+
argv: [process.execPath, path.join(__dirname, 'env', 'proxy.js'), routesFileAbs],
|
|
6571
6603
|
command: `node ${shellPath(path.join(__dirname, 'env', 'proxy.js'))} ${shellPath(routesFileAbs)}`,
|
|
6572
6604
|
env: {},
|
|
6573
6605
|
logFile: `${sdir}/logs/proxy.log`,
|
|
@@ -6579,8 +6611,15 @@ function proxyProcFor(config, routesFileAbs) {
|
|
|
6579
6611
|
// monorepo developing itself, and a project that installed the package. Naming
|
|
6580
6612
|
// the distribution here is a path, not provider machinery — `init.js` and
|
|
6581
6613
|
// `PROVIDER_COMMANDS` above already know package names by name.
|
|
6614
|
+
//
|
|
6615
|
+
// EVERY DISTRIBUTION, not only the base. A project installs exactly one, and a
|
|
6616
|
+
// superset missing here fell through to `__dirname` — the RUNNING copy — so a
|
|
6617
|
+
// worktree's engine saw the primary's server as executing a different script,
|
|
6618
|
+
// called it stale and stopped it (bug-review-serve-spawn-sh).
|
|
6582
6619
|
const DAEMON_LOCATIONS = [
|
|
6583
|
-
|
|
6620
|
+
...['skitterspec', 'skitterspec-linear', 'skitterspec-jira', 'skitterspec-github', 'skitterspec-azure-boards'].map(
|
|
6621
|
+
(pkg) => path.join('node_modules', '@skitterbyte', pkg, 'src', 'env', 'serve.js'),
|
|
6622
|
+
),
|
|
6584
6623
|
path.join('packages', 'common', 'src', 'env', 'serve.js'),
|
|
6585
6624
|
]
|
|
6586
6625
|
|
|
@@ -6636,8 +6675,10 @@ function serveProcFor(config, settingsFileAbs, { root = null } = {}) {
|
|
|
6636
6675
|
const sdir = stateDirLabel(config)
|
|
6637
6676
|
return {
|
|
6638
6677
|
name: 'review-serve',
|
|
6639
|
-
//
|
|
6640
|
-
//
|
|
6678
|
+
// `argv` is what runs — node itself, no shell. It used to go through
|
|
6679
|
+
// `sh -c`, and a Windows session without Git's bin on PATH has no `sh`
|
|
6680
|
+
// (bug-review-serve-spawn-sh). `command` is the same thing for a person.
|
|
6681
|
+
argv: [process.execPath, daemonScript(root), settingsFileAbs],
|
|
6641
6682
|
command: `node ${shellPath(daemonScript(root))} ${shellPath(settingsFileAbs)}`,
|
|
6642
6683
|
script: daemonScript(root),
|
|
6643
6684
|
env: {},
|
|
@@ -6890,6 +6931,9 @@ async function ensureReviewServer(dir, config, { host = '127.0.0.1', port, resta
|
|
|
6890
6931
|
) + '\n',
|
|
6891
6932
|
)
|
|
6892
6933
|
const res = startProcess(proc, { cwd: dir, rootDir: dir })
|
|
6934
|
+
// Nothing was spawned, so there is nothing to wait for — and the reason is
|
|
6935
|
+
// the only thing worth handing back.
|
|
6936
|
+
if (res.error) return { error: `could not start the server (${res.error})`, port: usePort, replaced, engineWas }
|
|
6893
6937
|
const up = await waitListening([usePort], { host: loopback ? host : '127.0.0.1' })
|
|
6894
6938
|
// A PORT ANSWERING IS NOT PROOF THAT OUR PROCESS IS ANSWERING IT. `waitListening`
|
|
6895
6939
|
// connects, and anything already bound satisfies a connect — so on its own it
|
|
@@ -7034,6 +7078,11 @@ async function specEnvReviewServe(dir, config, flags) {
|
|
|
7034
7078
|
return
|
|
7035
7079
|
}
|
|
7036
7080
|
|
|
7081
|
+
if (started.error) {
|
|
7082
|
+
process.stdout.write(`spec-env review serve: ${started.error} — see ${proc.logFile}\n`)
|
|
7083
|
+
return
|
|
7084
|
+
}
|
|
7085
|
+
|
|
7037
7086
|
const { port, token, loopback } = started
|
|
7038
7087
|
const res = { pid: started.pid }
|
|
7039
7088
|
|
|
@@ -8107,6 +8156,11 @@ async function run(argv) {
|
|
|
8107
8156
|
return
|
|
8108
8157
|
}
|
|
8109
8158
|
|
|
8159
|
+
if (cmd === 'idea') {
|
|
8160
|
+
process.exitCode = await require('./ideacmd.js').ideaCommand(rest)
|
|
8161
|
+
return
|
|
8162
|
+
}
|
|
8163
|
+
|
|
8110
8164
|
if (cmd === 'epic') {
|
|
8111
8165
|
const [sub, ...eArgs] = rest
|
|
8112
8166
|
if (sub === 'status') epicStatusCommand(eArgs)
|
package/src/env/config.js
CHANGED
|
@@ -927,6 +927,12 @@ function setProviderConfigFile(rel) {
|
|
|
927
927
|
providerConfigFile = rel || null
|
|
928
928
|
}
|
|
929
929
|
|
|
930
|
+
// Is a ticketing provider registered AND configured in this project? The same
|
|
931
|
+
// signal `land.specDocs` defaults on, so the two cannot disagree.
|
|
932
|
+
function providerConfigured(dir) {
|
|
933
|
+
return Boolean(providerConfigFile) && existsSync(join(dir, providerConfigFile))
|
|
934
|
+
}
|
|
935
|
+
|
|
930
936
|
// An explicit `specDocs` in the file — any value, even one the merge rejected —
|
|
931
937
|
// is the project's decision; a rejected typo stays on the conservative "trunk"
|
|
932
938
|
// rather than being promoted to the provider default.
|
|
@@ -976,6 +982,7 @@ module.exports = {
|
|
|
976
982
|
loadEnvConfig,
|
|
977
983
|
setProviderEnvDefaults,
|
|
978
984
|
setProviderConfigFile,
|
|
985
|
+
providerConfigured,
|
|
979
986
|
resolveServePort,
|
|
980
987
|
derivedServePort,
|
|
981
988
|
servePortRoot,
|
package/src/env/projectguard.js
CHANGED
|
@@ -52,7 +52,7 @@ const GIT_READS = new Set([
|
|
|
52
52
|
|
|
53
53
|
// skitterspec verbs that only read, as `verb` or `verb sub`.
|
|
54
54
|
const ENGINE_READS = new Set([
|
|
55
|
-
'tada', 'todo', 'status', 'help', '--help', '-h', '--version', '-v',
|
|
55
|
+
'tada', 'todo', 'idea list', 'status', 'help', '--help', '-h', '--version', '-v',
|
|
56
56
|
'spec-env status', 'spec-env resolve',
|
|
57
57
|
'epic status', 'epic check', 'gating check', 'spec-sync ownership', 'spec-sync board',
|
|
58
58
|
])
|
package/src/env/review.js
CHANGED
|
@@ -249,11 +249,36 @@ function detectReader(env = {}) {
|
|
|
249
249
|
* being told.
|
|
250
250
|
*/
|
|
251
251
|
function resolveReader(config, env = {}) {
|
|
252
|
+
// THE WRAPPER FIRST, because it is the one thing that knows this machine. A
|
|
253
|
+
// committed `review.reader` speaks for every checkout of the repo; a wrapper
|
|
254
|
+
// that runs the engine inside a VM (`prlctl exec`) speaks for this one, and
|
|
255
|
+
// the VM shows nothing else to detect — no SSH, no session variables.
|
|
256
|
+
const told = String(env.SKITTERSPEC_READER || '').trim().toLowerCase()
|
|
257
|
+
if (told === 'local' || told === 'remote') return { reader: told, why: 'SKITTERSPEC_READER' }
|
|
252
258
|
const setting = (config && config.review && config.review.reader) || 'detect'
|
|
253
259
|
if (setting === 'local' || setting === 'remote') return { reader: setting, why: 'configured' }
|
|
254
260
|
return detectReader(env)
|
|
255
261
|
}
|
|
256
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Whether the reader's browser is on another machine, so `127.0.0.1` is the
|
|
265
|
+
* wrong one — the question that hides the `local` tier.
|
|
266
|
+
*
|
|
267
|
+
* NARROWER THAN `reader === 'remote'`, deliberately. A bridge session is a
|
|
268
|
+
* reader driving this session from elsewhere, but often from a browser on this
|
|
269
|
+
* same machine, where loopback opens fine; and its variable is an undocumented
|
|
270
|
+
* harness internal. Hiding a working link on that guess is the load-bearing
|
|
271
|
+
* detection `detectReader` warns against, so only the signals someone set on
|
|
272
|
+
* purpose count: the wrapper's variable, the committed setting, and SSH.
|
|
273
|
+
*
|
|
274
|
+
* WHAT WOULD FOOL THIS: SSH with a `-L` port forward makes the reader's loopback
|
|
275
|
+
* reach this server, so `ssh` is a strong hint rather than proof —
|
|
276
|
+
* `SKITTERSPEC_READER=local` is the way back, and it outranks it.
|
|
277
|
+
*/
|
|
278
|
+
function readerOffMachine(reader) {
|
|
279
|
+
return Boolean(reader && reader.reader === 'remote' && reader.why !== 'bridge session')
|
|
280
|
+
}
|
|
281
|
+
|
|
257
282
|
/**
|
|
258
283
|
* Collect everything the page needs.
|
|
259
284
|
*
|
|
@@ -721,7 +746,7 @@ function surfacesFor({ live, tiers, buttons = null }) {
|
|
|
721
746
|
* pending store, and one wait covers both. `remote` is a second store, which is
|
|
722
747
|
* why it carries the line saying so.
|
|
723
748
|
*/
|
|
724
|
-
function reviewTierStack({ served, fileUrl, publishedUrl, config }) {
|
|
749
|
+
function reviewTierStack({ served, fileUrl, publishedUrl, config, reader = null }) {
|
|
725
750
|
const tiers = []
|
|
726
751
|
const loopbackUrl = served && served.loopbackUrl ? served.loopbackUrl : null
|
|
727
752
|
|
|
@@ -772,9 +797,46 @@ function reviewTierStack({ served, fileUrl, publishedUrl, config }) {
|
|
|
772
797
|
tiers.push({ tier: 'remote', unavailable: true, note: 'publishing is an ask — nothing published yet' })
|
|
773
798
|
}
|
|
774
799
|
|
|
800
|
+
// A READER ON ANOTHER MACHINE gets no `local` door: it points at this
|
|
801
|
+
// machine's loopback, so it hangs and never opens — first in the list, and
|
|
802
|
+
// the one habit reaches for. Hidden only when `network` has a URL to take
|
|
803
|
+
// its place; with none, an empty stack is worse than a dead link that says
|
|
804
|
+
// it is dead, so it stays and says so. Kept in `--json` either way, marked,
|
|
805
|
+
// so the decision is visible rather than an absence.
|
|
806
|
+
if (readerOffMachine(reader)) {
|
|
807
|
+
const network = tiers.find((t) => t.tier === 'network')
|
|
808
|
+
const why = `the reader is on another machine (${reader.why})`
|
|
809
|
+
tiers[0] =
|
|
810
|
+
network && network.url
|
|
811
|
+
? { ...tiers[0], hidden: true, reason: why }
|
|
812
|
+
: { ...tiers[0], note: "not reachable from the reader's machine" }
|
|
813
|
+
}
|
|
814
|
+
|
|
775
815
|
return tiers
|
|
776
816
|
}
|
|
777
817
|
|
|
818
|
+
/**
|
|
819
|
+
* The stack as printed text: every tier the reader can use, one line each,
|
|
820
|
+
* each ending in a newline. A `hidden` tier prints nothing — it is in `--json`
|
|
821
|
+
* for anyone who asks, and absent from the screen a reader clicks from.
|
|
822
|
+
*/
|
|
823
|
+
function reviewStackText(tiers) {
|
|
824
|
+
return tiers
|
|
825
|
+
.filter((t) => !t.hidden)
|
|
826
|
+
.map((t) => reviewTierLine(t) + '\n')
|
|
827
|
+
.join('')
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* The served tiers one wait covers, as the stack shows them. `local` and
|
|
832
|
+
* `network` are two doors into one room; with `local` hidden there is one door,
|
|
833
|
+
* and the line must not name one the reader was never shown.
|
|
834
|
+
*/
|
|
835
|
+
function waitCovers(tiers) {
|
|
836
|
+
const local = tiers.find((t) => t.tier === 'local')
|
|
837
|
+
return local && local.hidden ? ['network'] : ['local', 'network']
|
|
838
|
+
}
|
|
839
|
+
|
|
778
840
|
// One tier as a line, padded so the labels form a column the eye can run down.
|
|
779
841
|
// A tier with alternates renders them as indented `also:` lines of its own —
|
|
780
842
|
// they are PART of the tier, which is what puts them under `network:` rather
|
|
@@ -2632,6 +2694,8 @@ module.exports = {
|
|
|
2632
2694
|
surfacesFor,
|
|
2633
2695
|
reviewTierStack,
|
|
2634
2696
|
reviewTierLine,
|
|
2697
|
+
reviewStackText,
|
|
2698
|
+
waitCovers,
|
|
2635
2699
|
isTailnetAddress,
|
|
2636
2700
|
tailnetLabel,
|
|
2637
2701
|
COMMITTING,
|
|
@@ -2724,6 +2788,7 @@ module.exports = {
|
|
|
2724
2788
|
renderReviewFragment,
|
|
2725
2789
|
detectReader,
|
|
2726
2790
|
resolveReader,
|
|
2791
|
+
readerOffMachine,
|
|
2727
2792
|
CHECK_LEVELS,
|
|
2728
2793
|
loadTemplate,
|
|
2729
2794
|
TEMPLATE_PATH,
|
package/src/env/reviewers.js
CHANGED
|
@@ -32,7 +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
|
+
const { signalGroup, resolveShell } = require('./supervise.js')
|
|
36
36
|
|
|
37
37
|
const BUNDLED_ADAPTERS = { coderabbit: require('./reviewers/coderabbit.js') }
|
|
38
38
|
|
|
@@ -288,9 +288,10 @@ function runReviewer(entry, ctx) {
|
|
|
288
288
|
// Through a shell, deliberately: the config holds a command LINE, with
|
|
289
289
|
// pipes and quoting the project chose. It is read from a committed config
|
|
290
290
|
// in the project's own repo — the same trust level as a package script.
|
|
291
|
-
// `sh`
|
|
292
|
-
//
|
|
293
|
-
|
|
291
|
+
// Git for Windows' `sh` on Windows, where `/bin/sh` does not exist and no
|
|
292
|
+
// reviewer could run at all (chore-windows-ci) — found off PATH too, and
|
|
293
|
+
// left as a bare `sh` to fail as `did not run` when there is none.
|
|
294
|
+
child = spawnFn(process.platform === 'win32' ? resolveShell() || 'sh' : '/bin/sh', ['-c', rendered], {
|
|
294
295
|
cwd: worktree,
|
|
295
296
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
296
297
|
// THE CHILD LEADS ITS OWN PROCESS GROUP, and the timeout below depends
|
package/src/env/supervise.js
CHANGED
|
@@ -67,11 +67,48 @@ function readPid(pidFileAbs) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* The shell a planned `command` runs through, or null when there is none.
|
|
72
|
+
*
|
|
73
|
+
* POSIX: `sh` from PATH, as it always was. Windows: `sh` only exists where Git
|
|
74
|
+
* for Windows put its `bin` on PATH, and a `cmd /c` session (a VM driven from
|
|
75
|
+
* another host, a scheduled task) commonly has Git installed and not on PATH.
|
|
76
|
+
* So PATH first, then Git's own install locations, then the `bin` beside a
|
|
77
|
+
* `git.exe` that IS on PATH (`Git\cmd\git.exe` → `Git\bin\sh.exe`).
|
|
78
|
+
*
|
|
79
|
+
* WHAT WOULD FOOL THIS: Git installed somewhere none of those name — a scoop
|
|
80
|
+
* shim, a portable copy. Then the answer is null, and the caller refuses with
|
|
81
|
+
* a reason rather than spawning something that is not there.
|
|
82
|
+
*/
|
|
83
|
+
function resolveShell({ platform = process.platform, env = process.env, exists = fs.existsSync } = {}) {
|
|
84
|
+
if (platform !== 'win32') return 'sh'
|
|
85
|
+
const w = path.win32
|
|
86
|
+
const dirs = String(env.PATH || env.Path || '').split(';').filter(Boolean)
|
|
87
|
+
const candidates = dirs.map((d) => w.join(d, 'sh.exe'))
|
|
88
|
+
for (const base of [env.ProgramFiles, env.ProgramW6432, env['ProgramFiles(x86)']]) {
|
|
89
|
+
if (base) candidates.push(w.join(base, 'Git', 'bin', 'sh.exe'))
|
|
90
|
+
}
|
|
91
|
+
if (env.LOCALAPPDATA) candidates.push(w.join(env.LOCALAPPDATA, 'Programs', 'Git', 'bin', 'sh.exe'))
|
|
92
|
+
for (const d of dirs) {
|
|
93
|
+
if (exists(w.join(d, 'git.exe'))) candidates.push(w.join(d, '..', 'bin', 'sh.exe'))
|
|
94
|
+
}
|
|
95
|
+
return candidates.find((c) => exists(c)) || null
|
|
96
|
+
}
|
|
97
|
+
|
|
70
98
|
/**
|
|
71
99
|
* Start one planned process detached, appending stdout+stderr to its log and
|
|
72
100
|
* writing its pid file. Idempotent: if the pid file already names a live
|
|
73
101
|
* process, nothing is spawned — returns `{ started: false, pid }`.
|
|
74
102
|
*
|
|
103
|
+
* A proc carrying `argv` is spawned as exactly that, with no shell — the review
|
|
104
|
+
* server and the proxy are `node <script> <file>` and never needed one. A proc
|
|
105
|
+
* carrying only `command` runs through `resolveShell`.
|
|
106
|
+
*
|
|
107
|
+
* NEVER THROWS OVER A SPAWN THAT FAILED. A missing executable is reported as
|
|
108
|
+
* `{ started: false, pid: null, error }` with no pid file written: the ENOENT
|
|
109
|
+
* otherwise arrives as an unhandled 'error' event and takes the CLI down with
|
|
110
|
+
* it (bug-review-serve-spawn-sh).
|
|
111
|
+
*
|
|
75
112
|
* `spawnImpl` is injectable for tests; defaults to child_process.spawn.
|
|
76
113
|
*/
|
|
77
114
|
function startProcess(proc, { cwd, rootDir, spawnImpl = spawn }) {
|
|
@@ -83,19 +120,44 @@ function startProcess(proc, { cwd, rootDir, spawnImpl = spawn }) {
|
|
|
83
120
|
return { started: false, pid: existing, logFile: logAbs, pidFile: pidAbs }
|
|
84
121
|
}
|
|
85
122
|
|
|
123
|
+
const env = { ...process.env, ...proc.env }
|
|
124
|
+
let file
|
|
125
|
+
let args
|
|
126
|
+
if (proc.argv) {
|
|
127
|
+
;[file, ...args] = proc.argv
|
|
128
|
+
} else {
|
|
129
|
+
file = resolveShell({ env })
|
|
130
|
+
args = ['-c', proc.command]
|
|
131
|
+
if (!file) {
|
|
132
|
+
const error = 'no sh found — install Git for Windows or put its bin folder on PATH'
|
|
133
|
+
return { started: false, pid: null, error, logFile: logAbs, pidFile: pidAbs }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
86
137
|
fs.mkdirSync(path.dirname(logAbs), { recursive: true })
|
|
87
138
|
fs.mkdirSync(path.dirname(pidAbs), { recursive: true })
|
|
88
139
|
|
|
89
140
|
const out = fs.openSync(logAbs, 'a')
|
|
90
141
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
142
|
+
let child
|
|
143
|
+
try {
|
|
144
|
+
child = spawnImpl(file, args, {
|
|
145
|
+
cwd,
|
|
146
|
+
env,
|
|
147
|
+
detached: true,
|
|
148
|
+
// No console window per dev server on Windows; nothing anywhere else.
|
|
149
|
+
windowsHide: true,
|
|
150
|
+
stdio: ['ignore', out, out],
|
|
151
|
+
})
|
|
152
|
+
} catch (err) {
|
|
153
|
+
return { started: false, pid: null, error: `spawn ${file}: ${err.message}`, logFile: logAbs, pidFile: pidAbs }
|
|
154
|
+
}
|
|
155
|
+
// A spawn that could not start has no pid, and its error is emitted on the
|
|
156
|
+
// next tick — the listener is what keeps that from being fatal.
|
|
157
|
+
child.on('error', () => {})
|
|
158
|
+
if (!child.pid) {
|
|
159
|
+
return { started: false, pid: null, error: `could not start ${file}`, logFile: logAbs, pidFile: pidAbs }
|
|
160
|
+
}
|
|
99
161
|
child.unref()
|
|
100
162
|
fs.writeFileSync(pidAbs, `${child.pid}\n`)
|
|
101
163
|
return { started: true, pid: child.pid, logFile: logAbs, pidFile: pidAbs }
|
|
@@ -167,4 +229,4 @@ async function waitHealthy(
|
|
|
167
229
|
// therefore kills the wrapper, leaves the server holding its port, and then
|
|
168
230
|
// blames whatever it asserts next. Killing the group is what `stopProcess` does
|
|
169
231
|
// and what a test must do to mean "it died".
|
|
170
|
-
module.exports = { startProcess, stopProcess, waitHealthy, isAlive, readPid, signalGroup }
|
|
232
|
+
module.exports = { startProcess, stopProcess, waitHealthy, isAlive, readPid, signalGroup, resolveShell }
|
package/src/idea.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ideas — the inbox for work that is not a spec yet.
|
|
5
|
+
*
|
|
6
|
+
* `/spec-idea` captures a thought without grilling it, somewhere the team can
|
|
7
|
+
* see. Where a ticketing provider can hold ideas, it does (an issue kept off
|
|
8
|
+
* the board); everywhere else they live in one file on the base branch,
|
|
9
|
+
* `specs/ideas.md`. This module is the pure half: the file's format, the id
|
|
10
|
+
* an entry is addressed by, the add/drop planners, and the choice of store.
|
|
11
|
+
* Every git call lives in the CLI.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const IDEAS_FILE = 'specs/ideas.md'
|
|
15
|
+
|
|
16
|
+
const PREAMBLE = [
|
|
17
|
+
'# Ideas',
|
|
18
|
+
'',
|
|
19
|
+
'Captured with `/spec-idea`, not specced yet. Promote one with',
|
|
20
|
+
'`/spec idea:<id>`; discard one with `/spec-idea --drop <id>`.',
|
|
21
|
+
'',
|
|
22
|
+
].join('\n')
|
|
23
|
+
|
|
24
|
+
// `## <id> · <YYYY-MM-DD> · <author>`
|
|
25
|
+
const HEADER = /^## ([a-z0-9][a-z0-9-]*) · (\d{4}-\d{2}-\d{2}) · (.+)$/
|
|
26
|
+
|
|
27
|
+
// The id is part of a commit subject (`docs(ideas): drop <id>`), and the
|
|
28
|
+
// subject line is held to 50 characters.
|
|
29
|
+
const MAX_ID = 30
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Parse `specs/ideas.md`. Everything before the first `## ` line is the
|
|
33
|
+
* preamble and is kept verbatim. A `## ` line that is not an entry header is
|
|
34
|
+
* reported in `malformed` rather than guessed at, because rewriting the file
|
|
35
|
+
* around a hand edit we did not understand would lose it.
|
|
36
|
+
*/
|
|
37
|
+
function parseIdeas(text) {
|
|
38
|
+
const lines = String(text || '').split('\n')
|
|
39
|
+
const first = lines.findIndex((line) => line.startsWith('## '))
|
|
40
|
+
const preamble = first === -1 ? lines.join('\n') : lines.slice(0, first).join('\n')
|
|
41
|
+
const entries = []
|
|
42
|
+
const malformed = []
|
|
43
|
+
if (first === -1) return { preamble, entries, malformed }
|
|
44
|
+
|
|
45
|
+
let current = null
|
|
46
|
+
for (const line of lines.slice(first)) {
|
|
47
|
+
if (line.startsWith('## ')) {
|
|
48
|
+
const m = HEADER.exec(line)
|
|
49
|
+
if (!m) {
|
|
50
|
+
malformed.push(line)
|
|
51
|
+
current = null
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
current = { id: m[1], date: m[2], author: m[3].trim(), lines: [] }
|
|
55
|
+
entries.push(current)
|
|
56
|
+
} else if (current) {
|
|
57
|
+
current.lines.push(line)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
preamble,
|
|
62
|
+
entries: entries.map(({ lines: body, ...rest }) => ({ ...rest, ...splitText(body.join('\n')) })),
|
|
63
|
+
malformed,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** First non-empty line is the title; whatever follows it is the body. */
|
|
68
|
+
function splitText(text) {
|
|
69
|
+
const lines = String(text || '').replace(/\r\n/g, '\n').split('\n')
|
|
70
|
+
const at = lines.findIndex((line) => line.trim())
|
|
71
|
+
if (at === -1) return { title: '', body: '' }
|
|
72
|
+
return { title: lines[at].trim(), body: lines.slice(at + 1).join('\n').trim() }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function formatIdeas({ preamble, entries }) {
|
|
76
|
+
const head = (preamble && preamble.trim() ? preamble : PREAMBLE).replace(/\s+$/, '')
|
|
77
|
+
const blocks = entries.map((e) =>
|
|
78
|
+
[`## ${e.id} · ${e.date} · ${e.author}`, e.title, ...(e.body ? [e.body] : [])].join('\n'),
|
|
79
|
+
)
|
|
80
|
+
return [head, ...blocks].join('\n\n') + '\n'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A short kebab id from the title, unique among `taken`. */
|
|
84
|
+
function ideaId(title, taken = []) {
|
|
85
|
+
const words = String(title || '')
|
|
86
|
+
.toLowerCase()
|
|
87
|
+
.replace(/[^a-z0-9]+/g, ' ')
|
|
88
|
+
.trim()
|
|
89
|
+
.split(/\s+/)
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
let stem = ''
|
|
92
|
+
for (const word of words) {
|
|
93
|
+
const next = stem ? `${stem}-${word}` : word
|
|
94
|
+
if (next.length > MAX_ID) break
|
|
95
|
+
stem = next
|
|
96
|
+
}
|
|
97
|
+
if (!stem) stem = words.length ? words[0].slice(0, MAX_ID) : 'idea'
|
|
98
|
+
const used = new Set(taken)
|
|
99
|
+
if (!used.has(stem)) return stem
|
|
100
|
+
for (let n = 2; ; n++) {
|
|
101
|
+
const suffix = `-${n}`
|
|
102
|
+
const candidate = `${stem.slice(0, MAX_ID - suffix.length)}${suffix}`
|
|
103
|
+
if (!used.has(candidate)) return candidate
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function refuseMalformed(parsed) {
|
|
108
|
+
if (!parsed.malformed.length) return null
|
|
109
|
+
return (
|
|
110
|
+
`${IDEAS_FILE} has ${parsed.malformed.length} heading(s) that are not idea entries ` +
|
|
111
|
+
`(first: "${parsed.malformed[0]}") — fix them by hand; nothing was written`
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Plan an add: `{ id, content, message }`, or `{ refused }`. `text` is what
|
|
117
|
+
* was typed — the first line becomes the title.
|
|
118
|
+
*/
|
|
119
|
+
function planAdd(current, { text, author, date }) {
|
|
120
|
+
const { title, body } = splitText(text)
|
|
121
|
+
if (!title) return { refused: 'nothing to capture — give the idea some text' }
|
|
122
|
+
const parsed = parseIdeas(current)
|
|
123
|
+
const bad = refuseMalformed(parsed)
|
|
124
|
+
if (bad) return { refused: bad }
|
|
125
|
+
const id = ideaId(title, parsed.entries.map((e) => e.id))
|
|
126
|
+
// A body line that opens with `## ` would read back as an entry header.
|
|
127
|
+
const safe = body.replace(/^(#+ )/gm, '\\$1')
|
|
128
|
+
const entry = { id, date, author: author || 'unknown', title, body: safe }
|
|
129
|
+
return {
|
|
130
|
+
id,
|
|
131
|
+
entry,
|
|
132
|
+
content: formatIdeas({ preamble: parsed.preamble, entries: [...parsed.entries, entry] }),
|
|
133
|
+
message: `docs(ideas): add ${id}\n\n- Capture "${title}" in ${IDEAS_FILE}\n`,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Plan a drop: `{ id, content, message }`, or `{ refused }`. */
|
|
138
|
+
function planDrop(current, { id, reason }) {
|
|
139
|
+
const parsed = parseIdeas(current)
|
|
140
|
+
const bad = refuseMalformed(parsed)
|
|
141
|
+
if (bad) return { refused: bad }
|
|
142
|
+
const entry = parsed.entries.find((e) => e.id === id)
|
|
143
|
+
if (!entry) return { refused: `no idea "${id}" — \`skitterspec idea list\` shows them` }
|
|
144
|
+
const why = reason && reason.trim() ? reason.trim() : 'no reason given'
|
|
145
|
+
return {
|
|
146
|
+
id,
|
|
147
|
+
entry,
|
|
148
|
+
content: formatIdeas({ preamble: parsed.preamble, entries: parsed.entries.filter((e) => e !== entry) }),
|
|
149
|
+
message: `docs(ideas): drop ${id}\n\n- Discard "${entry.title}": ${why}\n`,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// A provider that can hold ideas registers its store here; one that cannot
|
|
154
|
+
// registers `{ supports: false }`. Left unregistered, the answer is unknown.
|
|
155
|
+
let providerIdeaStore
|
|
156
|
+
function setProviderIdeaStore(store) {
|
|
157
|
+
providerIdeaStore = store
|
|
158
|
+
}
|
|
159
|
+
function getProviderIdeaStore() {
|
|
160
|
+
return providerIdeaStore
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Which store holds ideas: `file`, `provider`, or `unknown`.
|
|
165
|
+
*
|
|
166
|
+
* The file is chosen only on a POSITIVE answer — no provider configured, or a
|
|
167
|
+
* provider that registered `supports: false`. A configured provider that said
|
|
168
|
+
* nothing is unknown, and capture refuses instead of writing to the file:
|
|
169
|
+
* filing there while the team reads the tracker would put one idea in each
|
|
170
|
+
* store with nothing to say which is the real one.
|
|
171
|
+
*/
|
|
172
|
+
function selectStore({ providerConfigured, store }) {
|
|
173
|
+
if (!providerConfigured) return 'file'
|
|
174
|
+
if (store && store.supports === true) return 'provider'
|
|
175
|
+
if (store && store.supports === false) return 'file'
|
|
176
|
+
return 'unknown'
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
module.exports = {
|
|
180
|
+
IDEAS_FILE,
|
|
181
|
+
parseIdeas,
|
|
182
|
+
formatIdeas,
|
|
183
|
+
splitText,
|
|
184
|
+
ideaId,
|
|
185
|
+
planAdd,
|
|
186
|
+
planDrop,
|
|
187
|
+
selectStore,
|
|
188
|
+
setProviderIdeaStore,
|
|
189
|
+
getProviderIdeaStore,
|
|
190
|
+
}
|
package/src/ideacmd.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `skitterspec idea <add|list|drop>` — the side-effecting half of `idea.js`.
|
|
5
|
+
*
|
|
6
|
+
* The file store writes `specs/ideas.md` straight onto the base branch with
|
|
7
|
+
* plumbing — a throwaway index, `commit-tree`, then a fast-forward — so no
|
|
8
|
+
* checkout is switched, no worktree is made, and the primary checkout is never
|
|
9
|
+
* left dirty. Where the base branch is checked out, the fast-forward runs
|
|
10
|
+
* there (`merge --ff-only`) so its working tree follows; elsewhere the ref
|
|
11
|
+
* moves by compare-and-swap. Either way a base that moved underneath us
|
|
12
|
+
* refuses rather than overwriting it.
|
|
13
|
+
*
|
|
14
|
+
* Nothing is pushed. The base branch is shared once it is pushed, and a push
|
|
15
|
+
* is always the operator's to make, so the command prints it instead.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const fs = require('node:fs')
|
|
19
|
+
const os = require('node:os')
|
|
20
|
+
const path = require('node:path')
|
|
21
|
+
const { execFileSync } = require('node:child_process')
|
|
22
|
+
|
|
23
|
+
const { IDEAS_FILE, parseIdeas, planAdd, planDrop, selectStore, getProviderIdeaStore } = require('./idea.js')
|
|
24
|
+
const { loadEnvConfig, providerConfigured } = require('./env/config.js')
|
|
25
|
+
const { describeBaseBranch, baseRemote } = require('./env/resolve.js')
|
|
26
|
+
const { primaryAnchor } = require('./env/project.js')
|
|
27
|
+
|
|
28
|
+
const USAGE =
|
|
29
|
+
'Usage: skitterspec idea add <text> | list [--count] | drop <id> [--reason <why>] [--json] [--dir <path>]\n'
|
|
30
|
+
|
|
31
|
+
function reader(cwd) {
|
|
32
|
+
return (argv) => {
|
|
33
|
+
try {
|
|
34
|
+
return execFileSync('git', ['-C', cwd, ...argv], { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
35
|
+
.toString()
|
|
36
|
+
.trim()
|
|
37
|
+
} catch {
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// A mutating call: throws with git's own stderr, which is what gets relayed.
|
|
44
|
+
function git(cwd, argv, { input, env } = {}) {
|
|
45
|
+
try {
|
|
46
|
+
return execFileSync('git', ['-C', cwd, ...argv], {
|
|
47
|
+
input,
|
|
48
|
+
env: env || process.env,
|
|
49
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
50
|
+
})
|
|
51
|
+
.toString()
|
|
52
|
+
.trim()
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new Error((error.stderr && error.stderr.toString().trim()) || error.message)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function parseArgs(argv) {
|
|
59
|
+
const flags = { json: false, count: false, dir: null, reason: null }
|
|
60
|
+
const positional = []
|
|
61
|
+
for (let i = 0; i < argv.length; i++) {
|
|
62
|
+
const a = argv[i]
|
|
63
|
+
if (a === '--json') flags.json = true
|
|
64
|
+
else if (a === '--count') flags.count = true
|
|
65
|
+
else if (a === '--dir') flags.dir = argv[++i]
|
|
66
|
+
else if (a === '--reason') flags.reason = argv[++i]
|
|
67
|
+
else positional.push(a)
|
|
68
|
+
}
|
|
69
|
+
return { flags, positional }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function localDay(now) {
|
|
73
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
74
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Where the file store lives: the primary checkout, its base branch, the path. */
|
|
78
|
+
function fileContext(from) {
|
|
79
|
+
const anchor = primaryAnchor(from, reader(from))
|
|
80
|
+
const read = reader(anchor.root)
|
|
81
|
+
let config = {}
|
|
82
|
+
try {
|
|
83
|
+
config = loadEnvConfig(anchor.dir).config
|
|
84
|
+
} catch {
|
|
85
|
+
// an unreadable config resolves the base the way a missing one does
|
|
86
|
+
}
|
|
87
|
+
const { base, refused } = describeBaseBranch(config, read)
|
|
88
|
+
return {
|
|
89
|
+
anchor,
|
|
90
|
+
read,
|
|
91
|
+
base,
|
|
92
|
+
refused,
|
|
93
|
+
remote: baseRemote(config),
|
|
94
|
+
rel: anchor.prefix ? `${anchor.prefix}/${IDEAS_FILE}` : IDEAS_FILE,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The file as the base branch holds it — `''` when it is not there yet. */
|
|
99
|
+
function readOnBase(ctx) {
|
|
100
|
+
const tip = ctx.read(['rev-parse', '--verify', '--quiet', `refs/heads/${ctx.base}^{commit}`])
|
|
101
|
+
if (!tip) return { tip: null, text: null }
|
|
102
|
+
return { tip, text: ctx.read(['show', `${tip}:${ctx.rel}`]) || '' }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The worktree that has `branch` checked out, else null. */
|
|
106
|
+
function checkedOutAt(ctx, branch) {
|
|
107
|
+
const out = ctx.read(['worktree', 'list', '--porcelain']) || ''
|
|
108
|
+
let at = null
|
|
109
|
+
for (const line of out.split('\n')) {
|
|
110
|
+
if (line.startsWith('worktree ')) at = line.slice('worktree '.length)
|
|
111
|
+
else if (line === `branch refs/heads/${branch}`) return at
|
|
112
|
+
}
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Commit `content` at `rel` on top of `tip`, then fast-forward the base to it. */
|
|
117
|
+
function landOnBase(ctx, tip, content, message) {
|
|
118
|
+
const root = ctx.anchor.root
|
|
119
|
+
const index = path.join(os.tmpdir(), `skitterspec-idea-${process.pid}-${Date.now()}.index`)
|
|
120
|
+
const env = { ...process.env, GIT_INDEX_FILE: index }
|
|
121
|
+
let commit
|
|
122
|
+
try {
|
|
123
|
+
git(root, ['read-tree', tip], { env })
|
|
124
|
+
const blob = git(root, ['hash-object', '-w', '--stdin'], { input: content })
|
|
125
|
+
git(root, ['update-index', '--add', '--cacheinfo', `100644,${blob},${ctx.rel}`], { env })
|
|
126
|
+
const tree = git(root, ['write-tree'], { env })
|
|
127
|
+
commit = git(root, ['commit-tree', tree, '-p', tip, '-F', '-'], { input: message })
|
|
128
|
+
} finally {
|
|
129
|
+
fs.rmSync(index, { force: true })
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const at = checkedOutAt(ctx, ctx.base)
|
|
133
|
+
if (at) {
|
|
134
|
+
// Its working tree must follow the ref, so the move happens there — and a
|
|
135
|
+
// local edit to the file is someone's work, which a fast-forward would
|
|
136
|
+
// either refuse over or carry; refuse first, with the reason in words.
|
|
137
|
+
const dirty = reader(at)(['status', '--porcelain', '--', ctx.rel])
|
|
138
|
+
if (dirty) throw new Error(`${ctx.rel} has uncommitted changes in ${at} — commit or discard them first`)
|
|
139
|
+
git(at, ['merge', '--ff-only', '--quiet', commit])
|
|
140
|
+
} else {
|
|
141
|
+
git(root, ['update-ref', '-m', 'skitterspec idea', `refs/heads/${ctx.base}`, commit, tip])
|
|
142
|
+
}
|
|
143
|
+
return commit
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function write(out, flags, json, lines) {
|
|
147
|
+
out.write(flags.json ? JSON.stringify(json, null, 2) + '\n' : lines.join('\n') + '\n')
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function refuse(out, flags, reason, extra = {}) {
|
|
151
|
+
write(out, flags, { ok: false, refused: reason, ...extra }, [`idea: ${reason}`])
|
|
152
|
+
return 1
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function fileStore(sub, positional, flags, { cwd, now, out }) {
|
|
156
|
+
const ctx = fileContext(cwd)
|
|
157
|
+
if (!ctx.base) return refuse(out, flags, ctx.refused ? ctx.refused.message : 'cannot resolve the base branch')
|
|
158
|
+
const { tip, text } = readOnBase(ctx)
|
|
159
|
+
|
|
160
|
+
if (sub === 'list') {
|
|
161
|
+
const ideas = tip ? parseIdeas(text).entries : []
|
|
162
|
+
if (flags.count) {
|
|
163
|
+
write(out, flags, { store: 'file', count: ideas.length }, [String(ideas.length)])
|
|
164
|
+
return 0
|
|
165
|
+
}
|
|
166
|
+
const lines = ideas.length
|
|
167
|
+
? [`ideas on ${ctx.base} (${ctx.rel}):`, ...ideas.map((e) => ` ${e.id.padEnd(30)} ${e.date} ${e.title}`)]
|
|
168
|
+
: [`idea: nothing waiting on ${ctx.base}`]
|
|
169
|
+
write(out, flags, { store: 'file', base: ctx.base, file: ctx.rel, ideas }, lines)
|
|
170
|
+
return 0
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!tip) return refuse(out, flags, `the base branch ${ctx.base} has no commits here`)
|
|
174
|
+
|
|
175
|
+
const plan =
|
|
176
|
+
sub === 'add'
|
|
177
|
+
? planAdd(text, {
|
|
178
|
+
text: positional.join(' '),
|
|
179
|
+
author: ctx.read(['config', 'user.name']),
|
|
180
|
+
date: localDay(now),
|
|
181
|
+
})
|
|
182
|
+
: planDrop(text, { id: positional[0], reason: flags.reason })
|
|
183
|
+
if (plan.refused) return refuse(out, flags, plan.refused, sub === 'add' ? { text: positional.join(' ') } : {})
|
|
184
|
+
|
|
185
|
+
let commit
|
|
186
|
+
try {
|
|
187
|
+
commit = landOnBase(ctx, tip, plan.content, plan.message)
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return refuse(out, flags, `nothing landed — ${error.message}`, sub === 'add' ? { text: positional.join(' ') } : {})
|
|
190
|
+
}
|
|
191
|
+
const push = `git push ${ctx.remote} ${ctx.base}`
|
|
192
|
+
const verb = sub === 'add' ? 'added' : 'dropped'
|
|
193
|
+
write(
|
|
194
|
+
out,
|
|
195
|
+
flags,
|
|
196
|
+
{ ok: true, store: 'file', action: sub, id: plan.id, title: plan.entry.title, base: ctx.base, commit, file: ctx.rel, push },
|
|
197
|
+
[
|
|
198
|
+
`idea: ${verb} "${plan.id}" ${sub === 'add' ? 'to' : 'from'} ${ctx.rel} on ${ctx.base} (${commit.slice(0, 7)})`,
|
|
199
|
+
` title: ${plan.entry.title}`,
|
|
200
|
+
` pushed: no — ${push} publishes it`,
|
|
201
|
+
],
|
|
202
|
+
)
|
|
203
|
+
return 0
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Entry point. Resolves to an exit code: 0 for an answer, 1 for a refusal —
|
|
208
|
+
* which for `add` carries the text back, so a refused capture loses nothing.
|
|
209
|
+
*/
|
|
210
|
+
async function ideaCommand(argv, { cwd = process.cwd(), now = new Date(), out = process.stdout } = {}) {
|
|
211
|
+
const [sub, ...rest] = argv
|
|
212
|
+
const { flags, positional } = parseArgs(rest)
|
|
213
|
+
const from = path.resolve(flags.dir || cwd)
|
|
214
|
+
if (!['add', 'list', 'drop'].includes(sub)) {
|
|
215
|
+
out.write(USAGE)
|
|
216
|
+
return sub ? 1 : 0
|
|
217
|
+
}
|
|
218
|
+
if (sub === 'add' && !positional.join(' ').trim()) return refuse(out, flags, 'nothing to capture — give the idea some text')
|
|
219
|
+
if (sub === 'drop' && !positional[0]) return refuse(out, flags, 'name the idea to drop — `skitterspec idea list` shows them')
|
|
220
|
+
|
|
221
|
+
const anchor = primaryAnchor(from, reader(from))
|
|
222
|
+
const store = getProviderIdeaStore()
|
|
223
|
+
const where = selectStore({ providerConfigured: providerConfigured(anchor.dir), store })
|
|
224
|
+
if (where === 'provider') return store.run(sub, rest, { cwd: from, out })
|
|
225
|
+
if (where === 'unknown') {
|
|
226
|
+
if (sub === 'list') {
|
|
227
|
+
write(out, flags, { store: 'unknown', count: null }, ['idea: cannot tell where ideas live — the configured provider declares no idea store'])
|
|
228
|
+
return 0
|
|
229
|
+
}
|
|
230
|
+
const text = positional.join(' ')
|
|
231
|
+
return refuse(
|
|
232
|
+
out,
|
|
233
|
+
flags,
|
|
234
|
+
'cannot tell where ideas live — the configured provider declares no idea store; nothing was written' +
|
|
235
|
+
(sub === 'add' ? `\n your idea, so nothing is lost:\n ${text.replace(/\n/g, '\n ')}` : ''),
|
|
236
|
+
sub === 'add' ? { text } : {},
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
return fileStore(sub, positional, flags, { cwd: from, now, out })
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
module.exports = { ideaCommand, USAGE }
|
package/src/tada/todo.js
CHANGED
|
@@ -179,13 +179,17 @@ function buildTodo({ leftOff, leftOffDay, today, home = null, blockersFor = () =
|
|
|
179
179
|
const e = entry({ ...home, here: true })
|
|
180
180
|
for (const g of home.groups) if (g.inFlight) e.groups.push({ spec: g.spec, branch: null, left: null, prompt: null, inFlight: g.inFlight })
|
|
181
181
|
}
|
|
182
|
+
// Ideas are counted for home only: the count is this project's to act on,
|
|
183
|
+
// and asking every project's tracker would turn a morning read into a crawl.
|
|
184
|
+
// Null — could not ask — and zero both print nothing.
|
|
185
|
+
if (home && home.ideas > 0) projects.get(keyOf(home)).ideas = home.ideas
|
|
182
186
|
|
|
183
187
|
const list = [...projects.values()]
|
|
184
188
|
.map((e) => {
|
|
185
189
|
const specs = e.groups.filter((g) => g.spec && g.inFlight).map((g) => g.spec)
|
|
186
190
|
return { ...e, blocked: e.repo && specs.length ? blockersFor(e.repo, specs) : [] }
|
|
187
191
|
})
|
|
188
|
-
.filter((e) => e.groups.length || e.finished.length || e.today.commits || e.today.moves)
|
|
192
|
+
.filter((e) => e.groups.length || e.finished.length || e.today.commits || e.today.moves || e.ideas)
|
|
189
193
|
// The home project first: it is the one this session acts on.
|
|
190
194
|
.sort((a, b) => (a.here !== b.here ? (a.here ? -1 : 1) : a.name.localeCompare(b.name)))
|
|
191
195
|
|
|
@@ -233,6 +237,7 @@ function formatTodo(todo, now = new Date()) {
|
|
|
233
237
|
}
|
|
234
238
|
if (p.finished.length) out.push(` finished: ${p.finished.join(', ')}`)
|
|
235
239
|
for (const b of p.blocked) out.push(` blocked: ${blockedText(b, now)}`)
|
|
240
|
+
if (p.ideas) out.push(` ideas: ${p.ideas} waiting · /spec-idea lists them`)
|
|
236
241
|
if (p.today.commits || p.today.moves) {
|
|
237
242
|
const parts = [p.today.commits && `${p.today.commits} commit${p.today.commits === 1 ? '' : 's'}`, p.today.moves && `${p.today.moves} move${p.today.moves === 1 ? '' : 's'}`]
|
|
238
243
|
out.push(` today: ${parts.filter(Boolean).join(', ')}`)
|