diff --git a/scripts/pm/post-stamped.mjs b/scripts/pm/post-stamped.mjs index 0064873bb65..b26f1c68b1b 100644 --- a/scripts/pm/post-stamped.mjs +++ b/scripts/pm/post-stamped.mjs @@ -47,6 +47,9 @@ * else. The author knows the token and typed a time anyway; that * typed one is the estimate. This is the case the filing card * names by hand. + * QUOTED a `{{WAS:…}}` value is not one stamp and nothing else, or names + * an instant LATER than the clock this act holds. See the + * direction section below. * UNKNOWN a `{{…}}` token survives substitution. A mistyped `{{now}}` * would otherwise post literally AND leave the artefact * unstamped, which is the quiet direction. @@ -56,6 +59,35 @@ * `{{NOW}}` is never refused — so mixed alone would not have caught the * recorded failure, whose comments carried no token at all. * + * ## The quoted route has a DIRECTION, not only a shape (#17763) + * + * Checking that a `{{WAS:…}}` value is shaped like a stamp leaves the estimate + * spellable through the one escape this tool offers by name: a seat whose sense + * of elapsed time runs AHEAD types its guess, is refused positionally, and the + * refusal's own second option takes that same guess unchanged. The recorded + * failures were forward-skewed, which is exactly the half a shape check cannot + * see. So a quoted value is judged against the clock this act holds as well: + * the quoted route renders a reading of something ELSE, and an instant that has + * not happened yet is provably not a reading of anything. + * + * The boundary, because the format is minute-grained: a stamp names the SPAN of + * its own grain (`stampSpan`, imported — the same widening H56 makes before it + * measures drift), and the value is a possible reading exactly while that span + * has STARTED. So a stamp equal to the act's own minute is ACCEPTED — a reading + * taken at any instant inside this minute is spelled exactly that way — and the + * refusal begins at the first minute whose start the clock has not reached. + * + * ⛔ There is no skew tolerance, and `H56_STAMP_TOLERANCE_MIN` is not one. + * That number measures how far a WRITE may land after the read it carries — a + * backward gap on the read side. Spending it forward here would reopen a + * quarter-hour window on the very direction the recorded failures took. + * + * The same judgement corrects what the OTHER refusals offer: the positional and + * mixed texts hand the seat `{{WAS:}}` with the stamp filled + * in, so when that stamp is in the future they must stop offering a route that + * will refuse it — a refusal text prescribing a refused remedy is a tool + * arguing with itself. + * * A bare stamp OUTSIDE those two positions is passed through with a note on * stderr rather than refused: prose quoting a ruling's date is a reading of * something else, and refusing it would push seats back onto the channel this @@ -98,6 +130,7 @@ import { proxyRearmPlan, resolveSweepRepo, stampDriftMinutes, + stampSpan, } from './check-half-states.mjs'; const SELF_PATH = fileURLToPath(import.meta.url); @@ -158,35 +191,75 @@ export function quotedStampValues(text) { return out; } +/** + * Whether `stamp` names an instant the clock this act holds has NOT reached. + * + * The stamp is widened to its own grain first (`stampSpan`, imported rather + * than re-derived — H56 measures drift against the same span, and two spellings + * of "which minute is this" would let the write side and the read side disagree + * about the boundary). A value is a possible reading exactly while its span has + * started, so the current minute is accepted and the next one is not. + * + * An unparseable value is NOT future — it is the shape refusal's business, and + * answering `true` here would file one typo under two kinds. + */ +export function stampIsFuture(stamp, nowMs = Date.now()) { + const span = stampSpan(String(stamp ?? '').trim()); + return span !== null && span.from > nowMs; +} + /** * Every reason this body may not be posted, in the order a reader should fix * them. An empty array is a body that may be written. + * + * `nowMs` is the clock the WRITING act holds — the same one `renderBody` + * substitutes, passed through so the direction check judges against the instant + * this body is being written at, never a second read taken later. */ -export function stampRefusals(text) { +export function stampRefusals(text, nowMs = Date.now()) { const raw = String(text ?? ''); const masked = maskQuotedStamps(raw); const refusals = []; + const now = stampNow(nowMs); for (const value of quotedStampValues(raw)) { - if (protocolStamps(value).length === 1 && protocolStamps(value)[0] === value.trim()) continue; + if (protocolStamps(value).length !== 1 || protocolStamps(value)[0] !== value.trim()) { + refusals.push({ + kind: 'quoted-not-a-stamp', + detail: + `\`{{WAS:${value}}}\` does not declare a stamp. The quoted route renders a reading of ` + + 'something else VERBATIM, so its contents must be one `YYYY-MM-DDThh:mmZ` and nothing else — ' + + 'it is a declaration, not a free-text escape from the contract.', + }); + continue; + } + if (!stampIsFuture(value, nowMs)) continue; refusals.push({ - kind: 'quoted-not-a-stamp', + kind: 'quoted-in-the-future', detail: - `\`{{WAS:${value}}}\` does not declare a stamp. The quoted route renders a reading of ` + - 'something else VERBATIM, so its contents must be one `YYYY-MM-DDThh:mmZ` and nothing else — ' + - 'it is a declaration, not a free-text escape from the contract.', + `\`{{WAS:${value}}}\` declares an instant LATER than the clock this act holds (\`${now}\`). The ` + + 'quoted route renders a reading of something ELSE verbatim, and a time that has not happened yet ' + + 'is provably not a reading of anything — it is an estimate with a declaration wrapped round it, ' + + `which is the defect this tool exists to make unspellable. Write \`${STAMP_TOKEN}\` if it is this ` + + 'act\'s own clock, or correct the value to the instant that was actually read. There is no skew ' + + 'tolerance here, forward: a stamp the clock has not reached is not nearly a reading.', }); } const positional = h56StampedReadings(masked); for (const hit of positional) { + const opener = + `${hit.where} carries the bare stamp \`${hit.stamp}\`. That position belongs to the writing ` + + 'act, so a stamp typed there is the act\'s own time written from memory — the defect this tool ' + + 'exists to make unspellable. '; refusals.push({ kind: 'positional', - detail: - `${hit.where} carries the bare stamp \`${hit.stamp}\`. That position belongs to the writing ` + - 'act, so a stamp typed there is the act\'s own time written from memory — the defect this tool ' + - `exists to make unspellable. Write \`${STAMP_TOKEN}\` there, or \`{{WAS:${hit.stamp}}}\` if it ` + - 'is genuinely a reading of something else.', + detail: stampIsFuture(hit.stamp, nowMs) + ? `${opener}Write \`${STAMP_TOKEN}\` there. The quoted route is NOT open to this one: ` + + `\`${hit.stamp}\` is later than the clock this act holds (\`${now}\`), so it cannot be a reading ` + + 'of something else either.' + : `${opener}Write \`${STAMP_TOKEN}\` there, or \`{{WAS:${hit.stamp}}}\` if it ` + + 'is genuinely a reading of something else.', }); } @@ -195,13 +268,18 @@ export function stampRefusals(text) { for (const stamp of protocolStamps(masked)) { if (seen.has(stamp)) continue; seen.add(stamp); + const opener = + `this body uses \`${STAMP_TOKEN}\` and also carries the bare stamp \`${stamp}\`. One of the ` + + 'two clocks was read by this act and the other was typed; a reader cannot tell which. '; refusals.push({ kind: 'mixed', - detail: - `this body uses \`${STAMP_TOKEN}\` and also carries the bare stamp \`${stamp}\`. One of the ` + - 'two clocks was read by this act and the other was typed; a reader cannot tell which. Declare ' + - `it with \`{{WAS:${stamp}}}\` if it is a quoted reading, or make it \`${STAMP_TOKEN}\` if it ` + - 'is this act\'s own.', + detail: stampIsFuture(stamp, nowMs) + ? `${opener}Make it \`${STAMP_TOKEN}\` if it is this act's own. The quoted route is NOT open to ` + + `it: \`${stamp}\` is later than the clock this act holds (\`${now}\`), so it cannot be a ` + + 'reading of something else either.' + : `${opener}Declare ` + + `it with \`{{WAS:${stamp}}}\` if it is a quoted reading, or make it \`${STAMP_TOKEN}\` if it ` + + 'is this act\'s own.', }); } } @@ -216,8 +294,9 @@ export function refusalText(refusals) { `post-stamped: REFUSED — ${rows.length} stamp-contract problem(s) in the body. Nothing was written.\n` + `${rows.join('\n')}\n\n` + ` The contract has exactly two spellings: \`${STAMP_TOKEN}\` for the clock this act reads, and\n` + - ' `{{WAS:YYYY-MM-DDThh:mmZ}}` for a stamp that is a reading of something else. There is no flag\n' + - ' that turns it off — a stamp typed from memory is the defect, not a formatting preference.' + ' `{{WAS:YYYY-MM-DDThh:mmZ}}` for a stamp that is a reading of something else — an instant the\n' + + ' clock has already reached, since nothing can be read out of the future. There is no flag that\n' + + ' turns it off — a stamp typed from memory is the defect, not a formatting preference.' ); } @@ -236,7 +315,7 @@ export function renderBody(text, nowMs = Date.now()) { ' reader has to judge; supply a body with --file=PATH or on stdin.', }; } - const refusals = stampRefusals(raw); + const refusals = stampRefusals(raw, nowMs); if (refusals.length > 0) return { ok: false, kind: 'stamp-contract', refusals, error: refusalText(refusals) }; const stamp = stampNow(nowMs); @@ -438,7 +517,8 @@ const USAGE = [ ' With no --file the body is read from stdin.', ` In the body: \`${STAMP_TOKEN}\` is the clock this run reads; \`{{WAS:YYYY-MM-DDThh:mmZ}}\` declares a`, ' stamp that is a reading of something else. A bare stamp on the opening line, or on a subscript', - ' reading-time line, is REFUSED — that position belongs to the writing act.', + ' reading-time line, is REFUSED — that position belongs to the writing act. A quoted stamp LATER', + ' than the clock this run reads is REFUSED too — the future is not a thing anyone read.', ' The attribution footer is the caller\'s: its form differs by channel and act, so this tool adds none.', ].join('\n'); @@ -550,12 +630,13 @@ async function main(argv) { const SELF_TEST_BATTERIES = Object.freeze({ 'the token contract: the two spellings, and nothing else': 9, 'the refusals: every route that must not reach the board': 20, + 'the direction check: a stamp no act can have read': 22, 'the substitution: one clock, read once, written everywhere': 9, 'the read-back: what the transcript can actually prove': 11, 'the CLI: the one decision a typo must never make': 12, 'the shared rule: this tool and H56 cannot come to disagree': 6, }); -const SELF_TEST_BATTERY_FLOOR = 6; +const SELF_TEST_BATTERY_FLOOR = 7; const UNATTRIBUTED_BATTERY = '(unattributed)'; let selfTestReachedVerdict = false; @@ -574,7 +655,7 @@ export function selfTest() { }; const NOW_MS = Date.parse('2026-09-10T06:37:48Z'); - const kinds = (text) => stampRefusals(text).map((r) => r.kind); + const kinds = (text, ms) => stampRefusals(text, ms).map((r) => r.kind); battery('the token contract: the two spellings, and nothing else'); t('the act-clock token is `{{NOW}}`', STAMP_TOKEN === '{{NOW}}'); @@ -610,6 +691,36 @@ export function selfTest() { t('…and states that no flag turns the contract off', refusalText(stampRefusals(OPENING)).includes('There is no flag')); t('…and that nothing was written', refusalText(stampRefusals(OPENING)).includes('Nothing was written')); + // The clock this act holds is 06:37:48 — so 06:37Z is the minute it is IN, + // 06:38Z the first minute it has not reached, and 06:51Z sits 14 minutes + // ahead, inside H56's drift tolerance and still not a thing anyone read. + battery('the direction check: a stamp no act can have read'); + const CARD_REPRO = 'Verdict {{NOW}} — on the board read {{WAS:2099-01-01T00:00Z}}.'; + t('⭐ the filed repro: a 2099 quoted stamp is REFUSED, not rendered verbatim', kinds(CARD_REPRO, NOW_MS).includes('quoted-in-the-future')); + t('…and the refusal names the clock it was judged against', stampRefusals(CARD_REPRO, NOW_MS)[0]?.detail?.includes('2026-09-10T06:37Z') === true); + t('…and says a time that has not happened is not a reading of anything', stampRefusals(CARD_REPRO, NOW_MS)[0]?.detail?.includes('provably not a reading of anything') === true); + t('⭐ …so the whole body is refused and NOTHING is rendered', renderBody(CARD_REPRO, NOW_MS).ok === false && renderBody(CARD_REPRO, NOW_MS).body === undefined); + t('⛔ a PAST quoted stamp is untouched — the route this closes is one direction only', renderBody('Verdict {{NOW}} — on the board read {{WAS:2026-09-08T14:00Z}}.', NOW_MS).body?.includes('board read 2026-09-08T14:00Z.') === true); + t('⭐ BOUNDARY: a stamp equal to the act\'s OWN minute is ACCEPTED — a reading taken inside 06:37 is spelled 06:37Z', stampRefusals('read {{WAS:2026-09-10T06:37Z}}', NOW_MS).length === 0); + t('⭐ …and the first minute the clock has NOT reached is refused', kinds('read {{WAS:2026-09-10T06:38Z}}', NOW_MS).includes('quoted-in-the-future')); + t('…the acceptance opens ON the tick: a clock standing exactly at 06:37:00 accepts 06:37Z', stampRefusals('read {{WAS:2026-09-10T06:37Z}}', Date.parse('2026-09-10T06:37:00Z')).length === 0); + t('…and one millisecond before it does not — the span must have STARTED, not be about to', kinds('read {{WAS:2026-09-10T06:37Z}}', Date.parse('2026-09-10T06:37:00Z') - 1).includes('quoted-in-the-future')); + t('⛔ no forward skew window: 14 minutes ahead is refused though H56 tolerates 14 minutes of DRIFT', kinds('read {{WAS:2026-09-10T06:51Z}}', NOW_MS).includes('quoted-in-the-future') && H56_STAMP_TOLERANCE_MIN === 15); + t('the grain is the stamp\'s own: 06:37:49Z is one second ahead of 06:37:48 and is refused', kinds('read {{WAS:2026-09-10T06:37:49Z}}', NOW_MS).includes('quoted-in-the-future')); + t('…while the same instant spelled to the minute is not', stampRefusals('read {{WAS:2026-09-10T06:37Z}}', NOW_MS).length === 0); + t('⛔ a shape failure is NOT also filed as a direction one — one typo, one refusal', kinds('{{WAS:2099-01-01T00:00Z ruling}}', NOW_MS).join() === 'quoted-not-a-stamp'); + t('…and the shape refusals still fire, unchanged', kinds('{{WAS:yesterday}}', NOW_MS).includes('quoted-not-a-stamp')); + t('an unreadable value is nobody\'s idea of the future', stampIsFuture('yesterday', NOW_MS) === false); + t('⭐ the `{{NOW}}` route is untouched: a token-only body still renders on this act\'s clock', renderBody('Claim: {{NOW}} — dispatched.', NOW_MS).body === 'Claim: 2026-09-10T06:37Z — dispatched.'); + const POSITIONAL_FUTURE = 'Claim: skills seat, 2099-01-01T00:00Z — dispatched.'; + t('⭐ the POSITIONAL refusal stops handing a future estimate back through the quoted route', stampRefusals(POSITIONAL_FUTURE, NOW_MS)[0]?.detail?.includes('{{WAS:2099-01-01T00:00Z}}') === false); + t('…and says instead that the stamp is later than the clock this act holds', stampRefusals(POSITIONAL_FUTURE, NOW_MS)[0]?.detail?.includes('later than the clock this act holds') === true); + t('…while a PAST typed stamp is still offered the quoted route, which is the whole control', stampRefusals(OPENING, NOW_MS)[0]?.detail?.includes('{{WAS:2026-09-10T06:37Z}}') === true); + const MIXED_FUTURE = 'Claim: {{NOW}}\n\nThe board was read at 2099-01-01T00:00Z.'; + t('the MIXED refusal likewise stops offering a route that would refuse it', stampRefusals(MIXED_FUTURE, NOW_MS).find((r) => r.kind === 'mixed')?.detail?.includes('{{WAS:2099-01-01T00:00Z}}') === false); + t('…and a past bare stamp keeps the declaration on offer', stampRefusals('Claim: {{NOW}}\n\nread 2026-09-08T14:00Z', NOW_MS).find((r) => r.kind === 'mixed')?.detail?.includes('{{WAS:2026-09-08T14:00Z}}') === true); + t('⛔ the clock defaults to Date.now() rather than to "no judgement" when a caller omits it', stampRefusals('read {{WAS:2099-01-01T00:00Z}}').map((r) => r.kind).includes('quoted-in-the-future')); + battery('the substitution: one clock, read once, written everywhere'); const TWO = renderBody('Claim: {{NOW}}\n\nRound opened {{NOW}}.', NOW_MS); t('a body that clears the contract renders', TWO.ok === true);