create-pmos 0.729.0 → 0.731.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 +28 -34
- package/payload/KIT-VERSION +1 -1
- package/payload/design-system/brand/icons.json +59 -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/changelog.json +27 -2
- package/workspace/design-system/brand/icons.json +59 -0
- package/workspace/guide/agent-capabilities.md +1 -0
- package/workspace/guide/cli.md +15 -0
- package/workspace/guide/initiatives-and-next-steps.md +9 -1
- package/workspace/guide/layout.md +2 -0
- package/workspace/lib/headless.js +1 -0
- package/workspace/lib/icon-check.js +280 -0
- package/workspace/lib/initiative-cli.js +61 -2
- package/workspace/lib/initiative-premium.js +1 -1
- package/workspace/lib/job-graph.js +1 -0
- package/workspace/lib/kind-scope.js +33 -5
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/principles-cli.js +109 -0
- package/workspace/lib/principles.js +165 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-principles.js +109 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/agenda-live.js +1 -1
- package/workspace/public/pm/bd-principles.js +64 -0
- package/workspace/public/pm/bd-span.js +1 -1
- package/workspace/public/pm/bd-sprint-ds.js +1 -1
- package/workspace/public/pm/bd-sprint.js +1 -1
- package/workspace/public/pm/bd-work.js +1 -1
- package/workspace/public/pm/cozy-day-pick.js +1 -1
- package/workspace/public/pm/cozy-events-view.js +1 -1
- package/workspace/public/pm/cozy-popup.js +1 -1
- package/workspace/public/pm/cozy-rec-present.js +1 -1
- package/workspace/public/pm/goal-chat.js +1 -1
- package/workspace/public/pm/home-chat.js +1 -1
- package/workspace/public/pm/home-rec-row.js +1 -1
- package/workspace/public/pm/home-today.js +3 -3
- package/workspace/public/pm/ini-agent.js +1 -1
- package/workspace/public/pm/ini-edit.js +2 -2
- package/workspace/public/pm/ini-groups.js +1 -1
- package/workspace/public/pm/ini-versions.js +1 -1
- package/workspace/public/pm/ini-view.js +2 -2
- package/workspace/public/pm/intent.js +2 -2
- package/workspace/public/pm/okr-list.js +2 -2
- package/workspace/public/pm/pinned-views.js +1 -1
- package/workspace/public/pm/premium-board.js +2 -0
- package/workspace/public/pm/premium-initiative-head.js +14 -3
- package/workspace/public/pm/premium-insights.js +3 -3
- package/workspace/public/pm/premium-mtg-present.js +2 -2
- package/workspace/public/pm/premium-mtg-replay.js +1 -1
- package/workspace/public/pm/premium-shell.js +1 -1
- package/workspace/public/pm/premium-vw-mtg.js +1 -1
- package/workspace/public/pm/premium-vw-slides.js +3 -3
- package/workspace/public/pm/task-card.js +1 -1
- package/workspace/public/pm/wf-page.js +1 -1
- package/workspace/public/premium-board.html +2 -0
- package/workspace/public/premium-events.html +2 -2
- package/workspace/skills/principles-draft.skill +23 -0
- package/workspace/test-lists/icon-check.json +9 -0
- package/workspace/test-lists/principles.json +9 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* icon-check.js — one icon per action (initiative icon-consistency-check, bet A414).
|
|
3
|
+
*
|
|
4
|
+
* The design system names one icon for each action (brand/icons.json: the action, the words of its labels, and the icon's
|
|
5
|
+
* shapes). This module reads the pages of a product, finds every control whose label names an action and that draws an
|
|
6
|
+
* icon, and reports:
|
|
7
|
+
* off a control that draws its action with another icon than the one icons.json names (the count the check keeps at 0)
|
|
8
|
+
* mixed an action drawn with more than one icon, listed or not (the hint for the next entry of icons.json)
|
|
9
|
+
* shared one icon that stands for two listed actions (an icon means one thing)
|
|
10
|
+
*
|
|
11
|
+
* It reads source text only: a button, link or span with an aria-label or title, and the first icon inside it. The icon is
|
|
12
|
+
* an inline <svg>, or a ${…} call whose argument is path data, or a name in an icon table of the same file or of a file it
|
|
13
|
+
* imports. An icon it cannot resolve is counted as `unread`, never guessed. Two drawings of the same lines in another order
|
|
14
|
+
* or direction are the same icon.
|
|
15
|
+
*
|
|
16
|
+
* loadRegistry(read) · actionOf(label, reg) · canon(markup) · scanText(text, file, tableOf) · check(repo, ref, opts) · count(…)
|
|
17
|
+
* node lib/icon-check.js check [--root <dir>] [--json] [--gate] the report; --gate exits 1 when an icon is off
|
|
18
|
+
* node lib/icon-check.js count [--days 7] [--root <dir>] the runs of the check in the last days (the health number)
|
|
19
|
+
*
|
|
20
|
+
* A product sets its own icons in pmos/design-system/brand/icons.json; PMOS's own copy is the default. `scan` in that file
|
|
21
|
+
* names the folders to read. Every run writes `[icon-check] run` to stderr and one line to pmos/state/icon-check.jsonl.
|
|
22
|
+
*/
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
const D = require('./design-drift.js');
|
|
26
|
+
|
|
27
|
+
const OWN = path.join(__dirname, '..', 'design-system', 'brand', 'icons.json');
|
|
28
|
+
const REG_PLACES = ['pmos/design-system/brand/icons.json', 'workspace/design-system/brand/icons.json'];
|
|
29
|
+
const LOG = 'pmos/state/icon-check.jsonl';
|
|
30
|
+
const SKIP_DIR = /(^|\/)(node_modules|vendor|third-party|dist|build|\.git)\//;
|
|
31
|
+
|
|
32
|
+
// ── the registry ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
/** The product's icons.json, else PMOS's own. read(p) → text|null for a repo path. */
|
|
35
|
+
function loadRegistry(read) {
|
|
36
|
+
let text = null;
|
|
37
|
+
for (const p of REG_PLACES) { text = read ? read(p) : null; if (text != null) break; }
|
|
38
|
+
if (text == null) text = fs.readFileSync(OWN, 'utf8');
|
|
39
|
+
const raw = JSON.parse(text);
|
|
40
|
+
const actions = {};
|
|
41
|
+
for (const [name, a] of Object.entries(raw.actions || {})) {
|
|
42
|
+
actions[name] = { name, words: (a.words || [name]).map(norm), except: (a.except || []).map(norm), svg: a.svg, icon: canon(a.svg), lucide: a.lucide || null };
|
|
43
|
+
}
|
|
44
|
+
return { actions, scan: raw.scan || ['workspace/public', 'src', 'app', 'public', 'web'] };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The action a label names: its first words match one of an action's words. 'Close the viewer' → 'close'. */
|
|
48
|
+
const norm = (s) => String(s || '').toLowerCase().replace(/[^a-z0-9 ]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
49
|
+
function actionOf(label, reg) {
|
|
50
|
+
const l = ' ' + norm(label) + ' ';
|
|
51
|
+
let best = null, len = 0;
|
|
52
|
+
for (const a of Object.values(reg.actions)) {
|
|
53
|
+
if ((a.except || []).some((x) => l.startsWith(' ' + x + ' '))) continue;
|
|
54
|
+
for (const w of a.words) if (l.startsWith(' ' + w + ' ') && w.length > len) { best = a.name; len = w.length; }
|
|
55
|
+
}
|
|
56
|
+
return best;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── the shape of an icon ──────────────────────────────────────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
const r2 = (n) => String(Math.round(Number(n) * 100) / 100);
|
|
62
|
+
const attr = (tag, k) => { const m = tag.match(new RegExp(`\\s${k}="([^"]*)"`)); return m ? m[1] : null; };
|
|
63
|
+
|
|
64
|
+
/** Path data → canonical pieces: each straight segment as a sorted point pair, each curve or arc as its absolute command. */
|
|
65
|
+
function pathPieces(d) {
|
|
66
|
+
const toks = String(d).match(/[a-zA-Z]|-?(?:\d*\.\d+|\d+)(?:e-?\d+)?/g) || [];
|
|
67
|
+
const out = [];
|
|
68
|
+
let i = 0, cmd = null, x = 0, y = 0, sx = 0, sy = 0;
|
|
69
|
+
const num = () => Number(toks[i++]);
|
|
70
|
+
const isNum = () => i < toks.length && !/^[a-zA-Z]$/.test(toks[i]);
|
|
71
|
+
const seg = (x1, y1, x2, y2) => { if (x1 === x2 && y1 === y2) return; const a = `${r2(x1)},${r2(y1)}`, b = `${r2(x2)},${r2(y2)}`; out.push('L' + (a < b ? a + ' ' + b : b + ' ' + a)); };
|
|
72
|
+
while (i < toks.length) {
|
|
73
|
+
if (/^[a-zA-Z]$/.test(toks[i])) cmd = toks[i++];
|
|
74
|
+
if (!cmd) { i++; continue; }
|
|
75
|
+
const rel = cmd === cmd.toLowerCase();
|
|
76
|
+
const C = cmd.toUpperCase();
|
|
77
|
+
if (C === 'Z') { seg(x, y, sx, sy); x = sx; y = sy; if (!isNum()) continue; }
|
|
78
|
+
if (!isNum()) { if (C !== 'Z') i++; continue; }
|
|
79
|
+
if (C === 'M') { let nx = num(), ny = num(); if (rel) { nx += x; ny += y; } x = sx = nx; y = sy = ny; cmd = rel ? 'l' : 'L'; }
|
|
80
|
+
else if (C === 'L') { let nx = num(), ny = num(); if (rel) { nx += x; ny += y; } seg(x, y, nx, ny); x = nx; y = ny; }
|
|
81
|
+
else if (C === 'H') { let nx = num(); if (rel) nx += x; seg(x, y, nx, y); x = nx; }
|
|
82
|
+
else if (C === 'V') { let ny = num(); if (rel) ny += y; seg(x, y, x, ny); y = ny; }
|
|
83
|
+
else {
|
|
84
|
+
const n = { C: 6, S: 4, Q: 4, T: 2, A: 7 }[C];
|
|
85
|
+
if (!n) { i++; continue; }
|
|
86
|
+
const v = []; for (let k = 0; k < n; k++) v.push(num());
|
|
87
|
+
const abs = v.slice();
|
|
88
|
+
if (rel) { if (C === 'A') { abs[5] += x; abs[6] += y; } else for (let k = 0; k < n; k += 2) { abs[k] += x; abs[k + 1] += y; } }
|
|
89
|
+
out.push(C + r2(x) + ',' + r2(y) + ' ' + abs.map(r2).join(','));
|
|
90
|
+
x = abs[n - 2]; y = abs[n - 1];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A rect as path data, so `<rect>` and the same square drawn as a path are one icon. */
|
|
97
|
+
function rectPath(x, y, w, h, rx) {
|
|
98
|
+
const r = Math.min(rx, w / 2, h / 2);
|
|
99
|
+
if (!r) return `M${x} ${y}H${x + w}V${y + h}H${x}Z`;
|
|
100
|
+
return `M${x + r} ${y}H${x + w - r}A${r} ${r} 0 0 1 ${x + w} ${y + r}V${y + h - r}A${r} ${r} 0 0 1 ${x + w - r} ${y + h}`
|
|
101
|
+
+ `H${x + r}A${r} ${r} 0 0 1 ${x} ${y + h - r}V${y + r}A${r} ${r} 0 0 1 ${x + r} ${y}Z`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The canonical key of an icon's markup (its shapes only: size, stroke and class do not count). '' when it has no shape. */
|
|
105
|
+
function canon(markup) {
|
|
106
|
+
const pieces = [];
|
|
107
|
+
for (const m of String(markup || '').matchAll(/<(path|rect|circle|line|polyline|polygon|ellipse)\b([^>]*)>/g)) {
|
|
108
|
+
const [tag, kind] = [m[0], m[1]];
|
|
109
|
+
if (kind === 'path') pieces.push(...pathPieces(attr(tag, 'd') || ''));
|
|
110
|
+
else if (kind === 'line') pieces.push(...pathPieces(`M${attr(tag, 'x1')} ${attr(tag, 'y1')}L${attr(tag, 'x2')} ${attr(tag, 'y2')}`));
|
|
111
|
+
else if (kind === 'polyline' || kind === 'polygon') pieces.push(...pathPieces('M' + (attr(tag, 'points') || '') + (kind === 'polygon' ? 'Z' : '')));
|
|
112
|
+
else if (kind === 'circle') pieces.push(`O${r2(attr(tag, 'cx') || 0)},${r2(attr(tag, 'cy') || 0)},${r2(attr(tag, 'r') || 0)}`);
|
|
113
|
+
else if (kind === 'ellipse') pieces.push(`E${r2(attr(tag, 'cx') || 0)},${r2(attr(tag, 'cy') || 0)},${r2(attr(tag, 'rx') || 0)},${r2(attr(tag, 'ry') || 0)}`);
|
|
114
|
+
else pieces.push(...pathPieces(rectPath(...['x', 'y', 'width', 'height'].map((k) => Number(attr(tag, k) || 0)), Number(attr(tag, 'rx') || attr(tag, 'ry') || 0))));
|
|
115
|
+
}
|
|
116
|
+
return [...new Set(pieces)].sort().join(' ');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── reading a page ────────────────────────────────────────────────────────────────────────────────────────────────
|
|
120
|
+
|
|
121
|
+
const GEOM = /^\s*[Mm]\s*-?[\d.]/;
|
|
122
|
+
const asMarkup = (s) => (GEOM.test(s) ? `<path d="${s}"/>` : /<(path|rect|circle|line|polyline|polygon|ellipse)\b/.test(s) ? s : null);
|
|
123
|
+
|
|
124
|
+
/** The icon tables of one file: every `name: '<path data or shapes>'` (or `const NAME = '…'`). → Map name → markup */
|
|
125
|
+
function tablesOf(text) {
|
|
126
|
+
const t = new Map();
|
|
127
|
+
for (const m of text.matchAll(/(?:^|[\s,{])['"]?([A-Za-z_$][\w$-]*)['"]?\s*:\s*(['"`])((?:(?!\2)[^\\]|\\.)*)\2/g)) {
|
|
128
|
+
const mk = asMarkup(m[3]); if (mk && !t.has(m[1])) t.set(m[1], mk);
|
|
129
|
+
}
|
|
130
|
+
for (const m of text.matchAll(/(?:\b(?:const|let|var)\s+|,\s*)([A-Za-z_$][\w$]*)\s*=\s*(['"`])((?:(?!\2)[^\\]|\\.)*)\2/g)) {
|
|
131
|
+
const mk = asMarkup(m[3]); if (mk && !t.has(m[1])) t.set(m[1], mk);
|
|
132
|
+
}
|
|
133
|
+
return t;
|
|
134
|
+
}
|
|
135
|
+
const importsOf = (text) => [...text.matchAll(/\bfrom\s+['"](\.{1,2}\/[^'"]+)['"]/g)].map((m) => m[1]);
|
|
136
|
+
|
|
137
|
+
/** One `${…}` expression → { markup } | { unread } | null (not an icon call). */
|
|
138
|
+
function iconOfExpr(e, lookup) {
|
|
139
|
+
if (!/^\s*[A-Za-z_$][\w$.]*\s*\(|^\s*[A-Za-z_$][\w$]*\s*(\.|\[)/.test(e)) return null;
|
|
140
|
+
for (const s of e.matchAll(/(['"`])((?:(?!\1)[^\\$]|\\.)*)\1/g)) { const mk = asMarkup(s[2]); if (mk) return { markup: mk }; }
|
|
141
|
+
const names = [...e.matchAll(/\.([A-Za-z_$][\w$]*)|\[\s*['"]([\w$-]+)['"]\s*\]|\(\s*['"]([\w$-]+)['"]/g)].map((m) => m[1] || m[2] || m[3]);
|
|
142
|
+
const bare = e.match(/^\s*[A-Za-z_$][\w$]*\s*\(\s*([A-Za-z_$][\w$]*)\s*[,)]/);
|
|
143
|
+
if (bare) names.push(bare[1]);
|
|
144
|
+
for (const n of names) { const mk = lookup(n); if (mk) return { markup: mk }; }
|
|
145
|
+
return { unread: e.trim().slice(0, 60) };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The icons a control's inner text draws, in order: inline <svg> or `${…}` icon calls. → [{ markup } | { unread }] */
|
|
149
|
+
function iconsIn(inner, lookup) {
|
|
150
|
+
const out = [];
|
|
151
|
+
const re = /<svg\b[\s\S]*?<\/svg>|\$\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}/g;
|
|
152
|
+
let m;
|
|
153
|
+
while ((m = re.exec(inner)) && out.length < 4) {
|
|
154
|
+
if (m[0].startsWith('<svg')) { if (canon(m[0])) out.push({ markup: m[0] }); else { const ex = m[0].match(/\$\{([^{}]*)\}/); const r = ex ? iconOfExpr(ex[1], lookup) : null; if (r) out.push(r); } }
|
|
155
|
+
else { const r = iconOfExpr(m[1], lookup); if (r) out.push(r); }
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Every labelled control that draws an icon in one file. → [{ file, line, label, icons: [{ markup } | { unread }] }] */
|
|
161
|
+
function scanText(text, file, lookup = () => null) {
|
|
162
|
+
const out = [];
|
|
163
|
+
const re = /<(button|a|span)\b((?:[^>"'`]|"[^"]*"|'[^']*')*?)\s(?:aria-label|title)="([^"]{1,80})"((?:[^>"'`]|"[^"]*"|'[^']*')*)>([\s\S]{0,600}?)<\/\1>/g;
|
|
164
|
+
let m;
|
|
165
|
+
while ((m = re.exec(text))) {
|
|
166
|
+
const label = m[3];
|
|
167
|
+
if (/^\$\{[^}]*\}$/.test(label.trim())) continue;
|
|
168
|
+
const head = m[5].search(/<(button|a)\b/);
|
|
169
|
+
const icons = iconsIn(head >= 0 ? m[5].slice(0, head) : m[5], lookup);
|
|
170
|
+
if (head >= 0) re.lastIndex = m.index + 1; // a control nested inside: read it as itself on the next match
|
|
171
|
+
if (!icons.length) continue;
|
|
172
|
+
const line = text.slice(0, m.index).split('\n').length;
|
|
173
|
+
out.push({ file, line, label: label.replace(/\$\{[^}]*\}/g, '…'), icons });
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ── the check ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
179
|
+
|
|
180
|
+
const isPage = (p, scan) => /\.(m?js|html|jsx|tsx|vue|svelte)$/.test(p) && !SKIP_DIR.test(p) && !/\.test\.|(^|\/)test[-.]/.test(p)
|
|
181
|
+
&& scan.some((d) => p === d || p.startsWith(d.replace(/\/$/, '') + '/'));
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Check one commit (or the files on disk). opts.files: { path: text } instead of git (tests).
|
|
185
|
+
* → { ref, uses, off: [use], mixed: [{ action, listed, icons: [{ icon, uses }] }], shared: [{ icon, actions }], unread, total }
|
|
186
|
+
*/
|
|
187
|
+
function check(repo, ref = 'WORKTREE', { files: given, registry } = {}) {
|
|
188
|
+
let all, read;
|
|
189
|
+
if (given) { all = Object.keys(given); read = (p) => (p in given ? given[p] : null); }
|
|
190
|
+
else { const R = D.readerOf(repo, ref); all = R.list(); read = R.read; }
|
|
191
|
+
const reg = registry || loadRegistry(read);
|
|
192
|
+
const pages = all.filter((p) => isPage(p, reg.scan)).sort();
|
|
193
|
+
const texts = given ? new Map(pages.map((p) => [p, given[p]])) : D.readMany(repo, ref === 'WORKTREE' ? null : ref, pages);
|
|
194
|
+
const tables = new Map();
|
|
195
|
+
const tableOf = (p) => { if (!tables.has(p)) tables.set(p, texts.has(p) ? tablesOf(texts.get(p)) : new Map()); return tables.get(p); };
|
|
196
|
+
const uses = [];
|
|
197
|
+
for (const p of pages) {
|
|
198
|
+
const text = texts.get(p); if (text == null) continue;
|
|
199
|
+
const near = [p, ...importsOf(text).map((i) => path.posix.normalize(path.posix.join(path.posix.dirname(p), i)))];
|
|
200
|
+
const lookup = (n) => { for (const q of near) { const mk = tableOf(q).get(n); if (mk) return mk; } return null; };
|
|
201
|
+
for (const u of scanText(text, p, lookup)) {
|
|
202
|
+
u.action = actionOf(u.label, reg);
|
|
203
|
+
const keys = u.icons.filter((i) => i.markup).map((i) => canon(i.markup)).filter(Boolean);
|
|
204
|
+
const want = u.action && reg.actions[u.action].icon;
|
|
205
|
+
// A control may draw two icons (a chip: its kind, then the X that drops it). It draws its action when one of them is the action's.
|
|
206
|
+
if (keys.length) u.icon = want && keys.includes(want) ? want : keys[0];
|
|
207
|
+
else u.unread = (u.icons.find((i) => i.unread) || {}).unread || 'no shape';
|
|
208
|
+
delete u.icons;
|
|
209
|
+
uses.push(u);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const read1 = uses.filter((u) => u.icon);
|
|
213
|
+
const off = read1.filter((u) => u.action && reg.actions[u.action].icon !== u.icon);
|
|
214
|
+
const byAction = new Map();
|
|
215
|
+
for (const u of read1) {
|
|
216
|
+
const key = u.action || 'unlisted:' + u.label.toLowerCase().replace(/[^a-z ]+/g, ' ').trim().split(/\s+/)[0];
|
|
217
|
+
if (!byAction.has(key)) byAction.set(key, new Map());
|
|
218
|
+
const g = byAction.get(key); if (!g.has(u.icon)) g.set(u.icon, []); g.get(u.icon).push(u);
|
|
219
|
+
}
|
|
220
|
+
const mixed = [...byAction].filter(([, g]) => g.size > 1).map(([k, g]) => ({
|
|
221
|
+
action: k.replace(/^unlisted:/, ''), listed: !k.startsWith('unlisted:'),
|
|
222
|
+
icons: [...g].map(([icon, us]) => ({ icon, uses: us.map((u) => ({ file: u.file, line: u.line, label: u.label })) })).sort((a, b) => b.uses.length - a.uses.length),
|
|
223
|
+
})).sort((a, b) => (b.listed - a.listed) || b.icons.length - a.icons.length);
|
|
224
|
+
const byIcon = new Map();
|
|
225
|
+
for (const a of Object.values(reg.actions)) { if (!byIcon.has(a.icon)) byIcon.set(a.icon, new Set()); byIcon.get(a.icon).add(a.name); }
|
|
226
|
+
const shared = [...byIcon].filter(([, s]) => s.size > 1).map(([icon, s]) => ({ icon, actions: [...s].sort() }));
|
|
227
|
+
return { ref, actions: Object.keys(reg.actions).length, uses: uses.length, read: read1.length, unread: uses.length - read1.length,
|
|
228
|
+
listedUses: read1.filter((u) => u.action).length, off, mixed, shared };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Append one run to the product's local log and say so on stderr (the health log). */
|
|
232
|
+
function logRun(root, result, now = Date.now()) {
|
|
233
|
+
process.stderr.write(`[icon-check] run off=${result.off.length}\n`);
|
|
234
|
+
try {
|
|
235
|
+
const p = path.join(root, LOG);
|
|
236
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
237
|
+
fs.appendFileSync(p, JSON.stringify({ at: new Date(now).toISOString(), off: result.off.length, mixed: result.mixed.length }) + '\n');
|
|
238
|
+
} catch { /* a read-only checkout still prints */ }
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The runs in the last `days` days. */
|
|
242
|
+
function count(root, days = 7, now = Date.now()) {
|
|
243
|
+
let text = '';
|
|
244
|
+
try { text = fs.readFileSync(path.join(root, LOG), 'utf8'); } catch { return 0; }
|
|
245
|
+
const since = now - days * 864e5;
|
|
246
|
+
return text.split('\n').filter(Boolean).filter((l) => { try { return Date.parse(JSON.parse(l).at) >= since; } catch { return false; } }).length;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
module.exports = { loadRegistry, actionOf, canon, pathPieces, rectPath, tablesOf, scanText, check, logRun, count, LOG, OWN };
|
|
250
|
+
|
|
251
|
+
const USAGE = [
|
|
252
|
+
'usage: node lib/icon-check.js check [--root <dir>] [--ref <ref>|WORKTREE] [--json] [--gate]',
|
|
253
|
+
' each control that draws its action with another icon than the design system names (brand/icons.json)',
|
|
254
|
+
' node lib/icon-check.js count [--days 7] [--root <dir>] the runs of the check in the last days',
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
/** The CLI. → exit code (0 done, 1 an icon is off with --gate or the folder is not a git repository, 2 usage). */
|
|
258
|
+
function main(args, { say = (l) => console.log(l), cwd = process.cwd(), now = Date.now() } = {}) {
|
|
259
|
+
const flag = (k, d) => { const i = args.indexOf('--' + k); return i >= 0 && args[i + 1] !== undefined && !args[i + 1].startsWith('--') ? args[i + 1] : d; };
|
|
260
|
+
const has = (k) => args.includes('--' + k);
|
|
261
|
+
const root = path.resolve(cwd, flag('root', '.'));
|
|
262
|
+
if (args[0] === 'count') { say(String(count(root, Number(flag('days', 7)), now))); return 0; }
|
|
263
|
+
if (args[0] !== 'check') { for (const l of USAGE) say(l); return 2; }
|
|
264
|
+
const top = D.gitOut(root, ['rev-parse', '--show-toplevel']);
|
|
265
|
+
if (!top) { say('✗ this is not a git repository. Run the check in your product\'s repository, or give --root.'); return 1; }
|
|
266
|
+
const r = check(top.trim(), flag('ref', 'WORKTREE'));
|
|
267
|
+
logRun(root, r, now);
|
|
268
|
+
if (has('json')) { say(JSON.stringify(r, null, 2)); return has('gate') && r.off.length ? 1 : 0; }
|
|
269
|
+
say(`${r.actions} actions have one icon each. ${r.listedUses} controls name one of them; ${r.off.length} draw it another way.`);
|
|
270
|
+
for (const u of r.off) say(` ${u.action} · ${u.file}:${u.line} · "${u.label}" draws another icon than the one the design system names`);
|
|
271
|
+
for (const s of r.shared) say(` ${s.actions.join(' and ')} share one icon: give one of them another`);
|
|
272
|
+
const hints = r.mixed.filter((m) => !m.listed).slice(0, 5);
|
|
273
|
+
if (hints.length) say(`Not listed yet, drawn more than one way: ${hints.map((m) => `${m.action} (${m.icons.length} icons)`).join(', ')}.`);
|
|
274
|
+
if (r.unread) say(`${r.unread} of ${r.uses} labelled icons could not be read from the source, and were not checked.`);
|
|
275
|
+
return has('gate') && (r.off.length || r.shared.length) ? 1 : 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
module.exports.main = main;
|
|
279
|
+
|
|
280
|
+
if (require.main === module) process.exitCode = main(process.argv.slice(2));
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* its `description:` line (initiative-description-field). An agent writes only after the PM's yes
|
|
16
16
|
* pmos initiative raised-by <id> ["<who>"|none] no value: who raised it and where that is read from; with a value: write its `raised_by:`
|
|
17
17
|
* line (who-raised-each-idea): you, pmos, tracker, "teammate: <name>" or "customer: <name>"
|
|
18
|
+
* pmos initiative kind <id> [product|project|sdlc] no kind: its kind and what each stage is (owned, watched, hidden); with a kind: write
|
|
19
|
+
* its `kind:` line and make the workflow move the Viewer's kind switch makes (kind-scope-chat-writes)
|
|
20
|
+
* pmos initiative role [product|project|sdlc] the kind new work starts as (Settings › General › New work starts as, work.role)
|
|
18
21
|
* every command: [--json] [--root <dir>]
|
|
19
22
|
*
|
|
20
23
|
* The SAME writers the workspace page uses (lib/initiative-writer.js, lib/placements.js) — no server is needed. Who
|
|
@@ -28,6 +31,7 @@
|
|
|
28
31
|
* D105 retired Now / Next / Later: `now`, `next` and `later` answer with what to use instead and change nothing.
|
|
29
32
|
* Exit codes: 0 done, 1 refused, 2 usage.
|
|
30
33
|
*/
|
|
34
|
+
const fs = require('fs');
|
|
31
35
|
const path = require('path');
|
|
32
36
|
const { execFileSync } = require('child_process');
|
|
33
37
|
const guard = require('./pm-guard.js');
|
|
@@ -53,6 +57,18 @@ function startOnDefault(root, r, actor) {
|
|
|
53
57
|
} catch { /* the initiative is made; it runs Product feature */ }
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
/** kind-scope-chat-writes: the workflow move the Viewer's kind switch makes (routes-boards kindSwitch), from a terminal. */
|
|
61
|
+
function kindSwitch(root, id, from, to, actor) {
|
|
62
|
+
try {
|
|
63
|
+
const D = require('./driver.js');
|
|
64
|
+
const dir = D.stateDirOf(root);
|
|
65
|
+
if (!dir) return null;
|
|
66
|
+
const w = { id: D.wsIdOf(root), name: path.basename(root), root };
|
|
67
|
+
const ctx = { getWs: () => w, workspaceList: () => [w], stateDirFor: () => dir, selfRoot: path.resolve(__dirname, '..', '..') };
|
|
68
|
+
return require('./routes-boards.js').kindSwitch(ctx, w, id, from, to, actor);
|
|
69
|
+
} catch { return null; } // the kind is written; the workflow stays as it was
|
|
70
|
+
}
|
|
71
|
+
|
|
56
72
|
/** The records on a document lane (D86 point 4): never on the Roadmap, Home or the Board. Stopped and accepted ones are left out. */
|
|
57
73
|
const documentsOf = (rows) => (rows || []).filter((r) => r && r.ok !== false && r.group && r.group !== 'work' && !r.accepted && !r.stopped)
|
|
58
74
|
.map((r) => ({ id: r.id, lane: r.lane || null }));
|
|
@@ -63,11 +79,11 @@ function docNote(docs) {
|
|
|
63
79
|
return `Not on the Roadmap · ${docs.length} on a document lane: ${names}. A document lane does not show on Home or the Board. If it is work, set lane: in its record to ${WORK_LANES}.`;
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
const COMMANDS = { initiative: ['new', 'top', 'up', 'down', 'bottom', 'after', 'check-by', 'adopt', 'drop', 'list', 'export', 'describe', 'raised-by'] };
|
|
82
|
+
const COMMANDS = { initiative: ['new', 'top', 'up', 'down', 'bottom', 'after', 'check-by', 'adopt', 'drop', 'list', 'export', 'describe', 'raised-by', 'kind', 'role'] };
|
|
67
83
|
/** The horizon verbs D105 retired: they answer with what to use instead. */
|
|
68
84
|
const RETIRED = Object.freeze(['now', 'next', 'later']);
|
|
69
85
|
const USAGE = [
|
|
70
|
-
'usage: pmos initiative new|top|up|down|bottom|after|check-by|adopt|drop|list|export|describe|raised-by — initiatives on the Roadmap',
|
|
86
|
+
'usage: pmos initiative new|top|up|down|bottom|after|check-by|adopt|drop|list|export|describe|raised-by|kind|role — initiatives on the Roadmap',
|
|
71
87
|
' pmos initiative new "<title>" --lane <lane> --anchor <KR|health:id> [--intent "<text>"] [--id <id>] [--kind product|sdlc|project] [--raised-by "<who>"]',
|
|
72
88
|
' pmos initiative new --from capture-YYYY-MM-DD-<n> [--anchor <anchor>] [--lane <lane>] [--title "<title>"]',
|
|
73
89
|
' pmos initiative top|up|down|bottom <id> reorder it on the Roadmap',
|
|
@@ -79,6 +95,8 @@ const USAGE = [
|
|
|
79
95
|
' pmos initiative export <id> the breakdown as markdown on stdout',
|
|
80
96
|
' pmos initiative describe <id> ["<text>"] read its description and what to draft it from; with text, save it (after the PM\'s yes)',
|
|
81
97
|
' pmos initiative raised-by <id> ["<who>"|none] who raised it; with a value, save it: you, pmos, tracker, "teammate: <name>", "customer: <name>"',
|
|
98
|
+
' pmos initiative kind <id> [product|project|sdlc] its kind and what each stage shows; with a kind, change it',
|
|
99
|
+
' pmos initiative role [product|project|sdlc] the kind new work starts as; with a kind, change it',
|
|
82
100
|
' --lane is a work lane of this repository: new-feature, improvement, bug-fix, discovery or chore in a product repository',
|
|
83
101
|
' (scripts/lane-defs.js; the PMOS repository itself uses feature, discovery, chore, incident, content and prototype)',
|
|
84
102
|
' every command: [--json] [--root <dir>]',
|
|
@@ -241,6 +259,47 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
241
259
|
return 0;
|
|
242
260
|
}
|
|
243
261
|
|
|
262
|
+
if (verb === 'kind') {
|
|
263
|
+
// kind-scope-chat-writes: the same writer as the Viewer's kind switch, so the Viewer shows the change on its next refresh
|
|
264
|
+
const KS = require('./kind-scope.js'), WK = require('./work-kind.js');
|
|
265
|
+
const kid = pos[0];
|
|
266
|
+
if (!kid || pos.length > 2) { say('usage: pmos initiative kind <id> [product|project|sdlc]'); return 2; }
|
|
267
|
+
if (pos.length === 2) {
|
|
268
|
+
if (!WK.valid(pos[1])) return fail(`kind must be one of ${WK.KINDS.join(', ')}`, 2);
|
|
269
|
+
const actor = actorLib.fromCli(who);
|
|
270
|
+
const r = writer.setKind(root, kid, pos[1], { actor });
|
|
271
|
+
if (!r.ok) return fail(r.error, r.status === 400 ? 2 : 1);
|
|
272
|
+
if (r.same) return done({ id: kid, kind: r.kind, same: true }, `${kid} is already ${WK.LABEL[r.kind]}.`);
|
|
273
|
+
const sw = kindSwitch(root, kid, r.from, r.kind, actor);
|
|
274
|
+
const moved = sw && sw.switched ? ` It moved to the ${WK.LABEL[r.kind]} workflow.` : '';
|
|
275
|
+
return done({ id: kid, from: r.from, kind: r.kind, scope: KS.scopeOf(r.kind), ...(sw ? { workflow: sw } : {}) },
|
|
276
|
+
`✓ ${kid}: ${WK.LABEL[r.from]} → ${WK.LABEL[r.kind]}.${moved} The Viewer shows it on its next refresh. Commit the record to keep it.\n ` + KS.describe(r.kind).join('\n '));
|
|
277
|
+
}
|
|
278
|
+
const d = rowsLib.deriveSync(root);
|
|
279
|
+
const row = d.ok ? d.rows.find((x) => x.id === kid) : null;
|
|
280
|
+
if (!row) return fail(`no initiative ${kid} here`);
|
|
281
|
+
let text = ''; try { text = row.record ? fs.readFileSync(path.resolve(root, String(row.record)), 'utf8') : ''; } catch { /* no line reads as product */ }
|
|
282
|
+
const k = KS.kindOfText(text); // the record's own kind: line, as the Board and the Viewer read it
|
|
283
|
+
if (json) { say(JSON.stringify({ ok: true, id: kid, kind: k, scope: KS.scopeOf(k), lines: KS.describe(k) })); return 0; }
|
|
284
|
+
say(`${kid} — ${row.title || kid}`);
|
|
285
|
+
for (const l of KS.describe(k)) say(' ' + l);
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (verb === 'role') {
|
|
290
|
+
// kind-scope-chat-writes: Settings › General › New work starts as, in the same settings file the page reads
|
|
291
|
+
const SS = require('./settings-store.js'), WK = require('./work-kind.js');
|
|
292
|
+
const dir = require('./state-root.js').defaultRoot({ env: who.env });
|
|
293
|
+
if (pos.length > 1) { say('usage: pmos initiative role [product|project|sdlc]'); return 2; }
|
|
294
|
+
if (!pos.length) {
|
|
295
|
+
const k = SS.get(dir, 'work.role');
|
|
296
|
+
return done({ role: k }, `New work starts as ${WK.LABEL[k] || k}. Change it with pmos initiative role product|project|sdlc.`);
|
|
297
|
+
}
|
|
298
|
+
const r = SS.set(dir, 'work.role', pos[0]);
|
|
299
|
+
if (!r.ok) return fail(r.error || `role must be one of ${WK.KINDS.join(', ')}`, 2);
|
|
300
|
+
return done({ role: pos[0] }, `✓ New work starts as ${WK.LABEL[pos[0]]}. Settings shows it now. Each initiative can still change its own kind.`);
|
|
301
|
+
}
|
|
302
|
+
|
|
244
303
|
if (verb === 'describe') {
|
|
245
304
|
// initiative-description-field: the record's own description. Read with no text; write with text, only after the PM said yes.
|
|
246
305
|
const did = pos[0];
|
|
@@ -106,7 +106,7 @@ function build(f) {
|
|
|
106
106
|
// stage's To finish tasks are one kind of task (feedback batch 5, lib/task-items.js), Jira rows are read-only ──
|
|
107
107
|
// every task the page draws (batch 7 item 7): a cap here left the 61st and later tasks with no editor, so a press fell back to the old list
|
|
108
108
|
const items = (f.items || []).filter((t) => t && t.ini === id);
|
|
109
|
-
const tracker = items.map((t, n) => ({ key: 'task:' + (t.uid || t.key || n), uid: t.uid || '', pmos: t.src === 'pmos', ref: t.key || t.ref || '', title: clip(t.title, 160), state: t.status || 'To do', src: t.src === 'jira' ? 'Jira (read-only)' : 'PMOS task', owner: t.owner || '', start: t.start || '', end: t.end || '', blocked: !!t.blocked, kind: t.kind || 'Task', notes: t.notes || '', readAt: t.readAt || '',
|
|
109
|
+
const tracker = items.map((t, n) => ({ key: 'task:' + (t.uid || t.key || n), uid: t.uid || '', pmos: t.src === 'pmos', ref: t.key || t.ref || '', title: clip(t.title, 160), state: t.status || 'To do', src: t.src === 'jira' ? 'Jira (read-only)' : 'PMOS task', owner: t.owner || '', start: t.start || '', end: t.end || '', blocked: !!t.blocked, kind: t.kind || 'Task', ...(t.milestone ? { milestone: true } : {}), notes: t.notes || '', readAt: t.readAt || '',
|
|
110
110
|
...(t.from ? { from: { stage: t.from.stage, finish: t.from.finish } } : {}), ...(t.store === 'item' ? { store: 'item' } : {}) }));
|
|
111
111
|
const dv = sheet && sheet.derived;
|
|
112
112
|
const reqs = dv && Array.isArray(dv.items) ? dv.items.slice(0, MAX_TASKS).map((x) => ({ key: 'req:' + x.id, ref: x.ref || x.id, title: clip(x.title, 160), state: null, src: 'PRD requirement' })) : [];
|
|
@@ -174,6 +174,7 @@ const JOBS = Object.freeze([
|
|
|
174
174
|
ai('rehearse', 'lib/rehearse-guard.js', [], ['task links']),
|
|
175
175
|
ai('next-prompt', 'lib/next-prompt.js', []),
|
|
176
176
|
ai('sharpen-prompt', 'lib/next-prompt.js', []),
|
|
177
|
+
ai('principles-draft', 'lib/routes-principles.js', [], ['repo:DECISIONS.md']), // bet A352: the drafts land in principles.jsonl through `pmos principles draft`
|
|
177
178
|
{ id: 'improve-self', kind: 'script', module: 'repo:scripts/improve.js', reads: ['repo:planning/improve/signals.jsonl'], writes: ['repo:planning/improve/loop.jsonl'] },
|
|
178
179
|
{ id: 'log-run', kind: 'script', module: 'repo:scripts/log-run.js', reads: [], writes: ['repo:planning/runs/agent-runs.jsonl', 'repo:planning/runs/verify-queue.jsonl'] },
|
|
179
180
|
]);
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Stage project product sdlc
|
|
9
9
|
* Triage, Discover hidden owned owned
|
|
10
10
|
* Plan, Prioritize owned owned owned
|
|
11
|
-
* Build watched (
|
|
11
|
+
* Build watched (milestone dates) watched (Jira) owned (the factory opens pull requests)
|
|
12
12
|
* Deliver, Monitor, Evaluate owned owned owned
|
|
13
13
|
* Gate Plan before start PRD and done test before build Done test and kill before build
|
|
14
14
|
*
|
|
@@ -19,8 +19,12 @@
|
|
|
19
19
|
* docHidden(kind, docKey) → bool
|
|
20
20
|
* prePick(name, lane, role) → { kind, cue } lib/work-kind.js fromName, with the PM's role as the default when the name gives no cue
|
|
21
21
|
* count(root) → n initiatives whose kind hides at least one stage (the health number)
|
|
22
|
+
* describe(kind) → [lines] the scope as a person reads it: the kind, owned, watched (and where), hidden, the gate
|
|
23
|
+
* writes() → [{ what, page, command }] each kind write the page offers, with the `pmos` command that does it from a chat
|
|
24
|
+
* (initiative kind-scope-chat-writes: anything the chat can be asked to change has a write path)
|
|
22
25
|
*
|
|
23
|
-
* node lib/kind-scope.js count [root] prints that number on its last line
|
|
26
|
+
* node lib/kind-scope.js count [root] prints that number on its last line
|
|
27
|
+
* node lib/kind-scope.js writes prints how many kind writes have a pmos command, on its last line */
|
|
24
28
|
const fs = require('fs');
|
|
25
29
|
const path = require('path');
|
|
26
30
|
const WK = require('./work-kind.js');
|
|
@@ -32,7 +36,7 @@ const TABLE = Object.freeze({
|
|
|
32
36
|
product: Object.freeze({ ...all('owned'), build: 'watched' }),
|
|
33
37
|
sdlc: Object.freeze(all('owned')),
|
|
34
38
|
});
|
|
35
|
-
const WATCH = Object.freeze({ project: { build: '
|
|
39
|
+
const WATCH = Object.freeze({ project: { build: 'milestone dates' }, product: { build: 'Jira' }, sdlc: {} });
|
|
36
40
|
const GATE = Object.freeze({ project: 'Plan before start', product: 'PRD and done test before build', sdlc: 'Done test and kill before build' });
|
|
37
41
|
const PRODUCT_DOCS = Object.freeze(new Set(['problem', 'research', 'prd', 'rubric', 'design']));
|
|
38
42
|
const LOG = '[kind-scope]';
|
|
@@ -50,6 +54,24 @@ function prePick(name, lane, role) {
|
|
|
50
54
|
return { kind: role, cue: '' };
|
|
51
55
|
}
|
|
52
56
|
|
|
57
|
+
const STAGE_LABEL = Object.freeze({ triage: 'Triage', discover: 'Discover', plan: 'Plan', prioritize: 'Prioritize', build: 'Build', deliver: 'Deliver', monitor: 'Monitor', evaluate: 'Evaluate' });
|
|
58
|
+
function describe(kind) {
|
|
59
|
+
const s = scopeOf(kind), of = (v) => STAGES.filter((k) => s.stages[k] === v).map((k) => STAGE_LABEL[k]);
|
|
60
|
+
const lines = [`Kind: ${s.label}`, `Owned: ${of('owned').join(', ') || 'none'}`];
|
|
61
|
+
for (const k of STAGES) if (s.stages[k] === 'watched') lines.push(`${STAGE_LABEL[k]}: watched ${s.watch[k] === 'milestone dates' ? 'by' : 'in'} ${s.watch[k] || 'the tracker'}`);
|
|
62
|
+
lines.push(`Hidden: ${of('hidden').join(', ') || 'none'}${s.hidden.length ? ' (still in Move to a stage)' : ''}`);
|
|
63
|
+
if (s.kind === 'project') lines.push('Product documents (problem, research, PRD, rubric, design) sit in a closed fold');
|
|
64
|
+
lines.push(`Gate: ${s.gate}`);
|
|
65
|
+
return lines;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The kind writes the workspace page offers, each with its pmos command. A page write with no command is one the chat cannot make. */
|
|
69
|
+
const WRITES = Object.freeze([
|
|
70
|
+
Object.freeze({ what: "an initiative's kind", page: 'Viewer › kind switch (POST /api/initiatives/kind)', command: 'pmos initiative kind <id> product|project|sdlc' }),
|
|
71
|
+
Object.freeze({ what: 'the kind new work starts as', page: 'Settings › General › New work starts as (work.role)', command: 'pmos initiative role product|project|sdlc' }),
|
|
72
|
+
]);
|
|
73
|
+
const writes = () => WRITES.map((w) => ({ ...w }));
|
|
74
|
+
|
|
53
75
|
const kindLine = (text) => { const m = /^---\n([\s\S]*?)\n---/.exec(text); const l = m && /^kind:\s*(.+)$/m.exec(m[1]); return l ? WK.kindOf(l[1]) : 'product'; };
|
|
54
76
|
function count(root) {
|
|
55
77
|
let n = 0;
|
|
@@ -63,11 +85,17 @@ function count(root) {
|
|
|
63
85
|
|
|
64
86
|
if (require.main === module) {
|
|
65
87
|
const [verb, root] = process.argv.slice(2);
|
|
66
|
-
if (verb
|
|
88
|
+
if (verb === 'writes') {
|
|
89
|
+
const w = writes().filter((x) => x.command);
|
|
90
|
+
for (const x of w) console.log(`[kind-scope] ${x.what}: ${x.command}`);
|
|
91
|
+
console.log(String(w.length));
|
|
92
|
+
process.exit(0);
|
|
93
|
+
}
|
|
94
|
+
if (verb !== 'count') { console.error('usage: node lib/kind-scope.js count|writes [root]'); process.exit(2); }
|
|
67
95
|
const r = path.resolve(root || process.cwd());
|
|
68
96
|
const n = count(r);
|
|
69
97
|
console.log(LOG + ' initiatives whose kind hides a stage in ' + r);
|
|
70
98
|
console.log(String(n));
|
|
71
99
|
}
|
|
72
100
|
|
|
73
|
-
module.exports = { STAGES, TABLE, GATE, PRODUCT_DOCS, LOG, scopeOf, docHidden, prePick, count };
|
|
101
|
+
module.exports = { STAGES, TABLE, GATE, PRODUCT_DOCS, LOG, scopeOf, docHidden, prePick, count, describe, writes, kindOfText: kindLine };
|
|
@@ -145,6 +145,9 @@ const VERBS = Object.freeze({
|
|
|
145
145
|
// Not a pm-os-absorb verb (run: null): initiative decision-journal-outcome-checks added it through the same table.
|
|
146
146
|
decisions: Object.freeze({ module: 'decisions-cli.js', run: null, guide: 'cli.md',
|
|
147
147
|
help: 'pmos decisions add|list|show|check|record — a decision journal: what you decided, what you expect, a date to check, and how your calls turned out (pmos decisions help)' }),
|
|
148
|
+
// Not a pm-os-absorb verb (run: null): initiative product-principles-draft (bet A352) added it through the same table.
|
|
149
|
+
principles: Object.freeze({ module: 'principles-cli.js', run: null, guide: 'cli.md',
|
|
150
|
+
help: 'pmos principles list|sources|draft|keep|drop|undo|add — the product\'s principles, drafted from its decisions, each citing them; keep or drop each (pmos principles help)' }),
|
|
148
151
|
// Not a pm-os-absorb verb (run: null): initiative parked-reason-way-back (bet A446) added it through the same table.
|
|
149
152
|
parked: Object.freeze({ module: 'parked-cli.js', run: null, guide: 'cli.md',
|
|
150
153
|
help: 'pmos parked list|hold|back|coverage — parked initiatives: why each is parked, what brings it back, and bringing it back (pmos parked help)' }),
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* principles-cli.js — `pmos principles`: a product's principles, drafted from its past decisions, each citing the decisions it came from, kept or
|
|
3
|
+
* dropped by the PM (bet A352, initiative product-principles-draft; the store is lib/principles.js).
|
|
4
|
+
*
|
|
5
|
+
* pmos principles list [--all] [--json] the kept principles, then the drafts that wait; --all adds the dropped ones
|
|
6
|
+
* pmos principles sources [--json] the decisions a draft may cite (DECISIONS.md and its ADRs, and the decision journal)
|
|
7
|
+
* pmos principles draft --text "<principle>" --why "<the pattern in the decisions>" --source <id> [--source <id> …]
|
|
8
|
+
* one draft; refused when a source is not a decision of this product (the drafting run's write)
|
|
9
|
+
* pmos principles keep|drop|undo <id> the PM's answer to a draft (the chat writes it for the PM; the Board shows it)
|
|
10
|
+
* pmos principles add --text "<principle>" [--why "<text>"] [--source <id> …] the PM's own principle, kept at once
|
|
11
|
+
* every command: [--root <dir>] (default: this repository)
|
|
12
|
+
*
|
|
13
|
+
* The principles live in principles.jsonl in the product's records folder, so what the chat writes shows on the Board.
|
|
14
|
+
* Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const { execFileSync } = require('child_process');
|
|
17
|
+
const P = require('./principles.js');
|
|
18
|
+
|
|
19
|
+
const COMMANDS = { principles: ['list', 'sources', 'draft', 'keep', 'drop', 'undo', 'add'] };
|
|
20
|
+
const USAGE = [
|
|
21
|
+
'usage: pmos principles list|sources|draft|keep|drop|undo|add — the product\'s principles, drafted from its decisions, each citing them',
|
|
22
|
+
' pmos principles list [--all] [--json] the kept principles, then the drafts that wait for you',
|
|
23
|
+
' pmos principles sources [--json] the decisions a principle may cite',
|
|
24
|
+
' pmos principles draft --text "<principle>" --why "<the pattern>" --source <id> [--source <id> …] one draft, 1 to ' + P.MAX_SOURCES + ' sources',
|
|
25
|
+
' pmos principles keep|drop|undo <id> keep or drop a draft, or put it back to open',
|
|
26
|
+
' pmos principles add --text "<principle>" [--why "<text>"] [--source <id> …] your own principle, kept at once',
|
|
27
|
+
'Run it in the product\'s repository, or pass --root <dir>.',
|
|
28
|
+
];
|
|
29
|
+
const ALLOWED = { list: ['json', 'root', 'all'], sources: ['json', 'root'], draft: ['json', 'root', 'text', 'why', 'source'], keep: ['json', 'root'], drop: ['json', 'root'],
|
|
30
|
+
undo: ['json', 'root'], add: ['json', 'root', 'text', 'why', 'source'] };
|
|
31
|
+
const BOOL = new Set(['json', 'all']);
|
|
32
|
+
|
|
33
|
+
function parse(args) {
|
|
34
|
+
const pos = [], flags = {};
|
|
35
|
+
for (let i = 0; i < args.length; i++) {
|
|
36
|
+
const a = args[i];
|
|
37
|
+
if (!a.startsWith('--')) { pos.push(a); continue; }
|
|
38
|
+
const k = a.slice(2);
|
|
39
|
+
if (BOOL.has(k)) { flags[k] = true; continue; }
|
|
40
|
+
const v = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
|
|
41
|
+
if (k === 'source') (flags.source = flags.source || []).push(...String(v).split(/[\s,]+/).filter(Boolean));
|
|
42
|
+
else flags[k] = v;
|
|
43
|
+
}
|
|
44
|
+
return { pos, flags };
|
|
45
|
+
}
|
|
46
|
+
function repoRoot(cwd) {
|
|
47
|
+
try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; }
|
|
48
|
+
}
|
|
49
|
+
function recordsDirOf(root) {
|
|
50
|
+
try { const { repoScript } = require('./repo-script.js'); return require(repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; } catch { return path.join(root, 'planning', 'records'); }
|
|
51
|
+
}
|
|
52
|
+
const pub = (x) => ({ id: x.id, state: x.state, own: !!x.own, text: x.text, why: x.why || null, sources: x.sources });
|
|
53
|
+
const lineOf = (x) => ` ${x.id} — ${x.text}${x.why ? `\n why: ${x.why}` : ''}${x.sources.length ? `\n from: ${x.sources.join(', ')}` : ''}`;
|
|
54
|
+
|
|
55
|
+
async function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now(), isTTY } = {}) {
|
|
56
|
+
const args = argv[0] === 'principles' ? argv.slice(1) : argv.slice();
|
|
57
|
+
const sub = args[0];
|
|
58
|
+
if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
|
|
59
|
+
if (!COMMANDS.principles.includes(sub)) { say(`unknown principles command "${sub}". Use one of: ${COMMANDS.principles.join(', ')}`); return 2; }
|
|
60
|
+
const { pos, flags } = parse(args.slice(1));
|
|
61
|
+
for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos principles ${sub}`); return 2; }
|
|
62
|
+
const root = path.resolve(flags.root || repoRoot(cwd));
|
|
63
|
+
const dir = recordsDirOf(root);
|
|
64
|
+
const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
|
|
65
|
+
const by = () => { try { return require('./actor.js').fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env }).by; } catch { return 'unknown'; } };
|
|
66
|
+
|
|
67
|
+
if (sub === 'list') {
|
|
68
|
+
if (pos.length) return fail('pmos principles list takes no argument', 2);
|
|
69
|
+
const all = P.read(dir);
|
|
70
|
+
const kept = all.filter((x) => x.state === 'kept'), open = all.filter((x) => x.state === 'open'), dropped = all.filter((x) => x.state === 'dropped');
|
|
71
|
+
if (flags.json) { say(JSON.stringify({ ok: true, principles: [...kept, ...open, ...(flags.all ? dropped : [])].map(pub) })); return 0; }
|
|
72
|
+
if (!all.length) { say('No principles yet. PMOS drafts them from the decisions once the product has ' + P.MIN_DECISIONS + ' or more (pmos principles sources).'); return 0; }
|
|
73
|
+
say(`${kept.length} kept · ${open.length} waiting for you · ${dropped.length} dropped`);
|
|
74
|
+
if (kept.length) say('\nKept:\n' + kept.map(lineOf).join('\n'));
|
|
75
|
+
if (open.length) say('\nDrafts:\n' + open.map(lineOf).join('\n') + '\n\nKeep or drop one: pmos principles keep|drop <id>');
|
|
76
|
+
if (flags.all && dropped.length) say('\nDropped:\n' + dropped.map(lineOf).join('\n'));
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (sub === 'sources') {
|
|
81
|
+
if (pos.length) return fail('pmos principles sources takes no argument', 2);
|
|
82
|
+
const D = P.decisionsOf(root, { now });
|
|
83
|
+
if (flags.json) { say(JSON.stringify({ ok: true, decisions: D })); return 0; }
|
|
84
|
+
if (!D.length) { say('No decisions in this repository yet (DECISIONS.md or pmos decisions).'); return 0; }
|
|
85
|
+
say(D.map((d) => ` ${d.id} — ${d.title} (${d.from})`).join('\n'));
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (sub === 'draft' || sub === 'add') {
|
|
90
|
+
if (pos.length) return fail(`usage: pmos principles ${sub} --text "<principle>" ${sub === 'draft' ? '--why "<the pattern>" --source <id>' : '[--why "<text>"]'}`, 2);
|
|
91
|
+
const input = { text: flags.text, why: flags.why, sources: flags.source || [] };
|
|
92
|
+
const D = P.decisionsOf(root, { now });
|
|
93
|
+
const r = sub === 'draft' ? P.draft(dir, input, D, { by: by(), now }) : P.add(dir, input, D, { by: by(), now });
|
|
94
|
+
if (!r.ok) return r.code === 'dropped' && !flags.json ? (say('dropped: ' + r.error), 1) : fail(r.error);
|
|
95
|
+
if (flags.json) { say(JSON.stringify({ ok: true, principle: pub(r.item) })); return 0; }
|
|
96
|
+
say(`✓ ${r.item.id}: ${sub === 'draft' ? 'drafted; it waits on the Board for a keep or a drop' : 'kept'}.`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// keep · drop · undo
|
|
101
|
+
if (pos.length !== 1) return fail(`usage: pmos principles ${sub} <id>`, 2);
|
|
102
|
+
const r = P.act(dir, sub, pos[0], { by: by(), now });
|
|
103
|
+
if (!r.ok) return fail(r.error);
|
|
104
|
+
if (flags.json) { say(JSON.stringify({ ok: true, principle: pub(r.item) })); return 0; }
|
|
105
|
+
say(`✓ ${r.item.id}: ${r.item.state === 'open' ? 'back to a draft' : r.item.state}. The Board shows it.`);
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = { run, COMMANDS, USAGE };
|