@johngaynor/entourage 0.1.0 → 0.1.2

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 CHANGED
@@ -4,7 +4,17 @@ A collection of agent skills for the software development lifecycle (SDLC).
4
4
 
5
5
  ## Status
6
6
 
7
- Early setup. Skills are being ported in.
7
+ Early setup. Three skills are in, and none has been run on a real card yet:
8
+
9
+ | Skill | What it does |
10
+ |---|---|
11
+ | `sdlc-define` | Sets a card's type and writes its Specification |
12
+ | `sdlc-plan` | Reads the card and the code, and writes the Plan |
13
+ | `sdlc-breakdown` | Decides whether the card is one piece or several slices, then asks you to approve it |
14
+
15
+ They live in [skills/](skills/). `entourage install` links them into
16
+ `~/.claude/skills`, so any Claude Code session on the machine can run one by
17
+ name, such as `/sdlc-define ABC-122`.
8
18
 
9
19
  ## Setting up a machine
10
20
 
@@ -14,8 +24,59 @@ entourage install
14
24
  ```
15
25
 
16
26
  `entourage install` links this repo into the tools on a machine, and
17
- `entourage update` keeps it current. Today that covers the Herdr setup; see
18
- [herdr/README.md](herdr/README.md) for the full walkthrough.
27
+ `entourage update` keeps it current. That covers the Herdr setup and the
28
+ skills; see [herdr/README.md](herdr/README.md) for the full walkthrough.
29
+
30
+ ## Projects
31
+
32
+ A project groups the repos that belong together, with a `PROJECT.md` saying
33
+ what each repo is for. Each project opens in Herdr as one space. A repo is
34
+ cloned once and can be in several projects.
35
+
36
+ ```sh
37
+ entourage project new my-project
38
+ entourage project add my-project ~/Dev/api
39
+ entourage project add my-project ~/Dev/web
40
+ entourage project open my-project
41
+ ```
42
+
43
+ Your projects live in `~/.config/entourage/projects`, outside this repo, so
44
+ they are never published and survive updates. See
45
+ [herdr/README.md](herdr/README.md#projects) for how a project is laid out.
46
+
47
+ ## Tasks
48
+
49
+ A task is one piece of work in a project, usually a Linear card. It has two
50
+ commands, used in this order.
51
+
52
+ `task new` writes the card up. It opens a tab in the project's Herdr space and
53
+ starts an agent there, which runs the three skills on the card and then asks
54
+ you to approve it:
55
+
56
+ ```sh
57
+ entourage task new my-project ABC-122
58
+ ```
59
+
60
+ `task start` starts the work. It makes a branch and a git worktree of it in
61
+ every repo of the project, and opens a tab for it:
62
+
63
+ ```sh
64
+ entourage task start my-project feat/abc-122-insert-task-here
65
+ ```
66
+
67
+ The branch is `<type>/<description>`, following
68
+ [Conventional Branch](https://conventionalbranch.org), with the card's ID in
69
+ the description. The description names the task:
70
+
71
+ ```
72
+ ~/.config/entourage/projects/my-project/
73
+ tasks/
74
+ abc-122-insert-task-here/ one folder per task
75
+ api/ a worktree of api on feat/abc-122-insert-task-here
76
+ web/ a worktree of web on the same branch
77
+ ```
78
+
79
+ See [herdr/README.md](herdr/README.md#tasks) for the details.
19
80
 
20
81
  To work on entourage itself, clone the repo and run `cli/entourage install`
21
82
  from the clone instead. Run the CLI's tests with `npm test`.
@@ -31,4 +92,6 @@ git push --follow-tags
31
92
  ```
32
93
 
33
94
  Then publish a GitHub release for that tag. The `Publish to npm` workflow runs
34
- the tests and publishes the package. It needs a repo secret `NPM_TOKEN`.
95
+ the tests and publishes the package. It signs in to npm by
96
+ [trusted publishing](https://docs.npmjs.com/trusted-publishers), so there is no
97
+ token to keep.
package/cli/entourage CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  # entourage: set up and maintain this machine's copy of the software factory.
3
- # Today that means the Herdr mods and layouts under herdr/.
3
+ # It links the Herdr mods and layouts under herdr/ and the agent skills under
4
+ # skills/, and manages projects (groups of repos that show up in Herdr as
5
+ # spaces) and their tasks (a card an agent writes up, then a worktree of each
6
+ # repo on one branch, each shown as a tab in the project's space).
4
7
  set -euo pipefail
5
8
 
6
9
  usage() {
@@ -10,10 +13,32 @@ entourage: set up and maintain this machine from the entourage repo
10
13
  Usage:
11
14
  entourage install first-time setup: link everything into the tools on this machine
12
15
  entourage update [--no-pull] get the latest entourage, link anything new, drop stale links, refresh Herdr
13
- entourage status show what is linked and what is not
16
+ entourage status show what is linked and what is not, and check your projects
17
+ entourage project new <name> make a project from the template
18
+ entourage project add <name> <path> add a repo that is already on this machine
19
+ entourage project open <name> show the project as a Herdr space
20
+ entourage project ls list projects and their repos
21
+ entourage task new <project> <card> write a card up: an agent defines, plans and breaks it down
22
+ entourage task start <project> <branch> start the work: a worktree per repo, opened as a tab
14
23
  entourage help
15
24
 
25
+ A project groups repos that belong together, with a PROJECT.md saying what
26
+ each repo is for. A repo can be in several projects.
27
+
28
+ A task is one piece of work in a project, usually a Linear card.
29
+ `task new` takes the card's ID, like ABC-122. It opens a tab in the project's
30
+ Herdr space and starts an agent there, which writes the card up with the
31
+ sdlc-define, sdlc-plan and sdlc-breakdown skills and asks you to approve it.
32
+ `task start` takes a branch, <type>/<description>, like
33
+ feat/abc-122-short-title (https://conventionalbranch.org). It makes a folder
34
+ in the project's tasks/ folder with a worktree of each repo on that branch,
35
+ and opens a tab for it.
36
+
16
37
  Herdr's folder is ~/.config/herdr-app (HERDR_APP_HOME picks another).
38
+ Skills are linked into ~/.claude/skills (CLAUDE_CONFIG_DIR picks another
39
+ ~/.claude). The agent is claude (ENTOURAGE_AGENT picks another command).
40
+ Your projects are in ~/.config/entourage/projects (ENTOURAGE_HOME picks
41
+ another ~/.config/entourage).
17
42
  EOF
18
43
  }
19
44
 
@@ -30,198 +55,38 @@ done
30
55
  REPO=$(cd -P "$(dirname "$self")/.." && pwd)
31
56
 
32
57
  APP_HOME=${HERDR_APP_HOME:-$HOME/.config/herdr-app}
58
+ # Where Claude Code looks for a person's own skills.
59
+ SKILLS_HOME=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills
33
60
  BIN_DIR=$HOME/.local/bin
34
61
  HERDR_INSTALL='curl -fsSL https://releases.herdr.dev/app/install.sh | sh'
35
62
  # What `update` reinstalls when entourage came from npm rather than a git clone.
36
63
  NPM_SPEC=${ENTOURAGE_NPM_SPEC:-@johngaynor/entourage}
37
64
 
38
- # A git clone updates with `git pull`; an npm install updates through npm.
39
- is_clone() { [ -e "$REPO/.git" ]; }
40
-
41
- say() { printf '%s\n' "$*"; }
42
- die() { printf 'entourage: %s\n' "$*" >&2; exit 1; }
43
-
44
- herdr_app() {
45
- if command -v herdr-app >/dev/null 2>&1; then herdr-app "$@"
46
- elif [ -x "$BIN_DIR/herdr-app" ]; then "$BIN_DIR/herdr-app" "$@"
47
- else return 127
48
- fi
49
- }
50
-
51
- have_herdr() { command -v herdr-app >/dev/null 2>&1 || [ -x "$BIN_DIR/herdr-app" ]; }
52
-
53
- # --- linking ----------------------------------------------------------------
54
-
55
- # Every (source, destination) pair this repo wants linked, one per line,
56
- # tab-separated.
57
- wanted() {
58
- local m l
59
- for m in "$REPO"/herdr/mods/*/; do
60
- [ -d "$m" ] || continue
61
- m=${m%/}
62
- printf '%s\t%s\n' "$m" "$APP_HOME/mods/${m##*/}"
63
- done
64
- for l in "$REPO"/herdr/layouts/*.json; do
65
- [ -f "$l" ] || continue
66
- printf '%s\t%s\n' "$l" "$APP_HOME/layouts/${l##*/}"
67
- done
68
- }
69
-
70
- # linked | missing | elsewhere (a link to somewhere else) | blocked (a real file)
71
- state_of() {
72
- local src=$1 dst=$2
73
- if [ -L "$dst" ]; then
74
- [ "$(readlink "$dst")" = "$src" ] && echo linked || echo elsewhere
75
- elif [ -e "$dst" ]; then echo blocked
76
- else echo missing
77
- fi
78
- }
79
-
80
- label() { local dst=$1; say "${dst#"$APP_HOME"/}"; }
81
-
82
- # Link what is missing. Never touches a real file or someone else's link.
83
- link_all() {
84
- local src dst added=0 skipped=0
85
- mkdir -p "$APP_HOME/mods" "$APP_HOME/layouts"
86
- while IFS=$'\t' read -r src dst; do
87
- case $(state_of "$src" "$dst") in
88
- linked) ;;
89
- missing) ln -s "$src" "$dst"; say " linked $(label "$dst")"; added=$((added + 1)) ;;
90
- elsewhere) say " skipped $(label "$dst") (already a link to $(readlink "$dst"))"; skipped=$((skipped + 1)) ;;
91
- blocked) say " skipped $(label "$dst") (a real file is in the way; move it aside to use ours)"; skipped=$((skipped + 1)) ;;
92
- esac
93
- done < <(wanted)
94
- [ "$added" -gt 0 ] || say " nothing new to link"
95
- CHANGED=$((CHANGED + added))
96
- SKIPPED=$skipped
97
- }
98
-
99
- # Remove links that point into this repo at something that no longer exists
100
- # (a mod or layout that was deleted or renamed upstream).
101
- prune() {
102
- local dst target
103
- for dst in "$APP_HOME"/mods/* "$APP_HOME"/layouts/*; do
104
- [ -L "$dst" ] || continue
105
- target=$(readlink "$dst")
106
- case $target in "$REPO"/herdr/*) ;; *) continue ;; esac
107
- if [ ! -e "$target" ]; then
108
- rm "$dst"; say " removed $(label "$dst") (no longer in the repo)"
109
- CHANGED=$((CHANGED + 1))
110
- fi
111
- done
112
- }
113
-
114
- # Herdr does not notice edits made through a link. Switching to a shipped
115
- # layout and back makes it re-read our layouts and mods.
116
- refresh_herdr() {
117
- local current
118
- current=$(herdr_app status 2>/dev/null | sed -n 's/.*"layout": *"\([^"]*\)".*/\1/p' | head -n 1) || true
119
- if [ -z "$current" ]; then
120
- say " Herdr is not running; it will pick everything up when it starts"
121
- return 0
122
- fi
123
- local other=main
124
- [ "$current" = main ] && other=terminals
125
- herdr_app do layout.switch "{\"name\":\"$other\"}" >/dev/null 2>&1 || true
126
- if herdr_app do layout.switch "{\"name\":\"$current\"}" >/dev/null 2>&1; then
127
- say " refreshed Herdr (layout: $current)"
128
- else
129
- say " could not switch Herdr back to '$current'; pick it from the Layout dropdown or press ctrl-shift-l"
130
- fi
131
- }
132
-
133
- require_herdr() {
134
- have_herdr || die "Herdr is not installed. Install it, open it once, then run this again:
135
- $HERDR_INSTALL"
136
- [ -d "$APP_HOME" ] || die "$APP_HOME does not exist yet. Open Herdr once so it creates its folder, then run this again."
137
- }
138
-
139
- # --- commands ---------------------------------------------------------------
140
-
141
- cmd_install() {
142
- require_herdr
143
- CHANGED=0 SKIPPED=0
144
- say "Linking mods and layouts into $APP_HOME"
145
- link_all
146
-
147
- # npm already put the command on PATH; a clone has to do it itself.
148
- if is_clone; then
149
- say "Putting entourage on your PATH"
150
- mkdir -p "$BIN_DIR"
151
- local me=$REPO/cli/entourage dst=$BIN_DIR/entourage
152
- case $(state_of "$me" "$dst") in
153
- linked) say " already at $dst" ;;
154
- missing) ln -s "$me" "$dst"; say " linked $dst" ;;
155
- *) say " skipped $dst (something else is already there)" ;;
156
- esac
157
- case ":$PATH:" in
158
- *":$BIN_DIR:"*) ;;
159
- *) say " note: $BIN_DIR is not on your PATH; add it to run 'entourage' from anywhere" ;;
160
- esac
161
- fi
162
-
163
- say "Refreshing Herdr"
164
- refresh_herdr
165
- say "Done. Pick a layout from the Layout dropdown, or press ctrl-shift-l."
166
- }
167
-
168
- cmd_update() {
169
- local pull=1
170
- case ${1:-} in
171
- --no-pull) pull=0 ;;
172
- '') ;;
173
- *) die "unknown option for update: $1" ;;
174
- esac
175
- require_herdr
176
- CHANGED=0 SKIPPED=0
177
- local before=none after=none
178
- if [ "$pull" = 1 ] && ! is_clone; then
179
- # Installed by npm: reinstall, then hand over to the new copy to relink.
180
- command -v npm >/dev/null 2>&1 || die "npm is needed to update this install, and it is not on your PATH."
181
- say "Updating entourage with npm ($NPM_SPEC)"
182
- npm install -g "$NPM_SPEC" || die "npm install failed; nothing was changed in Herdr."
183
- exec entourage update --no-pull
184
- fi
185
- if is_clone; then before=$(git -C "$REPO" rev-parse HEAD 2>/dev/null || echo none); fi
186
- if [ "$pull" = 1 ]; then
187
- say "Pulling $REPO"
188
- git -C "$REPO" pull --ff-only || die "git pull failed; fix that in $REPO and run update again."
189
- fi
190
- if is_clone; then after=$(git -C "$REPO" rev-parse HEAD 2>/dev/null || echo none); fi
191
-
192
- say "Linking mods and layouts into $APP_HOME"
193
- link_all
194
- prune
195
-
196
- say "Refreshing Herdr"
197
- if [ "$before" != "$after" ] || [ "$CHANGED" -gt 0 ] || [ "$pull" = 0 ]; then
198
- refresh_herdr
199
- else
200
- say " nothing changed"
201
- fi
202
- }
203
-
204
- cmd_status() {
205
- say "Repo: $REPO"
206
- say "Herdr: $APP_HOME"
207
- have_herdr || say " Herdr is not installed ($HERDR_INSTALL)"
208
- local src dst s problems=0
209
- while IFS=$'\t' read -r src dst; do
210
- s=$(state_of "$src" "$dst")
211
- [ "$s" = linked ] || problems=$((problems + 1))
212
- printf ' %-10s %s\n' "$s" "${dst#"$APP_HOME"/}"
213
- done < <(wanted)
214
- if [ "$problems" -gt 0 ]; then
215
- say "$problems not linked. Run: entourage update"
216
- return 1
217
- fi
218
- say "Everything is linked."
219
- }
65
+ # The user's own projects. They live outside the repo so that they are never
66
+ # published and an npm reinstall does not delete them.
67
+ ENT_HOME=${ENTOURAGE_HOME:-$HOME/.config/entourage}
68
+ PROJECTS=$ENT_HOME/projects
69
+ TEMPLATE=$REPO/herdr/projects/template
70
+ # A PROJECT.md that still has this line has not been filled in.
71
+ TEMPLATE_MARK='<!-- entourage:template -->'
72
+
73
+ # --- the rest of the CLI ----------------------------------------------------
74
+
75
+ # Sourced, so every file shares the settings above and each other's functions.
76
+ LIB=$REPO/cli/lib
77
+ for part in common links project task commands; do
78
+ [ -f "$LIB/$part.sh" ] ||
79
+ { printf 'entourage: %s is missing; reinstall entourage\n' "$LIB/$part.sh" >&2; exit 1; }
80
+ # shellcheck source=/dev/null
81
+ . "$LIB/$part.sh"
82
+ done
220
83
 
221
84
  case ${1:-help} in
222
85
  install) shift; cmd_install "$@" ;;
223
86
  update) shift; cmd_update "$@" ;;
224
87
  status) shift; cmd_status "$@" ;;
88
+ project) shift; cmd_project "$@" ;;
89
+ task) shift; cmd_task "$@" ;;
225
90
  help | -h | --help) usage ;;
226
91
  *) usage >&2; exit 2 ;;
227
92
  esac
@@ -0,0 +1,86 @@
1
+ # The top-level commands: install, update, status. Sourced by cli/entourage.
2
+
3
+ cmd_install() {
4
+ require_herdr
5
+ CHANGED=0 SKIPPED=0
6
+ say "Linking mods and layouts into $APP_HOME, and skills into $SKILLS_HOME"
7
+ link_all
8
+
9
+ # npm already put the command on PATH; a clone has to do it itself.
10
+ if is_clone; then
11
+ say "Putting entourage on your PATH"
12
+ mkdir -p "$BIN_DIR"
13
+ local me=$REPO/cli/entourage dst=$BIN_DIR/entourage
14
+ case $(state_of "$me" "$dst") in
15
+ linked) say " already at $dst" ;;
16
+ missing) ln -s "$me" "$dst"; say " linked $dst" ;;
17
+ *) say " skipped $dst (something else is already there)" ;;
18
+ esac
19
+ case ":$PATH:" in
20
+ *":$BIN_DIR:"*) ;;
21
+ *) say " note: $BIN_DIR is not on your PATH; add it to run 'entourage' from anywhere" ;;
22
+ esac
23
+ fi
24
+
25
+ say "Refreshing Herdr"
26
+ refresh_herdr
27
+ say "Done. Pick a layout from the Layout dropdown, or press ctrl-shift-l."
28
+ }
29
+
30
+ cmd_update() {
31
+ local pull=1
32
+ case ${1:-} in
33
+ --no-pull) pull=0 ;;
34
+ '') ;;
35
+ *) die "unknown option for update: $1" ;;
36
+ esac
37
+ require_herdr
38
+ CHANGED=0 SKIPPED=0
39
+ local before=none after=none
40
+ if [ "$pull" = 1 ] && ! is_clone; then
41
+ # Installed by npm: reinstall, then hand over to the new copy to relink.
42
+ command -v npm >/dev/null 2>&1 || die "npm is needed to update this install, and it is not on your PATH."
43
+ say "Updating entourage with npm ($NPM_SPEC)"
44
+ npm install -g "$NPM_SPEC" || die "npm install failed; nothing was changed in Herdr."
45
+ exec entourage update --no-pull
46
+ fi
47
+ if is_clone; then before=$(git -C "$REPO" rev-parse HEAD 2>/dev/null || echo none); fi
48
+ if [ "$pull" = 1 ]; then
49
+ say "Pulling $REPO"
50
+ git -C "$REPO" pull --ff-only || die "git pull failed; fix that in $REPO and run update again."
51
+ fi
52
+ if is_clone; then after=$(git -C "$REPO" rev-parse HEAD 2>/dev/null || echo none); fi
53
+
54
+ say "Linking mods and layouts into $APP_HOME, and skills into $SKILLS_HOME"
55
+ link_all
56
+ prune
57
+
58
+ say "Refreshing Herdr"
59
+ if [ "$before" != "$after" ] || [ "$CHANGED" -gt 0 ] || [ "$pull" = 0 ]; then
60
+ refresh_herdr
61
+ else
62
+ say " nothing changed"
63
+ fi
64
+ }
65
+
66
+ cmd_status() {
67
+ say "Repo: $REPO"
68
+ say "Herdr: $APP_HOME"
69
+ say "Skills: $SKILLS_HOME"
70
+ have_herdr || say " Herdr is not installed ($HERDR_INSTALL)"
71
+ local src dst s problems=0
72
+ while IFS=$'\t' read -r src dst; do
73
+ s=$(state_of "$src" "$dst")
74
+ [ "$s" = linked ] || problems=$((problems + 1))
75
+ printf ' %-10s %s\n' "$s" "$(label "$dst")"
76
+ done < <(wanted)
77
+ [ "$problems" = 0 ] || say "$problems not linked. Run: entourage update"
78
+ say "Projects: $PROJECTS"
79
+ local project_problems=0
80
+ check_projects || project_problems=$?
81
+ if [ "$problems" -gt 0 ] || [ "$project_problems" -gt 0 ]; then
82
+ [ "$project_problems" = 0 ] || say "$project_problems project problem(s)."
83
+ return 1
84
+ fi
85
+ say "Everything is in order."
86
+ }
@@ -0,0 +1,33 @@
1
+ # Helpers every part of the CLI uses. Sourced by cli/entourage.
2
+
3
+ # A git clone updates with `git pull`; an npm install updates through npm.
4
+ is_clone() { [ -e "$REPO/.git" ]; }
5
+
6
+ say() { printf '%s\n' "$*"; }
7
+ die() { printf 'entourage: %s\n' "$*" >&2; exit 1; }
8
+
9
+ herdr_app() {
10
+ if command -v herdr-app >/dev/null 2>&1; then herdr-app "$@"
11
+ elif [ -x "$BIN_DIR/herdr-app" ]; then "$BIN_DIR/herdr-app" "$@"
12
+ else return 127
13
+ fi
14
+ }
15
+
16
+ have_herdr() { command -v herdr-app >/dev/null 2>&1 || [ -x "$BIN_DIR/herdr-app" ]; }
17
+
18
+ # Herdr answers `status` with the layout it shows only while its window is open.
19
+ herdr_running() { herdr_app status 2>/dev/null | grep -q '"layout"'; }
20
+
21
+ require_herdr() {
22
+ have_herdr || die "Herdr is not installed. Install it, open it once, then run this again:
23
+ $HERDR_INSTALL"
24
+ [ -d "$APP_HOME" ] || die "$APP_HOME does not exist yet. Open Herdr once so it creates its folder, then run this again."
25
+ }
26
+
27
+ # Print a string as the inside of a JSON string. sed and awk do the work so
28
+ # that the result does not depend on the bash version's quoting rules.
29
+ json_str() {
30
+ printf '%s' "$1" | tr '\t\r' ' ' |
31
+ sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' |
32
+ awk 'BEGIN { ORS = "" } NR > 1 { print "\\n" } { print }'
33
+ }
@@ -0,0 +1,93 @@
1
+ # Linking mods and layouts into Herdr, and skills into Claude Code. Sourced by
2
+ # cli/entourage.
3
+
4
+ # Every (source, destination) pair this repo wants linked, one per line,
5
+ # tab-separated.
6
+ wanted() {
7
+ local m l s
8
+ for m in "$REPO"/herdr/mods/*/; do
9
+ [ -d "$m" ] || continue
10
+ m=${m%/}
11
+ printf '%s\t%s\n' "$m" "$APP_HOME/mods/${m##*/}"
12
+ done
13
+ for l in "$REPO"/herdr/layouts/*.json; do
14
+ [ -f "$l" ] || continue
15
+ printf '%s\t%s\n' "$l" "$APP_HOME/layouts/${l##*/}"
16
+ done
17
+ for s in "$REPO"/skills/*/; do
18
+ [ -f "$s/SKILL.md" ] || continue
19
+ s=${s%/}
20
+ printf '%s\t%s\n' "$s" "$SKILLS_HOME/${s##*/}"
21
+ done
22
+ }
23
+
24
+ # linked | missing | elsewhere (a link to somewhere else) | blocked (a real file)
25
+ state_of() {
26
+ local src=$1 dst=$2
27
+ if [ -L "$dst" ]; then
28
+ [ "$(readlink "$dst")" = "$src" ] && echo linked || echo elsewhere
29
+ elif [ -e "$dst" ]; then echo blocked
30
+ else echo missing
31
+ fi
32
+ }
33
+
34
+ # A short name for a destination: mods/cpu, layouts/default.json, skills/sdlc-plan.
35
+ label() {
36
+ local dst=$1
37
+ case $dst in
38
+ "$SKILLS_HOME"/*) say "skills/${dst#"$SKILLS_HOME"/}" ;;
39
+ *) say "${dst#"$APP_HOME"/}" ;;
40
+ esac
41
+ }
42
+
43
+ # Link what is missing. Never touches a real file or someone else's link.
44
+ link_all() {
45
+ local src dst added=0 skipped=0
46
+ mkdir -p "$APP_HOME/mods" "$APP_HOME/layouts"
47
+ [ ! -d "$REPO/skills" ] || mkdir -p "$SKILLS_HOME"
48
+ while IFS=$'\t' read -r src dst; do
49
+ case $(state_of "$src" "$dst") in
50
+ linked) ;;
51
+ missing) ln -s "$src" "$dst"; say " linked $(label "$dst")"; added=$((added + 1)) ;;
52
+ elsewhere) say " skipped $(label "$dst") (already a link to $(readlink "$dst"))"; skipped=$((skipped + 1)) ;;
53
+ blocked) say " skipped $(label "$dst") (a real file is in the way; move it aside to use ours)"; skipped=$((skipped + 1)) ;;
54
+ esac
55
+ done < <(wanted)
56
+ [ "$added" -gt 0 ] || say " nothing new to link"
57
+ CHANGED=$((CHANGED + added))
58
+ SKIPPED=$skipped
59
+ }
60
+
61
+ # Remove links that point into this repo at something that no longer exists
62
+ # (a mod, layout or skill that was deleted or renamed upstream).
63
+ prune() {
64
+ local dst target
65
+ for dst in "$APP_HOME"/mods/* "$APP_HOME"/layouts/* "$SKILLS_HOME"/*; do
66
+ [ -L "$dst" ] || continue
67
+ target=$(readlink "$dst")
68
+ case $target in "$REPO"/herdr/* | "$REPO"/skills/*) ;; *) continue ;; esac
69
+ if [ ! -e "$target" ]; then
70
+ rm "$dst"; say " removed $(label "$dst") (no longer in the repo)"
71
+ CHANGED=$((CHANGED + 1))
72
+ fi
73
+ done
74
+ }
75
+
76
+ # Herdr does not notice edits made through a link. Switching to a shipped
77
+ # layout and back makes it re-read our layouts and mods.
78
+ refresh_herdr() {
79
+ local current
80
+ current=$(herdr_app status 2>/dev/null | sed -n 's/.*"layout": *"\([^"]*\)".*/\1/p' | head -n 1) || true
81
+ if [ -z "$current" ]; then
82
+ say " Herdr is not running; it will pick everything up when it starts"
83
+ return 0
84
+ fi
85
+ local other=main
86
+ [ "$current" = main ] && other=terminals
87
+ herdr_app do layout.switch "{\"name\":\"$other\"}" >/dev/null 2>&1 || true
88
+ if herdr_app do layout.switch "{\"name\":\"$current\"}" >/dev/null 2>&1; then
89
+ say " refreshed Herdr (layout: $current)"
90
+ else
91
+ say " could not switch Herdr back to '$current'; pick it from the Layout dropdown or press ctrl-shift-l"
92
+ fi
93
+ }