Add ifStuck/stop to frames and captured date to sequences (Refs #23)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 12:24:35 -05:00
parent 32d4b06096
commit 29f44440ca
6 changed files with 45 additions and 6 deletions

View File

@@ -29,7 +29,10 @@ import { isImageDataUrl, MAX_IMAGE_DATA_CHARS } from './images.js';
// Item: { id, text, status: 'open'|'done'|'tbd', detail?: string } // Item: { id, text, status: 'open'|'done'|'tbd', detail?: string }
// Sequence (visual sequence): { id, kind: 'sequence', title, updated: 'YYYY-MM-DD', // Sequence (visual sequence): { id, kind: 'sequence', title, updated: 'YYYY-MM-DD',
// frames: [Frame] } -- a numbered series of pictures with optional text. // frames: [Frame] } -- a numbered series of pictures with optional text.
// Frame: { image: PNG/JPEG data URL or '', text, layout: 'right'|'under'|'none', secret?: boolean } // Frame: { image: PNG/JPEG data URL or '', text, layout: 'right'|'under'|'none', secret?: boolean,
// ifStuck?: string, what to do if the screen looks different or the step fails
// stop?: boolean } "stop here and call someone" marker; ifStuck says who/why
// A sequence may also carry `captured: 'YYYY-MM-DD'`, set when a step is captured from the screen.
// A sequence lives in the same ordered list as the records (records sections) or // A sequence lives in the same ordered list as the records (records sections) or
// items (steps / checklist sections), so it sits wherever the user puts it, but it // items (steps / checklist sections), so it sits wherever the user puts it, but it
// is not a record or an item (no number, no tick box). A 'text' section keeps its // is not a record or an item (no number, no tick box). A 'text' section keeps its
@@ -184,6 +187,7 @@ export function validate(doc) {
if (q.kind !== 'sequence') errs.push(`${where}: kind must be "sequence"`); if (q.kind !== 'sequence') errs.push(`${where}: kind must be "sequence"`);
if (!isStr(q.title) || !q.title) errs.push(`${where}: missing title`); if (!isStr(q.title) || !q.title) errs.push(`${where}: missing title`);
if (!DATE_RE.test(q.updated ?? '')) errs.push(`${where}: updated must be YYYY-MM-DD`); if (!DATE_RE.test(q.updated ?? '')) errs.push(`${where}: updated must be YYYY-MM-DD`);
if (q.captured !== undefined && !DATE_RE.test(q.captured)) errs.push(`${where}: captured must be YYYY-MM-DD`);
if (!Array.isArray(q.frames)) return errs.push(`${where}: frames must be an array`); if (!Array.isArray(q.frames)) return errs.push(`${where}: frames must be an array`);
q.frames.forEach((f, k) => { q.frames.forEach((f, k) => {
const fw = `${where}.frames[${k}]`; const fw = `${where}.frames[${k}]`;
@@ -193,6 +197,8 @@ export function validate(doc) {
if (!isStr(f.text)) errs.push(`${fw}: text must be a string`); if (!isStr(f.text)) errs.push(`${fw}: text must be a string`);
if (!FRAME_LAYOUTS.includes(f.layout)) errs.push(`${fw}: bad layout "${f.layout}"`); if (!FRAME_LAYOUTS.includes(f.layout)) errs.push(`${fw}: bad layout "${f.layout}"`);
if (f.secret !== undefined && typeof f.secret !== 'boolean') errs.push(`${fw}: secret must be a boolean`); if (f.secret !== undefined && typeof f.secret !== 'boolean') errs.push(`${fw}: secret must be a boolean`);
if (f.ifStuck !== undefined && !isStr(f.ifStuck)) errs.push(`${fw}: ifStuck must be a string`);
if (f.stop !== undefined && typeof f.stop !== 'boolean') errs.push(`${fw}: stop must be a boolean`);
}); });
} }

View File

@@ -184,7 +184,7 @@ export function allSequences(doc) {
// and the secret flags stay). Returns how many values were erased. // and the secret flags stay). Returns how many values were erased.
export function clearSecrets(doc) { export function clearSecrets(doc) {
let n = 0; let n = 0;
const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim())) { f.image = ''; f.text = ''; n++; } }; const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim() || String(f.ifStuck || '').trim())) { f.image = ''; f.text = ''; if (f.ifStuck) f.ifStuck = ''; n++; } };
for (const s of doc.sections) { for (const s of doc.sections) {
for (const r of s.records || []) { for (const r of s.records || []) {
if (isSequence(r)) frames(r); if (isSequence(r)) frames(r);
@@ -217,6 +217,14 @@ export function addFrame(seq, image = '', layout = 'under') {
return f; return f;
} }
// A step captured from the screen: a new frame, and the sequence remembers when,
// so the reader can be told the site may have changed since.
export function addCapture(seq, image) {
const f = addFrame(seq, image);
seq.captured = today();
return f;
}
// ---- what a section holds (for the delete confirmation) ---- // ---- what a section holds (for the delete confirmation) ----
export function sectionContents(section) { export function sectionContents(section) {
const c = { records: 0, items: 0, sequences: 0, images: 0, text: false }; const c = { records: 0, items: 0, sequences: 0, images: 0, text: false };

View File

@@ -46,19 +46,21 @@ export function frameLayout(frame) {
// What to show for a frame. A secret frame (picture and text) is withheld // What to show for a frame. A secret frame (picture and text) is withheld
// unless secrets are included; a frame with nothing in it is never "withheld". // unless secrets are included; a frame with nothing in it is never "withheld".
export function frameView(frame, includeSecrets) { export function frameView(frame, includeSecrets) {
const hasContent = !!(frame.image || String(frame.text || '').trim()); const hasContent = !!(frame.image || String(frame.text || '').trim() || String(frame.ifStuck || '').trim());
const withheld = !!frame.secret && !includeSecrets && hasContent; const withheld = !!frame.secret && !includeSecrets && hasContent;
return { return {
withheld, withheld,
image: withheld ? '' : frame.image, image: withheld ? '' : frame.image,
text: withheld ? '' : frame.text, text: withheld ? '' : frame.text,
ifStuck: withheld ? '' : String(frame.ifStuck || '').trim(),
stop: withheld ? false : !!frame.stop,
layout: withheld ? 'none' : frameLayout(frame), layout: withheld ? 'none' : frameLayout(frame),
}; };
} }
export function countSecrets(doc) { export function countSecrets(doc) {
let n = 0; let n = 0;
const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim())) n++; }; const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim() || String(f.ifStuck || '').trim())) n++; };
for (const s of doc.sections) { for (const s of doc.sections) {
for (const r of s.records || []) { for (const r of s.records || []) {
if (isSequence(r)) frames(r); if (isSequence(r)) frames(r);

View File

@@ -2,7 +2,7 @@
// YYMMDD is the date, X the iteration that day (A first, B second, ...). // YYMMDD is the date, X the iteration that day (A first, B second, ...).
// Bump with `npm run bump` (see bump-version.js). build.js strips `export`. // Bump with `npm run bump` (see bump-version.js). build.js strips `export`.
export const APP_VERSION = '261123A'; export const APP_VERSION = '261124A';
const VERSION_RE = /^(\d{6})([A-Z])$/; const VERSION_RE = /^(\d{6})([A-Z])$/;
export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v); export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);

View File

@@ -104,6 +104,9 @@ test('sequence validation: layout, image, text, secret, id, title', () => {
bad((x) => { x.frames[0].image = 5; }, /image must be a string/); bad((x) => { x.frames[0].image = 5; }, /image must be a string/);
bad((x) => { x.frames[0].text = null; }, /text must be a string/); bad((x) => { x.frames[0].text = null; }, /text must be a string/);
bad((x) => { x.frames[0].secret = 'yes'; }, /secret must be a boolean/); bad((x) => { x.frames[0].secret = 'yes'; }, /secret must be a boolean/);
bad((x) => { x.frames[0].ifStuck = 5; }, /ifStuck must be a string/);
bad((x) => { x.frames[0].stop = 'yes'; }, /stop must be a boolean/);
bad((x) => { x.captured = 'yesterday'; }, /captured must be YYYY-MM-DD/);
bad((x) => { x.title = ''; }, /missing title/); bad((x) => { x.title = ''; }, /missing title/);
bad((x) => { x.id = d.sections[0].records[0].id; }, /duplicate id/); bad((x) => { x.id = d.sections[0].records[0].id; }, /duplicate id/);
bad((x) => { delete x.frames; }, /frames must be an array/); bad((x) => { delete x.frames; }, /frames must be an array/);
@@ -116,8 +119,11 @@ test('frameLayout hides empty text; frameView withholds secret frames only when
assert.equal(frameLayout({ layout: 'right', text: 'x' }), 'right'); assert.equal(frameLayout({ layout: 'right', text: 'x' }), 'right');
assert.equal(frameLayout({ layout: 'none', text: 'x' }), 'none'); assert.equal(frameLayout({ layout: 'none', text: 'x' }), 'none');
const f = { image: PNG, text: 'pw is hunter2', layout: 'under', secret: true }; const f = { image: PNG, text: 'pw is hunter2', layout: 'under', secret: true };
assert.deepEqual(frameView(f, false), { withheld: true, image: '', text: '', layout: 'none' }); assert.deepEqual(frameView(f, false), { withheld: true, image: '', text: '', ifStuck: '', stop: false, layout: 'none' });
assert.equal(frameView(f, true).text, 'pw is hunter2'); assert.equal(frameView(f, true).text, 'pw is hunter2');
const g = { image: PNG, text: '', layout: 'none', ifStuck: ' call 555-0100 ', stop: true };
assert.deepEqual([frameView(g, false).ifStuck, frameView(g, false).stop], ['call 555-0100', true]);
assert.deepEqual([frameView({ ...g, secret: true }, false).ifStuck, frameView({ ...g, secret: true }, false).stop], ['', false]);
assert.equal(frameView({ image: '', text: '', layout: 'under', secret: true }, false).withheld, false); assert.equal(frameView({ image: '', text: '', layout: 'under', secret: true }, false).withheld, false);
}); });

View File

@@ -345,3 +345,20 @@ test('clearSecrets erases secret fields and frames, keeps the rest, returns the
assert.deepEqual(validate(doc), []); assert.deepEqual(validate(doc), []);
assert.equal(clearSecrets(doc), 0); assert.equal(clearSecrets(doc), 0);
}); });
test('addCapture adds a frame and stamps the sequence captured date; clearSecrets clears ifStuck on secret steps', async () => {
const { addCapture, clearSecrets, addSequence } = await import('../src/ops.js');
const doc = emptyDocument('x');
const s = addSection(doc, 'records', 'Banking');
const q = addSequence(doc, s);
assert.equal(q.captured, undefined);
const f = addCapture(q, '');
assert.equal(q.frames.length, 1);
assert.equal(f.layout, 'under');
assert.match(q.captured, /^\d{4}-\d{2}-\d{2}$/);
f.secret = true; f.ifStuck = 'call 555-0100'; f.stop = true;
assert.equal(clearSecrets(doc), 1);
assert.equal(f.ifStuck, '');
assert.equal(f.stop, true);
assert.deepEqual(validate(doc), []);
});