create-pmos 0.53.0 → 0.53.1

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.
Files changed (47) hide show
  1. package/package.json +1 -1
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/README.md +2 -0
  7. package/workspace/REMOTE.md +24 -63
  8. package/workspace/bin/pmos.js +4 -2
  9. package/workspace/guide/command-palette.md +1 -1
  10. package/workspace/guide/index.md +2 -1
  11. package/workspace/guide/launcher.md +51 -0
  12. package/workspace/guide/layout.md +4 -0
  13. package/workspace/guide/proactive-engine.md +21 -5
  14. package/workspace/lib/board-fold.js +2 -2
  15. package/workspace/lib/breakdown-export.js +1 -6
  16. package/workspace/lib/brief.js +20 -2
  17. package/workspace/lib/goals.js +165 -0
  18. package/workspace/lib/initiative-rows.js +7 -3
  19. package/workspace/lib/launcher-cli.js +207 -0
  20. package/workspace/lib/plan-tree.js +15 -2
  21. package/workspace/lib/pmos-verbs.js +3 -0
  22. package/workspace/lib/proactive-cli.js +58 -2
  23. package/workspace/lib/proactive.js +2 -2
  24. package/workspace/lib/qr.js +293 -0
  25. package/workspace/lib/remote-access.js +93 -1
  26. package/workspace/lib/report-draft.js +1 -2
  27. package/workspace/lib/routes-timeline.js +1 -1
  28. package/workspace/package-lock.json +1 -1
  29. package/workspace/package.json +1 -1
  30. package/workspace/public/icons/apple-touch-icon.png +0 -0
  31. package/workspace/public/icons/icon-192.png +0 -0
  32. package/workspace/public/icons/icon-512.png +0 -0
  33. package/workspace/public/index.html +11 -0
  34. package/workspace/public/pm/app.js +39 -8
  35. package/workspace/public/pm/components.css +82 -1
  36. package/workspace/public/pm/dest-today.js +8 -2
  37. package/workspace/public/pm/dock.js +73 -3
  38. package/workspace/public/pm/frame-copy.js +5 -0
  39. package/workspace/public/pm/panel-tabs.js +14 -12
  40. package/workspace/public/pm/today-copy.js +29 -0
  41. package/workspace/public/pm/today-goals.js +172 -0
  42. package/workspace/replaced-tests.json +13 -0
  43. package/workspace/server.js +134 -4
  44. package/workspace/skills/morning-brief.skill +15 -9
  45. package/workspace/test-files.json +2 -0
  46. package/workspace/test-lists/workspace-launcher.json +5 -0
  47. package/workspace/test-lists/workspace-phone-app.json +5 -0
@@ -0,0 +1,165 @@
1
+ 'use strict';
2
+ /* goals.js — the PM's goals for the day, and the plan that joins them to what is known and what is owed (initiative
3
+ * `today-goals`, PRD G1 and G4).
4
+ *
5
+ * Pure: no I/O, no clock of its own, no model, no network. The server reads the goals file, the brief and the Today cards,
6
+ * passes them with `now`, and writes what `edit` returns.
7
+ *
8
+ * emptyDay(date) → { date, goals: [] }
9
+ * edit(day, op, { now }) → { ok:true, day } | { ok:false, error }
10
+ * op: { action: 'add', text, initiative_id? } | { action: 'done'|'drop'|'reopen'|'remove', id }
11
+ * readDay(raw, date) → a checked day record, or an empty day when `raw` is not one
12
+ * planDay({ day, brief, cards, now, endOfDay }) → the plan Today and `pmos proactive goals` show
13
+ *
14
+ * THE JOIN IS CHECKABLE. A brief item or calendar event belongs to a goal when it names the goal's id (the morning-brief
15
+ * session sets it). Failing that, an item or Today card belongs to the first open goal tied to the same initiative. There
16
+ * is no word matching: a link is an id, so the PM can see why a step is under a goal. One step is under one goal only.
17
+ */
18
+ const crypto = require('crypto');
19
+
20
+ const MAX_GOALS = 7;
21
+ const MAX_TEXT = 140;
22
+ const STATUSES = ['open', 'done', 'dropped'];
23
+ const ACTIONS = ['add', 'done', 'drop', 'reopen', 'remove'];
24
+ const INI_RE = /^[a-z0-9][a-z0-9._-]*$/i;
25
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
26
+ const GOAL_ID_RE = /^g-[0-9a-f]{8}$/;
27
+ const START_OF_DAY = '09:00';
28
+ const END_OF_DAY = '18:00';
29
+ const clip = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
30
+
31
+ const emptyDay = (date) => ({ date, goals: [] });
32
+
33
+ /** A day record read from disk, checked. Anything that is not a day record for `date` reads as an empty day. */
34
+ function readDay(raw, date) {
35
+ if (!raw || typeof raw !== 'object' || raw.date !== date || !Array.isArray(raw.goals)) return emptyDay(date);
36
+ const goals = raw.goals.filter((g) => g && typeof g === 'object' && GOAL_ID_RE.test(g.id) && typeof g.text === 'string' && g.text.trim()
37
+ && STATUSES.includes(g.status)).slice(0, MAX_GOALS).map((g) => ({
38
+ id: g.id, text: clip(g.text, MAX_TEXT), initiative_id: typeof g.initiative_id === 'string' && INI_RE.test(g.initiative_id) ? g.initiative_id : null,
39
+ status: g.status, added_at: typeof g.added_at === 'string' ? g.added_at : null, closed_at: typeof g.closed_at === 'string' ? g.closed_at : null,
40
+ }));
41
+ return { date, goals };
42
+ }
43
+
44
+ /** One edit of the day's goals. A refused edit returns the reason and the caller writes nothing. */
45
+ function edit(day, op, { now = Date.now() } = {}) {
46
+ if (!day || !DATE_RE.test(String(day.date)) || !Array.isArray(day.goals)) return { ok: false, error: 'no day record to edit' };
47
+ if (!op || typeof op !== 'object' || !ACTIONS.includes(op.action)) return { ok: false, error: `action must be one of ${ACTIONS.join(', ')}` };
48
+ const at = new Date(now).toISOString();
49
+ const goals = day.goals.map((g) => ({ ...g }));
50
+ if (op.action === 'add') {
51
+ if (typeof op.text !== 'string' || !op.text.trim()) return { ok: false, error: 'a goal needs text' };
52
+ if (op.text.trim().length > MAX_TEXT) return { ok: false, error: `a goal is at most ${MAX_TEXT} characters` };
53
+ if (goals.length >= MAX_GOALS) return { ok: false, error: `a day has at most ${MAX_GOALS} goals. Drop or remove one first.` };
54
+ const ini = op.initiative_id == null || op.initiative_id === '' ? null : op.initiative_id;
55
+ if (ini !== null && (typeof ini !== 'string' || !INI_RE.test(ini))) return { ok: false, error: 'initiative_id is not an initiative id' };
56
+ const text = clip(op.text, MAX_TEXT);
57
+ if (goals.some((g) => g.text.toLowerCase() === text.toLowerCase())) return { ok: false, error: 'that goal is already on the list' };
58
+ const id = 'g-' + crypto.createHash('sha1').update(`${day.date}|${text}|${at}|${goals.length}`).digest('hex').slice(0, 8);
59
+ goals.push({ id, text, initiative_id: ini, status: 'open', added_at: at, closed_at: null });
60
+ return { ok: true, day: { date: day.date, goals }, goal: goals[goals.length - 1] };
61
+ }
62
+ const i = goals.findIndex((g) => g.id === op.id);
63
+ if (i < 0) return { ok: false, error: 'no goal with that id today' };
64
+ const g = goals[i];
65
+ if (op.action === 'remove') { goals.splice(i, 1); return { ok: true, day: { date: day.date, goals }, goal: g }; }
66
+ const to = { done: 'done', drop: 'dropped', reopen: 'open' }[op.action];
67
+ if (g.status === to) return { ok: false, error: `that goal is already ${to}` };
68
+ g.status = to; g.closed_at = to === 'open' ? null : at;
69
+ return { ok: true, day: { date: day.date, goals }, goal: g };
70
+ }
71
+
72
+ /* ── the plan ──────────────────────────────────────────────────────────────────────────────────────────────────── */
73
+
74
+ const minutesOf = (hhmm) => { const [h, m] = String(hhmm).split(':').map(Number); return h * 60 + m; };
75
+
76
+ /** Free minutes of the working day still ahead (from `now`, or 09:00 if earlier, to 18:00 local), and the next event. */
77
+ function freeTime(events, at, endOfDay = END_OF_DAY) {
78
+ const d = new Date(at);
79
+ const end = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, minutesOf(endOfDay)).getTime();
80
+ const now = Math.max(at, new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, minutesOf(START_OF_DAY)).getTime());
81
+ if (now >= end) return { free_minutes: 0, until: endOfDay, next: null };
82
+ const spans = [];
83
+ for (const e of events || []) {
84
+ const s = Date.parse(e.start); const f = e.end ? Date.parse(e.end) : s + 30 * 60000;
85
+ if (!Number.isFinite(s) || !Number.isFinite(f) || f <= now || s >= end) continue;
86
+ spans.push([Math.max(s, now), Math.min(f, end)]);
87
+ }
88
+ spans.sort((a, b) => a[0] - b[0]);
89
+ let busy = 0; let cur = null;
90
+ for (const sp of spans) {
91
+ if (!cur || sp[0] > cur[1]) { if (cur) busy += cur[1] - cur[0]; cur = sp.slice(); }
92
+ else cur[1] = Math.max(cur[1], sp[1]);
93
+ }
94
+ if (cur) busy += cur[1] - cur[0];
95
+ const upcoming = (events || []).filter((e) => Date.parse(e.start) > now).sort((a, b) => Date.parse(a.start) - Date.parse(b.start))[0] || null;
96
+ return { free_minutes: Math.max(0, Math.round((end - now - busy) / 60000)), until: endOfDay, next: upcoming ? { start: upcoming.start, title: upcoming.title } : null };
97
+ }
98
+
99
+ const stepOrder = (a, b) => (a.owner === b.owner ? 0 : a.owner === 'pm' ? -1 : 1) || (b.confidence - a.confidence) || a.title.localeCompare(b.title);
100
+
101
+ function itemStep(x) {
102
+ return { ref: 'brief:' + x.id, from: 'brief', source: x.source, title: x.title, why: x.why_now, evidence: x.evidence || '', owner: x.owner,
103
+ effort: x.effort, confidence: x.confidence, initiative_id: x.initiative_id || null, mention: !!x.mention, worth_asking: !!x.worth_asking,
104
+ prepare: x.owner === 'agent' && !!x.initiative_id };
105
+ }
106
+ function cardStep(c) {
107
+ return { ref: 'today:' + c.id, from: 'today', source: c.source || 'today', title: c.cause, why: c.cause, evidence: c.evidence || '', owner: 'pm',
108
+ effort: null, confidence: 1, initiative_id: c.initiative_id || null, kind: c.kind, act: c.act ? c.act.label : null, ws: c.ws || null, mention: false,
109
+ worth_asking: false, prepare: false };
110
+ }
111
+
112
+ /**
113
+ * The day plan.
114
+ * day the goals record for the day (readDay)
115
+ * brief the stored brief (lib/brief.js shape) or null
116
+ * cards Today cards (lib/today.js) across the workspaces read, or []
117
+ * now ms; the clock the server passes
118
+ * A brief for another day is not joined: it is named as out of date, and only the Today cards plan the goals.
119
+ */
120
+ function planDay({ day, brief = null, cards = [], now = Date.now(), endOfDay = END_OF_DAY } = {}) {
121
+ const date = day && day.date;
122
+ const fresh = !!brief && brief.date === date;
123
+ const items = fresh ? [...(brief.priorities || []), ...(brief.worth_asking || [])] : [];
124
+ const events = fresh ? (brief.calendar || []) : [];
125
+ const goals = (day && day.goals ? day.goals : []).map((g) => ({ ...g, steps: [], context: [] }));
126
+ const open = goals.filter((g) => g.status === 'open');
127
+ const byId = new Map(goals.map((g) => [g.id, g]));
128
+ const byIni = (ini) => (ini ? open.find((g) => g.initiative_id === ini) || null : null);
129
+ const unplaced = { items: [], cards: [] };
130
+
131
+ for (const x of items) {
132
+ const g = (x.goal && byId.get(x.goal)) || byIni(x.initiative_id);
133
+ if (g) g.steps.push(itemStep(x)); else unplaced.items.push(x);
134
+ }
135
+ for (const c of cards || []) {
136
+ const g = byIni(c.initiative_id);
137
+ if (g) g.steps.push(cardStep(c)); else unplaced.cards.push(c);
138
+ }
139
+ for (const e of events) {
140
+ const g = e.goal && byId.get(e.goal);
141
+ if (g) g.context.push({ start: e.start, end: e.end || null, title: e.title, with: e.with || null });
142
+ }
143
+ for (const g of goals) {
144
+ g.steps.sort(stepOrder);
145
+ g.coverage = g.status === 'done' ? 'done' : g.status === 'dropped' ? 'dropped' : g.steps.length ? 'planned' : 'needs-plan';
146
+ g.agent_steps = g.steps.filter((s) => s.prepare).length;
147
+ }
148
+ const also = [
149
+ ...unplaced.items.filter((x) => !x.worth_asking).map(itemStep),
150
+ ...unplaced.cards.map(cardStep),
151
+ ].sort(stepOrder);
152
+ const worthAsking = unplaced.items.filter((x) => x.worth_asking).map(itemStep).sort(stepOrder);
153
+ const notRead = fresh ? Object.entries(brief.sources || {}).filter(([, v]) => v !== 'read').map(([k, v]) => ({ source: k, state: v })) : [];
154
+ const counts = { open: open.length, done: goals.filter((g) => g.status === 'done').length, planned: goals.filter((g) => g.coverage === 'planned').length,
155
+ needs_plan: goals.filter((g) => g.coverage === 'needs-plan').length };
156
+ return {
157
+ date, goals, also, worth_asking: worthAsking, counts,
158
+ brief: brief ? { date: brief.date, fresh, generated_at: brief.generated_at || null } : null,
159
+ not_read: notRead,
160
+ time: fresh ? freeTime(events, now, endOfDay) : null,
161
+ mentions: items.filter((x) => x.mention).length,
162
+ };
163
+ }
164
+
165
+ module.exports = { MAX_GOALS, MAX_TEXT, STATUSES, ACTIONS, GOAL_ID_RE, START_OF_DAY, END_OF_DAY, emptyDay, readDay, edit, freeTime, planDay };
@@ -60,10 +60,14 @@ const iso = (v) => {
60
60
 
61
61
  /** The engine's JSON rows → the narrowed rows, each with its lane group. */
62
62
  function narrow(root, raw) {
63
- let groups = {};
64
- try { groups = workGroupOf(root); } catch { groups = {}; }
63
+ // The group comes from the lane the record DECLARES (plan-tree.js viewGroup): the engine's `lane` is the fallback
64
+ // when none is declared, and in a pm-artifacts repository that fallback is the document lane `prd`.
65
+ const planTree = require('./plan-tree.js');
66
+ const groupOf = (r) => {
67
+ try { return planTree.profileAndLane(root, r.id).group; } catch { return 'work'; }
68
+ };
65
69
  return (Array.isArray(raw) ? raw : []).map((r) => (r && r.ok !== false ? {
66
- ok: true, id: r.id, title: r.title || r.id, lane: r.lane, group: groups[r.lane] || null, anchor: r.anchor || null,
70
+ ok: true, id: r.id, title: r.title || r.id, lane: r.lane, group: groupOf(r), anchor: r.anchor || null,
67
71
  stage: r.stage || null, accepted: !!r.accepted,
68
72
  stopped: r.stopped ? { state: r.stopped.state, reason: r.stopped.reason || '', at: r.stopped.at || null } : null,
69
73
  last_activity: iso(r.last_activity), profile: r.profile || null, record: r.record || null, next: r.next || null,
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+ /* launcher-cli.js — `pmos launcher on|off|status`: start the workspace without a terminal (initiative workspace-launcher).
3
+ *
4
+ * pmos launcher on [<path>] [--no-login] write a PMOS app (and, unless --no-login, a login item) for one repository
5
+ * pmos launcher off remove what `on` wrote, and nothing else
6
+ * pmos launcher status say what is installed and whether it still points at a real node and repo
7
+ *
8
+ * The app and the login item are two more callers of `pmos up <repo>`; nothing here starts a server itself. The app
9
+ * opens the browser. The login item passes --no-open, so a login starts the server and opens nothing.
10
+ *
11
+ * macOS ~/Applications/PMOS.app Spotlight, Launchpad, drag it to the Dock
12
+ * ~/Library/LaunchAgents/com.pmos.workspace.plist runs at login (RunAtLoad), once
13
+ * Linux $XDG_DATA_HOME/applications/pmos.desktop the app menu
14
+ * $XDG_CONFIG_HOME/autostart/pmos-workspace.desktop
15
+ *
16
+ * A file started by the desktop has no shell profile, so the PATH of the terminal that ran `on` is written into the
17
+ * script; that is how `claude`, `git` and `tmux` resolve. It never starts remote (tailnet) mode and writes no token.
18
+ * `off` deletes a file only when it carries MARK, so a file of the same name that the PM wrote is left alone.
19
+ * Native Windows is refused: the workspace needs WSL there for a real PTY (doctor.js says the same).
20
+ *
21
+ * plan() is pure: every input is injected, so each platform's files are assertable from any machine.
22
+ */
23
+ const fs = require('fs');
24
+ const os = require('os');
25
+ const path = require('path');
26
+ const { spawnSync } = require('child_process');
27
+ const stateRoot = require('./state-root');
28
+
29
+ const COMMANDS = { launcher: ['on', 'off', 'status'] };
30
+ const MARK = 'pmos-launcher: written by `pmos launcher on`';
31
+ const LABEL = 'com.pmos.workspace';
32
+ const USAGE = [
33
+ 'usage: pmos launcher on|off|status — start the workspace without a terminal',
34
+ ' pmos launcher on [<path>] [--no-login] a PMOS app for this repository, and a login item that starts the server',
35
+ ' pmos launcher off remove the app and the login item',
36
+ ' pmos launcher status what is installed, and for which repository',
37
+ ];
38
+
39
+ // POSIX shell single quotes: nothing inside is special except the quote itself.
40
+ const shq = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
41
+ // XML text and attribute values in a plist.
42
+ const xml = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
43
+ // A .desktop Exec argument: double-quoted, with the four characters the spec reserves escaped.
44
+ const deq = (s) => `"${String(s).replace(/[\\"`$]/g, (c) => '\\' + c)}"`;
45
+
46
+ function script({ node, bin, repo, pathEnv, log }) {
47
+ return [
48
+ '#!/bin/sh',
49
+ `# ${MARK} (workspace/lib/launcher-cli.js). \`pmos launcher off\` removes it.`,
50
+ '# It runs `pmos up` on one repository with the PATH the terminal had at setup. Arguments pass through (--no-open).',
51
+ `PATH=${shq(pathEnv)}; export PATH`,
52
+ `exec ${shq(node)} ${shq(bin)} up ${shq(repo)} "$@" >>${shq(log)} 2>&1`,
53
+ '',
54
+ ].join('\n');
55
+ }
56
+
57
+ function plist(dict) {
58
+ const v = (x) => Array.isArray(x) ? `<array>${x.map((s) => `<string>${xml(s)}</string>`).join('')}</array>`
59
+ : typeof x === 'boolean' ? (x ? '<true/>' : '<false/>') : `<string>${xml(x)}</string>`;
60
+ return [
61
+ '<?xml version="1.0" encoding="UTF-8"?>',
62
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
63
+ `<!-- ${MARK} (workspace/lib/launcher-cli.js). \`pmos launcher off\` removes it. -->`,
64
+ '<plist version="1.0">',
65
+ '<dict>',
66
+ ...Object.entries(dict).map(([k, x]) => ` <key>${xml(k)}</key>${v(x)}`),
67
+ '</dict>',
68
+ '</plist>',
69
+ '',
70
+ ].join('\n');
71
+ }
72
+
73
+ function desktop(entries) {
74
+ return [`# ${MARK} (workspace/lib/launcher-cli.js). \`pmos launcher off\` removes it.`, '[Desktop Entry]',
75
+ ...Object.entries(entries).map(([k, x]) => `${k}=${x}`), ''].join('\n');
76
+ }
77
+
78
+ /**
79
+ * The files `on` writes, for one platform. Pure.
80
+ * → { files: [{ role: 'app'|'login', path, content, mode }], app, login } or { refused: '<reason>' }
81
+ * `login: false` leaves the login item out.
82
+ */
83
+ function plan({ platform, home, env = {}, node, bin, repo, login = true }) {
84
+ if (platform === 'win32') return { refused: 'native Windows needs WSL for a real PTY. Run `pmos launcher on` inside WSL.' };
85
+ if (platform !== 'darwin' && platform !== 'linux') return { refused: `no launcher is made for ${platform}. Start the workspace with \`pmos\`.` };
86
+ const log = path.join(stateRoot.defaultRoot({ env, platform, home }), 'launcher.log');
87
+ const body = script({ node, bin, repo, pathEnv: env.PATH || '/usr/bin:/bin', log });
88
+ const files = [];
89
+ if (platform === 'darwin') {
90
+ const appDir = path.join(home, 'Applications', 'PMOS.app');
91
+ const exe = path.join(appDir, 'Contents', 'MacOS', 'pmos-launch');
92
+ files.push({ role: 'app', path: exe, content: body, mode: 0o755 });
93
+ files.push({ role: 'app', path: path.join(appDir, 'Contents', 'Info.plist'), mode: 0o644, content: plist({
94
+ CFBundleName: 'PMOS', CFBundleDisplayName: 'PMOS', CFBundleIdentifier: 'com.pmos.launcher',
95
+ CFBundleExecutable: 'pmos-launch', CFBundlePackageType: 'APPL', CFBundleVersion: '1',
96
+ // No Dock icon: the script hands off to the browser and exits within seconds.
97
+ LSUIElement: true,
98
+ }) });
99
+ const agent = path.join(home, 'Library', 'LaunchAgents', `${LABEL}.plist`);
100
+ if (login) files.push({ role: 'login', path: agent, mode: 0o644, content: plist({
101
+ Label: LABEL, ProgramArguments: ['/bin/sh', exe, '--no-open'], RunAtLoad: true,
102
+ // `pmos up` detaches the server and exits; launchd must not reap the group it leaves behind.
103
+ AbandonProcessGroup: true,
104
+ }) });
105
+ return { files, app: appDir, login: login ? agent : null, removable: [appDir, agent] };
106
+ }
107
+ const data = env.XDG_DATA_HOME && path.isAbsolute(env.XDG_DATA_HOME) ? env.XDG_DATA_HOME : path.join(home, '.local', 'share');
108
+ const conf = env.XDG_CONFIG_HOME && path.isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(home, '.config');
109
+ const exe = path.join(data, 'pmos', 'pmos-launch.sh');
110
+ const app = path.join(data, 'applications', 'pmos.desktop');
111
+ const auto = path.join(conf, 'autostart', 'pmos-workspace.desktop');
112
+ files.push({ role: 'app', path: exe, content: body, mode: 0o755 });
113
+ files.push({ role: 'app', path: app, mode: 0o644, content: desktop({
114
+ Type: 'Application', Name: 'PMOS', Comment: 'Open the PMOS workspace', Exec: `/bin/sh ${deq(exe)}`,
115
+ Terminal: 'false', Categories: 'Development;' }) });
116
+ if (login) files.push({ role: 'login', path: auto, mode: 0o644, content: desktop({
117
+ Type: 'Application', Name: 'PMOS workspace', Comment: 'Start the PMOS workspace server at login',
118
+ Exec: `/bin/sh ${deq(exe)} --no-open`, Terminal: 'false', NoDisplay: 'true', 'X-GNOME-Autostart-enabled': 'true' }) });
119
+ return { files, app, login: login ? auto : null, removable: [exe, app, auto] };
120
+ }
121
+
122
+ const marked = (f) => { try { return fs.readFileSync(f, 'utf8').includes(MARK); } catch { return false; } };
123
+ // The file under a removable path that carries the mark: the bundle's script for a .app, else the path itself.
124
+ const markFile = (p) => p.endsWith('.app') ? path.join(p, 'Contents', 'MacOS', 'pmos-launch') : p;
125
+
126
+ function repoRootOf(dir) {
127
+ const r = spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd: dir, encoding: 'utf8' });
128
+ return r.status === 0 ? String(r.stdout).trim() : dir;
129
+ }
130
+
131
+ // What the installed script points at: the repository and whether node and pmos.js still exist.
132
+ function readTarget(exe) {
133
+ let src = '';
134
+ try { src = fs.readFileSync(exe, 'utf8'); } catch { return null; }
135
+ const m = src.match(/^exec '((?:[^']|'\\'')*)' '((?:[^']|'\\'')*)' up '((?:[^']|'\\'')*)'/m);
136
+ if (!m) return null;
137
+ const un = (s) => s.replace(/'\\''/g, "'");
138
+ return { node: un(m[1]), bin: un(m[2]), repo: un(m[3]) };
139
+ }
140
+
141
+ function run(argv, { say = console.log, platform = process.platform, home = os.homedir(), env = process.env,
142
+ node = process.execPath, bin = path.join(__dirname, '..', 'bin', 'pmos.js'), cwd = process.cwd() } = {}) {
143
+ const pos = argv.slice(1).filter((a) => !a.startsWith('--'));
144
+ const flags = new Set(argv.slice(1).filter((a) => a.startsWith('--')).map((a) => a.slice(2)));
145
+ const unknown = [...flags].filter((f) => f !== 'no-login' && f !== 'help');
146
+ if (unknown.length) { say(`✗ unknown option --${unknown[0]}`); for (const l of USAGE) say(l); return 2; }
147
+ const sub = pos[0];
148
+ if (!sub || flags.has('help') || sub === 'help') { for (const l of USAGE) say(l); return sub ? 0 : 2; }
149
+ if (!COMMANDS.launcher.includes(sub)) { say(`✗ pmos launcher ${sub} is not a command`); for (const l of USAGE) say(l); return 2; }
150
+
151
+ if (sub === 'on') {
152
+ const dir = pos[1] ? path.resolve(cwd, pos[1]) : cwd;
153
+ if (!fs.existsSync(dir)) { say(`✗ ${dir} does not exist`); return 1; }
154
+ const repo = repoRootOf(dir);
155
+ const p = plan({ platform, home, env, node, bin, repo, login: !flags.has('no-login') });
156
+ if (p.refused) { say(`✗ ${p.refused}`); return 1; }
157
+ // Never write over a file of the same name that the launcher did not write.
158
+ const foreign = p.files.filter((f) => fs.existsSync(f.path) && !marked(f.path));
159
+ if (foreign.length) { say(`✗ not written: ${foreign.map((f) => f.path).join(', ')} exists and was not written by pmos launcher`); return 1; }
160
+ for (const f of p.files) {
161
+ fs.mkdirSync(path.dirname(f.path), { recursive: true });
162
+ fs.writeFileSync(f.path, f.content, { mode: f.mode });
163
+ fs.chmodSync(f.path, f.mode);
164
+ }
165
+ say(`✓ PMOS app for ${repo}`);
166
+ say(` ${p.app}`);
167
+ say(platform === 'darwin' ? ' Open it from Spotlight or Launchpad, or drag it to the Dock.' : ' Open it from the app menu.');
168
+ if (p.login) {
169
+ say('✓ login item: the workspace server starts when you log in, without a browser window');
170
+ say(` ${p.login}`);
171
+ } else say(' no login item (--no-login): the server starts when you open the app');
172
+ say(' The app opens the browser on the running workspace and starts the server when none runs.');
173
+ say(' If you move or upgrade node, run `pmos launcher on` again.');
174
+ return 0;
175
+ }
176
+
177
+ const p = plan({ platform, home, env, node, bin, repo: cwd });
178
+ if (p.refused) { say(`✗ ${p.refused}`); return 1; }
179
+
180
+ if (sub === 'off') {
181
+ let removed = 0;
182
+ for (const r of p.removable) {
183
+ if (!fs.existsSync(r)) continue;
184
+ if (!marked(markFile(r))) { say(`· left ${r}: it was not written by pmos launcher`); continue; }
185
+ fs.rmSync(r, { recursive: true, force: true });
186
+ say(`✓ removed ${r}`);
187
+ removed++;
188
+ }
189
+ if (!removed) say('○ nothing to remove: no launcher is installed');
190
+ return 0;
191
+ }
192
+
193
+ // status
194
+ const exe = p.files.find((f) => f.role === 'app' && f.mode === 0o755).path;
195
+ const t = marked(exe) ? readTarget(exe) : null;
196
+ const loginPath = p.removable.find((r) => r.endsWith('.plist') || r.endsWith('pmos-workspace.desktop'));
197
+ const login = fs.existsSync(loginPath) && marked(loginPath);
198
+ if (!t) { say('○ no PMOS app is installed (pmos launcher on)'); if (login) say(`· a login item is installed without the app: ${loginPath}`); return 1; }
199
+ say(`✓ PMOS app — ${p.app}`);
200
+ say(` repository: ${t.repo}${fs.existsSync(t.repo) ? '' : ' ✗ not found'}`);
201
+ say(` node: ${t.node}${fs.existsSync(t.node) ? '' : ' ✗ not found — run `pmos launcher on` again'}`);
202
+ say(` pmos: ${t.bin}${fs.existsSync(t.bin) ? '' : ' ✗ not found — run `pmos launcher on` again'}`);
203
+ say(login ? `✓ login item — ${loginPath}` : '○ no login item: the server starts when you open the app');
204
+ return [t.repo, t.node, t.bin].every((x) => fs.existsSync(x)) ? 0 : 1;
205
+ }
206
+
207
+ module.exports = { run, plan, readTarget, COMMANDS, USAGE, MARK };
@@ -110,7 +110,20 @@ function profileAndLane(root, initiative) {
110
110
  // An unknown or missing lane is the profile's strictest, exactly as workflow-state.js computes `effLane`.
111
111
  const fallback = profile === 'pm-artifacts' ? 'prd' : 'feature';
112
112
  const lane = declared && defs[declared] ? declared : fallback;
113
- return { profile, lane, defs, record: file };
113
+ return { profile, lane, defs, record: file, group: viewGroup(defs, declared) };
114
+ }
115
+
116
+ /**
117
+ * Whether an initiative is a work card or a document in the planning views (D86 point 4), from its DECLARED lane.
118
+ *
119
+ * Only a record that declares a document lane is a document. A missing or unknown lane is work: the fallback above
120
+ * picks the strictest ladder for the gate, and in a pm-artifacts repository that fallback is `prd`, a document lane.
121
+ * Grouping by the fallback hid every record written before lanes were declared (0.53.0: most of a kit repository's
122
+ * initiatives were missing from Initiatives, Board and Reports).
123
+ */
124
+ function viewGroup(defs, declared) {
125
+ const d = String(declared || '').trim();
126
+ return d && defs && defs[d] && defs[d].group ? defs[d].group : 'work';
114
127
  }
115
128
 
116
129
  const cap = (s) => (s && /^[a-z]/.test(s) ? s[0].toUpperCase() + s.slice(1) : s);
@@ -363,5 +376,5 @@ function layout({ root, initiative, fold, ladder, now }) {
363
376
 
364
377
  module.exports = {
365
378
  STAGE_GROUPS, STEP_NOUN, OWED_ACTOR, OPEN, DONE_WINDOW_MS, INIT_RE, NOT_MERGED_LABEL, withFactory,
366
- mainTree, recordPath, profileAndLane, stagesFor, stageIdsFor, resolveStage, owedFor, nounFor, byLabel, progressLabel, layout, historyText,
379
+ mainTree, recordPath, profileAndLane, viewGroup, stagesFor, stageIdsFor, resolveStage, owedFor, nounFor, byLabel, progressLabel, layout, historyText,
367
380
  };
@@ -34,6 +34,9 @@ const VERBS = Object.freeze({
34
34
  help: 'pmos verify-work — mark work items integrated from the default branch (local refs only)' }),
35
35
  report: Object.freeze({ module: 'report-cli.js', run: 5, guide: 'reports.md',
36
36
  help: 'pmos report draft|issue|list … — draft and issue reports (pmos report help)' }),
37
+ // Not a pm-os-absorb verb (run: null): the workspace-launcher initiative added it through the same table.
38
+ launcher: Object.freeze({ module: 'launcher-cli.js', run: null, guide: 'launcher.md',
39
+ help: 'pmos launcher on|off|status — a PMOS app and a login item, so the workspace starts without a terminal' }),
37
40
  });
38
41
 
39
42
  const has = (verb) => typeof verb === 'string' && Object.prototype.hasOwnProperty.call(VERBS, verb);
@@ -13,6 +13,7 @@
13
13
  * pmos proactive brief [show]
14
14
  * pmos proactive brief submit --file PATH
15
15
  * pmos proactive brief schedule [--repo PATH]
16
+ * pmos proactive goals [list] | add TEXT [--initiative ID] | done N | drop N | reopen N | remove N | plan [--repo PATH]
16
17
  * pmos proactive prepare plan --initiative ID [--repo PATH]
17
18
  * pmos proactive prepare queue --initiative ID --item ITEM --sha HASH [--repo PATH]
18
19
  * pmos proactive prepare status | cancel ID | run
@@ -23,8 +24,8 @@ const path = require('path');
23
24
  const { execFileSync } = require('child_process');
24
25
  const { parseArgs } = require('./schedule-cli');
25
26
 
26
- const COMMANDS = { proactive: ['today', 'scan', 'settings', 'feedback', 'brief', 'prepare', 'learn'] };
27
- const BRIEF_SOURCES = ['calendar', 'wispr', 'mail', 'jira', 'confluence'];
27
+ const COMMANDS = { proactive: ['today', 'scan', 'settings', 'feedback', 'brief', 'goals', 'prepare', 'learn'] };
28
+ const BRIEF_SOURCES = ['calendar', 'wispr', 'mail', 'slack', 'jira', 'confluence'];
28
29
  const onOff = (v, what) => (v === 'on' || v === 'true' ? true : v === 'off' || v === 'false' ? false : { err: `${what} takes on or off` });
29
30
 
30
31
  async function run(argv, { call, say, cwd = process.cwd() }) {
@@ -189,6 +190,61 @@ async function run(argv, { call, say, cwd = process.cwd() }) {
189
190
  for (const l of r.lessons.filter((x) => x.status === 'proposed' || x.status === 'approved')) say(`${l.id} ${l.status} ${l.text}`);
190
191
  return 0;
191
192
  }
193
+ if (verb === 'goals') {
194
+ const sub = pos[0] || 'list';
195
+ const usage = 'usage: pmos proactive goals [list] | add TEXT [--initiative ID] | done N | drop N | reopen N | remove N | plan [--repo PATH]';
196
+ const wsOfRepo = async () => {
197
+ let root; try { root = execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd: flags.repo ? path.resolve(cwd, flags.repo) : cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim(); } catch { return null; }
198
+ const wl = await call('GET', '/api/workspaces');
199
+ const hit = ((wl && wl.workspaces) || []).find((w) => path.resolve(w.root) === path.resolve(root));
200
+ return hit ? hit.id : null;
201
+ };
202
+ const get = async () => { const ws = await wsOfRepo(); return call('GET', '/api/proactive/goals' + (ws ? '?ws=' + encodeURIComponent(ws) : '')); };
203
+ if (sub === 'add') {
204
+ const text = pos.slice(1).join(' ');
205
+ if (!text.trim()) return fail(usage);
206
+ const r = await call('POST', '/api/proactive/goals', { action: 'add', text, ...(flags.initiative ? { initiative_id: flags.initiative } : {}) });
207
+ if (!r || r.ok === false) return fail(`refused — ${(r && r.error) || 'the server did not answer'}. Nothing changed.`);
208
+ say(`added goal ${r.day.goals.length}: ${r.goal.text}${r.goal.initiative_id ? ' · ' + r.goal.initiative_id : ''}`);
209
+ return 0;
210
+ }
211
+ if (['done', 'drop', 'reopen', 'remove'].includes(sub)) {
212
+ const t = await get();
213
+ if (!t || t.ok === false) return fail((t && t.error) || 'the server did not answer');
214
+ const ref = pos[1];
215
+ const g = /^\d+$/.test(String(ref)) ? t.plan.goals[Number(ref) - 1] : t.plan.goals.find((x) => x.id === ref);
216
+ if (!g) return fail(`no goal ${ref || ''} today — ${usage}`);
217
+ const r = await call('POST', '/api/proactive/goals', { action: sub, id: g.id });
218
+ if (!r || r.ok === false) return fail(`refused — ${(r && r.error) || 'the server did not answer'}. Nothing changed.`);
219
+ say(`${sub === 'remove' ? 'removed' : sub === 'reopen' ? 'reopened' : sub === 'drop' ? 'dropped' : 'done'}: ${g.text}`);
220
+ return 0;
221
+ }
222
+ if (sub === 'plan') {
223
+ const ws = await wsOfRepo();
224
+ if (!ws) return fail('this is not inside a registered workspace — open it with pmos first, or use --repo PATH');
225
+ const r = await call('POST', '/api/proactive/goals/plan', { ws });
226
+ if (!r || r.ok === false) return fail(`not started — ${(r && r.error) || 'the server did not answer'}`);
227
+ say(`${r.seeded ? `scheduled the morning brief daily at ${r.schedule.time}, and ` : ''}started a morning-brief session to plan ${r.goals} goal(s). The plan shows when it submits the brief.`);
228
+ return 0;
229
+ }
230
+ if (sub !== 'list') return fail(usage);
231
+ const t = await get();
232
+ if (!t || t.ok === false) return fail((t && t.error) || 'the server did not answer');
233
+ const pl = t.plan;
234
+ if (!pl.goals.length) say(`No goals for ${t.today}. Add one with: pmos proactive goals add "…"`);
235
+ pl.goals.forEach((g, i) => {
236
+ say(`${i + 1}. ${g.id} [${g.coverage}] ${g.text}${g.initiative_id ? ' · ' + g.initiative_id : ''}`);
237
+ for (const e of g.context) say(` ${e.start} ${e.title}`);
238
+ for (const st of g.steps) say(` ${st.owner === 'pm' ? 'you ' : 'agent'} ${st.title} (${st.source}${st.mention ? ', mention' : ''}${st.prepare ? ', can prepare' : ''})`);
239
+ });
240
+ if (pl.also.length) { say('Also on your plate:'); for (const st of pl.also) say(` ${st.owner === 'pm' ? 'you ' : 'agent'} ${st.title} (${st.source})`); }
241
+ if (pl.brief && !pl.brief.fresh) say(`The brief is for ${pl.brief.date}, not today: it is not used. Run: pmos proactive goals plan`);
242
+ if (!pl.brief) say('No brief yet, so the plan uses only what Today derived. Run: pmos proactive goals plan');
243
+ if (pl.time) say(`Free until ${pl.time.until}: ${pl.time.free_minutes} min${pl.time.next ? ` · next: ${pl.time.next.title} at ${pl.time.next.start}` : ''}`);
244
+ if (pl.not_read.length) say('not read: ' + pl.not_read.map((x) => `${x.source} (${x.state})`).join(', '));
245
+ if (t.cards_error) say('! Today could not be read: ' + t.cards_error);
246
+ return 0;
247
+ }
192
248
  if (verb === 'brief') {
193
249
  const sub = pos[0] || 'show';
194
250
  if (sub === 'submit') {
@@ -29,9 +29,9 @@ const DISMISS_MS = 7 * DAY;
29
29
  const BASE = { needs: 100, returned: 100, review: 80, schedule: 60, stalled: 40 };
30
30
  const OWNER = { needs: 'pm', returned: 'pm', review: 'pm', schedule: 'pm', stalled: 'agent' };
31
31
 
32
- const BRIEF_SOURCES = ['calendar', 'wispr', 'mail', 'jira', 'confluence'];
32
+ const BRIEF_SOURCES = ['calendar', 'wispr', 'mail', 'slack', 'jira', 'confluence'];
33
33
  // Mail is off by default: a brief reads titles and metadata of the other sources, and the PM turns mail on.
34
- const BRIEF_DEFAULT = Object.freeze({ calendar: true, wispr: true, mail: false, jira: true, confluence: true });
34
+ const BRIEF_DEFAULT = Object.freeze({ calendar: true, wispr: true, mail: false, slack: true, jira: true, confluence: true });
35
35
  const DEFAULTS = Object.freeze({ name: '', briefSources: BRIEF_DEFAULT, briefScoring: false, backgroundPrepare: false, enabled: true, triggers: Object.freeze(Object.fromEntries(TRIGGERS.map((t) => [t, true]))), stalledDays: 5, quiet: null, pauseLearning: false });
36
36
 
37
37
  const idOf = (key) => crypto.createHash('sha1').update(String(key)).digest('hex').slice(0, 12);