create-pmos 0.848.0 → 0.849.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.848.0",
3
+ "version": "0.849.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -33,6 +33,30 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.849.0",
38
+ "at": "2026-11-25T18:55:50.990Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 2057,
43
+ "t": "A target mix for the roadmap and the rank move that closes the gap (job #2051)",
44
+ "s": "A target mix for the roadmap and the rank move that closes the gap (job #2051)",
45
+ "k": "new",
46
+ "h": "A target mix for the roadmap and the rank move that closes the gap (job #2051)",
47
+ "try": {
48
+ "steps": [
49
+ "On Today, find the row in Your move that proposes a target mix for the top of your roadmap, drawn from the roadmap itself. Press its ✦ to…",
50
+ "The row then names the rank move that closes the most gap. Press its ✦, check the Roadmap on Work, then press Undo",
51
+ "Open the chat (Ask PMOS). On a desk the chat opens from the menu button at the bottom left, then the speech bubble. Say: set my roadmap…"
52
+ ],
53
+ "see": "When the top of the roadmap leans one way, Today proposes a target mix by itself and ✦ saves it. Then a Today row names the one rank move that closes the most gap. ✦ makes that rank move and Undo…",
54
+ "open": "/today.html"
55
+ },
56
+ "i": "balance-rebalance"
57
+ }
58
+ ]
59
+ },
36
60
  {
37
61
  "v": "0.848.0",
38
62
  "at": "2026-11-25T18:33:59.152Z",
@@ -43,6 +67,7 @@
43
67
  "t": "Pmos change-request records a stakeholder's ask with what it would break (job #2024)",
44
68
  "s": "Pmos change-request records a stakeholder's ask with what it would break (job #2024)",
45
69
  "k": "new",
70
+ "i": "change-requests",
46
71
  "h": "Pmos change-request records a stakeholder's ask with what it would break (job #2024)",
47
72
  "try": {
48
73
  "steps": [
@@ -52,8 +77,7 @@
52
77
  ],
53
78
  "see": "Each open change request is a Today row by itself, naming who asked and what it would break. Approve records your answer and Undo takes it back. A new ask from the chat is recorded with an id and…",
54
79
  "open": "/today.html"
55
- },
56
- "i": "change-requests"
80
+ }
57
81
  }
58
82
  ]
59
83
  },
@@ -1025,71 +1049,6 @@
1025
1049
  }
1026
1050
  }
1027
1051
  ]
1028
- },
1029
- {
1030
- "v": "0.825.0",
1031
- "at": "2026-11-25T10:33:55.582Z",
1032
- "f": 4,
1033
- "prs": [
1034
- {
1035
- "n": 1939,
1036
- "t": "Settings › What PMOS does alone, one read-only table of each kind of action (A513)",
1037
- "s": "Settings › What PMOS does alone, one read-only table of each kind of action (A513)",
1038
- "k": "new",
1039
- "i": "does-alone"
1040
- },
1041
- {
1042
- "n": 1949,
1043
- "t": "Names in a Today line link to the person, meeting or document (job #1915, A536)",
1044
- "s": "Names in a Today line link to the person, meeting or document (job #1915, A536)",
1045
- "k": "new",
1046
- "i": "name-links",
1047
- "h": "Names in a Today line link to the person, meeting or document (job #1915, A536)",
1048
- "try": {
1049
- "steps": [
1050
- "Open Today",
1051
- "In the capture line type a line that names a person from People or a meeting you took notes in, for example 'Follow up on Azhar's notes…",
1052
- "Point at or tap the underlined name"
1053
- ],
1054
- "see": "The names that match one record are underlined. A small card shows the record (a meeting's date, people and notes) with one press: Open the notes, Open the document, or Ask PMOS about the person. A…",
1055
- "open": "/today.html"
1056
- }
1057
- },
1058
- {
1059
- "n": 1953,
1060
- "t": "What each connector reads and writes (job #1920, A150)",
1061
- "s": "What each connector reads and writes (job #1920, A150)",
1062
- "k": "new",
1063
- "i": "connector-data",
1064
- "h": "What each connector reads and writes (job #1920, A150)",
1065
- "try": {
1066
- "steps": [
1067
- "On Today, open Settings from the rail and go to Connectors.",
1068
- "Read the one line under Jira (or any connector you have).",
1069
- "Press the arrow on that row to open its page."
1070
- ],
1071
- "see": "Each connected row says in one line what PMOS reads and writes. The page shows What PMOS reads, What PMOS writes and What leaves this computer, with a switch only where PMOS can really stop the read.",
1072
- "open": "/today.html"
1073
- }
1074
- },
1075
- {
1076
- "n": 1941,
1077
- "t": "Hold the phone chat mic to talk (job #1891, A13)",
1078
- "s": "Hold the phone chat mic to talk (job #1891, A13)",
1079
- "k": "new",
1080
- "i": "hold-to-talk",
1081
- "h": "Hold the phone chat mic to talk (job #1891, A13)",
1082
- "try": {
1083
- "steps": [
1084
- "On a phone, open Today and its chat.",
1085
- "Press and hold the mic, say what to change (for example: move <one of your tasks> a day), and let go.",
1086
- "Press Undo under PMOS's answer, then hold again and slide left before letting go."
1087
- ],
1088
- "see": "Your words show above the mic while you hold it; letting go sends them like typing, so the change is done with Undo (a question gets an answer); sliding left cancels and nothing is sent.",
1089
- "open": "/today.html"
1090
- }
1091
- }
1092
- ]
1093
1052
  }
1094
1053
  ]
1095
1054
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@86fc4382a
1
+ kernel-source: pmos@92a63b229
2
2
  assembled: 2026-11-25
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-25T18:33:55Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T18:55:46Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-25T18:33:55Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T18:55:46Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-25T18:33:55Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T18:55:46Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,28 @@
1
1
  [
2
+ {
3
+ "v": "0.849.0",
4
+ "at": "2026-11-25T18:55:50.990Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 2057,
9
+ "t": "A target mix for the roadmap and the rank move that closes the gap (job #2051)",
10
+ "s": "A target mix for the roadmap and the rank move that closes the gap (job #2051)",
11
+ "k": "new",
12
+ "h": "A target mix for the roadmap and the rank move that closes the gap (job #2051)",
13
+ "try": {
14
+ "steps": [
15
+ "On Today, find the row in Your move that proposes a target mix for the top of your roadmap, drawn from the roadmap itself. Press its ✦ to…",
16
+ "The row then names the rank move that closes the most gap. Press its ✦, check the Roadmap on Work, then press Undo",
17
+ "Open the chat (Ask PMOS). On a desk the chat opens from the menu button at the bottom left, then the speech bubble. Say: set my roadmap…"
18
+ ],
19
+ "see": "When the top of the roadmap leans one way, Today proposes a target mix by itself and ✦ saves it. Then a Today row names the one rank move that closes the most gap. ✦ makes that rank move and Undo…",
20
+ "open": "/today.html"
21
+ },
22
+ "i": "balance-rebalance"
23
+ }
24
+ ]
25
+ },
2
26
  {
3
27
  "v": "0.848.0",
4
28
  "at": "2026-11-25T18:33:59.152Z",
@@ -9,6 +33,7 @@
9
33
  "t": "Pmos change-request records a stakeholder's ask with what it would break (job #2024)",
10
34
  "s": "Pmos change-request records a stakeholder's ask with what it would break (job #2024)",
11
35
  "k": "new",
36
+ "i": "change-requests",
12
37
  "h": "Pmos change-request records a stakeholder's ask with what it would break (job #2024)",
13
38
  "try": {
14
39
  "steps": [
@@ -18,8 +43,7 @@
18
43
  ],
19
44
  "see": "Each open change request is a Today row by itself, naming who asked and what it would break. Approve records your answer and Undo takes it back. A new ask from the chat is recorded with an id and…",
20
45
  "open": "/today.html"
21
- },
22
- "i": "change-requests"
46
+ }
23
47
  }
24
48
  ]
25
49
  },
@@ -536,6 +536,16 @@ See if a list leans too far one way, for example all features and no fixes. PMOS
536
536
  - A note shows only when one kind is more than your line of the list, and the list has 5 or more items. The line is 60% unless `--max <percent>` says otherwise. `--json` prints the counts as JSON.
537
537
  - Work shows the same mix as a thin bar under the header of the **Initiatives** list and of the **Backlog**. Press a kind in its legend to show only those items.
538
538
 
539
+ ### pmos balance target: a target mix for the roadmap
540
+
541
+ Say the mix you want at the top of the roadmap, and see which rank move gets you closer to it. PMOS never moves a rank by itself.
542
+
543
+ - `pmos balance target feature:50,fix:30,debt:20` saves the mix you want for the first 6 ranked initiatives of this repository. `--front <N>` sets another number. The kinds are feature, fix, debt, discovery and other, and the parts must add up to 100.
544
+ - `pmos balance target` shows the saved target. `pmos balance target --undo` puts the previous target back, and `pmos balance target --clear` removes it.
545
+ - `pmos balance gap` shows the mix of the top of the roadmap beside the target, and the gap in points (half the sum of the differences). It names at most 2 rank moves that close the most gap: an initiative of a kind under its target, from below the top, moved above one of a kind over its target. Each move is a `pmos initiative after` or `pmos initiative top` command, with the command that undoes it. `--json` prints the same as JSON.
546
+ - When the top of the roadmap is 15 points or more from the target and a move closes some of the gap, Today shows the best move in **Your move**. Press ✦ to make the move, and Undo to put the initiative back.
547
+ - With no target saved, Today can propose one in **Your move**: the mix of your whole roadmap, with the largest kind at most 60%, in steps of 10. It shows only when the top of the roadmap is 15 points or more from that mix and a rank move would help. Press ✦ to save it, and Undo to take it back.
548
+
539
549
  ### pmos decisions: a decision journal
540
550
 
541
551
  Write one line for each product decision, also one that is smaller than an initiative. Each decision has an expected outcome and a date to check it. Run the commands in the product's repository, or pass `--root <dir>`. The journal is `decision-journal.jsonl` in the runs folder (`pmos/state/` in a product, `planning/runs/` in PMOS itself). Commit it to keep it.
@@ -4,6 +4,9 @@
4
4
  * pmos balance show [--by kind|outcome] [--max <percent>] [--json] the roadmap: the live initiatives of this repository
5
5
  * pmos balance show --file <items.json> [--by …] [--max …] [--json] any list: a JSON array of items (ideas, backlog tasks), each with
6
6
  * its own kind, lane or type field, and an outcome field
7
+ * pmos balance target [<kind>:<pct>,…] [--front N] [--undo | --clear] [--json] the mix you want at the top of the roadmap (balance-rebalance)
8
+ * pmos balance gap [--json] how far the top of the roadmap is from it, and the 1-2 rank moves
9
+ * that close the most gap (lib/balance-target.js)
7
10
  * every command: [--root <dir>] (default: this repository)
8
11
  *
9
12
  * It prints the counts, one bar of the mix, and a quiet note only when one kind passes the line (default 60%). Each run writes one
@@ -13,15 +16,19 @@ const fs = require('fs');
13
16
  const path = require('path');
14
17
  const B = require('./list-balance.js');
15
18
 
16
- const COMMANDS = { balance: ['show'] };
19
+ const COMMANDS = { balance: ['show', 'target', 'gap'] };
17
20
  const USAGE = [
18
21
  'usage: pmos balance show — the mix of a list in one line: feature, fix, debt, discovery, or with and without an expected outcome',
19
22
  ' pmos balance show [--by kind|outcome] [--max <percent>] [--json] the roadmap: the live initiatives of this repository',
20
23
  ' pmos balance show --file <items.json> [--by kind|outcome] [--json] any list: a JSON array of items with a kind, lane or type field',
24
+ ' pmos balance target feature:50,fix:30,debt:20 [--front 6] save the mix you want for the first N ranked initiatives',
25
+ ' pmos balance target [--undo | --clear] show it, put the previous one back, or remove it',
26
+ ' pmos balance gap how far the top of the roadmap is from the target, and the rank moves that close it',
21
27
  'A note shows only when one kind is over the line (--max, default 60%). Run it in the product\'s repository, or pass --root <dir>.',
28
+ 'PMOS never moves a rank by itself: gap names the move, and you make it with pmos initiative after|top.',
22
29
  ];
23
- const ALLOWED = ['json', 'root', 'by', 'max', 'file'];
24
- const BOOL = new Set(['json']);
30
+ const ALLOWED = { show: ['json', 'root', 'by', 'max', 'file'], target: ['json', 'root', 'front', 'undo', 'clear'], gap: ['json', 'root'] };
31
+ const BOOL = new Set(['json', 'undo', 'clear']);
25
32
 
26
33
  function parse(args) {
27
34
  const pos = [], flags = {};
@@ -56,14 +63,15 @@ function bar(R) {
56
63
  return R.parts.map((p, i) => (GLYPH[p.key] || '·').repeat(cells[i])).join('');
57
64
  }
58
65
 
59
- async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), log = (s) => console.error(s) } = {}) {
66
+ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), log = (s) => console.error(s), env = process.env, stateDir = null, actor = null } = {}) {
60
67
  const args = argv[0] === 'balance' ? argv.slice(1) : argv.slice();
61
68
  const sub = args[0];
62
69
  if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
63
70
  if (!COMMANDS.balance.includes(sub)) { say(`unknown balance command "${sub}". Use one of: ${COMMANDS.balance.join(', ')}`); return 2; }
64
71
  const { pos, flags } = parse(args.slice(1));
65
- for (const k of Object.keys(flags)) if (!ALLOWED.includes(k)) { say(`✗ --${k} is not an option of pmos balance ${sub}`); return 2; }
72
+ for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos balance ${sub}`); return 2; }
66
73
  const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
74
+ if (sub === 'target' || sub === 'gap') return targetRun(sub, pos, flags, { say, cwd, log, env, stateDir, actor, fail });
67
75
  if (pos.length) return fail('usage: pmos balance show [--by kind|outcome] [--file <items.json>]', 2);
68
76
  if (flags.by !== undefined && !['kind', 'outcome'].includes(flags.by)) return fail('--by is kind or outcome', 2);
69
77
  if (flags.max !== undefined && !(Number(flags.max) > 0 && Number(flags.max) < 100)) return fail('--max is a percent between 1 and 99', 2);
@@ -86,4 +94,49 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), log
86
94
  return 0;
87
95
  }
88
96
 
97
+ /** `pmos balance target` and `pmos balance gap` (initiative balance-rebalance): lib/balance-target.js does the work. */
98
+ function targetRun(sub, pos, flags, { say, cwd, log, env, stateDir, actor, fail }) {
99
+ const T = require('./balance-target.js');
100
+ const root = path.resolve(flags.root || repoRoot(cwd));
101
+ const runtime = stateDir || require('./state-root.js').defaultRoot({ env });
102
+ const by = (actor || require('./actor.js').fromCli({ env })).by;
103
+ const json = !!flags.json;
104
+ const done = (o, text) => { if (json) say(JSON.stringify({ ok: true, ...o })); else for (const l of text) say(l); return 0; };
105
+ const savedWords = (s) => s ? `${T.mixWords(s.target)} for the top ${s.front} of the roadmap` : 'none';
106
+ if (sub === 'target') {
107
+ if (flags.undo && flags.clear) return fail('--undo or --clear, not both', 2);
108
+ if ((flags.undo || flags.clear) && (pos.length || flags.front !== undefined)) return fail(`--${flags.undo ? 'undo' : 'clear'} takes no mix`, 2);
109
+ if (pos.length > 1) return fail('usage: pmos balance target feature:50,fix:30,debt:20 [--front 6]', 2);
110
+ if (flags.undo || flags.clear) {
111
+ const r = flags.undo ? T.undoTarget(runtime, root, { by }) : T.clearTarget(runtime, root, { by });
112
+ if (!r.ok) return fail(r.error);
113
+ return done({ target: r.saved }, [flags.undo ? `✓ Target put back: ${savedWords(r.saved)}.` : '✓ Target removed. pmos balance target --undo puts it back.']);
114
+ }
115
+ if (!pos.length) {
116
+ if (flags.front !== undefined) return fail('--front goes with a mix, e.g. pmos balance target feature:50,fix:50 --front 8', 2);
117
+ const s = T.targetOf(runtime, root);
118
+ return done({ target: s }, [s ? `Target: ${savedWords(s)}.` : 'No target yet. Save one: pmos balance target feature:50,fix:30,debt:20']);
119
+ }
120
+ const p = T.parseTarget(pos[0]);
121
+ if (!p.ok) return fail(p.error, 2);
122
+ const r = T.setTarget(runtime, root, p.target, { front: flags.front === undefined ? undefined : Number(flags.front), by });
123
+ if (!r.ok) return fail(r.error, 2);
124
+ const g = T.gapOf(T.ranked(root), r.saved.target, r.saved.front);
125
+ return done({ target: r.saved, gap: g.gap }, [`✓ Target saved: ${savedWords(r.saved)}.`, `The top of the roadmap is ${g.gap} points from it. pmos balance gap names the moves. Undo: pmos balance target --undo`]);
126
+ }
127
+ // gap
128
+ if (pos.length) return fail('usage: pmos balance gap', 2);
129
+ const s = T.targetOf(runtime, root);
130
+ if (!s) return done({ target: null, gap: null, moves: [] }, ['No target yet. Save one: pmos balance target feature:50,fix:30,debt:20']);
131
+ T.used(runtime, root, 'gap');
132
+ try { log(`${B.TAG} gap`); } catch { /* no log */ }
133
+ const list = T.ranked(root), g = T.gapOf(list, s.target, s.front), moves = T.movesOf(list, s.target, s.front);
134
+ const out = [`Top ${g.front.length} of the roadmap: ${T.mixWords(g.mix)}. Target: ${T.mixWords(s.target)}.`, `Gap: ${g.gap} point${g.gap === 1 ? '' : 's'}.`];
135
+ if (!g.gap) out.push('On target.');
136
+ else if (!moves.length) out.push('No rank move closes it: no initiative of an under-target kind waits below the top.');
137
+ else for (const m of moves) out.push(`✦ Move ${m.id} (${B.KIND_LABEL[m.kind]}) above ${m.above}: the gap goes to ${m.gapAfter}. ${m.cli} · Undo: ${m.undo}`);
138
+ if (moves.length) out.push('Nothing moved. Make a move with its command.');
139
+ return done({ target: s, mix: g.mix, gap: g.gap, front: g.front.map((x) => x.id), moves, moved: false }, out);
140
+ }
141
+
89
142
  module.exports = { run, COMMANDS, USAGE, bar };
@@ -0,0 +1,228 @@
1
+ 'use strict';
2
+ /* balance-target.js — a target mix for the roadmap, and the rank move that closes the most gap (initiative balance-rebalance, bet A65,
3
+ * job #2051). `pmos balance target|gap` (lib/balance-cli.js) is its CLI; lib/list-balance.js gives the kind of each initiative.
4
+ *
5
+ * parseTarget('feature:50,fix:30,debt:20') → { ok, target: { feature: 50, fix: 30, debt: 20 } } | { ok: false, error }
6
+ * known kinds only (list-balance KINDS), whole percents, adding up to 100.
7
+ * setTarget(runtime, root, target, { front, by }) · clearTarget(runtime, root, { by }) · undoTarget(runtime, root, { by })
8
+ * append-only `<runtime>/balance-targets.jsonl`; one line per write. Undo takes the last set or clear back.
9
+ * targetOf(runtime, root) → { target, front, at, by } | null
10
+ * ranked(root) → [{ id, title, kind }] the live initiatives in Roadmap order (D105), finished ones left out
11
+ * gapOf(list, target, front) → { front: [...], mix: { kind: pct }, gap } gap = half the sum of |actual − target|, in points
12
+ * movesOf(list, target, front, { max }) → the best rank moves, at most `max` (2): an under-target initiative from below the front
13
+ * moved just above an over-target one in it. Each: { id, above, kind, pushes, gapAfter, closes, cli, undo }. Only moves that close gap.
14
+ * count(runtime, { days }) → target and gap uses recorded in the last N days (the health number)
15
+ * needs provider (lib/needs-providers.js): kinds ['balance-gap'] · rowsFor(w, { lead }) · sig(w)
16
+ * one Today row (kind 7) when a target is saved, the front is ROW_GAP points or more off it, and a move closes some of the gap.
17
+ * Its ✦ is the rank move (`pmos initiative after|top`), with Undo.
18
+ * With no target saved: one row (kind 7) that proposes a target drawn from the roadmap (proposeTarget), when the front is
19
+ * ROW_GAP points or more off that proposal and a move would close some of it. Its ✦ saves the proposal (`pmos balance target …`),
20
+ * with Undo (`pmos balance target --undo`). Otherwise no row.
21
+ * proposeTarget(list, front) → { feature: 60, fix: 30, … } | null the mix of the whole live roadmap, the largest kind
22
+ * capped at the balance line (60%) and the rest given to the other kinds it holds, in steps of 10. null when it holds one kind.
23
+ *
24
+ * Reading writes nothing in the repository. Nothing here moves a rank by itself or sends anything: a move is a command the PM presses.
25
+ */
26
+ const fs = require('fs');
27
+ const path = require('path');
28
+ const B = require('./list-balance.js');
29
+
30
+ const FILE = 'balance-targets.jsonl';
31
+ const DEFAULT_FRONT = 6;
32
+ const ROW_GAP = 15;
33
+ const KIND = 'balance-gap';
34
+ const fileOf = (runtime) => path.join(runtime, FILE);
35
+ const log = (s) => { try { process.stderr.write('[balance] ' + s + '\n'); } catch { /* a closed stream */ } };
36
+
37
+ function lines(runtime) {
38
+ let raw = '';
39
+ try { raw = fs.readFileSync(fileOf(runtime), 'utf8'); } catch { return []; }
40
+ const out = [];
41
+ for (const l of raw.split('\n')) { if (!l.trim()) continue; try { out.push(JSON.parse(l)); } catch { /* a torn line */ } }
42
+ return out;
43
+ }
44
+ function append(runtime, line) {
45
+ fs.mkdirSync(runtime, { recursive: true });
46
+ fs.appendFileSync(fileOf(runtime), JSON.stringify({ at: new Date().toISOString(), ...line }) + '\n');
47
+ }
48
+
49
+ function parseTarget(text) {
50
+ const s = String(text == null ? '' : text).trim();
51
+ if (!s) return { ok: false, error: 'say the mix, e.g. feature:50,fix:30,debt:20' };
52
+ const target = {};
53
+ for (const part of s.split(/[,\s]+/).filter(Boolean)) {
54
+ const m = /^([a-z-]+)[:=](\d{1,3})%?$/i.exec(part);
55
+ if (!m) return { ok: false, error: `"${part}" is not kind:percent, e.g. feature:50` };
56
+ const k = m[1].toLowerCase();
57
+ if (!B.KINDS.includes(k)) return { ok: false, error: `${k} is not a kind. Use ${B.KINDS.join(', ')}` };
58
+ if (k in target) return { ok: false, error: `${k} is named twice` };
59
+ target[k] = Number(m[2]);
60
+ }
61
+ const sum = Object.values(target).reduce((a, b) => a + b, 0);
62
+ if (sum !== 100) return { ok: false, error: `the parts add up to ${sum}, not 100` };
63
+ return { ok: true, target };
64
+ }
65
+
66
+ const keyOf = (root) => path.resolve(root);
67
+ /** The saved target of a repository, folded from its lines: each set or clear is a state; undo takes the last one back. */
68
+ function targetOf(runtime, root) {
69
+ const at = keyOf(root), stack = [];
70
+ for (const l of lines(runtime)) {
71
+ if (l.root !== at) continue;
72
+ if (l.ev === 'set') stack.push({ target: l.target, front: l.front || DEFAULT_FRONT, at: l.at, by: l.by });
73
+ else if (l.ev === 'clear') stack.push(null);
74
+ else if (l.ev === 'undo') stack.pop();
75
+ }
76
+ return stack.length ? stack[stack.length - 1] : null;
77
+ }
78
+ function writes(runtime, root) { return lines(runtime).filter((l) => l.root === keyOf(root) && ['set', 'clear'].includes(l.ev)).length - lines(runtime).filter((l) => l.root === keyOf(root) && l.ev === 'undo').length; }
79
+
80
+ function setTarget(runtime, root, target, { front, by } = {}) {
81
+ const f = front == null ? DEFAULT_FRONT : Number(front);
82
+ if (!Number.isInteger(f) || f < 2 || f > 50) return { ok: false, error: '--front is a whole number from 2 to 50' };
83
+ append(runtime, { ev: 'set', root: keyOf(root), target, front: f, by: by || 'agent:unknown' });
84
+ log(`target set ${Object.entries(target).map(([k, v]) => k + ':' + v).join(',')} front ${f}`);
85
+ return { ok: true, saved: targetOf(runtime, root) };
86
+ }
87
+ function clearTarget(runtime, root, { by } = {}) {
88
+ if (!targetOf(runtime, root)) return { ok: false, error: 'no target is saved for this repository' };
89
+ append(runtime, { ev: 'clear', root: keyOf(root), by: by || 'agent:unknown' });
90
+ log('target clear');
91
+ return { ok: true, saved: null };
92
+ }
93
+ function undoTarget(runtime, root, { by } = {}) {
94
+ if (writes(runtime, root) <= 0) return { ok: false, error: 'no target change to take back' };
95
+ append(runtime, { ev: 'undo', root: keyOf(root), by: by || 'agent:unknown' });
96
+ log('target undo');
97
+ return { ok: true, saved: targetOf(runtime, root) };
98
+ }
99
+ /** One use of `gap` (target writes count by themselves). */
100
+ function used(runtime, root, what) { try { append(runtime, { ev: 'use', root: keyOf(root), what }); } catch { /* a read-only runtime */ } }
101
+ function count(runtime, { days = 7, now = Date.now() } = {}) {
102
+ const since = now - days * 86400000;
103
+ return lines(runtime).filter((l) => ['set', 'clear', 'undo', 'use'].includes(l.ev) && Date.parse(l.at) >= since).length;
104
+ }
105
+
106
+ /** The live initiatives of a repository in Roadmap order (one ranked list, D105). Finished ones are left out. */
107
+ function ranked(root) {
108
+ const rowsLib = require('./initiative-rows.js'), P = require('./placements.js'), PR = require('./plan-rules.js');
109
+ const d = rowsLib.deriveSync(root);
110
+ if (!d.ok) return [];
111
+ const rows = new Map(d.rows.map((r) => [r.id, r]));
112
+ const placed = P.readPlacements(root, { now: Date.now(), rules: PR.readRules(root), records: d.rows });
113
+ return placed.ranked.map((id) => rows.get(id)).filter((r) => r && !r.accepted && !r.stopped)
114
+ .map((r) => ({ id: r.id, title: r.title || r.id, kind: B.kindOf(r) }));
115
+ }
116
+
117
+ function gapOf(list, target, front = DEFAULT_FRONT) {
118
+ const f = (list || []).slice(0, front), n = f.length;
119
+ const mix = Object.fromEntries(B.KINDS.map((k) => [k, n ? Math.round((f.filter((x) => x.kind === k).length / n) * 100) : 0]));
120
+ const exact = (k) => (n ? (f.filter((x) => x.kind === k).length / n) * 100 : 0);
121
+ const gap = n ? Math.round(B.KINDS.reduce((s, k) => s + Math.abs(exact(k) - (target[k] || 0)), 0) / 2) : 0;
122
+ return { front: f, mix, gap };
123
+ }
124
+
125
+ function movesOf(list, target, front = DEFAULT_FRONT, { max = 2 } = {}) {
126
+ const L = list || [];
127
+ if (L.length <= front) return [];
128
+ const now = gapOf(L, target, front), n = now.front.length;
129
+ const share = (k) => (now.front.filter((x) => x.kind === k).length / n) * 100;
130
+ const under = (k) => share(k) < (target[k] || 0), over = (k) => share(k) > (target[k] || 0);
131
+ const best = new Map();
132
+ for (let ui = front; ui < L.length; ui++) {
133
+ const u = L[ui];
134
+ if (!under(u.kind)) continue;
135
+ for (let oi = 0; oi < front; oi++) {
136
+ const o = L[oi];
137
+ if (!over(o.kind) || o.kind === u.kind) continue;
138
+ const moved = L.filter((x) => x.id !== u.id);
139
+ moved.splice(oi, 0, u);
140
+ const after = gapOf(moved, target, front).gap;
141
+ if (after >= now.gap) continue;
142
+ const m = { id: u.id, title: u.title, kind: u.kind, above: o.id, pushes: L[front - 1].id, gapAfter: after, closes: now.gap - after,
143
+ cli: oi === 0 ? `pmos initiative top ${u.id}` : `pmos initiative after ${u.id} ${L[oi - 1].id}`,
144
+ undo: `pmos initiative after ${u.id} ${L[ui - 1].id}` };
145
+ const was = best.get(u.id);
146
+ // the move that closes the most; on a tie, the one that lifts it least far (the lowest over-target one in the front)
147
+ if (!was || m.closes > was.closes || (m.closes === was.closes && oi > L.findIndex((x) => x.id === was.above))) best.set(u.id, m);
148
+ }
149
+ }
150
+ return [...best.values()].sort((a, b) => b.closes - a.closes || L.findIndex((x) => x.id === a.id) - L.findIndex((x) => x.id === b.id)).slice(0, max);
151
+ }
152
+
153
+ const label = (k) => B.KIND_LABEL[k] || k;
154
+ const mixWords = (o) => B.KINDS.filter((k) => o[k]).map((k) => `${label(k)} ${o[k]}%`).join(' · ') || 'nothing';
155
+
156
+ /* ── the needs provider: an off-target roadmap is a Today row by itself ─────────────────────────────────────────────── */
157
+ /** The Today row for workspace `ws` (pure): [] unless a target is saved, the gap is ROW_GAP or more and a move closes some of it. */
158
+ function rowsOf(ws, saved, list) {
159
+ if (!saved || !saved.target) return [];
160
+ const g = gapOf(list, saved.target, saved.front);
161
+ if (g.gap < ROW_GAP) return [];
162
+ const m = movesOf(list, saved.target, saved.front, { max: 1 })[0];
163
+ if (!m) return [];
164
+ const cause = `The top ${g.front.length} of your roadmap is ${g.gap} points off your target mix (${mixWords(g.mix)}; target ${mixWords(saved.target)}). Moving ${m.id} (${label(m.kind)}) above ${m.above} closes ${m.closes}.`;
165
+ return [{
166
+ run_id: `${KIND}:${ws}:${m.id}:${m.above}`, kind: KIND, initiative_id: m.id, question: cause, doc: null, ws,
167
+ today: { kind: 7, source: 'balance-target', cause, evidence: `pmos balance gap · target saved ${String(saved.at || '').slice(0, 10)}`,
168
+ act: { label: `Move ${m.id} up`, cli: m.cli, undo: m.undo } },
169
+ }];
170
+ }
171
+ /** A target drawn from the roadmap: its whole mix, the largest kind capped at the balance line, in steps of 10. Pure. */
172
+ function proposeTarget(list, front = DEFAULT_FRONT) {
173
+ const L = list || [];
174
+ if (L.length <= front) return null;
175
+ const n = Object.fromEntries(B.KINDS.map((k) => [k, L.filter((x) => x.kind === k).length]));
176
+ const present = B.KINDS.filter((k) => n[k] > 0);
177
+ if (present.length < 2) return null;
178
+ const share = Object.fromEntries(present.map((k) => [k, (n[k] / L.length) * 100]));
179
+ const top = present.reduce((a, b) => (share[b] > share[a] ? b : a));
180
+ if (share[top] > B.DEFAULT_MAX) {
181
+ const rest = 100 - share[top], spare = share[top] - B.DEFAULT_MAX;
182
+ share[top] = B.DEFAULT_MAX;
183
+ for (const k of present) if (k !== top) share[k] += spare * (share[k] / rest);
184
+ }
185
+ // whole steps of 10 that add up to 100: round down, then give the leftover steps to the largest remainders
186
+ const t = Object.fromEntries(present.map((k) => [k, Math.floor(share[k] / 10) * 10]));
187
+ let left = 100 - Object.values(t).reduce((a, b) => a + b, 0);
188
+ for (const k of [...present].sort((a, b) => (share[b] % 10) - (share[a] % 10) || B.KINDS.indexOf(a) - B.KINDS.indexOf(b))) { if (left <= 0) break; t[k] += 10; left -= 10; }
189
+ for (const k of present) if (!t[k]) delete t[k];
190
+ return Object.keys(t).length >= 2 ? t : null;
191
+ }
192
+ const targetText = (t) => B.KINDS.filter((k) => t[k]).map((k) => `${k}:${t[k]}`).join(',');
193
+ /** The proposal row (pure): [] unless the front is ROW_GAP or more off the proposed target and a move would close some of it. */
194
+ function proposalRowsOf(ws, list, front = DEFAULT_FRONT) {
195
+ const t = proposeTarget(list, front);
196
+ if (!t) return [];
197
+ const g = gapOf(list, t, front);
198
+ if (g.gap < ROW_GAP || !movesOf(list, t, front, { max: 1 }).length) return [];
199
+ const cause = `The top ${g.front.length} of your roadmap is ${mixWords(g.mix)}. Save a target mix of ${mixWords(t)}, drawn from your whole roadmap, and PMOS names the rank move that closes the ${g.gap}-point gap.`;
200
+ return [{
201
+ run_id: `${KIND}:${ws}:propose:${targetText(t)}`, kind: KIND, initiative_id: null, question: cause, doc: null, ws,
202
+ today: { kind: 7, source: 'balance-target', cause, evidence: `pmos balance show · ${list.length} live initiatives`,
203
+ act: { label: 'Save this target', cli: `pmos balance target ${targetText(t)}`, undo: 'pmos balance target --undo' } },
204
+ }];
205
+ }
206
+ const runtimeNow = () => require('./state-root.js').defaultRoot({ env: process.env });
207
+ function rowsFor(w, { lead } = {}) {
208
+ if (!lead || !w || !w.root) return [];
209
+ const saved = targetOf(runtimeNow(), w.root);
210
+ return saved ? rowsOf(w.id, saved, ranked(w.root)) : proposalRowsOf(w.id, ranked(w.root));
211
+ }
212
+ function sig(w) {
213
+ let t = '-';
214
+ try { const st = fs.statSync(fileOf(runtimeNow())); t = st.size + ':' + st.mtimeMs; } catch { /* no target yet */ }
215
+ let p = '-';
216
+ try { p = String(require('./plan-ledgers.js').ledgerSig(w.root, 'placements')); } catch { /* no ledger */ }
217
+ return t + '|' + p + '|' + new Date().toISOString().slice(0, 10);
218
+ }
219
+
220
+ module.exports = { FILE, DEFAULT_FRONT, ROW_GAP, KIND, kinds: [KIND], fileOf, parseTarget, targetOf, setTarget, clearTarget, undoTarget, used, count,
221
+ ranked, gapOf, movesOf, mixWords, proposeTarget, proposalRowsOf, rowsOf, rowsFor, sig };
222
+
223
+ if (require.main === module) {
224
+ const a = process.argv.slice(2);
225
+ if (a[0] !== 'count') { console.log('usage: node lib/balance-target.js count [--days N]'); process.exit(2); }
226
+ const i = a.indexOf('--days'), days = i >= 0 ? Math.max(1, Number(a[i + 1]) || 7) : 7;
227
+ console.log(String(count(runtimeNow(), { days })));
228
+ }
@@ -69,7 +69,7 @@
69
69
  {"id": "prototype", "audience": "user", "status": "ga", "group": "Before you ship", "name": "Simulated users try the prototype", "say": "Where simulated users, one per persona, got stuck on a prototype, and the personas that walk it.", "cmd": "/prototype", "verb": "prototype", "hint": "findings <initiative>"},
70
70
  {"id": "goals", "audience": "user", "status": "ga", "group": "Your product", "name": "Starter goals", "say": "Up to three goals drafted from your own product, each with its source; keep one and it becomes a goal.", "cmd": "/goals", "verb": "goals"},
71
71
  {"id": "approver", "audience": "user", "status": "ga", "group": "Before you ship", "name": "What an approver asks", "say": "What each approver asked or objected to before, ahead of the next sign-off.", "cmd": "/approver", "verb": "approver", "hint": "<name>"},
72
- {"id": "balance", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The mix of a list", "say": "Feature, fix, debt or discovery in one line, with a note when one kind is over your line.", "cmd": "/balance", "verb": "balance"},
72
+ {"id": "balance", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The mix of a list", "say": "Feature, fix, debt or discovery in one line, a target mix for the roadmap, and the rank move that closes the gap.", "cmd": "/balance", "verb": "balance"},
73
73
  {"id": "layouts", "audience": "user", "status": "ga", "group": "Before you ship", "name": "Three layouts for a new screen", "say": "Three layouts of a new screen side by side, the one that fits your picks, and the one you keep to build.", "cmd": "/layouts", "verb": "layouts"},
74
74
  {"id": "declined", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Asks you declined", "say": "Asks closed without being done, each with a kind reply draft PMOS never sends.", "cmd": "/declined", "verb": "declined"},
75
75
  {"id": "sprint", "audience": "user", "status": "ga", "group": "Catch up", "name": "Sprint retro", "say": "A closed sprint's retro from its close numbers, and its one tracked change.", "cmd": "/sprint", "verb": "sprint"},
@@ -45,6 +45,7 @@ const PROVIDERS = Object.freeze([
45
45
  'setup-station', // setup-station: a product that has not passed Setup (tracker read, agreed goal, owner), with the next ✦ (kind 7)
46
46
  'critical-needs', // critical-moved (bet A103): a task on an initiative's critical path moved its start or due date, with go-live (kind 7)
47
47
  'change-requests', // change-requests (bet A105): a stakeholder's open change request, with what it would break; ✦ approves with Undo (kind 1)
48
+ 'balance-target', // balance-rebalance (bet A65): the top of the roadmap is 15 points or more off the target mix, with the one ✦ rank move (kind 7)
48
49
  ]);
49
50
  /** Kinds that already mean something in the needs queue. A provider may not reuse one. */
50
51
  const RESERVED_KINDS = Object.freeze(['question', 'accept', 'outcome', 'keep', 'evidence', 'plan-flag', 'provider-error']);
@@ -204,7 +204,7 @@ const VERBS = Object.freeze({
204
204
  help: 'pmos approver list|show|brief — what each approver asked or objected to before, from the sign-offs and the decision journal, before the next sign-off (pmos approver help)' }),
205
205
  // Not a pm-os-absorb verb (run: null): initiative balance-meter (bet A448) added it through the same table.
206
206
  balance: Object.freeze({ module: 'balance-cli.js', run: null, guide: 'cli.md',
207
- help: 'pmos balance show — the mix of a list in one line: feature, fix, debt, discovery, or with and without an expected outcome, with a note when one kind is over your line (pmos balance help)' }),
207
+ help: 'pmos balance show|target|gap — the mix of a list in one line, a target mix for the roadmap, and the rank move that closes the gap (pmos balance help)' }),
208
208
  // Not a pm-os-absorb verb (run: null): initiative product-principles-draft (bet A352) added it through the same table.
209
209
  principles: Object.freeze({ module: 'principles-cli.js', run: null, guide: 'cli.md',
210
210
  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)' }),
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.848.0",
3
+ "version": "0.849.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.848.0",
9
+ "version": "0.849.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.848.0",
3
+ "version": "0.849.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "balance-rebalance (bet A65, job #2051): a target mix for the roadmap and the rank move that closes the gap. `pmos balance target|gap` on a temporary repository, the needs provider, and the must-nots (no rank moves by itself, nothing sent). No browser, no model.",
3
+ "modules": [
4
+ "balance-rebalance.test.js"
5
+ ],
6
+ "seconds": {
7
+ "balance-rebalance.test.js": 3
8
+ }
9
+ }