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
|
@@ -117,7 +117,9 @@ const put = (root, rel, text) => { fs.mkdirSync(path.dirname(path.join(root, rel
|
|
|
117
117
|
await menu(pg); await pg.click('#czMenu [data-cz-news]');
|
|
118
118
|
const nw = await until(() => pg.evaluate(() => { const v = document.querySelector('#czViewer:not([hidden]) .ev-news'); return v && !v.querySelector('.ev-skelrow') ? { t: v.textContent, rest: [...v.querySelectorAll('[data-ev-rest]')].map((b) => b.dataset.evRest), kind: document.querySelector('#czViewer .cz-vw-kind').textContent } : null; }), 20000);
|
|
119
119
|
ok('N1 New for you opens in the Viewer, says what is new or that nothing is, and names where the rest of Around you went', !!nw && /New since this morning/.test(nw.t) && /(Nothing new since you last looked|Mentions|Given to you|Finished while you were away)/.test(nw.t) && nw.rest.join() === 'pulse,rep,prop,scan', JSON.stringify(nw).slice(0, 400));
|
|
120
|
-
|
|
120
|
+
// Home's own background sync of its loose rows (batch 13 item 7) is not a post the Viewer makes.
|
|
121
|
+
const own = posts.filter((u) => u !== '/api/loose-props/rows');
|
|
122
|
+
ok('N1 opening it posted nothing', own.length === 0, JSON.stringify(posts));
|
|
121
123
|
await snap(pg, 'news-1440-light');
|
|
122
124
|
await pg.click('#czViewer [data-ev-rest="pulse"]');
|
|
123
125
|
ok('N2 a Where the rest went row opens its view, with Back to New for you', !!(await until(() => pg.evaluate(() => /Back to New for you/.test((document.querySelector('#czViewer [data-bda="back"]') || {}).textContent || '')))));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Claude proposes: the one ✦ on each initiative"
|
|
4
|
-
description: "What Claude finds when you add an initiative that already lives elsewhere, the new dates, done and tidy names it proposes for late tasks, how you keep or drop them in the Viewer, Undo, and the pmos propose commands."
|
|
5
|
-
timestamp: 2026-10-
|
|
4
|
+
description: "What Claude finds when you add an initiative that already lives elsewhere, the new dates, done and tidy names it proposes for late tasks, the clean-up of the work that is not in an initiative, how you keep or drop them in the Viewer, Undo, and the pmos propose commands."
|
|
5
|
+
timestamp: 2026-10-27
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Claude proposes: the one ✦ on each initiative
|
|
@@ -33,5 +33,22 @@ Claude's background run files proposals with these commands. The server pins the
|
|
|
33
33
|
- `pmos propose done --json <file|->`: a task that looks done, with the evidence.
|
|
34
34
|
- `pmos propose name --json <file|->`: tidy names.
|
|
35
35
|
- `pmos propose status`: what is open, kept and dropped.
|
|
36
|
+
- `pmos propose loose <link|merge|finish|start> --json <file|->`: the clean-up of the work that is not in an initiative. Only the clean-up run can file these, and that run files nothing else. `pmos propose loose status` shows what is open and kept.
|
|
36
37
|
|
|
37
38
|
Every proposal carries its source. Nothing is sent.
|
|
39
|
+
|
|
40
|
+
## The clean-up of loose work
|
|
41
|
+
|
|
42
|
+
Home's "Not in an initiative" group has its own blue ✦ with the number of rows Claude can place. Claude looks once each morning, and at once when the group passes 10 rows. With nothing to place, the ✦ is not shown.
|
|
43
|
+
|
|
44
|
+
Press the ✦ to open "Claude proposes" in the Viewer. The groups come in this order:
|
|
45
|
+
|
|
46
|
+
- **Link.** Rows that belong to an open initiative: chats, your own tasks and meetings. A repeating meeting links its series, so every occurrence follows. A row that waits on you or is late keeps its blue dot under the initiative. Each row has a tile with the initiative's letters. Press the tile to move that row to another initiative, or to start a new initiative from it.
|
|
47
|
+
- **Tidy.** A chat with the same name as your own task joins it, and your task stays. A chat whose last message closed the work is finished, with that message quoted. A chat with no message for 14 days, that waits on nothing, is put away. A put-away chat leaves Home and comes back when you write in it. Search keeps it. A session that is idle for 30 minutes and safe to close is closed: its work is committed and pushed, it has no open goal step, and nothing waits on you. Closing keeps the transcript.
|
|
48
|
+
- **Start an initiative.** When 3 or more rows are about one new thing, Claude proposes a new initiative from them, with its anchor.
|
|
49
|
+
|
|
50
|
+
In the pill menu on an initiative's row, a session that is idle and safe to close is light blue. Its line starts with ✦ and says why, and its ✓ closes it. An idle session that is not safe has no ✦ and no ✓. Its line says what holds it, such as "3 files not committed".
|
|
51
|
+
|
|
52
|
+
Each session shows how full its context window is, as a small pie in the pill list, the chat header, the phone top bar and the Live pill. The pie shows from 50% (grey). It turns amber from 70% and red from 90%. Hover it to see the tokens used, such as "156k of 200k used · last turn 10:12". The window is 1M when the session runs a 1M model, else 200k. From 70%, when it is your turn, Claude proposes Compact: the row's ✦ line says so, and its ✓ types /compact into the session. The chat shows the same offer as a chip. A session that is safe to close shows that ✦ instead. ✕ hides the Compact offer until the context is 10 points fuller.
|
|
53
|
+
|
|
54
|
+
✓ in the header keeps everything shown. Each proposal has its own ✓ and ✕, and ⌄ shows its rows. ✕ on a row leaves it out of that group for good, with Undo on the row. One toast says what was placed, with Undo. History lists each approval with its own Undo. An initiative that was started stays when you undo: close it on the Board.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Programs on the Board: All products, groupings and the program panel"
|
|
4
4
|
description: "A program groups initiatives across products. How it shows on the Board (stage track, Kanban, timeline and List), the All products mode, the By product grouping, the program panel and the side panel width."
|
|
5
|
-
timestamp: 2026-10-
|
|
5
|
+
timestamp: 2026-10-27
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Programs on the Board
|
|
@@ -20,6 +20,7 @@ Programs do not change how Insights, the weekly update or sprints count initiati
|
|
|
20
20
|
- **Kanban** shows programs as swimlanes, then products. Press a column header to fold the column to a strip with its count. An empty column starts folded. The Board remembers each fold.
|
|
21
21
|
- The **timeline** draws a program row that brackets its initiatives' bars, on every span. Program milestones are diamonds. Milestones that are close together merge into one diamond with a count.
|
|
22
22
|
- On the timeline, a **product's head row** also shows milestones. Nothing is added by hand: the row shows every milestone of the product's initiatives, which are each milestone task and each initiative's end diamond (its Deliver or Evaluate date). The diamonds are the same as on the initiative rows: open, filled when done, orange when late. Diamonds that are close together merge into one diamond with a count and the date range under it. Press it to see a list with the milestone, its initiative and the date. Press a line to open that initiative. Hold the pointer on a single diamond to see its milestone and initiative. A thin line goes from the first start to the last end of the product's initiatives. When the product is folded, the row stays the same, so it is a summary of the product. On a phone the diamonds have no dates; tap the row to see all the milestones in date order. A product inside a program has no such row, because the program row shows its milestones.
|
|
23
|
+
- On the timeline, an initiative row shows only its **pinned** milestones. By default that is its last milestone. Press a diamond to see every milestone of the initiative, with how many are on the timeline. Press the pin beside a milestone to show it or to hide it. To see every milestone or none, open **Filter** and pick **Milestones on the timeline: Pinned**, **All** or **None**. The Board keeps your pick. From a terminal: `pmos task set <task> --pin`, `--no-pin`, or `--pin-default` to go back to the default.
|
|
23
24
|
- **List** has a Product column and a Program column. Press a column header to sort by it.
|
|
24
25
|
- **New** opens a menu: **New initiative** or **New program**.
|
|
25
26
|
- A new program shows at once, before any initiative joins it. A program with no open initiative shows on its own product's Board and on All products, with "No initiatives yet" or "No open initiatives". Press its name, then **⋯** and **Move an initiative in**. That menu lists open initiatives only, grouped by product, with the program's own product first, wherever you open the program (Home, another product's Board or All products). An initiative joins in its own product.
|
|
@@ -324,7 +324,9 @@ function build(f) {
|
|
|
324
324
|
for (const w of f.items || []) {
|
|
325
325
|
if (!w || !w.milestone || w.kind === 'Epic' || !w.ini || !w.uid || w.status === "Won't do" || w.status === 'Archived' || !isoDay(w.end)) continue;
|
|
326
326
|
if (!msBy.has(w.ini)) msBy.set(w.ini, []);
|
|
327
|
-
msBy.get(w.ini).push({ id: w.uid, name: clip(w.title || w.uid, 120), date: String(w.end).slice(0, 10), done: w.status === 'Done', ...(typeof w.section === 'string' && w.section ? { sec: w.section } : w.from && w.from.stage ? { sec: w.from.stage } : {}), ...(w.src === 'jira' ? { jira: true } : {})
|
|
327
|
+
msBy.get(w.ini).push({ id: w.uid, name: clip(w.title || w.uid, 120), date: String(w.end).slice(0, 10), done: w.status === 'Done', ...(typeof w.section === 'string' && w.section ? { sec: w.section } : w.from && w.from.stage ? { sec: w.from.stage } : {}), ...(w.src === 'jira' ? { jira: true } : {}),
|
|
328
|
+
// the PM's pin (batch 13 item 4): only when set; unset follows pm/bd-pins.js's rule (the last milestone shows)
|
|
329
|
+
...(typeof w.pinned === 'boolean' ? { pinned: w.pinned } : {}) });
|
|
328
330
|
}
|
|
329
331
|
// every task, not the first 60: the Board's panel and Home count the same tasks (feedback batch 6 item 1: Board said 56 done, Home 61)
|
|
330
332
|
for (const r of rows.concat(stageRows, gone.cancelled, gone.archived)) if (!r.tasks) r.tasks = (taskBy.get(r.id) || []).slice(0, TASK_MAX);
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
* path what Claude wrote: absolute, ~/…, or relative to the session's folder. A trailing :line or :line:col is dropped.
|
|
8
8
|
* roots [{ id, root }] the workspaces the server serves. Nothing outside them is read.
|
|
9
9
|
* base the session's own workspace id: a relative path resolves against its root.
|
|
10
|
+
* cwd the folder the session runs in (may be a subfolder or a worktree): a relative path is tried there first.
|
|
11
|
+
* named full paths Claude wrote elsewhere in the session. A relative path that is missing where it was tried is looked up among the ones
|
|
12
|
+
* that end with it (PM, 2026-10-27: "scarlet-leadership-pack.md" written as a bare name answered "No such file").
|
|
10
13
|
* home the user's home folder, for ~/.
|
|
14
|
+
* A bare file name still missing after that is looked for by name inside the base workspace (findByName): one match opens, more do not.
|
|
11
15
|
* reason: 'outside' (no served workspace holds the path), 'missing' (no such file), 'not-file' (a folder), 'bad' (no path).
|
|
12
16
|
* Both the path and each root are resolved to their real paths, so a symlink inside a workspace cannot lead out of it.
|
|
13
17
|
*
|
|
@@ -30,7 +34,41 @@ function cleanPath(p) {
|
|
|
30
34
|
return s;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
function locate(
|
|
37
|
+
function locate(o = {}) {
|
|
38
|
+
const first = locateOne(o);
|
|
39
|
+
const p = cleanPath(o.path);
|
|
40
|
+
if (first.ok || first.reason === 'bad' || !p || p === '~' || p.startsWith('~/') || path.isAbsolute(p)) return first;
|
|
41
|
+
const tries = [];
|
|
42
|
+
if (o.cwd && path.isAbsolute(o.cwd)) tries.push(path.resolve(o.cwd, p));
|
|
43
|
+
const tail = '/' + p.replace(/^\.\//, '');
|
|
44
|
+
for (const n of [...(o.named || [])].reverse()) { const c = cleanPath(n); if ((path.isAbsolute(c) || c.startsWith('~/')) && c.endsWith(tail)) tries.push(c); }
|
|
45
|
+
if (!p.includes('/')) {
|
|
46
|
+
const list = (o.roots || []).filter((r) => r && r.id && r.root);
|
|
47
|
+
const b = list.find((r) => r.id === o.base) || list[0];
|
|
48
|
+
if (b) tries.push(...findByName(b.root, p));
|
|
49
|
+
}
|
|
50
|
+
for (const t of tries) { const r = locateOne({ ...o, path: t }); if (r.ok) return r; }
|
|
51
|
+
return first;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', '.next', 'dist', 'build', '.cache', 'vendor']);
|
|
55
|
+
/** A bare file name inside one root: its path when exactly one file has that name (a bounded walk), else []. */
|
|
56
|
+
function findByName(root, name, { maxDirs = 4000, maxDepth = 8 } = {}) {
|
|
57
|
+
const hits = [];
|
|
58
|
+
const queue = [[path.resolve(root), 0]];
|
|
59
|
+
let seen = 0;
|
|
60
|
+
while (queue.length && seen < maxDirs && hits.length < 2) {
|
|
61
|
+
const [dir, depth] = queue.shift(); seen++;
|
|
62
|
+
let ents; try { ents = fs.readdirSync(dir, { withFileTypes: true }); } catch { continue; }
|
|
63
|
+
for (const e of ents) {
|
|
64
|
+
if (e.isFile() && e.name === name) hits.push(path.join(dir, e.name));
|
|
65
|
+
else if (e.isDirectory() && depth < maxDepth && !SKIP_DIRS.has(e.name) && !e.name.startsWith('.')) queue.push([path.join(dir, e.name), depth + 1]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return hits.length === 1 ? hits : [];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function locateOne({ path: raw, roots = [], base = null, home = null } = {}) {
|
|
34
72
|
const p = cleanPath(raw);
|
|
35
73
|
if (!p || p.length > 4096 || p.includes('\0')) return { ok: false, reason: 'bad', why: 'There is no file path to open.' };
|
|
36
74
|
const list = roots.filter((r) => r && r.id && r.root).map((r) => ({ id: r.id, root: path.resolve(r.root), real: real(r.root) || path.resolve(r.root) }));
|
|
@@ -72,4 +110,4 @@ function extraRoots({ workspaces = [], worktreesOf = () => [], sessionDirs = [],
|
|
|
72
110
|
return out;
|
|
73
111
|
}
|
|
74
112
|
|
|
75
|
-
module.exports = { locate, cleanPath, extraRoots, extraId };
|
|
113
|
+
module.exports = { locate, findByName, cleanPath, extraRoots, extraId };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
/* context-use.js — how full a session's context window is, and whether Claude proposes to compact it (batch 13 item 8, canvas XctxA1Desk).
|
|
6
|
+
*
|
|
7
|
+
* of(seen, hints) → { used, window, pct, level, at } | null
|
|
8
|
+
* seen = transcript-read's `context`: { used, peak, at } of the newest real (not subagent) model turn, or null
|
|
9
|
+
* hints = model ids that can name the window: the model PMOS started the session with, the CLI's own setting
|
|
10
|
+
* advise(ctx, shown) → 'compact' | null
|
|
11
|
+
* cliHints(root, home?) → the model the CLI itself is set to: `model` in ~/.claude and <root>/.claude settings, and ANTHROPIC_MODEL
|
|
12
|
+
* The words under the wedge ("116k of 200k used · last turn 10:12") are drawn by pm/ctx-wedge.js, in the PM's own clock.
|
|
13
|
+
*
|
|
14
|
+
* THE NUMBER is what the next turn starts from: the newest reply's input + cache-read + cache-write tokens (what the model was sent) plus
|
|
15
|
+
* its output. It is not a running total, so it drops after a compact. THE WINDOW is 1M when a hint names a [1m] model or a turn already
|
|
16
|
+
* went past 200k, else 200k (the CLI's default). With no turn read, or an agent that is not Claude, there is nothing: no %, no advice.
|
|
17
|
+
* Advice only on the PM's turn (a session that works is never told to compact), and only from 70%. */
|
|
18
|
+
|
|
19
|
+
const BASE = 200000;
|
|
20
|
+
const LONG = 1000000;
|
|
21
|
+
const LEVELS = [[90, 'crit'], [70, 'warn'], [50, 'quiet']];
|
|
22
|
+
|
|
23
|
+
const isLong = (m) => /\[1m\]/i.test(String(m || ''));
|
|
24
|
+
|
|
25
|
+
function of(seen, hints = []) {
|
|
26
|
+
if (!seen || !(seen.used > 0)) return null;
|
|
27
|
+
const window = hints.some(isLong) || (seen.peak || 0) > BASE ? LONG : BASE;
|
|
28
|
+
const pct = Math.min(100, Math.floor((seen.used / window) * 100)); // floor: 69.6% is not yet 70%
|
|
29
|
+
const lv = LEVELS.find(([n]) => pct >= n);
|
|
30
|
+
return { used: seen.used, window, pct, level: lv ? lv[1] : null, at: seen.at || null };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function advise(ctx, shown) {
|
|
34
|
+
if (!ctx || ctx.pct == null || ctx.pct < 70) return null;
|
|
35
|
+
return shown === 'needs' || shown === 'quiet' ? 'compact' : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* The CLI's own model setting. A session PMOS started with no model choice runs the CLI's default, and that setting is what can make it a
|
|
39
|
+
* [1m] model. Read again only when a settings file changes (sessionList runs on every broadcast). */
|
|
40
|
+
const memo = new Map(); // file → { stamp, model }
|
|
41
|
+
function modelIn(file) {
|
|
42
|
+
let stamp = null; try { const st = fs.statSync(file); stamp = st.size + ':' + st.mtimeMs; } catch { return null; }
|
|
43
|
+
const m = memo.get(file); if (m && m.stamp === stamp) return m.model;
|
|
44
|
+
let model = null; try { const j = JSON.parse(fs.readFileSync(file, 'utf8')); model = typeof j.model === 'string' ? j.model : null; } catch { model = null; }
|
|
45
|
+
memo.set(file, { stamp, model });
|
|
46
|
+
return model;
|
|
47
|
+
}
|
|
48
|
+
function cliHints(root, home = os.homedir()) {
|
|
49
|
+
const files = [path.join(home, '.claude', 'settings.json')];
|
|
50
|
+
if (root) files.push(path.join(String(root), '.claude', 'settings.json'), path.join(String(root), '.claude', 'settings.local.json'));
|
|
51
|
+
return files.map(modelIn).concat(process.env.ANTHROPIC_MODEL || null).filter(Boolean);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = { of, advise, cliHints, BASE, LONG };
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
* never moves the initiative. `task` is a Board task or a breakdown item; the last line wins.
|
|
44
44
|
* task-milestone { task, milestone } a task flagged as a milestone (feedback batch 11 item 3): its due
|
|
45
45
|
* date is the milestone's date and Done is its done. `task` is a Board task, a breakdown item or a Jira key; the last line wins.
|
|
46
|
+
* task-pin { task, pinned } the PM's pin on a milestone (feedback batch 13 item 4, XcalmA5Milestones):
|
|
47
|
+
* true draws it on the Board timeline, false hides it, null goes back to the rule (only the initiative's last milestone).
|
|
48
|
+
* `task` is a Board task, a breakdown item or a Jira key; the last line wins.
|
|
46
49
|
* ticket-dates { ref, start, due } the PM's own start and due days for a Jira ticket (feedback batch 11
|
|
47
50
|
* item 23): kept in PMOS only, never written to Jira; '' clears one. They win over Jira's dates on the timeline; the last line wins.
|
|
48
51
|
* Nothing is deleted. A line that is not an object with a known kind is skipped.
|
|
@@ -165,7 +168,7 @@ function foundOf(f) {
|
|
|
165
168
|
const sources = Array.isArray(f.sources) ? f.sources.filter((x) => x && typeof x.ref === 'string').slice(0, 8).map((x) => ({ label: String(x.label || ''), ref: x.ref })) : [];
|
|
166
169
|
return { why: typeof f.why === 'string' ? f.why : '', sources, match: typeof f.match === 'string' && f.match ? f.match : null, scan: typeof f.scan === 'string' ? f.scan : null, run: typeof f.run === 'string' ? f.run : null };
|
|
167
170
|
}
|
|
168
|
-
const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'task-remove', 'task-restore', 'ticket-note', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto', 'task-section', 'task-milestone', 'ticket-dates',
|
|
171
|
+
const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'task-remove', 'task-restore', 'ticket-note', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto', 'task-section', 'task-milestone', 'task-pin', 'ticket-dates',
|
|
169
172
|
// split or merge initiatives (feedback batch 11 item 14): a Jira ticket moved to another initiative, the split and merge records with their Undo, Claude's suggestion dismissed
|
|
170
173
|
'ticket-move', 'ini-split', 'ini-merge', 'ini-sm-undo', 'ini-suggest']);
|
|
171
174
|
// A task's state is its only stage (Wawan, 2026-10-25): the same five every workflow ends in. An old 'In review' reads as In progress (taskState).
|
|
@@ -198,6 +201,7 @@ function fold(events) {
|
|
|
198
201
|
const tasks = new Map(); // task id → { id, board, initiative, title, epic, owner, state, start, due, at, by, history }
|
|
199
202
|
const sections = new Map(); // task id → the stage key its breakdown section is ('' = Not in a stage); the last task-section line wins
|
|
200
203
|
const milestones = new Map(); // task id (or Jira key) → true | false: the PM's milestone flag; the last task-milestone line wins
|
|
204
|
+
const pins = new Map(); // task id (or Jira key) → true | false: the PM's pin on a milestone; a null line takes it out (the rule again)
|
|
201
205
|
const removed = new Map(); // task id → the task a task-remove took out, so a task-restore (Delete's Undo) puts it back
|
|
202
206
|
const ticketNotes = new Map(); // key(board, Jira key) → the PM's notes on that ticket (the last ticket-note line wins)
|
|
203
207
|
const ticketDates = new Map(); // key(board, Jira key) → { start, due } the PM keeps in PMOS for that ticket (the last ticket-dates line wins)
|
|
@@ -291,6 +295,8 @@ function fold(events) {
|
|
|
291
295
|
sections.set(e.task, e.section);
|
|
292
296
|
} else if (e.kind === 'task-milestone' && typeof e.task === 'string' && e.task && typeof e.milestone === 'boolean') {
|
|
293
297
|
milestones.set(e.task, e.milestone);
|
|
298
|
+
} else if (e.kind === 'task-pin' && typeof e.task === 'string' && e.task && (typeof e.pinned === 'boolean' || e.pinned === null)) {
|
|
299
|
+
if (e.pinned === null) pins.delete(e.task); else pins.set(e.task, e.pinned);
|
|
294
300
|
} else if (e.kind === 'ticket-dates' && b && typeof e.ref === 'string' && JIRA_KEY_RE.test(e.ref)) {
|
|
295
301
|
const d = (v) => (typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v) ? v : '');
|
|
296
302
|
const v = { start: d(e.start), due: d(e.due) };
|
|
@@ -349,7 +355,7 @@ function fold(events) {
|
|
|
349
355
|
suggestNo.set(e.id, { kind: e.of === 'merge' ? 'merge' : 'split', fp: e.fp, at: e.at || null });
|
|
350
356
|
}
|
|
351
357
|
}
|
|
352
|
-
return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, sections, milestones, ticketNotes, ticketDates, epics, archives, notDup, iniWf, ends, judged, autoOver, ticketMoves, smOps, smUndone, suggestNo, events: list };
|
|
358
|
+
return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, sections, milestones, pins, ticketNotes, ticketDates, epics, archives, notDup, iniWf, ends, judged, autoOver, ticketMoves, smOps, smUndone, suggestNo, events: list };
|
|
353
359
|
}
|
|
354
360
|
|
|
355
361
|
/** The stages an initiative runs on a board: its own workflow when one is recorded, else the board's. */
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* idle-close — is a session idle and safe to close? (batch 13 item 7, canvas XcsA1Pill)
|
|
3
|
+
*
|
|
4
|
+
* Idle: the session is live, its last turn ended, nothing runs and nothing waits on the PM, for IDLE_MS. Safe: closing it loses nothing.
|
|
5
|
+
* Its folder has no uncommitted change and no commit that is on no remote, and it has no open goal step. A session the workspace started
|
|
6
|
+
* itself is never proposed: the automatic sweep in server.js ends those.
|
|
7
|
+
*
|
|
8
|
+
* The folder is read with git in the background (refresh), never on the 2-second session list: check() reads only the cache. A folder
|
|
9
|
+
* that git could not read is not safe, and the line says so. A folder that is not a repository holds no work to lose.
|
|
10
|
+
*/
|
|
11
|
+
const { execFile } = require('child_process');
|
|
12
|
+
|
|
13
|
+
const IDLE_MS = 30 * 60 * 1000;
|
|
14
|
+
const TTL_MS = 60 * 1000;
|
|
15
|
+
const cache = new Map(); // cwd → { at, v: { repo, dirty, ahead } | { error } }
|
|
16
|
+
const pending = new Set();
|
|
17
|
+
|
|
18
|
+
const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
|
|
19
|
+
const mins = (ms) => { const m = Math.round(ms / 60000); return m < 60 ? m + ' min' : Math.round(m / 60) + ' h'; };
|
|
20
|
+
|
|
21
|
+
function git(cwd, args) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
execFile('git', args, { cwd, timeout: 5000, maxBuffer: 1 << 20, env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' } }, (err, out) => resolve(err ? { err } : { out: String(out || '') }));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Reads one folder: { repo:false } | { repo:true, dirty, ahead } | { error }. */
|
|
27
|
+
async function readFolder(cwd) {
|
|
28
|
+
const st = await git(cwd, ['status', '--porcelain=v1']);
|
|
29
|
+
if (st.err) return /not a git repository/i.test(String(st.err.message || '')) ? { repo: false } : { error: true };
|
|
30
|
+
const dirty = st.out.split('\n').filter((l) => l.trim()).length;
|
|
31
|
+
// commits on no remote: a branch never pushed counts all of its own commits
|
|
32
|
+
const ah = await git(cwd, ['rev-list', '--count', 'HEAD', '--not', '--remotes']);
|
|
33
|
+
const ahead = ah.err ? (/unknown revision|ambiguous argument 'HEAD'/i.test(String(ah.err.message || '')) ? 0 : null) : Number(ah.out.trim()) || 0;
|
|
34
|
+
return ahead == null ? { error: true } : { repo: true, dirty, ahead };
|
|
35
|
+
}
|
|
36
|
+
/** Starts a background read of each folder whose cached answer is older than TTL_MS. */
|
|
37
|
+
function refresh(cwds, now = Date.now(), read = readFolder) {
|
|
38
|
+
for (const cwd of new Set((cwds || []).filter(Boolean))) {
|
|
39
|
+
const c = cache.get(cwd);
|
|
40
|
+
if ((c && now - c.at < TTL_MS) || pending.has(cwd)) continue;
|
|
41
|
+
pending.add(cwd);
|
|
42
|
+
Promise.resolve(read(cwd)).catch(() => ({ error: true })).then((v) => { cache.set(cwd, { at: Date.now(), v }); pending.delete(cwd); });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const folderOf = (cwd) => { const c = cache.get(cwd); return c ? c.v : null; };
|
|
46
|
+
|
|
47
|
+
/** x: { live, automatic, shown, quietMs, folder (folderOf), goalOpen }. → null (not idle, or not ours to propose) | { safe, say }. */
|
|
48
|
+
function check(x) {
|
|
49
|
+
if (!x || !x.live || x.automatic || x.shown !== 'quiet' || !(x.quietMs >= IDLE_MS)) return null;
|
|
50
|
+
const idle = 'Idle ' + mins(x.quietMs);
|
|
51
|
+
const f = x.folder;
|
|
52
|
+
if (x.goalOpen) return { safe: false, say: idle + ' · a goal step is open' };
|
|
53
|
+
if (!f) return null; // not read yet: no word until git has answered
|
|
54
|
+
if (f.error) return { safe: false, say: idle + ' · its folder could not be read' };
|
|
55
|
+
if (f.repo && f.dirty) return { safe: false, say: idle + ' · ' + plural(f.dirty, 'file', 'files') + ' not committed' };
|
|
56
|
+
if (f.repo && f.ahead) return { safe: false, say: idle + ' · ' + plural(f.ahead, 'commit', 'commits') + ' not pushed' };
|
|
57
|
+
return { safe: true, say: idle + '. Safe to close: ' + (f.repo ? 'pushed, ' : '') + 'nothing waits on you' };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { IDLE_MS, TTL_MS, check, refresh, folderOf, readFolder, _cache: cache };
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* loose-proposals.js — Claude's clean-up of Home's "Not in an initiative" (feedback batch 13 item 3, option A; canvas In development, XlcA0Grill
|
|
3
|
+
* (the twelve rules), XlcA1Desk, XlcA2After, XlcA3Sheet, XlcA4Pick). THE ONE WRITER and THE ONE FOLD of <runtime>/loose-props/, and the pure
|
|
4
|
+
* view the ✦ on the group's header opens. lib/routes-loose.js does the I/O; pm/loose-props.js draws the ✦ and the Viewer "Claude proposes N".
|
|
5
|
+
*
|
|
6
|
+
* WHAT A ROW IS. The rows Home draws under "Not in an initiative" (pm/home-list.js looseRowsOf), as the page last sent them (rows.json): each
|
|
7
|
+
* { id, kind: 'session' | 'item' | 'meeting', title, at (its last message or change, ISO), waits (the blue dot), late (a late check box),
|
|
8
|
+
* sids?, key? (a chat), item? (a PM item id), event? ({ title, series } of a meeting), daily? (it repeats), words? (a chat's last words) }
|
|
9
|
+
* The id is the row's own and stays while it is loose: 'c:<chat key>' a chat, 's:<session id>' another session, 'w:<item id>' the PM's own item,
|
|
10
|
+
* 'm:<series key>' a meeting (every occurrence: lib/calendar-links.js keyOf).
|
|
11
|
+
*
|
|
12
|
+
* THE GROUPS, in the Viewer's order (rule numbers are XlcA0Grill's rows):
|
|
13
|
+
* link Link N to <initiative>: one proposal per initiative, filed by Claude's run. A row may go to another initiative or to a new one (rule 1).
|
|
14
|
+
* A repeating meeting links the series (rule 2). A row that waits on the PM keeps its blue dot where it goes (rule 3).
|
|
15
|
+
* tidy merge Merge doubles: the PM's own item stays; the chat with the same name joins it and leaves Home (rule 5)
|
|
16
|
+
* finish Finish chats that are done: each row quotes the message that closed it, with its date; no quote, no Finish (rule 4)
|
|
17
|
+
* away Put away idle chats: no message for 14 days or more. Found here without a run (awayOf). They leave Home; Search keeps them,
|
|
18
|
+
* and a new message brings one back (rule 10)
|
|
19
|
+
* A row with a blue dot or a late check box is never finished, merged or put away: it can only be linked (rule 3).
|
|
20
|
+
* start Start an initiative from 3 or more leftovers about one new thing; it starts in the board's first stage (rule 11).
|
|
21
|
+
* A row shows once, in the first group that takes it (link, then merge, finish, start, away).
|
|
22
|
+
*
|
|
23
|
+
* THE LEDGER, <runtime>/loose-props/proposals.jsonl, one line per event { at, by, kind, ... }:
|
|
24
|
+
* look { run } a run started looking (the morning check, or the group passed 10 rows)
|
|
25
|
+
* end { run, ok, stopped? }
|
|
26
|
+
* propose { run, id, group, type, title, why, sources, items: [{ row, quote?, at? }], data } the last line for an id wins
|
|
27
|
+
* data: link { ini, title, ws? } · merge { into: row } · start { title, why, anchor }
|
|
28
|
+
* drop { scope, rows: [row] } ✕ on a proposal or on one row: that row is not proposed again in that scope (rule 6)
|
|
29
|
+
* undrop { scope, rows: [row] } the Undo of a row's ✕, while the Viewer still shows it struck
|
|
30
|
+
* keep { batch, ids, said, wrote: [write] } ✓: each write with what it was before, for Undo and History (rule 9)
|
|
31
|
+
* undo { batch }
|
|
32
|
+
* A WRITE: { op: 'bind', row, sids, key?, ini, prev: [{ sid, ini }] } · { op: 'item', row, item, ini, prev } · { op: 'meet', row, event, ini, ws?,
|
|
33
|
+
* prev: link | null } · { op: 'away', row, sids, why: 'idle' | 'done' | 'merged', into? } · { op: 'create', ini, title, ws, board }.
|
|
34
|
+
* Nothing is written before the PM's ✓ (rule 12): the run's only write is `pmos propose loose …`.
|
|
35
|
+
*
|
|
36
|
+
* dirOf(runtimeDir) · ledgerFile(dir) · rowsFile(dir) · readLines(file) · read(dir) → fold · append(dir, actor, line)
|
|
37
|
+
* readRows(dir) → { rows, inis, at, over10 } · saveRows(dir, rows, now, inis) → { changed, over10 } the snapshot of what Home shows loose
|
|
38
|
+
* fold(lines) PURE → { props, drops, kept, undone, looks, t }
|
|
39
|
+
* clean(group, type, input) → { prop } | { error } what `pmos propose loose …` checks
|
|
40
|
+
* awayOf(rows, today, o) PURE → the idle rows Claude proposes to put away, no run needed
|
|
41
|
+
* viewOf(F, rows, o) PURE → what the ✦ and the Viewer draw, or null (zero is silence)
|
|
42
|
+
* historyOf(F) → the approvals, newest first, each with its own Undo (rule 9) */
|
|
43
|
+
const fs = require('fs');
|
|
44
|
+
const path = require('path');
|
|
45
|
+
const crypto = require('crypto');
|
|
46
|
+
|
|
47
|
+
const DIR = 'loose-props';
|
|
48
|
+
const LEDGER = 'proposals.jsonl';
|
|
49
|
+
const ROWS = 'rows.json';
|
|
50
|
+
const KINDS = new Set(['look', 'end', 'propose', 'drop', 'undrop', 'keep', 'undo']);
|
|
51
|
+
const GROUPS = { link: ['ini'], tidy: ['merge', 'finish', 'away'], start: ['new'] };
|
|
52
|
+
const IDLE_DAYS = 14;
|
|
53
|
+
const MANY = 10; // the group passed 10 rows: Claude looks at once (rule 7)
|
|
54
|
+
const START_MIN = 3; // 3 or more leftovers about one new thing (rule 11)
|
|
55
|
+
const ROW_RE = /^(c|s|w|m):.{1,300}$/;
|
|
56
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
57
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
58
|
+
const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
59
|
+
const hash = (s) => crypto.createHash('sha1').update(String(s)).digest('hex').slice(0, 10);
|
|
60
|
+
const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
|
|
61
|
+
const newBatch = () => 'lk-' + crypto.randomBytes(5).toString('hex');
|
|
62
|
+
const scopeOf = (group) => (group === 'tidy' ? 'tidy' : group === 'start' ? 'start' : 'link');
|
|
63
|
+
const dropKey = (scope, row) => scope + '|' + row;
|
|
64
|
+
|
|
65
|
+
/* ── the files ── */
|
|
66
|
+
function dirOf(runtimeDir) { return runtimeDir ? path.join(runtimeDir, DIR) : null; }
|
|
67
|
+
const ledgerFile = (dir) => (dir ? path.join(dir, LEDGER) : null);
|
|
68
|
+
const rowsFile = (dir) => (dir ? path.join(dir, ROWS) : null);
|
|
69
|
+
function readLines(file) {
|
|
70
|
+
if (!file) return [];
|
|
71
|
+
let text = '';
|
|
72
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (isObj(l) && KINDS.has(l.kind)) out.push(l); } catch { /* a torn line is skipped */ } }
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
const read = (dir) => fold(readLines(ledgerFile(dir)));
|
|
78
|
+
function append(dir, actor, ev) {
|
|
79
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
80
|
+
const line = { at: new Date().toISOString(), by: (actor && actor.by) || null, ...ev };
|
|
81
|
+
fs.appendFileSync(ledgerFile(dir), JSON.stringify(line) + '\n');
|
|
82
|
+
return line;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ── the snapshot of the rows Home shows loose ── */
|
|
86
|
+
/** One row as the page sends it, cleaned; null when it is not a row. */
|
|
87
|
+
function rowOf(x) {
|
|
88
|
+
if (!isObj(x) || !ROW_RE.test(str(x.id))) return null;
|
|
89
|
+
const kind = ['session', 'item', 'meeting'].includes(x.kind) ? x.kind : null;
|
|
90
|
+
if (!kind) return null;
|
|
91
|
+
const r = { id: one(x.id, 300), kind, title: one(x.title, 160) || '(untitled)', at: /^\d{4}-\d{2}-\d{2}/.test(str(x.at)) ? str(x.at).slice(0, 30) : '' };
|
|
92
|
+
if (x.waits) r.waits = true;
|
|
93
|
+
if (x.late) r.late = true;
|
|
94
|
+
if (kind === 'session') {
|
|
95
|
+
r.sids = (Array.isArray(x.sids) ? x.sids : []).filter((s) => typeof s === 'string' && /^[A-Za-z0-9_.:-]{1,80}$/.test(s)).slice(0, 20);
|
|
96
|
+
if (str(x.key)) r.key = one(x.key, 200);
|
|
97
|
+
if (str(x.words)) r.words = one(x.words, 240);
|
|
98
|
+
if (!r.sids.length) return null;
|
|
99
|
+
}
|
|
100
|
+
if (kind === 'item') { if (!str(x.item)) return null; r.item = one(x.item, 120); }
|
|
101
|
+
if (kind === 'meeting') {
|
|
102
|
+
if (!isObj(x.event) || !str(x.event.title)) return null;
|
|
103
|
+
r.event = { title: one(x.event.title, 300), ...(str(x.event.series) ? { series: one(x.event.series, 300) } : {}) };
|
|
104
|
+
if (x.daily) r.daily = one(x.daily === true ? 'Repeats' : x.daily, 40);
|
|
105
|
+
}
|
|
106
|
+
return r;
|
|
107
|
+
}
|
|
108
|
+
/** An open initiative Home knows (any ticked product): what a Link may name. { id, title, ws?, anchor? } */
|
|
109
|
+
function iniOf(x) {
|
|
110
|
+
if (!isObj(x) || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(str(x.id))) return null;
|
|
111
|
+
return { id: x.id, title: one(x.title || x.id, 140), ...(str(x.ws) ? { ws: one(x.ws, 120) } : {}), ...(str(x.board) ? { board: one(x.board, 120) } : {}), ...(str(x.anchor) ? { anchor: one(x.anchor, 120) } : {}) };
|
|
112
|
+
}
|
|
113
|
+
function readRows(dir) {
|
|
114
|
+
try {
|
|
115
|
+
const j = JSON.parse(fs.readFileSync(rowsFile(dir), 'utf8'));
|
|
116
|
+
return { rows: (j.rows || []).map(rowOf).filter(Boolean), inis: (j.inis || []).map(iniOf).filter(Boolean), at: str(j.at), over10: str(j.over10), sig: str(j.sig) };
|
|
117
|
+
} catch { return { rows: [], inis: [], at: '', over10: '', sig: '' }; }
|
|
118
|
+
}
|
|
119
|
+
/** Saves what Home shows loose now, and the initiatives it knows. → { changed, over10, rows, inis } over10: when the group went past MANY
|
|
120
|
+
* rows ('' while it holds MANY or fewer). */
|
|
121
|
+
function saveRows(dir, rows, now = Date.now(), inis, pageSig) {
|
|
122
|
+
const clean = (Array.isArray(rows) ? rows : []).slice(0, 400).map(rowOf).filter(Boolean);
|
|
123
|
+
const was = readRows(dir);
|
|
124
|
+
const I = Array.isArray(inis) ? inis.slice(0, 400).map(iniOf).filter(Boolean) : was.inis;
|
|
125
|
+
const sig = (L) => hash(JSON.stringify(L));
|
|
126
|
+
const over10 = clean.length > MANY ? (was.rows.length > MANY && was.over10 ? was.over10 : new Date(now).toISOString()) : '';
|
|
127
|
+
// pageSig: the page's own signature of what it sent, so the next open reads instead of sending again
|
|
128
|
+
const ps = /^[a-z0-9]{1,24}$/.test(str(pageSig)) ? str(pageSig) : '';
|
|
129
|
+
if (sig(clean) === sig(was.rows) && sig(I) === sig(was.inis) && over10 === was.over10 && ps === was.sig) return { changed: false, over10, rows: clean, inis: I };
|
|
130
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
131
|
+
fs.writeFileSync(rowsFile(dir), JSON.stringify({ at: new Date(now).toISOString(), over10, ...(ps ? { sig: ps } : {}), rows: clean, inis: I }));
|
|
132
|
+
return { changed: true, over10, rows: clean, inis: I };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* ── what a run may file (`pmos propose loose …`): short fields, each claim with its pointer ── */
|
|
136
|
+
function clean(group, type, input) {
|
|
137
|
+
if (!GROUPS[group]) return { error: 'group is one of ' + Object.keys(GROUPS).join(', ') };
|
|
138
|
+
if (!GROUPS[group].includes(type)) return { error: `type of ${group} is one of ${GROUPS[group].join(', ')}` };
|
|
139
|
+
if (type === 'away') return { error: 'idle chats are found without a run: file link, merge, finish or start' };
|
|
140
|
+
if (!isObj(input)) return { error: 'the proposal is a JSON object' };
|
|
141
|
+
const why = one(input.why, 300);
|
|
142
|
+
if (!why) return { error: 'why is one line: what the rows share, in plain words' };
|
|
143
|
+
const sources = (Array.isArray(input.sources) ? input.sources : []).filter((s) => isObj(s) && str(s.label)).slice(0, 8).map((s) => ({ label: one(s.label, 80), ...(str(s.ref) ? { ref: one(s.ref, 500) } : {}) }));
|
|
144
|
+
const raw = Array.isArray(input.items) ? input.items : [];
|
|
145
|
+
if (!raw.length) return { error: 'items is the list of rows: [{ "row": "<row id>" }]' };
|
|
146
|
+
if (raw.length > 60) return { error: 'at most 60 rows' };
|
|
147
|
+
const items = [];
|
|
148
|
+
for (const [i, x] of raw.entries()) {
|
|
149
|
+
if (!isObj(x) || !ROW_RE.test(str(x.row))) return { error: `item ${i + 1}: row is a row id from the list (c:…, s:…, w:… or m:…)` };
|
|
150
|
+
const it = { row: one(x.row, 300) };
|
|
151
|
+
if (type === 'finish') {
|
|
152
|
+
// rule 4: each Finish row quotes the message that closed the work, with its date; no quote, no Finish
|
|
153
|
+
if (!one(x.quote, 200)) return { error: `item ${i + 1}: quote is the message that closed the work (no quote, no Finish)` };
|
|
154
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(str(x.at))) return { error: `item ${i + 1}: at is the date of that message, YYYY-MM-DD` };
|
|
155
|
+
it.quote = one(x.quote, 200); it.at = str(x.at);
|
|
156
|
+
}
|
|
157
|
+
if (items.some((y) => y.row === it.row)) continue;
|
|
158
|
+
items.push(it);
|
|
159
|
+
}
|
|
160
|
+
const data = {};
|
|
161
|
+
if (type === 'ini') {
|
|
162
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(str(input.initiative))) return { error: 'initiative is the id of the initiative the rows belong to' };
|
|
163
|
+
data.ini = str(input.initiative); data.title = one(input.title || input.initiative, 140);
|
|
164
|
+
if (str(input.ws)) data.ws = one(input.ws, 120);
|
|
165
|
+
}
|
|
166
|
+
if (type === 'merge') {
|
|
167
|
+
if (!/^w:/.test(str(input.into))) return { error: 'into is the row of the PM\'s own item that stays (w:…)' };
|
|
168
|
+
data.into = one(input.into, 300);
|
|
169
|
+
if (items.some((x) => !/^[cs]:/.test(x.row))) return { error: 'a merge takes chats (c:… or s:…) into the PM\'s own item' };
|
|
170
|
+
}
|
|
171
|
+
if (type === 'new') {
|
|
172
|
+
if (items.length < START_MIN) return { error: `an initiative starts from ${START_MIN} or more rows` };
|
|
173
|
+
data.title = one(input.title, 120);
|
|
174
|
+
if (!data.title) return { error: 'title is the new initiative\'s name' };
|
|
175
|
+
data.why = one(input.intent || input.why, 400);
|
|
176
|
+
data.anchor = one(input.anchor, 120);
|
|
177
|
+
if (!data.anchor) return { error: 'anchor is the KR or health:<id> it counts toward (unanchored work is rejected)' };
|
|
178
|
+
}
|
|
179
|
+
// the id names what it does and to which rows: the same proposal filed again is one, new rows for the same initiative are another
|
|
180
|
+
const key = type === 'ini' ? data.ini : type === 'merge' ? data.into : type === 'new' ? data.title.toLowerCase() : 'finish';
|
|
181
|
+
return { prop: { id: 'lp-' + hash([group, type, key, ...items.map((x) => x.row).sort()].join('|')), group, type, title: one(input.label, 140) || null, why, sources, items, data } };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* ── the fold ── */
|
|
185
|
+
function fold(lines) {
|
|
186
|
+
const props = new Map(), drops = new Set(), kept = [], undone = new Set(), looks = [];
|
|
187
|
+
let t = '';
|
|
188
|
+
for (const l of lines || []) {
|
|
189
|
+
if (!isObj(l) || !KINDS.has(l.kind)) continue;
|
|
190
|
+
if (l.at && String(l.at) > t) t = String(l.at);
|
|
191
|
+
if (l.kind === 'look' && str(l.run)) looks.push({ run: l.run, at: str(l.at), ended: false, ok: null });
|
|
192
|
+
else if (l.kind === 'end') { const L = looks.find((x) => x.run === l.run); if (L) { L.ended = true; L.ok = !!l.ok; L.stopped = !!l.stopped; } }
|
|
193
|
+
else if (l.kind === 'propose' && str(l.id) && GROUPS[l.group]) props.set(l.id, { id: l.id, run: str(l.run), group: l.group, type: str(l.type), title: str(l.title), why: str(l.why), sources: Array.isArray(l.sources) ? l.sources : [], items: (Array.isArray(l.items) ? l.items : []).filter((x) => isObj(x) && str(x.row)), data: isObj(l.data) ? l.data : {}, at: str(l.at) });
|
|
194
|
+
else if (l.kind === 'drop' || l.kind === 'undrop') { for (const r of Array.isArray(l.rows) ? l.rows : []) { const k = dropKey(str(l.scope) || 'link', r); if (l.kind === 'drop') drops.add(k); else drops.delete(k); } }
|
|
195
|
+
else if (l.kind === 'keep' && str(l.batch)) kept.push({ batch: l.batch, ids: Array.isArray(l.ids) ? l.ids : [], said: str(l.said), wrote: (Array.isArray(l.wrote) ? l.wrote : []).filter(isObj), at: str(l.at), by: l.by || null });
|
|
196
|
+
else if (l.kind === 'undo' && str(l.batch)) undone.add(l.batch);
|
|
197
|
+
}
|
|
198
|
+
return { props, drops, kept, undone, looks, t };
|
|
199
|
+
}
|
|
200
|
+
/** The rows a ✓ placed (an undone batch gives its rows back). */
|
|
201
|
+
// a closed session is not placed: it leaves Home by its away mark, and a chat the PM opens again can be placed later
|
|
202
|
+
function placedRows(F) { const s = new Set(); for (const k of F.kept) if (!F.undone.has(k.batch)) for (const w of k.wrote) if (w.row && w.op !== 'close') s.add(w.row); return s; }
|
|
203
|
+
const lastLook = (F) => (F.looks.length ? F.looks[F.looks.length - 1] : null);
|
|
204
|
+
|
|
205
|
+
/* ── rule 10: chats idle 14 days or more, no run needed ── */
|
|
206
|
+
const dayN = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? Math.round(Date.UTC(+m[1], +m[2] - 1, +m[3]) / 864e5) : null; };
|
|
207
|
+
/** PURE. today: YYYY-MM-DD. → [row] the sessions with no message for IDLE_DAYS or more, none waiting on the PM, the longest idle first. */
|
|
208
|
+
function awayOf(rows, today, o = {}) {
|
|
209
|
+
const t = dayN(today); if (t == null) return [];
|
|
210
|
+
return (rows || []).filter((r) => r.kind === 'session' && !r.waits && !r.late && dayN(r.at) != null && t - dayN(r.at) >= (o.days || IDLE_DAYS))
|
|
211
|
+
.sort((a, b) => String(a.at).localeCompare(String(b.at)));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* ── the view ── */
|
|
215
|
+
const TIDY = ['merge', 'finish', 'close', 'away'];
|
|
216
|
+
const ORDER = { ini: 0, merge: 1, finish: 2, new: 3, close: 4, away: 5 };
|
|
217
|
+
/**
|
|
218
|
+
* PURE. What the ✦ and the Viewer draw, or null when there is nothing to propose.
|
|
219
|
+
* rows the snapshot (readRows), what Home shows loose now
|
|
220
|
+
* o { today: YYYY-MM-DD, inis?: Map id → { title } (the open initiatives the page knows; a Link to one that is gone is not drawn) }
|
|
221
|
+
* → { n (rows Claude can place), total (rows loose), groups: [{ group, props: [p] }], looking, t }
|
|
222
|
+
* p: { id, group, type, scope, title, why, sources, data, rows: [{ row, kind, title, at, daily?, waits?, quote?, quoteAt?, words? }] }
|
|
223
|
+
*/
|
|
224
|
+
/** PURE. The close proposal from the server's closable list ([{ sid, key?, title, ini?, quietMs, say }]): one row per chat (by its key) or session. */
|
|
225
|
+
function closeOf(list) {
|
|
226
|
+
const rows = [], seen = new Set();
|
|
227
|
+
for (const c of Array.isArray(list) ? list : []) {
|
|
228
|
+
if (!c || !c.sid) continue;
|
|
229
|
+
const row = c.key ? 'c:' + c.key : 's:' + c.sid;
|
|
230
|
+
if (seen.has(row)) continue; seen.add(row);
|
|
231
|
+
rows.push({ row, kind: 'session', title: String(c.title || 'Session').slice(0, 160), at: '', sids: [c.sid], ...(c.key ? { key: c.key } : {}), ...(c.ini ? { ini: c.ini } : {}), say: String(c.say || '') });
|
|
232
|
+
}
|
|
233
|
+
return { id: 'lp-close', group: 'tidy', type: 'close', scope: 'tidy', title: '', why: 'Idle 30 minutes or more, pushed, and nothing waits on you. Closing keeps the transcript.', sources: [], data: {}, rows };
|
|
234
|
+
}
|
|
235
|
+
function viewOf(F, rows, o = {}) {
|
|
236
|
+
const byId = new Map((rows || []).map((r) => [r.id, r]));
|
|
237
|
+
const placed = placedRows(F), keptIds = new Set(); for (const k of F.kept) if (!F.undone.has(k.batch)) for (const id of k.ids) keptIds.add(id);
|
|
238
|
+
const taken = new Set();
|
|
239
|
+
const live = [];
|
|
240
|
+
const cands = [...F.props.values()].filter((p) => !keptIds.has(p.id)).sort((a, b) => (ORDER[a.type] ?? 9) - (ORDER[b.type] ?? 9) || String(b.at).localeCompare(String(a.at)));
|
|
241
|
+
const away = { id: 'lp-away', group: 'tidy', type: 'away', title: '', why: 'No message for 14 days or more, and none waits on you. They leave Home; Search keeps them.', sources: [], data: {},
|
|
242
|
+
items: awayOf(rows, o.today).map((r) => ({ row: r.id })) };
|
|
243
|
+
// batch 13 item 7: live sessions idle and safe to close, in an initiative or not (o.closable: the server's list, read now, never a run's)
|
|
244
|
+
const shut = closeOf(o.closable);
|
|
245
|
+
shut.rows = shut.rows.filter((x) => !F.drops.has(dropKey('tidy', x.row)));
|
|
246
|
+
if (shut.rows.length) {
|
|
247
|
+
for (const x of shut.rows) taken.add(x.row);
|
|
248
|
+
live.push(shut);
|
|
249
|
+
}
|
|
250
|
+
for (const p of cands.concat(away.items.length ? [away] : [])) {
|
|
251
|
+
const scope = scopeOf(p.group);
|
|
252
|
+
if (p.type === 'ini' && o.inis && !o.inis.has(p.data.ini)) continue;
|
|
253
|
+
const its = [];
|
|
254
|
+
for (const x of p.items) {
|
|
255
|
+
const r = byId.get(x.row);
|
|
256
|
+
if (!r || taken.has(r.id) || placed.has(r.id) || F.drops.has(dropKey(scope, r.id))) continue;
|
|
257
|
+
// rule 3: a row that waits on the PM, or a late check box, can only be linked; its dot moves with it
|
|
258
|
+
if (TIDY.includes(p.type) && (r.waits || r.late)) continue;
|
|
259
|
+
if (p.type === 'merge' && (r.kind !== 'session' || !byId.has(p.data.into) || placed.has(p.data.into))) continue;
|
|
260
|
+
if (p.type === 'finish' && !x.quote) continue;
|
|
261
|
+
its.push({ row: r.id, kind: r.kind, title: r.title, at: r.at, ...(r.daily ? { daily: r.daily } : {}), ...(r.waits ? { waits: true } : {}), ...(r.late ? { late: true } : {}),
|
|
262
|
+
...(x.quote ? { quote: x.quote, quoteAt: x.at || '' } : {}), ...(r.words ? { words: r.words } : {}) });
|
|
263
|
+
}
|
|
264
|
+
if (!its.length || (p.type === 'new' && its.length < START_MIN)) continue;
|
|
265
|
+
for (const x of its) taken.add(x.row);
|
|
266
|
+
live.push({ id: p.id, group: p.group, type: p.type, scope, title: p.title, why: p.why, sources: p.sources, data: p.data, rows: its,
|
|
267
|
+
...(p.type === 'merge' ? { into: { row: p.data.into, title: byId.get(p.data.into).title } } : {}) });
|
|
268
|
+
}
|
|
269
|
+
const L = lastLook(F), looking = !!(L && !L.ended);
|
|
270
|
+
if (!live.length) return looking ? { n: 0, total: (rows || []).length, groups: [], looking, t: F.t } : null;
|
|
271
|
+
const groups = [];
|
|
272
|
+
for (const g of ['link', 'tidy', 'start']) {
|
|
273
|
+
const ps = live.filter((p) => p.group === g);
|
|
274
|
+
if (!ps.length) continue;
|
|
275
|
+
// groups sorted by size (the grill's legacy pile); Tidy keeps merge, finish, away
|
|
276
|
+
if (g !== 'tidy') ps.sort((a, b) => b.rows.length - a.rows.length);
|
|
277
|
+
else ps.sort((a, b) => ORDER[a.type] - ORDER[b.type]);
|
|
278
|
+
groups.push({ group: g, props: ps });
|
|
279
|
+
}
|
|
280
|
+
return { n: taken.size, total: (rows || []).length, groups, looking, t: F.t };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The approvals, newest first: { batch, at, said, n, undone } (rule 9: each with its own Undo). */
|
|
284
|
+
function historyOf(F) {
|
|
285
|
+
return F.kept.map((k) => ({ batch: k.batch, at: k.at, said: k.said, n: new Set(k.wrote.map((w) => w.row).filter(Boolean)).size, undone: F.undone.has(k.batch) }))
|
|
286
|
+
.sort((a, b) => String(b.at).localeCompare(String(a.at)));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** The toast's one line (XlcA2After): "19 placed" or "4 placed, 1 initiative started". */
|
|
290
|
+
function saidOf(wrote) {
|
|
291
|
+
const n = new Set(wrote.filter((w) => w.op !== 'close').map((w) => w.row).filter(Boolean)).size;
|
|
292
|
+
const shut = new Set(wrote.filter((w) => w.op === 'close').map((w) => w.row)).size;
|
|
293
|
+
const made = wrote.filter((w) => w.op === 'create').length;
|
|
294
|
+
const parts = [n ? n + ' placed' : '', shut ? shut + ' closed' : ''].filter(Boolean);
|
|
295
|
+
return (parts.join(', ') || 'Nothing placed') + (made ? ', ' + plural(made, 'initiative', 'initiatives') + ' started' : '');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
module.exports = {
|
|
299
|
+
closeOf,
|
|
300
|
+
DIR, LEDGER, ROWS, GROUPS, IDLE_DAYS, MANY, START_MIN, dirOf, ledgerFile, rowsFile, readLines, read, append, readRows, saveRows, rowOf, iniOf, clean, fold,
|
|
301
|
+
placedRows, lastLook, awayOf, viewOf, historyOf, saidOf, newBatch, scopeOf, hash, dayN,
|
|
302
|
+
};
|
|
@@ -153,7 +153,7 @@ function rowOf(it, list, v, inReview, focusIds) {
|
|
|
153
153
|
const say = lead ? (overdue || list === 'waiting' ? state + ' ' : '') + lead : state;
|
|
154
154
|
const { sug, cta } = suggestOf(it, list, today, overdue);
|
|
155
155
|
return {
|
|
156
|
-
key: 'work:' + it.id, id: it.id, list, title: clip(it.title, 140), sub: sub + (added && (list === 'inbox' || list === 'tray') ? ' · added ' + added : ''), chip, overdue, src: srcLabel(it), sug, cta,
|
|
156
|
+
key: 'work:' + it.id, id: it.id, list, title: clip(it.title, 140), ...(it.initiative ? { ini: it.initiative } : {}), at: it.touched_at || it.created_at || null, sub: sub + (added && (list === 'inbox' || list === 'tray') ? ' · added ' + added : ''), chip, overdue, src: srcLabel(it), sug, cta,
|
|
157
157
|
agent: agentOf(it) && agentOf(it) !== 'suggest' ? agentOf(it) : null,
|
|
158
158
|
focus: list === 'today' && focusIds.has(it.id),
|
|
159
159
|
dialog: {
|