create-pmos 0.712.0 → 0.714.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 +99 -51
- 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 +10 -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 +98 -0
- 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 +10 -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 +27 -1
- 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/moments.js +41 -3
- 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-moments.js +1 -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/lib/use-log.js +27 -3
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-vw-doc-test.js +2 -0
- package/workspace/public/pm/action-keys.js +187 -0
- package/workspace/public/pm/back-place.js +87 -0
- 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-ev.css +7 -0
- package/workspace/public/pm/cozy-nav.js +2 -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-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-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/page-chat.js +16 -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-insights.js +2 -2
- 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/quiet-place.js +15 -2
- 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 +67 -0
- package/workspace/public/pm/use-log.js +127 -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/action-keys.json +9 -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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-prefs.js — view preferences that follow the person, over HTTP (bet A461, initiative prefs-follow-person). The store and its rules
|
|
3
|
+
* are lib/prefs-sync.js (<runtime>/view-prefs.json on this computer); the page side is public/pm/prefs-sync.js.
|
|
4
|
+
*
|
|
5
|
+
* GET /api/view-prefs/boot.js → text/javascript: the person's values, the allowlist, then public/pm/prefs-sync.js. Every page loads it
|
|
6
|
+
* first, right after the nonce meta, so the values are in this browser's storage before page code reads it.
|
|
7
|
+
* GET /api/view-prefs → { ok, on, keeps, followed }
|
|
8
|
+
* POST /api/view-prefs { set, followed, device } → { ok, wrote, refused } the page side, in batches
|
|
9
|
+
*
|
|
10
|
+
* NOTHING IS SENT ANYWHERE. A script load from another site (Sec-Fetch-Site cross-site or same-site) gets the script with no values, so
|
|
11
|
+
* another page cannot read the person's choices by including it. WHO WRITES: the person's own pages only (pm-guard requirePagePress: the
|
|
12
|
+
* page's Origin and launch nonce); a POST with an agent session header is refused. PMOS_PREFS_SYNC=off: no values, and a POST is refused. */
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const guard = require('./pm-guard.js');
|
|
16
|
+
const PS = require('./prefs-sync.js');
|
|
17
|
+
|
|
18
|
+
const PAGE_JS = path.join(__dirname, '..', 'public', 'pm', 'prefs-sync.js');
|
|
19
|
+
// JSON in a script: every `<` and line separator is written as a unicode escape, so no value can close the script element or open a comment.
|
|
20
|
+
const safe = (v) => JSON.stringify(v).replace(/</g, '\\u003c').replace(/[\u2028\u2029]/g, (c) => '\\u' + c.charCodeAt(0).toString(16));
|
|
21
|
+
|
|
22
|
+
function crossSite(req) {
|
|
23
|
+
const s = String((req.headers && req.headers['sec-fetch-site']) || '').toLowerCase();
|
|
24
|
+
return s === 'cross-site' || s === 'same-site';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function handle(req, res, url, ctx) {
|
|
28
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
29
|
+
const what = url.pathname.replace(/^\/api\/view-prefs\/?/, '');
|
|
30
|
+
const dir = ctx.runtimeDir || null;
|
|
31
|
+
const isOff = PS.off(process.env);
|
|
32
|
+
if (what === 'boot.js') {
|
|
33
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
|
|
34
|
+
let code = '';
|
|
35
|
+
try { code = fs.readFileSync(PAGE_JS, 'utf8'); } catch { code = ''; }
|
|
36
|
+
const vals = isOff || crossSite(req) ? {} : PS.values(dir);
|
|
37
|
+
const body = `window.__pmosViewPrefs=${safe(vals)};window.__pmosViewPrefsKeys=${safe(PS.KEYS)};window.__pmosViewPrefsOn=${isOff ? 'false' : 'true'};\n${code}`;
|
|
38
|
+
res.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' });
|
|
39
|
+
res.end(body);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (what !== '') return send(404, { ok: false, error: 'no such view-prefs route' });
|
|
43
|
+
if (req.method === 'GET') return send(200, { ok: true, on: !isOff, keeps: Object.keys(PS.values(dir)).length, followed: PS.count(dir) });
|
|
44
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
|
|
45
|
+
if (req.headers && req.headers['x-pmos-session']) return send(403, { ok: false, error: 'An agent session does not change view preferences. Only your own pages do.' });
|
|
46
|
+
if (isOff) return send(409, { ok: false, error: 'Preferences that follow you are off on this computer (PMOS_PREFS_SYNC=off).' });
|
|
47
|
+
const rd = await ctx.readJson(req);
|
|
48
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
49
|
+
const body = rd.body || {};
|
|
50
|
+
const g = guard.requirePagePress(req, body);
|
|
51
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
52
|
+
const r = PS.apply(dir, body);
|
|
53
|
+
return r.ok ? send(200, r) : send(r.error.startsWith('This workspace') ? 409 : 400, r);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { prefixes: ['/api/view-prefs'], handle };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-strategy-card.js — a product's five-line strategy over HTTP (bet A458, initiative strategy-five-lines). The card and its fit rule are
|
|
3
|
+
* lib/strategy-card.js; the file is strategy-card.jsonl in the product's records folder (lib/records-dir.js).
|
|
4
|
+
*
|
|
5
|
+
* GET /api/strategy-card?ws=<id>[&board=<id>] → { ok, card, labels, complete, notes } notes: null while the Board is still being read
|
|
6
|
+
* POST /api/strategy-card { ws, fields } → { ok, card, complete } | 400 when no known line is named
|
|
7
|
+
*
|
|
8
|
+
* The notes come from the Board's own backlog route (GET /api/boards/backlog, every view, the new-work stages), so they read the rows the Board draws.
|
|
9
|
+
* WHO WRITES. A page press: pm-guard requirePagePress checks the page's Origin and launch nonce. Nothing here is sent anywhere. */
|
|
10
|
+
const guard = require('./pm-guard.js');
|
|
11
|
+
const SC = require('./strategy-card.js');
|
|
12
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
13
|
+
|
|
14
|
+
/** GET a route module's own handler, as routes-board-premium.js does, and return { status, body }. */
|
|
15
|
+
async function via(mod, pathAndQuery, req, ctx) {
|
|
16
|
+
let out = { status: 500, body: null };
|
|
17
|
+
const c = Object.assign({}, ctx, { json: (res, obj, code) => { out = { status: code || 200, body: obj }; } });
|
|
18
|
+
const handled = await mod.handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, new URL('http://local' + pathAndQuery), c);
|
|
19
|
+
return handled === false ? { status: 404, body: null } : out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function rowsOf(req, ctx, ws, board) {
|
|
23
|
+
try {
|
|
24
|
+
// only the stages new work stands in (the old names too), so the 100-row page of the backlog route holds them all
|
|
25
|
+
const q = '?view=all&limit=100&stage=' + encodeURIComponent('Triage,Discover,Plan,Prioritize,Intake,Ideate,Strategize') + (ws ? '&ws=' + encodeURIComponent(ws) : '') + (board ? '&board=' + encodeURIComponent(board) : '');
|
|
26
|
+
const r = await via(require('./routes-boards.js'), '/api/boards/backlog' + q, req, ctx);
|
|
27
|
+
if (r.status !== 200 || !r.body || r.body.ok === false || r.body.pending) return null;
|
|
28
|
+
return Array.isArray(r.body.rows) ? r.body.rows : null;
|
|
29
|
+
} catch { return null; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function handle(req, res, url, ctx) {
|
|
33
|
+
if (url.pathname !== '/api/strategy-card') return false;
|
|
34
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
35
|
+
if (req.method === 'GET') {
|
|
36
|
+
const ws = url.searchParams.get('ws') || null;
|
|
37
|
+
const card = SC.read(recordsDirFor(ctx, ws));
|
|
38
|
+
const complete = SC.complete(card);
|
|
39
|
+
let notes = [];
|
|
40
|
+
if (complete) { const rows = ctx.strategyRows ? ctx.strategyRows : await rowsOf(req, ctx, ws, url.searchParams.get('board') || null); notes = rows ? SC.notes(card, rows) : null; }
|
|
41
|
+
return send(200, { ok: true, card, labels: SC.LABELS, complete, notes });
|
|
42
|
+
}
|
|
43
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
|
|
44
|
+
const rd = await ctx.readJson(req);
|
|
45
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
46
|
+
const body = rd.body || {};
|
|
47
|
+
const g = guard.requirePagePress(req, body);
|
|
48
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
49
|
+
const r = SC.save(recordsDirFor(ctx, body.ws || null), body.fields);
|
|
50
|
+
return r.ok ? send(200, { ok: true, card: r.card, complete: SC.complete(r.card) }) : send(400, { ok: false, error: r.error });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { prefixes: ['/api/strategy-card'], handle };
|
|
@@ -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
|
+
}
|