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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- **`tooling/templates/persistent-agent-worktree-setup.md`**: Added a reusable prompt template for role-based Claude/Codex worktree setup with `AGENTS.md` as the single source of truth and thin `CLAUDE.md`/`.codex/agent.md` pointer files
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new changelog entry is a single very long line (likely >120 chars), which will trip markdownlint MD013 in this repo’s configuration. Please wrap it across multiple lines (e.g., break after the colon and indent continuation lines) to keep lint output clean.

Suggested change
- **`tooling/templates/persistent-agent-worktree-setup.md`**: Added a reusable prompt template for role-based Claude/Codex worktree setup with `AGENTS.md` as the single source of truth and thin `CLAUDE.md`/`.codex/agent.md` pointer files
- **`tooling/templates/persistent-agent-worktree-setup.md`**:
Added a reusable prompt template for role-based Claude/Codex worktree
setup with `AGENTS.md` as the single source of truth and thin
`CLAUDE.md`/`.codex/agent.md` pointer files

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog entry describes AGENTS.md as the single source of truth with thin CLAUDE.md pointers, but in this repository CLAUDE.md is the authoritative, auto-loaded instruction set and is explicitly human-maintained. Consider clarifying in the entry (and/or template) that this worktree setup is intended for other repos, or adjust the template so it doesn’t conflict with this repo’s established instruction model.

Suggested change
- **`tooling/templates/persistent-agent-worktree-setup.md`**: Added a reusable prompt template for role-based Claude/Codex worktree setup with `AGENTS.md` as the single source of truth and thin `CLAUDE.md`/`.codex/agent.md` pointer files
- **`tooling/templates/persistent-agent-worktree-setup.md`**: Added a reusable prompt template (for downstream repos) for role-based Claude/Codex worktree setup with `AGENTS.md` as the single source of truth and thin `CLAUDE.md`/`.codex/agent.md` pointer files; in this repository, `CLAUDE.md` remains the authoritative, auto-loaded instruction set

Copilot uses AI. Check for mistakes.

- **`qyl-continuation` plugin (1.0.0)**: Smart auto-continuation for Claude Code. Two-phase stop hook: heuristic pre-filter eliminates ~80% of unnecessary Haiku calls (questions, completion signals, addressed tool results, substantial text), Haiku judge handles the ambiguous ~20%. Throttled to max 3 continuations per 5-minute window. Based on double-shot-latte (MIT)
- **`code-simplifier` plugin (1.0.0)**: Code simplification agent tuned to qyl engineering principles. Replaces Anthropic's JS/React-centric code-simplifier with a language-agnostic version that reads CLAUDE.md for project standards. Measures elegance as problem-complexity / solution-complexity ratio. Zero suppression tolerance, compile-time over runtime, less code is better code. 1 Opus agent
- **`elegance-pipeline` plugin (1.0.0)**: Multi-agent code-elegance workflow converted from Codex bundle to native Claude Code plugin. 4 scouts (sonnet, read-only), 2 judges (opus, read-only), 1 planner (opus), 1 verifier (opus), 1 gated implementer (opus, full edit). Persistent state manager with stage gates and implementation signal. 3 commands (`init`, `status`, `run`), 1 skill, 5 agents. All `.codex/` paths rewritten to `${CLAUDE_PLUGIN_ROOT}`, Codex-Spark->sonnet, GPT-5.4->opus, state moved to project-local `.claude/elegance_pipeline/state/`
Expand Down
285 changes: 285 additions & 0 deletions tooling/templates/persistent-agent-worktree-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
# Persistent Multi-Agent Worktree Setup

You are setting up a persistent multi-agent worktree environment for Claude and Codex.

## Requirements

- Create 6 permanent worktrees under `.worktrees/`:
- `.worktrees/agent-collector`
- `.worktrees/agent-generator`
- `.worktrees/agent-schema`
- `.worktrees/agent-investigator`
- `.worktrees/agent-architect`
- `.worktrees/agent-gardener`
- Branch policy: each worktree is on `worktree/<worktree-name>`.
- AGENTS is authoritative for each worktree; `CLAUDE.md` and `.codex/agent.md` mirror the read-forward policy.
- Include verification commands in infrastructure files:
- `dotnet build`
- `dotnet test`
- Do not modify existing repository source code.
- Idempotent: safe to run multiple times.
- Fail fast on conflicts.

## Execution rules

- Use only `bash`, `git`, and filesystem operations.
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execution rules say “Use only bash, git, and filesystem operations”, but the script relies on awk for parsing git worktree list --porcelain. Either allow awk explicitly in the rules, or rewrite the parsing to pure bash/git so the template is self-consistent.

Suggested change
- Use only `bash`, `git`, and filesystem operations.
- Use only `bash`, `git`, `awk`, and filesystem operations.

Copilot uses AI. Check for mistakes.
- If a worktree path exists but is not a registered worktree, abort.
- If worktree path and branch are already correct, reuse and sync files.
- Do not run model-specific tooling. This is shell/git driven.

## Architecture constraints

- Layer 1: Schema generation
- `eng/build/SchemaGenerator.cs`
- Layer 2: Roslyn source generator
- `src/qyl.servicedefaults.generator/`
- Layer 3: Runtime instrumentation
- `src/qyl.servicedefaults/`
- `src/qyl.collector/`

Layers must never be conflated.

## Agent roles

`agent-collector`
- Role: OTLP collector maintainer
- Scope: `src/qyl.collector`
- Focus: OTLP ingestion, DuckDB batching, SSE streaming lifecycle
- Rules: minimal diffs; never modify generators or schema code
Comment on lines +32 to +48
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Architecture constraints” section references eng/build/SchemaGenerator.cs and src/qyl.* paths that do not exist in this repository. This makes the template inaccurate for users running it here; either generalize these constraints, or explicitly label this template as intended for a different repo layout and replace the paths with placeholders.

Suggested change
- Layer 1: Schema generation
- `eng/build/SchemaGenerator.cs`
- Layer 2: Roslyn source generator
- `src/qyl.servicedefaults.generator/`
- Layer 3: Runtime instrumentation
- `src/qyl.servicedefaults/`
- `src/qyl.collector/`
Layers must never be conflated.
## Agent roles
`agent-collector`
- Role: OTLP collector maintainer
- Scope: `src/qyl.collector`
- Focus: OTLP ingestion, DuckDB batching, SSE streaming lifecycle
- Rules: minimal diffs; never modify generators or schema code
This template assumes a three-layer architecture for telemetry-related code. Adapt the concrete paths and modules to match your repository layout.
- Layer 1: Schema generation (build-time schema tools)
- Layer 2: Source generator(s) (compile-time code generation)
- Layer 3: Runtime instrumentation and collector services
Layers must never be conflated: schema tools, generators, and runtime code live in separate modules or directories.
## Agent roles
`agent-collector`
`agent-collector`
- Role: OTLP collector maintainer
- Scope: Runtime collector / ingestion layer (e.g., your `collector` service or equivalent path)
- Focus: OTLP ingestion, batching/persistence, streaming lifecycle
- Rules: minimal diffs; never modify generator or schema layers

Copilot uses AI. Check for mistakes.
- Default model: Claude Sonnet 4.6 (`high`)

`agent-generator`
- Role: Roslyn pipeline maintainer
- Scope: `src/qyl.servicedefaults.generator`
- Focus: incremental pipeline behavior, generator correctness, compile-time interception design
- Rules: preserve pipeline isolation/design; never touch `SchemaGenerator.cs` unless explicitly required
- Default model: Claude Opus 4.6 (`max`)

`agent-schema`
- Role: schema generator maintainer
- Scope: `eng/build/SchemaGenerator.cs`
- Focus: OpenAPI to C# scalar/enum generation, DuckDB DDL emission
- Rules: preserve single-source-of-truth schema pipeline
- Default model: Claude Opus 4.6 (`max`)

`agent-investigator`
- Role: cross-layer debugging agent
- Allowed scope: generator, runtime, collector
- Tasks: incident investigation, telemetry tracing, root cause analysis, cross-layer fault isolation
- Default model: Claude Opus 4.6 (`max`)

`agent-architect`
- Role: repository architecture engineer
- Tasks: cross-module cleanup, architecture improvements, multi-file changes, cross-cutting concern reduction
- Default model: Claude Opus 4.6 (`max`)

`agent-gardener`
- Role: repository gardener
- Tasks: small correctness fixes, comment cleanup, verification improvements, documentation accuracy
- Default model: Claude Sonnet 4.6 (`high`)

## Required generated files per worktree

Create/refresh:
- `AGENTS.md`
- `CLAUDE.md`
- `.codex/agent.md`

`CLAUDE.md` content:
```text
Read and follow AGENTS.md in this worktree.
```

`.codex/agent.md` content:
```text
Read and follow AGENTS.md in this worktree.
```

## Script: `scripts/setup-worktrees.sh`

```bash
#!/usr/bin/env bash
set -euo pipefail

repo_root="$(git rev-parse --show-toplevel)"
worktrees_dir="$repo_root/.worktrees"

worktrees=(
agent-collector
agent-generator
agent-schema
agent-investigator
agent-architect
agent-gardener
)

role_contents_common='\
## Repository architecture constraints

Layer 1: Schema generation
- `eng/build/SchemaGenerator.cs`
- NUKE build emits models, enums, scalars, and DuckDB DDL

Layer 2: Roslyn source generator
- `src/qyl.servicedefaults.generator/`
- 7 incremental pipelines that emit compile-time interceptors

Layer 3: Runtime instrumentation
- `src/qyl.servicedefaults/`
- `src/qyl.collector/`

Layers must never be conflated.
'
Comment on lines +116 to +132
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

role_contents_common is assigned as a multi-line single-quoted string that begins with a literal \ character (role_contents_common='\ …). That leading backslash will be written into every generated AGENTS.md and appears unintentional; remove it or switch to a heredoc-style assignment to avoid stray characters.

Copilot uses AI. Check for mistakes.

get_agent_section() {
local role=$1

case "$role" in
agent-collector)
cat <<'EOF_AGENT'
## Role
- OTLP collector maintainer
- Scope: `src/qyl.collector`
- Focus: OTLP ingestion, DuckDB batching, SSE streaming lifecycle
- Rules: minimal diffs; never modify generators or schema code
- Default model: Claude Sonnet 4.6 (effort: high)
- Escalate to Opus max only for cross-layer investigation.
EOF_AGENT
;;
agent-generator)
cat <<'EOF_AGENT'
## Role
- Roslyn pipeline maintainer
- Scope: `src/qyl.servicedefaults.generator`
- Focus: incremental pipeline behavior, generator correctness, compile-time interception design
- Rules: maintain pipeline isolation; preserve incremental generator design; never touch `SchemaGenerator.cs` unless explicitly required
- Default model: Claude Opus 4.6 (effort: max)
EOF_AGENT
;;
agent-schema)
cat <<'EOF_AGENT'
## Role
- schema generator maintainer
- Scope: `eng/build/SchemaGenerator.cs`
- Focus: OpenAPI to C# scalar/enum generation and DuckDB DDL emission
- Rules: maintain single-source-of-truth schema pipeline
- Default model: Claude Opus 4.6 (effort: max)
EOF_AGENT
;;
agent-investigator)
cat <<'EOF_AGENT'
## Role
- cross-layer debugging agent
- Allowed scope: generator, runtime, collector
- Tasks: incident investigation, telemetry tracing, root cause analysis, cross-layer fault isolation
- Default model: Claude Opus 4.6 (effort: max)
EOF_AGENT
;;
agent-architect)
cat <<'EOF_AGENT'
## Role
- repository architecture engineer
- Tasks: cross-module cleanup, architecture improvements, multi-file changes, cross-cutting concern reduction
- Default model: Claude Opus 4.6 (effort: max)
EOF_AGENT
;;
agent-gardener)
cat <<'EOF_AGENT'
## Role
- repository gardener
- Tasks: small correctness fixes, comment cleanup, verification improvements, documentation accuracy
- Default model: Claude Sonnet 4.6 (effort: high)
EOF_AGENT
;;
*)
echo "Unknown role: $role" >&2
exit 1
;;
esac
}

write_common_files() {
local path=$1
local role=$2

cat > "$path/AGENTS.md" <<EOF_AGENTS
# AGENTS.md for $role

${role_contents_common}

$(get_agent_section "$role")

## Required verification
- dotnet build
- dotnet test
EOF_AGENTS

mkdir -p "$path/.codex"
printf 'Read and follow AGENTS.md in this worktree.\n' > "$path/CLAUDE.md"
printf 'Read and follow AGENTS.md in this worktree.\n' > "$path/.codex/agent.md"
}
Comment on lines +205 to +220
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script overwrites AGENTS.md and CLAUDE.md in each worktree with minimal content. In this repository, CLAUDE.md/AGENTS.md are human-maintained and contain critical operational instructions, so following this template here would erase them on the worktree/* branches; consider writing to repo-specific filenames (e.g., WORKTREE_AGENTS.md) or appending a role section instead of replacing the files.

Copilot uses AI. Check for mistakes.

is_registered_worktree() {
local target=$1
git worktree list --porcelain | awk -v target="$target" '
$1 == "worktree" {path = $2}
path == target {found = 1}
END {exit found ? 0 : 1}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The awk script uses the ternary operator ? :. This is a GNU awk (gawk) extension and is not portable to other awk implementations, such as the default one on macOS. To ensure the script runs correctly on different systems, it's best to use a standard if/else construct.

Suggested change
END {exit found ? 0 : 1}
END {if (found) exit 0; else exit 1}

'
}

mkdir -p "$worktrees_dir"
declare -A status

Comment on lines +231 to +233
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template script uses declare -A status, which requires Bash 4+. On macOS (default /bin/bash is often 3.2), this will fail even though the template targets generic “bash”; consider avoiding associative arrays or explicitly documenting the required bash version.

Copilot uses AI. Check for mistakes.
for name in "${worktrees[@]}"; do
path="$worktrees_dir/$name"
branch="worktree/$name"

if [[ -e "$path" ]]; then
if ! is_registered_worktree "$path"; then
echo "ERROR: path exists but is not a registered worktree: $path" >&2
exit 1
fi

existing_branch=$(git -C "$path" rev-parse --abbrev-ref HEAD)
if [[ "$existing_branch" != "$branch" ]]; then
echo "ERROR: path $path uses branch '$existing_branch', expected '$branch'" >&2
exit 1
fi

write_common_files "$path" "$name"
status["$name"]=reused
continue
fi

if ! git show-ref --verify --quiet "refs/heads/$branch"; then
git branch "$branch" HEAD
fi

if git worktree list --porcelain | awk -v branch="refs/heads/$branch" '
$1 == "branch" && $2 == branch {found = 1}
END {exit found ? 0 : 1}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the other awk command in this script, the use of the ternary operator ? : here is a non-portable GNU awk extension. It should be replaced with a standard if/else to ensure compatibility with other awk implementations.

Suggested change
END {exit found ? 0 : 1}
END {if (found) exit 0; else exit 1}

'; then
echo "ERROR: branch '$branch' already used by another worktree" >&2
exit 1
fi

git worktree add "$path" "$branch"
write_common_files "$path" "$name"
status["$name"]=created

done

echo "--- Worktree summary ---"
for name in "${worktrees[@]}"; do
path="$worktrees_dir/$name"
b=$(git -C "$path" rev-parse --abbrev-ref HEAD)
printf "%s | %s | %s\n" "$name" "${status[$name]}" "$path"
printf " AGENTS.md: %s\n" "$( [[ -f \"$path/AGENTS.md\" ]] && echo exists || echo missing )"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove escaped quotes in summary file checks

The file checks in the summary always evaluate to missing because " is used inside a command substitution that is already within double quotes, so the backslashes become part of the [[ -f ... ]] expression and the tested path includes literal quote characters. Running the generated setup-worktrees.sh shows AGENTS.md, CLAUDE.md, and .codex/agent.md as missing even when they were created, which breaks the script’s verification output and can cause false failure triage.

Useful? React with 👍 / 👎.

printf " CLAUDE.md: %s\n" "$( [[ -f \"$path/CLAUDE.md\" ]] && echo exists || echo missing )"
printf " .codex/agent.md: %s\n" "$( [[ -f \"$path/.codex/agent.md\" ]] && echo exists || echo missing )"
Comment on lines +278 to +280

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The file existence checks in the summary section are incorrect. The escaped quotes \" in [[ -f \"$path/...\" ]] cause the test to look for a file path that literally contains double quotes, which will always fail. This results in the script incorrectly reporting that files are missing even when they exist. The backslashes should be removed to correctly test the file paths.

Suggested change
printf " AGENTS.md: %s\n" "$( [[ -f \"$path/AGENTS.md\" ]] && echo exists || echo missing )"
printf " CLAUDE.md: %s\n" "$( [[ -f \"$path/CLAUDE.md\" ]] && echo exists || echo missing )"
printf " .codex/agent.md: %s\n" "$( [[ -f \"$path/.codex/agent.md\" ]] && echo exists || echo missing )"
printf " AGENTS.md: %s\n" "$( [[ -f \"$path/AGENTS.md\" ]] && echo exists || echo missing )"\n printf " CLAUDE.md: %s\n" "$( [[ -f \"$path/CLAUDE.md\" ]] && echo exists || echo missing )"\n printf " .codex/agent.md: %s\n" "$( [[ -f \"$path/.codex/agent.md\" ]] && echo exists || echo missing )"

echo " branch: $b"
done

printf "\nGit worktree list (worktrees only):\n"
git worktree list --porcelain | awk '$1 == "worktree" {print $2}'
Loading