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
4 changes: 2 additions & 2 deletions app/specs/router/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@
"after": ", {$after} after the message it answers",
"lead": ": {$lead}",
"rhythm": ".input {$per :string}\n.match $per\n1 {{; they write about every {$every}}}\n* {{; they write about {$per} times every {$every}}}",
"when": ".input {$time :string}\n.input {$ago :string}\n.match $time $ago\n|| || {{{$day}}}\n|| * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}",
"when": ".input {$allDay :string}\n.input {$ago :string}\n.local $day = {$at :date fields=month-day-weekday length=medium}\n.local $time = {$at :time precision=minute}\n.match $allDay $ago\nyes || {{{$day}}}\nyes * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}",
"kept": ".input {$when :string}\n.match $when\n|| {{Keep “{$what}” as a note?}}\n* {{Keep “{$what}” for {$when}?}}",
"now": "It is {$when}",
"now": "It is {$at :datetime dateFields=year-month-day-weekday dateLength=long timePrecision=minute}",
"unmatched": "Nothing you hold mentions “{$what}”",
"empty": "Nothing has arrived yet: connect your mail and calendar, or keep a note, and ask again",
"help": "Ask about your day, a person, your mail, your calendar or your notes",
Expand Down
2 changes: 1 addition & 1 deletion app/src/PrismRealizability.lex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
name: realizabilityRouter,
parameters: [],
result: RealizabilityDescriptor,
body: (record RealizabilityDescriptor {facet := 20, digest := 2746994410, identity := (record RealizabilityElement {have := 20, need := 1}), vocabulary := (record RealizabilityElement {have := 9, need := 9}), capability := (record RealizabilityElement {have := 4, need := 4}), interfaceSpec := (record RealizabilityElement {have := 5, need := 5}), composition := (record RealizabilityElement {have := 0, need := 0}), dynamics := (record RealizabilityElement {have := 14, need := 14}), fidelity := (record RealizabilityElement {have := 16, need := 16}), resources := (record RealizabilityElement {have := 1107, need := 44}), authority := (record RealizabilityElement {have := 14, need := 14}), evidence := (record RealizabilityElement {have := 15, need := 13}), projection := (record RealizabilityElement {have := 5, need := 5})})
body: (record RealizabilityDescriptor {facet := 20, digest := 2513064876, identity := (record RealizabilityElement {have := 20, need := 1}), vocabulary := (record RealizabilityElement {have := 9, need := 9}), capability := (record RealizabilityElement {have := 4, need := 4}), interfaceSpec := (record RealizabilityElement {have := 5, need := 5}), composition := (record RealizabilityElement {have := 0, need := 0}), dynamics := (record RealizabilityElement {have := 14, need := 14}), fidelity := (record RealizabilityElement {have := 16, need := 16}), resources := (record RealizabilityElement {have := 1107, need := 44}), authority := (record RealizabilityElement {have := 14, need := 14}), evidence := (record RealizabilityElement {have := 15, need := 13}), projection := (record RealizabilityElement {have := 5, need := 5})})
}

definition{
Expand Down
3 changes: 2 additions & 1 deletion site/card.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,6 @@ export default async function start({ app, reason, $ }) {
// A turn is what was asked and what was said, together; one sentence per item, each on its own line.
const node = element("div", { className: "pr-turn" }, element("p", { className: "pr-you", textContent: prompt }), element("p", { className: "pr-said", textContent: said.sentences.join("\n") }));
chat.append(node);
node.scrollIntoView({ block: "nearest" });
const rows = said.sources.map(rowOf);
drawn.replaceChildren(...rows);
// The sentences link to the items they say; the list beneath holds all that was found.
Expand All @@ -1390,6 +1389,8 @@ export default async function start({ app, reason, $ }) {
return button;
}).filter(Boolean);
node.append(...(links.length ? [element("p", { className: "pr-sources" }, ...links)] : []), ...(offers.length ? [element("div", { className: "pr-offers" }, ...offers)] : []));
// Shown once it is whole, so the decision it offers is in view with it.
node.scrollIntoView({ block: "nearest" });
}
out.style.whiteSpace = "pre-line";
out.style.minWidth = "0";
Expand Down
17 changes: 7 additions & 10 deletions site/router/answer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import * as pin from "../message/guest.mjs";
const S = PROVIDERS.sentence;
const RANK = ["public", "internal", "confidential", "restricted"];
const higher = (a, b) => (RANK.indexOf(b) > RANK.indexOf(a) ? b : a);
const day = new Intl.DateTimeFormat(undefined, { weekday: "short", month: "short", day: "numeric" });
const clock = new Intl.DateTimeFormat(undefined, { hour: "numeric", minute: "2-digit" });
// Every sentence is a Unicode MessageFormat 2 message of the sentence provider
// (app/specs/router/spec.json), formatted by the message guest (app/src/PrismMessage.lex.tex).
// (app/specs/router/spec.json), formatted by the message guest (app/src/PrismMessage.lex.tex),
// dates and times too: a part named `at` is an instant, said in the wall time this browser keeps then.
const guest = new URL(pin.GUESTS.message.path, new URL("../message/guest.mjs", import.meta.url));
const format = await pin.openGuestSync(guest.protocol === "file:" ? await (await import("node:fs/promises")).readFile(guest) : new Uint8Array(await (await fetch(guest)).arrayBuffer()), pin.GUESTS.message.sha256);
// A value longer than a sentence can carry is cut; the item it cites holds the rest.
const zone = (at) => { const m = -new Date(at).getTimezoneOffset(), a = Math.abs(m); return `${m < 0 ? "-" : "+"}${String(Math.trunc(a / 60)).padStart(2, "0")}:${String(a % 60).padStart(2, "0")}`; };
const cut = (value) => { const text = String(value ?? ""); return text.length > S.lead * 2 ? `${text.slice(0, S.lead * 2)}…` : text; };
function fill(key, parts = {}) {
const [errors, ...text] = format(`format\n${JSON.stringify({ src: S.frames[key], bidiIsolation: "none", params: Object.entries(parts).map(([name, value]) => ({ name, value: cut(value) })) })}`).split("\n");
const [errors, ...text] = format(`format\n${JSON.stringify({ src: S.frames[key], bidiIsolation: "none", params: Object.entries(parts).map(([name, value]) => ({ name, value: cut(value) })), ...(parts.at ? { timeZone: zone(parts.at) } : {}) })}`).split("\n");
if (errors) throw Object.assign(new Error(`the ${key} sentence does not format: ${errors}`), { code: "message.format" });
return text.join("\n");
}
Expand All @@ -35,13 +35,10 @@ function fill(key, parts = {}) {
// a "now", also how far that is from it, in wall-time's own periods: "(in 2 days)".
export function whenOf(at, allDay = false, now = null) {
if (!at) return "";
const date = new Date(at);
const ago = Number.isFinite(now) ? relativeOf(allDay ? new Date(date).setHours(12) : at, allDay ? new Date(now).setHours(12) : now) : "";
return fill("when", { day: day.format(date), time: allDay ? "" : clock.format(date), ago });
const ago = Number.isFinite(now) ? relativeOf(allDay ? new Date(at).setHours(12) : at, allDay ? new Date(now).setHours(12) : now) : "";
return fill("when", { at: new Date(at).toISOString(), allDay: allDay ? "yes" : "", ago });
}

// What the browser's clock says now, as the person reads a date and a time.
const full = new Intl.DateTimeFormat(undefined, { dateStyle: "full", timeStyle: "short" });
const asksNow = (text, terms) => S.now.phrases.some((p) => text.toLowerCase().includes(p)) || (terms.length > 0 && terms.every((t) => S.now.words.includes(t)));

const whatOf = (item) => item.title || (item.body ?? "").split("\n")[0] || "";
Expand Down Expand Up @@ -84,7 +81,7 @@ export async function answer(prompt, options) {
// PrismAsk in LexLean), asked of the root guest: the page only carries it out.
const request = [halted(), asksNow(text, termsOf(text)) ? "asked" : "not", keep ? "keeps" : "asks", mapped.intent ?? "fact", mapped.start != null ? "yes" : "no", held.length ? "some" : "none"];
const decided = (await line(`ask ${request.join(" ")}`)).trim();
if (decided === "clock") return { sentences: [end(fill("now", { when: full.format(new Date(now)) }))], sources: [], offers: [], mapped };
if (decided === "clock") return { sentences: [end(fill("now", { at: new Date(now).toISOString() }))], sources: [], offers: [], mapped };
if (decided === "keep") return { sentences: [keptSentence(text, mapped)], sources: [], offers: [{ kind: "keep" }], mapped };
if (decided === "look") {
const asked = await answer(prompt, { ...options, keep: false });
Expand Down
4 changes: 2 additions & 2 deletions site/router/table.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,9 @@ export const SPEC = {
"after": ", {$after} after the message it answers",
"lead": ": {$lead}",
"rhythm": ".input {$per :string}\n.match $per\n1 {{; they write about every {$every}}}\n* {{; they write about {$per} times every {$every}}}",
"when": ".input {$time :string}\n.input {$ago :string}\n.match $time $ago\n|| || {{{$day}}}\n|| * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}",
"when": ".input {$allDay :string}\n.input {$ago :string}\n.local $day = {$at :date fields=month-day-weekday length=medium}\n.local $time = {$at :time precision=minute}\n.match $allDay $ago\nyes || {{{$day}}}\nyes * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}",
"kept": ".input {$when :string}\n.match $when\n|| {{Keep “{$what}” as a note?}}\n* {{Keep “{$what}” for {$when}?}}",
"now": "It is {$when}",
"now": "It is {$at :datetime dateFields=year-month-day-weekday dateLength=long timePrecision=minute}",
"unmatched": "Nothing you hold mentions “{$what}”",
"empty": "Nothing has arrived yet: connect your mail and calendar, or keep a note, and ask again",
"help": "Ask about your day, a person, your mail, your calendar or your notes",
Expand Down
3 changes: 2 additions & 1 deletion test/time/order.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ test("the chat answers from now: the time, how long ago, and a message's turn",
for (const question of ["What time is it?", "what's the date", "What day is it today?"]) {
const said = await ask(question);
const full = new Intl.DateTimeFormat(undefined, { dateStyle: "full", timeStyle: "short" }).format(new Date(now));
assert.deepEqual(said.sentences, [`It is ${full}.`], question);
// CLDR puts a narrow no-break space before AM and PM; V8 writes a plain one.
assert.deepEqual(said.sentences.map((s) => s.replace(/\u202f/gu, " ")), [`It is ${full}.`], question);
assert.deepEqual(said.sources, [], "the time draws on nothing held");
}
const item = read(reply);
Expand Down
Loading