@johngaynor/entourage 0.4.1-next.17 → 0.4.1-next.26
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 +20 -0
- package/cli/entourage +107 -8
- package/cli/lib/handoff.sh +79 -23
- package/cli/lib/linear.sh +270 -0
- package/cli/lib/project.sh +57 -1
- package/cli/lib/task.sh +35 -1
- package/herdr/README.md +106 -4
- package/herdr/mods/steps/main.js +100 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ the step that comes next. The agent records each block with
|
|
|
22
22
|
`entourage task handoff`, and your answer when you reply to a question.
|
|
23
23
|
`entourage task log` shows them for a card, with how long each step took, and
|
|
24
24
|
the Steps panel in Herdr shows the same for the card whose tab is selected.
|
|
25
|
+
With no card, both list the project's cards and where each stands.
|
|
25
26
|
|
|
26
27
|
## Setting up a machine
|
|
27
28
|
|
|
@@ -68,6 +69,18 @@ else. This needs `jq`; without it Claude Code asks once.
|
|
|
68
69
|
A task is one piece of work in a project, usually a Linear card. You run two
|
|
69
70
|
commands, in this order.
|
|
70
71
|
|
|
72
|
+
To see which cards there are first, `task ls` lists the open cards of the
|
|
73
|
+
project's Linear teams, under their statuses:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
entourage linear key # once: save your Linear API key
|
|
77
|
+
entourage project team my-project ABC # once: the team whose cards are ABC-122
|
|
78
|
+
entourage task ls my-project
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
It asks Linear itself, with no agent running. See
|
|
82
|
+
[herdr/README.md](herdr/README.md#seeing-a-projects-cards) for the details.
|
|
83
|
+
|
|
71
84
|
`task new` writes the card up. It opens a tab in the project's Herdr space and
|
|
72
85
|
starts an agent there, which runs the three skills on the card and then asks
|
|
73
86
|
you to approve it:
|
|
@@ -84,6 +97,13 @@ waited for your answer:
|
|
|
84
97
|
entourage task log my-project ABC-122
|
|
85
98
|
```
|
|
86
99
|
|
|
100
|
+
Leave the card out to see every card in the project that has hand-offs,
|
|
101
|
+
newest first, with where each stands, such as waiting on you:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
entourage task log my-project
|
|
105
|
+
```
|
|
106
|
+
|
|
87
107
|
`task start` starts the work. It makes a branch and a git worktree of it in
|
|
88
108
|
every repo of the project, and opens a tab for it:
|
|
89
109
|
|
package/cli/entourage
CHANGED
|
@@ -18,12 +18,16 @@ Usage:
|
|
|
18
18
|
entourage project add <name> <path> add a repo that is already on this machine
|
|
19
19
|
entourage project open <name> show the project as a Herdr space
|
|
20
20
|
entourage project ls [--json] list projects and their repos (--json for programs)
|
|
21
|
+
entourage project team <name> [<team>...] set the Linear teams whose cards are the project's, or print them
|
|
22
|
+
entourage task ls <project> [--json] list the open cards of the project's Linear teams, by status
|
|
21
23
|
entourage task new <project> <card> write a card up: an agent defines, plans and breaks it down
|
|
22
24
|
entourage task start <project> <branch> [<repo>[:<group>[,<group>...]] ...]
|
|
23
25
|
start the work: a worktree per repo, opened as a tab
|
|
24
26
|
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
|
|
27
|
+
entourage task log <project> [<card>] [--json]
|
|
28
|
+
list a card's hand-offs and how long each step took,
|
|
29
|
+
or with no card the cards that have hand-offs and where each stands
|
|
30
|
+
entourage linear key save your Linear API key, so entourage can read Linear
|
|
27
31
|
entourage help
|
|
28
32
|
|
|
29
33
|
A project groups repos that belong together, with a PROJECT.md saying what
|
|
@@ -33,6 +37,14 @@ marks the project's folder as trusted in Claude Code's own file
|
|
|
33
37
|
question. It needs jq; without it Claude Code asks once.
|
|
34
38
|
|
|
35
39
|
A task is one piece of work in a project, usually a Linear card.
|
|
40
|
+
`task ls` lists the cards `task new` can be given: every card of the
|
|
41
|
+
project's Linear teams that is not done, cancelled or a duplicate, under its
|
|
42
|
+
status. It needs two things set once. `linear key` asks for a Linear API key
|
|
43
|
+
and saves it (make one in Linear, under Settings, Account, Security & access,
|
|
44
|
+
Personal API keys; Read permission is enough to list cards). `project team`
|
|
45
|
+
names the project's teams by their keys: ABC for the team whose cards are
|
|
46
|
+
ABC-122. A project can name several teams, and several projects can name the
|
|
47
|
+
same one. Linear is asked with curl and its answer read with jq.
|
|
36
48
|
`task new` takes the card's ID, like ABC-122. It opens a tab in the project's
|
|
37
49
|
Herdr space and starts an agent there, which writes the card up with the
|
|
38
50
|
sdlc-define, sdlc-plan and sdlc-breakdown skills and asks you to approve it.
|
|
@@ -48,8 +60,10 @@ Join several groups with a comma: `app:athlete,coach`.
|
|
|
48
60
|
when the human answers a question. It reads a handoff block on stdin (phase,
|
|
49
61
|
status, next and so on, one per line), refuses one that breaks the rules, and
|
|
50
62
|
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
|
|
52
|
-
|
|
63
|
+
step took and how long it waited on the human. With no card it lists the
|
|
64
|
+
project's cards that have hand-offs, newest first, each with where it stands
|
|
65
|
+
and for how long. With --json it prints the same view as one line, for
|
|
66
|
+
programs: the Steps panel in Herdr draws it. Run
|
|
53
67
|
`entourage task handoff <project> <card>` with no block to see the rules.
|
|
54
68
|
|
|
55
69
|
Herdr's folder is ~/.config/herdr-app (HERDR_APP_HOME picks another).
|
|
@@ -58,6 +72,14 @@ Skills are linked into ~/.claude/skills (CLAUDE_CONFIG_DIR picks another
|
|
|
58
72
|
Your projects are in ~/.config/entourage/projects (ENTOURAGE_HOME picks
|
|
59
73
|
another ~/.config/entourage). Hand-offs are recorded beside them, in
|
|
60
74
|
entourage.db, with sqlite3 (ENTOURAGE_SQLITE picks another command).
|
|
75
|
+
|
|
76
|
+
These variables, and your Linear key as LINEAR_API_KEY, can be exported in
|
|
77
|
+
your shell or written as NAME=value lines in ~/.config/entourage/.env, which
|
|
78
|
+
`linear key` writes for you and only you can read. A variable you export wins
|
|
79
|
+
over its line in the file, unless it is empty; of two lines for a name, the
|
|
80
|
+
last is used. Herdr starts commands without your shell's exports, so what a
|
|
81
|
+
mod's run of entourage needs has to be in the file. ENTOURAGE_HOME is the one
|
|
82
|
+
variable the file cannot set.
|
|
61
83
|
EOF
|
|
62
84
|
}
|
|
63
85
|
|
|
@@ -73,6 +95,85 @@ while [ -L "$self" ]; do
|
|
|
73
95
|
done
|
|
74
96
|
REPO=$(cd -P "$(dirname "$self")/.." && pwd)
|
|
75
97
|
|
|
98
|
+
# The user's own things: their projects, and what entourage keeps for them.
|
|
99
|
+
# They live outside the repo so that they are never published and an npm
|
|
100
|
+
# reinstall does not delete them.
|
|
101
|
+
ENT_HOME=${ENTOURAGE_HOME:-$HOME/.config/entourage}
|
|
102
|
+
|
|
103
|
+
# entourage's own environment: NAME=value lines in this file, for the
|
|
104
|
+
# variables that would otherwise be exported in a shell. Herdr starts a
|
|
105
|
+
# command without a shell's exports, so a variable set only in a shell profile
|
|
106
|
+
# is missing when a mod runs entourage, and the file is where it is found.
|
|
107
|
+
ENV_FILE=$ENT_HOME/.env
|
|
108
|
+
# Whether the Linear key came with the environment, before the file is read.
|
|
109
|
+
KEY_EXPORTED=${LINEAR_API_KEY:+1}
|
|
110
|
+
|
|
111
|
+
# Take entourage's variables from the file. The file is read, never run: a
|
|
112
|
+
# line that is not NAME=value is skipped, and nothing in a value is expanded.
|
|
113
|
+
# What a line may hold:
|
|
114
|
+
# - export before the name, spaces around the =, one pair of quotes around
|
|
115
|
+
# the value, and a # comment after a value with no quotes;
|
|
116
|
+
# - of two lines for a name, the last one;
|
|
117
|
+
# - a variable already in the environment wins over the file, unless it is
|
|
118
|
+
# empty, which counts as not set.
|
|
119
|
+
# Only the variables entourage reads are taken: a line for PATH or anything
|
|
120
|
+
# else is skipped, and so is ENTOURAGE_HOME, which says where this file is.
|
|
121
|
+
# HERDR_APP_HOME and CLAUDE_CONFIG_DIR are exported, so a program entourage
|
|
122
|
+
# starts finds the same folders it does. The Linear key is not: only
|
|
123
|
+
# entourage reads it, and it hands it to curl on stdin.
|
|
124
|
+
load_env() {
|
|
125
|
+
local line name value from_file=' '
|
|
126
|
+
local re='^[[:space:]]*(export[[:space:]]+)?([A-Za-z_][A-Za-z0-9_]*)[[:space:]]*=[[:space:]]*(.*)$'
|
|
127
|
+
[ -f "$ENV_FILE" ] || return 0
|
|
128
|
+
# Stop rather than go on without the file: its settings would be missing,
|
|
129
|
+
# and `linear key` would write it anew with only the key in it.
|
|
130
|
+
[ -r "$ENV_FILE" ] || {
|
|
131
|
+
printf 'entourage: cannot read %s. It should be yours, and readable by you only: check its owner, then run: chmod 600 %s\n' \
|
|
132
|
+
"$ENV_FILE" "$ENV_FILE" >&2
|
|
133
|
+
exit 1
|
|
134
|
+
}
|
|
135
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
136
|
+
line=${line%$'\r'}
|
|
137
|
+
# The mark some editors put at the start of a file.
|
|
138
|
+
line=${line#$'\357\273\277'}
|
|
139
|
+
[[ $line =~ $re ]] || continue
|
|
140
|
+
name=${BASH_REMATCH[2]} value=${BASH_REMATCH[3]}
|
|
141
|
+
case $name in
|
|
142
|
+
ENTOURAGE_HOME) continue ;;
|
|
143
|
+
ENTOURAGE_* | LINEAR_API_KEY | HERDR_APP_HOME | CLAUDE_CONFIG_DIR) ;;
|
|
144
|
+
*) continue ;;
|
|
145
|
+
esac
|
|
146
|
+
# A name the file has set already is set again; one that came with the
|
|
147
|
+
# environment is left as it is.
|
|
148
|
+
case $from_file in
|
|
149
|
+
*" $name "*) ;;
|
|
150
|
+
*) [ -z "${!name:-}" ] || continue ;;
|
|
151
|
+
esac
|
|
152
|
+
from_file="$from_file$name "
|
|
153
|
+
# A # after a space starts a comment, in a value with no quotes.
|
|
154
|
+
case $value in
|
|
155
|
+
\"* | \'*) ;;
|
|
156
|
+
\#*) value= ;;
|
|
157
|
+
*) value=${value%%[[:space:]]#*} ;;
|
|
158
|
+
esac
|
|
159
|
+
# Spaces after the value, then one pair of quotes around it.
|
|
160
|
+
value=${value%"${value##*[![:space:]]}"}
|
|
161
|
+
case $value in
|
|
162
|
+
\"*\") value=${value#\"}; value=${value%\"} ;;
|
|
163
|
+
\'*\') value=${value#\'}; value=${value%\'} ;;
|
|
164
|
+
esac
|
|
165
|
+
if [ "$name" = LINEAR_API_KEY ]; then
|
|
166
|
+
# Set for entourage alone. -n also covers a key that came exported but
|
|
167
|
+
# empty, so that no program entourage starts finds it either way.
|
|
168
|
+
LINEAR_API_KEY=$value
|
|
169
|
+
export -n LINEAR_API_KEY
|
|
170
|
+
else
|
|
171
|
+
export "$name=$value"
|
|
172
|
+
fi
|
|
173
|
+
done < "$ENV_FILE"
|
|
174
|
+
}
|
|
175
|
+
load_env
|
|
176
|
+
|
|
76
177
|
APP_HOME=${HERDR_APP_HOME:-$HOME/.config/herdr-app}
|
|
77
178
|
# Where Claude Code looks for a person's own skills.
|
|
78
179
|
SKILLS_HOME=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills
|
|
@@ -84,9 +185,6 @@ HERDR_INSTALL='curl -fsSL https://releases.herdr.dev/app/install.sh | sh'
|
|
|
84
185
|
# What `update` reinstalls when entourage came from npm rather than a git clone.
|
|
85
186
|
NPM_SPEC=${ENTOURAGE_NPM_SPEC:-@johngaynor/entourage}
|
|
86
187
|
|
|
87
|
-
# The user's own projects. They live outside the repo so that they are never
|
|
88
|
-
# published and an npm reinstall does not delete them.
|
|
89
|
-
ENT_HOME=${ENTOURAGE_HOME:-$HOME/.config/entourage}
|
|
90
188
|
PROJECTS=$ENT_HOME/projects
|
|
91
189
|
TEMPLATE=$REPO/herdr/projects/template
|
|
92
190
|
# A PROJECT.md that still has this line has not been filled in.
|
|
@@ -96,7 +194,7 @@ TEMPLATE_MARK='<!-- entourage:template -->'
|
|
|
96
194
|
|
|
97
195
|
# Sourced, so every file shares the settings above and each other's functions.
|
|
98
196
|
LIB=$REPO/cli/lib
|
|
99
|
-
for part in common links recipes trust project task handoff commands; do
|
|
197
|
+
for part in common links recipes trust project linear task handoff commands; do
|
|
100
198
|
[ -f "$LIB/$part.sh" ] ||
|
|
101
199
|
{ printf 'entourage: %s is missing; reinstall entourage\n' "$LIB/$part.sh" >&2; exit 1; }
|
|
102
200
|
# shellcheck source=/dev/null
|
|
@@ -109,6 +207,7 @@ case ${1:-help} in
|
|
|
109
207
|
status) shift; cmd_status "$@" ;;
|
|
110
208
|
project) shift; cmd_project "$@" ;;
|
|
111
209
|
task) shift; cmd_task "$@" ;;
|
|
210
|
+
linear) shift; cmd_linear "$@" ;;
|
|
112
211
|
help | -h | --help) usage ;;
|
|
113
212
|
*) usage >&2; exit 2 ;;
|
|
114
213
|
esac
|
package/cli/lib/handoff.sh
CHANGED
|
@@ -194,8 +194,10 @@ task_handoff() {
|
|
|
194
194
|
# --- the log ----------------------------------------------------------------
|
|
195
195
|
|
|
196
196
|
# One query works out a card's view: each hand-off with its label, how long it
|
|
197
|
-
# took
|
|
198
|
-
# they cannot disagree, and a Herdr mod that
|
|
197
|
+
# took, whether it is a wait, and where the card stood after it. The plain log
|
|
198
|
+
# and the JSON both read it, so they cannot disagree, and a Herdr mod that
|
|
199
|
+
# draws the JSON formats nothing. With no card it works out the view of every
|
|
200
|
+
# card in the project at once, and the list of cards is each one's latest row.
|
|
199
201
|
#
|
|
200
202
|
# Nothing about time is stored beyond each row's own. A step's time is from
|
|
201
203
|
# the row before it to its own row. The time from a needs-human row to its
|
|
@@ -203,25 +205,29 @@ task_handoff() {
|
|
|
203
205
|
# row with nothing after it is still waiting, measured to now. A `new` row
|
|
204
206
|
# starts a run, so it has no time, however long ago the run before it ended.
|
|
205
207
|
|
|
206
|
-
# SQL for a number of seconds as text: 50s, 1m 44s, 1h 02m.
|
|
208
|
+
# SQL for a number of seconds as text: 50s, 1m 44s, 1h 02m, 3d 04h. @ stands
|
|
209
|
+
# for the column that holds the seconds.
|
|
207
210
|
sql_took() {
|
|
208
|
-
local s
|
|
209
|
-
|
|
210
|
-
when
|
|
211
|
-
else (
|
|
212
|
-
|
|
211
|
+
local t="case when @ < 60 then @ || 's'
|
|
212
|
+
when @ < 3600 then (@ / 60) || 'm ' || printf('%02d', @ % 60) || 's'
|
|
213
|
+
when @ < 86400 then (@ / 3600) || 'h ' || printf('%02d', @ % 3600 / 60) || 'm'
|
|
214
|
+
else (@ / 86400) || 'd ' || printf('%02d', @ % 86400 / 3600) || 'h' end"
|
|
215
|
+
printf '%s' "${t//@/$1}"
|
|
213
216
|
}
|
|
214
217
|
|
|
215
|
-
# SQL that starts a query on one card's view,
|
|
216
|
-
#
|
|
218
|
+
# SQL that starts a query on one card's view, or on every card's in the
|
|
219
|
+
# project, as the table `shown`. Each card's rows are worked out on their own.
|
|
220
|
+
# log_view <project> <card, or empty for all> <answer column, or null in a store without one>
|
|
217
221
|
log_view() {
|
|
222
|
+
local cards=''
|
|
223
|
+
[ -z "$2" ] || cards="and card = $(sql_str "$2")"
|
|
218
224
|
printf "with base as (
|
|
219
|
-
select id, at, phase, status, next, summary, flags, question, options,
|
|
225
|
+
select id, at, card, phase, status, next, summary, flags, question, options,
|
|
220
226
|
%s as answer, reason,
|
|
221
227
|
lag(at) over w as prev_at, lag(status) over w as before, lead(id) over w as after,
|
|
222
228
|
sum(case when phase = 'new' then 1 else 0 end) over w as run
|
|
223
|
-
from handoffs where project = %s
|
|
224
|
-
window w as (order by id)),
|
|
229
|
+
from handoffs where project = %s %s
|
|
230
|
+
window w as (partition by card order by id)),
|
|
225
231
|
timed as (
|
|
226
232
|
select *,
|
|
227
233
|
case when phase = 'new' or prev_at is null then null
|
|
@@ -229,7 +235,7 @@ log_view() {
|
|
|
229
235
|
case when after is null and status = 'needs-human'
|
|
230
236
|
then max(cast(strftime('%%s', 'now') - strftime('%%s', at) as integer), 0) end as open_seconds
|
|
231
237
|
from base),
|
|
232
|
-
|
|
238
|
+
labeled as (
|
|
233
239
|
select *,
|
|
234
240
|
case when phase = 'new' then 'start'
|
|
235
241
|
when status = 'answered' and before = 'needs-human' then 'wait'
|
|
@@ -248,16 +254,64 @@ log_view() {
|
|
|
248
254
|
else (%s) end as took,
|
|
249
255
|
case when open_seconds is null then ''
|
|
250
256
|
else 'waiting on the human for ' || (%s) end as waiting
|
|
251
|
-
from timed)
|
|
252
|
-
|
|
257
|
+
from timed),
|
|
258
|
+
shown as (
|
|
259
|
+
select *,
|
|
260
|
+
case when status = 'needs-human' then 'waiting on the human'
|
|
261
|
+
when phase = 'new' then 'started'
|
|
262
|
+
else label || substr(what, length(status) + 1) end as state
|
|
263
|
+
from labeled)" \
|
|
264
|
+
"$3" "$(sql_str "$1")" "$cards" \
|
|
253
265
|
"$(sql_took seconds)" "$(sql_took seconds)" "$(sql_took seconds)" "$(sql_took seconds)" \
|
|
254
266
|
"$(sql_took open_seconds)"
|
|
255
267
|
}
|
|
256
268
|
|
|
257
|
-
LOG_USAGE='usage: entourage task log <project> <card> [--json]'
|
|
269
|
+
LOG_USAGE='usage: entourage task log <project> [<card>] [--json]'
|
|
270
|
+
|
|
271
|
+
# The project's cards that have hand-offs, newest first by their latest row:
|
|
272
|
+
# where each stands and how long it has stood there. With --json, the same as
|
|
273
|
+
# one line of JSON.
|
|
274
|
+
# log_cards <project> <json: 1 or 0> <view>
|
|
275
|
+
log_cards() {
|
|
276
|
+
local name=$1 json=$2 list
|
|
277
|
+
# Each card's latest row is the one with nothing after it.
|
|
278
|
+
list="$3, latest as (
|
|
279
|
+
select *, max(cast(strftime('%s', 'now') - strftime('%s', at) as integer), 0) as since
|
|
280
|
+
from shown where after is null)"
|
|
281
|
+
if [ "$json" = 1 ]; then
|
|
282
|
+
if [ ! -e "$STORE" ]; then
|
|
283
|
+
printf '{"project":"%s","cards":[]}\n' "$(json_str "$name")"
|
|
284
|
+
return
|
|
285
|
+
fi
|
|
286
|
+
store "$STORE" "$list
|
|
287
|
+
select json_object('project', $(sql_str "$name"),
|
|
288
|
+
'cards', (select json_group_array(json(c)) from (
|
|
289
|
+
select json_object('card', card, 'at', at, 'state', state,
|
|
290
|
+
'waiting', nullif(waiting, ''), 'for', $(sql_took since), 'seconds', since,
|
|
291
|
+
'run', run, 'phase', phase, 'status', status, 'next', next) as c
|
|
292
|
+
from latest order by at desc, id desc)));" ||
|
|
293
|
+
die "could not read the hand-offs in $STORE. It may not be entourage's store."
|
|
294
|
+
return
|
|
295
|
+
fi
|
|
296
|
+
|
|
297
|
+
local sep=$'\x1f' found='' count=0 card state for
|
|
298
|
+
if [ -e "$STORE" ]; then
|
|
299
|
+
found=$(store -separator "$sep" "$STORE" "$list
|
|
300
|
+
select card, state, $(sql_took since) from latest order by at desc, id desc;") ||
|
|
301
|
+
die "could not read the hand-offs in $STORE. It may not be entourage's store."
|
|
302
|
+
fi
|
|
303
|
+
while IFS=$sep read -r card state for; do
|
|
304
|
+
[ -n "$card" ] || continue
|
|
305
|
+
[ "$count" -gt 0 ] || say "Cards in '$name' with hand-offs, newest first"
|
|
306
|
+
count=$((count + 1))
|
|
307
|
+
printf '%-10s %-28s for %s\n' "$card" "$state" "$for"
|
|
308
|
+
done <<< "$found"
|
|
309
|
+
[ "$count" -gt 0 ] || say "No hand-offs recorded in '$name'."
|
|
310
|
+
}
|
|
258
311
|
|
|
259
312
|
# List a card's hand-offs, oldest first, with how long each step took. With
|
|
260
|
-
# --json, the same view as
|
|
313
|
+
# no card, list the project's cards instead. With --json, the same view as
|
|
314
|
+
# one line of JSON.
|
|
261
315
|
task_log() {
|
|
262
316
|
local json=0 a
|
|
263
317
|
local args=()
|
|
@@ -272,17 +326,21 @@ task_log() {
|
|
|
272
326
|
local name=${1:-} card=${2:-}
|
|
273
327
|
[ -n "$name" ] || die "$LOG_USAGE"
|
|
274
328
|
project_named "$name" || die "there is no entourage project called '$name'. See: entourage project ls"
|
|
275
|
-
card=$(handoff_card "$name" "$card" log) || exit 1
|
|
276
329
|
[ "$#" -le 2 ] || die "$LOG_USAGE"
|
|
330
|
+
[ -z "$card" ] || card=$(handoff_card "$name" "$card" log) || exit 1
|
|
277
331
|
have_sqlite || die "$SQLITE is not installed, so no hand-offs have been recorded on this machine."
|
|
278
332
|
|
|
279
333
|
# Reading never changes the store. An older one has no answer column, so it
|
|
280
334
|
# is read without one.
|
|
281
|
-
local answer_column=null view found=''
|
|
335
|
+
local answer_column=null view='' found=''
|
|
282
336
|
if [ -e "$STORE" ]; then
|
|
283
337
|
! has_answer_column || answer_column=answer
|
|
284
338
|
view=$(log_view "$name" "$card" "$answer_column")
|
|
285
339
|
fi
|
|
340
|
+
if [ -z "$card" ]; then
|
|
341
|
+
log_cards "$name" "$json" "$view"
|
|
342
|
+
return
|
|
343
|
+
fi
|
|
286
344
|
|
|
287
345
|
if [ "$json" = 1 ]; then
|
|
288
346
|
if [ ! -e "$STORE" ]; then
|
|
@@ -294,9 +352,7 @@ task_log() {
|
|
|
294
352
|
# cannot be read is an error, not an empty history.
|
|
295
353
|
store "$STORE" "$view
|
|
296
354
|
select json_object('project', $(sql_str "$name"), 'card', $(sql_str "$card"),
|
|
297
|
-
'state', (select
|
|
298
|
-
when phase = 'new' then 'started' else label || substr(what, length(status) + 1) end
|
|
299
|
-
from shown order by id desc limit 1),
|
|
355
|
+
'state', (select state from shown order by id desc limit 1),
|
|
300
356
|
'waiting', (select nullif(waiting, '') from shown order by id desc limit 1),
|
|
301
357
|
'run', (select max(run) from shown),
|
|
302
358
|
'steps', (select json_group_array(json(step)) from (
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Linear: the one place entourage talks to Linear. Sourced by cli/entourage.
|
|
2
|
+
|
|
3
|
+
# Cards live in Linear. An agent reaches them through its own Linear tools.
|
|
4
|
+
# entourage reaches them here, with a Linear API key the human saves once, so
|
|
5
|
+
# that listing cards needs no agent and a Linear step goes the same way on
|
|
6
|
+
# every run.
|
|
7
|
+
#
|
|
8
|
+
# Linear is asked through its GraphQL API with curl, and its answers are read
|
|
9
|
+
# with jq. The rest of entourage needs neither, so a command here says which
|
|
10
|
+
# one is missing.
|
|
11
|
+
|
|
12
|
+
LINEAR_URL=https://api.linear.app/graphql
|
|
13
|
+
# The key is one of entourage's variables, LINEAR_API_KEY. It comes from the
|
|
14
|
+
# environment, or from entourage's env file ($ENV_FILE), which cli/entourage
|
|
15
|
+
# has read by now and `linear key` writes.
|
|
16
|
+
#
|
|
17
|
+
# What a key is made of. Linear's are lin_api_ and then letters and digits. A
|
|
18
|
+
# key with a quote, a backslash or a space in it is not one, and could not be
|
|
19
|
+
# handed to curl as a line of its config.
|
|
20
|
+
KEY_RE='^[A-Za-z0-9_.-]+$'
|
|
21
|
+
# How many seconds to wait for Linear before giving up.
|
|
22
|
+
LINEAR_WAIT=20
|
|
23
|
+
# Where the human makes a key.
|
|
24
|
+
KEY_PLACE='Linear, under Settings, Account, Security & access, Personal API keys'
|
|
25
|
+
|
|
26
|
+
# Stop unless the two programs every Linear command needs are here.
|
|
27
|
+
linear_tools() {
|
|
28
|
+
local tool
|
|
29
|
+
for tool in curl jq; do
|
|
30
|
+
command -v "$tool" >/dev/null 2>&1 ||
|
|
31
|
+
die "$tool is not installed, and entourage needs it to ask Linear anything. Install it, then run this again."
|
|
32
|
+
done
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# Ask Linear one thing and print the data it answers with, as one line of JSON.
|
|
36
|
+
# linear_ask <key> <query> [<the query's variables, as JSON>]
|
|
37
|
+
# The key goes to curl on stdin, as a line of its config: other programs on
|
|
38
|
+
# the machine can read a command's arguments, and cannot read its stdin. The
|
|
39
|
+
# ways this fails are told apart, because what the human does next differs:
|
|
40
|
+
# check the network, or replace the key.
|
|
41
|
+
linear_ask() {
|
|
42
|
+
local key=$1 query=$2 vars=${3:-} body out code=0 status said
|
|
43
|
+
[ -n "$vars" ] || vars='{}'
|
|
44
|
+
body=$(jq -cn --arg q "$query" --argjson v "$vars" '{query: $q, variables: $v}') ||
|
|
45
|
+
die "could not put a question to Linear together."
|
|
46
|
+
# --disable has to be curl's first argument. It keeps a person's ~/.curlrc
|
|
47
|
+
# from changing how Linear's answers are read, as -init /dev/null does for
|
|
48
|
+
# sqlite3 in handoff.sh: a --fail or --include there would make a rejected
|
|
49
|
+
# key look like the network, or a good answer unreadable. The key's own
|
|
50
|
+
# --config - is still read.
|
|
51
|
+
out=$(printf 'header = "Authorization: %s"\n' "$key" |
|
|
52
|
+
curl --disable --silent --show-error --max-time "$LINEAR_WAIT" --config - \
|
|
53
|
+
--header 'Content-Type: application/json' --data-binary "$body" \
|
|
54
|
+
--write-out '\n%{http_code}' "$LINEAR_URL" 2>&1) || code=$?
|
|
55
|
+
if [ "$code" -ne 0 ]; then
|
|
56
|
+
said=$(printf '%s\n' "$out" | grep -m 1 '^curl: ') || said=
|
|
57
|
+
die "could not reach Linear${said:+ ($said)}. Check the network, then run this again."
|
|
58
|
+
fi
|
|
59
|
+
# curl ends what it prints with the HTTP status, on a line of its own.
|
|
60
|
+
status=${out##*$'\n'}
|
|
61
|
+
out=${out%$'\n'*}
|
|
62
|
+
# A key Linear does not know: a 401, or Linear's own word for it at any
|
|
63
|
+
# status. A 403 counts only when it is Linear's own answer: a page from a
|
|
64
|
+
# proxy or a firewall says nothing about the key, and a new key would not
|
|
65
|
+
# get past it.
|
|
66
|
+
if [ "$status" = 401 ] ||
|
|
67
|
+
{ [ "$status" = 403 ] && printf '%s' "$out" | jq -e 'type == "object" and has("errors")' >/dev/null 2>&1; } ||
|
|
68
|
+
[ "$(printf '%s' "$out" | jq -r '[.errors[]?.extensions | ((.type // "") + " " + (.code // "")) | test("authentication"; "i")] | any' 2>/dev/null)" = true ]; then
|
|
69
|
+
die "Linear rejected the key. Make a new one in $KEY_PLACE, then save it with: entourage linear key"
|
|
70
|
+
fi
|
|
71
|
+
said=$(printf '%s' "$out" | jq -r '.errors[0].message // empty' 2>/dev/null) || said=
|
|
72
|
+
[ -z "$said" ] || die "Linear answered with an error: ${said//"$key"/<the key>}"
|
|
73
|
+
# An answer that is not JSON did not come from Linear's API.
|
|
74
|
+
[ "$status" = 200 ] || printf '%s' "$out" | jq -e . >/dev/null 2>&1 ||
|
|
75
|
+
die "something between this machine and Linear answered for it, with HTTP status $status. Check the network, then run this again."
|
|
76
|
+
[ "$status" = 200 ] || die "Linear answered with HTTP status $status and no result. Try again in a minute."
|
|
77
|
+
printf '%s' "$out" | jq -ce '.data // empty' 2>/dev/null ||
|
|
78
|
+
die "Linear's answer was not one entourage can read. Something between this machine and Linear may be answering for it."
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Print the key entourage has been given, or stop and say how to save one.
|
|
82
|
+
linear_saved_key() {
|
|
83
|
+
local key=${LINEAR_API_KEY:-}
|
|
84
|
+
[ -n "$key" ] ||
|
|
85
|
+
die "no Linear key is saved, so entourage cannot read Linear. Make one in $KEY_PLACE, then save it with: entourage linear key"
|
|
86
|
+
[[ $key =~ $KEY_RE ]] ||
|
|
87
|
+
die "LINEAR_API_KEY does not hold a Linear API key. Check your environment and $ENV_FILE, or save a new key with: entourage linear key"
|
|
88
|
+
printf '%s' "$key"
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# The kinds of status an open card is in, as Linear names them, in the order
|
|
92
|
+
# Linear shows them. A card that is done, cancelled or a duplicate is in one
|
|
93
|
+
# of the other kinds, and is never asked for.
|
|
94
|
+
OPEN_TYPES='["triage","backlog","unstarted","started"]'
|
|
95
|
+
# How many cards to ask for at a time, and how many times to ask before
|
|
96
|
+
# deciding that Linear will never say it has no more.
|
|
97
|
+
LINEAR_PAGE=100
|
|
98
|
+
LINEAR_PAGES=50
|
|
99
|
+
|
|
100
|
+
# The teams Linear knows of those asked for, their open statuses, and one page
|
|
101
|
+
# of their open cards, most recently changed first.
|
|
102
|
+
LIST_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: String) {
|
|
103
|
+
teams(filter: {key: {in: $teams}}) { nodes { key } }
|
|
104
|
+
workflowStates(first: 250, filter: {team: {key: {in: $teams}}, type: {in: $types}}) {
|
|
105
|
+
nodes { name type position team { key } }
|
|
106
|
+
}
|
|
107
|
+
issues(first: $first, after: $after, orderBy: updatedAt,
|
|
108
|
+
filter: {team: {key: {in: $teams}}, state: {type: {in: $types}}}) {
|
|
109
|
+
nodes { identifier title url state { name type position } }
|
|
110
|
+
pageInfo { hasNextPage endCursor }
|
|
111
|
+
}
|
|
112
|
+
}'
|
|
113
|
+
|
|
114
|
+
# Turn the pages Linear answered with (one line of JSON each, on stdin) into
|
|
115
|
+
# the list: every open status, in Linear's order, with its cards. Teams often
|
|
116
|
+
# share a status name; a status of one name and kind is one group, whichever
|
|
117
|
+
# teams have it. $project, $teams and $types are given by the caller.
|
|
118
|
+
# - A card can come on two pages, when it moves while they are fetched. The
|
|
119
|
+
# first copy is kept, in the order Linear gave them.
|
|
120
|
+
# - The statuses are the ones the first page names, and any a card is in
|
|
121
|
+
# that it did not, such as one made while the pages were fetched, so that
|
|
122
|
+
# no card is dropped for want of a group.
|
|
123
|
+
# - A closed status is never listed, should Linear send one.
|
|
124
|
+
LIST_SHAPE='
|
|
125
|
+
($types | to_entries | map({key: .value, value: .key}) | from_entries) as $rank
|
|
126
|
+
| .[0] as $first
|
|
127
|
+
| ([.[].issues.nodes[]] | to_entries | unique_by(.value.identifier) | sort_by(.key) | map(.value)) as $cards
|
|
128
|
+
| {
|
|
129
|
+
missing: ($teams - [$first.teams.nodes[].key]),
|
|
130
|
+
project: $project,
|
|
131
|
+
teams: $teams,
|
|
132
|
+
statuses: [
|
|
133
|
+
($first.workflowStates.nodes + [$cards[].state])
|
|
134
|
+
| map(select($rank[.type] != null))
|
|
135
|
+
| group_by([.type, .name])
|
|
136
|
+
| map({name: .[0].name, type: .[0].type, position: ((map(.position | numbers) | min) // 1000000)})
|
|
137
|
+
| sort_by([$rank[.type], .position, .name])
|
|
138
|
+
| .[]
|
|
139
|
+
| . as $status
|
|
140
|
+
| {
|
|
141
|
+
name: $status.name,
|
|
142
|
+
type: $status.type,
|
|
143
|
+
cards: [
|
|
144
|
+
$cards[]
|
|
145
|
+
| select(.state.name == $status.name and .state.type == $status.type)
|
|
146
|
+
| {id: .identifier, title: .title, url: .url}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}'
|
|
151
|
+
|
|
152
|
+
# Print the open cards of some Linear teams as one line of JSON, grouped by
|
|
153
|
+
# status:
|
|
154
|
+
# {"project":"demo","teams":["ABC"],"statuses":[
|
|
155
|
+
# {"name":"Backlog","type":"backlog","cards":[{"id":"ABC-1","title":"…","url":"…"}]}]}
|
|
156
|
+
# Every open status of the teams is there, with no cards when it has none.
|
|
157
|
+
# linear_open_cards <project> <team key>...
|
|
158
|
+
linear_open_cards() {
|
|
159
|
+
local project=$1 key teams vars data pages='' after='' more asked=0 list missing
|
|
160
|
+
shift
|
|
161
|
+
linear_tools
|
|
162
|
+
key=$(linear_saved_key) || exit 1
|
|
163
|
+
teams=$(printf '%s\n' "$@" | jq -Rcn '[inputs]')
|
|
164
|
+
while :; do
|
|
165
|
+
asked=$((asked + 1))
|
|
166
|
+
[ "$asked" -le "$LINEAR_PAGES" ] ||
|
|
167
|
+
die "Linear still had more cards after $LINEAR_PAGES pages of $LINEAR_PAGE, which is more than entourage lists."
|
|
168
|
+
vars=$(jq -cn --argjson teams "$teams" --argjson types "$OPEN_TYPES" --argjson first "$LINEAR_PAGE" \
|
|
169
|
+
--arg after "$after" \
|
|
170
|
+
'{teams: $teams, types: $types, first: $first, after: (if $after == "" then null else $after end)}')
|
|
171
|
+
data=$(linear_ask "$key" "$LIST_QUERY" "$vars") || exit 1
|
|
172
|
+
pages+=$data$'\n'
|
|
173
|
+
more=$(printf '%s' "$data" | jq -r '.issues.pageInfo.hasNextPage == true' 2>/dev/null) ||
|
|
174
|
+
die "Linear's answer was not one entourage can read."
|
|
175
|
+
[ "$more" = true ] || break
|
|
176
|
+
# Listing what came so far would pass a part of the list for the whole.
|
|
177
|
+
after=$(printf '%s' "$data" | jq -r '.issues.pageInfo.endCursor | strings' 2>/dev/null) || after=
|
|
178
|
+
[ -n "$after" ] ||
|
|
179
|
+
die "Linear said it had more cards but not where the next ones start, so the list would be cut short."
|
|
180
|
+
done
|
|
181
|
+
# The pages go to jq on stdin, not as an argument: a long list of cards is
|
|
182
|
+
# more than a command's arguments may hold.
|
|
183
|
+
list=$(printf '%s' "$pages" |
|
|
184
|
+
jq -cs --arg project "$project" --argjson teams "$teams" --argjson types "$OPEN_TYPES" "$LIST_SHAPE" 2>/dev/null) ||
|
|
185
|
+
die "Linear's answer was not one entourage can read."
|
|
186
|
+
missing=$(printf '%s' "$list" | jq -r '.missing | join(", ")')
|
|
187
|
+
[ -z "$missing" ] ||
|
|
188
|
+
die "Linear has no team with the key $missing that the saved key can see. See the project's teams with: entourage project team $project"
|
|
189
|
+
printf '%s' "$list" | jq -c 'del(.missing)'
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
# Save the human's Linear API key as LINEAR_API_KEY in entourage's env file,
|
|
193
|
+
# once Linear has said whose it is. The key is asked for or read from stdin,
|
|
194
|
+
# never taken as an argument, so that it stays out of the shell's history.
|
|
195
|
+
linear_key() {
|
|
196
|
+
# Every line the loader in cli/entourage would read as the key.
|
|
197
|
+
local key='' data who tmp tty_was key_line='^[[:space:]]*(export[[:space:]]+)?LINEAR_API_KEY[[:space:]]*='
|
|
198
|
+
[ "$#" -eq 0 ] ||
|
|
199
|
+
die "usage: entourage linear key (it asks for the key, or reads it from stdin; the key is never an argument)"
|
|
200
|
+
# A linked env file is often kept in a dotfiles repo. Replacing the link
|
|
201
|
+
# would cut it loose, and writing through it would put the key in that
|
|
202
|
+
# repo, so it is left alone, as trust.sh leaves a linked Claude Code file.
|
|
203
|
+
# This comes before the key is asked for, so nobody pastes one for nothing.
|
|
204
|
+
[ ! -L "$ENV_FILE" ] ||
|
|
205
|
+
die "$ENV_FILE is a link, so entourage left it alone and saved no key. Add the line LINEAR_API_KEY=<your key> to the file it links to yourself, or put a plain file in its place and run this again."
|
|
206
|
+
linear_tools
|
|
207
|
+
if [ -t 0 ]; then
|
|
208
|
+
printf 'Linear API key (it is not shown as you type or paste it): ' >&2
|
|
209
|
+
# read -s turns the terminal's echo off, and Ctrl-C at the prompt would
|
|
210
|
+
# leave it off. Put the terminal back as it was, then stop as Ctrl-C would
|
|
211
|
+
# have, so that whatever ran this sees it end the same way.
|
|
212
|
+
tty_was=$(stty -g 2>/dev/null) || tty_was=
|
|
213
|
+
trap 'stty "$tty_was" 2>/dev/null || stty echo 2>/dev/null; printf "\n" >&2; trap - INT; kill -INT $$' INT
|
|
214
|
+
IFS= read -rs key || true
|
|
215
|
+
trap - INT
|
|
216
|
+
printf '\n' >&2
|
|
217
|
+
else
|
|
218
|
+
IFS= read -r key || true
|
|
219
|
+
fi
|
|
220
|
+
# A pasted key often brings a space or a line ending with it.
|
|
221
|
+
key=${key%$'\r'}
|
|
222
|
+
key=${key#"${key%%[![:space:]]*}"}
|
|
223
|
+
key=${key%"${key##*[![:space:]]}"}
|
|
224
|
+
[ -n "$key" ] || die "no key was given. Make one in $KEY_PLACE, then run this again."
|
|
225
|
+
[[ $key =~ $KEY_RE ]] ||
|
|
226
|
+
die "that is not a Linear API key. A key is lin_api_ and then letters and digits. Make one in $KEY_PLACE."
|
|
227
|
+
data=$(linear_ask "$key" 'query { viewer { id name } }') || die "the key was not saved."
|
|
228
|
+
# Linear always says who a good key belongs to. An answer that names nobody
|
|
229
|
+
# did not come from Linear, so it checked nothing.
|
|
230
|
+
printf '%s' "$data" | jq -e '.viewer.id | strings' >/dev/null 2>&1 ||
|
|
231
|
+
die "Linear's answer did not say whose key it is, so the key was not saved. Something between this machine and Linear may be answering for it."
|
|
232
|
+
who=$(printf '%s' "$data" | jq -r '.viewer.name // empty' 2>/dev/null) || who=
|
|
233
|
+
|
|
234
|
+
# The file is the human's too: every other line of it is kept, and the key
|
|
235
|
+
# gets one line, in place of any it had. It is written beside itself and
|
|
236
|
+
# moved into place whole, so a run cut short leaves the old file or the new
|
|
237
|
+
# one, never half of one. It is made for its owner's eyes only.
|
|
238
|
+
mkdir -p "$ENT_HOME"
|
|
239
|
+
tmp=$ENV_FILE.entourage.$$
|
|
240
|
+
# grep -a: a file with a NUL or another odd byte in it is still text here.
|
|
241
|
+
# Without it grep calls the file binary and prints a note in place of its
|
|
242
|
+
# lines. grep exits 1 when no line is left, which is fine; 2 is an error,
|
|
243
|
+
# and must not leave a file with only the key in it.
|
|
244
|
+
if (umask 077
|
|
245
|
+
{
|
|
246
|
+
if [ -f "$ENV_FILE" ]; then
|
|
247
|
+
grep -a -v -E "$key_line" "$ENV_FILE"
|
|
248
|
+
[ "$?" -le 1 ]
|
|
249
|
+
fi &&
|
|
250
|
+
printf 'LINEAR_API_KEY=%s\n' "$key"
|
|
251
|
+
} > "$tmp") 2>/dev/null && mv -f "$tmp" "$ENV_FILE" 2>/dev/null; then
|
|
252
|
+
chmod 600 "$ENV_FILE" 2>/dev/null || true
|
|
253
|
+
else
|
|
254
|
+
rm -f "$tmp" 2>/dev/null || true
|
|
255
|
+
die "could not write $ENV_FILE, so the key was not saved."
|
|
256
|
+
fi
|
|
257
|
+
say "Saved the Linear key of ${who:-a user with no name} in $ENV_FILE"
|
|
258
|
+
# A key exported in the shell wins over the file, so a different one there
|
|
259
|
+
# would go on being used.
|
|
260
|
+
if [ -n "$KEY_EXPORTED" ] && [ "${LINEAR_API_KEY:-}" != "$key" ]; then
|
|
261
|
+
say " note LINEAR_API_KEY is also set in your environment, to another key. That one is used while it is set, not the one just saved."
|
|
262
|
+
fi
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
cmd_linear() {
|
|
266
|
+
case ${1:-} in
|
|
267
|
+
key) shift; linear_key "$@" ;;
|
|
268
|
+
*) die "usage: entourage linear key (see: entourage help)" ;;
|
|
269
|
+
esac
|
|
270
|
+
}
|
package/cli/lib/project.sh
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# A project is a folder in $PROJECTS:
|
|
4
4
|
# PROJECT.md what the project is and what belongs in each repo
|
|
5
5
|
# repos one repo path per line (~/ for the home folder, # for comments)
|
|
6
|
+
# teams the keys of the project's Linear teams, like ABC, one per line
|
|
6
7
|
# links/ generated: a link to each repo, named after its folder
|
|
7
8
|
# CLAUDE.md, AGENTS.md generated: links to PROJECT.md, so agents read it
|
|
8
9
|
|
|
@@ -208,6 +209,60 @@ project_ls() {
|
|
|
208
209
|
[ "$any" = 1 ] || say "No projects yet. Make one with: entourage project new <name>"
|
|
209
210
|
}
|
|
210
211
|
|
|
212
|
+
# A team's key is what its cards' IDs start with: ABC for ABC-122.
|
|
213
|
+
TEAM_RE='^[A-Za-z][A-Za-z0-9]*$'
|
|
214
|
+
|
|
215
|
+
# Print a project's Linear teams, one key per line in upper case, each once,
|
|
216
|
+
# or nothing when it has none. The file is the human's to edit, so a # starts
|
|
217
|
+
# a comment anywhere on a line, and spaces and blank lines are skipped. A line
|
|
218
|
+
# that is still not a team key stops it, naming the line, before anything is
|
|
219
|
+
# printed: a typo here would otherwise read as a team Linear does not have.
|
|
220
|
+
project_teams() {
|
|
221
|
+
local dir=$1 line n=0 keys=''
|
|
222
|
+
[ -f "$dir/teams" ] || return 0
|
|
223
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
224
|
+
n=$((n + 1))
|
|
225
|
+
line=${line%%#*}
|
|
226
|
+
line=${line#"${line%%[![:space:]]*}"}
|
|
227
|
+
line=${line%"${line##*[![:space:]]}"}
|
|
228
|
+
[ -n "$line" ] || continue
|
|
229
|
+
[[ $line =~ $TEAM_RE ]] ||
|
|
230
|
+
die "line $n of $dir/teams is '$line', which is not a Linear team key. A team's key is what its cards' IDs start with: ABC for ABC-122."
|
|
231
|
+
keys+=$line$'\n'
|
|
232
|
+
done < "$dir/teams"
|
|
233
|
+
[ -n "$keys" ] || return 0
|
|
234
|
+
printf '%s' "$keys" | tr '[:lower:]' '[:upper:]' | awk '!seen[$0]++'
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
# Set the Linear teams whose cards are a project's, or print them when no key
|
|
238
|
+
# is given. `task ls` lists those teams' cards. A project can name several
|
|
239
|
+
# teams, and several projects can name the same team. The keys given replace
|
|
240
|
+
# the ones there. They are not checked with Linear here, so teams can be set
|
|
241
|
+
# with no network and before a Linear key is saved.
|
|
242
|
+
project_team() {
|
|
243
|
+
local name=${1:-} dir key keys='' teams
|
|
244
|
+
dir=$(project_dir "$name")
|
|
245
|
+
shift
|
|
246
|
+
if [ "$#" -eq 0 ]; then
|
|
247
|
+
teams=$(project_teams "$dir") || exit 1
|
|
248
|
+
[ -n "$teams" ] ||
|
|
249
|
+
die "project '$name' has no Linear team. Set it with: entourage project team $name <team key>, like: entourage project team $name ABC"
|
|
250
|
+
say "$teams"
|
|
251
|
+
return
|
|
252
|
+
fi
|
|
253
|
+
# Every key is checked before the file is written, so a bad one does not
|
|
254
|
+
# leave the project with only some of its teams.
|
|
255
|
+
for key in "$@"; do
|
|
256
|
+
[[ $key =~ $TEAM_RE ]] ||
|
|
257
|
+
die "'$key' is not a Linear team key. A team's key is what its cards' IDs start with: ABC for ABC-122."
|
|
258
|
+
key=$(printf '%s' "$key" | tr '[:lower:]' '[:upper:]')
|
|
259
|
+
case $'\n'$keys in *$'\n'"$key"$'\n'*) continue ;; esac
|
|
260
|
+
keys+=$key$'\n'
|
|
261
|
+
done
|
|
262
|
+
printf '%s' "$keys" > "$dir/teams"
|
|
263
|
+
say "Project '$name' lists the cards of: $(printf '%s' "$keys" | tr '\n' ' ' | sed 's/ $//')"
|
|
264
|
+
}
|
|
265
|
+
|
|
211
266
|
# Print what is wrong with each project; return how many problems there are.
|
|
212
267
|
check_projects() {
|
|
213
268
|
local d repo problems=0 bad
|
|
@@ -247,6 +302,7 @@ cmd_project() {
|
|
|
247
302
|
add) shift; project_add "$@" ;;
|
|
248
303
|
open) shift; project_open "$@" ;;
|
|
249
304
|
ls | list) shift; project_ls "$@" ;;
|
|
250
|
-
|
|
305
|
+
team) shift; project_team "$@" ;;
|
|
306
|
+
*) die "usage: entourage project new|add|open|ls|team (see: entourage help)" ;;
|
|
251
307
|
esac
|
|
252
308
|
}
|
package/cli/lib/task.sh
CHANGED
|
@@ -315,12 +315,46 @@ task_start() {
|
|
|
315
315
|
say "Opened task '$task' on branch $branch"
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
# List the open cards of a project's Linear teams, grouped by status: the
|
|
319
|
+
# cards `task new` can be given. Linear itself is asked in linear.sh. --json
|
|
320
|
+
# prints the list as one line for programs; the cards mod reads it.
|
|
321
|
+
task_ls() {
|
|
322
|
+
local name=${1:-} json=0 dir team keys list
|
|
323
|
+
local -a teams=()
|
|
324
|
+
dir=$(project_dir "$name")
|
|
325
|
+
case ${2:-} in
|
|
326
|
+
--json) json=1 ;;
|
|
327
|
+
'') ;;
|
|
328
|
+
*) die "unknown option for task ls: $2" ;;
|
|
329
|
+
esac
|
|
330
|
+
[ "$#" -le 2 ] || die "usage: entourage task ls <project> [--json]"
|
|
331
|
+
# Read first, so that a bad line in the teams file stops it with its own
|
|
332
|
+
# message, not one saying there is no team.
|
|
333
|
+
keys=$(project_teams "$dir") || exit 1
|
|
334
|
+
while IFS= read -r team; do [ -z "$team" ] || teams+=("$team"); done <<< "$keys"
|
|
335
|
+
[ "${#teams[@]}" -gt 0 ] ||
|
|
336
|
+
die "project '$name' has no Linear team, so there are no cards to list. Set it with: entourage project team $name <team key>, like: entourage project team $name ABC"
|
|
337
|
+
list=$(linear_open_cards "$name" "${teams[@]}") || exit 1
|
|
338
|
+
if [ "$json" = 1 ]; then
|
|
339
|
+
printf '%s\n' "$list"
|
|
340
|
+
return
|
|
341
|
+
fi
|
|
342
|
+
# Titles and status names are anyone's text. In the list, a newline would
|
|
343
|
+
# start what looks like another card, and an escape sequence would reach the
|
|
344
|
+
# terminal, so every control character becomes a space. No regex, so any jq
|
|
345
|
+
# does it. --json above keeps the text as it is.
|
|
346
|
+
printf '%s' "$list" |
|
|
347
|
+
jq -r 'def plain: explode | map(if . < 32 or (. > 126 and . < 160) then 32 else . end) | implode;
|
|
348
|
+
.statuses[] | "\(.name | plain) (\(.cards | length))", (.cards[] | " \(.id | plain) \(.title | plain)")'
|
|
349
|
+
}
|
|
350
|
+
|
|
318
351
|
cmd_task() {
|
|
319
352
|
case ${1:-} in
|
|
320
353
|
new) shift; task_new "$@" ;;
|
|
354
|
+
ls | list) shift; task_ls "$@" ;;
|
|
321
355
|
start) shift; task_start "$@" ;;
|
|
322
356
|
handoff) shift; task_handoff "$@" ;;
|
|
323
357
|
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)" ;;
|
|
358
|
+
*) die "usage: entourage task ls <project> [--json], or: 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
359
|
esac
|
|
326
360
|
}
|
package/herdr/README.md
CHANGED
|
@@ -10,7 +10,7 @@ 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
|
+
| `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. With no card's tab selected, the project's cards and where each stands. |
|
|
14
14
|
| `layouts/default.json` | Herdr's own layout, plus the layout dropdown. |
|
|
15
15
|
| `layouts/test.json` | `default` with the projects list in place of spaces, plus the Steps panel and the CPU mod in the sidebar. |
|
|
16
16
|
| `projects/template/` | The starting `PROJECT.md` for every new project. |
|
|
@@ -94,6 +94,7 @@ template is in this repo. Your own projects are in
|
|
|
94
94
|
|---|---|
|
|
95
95
|
| `PROJECT.md` | What the project is and what belongs in each repo. You write this. |
|
|
96
96
|
| `repos` | One repo path per line. `entourage project add` writes it; you can edit it. |
|
|
97
|
+
| `teams` | The keys of the project's Linear teams, one per line, `#` for comments. `entourage project team` writes it; you can edit it. See [Seeing a project's cards](#seeing-a-projects-cards). |
|
|
97
98
|
| `links/` | Generated: a link to each repo, named after its folder. |
|
|
98
99
|
| `tasks/` | One folder per task, holding a worktree of each repo. See [Tasks](#tasks). |
|
|
99
100
|
| `CLAUDE.md`, `AGENTS.md` | Generated: links to `PROJECT.md`, so an agent started in the space reads it. |
|
|
@@ -126,6 +127,59 @@ template is in this repo. Your own projects are in
|
|
|
126
127
|
A task is one piece of work in a project, usually a Linear card. You run two
|
|
127
128
|
commands, in this order: `task new`, then `task start`. Two more, `task
|
|
128
129
|
handoff` and `task log`, record and show how each step of the write-up ended.
|
|
130
|
+
`task ls` lists the cards there are to start.
|
|
131
|
+
|
|
132
|
+
### Seeing a project's cards
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
entourage task ls <project> [--json]
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- **It lists the open cards of the project's Linear teams**, under their
|
|
139
|
+
statuses, in the order Linear shows the statuses. Open means not done, not
|
|
140
|
+
cancelled and not a duplicate, so a card in progress or in review is listed.
|
|
141
|
+
Each card is its ID and its title. A status with no cards is listed with a
|
|
142
|
+
count of 0.
|
|
143
|
+
- **It asks Linear itself, with no agent running.** That needs two things, each
|
|
144
|
+
set once:
|
|
145
|
+
|
|
146
|
+
| Set once | With | What it is |
|
|
147
|
+
|---|---|---|
|
|
148
|
+
| Your Linear API key | `entourage linear key` | Make the key in Linear, under Settings, Account, Security & access, Personal API keys. Read permission is enough to list cards. The command asks for it without showing it, checks it with Linear, and saves it. |
|
|
149
|
+
| The project's teams | `entourage project team <project> <team>...` | A team's key is what its cards' IDs start with: `ABC` for `ABC-122`. A project can name several teams, and several projects can name the same team. With no team given, the command prints the ones that are set. |
|
|
150
|
+
|
|
151
|
+
- **The key is one of entourage's variables, `LINEAR_API_KEY`.** `linear key`
|
|
152
|
+
writes it as a line of entourage's env file, `~/.config/entourage/.env`,
|
|
153
|
+
which only you can read. A key you export in your shell works too, and wins
|
|
154
|
+
over the file. See [entourage's variables](#entourages-variables).
|
|
155
|
+
- **The key is never shown.** It is handed to `curl` on its stdin, never as an
|
|
156
|
+
argument, and no message prints it. To take it off the machine, delete its
|
|
157
|
+
line from the env file.
|
|
158
|
+
- **When it cannot list, it says which thing is wrong:** no key saved, a key
|
|
159
|
+
Linear rejects, Linear out of reach, something between this machine and
|
|
160
|
+
Linear answering for it (a proxy's or a firewall's page), a project with no
|
|
161
|
+
team, a line of the `teams` file that is not a team key, or a team key Linear
|
|
162
|
+
does not have.
|
|
163
|
+
- **The `teams` file can be edited by hand.** Keys may be in lower case, a `#`
|
|
164
|
+
starts a comment, and blank lines and spaces are skipped. A line that is
|
|
165
|
+
still not a team key is named in the message.
|
|
166
|
+
- **A list it cannot fetch whole is not printed.** If Linear says it has more
|
|
167
|
+
cards but not where they start, the command fails rather than list part of
|
|
168
|
+
them. A card that comes on two pages is listed once, and a card in a status
|
|
169
|
+
Linear did not name up front is listed under that status.
|
|
170
|
+
- **In the plain list, control characters in titles become spaces**, so a title
|
|
171
|
+
cannot start what looks like another card or send escape sequences to your
|
|
172
|
+
terminal. `--json` keeps the text as Linear gave it.
|
|
173
|
+
- **Your `~/.curlrc` is not read**, so a line there such as `--fail` cannot
|
|
174
|
+
change what entourage reads back. A proxy set in the environment, such as
|
|
175
|
+
`HTTPS_PROXY`, is still used.
|
|
176
|
+
- **`--json` prints the list as one line for programs**: the project, its
|
|
177
|
+
teams, and each status with its `name`, its `type` (`triage`, `backlog`,
|
|
178
|
+
`unstarted` or `started`) and its `cards`, each with an `id`, a `title` and a
|
|
179
|
+
`url`. When it fails it prints nothing on stdout.
|
|
180
|
+
- **Two teams' cards share a group when the status has the same name**, such as
|
|
181
|
+
Backlog. A status only one team has is a group of its own.
|
|
182
|
+
- **It needs `curl` and `jq`**, and says which is missing.
|
|
129
183
|
|
|
130
184
|
### Writing the card up
|
|
131
185
|
|
|
@@ -173,7 +227,7 @@ EOF
|
|
|
173
227
|
```
|
|
174
228
|
|
|
175
229
|
```sh
|
|
176
|
-
entourage task log <project> <card>
|
|
230
|
+
entourage task log <project> [<card>]
|
|
177
231
|
```
|
|
178
232
|
|
|
179
233
|
- **The command holds the rules.** It refuses a block with a missing line, an
|
|
@@ -191,6 +245,11 @@ entourage task log <project> <card>
|
|
|
191
245
|
waited on you as a line of its own, counted in no step. A question with no
|
|
192
246
|
answer yet shows how long it has been waiting. A step that followed a
|
|
193
247
|
question with no recorded answer is marked as including the wait.
|
|
248
|
+
- **With no card, it lists the project's cards.** `task log <project>` shows
|
|
249
|
+
every card in the project that has hand-offs, newest first by its latest
|
|
250
|
+
one, with where it stands (waiting on you, failed, or the step it finished
|
|
251
|
+
and the one that comes next) and for how long. A card with no hand-offs is
|
|
252
|
+
not listed: `task ls` lists the cards in Linear.
|
|
194
253
|
- **They are kept in `~/.config/entourage/entourage.db`,** a SQLite file
|
|
195
254
|
beside your projects, on this machine only. It needs `sqlite3`, which macOS
|
|
196
255
|
ships; `ENTOURAGE_SQLITE` picks another command. Without it `task new`
|
|
@@ -202,8 +261,11 @@ entourage task log <project> <card>
|
|
|
202
261
|
new` opened, and the panel lists that card's steps: the time of day, what
|
|
203
262
|
the step did, how long it took, and its summary. A wait on you stands out,
|
|
204
263
|
and so does a question still waiting. It shows the latest run of a card
|
|
205
|
-
written up more than once.
|
|
206
|
-
|
|
264
|
+
written up more than once. With no card's tab selected, it lists the
|
|
265
|
+
project's cards instead, and a card waiting on you stands out. Click a card
|
|
266
|
+
to see its steps, even when its tab is closed, and "All cards" to go back;
|
|
267
|
+
selecting another tab goes back too. The panel draws what
|
|
268
|
+
`entourage task log <project> [<card>] --json` prints and works nothing out
|
|
207
269
|
itself, so the two always agree.
|
|
208
270
|
|
|
209
271
|
### Starting the work
|
|
@@ -291,6 +353,46 @@ setup:
|
|
|
291
353
|
- **`just` has to be installed** on the machine. Without it, tasks start
|
|
292
354
|
without setup and `entourage status` says so.
|
|
293
355
|
|
|
356
|
+
## entourage's variables
|
|
357
|
+
|
|
358
|
+
entourage reads a few environment variables. Each can be exported in your
|
|
359
|
+
shell, or written as a `NAME=value` line in entourage's env file,
|
|
360
|
+
`~/.config/entourage/.env`.
|
|
361
|
+
|
|
362
|
+
| Variable | What it sets |
|
|
363
|
+
|---|---|
|
|
364
|
+
| `LINEAR_API_KEY` | Your Linear API key. `entourage linear key` writes this line for you. |
|
|
365
|
+
| `ENTOURAGE_AGENT` | The agent `task new` starts. `claude` when it is not set. |
|
|
366
|
+
| `ENTOURAGE_SQLITE` | The command that records hand-offs. `sqlite3` when it is not set. |
|
|
367
|
+
| `HERDR_APP_HOME` | Herdr's folder. `~/.config/herdr-app` when it is not set. |
|
|
368
|
+
| `CLAUDE_CONFIG_DIR` | Claude Code's folder, where skills are linked. `~/.claude` when it is not set. |
|
|
369
|
+
| `ENTOURAGE_HOME` | entourage's own folder. `~/.config/entourage` when it is not set. Export only: it says where the env file is, so the file cannot set it. |
|
|
370
|
+
|
|
371
|
+
- **Use the file for anything a Herdr mod's run of entourage needs.** Herdr
|
|
372
|
+
starts a command without your shell's exports, so a variable set only in your
|
|
373
|
+
shell profile is missing there. The file is read every time, wherever
|
|
374
|
+
entourage is started from.
|
|
375
|
+
- **A variable you export wins** over its line in the file, unless it is
|
|
376
|
+
empty: an empty one counts as not set.
|
|
377
|
+
- **Of two lines for a name, the last is used**, so a line added at the end
|
|
378
|
+
takes over.
|
|
379
|
+
- **The file is read, never run.** A line that is not `NAME=value` is skipped,
|
|
380
|
+
and nothing in a value is expanded. These are allowed: `export` before the
|
|
381
|
+
name, spaces around the `=`, one pair of quotes around the value, and a `#`
|
|
382
|
+
comment after a value that has no quotes. Only entourage's own variables are
|
|
383
|
+
taken from it: the ones in the table, and any other whose name starts with
|
|
384
|
+
`ENTOURAGE_`. A line for anything else, such as `PATH`, is ignored.
|
|
385
|
+
- **The Linear key stays with entourage.** The other variables are passed on to
|
|
386
|
+
the programs entourage starts, so they find the same folders it does. The key
|
|
387
|
+
from the file is not: it reaches only `curl`, on its stdin.
|
|
388
|
+
- **Keep the file to yourself.** It holds your Linear key. `linear key` makes
|
|
389
|
+
it readable only by you; if you make it by hand, run
|
|
390
|
+
`chmod 600 ~/.config/entourage/.env`. A file entourage cannot read stops every
|
|
391
|
+
command, with a message saying so, rather than being skipped.
|
|
392
|
+
- **A linked env file is left alone.** If `.env` is a link, for example into a
|
|
393
|
+
dotfiles repo, `linear key` saves nothing and says so, so that the key does
|
|
394
|
+
not land in that repo. Add the `LINEAR_API_KEY` line yourself.
|
|
395
|
+
|
|
294
396
|
## Changing things
|
|
295
397
|
|
|
296
398
|
- Work from a git clone, not the npm install: clone the repo and run
|
package/herdr/mods/steps/main.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
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.
|
|
2
|
+
// did, how long it took, and how long it waited on the human. With no card's
|
|
3
|
+
// tab selected, the project's cards that have hand-offs, newest first, with
|
|
4
|
+
// where each stands. A click on a card shows its steps, even when its tab is
|
|
5
|
+
// closed.
|
|
3
6
|
//
|
|
4
|
-
// All of that is worked out by `entourage task log <project> <card> --json`.
|
|
5
|
-
// This mod draws the
|
|
7
|
+
// All of that is worked out by `entourage task log <project> [<card>] --json`.
|
|
8
|
+
// This mod draws the views that command returns and holds no rules about
|
|
6
9
|
// hand-offs: every label and every length of time arrives as text.
|
|
7
10
|
//
|
|
8
11
|
// A step is one line. A click on it opens what the step said.
|
|
@@ -11,7 +14,7 @@ import { v_flex, h_flex } from "gpui-base";
|
|
|
11
14
|
import { exec, spaces, theme, layout, window, checking, appHome } from "herdr";
|
|
12
15
|
|
|
13
16
|
const LOOK_MS = 2000; // how often to see whether another card is selected
|
|
14
|
-
const REREAD_MS = 6000; // how often to read
|
|
17
|
+
const REREAD_MS = 6000; // how often to read what is shown again
|
|
15
18
|
const PROJECTS_MS = 60000; // projects change rarely
|
|
16
19
|
const TIMEOUT_MS = 10000;
|
|
17
20
|
// How this mod's own link into the repo that ships it ends.
|
|
@@ -21,7 +24,15 @@ const CARD = /^[A-Za-z][A-Za-z0-9]*-[0-9]+$/;
|
|
|
21
24
|
|
|
22
25
|
// `herdr-app check` draws the mod once, with no card selected, which would
|
|
23
26
|
// show one line of text and none of the rows. It is given these to draw, all
|
|
24
|
-
// of them open, so a mistake in a row fails the check
|
|
27
|
+
// of them open, so a mistake in a row fails the check: a list of cards and a
|
|
28
|
+
// card's steps, with the way back from one to the other.
|
|
29
|
+
const SAMPLE_CARDS = {
|
|
30
|
+
project: "demo",
|
|
31
|
+
cards: [
|
|
32
|
+
{ card: "ABC-3", state: "waiting on the human", waiting: "waiting on the human for 2m 05s", for: "2m 05s" },
|
|
33
|
+
{ card: "ABC-1", state: "plan done, then breakdown", waiting: null, for: "3d 04h" },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
25
36
|
const SAMPLE = {
|
|
26
37
|
run: 1,
|
|
27
38
|
state: "waiting on the human",
|
|
@@ -58,20 +69,21 @@ function parse(text) {
|
|
|
58
69
|
// What a failed command said, without the name it starts its errors with.
|
|
59
70
|
const said = (r) => (r.stderr || r.stdout).trim().replace(/^entourage: /, "");
|
|
60
71
|
|
|
61
|
-
const OLD_CLI = "This entourage
|
|
62
|
-
// An entourage from before --json answers with its usage line, not JSON
|
|
72
|
+
const OLD_CLI = "This entourage is too old for the Steps panel. Run: entourage update";
|
|
73
|
+
// An entourage from before --json answers with its usage line, not JSON, and
|
|
74
|
+
// one from before the list of cards asks which card.
|
|
63
75
|
const failure = (r, what) => {
|
|
64
76
|
const text = said(r);
|
|
65
|
-
return text.startsWith("usage:") ? OLD_CLI : text || `${what} failed`;
|
|
77
|
+
return text.startsWith("usage:") || text.startsWith("which card?") ? OLD_CLI : text || `${what} failed`;
|
|
66
78
|
};
|
|
67
79
|
|
|
68
|
-
// What is selected on this computer: the shown space's folder,
|
|
69
|
-
//
|
|
80
|
+
// What is selected on this computer: the shown space's folder, the card its
|
|
81
|
+
// shown tab is for, if it is a card's tab, and which tab that is.
|
|
70
82
|
function selected() {
|
|
71
83
|
const space = spaces().find((s) => s.active && !s.machine) ?? null;
|
|
72
84
|
const tab = space?.tabs.find((t) => t.active) ?? null;
|
|
73
85
|
const card = tab && CARD.test(tab.name) ? tab.name.toUpperCase() : null;
|
|
74
|
-
return { folder: space?.folder ?? null, card,
|
|
86
|
+
return { folder: space?.folder ?? null, card, tab: `${space?.id ?? ""}\n${tab?.id ?? ""}` };
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
export default class Steps extends View {
|
|
@@ -81,7 +93,8 @@ export default class Steps extends View {
|
|
|
81
93
|
this.projectsAt = 0;
|
|
82
94
|
this.key = null; // what the view on hand was read for
|
|
83
95
|
this.project = null; // the entourage project of the shown space, or null
|
|
84
|
-
this.
|
|
96
|
+
this.picked = null; // a card chosen from the list, and the tab it was chosen in
|
|
97
|
+
this.view = null; // a card's steps, or the list of cards
|
|
85
98
|
this.error = null;
|
|
86
99
|
this.busy = false;
|
|
87
100
|
this.readAt = 0;
|
|
@@ -108,13 +121,32 @@ export default class Steps extends View {
|
|
|
108
121
|
}
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
124
|
+
// What the panel shows: the card of the selected tab; else the card chosen
|
|
125
|
+
// from the list; else the list. A card chosen from the list is let go as
|
|
126
|
+
// soon as another tab is seen selected, so coming back to that tab shows
|
|
127
|
+
// the list. The panel is drawn again whenever a tab is selected.
|
|
128
|
+
shown() {
|
|
129
|
+
const now = selected();
|
|
130
|
+
if (this.picked && (now.card || this.picked.tab !== now.tab)) this.picked = null;
|
|
131
|
+
const card = now.card ?? this.picked?.card ?? null;
|
|
132
|
+
return { folder: now.folder, card, picked: Boolean(this.picked), key: `${now.folder ?? ""}\n${card ?? ""}` };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Show a card chosen from the list, or the list again with null.
|
|
136
|
+
pick(card, cx) {
|
|
137
|
+
this.picked = card ? { card, tab: selected().tab } : null;
|
|
138
|
+
this.open = null;
|
|
139
|
+
cx.notify();
|
|
140
|
+
this.look(cx);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Read again when something else is to be shown, or what is on hand is
|
|
144
|
+
// stale. Nothing is read while nobody can see the panel, and a space that
|
|
145
|
+
// is not an entourage project has nothing to read again.
|
|
114
146
|
look(cx) {
|
|
115
147
|
if (this.busy || window()?.visible === false || narrow()) return;
|
|
116
|
-
const now =
|
|
117
|
-
const stale = Boolean(
|
|
148
|
+
const now = this.shown();
|
|
149
|
+
const stale = Boolean(this.project) && Date.now() - this.readAt >= REREAD_MS;
|
|
118
150
|
if (now.key === this.key && !stale) return;
|
|
119
151
|
this.busy = true;
|
|
120
152
|
cx.spawn(async (cx) => {
|
|
@@ -133,10 +165,11 @@ export default class Steps extends View {
|
|
|
133
165
|
}
|
|
134
166
|
}
|
|
135
167
|
project = (this.projects ?? []).find((p) => p.folder === now.folder)?.name ?? null;
|
|
136
|
-
if (!error && project
|
|
137
|
-
const
|
|
168
|
+
if (!error && project) {
|
|
169
|
+
const card = now.card ? [now.card] : [];
|
|
170
|
+
const r = await this.entourage(["task", "log", project, ...card, "--json"]);
|
|
138
171
|
const got = r.code === 0 ? parse(r.stdout) : null;
|
|
139
|
-
if (got && Array.isArray(got.steps)) view = got;
|
|
172
|
+
if (got && Array.isArray(now.card ? got.steps : got.cards)) view = got;
|
|
140
173
|
else error = r.code === 0 ? OLD_CLI : failure(r, "entourage task log");
|
|
141
174
|
}
|
|
142
175
|
} catch (e) {
|
|
@@ -149,15 +182,43 @@ export default class Steps extends View {
|
|
|
149
182
|
this.readAt = Date.now();
|
|
150
183
|
this.busy = false;
|
|
151
184
|
// A redraw of a mod redraws the whole window, so only when what it
|
|
152
|
-
// shows has changed.
|
|
153
|
-
|
|
185
|
+
// shows has changed. A card's seconds change at every read, and only
|
|
186
|
+
// the time drawn from them counts.
|
|
187
|
+
const cards = view?.cards?.map(({ seconds, ...c }) => c);
|
|
188
|
+
const drawn = JSON.stringify([now.key, project, cards ? { ...view, cards } : view, error]);
|
|
154
189
|
if (drawn !== this.drawn) {
|
|
155
190
|
this.drawn = drawn;
|
|
156
191
|
cx.notify();
|
|
157
192
|
}
|
|
193
|
+
// A card chosen while this was being read is read now, not at the
|
|
194
|
+
// next look.
|
|
195
|
+
if (this.shown().key !== now.key) this.look(cx);
|
|
158
196
|
});
|
|
159
197
|
}
|
|
160
198
|
|
|
199
|
+
// One card of the list: its ID and how long it has stood where it is,
|
|
200
|
+
// then where that is. A card waiting on the human stands out. A click shows
|
|
201
|
+
// its steps.
|
|
202
|
+
card(c, i, t) {
|
|
203
|
+
const color = c.waiting ? t.blocked : t.dim;
|
|
204
|
+
return v_flex().id(`card-${i}`).flex_none().px(8).py(4).gap(1).rounded(8)
|
|
205
|
+
.hover((el) => el.bg(t.hover))
|
|
206
|
+
.on_click((_e, cx) => this.pick(c.card, cx))
|
|
207
|
+
.child(h_flex().gap(8).items_center()
|
|
208
|
+
.child(div().flex_1().min_w(0).truncate().text_color(t.foreground).child(c.card ?? ""))
|
|
209
|
+
.child(div().flex_none().text_size(11.5).text_color(color).child(c.for ?? "")))
|
|
210
|
+
.child(div().text_size(11.5).text_color(c.waiting ? t.blocked : t.muted).whitespace_normal()
|
|
211
|
+
.child(c.state ?? ""));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// The way from a card chosen from the list back to the list.
|
|
215
|
+
back(t) {
|
|
216
|
+
return div().id("back").flex_none().px(8).py(4).rounded(8).text_size(11.5).text_color(t.dim)
|
|
217
|
+
.hover((el) => el.bg(t.hover))
|
|
218
|
+
.on_click((_e, cx) => this.pick(null, cx))
|
|
219
|
+
.child("‹ All cards");
|
|
220
|
+
}
|
|
221
|
+
|
|
161
222
|
// One hand-off, on one line: its clock, its label and the time alone. A
|
|
162
223
|
// click opens the rest of what the view says about it. `s` is a step of the
|
|
163
224
|
// view, and its kind says whether it is a wait.
|
|
@@ -189,32 +250,42 @@ export default class Steps extends View {
|
|
|
189
250
|
|
|
190
251
|
render() {
|
|
191
252
|
const t = theme();
|
|
253
|
+
const now = this.shown();
|
|
192
254
|
if (narrow()) return v_flex().size_full().bg(t.chrome);
|
|
193
255
|
const sample = checking();
|
|
194
|
-
const
|
|
256
|
+
const read = now.key === this.key;
|
|
195
257
|
const view = sample ? SAMPLE : this.view;
|
|
258
|
+
const list = sample ? SAMPLE_CARDS : this.view;
|
|
196
259
|
const note = (text, color) =>
|
|
197
260
|
div().px(8).py(6).text_size(12).text_color(color).whitespace_normal().child(text);
|
|
198
261
|
const items = [];
|
|
199
262
|
// The latest run only: a card written up twice keeps both in its log.
|
|
200
263
|
const steps = (view?.steps ?? []).filter((s) => s.run === view.run);
|
|
264
|
+
const cards = list?.cards ?? [];
|
|
201
265
|
const rows = () => {
|
|
202
266
|
// Where the card stands, as the view words it.
|
|
203
267
|
if (view.state) items.push(note(view.state, view.waiting ? t.blocked : t.dim));
|
|
204
268
|
steps.forEach((s, i) => items.push(this.row(s, i, t, sample || this.open === s.at)));
|
|
205
269
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
270
|
+
// A card chosen from the list always has the way back, even while it
|
|
271
|
+
// loads or when it could not be read.
|
|
272
|
+
if (sample || now.picked) items.push(this.back(t));
|
|
273
|
+
if (sample) {
|
|
274
|
+
cards.forEach((c, i) => items.push(this.card(c, i, t)));
|
|
275
|
+
rows();
|
|
276
|
+
} else if (!read) items.push(note("Loading…", t.dim));
|
|
209
277
|
else if (this.error) items.push(note(this.error, t.blocked));
|
|
210
278
|
else if (!this.project) items.push(note("This space is not an entourage project.", t.dim));
|
|
211
|
-
else if (
|
|
212
|
-
|
|
279
|
+
else if (now.card) {
|
|
280
|
+
if (steps.length === 0) items.push(note(`No hand-offs recorded for ${now.card} yet.`, t.dim));
|
|
281
|
+
else rows();
|
|
282
|
+
} else if (cards.length === 0) items.push(note("No hand-offs recorded in this project yet.", t.dim));
|
|
283
|
+
else cards.forEach((c, i) => items.push(this.card(c, i, t)));
|
|
213
284
|
return v_flex().size_full().min_h(0).bg(t.chrome).text_size(13)
|
|
214
285
|
.child(h_flex().h(31).flex_none().pl(16).pr(14).items_center().justify_between()
|
|
215
286
|
.text_size(11.5).text_color(t.dim)
|
|
216
287
|
.child("Steps")
|
|
217
|
-
.child(div().child(now.card ?? "")))
|
|
288
|
+
.child(div().child(now.card ?? (read ? this.project : null) ?? "")))
|
|
218
289
|
.child(v_flex().id("step-list").flex_1().min_h(0).px(8).pb(14)
|
|
219
290
|
.overflow_y_scrollbar().mode("always").children(items));
|
|
220
291
|
}
|
package/package.json
CHANGED