create-pmos 0.825.0 → 0.827.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 +119 -49
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +118 -16
- package/workspace/guide/agent-capabilities.md +1 -0
- package/workspace/guide/cli.md +36 -0
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/layout.md +1 -1
- package/workspace/guide/settings-and-switches.md +2 -0
- package/workspace/lib/arch-warns.js +121 -0
- package/workspace/lib/code-map-cli.js +108 -0
- package/workspace/lib/code-map.js +247 -0
- package/workspace/lib/features.json +59 -1
- package/workspace/lib/goals-cli.js +5 -0
- package/workspace/lib/pmos-verbs.js +6 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-arch-warns.js +39 -0
- package/workspace/lib/routes-code-map.js +66 -0
- package/workspace/lib/routes-onboard.js +18 -3
- package/workspace/lib/routes-today.js +2 -1
- package/workspace/lib/starter-goals.js +244 -0
- package/workspace/lib/today-cli.js +4 -2
- package/workspace/lib/today-order.js +120 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/code-map.js +60 -0
- package/workspace/public/pm/cozy-board.css +8 -0
- package/workspace/public/pm/cozy-onboard.css +4 -0
- package/workspace/public/pm/cozy-onboard.js +17 -1
- package/workspace/public/pm/cozy-pop-work.js +31 -1
- package/workspace/public/pm/cozy-settings.js +0 -1
- package/workspace/public/pm/cozy-today-app.js +41 -2
- package/workspace/public/pm/cozy-today-page.css +3 -0
- package/workspace/public/pm/cozy-today-view.js +20 -5
- package/workspace/public/pm/pop-cap.js +5 -2
- package/workspace/public/pm/pop-work-model.js +6 -0
- package/workspace/public/pm/premium-board.js +2 -0
- package/workspace/public/pm/starter-goals.js +35 -0
- package/workspace/public/pm/today-order.js +88 -0
- package/workspace/public/premium-board.html +2 -0
- package/workspace/test-lists/arch-warns.json +9 -0
- package/workspace/test-lists/code-map.json +9 -0
- package/workspace/test-lists/directory-all-verbs.json +9 -0
- package/workspace/test-lists/starter-goals.json +9 -0
- package/workspace/test-lists/today-order.json +9 -0
|
@@ -151,6 +151,8 @@ const MODULES = Object.freeze([
|
|
|
151
151
|
'routes-strategy-card', // bet A458: a product's five-line strategy above its Board, and the gentle "doesn't fit" note on new work (records strategy-card.jsonl; page-press POST)
|
|
152
152
|
'routes-principles', // bet A352: a product's principles drafted from its decisions, kept or dropped on the Board (records principles.jsonl; page-press POST)
|
|
153
153
|
'routes-prefs', // bet A461: view preferences that follow the person to the phone and other browsers (runtime view-prefs.json; page-press POST)
|
|
154
|
+
'routes-code-map', // idea A176: the product's code map on Work, redrawn when the default branch moves (records code-map.json; read-only)
|
|
155
|
+
'routes-arch-warns', // idea A54: one warning when an initiative names a risky part of the code (reads code-map.json; read-only)
|
|
154
156
|
'routes-live-rows', // bet A458: chat-made task changes streamed to open pages (runtime live-events.jsonl; read-only event stream)
|
|
155
157
|
'routes-connector-data', // connector-data (A150): what each connector reads and writes, from lib/connector-data.js (read only)
|
|
156
158
|
]);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-arch-warns.js — the architecture warning of one initiative over HTTP (idea A54, initiative arch-warns). The reading and its rules
|
|
3
|
+
* are lib/arch-warns.js; the code map it reads is code-map.json in the product's records folder (lib/records-dir.js), drawn by
|
|
4
|
+
* lib/routes-code-map.js.
|
|
5
|
+
*
|
|
6
|
+
* GET /api/arch-warns?ini=<id>&ws=<id> → { ok, warn } warn: { part, dir, what, tested, why, at, more, id, path } or null
|
|
7
|
+
*
|
|
8
|
+
* `warn` is null for everything that is not worth a line: no repository, no map yet, no such record, a record that names no part, a part
|
|
9
|
+
* the code map does not call risky, and work that is closed or done. A missing initiative is not an error, because the page asks for every
|
|
10
|
+
* initiative it opens.
|
|
11
|
+
*
|
|
12
|
+
* READ ONLY. It writes nothing, starts no code-map draw and sends nothing anywhere. The test task the ✦ offers is written by the PM's own
|
|
13
|
+
* press, through POST /api/boards/tasks/add. */
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const AW = require('./arch-warns.js');
|
|
16
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
17
|
+
|
|
18
|
+
const CHECKOUT = path.join(__dirname, '..', '..');
|
|
19
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]{0,80}$/;
|
|
20
|
+
function wsOf(ctx, ws) { try { return ctx && typeof ctx.getWs === 'function' ? ctx.getWs(ws || null) : null; } catch { return null; } }
|
|
21
|
+
const rootFor = (ctx, w) => (ctx && ctx.repoRoot) || (w && w.root) || CHECKOUT;
|
|
22
|
+
|
|
23
|
+
function handle(req, res, url, ctx) {
|
|
24
|
+
if (url.pathname !== '/api/arch-warns') return false;
|
|
25
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
26
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'GET' });
|
|
27
|
+
const ws = url.searchParams.get('ws') || null;
|
|
28
|
+
const ini = String(url.searchParams.get('ini') || '').trim();
|
|
29
|
+
if (!ID_RE.test(ini)) return send(400, { ok: false, error: 'ini is an initiative id' });
|
|
30
|
+
const dir = recordsDirFor(ctx, ws), root = rootFor(ctx, wsOf(ctx, ws));
|
|
31
|
+
let warn = null;
|
|
32
|
+
try { warn = AW.read(root, dir, ini); } catch { warn = null; } // an unreadable map or record says nothing
|
|
33
|
+
if (!warn) return send(200, { ok: true, warn: null });
|
|
34
|
+
AW.say('warned ' + ini + ': ' + warn.part + ' (' + warn.why + ')');
|
|
35
|
+
// the words live in lib/arch-warns.js, so the page, the terminal and the test all say the same thing
|
|
36
|
+
return send(200, { ok: true, warn: Object.assign({}, warn, { say: AW.sayOf(warn), note: AW.whyOf(warn, { path: warn.path }), task: AW.taskOf(warn) }) });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = { prefixes: ['/api/arch-warns'], handle };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-code-map.js — the product's code map over HTTP, for the Code panel on Work (idea A176, initiative code-map). The map and its rules
|
|
3
|
+
* are lib/code-map.js; the files are code-map.json and code-map-notes.jsonl in the product's records folder (lib/records-dir.js).
|
|
4
|
+
*
|
|
5
|
+
* GET /api/code-map?ws=<id> → { ok, map, building } map: the stored map with the PM's words on top, or null (no repository, no code,
|
|
6
|
+
* or not drawn yet); building: a redraw runs now
|
|
7
|
+
*
|
|
8
|
+
* REDRAWN ON MERGES. The GET answers from the stored map at once and never waits for git (page-open-speed). Behind it, at most once a
|
|
9
|
+
* minute per product, it reads the default branch's commit (lib/code-map.js headOf); when there is no map yet (a repository was just added)
|
|
10
|
+
* or the branch has moved past the map's commit (a merge), it draws the map again, one draw at a time per product. The panel reads again
|
|
11
|
+
* while `building` is true.
|
|
12
|
+
*
|
|
13
|
+
* READ ONLY. There is no write route: the PM's words for a part come through `pmos code describe` (the chat runs it), which writes the same
|
|
14
|
+
* notes file this route reads. Nothing is sent anywhere, and nothing in the repository is written. */
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const CM = require('./code-map.js');
|
|
17
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
18
|
+
|
|
19
|
+
const CHECK_MS = 60000;
|
|
20
|
+
const CHECKOUT = path.join(__dirname, '..', '..');
|
|
21
|
+
function wsOf(ctx, ws) { try { return ctx && typeof ctx.getWs === 'function' ? ctx.getWs(ws || null) : null; } catch { return null; } }
|
|
22
|
+
const rootFor = (ctx, w) => (ctx && ctx.repoRoot) || (w && w.root) || CHECKOUT;
|
|
23
|
+
|
|
24
|
+
/** One checker per server: per product root, the last check time and the draw in flight. */
|
|
25
|
+
function createChecker({ build = CM.build, headOf = CM.headOf, clock = () => Date.now(), every = CHECK_MS } = {}) {
|
|
26
|
+
const lastAt = new Map(), running = new Map();
|
|
27
|
+
let draws = 0;
|
|
28
|
+
function check(root, dir) {
|
|
29
|
+
if (running.has(root)) return running.get(root);
|
|
30
|
+
const t = clock();
|
|
31
|
+
if (lastAt.has(root) && t - lastAt.get(root) < every) return null;
|
|
32
|
+
lastAt.set(root, t);
|
|
33
|
+
const p = (async () => {
|
|
34
|
+
try {
|
|
35
|
+
const head = await headOf(root);
|
|
36
|
+
if (!head) return false; // not a repository (N1): nothing to draw
|
|
37
|
+
const have = CM.read(dir);
|
|
38
|
+
if (have && have.head === head.sha) return false; // the branch has not moved
|
|
39
|
+
draws++;
|
|
40
|
+
const map = await build(root);
|
|
41
|
+
if (!map) return false; // a repository with no code (N1)
|
|
42
|
+
CM.save(dir, map);
|
|
43
|
+
return true;
|
|
44
|
+
} catch { return false; } finally { running.delete(root); }
|
|
45
|
+
})();
|
|
46
|
+
running.set(root, p);
|
|
47
|
+
return p;
|
|
48
|
+
}
|
|
49
|
+
return { check, running: (root) => running.has(root), draws: () => draws };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let shared = null;
|
|
53
|
+
const checkerFor = (ctx) => (ctx && ctx.codeMapChecker) || (shared = shared || createChecker());
|
|
54
|
+
|
|
55
|
+
async function handle(req, res, url, ctx) {
|
|
56
|
+
if (url.pathname !== '/api/code-map') return false;
|
|
57
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
58
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'GET' });
|
|
59
|
+
const ws = url.searchParams.get('ws') || null;
|
|
60
|
+
const dir = recordsDirFor(ctx, ws), root = rootFor(ctx, wsOf(ctx, ws));
|
|
61
|
+
const checker = checkerFor(ctx);
|
|
62
|
+
checker.check(root, dir);
|
|
63
|
+
return send(200, { ok: true, map: CM.view(dir), building: checker.running(root) });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { prefixes: ['/api/code-map'], handle, createChecker, CHECK_MS };
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* POST /api/onboard/review { fields, jira } the PM's edits to the draft
|
|
17
17
|
* POST /api/onboard/init initialize or reuse, register, settle the fundamentals (resumable)
|
|
18
18
|
* POST /api/onboard/fundamental { key } the one-press change of one fundamentals line (lib/onboard-fundamentals.js)
|
|
19
|
+
* POST /api/onboard/starter { act, n } keep, drop or undo one starter goal (lib/starter-goals.js, job #1916); act: keep|drop|undo
|
|
19
20
|
* POST /api/onboard/reset start again (the folder and anything written stay)
|
|
20
21
|
*/
|
|
21
22
|
const fs = require('fs');
|
|
@@ -84,12 +85,14 @@ function view(ctx) {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
async function handle(req, res, url, ctx) {
|
|
87
|
-
const m = /^\/api\/onboard\/(state|own|login|check|project|folder|discover|search|review|init|fundamental|reset)$/.exec(url.pathname);
|
|
88
|
+
const m = /^\/api\/onboard\/(state|own|login|check|project|folder|discover|search|review|init|fundamental|starter|reset)$/.exec(url.pathname);
|
|
88
89
|
if (!m) return false;
|
|
89
90
|
const send = (body, code = 200) => { ctx.json(res, body, code); return true; };
|
|
90
91
|
if (!ctx.claudeSetup) return send({ ok: false, error: 'Claude setup is unavailable.' }, 503);
|
|
91
92
|
const verb = m[1];
|
|
92
|
-
|
|
93
|
+
// starter goals (A84, lib/starter-goals.js): the drafts still open for the product set up here, drawn under the fundamentals card
|
|
94
|
+
const starterOf = () => { const s0 = read(ctx); const SG = require('./starter-goals.js'); try { return s0.done && s0.done.root && ctx.getWs(s0.done.ws) ? SG.view(s0.done.root) : null; } catch { return null; } };
|
|
95
|
+
if (verb === 'state') return req.method === 'GET' ? send({ ...view(ctx), starter: starterOf() }) : send({ ok: false, error: 'GET only' }, 405);
|
|
93
96
|
if (req.method !== 'POST') return send({ ok: false, error: 'POST only' }, 405);
|
|
94
97
|
const got = await ctx.readJson(req); if (!got.ok) return send({ ok: false, error: 'Invalid JSON.' }, 400);
|
|
95
98
|
const b = got.body || {}, g = guard.requirePagePress(req, b);
|
|
@@ -99,6 +102,16 @@ async function handle(req, res, url, ctx) {
|
|
|
99
102
|
try {
|
|
100
103
|
if (verb === 'reset') { write(ctx, {}); try { fs.unlinkSync(journal(ctx)); } catch {} return send(view(ctx)); }
|
|
101
104
|
if (verb === 'own') return send(ctx.claudeSetup.ensureOwn());
|
|
105
|
+
// A84: starter goals write only the product's own goal file, so they need no Claude login check (before the bound gate)
|
|
106
|
+
if (verb === 'starter') {
|
|
107
|
+
const ws = st.done && st.done.ws && ctx.getWs(st.done.ws);
|
|
108
|
+
if (!ws || !st.done.root) return send({ ok: false, error: 'Set up the project first.', need: 'init' }, 409);
|
|
109
|
+
const act = str(b.act, 8), n = Number(b.n);
|
|
110
|
+
const o = { runtimeDir: ctx.runtimeDir, useDir: ctx.runtimeDir };
|
|
111
|
+
const SG = require('./starter-goals.js');
|
|
112
|
+
const r = act === 'keep' ? SG.keep(st.done.root, n, o) : act === 'drop' ? SG.drop(st.done.root, n, o) : act === 'undo' ? SG.undo(st.done.root, o) : { ok: false, error: 'act is keep, drop or undo' };
|
|
113
|
+
return send({ ...view(ctx), starter: starterOf(), ok: !!r.ok, error: r.ok ? undefined : r.error, starter_did: r.ok ? { act: r.act || act, n: r.n, kr: r.kr || null, file: r.file || null } : null });
|
|
114
|
+
}
|
|
102
115
|
if (verb === 'login') {
|
|
103
116
|
const dir = path.join(ctx.runtimeDir, 'onboarding', 'signin'); fs.mkdirSync(dir, { recursive: true });
|
|
104
117
|
const r = await ctx.claudeSetup.login(b.profile, null, 'login', dir);
|
|
@@ -219,9 +232,11 @@ async function handle(req, res, url, ctx) {
|
|
|
219
232
|
try { fundamentals = F.settle({ root: r.root, ws: w.id, sources: (st.found && st.found.sources) || [], fresh: !!(r.journal.steps.kit && r.journal.steps.kit.detail === 'installed'), refresh: ctx.refreshSources ? ctx.refreshSources() : F.refreshAt(ctx.runtimeDir), ...(ctx.launcher !== undefined ? { launcher: ctx.launcher } : {}) }); }
|
|
220
233
|
catch { fundamentals = { root: r.root, ws: w.id, lines: [], did: {}, error: 'Some fundamentals could not be settled. Change them in Settings.' }; }
|
|
221
234
|
}
|
|
235
|
+
// A84: starter goals drafted once from the product's own sources, right after the fundamentals; a product with goals gets none
|
|
236
|
+
try { require('./starter-goals.js').draft(r.root, { runtimeDir: ctx.runtimeDir }); } catch { /* no starter goals, setup goes on */ }
|
|
222
237
|
if (ctx.broadcast) ctx.broadcast({ t: 'focus', ws: w.id });
|
|
223
238
|
write(ctx, { ...st, init: { ok: true, steps: r.journal.steps }, fundamentals, done: { ws: w.id, name, root: r.root, context: r.journal.steps.context && r.journal.steps.context.detail, at: new Date().toISOString() } });
|
|
224
|
-
return send(view(ctx));
|
|
239
|
+
return send({ ...view(ctx), starter: starterOf() });
|
|
225
240
|
}
|
|
226
241
|
if (verb === 'fundamental') {
|
|
227
242
|
if (!st.fundamentals) return send({ ok: false, error: 'Set up the project first.', need: 'init' }, 409);
|
|
@@ -15,8 +15,9 @@ const path = require('path');
|
|
|
15
15
|
const today = require('./today.js');
|
|
16
16
|
|
|
17
17
|
module.exports = {
|
|
18
|
-
prefixes: ['/api/today'],
|
|
18
|
+
prefixes: ['/api/today', '/api/today-order'],
|
|
19
19
|
handle: async (req, res, url, ctx) => {
|
|
20
|
+
if (url.pathname === '/api/today-order') return require('./today-order.js').handle(req, res, url, ctx);
|
|
20
21
|
if (url.pathname !== '/api/today') return false;
|
|
21
22
|
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
22
23
|
const w = ctx.getWs(url.searchParams.get('ws'));
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* starter-goals.js — starter goals drafted from the product's own sources, offered once after setup (initiative starter-goals, job #1916,
|
|
3
|
+
* idea A84; board BatchMoreBDS panel 32, agreed 2026-11-25). `pmos goals …`.
|
|
4
|
+
*
|
|
5
|
+
* WHY. A new product ends setup with one drafted goal at most (lib/onboard-fundamentals.js). Generic industry packs would fill the list with
|
|
6
|
+
* goals that are not the PM's. The product's own files already say what it is for, so PMOS drafts from those and nothing else.
|
|
7
|
+
*
|
|
8
|
+
* sourcesOf(root, { runtimeDir }) → { name, goalsLine, purpose, readme, tickets, setupKr } what the drafts may come from
|
|
9
|
+
* draftsOf(sources) PURE → [{ n, kind: 'goal', text, source: { label, ref } }] at most MAX, each with a source
|
|
10
|
+
* draft(root, { runtimeDir, now }) → { ok, drafted, rows } | { ok: false, why } ONCE per product; refuses when goals exist already
|
|
11
|
+
* view(root) → { rows } the drafts still open (state 'draft'); none decided rows (zero is silence)
|
|
12
|
+
* keep(root, n) · drop(root, n) · undo(root) → { ok, … } every change of the store, from the page or `pmos goals`
|
|
13
|
+
* CLI: pmos goals [starter|draft|keep <n>|drop <n>|undo] [--json] [--root <dir>]
|
|
14
|
+
*
|
|
15
|
+
* WHERE THE DRAFTS COME FROM. Only the product's own files:
|
|
16
|
+
* - project-context.md: its "Goals and metrics" line (split into its items) and the Purpose sentence that names an aim (increase, reduce …);
|
|
17
|
+
* - the README: the bullets of a Goals / Objectives / Success section;
|
|
18
|
+
* - tickets: the "Sources read during setup" lines from a tracker (Jira, Atlassian, Linear, GitHub issues) and the product's tickets in the
|
|
19
|
+
* stored My work read (<runtime>/my-work/read.json, items whose key carries the product's Jira key). The first 40; a word that 3 or more of
|
|
20
|
+
* them name becomes "Fewer tickets about <word>", sourced as the count. No target number is ever invented (the proven-only rule).
|
|
21
|
+
* A candidate with no source label is never offered. None equals the setup draft's key result, and no two are alike.
|
|
22
|
+
*
|
|
23
|
+
* THE STORE. <state>/starter-goals.json (pmos/state in a kit): { drafted_at, rows: [{ n, kind, text, source, state, kr? }], undo: [...] }.
|
|
24
|
+
* The page and `pmos goals` read and write only this, so a chat write lands where the page reads (CHAT WRITES ALWAYS LAND).
|
|
25
|
+
* KEEP writes the draft as `- **KR-S<n>** <text>. Source: <label>.` under `## O-S — Starter goals` in planning/okrs/okrs-starter.md, which
|
|
26
|
+
* lib/okr-goals.js reads like any goal file. Until then a draft is in no goal file, so no report counts it. okrs-draft.md is never touched.
|
|
27
|
+
* Every log line carries [starter-goals]; each keep records the use-log control starterGoalKept (the health number). */
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
const path = require('path');
|
|
30
|
+
|
|
31
|
+
const TAG = '[starter-goals]';
|
|
32
|
+
const MAX = 3;
|
|
33
|
+
const TICKETS = 40;
|
|
34
|
+
const THEME_MIN = 3;
|
|
35
|
+
const STORE = 'starter-goals.json';
|
|
36
|
+
const FILE = 'okrs-starter.md';
|
|
37
|
+
const DRAFT_FILE = 'okrs-draft.md';
|
|
38
|
+
const TRACKER = /\b(jira|atlassian|linear|github issues?|tickets?)\b/i;
|
|
39
|
+
const AIM = /\b(increase|reduce|cut|grow|improve|raise|lower|double|halve|help|make|let|enable|get|reach|keep)\b/i;
|
|
40
|
+
const STOP = new Set(('a an the and or but for with from into onto over under about after before when where while this that these those '
|
|
41
|
+
+ 'their there they them then than have has had will would could should must can not no yes all any some each more most less few many '
|
|
42
|
+
+ 'make made does done doing being been were was are is its it’s it\'s our your you we us via per new add adds added update updates updated '
|
|
43
|
+
+ 'fix fixes fixed bug bugs task tasks story stories epic issue issues ticket tickets page pages user users test tests use used using also '
|
|
44
|
+
+ 'show shows when what which who why how first last next only just like into need needs should able').split(/\s+/));
|
|
45
|
+
|
|
46
|
+
const one = (s, n = 200) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
47
|
+
const clip = (s, n) => { s = one(s, 1000); return s.length > n ? s.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : s; };
|
|
48
|
+
const norm = (s) => one(s, 400).toLowerCase().replace(/[^a-z0-9 ]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
49
|
+
const day = (t) => new Date(t).toISOString().slice(0, 10);
|
|
50
|
+
const log = (o, line) => { try { (o.log || ((s) => console.error(s)))(TAG + ' ' + line); } catch { /* a log line never fails a press */ } };
|
|
51
|
+
|
|
52
|
+
function pmosIn(root) { return require('./project-onboard.js').pmosIn(root); }
|
|
53
|
+
function planningOf(root) { const pm = pmosIn(root); return pm ? pm.planning : path.join(root, 'planning'); }
|
|
54
|
+
function stateDirOf(root) { const pm = pmosIn(root); return pm && pm.kit ? path.join(pm.kit, 'state') : path.join(root, 'pmos', 'state'); }
|
|
55
|
+
const storeFile = (root) => path.join(stateDirOf(root), STORE);
|
|
56
|
+
const goalFile = (root) => path.join(planningOf(root), 'okrs', FILE);
|
|
57
|
+
function readStore(root) { try { const v = JSON.parse(fs.readFileSync(storeFile(root), 'utf8')); return v && Array.isArray(v.rows) ? v : null; } catch { return null; } }
|
|
58
|
+
function writeStore(root, v) { const f = storeFile(root); fs.mkdirSync(path.dirname(f), { recursive: true }); const tmp = f + '.tmp'; fs.writeFileSync(tmp, JSON.stringify(v, null, 1) + '\n'); fs.renameSync(tmp, f); return v; }
|
|
59
|
+
const readText = (f) => { try { return fs.readFileSync(f, 'utf8'); } catch { return null; } };
|
|
60
|
+
|
|
61
|
+
/* ── sources ── */
|
|
62
|
+
function readmeGoals(root) {
|
|
63
|
+
let names = []; try { names = fs.readdirSync(root); } catch { return null; }
|
|
64
|
+
const rn = names.find((n) => /^readme(\.md)?$/i.test(n)); if (!rn) return null;
|
|
65
|
+
const text = readText(path.join(root, rn)) || '';
|
|
66
|
+
const lines = text.split('\n');
|
|
67
|
+
const i = lines.findIndex((l) => /^#{1,3}\s+(goals?|objectives?|success( metrics| criteria)?|what success looks like)\b/i.test(l));
|
|
68
|
+
if (i < 0) return null;
|
|
69
|
+
const heading = one(lines[i].replace(/^#+\s*/, ''), 60);
|
|
70
|
+
const items = [];
|
|
71
|
+
for (let j = i + 1; j < lines.length && !/^#{1,3}\s/.test(lines[j]); j++) { const m = /^\s*[-*+]\s+(?:\[[ x]\]\s+)?(.+)$/.exec(lines[j]); if (m) items.push(one(m[1].replace(/\*\*|`/g, ''), 200)); }
|
|
72
|
+
return items.length ? { file: rn, heading, items: items.slice(0, 5) } : null;
|
|
73
|
+
}
|
|
74
|
+
function setupTickets(text) {
|
|
75
|
+
const out = []; const s = String(text || ''); const at = s.indexOf('## Sources read during setup'); if (at < 0) return out;
|
|
76
|
+
for (const m of s.slice(at).matchAll(/^- (.+?)(?: — (https:\S+))? \(([^)]+)\)$/gm)) if (TRACKER.test(m[3])) out.push({ title: one(m[1], 200), label: one(m[3], 40) });
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
function myWorkTickets(runtimeDir, key) {
|
|
80
|
+
if (!runtimeDir || !key) return [];
|
|
81
|
+
let r = null; try { r = JSON.parse(fs.readFileSync(path.join(runtimeDir, 'my-work', 'read.json'), 'utf8')); } catch { return []; }
|
|
82
|
+
const items = (r && (r.items || (r.read && r.read.items))) || [];
|
|
83
|
+
return items.filter((x) => x && new RegExp('^' + key + '-\\d+$').test(String(x.key || ''))).map((x) => ({ title: one(x.title, 200), label: 'Jira' }));
|
|
84
|
+
}
|
|
85
|
+
function sourcesOf(root, { runtimeDir = null } = {}) {
|
|
86
|
+
const P = require('./project-onboard.js');
|
|
87
|
+
const ctxText = readText(path.join(planningOf(root), 'project-context.md'));
|
|
88
|
+
const ctx = ctxText == null ? { name: '', fields: {}, jira: null, goal: null } : P.readContext(ctxText);
|
|
89
|
+
const f = ctx.fields || {};
|
|
90
|
+
const label = (v) => (v && v.source === 'finding' && v.source_label ? v.source_label + ' · project-context.md' : 'project-context.md');
|
|
91
|
+
const seen = new Set(), tickets = [];
|
|
92
|
+
for (const t of [...setupTickets(ctxText), ...myWorkTickets(runtimeDir, ctx.jira && ctx.jira.key)]) { const k = norm(t.title); if (!k || seen.has(k)) continue; seen.add(k); tickets.push(t); }
|
|
93
|
+
const draftText = readText(path.join(planningOf(root), 'okrs', DRAFT_FILE)) || '';
|
|
94
|
+
const setupKr = ((/\*\*KR1\*\*\s*(?:PROPOSED:\s*)?(.+?)\. Measure:/.exec(draftText) || [])[1]) || (ctx.goal && ctx.goal.kr) || '';
|
|
95
|
+
return { name: ctx.name || path.basename(root),
|
|
96
|
+
goalsLine: f.goals && f.goals.value ? { value: f.goals.value, label: label(f.goals) } : null,
|
|
97
|
+
purpose: f.purpose && f.purpose.value ? { value: f.purpose.value, label: 'purpose · ' + label(f.purpose) } : null,
|
|
98
|
+
readme: readmeGoals(root), tickets: tickets.slice(0, TICKETS), setupKr };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* ── drafts (PURE) ── */
|
|
102
|
+
function themes(tickets) {
|
|
103
|
+
const count = new Map();
|
|
104
|
+
for (const t of tickets || []) {
|
|
105
|
+
const words = new Set(norm(t.title).split(' ').filter((w) => w.length >= 4 && !STOP.has(w) && !/^\d+$/.test(w)));
|
|
106
|
+
for (const w of words) count.set(w, (count.get(w) || 0) + 1);
|
|
107
|
+
}
|
|
108
|
+
return [...count].filter(([, n]) => n >= THEME_MIN).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, 2);
|
|
109
|
+
}
|
|
110
|
+
function draftsOf(S = {}) {
|
|
111
|
+
const cands = [];
|
|
112
|
+
const add = (text, label, ref) => cands.push({ text: clip(String(text || '').replace(/[.;:]+$/, ''), 160), source: { label: one(label, 80), ref: one(ref, 120) } });
|
|
113
|
+
if (S.goalsLine) for (const item of String(S.goalsLine.value).split(/;|\s·\s|(?<=[a-z0-9%])\.\s+(?=[A-Z])/)) add(item, S.goalsLine.label, 'Goals and metrics');
|
|
114
|
+
if (S.readme) for (const item of S.readme.items) add(item, S.readme.file + ' · ' + S.readme.heading, S.readme.file);
|
|
115
|
+
const tickets = S.tickets || [];
|
|
116
|
+
for (const [w, n] of themes(tickets)) {
|
|
117
|
+
const where = [...new Set(tickets.map((t) => t.label))].join(', ') || 'tickets';
|
|
118
|
+
add('Fewer tickets about ' + w, `${n} of ${tickets.length} tickets in ${where} name “${w}”`, 'tickets read during setup');
|
|
119
|
+
}
|
|
120
|
+
if (S.purpose) { const s = String(S.purpose.value).split(/(?<=[.!?])\s+/).find((x) => AIM.test(x)); if (s) add(s, S.purpose.label, 'Purpose'); }
|
|
121
|
+
const out = [], seen = new Set([norm(S.setupKr)].filter(Boolean));
|
|
122
|
+
for (const c of cands) {
|
|
123
|
+
const k = norm(c.text);
|
|
124
|
+
if (!k || k.split(' ').length < 2 || seen.has(k)) continue;
|
|
125
|
+
if (!c.source.label || !c.source.ref) continue; // a draft without a source is never offered
|
|
126
|
+
seen.add(k); out.push({ n: out.length + 1, kind: 'goal', text: c.text, source: c.source });
|
|
127
|
+
if (out.length >= MAX) break;
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* ── the store ── */
|
|
133
|
+
/** Goal files other than the setup draft and this file: a product that has them gets no starter goals. */
|
|
134
|
+
function hasGoals(root) {
|
|
135
|
+
try { const r = require('./okr-goals.js').read(root); return (r.files || []).some((f) => ![DRAFT_FILE, FILE].includes(path.basename(f))) && (r.objectives || []).length > 0; }
|
|
136
|
+
catch { return false; }
|
|
137
|
+
}
|
|
138
|
+
function draft(root, o = {}) {
|
|
139
|
+
const now = o.now || Date.now();
|
|
140
|
+
const have = readStore(root);
|
|
141
|
+
if (have) return { ok: true, drafted: false, rows: have.rows.filter((r) => r.state === 'draft') };
|
|
142
|
+
if (hasGoals(root)) { log(o, `skipped root=${path.basename(root)} why=has-goals`); return { ok: false, why: 'has-goals', error: 'This product has goals already, so PMOS drafts no starter goals.' }; }
|
|
143
|
+
const rows = draftsOf(o.sources || sourcesOf(root, o)).map((r) => ({ ...r, state: 'draft' }));
|
|
144
|
+
if (!rows.length) { log(o, `none root=${path.basename(root)}`); return { ok: false, why: 'no-sources', rows: [] }; }
|
|
145
|
+
writeStore(root, { drafted_at: new Date(now).toISOString(), rows, undo: [] });
|
|
146
|
+
log(o, `drafted ${rows.length} root=${path.basename(root)} sources=${[...new Set(rows.map((r) => r.source.ref))].join('|')}`);
|
|
147
|
+
return { ok: true, drafted: true, rows };
|
|
148
|
+
}
|
|
149
|
+
function view(root) {
|
|
150
|
+
const s = readStore(root);
|
|
151
|
+
return { rows: s ? s.rows.filter((r) => r.state === 'draft').map(({ n, kind, text, source }) => ({ n, kind, text, source })) : [] };
|
|
152
|
+
}
|
|
153
|
+
const header = (name, today) => ['---', 'type: OKR', `title: "Starter goals: ${String(name).replace(/"/g, "'")}"`, `timestamp: ${today}`, '---', '',
|
|
154
|
+
`# Starter goals: ${name}`, '', `PMOS drafted these from ${name}'s own sources, and you kept each one. Change or remove a line here or in Goals.`, '',
|
|
155
|
+
'## O-S — Starter goals', ''].join('\n');
|
|
156
|
+
const krLine = (r) => `- **KR-S${r.n}** ${r.text.replace(/\n/g, ' ')}. Source: ${r.source.label}.`;
|
|
157
|
+
function rowOf(s, n) { return s && s.rows.find((r) => r.n === Number(n)); }
|
|
158
|
+
|
|
159
|
+
function keep(root, n, o = {}) {
|
|
160
|
+
const now = o.now || Date.now();
|
|
161
|
+
const s = readStore(root), r = rowOf(s, n);
|
|
162
|
+
if (!r) return { ok: false, error: 'There is no starter goal ' + n + '.' };
|
|
163
|
+
if (r.state !== 'draft') return { ok: false, error: 'Starter goal ' + n + ' was ' + (r.state === 'kept' ? 'kept' : 'dropped') + ' already.' };
|
|
164
|
+
const f = goalFile(root);
|
|
165
|
+
const before = readText(f);
|
|
166
|
+
const name = (o.sources && o.sources.name) || sourcesOf(root, o).name;
|
|
167
|
+
const line = krLine(r);
|
|
168
|
+
const after = (before == null ? header(name, day(now)) : before.replace(/\n*$/, '\n')) + line + '\n';
|
|
169
|
+
fs.mkdirSync(path.dirname(f), { recursive: true }); fs.writeFileSync(f, after);
|
|
170
|
+
r.state = 'kept'; r.kr = 'KR-S' + r.n;
|
|
171
|
+
s.undo.push({ act: 'keep', n: r.n, line, made: before == null, at: new Date(now).toISOString() });
|
|
172
|
+
writeStore(root, s);
|
|
173
|
+
log(o, `kept n=${r.n} file=${path.relative(root, f)}`);
|
|
174
|
+
try { require('./use-log.js').record(o.useDir || require('./state-root.js').defaultRoot({ env: o.env || process.env }), [{ kind: 'use', page: 'today', control: 'starterGoalKept', device: 'desk' }], now); } catch { /* a count, never a reason to fail */ }
|
|
175
|
+
return { ok: true, n: r.n, kr: r.kr, file: path.relative(root, f), rows: view(root).rows };
|
|
176
|
+
}
|
|
177
|
+
function drop(root, n, o = {}) {
|
|
178
|
+
const s = readStore(root), r = rowOf(s, n);
|
|
179
|
+
if (!r) return { ok: false, error: 'There is no starter goal ' + n + '.' };
|
|
180
|
+
if (r.state !== 'draft') return { ok: false, error: 'Starter goal ' + n + ' was ' + (r.state === 'kept' ? 'kept' : 'dropped') + ' already.' };
|
|
181
|
+
r.state = 'dropped'; s.undo.push({ act: 'drop', n: r.n, at: new Date(o.now || Date.now()).toISOString() });
|
|
182
|
+
writeStore(root, s);
|
|
183
|
+
log(o, `dropped n=${r.n}`);
|
|
184
|
+
return { ok: true, n: r.n, rows: view(root).rows };
|
|
185
|
+
}
|
|
186
|
+
function undo(root, o = {}) {
|
|
187
|
+
const s = readStore(root);
|
|
188
|
+
const last = s && s.undo[s.undo.length - 1];
|
|
189
|
+
if (!last) return { ok: false, error: 'Nothing to undo.' };
|
|
190
|
+
const r = rowOf(s, last.n);
|
|
191
|
+
if (last.act === 'keep') {
|
|
192
|
+
const f = goalFile(root), text = readText(f);
|
|
193
|
+
if (text == null || !text.split('\n').includes(last.line)) { log(o, `undo-refused n=${last.n} why=edited`); return { ok: false, error: `${path.relative(root, f)} changed since, so PMOS leaves it. Remove the line yourself if you want.` }; }
|
|
194
|
+
const after = text.split('\n').filter((l) => l !== last.line).join('\n');
|
|
195
|
+
if (last.made && !/^\s*[-*]\s*\*\*KR-/m.test(after)) fs.unlinkSync(f); else fs.writeFileSync(f, after);
|
|
196
|
+
delete r.kr;
|
|
197
|
+
}
|
|
198
|
+
r.state = 'draft'; s.undo.pop(); writeStore(root, s);
|
|
199
|
+
log(o, `undone ${last.act} n=${last.n}`);
|
|
200
|
+
return { ok: true, act: last.act, n: last.n, rows: view(root).rows };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* ── CLI ── */
|
|
204
|
+
const COMMANDS = { goals: ['starter', 'draft', 'keep', 'drop', 'undo'] };
|
|
205
|
+
const USAGE = [
|
|
206
|
+
'pmos goals — starter goals PMOS drafts from your own product (its project context, README and tickets)',
|
|
207
|
+
' pmos goals starter the open drafts, each with its source (the same rows as the setup page)',
|
|
208
|
+
' pmos goals draft draft them once, when the product has no goals beyond the setup draft',
|
|
209
|
+
' pmos goals keep <n> keep draft n: it becomes key result KR-S<n> in planning/okrs/okrs-starter.md',
|
|
210
|
+
' pmos goals drop <n> drop draft n; it writes no goal',
|
|
211
|
+
' pmos goals undo undo the newest keep or drop',
|
|
212
|
+
'A draft counts in no report until you keep it. Nothing is sent.',
|
|
213
|
+
];
|
|
214
|
+
function repoOf(cwd) {
|
|
215
|
+
let d = path.resolve(cwd);
|
|
216
|
+
for (;;) { if (fs.existsSync(path.join(d, '.git')) || pmosIn(d)) return d; const up = path.dirname(d); if (up === d) return path.resolve(cwd); d = up; }
|
|
217
|
+
}
|
|
218
|
+
function run(argv, o = {}) {
|
|
219
|
+
const say = o.say || ((s) => console.log(s));
|
|
220
|
+
const args = argv[0] === 'goals' ? argv.slice(1) : argv.slice();
|
|
221
|
+
const pos = [], flags = {};
|
|
222
|
+
for (let i = 0; i < args.length; i++) { const a = args[i]; if (a === '--root') flags.root = args[++i]; else if (a === '--json') flags.json = true; else pos.push(a); }
|
|
223
|
+
const cmd = pos[0] || 'starter';
|
|
224
|
+
if (cmd === 'help' || cmd === '--help') { USAGE.forEach((l) => say(l)); return 0; }
|
|
225
|
+
if (!COMMANDS.goals.includes(cmd)) { say(`✗ ${cmd} is not a command of pmos goals`); USAGE.forEach((l) => say(l)); return 2; }
|
|
226
|
+
const root = path.resolve(flags.root || o.root || repoOf(o.cwd || process.cwd()));
|
|
227
|
+
const opts = { ...o, runtimeDir: o.runtimeDir || (() => { try { return require('./state-root.js').defaultRoot({ env: o.env || process.env }); } catch { return null; } })() };
|
|
228
|
+
const r = cmd === 'starter' ? { ok: true, ...view(root) } : cmd === 'draft' ? draft(root, opts) : cmd === 'undo' ? undo(root, opts)
|
|
229
|
+
: (pos[1] == null ? { ok: false, error: `Say which draft: pmos goals ${cmd} <n>` } : (cmd === 'keep' ? keep : drop)(root, pos[1], opts));
|
|
230
|
+
if (flags.json) { say(JSON.stringify(r)); return r.ok ? 0 : 1; }
|
|
231
|
+
if (!r.ok) { say('✗ ' + (r.error || (r.why === 'no-sources' ? 'No source of this product names a goal yet, so PMOS drafts none.' : 'That did not work.'))); return 1; }
|
|
232
|
+
if (cmd === 'keep') say(`✓ Kept as ${r.kr} in ${r.file}. pmos goals undo takes it out again.`);
|
|
233
|
+
if (cmd === 'drop') say(`✓ Dropped starter goal ${r.n}. pmos goals undo brings it back.`);
|
|
234
|
+
if (cmd === 'undo') say(`✓ Undid the ${r.act} of starter goal ${r.n}.`);
|
|
235
|
+
const rows = r.rows || [];
|
|
236
|
+
if (cmd === 'starter' || cmd === 'draft') {
|
|
237
|
+
if (!rows.length) { say('No starter goals are open.'); return 0; }
|
|
238
|
+
for (const x of rows) say(`${x.n}. ${x.text} (from: ${x.source.label})`);
|
|
239
|
+
say('pmos goals keep <n> or drop <n>.');
|
|
240
|
+
}
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
module.exports = { TAG, MAX, TICKETS, THEME_MIN, FILE, sourcesOf, draftsOf, themes, draft, view, keep, drop, undo, hasGoals, run, COMMANDS, USAGE, storeFile, goalFile };
|
|
@@ -15,7 +15,7 @@ const { execFileSync } = require('child_process');
|
|
|
15
15
|
const today = require('./today.js');
|
|
16
16
|
const { parseArgs } = require('./schedule-cli');
|
|
17
17
|
|
|
18
|
-
const COMMANDS = { today: [] };
|
|
18
|
+
const COMMANDS = { today: ['order'] };
|
|
19
19
|
const USAGE = [
|
|
20
20
|
'usage: pmos today [--ws <id>] [--json]',
|
|
21
21
|
' pmos today --root <dir> [--json] [--wait]',
|
|
@@ -27,6 +27,7 @@ const USAGE = [
|
|
|
27
27
|
'repair). It does not read sessions then.',
|
|
28
28
|
'Without a server it reads the initiative records first when there are up to 100. With more, the Cycle review and',
|
|
29
29
|
'missing-anchor cards show as pending: add --wait to read them now (about 5 s for 500 records).',
|
|
30
|
+
'pmos today order [--pin <kind>|<blocks>] [--unpin] [--json]: the order of Today\'s blocks, and the pin Today reads (lib/today-order.js).',
|
|
30
31
|
];
|
|
31
32
|
const BOOL = new Set(['json', 'help', 'wait']);
|
|
32
33
|
const VALUE = new Set(['ws', 'root']);
|
|
@@ -118,7 +119,8 @@ function print(say, out, { sessions }) {
|
|
|
118
119
|
if (!sessions) say('No server is running, so waiting sessions were not read.');
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
async function run(argv, { say, call }) {
|
|
122
|
+
async function run(argv, { say, call, runtimeDir }) {
|
|
123
|
+
if (argv[1] === 'order') return require('./today-order.js').run(argv.slice(1), { say, runtimeDir }); // today-order (A310): the pin
|
|
122
124
|
const rest = []; const bools = {};
|
|
123
125
|
for (const a of argv.slice(1)) {
|
|
124
126
|
if (a.startsWith('--') && BOOL.has(a.slice(2))) bools[a.slice(2)] = true;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* today-order.js — Today rearranges to the day (idea A310, job #1914; board BatchMoreBDS panel 30; done test
|
|
3
|
+
* planning/done-tests/today-order.md). The pin: the one store the page and `pmos today order` read and write.
|
|
4
|
+
*
|
|
5
|
+
* public/pm/today-order.js decides the order from the calendar and what ships (pure; the page and this file import it). This file keeps
|
|
6
|
+
* only the PIN: an order the PM keeps until they unpin it. One small file, <runtime>/today-order/pin.json:
|
|
7
|
+
* { order: [block, …], kind: launch | meetings | monday | friday | own, at }
|
|
8
|
+
* It holds block names and a time only. A pin is repaired on read (whole()): an unknown block is left out and a missing one is put back,
|
|
9
|
+
* so a block never disappears from Today.
|
|
10
|
+
*
|
|
11
|
+
* read(runtimeDir) → { ok, pin: { order, kind, at } | null }
|
|
12
|
+
* pin(runtimeDir, { order, kind }, now) → { ok, pin } | { ok: false, error } (async: it reads the block names from the page module)
|
|
13
|
+
* unpin(runtimeDir) → { ok, pin: null }
|
|
14
|
+
* handle(req, res, url, ctx) GET /api/today-order → read; POST /api/today-order { order, kind } | { unpin: true } (page press)
|
|
15
|
+
* run(argv, { say, runtimeDir }) `pmos today order [--pin <a,b,c,d>|--pin <kind>] [--unpin] [--json]`
|
|
16
|
+
* SINGLE WRITER: put() writes the file, by a rename, so a half-written pin is never read. Each pin and unpin logs one `[today-order]` line.
|
|
17
|
+
*/
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const { pathToFileURL } = require('url');
|
|
21
|
+
|
|
22
|
+
const TAG = '[today-order]';
|
|
23
|
+
let MOD = null;
|
|
24
|
+
/** The page's pure module (BLOCKS, ORDERS, LABEL, whole): one source for the blocks and the day's orders. */
|
|
25
|
+
const mod = async () => (MOD = MOD || await import(pathToFileURL(path.join(__dirname, '..', 'public', 'pm', 'today-order.js')).href));
|
|
26
|
+
|
|
27
|
+
const fileOf = (rt) => path.join(rt, 'today-order', 'pin.json');
|
|
28
|
+
function put(rt, v) {
|
|
29
|
+
const f = fileOf(rt);
|
|
30
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
31
|
+
if (v == null) { try { fs.unlinkSync(f); } catch { /* already unpinned */ } return; }
|
|
32
|
+
const tmp = f + '.' + process.pid + '.tmp';
|
|
33
|
+
fs.writeFileSync(tmp, JSON.stringify(v) + '\n');
|
|
34
|
+
fs.renameSync(tmp, f);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function read(rt) {
|
|
38
|
+
if (!rt) return { ok: true, pin: null };
|
|
39
|
+
let v = null;
|
|
40
|
+
try { v = JSON.parse(fs.readFileSync(fileOf(rt), 'utf8')); } catch { return { ok: true, pin: null }; }
|
|
41
|
+
if (!v || !Array.isArray(v.order)) return { ok: true, pin: null };
|
|
42
|
+
return { ok: true, pin: { order: v.order.filter((x) => typeof x === 'string').slice(0, 8), kind: typeof v.kind === 'string' ? v.kind : 'own', at: typeof v.at === 'string' ? v.at : '' } };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function pin(rt, body = {}, now = new Date()) {
|
|
46
|
+
const M = await mod();
|
|
47
|
+
if (!rt) return { ok: false, error: 'no runtime folder to keep the pin in' };
|
|
48
|
+
const kind = body.kind == null || body.kind === '' ? 'own' : String(body.kind);
|
|
49
|
+
if (!M.KINDS.includes(kind)) return { ok: false, error: `${kind} is not a kind of day: ${M.KINDS.join(', ')}` };
|
|
50
|
+
const given = Array.isArray(body.order) ? body.order : kind !== 'own' ? M.ORDERS[kind] : null;
|
|
51
|
+
if (!given || !given.length) return { ok: false, error: 'name the order to pin: the blocks ' + M.BLOCKS.join(', ') + ', or a kind of day' };
|
|
52
|
+
const bad = given.find((b) => !M.BLOCKS.includes(b));
|
|
53
|
+
if (bad) return { ok: false, error: `${bad} is not a block of Today: ${M.BLOCKS.join(', ')}` };
|
|
54
|
+
const v = { order: M.whole(given), kind, at: now.toISOString() };
|
|
55
|
+
put(rt, v);
|
|
56
|
+
console.info(`${TAG} pinned kind=${kind} order=${v.order.join(',')}`);
|
|
57
|
+
return { ok: true, pin: v };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function unpin(rt) {
|
|
61
|
+
if (!rt) return { ok: false, error: 'no runtime folder to keep the pin in' };
|
|
62
|
+
put(rt, null);
|
|
63
|
+
console.info(`${TAG} unpinned`);
|
|
64
|
+
return { ok: true, pin: null };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** GET /api/today-order and POST /api/today-order (routes-today.js hands it on). A POST is a page press. */
|
|
68
|
+
async function handle(req, res, url, ctx) {
|
|
69
|
+
if (url.pathname !== '/api/today-order') return false;
|
|
70
|
+
const rt = ctx.runtimeDir;
|
|
71
|
+
if (req.method === 'GET') { ctx.json(res, read(rt)); return true; }
|
|
72
|
+
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'GET or POST only' }, 405); return true; }
|
|
73
|
+
const got = await ctx.readJson(req);
|
|
74
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
|
|
75
|
+
const body = got.body || {};
|
|
76
|
+
const g = require('./pm-guard.js').requirePagePress(req, body);
|
|
77
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
78
|
+
const out = body.unpin === true ? unpin(rt) : await pin(rt, body);
|
|
79
|
+
ctx.json(res, out, out.ok ? 200 : 400);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const USAGE = [
|
|
84
|
+
'usage: pmos today order [--json]',
|
|
85
|
+
' pmos today order --pin <kind>|<block,block,…>',
|
|
86
|
+
' pmos today order --unpin',
|
|
87
|
+
'Today keeps the same blocks (overview, move, log, agenda) and orders them to the day: launch day, 3 or more meetings, Monday, Friday.',
|
|
88
|
+
'A pinned order wins over the day until you unpin it. The page reads the same pin.',
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
async function run(argv, { say, runtimeDir } = {}) {
|
|
92
|
+
const M = await mod();
|
|
93
|
+
let rt = runtimeDir;
|
|
94
|
+
if (rt === undefined) { try { rt = require('./state-root.js').defaultRoot({ env: process.env }); } catch { rt = null; } }
|
|
95
|
+
const a = argv[0] === 'order' ? argv.slice(1) : argv.slice();
|
|
96
|
+
const f = { json: false, unpin: false, pin: null };
|
|
97
|
+
for (let i = 0; i < a.length; i++) {
|
|
98
|
+
if (a[i] === '--json') f.json = true;
|
|
99
|
+
else if (a[i] === '--unpin') f.unpin = true;
|
|
100
|
+
else if (a[i] === '--pin' && a[i + 1] && !a[i + 1].startsWith('--')) f.pin = a[++i];
|
|
101
|
+
else if (a[i] === '--help' || a[i] === '-h') { USAGE.forEach((l) => say(l)); return 0; }
|
|
102
|
+
else { say(`✗ ${a[i]} is not an option of pmos today order`); USAGE.forEach((l) => say(l)); return 2; }
|
|
103
|
+
}
|
|
104
|
+
if (f.pin && f.unpin) { say('✗ --pin and --unpin: use one'); return 2; }
|
|
105
|
+
let out;
|
|
106
|
+
if (f.unpin) out = unpin(rt);
|
|
107
|
+
else if (f.pin) out = await pin(rt, M.KINDS.includes(f.pin) ? { kind: f.pin } : { order: f.pin.split(',').map((x) => x.trim()).filter(Boolean) });
|
|
108
|
+
else out = read(rt);
|
|
109
|
+
if (!out.ok) { say('✗ ' + out.error); return 1; }
|
|
110
|
+
if (f.pin || f.unpin) try { require('./use-log.js').record(rt, [{ kind: 'use', page: 'today', control: 'todayOrderPin', device: 'desk' }]); } catch { /* the use log is a count only */ }
|
|
111
|
+
if (f.json) { say(JSON.stringify({ ok: true, pin: out.pin, blocks: M.BLOCKS, days: M.ORDERS })); return 0; }
|
|
112
|
+
if (out.pin) say(`Pinned · the order for ${M.LABEL[out.pin.kind] || M.LABEL.own}: ${M.whole(out.pin.order).join(', ')}`);
|
|
113
|
+
else {
|
|
114
|
+
say('Not pinned: Today orders itself to the day.');
|
|
115
|
+
for (const k of Object.keys(M.ORDERS)) say(` ${M.LABEL[k]}: ${M.ORDERS[k].join(', ')}`);
|
|
116
|
+
}
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { read, pin, unpin, handle, run, USAGE, TAG, fileOf };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.827.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.827.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED