create-pmos 0.293.0 → 0.295.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.293.0",
3
+ "version": "0.295.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": {
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@4c0d137
1
+ kernel-source: pmos@85d9eac
2
2
  assembled: 2026-10-19
3
3
  mode: vendor
@@ -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-19T04:24:11Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-19T05:19:17Z"}
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-19T04:24:11Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-19T05:19:17Z"}
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-19T04:24:11Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-19T05:19:17Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -83,7 +83,7 @@ const prop = (o) => Object.assign({ id: 'prop-a', state: 'proposed', prompt: 'ad
83
83
  const A = await open(); const p = A.page;
84
84
  ok('0 the sheet opens', !!(await p.evaluate(() => document.querySelector('#shT'))));
85
85
  /* E1 tabs */
86
- await p.click('#shV'); ok('E1 the sheet has a view menu with Read, Edit, Proposals, Edit log and Health, and the open count on Proposals', await p.evaluate(() => [...document.querySelectorAll('#shT [data-sh]')].map((b) => b.textContent.replace(/\s+/g, ' ').trim()).join('|') === 'Read|Edit|Proposals 1|Edit log|Health'));
86
+ await p.click('#shV'); ok('E1 the sheet has a view menu with Read, Edit, Proposals, Edit log, Health and Relations, and the open count on Proposals', await p.evaluate(() => [...document.querySelectorAll('#shT [data-sh]')].map((b) => b.textContent.replace(/\s+/g, ' ').trim()).join('|') === 'Read|Edit|Proposals 1|Edit log|Health|Relations'));
87
87
  ok('E1 the Read outline marks only a heading an open proposal names', await p.evaluate(() => { const b = [...document.querySelectorAll('.dso button')]; return b.length === 0 || b.every((x) => !x.querySelector('i') === !/Goal|Summary/.test(x.textContent)); }));
88
88
  ok('E7 the footnote no longer says read-only', !/Read-only/.test(await txt(p, '#oMain .xn')) && /only when you press Save or Accept/.test(await txt(p, '#oMain .xn')));
89
89
 
@@ -46,11 +46,15 @@ const HEALTH = { ok: true, path: 'planning/prd/self-serve-v2-prd.md', health: {
46
46
  const open = async ({ w = 1280, h = 900, theme = 'light', model = mk(), answers = null, qs = '?id=self-serve-v2&ws=w1&board=w1' } = {}) => {
47
47
  const ctx = await browser.newContext({ viewport: { width: w, height: h } });
48
48
  const page = await ctx.newPage();
49
- let current = model, calls = 0; const errors = [], posts = [], gets = []; let answer = { status: 200, body: { ok: true } }; let thread = { ok: true, turns: [], working: false };
49
+ let copies = []; let current = model, calls = 0; const errors = [], posts = [], gets = []; let answer = { status: 200, body: { ok: true } }; let thread = { ok: true, turns: [], working: false };
50
50
  page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
51
51
  await page.route('**/api/initiative-premium*', (r) => { calls++; if (answers) { const a = answers(calls); return r.fulfill({ status: a.status, contentType: 'application/json', body: JSON.stringify(a.body) }); } return r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, state: 'ready', model: current, as_of: F.NOW }) }); });
52
52
  await page.route('**/api/core-docs/**', (r) => { const rq = r.request(); posts.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}'), headers: rq.headers() }); r.fulfill({ status: answer.status, contentType: 'application/json', body: JSON.stringify(answer.body) }); });
53
- await page.route('**/api/doc-sheet/**', (r) => { const rq = r.request(), u = new URL(rq.url()); (rq.method() === 'GET' ? gets : posts).push({ path: u.pathname, query: u.search, method: rq.method() }); const b = u.pathname.endsWith('/log') ? LOG : u.pathname.endsWith('/at') ? { ok: true, path: LOG.path, rev: 2, text: TEXT } : { ok: false, error: 'not in this test' }; r.fulfill({ contentType: 'application/json', body: JSON.stringify(b) }); });
53
+ await page.route('**/api/doc-sheet/**', (r) => { const rq = r.request(), u = new URL(rq.url()); (rq.method() === 'GET' ? gets : posts).push({ path: u.pathname, query: u.search, method: rq.method() }); const b = u.pathname.endsWith('/log') ? LOG : u.pathname.endsWith('/at') ? { ok: true, path: LOG.path, rev: +u.searchParams.get('rev') || 2, text: u.searchParams.get('rev') === '1' ? TEXT.replace('waits', 'waited') : TEXT } : { ok: false, error: 'not in this test' }; r.fulfill({ contentType: 'application/json', body: JSON.stringify(b) }); });
54
+ await page.route(/\/api\/docs(\?.*)?$/, (r) => { const u = new URL(r.request().url()); gets.push({ path: u.pathname, query: u.search, method: 'GET' }); r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, docs: [{ path: 'planning/prd/self-serve-v2-prd.md', links: copies }] }) }); });
55
+ await page.route('**/api/docs/link', (r) => { const rq = r.request(); const b = JSON.parse(rq.postData() || '{}'); posts.push({ path: '/api/docs/link', body: b, method: 'POST' }); copies = [{ kind: b.kind, target: b.target, title: 'PRD', signal: 'unchecked', url: b.target }]; r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true }) }); });
56
+ await page.route('**/api/docs/check', (r) => { posts.push({ path: '/api/docs/check', body: JSON.parse(r.request().postData() || '{}'), method: 'POST' }); r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, session: 's1' }) }); });
57
+ await page.route('**/api/docs/library*', (r) => { const u = new URL(r.request().url()); gets.push({ path: u.pathname, query: u.search, method: 'GET' }); r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, kinds: ['cites'], files: [{ path: 'planning/prd/self-serve-v2-prd.md', title: 'PRD' }, { path: 'planning/briefs/self-serve-brief.md', title: 'Self-serve brief' }, { path: 'planning/okrs/q3.md', title: 'Activation goal', category: 'goal', node: 'Goal' }, { path: 'planning/evals/self-serve-rubric.md', title: 'Self-serve rubric' }], edges: [[1, 0, 0], [2, 0, 0], [0, 3, 0]] }) }); });
54
58
  await page.route('**/api/boards/tasks/**', (r) => { const rq = r.request(); posts.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}'), headers: rq.headers() }); r.fulfill({ status: answer.status, contentType: 'application/json', body: JSON.stringify(answer.body) }); });
55
59
  await page.route('**/api/doc-health/check', (r) => { posts.push({ path: '/api/doc-health/check', body: JSON.parse(r.request().postData() || '{}'), method: 'POST' }); r.fulfill({ contentType: 'application/json', body: JSON.stringify(HEALTH) }); });
56
60
  await page.route('**/api/briefing-premium/**', (r) => { const rq = r.request(); if (rq.method() === 'GET') return r.fulfill({ contentType: 'application/json', body: JSON.stringify(thread) }); posts.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}'), headers: rq.headers() }); r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true }) }); });
@@ -182,14 +186,34 @@ const HEALTH = { ok: true, path: 'planning/prd/self-serve-v2-prd.md', health: {
182
186
  const nPost0 = A.posts.length;
183
187
  await p.locator('#dmList .dmo[data-doc="prd"]').click(); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && /Self-serve onboarding v2/.test(document.querySelector('#oMain').textContent) && document.querySelector('#oMain .dsbody'))); await sleep(500); await p.click('#oMain [data-ds="meta"]');
184
188
  const sh = await p.evaluate(() => ({ title: document.querySelector('#dTitle').textContent, path: document.querySelector('#oMain [data-ds="meta"]').title, tabs: (() => { document.querySelector('#shV').click(); const t = [...document.querySelectorAll('#shT [data-sh]')].map((b) => b.textContent).join(','); document.querySelector('#shV').click(); return t; })(), fm: [...document.querySelectorAll('#oMain .kv2 span')].map((s) => s.textContent).join('|'), heads: [...document.querySelectorAll('#oMain h3.d2')].map((h) => h.textContent).join('|'), outline: [...document.querySelectorAll('#oMain .dso button')].map((b) => b.textContent).join('|'), pre: [...document.querySelectorAll('#oMain pre')].map((e) => e.textContent).join('|'), li: document.querySelectorAll('#oMain li').length }));
185
- ok('I8 Read shows the file\'s path, its front matter as a grid, its headings, list and code', sh.title === 'PRD' && sh.path === 'planning/prd/self-serve-v2-prd.md' && sh.tabs === 'Read,Edit,Proposals,Edit log,Health' && /type\|PRD\|title\|Self-serve onboarding v2/.test(sh.fm) && sh.heads === 'PRD: Self-serve onboarding v2|Problem|Goal|Requirements' && sh.li === 2 && /R1 a first call/.test(sh.pre), JSON.stringify(sh));
189
+ ok('I8 Read shows the file\'s path, its front matter as a grid, its headings, list and code', sh.title === 'PRD' && sh.path === 'planning/prd/self-serve-v2-prd.md' && sh.tabs === 'Read,Edit,Proposals,Edit log,Health,Relations' && /type\|PRD\|title\|Self-serve onboarding v2/.test(sh.fm) && sh.heads === 'PRD: Self-serve onboarding v2|Problem|Goal|Requirements' && sh.li === 2 && /R1 a first call/.test(sh.pre), JSON.stringify(sh));
186
190
  ok('I8 Read asked for the log and the last revision, by GET, for this path', A.gets.some((g) => g.path === '/api/doc-sheet/log' && /path=planning%2Fprd%2Fself-serve-v2-prd.md/.test(g.query)) && A.gets.some((g) => g.path === '/api/doc-sheet/at' && /rev=2/.test(g.query)));
187
191
  await p.click('#shV'); await p.click('#shT [data-sh="log"]');
188
192
  const lg = await until(() => p.evaluate(() => document.querySelector('#oMain .hsr') && [...document.querySelectorAll('#oMain .hsr')].map((r) => r.textContent.replace(/\s+/g, ' ').trim())));
189
193
  ok('I8 Edit log lists the revisions newest first with their reasons and the other entries', lg && /v2 tightened the goal · pm/.test(lg[0]) && /v1 The file as the sheet first saw it · baseline/.test(lg[1]) && /asked What is missing\?/.test(lg[2]), JSON.stringify(lg));
194
+ await p.click('#oMain [data-lgd="2"]');
195
+ const cmp = await until(() => p.evaluate(() => { const d = document.querySelector('#oMain .lgdf'); return d && d.querySelector('ins') && { ins: d.querySelector('ins').textContent, del: d.querySelector('del') && d.querySelector('del').textContent, btn: document.querySelector('#oMain [data-lgd="2"]').textContent, first: !!document.querySelector('#oMain [data-lgd="1"]') }; }));
196
+ ok('I8 Show change on a revision compares it with the one before: the new words are marked added, the old ones removed, and the first revision has no button', cmp && cmp.ins === 'waits' && cmp.del === 'waited' && cmp.btn === 'Hide change' && cmp.first === false, JSON.stringify(cmp));
197
+ ok('I8 the comparison asked for both revisions by GET, and nothing else', A.gets.filter((g) => g.path === '/api/doc-sheet/at' && /rev=1\b/.test(g.query)).length >= 1 && !A.posts.some((q) => /doc-sheet/.test(q.path) && /log|at/.test(q.path)));
198
+ await p.click('#oMain [data-lgd="2"]');
199
+ ok('I8 Hide change closes it', await p.evaluate(() => !document.querySelector('#oMain .lgdf')));
190
200
  await p.click('#shV'); await p.click('#shT [data-sh="health"]');
191
201
  const hl = await until(() => p.evaluate(() => document.querySelector('#oMain .ckr') && { note: document.querySelector('#oMain .note').textContent, rows: [...document.querySelectorAll('#oMain .ckr')].map((r) => r.className + ':' + r.querySelector('span').textContent) }));
192
202
  ok('I8 Health shows each check as passed, not passed or no input, and says no input is not counted', hl && /1 of 2 checks/.test(hl.note) && hl.rows.join() === 'ckr done:Passed,ckr blocked:Not passed,ckr skipped:No input', JSON.stringify(hl));
203
+ await p.click('#shV'); await p.click('#shT [data-sh="rel"]');
204
+ const rl = await until(() => p.evaluate(() => document.querySelector('#oMain .dsrr') && [...document.querySelectorAll('#oMain .label, #oMain .dsrr')].map((r) => r.textContent.replace(/\s+/g, ' ').trim())));
205
+ ok('I8 Relations lists the sources, the goals and the documents that use it, from the library route', rl && rl.join('|') === 'Sources · 1|Self-serve briefcites|Goals and initiative · 1|Activation goalcites · Goal|Used by · 1|Self-serve rubriccites', JSON.stringify(rl));
206
+ ok('I8 Relations read the library by GET for this workspace and a goal that is a node is listed, not opened', A.gets.some((g) => g.path === '/api/docs/library' && /ws=w1/.test(g.query)) && await p.evaluate(() => document.querySelectorAll('#oMain [data-rel]').length) === 2);
207
+ await p.click('#shV'); await p.click('#shT [data-sh="read"]');
208
+ ok('I8 a document with no copy offers Link a copy in the status line', await p.evaluate(() => /Link a copy/.test(document.querySelector('#oMain .dsm2').textContent)));
209
+ await p.click('#oMain [data-ds="cp"]'); await p.fill('#dsCpUrl', 'notes'); await p.click('[data-ds="cplink"]');
210
+ ok('I8 a link that names no tool is refused on the sheet, and nothing is posted', /Confluence page or Google Doc/.test(await txt('#oMain .dscp [role="alert"]')) && !A.posts.some((x) => x.path === '/api/docs/link'));
211
+ await p.fill('#dsCpUrl', 'https://docs.google.com/document/d/abc/edit'); await p.click('[data-ds="cplink"]');
212
+ await until(() => p.evaluate(() => /Google Doc: not checked/.test(document.querySelector('#oMain .dsm2').textContent)));
213
+ ok('I8 linking posts the path, the tool and the address, and the status line then names the copy', A.posts.some((x) => x.path === '/api/docs/link' && x.body.kind === 'google' && x.body.path === 'planning/prd/self-serve-v2-prd.md' && x.body.ws === 'w1' && /docs\.google\.com/.test(x.body.target)));
214
+ await p.click('[data-ds="cpcheck"]');
215
+ ok('I8 Check now posts the workspace only and the button reads Checking', A.posts.some((x) => x.path === '/api/docs/check' && Object.keys(x.body).join() === 'ws') && await until(() => p.evaluate(() => /Checking/.test(document.querySelector('[data-ds="cpcheck"]').textContent))));
216
+ await p.click('#oMain [data-ds="cp"]');
193
217
  ok('I8 the health check posts the path and the workspace only', A.posts.some((x) => x.path === '/api/doc-health/check' && Object.keys(x.body).sort().join() === 'path,ws' && x.body.ws === 'w1'));
194
218
  ok('I8 the sheet wrote nothing: no edit, propose, accept, reject, why, mark or ask post went out', !A.posts.slice(nPost0).some((x) => /doc-sheet/.test(x.path)) && !A.posts.some((x) => /^\/api\/doc-sheet\/(edit|propose|accept|reject|why|mark-current|ask)/.test(x.path)));
195
219
  ok('I8 the sheet says the file changes only on Save or Accept', /only when you press Save or Accept/.test(await txt('#oMain .xn')));
@@ -248,7 +248,7 @@ The initiative page is at `/premium-initiative.html?id=<initiative>`. A click on
248
248
  - **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.
249
249
  - **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.
250
250
  - **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.
251
- - **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.
251
+ - **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; **Show change** on a revision marks the words it added and removed against the revision before), **Health** (the document-health checks; a check with no input is not counted) and **Relations** (the documents it draws on, its goals, and the documents that use it, from the document library; a related file opens in the same sheet, and a goal or a missing file is listed but cannot be opened). The status line also names each **copy in another tool** (a Confluence page or Google Doc, with its state: in step, behind, both changed and so on), or offers **Link a copy**. Pressing it opens a panel with each copy's state, a link to open it, **Check now** (one agent session reads the copies with your connectors) and a box to paste a link. The sheet never writes to a copy; updating one is in the console. 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.
252
252
 
253
253
  Not drawn, because PMOS holds no record for them: the mockup's demo tasks, its Jira data, and the owner "Agents" on a requirement.
254
254
 
@@ -287,7 +287,7 @@ The premium Briefing is the default page: `/` and `/index.html` open it. The con
287
287
 
288
288
  ## The dialog on a phone and the document sheet's views
289
289
 
290
- On a phone or tablet (under 1000 px) every dialog opens on **Detail**. A **Detail / Conversation** switch sits under the title, and **Open it** at the foot of Detail brings the conversation when an action waits there. The header holds only **Close**. A document sheet picks its view (**Read**, **Edit**, **Proposals**, **Edit log**, **Health**) from one button with a menu.
290
+ On a phone or tablet (under 1000 px) every dialog opens on **Detail**. A **Detail / Conversation** switch sits under the title, and **Open it** at the foot of Detail brings the conversation when an action waits there. The header holds only **Close**. A document sheet picks its view (**Read**, **Edit**, **Proposals**, **Edit log**, **Health**, **Relations**) from one button with a menu.
291
291
 
292
292
  A dialog's detail panel opens with the record's path, its heading and one lead line. A decision's evidence reads as a list. A measure's dialog draws the measure's chart above its facts and readings.
293
293
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.293.0",
3
+ "version": "0.295.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.293.0",
9
+ "version": "0.295.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.293.0",
3
+ "version": "0.295.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -145,3 +145,64 @@ export function sectionAttribution(revs, texts) {
145
145
  });
146
146
  return out;
147
147
  }
148
+
149
+ /** What surrounds one document in a /api/docs/library answer (the console reader's hoodOf and graph columns, as three plain lists): the documents it draws on
150
+ * (sources), its initiative and goals, and the documents that use it. An edge is "in step" unless the answer says otherwise, or an older source is cited by a newer
151
+ * document. `open` is set only for a real file; a node or a missing file is listed and cannot be opened. */
152
+ export function relationsOf(lib, path, iniName) {
153
+ const none = { sources: [], goals: [], used: [], count: 0 };
154
+ if (!lib || !Array.isArray(lib.files)) return none;
155
+ const me = lib.files.findIndex((f) => f.path === path);
156
+ if (me < 0) return none;
157
+ const kinds = lib.kinds || [], files = lib.files;
158
+ const st = (a, b, k, s) => s || (['link', 'cites', 'anchor'].includes(kinds[k]) && a.date && b.date && a.date > b.date ? 'drift' : 'ok');
159
+ const isGoal = (f) => f.category === 'goal' || f.node === 'Goal';
160
+ const node = (f, kind, s) => ({ name: f.title || f.path, sub: [kind, f.node || ''].filter((x, i, a) => x && a.indexOf(x) === i).join(' · '), st: s, path: f.path, open: !f.node && f.st !== 'node' && f.st !== 'missing' });
161
+ const src = [], out = [];
162
+ for (const [a, b, k, s] of lib.edges || []) {
163
+ if (b === me && a !== me && files[a]) src.push(node(files[a], kinds[k] || '', st(files[a], files[me], k, s)));
164
+ else if (a === me && b !== me && files[b]) out.push(node(files[b], kinds[k] || '', st(files[me], files[b], k, s)));
165
+ }
166
+ const goals = src.filter((n) => isGoal(files.find((f) => f.path === n.path) || {}));
167
+ const sources = src.filter((n) => !goals.includes(n));
168
+ if (iniName) goals.unshift({ name: iniName, sub: 'initiative', st: 'ok', path: '', open: false });
169
+ return { sources, goals, used: out, count: sources.length + goals.filter((n) => n.path).length + out.length };
170
+ }
171
+
172
+ /** Which tool a pasted address names (the server checks it again): 'confluence', 'google', 'google-slides', 'google-sheets' or null. The console reader's rule. */
173
+ export function copyKindOf(target) {
174
+ const t = String(target || '');
175
+ if (/atlassian|confluence|\/wiki\/|pageId=/i.test(t)) return 'confluence';
176
+ if (/docs\.google\.com\/presentation|slides\.google|\/presentation\/d\//i.test(t)) return 'google-slides';
177
+ if (/docs\.google\.com\/spreadsheets|sheets\.google|\/spreadsheets\/d\//i.test(t)) return 'google-sheets';
178
+ if (/google|docs\.|drive\./i.test(t)) return 'google';
179
+ return null;
180
+ }
181
+ const COPY_STATE = {
182
+ same: ['In step', 'ok', 'Both have the same text.'], ahead: ['PMOS is ahead', 'warn', 'PMOS has changes the copy does not have.'], behind: ['Behind', 'warn', 'The copy has changes PMOS does not have.'],
183
+ diverged: ['Both changed', 'warn', 'Both changed since they last matched.'], unchecked: ['Not checked', '', 'No check has read this copy yet.'], unreadable: ['Cannot open', 'warn', 'The last check could not open the copy.'],
184
+ none: ['Not created', '', 'No copy exists yet.'], 'missing-remote': ['Not found', 'warn', 'The copy is not there any more.'], 'missing-repo': ['Not in PMOS', 'warn', 'This file is not in the repository any more.'] };
185
+ const COPY_KIND = { google: 'Google Doc', 'google-slides': 'Google Slides', 'google-sheets': 'Google Sheets', confluence: 'Confluence' };
186
+ /** One link of GET /api/docs as the sheet shows it: the tool's name, the state in words, a tone for the chip, and the sentence under it. */
187
+ export function copyView(l) {
188
+ const g = l.syncing ? ['Updating', 'warn', 'A session is updating this copy.'] : COPY_STATE[l.signal] || COPY_STATE.unchecked;
189
+ const tool = COPY_KIND[l.kind] || l.label || String(l.kind || 'Copy');
190
+ return { tool, state: g[0], tone: g[1], words: l.words || g[2], title: l.title || tool, url: l.url || '', target: l.target || '', checked: l.checked_at || '' };
191
+ }
192
+
193
+ /** The word diff of two texts as HTML: <ins> for added words, <del> for removed ones, whitespace kept. A text pair too large to compare shows the whole change. */
194
+ export function revDiffHtml(before, after) {
195
+ const x = String(before || '').split(/(\s+)/).filter((t) => t !== ''), y = String(after || '').split(/(\s+)/).filter((t) => t !== '');
196
+ const n = x.length, m = y.length, out = [];
197
+ const push = (op, t) => { const l = out[out.length - 1]; if (l && l.op === op) l.t += t; else out.push({ op, t }); };
198
+ if (n * m > 600000) { if (before) push('del', before); if (after) push('add', after); } else {
199
+ const L = []; for (let i = 0; i <= n; i++) L.push(new Array(m + 1).fill(0));
200
+ for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) L[i][j] = x[i] === y[j] ? L[i + 1][j + 1] + 1 : Math.max(L[i + 1][j], L[i][j + 1]);
201
+ let i = 0, j = 0;
202
+ while (i < n && j < m) { if (x[i] === y[j]) { push('same', x[i]); i++; j++; } else if (L[i + 1][j] >= L[i][j + 1]) push('del', x[i++]); else push('add', y[j++]); }
203
+ while (i < n) push('del', x[i++]);
204
+ while (j < m) push('add', y[j++]);
205
+ }
206
+ const changed = out.filter((o) => o.op !== 'same').length;
207
+ return { changed, html: out.map((o) => o.op === 'add' ? `<ins>${esc(o.t)}</ins>` : o.op === 'del' ? `<del>${esc(o.t)}</del>` : esc(o.t)).join('') };
208
+ }
@@ -3,14 +3,16 @@
3
3
  * /api/doc-sheet routes and POST /api/doc-health/check. A draft has Issue it (POST /api/core-docs/issue) and, where the page asks for it, Draft it again.
4
4
  * The caller gives the page's own facts: { ws(), scope(), rows(), reload(), noteKey(d), sub(), again }. */
5
5
  import { pmPost } from './http.js';
6
- import { proposalsModel, editBody, acceptBody, rejectBody, askBody, askLine, issueBody, mdHtml, sectionAttribution } from './premium-doc-edit.js';
6
+ import { proposalsModel, relationsOf, copyKindOf, copyView, editBody, acceptBody, rejectBody, askBody, askLine, issueBody, mdHtml, sectionAttribution, revDiffHtml } from './premium-doc-edit.js';
7
7
  import { $, $$, esc, openDlg, closeDlg, toast, loadThread, logHtml, turnA, ptx, kv, CHECK, CHEV, AI } from './premium-shell.js';
8
8
 
9
9
  const when = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); if (!m) return ''; return +m[3] + ' ' + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][+m[2] - 1]; };
10
10
 
11
11
  export function mountDocSheet(ctx) {
12
12
  let sheet = null; // { d, tab, text, log, health, props, draft, why, ask, askText, picked, busy, msg, err }
13
- const TABS = [['read', 'Read'], ['edit', 'Edit'], ['props', 'Proposals'], ['log', 'Edit log'], ['health', 'Health']];
13
+ const prevRev = (R, r) => { const i = R.indexOf(r); return i >= 0 && i + 1 < R.length ? R[i + 1].rev : null; }; // R is newest first
14
+ const cmpHtml = (c) => (c === 'busy' ? 'Comparing.' : c.err ? esc(c.err) : c.changed ? c.html : 'No change in the words.');
15
+ const TABS = [['read', 'Read'], ['edit', 'Edit'], ['props', 'Proposals'], ['log', 'Edit log'], ['health', 'Health'], ['rel', 'Relations']];
14
16
  const wsq = () => (ctx.ws() ? '&ws=' + encodeURIComponent(ctx.ws()) : '');
15
17
  const propsM = (s) => proposalsModel(s.props || []);
16
18
  /** The bar above a draft (core document Issue, initiative premium-core-doc-issue). The words are fixed; the state is the row's own. */
@@ -41,13 +43,16 @@ export function mountDocSheet(ctx) {
41
43
  }
42
44
  function sheetPane() {
43
45
  const s = sheet, d = s.d;
44
- const cnt = (k) => (k === 'props' && s.props && propsM(s).count ? ` <em>${propsM(s).count}</em>` : '');
46
+ const rels = s.lib && !s.lib.err ? relationsOf(s.lib, s.d.path, s.d.iniName) : null;
47
+ const cnt = (k) => (k === 'props' && s.props && propsM(s).count ? ` <em>${propsM(s).count}</em>` : k === 'rel' && rels && rels.count ? ` <em>${rels.count}</em>` : '');
45
48
  const EYE = '<svg class="i" viewBox="0 0 24 24"><path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/></svg>';
46
49
  const revs = (s.log && s.log.revisions) || [], last = revs[revs.length - 1], m0 = s.md || (s.text != null ? (s.md = mdHtml(s.text, { attr: s.attr })) : null);
47
50
  const menu = `<div class="dsvr" id="shT"><span class="dsvw"><button type="button" class="dsvb" id="shV" aria-haspopup="menu" aria-expanded="${!!s.vm}">${EYE}${esc(TABS.find((t) => t[0] === s.tab)[1])}${cnt(s.tab)}${CHEV}</button>${s.vm ? `<div class="dsmn" role="menu" aria-label="Document views">${TABS.map(([k, n]) => `<button type="button" role="menuitem" data-sh="${k}" aria-current="${s.tab === k}">${n}${cnt(k)}${s.tab === k ? CHECK : ''}</button>`).join('')}</div>` : ''}</span>${s.tab === 'read' && m0 && m0.outline.length > 2 ? `<button type="button" class="dsvb ol" data-ds="olt" aria-pressed="${!s.olHide}">${s.olHide ? 'Show the outline' : 'Hide the outline'}</button>` : ''}</div>`;
48
51
  const chk = s.health && s.health.total ? `<button type="button" class="chp lk ${s.health.passed === s.health.total ? 'ok' : 'warn'}" data-sh="health"><i></i>${s.health.passed} of ${s.health.total} checks</button>` : '';
52
+ const cps = (s.copies || []).map(copyView);
53
+ const cpc = s.copies == null ? '' : cps.length ? cps.map((c) => `<button type="button" class="chp lk ${c.tone}" data-ds="cp" aria-expanded="${!!s.cp}" title="${esc(c.words)}"><i></i>${esc(c.tool)}: ${esc(c.state.toLowerCase())}</button>`).join('') : `<button type="button" class="chp lk" data-ds="cp" aria-expanded="${!!s.cp}"><i></i>Link a copy</button>`;
49
54
  const file = String(d.path).split('/').pop();
50
- const head = `<div class="dsm2"><span class="chp ${d.st === 'ok' ? 'ok' : d.st === 'draft' ? 'warn' : ''}"><i></i>${esc(d.state)}</span>${revs.length ? `<span class="chp mono">v${revs.length}</span>` : ''}${chk}<button type="button" class="chp lk" data-ds="meta" aria-expanded="${!!s.meta}" title="${esc(d.path)}">${esc(file)}</button>${last ? `<span class="chp"><span>Last change: <b>${esc(whoOf(last))}</b>${last.at ? ', ' + esc(when(last.at)) : ''}</span></span>` : ''}${d.when && !last ? `<span class="chp">updated ${esc(d.when)}</span>` : ''}</div>${s.meta ? `<div class="dsmeta"><p class="dpath">${esc(d.path)}</p>${m0 && m0.fm.length ? kv(m0.fm) : '<p class="note">The file has no front matter.</p>'}</div>` : ''}`;
55
+ const head = `<div class="dsm2"><span class="chp ${d.st === 'ok' ? 'ok' : d.st === 'draft' ? 'warn' : ''}"><i></i>${esc(d.state)}</span>${revs.length ? `<span class="chp mono">v${revs.length}</span>` : ''}${chk}${cpc}<button type="button" class="chp lk" data-ds="meta" aria-expanded="${!!s.meta}" title="${esc(d.path)}">${esc(file)}</button>${last ? `<span class="chp"><span>Last change: <b>${esc(whoOf(last))}</b>${last.at ? ', ' + esc(when(last.at)) : ''}</span></span>` : ''}${d.when && !last ? `<span class="chp">updated ${esc(d.when)}</span>` : ''}</div>${s.cp ? copiesHtml(s, cps) : ''}${s.meta ? `<div class="dsmeta"><p class="dpath">${esc(d.path)}</p>${m0 && m0.fm.length ? kv(m0.fm) : '<p class="note">The file has no front matter.</p>'}</div>` : ''}`;
51
56
  let body = '';
52
57
  if (s.err) body = `<p class="empty3 plain">${esc(s.err)}</p>`;
53
58
  else if (s.tab === 'read') {
@@ -81,15 +86,32 @@ export function mountDocSheet(ctx) {
81
86
  if (!s.log) body = '<p class="empty3 plain">Reading the log.</p>';
82
87
  else {
83
88
  const R = (s.log.revisions || []).slice().reverse(), E = (s.log.events || []).slice().reverse();
84
- body = (R.length ? `<div class="evl">${R.map((r) => `<div class="hsr"><time>${esc(when(r.at))}</time><span><b>v${esc(r.rev)}</b> ${esc(r.why || (r.by === 'baseline' ? 'The file as the sheet first saw it' : 'No reason recorded'))}${r.by ? ' · ' + esc(r.by) : ''}</span></div>`).join('')}</div>` : '<p class="mut">No revision is recorded.</p>')
89
+ body = (R.length ? `<div class="evl">${R.map((r) => `<div class="hsr"><time>${esc(when(r.at))}</time><span><b>v${esc(r.rev)}</b> ${esc(r.why || (r.by === 'baseline' ? 'The file as the sheet first saw it' : 'No reason recorded'))}${r.by ? ' · ' + esc(r.by) : ''}</span>${prevRev(R, r) == null ? '' : `<button type="button" class="lk" data-lgd="${esc(r.rev)}" aria-expanded="${s.cmp && s.cmp[r.rev] ? 'true' : 'false'}">${s.cmp && s.cmp[r.rev] ? 'Hide change' : 'Show change'}</button>`}${s.cmp && s.cmp[r.rev] ? `<div class="dsdf lgdf">${cmpHtml(s.cmp[r.rev])}</div>` : ''}</div>`).join('')}</div>` : '<p class="mut">No revision is recorded.</p>')
85
90
  + (E.length ? `<p class="label" style="margin:18px 0 8px">Other entries</p><div class="evl">${E.map((e) => `<div class="hsr"><time>${esc(when(e.at))}</time><span><b>${esc(e.kind)}</b> ${esc(e.prompt || e.why || '')}</span></div>`).join('')}</div>` : '');
86
91
  }
87
92
  } else if (s.tab === 'health') {
88
93
  if (!s.health) body = '<p class="empty3 plain">Checking the document.</p>';
89
94
  else body = `<p class="note" style="margin:0 0 10px">${s.health.passed} of ${s.health.total} checks that had the input they need passed. A check with no input is not counted.</p><div class="ckl">${s.health.checks.map((c) => `<div class="ckr ${c.pass === true ? 'done' : c.pass === false ? 'blocked' : 'skipped'}"><i></i><b>${esc(c.id)}</b><span>${c.pass === true ? 'Passed' : c.pass === false ? 'Not passed' : 'No input'}</span><small>${esc(c.reason || '')}</small></div>`).join('')}</div>`;
95
+ } else if (s.tab === 'rel') {
96
+ body = relHtml(s, rels);
90
97
  }
91
98
  return `<article class="paper doc">${head}${menu}<div id="shBody">${body}</div><p class="xn">Every change is kept in the Edit log with its reason. The file changes only when you press Save or Accept.</p></article>`;
92
99
  }
100
+ /** Copies in other tools: each linked copy with its state, a link to open it, Check now, and a box to link another. The sheet never writes to the copy; updating one stays in the console. */
101
+ function copiesHtml(s, cps) {
102
+ const rows = cps.map((c) => `<div class="dscr"><div><b>${esc(c.title)}</b><span class="chp ${c.tone}">${esc(c.state)}</span></div><small>${esc([c.tool, c.target].filter(Boolean).join(' · '))}</small><p class="note" style="margin:4px 0 0">${esc(c.words)}${c.checked ? ' Last checked ' + esc(when(c.checked)) + '.' : ' Not checked yet.'}</p>${c.url ? `<a class="lk" href="${esc(c.url)}" target="_blank" rel="noopener">Open in ${esc(c.tool)}</a>` : ''}</div>`).join('');
103
+ return `<div class="dscp" data-copies><p class="label">Copies in other tools</p>${rows || '<p class="note">This document has no copy in Confluence or Google Docs yet. Link one to see whether it is in step.</p>'}`
104
+ + `<div class="dsrow"><input id="dsCpUrl" class="dsy" type="text" placeholder="Paste a Confluence page or Google Doc link" aria-label="Address of the copy" value="${esc(s.cpUrl || '')}"><button class="dmcta dark" data-ds="cplink">Link</button>${cps.length ? `<button class="dmcta alt" data-ds="cpcheck"${s.checkRun ? ' disabled' : ''}>${s.checkRun ? 'Checking' : 'Check now'}</button>` : ''}</div>`
105
+ + `${s.cpMsg ? `<p class="note" role="alert" style="margin:6px 0 0;color:var(--ember-ink)">${esc(s.cpMsg)}</p>` : ''}<p class="note" style="margin:8px 0 0">PMOS never writes to a copy from this sheet. Check now starts one agent session that reads the copies with your connectors. Updating a copy is in the console.</p></div>`;
106
+ }
107
+ /** Relations: three plain lists from the document library. A related file opens in this same sheet. */
108
+ function relHtml(s, R) {
109
+ if (s.lib === undefined || (s.lib === null && !s.err)) return '<p class="empty3 plain">Reading the document graph.</p>';
110
+ if (s.lib && s.lib.err) return `<p class="empty3 plain">${esc(s.lib.err)}</p>`;
111
+ const ST = { drift: 'Out of step', conflict: 'Conflict', missing: 'Missing', ahead: 'PMOS ahead' };
112
+ const grp = (h, list) => (list.length ? `<p class="label" style="margin:14px 0 8px">${h} · ${list.length}</p><div class="dsrel">${list.map((n) => `<div class="dsrr">${n.open ? `<button type="button" data-rel="${esc(n.path)}" data-rt="${esc(n.name)}" title="Open ${esc(n.name)}"><b>${esc(n.name)}</b><small>${esc(n.sub)}</small></button>` : `<span><b>${esc(n.name)}</b><small>${esc(n.sub)}</small></span>`}${n.st && n.st !== 'ok' ? `<span class="chp ${n.st === 'drift' ? 'warn' : ''}">${esc(ST[n.st] || n.st)}</span>` : ''}</div>`).join('')}</div>` : '');
113
+ return R && (R.sources.length || R.goals.length || R.used.length) ? grp('Sources', R.sources) + grp('Goals and initiative', R.goals) + grp('Used by', R.used) : '<p class="mut">No relation is recorded for this document.</p>';
114
+ }
93
115
  function propHtml(s, p) {
94
116
  const picked = s.picked && s.picked[p.id], on = (n) => (picked ? picked.includes(n) : true);
95
117
  const secs = p.sections.map((x) => `<div class="dsdf">${p.sections.length > 1 && !x.stale ? `<label><input type="checkbox" data-pk="${esc(p.id)}" value="${esc(x.name)}"${on(x.name) ? ' checked' : ''}> ` : ''}<b>${esc(x.name)}</b>${p.sections.length > 1 && !x.stale ? '</label>' : ''} ${x.stale ? '<span class="dst2">Changed since this was proposed</span>' : `<ins>+ ${esc(x.add)}</ins>`}</div>`).join('');
@@ -97,6 +119,18 @@ export function mountDocSheet(ctx) {
97
119
  }
98
120
  function drawSheet() { $('#oMain').innerHTML = sheetPane(); }
99
121
  async function getJson(url, init) { try { const r = await fetch(url, Object.assign({ credentials: 'same-origin' }, init || {})); return await r.json(); } catch { return null; } }
122
+ async function toggleCmp(rev) {
123
+ const s = sheet; s.cmp = s.cmp || {};
124
+ if (s.cmp[rev]) { delete s.cmp[rev]; drawSheet(); return; }
125
+ const R = ((s.log && s.log.revisions) || []).slice().reverse(), r = R.find((x) => String(x.rev) === String(rev)), pv = r && prevRev(R, r);
126
+ if (pv == null) return;
127
+ s.cmp[rev] = 'busy'; drawSheet();
128
+ const p = encodeURIComponent(s.d.path), ws = ctx.ws() ? '&ws=' + encodeURIComponent(ctx.ws()) : '';
129
+ const [a, b] = await Promise.all([getJson('/api/doc-sheet/at?path=' + p + '&rev=' + pv + ws), getJson('/api/doc-sheet/at?path=' + p + '&rev=' + rev + ws)]);
130
+ if (sheet !== s || !s.cmp || !s.cmp[rev]) return;
131
+ s.cmp[rev] = a && a.ok && b && b.ok ? revDiffHtml(a.text, b.text) : { err: (b && b.error) || (a && a.error) || 'The change could not be read.' };
132
+ drawSheet();
133
+ }
100
134
  async function loadTab(tab) {
101
135
  const s = sheet, p = encodeURIComponent(s.d.path), ws = ctx.ws() ? '&ws=' + encodeURIComponent(ctx.ws()) : '';
102
136
  if (tab !== 'props' && tab !== 'log' && tab !== 'health' && !s.props) {
@@ -124,6 +158,11 @@ export function mountDocSheet(ctx) {
124
158
  if (sheet !== s) return;
125
159
  if (!h || h.ok === false) s.err = (h && h.error) || 'The health check could not run.'; else s.health = h.health;
126
160
  }
161
+ if (tab === 'rel' && s.lib === undefined) {
162
+ s.lib = null; const j = await getJson('/api/docs/library?' + wsq().slice(1));
163
+ if (sheet !== s) return;
164
+ s.lib = j && j.ok ? j : { err: (j && j.error) || 'The document graph could not be read.' };
165
+ }
127
166
  if (sheet === s && s.tab === tab) drawSheet();
128
167
  if (tab === 'read' && s.text != null) loadAttr();
129
168
  }
@@ -133,16 +172,28 @@ export function mountDocSheet(ctx) {
133
172
  if (sheet !== s || !h || h.ok === false || !h.health) return;
134
173
  s.health = h.health; if (s.tab === 'read') drawSheet();
135
174
  }
175
+ /** The copies of this document in other tools (GET /api/docs: the links and their signals), read when the sheet opens and after a link or a check. */
176
+ async function loadCopies() {
177
+ const s = sheet; if (!s) return;
178
+ const j = await getJson('/api/docs?' + wsq().slice(1)); if (sheet !== s) return;
179
+ if (!j || j.ok === false) { s.copies = s.copies || []; s.cpMsg = (j && j.error) || 'The copies could not be read.'; }
180
+ else { const d = (j.docs || []).find((x) => x.path === s.d.path); s.copies = d ? d.links || [] : []; s.checkRun = j.session || j.open || null; }
181
+ if (s.tab === 'read' || s.cp) drawSheet();
182
+ }
136
183
  function openSheet(d) {
137
184
  if (!d || !d.path) return;
138
185
  sheet = { d, tab: 'read', text: null, log: null, health: null, props: null, draft: null, why: '', ask: null, askText: '', picked: {}, busy: false, msg: '', err: null };
139
186
  const key = ctx.noteKey(d), 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 change the file, with Save or Accept.';
140
187
  openDlg({ eye: 'Document · real data', title: d.title, sub: ctx.sub(), say, stream: turnA(logHtml({ logTitle: 'Read from the repository', log: ['Found the file ' + d.path, 'Read its revisions from the document sheet', 'Left the file as it is'] })) + turnA(ptx(say)), noteKey: key, pane: '', label: 'Document' });
141
- drawSheet(); loadThread(key); loadTab('read'); loadChip();
188
+ drawSheet(); loadThread(key); loadTab('read'); loadChip(); loadCopies();
142
189
  }
143
190
  $('#oMain').addEventListener('click', (e) => {
144
191
  if (sheet && sheet.vm && !e.target.closest('.dsvw')) { sheet.vm = false; drawSheet(); }
145
192
  if (sheet && e.target.closest('#shV')) { keepDraft(); sheet.vm = !sheet.vm; drawSheet(); return; }
193
+ const lg = e.target.closest('[data-lgd]');
194
+ if (lg && sheet) { toggleCmp(lg.dataset.lgd); return; }
195
+ const rl = e.target.closest('[data-rel]');
196
+ if (rl && sheet) { openSheet({ path: rl.dataset.rel, title: rl.dataset.rt, st: 'ok', state: 'Current', key: 'rel:' + rl.dataset.rel }); return; }
146
197
  const t = e.target.closest('[data-sh]');
147
198
  if (t && sheet) { keepDraft(); sheet.vm = false; sheet.tab = t.dataset.sh; sheet.err = null; sheet.msg = ''; drawSheet(); loadTab(sheet.tab); return; }
148
199
  const b = e.target.closest('[data-ds]'); if (b && sheet) { sheetPress(b.dataset.ds); return; }
@@ -156,12 +207,13 @@ export function mountDocSheet(ctx) {
156
207
  else if (e.target.id === 'dsAsk') sheet.askText = e.target.value;
157
208
  else if (e.target.id === 'dsOlq') { sheet.olq = e.target.value; const it = $('#dsOlItems'); if (it && sheet.md) it.innerHTML = olItems(sheet, sheet.md); }
158
209
  else if (e.target.id === 'dsRj') sheet.rejWhy = e.target.value;
210
+ else if (e.target.id === 'dsCpUrl') sheet.cpUrl = e.target.value;
159
211
  });
160
212
  function keepDraft() { if (!sheet) return; const ed = $('#dsEd'), w = $('#dsWhy'), a = $('#dsAsk'), rj = $('#dsRj'); if (rj) sheet.rejWhy = rj.value; if (ed) sheet.draft = ed.value; if (w) sheet.why = w.value; if (a) sheet.askText = a.value; }
161
213
  /* the sheet's presses: each posts to one existing /api/doc-sheet route (ws in the query, as the routes read it) and then reads the routes again */
162
214
  const dsPost = (route, body) => pmPost('/api/doc-sheet/' + route + (ctx.ws() ? '?ws=' + encodeURIComponent(ctx.ws()) : ''), body);
163
215
  async function reloadSheet(s) {
164
- s.text = null; s.md = null; s.attr = null; s.log = null; s.health = null; s.props = null; s.draft = null; s.why = ''; s.rejecting = null;
216
+ s.text = null; s.md = null; s.attr = null; s.cmp = null; s.log = null; s.health = null; s.props = null; s.draft = null; s.why = ''; s.rejecting = null;
165
217
  await loadTab(s.tab);
166
218
  if (sheet === s) { s.busy = false; drawSheet(); }
167
219
  }
@@ -169,6 +221,21 @@ export function mountDocSheet(ctx) {
169
221
  const s = sheet; keepDraft();
170
222
  const fail = (m) => { s.busy = false; s.msg = m; drawSheet(); };
171
223
  if (act === 'meta') { s.meta = !s.meta; drawSheet(); return; }
224
+ if (act === 'cp') { s.cp = !s.cp; s.cpMsg = ''; drawSheet(); return; }
225
+ if (act === 'cplink') {
226
+ const t = String(s.cpUrl || '').trim(), kind = copyKindOf(t);
227
+ if (!kind) { s.cpMsg = 'Paste a Confluence page or Google Doc link.'; drawSheet(); const f = $('#dsCpUrl'); if (f) f.focus(); return; }
228
+ const r = await pmPost('/api/docs/link', { ws: ctx.ws(), path: s.d.path, kind, target: t }).catch(() => null); if (sheet !== s) return;
229
+ if (!r || r.ok !== true) { s.cpMsg = (r && r.error) || 'The copy was not linked.'; drawSheet(); return; }
230
+ s.cpUrl = ''; s.cpMsg = ''; toast('Linked the copy. Check now reads it.'); await loadCopies(); return;
231
+ }
232
+ if (act === 'cpcheck') {
233
+ const r = await pmPost('/api/docs/check', { ws: ctx.ws() }).catch(() => null); if (sheet !== s) return;
234
+ if (!r || r.ok !== true) { s.cpMsg = (r && r.error) || 'The check did not start.'; drawSheet(); return; }
235
+ s.checkRun = { id: r.session }; s.cpMsg = ''; drawSheet();
236
+ for (let i = 0; i < 120 && sheet === s && s.checkRun; i++) { await new Promise((ok) => setTimeout(ok, 5000)); await loadCopies(); }
237
+ return;
238
+ }
172
239
  if (act === 'olt') { s.olHide = !s.olHide; drawSheet(); return; }
173
240
  if (act === 'rejno') { s.rejecting = null; s.msg = ''; drawSheet(); return; }
174
241
  if (act === 'discard') { s.draft = null; s.why = ''; s.msg = ''; drawSheet(); return; }
@@ -1896,6 +1896,12 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
1896
1896
  .dsbody .dsat i{width:18px;height:18px;border-radius:50%;background:var(--well);display:grid;place-items:center;font:600 10px var(--mono);font-style:normal;color:var(--ink-2)}
1897
1897
  .rdbar .rdsp{margin-left:auto;display:flex;gap:8px;flex-wrap:wrap}
1898
1898
  .rdbar .dsvw:last-child .dsmn,.rdbar .rdsp .dsmn{left:auto;right:0}
1899
+ .dsrel{display:grid;gap:6px}
1900
+ .dsrr{display:flex;align-items:center;gap:10px;justify-content:space-between;padding:6px 10px;border-radius:10px;background:var(--well)}
1901
+ .dsrr button,.dsrr>span:first-child{display:grid;gap:2px;text-align:left;min-height:44px;align-content:center;color:var(--ink)}
1902
+ .dsrr button:hover b{text-decoration:underline}
1903
+ .dsrr b{font-weight:600;font-size:14px}
1904
+ .dsrr small{font:12px var(--mono);color:var(--ink-3)}
1899
1905
 
1900
1906
  .frl{list-style:none;margin:0 0 12px;padding:0}.frs{display:grid;grid-template-columns:30px minmax(0,1fr) auto;gap:10px;align-items:center;width:100%;min-height:44px;padding:6px 4px;text-align:left;border-top:1px solid var(--hair);font-size:14px}
1901
1907
  .frl li:first-child .frs{border-top:0}.frs i{font:600 12px var(--mono);font-style:normal;width:26px;height:26px;border-radius:50%;display:grid;place-items:center;background:var(--well);color:var(--ink-2)}.frs b{font-weight:650}.frs:disabled{opacity:.5}
@@ -1912,3 +1918,11 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
1912
1918
  .agpa{display:flex;gap:6px}
1913
1919
  .xlab{margin:12px 0 6px;font-size:.78rem;color:var(--ink-3)}
1914
1920
  .xco .xwarn{color:var(--ember-ink)}
1921
+ .dscp{display:grid;gap:8px;margin:0 0 12px;padding:12px 14px;border-radius:12px;background:var(--well)}
1922
+ .dscr{display:grid;gap:2px;padding:8px 0;border-top:1px solid var(--hair)}
1923
+ .dscr:first-of-type{border-top:0}
1924
+ .dscr>div:first-child{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
1925
+ .dscr small{font:12px var(--mono);color:var(--ink-3);overflow-wrap:anywhere}
1926
+ .dscr .lk{justify-self:start;min-height:44px;display:inline-flex;align-items:center}
1927
+ .lgdf{margin-top:6px;white-space:pre-wrap;overflow-wrap:anywhere}.lgdf del{color:var(--bad);text-decoration:line-through}
1928
+ .evl .hsr .lk{grid-column:2;justify-self:start;min-height:44px;display:inline-flex;align-items:center}.evl .hsr .dsdf{grid-column:2}