create-pmos 0.824.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 +149 -39
- 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 +148 -12
- package/workspace/guide/agent-capabilities.md +1 -0
- package/workspace/guide/cli.md +32 -0
- package/workspace/guide/home.md +2 -0
- package/workspace/guide/layout.md +1 -1
- package/workspace/guide/settings-and-switches.md +4 -0
- package/workspace/lib/autonomy-cli.js +14 -2
- package/workspace/lib/code-map-cli.js +100 -0
- package/workspace/lib/code-map.js +247 -0
- package/workspace/lib/connector-data.js +138 -0
- package/workspace/lib/connectors-cli.js +6 -0
- package/workspace/lib/does-alone.js +67 -0
- package/workspace/lib/features.json +58 -1
- package/workspace/lib/mention-cli.js +36 -2
- package/workspace/lib/name-links.js +203 -0
- package/workspace/lib/pmos-verbs.js +6 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-autonomy.js +9 -0
- package/workspace/lib/routes-code-map.js +66 -0
- package/workspace/lib/routes-connector-data.js +17 -0
- package/workspace/lib/routes-today-log.js +8 -1
- 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/connector-data.js +47 -0
- package/workspace/public/pm/cozy-board.css +8 -0
- package/workspace/public/pm/cozy-name-links.js +118 -0
- package/workspace/public/pm/cozy-settings.js +41 -7
- package/workspace/public/pm/cozy-today-app.js +67 -2
- package/workspace/public/pm/cozy-today-page.css +8 -0
- package/workspace/public/pm/cozy-today-view.js +28 -8
- package/workspace/public/pm/cozy-today.css +9 -0
- package/workspace/public/pm/home-chat.js +16 -1
- package/workspace/public/pm/home-hold.js +121 -0
- 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/connector-data.json +9 -0
- package/workspace/test-lists/directory-all-verbs.json +9 -0
- package/workspace/test-lists/does-alone.json +9 -0
- package/workspace/test-lists/hold-to-talk.json +9 -0
- package/workspace/test-lists/name-links.json +9 -0
- package/workspace/test-lists/today-order.json +9 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* code-map-cli.js — `pmos code`: the product's code map, the same map the Code panel on Work shows (idea A176, initiative code-map).
|
|
3
|
+
* The store is lib/code-map.js (code-map.json and code-map-notes.jsonl in the product's records folder).
|
|
4
|
+
*
|
|
5
|
+
* pmos code show [--json] one line per main part: what it is, how tested, who changed it last; ! marks a risky part
|
|
6
|
+
* pmos code map [--json] draw the map again now from the default branch (read-only git)
|
|
7
|
+
* pmos code describe --part <name> --text "<…>" say what a part is in your own words (the chat writes it for the PM); "" puts PMOS's back
|
|
8
|
+
* pmos code count the number of parts in the map, on the last line
|
|
9
|
+
* every command: [--root <dir>] (default: this repository)
|
|
10
|
+
*
|
|
11
|
+
* Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent, and nothing in the repository is written. */
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const CM = require('./code-map.js');
|
|
15
|
+
|
|
16
|
+
const COMMANDS = { code: ['show', 'map', 'describe', 'count'] };
|
|
17
|
+
const USAGE = [
|
|
18
|
+
'usage: pmos code show|map|describe|count — the product\'s code map: one line per main part',
|
|
19
|
+
' pmos code show [--json] what each part is, how it is tested, who changed it last; ! marks a risky part',
|
|
20
|
+
' pmos code map [--json] draw the map again now from the default branch',
|
|
21
|
+
' pmos code describe --part api --text "<what it is>" say what a part is; --text "" puts PMOS\'s words back',
|
|
22
|
+
' pmos code count the number of parts in the map',
|
|
23
|
+
'Run it in the product\'s repository, or pass --root <dir>.',
|
|
24
|
+
];
|
|
25
|
+
const ALLOWED = { show: ['json', 'root'], map: ['json', 'root'], describe: ['json', 'root', 'part', 'text'], count: ['json', 'root'] };
|
|
26
|
+
const BOOL = new Set(['json']);
|
|
27
|
+
|
|
28
|
+
function parse(args) {
|
|
29
|
+
const pos = [], flags = {};
|
|
30
|
+
for (let i = 0; i < args.length; i++) {
|
|
31
|
+
const a = args[i];
|
|
32
|
+
if (!a.startsWith('--')) { pos.push(a); continue; }
|
|
33
|
+
const k = a.slice(2);
|
|
34
|
+
if (BOOL.has(k)) { flags[k] = true; continue; }
|
|
35
|
+
flags[k] = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
|
|
36
|
+
}
|
|
37
|
+
return { pos, flags };
|
|
38
|
+
}
|
|
39
|
+
/** The nearest folder at or above `cwd` that holds a .git entry, read from the disk with no git run; `cwd` when there is none. */
|
|
40
|
+
function repoRoot(cwd) {
|
|
41
|
+
let dir = path.resolve(cwd);
|
|
42
|
+
for (let i = 0; i < 64; i++) {
|
|
43
|
+
if (fs.existsSync(path.join(dir, '.git'))) return dir;
|
|
44
|
+
const up = path.dirname(dir); if (up === dir) break; dir = up;
|
|
45
|
+
}
|
|
46
|
+
return cwd;
|
|
47
|
+
}
|
|
48
|
+
function recordsDirOf(root) {
|
|
49
|
+
try { const { repoScript } = require('./repo-script.js'); return require(repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; } catch { return path.join(root, 'planning', 'records'); }
|
|
50
|
+
}
|
|
51
|
+
const dayOf = (iso) => { const d = new Date(iso); return isNaN(d) ? '' : d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' }); };
|
|
52
|
+
/** One part as one line. */
|
|
53
|
+
function lineOf(p) {
|
|
54
|
+
const what = p.note || [p.kind, p.code + (p.code === 1 ? ' file' : ' files')].filter(Boolean).join(' · ');
|
|
55
|
+
const who = p.last && p.last.by ? ` · ${p.last.by} last, ${dayOf(p.last.at)}` : '';
|
|
56
|
+
return `${p.risky ? '!' : ' '} ${p.name}: ${what} · ${p.tested}${p.risky && p.why !== 'no tests' ? ' · ' + p.why.replace(/^no tests, /, '') : ''}${who}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Date.now() } = {}) {
|
|
60
|
+
const args = argv[0] === 'code' ? argv.slice(1) : argv.slice();
|
|
61
|
+
const sub = args[0];
|
|
62
|
+
if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
|
|
63
|
+
if (!COMMANDS.code.includes(sub)) { say(`unknown code command "${sub}". Use one of: ${COMMANDS.code.join(', ')}`); return 2; }
|
|
64
|
+
const { pos, flags } = parse(args.slice(1));
|
|
65
|
+
for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos code ${sub}`); return 2; }
|
|
66
|
+
if (pos.length) { say(`✗ pmos code ${sub} takes options, not an argument (pmos code help)`); return 2; }
|
|
67
|
+
const root = path.resolve(flags.root || repoRoot(cwd));
|
|
68
|
+
const dir = recordsDirOf(root);
|
|
69
|
+
const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
|
|
70
|
+
|
|
71
|
+
if (sub === 'map') {
|
|
72
|
+
const map = await CM.build(root, { now });
|
|
73
|
+
if (!map) return fail('no code map: this folder is not a git repository, or it holds no code');
|
|
74
|
+
CM.save(dir, map);
|
|
75
|
+
if (flags.json) { say(JSON.stringify({ ok: true, map: CM.view(dir) })); return 0; }
|
|
76
|
+
say(`Drew ${map.parts.length} parts from ${map.ref} ${map.head.slice(0, 7)}.`);
|
|
77
|
+
for (const p of CM.view(dir).parts) say(lineOf(p));
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
const map = CM.view(dir);
|
|
81
|
+
if (sub === 'count') { say(flags.json ? JSON.stringify({ ok: true, parts: map ? map.parts.length : 0 }) : String(map ? map.parts.length : 0)); return 0; }
|
|
82
|
+
if (sub === 'show') {
|
|
83
|
+
if (flags.json) { say(JSON.stringify({ ok: true, map })); return 0; }
|
|
84
|
+
if (!map) { say('No code map yet. Run pmos code map, or open Work on this product.'); return 0; }
|
|
85
|
+
say(`Code map, read from ${map.ref} ${map.head.slice(0, 7)} on ${dayOf(map.at)}:`);
|
|
86
|
+
for (const p of map.parts) say(lineOf(p));
|
|
87
|
+
if (map.more) say(` and ${map.more} smaller part${map.more === 1 ? '' : 's'}`);
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
// describe
|
|
91
|
+
if (!flags.part) return fail('--part <name> is needed (pmos code show lists the parts)', 2);
|
|
92
|
+
if (flags.text === undefined) return fail('--text "<what it is>" is needed ("" puts PMOS\'s words back)', 2);
|
|
93
|
+
const r = CM.describe(dir, flags.part, flags.text, now);
|
|
94
|
+
if (!r.ok) return fail(r.error);
|
|
95
|
+
const p = CM.findPart(r.map, flags.part);
|
|
96
|
+
say(flags.json ? JSON.stringify({ ok: true, part: p }) : `${p.name}: ${p.note || "PMOS's words again"}`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = { run, COMMANDS, USAGE, lineOf };
|
|
@@ -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 };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* connector-data.js — what each connector reads and writes (initiative connector-data, idea A150; board ConnDataDS). THE ONE LIST that
|
|
3
|
+
* Settings › Connectors (pm/connector-data.js), `pmos connectors data` and the drift test (connector-data.test.js) read.
|
|
4
|
+
*
|
|
5
|
+
* REGISTRY one entry per connector PMOS uses: { id, name, match, reads[], writes[], line }
|
|
6
|
+
* reads[] { id, what, detail, switch, skills } switch: the brief source in Settings that stops the read (proactive.js
|
|
7
|
+
* BRIEF_SOURCES), or null when PMOS cannot stop it yet: then the page says "Read while connected" and shows no switch.
|
|
8
|
+
* writes[] { what, skills } the standing rules; never a switch. An entry that writes nothing has [].
|
|
9
|
+
* NOT_CONNECTORS brief sources that are not connectors (your websites, the open web)
|
|
10
|
+
* byId(id) · ofLabel(label) the entry for a source id, or for a connected connector's name ("claude.ai Atlassian MCP" → jira)
|
|
11
|
+
* toolService(tool) the entry id a connector tool belongs to (mcp__claude_ai_Gmail__get_thread → mail), or null
|
|
12
|
+
* leaves(entry) the "What leaves this computer" text: AI work goes through the person's own AI account
|
|
13
|
+
* view(entry, { settings, read, connected }) → what the page and the command show, with each switch's state and the last read
|
|
14
|
+
* viewAll(rt, connectedNames) → every entry's view, for GET /api/connector-data
|
|
15
|
+
* textOf(view) · lines(views) the command's plain text
|
|
16
|
+
*
|
|
17
|
+
* Plain words only (done test D1): no tool name, no field name. When a skill starts reading or writing through a connector, add it here;
|
|
18
|
+
* the test fails until you do.
|
|
19
|
+
*/
|
|
20
|
+
const SEP = ' · ';
|
|
21
|
+
|
|
22
|
+
const REGISTRY = Object.freeze([
|
|
23
|
+
{ id: 'jira', name: 'Jira', match: /jira|atlassian/i, line: "Reads your initiatives' tasks · writes only what you move or approve",
|
|
24
|
+
reads: [
|
|
25
|
+
{ id: 'tasks', what: 'Tasks of your initiatives', detail: 'title, status, sprint and subtasks · for Work and This sprint', switch: null, skills: ['jira-sync'] },
|
|
26
|
+
{ id: 'mine', what: 'Open tickets assigned to you', detail: 'with their comments and links · for My work', switch: null, skills: ['my-work-read'] },
|
|
27
|
+
{ id: 'mentions', what: 'Tickets and comments that mention you', detail: 'who asked, where, and the link · for the Briefing and Mentions', switch: 'jira', skills: ['sources-read'] },
|
|
28
|
+
],
|
|
29
|
+
writes: [
|
|
30
|
+
{ what: 'Status, only for a ticket you move in PMOS.', skills: ['jira-move'] },
|
|
31
|
+
{ what: 'Epic and acceptance criteria, only on tickets assigned to you, after you approve them.', skills: ['jira-epic', 'jira-criteria'] },
|
|
32
|
+
{ what: 'New tickets and their edits, only the ones you select and send.', skills: ['jira-push'] },
|
|
33
|
+
] },
|
|
34
|
+
{ id: 'confluence', name: 'Confluence', match: /confluence|atlassian/i, line: 'Reads pages your initiatives link · writes nothing',
|
|
35
|
+
reads: [{ id: 'pages', what: 'Pages your initiatives link, and pages that mention you', detail: 'title, who changed it, and the link · for the Briefing', switch: 'confluence', skills: ['sources-read'] }],
|
|
36
|
+
writes: [] },
|
|
37
|
+
{ id: 'slack', name: 'Slack', match: /slack/i, line: 'Reads threads that mention you · writes nothing',
|
|
38
|
+
reads: [{ id: 'mentions', what: 'Threads that mention you', detail: 'who asked, where, and the link · for the Briefing and Mentions', switch: 'slack', skills: ['sources-read'] }],
|
|
39
|
+
writes: [] },
|
|
40
|
+
{ id: 'calendar', name: 'Google Calendar', match: /calendar/i, line: 'Reads your meetings · writes nothing',
|
|
41
|
+
reads: [{ id: 'meetings', what: 'Your meetings', detail: 'title, time and who comes, today and the next 14 days · for Today and Events', switch: 'calendar', skills: ['calendar-sync'] }],
|
|
42
|
+
writes: [] },
|
|
43
|
+
{ id: 'mail', name: 'Mail', match: /gmail|outlook|\bmail\b/i, line: 'Reads subjects of mail that waits on you · writes nothing',
|
|
44
|
+
reads: [{ id: 'waiting', what: 'Mail that waits on you', detail: 'subject and sender only; a message is never copied · for the Briefing', switch: 'mail', skills: ['sources-read'] }],
|
|
45
|
+
writes: [] },
|
|
46
|
+
{ id: 'wispr', name: 'Wispr Flow', match: /wispr/i, line: 'Reads your meeting notes · writes nothing',
|
|
47
|
+
reads: [{ id: 'notes', what: "Today's and yesterday's meeting notes", detail: 'what was decided and what is still open · for the Briefing', switch: 'wispr', skills: ['sources-read'] }],
|
|
48
|
+
writes: [] },
|
|
49
|
+
{ id: 'github', name: 'GitHub', match: /github/i, line: 'Reads pull requests that wait on you · writes nothing',
|
|
50
|
+
reads: [{ id: 'waiting', what: 'Pull requests and issues that wait on you', detail: 'reviews asked of you, failed checks, issues assigned to you · for the Briefing', switch: 'github', skills: ['sources-read'] }],
|
|
51
|
+
writes: [] },
|
|
52
|
+
{ id: 'drive', name: 'Google Drive', match: /drive/i, line: 'Reads files shared with you · writes nothing',
|
|
53
|
+
reads: [{ id: 'files', what: 'Files shared with you or changed', detail: 'name, who changed it, and the link · for the Briefing', switch: 'drive', skills: ['sources-read'] }],
|
|
54
|
+
writes: [] },
|
|
55
|
+
{ id: 'figma', name: 'Figma', match: /figma/i, line: 'Reads design files that ask for you · writes nothing',
|
|
56
|
+
reads: [{ id: 'files', what: 'Files you own or were asked to look at', detail: 'new comments and the link · for the Briefing', switch: 'figma', skills: ['sources-read'] }],
|
|
57
|
+
writes: [] },
|
|
58
|
+
].map((e) => Object.freeze({ ...e, reads: Object.freeze(e.reads.map((r) => Object.freeze(r))), writes: Object.freeze(e.writes.map((w) => Object.freeze(w))) })));
|
|
59
|
+
|
|
60
|
+
const NOT_CONNECTORS = Object.freeze(['website', 'web']);
|
|
61
|
+
const BY_ID = new Map(REGISTRY.map((e) => [e.id, e]));
|
|
62
|
+
const byId = (id) => BY_ID.get(String(id || '')) || null;
|
|
63
|
+
const labelOf = (name) => String(name || '').replace(/^claude\.ai\s+/i, '').trim();
|
|
64
|
+
/** The entry for a connected connector's name. Atlassian backs Jira and Confluence: the first match is Jira. */
|
|
65
|
+
const ofLabel = (name) => REGISTRY.find((e) => e.match.test(labelOf(name))) || null;
|
|
66
|
+
/** Every entry a connector name backs (Atlassian → Jira and Confluence). */
|
|
67
|
+
const allOfLabel = (name) => REGISTRY.filter((e) => e.match.test(labelOf(name)));
|
|
68
|
+
|
|
69
|
+
// A connector tool's server part (mcp__claude_ai_<server>__<tool>) → the entry. Atlassian tools that name Confluence are Confluence's.
|
|
70
|
+
const SERVERS = [[/^Atlassian(_MCP)?$/i, (t) => (/confluence/i.test(t) ? 'confluence' : 'jira')], [/slack/i, () => 'slack'], [/calendar/i, () => 'calendar'],
|
|
71
|
+
[/gmail|outlook/i, () => 'mail'], [/drive/i, () => 'drive'], [/figma/i, () => 'figma'], [/github/i, () => 'github'], [/wispr/i, () => 'wispr']];
|
|
72
|
+
function toolService(tool) {
|
|
73
|
+
const m = /^mcp__claude_ai_(.+?)__(.+)$/.exec(String(tool || ''));
|
|
74
|
+
if (!m) return null;
|
|
75
|
+
const hit = SERVERS.find(([re]) => re.test(m[1]));
|
|
76
|
+
return hit ? hit[1](m[2]) : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const leaves = (e) => `PMOS reads ${e.name} through the connector in your own AI account and keeps its copy on this computer, in PMOS's own folder. `
|
|
80
|
+
+ 'When PMOS writes a summary or a suggestion from it, that text goes through your own AI account. Nothing goes to the PMOS makers, and there is no telemetry.';
|
|
81
|
+
|
|
82
|
+
/** What the page and the command show for one entry. settings: Settings (briefSources); read: the stored read (lib/source-reads.js) or null. */
|
|
83
|
+
function view(e, { settings = null, read = null, connected = true } = {}) {
|
|
84
|
+
const S = settings || require('./proactive.js').normalizeSettings({}).settings; // no saved Settings: the defaults PMOS uses
|
|
85
|
+
const on = (S && S.briefSources) || {};
|
|
86
|
+
const items = read && Array.isArray(read.items) ? read.items.length : null;
|
|
87
|
+
return {
|
|
88
|
+
id: e.id, name: e.name, line: e.line, match: e.match.source, connected: !!connected,
|
|
89
|
+
reads: e.reads.map((r) => ({ id: r.id, what: r.what, detail: r.detail, switch: r.switch, on: r.switch ? on[r.switch] === true : true })),
|
|
90
|
+
writes: e.writes.map((w) => w.what),
|
|
91
|
+
leaves: leaves(e),
|
|
92
|
+
lastRead: read && read.read_at ? { at: read.read_at, items } : null,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Every entry's view for the runtime folder `rt`. connectedNames: the connectors the session has; an entry no name backs is not connected. */
|
|
97
|
+
function viewAll(rt, connectedNames) {
|
|
98
|
+
// Settings as /api/proactive/settings saves them (<runtime>/proactive-settings.json), normalised like routes-mentions.js reads them
|
|
99
|
+
let settings = null;
|
|
100
|
+
try { const n = require('./proactive.js').normalizeSettings(JSON.parse(require('fs').readFileSync(require('path').join(rt, 'proactive-settings.json'), 'utf8'))); settings = n.ok ? n.settings : null; } catch { settings = null; }
|
|
101
|
+
const SR = require('./source-reads.js');
|
|
102
|
+
const names = Array.isArray(connectedNames) ? connectedNames : null;
|
|
103
|
+
const conn = names ? new Set(names.flatMap((n) => allOfLabel(n).map((e) => e.id))) : null;
|
|
104
|
+
return REGISTRY.map((e) => view(e, { settings, read: SR.SOURCES.includes(e.id) ? SR.read(rt, e.id) : null, connected: conn ? conn.has(e.id) : true }));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function textOf(v) {
|
|
108
|
+
const out = [v.name + (v.lastRead ? ` (last read ${v.lastRead.at})` : ''), '', 'What PMOS reads'];
|
|
109
|
+
for (const r of v.reads) out.push(`- ${r.what}: ${r.detail}. ${r.switch ? (r.on ? 'On' : 'Off') + ` (pmos proactive settings --brief-source ${r.switch}=on|off)` : 'Read while connected.'}`);
|
|
110
|
+
out.push('', 'What PMOS writes');
|
|
111
|
+
if (!v.writes.length) out.push('- Nothing.'); else for (const w of v.writes) out.push('- ' + w);
|
|
112
|
+
out.push('', 'What leaves this computer', v.leaves);
|
|
113
|
+
return out.join('\n');
|
|
114
|
+
}
|
|
115
|
+
const lines = (views) => views.map((v) => `${v.id.padEnd(11)}${v.name}: ${v.line}${v.connected ? '' : SEP + 'not connected'}`).join('\n');
|
|
116
|
+
|
|
117
|
+
const USAGE = 'pmos connectors data [<connector>] [--json] what PMOS reads and writes through each connector (read only). '
|
|
118
|
+
+ 'A read switch: pmos proactive settings --brief-source NAME=on|off. Connectors: ' + REGISTRY.map((e) => e.id).join(', ');
|
|
119
|
+
|
|
120
|
+
/** `pmos connectors data [<id>] [--json]`. call(method, path) reaches the running server; without one the list prints with no switch state. */
|
|
121
|
+
async function run(argv, { say = console.log, call = async () => null } = {}) {
|
|
122
|
+
const args = argv[0] === 'connectors' ? argv.slice(1) : argv;
|
|
123
|
+
const json = args.includes('--json'), rest = args.filter((a) => a !== '--json');
|
|
124
|
+
if (rest[0] !== 'data' || rest.length > 2) { say(USAGE); return rest[0] === 'help' || !rest.length ? 0 : 2; }
|
|
125
|
+
const id = rest[1];
|
|
126
|
+
if (id && !byId(id)) { say(`no connector "${id}" — one of ${REGISTRY.map((e) => e.id).join(', ')}`); return 1; }
|
|
127
|
+
const r = await call('GET', '/api/connector-data').catch(() => null);
|
|
128
|
+
const views = r && r.ok && Array.isArray(r.connectors) ? r.connectors : REGISTRY.map((e) => view(e));
|
|
129
|
+
const pick = id ? views.filter((v) => v.id === id) : views;
|
|
130
|
+
if (json) { say(JSON.stringify(id ? pick[0] : pick, null, 2)); return 0; }
|
|
131
|
+
if (!(r && r.ok)) say('(No workspace server runs, so the switches show their defaults and no last read.)');
|
|
132
|
+
say(id ? textOf(pick[0]) : lines(pick));
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const COMMANDS = Object.freeze({ connectors: ['data'] });
|
|
137
|
+
|
|
138
|
+
module.exports = { COMMANDS, REGISTRY, NOT_CONNECTORS, byId, ofLabel, allOfLabel, toolService, leaves, view, viewAll, textOf, lines, run, USAGE };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* connectors-cli.js — `pmos connectors data [<connector>] [--json]` (initiative connector-data, A150): the verb module lib/pmos-verbs.js
|
|
3
|
+
* runs. The list, the views and the text are lib/connector-data.js, the one list Settings › Connectors reads too. */
|
|
4
|
+
const CD = require('./connector-data.js');
|
|
5
|
+
|
|
6
|
+
module.exports = { run: CD.run, COMMANDS: CD.COMMANDS, USAGE: CD.USAGE };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* does-alone.js — one page: what PMOS may do alone (initiative does-alone, job #1890, idea A513; board BatchPagesDS panel 2, agreed
|
|
3
|
+
* 2026-11-25; done test planning/done-tests/does-alone.md).
|
|
4
|
+
*
|
|
5
|
+
* WHAT IT IS. A read-only list of today's rules, one row per kind of action, in plain words: what PMOS does now, since when, and the
|
|
6
|
+
* decision behind it. The kinds and their ways are lib/autonomy.js's own (KIND_LIST, kindsOf, the PM's claude.ways), so this page and
|
|
7
|
+
* Settings › How PMOS decides never disagree. Then the fixed rows: what others see waits for the daily press, and the calls that always
|
|
8
|
+
* ask. Nothing here is set: a kind's way is changed in How PMOS decides (pm/cozy-settings.js).
|
|
9
|
+
*
|
|
10
|
+
* FIXED · DECISION · pmosOf(way) PURE · sinceOf(k) PURE · rowsOf(kinds, { off }) PURE → [row] · stopsOf(lines, { now }) PURE → [kind label]
|
|
11
|
+
* lineOf(stops) PURE → the ✦ line | null · aloneOf(dirs, { now, env, settingsDir }) → { ok, off, rows, stops, line } READ-ONLY
|
|
12
|
+
* row: { key, what, pmos, since, fixed, decision: { id, page } }
|
|
13
|
+
*
|
|
14
|
+
* It writes nothing: no ledger line, no setting. GET /api/autonomy/alone (lib/routes-autonomy.js) and `pmos autonomy alone` read it. */
|
|
15
|
+
const A = require('./autonomy.js');
|
|
16
|
+
|
|
17
|
+
const DAY = 86400000;
|
|
18
|
+
const DECISION = Object.freeze({ id: 'D106', page: 'agent-capabilities' }); // Full autonomy now (2026-11-08): the guide page explains it
|
|
19
|
+
const FIXED = Object.freeze([
|
|
20
|
+
Object.freeze({ key: 'others', what: 'Anything others see: stages and dates in Jira or on Work', pmos: 'Once a day, in one batch' }),
|
|
21
|
+
Object.freeze({ key: 'sends', what: 'Messages to people, Jira writes, merges, deletes and spend', pmos: 'Asks you' }),
|
|
22
|
+
Object.freeze({ key: 'calls', what: 'Starting a new request, and saying if an outcome worked', pmos: 'Asks you' }),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
/** PURE. What PMOS does for a way. */
|
|
26
|
+
const pmosOf = (way) => (way === 'quiet' ? 'Does it, Undo' : way === 'show' ? 'Does it and shows you, Undo' : 'Asks you');
|
|
27
|
+
const dayOf = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? new Date(t).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' }) : ''; };
|
|
28
|
+
/** PURE. Since when: the PM's way, a demotion's end, or the automatic way. */
|
|
29
|
+
const sinceOf = (k) => (k.set ? 'you set it' : k.until ? 'asks until ' + dayOf(k.until) : 'auto');
|
|
30
|
+
|
|
31
|
+
/** PURE. One row per kind (KIND_LIST order), its way from kindsOf when it has one, then the fixed rows. off: every row asks. */
|
|
32
|
+
function rowsOf(kinds = [], { off = null } = {}) {
|
|
33
|
+
const by = new Map((kinds || []).map((k) => [k.kind, k]));
|
|
34
|
+
const rows = A.KIND_LIST.map((x) => {
|
|
35
|
+
const k = by.get(x.key) || { kind: x.key, set: null, until: null, way: A.autoWay({ kept: 0, demoted: false }) };
|
|
36
|
+
return { key: x.key, what: x.label, pmos: off ? 'Asks you' : pmosOf(k.way), since: off ? 'switched off' : sinceOf(k), fixed: false, decision: DECISION };
|
|
37
|
+
});
|
|
38
|
+
return [...rows, ...FIXED.map((f) => ({ key: f.key, what: f.what, pmos: f.pmos, since: 'always', fixed: true, decision: DECISION }))];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** PURE. The kinds PMOS went back to asking for by itself in the last 7 days (a demote line), one entry per line, newest first. */
|
|
42
|
+
function stopsOf(lines = [], { now } = {}) {
|
|
43
|
+
const t = now == null ? Date.now() : now;
|
|
44
|
+
return (lines || []).filter((l) => l && l.ev === 'demote' && t - Date.parse(l.at) <= 7 * DAY && t >= Date.parse(l.at))
|
|
45
|
+
.sort((a, b) => String(b.at).localeCompare(String(a.at)))
|
|
46
|
+
.map((l) => { const kk = A.kindOf(l.job); const x = A.KIND_LIST.find((y) => y.key === kk); return x ? x.label : String(l.job); });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** PURE. The ✦ line, or null (zero is silence). */
|
|
50
|
+
function lineOf(stops = []) {
|
|
51
|
+
if (!stops.length) return null;
|
|
52
|
+
const names = [...new Set(stops)];
|
|
53
|
+
return `PMOS went back to asking by itself ${stops.length === 1 ? 'once' : stops.length + ' times'} this week, after your Undos (${names.slice(0, 3).join(', ')}${names.length > 3 ? ' and ' + (names.length - 3) + ' more' : ''}).`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** READ-ONLY. The page over the given state folders. */
|
|
57
|
+
function aloneOf(dirs = [], { now, env = process.env, settingsDir = null } = {}) {
|
|
58
|
+
const off = A.killed({ env, settingsDir });
|
|
59
|
+
const kinds = A.kindsOf(dirs, { now, settingsDir });
|
|
60
|
+
const set = A.waysSet(settingsDir);
|
|
61
|
+
// kindsOf lists only the kinds with a change or a set way; a set way with no change is in it already, so the rest are automatic
|
|
62
|
+
for (const [kk, w] of Object.entries(set)) if (!kinds.some((k) => k.kind === kk)) kinds.push({ kind: kk, set: w, way: w, until: null });
|
|
63
|
+
const stops = stopsOf((dirs || []).flatMap((d) => A.read(d)), { now });
|
|
64
|
+
return { ok: true, off: off || null, rows: rowsOf(kinds, { off }), stops, line: off ? null : lineOf(stops) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = { FIXED, DECISION, pmosOf, sinceOf, rowsOf, stopsOf, lineOf, aloneOf };
|