create-pmos 0.761.0 → 0.763.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 +39 -51
- 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 +38 -0
- package/workspace/guide/cli.md +6 -0
- package/workspace/guide/home.md +2 -1
- package/workspace/guide/notes.md +15 -0
- package/workspace/lib/actor.js +8 -3
- package/workspace/lib/contradictions.js +137 -0
- package/workspace/lib/meeting-focus.js +14 -1
- package/workspace/lib/open-questions.js +23 -5
- package/workspace/lib/outcome-judge.js +1 -1
- package/workspace/lib/outcome-props.js +51 -5
- package/workspace/lib/outcomes-cli.js +49 -3
- package/workspace/lib/plan-baseline.js +106 -0
- package/workspace/lib/proposal-runs.js +1 -1
- package/workspace/lib/proposals.js +1 -1
- package/workspace/lib/propose-cli.js +16 -7
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-drift.js +30 -0
- package/workspace/lib/routes-meeting-focus.js +6 -1
- package/workspace/lib/routes-open-questions.js +9 -2
- package/workspace/lib/routes-tracker-sync.js +64 -0
- package/workspace/lib/task-jira.js +9 -3
- package/workspace/lib/tracker-sync-take.js +92 -0
- package/workspace/lib/week-moves.js +8 -2
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-rec-tab-test.js +2 -1
- package/workspace/public/pm/buddy-core.js +162 -0
- package/workspace/public/pm/buddy-float.js +63 -0
- package/workspace/public/pm/cozy-buddy.css +26 -0
- package/workspace/public/pm/cozy-buddy.js +59 -7
- package/workspace/public/pm/cozy-rec-tab.js +10 -2
- package/workspace/public/pm/cozy-today-app.js +40 -1
- package/workspace/public/pm/cozy-today-model.js +27 -0
- package/workspace/public/pm/cozy-today-view.js +14 -2
- package/workspace/public/pm/cozy-today.css +2 -0
- package/workspace/public/pm/moves-view.js +11 -1
- package/workspace/public/pm/open-questions-view.js +1 -0
- package/workspace/public/premium-buddy.html +4 -0
- package/workspace/skills/initiative-propose.skill +2 -2
- package/workspace/test-lists/outcome-checks-finish.json +9 -0
- package/workspace/test-lists/slip-baseline-contradictions.json +9 -0
- package/workspace/test-lists/tracker-sync-on-today.json +9 -0
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
* left out when the bet already has a named test.
|
|
20
20
|
* pmos outcomes tests [--count] [--json] the ranked bets with no smallest test, the tests waiting for a result, and the results;
|
|
21
21
|
* --count prints the number of bets with a result in the last 14 days (the health number).
|
|
22
|
+
* pmos outcomes rate [--days <n>] [--json] the bet's number (outcome-checks-finish): checks due in the last n days (30) and at least 2
|
|
23
|
+
* days past, how many got a verdict within 2 days, how many of those PMOS recorded; the last
|
|
24
|
+
* line is that percent. Reads only.
|
|
22
25
|
* every command: [--root <dir>] (default: this repository)
|
|
23
26
|
*
|
|
24
27
|
* The agent runs declare and record only after the PM said yes in the chat; the line names who wrote it (lib/actor.js). A verdict is the
|
|
@@ -29,7 +32,7 @@ const { execFileSync } = require('child_process');
|
|
|
29
32
|
const O = require('./outcomes.js');
|
|
30
33
|
const ST = require('./smallest-test.js');
|
|
31
34
|
|
|
32
|
-
const COMMANDS = { outcomes: ['list', 'propose', 'declare', 'record', 'live', 'test', 'tests'] };
|
|
35
|
+
const COMMANDS = { outcomes: ['list', 'propose', 'declare', 'record', 'live', 'test', 'tests', 'rate'] };
|
|
33
36
|
const USAGE = [
|
|
34
37
|
'usage: pmos outcomes list|propose|declare|record|live|test|tests — every initiative has an expected outcome and a date to check it',
|
|
35
38
|
' pmos outcomes list [--json] checks due, outcomes with no date, initiatives with no outcome; reads only',
|
|
@@ -40,8 +43,37 @@ const USAGE = [
|
|
|
40
43
|
' pmos outcomes test <id> --test "<text>" [--method data-count|fake-door|concierge|other] [--result planned|holds|fails|unclear] [--evidence "<text>"]',
|
|
41
44
|
' the smallest test that could kill a ranked bet, and what it showed',
|
|
42
45
|
' pmos outcomes tests [--count] [--json] ranked bets with no test, tests waiting for a result, results; --count: results in 14 days',
|
|
46
|
+
' pmos outcomes rate [--days <n>] [--json] checks due in the last n days (30) that got a verdict within 2 days, and how many PMOS did',
|
|
43
47
|
'Run it in the product\'s repository, or pass --root <dir>. Show each ✦ to the PM and write only after a yes.',
|
|
44
48
|
];
|
|
49
|
+
/* `pmos outcomes rate` (initiative outcome-checks-finish): the bet's own number. A check counts when its date fell in the last `days` days
|
|
50
|
+
* and is at least ON_TIME_DAYS past (so it had its full chance); it is on time when a live verdict (not undone) for that date was recorded
|
|
51
|
+
* no later than ON_TIME_DAYS after it, and PMOS's when an agent wrote it. A blocked check is not due (lib/outcomes.js), so it is left out. */
|
|
52
|
+
const RATE_DAYS = 30, ON_TIME_DAYS = 2;
|
|
53
|
+
const addDays = (day, n) => new Date(Date.parse(day + 'T00:00:00Z') + n * 864e5).toISOString().slice(0, 10);
|
|
54
|
+
function rateOf(root, { today, days = RATE_DAYS } = {}) {
|
|
55
|
+
const S = O.scan(root, { today });
|
|
56
|
+
const from = addDays(today, -days), to = addDays(today, -ON_TIME_DAYS);
|
|
57
|
+
const rows = [];
|
|
58
|
+
for (const f of [...new Set([path.join(S.layout.runsDir, 'outcome_checks.jsonl'), path.join(root, 'pmos', 'state', 'outcome_checks.jsonl'), path.join(root, 'planning', 'runs', 'outcome_checks.jsonl')])]) {
|
|
59
|
+
let t = ''; try { t = require('fs').readFileSync(f, 'utf8'); } catch { continue; }
|
|
60
|
+
for (const l of t.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object') rows.push(o); } catch { /* torn */ } }
|
|
61
|
+
}
|
|
62
|
+
const live = O.liveChecks(rows).filter((c) => c && c.initiative_id && O.DISPOSITIONS.includes(c.disposition));
|
|
63
|
+
const blocked = new Set(S.blocked.map((it) => it.id));
|
|
64
|
+
const due = [];
|
|
65
|
+
for (const it of S.subjects) {
|
|
66
|
+
if (!it.metric || !it.horizon || it.horizon < from || it.horizon > to || blocked.has(it.id)) continue;
|
|
67
|
+
const mine = live.filter((c) => c.initiative_id === it.id && (!c.horizon || c.horizon === it.horizon) && String(c.date || c.at || '').slice(0, 10) >= it.horizon)
|
|
68
|
+
.sort((a, b) => String(a.at || a.date).localeCompare(String(b.at || b.date)));
|
|
69
|
+
const v = mine[0] || null, vDate = v ? String(v.date || v.at).slice(0, 10) : null;
|
|
70
|
+
const onTime = !!v && vDate <= addDays(it.horizon, ON_TIME_DAYS);
|
|
71
|
+
due.push({ id: it.id, horizon: it.horizon, onTime, byPmos: onTime && /^agent:/.test(String(v.by || '')), verdict: v ? { disposition: v.disposition, date: vDate, by: v.by || null } : null });
|
|
72
|
+
}
|
|
73
|
+
const byPmos = due.filter((x) => x.byPmos).length;
|
|
74
|
+
return { from, to, days, onTimeDays: ON_TIME_DAYS, due, onTime: due.filter((x) => x.onTime).length, byPmos, pct: due.length ? Math.round((100 * byPmos) / due.length) : null };
|
|
75
|
+
}
|
|
76
|
+
|
|
45
77
|
const VERDICT = { worked: 'validated', validated: 'validated', 'didnt-work': 'refuted', "didn't-work": 'refuted', refuted: 'refuted', 'cant-tell': 'inconclusive', "can't-tell": 'inconclusive', inconclusive: 'inconclusive' };
|
|
46
78
|
|
|
47
79
|
function parse(args) {
|
|
@@ -71,7 +103,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
|
|
|
71
103
|
if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
|
|
72
104
|
if (!COMMANDS.outcomes.includes(sub)) { say(`unknown outcomes command "${sub}". Use one of: ${COMMANDS.outcomes.join(', ')}`); return 2; }
|
|
73
105
|
const { pos, flags } = parse(args.slice(1));
|
|
74
|
-
const allowed = { list: ['json', 'root'], propose: ['json', 'root', 'max'], declare: ['json', 'root', 'metric', 'horizon'], record: ['json', 'root', 'evidence'], live: ['json', 'root', 'where', 'version'], test: ['json', 'root', 'test', 'method', 'result', 'evidence'], tests: ['json', 'root', 'count'] }[sub];
|
|
106
|
+
const allowed = { list: ['json', 'root'], propose: ['json', 'root', 'max'], declare: ['json', 'root', 'metric', 'horizon'], record: ['json', 'root', 'evidence'], live: ['json', 'root', 'where', 'version'], test: ['json', 'root', 'test', 'method', 'result', 'evidence'], tests: ['json', 'root', 'count'], rate: ['json', 'root', 'days'] }[sub];
|
|
75
107
|
for (const k of Object.keys(flags)) if (!allowed.includes(k)) { say(`✗ --${k} is not an option of pmos outcomes ${sub}`); return 2; }
|
|
76
108
|
const root = path.resolve(flags.root || repoRoot(cwd));
|
|
77
109
|
const today = O.todayOf(now);
|
|
@@ -95,6 +127,20 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
|
|
|
95
127
|
return 0;
|
|
96
128
|
}
|
|
97
129
|
|
|
130
|
+
if (sub === 'rate') {
|
|
131
|
+
if (pos.length) return fail('pmos outcomes rate takes no argument', 2);
|
|
132
|
+
const days = flags.days === undefined ? RATE_DAYS : Number(flags.days);
|
|
133
|
+
if (!Number.isInteger(days) || days < ON_TIME_DAYS || days > 366) return fail(`--days is a whole number from ${ON_TIME_DAYS} to 366`, 2);
|
|
134
|
+
const r = rateOf(root, { today, days });
|
|
135
|
+
if (flags.json) { say(JSON.stringify({ ok: true, ...r })); return 0; }
|
|
136
|
+
const n = r.due.length, onTime = r.due.filter((x) => x.onTime).length;
|
|
137
|
+
say(n ? `${n} check${n === 1 ? '' : 's'} came due from ${O.short(r.from)} to ${O.short(r.to)} · ${onTime} got a verdict within ${ON_TIME_DAYS} days · ${r.byPmos} by PMOS with no PM step`
|
|
138
|
+
: `No check came due from ${O.short(r.from)} to ${O.short(r.to)}.`);
|
|
139
|
+
for (const x of r.due.filter((y) => !y.onTime)) say(` late: ${x.id} — due ${O.short(x.horizon)}${x.verdict ? `, verdict on ${O.short(x.verdict.date)}` : ', no verdict yet'}`);
|
|
140
|
+
say(r.pct == null ? 'none due' : r.pct + '%');
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
98
144
|
if (sub === 'propose') {
|
|
99
145
|
if (pos.length > 1) return fail('pmos outcomes propose takes at most one initiative id', 2);
|
|
100
146
|
const max = flags.max === undefined ? 3 : Number(flags.max);
|
|
@@ -194,4 +240,4 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
|
|
|
194
240
|
return 0;
|
|
195
241
|
}
|
|
196
242
|
|
|
197
|
-
module.exports = { run, COMMANDS, USAGE, VERDICT };
|
|
243
|
+
module.exports = { rateOf, ON_TIME_DAYS, run, COMMANDS, USAGE, VERDICT };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* plan-baseline.js — every slip against a baseline (initiative slip-baseline-contradictions; bet 1c, proof A102). READ-ONLY: it writes nothing.
|
|
4
|
+
*
|
|
5
|
+
* Proof A102: PMOS moved 96 due dates with no evidence on two products, about 1,470 task-days, and with no baseline the plan still looked on
|
|
6
|
+
* time. The baseline of a task is the FIRST due date its lines ever set. It is derived from the ledgers, never declared, so no record has to
|
|
7
|
+
* be kept in step and every product that has task lines has a baseline today.
|
|
8
|
+
*
|
|
9
|
+
* baselineOf(task) → { baseline, due, open, removed, moves: [line] } PURE. task: a lib/drift-facts.js task
|
|
10
|
+
* daysBetween(a, b) → whole days from day a to day b (YYYY-MM-DD)
|
|
11
|
+
* slipOf(facts, { today }) → { today, initiatives: [row], tasks, days, unsourced_days } PURE. facts: one factsOf result or a list
|
|
12
|
+
* forRepo(root, { now }) → slipOf of one checkout (its state folder found as `pmos drift` finds it)
|
|
13
|
+
*
|
|
14
|
+
* A TASK IS BEHIND when it is open (not Done, not Won't do), not removed, and its current due date is later than its baseline. Its days
|
|
15
|
+
* behind are the days from the baseline to the current due. They count as UNSOURCED when any move after the baseline rests on no source, by
|
|
16
|
+
* the rule of the weekly what-moved list (lib/week-moves.js sourceOf). A task moved earlier, done, removed or never dated is not behind.
|
|
17
|
+
*
|
|
18
|
+
* AN INITIATIVE ROW: { product, name, ini, title, tasks, days, unsourced_days, worst: { task, title, baseline, due, behind, sourced, owner } }
|
|
19
|
+
*
|
|
20
|
+
* CLI: node lib/plan-baseline.js list|count [<root>] [--json]. `count` ends with the unsourced task-days on its last line.
|
|
21
|
+
* Every log line carries [baseline]. */
|
|
22
|
+
const path = require('path');
|
|
23
|
+
|
|
24
|
+
const TAG = '[baseline]';
|
|
25
|
+
const DAY = 86400000;
|
|
26
|
+
const CLOSED = /^(done|won'?t do|cancel+ed|closed)$/i;
|
|
27
|
+
const isDate = (s) => /^\d{4}-\d{2}-\d{2}/.test(String(s || ''));
|
|
28
|
+
const dayOf = (s) => String(s).slice(0, 10);
|
|
29
|
+
const dayMs = (s) => Date.parse(dayOf(s) + 'T00:00:00Z');
|
|
30
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
31
|
+
const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); };
|
|
32
|
+
|
|
33
|
+
/** Whole days from day a to day b. */
|
|
34
|
+
function daysBetween(a, b) { return Math.round((dayMs(b) - dayMs(a)) / DAY); }
|
|
35
|
+
|
|
36
|
+
/** A task's first due date, its current one, whether it is open, and the lines that moved its date after the first. PURE. */
|
|
37
|
+
function baselineOf(t) {
|
|
38
|
+
const lines = (t && t.lines ? t.lines : []).filter((l) => Number.isFinite(l.at)).slice().sort((a, b) => a.at - b.at);
|
|
39
|
+
let baseline = null, due = null, state, removed = false, owner;
|
|
40
|
+
const moves = [];
|
|
41
|
+
for (const l of lines) {
|
|
42
|
+
if (l.kind === 'task-remove') removed = true;
|
|
43
|
+
if (l.kind === 'task-restore') removed = false;
|
|
44
|
+
if (typeof l.state === 'string' && l.state) state = l.state;
|
|
45
|
+
if (typeof l.owner === 'string' && l.owner.trim()) owner = l.owner;
|
|
46
|
+
if (l.due === undefined) continue;
|
|
47
|
+
const next = isDate(l.due) ? dayOf(l.due) : null;
|
|
48
|
+
if (baseline === null) { if (next) baseline = next; due = next; continue; }
|
|
49
|
+
if (next !== due) moves.push(l);
|
|
50
|
+
due = next;
|
|
51
|
+
}
|
|
52
|
+
return { baseline, due, state: state || '', open: !CLOSED.test(String(state || '').trim()), removed, owner, moves };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Task-days behind the first plan, per initiative and per product. PURE. */
|
|
56
|
+
function slipOf(facts, { today = localDay(Date.now()) } = {}) {
|
|
57
|
+
const WM = require('./week-moves.js');
|
|
58
|
+
const list = (Array.isArray(facts) ? facts : [facts]).filter(Boolean);
|
|
59
|
+
const rows = [];
|
|
60
|
+
for (const f of list) {
|
|
61
|
+
const titles = new Map((f.initiatives || []).map((i) => [i.id, i.title || i.id]));
|
|
62
|
+
const by = new Map();
|
|
63
|
+
for (const t of f.tasks || []) {
|
|
64
|
+
const b = baselineOf(t);
|
|
65
|
+
if (!b.open || b.removed || !b.baseline || !b.due || b.due <= b.baseline) continue;
|
|
66
|
+
const behind = daysBetween(b.baseline, b.due);
|
|
67
|
+
const sourced = b.moves.every((l) => WM.sourceOf(l).sourced);
|
|
68
|
+
const r = by.get(t.initiative) || { product: f.ws, name: f.name || f.ws, ini: t.initiative, title: titles.get(t.initiative) || t.initiative, tasks: 0, days: 0, unsourced_days: 0, worst: null };
|
|
69
|
+
r.tasks++; r.days += behind; if (!sourced) r.unsourced_days += behind;
|
|
70
|
+
if (!r.worst || behind > r.worst.behind) r.worst = { task: t.id, title: t.title, baseline: b.baseline, due: b.due, behind, sourced, owner: WM.ownerOf(b.owner).owner };
|
|
71
|
+
by.set(t.initiative, r);
|
|
72
|
+
}
|
|
73
|
+
rows.push(...by.values());
|
|
74
|
+
}
|
|
75
|
+
rows.sort((a, b) => b.unsourced_days - a.unsourced_days || b.days - a.days || String(a.title).localeCompare(String(b.title)));
|
|
76
|
+
const sum = (k) => rows.reduce((s, r) => s + r[k], 0);
|
|
77
|
+
return { today, initiatives: rows, tasks: sum('tasks'), days: sum('days'), unsourced_days: sum('unsourced_days') };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One checkout's slip. Reads its ledgers; writes nothing. */
|
|
81
|
+
function forRepo(root, { now = Date.now(), name } = {}) {
|
|
82
|
+
const Dr = require('./driver.js');
|
|
83
|
+
const f = require('./drift-facts.js').factsOf({ id: Dr.wsIdOf(root), name: name || path.basename(root), root }, { stateDir: Dr.stateDirOf(root) });
|
|
84
|
+
return { notRead: f.notRead, ...slipOf(f, { today: localDay(now) }) };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
|
|
88
|
+
|
|
89
|
+
function main(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Date.now() } = {}) {
|
|
90
|
+
const pos = [], flags = {};
|
|
91
|
+
for (const a of argv) { if (a === '--json') flags.json = true; else pos.push(a); }
|
|
92
|
+
const [sub = 'list', rootArg] = pos;
|
|
93
|
+
if (!['list', 'count'].includes(sub)) { say('usage: node lib/plan-baseline.js list|count [<root>] [--json] — open tasks behind their first plan, and the days with no source'); return 2; }
|
|
94
|
+
const root = path.resolve(cwd, rootArg || '.');
|
|
95
|
+
let r;
|
|
96
|
+
try { r = forRepo(root, { now }); } catch (e) { say(`${TAG} could not read ${root}: ${(e && e.message) || e}`); return 1; }
|
|
97
|
+
if (flags.json) { say(JSON.stringify(sub === 'count' ? { today: r.today, tasks: r.tasks, days: r.days, unsourced_days: r.unsourced_days, notRead: r.notRead } : r)); return 0; }
|
|
98
|
+
if (sub === 'list') for (const x of r.initiatives) say(`${x.unsourced_days ? '!' : ' '} ${x.title} · ${plural(x.tasks, 'task', 'tasks')} · ${plural(x.days, 'day', 'days')} behind the first plan, ${x.unsourced_days} with no source · worst: ${x.worst.title} (due ${x.worst.baseline} → ${x.worst.due})`);
|
|
99
|
+
say(`${TAG} ${plural(r.tasks, 'open task', 'open tasks')} behind the first plan, ${plural(r.days, 'task-day', 'task-days')} in all, ${r.unsourced_days} with no source${r.notRead.length ? ' (not read: ' + r.notRead.join(', ') + ')' : ''}`);
|
|
100
|
+
if (sub === 'count') say(String(r.unsourced_days));
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = { baselineOf, daysBetween, slipOf, forRepo, main, TAG };
|
|
105
|
+
|
|
106
|
+
if (require.main === module) process.exitCode = main(process.argv.slice(2));
|
|
@@ -45,7 +45,7 @@ const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-'
|
|
|
45
45
|
const WHY = {
|
|
46
46
|
populate: 'The PM just added this initiative. It most likely already lives elsewhere: find it in every connected source and file what you find (Found elsewhere).',
|
|
47
47
|
check: 'The morning check: some tasks are late or at risk. Find why each one slipped and file new dates, "looks done" and tidy names.',
|
|
48
|
-
outcome: 'Its outcome check date has passed and its goal\'s own reading did not decide it. Read its records and file whether it worked (`pmos propose verdict`),
|
|
48
|
+
outcome: 'Its outcome check date has passed and its goal\'s own reading did not decide it. Read its records and file whether it worked (`pmos propose verdict`); when you cannot tell, file `cant-tell` with what you read and what was missing.',
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
function promptOf(skill, o) {
|
|
@@ -192,7 +192,7 @@ function clean(group, type, input) {
|
|
|
192
192
|
// PMOS's own verdict on a due outcome (initiative outcome-checks-run-themselves; lib/outcome-judge.js, or the outcome run's `pmos propose
|
|
193
193
|
// verdict`). Class B: applied by itself with Undo, it records the check in outcome_checks.jsonl (lib/outcomes.js recordCheck)
|
|
194
194
|
const d = isObj(input.data) ? input.data : {};
|
|
195
|
-
if (!['validated', 'refuted'].includes(d.disposition)) return { error: 'data.disposition is validated or
|
|
195
|
+
if (!['validated', 'refuted', 'inconclusive'].includes(d.disposition)) return { error: 'data.disposition is validated, refuted or inconclusive (can\'t tell, with what was read and what was missing: initiative outcome-checks-finish)' };
|
|
196
196
|
const evidence = one(d.evidence, 600);
|
|
197
197
|
if (evidence.length < 12) return { error: 'data.evidence says what shows it, at least 12 characters' };
|
|
198
198
|
if (!DAY_RE.test(str(d.horizon))) return { error: 'data.horizon is the check date it answers, YYYY-MM-DD' };
|
|
@@ -87,8 +87,11 @@ const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (a
|
|
|
87
87
|
|
|
88
88
|
/** `pmos propose verdict`: the outcome run's verdict on a due check (initiative outcome-checks-run-themselves). Every claim's quote must be
|
|
89
89
|
* on its path:line in the repository (lib/ai-guard.js check) or nothing is filed. It files the class B verdict ✦; the server records it
|
|
90
|
-
* with Undo (lib/routes-proposals.js applyOne). "cant-tell"
|
|
91
|
-
|
|
90
|
+
* with Undo (lib/routes-proposals.js applyOne). "cant-tell" is a verdict too (initiative outcome-checks-finish): it files the same class B ✦ as
|
|
91
|
+
* `inconclusive`, with what the run read and what was missing as its evidence, so the PM is not left a question. Its claims are optional;
|
|
92
|
+
* any it gives still pass the guard. */
|
|
93
|
+
const VERDICT = { worked: 'validated', 'didnt-work': 'refuted', validated: 'validated', refuted: 'refuted', 'cant-tell': 'inconclusive', inconclusive: 'inconclusive' };
|
|
94
|
+
const SAID = { validated: 'worked', refuted: 'didn\'t work', inconclusive: 'can\'t tell' };
|
|
92
95
|
function verdict(args, { say, stdin, env, file, runId, ini, board, F, line }) {
|
|
93
96
|
const root = env.PMOS_PROPOSE_ROOT;
|
|
94
97
|
if (!root) { say('✗ pmos propose verdict is for PMOS\'s outcome run (the server pins PMOS_PROPOSE_ROOT)'); return 1; }
|
|
@@ -96,17 +99,23 @@ function verdict(args, { say, stdin, env, file, runId, ini, board, F, line }) {
|
|
|
96
99
|
if (!src) { say('usage: pmos propose verdict --json <file|->'); return 2; }
|
|
97
100
|
const r = readJson(src, stdin); if (r.error) { say('✗ ' + r.error); return 1; }
|
|
98
101
|
const b = r.body && typeof r.body === 'object' && !Array.isArray(r.body) ? r.body : {};
|
|
99
|
-
if (b.disposition === 'cant-tell' || b.disposition === 'inconclusive') { say('filed nothing: the check stays due and Your move asks the PM'); return 0; }
|
|
100
102
|
const disposition = VERDICT[b.disposition];
|
|
101
103
|
if (!disposition) { say('✗ refused: disposition is worked, didnt-work or cant-tell'); return 1; }
|
|
102
104
|
const O = require('./outcomes.js'), AG = require('./ai-guard.js'), J = require('./outcome-judge.js');
|
|
103
105
|
const it = O.scan(root).due.find((x) => x.id === ini);
|
|
104
106
|
if (!it) { say(`✗ refused: ${ini} has no outcome check due now`); return 1; }
|
|
105
107
|
const evidence = String(b.evidence || '').replace(/\s+/g, ' ').trim();
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const cant = disposition === 'inconclusive';
|
|
109
|
+
if (cant && evidence.length < 24) { say('✗ refused: a can\'t tell needs its evidence: what you read and what was missing (at least 24 characters)'); return 1; }
|
|
110
|
+
let sources = [];
|
|
111
|
+
if (!cant || (Array.isArray(b.claims) && b.claims.length)) {
|
|
112
|
+
const c0 = AG.check({ id: 'outcome-verdict:' + ini, title: J.WORDS[disposition], say: evidence || '-', confidence: 'medium', cls: 'B', claims: b.claims }, { root, stateDir: require('path').dirname(file) });
|
|
113
|
+
if (!c0.ok) { say('✗ refused: ' + c0.errors.join('; ')); return 1; }
|
|
114
|
+
sources = c0.p.claims.flatMap((c) => c.sources).filter((x) => x.verified).map((x) => ({ label: x.label, ref: x.ref }));
|
|
115
|
+
}
|
|
116
|
+
// a can't tell with no claims cites the record's outcome line, so it is never a change with no source (lib/autonomy.js)
|
|
117
|
+
if (!sources.length && it.fm && it.fm.outcome_metric) sources = [{ label: 'Expected outcome', ref: it.record + ':' + it.fm.outcome_metric.n }];
|
|
118
|
+
const why = `Its check date was ${O.short(it.horizon)}. ${evidence.replace(/[.\s]+$/, '')}. PMOS recorded "${SAID[disposition]}". Undo takes it back.`;
|
|
110
119
|
const c = PR.clean('outcome', 'verdict', { title: `${J.WORDS[disposition]}: ${it.title}`.slice(0, 120), why, sources, items: [{ id: 'verdict', title: J.WORDS[disposition] }], data: { disposition, evidence, horizon: it.horizon } });
|
|
111
120
|
if (c.error) { say('✗ refused: ' + c.error); return 1; }
|
|
112
121
|
const id = PR.idOf(ini, 'outcome', 'verdict', it.horizon);
|
|
@@ -98,6 +98,7 @@ const MODULES = Object.freeze([
|
|
|
98
98
|
'routes-proposals', // batch 12 items 2, 3 and 4: everything Claude proposes on an initiative, under its one ✦ (proposals.jsonl; page-press POST)
|
|
99
99
|
'routes-autonomy', // D106: what agents did by themselves (the Done group, 14 days), its Undo, and the demotions Home says once (autonomy.jsonl)
|
|
100
100
|
'routes-your-move', // workspace grill W3: Your move's overdue outcome verdicts (drafted from Jira) and the first key result with no reading (GET)
|
|
101
|
+
'routes-tracker-sync', // tracker-sync-on-today: the sync with Jira of a product, the PM's ✓ that takes Jira's value, and its Undo (task ledger; page-press POST)
|
|
101
102
|
'routes-standing-rules', // standing-rules-list (A470): the standing rules PMOS keeps, with edit, retire and bring back (memory + standing-rules.jsonl)
|
|
102
103
|
'routes-lab', // idle lab (build U): Intelligence › Lab, the compare view, the specimen files and the Lab's own ✦ (idle-lab.jsonl; page-press POST)
|
|
103
104
|
'routes-loose', // batch 13 item 3: Claude's clean-up of Home's "Not in an initiative" under the group's ✦ (loose-props/; page-press POST)
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* POST /api/drift/looked { week } → { ok } the card was shown for that week
|
|
11
11
|
* GET /api/drift/moves?ws=<id>[&week=YYYY-MM-DD] → { ok, ws, name, week, label, notRead, rows, total, unsourced } the weekly what-moved list of
|
|
12
12
|
* one product (initiative weekly-what-moved, lib/week-moves.js): last week by default; read-only
|
|
13
|
+
* GET /api/drift/slip?ws=<id> → { ok, ws, name, notRead, today, initiatives, tasks, days, unsourced_days } open tasks behind
|
|
14
|
+
* their first plan (initiative slip-baseline-contradictions, lib/plan-baseline.js); read-only
|
|
15
|
+
* GET /api/drift/contradictions?ws=<id> → { ok, ws, name, notRead, items, total } records that disagree (lib/contradictions.js); read-only
|
|
13
16
|
*
|
|
14
17
|
* THE SWITCH. PMOS_DRIFT=off, or the shared guard's switch (lib/ai-guard.js off: PMOS_AI, the ai settings): every GET answers { ok, on: false }
|
|
15
18
|
* and every POST 409. WHO WRITES: a POST that carries an agent session header is refused (403); pm-guard requirePagePress checks the page. */
|
|
@@ -60,6 +63,33 @@ async function handle(req, res, url, ctx) {
|
|
|
60
63
|
return send(bad(500, 'The moves could not be read.'));
|
|
61
64
|
}
|
|
62
65
|
}
|
|
66
|
+
if (what === 'slip' || what === 'contradictions') {
|
|
67
|
+
// every slip against the first plan (lib/plan-baseline.js) and records that disagree (lib/contradictions.js): initiative
|
|
68
|
+
// slip-baseline-contradictions. Read-only, no model, so the drift switch does not gate them.
|
|
69
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
70
|
+
let w = null;
|
|
71
|
+
try { w = ctx.getWs(url.searchParams.get('ws') || null); } catch { w = null; }
|
|
72
|
+
if (!w || !w.root) return send(bad(404, 'no such workspace'));
|
|
73
|
+
const mod = what === 'slip' ? require('./plan-baseline.js') : require('./contradictions.js');
|
|
74
|
+
try {
|
|
75
|
+
const stateDir = ctx.stateDirFor ? ctx.stateDirFor(w) : null;
|
|
76
|
+
let rows = [];
|
|
77
|
+
try { const IR = require('./initiative-rows.js').rowsFor(w.root); rows = IR && IR.ok ? IR.rows : []; } catch { rows = []; }
|
|
78
|
+
const f = require('./drift-facts.js').factsOf({ id: w.id, name: w.name || w.id, root: w.root }, { stateDir, rows });
|
|
79
|
+
const now = nowMs(ctx);
|
|
80
|
+
if (what === 'slip') {
|
|
81
|
+
const r = mod.slipOf(f, { today: new Date(now).toISOString().slice(0, 10) });
|
|
82
|
+
console.log(`${mod.TAG} ws=${w.id} tasks=${r.tasks} days=${r.days} unsourced_days=${r.unsourced_days}`);
|
|
83
|
+
return send({ status: 200, body: { ok: true, ws: w.id, name: w.name || w.id, notRead: f.notRead, ...r } });
|
|
84
|
+
}
|
|
85
|
+
const items = mod.contradictionsOf(f, { now });
|
|
86
|
+
console.log(`${mod.TAG} ws=${w.id} items=${items.length}`);
|
|
87
|
+
return send({ status: 200, body: { ok: true, ws: w.id, name: w.name || w.id, notRead: f.notRead, items, total: items.length } });
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.warn(mod.TAG + ' could not read ' + w.id + ': ' + ((e && e.message) || e));
|
|
90
|
+
return send(bad(500, 'The records could not be read.'));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
63
93
|
if (!['drop', 'undo', 'looked'].includes(what)) return send(bad(404, 'no such drift route'));
|
|
64
94
|
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
65
95
|
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'Only you drop an item, from the page.'));
|
|
@@ -123,12 +123,17 @@ async function realBrief(ctx, ev, date) {
|
|
|
123
123
|
const layers = require('./calendar-layers.js');
|
|
124
124
|
const views = require('./routes-calendar-views.js');
|
|
125
125
|
let inis = [];
|
|
126
|
-
if (root) { try { const facts = await require('./facts-async.js').readFactsAsync(root); inis = ((facts && facts.inis) || []).filter((i) => i && i.id).map((i) => ({ id: i.id, title: i.title || i.id, status: null })); } catch { inis = []; } }
|
|
126
|
+
if (root) { try { const facts = await require('./facts-async.js').readFactsAsync(root); inis = ((facts && facts.inis) || []).filter((i) => i && i.id).map((i) => ({ id: i.id, title: i.title || i.id, status: null, parent_kr: i.parent_kr || null })); } catch { inis = []; } }
|
|
127
127
|
const src = root ? views.readers(root, ctx.runtimeDir).readContextSources() : { notes: [], planItems: [], ownItems: [] };
|
|
128
128
|
const mine = (src.notes || []).filter((n) => n.meeting && (n.meeting.event_id === ev.id || n.meeting.event_id === baseId(ev.id)));
|
|
129
129
|
let links = null; try { links = require('./calendar-links.js').read(ctx.runtimeDir); } catch { links = null; }
|
|
130
130
|
let boards = null; try { boards = require('./routes-boards.js').meetingBoards(ctx); } catch { boards = null; }
|
|
131
131
|
brief = layers.briefOf(ev, mine, src, { today: localDay(Date.now()), inis, links, boards }).brief || null;
|
|
132
|
+
// meeting-float: the initiative's goal, from its anchor (a key result, an objective or a health budget)
|
|
133
|
+
if (brief && brief.initiative && root) {
|
|
134
|
+
const row = inis.find((i) => i.id === brief.initiative.id);
|
|
135
|
+
if (row && row.parent_kr) { try { const g = F.goalOf(row.parent_kr, require('./initiative-rows.js').anchorsOf(root).resolve); if (g) brief.initiative.goal = g; } catch { /* no goal */ } }
|
|
136
|
+
}
|
|
132
137
|
} catch { brief = null; }
|
|
133
138
|
briefCache.set(key, { at: Date.now(), brief });
|
|
134
139
|
return brief;
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* GET /api/open-questions?ws=<id> → { ok, ws, today, lines: [lib/open-questions.js line], median_age }
|
|
6
6
|
*
|
|
7
7
|
* The day's question list comes from lib/routes-your-move.js questions() with take: false, so this read never takes a default (taking
|
|
8
|
-
* stays with Your move, lib/default-decisions.js). The open Driver drafts come from the repository's driver.jsonl.
|
|
8
|
+
* stays with Your move, lib/default-decisions.js). The open Driver drafts come from the repository's driver.jsonl. Records that disagree come
|
|
9
|
+
* from lib/contradictions.js (initiative slip-baseline-contradictions). Nothing is sent. */
|
|
9
10
|
const OQ = require('./open-questions.js');
|
|
10
11
|
|
|
11
12
|
module.exports = {
|
|
@@ -19,8 +20,14 @@ module.exports = {
|
|
|
19
20
|
const now = Date.now(), today = OQ.localDay(now);
|
|
20
21
|
let questions = null;
|
|
21
22
|
try { questions = require('./routes-your-move.js').questions(ctx, w, today, { take: false }).questions; } catch { questions = null; }
|
|
23
|
+
// records that disagree (lib/contradictions.js): from the initiative rows as already read, never a synchronous derive on a request
|
|
24
|
+
let records = [];
|
|
22
25
|
try {
|
|
23
|
-
const
|
|
26
|
+
const IR = require('./initiative-rows.js').rowsFor(w.root);
|
|
27
|
+
if (IR && IR.ok) records = require('./contradictions.js').forRepo(w.root, { now, rows: IR.rows, id: w.id, name: w.name, stateDir: ctx.stateDirFor ? ctx.stateDirFor(w) : undefined }).items;
|
|
28
|
+
} catch { records = []; }
|
|
29
|
+
try {
|
|
30
|
+
const r = OQ.read(w.root, { now, questions, records });
|
|
24
31
|
console.log(`${OQ.TAG} ws=${w.id} lines=${r.lines.length} median_age=${r.median_age}`);
|
|
25
32
|
ctx.json(res, { ok: true, ws: w.id, ...r });
|
|
26
33
|
} catch (e) { ctx.json(res, { ok: false, error: String((e && e.message) || e) }, 500); }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-tracker-sync.js — the tracker sync of a product on Today, and the PM's ✓ that takes Jira's value, with Undo
|
|
3
|
+
* (initiative tracker-sync-on-today; board TrackerSyncDesk on Exploring 3).
|
|
4
|
+
*
|
|
5
|
+
* GET /api/tracker-sync?ws=<id> → { ok, ws, read, inSync, unread, pct, quiet, readAt, rows, more } lib/task-jira.js syncOf (reads only)
|
|
6
|
+
* POST /api/tracker-sync/take { ws, rows? } → { ok, batch, n } rows: [{ task, field }] or none for every difference (page press)
|
|
7
|
+
* POST /api/tracker-sync/undo { ws, batch } → { ok, batch, n } puts the batch's old values back (page press)
|
|
8
|
+
*
|
|
9
|
+
* The rows are capped at ROWS (Today lists the first ones; take without rows still takes all). Jira is only read: its stored snapshots
|
|
10
|
+
* (lib/jira-status.js readSnapshot). The writes go to the task ledger (lib/tracker-sync-take.js), one [tracker-sync-take] line each. */
|
|
11
|
+
const guard = require('./pm-guard.js');
|
|
12
|
+
const TJ = require('./task-jira.js');
|
|
13
|
+
const TK = require('./tracker-sync-take.js');
|
|
14
|
+
|
|
15
|
+
const ROWS = 50;
|
|
16
|
+
const text = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
17
|
+
const snapOf = (root) => (ini) => require('./jira-status.js').readSnapshot(root, ini);
|
|
18
|
+
|
|
19
|
+
function wsOf(ctx, id) {
|
|
20
|
+
let w = null;
|
|
21
|
+
try { w = ctx.getWs(id || null); } catch { w = null; }
|
|
22
|
+
return w && w.root ? w : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function handle(req, res, url, ctx) {
|
|
26
|
+
const p = url.pathname;
|
|
27
|
+
if (p !== '/api/tracker-sync' && p !== '/api/tracker-sync/take' && p !== '/api/tracker-sync/undo') return false;
|
|
28
|
+
if (p === '/api/tracker-sync') {
|
|
29
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
30
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
31
|
+
if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
32
|
+
let S;
|
|
33
|
+
try { S = TJ.syncOf(TJ.readLines(w.root), snapOf(w.root)); } catch (e) { ctx.json(res, { ok: false, error: 'the sync could not be read: ' + (e && e.message) }, 500); return true; }
|
|
34
|
+
// readAt: the newest Jira read the product's keyed tasks rest on (the ✦ row says "as of"), null with none
|
|
35
|
+
let readAt = null;
|
|
36
|
+
try { const so = snapOf(w.root); for (const ini of TJ.readKeys(w.root).keys()) { const s = so(ini); if (s && s.fetchedAt && (!readAt || s.fetchedAt > readAt)) readAt = s.fetchedAt; } } catch { readAt = null; }
|
|
37
|
+
ctx.json(res, { ok: true, ws: w.id, ...S, readAt, rows: S.rows.slice(0, ROWS), more: Math.max(0, S.rows.length - ROWS) });
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
41
|
+
const read = await ctx.readJson(req);
|
|
42
|
+
if (!read.ok) { ctx.json(res, { ok: false, error: 'the body is not JSON' }, 400); return true; }
|
|
43
|
+
const body = read.body || {};
|
|
44
|
+
const g = guard.requirePagePress(req, body);
|
|
45
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
46
|
+
const w = wsOf(ctx, text(body.ws));
|
|
47
|
+
if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
48
|
+
const by = (g.actor && g.actor.by) || 'pm';
|
|
49
|
+
let r;
|
|
50
|
+
if (p.endsWith('/take')) {
|
|
51
|
+
const pick = Array.isArray(body.rows) ? body.rows.filter((x) => x && text(x.task) && text(x.field)).map((x) => ({ task: text(x.task), field: text(x.field) })) : null;
|
|
52
|
+
if (Array.isArray(body.rows) && !pick.length) { ctx.json(res, { ok: false, error: 'no row named' }, 400); return true; }
|
|
53
|
+
r = TK.take(w.root, snapOf(w.root), { pick, by });
|
|
54
|
+
} else {
|
|
55
|
+
const batch = text(body.batch);
|
|
56
|
+
if (!batch) { ctx.json(res, { ok: false, error: 'no batch named' }, 400); return true; }
|
|
57
|
+
r = TK.undo(w.root, batch, { by });
|
|
58
|
+
}
|
|
59
|
+
try { if (r.ok && ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg(w.id); } catch { /* the next poll recounts */ }
|
|
60
|
+
ctx.json(res, r, r.ok ? 200 : 409);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { prefixes: ['/api/tracker-sync'], handle };
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
* SPRINT DATES (product line slice 3, "Discovery reads tracker assignees and sprints"). An open task whose ticket is in an active or planned
|
|
32
32
|
* sprint with a start and an end takes those days as its start and due, unless someone set the task's dates by hand after it was made.
|
|
33
33
|
* A closed sprint, a backlog ticket or a sprint with no dates changes nothing. The task's own dates stay in the ledger; the read is in memory.
|
|
34
|
+
* FOLLOW (tracker-sync-on-today). A line by the tracker with `follow: true` (the PM took Jira's value on Today, lib/tracker-sync-take.js) hands the
|
|
35
|
+
* owner back to the tracker: its by-hand mark is cleared, so a later Jira move is followed again. A done day by the tracker is never by hand.
|
|
34
36
|
* SYNC (A439). After the read is applied, a task the read returned is in sync when its state, done day and owner match the reading.
|
|
35
37
|
* pct = in sync ÷ read; the tasks the read did not return are counted apart (unread). quiet at 95% or more (zero is silence).
|
|
36
38
|
* STALE. The Jira read is due every day: a read older than 26 hours (lib/freshness.js, jira stale_after_ms) is stale, and so is a task
|
|
@@ -76,7 +78,7 @@ function keyedTasks(lines) {
|
|
|
76
78
|
t.since = typeof e.happened === 'string' ? e.happened : String(e.at || '').slice(0, 10) || null;
|
|
77
79
|
t.dayByHand = typeof e.happened === 'string' && e.by !== BY;
|
|
78
80
|
}
|
|
79
|
-
if (typeof e.owner === 'string') { t.owner = e.owner.trim() || null; if (e.by !== BY) t.ownerAt = e.at || t.ownerAt || 'by-hand'; }
|
|
81
|
+
if (typeof e.owner === 'string') { t.owner = e.owner.trim() || null; if (e.by !== BY) t.ownerAt = e.at || t.ownerAt || 'by-hand'; else if (e.follow) t.ownerAt = null; }
|
|
80
82
|
// SPRINT DATES: a start or due someone wrote after the task was made is theirs; the tracker's own lines are not
|
|
81
83
|
for (const k of ['start', 'due']) if (k in e && e.kind === 'task-update') { t[k] = DAY_RE.test(String(e[k] || '')) ? e[k] : null; if (e.by !== BY) t.datesByHand = true; }
|
|
82
84
|
} else if (e.kind === 'task-remove') {
|
|
@@ -195,7 +197,7 @@ function samePerson(a, b) {
|
|
|
195
197
|
/**
|
|
196
198
|
* How much of PMOS matches the last Jira read (A439). The read is applied first (trackerLines), so what is left is what PMOS keeps on
|
|
197
199
|
* purpose: a state changed after Jira's last move, a done day or an owner set by hand. Each row is
|
|
198
|
-
* { task, key, title, initiative, field: 'state' | 'done day' | 'owner', pmos, tracker }.
|
|
200
|
+
* { task, key, title, initiative, field: 'state' | 'done day' | 'owner', pmos, tracker, pmosAt, trackerAt } (the days each side set it, or null).
|
|
199
201
|
*/
|
|
200
202
|
function syncOf(lines, snapOf) {
|
|
201
203
|
const snap = snapMemo(snapOf);
|
|
@@ -215,7 +217,11 @@ function syncOf(lines, snapOf) {
|
|
|
215
217
|
const who = humanAssignee(rd.assignee);
|
|
216
218
|
if (who && !samePerson(who, t.owner)) diff.push(['owner', t.owner, who]);
|
|
217
219
|
if (!diff.length) { inSync++; continue; }
|
|
218
|
-
|
|
220
|
+
// when each side last set it (tracker-sync-on-today: the list shows which value is newer); a done day is a day itself
|
|
221
|
+
const day10 = (v) => (DAY_RE.test(String(v || '').slice(0, 10)) ? String(v).slice(0, 10) : null);
|
|
222
|
+
const jAt = day10(rd.updated) || day10(rd.resolved);
|
|
223
|
+
const atOf = { state: [day10(t.stateAt), jAt], 'done day': [null, null], owner: [day10(t.ownerAt), jAt] };
|
|
224
|
+
for (const [field, pmos, tracker] of diff) rows.push({ task: t.task, key: t.key, title: t.title, initiative: t.initiative, field, pmos: pmos || null, tracker, pmosAt: atOf[field][0], trackerAt: atOf[field][1] });
|
|
219
225
|
}
|
|
220
226
|
const pct = read ? Math.floor((inSync / read) * 100) : null;
|
|
221
227
|
return { read, inSync, unread, pct, quiet: pct === null || pct >= 95, rows };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* tracker-sync-take.js — take the tracker's value for the tasks where PMOS and the last Jira read differ, with Undo
|
|
3
|
+
* (initiative tracker-sync-on-today; follow-up of tracker-dates-owners-sync, bets A439 and A440; board TrackerSyncDesk on Exploring 3).
|
|
4
|
+
*
|
|
5
|
+
* takeLines(lines, snapOf, { pick, batch, at, by }) PURE → [task-update line] one line per task that differs (or per picked row)
|
|
6
|
+
* undoLines(lines, batch, { at, by }) PURE → [task-update line] the old values of one batch, by hand again
|
|
7
|
+
* batchesOf(lines) PURE → Map batch → { at, n, undone }
|
|
8
|
+
* take(root, snapOf, o) · undo(root, batch, o) write those lines to the initiative ledger (lib/task-store.js write)
|
|
9
|
+
*
|
|
10
|
+
* WHY. After the read (lib/task-jira.js trackerLines) the differences that stay are values someone set by hand in PMOS: an owner, a done
|
|
11
|
+
* day, a state changed after Jira's last move. PMOS never overwrites them alone. The PM's ✓ on Today takes Jira's value.
|
|
12
|
+
* TAKE. Each line is { kind: 'task-update', by: 'tracker:jira', follow: true, take: <batch>, approved: <by>, task, owner?, happened?, state?,
|
|
13
|
+
* was: { owner?, happened?, state? } }. `by` is the tracker and `follow` hands the field back to it: lib/task-jira.js keyedTasks clears the
|
|
14
|
+
* by-hand mark, so a later Jira move is followed again. A done day is written with the state it belongs to.
|
|
15
|
+
* UNDO. One line per task of the batch with the `was` values, by the PM (by hand again: the next read keeps them), and `undo: <batch>`.
|
|
16
|
+
* A batch undone once is not undone twice.
|
|
17
|
+
* BOUNDARY. No network: Jira is only read (its stored snapshots). Writes go to the task ledger only. */
|
|
18
|
+
const TJ = require('./task-jira.js');
|
|
19
|
+
|
|
20
|
+
const FIELD = { owner: 'owner', 'done day': 'happened', state: 'state' };
|
|
21
|
+
|
|
22
|
+
function takeLines(lines, snapOf, o = {}) {
|
|
23
|
+
const S = TJ.syncOf(lines, snapOf);
|
|
24
|
+
const pick = Array.isArray(o.pick) && o.pick.length ? new Set(o.pick.map((p) => p.task + '|' + p.field)) : null;
|
|
25
|
+
const tasks = TJ.keyedTasks((lines || []).concat(TJ.trackerLines(lines, snapOf)));
|
|
26
|
+
const by = new Map();
|
|
27
|
+
for (const r of S.rows) {
|
|
28
|
+
if (pick && !pick.has(r.task + '|' + r.field)) continue;
|
|
29
|
+
const k = FIELD[r.field]; if (!k) continue;
|
|
30
|
+
if (!by.has(r.task)) by.set(r.task, { row: r, set: {}, was: {} });
|
|
31
|
+
const x = by.get(r.task), t = tasks.get(r.task) || {};
|
|
32
|
+
x.set[k] = r.tracker;
|
|
33
|
+
x.was[k] = k === 'happened' ? (t.since || null) : (r.pmos || null);
|
|
34
|
+
if (k === 'happened' && !x.set.state) x.set.state = t.state; // a done day is written with its state, as the board folds it
|
|
35
|
+
}
|
|
36
|
+
const at = o.at || new Date().toISOString();
|
|
37
|
+
return [...by.values()].map(({ row, set, was }) => ({ at, by: TJ.BY, kind: 'task-update', task: row.task, ...set, follow: true, take: o.batch, approved: o.by || 'pm',
|
|
38
|
+
was, why: `took Jira's ${Object.keys(was).map((k) => (k === 'happened' ? 'done day' : k)).join(', ')} (${row.key})` }));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function batchesOf(lines) {
|
|
42
|
+
const out = new Map();
|
|
43
|
+
for (const e of lines || []) {
|
|
44
|
+
if (!e || e.kind !== 'task-update') continue;
|
|
45
|
+
if (e.take) { const b = out.get(e.take) || { at: e.at, n: 0, undone: false }; b.n++; out.set(e.take, b); }
|
|
46
|
+
if (e.undo && out.has(e.undo)) out.get(e.undo).undone = true;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function undoLines(lines, batch, o = {}) {
|
|
52
|
+
const B = batchesOf(lines).get(batch);
|
|
53
|
+
if (!B || B.undone) return [];
|
|
54
|
+
const at = o.at || new Date().toISOString();
|
|
55
|
+
return (lines || []).filter((e) => e && e.kind === 'task-update' && e.take === batch && e.was).map((e) => {
|
|
56
|
+
const back = {};
|
|
57
|
+
if ('owner' in e.was) back.owner = e.was.owner || '';
|
|
58
|
+
if ('state' in e.was && e.was.state) back.state = e.was.state;
|
|
59
|
+
if ('happened' in e.was && e.was.happened) { back.happened = e.was.happened; if (!back.state) back.state = e.state; }
|
|
60
|
+
return { at, by: o.by || 'pm', kind: 'task-update', task: e.task, ...back, undo: batch, why: 'undo: took Jira\'s value' };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const newBatch = () => 'ts-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 6);
|
|
65
|
+
|
|
66
|
+
function writeAll(root, out) {
|
|
67
|
+
const TS = require('./task-store.js');
|
|
68
|
+
let n = 0;
|
|
69
|
+
for (const l of out) { if (!TS.write(root, l)) break; n++; }
|
|
70
|
+
return n;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Take Jira's value: all differences, or o.pick [{ task, field }]. → { ok, batch, n, fields } | { ok: false, error } */
|
|
74
|
+
function take(root, snapOf, o = {}) {
|
|
75
|
+
const batch = newBatch();
|
|
76
|
+
const out = takeLines(TJ.readLines(root), snapOf, { ...o, batch });
|
|
77
|
+
if (!out.length) return { ok: false, error: 'Nothing differs from Jira now. Nothing changed.' };
|
|
78
|
+
const n = writeAll(root, out);
|
|
79
|
+
if (!n) return { ok: false, error: 'The tasks could not be saved. Nothing changed.' };
|
|
80
|
+
console.log(`[tracker-sync-take] root=${root} act=take batch=${batch} tasks=${n}`);
|
|
81
|
+
return { ok: true, batch, n };
|
|
82
|
+
}
|
|
83
|
+
/** Undo one batch. → { ok, batch, n } | { ok: false, error } */
|
|
84
|
+
function undo(root, batch, o = {}) {
|
|
85
|
+
const out = undoLines(TJ.readLines(root), batch, o);
|
|
86
|
+
if (!out.length) return { ok: false, error: 'There is nothing to undo for this change.' };
|
|
87
|
+
const n = writeAll(root, out);
|
|
88
|
+
console.log(`[tracker-sync-take] root=${root} act=undo batch=${batch} tasks=${n}`);
|
|
89
|
+
return n ? { ok: true, batch, n } : { ok: false, error: 'The tasks could not be saved. Nothing changed.' };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { takeLines, undoLines, batchesOf, take, undo };
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
* dates that meet are a guess) is not sourced.
|
|
20
20
|
* owner who to ask: the task's owner, else the PM ('you', toPm) when the plan names nobody or names an agent
|
|
21
21
|
* ref path:line of the line it came from, and `quote` that line's text (lib/drift-facts.js)
|
|
22
|
+
* baseline a date row's first due date (the task's first plan) and `behind` the days from it to the new date, negative when ahead
|
|
23
|
+
* (initiative slip-baseline-contradictions, lib/plan-baseline.js)
|
|
22
24
|
*
|
|
23
25
|
* CLI: node lib/week-moves.js list|count [<root>] [--week YYYY-MM-DD] [--json]. `count` ends with the number of moves on its last line.
|
|
24
26
|
* Every log line carries [moves]. */
|
|
@@ -74,7 +76,7 @@ function productMoves(f, from, to) {
|
|
|
74
76
|
const rows = [], scope = new Map();
|
|
75
77
|
for (const t of f.tasks || []) {
|
|
76
78
|
const lines = (t.lines || []).filter((l) => Number.isFinite(l.at)).slice().sort((a, b) => a.at - b.at);
|
|
77
|
-
let due, owner;
|
|
79
|
+
let due, owner, first = null; // first: the task's first due date, its baseline (lib/plan-baseline.js; initiative slip-baseline-contradictions)
|
|
78
80
|
for (const l of lines) {
|
|
79
81
|
if (typeof l.owner === 'string' && l.owner.trim()) owner = l.owner;
|
|
80
82
|
const inWeek = l.at >= from && l.at < to;
|
|
@@ -89,7 +91,11 @@ function productMoves(f, from, to) {
|
|
|
89
91
|
}
|
|
90
92
|
if (l.due !== undefined) {
|
|
91
93
|
const next = isDate(l.due) ? String(l.due).slice(0, 10) : '';
|
|
92
|
-
if (inWeek && l.kind === 'task-update' && due !== undefined && next !== due)
|
|
94
|
+
if (inWeek && l.kind === 'task-update' && due !== undefined && next !== due) {
|
|
95
|
+
const behind = first && next ? Math.round((Date.parse(next + 'T00:00:00Z') - Date.parse(first + 'T00:00:00Z')) / 86400000) : null;
|
|
96
|
+
rows.push({ ...base(), kind: 'date', n: 1, titles: [t.title], was: due || null, now: next || null, baseline: first, behind });
|
|
97
|
+
}
|
|
98
|
+
if (first === null && next) first = next;
|
|
93
99
|
due = next;
|
|
94
100
|
}
|
|
95
101
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.763.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.763.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|