create-pmos 0.267.0 → 0.268.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 +1 -1
- 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/briefing-premium-board-test.js +1 -1
- package/workspace/briefing-premium-initiative-test.js +1 -1
- package/workspace/guide/briefing-premium.md +2 -2
- package/workspace/lib/board-premium.js +1 -1
- package/workspace/lib/initiative-premium.js +1 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-core-doc-issue-test.js +173 -0
- package/workspace/public/pm/premium-board.js +64 -4
- package/workspace/public/pm/premium-doc-edit.js +30 -0
- package/workspace/public/pm/premium-initiative.js +20 -22
- package/workspace/public/pm/premium.css +8 -0
- package/workspace/test-lists/premium-core-doc-issue.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.268.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-18T11:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-18T11:47:32Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-18T11:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-18T11:47:32Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-18T11:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-18T11:47:32Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -125,7 +125,7 @@ const MOCKUP = path.join(__dirname, '..', 'prototype', 'premium-ux-concept', 'br
|
|
|
125
125
|
const docs = await p.evaluate(() => ({ cap: document.querySelector('#docCap').textContent, rows: [...document.querySelectorAll('#docBody .dmr')].map((r) => ({ t: r.querySelector('.dmn b').textContent, s: r.querySelector('.dmm .s').textContent.trim(), b: r.querySelector('.dmcta') ? r.querySelector('.dmcta').textContent.trim() : null, dis: r.querySelector('.dmcta') ? r.querySelector('.dmcta').disabled : null, kind: r.querySelector('.dmcta') ? (r.querySelector('.dmcta').dataset.draft ? 'draft' : 'go') : null })), all: document.querySelector('#cDocs').textContent }));
|
|
126
126
|
ok('B7 the documents come from the record with their state, and the summary counts them', docs.cap === '6' && docs.rows.length === 6 && docs.rows[0].t === 'Board charter' && docs.rows[0].s === 'Not started' && docs.rows[1].s === 'Live' && docs.rows[3].s === 'Draft' && docs.rows[4].s === 'Stale', JSON.stringify(docs));
|
|
127
127
|
ok('B7 the button is the record\'s own action: Draft it, Set it up, Open; a draft to review and a document with no action have none; a running one is off', docs.rows[0].b === 'Draft it' && docs.rows[0].kind === 'draft' && docs.rows[2].b === 'Set it up' && docs.rows[2].kind === 'go' && docs.rows[1].b === 'Open' && docs.rows[3].b === null && docs.rows[5].b === 'Drafting' && docs.rows[5].dis === true, JSON.stringify(docs.rows));
|
|
128
|
-
ok('B7
|
|
128
|
+
ok('B7 Drop is not on the page, and the list has no Issue it press (it is in a draft\'s reader)', !/\bDrop\b/.test(docs.all) && await p.evaluate(() => !document.querySelector('#docBody [data-rd="issue"], #docBody button.dmcta')?.textContent.includes('Issue it')));
|
|
129
129
|
A.set({ status: 200, body: { ok: true, run: 'r1' } });
|
|
130
130
|
const g0 = A.calls();
|
|
131
131
|
await p.locator('#docBody [data-draft="charter"]').click();
|
|
@@ -169,7 +169,7 @@ const HEALTH = { ok: true, path: 'planning/prd/self-serve-v2-prd.md', health: {
|
|
|
169
169
|
A.set({ status: 409, body: { ok: false, error: 'a run is already drafting that document' } });
|
|
170
170
|
await p.locator('#dmList [data-draft="problem"]').click();
|
|
171
171
|
ok('I10 a refused press shows the route\'s reason and turns the button back on', await until(() => p.evaluate(() => /already drafting/.test(document.querySelector('#toast').textContent) && !document.querySelector('#dmList [data-draft="problem"]').disabled)));
|
|
172
|
-
ok('I10
|
|
172
|
+
ok('I10 Drop, Accept and editing are not on the page, and no Issue it press is in the list (it is on a draft\'s sheet)', !/\b(Drop|Accept|Edit)\b/.test(await txt('#iMain')) && await p.evaluate(() => ![...document.querySelectorAll('#iMain button')].some((b) => /Issue it/.test(b.textContent))));
|
|
173
173
|
ok('I7 a running document shows Drafting and is off', await p.evaluate(() => { const b = document.querySelector('#dmList [data-draft="launch"]'); return !!b && b.disabled && /Drafting/.test(b.textContent); }));
|
|
174
174
|
|
|
175
175
|
/* the batch press: one existing draft run for each document not started */
|
|
@@ -162,7 +162,7 @@ Board is the third place on the rail, at `/premium-board.html`. It reads what th
|
|
|
162
162
|
- **Sprint** appears when an agent session has read Jira for the board. Otherwise it says there is none. **Coming up** shows the next release, from the releases ledger.
|
|
163
163
|
- **Metrics** appears above the Initiatives card on the board of any workspace except the home one (PMOS itself), and counts from that workspace's own repository. It has four tiles. **Corrections per 100 runs** is the corrections logged on the week's runs in `planning/runs/agent-runs.jsonl`; a week with fewer than 10 runs is left blank. **Merged a week** counts the commits on the first-parent line of the trunk. **Blocked** and **Idle for a month** come from the workflow engine and keep no history, so they have no chart. Move over a chart, or use the arrow keys, to read a week. A tile that cannot be counted says **Not read** and why. Press a tile for its definition and values, with the read-only agent beside it. There are no targets, and Day and Month are off. It was tested only on made-up repositories, not on a real IDPF or microsite repository.
|
|
164
164
|
- **The crumb** at the top names the board. With more than one board a menu switches between them, and the sparkle opens the board in the dialog with the read-only agent.
|
|
165
|
-
- **Core documents** lists the board's documents with their state, cadence and writer, a summary (drafts to review, not started, up to date), a progress bar, a filter and a search. **Draft it** starts the existing read-only run that writes a draft and sends nothing; **Draft the N not started** does that for each document that can be drafted. **Set it up** and **Open** go to the console. **Add a document** opens a form (title, who writes it, where it lives) and saves a document the core set does not cover on the board's record, in `custom-docs.jsonl`. A document with no link reads "Not started". A document with a link to Confluence or Google Docs reads "Linked" and shows its address. PMOS does not read or sync the linked page, so a linked document is never counted as up to date. Issue and Drop are not on this page.
|
|
165
|
+
- **Core documents** lists the board's documents with their state, cadence and writer, a summary (drafts to review, not started, up to date), a progress bar, a filter and a search. A document with a file opens in the dialog, read only, with its path and state; a draft there has **Issue it**, which marks it issued through the console's own route and sends nothing, and **Draft it again**, which starts a new draft that replaces this one (a board draft has no Edit tab). **Draft it** starts the existing read-only run that writes a draft and sends nothing; **Draft the N not started** does that for each document that can be drafted. **Set it up** and **Open** go to the console. **Add a document** opens a form (title, who writes it, where it lives) and saves a document the core set does not cover on the board's record, in `custom-docs.jsonl`. A document with no link reads "Not started". A document with a link to Confluence or Google Docs reads "Linked" and shows its address. PMOS does not read or sync the linked page, so a linked document is never counted as up to date. Issue and Drop are not on this page.
|
|
166
166
|
- **Opening an initiative.** A click on an initiative opens its page (see "Initiative page"). The **Page / Popup** switch in the header changes that: Popup opens the initiative's dialog instead, which shows its record as a grid and the path of its file, with the read-only agent beside it. The choice is kept in this browser. The dialog holds no press.
|
|
167
167
|
- **New asks** sits at the top of the right column on a team board. Each ask shows where it came from and the drafted title, lane and anchor. **Accept** makes it an initiative in the first stage, through the console's accept route; **Decline** asks for a reason first. The card says when nothing is left to triage.
|
|
168
168
|
- **New initiative** (beside the Initiatives heading, team boards only) asks for a title, a lane and an anchor (a KR or a health budget). It writes an ask and accepts it, as the console does. An unanchored initiative is refused on the page.
|
|
@@ -182,7 +182,7 @@ The initiative page is at `/premium-initiative.html?id=<initiative>`. A click on
|
|
|
182
182
|
- **Checks** lists the engine's six steps (spec, contract, build, quality, review, accept) with their state and the evidence each states, and marks the next one. "All N workflow steps" lists every step.
|
|
183
183
|
- **Tasks** lists the PRD requirements and the board's tracker items for this initiative. The repository records no result for each requirement, so a requirement says "No result" and is never drawn as done or open. **By stage** groups them by state. **Timeline** draws a bar for each task that has both a start and a due date, and lists the rest. Press a task to read its record; for a PMOS task you can change its status. **Add a task** writes a PMOS task to the board's own record; with no dates the board plans it from tomorrow for a week. Jira tickets stay read-only. **Add a document** works as on the Board, with a phase as well, and saves on the initiative's record.
|
|
184
184
|
- **Core documents** has the same counts, filter and search as the Board's card, for this initiative. **Draft it** starts the existing read-only run that writes a draft and sends nothing. Technical documents (the record, the rubric, the stories, the review and the explainer) are grouped and not counted.
|
|
185
|
-
- **The document sheet.** A document that has a file opens in a dialog with **Read** (the file's text, its front matter as a grid and an outline), **Edit** (the file as plain Markdown, a reason, and **Save**), **Proposals** (**Ask the agent**, the open proposals with **Accept** and **Reject**, and the closed ones), **Edit log** (the revisions and other entries of the document sheet) and **Health** (the document-health checks; a check with no input is not counted). The file changes only when you press Save or Accept, and every change is kept in the Edit log with its reason. Save and Reject need a reason. A proposal made on text that has since changed shows which sections are out of date and cannot take them. The agent beside the sheet still only reads. Bold and undo buttons
|
|
185
|
+
- **The document sheet.** A document that has a file opens in a dialog with **Read** (the file's text, its front matter as a grid and an outline), **Edit** (the file as plain Markdown, a reason, and **Save**), **Proposals** (**Ask the agent**, the open proposals with **Accept** and **Reject**, and the closed ones), **Edit log** (the revisions and other entries of the document sheet) and **Health** (the document-health checks; a check with no input is not counted). The file changes only when you press Save or Accept, and every change is kept in the Edit log with its reason. Save and Reject need a reason. A proposal made on text that has since changed shows which sections are out of date and cannot take them. The agent beside the sheet still only reads. A draft shows a bar above its text: **Issue it** marks the draft issued, through the console's own route, and sends nothing; it refuses while the Edit tab holds unsaved changes. Bold and undo buttons and Drop are not built on this page.
|
|
186
186
|
|
|
187
187
|
Not drawn, because PMOS holds no record for them: the mockup's demo tasks, its Jira data, and the owner "Agents" on a requirement.
|
|
188
188
|
|
|
@@ -131,7 +131,7 @@ function build(f) {
|
|
|
131
131
|
cap: dd.summary ? [(dd.summary.missing + nCustomNone) ? (dd.summary.missing + nCustomNone) + ' not started' : null, dd.summary.draft ? dd.summary.draft + ' ' + plural(dd.summary.draft, 'draft', 'drafts') : null, dd.summary.stale ? dd.summary.stale + ' stale' : null, dd.summary.due ? dd.summary.due + ' due' : null].concat(nLinked ? [nLinked + ' linked'] : []).filter(Boolean).join(' · ') || 'all up to date' : '',
|
|
132
132
|
scope: dd.scope || null,
|
|
133
133
|
counts: null,
|
|
134
|
-
rows: (dd.docs || []).map((d) => ({ key: d.key, title: d.title, what: d.for || '', state: d.kind === 'live' ? 'Live' : DOC_STATE[d.st] || d.st || '', st: d.st, cadence: d.cadence || '', by: BY[d.by] || d.by || '', running: !!d.running,
|
|
134
|
+
rows: (dd.docs || []).map((d) => ({ key: d.key, title: d.title, what: d.for || '', state: d.kind === 'live' ? 'Live' : DOC_STATE[d.st] || d.st || '', st: d.st, cadence: d.cadence || '', by: BY[d.by] || d.by || '', running: !!d.running, when: d.when ? shortDate(d.when) : '', path: d.open && d.open.path ? d.open.path : null, slot: d.st === 'draft' && d.draft && d.draft.slot ? d.draft.slot : '',
|
|
135
135
|
act: d.act && d.act.do === 'draft' ? { kind: 'draft', label: d.running ? 'Drafting' : d.act.label || 'Draft it' } : d.act && d.act.go ? { kind: 'go', label: d.act.label || 'Open', tab: GO[d.act.go] || 'init' } : d.open && d.open.tab ? { kind: 'go', label: 'Open', tab: GO[d.open.tab] || 'init' } : null })).concat(custom),
|
|
136
136
|
} : { cap: '', rows: custom, missing: true, scope: board.id ? 'board:' + board.id : null };
|
|
137
137
|
docs.counts = dd || custom.length ? { all: docs.rows.length, none: docs.rows.filter((d) => d.st === 'missing').length, draft: docs.rows.filter((d) => d.st === 'draft').length, ok: docs.rows.filter((d) => d.st === 'ok').length } : { all: 0, none: 0, draft: 0, ok: 0 };
|
|
@@ -103,7 +103,7 @@ function build(f) {
|
|
|
103
103
|
const dd = f.docs || null;
|
|
104
104
|
const all = dd ? (dd.docs || []).map((d) => ({
|
|
105
105
|
key: d.key, title: d.title, what: d.for || '', st: d.st, state: d.kind === 'live' ? 'Live' : DOC_STATE[d.st] || d.st || '', by: BY[d.by] || d.by || '', byKey: d.by || '',
|
|
106
|
-
when: d.when ? shortDate(d.when) : '', cat: d.cat === 'Do' ? 'Build' : d.cat === 'Learn' ? 'Evaluate' : d.cat || 'Board', path: d.open && d.open.path ? d.open.path : null, running: !!d.running, tech: TECH.has(d.key),
|
|
106
|
+
when: d.when ? shortDate(d.when) : '', cat: d.cat === 'Do' ? 'Build' : d.cat === 'Learn' ? 'Evaluate' : d.cat || 'Board', path: d.open && d.open.path ? d.open.path : null, slot: d.st === 'draft' && d.draft && d.draft.slot ? d.draft.slot : '', running: !!d.running, tech: TECH.has(d.key),
|
|
107
107
|
act: d.act && d.act.do === 'draft' ? { kind: 'draft', label: d.running ? 'Drafting' : d.act.label || 'Draft it' } : null,
|
|
108
108
|
})) : [];
|
|
109
109
|
const custom = (f.custom || []).map((d) => Object.assign(Custom.rowOf(d), { added: shortDate(d.at), cat: d.phase || 'Board' }));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.268.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.268.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* premium-core-doc-issue-test.js — Issue it on a core document draft, on the premium Board and the premium initiative page (initiative premium-core-doc-issue;
|
|
4
|
+
* planning/prd/premium-core-doc-issue-prd.md I1 to I7). A real server on a scratch `team` repository, never the PMOS checkout. The drafts are written by the
|
|
5
|
+
* core-docs writer (lib/core-docs.js writeDraft), so the pages read what the agent's run would leave. The real pages press the real route:
|
|
6
|
+
* R reading (slot and path) · B the Board reader and Issue it · I the initiative sheet, unsaved edits and a refusal · P the POST allow-list · F floors */
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { spawn } = require('child_process');
|
|
10
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
11
|
+
const T = require('./test-run').configure({ name: 'premium-core-doc-issue' });
|
|
12
|
+
const { makeRepos, codeRepo, write, git } = require('./plan-test-repos');
|
|
13
|
+
const CD = require('./lib/core-docs.js');
|
|
14
|
+
|
|
15
|
+
const BASE = T.BASE;
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
const until = async (fn, ms = 20000, step = 150) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
18
|
+
const results = [];
|
|
19
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 500) : ''}`); };
|
|
20
|
+
const R = makeRepos('premium-core-doc-issue');
|
|
21
|
+
const team = codeRepo(path.join(R.base, 'team'));
|
|
22
|
+
fs.mkdirSync(path.join(team, 'pmos', 'state'), { recursive: true });
|
|
23
|
+
write(team, 'planning/initiatives/pa-one.md', '---\ntype: Initiative\ntitle: Partner rate limits\ntimestamp: 2026-10-01\nid: pa-one\nlane: chore\nparent_kr: health:tech\nspecimen_test: "description-judgeable — x"\nsurface_check: "greenfield — x"\n---\n\nbody\n');
|
|
24
|
+
git(team, ['add', '-A']); git(team, ['commit', '-q', '-m', 'pa-one']);
|
|
25
|
+
let srv = null; let browser = null;
|
|
26
|
+
const finish = async (code) => {
|
|
27
|
+
if (browser) await browser.close().catch(() => {});
|
|
28
|
+
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
29
|
+
T.killTmux(); R.cleanup();
|
|
30
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
31
|
+
console.log(`\n${results.length - bad}/${results.length} premium-core-doc-issue assertions passed`);
|
|
32
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
33
|
+
};
|
|
34
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
35
|
+
|
|
36
|
+
const ledger = () => { const f = CD.ledgerFile(team); return fs.existsSync(f) ? fs.readFileSync(f, 'utf8').split('\n').filter(Boolean).map((x) => JSON.parse(x)) : []; };
|
|
37
|
+
const ALLOWED = /^\/api\/(?:core-docs\/issue|briefing-premium\/note)$/;
|
|
38
|
+
const BODY = '## Purpose\n\nWhy this board exists.\n\n## Scope\n\nWhat it covers.\n';
|
|
39
|
+
|
|
40
|
+
(async () => {
|
|
41
|
+
const exe = findBrowser();
|
|
42
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
43
|
+
let chromium;
|
|
44
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
45
|
+
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT), PMOS_SELF_ROOT: team, PMOS_NO_OPEN: '1' }) });
|
|
46
|
+
await T.waitForServer(BASE);
|
|
47
|
+
const ready = await until(async () => { const r = await fetch(BASE + '/api/board-premium'); const j = await r.json().catch(() => null); return r.status === 200 && j && j.ok && j.state === 'ready' && j.model.initiatives.list.rows.length ? j : null; }, 90000, 400);
|
|
48
|
+
if (!ready) { ok('setup the real route reads the scratch board', false); return finish(1); }
|
|
49
|
+
const B = ready.model.board, bscope = ready.model.docs.scope;
|
|
50
|
+
const bkey = (ready.model.docs.rows.find((d) => d.act && d.act.kind === 'draft' && d.st === 'missing') || {}).key;
|
|
51
|
+
ok('setup the board has a core document not started, and a scope', !!bkey && /^board:/.test(bscope), JSON.stringify({ bscope, bkey }));
|
|
52
|
+
const d1 = CD.writeDraft(team, { scope: bscope, key: bkey, markdown: BODY, by: 'agent:test', now: Date.now() });
|
|
53
|
+
const iq = '?id=pa-one&ws=' + encodeURIComponent(B.ws) + '&board=' + encodeURIComponent(B.id);
|
|
54
|
+
const ini = await until(async () => { const r = await fetch(BASE + '/api/initiative-premium' + iq); const j = await r.json().catch(() => null); return r.status === 200 && j && j.ok && j.state === 'ready' ? j : null; }, 90000, 400);
|
|
55
|
+
/* the initiative documents PMOS keeps itself are Risks and Outcome review (lib/core-docs.js storable); the others are read from their own source */
|
|
56
|
+
const free = ini ? ['risks', 'outcome'].filter((k) => ini.model.docs.rows.some((d) => d.key === k && !d.tech)) : [];
|
|
57
|
+
const ikey = free[0];
|
|
58
|
+
const iscope = ini && ini.model.docs.scope;
|
|
59
|
+
ok('setup the initiative has two core documents not started', free.length >= 2 && iscope === 'initiative:pa-one', JSON.stringify({ iscope, ikey }));
|
|
60
|
+
if (!ikey) return finish(1);
|
|
61
|
+
const d2 = CD.writeDraft(team, { scope: iscope, key: ikey, markdown: BODY, by: 'agent:test', now: Date.now() });
|
|
62
|
+
const d3 = CD.writeDraft(team, { scope: iscope, key: free[1], markdown: BODY, by: 'agent:test', now: Date.now() });
|
|
63
|
+
ok('setup the writer left three drafts', d1.ok && d2.ok && d3.ok, JSON.stringify([d1, d2, d3]));
|
|
64
|
+
|
|
65
|
+
/* R reading */
|
|
66
|
+
const board2 = await (await fetch(BASE + '/api/board-premium')).json();
|
|
67
|
+
const br = board2.model.docs.rows.find((d) => d.key === bkey);
|
|
68
|
+
ok('R1 the board model carries the draft\'s slot and path from the core-docs answer', br.st === 'draft' && br.slot === d1.slot && br.path === d1.path, JSON.stringify(br));
|
|
69
|
+
const ini2 = await (await fetch(BASE + '/api/initiative-premium' + iq)).json();
|
|
70
|
+
const ir = ini2.model.docs.rows.find((d) => d.key === ikey);
|
|
71
|
+
ok('R2 the initiative model carries the draft\'s slot and path', ir.st === 'draft' && ir.slot === d2.slot && ir.path === d2.path, JSON.stringify(ir));
|
|
72
|
+
|
|
73
|
+
browser = await chromium.launch({ executablePath: exe });
|
|
74
|
+
const open = async (url, { w = 1280, h = 900, theme = 'light' } = {}) => {
|
|
75
|
+
const ctx = await browser.newContext({ viewport: { width: w, height: h } });
|
|
76
|
+
await ctx.addInitScript(() => { try { localStorage.setItem('pmos.premium.openAs', 'popup'); } catch { /* none */ } });
|
|
77
|
+
const page = await ctx.newPage(), errors = [], posts = [];
|
|
78
|
+
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
|
|
79
|
+
page.on('request', (rq) => { if (rq.method() === 'POST') posts.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}'), headers: rq.headers() }); });
|
|
80
|
+
await page.goto(BASE + url);
|
|
81
|
+
if (theme === 'dark') await page.evaluate(() => { document.documentElement.dataset.theme = 'dark'; });
|
|
82
|
+
return { ctx, page, errors, posts };
|
|
83
|
+
};
|
|
84
|
+
const dlgOn = async (p) => { const v = await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on'))); await sleep(800); return v; };
|
|
85
|
+
const toastIs = (p, re) => until(() => p.evaluate((s) => { const t = document.querySelector('#toast'); return t.classList.contains('on') && new RegExp(s).test(t.textContent) ? t.textContent : null; }, re.source));
|
|
86
|
+
const H = await T.pressHeaders(BASE);
|
|
87
|
+
const nonce = H['x-pmos-nonce'];
|
|
88
|
+
|
|
89
|
+
/* B the Board reader */
|
|
90
|
+
const P = await open('/premium-board.html'), p = P.page;
|
|
91
|
+
ok('B1 a board document with a file is a button that opens the reader', await until(() => p.evaluate((k) => !!document.querySelector(`#docBody [data-doc="${k}"]`), bkey)));
|
|
92
|
+
ok('B1 a document with no file is not', await p.evaluate((k) => !document.querySelector('#docBody .dmo:not(button)') || [...document.querySelectorAll('#docBody .dmo:not(button)')].every((x) => !x.closest('.dmr').querySelector(`[data-doc="${k}"]`)), bkey));
|
|
93
|
+
await p.click(`#docBody [data-doc="${bkey}"]`); await dlgOn(p);
|
|
94
|
+
ok('B2 the reader shows the file\'s text and path, and the bar says nothing is sent', await until(() => p.evaluate((pt) => { const o = document.querySelector('#oMain'); return /Why this board exists/.test(o.textContent) && o.textContent.includes(pt) && !!o.querySelector('[data-issue-bar="draft"]') && /Nothing is sent/.test(o.querySelector('[data-issue-bar]').textContent) && !!o.querySelector('[data-rd="issue"]'); }, d1.path)), await p.evaluate(() => document.querySelector('#oMain').textContent));
|
|
95
|
+
ok('B2 the reader has no Edit tab', await p.evaluate(() => !document.querySelector('#oMain [data-sh]')));
|
|
96
|
+
const n0 = ledger().filter((l) => l.ev === 'issue').length;
|
|
97
|
+
await p.click('[data-rd="issue"]');
|
|
98
|
+
ok('B3 Issue it says it sent nothing', !!(await toastIs(p, /Issued\. Nothing was sent to anyone/)));
|
|
99
|
+
const sent = P.posts.filter((x) => x.path === '/api/core-docs/issue');
|
|
100
|
+
ok('B4 it posted the workspace, the scope, the key and the slot, and nothing else, with the launch nonce', sent.length === 1 && Object.keys(sent[0].body).sort().join() === 'key,scope,slot,ws' && sent[0].body.scope === bscope && sent[0].body.key === bkey && sent[0].body.slot === d1.slot && sent[0].body.ws === B.ws && sent[0].headers['x-pmos-nonce'] === nonce && !!nonce, JSON.stringify(sent));
|
|
101
|
+
const il = ledger().filter((l) => l.ev === 'issue');
|
|
102
|
+
ok('B5 the ledger has one new issue line for that draft, written by the PM', il.length === n0 + 1 && il[il.length - 1].slot === d1.slot && il[il.length - 1].scope === bscope && /pm/.test(String(il[il.length - 1].by)), JSON.stringify(il));
|
|
103
|
+
ok('B5 the file now says state: issued', /^state: issued$/m.test(fs.readFileSync(path.join(team, d1.path), 'utf8')));
|
|
104
|
+
ok('B6 the reader says it is issued, the Issue it press is gone, and the row reads Up to date', await until(() => p.evaluate(() => { const o = document.querySelector('#oMain'); return !!o.querySelector('[data-issue-bar="done"]') && !o.querySelector('[data-rd="issue"]') && /state: issued|issued/.test(o.textContent); })) && await until(() => p.evaluate((k) => { const r = document.querySelector(`#docBody [data-doc="${k}"]`); return r && /Up to date/.test(r.textContent); }, bkey)));
|
|
105
|
+
await p.screenshot({ path: path.join(R.base, 'board-issued.png') });
|
|
106
|
+
await P.ctx.close();
|
|
107
|
+
|
|
108
|
+
/* I the initiative sheet */
|
|
109
|
+
const I = await open('/premium-initiative.html' + iq), ip = I.page;
|
|
110
|
+
await until(() => ip.evaluate((k) => !!document.querySelector(`#dmList [data-doc="${k}"]`), ikey), 60000);
|
|
111
|
+
await ip.click(`#dmList [data-doc="${ikey}"]`); await dlgOn(ip);
|
|
112
|
+
ok('I1 the Read tab of a draft has the Issue it bar above the text', await until(() => ip.evaluate(() => { const o = document.querySelector('#oMain'); const b = o.querySelector('[data-issue-bar="draft"]'); return !!b && /Nothing is sent/.test(b.textContent) && /Why this board exists/.test(o.textContent) && b.compareDocumentPosition(o.querySelector('.dsbody')) & Node.DOCUMENT_POSITION_FOLLOWING; })));
|
|
113
|
+
await ip.click('[data-sh="edit"]');
|
|
114
|
+
await until(() => ip.evaluate(() => !!document.querySelector('#dsEd')));
|
|
115
|
+
await ip.fill('#dsEd', BODY + '\n## Added\n\nUnsaved line.\n');
|
|
116
|
+
await ip.click('[data-sh="read"]');
|
|
117
|
+
await until(() => ip.evaluate(() => !!document.querySelector('[data-ds="issue"]')));
|
|
118
|
+
const nI = I.posts.length;
|
|
119
|
+
await ip.click('[data-ds="issue"]');
|
|
120
|
+
ok('I2 Issue it with unsaved edits posts nothing and says to save or cancel first', await until(() => ip.evaluate(() => /unsaved changes.*Save or cancel/.test((document.querySelector('#dsErr') || {}).textContent || ''))) && I.posts.length === nI);
|
|
121
|
+
ok('I2 the ledger has no issue line for that draft yet', !ledger().some((l) => l.ev === 'issue' && l.slot === d2.slot && l.scope === iscope));
|
|
122
|
+
await ip.click('[data-sh="edit"]'); await until(() => ip.evaluate(() => !!document.querySelector('[data-ds="discard"]')));
|
|
123
|
+
await ip.click('[data-ds="discard"]'); await ip.click('[data-sh="read"]');
|
|
124
|
+
await until(() => ip.evaluate(() => !!document.querySelector('[data-ds="issue"]')));
|
|
125
|
+
/* a refusal: someone else issues the same draft first (the console, a second tab) */
|
|
126
|
+
const raced = await fetch(BASE + '/api/core-docs/issue', { method: 'POST', headers: H, body: JSON.stringify({ ws: B.ws, scope: iscope, key: ikey, slot: d2.slot }) });
|
|
127
|
+
ok('I3 setup the draft is issued behind the page\'s back', raced.status === 200);
|
|
128
|
+
await ip.click('[data-ds="issue"]');
|
|
129
|
+
ok('I3 a refused press shows the server\'s words and the sheet changes nothing else', await until(() => ip.evaluate(() => /already/.test((document.querySelector('#dsErr') || {}).textContent || ''))));
|
|
130
|
+
ok('I3 the refusal wrote no second issue line', ledger().filter((l) => l.ev === 'issue' && l.slot === d2.slot && l.scope === iscope).length === 1);
|
|
131
|
+
await ip.click('#dlg [data-act="close"], #dClose').catch(() => {});
|
|
132
|
+
await I.ctx.close();
|
|
133
|
+
|
|
134
|
+
/* I4 a fresh page: press Issue it on the third draft */
|
|
135
|
+
const J = await open('/premium-initiative.html' + iq), jp = J.page;
|
|
136
|
+
const k3 = d3.path.split('/').slice(-2)[0];
|
|
137
|
+
await until(() => jp.evaluate((k) => !!document.querySelector(`#dmList [data-doc="${k}"]`), k3), 60000);
|
|
138
|
+
await jp.click(`#dmList [data-doc="${k3}"]`); await dlgOn(jp);
|
|
139
|
+
await until(() => jp.evaluate(() => !!document.querySelector('[data-ds="issue"]')));
|
|
140
|
+
await jp.click('[data-ds="issue"]');
|
|
141
|
+
ok('I4 Issue it works from the sheet: the toast, the issued bar, and the row reads Up to date', !!(await toastIs(jp, /Issued\. Nothing was sent to anyone/)) && await until(() => jp.evaluate(() => !!document.querySelector('#oMain [data-issue-bar="done"]') && !document.querySelector('[data-ds="issue"]'))) && await until(() => jp.evaluate((k) => /Up to date/.test((document.querySelector(`#dmList [data-doc="${k}"]`) || {}).textContent || ''), k3)));
|
|
142
|
+
ok('I4 the file says state: issued and the ledger has its issue line', /^state: issued$/m.test(fs.readFileSync(path.join(team, d3.path), 'utf8')) && ledger().some((l) => l.ev === 'issue' && l.slot === d3.slot && l.scope === iscope));
|
|
143
|
+
await jp.screenshot({ path: path.join(R.base, 'ini-issued.png') });
|
|
144
|
+
|
|
145
|
+
/* P the POST allow-list and the refusals */
|
|
146
|
+
const all = P.posts.concat(I.posts, J.posts);
|
|
147
|
+
const other = all.filter((x) => !ALLOWED.test(x.path));
|
|
148
|
+
ok('P1 the pages post only to the issue route (and the conversation note)', all.length >= 3 && !other.length, JSON.stringify(other));
|
|
149
|
+
const sentAll = all.filter((x) => x.path === '/api/core-docs/issue');
|
|
150
|
+
ok('P2 every issue press carried the nonce and no writer field', sentAll.length >= 3 && sentAll.every((x) => x.headers['x-pmos-nonce'] === nonce && !['by', 'via', 'at', 'actor', 'pm', 'nonce'].some((k) => k in x.body)));
|
|
151
|
+
const bare = await fetch(BASE + '/api/core-docs/issue', { method: 'POST', headers: { 'Content-Type': 'application/json', Origin: BASE }, body: JSON.stringify({ ws: B.ws, scope: bscope, key: bkey, slot: d1.slot }) });
|
|
152
|
+
ok('P3 a press without the launch nonce is refused', bare.status === 403);
|
|
153
|
+
const agent = await fetch(BASE + '/api/core-docs/issue', { method: 'POST', headers: { ...H, 'x-pmos-session': 's1' }, body: JSON.stringify({ ws: B.ws, scope: bscope, key: bkey, slot: d1.slot }) });
|
|
154
|
+
ok('P4 an agent session gets 403', agent.status === 403);
|
|
155
|
+
ok('P5 no script error on any page', !P.errors.length && !I.errors.length && !J.errors.length, P.errors.concat(I.errors, J.errors).join(' | '));
|
|
156
|
+
await J.ctx.close();
|
|
157
|
+
|
|
158
|
+
/* F floors and fidelity: a fresh draft, at 390 and 1280, light and dark */
|
|
159
|
+
const d4 = CD.writeDraft(team, { scope: bscope, key: (board2.model.docs.rows.filter((d) => d.act && d.act.kind === 'draft' && d.st === 'missing' && d.key !== bkey)[0] || {}).key, markdown: BODY, by: 'agent:test', now: Date.now() });
|
|
160
|
+
const k4 = d4.path.split('/').slice(-2)[0];
|
|
161
|
+
for (const [w, h, theme] of [[390, 844, 'light'], [390, 844, 'dark'], [1280, 900, 'dark']]) {
|
|
162
|
+
const S = await open('/premium-board.html', { w, h, theme });
|
|
163
|
+
await until(() => S.page.evaluate((k) => !!document.querySelector(`#docBody [data-doc="${k}"]`), k4), 60000);
|
|
164
|
+
await S.page.click(`#docBody [data-doc="${k4}"]`); await dlgOn(S.page);
|
|
165
|
+
await until(() => S.page.evaluate(() => !!document.querySelector('[data-rd="issue"]')));
|
|
166
|
+
const f = await S.page.evaluate(() => ({ wide: document.documentElement.scrollWidth > innerWidth + 1, small: [...document.querySelectorAll('#oMain [data-rd]')].filter((b) => b.getBoundingClientRect().height < 44 || b.getBoundingClientRect().width < 44).map((b) => b.dataset.rd), bg: getComputedStyle(document.querySelector('[data-issue-bar]')).backgroundColor }));
|
|
167
|
+
ok(`F1 ${w} px ${theme}: no sideways scroll and the bar's buttons are at least 44 px`, !f.wide && !f.small.length, JSON.stringify(f));
|
|
168
|
+
await S.page.screenshot({ path: path.join(R.base, `bar-${w}-${theme}.png`) });
|
|
169
|
+
await S.ctx.close();
|
|
170
|
+
}
|
|
171
|
+
if (process.env.KEEP_SHOTS) { for (const f of fs.readdirSync(R.base).filter((x) => /\.png$/.test(x))) fs.copyFileSync(path.join(R.base, f), path.join(process.env.KEEP_SHOTS, f)); }
|
|
172
|
+
finish();
|
|
173
|
+
})();
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* lib/board-premium.js builds from the routes the production Initiatives page reads: the Initiatives card (List, By stage, Timeline), the Sprint and
|
|
3
3
|
* Coming up cards, Core documents, the dock and the standard dialog. The presses are Draft it on a core document, through POST /api/core-docs/draft,
|
|
4
4
|
* and the board's own presses of pm/premium-acts.js (initiative premium-board-actions): the New asks card, New initiative, and a row's menu (move,
|
|
5
|
-
* hold, cancel, archive and their Undo).
|
|
5
|
+
* hold, cancel, archive and their Undo). Issue it on a document draft, read in a dialog, is POST /api/core-docs/issue (initiative premium-core-doc-issue). */
|
|
6
6
|
import { pmPost } from './http.js';
|
|
7
|
-
import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, CHECK, store, crumbHtml, wireCrumb, kv, H, openAddDoc } from './premium-shell.js';
|
|
7
|
+
import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, CHECK, AI, store, crumbHtml, wireCrumb, kv, H, openAddDoc } from './premium-shell.js';
|
|
8
|
+
import { mdHtml, issueBody } from './premium-doc-edit.js';
|
|
8
9
|
import { dotsBtn, openMenu, closeMenu, menuKey, asksHtml, onAsks, openIniForm } from './premium-acts.js';
|
|
9
10
|
|
|
10
11
|
const MODE_KEY = 'pmos.premium.openAs';
|
|
@@ -105,7 +106,7 @@ function drawSide() {
|
|
|
105
106
|
}
|
|
106
107
|
function docRow(d) {
|
|
107
108
|
const act = !d.act ? '' : d.act.kind === 'draft' ? `<button class="dmcta alt" data-draft="${esc(d.key)}"${d.running ? ' disabled' : ''}>${d.running ? '<span class="spin"></span>' : ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}${esc(d.act.label)}</button>` : `<button class="dmcta alt" data-tab="${esc(d.act.tab)}">${esc(d.act.label)}</button>`;
|
|
108
|
-
return `<div class="dmr" role="listitem"
|
|
109
|
+
return `<div class="dmr ${esc(d.st || '')}" role="listitem">${d.path ? `<button class="dmo" data-doc="${esc(d.key)}" aria-haspopup="dialog">` : '<span class="dmo">'}<span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(d.title)}</b><small>${esc(d.what)}</small><span class="dmm"><span class="s ${esc(d.st || 'live')}">${ICO(STATE_ICO[d.state] || STATE_ICO['Not started'])}${esc(d.state)}</span>${d.added ? `<span>${ICO('<rect x="3" y="5" width="18" height="16" rx="3"/><path d="M3 10h18M8 3v4M16 3v4"/>')}added ${esc(d.added)}</span>` : ''}${d.cadence ? `<span>${ICO('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')}${esc(d.cadence)}</span>` : ''}${d.by ? `<span>${ICO('<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>')}${esc(d.by)}</span>` : ''}</span></span>${d.path ? '</button>' : '</span>'}<span class="dmq">${act}</span></div>`;
|
|
109
110
|
}
|
|
110
111
|
let docFilter = 'all', docQuery = '';
|
|
111
112
|
const draftable = () => (M.docs.rows || []).filter((d) => d.st === 'missing' && d.act && d.act.kind === 'draft' && !d.running);
|
|
@@ -128,7 +129,7 @@ function drawDocs() {
|
|
|
128
129
|
<label class="dmsr">${ICO('<circle cx="11" cy="11" r="6.5"/><path d="m20 20-4-4"/>')}<input id="dmQ" type="search" placeholder="Find a document" aria-label="Find a document" value="${esc(docQuery)}"></label></div>`;
|
|
129
130
|
drawDocList();
|
|
130
131
|
if (hadQ) { const q = $('#dmQ'); q.focus(); q.setSelectionRange(q.value.length, q.value.length); }
|
|
131
|
-
$('#docNote').textContent = 'Draft it starts a read-only agent run that writes a draft for you to read. Nothing is sent.
|
|
132
|
+
$('#docNote').textContent = 'Draft it starts a read-only agent run that writes a draft for you to read. Nothing is sent. Press a document to read it; a draft has Issue it, which marks it issued and sends nothing. Dropping a document is not built on this page.';
|
|
132
133
|
}
|
|
133
134
|
$('#docTop').addEventListener('click', async (e) => {
|
|
134
135
|
const f = e.target.closest('[data-dmf]'); if (f) { docFilter = f.dataset.dmf; drawDocList(); return; }
|
|
@@ -141,6 +142,7 @@ $('#docTop').addEventListener('click', async (e) => {
|
|
|
141
142
|
$('#docTop').addEventListener('input', (e) => { if (e.target.id === 'dmQ') { docQuery = e.target.value; drawDocList(); } });
|
|
142
143
|
const GOTAB = { rep: '/c3.html?tab=rep', init: '/c3.html?tab=init' };
|
|
143
144
|
$('#docBody').addEventListener('click', async (e) => {
|
|
145
|
+
const o = e.target.closest('[data-doc]'); if (o) { openReader(M.docs.rows.find((x) => x.key === o.dataset.doc)); return; }
|
|
144
146
|
const t = e.target.closest('[data-tab]'); if (t) { location.assign(GOTAB[t.dataset.tab] || '/c3.html'); return; }
|
|
145
147
|
const b = e.target.closest('[data-draft]'); if (!b || b.disabled) return;
|
|
146
148
|
const key = b.dataset.draft, d = M.docs.rows.find((x) => x.key === key);
|
|
@@ -151,6 +153,64 @@ $('#docBody').addEventListener('click', async (e) => {
|
|
|
151
153
|
await load();
|
|
152
154
|
});
|
|
153
155
|
|
|
156
|
+
/* ── a board document: read it, and issue a draft (initiative premium-core-doc-issue) ────────────────────── */
|
|
157
|
+
let rd = null; // { d, text, md, err, busy, msg, issued }
|
|
158
|
+
const rdGet = async (url) => { try { const r = await fetch(url, { credentials: 'same-origin' }); return await r.json(); } catch { return null; } };
|
|
159
|
+
function rdBar(r) {
|
|
160
|
+
const d = r.d;
|
|
161
|
+
if (r.issued && d.st !== 'draft') return `<div class="dsiss dsok" data-issue-bar="done" role="status"><span>${CHECK}Issued. Nothing was sent to anyone. The row now reads ${esc(d.state)}.</span></div>`;
|
|
162
|
+
if (d.st !== 'draft' || !d.slot) return '';
|
|
163
|
+
return `<div class="dsiss" data-issue-bar="draft"><span>${AI}PMOS drafted this from its sources. Nothing is sent. Read it, then issue it, or draft it again.</span><span class="dsa"><button class="dmcta dark" data-rd="issue"${r.busy ? ' disabled' : ''}>Issue it</button><button class="dmcta alt" data-rd="again"${r.busy ? ' disabled' : ''}>Draft it again</button></span></div>`
|
|
164
|
+
+ (r.msg ? `<p class="note" id="rdErr" role="alert" style="margin:-4px 0 10px;color:var(--ember-ink)">${esc(r.msg)}</p>` : '');
|
|
165
|
+
}
|
|
166
|
+
function drawReader() {
|
|
167
|
+
const r = rd, d = r.d;
|
|
168
|
+
let body;
|
|
169
|
+
if (r.err) body = `<p class="empty3 plain">${esc(r.err)}</p>`;
|
|
170
|
+
else if (r.text == null) body = '<p class="empty3 plain">Reading the file.</p>';
|
|
171
|
+
else { const m = r.md || (r.md = mdHtml(r.text)); body = (m.fm.length ? kv(m.fm) : '') + `<div class="dsrd no"><div class="dsbody">${m.html}</div></div>`; }
|
|
172
|
+
$('#oMain').innerHTML = `<article class="paper doc"><p class="dpath">${esc(d.path)}</p><div class="dsm"><span class="${d.st === 'ok' ? 'ok' : d.st === 'draft' ? 'warn' : 'mut'}">${esc(d.state)}</span>${d.when ? `<span>updated ${esc(d.when)}</span>` : ''}${d.by ? `<span>${esc(d.by)}</span>` : ''}</div>${rdBar(r)}<div id="shBody">${body}</div><p class="xn">${d.st === 'draft' ? 'A board draft is changed by drafting it again; the new draft replaces this one. ' : ''}The file changes only when you press Issue it.</p></article>`;
|
|
173
|
+
}
|
|
174
|
+
async function openReader(d) {
|
|
175
|
+
if (!d || !d.path) return;
|
|
176
|
+
const r = rd = { d, text: null, md: null, err: null, busy: false, msg: '', issued: false };
|
|
177
|
+
const say = d.title + ' is ' + d.state.toLowerCase() + (d.by ? '. ' + d.by + '.' : '.') + ' I can read the file with you and answer questions. I change nothing; only you issue it.';
|
|
178
|
+
openDlg({ eye: 'Document · real data', title: d.title, sub: M.board.name, say, stream: turnA(logHtml({ logTitle: 'Read from the repository', log: ['Found the file ' + d.path, 'Left the file as it is'] })) + turnA(ptx(say)), noteKey: 'doc:' + M.board.id + ':' + d.key, pane: '', label: 'Document' });
|
|
179
|
+
drawReader(); loadThread('doc:' + M.board.id + ':' + d.key);
|
|
180
|
+
await rdRead(r);
|
|
181
|
+
}
|
|
182
|
+
/** The file's latest revision, as the document sheet reads it (the log route first records an outside change, so an issue shows up). */
|
|
183
|
+
async function rdRead(r) {
|
|
184
|
+
const p = encodeURIComponent(r.d.path), ws = M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) : '';
|
|
185
|
+
const lg = await rdGet('/api/doc-sheet/log?path=' + p + ws); if (rd !== r) return;
|
|
186
|
+
const revs = lg && lg.ok ? lg.revisions || [] : [];
|
|
187
|
+
const at = revs.length ? await rdGet('/api/doc-sheet/at?path=' + p + '&rev=' + revs[revs.length - 1].rev + ws) : null; if (rd !== r) return;
|
|
188
|
+
r.err = null;
|
|
189
|
+
if (at && at.ok) r.text = at.text; else r.err = (at && at.error) || (lg && lg.error) || 'The file could not be read.';
|
|
190
|
+
r.md = null; drawReader();
|
|
191
|
+
}
|
|
192
|
+
$('#oMain').addEventListener('click', async (e) => {
|
|
193
|
+
const b = e.target.closest('[data-rd]'); if (!b || !rd || b.disabled) return;
|
|
194
|
+
const r = rd, d = r.d;
|
|
195
|
+
const fail = (m) => { r.busy = false; r.msg = m; drawReader(); };
|
|
196
|
+
r.msg = '';
|
|
197
|
+
if (b.dataset.rd === 'issue') {
|
|
198
|
+
const q = issueBody(M.board.ws, M.docs.scope, d.key, d.slot, false); if (q.error) return fail(q.error);
|
|
199
|
+
r.busy = true; drawReader();
|
|
200
|
+
const res = await pmPost('/api/core-docs/issue', q.body); if (rd !== r) return;
|
|
201
|
+
if (!res || res.ok !== true) return fail((res && res.error) || 'The document could not be issued.');
|
|
202
|
+
toast('Issued. Nothing was sent to anyone.');
|
|
203
|
+
r.issued = true; r.busy = false; await load(); if (rd !== r) return;
|
|
204
|
+
r.d = M.docs.rows.find((x) => x.key === d.key) || r.d; r.text = null; r.md = null; drawReader(); await rdRead(r);
|
|
205
|
+
} else if (b.dataset.rd === 'again') {
|
|
206
|
+
r.busy = true; drawReader();
|
|
207
|
+
const res = await pmPost('/api/core-docs/draft', { ws: M.board.ws, scope: M.docs.scope, key: d.key }); if (rd !== r) return;
|
|
208
|
+
if (!res || res.ok !== true) return fail((res && res.error) || 'The draft could not be started.');
|
|
209
|
+
toast('The agent is drafting “' + d.title + '” again. The new draft replaces this one when it is ready, and it sends nothing.');
|
|
210
|
+
r.busy = false; closeDlg(); await load();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
154
214
|
$('#addDoc').onclick = () => openAddDoc({ ws: M.board.ws, scope: M.docs.scope, sub: M.board.name, onAdded: load });
|
|
155
215
|
|
|
156
216
|
/* ── new asks and New initiative (initiative premium-board-actions) ───────────────────────────────────────── */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* premium-doc-edit.js — the pure half of the premium document sheet's Edit and Proposals tabs (initiative briefing-premium-doc-edit).
|
|
2
2
|
* No DOM and no fetch: it turns the answers of /api/doc-sheet/* into what the tabs draw, and builds the bodies of the presses. Every figure here is a
|
|
3
3
|
* field of a route's answer; a proposal's section is stale only because the route says it is. */
|
|
4
|
+
const esc = (s) => String(s == null ? '' : s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
4
5
|
const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).trimEnd() + '…' : t; };
|
|
5
6
|
|
|
6
7
|
/** One proposal as the tab draws it. `p` is a row of GET /api/doc-sheet/proposals. */
|
|
@@ -68,3 +69,32 @@ export function askLine(a) {
|
|
|
68
69
|
if (a.state === 'failed') return a.error || 'The agent could not answer.';
|
|
69
70
|
return '';
|
|
70
71
|
}
|
|
72
|
+
|
|
73
|
+
/** Issue press (a core document draft). The route needs the workspace, the scope, the key and the draft's slot, and takes nothing else. */
|
|
74
|
+
export function issueBody(ws, scope, key, slot, unsaved) {
|
|
75
|
+
if (unsaved) return { error: 'You have unsaved changes in the Edit tab. Save or cancel them first, so the document you issue is the one you read.' };
|
|
76
|
+
if (!slot) return { error: 'This document has no open draft to issue.' };
|
|
77
|
+
return { body: { ws, scope, key, slot } };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The Read tab's text as html with its outline and front matter. Pure: the page puts the html in the sheet. */
|
|
81
|
+
export function mdHtml(text) {
|
|
82
|
+
const lines = String(text || '').replace(/\r/g, '').split('\n'), out = [], outline = [];
|
|
83
|
+
let i = 0, fm = [];
|
|
84
|
+
if (lines[0] === '---') { const e = lines.indexOf('---', 1); if (e > 0) { fm = lines.slice(1, e).map((l) => /^([A-Za-z_][\w -]*):\s*(.*)$/.exec(l)).filter(Boolean).slice(0, 10).map((m) => [m[1], m[2].replace(/^"(.*)"$/, '$1')]); i = e + 1; } }
|
|
85
|
+
let para = [], list = [];
|
|
86
|
+
const flushP = () => { if (para.length) { out.push(`<p>${esc(para.join(' '))}</p>`); para = []; } };
|
|
87
|
+
const flushL = () => { if (list.length) { out.push(`<ul>${list.map((x) => `<li>${esc(x)}</li>`).join('')}</ul>`); list = []; } };
|
|
88
|
+
for (; i < lines.length; i++) {
|
|
89
|
+
const l = lines[i];
|
|
90
|
+
if (/^```/.test(l)) { flushP(); flushL(); const buf = []; for (i++; i < lines.length && !/^```/.test(lines[i]); i++) buf.push(lines[i]); out.push(`<pre class="mdp">${esc(buf.join('\n'))}</pre>`); continue; }
|
|
91
|
+
const h = /^(#{1,4})\s+(.*)$/.exec(l);
|
|
92
|
+
if (h) { flushP(); flushL(); const n = outline.length; outline.push(h[2]); out.push(`<h3 class="d2" id="ds-h${n}">${esc(h[2])}</h3>`); continue; }
|
|
93
|
+
if (/^\s*[-*]\s+/.test(l)) { flushP(); list.push(l.replace(/^\s*[-*]\s+/, '')); continue; }
|
|
94
|
+
if (/^\|/.test(l)) { flushP(); flushL(); const buf = [l]; while (i + 1 < lines.length && /^\|/.test(lines[i + 1])) buf.push(lines[++i]); out.push(`<pre class="mdp">${esc(buf.join('\n'))}</pre>`); continue; }
|
|
95
|
+
if (!l.trim()) { flushP(); flushL(); continue; }
|
|
96
|
+
flushL(); para.push(l.trim());
|
|
97
|
+
}
|
|
98
|
+
flushP(); flushL();
|
|
99
|
+
return { html: out.join(''), outline, fm };
|
|
100
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* existing /api/doc-sheet routes, initiative briefing-premium-doc-edit), Add a task and a task's status, and the bar under the stages (initiative
|
|
6
6
|
* premium-board-actions, pm/premium-acts.js): move to the next stage or back, hold, cancel, archive, resume, reopen and restore, each with Undo. Nothing here issues a document. */
|
|
7
7
|
import { pmPost } from './http.js';
|
|
8
|
-
import { proposalsModel, editBody, acceptBody, rejectBody, askBody, askLine } from './premium-doc-edit.js';
|
|
8
|
+
import { proposalsModel, editBody, acceptBody, rejectBody, askBody, askLine, issueBody, mdHtml } from './premium-doc-edit.js';
|
|
9
9
|
import { $, $$, esc, openDlg, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, kv, H2, CHECK, crumbHtml, wireCrumb, AI, openAddDoc } from './premium-shell.js';
|
|
10
10
|
import { barHtml, onBar, closeMenu } from './premium-acts.js';
|
|
11
11
|
|
|
@@ -182,7 +182,7 @@ function docsHtml() {
|
|
|
182
182
|
<div class="dtool"><div class="seg" id="dmF" role="group" aria-label="Filter documents"><i class="pill"></i>${[['all', 'All', c.all], ['none', 'Not started', c.none], ['draft', 'Draft', c.draft], ['ok', 'Up to date', c.ok]].map(([k, l, n]) => `<button data-dmf="${k}" aria-pressed="${docFilter === k}">${l}<em>${n}</em></button>`).join('')}</div>
|
|
183
183
|
<label class="dmsr">${ICO('<circle cx="11" cy="11" r="6.5"/><path d="m20 20-4-4"/>')}<input id="dmQ" type="search" placeholder="Find a document" aria-label="Find a document" value="${esc(docQuery)}"></label></div>
|
|
184
184
|
<div id="dmList"></div>
|
|
185
|
-
<p class="note" style="margin-top:12px">The core documents of this initiative. Press a row to read it, see its edit log or its health. Draft it starts a read-only agent run that writes a draft for you to read; nothing is sent.
|
|
185
|
+
<p class="note" style="margin-top:12px">The core documents of this initiative. Press a row to read it, see its edit log or its health. Draft it starts a read-only agent run that writes a draft for you to read; nothing is sent. Issue it on a draft's sheet marks the draft as issued; nothing is sent. Dropping a document is not built on this page. A document you add is saved on the record; PMOS does not read a linked page.</p></section>`;
|
|
186
186
|
}
|
|
187
187
|
$('#iMain').addEventListener('input', (e) => { if (e.target.id === 'dmQ') { docQuery = e.target.value; drawDocList(); } });
|
|
188
188
|
const draftable = () => M.docs.rows.filter((d) => !d.tech && d.st === 'missing' && d.act && d.act.kind === 'draft' && !d.running);
|
|
@@ -223,25 +223,13 @@ let sheet = null; // { d, tab, text, log, health, props, draft, why, ask, askT
|
|
|
223
223
|
const TABS = [['read', 'Read'], ['edit', 'Edit'], ['props', 'Proposals'], ['log', 'Edit log'], ['health', 'Health']];
|
|
224
224
|
const wsq = () => (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) : '');
|
|
225
225
|
const propsM = (s) => proposalsModel(s.props || []);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
for (; i < lines.length; i++) {
|
|
234
|
-
const l = lines[i];
|
|
235
|
-
if (/^```/.test(l)) { flushP(); flushL(); const buf = []; for (i++; i < lines.length && !/^```/.test(lines[i]); i++) buf.push(lines[i]); out.push(`<pre class="mdp">${esc(buf.join('\n'))}</pre>`); continue; }
|
|
236
|
-
const h = /^(#{1,4})\s+(.*)$/.exec(l);
|
|
237
|
-
if (h) { flushP(); flushL(); const n = outline.length; outline.push(h[2]); out.push(`<h3 class="d2" id="ds-h${n}">${esc(h[2])}</h3>`); continue; }
|
|
238
|
-
if (/^\s*[-*]\s+/.test(l)) { flushP(); list.push(l.replace(/^\s*[-*]\s+/, '')); continue; }
|
|
239
|
-
if (/^\|/.test(l)) { flushP(); flushL(); const buf = [l]; while (i + 1 < lines.length && /^\|/.test(lines[i + 1])) buf.push(lines[++i]); out.push(`<pre class="mdp">${esc(buf.join('\n'))}</pre>`); continue; }
|
|
240
|
-
if (!l.trim()) { flushP(); flushL(); continue; }
|
|
241
|
-
flushL(); para.push(l.trim());
|
|
242
|
-
}
|
|
243
|
-
flushP(); flushL();
|
|
244
|
-
return { html: out.join(''), outline, fm };
|
|
226
|
+
/** The bar above a draft (core document Issue, initiative premium-core-doc-issue). The words are fixed; the state is the row's own. */
|
|
227
|
+
function issueBar(s) {
|
|
228
|
+
const d = s.d;
|
|
229
|
+
if (s.issued && d.st !== 'draft') return `<div class="dsiss dsok" data-issue-bar="done" role="status"><span>${CHECK}Issued. Nothing was sent to anyone. The row now reads ${esc(d.state)}.</span></div>`;
|
|
230
|
+
if (d.st !== 'draft' || !d.slot) return '';
|
|
231
|
+
return `<div class="dsiss" data-issue-bar="draft"><span>${AI}PMOS drafted this from its sources. Nothing is sent. Read it, change what you like, then issue it.</span><button class="dmcta dark" data-ds="issue"${s.busy ? ' disabled' : ''}>Issue it</button></div>`
|
|
232
|
+
+ (s.msg && s.tab === 'read' ? `<p class="note" id="dsErr" role="alert" style="margin:-4px 0 10px;color:var(--ember-ink)">${esc(s.msg)}</p>` : '');
|
|
245
233
|
}
|
|
246
234
|
function sheetPane() {
|
|
247
235
|
const s = sheet, d = s.d;
|
|
@@ -251,7 +239,7 @@ function sheetPane() {
|
|
|
251
239
|
if (s.err) body = `<p class="empty3 plain">${esc(s.err)}</p>`;
|
|
252
240
|
else if (s.tab === 'read') {
|
|
253
241
|
if (s.text == null) body = '<p class="empty3 plain">Reading the file.</p>';
|
|
254
|
-
else { const m = s.md || (s.md = mdHtml(s.text)); body = (m.fm.length ? kv(m.fm) : '') + `<div class="dsrd${m.outline.length > 2 ? '' : ' no'}">${m.outline.length > 2 ? `<nav class="dso" aria-label="Outline"><p class="label">Outline <em>${m.outline.length} headings</em></p>${m.outline.map((t, n) => `<button data-go="${n}">${esc(t)}${s.props && propsM(s).marked.has(t) ? '<i></i>' : ''}</button>`).join('')}</nav>` : ''}<div class="dsbody">${m.html}</div></div>`; }
|
|
242
|
+
else { const m = s.md || (s.md = mdHtml(s.text)); body = issueBar(s) + (m.fm.length ? kv(m.fm) : '') + `<div class="dsrd${m.outline.length > 2 ? '' : ' no'}">${m.outline.length > 2 ? `<nav class="dso" aria-label="Outline"><p class="label">Outline <em>${m.outline.length} headings</em></p>${m.outline.map((t, n) => `<button data-go="${n}">${esc(t)}${s.props && propsM(s).marked.has(t) ? '<i></i>' : ''}</button>`).join('')}</nav>` : ''}<div class="dsbody">${m.html}</div></div>`; }
|
|
255
243
|
} else if (s.tab === 'edit') {
|
|
256
244
|
if (s.text == null) body = '<p class="empty3 plain">Reading the file.</p>';
|
|
257
245
|
else {
|
|
@@ -355,6 +343,16 @@ async function sheetPress(act) {
|
|
|
355
343
|
const fail = (m) => { s.busy = false; s.msg = m; drawSheet(); };
|
|
356
344
|
if (act === 'rejno') { s.rejecting = null; s.msg = ''; drawSheet(); return; }
|
|
357
345
|
if (act === 'discard') { s.draft = null; s.why = ''; s.msg = ''; drawSheet(); return; }
|
|
346
|
+
if (act === 'issue') {
|
|
347
|
+
const r = issueBody(M.board.ws, M.docs.scope, s.d.key, s.d.slot, s.draft != null && s.draft !== s.text); if (r.error) return fail(r.error);
|
|
348
|
+
s.busy = true; s.msg = ''; drawSheet();
|
|
349
|
+
const res = await pmPost('/api/core-docs/issue', r.body); if (sheet !== s) return;
|
|
350
|
+
if (!res || res.ok !== true) return fail((res && res.error) || 'The document could not be issued.');
|
|
351
|
+
toast('Issued. Nothing was sent to anyone.');
|
|
352
|
+
s.issued = true; await load(); if (sheet !== s) return;
|
|
353
|
+
s.d = M.docs.rows.find((x) => x.key === s.d.key) || s.d;
|
|
354
|
+
return reloadSheet(s);
|
|
355
|
+
}
|
|
358
356
|
if (act === 'save') {
|
|
359
357
|
const r = editBody(s.d.path, s.text, s.draft == null ? s.text : s.draft, s.why); if (r.error) return fail(r.error);
|
|
360
358
|
s.busy = true; s.msg = ''; drawSheet();
|
|
@@ -1362,3 +1362,11 @@ button.dsn:hover{box-shadow:inset 0 0 0 1.5px rgb(79,109,245)}
|
|
|
1362
1362
|
.ssdone{color:var(--ok);font-weight:650}
|
|
1363
1363
|
.sse{padding:34px 20px;text-align:center;border-radius:var(--r-in);background:var(--well)}.sse b{display:block;font-size:17px;font-weight:650}.sse p{color:var(--ink-2);margin-top:6px;font-size:var(--t-small)}
|
|
1364
1364
|
@media (max-width:700px){.ssr{grid-template-columns:auto minmax(0,1fr)}.ssr>.cta{grid-column:2}}
|
|
1365
|
+
|
|
1366
|
+
/* Issue it on a core document draft (initiative premium-core-doc-issue) */
|
|
1367
|
+
.dsiss{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;padding:12px 16px;border-radius:14px;background:color-mix(in oklab,var(--ember) 12%,transparent);margin:0 0 12px;font-size:12.5px}
|
|
1368
|
+
.dsiss>span:first-child{display:inline-flex;gap:8px;align-items:center;flex:1 1 220px;min-width:0}
|
|
1369
|
+
.dsiss svg{width:15px;height:15px;flex:none;color:var(--ember-ink)}
|
|
1370
|
+
.dsiss .dsa{display:flex;gap:8px;flex-wrap:wrap}
|
|
1371
|
+
.dsiss.dsok{background:color-mix(in oklab,var(--ok) 12%,transparent)}
|
|
1372
|
+
.dsiss.dsok svg{color:var(--ok)}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Initiative premium-core-doc-issue: Issue it on a core document draft, from the premium Board's reader and the premium initiative sheet, against the real server on a scratch team repo.",
|
|
3
|
+
"panels": [
|
|
4
|
+
"premium-core-doc-issue-test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"premium-core-doc-issue-test.js": 150
|
|
8
|
+
}
|
|
9
|
+
}
|