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 @@ -10,7 +10,7 @@
"plugins": [
{
"name": "genie",
"version": "5.260803.3",
"version": "5.260803.6",
"source": "./plugins/genie",
"description": "Human-AI partnership for Claude Code. Share a terminal, orchestrate workers, evolve together. Brainstorm ideas, wish them into plans, make with parallel agents, ship as one team. A coding genie that grows with your project."
}
Expand Down
28 changes: 14 additions & 14 deletions .genie/wishes/lifecycle-lease-busy-grace/WISH.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| Field | Value |
|-------|-------|
| **Status** | IN_PROGRESS |
| **Status** | SHIPPED |
| **Slug** | `lifecycle-lease-busy-grace` |
| **Date** | 2026-08-02 |
| **Author** | Felipe Rosa + Genie |
Expand Down Expand Up @@ -99,12 +99,12 @@ Group 2 depends on Group 1; one worker running the wave sequentially is acceptab
7. Update the "ONE protocol, two acquirers" doc comment (`agent-sync.ts:6211-6229`) to record the deliberate one-sided divergence: TS steals fresh same-host dead locks; install.sh's `recover_stale_lifecycle_lock` (`install.sh:245-274`) remains staleness-gated. Note that `acquireRetirementLock` (`:3018`) inherits the early steal via `acquireFileLock` (benign — cross-host retirement refusal unchanged).

**Acceptance Criteria:**
- [ ] No `throw new Error(\`Another Genie lifecycle command is active…\`)` remains anywhere in `src/genie-commands/`.
- [ ] Busy messages contain the lock path and no "(the holder converges the same targets)"; no stack trace reaches the terminal.
- [ ] No `codex-lifecycle-busy` or `INSTALL_ACTION_REQUIRED` trailer is emitted for an agent-sync holder.
- [ ] Borrow-mismatch (`LIFECYCLE_LEASE_PATH_ENV` set but stale/mismatched) fails without a single retry sleep.
- [ ] Same-host dead-holder steal detects pid-reuse via start-identity (a reused pid is judged dead and stolen) and never steals cross-host or unknown-host records.
- [ ] `setup`'s busy message no longer contains the false phrase (inherited from the source fix; `setup.test.ts:1152`'s `toContain('holds the lock')` still passes).
- [x] No `throw new Error(\`Another Genie lifecycle command is active…\`)` remains anywhere in `src/genie-commands/`.
- [x] Busy messages contain the lock path and no "(the holder converges the same targets)"; no stack trace reaches the terminal.
- [x] No `codex-lifecycle-busy` or `INSTALL_ACTION_REQUIRED` trailer is emitted for an agent-sync holder.
- [x] Borrow-mismatch (`LIFECYCLE_LEASE_PATH_ENV` set but stale/mismatched) fails without a single retry sleep.
- [x] Same-host dead-holder steal detects pid-reuse via start-identity (a reused pid is judged dead and stolen) and never steals cross-host or unknown-host records.
- [x] `setup`'s busy message no longer contains the false phrase (inherited from the source fix; `setup.test.ts:1152`'s `toContain('holds the lock')` still passes).

**Validation:**
```bash
Expand All @@ -126,9 +126,9 @@ bun run typecheck && bun test src/lib/agent-sync.test.ts src/genie-commands/__te
4. All waits driven by `GENIE_LIFECYCLE_LEASE_WAIT_MS` at millisecond scale — no test slower than ~1s.

**Acceptance Criteria:**
- [ ] Reverting any Group 1 projection or the steal reorder makes at least one new test fail.
- [ ] Existing agent-sync report-wording tests pass unmodified.
- [ ] `tests/integration/install-exit2-propagation.test.ts` passes unmodified.
- [x] Reverting any Group 1 projection or the steal reorder makes at least one new test fail.
- [x] Existing agent-sync report-wording tests pass unmodified.
- [x] `tests/integration/install-exit2-propagation.test.ts` passes unmodified.

**Validation:**
```bash
Expand All @@ -141,10 +141,10 @@ bun run check

## QA Criteria

- [ ] Functional: with a second terminal holding the lease (paused `genie install`), `genie update` waits, then either completes (holder finished) or prints one clean line with the lock path and exits 2 — no Bun stack trace.
- [ ] Functional: kill -9 a lease-holding command, immediately run `genie update` → it steals the dead lock and updates (the 2026-08-02 incident scenario).
- [ ] Integration: uncontended `genie update` output and behavior unchanged (prompt before lease, delivery after).
- [ ] Regression: `--post-delivery-converge` child still borrows the parent lease correctly (one end-to-end dev-build update).
- [x] Functional: live holder → `update --sync-only` (dev-tip binary f7c4314b9, isolated GENIE_HOME sandbox, 2026-08-03) exited 2 with one clean line naming the real lock path, no stack trace, no false phrase.
- [x] Functional: SIGKILLed holder with fresh-mtime lock → same sandbox run stole the lock in ~100ms (lock file gone) and the command completed exit 0 — the 2026-08-02 incident scenario, fixed.
- [x] Integration: uncontended sandbox run exited 0 with normal sync output, no busy line.
- [x] Regression: real host `genie update -y` (2026-08-03) delivered 5.260803.1 → 5.260803.3 end-to-end — verified release promotion, borrowed-lease converge, integration refresh — exit 0.

---

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@automagik/genie",

"version": "5.260803.3",
"version": "5.260803.6",
"description": "Collaborative terminal toolkit for human + AI workflows. NOTE: npm distribution discontinued 2026-05-09 — install via `curl -fsSL https://raw.githubusercontent.com/automagik-dev/genie/main/install.sh | bash` (cosign + SLSA verified). See https://automagik.dev/genie/release-process",

"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion plugins/genie/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genie",
"version": "5.260803.3",
"version": "5.260803.6",
"description": "Human-AI partnership for Claude Code. Share a terminal, orchestrate workers, evolve together. Brainstorm ideas, turn them into wishes, execute with /work, validate with /review, and ship as one team.",
"author": {
"name": "Namastex Labs"
Expand Down
2 changes: 1 addition & 1 deletion plugins/genie/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genie",
"version": "5.260803.3",
"version": "5.260803.6",
"description": "Plan, execute, review, and ship software with Genie workflows in Codex.",
"author": {
"name": "Namastex Labs",
Expand Down
2 changes: 1 addition & 1 deletion plugins/genie/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genie-plugin",
"version": "5.260803.3",
"version": "5.260803.6",
"private": true,
"description": "Runtime dependencies for genie bundled CLIs",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion plugins/hermes-genie/plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: genie
version: 5.260803.3
version: 5.260803.6
description: "Native Hermes surface for Genie orchestration: read-only status plus work-plan and review-plan gap tools that the MCP board surface does not cover, hooks, commands, and a thin cockpit skill. Board/task truth comes from the genie MCP tools."
provides_tools:
# Default surface: exactly the three gap tools the MCP board surface does not cover.
Expand Down
25 changes: 18 additions & 7 deletions plugins/pi-genie/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ the pi extension **automatically**:
finishing `genie install` aux-layout normalization), and
- the agent-sync **`pi` lane** — run by `genie install` and every `genie update`
— symlinks `~/.pi/agent/extensions/genie` → `$GENIE_HOME/plugins/pi-genie`
whenever pi is detected (pi CLI on PATH or the pi extensions dir present).
A relocated pi agent dir is honored: the lane targets `$PI_CODING_AGENT_DIR`
when set (pi's real override, tilde-expanded), falling back to
`~/.pi/agent`. The legacy `$PI_HOME` alias is still accepted.

`genie doctor` reports the link as `agent sync: pi`. No manual step needed on
fresh installs or updates.
whenever pi is detected (pi CLI on PATH or the pi **agent dir** present — pi
only creates `extensions/` when it installs a package, so detection roots one
level up; the lane creates `extensions/` when needed and pi discovers the link
on its next run). A relocated pi agent dir is honored: the lane targets
`$PI_CODING_AGENT_DIR` when set (pi's real override, tilde-expanded), falling
back to `~/.pi/agent`. The legacy `$PI_HOME` alias is still accepted.

`genie doctor` reports the link as `agent sync: pi`. Auto-sync needs no manual
step when `extensions/genie` is absent or already points at
`$GENIE_HOME/plugins/pi-genie` (a real directory there is backed up and adopted).
It never repoints a `genie` symlink aimed somewhere else — e.g. a dev checkout
installed by `install-local.sh`. That case is preserved as-is and reported by
`genie doctor` as an `agent sync: pi` warning; remediation is manual (remove or
repoint your own link, then run `genie update`).

`genie uninstall` removes the link the lane created — identity-checked, so a
`genie` entry pointing at your own checkout (or a real directory) is left in
place.

For a dev checkout (edits are live) or a detached, release-style copy, the
local installer remains available (it resolves the same way: `$PI_CODING_AGENT_DIR`
Expand Down
2 changes: 1 addition & 1 deletion plugins/pi-genie/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genie-pi-plugin",
"version": "5.260803.3",
"version": "5.260803.6",
"private": true,
"description": "Pi extension manifest for the Genie pi plugin — the plugin payload is plugins/pi-genie/extension.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion plugins/pi-genie/references/native-surface.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tool is read-only; every payload reports `mutation: "none"`.
| Session hook | `session_start` hint in Genie workspaces | `pi.on('session_start')` |
| Context hook | Bounded board snapshot before each turn | `pi.on('before_agent_start')` (system-prompt append) |
| Skills | pi-native discovery of `~/.agents/skills` / `.agents/skills`; opt-in canonical mirror via `GENIE_PI_CANONICAL_SKILLS=1` | `pi.on('resources_discover')` |
| Agent sync | Auto-install: symlink `~/.pi/agent/extensions/genie` → `$GENIE_HOME/plugins/pi-genie`; doctor `agent sync: pi` | `runAgentSync` `pi` lane (`genie install` / `genie update` / `--sync-only`) |
| Agent sync | Auto-install when detected (pi agent dir present OR pi CLI on PATH): symlink `~/.pi/agent/extensions/genie` → `$GENIE_HOME/plugins/pi-genie`; doctor `agent sync: pi`; identity-checked removal on `genie uninstall` | `runAgentSync` `pi` lane (`genie install` / `genie update` / `--sync-only`) |
| Install | Dev fallback: `scripts/install-local.sh` (symlink default, `--copy` detached) | `~/.pi/agent/extensions/genie` |
| Version | `plugins/pi-genie/package.json` synced by release machinery | `scripts/version.ts` |

Expand Down
12 changes: 10 additions & 2 deletions plugins/pi-genie/scripts/install-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,22 @@ plugin_src="$(cd "$script_dir/.." && pwd)"

# Resolve the pi agent dir the same way pi does: $PI_CODING_AGENT_DIR (real
# relocation override, tilde-expanded) or $PI_HOME/agent (legacy alias).
if [ -n "${PI_CODING_AGENT_DIR:-}" ]; then
# An empty or whitespace-only override is treated as unset: it would otherwise
# resolve to a cwd-relative "extensions" path and mutate the wrong directory.
pi_agent_dir_trimmed="$(printf '%s' "${PI_CODING_AGENT_DIR:-}" | tr -d '[:space:]')"
pi_home_trimmed="$(printf '%s' "${PI_HOME:-}" | tr -d '[:space:]')"
if [ -n "$pi_agent_dir_trimmed" ]; then
agent_dir="$PI_CODING_AGENT_DIR"
case "$agent_dir" in
"~") agent_dir="$HOME" ;;
"~/"*) agent_dir="$HOME/${agent_dir#\~/}" ;;
esac
else
pi_home="${PI_HOME:-$HOME/.pi}"
if [ -n "$pi_home_trimmed" ]; then
pi_home="$PI_HOME"
else
pi_home="$HOME/.pi"
fi
agent_dir="$pi_home/agent"
fi
extensions_dir="$agent_dir/extensions"
Expand Down
6 changes: 4 additions & 2 deletions src/genie-commands/__tests__/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,10 @@ describe('updateCommand wiring', () => {
const logSpy = spyOn(console, 'log').mockImplementation((...args: unknown[]) => stdout.push(args.join(' ')));
const errorSpy = spyOn(console, 'error').mockImplementation((...args: unknown[]) => stderr.push(args.join(' ')));
process.exitCode = undefined;
// Millisecond-scale so the bounded poll is exercised, not endured.
process.env.GENIE_LIFECYCLE_LEASE_WAIT_MS = '60';
// Millisecond-scale so the bounded poll is exercised, not endured. 500ms
// (not 60ms) so a GC/scheduler pause cannot collapse the 25ms poll loop to
// a single attempt and flake the `attempts > 1` assertion.
process.env.GENIE_LIFECYCLE_LEASE_WAIT_MS = '500';
let attempts = 0;
let thrown: unknown;
try {
Expand Down
81 changes: 81 additions & 0 deletions src/genie-commands/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,71 @@ describe('omni hook-timeout guardrail', () => {
});
});

describe('doctorCommand — pi extension link (user-facing CLI surface)', () => {
/**
* Pin pi's own relocation override at the isolated home so no real `~/.pi` is
* read (Bun resolves `homedir()` independently of the `HOME` override).
* `await`s inside the window — restoring before the async doctor run would
* hand the real pi home back to the check.
*/
async function withIsolatedPiAgentDir<T>(agentDir: string, run: () => Promise<T>): Promise<T> {
const prior = process.env.PI_CODING_AGENT_DIR;
process.env.PI_CODING_AGENT_DIR = agentDir;
try {
return await run();
} finally {
if (prior === undefined) Reflect.deleteProperty(process.env, 'PI_CODING_AGENT_DIR');
else process.env.PI_CODING_AGENT_DIR = prior;
}
}

afterEach(() => {
process.exitCode = 0;
});

test('a detected pi install with no genie link warns non-fatally with the sync suggestion', async () => {
const genieHome = join(isolatedHome, 'genie');
mkdirSync(join(genieHome, 'plugins', 'genie', 'skills'), { recursive: true });
mkdirSync(join(genieHome, 'plugins', 'pi-genie'), { recursive: true });
writeFileSync(join(genieHome, 'VERSION'), '5.0.0\n', 'utf8');
const agentDir = join(isolatedHome, '.pi', 'agent');
mkdirSync(join(agentDir, 'extensions'), { recursive: true });

const { output, exitCode } = await withIsolatedPiAgentDir(agentDir, () =>
captureDoctor(() => doctorCommand({}, isolatedDoctorDeps())),
);

// Human-readable surface: the warn glyph, the check name, the actionable
// detail and the suggestion — and a warning never fails the command.
expect(output).toContain('agent sync: pi');
expect(output).toContain('extensions/genie link absent');
expect(output).toContain('genie update');
expect(output).toMatch(/!.*agent sync: pi/);
expect(exitCode).toBe(0);
});

test('a correct pi extension link passes and prints no pi warning', async () => {
const genieHome = join(isolatedHome, 'genie');
const piSource = join(genieHome, 'plugins', 'pi-genie');
mkdirSync(join(genieHome, 'plugins', 'genie', 'skills'), { recursive: true });
mkdirSync(piSource, { recursive: true });
writeFileSync(join(genieHome, 'VERSION'), '5.0.0\n', 'utf8');
const agentDir = join(isolatedHome, '.pi', 'agent');
mkdirSync(join(agentDir, 'extensions'), { recursive: true });
symlinkSync(piSource, join(agentDir, 'extensions', 'genie'));

const { output, exitCode } = await withIsolatedPiAgentDir(agentDir, () =>
captureDoctor(() => doctorCommand({ json: true }, isolatedDoctorDeps())),
);
const json = JSON.parse(output) as { checks: Array<{ name: string; status: string; detail?: string }> };
const pi = json.checks.find((check) => check.name === 'agent sync: pi');

expect(pi?.status).toBe('pass');
expect(pi?.detail).toContain('linked');
expect(exitCode).toBe(0);
});
});

describe('doctorCommand — genie.db check branches', () => {
// The db check resolves its path from the current repo root (git rev-parse),
// so we drive doctorCommand inside a throwaway git repo to exercise the
Expand Down Expand Up @@ -1027,6 +1092,22 @@ describe('checkAgentSync', () => {
expect(pi?.suggestion).toBeDefined();
});

// The detection gate is the pi AGENT dir (what pi always creates), not the
// `extensions` child (which pi only creates when installing a package) — and it
// must stay byte-identical to `syncPi`, so every warning here is repairable by
// the suggested sync. The pi home alone is still "not detected".
test('pi: agent dir without an extensions dir → warn (same gate as the sync lane)', () => {
mkdirSync(join(piHome, 'agent'), { recursive: true });
const pi = find(checkAgentSync(paths()), 'agent sync: pi');
expect(pi?.status).toBe('warn');
expect(pi?.suggestion).toBeDefined();
});

test('pi: pi home without an agent dir → not detected', () => {
mkdirSync(piHome, { recursive: true });
expect(find(checkAgentSync(paths()), 'agent sync: pi')?.detail).toBe('not detected');
});

// Codex Genie skills are plugin-only (R5): an EMPTY user tier is the healthy
// state, and a clean managed fallback there is repairable duplicate state.
test('codex detected, empty ~/.agents/skills tier → pass (plugin-only)', () => {
Expand Down
10 changes: 6 additions & 4 deletions src/genie-commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1406,16 +1406,18 @@ interface PiCheckInput {

/**
* pi health: the `~/.pi/agent/extensions/genie` symlink converging on the
* shipped `pi-genie` source. Pass when pi is undetected (no extensions dir and
* shipped `pi-genie` source. Pass when pi is undetected (no agent dir and
* no pi CLI) or the source is absent — the link check only runs when both
* sides exist. The detection gate matches the agent-sync `pi` lane exactly
* (`syncPi`): extensions dir present OR pi CLI on PATH. Link-only: pi has no
* enable command or config legs to converge.
* (`syncPi`): pi AGENT dir present OR pi CLI on PATH — pi only creates
* `<agentDir>/extensions` when it installs a package resource, so gating on
* `extensions` here would report "not detected" for real installs the sync lane
* converges. Link-only: pi has no enable command or config legs to converge.
*/
function checkPiSync(input: PiCheckInput): CheckResult[] {
const { piRoot, piHome } = input;
const extensionsDir = resolvePiExtensionsDir(process.env, piHome);
if (!existsSync(extensionsDir) && input.binary === null) {
if (!existsSync(dirname(extensionsDir)) && input.binary === null) {
return [{ name: 'agent sync: pi', status: 'pass', detail: 'not detected' }];
}
if (piRoot === null) {
Expand Down
6 changes: 4 additions & 2 deletions src/genie-commands/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,10 @@ describe('installCommand — a busy agent-sync lifecycle lease (2026-08-02 incid

beforeEach(() => {
process.exitCode = 0;
// Millisecond-scale: the bounded poll is exercised, not endured.
process.env.GENIE_LIFECYCLE_LEASE_WAIT_MS = '60';
// Millisecond-scale: the bounded poll is exercised, not endured. 500ms
// (not 60ms) so a GC/scheduler pause cannot collapse the 25ms poll loop to
// a single attempt and flake the `attempts > 1` assertion.
process.env.GENIE_LIFECYCLE_LEASE_WAIT_MS = '500';
logs = [];
errors = [];
logSpy = spyOn(console, 'log').mockImplementation((...a: unknown[]) => {
Expand Down
8 changes: 6 additions & 2 deletions src/genie-commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import {
} from '../lib/codex-lifecycle-lease.js';
import { genieConfigExists, getGenieConfigPath } from '../lib/genie-config.js';
import { retireInstallVersionMarker } from '../lib/install-version-marker.js';
import { acquireOrderedLifecycleLeases, releaseOrderedLifecycleLeases } from '../lib/ordered-lifecycle-leases.js';
import {
acquireOrderedLifecycleLeases,
lifecycleBusyMessage,
releaseOrderedLifecycleLeases,
} from '../lib/ordered-lifecycle-leases.js';
import {
type InstallIntegrationsOptions,
type IntegrationResult,
Expand Down Expand Up @@ -411,7 +415,7 @@ export async function installCommand(
// install.sh parses those machine trailers, and reporting
// `codex-lifecycle-busy` for an agent-sync holder would be a lie. One
// human-readable stderr line plus exit 2 is the whole contract here.
console.error(`Another Genie lifecycle command is active: ${acquired.detail}`);
console.error(lifecycleBusyMessage(acquired.detail));
process.exitCode = 2;
return;
}
Expand Down
Loading
Loading