Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions apps/client/src/surfaces/blocks/selection-hygiene.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const rel: RelevantEntity = { entity: linkEntity, score: 1, moments: [] }
const relNode = render(relBlock, [rel])

const todoBlock: Block = { block: 'todos', show: 'always', query: { source: 'todos', params: { session: 'current' } }, actions: copyAction }
const todo: TodoItem = { id: 't1', text: 'Send Dana the signed MSA', createdAt: '2026-07-16T14:40:00Z', provenance: { sessionId: 'ses', distillateId: 'dst-9' } }
// Carries a due so the deadline decoration ("due 3:29p") is in the row — it must NOT ride into a selection.
const todo: TodoItem = { id: 't1', text: 'Send Dana the signed MSA', due: '2026-07-16T15:29:00Z', createdAt: '2026-07-16T14:40:00Z', provenance: { sessionId: 'ses', distillateId: 'dst-9', dueSource: 'model' } }
const todoNode = render(todoBlock, [todo])

const distBlock: Block = { block: 'distillates', show: 'always', query: { source: 'distillates', params: {} }, actions: copyAction }
Expand Down Expand Up @@ -117,7 +118,7 @@ test('a native selection of a distillates (transcript) row keeps the bare value
test('the classes this test relies on are non-selectable in the ACTUAL stylesheet (by-construction guard)', () => {
// Derived from styles.ts / panel-styles.ts, not hardcoded — removing any of these rules fails BOTH this
// assertion and the equality tests above (the decoration text would leak into selectableText).
for (const cls of ['why', 'ext', 'mk', 'glbl', 'go', 'dot', 't', 'unans', 'in-cites', 'in-who']) {
for (const cls of ['why', 'ext', 'due', 'mk', 'glbl', 'go', 'dot', 't', 'unans', 'in-cites', 'in-who']) {
assert.ok(suppressed.has(cls), `.${cls} must be non-selectable`)
}
})
Expand Down
22 changes: 22 additions & 0 deletions apps/client/src/surfaces/blocks/todos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import type { QueryResult, Surface, TodoItem } from '@openinfo/contracts'
import { renderSurface, renderToHtml, type NowContext } from '../block-renderer/index.js'
import { defaultBlockRegistry } from './index.js'

// clockLabel renders viewer-local; pin this process to UTC so the due-time assertion below is host-stable.
process.env.TZ = 'UTC'

const now: NowContext = { live: true, workspace: 'acme', title: 'Renewal — security review' }
const result = (items: unknown[]): QueryResult => ({ source: 'todos', items, truncated: false })

Expand Down Expand Up @@ -62,6 +65,25 @@ test('the todos block renders STORE-DERIVED items: text, done status and a prove
assert.match(html, /<button class="mini ghost" data-verb="mark-done" data-action="a-done">Done<\/button>/)
})

test('a due deadline renders as an honest "due <time>" decoration; absent/invalid due ⇒ no decoration; copy stays bare text (#179)', () => {
const items = [
todo('t1', 'Give QA feedback', { due: '2026-07-16T15:18:00Z', provenance: { sessionId: 'ses', distillateId: 'dst-1', dueSource: 'model' } }),
todo('t2', 'Send the deck'), // no due → no decoration
todo('t3', 'Broken deadline', { due: 'not-a-time' }), // unparseable → no decoration (never a placeholder)
]
const html = renderToHtml(
renderSurface({ surface, now, results: [undefined, result(items)] }, defaultBlockRegistry),
)
// the deadline shows as a compact clock decoration on the row (UTC-pinned: 15:18 → 3:18p)
assert.match(html, /class="due">due 3:18p/)
// exactly one due decoration — the no-due and the invalid-due rows render none
assert.equal(html.match(/class="due"/g)?.length, 1)
// the copy payload is the BARE task text — the due time never rides into a copy (negative guard)
assert.match(html, /data-copy="Give QA feedback"/)
assert.doesNotMatch(html, /data-copy="[^"]*3:18p[^"]*"/)
assert.doesNotMatch(html, /data-copy="[^"]*due[^"]*"/)
})

test('empty is EXPLAINABLE, not silent: an always-visible todos block renders a no-follow-ups line', () => {
const html = renderToHtml(
renderSurface({ surface, now, results: [undefined, result([])] }, defaultBlockRegistry),
Expand Down
17 changes: 16 additions & 1 deletion apps/client/src/surfaces/blocks/todos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Block, TodoItem } from '@openinfo/contracts'
import { h, type VNode } from '../block-renderer/vnode.js'
import type { BlockRenderer } from '../block-renderer/registry.js'
import { clockLabel } from '../block-renderer/format.js'
import { stateDot, resolveStateVocab, type StateVocab } from '../block-renderer/micro-state.js'
import { rowAffordances, type ActionPayload } from './actions.js'

Expand Down Expand Up @@ -29,6 +30,20 @@ const whyLine = (item: TodoItem): string => {
return item.done === true ? `done · ${origin}` : origin
}

/**
* The due decoration (#179): a follow-up with a resolved deadline shows it as "due 3:29p" (the same
* compact clockLabel the summary/transcript rows use). Rendered ONLY when the item carries a `due` that
* parses to a real wall-clock — an absent or unparseable due yields NO decoration, never a placeholder
* or fake time. It states the deadline plainly, with no urgency dressing (no colour, no "overdue!",
* no exclamation) — honest whether the time is ahead or already past. The span is user-select:none (see
* styles.ts): the deadline is decoration, so a native selection of the row keeps only the bare task text.
*/
const dueDecoration = (item: TodoItem): VNode | false => {
if (item.due === undefined) return false
const label = clockLabel(item.due)
return label.length > 0 ? h('span', { class: 'due' }, `due ${label}`) : false
}

const todoRow = (item: TodoItem, actions: Actions, vocab: StateVocab, dismissBase: DismissBase): VNode => {
const done = item.done === true
// mark-done addresses PUT /todos/:sessionId. The flattened query row keeps the item's provenance, and
Expand All @@ -48,7 +63,7 @@ const todoRow = (item: TodoItem, actions: Actions, vocab: StateVocab, dismissBas
h(
'span',
{ class: 'body' },
h('span', { class: done ? 'ttl done' : 'ttl' }, stateDot(item.state, vocab), item.text),
h('span', { class: done ? 'ttl done' : 'ttl' }, stateDot(item.state, vocab), item.text, dueDecoration(item)),
h('span', { class: 'why' }, whyLine(item)),
),
h('span', { class: 'go' }, ...rowAffordances(actions, item.text, { markDone, dismiss })),
Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/surfaces/hud/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ body{margin:0;background:var(--page-bg);
.rel .mk{padding-top:3px;text-align:center;font-size:10px;line-height:1}
.rel .body .ttl{font-size:12.5px;font-weight:600;color:var(--s-ink);line-height:1.4}
.rel .body .ttl .ext{font-family:var(--s-mono);font-size:10px;color:var(--s-faint);font-weight:400}
.rel .body .ttl .due{margin-left:8px;font-family:var(--s-mono);font-size:10px;color:var(--s-muted);font-weight:400}
.rel .body .why{font-size:11.5px;color:var(--s-muted);line-height:1.5;margin-top:1px}
.rel .go{display:flex;gap:6px;padding-top:2px}
.mini{padding:3px 10px;border-radius:6px;font-size:10.5px;font-weight:600;border:1px solid var(--s-line);color:var(--s-ink);background:rgba(27,31,40,.9);white-space:nowrap;cursor:pointer}
Expand Down Expand Up @@ -120,6 +121,7 @@ body{margin:0;background:var(--page-bg);
.hgroup .glbl,
.rel .mk,
.rel .body .ttl .ext,
.rel .body .ttl .due,
.rel .body .why,
.rel .go,
.dot,
Expand Down
8 changes: 6 additions & 2 deletions apps/engine/src/act/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export const defaultTaskExtractTemplate: PromptTemplate = {
'do after it. Base them ONLY on what the summaries and moments support; invent nothing.\n\n' +
'What was discussed (distilled summaries):\n{{summaries}}\n\n' +
'Key moments:\n{{moments}}\n\n' +
'Return a JSON array of follow-up tasks, each an object with a single "text" field holding one short ' +
'imperative line (e.g. [{"text": "Send Dana the updated deck"}]). If there are no follow-ups yet, ' +
'The current time is {{now}} (ISO-8601). If a task has a stated deadline — absolute ("by 3pm") or ' +
'relative ("in eighteen minutes", "tomorrow") — resolve it AGAINST that current time and add a "due" ' +
'field holding the absolute ISO-8601 instant. If a task has no clear deadline, OMIT "due" — never guess one.\n\n' +
'Return a JSON array of follow-up tasks, each an object with a "text" field (one short imperative line) ' +
'and an optional "due" (ISO-8601) — e.g. [{"text": "Send Dana the updated deck"}, ' +
'{"text": "Give QA feedback", "due": "2026-07-16T15:18:00Z"}]. If there are no follow-ups yet, ' +
'return []. Return ONLY the JSON array, nothing else.',
}
71 changes: 71 additions & 0 deletions apps/engine/src/act/due.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { resolveDue } from './due.js'

// A fixed extraction wall-clock so every assertion is deterministic.
const anchor = new Date('2026-07-16T15:00:00.000Z')

test('model proposal: a parseable, in-horizon ISO is accepted verbatim and marked model-sourced', () => {
const r = resolveDue({ modelDue: '2026-07-16T15:18:00.000Z', text: 'Give QA feedback', anchor })
assert.equal(r.due, '2026-07-16T15:18:00.000Z')
assert.equal(r.dueSource, 'model')
})

test('model proposal: garbage ISO is DROPPED (no due), the item survives without a fabricated deadline', () => {
const r = resolveDue({ modelDue: 'sometime next week', text: 'Give QA feedback', anchor })
assert.equal(r.due, undefined)
assert.equal(r.dueSource, undefined)
})

test('model proposal: a time in the PAST beyond the slack is dropped', () => {
const r = resolveDue({ modelDue: '2026-07-16T13:00:00.000Z', text: 'Give QA feedback', anchor })
assert.equal(r.due, undefined)
})

test('model proposal: a time FAR in the future (> 60 days) is dropped as an implausible mis-parse', () => {
const r = resolveDue({ modelDue: '2026-12-31T00:00:00.000Z', text: 'Give QA feedback', anchor })
assert.equal(r.due, undefined)
})

test('model proposal: a within-slack near-past time (clock skew) is kept', () => {
const r = resolveDue({ modelDue: '2026-07-16T14:59:30.000Z', text: 'x', anchor })
assert.equal(r.dueSource, 'model')
})

test('deterministic fallback: the flagship spoken form "in eighteen minutes" anchors to windowEnd', () => {
const r = resolveDue({ modelDue: undefined, text: 'Provide feedback to QA in eighteen minutes', anchor })
assert.equal(r.due, '2026-07-16T15:18:00.000Z')
assert.equal(r.dueSource, 'anchored')
})

test('deterministic fallback: digits work too — "in 2 hours"', () => {
const r = resolveDue({ modelDue: undefined, text: 'Ship the patch in 2 hours', anchor })
assert.equal(r.due, '2026-07-16T17:00:00.000Z')
assert.equal(r.dueSource, 'anchored')
})

test('deterministic fallback: compound number words — "in forty-five minutes"', () => {
const r = resolveDue({ modelDue: undefined, text: 'Call back in forty-five minutes', anchor })
assert.equal(r.due, '2026-07-16T15:45:00.000Z')
})

test('deterministic fallback: "in 3 days"', () => {
const r = resolveDue({ modelDue: undefined, text: 'Follow up in 3 days', anchor })
assert.equal(r.due, '2026-07-19T15:00:00.000Z')
})

test('deterministic fallback: an out-of-horizon relative time ("in 90 days") is dropped', () => {
const r = resolveDue({ modelDue: undefined, text: 'Renew in 90 days', anchor })
assert.equal(r.due, undefined)
})

test('no deadline anywhere ⇒ no due (nothing invented)', () => {
const r = resolveDue({ modelDue: undefined, text: 'Send Dana the deck', anchor })
assert.deepEqual(r, {})
})

test('a valid model ISO wins even when the text also carries a relative phrase', () => {
const r = resolveDue({ modelDue: '2026-07-16T16:00:00.000Z', text: 'do it in 5 minutes', anchor })
assert.equal(r.due, '2026-07-16T16:00:00.000Z')
assert.equal(r.dueSource, 'model')
})
127 changes: 127 additions & 0 deletions apps/engine/src/act/due.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Deadline resolution for the to-do capture path (#179 opener). The task-extract model MAY propose a
* `due` per item; the engine — never the model — decides whether it stands. Two derivation paths, both
* validated against one sane horizon:
*
* - `model`: the model emitted an absolute time. We accept it ONLY if it parses as ISO and lands inside
* the horizon. A model's ISO is a PROPOSAL, so an unparseable or out-of-horizon value is dropped (the
* item keeps, just without a fabricated deadline).
* - `anchored`: the model gave no usable time, so we deterministically resolve a plain relative
* expression ("in eighteen minutes", "in 2 hours") found in the item text against the extraction
* wall-clock. This is the safety net that makes the flagship case work on weak local models, which
* routinely echo the spoken phrase into the task text but cannot compute an ISO instant.
*
* Nothing is invented: no expression + no valid model time ⇒ no due.
*/

/**
* The acceptance horizon, measured from the extraction wall-clock (the anchor):
* - not earlier than 60s BEFORE the anchor. A deadline captured "now" cannot legitimately already be in
* the past; the 60s slack only absorbs clock skew between the spoken moment and the drain that extracts it.
* - not later than 60 DAYS after the anchor. The #179 opener targets near-term, watch-able commitments;
* a due weeks-to-months out is far more likely a mis-parse (a hallucinated calendar date / wrong year)
* than a live meeting deadline, so we drop it rather than surface a bogus far-future time.
*/
export const DUE_PAST_SLACK_MS = 60_000
export const DUE_MAX_HORIZON_MS = 60 * 24 * 60 * 60_000

/** Whole-number words 0–19 (the ones + teens), for resolving spoken relative times deterministically. */
const ONES: Record<string, number> = {
zero: 0, one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9,
ten: 10, eleven: 11, twelve: 12, thirteen: 13, fourteen: 14, fifteen: 15, sixteen: 16,
seventeen: 17, eighteen: 18, nineteen: 19,
}
/** The tens (20–90), which may stand alone or lead a compound like "forty-five". */
const TENS: Record<string, number> = {
twenty: 20, thirty: 30, forty: 40, fifty: 50, sixty: 60, seventy: 70, eighty: 80, ninety: 90,
}

/** Milliseconds per relative-time unit the deterministic fallback understands. */
const UNIT_MS: Record<string, number> = {
minute: 60_000, min: 60_000,
hour: 3_600_000, hr: 3_600_000,
day: 86_400_000,
}

/**
* Parse a spelled-out or numeric quantity ("eighteen", "forty-five", "20") into a non-negative integer,
* or undefined if it is not a plain quantity we resolve. Handles a/an = 1, ones, teens, tens, and simple
* tens+ones compounds ("twenty five" / "twenty-five"). Deliberately bounded — anything fancier is left to
* the model's own ISO output.
*/
const parseQuantity = (raw: string): number | undefined => {
const t = raw.trim().toLowerCase()
if (t.length === 0) return undefined
if (/^\d+$/.test(t)) return Number(t)
if (t === 'a' || t === 'an') return 1
const parts = t.split(/[\s-]+/).filter((p) => p.length > 0)
if (parts.length === 1) {
const w = parts[0]!
if (w in ONES) return ONES[w]
if (w in TENS) return TENS[w]
return undefined
}
if (parts.length === 2 && parts[0]! in TENS && parts[1]! in ONES && ONES[parts[1]!]! < 10) {
return TENS[parts[0]!]! + ONES[parts[1]!]!
}
return undefined
}

/** Normalize a unit token ("minutes"/"mins"/"hr") to its UNIT_MS key, or undefined. */
const unitKey = (raw: string): string | undefined => {
const u = raw.trim().toLowerCase().replace(/s$/, '')
if (u === 'mins') return 'min'
return u in UNIT_MS ? u : undefined
}

// "in <quantity> <unit>" — the trivial spoken form. Quantity is digits or up to two number-words.
const RELATIVE_RE = /\bin\s+((?:\d+)|(?:[a-z]+(?:[\s-][a-z]+)?))\s+(minutes?|mins?|min|hours?|hrs?|hr|days?)\b/i

const withinHorizon = (dueMs: number, anchorMs: number): boolean =>
dueMs >= anchorMs - DUE_PAST_SLACK_MS && dueMs <= anchorMs + DUE_MAX_HORIZON_MS

export interface ResolveDueInput {
/** the model's proposed `due` for this item, if any (a bare string off the JSON candidate). */
modelDue?: unknown
/** the item's own text — scanned for a relative expression when no valid model time is present. */
text: string
/** the extraction wall-clock: relative expressions resolve against this, and it bounds the horizon. */
anchor: Date
}

export interface ResolvedDue {
due?: string
dueSource?: 'model' | 'anchored'
}

/**
* Resolve an item's deadline. Model ISO wins when valid; otherwise a deterministic relative-time fallback
* over the text; otherwise nothing. The returned `due` is always a validated, in-horizon ISO string.
*/
export const resolveDue = (input: ResolveDueInput): ResolvedDue => {
const anchorMs = input.anchor.getTime()

// 1) Model proposal: accept a parseable, in-horizon ISO instant verbatim.
if (typeof input.modelDue === 'string' && input.modelDue.trim().length > 0) {
const parsed = new Date(input.modelDue.trim())
const ms = parsed.getTime()
if (!Number.isNaN(ms) && withinHorizon(ms, anchorMs)) {
return { due: parsed.toISOString(), dueSource: 'model' }
}
}

// 2) Deterministic fallback: resolve a plain "in N <unit>" against the anchor.
const match = RELATIVE_RE.exec(input.text)
if (match) {
const qty = parseQuantity(match[1]!)
const unit = unitKey(match[2]!)
if (qty !== undefined && unit !== undefined) {
const dueMs = anchorMs + qty * UNIT_MS[unit]!
if (withinHorizon(dueMs, anchorMs)) {
return { due: new Date(dueMs).toISOString(), dueSource: 'anchored' }
}
}
}

return {}
}
Loading
Loading