create-pmos 0.413.0 → 0.415.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/AGENTS.md +2 -2
- package/payload/KIT-VERSION +1 -1
- package/payload/mods/pmos-cockpit/README.md +1 -1
- package/payload/mods/pmos-cockpit/hooks/lib/guard.mjs +11 -5
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/pmos-log.sh +12 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/bin/pmos.js +1 -1
- package/workspace/briefing-premium-board-test.js +45 -9
- package/workspace/briefing-premium-test.js +3 -2
- package/workspace/changelog.json +24 -0
- package/workspace/guide/programs.md +13 -0
- package/workspace/guide/workflows.md +10 -0
- package/workspace/home-other-product-test.js +18 -0
- package/workspace/lib/board-premium.js +9 -0
- package/workspace/lib/engine/boards.js +4 -2
- package/workspace/lib/goal-chat.js +46 -15
- package/workspace/lib/headless.js +10 -1
- package/workspace/lib/initiative-chat.js +5 -3
- package/workspace/lib/initiative-premium.js +4 -2
- package/workspace/lib/item-cli.js +2 -1
- package/workspace/lib/milestone-review.js +120 -0
- package/workspace/lib/milestone-suggest.js +176 -0
- package/workspace/lib/pmos-verbs.js +6 -0
- package/workspace/lib/program-cli.js +56 -0
- package/workspace/lib/programs.js +4 -1
- package/workspace/lib/routes-boards.js +121 -16
- package/workspace/lib/routes-briefing-premium.js +14 -1
- package/workspace/lib/routes-programs.js +73 -7
- package/workspace/lib/task-cli.js +168 -0
- package/workspace/lib/task-items.js +86 -0
- package/workspace/milestone-suggest-test.js +175 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-chat-line-test.js +3 -1
- package/workspace/public/pm/bd-ini-model.js +81 -0
- package/workspace/public/pm/bd-ini-panel.js +144 -59
- package/workspace/public/pm/bd-prog-panel.js +54 -14
- package/workspace/public/pm/cozy-home.css +5 -0
- package/workspace/public/pm/cozy-panel.css +2 -0
- package/workspace/public/pm/cozy-viewer.js +2 -0
- package/workspace/public/pm/cozy-xv.css +51 -16
- package/workspace/public/pm/cozy-xv.js +6 -5
- package/workspace/public/pm/home-app.js +13 -11
- package/workspace/public/pm/home-ask.js +9 -3
- package/workspace/public/pm/home-chat.js +10 -1
- package/workspace/public/pm/home-list.js +12 -7
- package/workspace/public/pm/home-stage-card.js +3 -2
- package/workspace/public/pm/home-today.js +5 -8
- package/workspace/public/pm/ms-suggest.css +50 -0
- package/workspace/public/pm/ms-suggest.js +98 -0
- package/workspace/public/pm/premium-board.js +11 -2
- package/workspace/public/pm/premium-initiative-head.js +25 -6
- package/workspace/public/pm/program-charter.js +47 -7
- package/workspace/public/pm/program-model.js +4 -1
- package/workspace/public/pm/wf-page.js +3 -0
- package/workspace/server.js +23 -1
- package/workspace/skills/milestone-review.skill +53 -0
- package/workspace/test-lists/bd-ini-panel.json +5 -0
- package/workspace/test-lists/milestone-suggest.json +6 -0
- package/workspace/test-lists/one-task-list.json +5 -0
|
@@ -68,10 +68,11 @@ const unskipMessage = (point) => MARK.unskip + ' The PM took the skip back: the
|
|
|
68
68
|
|
|
69
69
|
function startMessage(draft) {
|
|
70
70
|
return [
|
|
71
|
-
MARK.start + ' The PM pressed Start. Work on this goal now,
|
|
71
|
+
MARK.start + ' The PM pressed Start. Work on this goal now, on your own, until every done point is met:',
|
|
72
72
|
JSON.stringify(draft),
|
|
73
|
-
'
|
|
74
|
-
'
|
|
73
|
+
'Do whatever the goal needs, as the PM would. Do not stop to ask for approval, feedback or a choice: pick the sensible option yourself, say in one line what you chose, and go on. Merging follows the PM\'s standing rule (merge once required CI is green).',
|
|
74
|
+
'Stop for the PM only when the work cannot go on without them: a sign-in or secret only they have, or a message that goes to other people. Then do every other open point first, and end with needs-you and exactly what you need.',
|
|
75
|
+
'At the end of each message about this goal, add a fenced pmos-goal block: {"step":"progress","state":"working|done|needs-you","met":["done points met"],"open":["done points still open"]}. Copy each done point word for word. Report done only after you checked every point.',
|
|
75
76
|
].join('\n');
|
|
76
77
|
}
|
|
77
78
|
const cancelMessage = () => MARK.cancel + ' The PM cancelled this goal. Do no more work for it and say in one line what you stopped.';
|
|
@@ -141,6 +142,13 @@ function blockOf(text) {
|
|
|
141
142
|
try { const b = JSON.parse(last[1]); return b && typeof b === 'object' ? b : null; } catch { return null; }
|
|
142
143
|
}
|
|
143
144
|
const strs = (a) => (Array.isArray(a) ? a.map((x) => clip(x, 200)).filter(Boolean).slice(0, 8) : null);
|
|
145
|
+
const norm = (x) => String(x == null ? '' : x).toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
|
146
|
+
/** The plan points Claude reports met. Claude rewords them (bug 2026-10-25: "Goal done" with 0 of 4 met), so a point counts when a
|
|
147
|
+
* reported string is the same after norm, or, both 12 characters or more, one holds the other. */
|
|
148
|
+
function matchPoints(reported, all) {
|
|
149
|
+
const got = (Array.isArray(reported) ? reported : []).map(norm).filter(Boolean);
|
|
150
|
+
return (all || []).filter((p) => { const n = norm(p); return n && got.some((r) => r === n || (r.length >= 12 && n.length >= 12 && (r.includes(n) || n.includes(r)))); });
|
|
151
|
+
}
|
|
144
152
|
/** The chat key a session belongs to (premium-chat-sessions.jsonl, the last line that names it), or null. */
|
|
145
153
|
function keyOfSession(runtimeDir, session, chatsFile) {
|
|
146
154
|
let t; try { t = fs.readFileSync(path.join(runtimeDir, chatsFile), 'utf8'); } catch { return null; }
|
|
@@ -156,21 +164,33 @@ const roundsOf = (runtimeDir, id) => {
|
|
|
156
164
|
function onStop({ runtimeDir, key, message, now = new Date() }) {
|
|
157
165
|
const g = key && goalOf(runtimeDir, key);
|
|
158
166
|
if (!g || g.state !== 'started' || !g.draft) return {};
|
|
159
|
-
const d = g.draft, b = blockOf(message), all = requiredOf(g)
|
|
160
|
-
const
|
|
161
|
-
|
|
167
|
+
const d = g.draft, b = blockOf(message), all = requiredOf(g);
|
|
168
|
+
const p = b && b.step === 'progress' ? b : null;
|
|
169
|
+
// the plan decides what is met and open: Claude's own open list and its "done" alone do not count
|
|
170
|
+
const met = p && Array.isArray(p.met) ? matchPoints(strs(p.met), all) : (g.met || []).filter((x) => all.includes(x));
|
|
171
|
+
const open = all.filter((x) => !met.includes(x));
|
|
162
172
|
const base = { id: g.id, key, met, open, at: now.toISOString() };
|
|
163
|
-
if (
|
|
164
|
-
|
|
173
|
+
if (all.length && !open.length) { append(runtimeDir, { event: 'done', ...base }); return {}; }
|
|
174
|
+
const prev = roundsOf(runtimeDir, g.id), last = prev[prev.length - 1];
|
|
175
|
+
const needs = !!(p && p.state === 'needs-you');
|
|
176
|
+
// the goal works on its own (feedback 2026-10-25): the first needs-you is sent back; a second one in a row waits on the PM
|
|
177
|
+
if (needs && last && last.asked && Date.parse(last.at) >= Date.parse(g.at || '')) { append(runtimeDir, { event: 'waiting', ...base }); return {}; }
|
|
165
178
|
const due = Date.parse(d.by || '');
|
|
166
179
|
const stop = (reason) => { append(runtimeDir, { event: 'stopped', reason, ...base }); return {}; };
|
|
167
180
|
if (Number.isFinite(due) && now.getTime() > due) return stop('deadline');
|
|
168
181
|
const n = (g.rounds || 0) + 1;
|
|
169
182
|
if (n > (d.limit || LIMIT)) return stop('limit');
|
|
170
|
-
const
|
|
183
|
+
const head = '[PMOS /goal round ' + n + '] ';
|
|
184
|
+
if (needs) {
|
|
185
|
+
append(runtimeDir, { event: 'round', n, asked: true, ...base });
|
|
186
|
+
return { decision: 'block', reason: head + 'Do not wait for the PM. Pick the sensible option yourself, say in one line what you chose, and go on. Only if the work truly cannot go on without the PM (a sign-in or secret only they have, or a message to other people), end again with needs-you and exactly what you need.' };
|
|
187
|
+
}
|
|
171
188
|
if (prev.length >= NO_PROGRESS && prev.slice(-NO_PROGRESS).every((r) => (r.met || []).length >= met.length)) return stop('no-progress');
|
|
172
189
|
append(runtimeDir, { event: 'round', n, ...base });
|
|
173
|
-
|
|
190
|
+
const said = p && p.state === 'done'
|
|
191
|
+
? 'You reported done, but these points are not met yet: ' + open.join('; ') + '. Check each one, and work on the ones that are not true yet. Copy each point word for word in met.'
|
|
192
|
+
: 'The goal is not done yet: ' + met.length + ' of ' + all.length + ' done points met. Keep working on: ' + (open.length ? open.join('; ') : 'the open points') + '.';
|
|
193
|
+
return { decision: 'block', reason: head + said + ' This is round ' + n + ' of ' + (d.limit || LIMIT) + '. End each message with the progress block. Do not stop to ask for approval. Decide yourself and go on.' };
|
|
174
194
|
}
|
|
175
195
|
/** The PM wrote in the goal's conversation. A goal that waits on them is working again (U3); a finished or stopped goal is seen,
|
|
176
196
|
* so its Briefing row goes (U7). A goal in any other state is left as it is. */
|
|
@@ -228,10 +248,10 @@ function withGoalRows(model, rows) {
|
|
|
228
248
|
const count = (model.list.count || 0) + add.length;
|
|
229
249
|
return { ...model, list: { ...model.list, rows: list, count }, dock: model.dock && model.dock.needs != null ? { ...model.dock, needs: count, label: count === 1 ? 'needs you' : 'need you', next: list[0].title } : model.dock };
|
|
230
250
|
}
|
|
231
|
-
/** The Claude Code --settings for a chat session: a Stop hook
|
|
251
|
+
/** The Claude Code --settings for a chat session: a Stop hook, an AskUserQuestion hook and a hook on every tool (goal-tool), each posting to this workspace with the session's token. */
|
|
232
252
|
function hookSettings(port, host = '127.0.0.1') {
|
|
233
253
|
const hook = (route) => ({ type: 'http', url: 'http://' + host + ':' + port + '/api/briefing-premium/' + route, headers: { 'x-pmos-session': '$PMOS_SESSION' }, allowedEnvVars: ['PMOS_SESSION'], timeout: 10 });
|
|
234
|
-
return { hooks: { Stop: [{ hooks: [hook('goal-stop')] }], PreToolUse: [{ matcher: ASK_TOOL, hooks: [hook('ask-tool')] }] } };
|
|
254
|
+
return { hooks: { Stop: [{ hooks: [hook('goal-stop')] }], PreToolUse: [{ matcher: ASK_TOOL, hooks: [hook('ask-tool')] }, { matcher: '*', hooks: [hook('goal-tool')] }] } };
|
|
235
255
|
}
|
|
236
256
|
/* chat-ask-card (bug 2026-10-22): Claude Code's question tool draws a picker in the terminal, and the chat panel cannot show it. The panel
|
|
237
257
|
* showed "Claude is working", the PM pressed Stop (Esc) and the question ended as "[Request interrupted by user for tool use]", again and
|
|
@@ -241,8 +261,19 @@ const ASK_TOOL = 'AskUserQuestion';
|
|
|
241
261
|
const ASK_REASON = 'The PM is in the PMOS chat panel, not a terminal. The panel already shows these questions and their options as buttons, '
|
|
242
262
|
+ 'and the PM\'s answer comes as their next message. Do not ask again and do not guess the answer: end your turn now with one short line. '
|
|
243
263
|
+ 'If you are working on a /goal, end with a pmos-goal progress block whose state is needs-you.';
|
|
244
|
-
|
|
245
|
-
|
|
264
|
+
const GOAL_ASK_REASON = 'You are working on a /goal the PM started, and the PM asked you to finish it on your own. Do not ask: pick the sensible option yourself, '
|
|
265
|
+
+ 'say in one line what you chose, and go on. Only if the work truly cannot go on without the PM (a sign-in or secret only they have, or a message to other people), '
|
|
266
|
+
+ 'end your turn with a pmos-goal progress block whose state is needs-you.';
|
|
267
|
+
/** goal: the chat key's goal, or null. A started goal does not ask at all; any other chat waits for the PM's answer in the panel. */
|
|
268
|
+
function askToolReply(goal) {
|
|
269
|
+
const reason = goal && goal.state === 'started' ? GOAL_ASK_REASON : ASK_REASON;
|
|
270
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: reason } };
|
|
271
|
+
}
|
|
272
|
+
/* A started goal works on its own (feedback 2026-10-25: it stopped for approval prompts): no permission prompt stops it. The PM's deny
|
|
273
|
+
* rules still apply. With no started goal the answer is {} and Claude Code asks as usual. */
|
|
274
|
+
function goalToolReply(goal, toolName) {
|
|
275
|
+
if (!goal || goal.state !== 'started' || toolName === ASK_TOOL) return {};
|
|
276
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'allow', permissionDecisionReason: 'PMOS: the PM started a /goal and asked Claude to finish it on its own.' } };
|
|
246
277
|
}
|
|
247
278
|
|
|
248
279
|
/** chat() hands a `/goal` message here: { error } or { id, prompt } with the grilling line already on record. */
|
|
@@ -305,4 +336,4 @@ function decide({ runtimeDir, key, id, act, draft, point, session, sessions, now
|
|
|
305
336
|
return { status: 200, body: { ok: true, id, state: act === 'start' ? 'started' : 'cancelled' } };
|
|
306
337
|
}
|
|
307
338
|
|
|
308
|
-
module.exports = { parseCommand, grillPrompt, methodMessage, planMessage, skipMessage, unskipMessage, METHODS, startMessage, cancelMessage, cleanDraft, goalOf, statesAt, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, askToolReply, ASK_TOOL, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
|
|
339
|
+
module.exports = { parseCommand, grillPrompt, methodMessage, planMessage, skipMessage, unskipMessage, METHODS, startMessage, cancelMessage, cleanDraft, goalOf, statesAt, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, askToolReply, goalToolReply, matchPoints, ASK_TOOL, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (initiative workspace-headless-jobs; PM decision 2026-10-11: keep Jev, no direct Claude API, background
|
|
4
4
|
* jobs that need no human run headless).
|
|
5
5
|
*
|
|
6
|
-
* kindFor({ agent, origin, skill, env }) → 'notes' | 'skill' | 'ask' | 'drive' | 'scan-web' | 'scan-repo' | 'scan-research-web' | 'scan-research-repo' | 'report-setup' | 'report-find' | 'core-doc' | 'report-design' | 'report-structure-pull' | 'report-sample-fetch' | 'report-structure' | 'report-structure-dry' | null (null: open a pane, as before)
|
|
6
|
+
* kindFor({ agent, origin, skill, env }) → 'notes' | 'skill' | 'ask' | 'drive' | 'scan-web' | 'scan-repo' | 'scan-research-web' | 'scan-research-repo' | 'report-setup' | 'report-find' | 'core-doc' | 'report-design' | 'report-structure-pull' | 'report-sample-fetch' | 'report-structure' | 'report-structure-dry' | 'ms-review' | null (null: open a pane, as before)
|
|
7
7
|
* argsFor(kind, { modelArgs, addDirs, writePaths }) → the argv after `claude` (writePaths: the one render file a report-design job may write;
|
|
8
8
|
* for the skill kind, the folders the run may write in, from skillWriteDirs)
|
|
9
9
|
* skillWriteDirs(skill, { root, scratch }) → the absolute folders a background skill run may write in: its scratch folder and the state folders its skill writes
|
|
@@ -50,6 +50,9 @@
|
|
|
50
50
|
* (the cycle document, the samples, the earlier versions and the brief) and writes ONE file: the render at the pending path the server gives it, named in
|
|
51
51
|
* its tool list as `Write(//<path>)` and `Edit(//<path>)`. It has no web tool, no Bash and no connector tool, and nothing that sends. The server sanitizes
|
|
52
52
|
* the render before anything shows it. It never runs in a pane.
|
|
53
|
+
* The `ms-review` kind is Claude's milestone review of one program (feedback batch 4 item 6): origin `ms-review:<program>:<run>`. It reads the
|
|
54
|
+
* repositories of the program's initiatives and, where the PM's own settings allow it, Jira and meeting notes through connectors; its only write is
|
|
55
|
+
* `pmos program suggest`, pinned by the server to that program and run. It never writes the charter and sends nothing. It never runs in a pane.
|
|
53
56
|
* The `report-structure` and `report-structure-dry` kinds are the report structure step (initiative report-structure): origins `report-structure:<id>` and
|
|
54
57
|
* `report-structure-dry:<id>`. A turn proposes or refines the plan of a report (sources, charts, outline); a dry run tries a saved version on the last complete
|
|
55
58
|
* period. Each reads the repository and, where the PM's own Claude Code settings allow it, reads through connectors (none is named in the list, as for
|
|
@@ -88,6 +91,8 @@ const REPORT_SETUP_ORIGINS = Object.freeze(['report-setup:']);
|
|
|
88
91
|
const REPORT_FIND_ORIGINS = Object.freeze(['report-find:']);
|
|
89
92
|
// core-documents: one run drafts one core document of a portfolio, a board or an initiative (origin `core-doc:<scope>:<key>`).
|
|
90
93
|
const CORE_DOC_ORIGINS = Object.freeze(['core-doc:']);
|
|
94
|
+
// Claude's milestone review of one program (origin `ms-review:<program>:<run>`, lib/milestone-review.js).
|
|
95
|
+
const MS_REVIEW_ORIGINS = Object.freeze(['ms-review:']);
|
|
91
96
|
// report-design-studio: a studio turn, a cycle render or a re-render to match (origin `report-design:<cadence>`).
|
|
92
97
|
const REPORT_DESIGN_ORIGINS = Object.freeze(['report-design:']);
|
|
93
98
|
// report-design-studio: reading ONE linked Google or Confluence file through the PM's own connectors (origin `report-sample-fetch:<cadence>:<sampleId>`).
|
|
@@ -134,6 +139,9 @@ const TOOLS = Object.freeze({
|
|
|
134
139
|
'report-find': Object.freeze(['Read', 'Glob', 'Grep', 'Bash(pmos report propose *)']),
|
|
135
140
|
// The core-doc run: read and search, and the one verb that writes a draft. No Write, no Edit, no web, nothing that sends.
|
|
136
141
|
'core-doc': Object.freeze(['Read', 'Glob', 'Grep', 'Bash(pmos coredoc write *)']),
|
|
142
|
+
// The milestone review run: read and search the initiatives' repositories, and the one verb that files a suggestion. Jira and meeting notes are
|
|
143
|
+
// read through the PM's own connectors only where the PM's settings allow it. No Write, no Edit, no web, nothing that sends; it never writes the charter.
|
|
144
|
+
'ms-review': Object.freeze(['Read', 'Glob', 'Grep', 'Bash(pmos program suggest *)']),
|
|
137
145
|
// The design run: read and search only. Its one write, the render file, is added per run by argsFor (writePaths). No Bash, no web, nothing that sends.
|
|
138
146
|
'report-design': Object.freeze(['Read', 'Glob', 'Grep']),
|
|
139
147
|
// The link fetch run: Read, and its one write (the text copy of the linked file) is added per run by argsFor. No Bash, no web, no connector tool named.
|
|
@@ -169,6 +177,7 @@ function kindFor({ agent, origin, skill, env } = {}) {
|
|
|
169
177
|
if (REPORT_SETUP_ORIGINS.some((p) => o.startsWith(p))) return 'report-setup';
|
|
170
178
|
if (REPORT_FIND_ORIGINS.some((p) => o.startsWith(p))) return 'report-find';
|
|
171
179
|
if (CORE_DOC_ORIGINS.some((p) => o.startsWith(p))) return 'core-doc';
|
|
180
|
+
if (MS_REVIEW_ORIGINS.some((p) => o.startsWith(p))) return 'ms-review';
|
|
172
181
|
if (REPORT_DESIGN_ORIGINS.some((p) => o.startsWith(p))) return 'report-design';
|
|
173
182
|
if (REPORT_SAMPLE_FETCH_ORIGINS.some((p) => o.startsWith(p))) return 'report-sample-fetch';
|
|
174
183
|
// 'report-structure-dry:' is not a prefix of 'report-structure:' (the colon differs), so the two are told apart by their prefix alone
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* infoOf(answer) → { id, title, wf: { id, name }, stage: { key, name, n, of }, stages: [{ key, name, status }], ended } | null
|
|
12
12
|
* from lib/routes-boards.js initiativeWorkflow's answer
|
|
13
13
|
* rule(info, id) → the rule's lines, with the workflow and stage when info is known
|
|
14
|
-
* isAsk(text) → whether a message is about a stage, a workflow or a
|
|
14
|
+
* isAsk(text) → whether a message is about a stage, a workflow, a move or a task
|
|
15
15
|
* wrap(text, info, id) → the message as PMOS types it into a live session */
|
|
16
16
|
|
|
17
17
|
// The first line of every message PMOS wraps. The page reads it to show the PM's turn as typed (public/pm/goal-chat.js shownUser).
|
|
18
18
|
const MARK = '[PMOS initiative]';
|
|
19
19
|
const SAYS = 'The PM says: ';
|
|
20
|
-
const ASK_RE = /\b(stages?|workflows?|move[sd]?|moving|phases?|advance|next step)\b/i;
|
|
20
|
+
const ASK_RE = /\b(stages?|workflows?|move[sd]?|moving|phases?|advance|next step|tasks?)\b/i; // a task ask gets the one-kind-of-task rule (feedback batch 5)
|
|
21
21
|
|
|
22
22
|
const isAsk = (text) => ASK_RE.test(String(text == null ? '' : text)) && !String(text).trim().startsWith('/');
|
|
23
23
|
|
|
@@ -38,7 +38,9 @@ function rule(info, id) {
|
|
|
38
38
|
} else out.push(`Run \`pmos workflow of ${ini}\` to see the workflow this initiative runs and its current stage.`);
|
|
39
39
|
out.push(
|
|
40
40
|
`The workflow stage is on the initiative: the stage card and the Board show it. \`pmos workflow of ${ini}\` reads it. When the PM asks to move the initiative, run \`pmos workflow move ${ini} --stage <key> --why "<reason>"\`. When the PM asks to change its workflow, run \`pmos workflow switch ${ini} --to <workflow id>\`. Both write what the page's press writes, under your name.`,
|
|
41
|
-
'
|
|
41
|
+
'There is one kind of task: the ones the PM sees in the initiative\'s Tasks section. The stage card\'s To finish entries and the older breakdown items are tasks too. '
|
|
42
|
+
+ 'A task has no workflow stage. Its only stage is its state: To do, In progress, Done, Won\'t do or Archived. When the PM asks to add, close or change a task, '
|
|
43
|
+
+ `do it yourself, never send the PM to the Board: \`pmos task add ${ini} "<title>" [--due YYYY-MM-DD]\` adds one, \`pmos task list ${ini}\` names them all and \`pmos task state <task> [<task> …] --to "<state>" --why "<what shows it>"\` sets them. Never use \`pmos item add\` for new work. Never set a task's stage, and never change tasks to move the initiative.`,
|
|
42
44
|
);
|
|
43
45
|
return out;
|
|
44
46
|
}
|
|
@@ -89,9 +89,11 @@ function build(f) {
|
|
|
89
89
|
: ((sheet && sheet.stepper) || []).map((s) => ({ k: s.id, label: s.label || s.id, state: s.state === 'todo' ? 'pending' : s.state, stateLabel: STEP_STATE[s.state] || cap1(s.state), owed: s.owed ? clip(typeof s.owed === 'string' ? s.owed : s.owed.text || s.owed.what || '', 160) : '', cur: s.state === 'current' }));
|
|
90
90
|
const allSteps = steps ? steps.map((s) => ({ label: s.label || s.key, stateLabel: LAD_STATE[s.status] || cap1(s.status), note: clip(s.evidence || (s.basis && s.basis.rule) || s.rule || '', 220) })) : [];
|
|
91
91
|
|
|
92
|
-
// ── tasks: PRD requirements (no result per requirement) and the board's
|
|
92
|
+
// ── tasks: PRD requirements (no result per requirement) and the board's items: its Board tasks, the initiative's breakdown items and its
|
|
93
|
+
// stage's To finish tasks are one kind of task (feedback batch 5, lib/task-items.js), Jira rows are read-only ──
|
|
93
94
|
const items = (f.items || []).filter((t) => t && t.ini === id).slice(0, MAX_TASKS);
|
|
94
|
-
const tracker = items.map((t, n) => ({ key: 'task:' + (t.uid || t.key || n), uid: t.uid || '', pmos: t.src === 'pmos', ref: t.key || t.ref || '', title: clip(t.title, 160), state: t.status || 'To do', src: t.src === 'jira' ? 'Jira (read-only)' : 'PMOS task', owner: t.owner || '', start: t.start || '', end: t.end || '', blocked: !!t.blocked, kind: t.kind || 'Task', notes: t.notes || '', readAt: t.readAt || ''
|
|
95
|
+
const tracker = items.map((t, n) => ({ key: 'task:' + (t.uid || t.key || n), uid: t.uid || '', pmos: t.src === 'pmos', ref: t.key || t.ref || '', title: clip(t.title, 160), state: t.status || 'To do', src: t.src === 'jira' ? 'Jira (read-only)' : 'PMOS task', owner: t.owner || '', start: t.start || '', end: t.end || '', blocked: !!t.blocked, kind: t.kind || 'Task', notes: t.notes || '', readAt: t.readAt || '',
|
|
96
|
+
...(t.from ? { from: { stage: t.from.stage, finish: t.from.finish } } : {}), ...(t.store === 'item' ? { store: 'item' } : {}) }));
|
|
95
97
|
const dv = sheet && sheet.derived;
|
|
96
98
|
const reqs = dv && Array.isArray(dv.items) ? dv.items.slice(0, MAX_TASKS).map((x) => ({ key: 'req:' + x.id, ref: x.ref || x.id, title: clip(x.title, 160), state: null, src: 'PRD requirement' })) : [];
|
|
97
99
|
const prog = ini.progress || null;
|
|
@@ -27,7 +27,8 @@ const { parseArgs } = require('./schedule-cli');
|
|
|
27
27
|
|
|
28
28
|
const COMMANDS = { item: ['add', 'set', 'move', 'withdraw', 'list'] };
|
|
29
29
|
const USAGE = [
|
|
30
|
-
'usage: pmos item add|set|move|withdraw|list — an initiative\'s breakdown items',
|
|
30
|
+
'usage: pmos item add|set|move|withdraw|list — an initiative\'s breakdown items, the older record of its tasks',
|
|
31
|
+
'New tasks go through pmos task add, and pmos task list|state lists and closes breakdown items too. There is one kind of task.',
|
|
31
32
|
' pmos item add <initiative> "<title>" --stage <stage> [--due YYYY-MM-DD] [--start YYYY-MM-DD]',
|
|
32
33
|
' [--owner you|agent|person:<name>|tracker:<ref>] [--after <item>[,<item>]] [--milestone] [--note "<text>"]',
|
|
33
34
|
' pmos item set <item> [--title "<title>"] [--stage <stage>] [--due <date>|none] [--start <date>|none] [--owner <owner>]',
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* lib/milestone-review.js — Claude reviews a program's milestones and files suggestions the PM keeps, changes or drops (feedback batch 4 item 6;
|
|
3
|
+
* canvas XmsgB, the sticky xmsgRules).
|
|
4
|
+
*
|
|
5
|
+
* off(env) → true when PMOS_MS_REVIEW=off (or 0, false, no)
|
|
6
|
+
* reviewPrompt(skill, o) → the prompt of one run. o: { program, run, why, now, open, declined, roots, rows }
|
|
7
|
+
* create(deps) → { tick(opts), active() }
|
|
8
|
+
*
|
|
9
|
+
* WHEN (lib/milestone-suggest.js dueOf): Check now at once; else inside the working hours, for a program never reviewed, after an initiative
|
|
10
|
+
* joins or leaves, after the page saw a ◆ date move (a Jira slip moves one too), when a milestone's date comes, and every Monday from 09:00.
|
|
11
|
+
* At most ONE run at a time for the machine, and one start per tick. A run that ends badly waits 6 hours before the next automatic one.
|
|
12
|
+
*
|
|
13
|
+
* WHAT THE RUN MAY DO. It is headless (lib/headless.js kind ms-review, origin `ms-review:<program>:<run>`): it reads and searches the repositories
|
|
14
|
+
* of the program's initiatives (their records, plan items and meeting notes) and, where the PM's own Claude Code settings allow it, reads Jira and
|
|
15
|
+
* the meeting notes through connectors. Its only write is `pmos program suggest`, pinned by the server to this program and run
|
|
16
|
+
* (PMOS_MS_REVIEW_FILE, PMOS_MS_REVIEW_RUN, PMOS_MS_REVIEW_PROGRAM). It never writes the charter: only the PM's press does (POST
|
|
17
|
+
* /api/programs/suggestion). Nothing is sent.
|
|
18
|
+
*
|
|
19
|
+
* deps: { programs() → [program with home], reviewOf(p) → { file, state } | null, rootOf(ws) → root | null, open(now) → bool (working hours),
|
|
20
|
+
* headlessOff() → bool, env, promptFor(skillId) → skill body | null, rowsOf(p) → [{ id, title, stage, deliver }] (what the server's last
|
|
21
|
+
* board read says, or []), spawn(spec) → session row (through the capacity governor), spawnNow(spec) (Check now), stop(session),
|
|
22
|
+
* append(file, line), warn(what, err) }
|
|
23
|
+
*/
|
|
24
|
+
const crypto = require('crypto');
|
|
25
|
+
const MS = require('./milestone-suggest.js');
|
|
26
|
+
|
|
27
|
+
const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
|
|
28
|
+
const off = (env) => flagOff((env || process.env).PMOS_MS_REVIEW);
|
|
29
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
30
|
+
const WHY = {
|
|
31
|
+
asked: 'The PM pressed Check now.',
|
|
32
|
+
new: 'The program has never been reviewed. If it has no milestones, suggest its first ones.',
|
|
33
|
+
members: 'An initiative joined or left the program.',
|
|
34
|
+
dates: 'A ◆ date of one of its initiatives moved (a plan or Jira change).',
|
|
35
|
+
date: 'A milestone\'s date has come.',
|
|
36
|
+
weekly: 'The weekly review (Monday).',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function reviewPrompt(skill, o) {
|
|
40
|
+
const p = o.program;
|
|
41
|
+
const ms = (p.milestones || []).map((m) => `- ${m.id} · ${one(m.name, 80)} · ${m.date || 'no date'} · ${(m.waits || []).length ? 'waits on ' + m.waits.join(', ') : 'a check the PM ticks'}${m.done ? ' · done' : ''}${m.risk ? ' · at risk: ' + one(m.risk, 120) : ''}`);
|
|
42
|
+
const mem = (p.members || []).map((m) => { const r = (o.rows || []).find((x) => x.id === m.initiative); return `- ${m.initiative}${r ? ` · ${one(r.title, 80)} · stage ${one(r.stage, 30) || 'unknown'}${r.deliver ? ' · ◆ ' + r.deliver : ''}` : ''} · repository ${(o.roots || {})[m.ws] || 'not on this machine'}`; });
|
|
43
|
+
const open = (o.open || []).map((i) => `- ${JSON.stringify({ op: i.op, milestone: i.milestone, name: i.name, date: i.date, waits: i.waits, why: i.why, src: i.src })}`);
|
|
44
|
+
const dec = (o.declined || []).map((x) => `- ${x}`);
|
|
45
|
+
const list = (a, none) => (a.length ? a.join('\n') : '- ' + none);
|
|
46
|
+
return `${skill}\n\nThis run:\n- Run: ${o.run}\n- Today: ${new Date(o.now).toISOString().slice(0, 10)}\n- Why it runs: ${WHY[o.why] || WHY.weekly}\n`
|
|
47
|
+
+ `- Program: ${p.id} · ${one(p.title, 120)}${p.goal ? ' · goal: ' + one(p.goal, 160) : ''}\n- Span: ${p.start || 'no start'} to ${p.target || 'no target'}${p.jira ? '\n- Jira: ' + one(p.jira, 40) : ''}\n`
|
|
48
|
+
+ `- Milestones (${(p.milestones || []).length} of 12):\n${list(ms, 'none yet')}\n- Initiatives in the program:\n${list(mem, 'none')}\n`
|
|
49
|
+
+ `- Open suggestions from the last review (file again each one that still holds; one you do not file again is withdrawn):\n${list(open, 'none')}\n`
|
|
50
|
+
+ `- Declined by the PM (do not suggest these again from the same source):\n${list(dec, 'none')}\n\n`
|
|
51
|
+
+ 'File each suggestion with `pmos program suggest --json -`. File at most 8. Write no charter. Send nothing.';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function create(deps) {
|
|
55
|
+
const active = new Map(); // run → { p, file, session }
|
|
56
|
+
const warn = deps.warn || (() => {});
|
|
57
|
+
|
|
58
|
+
function ended(run, r, now = Date.now()) {
|
|
59
|
+
const a = active.get(run); if (!a) return;
|
|
60
|
+
active.delete(run);
|
|
61
|
+
const res = (r && r.result) || {};
|
|
62
|
+
const ok = !!(r && !r.timedOut && !r.stopped && r.code === 0 && res.ok && !res.isError);
|
|
63
|
+
try { deps.append(a.file, { kind: 'review-end', program: a.p.id, run, ok, ...(ok ? {} : { error: one((r && r.note) || res.text || 'the run failed', 200) }) }, new Date(now)); } catch (e) { warn('milestone review end', e); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function start(p, R, why, now) {
|
|
67
|
+
const run = 'r' + now.toString(36) + crypto.randomBytes(3).toString('hex');
|
|
68
|
+
const begin = () => { deps.append(R.file, { kind: 'review-start', program: p.id, run, why, members: MS.membersFp(p) }, new Date(now)); active.set(run, { p, file: R.file, session: null }); };
|
|
69
|
+
const skill = deps.promptFor('milestone-review');
|
|
70
|
+
if (!skill) { begin(); ended(run, { code: 1, note: 'the milestone-review skill is not installed', result: {} }, now); return; }
|
|
71
|
+
const st = R.state;
|
|
72
|
+
const open = st ? MS.openOf(st, p) : [];
|
|
73
|
+
const declined = st ? [...st.items.values()].filter((i) => st.answers.get(i.key) === 'decline').map((i) => `${i.op} ${i.milestone || i.name}${i.date ? ' to ' + i.date : ''} (source: ${i.src.kind}, ${i.src.label})`) : [];
|
|
74
|
+
const roots = {};
|
|
75
|
+
for (const m of p.members || []) if (!(m.ws in roots)) roots[m.ws] = deps.rootOf(m.ws) || '';
|
|
76
|
+
let rows = [];
|
|
77
|
+
try { rows = (deps.rowsOf && deps.rowsOf(p)) || []; } catch { rows = []; }
|
|
78
|
+
const prompt = reviewPrompt(skill, { program: p, run, why, now, open, declined, roots, rows });
|
|
79
|
+
const home = deps.rootOf(p.home);
|
|
80
|
+
const addDirs = [...new Set(Object.values(roots).filter((r) => r && r !== home))];
|
|
81
|
+
// Check now is the PM's press: it starts at once (deps.spawnNow); the rest go through the capacity governor, which may hold a start
|
|
82
|
+
const go = why === 'asked' && deps.spawnNow ? deps.spawnNow : deps.spawn;
|
|
83
|
+
let session = null;
|
|
84
|
+
try {
|
|
85
|
+
session = go({ name: 'Milestone review · ' + one(p.title, 60), ws: p.home, origin: `ms-review:${p.id}:${run}`, initialInput: prompt + '\r', addDirs,
|
|
86
|
+
env: { PMOS_MS_REVIEW_FILE: R.file, PMOS_MS_REVIEW_RUN: run, PMOS_MS_REVIEW_PROGRAM: p.id }, onDone: (r) => ended(run, r) });
|
|
87
|
+
} catch (e) { warn('milestone review', e); }
|
|
88
|
+
if (session && session.held) return; // held by the capacity governor: nothing is written, the next tick tries again
|
|
89
|
+
begin();
|
|
90
|
+
if (!session || session.state === 'exited' || session.headless !== 'ms-review') {
|
|
91
|
+
// a start that did not become a headless run (no `claude`, headless off, a refused model) is a failed run, never a pane
|
|
92
|
+
if (session && session.headless !== 'ms-review' && session.state !== 'exited' && deps.stop) { try { deps.stop(session); } catch { /* best effort */ } }
|
|
93
|
+
ended(run, { code: 1, note: (session && session.note) || 'the review could not start as a background run', result: {} }, now);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const a = active.get(run); if (a) a.session = session.id;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function tick({ now = Date.now(), env } = {}) {
|
|
100
|
+
if (off(env || deps.env) || (deps.headlessOff && deps.headlessOff())) return { off: true };
|
|
101
|
+
if (active.size) return { running: active.size };
|
|
102
|
+
let open = true;
|
|
103
|
+
try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
|
|
104
|
+
for (const p of deps.programs() || []) {
|
|
105
|
+
if (!p || !p.home || p.archived) continue;
|
|
106
|
+
let R = null;
|
|
107
|
+
try { R = deps.reviewOf(p); } catch (e) { warn('milestone review read', e); }
|
|
108
|
+
if (!R) continue;
|
|
109
|
+
const due = MS.dueOf(R.state, p, now, { open });
|
|
110
|
+
if (!due) continue;
|
|
111
|
+
try { start(p, R, due.why, now); } catch (e) { warn('milestone review start', e); }
|
|
112
|
+
return { started: p.id, why: due.why };
|
|
113
|
+
}
|
|
114
|
+
return { started: null };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { tick, active: () => [...active.keys()] };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { off, reviewPrompt, create, WHY };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* lib/milestone-suggest.js — Claude's milestone suggestions for a program, and the reviews that make them (feedback batch 4 item 6; canvas XmsgB,
|
|
3
|
+
* rules on the sticky xmsgRules).
|
|
4
|
+
*
|
|
5
|
+
* validItem(x) → { item } | { error } what one filed suggestion may say
|
|
6
|
+
* sigOf(item) · keyOf(program, item) the source signature (a decline remembers it) and the suggestion's key
|
|
7
|
+
* fold(lines) → { [program]: state } PURE. state: { items: Map key → item, answers: Map key → answer, declined: Set sig,
|
|
8
|
+
* runs: [run], asks: [iso], facts: fp | '' }
|
|
9
|
+
* openOf(state, program, now) → [item] what waits on the PM now: the latest finished review's items, less the answered,
|
|
10
|
+
* the declined and the ones the charter already says
|
|
11
|
+
* viewOf(state, program, now) → { checked, running, open } for GET /api/programs (each program's `review`)
|
|
12
|
+
* applyTo(program, item) → the charter body POST /api/programs/save takes, with the change made (✓ Keep)
|
|
13
|
+
* dueOf(state, program, now, o) → { why } | null should a review start now? o: { open (working hours), membersFp }
|
|
14
|
+
* membersFp(program) the member set as one string: a join or a leave changes it
|
|
15
|
+
* fileOf(stateDir) <state>/milestone-reviews.jsonl, in the charter's workspace
|
|
16
|
+
*
|
|
17
|
+
* A LINE is one of:
|
|
18
|
+
* { kind: 'review-start', program, run, why, members } a review began (why: new | members | asked | dates | date | weekly)
|
|
19
|
+
* { kind: 'review-end', program, run, ok, error? }
|
|
20
|
+
* { kind: 'suggest', program, run, key, item } one suggestion the review run filed (`pmos program suggest`)
|
|
21
|
+
* { kind: 'answer', program, key, answer } the PM's press: keep (written at once) · edit (saved from the charter) · decline
|
|
22
|
+
* { kind: 'review-ask', program, why } Check now (why 'asked'), or the page saw a ◆ date move (why 'dates')
|
|
23
|
+
* { kind: 'facts', program, fp } the ◆ dates the page last saw, so a move asks for a review once
|
|
24
|
+
*
|
|
25
|
+
* THE RULES (xmsgRules). Claude proposes add, move, rename, drop or at risk, each with why and its source. Nothing is written without the PM:
|
|
26
|
+
* keep writes the charter in one press, the pencil opens the charter with the change filled in, decline drops it and Claude does not ask again
|
|
27
|
+
* unless that source changes (the signature holds the source's label, so "Jira, Oct 30" is a new source after "Jira, Oct 22"). A review files
|
|
28
|
+
* the whole list it stands by: a suggestion an older review filed and the latest one did not is no longer open. No change, nothing shows. */
|
|
29
|
+
const path = require('path');
|
|
30
|
+
const crypto = require('crypto');
|
|
31
|
+
|
|
32
|
+
const OPS = ['add', 'move', 'rename', 'drop', 'risk'];
|
|
33
|
+
const SRC = ['deliver', 'jira', 'meeting', 'task', 'target', 'member', 'charter'];
|
|
34
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]{0,60}$/;
|
|
35
|
+
const INI_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
|
|
36
|
+
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
37
|
+
const MAX_MS = 12;
|
|
38
|
+
const RUN_MS = 30 * 60 * 1000; // a start with no end after this is over (the server stopped mid-run)
|
|
39
|
+
const GAP_MS = 30 * 60 * 1000; // two automatic reviews of one program are this far apart at least
|
|
40
|
+
const RETRY_MS = 6 * 60 * 60 * 1000; // after a failed run, the next automatic one waits this long
|
|
41
|
+
const SLOT_H = 9; // the weekly review: Monday from 09:00
|
|
42
|
+
const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
43
|
+
const slug = (t) => String(t || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 50);
|
|
44
|
+
const fileOf = (stateDir) => path.join(stateDir, 'milestone-reviews.jsonl');
|
|
45
|
+
|
|
46
|
+
/** One filed suggestion: { op, milestone?, name?, date?, waits?, why, src: { kind, label } }. Each op says what it needs. */
|
|
47
|
+
function validItem(x) {
|
|
48
|
+
if (!x || typeof x !== 'object' || Array.isArray(x)) return { error: 'a suggestion is a JSON object' };
|
|
49
|
+
const op = String(x.op || '');
|
|
50
|
+
if (!OPS.includes(op)) return { error: 'op is one of ' + OPS.join(', ') };
|
|
51
|
+
const why = str(x.why, 240);
|
|
52
|
+
if (!why) return { error: 'why says, in one line, what you read that makes the change' };
|
|
53
|
+
const s = x.src && typeof x.src === 'object' ? x.src : {};
|
|
54
|
+
if (!SRC.includes(String(s.kind || ''))) return { error: 'src.kind is one of ' + SRC.join(', ') };
|
|
55
|
+
const label = str(s.label, 80);
|
|
56
|
+
if (!label) return { error: 'src.label names the source, for example "Steering, Oct 22" or "Jira DSC-41"' };
|
|
57
|
+
const item = { op, why, src: { kind: String(s.kind), label } };
|
|
58
|
+
if (op !== 'add') {
|
|
59
|
+
if (!ID_RE.test(String(x.milestone || ''))) return { error: op + ' names the milestone by its id (milestone)' };
|
|
60
|
+
item.milestone = String(x.milestone);
|
|
61
|
+
}
|
|
62
|
+
if (op === 'add' || op === 'rename') {
|
|
63
|
+
const name = str(x.name, 80);
|
|
64
|
+
if (!name) return { error: op + ' needs the milestone name (name)' };
|
|
65
|
+
item.name = name;
|
|
66
|
+
}
|
|
67
|
+
if (op === 'add' || op === 'move') {
|
|
68
|
+
if (!DAY_RE.test(String(x.date || ''))) return { error: op + ' needs the date as YYYY-MM-DD (date)' };
|
|
69
|
+
item.date = String(x.date);
|
|
70
|
+
}
|
|
71
|
+
if (op === 'add') {
|
|
72
|
+
const w = Array.isArray(x.waits) ? x.waits.map(String) : [];
|
|
73
|
+
const bad = w.find((i) => !INI_RE.test(i));
|
|
74
|
+
if (bad) return { error: 'waits holds initiative ids; ' + str(bad, 40) + ' is not one' };
|
|
75
|
+
item.waits = [...new Set(w)].slice(0, 20);
|
|
76
|
+
}
|
|
77
|
+
return { item };
|
|
78
|
+
}
|
|
79
|
+
/** What a decline remembers: the change and its source. A new source label is a new signature, so Claude may ask again. */
|
|
80
|
+
const sigOf = (i) => [i.op, i.milestone || slug(i.name), i.date || '', i.op === 'rename' ? slug(i.name) : '', i.src.kind, i.src.label.toLowerCase()].join('|');
|
|
81
|
+
const keyOf = (program, i) => 's' + crypto.createHash('sha1').update(program + '|' + sigOf(i)).digest('hex').slice(0, 12);
|
|
82
|
+
|
|
83
|
+
const blank = () => ({ items: new Map(), answers: new Map(), declined: new Set(), runs: [], asks: [], facts: '', factsAt: '' });
|
|
84
|
+
function fold(lines) {
|
|
85
|
+
const out = {};
|
|
86
|
+
const get = (id) => out[id] || (out[id] = blank());
|
|
87
|
+
for (const l of lines || []) {
|
|
88
|
+
if (!l || typeof l !== 'object' || !ID_RE.test(String(l.program || ''))) continue;
|
|
89
|
+
const s = get(String(l.program));
|
|
90
|
+
if (l.kind === 'review-start' && l.run) s.runs.push({ run: String(l.run), start: l.at || '', why: l.why || '', members: l.members || '', end: '', ok: null, error: '' });
|
|
91
|
+
else if (l.kind === 'review-end' && l.run) { const r = s.runs.find((x) => x.run === String(l.run)); if (r && !r.end) Object.assign(r, { end: l.at || '', ok: !!l.ok, error: l.error || '' }); }
|
|
92
|
+
else if (l.kind === 'suggest' && l.key && l.item) { const v = validItem(l.item); if (v.item) s.items.set(String(l.key), { ...v.item, key: String(l.key), run: String(l.run || ''), at: l.at || '' }); }
|
|
93
|
+
else if (l.kind === 'answer' && l.key && ['keep', 'edit', 'decline'].includes(l.answer)) {
|
|
94
|
+
s.answers.set(String(l.key), l.answer);
|
|
95
|
+
const it = s.items.get(String(l.key));
|
|
96
|
+
if (it && l.answer === 'decline') s.declined.add(sigOf(it));
|
|
97
|
+
} else if (l.kind === 'review-ask') s.asks.push({ at: l.at || '', why: l.why || 'asked' });
|
|
98
|
+
else if (l.kind === 'facts' && typeof l.fp === 'string') { s.facts = l.fp; s.factsAt = l.at || ''; }
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
const ms = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : 0; };
|
|
103
|
+
const runningOf = (s, now) => (s ? s.runs.filter((r) => !r.end && now - ms(r.start) < RUN_MS) : []);
|
|
104
|
+
const lastDone = (s) => (s ? s.runs.filter((r) => r.end && r.ok).sort((a, b) => ms(a.end) - ms(b.end)).pop() || null : null);
|
|
105
|
+
|
|
106
|
+
/** True when the charter already says what the item would change, or the item no longer has anything to change. */
|
|
107
|
+
function stale(i, p) {
|
|
108
|
+
const M = (p && p.milestones) || [];
|
|
109
|
+
const m = i.milestone ? M.find((x) => x.id === i.milestone) : null;
|
|
110
|
+
if (i.op === 'add') return M.length >= MAX_MS || M.some((x) => slug(x.name) === slug(i.name));
|
|
111
|
+
if (!m) return true;
|
|
112
|
+
if (i.op === 'move') return m.date === i.date;
|
|
113
|
+
if (i.op === 'rename') return m.name === i.name;
|
|
114
|
+
if (i.op === 'risk') return !!m.risk || !!m.done;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
function openOf(s, p) {
|
|
118
|
+
const last = lastDone(s);
|
|
119
|
+
if (!last) return [];
|
|
120
|
+
const out = [];
|
|
121
|
+
for (const it of s.items.values()) {
|
|
122
|
+
if (it.run !== last.run || s.answers.has(it.key) || s.declined.has(sigOf(it)) || stale(it, p)) continue;
|
|
123
|
+
out.push(it);
|
|
124
|
+
}
|
|
125
|
+
// the program's own order: by the date the change is about, then what it is
|
|
126
|
+
const dayOf = (i) => i.date || (((p && p.milestones) || []).find((m) => m.id === i.milestone) || {}).date || '9999';
|
|
127
|
+
return out.sort((a, b) => dayOf(a).localeCompare(dayOf(b)) || OPS.indexOf(a.op) - OPS.indexOf(b.op));
|
|
128
|
+
}
|
|
129
|
+
function viewOf(s, p, now = Date.now()) {
|
|
130
|
+
const last = lastDone(s);
|
|
131
|
+
return { checked: last ? last.end : '', running: runningOf(s, now).length > 0, open: s ? openOf(s, p) : [], facts: (s && s.facts) || '' };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The charter with the item's change made, as validProgram takes it. The milestone keeps its id; a new one gets one from its name. */
|
|
135
|
+
function applyTo(p, i) {
|
|
136
|
+
let L = ((p && p.milestones) || []).map((m) => ({ ...m, waits: (m.waits || []).slice() }));
|
|
137
|
+
if (i.op === 'add') L.push({ name: i.name, date: i.date, waits: (i.waits || []).slice() });
|
|
138
|
+
else {
|
|
139
|
+
const m = L.find((x) => x.id === i.milestone);
|
|
140
|
+
if (!m) return { error: 'that milestone is no longer in the charter' };
|
|
141
|
+
if (i.op === 'move') m.date = i.date;
|
|
142
|
+
else if (i.op === 'rename') m.name = i.name;
|
|
143
|
+
else if (i.op === 'risk') m.risk = i.why;
|
|
144
|
+
else if (i.op === 'drop') L = L.filter((x) => x !== m);
|
|
145
|
+
}
|
|
146
|
+
if (L.length > MAX_MS) return { error: 'the charter holds 12 milestones at most' };
|
|
147
|
+
L.sort((a, b) => String(a.date || '9999').localeCompare(String(b.date || '9999')));
|
|
148
|
+
return { program: { id: p.id, title: p.title, owner: p.owner, goal: p.goal, why: p.why, start: p.start, target: p.target, jira: p.jira, milestones: L } };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const membersFp = (p) => ((p && p.members) || []).map((m) => (m.ws || '') + ':' + m.initiative).sort().join(',');
|
|
152
|
+
/** The Monday 00:00 (local) of the week that holds `t`. */
|
|
153
|
+
function weekStart(t) { const d = new Date(t); d.setHours(0, 0, 0, 0); d.setDate(d.getDate() - ((d.getDay() + 6) % 7)); return d.getTime(); }
|
|
154
|
+
|
|
155
|
+
/** Should a review of this program start now? Check now goes at once; the rest wait for the working hours, keep GAP_MS apart, and RETRY_MS
|
|
156
|
+
* after a failed run. The reasons, in order: asked · new (never reviewed) · members (a join or a leave) · dates (the page saw a ◆ date move) ·
|
|
157
|
+
* date (a milestone's date came) · weekly (Monday from 09:00, once a week). */
|
|
158
|
+
function dueOf(s, p, now, o = {}) {
|
|
159
|
+
if (runningOf(s, now).length) return null;
|
|
160
|
+
const runs = (s && s.runs) || [];
|
|
161
|
+
const last = runs.slice().sort((a, b) => ms(a.start) - ms(b.start)).pop() || null;
|
|
162
|
+
const since = last ? ms(last.start) : 0;
|
|
163
|
+
const asks = ((s && s.asks) || []).filter((a) => ms(a.at) > since);
|
|
164
|
+
if (asks.some((a) => a.why === 'asked')) return { why: 'asked' };
|
|
165
|
+
if (o.open === false) return null;
|
|
166
|
+
if (last && now - since < (last.end && !last.ok ? RETRY_MS : GAP_MS)) return null;
|
|
167
|
+
if (!last) return { why: 'new' };
|
|
168
|
+
if ((last.members || '') !== membersFp(p)) return { why: 'members' };
|
|
169
|
+
if (asks.length) return { why: 'dates' };
|
|
170
|
+
if (((p && p.milestones) || []).some((m) => m.date && DAY_RE.test(m.date) && !m.done && (() => { const d = new Date(m.date + 'T00:00:00').getTime(); return d > since && d <= now; })())) return { why: 'date' };
|
|
171
|
+
const d = new Date(now);
|
|
172
|
+
if (d.getDay() === 1 && d.getHours() >= SLOT_H && since < weekStart(now)) return { why: 'weekly' };
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = { OPS, SRC, validItem, sigOf, keyOf, fold, openOf, viewOf, applyTo, dueOf, membersFp, fileOf, weekStart, RUN_MS };
|
|
@@ -65,6 +65,12 @@ const VERBS = Object.freeze({
|
|
|
65
65
|
// Not a pm-os-absorb verb (run: null): workflows-per-initiative (D99) added it through the same table.
|
|
66
66
|
workflow: Object.freeze({ module: 'workflow-cli.js', run: null, guide: 'workflows.md',
|
|
67
67
|
help: 'pmos workflow list|show|draft|show-draft|judge|of|move|switch … — the workflows of this repository, the New workflow draft, a reading of an Only-when stage, and an initiative\'s workflow stage (pmos workflow help)' }),
|
|
68
|
+
// Not a pm-os-absorb verb (run: null): feedback batch 4 (Wawan, 2026-10-25) added it through the same table.
|
|
69
|
+
task: Object.freeze({ module: 'task-cli.js', run: null, guide: 'workflows.md',
|
|
70
|
+
help: 'pmos task add|list|state … — an initiative\'s tasks: add one, list them, set their state when the PM asks (pmos task help)' }),
|
|
71
|
+
// Not a pm-os-absorb verb (run: null): feedback batch 4 item 6 (Claude suggests program milestones) added it through the same table.
|
|
72
|
+
program: Object.freeze({ module: 'program-cli.js', run: null, guide: 'programs.md',
|
|
73
|
+
help: 'pmos program suggest — Claude\'s milestone suggestions for a program, filed by its review run (pmos program help)' }),
|
|
68
74
|
// Not a pm-os-absorb verb (run: null): c3-meet-extension added it through the same table.
|
|
69
75
|
extension: Object.freeze({ module: 'extension-cli.js', run: null, guide: 'console-calendar.md',
|
|
70
76
|
help: 'pmos extension — the folder of the Chrome extension for Google Meet, and the three steps to load it' }),
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* program-cli.js — `pmos program suggest`: the one write of Claude's milestone review run (feedback batch 4 item 6; canvas XmsgB).
|
|
3
|
+
*
|
|
4
|
+
* pmos program suggest --json <file|-> files one suggestion, or a list of them, for the program the review runs on
|
|
5
|
+
*
|
|
6
|
+
* The server pins the program, the run and the file in the run's environment (PMOS_MS_REVIEW_PROGRAM, PMOS_MS_REVIEW_RUN, PMOS_MS_REVIEW_FILE;
|
|
7
|
+
* lib/milestone-review.js); outside such a run the verb refuses. It writes `suggest` lines and nothing else: the charter changes only when the
|
|
8
|
+
* PM keeps a suggestion, on the page. A suggestion the PM declined from the same source answers `declined`, one this run filed already
|
|
9
|
+
* `duplicate`. Exit codes: 0 filed, 1 refused, 2 usage. Nothing is sent. */
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const pmItems = require('./pm-items.js');
|
|
12
|
+
const MS = require('./milestone-suggest.js');
|
|
13
|
+
|
|
14
|
+
const COMMANDS = { program: ['suggest'] };
|
|
15
|
+
const USAGE = [
|
|
16
|
+
'usage: pmos program suggest — Claude\'s milestone suggestions for a program',
|
|
17
|
+
' pmos program suggest --json <file|->',
|
|
18
|
+
' File one suggestion (a JSON object) or a list of them, in a milestone review run only. Each one:',
|
|
19
|
+
' { "op": "add|move|rename|drop|risk", "milestone": "<id, not for add>", "name": "<add, rename>", "date": "YYYY-MM-DD (add, move)",',
|
|
20
|
+
' "waits": ["<initiative id>", … (add)], "why": "<one line>", "src": { "kind": "deliver|jira|meeting|task|target|member|charter", "label": "Steering, Oct 22" } }',
|
|
21
|
+
' It answers filed, duplicate or declined for each. The PM keeps, changes or drops it on the page. Nothing is sent.',
|
|
22
|
+
];
|
|
23
|
+
const MAX_PER_RUN = 8;
|
|
24
|
+
|
|
25
|
+
async function run(argv, { say = (s) => console.log(s), env = process.env, stdin } = {}) {
|
|
26
|
+
const args = argv[0] === 'program' ? argv.slice(1) : argv.slice();
|
|
27
|
+
const verb = args[0];
|
|
28
|
+
if (!verb || verb === 'help' || verb === '--help' || verb === '-h') { for (const l of USAGE) say(l); return verb ? 0 : 1; }
|
|
29
|
+
if (!COMMANDS.program.includes(verb)) { say(`unknown program command "${verb}" — one of ${COMMANDS.program.join(', ')}`); return 2; }
|
|
30
|
+
const i = args.indexOf('--json'), src = i >= 0 ? args[i + 1] : null;
|
|
31
|
+
if (!src) { say('usage: pmos program suggest --json <file|->'); return 2; }
|
|
32
|
+
const file = env.PMOS_MS_REVIEW_FILE, runId = env.PMOS_MS_REVIEW_RUN, program = env.PMOS_MS_REVIEW_PROGRAM;
|
|
33
|
+
if (!file || !runId || !program) { say('✗ pmos program suggest is for Claude\'s milestone review run. The PM changes milestones in the charter'); return 1; }
|
|
34
|
+
let text;
|
|
35
|
+
try { text = src === '-' ? (stdin !== undefined ? String(stdin) : fs.readFileSync(0, 'utf8')) : fs.readFileSync(src, 'utf8'); } catch (e) { say(`✗ could not read ${src}: ${String((e && e.message) || e).slice(0, 120)}`); return 1; }
|
|
36
|
+
let body;
|
|
37
|
+
try { body = JSON.parse(text); } catch { say('✗ the input is not JSON'); return 1; }
|
|
38
|
+
const list = Array.isArray(body) ? body : [body];
|
|
39
|
+
const st = MS.fold(pmItems.readLines(file))[program] || null;
|
|
40
|
+
const mine = st ? [...st.items.values()].filter((x) => x.run === runId) : [];
|
|
41
|
+
let bad = 0;
|
|
42
|
+
for (const x of list) {
|
|
43
|
+
const v = MS.validItem(x);
|
|
44
|
+
if (v.error) { say(`✗ refused: ${v.error}`); bad++; continue; }
|
|
45
|
+
const key = MS.keyOf(program, v.item);
|
|
46
|
+
if (st && st.declined.has(MS.sigOf(v.item))) { say(`declined ${key}: the PM dropped this change from the same source`); continue; }
|
|
47
|
+
if (mine.some((y) => y.key === key)) { say(`duplicate ${key}`); continue; }
|
|
48
|
+
if (mine.length >= MAX_PER_RUN) { say(`✗ refused: a review files ${MAX_PER_RUN} suggestions at most`); bad++; continue; }
|
|
49
|
+
pmItems.appendEvent(file, { kind: 'suggest', program, run: runId, key, item: v.item });
|
|
50
|
+
mine.push({ ...v.item, key, run: runId });
|
|
51
|
+
say(`filed ${key}`);
|
|
52
|
+
}
|
|
53
|
+
return bad ? 1 : 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { run, COMMANDS, USAGE };
|