create-pmos 0.837.0 → 0.838.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 +78 -35
- 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 +77 -4
- package/workspace/guide/cli.md +11 -0
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/initiatives-and-next-steps.md +8 -0
- package/workspace/lib/features.json +1 -0
- package/workspace/lib/hire-draft.js +4 -3
- package/workspace/lib/initiative-rows.js +3 -0
- package/workspace/lib/meeting-stance.js +199 -0
- package/workspace/lib/people-cli.js +44 -1
- package/workspace/lib/pmos-verbs.js +4 -1
- package/workspace/lib/route-modules.js +3 -0
- package/workspace/lib/routes-meeting-stance.js +43 -0
- package/workspace/lib/routes-segments.js +47 -0
- package/workspace/lib/routes-surface-moments.js +36 -0
- package/workspace/lib/segments-cli.js +102 -0
- package/workspace/lib/segments.js +214 -0
- package/workspace/lib/surface-moments.js +185 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-board.css +11 -0
- package/workspace/public/pm/cozy-pop-work.js +5 -2
- package/workspace/public/pm/cozy-today-app.js +42 -1
- package/workspace/public/pm/cozy-today-model.js +70 -3
- package/workspace/public/pm/cozy-today-view.js +6 -0
- package/workspace/public/pm/meeting-stance.js +113 -0
- package/workspace/public/pm/premium-board.js +2 -0
- package/workspace/public/pm/segments.js +113 -0
- package/workspace/public/premium-board.html +2 -0
- package/workspace/test-lists/meeting-stance.json +9 -0
- package/workspace/test-lists/segments.json +9 -0
- package/workspace/test-lists/surface-moments.json +9 -0
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* pmos people settings [--json] whether calendar attendee names are kept
|
|
9
9
|
* pmos people map <initiative> [--json] who decides, must agree, needs to know, and when each last heard (A371)
|
|
10
10
|
* pmos people keep|drop|told|undo <initiative> <person> [--group decides|agree|know] the PM's word on one name (lib/stakeholder-map.js)
|
|
11
|
+
* pmos people stance <initiative> [sent | answer <person> <1|2> <yes|no|clear> | undo] [--json] before the meeting: the two questions
|
|
12
|
+
* for the contested decision and where each person stands (A333, lib/meeting-stance.js)
|
|
11
13
|
* pmos people prep <person> [--days N] [--json] a 1:1 brief from the tasks they own (lib/people-prep.js, idea A85)
|
|
12
14
|
*
|
|
13
15
|
* The same module the People place reads (lib/people-store.js), so a terminal line and the page cannot disagree.
|
|
@@ -23,7 +25,7 @@ const path = require('path');
|
|
|
23
25
|
const store = require('./people-store');
|
|
24
26
|
const { parseArgs } = require('./schedule-cli');
|
|
25
27
|
|
|
26
|
-
const COMMANDS = { people: ['list', 'show', 'record', 'settings', 'map', 'keep', 'drop', 'told', 'undo', 'prep'] };
|
|
28
|
+
const COMMANDS = { people: ['list', 'show', 'record', 'settings', 'map', 'keep', 'drop', 'told', 'undo', 'stance', 'prep'] };
|
|
27
29
|
const USAGE = [
|
|
28
30
|
'usage: pmos people [list|show|record|settings] — the people you work with in this repository',
|
|
29
31
|
' pmos people [list] [--json] each person, and what waits for you in the review list',
|
|
@@ -32,6 +34,8 @@ const USAGE = [
|
|
|
32
34
|
' pmos people settings [--json] whether calendar attendee names are kept (calendar names: on|off)',
|
|
33
35
|
' pmos people map <initiative> [--json] who decides, who must agree, who needs to know, and when each last heard from you',
|
|
34
36
|
' pmos people keep <initiative> <person> [--group decides|agree|know] keep a name on the map (in that group)',
|
|
37
|
+
' pmos people stance <initiative> [--json] before the meeting: the two questions for the contested decision, or where each person stands',
|
|
38
|
+
' pmos people stance <initiative> sent | answer <person> <1|2> <yes|no|clear> | undo you sent the questions, one answer, or take back the last',
|
|
35
39
|
' pmos people drop|told|undo <initiative> <person> take a name off, mark that you sent them an update, or take back the last of these',
|
|
36
40
|
' pmos people prep <person> [--days N] [--json] a 1:1 brief: what they shipped, where they are stuck, one thing to recognise',
|
|
37
41
|
'Nothing here removes a person, merges, sets a tone or writes a note. Do that in People. PMOS never sends an update: you do.',
|
|
@@ -142,6 +146,7 @@ async function run(argv, { say = console.log, cwd = process.cwd(), env = process
|
|
|
142
146
|
return r.ok ? 0 : 1;
|
|
143
147
|
}
|
|
144
148
|
if (sub === 'map' || SM_ACTS.includes(sub)) return mapCmd(sub, pos, flags, { say, root, json, fail, now });
|
|
149
|
+
if (sub === 'stance') return stanceCmd(pos, { say, root, json, fail, now });
|
|
145
150
|
return fail(`pmos people ${sub} is not a command. ${USAGE[0]}`, 2);
|
|
146
151
|
}
|
|
147
152
|
|
|
@@ -180,4 +185,42 @@ function mapCmd(sub, pos, flags, { say, root, json, fail, now }) {
|
|
|
180
185
|
return 0;
|
|
181
186
|
}
|
|
182
187
|
|
|
188
|
+
/** `pmos people stance` (initiative meeting-stance): the store the Work popup's "before the meeting" block reads. PMOS never sends. */
|
|
189
|
+
function stanceCmd(pos, { say, root, json, fail, now }) {
|
|
190
|
+
const MS = require('./meeting-stance.js');
|
|
191
|
+
const SM = require('./stakeholder-map.js');
|
|
192
|
+
const ini = String(pos[1] || ''), what = String(pos[2] || '');
|
|
193
|
+
const usage = 'usage: pmos people stance <initiative> [sent | answer <person> <1|2> <yes|no|clear> | undo]';
|
|
194
|
+
if (!ini) return fail(usage, 2);
|
|
195
|
+
const s = MS.read(root, ini, { now });
|
|
196
|
+
if (!what) {
|
|
197
|
+
if (json) { say(JSON.stringify({ ok: true, stance: s })); return 0; }
|
|
198
|
+
if (!s) { say('No contested decision on this initiative. PMOS drafts questions for a live journal decision someone argued against.'); return 0; }
|
|
199
|
+
say(`Before the meeting · ${s.title} · ${s.decision.decided}`);
|
|
200
|
+
if (!s.asked) {
|
|
201
|
+
say(`✦ PMOS drafted two questions for ${s.people.map((p) => p.name).join(', ')}. Send them yourself, then run: pmos people stance ${ini} sent`);
|
|
202
|
+
s.questions.forEach((q, i) => say(` ${i + 1}. ${q}`));
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
for (const r of s.grid) say(` ${r.n}. ${r.q} ` + r.cells.map((c) => `${c.name}: ${c.says || '—'}${c.diff ? ' (differs)' : ''}`).join(' · '));
|
|
206
|
+
if (s.settle) say(`✦ ${s.settle}`);
|
|
207
|
+
say(`${s.answered} of ${s.total} answered · ${s.askedWord}`);
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
if (!s) return fail('No contested decision on this initiative.');
|
|
211
|
+
const input = { ini, decision: s.decision.id, kind: what };
|
|
212
|
+
if (what === 'sent') input.people = s.people;
|
|
213
|
+
else if (what === 'answer') {
|
|
214
|
+
const who = String(pos[3] || ''), q = pos[4], says = pos[5];
|
|
215
|
+
const p = s.people.find((x) => x.id === who.toLowerCase()) || s.people.find((x) => SM.same(x.name, who));
|
|
216
|
+
if (!p) return fail(`${who || 'That person'} is not asked on this decision: ${s.people.map((x) => x.id).join(', ')}`);
|
|
217
|
+
Object.assign(input, { person: p.id, name: p.name, q, says });
|
|
218
|
+
} else if (what !== 'undo') return fail(usage, 2);
|
|
219
|
+
const r = MS.act(SM.recordsDirOf(root), input, { by: 'pm', now });
|
|
220
|
+
if (json) { say(JSON.stringify(r)); return r.ok ? 0 : 1; }
|
|
221
|
+
if (!r.ok) return fail(r.error);
|
|
222
|
+
say(what === 'sent' ? `✓ marked: you sent the questions to ${r.line.people.map((p) => p.name).join(', ')}` : what === 'answer' ? `✓ ${r.line.name || r.line.person} on question ${r.line.q}: ${r.line.says || 'cleared'}` : '✓ your last press taken back');
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
183
226
|
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -50,7 +50,7 @@ const VERBS = Object.freeze({
|
|
|
50
50
|
help: 'pmos docs [list|link|unlink|find] … — is each linked document the same as, ahead of or behind its Google Docs and Confluence copy, and record a sync (pmos docs help)' }),
|
|
51
51
|
// Not a pm-os-absorb verb (run: null): people-directory added it through the same table.
|
|
52
52
|
people: Object.freeze({ module: 'people-cli.js', run: null, guide: 'cli.md',
|
|
53
|
-
help: 'pmos people list|show|record|settings|map|keep|drop|told|undo … — the people you work with in this repository,
|
|
53
|
+
help: 'pmos people list|show|record|settings|map|keep|drop|told|undo|stance|prep … — the people you work with in this repository, who decides on each initiative, where each stands before a meeting, and a 1:1 brief (pmos people help)' }),
|
|
54
54
|
// Not a pm-os-absorb verb (run: null): initiative dry-run-tickets-before-build added it through the same table.
|
|
55
55
|
signoff: Object.freeze({ module: 'signoff-cli.js', run: null, guide: 'cli.md',
|
|
56
56
|
help: 'pmos signoff ask|answer|drop|evidence|list … — the sign-offs an initiative waits on; a stage\'s sign-offs are Your move rows on Today (pmos signoff help)' }),
|
|
@@ -203,6 +203,9 @@ const VERBS = Object.freeze({
|
|
|
203
203
|
// Not a pm-os-absorb verb (run: null): initiative positioning-draft (idea A328) added it through the same table.
|
|
204
204
|
positioning: Object.freeze({ module: 'positioning-cli.js', run: null, guide: 'cli.md',
|
|
205
205
|
help: 'pmos positioning strategy|list|keep|drop — the product\'s positioning and key messages, each citing its strategy lines (pmos positioning help)' }),
|
|
206
|
+
// Not a pm-os-absorb verb (run: null): initiative segments (idea A327, job #1893) added it through the same table.
|
|
207
|
+
segments: Object.freeze({ module: 'segments-cli.js', run: null, guide: 'cli.md',
|
|
208
|
+
help: 'pmos segments list|draft|add|keep|rename|drop|undo|tag|untag — the product\'s user groups, their size and health, and the roadmap items that serve each (pmos segments help)' }),
|
|
206
209
|
// Not a pm-os-absorb verb (run: null): initiative code-map (idea A176) added it through the same table.
|
|
207
210
|
code: Object.freeze({ module: 'code-map-cli.js', run: null, guide: 'cli.md',
|
|
208
211
|
help: 'pmos code show|map|describe|count — the product\'s code map: one line per main part, what it is, how it is tested, who changed it last (pmos code help)' }),
|
|
@@ -147,16 +147,19 @@ const MODULES = Object.freeze([
|
|
|
147
147
|
'routes-next-prompt', // batch 26 item 2: the chat's suggested next prompt and Sharper card (lib/next-prompt.js, through lib/ai-guard.js)
|
|
148
148
|
'routes-drift', // weekly-drift-check: What would I have missed, Home's weekly ✦ and its ⋯ drop and Undo (runtime drift/drift.jsonl; page-press POST)
|
|
149
149
|
'routes-moments', // onboarding B3 gradual exposure: the day's ✦ in Home's chat, the menu dots, a quiet place's one line (onboarding-progress record; page-press POST)
|
|
150
|
+
'routes-surface-moments', // surface-moments (job #1985, LINE.md Rule 12): the ✦ moments in Your move on Today (page-press POST)
|
|
150
151
|
'routes-spec-critic', // spec-critic: the sceptical reviewer's hardest questions on a document before it is shared (runtime spec-critic.jsonl)
|
|
151
152
|
'routes-jira-epics', // work-subtasks: the epic check's fix, direct on tickets assigned to the PM, the day's draft for the rest (tracker/jira/epics.jsonl; page-press POST)
|
|
152
153
|
'routes-use-log', // bet A466: the local use log, page opens and controls pressed, on this computer only (runtime use-log.jsonl; page-press POST)
|
|
153
154
|
'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)
|
|
155
|
+
'routes-segments', // idea A327: a product's user groups and the roadmap items that serve each, kept or renamed on Work (records segments.jsonl; page-press POST)
|
|
154
156
|
'routes-principles', // bet A352: a product's principles drafted from its decisions, kept or dropped on the Board (records principles.jsonl; page-press POST)
|
|
155
157
|
'routes-switches', // idea A263: who has which switch, per customer, on Work; turning one waits for the PM's own press (records switches.jsonl; page-press POST)
|
|
156
158
|
'routes-prefs', // bet A461: view preferences that follow the person to the phone and other browsers (runtime view-prefs.json; page-press POST)
|
|
157
159
|
'routes-skill-map', // bet A208: the team skill map on Work, for the person and their lead only (records skill-map.jsonl; page-press POST)
|
|
158
160
|
'routes-first-hour', // bet A55: the first hour for a new engineer on Work (records first-hour.jsonl; page-press POST)
|
|
159
161
|
'routes-stakeholders', // bet A371: an initiative's stakeholder map, decides / must agree / needs to know, in the Work popup (records stakeholders.jsonl; page-press POST)
|
|
162
|
+
'routes-meeting-stance', // bet A333: before the meeting, the two questions for a contested decision and where each person stands, in the Work popup (records meeting-stance.jsonl; page-press POST)
|
|
160
163
|
'routes-code-map', // idea A176: the product's code map on Work, redrawn when the default branch moves (records code-map.json; read-only)
|
|
161
164
|
'routes-arch-warns', // idea A54: one warning when an initiative names a risky part of the code (reads code-map.json; read-only)
|
|
162
165
|
'routes-live-rows', // bet A458: chat-made task changes streamed to open pages (runtime live-events.jsonl; read-only event stream)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-meeting-stance.js — where each person stands on an initiative's contested decision, over HTTP (initiative meeting-stance, job
|
|
3
|
+
* #1897, idea A333). The store and the fold are lib/meeting-stance.js (meeting-stance.jsonl in the product's records folder,
|
|
4
|
+
* lib/records-dir.js); the verb is `pmos people stance`.
|
|
5
|
+
*
|
|
6
|
+
* GET /api/meeting-stance?ini=<id>&ws=<id> → { ok, stance } stance is null when no decision of the initiative is contested
|
|
7
|
+
* POST /api/meeting-stance { ws, ini, decision, act, person?, name?, q?, says?, people? } → { ok, line } | 400 act ∈ sent · answer · undo
|
|
8
|
+
*
|
|
9
|
+
* WHO WRITES. A page press: pm-guard requirePagePress checks the page's Origin and launch nonce. The chat writes with `pmos people stance`.
|
|
10
|
+
* Nothing here reads a connector or sends anything: the PM sends the questions, and "I sent them" only records that. */
|
|
11
|
+
const guard = require('./pm-guard.js');
|
|
12
|
+
const MS = require('./meeting-stance.js');
|
|
13
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
14
|
+
|
|
15
|
+
const INI_RE = /^[a-z0-9][a-z0-9-]{0,79}$/;
|
|
16
|
+
function wsOf(ctx, ws) { try { return ctx && typeof ctx.getWs === 'function' ? ctx.getWs(ws || null) : null; } catch { return null; } }
|
|
17
|
+
const rootOf = (ctx, w) => (ctx && ctx.repoRoot) || (w && w.root) || (ctx && ctx.selfRoot) || null;
|
|
18
|
+
function stateDirOf(ctx, w) { try { return ctx && typeof ctx.stateDirFor === 'function' && w ? ctx.stateDirFor(w) : null; } catch { return null; } }
|
|
19
|
+
|
|
20
|
+
async function handle(req, res, url, ctx) {
|
|
21
|
+
if (url.pathname !== '/api/meeting-stance') return false;
|
|
22
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
23
|
+
if (req.method === 'GET') {
|
|
24
|
+
const ini = String(url.searchParams.get('ini') || '');
|
|
25
|
+
if (!INI_RE.test(ini)) return send(400, { ok: false, error: 'Name the initiative: ?ini=<id>.' });
|
|
26
|
+
const wsId = url.searchParams.get('ws') || null;
|
|
27
|
+
const w = wsOf(ctx, wsId), root = rootOf(ctx, w);
|
|
28
|
+
if (!root) return send(404, { ok: false, error: 'no such workspace' });
|
|
29
|
+
const stance = MS.read(root, ini, { stateDir: stateDirOf(ctx, w), dir: recordsDirFor(ctx, wsId), people: ctx.people || undefined });
|
|
30
|
+
return send(200, { ok: true, stance });
|
|
31
|
+
}
|
|
32
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
|
|
33
|
+
const rd = await ctx.readJson(req);
|
|
34
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
35
|
+
const body = rd.body || {};
|
|
36
|
+
const g = guard.requirePagePress(req, body);
|
|
37
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
38
|
+
const r = MS.act(recordsDirFor(ctx, body.ws || null), { ini: body.ini, decision: body.decision, kind: String(body.act || ''), person: body.person,
|
|
39
|
+
name: body.name, q: body.q, says: body.says, people: body.people }, { by: (g.actor && g.actor.by) || 'pm' });
|
|
40
|
+
return r.ok ? send(200, { ok: true, line: r.line }) : send(400, { ok: false, error: r.error });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = { prefixes: ['/api/meeting-stance'], handle };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-segments.js — a product's user groups over HTTP (idea A327, initiative segments). The store is lib/segments.js (segments.jsonl in
|
|
3
|
+
* the product's records folder, lib/records-dir.js); the verb is `pmos segments`.
|
|
4
|
+
*
|
|
5
|
+
* GET /api/segments?ws=<id> → { ok, rows, total, line, offer } rows: the groups not dropped, most users first, each with
|
|
6
|
+
* roadmap (its live tagged initiatives); line: the one imbalance line, or null;
|
|
7
|
+
* offer: { items } when no group exists yet and 3+ roadmap items are live, else null
|
|
8
|
+
* POST /api/segments { ws, act, gid, to? } → { ok, group } | 400 act ∈ keep · rename · drop · undo
|
|
9
|
+
*
|
|
10
|
+
* The live initiatives are the product's own (lib/list-balance.js roadmapItems: not stopped, not accepted); ctx.segmentsLive overrides
|
|
11
|
+
* them in a test. WHO WRITES. A page press: pm-guard requirePagePress checks the page's Origin and launch nonce. The chat drafts and tags
|
|
12
|
+
* with `pmos segments`. Nothing here is sent anywhere. */
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const guard = require('./pm-guard.js');
|
|
15
|
+
const SG = require('./segments.js');
|
|
16
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
17
|
+
|
|
18
|
+
const CHECKOUT = path.join(__dirname, '..', '..');
|
|
19
|
+
const PAGE_ACTS = ['keep', 'rename', 'drop', 'undo'];
|
|
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
|
+
function liveOf(ctx, w) {
|
|
23
|
+
if (ctx && Array.isArray(ctx.segmentsLive)) return ctx.segmentsLive;
|
|
24
|
+
try { return require('./list-balance.js').roadmapItems(rootFor(ctx, w)).map((x) => x.id); } catch { return []; }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function handle(req, res, url, ctx) {
|
|
28
|
+
if (url.pathname !== '/api/segments') return false;
|
|
29
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
30
|
+
if (req.method === 'GET') {
|
|
31
|
+
const wsId = url.searchParams.get('ws') || null;
|
|
32
|
+
const v = SG.view(recordsDirFor(ctx, wsId), liveOf(ctx, wsOf(ctx, wsId)));
|
|
33
|
+
return send(200, { ok: true, rows: v.rows, total: v.total, line: v.line, offer: v.offer });
|
|
34
|
+
}
|
|
35
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
|
|
36
|
+
const rd = await ctx.readJson(req);
|
|
37
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
38
|
+
const body = rd.body || {};
|
|
39
|
+
const g = guard.requirePagePress(req, body);
|
|
40
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
41
|
+
const a = String(body.act || '');
|
|
42
|
+
if (!PAGE_ACTS.includes(a)) return send(400, { ok: false, error: 'act is one of: ' + PAGE_ACTS.join(', ') });
|
|
43
|
+
const r = SG.act(recordsDirFor(ctx, body.ws || null), a, { gid: body.gid, to: body.to });
|
|
44
|
+
return r.ok ? send(200, { ok: true, group: r.group }) : send(400, { ok: false, error: r.error });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = { prefixes: ['/api/segments'], handle, PAGE_ACTS };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-surface-moments.js — the moments in Your move over HTTP (initiative surface-moments, job #1985; LINE.md Rule 12). lib/surface-moments.js
|
|
3
|
+
* holds the rules; pm/cozy-today-app.js asks for the rows and draws them.
|
|
4
|
+
*
|
|
5
|
+
* GET /api/surface-moments?ws=&free=&away=&awayWord=&awayFrom=&steer=&steerDay=&steerWord= → { ok, ws, rows: [row] } reads only
|
|
6
|
+
* POST /api/surface-moments { ws, kind, until?, job?, id?, file?, undo? } → { ok, said, file?, undo? } | 4xx
|
|
7
|
+
*
|
|
8
|
+
* WHO WRITES. A page press only: pm-guard requirePagePress checks the page's Origin and launch nonce before any ✓ or Undo. Nothing here
|
|
9
|
+
* sends anything. */
|
|
10
|
+
const guard = require('./pm-guard.js');
|
|
11
|
+
const SM = require('./surface-moments.js');
|
|
12
|
+
|
|
13
|
+
async function handle(req, res, url, ctx) {
|
|
14
|
+
if (url.pathname !== '/api/surface-moments') return false;
|
|
15
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
16
|
+
if (req.method === 'GET') {
|
|
17
|
+
let w = null; try { w = ctx.getWs(url.searchParams.get('ws') || null); } catch { w = null; }
|
|
18
|
+
if (!w || !w.root) return send(404, { ok: false, error: 'no such workspace' });
|
|
19
|
+
const q = Object.fromEntries(['free', 'away', 'awayWord', 'awayFrom', 'steer', 'steerDay', 'steerWord'].map((k) => [k, url.searchParams.get(k) || '']));
|
|
20
|
+
let rows = [];
|
|
21
|
+
try { rows = SM.read(ctx, w, q); } catch (e) { return send(500, { ok: false, error: 'the moments could not be read: ' + (e && e.message) }); }
|
|
22
|
+
return send(200, { ok: true, ws: w.id, rows });
|
|
23
|
+
}
|
|
24
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
|
|
25
|
+
const rd = await ctx.readJson(req);
|
|
26
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
27
|
+
const body = rd.body || {};
|
|
28
|
+
const g = guard.requirePagePress(req, body);
|
|
29
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
30
|
+
let w = null; try { w = ctx.getWs(body.ws || null); } catch { w = null; }
|
|
31
|
+
if (!w || !w.root) return send(404, { ok: false, error: 'no such workspace' });
|
|
32
|
+
const r = SM.act(ctx, w, body);
|
|
33
|
+
return r.ok ? send(200, r) : send(400, { ok: false, error: r.error });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { prefixes: ['/api/surface-moments'], handle };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* segments-cli.js — `pmos segments`: a product's user groups and the roadmap items that serve each, the same groups the Segments part on
|
|
3
|
+
* Work shows (idea A327, initiative segments). The store is lib/segments.js (segments.jsonl in the product's records folder).
|
|
4
|
+
*
|
|
5
|
+
* pmos segments list [--json] the groups, most users first, each with its roadmap count; the ✦ line
|
|
6
|
+
* pmos segments draft --name "<group>" --users <n> --source "<connector · what>" [--health 0-100] [--uses "<text>"] [--asks "<text>"]
|
|
7
|
+
* PMOS's draft from a usage or revenue read; refused with no --source
|
|
8
|
+
* pmos segments add --name "<group>" --users <n> [--health …] [--uses …] [--asks …] [--source …] the PM's own group, kept at once
|
|
9
|
+
* pmos segments keep <group> keep a draft
|
|
10
|
+
* pmos segments rename <group> --to "<name>" rename a group (keeps a draft)
|
|
11
|
+
* pmos segments drop <group> hide a group
|
|
12
|
+
* pmos segments undo <group> take back the last change to a group
|
|
13
|
+
* pmos segments tag <group> <initiative> · untag <group> <initiative> the roadmap item serves the group (live initiatives only)
|
|
14
|
+
* every command: [--root <dir>] (default: this repository). <group> is its name or its id (sg_…).
|
|
15
|
+
*
|
|
16
|
+
* Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const SG = require('./segments.js');
|
|
20
|
+
|
|
21
|
+
const COMMANDS = { segments: ['list', 'draft', 'add', 'keep', 'rename', 'drop', 'undo', 'tag', 'untag'] };
|
|
22
|
+
const USAGE = [
|
|
23
|
+
'usage: pmos segments list|draft|add|keep|rename|drop|undo|tag|untag — the product\'s user groups and the roadmap items that serve each',
|
|
24
|
+
' pmos segments list [--json] the groups, most users first, with their roadmap count; ✦ marks a draft',
|
|
25
|
+
' pmos segments draft --name "Small teams" --users 4120 --source "<connector · what you read>" [--health 0-100] [--uses "…"] [--asks "…"]',
|
|
26
|
+
' pmos segments add --name "Small teams" --users 4120 [--health 0-100] [--uses "…"] [--asks "…"] your own group, kept at once',
|
|
27
|
+
' pmos segments keep|drop|undo <group> keep a draft, hide a group, or take back its last change',
|
|
28
|
+
' pmos segments rename <group> --to "<name>" rename a group; a renamed draft is kept',
|
|
29
|
+
' pmos segments tag|untag <group> <initiative> the roadmap item serves the group',
|
|
30
|
+
'At most ' + SG.MAX_GROUPS + ' groups. Run it in the product\'s repository, or pass --root <dir>.',
|
|
31
|
+
];
|
|
32
|
+
const GROUP = ['json', 'root'];
|
|
33
|
+
const FIELDS = ['json', 'root', 'name', 'users', 'health', 'uses', 'asks', 'source'];
|
|
34
|
+
const ALLOWED = { list: GROUP, draft: FIELDS, add: FIELDS, keep: GROUP, rename: [...GROUP, 'to'], drop: GROUP, undo: GROUP, tag: GROUP, untag: GROUP };
|
|
35
|
+
const ARGS = { list: 0, draft: 0, add: 0, keep: 1, rename: 1, drop: 1, undo: 1, tag: 2, untag: 2 };
|
|
36
|
+
const BOOL = new Set(['json']);
|
|
37
|
+
|
|
38
|
+
function parse(args) {
|
|
39
|
+
const pos = [], flags = {};
|
|
40
|
+
for (let i = 0; i < args.length; i++) {
|
|
41
|
+
const a = args[i];
|
|
42
|
+
if (!a.startsWith('--')) { pos.push(a); continue; }
|
|
43
|
+
const k = a.slice(2);
|
|
44
|
+
if (BOOL.has(k)) { flags[k] = true; continue; }
|
|
45
|
+
flags[k] = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
|
|
46
|
+
}
|
|
47
|
+
return { pos, flags };
|
|
48
|
+
}
|
|
49
|
+
function repoRoot(cwd) { // the nearest folder up from cwd that holds .git; cwd itself when none does
|
|
50
|
+
for (let d = path.resolve(cwd); ; d = path.dirname(d)) {
|
|
51
|
+
if (fs.existsSync(path.join(d, '.git'))) return d;
|
|
52
|
+
if (path.dirname(d) === d) return cwd;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function recordsDirOf(root) {
|
|
56
|
+
try { const { repoScript } = require('./repo-script.js'); return require(repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; } catch { return path.join(root, 'planning', 'records'); }
|
|
57
|
+
}
|
|
58
|
+
/** The live initiative ids of the product (not stopped, not accepted). */
|
|
59
|
+
function liveOf(root) { try { return require('./list-balance.js').roadmapItems(root).map((x) => x.id); } catch { return []; } }
|
|
60
|
+
|
|
61
|
+
async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Date.now() } = {}) {
|
|
62
|
+
const args = argv[0] === 'segments' ? argv.slice(1) : argv.slice();
|
|
63
|
+
const sub = args[0];
|
|
64
|
+
if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
|
|
65
|
+
if (!COMMANDS.segments.includes(sub)) { say(`unknown segments command "${sub}". Use one of: ${COMMANDS.segments.join(', ')}`); return 2; }
|
|
66
|
+
const { pos, flags } = parse(args.slice(1));
|
|
67
|
+
for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos segments ${sub}`); return 2; }
|
|
68
|
+
if (pos.length !== ARGS[sub]) { say(`✗ pmos segments ${sub} takes ${ARGS[sub] === 0 ? 'options only' : ARGS[sub] === 1 ? 'one group' : 'a group and an initiative'} (pmos segments help)`); return 2; }
|
|
69
|
+
const root = path.resolve(flags.root || repoRoot(cwd));
|
|
70
|
+
const dir = recordsDirOf(root);
|
|
71
|
+
const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
|
|
72
|
+
|
|
73
|
+
if (sub === 'list') {
|
|
74
|
+
const v = SG.view(dir, liveOf(root));
|
|
75
|
+
if (flags.json) { say(JSON.stringify({ ok: true, rows: v.rows, total: v.total, line: v.line })); return 0; }
|
|
76
|
+
if (!v.rows.length) { say('No groups yet. Draft them from a usage or revenue read: pmos segments draft --name "<group>" --users <n> --source "<where>".'); return 0; }
|
|
77
|
+
for (const r of v.rows) {
|
|
78
|
+
say(` ${r.draft ? '✦' : ' '} ${r.name} · ${r.users.toLocaleString('en-US')} users${r.health !== null ? ` · health ${r.health}` : ''} · ${r.roadmap ? r.roadmap + ' roadmap item' + (r.roadmap === 1 ? '' : 's') : 'nothing on the roadmap'} (${r.gid})`);
|
|
79
|
+
const more = [r.uses ? 'uses ' + r.uses : '', r.asks ? 'asks for ' + r.asks : '', r.draft && r.source ? 'from ' + r.source : ''].filter(Boolean).join(' · ');
|
|
80
|
+
if (more) say(' ' + more);
|
|
81
|
+
}
|
|
82
|
+
if (v.line) say('\n✦ ' + v.line.text);
|
|
83
|
+
if (v.rows.some((r) => r.draft)) say('\nKeep or rename a draft: pmos segments keep <group> · pmos segments rename <group> --to "<name>"');
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const o = { ...flags };
|
|
88
|
+
if (sub === 'rename') o.to = flags.to;
|
|
89
|
+
if (ARGS[sub] >= 1) o.gid = pos[0];
|
|
90
|
+
if (sub === 'tag' || sub === 'untag') { o.initiative = pos[1]; if (sub === 'tag') o.live = liveOf(root); }
|
|
91
|
+
const r = SG.act(dir, sub, o, now);
|
|
92
|
+
if (!r.ok) return fail(r.error);
|
|
93
|
+
if (flags.json) { say(JSON.stringify({ ok: true, group: r.group })); return 0; }
|
|
94
|
+
const g = r.group;
|
|
95
|
+
const word = { draft: 'Drafted', add: 'Added', keep: 'Kept', rename: 'Renamed', drop: 'Dropped', undo: 'Undone', tag: 'Tagged', untag: 'Untagged' }[sub];
|
|
96
|
+
say(`✓ ${word}: ${g ? g.name + ' (' + g.gid + ')' : pos[0]}${o.initiative ? ' · ' + o.initiative : ''}. Undo: pmos segments undo ${g ? g.gid : pos[0]}`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = { run, COMMANDS, USAGE };
|
|
101
|
+
|
|
102
|
+
if (require.main === module) run(process.argv.slice(2)).then((c) => process.exit(c), (e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* segments.js — a product's user groups and the roadmap items that serve each (idea A327, initiative segments; done test
|
|
3
|
+
* planning/done-tests/segments.md; board BatchPlanDS panel 6).
|
|
4
|
+
*
|
|
5
|
+
* A few groups (at most MAX_GROUPS) split the product's users by usage and revenue. Each has a size (users), a health from 0 to 100,
|
|
6
|
+
* what the group uses and what it asks for. Roadmap items (the live initiatives) carry a group tag; the Roadmap column counts them.
|
|
7
|
+
* When one large group gets little of the roadmap, one line says so (say it once).
|
|
8
|
+
*
|
|
9
|
+
* THE FILE: segments.jsonl in the product's records folder (lib/records-dir.js: planning/records in the PMOS repo, pmos/state/records in a
|
|
10
|
+
* kit product). Append-only JSON lines, one event each:
|
|
11
|
+
* { v, at, ev: 'draft', gid, name, users, health?, uses?, asks?, source, by: 'pmos' } PMOS's draft, citing the usage or revenue read
|
|
12
|
+
* { v, at, ev: 'add', gid, name, users, health?, uses?, asks?, source?, by: 'pm' } the PM's own group, kept at once
|
|
13
|
+
* { v, at, ev: 'keep', gid } a draft kept
|
|
14
|
+
* { v, at, ev: 'rename', gid, name } a new name; renaming keeps a draft
|
|
15
|
+
* { v, at, ev: 'drop', gid } hidden
|
|
16
|
+
* { v, at, ev: 'tag', gid, initiative } the initiative serves the group
|
|
17
|
+
* { v, at, ev: 'untag', gid, initiative }
|
|
18
|
+
* { v, at, ev: 'undo', gid } takes back the last event of that group that still stands
|
|
19
|
+
* A draft for a name that already has a group updates that group's numbers (a fresh read), and keeps its state.
|
|
20
|
+
*
|
|
21
|
+
* readLines(dir) · append(dir, line, now?)
|
|
22
|
+
* fold(lines) → [group] group: { gid, name, users, health, uses, asks, source, by, state, tags }
|
|
23
|
+
* state ∈ draft · kept · dropped
|
|
24
|
+
* act(dir, act, o, now?) → { ok, group?, error? } act ∈ draft · add · keep · rename · drop · tag · untag · undo
|
|
25
|
+
* rowsOf(groups, liveIds) → { rows, total } rows: the groups not dropped, most users first, each with roadmap: n
|
|
26
|
+
* (live tagged items); total: the live items tagged with any of them
|
|
27
|
+
* imbalanceOf({ rows, total }) → null | { gid, name, pct, n, total, text }
|
|
28
|
+
* view(dir, liveIds) → { groups, rows, total, line }
|
|
29
|
+
* count(dirs) → kept groups (the health number)
|
|
30
|
+
*
|
|
31
|
+
* THE LINE. A group with SHARE_MIN (30%) or more of all users whose share of the tagged roadmap is a third or less of its user share,
|
|
32
|
+
* with MIN_TAGGED (3) or more tagged items. Only the group with the largest gap is named. No group passes: no line (zero is silence).
|
|
33
|
+
*
|
|
34
|
+
* Nothing here is sent anywhere. Works on any product built with PMOS. Every write logs [segments]. */
|
|
35
|
+
const fs = require('fs');
|
|
36
|
+
const path = require('path');
|
|
37
|
+
const crypto = require('crypto');
|
|
38
|
+
|
|
39
|
+
const TAG = '[segments]';
|
|
40
|
+
const FILE = 'segments.jsonl';
|
|
41
|
+
const MAX_GROUPS = 6;
|
|
42
|
+
const MAX_NAME = 40;
|
|
43
|
+
const MAX_TEXT = 80;
|
|
44
|
+
const MAX_SOURCE = 120;
|
|
45
|
+
const SHARE_MIN = 0.3;
|
|
46
|
+
const MIN_TAGGED = 3;
|
|
47
|
+
const ACTS = Object.freeze(['draft', 'add', 'keep', 'rename', 'drop', 'tag', 'untag', 'undo']);
|
|
48
|
+
const say = (s) => { try { console.log(TAG + ' ' + s); } catch { /* no console */ } };
|
|
49
|
+
|
|
50
|
+
const one = (v, max) => { const s = String(v == null ? '' : v).replace(/\s+/g, ' ').trim(); return s.length > max ? s.slice(0, max - 1).trimEnd() + '…' : s; };
|
|
51
|
+
const gidOf = (name) => 'sg_' + crypto.createHash('sha1').update(one(name, MAX_NAME).toLowerCase()).digest('hex').slice(0, 8);
|
|
52
|
+
const fileOf = (dir) => path.join(dir, FILE);
|
|
53
|
+
|
|
54
|
+
function readLines(dir) {
|
|
55
|
+
if (!dir) return [];
|
|
56
|
+
let text = '';
|
|
57
|
+
try { text = fs.readFileSync(fileOf(dir), 'utf8'); } catch { return []; }
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object' && ACTS.includes(o.ev) && o.gid) out.push(o); } catch { /* a torn line is skipped */ } }
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function append(dir, line, now = Date.now()) {
|
|
64
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
65
|
+
const l = { v: 1, at: new Date(now).toISOString(), ...line };
|
|
66
|
+
fs.appendFileSync(fileOf(dir), JSON.stringify(l) + '\n');
|
|
67
|
+
return l;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Each group's events that still stand: an undo takes back the last one. */
|
|
71
|
+
function standing(lines) {
|
|
72
|
+
const by = new Map();
|
|
73
|
+
for (const l of lines) {
|
|
74
|
+
if (!by.has(l.gid)) by.set(l.gid, []);
|
|
75
|
+
const st = by.get(l.gid);
|
|
76
|
+
if (l.ev === 'undo') st.pop(); else st.push(l);
|
|
77
|
+
}
|
|
78
|
+
return by;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function fold(lines) {
|
|
82
|
+
const out = [];
|
|
83
|
+
for (const [gid, evs] of standing(lines)) {
|
|
84
|
+
let g = null;
|
|
85
|
+
for (const e of evs) {
|
|
86
|
+
if (e.ev === 'draft' || e.ev === 'add') {
|
|
87
|
+
const nums = { users: Number(e.users) || 0, health: Number.isFinite(e.health) ? e.health : null, uses: e.uses || '', asks: e.asks || '', source: e.source || '' };
|
|
88
|
+
if (!g) g = { gid, name: e.name, by: e.by || (e.ev === 'add' ? 'pm' : 'pmos'), state: e.ev === 'add' ? 'kept' : 'draft', tags: new Set(), ...nums };
|
|
89
|
+
else Object.assign(g, nums);
|
|
90
|
+
} else if (!g) continue;
|
|
91
|
+
else if (e.ev === 'keep') g.state = 'kept';
|
|
92
|
+
else if (e.ev === 'rename') { g.name = e.name; g.state = 'kept'; }
|
|
93
|
+
else if (e.ev === 'drop') g.state = 'dropped';
|
|
94
|
+
else if (e.ev === 'tag') g.tags.add(e.initiative);
|
|
95
|
+
else if (e.ev === 'untag') g.tags.delete(e.initiative);
|
|
96
|
+
}
|
|
97
|
+
if (g) out.push({ ...g, tags: [...g.tags] });
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The fields of a draft or add, checked. → { ok, fields } | { ok: false, error } */
|
|
103
|
+
function fieldsOf(o, { needSource }) {
|
|
104
|
+
const name = one(o.name, MAX_NAME);
|
|
105
|
+
if (!name) return { ok: false, error: 'a group needs a name' };
|
|
106
|
+
const users = Number(o.users);
|
|
107
|
+
if (!Number.isInteger(users) || users < 0) return { ok: false, error: 'users is a whole number, 0 or more' };
|
|
108
|
+
let health = null;
|
|
109
|
+
if (o.health !== undefined && o.health !== null && o.health !== '') {
|
|
110
|
+
health = Number(o.health);
|
|
111
|
+
if (!Number.isFinite(health) || health < 0 || health > 100) return { ok: false, error: 'health is a number from 0 to 100' };
|
|
112
|
+
health = Math.round(health);
|
|
113
|
+
}
|
|
114
|
+
const source = one(o.source, MAX_SOURCE);
|
|
115
|
+
if (needSource && !source) return { ok: false, error: 'a PMOS draft names the usage or revenue read it came from (--source "<connector · what>")' };
|
|
116
|
+
const f = { name, users, uses: one(o.uses, MAX_TEXT), asks: one(o.asks, MAX_TEXT) };
|
|
117
|
+
if (health !== null) f.health = health;
|
|
118
|
+
if (source) f.source = source;
|
|
119
|
+
return { ok: true, fields: f };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** One write. o: { gid?, name?, users?, health?, uses?, asks?, source?, initiative?, live? (the live initiative ids, for a tag) }. */
|
|
123
|
+
function act(dir, a, o = {}, now = Date.now()) {
|
|
124
|
+
if (!ACTS.includes(a)) return { ok: false, error: 'act is one of: ' + ACTS.join(', ') };
|
|
125
|
+
const groups = fold(readLines(dir));
|
|
126
|
+
const find = (ref) => { const r = String(ref || '').trim(); if (!r) return null; const low = r.toLowerCase(); return groups.find((g) => g.gid === r) || groups.find((g) => g.name.toLowerCase() === low) || null; };
|
|
127
|
+
if (a === 'draft' || a === 'add') {
|
|
128
|
+
const f = fieldsOf(o, { needSource: a === 'draft' });
|
|
129
|
+
if (!f.ok) return f;
|
|
130
|
+
const had = find(f.fields.name);
|
|
131
|
+
if (had && had.state === 'dropped' && a === 'draft') return { ok: false, error: `"${had.name}" was dropped; undo the drop to bring it back` };
|
|
132
|
+
if (!had && groups.filter((g) => g.state !== 'dropped').length >= MAX_GROUPS) return { ok: false, error: `a product keeps at most ${MAX_GROUPS} groups; drop one first` };
|
|
133
|
+
const gid = had ? had.gid : gidOf(f.fields.name);
|
|
134
|
+
append(dir, { ev: a, gid, ...f.fields, by: a === 'draft' ? 'pmos' : 'pm' }, now);
|
|
135
|
+
say(`${a} ${gid} "${f.fields.name}" users=${f.fields.users}${f.fields.source ? ' source="' + f.fields.source + '"' : ''}`);
|
|
136
|
+
return { ok: true, group: fold(readLines(dir)).find((g) => g.gid === gid) || null };
|
|
137
|
+
}
|
|
138
|
+
const g = find(o.gid || o.name);
|
|
139
|
+
if (!g) return { ok: false, error: `no group "${o.gid || o.name || ''}" on this product` };
|
|
140
|
+
const line = { ev: a, gid: g.gid };
|
|
141
|
+
if (a === 'keep' && g.state !== 'draft') return { ok: false, error: `"${g.name}" is not a draft` };
|
|
142
|
+
if (a === 'rename') { const name = one(o.to !== undefined ? o.to : o.newName, MAX_NAME); if (!name) return { ok: false, error: 'rename needs the new name' }; line.name = name; }
|
|
143
|
+
if (a === 'drop' && g.state === 'dropped') return { ok: false, error: `"${g.name}" is already dropped` };
|
|
144
|
+
if (a === 'tag' || a === 'untag') {
|
|
145
|
+
const ini = String(o.initiative || '').trim();
|
|
146
|
+
if (!ini) return { ok: false, error: a + ' needs the initiative id' };
|
|
147
|
+
if (g.state === 'dropped') return { ok: false, error: `"${g.name}" is dropped` };
|
|
148
|
+
if (a === 'tag' && Array.isArray(o.live) && !o.live.includes(ini)) return { ok: false, error: `${ini} is not a live initiative of this product` };
|
|
149
|
+
if (a === 'tag' && g.tags.includes(ini)) return { ok: true, group: g };
|
|
150
|
+
if (a === 'untag' && !g.tags.includes(ini)) return { ok: false, error: `${ini} is not tagged "${g.name}"` };
|
|
151
|
+
line.initiative = ini;
|
|
152
|
+
}
|
|
153
|
+
append(dir, line, now);
|
|
154
|
+
say(`${a} ${g.gid} "${g.name}"${line.initiative ? ' ' + line.initiative : ''}${line.name ? ' → "' + line.name + '"' : ''}`);
|
|
155
|
+
return { ok: true, group: fold(readLines(dir)).find((x) => x.gid === g.gid) || null };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function rowsOf(groups, liveIds) {
|
|
159
|
+
const live = new Set(liveIds || []);
|
|
160
|
+
const shown = groups.filter((g) => g.state !== 'dropped');
|
|
161
|
+
const all = new Set();
|
|
162
|
+
const rows = shown.map((g) => {
|
|
163
|
+
const items = g.tags.filter((t) => live.has(t));
|
|
164
|
+
items.forEach((t) => all.add(t));
|
|
165
|
+
return { gid: g.gid, name: g.name, users: g.users, health: g.health, uses: g.uses, asks: g.asks, source: g.source, draft: g.state === 'draft', roadmap: items.length, items };
|
|
166
|
+
});
|
|
167
|
+
rows.sort((a, b) => b.users - a.users || a.name.localeCompare(b.name));
|
|
168
|
+
return { rows, total: all.size };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function imbalanceOf({ rows, total }) {
|
|
172
|
+
if (!Array.isArray(rows) || rows.length < 2 || !(total >= MIN_TAGGED)) return null;
|
|
173
|
+
const U = rows.reduce((s, r) => s + (r.users || 0), 0);
|
|
174
|
+
if (U <= 0) return null;
|
|
175
|
+
let best = null;
|
|
176
|
+
for (const r of rows) {
|
|
177
|
+
const us = r.users / U, is = r.roadmap / total;
|
|
178
|
+
if (us < SHARE_MIN || is > us / 3) continue;
|
|
179
|
+
const gap = us - is;
|
|
180
|
+
if (!best || gap > best.gap) best = { r, gap, us };
|
|
181
|
+
}
|
|
182
|
+
if (!best) return null;
|
|
183
|
+
const pct = Math.round(best.us * 100), n = best.r.roadmap;
|
|
184
|
+
return { gid: best.r.gid, name: best.r.name, pct, n, total, text: `${best.r.name} are ${pct}% of users and get ${n === 0 ? 'none' : n} of the ${total} roadmap items.` };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function view(dir, liveIds) {
|
|
188
|
+
const groups = fold(readLines(dir));
|
|
189
|
+
const r = rowsOf(groups, liveIds);
|
|
190
|
+
return { groups, rows: r.rows, total: r.total, line: imbalanceOf(r), offer: offerOf(groups, liveIds) };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The ✦ offer on Work when the product has no group yet (LINE.md Rule 12: the part shows by itself, never only on a typed ask): it has
|
|
194
|
+
* MIN_TAGGED live roadmap items or more and no group ever drafted, added or dropped. Fewer items, or any group at all: null (silence). */
|
|
195
|
+
function offerOf(groups, liveIds) {
|
|
196
|
+
const items = new Set((liveIds || []).map(String)).size;
|
|
197
|
+
return !(groups || []).length && items >= MIN_TAGGED ? { items } : null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function count(dirs) {
|
|
201
|
+
let n = 0;
|
|
202
|
+
for (const d of dirs || []) n += fold(readLines(d)).filter((g) => g.state === 'kept').length;
|
|
203
|
+
return n;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
module.exports = { TAG, FILE, MAX_GROUPS, SHARE_MIN, MIN_TAGGED, ACTS, gidOf, readLines, append, fold, act, rowsOf, imbalanceOf, offerOf, view, count };
|
|
207
|
+
|
|
208
|
+
if (require.main === module) {
|
|
209
|
+
if (process.argv[2] !== 'count') { console.error('usage: node workspace/lib/segments.js count [<product checkout>] (the groups the PM kept)'); process.exit(2); }
|
|
210
|
+
const root = process.argv[3] || process.cwd();
|
|
211
|
+
let dir = null;
|
|
212
|
+
try { const { repoScript } = require('./repo-script.js'); dir = require(repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; } catch { dir = path.join(root, 'planning', 'records'); }
|
|
213
|
+
console.log(String(count([dir])));
|
|
214
|
+
}
|