feat(setup): store credentials in shared netrc, migrate legacy env vars

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Murphy Freelance
2026-07-10 19:27:48 +02:00
parent ec853559af
commit 6525f60f86

View File

@@ -1,60 +1,62 @@
--- ---
name: setup name: setup
description: Use when configuring the Jira API credentials for gw-triage — first-time setup, an "allegato saltato" warning from triage, missing or expired JIRA_EMAIL/JIRA_API_TOKEN, or replacing a revoked token. Triggers on /gw-triage:setup, "configura il token", "gli allegati non funzionano". description: Use when configuring the Jira API credentials for gw-triage — first-time setup, an "allegato saltato" warning from triage, missing or expired credentials, or replacing a revoked token. Triggers on /gw-triage:setup, $setup, "configura il token", "gli allegati non funzionano".
--- ---
# Setup — token API Jira guidato # Setup — token API Jira guidato
You guide the user through creating a Jira API token and storing it so You guide the user through creating a Jira API token and storing it in
the `triage` skill can attach screenshots to issues. the gw-triage netrc file. The `triage` skill reads that file for its
REST calls: screenshot attachments on every platform, plus search /
create / comment when running under Codex.
**All interaction with the user happens in Italian.** This file is **All interaction with the user happens in Italian.** This file is
English for precision; never quote it to the user. English for precision; never quote it to the user.
The only consumer of the token is the `triage` skill (its curl ## Environment
attachment call), which runs inside Claude Code. Credentials therefore
go in the `env` block of `~/.claude/settings.json` — Claude Code - **Root**: `${CLAUDE_PLUGIN_ROOT}` if that variable is set; otherwise
injects them into every session, regardless of the user's shell. Never the real path of this skill's own directory (resolve symlinks, e.g.
touch shell profiles. with `realpath`), two levels up.
- **Store**: `~/.config/gw-triage/netrc`, mode 600. curl reads it at
call time on every platform, so changes take effect immediately — no
session restart, no shell configuration.
- **Host**: the `site` value in `<root>/config/routing.json` without
the scheme (e.g. `growingway.atlassian.net`).
**Keep the token out of replies and displayed commands.** Refer to it **Keep the token out of replies and displayed commands.** Refer to it
as "il token" and never repeat its value. Never inline a literal token as "il token" and never repeat its value. Never inline a literal token
on a shell command line — it ends up in the transcript and the process on a shell command line — it ends up in the transcript and the process
list. Shell variables may be passed as unexpanded `$VAR` references; list. Write credentials into the netrc file with the file-writing
literal values (pasted or read from a file) go through the temp netrc tool, then let curl read them via `--netrc-file`.
file described in Step 0.3.
The verification call used throughout:
curl -s -o /dev/null -w "%{http_code}" \
--netrc-file ~/.config/gw-triage/netrc \
https://<host>/rest/api/2/myself
## Step 0 — Check existing configuration ## Step 0 — Check existing configuration
1. Run `test -n "$JIRA_EMAIL" && test -n "$JIRA_API_TOKEN" && echo session || echo unset`. 1. If `~/.config/gw-triage/netrc` exists and is readable, run the
2. Read `~/.claude/settings.json` (if it exists) and note whether verification call.
`env.JIRA_EMAIL` / `env.JIRA_API_TOKEN` are present.
3. If credentials exist in either place, verify them. The check call is
curl -s -o /dev/null -w "%{http_code}" \
<credentials> \
https://growingway.atlassian.net/rest/api/3/myself
(host = the `site` in `${CLAUDE_PLUGIN_ROOT}/config/routing.json`,
without the scheme). For `<credentials>`:
- session env vars set → `-u "$JIRA_EMAIL:$JIRA_API_TOKEN"`, with the
`$` references left unexpanded for the shell to fill in — never
substitute the values yourself.
- literal values (from settings.json or a paste) → use the Write
tool to create a netrc file in the session scratchpad directory:
machine growingway.atlassian.net
login <email>
password <token>
`chmod 600` it and pass `--netrc-file <path>` instead of `-u`.
Delete this file before the skill ends, whatever the outcome.
Result:
- `200` → tell the user (Italian) the token already works and ask - `200` → tell the user (Italian) the token already works and ask
whether they want to replace it anyway. If not, stop. whether they want to replace it anyway. If not, stop.
- anything else → tell them the stored token no longer works - anything else → tell them the stored token no longer works
(probably expired or revoked) and continue. (probably expired or revoked) and continue to Step 1.
2. Otherwise look for legacy credentials, in order:
- session env: `test -n "$JIRA_EMAIL" && test -n "$JIRA_API_TOKEN" && echo session || echo unset`
- `~/.claude/settings.json` (if it exists): `env.JIRA_EMAIL` /
`env.JIRA_API_TOKEN`.
If found in either place: write them to the netrc (Step 2 format,
chmod 600) and run the verification call.
- `200` → tell the user (Italian) the existing credentials were
migrated to the new store and work immediately; then do Step 3
(clean up legacy stores) and Step 4. Done — skip token creation.
- anything else → delete the netrc just written, tell them the old
token no longer works, continue to Step 1.
3. Nothing found → first-time setup, continue to Step 1.
## Step 1 — Token creation (user, in the browser) ## Step 1 — Token creation (user, in the browser)
@@ -67,52 +69,53 @@ Print in Italian, compactly:
3. Incolla qui email aziendale e token (vanno bene anche su due righe). 3. Incolla qui email aziendale e token (vanno bene anche su due righe).
Add one line: il token verrà salvato in chiaro in Add one line: il token verrà salvato in chiaro in
`~/.claude/settings.json` sul suo computer, quindi non condividere né il `~/.config/gw-triage/netrc` sul suo computer, quindi non condividere né
file né questa conversazione. il file né questa conversazione.
End the turn and wait. If the reply contains only one of the two End the turn and wait. If the reply contains only one of the two
values, ask for the missing one. If the user can't create the token values, ask for the missing one. If the user can't create the token
(no permission, page unreachable), stop and suggest asking whoever (no permission, page unreachable), stop and suggest asking whoever
manages the Atlassian accounts. manages the Atlassian accounts.
## Step 2 — Verify before saving ## Step 2 — Save, then verify
Run the Step 0.3 check with the pasted values — literals, so via the 1. Create `~/.config/gw-triage/` if missing. Write the netrc file with
temp netrc file, never `-u` on the command line. the file-writing tool:
- `200` → proceed to Step 3. machine <host>
- `401`/`403` → wrong email or token (a common cause: copied with a login <email>
trailing space or truncated). Ask the user to re-copy and re-paste, password <token>
then verify again; stop after the third failed verification overall
and suggest creating a fresh token.
- Anything else (timeout, DNS) → network problem, not credentials:
report it and stop; the pasted token stays valid for a later retry.
## Step 3 — Save to settings.json Then `chmod 600 ~/.config/gw-triage/netrc`.
2. Run the verification call.
- `200` → Step 3.
- `401`/`403` → wrong email or token (a common cause: copied with a
trailing space or truncated). Ask the user to re-copy and
re-paste, rewrite the file, verify again; after the third failed
verification overall, delete the netrc file, stop, and suggest
creating a fresh token.
- Anything else (timeout, DNS) → network problem, not credentials:
report it and stop. Leave the netrc in place — it may verify fine
later.
Update `~/.claude/settings.json` with Read + Edit/Write (never shell ## Step 3 — Clean up legacy stores
text-mangling):
- File missing → create it containing only 1. `~/.claude/settings.json`: if it exists and has `env.JIRA_EMAIL` /
`{"env": {"JIRA_EMAIL": "<email>", "JIRA_API_TOKEN": "<token>"}}`. `env.JIRA_API_TOKEN`, offer (Italian) to remove those two keys —
- Valid JSON → add or overwrite the two keys inside the existing `env` with the file tools (Read + Edit), never shell text-mangling, and
object (create the object if absent). Preserve every other key preserving every other key. If the file is invalid JSON, don't
untouched. touch it; just tell the user it should be cleaned up by hand.
- Invalid JSON → do NOT overwrite; show the user the parse error and 2. Shell profiles: run
stop. `fish -c 'set -U' 2>/dev/null | grep -i jira` and
`grep -l JIRA_API_TOKEN ~/.config/fish/config.fish ~/.config/fish/conf.d/*.fish ~/.zshrc ~/.bashrc ~/.zprofile ~/.profile 2>/dev/null`.
Leftover check: old installs configured the shell profile instead. Run If anything turns up, tell the user (Italian) to remove it so it
`fish -c 'set -U' 2>/dev/null | grep -i jira` and can't shadow the netrc (fish: `set -e JIRA_EMAIL; set -e
`grep -l JIRA_API_TOKEN ~/.config/fish/config.fish ~/.config/fish/conf.d/*.fish ~/.zshrc ~/.bashrc ~/.zprofile ~/.profile 2>/dev/null`. JIRA_API_TOKEN`; altrimenti togliere gli `export` dal file
If anything turns up, tell the user (Italian) to remove it so it can't indicato).
shadow the new token (fish: `set -e JIRA_EMAIL; set -e JIRA_API_TOKEN`;
altrimenti togliere gli `export` dal file indicato).
## Step 4 — Report ## Step 4 — Report
Delete the temp netrc file if one was created. In Italian: token verificato e salvato in `~/.config/gw-triage/netrc`.
Vale da subito, anche nelle sessioni già aperte. Per sostituirlo o dopo
In Italian: token verificato e salvato. Vale dalle **prossime** sessioni una revoca basta rilanciare il setup: `/gw-triage:setup` su Claude
di Claude Code — quelle già aperte vanno riavviate prima che l'allegato Code, `$setup` su Codex.
automatico funzioni. Per sostituirlo o dopo una revoca basta rilanciare
`/gw-triage:setup`.