create-pmos 0.698.0 → 0.700.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 +13 -7
- 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 +12 -6
- package/workspace/guide/layout.md +9 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-draft-keep.js +65 -0
- package/workspace/lib/tracker-cli.js +43 -4
- package/workspace/lib/tracker-match.js +275 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-draft-keep.js +74 -0
- package/workspace/public/pm/cozy-nav.js +1 -0
- package/workspace/public/pm/draft-keep.js +151 -0
- package/workspace/public/pm/home-chat.js +1 -1
- package/workspace/public/pm/premium-vw-page.js +1 -0
- package/workspace/test-lists/forms-keep-drafts.json +9 -0
- package/workspace/test-lists/tracker-match.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.700.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,15 +34,21 @@
|
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
36
|
{
|
|
37
|
-
"v": "0.
|
|
38
|
-
"at": "2026-11-22T10:
|
|
37
|
+
"v": "0.700.0",
|
|
38
|
+
"at": "2026-11-22T10:32:18.156Z",
|
|
39
39
|
"f": 4,
|
|
40
40
|
"prs": [
|
|
41
41
|
{
|
|
42
|
-
"n":
|
|
43
|
-
"t": "
|
|
44
|
-
"s": "
|
|
45
|
-
"k": "
|
|
42
|
+
"n": 1518,
|
|
43
|
+
"t": "Forms keep drafts when panels close",
|
|
44
|
+
"s": "Forms keep drafts when panels close",
|
|
45
|
+
"k": "new"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"n": 1529,
|
|
49
|
+
"t": "PMOS proposes each unlinked initiative's Jira work under its ✦ (A465)",
|
|
50
|
+
"s": "PMOS proposes each unlinked initiative's Jira work under its ✦ (A465)",
|
|
51
|
+
"k": "new"
|
|
46
52
|
}
|
|
47
53
|
]
|
|
48
54
|
},
|
package/payload/KIT-VERSION
CHANGED
|
@@ -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:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T10:32:15Z"}
|
|
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:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T10:32:15Z"}
|
|
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:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T10:32:15Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"v": "0.
|
|
4
|
-
"at": "2026-11-22T10:
|
|
3
|
+
"v": "0.700.0",
|
|
4
|
+
"at": "2026-11-22T10:32:18.156Z",
|
|
5
5
|
"f": 4,
|
|
6
6
|
"prs": [
|
|
7
7
|
{
|
|
8
|
-
"n":
|
|
9
|
-
"t": "
|
|
10
|
-
"s": "
|
|
11
|
-
"k": "
|
|
8
|
+
"n": 1518,
|
|
9
|
+
"t": "Forms keep drafts when panels close",
|
|
10
|
+
"s": "Forms keep drafts when panels close",
|
|
11
|
+
"k": "new"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"n": 1529,
|
|
15
|
+
"t": "PMOS proposes each unlinked initiative's Jira work under its ✦ (A465)",
|
|
16
|
+
"s": "PMOS proposes each unlinked initiative's Jira work under its ✦ (A465)",
|
|
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
|
+
}
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* pmos tracker done [--moved N] [--left N] [--not-found N] [--json]
|
|
5
5
|
* pmos tracker status [--json]
|
|
6
6
|
* pmos tracker sync [--json | --number] how much of PMOS matches the last Jira read here (initiative tracker-dates-owners-sync, A439)
|
|
7
|
+
* pmos tracker match [--json | --number | --file] the initiatives the Jira read does not cover, and the epic or ticket that most likely
|
|
8
|
+
* holds each one's work (initiative link-tracker-work, A465; lib/tracker-match.js). --file files them
|
|
9
|
+
* under each initiative's ✦ for the PM's ✓; `done` files them after every read
|
|
7
10
|
* The repository is the one this terminal is in. The record is kept in the per-user runtime folder (lib/tracker-read.js),
|
|
8
11
|
* never in a repository. This command calls no tracker and moves no item.
|
|
9
12
|
*/
|
|
@@ -11,14 +14,16 @@ const { execFileSync } = require('child_process');
|
|
|
11
14
|
const stateRoot = require('./state-root');
|
|
12
15
|
const TR = require('./tracker-read.js');
|
|
13
16
|
|
|
14
|
-
const COMMANDS = { tracker: ['done', 'status', 'sync'] };
|
|
17
|
+
const COMMANDS = { tracker: ['done', 'status', 'sync', 'match'] };
|
|
15
18
|
const USAGE = [
|
|
16
19
|
'usage: pmos tracker done|status — when tracker items were last read for this repository',
|
|
17
20
|
' pmos tracker done [--moved N] [--left N] [--not-found N] the tracker-refresh skill runs this as its last step',
|
|
18
21
|
' pmos tracker status when the last read finished, and what it found',
|
|
19
22
|
' pmos tracker sync [--number] how much of PMOS matches the last Jira read: state, done day, owner',
|
|
23
|
+
' pmos tracker match [--number | --file] the initiatives the Jira read does not cover, and the epic or ticket',
|
|
24
|
+
' that most likely holds their work; --file proposes it under each ✦',
|
|
20
25
|
' every command: [--json]',
|
|
21
|
-
'This command never calls a tracker and moves no item.',
|
|
26
|
+
'This command never calls a tracker and moves no item. Only the PM\'s ✓ links a proposed match.',
|
|
22
27
|
];
|
|
23
28
|
|
|
24
29
|
function parseArgs(argv) {
|
|
@@ -28,7 +33,7 @@ function parseArgs(argv) {
|
|
|
28
33
|
if (!t.startsWith('--')) { out._.push(t); continue; }
|
|
29
34
|
const eq = t.indexOf('=');
|
|
30
35
|
const key = eq > 0 ? t.slice(2, eq) : t.slice(2);
|
|
31
|
-
if (key === 'json' || key === 'help' || key === 'number') out[key] = true;
|
|
36
|
+
if (key === 'json' || key === 'help' || key === 'number' || key === 'file') out[key] = true;
|
|
32
37
|
else if (eq > 0) out[key] = t.slice(eq + 1);
|
|
33
38
|
else if (argv[i + 1] !== undefined) out[key] = argv[++i];
|
|
34
39
|
else out[key] = '';
|
|
@@ -59,10 +64,16 @@ function run(argv, { say = console.log, env = process.env, stateDir, cwd = proce
|
|
|
59
64
|
counts[key] = n;
|
|
60
65
|
}
|
|
61
66
|
const rec = TR.write(dir, root, counts, now());
|
|
62
|
-
|
|
67
|
+
// link-tracker-work (A465): after each read, the initiatives the read does not cover get their likely epic or ticket under the ✦
|
|
68
|
+
let m = null;
|
|
69
|
+
try { m = require('./tracker-match.js').file(root); } catch (e) { m = { ok: false, error: String((e && e.message) || e), filed: [] }; }
|
|
70
|
+
logMatch(root, m);
|
|
71
|
+
const n = m && m.ok ? m.filed.length : 0;
|
|
72
|
+
out({ ok: true, ...rec, matched: n }, `tracker items read at ${rec.read_at} for ${rec.root}. The freshness line shows it.${n ? ` PMOS proposes the Jira work of ${n} initiative${n === 1 ? '' : 's'} under their ✦.` : ''}`);
|
|
63
73
|
return 0;
|
|
64
74
|
}
|
|
65
75
|
if (sub === 'sync') return sync(root, a, say);
|
|
76
|
+
if (sub === 'match') return match(root, a, say);
|
|
66
77
|
const rec = TR.read(dir, root);
|
|
67
78
|
out({ ok: true, record: rec }, rec ? `tracker items last read at ${rec.read_at} (moved ${rec.moved ?? '?'}, left ${rec.left ?? '?'}, not found ${rec.not_found ?? '?'})` : 'tracker items not read yet for this repository');
|
|
68
79
|
return 0;
|
|
@@ -84,4 +95,32 @@ function sync(root, a, say) {
|
|
|
84
95
|
return 0;
|
|
85
96
|
}
|
|
86
97
|
|
|
98
|
+
/** One `[tracker-match]` line per run (the health log of link-tracker-work). */
|
|
99
|
+
function logMatch(root, m) {
|
|
100
|
+
const s = (m && m.scan) || {};
|
|
101
|
+
console.log(`[tracker-match] root=${root} with_tasks=${s.withTasks ?? 'none'} linked=${s.linked ?? 'none'} pct=${s.pct == null ? 'none' : s.pct} filed=${m && m.ok ? m.filed.length : 0}${m && !m.ok && m.error ? ' error=' + JSON.stringify(m.error) : ''}`);
|
|
102
|
+
}
|
|
103
|
+
/** `pmos tracker match`: the initiatives the Jira read does not cover, and their likely tracker work (lib/tracker-match.js). Reads the
|
|
104
|
+
* task ledger, the records and the stored Jira reads. Writes only with --file: `propose` lines in the proposals ledger. --number prints
|
|
105
|
+
* the percent of initiatives with tasks that the read covers alone on the last line (the health read). */
|
|
106
|
+
function match(root, a, say) {
|
|
107
|
+
const TM = require('./tracker-match.js');
|
|
108
|
+
const m = a.file ? TM.file(root) : { ok: true, filed: [], scan: TM.scan(root) };
|
|
109
|
+
logMatch(root, m);
|
|
110
|
+
const s = m.scan;
|
|
111
|
+
if (a.json) { say(JSON.stringify({ ok: m.ok, root, ...(m.error ? { error: m.error } : {}), withTasks: s.withTasks, linked: s.linked, pct: s.pct, reads: s.reads, filed: m.filed, unlinked: s.unlinked })); return m.ok ? 0 : 1; }
|
|
112
|
+
if (a.number) { say(s.pct === null ? 'none' : String(s.pct)); return 0; }
|
|
113
|
+
if (!m.ok) { say(`✗ ${m.error}`); return 1; }
|
|
114
|
+
if (s.pct === null) { say('No initiative here has tasks yet.'); return 0; }
|
|
115
|
+
say(`${s.pct}% of initiatives with tasks are linked to their Jira work (${s.linked} of ${s.withTasks}).${s.reads ? '' : ' No Jira read is stored here yet, so PMOS has nothing to match against.'}`);
|
|
116
|
+
for (const u of s.unlinked) {
|
|
117
|
+
if (!u.open) continue;
|
|
118
|
+
say(` ${u.ini} · ${u.title.slice(0, 60)}`);
|
|
119
|
+
if (!u.matches.length) { say(' no match in the stored Jira reads'); continue; }
|
|
120
|
+
for (const x of u.matches) say(` ${TM.reasonOf(x, u.tasks)}`);
|
|
121
|
+
}
|
|
122
|
+
if (a.file) say(m.filed.length ? `Proposed under the ✦ of ${m.filed.length} initiative${m.filed.length === 1 ? '' : 's'}. Nothing is linked before the PM's ✓.` : 'Nothing new to propose.');
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
87
126
|
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* tracker-match.js — every initiative linked to its tracker work (bet A465, initiative link-tracker-work; proof T64, 2026-11-22).
|
|
3
|
+
*
|
|
4
|
+
* WHY. PMOS takes progress, done days, owners and dates from Jira only for an initiative whose tracker work it knows: tickets it pushed,
|
|
5
|
+
* a Jira epic linked on the page or named in the record, or tasks whose titles start with a ticket key (lib/jira-status.js queryFor).
|
|
6
|
+
* On 22 Nov 25 of 60 initiatives with tasks had none of these (CAS 6 of 9, Scarlet 10 of 20, idpf 8 of 24), so the daily Jira read
|
|
7
|
+
* skipped them. Here PMOS finds the epic or ticket that most likely holds such an initiative's work, in the Jira reads it already
|
|
8
|
+
* stores, and files it under the initiative's ✦ for the PM's one ✓.
|
|
9
|
+
*
|
|
10
|
+
* tokens(text) PURE → [word] the words a match compares: lower case, no stop words, no keys, no numbers
|
|
11
|
+
* candidatesOf(readings, claimed) PURE → [candidate] epics (with their children) and tickets with no epic, from stored readings
|
|
12
|
+
* matchOne(ini, candidates, o) PURE → [match] the candidates that hold this initiative's work, best first, at most MAX
|
|
13
|
+
* scan(root, o) → { initiatives, withTasks, linked, pct, unlinked: [{ ini, title, matches }] }
|
|
14
|
+
* proposalOf(u, o) PURE → the propose line for one unlinked initiative with matches (lib/proposals.js ledger)
|
|
15
|
+
* file(root, o) → { filed, skipped, dir } appends the proposals that changed; nothing when no state folder
|
|
16
|
+
* proposalsDir(root) → the folder of proposals.jsonl, as the workspace server resolves it, or null
|
|
17
|
+
*
|
|
18
|
+
* THE MATCH. The initiative's name against the epic's name (or the ticket's summary), and the initiative's task titles against the
|
|
19
|
+
* epic's children. A candidate is proposed when the names share 2 or more words and at least half their words, or 2 or more task
|
|
20
|
+
* titles match children, or 1 task title matches and the names share a third of their words. A task title matches a child when they
|
|
21
|
+
* share 2 or more words and half their words.
|
|
22
|
+
* DATES. A candidate whose sprints (or resolution days) end more than SLACK_DAYS before the initiative's first date, or start more
|
|
23
|
+
* than SLACK_DAYS after its last, is not proposed. With no date on either side, dates decide nothing.
|
|
24
|
+
* CLAIMED. A key the Jira read of another initiative covers (its pushed tickets, its epics, its task keys and every ticket its stored
|
|
25
|
+
* read returned) is never a candidate: a ticket belongs to one initiative.
|
|
26
|
+
* THE PROPOSAL. group `found`, type `tasks`, section `check` (its own ✓, never Keep all), one item per key with `jira`. The existing ✓
|
|
27
|
+
* path (lib/routes-proposals.js applyOne) links the keys as the initiative's Jira epics (POST /api/boards/ini-epics), with Undo, and
|
|
28
|
+
* from the next read the initiative is in epic mode. A ✕ on the proposal or on one item refuses those keys for that initiative for
|
|
29
|
+
* good; the rest can come back.
|
|
30
|
+
*
|
|
31
|
+
* BOUNDARY. No network and no write to Jira. The only write is `propose` lines in the proposals ledger, and only from `file`.
|
|
32
|
+
*/
|
|
33
|
+
const fs = require('fs');
|
|
34
|
+
const path = require('path');
|
|
35
|
+
const crypto = require('crypto');
|
|
36
|
+
|
|
37
|
+
const MAX = 3;
|
|
38
|
+
const SLACK_DAYS = 30;
|
|
39
|
+
const LOG = '[tracker-match]';
|
|
40
|
+
const CLOSED = new Set(['Done', "Won't do", 'Archived']);
|
|
41
|
+
const STOP = new Set(('the and for with from into onto that this these those are was were will would should could can not but all any '
|
|
42
|
+
+ 'its our your their his her has have had per via out off new old one two use using used make made get set add adds added update '
|
|
43
|
+
+ 'updates fix fixes task tasks story stories epic epics ticket tickets item items work phase part page pages team when then than '
|
|
44
|
+
+ 'also more less each every some only just like what which who how why yet very').split(' '));
|
|
45
|
+
const KEY_RE = /^[A-Z][A-Z0-9_]{0,30}-\d{1,9}$/;
|
|
46
|
+
const hash = (s) => crypto.createHash('sha1').update(String(s)).digest('hex').slice(0, 10);
|
|
47
|
+
const one = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).trimEnd() + '…' : t; };
|
|
48
|
+
const dn = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? Math.round(Date.UTC(+m[1], +m[2] - 1, +m[3]) / 864e5) : null; };
|
|
49
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
50
|
+
const md = (n) => { const d = new Date(n * 864e5); return MON[d.getUTCMonth()] + ' ' + d.getUTCDate(); };
|
|
51
|
+
|
|
52
|
+
/** The words a match compares. A leading or embedded ticket key, a number and a stop word are not words of the work. */
|
|
53
|
+
function tokens(text) {
|
|
54
|
+
const out = new Set();
|
|
55
|
+
for (const raw of String(text == null ? '' : text).replace(/\b[A-Z][A-Z0-9_]{0,30}-\d{1,9}\b/g, ' ').toLowerCase().split(/[^a-z0-9]+/)) {
|
|
56
|
+
if (raw.length < 3 || /^\d+$/.test(raw) || STOP.has(raw)) continue;
|
|
57
|
+
out.add(raw.length > 4 && raw.endsWith('s') && !raw.endsWith('ss') ? raw.slice(0, -1) : raw);
|
|
58
|
+
}
|
|
59
|
+
return [...out];
|
|
60
|
+
}
|
|
61
|
+
/** { shared: [word], sim } — the words both sides have, and shared ÷ all words of both (Jaccard). */
|
|
62
|
+
function overlap(a, b) {
|
|
63
|
+
const A = new Set(a), B = new Set(b);
|
|
64
|
+
const shared = [...A].filter((w) => B.has(w));
|
|
65
|
+
const all = new Set([...A, ...B]).size;
|
|
66
|
+
return { shared, sim: all ? shared.length / all : 0 };
|
|
67
|
+
}
|
|
68
|
+
const sameWork = (a, b) => { const o = overlap(a, b); return o.shared.length >= 2 && o.sim >= 0.5; };
|
|
69
|
+
|
|
70
|
+
/** PURE. The candidates in a set of readings (lib/jira-status.js reading shape). An epic carries the readings under it; a ticket with no
|
|
71
|
+
* parent stands for itself. A key in `claimed` (and an epic in it, with its children) is left out. */
|
|
72
|
+
function candidatesOf(readings, claimed = new Set()) {
|
|
73
|
+
const by = new Map();
|
|
74
|
+
const cand = (key) => { if (!by.has(key)) by.set(key, { key, kind: 'epic', name: '', children: [], dates: [], src: null, url: null }); return by.get(key); };
|
|
75
|
+
for (const { r, src } of readings) {
|
|
76
|
+
if (!r || !KEY_RE.test(String(r.key || '')) || claimed.has(r.key)) continue;
|
|
77
|
+
const ds = [r.sprint && r.sprint.start, r.sprint && r.sprint.end, r.resolved].map(dn).filter((x) => x != null);
|
|
78
|
+
if (/^epic$/i.test(String(r.type || ''))) {
|
|
79
|
+
const c = cand(r.key); c.name = c.name || String(r.summary || ''); c.src = c.src || src; c.url = c.url || r.url || null;
|
|
80
|
+
c.dates.push(...ds);
|
|
81
|
+
} else if (r.parent && KEY_RE.test(r.parent)) {
|
|
82
|
+
if (claimed.has(r.parent)) continue;
|
|
83
|
+
const c = cand(r.parent); if (!c.name && r.parentName) c.name = String(r.parentName); c.src = c.src || src;
|
|
84
|
+
c.children.push(r); c.dates.push(...ds);
|
|
85
|
+
} else if (!/sub-?task/i.test(String(r.type || ''))) {
|
|
86
|
+
if (by.has(r.key)) continue;
|
|
87
|
+
by.set(r.key, { key: r.key, kind: 'ticket', name: String(r.summary || ''), children: [r], dates: ds, src, url: r.url || null });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return [...by.values()].filter((c) => c.name || c.children.length);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** PURE. ini: { id, title, tasks: [title], start, end (day numbers or null) }. → [{ key, kind, name, shared, taskHits, score, from, to, src, url }] */
|
|
94
|
+
function matchOne(ini, candidates, o = {}) {
|
|
95
|
+
const refused = o.refused || new Set();
|
|
96
|
+
const iniTok = tokens(ini.title);
|
|
97
|
+
const taskTok = (ini.tasks || []).map(tokens).filter((t) => t.length >= 2);
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const c of candidates) {
|
|
100
|
+
if (refused.has(c.key)) continue;
|
|
101
|
+
const { shared, sim } = overlap(iniTok, tokens(c.name));
|
|
102
|
+
const kids = c.children.map((r) => tokens(r.summary));
|
|
103
|
+
const taskHits = taskTok.filter((t) => kids.some((k) => sameWork(t, k))).length;
|
|
104
|
+
const ok = (shared.length >= 2 && sim >= 0.5) || taskHits >= 2 || (taskHits >= 1 && shared.length >= 1 && sim >= 1 / 3);
|
|
105
|
+
if (!ok) continue;
|
|
106
|
+
const from = c.dates.length ? Math.min(...c.dates) : null, to = c.dates.length ? Math.max(...c.dates) : null;
|
|
107
|
+
if (from != null && ini.end != null && ini.start != null) {
|
|
108
|
+
if (to < ini.start - SLACK_DAYS || from > ini.end + SLACK_DAYS) continue;
|
|
109
|
+
}
|
|
110
|
+
out.push({ key: c.key, kind: c.kind, name: one(c.name, 100), shared, taskHits, score: sim + 0.25 * taskHits, from, to, src: c.src, url: c.url });
|
|
111
|
+
}
|
|
112
|
+
return out.sort((a, b) => b.score - a.score || a.key.localeCompare(b.key)).slice(0, o.max || MAX);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Why this candidate, in one line a PM can check. */
|
|
116
|
+
function reasonOf(m, nTasks) {
|
|
117
|
+
const bits = [];
|
|
118
|
+
if (m.shared.length) bits.push(`shares ${m.shared.map((w) => '"' + w + '"').join(', ')} with the name`);
|
|
119
|
+
if (m.taskHits) bits.push(`holds ${m.taskHits} of its ${nTasks} task${nTasks === 1 ? '' : 's'}`);
|
|
120
|
+
if (m.from != null) bits.push(m.from === m.to ? `dated ${md(m.from)}` : `sprints ${md(m.from)} to ${md(m.to)}`);
|
|
121
|
+
return `${m.kind === 'epic' ? 'Epic' : 'Ticket'} ${m.key}${m.name ? ' "' + m.name + '"' : ''} ${bits.join('; ')}.`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* ── the repository ── */
|
|
125
|
+
function JSm() { return require('./jira-status.js'); }
|
|
126
|
+
function JTm() { return require('./jira-tickets.js'); }
|
|
127
|
+
function TJm() { return require('./task-jira.js'); }
|
|
128
|
+
|
|
129
|
+
/** The folder of proposals.jsonl, as the workspace server's stateDirFor resolves it (pmos/state, state or .pmos), or null. */
|
|
130
|
+
function proposalsDir(root) {
|
|
131
|
+
for (const rel of [['pmos', 'state'], ['state'], ['.pmos']]) {
|
|
132
|
+
const d = path.join(root, ...rel);
|
|
133
|
+
try { if (fs.statSync(d).isDirectory()) return d; } catch { /* next */ }
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
/** The stored Jira reads of the repository: every snapshot in <state>/tracker/jira except the ticket drafts and the sprint notes. */
|
|
138
|
+
function storedReads(root) {
|
|
139
|
+
let dir, names = [];
|
|
140
|
+
try { dir = JTm().jiraDir(root); names = fs.readdirSync(dir); } catch { return []; }
|
|
141
|
+
const out = [];
|
|
142
|
+
for (const n of names.sort()) {
|
|
143
|
+
if (!n.endsWith('.md') || n.endsWith('-tickets.md') || n === '_sprint-notes.md') continue;
|
|
144
|
+
const id = n.slice(0, -3);
|
|
145
|
+
const s = JSm().readSnapshot(root, id);
|
|
146
|
+
if (s) out.push({ id, src: JTm().relOf(root, path.join(dir, n)), snap: s });
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/** Every initiative of the repository: its record (title) and its tasks (titles, dates, board). */
|
|
151
|
+
function initiativesOf(root, lines) {
|
|
152
|
+
const by = new Map();
|
|
153
|
+
const ini = (id) => { if (!by.has(id)) by.set(id, { id, title: '', tasks: new Map(), board: '' }); return by.get(id); };
|
|
154
|
+
let names = [];
|
|
155
|
+
try { names = fs.readdirSync(JTm().stateDirOf(root) ? path.join(JTm().stateDirOf(root), 'initiatives') : '').filter((n) => n.endsWith('.md') && n !== 'README.md' && n !== 'index.md'); } catch { names = []; }
|
|
156
|
+
for (const n of names) ini(n.slice(0, -3));
|
|
157
|
+
const removed = new Set();
|
|
158
|
+
for (const e of lines || []) {
|
|
159
|
+
if (!e || typeof e.task !== 'string') continue;
|
|
160
|
+
if (e.kind === 'task' && typeof e.initiative === 'string' && e.initiative) {
|
|
161
|
+
const I = ini(e.initiative); if (!I.board && typeof e.board === 'string') I.board = e.board;
|
|
162
|
+
if (!I.tasks.has(e.task)) I.tasks.set(e.task, { title: String(e.title || ''), state: e.state || 'To do', start: e.start || null, due: e.due || null });
|
|
163
|
+
} else if (e.kind === 'task-update' || e.kind === 'task-remove' || e.kind === 'task-restore') {
|
|
164
|
+
for (const I of by.values()) {
|
|
165
|
+
const t = I.tasks.get(e.task); if (!t) continue;
|
|
166
|
+
if (e.kind === 'task-remove') removed.add(e.task); else if (e.kind === 'task-restore') removed.delete(e.task);
|
|
167
|
+
else {
|
|
168
|
+
if (typeof e.title === 'string' && e.title.trim()) t.title = e.title.trim();
|
|
169
|
+
if (typeof e.state === 'string' && e.state) t.state = e.state;
|
|
170
|
+
if (typeof e.start === 'string') t.start = e.start || null;
|
|
171
|
+
if (typeof e.due === 'string') t.due = e.due || null;
|
|
172
|
+
if (typeof e.initiative === 'string' && e.initiative && e.initiative !== I.id) { ini(e.initiative).tasks.set(e.task, t); I.tasks.delete(e.task); }
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (const I of by.values()) {
|
|
179
|
+
for (const k of removed) I.tasks.delete(k);
|
|
180
|
+
const fm = JTm().recordFm(root, I.id);
|
|
181
|
+
I.title = (fm && fm.title) || I.id.replace(/[-_.]+/g, ' ');
|
|
182
|
+
}
|
|
183
|
+
return [...by.values()];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** → { initiatives, withTasks, linked, pct, unlinked: [{ ini, title, board, open, matches }] }. o: { refusedOf(ini) → Set of keys } */
|
|
187
|
+
function scan(root, o = {}) {
|
|
188
|
+
const lines = TJm().readLines(root);
|
|
189
|
+
const byIni = TJm().keysByInitiative(lines);
|
|
190
|
+
const inis = initiativesOf(root, lines);
|
|
191
|
+
const reads = storedReads(root);
|
|
192
|
+
const claimed = new Set();
|
|
193
|
+
const linked = new Set();
|
|
194
|
+
for (const I of inis) {
|
|
195
|
+
let q = null;
|
|
196
|
+
try { q = JSm().queryFor(root, I.id, byIni); } catch { q = null; }
|
|
197
|
+
if (!q || !q.ok || !q.linked) continue;
|
|
198
|
+
linked.add(I.id);
|
|
199
|
+
for (const k of [...(q.keys || []), ...(q.epics || [])]) claimed.add(k);
|
|
200
|
+
const own = reads.find((x) => x.id === I.id);
|
|
201
|
+
if (own) for (const k of own.snap.tickets.keys()) claimed.add(k);
|
|
202
|
+
}
|
|
203
|
+
const readings = [];
|
|
204
|
+
for (const x of reads) for (const r of x.snap.tickets.values()) readings.push({ r, src: x.src });
|
|
205
|
+
const candidates = candidatesOf(readings, claimed);
|
|
206
|
+
const withTasks = inis.filter((I) => [...I.tasks.values()].some((t) => t.state !== 'Archived'));
|
|
207
|
+
const unlinked = [];
|
|
208
|
+
for (const I of inis) {
|
|
209
|
+
if (linked.has(I.id)) continue;
|
|
210
|
+
const tasks = [...I.tasks.values()].filter((t) => t.state !== 'Archived');
|
|
211
|
+
const open = !tasks.length || tasks.some((t) => !CLOSED.has(t.state));
|
|
212
|
+
const days = tasks.flatMap((t) => [dn(t.start), dn(t.due)]).filter((x) => x != null);
|
|
213
|
+
const iv = { id: I.id, title: I.title, tasks: tasks.map((t) => t.title), start: days.length ? Math.min(...days) : null, end: days.length ? Math.max(...days) : null };
|
|
214
|
+
const matches = open ? matchOne(iv, candidates, { refused: o.refusedOf ? o.refusedOf(I.id) : null }) : [];
|
|
215
|
+
unlinked.push({ ini: I.id, title: I.title, board: I.board, tasks: tasks.length, open, matches });
|
|
216
|
+
}
|
|
217
|
+
const nLinked = withTasks.filter((I) => linked.has(I.id)).length;
|
|
218
|
+
return { initiatives: inis.length, withTasks: withTasks.length, linked: nLinked, pct: withTasks.length ? Math.floor((nLinked / withTasks.length) * 100) : null, reads: reads.length, unlinked };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** PURE. The propose line for one unlinked initiative with matches. Its id names the initiative and the keys, so a kept match is never
|
|
222
|
+
* hidden by a later one, and the same match filed again is the same proposal. */
|
|
223
|
+
function proposalOf(u) {
|
|
224
|
+
const keys = u.matches.map((m) => m.key);
|
|
225
|
+
const best = u.matches[0];
|
|
226
|
+
const srcs = [...new Set(u.matches.map((m) => m.src).filter(Boolean))].slice(0, 4);
|
|
227
|
+
return {
|
|
228
|
+
kind: 'propose', ini: u.ini, board: u.board || '', run: 'tracker-match', id: 'tm-' + hash(u.ini + '|' + keys.join(',')),
|
|
229
|
+
group: 'found', type: 'tasks', section: 'check', title: 'Link to its Jira work',
|
|
230
|
+
why: one(`No Jira epic or ticket is linked, so its progress and dates do not come from the tracker. ${reasonOf(best, u.tasks)}`, 300),
|
|
231
|
+
sources: srcs.length ? srcs.map((s) => ({ label: 'Stored Jira read', ref: s })) : [{ label: 'Stored Jira read' }],
|
|
232
|
+
items: u.matches.map((m) => ({ id: m.key, jira: m.key, title: one(m.key + (m.name ? ' · ' + m.name : ''), 140), why: one(reasonOf(m, u.tasks), 300), kind: m.kind, ...(m.url ? { ref: one(m.url, 500) } : {}) })),
|
|
233
|
+
data: {},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The keys the PM refused per initiative: every item of a tracker-match proposal whose ✕ is on file (the whole proposal or that item). */
|
|
238
|
+
function refusedFrom(PR, lines, F) {
|
|
239
|
+
const out = new Map();
|
|
240
|
+
for (const l of lines) {
|
|
241
|
+
if (l.kind !== 'propose' || l.run !== 'tracker-match' || typeof l.ini !== 'string') continue;
|
|
242
|
+
const p = { ...l, items: Array.isArray(l.items) ? l.items : [] };
|
|
243
|
+
const whole = F.drops.has(PR.sigOf(p));
|
|
244
|
+
for (const x of p.items) {
|
|
245
|
+
if (!x || !x.jira) continue;
|
|
246
|
+
if (whole || F.drops.has(PR.itemSig(p, x))) { if (!out.has(l.ini)) out.set(l.ini, new Set()); out.get(l.ini).add(x.jira); }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Files the proposals that changed. → { ok, filed: [{ ini, id, keys }], skipped, dir, scan } */
|
|
253
|
+
function file(root, o = {}) {
|
|
254
|
+
const dir = o.dir || proposalsDir(root);
|
|
255
|
+
const PR = require('./proposals.js');
|
|
256
|
+
const ledger = dir ? PR.ledgerFile(dir) : null;
|
|
257
|
+
const lines = ledger ? PR.readLines(ledger) : [];
|
|
258
|
+
const F = PR.fold(lines);
|
|
259
|
+
const refused = refusedFrom(PR, lines, F);
|
|
260
|
+
const s = scan(root, { refusedOf: (ini) => refused.get(ini) || null });
|
|
261
|
+
if (!dir) return { ok: false, error: 'no state folder (pmos/state, state or .pmos) in this repository to file proposals in', filed: [], skipped: 0, dir: null, scan: s };
|
|
262
|
+
const kept = new Set(); for (const k of F.kept) if (!F.undone.has(k.batch)) for (const id of k.ids) kept.add(id);
|
|
263
|
+
const filed = []; let skipped = 0;
|
|
264
|
+
for (const u of s.unlinked) {
|
|
265
|
+
if (!u.matches.length) continue;
|
|
266
|
+
const p = proposalOf(u);
|
|
267
|
+
const was = F.props.get(p.id);
|
|
268
|
+
if (kept.has(p.id) || (was && PR.sigOf(was) === PR.sigOf(p))) { skipped++; continue; }
|
|
269
|
+
PR.append(dir, { by: 'pmos:tracker-match' }, p);
|
|
270
|
+
filed.push({ ini: u.ini, id: p.id, keys: p.items.map((x) => x.jira) });
|
|
271
|
+
}
|
|
272
|
+
return { ok: true, filed, skipped, dir, scan: s };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
module.exports = { MAX, SLACK_DAYS, LOG, tokens, overlap, candidatesOf, matchOne, reasonOf, scan, proposalOf, file, proposalsDir, storedReads, initiativesOf };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.700.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.700.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "link-tracker-work (A465): initiatives the Jira read does not cover get their likely epic or ticket proposed under the ✦ (lib/tracker-match.js, pmos tracker match).",
|
|
3
|
+
"modules": [
|
|
4
|
+
"tracker-match.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"tracker-match.test.js": 1
|
|
8
|
+
}
|
|
9
|
+
}
|