create-pmos 0.425.0 → 0.427.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 +25 -25
- 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/board-deliveries-test.js +153 -0
- package/workspace/board-programs-test.js +19 -10
- package/workspace/board-shot.js +4 -3
- package/workspace/briefing-premium-board-test.js +2 -2
- package/workspace/calm-timeline-test.js +190 -0
- package/workspace/changelog.json +24 -0
- package/workspace/ev-everywhere-test.js +3 -1
- package/workspace/guide/claude-proposes.md +19 -2
- package/workspace/guide/programs.md +2 -1
- package/workspace/lib/board-premium.js +3 -1
- package/workspace/lib/chat-file-locate.js +40 -2
- package/workspace/lib/context-use.js +54 -0
- package/workspace/lib/engine/boards.js +8 -2
- package/workspace/lib/idle-close.js +60 -0
- package/workspace/lib/loose-proposals.js +302 -0
- package/workspace/lib/my-work-premium.js +1 -1
- package/workspace/lib/proposal-runs.js +77 -2
- package/workspace/lib/propose-cli.js +42 -1
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-boards.js +16 -4
- package/workspace/lib/routes-brief-page.js +9 -1
- package/workspace/lib/routes-live.js +3 -1
- package/workspace/lib/routes-loose.js +210 -0
- package/workspace/lib/routes-pm-items.js +27 -17
- package/workspace/lib/task-cli.js +18 -11
- package/workspace/lib/transcript-read.js +9 -2
- package/workspace/milestone-pins-test.js +170 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +2 -1
- package/workspace/premium-briefing-depth-test.js +1 -1
- package/workspace/premium-chat-term-test.js +13 -2
- package/workspace/premium-core-doc-issue-test.js +1 -1
- package/workspace/product-lane-test.js +30 -17
- package/workspace/public/pm/bd-acts.js +6 -3
- package/workspace/public/pm/bd-deliveries.js +218 -0
- package/workspace/public/pm/bd-pin-card.css +16 -0
- package/workspace/public/pm/bd-pin-card.js +80 -0
- package/workspace/public/pm/bd-pins.js +33 -0
- package/workspace/public/pm/bd-pop.js +2 -0
- package/workspace/public/pm/bd-prog.js +5 -4
- package/workspace/public/pm/bd-span.js +140 -102
- package/workspace/public/pm/cozy-board.css +73 -11
- package/workspace/public/pm/cozy-home.css +23 -1
- package/workspace/public/pm/cozy-live-pill.css +1 -0
- package/workspace/public/pm/cozy-live-pill.js +2 -1
- package/workspace/public/pm/cozy-today.css +7 -0
- package/workspace/public/pm/cozy.css +6 -0
- package/workspace/public/pm/ctx-wedge.js +45 -0
- package/workspace/public/pm/home-app.js +29 -2
- package/workspace/public/pm/home-chat.js +7 -2
- package/workspace/public/pm/home-data.js +6 -3
- package/workspace/public/pm/home-list.js +46 -5
- package/workspace/public/pm/home-today.js +22 -6
- package/workspace/public/pm/ini-tasks.js +4 -1
- package/workspace/public/pm/live-model.js +1 -1
- package/workspace/public/pm/loose-props.css +54 -0
- package/workspace/public/pm/loose-props.js +262 -0
- package/workspace/public/pm/premium-board.js +9 -5
- package/workspace/public/pm/term-view.js +81 -10
- package/workspace/public/premium-board.html +1 -0
- package/workspace/server.js +135 -6
- package/workspace/skills/loose-propose.skill +39 -0
- package/workspace/task-milestones-test.js +15 -6
- package/workspace/test-lists/batch13-context-use.json +5 -0
- package/workspace/test-lists/board-deliveries.json +13 -0
- package/workspace/test-lists/calm-timeline.json +5 -0
- package/workspace/test-lists/loose-props.json +9 -0
- package/workspace/test-lists/milestone-pins.json +6 -0
- package/workspace/timeline-holds-test.js +44 -42
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
*
|
|
21
21
|
* At most 2 runs at once for the machine; one per initiative. A run that ends writes the `end` line; ■ Stop ends it at once.
|
|
22
22
|
*
|
|
23
|
+
* HOME'S CLEAN-UP (batch 13 item 3, lib/loose-proposals.js): the same kind, for the rows under Home's "Not in an initiative" (origin
|
|
24
|
+
* `propose:<ws>:~loose:<run>`, skill loose-propose). It looks with the morning check, once a day, and at once when the group passes 10 rows
|
|
25
|
+
* (rule 7). It reads the rows Home last showed (rows.json) and files with `pmos propose loose …`; the PM's ✓ on Home writes.
|
|
26
|
+
* startLoose({ now, press }) → { ok, run } | { ok: false, error }
|
|
27
|
+
*
|
|
23
28
|
* deps: { workspaces() → [w], isLead(w), stateDirFor(w), boardOf(w, id) → board id | null, created(w) → [{ initiative, at }],
|
|
24
29
|
* checks(w, today) → [{ ini, board, title, tasks: [line] }] (the initiatives with a late or at-risk task), rowOf(w, id) → { title, intent,
|
|
25
30
|
* stage, stages } | null, open(now) → bool (the day-check window), headlessOff() → bool, env, promptFor(skillId) → skill body | null,
|
|
@@ -27,6 +32,7 @@
|
|
|
27
32
|
*/
|
|
28
33
|
const crypto = require('crypto');
|
|
29
34
|
const PR = require('./proposals.js');
|
|
35
|
+
const LP = require('./loose-proposals.js');
|
|
30
36
|
|
|
31
37
|
const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
|
|
32
38
|
const off = (env) => flagOff((env || process.env).PMOS_PROPOSE);
|
|
@@ -48,6 +54,19 @@ function promptOf(skill, o) {
|
|
|
48
54
|
+ 'File with `pmos propose` only (the server pins this initiative and run). Report each source as you read it with `pmos propose look`. Send nothing.';
|
|
49
55
|
}
|
|
50
56
|
|
|
57
|
+
const LOOSE = '~loose';
|
|
58
|
+
/** The prompt of one clean-up run. o: { run, why, today, rows, inis, dropped } */
|
|
59
|
+
function promptOfLoose(skill, o) {
|
|
60
|
+
const list = (a, none) => (a && a.length ? a.map((x) => '- ' + x).join('\n') : '- ' + none);
|
|
61
|
+
const rowLine = (r) => [r.id, r.kind, one(r.title, 120), r.at ? 'last ' + String(r.at).slice(0, 10) : '', r.waits ? 'WAITS ON THE PM' : '', r.late ? 'LATE' : '', r.daily ? 'repeats' : '',
|
|
62
|
+
r.words ? 'last words: "' + one(r.words, 160) + '"' : ''].filter(Boolean).join(' · ');
|
|
63
|
+
return `${skill}\n\nThis run:\n- Run: ${o.run}\n- Why it runs: ${o.why === 'many' ? 'the group passed ' + LP.MANY + ' rows' : 'the morning check'}\n- Today: ${o.today}\n`
|
|
64
|
+
+ `- The rows under "Not in an initiative" (id · kind · title · facts):\n${list((o.rows || []).map(rowLine), 'none')}\n`
|
|
65
|
+
+ `- The PM's open initiatives (id · title · product):\n${list((o.inis || []).map((i) => i.id + ' · ' + one(i.title, 100) + (i.ws ? ' · ' + i.ws : '')), 'none')}\n`
|
|
66
|
+
+ `- Dropped by the PM (do not file these rows again in that group):\n${list(o.dropped, 'none')}\n\n`
|
|
67
|
+
+ 'File with `pmos propose loose` only. Send nothing.';
|
|
68
|
+
}
|
|
69
|
+
|
|
51
70
|
function create(deps) {
|
|
52
71
|
const active = new Map(); // run → { ws, ini, dir, session, why }
|
|
53
72
|
const warn = deps.warn || (() => {});
|
|
@@ -56,6 +75,13 @@ function create(deps) {
|
|
|
56
75
|
function ended(run, r, now = Date.now()) {
|
|
57
76
|
const a = active.get(run); if (!a) return;
|
|
58
77
|
active.delete(run);
|
|
78
|
+
if (a.ini === LOOSE) {
|
|
79
|
+
const L0 = LP.lastLook(LP.read(a.dir)); if (L0 && L0.run === run && L0.ended) return;
|
|
80
|
+
const res0 = (r && r.result) || {};
|
|
81
|
+
const ok0 = !!(r && !r.timedOut && !r.stopped && r.code === 0 && res0.ok !== false && !res0.isError);
|
|
82
|
+
try { LP.append(a.dir, null, { kind: 'end', run, ok: ok0 }); } catch (e) { warn('clean-up run end', e); }
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
59
85
|
const F = PR.read(a.dir), L = F.looks.get(a.ini);
|
|
60
86
|
if (L && L.run === run && L.ended) return; // ■ Stop wrote it already
|
|
61
87
|
const res = (r && r.result) || {};
|
|
@@ -102,6 +128,48 @@ function create(deps) {
|
|
|
102
128
|
return { ok: true, run };
|
|
103
129
|
}
|
|
104
130
|
|
|
131
|
+
/** Home's clean-up: one run over the rows Home last showed loose. → { ok, run } | { ok: false, error, held? } */
|
|
132
|
+
function startLoose({ why = 'check', press = true, now = Date.now() } = {}) {
|
|
133
|
+
if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { ok: false, error: 'Claude\'s background runs are off (PMOS_PROPOSE or PMOS_HEADLESS)' };
|
|
134
|
+
const dir = deps.looseDir ? deps.looseDir() : null, w = deps.homeWs ? deps.homeWs() : null;
|
|
135
|
+
if (!dir || !w) return { ok: false, error: 'no place to keep the clean-up' };
|
|
136
|
+
for (const [r, a] of active) if (a.ini === LOOSE) return { ok: true, run: r, already: true };
|
|
137
|
+
const snap = LP.readRows(dir);
|
|
138
|
+
if (!snap.rows.length) return { ok: false, error: 'nothing sits outside an initiative' };
|
|
139
|
+
const skill = deps.promptFor('loose-propose');
|
|
140
|
+
if (!skill) return { ok: false, error: 'the loose-propose skill is not installed' };
|
|
141
|
+
const run = 'lp' + now.toString(36) + crypto.randomBytes(3).toString('hex');
|
|
142
|
+
const F = LP.read(dir);
|
|
143
|
+
const dropped = [...F.drops].slice(0, 40).map((k) => k.replace('|', ' · '));
|
|
144
|
+
const prompt = promptOfLoose(skill, { run, why, today: localDay(now), rows: snap.rows, inis: snap.inis, dropped });
|
|
145
|
+
const go = press && deps.spawnNow ? deps.spawnNow : deps.spawn;
|
|
146
|
+
active.set(run, { ws: w.id, ini: LOOSE, dir, session: null, why });
|
|
147
|
+
let session = null;
|
|
148
|
+
try {
|
|
149
|
+
session = go({ name: 'Tidy loose work', ws: w.id, origin: `propose:${w.id}:${LOOSE}:${run}`, initialInput: prompt + '\r',
|
|
150
|
+
env: { PMOS_PROPOSE_FILE: LP.ledgerFile(dir), PMOS_PROPOSE_WS: w.id, PMOS_PROPOSE_BOARD: '', PMOS_PROPOSE_INI: LOOSE, PMOS_PROPOSE_RUN: run }, onDone: (r) => ended(run, r) });
|
|
151
|
+
} catch (e) { warn('clean-up run', e); }
|
|
152
|
+
if (session && session.held) { active.delete(run); return { ok: false, held: true, error: 'Claude is busy with other runs; it looks again in a minute' }; }
|
|
153
|
+
LP.append(dir, null, { kind: 'look', run, why, at: new Date(now).toISOString() });
|
|
154
|
+
if (!session || session.state === 'exited' || session.headless !== 'propose') {
|
|
155
|
+
if (session && session.headless !== 'propose' && session.state !== 'exited' && deps.stop) { try { deps.stop(session); } catch { /* best effort */ } }
|
|
156
|
+
ended(run, { code: 1, note: (session && session.note) || 'the run could not start in the background', result: {} }, now);
|
|
157
|
+
return { ok: false, error: (session && session.note) || 'Claude could not start looking' };
|
|
158
|
+
}
|
|
159
|
+
const a = active.get(run); if (a) a.session = session;
|
|
160
|
+
return { ok: true, run };
|
|
161
|
+
}
|
|
162
|
+
/** Is the clean-up due? The morning check once a day, or the group passed 10 rows since the last look (rule 7). → 'check' | 'many' | null */
|
|
163
|
+
function looseDue(now, open) {
|
|
164
|
+
const dir = deps.looseDir ? deps.looseDir() : null; if (!dir) return null;
|
|
165
|
+
const snap = LP.readRows(dir); if (!snap.rows.length) return null;
|
|
166
|
+
const L = LP.lastLook(LP.read(dir));
|
|
167
|
+
if (L && !L.ended) return null;
|
|
168
|
+
if (snap.over10 && (!L || String(L.at) < snap.over10)) return 'many';
|
|
169
|
+
if (open && (!L || localDay(Date.parse(L.at) || 0) !== localDay(now))) return 'check';
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
105
173
|
function stop(run) { const a = active.get(run); if (a && a.session && deps.stop) deps.stop(a.session); }
|
|
106
174
|
|
|
107
175
|
function tick({ now = Date.now(), env } = {}) {
|
|
@@ -139,10 +207,17 @@ function create(deps) {
|
|
|
139
207
|
if (r.held) { lastScan.delete(w.id); return { held: true }; }
|
|
140
208
|
}
|
|
141
209
|
}
|
|
210
|
+
let why = null;
|
|
211
|
+
try { why = looseDue(now, open); } catch (e) { warn('clean-up scan', e); }
|
|
212
|
+
if (why) {
|
|
213
|
+
const r = startLoose({ why, press: false, now });
|
|
214
|
+
if (r.ok) return { started: LOOSE, why };
|
|
215
|
+
if (r.held) return { held: true };
|
|
216
|
+
}
|
|
142
217
|
return { started: null };
|
|
143
218
|
}
|
|
144
219
|
|
|
145
|
-
return { tick, start, stop, active: () => [...active.keys()] };
|
|
220
|
+
return { tick, start, startLoose, looseDue, stop, active: () => [...active.keys()] };
|
|
146
221
|
}
|
|
147
222
|
|
|
148
|
-
module.exports = { off, promptOf, create, WHY, MAX };
|
|
223
|
+
module.exports = { off, promptOf, promptOfLoose, create, WHY, MAX, LOOSE };
|
|
@@ -9,14 +9,17 @@
|
|
|
9
9
|
* pmos propose done --json <file|-> "looks done": the evidence says the work happened
|
|
10
10
|
* pmos propose name --json <file|-> tidy names, before → after; the detail cut goes to the notes
|
|
11
11
|
* pmos propose status what is open, kept and dropped on this initiative (read)
|
|
12
|
+
* pmos propose loose link|merge|finish|start --json <file|-> Home's clean-up of "Not in an initiative" (batch 13 item 3,
|
|
13
|
+
* lib/loose-proposals.js), only in the clean-up run (PMOS_PROPOSE_INI=~loose); `loose status` reads
|
|
12
14
|
*
|
|
13
15
|
* The server pins the initiative, the board, the run and the ledger in the run's environment (PMOS_PROPOSE_INI, _BOARD, _RUN, _FILE);
|
|
14
16
|
* outside such a run the verb refuses: the PM keeps and drops on the page. It writes `src` and `propose` lines only. A proposal the PM
|
|
15
17
|
* dropped from the same evidence answers `dropped`. Exit codes: 0 filed, 1 refused, 2 usage. Nothing is sent. */
|
|
16
18
|
const fs = require('fs');
|
|
17
19
|
const PR = require('./proposals.js');
|
|
20
|
+
const LP = require('./loose-proposals.js');
|
|
18
21
|
|
|
19
|
-
const COMMANDS = { propose: ['look', 'found', 'date', 'done', 'name', 'status'] };
|
|
22
|
+
const COMMANDS = { propose: ['look', 'found', 'date', 'done', 'name', 'status', 'loose'] };
|
|
20
23
|
const USAGE = [
|
|
21
24
|
'usage: pmos propose look|found|date|done|name|status — what Claude proposes on an initiative, under its ✦',
|
|
22
25
|
' pmos propose look <source> --reading | --found <n> --what "<5 documents>" | --none',
|
|
@@ -32,8 +35,44 @@ const USAGE = [
|
|
|
32
35
|
' pmos propose name --json <file|-> { "why", "sources", "items": [{ "task", "to", "notes"? }] } verb first, sentence case, about 7 words,',
|
|
33
36
|
' the WBS number kept, no "+" and no brackets; the cut detail goes in notes',
|
|
34
37
|
' pmos propose status',
|
|
38
|
+
' pmos propose loose link --json - { "initiative", "title", "why", "items": [{ "row" }] } rows that belong to one open initiative',
|
|
39
|
+
' pmos propose loose merge --json - { "into": "w:<item>", "why", "items": [{ "row": "c:<chat>" }] } a chat that doubles the PM\'s own item',
|
|
40
|
+
' pmos propose loose finish --json - { "why", "items": [{ "row", "quote", "at": "YYYY-MM-DD" }] } the message that closed the work; no quote, no finish',
|
|
41
|
+
' pmos propose loose start --json - { "title", "intent", "anchor", "why", "items": [{ "row" }, …3 or more] } one new thing, not an open initiative',
|
|
42
|
+
' pmos propose loose status',
|
|
35
43
|
'Every proposal carries its source. It waits for the PM\'s ✓ on the page. Nothing is sent.',
|
|
36
44
|
];
|
|
45
|
+
const LOOSE_TYPES = { link: ['link', 'ini'], merge: ['tidy', 'merge'], finish: ['tidy', 'finish'], start: ['start', 'new'] };
|
|
46
|
+
/** `pmos propose loose …`: Home's clean-up run files what the ✦ on "Not in an initiative" proposes. */
|
|
47
|
+
function loose(args, { say, stdin, file, runId }) {
|
|
48
|
+
const sub = args[1];
|
|
49
|
+
const F = LP.fold(LP.readLines(file));
|
|
50
|
+
if (sub === 'status') {
|
|
51
|
+
const kept = new Set(F.kept.filter((k) => !F.undone.has(k.batch)).flatMap((k) => k.ids));
|
|
52
|
+
if (!F.props.size) say('nothing filed');
|
|
53
|
+
for (const p of F.props.values()) say(`${kept.has(p.id) ? 'kept' : 'open'} ${p.group}/${p.type} ${p.id} · ${p.items.length} rows · ${p.why}`);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
if (!LOOSE_TYPES[sub]) { say('usage: pmos propose loose link|merge|finish|start --json <file|-> or pmos propose loose status'); return 2; }
|
|
57
|
+
const L = LP.lastLook(F);
|
|
58
|
+
if (!L || L.run !== runId || L.ended) { say('✗ this run is not looking now (it ended, or the PM pressed Stop)'); return 1; }
|
|
59
|
+
const jsonAt = args.indexOf('--json'), src = jsonAt >= 0 ? args[jsonAt + 1] : null;
|
|
60
|
+
if (!src) { say(`usage: pmos propose loose ${sub} --json <file|->`); return 2; }
|
|
61
|
+
const r = readJson(src, stdin); if (r.error) { say('✗ ' + r.error); return 1; }
|
|
62
|
+
const [group, type] = LOOSE_TYPES[sub];
|
|
63
|
+
let bad = 0;
|
|
64
|
+
for (const x of Array.isArray(r.body) ? r.body : [r.body]) {
|
|
65
|
+
const c = LP.clean(group, type, x);
|
|
66
|
+
if (c.error) { say(`✗ refused: ${c.error}`); bad++; continue; }
|
|
67
|
+
// rule 6: a row the PM dropped or left out in this group is not proposed again
|
|
68
|
+
const scope = LP.scopeOf(group), was = c.prop.items.length;
|
|
69
|
+
c.prop.items = c.prop.items.filter((it) => !F.drops.has(scope + '|' + it.row));
|
|
70
|
+
if (!c.prop.items.length) { say(`dropped ${c.prop.id}: the PM left these rows out`); continue; }
|
|
71
|
+
fs.appendFileSync(file, JSON.stringify({ at: new Date().toISOString(), by: null, kind: 'propose', run: runId, ...c.prop }) + '\n');
|
|
72
|
+
say(`filed ${c.prop.id} · ${group}/${type} · ${c.prop.items.length} rows${was > c.prop.items.length ? ' (' + (was - c.prop.items.length) + ' left out by the PM)' : ''}`);
|
|
73
|
+
}
|
|
74
|
+
return bad ? 1 : 0;
|
|
75
|
+
}
|
|
37
76
|
const GROUP = { found: 'found', date: 'dates', done: 'status', name: 'names' };
|
|
38
77
|
|
|
39
78
|
function readJson(src, stdin) {
|
|
@@ -50,6 +89,8 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
|
|
|
50
89
|
if (!COMMANDS.propose.includes(verb)) { say(`unknown propose command "${verb}" — one of ${COMMANDS.propose.join(', ')}`); return 2; }
|
|
51
90
|
const file = env.PMOS_PROPOSE_FILE, runId = env.PMOS_PROPOSE_RUN, ini = env.PMOS_PROPOSE_INI, board = env.PMOS_PROPOSE_BOARD || '';
|
|
52
91
|
if (!file || !runId || !ini) { say('✗ pmos propose is for Claude\'s proposal run. The PM keeps and drops proposals on the page, under the initiative\'s ✦'); return 1; }
|
|
92
|
+
if ((verb === 'loose') !== (ini === '~loose')) { say(verb === 'loose' ? '✗ pmos propose loose is for Home\'s clean-up run' : '✗ this is Home\'s clean-up run: file with pmos propose loose'); return 1; }
|
|
93
|
+
if (verb === 'loose') return loose(args, { say, stdin, file, runId });
|
|
53
94
|
const F = PR.fold(PR.readLines(file));
|
|
54
95
|
const line = (ev) => { fs.appendFileSync(file, JSON.stringify({ at: new Date().toISOString(), by: null, ...ev }) + '\n'); };
|
|
55
96
|
|
|
@@ -76,6 +76,7 @@ const MODULES = Object.freeze([
|
|
|
76
76
|
'routes-task-plans', // batch 11 item 8: drafts of an initiative's tasks, saved plans, Make live (task-plans.jsonl; page-press POST)
|
|
77
77
|
'routes-task-links', // batch 11 item 15: links between tasks, Claude's proposals, the quiet moves (task-links.jsonl; page-press POST)
|
|
78
78
|
'routes-proposals', // batch 12 items 2, 3 and 4: everything Claude proposes on an initiative, under its one ✦ (proposals.jsonl; page-press POST)
|
|
79
|
+
'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)
|
|
79
80
|
'routes-workflows', // workflows-per-initiative (D99): the workflow library, save, copy, archive and the chat's draft (workflows.jsonl; page-press POST)
|
|
80
81
|
'routes-settings', // console3 Settings: the settings store for settings with no home of their own (GET; page-press POST)
|
|
81
82
|
'routes-hooks', // planning-flows run 7: CLI hook endpoints (session token, per-run JSONL)
|
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
* POST /api/boards/tasks/reschedule { ws, board, task, days } → { ok, item }
|
|
30
30
|
* POST /api/boards/tasks/undo-add { ws, board, task } → { ok } takes back a task added in the last 2 minutes, still To do
|
|
31
31
|
* POST /api/boards/tasks/rename { ws, board, task, title } → { ok, from, item } only the title changes
|
|
32
|
-
* POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative?, section?, milestone? } → { ok, from, item } the Viewer's edits in place
|
|
32
|
+
* POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative?, section?, milestone?, pinned? } → { ok, from, item } the Viewer's edits in place
|
|
33
33
|
* (milestone: true | false, the ◇ flag of batch 11 item 3; a Jira key takes the flag only)
|
|
34
|
+
* (pinned: true | false | null, a milestone's pin on the Board timeline, batch 13 item 4; null = the rule, the last one only)
|
|
34
35
|
* (section: the task's place in the breakdown, a stage key of its initiative's workflow or '' — a task-section line)
|
|
35
36
|
* (canvas XetX1Rest); `from` holds the fields as they were, so Undo is the same call with `from`
|
|
36
37
|
* POST /api/boards/tickets/note { ws, board, ref, notes } → { ok, from, notes } the PM's notes on a Jira ticket
|
|
@@ -547,6 +548,9 @@ function itemsOf(w, fr, board, rows) {
|
|
|
547
548
|
// a task flagged as a milestone (feedback batch 11 item 3): the PM's flag on the board ledger, else a breakdown item's own plan-items flag
|
|
548
549
|
const MS = fr.folded.milestones || new Map();
|
|
549
550
|
for (const x of out) if (x.kind !== 'Epic') { const on = MS.has(x.uid) ? MS.get(x.uid) : !!x.milestone; if (on) x.milestone = true; else delete x.milestone; }
|
|
551
|
+
// the PM's pin on a milestone (batch 13 item 4, XcalmA5Milestones): carried only when set, so an unset one follows the rule (the last one shows)
|
|
552
|
+
const PN = fr.folded.pins || new Map();
|
|
553
|
+
if (PN.size) for (const x of out) if (x.kind !== 'Epic' && PN.has(x.uid)) x.pinned = PN.get(x.uid);
|
|
550
554
|
return B.rollupItems(out);
|
|
551
555
|
}
|
|
552
556
|
|
|
@@ -1228,11 +1232,14 @@ const WRITES = {
|
|
|
1228
1232
|
const p = postFrame(ctx, res, body);
|
|
1229
1233
|
if (!p) return;
|
|
1230
1234
|
if (body.milestone != null && typeof body.milestone !== 'boolean') return fail(ctx, res, 400, 'milestone is true or false');
|
|
1235
|
+
if (body.pinned !== undefined && body.pinned !== null && typeof body.pinned !== 'boolean') return fail(ctx, res, 400, 'pinned is true, false, or null for the rule (the last milestone only)');
|
|
1236
|
+
const pinWas = (id) => { const PN = p.fr.folded.pins || new Map(); return PN.has(id) ? PN.get(id) : null; };
|
|
1237
|
+
const pinLine = (id) => ({ kind: 'task-pin', board: p.board.id, task: id, pinned: body.pinned, why: body.pinned === true ? 'pinned to the timeline' : body.pinned === false ? 'taken off the timeline' : 'pin back to the rule' });
|
|
1231
1238
|
// a Jira ticket takes the milestone flag (feedback batch 11 item 3) and the PM's own start and due days, kept in PMOS only (item 23):
|
|
1232
1239
|
// Jira keeps its title, status and assignee, and nothing is written to Jira
|
|
1233
1240
|
if (typeof body.task === 'string' && B.JIRA_KEY_RE.test(body.task) && !B.taskOf(p.fr.folded, body.task)) {
|
|
1234
|
-
if (['owner', 'notes', 'initiative', 'section'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates
|
|
1235
|
-
if (body.milestone == null && body.start == null && body.due == null) return fail(ctx, res, 400, 'nothing to change: send start, due or
|
|
1241
|
+
if (['owner', 'notes', 'initiative', 'section'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates, its milestone flag and its pin change here');
|
|
1242
|
+
if (body.milestone == null && body.start == null && body.due == null && body.pinned === undefined) return fail(ctx, res, 400, 'nothing to change: send start, due, milestone or pinned');
|
|
1236
1243
|
for (const k of ['start', 'due']) if (body[k] != null && body[k] !== '' && !/^\d{4}-\d{2}-\d{2}$/.test(String(body[k]))) return fail(ctx, res, 400, `${k} is a day, YYYY-MM-DD, or '' for none`);
|
|
1237
1244
|
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
1238
1245
|
const from = {}, ref = body.task.toUpperCase();
|
|
@@ -1249,6 +1256,7 @@ const WRITES = {
|
|
|
1249
1256
|
from.milestone = !!MS0.get(body.task);
|
|
1250
1257
|
append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: body.task, milestone: body.milestone, why: body.milestone ? 'made a milestone' : 'no longer a milestone' });
|
|
1251
1258
|
}
|
|
1259
|
+
if (body.pinned !== undefined) { from.pinned = pinWas(body.task); append(p.file, g.actor, pinLine(body.task)); }
|
|
1252
1260
|
return ctx.json(res, { ok: true, from, item: null });
|
|
1253
1261
|
}
|
|
1254
1262
|
const t0 = B.taskOf(p.fr.folded, body.task);
|
|
@@ -1298,9 +1306,13 @@ const WRITES = {
|
|
|
1298
1306
|
const MS0 = p.fr.folded.milestones || new Map();
|
|
1299
1307
|
ms = body.milestone; from.milestone = MS0.has(t.id) ? MS0.get(t.id) : !!t.milestone;
|
|
1300
1308
|
}
|
|
1301
|
-
|
|
1309
|
+
// the pin (batch 13 item 4): a board-ledger line like the milestone flag
|
|
1310
|
+
const pin = body.pinned !== undefined;
|
|
1311
|
+
if (pin) { if (!p.file) return fail(ctx, res, 409, NO_STATE); from.pinned = pinWas(t.id); }
|
|
1312
|
+
if (!Object.keys(ev).length && sec == null && ms == null && !pin) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, initiative, section, milestone or pinned');
|
|
1302
1313
|
if (sec != null) append(p.file, g.actor, { kind: 'task-section', board: p.board.id, task: t.id, section: sec, why: sec ? 'placed under ' + sec : 'placed under no stage' });
|
|
1303
1314
|
if (ms != null) append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: t.id, milestone: ms, why: ms ? 'made a milestone' : 'no longer a milestone' });
|
|
1315
|
+
if (pin) append(p.file, g.actor, pinLine(t.id));
|
|
1304
1316
|
if (!Object.keys(ev).length) {
|
|
1305
1317
|
const items = itemsOf(p.w, { ...p.fr, folded: B.fold(readLedger(ctx, p.w)) }, p.board, (needRows(ctx, res, p.w) || []).filter((r) => r.id === t.initiative));
|
|
1306
1318
|
return ctx.json(res, { ok: true, from, item: items.find((x) => x.uid === t.id) || null });
|
|
@@ -73,7 +73,9 @@ function todayAgenda(events, items, now, notes = {}) {
|
|
|
73
73
|
const before = open.filter((i) => (i.meeting_id && i.meeting_id === e.id) || (i.event_id && i.event_id === e.id) || (t.length >= 6 && norm(i.title).includes(t)))
|
|
74
74
|
.map((i) => ({ id: i.id, title: i.title, due: i.due || null, done: !!i.done }));
|
|
75
75
|
return { id: e.id, title: e.title, start: s.toISOString(), end: new Date(endMs).toISOString(), startLocal: hhmm(s), minutes: Math.max(0, Math.round((endMs - s.getTime()) / 60000)),
|
|
76
|
-
people: Array.isArray(e.attendees) ? e.attendees.slice(0, 12) : [],
|
|
76
|
+
people: Array.isArray(e.attendees) ? e.attendees.slice(0, 12) : [],
|
|
77
|
+
// the link the PM set on the meeting (lib/calendar-links.js, every occurrence of it) wins; Home's clean-up writes one (batch 13 item 3)
|
|
78
|
+
initiative: (notes.linkOf && notes.linkOf(e)) || e.initiative || null, ...(e.series ? { series: String(e.series).slice(0, 300) } : {}), prepared, before, _s: s.getTime(), _e: endMs };
|
|
77
79
|
});
|
|
78
80
|
let nextDone = false;
|
|
79
81
|
for (const r of rows) {
|
|
@@ -212,7 +214,13 @@ function build(query, deps = {}) {
|
|
|
212
214
|
function notesAdapter(runtimeDir) {
|
|
213
215
|
let notes; try { notes = require('./notes.js'); } catch { return {}; }
|
|
214
216
|
const rows = () => { try { const l = notes.list(runtimeDir); return l && l.ok ? l.notes.filter((n) => !n.private) : []; } catch { return []; } };
|
|
217
|
+
let links = null;
|
|
215
218
|
return {
|
|
219
|
+
linkOf: (e) => {
|
|
220
|
+
if (!links) { try { links = require('./calendar-links.js').read(runtimeDir); } catch { links = new Map(); } }
|
|
221
|
+
const l = links.get(require('./calendar-links.js').keyOf(e));
|
|
222
|
+
return l && l.kind === 'initiative' ? l.initiative : null;
|
|
223
|
+
},
|
|
216
224
|
findByEvent: (e) => { try { const n = notes.findByEvent(runtimeDir, { event_id: e.id, start: e.at, title: e.title }); return n && !n.private ? { id: n.id, title: n.title || 'Untitled note' } : null; } catch { return null; } },
|
|
217
225
|
lastBefore: (e) => {
|
|
218
226
|
const t = norm(e.title);
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* GET /api/live → { ok, sessions: [row], titles: { [initiative id]: title } }
|
|
5
5
|
* row = the /api/sessions fields the pill needs: id, ws, name, auto_name, name_by, agent, origin, automatic, shown, created,
|
|
6
|
-
* lastOutputAt, touched_at, exited_at, auto_ended, outcome { ok } | null, initiative, hx { title, turn } | null
|
|
6
|
+
* lastOutputAt, touched_at, exited_at, auto_ended, outcome { ok } | null, initiative, hx { title, turn } | null,
|
|
7
|
+
* ctx { used, window, pct, level, at } | null
|
|
7
8
|
* titles = the initiatives those sessions work on, by id, from each workspace's records (kept 60 s per workspace)
|
|
8
9
|
*
|
|
9
10
|
* Read-only. The pill shows on every page, so it reads this small answer every 10 s rather than the whole of /api/sessions; the
|
|
@@ -32,6 +33,7 @@ function rowOf(s) {
|
|
|
32
33
|
touched_at: s.touched_at || null, exited_at: s.exited_at || null, auto_ended: !!s.auto_ended,
|
|
33
34
|
outcome: s.outcome ? { ok: s.outcome.ok !== false } : null, initiative: s.initiative || null,
|
|
34
35
|
hx: s.hx ? { title: s.hx.title || null, turn: s.hx.turn || null } : null,
|
|
36
|
+
ctx: s.ctx ? { used: s.ctx.used, window: s.ctx.window, pct: s.ctx.pct, level: s.ctx.level, at: s.ctx.at } : null, // the context pie (batch 13 item 8)
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-loose.js — Claude's clean-up of Home's "Not in an initiative" (feedback batch 13 item 3, option A; canvas In development, XlcA0Grill to
|
|
3
|
+
* XlcA4Pick). The fold and the view are lib/loose-proposals.js. Every write goes through the store that already holds it: a chat's initiative
|
|
4
|
+
* through the session record (ctx.looseSessions, the same field POST /api/session/initiative sets), the PM's own item through pm-items' edit
|
|
5
|
+
* (routes-pm-items pressAs), a meeting through lib/calendar-links.js (every occurrence of it), a new initiative through the Board's own Add an
|
|
6
|
+
* ask and Accept (routes-boards writeAs). Nothing is written before the PM's ✓ (rule 12), and nothing is deleted: a chat put away keeps its
|
|
7
|
+
* transcript, Search finds it, and the PM's next message in it brings it back (rule 10).
|
|
8
|
+
*
|
|
9
|
+
* GET /api/loose-props → { ok, props, history, sig } sig: the page's signature of the rows it last sent props: lib/loose-proposals.js viewOf (null: nothing to show)
|
|
10
|
+
* POST /api/loose-props/rows { rows, inis, today? } → { ok, props, history } what Home shows loose now and the open initiatives it knows;
|
|
11
|
+
* when the group passed 10 rows Claude looks at once (rule 7)
|
|
12
|
+
* POST /api/loose-props/close { sid } → closes one session that is idle and safe (the pill menu's ✓); { batch, said } for Undo
|
|
13
|
+
* POST /api/loose-props/keep { ids?: [id] | all: true, out?: [row], choices?: { <row>: { ini, title?, ws? } | { new: true, ws, board, anchor } },
|
|
14
|
+
* where?: { ws, board }, today? } → { ok, batch, said, props, history } ✓ on one proposal, or the header's ✓
|
|
15
|
+
* (all). A row's tile can name another initiative or a new one (rule 1); `out` are rows left out (✕)
|
|
16
|
+
* POST /api/loose-props/drop { scope, rows } → { ok } ✕: those rows are not proposed again in that group (rule 6)
|
|
17
|
+
* POST /api/loose-props/undrop { scope, rows } → { ok } the Undo of a row's ✕
|
|
18
|
+
* POST /api/loose-props/undo { batch } → { ok, back, kept } one approval, from the toast or the History fold (rule 9)
|
|
19
|
+
* POST /api/loose-props/look { } → { ok, started } Claude looks now
|
|
20
|
+
* Every POST passes pm-guard requirePagePress. */
|
|
21
|
+
const LP = require('./loose-proposals.js');
|
|
22
|
+
const guard = require('./pm-guard.js');
|
|
23
|
+
|
|
24
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
25
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/;
|
|
26
|
+
const fail = (ctx, res, status, error) => { ctx.json(res, { ok: false, error }, status); return true; };
|
|
27
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
28
|
+
const localDay = (d = new Date()) => d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
|
|
29
|
+
const dayOf = (body) => (body && /^\d{4}-\d{2}-\d{2}$/.test(String(body.today || '')) ? String(body.today) : localDay());
|
|
30
|
+
|
|
31
|
+
function viewNow(ctx, dir, today) {
|
|
32
|
+
const snap = LP.readRows(dir), F = LP.read(dir);
|
|
33
|
+
const inis = snap.inis.length ? new Map(snap.inis.map((i) => [i.id, i])) : null;
|
|
34
|
+
const closable = ctx.looseSessions && ctx.looseSessions.closable ? (() => { try { return ctx.looseSessions.closable(); } catch { return []; } })() : [];
|
|
35
|
+
return { props: LP.viewOf(F, snap.rows, { today, inis, closable }), history: LP.historyOf(F).slice(0, 20), sig: snap.sig };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* ── the writes, each with what it was before ── */
|
|
39
|
+
const CL = () => require('./calendar-links.js');
|
|
40
|
+
const PMI = () => require('./routes-pm-items.js');
|
|
41
|
+
function linkRow(ctx, row, ini, g) {
|
|
42
|
+
if (row.kind === 'session') {
|
|
43
|
+
if (!ctx.looseSessions) return null;
|
|
44
|
+
const prev = ctx.looseSessions.bind(row.sids, row.key || null, ini.id);
|
|
45
|
+
return prev.length ? { op: 'bind', row: row.id, sids: row.sids, ...(row.key ? { key: row.key } : {}), ini: ini.id, prev } : null;
|
|
46
|
+
}
|
|
47
|
+
if (row.kind === 'item') {
|
|
48
|
+
const was = PMI().itemOf(ctx, row.item);
|
|
49
|
+
const r = PMI().pressAs(ctx, 'POST /api/pm-items/edit', { id: row.item, fields: { initiative: ini.id } });
|
|
50
|
+
return r.status === 200 ? { op: 'item', row: row.id, item: row.item, ini: ini.id, prev: (was && was.initiative) || null } : null;
|
|
51
|
+
}
|
|
52
|
+
if (row.kind === 'meeting') {
|
|
53
|
+
const prev = CL().read(ctx.runtimeDir).get(CL().keyOf(row.event)) || null;
|
|
54
|
+
const r = CL().append(ctx.runtimeDir, { event: row.event, kind: 'initiative', initiative: ini.id, ...(ini.ws ? { ws: ini.ws } : {}), title: ini.title }, g.actor && g.actor.by);
|
|
55
|
+
return r.ok ? { op: 'meet', row: row.id, event: row.event, ini: ini.id, ...(ini.ws ? { ws: ini.ws } : {}), prev } : null;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function awayRow(ctx, row, why, into) {
|
|
60
|
+
if (row.kind !== 'session' || !ctx.looseSessions) return null;
|
|
61
|
+
const v = { at: new Date().toISOString(), why, ...(into ? { into } : {}) };
|
|
62
|
+
const ids = ctx.looseSessions.away(row.sids, row.key || null, v);
|
|
63
|
+
return ids.length ? { op: 'away', row: row.id, sids: row.sids, ...(row.key ? { key: row.key } : {}), why, ...(into ? { into } : {}) } : null;
|
|
64
|
+
}
|
|
65
|
+
/** Closes a session that is still idle and safe (batch 13 item 7). The server checks again: one that woke up or got work since is held. */
|
|
66
|
+
function closeRow(ctx, x) {
|
|
67
|
+
if (!ctx.looseSessions || !ctx.looseSessions.close) return { error: 'Sessions cannot be closed here' };
|
|
68
|
+
const r = ctx.looseSessions.close(x.sids || [], x.key || null, { at: new Date().toISOString(), why: 'closed' });
|
|
69
|
+
if (!r.closed.length) return { error: (r.held[0] && r.held[0].say) || 'It is no longer idle' };
|
|
70
|
+
return { op: 'close', row: x.row, sids: r.closed, ...(x.key ? { key: x.key } : {}), title: x.title };
|
|
71
|
+
}
|
|
72
|
+
/** A new initiative from rows (rule 11, and a tile's "+ New initiative from this row"): the Board's own Add an ask and Accept. → { id, write } | { error } */
|
|
73
|
+
function createIni(ctx, g, at, title, anchor, intent) {
|
|
74
|
+
const RB = require('./routes-boards.js');
|
|
75
|
+
if (!at || !ID_RE.test(String(at.ws || '')) || !ID_RE.test(String(at.board || ''))) return { error: 'the product to start it in is not known' };
|
|
76
|
+
if (!anchor) return { error: 'a new initiative needs what it counts toward' };
|
|
77
|
+
const a = RB.writeAs(ctx, '/api/boards/asks/add', { ws: at.ws, board: at.board, line: String(title).slice(0, 480), source: 'Home clean-up, approved by you' }, g);
|
|
78
|
+
if (!a.body || !a.body.ok) return { error: (a.body && a.body.error) || 'the ask was not added' };
|
|
79
|
+
const r = RB.writeAs(ctx, '/api/boards/asks/accept', { ws: at.ws, board: at.board, ask: a.body.ask.id, title, lane: 'feature', anchor, ...(intent ? { intent } : {}) }, g);
|
|
80
|
+
if (!r.body || !r.body.ok) return { error: (r.body && r.body.error) || 'the initiative was not started' };
|
|
81
|
+
const id = r.body.initiative && r.body.initiative.id;
|
|
82
|
+
return { id, write: { op: 'create', ini: id, title, ws: at.ws, board: at.board, stage: r.body.stage || '' } };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const WRITES = {
|
|
86
|
+
'/api/loose-props/rows': (ctx, res, body, g, dir) => {
|
|
87
|
+
if (!Array.isArray(body.rows)) return fail(ctx, res, 400, 'rows is the list Home shows under "Not in an initiative"');
|
|
88
|
+
const s = LP.saveRows(dir, body.rows, Date.now(), Array.isArray(body.inis) ? body.inis : undefined, body.sig);
|
|
89
|
+
// rule 7: the group passed 10 rows, so Claude looks now, not tomorrow morning
|
|
90
|
+
if (s.over10 && ctx.proposalRuns && ctx.proposalRuns.looseDue) {
|
|
91
|
+
try { if (ctx.proposalRuns.looseDue(Date.now(), false) === 'many') ctx.proposalRuns.startLoose({ why: 'many', press: false }); } catch { /* the tick tries again */ }
|
|
92
|
+
}
|
|
93
|
+
ctx.json(res, { ok: true, ...viewNow(ctx, dir, dayOf(body)) });
|
|
94
|
+
},
|
|
95
|
+
'/api/loose-props/keep': (ctx, res, body, g, dir) => {
|
|
96
|
+
const today = dayOf(body), v = viewNow(ctx, dir, today).props;
|
|
97
|
+
const all = v ? v.groups.flatMap((x) => x.props) : [];
|
|
98
|
+
const ids = Array.isArray(body.ids) ? body.ids.filter((x) => typeof x === 'string').slice(0, 60) : [];
|
|
99
|
+
if (!ids.length && body.all !== true) return fail(ctx, res, 400, 'ids names the proposals to approve, or all: true');
|
|
100
|
+
const want = body.all === true ? all : all.filter((p) => ids.includes(p.id));
|
|
101
|
+
if (!want.length) return fail(ctx, res, 409, 'Those proposals are no longer open');
|
|
102
|
+
const out = new Set(Array.isArray(body.out) ? body.out.filter((x) => typeof x === 'string') : []);
|
|
103
|
+
const choices = isObj(body.choices) ? body.choices : {};
|
|
104
|
+
const snap = LP.readRows(dir), byId = new Map(snap.rows.map((r) => [r.id, r])), inis = new Map(snap.inis.map((i) => [i.id, i]));
|
|
105
|
+
const wrote = [], keptIds = [], errors = [];
|
|
106
|
+
const made = new Map(); // one new initiative per title, so a start and a tile's "new" do not make two
|
|
107
|
+
const newIni = (title, at, anchor, intent) => {
|
|
108
|
+
const k = String(title).toLowerCase(); if (made.has(k)) return made.get(k);
|
|
109
|
+
const r = createIni(ctx, g, at, title, anchor, intent);
|
|
110
|
+
if (r.error) { errors.push(r.error); made.set(k, null); return null; }
|
|
111
|
+
wrote.push(r.write); const ini = { id: r.id, title, ws: at.ws }; made.set(k, ini); return ini;
|
|
112
|
+
};
|
|
113
|
+
for (const p of want) {
|
|
114
|
+
let any = false;
|
|
115
|
+
for (const x of p.rows) {
|
|
116
|
+
const row = p.type === 'close' ? x : byId.get(x.row); if (!row || out.has(row.id || row.row)) continue;
|
|
117
|
+
let w = null;
|
|
118
|
+
if (p.type === 'ini' || p.type === 'new') {
|
|
119
|
+
// rule 1: the row's tile may name another initiative, or a new one from this row
|
|
120
|
+
const c = isObj(choices[row.id]) ? choices[row.id] : null;
|
|
121
|
+
let ini = null;
|
|
122
|
+
if (c && c.new === true) ini = newIni(row.title, { ws: c.ws, board: c.board }, String(c.anchor || ''), '');
|
|
123
|
+
else if (c && ID_RE.test(String(c.ini || ''))) ini = inis.get(c.ini) || { id: c.ini, title: String(c.title || c.ini).slice(0, 140), ...(c.ws ? { ws: String(c.ws) } : {}) };
|
|
124
|
+
else if (p.type === 'ini') ini = inis.get(p.data.ini) || { id: p.data.ini, title: p.data.title || p.data.ini, ...(p.data.ws ? { ws: p.data.ws } : {}) };
|
|
125
|
+
else ini = newIni(p.data.title, isObj(body.where) ? body.where : null, p.data.anchor, p.data.why);
|
|
126
|
+
if (ini) w = linkRow(ctx, row, ini, g);
|
|
127
|
+
} else if (p.type === 'merge') w = awayRow(ctx, row, 'merged', p.data.into);
|
|
128
|
+
else if (p.type === 'finish') w = awayRow(ctx, row, 'done');
|
|
129
|
+
else if (p.type === 'away') w = awayRow(ctx, row, 'idle');
|
|
130
|
+
else if (p.type === 'close') { const c = closeRow(ctx, row); if (c.error) errors.push(c.error); else w = c; }
|
|
131
|
+
if (w) { wrote.push({ ...w, why: p.why, group: p.type }); any = true; }
|
|
132
|
+
}
|
|
133
|
+
if (any) keptIds.push(p.id);
|
|
134
|
+
}
|
|
135
|
+
if (!wrote.length) return fail(ctx, res, 409, errors[0] || 'Nothing could be placed');
|
|
136
|
+
const batch = LP.newBatch(), said = LP.saidOf(wrote);
|
|
137
|
+
LP.append(dir, g.actor, { kind: 'keep', batch, ids: keptIds, said, wrote });
|
|
138
|
+
ctx.json(res, { ok: true, batch, said, ...(errors.length ? { warn: errors[0] } : {}), ...viewNow(ctx, dir, today) });
|
|
139
|
+
},
|
|
140
|
+
// the pill menu's ✓ on one session (batch 13 item 7): the same keep, for one row of the close proposal
|
|
141
|
+
'/api/loose-props/close': (ctx, res, body, g, dir) => {
|
|
142
|
+
const sid = String(body.sid || '');
|
|
143
|
+
const c = (ctx.looseSessions && ctx.looseSessions.closable ? ctx.looseSessions.closable() : []).find((x) => x.sid === sid);
|
|
144
|
+
if (!c) return fail(ctx, res, 409, 'That session is no longer idle and safe to close');
|
|
145
|
+
const row = LP.closeOf([c]).rows[0];
|
|
146
|
+
const w = closeRow(ctx, row);
|
|
147
|
+
if (w.error) return fail(ctx, res, 409, w.error);
|
|
148
|
+
const batch = LP.newBatch(), said = 'Closed "' + row.title + '". Its transcript is kept';
|
|
149
|
+
LP.append(dir, g.actor, { kind: 'keep', batch, ids: ['lp-close'], said, wrote: [{ ...w, why: 'pill', group: 'close' }] });
|
|
150
|
+
ctx.json(res, { ok: true, batch, said, ...viewNow(ctx, dir, dayOf(body)) });
|
|
151
|
+
},
|
|
152
|
+
'/api/loose-props/drop': (ctx, res, body, g, dir) => dropLine(ctx, res, body, g, dir, 'drop'),
|
|
153
|
+
'/api/loose-props/undrop': (ctx, res, body, g, dir) => dropLine(ctx, res, body, g, dir, 'undrop'),
|
|
154
|
+
'/api/loose-props/undo': (ctx, res, body, g, dir) => {
|
|
155
|
+
const F = LP.read(dir), id = String(body.batch || ''), k = F.kept.find((x) => x.batch === id);
|
|
156
|
+
if (!k || F.undone.has(id)) return fail(ctx, res, 409, 'Nothing to undo');
|
|
157
|
+
let back = 0, kept = 0;
|
|
158
|
+
for (const w of k.wrote.slice().reverse()) {
|
|
159
|
+
try {
|
|
160
|
+
if (w.op === 'bind' && ctx.looseSessions) { for (const p of w.prev || []) ctx.looseSessions.bind([p.sid], null, p.ini); back++; }
|
|
161
|
+
else if (w.op === 'item') { const r = PMI().pressAs(ctx, 'POST /api/pm-items/edit', { id: w.item, fields: { initiative: w.prev || null } }); if (r.status === 200) back++; else kept++; }
|
|
162
|
+
else if (w.op === 'meet') {
|
|
163
|
+
const p = w.prev;
|
|
164
|
+
const r = CL().append(ctx.runtimeDir, p ? { event: w.event, kind: p.kind, ...(p.ws ? { ws: p.ws } : {}), ...(p.board ? { board: p.board } : {}), ...(p.initiative ? { initiative: p.initiative } : {}), ...(p.title ? { title: p.title } : {}) } : { event: w.event, kind: 'none' }, g.actor && g.actor.by);
|
|
165
|
+
if (r.ok) back++; else kept++;
|
|
166
|
+
} else if ((w.op === 'away' || w.op === 'close') && ctx.looseSessions) { ctx.looseSessions.away(w.sids, w.key || null, null); back++; } // a closed chat is back on Home and resumes on its next message
|
|
167
|
+
else if (w.op === 'create') kept++; // a started initiative stays: close it on the Board if it should not be there
|
|
168
|
+
} catch { kept++; }
|
|
169
|
+
}
|
|
170
|
+
LP.append(dir, g.actor, { kind: 'undo', batch: id });
|
|
171
|
+
ctx.json(res, { ok: true, back, kept, ...viewNow(ctx, dir, dayOf(body)) });
|
|
172
|
+
},
|
|
173
|
+
'/api/loose-props/look': (ctx, res, body, g) => {
|
|
174
|
+
if (!ctx.proposalRuns || !ctx.proposalRuns.startLoose) return fail(ctx, res, 503, 'Claude\'s runs are off on this server');
|
|
175
|
+
const r = ctx.proposalRuns.startLoose({ why: 'check', press: true });
|
|
176
|
+
if (!r || !r.ok) return fail(ctx, res, 409, (r && r.error) || 'Claude could not start looking');
|
|
177
|
+
ctx.json(res, { ok: true, started: r.run });
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
function dropLine(ctx, res, body, g, dir, kind) {
|
|
181
|
+
const scope = ['link', 'tidy', 'start'].includes(body.scope) ? body.scope : null;
|
|
182
|
+
const rows = Array.isArray(body.rows) ? body.rows.filter((x) => typeof x === 'string' && /^(c|s|w|m):/.test(x)).slice(0, 60) : [];
|
|
183
|
+
if (!scope || !rows.length) return fail(ctx, res, 400, 'scope is link, tidy or start; rows names the rows');
|
|
184
|
+
LP.append(dir, g.actor, { kind, scope, rows });
|
|
185
|
+
ctx.json(res, { ok: true });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = {
|
|
189
|
+
prefixes: ['/api/loose-props'],
|
|
190
|
+
handle: async (req, res, url, ctx) => {
|
|
191
|
+
const p = url.pathname;
|
|
192
|
+
const dir = LP.dirOf(ctx.runtimeDir);
|
|
193
|
+
if (req.method === 'GET') {
|
|
194
|
+
if (p !== '/api/loose-props') return fail(ctx, res, 404, 'not found');
|
|
195
|
+
if (!dir) { ctx.json(res, { ok: true, props: null, history: [] }); return true; }
|
|
196
|
+
ctx.json(res, { ok: true, ...viewNow(ctx, dir, /^\d{4}-\d{2}-\d{2}$/.test(url.searchParams.get('today') || '') ? url.searchParams.get('today') : localDay()) });
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (req.method !== 'POST') return fail(ctx, res, 405, 'GET or POST only');
|
|
200
|
+
const fn = WRITES[p];
|
|
201
|
+
if (!fn) return fail(ctx, res, 404, 'not found');
|
|
202
|
+
const got = await ctx.readJson(req);
|
|
203
|
+
if (!got.ok || !isObj(got.body)) return fail(ctx, res, 400, 'the body must be a JSON object');
|
|
204
|
+
const g = guard.requirePagePress(req, got.body);
|
|
205
|
+
if (!g.ok) return fail(ctx, res, g.status, g.error);
|
|
206
|
+
if (!dir) return fail(ctx, res, 409, 'PMOS has no runtime folder');
|
|
207
|
+
fn(ctx, res, got.body, g, dir);
|
|
208
|
+
return true;
|
|
209
|
+
},
|
|
210
|
+
};
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* GET /api/pm-items?counts=1 → { ok, today, counts } the counts alone (the console's Work tab badge)
|
|
11
11
|
* POST /api/pm-items/add { line } → { ok, item } one line: the parser (lib/pm-items.js) reads the parts
|
|
12
12
|
* POST /api/pm-items/edit { id, fields }→ { ok, item } fields: title, due, priority, waiting_on, job,
|
|
13
|
-
* defer, flagged, resolves, kind, person, evidence, outcome
|
|
13
|
+
* defer, flagged, resolves, kind, person, evidence, outcome, initiative (the initiative it belongs to:
|
|
14
|
+
* Home lists it under that initiative, not under "Not in an initiative"; batch 13 item 3)
|
|
14
15
|
* POST /api/pm-items/remove { id } → { ok, undo_ms } deleted (created here) or dropped (imported)
|
|
15
16
|
* POST /api/pm-items/undo { id } → { ok, item } | 409 restores the last removal inside the 8 s window
|
|
16
17
|
* POST /api/pm-items/done { id, outcome?, how? } → { ok } folds to item.done + done_at (+ outcome, one line; + done_how: you|agent|confirmed); /reopen undoes it
|
|
@@ -51,8 +52,8 @@ const steps = require('./item-steps.js');
|
|
|
51
52
|
const assigned = require('./work-assigned.js');
|
|
52
53
|
const { repoScript } = require('./repo-script.js');
|
|
53
54
|
|
|
54
|
-
const FIELDS = ['title', 'due', 'priority', 'waiting_on', 'job', 'defer', 'flagged', 'resolves', 'kind', 'person', 'evidence', 'outcome'];
|
|
55
|
-
const STRING_OR_NULL = ['resolves', 'person', 'evidence', 'outcome'];
|
|
55
|
+
const FIELDS = ['title', 'due', 'priority', 'waiting_on', 'job', 'defer', 'flagged', 'resolves', 'kind', 'person', 'evidence', 'outcome', 'initiative'];
|
|
56
|
+
const STRING_OR_NULL = ['resolves', 'person', 'evidence', 'outcome', 'initiative'];
|
|
56
57
|
const NOT_YET = ['later-today', 'tomorrow', 'next-week'];
|
|
57
58
|
const JOB_FIELDS = ['when', 'want', 'so'];
|
|
58
59
|
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -147,6 +148,7 @@ function checkFields(fields, allowed) {
|
|
|
147
148
|
if ('priority' in fields && fields.priority !== null && !/^P[1-3]$/.test(String(fields.priority))) return 'priority must be P1, P2, P3 or null';
|
|
148
149
|
if ('defer' in fields && fields.defer !== null && !DATE_RE.test(String(fields.defer))) return 'defer must be YYYY-MM-DD or null';
|
|
149
150
|
if ('flagged' in fields && typeof fields.flagged !== 'boolean') return 'flagged must be true or false';
|
|
151
|
+
if ('initiative' in fields && fields.initiative !== null && !/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(String(fields.initiative))) return 'initiative must be an initiative id or null';
|
|
150
152
|
if ('kind' in fields && fields.kind !== null && fields.kind !== 'offline') return 'kind must be offline or null';
|
|
151
153
|
for (const k of STRING_OR_NULL) {
|
|
152
154
|
if (k in fields && fields[k] !== null && typeof fields[k] !== 'string') return `${k} must be a string or null`;
|
|
@@ -371,21 +373,29 @@ module.exports = {
|
|
|
371
373
|
const body = got.body || {};
|
|
372
374
|
const g = guard.requirePagePress(req, body);
|
|
373
375
|
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
374
|
-
const
|
|
375
|
-
// the first press on assigned or suggested work puts it in the PM's ledger, with its source, before the press itself
|
|
376
|
-
if (typeof body.id === 'string' && VIRTUAL_ID.test(body.id) && !findItem(c.itemLines, body.id)) {
|
|
377
|
-
const v = assigned.addable(assignedSync(ctx, c.now), c.itemLines).find((x) => x.id === body.id);
|
|
378
|
-
if (v) { const ev = assigned.createdEvent(v); pmItems.appendEvent(itemsFile(ctx), ev, c.now); c.itemLines.push({ ...ev, at: c.now.toISOString() }); }
|
|
379
|
-
}
|
|
380
|
-
const r = ROUTES[key](body, c);
|
|
381
|
-
if (r.status === 200 && r.events) {
|
|
382
|
-
for (const ev of r.events) {
|
|
383
|
-
const which = ev._file || r.file;
|
|
384
|
-
const { _file, ...line } = ev;
|
|
385
|
-
pmItems.appendEvent(which === 'jobs' ? jobsFile(ctx) : which === 'steps' ? stepsFile(ctx) : which === 'focus' ? focusFile(ctx) : itemsFile(ctx), line, c.now);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
376
|
+
const r = pressAs(ctx, key, body);
|
|
388
377
|
ctx.json(res, r.body, r.status);
|
|
389
378
|
return true;
|
|
390
379
|
},
|
|
391
380
|
};
|
|
381
|
+
/** One press, as the page's POST runs it (the Home clean-up's ✓ links an item to an initiative through it, batch 13 item 3).
|
|
382
|
+
* key: 'POST /api/pm-items/<verb>'. The caller has checked the press. → { status, body } */
|
|
383
|
+
function pressAs(ctx, key, body) {
|
|
384
|
+
const c = prepare(ctx);
|
|
385
|
+
// the first press on assigned or suggested work puts it in the PM's ledger, with its source, before the press itself
|
|
386
|
+
if (typeof body.id === 'string' && VIRTUAL_ID.test(body.id) && !findItem(c.itemLines, body.id)) {
|
|
387
|
+
const v = assigned.addable(assignedSync(ctx, c.now), c.itemLines).find((x) => x.id === body.id);
|
|
388
|
+
if (v) { const ev = assigned.createdEvent(v); pmItems.appendEvent(itemsFile(ctx), ev, c.now); c.itemLines.push({ ...ev, at: c.now.toISOString() }); }
|
|
389
|
+
}
|
|
390
|
+
const r = ROUTES[key](body, c);
|
|
391
|
+
if (r.status === 200 && r.events) {
|
|
392
|
+
for (const ev of r.events) {
|
|
393
|
+
const which = ev._file || r.file;
|
|
394
|
+
const { _file, ...line } = ev;
|
|
395
|
+
pmItems.appendEvent(which === 'jobs' ? jobsFile(ctx) : which === 'steps' ? stepsFile(ctx) : which === 'focus' ? focusFile(ctx) : itemsFile(ctx), line, c.now);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return r;
|
|
399
|
+
}
|
|
400
|
+
module.exports.pressAs = pressAs;
|
|
401
|
+
module.exports.itemOf = (ctx, id) => findItem(prepare(ctx).itemLines, id) || null;
|