diff --git a/cms/.vitepress/theme/components/DaemonDashboard.vue b/cms/.vitepress/theme/components/DaemonDashboard.vue index 0166623..8383b32 100644 --- a/cms/.vitepress/theme/components/DaemonDashboard.vue +++ b/cms/.vitepress/theme/components/DaemonDashboard.vue @@ -89,12 +89,30 @@
: text" — e.g.
+// "P1: Not enough people understand ...". The letter is the TELOS section; the
+// number is a stable identifier (M1 answers P1), NOT a priority ranking.
+//
+// Framework: https://github.com/danielmiessler/Telos
+const TELOS_CODE_LABELS: Record = {
+ P: 'Problem',
+ M: 'Mission',
+ N: 'Narrative',
+ G: 'Goal',
+ C: 'Challenge',
+ I: 'Idea',
+ K: 'Metric (KPI)',
+}
+
+// Only the recognised TELOS code letters are treated as codes — derived from the
+// map above so the parser, the labels, and the popover legend can never drift.
+const CODES = Object.keys(TELOS_CODE_LABELS).join('') // 'PMNGCIK'
+const ID_RE = new RegExp(`^([${CODES}])(\\d+)`, 'i')
+const PREFIX_RE = new RegExp(`^[${CODES}]\\d+:\\s*`, 'i')
+const CODE_RE = new RegExp(`^([${CODES}])\\d+`, 'i')
+
+/** The "" id at the start of a telos entry (e.g. "P1"), uppercased; '---' when the leading code isn't a known TELOS code. */
+export function extractTelosId(item: string): string {
+ const m = item.match(ID_RE)
+ return m ? m[1].toUpperCase() + m[2] : '---'
+}
+
+/** The entry text with a recognised ": " prefix removed. */
+export function extractTelosText(item: string): string {
+ return item.replace(PREFIX_RE, '')
+}
+
+/** Friendly section name for a telos entry's code, or '' when the code isn't a known TELOS code. */
+export function telosCodeLabel(item: string): string {
+ const m = item.match(CODE_RE)
+ return m ? TELOS_CODE_LABELS[m[1].toUpperCase()] : ''
+}
+
+/** Accessible label for the id cell: the id plus its section name when known (e.g. "P1, Problem"). */
+export function telosAriaLabel(item: string): string {
+ const id = extractTelosId(item)
+ const label = telosCodeLabel(item)
+ return label ? `${id}, ${label}` : id
+}
diff --git a/tests/telosCodes.test.ts b/tests/telosCodes.test.ts
new file mode 100644
index 0000000..4b10d46
--- /dev/null
+++ b/tests/telosCodes.test.ts
@@ -0,0 +1,42 @@
+import { expect, test } from 'bun:test'
+import { extractTelosId, extractTelosText, telosCodeLabel, telosAriaLabel } from '../cms/.vitepress/theme/telosCodes'
+
+test('telosCodeLabel maps every known TELOS code to its section name', () => {
+ expect(telosCodeLabel('P1: a problem')).toBe('Problem')
+ expect(telosCodeLabel('M2: a mission')).toBe('Mission')
+ expect(telosCodeLabel('N1: a narrative')).toBe('Narrative')
+ expect(telosCodeLabel('G3: a goal')).toBe('Goal')
+ expect(telosCodeLabel('C4: a challenge')).toBe('Challenge')
+ expect(telosCodeLabel('I1: an idea')).toBe('Idea')
+ expect(telosCodeLabel('K2: a metric')).toBe('Metric (KPI)')
+})
+
+test('telosCodeLabel is case-insensitive on the code letter', () => {
+ expect(telosCodeLabel('p1: lowercase code')).toBe('Problem')
+})
+
+test('telosCodeLabel returns an empty string for unknown or missing codes', () => {
+ expect(telosCodeLabel('Z9: unrecognised code')).toBe('')
+ expect(telosCodeLabel('freeform entry, no code')).toBe('')
+})
+
+test('extractTelosId returns the id (uppercased) only for a known TELOS code', () => {
+ expect(extractTelosId('P1: a problem')).toBe('P1')
+ expect(extractTelosId('K12: a metric')).toBe('K12')
+ expect(extractTelosId('p1: lowercase')).toBe('P1')
+ expect(extractTelosId('Z9: unknown code')).toBe('---')
+ expect(extractTelosId('COVID19: not a code')).toBe('---')
+ expect(extractTelosId('freeform entry')).toBe('---')
+})
+
+test('extractTelosText strips only a recognised ": " prefix', () => {
+ expect(extractTelosText('M1: Own the system')).toBe('Own the system')
+ expect(extractTelosText('Z9: unknown code stays')).toBe('Z9: unknown code stays')
+ expect(extractTelosText('freeform entry')).toBe('freeform entry')
+})
+
+test('telosAriaLabel combines the id and section name, or falls back to the id', () => {
+ expect(telosAriaLabel('P1: a problem')).toBe('P1, Problem')
+ expect(telosAriaLabel('M2: a mission')).toBe('M2, Mission')
+ expect(telosAriaLabel('Z9: unknown')).toBe('---')
+})