Skip to content

Commit 757b356

Browse files
authored
Merge pull request #220 from bashhack/agents-md
AGENTS.md and scripts/sesh-dev: work on sesh apart from an installed sesh
2 parents 6b8ccff + ff6dd53 commit 757b356

4 files changed

Lines changed: 241 additions & 8 deletions

File tree

‎AGENTS.md‎

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Working on sesh
2+
3+
For anyone changing sesh, person or coding agent. If you use sesh day to day
4+
as well, the first thing is keeping the sesh you use apart from the one you're
5+
working on.
6+
7+
## Two seshes: the one in use, and the one being built
8+
9+
- **The daily sesh** is an installed release (`brew install bashhack/sesh/sesh`,
10+
so `/opt/homebrew/bin/sesh`). Its vault, config, agent and Touch ID key are in
11+
the default places: `~/Library/Application Support/sesh/` (on Linux
12+
`~/.local/share/sesh/`), `~/.config/sesh/config.toml`, and the agent's socket
13+
under the user cache folder.
14+
- **The dev sesh** is this checkout, run with `scripts/sesh-dev`. It builds the
15+
working tree to `build/sesh-dev` and runs it on a vault, config and agent of
16+
its own, in `SESH_DEV_DIR` (an absolute path; default
17+
`~/.local/share/sesh-dev`):
18+
19+
```bash
20+
scripts/sesh-dev add password github --username alice
21+
scripts/sesh-dev ui
22+
```
23+
24+
Don't run a development build against the daily sesh's vault, config or agent.
25+
The two would also replace each other's agent on every switch (an agent from
26+
another build is replaced), so the daily sesh would keep asking to unlock.
27+
28+
### For coding agents
29+
30+
- **Use a throwaway folder for every run,** never the person's dev vault or the
31+
daily one, and give the master password in the environment, with a small key
32+
setting so it's quick:
33+
34+
```bash
35+
export SESH_DEV_DIR=$(mktemp -d) SESH_MASTER_PASSWORD=throwaway-test-1 SESH_KDF_MEMORY=19MiB
36+
printf 'pw\n' | scripts/sesh-dev add password demo --username me
37+
scripts/sesh-dev list
38+
```
39+
40+
`mktemp -d` gives a short enough path: an agent socket's path can be at most
41+
103 characters on macOS. Delete the folder when you're done.
42+
- **Don't touch:** the daily vault, `~/.config/sesh`, the running agent,
43+
`~/.aws`, or the person's tmux sessions. Use a separate tmux server
44+
(`tmux -L <name>`) to drive `sesh ui`.
45+
- **Don't copy:** these use the real clipboard: `sesh copy`, `--clip`,
46+
`add --generate` and `generate --copy` (they copy the new password),
47+
`history --clip`, and `sesh aws` while it signs in (it puts the MFA code
48+
there). In `sesh ui`: Enter and Ctrl-Y, the copy actions, the password
49+
generator, and saving a generated password. Read the code instead, or use
50+
`sesh get`.
51+
- **Don't run `sesh touchid enable` or `sesh browser install`** unless asked:
52+
the first makes a key in the Mac's secure chip, tied to the person's
53+
fingerprints; the second repoints their browsers (below). And don't accept
54+
`sesh sync init`'s offer of an iCloud Drive folder: iCloud copies it to the
55+
person's other computers.
56+
- Stop every agent and process you start (`scripts/sesh-dev agent stop`), and
57+
put a time limit on every test run, so nothing is left behind.
58+
59+
### What the two still share
60+
61+
- **The browser extension.** The browser starts whatever sesh the script in the
62+
daily data folder (`browser-host`) names, without `scripts/sesh-dev`'s
63+
settings, so it always runs on the daily vault and agent.
64+
`scripts/sesh-dev browser …` refuses for that reason; to try the extension
65+
against a dev build, try the build as the daily sesh (below).
66+
- **The agent's log**, `agent.log` in the user cache folder: both agents write
67+
to it.
68+
- **The clipboard**, and the AWS CLI's own files: `scripts/sesh-dev aws` uses
69+
the real `~/.aws`. For AWS work without AWS, see `scripts/README.md` (a mock
70+
AWS CLI).
71+
- **What the dev sesh starts** keeps its settings: in `sesh run`'s command,
72+
`sesh aws`'s shell and the notes editor, `SESH_DB_PATH`, `SESH_AUTH_SOCK`
73+
and `XDG_CONFIG_HOME` point at the dev folder, so a `sesh` run there uses
74+
the dev vault, and other programs (git, an editor) look for their config in
75+
it. The other way round, a `scripts/sesh-dev aws` run inside the daily
76+
sesh's AWS shell refuses ("already in a sesh environment"), except for a
77+
profile that signs in with `aws login` or SSO whose session has ended: the
78+
dev build signs it in again.
79+
- **`sesh init`:** it offers the default vault location, not the dev one;
80+
`scripts/sesh-dev init` gives it the dev vault's.
81+
82+
### Trying a dev build as the daily sesh
83+
84+
Rarely, a change needs trying for real before it's released:
85+
86+
```bash
87+
go build -o ~/go/bin/sesh ./sesh/cmd/sesh # a folder on PATH after Homebrew's
88+
brew unlink sesh && hash -r # now `sesh` is the dev build
89+
~/go/bin/sesh browser install # the extension too, if needed
90+
# … and back:
91+
rm ~/go/bin/sesh && brew link sesh && hash -r
92+
sesh browser install # the extension back to Homebrew's
93+
```
94+
95+
While it's unlinked, a `browser-host` script naming Homebrew's sesh points at
96+
nothing, so the extension only works after the `browser install` above.
97+
98+
## Building and testing
99+
100+
- Go 1.27+, and on macOS Xcode's command line tools: Touch ID and the screen
101+
lock check are built with cgo.
102+
- `go build ./...`, then test only the packages you changed while you work
103+
(`go test ./internal/tui/`). CI runs everything, and the race detector in
104+
three parts. It leaves Argon2id uninstrumented, for speed, which needs a Go
105+
experiment turned off too, or it reports false races:
106+
107+
```bash
108+
GOEXPERIMENT=nosizespecializedmalloc go test -race -gcflags='golang.org/x/crypto/argon2=-race=false' ./internal/...
109+
```
110+
111+
A plain `go test -race` works as well, more slowly.
112+
- `make dev/setup/hooks` installs the pre-commit hook: goimports and
113+
`go build ./...`, then go vet and golangci-lint on the packages a commit
114+
touches. `make audit` tidies, formats, vets, lints and tests everything, and
115+
rewrites files as it goes.
116+
- `make agent-smoke` runs the agent end to end.
117+
118+
## Changes
119+
120+
- **One pull request per change**, each on its own branch (a git worktree per
121+
branch keeps them apart). Each is reviewed before it's merged, and CI must
122+
pass.
123+
- **Commit messages are one line,** saying what the change does.
124+
- **Stage files by name,** not `git add -A`: a checkout can hold notes and
125+
scratch files that aren't meant for the repo.
126+
- **Comments and docs say how things are,** not how they came to be.
127+
`docs/USAGE_AND_CONFIGURATION.md`, `docs/SECURITY_MODEL.md` and
128+
`docs/ARCHITECTURE.md` are checked against the code; change them with it.
129+
130+
## Releasing
131+
132+
Tag `vX.Y.Z` on `main` and push the tag. The release job tests it again,
133+
builds, signs and notarizes the macOS binaries, publishes the GitHub release,
134+
and updates the Homebrew formula in `bashhack/homebrew-sesh`. A tag with
135+
`.github/release-notes/<tag>.md` is released with those notes; otherwise, with
136+
the commits since the last tag. Then `brew upgrade sesh` updates the daily sesh.

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,21 @@ make coverage
293293
make audit
294294
```
295295

296+
### Developing while using sesh every day
297+
298+
`scripts/sesh-dev` builds this checkout and runs it on a vault, config and
299+
agent of its own (in `~/.local/share/sesh-dev`), so an installed sesh and its
300+
vault are never touched:
301+
302+
```bash
303+
scripts/sesh-dev add password github --username alice
304+
scripts/sesh-dev ui
305+
```
306+
307+
[AGENTS.md](AGENTS.md) has the rest: what the two still share (the browser
308+
extension, the clipboard), trying a dev build as your everyday sesh, and the
309+
rules for coding agents working on sesh.
310+
296311
## License
297312

298313
MIT License - see [LICENSE](LICENSE) for details.

‎scripts/README.md‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
This directory contains utility scripts to help with local development and testing of the `sesh` CLI tool. These scripts allow you to test AWS and TOTP flows without needing real AWS credentials or actual TOTP-enabled services.
44

5-
**Use a scratch vault.** The flows below add entries to whatever vault sesh opens, so point it at a throwaway one first:
6-
7-
```bash
8-
export SESH_DB_PATH=/tmp/sesh-dev/passwords.db
9-
export SESH_AUTH_SOCK=/tmp/sesh-dev/agent.sock # an agent of its own: the agent holds one vault's key at a time
10-
```
11-
12-
Your config file (`~/.config/sesh/config.toml`) still applies.
5+
**Use a scratch vault.** The flows below add entries to whatever vault sesh opens, so run them through `sesh-dev` (below), which gives a build of this checkout a vault, config and agent of its own: `scripts/sesh-dev add totp …` in place of `sesh add totp …`.
136

147
**QR codes on screen** are read only on macOS (`--qr`). On Linux, save a screenshot of the code and give it with `--qr-image shot.png`.
158

169
## Scripts Overview
1710

11+
### 🧰 `sesh-dev`
12+
**Purpose**: Build this checkout's sesh and run it on a vault, config and agent of its own (`SESH_DEV_DIR`, default `~/.local/share/sesh-dev`), apart from the sesh you use every day.
13+
14+
```bash
15+
scripts/sesh-dev ui
16+
SESH_DEV_DIR=$(mktemp -d) SESH_MASTER_PASSWORD=throwaway scripts/sesh-dev list # a throwaway vault
17+
```
18+
19+
See [AGENTS.md](../AGENTS.md) for what it keeps apart, and what it doesn't.
20+
1821
### 🔐 `mock-totp-service.go`
1922
**Purpose**: Simulates an external TOTP service (like GitHub, Google, etc.) for testing the TOTP setup flow.
2023

‎scripts/sesh-dev‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
# sesh-dev builds this checkout's sesh and runs it on a vault, config and
3+
# agent of its own, so the sesh you use day to day (Homebrew's, say), its
4+
# vault, its settings and its agent are never touched.
5+
#
6+
# scripts/sesh-dev add password github --username alice
7+
# scripts/sesh-dev ui
8+
# SESH_DEV_DIR=$(mktemp -d) scripts/sesh-dev ... # a throwaway one
9+
#
10+
# Everything lives in SESH_DEV_DIR (default ~/.local/share/sesh-dev), which
11+
# must be an absolute path: the vault (passwords.db, with its backups and
12+
# touchid.key beside it), the config (config/sesh/config.toml) and the
13+
# agent's socket (agent.sock). The build is build/sesh-dev in this checkout,
14+
# rebuilt on every run (Go's cache makes an unchanged one quick); a changed
15+
# build replaces the agent.
16+
set -euo pipefail
17+
18+
repo=$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
19+
dir=${SESH_DEV_DIR:-$HOME/.local/share/sesh-dev}
20+
case "$dir" in
21+
/*) ;;
22+
*)
23+
# sesh ignores a config folder that isn't absolute, and would read the
24+
# daily config instead.
25+
echo "sesh-dev: SESH_DEV_DIR must be an absolute path, not $dir" >&2
26+
exit 2
27+
;;
28+
esac
29+
30+
# The command: the first word after any --db-path the arguments start with
31+
# (sesh takes it with any number of dashes). has_db_path: one is given anywhere.
32+
cmd="" skip="" has_db_path=""
33+
for a in "$@"; do
34+
case "$a" in
35+
-*db-path | -*db-path=*) has_db_path=1 ;;
36+
esac
37+
done
38+
for a in "$@"; do
39+
if [ -n "$skip" ]; then
40+
skip=""
41+
continue
42+
fi
43+
case "$a" in
44+
-*db-path) skip=1 ;;
45+
-*db-path=*) ;;
46+
*)
47+
cmd=$a
48+
break
49+
;;
50+
esac
51+
done
52+
53+
if [ "$cmd" = browser ]; then
54+
# The browser starts sesh by the path browser install writes, without
55+
# this script's settings: it would run the dev build on the daily vault
56+
# and agent.
57+
echo "sesh-dev: browser install would point your browsers at the dev build, run on your daily vault and agent. AGENTS.md (\"Trying a dev build as the daily sesh\") says how to try the extension against one." >&2
58+
exit 2
59+
fi
60+
61+
mkdir -p "$dir"
62+
chmod 700 "$dir"
63+
64+
bin="$repo/build/sesh-dev"
65+
(CDPATH='' cd -- "$repo" && go build -o "$bin" ./sesh/cmd/sesh)
66+
67+
# Where the daily sesh's things are, from the shell, isn't inherited: a
68+
# sync or backup folder set there would otherwise be this vault's too.
69+
unset SESH_BACKUP_DIR SESH_SYNC_DIR SESH_SYNC_NAME
70+
export SESH_DB_PATH="$dir/passwords.db"
71+
export SESH_AUTH_SOCK="$dir/agent.sock"
72+
export XDG_CONFIG_HOME="$dir/config"
73+
74+
# sesh init offers the default vault location, not SESH_DB_PATH: given the
75+
# dev vault's, it doesn't ask.
76+
if [ "$cmd" = init ] && [ -z "$has_db_path" ]; then
77+
set -- "$@" --db-path "$SESH_DB_PATH"
78+
fi
79+
exec "$bin" "$@"

0 commit comments

Comments
 (0)