create-pmos 0.825.0 → 0.826.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 +88 -30
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +87 -16
- package/workspace/guide/agent-capabilities.md +1 -0
- package/workspace/guide/cli.md +23 -0
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/layout.md +1 -1
- package/workspace/guide/settings-and-switches.md +2 -0
- package/workspace/lib/code-map-cli.js +100 -0
- package/workspace/lib/code-map.js +247 -0
- package/workspace/lib/features.json +58 -1
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-code-map.js +66 -0
- package/workspace/lib/routes-today.js +2 -1
- package/workspace/lib/today-cli.js +4 -2
- package/workspace/lib/today-order.js +120 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/code-map.js +60 -0
- package/workspace/public/pm/cozy-board.css +8 -0
- package/workspace/public/pm/cozy-settings.js +0 -1
- package/workspace/public/pm/cozy-today-app.js +41 -2
- package/workspace/public/pm/cozy-today-page.css +3 -0
- package/workspace/public/pm/cozy-today-view.js +20 -5
- package/workspace/public/pm/pop-cap.js +5 -2
- package/workspace/public/pm/premium-board.js +2 -0
- package/workspace/public/pm/today-order.js +88 -0
- package/workspace/public/premium-board.html +2 -0
- package/workspace/test-lists/code-map.json +9 -0
- package/workspace/test-lists/directory-all-verbs.json +9 -0
- package/workspace/test-lists/today-order.json +9 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* code-map.js — a map of a product's code: one box per main part, what it is, how it is tested, who changed it last (idea A176,
|
|
3
|
+
* initiative code-map, agreed board BatchCodeDS panel 13).
|
|
4
|
+
*
|
|
5
|
+
* partsOf(files) → { parts: [{ name, dir, files, code, tests, langs, testsOutside }], more } PURE
|
|
6
|
+
* summarize({ files, log, last, pkgs, now }) → map without head/at PURE: the parts with kind, tested, bugs, last, risky, why
|
|
7
|
+
* riskOf(part) → null | 'no tests' | 'N fixes in 30 days' | both joined PURE
|
|
8
|
+
* build(root, { now, git }) → Promise<map | null> reads the default branch with read-only git verbs; null: not a repo / no code
|
|
9
|
+
* headOf(root, { git }) → Promise<{ ref, sha } | null> the default branch: origin/HEAD, origin/main, origin/master, main, master, HEAD
|
|
10
|
+
* read(dir) · save(dir, map) the stored map: <records>/code-map.json (derived, rewritten on each draw)
|
|
11
|
+
* describe(dir, part, text, now) → { ok, map } | { ok: false, error } the PM's own words for what a part is; '' puts PMOS's back
|
|
12
|
+
* view(dir) → the stored map with the PM's words on top (what `pmos code show` and the panel read)
|
|
13
|
+
*
|
|
14
|
+
* WHAT IT NEVER DOES. It runs only `git rev-parse`, `git ls-tree`, `git log` and `git show <sha>:<path>` (read-only); it never checks out,
|
|
15
|
+
* fetches, or writes inside the repository. The only files it writes are the two in the product's records folder.
|
|
16
|
+
*
|
|
17
|
+
* RULES (said once, here):
|
|
18
|
+
* · A part is a top-level folder holding code. A container folder (packages, apps, services, libs, modules, src, cmd, internal, components,
|
|
19
|
+
* crates, projects) opens one level down. node_modules, vendor, dist, build, coverage and dot folders are never parts.
|
|
20
|
+
* · A folder that is mostly tests (tests/, test/, spec/ …) is not a part; each test file in it counts for the part whose name appears
|
|
21
|
+
* in its path. Code files at the top level form a part "(top level)" when there are 3 or more.
|
|
22
|
+
* · At most MAX_PARTS parts, most code files first; the rest are counted in `more`.
|
|
23
|
+
* · Risky: no test files, or RISKY_FIXES or more fix commits touching the part in the last 30 days that are at least half of its
|
|
24
|
+
* commits there (a busy, well-kept part is not risky only for being busy). */
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
const { execFile } = require('child_process');
|
|
28
|
+
|
|
29
|
+
const MAP_FILE = 'code-map.json';
|
|
30
|
+
const NOTES_FILE = 'code-map-notes.jsonl';
|
|
31
|
+
const MAX_PARTS = 12;
|
|
32
|
+
const RISKY_FIXES = 5;
|
|
33
|
+
const FIX_DAYS = 30;
|
|
34
|
+
const FIX_SHARE = 0.5; // fixes must be at least half the part's commits in the window, so a busy part is not risky only for being busy
|
|
35
|
+
const MAX_TEXT = 120;
|
|
36
|
+
const DAY = 86400000;
|
|
37
|
+
const CONTAINERS = new Set(['packages', 'apps', 'services', 'libs', 'modules', 'src', 'cmd', 'internal', 'components', 'crates', 'projects']);
|
|
38
|
+
const SKIP = new Set(['node_modules', 'vendor', 'dist', 'build', 'coverage', 'out', 'target', 'tmp', '__pycache__', 'bower_components', 'third_party']);
|
|
39
|
+
const TEST_DIRS = new Set(['test', 'tests', '__tests__', 'spec', 'specs', 'e2e', 'testing']);
|
|
40
|
+
const LANG = { js: 'JavaScript', jsx: 'JavaScript', mjs: 'JavaScript', cjs: 'JavaScript', ts: 'TypeScript', tsx: 'TypeScript', py: 'Python', rb: 'Ruby',
|
|
41
|
+
go: 'Go', rs: 'Rust', java: 'Java', kt: 'Kotlin', swift: 'Swift', php: 'PHP', cs: 'C#', c: 'C', h: 'C', cc: 'C++', cpp: 'C++', hpp: 'C++',
|
|
42
|
+
scala: 'Scala', vue: 'Vue', svelte: 'Svelte', sh: 'Shell', sql: 'SQL', ex: 'Elixir', exs: 'Elixir', dart: 'Dart', m: 'Objective-C', lua: 'Lua' };
|
|
43
|
+
const FRAMEWORKS = [['next', 'Next.js'], ['react', 'React'], ['vue', 'Vue'], ['svelte', 'Svelte'], ['@angular/core', 'Angular'], ['@nestjs/core', 'NestJS'],
|
|
44
|
+
['express', 'Express'], ['fastify', 'Fastify'], ['koa', 'Koa'], ['electron', 'Electron'], ['react-native', 'React Native']];
|
|
45
|
+
const FIX_RE = /\b(fix|fixes|fixed|bug|bugfix|hotfix|regression|revert)\b/i;
|
|
46
|
+
const say = (s) => { try { console.log('[code-map] ' + s); } catch { /* no console */ } };
|
|
47
|
+
|
|
48
|
+
const extOf = (f) => { const b = f.slice(f.lastIndexOf('/') + 1); const i = b.lastIndexOf('.'); return i > 0 ? b.slice(i + 1).toLowerCase() : ''; };
|
|
49
|
+
const isCode = (f) => !!LANG[extOf(f)];
|
|
50
|
+
function isTest(f) {
|
|
51
|
+
const segs = f.split('/');
|
|
52
|
+
const base = segs[segs.length - 1];
|
|
53
|
+
if (segs.slice(0, -1).some((s) => TEST_DIRS.has(s.toLowerCase()))) return true;
|
|
54
|
+
return /[._-](test|spec)\.[a-z0-9]+$/i.test(base) || /^test_.+\.py$/i.test(base) || /_test\.(go|py|rb|exs)$/i.test(base);
|
|
55
|
+
}
|
|
56
|
+
const skipped = (f) => f.split('/').slice(0, -1).some((s) => s.startsWith('.') || SKIP.has(s));
|
|
57
|
+
|
|
58
|
+
/** The key of the part a file belongs to: 'a', 'packages/api', or '' for a top-level file. */
|
|
59
|
+
function keyOf(f, open) {
|
|
60
|
+
const segs = f.split('/');
|
|
61
|
+
if (segs.length === 1) return '';
|
|
62
|
+
if (open.has(segs[0]) && segs.length > 2) return segs[0] + '/' + segs[1];
|
|
63
|
+
return segs[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Group a repository's files into its main parts. PURE. */
|
|
67
|
+
function partsOf(files) {
|
|
68
|
+
const list = (Array.isArray(files) ? files : []).map(String).filter((f) => f && !skipped(f) && !f.split('/').pop().startsWith('.'));
|
|
69
|
+
// a container opens only when it has sub-folders with code (a flat src/ stays one part)
|
|
70
|
+
const open = new Set();
|
|
71
|
+
for (const f of list) { const s = f.split('/'); if (CONTAINERS.has(s[0]) && s.length > 2 && isCode(f)) open.add(s[0]); }
|
|
72
|
+
const by = new Map();
|
|
73
|
+
for (const f of list) {
|
|
74
|
+
const k = keyOf(f, open);
|
|
75
|
+
if (!by.has(k)) by.set(k, { name: k || '(top level)', dir: k, files: 0, code: 0, tests: 0, langs: {}, testsOutside: 0, _tests: [] });
|
|
76
|
+
const p = by.get(k);
|
|
77
|
+
p.files++;
|
|
78
|
+
if (!isCode(f)) continue;
|
|
79
|
+
if (isTest(f)) { p.tests++; p._tests.push(f); continue; }
|
|
80
|
+
p.code++;
|
|
81
|
+
const l = LANG[extOf(f)]; p.langs[l] = (p.langs[l] || 0) + 1;
|
|
82
|
+
}
|
|
83
|
+
let parts = [...by.values()];
|
|
84
|
+
// a folder that is mostly tests is not a part: its tests count for the part they name
|
|
85
|
+
const testOnly = parts.filter((p) => p.dir && TEST_DIRS.has(p.dir.split('/').pop().toLowerCase()) && p.tests > 0 && p.tests >= p.code * 4);
|
|
86
|
+
parts = parts.filter((p) => !testOnly.includes(p) && p.code > 0 && (p.dir || p.code >= 3));
|
|
87
|
+
for (const t of testOnly) for (const f of t._tests) {
|
|
88
|
+
const segs = f.toLowerCase().replace(/\.[a-z0-9]+$/, '').split(/[/._-]+/);
|
|
89
|
+
const hit = parts.find((p) => p.dir && segs.includes(p.dir.split('/').pop().toLowerCase()));
|
|
90
|
+
if (hit) { hit.tests++; hit.testsOutside++; }
|
|
91
|
+
}
|
|
92
|
+
parts.sort((a, b) => b.code - a.code || a.name.localeCompare(b.name));
|
|
93
|
+
const more = Math.max(0, parts.length - MAX_PARTS);
|
|
94
|
+
return { parts: parts.slice(0, MAX_PARTS).map(({ _tests, ...p }) => p), more };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Why a part is risky, or null. PURE. */
|
|
98
|
+
function riskOf(p) {
|
|
99
|
+
const why = [];
|
|
100
|
+
if (!p.tests) why.push('no tests');
|
|
101
|
+
if ((p.fixes || 0) >= RISKY_FIXES && (p.fixes || 0) >= (p.commits || 0) * FIX_SHARE) why.push(p.fixes + ' fixes in ' + FIX_DAYS + ' days');
|
|
102
|
+
return why.length ? why.join(', ') : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const mainLang = (langs) => Object.entries(langs || {}).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]?.[0] || '';
|
|
106
|
+
function frameworkOf(pkg) {
|
|
107
|
+
if (!pkg || typeof pkg !== 'object') return '';
|
|
108
|
+
const deps = Object.assign({}, pkg.dependencies || {}, pkg.devDependencies || {}, pkg.peerDependencies || {});
|
|
109
|
+
const hit = FRAMEWORKS.find(([n]) => Object.prototype.hasOwnProperty.call(deps, n));
|
|
110
|
+
return hit ? hit[1] : '';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The parts with what they are, how tested, who changed them last and their risk. PURE.
|
|
114
|
+
* log: [{ at, files: [path] , fix: bool }] (commits, newest first) · last: { <dir>: { by, at } } · pkgs: { <dir>: parsed package.json } */
|
|
115
|
+
function summarize({ files, log = [], last = {}, pkgs = {}, now = Date.now() } = {}) {
|
|
116
|
+
const { parts, more } = partsOf(files);
|
|
117
|
+
if (!parts.length) return null;
|
|
118
|
+
const since = now - FIX_DAYS * DAY;
|
|
119
|
+
const inPart = (p, f) => (p.dir ? f === p.dir || f.startsWith(p.dir + '/') : !f.includes('/'));
|
|
120
|
+
const out = parts.map((p) => {
|
|
121
|
+
let fixes = 0, commits = 0;
|
|
122
|
+
for (const c of log) if (Date.parse(c.at) >= since && (c.files || []).some((f) => inPart(p, f))) { commits++; if (c.fix) fixes++; }
|
|
123
|
+
const lang = mainLang(p.langs), fw = frameworkOf(pkgs[p.dir]);
|
|
124
|
+
const kind = [lang, fw].filter(Boolean).join(' · ');
|
|
125
|
+
const tested = p.tests ? p.tests + (p.tests === 1 ? ' test file' : ' test files') : 'no tests';
|
|
126
|
+
const l = last[p.dir] || null;
|
|
127
|
+
const q = { name: p.name, dir: p.dir, kind, code: p.code, tests: p.tests, tested, fixes, commits, last: l ? { by: l.by, at: l.at } : null };
|
|
128
|
+
q.why = riskOf(q);
|
|
129
|
+
q.risky = !!q.why;
|
|
130
|
+
return q;
|
|
131
|
+
});
|
|
132
|
+
return { parts: out, more };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function gitRun(root, args) {
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
execFile('git', args, { cwd: root, maxBuffer: 64 << 20, timeout: 30000, encoding: 'utf8' }, (err, out) => resolve(err ? null : out));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const READ_VERBS = new Set(['rev-parse', 'ls-tree', 'log', 'show']);
|
|
141
|
+
/** Only read-only verbs pass (N2): anything else is refused before git runs. */
|
|
142
|
+
const guarded = (git) => (root, args) => (READ_VERBS.has(args[0]) ? git(root, args) : Promise.resolve(null));
|
|
143
|
+
|
|
144
|
+
/** The default branch's commit: origin/HEAD, origin/main, origin/master, main, master, then HEAD. */
|
|
145
|
+
async function headOf(root, { git = gitRun } = {}) {
|
|
146
|
+
if (!root) return null;
|
|
147
|
+
const g = guarded(git);
|
|
148
|
+
const top = await g(root, ['rev-parse', '--show-toplevel']);
|
|
149
|
+
if (!top) return null;
|
|
150
|
+
for (const ref of ['origin/HEAD', 'origin/main', 'origin/master', 'main', 'master', 'HEAD']) {
|
|
151
|
+
const sha = await g(root, ['rev-parse', '--verify', '-q', ref + '^{commit}']);
|
|
152
|
+
if (sha && /^[0-9a-f]{7,64}$/.test(sha.trim())) return { ref, sha: sha.trim(), top: top.trim() };
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Draw the map from the default branch. null when `root` is not a git repository or holds no code (N1). */
|
|
158
|
+
async function build(root, { now = Date.now(), git = gitRun } = {}) {
|
|
159
|
+
const g = guarded(git);
|
|
160
|
+
const head = await headOf(root, { git });
|
|
161
|
+
if (!head) return null;
|
|
162
|
+
const top = head.top;
|
|
163
|
+
const ls = await g(top, ['ls-tree', '-r', '--name-only', '-z', head.sha]);
|
|
164
|
+
if (ls == null) return null;
|
|
165
|
+
const files = ls.split('\0').filter(Boolean);
|
|
166
|
+
const { parts } = partsOf(files);
|
|
167
|
+
if (!parts.length) return null;
|
|
168
|
+
// fix commits in the window, with their files
|
|
169
|
+
const sinceIso = new Date(now - FIX_DAYS * DAY).toISOString();
|
|
170
|
+
const raw = (await g(top, ['log', head.sha, '--no-merges', '--since=' + sinceIso, '-n', '3000', '--format=%x1e%aI%x1f%s', '--name-only'])) || '';
|
|
171
|
+
const log = [];
|
|
172
|
+
for (const chunk of raw.split('\x1e')) {
|
|
173
|
+
if (!chunk.trim()) continue;
|
|
174
|
+
const [first, ...rest] = chunk.split('\n');
|
|
175
|
+
const [at, subject] = first.split('\x1f');
|
|
176
|
+
log.push({ at, fix: FIX_RE.test(subject || ''), files: rest.map((s) => s.trim()).filter(Boolean) });
|
|
177
|
+
}
|
|
178
|
+
// who changed each part last
|
|
179
|
+
const last = {};
|
|
180
|
+
for (const p of parts) {
|
|
181
|
+
const out = await g(top, ['log', '-1', '--format=%an%x1f%aI', head.sha, '--', p.dir || '.']);
|
|
182
|
+
if (out && out.trim()) { const [by, at] = out.trim().split('\x1f'); last[p.dir] = { by, at }; }
|
|
183
|
+
}
|
|
184
|
+
// a framework the part's own package.json names
|
|
185
|
+
const pkgs = {};
|
|
186
|
+
const have = new Set(files);
|
|
187
|
+
for (const p of parts) {
|
|
188
|
+
const f = p.dir ? p.dir + '/package.json' : 'package.json';
|
|
189
|
+
if (!have.has(f)) continue;
|
|
190
|
+
const txt = await g(top, ['show', head.sha + ':' + f]);
|
|
191
|
+
try { pkgs[p.dir] = JSON.parse(txt); } catch { /* not JSON */ }
|
|
192
|
+
}
|
|
193
|
+
const map = summarize({ files, log, last, pkgs, now });
|
|
194
|
+
if (!map) return null;
|
|
195
|
+
const out = Object.assign({ at: new Date(now).toISOString(), ref: head.ref, head: head.sha }, map);
|
|
196
|
+
say(`drew ${out.parts.length} parts (${out.parts.filter((p) => p.risky).length} risky) from ${head.ref} ${head.sha.slice(0, 7)}`);
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const fileIn = (dir, f) => (dir ? path.join(dir, f) : null);
|
|
201
|
+
function read(dir) {
|
|
202
|
+
try { const m = JSON.parse(fs.readFileSync(fileIn(dir, MAP_FILE), 'utf8')); return m && Array.isArray(m.parts) ? m : null; } catch { return null; }
|
|
203
|
+
}
|
|
204
|
+
function save(dir, map) {
|
|
205
|
+
if (!dir || !map) return false;
|
|
206
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
207
|
+
const f = fileIn(dir, MAP_FILE), tmp = f + '.' + process.pid + '.tmp';
|
|
208
|
+
fs.writeFileSync(tmp, JSON.stringify(map, null, 1) + '\n');
|
|
209
|
+
fs.renameSync(tmp, f);
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
/** The PM's words per part: the latest line for each part wins; '' means PMOS's words again. */
|
|
213
|
+
function notesOf(dir) {
|
|
214
|
+
const out = {};
|
|
215
|
+
let txt = '';
|
|
216
|
+
try { txt = fs.readFileSync(fileIn(dir, NOTES_FILE), 'utf8'); } catch { return out; }
|
|
217
|
+
for (const l of txt.split('\n')) {
|
|
218
|
+
if (!l.trim()) continue;
|
|
219
|
+
try { const o = JSON.parse(l); if (o && typeof o.part === 'string') { if (o.text) out[o.part] = o.text; else delete out[o.part]; } } catch { /* a torn line */ }
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
const oneLine = (v) => { const s = String(v == null ? '' : v).replace(/\s+/g, ' ').trim(); return s.length > MAX_TEXT ? s.slice(0, MAX_TEXT - 1).trimEnd() + '…' : s; };
|
|
224
|
+
/** Find a part by its name, its folder or the folder's last segment (case does not matter). */
|
|
225
|
+
function findPart(map, name) {
|
|
226
|
+
const n = String(name || '').trim().toLowerCase();
|
|
227
|
+
if (!map || !n) return null;
|
|
228
|
+
return map.parts.find((p) => p.name.toLowerCase() === n || (p.dir || '').toLowerCase() === n)
|
|
229
|
+
|| map.parts.find((p) => (p.dir || '').split('/').pop().toLowerCase() === n) || null;
|
|
230
|
+
}
|
|
231
|
+
function view(dir) {
|
|
232
|
+
const map = read(dir);
|
|
233
|
+
if (!map) return null;
|
|
234
|
+
const notes = notesOf(dir);
|
|
235
|
+
return Object.assign({}, map, { parts: map.parts.map((p) => (notes[p.dir] ? Object.assign({}, p, { note: notes[p.dir] }) : p)) });
|
|
236
|
+
}
|
|
237
|
+
function describe(dir, name, text, now = Date.now()) {
|
|
238
|
+
const map = read(dir);
|
|
239
|
+
if (!map) return { ok: false, error: 'there is no code map yet: run pmos code map first' };
|
|
240
|
+
const p = findPart(map, name);
|
|
241
|
+
if (!p) return { ok: false, error: `the map has no part "${name}". Parts: ${map.parts.map((x) => x.name).join(', ')}` };
|
|
242
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
243
|
+
fs.appendFileSync(fileIn(dir, NOTES_FILE), JSON.stringify({ at: new Date(now).toISOString(), part: p.dir, text: oneLine(text) }) + '\n');
|
|
244
|
+
return { ok: true, part: p.name, map: view(dir) };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
module.exports = { partsOf, summarize, riskOf, build, headOf, read, save, view, describe, findPart, isTest, MAP_FILE, NOTES_FILE, MAX_PARTS, RISKY_FIXES, FIX_DAYS, FIX_SHARE };
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
{"id": "parked", "audience": "user", "status": "ga", "group": "Catch up", "name": "Parked work", "say": "Each initiative on hold, why it is parked and what brings it back.", "cmd": "/parked", "verb": "parked", "sub": "list", "phrases": ["parked work", "what is on hold", "what is parked", "paused initiatives"], "since": "0.700.0"},
|
|
17
17
|
{"id": "people", "audience": "user", "status": "ga", "group": "Catch up", "name": "People you work with", "say": "Each person with their role, how often you talk and their tone.", "cmd": "/people", "verb": "people", "sub": "list", "phrases": ["who do I work with", "stakeholders list", "people on this", "who is involved"], "since": "0.610.0"},
|
|
18
18
|
{"id": "strategy", "audience": "user", "status": "ga", "group": "Your product", "name": "Five-line strategy", "say": "Who it is for, the problem, the bet, how you win and what you will not do.", "cmd": "/strategy", "verb": "strategy", "sub": "show", "place": "board", "phrases": ["our strategy", "product strategy", "draft the strategy", "how we win"], "since": "0.776.0"},
|
|
19
|
+
{"id": "code", "audience": "user", "status": "ga", "group": "Your product", "name": "Code map", "say": "One line per main part of the code: what it is, how it is tested, who changed it last.", "cmd": "/code", "verb": "code", "sub": "show", "place": "board", "since": "0.826.0"},
|
|
20
|
+
{"id": "connectors", "audience": "user", "status": "ga", "group": "Your product", "name": "What connectors read and write", "say": "What PMOS reads and writes through each connector, and what leaves this computer.", "cmd": "/connectors", "verb": "connectors", "sub": "data", "since": "0.825.0"},
|
|
19
21
|
{"id": "positioning", "audience": "user", "status": "ga", "group": "Your product", "name": "Positioning and key messages", "say": "A positioning statement and key messages, each citing a strategy line.", "cmd": "/positioning", "verb": "positioning", "sub": "list", "phrases": ["positioning statement", "key messages", "messaging for"], "since": "0.740.0"},
|
|
20
22
|
{"id": "principles", "audience": "user", "status": "ga", "group": "Your product", "name": "Product principles", "say": "Four to six principles drafted from your past decisions, each citing them.", "cmd": "/principles", "verb": "principles", "sub": "list", "phrases": ["product principles", "our principles", "design principles for"], "since": "0.720.0"},
|
|
21
23
|
{"id": "glossary", "audience": "user", "status": "ga", "group": "Your product", "name": "Glossary", "say": "The product's own words; every page shows a word's meaning on hover.", "cmd": "/glossary", "verb": "glossary", "sub": "list", "hint": "<word>", "phrases": ["define the word", "glossary", "add to glossary", "meaning of the word"], "since": "0.690.0"},
|
|
@@ -26,6 +28,61 @@
|
|
|
26
28
|
{"id": "describe", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Task descriptions", "say": "What, why and done-when for each task, drafted from its sources.", "cmd": "/describe", "verb": "task", "sub": "describe", "hint": "<task>", "place": "board", "phrases": ["describe this task", "task description", "write the description", "what is this task about"], "since": "0.770.0"},
|
|
27
29
|
{"id": "search", "audience": "user", "status": "ga", "group": "Find your way", "name": "Search and ask", "say": "Ctrl+K finds work, pages and features, and answers questions from your files.", "keys": "Ctrl K", "since": "0.737.0"},
|
|
28
30
|
{"id": "action-keys", "audience": "user", "status": "ga", "group": "Find your way", "name": "Keys for the five common actions", "say": "Yes, open, next sprint, park and undo, one key each. Press ? to see them.", "keys": "?", "since": "0.730.0"},
|
|
29
|
-
{"id": "guide", "audience": "user", "status": "ga", "group": "Find your way", "name": "The Guide", "say": "How each part of PMOS works, page by page.", "action": "guide", "since": "0.500.0"}
|
|
31
|
+
{"id": "guide", "audience": "user", "status": "ga", "group": "Find your way", "name": "The Guide", "say": "How each part of PMOS works, page by page.", "action": "guide", "since": "0.500.0"},
|
|
32
|
+
{"id": "initiative", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Make and order initiatives", "say": "Start an initiative and put it in Now, Next or Later on the roadmap.", "cmd": "/initiative", "verb": "initiative", "hint": "<title>"},
|
|
33
|
+
{"id": "measure", "audience": "user", "status": "ga", "group": "Your product", "name": "Record a measured value", "say": "Write down a KR or health number with where it came from.", "cmd": "/measure", "verb": "measure", "hint": "<kr> <value>"},
|
|
34
|
+
{"id": "today", "audience": "user", "status": "ga", "group": "Catch up", "name": "What needs you today", "say": "The asks that need you, in the order Today shows them.", "cmd": "/today", "verb": "today"},
|
|
35
|
+
{"id": "pick", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Pick one thing for the time you have", "say": "Say how many minutes you have; PMOS picks the one ask that fits and unblocks the most.", "cmd": "/pick", "verb": "pick", "hint": "--minutes <n>"},
|
|
36
|
+
{"id": "board", "audience": "user", "status": "ga", "group": "Catch up", "name": "Every initiative's items", "say": "The items of every initiative by column, or only yours.", "cmd": "/board", "verb": "board"},
|
|
37
|
+
{"id": "report", "audience": "user", "status": "ga", "group": "Your product", "name": "Draft and issue a report", "say": "Draft a cadence report with every number filled in, then issue it.", "cmd": "/report", "verb": "report", "hint": "<cadence>"},
|
|
38
|
+
{"id": "jira", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Jira tickets from the spec", "say": "Draft Jira tickets from the PRD, approve them and see their status.", "cmd": "/jira", "verb": "jira"},
|
|
39
|
+
{"id": "docs", "audience": "user", "status": "ga", "group": "Your product", "name": "Linked documents in step", "say": "Is each linked document the same as, ahead of or behind its Google Docs or Confluence copy.", "cmd": "/docs", "verb": "docs"},
|
|
40
|
+
{"id": "signoff", "audience": "user", "status": "ga", "group": "Before you ship", "name": "Sign-offs", "say": "Ask for, answer and list the sign-offs an initiative waits on.", "cmd": "/signoff", "verb": "signoff", "hint": "<initiative>"},
|
|
41
|
+
{"id": "my-work", "audience": "user", "status": "ga", "group": "Catch up", "name": "Your assigned work", "say": "The Jira tickets and plan items assigned to you, ranked.", "cmd": "/my-work", "verb": "my-work"},
|
|
42
|
+
{"id": "tracker", "audience": "user", "status": "ga", "group": "Catch up", "name": "When the tracker was last read", "say": "When tracker items were last read and how much matches the last Jira read.", "cmd": "/tracker", "verb": "tracker"},
|
|
43
|
+
{"id": "mention", "audience": "user", "status": "ga", "group": "Catch up", "name": "Mentions that wait on you", "say": "What waits on you in your tools, with a reply PMOS drafts for you to send.", "cmd": "/mention", "verb": "mention"},
|
|
44
|
+
{"id": "workflow", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Workflows", "say": "The workflows of this product, a new workflow draft, and moving an initiative to another one.", "cmd": "/workflow", "verb": "workflow"},
|
|
45
|
+
{"id": "blueprint", "audience": "user", "status": "ga", "group": "Your product", "name": "Every feature and its state", "say": "Every feature of the product with a status worked out from its evidence.", "cmd": "/blueprint", "verb": "blueprint"},
|
|
46
|
+
{"id": "program", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Programs", "say": "Make and change programs: charter, milestones, order, capacity and steering.", "cmd": "/program", "verb": "program"},
|
|
47
|
+
{"id": "extension", "audience": "user", "status": "ga", "group": "Find your way", "name": "Google Meet extension", "say": "The folder of the Chrome extension for Google Meet and the three steps to load it.", "cmd": "/extension", "verb": "extension"},
|
|
48
|
+
{"id": "team", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "The role agents", "say": "Who owns what among the role agents, what each works on, and pause or resume them.", "cmd": "/team", "verb": "team"},
|
|
49
|
+
{"id": "improve", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "What PMOS learned", "say": "What the improvement loop found, what it learned and what waits for you.", "cmd": "/improve", "verb": "improve"},
|
|
50
|
+
{"id": "ai", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "AI jobs and their switch", "say": "Each AI job, its off switch and what it did.", "cmd": "/ai", "verb": "ai"},
|
|
51
|
+
{"id": "grill", "audience": "user", "status": "ga", "group": "Before you ship", "name": "Grill settings", "say": "When PMOS grills a spec and what it may spend.", "cmd": "/grill", "verb": "grill"},
|
|
52
|
+
{"id": "design", "audience": "user", "status": "ga", "group": "Your product", "name": "Design drift", "say": "Which pages are built from your design system and which drift from it.", "cmd": "/design", "verb": "design"},
|
|
53
|
+
{"id": "pages", "audience": "user", "status": "ga", "group": "Your product", "name": "Pages that keep breaking", "say": "Each page's fixes, reverts and restores in the last 14 days.", "cmd": "/pages", "verb": "pages"},
|
|
54
|
+
{"id": "away", "audience": "user", "status": "ga", "group": "Catch up", "name": "Away days", "say": "Set your away days, read the handover note and see what moved while you were away.", "cmd": "/away", "verb": "away"},
|
|
55
|
+
{"id": "try", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "Try what shipped", "say": "The changes your recent updates brought, how to try each, and your answer.", "cmd": "/try", "verb": "try"},
|
|
56
|
+
{"id": "rules", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "Rules PMOS learned", "say": "The standing rules PMOS learned from your corrections, and edit or retire one.", "cmd": "/rules", "verb": "rules"},
|
|
57
|
+
{"id": "line", "audience": "user", "status": "ga", "group": "Catch up", "name": "Where each initiative stands", "say": "Days in its stage, what is missing, the next move, and whether it is stuck.", "cmd": "/line", "verb": "line", "hint": "<initiative>"},
|
|
58
|
+
{"id": "hire", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The next hire", "say": "The role your open work most needs, and a one-page role brief to edit.", "cmd": "/hire", "verb": "hire"},
|
|
59
|
+
{"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>"},
|
|
60
|
+
{"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"},
|
|
61
|
+
{"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"},
|
|
62
|
+
{"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"},
|
|
63
|
+
{"id": "quiet", "audience": "user", "status": "ga", "group": "Catch up", "name": "Quiet initiatives", "say": "The weekly sweep of initiatives quiet 30 days or more: keep, park or close each.", "cmd": "/quiet", "verb": "quiet"},
|
|
64
|
+
{"id": "units", "audience": "user", "status": "ga", "group": "Your product", "name": "Programs, products and projects", "say": "Who owns each initiative, and each owner's brief.", "cmd": "/units", "verb": "units"},
|
|
65
|
+
{"id": "owner", "audience": "user", "status": "ga", "group": "Your product", "name": "An owner's brief", "say": "A unit owner's daily brief now.", "cmd": "/owner", "verb": "owner", "hint": "<unit>"},
|
|
66
|
+
{"id": "driver", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "The Initiative Driver", "say": "What the Driver changed with Undo and what waits for you.", "cmd": "/driver", "verb": "driver"},
|
|
67
|
+
{"id": "setup", "audience": "user", "status": "ga", "group": "Find your way", "name": "Set up a new product", "say": "The tracker read, an agreed goal and an owner for a new product.", "cmd": "/setup", "verb": "setup"},
|
|
68
|
+
{"id": "loop", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "A goal agents work on", "say": "Start, check and stop a goal agents work on until it is done.", "cmd": "/loop", "verb": "loop"},
|
|
69
|
+
{"id": "scan", "audience": "user", "status": "ga", "group": "Catch up", "name": "Horizon scan", "say": "The portfolio watch list and what the scan found.", "cmd": "/scan", "verb": "scan"},
|
|
70
|
+
{"id": "artefacts", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The seven artefacts", "say": "Intent, Goal, Narrative, Experiment, Specimens, Done test and Lessons of an initiative.", "cmd": "/artefacts", "verb": "artefacts", "hint": "<initiative>"},
|
|
71
|
+
{"id": "forecast", "audience": "user", "status": "ga", "group": "Your product", "name": "Goal forecasts", "say": "A goal forecast's kept baseline, and the forecasts that turned.", "cmd": "/forecast", "verb": "forecast"},
|
|
72
|
+
{"id": "git-identity", "audience": "user", "status": "ga", "group": "Find your way", "name": "Your git identity", "say": "Which git identity and GitHub login this repository uses.", "cmd": "/git-identity", "verb": "git-identity"},
|
|
73
|
+
{"id": "signal", "audience": "user", "status": "ga", "group": "Your product", "name": "Customer signals", "say": "The customer signals behind each roadmap item.", "cmd": "/signal", "verb": "signal", "hint": "<item>"},
|
|
74
|
+
{"id": "launcher", "audience": "user", "status": "ga", "group": "Find your way", "name": "Start without a terminal", "say": "A PMOS app and a login item, so the workspace starts by itself.", "cmd": "/launcher", "verb": "launcher"},
|
|
75
|
+
{"id": "verify-work", "audience": "agent", "status": "ga", "group": "What PMOS did", "name": "Mark integrated work", "say": "A build run marks work items integrated from the default branch.", "cmd": "/verify-work", "verb": "verify-work"},
|
|
76
|
+
{"id": "build", "audience": "agent", "status": "ga", "group": "What PMOS did", "name": "The Builder", "say": "A declared work item becomes a pull request; the factory's runs use it.", "cmd": "/build", "verb": "build"},
|
|
77
|
+
{"id": "calendar", "audience": "agent", "status": "ga", "group": "Catch up", "name": "Saved calendar events", "say": "An agent session saves the calendar events it read for Briefing.", "cmd": "/calendar", "verb": "calendar"},
|
|
78
|
+
{"id": "source", "audience": "agent", "status": "ga", "group": "Catch up", "name": "Stored tool reads", "say": "An agent session saves its read of a tool for the Briefing.", "cmd": "/source", "verb": "source"},
|
|
79
|
+
{"id": "refresh", "audience": "agent", "status": "ga", "group": "Catch up", "name": "Read only what changed", "say": "An agent session asks a tool what changed since the last read.", "cmd": "/refresh", "verb": "refresh"},
|
|
80
|
+
{"id": "lead", "audience": "agent", "status": "ga", "group": "Catch up", "name": "A popup's lead", "say": "PMOS writes a popup's short lead ahead, from stored reads.", "cmd": "/lead", "verb": "lead"},
|
|
81
|
+
{"id": "propose", "audience": "agent", "status": "ga", "group": "What PMOS did", "name": "File a suggestion", "say": "A PMOS run files what it found under an initiative's ✦ for you to keep or drop.", "cmd": "/propose", "verb": "propose"},
|
|
82
|
+
{"id": "lab", "audience": "agent", "status": "ga", "group": "What PMOS did", "name": "The idle lab", "say": "What the idle lab's runs read and filed while you were away.", "cmd": "/lab", "verb": "lab"},
|
|
83
|
+
{"id": "metrics", "audience": "agent", "status": "ga", "group": "Your product", "name": "Metric drafts", "say": "A metric-draft run files a metric for you to keep or drop.", "cmd": "/metrics", "verb": "metrics"},
|
|
84
|
+
{"id": "impact", "audience": "agent", "status": "ga", "group": "Your product", "name": "Impact findings", "say": "An impact run files a finding for you to check.", "cmd": "/impact", "verb": "impact"},
|
|
85
|
+
{"id": "coredoc", "audience": "agent", "status": "ga", "group": "Plan and decide", "name": "Core document drafts", "say": "A run writes one draft of a core document; you issue it on the page.", "cmd": "/coredoc", "verb": "coredoc"},
|
|
86
|
+
{"id": "mcp", "audience": "agent", "status": "ga", "group": "Find your way", "name": "PMOS cards for other agents", "say": "PMOS cards for another agent, over MCP.", "cmd": "/mcp-cards", "verb": "mcp"}
|
|
30
87
|
]
|
|
31
88
|
}
|
|
@@ -184,6 +184,9 @@ const VERBS = Object.freeze({
|
|
|
184
184
|
// Not a pm-os-absorb verb (run: null): initiative positioning-draft (idea A328) added it through the same table.
|
|
185
185
|
positioning: Object.freeze({ module: 'positioning-cli.js', run: null, guide: 'cli.md',
|
|
186
186
|
help: 'pmos positioning strategy|list|keep|drop — the product\'s positioning and key messages, each citing its strategy lines (pmos positioning help)' }),
|
|
187
|
+
// Not a pm-os-absorb verb (run: null): initiative code-map (idea A176) added it through the same table.
|
|
188
|
+
code: Object.freeze({ module: 'code-map-cli.js', run: null, guide: 'cli.md',
|
|
189
|
+
help: 'pmos code show|map|describe|count — the product\'s code map: one line per main part, what it is, how it is tested, who changed it last (pmos code help)' }),
|
|
187
190
|
// Not a pm-os-absorb verb (run: null): initiative strategy-draft (Wawan 2026-11-24) added it through the same table.
|
|
188
191
|
strategy: Object.freeze({ module: 'strategy-cli.js', run: null, guide: 'cli.md',
|
|
189
192
|
help: 'pmos strategy show|sources|draft|set|undo — the product\'s five-line strategy; PMOS drafts blank lines from the product\'s files, each citing them (pmos strategy help)' }),
|
|
@@ -151,6 +151,7 @@ const MODULES = Object.freeze([
|
|
|
151
151
|
'routes-strategy-card', // bet A458: a product's five-line strategy above its Board, and the gentle "doesn't fit" note on new work (records strategy-card.jsonl; page-press POST)
|
|
152
152
|
'routes-principles', // bet A352: a product's principles drafted from its decisions, kept or dropped on the Board (records principles.jsonl; page-press POST)
|
|
153
153
|
'routes-prefs', // bet A461: view preferences that follow the person to the phone and other browsers (runtime view-prefs.json; page-press POST)
|
|
154
|
+
'routes-code-map', // idea A176: the product's code map on Work, redrawn when the default branch moves (records code-map.json; read-only)
|
|
154
155
|
'routes-live-rows', // bet A458: chat-made task changes streamed to open pages (runtime live-events.jsonl; read-only event stream)
|
|
155
156
|
'routes-connector-data', // connector-data (A150): what each connector reads and writes, from lib/connector-data.js (read only)
|
|
156
157
|
]);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-code-map.js — the product's code map over HTTP, for the Code panel on Work (idea A176, initiative code-map). The map and its rules
|
|
3
|
+
* are lib/code-map.js; the files are code-map.json and code-map-notes.jsonl in the product's records folder (lib/records-dir.js).
|
|
4
|
+
*
|
|
5
|
+
* GET /api/code-map?ws=<id> → { ok, map, building } map: the stored map with the PM's words on top, or null (no repository, no code,
|
|
6
|
+
* or not drawn yet); building: a redraw runs now
|
|
7
|
+
*
|
|
8
|
+
* REDRAWN ON MERGES. The GET answers from the stored map at once and never waits for git (page-open-speed). Behind it, at most once a
|
|
9
|
+
* minute per product, it reads the default branch's commit (lib/code-map.js headOf); when there is no map yet (a repository was just added)
|
|
10
|
+
* or the branch has moved past the map's commit (a merge), it draws the map again, one draw at a time per product. The panel reads again
|
|
11
|
+
* while `building` is true.
|
|
12
|
+
*
|
|
13
|
+
* READ ONLY. There is no write route: the PM's words for a part come through `pmos code describe` (the chat runs it), which writes the same
|
|
14
|
+
* notes file this route reads. Nothing is sent anywhere, and nothing in the repository is written. */
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const CM = require('./code-map.js');
|
|
17
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
18
|
+
|
|
19
|
+
const CHECK_MS = 60000;
|
|
20
|
+
const CHECKOUT = path.join(__dirname, '..', '..');
|
|
21
|
+
function wsOf(ctx, ws) { try { return ctx && typeof ctx.getWs === 'function' ? ctx.getWs(ws || null) : null; } catch { return null; } }
|
|
22
|
+
const rootFor = (ctx, w) => (ctx && ctx.repoRoot) || (w && w.root) || CHECKOUT;
|
|
23
|
+
|
|
24
|
+
/** One checker per server: per product root, the last check time and the draw in flight. */
|
|
25
|
+
function createChecker({ build = CM.build, headOf = CM.headOf, clock = () => Date.now(), every = CHECK_MS } = {}) {
|
|
26
|
+
const lastAt = new Map(), running = new Map();
|
|
27
|
+
let draws = 0;
|
|
28
|
+
function check(root, dir) {
|
|
29
|
+
if (running.has(root)) return running.get(root);
|
|
30
|
+
const t = clock();
|
|
31
|
+
if (lastAt.has(root) && t - lastAt.get(root) < every) return null;
|
|
32
|
+
lastAt.set(root, t);
|
|
33
|
+
const p = (async () => {
|
|
34
|
+
try {
|
|
35
|
+
const head = await headOf(root);
|
|
36
|
+
if (!head) return false; // not a repository (N1): nothing to draw
|
|
37
|
+
const have = CM.read(dir);
|
|
38
|
+
if (have && have.head === head.sha) return false; // the branch has not moved
|
|
39
|
+
draws++;
|
|
40
|
+
const map = await build(root);
|
|
41
|
+
if (!map) return false; // a repository with no code (N1)
|
|
42
|
+
CM.save(dir, map);
|
|
43
|
+
return true;
|
|
44
|
+
} catch { return false; } finally { running.delete(root); }
|
|
45
|
+
})();
|
|
46
|
+
running.set(root, p);
|
|
47
|
+
return p;
|
|
48
|
+
}
|
|
49
|
+
return { check, running: (root) => running.has(root), draws: () => draws };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let shared = null;
|
|
53
|
+
const checkerFor = (ctx) => (ctx && ctx.codeMapChecker) || (shared = shared || createChecker());
|
|
54
|
+
|
|
55
|
+
async function handle(req, res, url, ctx) {
|
|
56
|
+
if (url.pathname !== '/api/code-map') return false;
|
|
57
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
58
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'GET' });
|
|
59
|
+
const ws = url.searchParams.get('ws') || null;
|
|
60
|
+
const dir = recordsDirFor(ctx, ws), root = rootFor(ctx, wsOf(ctx, ws));
|
|
61
|
+
const checker = checkerFor(ctx);
|
|
62
|
+
checker.check(root, dir);
|
|
63
|
+
return send(200, { ok: true, map: CM.view(dir), building: checker.running(root) });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { prefixes: ['/api/code-map'], handle, createChecker, CHECK_MS };
|
|
@@ -15,8 +15,9 @@ const path = require('path');
|
|
|
15
15
|
const today = require('./today.js');
|
|
16
16
|
|
|
17
17
|
module.exports = {
|
|
18
|
-
prefixes: ['/api/today'],
|
|
18
|
+
prefixes: ['/api/today', '/api/today-order'],
|
|
19
19
|
handle: async (req, res, url, ctx) => {
|
|
20
|
+
if (url.pathname === '/api/today-order') return require('./today-order.js').handle(req, res, url, ctx);
|
|
20
21
|
if (url.pathname !== '/api/today') return false;
|
|
21
22
|
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
22
23
|
const w = ctx.getWs(url.searchParams.get('ws'));
|
|
@@ -15,7 +15,7 @@ const { execFileSync } = require('child_process');
|
|
|
15
15
|
const today = require('./today.js');
|
|
16
16
|
const { parseArgs } = require('./schedule-cli');
|
|
17
17
|
|
|
18
|
-
const COMMANDS = { today: [] };
|
|
18
|
+
const COMMANDS = { today: ['order'] };
|
|
19
19
|
const USAGE = [
|
|
20
20
|
'usage: pmos today [--ws <id>] [--json]',
|
|
21
21
|
' pmos today --root <dir> [--json] [--wait]',
|
|
@@ -27,6 +27,7 @@ const USAGE = [
|
|
|
27
27
|
'repair). It does not read sessions then.',
|
|
28
28
|
'Without a server it reads the initiative records first when there are up to 100. With more, the Cycle review and',
|
|
29
29
|
'missing-anchor cards show as pending: add --wait to read them now (about 5 s for 500 records).',
|
|
30
|
+
'pmos today order [--pin <kind>|<blocks>] [--unpin] [--json]: the order of Today\'s blocks, and the pin Today reads (lib/today-order.js).',
|
|
30
31
|
];
|
|
31
32
|
const BOOL = new Set(['json', 'help', 'wait']);
|
|
32
33
|
const VALUE = new Set(['ws', 'root']);
|
|
@@ -118,7 +119,8 @@ function print(say, out, { sessions }) {
|
|
|
118
119
|
if (!sessions) say('No server is running, so waiting sessions were not read.');
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
async function run(argv, { say, call }) {
|
|
122
|
+
async function run(argv, { say, call, runtimeDir }) {
|
|
123
|
+
if (argv[1] === 'order') return require('./today-order.js').run(argv.slice(1), { say, runtimeDir }); // today-order (A310): the pin
|
|
122
124
|
const rest = []; const bools = {};
|
|
123
125
|
for (const a of argv.slice(1)) {
|
|
124
126
|
if (a.startsWith('--') && BOOL.has(a.slice(2))) bools[a.slice(2)] = true;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* today-order.js — Today rearranges to the day (idea A310, job #1914; board BatchMoreBDS panel 30; done test
|
|
3
|
+
* planning/done-tests/today-order.md). The pin: the one store the page and `pmos today order` read and write.
|
|
4
|
+
*
|
|
5
|
+
* public/pm/today-order.js decides the order from the calendar and what ships (pure; the page and this file import it). This file keeps
|
|
6
|
+
* only the PIN: an order the PM keeps until they unpin it. One small file, <runtime>/today-order/pin.json:
|
|
7
|
+
* { order: [block, …], kind: launch | meetings | monday | friday | own, at }
|
|
8
|
+
* It holds block names and a time only. A pin is repaired on read (whole()): an unknown block is left out and a missing one is put back,
|
|
9
|
+
* so a block never disappears from Today.
|
|
10
|
+
*
|
|
11
|
+
* read(runtimeDir) → { ok, pin: { order, kind, at } | null }
|
|
12
|
+
* pin(runtimeDir, { order, kind }, now) → { ok, pin } | { ok: false, error } (async: it reads the block names from the page module)
|
|
13
|
+
* unpin(runtimeDir) → { ok, pin: null }
|
|
14
|
+
* handle(req, res, url, ctx) GET /api/today-order → read; POST /api/today-order { order, kind } | { unpin: true } (page press)
|
|
15
|
+
* run(argv, { say, runtimeDir }) `pmos today order [--pin <a,b,c,d>|--pin <kind>] [--unpin] [--json]`
|
|
16
|
+
* SINGLE WRITER: put() writes the file, by a rename, so a half-written pin is never read. Each pin and unpin logs one `[today-order]` line.
|
|
17
|
+
*/
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const { pathToFileURL } = require('url');
|
|
21
|
+
|
|
22
|
+
const TAG = '[today-order]';
|
|
23
|
+
let MOD = null;
|
|
24
|
+
/** The page's pure module (BLOCKS, ORDERS, LABEL, whole): one source for the blocks and the day's orders. */
|
|
25
|
+
const mod = async () => (MOD = MOD || await import(pathToFileURL(path.join(__dirname, '..', 'public', 'pm', 'today-order.js')).href));
|
|
26
|
+
|
|
27
|
+
const fileOf = (rt) => path.join(rt, 'today-order', 'pin.json');
|
|
28
|
+
function put(rt, v) {
|
|
29
|
+
const f = fileOf(rt);
|
|
30
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
31
|
+
if (v == null) { try { fs.unlinkSync(f); } catch { /* already unpinned */ } return; }
|
|
32
|
+
const tmp = f + '.' + process.pid + '.tmp';
|
|
33
|
+
fs.writeFileSync(tmp, JSON.stringify(v) + '\n');
|
|
34
|
+
fs.renameSync(tmp, f);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function read(rt) {
|
|
38
|
+
if (!rt) return { ok: true, pin: null };
|
|
39
|
+
let v = null;
|
|
40
|
+
try { v = JSON.parse(fs.readFileSync(fileOf(rt), 'utf8')); } catch { return { ok: true, pin: null }; }
|
|
41
|
+
if (!v || !Array.isArray(v.order)) return { ok: true, pin: null };
|
|
42
|
+
return { ok: true, pin: { order: v.order.filter((x) => typeof x === 'string').slice(0, 8), kind: typeof v.kind === 'string' ? v.kind : 'own', at: typeof v.at === 'string' ? v.at : '' } };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function pin(rt, body = {}, now = new Date()) {
|
|
46
|
+
const M = await mod();
|
|
47
|
+
if (!rt) return { ok: false, error: 'no runtime folder to keep the pin in' };
|
|
48
|
+
const kind = body.kind == null || body.kind === '' ? 'own' : String(body.kind);
|
|
49
|
+
if (!M.KINDS.includes(kind)) return { ok: false, error: `${kind} is not a kind of day: ${M.KINDS.join(', ')}` };
|
|
50
|
+
const given = Array.isArray(body.order) ? body.order : kind !== 'own' ? M.ORDERS[kind] : null;
|
|
51
|
+
if (!given || !given.length) return { ok: false, error: 'name the order to pin: the blocks ' + M.BLOCKS.join(', ') + ', or a kind of day' };
|
|
52
|
+
const bad = given.find((b) => !M.BLOCKS.includes(b));
|
|
53
|
+
if (bad) return { ok: false, error: `${bad} is not a block of Today: ${M.BLOCKS.join(', ')}` };
|
|
54
|
+
const v = { order: M.whole(given), kind, at: now.toISOString() };
|
|
55
|
+
put(rt, v);
|
|
56
|
+
console.info(`${TAG} pinned kind=${kind} order=${v.order.join(',')}`);
|
|
57
|
+
return { ok: true, pin: v };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function unpin(rt) {
|
|
61
|
+
if (!rt) return { ok: false, error: 'no runtime folder to keep the pin in' };
|
|
62
|
+
put(rt, null);
|
|
63
|
+
console.info(`${TAG} unpinned`);
|
|
64
|
+
return { ok: true, pin: null };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** GET /api/today-order and POST /api/today-order (routes-today.js hands it on). A POST is a page press. */
|
|
68
|
+
async function handle(req, res, url, ctx) {
|
|
69
|
+
if (url.pathname !== '/api/today-order') return false;
|
|
70
|
+
const rt = ctx.runtimeDir;
|
|
71
|
+
if (req.method === 'GET') { ctx.json(res, read(rt)); return true; }
|
|
72
|
+
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'GET or POST only' }, 405); return true; }
|
|
73
|
+
const got = await ctx.readJson(req);
|
|
74
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
|
|
75
|
+
const body = got.body || {};
|
|
76
|
+
const g = require('./pm-guard.js').requirePagePress(req, body);
|
|
77
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
78
|
+
const out = body.unpin === true ? unpin(rt) : await pin(rt, body);
|
|
79
|
+
ctx.json(res, out, out.ok ? 200 : 400);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const USAGE = [
|
|
84
|
+
'usage: pmos today order [--json]',
|
|
85
|
+
' pmos today order --pin <kind>|<block,block,…>',
|
|
86
|
+
' pmos today order --unpin',
|
|
87
|
+
'Today keeps the same blocks (overview, move, log, agenda) and orders them to the day: launch day, 3 or more meetings, Monday, Friday.',
|
|
88
|
+
'A pinned order wins over the day until you unpin it. The page reads the same pin.',
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
async function run(argv, { say, runtimeDir } = {}) {
|
|
92
|
+
const M = await mod();
|
|
93
|
+
let rt = runtimeDir;
|
|
94
|
+
if (rt === undefined) { try { rt = require('./state-root.js').defaultRoot({ env: process.env }); } catch { rt = null; } }
|
|
95
|
+
const a = argv[0] === 'order' ? argv.slice(1) : argv.slice();
|
|
96
|
+
const f = { json: false, unpin: false, pin: null };
|
|
97
|
+
for (let i = 0; i < a.length; i++) {
|
|
98
|
+
if (a[i] === '--json') f.json = true;
|
|
99
|
+
else if (a[i] === '--unpin') f.unpin = true;
|
|
100
|
+
else if (a[i] === '--pin' && a[i + 1] && !a[i + 1].startsWith('--')) f.pin = a[++i];
|
|
101
|
+
else if (a[i] === '--help' || a[i] === '-h') { USAGE.forEach((l) => say(l)); return 0; }
|
|
102
|
+
else { say(`✗ ${a[i]} is not an option of pmos today order`); USAGE.forEach((l) => say(l)); return 2; }
|
|
103
|
+
}
|
|
104
|
+
if (f.pin && f.unpin) { say('✗ --pin and --unpin: use one'); return 2; }
|
|
105
|
+
let out;
|
|
106
|
+
if (f.unpin) out = unpin(rt);
|
|
107
|
+
else if (f.pin) out = await pin(rt, M.KINDS.includes(f.pin) ? { kind: f.pin } : { order: f.pin.split(',').map((x) => x.trim()).filter(Boolean) });
|
|
108
|
+
else out = read(rt);
|
|
109
|
+
if (!out.ok) { say('✗ ' + out.error); return 1; }
|
|
110
|
+
if (f.pin || f.unpin) try { require('./use-log.js').record(rt, [{ kind: 'use', page: 'today', control: 'todayOrderPin', device: 'desk' }]); } catch { /* the use log is a count only */ }
|
|
111
|
+
if (f.json) { say(JSON.stringify({ ok: true, pin: out.pin, blocks: M.BLOCKS, days: M.ORDERS })); return 0; }
|
|
112
|
+
if (out.pin) say(`Pinned · the order for ${M.LABEL[out.pin.kind] || M.LABEL.own}: ${M.whole(out.pin.order).join(', ')}`);
|
|
113
|
+
else {
|
|
114
|
+
say('Not pinned: Today orders itself to the day.');
|
|
115
|
+
for (const k of Object.keys(M.ORDERS)) say(` ${M.LABEL[k]}: ${M.ORDERS[k].join(', ')}`);
|
|
116
|
+
}
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { read, pin, unpin, handle, run, USAGE, TAG, fileOf };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.826.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.826.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|