Something went wrong. Try again.
A monorepo for writing specs and other serious text on the AT Protocol.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243// How an ask is spoken of in the chrome: its verb and its place, as a line// ("Outline the piece", "Write §3"), and as what is going on ("writing §3").// The place is named by the document, so the section numbers are the page's.import type { Node as PMNode } from '@tiptap/pm/model';import type { Ask, AskScope, AskVerb } from './draft.ts';import { findBlock } from './doc.ts';
/** An assistant's name without what follows in brackets: "the house assistant", "hm-write". */export const shortWho = (name: string): string => name.replace(/\s*\(.*\)\s*$/, '');
export const VERB_NAMES: Record<AskVerb, string> = { write: 'Write', finer: 'Finer', tighten: 'Tighten', review: 'Review', proofread: 'Proofread', outline: 'Outline', structure: 'Review the structure of', anything: 'About' };const DOING: Record<AskVerb, string> = { write: 'writing', finer: 'going finer in', tighten: 'tightening', review: 'reviewing', proofread: 'proofreading', outline: 'outlining', structure: 'reviewing the structure of', anything: 'on' };
/** The place an ask is made about, as a word or a section number. */export function scopeName(scope: AskScope, doc: PMNode | null, opts: { chapter?: boolean } = {}): string { switch (scope.kind) { case 'piece': return opts.chapter ? 'this chapter' : 'the piece'; case 'book': return 'the book'; case 'selection': return 'the selection'; case 'note': return 'a note'; case 'section': { const b = doc ? findBlock(doc, scope.id) : undefined; return b?.number ? `§${b.number}` : 'a section'; } }}
/** "Outline the piece", "Write §3", "Finer in §2.1". */export function describeAsk(a: Pick<Ask, 'verb' | 'scope'>, doc: PMNode | null, opts: { chapter?: boolean } = {}): string { const place = scopeName(a.scope, doc, opts); if (a.verb === 'finer') return `Finer in ${place}`; return `${VERB_NAMES[a.verb]} ${place}`;}
/** "writing §3", for a chip while it goes on. */export function doingAsk(a: Pick<Ask, 'verb' | 'scope'>, doc: PMNode | null, opts: { chapter?: boolean } = {}): string { return `${DOING[a.verb]} ${scopeName(a.scope, doc, opts)}`;}