create-pmos 0.408.0 → 0.410.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-programs-test.js +1 -1
- package/workspace/board-wf-shot.js +45 -0
- package/workspace/board-workflows-test.js +186 -0
- package/workspace/briefing-premium-board-test.js +2 -2
- package/workspace/briefing-premium-initiative-test.js +1 -1
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-workflows-facts.js +49 -0
- package/workspace/fixtures/workflows-facts.js +53 -0
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/programs.md +2 -1
- package/workspace/guide/workflows.md +58 -0
- package/workspace/ini-workflow-test.js +177 -0
- package/workspace/lib/board-premium.js +30 -5
- package/workspace/lib/board-trail.js +24 -7
- package/workspace/lib/briefing-premium-agent.js +3 -0
- package/workspace/lib/engine/boards.js +30 -2
- package/workspace/lib/engine/workflows.js +204 -0
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/programs.js +22 -7
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-boards.js +157 -7
- package/workspace/lib/routes-programs.js +5 -0
- package/workspace/lib/routes-workflows.js +105 -0
- package/workspace/lib/workflow-chat.js +26 -0
- package/workspace/lib/workflow-cli.js +141 -0
- package/workspace/lib/workflows-store.js +108 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/program-charter-test.js +243 -0
- package/workspace/program-panel-test.js +1 -1
- package/workspace/public/pm/bd-acts.js +10 -5
- package/workspace/public/pm/bd-asks.js +2 -2
- package/workspace/public/pm/bd-prog-panel.js +36 -15
- package/workspace/public/pm/bd-prog.js +14 -4
- package/workspace/public/pm/bd-views.js +128 -45
- package/workspace/public/pm/bd-wf.js +99 -0
- package/workspace/public/pm/cozy-board.css +67 -6
- package/workspace/public/pm/cozy-evmodel.js +1 -1
- package/workspace/public/pm/cozy-panel.css +12 -6
- package/workspace/public/pm/cozy-settings.js +4 -2
- package/workspace/public/pm/cozy-viewer.js +36 -9
- package/workspace/public/pm/cozy-vw-shell.css +8 -0
- package/workspace/public/pm/goal-chat.js +1 -1
- package/workspace/public/pm/home-app.js +17 -9
- package/workspace/public/pm/home-ini-model.js +2 -2
- package/workspace/public/pm/home-ini.css +30 -0
- package/workspace/public/pm/home-ini.js +52 -9
- package/workspace/public/pm/home-list.js +10 -5
- package/workspace/public/pm/home-today.js +5 -5
- package/workspace/public/pm/ini-wf-model.js +91 -0
- package/workspace/public/pm/ini-wf.js +160 -0
- package/workspace/public/pm/premium-board.js +98 -30
- package/workspace/public/pm/premium-initiative-head.js +18 -8
- package/workspace/public/pm/program-charter.css +135 -0
- package/workspace/public/pm/program-charter.js +333 -0
- package/workspace/public/pm/program-model.js +48 -5
- package/workspace/public/pm/wf-edit.js +119 -0
- package/workspace/public/pm/wf-model.js +48 -0
- package/workspace/public/pm/wf-page.css +162 -0
- package/workspace/public/pm/wf-page.js +398 -0
- package/workspace/public/pm/wf-stage.js +187 -0
- package/workspace/public/premium-workflows.html +31 -0
- package/workspace/public/premium.html +1 -0
- package/workspace/server.js +1 -1
- package/workspace/skills/workflow-setup.skill +57 -0
- package/workspace/test-lists/ini-workflow.json +6 -0
- package/workspace/test-lists/program-charter.json +9 -0
- package/workspace/test-lists/workflows-board.json +13 -0
- package/workspace/test-lists/workflows-setup.json +13 -0
- package/workspace/test-lists/workflows.json +5 -0
- package/workspace/workflows-setup-test.js +346 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-workflows.js — the workflow library (D99, initiative workflows-per-initiative). Writes go through lib/workflows-store.js.
|
|
3
|
+
*
|
|
4
|
+
* GET /api/workflows?ws= → { ok, workflows: [workflow + { count }], cats, ends, outputKinds, whenModes, draft }
|
|
5
|
+
* GET /api/workflows/draft?ws= → { ok, draft: { draft, note, at } | null }
|
|
6
|
+
* POST /api/workflows/save { ws, wf, moveRemoved? } → { ok, workflow, moved } | 409 { ok:false, error, inUse }
|
|
7
|
+
* POST /api/workflows/copy { ws, id, name? } → { ok, workflow }
|
|
8
|
+
* POST /api/workflows/archive { ws, id, archived } → { ok } | 409 { inUse }
|
|
9
|
+
* POST /api/workflows/draft { ws, draft | null, note? } → { ok, draft } (the page relays the chat's draft; the agent writes through `pmos workflow draft`)
|
|
10
|
+
*
|
|
11
|
+
* WHO WRITES. Every POST passes pm-guard requirePagePress and refuses an agent session header (403), as routes-premium-dashboards.js does.
|
|
12
|
+
* The agent drafts and judges through lib/workflow-cli.js, which calls lib/workflows-store.js; only the PM's press saves a workflow.
|
|
13
|
+
* A save that removes a stage moves the initiatives standing in it with one `move` line each in boards.jsonl, on their own board. */
|
|
14
|
+
const guard = require('./pm-guard.js');
|
|
15
|
+
const WS = require('./workflows-store.js');
|
|
16
|
+
const boards = require('./routes-boards.js');
|
|
17
|
+
const { repoScript } = require('./repo-script.js');
|
|
18
|
+
const WF = require(repoScript('workflows.js'));
|
|
19
|
+
|
|
20
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
21
|
+
const bad = (status, error, extra) => ({ status, body: { ok: false, error, ...(extra || {}) } });
|
|
22
|
+
function wsOf(ctx, id) {
|
|
23
|
+
const w = ctx.getWs(id || null);
|
|
24
|
+
return w && (!id || w.id === id) ? w : null;
|
|
25
|
+
}
|
|
26
|
+
const stateOf = (ctx, w) => (ctx.stateDirFor ? ctx.stateDirFor(w) : null);
|
|
27
|
+
|
|
28
|
+
/** Every initiative of the workspace with its board, workflow and stage key: [{ id, title, board, wf, stage }]. null while rows are read. */
|
|
29
|
+
function standingOf(ctx, w) {
|
|
30
|
+
const got = boards.baseRows(w);
|
|
31
|
+
if (!got.ok) return null;
|
|
32
|
+
const fr = boards.frameFor(ctx, w);
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const b of fr.boards) {
|
|
35
|
+
for (const r of got.rows) {
|
|
36
|
+
if (boards.boardIdOf(r, fr.boards, fr.folded, w) !== b.id) continue;
|
|
37
|
+
let row;
|
|
38
|
+
try { row = boards.boardRow(b, r, fr.folded); } catch { continue; }
|
|
39
|
+
out.push({ id: r.id, title: r.title, board: b.id, wf: row.wf.id, stage: row.wfStage.key, ended: !!row.ended });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function handle(req, res, url, ctx) {
|
|
46
|
+
const send = (r) => { ctx.json(res, r.body, r.status || 200); return true; };
|
|
47
|
+
const p = url.pathname;
|
|
48
|
+
if (req.method === 'GET') {
|
|
49
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
50
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
51
|
+
const lib = WS.library(stateOf(ctx, w));
|
|
52
|
+
if (p === '/api/workflows/draft') return send({ body: { ok: true, draft: lib.draft } });
|
|
53
|
+
if (p !== '/api/workflows') return send(bad(404, 'not found'));
|
|
54
|
+
const st = standingOf(ctx, w) || [];
|
|
55
|
+
const counts = {};
|
|
56
|
+
for (const x of st) if (!x.ended) counts[x.wf] = (counts[x.wf] || 0) + 1;
|
|
57
|
+
return send({ body: { ok: true, workflows: WF.list(lib, counts), cats: WF.CATS.map((k) => [k, WF.CAT_LABEL[k]]), ends: WF.ENDS.map((k) => [k, WF.CAT_LABEL[k]]),
|
|
58
|
+
outputKinds: WF.OUTPUT_KINDS, whenModes: WF.WHEN_MODES, draft: lib.draft } });
|
|
59
|
+
}
|
|
60
|
+
if (req.method !== 'POST') return send(bad(405, 'GET or POST only'));
|
|
61
|
+
const read = await ctx.readJson(req);
|
|
62
|
+
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
63
|
+
const body = read.body;
|
|
64
|
+
if (!isObj(body)) return send(bad(400, 'the body must be a JSON object'));
|
|
65
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot save, copy or archive a workflow. It drafts one with `pmos workflow draft`, and the PM presses Create'));
|
|
66
|
+
const g = guard.requirePagePress(req, body);
|
|
67
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
68
|
+
const w = wsOf(ctx, typeof body.ws === 'string' ? body.ws : null);
|
|
69
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
70
|
+
const dir = stateOf(ctx, w);
|
|
71
|
+
|
|
72
|
+
if (p === '/api/workflows/save') {
|
|
73
|
+
const st = standingOf(ctx, w);
|
|
74
|
+
if (!st) return send(bad(202, 'The initiatives are still being read. Try again in a moment.', { pending: true }));
|
|
75
|
+
const id = isObj(body.wf) ? WF.slug(body.wf.id || body.wf.name || '') : '';
|
|
76
|
+
const standing = st.filter((x) => x.wf === id && !x.ended);
|
|
77
|
+
const r = WS.save(dir, { wf: body.wf, moveRemoved: body.moveRemoved }, g.actor, { standing });
|
|
78
|
+
if (!r.ok) return send(bad(r.status || 400, r.error, r.inUse ? { inUse: r.inUse } : null));
|
|
79
|
+
const file = boards.ledgerFile(ctx, w);
|
|
80
|
+
const boardOf = new Map(st.map((x) => [x.id, x.board]));
|
|
81
|
+
for (const m of r.moved) if (file) boards.append(file, g.actor, { kind: 'move', board: boardOf.get(m.id), id: m.id, from: m.from, to: m.to, why: 'stage removed from ' + r.workflow.name, warnings: [] });
|
|
82
|
+
return send({ body: { ok: true, workflow: r.workflow, moved: r.moved, created: r.created } });
|
|
83
|
+
}
|
|
84
|
+
if (p === '/api/workflows/copy') {
|
|
85
|
+
if (typeof body.id !== 'string' || !body.id) return send(bad(400, 'id is required'));
|
|
86
|
+
const r = WS.copy(dir, body.id, body.name, g.actor);
|
|
87
|
+
return send(r.ok ? { body: { ok: true, workflow: r.workflow } } : bad(r.status || 400, r.error));
|
|
88
|
+
}
|
|
89
|
+
if (p === '/api/workflows/archive') {
|
|
90
|
+
if (typeof body.id !== 'string' || !body.id) return send(bad(400, 'id is required'));
|
|
91
|
+
if (typeof body.archived !== 'boolean') return send(bad(400, 'archived is true or false'));
|
|
92
|
+
const st = standingOf(ctx, w);
|
|
93
|
+
if (!st) return send(bad(202, 'The initiatives are still being read. Try again in a moment.', { pending: true }));
|
|
94
|
+
const inUse = st.filter((x) => x.wf === body.id && !x.ended).map((x) => ({ id: x.id, title: x.title, stage: x.stage }));
|
|
95
|
+
const r = WS.archive(dir, body.id, body.archived, g.actor, { inUse });
|
|
96
|
+
return send(r.ok ? { body: { ok: true } } : bad(r.status || 400, r.error, r.inUse ? { inUse: r.inUse } : null));
|
|
97
|
+
}
|
|
98
|
+
if (p === '/api/workflows/draft') {
|
|
99
|
+
const r = WS.saveDraft(dir, { draft: body.draft, note: body.note }, g.actor);
|
|
100
|
+
return send(r.ok ? { body: { ok: true, draft: r.draft } } : bad(r.status || 400, r.error));
|
|
101
|
+
}
|
|
102
|
+
return send(bad(404, 'not found'));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = { prefixes: ['/api/workflows'], handle, standingOf };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* workflow-chat — what the New workflow chat knows (D99, initiative workflows-per-initiative; canvas WfANew, WfADraft).
|
|
3
|
+
* Settings › Workflows opens the normal chat under the key pop:workflow:new-<n> (public/pm/wf-page.js). Every message in that chat reaches
|
|
4
|
+
* the session with this rule first, as lib/program-chat.js does for programs: the chat drafts the workflow with `pmos workflow draft` (the
|
|
5
|
+
* skill workflow-setup), so the page shows it in the Viewer, and the PM presses Create. The chat never saves a workflow itself. */
|
|
6
|
+
|
|
7
|
+
// 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).
|
|
8
|
+
const MARK = '[PMOS workflow]';
|
|
9
|
+
const SAYS = 'The PM says: ';
|
|
10
|
+
const KEY_RE = /^pop:workflow:[A-Za-z0-9._-]{1,60}$/;
|
|
11
|
+
|
|
12
|
+
const isKey = (key) => KEY_RE.test(String(key || ''));
|
|
13
|
+
|
|
14
|
+
const RULE = [
|
|
15
|
+
'The PM is in Settings › Workflows, describing a new workflow: the stages one kind of initiative goes through. Follow the workflow-setup skill (workspace/skills/workflow-setup.skill).',
|
|
16
|
+
'Draft it with `pmos workflow draft --file <json>`: the page shows the draft beside this chat at once. Draft again after each answer or change; the newest draft replaces the one before.',
|
|
17
|
+
'A workflow is ONE numbered list of stages. Triage is always the first stage, in To do. Each stage sits in To do, In progress or Done. Won\'t do and Archived are in every workflow: do not draft them as stages.',
|
|
18
|
+
'Write conditions in the PM\'s plain words ("Only when they touch customer data"), never as a rule or code.',
|
|
19
|
+
'In the chat, say in one line per choice why you drafted it so (quote the PM or the file they added), then ask at most one question when something is unclear.',
|
|
20
|
+
'You never save, copy or archive a workflow: the PM presses Create workflow. Never write a .jsonl file by hand.',
|
|
21
|
+
].join('\n');
|
|
22
|
+
|
|
23
|
+
/** The message as PMOS types it into the session: the rule, then the PM's words. */
|
|
24
|
+
function wrap(text) { return MARK + ' ' + RULE + '\n\n' + SAYS + String(text == null ? '' : text); }
|
|
25
|
+
|
|
26
|
+
module.exports = { MARK, KEY_RE, isKey, wrap, RULE };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* workflow-cli.js — `pmos workflow …`: what an agent writes about workflows (D99, initiative workflows-per-initiative; canvas WfADraft, WfACond).
|
|
3
|
+
*
|
|
4
|
+
* pmos workflow list the workflows of this repository, Product feature first: id, name, stages
|
|
5
|
+
* pmos workflow show <id> one workflow's stages, numbered, with their category, output and when they run
|
|
6
|
+
* pmos workflow draft --file <path|-> [--note <text>]
|
|
7
|
+
* writes THE draft the New workflow chat shows in the Viewer (one wf-draft line). The JSON is one workflow { name, icon?, decide?,
|
|
8
|
+
* stages: [...] }, checked as a save is, so the page never shows a draft that Create would refuse. A new draft replaces the one before.
|
|
9
|
+
* pmos workflow show-draft the draft now open, as JSON
|
|
10
|
+
* pmos workflow judge --board <id> --id <initiative> --stage <key> --runs yes|no|unsure --why <reason> [--cite <where>]
|
|
11
|
+
* pmos workflow judge --board <id> --id <initiative> --stage <key> --undo
|
|
12
|
+
* records PMOS's reading of an Only-when stage (one stage-judge line in boards.jsonl): yes runs it, no skips it, unsure asks the PM.
|
|
13
|
+
*
|
|
14
|
+
* WHO WRITES. These write through lib/workflows-store.js, never over HTTP. An agent may draft and judge; it never saves, copies or archives a
|
|
15
|
+
* workflow: Create, Copy and Archive are the PM's presses on the Workflows page. Who wrote a line is the call path (lib/actor.js), never an
|
|
16
|
+
* argument. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const { execFileSync } = require('child_process');
|
|
20
|
+
const actorLib = require('./actor.js');
|
|
21
|
+
const driver = require('./driver.js');
|
|
22
|
+
const WS = require('./workflows-store.js');
|
|
23
|
+
const { repoScript } = require('./repo-script.js');
|
|
24
|
+
const WF = require(repoScript('workflows.js'));
|
|
25
|
+
|
|
26
|
+
const COMMANDS = { workflow: ['list', 'show', 'draft', 'show-draft', 'judge'] };
|
|
27
|
+
const USAGE = [
|
|
28
|
+
'usage: pmos workflow list|show|draft|show-draft|judge — the workflows each kind of initiative goes through (D99)',
|
|
29
|
+
' pmos workflow list the workflows of this repository',
|
|
30
|
+
' pmos workflow show <id> one workflow, its stages numbered',
|
|
31
|
+
' pmos workflow draft --file <path|-> [--note <text>]',
|
|
32
|
+
' Write the draft the New workflow chat shows beside it. The PM presses Create workflow; you never save one.',
|
|
33
|
+
' pmos workflow show-draft the draft now open',
|
|
34
|
+
' pmos workflow judge --board <id> --id <initiative> --stage <key> --runs yes|no|unsure --why <reason> [--cite <where>]',
|
|
35
|
+
' pmos workflow judge --board <id> --id <initiative> --stage <key> --undo',
|
|
36
|
+
' Record PMOS\'s reading of an Only-when stage: yes runs it, no skips it, unsure asks the PM. Give the reason and where you read it.',
|
|
37
|
+
' every command: [--json] [--root <dir>]. Nothing is sent.',
|
|
38
|
+
];
|
|
39
|
+
const BOOL = new Set(['json', 'help', 'undo']);
|
|
40
|
+
const VALUE = new Set(['file', 'note', 'board', 'id', 'stage', 'runs', 'why', 'cite', 'root']);
|
|
41
|
+
const RUNS = { yes: true, no: false, unsure: null };
|
|
42
|
+
|
|
43
|
+
function parse(argv) {
|
|
44
|
+
const pos = []; const flags = {};
|
|
45
|
+
for (let i = 0; i < argv.length; i++) {
|
|
46
|
+
const a = argv[i];
|
|
47
|
+
if (a === '-h') { flags.help = true; continue; }
|
|
48
|
+
if (a === '-' || !a.startsWith('--')) { pos.push(a); continue; }
|
|
49
|
+
const eq = a.indexOf('=');
|
|
50
|
+
const key = eq > 0 ? a.slice(2, eq) : a.slice(2);
|
|
51
|
+
if (BOOL.has(key)) { flags[key] = true; continue; }
|
|
52
|
+
let val;
|
|
53
|
+
if (eq > 0) val = a.slice(eq + 1);
|
|
54
|
+
else { const next = argv[i + 1]; if (next === undefined || (next.startsWith('--') && next.length > 2)) val = ''; else { val = next; i++; } }
|
|
55
|
+
flags[key] = val;
|
|
56
|
+
}
|
|
57
|
+
return { pos, flags };
|
|
58
|
+
}
|
|
59
|
+
function repoRoot(cwd) {
|
|
60
|
+
try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
|
|
61
|
+
catch { return cwd; }
|
|
62
|
+
}
|
|
63
|
+
function readStdin(stdin) {
|
|
64
|
+
if (typeof stdin === 'string') return stdin;
|
|
65
|
+
try { return fs.readFileSync(0, 'utf8'); } catch { return ''; }
|
|
66
|
+
}
|
|
67
|
+
const WHEN_WORDS = (s) => (s.when && s.when.mode === 'only' ? 'only when ' + s.when.text : s.when && s.when.mode === 'optional' ? 'optional' : 'always');
|
|
68
|
+
const stageLine = (s, i) => `${String(i + 1).padStart(2)}. ${s.milestone ? '◆ ' : ''}${s.name} [${s.key}] · ${WF.CAT_LABEL[s.cat]} · ${s.output && s.output.name ? s.output.name + ' (' + s.output.kind + ')' : s.output.kind} · ${WHEN_WORDS(s)}`;
|
|
69
|
+
|
|
70
|
+
async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isTTY, env, stdin } = {}) {
|
|
71
|
+
const args = argv[0] === 'workflow' ? argv.slice(1) : argv.slice();
|
|
72
|
+
const verb = args[0];
|
|
73
|
+
const { pos, flags } = parse(args.slice(1));
|
|
74
|
+
const json = !!flags.json;
|
|
75
|
+
if (!verb || verb === 'help' || verb === '--help' || verb === '-h' || flags.help) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
|
|
76
|
+
if (!COMMANDS.workflow.includes(verb)) { say(`unknown workflow command "${verb}" — one of ${COMMANDS.workflow.join(', ')}`); return 2; }
|
|
77
|
+
if ('by' in flags || 'via' in flags) { say(`attribution is set from the call path; --${'by' in flags ? 'by' : 'via'} is not accepted`); return 2; }
|
|
78
|
+
for (const k of Object.keys(flags)) {
|
|
79
|
+
if (!BOOL.has(k) && !VALUE.has(k)) { say(`unknown option --${k}`); return 2; }
|
|
80
|
+
if (VALUE.has(k) && flags[k] === '' && k !== 'note') { say(`--${k} needs a value`); return 2; }
|
|
81
|
+
}
|
|
82
|
+
const fail = (error, code = 1) => { if (json) say(JSON.stringify({ ok: false, error })); else say(`✗ ${error}`); return code; };
|
|
83
|
+
const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
|
|
84
|
+
const stateDir = driver.stateDirOf(root, { create: verb === 'draft' || verb === 'judge' });
|
|
85
|
+
if (!stateDir) return fail('this repository has no PMOS state folder (pmos/state, state or .pmos)');
|
|
86
|
+
const e = env === undefined ? process.env : env;
|
|
87
|
+
const actor = actorLib.fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env: e });
|
|
88
|
+
|
|
89
|
+
if (verb === 'list') {
|
|
90
|
+
const all = WF.list(WS.library(stateDir));
|
|
91
|
+
if (json) { say(JSON.stringify({ ok: true, workflows: all.map((w) => ({ id: w.id, name: w.name, stages: w.stages.length, archived: !!w.archived })) })); return 0; }
|
|
92
|
+
for (const w of all) say(`${w.id} · ${w.name} · ${w.stages.length} stage${w.stages.length === 1 ? '' : 's'}${w.archived ? ' · archived' : ''}`);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
if (verb === 'show') {
|
|
96
|
+
const id = pos[0]; if (!id) { say('usage: pmos workflow show <id>'); return 2; }
|
|
97
|
+
const w = WS.library(stateDir).byId.get(id);
|
|
98
|
+
if (!w) return fail(`no workflow ${id} — pmos workflow list names them`);
|
|
99
|
+
if (json) { say(JSON.stringify({ ok: true, workflow: w })); return 0; }
|
|
100
|
+
say(`${w.name} (${w.id}) · ${w.decide === 'confirm' ? 'PMOS suggests, the PM confirms' : 'PMOS decides and tells why'}`);
|
|
101
|
+
w.stages.forEach((s, i) => say(stageLine(s, i)));
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
if (verb === 'show-draft') {
|
|
105
|
+
const d = WS.readDraft(stateDir);
|
|
106
|
+
if (json) { say(JSON.stringify({ ok: true, draft: d })); return 0; }
|
|
107
|
+
if (!d || !d.draft) { say('No draft is open.'); return 0; }
|
|
108
|
+
say(`${d.draft.name} · draft${d.at ? ' of ' + d.at : ''}`);
|
|
109
|
+
d.draft.stages.forEach((s, i) => say(stageLine(s, i)));
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
if (verb === 'draft') {
|
|
113
|
+
if (!flags.file) { say('usage: pmos workflow draft --file <path|-> [--note <text>]'); return 2; }
|
|
114
|
+
let text;
|
|
115
|
+
if (flags.file === '-') text = readStdin(stdin);
|
|
116
|
+
else { try { text = fs.readFileSync(path.resolve(cwd, flags.file), 'utf8'); } catch (err) { return fail(`cannot read ${flags.file}: ${String(err.code || err.message)}`, 2); } }
|
|
117
|
+
let draft;
|
|
118
|
+
try { draft = JSON.parse(text); } catch (err) { return fail(`the file is not JSON: ${String(err.message).slice(0, 120)}`, 2); }
|
|
119
|
+
if (draft && draft.wf && !draft.stages) draft = draft.wf; // { wf: {...} } reads as the workflow
|
|
120
|
+
const r = WS.saveDraft(stateDir, { draft, note: flags.note || '' }, actor);
|
|
121
|
+
if (!r.ok) return fail(r.error);
|
|
122
|
+
if (json) say(JSON.stringify({ ok: true, draft: r.draft }));
|
|
123
|
+
else say(`✓ drafted ${r.draft.name} with ${r.draft.stages.length} stages. The Workflows page shows it beside the chat; the PM presses Create workflow. Nothing was sent.`);
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
// judge
|
|
127
|
+
if (!flags.board || !flags.id || !flags.stage) { say('usage: pmos workflow judge --board <id> --id <initiative> --stage <key> --runs yes|no|unsure --why <reason> [--cite <where>]'); return 2; }
|
|
128
|
+
let r;
|
|
129
|
+
if (flags.undo) r = WS.judge(stateDir, { board: flags.board, id: flags.id, stage: flags.stage, undo: true }, actor);
|
|
130
|
+
else {
|
|
131
|
+
if (!Object.prototype.hasOwnProperty.call(RUNS, String(flags.runs || ''))) { say('--runs is yes, no or unsure'); return 2; }
|
|
132
|
+
r = WS.judge(stateDir, { board: flags.board, id: flags.id, stage: flags.stage, runs: RUNS[flags.runs], why: flags.why, cite: flags.cite }, actor);
|
|
133
|
+
}
|
|
134
|
+
if (!r.ok) return fail(r.error);
|
|
135
|
+
const said = flags.undo ? 'undid the reading of' : flags.runs === 'yes' ? 'runs' : flags.runs === 'no' ? 'skips' : 'asks the PM about';
|
|
136
|
+
if (json) say(JSON.stringify({ ok: true }));
|
|
137
|
+
else say(`✓ ${flags.id} ${said} ${flags.stage}. The stage card shows the reason. Nothing was sent.`);
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* workflows-store.js — the one writer of workflows.jsonl and of the agent's workflow lines in boards.jsonl (D99, initiative workflows-per-initiative).
|
|
3
|
+
*
|
|
4
|
+
* library(stateDir) → the folded library (scripts/workflows.js fold)
|
|
5
|
+
* save(stateDir, { wf, moveRemoved }, actor, { standing }) → { ok, workflow, moved } | { ok:false, status, error, inUse? }
|
|
6
|
+
* copy(stateDir, id, name, actor) → { ok, workflow }
|
|
7
|
+
* archive(stateDir, id, archived, actor, { inUse }) → { ok }
|
|
8
|
+
* saveDraft(stateDir, { draft, note }, actor) → { ok, draft } (the chat's draft; null clears it)
|
|
9
|
+
* readDraft(stateDir) → { draft, note, at } | null
|
|
10
|
+
* judge(stateDir, { board, id, stage, runs, why, cite, undo }, actor) → { ok } one stage-judge line in boards.jsonl
|
|
11
|
+
*
|
|
12
|
+
* WHO CALLS. lib/routes-workflows.js (page presses: save, copy, archive, draft) and lib/workflow-cli.js (`pmos workflow …`, an agent: draft and
|
|
13
|
+
* judge only). A caller passes the actor ({ by }); the writer never decides who the caller is. Lines are appended, never rewritten. */
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const { repoScript } = require('./repo-script.js');
|
|
17
|
+
const W = require(repoScript('workflows.js'));
|
|
18
|
+
|
|
19
|
+
const FILE = 'workflows.jsonl';
|
|
20
|
+
const BOARDS = 'boards.jsonl';
|
|
21
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
22
|
+
const oneLine = (v, max) => typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= max && !/[\r\n\x00-\x08\x0b-\x1f]/.test(v);
|
|
23
|
+
|
|
24
|
+
const fileOf = (stateDir) => (stateDir ? path.join(stateDir, FILE) : null);
|
|
25
|
+
function lines(file) { try { return fs.readFileSync(file, 'utf8').split('\n').filter(Boolean); } catch { return []; } }
|
|
26
|
+
function append(file, actor, ev) {
|
|
27
|
+
const line = { at: new Date().toISOString(), by: (actor && actor.by) || 'unknown', ...ev };
|
|
28
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
29
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
30
|
+
return line;
|
|
31
|
+
}
|
|
32
|
+
const NO_STATE = 'This workspace has no state folder yet, so a workflow cannot be saved here.';
|
|
33
|
+
|
|
34
|
+
const library = (stateDir) => W.fold(stateDir ? lines(fileOf(stateDir)) : []);
|
|
35
|
+
|
|
36
|
+
/** Create or edit. standing: [{ id, title, stage }] the initiatives on this workflow now (stage = key), so a removal can ask where they go. */
|
|
37
|
+
function save(stateDir, { wf, moveRemoved } = {}, actor, { standing = [] } = {}) {
|
|
38
|
+
if (!stateDir) return { ok: false, status: 409, error: NO_STATE };
|
|
39
|
+
const c = W.check(wf);
|
|
40
|
+
if (!c.ok) return c;
|
|
41
|
+
const lib = library(stateDir);
|
|
42
|
+
const before = lib.byId.get(c.workflow.id) || null;
|
|
43
|
+
let moved = [];
|
|
44
|
+
if (before) {
|
|
45
|
+
const gone = W.removedInUse(before, c.workflow, standing);
|
|
46
|
+
const mr = isObj(moveRemoved) ? moveRemoved : {};
|
|
47
|
+
const missing = gone.filter((x) => !(typeof mr[x.stage] === 'string' && W.stageByRef(c.workflow, mr[x.stage])));
|
|
48
|
+
if (missing.length) {
|
|
49
|
+
const title = new Map(standing.map((x) => [x.id, x.title]));
|
|
50
|
+
return { ok: false, status: 409, error: `${missing.length === 1 ? 'An initiative stands' : missing.length + ' initiatives stand'} in a stage this change removes. Say where ${missing.length === 1 ? 'it moves' : 'they move'} (moveRemoved).`,
|
|
51
|
+
inUse: missing.map((x) => ({ id: x.id, title: title.get(x.id) || x.id, stage: x.stage })) };
|
|
52
|
+
}
|
|
53
|
+
moved = gone.map((x) => ({ id: x.id, from: x.stage, to: W.stageByRef(c.workflow, mr[x.stage]).key }));
|
|
54
|
+
}
|
|
55
|
+
append(fileOf(stateDir), actor, { kind: 'wf-save', wf: c.workflow, ...(moved.length ? { moved } : {}) });
|
|
56
|
+
// Create clears the chat's draft of the same workflow
|
|
57
|
+
const d = lib.draft;
|
|
58
|
+
if (d && d.draft && (W.slug(d.draft.id || d.draft.name) === c.workflow.id)) append(fileOf(stateDir), actor, { kind: 'wf-draft', draft: null });
|
|
59
|
+
return { ok: true, workflow: c.workflow, moved, created: !before };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function copy(stateDir, id, name, actor) {
|
|
63
|
+
if (!stateDir) return { ok: false, status: 409, error: NO_STATE };
|
|
64
|
+
const lib = library(stateDir);
|
|
65
|
+
const src = lib.byId.get(id);
|
|
66
|
+
if (!src) return { ok: false, status: 404, error: `no workflow ${id}` };
|
|
67
|
+
const wf = W.copyOf(src, name, new Set(lib.byId.keys()));
|
|
68
|
+
const c = W.check(wf);
|
|
69
|
+
if (!c.ok) return c;
|
|
70
|
+
append(fileOf(stateDir), actor, { kind: 'wf-save', wf: c.workflow, copiedFrom: id });
|
|
71
|
+
return { ok: true, workflow: c.workflow };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function archive(stateDir, id, archived, actor, { inUse = [] } = {}) {
|
|
75
|
+
if (!stateDir) return { ok: false, status: 409, error: NO_STATE };
|
|
76
|
+
if (id === W.PRODUCT_FEATURE_ID) return { ok: false, status: 409, error: 'Product feature is built in and stays.' };
|
|
77
|
+
const lib = library(stateDir);
|
|
78
|
+
if (!lib.byId.has(id)) return { ok: false, status: 404, error: `no workflow ${id}` };
|
|
79
|
+
if (archived && inUse.length) return { ok: false, status: 409, error: `${inUse.length} ${inUse.length === 1 ? 'initiative runs' : 'initiatives run'} this workflow. Move ${inUse.length === 1 ? 'it' : 'them'} to another workflow first.`, inUse };
|
|
80
|
+
append(fileOf(stateDir), actor, { kind: 'wf-archive', id, archived: !!archived });
|
|
81
|
+
return { ok: true };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The chat's draft. It is checked like a save (so the Viewer never shows a draft Create would refuse); null clears it. */
|
|
85
|
+
function saveDraft(stateDir, { draft, note } = {}, actor) {
|
|
86
|
+
if (!stateDir) return { ok: false, status: 409, error: NO_STATE };
|
|
87
|
+
if (draft === null) { append(fileOf(stateDir), actor, { kind: 'wf-draft', draft: null }); return { ok: true, draft: null }; }
|
|
88
|
+
const c = W.check(draft);
|
|
89
|
+
if (!c.ok) return c;
|
|
90
|
+
if (note != null && note !== '' && (typeof note !== 'string' || note.length > 4000)) return { ok: false, status: 400, error: 'note is text of at most 4000 characters' };
|
|
91
|
+
append(fileOf(stateDir), actor, { kind: 'wf-draft', draft: c.workflow, note: note || '' });
|
|
92
|
+
return { ok: true, draft: c.workflow };
|
|
93
|
+
}
|
|
94
|
+
const readDraft = (stateDir) => library(stateDir).draft;
|
|
95
|
+
|
|
96
|
+
/** The agent's reading of an Only-when stage (runs true, false, or null = not sure, ask the PM), or undo. One line in boards.jsonl. */
|
|
97
|
+
function judge(stateDir, { board, id, stage, runs, why, cite, undo } = {}, actor) {
|
|
98
|
+
if (!stateDir) return { ok: false, status: 409, error: NO_STATE };
|
|
99
|
+
if (!oneLine(board, 80) || !oneLine(id, 120) || !oneLine(stage, 60)) return { ok: false, status: 400, error: 'board, id and stage are required' };
|
|
100
|
+
if (undo === true) { append(path.join(stateDir, BOARDS), actor, { kind: 'stage-judge', board, id, stage, undo: true }); return { ok: true }; }
|
|
101
|
+
if (!(runs === true || runs === false || runs === null)) return { ok: false, status: 400, error: 'runs is true, false or null (not sure)' };
|
|
102
|
+
if (!oneLine(why, 500)) return { ok: false, status: 400, error: 'a reading needs its reason (why), one line of at most 500 characters' };
|
|
103
|
+
if (cite != null && cite !== '' && !oneLine(cite, 200)) return { ok: false, status: 400, error: 'cite is one line of at most 200 characters' };
|
|
104
|
+
append(path.join(stateDir, BOARDS), actor, { kind: 'stage-judge', board, id, stage, runs, why: why.trim(), ...(cite ? { cite: cite.trim() } : {}) });
|
|
105
|
+
return { ok: true };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = { FILE, library, save, copy, archive, saveDraft, readDraft, judge, fileOf };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.410.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.410.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED