mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
One loop, raea goal: every rule in TypeScript, held at edit, render, publish and done (goal check, tasks, judge, seen, gates, next); the brief's contract is goal: (one goal or a list, a workflow inline), and its plan is plan:. raea make is making a finished asset: character, clothes, motion, solid, wear, splat, physics, bake, sounds, component, the kit pipeline and shots. Instruments (check, judge, ask, world, scene faults, light check) stay top-level. With it: the montage pack (MK48-MK51), JavaScriptCore fixes raea goal needs (CommonJS named exports, reserved words too, dynamic import of file URLs, process.exit from a promise, stdin for -), raea-cli-goal and raea-cli-refused split out of raea-cli, and skills at raea-skills 105aede.
162 lines
6.5 KiB
TypeScript
162 lines
6.5 KiB
TypeScript
// A plan as values (docs/plan.feature PL2): every task and heading of the brief's plan as an entry, the ones with a
|
|
// keyword as tasks, each with its state, priority, tags, dates, properties, checkboxes, progress and links. Read-only:
|
|
// edits go through edit.ts, by task id, and come back as the plan's new value.
|
|
import { checksOf, docOf, fileSequences, linksIn, linkText, newDoc, type Check, type Link, type PlanDoc, type PlanFile } from "./doc.ts"
|
|
import { plans, sequence, type PlanRegistry } from "./extend.ts"
|
|
import type { Timestamp } from "./time.ts"
|
|
|
|
/** Where a task stands, whatever its keyword is called: the board's lanes, and done or dropped for closed. */
|
|
export type State = "todo" | "making" | "review" | "done" | "dropped"
|
|
|
|
/** Done and dropped are closed: Org's words after the bar. */
|
|
export const isClosed = (s: State | undefined) => s === "done" || s === "dropped"
|
|
|
|
export interface Task {
|
|
/** how an edit names it: its :ID:, or #N (its place among the headlines) for one that has none yet */
|
|
ref: string
|
|
id?: string
|
|
/** its place among the plan's entries */
|
|
index: number
|
|
level: number
|
|
keyword?: string
|
|
/** undefined for a heading that only groups tasks */
|
|
state?: State
|
|
priority?: string
|
|
/** its words as written: links included */
|
|
title: string
|
|
/** its words as a reader sees them: each link as its words */
|
|
text: string
|
|
tags: string[]
|
|
/** tags from the headings above it and the plan's own `tags` */
|
|
inherited: string[]
|
|
scheduled?: Timestamp
|
|
deadline?: Timestamp
|
|
closed?: Timestamp
|
|
/** every property, keys in upper case */
|
|
props: Record<string, string>
|
|
/** :ITEM:, the feed item it stands on */
|
|
item?: string
|
|
/** :AGENT:, who has it, by id */
|
|
agents: string[]
|
|
/** :FROM:, what asked for it */
|
|
from?: string
|
|
kind?: string
|
|
verb?: string
|
|
parent?: string
|
|
children: string[]
|
|
/** the nearest heading above it that isn't a task ("" at the top): the stage it's in */
|
|
stage: string
|
|
checks: Check[]
|
|
/** its tasks under it, done of all; or, with none, its checkboxes */
|
|
progress?: { done: number; total: number }
|
|
links: Link[]
|
|
/** its notes, a line each */
|
|
body: string
|
|
}
|
|
|
|
export interface Plan {
|
|
title?: string
|
|
filetags: string[]
|
|
/** every entry in order: the tasks and the headings that group them */
|
|
entries: Task[]
|
|
/** the entries with a keyword */
|
|
tasks: Task[]
|
|
/** the keywords this plan knows, each with its state: the registry's and its own `keywords` */
|
|
words: Map<string, State>
|
|
doc: PlanDoc
|
|
/** why the value isn't a plan, when it isn't: the plan is empty then */
|
|
problem?: string
|
|
}
|
|
|
|
/** The keywords a plan's own sequences and the registry know, with their states (the registry's win). */
|
|
export function keywordsOf(keywords: readonly string[], reg: PlanRegistry = plans): Map<string, State> {
|
|
const words = new Map(reg.words)
|
|
for (const s of fileSequences(keywords)) for (const w of sequence("file", s.open, s.done, {}, reg.words).words) if (!words.has(w.word)) words.set(w.word, w.state)
|
|
return words
|
|
}
|
|
|
|
/** Reads a plan's value (the brief's `plan`). Never throws: a value that isn't a plan reads as an empty one, with its
|
|
* `problem`; none at all is an empty plan. */
|
|
export function readPlan(file: PlanFile | undefined | null, reg: PlanRegistry = plans): Plan {
|
|
let doc: PlanDoc
|
|
try {
|
|
doc = docOf(file)
|
|
} catch (e) {
|
|
return { ...planOf(newDoc(""), keywordsOf([], reg)), problem: (e as Error).message }
|
|
}
|
|
return planOf(doc, keywordsOf(doc.keywords, reg))
|
|
}
|
|
|
|
const split = (v: string | undefined) => (v ? v.split(/[\s,]+/).filter(Boolean) : [])
|
|
const shown = (title: string) => linkText(title).replace(/\s+/g, " ").trim()
|
|
|
|
/** The plan of a document already read. */
|
|
export function planOf(doc: PlanDoc, words: Map<string, State>): Plan {
|
|
const filetags = doc.filetags
|
|
const entries: Task[] = []
|
|
const stack: Task[] = []
|
|
doc.sections.forEach((s, index) => {
|
|
const props: Record<string, string> = {}
|
|
for (const [k, v] of s.props ?? []) props[k.toUpperCase()] = v
|
|
while (stack.length && stack.at(-1)!.level >= s.level) stack.pop()
|
|
const parent = stack.at(-1)
|
|
const heading = [...stack].reverse().find((t) => !t.state)
|
|
const id = props.ID || undefined
|
|
const t: Task = {
|
|
ref: id ?? `#${index}`,
|
|
...(id && { id }),
|
|
index,
|
|
level: s.level,
|
|
...(s.keyword && { keyword: s.keyword, state: words.get(s.keyword) }),
|
|
...(s.priority && { priority: s.priority }),
|
|
title: s.title,
|
|
text: shown(s.title),
|
|
tags: s.tags,
|
|
inherited: [...new Set([...filetags, ...(parent ? [...parent.inherited, ...parent.tags] : [])])],
|
|
...(s.planning.scheduled && { scheduled: s.planning.scheduled }),
|
|
...(s.planning.deadline && { deadline: s.planning.deadline }),
|
|
...(s.planning.closed && { closed: s.planning.closed }),
|
|
props,
|
|
...(props.ITEM && { item: props.ITEM }),
|
|
agents: split(props.AGENT),
|
|
...(props.FROM && { from: props.FROM }),
|
|
...(props.KIND && { kind: props.KIND }),
|
|
...(props.VERB && { verb: props.VERB }),
|
|
...(parent && { parent: parent.ref }),
|
|
children: [],
|
|
stage: heading?.text ?? "",
|
|
checks: checksOf(s.body),
|
|
links: linksIn([s.title, ...s.body].join("\n")),
|
|
body: s.body.join("\n"),
|
|
}
|
|
parent?.children.push(t.ref)
|
|
stack.push(t)
|
|
entries.push(t)
|
|
})
|
|
const byRef = new Map(entries.map((t) => [t.ref, t]))
|
|
for (const t of entries) {
|
|
const kids = t.children.map((r) => byRef.get(r)!).filter((c) => c.state)
|
|
if (kids.length) t.progress = { done: kids.filter((c) => isClosed(c.state)).length, total: kids.length }
|
|
else if (t.checks.length) {
|
|
const top = Math.min(...t.checks.map((c) => c.indent))
|
|
const own = t.checks.filter((c) => c.indent === top)
|
|
t.progress = { done: own.filter((c) => c.done).length, total: own.length }
|
|
}
|
|
}
|
|
return { title: doc.title, filetags, entries, tasks: entries.filter((t) => t.state), words, doc }
|
|
}
|
|
|
|
/** An entry by its ref: its :ID:, or #N. */
|
|
export function find(plan: Plan, ref: string): Task | undefined {
|
|
return plan.entries.find((t) => t.ref === ref || t.id === ref)
|
|
}
|
|
|
|
/** The open tasks (not done or dropped), in the plan's order. */
|
|
export const openTasks = (plan: Plan) => plan.tasks.filter((t) => !isClosed(t.state))
|
|
|
|
/** A deadline or schedule as the app shows it: MM-DD this year, YYYY-MM-DD otherwise. */
|
|
export function shortDay(t: Timestamp | undefined, now = new Date()): string | undefined {
|
|
if (!t) return undefined
|
|
return t.date.startsWith(`${now.getFullYear()}-`) ? t.date.slice(5) : t.date
|
|
}
|