@johngaynor/entourage 0.3.0 → 0.4.1-next.10

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,12 @@ 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 your answer when you reply to a question.
23
+ `entourage task log` shows them for a card, with how long each step took, and
24
+ the Steps panel in Herdr shows the same for the card whose tab is selected.
23
25
 
24
26
  ## Setting up a machine
25
27
 
@@ -45,14 +47,26 @@ entourage project add my-project ~/Dev/web
45
47
  entourage project open my-project
46
48
  ```
47
49
 
50
+ `project new` also takes the repos after the name, to do the first three
51
+ lines in one: `entourage project new my-project ~/Dev/api ~/Dev/web`.
52
+
53
+ In Herdr, the `+` above the projects list does the same without a terminal:
54
+ choose a repo's folder, name the project, and its space opens.
55
+
48
56
  Your projects live in `~/.config/entourage/projects`, outside this repo, so
49
57
  they are never published and survive updates. See
50
58
  [herdr/README.md](herdr/README.md#projects) for how a project is laid out.
51
59
 
60
+ `project new` also marks the project's folder as trusted in Claude Code's own
61
+ file, `~/.claude.json`, so an agent started there is not stopped by the "do
62
+ you trust this folder?" question. Only a project folder that entourage made
63
+ is marked: never a repo, and not a project folder you linked in from somewhere
64
+ else. This needs `jq`; without it Claude Code asks once.
65
+
52
66
  ## Tasks
53
67
 
54
- A task is one piece of work in a project, usually a Linear card. It has two
55
- commands, used in this order.
68
+ A task is one piece of work in a project, usually a Linear card. You run two
69
+ commands, in this order.
56
70
 
57
71
  `task new` writes the card up. It opens a tab in the project's Herdr space and
58
72
  starts an agent there, which runs the three skills on the card and then asks
@@ -62,6 +76,14 @@ you to approve it:
62
76
  entourage task new my-project ABC-122
63
77
  ```
64
78
 
79
+ As it goes, the agent records how each step ended. `task log` lists that for
80
+ a card, oldest first, with how long each step took and how long a question
81
+ waited for your answer:
82
+
83
+ ```sh
84
+ entourage task log my-project ABC-122
85
+ ```
86
+
65
87
  `task start` starts the work. It makes a branch and a git worktree of it in
66
88
  every repo of the project, and opens a tab for it:
67
89
 
@@ -95,7 +117,9 @@ the task's tab, so the checkout is ready to work in. See
95
117
  See [herdr/README.md](herdr/README.md#tasks) for the details.
96
118
 
97
119
  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`.
120
+ from the clone instead. Run the CLI's tests with `npm test`. The cases run
121
+ side by side, one per processor; `ENTOURAGE_TEST_JOBS=1 npm test` runs them
122
+ one at a time.
99
123
 
100
124
  ## Releasing
101
125
 
@@ -111,3 +135,13 @@ Then publish a GitHub release for that tag. The `Publish to npm` workflow runs
111
135
  the tests and publishes the package. It signs in to npm by
112
136
  [trusted publishing](https://docs.npmjs.com/trusted-publishers), so there is no
113
137
  token to keep.
138
+
139
+ Every push to `main` is published too, as a merge build under the npm tag
140
+ `next` (`0.4.1-next.3`, for example). `entourage update` does not install
141
+ those. To try one on a machine:
142
+
143
+ ```sh
144
+ ENTOURAGE_NPM_SPEC=@johngaynor/entourage@next entourage update
145
+ ```
146
+
147
+ A plain `entourage update` goes back to the latest release.
package/cli/entourage CHANGED
@@ -14,17 +14,23 @@ 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 [--json] list projects and their repos (--json for programs)
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> [--json]
26
+ list a card's hand-offs and how long each step took
24
27
  entourage help
25
28
 
26
29
  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.
30
+ each repo is for. A repo can be in several projects. `project new` also
31
+ marks the project's folder as trusted in Claude Code's own file
32
+ (~/.claude.json), so an agent started there is not stopped by the trust
33
+ question. It needs jq; without it Claude Code asks once.
28
34
 
29
35
  A task is one piece of work in a project, usually a Linear card.
30
36
  `task new` takes the card's ID, like ABC-122. It opens a tab in the project's
@@ -38,12 +44,20 @@ gets `just setup` run in that tab, so the checkout is ready to work in.
38
44
  Targets after the branch narrow the task: `app` takes only that repo, and
39
45
  `app:athlete` sets it up for its athlete group (`just setup athlete`).
40
46
  Join several groups with a comma: `app:athlete,coach`.
47
+ `task handoff` is run by the agent each time a step ends or pauses, and
48
+ when the human answers a question. It reads a handoff block on stdin (phase,
49
+ status, next and so on, one per line), refuses one that breaks the rules, and
50
+ records it. `task log` lists what was recorded for a card, with how long each
51
+ step took and how long it waited on the human. With --json it prints the
52
+ same view as one line, for programs: the Steps panel in Herdr draws it. Run
53
+ `entourage task handoff <project> <card>` with no block to see the rules.
41
54
 
42
55
  Herdr's folder is ~/.config/herdr-app (HERDR_APP_HOME picks another).
43
56
  Skills are linked into ~/.claude/skills (CLAUDE_CONFIG_DIR picks another
44
57
  ~/.claude). The agent is claude (ENTOURAGE_AGENT picks another command).
45
58
  Your projects are in ~/.config/entourage/projects (ENTOURAGE_HOME picks
46
- another ~/.config/entourage).
59
+ another ~/.config/entourage). Hand-offs are recorded beside them, in
60
+ entourage.db, with sqlite3 (ENTOURAGE_SQLITE picks another command).
47
61
  EOF
48
62
  }
49
63
 
@@ -62,6 +76,9 @@ REPO=$(cd -P "$(dirname "$self")/.." && pwd)
62
76
  APP_HOME=${HERDR_APP_HOME:-$HOME/.config/herdr-app}
63
77
  # Where Claude Code looks for a person's own skills.
64
78
  SKILLS_HOME=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills
79
+ # Claude Code's own record for this machine. Among much else it holds the
80
+ # folders Claude Code starts in without asking.
81
+ CLAUDE_STATE=${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json
65
82
  BIN_DIR=$HOME/.local/bin
66
83
  HERDR_INSTALL='curl -fsSL https://releases.herdr.dev/app/install.sh | sh'
67
84
  # What `update` reinstalls when entourage came from npm rather than a git clone.
@@ -79,7 +96,7 @@ TEMPLATE_MARK='<!-- entourage:template -->'
79
96
 
80
97
  # Sourced, so every file shares the settings above and each other's functions.
81
98
  LIB=$REPO/cli/lib
82
- for part in common links recipes project task commands; do
99
+ for part in common links recipes trust project task handoff commands; do
83
100
  [ -f "$LIB/$part.sh" ] ||
84
101
  { printf 'entourage: %s is missing; reinstall entourage\n' "$LIB/$part.sh" >&2; exit 1; }
85
102
  # 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
@@ -0,0 +1,336 @@
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 answer 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), answered (needs answer: what the
34
+ human replied to a needs-human hand-off) or failed (needs reason). phase and
35
+ next are one of: $HANDOFF_STEPS. Every value goes on one line."
36
+
37
+ have_sqlite() { command -v "$SQLITE" >/dev/null 2>&1; }
38
+
39
+ # Run one statement against the store.
40
+ # -init /dev/null: a person's own ~/.sqliterc must not change how answers are
41
+ # printed. .timeout: wait for another task's write to finish, not fail at once.
42
+ store() { "$SQLITE" -init /dev/null -batch -cmd '.timeout 5000' "$@" 2>/dev/null; }
43
+
44
+ # Print a value as an SQL string literal, or NULL when it is empty. Doubling
45
+ # the quote is SQLite's only escape, and no value holds a newline, so nothing
46
+ # in a value can end the literal or start a sqlite3 dot-command.
47
+ # LC_ALL=C: sed must not give up on text that is not valid in this locale.
48
+ sql_str() {
49
+ [ -n "$1" ] || { printf 'NULL'; return; }
50
+ printf "'%s'" "$(printf '%s' "$1" | LC_ALL=C sed "s/'/''/g")"
51
+ }
52
+
53
+ has_answer_column() { store "$STORE" 'select answer from handoffs limit 0;' >/dev/null; }
54
+
55
+ # A store made before answers were recorded has no column for them. Add it.
56
+ # Two hand-offs can get here at the same moment: one adds the column and the
57
+ # other's attempt fails, so look again before calling that a failure.
58
+ store_upgrade() {
59
+ has_answer_column ||
60
+ store "$STORE" 'alter table handoffs add column answer text;' ||
61
+ has_answer_column
62
+ }
63
+
64
+ # Make the store if this is its first use, and bring an older one up to date.
65
+ store_ready() {
66
+ mkdir -p "$ENT_HOME"
67
+ store "$STORE" 'create table if not exists handoffs (
68
+ id integer primary key, at text not null, project text not null,
69
+ card text not null, phase text not null, status text not null,
70
+ next text, summary text, flags text, question text, options text,
71
+ answer text, reason text);' && store_upgrade
72
+ }
73
+
74
+ # Record one hand-off, timed now in UTC:
75
+ # store_handoff <project> <card> <phase> <status> <next> <summary> <flags> <question> <options> <answer> <reason>
76
+ store_handoff() {
77
+ local at values='' v
78
+ at=$(date -u +%Y-%m-%dT%H:%M:%SZ)
79
+ for v in "$at" "$@"; do values="$values${values:+, }$(sql_str "$v")"; done
80
+ store "$STORE" "insert into handoffs
81
+ (at, project, card, phase, status, next, summary, flags, question, options, answer, reason)
82
+ values ($values);"
83
+ }
84
+
85
+ # Note that a card's write-up has begun, so the first step's length can be
86
+ # read from the store. It never fails a `task new`: it only says when it could
87
+ # not record.
88
+ record_start() {
89
+ if ! have_sqlite; then
90
+ say " note $SQLITE is not installed, so hand-offs are not recorded"
91
+ return 0
92
+ fi
93
+ { store_ready && store_handoff "$1" "$2" new done define '' '' '' '' '' ''; } ||
94
+ say " note could not record the start in $STORE"
95
+ }
96
+
97
+ # Is $1 one of the words in $2? A value with a space in it never is, so
98
+ # "define plan" does not pass as a step.
99
+ in_list() {
100
+ case $1 in '' | *[[:space:]]*) return 1 ;; esac
101
+ case " $2 " in *" $1 "*) return 0 ;; *) return 1 ;; esac
102
+ }
103
+
104
+ # Is there a project folder with exactly this name? On a Mac the folder demo
105
+ # also answers to Demo, and a hand-off recorded as Demo would never show in
106
+ # demo's log.
107
+ project_named() {
108
+ local d
109
+ for d in "$PROJECTS"/*/; do
110
+ d=${d%/}
111
+ [ "${d##*/}" != "$1" ] || return 0
112
+ done
113
+ return 1
114
+ }
115
+
116
+ # Check a card ID as the task commands take it, and print it in its usual
117
+ # upper-case form.
118
+ handoff_card() {
119
+ local name=$1 card=$2 what=$3
120
+ [ -n "$card" ] || die "which card? Usage: entourage task $what $name <card>, like: entourage task $what $name ABC-122"
121
+ [[ $card =~ $CARD_RE ]] || die "'$card' is not a card ID like ABC-122."
122
+ printf '%s' "$card" | tr '[:lower:]' '[:upper:]'
123
+ }
124
+
125
+ # Read a handoff block on stdin, refuse one that breaks the rules, record it
126
+ # and print it back with its lines in the usual order.
127
+ task_handoff() {
128
+ local name=${1:-} card=${2:-}
129
+ [ -n "$name" ] || die "$HANDOFF_USAGE"
130
+ # Not project_dir: its advice is to make the project, which is not for an
131
+ # agent to do in the middle of a step.
132
+ project_named "$name" ||
133
+ die "there is no entourage project called '$name', so the hand-off was not recorded. Write the block in your message instead."
134
+ card=$(handoff_card "$name" "$card" handoff) || exit 1
135
+ [ "$#" -le 2 ] || die "$HANDOFF_USAGE"
136
+ [ ! -t 0 ] || die "$HANDOFF_USAGE"
137
+
138
+ local phase='' status='' next='' summary='' flags='' question='' options='' answer='' reason=''
139
+ local line key value n=0 seen=' '
140
+ local re='^[[:space:]]*([a-z]+):[[:space:]]*(.*)$' blank='^[[:space:]]*$' hint='^<.*>$'
141
+ while IFS= read -r line || [ -n "$line" ]; do
142
+ n=$((n + 1))
143
+ [ "${#line}" -le "$HANDOFF_LINE_MAX" ] ||
144
+ die "line $n of the block is ${#line} characters long. A block is a summary: keep each line under $HANDOFF_LINE_MAX characters."
145
+ line=${line%$'\r'}
146
+ [[ $line =~ $blank ]] && continue
147
+ [[ $line =~ $re ]] ||
148
+ die "line $n of the block is not 'key: value'. Every value goes on one line."
149
+ key=${BASH_REMATCH[1]} value=${BASH_REMATCH[2]}
150
+ # Drop spaces after the value.
151
+ value=${value%"${value##*[![:space:]]}"}
152
+ in_list "$key" "$HANDOFF_KEYS" ||
153
+ die "a handoff block has no '$key:' line. Its lines are: $HANDOFF_KEYS."
154
+ ! in_list "$key" "$seen" || die "the block has '$key:' twice."
155
+ seen="$seen$key "
156
+ [ -n "$value" ] || die "'$key:' is empty. Leave the line out when there is nothing to say."
157
+ case $value in *[[:cntrl:]]*) die "'$key:' has a tab or another control character in it. Use plain text on one line." ;; esac
158
+ ! [[ $value =~ $hint ]] ||
159
+ die "'$key:' still holds a placeholder in angle brackets. Write what happened, or leave the line out."
160
+ printf -v "$key" '%s' "$value"
161
+ done
162
+ [ "$seen" != ' ' ] || die "there is no block on stdin. $HANDOFF_USAGE"
163
+
164
+ [ -n "$phase" ] || die "the block has no 'phase:' line, the step that is handing off."
165
+ in_list "$phase" "$HANDOFF_STEPS" || die "'$phase' is not a step. The steps are: $HANDOFF_STEPS."
166
+ [ -n "$status" ] || die "the block has no 'status:' line. Use done, needs-human, answered or failed."
167
+ local need allow
168
+ case $status in
169
+ done) need='next summary' allow='flags' ;;
170
+ needs-human) need='question options' allow='summary' ;;
171
+ answered) need='answer' allow='' ;;
172
+ failed) need='reason' allow='' ;;
173
+ *) die "'$status' is not a status. Use done, needs-human, answered or failed." ;;
174
+ esac
175
+ for key in $need; do
176
+ [ -n "${!key}" ] || die "a hand-off with status $status needs a '$key:' line."
177
+ done
178
+ for key in next summary flags question options answer reason; do
179
+ [ -z "${!key}" ] || in_list "$key" "$need $allow" ||
180
+ die "a hand-off with status $status has no '$key:' line. Take it out."
181
+ done
182
+ [ -z "$next" ] || in_list "$next" "$HANDOFF_STEPS" ||
183
+ die "'$next' is not a step that can come next. The steps are: $HANDOFF_STEPS."
184
+
185
+ have_sqlite ||
186
+ die "$SQLITE is not installed, so the hand-off was not recorded. Write the block in your message instead."
187
+ { store_ready && store_handoff "$name" "$card" "$phase" "$status" "$next" "$summary" "$flags" "$question" "$options" "$answer" "$reason"; } ||
188
+ die "the hand-off was not recorded: could not write to $STORE. Write the block in your message instead."
189
+ for key in $HANDOFF_KEYS; do
190
+ [ -z "${!key}" ] || printf '%s: %s\n' "$key" "${!key}"
191
+ done
192
+ }
193
+
194
+ # --- the log ----------------------------------------------------------------
195
+
196
+ # One query works out a card's view: each hand-off with its label, how long it
197
+ # took and whether it is a wait. The plain log and the JSON both read it, so
198
+ # they cannot disagree, and a Herdr mod that draws the JSON formats nothing.
199
+ #
200
+ # Nothing about time is stored beyond each row's own. A step's time is from
201
+ # the row before it to its own row. The time from a needs-human row to its
202
+ # answered row is waiting on the human and belongs to no step. A needs-human
203
+ # row with nothing after it is still waiting, measured to now. A `new` row
204
+ # starts a run, so it has no time, however long ago the run before it ended.
205
+
206
+ # SQL for a number of seconds as text: 50s, 1m 44s, 1h 02m.
207
+ sql_took() {
208
+ local s=$1
209
+ printf "case when %s < 60 then %s || 's'
210
+ when %s < 3600 then (%s / 60) || 'm ' || printf('%%02d', %s %% 60) || 's'
211
+ else (%s / 3600) || 'h ' || printf('%%02d', %s %% 3600 / 60) || 'm' end" \
212
+ "$s" "$s" "$s" "$s" "$s" "$s" "$s"
213
+ }
214
+
215
+ # SQL that starts a query on one card's view, as the table `shown`.
216
+ # log_view <project> <card> <answer column, or null in a store without one>
217
+ log_view() {
218
+ printf "with base as (
219
+ select id, at, phase, status, next, summary, flags, question, options,
220
+ %s as answer, reason,
221
+ lag(at) over w as prev_at, lag(status) over w as before, lead(id) over w as after,
222
+ sum(case when phase = 'new' then 1 else 0 end) over w as run
223
+ from handoffs where project = %s and card = %s
224
+ window w as (order by id)),
225
+ timed as (
226
+ select *,
227
+ case when phase = 'new' or prev_at is null then null
228
+ else max(cast(strftime('%%s', at) - strftime('%%s', prev_at) as integer), 0) end as seconds,
229
+ case when after is null and status = 'needs-human'
230
+ then max(cast(strftime('%%s', 'now') - strftime('%%s', at) as integer), 0) end as open_seconds
231
+ from base),
232
+ shown as (
233
+ select *,
234
+ case when phase = 'new' then 'start'
235
+ when status = 'answered' and before = 'needs-human' then 'wait'
236
+ else 'step' end as kind,
237
+ status || case when next is null then '' else ', then ' || next end as what,
238
+ case when phase = 'new' then 'started'
239
+ when status = 'done' then phase || ' done'
240
+ when status = 'needs-human' then phase || ' asked a question'
241
+ when status = 'answered' then 'answered'
242
+ when status = 'failed' then phase || ' failed'
243
+ else phase || ' ' || status end as label,
244
+ case when seconds is null then ''
245
+ when status = 'answered' and before = 'needs-human' then 'waited ' || (%s)
246
+ when before = 'needs-human' then (%s) || ', includes waiting on the human'
247
+ else (%s) end as took,
248
+ case when open_seconds is null then ''
249
+ else 'waiting on the human for ' || (%s) end as waiting
250
+ from timed)" \
251
+ "$3" "$(sql_str "$1")" "$(sql_str "$2")" \
252
+ "$(sql_took seconds)" "$(sql_took seconds)" "$(sql_took seconds)" "$(sql_took open_seconds)"
253
+ }
254
+
255
+ LOG_USAGE='usage: entourage task log <project> <card> [--json]'
256
+
257
+ # List a card's hand-offs, oldest first, with how long each step took. With
258
+ # --json, the same view as one line of JSON.
259
+ task_log() {
260
+ local json=0 a
261
+ local args=()
262
+ for a in "$@"; do
263
+ case $a in
264
+ --json) json=1 ;;
265
+ -*) die "$LOG_USAGE" ;;
266
+ *) args+=("$a") ;;
267
+ esac
268
+ done
269
+ set -- ${args[@]+"${args[@]}"}
270
+ local name=${1:-} card=${2:-}
271
+ [ -n "$name" ] || die "$LOG_USAGE"
272
+ project_named "$name" || die "there is no entourage project called '$name'. See: entourage project ls"
273
+ card=$(handoff_card "$name" "$card" log) || exit 1
274
+ [ "$#" -le 2 ] || die "$LOG_USAGE"
275
+ have_sqlite || die "$SQLITE is not installed, so no hand-offs have been recorded on this machine."
276
+
277
+ # Reading never changes the store. An older one has no answer column, so it
278
+ # is read without one.
279
+ local answer_column=null view found=''
280
+ if [ -e "$STORE" ]; then
281
+ ! has_answer_column || answer_column=answer
282
+ view=$(log_view "$name" "$card" "$answer_column")
283
+ fi
284
+
285
+ if [ "$json" = 1 ]; then
286
+ if [ ! -e "$STORE" ]; then
287
+ printf '{"project":"%s","card":"%s","state":null,"waiting":null,"steps":[]}\n' \
288
+ "$(json_str "$name")" "$(json_str "$card")"
289
+ return
290
+ fi
291
+ # SQLite builds the JSON, so no value is escaped by hand. A store that
292
+ # cannot be read is an error, not an empty history.
293
+ store "$STORE" "$view
294
+ select json_object('project', $(sql_str "$name"), 'card', $(sql_str "$card"),
295
+ 'state', (select case when status = 'needs-human' then 'waiting on the human'
296
+ when phase = 'new' then 'started' else label || substr(what, length(status) + 1) end
297
+ from shown order by id desc limit 1),
298
+ 'waiting', (select nullif(waiting, '') from shown order by id desc limit 1),
299
+ 'run', (select max(run) from shown),
300
+ 'steps', (select json_group_array(json(step)) from (
301
+ select json_object('run', run, 'at', at, 'clock', strftime('%H:%M', at, 'localtime'),
302
+ 'phase', phase, 'status', status, 'next', next, 'kind', kind, 'label', label,
303
+ 'took', took, 'seconds', seconds, 'waiting', nullif(waiting, ''),
304
+ 'summary', summary, 'flags', flags, 'question', question, 'options', options,
305
+ 'answer', answer, 'reason', reason) as step
306
+ from shown order by id)));" ||
307
+ die "could not read the hand-offs in $STORE. It may not be entourage's store."
308
+ return
309
+ fi
310
+
311
+ # The unit separator: no value can hold it, and unlike a tab it does not let
312
+ # `read` run two empty fields together.
313
+ local sep=$'\x1f' count=0 key
314
+ local at phase what took summary flags question options answer reason waiting
315
+ if [ -e "$STORE" ]; then
316
+ found=$(store -separator "$sep" "$STORE" "$view
317
+ select at, phase, what, took, coalesce(summary, ''), coalesce(flags, ''),
318
+ coalesce(question, ''), coalesce(options, ''), coalesce(answer, ''),
319
+ coalesce(reason, ''), waiting
320
+ from shown order by id;") ||
321
+ die "could not read the hand-offs in $STORE. It may not be entourage's store."
322
+ fi
323
+ while IFS=$sep read -r at phase what took summary flags question options answer reason waiting; do
324
+ [ -n "$at" ] || continue
325
+ [ "$count" -gt 0 ] || say "$card in '$name'"
326
+ count=$((count + 1))
327
+ if [ -n "$took" ]; then printf '%s %-10s %-22s %s\n' "$at" "$phase" "$what" "$took"
328
+ else printf '%s %-10s %s\n' "$at" "$phase" "$what"
329
+ fi
330
+ for key in summary flags question options answer reason; do
331
+ [ -z "${!key}" ] || printf ' %s: %s\n' "$key" "${!key}"
332
+ done
333
+ [ -z "$waiting" ] || printf ' %s\n' "$waiting"
334
+ done <<< "$found"
335
+ [ "$count" -gt 0 ] || say "No hand-offs recorded for $card in '$name'."
336
+ }
@@ -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"
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> [--json] (see: entourage help)" ;;
316
325
  esac
317
326
  }