Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4a3a0d
fix: snapshot replay JSON before hashing and persistence
haelyra Nov 19, 2026
51b8960
Merge reviewed canonical fixture recording repair
haelyra Nov 19, 2026
7b9f56f
fix: preserve runtime history and project discovery across hook races
haelyra Nov 19, 2026
6c3ebea
test: document and verify orphan log recovery fallback
haelyra Nov 19, 2026
348f6e6
fix: reserve log lock quarantines without overwriting foreign files
haelyra Nov 19, 2026
a01e859
Merge reviewed hook logging, batch warning and project cache repairs
haelyra Nov 19, 2026
f37ab7e
test: backdate held log lock without an existence race
haelyra Nov 19, 2026
548d945
Merge reviewed log regression fixture cleanup
haelyra Nov 19, 2026
6edc259
fix: preserve UI Canvas edits through delivery and reload
haelyra Nov 19, 2026
4cd4a91
Merge reviewed canvas acknowledgement, reset and replay repairs
haelyra Nov 19, 2026
0068bd0
fix: retain newer canvas drafts and scope acknowledgment guidance
haelyra Nov 19, 2026
685a1f6
Merge reviewed canvas draft preservation and scoped acknowledgement f…
haelyra Nov 19, 2026
c368e85
fix: freeze preview editing while Finish is pending
haelyra Nov 19, 2026
52fbaed
Merge reviewed Finish delivery protection and skill formatting repair
haelyra Nov 19, 2026
442ca47
fix: reject lossy canvas replay before export
haelyra Nov 19, 2026
8cb860a
fix: preserve immutable UI deliveries through retry and reload
haelyra Nov 19, 2026
3b7d85f
Merge independently reviewed lossless UI replay validation
haelyra Nov 19, 2026
5c61c1c
fix: confirm delayed Finish acceptance in canvas status
haelyra Nov 19, 2026
6dbaa34
fix: publish canvas feedback state only after persistence
haelyra Nov 19, 2026
abe4424
fix: preserve bounded subpixel canvas nudges
haelyra Nov 19, 2026
863e3ee
Merge reviewed fractional nudge preservation
haelyra Nov 19, 2026
4368a6a
fix: reconcile captured snapshot coverage with durable receipts
haelyra Nov 20, 2026
e5d4f46
fix: preserve canvas reply and end snapshots
haelyra Nov 20, 2026
8339b16
test: synchronize canvas waits and isolate watcher state freshness
haelyra Nov 20, 2026
5f60151
Merge reviewed immutable legacy session transitions
haelyra Nov 20, 2026
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
12 changes: 9 additions & 3 deletions .agents/skills/ui-canvas/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ listening" so the human knows you are connected.
request to repaint is the target for a one-property change.

```json
{ "kind": "edits", "editCount": 3, "edits": [ { "kind": "resize", "selector": "img.art", "width": 220, "height": 220, "before": { "width": 260, "height": 260 } } ],
{ "id": "fb-123", "kind": "edits", "editCount": 3, "edits": [ { "kind": "resize", "selector": "img.art", "width": 220, "height": 220, "before": { "width": 260, "height": 260 } } ],
"viewport": { "preset": "mobile", "width": 393, "height": 852 },
"exportPath": "/abs/.claude/previews/pricing-card.apply-mf3k2x-9a1c.edited.html", "editsPath": "/abs/.claude/previews/pricing-card.apply-mf3k2x-9a1c.edits.json" }
```
Expand All @@ -115,8 +115,14 @@ listening" so the human knows you are connected.
their inline-style changes), tidy it into real CSS if it is messy, keep it
self-contained, and reply. Each Apply writes its own
`<name>.apply-<batch>.*` pair, so a queued earlier batch keeps its own
snapshot. The canvas keeps showing the applied edits until your write to
the mockup reloads it, then drops them, so nothing is applied twice.
snapshot. The canvas keeps showing submitted edits until it recognizes the
exact exported snapshot or you explicitly acknowledge the incorporated batch.
After incorporating a batch, acknowledge its feedback ID with
`ecc-ui-canvas await <file> --ack fb-123 --reply "Applied the requested changes."`.
Multiple IDs may be comma-separated. Do not acknowledge a queued batch while
answering an earlier chat. Exact copies of exported snapshots are recognized
automatically; an unrelated file save is not acknowledgment. If a submitted
batch no longer matches the file, resolve it before applying more changes.

```json
{ "kind": "finish", "editCount": 5, "edits": [ "…" ], "viewport": { "preset": "desktop", "width": 1412, "height": 806 },
Expand Down
2 changes: 1 addition & 1 deletion commands/ui-canvas.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export.
4. On `chat`: signal `typing --state thinking`, edit the mockup file (the
preview live-reloads and keeps their pending edits), answer with
`await <file> --reply "…"`, repeat.
5. On `edits`: rewrite the mockup from `exportPath`, reply, keep listening.
5. On `edits`: rewrite the mockup from `exportPath`, then acknowledge its feedback ID with `await <file> --ack fb-123 --reply "…"` and keep listening. Acknowledge only batches actually incorporated; unrelated saves retain queued edits.
6. On `finish`: read `exportPath` and `editsPath`, implement that exact
design in the real component, commit per repo rules, report in chat.

Expand Down
17 changes: 17 additions & 0 deletions docs/command-logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Command log retention

The optional audit and development command hooks write private command logs
using the standalone `scripts/hooks/post-bash-command-log.js` helper. Commands
pass through the existing secret redaction before being recorded.

Rotation keeps the active log and one archive. Writers coordinate the size
check, rotation, and append with a cross-process lock so simultaneous rotations
do not overwrite newly archived history. Only a lock whose owner is verifiably
dead can be reclaimed; elapsed time alone never establishes ownership.

Logging waits at most 500 milliseconds for ownership, then appends without
rotating. The size limit is best effort: rotation resumes when ownership becomes
available. Unsupported lock operations or an orphaned recovery guard can defer
rotation indefinitely while command recording continues. The recovery guard is
not recursively reclaimed, so operators should investigate persistent lock files
and establish that all writers have stopped before removing an orphan guard.
12 changes: 12 additions & 0 deletions docs/design/ui-canvas.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,15 @@ The skill tells the agent to signal `typing --state thinking` immediately and re
`node tests/integration/ui-canvas-e2e.test.js`, plus the existing Plan Canvas suites, run under
`node tests/run-all.js`. Manual browser QA uses a mockup opened with
`ECC_PLAN_CANVAS_STATE_DIR=/tmp/uc ECC_PLAN_CANVAS_PORT=4599 node scripts/ui-canvas.js open <file> --no-open`.

Replay identifies a target only when its selector has exactly one match. Unique
`#id` targets (and `body`/`html`) may survive an unrelated save; positional paths
and positional move parents replay only against their captured source revision.
Changed positional targets and duplicate IDs stay stale rather than editing a
different element. Submitted batches replay atomically: if any target cannot be
resolved safely, the whole batch stays visibly unresolved and Apply/Finish wait
for agent resolution. Reset reverts unsent edits and retains unresolved submitted
changes. The agent may acknowledge specific incorporated batches using UI Canvas
`await --ack fb-123`; merely draining feedback or saving another change is not
acknowledgment. An exact exported snapshot can acknowledge only the batch and
older batches proven completely represented in that snapshot.
2 changes: 2 additions & 0 deletions docs/gateguard/design-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ is the batch.
`batch-deny`. It does not add to `fact_force_denials`, so the denial cap and
the condensed ordinals are unchanged.
- A call from any other message passes, including the retry in the next turn.
- Earlier permitted siblings, such as comment-only edits, are never rolled back.
Every batch denial keeps a re-read warning; a lock cannot prove the file is unchanged.
- There is no fallback to the newest assistant message: a guessed batch could
match the retry and deny it forever. With no `tool_use_id`, no transcript, or
the pending call missing from the transcript, nothing is locked. The denial
Expand Down
2 changes: 1 addition & 1 deletion manifests/context-packs/skill-triggers@1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"id": "hand-seeded",
"source": "manual-curation-pending-regeneration"
},
"registryDigest": "27e0424730a1ad30f57f210cdfc8f8d72493cfe8f5ffc9d3ead4b2943e1131ed",
"registryDigest": "e1ae66afd0ca1437da7cb799d413a74a8f5171f285074c9de8bbe2630dc02265",
"schemaVersion": 1,
"triggers": {
"skill:agent-runtime-gateway-smoke-test": [
Expand Down
11 changes: 6 additions & 5 deletions scripts/hooks/gateguard-fact-force.js
Original file line number Diff line number Diff line change
Expand Up @@ -2105,16 +2105,17 @@ const READ_ONLY_GIT_SUBCOMMANDS = new Map([
* Batch-consistency note (#3136, #3936). A first-touch denial marks the
* file checked so the retry passes. When the pending call's batch is found
* in the transcript, the denial also locks the file for that batch, so the
* siblings are denied too and the file stays whole (`locked`). Otherwise
* later siblings are denied too (`locked`), but earlier allowed edits are
* never rolled back. Otherwise
* the hook cannot tell siblings from the retry, so the denial says out
* loud that siblings may already have been applied.
* see docs/gateguard/design-notes.md#same-batch-siblings
*/
function batchSiblingWarning(safePath, locked = false) {
if (locked) {
return (
`Other edits to ${safePath} from this batch are denied too, so the file is unchanged. ` +
'Resend all of them with the retry.'
`Other edits to ${safePath} from this batch are denied too. Earlier edits may already have been applied. ` +
'Re-read the file and resend every denied edit with the retry.'
);
}
return (
Expand All @@ -2127,8 +2128,8 @@ function sameBatchGateMsg(filePath) {
const safe = sanitizePath(filePath);
return (
`[Fact-Forcing Gate] An earlier edit to ${safe} in this same batch was denied at first touch, ` +
`so this one is denied too and ${safe} is unchanged. ` +
'Present the facts that denial asked for, then resend every edit to this file from this batch.'
`so this one is denied too. Earlier edits may already have been applied. ` +
'Re-read the file, present the facts that denial asked for, then resend every denied edit to this file from this batch.'
);
}

Expand Down
165 changes: 141 additions & 24 deletions scripts/hooks/post-bash-command-log.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
'use strict';

const crypto = require('crypto');
const fs = require('fs');
const os = require('os');
const path = require('path');
Expand Down Expand Up @@ -197,38 +198,154 @@ function sanitizeCommand(command) {
const LOG_MAX_BYTES = 10 * 1024 * 1024;
const LOG_FILE_MODE = 0o600;

function appendLine(filePath, line) {
const data = `${line}\n`;
fs.mkdirSync(path.dirname(filePath), { recursive: true });
// Keep this hook standalone: managed copies may omit scripts/lib. Lock
// publication and release use descriptor identities, as the installer does.
const LOG_LOCK_WAIT_MS = 500;
function sameLogLock(left, right) {
return left.ino === right.ino && (left.dev === right.dev
|| (process.platform === 'win32' && (!left.dev || !right.dev)));
}

function restoreLogLock(quarantine, lockPath) {
// Exclusive publication never overwrites a replacement owner's lock. Keep
// the displaced file for inspection if another owner already holds the path.
fs.linkSync(quarantine, lockPath);
fs.unlinkSync(quarantine);
}

function reserveLogQuarantine(lockPath, phase) {
const quarantine = `${lockPath}.${phase}-${process.pid}-${crypto.randomBytes(8).toString('hex')}`;
// Reserve exclusively before rename, which otherwise overwrites a colliding
// foreign file. A failed reservation must never enter path cleanup.
const descriptor = fs.openSync(quarantine, 'wx', LOG_FILE_MODE);
fs.closeSync(descriptor);
return quarantine;
}

let stat = null;
function publishLogLock(lockPath) {
const temporary = `${lockPath}.create-${process.pid}-${crypto.randomBytes(8).toString('hex')}`;
let descriptor = fs.openSync(temporary, 'wx', LOG_FILE_MODE);
let identity;
try {
stat = fs.statSync(filePath);
} catch {
// No log yet.
}
// Logs written by earlier versions were group/world readable. Tighten an
// existing log before it can be rotated, so the `.1` copy is private too.
// Windows has no POSIX permission bits to tighten.
if (stat && stat.isFile() && process.platform !== 'win32' && (stat.mode & 0o077) !== 0) {
fs.chmodSync(filePath, LOG_FILE_MODE);
fs.writeFileSync(descriptor, JSON.stringify({ pid: process.pid }));
fs.fsyncSync(descriptor);
identity = fs.fstatSync(descriptor, { bigint: true });
fs.closeSync(descriptor);
descriptor = undefined;
fs.linkSync(temporary, lockPath);
} finally {
if (descriptor !== undefined) fs.closeSync(descriptor);
fs.rmSync(temporary, { force: true });
}
if (stat && stat.isFile() && stat.size > 0 && stat.size + Buffer.byteLength(data) > LOG_MAX_BYTES) {
try {
fs.renameSync(filePath, `${filePath}.1`);
} catch {
// Rotation is best effort (another process may have rotated first, or
// Windows may refuse the rename); still record this command.
return () => {
const quarantine = reserveLogQuarantine(lockPath, 'release');
fs.renameSync(lockPath, quarantine);
if (!sameLogLock(fs.lstatSync(quarantine, { bigint: true }), identity)) {
restoreLogLock(quarantine, lockPath);
throw new Error('Command log lock changed owner before release');
}
fs.unlinkSync(quarantine);
};
}

function inspectLogLock(lockPath) {
const descriptor = fs.openSync(lockPath, fs.constants.O_RDONLY
| (fs.constants.O_NOFOLLOW || 0) | (fs.constants.O_NONBLOCK || 0));
try {
const identity = fs.fstatSync(descriptor, { bigint: true });
const named = fs.lstatSync(lockPath, { bigint: true });
if (!identity.isFile() || named.isSymbolicLink() || !sameLogLock(identity, named)
|| identity.size > 4096n) return null;
const bytes = Buffer.alloc(4097);
const count = fs.readSync(descriptor, bytes, 0, bytes.length, 0);
if (count > 4096) return null;
const owner = JSON.parse(bytes.subarray(0, count).toString('utf8'));
if (!Number.isSafeInteger(owner.pid) || owner.pid <= 0) return null;
try { process.kill(owner.pid, 0); return null; }
catch (error) { return error.code === 'ESRCH' ? identity : null; }
} finally { fs.closeSync(descriptor); }
}

function recoverLogLock(lockPath) {
let releaseGuard;
try { releaseGuard = publishLogLock(`${lockPath}.recover`); }
catch { return null; }
// The recovery guard is not recursively reclaimed. A crash here may leave
// it behind, so later calls preserve events through append-only fallback.
try {
const identity = inspectLogLock(lockPath);
if (!identity) return null; // Never take a live or unverifiable owner's lock.
const quarantine = reserveLogQuarantine(lockPath, 'stale');
fs.renameSync(lockPath, quarantine);
if (!sameLogLock(fs.lstatSync(quarantine, { bigint: true }), identity)) {
restoreLogLock(quarantine, lockPath);
return null;
}
fs.unlinkSync(quarantine);
return publishLogLock(lockPath);
} finally { releaseGuard(); }
}

function acquireLogLock(filePath) {
const lockPath = `${filePath}.lock`;
const deadline = performance.now() + LOG_LOCK_WAIT_MS;
const sleeper = new Int32Array(new SharedArrayBuffer(4));
while (true) {
try { return publishLogLock(lockPath); }
catch (error) { if (error.code !== 'EEXIST') return null; }
try {
const release = recoverLogLock(lockPath);
if (release) return release;
} catch { /* A writer can finish while recovery inspects the path. */ }
const remaining = deadline - performance.now();
if (remaining <= 0) return null;
Atomics.wait(sleeper, 0, 0, Math.min(10, remaining));
}
}

// The mode only applies when this call creates the file; an existing log
// was tightened above.
const fd = fs.openSync(filePath, 'a', LOG_FILE_MODE);
function appendOnly(filePath, data) {
const descriptor = fs.openSync(filePath, 'a', LOG_FILE_MODE);
try {
if (process.platform !== 'win32') fs.fchmodSync(descriptor, LOG_FILE_MODE);
fs.writeSync(descriptor, data);
} finally { fs.closeSync(descriptor); }
}

function appendLine(filePath, line) {
const data = `${line}\n`;
fs.mkdirSync(path.dirname(filePath), { recursive: true });
const release = acquireLogLock(filePath);
if (!release) {
// Preserve the command after a bounded wait or unsupported lock operation.
// Only the lock owner rotates; size enforcement resumes when the lock
// becomes available. An orphan recovery guard can defer this indefinitely.
appendOnly(filePath, data);
return;
}
try {
fs.writeSync(fd, data);
let stat = null;
try {
stat = fs.statSync(filePath);
} catch {
// No log yet.
}
// Logs written by earlier versions were group/world readable. Tighten an
// existing log before it can be rotated, so the `.1` copy is private too.
// Windows has no POSIX permission bits to tighten.
if (stat && stat.isFile() && process.platform !== 'win32' && (stat.mode & 0o077) !== 0) {
fs.chmodSync(filePath, LOG_FILE_MODE);
}
if (stat && stat.isFile() && stat.size > 0 && stat.size + Buffer.byteLength(data) > LOG_MAX_BYTES) {
try {
fs.renameSync(filePath, `${filePath}.1`);
} catch {
// Rotation is best effort (another process may have rotated first, or
// Windows may refuse the rename); still record this command.
}
}
appendOnly(filePath, data);
} finally {
fs.closeSync(fd);
try { release(); } catch { /* Preserve the write result and foreign locks. */ }
}
}

Expand Down
24 changes: 17 additions & 7 deletions scripts/lib/eval-harness/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ class ReplayError extends Error {
}
}

function fixtureIdentity(tool, args) {
// Use the same root JSON snapshot in record and replay. A live toJSON(key)
// must not see a different holder key inside the fixture identity envelope.
const snapshot = JSON.parse(canonicalJson(args));
return { key: hashValue({ tool, args: snapshot }), args_hash: hashValue(snapshot) };
}

class FixtureStore {
constructor(dir) {
this.dir = path.resolve(dir);
fs.mkdirSync(this.dir, { recursive: true });
}

key(tool, args) {
return hashValue({ tool, args });
return fixtureIdentity(tool, args).key;
}

pathFor(key) {
Expand All @@ -50,20 +57,23 @@ class FixtureStore {
}

put(tool, args, response) {
const key = this.key(tool, args);
const { key, args_hash } = fixtureIdentity(tool, args);
// Hash and persist one plain JSON value, without invoking a response's
// serializer again under the record's different 'response' holder key.
const snapshot = JSON.parse(canonicalJson(response));
const record = {
key,
tool,
args_hash: hashValue(args),
response_hash: hashValue(response),
response,
args_hash,
response_hash: hashValue(snapshot),
response: snapshot,
};
writeFileAtomic(this.pathFor(key), canonicalJson(record) + '\n');
return record;
}

get(tool, args) {
const key = this.key(tool, args);
const { key, args_hash } = fixtureIdentity(tool, args);
const filePath = this.pathFor(key);
if (!fs.existsSync(filePath)) {
throw new ReplayError('tool.fixture_missing', `no fixture for ${tool} (${key.slice(0, 16)})`, { tool, key });
Expand All @@ -80,7 +90,7 @@ class FixtureStore {
typeof record[field] !== 'string' || !envelope.HASH_PATTERN.test(record[field]))) {
throw new ReplayError('tool.fixture_corrupt', `fixture ${key.slice(0, 16)} has invalid record fields`, { tool, key });
}
if (record.key !== key || record.tool !== tool || record.args_hash !== hashValue(args)) {
if (record.key !== key || record.tool !== tool || record.args_hash !== args_hash) {
throw new ReplayError('tool.fixture_mismatch', `fixture ${key.slice(0, 16)} was recorded for different arguments`, { tool, key });
}
if (record.response_hash !== hashValue(record.response)) {
Expand Down
Loading
Loading