create-pmos 0.779.0 → 0.781.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 (33) hide show
  1. package/package.json +36 -44
  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 +35 -0
  7. package/workspace/guide/agent-capabilities.md +2 -1
  8. package/workspace/guide/claude-proposes.md +11 -1
  9. package/workspace/guide/cli.md +2 -2
  10. package/workspace/guide/initiatives-and-next-steps.md +1 -1
  11. package/workspace/guide/positioning.md +4 -2
  12. package/workspace/lib/card-catalog.js +67 -0
  13. package/workspace/lib/card-catalog.json +2032 -0
  14. package/workspace/lib/routes-card-catalog.js +19 -0
  15. package/workspace/lib/routes-slash.js +7 -1
  16. package/workspace/lib/routes-star-drafts.js +36 -0
  17. package/workspace/lib/star-draft.js +99 -0
  18. package/workspace/lib/strategy-card.js +6 -3
  19. package/workspace/lib/strategy-cli.js +7 -3
  20. package/workspace/lib/strategy-sources.js +46 -10
  21. package/workspace/package-lock.json +2 -2
  22. package/workspace/package.json +1 -1
  23. package/workspace/public/pm/action-run.js +120 -0
  24. package/workspace/public/pm/bd-pop-ds.js +2 -2
  25. package/workspace/public/pm/bd-positioning.js +19 -7
  26. package/workspace/public/pm/bd-strategy.js +9 -2
  27. package/workspace/public/pm/card-run.js +25 -0
  28. package/workspace/public/pm/cozy-pop-work.js +91 -10
  29. package/workspace/public/pm/goals-open.js +14 -2
  30. package/workspace/public/pm/star-draft.js +63 -0
  31. package/workspace/public/pm/state-blocks.js +18 -1
  32. package/workspace/skills/strategy-draft.skill +6 -3
  33. package/workspace/test-lists/star-buttons-act-directly.json +13 -0
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+ /* routes-card-catalog.js — the card catalog for the page (star-buttons-act-directly).
3
+ *
4
+ * GET /api/card-catalog → { ok, catalog } the committed v2 catalog (lib/card-catalog.json), read only
5
+ *
6
+ * The page runs a button with public/pm/action-run.js; the catalog only says which command a button runs and who acts. */
7
+ const CC = require('./card-catalog.js');
8
+
9
+ module.exports = {
10
+ prefixes: ['/api/card-catalog'],
11
+ handle: async (req, res, url, ctx) => {
12
+ if (url.pathname !== '/api/card-catalog') return false;
13
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
14
+ let catalog = null;
15
+ try { catalog = CC.load(); } catch (e) { ctx.json(res, { ok: false, error: 'The card catalog could not be read: ' + e.message }, 500); return true; }
16
+ ctx.json(res, { ok: true, catalog });
17
+ return true;
18
+ },
19
+ };
@@ -80,10 +80,16 @@ function list(deps = {}) {
80
80
  return { status: 200, body: { ok: true, commands: out } };
81
81
  }
82
82
 
83
+ // The commands a card's buttons run live beside the chat's commands (star-buttons-act-directly): GET /api/card-catalog
84
+ // (lib/routes-card-catalog.js) and the ✦ drafts' background job, POST/GET /api/star-drafts (lib/routes-star-drafts.js). They ride on this
85
+ // module's entry, so route-modules.js keeps its list.
86
+ const BESIDE = [require('./routes-card-catalog.js'), require('./routes-star-drafts.js')];
87
+
83
88
  module.exports = {
84
- prefixes: ['/api/slash-commands'],
89
+ prefixes: ['/api/slash-commands', '/api/card-catalog', '/api/star-drafts'],
85
90
  list, sayOf, CLAUDE,
86
91
  handle: async (req, res, url, ctx) => {
92
+ for (const m of BESIDE) if (m.prefixes.includes(url.pathname)) return m.handle(req, res, url, ctx);
87
93
  if (url.pathname !== '/api/slash-commands') return false;
88
94
  if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
89
95
  const ws = url.searchParams.get('ws');
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+ /* routes-star-drafts.js — a ✦ "Draft …" answer as a PMOS background job (star-buttons-act-directly, done test A7; lib/star-draft.js).
3
+ *
4
+ * POST /api/star-drafts { ws, ask, again? } → { ok, state: 'pending' | 'ready' | 'failed', key, text?, why? } starts the job, or
5
+ * answers the kept draft at once
6
+ * GET /api/star-drafts?key= → { ok, state: 'pending' | 'ready' | 'failed' | 'none', key, text?, why? } the page reads it until it lands
7
+ *
8
+ * The POST is a page press (pm-guard requirePagePress). The job reads and drafts only: nothing is written until the PM's ✓ on the row,
9
+ * which saves through the row's own route with Undo. */
10
+ const guard = require('./pm-guard.js');
11
+ const SD = require('./star-draft.js');
12
+
13
+ module.exports = {
14
+ prefixes: ['/api/star-drafts'],
15
+ handle: async (req, res, url, ctx) => {
16
+ if (url.pathname !== '/api/star-drafts') return false;
17
+ const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
18
+ if (req.method === 'GET') {
19
+ const key = String(url.searchParams.get('key') || '');
20
+ if (!/^[0-9a-f]{16}$/.test(key)) return bad('key must name a draft');
21
+ ctx.json(res, { ok: true, ...SD.peek(ctx, key) });
22
+ return true;
23
+ }
24
+ if (req.method !== 'POST') return bad('GET or POST only', 405);
25
+ const got = await ctx.readJson(req);
26
+ if (!got.ok) return bad('invalid JSON body');
27
+ const b = got.body || {};
28
+ const g = guard.requirePagePress(req, b);
29
+ if (!g.ok) return bad(g.error, g.status);
30
+ const ask = String(b.ask || '').trim();
31
+ if (!ask) return bad('ask must hold the words of the draft');
32
+ const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
33
+ ctx.json(res, { ok: true, ...SD.start(ctx, { ws: w ? w.id : (b.ws || null), ask, again: !!b.again }) });
34
+ return true;
35
+ },
36
+ };
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+ /* star-draft.js — a ✦ "Draft …" answer runs as a PMOS background job, and its result lands on the row it came from (initiative
3
+ * star-buttons-act-directly, done test A7; Wawan chose "Yes, run drafts in background" on 2026-11-24).
4
+ *
5
+ * Before, a ✦ that offered a draft (the Overview's Problem, Goal and Done when, a program's For and Goal, the missing gate documents, a
6
+ * goal or initiatives from the strategy, an outcome verdict, a name) wrote its words into the chat and the PM had to send them. Now the
7
+ * press starts one short read-only PMOS session and the row shows "PMOS is drafting…", then the draft. Nothing is kept until the PM's ✓.
8
+ *
9
+ * keyOf(ws, ask) → the job's key: one job per workspace and words PURE
10
+ * askOf(ask) → the words the session gets: the ✦ words without their save step ("When I say yes, save it with …"),
11
+ * and the answer rules: the draft only, plain text, no preamble PURE
12
+ * clean(text) → the draft as the row shows it, or '' when there is none PURE
13
+ * start(ctx, { ws, ask, again }) → { state: 'pending' | 'ready' | 'failed', key, text?, why? }
14
+ * peek(ctx, key) → the same, or { state: 'none', key }
15
+ *
16
+ * THE RUN. One session of the existing read-only `ask` kind (lib/headless.js, origin briefing-ask:star-draft:<key>), in the workspace's
17
+ * folder, with Read, Glob and Grep only: it reads the records and writes nothing and sends nothing. The answer is kept in
18
+ * <runtime>/star-drafts.json by key (the newest 60), so a second press reads it at once. No session or an empty answer: state failed with
19
+ * the reason, and the row offers Try again (honest state). Tests inject ctx.askClaude(prompt, { job, key }) → Promise<string|null>. */
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+ const crypto = require('crypto');
23
+
24
+ const MODEL = 'claude-sonnet-5-5';
25
+ const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read,Glob,Grep' }]);
26
+ const TIMEOUT_MS = 180000, KEEP = 60, MAX_ASK = 4000, MAX_TEXT = 6000;
27
+
28
+ const keyOf = (ws, ask) => crypto.createHash('sha1').update(String(ws || '') + '\n' + String(ask || '')).digest('hex').slice(0, 16);
29
+
30
+ /** The ✦ words without the step that saves (the row saves on ✓), and the rules of the answer. */
31
+ function askOf(ask) {
32
+ const words = String(ask || '').replace(/\s*When I say yes,[\s\S]*$/, '').replace(/\s*Show it to me before you keep it\.?/g, '').trim().slice(0, MAX_ASK);
33
+ return words + '\n\nRead the records in this folder that you need. Change nothing, write nothing, send nothing.'
34
+ + '\nAnswer with the draft only, as plain text: no preamble, no heading, no closing line. If the records hold nothing to draft it from, answer exactly: NOTHING';
35
+ }
36
+
37
+ function clean(text) {
38
+ const t = String(text == null ? '' : text).replace(/\r\n?/g, '\n').replace(/^\s*```[a-z]*\n?|\n?```\s*$/g, '').trim();
39
+ if (!t || /^NOTHING\.?$/i.test(t)) return '';
40
+ return t.length > MAX_TEXT ? t.slice(0, MAX_TEXT - 1).replace(/\s+\S*$/, '') + '…' : t;
41
+ }
42
+
43
+ /* ── the kept answers, in the runtime folder ── */
44
+ const fileOf = (ctx) => path.join((ctx && ctx.runtimeDir) || require('os').tmpdir(), 'star-drafts.json');
45
+ function readAll(ctx) { try { const o = JSON.parse(fs.readFileSync(fileOf(ctx), 'utf8')); return o && typeof o === 'object' ? o : {}; } catch { return {}; } }
46
+ function keepOne(ctx, key, value) {
47
+ const all = readAll(ctx); all[key] = { at: new Date().toISOString(), ...value };
48
+ const keys = Object.keys(all).sort((a, b) => String(all[b].at).localeCompare(String(all[a].at)));
49
+ for (const k of keys.slice(KEEP)) delete all[k];
50
+ fs.mkdirSync(path.dirname(fileOf(ctx)), { recursive: true });
51
+ fs.writeFileSync(fileOf(ctx), JSON.stringify(all));
52
+ }
53
+ const running = new Map(); // key → started at (ms)
54
+ const say = (s) => { try { console.log('[star-draft] ' + s); } catch { /* no console */ } }; // the health log: landed / failed
55
+
56
+ function viaSession(ctx, ws, prompt, key) {
57
+ if (ctx && typeof ctx.askClaude === 'function') return Promise.resolve(ctx.askClaude(prompt, { job: 'star-draft', key, ws })).catch(() => null);
58
+ const headless = require('./headless.js');
59
+ const origin = 'briefing-ask:star-draft:' + key;
60
+ if (!ctx || typeof ctx.spawnSession !== 'function' || headless.kindFor({ agent: 'claude', origin }) !== 'ask') return Promise.resolve(null);
61
+ return new Promise((resolve) => {
62
+ let settled = false; const done = (v) => { if (settled) return; settled = true; clearTimeout(tm); resolve(v); };
63
+ const tm = setTimeout(() => done(null), TIMEOUT_MS);
64
+ let s = null;
65
+ try {
66
+ s = ctx.spawnSession({ name: 'Draft: ' + prompt.split('\n')[0].slice(0, 60), agent: 'claude', ws: ws || null, origin, initialInput: prompt,
67
+ modelAsk: { explicit: { model: MODEL, effort: 'low' } }, launchFlags: LEAN.map((f) => ({ ...f })),
68
+ onDone: (d) => { const r = d && d.result; done(r && r.ok && !r.isError ? String(r.text || '') : null); } });
69
+ } catch { s = null; }
70
+ if (!s || s.state === 'exited') done(null);
71
+ });
72
+ }
73
+
74
+ function peek(ctx, key) {
75
+ const have = readAll(ctx)[key];
76
+ if (running.has(key)) return { state: 'pending', key };
77
+ if (!have) return { state: 'none', key };
78
+ return have.text ? { state: 'ready', key, text: have.text, at: have.at } : { state: 'failed', key, why: have.why || 'PMOS could not draft it.' };
79
+ }
80
+
81
+ function start(ctx, { ws, ask, again = false, wait = false } = {}) {
82
+ const words = String(ask || '').trim();
83
+ if (!words) return { state: 'failed', key: '', why: 'There is nothing to draft.' };
84
+ const key = keyOf(ws, words);
85
+ if (running.has(key)) return { state: 'pending', key };
86
+ const have = readAll(ctx)[key];
87
+ if (have && have.text && !again) return { state: 'ready', key, text: have.text, at: have.at };
88
+ running.set(key, Date.now());
89
+ const p = Promise.resolve(viaSession(ctx, ws, askOf(words), key)).then((text) => {
90
+ const t = clean(text);
91
+ const value = t ? { text: t } : { text: '', why: text == null ? 'PMOS could not start a session.' : 'The records hold nothing to draft it from.' };
92
+ try { keepOne(ctx, key, value); } catch { /* the next press tries again */ }
93
+ say(t ? 'landed ' + t.length + ' characters' : 'failed: ' + value.why);
94
+ }).catch(() => {}).finally(() => running.delete(key));
95
+ if (wait) return p.then(() => peek(ctx, key));
96
+ return { state: 'pending', key };
97
+ }
98
+
99
+ module.exports = { keyOf, askOf, clean, start, peek, MODEL };
@@ -8,8 +8,9 @@
8
8
  * fit(card, row) → null (fits, or nothing to say) | { kind: 'wont' | 'none', why }
9
9
  * notes(card, rows) → [{ id, title, stage, kind, why }] at most MAX_NOTES
10
10
  * count(dirs) → how many of the folders hold a complete card
11
- * draft(dir, fields, sources, now?) → { ok, card, wrote } | { ok: false, error } PMOS's draft (initiative strategy-draft): only blank lines,
12
- * each citing 1 to MAX_SOURCES refs that lib/strategy-sources.js accepts; appends { at, by: 'pmos', fields, sources }
11
+ * draft(dir, fields, sources, { check, wide }) → { ok, card, wrote } | { ok: false, error } PMOS's draft (initiative strategy-draft): only
12
+ * blank lines, each citing 1 to MAX_SOURCES refs that check() accepts and wide() finds broad enough for the whole
13
+ * product (lib/strategy-sources.js checkRef, breadth); appends { at, by: 'pmos', fields, sources }
13
14
  * undo(dir, key?, now?) → { ok, card, blanked } | { ok: false, error } blanks the lines that still hold PMOS's draft (or one), { ev: 'undo' }
14
15
  * drafted(dirs) → how many lines PMOS drafted still stand (the health number of strategy-draft)
15
16
  *
@@ -111,7 +112,7 @@ function save(dir, fields, now = Date.now()) {
111
112
  }
112
113
 
113
114
  /** PMOS's draft: only the lines that are blank now, each with the refs it came from. `check(ref)` → true when the ref is a source of the product. */
114
- function draft(dir, fields, sources, { now = Date.now(), check = null } = {}) {
115
+ function draft(dir, fields, sources, { now = Date.now(), check = null, wide = null } = {}) {
115
116
  if (!fileOf(dir)) return { ok: false, error: 'This product has no records folder.' };
116
117
  const c = clean(fields);
117
118
  if (!Object.keys(c).length) return { ok: false, error: 'Name a line to draft: ' + FIELDS.join(', ') + '.' };
@@ -124,6 +125,8 @@ function draft(dir, fields, sources, { now = Date.now(), check = null } = {}) {
124
125
  if (refs.length > MAX_SOURCES) return { ok: false, error: `Cite at most ${MAX_SOURCES} sources for "${LABELS[k]}".` };
125
126
  const bad = check ? refs.filter((r) => !check(r)) : [];
126
127
  if (bad.length) return { ok: false, error: 'Not a source of this product: ' + bad.join(', ') + '. `pmos strategy sources` lists the files a line may cite; a tracker key (ABC-123) is accepted too.' };
128
+ const narrow = wide ? wide(refs) : null; // lib/strategy-sources.js breadth: the line must speak for the whole product
129
+ if (narrow) return { ok: false, code: 'narrow', error: `"${LABELS[k]}": ${narrow}.` };
127
130
  out[k] = c[k]; src[k] = refs;
128
131
  }
129
132
  if (!Object.keys(out).length) return { ok: false, code: 'written', error: 'Those lines are written already (' + kept.map((k) => LABELS[k]).join(', ') + '); PMOS drafts only blank lines.' };
@@ -75,13 +75,17 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd() } =
75
75
  if (sub === 'sources') {
76
76
  const list = SS.sourcesOf(root);
77
77
  if (flags.json) { say(JSON.stringify({ ok: true, sources: list })); return 0; }
78
- if (!list.length) say('No initiative, PRD, goal or doc file found. A tracker key (ABC-123) can be cited too.');
79
- for (const s of list) say(` ${s.kind.padEnd(10)} ${s.ref} — ${s.title}`);
78
+ if (!list.length) say('No product doc, goal, initiative or PRD file found. A tracker key (ABC-123) can be cited too.');
79
+ let level = null;
80
+ for (const s of list) {
81
+ if (s.level !== level) { level = s.level; say(level === 'product' ? 'The whole product (start here):' : 'The work, as evidence (a line needs 2 or more initiatives, or a product file too):'); }
82
+ say(` ${s.kind.padEnd(12)} ${s.ref} — ${s.title}`);
83
+ }
80
84
  return 0;
81
85
  }
82
86
  if (sub === 'draft') {
83
87
  const bad = needLine(); if (bad != null) return bad;
84
- const r = SC.draft(dir, { [flags.line]: flags.text }, { [flags.line]: flags.source || [] }, { check: (ref) => SS.checkRef(root, ref) });
88
+ const r = SC.draft(dir, { [flags.line]: flags.text }, { [flags.line]: flags.source || [] }, { check: (ref) => SS.checkRef(root, ref), wide: SS.breadth });
85
89
  if (!r.ok) return fail(r.error);
86
90
  say(flags.json ? JSON.stringify({ ok: true, wrote: r.wrote }) : `✦ drafted ${SC.LABELS[flags.line]}: ${r.card[flags.line]}`);
87
91
  return 0;
@@ -2,8 +2,13 @@
2
2
  /* strategy-sources.js — the product's own files a drafted strategy line may cite (initiative strategy-draft; done test
3
3
  * planning/done-tests/strategy-draft.md C4). READ-ONLY.
4
4
  *
5
- * sourcesOf(root) → [{ ref, kind, title }] ref: the file's path relative to the product root ('/' separators)
6
- * kind ∈ initiative · prd · done-test · goal · brief · doc
5
+ * sourcesOf(root) → [{ ref, kind, level, title }] ref: the file's path relative to the product root ('/' separators)
6
+ * kind ∈ doc · goal · brief · out-of-scope · research · decisions (level 'product', listed first) ·
7
+ * initiative · prd · done-test (level 'initiative': evidence, never the strategy on its own)
8
+ * levelOf(ref) → 'product' | 'initiative' a file under initiatives/, prd/, done-tests/ or core-docs/initiative-*, or a tracker key,
9
+ * is one piece of work; any other file of the product speaks for the whole product
10
+ * breadth(refs) → null when the refs can carry a PRODUCT strategy line: 1+ product-level file, or work from 2+ different initiatives;
11
+ * else the reason (Wawan 2026-11-24: a draft from one initiative's files read as that feature's scope)
7
12
  * checkRef(root, ref) → true when `ref` is a file inside the product root (not under .git or node_modules), or a tracker key (ABC-123)
8
13
  * titleOf(root, ref) → the file's title (frontmatter `title`, else its first heading, else its name), or the key itself
9
14
  *
@@ -15,7 +20,9 @@ const path = require('path');
15
20
  const PER_KIND = 40;
16
21
  const KEY = /^[A-Z][A-Z0-9]{1,15}-\d{1,7}$/;
17
22
  const SKIP = /(^|\/)(\.git|node_modules)(\/|$)/;
18
- const DIRS = [['initiatives', 'initiative'], ['prd', 'prd'], ['done-tests', 'done-test'], ['okrs', 'goal'], ['briefs', 'brief']];
23
+ const PRODUCT_DIRS = [['okrs', 'goal'], ['briefs', 'brief'], ['out-of-scope', 'out-of-scope'], ['research', 'research']];
24
+ const WORK_DIRS = [['initiatives', 'initiative'], ['prd', 'prd'], ['done-tests', 'done-test']];
25
+ const WORK = /(^|\/)(initiatives|prd|done-tests)\/|(^|\/)core-docs\/initiative-/;
19
26
  const BASES = ['planning', 'pmos/planning', 'pmos/state'];
20
27
  const DOC_NAME = /(readme|vision|strategy|brief|product|overview|about)/i;
21
28
 
@@ -44,18 +51,47 @@ function sourcesOf(root) {
44
51
  const ref = posix(path.relative(root, f));
45
52
  if (seen.has(ref) || !inside(root, f)) return;
46
53
  seen.add(ref);
47
- out.push({ ref, kind, title: head(f) || path.basename(f, '.md') });
54
+ out.push({ ref, kind, level: levelOf(ref), title: head(f) || path.basename(f, '.md') });
48
55
  };
49
- for (const [sub, kind] of DIRS) {
50
- const files = [];
51
- for (const b of BASES) files.push(...mdIn(path.join(root, b, sub)));
52
- for (const f of newest(files).slice(0, PER_KIND)) push(f, kind);
53
- }
56
+ const dirs = (list) => {
57
+ for (const [sub, kind] of list) {
58
+ const files = [];
59
+ for (const b of BASES) files.push(...mdIn(path.join(root, b, sub)));
60
+ for (const f of newest(files).slice(0, PER_KIND)) push(f, kind);
61
+ }
62
+ };
63
+ // the whole product first: its docs, decisions, goals, briefs, out-of-scope list and research
54
64
  const docs = [...mdIn(root), ...mdIn(path.join(root, 'docs'))].filter((f) => DOC_NAME.test(path.basename(f)));
55
65
  for (const f of newest(docs).slice(0, PER_KIND)) push(f, 'doc');
66
+ for (const f of [path.join(root, 'DECISIONS.md'), path.join(root, 'pmos', 'DECISIONS.md')]) { try { if (fs.statSync(f).isFile()) push(f, 'decisions'); } catch { /* none */ } }
67
+ dirs(PRODUCT_DIRS);
68
+ // then the work, as evidence of what the product does
69
+ dirs(WORK_DIRS);
56
70
  return out;
57
71
  }
58
72
 
73
+ function levelOf(ref) {
74
+ const r = String(ref || '').trim();
75
+ return KEY.test(r) || WORK.test(r) ? 'initiative' : 'product';
76
+ }
77
+
78
+ /** The piece of work a work-level ref belongs to: the initiative id (a PRD's '-prd' cut), or the tracker key. */
79
+ function workOf(ref) {
80
+ const r = String(ref || '').trim();
81
+ if (KEY.test(r)) return 'key:' + r;
82
+ const m = /core-docs\/initiative-([^/]+)\//.exec(r);
83
+ if (m) return m[1];
84
+ return path.basename(r).replace(/\.md$/, '').replace(/-prd$/, '');
85
+ }
86
+
87
+ function breadth(refs) {
88
+ const list = (refs || []).map((r) => String(r || '').trim()).filter(Boolean);
89
+ if (list.some((r) => levelOf(r) === 'product')) return null;
90
+ const work = new Set(list.map(workOf));
91
+ if (work.size >= 2) return null;
92
+ return 'every source is one piece of work (' + [...work].join(', ') + '). A strategy line speaks for the whole product: cite a product file (README, goals, brief, out-of-scope, research, decisions) or a pattern in 2 or more initiatives';
93
+ }
94
+
59
95
  function checkRef(root, ref) {
60
96
  const r = String(ref || '').trim();
61
97
  if (KEY.test(r)) return true;
@@ -73,4 +109,4 @@ function titleOf(root, ref) {
73
109
  return head(path.resolve(String(root || ''), r)) || path.basename(r).replace(/\.md$/, '');
74
110
  }
75
111
 
76
- module.exports = { PER_KIND, sourcesOf, checkRef, titleOf };
112
+ module.exports = { PER_KIND, sourcesOf, checkRef, titleOf, levelOf, breadth };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.779.0",
3
+ "version": "0.781.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.779.0",
9
+ "version": "0.781.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.779.0",
3
+ "version": "0.781.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,120 @@
1
+ /* pm/action-run.js — one catalog button runs its pmos command through the page's own route, with Undo (initiative
2
+ * star-buttons-act-directly, done test A2–A4; the card catalog is lib/card-catalog.json, GET /api/card-catalog).
3
+ *
4
+ * runAction({ kind, action, id, args, was, ws, board, yes }, { pmPost, catalog? })
5
+ * → { ok: true, said, undo: async () => result, field, value } it ran: one POST, no chat, no session
6
+ * | { ok: false, needsYes: true, said } a "waits" button: it runs only with yes: true
7
+ * | { ok: false, ask: words } an "agent" button: PMOS does it; the words go to Ask PMOS
8
+ * | { ok: false, unknown: true, error } no route for this button: nothing was written
9
+ * | { ok: false, error } the route refused; nothing changed
10
+ * routeOf(run) → the ROUTES entry for "pmos <verb> <sub> …", or null PURE
11
+ * argsOf(run, args) → { flags, pos } the command's placeholders filled from args, by flag name, then by placeholder name PURE
12
+ *
13
+ * WHY THE PAGE ROUTES. A write is attributed from the call path (lib/actor.js): the page's routes name the PM, so a button runs the same
14
+ * route the command calls (lib/task-cli.js), never the CLI. After every run and every Undo it sends window event `pmos:action` with
15
+ * { kind, id, field, value, undo } so a card or a list can redraw (pm/live-edit.js shows the edit at once).
16
+ *
17
+ * A COMMENT has no Undo route. It is sent when its Undo window closes (UNDO_MS): Undo inside the window means it is never written. */
18
+ import { parseRun } from './card-run.js';
19
+
20
+ export const UNDO_MS = 8000;
21
+ const STATE = { 'to do': 'To do', todo: 'To do', 'in progress': 'In progress', doing: 'In progress', blocked: 'Blocked', done: 'Done', dropped: 'Dropped' };
22
+ const stateOf = (s) => STATE[String(s || '').trim().toLowerCase()] || String(s || '');
23
+ const clean = (s) => String(s == null ? '' : s).replace(/^"|"$/g, '');
24
+
25
+ /** The task family: what each "pmos task <sub>" sends, and how Undo puts it back. f: the filled flags, p: the positionals, a: the args. */
26
+ const ROUTES = {
27
+ 'task set': {
28
+ post: (f, p, a) => {
29
+ const b = { task: p[0] };
30
+ for (const k of ['due', 'start', 'owner', 'notes', 'description']) if (f[k] !== undefined) b[k] = f[k] === true ? '' : String(f[k]);
31
+ if (f.milestone !== undefined) b.milestone = f.milestone === true ? true : f.milestone !== 'false';
32
+ if (f.pin !== undefined) b.pinned = f.pin === true ? true : f.pin !== 'false';
33
+ return ['/api/boards/tasks/edit', b];
34
+ },
35
+ undo: (r, b) => (r && r.from ? ['/api/boards/tasks/edit', { task: b.task, ...r.from }] : null),
36
+ },
37
+ 'task state': {
38
+ post: (f, p) => ['/api/boards/tasks/state', { task: p[0], state: stateOf(f.to), ...(f.why && f.why !== true ? { why: String(f.why) } : {}) }],
39
+ undo: (r, b, a) => (a.was ? ['/api/boards/tasks/state', { task: b.task, state: stateOf(a.was), why: 'undo' }] : null),
40
+ },
41
+ 'task add': {
42
+ post: (f, p) => ['/api/boards/tasks/add', { initiative: p[0], title: String(p[1] || ''), ...(f.parent && f.parent !== true ? { parent: String(f.parent) } : {}) }],
43
+ undo: (r) => (r && r.item && r.item.uid ? ['/api/boards/tasks/undo-add', { task: r.item.uid }] : null),
44
+ },
45
+ 'task remove': {
46
+ post: (f, p) => ['/api/boards/tasks/delete', { task: p[0], ...(f.why && f.why !== true ? { why: String(f.why) } : {}) }],
47
+ undo: (r, b) => ['/api/boards/tasks/restore', { task: b.task }],
48
+ },
49
+ 'task comment': { post: (f, p) => ['/api/boards/tasks/comment', { task: p[0], text: String(p[1] || '') }], deferred: true },
50
+ };
51
+ const FIELD = { 'task set': (b) => ['due', 'start', 'owner', 'notes', 'description', 'milestone', 'pinned'].find((k) => k in b) || 'task',
52
+ 'task state': () => 'state', 'task add': () => 'task', 'task remove': () => 'removed', 'task comment': () => 'comment' };
53
+
54
+ export function routeOf(run) {
55
+ const c = parseRun(run);
56
+ return c ? ROUTES[c.verb + ' ' + c.sub] || null : null;
57
+ }
58
+
59
+ /** Fills "<id>", "<date>" … from args: a flag by its own name (args.due), else its placeholder's name (args.date); a positional by its
60
+ * placeholder (args.id, args.title, args.text). A flag with no value (--milestone) stays true. */
61
+ export function argsOf(run, args = {}) {
62
+ const c = parseRun(run);
63
+ if (!c) return null;
64
+ const fill = (v, name) => {
65
+ if (v === true) return true;
66
+ const ph = /^<([^>]*)>$/.exec(String(v).replace(/^"|"$/g, ''));
67
+ if (!ph) return clean(v);
68
+ const k = ph[1];
69
+ if (name && args[name] !== undefined) return args[name];
70
+ if (args[k] !== undefined) return args[k];
71
+ if (k === 'id' && args.task !== undefined) return args.task;
72
+ return undefined;
73
+ };
74
+ const flags = {};
75
+ for (const [k, v] of Object.entries(c.flags)) { const x = fill(v, k); if (x !== undefined) flags[k] = x; }
76
+ const pos = c.pos.map((v) => { const x = fill(v); return x === undefined ? undefined : x; });
77
+ return { verb: c.verb, sub: c.sub, flags, pos };
78
+ }
79
+
80
+ const actionsOf = (catalog, kind) => {
81
+ for (const g of (catalog && catalog.groups) || []) for (const k of g.kinds || []) if (k.id === kind) return k.actions || [];
82
+ return null;
83
+ };
84
+ function tell(detail) {
85
+ try { if (typeof window !== 'undefined' && window.dispatchEvent) window.dispatchEvent(new CustomEvent('pmos:action', { detail })); } catch { /* no window in Node */ }
86
+ }
87
+
88
+ export async function runAction(o = {}, { pmPost, catalog } = {}) {
89
+ const list = catalog ? actionsOf(catalog, o.kind) : null;
90
+ const act = typeof o.action === 'object' && o.action ? o.action : list ? list.find((a) => a.label === o.action) : null;
91
+ if (!act || !act.run) return { ok: false, unknown: true, error: 'No such button on a ' + (o.kind || 'card') + '.' };
92
+ if (act.who === 'agent') return { ok: false, ask: act.label + ' for ' + (o.id || 'this') + '.' };
93
+ if (act.who === 'waits' && !o.yes) return { ok: false, needsYes: true, said: act.label + ' waits for your yes.' };
94
+ const c = parseRun(act.run), key = c ? c.verb + ' ' + c.sub : '', R = ROUTES[key];
95
+ if (!R) return { ok: false, unknown: true, error: 'PMOS cannot run "' + act.label + '" from here yet.' };
96
+ const args = { ...(o.args || {}), id: o.id, task: o.id };
97
+ const filled = argsOf(act.run, args);
98
+ if (filled.pos.some((v) => v === undefined || v === '')) return { ok: false, error: act.label + ' needs ' + (act.field || 'a value') + '.' };
99
+ const [route, body0] = R.post(filled.flags, filled.pos, { ...args, was: o.was });
100
+ const body = { ws: o.ws, board: o.board, ...body0 };
101
+ const field = FIELD[key](body0), value = body0[field] !== undefined ? body0[field] : true;
102
+ if (!pmPost) return { ok: false, error: 'No way to write from here.' };
103
+
104
+ if (R.deferred) { // a comment: written when the Undo window closes, unless Undo came first
105
+ let off = false;
106
+ const tm = setTimeout(async () => { if (!off) { const r = await pmPost(route, body).catch(() => null); if (r && r.ok !== false) tell({ kind: o.kind, id: o.id, field, value, undo: false }); } }, o.deferMs != null ? o.deferMs : UNDO_MS);
107
+ return { ok: true, said: act.label + ' sent.', field, value, deferred: true,
108
+ undo: async () => { off = true; clearTimeout(tm); tell({ kind: o.kind, id: o.id, field, value: null, undo: true }); return { ok: true }; } };
109
+ }
110
+ const res = await pmPost(route, body).catch(() => null);
111
+ if (!res || res.ok === false) return { ok: false, error: (res && res.error) || 'The change did not land.' };
112
+ tell({ kind: o.kind, id: o.id, field, value, undo: false });
113
+ const back = R.undo ? R.undo(res, body, { was: o.was }) : null;
114
+ return { ok: true, said: act.label + ' done.', field, value, result: res,
115
+ undo: back ? async () => {
116
+ const u = await pmPost(back[0], { ws: o.ws, board: o.board, ...back[1] }).catch(() => null);
117
+ if (u && u.ok !== false) tell({ kind: o.kind, id: o.id, field, value: o.was !== undefined ? o.was : null, undo: true });
118
+ return u || { ok: false, error: 'The undo did not land.' };
119
+ } : null };
120
+ }
@@ -249,7 +249,7 @@ export function sourceItems(c, f = 'all') {
249
249
 
250
250
  /* ── the side column ── */
251
251
  /** The case: the lines PMOS read from the records, each a press that edits it in place; a line not written offers a PMOS draft. No line
252
- * written: one Suggestion drafts them all (✓ sends the asks to Ask PMOS), ✕ says not now, the pencil starts the first line yourself. */
252
+ * written: one Suggestion drafts them all (✓ runs each draft as a PMOS background job, pm/star-draft.js), ✕ says not now, the pencil starts the first line yourself. */
253
253
  function caseParts(W, o = {}) {
254
254
  const ov = W.overview || { lines: [] }, dr = o.dropped || new Set(), oid = o.oid || '';
255
255
  const L = ov.lines || [], none = L.length && L.every((x) => !x.text);
@@ -265,7 +265,7 @@ function caseParts(W, o = {}) {
265
265
  }
266
266
  const lines = L.filter((x) => !(none && top) || x.text).map((x) => {
267
267
  const ed = !o.ro && x.edit;
268
- const words = x.text ? esc(x.text) : 'Not written yet.';
268
+ const words = x.text ? esc(x.text) : x.drafting ? 'PMOS is drafting it. It shows here.' : 'Not written yet.';
269
269
  const tx = ed ? `<span class="pwd-cv${x.text ? '' : ' grey'}" data-pw-line="${esc(x.id)}" tabindex="0" role="button" aria-label="${esc((x.text ? 'Change the ' : 'Write the ') + x.k.toLowerCase())}">${words}</span>` : `<span class="${x.text ? '' : 'grey'}">${words}</span>`;
270
270
  const src = !o.ro && x.text && x.src ? (x.path ? ` <button type="button" class="pw-osrc" data-pw-src="${esc(x.path)}">from ${esc(x.src)}</button>` : ` <span class="pm-meta">from ${esc(x.src)}</span>`) : '';
271
271
  const off = !o.ro && !x.text && x.ask && !dr.has(sid(x)) ? `<span class="pm-row pwd-off"><button type="button" class="pm-btn" data-pw-lkeep="${esc(x.id)}" aria-label="Yes, PMOS drafts it" title="Yes, PMOS drafts it">${SV(I.star, 14)}</button><button type="button" class="pm-btn" data-pw-ldrop="${esc(sid(x))}" aria-label="No" title="No">${SV(I.x, 14)}</button></span>` : '';
@@ -6,7 +6,9 @@
6
6
  * Built only from Komorebi parts: pm-btn (icon only), pm-input to edit a drafted line, pm-li for each line, pm-meta for its source.
7
7
  * It reads and writes /api/positioning (lib/routes-strategy-card.js) and nothing else.
8
8
  * · Nothing kept, no draft: one quiet line, "Positioning · not drafted yet", and the ✦ that drafts.
9
- * · Kept lines: each with the strategy lines it comes from; a line whose strategy line changed since says so. ✕ drops it.
9
+ * · Collapsed by default (Wawan 2026-11-24, "taking too much space"): the positioning statement only, and "N key messages" that opens
10
+ * the rest (bdPosMore). Where each line comes from is in its tooltip.
11
+ * · Kept lines: a line whose strategy line changed since says so. ✕ drops it.
10
12
  * · A draft: each line in an input the PM can edit, with where it comes from, ✓ to keep it and ✕ to leave it. Lines put together
11
13
  * without AI say so once.
12
14
  * The controls carry ids (bdPosDraft, bdPosKeep, bdPosDrop) so the local use log counts their use (the bet's kill line). */
@@ -15,7 +17,7 @@ import { pmPost } from './http.js';
15
17
  const API = '/api/positioning';
16
18
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
17
19
  const SV = (d) => `<svg class="pm-ic" width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
18
- const I = { spark: 'M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8z', ok: 'M5 12l5 5 9-10', x: 'M6 6l12 12M18 6L6 18', again: 'M4 12a8 8 0 0 1 14-5.3M20 4v5h-5M20 12a8 8 0 0 1-14 5.3M4 20v-5h5' };
20
+ const I = { spark: 'M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8z', ok: 'M5 12l5 5 9-10', x: 'M6 6l12 12M18 6L6 18', again: 'M4 12a8 8 0 0 1 14-5.3M20 4v5h-5M20 12a8 8 0 0 1-14 5.3M4 20v-5h5', chev: 'M7 10l5 5 5-5' };
19
21
  const LABELS = { for: 'Who it is for', problem: 'The problem', bet: 'The bet', win: 'How we win', wont: "What we won't do" };
20
22
  const btn = (id, icon, label, kind, data = '') => `<button type="button" class="pm-btn${kind ? ' ' + kind : ''}" id="${id}"${data} aria-label="${esc(label)}" title="${esc(label)}">${SV(icon)}</button>`;
21
23
 
@@ -23,7 +25,9 @@ const btn = (id, icon, label, kind, data = '') => `<button type="button" class="
23
25
  export const fromLine = (l) => 'From ' + (l.cites || []).map((c) => `${LABELS[c] || c}: ${(l.quotes && l.quotes[c]) || ''}`).join(' · ');
24
26
  const kindWord = (l) => (l.kind === 'positioning' ? 'Positioning' : 'Message');
25
27
 
26
- /** The part's markup. state = { kept, draft, busy }. Pure, so the test reads it. */
28
+ /** The part's markup. state = { kept, draft, busy, left, open }. Pure, so the test reads it.
29
+ * Collapsed (the default): the positioning statement only, and a fold "N key messages" (bdPosMore) that opens the rest. Where a line comes
30
+ * from sits in its tooltip, not under it, so the part stays short; a line whose strategy changed still says so. */
27
31
  export function partHtml(state) {
28
32
  const kept = Array.isArray(state.kept) ? state.kept : [];
29
33
  const d = state.draft && state.draft.state === 'ready' ? state.draft : null;
@@ -32,10 +36,17 @@ export function partHtml(state) {
32
36
  const fresh = d ? d.lines.filter((l) => !keptIds.has(l.id) && !(state.left || []).includes(l.id)) : [];
33
37
  const head = `<div class="head"><h4 class="pm-h-sm" style="flex:1">Positioning${kept.length || fresh.length || pending ? '' : ' <span class="pm-meta">· not drafted yet</span>'}${pending ? ' <span class="pm-meta">· drafting…</span>' : ''}</h4>`
34
38
  + (pending ? '' : btn('bdPosDraft', kept.length || d ? I.again : I.spark, kept.length || d ? 'Draft again from the strategy' : 'Draft positioning from the strategy')) + '</div>';
35
- const keptRows = kept.map((l) => `<div class="pm-li" role="listitem" data-pos="${esc(l.id)}"><span class="txt"><span class="t">${esc(l.text)}</span><span class="w">${esc(kindWord(l))} · ${esc(fromLine(l))}${l.stale ? ' · the strategy changed since you kept this' : ''}</span></span>${btn('bdPosDrop', I.x, 'Drop this line', 'outline', ` data-id="${esc(l.id)}"`)}</div>`).join('');
36
- const draftRows = fresh.map((l) => `<div class="pm-li" role="listitem" data-draft="${esc(l.id)}"><span class="txt"><input class="pm-input" data-text="${esc(l.id)}" maxlength="200" value="${esc(l.text)}" aria-label="${esc(kindWord(l))}" /><span class="w">${esc(kindWord(l))} · ${esc(fromLine(l))}</span></span>${btn('bdPosKeep', I.ok, 'Keep this line', 'primary', ` data-id="${esc(l.id)}"`)}${btn('bdPosLeave', I.x, 'Leave this line', 'outline', ` data-id="${esc(l.id)}"`)}</div>`).join('');
39
+ const tip = (l) => ` title="${esc(kindWord(l) + ' · ' + fromLine(l))}"`;
40
+ const keptRow = (l) => `<div class="pm-li" role="listitem" data-pos="${esc(l.id)}"${tip(l)}><span class="txt"><span class="t">${esc(l.text)}</span>${l.stale ? '<span class="w">The strategy changed since you kept this</span>' : ''}</span>${btn('bdPosDrop', I.x, 'Drop this line', 'outline', ` data-id="${esc(l.id)}"`)}</div>`;
41
+ const draftRow = (l) => `<div class="pm-li" role="listitem" data-draft="${esc(l.id)}"${tip(l)}><span class="txt"><input class="pm-input" data-text="${esc(l.id)}" maxlength="200" value="${esc(l.text)}" aria-label="${esc(kindWord(l))}" /></span>${btn('bdPosKeep', I.ok, 'Keep this line', 'primary', ` data-id="${esc(l.id)}"`)}${btn('bdPosLeave', I.x, 'Leave this line', 'outline', ` data-id="${esc(l.id)}"`)}</div>`;
42
+ const rows = [...kept.map((l) => ({ l, html: keptRow(l) })), ...fresh.map((l) => ({ l, html: draftRow(l) }))];
43
+ const first = rows.findIndex((r) => r.l.kind === 'positioning');
44
+ const lead = first >= 0 ? rows[first] : rows[0];
45
+ const rest = rows.filter((r) => r !== lead);
46
+ const shown = state.open ? [lead, ...rest].filter(Boolean) : (lead ? [lead] : []);
47
+ const fold = rest.length ? `<button type="button" class="pm-fold" id="bdPosMore" aria-expanded="${!!state.open}">${SV(I.chev)}${rest.length} key message${rest.length === 1 ? '' : 's'}</button>` : '';
37
48
  const note = fresh.length && d.by === 'template' ? '<p class="pm-meta">Put together from the strategy word for word, without AI. Edit before you keep.</p>' : '';
38
- return `<div aria-label="Positioning">${head}${keptRows ? `<div role="list">${keptRows}</div>` : ''}${note}${draftRows ? `<div role="list">${draftRows}</div>` : ''}</div>`;
49
+ return `<div aria-label="Positioning">${head}${note}${shown.length ? `<div role="list">${shown.map((r) => r.html).join('')}</div>` : ''}${fold}</div>`;
39
50
  }
40
51
 
41
52
  /** Draw the part into `host` and wire its presses. */
@@ -46,7 +57,7 @@ export async function mount(host, opts = {}) {
46
57
  const get = async () => { try { return await (await fetch(API + q, { credentials: 'same-origin' })).json(); } catch { return null; } };
47
58
  const r = await get();
48
59
  if (!r || !r.ok || !r.complete) { host.hidden = true; host.innerHTML = ''; return; } // an extra: no strategy, no part
49
- const S = { kept: r.kept, draft: r.draft, busy: false, left: [] };
60
+ const S = { kept: r.kept, draft: r.draft, busy: false, left: [], open: host.dataset.open === '1' };
50
61
  const draw = () => { host.hidden = false; host.innerHTML = partHtml(S); };
51
62
  let tries = 0;
52
63
  const poll = async () => {
@@ -75,6 +86,7 @@ export async function mount(host, opts = {}) {
75
86
  const kid = res.line && res.line.id;
76
87
  if (say) say('Line kept.', async () => { if (kid) await pmPost(API + '/drop', { ws, id: kid }).catch(() => null); S.left = S.left.filter((x) => x !== id); poll(); });
77
88
  } else if (b.id === 'bdPosLeave') { S.left.push(id); draw(); }
89
+ else if (b.id === 'bdPosMore') { S.open = !S.open; host.dataset.open = S.open ? '1' : ''; draw(); }
78
90
  else if (b.id === 'bdPosDrop') {
79
91
  const was = S.kept.find((x) => x.id === id);
80
92
  const res = await pmPost(API + '/drop', { ws, id }).catch(() => null);
@@ -7,7 +7,7 @@
7
7
  * · Not written: one quiet line, "Strategy · not written yet", the ✦ that has PMOS draft it (bdStratDraft) and the pencil. While PMOS
8
8
  * drafts (initiative strategy-draft: it starts by itself on a product with no strategy), "drafting from this product's files…".
9
9
  * · A line PMOS drafted shows ✦ and, under it, the files it came from. One Undo in the head (bdStratUndo) takes every drafted line back;
10
- * editing a line makes it the PM's. The inputs carry neutral hints, never an example product's strategy.
10
+ * editing a line makes it the PM's. ✦ beside it (bdStratRedraft) takes PMOS's lines back and drafts them again from the whole product. The inputs carry neutral hints, never an example product's strategy.
11
11
  * · Written: the five lines. Once all five are written, new work that does not fit folds under one line, "2 don't fit", that opens
12
12
  * them, each with why. A note informs only; nothing is moved or blocked. No note, no line (zero is silence).
13
13
  * · The pencil turns the lines into inputs; the tick (or Enter) saves, Esc puts them back. A save offers Undo in the Board's toast.
@@ -45,7 +45,7 @@ export function cardHtml(state) {
45
45
  const drafted = (card && card.drafted) || {}, src = state.sources || {};
46
46
  const from = (k) => (src[k] && src[k].length ? `<span class="pm-meta" style="display:block">From ${src[k].map((x) => esc(x.title)).join(' · ')}</span>` : '');
47
47
  const rows = FIELDS.map((k) => `<dt>${esc(LABELS[k])}</dt><dd${drafted[k] ? ' data-drafted="1"' : ''}>${String(card[k] || '').trim() ? (drafted[k] ? `<span aria-label="Drafted by PMOS" title="Drafted by PMOS">✦</span> ` : '') + esc(card[k]) + (drafted[k] ? from(k) : '') : '<span class="pm-meta">Not written</span>'}</dd>`).join('');
48
- const undo = Object.keys(drafted).length ? btn('bdStratUndo', I.undo, "Undo PMOS's draft", 'outline') : '';
48
+ const undo = Object.keys(drafted).length ? btn('bdStratRedraft', I.spark, "Draft again from the whole product's files", 'outline') + btn('bdStratUndo', I.undo, "Undo PMOS's draft", 'outline') : '';
49
49
  const n = Array.isArray(notes) ? notes.length : 0;
50
50
  const fold = n ? `<button type="button" class="pm-fold" id="bdStratFits" aria-expanded="${!!open}">${SV(I.chev)}${esc(fitsLine(n))}</button>`
51
51
  + (open ? `<div role="list">${notes.map((x) => `<div class="pm-li" role="listitem" data-ini="${esc(x.id)}"><span class="txt"><span class="t">${esc(x.title)}</span><span class="w">Doesn't fit the strategy because it ${esc(x.why)}</span></span></div>`).join('')}</div>` : '')
@@ -102,6 +102,13 @@ export async function mount(host, opts = {}) {
102
102
  host.dataset.polls = ''; mount(host, opts);
103
103
  }).catch(() => { S.drafting = false; draw(); });
104
104
  }
105
+ else if (b.id === 'bdStratRedraft') {
106
+ // take PMOS's lines back, then draft again; the PM's own lines stay
107
+ pmPost('/api/strategy-card', { ws, undo: true }).then((x) => {
108
+ if (!x || !x.ok) { if (say) say((x && x.error) || 'The strategy was not drafted again.'); return null; }
109
+ return pmPost('/api/strategy-card/draft', { ws });
110
+ }).then((x) => { if (x && !x.drafting && say) say('PMOS could not draft: ' + (x.error || x.why || 'no run started') + '.'); host.dataset.polls = ''; mount(host, opts); }).catch(() => null);
111
+ }
105
112
  else if (b.id === 'bdStratUndo') {
106
113
  pmPost('/api/strategy-card', { ws, undo: true }).then((x) => {
107
114
  if (!x || !x.ok) { if (say) say((x && x.error) || 'The draft was not taken back.'); return; }