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 plugins/allium/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allium",
"version": "3.14.0",
"version": "3.15.0",
"description": "Velocity through clarity.",
"author": {
"name": "JUXT",
Expand Down
2 changes: 1 addition & 1 deletion plugins/allium/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allium",
"version": "3.14.0",
"version": "3.15.0",
"description": "Velocity through clarity.",
"author": {
"name": "JUXT",
Expand Down
43 changes: 33 additions & 10 deletions plugins/allium/hooks/loop-trace.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
// blocks a call (always exits 0), and swallows its own errors.

import {
closeSync,
constants,
existsSync,
lstatSync,
openSync,
readFileSync,
writeFileSync,
appendFileSync,
realpathSync,
writeFileSync,
} from "fs";
import path from "path";

Expand Down Expand Up @@ -75,26 +78,50 @@ if (!projectRoot) process.exit(0);
// Only trace while a loop is running; otherwise this is an unrelated subagent.
const loopDir = path.join(projectRoot, ".allium-loop");
if (!existsSync(loopDir)) process.exit(0);
try {
const stat = lstatSync(loopDir);
if (!stat.isDirectory() || stat.isSymbolicLink()) process.exit(0);
} catch {
process.exit(0);
}

const pendingPath = path.join(loopDir, ".timing-pending.json");
const timingsPath = path.join(loopDir, "timings.jsonl");
const now = Date.now();

function readPending() {
try {
const stat = lstatSync(pendingPath);
if (!stat.isFile() || stat.isSymbolicLink()) return { byId: {}, fifo: [] };
const p = JSON.parse(readFileSync(pendingPath, "utf-8"));
return { byId: p.byId ?? {}, fifo: Array.isArray(p.fifo) ? p.fifo : [] };
} catch {
return { byId: {}, fifo: [] };
}
}
function writePending(p) {
function writeWithoutFollowingSymlinks(filePath, data, append = false) {
let fd;
try {
writeFileSync(pendingPath, JSON.stringify(p));
const noFollow = constants.O_NOFOLLOW ?? 0;
const mode = append ? constants.O_APPEND : constants.O_TRUNC;
fd = openSync(filePath, constants.O_WRONLY | constants.O_CREAT | mode | noFollow, 0o600);
writeFileSync(fd, data);
return true;
} catch {
// best-effort
return false;
} finally {
if (fd !== undefined) {
try {
closeSync(fd);
} catch {
// best-effort
}
}
}
}
function writePending(p) {
writeWithoutFollowingSymlinks(pendingPath, JSON.stringify(p));
}

if (event === "pre") {
const p = readPending();
Expand Down Expand Up @@ -122,10 +149,6 @@ if (rec) {
agent: rec.agent,
duration_ms: now - rec.start,
}) + "\n";
try {
appendFileSync(timingsPath, line);
} catch {
// best-effort
}
writeWithoutFollowingSymlinks(timingsPath, line, true);
}
process.exit(0);
38 changes: 37 additions & 1 deletion plugins/allium/hooks/loop-trace.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execFileSync } from "child_process";
import { mkdtempSync, mkdirSync, readFileSync, existsSync, rmSync } from "fs";
import { mkdtempSync, mkdirSync, readFileSync, existsSync, rmSync, symlinkSync, writeFileSync } from "fs";
import path from "path";
import { tmpdir } from "os";

Expand Down Expand Up @@ -94,5 +94,41 @@ console.log("\n── loop-trace hook ──\n");
rmSync(dir, { recursive: true, force: true });
}

// 6. A repository-controlled .allium-loop symlink must not redirect writes.
{
const dir = newProject({ withLoopDir: false });
const outside = mkdtempSync(path.join(tmpdir(), "allium-timing-outside-"));
symlinkSync(outside, path.join(dir, ".allium-loop"));
const payload = { tool_use_id: "linked-dir", tool_name: "Task", tool_input: { subagent_type: "allium:weed" } };
runHook("pre", payload, dir);
assert("refuses a symlinked loop directory", !existsSync(path.join(outside, ".timing-pending.json")));
rmSync(dir, { recursive: true, force: true });
rmSync(outside, { recursive: true, force: true });
}

// 7. A symlinked pending-state file must not be read or overwritten.
{
const dir = newProject({ withLoopDir: true });
const victim = path.join(dir, "victim-pending.txt");
writeFileSync(victim, "unchanged");
symlinkSync(victim, path.join(dir, ".allium-loop", ".timing-pending.json"));
runHook("pre", { tool_use_id: "linked-pending", tool_name: "Task", tool_input: { subagent_type: "allium:weed" } }, dir);
assert("refuses a symlinked pending-state file", readFileSync(victim, "utf-8") === "unchanged");
rmSync(dir, { recursive: true, force: true });
}

// 8. A symlinked timing log must not receive appended data.
{
const dir = newProject({ withLoopDir: true });
const payload = { tool_use_id: "linked-log", tool_name: "Task", tool_input: { subagent_type: "allium:weed" } };
runHook("pre", payload, dir);
const victim = path.join(dir, "victim-timings.txt");
writeFileSync(victim, "unchanged");
symlinkSync(victim, path.join(dir, ".allium-loop", "timings.jsonl"));
runHook("post", payload, dir);
assert("refuses a symlinked timing log", readFileSync(victim, "utf-8") === "unchanged");
rmSync(dir, { recursive: true, force: true });
}

console.log(`\n${passed} passed, ${failed} failed`);
process.exit(failed > 0 ? 1 : 0);
48 changes: 47 additions & 1 deletion plugins/allium/scripts/test-skills.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* node scripts/test-skills.mjs structure # run one group
* node scripts/test-skills.mjs portability links # run multiple groups
*
* Groups: structure, codex, consistency, portability, links, routing, generation, loopdocs, hooks, modes, handoffs, trace, discovery, parking, witnessing, timinghook, crosstalk
* Groups: structure, codex, consistency, portability, links, routing, generation, loopdocs, hooks, modes, handoffs, trace, reduce, discovery, parking, witnessing, timinghook, crosstalk
*
* All groups except discovery, parking, witnessing and crosstalk are offline (free, fast);
* those four require --live and make Claude API calls.
Expand Down Expand Up @@ -734,6 +734,52 @@ if (shouldRun("hooks")) {
}
}

// ---------------------------------------------------------------------------
// Reduce — the fan-out reduce step (driving-the-loop §6 + integrating-slices).
// Pins the constructs that make the reduce a real procedure, so a reword can't
// silently drop them: the reference doc exists and is linked from §6, the
// cross-check runs `allium analyse` over all slices, and the seam-signal
// diagnostic is documented in actioning-findings. Offline and deterministic.
// ---------------------------------------------------------------------------

if (shouldRun("reduce")) {
console.log("\n── reduce: the fan-out integration (reduce) step ──\n");

const integ = path.join(ROOT, "skills", "allium", "references", "integrating-slices.md");
const loop = path.join(ROOT, "skills", "allium", "references", "driving-the-loop.md");
const findings = path.join(ROOT, "skills", "allium", "references", "actioning-findings.md");

if (existsSync(integ)) pass("integrating-slices.md exists");
else fail("integrating-slices.md", "reduce-step reference doc missing");

const integSrc = existsSync(integ) ? readFileSync(integ, "utf-8") : "";
// The reduce leans on the CLI cross-checking all slices at once.
/allium analyse/.test(integSrc)
? pass("integrating-slices: cross-checks with allium analyse")
: fail("integrating-slices: analyse", "must run `allium analyse` over the slices");
// Canonical owner for shared entities is the assembly rule.
/canonical owner/i.test(integSrc)
? pass("integrating-slices: canonical owner rule")
: fail("integrating-slices: canonical owner", "must state the canonical-owner rule for shared entities");
// No new agent: edits are delegated to existing phase agents.
/\btend\b/.test(integSrc) && /\bwitness\b/.test(integSrc)
? pass("integrating-slices: delegates to existing phase agents")
: fail("integrating-slices: delegation", "must route edits through tend and witness the whole");

const loopSrc = readFileSync(loop, "utf-8");
loopSrc.includes("integrating-slices.md")
? pass("driving-the-loop §6 links the reduce reference")
: fail("driving-the-loop §6 link", "§6 must link integrating-slices.md");
/reduce step/i.test(loopSrc)
? pass("driving-the-loop §6 names the reduce step")
: fail("driving-the-loop §6", 'must name the "reduce step"');

const findingsSrc = readFileSync(findings, "utf-8");
findingsSrc.includes("allium.reference.unknownName")
? pass("actioning-findings documents the seam signal (reference.unknownName)")
: fail("actioning-findings seam signal", "must document allium.reference.unknownName as a seam signal");
}

// ---------------------------------------------------------------------------
// Modes — the interaction-mode contract is stated everywhere it must be.
// The skill is the single source of truth for each agent-backed capability;
Expand Down
1 change: 1 addition & 0 deletions plugins/allium/skills/allium/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,5 @@ When the `allium` CLI is installed, a hook validates `.allium` files automatical
- [Test generation](./references/test-generation.md) — generating tests from specifications
- [Recommended loops](./references/recommended-loops.md) — the gather-context → take-action → verify → repeat loop, with spec-first and code-first walkthroughs
- [Driving the loop](./references/driving-the-loop.md) — the procedure `/allium` follows to drive a goal to convergence (entry detection, the tick, stop conditions, the ledger)
- [Integrating slices](./references/integrating-slices.md) — the reduce step for fanned-out goals: assemble the slices, cross-check the seams with `allium analyse`, reconcile and witness the whole
- [Patterns](./references/patterns.md) — 9 worked patterns: auth, RBAC, invitations, soft delete, notifications, usage limits, comments, library spec integration, framework integration contract
11 changes: 11 additions & 0 deletions plugins/allium/skills/allium/references/actioning-findings.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ A rule's `ensures` clause could produce a state that violates a declared invaria

The finding's evidence shows the mechanism — how the ensures clause is inconsistent with the invariant. Use this to suggest a specific fix rather than asking an open-ended question.

## Findings across a seam (the reduce step)

When `analyse` runs over several assembled slices at once (the reduce step — see [integrating slices](./integrating-slices.md)), the same finding types apply, but a finding on one slice often points at a *seam* with another: the consumer depends on behaviour the producer doesn't supply, or the two slices disagree about a shared entity. Read the finding as a cross-slice question rather than a single-spec gap.

- A **`missing_producer`** or **`unreachable_trigger`** on a consuming slice usually means the *producing* slice should emit the trigger or expose the surface — decide which slice owns the source and `tend` that one, rather than adding the producer to the consumer.
- A **`dead_transition`** / **`deadlock`** whose exit is witnessed in another slice is a *wiring* problem first: check the `use` import and qualified names line up before treating it as a genuine gap.

### `allium.reference.unknownName` (diagnostic, seam signal)

Not a finding — a diagnostic — but the clearest sign of a broken seam in the reduce step: a slice references a qualified name (`orders/OrderPaid`) that the owning slice doesn't declare or emit. It typically appears alongside a `deadlock` on the owning slice whose exit that reference was meant to witness. **Ask which slice owns the name.** Either the producer should provide it (`tend` the producer to emit the trigger / declare the entity), or the reference is mis-wired (fix the `use` alias or qualified name). Always read the `diagnostics` array, not just `findings`, when integrating slices — a seam often breaks here first.

## Choosing which finding to present

When `analyse` returns multiple findings, pick the most relevant one. Apply these criteria in order:
Expand Down
9 changes: 8 additions & 1 deletion plugins/allium/skills/allium/references/driving-the-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ Rule: a question is *blocking* iff the next unit of work depends on its answer.

If the goal spans more than one independent behavioural slice, decompose along the spec's seams — one sub-goal per **entity lifecycle**, **surface**, or **independent rule / data-flow chain**. Order sub-goals topologically by the data-flow / trigger graph (producers before consumers). Run each sub-goal as its own loop, and witness each slice at its own convergence gate (§11) before you count it converged, so a falsified slice cannot be assembled into the whole.

After the slices converge, run a **whole-spec integration pass** — cross-entity / data-flow / reachability tests plus a full `weed`, and a final `witness` over the assembled spec — so the seams *between* slices converge too. Run this autonomously without blocking to confirm the plan, and produce one consolidated summary at the end.
After the slices converge, run the **reduce step** — assemble them into one spec and drive the seams *between* slices to convergence. Fan-out is the map; this is the reduce, and it is a real procedure, not a hand-wave:

1. **Assemble and wire** — pick a canonical owner for any shared entity (compare declarations with `allium model`, cheap JSON), add the `use` imports and qualified names so the slices form one connected graph. Un-wired, the checker sees them as separate islands.
2. **Cross-check with the CLI** — run `allium analyse` over **all the assembled slices at once**. It resolves references and traces data flow, reachability and witnessing *across* the `use` seams, returning a small JSON list of the seams that don't line up. The CLI does the seeing; you hold only the findings.
3. **Route each seam problem** — read both the `findings` and the `diagnostics` arrays (a broken seam often shows as a dangling `reference.unknownName` on the consumer plus a `deadlock` on the producer). Translate each via [actioning findings](./actioning-findings.md) — a cross-seam `missing_producer` / dangling reference → `tend` the slice that should provide it (or fix the wiring); a cross-slice `conflict` → escalate (§5). Delegate every edit to `tend` / `weed`; re-run `analyse` until the seams are clean, under the normal caps (§4).
4. **Cross-service tests, then witness** — `propagate` over the assembled set for the cross-slice tests the per-slice loops could not exercise, then a final `witness` (§11) over the whole so the integrated spec carries the same convergence guarantee each slice did.

Run the reduce autonomously without blocking to confirm the plan, and produce one consolidated summary at the end. The seam detail — canonical entity ownership, `use` wiring, contract matching, which findings signal a broken seam — is in [integrating slices](./integrating-slices.md). Throughout, the orchestrator holds slice paths and CLI JSON, never slice bodies — the same isolation the map uses, applied to the reduce.

## 7. Delegate each phase to an isolated sub-agent (default)

Expand Down
Loading
Loading