@johngaynor/entourage 0.4.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
@@ -19,7 +19,9 @@ name, such as `/sdlc-define ABC-122`.
19
19
  Whenever a skill ends or pauses, it hands off with a block: which step it was,
20
20
  and whether it is `done`, `needs-human` or `failed`. A `done` block also names
21
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.
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
 
@@ -75,7 +77,8 @@ entourage task new my-project ABC-122
75
77
  ```
76
78
 
77
79
  As it goes, the agent records how each step ended. `task log` lists that for
78
- a card, oldest first:
80
+ a card, oldest first, with how long each step took and how long a question
81
+ waited for your answer:
79
82
 
80
83
  ```sh
81
84
  entourage task log my-project ABC-122
@@ -132,3 +135,13 @@ Then publish a GitHub release for that tag. The `Publish to npm` workflow runs
132
135
  the tests and publishes the package. It signs in to npm by
133
136
  [trusted publishing](https://docs.npmjs.com/trusted-publishers), so there is no
134
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
@@ -22,7 +22,8 @@ Usage:
22
22
  entourage task start <project> <branch> [<repo>[:<group>[,<group>...]] ...]
23
23
  start the work: a worktree per repo, opened as a tab
24
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
25
+ entourage task log <project> <card> [--json]
26
+ list a card's hand-offs and how long each step took
26
27
  entourage help
27
28
 
28
29
  A project groups repos that belong together, with a PROJECT.md saying what
@@ -43,11 +44,13 @@ gets `just setup` run in that tab, so the checkout is ready to work in.
43
44
  Targets after the branch narrow the task: `app` takes only that repo, and
44
45
  `app:athlete` sets it up for its athlete group (`just setup athlete`).
45
46
  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.
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.
51
54
 
52
55
  Herdr's folder is ~/.config/herdr-app (HERDR_APP_HOME picks another).
53
56
  Skills are linked into ~/.claude/skills (CLAUDE_CONFIG_DIR picks another
@@ -13,7 +13,7 @@ STORE=$ENT_HOME/entourage.db
13
13
  SQLITE=${ENTOURAGE_SQLITE:-sqlite3}
14
14
 
15
15
  # The lines a block can have, in the order they are printed.
16
- HANDOFF_KEYS='phase status next summary flags question options reason'
16
+ HANDOFF_KEYS='phase status next summary flags question options answer reason'
17
17
  # The steps a block can name as its phase or as what comes next.
18
18
  HANDOFF_STEPS='define plan breakdown setup'
19
19
  # A block is a summary. A line longer than this is not one, and a very long
@@ -30,7 +30,8 @@ summary: One to three sentences on what was done.
30
30
  EOF
31
31
 
32
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
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
34
35
  next are one of: $HANDOFF_STEPS. Every value goes on one line."
35
36
 
36
37
  have_sqlite() { command -v "$SQLITE" >/dev/null 2>&1; }
@@ -49,23 +50,35 @@ sql_str() {
49
50
  printf "'%s'" "$(printf '%s' "$1" | LC_ALL=C sed "s/'/''/g")"
50
51
  }
51
52
 
52
- # Make the store if this is its first use.
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.
53
65
  store_ready() {
54
66
  mkdir -p "$ENT_HOME"
55
67
  store "$STORE" 'create table if not exists handoffs (
56
68
  id integer primary key, at text not null, project text not null,
57
69
  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);'
70
+ next text, summary text, flags text, question text, options text,
71
+ answer text, reason text);' && store_upgrade
59
72
  }
60
73
 
61
74
  # Record one hand-off, timed now in UTC:
62
- # store_handoff <project> <card> <phase> <status> <next> <summary> <flags> <question> <options> <reason>
75
+ # store_handoff <project> <card> <phase> <status> <next> <summary> <flags> <question> <options> <answer> <reason>
63
76
  store_handoff() {
64
77
  local at values='' v
65
78
  at=$(date -u +%Y-%m-%dT%H:%M:%SZ)
66
79
  for v in "$at" "$@"; do values="$values${values:+, }$(sql_str "$v")"; done
67
80
  store "$STORE" "insert into handoffs
68
- (at, project, card, phase, status, next, summary, flags, question, options, reason)
81
+ (at, project, card, phase, status, next, summary, flags, question, options, answer, reason)
69
82
  values ($values);"
70
83
  }
71
84
 
@@ -77,7 +90,7 @@ record_start() {
77
90
  say " note $SQLITE is not installed, so hand-offs are not recorded"
78
91
  return 0
79
92
  fi
80
- { store_ready && store_handoff "$1" "$2" new done define '' '' '' '' ''; } ||
93
+ { store_ready && store_handoff "$1" "$2" new done define '' '' '' '' '' ''; } ||
81
94
  say " note could not record the start in $STORE"
82
95
  }
83
96
 
@@ -122,7 +135,7 @@ task_handoff() {
122
135
  [ "$#" -le 2 ] || die "$HANDOFF_USAGE"
123
136
  [ ! -t 0 ] || die "$HANDOFF_USAGE"
124
137
 
125
- local phase='' status='' next='' summary='' flags='' question='' options='' reason=''
138
+ local phase='' status='' next='' summary='' flags='' question='' options='' answer='' reason=''
126
139
  local line key value n=0 seen=' '
127
140
  local re='^[[:space:]]*([a-z]+):[[:space:]]*(.*)$' blank='^[[:space:]]*$' hint='^<.*>$'
128
141
  while IFS= read -r line || [ -n "$line" ]; do
@@ -150,62 +163,174 @@ task_handoff() {
150
163
 
151
164
  [ -n "$phase" ] || die "the block has no 'phase:' line, the step that is handing off."
152
165
  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."
166
+ [ -n "$status" ] || die "the block has no 'status:' line. Use done, needs-human, answered or failed."
154
167
  local need allow
155
168
  case $status in
156
169
  done) need='next summary' allow='flags' ;;
157
170
  needs-human) need='question options' allow='summary' ;;
171
+ answered) need='answer' allow='' ;;
158
172
  failed) need='reason' allow='' ;;
159
- *) die "'$status' is not a status. Use done, needs-human or failed." ;;
173
+ *) die "'$status' is not a status. Use done, needs-human, answered or failed." ;;
160
174
  esac
161
175
  for key in $need; do
162
- [ -n "${!key}" ] || die "a $status hand-off needs a '$key:' line."
176
+ [ -n "${!key}" ] || die "a hand-off with status $status needs a '$key:' line."
163
177
  done
164
- for key in next summary flags question options reason; do
178
+ for key in next summary flags question options answer reason; do
165
179
  [ -z "${!key}" ] || in_list "$key" "$need $allow" ||
166
- die "a $status hand-off has no '$key:' line. Take it out."
180
+ die "a hand-off with status $status has no '$key:' line. Take it out."
167
181
  done
168
182
  [ -z "$next" ] || in_list "$next" "$HANDOFF_STEPS" ||
169
183
  die "'$next' is not a step that can come next. The steps are: $HANDOFF_STEPS."
170
184
 
171
185
  have_sqlite ||
172
186
  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"; } ||
187
+ { store_ready && store_handoff "$name" "$card" "$phase" "$status" "$next" "$summary" "$flags" "$question" "$options" "$answer" "$reason"; } ||
174
188
  die "the hand-off was not recorded: could not write to $STORE. Write the block in your message instead."
175
189
  for key in $HANDOFF_KEYS; do
176
190
  [ -z "${!key}" ] || printf '%s: %s\n' "$key" "${!key}"
177
191
  done
178
192
  }
179
193
 
180
- # List a card's hand-offs, oldest first.
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.
181
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[@]}"}
182
270
  local name=${1:-} card=${2:-}
183
- [ -n "$name" ] || die "usage: entourage task log <project> <card>"
271
+ [ -n "$name" ] || die "$LOG_USAGE"
184
272
  project_named "$name" || die "there is no entourage project called '$name'. See: entourage project ls"
185
273
  card=$(handoff_card "$name" "$card" log) || exit 1
186
- [ "$#" -le 2 ] || die "usage: entourage task log <project> <card>"
274
+ [ "$#" -le 2 ] || die "$LOG_USAGE"
187
275
  have_sqlite || die "$SQLITE is not installed, so no hand-offs have been recorded on this machine."
188
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
+
189
311
  # The unit separator: no value can hold it, and unlike a tab it does not let
190
312
  # `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
313
+ local sep=$'\x1f' count=0 key
314
+ local at phase what took summary flags question options answer reason waiting
193
315
  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;") ||
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;") ||
199
321
  die "could not read the hand-offs in $STORE. It may not be entourage's store."
200
322
  fi
201
- while IFS=$sep read -r at phase status next summary flags question options reason; do
323
+ while IFS=$sep read -r at phase what took summary flags question options answer reason waiting; do
202
324
  [ -n "$at" ] || continue
203
325
  [ "$count" -gt 0 ] || say "$card in '$name'"
204
326
  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
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
207
331
  [ -z "${!key}" ] || printf ' %s: %s\n' "$key" "${!key}"
208
332
  done
333
+ [ -z "$waiting" ] || printf ' %s\n' "$waiting"
209
334
  done <<< "$found"
210
335
  [ "$count" -gt 0 ] || say "No hand-offs recorded for $card in '$name'."
211
336
  }
package/cli/lib/task.sh CHANGED
@@ -321,6 +321,6 @@ cmd_task() {
321
321
  start) shift; task_start "$@" ;;
322
322
  handoff) shift; task_handoff "$@" ;;
323
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)" ;;
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)" ;;
325
325
  esac
326
326
  }
package/herdr/README.md CHANGED
@@ -10,8 +10,9 @@ layouts (whole-window arrangements of mods).
10
10
  | `mods/cpu/` | Live CPU usage with a scrolling history. macOS only (reads `/usr/bin/top`). |
11
11
  | `mods/layout-switch/` | A dropdown that shows the current layout and switches to another. |
12
12
  | `mods/projects/` | Every project in your config, open or not. Click one to show its space; `+` makes a new one. |
13
+ | `mods/steps/` | The steps of the card whose tab is selected: what each did, how long it took, and how long it waited on you. |
13
14
  | `layouts/default.json` | Herdr's own layout, plus the layout dropdown. |
14
- | `layouts/test.json` | `default` with the projects list in place of spaces, plus the CPU mod in the sidebar. |
15
+ | `layouts/test.json` | `default` with the projects list in place of spaces, plus the Steps panel and the CPU mod in the sidebar. |
15
16
  | `projects/template/` | The starting `PROJECT.md` for every new project. |
16
17
 
17
18
  The skills are in [../skills/](../skills/), outside this folder. They are
@@ -184,6 +185,12 @@ entourage task log <project> <card>
184
185
  commands.
185
186
  - **`task new` records the start,** so the time each step took can be read
186
187
  from the hand-offs alone.
188
+ - **It records your answers too.** When you reply to a question, the agent
189
+ records a hand-off with `status: answered` and what you said in a few
190
+ words. `task log` shows how long each step took, and the time a question
191
+ waited on you as a line of its own, counted in no step. A question with no
192
+ answer yet shows how long it has been waiting. A step that followed a
193
+ question with no recorded answer is marked as including the wait.
187
194
  - **They are kept in `~/.config/entourage/entourage.db`,** a SQLite file
188
195
  beside your projects, on this machine only. It needs `sqlite3`, which macOS
189
196
  ships; `ENTOURAGE_SQLITE` picks another command. Without it `task new`
@@ -191,6 +198,13 @@ entourage task log <project> <card>
191
198
  `entourage status` says so.
192
199
  - **The card stays in Linear.** The store records how a step ended, not what
193
200
  was written.
201
+ - **The Steps panel shows it in Herdr.** Select a card's tab, the one `task
202
+ new` opened, and the panel lists that card's steps: the time of day, what
203
+ the step did, how long it took, and its summary. A wait on you stands out,
204
+ and so does a question still waiting. It shows the latest run of a card
205
+ written up more than once. The panel draws what
206
+ `entourage task log <project> <card> --json` prints and works nothing out
207
+ itself, so the two always agree.
194
208
 
195
209
  ### Starting the work
196
210
 
@@ -56,6 +56,17 @@
56
56
  "weight": 1
57
57
  },
58
58
  "min": 90
59
+ },
60
+ {
61
+ "id": "steps",
62
+ "type": "block",
63
+ "content": {
64
+ "mod": "steps"
65
+ },
66
+ "size": {
67
+ "weight": 1
68
+ },
69
+ "min": 90
59
70
  }
60
71
  ]
61
72
  },
@@ -0,0 +1,191 @@
1
+ // The steps of the card whose tab is selected: what each step of its write-up
2
+ // did, how long it took, and how long it waited on the human.
3
+ //
4
+ // All of that is worked out by `entourage task log <project> <card> --json`.
5
+ // This mod draws the view that command returns and holds no rules about
6
+ // hand-offs: every label and every length of time arrives as text.
7
+ import { View, div } from "gpui-kit";
8
+ import { v_flex, h_flex } from "gpui-base";
9
+ import { exec, spaces, theme, layout, window, checking, appHome } from "herdr";
10
+
11
+ const LOOK_MS = 2000; // how often to see whether another card is selected
12
+ const REREAD_MS = 6000; // how often to read the selected card's steps again
13
+ const PROJECTS_MS = 60000; // projects change rarely
14
+ const TIMEOUT_MS = 10000;
15
+ // How this mod's own link into the repo that ships it ends.
16
+ const LINKED_AT = "/herdr/mods/steps";
17
+ // A tab is a card's when it is named as `entourage task new` names it.
18
+ const CARD = /^[A-Za-z][A-Za-z0-9]*-[0-9]+$/;
19
+ const OLD_CLI = "This entourage cannot give a card's steps as JSON. Run: entourage update";
20
+ // A time longer than this goes on a line of its own.
21
+ const SHORT = 14;
22
+
23
+ // `herdr-app check` draws the mod once, with no card selected, which would
24
+ // show one line of text and none of the rows. It is given these to draw, so a
25
+ // mistake in a row fails the check.
26
+ const SAMPLE = {
27
+ run: 1,
28
+ steps: [
29
+ { run: 1, clock: "10:00", kind: "start", label: "started", took: "" },
30
+ { run: 1, clock: "10:00", kind: "step", label: "define done", took: "50s", summary: "A summary.", flags: "A flag." },
31
+ { run: 1, clock: "10:09", kind: "wait", label: "answered", took: "waited 7m 04s", answer: "approve" },
32
+ { run: 1, clock: "10:17", kind: "step", label: "plan done", took: "7m 24s, includes waiting on the human" },
33
+ { run: 1, clock: "10:17", kind: "step", label: "breakdown asked a question", took: "5s", question: "Approve?", waiting: "waiting on the human for 2m 05s" },
34
+ ],
35
+ };
36
+
37
+ function find(node, id) {
38
+ if (node?.id === id) return node;
39
+ for (const child of node?.children ?? []) {
40
+ const found = find(child, id);
41
+ if (found) return found;
42
+ }
43
+ return null;
44
+ }
45
+
46
+ // The sidebar's rail goes by its width, as in Herdr's own lists.
47
+ const narrow = () => (find(layout(), "sidebar")?.size?.px ?? Infinity) < 160;
48
+
49
+ function parse(text) {
50
+ try {
51
+ return JSON.parse(text);
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
56
+
57
+ // What a failed command said, without the name it starts its errors with.
58
+ const said = (r) => (r.stderr || r.stdout).trim().replace(/^entourage: /, "");
59
+
60
+ // What is selected on this computer: the shown space's folder, and the card
61
+ // its shown tab is for, if it is a card's tab.
62
+ function selected() {
63
+ const space = spaces().find((s) => s.active && !s.machine) ?? null;
64
+ const tab = space?.tabs.find((t) => t.active) ?? null;
65
+ const card = tab && CARD.test(tab.name) ? tab.name.toUpperCase() : null;
66
+ return { folder: space?.folder ?? null, card, key: `${space?.folder ?? ""}\n${card ?? ""}` };
67
+ }
68
+
69
+ export default class Steps extends View {
70
+ init(_props, cx) {
71
+ this.cmd = "entourage"; // the one on PATH, until that cannot start
72
+ this.projects = null; // the last listing of projects
73
+ this.projectsAt = 0;
74
+ this.key = null; // what the view on hand was read for
75
+ this.project = null; // the entourage project of the shown space, or null
76
+ this.view = null;
77
+ this.error = null;
78
+ this.busy = false;
79
+ this.readAt = 0;
80
+ if (checking()) return;
81
+ cx.timer.every(LOOK_MS, (cx) => this.look(cx));
82
+ this.look(cx);
83
+ }
84
+
85
+ // Runs the entourage command. One that cannot run is tried again as the
86
+ // copy this mod is linked from: Herdr may have been started without the
87
+ // user's PATH. Everything this mod runs only reads, so twice is safe.
88
+ async entourage(args) {
89
+ try {
90
+ return await exec(this.cmd, args, { timeout: TIMEOUT_MS });
91
+ } catch (e) {
92
+ if (this.cmd !== "entourage") throw e;
93
+ const link = await exec("readlink", [`${appHome()}/mods/steps`]);
94
+ const at = link.stdout.trim();
95
+ if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
96
+ this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/entourage`;
97
+ return exec(this.cmd, args, { timeout: TIMEOUT_MS });
98
+ }
99
+ }
100
+
101
+ // Read again when another card is selected, or the one on hand is stale.
102
+ look(cx) {
103
+ if (this.busy || window()?.visible === false) return;
104
+ const now = selected();
105
+ if (now.key === this.key && Date.now() - this.readAt < REREAD_MS) return;
106
+ this.busy = true;
107
+ cx.spawn(async (cx) => {
108
+ let project = null;
109
+ let view = null;
110
+ let error = null;
111
+ try {
112
+ if (!this.projects || Date.now() - this.projectsAt > PROJECTS_MS) {
113
+ const r = await this.entourage(["project", "ls", "--json"]);
114
+ const list = r.code === 0 ? parse(r.stdout)?.projects : null;
115
+ if (Array.isArray(list)) {
116
+ this.projects = list;
117
+ this.projectsAt = Date.now();
118
+ } else {
119
+ error = r.code === 0 ? OLD_CLI : said(r) || "entourage project ls failed";
120
+ }
121
+ }
122
+ project = (this.projects ?? []).find((p) => p.folder === now.folder)?.name ?? null;
123
+ if (!error && project && now.card) {
124
+ const r = await this.entourage(["task", "log", project, now.card, "--json"]);
125
+ const got = r.code === 0 ? parse(r.stdout) : null;
126
+ if (got && Array.isArray(got.steps)) view = got;
127
+ else error = r.code === 0 ? OLD_CLI : said(r) || "entourage task log failed";
128
+ }
129
+ } catch (e) {
130
+ error = `Could not run entourage: ${e?.message ?? e}`;
131
+ }
132
+ this.key = now.key;
133
+ this.project = project;
134
+ this.view = view;
135
+ this.error = error;
136
+ this.readAt = Date.now();
137
+ this.busy = false;
138
+ cx.notify();
139
+ });
140
+ }
141
+
142
+ // One hand-off. `s` is a step of the view: its clock, label and took are
143
+ // text to show as they are, and its kind says whether it is a wait.
144
+ row(s, i, t) {
145
+ const wait = s.kind === "wait";
146
+ const start = s.kind === "start";
147
+ const took = s.took ?? "";
148
+ const beside = took.length <= SHORT;
149
+ const detail = s.question ?? s.answer ?? s.reason ?? s.summary ?? null;
150
+ const small = (text, color) =>
151
+ div().pl(46).pr(4).text_size(11.5).text_color(color).whitespace_normal().child(text);
152
+ return v_flex().id(`step-${i}`).flex_none().px(8).py(5).gap(2).rounded(8)
153
+ .child(h_flex().gap(8).items_center()
154
+ .child(div().w(38).flex_none().text_size(11.5).text_color(t.dim).child(s.clock ?? ""))
155
+ .child(div().flex_1().min_w(0).truncate()
156
+ .text_color(wait ? t.blocked : start ? t.muted : t.foreground).child(s.label ?? ""))
157
+ .when(beside && took !== "", (el) =>
158
+ el.child(div().flex_none().text_size(11.5).text_color(wait ? t.blocked : t.dim).child(took))))
159
+ .when(!beside, (el) => el.child(small(took, t.dim)))
160
+ .when(Boolean(detail), (el) => el.child(small(detail, t.muted)))
161
+ .when(Boolean(s.flags), (el) => el.child(small(`Flags: ${s.flags}`, t.dim)))
162
+ .when(Boolean(s.waiting), (el) => el.child(small(s.waiting, t.blocked)));
163
+ }
164
+
165
+ render() {
166
+ const t = theme();
167
+ if (narrow()) return v_flex().size_full().bg(t.chrome);
168
+ const sample = checking();
169
+ const now = selected();
170
+ const view = sample ? SAMPLE : this.view;
171
+ const note = (text, color) =>
172
+ div().px(8).py(6).text_size(12).text_color(color).whitespace_normal().child(text);
173
+ const items = [];
174
+ // The latest run only: a card written up twice keeps both in its log.
175
+ const steps = (view?.steps ?? []).filter((s) => s.run === view.run);
176
+ if (sample) steps.forEach((s, i) => items.push(this.row(s, i, t)));
177
+ else if (!now.card) items.push(note("Select a card's tab to see its steps.", t.dim));
178
+ else if (now.key !== this.key) items.push(note("Loading…", t.dim));
179
+ else if (this.error) items.push(note(this.error, t.blocked));
180
+ else if (!this.project) items.push(note("This space is not an entourage project.", t.dim));
181
+ else if (steps.length === 0) items.push(note(`No hand-offs recorded for ${now.card} yet.`, t.dim));
182
+ else steps.forEach((s, i) => items.push(this.row(s, i, t)));
183
+ return v_flex().size_full().min_h(0).bg(t.chrome).text_size(13)
184
+ .child(h_flex().h(31).flex_none().pl(16).pr(14).items_center().justify_between()
185
+ .text_size(11.5).text_color(t.dim)
186
+ .child("Steps")
187
+ .child(div().child(now.card ?? "")))
188
+ .child(v_flex().id("step-list").flex_1().min_h(0).px(8).pb(14)
189
+ .overflow_y_scrollbar().mode("always").children(items));
190
+ }
191
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Steps" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/entourage",
3
- "version": "0.4.0",
3
+ "version": "0.4.1-next.10",
4
4
  "description": "A software factory: agent skills and the Herdr setup to run them, installed with one command.",
5
5
  "bin": {
6
6
  "entourage": "cli/entourage"
@@ -3,7 +3,7 @@ Write up Linear card {card} so that it is ready to build. This session is in the
3
3
  Start with the sdlc-define skill. Each skill ends by recording a hand-off with `entourage task handoff {project} {card}`, as the skill describes. Record each one before you start the next skill, even though you carry straight on: the hand-offs are how I see how each step ended. You are driving this run, so act on the `status` you recorded:
4
4
 
5
5
  - `done`: go straight on to the step in `next`, without waiting for me. `plan` is the sdlc-plan skill and `breakdown` is the sdlc-breakdown skill.
6
- - `needs-human`: wait for my answer, then carry on with the same skill.
6
+ - `needs-human`: wait for my answer. When it comes, record my answer as the skill describes, then carry on with the same skill.
7
7
  - `failed`: stop there. Don't start the next skill.
8
8
 
9
9
  If I ask for a change when I'm approving, sdlc-breakdown tells you which skill makes it. When that skill hands off, go back to sdlc-breakdown, not on to `next`.
@@ -171,6 +171,7 @@ summary: <one to three sentences on what you did>
171
171
  flags: <what the human should know but wasn't asked>
172
172
  question: <one question>
173
173
  options: <the answers you expect, your recommendation first, separated by " | ">
174
+ answer: <what the human said, in a few words>
174
175
  reason: <what went wrong, and what you already tried>
175
176
  EOF
176
177
  ```
@@ -181,12 +182,13 @@ EOF
181
182
  |---|---|---|
182
183
  | `done` | This step's work is on the card and you have read it back | `phase`, `status`, `next`, `summary`, and `flags` if there are any |
183
184
  | `needs-human` | You can't go on without an answer or an approval | `phase`, `status`, `question`, `options`, and `summary` if it helps them answer |
185
+ | `answered` | The human has replied to a `needs-human` hand-off | `phase`, `status`, `answer` |
184
186
  | `failed` | Something is missing or went wrong, and this skill tells you to stop or doesn't cover it | `phase`, `status`, `reason` |
185
187
 
186
188
  - **If the command refuses the block, fix what it names and run it again.** If it can't record at all, because the command is missing, you are not in an entourage project, or it says the hand-off was not recorded, write the block in your message instead and carry on. Don't make a project or install anything to get it to run.
187
189
  - **When you stop for the human, end your message with the block the command printed.** Above it goes only what the human needs and can't read on the card: a section you could not write there, or the summary they approve from.
188
190
  - **Wherever this skill says to ask, tell or stop, use the block.** An ask is `needs-human`. Something to tell goes in `flags`. A stop because something is missing or went wrong is `failed`.
189
- - **`needs-human` is a pause, not an ending.** Wait for the answer, then carry on with this step. The step is over only at `done` or `failed`.
191
+ - **`needs-human` is a pause, not an ending.** Wait for the answer. When it comes, record it before anything else, as a hand-off with `status: answered` and what they said in a few words. That is how the time spent waiting on them is told from your own work. Then carry on with this step. The step is over only at `done` or `failed`.
190
192
  - **Ask one question per block.** If you have two, ask first the one whose answer could change the other. The human can always answer in their own words, so `options` are suggestions.
191
193
  - **After `done`, this step is over.** Record the hand-off before anything else. If another step sent you here to revise this section, go back to that step and ignore `next`. Otherwise go on to the step in `next` only if you were asked to run more than this one step, and if you weren't, stop there.
192
194
  - **After `failed`, change nothing more.** Leave the card as it is for the human.
@@ -131,6 +131,7 @@ summary: <one to three sentences on what you did>
131
131
  flags: <what the human should know but wasn't asked>
132
132
  question: <one question>
133
133
  options: <the answers you expect, your recommendation first, separated by " | ">
134
+ answer: <what the human said, in a few words>
134
135
  reason: <what went wrong, and what you already tried>
135
136
  EOF
136
137
  ```
@@ -141,12 +142,13 @@ EOF
141
142
  |---|---|---|
142
143
  | `done` | This step's work is on the card and you have read it back | `phase`, `status`, `next`, `summary`, and `flags` if there are any |
143
144
  | `needs-human` | You can't go on without an answer or an approval | `phase`, `status`, `question`, `options`, and `summary` if it helps them answer |
145
+ | `answered` | The human has replied to a `needs-human` hand-off | `phase`, `status`, `answer` |
144
146
  | `failed` | Something is missing or went wrong, and this skill tells you to stop or doesn't cover it | `phase`, `status`, `reason` |
145
147
 
146
148
  - **If the command refuses the block, fix what it names and run it again.** If it can't record at all, because the command is missing, you are not in an entourage project, or it says the hand-off was not recorded, write the block in your message instead and carry on. Don't make a project or install anything to get it to run.
147
149
  - **When you stop for the human, end your message with the block the command printed.** Above it goes only what the human needs and can't read on the card: a section you could not write there, or the summary they approve from.
148
150
  - **Wherever this skill says to ask, tell or stop, use the block.** An ask is `needs-human`. Something to tell goes in `flags`. A stop because something is missing or went wrong is `failed`.
149
- - **`needs-human` is a pause, not an ending.** Wait for the answer, then carry on with this step. The step is over only at `done` or `failed`.
151
+ - **`needs-human` is a pause, not an ending.** Wait for the answer. When it comes, record it before anything else, as a hand-off with `status: answered` and what they said in a few words. That is how the time spent waiting on them is told from your own work. Then carry on with this step. The step is over only at `done` or `failed`.
150
152
  - **Ask one question per block.** If you have two, ask first the one whose answer could change the other. The human can always answer in their own words, so `options` are suggestions.
151
153
  - **After `done`, this step is over.** Record the hand-off before anything else. If another step sent you here to revise this section, go back to that step and ignore `next`. Otherwise go on to the step in `next` only if you were asked to run more than this one step, and if you weren't, stop there.
152
154
  - **After `failed`, change nothing more.** Leave the card as it is for the human.
@@ -127,6 +127,7 @@ summary: <one to three sentences on what you did>
127
127
  flags: <what the human should know but wasn't asked>
128
128
  question: <one question>
129
129
  options: <the answers you expect, your recommendation first, separated by " | ">
130
+ answer: <what the human said, in a few words>
130
131
  reason: <what went wrong, and what you already tried>
131
132
  EOF
132
133
  ```
@@ -137,12 +138,13 @@ EOF
137
138
  |---|---|---|
138
139
  | `done` | This step's work is on the card and you have read it back | `phase`, `status`, `next`, `summary`, and `flags` if there are any |
139
140
  | `needs-human` | You can't go on without an answer or an approval | `phase`, `status`, `question`, `options`, and `summary` if it helps them answer |
141
+ | `answered` | The human has replied to a `needs-human` hand-off | `phase`, `status`, `answer` |
140
142
  | `failed` | Something is missing or went wrong, and this skill tells you to stop or doesn't cover it | `phase`, `status`, `reason` |
141
143
 
142
144
  - **If the command refuses the block, fix what it names and run it again.** If it can't record at all, because the command is missing, you are not in an entourage project, or it says the hand-off was not recorded, write the block in your message instead and carry on. Don't make a project or install anything to get it to run.
143
145
  - **When you stop for the human, end your message with the block the command printed.** Above it goes only what the human needs and can't read on the card: a section you could not write there, or the summary they approve from.
144
146
  - **Wherever this skill says to ask, tell or stop, use the block.** An ask is `needs-human`. Something to tell goes in `flags`. A stop because something is missing or went wrong is `failed`.
145
- - **`needs-human` is a pause, not an ending.** Wait for the answer, then carry on with this step. The step is over only at `done` or `failed`.
147
+ - **`needs-human` is a pause, not an ending.** Wait for the answer. When it comes, record it before anything else, as a hand-off with `status: answered` and what they said in a few words. That is how the time spent waiting on them is told from your own work. Then carry on with this step. The step is over only at `done` or `failed`.
146
148
  - **Ask one question per block.** If you have two, ask first the one whose answer could change the other. The human can always answer in their own words, so `options` are suggestions.
147
149
  - **After `done`, this step is over.** Record the hand-off before anything else. If another step sent you here to revise this section, go back to that step and ignore `next`. Otherwise go on to the step in `next` only if you were asked to run more than this one step, and if you weren't, stop there.
148
150
  - **After `failed`, change nothing more.** Leave the card as it is for the human.