create-pmos 0.761.0 → 0.762.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/package.json +26 -20
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/changelog.json +25 -0
  7. package/workspace/guide/cli.md +6 -0
  8. package/workspace/guide/home.md +1 -1
  9. package/workspace/guide/notes.md +15 -0
  10. package/workspace/lib/actor.js +8 -3
  11. package/workspace/lib/contradictions.js +137 -0
  12. package/workspace/lib/meeting-focus.js +14 -1
  13. package/workspace/lib/open-questions.js +23 -5
  14. package/workspace/lib/outcome-judge.js +1 -1
  15. package/workspace/lib/outcome-props.js +51 -5
  16. package/workspace/lib/outcomes-cli.js +49 -3
  17. package/workspace/lib/plan-baseline.js +106 -0
  18. package/workspace/lib/proposal-runs.js +1 -1
  19. package/workspace/lib/proposals.js +1 -1
  20. package/workspace/lib/propose-cli.js +16 -7
  21. package/workspace/lib/routes-drift.js +30 -0
  22. package/workspace/lib/routes-meeting-focus.js +6 -1
  23. package/workspace/lib/routes-open-questions.js +9 -2
  24. package/workspace/lib/week-moves.js +8 -2
  25. package/workspace/package-lock.json +2 -2
  26. package/workspace/package.json +1 -1
  27. package/workspace/premium-rec-tab-test.js +2 -1
  28. package/workspace/public/pm/buddy-core.js +162 -0
  29. package/workspace/public/pm/buddy-float.js +63 -0
  30. package/workspace/public/pm/cozy-buddy.css +26 -0
  31. package/workspace/public/pm/cozy-buddy.js +59 -7
  32. package/workspace/public/pm/cozy-rec-tab.js +10 -2
  33. package/workspace/public/pm/moves-view.js +11 -1
  34. package/workspace/public/pm/open-questions-view.js +1 -0
  35. package/workspace/public/premium-buddy.html +4 -0
  36. package/workspace/skills/initiative-propose.skill +2 -2
  37. package/workspace/test-lists/outcome-checks-finish.json +9 -0
  38. package/workspace/test-lists/slip-baseline-contradictions.json +9 -0
@@ -19,6 +19,9 @@
19
19
  * left out when the bet already has a named test.
20
20
  * pmos outcomes tests [--count] [--json] the ranked bets with no smallest test, the tests waiting for a result, and the results;
21
21
  * --count prints the number of bets with a result in the last 14 days (the health number).
22
+ * pmos outcomes rate [--days <n>] [--json] the bet's number (outcome-checks-finish): checks due in the last n days (30) and at least 2
23
+ * days past, how many got a verdict within 2 days, how many of those PMOS recorded; the last
24
+ * line is that percent. Reads only.
22
25
  * every command: [--root <dir>] (default: this repository)
23
26
  *
24
27
  * The agent runs declare and record only after the PM said yes in the chat; the line names who wrote it (lib/actor.js). A verdict is the
@@ -29,7 +32,7 @@ const { execFileSync } = require('child_process');
29
32
  const O = require('./outcomes.js');
30
33
  const ST = require('./smallest-test.js');
31
34
 
32
- const COMMANDS = { outcomes: ['list', 'propose', 'declare', 'record', 'live', 'test', 'tests'] };
35
+ const COMMANDS = { outcomes: ['list', 'propose', 'declare', 'record', 'live', 'test', 'tests', 'rate'] };
33
36
  const USAGE = [
34
37
  'usage: pmos outcomes list|propose|declare|record|live|test|tests — every initiative has an expected outcome and a date to check it',
35
38
  ' pmos outcomes list [--json] checks due, outcomes with no date, initiatives with no outcome; reads only',
@@ -40,8 +43,37 @@ const USAGE = [
40
43
  ' pmos outcomes test <id> --test "<text>" [--method data-count|fake-door|concierge|other] [--result planned|holds|fails|unclear] [--evidence "<text>"]',
41
44
  ' the smallest test that could kill a ranked bet, and what it showed',
42
45
  ' pmos outcomes tests [--count] [--json] ranked bets with no test, tests waiting for a result, results; --count: results in 14 days',
46
+ ' pmos outcomes rate [--days <n>] [--json] checks due in the last n days (30) that got a verdict within 2 days, and how many PMOS did',
43
47
  'Run it in the product\'s repository, or pass --root <dir>. Show each ✦ to the PM and write only after a yes.',
44
48
  ];
49
+ /* `pmos outcomes rate` (initiative outcome-checks-finish): the bet's own number. A check counts when its date fell in the last `days` days
50
+ * and is at least ON_TIME_DAYS past (so it had its full chance); it is on time when a live verdict (not undone) for that date was recorded
51
+ * no later than ON_TIME_DAYS after it, and PMOS's when an agent wrote it. A blocked check is not due (lib/outcomes.js), so it is left out. */
52
+ const RATE_DAYS = 30, ON_TIME_DAYS = 2;
53
+ const addDays = (day, n) => new Date(Date.parse(day + 'T00:00:00Z') + n * 864e5).toISOString().slice(0, 10);
54
+ function rateOf(root, { today, days = RATE_DAYS } = {}) {
55
+ const S = O.scan(root, { today });
56
+ const from = addDays(today, -days), to = addDays(today, -ON_TIME_DAYS);
57
+ const rows = [];
58
+ for (const f of [...new Set([path.join(S.layout.runsDir, 'outcome_checks.jsonl'), path.join(root, 'pmos', 'state', 'outcome_checks.jsonl'), path.join(root, 'planning', 'runs', 'outcome_checks.jsonl')])]) {
59
+ let t = ''; try { t = require('fs').readFileSync(f, 'utf8'); } catch { continue; }
60
+ for (const l of t.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object') rows.push(o); } catch { /* torn */ } }
61
+ }
62
+ const live = O.liveChecks(rows).filter((c) => c && c.initiative_id && O.DISPOSITIONS.includes(c.disposition));
63
+ const blocked = new Set(S.blocked.map((it) => it.id));
64
+ const due = [];
65
+ for (const it of S.subjects) {
66
+ if (!it.metric || !it.horizon || it.horizon < from || it.horizon > to || blocked.has(it.id)) continue;
67
+ const mine = live.filter((c) => c.initiative_id === it.id && (!c.horizon || c.horizon === it.horizon) && String(c.date || c.at || '').slice(0, 10) >= it.horizon)
68
+ .sort((a, b) => String(a.at || a.date).localeCompare(String(b.at || b.date)));
69
+ const v = mine[0] || null, vDate = v ? String(v.date || v.at).slice(0, 10) : null;
70
+ const onTime = !!v && vDate <= addDays(it.horizon, ON_TIME_DAYS);
71
+ due.push({ id: it.id, horizon: it.horizon, onTime, byPmos: onTime && /^agent:/.test(String(v.by || '')), verdict: v ? { disposition: v.disposition, date: vDate, by: v.by || null } : null });
72
+ }
73
+ const byPmos = due.filter((x) => x.byPmos).length;
74
+ return { from, to, days, onTimeDays: ON_TIME_DAYS, due, onTime: due.filter((x) => x.onTime).length, byPmos, pct: due.length ? Math.round((100 * byPmos) / due.length) : null };
75
+ }
76
+
45
77
  const VERDICT = { worked: 'validated', validated: 'validated', 'didnt-work': 'refuted', "didn't-work": 'refuted', refuted: 'refuted', 'cant-tell': 'inconclusive', "can't-tell": 'inconclusive', inconclusive: 'inconclusive' };
46
78
 
47
79
  function parse(args) {
@@ -71,7 +103,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
71
103
  if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
72
104
  if (!COMMANDS.outcomes.includes(sub)) { say(`unknown outcomes command "${sub}". Use one of: ${COMMANDS.outcomes.join(', ')}`); return 2; }
73
105
  const { pos, flags } = parse(args.slice(1));
74
- const allowed = { list: ['json', 'root'], propose: ['json', 'root', 'max'], declare: ['json', 'root', 'metric', 'horizon'], record: ['json', 'root', 'evidence'], live: ['json', 'root', 'where', 'version'], test: ['json', 'root', 'test', 'method', 'result', 'evidence'], tests: ['json', 'root', 'count'] }[sub];
106
+ const allowed = { list: ['json', 'root'], propose: ['json', 'root', 'max'], declare: ['json', 'root', 'metric', 'horizon'], record: ['json', 'root', 'evidence'], live: ['json', 'root', 'where', 'version'], test: ['json', 'root', 'test', 'method', 'result', 'evidence'], tests: ['json', 'root', 'count'], rate: ['json', 'root', 'days'] }[sub];
75
107
  for (const k of Object.keys(flags)) if (!allowed.includes(k)) { say(`✗ --${k} is not an option of pmos outcomes ${sub}`); return 2; }
76
108
  const root = path.resolve(flags.root || repoRoot(cwd));
77
109
  const today = O.todayOf(now);
@@ -95,6 +127,20 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
95
127
  return 0;
96
128
  }
97
129
 
130
+ if (sub === 'rate') {
131
+ if (pos.length) return fail('pmos outcomes rate takes no argument', 2);
132
+ const days = flags.days === undefined ? RATE_DAYS : Number(flags.days);
133
+ if (!Number.isInteger(days) || days < ON_TIME_DAYS || days > 366) return fail(`--days is a whole number from ${ON_TIME_DAYS} to 366`, 2);
134
+ const r = rateOf(root, { today, days });
135
+ if (flags.json) { say(JSON.stringify({ ok: true, ...r })); return 0; }
136
+ const n = r.due.length, onTime = r.due.filter((x) => x.onTime).length;
137
+ say(n ? `${n} check${n === 1 ? '' : 's'} came due from ${O.short(r.from)} to ${O.short(r.to)} · ${onTime} got a verdict within ${ON_TIME_DAYS} days · ${r.byPmos} by PMOS with no PM step`
138
+ : `No check came due from ${O.short(r.from)} to ${O.short(r.to)}.`);
139
+ for (const x of r.due.filter((y) => !y.onTime)) say(` late: ${x.id} — due ${O.short(x.horizon)}${x.verdict ? `, verdict on ${O.short(x.verdict.date)}` : ', no verdict yet'}`);
140
+ say(r.pct == null ? 'none due' : r.pct + '%');
141
+ return 0;
142
+ }
143
+
98
144
  if (sub === 'propose') {
99
145
  if (pos.length > 1) return fail('pmos outcomes propose takes at most one initiative id', 2);
100
146
  const max = flags.max === undefined ? 3 : Number(flags.max);
@@ -194,4 +240,4 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
194
240
  return 0;
195
241
  }
196
242
 
197
- module.exports = { run, COMMANDS, USAGE, VERDICT };
243
+ module.exports = { rateOf, ON_TIME_DAYS, run, COMMANDS, USAGE, VERDICT };
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* plan-baseline.js — every slip against a baseline (initiative slip-baseline-contradictions; bet 1c, proof A102). READ-ONLY: it writes nothing.
4
+ *
5
+ * Proof A102: PMOS moved 96 due dates with no evidence on two products, about 1,470 task-days, and with no baseline the plan still looked on
6
+ * time. The baseline of a task is the FIRST due date its lines ever set. It is derived from the ledgers, never declared, so no record has to
7
+ * be kept in step and every product that has task lines has a baseline today.
8
+ *
9
+ * baselineOf(task) → { baseline, due, open, removed, moves: [line] } PURE. task: a lib/drift-facts.js task
10
+ * daysBetween(a, b) → whole days from day a to day b (YYYY-MM-DD)
11
+ * slipOf(facts, { today }) → { today, initiatives: [row], tasks, days, unsourced_days } PURE. facts: one factsOf result or a list
12
+ * forRepo(root, { now }) → slipOf of one checkout (its state folder found as `pmos drift` finds it)
13
+ *
14
+ * A TASK IS BEHIND when it is open (not Done, not Won't do), not removed, and its current due date is later than its baseline. Its days
15
+ * behind are the days from the baseline to the current due. They count as UNSOURCED when any move after the baseline rests on no source, by
16
+ * the rule of the weekly what-moved list (lib/week-moves.js sourceOf). A task moved earlier, done, removed or never dated is not behind.
17
+ *
18
+ * AN INITIATIVE ROW: { product, name, ini, title, tasks, days, unsourced_days, worst: { task, title, baseline, due, behind, sourced, owner } }
19
+ *
20
+ * CLI: node lib/plan-baseline.js list|count [<root>] [--json]. `count` ends with the unsourced task-days on its last line.
21
+ * Every log line carries [baseline]. */
22
+ const path = require('path');
23
+
24
+ const TAG = '[baseline]';
25
+ const DAY = 86400000;
26
+ const CLOSED = /^(done|won'?t do|cancel+ed|closed)$/i;
27
+ const isDate = (s) => /^\d{4}-\d{2}-\d{2}/.test(String(s || ''));
28
+ const dayOf = (s) => String(s).slice(0, 10);
29
+ const dayMs = (s) => Date.parse(dayOf(s) + 'T00:00:00Z');
30
+ const pad = (n) => String(n).padStart(2, '0');
31
+ const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); };
32
+
33
+ /** Whole days from day a to day b. */
34
+ function daysBetween(a, b) { return Math.round((dayMs(b) - dayMs(a)) / DAY); }
35
+
36
+ /** A task's first due date, its current one, whether it is open, and the lines that moved its date after the first. PURE. */
37
+ function baselineOf(t) {
38
+ const lines = (t && t.lines ? t.lines : []).filter((l) => Number.isFinite(l.at)).slice().sort((a, b) => a.at - b.at);
39
+ let baseline = null, due = null, state, removed = false, owner;
40
+ const moves = [];
41
+ for (const l of lines) {
42
+ if (l.kind === 'task-remove') removed = true;
43
+ if (l.kind === 'task-restore') removed = false;
44
+ if (typeof l.state === 'string' && l.state) state = l.state;
45
+ if (typeof l.owner === 'string' && l.owner.trim()) owner = l.owner;
46
+ if (l.due === undefined) continue;
47
+ const next = isDate(l.due) ? dayOf(l.due) : null;
48
+ if (baseline === null) { if (next) baseline = next; due = next; continue; }
49
+ if (next !== due) moves.push(l);
50
+ due = next;
51
+ }
52
+ return { baseline, due, state: state || '', open: !CLOSED.test(String(state || '').trim()), removed, owner, moves };
53
+ }
54
+
55
+ /** Task-days behind the first plan, per initiative and per product. PURE. */
56
+ function slipOf(facts, { today = localDay(Date.now()) } = {}) {
57
+ const WM = require('./week-moves.js');
58
+ const list = (Array.isArray(facts) ? facts : [facts]).filter(Boolean);
59
+ const rows = [];
60
+ for (const f of list) {
61
+ const titles = new Map((f.initiatives || []).map((i) => [i.id, i.title || i.id]));
62
+ const by = new Map();
63
+ for (const t of f.tasks || []) {
64
+ const b = baselineOf(t);
65
+ if (!b.open || b.removed || !b.baseline || !b.due || b.due <= b.baseline) continue;
66
+ const behind = daysBetween(b.baseline, b.due);
67
+ const sourced = b.moves.every((l) => WM.sourceOf(l).sourced);
68
+ const r = by.get(t.initiative) || { product: f.ws, name: f.name || f.ws, ini: t.initiative, title: titles.get(t.initiative) || t.initiative, tasks: 0, days: 0, unsourced_days: 0, worst: null };
69
+ r.tasks++; r.days += behind; if (!sourced) r.unsourced_days += behind;
70
+ if (!r.worst || behind > r.worst.behind) r.worst = { task: t.id, title: t.title, baseline: b.baseline, due: b.due, behind, sourced, owner: WM.ownerOf(b.owner).owner };
71
+ by.set(t.initiative, r);
72
+ }
73
+ rows.push(...by.values());
74
+ }
75
+ rows.sort((a, b) => b.unsourced_days - a.unsourced_days || b.days - a.days || String(a.title).localeCompare(String(b.title)));
76
+ const sum = (k) => rows.reduce((s, r) => s + r[k], 0);
77
+ return { today, initiatives: rows, tasks: sum('tasks'), days: sum('days'), unsourced_days: sum('unsourced_days') };
78
+ }
79
+
80
+ /** One checkout's slip. Reads its ledgers; writes nothing. */
81
+ function forRepo(root, { now = Date.now(), name } = {}) {
82
+ const Dr = require('./driver.js');
83
+ const f = require('./drift-facts.js').factsOf({ id: Dr.wsIdOf(root), name: name || path.basename(root), root }, { stateDir: Dr.stateDirOf(root) });
84
+ return { notRead: f.notRead, ...slipOf(f, { today: localDay(now) }) };
85
+ }
86
+
87
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
88
+
89
+ function main(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Date.now() } = {}) {
90
+ const pos = [], flags = {};
91
+ for (const a of argv) { if (a === '--json') flags.json = true; else pos.push(a); }
92
+ const [sub = 'list', rootArg] = pos;
93
+ if (!['list', 'count'].includes(sub)) { say('usage: node lib/plan-baseline.js list|count [<root>] [--json] — open tasks behind their first plan, and the days with no source'); return 2; }
94
+ const root = path.resolve(cwd, rootArg || '.');
95
+ let r;
96
+ try { r = forRepo(root, { now }); } catch (e) { say(`${TAG} could not read ${root}: ${(e && e.message) || e}`); return 1; }
97
+ if (flags.json) { say(JSON.stringify(sub === 'count' ? { today: r.today, tasks: r.tasks, days: r.days, unsourced_days: r.unsourced_days, notRead: r.notRead } : r)); return 0; }
98
+ if (sub === 'list') for (const x of r.initiatives) say(`${x.unsourced_days ? '!' : ' '} ${x.title} · ${plural(x.tasks, 'task', 'tasks')} · ${plural(x.days, 'day', 'days')} behind the first plan, ${x.unsourced_days} with no source · worst: ${x.worst.title} (due ${x.worst.baseline} → ${x.worst.due})`);
99
+ say(`${TAG} ${plural(r.tasks, 'open task', 'open tasks')} behind the first plan, ${plural(r.days, 'task-day', 'task-days')} in all, ${r.unsourced_days} with no source${r.notRead.length ? ' (not read: ' + r.notRead.join(', ') + ')' : ''}`);
100
+ if (sub === 'count') say(String(r.unsourced_days));
101
+ return 0;
102
+ }
103
+
104
+ module.exports = { baselineOf, daysBetween, slipOf, forRepo, main, TAG };
105
+
106
+ if (require.main === module) process.exitCode = main(process.argv.slice(2));
@@ -45,7 +45,7 @@ const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-'
45
45
  const WHY = {
46
46
  populate: 'The PM just added this initiative. It most likely already lives elsewhere: find it in every connected source and file what you find (Found elsewhere).',
47
47
  check: 'The morning check: some tasks are late or at risk. Find why each one slipped and file new dates, "looks done" and tidy names.',
48
- outcome: 'Its outcome check date has passed and its goal\'s own reading did not decide it. Read its records and file whether it worked (`pmos propose verdict`), or file nothing when you cannot tell.',
48
+ outcome: 'Its outcome check date has passed and its goal\'s own reading did not decide it. Read its records and file whether it worked (`pmos propose verdict`); when you cannot tell, file `cant-tell` with what you read and what was missing.',
49
49
  };
50
50
 
51
51
  function promptOf(skill, o) {
@@ -192,7 +192,7 @@ function clean(group, type, input) {
192
192
  // PMOS's own verdict on a due outcome (initiative outcome-checks-run-themselves; lib/outcome-judge.js, or the outcome run's `pmos propose
193
193
  // verdict`). Class B: applied by itself with Undo, it records the check in outcome_checks.jsonl (lib/outcomes.js recordCheck)
194
194
  const d = isObj(input.data) ? input.data : {};
195
- if (!['validated', 'refuted'].includes(d.disposition)) return { error: 'data.disposition is validated or refuted (when PMOS cannot tell, it files nothing: the PM is asked)' };
195
+ if (!['validated', 'refuted', 'inconclusive'].includes(d.disposition)) return { error: 'data.disposition is validated, refuted or inconclusive (can\'t tell, with what was read and what was missing: initiative outcome-checks-finish)' };
196
196
  const evidence = one(d.evidence, 600);
197
197
  if (evidence.length < 12) return { error: 'data.evidence says what shows it, at least 12 characters' };
198
198
  if (!DAY_RE.test(str(d.horizon))) return { error: 'data.horizon is the check date it answers, YYYY-MM-DD' };
@@ -87,8 +87,11 @@ const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (a
87
87
 
88
88
  /** `pmos propose verdict`: the outcome run's verdict on a due check (initiative outcome-checks-run-themselves). Every claim's quote must be
89
89
  * on its path:line in the repository (lib/ai-guard.js check) or nothing is filed. It files the class B verdict ✦; the server records it
90
- * with Undo (lib/routes-proposals.js applyOne). "cant-tell" files nothing: the check stays due and Your move asks the PM. */
91
- const VERDICT = { worked: 'validated', 'didnt-work': 'refuted', validated: 'validated', refuted: 'refuted' };
90
+ * with Undo (lib/routes-proposals.js applyOne). "cant-tell" is a verdict too (initiative outcome-checks-finish): it files the same class B ✦ as
91
+ * `inconclusive`, with what the run read and what was missing as its evidence, so the PM is not left a question. Its claims are optional;
92
+ * any it gives still pass the guard. */
93
+ const VERDICT = { worked: 'validated', 'didnt-work': 'refuted', validated: 'validated', refuted: 'refuted', 'cant-tell': 'inconclusive', inconclusive: 'inconclusive' };
94
+ const SAID = { validated: 'worked', refuted: 'didn\'t work', inconclusive: 'can\'t tell' };
92
95
  function verdict(args, { say, stdin, env, file, runId, ini, board, F, line }) {
93
96
  const root = env.PMOS_PROPOSE_ROOT;
94
97
  if (!root) { say('✗ pmos propose verdict is for PMOS\'s outcome run (the server pins PMOS_PROPOSE_ROOT)'); return 1; }
@@ -96,17 +99,23 @@ function verdict(args, { say, stdin, env, file, runId, ini, board, F, line }) {
96
99
  if (!src) { say('usage: pmos propose verdict --json <file|->'); return 2; }
97
100
  const r = readJson(src, stdin); if (r.error) { say('✗ ' + r.error); return 1; }
98
101
  const b = r.body && typeof r.body === 'object' && !Array.isArray(r.body) ? r.body : {};
99
- if (b.disposition === 'cant-tell' || b.disposition === 'inconclusive') { say('filed nothing: the check stays due and Your move asks the PM'); return 0; }
100
102
  const disposition = VERDICT[b.disposition];
101
103
  if (!disposition) { say('✗ refused: disposition is worked, didnt-work or cant-tell'); return 1; }
102
104
  const O = require('./outcomes.js'), AG = require('./ai-guard.js'), J = require('./outcome-judge.js');
103
105
  const it = O.scan(root).due.find((x) => x.id === ini);
104
106
  if (!it) { say(`✗ refused: ${ini} has no outcome check due now`); return 1; }
105
107
  const evidence = String(b.evidence || '').replace(/\s+/g, ' ').trim();
106
- const c0 = AG.check({ id: 'outcome-verdict:' + ini, title: J.WORDS[disposition], say: evidence || '-', confidence: 'medium', cls: 'B', claims: b.claims }, { root, stateDir: require('path').dirname(file) });
107
- if (!c0.ok) { say('✗ refused: ' + c0.errors.join('; ')); return 1; }
108
- const sources = c0.p.claims.flatMap((c) => c.sources).filter((x) => x.verified).map((x) => ({ label: x.label, ref: x.ref }));
109
- const why = `Its check date was ${O.short(it.horizon)}. ${evidence.replace(/[.\s]+$/, '')}. PMOS recorded "${disposition === 'validated' ? 'worked' : 'didn\'t work'}". Undo takes it back.`;
108
+ const cant = disposition === 'inconclusive';
109
+ if (cant && evidence.length < 24) { say('✗ refused: a can\'t tell needs its evidence: what you read and what was missing (at least 24 characters)'); return 1; }
110
+ let sources = [];
111
+ if (!cant || (Array.isArray(b.claims) && b.claims.length)) {
112
+ const c0 = AG.check({ id: 'outcome-verdict:' + ini, title: J.WORDS[disposition], say: evidence || '-', confidence: 'medium', cls: 'B', claims: b.claims }, { root, stateDir: require('path').dirname(file) });
113
+ if (!c0.ok) { say('✗ refused: ' + c0.errors.join('; ')); return 1; }
114
+ sources = c0.p.claims.flatMap((c) => c.sources).filter((x) => x.verified).map((x) => ({ label: x.label, ref: x.ref }));
115
+ }
116
+ // a can't tell with no claims cites the record's outcome line, so it is never a change with no source (lib/autonomy.js)
117
+ if (!sources.length && it.fm && it.fm.outcome_metric) sources = [{ label: 'Expected outcome', ref: it.record + ':' + it.fm.outcome_metric.n }];
118
+ const why = `Its check date was ${O.short(it.horizon)}. ${evidence.replace(/[.\s]+$/, '')}. PMOS recorded "${SAID[disposition]}". Undo takes it back.`;
110
119
  const c = PR.clean('outcome', 'verdict', { title: `${J.WORDS[disposition]}: ${it.title}`.slice(0, 120), why, sources, items: [{ id: 'verdict', title: J.WORDS[disposition] }], data: { disposition, evidence, horizon: it.horizon } });
111
120
  if (c.error) { say('✗ refused: ' + c.error); return 1; }
112
121
  const id = PR.idOf(ini, 'outcome', 'verdict', it.horizon);
@@ -10,6 +10,9 @@
10
10
  * POST /api/drift/looked { week } → { ok } the card was shown for that week
11
11
  * GET /api/drift/moves?ws=<id>[&week=YYYY-MM-DD] → { ok, ws, name, week, label, notRead, rows, total, unsourced } the weekly what-moved list of
12
12
  * one product (initiative weekly-what-moved, lib/week-moves.js): last week by default; read-only
13
+ * GET /api/drift/slip?ws=<id> → { ok, ws, name, notRead, today, initiatives, tasks, days, unsourced_days } open tasks behind
14
+ * their first plan (initiative slip-baseline-contradictions, lib/plan-baseline.js); read-only
15
+ * GET /api/drift/contradictions?ws=<id> → { ok, ws, name, notRead, items, total } records that disagree (lib/contradictions.js); read-only
13
16
  *
14
17
  * THE SWITCH. PMOS_DRIFT=off, or the shared guard's switch (lib/ai-guard.js off: PMOS_AI, the ai settings): every GET answers { ok, on: false }
15
18
  * and every POST 409. WHO WRITES: a POST that carries an agent session header is refused (403); pm-guard requirePagePress checks the page. */
@@ -60,6 +63,33 @@ async function handle(req, res, url, ctx) {
60
63
  return send(bad(500, 'The moves could not be read.'));
61
64
  }
62
65
  }
66
+ if (what === 'slip' || what === 'contradictions') {
67
+ // every slip against the first plan (lib/plan-baseline.js) and records that disagree (lib/contradictions.js): initiative
68
+ // slip-baseline-contradictions. Read-only, no model, so the drift switch does not gate them.
69
+ if (req.method !== 'GET') return send(bad(405, 'GET only'));
70
+ let w = null;
71
+ try { w = ctx.getWs(url.searchParams.get('ws') || null); } catch { w = null; }
72
+ if (!w || !w.root) return send(bad(404, 'no such workspace'));
73
+ const mod = what === 'slip' ? require('./plan-baseline.js') : require('./contradictions.js');
74
+ try {
75
+ const stateDir = ctx.stateDirFor ? ctx.stateDirFor(w) : null;
76
+ let rows = [];
77
+ try { const IR = require('./initiative-rows.js').rowsFor(w.root); rows = IR && IR.ok ? IR.rows : []; } catch { rows = []; }
78
+ const f = require('./drift-facts.js').factsOf({ id: w.id, name: w.name || w.id, root: w.root }, { stateDir, rows });
79
+ const now = nowMs(ctx);
80
+ if (what === 'slip') {
81
+ const r = mod.slipOf(f, { today: new Date(now).toISOString().slice(0, 10) });
82
+ console.log(`${mod.TAG} ws=${w.id} tasks=${r.tasks} days=${r.days} unsourced_days=${r.unsourced_days}`);
83
+ return send({ status: 200, body: { ok: true, ws: w.id, name: w.name || w.id, notRead: f.notRead, ...r } });
84
+ }
85
+ const items = mod.contradictionsOf(f, { now });
86
+ console.log(`${mod.TAG} ws=${w.id} items=${items.length}`);
87
+ return send({ status: 200, body: { ok: true, ws: w.id, name: w.name || w.id, notRead: f.notRead, items, total: items.length } });
88
+ } catch (e) {
89
+ console.warn(mod.TAG + ' could not read ' + w.id + ': ' + ((e && e.message) || e));
90
+ return send(bad(500, 'The records could not be read.'));
91
+ }
92
+ }
63
93
  if (!['drop', 'undo', 'looked'].includes(what)) return send(bad(404, 'no such drift route'));
64
94
  if (req.method !== 'POST') return send(bad(405, 'POST only'));
65
95
  if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'Only you drop an item, from the page.'));
@@ -123,12 +123,17 @@ async function realBrief(ctx, ev, date) {
123
123
  const layers = require('./calendar-layers.js');
124
124
  const views = require('./routes-calendar-views.js');
125
125
  let inis = [];
126
- if (root) { try { const facts = await require('./facts-async.js').readFactsAsync(root); inis = ((facts && facts.inis) || []).filter((i) => i && i.id).map((i) => ({ id: i.id, title: i.title || i.id, status: null })); } catch { inis = []; } }
126
+ if (root) { try { const facts = await require('./facts-async.js').readFactsAsync(root); inis = ((facts && facts.inis) || []).filter((i) => i && i.id).map((i) => ({ id: i.id, title: i.title || i.id, status: null, parent_kr: i.parent_kr || null })); } catch { inis = []; } }
127
127
  const src = root ? views.readers(root, ctx.runtimeDir).readContextSources() : { notes: [], planItems: [], ownItems: [] };
128
128
  const mine = (src.notes || []).filter((n) => n.meeting && (n.meeting.event_id === ev.id || n.meeting.event_id === baseId(ev.id)));
129
129
  let links = null; try { links = require('./calendar-links.js').read(ctx.runtimeDir); } catch { links = null; }
130
130
  let boards = null; try { boards = require('./routes-boards.js').meetingBoards(ctx); } catch { boards = null; }
131
131
  brief = layers.briefOf(ev, mine, src, { today: localDay(Date.now()), inis, links, boards }).brief || null;
132
+ // meeting-float: the initiative's goal, from its anchor (a key result, an objective or a health budget)
133
+ if (brief && brief.initiative && root) {
134
+ const row = inis.find((i) => i.id === brief.initiative.id);
135
+ if (row && row.parent_kr) { try { const g = F.goalOf(row.parent_kr, require('./initiative-rows.js').anchorsOf(root).resolve); if (g) brief.initiative.goal = g; } catch { /* no goal */ } }
136
+ }
132
137
  } catch { brief = null; }
133
138
  briefCache.set(key, { at: Date.now(), brief });
134
139
  return brief;
@@ -5,7 +5,8 @@
5
5
  * GET /api/open-questions?ws=<id> → { ok, ws, today, lines: [lib/open-questions.js line], median_age }
6
6
  *
7
7
  * The day's question list comes from lib/routes-your-move.js questions() with take: false, so this read never takes a default (taking
8
- * stays with Your move, lib/default-decisions.js). The open Driver drafts come from the repository's driver.jsonl. Nothing is sent. */
8
+ * stays with Your move, lib/default-decisions.js). The open Driver drafts come from the repository's driver.jsonl. Records that disagree come
9
+ * from lib/contradictions.js (initiative slip-baseline-contradictions). Nothing is sent. */
9
10
  const OQ = require('./open-questions.js');
10
11
 
11
12
  module.exports = {
@@ -19,8 +20,14 @@ module.exports = {
19
20
  const now = Date.now(), today = OQ.localDay(now);
20
21
  let questions = null;
21
22
  try { questions = require('./routes-your-move.js').questions(ctx, w, today, { take: false }).questions; } catch { questions = null; }
23
+ // records that disagree (lib/contradictions.js): from the initiative rows as already read, never a synchronous derive on a request
24
+ let records = [];
22
25
  try {
23
- const r = OQ.read(w.root, { now, questions });
26
+ const IR = require('./initiative-rows.js').rowsFor(w.root);
27
+ if (IR && IR.ok) records = require('./contradictions.js').forRepo(w.root, { now, rows: IR.rows, id: w.id, name: w.name, stateDir: ctx.stateDirFor ? ctx.stateDirFor(w) : undefined }).items;
28
+ } catch { records = []; }
29
+ try {
30
+ const r = OQ.read(w.root, { now, questions, records });
24
31
  console.log(`${OQ.TAG} ws=${w.id} lines=${r.lines.length} median_age=${r.median_age}`);
25
32
  ctx.json(res, { ok: true, ws: w.id, ...r });
26
33
  } catch (e) { ctx.json(res, { ok: false, error: String((e && e.message) || e) }, 500); }
@@ -19,6 +19,8 @@
19
19
  * dates that meet are a guess) is not sourced.
20
20
  * owner who to ask: the task's owner, else the PM ('you', toPm) when the plan names nobody or names an agent
21
21
  * ref path:line of the line it came from, and `quote` that line's text (lib/drift-facts.js)
22
+ * baseline a date row's first due date (the task's first plan) and `behind` the days from it to the new date, negative when ahead
23
+ * (initiative slip-baseline-contradictions, lib/plan-baseline.js)
22
24
  *
23
25
  * CLI: node lib/week-moves.js list|count [<root>] [--week YYYY-MM-DD] [--json]. `count` ends with the number of moves on its last line.
24
26
  * Every log line carries [moves]. */
@@ -74,7 +76,7 @@ function productMoves(f, from, to) {
74
76
  const rows = [], scope = new Map();
75
77
  for (const t of f.tasks || []) {
76
78
  const lines = (t.lines || []).filter((l) => Number.isFinite(l.at)).slice().sort((a, b) => a.at - b.at);
77
- let due, owner;
79
+ let due, owner, first = null; // first: the task's first due date, its baseline (lib/plan-baseline.js; initiative slip-baseline-contradictions)
78
80
  for (const l of lines) {
79
81
  if (typeof l.owner === 'string' && l.owner.trim()) owner = l.owner;
80
82
  const inWeek = l.at >= from && l.at < to;
@@ -89,7 +91,11 @@ function productMoves(f, from, to) {
89
91
  }
90
92
  if (l.due !== undefined) {
91
93
  const next = isDate(l.due) ? String(l.due).slice(0, 10) : '';
92
- if (inWeek && l.kind === 'task-update' && due !== undefined && next !== due) rows.push({ ...base(), kind: 'date', n: 1, titles: [t.title], was: due || null, now: next || null });
94
+ if (inWeek && l.kind === 'task-update' && due !== undefined && next !== due) {
95
+ const behind = first && next ? Math.round((Date.parse(next + 'T00:00:00Z') - Date.parse(first + 'T00:00:00Z')) / 86400000) : null;
96
+ rows.push({ ...base(), kind: 'date', n: 1, titles: [t.title], was: due || null, now: next || null, baseline: first, behind });
97
+ }
98
+ if (first === null && next) first = next;
93
99
  due = next;
94
100
  }
95
101
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.761.0",
3
+ "version": "0.762.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.761.0",
9
+ "version": "0.762.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.761.0",
3
+ "version": "0.762.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -86,7 +86,8 @@ async function context(o = {}) {
86
86
  ok('T1 in the room (no screen) the tab is the light page: no dark stage, no picture', await until(() => tab.evaluate(() => document.getElementById('rt').dataset.mode === 'room' && !document.querySelector('.rt-scr'))), await tab.evaluate(() => document.getElementById('rt').dataset.mode));
87
87
  ok('T1 the header is the clock and the title; the browser tab says the clock', await until(() => tab.evaluate(() => /^\d+:\d{2}$/.test(document.getElementById('rtClock').textContent) && document.getElementById('rtTitle').textContent === 'Design crit' && /^\d+:\d{2} · Design crit$/.test(document.title))));
88
88
  const bar = await tab.evaluate(() => [...document.querySelectorAll('#rtBar > .rt-b')].map((b) => [b.getAttribute('aria-label'), b.textContent.trim()]));
89
- ok('T1 the bar is icon only: Highlight, Pause, then the red Stop (no screenshots toggle in the room)', JSON.stringify(bar.map((x) => x[0])) === JSON.stringify(['Highlight the last 30 seconds', 'Pause', 'Stop the recording']) && bar.every((x) => x[1] === ''), JSON.stringify(bar));
89
+ // meeting-float: Float PMOS over the call sits before Stop where the browser can float a page (Document Picture-in-Picture)
90
+ ok('T1 the bar is icon only: Highlight, Pause, Float where the browser can, then the red Stop (no screenshots toggle in the room)', JSON.stringify(bar.map((x) => x[0]).filter((l) => l !== 'Float PMOS over the call')) === JSON.stringify(['Highlight the last 30 seconds', 'Pause', 'Stop the recording']) && bar.every((x) => x[1] === ''), JSON.stringify(bar));
90
91
  ok('T1 the slots for the Now panel and Present are in the bar', await tab.evaluate(() => !!document.querySelector('#rtBar [data-slot="now"]') && !!document.querySelector('#rtBar [data-slot="present"]')));
91
92
  ok('T1 links in the recording tab open in the other PMOS tab', await tab.evaluate(() => document.querySelector('base').target === 'pmos-main') && await p.evaluate(() => window.name === 'pmos-main'));
92
93
 
@@ -164,3 +164,165 @@ export function heardHtml(m) {
164
164
  const h = consentHtml(m) + nudgeHtml(m) + filedHtml(m) + draftsHtml(m);
165
165
  return h ? `<div class="mb-card">${h}</div>` : '';
166
166
  }
167
+
168
+ /* ── the float (initiative meeting-float; Exploring 3, page "Meeting companion floats over the call") ─────────────────────────────────────
169
+ * walkInModel(F, { now }) → { title, at, startsIn, rows } | null the walk-in card: 2 min before the start until PMOS listens
170
+ * walkInHtml(w) → string
171
+ * openModel(F, m) → { forTopic, people, filed } the wide view (the open size)
172
+ * openHtml(m, o) → string two columns: Now and For this topic · People, Filed, drafts
173
+ * roomModel(F, m) → { asked, table, agreed } room view: what the user shares on screen in the call
174
+ * roomHtml(m, r) → string no private row and no press: no drafts, consent, Undo, own asks, People */
175
+ export const WALK_BEFORE_MIN = 2, WALK_AFTER_MIN = 10;
176
+ const MINE = /^(me|i|you|myself|pm)$/i;
177
+ const OPEN_MAX = 6, ROOM_ASKED_MAX = 4;
178
+ const dayOf = (iso) => { const t = Date.parse(iso || ''); if (!Number.isFinite(t)) return ''; const d = new Date(t); return d.getDate() + ' ' + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()]; };
179
+ const tokens = (s) => String(s == null ? '' : s).toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
180
+ /** Which attendee an owner names: the attendee's full name, or a first name both share. null when none. */
181
+ export function attendeeOf(owner, attendees) {
182
+ const o = tokens(owner); if (!o.length) return null;
183
+ for (const a of attendees || []) {
184
+ const t = tokens(a); if (!t.length) continue;
185
+ if (t.join(' ') === o.join(' ') || t[0] === o[0]) return String(a);
186
+ }
187
+ return null;
188
+ }
189
+ const iniHref = (ini) => (ini && ini.id ? '/premium.html?ini=' + encodeURIComponent(ini.id) : null);
190
+ const goalText = (g) => (g && g.title ? clip(g.title, 90) : '');
191
+ /** What each side owes, from the last meeting's actions and the user's own late items. */
192
+ function owesOf(f) {
193
+ const b = f.brief || {}; const att = (f.event && f.event.attendees) || [];
194
+ const theirs = [], mine = [];
195
+ for (const a of (b.last && Array.isArray(b.last.actions) ? b.last.actions : [])) {
196
+ if (!a || !a.text) continue;
197
+ const text = clip(a.text, 140) + (a.due ? ', due ' + (dayOf(a.due) || a.due) : '');
198
+ if (a.owner && MINE.test(String(a.owner).trim())) mine.push({ who: '', text });
199
+ else { const who = attendeeOf(a.owner, att); if (who) theirs.push({ who, text }); }
200
+ }
201
+ for (const x of Array.isArray(b.matters) ? b.matters : []) if (x && /^yours\b/.test(String(x.meta || '')) && x.text) mine.push({ who: '', text: clip(x.text, 140) });
202
+ return { theirs, mine };
203
+ }
204
+ /** The one thing to settle: a blocked item, then a late one, then decisions from last time still to confirm. */
205
+ function settleOf(b) {
206
+ const M = Array.isArray(b.matters) ? b.matters : [];
207
+ const blocked = M.find((x) => x && x.tag === 'Blocked'); if (blocked) return clip(blocked.text, 160);
208
+ const late = M.find((x) => x && x.tag === 'Late'); if (late) return clip(late.text, 140) + ': late';
209
+ const n = b.last && b.last.to_confirm; if (n > 0) return n + (n === 1 ? ' decision' : ' decisions') + ' from last time to confirm';
210
+ return '';
211
+ }
212
+ function iniRow(b) {
213
+ const ini = b.initiative; if (!ini || !ini.title) return null;
214
+ const blocked = (Array.isArray(b.matters) ? b.matters : []).filter((x) => x && x.tag === 'Blocked').length;
215
+ return { label: 'Work', text: clip(ini.title, 100) + (ini.status ? ' · ' + ini.status : ''), tag: blocked ? blocked + ' blocked' : '', sub: goalText(ini.goal) ? 'Goal: ' + goalText(ini.goal) : '', href: iniHref(ini) };
216
+ }
217
+ function goalRow(b) {
218
+ const g = b.initiative && b.initiative.goal; if (!g || !g.title) return null;
219
+ return { label: 'Goal', text: goalText(g), sub: g.kind === 'health' ? 'Health budget' : g.kind === 'objective' ? 'Objective' : 'Key result' };
220
+ }
221
+ function lastDecisionRow(b) {
222
+ const d = b.last && Array.isArray(b.last.decisions) ? b.last.decisions[0] : null; if (!d) return null;
223
+ const on = dayOf(b.last.at);
224
+ return { label: 'Decided before' + (on ? ' · ' + on : ''), text: clip(d, 160), sub: b.last.title ? 'From the notes of ' + clip(b.last.title, 60) : '' };
225
+ }
226
+ function docRows(f) {
227
+ const out = []; const seen = new Set();
228
+ const call = f.event && f.event.call ? f.event.call.url : '';
229
+ for (const m of Array.isArray(f.material) ? f.material : []) {
230
+ const title = m && (m.title || m.url || m.ref); if (!title) continue;
231
+ const url = m.url && /^https:\/\//i.test(m.url) ? m.url : null;
232
+ const k = url || title; if (seen.has(k)) continue; seen.add(k);
233
+ out.push({ label: 'Document', text: clip(title, 100), sub: 'Linked to the meeting', href: url });
234
+ }
235
+ for (const l of f.event && Array.isArray(f.event.links) ? f.event.links : []) {
236
+ if (!l || !l.url || l.url === call || seen.has(l.url) || !/^https:\/\//i.test(l.url)) continue;
237
+ seen.add(l.url); out.push({ label: 'Document', text: clip(l.label || l.url, 100), sub: 'In the invite', href: l.url });
238
+ }
239
+ return out.slice(0, 3);
240
+ }
241
+
242
+ export function walkInModel(F, { now = Date.now() } = {}) {
243
+ const f = F && F.ok ? F : {};
244
+ const ev = f.event; if (!ev || f.talk) return null;
245
+ const st = f.note ? f.note.state : null;
246
+ if (st === 'recording' || st === 'paused' || st === 'ended') return null;
247
+ const start = Date.parse(ev.at || ''); if (!Number.isFinite(start)) return null;
248
+ if (now < start - WALK_BEFORE_MIN * 60000 || now >= start + WALK_AFTER_MIN * 60000) return null;
249
+ const b = f.brief || {};
250
+ const rows = [];
251
+ if (b.initiative && b.initiative.title) rows.push({ label: 'For', text: clip(b.initiative.title, 100) + (goalText(b.initiative.goal) ? ' · ' + goalText(b.initiative.goal) : ''), href: iniHref(b.initiative) });
252
+ const o = owesOf(f);
253
+ for (const x of o.theirs.slice(0, 2)) rows.push({ label: 'Owed to you', who: x.who.split(/\s+/)[0], text: x.text });
254
+ for (const x of o.mine.slice(0, 2)) rows.push({ label: 'You owe', text: x.text });
255
+ const d = lastDecisionRow(b); if (d) rows.push({ label: d.label.replace('Decided before', 'Last decision'), text: d.text });
256
+ const s = settleOf(b); if (s) rows.push({ label: 'Settle today', text: s, settle: true });
257
+ if (!rows.length) return null;
258
+ return { title: clip(ev.title, 120), at: hm(start), startsIn: Math.round((start - now) / 60000), rows };
259
+ }
260
+ export function walkInHtml(w) {
261
+ if (!w) return '';
262
+ const when = w.startsIn > 0 ? 'Starts in ' + w.startsIn + ' min · ' + w.at : w.startsIn === 0 ? 'Starts now · ' + w.at : 'Started ' + -w.startsIn + ' min ago · ' + w.at;
263
+ return `<section class="mb-walk" aria-label="Before the meeting"><div class="mb-wh"><small>${esc(when)}</small><b>${esc(w.title)}</b></div>`
264
+ + w.rows.map((r) => `<div class="mb-r${r.settle ? ' mb-settle' : ''}"><span class="t"><small>${esc(r.label)}</small>${r.who ? '<b>' + esc(r.who) + '</b> · ' : ''}${esc(r.text)}</span>`
265
+ + (r.href ? `<a class="mb-ib pm-btn" href="${esc(r.href)}" target="_blank" rel="noopener noreferrer" aria-label="Open it" title="Open it">${svg(P.open)}</a>` : r.settle ? `<span class="mb-spark">${svg(P.spark, 14)}</span>` : '') + '</div>').join('')
266
+ + '</section>';
267
+ }
268
+
269
+ export function openModel(F, m) {
270
+ const f = F && F.ok ? F : {}; const b = f.brief || {};
271
+ const forTopic = [];
272
+ const notes = Array.isArray(f.notes) ? f.notes : [];
273
+ for (const n of notes.slice().reverse()) {
274
+ if (forTopic.length >= 3 || !n || n.ask || !['Context', 'Fact check', 'Decision', 'Follow-up'].includes(n.cat)) continue;
275
+ const act = (n.acts || []).find((a) => hrefOf(a));
276
+ forTopic.push({ label: n.cat === 'Context' ? 'Context' : n.cat, text: clip(n.body, 200), sub: n.src ? clip(n.src, 80) : '', href: act ? hrefOf(act) : null });
277
+ }
278
+ for (const c of Array.isArray(f.chips) ? f.chips : []) {
279
+ if (forTopic.length >= 4) break;
280
+ const href = hrefOf(c); if (!href) continue;
281
+ forTopic.push({ label: 'Context', text: clip(c.label + (c.sub ? ' · ' + c.sub : ''), 160), sub: '', href });
282
+ }
283
+ for (const r of [iniRow(b), lastDecisionRow(b), ...docRows(f)]) if (r && forTopic.length < OPEN_MAX + 2) forTopic.push(r);
284
+ const o = owesOf(f);
285
+ const people = ((f.event && f.event.attendees) || []).slice(0, 8).map((name) => {
286
+ const theirs = o.theirs.filter((x) => x.who === name).map((x) => 'Owes you ' + x.text);
287
+ return { name: clip(name, 60), initials: tokens(name).slice(0, 2).map((t) => t[0].toUpperCase()).join(''), sub: theirs[0] || '' };
288
+ });
289
+ const cap = f.captured || {};
290
+ const filed = [];
291
+ for (const [kind, key] of [['decision', 'decisions'], ['action', 'actions'], ['question', 'questions']]) {
292
+ for (const x of Array.isArray(cap[key]) ? cap[key] : []) if (x && x.bid && x.text) filed.push({ kind, label: 'Filed · ' + KIND_WORD[kind], text: clip(x.text, 200), bid: String(x.bid) });
293
+ }
294
+ filed.sort((a, b2) => a.bid.localeCompare(b2.bid, 'en', { numeric: true }));
295
+ return { forTopic, people, filed, youOwe: o.mine.slice(0, 3) };
296
+ }
297
+ const listRow = (r) => `<div class="mb-r"><span class="t"><small>${esc(r.label)}</small>${esc(r.text)}${r.tag ? ` <span class="mb-tag">${esc(r.tag)}</span>` : ''}${r.sub ? `<span class="mb-src">${esc(r.sub)}</span>` : ''}</span>`
298
+ + (r.href ? `<a class="mb-ib pm-btn" href="${esc(r.href)}" target="_blank" rel="noopener noreferrer" aria-label="Open it" title="Open it">${svg(P.open)}</a>` : '') + '</div>';
299
+ const sec = (t, n) => `<div class="mb-sec">${esc(t)}${n != null ? ` <span>${esc(n)}</span>` : ''}</div>`;
300
+ export function openHtml(m, o) {
301
+ const left = topicHtml(m) + nowHtml(m) + nudgeHtml(m) + consentHtml(m)
302
+ + (o.forTopic.length ? `<div class="mb-sec"><span class="mb-spark">${svg(P.spark, 12)}</span>For this topic</div>` + o.forTopic.map(listRow).join('') : '') + answerHtml(m);
303
+ const people = o.people.length ? sec('People', o.people.length + ' in the invite') + o.people.map((p) => `<div class="mb-r mb-person"><span class="mb-av" aria-hidden="true">${esc(p.initials)}</span><span class="t">${esc(p.name)}${p.sub ? `<span class="mb-src">${esc(p.sub)}</span>` : ''}</span></div>`).join('') : '';
304
+ const owe = o.youOwe.length ? sec('You owe') + o.youOwe.map((x) => `<div class="mb-r"><span class="t">${esc(x.text)}</span></div>`).join('') : '';
305
+ const filed = o.filed.length ? sec('Filed', o.filed.length) + o.filed.map((x) => row(x.label, esc(x.text), ib('undo', 'Undo: take it out of the notes', P.undo, ` data-bid="${esc(x.bid)}"`))).join('') : '';
306
+ const right = people + owe + filed + draftsHtml(m);
307
+ return `<div class="mb-wide"><div class="mb-col">${left}</div>${right ? `<div class="mb-col">${right}</div>` : ''}</div>`;
308
+ }
309
+
310
+ export function roomModel(F, m) {
311
+ const f = F && F.ok ? F : {}; const b = f.brief || {};
312
+ const notes = Array.isArray(f.notes) ? f.notes : [];
313
+ const asked = notes.filter((n) => n && !n.ask && n.heard && (n.cat === 'Answer' || n.cat === 'Fact check')).slice(-ROOM_ASKED_MAX)
314
+ .map((n) => ({ heard: clip(n.heard, 200), body: clip(n.body, 400), src: n.from && n.from.length ? 'From ' + n.from.map((k) => FROM_WORDS[k]).filter(Boolean).join(' and ') : n.src ? clip(n.src, 80) : '' }));
315
+ const table = [goalRow(b), iniRow(b), ...docRows(f)].filter(Boolean).map((r) => ({ ...r, href: null, sub: r.label === 'Work' ? '' : r.sub }));
316
+ const cap = f.captured || {};
317
+ const agreed = [...(cap.decisions || []).map((x) => ({ label: 'Decision', text: x && x.text })), ...(cap.actions || []).map((x) => ({ label: 'Action', text: x && x.text }))]
318
+ .filter((x) => x.text).slice(-6).map((x) => ({ label: x.label, text: clip(x.text, 200) }));
319
+ return { asked, table, agreed };
320
+ }
321
+ export function roomHtml(m, r) {
322
+ const asked = r.asked.map((a) => `<div class="mb-r mb-heard"><span class="t"><small>Asked in the room</small>${esc(a.heard)}</span></div>`
323
+ + `<div class="mb-r"><span class="t"><small>PMOS</small>${esc(a.body)}${a.src ? `<span class="mb-src">${esc(a.src)}</span>` : ''}</span><span class="mb-spark">${svg(P.spark, 14)}</span></div>`).join('');
324
+ const left = topicHtml(m) + nowHtml(m) + (asked || '<div class="mb-r mb-quiet"><span class="t mb-sm">Ask PMOS out loud: a number, a date, what was decided. The answer shows here.</span></div>');
325
+ const right = (r.table.length ? `<div class="mb-sec"><span class="mb-spark">${svg(P.spark, 12)}</span>On the table</div>` + r.table.map(listRow).join('') : '')
326
+ + (r.agreed.length ? sec('Agreed so far') + r.agreed.map((x) => row(x.label, esc(x.text))).join('') : '');
327
+ return `<div class="mb-wide mb-room"><div class="mb-col">${left}</div>${right ? `<div class="mb-col">${right}</div>` : ''}</div>`;
328
+ }