create-pmos 0.780.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.
@@ -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 };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.780.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.780.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.780.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>` : '';
@@ -0,0 +1,25 @@
1
+ /* pm/card-run.js — a catalog button's "run" read as a pmos command, for the page (star-buttons-act-directly; the same reading as
2
+ * lib/card-catalog.js parseRun, which card-catalog.test.js holds equal on every button of the catalog).
3
+ *
4
+ * words(s) → the words of a command: "a quoted part", <a placeholder> and plain words PURE
5
+ * parseRun(s) → { verb, sub, pos: [word], flags: { name: word | true } } | null (null when it is not "pmos …") PURE */
6
+ export function words(s) {
7
+ const out = []; const re = /"[^"]*"|<[^>]*>|\S+/g; let m;
8
+ while ((m = re.exec(s))) out.push(m[0]);
9
+ return out;
10
+ }
11
+ export function parseRun(run) {
12
+ const w = words(String(run || '').trim());
13
+ if (w[0] !== 'pmos' || !w[1]) return null;
14
+ const verb = w[1];
15
+ const sub = w[2] && !w[2].startsWith('-') && !w[2].startsWith('<') && !w[2].startsWith('"') ? w[2] : '';
16
+ const pos = [], flags = {};
17
+ for (let i = sub ? 3 : 2; i < w.length; i++) {
18
+ const x = w[i];
19
+ if (x.startsWith('--')) {
20
+ const nx = w[i + 1];
21
+ if (nx !== undefined && !nx.startsWith('--')) { flags[x.slice(2)] = nx; i++; } else flags[x.slice(2)] = true;
22
+ } else pos.push(x);
23
+ }
24
+ return { verb, sub, pos, flags };
25
+ }
@@ -33,6 +33,7 @@ import * as AK from './artefact-kind.js';
33
33
  import * as WT from './work-tree.js'; // subtasks, the epic check and its fix (initiative work-subtasks)
34
34
  import * as SEL from './work-select.js'; // select several rows and move them together (WorkBulkDS)
35
35
  import * as IF from './inline-fields.js'; // a task's sprint and priority, set in the row (initiative inline-sprint-priority)
36
+ import * as SD from './star-draft.js'; // a ✦ draft runs as a PMOS background job and lands on its line (star-buttons-act-directly A7)
36
37
  import * as PD from './bd-pop-ds.js'; // the popup on a computer, built from the design system's blocks (initiative work-ds-popup) // the Kind of a file and one row per kind (round 3 point 16), shared with the Library // the rename and its Undo, the same write as the old List (batch 18 item 16)
37
38
 
38
39
  const CSS = new URL('./cozy-pop-work.css', import.meta.url).href, DSCSS = new URL('./bd-pop-ds.css', import.meta.url).href;
@@ -181,7 +182,7 @@ function ovLines(ov, oid, edit = true) {
181
182
  const dr = dropped();
182
183
  return `<div class="pw-ols">${ov.lines.map((L) => {
183
184
  const ed = edit && L.edit;
184
- const words = L.text ? esc(L.text) : 'Not written yet.'; // the label already names it: said once (round 3 design check)
185
+ const words = L.text ? esc(L.text) : L.drafting ? 'PMOS is drafting it. It shows here.' : 'Not written yet.'; // the label already names it: said once (round 3 design check)
185
186
  const tx = ed ? `<span class="pw-otx${L.text ? '' : ' grey'}" data-pw-line="${esc(L.id)}" tabindex="0" role="button" aria-label="${esc((L.text ? 'Change the ' : 'Write the ') + L.k.toLowerCase())}">${words}</span>` : `<span class="${L.text ? '' : 'grey'}">${words}</span>`;
186
187
  const src = !RO && L.text && L.src ? (L.path ? ` <button type="button" class="pw-osrc" data-pw-src="${esc(L.path)}">from ${esc(L.src)}</button>` : ` <span class="pw-osrc">from ${esc(L.src)}</span>`) : '';
187
188
  const sid = 'ov:' + oid + ':' + L.id;
@@ -401,6 +402,7 @@ function model(r, v0, o) {
401
402
  const g = o.goal || goalOf(o.ws, o.board, r.anchor || v.anchor);
402
403
  const W = M.workOf(r, v, { ...o, goal: M.idShaped(g) ? '' : g, product: productName(o.product, o.ws), art: artOf(id, o.ws), open: S.open, shut: S.shut, moreOpen: S.moreOpen, farOpen: S.farOpen, focus: S.focus, subOpen: S.subOpen, subShut: S.subShut, mode: store.get(SPAN, 'full'), items: it || [], dropped: dropped() });
403
404
  if (pd && W.overview) for (const L of W.overview.lines || []) if (pd.lines[L.id] != null) { L.text = pd.lines[L.id]; delete L.ask; delete L.miss; }
405
+ if (W.overview) for (const L of W.overview.lines || []) if (!L.text && DRAFTING.has(id0 + ':' + L.id)) { L.drafting = true; delete L.ask; delete L.miss; }
404
406
  const mk = M.marksOf(W.span, W.today, W.view); W.tx = mk.today;
405
407
  W.epics = (r.epics || []).filter(Boolean); RSEL = S.sel; // the epic check and the picked rows, for the Gantt rows (initiative work-subtasks)
406
408
  // the Gantt's Jira column (work-subtasks-followups): on unless Choose columns hides it, and only when the work has a Jira row
@@ -600,12 +602,89 @@ function sendToChat(text) {
600
602
  const f = ta.closest('form'); if (f && f.requestSubmit) f.requestSubmit(); else ta.focus();
601
603
  return true;
602
604
  }
605
+ /* the words go to Ask PMOS (star-buttons-act-directly A5): the popup's chat when it is open, else the chat over the page (page-chat.js ask),
606
+ * written in and not sent. No press ends at a toast that only says to open the chat. */
607
+ function toAsk(text, h) {
608
+ if (!text || sendToChat(text)) return;
609
+ const w = h && h.where ? h.where() : {};
610
+ import('./page-chat.js').then((PC) => PC.ask(text, { ws: w.ws || (ASK_AT && ASK_AT.ws) || undefined, here: 'Work' })).catch(() => { if (h && h.toast) h.toast('Ask PMOS did not open. Try again.'); });
611
+ }
612
+ /* a ✦ draft (star-buttons-act-directly A7; Wawan chose "Yes, run drafts in background" on 2026-11-24): the words run as a PMOS background
613
+ * job (pm/star-draft.js, POST /api/star-drafts) with no chat and no session of the PM's. The line says PMOS is drafting it; the draft then
614
+ * lands on the line itself through the line's own save, with Undo. A job that fails says why, with Try again. */
615
+ const DRAFTING = new Set(); // '<popup key>:<line id>' while its job runs
616
+ async function draftLine(L, x, h) {
617
+ const w = h.where ? h.where() : {}, kid = keyOf(x.v(), x.o()), k = kid + ':' + L.id;
618
+ if (DRAFTING.has(k)) return;
619
+ DRAFTING.add(k); if (h.redraw) h.redraw();
620
+ const r = await SD.run(L.ask, { ws: w.ws || x.o().ws, pmPost, pmGet });
621
+ DRAFTING.delete(k);
622
+ if (!r.ok) { if (h.redraw) h.redraw(); undoToast(r.why, () => draftLine(L, x, h), 12000, 'Try again'); return; }
623
+ await saveLine(L, r.text.replace(/\s+/g, ' ').trim().slice(0, 600), x, h);
624
+ }
625
+ /* a program's line (its charter's why or goal): the same job, saved with POST /api/programs/save, and Undo saves the line as it was */
626
+ const LV_FIELD = { for: 'why', goal: 'goal' };
627
+ async function draftLevelLine(Lv, line, h) {
628
+ const f = LV_FIELD[line.id], k = 'level:' + Lv.id + ':' + line.id;
629
+ if (!f || !Lv.id || Lv.kind !== 'program') { toAsk(line.ask, h); return; }
630
+ if (DRAFTING.has(k)) return;
631
+ DRAFTING.add(k); if (h.redraw) h.redraw();
632
+ const r = await SD.run(line.ask, { ws: Lv.home || Lv.ws, pmPost, pmGet });
633
+ DRAFTING.delete(k);
634
+ if (!r.ok) { if (h.redraw) h.redraw(); undoToast(r.why, () => draftLevelLine(Lv, line, h), 12000, 'Try again'); return; }
635
+ const text = r.text.replace(/\s+/g, ' ').trim().slice(0, 600);
636
+ const all = await pmGet('/api/programs').catch(() => null), p = all && all.ok ? (all.programs || []).find((q) => q.id === Lv.id) : null;
637
+ if (!p) { if (h.redraw) h.redraw(); undoToast('The program was not found, so the draft was not saved.', () => draftLevelLine(Lv, line, h), 12000, 'Try again'); return; }
638
+ const was = p[f] || '';
639
+ const res = await pmPost('/api/programs/save', { ws: p.home, program: { ...p, [f]: text } }).catch(() => null);
640
+ if (!res || res.ok === false) { if (h.redraw) h.redraw(); undoToast(LE.notSaved(res), () => draftLevelLine(Lv, line, h), 12000, 'Try again'); return; }
641
+ if (h.reload) await h.reload(); else if (h.redraw) h.redraw();
642
+ undoToast(line.k + ' saved.', async () => {
643
+ const u = await pmPost('/api/programs/save', { ws: p.home, program: { ...((res && res.program) || p), [f]: was } }).catch(() => null);
644
+ if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
645
+ if (h.reload) await h.reload(); else if (h.redraw) h.redraw();
646
+ });
647
+ }
648
+ /* the documents a gate needs (d:draft): each is a PMOS background job with no chat. A core document runs its own draft run (POST
649
+ * /api/core-docs/draft) and lands in Artefacts as a draft for the PM to read; the done test is drafted by the ✦ job and lands as its checks
650
+ * (POST /api/artefacts/set, with Undo); a document PMOS has no writer for here (a PRD or rubric with no core-document entry) is drafted the
651
+ * same way and its draft is written into Ask PMOS with where to save it, so the PM reads it before anything is kept. */
652
+ async function draftDocs(s, x, h) {
653
+ const w = h.where ? h.where() : {}, o = x.o(), id = o.id, ws = w.ws || o.ws, kid = keyOf(x.v(), o), k = kid + ':d:draft';
654
+ if (DRAFTING.has(k)) return;
655
+ const W = model(x.r(), x.v(), o).W, miss = (W.artefacts || []).filter((a) => a.missing);
656
+ if (!miss.length) { toAsk(s.ask, h); return; }
657
+ DRAFTING.add(k);
658
+ if (h.toast) h.toast('PMOS is drafting ' + miss.map((a) => 'the ' + a.title).join(', ').replace(/, (?=[^,]*$)/, ' and ') + '. Each lands in Artefacts.');
659
+ let started = 0;
660
+ for (const a of miss) {
661
+ if (a.key) { const r = await pmPost('/api/core-docs/draft', { ws, scope: 'initiative:' + id, key: a.key }).catch(() => null); if (r && r.ok !== false) { started++; continue; } }
662
+ const done = /^done test$/i.test(a.title);
663
+ const ask = done ? 'Draft the done test for ' + (x.v().title || id) + ': two to four checks, one per line, each one testable. Do not invent anything the records do not say.'
664
+ : 'Draft the ' + a.title + ' for ' + (x.v().title || id) + ' from its documents. Do not invent anything the records do not say.';
665
+ const r = await SD.run(ask, { ws, pmPost, pmGet });
666
+ if (!r.ok) { undoToast(a.title + ': ' + r.why, () => draftDocs(s, x, h), 12000, 'Try again'); continue; }
667
+ started++;
668
+ if (done) {
669
+ const refs = [];
670
+ for (const line of r.text.split(/\n+/).map((t) => t.replace(/^\s*(?:[-*•]|\d+[.)])\s*/, '').trim()).filter(Boolean).slice(0, 6)) {
671
+ const res = await pmPost('/api/artefacts/set', { ws, scope: 'experiment:' + id, artefact: 'done-test', field: 'check', text: line }).catch(() => null);
672
+ if (res && res.ok !== false && res.line) refs.push(res.line.id);
673
+ }
674
+ ART.delete(id);
675
+ if (refs.length) undoToast('Done test drafted: ' + refs.length + (refs.length === 1 ? ' check.' : ' checks.'), async () => { for (const ref of refs) await pmPost('/api/artefacts/undo', { ws, ref }).catch(() => null); ART.delete(id); if (h.redraw) h.redraw(); });
676
+ } else toAsk('Here is a draft of the ' + a.title + ' for ' + (x.v().title || id) + '. Read it with me, then save it where the Artefacts list reads it.\n\n' + r.text, h);
677
+ }
678
+ DRAFTING.delete(k);
679
+ if (h.reload) await h.reload(); else if (h.redraw) h.redraw();
680
+ return started;
681
+ }
603
682
  /* a direct ✓ (bet 1f): the plan end, closing the open tasks, reopening. One press writes through POST /api/boards/ini-<act> with Undo; no chat
604
683
  * message, no session. Only when the route answers ask: true (the plain reading does not hold) do the words go to Ask PMOS, as before. */
605
684
  async function direct(d, ask, x, h) {
606
685
  const w = h.where ? h.where() : {}, id = x.o().id;
607
686
  const res = await pmPost('/api/boards/ini-' + d.act, { ws: w.ws, board: w.board, id, ...(d.to ? { to: d.to } : {}) }).catch(() => null);
608
- if (!res || res.ask) { if (ask && !sendToChat(ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
687
+ if (!res || res.ask) { toAsk(ask, h); return; }
609
688
  if (res.ok === false) { if (h.toast) h.toast(res.error || 'Nothing was changed.'); return; }
610
689
  if (h.reload) await h.reload();
611
690
  if (res.same) { if (h.toast) h.toast(res.said || 'Nothing to change.'); return; }
@@ -624,7 +703,8 @@ async function keepSug(s, x, h) {
624
703
  if (s.move && h.move) { await h.move(s.move.uid, { to: s.move.to, from: '', name: s.move.name }); return; }
625
704
  if (s.moveAll) { await moveAll(s.moveAll, h); return; }
626
705
  if (s.direct) { await direct(s.direct, s.ask, x, h); return; }
627
- if (s.ask && !sendToChat(s.ask) && h.toast) h.toast('Open Ask PMOS to send this.');
706
+ if (s.ask && s.id === 'd:draft') { draftDocs(s, x, h); return; }
707
+ if (s.ask) toAsk(s.ask, h);
628
708
  return;
629
709
  }
630
710
  if (s.sm) { if (h.sm) h.sm('yes'); return; }
@@ -728,20 +808,20 @@ export function wire(body, h0, x0) {
728
808
  if ('pwSpan' in d) { spanMenu(b, redraw); return; }
729
809
  if (d.pwTune) { tuneMenu(b, d.pwTune, redraw); return; }
730
810
  if ('pwBig' in d) { big(c, x, h); return; }
731
- if (d.pwKeep && /^merge:/.test(d.pwKeep)) { const m = mergeOf(W.artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
811
+ if (d.pwKeep && /^merge:/.test(d.pwKeep)) { const m = mergeOf(W.artefacts); if (m) toAsk(m.ask, h); return; }
732
812
  if (d.pwDrop && /^merge:/.test(d.pwDrop)) { const dd = dropped(); dd.add(d.pwDrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
733
- if (d.pwSug && /^merge:/.test(d.pwSug)) { const m = mergeOf(W.artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
813
+ if (d.pwSug && /^merge:/.test(d.pwSug)) { const m = mergeOf(W.artefacts); if (m) toAsk(m.ask, h); return; }
734
814
  if (d.pwKeep) { const s = findSug(W, d.pwKeep); if (s) { b.disabled = true; await keepSug(s, x, h); if (VW.current() && /^sug:/.test(VW.current().id)) VW.back(); } return; }
735
815
  if (d.pwDrop) { const s = findSug(W, d.pwDrop); if (s) { b.disabled = true; await dropSug(s, x, h); if (VW.current() && /^sug:/.test(VW.current().id)) VW.back(); } return; }
736
816
  if (d.pwSug) { const s = findSug(W, d.pwSug); if (s) openSug(s, c, x, h); return; }
737
817
  if ('pwProps' in d) { if (h.props) h.props(); return; }
738
818
  if (d.pwLine) { const L = W.overview.lines.find((q) => q.id === d.pwLine); if (L && L.edit) editLine(b, L, c, x, h); return; }
739
819
  // a phone asks for several lines in one proposal: "problem,done"
740
- if (d.pwLkeep) { const asks = d.pwLkeep.split(',').map((k) => W.overview.lines.find((q) => q.id === k)).filter((L) => L && L.ask).map((L) => L.ask); if (asks.length && !sendToChat(asks.join('\n\n')) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
820
+ if (d.pwLkeep) { const ls = d.pwLkeep.split(',').map((k) => W.overview.lines.find((q) => q.id === k)).filter((L) => L && L.ask); for (const L of ls) { if (L.edit) draftLine(L, x, h); else toAsk(L.ask, h); } return; }
741
821
  if (d.pwLdrop) { const dd = dropped(); for (const k of d.pwLdrop.split(',')) dd.add(k); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
742
822
  if ('pwPdocs' in d) { if (PH_ARTS.has(c.id)) PH_ARTS.delete(c.id); else PH_ARTS.add(c.id); redraw(); return; }
743
823
  if (d.pwSrc) { if (h.doc) h.doc(d.pwSrc); return; }
744
- if (d.pwChoice) { const [sid, k] = d.pwChoice.split('|'), s = findSug(W, sid), ch = s && s.choices && s.choices[+k]; if (ch && ch.direct) { b.disabled = true; await direct(ch.direct, ch.ask, x, h); return; } if (ch && !sendToChat(ch.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
824
+ if (d.pwChoice) { const [sid, k] = d.pwChoice.split('|'), s = findSug(W, sid), ch = s && s.choices && s.choices[+k]; if (ch && ch.direct) { b.disabled = true; await direct(ch.direct, ch.ask, x, h); return; } if (ch) toAsk(ch.ask, h); return; }
745
825
  if (d.pwMore != null) { S.moreOpen.add(d.pwMore); redraw(); return; }
746
826
  if (d.pwVer) { if (ARTOPEN.has(d.pwVer)) ARTOPEN.delete(d.pwVer); else ARTOPEN.add(d.pwVer); redraw(); return; }
747
827
  if (d.pwRowMore) { rowMenu(b, d.pwRowMore, c, h, body); return; }
@@ -1469,12 +1549,13 @@ function artItems(body) {
1469
1549
  const W = model(r, v, x.o()).W, mg = mergeOf(W.artefacts);
1470
1550
  return PD.artMenu(W.artefacts, { ro: RO, merge: mg }).map((it) => ({ ...it, top: true })).map((it) => (it.art != null ? { ...it, on: () => openArt(W.artefacts[it.art], h, x) }
1471
1551
  : it.add ? { ...it, on: () => addArt(x, h) }
1472
- : it.merge ? { ...it, on: () => { if (!sendToChat(mg.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); } } : it));
1552
+ : it.merge ? { ...it, on: () => toAsk(mg.ask, h) } : it));
1473
1553
  }
1474
1554
 
1475
1555
  /* ── one level up: a program or a product (boards 26, 27) ── */
1476
1556
  export function levelHtml(L, o = {}) {
1477
1557
  const W = M.levelOf(L, { today: o.today, mode: store.get(SPAN, 'full') }), C = cols(), mode = store.get(SPAN, 'full');
1558
+ for (const q of (W.overview && W.overview.lines) || []) if (!q.text && DRAFTING.has('level:' + L.id + ':' + q.id)) { q.drafting = true; delete q.ask; delete q.miss; }
1478
1559
  const mk = M.marksOf(W.span, W.today, W.view); W.tx = mk.today;
1479
1560
  const sug = !RO && W.suggests.length ? `<div class="pw-sugs" role="list" aria-label="PMOS suggests"><p class="pw-sugh">PMOS suggests</p>${W.suggests.map((s) => sugLine(s)).join('')}</div>` : '';
1480
1561
  // the same Overview shape as an initiative (round 3 point 10): what it is for, its goal, done when; then the status line and Details ›
@@ -1510,9 +1591,9 @@ export function wireLevel(body, h0, L0) {
1510
1591
  if (d.pwTune) { tuneMenu(b, d.pwTune, redraw); return; }
1511
1592
  if (d.pwDetails) { const S = stOf(d.pwDetails); S.details = !S.details; redraw(); return; }
1512
1593
  if (d.pwVer) { if (ARTOPEN.has(d.pwVer)) ARTOPEN.delete(d.pwVer); else ARTOPEN.add(d.pwVer); redraw(); return; }
1513
- if ((d.pwKeep || d.pwSug) && /^merge:/.test(d.pwKeep || d.pwSug)) { const m = mergeOf(M.levelOf(L()).artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
1594
+ if ((d.pwKeep || d.pwSug) && /^merge:/.test(d.pwKeep || d.pwSug)) { const m = mergeOf(M.levelOf(L()).artefacts); if (m) toAsk(m.ask, h); return; }
1514
1595
  if (d.pwDrop && /^merge:/.test(d.pwDrop)) { const dd = dropped(); dd.add(d.pwDrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
1515
- if (d.pwLkeep) { const x = M.levelOf(L()).overview.lines.find((q) => q.id === d.pwLkeep); if (x && x.ask && !sendToChat(x.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
1596
+ if (d.pwLkeep) { const Lv = L(), x = M.levelOf(Lv).overview.lines.find((q) => q.id === d.pwLkeep); if (x && x.ask) draftLevelLine(Lv, x, h); return; }
1516
1597
  if (d.pwLdrop) { const dd = dropped(); dd.add(d.pwLdrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
1517
1598
  if (d.pwGo) { const i = d.pwGo.indexOf(':'); if (h.go) h.go(d.pwGo.slice(0, i), d.pwGo.slice(i + 1), b); return; }
1518
1599
  if (d.pwArt != null) { const a = M.levelOf(L()).artefacts[+d.pwArt]; if (a && h.art && h.art(a, b)) return; if (a && a.url) window.open(a.url, '_blank', 'noopener'); else if (a && a.path && h.doc) h.doc(a.path); return; }
@@ -14,6 +14,8 @@
14
14
  import * as POP from './cozy-popup.js';
15
15
  import * as VW from './cozy-viewer.js';
16
16
  import * as GM from './goals-model.js';
17
+ import { pmGet, pmPost } from './http.js';
18
+ import * as SD from './star-draft.js'; // a ✦ draft runs as a PMOS background job and lands under its row (star-buttons-act-directly A7)
17
19
 
18
20
  const CSS = ['./cozy-pop-work.css', './cozy-goals.css'].map((p) => new URL(p, import.meta.url).href);
19
21
  if (typeof document !== 'undefined' && document.head) for (const h of CSS) if (!document.querySelector(`link[href="${h}"]`)) { const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = h; document.head.appendChild(l); }
@@ -25,6 +27,16 @@ const ib = (attr, label, d, cls = '') => `<button type="button" class="pw-ib${cl
25
27
  const row = (attr, label, val, cls = '') => `<button type="button" class="pw-src gl-src" ${attr}><span>${esc(label)}</span><span class="gl-srcv"><small class="${cls}">${esc(val || '')}</small>${SVG(P.right, 14)}</span></button>`;
26
28
  const ask = '<button type="button" class="pw-ask" data-gl-ask>' + SVG(P.chat, 15) + 'Ask PMOS about this</button>';
27
29
 
30
+ /** A ✦ draft (star-buttons-act-directly A7): the words run as a PMOS background job with no chat, and the draft lands under the row that
31
+ * was pressed, for the PM to read. ✓ writes the read draft into the chat with `keep` (what to keep), so nothing is kept without the PM. */
32
+ function draftHere(t, ctx, ask, what, keep) {
33
+ const host = (t.closest && t.closest('.pw-card, .pw-spc')) || t.parentElement;
34
+ if (!host || !host.after) { toChat(ask); return; }
35
+ let el = host.nextElementSibling;
36
+ if (!el || !el.hasAttribute || !el.hasAttribute('data-gl-draft')) { el = document.createElement('div'); el.setAttribute('data-gl-draft', ''); host.after(el); }
37
+ SD.mount(el, { ask, ws: ctx.ws || undefined, pmPost, pmGet, what, keep: async (text) => { toChat(keep + '\n\n' + text); return true; } });
38
+ }
39
+
28
40
  /** The words go in the chat on the right, as a draft the PM sends. The chat shows first when it was hidden. */
29
41
  export function toChat(text) {
30
42
  const a = document.querySelector('.cz-pop [data-pop="ask"]'); if (a && !a.closest('[hidden]')) a.click();
@@ -88,7 +100,7 @@ export function openSetup(ctx) {
88
100
  if ('glNsdrop' in d) { t.disabled = true; await ctx.dropNs(ns.row); return; }
89
101
  // the draft run files the draft this page waits for; the chat could not (initiative chat-saves-to-cards)
90
102
  if ('glNsdraft' in d) { t.disabled = true; if (ctx.startNs) { const ok = await ctx.startNs(); if (ok) b.innerHTML = '<div class="pw gl-pg"><p class="grey">PMOS is drafting the North Star. It shows here for your tick.</p></div>'; else t.disabled = false; } else toChat('Draft a North Star for this product from its key results. I approve it with a tick.'); return; }
91
- if (d.glName) { const n = S.names.find((x) => x.id === d.glName); if (n) toChat((n.named ? 'Check the name of ' : 'Name ') + n.label + ' (' + n.krs + '). Draft it from its key results; I approve it with a tick.'); return; }
103
+ if (d.glName) { const n = S.names.find((x) => x.id === d.glName); if (n) draftHere(t, ctx, (n.named ? 'Check the name of ' : 'Name ') + n.label + ' (' + n.krs + '). Draft it from its key results; I approve it with a tick.', 'a name for ' + n.label, 'Keep this name for ' + n.label + '.'); return; }
92
104
  if (d.glSrc) { const s = S.sources.find((x) => x.need === d.glSrc); if (s) toChat('Connect ' + s.need + '. ' + s.frees + '. Test a read before you keep it, and tell me what you need from me.'); return; }
93
105
  if ('glAsk' in d) toChat('About setting up Goals: what should I confirm or connect first?');
94
106
  });
@@ -107,7 +119,7 @@ export function openVerdict(ctx, id, back = false) {
107
119
  + ask + '</div>';
108
120
  show(ctx, { id: 'outcome:' + id, kind: 'Outcome', title: V.title, back }, html, (t) => {
109
121
  const d = t.dataset;
110
- if ('glJudge' in d) { toChat('Judge the outcome of ' + V.title + ': read the result, set it beside the promise and give me a verdict with the reason. Change nothing in the plan until I approve the lesson.'); return; }
122
+ if ('glJudge' in d) { draftHere(t, ctx, 'Judge the outcome of ' + V.title + ': read the result, set it beside the promise and give me a verdict with the reason. Change nothing in the plan until I approve the lesson.', 'a verdict on ' + V.title, 'Keep this verdict on the outcome of ' + V.title + '. Change nothing in the plan until I approve the lesson.'); return; }
111
123
  if (d.glKr) { openKr(ctx, d.glKr, true); return; }
112
124
  if (d.glIni) { openIni(ctx, d.glIni); return; }
113
125
  if ('glAsk' in d) toChat('About the outcome of ' + V.title + ': did it do what it promised?');