create-pmos 0.727.0 → 0.729.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 (36) hide show
  1. package/package.json +39 -39
  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 +38 -0
  7. package/workspace/guide/cli.md +14 -0
  8. package/workspace/guide/jira.md +18 -0
  9. package/workspace/guide/layout.md +1 -1
  10. package/workspace/lib/change-cues.js +34 -0
  11. package/workspace/lib/jira-cli.js +101 -3
  12. package/workspace/lib/jira-criteria.js +214 -0
  13. package/workspace/lib/jira-status.js +10 -5
  14. package/workspace/lib/jira-tiers.js +266 -0
  15. package/workspace/lib/open-questions.js +163 -0
  16. package/workspace/lib/pmos-verbs.js +3 -0
  17. package/workspace/lib/questions-cli.js +97 -0
  18. package/workspace/lib/refresh-probe.js +5 -0
  19. package/workspace/lib/refresh-run.js +2 -0
  20. package/workspace/lib/route-modules.js +1 -0
  21. package/workspace/lib/routes-jira-epics.js +62 -4
  22. package/workspace/lib/routes-open-questions.js +29 -0
  23. package/workspace/package-lock.json +2 -2
  24. package/workspace/package.json +1 -1
  25. package/workspace/public/pm/change-cues.css +15 -0
  26. package/workspace/public/pm/change-cues.js +52 -0
  27. package/workspace/public/pm/cozy-pop-work.js +46 -3
  28. package/workspace/public/pm/cozy-today-app.js +11 -8
  29. package/workspace/public/pm/home-app.js +4 -2
  30. package/workspace/public/today.html +1 -0
  31. package/workspace/skills/jira-criteria.skill +35 -0
  32. package/workspace/skills/jira-sync.skill +7 -2
  33. package/workspace/test-lists/change-cues.json +9 -0
  34. package/workspace/test-lists/jira-criteria-write.json +9 -0
  35. package/workspace/test-lists/jira-tiered-refresh.json +9 -0
  36. package/workspace/test-lists/open-questions.json +9 -0
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+ /* open-questions.js — one register of every unanswered question across initiatives, each with its owner, its age and its default
3
+ * (initiative open-questions-register, bet A420 in pmos-ideas/bets.md; proofs stale-drafts and A26).
4
+ *
5
+ * DRAFT_DAYS · TAG
6
+ * draftsOf(state, { titleOf }) PURE → [draft ask] the open Driver drafts (lib/driver.js fold), one per proposal
7
+ * registerOf({ questions, drafts, today }) PURE → [line] one line per owner and initiative, oldest first
8
+ * medianAge(lines) PURE → integer the health number: the median age in days, 0 when nothing waits
9
+ * diskQuestions(root, { now }) → the day's other asks read from disk (dry-run gaps, sign-offs), as annotated questions
10
+ * read(root, { now, questions }) → { today, lines, median_age } drafts from the repository's driver.jsonl, plus `questions`
11
+ * (the day's list, lib/routes-your-move.js questions) or, without them, diskQuestions(root)
12
+ *
13
+ * THE SOURCES. (1) The day's question list (lib/question-batch.js, annotated by lib/default-decisions.js): the plan changes PMOS holds for
14
+ * want of a source, a drafted ticket's dry-run gaps and the outside sign-offs. Each question already has its owner, `waiting` (days on the
15
+ * list), and `default` or `waits`. (2) The open Driver drafts: a proposal in driver.jsonl with no keep, return or drop. Your move does not
16
+ * list them, and on four test products all 56 were older than 14 days.
17
+ *
18
+ * THE DEFAULT OF A DRAFT. A draft is a proposal: nothing lands until the PM keeps it. So the safe answer is to drop it, and nothing on the
19
+ * plan changes. It is due DRAFT_DAYS after the draft was filed (Your move's expiry window). The register says the default; it takes none.
20
+ * Taking defaults stays with lib/default-decisions.js.
21
+ *
22
+ * A LINE: { key, owner, toPm, ini, title, n, kinds: { change?, ask?, draft? }, since, age, default: { say, due } | null, waits, text, ids }.
23
+ * A line has a default only when every part of it has one; otherwise `waits` says why. Never both, never neither. Oldest first.
24
+ * Nothing here writes or sends anything. */
25
+
26
+ const DRAFT_DAYS = 14;
27
+ const TAG = '[open-questions]';
28
+ const MAX_ID_SHOW = 3;
29
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
30
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
31
+ const one = (v, n) => { const s = String(v == null ? '' : v).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
32
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
33
+ const dn = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? Math.round(Date.UTC(+m[1], +m[2] - 1, +m[3]) / 864e5) : null; };
34
+ const isoOf = (d) => new Date(d * 864e5).toISOString().slice(0, 10);
35
+ const md = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
36
+ const localDay = (ms = Date.now()) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
37
+ const WHAT = { problem: 'problem statement', evidence: 'evidence', sizing: 'sizing', assumption: 'riskiest assumption', stakeholders: 'stakeholders',
38
+ move: 'stage move', note: 'note', doc: 'document draft', overlap: 'possible overlap', artefact: 'artefact', 'next-step': 'next step', 'follow-up': 'follow-up' };
39
+
40
+ /** The open Driver drafts, one ask each. PURE. state: lib/driver.js fold(lines). titleOf(target) → a title or ''. */
41
+ function draftsOf(state, { titleOf = () => '' } = {}) {
42
+ const out = [];
43
+ if (!state || !Array.isArray(state.order) || !(state.proposals instanceof Map)) return out;
44
+ for (const id of state.order) {
45
+ const p = state.proposals.get(id);
46
+ if (!p || p.state !== 'open' || !isObj(p.target) || !p.target.id) continue;
47
+ const ini = p.target.kind === 'work' ? 'work:' + p.target.id : String(p.target.id);
48
+ let title = '';
49
+ try { title = titleOf(p.target) || ''; } catch { title = ''; }
50
+ const why = one(p.why || (isObj(p.data) && (p.data.text || p.data.title)) || '', 100);
51
+ out.push({ id: String(id), ini, title: title || String(p.target.id), at: p.at || '', what: p.what || '',
52
+ text: `${WHAT[p.what] || 'draft'}${why ? ': ' + why : ''}` });
53
+ }
54
+ return out;
55
+ }
56
+
57
+ /** One register: the day's questions and the open drafts, one line per owner and initiative, oldest first. PURE.
58
+ * questions: lib/routes-your-move.js questions().questions (each { key, owner, toPm, ini, title, ids, n, text, default, waits, waiting }).
59
+ * drafts: draftsOf(). today: 'YYYY-MM-DD'. pm: the owner word for the PM. */
60
+ function registerOf({ questions = [], drafts = [], today = '', pm = 'PM' } = {}) {
61
+ const t = dn(today);
62
+ const by = new Map();
63
+ const seen = new Set();
64
+ const lineOf = (owner, toPm, ini, title) => {
65
+ const key = (toPm ? '' : owner) + '|' + ini;
66
+ if (!by.has(key)) by.set(key, { key, owner: toPm ? pm : owner, toPm, ini, title: title || ini, n: 0, kinds: {}, ages: [], dues: [], says: [], waits: [], parts: [], ids: [] });
67
+ const l = by.get(key);
68
+ if ((!l.title || l.title === ini) && title) l.title = title;
69
+ return l;
70
+ };
71
+ for (const q of questions || []) {
72
+ if (!isObj(q) || !q.ini) continue;
73
+ const ids = (Array.isArray(q.ids) ? q.ids : []).map(String).filter((id) => !seen.has(id));
74
+ if (!ids.length && Array.isArray(q.ids) && q.ids.length) continue;
75
+ ids.forEach((id) => seen.add(id));
76
+ const l = lineOf(q.owner || pm, q.toPm === true || !q.owner, q.ini, q.title);
77
+ const n = ids.length || Number(q.n) || 1;
78
+ const asks = Number(q.asks) || 0;
79
+ if (n - asks > 0) l.kinds.change = (l.kinds.change || 0) + (n - asks);
80
+ if (asks) l.kinds.ask = (l.kinds.ask || 0) + asks;
81
+ l.n += n;
82
+ l.ids.push(...ids);
83
+ l.ages.push(Math.max(0, Number(q.waiting) || 0));
84
+ if (isObj(q.default) && q.default.due && !q.waits) { l.dues.push(q.default.due); l.says.push(q.default.say || ''); }
85
+ if (q.waits) l.waits.push(q.waits);
86
+ else if (!isObj(q.default)) l.waits.push('PMOS has no safe default for it, so it waits for an answer.');
87
+ if (q.text) l.parts.push(one(q.text, 300));
88
+ }
89
+ const draftBy = new Map();
90
+ for (const d of drafts || []) {
91
+ if (!isObj(d) || !d.id || !d.ini || seen.has(String(d.id))) continue;
92
+ seen.add(String(d.id));
93
+ if (!draftBy.has(d.ini)) draftBy.set(d.ini, []);
94
+ draftBy.get(d.ini).push(d);
95
+ }
96
+ for (const [ini, ds] of draftBy) {
97
+ const l = lineOf(pm, true, ini, ds[0].title);
98
+ const firstDay = ds.map((d) => dn(d.at)).filter((x) => x != null).sort((a, b) => a - b)[0];
99
+ const age = firstDay != null && t != null ? Math.max(0, t - firstDay) : 0;
100
+ const due = firstDay != null ? isoOf(firstDay + DRAFT_DAYS) : '';
101
+ l.kinds.draft = ds.length;
102
+ l.n += ds.length;
103
+ l.ids.push(...ds.map((d) => String(d.id)));
104
+ l.ages.push(age);
105
+ if (due) { l.dues.push(due); l.says.push(`PMOS drops the ${ds.length === 1 ? 'draft' : 'drafts'}; nothing on the plan changes`); }
106
+ else l.waits.push('PMOS cannot read when the drafts were filed, so they wait for an answer.');
107
+ const shown = ds.slice(0, MAX_ID_SHOW).map((d) => d.text);
108
+ l.parts.push(`${plural(ds.length, 'draft from PMOS', 'drafts from PMOS')}: ${shown.join('; ')}${ds.length > shown.length ? `; and ${ds.length - shown.length} more` : ''}.`);
109
+ }
110
+ const out = [];
111
+ for (const l of by.values()) {
112
+ const age = l.ages.length ? Math.max(...l.ages) : 0;
113
+ const since = t != null ? isoOf(t - age) : '';
114
+ const hasDefault = l.waits.length === 0 && l.dues.length > 0;
115
+ const due = hasDefault ? l.dues.slice().sort()[0] : '';
116
+ const sayWhat = [...new Set(l.says.filter(Boolean))].join(', and ');
117
+ out.push({
118
+ key: l.key, owner: l.owner, toPm: l.toPm, ini: l.ini, title: l.title, n: l.n, kinds: l.kinds, since, age,
119
+ default: hasDefault ? { due, say: `If nobody answers by ${md(due)}, ${sayWhat}.` } : null,
120
+ waits: hasDefault ? null : [...new Set(l.waits.length ? l.waits : ['It waits for an answer.'])].join(' '),
121
+ text: one(l.parts.join(' '), 600), ids: l.ids,
122
+ });
123
+ }
124
+ return out.sort((a, b) => b.age - a.age || (a.toPm === b.toPm ? 0 : a.toPm ? -1 : 1) || a.title.localeCompare(b.title) || a.owner.localeCompare(b.owner));
125
+ }
126
+
127
+ /** The median age in days of the lines, rounded down; 0 when nothing waits. PURE. */
128
+ function medianAge(lines) {
129
+ const a = (lines || []).map((l) => Math.max(0, Number(l && l.age) || 0)).sort((x, y) => x - y);
130
+ if (!a.length) return 0;
131
+ const m = a.length >> 1;
132
+ return Math.floor(a.length % 2 ? a[m] : (a[m - 1] + a[m]) / 2);
133
+ }
134
+
135
+ /** The day's other asks read from the records on disk (dry-run gaps, sign-offs), as questions with their reason to wait. No server needed.
136
+ * Held plan changes need the boards a workspace server reads, so they are not here. */
137
+ function diskQuestions(root, { now = Date.now() } = {}) {
138
+ const YM = require('./routes-your-move.js'), QB = require('./question-batch.js'), DD = require('./default-decisions.js');
139
+ let extra = [];
140
+ try { extra = YM.asksOf(root, now); } catch { extra = []; }
141
+ if (!extra.length) return [];
142
+ return DD.annotate(QB.questionsOf([], { extra }), [], { today: localDay(now), extra });
143
+ }
144
+
145
+ /** The register of a repository. questions: the day's list from the server; without it the disk asks. */
146
+ function read(root, { now = Date.now(), questions = null, pm = 'PM' } = {}) {
147
+ const D = require('./driver.js');
148
+ const today = localDay(now);
149
+ let drafts = [];
150
+ try {
151
+ const dir = D.stateDirOf(root);
152
+ if (dir) {
153
+ const JT = require('./jira-tickets.js');
154
+ const titleOf = (t) => (t.kind === 'initiative' ? ((JT.recordFm(root, t.id) || {}).title || '') : '');
155
+ drafts = draftsOf(D.fold(D.readLines(D.ledgerFile(dir))), { titleOf });
156
+ }
157
+ } catch { drafts = []; }
158
+ const qs = Array.isArray(questions) ? questions : diskQuestions(root, { now });
159
+ const lines = registerOf({ questions: qs, drafts, today, pm });
160
+ return { today, lines, median_age: medianAge(lines) };
161
+ }
162
+
163
+ module.exports = { DRAFT_DAYS, TAG, draftsOf, registerOf, medianAge, diskQuestions, read, localDay };
@@ -133,6 +133,9 @@ const VERBS = Object.freeze({
133
133
  // Not a pm-os-absorb verb (run: null): initiative page-fix-count-first (bet A462) added it through the same table.
134
134
  pages: Object.freeze({ module: 'pages-cli.js', run: null, guide: 'cli.md',
135
135
  help: 'pmos pages [show|check] — each page\'s fixes, reverts and restores in the last 14 days, and a feature change that adds to a page that keeps breaking (pmos pages help)' }),
136
+ // Not a pm-os-absorb verb (run: null): initiative open-questions-register (bet A420) added it through the same table.
137
+ questions: Object.freeze({ module: 'questions-cli.js', run: null, guide: 'cli.md',
138
+ help: 'pmos questions [age] — every unanswered question across initiatives, oldest first, with who can answer, its age and its default (pmos questions help)' }),
136
139
  // Not a pm-os-absorb verb (run: null): initiative three-line-why (bet A86) added it through the same table.
137
140
  why: Object.freeze({ module: 'why-cli.js', run: null, guide: 'cli.md',
138
141
  help: 'pmos why <initiative or task> | coverage — why the work exists in three lines: goal, problem, evidence, read from its records (pmos why help)' }),
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+ /* questions-cli.js — `pmos questions …`: every unanswered question across initiatives in one list (initiative open-questions-register,
3
+ * bet A420; lib/open-questions.js).
4
+ *
5
+ * pmos questions [--json] [--root <dir>] [--ws <id>] the register: one line per owner and initiative, oldest first
6
+ * pmos questions age [--root <dir>] [--ws <id>] the median age in days of the lines; the last line is the number
7
+ *
8
+ * With a workspace server running it asks GET /api/open-questions, so the held plan changes are in the list. With none (or with
9
+ * --root) it reads the records on disk: the open Driver drafts, the dry-run gaps and the sign-offs, and says that held plan changes
10
+ * were not read. It writes nothing and takes no default. Exit codes: 0 done (an empty list is done), 1 the list could not be read, 2 usage.
11
+ */
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const { execFileSync } = require('child_process');
15
+ const OQ = require('./open-questions.js');
16
+
17
+ const COMMANDS = { questions: ['age'] };
18
+ const USAGE = [
19
+ 'usage: pmos questions [age] — every unanswered question across initiatives, oldest first',
20
+ ' pmos questions one line per person and initiative: who can answer, how many days it waited, and what PMOS does',
21
+ ' if nobody answers (and by when), or why it waits',
22
+ ' pmos questions age the median age in days of those lines; the last line is the number',
23
+ ' every command: [--json] [--root <dir>] [--ws <id>]',
24
+ 'It shows the defaults and takes none. Nothing is sent.',
25
+ ];
26
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
27
+
28
+ function repoRoot(cwd) {
29
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
30
+ catch { return cwd; }
31
+ }
32
+
33
+ function parse(argv) {
34
+ const pos = []; const flags = {};
35
+ for (let i = 0; i < argv.length; i++) {
36
+ const a = argv[i];
37
+ if (a === '--root' || a === '--ws') flags[a.slice(2)] = argv[++i];
38
+ else if (a.startsWith('--root=')) flags.root = a.slice(7);
39
+ else if (a.startsWith('--ws=')) flags.ws = a.slice(5);
40
+ else if (a.startsWith('--')) flags[a.slice(2)] = true;
41
+ else if (a === '-h') flags.help = true;
42
+ else pos.push(a);
43
+ }
44
+ return { pos, flags };
45
+ }
46
+
47
+ /** The register from the server, or null when none answers for this repository. */
48
+ async function fromServer(call, root, ws) {
49
+ let id = ws || null;
50
+ if (!id) {
51
+ const list = await call('GET', '/api/workspaces');
52
+ const mine = list && Array.isArray(list.workspaces) ? list.workspaces.find((x) => x && x.root && path.resolve(x.root) === root) : null;
53
+ id = mine ? mine.id : null;
54
+ }
55
+ if (!id) return null;
56
+ const r = await call('GET', '/api/open-questions?ws=' + encodeURIComponent(id));
57
+ return r && r.ok ? r : null;
58
+ }
59
+
60
+ async function run(argv, { say = (s) => console.log(s), call = async () => null, cwd = process.cwd(), now = Date.now() } = {}) {
61
+ const { pos, flags } = parse(argv[0] === 'questions' ? argv.slice(1) : argv.slice());
62
+ if (flags.help || pos[0] === 'help') { for (const l of USAGE) say(l); return 0; }
63
+ if (pos.length && pos[0] !== 'age') { say(`✗ ${pos[0]} is not a command of pmos questions`); for (const l of USAGE) say(l); return 2; }
64
+ if (flags.root === true || flags.ws === true || flags.root === '' || flags.ws === '') { say('✗ --root and --ws need a value'); return 2; }
65
+ const root = path.resolve(flags.root || repoRoot(cwd));
66
+ if (flags.root) { let dir = false; try { dir = fs.statSync(root).isDirectory(); } catch { dir = false; } if (!dir) { say(`✗ ${root} is not a directory`); return 1; } }
67
+ const json = !!flags.json;
68
+
69
+ let r = null, held = false;
70
+ if (!flags.root) {
71
+ try { r = await fromServer(call, root, flags.ws); } catch { r = null; }
72
+ held = !!r;
73
+ if (flags.ws && !r) { say(`✗ the workspace ${flags.ws} could not be reached: no workspace server answered. Start it, or give --root <dir>.`); return 1; }
74
+ }
75
+ if (!r) {
76
+ try { r = OQ.read(root, { now }); } catch (e) { say(`✗ the questions could not be read: ${String((e && e.message) || e).slice(0, 200)}`); return 1; }
77
+ }
78
+
79
+ if (pos[0] === 'age') {
80
+ if (json) { say(JSON.stringify({ ok: true, lines: r.lines.length, median_age: r.median_age, held_read: held })); return 0; }
81
+ say(`${OQ.TAG} ${plural(r.lines.length, 'open question line', 'open question lines')}, median age ${plural(r.median_age, 'day', 'days')}.`);
82
+ say(String(r.median_age));
83
+ return 0;
84
+ }
85
+ if (json) { say(JSON.stringify({ ok: true, today: r.today, lines: r.lines, median_age: r.median_age, held_read: held })); return 0; }
86
+ if (!r.lines.length) say('Nothing waits for an answer.');
87
+ for (const l of r.lines) {
88
+ say(`${l.title} (${l.ini}) · ${l.toPm ? 'you' : l.owner} · waiting ${plural(l.age, 'day', 'days')}`);
89
+ say(` ${l.text}`);
90
+ say(` ${l.default ? l.default.say : l.waits}`);
91
+ }
92
+ if (!held) say('No workspace server answered, so plan changes PMOS holds for want of a source were not read. Open the workspace to see them too.');
93
+ say(`${OQ.TAG} ${plural(r.lines.length, 'line', 'lines')}, median age ${plural(r.median_age, 'day', 'days')}.`);
94
+ return 0;
95
+ }
96
+
97
+ module.exports = { run, COMMANDS, USAGE };
@@ -66,6 +66,11 @@ function since(rt, source, dirs = {}, now = Date.now()) {
66
66
  if (!last.at) { verdict = 'full'; why = 'nothing is stored yet'; }
67
67
  else if (!full) { verdict = 'full'; why = 'no full read is recorded yet'; }
68
68
  else if (now - full > FULL_MS) { verdict = 'full'; why = 'the last full read is older than 24 hours'; }
69
+ // jira-tiered-refresh: once `pmos jira query --changed` planned the refresh, its weekly full read replaces the 24-hour rule
70
+ if (source === 'jira' && last.at) {
71
+ const due = require('./jira-tiers.js').fullDue(dirs.jira);
72
+ if (due) { verdict = due.length ? 'full' : 'ask'; why = due.length ? `a full read is due for ${due.join(', ')}` : 'the tiered check asks Jira what changed among every tracked ticket'; }
73
+ }
69
74
  // the question's window in whole minutes, with 5 minutes to spare, for a search that takes "updated in the last N minutes"
70
75
  const out = { ok: true, source, last_read_at: iso(last.at), full_at: iso(full), verdict, why, ...(last.at ? { minutes: Math.max(1, Math.ceil((now - last.at) / 60000)) + 5 } : {}) };
71
76
  if (last.per) out.tools = Object.fromEntries(Object.entries(last.per).map(([k, v]) => [k, { read_at: iso(v.at), state: v.state }]));
@@ -308,6 +308,8 @@ function create(host) {
308
308
  // "Checked 10:42 · same since 09:15" (canvas SrSee R3, CnA): when this read was measured, and since when its facts are the same
309
309
  if (fp) next.seen = { at: t, since: change === 'same' ? (st.seen && st.seen.since) || null : t };
310
310
  else measured = { how: asked ? 'asked' : 'full' };
311
+ // jira-tiered-refresh: what the tiered check searched and fetched, so the outcome is a count (tiers, checked, fetched, mode)
312
+ if (id === 'jira') { let ts = null; try { ts = require('./jira-tiers.js').runStats(dirs.jira, o.at); } catch { ts = null; } if (ts) measured = { ...(measured || {}), ...ts }; }
311
313
  if (!asked) next.full_at = t;
312
314
  } catch (e) { warn('read fingerprint', e); }
313
315
  }
@@ -51,6 +51,7 @@ const MODULES = Object.freeze([
51
51
  'routes-doc-health', // console3 B2: the six document health checks, recomputed from text
52
52
  'routes-outbox', // console3 B3: the outbox queue, hash-bound confirm (no channel connected)
53
53
  'routes-waiting', // home-your-move-waiting: Waiting on others, derived from records, with its exit rule
54
+ 'routes-open-questions', // open-questions-register (A420): one register of every unanswered question, with owner, age and default
54
55
  'routes-calendar-views', // console3 C2: Day/Week/Month/Quarter/Year cells, Gantt and the strategy lens (read-only)
55
56
  'routes-events-place', // events-place (nav slice 6): every date PMOS holds, grouped Late / Today / Coming up, and the PM's fixed marks and noes (events/marks.jsonl; page-press POST)
56
57
  'routes-briefing', // console3 C1: the day-part Briefing cards from the signal engine (read-only)
@@ -7,27 +7,85 @@
7
7
  *
8
8
  * A ticket assigned to the PM is direct: a jira-epic session with the PM's own Atlassian connection sets its epic and answers with
9
9
  * `pmos jira epic-done`. Every other ticket waits in the day's draft for its owner, which the PM reads first. This route makes no request to
10
- * Jira (D53). Every POST passes pm-guard requirePagePress: the page only. */
10
+ * Jira (D53). Every POST passes pm-guard requirePagePress: the page only.
11
+ *
12
+ * The done test's acceptance criteria on the Jira tickets an initiative tracks (initiative jira-criteria-write, A384; lib/jira-criteria.js
13
+ * is the store), the same shape:
14
+ * GET /api/jira-criteria?ws&ini → { ok, proposals, unmatched, doneTest, asks, draft } the ✦'s proposals and what waits
15
+ * POST /api/jira-criteria/ask { ws, ini, keys } → { ok, direct: [key], draft: [{ key, who }], ids, skipped, session? }
16
+ * POST /api/jira-criteria/undo { ws, ids } → { ok, withdrawn, kept }
17
+ * The blocks are computed by the server from the done test; the page sends keys only. A ticket assigned to the PM is direct: one
18
+ * jira-criteria session writes it with the PM's own Atlassian connection. */
11
19
  const fs = require('fs');
12
20
  const path = require('path');
13
21
  const guard = require('./pm-guard.js');
14
22
  const JE = require('./jira-epics.js');
23
+ const JC = require('./jira-criteria.js');
15
24
 
16
25
  const pmNameOf = () => { try { return require('./routes-board-publish.js').sharedBy() || process.env.PMOS_PM_NAME || ''; } catch { return process.env.PMOS_PM_NAME || ''; } };
17
26
  const SKILL = path.join(__dirname, '..', 'skills', 'jira-epic.skill');
27
+ const CRITERIA_SKILL = path.join(__dirname, '..', 'skills', 'jira-criteria.skill');
18
28
  /** The skill's body: the prompt the session starts with. */
19
- function promptOf() {
29
+ function promptOf(file = SKILL) {
20
30
  let t = '';
21
- try { t = fs.readFileSync(SKILL, 'utf8'); } catch { return null; }
31
+ try { t = fs.readFileSync(file, 'utf8'); } catch { return null; }
22
32
  const m = /^---\n[\s\S]*?\n---\n([\s\S]*)$/.exec(t);
23
33
  return (m ? m[1] : t).trim() || null;
24
34
  }
25
35
  const running = new Map(); // ws id → session id
36
+ const runningCriteria = new Map(); // ws id → the jira-criteria session id
37
+
38
+ /** The acceptance-criteria routes (jira-criteria-write). */
39
+ async function handleCriteria(req, res, url, ctx) {
40
+ const p = url.pathname;
41
+ if (p === '/api/jira-criteria' && req.method === 'GET') {
42
+ const w = ctx.getWs(url.searchParams.get('ws'));
43
+ if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
44
+ const ini = url.searchParams.get('ini') || '';
45
+ const F = JC.readCriteriaAsks(w.root);
46
+ const base = { ok: true, asks: JC.pendingCriteriaAsks(F).filter((a) => !ini || a.ini === ini), draft: JC.criteriaDraftText(F) };
47
+ if (!ini) { ctx.json(res, { ...base, proposals: [] }); return true; }
48
+ const r = JC.propose(w.root, ini, { me: pmNameOf() });
49
+ if (!r.ok) { ctx.json(res, r, r.status || 400); return true; }
50
+ ctx.json(res, { ...base, doneTest: r.doneTest, checks: r.checks, unmatched: r.unmatched,
51
+ proposals: r.proposals.map((x) => ({ key: x.key, summary: x.summary, who: x.who, direct: x.direct, labels: x.labels, block: x.block })) });
52
+ return true;
53
+ }
54
+ if (req.method !== 'POST' || (p !== '/api/jira-criteria/ask' && p !== '/api/jira-criteria/undo')) return false;
55
+ const got = await ctx.readJson(req);
56
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
57
+ const body = got.body || {};
58
+ const g = guard.requirePagePress(req, body);
59
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
60
+ const w = ctx.getWs(typeof body.ws === 'string' && body.ws ? body.ws : null);
61
+ if (!w || (body.ws && w.id !== body.ws)) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
62
+ const by = (g.actor && g.actor.by) || 'pm';
63
+ if (p === '/api/jira-criteria/undo') { ctx.json(res, JC.withdrawCriteriaAsks(w.root, Array.isArray(body.ids) ? body.ids : [], by)); return true; }
64
+ // keys only: the blocks are computed here from the done test, never taken from the page
65
+ const r = JC.askCriteria(w.root, { ini: body.ini, keys: Array.isArray(body.keys) ? body.keys : null, me: pmNameOf() }, by);
66
+ if (!r.ok) { ctx.json(res, r, r.status || 400); return true; }
67
+ const out = { ok: true, direct: r.direct.map((a) => a.key), draft: r.draft.map((a) => ({ key: a.key, who: a.who })), ids: r.ids, skipped: r.skipped };
68
+ if (r.direct.length && typeof ctx.spawnSession === 'function') {
69
+ const prompt = promptOf(CRITERIA_SKILL), was = runningCriteria.get(w.id), live = was && typeof ctx.sessionList === 'function' && (ctx.sessionList() || []).some((s) => s && s.id === was && s.state !== 'exited');
70
+ const fail = (why) => { for (const a of r.direct) JC.answerCriteriaAsk(w.root, a.id, { why }, 'pmos'); };
71
+ if (prompt && !live) {
72
+ try {
73
+ const s = ctx.spawnSession({ name: 'Write criteria in Jira', agent: 'claude', ws: w.id, origin: 'jira:criteria', initialInput: prompt + `\n\nThis run: the asks \`pmos jira criteria-asks --direct\` lists (the first: ${r.direct[0].key}).\r` });
74
+ if (s && s.state !== 'exited') { runningCriteria.set(w.id, s.id); out.session = s.id; }
75
+ else fail((s && s.note) || 'the agent could not start');
76
+ } catch { fail('the agent could not start'); }
77
+ } else if (live) out.session = was;
78
+ else if (!prompt) fail('the jira-criteria skill is not installed');
79
+ }
80
+ ctx.json(res, out);
81
+ return true;
82
+ }
26
83
 
27
84
  module.exports = {
28
- prefixes: ['/api/jira-epics'],
85
+ prefixes: ['/api/jira-epics', '/api/jira-criteria'],
29
86
  handle: async (req, res, url, ctx) => {
30
87
  const p = url.pathname;
88
+ if (p === '/api/jira-criteria' || p.startsWith('/api/jira-criteria/')) return handleCriteria(req, res, url, ctx);
31
89
  if (p === '/api/jira-epics' && req.method === 'GET') {
32
90
  const w = ctx.getWs(url.searchParams.get('ws'));
33
91
  if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+ /* routes-open-questions.js — one register of every unanswered question across initiatives (initiative open-questions-register, bet A420;
3
+ * lib/open-questions.js).
4
+ *
5
+ * GET /api/open-questions?ws=<id> → { ok, ws, today, lines: [lib/open-questions.js line], median_age }
6
+ *
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. */
9
+ const OQ = require('./open-questions.js');
10
+
11
+ module.exports = {
12
+ prefixes: ['/api/open-questions'],
13
+ handle: async (req, res, url, ctx) => {
14
+ if (url.pathname !== '/api/open-questions') return false;
15
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
16
+ let w = null;
17
+ try { w = ctx.getWs(url.searchParams.get('ws') || null); } catch { w = null; }
18
+ if (!w || !w.root) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
19
+ const now = Date.now(), today = OQ.localDay(now);
20
+ let questions = null;
21
+ try { questions = require('./routes-your-move.js').questions(ctx, w, today, { take: false }).questions; } catch { questions = null; }
22
+ try {
23
+ const r = OQ.read(w.root, { now, questions });
24
+ console.log(`${OQ.TAG} ws=${w.id} lines=${r.lines.length} median_age=${r.median_age}`);
25
+ ctx.json(res, { ok: true, ws: w.id, ...r });
26
+ } catch (e) { ctx.json(res, { ok: false, error: String((e && e.message) || e) }, 500); }
27
+ return true;
28
+ },
29
+ };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.727.0",
3
+ "version": "0.729.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.727.0",
9
+ "version": "0.729.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.727.0",
3
+ "version": "0.729.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",
@@ -0,0 +1,15 @@
1
+ /* change-cues.css — the short cue on a row that is done, moved or dropped (pm/change-cues.js, idea A313). Komorebi tokens only. */
2
+ .pm-cue-done, .pm-cue-moved, .pm-cue-gone { pointer-events: none; }
3
+ .pm-cue-done { animation: pmCueDone var(--duration-leaf) var(--ease-out) both; }
4
+ .pm-cue-moved { animation: pmCueMoved var(--duration-leaf) var(--ease-out) both; }
5
+ .pm-cue-gone { animation: pmCueGone var(--duration-leaf) var(--ease-out) both; }
6
+ @keyframes pmCueDone { 0% { background: transparent; } 35% { background: var(--leaf-tint); transform: none; opacity: 1; } 100% { background: var(--leaf-tint); transform: translateX(var(--space-24)); opacity: 0; } }
7
+ @keyframes pmCueMoved { 0% { background: transparent; } 30% { background: var(--blue-tint); transform: none; opacity: 1; } 100% { background: var(--blue-tint); transform: translateX(var(--space-24)); opacity: 0; } }
8
+ @keyframes pmCueGone { from { opacity: 1; } to { opacity: 0; } }
9
+ /* reduced motion: still. The row is tinted for the same time and nothing moves or fades. */
10
+ @media (prefers-reduced-motion: reduce) {
11
+ .pm-cue-done, .pm-cue-moved, .pm-cue-gone { animation: none; transform: none; }
12
+ .pm-cue-done { background: var(--leaf-tint); }
13
+ .pm-cue-moved { background: var(--blue-tint); }
14
+ .pm-cue-gone { background: var(--well); }
15
+ }
@@ -0,0 +1,52 @@
1
+ /* pm/change-cues.js — a short cue when an item moves or is done (idea A313, initiative change-cues, job #1616).
2
+ *
3
+ * When the user marks a row done, moves it to another day or drops it, the page saves the change and draws the list again. Without a cue
4
+ * the row just vanishes. This plays about half a second on the row first, so the eye sees which row went and how:
5
+ * done the row tints green and slides out (class pm-cue-done)
6
+ * moved the row slides out to the side (class pm-cue-moved)
7
+ * gone the row fades (class pm-cue-gone)
8
+ * The timing is the Komorebi motion tokens (--duration-leaf, --ease-out) in change-cues.css. With reduced motion asked for, the cue is
9
+ * still: the row is tinted for the same time and nothing moves (the CSS sets the still form; the script only waits less).
10
+ *
11
+ * kindOf(act) PURE: a page's action word → 'done' | 'moved' | 'gone' | ''
12
+ * classOf(kind) PURE: the class a kind adds, or ''
13
+ * reducedMotion(win) true when the window asks for reduced motion
14
+ * cue(el, kind, opt) adds the class and resolves when the cue ends (animationend, or a bounded wait); notes cue-<kind> in the local
15
+ * use log and writes one [change-cues] console line (the health log). A missing element or unknown kind resolves at once.
16
+ *
17
+ * Callers play the cue after the change is saved and before the list draws again; a failed save plays none. */
18
+ import { noteUse } from './use-log.js';
19
+
20
+ const KINDS = { done: 'done', tomorrow: 'moved', later: 'moved', move: 'moved', moved: 'moved', drop: 'gone', remove: 'gone', gone: 'gone' };
21
+ export const CUE_MS = 600; // the length of --duration-leaf; the wait if no animation event comes
22
+ export const STILL_MS = 450; // reduced motion: how long the still tint holds before the list draws again
23
+ const MARGIN_MS = 150;
24
+
25
+ export const kindOf = (act) => (Object.prototype.hasOwnProperty.call(KINDS, String(act || '')) ? KINDS[act] : '');
26
+ export const classOf = (kind) => (kind === 'done' || kind === 'moved' || kind === 'gone' ? 'pm-cue-' + kind : '');
27
+
28
+ export function reducedMotion(win) {
29
+ try { const w = win || (typeof window !== 'undefined' ? window : null); return !!(w && w.matchMedia && w.matchMedia('(prefers-reduced-motion: reduce)').matches); }
30
+ catch { return false; }
31
+ }
32
+
33
+ /** Play the cue on one element. opt: { win, note(control), log(line) } (tests pass fakes; the page uses window, noteUse, console.log). */
34
+ export function cue(el, kind, opt = {}) {
35
+ const cls = classOf(kind);
36
+ if (!el || !el.classList || !cls) return Promise.resolve(false);
37
+ const still = reducedMotion(opt.win);
38
+ const note = opt.note || noteUse;
39
+ const log = opt.log || ((s) => { try { console.log(s); } catch { /* no console */ } });
40
+ try { note('cue-' + kind); } catch { /* the use log is best effort */ }
41
+ log('[change-cues] ' + kind + (still ? ' still' : ''));
42
+ el.classList.add(cls);
43
+ return new Promise((resolve) => {
44
+ let over = false;
45
+ const end = () => { if (over) return; over = true; if (el.removeEventListener) el.removeEventListener('animationend', end); clearTimeout(t); resolve(true); };
46
+ const t = setTimeout(end, still ? STILL_MS : CUE_MS + MARGIN_MS);
47
+ if (!still && el.addEventListener) el.addEventListener('animationend', end);
48
+ });
49
+ }
50
+
51
+ /** The row an action button sits in: the closest list row, or the element itself. */
52
+ export const rowOf = (b) => (b && b.closest ? b.closest('.pm-li, [role="listitem"], li') || null : null);
@@ -92,7 +92,31 @@ function readItems(id, ws, redraw) {
92
92
  .then((x) => { ITEMS.set(id, x && x.ok && Array.isArray(x.items) ? x.items : false); if (x && x.ok && (x.items || []).length) redraw(); })
93
93
  .catch(() => ITEMS.set(id, false));
94
94
  }
95
- export const resetItems = () => ITEMS.clear();
95
+ export const resetItems = () => { ITEMS.clear(); CRIT.clear(); };
96
+ /* the done test's acceptance criteria for the initiative's Jira tickets (initiative jira-criteria-write, A384): GET /api/jira-criteria once
97
+ * per initiative; the ✦ shows when PMOS proposes at least one ticket (zero is silence) */
98
+ const CRIT = new Map(); // initiative id → { proposals, unmatched } | null while reading | false when there is nothing or no route
99
+ function readCrit(id, ws, redraw) {
100
+ if (!id || RO || CRIT.has(id)) return;
101
+ CRIT.set(id, null);
102
+ pmGet('/api/jira-criteria?ini=' + encodeURIComponent(id) + (ws ? '&ws=' + encodeURIComponent(ws) : ''))
103
+ .then((x) => { const ok = x && x.ok && Array.isArray(x.proposals) && x.proposals.length; CRIT.set(id, ok ? { proposals: x.proposals, unmatched: x.unmatched || [] } : false); if (ok) redraw(); })
104
+ .catch(() => CRIT.set(id, false));
105
+ }
106
+ /** The ✦ of the done test's criteria, above the list: each ticket, whose it is, and the checks it gets. */
107
+ function critSugHtml(cr) {
108
+ if (!cr || !cr.proposals || !cr.proposals.length) return '';
109
+ const L = cr.proposals, n = L.length, mine = L.filter((p) => p.direct).length;
110
+ const say = `Add the done test's checks to ${n === 1 ? L[0].key : n + ' Jira tickets'}`;
111
+ const row = (p) => `<li><b>${esc(p.key)}</b> ${esc(p.summary || '')} <span class="hi-small">${esc((p.direct ? 'yours, written in Jira' : 'draft for ' + (p.who || 'its owner')) + ' · check' + (p.labels.length === 1 ? ' ' : 's ') + p.labels.join(', '))}</span></li>`;
112
+ const will = [mine ? `Write them at the end of the description of ${mine === 1 ? 'your ticket' : 'your ' + mine + ' tickets'} in Jira, and change nothing else` : '',
113
+ n - mine ? `Put the other ${n - mine === 1 ? 'ticket' : n - mine + ' tickets'} in today's draft for ${n - mine === 1 ? 'its owner' : 'their owners'}, for you to send` : ''].filter(Boolean);
114
+ return `<div class="pm-sug x" role="group" aria-label="PMOS suggests"><div class="ttl">${SVG(P.spark || P.dia, 14)}<b class="say">${esc(say)}</b></div>`
115
+ + `<dl><dt>Why</dt><dd>${esc('The people who build these tickets do not see the done test. Each check goes on the ticket it fits, as Given / When / Then.')}</dd>`
116
+ + `<dt>PMOS will</dt><dd><ul>${will.map((w) => `<li>${esc(w)}</li>`).join('')}</ul></dd><dt>Tickets</dt><dd><ul>${L.map(row).join('')}</ul></dd></dl>`
117
+ + `<div class="ans"><button type="button" class="pm-btn primary" data-pw-crit-ok aria-label="Yes, do it" title="Yes, do it">${SVG(P.check, 14)}</button>`
118
+ + `<button type="button" class="pm-btn outline" data-pw-crit-drop aria-label="No" title="No">${SVG(P.x, 14)}</button></div></div>`;
119
+ }
96
120
  /* the goal's name, not its id (board 25: "De-risk Okta dependency", not KR-C4): GET /api/boards/anchors once per product */
97
121
  const GOALS = new Map(); // ws|board → [{ value, kind, label }] | null while reading | false
98
122
  let goalsRedraw = null;
@@ -350,7 +374,9 @@ function dsHtml(r, v, o, W, S, C, mode) {
350
374
  ? breakdownHtml(W, C, mode, false, S).replace('<h3>Work breakdown</h3>', head('gantt') + (S.sel.size ? SEL.barHtml(S.sel.size, { epic: epicSel }) : '')).replace('class="pw-sec"', 'class="pw-sec pm-block pwd-blk pwd-wbs"')
351
375
  : `<section class="pm-block pwd-blk pwd-wbs" aria-label="Work breakdown">${S.sel.size ? '' : head('list')}${PD.listHtml(stF, W, { looseN: W.looseN, epics, fix, ask, sel: S.sel, nested: st.some((x) => x.kids), drag: canDrag(), group, epicSel })}</section>`;
352
376
  const mg = mergeOf(W.artefacts), merge = mg ? `<div class="pw-sugs pw-amg" role="list" aria-label="PMOS suggests">${sugLine({ id: mg.id, say: mg.say, merge: mg })}</div>` : '';
353
- return `<div class="pw pwd">${'<div class="pwd-main">'}${PD.standsHtml(W, r)}${PD.stagesHtml(st, W)}${wbs}</div>`
377
+ // the done test's acceptance criteria on the initiative's Jira tickets (jira-criteria-write): its ✦ above the breakdown, unless the PM said no
378
+ const crit = S.sel.size || dropped().has('crit:' + id) ? '' : critSugHtml(CRIT.get(id));
379
+ return `<div class="pw pwd">${'<div class="pwd-main">'}${PD.standsHtml(W, r)}${PD.stagesHtml(st, W)}${crit}${wbs}</div>`
354
380
  + `<aside class="pwd-side">${PD.caseHtml(W, { oid: id, dropped: dropped() })}${PD.artsHtml(W.artefacts, { merge })}</aside></div>`;
355
381
  }
356
382
 
@@ -580,7 +606,7 @@ export function wire(body, h0, x0) {
580
606
  // the Viewer reuses its body for the next item: the presses read the item shown now from the body, so one set of listeners serves all
581
607
  body.__pwh = ED.writes(h0); body.__pwx = x0;
582
608
  { const o = x0 && x0.o ? x0.o() || {} : {}; ASK_AT = o.id ? { id: String(o.id), ws: o.ws || '' } : null; }
583
- { const c = cur(); if (c) { readItems(c.id, (x0.o() || {}).ws, () => redraw()); if (c.S.top) body.scrollTop = c.S.top; }
609
+ { const c = cur(); if (c) { readItems(c.id, (x0.o() || {}).ws, () => redraw()); readCrit(c.id, (x0.o() || {}).ws, () => redraw()); if (c.S.top) body.scrollTop = c.S.top; }
584
610
  const q = OPEN_ON_DRAW;
585
611
  if (c && q && q.id === String(c.id) && Date.now() - q.at < 15000) { OPEN_ON_DRAW = null; setTimeout(() => { const c2 = cur(); if (c2) openSmall(q.uid, c2, body.__pwh, body.__pwx, body); }, 0); } }
586
612
  if (body.__pw) return;
@@ -653,6 +679,8 @@ export function wire(body, h0, x0) {
653
679
  if ('pwTickNo' in d) { const u = S.tickAsk; S.tickAsk = ''; redraw(); if (u && h.status) await h.status(u, 'Done'); return; }
654
680
  if (d.pwSub) { const u = d.pwSub, open = b.getAttribute('aria-expanded') === 'true'; S.subOpen.delete(u); S.subShut.delete(u); (open ? S.subShut : S.subOpen).add(u); redraw(); return; }
655
681
  if ('pwEpicFix' in d) { b.disabled = true; await epicFix(c, h, x); return; }
682
+ if ('pwCritOk' in d) { b.disabled = true; await critFix(c, h, x); return; }
683
+ if ('pwCritDrop' in d) { const dd = dropped(); dd.add('crit:' + c.id); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
656
684
  if ('pwEpicDrop' in d) { const dd = dropped(); dd.add('epic:' + c.id); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
657
685
  if (d.wsOp) { await bulkPress(b, d.wsOp, c, h, x); return; }
658
686
  // the follow-ups (work-subtasks-followups): the Source filter, the ✦ grouping (✓ makes the parents, ✕ hides it)
@@ -1132,6 +1160,21 @@ async function epicFix(c, h, x) {
1132
1160
  say(words, async () => { const u = await pmPost('/api/jira-epics/undo', { ws: at.ws, ids: r.ids }).catch(() => null); dd.delete('epic:' + c.id); store.set(DROP, [...dd].slice(-200)); say(u && u.kept && u.kept.length ? 'Put back, except ' + u.kept.join(', ') + ': Jira already has it.' : 'Put back.'); if (h.redraw) h.redraw(); });
1133
1161
  if (h.redraw) h.redraw();
1134
1162
  }
1163
+ /** The done test's criteria ✦ (jira-criteria-write): the tickets it lists get them. The page sends the keys only; the server writes the
1164
+ * block from the done test. Tickets assigned to the PM are written in Jira by a session with the PM's own connection; the rest go to the
1165
+ * day's draft for their owners. Undo withdraws what Jira has not done yet (POST /api/jira-criteria/undo). */
1166
+ async function critFix(c, h, x) {
1167
+ const at = atOf(h, x), cr = CRIT.get(c.id);
1168
+ if (!cr || !cr.proposals.length) return;
1169
+ const r = await pmPost('/api/jira-criteria/ask', { ws: at.ws, ini: at.ini || c.id, keys: cr.proposals.map((p) => p.key) }).catch(() => null);
1170
+ const say = (m, u) => (u ? undoToast(m, u) : h.toast ? h.toast(m) : undoToast(m));
1171
+ if (!r || r.ok === false) { say((r && r.error) || 'The criteria were not asked.'); if (h.redraw) h.redraw(); return; }
1172
+ CRIT.set(c.id, false);
1173
+ const words = [r.direct.length ? (r.direct.length === 1 ? r.direct[0] + ' gets' : r.direct.length + ' tickets get') + ' the criteria in Jira now.' : '',
1174
+ r.draft.length ? (r.draft.length === 1 ? r.draft[0].key + ' is' : r.draft.length + ' tickets are') + ' in today\'s Jira draft for ' + [...new Set(r.draft.map((q) => q.who || 'their owner'))].join(', ') + '.' : ''].filter(Boolean).join(' ');
1175
+ say(words, async () => { const u = await pmPost('/api/jira-criteria/undo', { ws: at.ws, ids: r.ids }).catch(() => null); CRIT.delete(c.id); say(u && u.kept && u.kept.length ? 'Taken back, except ' + u.kept.join(', ') + ': Jira already has it.' : 'Taken back.'); if (h.redraw) h.redraw(); });
1176
+ if (h.redraw) h.redraw();
1177
+ }
1135
1178
  /* Who (WorkStatesDS 1): You, the people who own this initiative's tasks, and "PMOS does it". A name writes the owner (Undo puts the old one
1136
1179
  * back, POST /api/boards/tasks/edit with `from`); PMOS does it gives the task to PMOS (POST /api/backlog/give; Undo is /api/backlog/stop). */
1137
1180
  function whoMenu(btn, uid, c, h, x) {