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.
- package/package.json +23 -22
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +22 -0
- package/workspace/guide/agent-capabilities.md +2 -1
- package/workspace/guide/claude-proposes.md +11 -1
- package/workspace/lib/card-catalog.js +67 -0
- package/workspace/lib/card-catalog.json +2032 -0
- package/workspace/lib/routes-card-catalog.js +19 -0
- package/workspace/lib/routes-slash.js +7 -1
- package/workspace/lib/routes-star-drafts.js +36 -0
- package/workspace/lib/star-draft.js +99 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/action-run.js +120 -0
- package/workspace/public/pm/bd-pop-ds.js +2 -2
- package/workspace/public/pm/card-run.js +25 -0
- package/workspace/public/pm/cozy-pop-work.js +91 -10
- package/workspace/public/pm/goals-open.js +14 -2
- package/workspace/public/pm/star-draft.js +63 -0
- package/workspace/public/pm/state-blocks.js +18 -1
- package/workspace/test-lists/star-buttons-act-directly.json +13 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* pm/star-draft.js — a ✦ "Draft …" answer runs as a PMOS background job, and the draft lands on the row it came from (initiative
|
|
2
|
+
* star-buttons-act-directly, done test A7; the job is lib/star-draft.js behind POST/GET /api/star-drafts).
|
|
3
|
+
*
|
|
4
|
+
* run(ask, { ws, pmPost, pmGet, again, every, upto }) → { ok: true, text } | { ok: false, why }
|
|
5
|
+
* starts the job (or reads the kept draft) and reads it every `every` ms until it lands or `upto` ms pass. No chat, no session of
|
|
6
|
+
* the PM's: the job reads the records and writes nothing.
|
|
7
|
+
* mount(el, { ask, ws, pmPost, pmGet, what, keep, done })
|
|
8
|
+
* draws the job in `el`, the row's own place: "PMOS is drafting …" (the State part, loading), then the draft with ✓ Keep and ✕,
|
|
9
|
+
* or the reason with Try again. keep(text) → true | false saves it the row's own way (with its Undo); done() after ✓ or ✕.
|
|
10
|
+
* pendingHtml(what) · readyHtml(text, what) · failedHtml(why) the three looks PURE
|
|
11
|
+
*
|
|
12
|
+
* Nothing is kept until ✓: the draft is for the PM to read (the words of every draft ask say so). */
|
|
13
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
14
|
+
const SVG = (d) => `<svg class="pm-ic" width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
|
|
15
|
+
const OK = 'M5 12.5l4.5 4.5L19 7.5', NO = 'M6 6l12 12M18 6L6 18', AGAIN = 'M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5';
|
|
16
|
+
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
|
|
18
|
+
export async function run(ask, { ws, pmPost, pmGet, again = false, every = 2500, upto = 200000 } = {}) {
|
|
19
|
+
if (!pmPost || !pmGet) return { ok: false, why: 'No way to reach PMOS from here.' };
|
|
20
|
+
let r = await pmPost('/api/star-drafts', { ws, ask, again }).catch(() => null);
|
|
21
|
+
if (!r || r.ok === false) return { ok: false, why: (r && r.error) || 'PMOS could not start the draft.' };
|
|
22
|
+
const t0 = Date.now();
|
|
23
|
+
while (r.state === 'pending' && Date.now() - t0 < upto) {
|
|
24
|
+
await wait(every);
|
|
25
|
+
r = (await pmGet('/api/star-drafts?key=' + encodeURIComponent(r.key)).catch(() => null)) || { state: 'pending', key: r.key };
|
|
26
|
+
}
|
|
27
|
+
if (r.state === 'ready' && r.text) return { ok: true, text: r.text, key: r.key };
|
|
28
|
+
if (r.state === 'pending') return { ok: false, why: 'The draft is taking longer than it should.' };
|
|
29
|
+
return { ok: false, why: r.why || 'PMOS could not draft it.' };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const pendingHtml = (what) => `<div class="pm-sug pm-draft" role="status"><span class="pm-star" aria-hidden="true">✦</span><span class="say">PMOS is drafting ${esc(what || 'it')}. It shows here.</span></div>`;
|
|
33
|
+
export const readyHtml = (text, what) => `<div class="pm-sug pm-draft" role="group" aria-label="${esc('Draft of ' + (what || 'it'))}"><span class="pm-star" aria-hidden="true">✦</span>`
|
|
34
|
+
+ `<div class="say">${String(text).split(/\n{2,}/).map((p) => `<p>${esc(p).replace(/\n/g, '<br>')}</p>`).join('')}</div>`
|
|
35
|
+
+ `<span class="ans"><button type="button" class="pm-btn primary" data-sd-keep aria-label="Keep this draft" title="Keep this draft">${SVG(OK)}</button>`
|
|
36
|
+
+ `<button type="button" class="pm-btn" data-sd-drop aria-label="Not this one" title="Not this one">${SVG(NO)}</button></span></div>`;
|
|
37
|
+
export const failedHtml = (why) => `<p class="pm-state error" role="alert"><span>${esc(why)}</span><button type="button" class="pm-btn" data-sd-again aria-label="Try again" title="Try again">${SVG(AGAIN)}</button></p>`;
|
|
38
|
+
|
|
39
|
+
export function mount(el, o = {}) {
|
|
40
|
+
if (!el) return null;
|
|
41
|
+
let text = '';
|
|
42
|
+
const go = async (again) => {
|
|
43
|
+
el.innerHTML = pendingHtml(o.what);
|
|
44
|
+
const r = await run(o.ask, { ws: o.ws, pmPost: o.pmPost, pmGet: o.pmGet, again, every: o.every, upto: o.upto });
|
|
45
|
+
if (!el.isConnected && el.isConnected !== undefined) return;
|
|
46
|
+
if (r.ok) { text = r.text; el.innerHTML = readyHtml(text, o.what); } else el.innerHTML = failedHtml(r.why);
|
|
47
|
+
};
|
|
48
|
+
// one press handler on the document, for the buttons inside el (the design system's rule: no click listener on an element)
|
|
49
|
+
const on = async (e) => {
|
|
50
|
+
if (!el.isConnected) { document.removeEventListener('click', on); return; }
|
|
51
|
+
const b = e.target && e.target.closest ? e.target.closest('[data-sd-keep],[data-sd-drop],[data-sd-again]') : null;
|
|
52
|
+
if (!b || !el.contains(b)) return;
|
|
53
|
+
e.preventDefault(); e.stopPropagation();
|
|
54
|
+
if ('sdAgain' in b.dataset) { go(true); return; }
|
|
55
|
+
if ('sdDrop' in b.dataset) { el.innerHTML = ''; if (o.done) o.done(false); return; }
|
|
56
|
+
b.disabled = true;
|
|
57
|
+
const ok = o.keep ? await o.keep(text) : false;
|
|
58
|
+
if (ok) { el.innerHTML = ''; if (o.done) o.done(true); } else b.disabled = false;
|
|
59
|
+
};
|
|
60
|
+
document.addEventListener('click', on);
|
|
61
|
+
go(false);
|
|
62
|
+
return { again: () => go(true) };
|
|
63
|
+
}
|
|
@@ -49,6 +49,21 @@ export function next(step) {
|
|
|
49
49
|
+ `<button type="button" data-sb-next="${esc(step.ask)}" class="pm-btn primary" aria-label="${name}" title="${name}">${SEND}</button></div>`;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** A draft step runs as a PMOS background job (star-buttons-act-directly A7): the draft lands under the step for the person to read, and ✓
|
|
53
|
+
* writes it into the chat with what to keep, so nothing is kept without their yes. A step that needs the person's own words (a list to
|
|
54
|
+
* paste, what they want to reach: its words end in an empty line) still goes to the chat for them to write. */
|
|
55
|
+
export const isDraft = (ask) => /^(Draft|Make draft)\b/.test(String(ask || '')) && !/\n\n$/.test(String(ask || ''));
|
|
56
|
+
async function draftHere(b, ask) {
|
|
57
|
+
const host = b.closest('.pm-state-next') || b.parentElement;
|
|
58
|
+
if (!host || !host.after) { askInChat(ask).catch(() => null); return; }
|
|
59
|
+
let el = host.nextElementSibling;
|
|
60
|
+
if (!el || !el.hasAttribute || !el.hasAttribute('data-sb-draft')) { el = document.createElement('div'); el.setAttribute('data-sb-draft', ''); host.after(el); }
|
|
61
|
+
let ws; try { ws = new URLSearchParams(location.search).get('ws') || undefined; } catch { ws = undefined; }
|
|
62
|
+
const [SD, H] = await Promise.all([import('./star-draft.js'), import('./http.js')]);
|
|
63
|
+
SD.mount(el, { ask, ws, pmPost: H.pmPost, pmGet: H.pmGet, what: 'it',
|
|
64
|
+
keep: async (text) => { await askInChat('Keep these drafts. Make each one as you show it here.\n\n' + text); return true; } });
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
/** The step's words go in the one chat, not sent: Home's own box on Home, else the chat over this page. */
|
|
53
68
|
async function askInChat(text) {
|
|
54
69
|
const box = document.getElementById('hmIn');
|
|
@@ -62,6 +77,8 @@ if (typeof document !== 'undefined' && document.addEventListener) {
|
|
|
62
77
|
const b = e.target && e.target.closest ? e.target.closest('[data-sb-next]') : null;
|
|
63
78
|
if (!b) return;
|
|
64
79
|
e.preventDefault();
|
|
65
|
-
|
|
80
|
+
const ask = b.getAttribute('data-sb-next') || '';
|
|
81
|
+
if (isDraft(ask)) { draftHere(b, ask); return; }
|
|
82
|
+
askInChat(ask).catch(() => null);
|
|
66
83
|
});
|
|
67
84
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "✦ buttons act directly, from one action catalog (initiative star-buttons-act-directly, done test A1-A7): the card catalog loader and route, the action runner with a stub pmPost, a read of the page code and the ✦ draft job with a stubbed session answer. No server, browser or network.",
|
|
3
|
+
"modules": [
|
|
4
|
+
"card-catalog.test.js",
|
|
5
|
+
"action-run.test.js",
|
|
6
|
+
"star-direct.test.js"
|
|
7
|
+
],
|
|
8
|
+
"seconds": {
|
|
9
|
+
"card-catalog.test.js": 1,
|
|
10
|
+
"action-run.test.js": 1,
|
|
11
|
+
"star-direct.test.js": 1
|
|
12
|
+
}
|
|
13
|
+
}
|