Files
ruflo/plugins/ruflo-console/hooks/data/safe.ts
T
Dragan SpiridonovandRuflo & AQE 31c288db71 fix(console): bound CLI numbers at the reader, keep unreadable counts visible, and a resume by Claude keeps hand-out counts
Leftovers of #3817/#3822 and #3818/#3823.

Numbers from CLI JSON (#3822). JSON.parse('1e999') is Infinity; a count can
also be negative, fractional or absurd. Bounded where read with data/safe.ts
countOf / ratioOf and a new measureOf (finite, within +-1e12):
- secure.ts scanReader: every severity count and the total are at least
  the listed findings, so a summary never reads CLEAN beside a listed
  finding. A count or total the tool printed but no reader can trust stays
  UNKNOWN (SecFindings.unreadable / isTotalUnknown), with the listed
  findings only as its lower bound: "critical ?" / "high ≥2 ?",
  "? findings (total unreadable)", COUNTS UNREADABLE. securityBand() is the
  one rule for the band (views/bar.ts) and the menu badge (menu-style.ts):
  it warns on high/critical ("N+" when anything is unknown) and on any
  unknown count or total. Threat confidence via ratioOf, composition score via measureOf.
  The verdict-exit judgement (#3934, SCAN_FOUND/countsWith) is unchanged.
- Same class swept in perf.ts, mh-lab.ts (labLines cells, gepa chars,
  genome ids, receipts), neural.ts, memory-lines.ts,
  data/evolve.ts, data/research.ts and data/cli.ts.

Mission resume (#3823). setPaused takes who resumed. The mission-resume
palette entry built inside Claude's console_run (state.control.viaModel)
resumes as 'model': hand-out counts are kept and an advisor stop-the-line
is not re-opened, so an exhausted task gets no new billed hand-out. The
person's resume (page buttons, palette, a typed /ruflo run) still gives
every task its hand-outs back.

Co-Authored-By: Ruflo & AQE
Claude-Session: https://claude.ai/code/session_01CGoza3gyxBjpaiMPhGHcHs
2026-10-10 10:57:58 -04:00

40 lines
2.9 KiB
TypeScript

/**
* Values from files and CLI answers that another process wrote: a time past what `Date` holds, a negative, fractional-hostile or infinite
* count, a ratio outside 0..1. Each helper answers undefined (or text) for what it will not draw, and none throws (#3817). A leaf: no imports.
*/
/** The edge of what `Date` can hold: a time past it makes `toISOString()` throw, so no reader keeps one (#3817). */
export const MAX_TIME_MS = 8.64e15
/** The largest count any view draws: a hostile 1e300 is clamped, never a display value. */
export const MAX_COUNT = 1e12
/** A time in epoch milliseconds that `Date` can hold, else undefined. */
export const timeOf = (value: unknown): number | undefined => (typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= MAX_TIME_MS ? value : undefined)
/** A time as ISO text, clamped to `Date`'s range; 'n/a' for anything that is not a finite number. It never throws. */
export const isoOf = (value: unknown): string => (typeof value === 'number' && Number.isFinite(value) ? new Date(Math.min(MAX_TIME_MS, Math.max(-MAX_TIME_MS, value))).toISOString() : 'n/a')
/** A whole, non-negative count capped at MAX_COUNT, else undefined (a negative, fractional-hostile, NaN or infinite value is not a count). */
export const countOf = (value: unknown): number | undefined => (typeof value === 'number' && Number.isFinite(value) && value >= 0 ? Math.min(Math.floor(value), MAX_COUNT) : undefined)
/** A signed measurement (a score, a lift, a latency, a percentage) that is finite and within ±MAX_COUNT, else undefined: never "Infinity" or "1e+300" on screen (#3822). */
export const measureOf = (value: unknown): number | undefined => (typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= MAX_COUNT ? value : undefined)
/** A ratio clamped to 0..1, else undefined. */
export const ratioOf = (value: unknown): number | undefined => (typeof value === 'number' && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : undefined)
/** A value keyed by a name a file or the CLI supplied: an OWN key only, so `toString`, `constructor` or `__proto__` read as absent, never as a function. */
export const own = <T>(record: Readonly<Record<string, T>>, key: unknown): T | undefined => (typeof key === 'string' && Object.hasOwn(record, key) ? record[key] : undefined)
/** 2000-01-01T00:00:00Z: no ruflo file was written before it. */
const EARLIEST_MS = 946_684_800_000
/** How far ahead of now a write time may be (a clock a little ahead) before it is not believed. */
const FUTURE_SLACK_MS = 86_400_000
/**
* A write time fit to say "N ago" about: from 2000 to a day past now, else undefined (shown as n/a). timeOf alone admits ±8.64e15, which read
* "100020735d ago", and a time in the future, which read "0s ago".
*/
export const sinceOf = (ms: number | null | undefined, nowMs: number): number | undefined =>
typeof ms === 'number' && Number.isFinite(ms) && ms >= EARLIEST_MS && ms <= nowMs + FUTURE_SLACK_MS ? ms : undefined