@sassywares/skills 0.11.22 → 0.12.1
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/CONCEPTS.md +36 -22
- package/README.md +42 -33
- package/package.json +1 -1
- package/skills/sassy-goal/SKILL.md +5 -5
- package/skills/sassy-goal/references/close.md +4 -4
- package/skills/sassy-goal/references/goal-format.md +27 -4
- package/skills/sassy-goal/references/next.md +2 -1
- package/skills/sassy-goal/references/write.md +2 -2
- package/skills/sassy-lfg/SKILL.md +2 -2
- package/skills/sassy-overview/SKILL.md +52 -0
- package/skills/sassy-overview/references/identify.md +82 -0
- package/skills/sassy-overview/scripts/identify.sh +83 -0
- package/skills/sassy-overview/scripts/lib.sh +334 -0
- package/skills/sassy-plan/SKILL.md +5 -5
- package/skills/sassy-plan/references/plan-format.md +34 -6
- package/skills/sassy-setup/SKILL.md +8 -8
- package/skills/sassy-setup/assets/dogfood-recipe.md +1 -1
- package/skills/sassy-setup/assets/lifecycle/down +29 -0
- package/skills/sassy-setup/assets/lifecycle/up +34 -0
- package/skills/sassy-setup/assets/roster +1 -0
- package/skills/sassy-setup/assets/sassywares-readme.md +5 -4
- package/skills/sassy-setup/assets/worktree/_lib.sh +52 -213
- package/skills/sassy-setup/assets/worktree/create +18 -33
- package/skills/sassy-setup/assets/worktree/list +20 -54
- package/skills/sassy-setup/assets/worktree/prune +13 -9
- package/skills/sassy-setup/assets/worktree/remove +83 -26
- package/skills/sassy-setup/references/branching.md +7 -3
- package/skills/sassy-setup/references/config.md +105 -24
- package/skills/sassy-setup/references/dogfood.md +11 -17
- package/skills/sassy-setup/references/init.md +18 -4
- package/skills/sassy-setup/references/workspace.md +27 -34
- package/skills/sassy-setup/references/worktree.md +66 -75
- package/skills/sassy-setup/scripts/detect.sh +112 -103
- package/skills/sassy-setup/scripts/hash-skill.mjs +31 -18
- package/skills/sassy-setup/scripts/worktree-check.mjs +89 -0
- package/skills/sassy-ship/SKILL.md +1 -1
- package/skills/sassy-work/SKILL.md +2 -2
- package/skills/sassy-worktree/SKILL.md +17 -21
- package/skills/sassy-worktree/references/create.md +3 -3
- package/skills/sassy-worktree/references/list.md +2 -2
- package/skills/sassy-worktree/references/prune.md +4 -4
- package/skills/sassy-worktree/references/remove.md +8 -6
- package/skills/sassy-setup/assets/worktree/stop +0 -65
- package/skills/sassy-worktree/references/preview.md +0 -17
|
@@ -35,9 +35,9 @@ A check run never edits the config and never rewrites the tree. Its only possibl
|
|
|
35
35
|
|
|
36
36
|
## Steps 7–9 — shared by both modes
|
|
37
37
|
|
|
38
|
-
7. **Verify.** Run `scripts/detect.sh --root <path> --check`. It validates the config against the tree — topology and remotes, `base_map` shape and cycles, `repos` against each nested repo, hooks, artifacts paths, `knowledge`, `pr.*` booleans, `commit.branch`, the `worktrees` block, the `dogfood` block, any unknown key, and in `workspace` mode the installed snapshot's version — plus, for a project-scope install, the pin: every suite-skill folder in `.agents/skills` (a name in the suite's roster, `assets/roster` in sassy-setup, not any `sassy-` prefix) hashed against `skills-lock.json`, the lock's coverage both ways, and whether git carries the lock. A user-scope install has no pin here; the check notes the scope it found. Report every `drift:` line verbatim, or that the config matches the tree. Drift blocks step 8.
|
|
38
|
+
7. **Verify.** Run `scripts/detect.sh --root <path> --check`. It validates the config against the tree — topology and remotes, `base_map` shape and cycles, `repos` against each nested repo, hooks, artifacts paths, `knowledge`, `pr.*` booleans, `commit.branch`, the `worktrees` block, the top-level `up`/`down` pair (accepted there, and a stray nested `up.*`/`down.*` is an unknown key), the `dogfood` block, any unknown key, and in `workspace` mode the installed snapshot's version — plus, for a project-scope install, the pin: every suite-skill folder in `.agents/skills` (a name in the suite's roster, `assets/roster` in sassy-setup, not any `sassy-` prefix) hashed against `skills-lock.json`, the lock's coverage both ways, and whether git carries the lock. A user-scope install has no pin here; the check notes the scope it found. Report every `drift:` line verbatim, or that the config matches the tree. Drift blocks step 8.
|
|
39
39
|
|
|
40
|
-
The `worktrees` half checks what a run would read: the switch
|
|
40
|
+
The `worktrees` half checks what a run would read: the switch, that the tooling is installed with the shipped bytes, that no checkout sits inside the working tree, and that none holds a branch `base_map` names as a base.
|
|
41
41
|
|
|
42
42
|
The `dogfood` half is structural and never runs the product: `enabled` and `timeout` are in range, the two paths are relative and stay inside the project, `reports` and `.sassywares/session` are gitignored in a `repo` topology, and the recipe has a `**Prove it:**` line per section with an `**Expect**` per step and no secret-shaped string. A recipe that does not exist yet is a note, not drift — unless `enabled` is `true`, which is the one combination that would let a planner write Auto rows against a check nobody has.
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ A check run never edits the config and never rewrites the tree. Its only possibl
|
|
|
45
45
|
|
|
46
46
|
8. **Commit what setup owns.** `repo` topology only, and only when step 7 is clean. The file list is exactly what setup wrote or found unwritten:
|
|
47
47
|
|
|
48
|
-
`.sassywares/config.yaml`, `.sassywares/README.md`, `.sassywares/dogfood/recipe.md` and `.sassywares/.gitignore` when step 4 created them, `.sassywares/worktree/*`
|
|
48
|
+
`.sassywares/config.yaml`, `.sassywares/README.md`, `.sassywares/dogfood/recipe.md` and `.sassywares/.gitignore` when step 4 created them, the `up`/`down` stubs step 4 wrote (only those two named scripts — never their directory), `.sassywares/worktree/*` when step 6 installed the tooling, the runner file when the user accepted aliases in it, `.agents/skills/sassy-*` and `skills-lock.json` when the suite is in project scope, the project-scope agent files when step 5 copied them, and a root `.gitignore` when step 5 created one. Named files only — never `git add -A`, never `git add .`. The reports directory is never in this list: it is gitignored, and nothing setup writes lives there.
|
|
49
49
|
|
|
50
50
|
Dispatch `sassy-commit` with that list and `branch:current`. The token is explicit, not this skill's default: wiring is a one-time bootstrap commit, and cutting a branch would leave the project configured but uncommitted until someone ships it. Name the branch it landed on, base branch included.
|
|
51
51
|
|
|
@@ -54,7 +54,7 @@ A check run never edits the config and never rewrites the tree. Its only possibl
|
|
|
54
54
|
- **`workspace`** — nothing to commit: the root is not a repo, and `references/workspace.md` forbids running the snapshot here. Say the root config and the pin land with the project's next snapshot.
|
|
55
55
|
- **`none`** — nothing to commit, deliberately.
|
|
56
56
|
|
|
57
|
-
9. **Report.** The config path, the topology, the resolved artifact and knowledge paths, whether agent QA is **off** — one line saying every QA row stays a human's, with no suggestion attached — or on, and then whether the recipe is ready or still a skeleton until `sassy-dogfood mode:discover` runs, where the skills are installed (scope) and where the agents are (scope and harness), or why either is not, the commit (hash and branch) or why there is none, and in `workspace` mode what was installed, with versions (`snapshot vN`, `workspace-git vN`), and the
|
|
57
|
+
9. **Report.** The config path, the topology, the resolved artifact and knowledge paths, the lifecycle — the two values `up` and `down` name, or one line saying the project declares **no lifecycle** because the keys are absent, with no suggestion attached — whether agent QA is **off** — one line saying every QA row stays a human's, with no suggestion attached — or on, and then whether the recipe is ready or still a skeleton until `sassy-dogfood mode:discover` runs, where the skills are installed (scope) and where the agents are (scope and harness), or why either is not, the commit (hash and branch) or why there is none, and in `workspace` mode what was installed, with versions (`snapshot vN`, `workspace-git vN`), and where the `worktree:*` / `workspace:*` aliases went, or that none were wired because the project has no command-building file to put them in — naming the scripts' path instead, since that is how they are run either way. Remind: `/reload` so the harness rescans. Close with what is left over — at most dirt setup deliberately did not commit — and nothing else: a clean setup leaves the user good to go.
|
|
58
58
|
|
|
59
59
|
## Hard rules — every mode
|
|
60
60
|
|
|
@@ -62,13 +62,13 @@ A check run never edits the config and never rewrites the tree. Its only possibl
|
|
|
62
62
|
|------|-------------|
|
|
63
63
|
| No `git init` | Setup never turns a folder into a repo, and never does remote or ref surgery. The step 8 commit is its only git write. |
|
|
64
64
|
| Verify before commit | A config that fails `--check` is reported, never committed. |
|
|
65
|
-
| Commit only what setup owns | The config, the setup README, the vendored `sassy-*` folders and `skills-lock.json` (project scope), the project-scope agent files, and a `.gitignore` setup created. Never a file the user wrote or the repo already had, unless they name it. |
|
|
65
|
+
| Commit only what setup owns | The config, the setup README, the `up`/`down` stubs step 4 wrote, the vendored `sassy-*` folders and `skills-lock.json` (project scope), the project-scope agent files, and a `.gitignore` setup created. Never a file the user wrote or the repo already had, unless they name it. |
|
|
66
66
|
| No silent overwrite | An existing config or an existing `.sassywares/workspace/snapshot` is shown and asked about, never replaced blind. |
|
|
67
|
-
| Write boundary | Only `.sassywares/` (the config, the setup README, the dogfood scaffold, and the worktree tooling), the skills and agent files step 5 installed in the scope the user chose, `skills-lock.json` (project scope), `.sassywares/.gitignore` with its two lines, and at most one root `.gitignore` line that step 5 created. Never `package.json` outside step 6's `worktree:*` and `workspace:*` aliases, never a root `.gitignore` in a workspace. Workspace git helpers land in `.sassywares/workspace/`, never in a project's `bin/`. |
|
|
68
|
-
| Install the tooling, never use it | Setup copies `.sassywares/worktree/` and
|
|
67
|
+
| Write boundary | Only `.sassywares/` (the config, the setup README, the dogfood scaffold, and the worktree tooling), the two `up`/`down` stubs step 4 wrote at their probed path, the skills and agent files step 5 installed in the scope the user chose, `skills-lock.json` (project scope), `.sassywares/.gitignore` with its two lines, and at most one root `.gitignore` line that step 5 created. Never `package.json` outside step 6's `worktree:*` and `workspace:*` aliases, never a root `.gitignore` in a workspace. Workspace git helpers land in `.sassywares/workspace/`, never in a project's `bin/`. |
|
|
68
|
+
| Install the tooling, never use it | Setup copies `.sassywares/worktree/` and offers the aliases. It never creates a checkout, never runs a script, and never starts or stops the project's stack — `up` is the project's or the user's, and `down` runs only from `remove`. |
|
|
69
69
|
| Skills come from upstream | Install with `npx skills add`, `-g` for user scope; never hand-copy skill files or maintain the links yourself. |
|
|
70
70
|
| Agents come from sassy-agents | Only the running harness's folder, as-is: linked by `install.sh` (user scope) or copied verbatim (project scope). Never edit, merge, or overwrite a differing agent file without asking. |
|
|
71
|
-
| Never edit the manifest | No dependencies, no `postinstall`, no `skills:*` scripts.
|
|
71
|
+
| Never edit the manifest | No dependencies, no `postinstall`, no `skills:*` scripts. Step 6's `worktree:*` and `workspace:*` aliases may be added, and only into a file that already carries named commands: appended or corrected, never removed, nothing else in the file touched, and **never a manifest created to hold them**. A project with no such file gets no aliases and loses nothing — the scripts are run by path. Setup installs the suite; the user or project decides how it updates. |
|
|
72
72
|
| Run output and sessions never ship | `.sassywares/.gitignore` holds `/session/` and `/dogfood/reports/`. Never remove a line, never add anything from either path to the commit, and never write a credential anywhere else. |
|
|
73
73
|
| No secrets in setup's writes | Env var names only, in the config and in the skeleton. A credential never lands in a file setup commits. |
|
|
74
74
|
| Version is reported | Setup names the snapshot and `workspace-git` versions it installed; `--check` flags an installed copy older than the skill's. |
|
|
@@ -8,7 +8,7 @@ never values>
|
|
|
8
8
|
**Reset:** <the product back to a known state — a database, a cache, a temp dir.
|
|
9
9
|
Never `reports/`: evidence must outlive the run that made it>`
|
|
10
10
|
|
|
11
|
-
**Preview:** <what you look at once it is up —
|
|
11
|
+
**Preview:** <what you look at once it is up — a URL, a simulator name, a window. Not the command; that is a step below.>
|
|
12
12
|
|
|
13
13
|
<!--
|
|
14
14
|
Incomplete on purpose. sassy-setup writes this skeleton so the shape is visible;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# down — how this project's stack stops.
|
|
3
|
+
#
|
|
4
|
+
# sassy-setup wrote this stub and will never edit it again: replace the body below
|
|
5
|
+
# with this project's real stop command. The suite reads the `down:` key in
|
|
6
|
+
# .sassywares/config.yaml, not this file's name, so keep the two in step if you
|
|
7
|
+
# rename the file.
|
|
8
|
+
#
|
|
9
|
+
# Unimplemented: this stub exits 78. Implement it, or delete the `down:` key if
|
|
10
|
+
# nothing needs stopping.
|
|
11
|
+
#
|
|
12
|
+
# The contract:
|
|
13
|
+
# * Terminate what `up` started, then exit: no daemon left behind, nothing else
|
|
14
|
+
# still holding this checkout.
|
|
15
|
+
# * Idempotent. A stack that is already down is not an error.
|
|
16
|
+
# * It runs from inside the checkout, before the folder is deleted, after the
|
|
17
|
+
# guards have passed — so a failure here aborts the removal rather than
|
|
18
|
+
# leaving something running in a directory nobody owns. Until this stub is
|
|
19
|
+
# real, that is what it does: it refuses, because how this project stops is
|
|
20
|
+
# still unknown. Delete the `down:` key instead if nothing needs stopping.
|
|
21
|
+
# * These are exported: WT_PATH (this checkout), WT_BRANCH, WT_SLUG, and
|
|
22
|
+
# WT_NAMESPACE (the derived database / compose project / device name).
|
|
23
|
+
set -euo pipefail
|
|
24
|
+
|
|
25
|
+
printf 'down: not implemented yet — this project has not said how its stack stops.\n' >&2
|
|
26
|
+
printf ' Read the contract at the top of %s, then replace this body.\n' "$0" >&2
|
|
27
|
+
printf ' WT_PATH=%s\n WT_BRANCH=%s\n WT_SLUG=%s\n WT_NAMESPACE=%s\n' \
|
|
28
|
+
"${WT_PATH:-<unset>}" "${WT_BRANCH:-<unset>}" "${WT_SLUG:-<unset>}" "${WT_NAMESPACE:-<unset>}" >&2
|
|
29
|
+
exit 78
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# up — how this project's stack starts.
|
|
3
|
+
#
|
|
4
|
+
# sassy-setup wrote this stub and will never edit it again: replace the body below
|
|
5
|
+
# with this project's real start command. The suite reads the `up:` key in
|
|
6
|
+
# .sassywares/config.yaml, not this file's name, so keep the two in step if you
|
|
7
|
+
# rename the file.
|
|
8
|
+
#
|
|
9
|
+
# Unimplemented: this stub exits 78. Implement it, or delete the `up:` key if
|
|
10
|
+
# nothing needs starting.
|
|
11
|
+
#
|
|
12
|
+
# The contract:
|
|
13
|
+
# * Run in the FOREGROUND. This process owns the stack until it is stopped, so a
|
|
14
|
+
# detached or daemonized app outlives the call and holds the checkout — which
|
|
15
|
+
# is exactly what `down` then cannot kill.
|
|
16
|
+
# * Stop on SIGTERM (and Ctrl-C) and reap the children you started before you
|
|
17
|
+
# exit. `down` is the other half of the pair: it must terminate what this one
|
|
18
|
+
# started, and it runs before a checkout is deleted.
|
|
19
|
+
# * These are exported by whoever runs this, so a checkout stays distinct from
|
|
20
|
+
# its siblings. Derive names from them, never build one by hand:
|
|
21
|
+
# WT_PATH this checkout
|
|
22
|
+
# WT_BRANCH the branch it holds
|
|
23
|
+
# WT_SLUG the branch, filesystem-safe
|
|
24
|
+
# WT_NAMESPACE the derived name for a database, a compose project, a device
|
|
25
|
+
# * Ports are this project's business: the suite derives none, so two checkouts
|
|
26
|
+
# running the same app collide on a fixed port. Hash WT_SLUG into one instead,
|
|
27
|
+
# e.g. PORT=$(( 3000 + $(printf '%s' "$WT_SLUG" | cksum | cut -d' ' -f1) % 100 )).
|
|
28
|
+
set -euo pipefail
|
|
29
|
+
|
|
30
|
+
printf 'up: not implemented yet — nothing here starts this project.\n' >&2
|
|
31
|
+
printf ' Read the contract at the top of %s, then replace this body.\n' "$0" >&2
|
|
32
|
+
printf ' WT_PATH=%s\n WT_BRANCH=%s\n WT_SLUG=%s\n WT_NAMESPACE=%s\n' \
|
|
33
|
+
"${WT_PATH:-<unset>}" "${WT_BRANCH:-<unset>}" "${WT_SLUG:-<unset>}" "${WT_NAMESPACE:-<unset>}" >&2
|
|
34
|
+
exit 78
|
|
@@ -59,10 +59,11 @@ across the sibling repos, next to the `snapshot` that versions the glue:
|
|
|
59
59
|
.sassywares/workspace/snapshot # commit + push the glue
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
Run them by path from the root — that is all they need, and it works in every
|
|
63
|
+
shell. If this project already had a file carrying named commands, the same
|
|
64
|
+
scripts are also wired into it as `workspace:<script>` (`workspace:pull`,
|
|
65
|
+
`workspace:snapshot`, …), so your runner reaches them too. The aliases are a
|
|
66
|
+
convenience; the paths are the contract.
|
|
66
67
|
|
|
67
68
|
They read the repo inventory and the PR bases from `repos:` in `config.yaml`, so
|
|
68
69
|
there is no second base map to keep in step. They are this project's files:
|
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Shared helpers for the worktree scripts: create, list,
|
|
2
|
+
# Shared helpers for the worktree scripts: create, list, remove, prune.
|
|
3
3
|
#
|
|
4
|
-
# Installed next to those scripts by sassy-setup
|
|
5
|
-
#
|
|
4
|
+
# Installed next to those scripts by sassy-setup. Suite-owned and read-only, so
|
|
5
|
+
# every project runs the same mechanics. Three rules worth keeping:
|
|
6
6
|
#
|
|
7
|
-
# 1.
|
|
8
|
-
# `worktrees:` in .sassywares/config.yaml
|
|
9
|
-
#
|
|
7
|
+
# 1. Two config sources, each with exactly one owner. The worktree home and the
|
|
8
|
+
# on/off switch live under `worktrees:` in .sassywares/config.yaml; the stack
|
|
9
|
+
# life cycle is the top-level `down:`/`up:`. Never duplicate either one into
|
|
10
|
+
# the other block, and never grow a third source.
|
|
11
|
+
# 2. Identity is derived here once — never built by hand downstream.
|
|
10
12
|
# 3. Everything resolves against the MAIN checkout, so running any of these
|
|
11
13
|
# from inside a worktree behaves identically.
|
|
12
14
|
#
|
|
13
|
-
# worktree-version:
|
|
15
|
+
# worktree-version: 12
|
|
14
16
|
|
|
15
17
|
set -euo pipefail
|
|
16
18
|
|
|
17
|
-
WT_VERSION="
|
|
19
|
+
WT_VERSION="12"
|
|
18
20
|
WT_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
19
21
|
|
|
20
22
|
log() { printf '%s\n' "$*"; }
|
|
21
23
|
ok() { printf ' %-9s %s\n' "$1" "$2"; }
|
|
22
|
-
warn() { printf ' %-9s %s\n' "!" "
|
|
24
|
+
warn() { printf ' %-9s %s\n' "!" "$*" >&2; }
|
|
23
25
|
die() { printf ' ✗ %s\n' "$*" >&2; exit 1; }
|
|
24
26
|
hint() { printf ' %-9s %s\n' "→" "$*"; }
|
|
27
|
+
# The exit-3 handshake: something the script cannot dispatch is still owed, and
|
|
28
|
+
# the caller has to run it before re-invoking with --hook-ok.
|
|
29
|
+
require_dispatch() {
|
|
30
|
+
hint "$1" >&2
|
|
31
|
+
exit 3
|
|
32
|
+
}
|
|
25
33
|
|
|
26
34
|
# The nearest config, walking up from the cwd — used only to explain a refusal
|
|
27
35
|
# when there is no repo to work in at all.
|
|
@@ -88,15 +96,45 @@ wt_flat() {
|
|
|
88
96
|
}' "${1:-${CONFIG:-/dev/null}}" 2>/dev/null
|
|
89
97
|
}
|
|
90
98
|
|
|
99
|
+
# wt_get PATH — the value of one flattened config path, or empty. The one lookup
|
|
100
|
+
# every reader uses, so a nested map has exactly one interpretation.
|
|
101
|
+
wt_get() {
|
|
102
|
+
wt_flat | awk -F'\t' -v p="$1" '$1 == p { print $2; exit }'
|
|
103
|
+
}
|
|
104
|
+
|
|
91
105
|
# wt_cfg KEY DEFAULT — a dotted path under the `worktrees:` block.
|
|
92
106
|
wt_cfg() {
|
|
93
107
|
local v
|
|
94
|
-
v="$(
|
|
108
|
+
v="$(wt_get "worktrees${WLIB_US}$1")"
|
|
95
109
|
printf '%s' "${v:-$2}"
|
|
96
110
|
}
|
|
97
111
|
|
|
98
112
|
wt_enabled() { [ "$(wt_cfg enabled false)" = "true" ]; }
|
|
99
113
|
|
|
114
|
+
# wt_down — the top-level `down:` entry, exactly as written, or empty when the
|
|
115
|
+
# project declares no lifecycle. Top-level by design (never under `worktrees:`).
|
|
116
|
+
wt_down() { wt_get down; }
|
|
117
|
+
|
|
118
|
+
# wt_resolve VALUE CHECKOUT — how to run one top-level life-cycle value, as
|
|
119
|
+
# `<run|skill|missing|none><TAB><command><TAB><args…>`. `run` means the command
|
|
120
|
+
# exists — a path in the checkout, an absolute path, or a word on PATH — so a
|
|
121
|
+
# shell script can execute it; `skill` means nothing on disk claims the word, so
|
|
122
|
+
# only an agent can dispatch it; `missing` means the value is path-shaped but no
|
|
123
|
+
# such executable exists; `none` means the value is empty. Args are command
|
|
124
|
+
# words, not patterns: callers disable globbing before expanding them.
|
|
125
|
+
wt_resolve() {
|
|
126
|
+
local value="${1:-}" checkout="${2:-}" cmd="" args="" how=skill
|
|
127
|
+
[ -n "$value" ] || { printf 'none\t\t'; return 0; }
|
|
128
|
+
cmd="${value%% *}"
|
|
129
|
+
case "$value" in *" "*) args="${value#* }" ;; esac
|
|
130
|
+
case "$cmd" in
|
|
131
|
+
/*) if [ -f "$cmd" ] && [ -x "$cmd" ]; then how=run; else how=missing; fi ;;
|
|
132
|
+
*/*) if [ -f "$checkout/$cmd" ] && [ -x "$checkout/$cmd" ]; then how=run; else how=missing; fi ;;
|
|
133
|
+
*) command -v "$cmd" >/dev/null 2>&1 && how=run ;;
|
|
134
|
+
esac
|
|
135
|
+
printf '%s\t%s\t%s' "$how" "$cmd" "$args"
|
|
136
|
+
}
|
|
137
|
+
|
|
100
138
|
# A list value (`[a b]`) split one per line.
|
|
101
139
|
wt_list_items() {
|
|
102
140
|
printf '%s' "$1" | sed -e 's/^\[//' -e 's/\]$//' | tr ',' '\n' \
|
|
@@ -107,9 +145,9 @@ wt_list_items() {
|
|
|
107
145
|
# The first match wins, so `hooks.worktree."*"` applies when no branch matches.
|
|
108
146
|
wt_hook() { # $1 point (after_create|before_remove), $2 branch — one entry per line
|
|
109
147
|
local point="$1" branch="$2" v=""
|
|
110
|
-
v="$(
|
|
148
|
+
v="$(wt_get "hooks${WLIB_US}worktree${WLIB_US}${branch}${WLIB_US}${point}")"
|
|
111
149
|
if [ -z "$v" ]; then
|
|
112
|
-
v="$(
|
|
150
|
+
v="$(wt_get "hooks${WLIB_US}worktree${WLIB_US}*${WLIB_US}${point}")"
|
|
113
151
|
fi
|
|
114
152
|
wt_list_items "$v"
|
|
115
153
|
}
|
|
@@ -137,7 +175,7 @@ wt_home() {
|
|
|
137
175
|
*) dir="$MAIN/$dir" ;;
|
|
138
176
|
esac
|
|
139
177
|
# Resolve through the parent, so /tmp and /private/tmp never disagree and the
|
|
140
|
-
# paths match what `git worktree list`
|
|
178
|
+
# paths match what `git worktree list` prints.
|
|
141
179
|
parent="$(dirname "$dir")"
|
|
142
180
|
[ -d "$parent" ] && dir="$(cd "$parent" && pwd -P)/$(basename "$dir")"
|
|
143
181
|
base="$(basename "$MAIN")"
|
|
@@ -155,43 +193,7 @@ wt_home() {
|
|
|
155
193
|
|
|
156
194
|
wt_path() { printf '%s/%s' "$(wt_home)" "$1"; }
|
|
157
195
|
|
|
158
|
-
# ---
|
|
159
|
-
# A port is one resource a checkout may need, not the definition of a preview. A
|
|
160
|
-
# mobile app claims a simulator, a desktop app nothing, and both are legitimate:
|
|
161
|
-
# when `worktrees.ports` is absent nothing is derived and nothing is claimed.
|
|
162
|
-
wt_has_ports() { [ -n "$(wt_cfg ports '')" ]; }
|
|
163
|
-
|
|
164
|
-
wt_range() {
|
|
165
|
-
local r lo hi
|
|
166
|
-
r="$(wt_cfg ports '')"
|
|
167
|
-
[ -n "$r" ] || return 0
|
|
168
|
-
case "$r" in
|
|
169
|
-
*-*) lo="${r%%-*}"; hi="${r##*-}" ;;
|
|
170
|
-
*) lo="$r"; hi="$r" ;;
|
|
171
|
-
esac
|
|
172
|
-
case "$lo$hi" in *[!0-9]*) die "worktrees.ports '$r' is not <from>-<to>" ;; esac
|
|
173
|
-
[ "$lo" -le "$hi" ] || die "worktrees.ports '$r' has an empty range"
|
|
174
|
-
printf '%s %s' "$lo" "$hi"
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
# tcp_up PORT — 0 when something accepts a connection on loopback.
|
|
178
|
-
# Liveness is observed, never read from a state file: a killed preview leaves no
|
|
179
|
-
# trace to go stale. The probe runs in a subshell so a successful connect cannot
|
|
180
|
-
# leave a descriptor (or a fatal `exec`) behind in the caller.
|
|
181
|
-
tcp_up() {
|
|
182
|
-
local port="$1"
|
|
183
|
-
# IPv4, then IPv6: a dev server that binds `[::1]` only is up, and an IPv4-only
|
|
184
|
-
# probe reads it as down — which would make `LIVE` lie and `remove`'s
|
|
185
|
-
# live-preview refusal unreachable.
|
|
186
|
-
if (exec 3<>"/dev/tcp/127.0.0.1/$port") >/dev/null 2>&1; then return 0; fi
|
|
187
|
-
if (exec 3<>"/dev/tcp/::1/$port") >/dev/null 2>&1; then return 0; fi
|
|
188
|
-
# Last resort for a listener /dev/tcp cannot reach.
|
|
189
|
-
if command -v lsof >/dev/null 2>&1 && lsof -nP -iTCP:"$port" -sTCP:LISTEN >/dev/null 2>&1; then
|
|
190
|
-
return 0
|
|
191
|
-
fi
|
|
192
|
-
return 1
|
|
193
|
-
}
|
|
194
|
-
|
|
196
|
+
# --- display --------------------------------------------------------------
|
|
195
197
|
# short_path PATH WIDTH — keep the tail of a long path, because the tail holds the
|
|
196
198
|
# slug and the start is always the same worktree home.
|
|
197
199
|
short_path() {
|
|
@@ -199,64 +201,6 @@ short_path() {
|
|
|
199
201
|
if [ "${#s}" -gt "$w" ]; then printf '…%s' "${s: -$(( w - 1 ))}"; else printf '%s' "$s"; fi
|
|
200
202
|
}
|
|
201
203
|
|
|
202
|
-
wt_claim_dir() { printf '%s/ports/%s' "$(wt_home)" "$1"; }
|
|
203
|
-
|
|
204
|
-
# wt_owner PORT — the slug that claimed a port, or empty.
|
|
205
|
-
wt_owner() {
|
|
206
|
-
local f
|
|
207
|
-
f="$(wt_claim_dir "$1")/owner"
|
|
208
|
-
[ -f "$f" ] && cat "$f" 2>/dev/null || true
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
# wt_claim SLUG — print the port this slug owns, claiming one when needed.
|
|
212
|
-
# Deterministic first (a restarted preview comes back on the same port), then a
|
|
213
|
-
# linear probe so two slugs that hash alike do not fight.
|
|
214
|
-
# wt_port_for SLUG — the port this slug uses: an existing claim, else the derived
|
|
215
|
-
# one probed forward past claims held by others. Read-only, so `list` may call it.
|
|
216
|
-
wt_port_for() {
|
|
217
|
-
local slug="$1" lo hi span i port owner hex d
|
|
218
|
-
wt_has_ports || return 0
|
|
219
|
-
read -r lo hi <<<"$(wt_range)"
|
|
220
|
-
for d in "$(wt_home)/ports"/*; do
|
|
221
|
-
[ -d "$d" ] || continue
|
|
222
|
-
if [ "$(cat "$d/owner" 2>/dev/null)" = "$slug" ]; then
|
|
223
|
-
basename "$d"
|
|
224
|
-
return 0
|
|
225
|
-
fi
|
|
226
|
-
done
|
|
227
|
-
span=$(( hi - lo + 1 ))
|
|
228
|
-
hex="$(printf '%s' "$slug" | shasum -a 256 | cut -c1-8)"
|
|
229
|
-
i=$(( 16#$hex % span ))
|
|
230
|
-
port=$(( lo + i ))
|
|
231
|
-
while :; do
|
|
232
|
-
owner="$(wt_owner "$port")"
|
|
233
|
-
if [ -z "$owner" ] || [ "$owner" = "$slug" ]; then
|
|
234
|
-
printf '%s' "$port"
|
|
235
|
-
return 0
|
|
236
|
-
fi
|
|
237
|
-
port=$(( port + 1 ))
|
|
238
|
-
[ "$port" -gt "$hi" ] && port=$lo
|
|
239
|
-
i=$(( i + 1 ))
|
|
240
|
-
[ "$i" -gt "$span" ] && die "no free port in $(wt_range | sed 's/ /-/')"
|
|
241
|
-
done
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
# wt_claim SLUG — claim and print the port, writing the lock directory.
|
|
245
|
-
wt_claim() {
|
|
246
|
-
local slug="$1" port
|
|
247
|
-
port="$(wt_port_for "$slug")"
|
|
248
|
-
mkdir -p "$(wt_claim_dir "$port")"
|
|
249
|
-
printf '%s' "$slug" > "$(wt_claim_dir "$port")/owner"
|
|
250
|
-
printf '%s' "$port"
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
wt_release() { # $1 port, $2 slug
|
|
254
|
-
local d
|
|
255
|
-
d="$(wt_claim_dir "$1")"
|
|
256
|
-
[ "$(wt_owner "$1")" = "$2" ] && rm -rf "$d"
|
|
257
|
-
return 0
|
|
258
|
-
}
|
|
259
|
-
|
|
260
204
|
# --- checkouts ------------------------------------------------------------
|
|
261
205
|
# Emits one record per worktree: path<TAB>branch.
|
|
262
206
|
wt_all() {
|
|
@@ -340,108 +284,3 @@ wt_upstream_state() { # merged | gone | unmerged
|
|
|
340
284
|
printf 'unmerged'
|
|
341
285
|
fi
|
|
342
286
|
}
|
|
343
|
-
|
|
344
|
-
# wt_subst LINE NAME VALUE — expand `$NAME`, `${NAME}` and `${NAME:-default}` for
|
|
345
|
-
# one variable. No name here is a prefix of another, so a plain replace is exact.
|
|
346
|
-
wt_subst() {
|
|
347
|
-
local line="$1" name="$2" val="$3"
|
|
348
|
-
if [ -n "$val" ]; then
|
|
349
|
-
printf '%s' "$line" \
|
|
350
|
-
| sed -e "s|\${$name:-[^}]*}|$val|g" -e "s|\${$name}|$val|g" -e "s|\$$name|$val|g"
|
|
351
|
-
else
|
|
352
|
-
printf '%s' "$line" \
|
|
353
|
-
| sed -e "s|\${$name:-\([^}]*\)}|\1|g" -e "s|\${$name}||g" -e "s|\$$name||g"
|
|
354
|
-
fi
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
# _wt_preview_block RECIPE [SECTION] — the `**Preview:**` block, joined to one line.
|
|
358
|
-
# With no section it reads only what sits *before* the first `## ` heading, so a
|
|
359
|
-
# nested recipe's first app cannot masquerade as the file-level address.
|
|
360
|
-
_wt_preview_block() {
|
|
361
|
-
awk -v want="${2:-}" '
|
|
362
|
-
/^## / {
|
|
363
|
-
if (want == "") exit
|
|
364
|
-
s = $0; sub(/^## +/, "", s); split(s, pr, /[ \t]+/); cur = pr[1]; inb = 0; next
|
|
365
|
-
}
|
|
366
|
-
want != "" && cur != want { next }
|
|
367
|
-
/^\*\*Preview:\*\*/ { sub(/^\*\*Preview:\*\*[[:space:]]*/, ""); buf = $0; inb = 1; next }
|
|
368
|
-
inb && /^[[:space:]]*$/ { inb = 0; next }
|
|
369
|
-
inb && /^\*\*/ { inb = 0; next }
|
|
370
|
-
inb { buf = buf " " $0 }
|
|
371
|
-
END { printf "%s", buf }
|
|
372
|
-
' "$1" | sed -E 's/[[:space:]]+/ /g; s/[[:space:]]+$//'
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
# wt_preview SLUG [SECTION] — how to see this checkout, substituted.
|
|
376
|
-
# A section's own line wins when one is asked for; otherwise the file-level line is
|
|
377
|
-
# the checkout's address. With no file-level line and exactly one section, that
|
|
378
|
-
# section is the answer; with several, nothing is returned rather than guessing which
|
|
379
|
-
# app a checkout is serving.
|
|
380
|
-
wt_preview() {
|
|
381
|
-
local slug="$1" sect="${2:-}" recipe line="" cand count sl port base
|
|
382
|
-
recipe="$(wt_flat | awk -F'\t' -v p="dogfood${WLIB_US}recipe" '$1 == p { print $2; exit }')"
|
|
383
|
-
recipe="${recipe:-.sassywares/dogfood/recipe.md}"
|
|
384
|
-
case "$recipe" in /*) ;; *) recipe="$MAIN/$recipe" ;; esac
|
|
385
|
-
[ -f "$recipe" ] || return 0
|
|
386
|
-
if [ -n "$sect" ]; then line="$(_wt_preview_block "$recipe" "$sect")"; fi
|
|
387
|
-
if [ -z "$line" ]; then line="$(_wt_preview_block "$recipe" "")"; fi
|
|
388
|
-
if [ -z "$line" ]; then
|
|
389
|
-
# Fall back to the single section that *declares* an address. Counting sections
|
|
390
|
-
# would fail on a recipe with one app and one uncovered surface, which is a
|
|
391
|
-
# perfectly ordinary shape: only the app has somewhere to look.
|
|
392
|
-
count=0; cand=""
|
|
393
|
-
while IFS= read -r sl; do
|
|
394
|
-
[ -n "$sl" ] || continue
|
|
395
|
-
cand="$(_wt_preview_block "$recipe" "$sl")"
|
|
396
|
-
[ -n "$cand" ] || continue
|
|
397
|
-
count=$((count + 1))
|
|
398
|
-
line="$cand"
|
|
399
|
-
done < <(sed -n 's/^## \([^ ]*\).*/\1/p' "$recipe")
|
|
400
|
-
[ "$count" -eq 1 ] || line=""
|
|
401
|
-
fi
|
|
402
|
-
[ -n "$line" ] || return 0
|
|
403
|
-
port=""
|
|
404
|
-
if wt_has_ports; then
|
|
405
|
-
port="$(wt_port_for "$slug")"
|
|
406
|
-
base="http://localhost:$port"
|
|
407
|
-
fi
|
|
408
|
-
line="$(wt_subst "$line" WT_SLUG "$slug")"
|
|
409
|
-
line="$(wt_subst "$line" WT_NAMESPACE "$(wt_namespace "$slug")")"
|
|
410
|
-
line="$(wt_subst "$line" WT_PATH "$(wt_path "$slug")")"
|
|
411
|
-
line="$(wt_subst "$line" WT_PORT "$port")"
|
|
412
|
-
line="$(wt_subst "$line" WT_BASE_URL "$base")"
|
|
413
|
-
printf '%s' "$line"
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
# wt_preview_port SLUG — the port the preview line advertises, if it names one.
|
|
417
|
-
# A project with no `worktrees.ports` still has an address; this is how the tools
|
|
418
|
-
# find it without assuming a browser or a claim.
|
|
419
|
-
wt_preview_port() {
|
|
420
|
-
local line
|
|
421
|
-
line="$(wt_preview "$1")"
|
|
422
|
-
[ -n "$line" ] || return 0
|
|
423
|
-
printf '%s' "$line" \
|
|
424
|
-
| grep -oE '(localhost|127\.0\.0\.1):[0-9]+' | head -n 1 | grep -oE '[0-9]+$'
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
# wt_live_port SLUG — where to probe this checkout: its claim if it has one, else
|
|
428
|
-
# the port its preview advertises. Empty means "nothing to probe here".
|
|
429
|
-
wt_live_port() {
|
|
430
|
-
local slug="$1" p
|
|
431
|
-
if wt_has_ports; then
|
|
432
|
-
p="$(wt_port_for "$slug")"
|
|
433
|
-
[ -n "$p" ] && { printf '%s' "$p"; return 0; }
|
|
434
|
-
fi
|
|
435
|
-
wt_preview_port "$slug"
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
# Newest dogfood verdict for a checkout, as `status class` — or empty.
|
|
439
|
-
wt_verdict() {
|
|
440
|
-
local dir="$1/.sassywares/dogfood/reports" newest s c
|
|
441
|
-
[ -d "$dir" ] || return 0
|
|
442
|
-
newest="$(ls -1t "$dir" 2>/dev/null | head -n 1)"
|
|
443
|
-
[ -n "$newest" ] || return 0
|
|
444
|
-
s="$(sed -n 's/^\*\*status:\*\* //p' "$dir/$newest/summary.md" 2>/dev/null | head -n 1)"
|
|
445
|
-
c="$(sed -n 's/^\*\*class:\*\* //p' "$dir/$newest/summary.md" 2>/dev/null | head -n 1)"
|
|
446
|
-
printf '%s%s' "${s:-unknown}" "$( [ -n "$c" ] && printf ' %s' "$c" )"
|
|
447
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Add a worktree for one branch
|
|
2
|
+
# Add a worktree for one branch.
|
|
3
3
|
#
|
|
4
|
-
# Idempotent: a branch already in a worktree of ours is
|
|
4
|
+
# Idempotent: a branch already in a worktree of ours is shown, not recreated,
|
|
5
5
|
# and nobody else's checkout holding it is a stop rather than a clobber.
|
|
6
6
|
#
|
|
7
7
|
# Usage: .sassywares/worktree/create <branch> [--from <start-point>] [--env]
|
|
@@ -16,9 +16,8 @@ usage() {
|
|
|
16
16
|
cat <<'EOF'
|
|
17
17
|
Usage: .sassywares/worktree/create <branch> [--from <start-point>] [--env]
|
|
18
18
|
|
|
19
|
-
Create (or
|
|
20
|
-
|
|
21
|
-
WT_BASE_URL.
|
|
19
|
+
Create (or find) the worktree for <branch> and print the namespace a run
|
|
20
|
+
inherits: WT_PATH, WT_BRANCH, WT_SLUG, WT_NAMESPACE.
|
|
22
21
|
|
|
23
22
|
--from <ref> where a new branch is cut from (default HEAD). A caller that has
|
|
24
23
|
already resolved the base passes it; this script never guesses.
|
|
@@ -49,46 +48,31 @@ wt_enabled || die "worktrees are off here — set worktrees.enabled: true in .sa
|
|
|
49
48
|
slug="$(wt_slug "$branch")"
|
|
50
49
|
path="$(wt_path "$slug")"
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
local
|
|
51
|
+
show() { # $1 path
|
|
52
|
+
local ns
|
|
54
53
|
ns="$(wt_namespace "$slug")"
|
|
55
|
-
# A port is a resource this project asked for, not a property of a checkout.
|
|
56
|
-
if wt_has_ports; then
|
|
57
|
-
port="$(wt_claim "$slug")"
|
|
58
|
-
addr="http://localhost:$port"
|
|
59
|
-
fi
|
|
60
54
|
if [ "$env_only" -eq 1 ]; then
|
|
61
|
-
printf 'WT_PATH=%s\nWT_BRANCH=%s\nWT_SLUG=%s\nWT_NAMESPACE=%s\n' "$1" "$
|
|
62
|
-
[ -n "$port" ] && printf 'WT_PORT=%s\nWT_BASE_URL=%s\n' "$port" "$addr"
|
|
55
|
+
printf 'WT_PATH=%s\nWT_BRANCH=%s\nWT_SLUG=%s\nWT_NAMESPACE=%s\n' "$1" "$branch" "$slug" "$ns"
|
|
63
56
|
return 0
|
|
64
57
|
fi
|
|
65
58
|
ok worktree "$1"
|
|
66
|
-
ok branch "$
|
|
59
|
+
ok branch "$branch"
|
|
67
60
|
# Say the tracking out loud. A branch cut from a remote-tracking ref used to
|
|
68
61
|
# inherit it as its upstream, so a plain push aimed at the base; and a branch
|
|
69
62
|
# that tracks something other than its own name is the state that made that
|
|
70
|
-
# invisible. `create` never sets a base — it
|
|
63
|
+
# invisible. `create` never sets a base — it shows what it found.
|
|
71
64
|
local up
|
|
72
65
|
up="$(wt_upstream "$1")"
|
|
73
66
|
ok upstream "${up:-none}"
|
|
74
|
-
[ -z "$up" ] || [ "${up#*/}" = "$
|
|
75
|
-
|| warn upstream "this branch tracks '$up', not '$
|
|
67
|
+
[ -z "$up" ] || [ "${up#*/}" = "$branch" ] \
|
|
68
|
+
|| warn upstream "this branch tracks '$up', not '$branch' — a plain 'git push' lands there"
|
|
76
69
|
ok namespace "$ns"
|
|
77
|
-
if [ -n "$port" ]; then
|
|
78
|
-
ok port "$port"
|
|
79
|
-
ok address "$addr"
|
|
80
|
-
else
|
|
81
|
-
ok port "none — worktrees.ports is unset, so this checkout holds no port"
|
|
82
|
-
fi
|
|
83
|
-
local preview
|
|
84
|
-
preview="$(wt_preview "$slug")"
|
|
85
|
-
[ -n "$preview" ] && ok preview "$preview"
|
|
86
70
|
# A branch cut from a ref that predates setup has no config and no tooling, so
|
|
87
71
|
# this checkout is not managed here: `list` skips it, `prune` leaves it alone.
|
|
88
72
|
[ -f "$1/.sassywares/config.yaml" ] \
|
|
89
73
|
|| ok unmanaged "this branch has no .sassywares/config.yaml — cut from a ref that predates setup; list and prune will skip it"
|
|
90
74
|
local hooks n
|
|
91
|
-
hooks="$(wt_hook after_create "$
|
|
75
|
+
hooks="$(wt_hook after_create "$branch")"
|
|
92
76
|
if [ -z "$hooks" ]; then
|
|
93
77
|
ok hook "hooks.worktree.after_create — none declared"
|
|
94
78
|
else
|
|
@@ -99,7 +83,7 @@ report() { # $1 path, $2 branch
|
|
|
99
83
|
fi
|
|
100
84
|
}
|
|
101
85
|
|
|
102
|
-
# Already in a worktree of ours:
|
|
86
|
+
# Already in a worktree of ours: show it and stop. This is the second call in a
|
|
103
87
|
# resumed run, and it must not fail.
|
|
104
88
|
existing="$(wt_find "$branch" || true)"
|
|
105
89
|
if [ -n "$existing" ]; then
|
|
@@ -107,7 +91,7 @@ if [ -n "$existing" ]; then
|
|
|
107
91
|
if wt_is_main "$epath"; then
|
|
108
92
|
die "'$branch' is checked out in the main checkout — leave it, or switch the main checkout first"
|
|
109
93
|
fi
|
|
110
|
-
|
|
94
|
+
show "$epath"
|
|
111
95
|
exit 0
|
|
112
96
|
fi
|
|
113
97
|
|
|
@@ -115,8 +99,9 @@ if [ -e "$path" ]; then
|
|
|
115
99
|
die "'$path' exists but no worktree is registered for '$branch' — inspect it, then prune"
|
|
116
100
|
fi
|
|
117
101
|
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
home="$(wt_home)"
|
|
103
|
+
(umask 077; mkdir -p "$home")
|
|
104
|
+
printf '%s\n' "$MAIN" > "$home/.repo"
|
|
120
105
|
|
|
121
106
|
if git show-ref --verify --quiet "refs/heads/$branch"; then
|
|
122
107
|
git worktree add --quiet "$path" "$branch"
|
|
@@ -127,4 +112,4 @@ else
|
|
|
127
112
|
git worktree add --quiet --no-track -b "$branch" "$path" "$from"
|
|
128
113
|
fi
|
|
129
114
|
|
|
130
|
-
|
|
115
|
+
show "$path"
|