create-pmos 0.818.0 → 0.819.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.818.0",
3
+ "version": "0.819.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": {
@@ -34,8 +34,8 @@
34
34
  ],
35
35
  "pmosChanges": [
36
36
  {
37
- "v": "0.818.0",
38
- "at": "2026-11-25T08:22:03.053Z",
37
+ "v": "0.819.0",
38
+ "at": "2026-11-25T08:28:20.856Z",
39
39
  "f": 4,
40
40
  "prs": [
41
41
  {
@@ -69,6 +69,38 @@
69
69
  "see": "The copy opens in the Viewer, says it is a translation for Dita, and every number and id matches the original.",
70
70
  "open": "/today.html"
71
71
  }
72
+ },
73
+ {
74
+ "n": 1868,
75
+ "t": "The factory numbers snapshot per station (job #1862)",
76
+ "s": "The factory numbers snapshot per station (job #1862)",
77
+ "k": "new",
78
+ "h": "The factory numbers snapshot per station (job #1862)",
79
+ "try": {
80
+ "steps": [
81
+ "On Today, open Ask PMOS and ask: what did each factory station make this week?",
82
+ "Open Work and compare the initiatives it names as waiting with their rows."
83
+ ],
84
+ "see": "PMOS answers per station (Intake, Shape, Plan, Track, Evaluate, Check, You) with what waits, what it made this week, its PMOS time and what you undid; tokens and money say not recorded yet.",
85
+ "open": "/today.html"
86
+ },
87
+ "i": "factory-floor-snapshot"
88
+ },
89
+ {
90
+ "n": 1875,
91
+ "t": "I have N minutes — one pick in Ctrl K, the chat and pmos pick (job #1873)",
92
+ "s": "I have N minutes — one pick in Ctrl K, the chat and pmos pick (job #1873)",
93
+ "k": "new",
94
+ "i": "time-box-pick-chat",
95
+ "try": {
96
+ "steps": [
97
+ "On Today, press Ctrl K and type: I have 30 minutes",
98
+ "Read the first row, then press it",
99
+ "On Today, ask the chat: I have 15 minutes, what should I do?"
100
+ ],
101
+ "see": "The first row names one thing from Your move or Waiting on others that fits in the time, about how long it takes and how many others it unblocks. Pressing it opens that item. The chat gives the same…",
102
+ "open": "/today.html"
103
+ }
72
104
  }
73
105
  ]
74
106
  },
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@33bacf175
1
+ kernel-source: pmos@106b1695f
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-25T08:21:59Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T08:28:18Z"}
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-25T08:21:59Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T08:28:18Z"}
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-25T08:21:59Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T08:28:18Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,7 +1,7 @@
1
1
  [
2
2
  {
3
- "v": "0.818.0",
4
- "at": "2026-11-25T08:22:03.053Z",
3
+ "v": "0.819.0",
4
+ "at": "2026-11-25T08:28:20.856Z",
5
5
  "f": 4,
6
6
  "prs": [
7
7
  {
@@ -35,6 +35,38 @@
35
35
  "see": "The copy opens in the Viewer, says it is a translation for Dita, and every number and id matches the original.",
36
36
  "open": "/today.html"
37
37
  }
38
+ },
39
+ {
40
+ "n": 1868,
41
+ "t": "The factory numbers snapshot per station (job #1862)",
42
+ "s": "The factory numbers snapshot per station (job #1862)",
43
+ "k": "new",
44
+ "h": "The factory numbers snapshot per station (job #1862)",
45
+ "try": {
46
+ "steps": [
47
+ "On Today, open Ask PMOS and ask: what did each factory station make this week?",
48
+ "Open Work and compare the initiatives it names as waiting with their rows."
49
+ ],
50
+ "see": "PMOS answers per station (Intake, Shape, Plan, Track, Evaluate, Check, You) with what waits, what it made this week, its PMOS time and what you undid; tokens and money say not recorded yet.",
51
+ "open": "/today.html"
52
+ },
53
+ "i": "factory-floor-snapshot"
54
+ },
55
+ {
56
+ "n": 1875,
57
+ "t": "I have N minutes — one pick in Ctrl K, the chat and pmos pick (job #1873)",
58
+ "s": "I have N minutes — one pick in Ctrl K, the chat and pmos pick (job #1873)",
59
+ "k": "new",
60
+ "i": "time-box-pick-chat",
61
+ "try": {
62
+ "steps": [
63
+ "On Today, press Ctrl K and type: I have 30 minutes",
64
+ "Read the first row, then press it",
65
+ "On Today, ask the chat: I have 15 minutes, what should I do?"
66
+ ],
67
+ "see": "The first row names one thing from Your move or Waiting on others that fits in the time, about how long it takes and how many others it unblocks. Pressing it opens that item. The chat gives the same…",
68
+ "open": "/today.html"
69
+ }
38
70
  }
39
71
  ]
40
72
  },
@@ -158,6 +158,18 @@ The session commands must name who read or wrote. In a workspace session that is
158
158
 
159
159
  Nothing here writes a record, sends anything or calls a model.
160
160
 
161
+ ### pmos pick
162
+
163
+ `pmos pick --minutes 30` picks the one ask from Your move and Waiting on others that fits in 30 minutes and unblocks the most others. It prints one line: what to do, about how long it takes, and why. When nothing fits, it names the shortest ask and its time. The chat can run it when you tell it how long you have.
164
+
165
+ ```
166
+ pmos pick --minutes 30 # the repository you are in
167
+ pmos pick --minutes 15 --json # the pick as JSON
168
+ pmos pick --minutes 60 --root <dir> # read a repository folder without a server
169
+ ```
170
+
171
+ It calls no model, sends nothing and changes nothing. It exits with 0 when it read the asks, 1 when it could not read them, and 2 when `--minutes` is missing.
172
+
161
173
  ## PMOS's proposals and checks
162
174
 
163
175
  ### pmos propose: the one ✦ on each initiative
@@ -310,6 +310,8 @@ When the words you type in Search point clearly to one thing, the first row is t
310
310
 
311
311
  When you type a question, such as "why do some customers still use a spreadsheet instead of the app?", and no one sentence holds all your words, the first row says "Finding an answer in your work…". After a few seconds it shows a short answer, written only from passages of your own files, and the names of the files it used. Press Enter on the answer to open the first of them. To go deeper, pick "Ask PMOS" in the next row. When your files do not answer the question, the row goes away and the matches stay.
312
312
 
313
+ When you say how long you have, such as "I have 30 minutes" or "half an hour", the first row is one pick: the ask from Your move or Waiting on others that fits in that time and unblocks the most others, about how long it takes, and why. Press Enter on it to open its initiative, or Today when it has none. PMOS counts a fixed time for each kind of ask (2 minutes to name an owner or send a nudge, 5 for a session that asks, 10 for a gate, 15 for work to check, 30 for a cycle review). When nothing fits, the row names the shortest ask and its time. The chat can give the same pick when you tell it "I have 30 minutes". PMOS calls no model to pick, and it sends and changes nothing.
314
+
313
315
  ## Ask about what you point at
314
316
 
315
317
  Right-click any part of a page to ask PMOS about it. On a phone, press and hold it. A small Ask card opens next to it.
@@ -143,7 +143,7 @@ function create(deps) {
143
143
  session = deps.spawn({
144
144
  name: `Driver · ${kind} ${group.target.id}`, ws: w.id, origin: `drive:${kind}:${group.target.id}`, initialInput: prompt + '\r',
145
145
  initiative: kind === 'initiative' ? group.target.id : undefined,
146
- onDone: (r) => endRun(file, runId, group.target, r, group.wakes),
146
+ onDone: (r) => endRun(file, runId, group.target, r, group.wakes, w),
147
147
  });
148
148
  } catch (e) { warn('driver run', e); }
149
149
  D.append(file, { ev: 'run-start', run: runId, target: group.target, board, wakes: group.wakes, session: session ? session.id : null }, { now });
@@ -166,7 +166,7 @@ function create(deps) {
166
166
  // The task ledger is bookkeeping for the restart: a failed write is reported and never stops or fails a run.
167
167
  function taskLedger(fn) { try { fn(); } catch (e) { warn('orchestrator task ledger', e); } }
168
168
 
169
- function endRun(file, runId, target, r, wakeKeys) {
169
+ function endRun(file, runId, target, r, wakeKeys, w) {
170
170
  active.delete(runId);
171
171
  const res = (r && r.result) || {};
172
172
  const ok = !!(r && !r.timedOut && !r.stopped && r.code === 0 && res.ok && !res.isError);
@@ -178,6 +178,8 @@ function create(deps) {
178
178
  agent_run: agentRun(runId, target, ok) });
179
179
  } catch (e) { warn('driver run end', e); }
180
180
  taskLedger(() => tasksEnd(path.dirname(file), wakeKeys, { ok, reason }));
181
+ // factory-floor-snapshot: the factory's numbers are saved after each run, so the Factory page reads one file (lib/factory-floor.js)
182
+ if (w && w.root) { try { require('./factory-floor.js').save(w.root, { stateDir: path.dirname(file), runtimeDir: deps.runtimeDir || null, ws: w.id, name: w.name || w.id }); } catch (e) { warn('[factory-floor] snapshot', e); } }
181
183
  }
182
184
 
183
185
  /* `sweepNow` (Refresh now, data-refresh-settings R8) runs the unblock sweep at once, inside or outside the window. */
@@ -1,5 +1,10 @@
1
1
  'use strict';
2
2
  /* factory-cli.js — `pmos factory`: one view of everything PMOS changed by itself (initiative one-change-record-no-source-no-auto).
3
+ *
4
+ * pmos factory [--json] [--root <dir>]
5
+ * The factory floor (initiative factory-floor-snapshot): per station (Intake, Shape, Plan, Track, Evaluate, Check, You) what waits now,
6
+ * what it made in the last 7 days, PMOS minutes and how many changes were undone (lib/factory-floor.js). It folds the ledgers fresh;
7
+ * the Factory page reads the copy the Driver saves after each run. --json prints the snapshot.
3
8
  *
4
9
  * pmos factory today [--days N] [--json] [--unsourced] [--root <dir>]
5
10
  * Per line (product, project, SDLC) and station: changes, applied by PMOS, kept, undone, ignored, applied with no source, and
@@ -13,6 +18,7 @@ const CR = require('./change-record.js');
13
18
 
14
19
  const COMMANDS = { factory: ['today'] };
15
20
  const USAGE = [
21
+ 'usage: pmos factory [--json] — per station: what waits, what it made in 7 days, PMOS minutes and what was undone',
16
22
  'usage: pmos factory today [--days N] [--json] [--unsourced] — everything PMOS changed by itself, in one record',
17
23
  ' pmos factory today per line and station: changes, applied, kept, undone, ignored, with no source, runs (today)',
18
24
  ' pmos factory today --days 7 the same over the last 7 days',
@@ -27,7 +33,8 @@ const num = (v, n = 6) => String(v).padStart(n);
27
33
  function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), env = process.env, now = Date.now(), runtimeDir } = {}) {
28
34
  const args = argv[0] === 'factory' ? argv.slice(1) : argv.slice();
29
35
  const verb = args[0];
30
- if (!verb || ['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return verb ? 0 : 2; }
36
+ if (['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return 0; }
37
+ if (!verb || verb.startsWith('--')) return floor(args, { say, cwd, env, now, runtimeDir });
31
38
  if (!COMMANDS.factory.includes(verb)) { say(`unknown factory command "${verb}" — one of ${COMMANDS.factory.join(', ')}`); return 2; }
32
39
  const d = flag(args, 'days');
33
40
  const days = d === undefined ? 1 : Number(d);
@@ -55,4 +62,21 @@ function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), env = pro
55
62
  return 0;
56
63
  }
57
64
 
65
+ /** `pmos factory [--json]`: the factory floor of this repository, folded now (lib/factory-floor.js). */
66
+ function floor(args, { say, cwd, env, now, runtimeDir }) {
67
+ const FF = require('./factory-floor.js');
68
+ const root = typeof flag(args, 'root') === 'string' ? path.resolve(cwd, flag(args, 'root')) : repoRoot(cwd);
69
+ let rt = runtimeDir;
70
+ if (rt === undefined) { try { rt = require('./state-root.js').defaultRoot({ env }); } catch { rt = null; } }
71
+ const S = FF.build(root, { runtimeDir: rt, now });
72
+ if (!S) { say('✗ this repository has no PMOS state folder (pmos/state, state or .pmos)'); return 1; }
73
+ if (flag(args, 'json')) { say(JSON.stringify({ ok: true, ...S })); return 0; }
74
+ say(`The factory, last ${S.days} days: ${S.runs} Driver ${S.runs === 1 ? 'run' : 'runs'}`);
75
+ say(' ' + pad('Station', 10) + ['waiting', 'made', 'undone', 'minutes'].map((h) => h.padStart(9)).join(''));
76
+ for (const s of S.stations) say(' ' + pad(s.name, 10) + [s.waiting, s.made, s.undone, s.minutes].map((v) => num(v, 9)).join(''));
77
+ if (S.unplaced.made || S.unplaced.minutes) say(` not placed: ${S.unplaced.made} made, ${S.unplaced.minutes} minutes`);
78
+ say(` tokens and money: ${FF.NOT_RECORDED}`);
79
+ return 0;
80
+ }
81
+
58
82
  module.exports = { run, COMMANDS, USAGE };
@@ -0,0 +1,245 @@
1
+ 'use strict';
2
+ /* factory-floor.js — the factory's numbers per product and per station, saved ahead so the Factory page opens in 200 ms or less
3
+ * (initiative factory-floor-snapshot, slice B of the Factory page; brief agreed by the PM 2026-11-25).
4
+ *
5
+ * THE MODEL (keep the two apart): the work is what gets made (goals, programs, initiatives, their breakdown); the factory is who makes it.
6
+ * PMOS's stations, in flow order: Intake (asks become initiatives), Shape (problem, evidence, assumptions, PRD), Plan (milestones, tasks,
7
+ * owners, dates), Track (tracker, follow-ups, slips, moves), Evaluate (outcome reading, lessons), Check (PMOS checking its own work) and
8
+ * You (only what no record can decide).
9
+ *
10
+ * STATIONS · WHAT_STATION the stations and the Driver proposal kinds each one makes
11
+ * stationOfJob(job) PURE → a station key | null a change-record job (`driver:<what>`, `propose:<group>`, `ai:<role>`, `outbox`)
12
+ * stationOfCode(code) PURE → a station key | null a Driver blocker code: the station the item waits at
13
+ * compute(input, { now, days, ws, name }) PURE → the snapshot (below). input: read(root, …)
14
+ * read(root, { runtimeDir }) → the ledgers of one repository; no write
15
+ * build(root, { runtimeDir, now, ws, name }) → compute(read(root)) for one repository
16
+ * fileOf(stateDir) → <state folder>/factory-floor.json
17
+ * save(root, { … }) → { ok, file, snapshot } | { ok: false, error } THE ONLY WRITER of the snapshot
18
+ * load(root) → the saved snapshot | null reads one file, folds nothing
19
+ * ageMinutes(root, now) → whole minutes since the snapshot was saved, or -1 (the health number)
20
+ *
21
+ * THE SNAPSHOT { v: 1, at, ws, name, days, from, stations: [{ key, name, waiting, made, undone, minutes, items }], unplaced: { made, minutes },
22
+ * runs, tokens: null, money: null, usage: 'not recorded yet' }
23
+ * waiting what waits at the station now. Intake to Evaluate: the initiatives and Work tasks whose agent blocker of the latest sweep day
24
+ * belongs to it (one per target). Check: the Driver drafts of ended runs the Checker has not graded yet. You: the open sign-offs
25
+ * and the Driver drafts that have waited on the PM for a day (pm-open).
26
+ * made what the station made in the last `days` days, whatever happened to it next (one row per change, lib/change-record.js, so a change
27
+ * PMOS applied by itself is counted once), plus its background runs (tracker reads, outcome runs, lessons, milestone reviews).
28
+ * Check: the Checker's verdicts. You: sign-offs answered and Driver drafts the PM decided.
29
+ * undone of what it made, how many were undone.
30
+ * minutes PMOS minutes of the Driver's runs that ended in the window (run-start to run-end), split evenly over the stations of what each
31
+ * run filed; a run that filed nothing counts for the station of the blocker that woke it; else it is unplaced.
32
+ * items up to MAX_ITEMS waiting items: { kind, id, title, code, text }, what each one waits on.
33
+ * tokens and money stay null ("not recorded yet") until each run records its usage (a later slice). An honest gap, never a guess.
34
+ *
35
+ * Every log line carries [factory-floor]. Nothing here sends anything, and the factory graph never writes it (D65): the server writes it
36
+ * after a Driver run. */
37
+ const fs = require('fs');
38
+ const path = require('path');
39
+
40
+ const FILE = 'factory-floor.json';
41
+ const DAY = 86400000;
42
+ const DAYS = 7;
43
+ const MAX_ITEMS = 50;
44
+ const LOG = '[factory-floor]';
45
+ const NOT_RECORDED = 'not recorded yet';
46
+ const STATIONS = Object.freeze([
47
+ { key: 'intake', name: 'Intake' }, { key: 'shape', name: 'Shape' }, { key: 'plan', name: 'Plan' }, { key: 'track', name: 'Track' },
48
+ { key: 'evaluate', name: 'Evaluate' }, { key: 'check', name: 'Check' }, { key: 'you', name: 'You' },
49
+ ]);
50
+ // The brief's map of Driver proposal kinds. `note` is a remark, not a made thing: an initiative note is Shape's, a Work task note is Track's.
51
+ const WHAT_STATION = Object.freeze({
52
+ overlap: 'intake',
53
+ problem: 'shape', evidence: 'shape', assumption: 'shape', doc: 'shape', artefact: 'shape',
54
+ sizing: 'plan', stakeholders: 'plan', 'next-step': 'plan',
55
+ 'follow-up': 'track', move: 'track',
56
+ });
57
+ // The ✦ groups (lib/proposals.js GROUPS) and the rest of the change record.
58
+ const GROUP_STATION = Object.freeze({ found: 'intake', description: 'shape', dates: 'plan', status: 'track', names: 'track', links: 'track', tidy: 'track',
59
+ default: 'track', ask: 'track', outcome: 'evaluate' });
60
+ // The background runs that make something of their own (lib/bg-queue.js JOBS): tracker reads, outcome runs, lessons, milestone reviews.
61
+ const RUN_STATION = Object.freeze({ refresh: 'track', outcomes: 'evaluate', impact: 'evaluate', 'metric-reads': 'evaluate', improve: 'evaluate', milestones: 'plan' });
62
+ // The Driver's blocker codes (lib/driver.js detect, lib/line-driver.js blockerOf): the station each waiting item stands at.
63
+ const CODE_STATION = Object.freeze({
64
+ 'no-anchor': 'intake',
65
+ 'no-problem': 'shape', 'no-evidence': 'shape', 'no-prd': 'shape', 'no-done-criteria': 'shape', 'doc-due': 'shape', 'doc-stale': 'shape',
66
+ 'work-no-next-step': 'plan',
67
+ 'no-ticket-movement': 'track', 'ticket-blocked': 'track', stalled: 'track', 'work-overdue': 'track', 'work-waiting': 'track', 'work-untouched': 'track',
68
+ 'exit-missing': 'track',
69
+ 'check-by-passed': 'evaluate', 'kill-tripped': 'evaluate',
70
+ });
71
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
72
+ const ms = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : null; };
73
+ const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
74
+
75
+ function stationOfJob(job, { kind } = {}) {
76
+ const [k, name = ''] = String(job || '').split(':');
77
+ if (k === 'driver') return name === 'note' ? (kind === 'work' ? 'track' : 'shape') : WHAT_STATION[name] || null;
78
+ if (k === 'propose') return GROUP_STATION[name] || null;
79
+ if (k === 'ai') return name === 'improve' ? 'evaluate' : null;
80
+ if (k === 'outbox') return 'track';
81
+ return null;
82
+ }
83
+ const stationOfCode = (code) => CODE_STATION[String(code || '')] || null;
84
+
85
+ /* ── the fold ── */
86
+ function compute(input = {}, { now = Date.now(), days = DAYS, ws = null, name = null } = {}) {
87
+ const D = require('./driver.js');
88
+ const CR = require('./change-record.js');
89
+ const from = now - days * DAY;
90
+ const inWin = (at) => { const t = ms(at); return t != null && t >= from && t <= now + 60000; };
91
+ const st = new Map(STATIONS.map((s) => [s.key, { key: s.key, name: s.name, waiting: 0, made: 0, undone: 0, minutes: 0, items: [], _targets: new Set() }]));
92
+ const unplaced = { made: 0, minutes: 0 };
93
+ const wait = (key, item) => {
94
+ const s = st.get(key);
95
+ const tk = `${item.kind}:${item.id}`;
96
+ if (s._targets.has(tk)) return;
97
+ s._targets.add(tk); s.waiting++;
98
+ if (s.items.length < MAX_ITEMS) s.items.push(item);
99
+ };
100
+ const driverLines = Array.isArray(input.driver) ? input.driver : [];
101
+ const state = D.fold(driverLines);
102
+
103
+ // MADE and UNDONE: one row per change (lib/change-record.js), placed by its job
104
+ const { rows } = CR.rows(input, { now });
105
+ for (const r of rows) {
106
+ if (!inWin(r.at)) continue;
107
+ const dp = r.ref ? state.proposals.get(r.ref) : null;
108
+ const key = stationOfJob(r.job, { kind: dp ? dp.target.kind : 'initiative' });
109
+ if (!key) { unplaced.made++; continue; }
110
+ const s = st.get(key);
111
+ s.made++;
112
+ if (r.state === 'undone') s.undone++;
113
+ }
114
+ for (const l of Array.isArray(input.bgQueue) ? input.bgQueue : []) {
115
+ if (!isObj(l) || l.kind !== 'done' || !inWin(l.at) || (ws && l.ws && l.ws !== ws)) continue;
116
+ const key = RUN_STATION[String(l.job || '')];
117
+ if (key) st.get(key).made++;
118
+ }
119
+
120
+ // WAITING at a working station: the agent blockers of the latest sweep day, one per target
121
+ let lastDay = null;
122
+ for (const b of state.blockers) if (b.owner === 'agent' && (!lastDay || b.day > lastDay)) lastDay = b.day;
123
+ for (const b of state.blockers) {
124
+ if (b.owner !== 'agent' || b.day !== lastDay || !b.target) continue;
125
+ const key = stationOfCode(b.code);
126
+ if (key) wait(key, { kind: b.target.kind, id: b.target.id, title: one(b.title || b.target.id, 120), code: b.code, text: one(b.text, 200) });
127
+ }
128
+
129
+ // CHECK: the Checker's verdicts made; the drafts of ended runs it has not graded yet wait
130
+ const checks = Array.isArray(input.checker) ? input.checker : [];
131
+ const checked = new Map();
132
+ for (const c of checks) {
133
+ if (!isObj(c) || typeof c.proposal !== 'string' || !['pass', 'flag', 'none'].includes(c.verdict)) continue;
134
+ if (!checked.has(c.proposal)) checked.set(c.proposal, c);
135
+ if (c.verdict !== 'none' && inWin(c.at)) st.get('check').made++;
136
+ }
137
+ for (const d of require('./orchestrator-checker.js').due(state, checked, { now })) {
138
+ wait('check', { kind: d.target.kind, id: d.target.id, title: d.target.id, code: 'unchecked', text: `${d.proposals.length} ${d.proposals.length === 1 ? 'draft' : 'drafts'} not checked yet` });
139
+ }
140
+
141
+ // YOU: open sign-offs and Driver drafts that waited a day (pm-open); answered sign-offs and the PM's decisions are what You made
142
+ const SO = require('./signoffs.js');
143
+ for (const s of SO.fold(Array.isArray(input.signoffs) ? input.signoffs : [])) {
144
+ if (s.state === 'open') { const you = st.get('you'); you.waiting++; if (you.items.length < MAX_ITEMS) you.items.push({ kind: 'signoff', id: s.id, title: one(s.what, 120), code: 'signoff', text: one(`${s.who}: ${s.what}`, 200), ini: s.ini || null }); }
145
+ else if (s.state === 'answered' && inWin(s.answeredAt)) st.get('you').made++;
146
+ }
147
+ for (const p of D.openProposals(state)) {
148
+ if (!p.at || now - Date.parse(p.at) < D.PM_WAIT_MS) continue;
149
+ wait('you', { kind: p.target.kind, id: p.target.id, title: p.target.id, code: 'pm-open', text: `Drafts have waited on you since ${p.at.slice(0, 10)}` });
150
+ }
151
+ for (const p of state.proposals.values()) {
152
+ if (p.decided_by && String(p.decided_by).startsWith('pm:') && !p.auto && inWin(p.decided_at)) st.get('you').made++;
153
+ }
154
+
155
+ // MINUTES: the Driver's runs that ended in the window
156
+ const wakeOf = new Map(state.wakes.map((w) => [w.key, w]));
157
+ let runs = 0;
158
+ for (const r of state.runs.values()) {
159
+ if (!r.end || !inWin(r.end)) continue;
160
+ const t0 = ms(r.start), t1 = ms(r.end);
161
+ if (t0 == null || t1 == null || t1 < t0) continue;
162
+ runs++;
163
+ const mins = (t1 - t0) / 60000;
164
+ let keys = [...new Set([...state.proposals.values()].filter((p) => p.run === r.run).map((p) => stationOfJob('driver:' + p.what, { kind: p.target.kind })).filter(Boolean))];
165
+ if (!keys.length) {
166
+ for (const k of r.wakes) {
167
+ const w = wakeOf.get(k);
168
+ const key = w && (w.blocker ? stationOfCode(w.blocker) : w.reason === 'created' ? 'intake' : w.reason === 'moved' ? 'track' : null);
169
+ if (key) { keys = [key]; break; }
170
+ }
171
+ }
172
+ if (!keys.length) { unplaced.minutes += mins; continue; }
173
+ for (const k of keys) st.get(k).minutes += mins / keys.length;
174
+ }
175
+
176
+ const stations = [...st.values()].map(({ _targets, ...s }) => ({ ...s, minutes: Math.round(s.minutes) }));
177
+ return { v: 1, at: new Date(now).toISOString(), ws, name, days, from: new Date(from).toISOString(), stations,
178
+ unplaced: { made: unplaced.made, minutes: Math.round(unplaced.minutes) }, runs, tokens: null, money: null, usage: NOT_RECORDED };
179
+ }
180
+
181
+ /* ── the read (no write) ── */
182
+ function linesOf(file) {
183
+ let text = '';
184
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
185
+ const out = [];
186
+ for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (isObj(l)) out.push(l); } catch { /* a torn line is skipped */ } }
187
+ return out;
188
+ }
189
+ /** The ledgers of one repository. `stateDir` is the state folder the caller already knows (the Driver's ledger folder); else the rule
190
+ * lib/driver.js stateDirOf uses. No write. */
191
+ function read(root, { runtimeDir = null, stateDir = null } = {}) {
192
+ const dir = stateDir || require('./driver.js').stateDirOf(root);
193
+ const pick = (name) => [dir, runtimeDir].filter(Boolean).map((d) => path.join(d, name)).find((f) => fs.existsSync(f)) || null;
194
+ const ob = runtimeDir ? path.join(runtimeDir, 'outbox', 'outbox.jsonl') : null;
195
+ const at = (name) => (dir ? linesOf(path.join(dir, name)) : []);
196
+ return {
197
+ stateDir: dir,
198
+ autonomy: at('autonomy.jsonl'), proposals: at('proposals.jsonl'), driver: at('driver.jsonl'), checker: at('checker.jsonl'),
199
+ signoffs: dir ? linesOf(require('./signoffs.js').fileOf(dir)) : [],
200
+ bgQueue: pick('bg-queue.jsonl') ? linesOf(pick('bg-queue.jsonl')) : [],
201
+ outbox: ob && fs.existsSync(ob) ? linesOf(ob) : [],
202
+ checks: require('./change-record.js').checksOf(root),
203
+ };
204
+ }
205
+ function build(root, { runtimeDir = null, stateDir = null, now = Date.now(), days = DAYS, ws, name = null } = {}) {
206
+ const input = read(root, { runtimeDir, stateDir });
207
+ if (!input.stateDir) return null;
208
+ const id = ws || require('./driver.js').wsIdOf(root);
209
+ input.outbox = input.outbox.filter((l) => !l.ws || l.ws === id);
210
+ return compute(input, { now, days, ws: id, name });
211
+ }
212
+
213
+ const fileOf = (stateDir) => path.join(stateDir, FILE);
214
+ /** THE ONLY WRITER of the snapshot: build it and write it whole (a temporary file renamed over the old one, so a read never sees half). */
215
+ function save(root, opts = {}) {
216
+ const dir = opts.stateDir || require('./driver.js').stateDirOf(root);
217
+ if (!dir) return { ok: false, error: 'no PMOS state folder' };
218
+ const snapshot = build(root, { ...opts, stateDir: dir });
219
+ const file = fileOf(dir);
220
+ const tmp = `${file}.${process.pid}.tmp`;
221
+ fs.writeFileSync(tmp, JSON.stringify(snapshot) + '\n');
222
+ fs.renameSync(tmp, file);
223
+ return { ok: true, file, snapshot };
224
+ }
225
+ /** The saved snapshot, or null. It reads one file and folds nothing. */
226
+ function load(root, { stateDir = null } = {}) {
227
+ const dir = stateDir || require('./driver.js').stateDirOf(root);
228
+ if (!dir) return null;
229
+ try { const s = JSON.parse(fs.readFileSync(fileOf(dir), 'utf8')); return isObj(s) && s.v === 1 ? s : null; } catch { return null; }
230
+ }
231
+ function ageMinutes(root, now = Date.now()) {
232
+ const s = load(root);
233
+ const t = s && ms(s.at);
234
+ return t == null ? -1 : Math.max(0, Math.floor((now - t) / 60000));
235
+ }
236
+
237
+ module.exports = { STATIONS, WHAT_STATION, GROUP_STATION, RUN_STATION, CODE_STATION, FILE, DAYS, LOG, NOT_RECORDED, MAX_ITEMS,
238
+ stationOfJob, stationOfCode, compute, read, build, fileOf, save, load, ageMinutes };
239
+
240
+ // `node lib/factory-floor.js age <checkout>`: the health number, minutes since the snapshot was saved (-1 when there is none)
241
+ if (require.main === module) {
242
+ const [verb, root = '.'] = process.argv.slice(2);
243
+ if (verb !== 'age') { console.log('usage: node lib/factory-floor.js age <checkout>'); process.exit(2); }
244
+ console.log(String(ageMinutes(path.resolve(root))));
245
+ }
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+ /* pick-cli.js — `pmos pick --minutes <n>`: the one ask that fits the time you have and unblocks the most (initiative time-box-pick-chat,
3
+ * job #1873, idea A293; lib/time-box-pick.js).
4
+ *
5
+ * pmos pick --minutes 30 [--ws <id>] [--json]
6
+ * pmos pick --minutes 30 --root <dir> [--json]
7
+ *
8
+ * With a workspace server running it asks the server (GET /api/find with "I have N minutes", the same answer Ctrl K shows, waiting
9
+ * sessions included). With none it reads the repository and the runtime folder itself. It calls no model, sends nothing and changes no
10
+ * record; the only write is one line in the local use log. Exit codes: 0 done (nothing to pick is done), 1 the asks could not be read,
11
+ * 2 usage. */
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const TB = require('./time-box-pick.js');
15
+ const { parseArgs } = require('./schedule-cli');
16
+
17
+ const COMMANDS = { pick: [] };
18
+ const USAGE = [
19
+ 'usage: pmos pick --minutes <n> [--ws <id>] [--json]',
20
+ ' pmos pick --minutes <n> --root <dir> [--json]',
21
+ 'Picks the one ask from Your move and Waiting on others that fits in <n> minutes and unblocks the most others, with why in one line.',
22
+ 'It calls no model, sends nothing and changes nothing.',
23
+ ];
24
+ const BOOL = new Set(['json', 'help']);
25
+ const VALUE = new Set(['minutes', 'ws', 'root']);
26
+
27
+ /** The repository this directory is in: the nearest folder up with a .git (no git process), else the directory itself. */
28
+ function repoRoot(cwd) {
29
+ let d = path.resolve(cwd);
30
+ for (;;) { try { if (fs.existsSync(path.join(d, '.git'))) return d; } catch { /* unreadable: look further up */ } const up = path.dirname(d); if (up === d) return path.resolve(cwd); d = up; }
31
+ }
32
+
33
+ async function run(argv, { say, call = async () => null, runtimeDir } = {}) {
34
+ const rest = [], bools = {};
35
+ for (const a of argv.slice(1)) {
36
+ if (a.startsWith('--') && BOOL.has(a.slice(2))) bools[a.slice(2)] = true;
37
+ else if (a === '-h' || a === 'help') bools.help = true;
38
+ else rest.push(a);
39
+ }
40
+ const { pos, flags } = parseArgs(rest);
41
+ const f = { ...flags, ...bools };
42
+ if (f.help) { USAGE.forEach((l) => say(l)); return 0; }
43
+ const bad = Object.keys(f).find((k) => !BOOL.has(k) && !VALUE.has(k));
44
+ if (bad || pos.length) { say(`✗ ${bad ? '--' + bad : pos[0]} is not an option of pmos pick`); USAGE.forEach((l) => say(l)); return 2; }
45
+ const mins = TB.minutesOf(String(f.minutes || '').trim() + (/^\d+(?:\.\d+)?$/.test(String(f.minutes || '').trim()) ? ' min' : ''));
46
+ if (!mins) { say('✗ say how long you have: --minutes 30'); USAGE.forEach((l) => say(l)); return 2; }
47
+ if (f.ws && f.root) { say('✗ --ws and --root name two different things: use one'); return 2; }
48
+ const root = path.resolve(f.root ? f.root : repoRoot(process.cwd()));
49
+ let p = null;
50
+ if (!f.root) {
51
+ let ws = f.ws || null;
52
+ if (!ws) {
53
+ const list = await call('GET', '/api/workspaces');
54
+ const mine = list && Array.isArray(list.workspaces) ? list.workspaces.find((x) => x && x.root && path.resolve(x.root) === root) : null;
55
+ ws = mine ? mine.id : null;
56
+ }
57
+ const r = ws ? await call('GET', '/api/find?q=' + encodeURIComponent('I have ' + mins + ' minutes') + '&ws=' + encodeURIComponent(ws)) : null;
58
+ if (f.ws && !(r && r.ok)) { say(`✗ the workspace ${f.ws} could not be reached: no workspace server answered. Start it, or give --root <dir>.`); return 1; }
59
+ if (r && r.ok && r.answer) p = { line: r.answer.text, pick: r.answer.pick || null, minutes: mins, via: 'server' };
60
+ }
61
+ if (!p) {
62
+ let rt = runtimeDir;
63
+ if (rt === undefined) { try { rt = require('./state-root.js').defaultRoot({ env: process.env }); } catch { rt = null; } }
64
+ let t = null;
65
+ try { t = TB.read({ w: { id: 'local', root }, runtimeDir: rt, minutes: mins }); } catch (e) { say('✗ the asks could not be read: ' + ((e && e.message) || e)); return 1; }
66
+ TB.logUse(rt, 'cli');
67
+ const c = t.pick || t.shortest;
68
+ p = { line: t.line, pick: c ? { key: c.key, kind: c.kind, minutes: c.minutes, unblocks: c.unblocks, ini: c.ini || null } : null, minutes: mins, fits: t.fits, via: 'local' };
69
+ }
70
+ if (f.json) say(JSON.stringify({ ok: true, ...p }));
71
+ else { say(p.line); if (p.pick && p.pick.ini) say(' open: ' + p.pick.ini); }
72
+ return 0;
73
+ }
74
+
75
+ module.exports = { run, COMMANDS, USAGE };
@@ -29,6 +29,9 @@ const VERBS = Object.freeze({
29
29
  help: 'pmos measure … — record a measured value of a KR or a health budget, with its source (pmos measure help)' }),
30
30
  today: Object.freeze({ module: 'today-cli.js', run: 3, guide: 'cli.md',
31
31
  help: 'pmos today — what needs you, ranked as Today shows it' }),
32
+ // Not a pm-os-absorb verb (run: null): time-box-pick-chat (idea A293) added it through the same table.
33
+ pick: Object.freeze({ module: 'pick-cli.js', run: null, guide: 'cli.md',
34
+ help: 'pmos pick --minutes <n> — for "I have 30 minutes": the one ask that fits the time and unblocks the most' }),
32
35
  board: Object.freeze({ module: 'board-cli.js', run: 4, guide: 'cli.md',
33
36
  help: 'pmos board [--mine] [--init <id>] — the items of every initiative, by column' }),
34
37
  'verify-work': Object.freeze({ module: 'verify-work-cli.js', run: 4, guide: 'cli.md',
@@ -7,6 +7,11 @@
7
7
  * merge, cost per merged pull request, human corrections per item. Zero is silence: a product with no factory run in the window
8
8
  * is left out, so no factory runs anywhere answers products: [].
9
9
  * `pmos build metrics` prints the same numbers for one repository.
10
+ *
11
+ * GET /api/factory?ws → { ok, products: [{ ws, name, snapshot }] } (initiative factory-floor-snapshot)
12
+ * The factory floor per product as the Driver saved it after its last run (lib/factory-floor.js load). It reads one file per product and
13
+ * folds nothing, so the Factory page opens in 200 ms or less. snapshot is null while no run has saved one: a read never computes or writes.
14
+ * ws: one workspace (404 when unknown); without it, every workspace.
10
15
  */
11
16
  const FT = require('./factory-traces.js');
12
17
 
@@ -28,8 +33,24 @@ function metricsFor(ctx, { ws = '', days = 30, now = Date.now() } = {}) {
28
33
  return { status: 200, body: { ok: true, days, products } };
29
34
  }
30
35
 
36
+ function floorFor(ctx, { ws = '' } = {}) {
37
+ let list;
38
+ if (ws) {
39
+ const w = ctx.getWs(ws);
40
+ if (!w || w.id !== ws) return bad(404, 'no such workspace');
41
+ list = [w];
42
+ } else list = (ctx.workspaceList ? ctx.workspaceList() : []).filter((w) => w && w.root && !w.linked);
43
+ const FF = require('./factory-floor.js');
44
+ const products = list.map((w) => ({ ws: w.id, name: w.name || w.id, snapshot: FF.load(w.root, { stateDir: require('./driver.js').stateDirOf(w.root) || (ctx.stateDirFor ? ctx.stateDirFor(w) : null) }) }));
45
+ return { status: 200, body: { ok: true, products } };
46
+ }
47
+
31
48
  async function handle(req, res, url, ctx) {
32
49
  const send = (r) => { ctx.json(res, r.body, r.status); return true; };
50
+ if (url.pathname === '/api/factory') {
51
+ if (req.method !== 'GET') return send(bad(405, 'GET only'));
52
+ return send(floorFor(ctx, { ws: String(url.searchParams.get('ws') || '') }));
53
+ }
33
54
  if (url.pathname !== '/api/factory/metrics') return send(bad(404, 'no such factory route'));
34
55
  if (req.method !== 'GET') return send(bad(405, 'GET only'));
35
56
  const d = url.searchParams.get('days');
@@ -38,4 +59,4 @@ async function handle(req, res, url, ctx) {
38
59
  return send(metricsFor(ctx, { ws: String(url.searchParams.get('ws') || ''), days }));
39
60
  }
40
61
 
41
- module.exports = { prefixes: ['/api/factory/metrics'], handle, metricsFor };
62
+ module.exports = { prefixes: ['/api/factory/metrics', '/api/factory'], handle, metricsFor, floorFor };
@@ -2,7 +2,9 @@
2
2
  /* routes-search.js — Search across the repository and every worktree (initiative premium-uncovered-features, E1; lib/search-index.js).
3
3
  *
4
4
  * GET /api/find?q=<words>&ws=<id>&wt=<id,id> → { ok, q, worktrees, counts, results, more, answer? } wt: the worktrees to search (none: all)
5
- * answer: one sentence from the user's own files with its source (lib/search-answer.js); absent when nothing is clear
5
+ * answer: one sentence from the user's own files with its source (lib/search-answer.js); absent when nothing is clear.
6
+ * "I have 30 minutes" (time-box-pick-chat, A293): the answer is instead the one ask that fits the time and unblocks the most
7
+ * (lib/time-box-pick.js, read-only, no model), and the use log counts it
6
8
  * GET /api/search-ask?q=<question>&ws=<id> → { ok, answer, why? } a question's answer (lib/search-ask.js): the copied sentence when there is
7
9
  * one, else one written by a read-only PMOS session from passages of the user's files, with those files as its sources (search-answers-questions)
8
10
  * GET /api/find/file?ws=<id>&wt=<id>&path=<p> → { ok, wt, branch, main, path, text, mtime } one file of a listed worktree, for the Viewer
@@ -36,6 +38,20 @@ module.exports = {
36
38
  ctx.json(res, { ws: w.id, q: String(url.searchParams.get('q') || '').trim(), ...r });
37
39
  return true;
38
40
  }
41
+ const mins = require('./time-box-pick.js').minutesOf(url.searchParams.get('q') || '');
42
+ if (mins) {
43
+ const TB = require('./time-box-pick.js');
44
+ let sessions = [];
45
+ try { sessions = ctx.sessionList ? ctx.sessionList() : []; } catch { sessions = []; }
46
+ try {
47
+ const p = TB.read({ w, stateDir: ctx.stateDirFor ? ctx.stateDirFor(w) : undefined, runtimeDir: ctx.runtimeDir, sessions, minutes: mins });
48
+ TB.logUse(ctx.runtimeDir, 'search');
49
+ ctx.json(res, { ok: true, ws: w.id, q: String(url.searchParams.get('q') || '').trim(), worktrees: [], counts: {}, results: [], more: false, answer: TB.answerOf(p) });
50
+ } catch (e) {
51
+ ctx.json(res, { ok: false, error: 'the pick could not be made: ' + String((e && e.message) || e).slice(0, 160) }, 500);
52
+ }
53
+ return true;
54
+ }
39
55
  let notes = [];
40
56
  try { const l = ctx.runtimeDir ? require('./notes.js').list(ctx.runtimeDir) : null; notes = l && l.ok ? l.notes : []; } catch { notes = []; }
41
57
  const only = (url.searchParams.get('wt') || '').split(',').map((x) => x.trim()).filter(Boolean);
@@ -0,0 +1,141 @@
1
+ 'use strict';
2
+ /* time-box-pick.js — "I have N minutes": the one thing that fits the time and unblocks the most (initiative time-box-pick-chat, job #1873,
3
+ * idea A293; done test planning/done-tests/time-box-pick-chat.md).
4
+ *
5
+ * minutesOf(text) → the minutes the PM says they have ("I have 30 minutes", "an hour", "2h"), or null PURE
6
+ * candidatesOf({ cards, gaps, nudges }) → [candidate] one per Today card, action with no owner, and drafted nudge PURE
7
+ * pick(cands, minutes) → { pick, line, fits, minutes, shortest } the choice and its one line of why PURE
8
+ * read({ w, stateDir, runtimeDir, sessions, minutes }) → pick() over what PMOS holds now READ-ONLY
9
+ * answerOf(p) → the Ctrl K answer row (lib/search-answer.js shape) | null PURE
10
+ * logUse(runtimeDir, page) → one `timeBoxPick` line in the local use log (the kill line's count)
11
+ *
12
+ * WHERE IT LOOKS. The asks Today ranks (lib/today.js todayFor cards, in Today's order) and Waiting on others (lib/waiting-on.js): an
13
+ * action a meeting agreed that nobody owns, and a nudge PMOS drafted that is not sent yet. Nothing else: no model picks and no new list.
14
+ *
15
+ * HOW LONG. A fixed time per kind, so the PM can check it (MINUTES): a session that asks 5 min, a gate 10, a returned step or work to
16
+ * check 15, a breakdown or a capture 5, a cycle review 30, a repair 20, naming an owner or sending a nudge 2.
17
+ *
18
+ * WHAT IT UNBLOCKS. 1 when a person or a run waits on it (a gate, a session, a returned step, an action with no owner, a nudge), plus
19
+ * the other candidates on the same initiative, which move once this one does. The pick is the candidate that fits and unblocks the most;
20
+ * a tie goes to Today's order, then the shorter. Nothing fits: the shortest is named with its time. Nothing at all: "Nothing needs you".
21
+ *
22
+ * It calls no model, sends nothing and changes no record. The only write is the use log line, through lib/use-log.js. */
23
+ const TAG = '[time-box-pick]';
24
+
25
+ const NUM = { a: 1, an: 1, one: 1, two: 2, three: 3, four: 4, five: 5, ten: 10, fifteen: 15, twenty: 20, thirty: 30, forty: 40, 'forty-five': 45, sixty: 60, ninety: 90 };
26
+ const UNIT = '(minutes?|mins?|m|hours?|hrs?|h)';
27
+ const AMOUNT = '(\\d+(?:[.,]\\d+)?|a|an|one|two|three|four|five|ten|fifteen|twenty|thirty|forty-five|forty|sixty|ninety)';
28
+ const TIME_RE = new RegExp('(?:^|[^a-z0-9])' + AMOUNT + '\\s*' + UNIT + '(?![a-z])', 'i');
29
+ const HALF_RE = /\bhalf an? hour\b/i;
30
+ const QUARTER_RE = /\ba quarter of an hour\b/i;
31
+ // the time must be the PM's own: "I have", "I've got", "got", "free for", "with", or the time alone ("30 min")
32
+ const OWN_RE = /\b(i\s*have|i've|ive|i\s*got|got|have|free|spare|with|only|just|next)\b/i;
33
+
34
+ /** The minutes in "I have 30 minutes" (1 to 480), or null when the text names no time the PM has. Pure. */
35
+ function minutesOf(text) {
36
+ const s = String(text || '').trim();
37
+ if (!s || s.length > 120) return null;
38
+ let m = null;
39
+ if (QUARTER_RE.test(s)) m = 15;
40
+ else if (HALF_RE.test(s)) m = 30;
41
+ else {
42
+ const t = TIME_RE.exec(s);
43
+ if (!t) return null;
44
+ const raw = t[1].toLowerCase(), n = /\d/.test(raw) ? Number(raw.replace(',', '.')) : NUM[raw];
45
+ if (!Number.isFinite(n) || n <= 0) return null;
46
+ m = /^h/i.test(t[2]) ? n * 60 : n;
47
+ // "30 min" alone is the time; a longer sentence must say it is the PM's time
48
+ const alone = s.replace(t[0], ' ').replace(/[\s?.!,]+/g, '') === '';
49
+ if (!alone && !OWN_RE.test(s)) return null;
50
+ }
51
+ m = Math.round(m);
52
+ return m >= 1 && m <= 480 ? m : null;
53
+ }
54
+
55
+ /** How long each kind of ask takes, in minutes (Today's kinds 1 to 8, then Waiting on others). */
56
+ const MINUTES = Object.freeze({ 1: 10, 2: 5, 3: 15, 4: 15, 5: 5, 6: 5, 7: 30, 8: 20, owner: 2, nudge: 2 });
57
+ const WAITS = new Set([1, 2, 3, 'owner', 'nudge']);
58
+ const VERB = Object.freeze({ 1: 'a gate you owe', 2: 'a session waits on you', 3: 'a step came back to you', 4: 'work to check', 5: 'a breakdown to keep',
59
+ 6: 'a capture to file', 7: 'a cycle review', 8: 'something to repair', owner: 'an action with no owner', nudge: 'a nudge to send' });
60
+ const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
61
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
62
+ const timeWord = (m) => (m >= 60 && m % 60 === 0 ? plural(m / 60, 'hour', 'hours') : m > 60 ? (m / 60).toFixed(1).replace(/\.0$/, '') + ' hours' : m + ' min');
63
+
64
+ /** One candidate per ask. cards: lib/today.js cards (Today's order); gaps: waiting-on gaps; nudges: outbox entries drafted, not sent. Pure. */
65
+ function candidatesOf({ cards = [], gaps = [], nudges = [] } = {}) {
66
+ const out = [];
67
+ (cards || []).forEach((c, i) => {
68
+ if (!c || !Number.isInteger(c.kind)) return;
69
+ out.push({ key: 'card:' + (c.id || i), kind: c.kind, title: clip(c.cause, 140), minutes: MINUTES[c.kind] || 15, ini: c.initiative_id || '',
70
+ ws: c.ws || '', order: i, base: WAITS.has(c.kind) ? 1 : 0, open: c.act && c.act.cli ? c.act.cli : '' });
71
+ });
72
+ for (const g of gaps || []) {
73
+ if (!g || !g.key) continue;
74
+ out.push({ key: g.key, kind: 'owner', title: clip('Name an owner for: ' + g.title, 140), minutes: MINUTES.owner, ini: g.ini || '', ws: g.ws || '', order: 1000 + out.length, base: 1, open: '' });
75
+ }
76
+ for (const e of nudges || []) {
77
+ if (!e || !e.id || !e.about || e.state !== 'queued') continue;
78
+ out.push({ key: 'nudge:' + e.id, kind: 'nudge', title: clip('Send the nudge to ' + (e.recipient || 'them') + (e.subject ? ': ' + String(e.subject).replace(/^Nudge:\s*/, '') : ''), 140),
79
+ minutes: MINUTES.nudge, ini: '', ws: '', order: 2000 + out.length, base: 1, open: '' });
80
+ }
81
+ const perIni = new Map();
82
+ for (const c of out) if (c.ini) perIni.set(c.ini, (perIni.get(c.ini) || 0) + 1);
83
+ for (const c of out) c.unblocks = c.base + (c.ini ? perIni.get(c.ini) - 1 : 0);
84
+ return out;
85
+ }
86
+
87
+ /** The pick for a time: { pick, line, fits, minutes, shortest }. pick is null when nothing fits or nothing waits. Pure. */
88
+ function pick(cands, minutes) {
89
+ const all = (cands || []).filter(Boolean);
90
+ const m = Number(minutes);
91
+ if (!all.length) return { pick: null, fits: 0, minutes: m, shortest: null, line: 'Nothing needs you, so the ' + timeWord(m) + ' are yours.' };
92
+ const fit = all.filter((c) => c.minutes <= m).sort((a, b) => b.unblocks - a.unblocks || a.order - b.order || a.minutes - b.minutes);
93
+ if (!fit.length) {
94
+ const s = all.slice().sort((a, b) => a.minutes - b.minutes || a.order - b.order)[0];
95
+ return { pick: null, fits: 0, minutes: m, shortest: s, line: 'Nothing fits in ' + timeWord(m) + '. The shortest is "' + s.title + '", about ' + timeWord(s.minutes) + '.' };
96
+ }
97
+ const p = fit[0];
98
+ const why = p.unblocks ? 'it unblocks ' + plural(p.unblocks, 'other', 'others') : 'nothing else that fits unblocks more';
99
+ return { pick: p, fits: fit.length, minutes: m, shortest: null,
100
+ line: 'In ' + timeWord(m) + ': ' + p.title.replace(/[.…]+$/, '') + ' (about ' + timeWord(p.minutes) + '). ' + VERB[p.kind].replace(/^./, (x) => x.toUpperCase()) + ', and ' + why + '.' };
101
+ }
102
+
103
+ /** What PMOS holds now, picked for the time. READ-ONLY: it never runs Waiting on others' view (that drafts nudges). */
104
+ function read({ w, stateDir, runtimeDir, sessions = [], registered, minutes, cards } = {}) {
105
+ let list = Array.isArray(cards) ? cards : null;
106
+ if (!list) {
107
+ try { const t = require('./today.js').todayFor(w, { stateDir: stateDir || undefined, sessions, registered }); list = t && t.ok ? t.cards : []; } catch { list = []; }
108
+ }
109
+ let gaps = [], nudges = [];
110
+ if (runtimeDir) {
111
+ try {
112
+ const WO = require('./waiting-on.js'), store = require('./outbox-store.js');
113
+ const entries = store.readOutbox(runtimeDir);
114
+ nudges = entries.filter((e) => e && e.about && e.state === 'queued');
115
+ gaps = WO.derive({ notes: WO.notesOf(runtimeDir, Date.now()), jira: [], sent: entries, mentions: [] }, {}).gaps || [];
116
+ } catch { gaps = []; }
117
+ }
118
+ const p = pick(candidatesOf({ cards: list, gaps, nudges }), minutes);
119
+ console.info(TAG + ' minutes=' + minutes + ' candidates=' + (list.length + gaps.length + nudges.length) + ' fits=' + p.fits + ' pick=' + (p.pick ? p.pick.kind : 'none'));
120
+ return p;
121
+ }
122
+
123
+ /** The Ctrl K answer row: the line, opening the item's initiative, else Today. Pure. */
124
+ function answerOf(p) {
125
+ if (!p || !p.line) return null;
126
+ const c = p.pick || p.shortest;
127
+ const source = c && c.ini ? { kind: 'initiative', id: c.ini, title: c.ini, path: '', main: true, ...(c.ws ? { ws: c.ws } : {}) } : { kind: 'today', title: 'Today', path: '', main: true };
128
+ return { text: p.line, facts: [], made: true, source, sources: [{ title: 'Your move and Waiting on others', path: '' }], pick: c ? { key: c.key, kind: c.kind, minutes: c.minutes, unblocks: c.unblocks, ini: c.ini || null } : null };
129
+ }
130
+
131
+ /** One `timeBoxPick` line in the local use log, so the kill line can count picks. Ctrl K asks again as the PM types ("30 m", "30 min",
132
+ * "30 minutes"), so a second pick within a minute is the same pick and is not counted. Never throws. */
133
+ const lastLog = new Map();
134
+ function logUse(runtimeDir, page = 'search', now = Date.now()) {
135
+ if (!runtimeDir) return;
136
+ if (now - (lastLog.get(runtimeDir) || 0) < 60e3) return;
137
+ lastLog.set(runtimeDir, now);
138
+ try { require('./use-log.js').record(runtimeDir, [{ kind: 'use', page, control: 'timeBoxPick', device: 'desk' }]); } catch { /* the count misses one */ }
139
+ }
140
+
141
+ module.exports = { TAG, MINUTES, minutesOf, candidatesOf, pick, read, answerOf, logUse };
@@ -8,6 +8,7 @@
8
8
  * nudgesToDraft(rows, lines, now) → [entry] pure. The nudges to put in the outbox (drafted, never sent)
9
9
  * view(rt, o) → { ok, rows, gaps, closed } the files: reads the records, writes <rt>/waiting/state.json and the drafts
10
10
  * channelWord(channel) → 'Jira comment' · 'team note' · …
11
+ * notesOf(rt, now) → the notes derive reads (read-only; lib/time-box-pick.js reads the gaps with it)
11
12
  *
12
13
  * THE SOURCES (the brief, item 2). A row exists only with a real who: a name or a Jira assignee.
13
14
  * note a meeting note's action item whose owner is not the PM (the final notes' actions when they exist, else the local summary's).
@@ -249,4 +250,4 @@ function view(rt, o = {}) {
249
250
  return { ok: true, rows, gaps: d.gaps, closed: t.closed, as_of: new Date(now).toISOString() };
250
251
  }
251
252
 
252
- module.exports = { WINDOW_DAYS, STALE_DAYS, NUDGE_DAYS, CLOSED_DAYS, realWho, isMe, derive, track, nudgeOf, nudgesToDraft, nudgeBody, channelWord, view, stateFile };
253
+ module.exports = { WINDOW_DAYS, STALE_DAYS, NUDGE_DAYS, CLOSED_DAYS, realWho, isMe, derive, track, nudgeOf, nudgesToDraft, nudgeBody, channelWord, view, stateFile, notesOf };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.818.0",
3
+ "version": "0.819.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.818.0",
9
+ "version": "0.819.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.818.0",
3
+ "version": "0.819.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",
@@ -215,6 +215,7 @@ function go(r) {
215
215
  closeSearch();
216
216
  if (r.kind === 'ask') { askClaude(r.title); return; }
217
217
  if (r.kind === 'answer') { const src = r.answer.source; go({ ...src, kind: src.kind || 'document', title: src.title || src.path }); return; }
218
+ if (r.kind === 'today') { location.assign(homeUrl({})); return; } // "I have 30 minutes" with no initiative: the ask is on Today (time-box-pick-chat)
218
219
  if (r.kind === 'scoped') { if (typeof r.open === 'function') r.open(); return; }
219
220
  if (r.kind === 'initiative') { if (S.go) { S.go({ ini: r.id }); return; } location.assign(homeUrl(r.board ? { ini: r.id, board: r.board } : { ini: r.id })); return; }
220
221
  if (r.kind === 'session') { if (S.go) { S.go({ ses: r.id }); return; } location.assign(homeUrl({ session: r.id })); return; }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Factory page slice B (factory-floor-snapshot): the factory's numbers per product and station, saved after each Driver run (lib/factory-floor.js, GET /api/factory in lib/routes-factory-metrics.js, pmos factory). Temporary state folders; no git, no server, no browser.",
3
+ "modules": [
4
+ "factory-floor.test.js"
5
+ ],
6
+ "seconds": {
7
+ "factory-floor.test.js": 2
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "I have N minutes (initiative time-box-pick-chat, done test P1-P6, N1-N3): the pure pick, the Ctrl K route in process on a scratch runtime folder, and pmos pick. No server, browser, model or network.",
3
+ "modules": [
4
+ "time-box-pick.test.js"
5
+ ],
6
+ "seconds": {
7
+ "time-box-pick.test.js": 3
8
+ }
9
+ }