Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"name": "youtrack-task",
"description": "Create or pick up a JetBrains YouTrack issue from any repo: branch, move to In Progress, plan, ship a PR, and write everything back to the issue.",
"version": "0.20.0",
"version": "0.21.0",
"source": "./",
"author": {
"name": "Jeffry Wuermli"
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "youtrack-task",
"description": "Create or pick up a JetBrains YouTrack issue from any repo: branch, move to In Progress, plan, ship a PR, and write everything back to the issue.",
"version": "0.20.0",
"version": "0.21.0",
"author": {
"name": "Jeffry Wuermli"
},
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project are documented here. The format is based on
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.21.0 — 2026-11-22

- **The config file creates and maintains itself.** A `SessionStart` hook (`hooks/sync-config`)
runs once per plugin version, on the first Claude Code start after an install or update.
Without `~/.config/youtrack-task/config.toml` it creates the file from `config.example.toml`,
so you start from one file with every option. With one, it appends the options the new version
added (commented out, with their comment, placed before any `[table]` header so they still work when uncommented) and removes the ones it dropped, judged against a
snapshot of the previous example. Your own values, keys and comments are never touched, a
`config.toml.bak` is written before any change, and one line tells you what happened. An
unchanged version exits at once; `read-config` stays read-only. The first update after
adopting this removes nothing, because there is no earlier snapshot.
- `tests/sync-config.sh` covers create, no-op, add, prune, idempotence, backup, the
`[type_prefix]` block, the real example and the read-only case.

## 0.20.0 — 2026-11-22

- **Chat language follows the session, else the issue.** The skill now has a rule for what it
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ On pickup the plugin:
|:-:|------|--------|
| 🚀 | [Usage](docs/usage.md) | Pickup steps, flags, creating issues, parallel worktrees, sub-commands |
| 🤖 | [Batch (`all`)](docs/batch.md) | Triage, workers, review loop, `--auto-merge`, guard hook |
| ⚙️ | [Configuration](docs/configuration.md) | Config keys with defaults, extra reviewer commands, what lives where, MCP tools used |
| ⚙️ | [Configuration](docs/configuration.md) | Config keys with defaults, how the config file is created and kept up to date, extra reviewer commands, what lives where, MCP tools used |
| 🧩 | [Other agents](docs/other-agents.md) | Cursor, Copilot, Codex and the Agensi package: MCP setup and what differs |
| 🩺 | [Troubleshooting](docs/troubleshooting.md) | Symptoms and fixes, grouped by topic |

Expand Down
22 changes: 21 additions & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ youtrack-task/
│ └── marketplace.json # so `/plugin marketplace add JtheGunner/youtrack-task` works
├── .mcp.json # YouTrack HTTP MCP server, values from env vars
├── hooks/
│ ├── hooks.json # PreToolUse: YouTrack `create_issue`; Bash, Edit, Write, MultiEdit from `all` subagents (timeout 10 s)
│ ├── hooks.json # SessionStart (startup): sync-config; PreToolUse: YouTrack `create_issue`; Bash, Edit, Write, MultiEdit from `all` subagents (timeout 10 s)
│ ├── sync-config # once per plugin version: create config.toml from config.example.toml, or add new options (commented) and remove obsolete ones
│ ├── require-assignee # rejects a create_issue without Assignee (Claude Code only)
│ ├── guard-subagent # confines ticket-worker / ticket-reviewer (push, merge, read-only; worker file writes only inside its worktree)
│ └── require-review # opt-in (review_gate_hook): no push / gh pr create of an issue branch without a review stamp
Expand Down Expand Up @@ -596,6 +597,25 @@ the user.
`config.example.toml` in the repo is this block with every line commented and
dummy values — no real query, no real state names beyond YouTrack defaults.

**Keeping the file in step (`hooks/sync-config`).** A plugin `SessionStart` hook
(matcher `startup`) runs its work once per plugin version: the last synced version is
stamped in `${CLAUDE_PLUGIN_DATA}`, and an unchanged version exits at once, so normal
sessions are unaffected. On a new version (first install or an update):

| `config.toml` | The hook |
| --- | --- |
| missing | copies `config.example.toml` there |
| present | adds the example's options it lacks, commented out (`# key = default` with their comment) before the first active `[table]` header, since `read-config` ignores everything after it (the `[type_prefix]` table is appended as a block at the end when absent altogether), and removes options the example no longer has |

An option counts as present when it appears active or commented. Removal uses a
snapshot of the previous example kept next to the stamp: only options that snapshot
shipped are removed (the active and the commented line, plus the comment lines directly
above that match the snapshot). Your own keys and comments are never touched, and the
first run without a snapshot removes nothing. `config.toml.bak` is written before any
change, and the hook shows one line saying what it created, added or removed. It never
fails a session: when it cannot write it warns and leaves the stamp unset, so the next
session tries again. `read-config` stays read-only.

## Error handling

| Situation | Behavior |
Expand Down
7 changes: 4 additions & 3 deletions config.example.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# youtrack-task — optional configuration
#
# Copy to ~/.config/youtrack-task/config.toml and uncomment what you want to
# override. Every key is optional; the defaults below are what the skill uses if
# this file is absent.
# The plugin creates ~/.config/youtrack-task/config.toml from this file on first
# start and, after each update, adds new options (commented out) and removes
# obsolete ones. Uncomment what you want to override. Every key is optional; the
# defaults below are what the skill uses if the file is absent.
#
# The YouTrack URL and API token are NOT configured here — they are environment
# variables (YOUTRACK_MCP_URL, YOUTRACK_TOKEN) read by the bundled MCP server.
Expand Down
28 changes: 25 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ and `${YOUTRACK_TOKEN}`. Nothing instance-specific is stored in this repo.

## Config overrides

Optional and only needed if your workflow differs from the defaults. Copy
[`config.example.toml`](../config.example.toml) to
`~/.config/youtrack-task/config.toml` and uncomment what you need.
Optional and only needed if your workflow differs from the defaults. The plugin
creates `~/.config/youtrack-task/config.toml` for you from
[`config.example.toml`](../config.example.toml) (see
[Config file upkeep](#config-file-upkeep)); uncomment what you need.

> [!NOTE]
> Arrays such as `worktree_clone` must be written on a **single line**. A multi-line
Expand Down Expand Up @@ -93,6 +94,26 @@ ddev exec vendor/bin/pest
make verify
```

## Config file upkeep

The plugin keeps `~/.config/youtrack-task/config.toml` in step with
[`config.example.toml`](../config.example.toml), once per plugin version: the first
Claude Code start after you install or update it (a `SessionStart` hook,
`hooks/sync-config`). Sessions on an unchanged version are not affected.

| Your `config.toml` | What happens |
|--------------------|--------------|
| missing | It is created from the example, with every option and its comment, all commented out. |
| present, options added in the new version | They are added commented out (`# key = default`) with their comment, under a `# --- added by youtrack-task … ---` line. They go before your first `[table]` header, because options below a table header are not read. |
| present, options removed in the new version | Those options (active or commented) are removed, with the comment lines the plugin wrote above them. |

Options count as present when they appear active or commented, so a second run changes
nothing. Your own values, keys and comments are never touched. Before any change the
hook writes `config.toml.bak`, and it shows one line saying what it created, added or
removed. The first update after you adopt this feature removes nothing, because there
is no earlier example to compare against. If the config directory is not writable, the
hook warns and tries again next session.

## How config is resolved

`scripts/read-config` is step 0 of every invocation. It reads your `config.toml`,
Expand All @@ -110,6 +131,7 @@ read the file.
| 🔐 | YouTrack URL | `YOUTRACK_MCP_URL` env var | 🚫 |
| 🔐 | API token | `YOUTRACK_TOKEN` env var | 🚫 |
| 🔐 | Which project an issue is in | Encoded in the issue ID (`INFRA-42`) | 🚫 |
| ⚙️ | The config file itself: created, extended and pruned once per plugin version | `hooks/sync-config`, state in the plugin data dir | ✅ |
| ⚙️ | State names, list query, prefix map, branch-name and PR confirmation, superpowers / review / worktree settings | Defaults in the skill; overrides in `~/.config/youtrack-task/config.toml` | ✅ defaults only |
| ⚙️ | Extra reviewer commands (`reviewer_commands`; per project: `.youtrack-task/reviewer-commands`, read from the base branch) | `~/.config/youtrack-task/config.toml`; the project file in the repository | ✅ defaults only |
| ⚙️ | `all` settings (`batch_query`, `batch_max_parallel`, `batch_skip_tags`; review rounds via `review_rounds`) | Defaults in the skill; overrides in `~/.config/youtrack-task/config.toml` | ✅ defaults only |
Expand Down
1 change: 1 addition & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Find your symptom, apply the fix. Back to the [README](../README.md).
| "YouTrack MCP server isn't connected" | `YOUTRACK_MCP_URL` / `YOUTRACK_TOKEN` are not set in the shell that launched Claude Code, or your proxy blocks `/mcp`. Check `curl -H "Authorization: Bearer $YOUTRACK_TOKEN" "$YOUTRACK_MCP_URL"`. |
| MCP connects but writes fail with 403 | The token's user lacks permission on that project, or the token scope is wrong. |
| "There is no project named …" although the project exists | Fixed in 0.15.1: the skill searches by repo name first and, if needed, pages through *all* projects (the YouTrack MCP server returns only 20 per page) before claiming a project is missing. Update the plugin (`/plugin marketplace update youtrack-task`, then `/plugin update youtrack-task@youtrack-task`) and restart Claude Code. A project whose name differs from the repo name can always be named with `--project KEY`. |
| `config.toml` was not created or has no new options after an update | The sync runs once per plugin version at the start of a Claude Code session, so restart Claude Code after the update. A warning *"could not update …"* at the start means the config directory is not writable; fix that and start a new session, it tries again. Your previous file is kept as `config.toml.bak` whenever the sync changed something. |
| Scripts reported as missing (`SCRIPTS=missing`) | The skill was loaded without its `scripts/` directory, so it falls back to plain git in place. Install it as a plugin (or copy the whole skill directory) so `‹skill-dir›/scripts/read-config` exists. |
| Issues still come out in English although you write German | Almost always a stale plugin: third-party marketplaces don't auto-update. Run `/plugin marketplace update youtrack-task` then `/plugin update youtrack-task@youtrack-task`, restart Claude Code, and check the version under `/plugin`. Enable *Auto-update* for the marketplace in `/plugin` → Marketplaces to stop it recurring. If it persists, name the language in your input ("auf Deutsch"): an explicit instruction always wins. |

Expand Down
14 changes: 13 additions & 1 deletion hooks/hooks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"description": "Guards direct YouTrack create_issue calls (an Assignee must always be set, text in the user's language), confines the `all` sub-command's worker and reviewer subagents (no pushes or merges, read-only reviewer, worker file writes only inside its worktree), and — only when review_gate_hook is on — blocks pushing or opening a PR for an issue branch without a review stamp.",
"description": "Once per plugin version, creates ~/.config/youtrack-task/config.toml from config.example.toml or syncs it (adds new options commented out, removes obsolete ones). Guards direct YouTrack create_issue calls (an Assignee must always be set, text in the user's language), confines the `all` sub-command's worker and reviewer subagents (no pushes or merges, read-only reviewer, worker file writes only inside its worktree), and — only when review_gate_hook is on — blocks pushing or opening a PR for an issue branch without a review stamp.",
"hooks": {
"SessionStart": [
{
"matcher": "startup",
"hooks": [
{
"type": "command",
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/sync-config\"",
"timeout": 10
}
]
}
],
"PreToolUse": [
{
"matcher": "mcp__.*youtrack.*__create_issue",
Expand Down
172 changes: 172 additions & 0 deletions hooks/sync-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env bash
# SessionStart hook: keep the user's config.toml in step with config.example.toml.
#
# Runs its work once per plugin version: the last synced version is stamped in the
# plugin data dir, which survives updates. An unchanged version exits at once
# without touching anything, so the hook has no effect on normal sessions.
#
# On a new version (first install or an update):
# - config.toml missing -> copy config.example.toml there.
# - config.toml present -> append the example's options it lacks, commented out
# (`# key = default`, with their comment), and remove the
# options the example no longer has. An option counts as
# present when it appears active or commented. Removal is
# driven by a snapshot of the previous example, so only
# options this plugin once shipped are ever removed.
# Your own keys and comments are never touched. A backup
# (config.toml.bak) is written before any change.
#
# Best effort: it never fails a session. When it cannot write, it shows a warning
# and leaves the stamp unset so the next session tries again. Needs bash, sed, awk,
# cmp; no jq.
#
# Environment: CLAUDE_PLUGIN_ROOT, CLAUDE_PLUGIN_DATA (set by Claude Code),
# YOUTRACK_TASK_CONFIG (config path override, as in scripts/read-config).
set -u

ROOT="${CLAUDE_PLUGIN_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}"
DATA="${CLAUDE_PLUGIN_DATA:-${XDG_STATE_HOME:-$HOME/.local/state}/youtrack-task}"
CFG="${YOUTRACK_TASK_CONFIG:-$HOME/.config/youtrack-task/config.toml}"
EXAMPLE="$ROOT/config.example.toml"

version=$(sed -nE 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/p' "$ROOT/.claude-plugin/plugin.json" 2>/dev/null | head -1)
[ -n "$version" ] && [ -f "$EXAMPLE" ] || exit 0

STAMP="$DATA/config-synced-version"
SNAPSHOT="$DATA/config.example.snapshot"
[ "$(cat "$STAMP" 2>/dev/null)" = "$version" ] && exit 0

tmp=$(mktemp -d 2>/dev/null) || exit 0
trap 'rm -rf "$tmp"' EXIT

say() { # $1 = message ; shown to the user, never to the model's task
local m=${1//\\/\\\\}
m=${m//\"/\\\"}
printf '{"systemMessage":"youtrack-task: %s"}\n' "$m"
}

give_up() {
say "could not update $CFG ($1); will try again next session."
exit 0
}

# entries <file>: the options of a config file as a stream. Each option starts with
# "@@KEY <name>", followed by its comment lines and its own line. The [type_prefix]
# table is one option whose body runs to the next blank line.
entries() {
awk '
/^[[:space:]]*$/ { pending = ""; intable = 0; next }
intable { print; next }
/^#[[:space:]]*\[[a-z_]+\][[:space:]]*$/ {
key = $0; sub(/^#[[:space:]]*/, "", key); sub(/[[:space:]]*$/, "", key)
print "@@KEY " key; printf "%s", pending; print; pending = ""; intable = 1; next
}
/^#?[[:space:]]*[a-z_]+[[:space:]]*=/ {
key = $0; sub(/^#?[[:space:]]*/, "", key); sub(/[[:space:]]*=.*/, "", key)
print "@@KEY " key; printf "%s", pending; print; pending = ""; next
}
{ pending = pending $0 "\n" }
' "$1"
}

keys_of() { entries "$1" | sed -n 's/^@@KEY //p'; }

entry_text() { # $1 = file, $2 = key
entries "$1" | awk -v k="$2" '/^@@KEY /{ on = ($0 == "@@KEY " k); next } on'
}

is_present() { # $1 = file, $2 = key
case "$2" in
\[*) grep -Eq "^#?[[:space:]]*\\[${2#[}[[:space:]]*" "$1" ;;
*) grep -Eq "^#?[[:space:]]*$2[[:space:]]*=" "$1" ;;
esac
}

remove_key() { # $1 = file (rewritten in place), $2 = key, $3 = file with the key's old entry text
awk -v key="$2" -v entry="$3" '
BEGIN { while ((getline l < entry) > 0) T[++m] = l }
{ U[NR] = $0 }
END {
kre = "^#?[[:space:]]*" key "[[:space:]]*="
for (i = 1; i <= NR; i++) if (U[i] ~ kre) {
gone[i] = 1
j = i - 1; t = m - 1
while (t >= 1 && j >= 1 && !(j in gone) && U[j] == T[t]) { gone[j] = 1; j--; t-- }
}
for (i = 1; i <= NR; i++) if (!(i in gone)) print U[i]
}
' "$1" > "$1.out" && cat "$1.out" > "$1"
}

join() { local IFS=,; echo "$*" | sed 's/,/, /g'; }

created=""; added=(); removed=()

if [ ! -f "$CFG" ]; then
mkdir -p "$(dirname "$CFG")" 2>/dev/null && cp "$EXAMPLE" "$CFG" 2>/dev/null || give_up "cannot create it"
created=1
else
cp "$CFG" "$tmp/new" || give_up "cannot read it"

if [ -f "$SNAPSHOT" ]; then
keys_of "$EXAMPLE" | sort > "$tmp/current-keys"
while IFS= read -r key; do
case "$key" in \[*) continue ;; esac
grep -qxF -- "$key" "$tmp/current-keys" && continue
is_present "$tmp/new" "$key" || continue
entry_text "$SNAPSHOT" "$key" > "$tmp/entry"
remove_key "$tmp/new" "$key" "$tmp/entry" && removed+=("$key")
done < <(keys_of "$SNAPSHOT")
fi

top=""; tables=""
while IFS= read -r key; do
is_present "$tmp/new" "$key" && continue
text=$(entry_text "$EXAMPLE" "$key")
case "$key" in
\[*) tables="${tables}${text}"$'\n\n' ;;
*) top="${top}${text}"$'\n\n'; added+=("$key") ;;
esac
done < <(keys_of "$EXAMPLE")

marker="# --- added by youtrack-task $version (config sync) ---"

# Top-level options go before the first active [table] header: read-config ignores
# everything from there on, so an option appended after it would stop working the
# moment it is uncommented.
if [ -n "$top" ]; then
printf '%s\n%s' "$marker" "$top" > "$tmp/top"
if grep -Eq '^[[:space:]]*\[' "$tmp/new"; then
awk -v ins="$tmp/top" '
BEGIN { while ((getline l < ins) > 0) block = block l "\n" }
!done && /^[[:space:]]*\[/ { if (NR > 1 && prev != "") printf "\n"; printf "%s", block; done = 1 }
{ print; prev = $0 }
' "$tmp/new" > "$tmp/new.out" && cat "$tmp/new.out" > "$tmp/new"
else
[ -z "$(tail -c1 "$tmp/new")" ] || echo >> "$tmp/new"
{ echo; cat "$tmp/top"; } >> "$tmp/new"
fi
fi

if [ -n "$tables" ]; then
[ -z "$(tail -c1 "$tmp/new")" ] || echo >> "$tmp/new"
{ echo; echo "$marker"; printf '%s' "$tables"; } >> "$tmp/new"
fi

if ! cmp -s "$CFG" "$tmp/new"; then
cp "$CFG" "$CFG.bak" 2>/dev/null || give_up "cannot write a backup next to it"
cat "$tmp/new" > "$CFG" 2>/dev/null || give_up "cannot write it"
else
added=(); removed=()
fi
fi

mkdir -p "$DATA" 2>/dev/null && cp "$EXAMPLE" "$SNAPSHOT" 2>/dev/null && printf '%s\n' "$version" > "$STAMP" 2>/dev/null \
|| give_up "cannot write the sync state to $DATA"

parts=()
[ -n "$created" ] && parts+=("created $CFG with all options.")
[ "${#added[@]}" -gt 0 ] && parts+=("added new options to $CFG, commented out: $(join "${added[@]}").")
[ "${#removed[@]}" -gt 0 ] && parts+=("removed obsolete options from $CFG: $(join "${removed[@]}") (backup: $CFG.bak).")
[ "${#parts[@]}" -gt 0 ] && say "${parts[*]}"
exit 0
Loading
Loading