create-pmos 0.286.0 → 0.288.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.286.0",
3
+ "version": "0.288.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@08f8f33
1
+ kernel-source: pmos@12d8962
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-19T03:07:18Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-19T03:25:02Z"}
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-19T03:07:18Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-19T03:25:02Z"}
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-19T03:07:18Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-19T03:25:02Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -180,8 +180,8 @@ const HEALTH = { ok: true, path: 'planning/prd/self-serve-v2-prd.md', health: {
180
180
 
181
181
  /* I8 the document sheet */
182
182
  const nPost0 = A.posts.length;
183
- 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);
184
- const sh = await p.evaluate(() => ({ title: document.querySelector('#dTitle').textContent, path: document.querySelector('#oMain .dpath').textContent, 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 }));
183
+ 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
+ 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
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));
186
186
  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
187
  await p.click('#shV'); await p.click('#shT [data-sh="log"]');
@@ -96,7 +96,7 @@ const MOCKUP = path.join(__dirname, '..', 'prototype', 'premium-ux-concept', 'br
96
96
  ok('M4 no suggestion, no estimate and no demo label is drawn', !(await p.evaluate(() => /Accept all|~\d+ min|demo/i.test(document.querySelector('#plate').textContent))));
97
97
 
98
98
  /* M5 */
99
- const ag = await p.evaluate(() => ({ tiles: [...document.querySelectorAll('#pipe .pst')].map((x) => x.textContent.replace(/\s+/g, ' ').trim()), hot: document.querySelectorAll('#pipe .pst.hot').length, rows: [...document.querySelectorAll('#agl .ws')].map((x) => x.textContent), cap: document.querySelector('#agCap').textContent, hold: document.querySelector('#agHold').textContent, buttons: [...document.querySelectorAll('button')].map((b) => b.textContent).join('|') }));
99
+ const ag = await p.evaluate(() => ({ tiles: [...document.querySelectorAll('#pipe .pst')].map((x) => x.textContent.replace(/\s+/g, ' ').trim()), hot: document.querySelectorAll('#pipe .pst.hot').length, rows: [...document.querySelectorAll('#agl .ws')].map((x) => x.textContent), cap: document.querySelector('#agCap').textContent, hold: document.querySelector('#agHold').textContent, buttons: [...document.querySelectorAll('#agCard button')].map((b) => b.textContent).join('|') }));
100
100
  ok('M5 three counts from the agent field and the rows that are running or ready', ag.tiles.join() === '1Running,1Failed,1To review' && ag.hot === 1 && ag.rows.length === 3 && /draft ready to review/.test(ag.rows[0]) && /the run failed/.test(ag.rows.join()) && ag.cap === 'one to review', JSON.stringify(ag));
101
101
  ok('M5 the With agents card offers no press of its own, and says nothing is posted before a confirm', !/\b(Give to agent|Approve|Revise|Retry)\b/i.test(ag.buttons) && /Nothing is posted until you confirm it/.test(ag.hold));
102
102
 
@@ -35,7 +35,7 @@ You work across products, and a conversation in email, the calendar or Confluenc
35
35
 
36
36
  The page reads today's morning brief (`briefs/<date>.json` in the state folder) and the Jira tickets assigned to you. Nothing is sent, posted or recorded from these rows.
37
37
 
38
- - **Rows.** The brief's mail, Jira and Confluence items become rows in "What you need to do" when you own them, when they mention you, or when they are worth asking. Slack, GitHub, Drive, Figma and website items are left out, and so are agent-owned items that do not mention you. A row shows its source and sender, then the verb and the prepared line, then why it is on the list. Only fields the item holds are shown.
38
+ - **Rows.** The brief's items become rows in "What you need to do" when you own them, when they mention you, or when they are worth asking, whatever their source: calendar, Wispr Flow, mail, Slack, Jira, Confluence, GitHub, Drive, Figma or website. The row names the source. Items the agent owns that do not mention you are left out, and so are PMOS's own derived items. A row shows its source and sender, then the verb and the prepared line, then why it is on the list. Only fields the item holds are shown.
39
39
  - **Tickets.** An assigned Jira ticket becomes a row when it is overdue, due today, blocked or a decision, and your Work list has not marked it done or put it aside.
40
40
  - **The tag.** A row names a product only when the item names an initiative that belongs to exactly one product you included. Every other row reads "Across products". The page never guesses a product.
41
41
  - **The order.** These rows follow the repository rows: tickets first, then the brief's items in the brief's own order. The cap of seven rows is shared, and the rest are counted as more.
@@ -44,6 +44,15 @@ The page reads today's morning brief (`briefs/<date>.json` in the state folder)
44
44
  - **The header** says "no morning brief for today" when there is none, or that the brief could not be read, or that it did not reach a source (mail, Jira, Confluence or Slack).
45
45
  - **`?ws=<id>`** does not show these rows.
46
46
 
47
+ ## The agent's drafts
48
+
49
+ The list also shows what the Initiative Driver is waiting on you for, the same two rows the console's Needs you shows: "Agent has 4 drafts on <initiative>" and "<initiative> is waiting on you: the drafts are 6 days old". They are read from each included product's Driver ledger. Nothing is recorded from these rows.
50
+
51
+ - **Order.** A product whose agent is stopped on you comes after the repository rows and before mail, Jira and Confluence. Open drafts come after those, the oldest first. The list shows seven rows; the rest are counted under "more".
52
+ - **The hero** says how many agent drafts wait on you, counting every one, shown or not. The dock counts them too.
53
+ - **The dialog** shows only what the Driver's row holds: the cause, the draft count, the age, and the confidence, recommendation, reversibility and effort the agent stated when it filed. A fact nobody stated is left out. **Review the drafts** opens Around you's Agent proposals, where Keep, Send back and Drop are.
54
+ - **Left out.** Core-document drafts open the console's Docs view.
55
+
47
56
  ## How long it takes to load
48
57
 
49
58
  Two reads feed the page. The quick read takes the kill conditions, the failed-review verdicts, today's merges and agent runs, and the calendar. It finishes in seconds. The slow read derives the state of every initiative from git history. It takes about half a minute on a fast machine, and much longer on a machine that is busy. The page never waits on the slow read:
@@ -175,6 +184,12 @@ The Start button on a blocked row stays off. Starting an agent that writes needs
175
184
 
176
185
  My work is the second place on the rail, at `/premium-work.html`. It reads the list the Work page reads, so the two pages show one list, and every press uses the Work page's own route. It adds no writer of its own.
177
186
 
187
+ **This week.** A card at the top of the right column shows Monday to Friday. Each day has a bar for its meeting time, from your calendar, and counts of items done and items due that day, from your list. If PMOS cannot read the calendar, the card says so and draws no bars. It makes no "will not fit" note, because no item has a size and PMOS holds no working hours.
188
+
189
+ **Row suggestions and buttons.** A row shows a suggestion line only when a record backs it: an agent's offer on the item, a draft that is ready, or a date. A row also has one button: Today, Tomorrow, Review, or Give to agent. Give to agent opens the item, where you start the agent. A row from Jira shows its Jira key.
190
+
191
+ **The agent's draft.** In an item's dialog the draft shows as formatted text, with a list of the agent's turns under it.
192
+
178
193
  - **The hero** is built from counts of your list: new in the inbox, overdue, due today, people who owe you something (and the longest wait), agent drafts to review, and items untouched for seven days. A clause with no record is left out.
179
194
  - **One count.** "To clear" is the inbox, plus today, plus agent drafts to review. The hero, the card and the dock use it.
180
195
  - **Add** takes one line, read by the Work page's own parser (`Reply to Rina about SSO by Friday !p1`). A new item with no date waits in **Your tray** and its dialog opens at once, so you can place it. An item with a date goes where its date says.
@@ -268,3 +283,5 @@ On a phone or tablet (under 1000 px) every dialog opens on **Detail**. A **Detai
268
283
  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.
269
284
 
270
285
  A calendar meeting's panel follows the mockup's Design review panel: the title with a status chip (when it starts, on now, or done), **Focus** and **Record**, **Prepared for you** (what it is about, people, material and the last meeting, each Ready only when PMOS holds that record), **Material** with **Add material**, **Previous meetings** and **Topics**. What Record and Focus do is one press away under **What Record does** and **What Focus reads**.
286
+
287
+ A document opens in one sheet on both the Board and the initiative page. Its status line shows the state, the version, the checks, the file and the last change; the file's path and front matter sit behind the file chip. The outline lists the headings at their depth, with **Find a heading** when there are many and **Hide the outline**. The body shows lists, tables, bold, code and links. A board draft keeps **Issue it** and **Draft it again**.
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+ /* lib/briefing-premium-drafts.js — the agent's drafts on the premium Briefing (initiative briefing-premium-agent-drafts).
3
+ *
4
+ * build({ parts, now }) → { rows } PURE. parts = [{ ws, name, needs }]: each product's driver rows (lib/driver-needs.js).
5
+ * readDrafts(available, now) → parts what the route reads: the driver ledger of each included product. A ledger that cannot be read gives nothing.
6
+ *
7
+ * The console's Needs you lists "Agent has 3 drafts on <title>" and "<title> is waiting on you: the drafts are 6 days old". The premium list had neither.
8
+ * THE RULE: every word comes from the driver's own row (question, cause, age, the facts the agent stated when it asked). A fact nobody stated is left out.
9
+ * A row has no write of its own: Keep, send back and Drop stay in Around you, which posts the existing /api/driver routes. PURE except readDrafts. */
10
+ const crypto = require('crypto');
11
+
12
+ const ACROSS = 'Across products';
13
+ const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
14
+ const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
15
+
16
+ /** A row key the Briefing's ask route accepts: src:<chars>, up to 100 after the prefix. A long id keeps its head and gains a short hash. */
17
+ function keyOf(ws, runId) {
18
+ const raw = `drv:${ws}:${runId}`, safe = raw.replace(/[^A-Za-z0-9._:-]/g, '-');
19
+ return 'src:' + (safe.length <= 90 ? safe : safe.slice(0, 80) + '-' + crypto.createHash('sha1').update(raw).digest('hex').slice(0, 8));
20
+ }
21
+
22
+ function rowOf(n, product) {
23
+ const blocked = n.kind === 'driver-blocked';
24
+ const rk = n.rank && typeof n.rank === 'object' ? n.rank : {};
25
+ const f = rk.facts && typeof rk.facts === 'object' ? rk.facts : {};
26
+ const age = Number.isFinite(rk.age_days) ? rk.age_days : null;
27
+ const ageWord = age === null ? '' : age === 0 ? 'Filed today' : 'Oldest is ' + plural(age, 'day', 'days') + ' old';
28
+ const why = n.today && n.today.cause ? clip(n.today.cause, 240) : '';
29
+ const facts = [
30
+ ['Source', 'The agent (Initiative Driver)'],
31
+ ['Product', product.name],
32
+ ['Initiative', n.initiative_id || ''],
33
+ ['Drafts waiting', Number.isFinite(rk.drafts) ? String(rk.drafts) : ''],
34
+ ['Age', ageWord],
35
+ ['Wakes held while it waited', Number.isFinite(rk.blocked_runs) && rk.blocked_runs > 0 ? String(rk.blocked_runs) : ''],
36
+ ['Agent confidence', typeof f.confidence === 'number' ? Math.round(f.confidence * 100) + '%' : ''],
37
+ ['Agent recommends', typeof f.recommended === 'string' ? clip(f.recommended, 120) : ''],
38
+ ['Reversible', typeof f.reversible === 'boolean' ? (f.reversible ? 'Yes' : 'No') : ''],
39
+ ['Effort', f.effort || ''],
40
+ ].filter((x) => x[1]);
41
+ const prepared = blocked ? 'The agent will not go on until you keep, send back or drop its drafts.' : 'Keep, send back or drop each draft.';
42
+ return {
43
+ kind: 'agent', key: keyOf(product.ws, n.run_id), title: clip(n.question, 140),
44
+ subject: ['Agent drafts', blocked ? 'waiting on you' : '', age ? plural(age, 'day', 'days') + ' old' : ''].filter(Boolean).join(' · '),
45
+ prepared, skip: why ? 'Why: ' + why : 'No reason is on record.',
46
+ product: product.name || ACROSS, from: ['driver:' + n.run_id], detail: { blocked },
47
+ dialog: {
48
+ eye: 'Agent drafts', logTitle: 'Read from the Driver ledger', title: clip(n.question, 140), sub: ['Agent drafts', product.name].filter(Boolean).join(' · '),
49
+ log: ['Read the Initiative Driver ledger of ' + product.name, 'Found open drafts for ' + (n.initiative_id ? 'the initiative ' + n.initiative_id : 'a Work task'), 'Read only what the agent stated when it filed them'],
50
+ say: why || 'The agent filed drafts and waits for you. Nothing it wrote has changed a record until you keep it.',
51
+ head: 'The drafts', facts, opts: [], sel: null, nodef: '', proposals: true,
52
+ pane: { label: 'Driver ledger', file: (n.today && n.today.evidence) || 'driver.jsonl', h: clip(n.question, 140), intro: why, rows: facts, paras: [], parasTitle: '' },
53
+ },
54
+ };
55
+ }
56
+
57
+ /** Blocked rows first (the agent is stopped), then drafts, the oldest first. */
58
+ const order = (a, b) => (b.detail.blocked - a.detail.blocked) || ((b._age || 0) - (a._age || 0));
59
+
60
+ function build({ parts } = {}) {
61
+ const rows = [];
62
+ for (const p of parts || []) {
63
+ if (!p || !p.ws || !Array.isArray(p.needs)) continue;
64
+ for (const n of p.needs) {
65
+ if (!n || (n.kind !== 'driver-drafts' && n.kind !== 'driver-blocked') || !n.run_id || !clip(n.question, 140)) continue;
66
+ const r = rowOf(n, { ws: p.ws, name: p.name || p.ws });
67
+ r._age = n.rank && Number.isFinite(n.rank.age_days) ? n.rank.age_days : 0;
68
+ rows.push(r);
69
+ }
70
+ }
71
+ rows.sort(order);
72
+ rows.forEach((r) => delete r._age);
73
+ return { rows };
74
+ }
75
+
76
+ /** One entry per included product: its driver rows. A product whose ledger cannot be read gives none, and no error. */
77
+ function readDrafts(available) {
78
+ const DN = require('./driver-needs.js');
79
+ const out = [];
80
+ for (const a of available || []) {
81
+ if (!a || !a.on || !a.root) continue;
82
+ let needs = [];
83
+ try { needs = DN.rowsFor({ root: a.root }, { lead: true }); } catch { needs = []; }
84
+ out.push({ ws: a.ws, name: a.name, needs });
85
+ }
86
+ return out;
87
+ }
88
+
89
+ module.exports = { build, readDrafts, keyOf };
@@ -71,7 +71,7 @@ function start(p, engine, runtimeDir) {
71
71
  }
72
72
 
73
73
  /** The merged answer for the workspaces that are on. `available` is choose()'s list (all of them, with `on`). */
74
- async function modelOfMany({ available, engine, runtimeDir, sources }) {
74
+ async function modelOfMany({ available, engine, runtimeDir, sources, agent }) {
75
75
  const now = Date.now();
76
76
  const on = (available || []).filter((a) => a.on);
77
77
  const parts = [];
@@ -98,7 +98,7 @@ async function modelOfMany({ available, engine, runtimeDir, sources }) {
98
98
  const settled = parts.filter((p) => p.state === 'ready').length;
99
99
  if (on.length && !settled && parts.every((p) => p.state === 'reading')) return { state: 'reading', elapsed_ms: elapsed };
100
100
  if (on.length && !settled && parts.every((p) => p.state === 'error')) return { state: 'error', error: parts.map((p) => p.product.name + ': ' + p.error).join('; ').slice(0, 300) };
101
- const model = BP.buildMany({ now, asOf: asOf || now, meetings: BP.readMeetings(runtimeDir, now), defers: Object.fromEntries(W.readDefers(runtimeDir, now)), available: (available || []).map((a) => ({ ws: a.ws, name: a.name, home: a.home, on: a.on })), parts, sources });
101
+ const model = BP.buildMany({ now, asOf: asOf || now, meetings: BP.readMeetings(runtimeDir, now), defers: Object.fromEntries(W.readDefers(runtimeDir, now)), available: (available || []).map((a) => ({ ws: a.ws, name: a.name, home: a.home, on: a.on })), parts, sources, agent });
102
102
  last = model;
103
103
  return { state: 'ready', model, as_of: asOf || now, refreshing, pending: model.pending, ...(error ? { error } : {}) };
104
104
  }
@@ -14,8 +14,8 @@ const path = require('path');
14
14
  const Real = require('./briefing-real.js');
15
15
  const { localDate } = require('./brief.js');
16
16
 
17
- const SOURCE_WORD = { mail: 'Mail', jira: 'Jira', confluence: 'Confluence', slack: 'Slack' };
18
- const ROW_SOURCES = ['mail', 'jira', 'confluence'];
17
+ const SOURCE_WORD = { calendar: 'Calendar', wispr: 'Wispr Flow', mail: 'Mail', jira: 'Jira', confluence: 'Confluence', slack: 'Slack', github: 'GitHub', drive: 'Drive', figma: 'Figma', website: 'Website' };
18
+ const ROW_SOURCES = ['calendar', 'wispr', 'mail', 'slack', 'jira', 'confluence', 'github', 'drive', 'figma', 'website']; // every source of the brief but its own derived items, as the console's cards take them
19
19
  const VERB_WORD = { reply: 'Reply', review: 'Review', decide: 'Decide', 'sign-off': 'Sign off', read: 'Read', do: 'Do' };
20
20
  const EFFORT_WORD = { minutes: 'minutes', 'an-hour': 'an hour', 'half-day': 'half a day', day: 'a day' };
21
21
  const ACROSS = 'Across products';
@@ -27,7 +27,7 @@ const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
27
27
  const pad = (n) => String(n).padStart(2, '0');
28
28
  const hhmm = (ms) => { const d = new Date(ms); return pad(d.getHours()) + ':' + pad(d.getMinutes()); };
29
29
 
30
- /** The items that become rows: a mail, Jira or Confluence item the PM owns, or that mentions the PM, or that is worth asking. */
30
+ /** The items that become rows: an item of any source the brief names the PM owns, or that mentions the PM, or that is worth asking. */
31
31
  function rowItems(brief) {
32
32
  const keep = (x) => x && typeof x === 'object' && x.id && text(x.title, 140) && ROW_SOURCES.includes(x.source);
33
33
  const asks = list(brief.worth_asking).filter((x) => keep(x));
@@ -22,6 +22,7 @@ const path = require('path');
22
22
  const { execFile } = require('child_process');
23
23
  const W = require('./briefing-premium-writes.js');
24
24
  const Src = require('./briefing-premium-sources.js');
25
+ const Drafts = require('./briefing-premium-drafts.js');
25
26
 
26
27
  const DAY = 86400000;
27
28
  const MAX_ROWS = 7;
@@ -385,7 +386,9 @@ function buildMany(g) {
385
386
  const owner = new Map();
386
387
  for (const p of read) for (const i of p.f.initiatives) owner.set(i.id, owner.has(i.id) ? null : { ws: p.product.ws, name: p.product.name });
387
388
  const sx = g.sources ? Src.build(Object.assign({}, g.sources, { products: (id) => owner.get(id) || null })) : null;
388
- const { rows, more } = cut(every.concat(sx ? sx.rows : []), putOff);
389
+ // the agent's drafts (initiative: the agent drafts slice): a product whose agent is stopped on the PM comes before the sources, the open drafts after them
390
+ const dx = g.agent ? Drafts.build({ parts: g.agent }).rows : [];
391
+ const { rows, more } = cut(every.concat(dx.filter((r) => r.detail.blocked), sx ? sx.rows : [], dx.filter((r) => !r.detail.blocked)), putOff);
389
392
  const tag = (list, p) => list.map((x) => Object.assign({}, x, { ws: p.product.ws, product: p.product.name }));
390
393
  const cf = {
391
394
  now, asOf, meetings, defers: g.defers || {},
@@ -408,6 +411,8 @@ function buildMany(g) {
408
411
  : heroOf(cf, rows);
409
412
  const srcRows = rows.filter((r) => r.kind === 'source'), srcSeen = [...new Set(srcRows.map((r) => r.detail.source))];
410
413
  if (srcRows.length) hero.push({ parts: [{ t: num(srcRows.length) + ' ' + plural(srcRows.length, 'item', 'items') + ' from ' + joinNames(srcSeen.map((k) => Src.SOURCE_WORD[k])), s: true }, { t: ' ' + plural(srcRows.length, 'needs', 'need') + ' you.', s: false }], from: srcRows.map((r) => r.from[0]) });
414
+ const agRows = rows.filter((r) => r.kind === 'agent'), agAll = dx.length;
415
+ if (agAll) hero.push({ parts: [{ t: num(agAll) + ' ' + plural(agAll, 'agent draft', 'agent drafts') + ' ' + (agAll === 1 ? 'waits' : 'wait'), s: true }, { t: ' on you.', s: false }], from: (agRows.length ? agRows : dx).map((r) => r.from[0]) });
411
416
  const sxNote = !sx ? '' : sx.state === 'ok' ? (sx.notRead.length ? ' · not read by the morning brief: ' + sx.notRead.join(', ') : '') : sx.state === 'bad' ? ' · the morning brief could not be read' : ' · no morning brief for today';
412
417
  return {
413
418
  date: dateLine(now),
@@ -59,6 +59,7 @@ function agentDetail(it) {
59
59
  draft: d ? { summary: clip(d.summary || '', 300), body: String(d.body || '').slice(0, 4000), step: d.step ? clip(d.step, 200) : null } : null,
60
60
  error: a.error ? clip(a.error, 300) : null, asks: !!a.asks, session: a.session || null,
61
61
  mine, where: mine ? null : it.origin === 'jira' ? 'Jira' : PLACE[it.place] || 'its source',
62
+ turns: (Array.isArray(a.log) ? a.log : []).slice(-12).map((t, i) => ({ who: t.who === 'agent' ? 'agent' : 'you', kind: String(t.kind || ''), at: t.at || null, text: clip(t.text || '', 300), has_body: !!t.body })),
62
63
  started_at: a.started_at || null, sent_at: a.sent && a.sent.at ? a.sent.at : null, link: a.sent && isUrl(a.sent.link) ? a.sent.link : null,
63
64
  };
64
65
  }
@@ -72,15 +73,52 @@ function dueChip(it, today) {
72
73
  return { chip: shortDate(it.due), overdue: false };
73
74
  }
74
75
 
76
+ /** The suggestion line and the one press on a row. A line shows only when a record says it: an agent's own offer on the item, a draft ready, or a date.
77
+ * PMOS does not guess a place for an item. The press is a route that already exists: Today (/flag), Tomorrow (/defer), or the item's dialog, where the agent brief and the review run. */
78
+ function suggestOf(it, list, today, overdue) {
79
+ const ag = it.agent || {}, state = agentOf(it), d = it.due ? daysBetween(today, it.due) : null;
80
+ let sug = null, cta = null;
81
+ if (state === 'ready') { sug = { b: 'Agent draft, not checked.', t: clip((ag.draft && (ag.draft.summary || ag.draft.body)) || 'Open it to read the draft.', 140) }; cta = { label: 'Review', act: 'open' }; }
82
+ else if (state === 'suggest' && (ag.instruction || ag.suggest)) { sug = { b: 'Agent can:', t: clip(ag.instruction || ag.suggest, 140) }; cta = { label: 'Give to agent', act: 'open' }; }
83
+ else if (overdue) sug = { b: 'Overdue.', t: 'It was due ' + shortDate(it.due) + ' and is still open.' };
84
+ else if (d === 0) sug = { b: 'Due today.', t: 'Its date is today.' };
85
+ else if (d != null && d > 0 && d <= 6) sug = { b: 'This week.', t: 'Its date is ' + shortDate(it.due) + '.' };
86
+ if (!cta && list !== 'waiting' && !isRunning(it) && state !== 'failed') cta = list === 'today' ? { label: 'Tomorrow', act: 'tomorrow' } : { label: 'Today', act: 'today' };
87
+ return { sug, cta };
88
+ }
89
+
90
+ /** This week, Monday to Friday, from three records: the meetings the calendar holds, the items marked done that day, and the open items with that due date.
91
+ * No effort, capacity or "won't fit" figure is made: no item carries a size and PMOS holds no working hours. */
92
+ function weekOf({ today, items, events }) {
93
+ const base = isoDay(today);
94
+ const dow = (base.getDay() + 6) % 7;
95
+ const iso = (d) => d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
96
+ const days = [0, 1, 2, 3, 4].map((i) => { const d = new Date(base.getFullYear(), base.getMonth(), base.getDate() - dow + i); return { iso: iso(d), dow: WEEKDAYS[d.getDay()].slice(0, 3).toUpperCase(), n: d.getDate() }; });
97
+ const read = Array.isArray(events);
98
+ for (const d of days) {
99
+ const ev = read ? events.filter((e) => String(e.at || '').slice(0, 10) === d.iso) : [];
100
+ d.meetings = ev.length;
101
+ d.meet_min = ev.reduce((a, e) => { const m = Date.parse(e.end) - Date.parse(e.at); return a + (m > 0 && m < 86400000 ? Math.round(m / 60000) : 0); }, 0);
102
+ d.done = items.filter((it) => it.done && String(it.done_at || '').slice(0, 10) === d.iso).length;
103
+ d.due = items.filter((it) => !it.done && it.due === d.iso).length;
104
+ d.today = d.iso === today; d.past = d.iso < today;
105
+ }
106
+ const tot = (k) => days.reduce((a, d) => a + d[k], 0);
107
+ const bits = [read ? tot('meetings') + ' ' + plural(tot('meetings'), 'meeting', 'meetings') : null, tot('done') + ' done', tot('due') + ' due'].filter(Boolean);
108
+ return { title: 'This week', cap: bits.join(' · '), days, calendar: read,
109
+ note: (read ? 'Bars are meeting time from your calendar. ' : 'The calendar could not be read, so there are no bars. ') + 'Done and due counts come from your list. PMOS holds no estimate or working hours, so it does not say what will not fit.' };
110
+ }
111
+
75
112
  function rowOf(it, list, v, inReview, focusIds) {
76
113
  const today = v.today, { chip, overdue } = dueChip(it, today);
77
- const sub = [srcLabel(it), it.priority, it.waiting_on ? 'waiting on ' + it.waiting_on : null].filter(Boolean).join(' · ');
114
+ const sub = [srcLabel(it) + (it.key && it.source !== 'local' ? ' ' + it.key : ''), it.priority, it.waiting_on ? 'waiting on ' + it.waiting_on : null].filter(Boolean).join(' · ');
78
115
  const days = it.waiting_since ? daysBetween(String(it.waiting_since).slice(0, 10), today) : null;
79
116
  const facts = [
80
117
  ['From', srcLabel(it)], ['Place', list === 'upcoming' ? 'Upcoming' : list.charAt(0).toUpperCase() + list.slice(1)], ['Due', it.due ? shortDate(it.due) + (overdue ? ' (overdue)' : '') : ''],
81
118
  ['Priority', it.priority], ['Waiting on', it.waiting_on], ['Waiting since', it.waiting_since ? shortDate(String(it.waiting_since).slice(0, 10)) + (days != null ? ' (' + days + ' ' + plural(days, 'day', 'days') + ')' : '') : ''],
82
119
  ['Not before', it.defer && it.defer > today ? shortDate(it.defer) : ''], ['Added', it.created_at ? shortDate(String(it.created_at).slice(0, 10)) : ''], ['Last touched', it.touched_at ? shortDate(String(it.touched_at).slice(0, 10)) : ''],
83
120
  ].filter((x) => x[1]);
121
+ const added = it.created_at ? shortDate(String(it.created_at).slice(0, 10)) : '';
84
122
  const draft = it.agent && it.agent.draft && (it.agent.draft.body || it.agent.draft.summary);
85
123
  const actions = ['done', 'notyet'];
86
124
  if (list !== 'today') actions.push('flag');
@@ -88,8 +126,9 @@ function rowOf(it, list, v, inReview, focusIds) {
88
126
  actions.push('remove');
89
127
  if (inReview) actions.push('keep');
90
128
  const say = overdue ? 'This was due ' + shortDate(it.due) + ' and is still open.' : list === 'tray' ? 'You threw this in. It has no date or place yet. Place it, or drop it.' : list === 'inbox' ? 'This is new and has no date or place yet.' : list === 'waiting' ? 'You are waiting on ' + (it.waiting_on || 'someone') + (days != null ? ' for ' + days + ' ' + plural(days, 'day', 'days') : '') + '.' : 'This is on your list.';
129
+ const { sug, cta } = suggestOf(it, list, today, overdue);
91
130
  return {
92
- key: 'work:' + it.id, id: it.id, list, title: clip(it.title, 140), sub, chip, overdue, src: srcLabel(it),
131
+ key: 'work:' + it.id, id: it.id, list, title: clip(it.title, 140), sub: sub + (added && (list === 'inbox' || list === 'tray') ? ' · added ' + added : ''), chip, overdue, src: srcLabel(it), sug, cta,
93
132
  agent: agentOf(it) && agentOf(it) !== 'suggest' ? agentOf(it) : null,
94
133
  focus: list === 'today' && focusIds.has(it.id),
95
134
  dialog: {
@@ -108,7 +147,7 @@ function rowOf(it, list, v, inReview, focusIds) {
108
147
  };
109
148
  }
110
149
 
111
- function build({ v, now }) {
150
+ function build({ v, now, events }) {
112
151
  now = now || Date.now();
113
152
  v = v || {};
114
153
  const today = v.today || new Date(now).toISOString().slice(0, 10);
@@ -165,12 +204,13 @@ function build({ v, now }) {
165
204
  header: { text: 'Real data · as of ' + hhmm(now) + ' · Jira and Slack appear only when an agent session has read them', missing: [] },
166
205
  hero, empty,
167
206
  capture: { placeholder: 'Add anything: "Reply to Rina about SSO by Friday"', hint: 'One line. The date and priority are read from it.' },
168
- plate: { title: 'On your plate', cap: clear + ' to clear', n: clear, sections, note: 'Each item comes from your list. A date shows only when one was set. Nothing changes in Jira or Slack from here.' },
207
+ plate: { title: 'On your plate', cap: clear + ' to clear', n: clear, sections, note: 'Each item comes from your list. A suggestion shows only when an agent offered it, a draft is ready, or a date says so; PMOS does not guess a place. A date shows only when one was set. Nothing changes in Jira or Slack from here.' },
169
208
  tray: { title: 'Your tray', cap: tray.length ? tray.length + ' to place' : 'empty', n: tray.length, more: Math.max(0, tray.length - MAX_PER), rows: trayRows, note: 'Anything you add lands here first. Open one to place it: Today, Later, waiting on someone, or drop it. Nothing here counts as work to clear until you place it.' },
170
209
  agents: { title: 'With agents', cap: ready.length ? num(ready.length) + ' to review' : running.length ? num(running.length) + ' running' : 'nothing running', counts: { running: running.length, ready: ready.length, failed: failed.length }, rows: agentRows, hold: HOLD.agent },
171
210
  waiting: { title: 'Waiting on others', cap: longest != null ? 'longest ' + longest + ' ' + plural(longest, 'day', 'days') : (work.waiting || []).length ? num(work.waiting.length) + ' waiting' : '', n: (work.waiting || []).length, more: Math.max(0, (work.waiting || []).length - MAX_PER), rows: waitingRows },
172
211
  review: { n: (v.review || []).length, days: v.review_days, ids: (v.review || []).map((i) => i.id) },
173
212
  dock: { needs: clear, label: 'to clear', next: firstToday ? firstToday.title : (sections[0].rows[0] ? sections[0].rows[0].title : null) },
213
+ week: weekOf({ today, items: v.items || all.map((x) => x.it), events }),
174
214
  focus, jobs,
175
215
  rows: rowsAll,
176
216
  };
@@ -23,6 +23,7 @@ const { appendOutbox } = require(repoScript('outbox.js'));
23
23
 
24
24
  const Prod = require('./briefing-premium-products.js');
25
25
  const Src = require('./briefing-premium-sources.js');
26
+ const Drafts = require('./briefing-premium-drafts.js');
26
27
  const settings = require('./settings-store.js');
27
28
 
28
29
  /** The workspaces the Briefing may read right now (initiative briefing-premium-products): choose()'s list, from the server's workspace list and the PM's setting. */
@@ -103,7 +104,8 @@ module.exports = {
103
104
  if (!url.searchParams.get('ws')) {
104
105
  const sel = products(ctx);
105
106
  const sources = await Src.readSources(ctx, Date.now()).catch(() => null);
106
- const r = await Prod.modelOfMany({ available: sel.available, engine: enginePath(), runtimeDir: ctx.runtimeDir, sources });
107
+ const agent = Drafts.readDrafts(sel.available);
108
+ const r = await Prod.modelOfMany({ available: sel.available, engine: enginePath(), runtimeDir: ctx.runtimeDir, sources, agent });
107
109
  ctx.json(res, r.state === 'error' ? { ok: false, ...r } : { ok: true, ...r }, r.state === 'ready' ? 200 : r.state === 'reading' ? 202 : 500);
108
110
  return true;
109
111
  }
@@ -23,8 +23,10 @@ module.exports = {
23
23
  let v = null, err = null;
24
24
  try { v = await listView(req, ctx); } catch (e) { err = String((e && e.message) || e).slice(0, 200); }
25
25
  if (!v || v.ok === false) { ctx.json(res, { ok: false, state: 'error', error: err || (v && v.error) || 'the list could not be read' }, 500); return true; }
26
+ let events = null;
27
+ try { events = require('./calendar-events.js').readAll(ctx.runtimeDir, { now: Date.now() }); } catch { events = null; }
26
28
  let model;
27
- try { model = WP.build({ v, now: Date.now() }); } catch (e) { ctx.json(res, { ok: false, state: 'error', error: 'the page could not be built: ' + String((e && e.message) || e).slice(0, 160) }, 500); return true; }
29
+ try { model = WP.build({ v, now: Date.now(), events }); } catch (e) { ctx.json(res, { ok: false, state: 'error', error: 'the page could not be built: ' + String((e && e.message) || e).slice(0, 160) }, 500); return true; }
28
30
  ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
29
31
  return true;
30
32
  },
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.286.0",
3
+ "version": "0.288.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.286.0",
9
+ "version": "0.288.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.286.0",
3
+ "version": "0.288.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",
@@ -34,7 +34,7 @@ const finish = async (code) => {
34
34
  process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
35
35
 
36
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)$/;
37
+ const ALLOWED = /^\/api\/(?:core-docs\/issue|briefing-premium\/note|doc-health\/check)$/;
38
38
  const BODY = '## Purpose\n\nWhy this board exists.\n\n## Scope\n\nWhat it covers.\n';
39
39
 
40
40
  (async () => {
@@ -91,17 +91,18 @@ const BODY = '## Purpose\n\nWhy this board exists.\n\n## Scope\n\nWhat it covers
91
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
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
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], #oMain #shV')));
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.querySelector('[data-ds="meta"]') && !!o.querySelector('[data-issue-bar="draft"]') && /Nothing is sent/.test(o.querySelector('[data-issue-bar]').textContent) && !!o.querySelector('[data-ds="issue"]'); }, d1.path)), await p.evaluate(() => document.querySelector('#oMain').textContent));
95
+ ok('B2 the path is behind the file chip, not in the way', await p.evaluate((pt) => !document.querySelector('#oMain .dsmeta') && !!document.querySelector('#oMain [data-ds="meta"]'), d1.path) && (await p.click('#oMain [data-ds="meta"]'), await p.evaluate((pt) => document.querySelector('#oMain .dsmeta').textContent.includes(pt), d1.path)));
96
+ ok('B2 the reader has the sheet\'s view menu, as the initiative page does', await p.evaluate(() => !!document.querySelector('#oMain #shV')));
96
97
  const n0 = ledger().filter((l) => l.ev === 'issue').length;
97
- await p.click('[data-rd="issue"]');
98
+ await p.click('[data-ds="issue"]');
98
99
  ok('B3 Issue it says it sent nothing', !!(await toastIs(p, /Issued\. Nothing was sent to anyone/)));
99
100
  const sent = P.posts.filter((x) => x.path === '/api/core-docs/issue');
100
101
  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
102
  const il = ledger().filter((l) => l.ev === 'issue');
102
103
  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
104
  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
+ 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-ds="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
106
  await p.screenshot({ path: path.join(R.base, 'board-issued.png') });
106
107
  await P.ctx.close();
107
108
 
@@ -162,8 +163,8 @@ const BODY = '## Purpose\n\nWhy this board exists.\n\n## Scope\n\nWhat it covers
162
163
  const S = await open('/premium-board.html', { w, h, theme });
163
164
  await until(() => S.page.evaluate((k) => !!document.querySelector(`#docBody [data-doc="${k}"]`), k4), 60000);
164
165
  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 }));
166
+ await until(() => S.page.evaluate(() => !!document.querySelector('[data-ds="issue"]')));
167
+ const f = await S.page.evaluate(() => ({ wide: document.documentElement.scrollWidth > innerWidth + 1, small: [...document.querySelectorAll('#oMain [data-ds="issue"], #oMain [data-ds="again"]')].filter((b) => b.getBoundingClientRect().height < 44 || b.getBoundingClientRect().width < 44).map((b) => b.dataset.ds), bg: getComputedStyle(document.querySelector('[data-issue-bar]')).backgroundColor }));
167
168
  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
169
  await S.page.screenshot({ path: path.join(R.base, `bar-${w}-${theme}.png`) });
169
170
  await S.ctx.close();
@@ -5,11 +5,13 @@
5
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
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
+ import { issueBody } from './premium-doc-edit.js';
9
+ import { mountDocSheet } from './premium-doc-sheet.js';
9
10
  import { dotsBtn, openMenu, closeMenu, menuKey, asksHtml, onAsks, openIniForm } from './premium-acts.js';
10
11
 
11
12
  const MODE_KEY = 'pmos.premium.openAs';
12
13
  let M = null; // the model
14
+ const docSheet = mountDocSheet({ ws: () => M.board.ws, scope: () => M.docs.scope, rows: () => M.docs.rows, reload: () => load(), noteKey: (d) => 'doc:' + M.board.id + ':' + d.key, sub: () => M.board.name, again: true });
13
15
  let view = 'list';
14
16
  let shown = 25; // rows of the list on screen
15
17
  let readTimer = null;
@@ -142,7 +144,7 @@ $('#docTop').addEventListener('click', async (e) => {
142
144
  $('#docTop').addEventListener('input', (e) => { if (e.target.id === 'dmQ') { docQuery = e.target.value; drawDocList(); } });
143
145
  const GOTAB = { rep: '/console.html?tab=rep', init: '/console.html?tab=init' };
144
146
  $('#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; }
147
+ const o = e.target.closest('[data-doc]'); if (o) { docSheet.open(M.docs.rows.find((x) => x.key === o.dataset.doc)); return; }
146
148
  const t = e.target.closest('[data-tab]'); if (t) { location.assign(GOTAB[t.dataset.tab] || '/console.html'); return; }
147
149
  const b = e.target.closest('[data-draft]'); if (!b || b.disabled) return;
148
150
  const key = b.dataset.draft, d = M.docs.rows.find((x) => x.key === key);
@@ -153,64 +155,6 @@ $('#docBody').addEventListener('click', async (e) => {
153
155
  await load();
154
156
  });
155
157
 
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
-
214
158
  $('#addDoc').onclick = () => openAddDoc({ ws: M.board.ws, scope: M.docs.scope, sub: M.board.name, onAdded: load });
215
159
 
216
160
  /* ── new asks and New initiative (initiative premium-board-actions) ───────────────────────────────────────── */