@johngaynor/entourage 0.2.0 → 0.4.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 CHANGED
@@ -4,7 +4,7 @@ A collection of agent skills for the software development lifecycle (SDLC).
4
4
 
5
5
  ## Status
6
6
 
7
- Early setup. Three skills are in, and none has been run on a real card yet:
7
+ Early setup. Three skills are in, and they have had only a few runs on real cards:
8
8
 
9
9
  | Skill | What it does |
10
10
  |---|---|
@@ -16,10 +16,10 @@ They live in [skills/](skills/). `entourage install` links them into
16
16
  `~/.claude/skills`, so any Claude Code session on the machine can run one by
17
17
  name, such as `/sdlc-define ABC-122`.
18
18
 
19
- Whenever a skill stops, it ends with a handoff block: which step it was, and
20
- whether it is `done`, `needs-human` or `failed`. A `done` block also names the
21
- step that comes next. Whoever is driving, you or `entourage task new`, reads
22
- that block to know what happens next.
19
+ Whenever a skill ends or pauses, it hands off with a block: which step it was,
20
+ and whether it is `done`, `needs-human` or `failed`. A `done` block also names
21
+ the step that comes next. The agent records each block with
22
+ `entourage task handoff`, and `entourage task log` shows them for a card.
23
23
 
24
24
  ## Setting up a machine
25
25
 
@@ -45,14 +45,26 @@ entourage project add my-project ~/Dev/web
45
45
  entourage project open my-project
46
46
  ```
47
47
 
48
+ `project new` also takes the repos after the name, to do the first three
49
+ lines in one: `entourage project new my-project ~/Dev/api ~/Dev/web`.
50
+
51
+ In Herdr, the `+` above the projects list does the same without a terminal:
52
+ choose a repo's folder, name the project, and its space opens.
53
+
48
54
  Your projects live in `~/.config/entourage/projects`, outside this repo, so
49
55
  they are never published and survive updates. See
50
56
  [herdr/README.md](herdr/README.md#projects) for how a project is laid out.
51
57
 
58
+ `project new` also marks the project's folder as trusted in Claude Code's own
59
+ file, `~/.claude.json`, so an agent started there is not stopped by the "do
60
+ you trust this folder?" question. Only a project folder that entourage made
61
+ is marked: never a repo, and not a project folder you linked in from somewhere
62
+ else. This needs `jq`; without it Claude Code asks once.
63
+
52
64
  ## Tasks
53
65
 
54
- A task is one piece of work in a project, usually a Linear card. It has two
55
- commands, used in this order.
66
+ A task is one piece of work in a project, usually a Linear card. You run two
67
+ commands, in this order.
56
68
 
57
69
  `task new` writes the card up. It opens a tab in the project's Herdr space and
58
70
  starts an agent there, which runs the three skills on the card and then asks
@@ -62,6 +74,13 @@ you to approve it:
62
74
  entourage task new my-project ABC-122
63
75
  ```
64
76
 
77
+ As it goes, the agent records how each step ended. `task log` lists that for
78
+ a card, oldest first:
79
+
80
+ ```sh
81
+ entourage task log my-project ABC-122
82
+ ```
83
+
65
84
  `task start` starts the work. It makes a branch and a git worktree of it in
66
85
  every repo of the project, and opens a tab for it:
67
86
 
@@ -95,7 +114,9 @@ the task's tab, so the checkout is ready to work in. See
95
114
  See [herdr/README.md](herdr/README.md#tasks) for the details.
96
115
 
97
116
  To work on entourage itself, clone the repo and run `cli/entourage install`
98
- from the clone instead. Run the CLI's tests with `npm test`.
117
+ from the clone instead. Run the CLI's tests with `npm test`. The cases run
118
+ side by side, one per processor; `ENTOURAGE_TEST_JOBS=1 npm test` runs them
119
+ one at a time.
99
120
 
100
121
  ## Releasing
101
122
 
package/cli/entourage CHANGED
@@ -14,17 +14,22 @@ Usage:
14
14
  entourage install first-time setup: link everything into the tools on this machine
15
15
  entourage update [--no-pull] get the latest entourage, link anything new, drop stale links, refresh Herdr
16
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
17
+ entourage project new <name> [<path>...] make a project from the template, with the repos at those paths
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 [--json] list projects and their repos (--json for programs)
21
21
  entourage task new <project> <card> write a card up: an agent defines, plans and breaks it down
22
22
  entourage task start <project> <branch> [<repo>[:<group>[,<group>...]] ...]
23
23
  start the work: a worktree per repo, opened as a tab
24
+ entourage task handoff <project> <card> record how a step ended: a handoff block on stdin
25
+ entourage task log <project> <card> list a card's hand-offs, oldest first
24
26
  entourage help
25
27
 
26
28
  A project groups repos that belong together, with a PROJECT.md saying what
27
- each repo is for. A repo can be in several projects.
29
+ each repo is for. A repo can be in several projects. `project new` also
30
+ marks the project's folder as trusted in Claude Code's own file
31
+ (~/.claude.json), so an agent started there is not stopped by the trust
32
+ question. It needs jq; without it Claude Code asks once.
28
33
 
29
34
  A task is one piece of work in a project, usually a Linear card.
30
35
  `task new` takes the card's ID, like ABC-122. It opens a tab in the project's
@@ -38,12 +43,18 @@ gets `just setup` run in that tab, so the checkout is ready to work in.
38
43
  Targets after the branch narrow the task: `app` takes only that repo, and
39
44
  `app:athlete` sets it up for its athlete group (`just setup athlete`).
40
45
  Join several groups with a comma: `app:athlete,coach`.
46
+ `task handoff` is run by the agent each time a step ends or pauses. It reads
47
+ a handoff block on stdin (phase, status, next and so on, one per line),
48
+ refuses one that breaks the rules, and records it. `task log` lists what was
49
+ recorded for a card. Run `entourage task handoff <project> <card>` with no
50
+ block to see the rules.
41
51
 
42
52
  Herdr's folder is ~/.config/herdr-app (HERDR_APP_HOME picks another).
43
53
  Skills are linked into ~/.claude/skills (CLAUDE_CONFIG_DIR picks another
44
54
  ~/.claude). The agent is claude (ENTOURAGE_AGENT picks another command).
45
55
  Your projects are in ~/.config/entourage/projects (ENTOURAGE_HOME picks
46
- another ~/.config/entourage).
56
+ another ~/.config/entourage). Hand-offs are recorded beside them, in
57
+ entourage.db, with sqlite3 (ENTOURAGE_SQLITE picks another command).
47
58
  EOF
48
59
  }
49
60
 
@@ -62,6 +73,9 @@ REPO=$(cd -P "$(dirname "$self")/.." && pwd)
62
73
  APP_HOME=${HERDR_APP_HOME:-$HOME/.config/herdr-app}
63
74
  # Where Claude Code looks for a person's own skills.
64
75
  SKILLS_HOME=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills
76
+ # Claude Code's own record for this machine. Among much else it holds the
77
+ # folders Claude Code starts in without asking.
78
+ CLAUDE_STATE=${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json
65
79
  BIN_DIR=$HOME/.local/bin
66
80
  HERDR_INSTALL='curl -fsSL https://releases.herdr.dev/app/install.sh | sh'
67
81
  # What `update` reinstalls when entourage came from npm rather than a git clone.
@@ -79,7 +93,7 @@ TEMPLATE_MARK='<!-- entourage:template -->'
79
93
 
80
94
  # Sourced, so every file shares the settings above and each other's functions.
81
95
  LIB=$REPO/cli/lib
82
- for part in common links recipes project task commands; do
96
+ for part in common links recipes trust project task handoff commands; do
83
97
  [ -f "$LIB/$part.sh" ] ||
84
98
  { printf 'entourage: %s is missing; reinstall entourage\n' "$LIB/$part.sh" >&2; exit 1; }
85
99
  # shellcheck source=/dev/null
@@ -82,6 +82,9 @@ cmd_status() {
82
82
  if ! have_just && [ -n "$(ls -d "$PROJECTS"/*/ 2>/dev/null)" ]; then
83
83
  say " note just is not installed, so tasks start without setup. Install it: https://just.systems"
84
84
  fi
85
+ if ! have_sqlite && [ -n "$(ls -d "$PROJECTS"/*/ 2>/dev/null)" ]; then
86
+ say " note $SQLITE is not installed, so hand-offs are not recorded."
87
+ fi
85
88
  if [ "$problems" -gt 0 ] || [ "$project_problems" -gt 0 ]; then
86
89
  [ "$project_problems" = 0 ] || say "$project_problems project problem(s)."
87
90
  return 1
package/cli/lib/common.sh CHANGED
@@ -38,9 +38,15 @@ require_herdr() {
38
38
  [ -d "$APP_HOME" ] || die "$APP_HOME does not exist yet. Open Herdr once so it creates its folder, then run this again."
39
39
  }
40
40
 
41
- # Print a string as the inside of a JSON string. sed and awk do the work so
42
- # that the result does not depend on the bash version's quoting rules.
41
+ # Print a string as the inside of a JSON string. Most strings have nothing to
42
+ # escape and are printed as they are, with no program started. For the rest,
43
+ # sed and awk do the work so that the result does not depend on the bash
44
+ # version's quoting rules.
43
45
  json_str() {
46
+ case $1 in
47
+ *[\\\"[:cntrl:]]*) ;;
48
+ *) printf '%s' "$1"; return ;;
49
+ esac
44
50
  printf '%s' "$1" | tr '\t\r' ' ' |
45
51
  sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' |
46
52
  awk 'BEGIN { ORS = "" } NR > 1 { print "\\n" } { print }'
@@ -0,0 +1,211 @@
1
+ # Hand-offs: how each step of a task ended, recorded on this machine. Sourced
2
+ # by cli/entourage.
3
+
4
+ # A step of the lifecycle ends with a handoff block: which step it was, how it
5
+ # ended and what comes next. An agent runs `task handoff` with the block on
6
+ # stdin each time a step ends or pauses. The rules for a block are here, once;
7
+ # the skills only say to run the command.
8
+
9
+ # The store: one SQLite file beside the projects, so it is never published and
10
+ # an npm reinstall does not delete it.
11
+ STORE=$ENT_HOME/entourage.db
12
+ # The command that reads and writes it: one word, a command on PATH.
13
+ SQLITE=${ENTOURAGE_SQLITE:-sqlite3}
14
+
15
+ # The lines a block can have, in the order they are printed.
16
+ HANDOFF_KEYS='phase status next summary flags question options reason'
17
+ # The steps a block can name as its phase or as what comes next.
18
+ HANDOFF_STEPS='define plan breakdown setup'
19
+ # A block is a summary. A line longer than this is not one, and a very long
20
+ # line is slow to check and too big to hand to sqlite3 as an argument.
21
+ HANDOFF_LINE_MAX=2000
22
+
23
+ HANDOFF_USAGE="Usage: entourage task handoff <project> <card>, with the block on stdin:
24
+
25
+ entourage task handoff <project> <card> <<'EOF'
26
+ phase: define
27
+ status: done
28
+ next: plan
29
+ summary: One to three sentences on what was done.
30
+ EOF
31
+
32
+ status is done (needs next and summary, may have flags), needs-human (needs
33
+ question and options, may have summary) or failed (needs reason). phase and
34
+ next are one of: $HANDOFF_STEPS. Every value goes on one line."
35
+
36
+ have_sqlite() { command -v "$SQLITE" >/dev/null 2>&1; }
37
+
38
+ # Run one statement against the store.
39
+ # -init /dev/null: a person's own ~/.sqliterc must not change how answers are
40
+ # printed. .timeout: wait for another task's write to finish, not fail at once.
41
+ store() { "$SQLITE" -init /dev/null -batch -cmd '.timeout 5000' "$@" 2>/dev/null; }
42
+
43
+ # Print a value as an SQL string literal, or NULL when it is empty. Doubling
44
+ # the quote is SQLite's only escape, and no value holds a newline, so nothing
45
+ # in a value can end the literal or start a sqlite3 dot-command.
46
+ # LC_ALL=C: sed must not give up on text that is not valid in this locale.
47
+ sql_str() {
48
+ [ -n "$1" ] || { printf 'NULL'; return; }
49
+ printf "'%s'" "$(printf '%s' "$1" | LC_ALL=C sed "s/'/''/g")"
50
+ }
51
+
52
+ # Make the store if this is its first use.
53
+ store_ready() {
54
+ mkdir -p "$ENT_HOME"
55
+ store "$STORE" 'create table if not exists handoffs (
56
+ id integer primary key, at text not null, project text not null,
57
+ card text not null, phase text not null, status text not null,
58
+ next text, summary text, flags text, question text, options text, reason text);'
59
+ }
60
+
61
+ # Record one hand-off, timed now in UTC:
62
+ # store_handoff <project> <card> <phase> <status> <next> <summary> <flags> <question> <options> <reason>
63
+ store_handoff() {
64
+ local at values='' v
65
+ at=$(date -u +%Y-%m-%dT%H:%M:%SZ)
66
+ for v in "$at" "$@"; do values="$values${values:+, }$(sql_str "$v")"; done
67
+ store "$STORE" "insert into handoffs
68
+ (at, project, card, phase, status, next, summary, flags, question, options, reason)
69
+ values ($values);"
70
+ }
71
+
72
+ # Note that a card's write-up has begun, so the first step's length can be
73
+ # read from the store. It never fails a `task new`: it only says when it could
74
+ # not record.
75
+ record_start() {
76
+ if ! have_sqlite; then
77
+ say " note $SQLITE is not installed, so hand-offs are not recorded"
78
+ return 0
79
+ fi
80
+ { store_ready && store_handoff "$1" "$2" new done define '' '' '' '' ''; } ||
81
+ say " note could not record the start in $STORE"
82
+ }
83
+
84
+ # Is $1 one of the words in $2? A value with a space in it never is, so
85
+ # "define plan" does not pass as a step.
86
+ in_list() {
87
+ case $1 in '' | *[[:space:]]*) return 1 ;; esac
88
+ case " $2 " in *" $1 "*) return 0 ;; *) return 1 ;; esac
89
+ }
90
+
91
+ # Is there a project folder with exactly this name? On a Mac the folder demo
92
+ # also answers to Demo, and a hand-off recorded as Demo would never show in
93
+ # demo's log.
94
+ project_named() {
95
+ local d
96
+ for d in "$PROJECTS"/*/; do
97
+ d=${d%/}
98
+ [ "${d##*/}" != "$1" ] || return 0
99
+ done
100
+ return 1
101
+ }
102
+
103
+ # Check a card ID as the task commands take it, and print it in its usual
104
+ # upper-case form.
105
+ handoff_card() {
106
+ local name=$1 card=$2 what=$3
107
+ [ -n "$card" ] || die "which card? Usage: entourage task $what $name <card>, like: entourage task $what $name ABC-122"
108
+ [[ $card =~ $CARD_RE ]] || die "'$card' is not a card ID like ABC-122."
109
+ printf '%s' "$card" | tr '[:lower:]' '[:upper:]'
110
+ }
111
+
112
+ # Read a handoff block on stdin, refuse one that breaks the rules, record it
113
+ # and print it back with its lines in the usual order.
114
+ task_handoff() {
115
+ local name=${1:-} card=${2:-}
116
+ [ -n "$name" ] || die "$HANDOFF_USAGE"
117
+ # Not project_dir: its advice is to make the project, which is not for an
118
+ # agent to do in the middle of a step.
119
+ project_named "$name" ||
120
+ die "there is no entourage project called '$name', so the hand-off was not recorded. Write the block in your message instead."
121
+ card=$(handoff_card "$name" "$card" handoff) || exit 1
122
+ [ "$#" -le 2 ] || die "$HANDOFF_USAGE"
123
+ [ ! -t 0 ] || die "$HANDOFF_USAGE"
124
+
125
+ local phase='' status='' next='' summary='' flags='' question='' options='' reason=''
126
+ local line key value n=0 seen=' '
127
+ local re='^[[:space:]]*([a-z]+):[[:space:]]*(.*)$' blank='^[[:space:]]*$' hint='^<.*>$'
128
+ while IFS= read -r line || [ -n "$line" ]; do
129
+ n=$((n + 1))
130
+ [ "${#line}" -le "$HANDOFF_LINE_MAX" ] ||
131
+ die "line $n of the block is ${#line} characters long. A block is a summary: keep each line under $HANDOFF_LINE_MAX characters."
132
+ line=${line%$'\r'}
133
+ [[ $line =~ $blank ]] && continue
134
+ [[ $line =~ $re ]] ||
135
+ die "line $n of the block is not 'key: value'. Every value goes on one line."
136
+ key=${BASH_REMATCH[1]} value=${BASH_REMATCH[2]}
137
+ # Drop spaces after the value.
138
+ value=${value%"${value##*[![:space:]]}"}
139
+ in_list "$key" "$HANDOFF_KEYS" ||
140
+ die "a handoff block has no '$key:' line. Its lines are: $HANDOFF_KEYS."
141
+ ! in_list "$key" "$seen" || die "the block has '$key:' twice."
142
+ seen="$seen$key "
143
+ [ -n "$value" ] || die "'$key:' is empty. Leave the line out when there is nothing to say."
144
+ case $value in *[[:cntrl:]]*) die "'$key:' has a tab or another control character in it. Use plain text on one line." ;; esac
145
+ ! [[ $value =~ $hint ]] ||
146
+ die "'$key:' still holds a placeholder in angle brackets. Write what happened, or leave the line out."
147
+ printf -v "$key" '%s' "$value"
148
+ done
149
+ [ "$seen" != ' ' ] || die "there is no block on stdin. $HANDOFF_USAGE"
150
+
151
+ [ -n "$phase" ] || die "the block has no 'phase:' line, the step that is handing off."
152
+ in_list "$phase" "$HANDOFF_STEPS" || die "'$phase' is not a step. The steps are: $HANDOFF_STEPS."
153
+ [ -n "$status" ] || die "the block has no 'status:' line. Use done, needs-human or failed."
154
+ local need allow
155
+ case $status in
156
+ done) need='next summary' allow='flags' ;;
157
+ needs-human) need='question options' allow='summary' ;;
158
+ failed) need='reason' allow='' ;;
159
+ *) die "'$status' is not a status. Use done, needs-human or failed." ;;
160
+ esac
161
+ for key in $need; do
162
+ [ -n "${!key}" ] || die "a $status hand-off needs a '$key:' line."
163
+ done
164
+ for key in next summary flags question options reason; do
165
+ [ -z "${!key}" ] || in_list "$key" "$need $allow" ||
166
+ die "a $status hand-off has no '$key:' line. Take it out."
167
+ done
168
+ [ -z "$next" ] || in_list "$next" "$HANDOFF_STEPS" ||
169
+ die "'$next' is not a step that can come next. The steps are: $HANDOFF_STEPS."
170
+
171
+ have_sqlite ||
172
+ die "$SQLITE is not installed, so the hand-off was not recorded. Write the block in your message instead."
173
+ { store_ready && store_handoff "$name" "$card" "$phase" "$status" "$next" "$summary" "$flags" "$question" "$options" "$reason"; } ||
174
+ die "the hand-off was not recorded: could not write to $STORE. Write the block in your message instead."
175
+ for key in $HANDOFF_KEYS; do
176
+ [ -z "${!key}" ] || printf '%s: %s\n' "$key" "${!key}"
177
+ done
178
+ }
179
+
180
+ # List a card's hand-offs, oldest first.
181
+ task_log() {
182
+ local name=${1:-} card=${2:-}
183
+ [ -n "$name" ] || die "usage: entourage task log <project> <card>"
184
+ project_named "$name" || die "there is no entourage project called '$name'. See: entourage project ls"
185
+ card=$(handoff_card "$name" "$card" log) || exit 1
186
+ [ "$#" -le 2 ] || die "usage: entourage task log <project> <card>"
187
+ have_sqlite || die "$SQLITE is not installed, so no hand-offs have been recorded on this machine."
188
+
189
+ # The unit separator: no value can hold it, and unlike a tab it does not let
190
+ # `read` run two empty fields together.
191
+ local sep=$'\x1f' count=0 key found=''
192
+ local at phase status next summary flags question options reason
193
+ if [ -e "$STORE" ]; then
194
+ # A store that cannot be read is an error, not an empty history.
195
+ found=$(store -separator "$sep" "$STORE" "select at, phase, status, coalesce(next, ''),
196
+ coalesce(summary, ''), coalesce(flags, ''), coalesce(question, ''), coalesce(options, ''),
197
+ coalesce(reason, '') from handoffs
198
+ where project = $(sql_str "$name") and card = $(sql_str "$card") order by id;") ||
199
+ die "could not read the hand-offs in $STORE. It may not be entourage's store."
200
+ fi
201
+ while IFS=$sep read -r at phase status next summary flags question options reason; do
202
+ [ -n "$at" ] || continue
203
+ [ "$count" -gt 0 ] || say "$card in '$name'"
204
+ count=$((count + 1))
205
+ printf '%s %-10s %s%s\n' "$at" "$phase" "$status" "${next:+, then $next}"
206
+ for key in summary flags question options reason; do
207
+ [ -z "${!key}" ] || printf ' %s: %s\n' "$key" "${!key}"
208
+ done
209
+ done <<< "$found"
210
+ [ "$count" -gt 0 ] || say "No hand-offs recorded for $card in '$name'."
211
+ }
@@ -17,6 +17,18 @@ project_dir() {
17
17
  (cd -P "$PROJECTS/$name" && pwd)
18
18
  }
19
19
 
20
+ # Mark a project's folder as trusted by Claude Code (see trust.sh), when
21
+ # entourage made it: a folder of its own in $PROJECTS. A project name that is
22
+ # a link leads to a folder someone else made, perhaps a repo, and entourage
23
+ # does not answer for that. Claude Code asks about it itself, once.
24
+ trust_project() {
25
+ local name=$1
26
+ [ ! -L "$PROJECTS/$name" ] || return 0
27
+ # The real path, which is what Claude Code looks up: $PROJECTS may run
28
+ # through a link.
29
+ trust_folder "$(project_dir "$name")"
30
+ }
31
+
20
32
  # Print a project's repo paths, absolute, one per line.
21
33
  project_repos() {
22
34
  local dir=$1 line
@@ -59,40 +71,70 @@ sync_links() {
59
71
  done
60
72
  }
61
73
 
74
+ # Print the real folder of the repo a path names, or stop if it is not one.
75
+ repo_at() {
76
+ local path=$1 abs
77
+ [ -d "$path" ] || die "$path is not a folder"
78
+ abs=$(cd "$path" && pwd -P)
79
+ is_repo "$abs" || die "$abs is not a git repo (the top folder of a clone is needed)"
80
+ printf '%s\n' "$abs"
81
+ }
82
+
83
+ # Add a line for a repo to a project's repos file, with ~/ for the home folder.
84
+ store_repo() {
85
+ local dir=$1 abs=$2
86
+ case $abs in
87
+ "$HOME"/*) abs="~/${abs#"$HOME"/}" ;;
88
+ esac
89
+ printf '%s\n' "$abs" >> "$dir/repos"
90
+ }
91
+
92
+ # With repo paths after the name, the project starts with those repos. The
93
+ # projects mod makes a project this way, in one command.
62
94
  project_new() {
63
- local name=${1:-} dir
95
+ local name=${1:-} dir path abs other
96
+ local -a repos=()
64
97
  valid_name "$name" || die "a project name is lowercase letters, digits and dashes, like: my-project"
65
98
  dir=$PROJECTS/$name
66
99
  [ ! -e "$dir" ] || die "project '$name' already exists at $dir"
67
100
  [ -f "$TEMPLATE/PROJECT.md" ] || die "the project template is missing from $TEMPLATE"
101
+ shift
102
+ # Every repo is checked before anything is made, so that a bad one does not
103
+ # leave a project behind with only some of them.
104
+ for path in "$@"; do
105
+ abs=$(repo_at "$path")
106
+ for other in ${repos[@]+"${repos[@]}"}; do
107
+ [ "$other" != "$abs" ] || die "$abs is listed twice"
108
+ [ "${other##*/}" != "${abs##*/}" ] ||
109
+ die "$other and $abs are both called ${abs##*/}; two repos in a project cannot share a folder name"
110
+ done
111
+ repos+=("$abs")
112
+ done
68
113
  mkdir -p "$dir"
69
114
  sed "s/__NAME__/$name/" "$TEMPLATE/PROJECT.md" > "$dir/PROJECT.md"
70
115
  : > "$dir/repos"
116
+ for abs in ${repos[@]+"${repos[@]}"}; do store_repo "$dir" "$abs"; done
71
117
  sync_links "$dir"
118
+ trust_project "$name"
72
119
  say "Made project '$name' at $dir"
120
+ for abs in ${repos[@]+"${repos[@]}"}; do say " added ${abs##*/}"; done
73
121
  say "Next:"
74
- say " entourage project add $name <path to a repo>"
122
+ [ "${#repos[@]}" -gt 0 ] || say " entourage project add $name <path to a repo>"
75
123
  say " fill in $dir/PROJECT.md"
76
124
  say " entourage project open $name"
77
125
  }
78
126
 
79
127
  project_add() {
80
- local name=${1:-} path=${2:-} dir abs other stored
128
+ local name=${1:-} path=${2:-} dir abs other
81
129
  dir=$(project_dir "$name")
82
130
  [ -n "$path" ] || die "which repo? Usage: entourage project add $name <path>"
83
- [ -d "$path" ] || die "$path is not a folder"
84
- abs=$(cd "$path" && pwd -P)
85
- is_repo "$abs" || die "$abs is not a git repo (the top folder of a clone is needed)"
131
+ abs=$(repo_at "$path")
86
132
  while IFS= read -r other; do
87
133
  [ "$other" != "$abs" ] || die "$abs is already in project '$name'"
88
134
  [ "${other##*/}" != "${abs##*/}" ] ||
89
135
  die "project '$name' already has a repo called ${abs##*/} ($other); two repos in a project cannot share a folder name"
90
136
  done < <(project_repos "$dir")
91
- case $abs in
92
- "$HOME"/*) stored="~/${abs#"$HOME"/}" ;;
93
- *) stored=$abs ;;
94
- esac
95
- printf '%s\n' "$stored" >> "$dir/repos"
137
+ store_repo "$dir" "$abs"
96
138
  sync_links "$dir"
97
139
  say "Added ${abs##*/} to project '$name'"
98
140
  say "Describe what it owns in $dir/PROJECT.md"
@@ -128,8 +170,34 @@ project_open() {
128
170
  show_space "$name" "$dir"
129
171
  }
130
172
 
173
+ # The same list for programs: one line of JSON, each project with its folder
174
+ # (as project_dir prints it) and its repos. The projects mod reads this.
175
+ project_ls_json() {
176
+ local d repo sep='' rsep
177
+ printf '{"projects":['
178
+ for d in "$PROJECTS"/*/; do
179
+ [ -d "$d" ] || continue
180
+ d=${d%/}
181
+ printf '%s{"name":"%s","folder":"%s","repos":[' "$sep" \
182
+ "$(json_str "${d##*/}")" "$(json_str "$(cd -P "$d" && pwd)")"
183
+ rsep=''
184
+ while IFS= read -r repo; do
185
+ printf '%s"%s"' "$rsep" "$(json_str "$repo")"
186
+ rsep=,
187
+ done < <(project_repos "$d")
188
+ printf ']}'
189
+ sep=,
190
+ done
191
+ printf ']}\n'
192
+ }
193
+
131
194
  project_ls() {
132
195
  local d any=0 repo
196
+ case ${1:-} in
197
+ --json) project_ls_json; return ;;
198
+ '') ;;
199
+ *) die "unknown option for project ls: $1" ;;
200
+ esac
133
201
  for d in "$PROJECTS"/*/; do
134
202
  [ -d "$d" ] || continue
135
203
  any=1
@@ -178,7 +246,7 @@ cmd_project() {
178
246
  new) shift; project_new "$@" ;;
179
247
  add) shift; project_add "$@" ;;
180
248
  open) shift; project_open "$@" ;;
181
- ls | list) shift; project_ls ;;
249
+ ls | list) shift; project_ls "$@" ;;
182
250
  *) die "usage: entourage project new|add|open|ls (see: entourage help)" ;;
183
251
  esac
184
252
  }
package/cli/lib/task.sh CHANGED
@@ -1,10 +1,12 @@
1
1
  # Tasks: a card an agent writes up, then a worktree of each repo on one
2
2
  # branch. Sourced by cli/entourage.
3
3
 
4
- # A task is one piece of work in a project, usually a Linear card. It has two
5
- # commands, in the order they are used:
4
+ # A task is one piece of work in a project, usually a Linear card. A person
5
+ # runs two commands, in this order:
6
6
  # task new an agent writes the card up, in a tab in the project's space
7
7
  # task start a worktree of each repo on the card's branch, in a tab of its own
8
+ # The agent runs `task handoff` as each step ends, and `task log` shows what
9
+ # it recorded. Both are in handoff.sh.
8
10
 
9
11
  # A card ID is a team key and a number, like ABC-122.
10
12
  CARD_RE='^[A-Za-z][A-Za-z0-9]*-[0-9]+$'
@@ -40,12 +42,17 @@ task_new() {
40
42
  prompt=$(sed -e "s/{card}/$card/g" -e "s/{project}/$name/g" "$CARD_PROMPT")
41
43
 
42
44
  sync_links "$dir"
45
+ # `project new` does this too. Here it covers a project made before it did,
46
+ # or on a day Claude Code's file could not be written. It comes before the
47
+ # tab, because the agent meets the trust question the moment it starts.
48
+ trust_project "$name"
43
49
  (show_space "$name" "$dir") ||
44
50
  die "could not show the space for '$name', so no agent was started."
45
51
  # No `space` argument: the tab goes in the selected space, which show_space
46
52
  # has just selected or made. argv is the agent and task is its first message.
47
53
  herdr_app do tab.new "{\"name\":\"$card\",\"folder\":\"$(json_str "$dir")\",\"argv\":[\"$(json_str "$AGENT")\"],\"task\":\"$(json_str "$prompt")\"}" >/dev/null 2>&1 ||
48
54
  die "could not open a tab for $card. Is Herdr open?"
55
+ record_start "$name" "$card"
49
56
  say "Started $card in the space for '$name'"
50
57
  say "The agent writes the card up, then asks you to approve it."
51
58
  }
@@ -312,6 +319,8 @@ cmd_task() {
312
319
  case ${1:-} in
313
320
  new) shift; task_new "$@" ;;
314
321
  start) shift; task_start "$@" ;;
315
- *) die "usage: entourage task new <project> <card>, or: entourage task start <project> <branch> [<repo>[:<group>[,<group>...]] ...] (see: entourage help)" ;;
322
+ handoff) shift; task_handoff "$@" ;;
323
+ log) shift; task_log "$@" ;;
324
+ *) die "usage: entourage task new <project> <card>, or: entourage task start <project> <branch> [<repo>[:<group>[,<group>...]] ...], or: entourage task handoff <project> <card>, or: entourage task log <project> <card> (see: entourage help)" ;;
316
325
  esac
317
326
  }
@@ -0,0 +1,70 @@
1
+ # Folders Claude Code starts in without asking. Sourced by cli/entourage.
2
+
3
+ # Claude Code asks "do you trust this folder?" the first time it starts in one,
4
+ # and keeps the answer in its own file, $CLAUDE_STATE, as
5
+ # .projects["<the folder's real path>"].hasTrustDialogAccepted
6
+ # A folder cannot answer for itself. entourage answers for the folders it made
7
+ # itself (a project's folder), so that an agent `task new` starts there is not
8
+ # left waiting on the question. It never answers for a repo.
9
+ #
10
+ # The file is Claude Code's. It holds much more than this, and every running
11
+ # session rewrites it. So this is the only place that writes it, it changes one
12
+ # value, and what it cannot do cleanly it leaves undone and says so.
13
+
14
+ # The jq test for "this folder is trusted". $d is the folder.
15
+ TRUST_TEST='.projects[$d].hasTrustDialogAccepted == true'
16
+
17
+ # Whether a state file ($2) says a folder ($1) is trusted. The answer is read
18
+ # from what jq prints, never from its exit code: jq 1.6 exits zero for an
19
+ # empty file even with -e. One "true" and nothing else is a yes, so a file
20
+ # holding two values where there should be one is a no as well.
21
+ trust_recorded() { [ "$(jq --arg d "$1" "$TRUST_TEST" "$2" 2>/dev/null)" = true ]; }
22
+
23
+ # "may ask": not every case below can tell whether the folder is trusted.
24
+ trust_note() { say " note Claude Code may ask to trust $1: $2"; }
25
+
26
+ # Record a folder as trusted. The folder is a real path, as project_dir prints
27
+ # it, because that is what Claude Code looks up. Always returns 0: a project or
28
+ # a task is never held up by this, so every command here that can fail is
29
+ # guarded.
30
+ trust_folder() {
31
+ local dir=$1 file=$CLAUDE_STATE lock tmp tries=0 ok=0
32
+ lock=$file.lock
33
+ tmp=$file.entourage.$$
34
+ if [ ! -e "$file" ] && [ ! -L "$file" ]; then trust_note "$dir" "there is no $file yet"; return 0; fi
35
+ if ! command -v jq >/dev/null 2>&1; then trust_note "$dir" "jq is not installed"; return 0; fi
36
+ # Reading is harmless, through a link too, so this comes before anything
37
+ # that refuses to write.
38
+ if trust_recorded "$dir" "$file"; then return 0; fi
39
+ # Replacing a link with a plain file would break whatever keeps the real
40
+ # file somewhere else.
41
+ if [ -L "$file" ]; then trust_note "$dir" "$file is a link, so it was left alone"; return 0; fi
42
+
43
+ # Claude Code's own lock: a folder beside the file, held while it writes. It
44
+ # clears a lock that nobody refreshes, so a run killed in here does no
45
+ # lasting harm. A lock someone else holds is waited for, never removed.
46
+ until mkdir "$lock" 2>/dev/null; do
47
+ tries=$((tries + 1))
48
+ if [ "$tries" -ge 10 ]; then trust_note "$dir" "$file is in use, so it was left alone"; return 0; fi
49
+ sleep 0.1 || true
50
+ done
51
+ # The new file is made for its owner's eyes only, as Claude Code makes it.
52
+ # It is checked before it replaces the old one: jq prints nothing for an
53
+ # empty file and still exits zero.
54
+ if (umask 077 && jq --arg d "$dir" \
55
+ 'if type == "object" then .projects[$d].hasTrustDialogAccepted = true else error("not an object") end' \
56
+ "$file" > "$tmp") 2>/dev/null &&
57
+ trust_recorded "$dir" "$tmp" &&
58
+ mv -f "$tmp" "$file" 2>/dev/null; then
59
+ ok=1
60
+ fi
61
+ rm -f "$tmp" 2>/dev/null || true
62
+ rmdir "$lock" 2>/dev/null || true
63
+
64
+ if [ "$ok" = 1 ]; then
65
+ say " trusted $dir (Claude Code will not ask to trust it)"
66
+ else
67
+ trust_note "$dir" "$file could not be updated, so it was left alone"
68
+ fi
69
+ return 0
70
+ }