create-pmos 0.698.0 → 0.699.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.698.0",
3
+ "version": "0.699.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -34,8 +34,8 @@
34
34
  ],
35
35
  "pmosChanges": [
36
36
  {
37
- "v": "0.698.0",
38
- "at": "2026-11-22T10:16:59.106Z",
37
+ "v": "0.699.0",
38
+ "at": "2026-11-22T10:23:23.766Z",
39
39
  "f": 4,
40
40
  "prs": [
41
41
  {
@@ -43,6 +43,12 @@
43
43
  "t": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
44
44
  "s": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
45
45
  "k": "x"
46
+ },
47
+ {
48
+ "n": 1518,
49
+ "t": "Forms keep drafts when panels close",
50
+ "s": "Forms keep drafts when panels close",
51
+ "k": "new"
46
52
  }
47
53
  ]
48
54
  },
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@3eebb089
1
+ kernel-source: pmos@dc606942
2
2
  assembled: 2026-11-22
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-22T10:16:55Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T10:23:20Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-22T10:16:55Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T10:23:20Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-22T10:16:55Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T10:23:20Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,7 +1,7 @@
1
1
  [
2
2
  {
3
- "v": "0.698.0",
4
- "at": "2026-11-22T10:16:59.106Z",
3
+ "v": "0.699.0",
4
+ "at": "2026-11-22T10:23:23.766Z",
5
5
  "f": 4,
6
6
  "prs": [
7
7
  {
@@ -9,6 +9,12 @@
9
9
  "t": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
10
10
  "s": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
11
11
  "k": "x"
12
+ },
13
+ {
14
+ "n": 1518,
15
+ "t": "Forms keep drafts when panels close",
16
+ "s": "Forms keep drafts when panels close",
17
+ "k": "new"
12
18
  }
13
19
  ]
14
20
  },
@@ -116,6 +116,15 @@ The Viewer shows one item: an initiative, a program, a task, a document, a meeti
116
116
  - On a page drawn from the PMOS design system (Today, Home, an item on its own page), the parts inside the Viewer card follow the system too: a meeting, the calendar and a report use its corners, its buttons and its switches. A word button has a small corner, a switch looks like tabs, and a chip or a tag stays round.
117
117
  - One item shows in one Viewer only. If an item is already open, opening it again (a row, a ⌘-click, Open beside) shows it in the Viewer it is in. It never opens a second copy.
118
118
 
119
+ ### What you type is kept
120
+
121
+ Text you type in a PMOS box (a chat message, a Why, notes, a routine's instructions) is kept on this computer until you send it, save it or clear it.
122
+
123
+ - If a panel closes or the page reloads before you send, open the same box again: the text is back, and a short note at the bottom of the page says **Draft kept**. On a phone the note shows under the top bar.
124
+ - Press the Undo icon on that note to start empty instead.
125
+ - A message typed in one chat stays with that chat.
126
+ - PMOS keeps nothing from password, key, token or search boxes. A kept draft goes after 14 days.
127
+
119
128
  ### A task opened from a place
120
129
 
121
130
  On a computer, a PMOS task you open from Events, Today, Goals or Search opens as one full popup, in the middle of the page. Home keeps its Viewer until Home is rebuilt, and a Jira ticket keeps the ticket Viewer.
@@ -45,6 +45,7 @@ const MODULES = Object.freeze([
45
45
  'routes-my-work', // initiative my-work: the ranked list of work assigned to the PM, the brief, Read again
46
46
  'routes-intake', // planning-flows run 4: one-line intake draft (drafts only)
47
47
  'routes-pm-items', // planning-flows runs 1-2: the PM's own items and jobs to be done (add, edit, remove, undo)
48
+ 'routes-draft-keep', // forms-keep-drafts: counts of returned and undone drafts, never the text (draft-keep/marks.jsonl; page-press POST)
48
49
  'routes-today-log', // six-place navigation slice 5: Today's log, the PM's own entries and marks (today-log/log.jsonl; page-press POST)
49
50
  'routes-runs', // console3 agent surfaces: runs grouped for the sessions panel, PM answers, corrections
50
51
  'routes-doc-health', // console3 B2: the six document health checks, recomputed from text
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+ /* routes-draft-keep.js — the health number of forms that keep drafts (initiative forms-keep-drafts; pm/draft-keep.js is the page side).
3
+ *
4
+ * POST /api/draft-keep/mark { ev: "restored" | "undone", n } → { ok } a page press; appends { at, ev, n } and nothing else
5
+ *
6
+ * The drafts themselves stay in the browser's local storage: this route never receives or keeps any typed text, only counts.
7
+ * STATE: <runtime>/draft-keep/marks.jsonl, append-only.
8
+ * HEALTH (record health_read): `node workspace/lib/routes-draft-keep.js --kept-percent` prints the percent of returned drafts kept, not
9
+ * undone, over the last 14 days; -1 when no draft came back in that time. Every line it logs starts with [draft-keep]. */
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const guard = require('./pm-guard.js');
13
+
14
+ const EVENTS = new Set(['restored', 'undone']);
15
+ const WINDOW = 14 * 864e5;
16
+ const fileOf = (runtimeDir) => path.join(runtimeDir, 'draft-keep', 'marks.jsonl');
17
+
18
+ function readLines(file) {
19
+ let raw = '';
20
+ try { raw = fs.readFileSync(file, 'utf8'); } catch { return []; }
21
+ return raw.split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
22
+ }
23
+
24
+ /** Percent of returned drafts kept (not undone) in the 14 days before `now`; -1 when none came back. */
25
+ function keptPercent(lines, now) {
26
+ let back = 0, undone = 0;
27
+ for (const l of lines) {
28
+ const t = Date.parse(l.at);
29
+ if (!(now - t <= WINDOW)) continue;
30
+ const n = Number.isInteger(l.n) && l.n > 0 ? l.n : 1;
31
+ if (l.ev === 'restored') back += n; else if (l.ev === 'undone') undone += n;
32
+ }
33
+ if (!back) return -1;
34
+ return Math.round(100 * Math.max(0, back - undone) / back);
35
+ }
36
+
37
+ module.exports = {
38
+ prefixes: ['/api/draft-keep'],
39
+ fileOf,
40
+ keptPercent,
41
+ handle: async (req, res, url, ctx) => {
42
+ if (url.pathname !== '/api/draft-keep/mark' || req.method !== 'POST') return false;
43
+ if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'PMOS has no state folder here, so it cannot count returned drafts' }, 503); return true; }
44
+ const got = await ctx.readJson(req);
45
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
46
+ const body = got.body || {};
47
+ const g = guard.requirePagePress(req, body);
48
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
49
+ if (!EVENTS.has(body.ev)) { ctx.json(res, { ok: false, error: 'ev is restored or undone' }, 400); return true; }
50
+ const n = Number.isInteger(body.n) && body.n > 0 && body.n < 1000 ? body.n : 1;
51
+ const file = fileOf(ctx.runtimeDir);
52
+ fs.mkdirSync(path.dirname(file), { recursive: true });
53
+ fs.appendFileSync(file, JSON.stringify({ at: new Date().toISOString(), ev: body.ev, n }) + '\n');
54
+ console.log(`[draft-keep] ${body.ev} ${n}`);
55
+ ctx.json(res, { ok: true });
56
+ return true;
57
+ },
58
+ };
59
+
60
+ if (require.main === module && process.argv.includes('--kept-percent')) {
61
+ const root = require('./state-root.js').resolveStateRoot({ env: process.env, legacy: null }).root;
62
+ const lines = readLines(fileOf(root));
63
+ console.log(`[draft-keep] ${lines.length} marks in ${fileOf(root)}`);
64
+ console.log(String(keptPercent(lines, Date.now())));
65
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.698.0",
3
+ "version": "0.699.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.698.0",
9
+ "version": "0.699.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.698.0",
3
+ "version": "0.699.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,74 @@
1
+ /**
2
+ * cozy-draft-keep.js — the page side of pm/draft-keep.js (initiative forms-keep-drafts): one keeper per page, its listeners on the
3
+ * document, and the design system's Toast when a draft comes back. draft-keep.js loads it in a browser; the engine and the Toast's
4
+ * markup stay in draft-keep.js, where node tests reach them.
5
+ */
6
+ import { createKeeper, toastHtml } from './draft-keep.js';
7
+ const TOAST_MS = 6000;
8
+
9
+ export function install() {
10
+ const W = window;
11
+ const store = {
12
+ get: (k) => { const s = W.localStorage.getItem(k); return s ? JSON.parse(s) : null; },
13
+ set: (k, v) => W.localStorage.setItem(k, JSON.stringify(v)),
14
+ remove: (k) => W.localStorage.removeItem(k),
15
+ keys: () => Array.from({ length: W.localStorage.length }, (_, i) => W.localStorage.key(i)).filter(Boolean),
16
+ };
17
+ const mark = (ev, n) => {
18
+ console.info(`[draft-keep] ${ev} ${n}`);
19
+ import('./http.js').then((h) => h.pmPost('/api/draft-keep/mark', { ev, n })).catch(() => {});
20
+ };
21
+ // a press is near a box when they share a form, or the press sits within the box's three nearest ancestors
22
+ const near = (btn, el) => {
23
+ if (el.form && btn.form === el.form) return true;
24
+ let a = el.parentElement;
25
+ for (let i = 0; i < 3 && a; i++, a = a.parentElement) if (a.contains(btn)) return true;
26
+ return false;
27
+ };
28
+ let pend = 0, toastEl = null, toastT = 0;
29
+ const still = () => (W.matchMedia && W.matchMedia('(prefers-reduced-motion: reduce)').matches) || document.documentElement.classList.contains('ad-still');
30
+ const showToast = () => {
31
+ const n = pend; pend = 0;
32
+ if (!n) return;
33
+ if (!toastEl) {
34
+ toastEl = document.createElement('div');
35
+ toastEl.className = 'pm-ds'; // the Komorebi scope: its Toast and tokens apply inside it
36
+ // a desk: bottom centre, as the Toast part says. A phone: under the top bar, so it never covers the chat box at the foot (critic, p16)
37
+ const phone = W.innerWidth <= 760; // the same edge as the menu's phone layout (cozy-nav.js)
38
+ toastEl.style.cssText = `position:fixed;left:50%;${phone ? 'top:var(--space-64)' : 'bottom:var(--space-24)'};transform:translateX(-50%);z-index:2147483000;background:none`
39
+ + (still() ? '' : ';transition:opacity var(--duration-enter) var(--ease-out)');
40
+ document.body.appendChild(toastEl);
41
+ toastEl.addEventListener('click', (e) => { if (e.target.closest('[data-dk-undo]')) { K.undo(); hide(); } });
42
+ toastEl.addEventListener('mouseenter', () => clearTimeout(toastT));
43
+ toastEl.addEventListener('mouseleave', () => { toastT = setTimeout(hide, TOAST_MS); });
44
+ }
45
+ toastEl.innerHTML = toastHtml(n);
46
+ toastEl.hidden = false; toastEl.style.opacity = '1';
47
+ const bar = toastEl.querySelector('[data-dk-timer]');
48
+ // the countdown line moves only when motion is allowed (critic, p12): reduced motion or Settings > Adler > Motion: Still shows it still
49
+ if (bar) { bar.style.display = 'block'; bar.style.width = '100%'; if (!still()) { bar.style.transition = `width ${TOAST_MS / 1000}s linear`; requestAnimationFrame(() => { bar.style.width = '0'; }); } }
50
+ clearTimeout(toastT); toastT = setTimeout(hide, TOAST_MS);
51
+ };
52
+ const hide = () => { if (toastEl) { toastEl.hidden = true; toastEl.innerHTML = ''; } };
53
+ const K = createKeeper({
54
+ store, near, path: location.pathname,
55
+ onRestore: (list) => { if (!pend) queueMicrotask(showToast); pend += list.length; },
56
+ onMark: mark,
57
+ });
58
+ let tickT = 0;
59
+ const soon = () => { clearTimeout(tickT); tickT = setTimeout(() => K.tick(), 60); };
60
+ const later = () => { soon(); setTimeout(() => K.tick(), 700); setTimeout(() => K.tick(), 2000); };
61
+ const boxes = (root) => (root.matches && root.matches('textarea,input') ? [root] : []).concat(root.querySelectorAll ? [...root.querySelectorAll('textarea,input')] : []);
62
+ const scan = (root) => { for (const el of boxes(root)) K.seen(el); };
63
+ document.addEventListener('focusin', (e) => K.seen(e.target), true);
64
+ document.addEventListener('input', (e) => { if (e.isTrusted) K.input(e.target); }, true);
65
+ document.addEventListener('submit', (e) => { K.submitted(e.target); later(); }, true);
66
+ document.addEventListener('click', (e) => { const b = e.target.closest && e.target.closest('button,[role="button"],input[type="submit"]'); if (b) { K.pressed(b); later(); } }, true);
67
+ document.addEventListener('keydown', (e) => { if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { K.entered(e.target); later(); } }, true);
68
+ new MutationObserver((ms) => {
69
+ for (const m of ms) for (const a of m.addedNodes) if (a.nodeType === 1) scan(a);
70
+ soon();
71
+ }).observe(document.documentElement, { childList: true, subtree: true });
72
+ scan(document);
73
+ }
74
+
@@ -41,6 +41,7 @@
41
41
  import { esc, svg, ICON, wsQ } from './cozy-evui.js';
42
42
  import { fabLabel, bannerOf } from './cozy-evmodel.js';
43
43
  import { mountToastFaces, loadPrefs } from './cozy-adler.js';
44
+ import './draft-keep.js'; // forms-keep-drafts: every text box on every page keeps a draft until sent, saved or cleared
44
45
  import { pmPost } from './http.js'; // Adler (batch 16 item 2): every toast carries his S face; Settings > Adler is read once
45
46
 
46
47
  /* The six places (slice 1). A place shows once it has an href: Events, Library and Routine get theirs when their slice ships. Until then
@@ -0,0 +1,151 @@
1
+ /**
2
+ * draft-keep.js — every text box keeps a draft until it is sent, saved or cleared (initiative forms-keep-drafts, idea A400).
3
+ *
4
+ * The panel rule closes the oldest panel when a new one opens, and a reload drops what was typed. This module listens at the document
5
+ * level, so no page has to change: what the PM types in a textarea or a text input is kept in this browser's local storage, and when
6
+ * the same box opens again showing the same value it opened with, the text is put back and one quiet Toast says "Draft kept", with Undo.
7
+ *
8
+ * keyFor(el, path) the draft's key, or null when this box keeps nothing (password, email, search, key or token boxes,
9
+ * read-only or disabled boxes, data-draft="off", a box with no name, id, label or placeholder)
10
+ * createKeeper(opts) the engine, on any store: { seen, input, pressed, entered, submitted, tick, undo }
11
+ * toastHtml(n) the design system's Toast (pm-toast), Undo as an icon button
12
+ * PREFIX the storage key prefix
13
+ *
14
+ * The key is data-draft-key on the box or an ancestor (a chat box names its chat), else the page path, the nearest ancestor id and the
15
+ * box's own name. A draft is { v, base, at }: it comes back only on its own base, so a saved value that changed since is never covered.
16
+ * A draft is dropped when its form submits, when a send or save press near the box is followed by the box emptying or going away, when
17
+ * the page empties or resets the box itself, and after 14 days (at most 200 are kept). Contenteditable editors are left alone.
18
+ * Health (record health_read): each return and each Undo posts a count, never the text, to POST /api/draft-keep/mark, and logs [draft-keep].
19
+ */
20
+ export const PREFIX = 'pmos.draft:';
21
+ const DAY = 864e5, MAX_AGE = 14 * DAY, MAX_DRAFTS = 200, PRESS_WINDOW = 3000;
22
+ const SENSITIVE = /password|passcode|passphrase|\bpass\b|token|secret|api[\s_-]*key|\bkey\b|one-time|\botp\b|\bcc-|card|cvc|\bssn\b|search|filter|\bfind\b/i;
23
+ const SENDS = /\b(send|save|add|post|submit|done|create|keep|reply|ask|update|apply|publish|confirm)\b/i;
24
+
25
+ const attr = (el, k) => { try { const v = el.getAttribute(k); return v == null ? '' : String(v); } catch { return ''; } };
26
+
27
+ /** The draft's key for this box, or null when it keeps nothing. path: the page's path. */
28
+ export function keyFor(el, path) {
29
+ if (!el || !el.tagName) return null;
30
+ const tag = String(el.tagName).toLowerCase();
31
+ if (tag === 'input') { if ((attr(el, 'type') || 'text').toLowerCase() !== 'text') return null; }
32
+ else if (tag !== 'textarea') return null;
33
+ if (el.readOnly || el.disabled) return null;
34
+ const role = attr(el, 'role').toLowerCase();
35
+ if (role === 'searchbox' || role === 'combobox') return null;
36
+ if (el.closest && el.closest('[data-draft="off"]')) return null;
37
+ const words = ['name', 'id', 'aria-label', 'placeholder', 'autocomplete'].map((k) => attr(el, k)).join(' ');
38
+ if (SENSITIVE.test(words)) return null;
39
+ const ident = attr(el, 'name') || attr(el, 'id') || attr(el, 'aria-label') || attr(el, 'placeholder');
40
+ const own = el.closest ? el.closest('[data-draft-key]') : null;
41
+ if (own) return `k:${attr(own, 'data-draft-key')}|${ident || '-'}`;
42
+ if (!ident) return null;
43
+ let scope = '';
44
+ for (let x = el.parentElement; x && !scope; x = x.parentElement) scope = attr(x, 'id');
45
+ return `p:${path || ''}|${scope}|${ident}`;
46
+ }
47
+
48
+ /**
49
+ * The engine. opts: { store: { get, set, remove, keys }, now(), path, onRestore(list), onMark(ev, n), near(button, box) }.
50
+ * The page calls seen() when a box appears or takes focus, input() on each change, pressed() on a button press, entered() on Enter
51
+ * in a box, submitted() on a form submit, and tick() a little after each of those.
52
+ */
53
+ export function createKeeper(opts) {
54
+ const S = opts.store, now = opts.now || Date.now, near = opts.near || (() => false);
55
+ const live = new Set();
56
+ let lastBatch = [];
57
+ const safe = (fn, dflt) => { try { return fn(); } catch { return dflt; } };
58
+ const get = (k) => safe(() => { const d = S.get(PREFIX + k); return d && typeof d.v === 'string' && typeof d.base === 'string' ? d : null; }, null);
59
+ const put = (k, d) => safe(() => S.set(PREFIX + k, d));
60
+ const drop = (k) => safe(() => S.remove(PREFIX + k));
61
+ const recOf = (el) => { for (const r of live) if (r.el === el) return r; return null; };
62
+
63
+ // old drafts go: older than 14 days, then the oldest beyond 200
64
+ safe(() => {
65
+ const all = S.keys().filter((k) => k.startsWith(PREFIX)).map((k) => [k, safe(() => S.get(k), null)]);
66
+ const t = now(), keep = [];
67
+ for (const [k, d] of all) { if (!d || typeof d.at !== 'number' || t - d.at > MAX_AGE) S.remove(k); else keep.push([k, d.at]); }
68
+ keep.sort((a, b) => a[1] - b[1]);
69
+ while (keep.length > MAX_DRAFTS) S.remove(keep.shift()[0]);
70
+ });
71
+
72
+ function seen(el) {
73
+ if (recOf(el)) return recOf(el);
74
+ const key = keyFor(el, opts.path);
75
+ if (!key) return null;
76
+ const r = { el, key, base: el.value, last: el.value, pending: 0, restored: null };
77
+ let d = get(key);
78
+ // the same box drawn again right after a send or save (an Add that clears and redraws its list): the draft went with the press
79
+ for (const o of live) if (o.key === key && o.pending && now() - o.pending < PRESS_WINDOW && (!o.el.isConnected || o.el.value === '')) { drop(key); d = null; live.delete(o); }
80
+ if (d && el.value === d.v) r.base = d.base; // the page drew the box again with the draft in it
81
+ else if (d && el.value === d.base && d.v !== d.base) { // the box opened again as it was: put the draft back
82
+ r.last = d.v; r.restored = d.v; el.value = d.v;
83
+ live.add(r);
84
+ safe(() => el.dispatchEvent(new Event('input', { bubbles: true })));
85
+ lastBatch = lastBatch.filter((x) => x.el.isConnected).concat(r);
86
+ if (opts.onRestore) opts.onRestore([r]);
87
+ if (opts.onMark) opts.onMark('restored', 1);
88
+ return r;
89
+ }
90
+ live.add(r);
91
+ return r;
92
+ }
93
+ function input(el) {
94
+ const r = recOf(el) || seen(el);
95
+ if (!r) return;
96
+ r.last = el.value;
97
+ if (el.value === r.base) drop(r.key);
98
+ else put(r.key, { v: el.value, base: r.base, at: now() });
99
+ }
100
+ function pressed(btn) {
101
+ if (!btn) return;
102
+ const label = attr(btn, 'aria-label') || String(btn.textContent || '').trim() || attr(btn, 'title');
103
+ if (String(btn.type || '').toLowerCase() !== 'submit' && !SENDS.test(label)) return;
104
+ for (const r of live) if (safe(() => near(btn, r.el), false)) r.pending = now();
105
+ }
106
+ function entered(el) { const r = recOf(el); if (r) r.pending = now(); }
107
+ function submitted(form) {
108
+ for (const r of live) if (r.el.form && r.el.form === form) { drop(r.key); r.pending = now(); r.base = r.el.value; r.last = r.el.value; }
109
+ }
110
+ function tick() {
111
+ const t = now();
112
+ for (const r of [...live]) {
113
+ const sent = r.pending && t - r.pending < PRESS_WINDOW;
114
+ if (!r.el.isConnected) { if (sent) drop(r.key); live.delete(r); continue; }
115
+ if (r.el.value !== r.last) { // the page changed the box itself: sent, saved or reset
116
+ drop(r.key); r.base = r.el.value; r.last = r.el.value;
117
+ } else if (sent && r.el.value === '') drop(r.key);
118
+ if (r.pending && !sent) r.pending = 0;
119
+ }
120
+ }
121
+ function undo() {
122
+ const batch = lastBatch; lastBatch = [];
123
+ if (!batch.length) return 0;
124
+ for (const r of batch) {
125
+ if (r.el.isConnected && r.el.value === r.restored) {
126
+ r.el.value = r.base; r.last = r.base;
127
+ safe(() => r.el.dispatchEvent(new Event('input', { bubbles: true })));
128
+ }
129
+ drop(r.key);
130
+ }
131
+ if (opts.onMark) opts.onMark('undone', batch.length);
132
+ return batch.length;
133
+ }
134
+ return { seen, input, pressed, entered, submitted, tick, undo };
135
+ }
136
+
137
+ const UNDO_ICON = '<svg class="pm-ic" aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3"/></svg>';
138
+
139
+ /** The design system's Toast for n returned drafts. */
140
+ export function toastHtml(n) {
141
+ const say = n > 1 ? `${n} drafts kept` : 'Draft kept';
142
+ return `<div class="pm-toast" role="status" aria-live="polite"><span class="in"><span>${say}</span>`
143
+ + `<button type="button" class="pm-btn" data-dk-undo aria-label="Undo: start empty" title="Undo">${UNDO_ICON}</button></span>`
144
+ + '<span class="timer" data-dk-timer></span></div>';
145
+ }
146
+
147
+ /* the browser: the page side lives in cozy-draft-keep.js (the Agreed design's layer), loaded once per page */
148
+ if (typeof window !== 'undefined' && typeof document !== 'undefined' && !window.__pmosDraftKeep) {
149
+ window.__pmosDraftKeep = true;
150
+ import('./cozy-draft-keep.js').then((m) => m.install()).catch((e) => console.info('[draft-keep] off:', e && e.message));
151
+ }
@@ -481,7 +481,7 @@ export function mountChat(el, host) {
481
481
  // chief-of-staff C5 (CsB): the soft "You are on …" chip of the chat over a page; × drops it (sc.drop), and the chip then reads Everything
482
482
  const scope = to || wait ? '' : sc.drop ? `<button type="button" class="hm-chip soft" data-hm-scope aria-label="${esc(sc.text)}. Drop this" title="Drop this">${SVG(sc.icon, 14)}<span>${esc(sc.text)}</span>${SVG(XX, 14)}</button>`
483
483
  : `<button type="button" class="hm-chip${sc.loose ? ' loose' : ''}" data-hm-scope aria-label="Where this goes: ${esc(sc.text)}. Change" title="Where this goes: ${esc(sc.text)}">${SVG(sc.icon, 14)}<span>In: ${esc(sc.text)}</span></button>`;
484
- const html = `${also}<form class="hm-box${on ? ' ut-on' : ''}" id="hmForm">${dot}<textarea id="hmIn" rows="1" aria-label="A message for ${esc(R.role.name)}" placeholder="${esc(ph)}"></textarea>`
484
+ const html = `${also}<form class="hm-box${on ? ' ut-on' : ''}" id="hmForm" data-draft-key="chat:${esc(t.key || t.sid || 'new')}">${dot}<textarea id="hmIn" rows="1" aria-label="A message for ${esc(R.role.name)}" placeholder="${esc(ph)}"></textarea>`
485
485
  + `<div class="hm-tb">${add}`
486
486
  + to + wait + scope + `<span class="sp"></span>${host.viewerClosed() ? '<span class="hm-key">Enter sends · Shift+Enter for a new line</span>' : ''}`
487
487
  + `${NPU.undoHtml()}${mic}<button type="submit" class="hm-send" aria-label="Send" title="Send">${SVG(UP, 18)}</button></div>`
@@ -4,6 +4,7 @@
4
4
  * Closing the card leaves a line that links to Home. An address that names nothing says so. */
5
5
  import { views } from './premium-vw-open.js';
6
6
  import { onChange } from './cozy-viewer.js';
7
+ import './draft-keep.js'; // forms-keep-drafts: the Viewer page has no menu, so it loads the draft keeper itself
7
8
 
8
9
  const q = new URLSearchParams(location.search), ws = q.get('ws') || '';
9
10
  const gone = document.getElementById('vzGone');
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Forms keep drafts when panels close (initiative forms-keep-drafts, done test T1-T9): which boxes keep a draft, when it comes back and when it is dropped, the system Toast, and the marks route that keeps counts only. Pure checks in node with a fake box; no browser, no network.",
3
+ "modules": [
4
+ "draft-keep.test.js"
5
+ ],
6
+ "seconds": {
7
+ "draft-keep.test.js": 3
8
+ }
9
+ }