create-pmos 0.711.0 → 0.713.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 +88 -40
- package/payload/KIT-VERSION +1 -1
- package/payload/design-system/ui/README.md +1 -1
- package/payload/design-system/ui/components/State/README.md +21 -0
- package/payload/design-system/ui/components/State/preview.html +8 -0
- package/payload/design-system/ui/components/bundle.css +12 -0
- package/payload/design-system/ui/interactions.md +2 -0
- 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/bin/back-place-health.js +70 -0
- package/workspace/changelog.json +87 -2
- package/workspace/design-system/ui/README.md +1 -1
- package/workspace/design-system/ui/components/State/README.md +21 -0
- package/workspace/design-system/ui/components/State/preview.html +8 -0
- package/workspace/design-system/ui/components/bundle.css +12 -0
- package/workspace/design-system/ui/interactions.md +2 -0
- package/workspace/guide/breakdown.md +20 -1
- package/workspace/guide/claude-proposes.md +5 -1
- package/workspace/guide/cli.md +10 -1
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/initiatives-and-next-steps.md +13 -0
- package/workspace/guide/layout.md +10 -3
- package/workspace/guide/routine.md +10 -2
- package/workspace/guide/settings-and-switches.md +4 -0
- package/workspace/lib/briefing-premium-products.js +16 -2
- package/workspace/lib/changed-mark.js +34 -0
- package/workspace/lib/launch-cli.js +43 -5
- package/workspace/lib/launch-tiers.js +143 -0
- package/workspace/lib/needs-providers.js +1 -0
- package/workspace/lib/parked-cli.js +105 -0
- package/workspace/lib/parked-reasons.js +245 -0
- package/workspace/lib/pmos-verbs.js +4 -1
- package/workspace/lib/prefs-sync.js +138 -0
- package/workspace/lib/product-dots.js +60 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-briefing-premium.js +11 -1
- package/workspace/lib/routes-prefs.js +56 -0
- package/workspace/lib/routes-strategy-card.js +53 -0
- package/workspace/lib/routes-use-log.js +24 -3
- package/workspace/lib/routine-sentence.js +250 -0
- package/workspace/lib/strategy-card.js +133 -0
- package/workspace/lib/unused-controls.js +178 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/back-place.js +87 -0
- package/workspace/public/pm/bd-backlog.css +1 -1
- package/workspace/public/pm/bd-backlog.js +9 -3
- package/workspace/public/pm/bd-pop-ds.css +10 -0
- package/workspace/public/pm/bd-pop-ds.js +27 -3
- package/workspace/public/pm/bd-strategy.js +85 -0
- package/workspace/public/pm/bd-views.js +2 -1
- package/workspace/public/pm/changed-mark.css +7 -0
- package/workspace/public/pm/changed-mark.js +117 -0
- package/workspace/public/pm/cozy-home.css +7 -0
- package/workspace/public/pm/cozy-pick.css +12 -0
- package/workspace/public/pm/cozy-pop-work.css +10 -1
- package/workspace/public/pm/cozy-pop-work.js +201 -17
- package/workspace/public/pm/cozy-routine-job.js +50 -7
- package/workspace/public/pm/cozy-routine.css +2 -0
- package/workspace/public/pm/cozy-settings.js +21 -3
- package/workspace/public/pm/cozy-task-pop.css +7 -0
- package/workspace/public/pm/cozy-today-page.css +1 -0
- package/workspace/public/pm/cozy-viewer.css +1 -1
- package/workspace/public/pm/cozy-viewer.js +14 -2
- package/workspace/public/pm/cozy-vw-mtg.css +0 -2
- package/workspace/public/pm/cozy-vw.css +0 -1
- package/workspace/public/pm/home-app.js +21 -1
- package/workspace/public/pm/home-ask.js +19 -1
- package/workspace/public/pm/home-chat.js +16 -3
- package/workspace/public/pm/home-today.js +2 -0
- package/workspace/public/pm/ini-tasks.js +4 -1
- package/workspace/public/pm/komorebi.css +11 -0
- package/workspace/public/pm/prefs-sync.js +111 -0
- package/workspace/public/pm/premium-board.js +20 -2
- package/workspace/public/pm/premium-chart-tab.js +2 -1
- package/workspace/public/pm/premium-mtg-replay.js +4 -3
- package/workspace/public/pm/premium-report-read.js +5 -4
- package/workspace/public/pm/premium-report-tab.js +4 -3
- package/workspace/public/pm/premium-vw-backlog.css +2 -1
- package/workspace/public/pm/premium-vw-backlog.js +4 -3
- package/workspace/public/pm/premium-vw-cal.css +1 -2
- package/workspace/public/pm/premium-vw-cal.js +14 -13
- package/workspace/public/pm/premium-vw-copies.js +3 -2
- package/workspace/public/pm/premium-vw-copy.css +0 -3
- package/workspace/public/pm/premium-vw-mtg.js +12 -11
- package/workspace/public/pm/product-switcher.js +41 -0
- package/workspace/public/pm/report-orders-ui.js +2 -1
- package/workspace/public/pm/rp-parts.js +3 -2
- package/workspace/public/pm/state-blocks.js +36 -0
- package/workspace/public/pm/use-log.js +118 -1
- package/workspace/public/pm/work-select.js +92 -2
- package/workspace/public/pm/work-tree.js +70 -0
- package/workspace/public/premium-aud.html +1 -0
- package/workspace/public/premium-board.html +5 -0
- package/workspace/public/premium-buddy.html +1 -0
- package/workspace/public/premium-events.html +1 -0
- package/workspace/public/premium-goals.html +1 -0
- package/workspace/public/premium-intelligence.html +1 -0
- package/workspace/public/premium-library.html +1 -0
- package/workspace/public/premium-present.html +1 -0
- package/workspace/public/premium-rec.html +1 -0
- package/workspace/public/premium-routine.html +1 -0
- package/workspace/public/premium-viewer.html +1 -0
- package/workspace/public/premium-workflows.html +1 -0
- package/workspace/public/today.html +1 -0
- package/workspace/server.js +20 -0
- package/workspace/test-lists/back-place.json +9 -0
- package/workspace/test-lists/changed-mark.json +9 -0
- package/workspace/test-lists/launch-tiers.json +9 -0
- package/workspace/test-lists/parked-reasons.json +9 -0
- package/workspace/test-lists/prefs-follow-person.json +9 -0
- package/workspace/test-lists/product-switcher-dots.json +9 -0
- package/workspace/test-lists/routine-sentence.json +9 -0
- package/workspace/test-lists/shared-empty-states.json +9 -0
- package/workspace/test-lists/strategy-card.json +9 -0
- package/workspace/test-lists/unused-controls.json +9 -0
- package/workspace/test-lists/work-subtasks-followups.json +9 -0
|
@@ -4,20 +4,33 @@
|
|
|
4
4
|
*
|
|
5
5
|
* GET /api/use-log → { ok, keep, days, opens, uses, pages, controls } Settings › General › Use log
|
|
6
6
|
* POST /api/use-log { events } → { ok, wrote } the page side (public/pm/use-log.js), in batches
|
|
7
|
-
* POST /api/use-log/clear {} → { ok } Clear, in Settings
|
|
7
|
+
* POST /api/use-log/clear {} → { ok } Clear, in Settings (also forgets what pages showed)
|
|
8
|
+
* Hide the buttons nobody presses (idea A454; the store and the rule are lib/unused-controls.js):
|
|
9
|
+
* GET /api/use-log/hidden[?page=] → { ok, hidden: [{ page, control, at }] } the page at load; Settings › Use log
|
|
10
|
+
* POST /api/use-log/unused { page, present } → { ok, hidden, propose } what the page shows (ids), and the ✦
|
|
11
|
+
* POST /api/use-log/hide { page, controls } → { ok, hidden } Yes
|
|
12
|
+
* POST /api/use-log/show { page, controls } | { all: true } → { ok, shown } Undo, Show, Show all
|
|
13
|
+
* POST /api/use-log/decline { page, controls } → { ok, declined } No
|
|
8
14
|
* `ws` is accepted and ignored: the log is per person, across products.
|
|
9
15
|
*
|
|
10
16
|
* WHO WRITES. The PM's own pages only: a POST that carries an agent session header is refused (403; an agent does not open pages), and
|
|
11
17
|
* pm-guard requirePagePress checks the page's Origin and launch nonce. */
|
|
12
18
|
const guard = require('./pm-guard.js');
|
|
13
19
|
const UL = require('./use-log.js');
|
|
20
|
+
const UC = require('./unused-controls.js');
|
|
21
|
+
const POSTS = ['', 'clear', 'unused', 'hide', 'show', 'decline'];
|
|
14
22
|
|
|
15
23
|
async function handle(req, res, url, ctx) {
|
|
16
24
|
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
17
25
|
const what = url.pathname.replace(/^\/api\/use-log\/?/, '');
|
|
18
|
-
if (what
|
|
26
|
+
if (!POSTS.includes(what) && what !== 'hidden') return send(404, { ok: false, error: 'no such use-log route' });
|
|
19
27
|
const dir = ctx.runtimeDir || null;
|
|
20
28
|
if (what === '' && req.method === 'GET') return send(200, { ok: true, ...UL.summary(UL.readLines(dir)) });
|
|
29
|
+
if (what === 'hidden') {
|
|
30
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
|
|
31
|
+
const page = url.searchParams.get('page');
|
|
32
|
+
return send(200, { ok: true, hidden: UC.hiddenOf(UC.readStore(dir), page ? UL.pageOf(page) : '') });
|
|
33
|
+
}
|
|
21
34
|
if (req.method !== 'POST') return send(405, { ok: false, error: what ? 'POST only' : 'GET or POST' });
|
|
22
35
|
if (req.headers && req.headers['x-pmos-session']) return send(403, { ok: false, error: 'An agent session does not open pages or press buttons. Only your own use is recorded.' });
|
|
23
36
|
const rd = await ctx.readJson(req);
|
|
@@ -25,7 +38,15 @@ async function handle(req, res, url, ctx) {
|
|
|
25
38
|
const body = rd.body || {};
|
|
26
39
|
const g = guard.requirePagePress(req, body);
|
|
27
40
|
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
28
|
-
if (what === 'clear') { const r = UL.clear(dir); return r.ok ? send(200, { ok: true }) : send(500, r); }
|
|
41
|
+
if (what === 'clear') { const r = UL.clear(dir); if (r.ok) UC.clearSeen(dir); return r.ok ? send(200, { ok: true }) : send(500, r); }
|
|
42
|
+
if (what !== '') {
|
|
43
|
+
const page = UL.pageOf(body.page);
|
|
44
|
+
const r = what === 'unused' ? UC.seeAndPropose(dir, page, body.present, UL.readLines(dir))
|
|
45
|
+
: what === 'hide' ? UC.hide(dir, page, body.controls)
|
|
46
|
+
: what === 'show' ? UC.show(dir, body.all === true ? { all: true } : { page, controls: body.controls })
|
|
47
|
+
: UC.decline(dir, page, body.controls);
|
|
48
|
+
return r.ok ? send(200, r) : send(r.error.startsWith('This workspace') ? 409 : 400, r);
|
|
49
|
+
}
|
|
29
50
|
const r = UL.record(dir, body.events);
|
|
30
51
|
return r.ok ? send(200, { ok: true, wrote: r.wrote }) : send(r.error.startsWith('This workspace') ? 409 : 400, { ok: false, error: r.error });
|
|
31
52
|
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routine-sentence.js — a routine from one typed sentence (initiative routine-from-sentence, bet A144; done test
|
|
3
|
+
* planning/done-tests/routine-from-sentence.md).
|
|
4
|
+
*
|
|
5
|
+
* read(text, now?) PURE. → { ok: true, schedule: { name, cadence, day?, dayOfMonth?, date?, time, args }, words: { when, does, tells }, notes: [] }
|
|
6
|
+
* or { ok: false, ask }: one short question back, never a guess.
|
|
7
|
+
* whenWords(s) PURE. "Every Monday at 09:00", "Every other Friday at 16:00", "Every month on day 1 at 10:00", "Once, Tue 25 Nov at 12:00"
|
|
8
|
+
* count(list, now?) PURE. Schedules made from a sentence in the last 30 days.
|
|
9
|
+
* SKILL the built-in skill a sentence routine runs: report-special writes a draft and sends nothing.
|
|
10
|
+
*
|
|
11
|
+
* The route is POST /api/routine-sentence in server.js. It reads, and writes only on the PM's press (`set: true`).
|
|
12
|
+
* Times are this computer's clock, like every schedule (lib/schedule-logic.js).
|
|
13
|
+
*
|
|
14
|
+
* CLI (the health number): node routine-sentence.js count → the count on the last line. */
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
const SKILL = 'report-special';
|
|
19
|
+
const TAG = '[routine-sentence]';
|
|
20
|
+
const DAYS = { mon: 'Mon', monday: 'Mon', tue: 'Tue', tues: 'Tue', tuesday: 'Tue', wed: 'Wed', wednesday: 'Wed', thu: 'Thu', thur: 'Thu', thurs: 'Thu', thursday: 'Thu', fri: 'Fri', friday: 'Fri', sat: 'Sat', saturday: 'Sat', sun: 'Sun', sunday: 'Sun' };
|
|
21
|
+
const DAY_NAME = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
|
|
22
|
+
const DAY_IDX = { Sun: 0, Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6 };
|
|
23
|
+
const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
24
|
+
const MON_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
25
|
+
const ORD = { first: 1, second: 2, third: 3, fourth: 4, fifth: 5, tenth: 10, fifteenth: 15, twentieth: 20 };
|
|
26
|
+
const DAY_RE = '(mon(?:day)?|tue(?:s(?:day)?)?|wed(?:nesday)?|thu(?:r(?:s(?:day)?)?)?|fri(?:day)?|sat(?:urday)?|sun(?:day)?)';
|
|
27
|
+
const MONTH_RE = '(jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|june?|july?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)';
|
|
28
|
+
const TELLS = 'Nobody. PMOS drafts it; you send it.';
|
|
29
|
+
|
|
30
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
31
|
+
const hm = (h, m) => `${pad(h)}:${pad(m)}`;
|
|
32
|
+
const ymd = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
33
|
+
const dayOf = (w) => DAYS[String(w || '').toLowerCase()] || null;
|
|
34
|
+
const no = (ask) => ({ ok: false, ask });
|
|
35
|
+
|
|
36
|
+
/** Take the first match of `re` out of `st.rest` and return it (or null). */
|
|
37
|
+
function take(st, re) {
|
|
38
|
+
const m = re.exec(st.rest);
|
|
39
|
+
if (!m) return null;
|
|
40
|
+
st.rest = st.rest.slice(0, m.index) + ' ' + st.rest.slice(m.index + m[0].length);
|
|
41
|
+
return m;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The time of day, taken out of the sentence: 9am, 9:30 pm, 16:00, at 8, noon, midnight, end of day. */
|
|
45
|
+
function readTime(st) {
|
|
46
|
+
let m = take(st, /\b(?:at\s+)?(\d{1,2})[:.](\d{2})\s*(a\.?m\.?|p\.?m\.?)?(?![\w])/i);
|
|
47
|
+
if (m) {
|
|
48
|
+
let h = +m[1]; const mi = +m[2], ap = (m[3] || '').toLowerCase()[0];
|
|
49
|
+
if (h > 23 || mi > 59 || (ap && (h < 1 || h > 12))) return { bad: true };
|
|
50
|
+
if (ap === 'p' && h < 12) h += 12; if (ap === 'a' && h === 12) h = 0;
|
|
51
|
+
return { time: hm(h, mi) };
|
|
52
|
+
}
|
|
53
|
+
m = take(st, /\b(?:at\s+)?(\d{1,2})\s*(a\.?m\.?|p\.?m\.?)(?![\w])/i);
|
|
54
|
+
if (m) {
|
|
55
|
+
let h = +m[1]; const ap = m[2].toLowerCase()[0];
|
|
56
|
+
if (h < 1 || h > 12) return { bad: true };
|
|
57
|
+
if (ap === 'p' && h < 12) h += 12; if (ap === 'a' && h === 12) h = 0;
|
|
58
|
+
return { time: hm(h, 0) };
|
|
59
|
+
}
|
|
60
|
+
m = take(st, /\bat\s+(\d{1,2})\b(?!\s*(?:st|nd|rd|th|%|days?|weeks?|months?|hours?|minutes?|mins?|people|items?|risks?|tickets?)\b)/i);
|
|
61
|
+
if (m) { const h = +m[1]; if (h > 23) return { bad: true }; return { time: hm(h, 0) }; }
|
|
62
|
+
if (take(st, /\b(?:at\s+)?(?:noon|midday|lunchtime|lunch time)\b/i)) return { time: '12:00' };
|
|
63
|
+
if (take(st, /\b(?:at\s+)?midnight\b/i)) return { time: '00:00' };
|
|
64
|
+
if (take(st, /\b(?:at\s+the\s+|by\s+the\s+|at\s+|by\s+)?(?:end of (?:the )?(?:work(?:ing)? )?day|close of business|eod|cob)\b/i)) return { time: '17:00' };
|
|
65
|
+
if (take(st, /\b(?:at\s+the\s+)?start of (?:the )?(?:work(?:ing)? )?day\b/i)) return { time: '09:00' };
|
|
66
|
+
if (take(st, /\b(?:in the |each |every )?morning\b/i)) return { time: '09:00', part: true };
|
|
67
|
+
if (take(st, /\b(?:in the |each |every )?afternoon\b/i)) return { time: '14:00', part: true };
|
|
68
|
+
if (take(st, /\b(?:in the |each |every )?evening\b/i)) return { time: '18:00', part: true };
|
|
69
|
+
if (take(st, /\b(?:at |each |every )?night\b/i)) return { time: '20:00', part: true };
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The day of the month: "the 1st", "15th", "the first", "day 3". Returns a number, 'last', or null. */
|
|
74
|
+
function readDom(st) {
|
|
75
|
+
let m = take(st, /\b(?:on\s+)?(?:the\s+)?last\s+day(?:\s+of\s+(?:every|each|the)\s+month)?\b/i);
|
|
76
|
+
if (m) return 'last';
|
|
77
|
+
m = take(st, /\b(?:on\s+)?(?:the\s+)?(\d{1,2})(?:st|nd|rd|th)(?:\s+day)?(?:\s+of\s+(?:every|each|the)\s+month)?\b/i)
|
|
78
|
+
|| take(st, /\b(?:on\s+)?the\s+(\d{1,2})(?!\s*[:.]\d)(?:\s+of\s+(?:every|each|the)\s+month)?\b/i)
|
|
79
|
+
|| take(st, /\b(?:on\s+)?day\s+(\d{1,2})(?:\s+of\s+(?:every|each|the)\s+month)?\b/i);
|
|
80
|
+
if (m) return +m[1];
|
|
81
|
+
m = take(st, /\b(?:on\s+)?(?:the\s+)?(first|second|third|fourth|fifth|tenth|fifteenth|twentieth)(?:\s+day)?(?:\s+of\s+(?:every|each|the)\s+month)?\b/i);
|
|
82
|
+
if (m) return ORD[m[1].toLowerCase()];
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A one-off date: tomorrow, today, tonight, next Friday, on Friday, on 2026-12-01, on 1 December, on December 1. */
|
|
87
|
+
function readDate(st, now) {
|
|
88
|
+
const base = new Date(now); base.setHours(0, 0, 0, 0);
|
|
89
|
+
const plus = (n) => { const d = new Date(base); d.setDate(d.getDate() + n); return d; };
|
|
90
|
+
if (take(st, /\b(?:the\s+)?day after tomorrow\b/i)) return { date: plus(2) };
|
|
91
|
+
if (take(st, /\btomorrow\b/i)) return { date: plus(1) };
|
|
92
|
+
const tn = take(st, /\b(?:today|tonight|this (?:morning|afternoon|evening))\b/i);
|
|
93
|
+
if (tn) return { date: plus(0), part: /tonight|evening/i.test(tn[0]) ? '18:00' : /afternoon/i.test(tn[0]) ? '14:00' : /morning/i.test(tn[0]) ? '09:00' : null };
|
|
94
|
+
let m = take(st, /\b(?:on\s+)?(\d{4})-(\d{2})-(\d{2})\b/);
|
|
95
|
+
if (m) { const d = new Date(+m[1], +m[2] - 1, +m[3]); return d.getMonth() === +m[2] - 1 ? { date: d } : { bad: true }; }
|
|
96
|
+
m = take(st, new RegExp(`\\b(?:on\\s+)?(?:the\\s+)?(\\d{1,2})(?:st|nd|rd|th)?\\s+(?:of\\s+)?${MONTH_RE}\\b(?:\\s+(\\d{4}))?`, 'i'))
|
|
97
|
+
|| null;
|
|
98
|
+
let day, mon, yr;
|
|
99
|
+
if (m) { day = +m[1]; mon = MONTHS.indexOf(m[2].slice(0, 3).toLowerCase()); yr = m[3] ? +m[3] : null; }
|
|
100
|
+
else {
|
|
101
|
+
m = take(st, new RegExp(`\\b(?:on\\s+)?${MONTH_RE}\\s+(\\d{1,2})(?:st|nd|rd|th)?\\b(?:,?\\s+(\\d{4}))?`, 'i'));
|
|
102
|
+
if (m) { day = +m[2]; mon = MONTHS.indexOf(m[1].slice(0, 3).toLowerCase()); yr = m[3] ? +m[3] : null; }
|
|
103
|
+
}
|
|
104
|
+
if (m) {
|
|
105
|
+
let d = new Date(yr || base.getFullYear(), mon, day);
|
|
106
|
+
if (d.getMonth() !== mon) return { bad: true };
|
|
107
|
+
if (!yr && d < base) d = new Date(base.getFullYear() + 1, mon, day);
|
|
108
|
+
return { date: d };
|
|
109
|
+
}
|
|
110
|
+
m = take(st, new RegExp(`\\b(?:(next|this|on)\\s+)${DAY_RE}\\b(?!s)`, 'i'));
|
|
111
|
+
if (m) {
|
|
112
|
+
const want = DAY_IDX[dayOf(m[2])];
|
|
113
|
+
let n = (want - base.getDay() + 7) % 7;
|
|
114
|
+
if (n === 0 && /next/i.test(m[1])) n = 7;
|
|
115
|
+
return { date: plus(n), sameDay: n === 0 };
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Clean what is left of the sentence into the instruction. */
|
|
121
|
+
function cleanRest(s) {
|
|
122
|
+
let t = String(s || '').replace(/\s+/g, ' ').replace(/\s+([,.;:!?])/g, '$1').trim();
|
|
123
|
+
for (let i = 0; i < 4; i++) {
|
|
124
|
+
const before = t;
|
|
125
|
+
t = t.replace(/^[\s,.;:–—-]+|[\s,;:–—-]+$/g, '')
|
|
126
|
+
.replace(/^(?:at|on|and|then|to|please|pmos,?|can you|could you|i want you to|i'd like you to|remind me to)\b\s*/i, (x) => (/^remind me to/i.test(x) ? 'Remind me to ' : ''))
|
|
127
|
+
.replace(/\s*\b(?:please|thanks?|thank you)[.!]?$/i, '')
|
|
128
|
+
.trim();
|
|
129
|
+
if (t === before) break;
|
|
130
|
+
}
|
|
131
|
+
t = t.replace(/^[,.;:]+/, '').trim();
|
|
132
|
+
return t ? t[0].toUpperCase() + t.slice(1) : '';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Read one sentence. PURE: the same sentence and clock give the same answer. */
|
|
136
|
+
function read(text, now = Date.now()) {
|
|
137
|
+
const raw = String(text == null ? '' : text).replace(/\s+/g, ' ').trim();
|
|
138
|
+
if (!raw) return no('Say what should repeat and when, in one sentence.');
|
|
139
|
+
if (raw.length > 600) return no('That is long for one routine. Say it in one sentence, or tell PMOS in the chat.');
|
|
140
|
+
const st = { rest: ' ' + raw + ' ' };
|
|
141
|
+
const notes = [];
|
|
142
|
+
if (/\b(?:every\s+|on\s+|each\s+)?(?:week\s?days?|working days?|work days?|business days?)\b|\bmon(?:day)?\s*(?:-|–|to|through|thru)\s*fri(?:day)?\b/i.test(raw)) {
|
|
143
|
+
return no('PMOS can repeat a routine every day or on one weekday. Which one: every day, or one weekday such as Monday?');
|
|
144
|
+
}
|
|
145
|
+
if (/\bevery\s+(?:\d+|two|three|four|five|six)\s+(?:minutes?|mins?|hours?|days?|months?)\b/i.test(raw) || /\bevery\s+(?:[3-9]|three|four|five|six)\s+weeks?\b/i.test(raw)) {
|
|
146
|
+
return no('PMOS can repeat every hour, day, week, 2 weeks or month. Which one fits?');
|
|
147
|
+
}
|
|
148
|
+
if (/\b(?:twice|three times|\d+ times) (?:a|per|each) (?:day|week|month)\b/i.test(raw)) {
|
|
149
|
+
return no('A routine runs once per repeat. Set up one routine per time, or pick one time.');
|
|
150
|
+
}
|
|
151
|
+
let cadence = null, day = null, dom = null, date = null, partTime = null;
|
|
152
|
+
let m;
|
|
153
|
+
// "every …" phrases first; a bare "weekly" or "monthly" may be part of the instruction ("the weekly risks"), so it counts only after them
|
|
154
|
+
const dayAfter = () => { const d = take(st, new RegExp(`\\b(?:on\\s+)?${DAY_RE}s?\\b`, 'i')); return d ? dayOf(d[1]) : null; };
|
|
155
|
+
if ((m = take(st, /\b(?:every|each)\s+hour\b/i))) cadence = 'hourly';
|
|
156
|
+
else if ((m = take(st, new RegExp(`\\b(?:every|each)\\s+(?:other|second|2nd|alternate)\\s+${DAY_RE}s?\\b`, 'i')))) { cadence = 'bi-weekly'; day = dayOf(m[1]); }
|
|
157
|
+
else if ((m = take(st, /\b(?:every\s+(?:2|two|other)\s+weeks?|every\s+fortnight)\b/i))) { cadence = 'bi-weekly'; day = dayAfter(); }
|
|
158
|
+
else if ((m = take(st, /\b(?:every|each)\s+month\b|\bof\s+(?:every|each)\s+month\b|\bonce\s+a\s+month\b/i))) cadence = 'monthly';
|
|
159
|
+
else if ((m = take(st, new RegExp(`\\b(?:every|each)\\s+${DAY_RE}\\b`, 'i')))) { cadence = 'weekly'; day = dayOf(m[1]); }
|
|
160
|
+
else if ((m = take(st, new RegExp(`\\b(?:on\\s+)?${DAY_RE}s\\b`, 'i')))) { cadence = 'weekly'; day = dayOf(m[1]); }
|
|
161
|
+
else if ((m = take(st, /\b(?:every|each|once\s+a|once\s+per)\s+week\b/i))) { cadence = 'weekly'; day = dayAfter(); }
|
|
162
|
+
else if ((m = take(st, /\b(?:every|each)\s+(morning|afternoon|evening|night)\b/i))) { cadence = 'daily'; partTime = { morning: '09:00', afternoon: '14:00', evening: '18:00', night: '20:00' }[m[1].toLowerCase()]; }
|
|
163
|
+
else if ((m = take(st, /\b(?:every|each)\s*day\b|\bonce\s+a\s+day\b|\bevery\s+single\s+day\b/i))) cadence = 'daily';
|
|
164
|
+
else if ((m = take(st, /\bhourly\b/i))) cadence = 'hourly';
|
|
165
|
+
else if ((m = take(st, /\b(?:bi-?weekly|fortnightly)\b/i))) { cadence = 'bi-weekly'; day = dayAfter(); }
|
|
166
|
+
else if ((m = take(st, /\bmonthly\b/i))) cadence = 'monthly';
|
|
167
|
+
else if ((m = take(st, /\bweekly\b/i))) { cadence = 'weekly'; day = dayAfter(); }
|
|
168
|
+
else if ((m = take(st, /\bdaily\b/i))) cadence = 'daily';
|
|
169
|
+
if (cadence === 'monthly') {
|
|
170
|
+
dom = readDom(st);
|
|
171
|
+
if (dom === 'last' || (typeof dom === 'number' && dom > 28)) return no('PMOS can repeat on day 1 to 28 of the month, the days every month has. Which day?');
|
|
172
|
+
if (dom === 0) return no('Which day of the month: 1 to 28?');
|
|
173
|
+
if (dom == null) { dom = 1; notes.push('No day of the month given, so day 1.'); }
|
|
174
|
+
}
|
|
175
|
+
if ((cadence === 'weekly' || cadence === 'bi-weekly') && !day) { day = 'Mon'; notes.push('No day given, so Monday.'); }
|
|
176
|
+
let once = null;
|
|
177
|
+
if (!cadence) {
|
|
178
|
+
once = readDate(st, now);
|
|
179
|
+
if (once && once.bad) return no('That date does not exist. Which day did you mean?');
|
|
180
|
+
if (!once) return no('When should it repeat? For example: every Monday at 9am, every day at 17:00, or the 1st of every month.');
|
|
181
|
+
cadence = 'once'; date = once.date;
|
|
182
|
+
}
|
|
183
|
+
const t = readTime(st);
|
|
184
|
+
if (t && t.bad) return no('That time does not exist. Say it as 9am, 4:30 pm or 16:30.');
|
|
185
|
+
let time = (t && t.time) || partTime || (once && once.part) || null;
|
|
186
|
+
if (!time) {
|
|
187
|
+
if (cadence === 'hourly') time = '09:00';
|
|
188
|
+
else { time = '09:00'; notes.push('No time given, so 09:00.'); }
|
|
189
|
+
}
|
|
190
|
+
if (cadence === 'hourly') {
|
|
191
|
+
const mm = take(st, /\b(?:at\s+)?(?::|minute\s+)(\d{1,2})\b|\b(\d{1,2})\s+(?:minutes?\s+)?past(?:\s+the\s+hour)?\b/i);
|
|
192
|
+
if (mm) time = hm(9, Math.min(59, +(mm[1] || mm[2])));
|
|
193
|
+
}
|
|
194
|
+
if (cadence === 'once') {
|
|
195
|
+
const [h, mi] = time.split(':').map(Number);
|
|
196
|
+
const at = new Date(date); at.setHours(h, mi, 0, 0);
|
|
197
|
+
if (at.getTime() <= now) return no('That moment has passed. When should it run?');
|
|
198
|
+
}
|
|
199
|
+
const does = cleanRest(st.rest);
|
|
200
|
+
if (!does || !/[a-z]{2}/i.test(does)) return no('What should PMOS do each time? For example: sum up the week\'s risks for the team.');
|
|
201
|
+
const name = does.replace(/[.!?]+$/, '').split(' ').slice(0, 8).join(' ').slice(0, 80);
|
|
202
|
+
const schedule = { name, cadence, time, args: does.slice(0, 2000),
|
|
203
|
+
...(cadence === 'weekly' || cadence === 'bi-weekly' ? { day } : {}),
|
|
204
|
+
...(cadence === 'monthly' ? { dayOfMonth: dom } : {}),
|
|
205
|
+
...(cadence === 'once' ? { date: ymd(date) } : {}) };
|
|
206
|
+
return { ok: true, schedule, words: { when: whenWords(schedule), does, tells: TELLS }, notes };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Plain words for a schedule's repeat, the way the Setup box says it. PURE. */
|
|
210
|
+
function whenWords(s) {
|
|
211
|
+
const t = s.time || '09:00';
|
|
212
|
+
switch (s.cadence) {
|
|
213
|
+
case 'hourly': return `Every hour at :${t.slice(-2)}`;
|
|
214
|
+
case 'daily': return `Every day at ${t}`;
|
|
215
|
+
case 'weekly': return `Every ${DAY_NAME[s.day] || 'Monday'} at ${t}`;
|
|
216
|
+
case 'bi-weekly': return `Every other ${DAY_NAME[s.day] || 'Monday'} at ${t}`;
|
|
217
|
+
case 'monthly': return `Every month on day ${s.dayOfMonth || 1} at ${t}`;
|
|
218
|
+
case 'once': {
|
|
219
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(s.date || ''));
|
|
220
|
+
if (!m) return `Once at ${t}`;
|
|
221
|
+
const d = new Date(+m[1], +m[2] - 1, +m[3]);
|
|
222
|
+
return `Once, ${Object.keys(DAY_IDX)[d.getDay()]} ${d.getDate()} ${MON_SHORT[d.getMonth()]} at ${t}`;
|
|
223
|
+
}
|
|
224
|
+
default: return '';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Schedules made from a sentence in the last `days` days. PURE. */
|
|
229
|
+
function count(list, now = Date.now(), days = 30) {
|
|
230
|
+
const from = now - days * 86400000;
|
|
231
|
+
return (Array.isArray(list) ? list : []).filter((s) => s && s.made === 'sentence' && (Date.parse(s.madeAt || '') || 0) >= from).length;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
module.exports = { SKILL, TAG, TELLS, read, whenWords, count };
|
|
235
|
+
|
|
236
|
+
/* node routine-sentence.js count — this computer's schedules (PMOS_STATE_DIR, else the user's state folder) */
|
|
237
|
+
if (require.main === module) {
|
|
238
|
+
const cmd = process.argv[2];
|
|
239
|
+
if (cmd === 'count') {
|
|
240
|
+
let list = [];
|
|
241
|
+
try {
|
|
242
|
+
const root = require('./state-root.js').resolveStateRoot({ env: process.env }).root;
|
|
243
|
+
list = JSON.parse(fs.readFileSync(path.join(root, 'schedules.json'), 'utf8'));
|
|
244
|
+
if (list && !Array.isArray(list)) list = list.schedules || [];
|
|
245
|
+
} catch { list = []; }
|
|
246
|
+
process.stdout.write(`${count(list)}\n`);
|
|
247
|
+
} else {
|
|
248
|
+
process.stdout.write('usage: node routine-sentence.js count\n');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* strategy-card.js — a product's strategy in five lines, and the gentle "doesn't fit" note on new work (bet A458, initiative strategy-five-lines).
|
|
3
|
+
*
|
|
4
|
+
* read(dir) → { for, problem, bet, win, wont, at, since } the latest value of each line ('' when never written), the last
|
|
5
|
+
* save's time, and the time all five lines were first written
|
|
6
|
+
* save(dir, fields, now?) → { ok, card } | { ok: false, error } appends one line { at, fields } to <dir>/strategy-card.jsonl
|
|
7
|
+
* complete(card) → true when all five lines are written
|
|
8
|
+
* fit(card, row) → null (fits, or nothing to say) | { kind: 'wont' | 'none', why }
|
|
9
|
+
* notes(card, rows) → [{ id, title, stage, kind, why }] at most MAX_NOTES
|
|
10
|
+
* count(dirs) → how many of the folders hold a complete card
|
|
11
|
+
*
|
|
12
|
+
* WHERE. `dir` is the product's records folder (lib/records-dir.js): planning/records in the PMOS repo, pmos/state/records in a kit product.
|
|
13
|
+
* The file is append-only; nothing rewrites it, so the history of the strategy stays.
|
|
14
|
+
*
|
|
15
|
+
* THE FIT RULE. Plain word overlap, no model: words of 4 or more letters, without common words, with a plain plural cut ("reports" → "report").
|
|
16
|
+
* A row that shares a word with "what we won't do" touches it. Else a row that shares no word with the other four lines names none of them;
|
|
17
|
+
* that second note is kept to rows changed (`updated`) on or after the day all five lines were first written (`since`).
|
|
18
|
+
* Only new work gets a note: an open row in Triage, Discover, Plan or Prioritize, in a lane other than chore or incident. A card with a blank
|
|
19
|
+
* line gives no note at all (zero is silence). A note informs only: nothing is moved, hidden or blocked. */
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
|
|
23
|
+
const FILE = 'strategy-card.jsonl';
|
|
24
|
+
const FIELDS = ['for', 'problem', 'bet', 'win', 'wont'];
|
|
25
|
+
const LABELS = { for: 'Who it is for', problem: 'The problem', bet: 'The bet', win: 'How we win', wont: "What we won't do" };
|
|
26
|
+
const MAX_LEN = 160;
|
|
27
|
+
const MAX_NOTES = 20;
|
|
28
|
+
const NEW_STAGES = ['triage', 'discover', 'plan', 'prioritize', 'intake', 'ideate', 'strategize']; // old names count for the new ones (lib/board-premium.js)
|
|
29
|
+
const SKIP_LANES = ['chore', 'incident'];
|
|
30
|
+
const STOP = new Set(('a an and are but for from have into its more most much must not only our over same some such than that the their them then '
|
|
31
|
+
+ 'there these they this those very what when where which while who whom will with your you also each every just like make makes made want wont '
|
|
32
|
+
+ 'does doing done should would could about after before other others than through without within page pages work item items new add adds added').split(/\s+/));
|
|
33
|
+
const say = (s) => { try { console.log('[strategy-card] ' + s); } catch { /* no console */ } };
|
|
34
|
+
|
|
35
|
+
/** One line of text: newlines and runs of space become one space, cut at MAX_LEN. */
|
|
36
|
+
const line = (v) => { const s = String(v == null ? '' : v).replace(/\s+/g, ' ').trim(); return s.length > MAX_LEN ? s.slice(0, MAX_LEN - 1).trimEnd() + '…' : s; };
|
|
37
|
+
const stem = (w) => (w.length > 5 && w.endsWith('ies') ? w.slice(0, -3) + 'y' : w.length > 4 && /(ches|shes|sses|xes)$/.test(w) ? w.slice(0, -2) : w.length > 4 && w.endsWith('s') && !w.endsWith('ss') ? w.slice(0, -1) : w);
|
|
38
|
+
/** The words a line is about. */
|
|
39
|
+
function words(s) {
|
|
40
|
+
const out = new Set();
|
|
41
|
+
for (const w of String(s || '').toLowerCase().replace(/['’]/g, '').split(/[^a-z0-9]+/)) if (w.length >= 4 && !STOP.has(w) && !/^\d+$/.test(w)) out.add(stem(w));
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
const shared = (a, b) => [...a].filter((w) => b.has(w));
|
|
45
|
+
|
|
46
|
+
const fileOf = (dir) => (dir ? path.join(dir, FILE) : null);
|
|
47
|
+
|
|
48
|
+
function readLines(dir) {
|
|
49
|
+
const f = fileOf(dir);
|
|
50
|
+
if (!f) return [];
|
|
51
|
+
let text = '';
|
|
52
|
+
try { text = fs.readFileSync(f, 'utf8'); } catch { return []; }
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object' && o.fields && typeof o.fields === 'object') out.push(o); } catch { /* a torn line is skipped */ } }
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function read(dir) {
|
|
59
|
+
const card = { for: '', problem: '', bet: '', win: '', wont: '', at: null, since: null };
|
|
60
|
+
for (const l of readLines(dir)) {
|
|
61
|
+
for (const k of FIELDS) if (Object.prototype.hasOwnProperty.call(l.fields, k)) card[k] = line(l.fields[k]);
|
|
62
|
+
card.at = l.at || card.at;
|
|
63
|
+
if (!card.since && complete(card)) card.since = l.at || null; // the day all five lines were first written
|
|
64
|
+
}
|
|
65
|
+
return card;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Only the five known lines, each cut to one line. Unknown keys are dropped. */
|
|
69
|
+
function clean(fields) {
|
|
70
|
+
const out = {};
|
|
71
|
+
if (!fields || typeof fields !== 'object') return out;
|
|
72
|
+
for (const k of FIELDS) if (Object.prototype.hasOwnProperty.call(fields, k)) out[k] = line(fields[k]);
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function save(dir, fields, now = Date.now()) {
|
|
77
|
+
const f = fileOf(dir);
|
|
78
|
+
if (!f) return { ok: false, error: 'This product has no records folder.' };
|
|
79
|
+
const c = clean(fields);
|
|
80
|
+
if (!Object.keys(c).length) return { ok: false, error: 'Name a line to save: ' + FIELDS.join(', ') + '.' };
|
|
81
|
+
try { fs.mkdirSync(dir, { recursive: true }); fs.appendFileSync(f, JSON.stringify({ at: new Date(now).toISOString(), fields: c }) + '\n'); } catch (e) { return { ok: false, error: 'could not save the strategy: ' + ((e && e.message) || e) }; }
|
|
82
|
+
const card = read(dir);
|
|
83
|
+
say('saved ' + Object.keys(c).join(', ') + (complete(card) ? ' (all five lines written)' : ''));
|
|
84
|
+
return { ok: true, card };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const complete = (card) => !!card && FIELDS.every((k) => String(card[k] || '').trim() !== '');
|
|
88
|
+
|
|
89
|
+
/** Is this row new work: open, before Build, not upkeep? */
|
|
90
|
+
function isNew(row) {
|
|
91
|
+
if (!row || !row.id || !String(row.title || '').trim()) return false;
|
|
92
|
+
if (row.closed || row.ended || row.archived || ['done', 'cancelled'].includes(String(row.status || '').toLowerCase())) return false;
|
|
93
|
+
if (SKIP_LANES.includes(String(row.lane || '').toLowerCase())) return false;
|
|
94
|
+
const st = String(row.stage || '').trim().toLowerCase().replace(/^◆\s*/, '');
|
|
95
|
+
return NEW_STAGES.includes(st);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function fit(card, row) {
|
|
99
|
+
if (!complete(card) || !isNew(row)) return null;
|
|
100
|
+
const t = words(row.title);
|
|
101
|
+
if (!t.size) return null;
|
|
102
|
+
const hit = shared(t, words(card.wont));
|
|
103
|
+
if (hit.length) return { kind: 'wont', why: "touches what we won't do: " + card.wont };
|
|
104
|
+
// "names none" speaks only of work changed since the strategy was written: on real data (the PMOS repo, 2026-11-22) it named 18 of 20
|
|
105
|
+
// older initiatives in Plan, which is noise, not a gentle note. A row with no `updated` counts as new.
|
|
106
|
+
if (card.since && row.updated && String(row.updated).slice(0, 10) < String(card.since).slice(0, 10)) return null;
|
|
107
|
+
const own = words([card.for, card.problem, card.bet, card.win].join(' '));
|
|
108
|
+
if (!shared(t, own).length) return { kind: 'none', why: 'names none of who it is for, the problem, the bet or how we win' };
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function notes(card, rows) {
|
|
113
|
+
if (!complete(card)) return [];
|
|
114
|
+
const out = [];
|
|
115
|
+
for (const r of rows || []) {
|
|
116
|
+
const f = fit(card, r);
|
|
117
|
+
if (f) out.push({ id: r.id, title: line(r.title), stage: r.stage || '', kind: f.kind, why: f.why });
|
|
118
|
+
if (out.length >= MAX_NOTES) break;
|
|
119
|
+
}
|
|
120
|
+
return out.sort((a, b) => (a.kind === b.kind ? 0 : a.kind === 'wont' ? -1 : 1));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const count = (dirs) => (dirs || []).filter((d) => complete(read(d))).length;
|
|
124
|
+
|
|
125
|
+
module.exports = { FILE, FIELDS, LABELS, MAX_LEN, MAX_NOTES, words, read, save, clean, complete, fit, notes, count, readLines };
|
|
126
|
+
|
|
127
|
+
if (require.main === module) {
|
|
128
|
+
const cmd = process.argv[2];
|
|
129
|
+
if (cmd !== 'count') { console.error('usage: node workspace/lib/strategy-card.js count [<product checkout>] (products with all five lines saved)'); process.exit(2); }
|
|
130
|
+
let dir = null;
|
|
131
|
+
try { const { repoScript } = require('./repo-script.js'); dir = require(repoScript('signals/layout-paths.js')).pathsFor(process.argv[3] || process.cwd()).recordsDir; } catch { dir = path.join(process.argv[3] || process.cwd(), 'planning', 'records'); }
|
|
132
|
+
console.log(String(count([dir])));
|
|
133
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* unused-controls.js — hide the buttons nobody presses (idea A454, initiative hide-unused-controls). THE ONE STORE and THE ONE RULE.
|
|
4
|
+
* lib/routes-use-log.js does the HTTP; public/pm/use-log.js is the page side (the ✦ suggestion, the Toast with Undo); Settings › General ›
|
|
5
|
+
* Use log lists every hidden button with Show and Show all, so a hidden button is never lost.
|
|
6
|
+
*
|
|
7
|
+
* LOCAL ONLY, like the use log (lib/use-log.js): <runtime>/hidden-controls.json on this computer, never sent. It keeps ids only, never a
|
|
8
|
+
* button's text: an id must match ID_RE and must not be a data- attribute name (those name a whole group of buttons, not one).
|
|
9
|
+
*
|
|
10
|
+
* THE STORE. { v: 1, seen, hidden, declined }
|
|
11
|
+
* seen { [page]: { [id]: { first: 'YYYY-MM-DD', days: ['YYYY-MM-DD'…] } } } the days a page showed the button (last SEEN_KEEP days)
|
|
12
|
+
* hidden [{ page, control, at, shown_at? }] a row with shown_at was shown again (Undo, Show, Show all): kept so re-shows can be counted
|
|
13
|
+
* declined [{ page, control, at }] the user said No: never proposed again
|
|
14
|
+
*
|
|
15
|
+
* THE RULE (proposeOf). A button on a page is proposed only when ALL hold:
|
|
16
|
+
* the use log has lines from WINDOW_DAYS or more days ago (it has watched long enough);
|
|
17
|
+
* the page was opened on MIN_DAYS or more of the last WINDOW_DAYS days;
|
|
18
|
+
* the button was first seen WINDOW_DAYS or more days ago and seen on MIN_DAYS or more of the last WINDOW_DAYS days;
|
|
19
|
+
* it was never pressed on that page in the last WINDOW_DAYS days; it is not hidden now and was not declined.
|
|
20
|
+
* At most MAX_PROPOSE at once.
|
|
21
|
+
*
|
|
22
|
+
* storeFile(dir) · readStore(dir) · cleanIds(list) → ids
|
|
23
|
+
* noteSeen(store, page, ids, now) → changed? PURE on the store object
|
|
24
|
+
* proposeOf({ store, lines, page, now }) → ids PURE
|
|
25
|
+
* hiddenOf(store, page?) → [{ page, control, at }] PURE, the rows hidden now
|
|
26
|
+
* seeAndPropose(dir, page, present, lines, now) → { ok, hidden, propose }
|
|
27
|
+
* hide(dir, page, ids, now) · show(dir, { page, controls } | { all: true }, now) · decline(dir, page, ids, now) · clearSeen(dir)
|
|
28
|
+
* CLI: node lib/unused-controls.js count → the buttons hidden now, on its last line (the health number) */
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
|
|
32
|
+
const FILE = 'hidden-controls.json';
|
|
33
|
+
const WINDOW_DAYS = 14;
|
|
34
|
+
const MIN_DAYS = 5;
|
|
35
|
+
const MAX_PROPOSE = 12;
|
|
36
|
+
const SEEN_KEEP = 30;
|
|
37
|
+
const MAX_IDS = 300;
|
|
38
|
+
const MAX_SHOWN = 500;
|
|
39
|
+
const DAY = 864e5;
|
|
40
|
+
const ID_RE = /^[A-Za-z][A-Za-z0-9_-]{0,79}$/;
|
|
41
|
+
const PAGE_RE = /^[a-z0-9][a-z0-9._-]{0,59}$/;
|
|
42
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
43
|
+
const say = (s) => { try { console.log('[unused-controls] ' + s); } catch { /* no console */ } };
|
|
44
|
+
const dayOf = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
45
|
+
|
|
46
|
+
function storeFile(dir) { return dir ? path.join(dir, FILE) : null; }
|
|
47
|
+
const empty = () => ({ v: 1, seen: {}, hidden: [], declined: [] });
|
|
48
|
+
|
|
49
|
+
function readStore(dir) {
|
|
50
|
+
const f = storeFile(dir); if (!f) return empty();
|
|
51
|
+
try {
|
|
52
|
+
const s = JSON.parse(fs.readFileSync(f, 'utf8'));
|
|
53
|
+
if (!isObj(s)) return empty();
|
|
54
|
+
return { v: 1, seen: isObj(s.seen) ? s.seen : {}, hidden: Array.isArray(s.hidden) ? s.hidden.filter(isObj) : [], declined: Array.isArray(s.declined) ? s.declined.filter(isObj) : [] };
|
|
55
|
+
} catch { return empty(); }
|
|
56
|
+
}
|
|
57
|
+
function writeStore(dir, s) {
|
|
58
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
59
|
+
const f = storeFile(dir), tmp = f + '.tmp';
|
|
60
|
+
fs.writeFileSync(tmp, JSON.stringify(s));
|
|
61
|
+
fs.renameSync(tmp, f);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Only ids: a value with text, a URL, an address or a data- attribute name is dropped. At most MAX_IDS, no repeats. */
|
|
65
|
+
function cleanIds(list) {
|
|
66
|
+
if (!Array.isArray(list)) return [];
|
|
67
|
+
const out = new Set();
|
|
68
|
+
for (const v of list) { const s = String(v == null ? '' : v); if (ID_RE.test(s) && !/^data-/i.test(s)) out.add(s); if (out.size >= MAX_IDS) break; }
|
|
69
|
+
return [...out];
|
|
70
|
+
}
|
|
71
|
+
const okPage = (p) => PAGE_RE.test(String(p || ''));
|
|
72
|
+
|
|
73
|
+
/** Note that the page showed these buttons today. Days older than SEEN_KEEP drop off. → true when the store changed. */
|
|
74
|
+
function noteSeen(store, page, ids, now = Date.now()) {
|
|
75
|
+
if (!okPage(page)) return false;
|
|
76
|
+
const today = dayOf(now), cut = dayOf(now - SEEN_KEEP * DAY);
|
|
77
|
+
const P = store.seen[page] = isObj(store.seen[page]) ? store.seen[page] : {};
|
|
78
|
+
let changed = false;
|
|
79
|
+
for (const id of cleanIds(ids)) {
|
|
80
|
+
const r = isObj(P[id]) ? P[id] : (changed = true, P[id] = { first: today, days: [] });
|
|
81
|
+
if (!Array.isArray(r.days)) r.days = [];
|
|
82
|
+
if (!r.days.includes(today)) { r.days.push(today); changed = true; }
|
|
83
|
+
const keep = r.days.filter((d) => d >= cut);
|
|
84
|
+
if (keep.length !== r.days.length) { r.days = keep; changed = true; }
|
|
85
|
+
}
|
|
86
|
+
const ids2 = Object.keys(P);
|
|
87
|
+
if (ids2.length > MAX_IDS) { // keep the ones seen most lately
|
|
88
|
+
const last = (id) => (P[id].days || []).slice(-1)[0] || '';
|
|
89
|
+
ids2.sort((a, b) => (last(a) < last(b) ? -1 : 1)).slice(0, ids2.length - MAX_IDS).forEach((id) => delete P[id]);
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
return changed;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const activeHidden = (store) => store.hidden.filter((h) => !h.shown_at);
|
|
96
|
+
function hiddenOf(store, page) {
|
|
97
|
+
return activeHidden(store).filter((h) => !page || h.page === page).map((h) => ({ page: h.page, control: h.control, at: h.at }));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function proposeOf({ store, lines, page, now = Date.now() }) {
|
|
101
|
+
if (!okPage(page) || !store || !isObj(store.seen) || !isObj(store.seen[page])) return [];
|
|
102
|
+
const since = now - WINDOW_DAYS * DAY, sinceDay = dayOf(since);
|
|
103
|
+
const L = Array.isArray(lines) ? lines : [];
|
|
104
|
+
const oldest = Math.min(...L.map((l) => Date.parse(l && l.at)).filter(Number.isFinite));
|
|
105
|
+
if (!(oldest <= since)) return []; // the use log has not watched for 14 days yet
|
|
106
|
+
const recent = L.filter((l) => Date.parse(l.at) >= since && l.page === page);
|
|
107
|
+
const openDays = new Set(recent.filter((l) => l.kind === 'open').map((l) => l.at.slice(0, 10)));
|
|
108
|
+
if (openDays.size < MIN_DAYS) return []; // a page opened rarely says nothing about its buttons
|
|
109
|
+
const pressed = new Set(recent.filter((l) => l.kind === 'use').map((l) => l.control));
|
|
110
|
+
const off = new Set(activeHidden(store).filter((h) => h.page === page).map((h) => h.control));
|
|
111
|
+
for (const d of store.declined) if (d.page === page) off.add(d.control);
|
|
112
|
+
const out = [];
|
|
113
|
+
for (const [id, r] of Object.entries(store.seen[page])) {
|
|
114
|
+
if (!ID_RE.test(id) || /^data-/i.test(id) || pressed.has(id) || off.has(id) || !isObj(r)) continue;
|
|
115
|
+
if (!(String(r.first || '9') <= sinceDay)) continue; // a new button gets its 14 days
|
|
116
|
+
if ((Array.isArray(r.days) ? r.days.filter((d) => d >= sinceDay) : []).length < MIN_DAYS) continue;
|
|
117
|
+
out.push(id);
|
|
118
|
+
}
|
|
119
|
+
return out.sort().slice(0, MAX_PROPOSE);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function seeAndPropose(dir, page, present, lines, now = Date.now()) {
|
|
123
|
+
if (!dir) return { ok: false, error: 'This workspace has no runtime folder, so PMOS cannot see which buttons go unused.' };
|
|
124
|
+
if (!okPage(page)) return { ok: false, error: 'page is a page file name' };
|
|
125
|
+
const s = readStore(dir);
|
|
126
|
+
if (noteSeen(s, page, present, now)) writeStore(dir, s);
|
|
127
|
+
return { ok: true, hidden: hiddenOf(s, page).map((h) => h.control), propose: proposeOf({ store: s, lines, page, now }) };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function hide(dir, page, ids, now = Date.now()) {
|
|
131
|
+
if (!dir) return { ok: false, error: 'This workspace has no runtime folder.' };
|
|
132
|
+
if (!okPage(page)) return { ok: false, error: 'page is a page file name' };
|
|
133
|
+
const s = readStore(dir), on = new Set(hiddenOf(s, page).map((h) => h.control)), at = new Date(now).toISOString();
|
|
134
|
+
const add = cleanIds(ids).filter((id) => !on.has(id));
|
|
135
|
+
for (const control of add) s.hidden.push({ page, control, at });
|
|
136
|
+
if (add.length) { writeStore(dir, s); say(`hid ${add.length} on ${page}`); }
|
|
137
|
+
return { ok: true, hidden: add.length };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function show(dir, what = {}, now = Date.now()) {
|
|
141
|
+
if (!dir) return { ok: false, error: 'This workspace has no runtime folder.' };
|
|
142
|
+
const s = readStore(dir), at = new Date(now).toISOString();
|
|
143
|
+
const all = what && what.all === true, page = what && what.page, ids = new Set(cleanIds(what && what.controls));
|
|
144
|
+
if (!all && (!okPage(page) || !ids.size)) return { ok: false, error: 'show takes { page, controls } or { all: true }' };
|
|
145
|
+
let n = 0;
|
|
146
|
+
for (const h of s.hidden) if (!h.shown_at && (all || (h.page === page && ids.has(h.control)))) { h.shown_at = at; n++; }
|
|
147
|
+
const shown = s.hidden.filter((h) => h.shown_at);
|
|
148
|
+
if (shown.length > MAX_SHOWN) { const drop = new Set(shown.slice(0, shown.length - MAX_SHOWN)); s.hidden = s.hidden.filter((h) => !drop.has(h)); }
|
|
149
|
+
if (n) { writeStore(dir, s); say(`showed ${n}${all ? ' (show all)' : ' on ' + page}`); }
|
|
150
|
+
return { ok: true, shown: n };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function decline(dir, page, ids, now = Date.now()) {
|
|
154
|
+
if (!dir) return { ok: false, error: 'This workspace has no runtime folder.' };
|
|
155
|
+
if (!okPage(page)) return { ok: false, error: 'page is a page file name' };
|
|
156
|
+
const s = readStore(dir), had = new Set(s.declined.filter((d) => d.page === page).map((d) => d.control)), at = new Date(now).toISOString();
|
|
157
|
+
const add = cleanIds(ids).filter((id) => !had.has(id));
|
|
158
|
+
for (const control of add) s.declined.push({ page, control, at });
|
|
159
|
+
if (add.length) { writeStore(dir, s); say(`declined ${add.length} on ${page}`); }
|
|
160
|
+
return { ok: true, declined: add.length };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Clear of the use log forgets what pages showed too; the hidden list stays (the user's own choice). */
|
|
164
|
+
function clearSeen(dir) {
|
|
165
|
+
if (!dir) return { ok: true };
|
|
166
|
+
const s = readStore(dir);
|
|
167
|
+
if (!Object.keys(s.seen).length) return { ok: true };
|
|
168
|
+
s.seen = {}; writeStore(dir, s);
|
|
169
|
+
return { ok: true };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = { FILE, WINDOW_DAYS, MIN_DAYS, MAX_PROPOSE, ID_RE, storeFile, readStore, cleanIds, noteSeen, proposeOf, hiddenOf, seeAndPropose, hide, show, decline, clearSeen };
|
|
173
|
+
|
|
174
|
+
if (require.main === module) {
|
|
175
|
+
if (process.argv[2] !== 'count') { console.error('usage: node lib/unused-controls.js count (the buttons hidden now)'); process.exit(2); }
|
|
176
|
+
const dir = require('./state-root.js').defaultRoot({ env: process.env });
|
|
177
|
+
console.log(String(hiddenOf(readStore(dir)).length));
|
|
178
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.713.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.713.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED