@johngaynor/entourage 0.4.1-next.13 → 0.4.1-next.22

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
@@ -68,6 +68,18 @@ else. This needs `jq`; without it Claude Code asks once.
68
68
  A task is one piece of work in a project, usually a Linear card. You run two
69
69
  commands, in this order.
70
70
 
71
+ To see which cards there are first, `task ls` lists the open cards of the
72
+ project's Linear teams, under their statuses:
73
+
74
+ ```sh
75
+ entourage linear key # once: save your Linear API key
76
+ entourage project team my-project ABC # once: the team whose cards are ABC-122
77
+ entourage task ls my-project
78
+ ```
79
+
80
+ It asks Linear itself, with no agent running. See
81
+ [herdr/README.md](herdr/README.md#seeing-a-projects-cards) for the details.
82
+
71
83
  `task new` writes the card up. It opens a tab in the project's Herdr space and
72
84
  starts an agent there, which runs the three skills on the card and then asks
73
85
  you to approve it:
@@ -123,8 +135,7 @@ one at a time.
123
135
 
124
136
  ## Releasing
125
137
 
126
- Machines get changes from the npm registry, so a merged change is live only
127
- after a release:
138
+ A machine installed through npm gets changes only from a release:
128
139
 
129
140
  ```sh
130
141
  npm version patch # or minor / major; commits and tags vX.Y.Z
@@ -138,7 +149,7 @@ token to keep.
138
149
 
139
150
  Every push to `main` is published too, as a merge build under the npm tag
140
151
  `next` (`0.4.1-next.3`, for example). `entourage update` does not install
141
- those. To try one on a machine:
152
+ those. To try one on a machine installed through npm:
142
153
 
143
154
  ```sh
144
155
  ENTOURAGE_NPM_SPEC=@johngaynor/entourage@next entourage update
package/cli/entourage CHANGED
@@ -18,12 +18,15 @@ 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
27
  entourage task log <project> <card> [--json]
26
28
  list a card's hand-offs and how long each step took
29
+ entourage linear key save your Linear API key, so entourage can read Linear
27
30
  entourage help
28
31
 
29
32
  A project groups repos that belong together, with a PROJECT.md saying what
@@ -33,6 +36,14 @@ marks the project's folder as trusted in Claude Code's own file
33
36
  question. It needs jq; without it Claude Code asks once.
34
37
 
35
38
  A task is one piece of work in a project, usually a Linear card.
39
+ `task ls` lists the cards `task new` can be given: every card of the
40
+ project's Linear teams that is not done, cancelled or a duplicate, under its
41
+ status. It needs two things set once. `linear key` asks for a Linear API key
42
+ and saves it (make one in Linear, under Settings, Account, Security & access,
43
+ Personal API keys; Read permission is enough to list cards). `project team`
44
+ names the project's teams by their keys: ABC for the team whose cards are
45
+ ABC-122. A project can name several teams, and several projects can name the
46
+ same one. Linear is asked with curl and its answer read with jq.
36
47
  `task new` takes the card's ID, like ABC-122. It opens a tab in the project's
37
48
  Herdr space and starts an agent there, which writes the card up with the
38
49
  sdlc-define, sdlc-plan and sdlc-breakdown skills and asks you to approve it.
@@ -58,6 +69,14 @@ Skills are linked into ~/.claude/skills (CLAUDE_CONFIG_DIR picks another
58
69
  Your projects are in ~/.config/entourage/projects (ENTOURAGE_HOME picks
59
70
  another ~/.config/entourage). Hand-offs are recorded beside them, in
60
71
  entourage.db, with sqlite3 (ENTOURAGE_SQLITE picks another command).
72
+
73
+ These variables, and your Linear key as LINEAR_API_KEY, can be exported in
74
+ your shell or written as NAME=value lines in ~/.config/entourage/.env, which
75
+ `linear key` writes for you and only you can read. A variable you export wins
76
+ over its line in the file, unless it is empty; of two lines for a name, the
77
+ last is used. Herdr starts commands without your shell's exports, so what a
78
+ mod's run of entourage needs has to be in the file. ENTOURAGE_HOME is the one
79
+ variable the file cannot set.
61
80
  EOF
62
81
  }
63
82
 
@@ -73,6 +92,85 @@ while [ -L "$self" ]; do
73
92
  done
74
93
  REPO=$(cd -P "$(dirname "$self")/.." && pwd)
75
94
 
95
+ # The user's own things: their projects, and what entourage keeps for them.
96
+ # They live outside the repo so that they are never published and an npm
97
+ # reinstall does not delete them.
98
+ ENT_HOME=${ENTOURAGE_HOME:-$HOME/.config/entourage}
99
+
100
+ # entourage's own environment: NAME=value lines in this file, for the
101
+ # variables that would otherwise be exported in a shell. Herdr starts a
102
+ # command without a shell's exports, so a variable set only in a shell profile
103
+ # is missing when a mod runs entourage, and the file is where it is found.
104
+ ENV_FILE=$ENT_HOME/.env
105
+ # Whether the Linear key came with the environment, before the file is read.
106
+ KEY_EXPORTED=${LINEAR_API_KEY:+1}
107
+
108
+ # Take entourage's variables from the file. The file is read, never run: a
109
+ # line that is not NAME=value is skipped, and nothing in a value is expanded.
110
+ # What a line may hold:
111
+ # - export before the name, spaces around the =, one pair of quotes around
112
+ # the value, and a # comment after a value with no quotes;
113
+ # - of two lines for a name, the last one;
114
+ # - a variable already in the environment wins over the file, unless it is
115
+ # empty, which counts as not set.
116
+ # Only the variables entourage reads are taken: a line for PATH or anything
117
+ # else is skipped, and so is ENTOURAGE_HOME, which says where this file is.
118
+ # HERDR_APP_HOME and CLAUDE_CONFIG_DIR are exported, so a program entourage
119
+ # starts finds the same folders it does. The Linear key is not: only
120
+ # entourage reads it, and it hands it to curl on stdin.
121
+ load_env() {
122
+ local line name value from_file=' '
123
+ local re='^[[:space:]]*(export[[:space:]]+)?([A-Za-z_][A-Za-z0-9_]*)[[:space:]]*=[[:space:]]*(.*)$'
124
+ [ -f "$ENV_FILE" ] || return 0
125
+ # Stop rather than go on without the file: its settings would be missing,
126
+ # and `linear key` would write it anew with only the key in it.
127
+ [ -r "$ENV_FILE" ] || {
128
+ printf 'entourage: cannot read %s. It should be yours, and readable by you only: check its owner, then run: chmod 600 %s\n' \
129
+ "$ENV_FILE" "$ENV_FILE" >&2
130
+ exit 1
131
+ }
132
+ while IFS= read -r line || [ -n "$line" ]; do
133
+ line=${line%$'\r'}
134
+ # The mark some editors put at the start of a file.
135
+ line=${line#$'\357\273\277'}
136
+ [[ $line =~ $re ]] || continue
137
+ name=${BASH_REMATCH[2]} value=${BASH_REMATCH[3]}
138
+ case $name in
139
+ ENTOURAGE_HOME) continue ;;
140
+ ENTOURAGE_* | LINEAR_API_KEY | HERDR_APP_HOME | CLAUDE_CONFIG_DIR) ;;
141
+ *) continue ;;
142
+ esac
143
+ # A name the file has set already is set again; one that came with the
144
+ # environment is left as it is.
145
+ case $from_file in
146
+ *" $name "*) ;;
147
+ *) [ -z "${!name:-}" ] || continue ;;
148
+ esac
149
+ from_file="$from_file$name "
150
+ # A # after a space starts a comment, in a value with no quotes.
151
+ case $value in
152
+ \"* | \'*) ;;
153
+ \#*) value= ;;
154
+ *) value=${value%%[[:space:]]#*} ;;
155
+ esac
156
+ # Spaces after the value, then one pair of quotes around it.
157
+ value=${value%"${value##*[![:space:]]}"}
158
+ case $value in
159
+ \"*\") value=${value#\"}; value=${value%\"} ;;
160
+ \'*\') value=${value#\'}; value=${value%\'} ;;
161
+ esac
162
+ if [ "$name" = LINEAR_API_KEY ]; then
163
+ # Set for entourage alone. -n also covers a key that came exported but
164
+ # empty, so that no program entourage starts finds it either way.
165
+ LINEAR_API_KEY=$value
166
+ export -n LINEAR_API_KEY
167
+ else
168
+ export "$name=$value"
169
+ fi
170
+ done < "$ENV_FILE"
171
+ }
172
+ load_env
173
+
76
174
  APP_HOME=${HERDR_APP_HOME:-$HOME/.config/herdr-app}
77
175
  # Where Claude Code looks for a person's own skills.
78
176
  SKILLS_HOME=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills
@@ -84,9 +182,6 @@ HERDR_INSTALL='curl -fsSL https://releases.herdr.dev/app/install.sh | sh'
84
182
  # What `update` reinstalls when entourage came from npm rather than a git clone.
85
183
  NPM_SPEC=${ENTOURAGE_NPM_SPEC:-@johngaynor/entourage}
86
184
 
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
185
  PROJECTS=$ENT_HOME/projects
91
186
  TEMPLATE=$REPO/herdr/projects/template
92
187
  # A PROJECT.md that still has this line has not been filled in.
@@ -96,7 +191,7 @@ TEMPLATE_MARK='<!-- entourage:template -->'
96
191
 
97
192
  # Sourced, so every file shares the settings above and each other's functions.
98
193
  LIB=$REPO/cli/lib
99
- for part in common links recipes trust project task handoff commands; do
194
+ for part in common links recipes trust project linear task handoff commands; do
100
195
  [ -f "$LIB/$part.sh" ] ||
101
196
  { printf 'entourage: %s is missing; reinstall entourage\n' "$LIB/$part.sh" >&2; exit 1; }
102
197
  # shellcheck source=/dev/null
@@ -109,6 +204,7 @@ case ${1:-help} in
109
204
  status) shift; cmd_status "$@" ;;
110
205
  project) shift; cmd_project "$@" ;;
111
206
  task) shift; cmd_task "$@" ;;
207
+ linear) shift; cmd_linear "$@" ;;
112
208
  help | -h | --help) usage ;;
113
209
  *) usage >&2; exit 2 ;;
114
210
  esac
@@ -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
+ }
@@ -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
- *) die "usage: entourage project new|add|open|ls (see: entourage help)" ;;
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
@@ -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
 
@@ -291,6 +345,46 @@ setup:
291
345
  - **`just` has to be installed** on the machine. Without it, tasks start
292
346
  without setup and `entourage status` says so.
293
347
 
348
+ ## entourage's variables
349
+
350
+ entourage reads a few environment variables. Each can be exported in your
351
+ shell, or written as a `NAME=value` line in entourage's env file,
352
+ `~/.config/entourage/.env`.
353
+
354
+ | Variable | What it sets |
355
+ |---|---|
356
+ | `LINEAR_API_KEY` | Your Linear API key. `entourage linear key` writes this line for you. |
357
+ | `ENTOURAGE_AGENT` | The agent `task new` starts. `claude` when it is not set. |
358
+ | `ENTOURAGE_SQLITE` | The command that records hand-offs. `sqlite3` when it is not set. |
359
+ | `HERDR_APP_HOME` | Herdr's folder. `~/.config/herdr-app` when it is not set. |
360
+ | `CLAUDE_CONFIG_DIR` | Claude Code's folder, where skills are linked. `~/.claude` when it is not set. |
361
+ | `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. |
362
+
363
+ - **Use the file for anything a Herdr mod's run of entourage needs.** Herdr
364
+ starts a command without your shell's exports, so a variable set only in your
365
+ shell profile is missing there. The file is read every time, wherever
366
+ entourage is started from.
367
+ - **A variable you export wins** over its line in the file, unless it is
368
+ empty: an empty one counts as not set.
369
+ - **Of two lines for a name, the last is used**, so a line added at the end
370
+ takes over.
371
+ - **The file is read, never run.** A line that is not `NAME=value` is skipped,
372
+ and nothing in a value is expanded. These are allowed: `export` before the
373
+ name, spaces around the `=`, one pair of quotes around the value, and a `#`
374
+ comment after a value that has no quotes. Only entourage's own variables are
375
+ taken from it: the ones in the table, and any other whose name starts with
376
+ `ENTOURAGE_`. A line for anything else, such as `PATH`, is ignored.
377
+ - **The Linear key stays with entourage.** The other variables are passed on to
378
+ the programs entourage starts, so they find the same folders it does. The key
379
+ from the file is not: it reaches only `curl`, on its stdin.
380
+ - **Keep the file to yourself.** It holds your Linear key. `linear key` makes
381
+ it readable only by you; if you make it by hand, run
382
+ `chmod 600 ~/.config/entourage/.env`. A file entourage cannot read stops every
383
+ command, with a message saying so, rather than being skipped.
384
+ - **A linked env file is left alone.** If `.env` is a link, for example into a
385
+ dotfiles repo, `linear key` saves nothing and says so, so that the key does
386
+ not land in that repo. Add the `LINEAR_API_KEY` line yourself.
387
+
294
388
  ## Changing things
295
389
 
296
390
  - Work from a git clone, not the npm install: clone the repo and run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/entourage",
3
- "version": "0.4.1-next.13",
3
+ "version": "0.4.1-next.22",
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"