mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-06 23:24:01 +09:00
fix: retain newer canvas drafts and scope acknowledgment guidance
This commit is contained in:
4 files changed
+43
-7
No files matched your search
@@ -431,7 +431,8 @@ ${inspectorClientJs()}
|
||||
}
|
||||
async function sendChat() {
|
||||
if (ended || sending) return;
|
||||
const text = input.value.trim();
|
||||
const draft = input.value;
|
||||
const text = draft.trim();
|
||||
if (!text) { statusEl.textContent = 'Type a message first.'; return; }
|
||||
const item = { kind: 'chat', text };
|
||||
if (selection && anchorEnabled) item.anchor = { selector: selection.selector, tag: selection.tag, snippet: selection.snippet, size: selection.size };
|
||||
@@ -442,7 +443,7 @@ ${inspectorClientJs()}
|
||||
statusEl.textContent = 'Sending…';
|
||||
try {
|
||||
const body = await postFeedback([item], false);
|
||||
input.value = '';
|
||||
if (input.value === draft) input.value = '';
|
||||
statusEl.textContent = describeDelivery(body);
|
||||
if (body.presence) applyPresence(body.presence, agent);
|
||||
} catch (err) {
|
||||
@@ -463,6 +464,7 @@ ${inspectorClientJs()}
|
||||
statusEl.textContent = 'Some applied changes no longer match the file. Ask the agent to resolve them before applying more.';
|
||||
return;
|
||||
}
|
||||
const draft = input.value;
|
||||
sending = true;
|
||||
sendBtn.disabled = true;
|
||||
$('applyBtn').disabled = true;
|
||||
@@ -471,10 +473,10 @@ ${inspectorClientJs()}
|
||||
try {
|
||||
const snapshot = await requestExport();
|
||||
const item = { kind, edits: (snapshot.edits || edits).filter(edit => !edit.submitted), bakedEditIds: snapshot.bakedEditIds || [], html: snapshot.html, viewport: { preset: vp.preset, width: actual.width, height: actual.height } };
|
||||
const note = input.value.trim();
|
||||
const note = draft.trim();
|
||||
if (note) item.text = note;
|
||||
const body = await postFeedback([item], kind === 'finish');
|
||||
input.value = '';
|
||||
if (input.value === draft) input.value = '';
|
||||
if (kind === 'finish') {
|
||||
markEnded('finished');
|
||||
} else {
|
||||
|
||||
@@ -83,7 +83,12 @@ const UI_PROFILE = {
|
||||
return `The human clicked Save and Finish. Read the final markup at ${finish.exportPath} (edit log: ${finish.editsPath}), reproduce that exact look in the real component with full functionality, and report in chat. Do not reopen the canvas.`;
|
||||
}
|
||||
if (applied) {
|
||||
return `The human applied ${applied.editCount} edit(s) to the preview. Rewrite the mockup file from ${applied.exportPath} (keep it self-contained), then run \`ecc-ui-canvas await <file> --ack ${appliedItems.map(item => item.id).join(',')} --reply "<what you changed>"\` only after those batches are incorporated, to keep listening.`;
|
||||
const ackIds = [...new Set([applied.id, ...(applied.includedBatches || [])])]
|
||||
.filter(id => typeof id === 'string' && /^fb-[1-9][0-9]{0,15}$/.test(id));
|
||||
const ack = ackIds.length ? ` --ack ${ackIds.join(',')}` : '';
|
||||
const remaining = appliedItems.some(item => !ackIds.includes(item.id))
|
||||
? ' Resolve any other Apply batches separately; draining them does not acknowledge them.' : '';
|
||||
return `The human applied ${applied.editCount} edit(s) to the preview. Rewrite the mockup file from ${applied.exportPath} (keep it self-contained), then run \`ecc-ui-canvas await <file>${ack} --reply "<what you changed>"\` only after those batches are incorporated, to keep listening.${remaining}`;
|
||||
}
|
||||
if (result.sessionEnded) {
|
||||
return 'The human sent this and ended the preview. Address it and report in chat; do not reopen the canvas uninvited.';
|
||||
|
||||
@@ -29,6 +29,7 @@ function client({ boot = {}, stored = {} } = {}) {
|
||||
const node = id => { if (!nodes.has(id)) nodes.set(id, element()); return nodes.get(id); };
|
||||
node('uc-session').textContent = JSON.stringify({ key: 'abcdefabcdef', status: 'open', chat: [], presets: { desktop: { width: 1200, height: 900 } }, ...boot });
|
||||
const packets = [];
|
||||
const requests = [];
|
||||
const frame = { postMessage: packet => packets.push(packet) };
|
||||
node('artifact').contentWindow = frame;
|
||||
let saved = stored;
|
||||
@@ -42,11 +43,11 @@ function client({ boot = {}, stored = {} } = {}) {
|
||||
localStorage: { getItem: () => null, setItem() {} },
|
||||
setTimeout: () => 1, clearTimeout() {},
|
||||
EventSource: class { constructor() { events = {}; } addEventListener(type, run) { events[type] = run; } },
|
||||
fetch: () => new Promise(resolve => { answer = resolve; }),
|
||||
fetch: (url, options) => { requests.push({ url, body: JSON.parse(options.body) }); return new Promise(resolve => { answer = resolve; }); },
|
||||
};
|
||||
vm.runInNewContext(uiClientJs(), context);
|
||||
return {
|
||||
node, packets, saved: () => saved,
|
||||
node, packets, requests, saved: () => saved,
|
||||
message: data => message({ source: frame, data }),
|
||||
event: (name, data = {}) => events[name]({ data: JSON.stringify(data) }),
|
||||
answer: body => answer({ ok: true, json: async () => body }),
|
||||
@@ -102,6 +103,24 @@ async function main() {
|
||||
assert.deepEqual(h.saved().edits, [first, later]);
|
||||
assert.equal(h.packets.find(packet => packet.type === 'uc:delivery-end').accepted, false);
|
||||
});
|
||||
await test('Apply captures the original note before export and preserves newer draft input', async () => {
|
||||
const h = client(); h.node('chatInput').value = ' Original Apply note ';
|
||||
h.message({ type: 'uc:edits', edits: [first], canUndo: true }); h.node('applyBtn').handlers.click();
|
||||
h.node('chatInput').value = 'New draft while export is pending';
|
||||
const packet = h.packets.find(item => item.type === 'uc:export');
|
||||
h.message({ type: 'uc:export', requestId: packet.requestId, edits: [first], html: '<html></html>' }); await tick();
|
||||
assert.equal(h.requests[0].body.items[0].text, 'Original Apply note');
|
||||
h.answer({ batches: [{ id: 'fb-1', edits: [first] }] }); await tick();
|
||||
assert.equal(h.node('chatInput').value, 'New draft while export is pending');
|
||||
});
|
||||
await test('chat response preserves a newer draft and clears only unchanged submitted raw text', async () => {
|
||||
const h = client(); h.node('chatInput').value = ' Original chat '; h.node('send').handlers.click(); await tick();
|
||||
assert.equal(h.requests[0].body.items[0].text, 'Original chat');
|
||||
h.node('chatInput').value = 'New chat draft'; h.answer({}); await tick();
|
||||
assert.equal(h.node('chatInput').value, 'New chat draft');
|
||||
h.node('send').handlers.click(); await tick(); h.answer({}); await tick();
|
||||
assert.equal(h.node('chatInput').value, '');
|
||||
});
|
||||
await test('snapshot boundary prevents rapid nudge, style and resize coalescing', () => {
|
||||
const source = editorGesturesJs();
|
||||
const start = source.indexOf(' function nudgeBy(');
|
||||
|
||||
@@ -8,6 +8,7 @@ const http = require('node:http');
|
||||
const { execFile } = require('node:child_process');
|
||||
const { promisify } = require('node:util');
|
||||
const { createSessionStore } = require('../../scripts/lib/plan-canvas/sessions');
|
||||
const { UI_PROFILE } = require('../../scripts/ui-canvas');
|
||||
const { createPlanCanvasServer } = require('../../scripts/lib/plan-canvas/server');
|
||||
|
||||
let passed = 0;
|
||||
@@ -125,6 +126,15 @@ async function main() {
|
||||
await assert.rejects(cli('await', file, '--ack', 'fb-0'), error => { assert.match(error.stdout, /requires comma-separated UI batch IDs/); return true; });
|
||||
await assert.rejects(cli('await', file, '--ack', 'fb-999999'), error => { assert.match(error.stdout, /unknown UI batch ID/); return true; });
|
||||
}));
|
||||
await test('latest-snapshot guidance acknowledges only its batch and proven coverage', () => {
|
||||
const first = { kind: 'edits', id: 'fb-1', exportPath: '/first.html', editCount: 1 };
|
||||
const latest = { kind: 'edits', id: 'fb-2', exportPath: '/latest.html', editCount: 1, includedBatches: [] };
|
||||
const uncovered = UI_PROFILE.nextSteps.feedback({ items: [first, latest] });
|
||||
assert.match(uncovered, /--ack fb-2 --reply/); assert.doesNotMatch(uncovered, /--ack [^ ]*fb-1/);
|
||||
assert.match(uncovered, /Resolve any other Apply batches separately/);
|
||||
const covered = UI_PROFILE.nextSteps.feedback({ items: [first, { ...latest, includedBatches: ['fb-1'] }] });
|
||||
assert.match(covered, /--ack fb-2,fb-1 --reply/); assert.doesNotMatch(covered, /Resolve any other/);
|
||||
});
|
||||
console.log(`Passed: ${passed}\nFailed: ${failed}`); process.exitCode = failed ? 1 : 0;
|
||||
}
|
||||
main().catch(error => { console.error(error); process.exitCode = 1; });
|
||||
Reference in new issue
Block a user