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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bump: minor
---
Recover tool calls that some models emit as inline XML text into structured tool calls, and add changeset-driven automatic versioning + npm publish on merge to master.
44 changes: 44 additions & 0 deletions .changes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changesets

This folder drives **automatic versioning + npm publishing**. When a commit lands on `master`
with one or more changeset files here, the [`release` workflow](../.github/workflows/release.yml)
bumps the version, publishes to npm, tags the release, and deletes the spent changesets.

**No changeset = no release.** Plain `docs:` / `chore:` commits don't publish anything.

## Add a changeset

```bash
npm run changeset minor "namespaced worker routes" # or: patch | major
```

…or just drop a file `.changes/anything.md`:

```markdown
---
bump: minor
---
Human-readable summary of the change. This line is prepended to CHANGELOG.md.
```

## Bump levels (standard semver, no 0.x special-casing)

| level | 0.1.0 → | when |
|---------|---------|------|
| `patch` | 0.1.1 | bug fix, no API/route change |
| `minor` | 0.2.0 | new feature, additive |
| `major` | 1.0.0 | breaking change (e.g. route/CLI/config that requires user action) |

If several changesets are present in one release, the **highest** level wins.

## What the release does

1. reads the highest `bump:` across all changesets here
2. `npm version <bump>` → regenerates `src/version.ts`
3. `npm run build && npm test` (gate)
4. `npm publish` (idempotent — skipped if that version is already on npm)
5. consumes (deletes) these changeset files, prepends their bodies to `CHANGELOG.md`
6. commits `release: vX.Y.Z` + tags `vX.Y.Z`, pushes back to `master`

The release commit is pushed with the default `GITHUB_TOKEN`, so it does **not** re-trigger the
workflow — no publish loop.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
- name: Typecheck + build
run: npm run build

- name: Check src/version.ts is in sync with package.json
run: |
node scripts/gen-version.mjs
git diff --exit-code src/version.ts \
|| (echo "::error::src/version.ts is stale — run 'node scripts/gen-version.mjs' and commit" && exit 1)

- name: Run tests
run: npm test

Expand Down
30 changes: 13 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Publish
name: Publish (manual break-glass)

# Publish to npm when a version tag is pushed, e.g. `git tag v0.0.1 && git push --tags`.
# Normal releases are automated by release.yml (changeset-driven, on push to master).
# This workflow is a manual fallback: trigger it from the Actions tab to build, test, and
# publish the CURRENT package.json version to npm — e.g. if an automated release half-failed.
on:
push:
tags:
- "v*"
workflow_dispatch:

jobs:
publish:
Expand All @@ -29,17 +29,13 @@ jobs:
npm run build
npm test

- name: Verify tag matches package.json version
run: |
PKG_VERSION="v$(node -p "require('./package.json').version")"
TAG="${GITHUB_REF_NAME}"
echo "package.json: $PKG_VERSION tag: $TAG"
if [ "$PKG_VERSION" != "$TAG" ]; then
echo "::error::Tag $TAG does not match package.json version $PKG_VERSION"
exit 1
fi

- name: Publish to npm
run: npm publish --access public
- name: Publish current version to npm (idempotent)
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
VERSION="$(node -p "require('./package.json').version")"
if npm view "copilot-reverse@$VERSION" version >/dev/null 2>&1; then
echo "copilot-reverse@$VERSION already on npm — nothing to do"
else
npm publish --access public
fi
115 changes: 115 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Release

# Auto-publish on merge to master, driven by changeset files in .changes/.
# No changeset present -> the `release` job is skipped -> nothing is published.
# The release commit/tag is pushed with the default GITHUB_TOKEN, which does NOT
# re-trigger workflows, so there is no publish loop.
on:
push:
branches: [master]

# Serialize releases; never cancel a half-finished publish.
concurrency:
group: release
cancel-in-progress: false

jobs:
detect:
runs-on: ubuntu-latest
outputs:
has: ${{ steps.status.outputs.has }}
bump: ${{ steps.status.outputs.bump }}
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 1 }
- uses: actions/setup-node@v4
with: { node-version: 22 }
- id: status
run: node scripts/changesets.mjs status --github-output

release:
needs: detect
if: ${{ needs.detect.outputs.has == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write # push the release commit + tag back to master
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true # keep GITHUB_TOKEN for the push

- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: "https://registry.npmjs.org"
cache: npm

- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Install dependencies
run: npm ci

- name: Bump version (no tag yet)
id: bump
run: |
NEW=$(npm version "${{ needs.detect.outputs.bump }}" --no-git-tag-version)
echo "version=${NEW#v}" >> "$GITHUB_OUTPUT"
echo "Bumped to $NEW"

- name: Regenerate src/version.ts
run: node scripts/gen-version.mjs

- name: Build + test (gate before publish)
run: |
npm run build
npm test

# Idempotent: if this version is already on npm (e.g. a prior run published but
# failed to push), skip publish so a re-run can still land the commit/tag.
- name: Publish to npm (idempotent)
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
VERSION="${{ steps.bump.outputs.version }}"
if npm view "copilot-reverse@$VERSION" version >/dev/null 2>&1; then
echo "copilot-reverse@$VERSION already on npm — skipping publish"
else
npm publish --access public
fi

- name: Update CHANGELOG + consume changesets
run: |
VERSION="${{ steps.bump.outputs.version }}"
DATE=$(date +%Y-%m-%d)
BODIES=$(node scripts/changesets.mjs bodies)
{
echo "## v$VERSION — $DATE"
echo ""
echo "$BODIES"
echo ""
if [ -f CHANGELOG.md ]; then cat CHANGELOG.md; fi
} > CHANGELOG.next.md
mv CHANGELOG.next.md CHANGELOG.md
node scripts/changesets.mjs consume

- name: Commit, tag, push (with rebase retry)
run: |
VERSION="${{ steps.bump.outputs.version }}"
git add package.json package-lock.json src/version.ts CHANGELOG.md
git add -A .changes
git commit -m "release: v$VERSION"
git tag "v$VERSION"
for i in 1 2 3; do
git pull --rebase origin master \
&& git push origin HEAD:master \
&& git push origin "v$VERSION" \
&& exit 0
echo "push attempt $i failed; retrying after rebase…"
sleep 3
done
echo "::error::failed to push release after 3 attempts"
exit 1
34 changes: 34 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# CLAUDE.md

Guidance for Claude Code when working in this repo.

## Workflow: prefer git worktrees

**For any new feature or bug fix, work in a dedicated git worktree — do not commit directly on `master`.**

- At the start of a feature/bugfix task, create a worktree (use the `EnterWorktree` tool, or `git worktree add`) and do all work there on a new branch.
- Keep `master` clean; open a PR from the worktree branch to merge.
- Small, single-file edits, docs-only tweaks, or quick investigations don't need a worktree — use judgment.
- When the work is merged or abandoned, remove the worktree.

## Commit hygiene

- Stage by explicit path (`git add <path>`). **Never** `git add -A` / `git add .` — the tree is shared and may hold unrelated changes.
- Create new commits; don't amend published ones.

## Dev essentials

Requires Node >=20.

- Install / verify: `npm install && npm test && npm run build`
- Run the app locally: `npm run dev` (tsx on `src/`, no build needed)
- Tests: `npm test` (vitest, includes e2e) · `npm run test:e2e` (e2e only)
- **Every change must keep the full e2e suite green.** After a change, re-run and update [`e2e/RESULTS.md`](e2e/RESULTS.md). Case catalog: [`e2e/cases.md`](e2e/cases.md).

## Architecture (3 processes, one terminal app)

- **TUI** (Ink) — the `copilot-reverse` process: REPL + slash commands + a claude-agent-sdk assistant.
- **Supervisor** (:7890) — control API + SQLite + self-healing worker supervision.
- **Worker** (:7891) — OpenAI `/openai/chat/completions` + Anthropic `/anthropic/v1/messages` → Copilot, with tool-use translation both ways.

Data dir: `~/.copilot-reverse`.
5 changes: 5 additions & 0 deletions e2e/RESULTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Latest run of the end-to-end suite. Regenerate after every code change with `npm run test:e2e`
and update this file (paste the summary).

- **2026-06-23** — Added `ToolCallExtractor` (recovers text-emitted `<function_calls>`/`<invoke>`
tool calls into structured tool chunks) plus changeset-driven auto-release (build-time version
injection, release workflow). Full suite green: `npm test` → **236 passed** (47 files), e2e all
green, tsc build clean.

- **Date:** 2026-06-22 22:14 CST
- **Runner:** vitest 2.1.9 · Node v25.6.0
- **Command:** `npm run test:e2e`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
"llm"
],
"scripts": {
"prebuild": "node scripts/gen-version.mjs",
"build": "tsc -p tsconfig.json",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:e2e": "vitest run e2e/copilot-reverse.e2e.test.ts tests/e2e",
"test:integration": "vitest run --config vitest.integration.config.ts",
"dev": "tsx src/cli/index.ts",
"changeset": "node scripts/changesets.mjs new",
"prepublishOnly": "npm run build && npm run test"
},
"engines": {
Expand Down
73 changes: 73 additions & 0 deletions scripts/changesets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Lightweight changeset engine (no @changesets/cli dependency — overkill for a single-package repo).
//
// A "changeset" is any .md file in .changes/ (except README.md) carrying a bump level:
//
// ---
// bump: minor # patch | minor | major
// ---
// Human-readable summary of the change (goes into CHANGELOG.md).
//
// The release workflow reads `status` to decide whether (and how much) to bump, publishes,
// then calls `consume` to delete the spent changesets. Developers scaffold one with `new`.
import { readdirSync, readFileSync, writeFileSync, rmSync, existsSync, mkdirSync, appendFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const DIR = join(root, ".changes");
const BUMP_ORDER = { patch: 1, minor: 2, major: 3 };
const BUMP_RE = /^bump:\s*(patch|minor|major)\s*$/im;

// Strips an optional leading `--- ... ---` front-matter fence, returning the prose body.
function stripFrontMatter(text) {
const m = text.match(/^---\n[\s\S]*?\n---\n?/);
return (m ? text.slice(m[0].length) : text).trim();
}

// Every non-README .md in .changes/ is a changeset. A missing/invalid bump line is a hard error —
// a typo'd level must fail loudly, not silently skip a release.
function active() {
if (!existsSync(DIR)) return [];
const out = [];
for (const f of readdirSync(DIR)) {
if (!f.endsWith(".md") || f === "README.md") continue;
const full = join(DIR, f);
const text = readFileSync(full, "utf8");
const m = text.match(BUMP_RE);
if (!m) throw new Error(`changeset ${f} has no valid "bump: patch|minor|major" line`);
out.push({ file: full, name: f, bump: m[1].toLowerCase(), body: stripFrontMatter(text.replace(/^---\n[\s\S]*?\n---\n?/, "")) });
}
return out;
}

const highest = (list) => list.reduce((hi, x) => (BUMP_ORDER[x.bump] > BUMP_ORDER[hi] ? x.bump : hi), "patch");

const cmd = process.argv[2];

if (cmd === "status") {
const list = active();
const result = { hasChangeset: list.length > 0, bump: list.length ? highest(list) : null, files: list.map((x) => x.name), bodies: list.map((x) => x.body) };
console.log(JSON.stringify(result, null, 2));
if (process.argv.includes("--github-output") && process.env.GITHUB_OUTPUT) {
appendFileSync(process.env.GITHUB_OUTPUT, `has=${result.hasChangeset}\nbump=${result.bump ?? ""}\n`);
}
} else if (cmd === "bodies") {
// Print just the changeset bodies (used by the release workflow to build CHANGELOG entries).
console.log(active().map((x) => x.body).filter(Boolean).join("\n\n"));
} else if (cmd === "consume") {
const list = active();
for (const x of list) rmSync(x.file);
console.log(`consumed ${list.length} changeset(s)`);
} else if (cmd === "new") {
const bump = process.argv[3];
if (!BUMP_ORDER[bump]) { console.error("usage: changesets.mjs new <patch|minor|major> [slug...]"); process.exit(1); }
const slug = process.argv.slice(4).join("-").replace(/[^a-z0-9-]/gi, "-").toLowerCase() || "change";
// No Date.now() name collisions in practice; if two land the same ms, the second just overwrites — fine for a scaffold.
if (!existsSync(DIR)) mkdirSync(DIR, { recursive: true });
const file = join(DIR, `${Date.now()}-${slug}.md`);
writeFileSync(file, `---\nbump: ${bump}\n---\nDescribe the change here (this line lands in CHANGELOG.md).\n`);
console.log(`created ${file}`);
} else {
console.error("usage: changesets.mjs <status|bodies|consume|new>");
process.exit(1);
}
20 changes: 20 additions & 0 deletions scripts/gen-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Generates src/version.ts from package.json — the single source of truth for the app version.
// Run automatically via the `prebuild` npm hook, and by the release workflow after bumping.
// CLI code can't `import "../package.json"` because rootDir is "src" (it's outside), so we
// materialize the version as an in-tree module instead. Writes only when the content changes,
// so repeated builds don't churn git.
import { readFileSync, writeFileSync, existsSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const version = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).version;
const out = `// AUTO-GENERATED by scripts/gen-version.mjs from package.json — do not edit.\nexport const APP_VERSION = ${JSON.stringify(version)};\n`;

const target = join(root, "src", "version.ts");
if (!existsSync(target) || readFileSync(target, "utf8") !== out) {
writeFileSync(target, out);
console.log(`gen-version: wrote src/version.ts (APP_VERSION=${version})`);
} else {
console.log(`gen-version: src/version.ts already up to date (APP_VERSION=${version})`);
}
Loading
Loading