create-pmos 0.382.0 → 0.384.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 +30 -35
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/REMOTE.md +39 -0
- package/workspace/briefing-premium-initiative-test.js +9 -0
- package/workspace/briefing-premium-test.js +1 -1
- package/workspace/changelog.json +29 -0
- package/workspace/guide/briefing-premium.md +6 -1
- package/workspace/lib/lead-cli.js +63 -0
- package/workspace/lib/my-work-premium.js +29 -3
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/popup-leads.js +68 -0
- package/workspace/lib/routes-briefing-premium.js +4 -1
- package/workspace/lib/routes-pm-items.js +5 -2
- package/workspace/lib/share-store.js +150 -0
- package/workspace/lib/work-assigned.js +12 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-viewer-share-test.js +208 -0
- package/workspace/public/pm/premium-shell.js +19 -0
- package/workspace/public/pm/premium-vw-doc.css +30 -0
- package/workspace/public/pm/premium-vw-file.js +22 -10
- package/workspace/public/pm/premium-vw-share.js +112 -0
- package/workspace/public/pm/premium-work.js +18 -3
- package/workspace/public/pm/premium.css +11 -0
- package/workspace/public/pm/premium.js +3 -1
- package/workspace/server.js +65 -0
- package/workspace/share-server.js +135 -0
- package/workspace/test-lists/popup-context.json +5 -0
- package/workspace/test-lists/premium-viewer-share.json +5 -3
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* pm/premium-vw-share.js — the share icon's popover on a file in the viewer (premium-viewer-share S1-S9, P1; PM 2026-10-21: "I should be able to download
|
|
2
|
+
* or share (no need login to cloudflare, but I can set password)"). It opens under the icon (a sheet at the bottom on a phone) and holds:
|
|
3
|
+
* Send a copy on a device that can share files (a phone), the system share sheet with the file attached. No link is made.
|
|
4
|
+
* Public link Password (on, a generated one the PM can change), Ends (1, 7 or 30 days; 7), Create link. A copy of the file as it is now goes to
|
|
5
|
+
* the share copies folder through POST /api/shares; the share server (share-server.js, D97) serves it. Nothing is public before the press.
|
|
6
|
+
* Open links every open link with its end date and views, and Turn off (a second press confirms). Turn off deletes the copy at once.
|
|
7
|
+
* Reads GET /api/shares and GET /api/shares/password; writes only through the two page-press routes.
|
|
8
|
+
* shareMenu(btn, f) f is the file tab's record: { name, ws, rel, kind, text } */
|
|
9
|
+
import { pmGet, pmPost } from './http.js';
|
|
10
|
+
|
|
11
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
12
|
+
const day = (iso) => { try { return new Date(iso).toLocaleDateString(undefined, { day: 'numeric', month: 'short' }); } catch { return ''; } };
|
|
13
|
+
const LOCK = '<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg>';
|
|
14
|
+
const LINK = '<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/></svg>';
|
|
15
|
+
const SEND = '<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 12l16-8-6 16-2-7z"/></svg>';
|
|
16
|
+
|
|
17
|
+
/** Whether this device can hand a file to the system share sheet (a phone, mostly). */
|
|
18
|
+
export function canSendFile(f) {
|
|
19
|
+
try { return typeof navigator !== 'undefined' && !!navigator.share && !!navigator.canShare && navigator.canShare({ files: [new File([f.text || ''], f.name || 'file.txt', { type: 'text/plain' })] }); }
|
|
20
|
+
catch { return false; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The popover's inside as HTML. Pure. S = { pw, pass, days, made, err, busy, list, host, off, send } */
|
|
24
|
+
export function shareHtml(S) {
|
|
25
|
+
const send = S.send ? `<button type="button" class="vwsm" data-sh="send">${SEND}<span>Send a copy</span><small>share sheet</small></button><div class="vwssep"></div>` : '';
|
|
26
|
+
const list = S.list && S.list.length
|
|
27
|
+
? `<div class="vwsh">Open links (${S.list.length})</div>` + S.list.map((x) => `<div class="vwsrow">${x.pw ? LOCK : LINK}<span><b>${esc(x.name)}</b><em>Ends ${esc(day(x.ends))} · ${x.views ? x.views + (x.views === 1 ? ' view' : ' views') : 'not opened yet'}</em></span>`
|
|
28
|
+
+ `<button type="button" class="vwsoff" data-off="${esc(x.id)}">${S.off === x.id ? 'Sure? Turn off' : 'Turn off'}</button></div>`).join('')
|
|
29
|
+
: '';
|
|
30
|
+
if (S.made) {
|
|
31
|
+
return send + `<div class="vwsh">Link ready</div><div class="vwslnk"><code class="vwsu">${esc(S.made.url)}</code>`
|
|
32
|
+
+ (S.made.pass ? `<div class="vwspw">${LOCK}<code>${esc(S.made.pass)}</code></div>` : '')
|
|
33
|
+
+ `<div class="vwsr"><button type="button" class="vwbtn pri" data-sh="copy">${S.made.pass ? 'Copy link and password' : 'Copy link'}</button><span class="vwsok" role="status">${esc(S.copied || '')}</span></div>`
|
|
34
|
+
+ `<p class="vwsn">Ends ${esc(day(S.made.ends))}.${S.made.pass ? ' Send the password in a different message.' : ''}</p></div>`
|
|
35
|
+
+ (list ? '<div class="vwssep"></div>' + list : '');
|
|
36
|
+
}
|
|
37
|
+
return send + `<div class="vwsh">Public link</div>`
|
|
38
|
+
+ `<div class="vwsrow2">${LOCK}<span>Password</span><button type="button" class="vwsw" role="switch" aria-checked="${S.pw}" aria-label="Password" data-sh="pw"></button></div>`
|
|
39
|
+
+ (S.pw ? `<div class="vwspwi"><input id="vwsPass" type="text" spellcheck="false" autocomplete="off" aria-label="Password" value="${esc(S.pass)}"><button type="button" class="vwbtn" data-sh="new">New</button></div>` : '')
|
|
40
|
+
+ `<div class="vwsrow2"><span>Ends</span><div class="vwsg" role="group" aria-label="Link ends after">${[1, 7, 30].map((d) => `<button type="button" class="vwseg" data-days="${d}" aria-pressed="${S.days === d}">${d === 1 ? '1 day' : d + ' days'}</button>`).join('')}</div></div>`
|
|
41
|
+
+ `<p class="vwsn">Anyone with the link${S.pw ? ' and the password' : ''} can read a copy of this file as it is now. Later edits are not shared.</p>`
|
|
42
|
+
+ (S.err ? `<p class="vwserr" role="alert">${esc(S.err)}</p>` : '')
|
|
43
|
+
+ `<button type="button" class="vwbtn pri vwsgo" data-sh="make"${S.busy ? ' disabled' : ''}>${S.busy ? 'Making the link…' : 'Create link'}</button>`
|
|
44
|
+
+ (list ? '<div class="vwssep"></div>' + list : '');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function shareMenu(btn, f) {
|
|
48
|
+
const box = btn.parentElement;
|
|
49
|
+
const old = box.querySelector('.vwshp');
|
|
50
|
+
const close = (focus) => { const k = box.querySelector('.vwshp'); if (k) k.remove(); btn.setAttribute('aria-expanded', 'false'); if (focus) btn.focus(); };
|
|
51
|
+
if (old) return close();
|
|
52
|
+
// Escape closes the popover wherever the focus is (a press redraws it), before the dialog under it sees the key
|
|
53
|
+
const onKey = (e) => { if (e.key !== 'Escape') return; document.removeEventListener('keydown', onKey, true); if (!m.isConnected) return; e.stopPropagation(); close(true); };
|
|
54
|
+
box.querySelectorAll('.vmenu').forEach((m) => m.remove());
|
|
55
|
+
const S = { pw: true, pass: '', days: 7, made: null, err: '', busy: false, list: [], host: null, off: null, send: canSendFile(f), copied: '' };
|
|
56
|
+
const m = document.createElement('div');
|
|
57
|
+
m.className = 'vwshp'; m.setAttribute('role', 'dialog'); m.setAttribute('aria-label', 'Share ' + (f.name || 'this file')); m.dataset.escLayer = '1';
|
|
58
|
+
const draw = (focus) => {
|
|
59
|
+
m.innerHTML = shareHtml(S);
|
|
60
|
+
const f2 = focus && m.querySelector(focus); if (f2) f2.focus();
|
|
61
|
+
};
|
|
62
|
+
const load = async () => {
|
|
63
|
+
const [l, p] = await Promise.all([pmGet('/api/shares'), S.pass ? null : pmGet('/api/shares/password')]);
|
|
64
|
+
if (l && l.ok) { S.list = l.shares || []; S.host = l.host; }
|
|
65
|
+
const typed = m.querySelector('#vwsPass');
|
|
66
|
+
if (typed && typed.value) S.pass = typed.value; // the PM typed before the generated one arrived
|
|
67
|
+
else if (p && p.ok && !S.pass) S.pass = p.password;
|
|
68
|
+
if (m.isConnected) draw(document.activeElement && m.contains(document.activeElement) && document.activeElement.dataset.sh ? `[data-sh="${document.activeElement.dataset.sh}"]` : null);
|
|
69
|
+
};
|
|
70
|
+
m.onclick = async (e) => {
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
const b = e.target.closest('button'); if (!b) return;
|
|
73
|
+
const pass = m.querySelector('#vwsPass'); if (pass) S.pass = pass.value;
|
|
74
|
+
if (b.dataset.days) { S.days = Number(b.dataset.days); return draw(`[data-days="${S.days}"]`); }
|
|
75
|
+
if (b.dataset.off) {
|
|
76
|
+
if (S.off !== b.dataset.off) { S.off = b.dataset.off; return draw(`[data-off="${S.off}"]`); }
|
|
77
|
+
const r = await pmPost('/api/shares/off', { id: b.dataset.off });
|
|
78
|
+
S.off = null; if (r && r.ok) S.list = S.list.filter((x) => x.id !== b.dataset.off); else S.err = (r && r.error) || 'The link could not be turned off.';
|
|
79
|
+
return draw();
|
|
80
|
+
}
|
|
81
|
+
const k = b.dataset.sh;
|
|
82
|
+
if (k === 'pw') { S.pw = !S.pw; return draw('[data-sh="pw"]'); }
|
|
83
|
+
if (k === 'new') { const p = await pmGet('/api/shares/password'); if (p && p.ok) S.pass = p.password; return draw('[data-sh="new"]'); }
|
|
84
|
+
if (k === 'send') {
|
|
85
|
+
try { await navigator.share({ files: [new File([f.text || ''], f.name || 'file.txt', { type: 'text/plain' })], title: f.name }); close(true); }
|
|
86
|
+
catch { /* the PM closed the share sheet */ }
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (k === 'make') {
|
|
90
|
+
if (S.pw && String(S.pass || '').trim().length < 8) { S.err = 'The password needs at least 8 characters.'; return draw(); }
|
|
91
|
+
S.busy = true; S.err = ''; draw();
|
|
92
|
+
const r = await pmPost('/api/shares', { ws: f.ws, path: f.rel, days: S.days, password: S.pw ? String(S.pass).trim() : null });
|
|
93
|
+
S.busy = false;
|
|
94
|
+
if (!r || !r.ok) { S.err = (r && r.error) || 'The link could not be made.'; return draw(); }
|
|
95
|
+
S.made = { url: r.url, ends: r.ends, pass: S.pw ? String(S.pass).trim() : '' };
|
|
96
|
+
const l = await pmGet('/api/shares'); if (l && l.ok) S.list = l.shares || [];
|
|
97
|
+
return draw('[data-sh="copy"]');
|
|
98
|
+
}
|
|
99
|
+
if (k === 'copy') {
|
|
100
|
+
const t = S.made.url + (S.made.pass ? '\nPassword: ' + S.made.pass : '');
|
|
101
|
+
try { await navigator.clipboard.writeText(t); S.copied = 'Copied'; }
|
|
102
|
+
catch { const c = m.querySelector('.vwsu'); if (c) { const r = document.createRange(); r.selectNodeContents(c); getSelection().removeAllRanges(); getSelection().addRange(r); } S.copied = 'Press Copy on your keyboard'; }
|
|
103
|
+
return draw('[data-sh="copy"]');
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
document.addEventListener('keydown', onKey, true);
|
|
107
|
+
draw();
|
|
108
|
+
box.append(m); btn.setAttribute('aria-expanded', 'true');
|
|
109
|
+
const first = m.querySelector('button'); if (first) first.focus();
|
|
110
|
+
setTimeout(() => document.addEventListener('click', function off(e) { if (!e.target.closest('.vwshp,[data-fsh]')) close(); if (!box.querySelector('.vwshp')) document.removeEventListener('click', off, true); }, true), 0);
|
|
111
|
+
load();
|
|
112
|
+
}
|
|
@@ -295,9 +295,24 @@ function paneHtml(r) {
|
|
|
295
295
|
+ (dr.step ? `<p class="agstep">Step when you approve: ${esc(dr.step)}</p>` : '')
|
|
296
296
|
+ `<div class="mdr${clip ? ' clipd' : ''}">${mdHtml(dr.body || dr.summary)}</div>${long ? `<button class="xtb" data-pp="all" type="button" aria-expanded="${!clip}">${clip ? 'Show all' : 'Show less'}</button>` : ''}</article>`;
|
|
297
297
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
// the dialog head already shows the title and its line, so the pane opens the source and keeps the record behind Details
|
|
299
|
+
const kv = p.rows && p.rows.length ? `<div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>` : '';
|
|
300
|
+
const sc = r.dialog.source;
|
|
301
|
+
if (sc) return h + srcHtml(sc) + `<details class="paper doc wkdet"><summary>Details</summary>${kv}<p class="xn">${esc(p.file)}</p></details>`;
|
|
302
|
+
return h + `<article class="paper doc">${kv}<p class="xn">The item as your list holds it · ${esc(p.file)}</p></article>`;
|
|
303
|
+
}
|
|
304
|
+
/* the message, ticket or thread the item came from, as the brief stored it: nothing is read live on open */
|
|
305
|
+
function srcHtml(sc) {
|
|
306
|
+
const by = [sc.who, sc.where ? 'in ' + sc.where : ''].filter(Boolean).join(' ');
|
|
307
|
+
let g = `<p class="agtag"><span class="agst">${esc(sc.name || 'Source')}</span>${by ? ' ' + esc(by) : ''}</p>`;
|
|
308
|
+
if (sc.thread && sc.thread.length) g += `<div class="wksrc">${sc.thread.map((m) => `<p class="wkmsg"><b>${esc(m.who || 'Someone')}</b>${m.at ? ` <span class="xn">${esc(m.at)}</span>` : ''}<br>${esc(m.text)}</p>`).join('')}</div>`;
|
|
309
|
+
else if (sc.quote) g += `<blockquote class="wkq">${esc(sc.quote)}</blockquote>`;
|
|
310
|
+
if (sc.ask && !(sc.thread && sc.thread.length) && !sc.quote) g += `<p><b>Asked:</b> ${esc(sc.ask)}</p>`;
|
|
311
|
+
if (sc.about) g += `<p>${esc(sc.about)}</p>`;
|
|
312
|
+
for (const rf of sc.refs || []) g += `<p class="wkref"><b>${rf.link ? `<a href="${esc(rf.link)}" target="_blank" rel="noopener">${esc(rf.label)}</a>` : esc(rf.label)}</b></p>${rf.lines.length ? `<ul>${rf.lines.map((l) => `<li>${esc(l)}</li>`).join('')}</ul>` : ''}`;
|
|
313
|
+
if (sc.evidence) g += `<p class="xn">Evidence: ${esc(sc.evidence)}</p>`;
|
|
314
|
+
if (sc.link) g += `<p><a class="xtb" href="${esc(sc.link)}" target="_blank" rel="noopener">Open in ${esc(sc.name || 'its source')}</a></p>`;
|
|
315
|
+
return `<article class="paper doc wksrcp">${g}</article>`;
|
|
301
316
|
}
|
|
302
317
|
const paneLabel = (r) => (r.dialog.agent && r.dialog.agent.draft && (r.dialog.agent.draft.body || r.dialog.agent.draft.summary) ? 'Draft and item record' : r.dialog.pane.label);
|
|
303
318
|
const paneSig = (r) => JSON.stringify([r.dialog.agent && r.dialog.agent.draft, r.dialog.agent && r.dialog.agent.round, r.dialog.agent && r.dialog.agent.state, r.dialog.pane]);
|
|
@@ -2707,3 +2707,14 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
|
|
|
2707
2707
|
.ctxpeek b{color:var(--ink);font-weight:600}
|
|
2708
2708
|
.ctxpeek em{font-style:normal;font-weight:600;color:var(--ink)}
|
|
2709
2709
|
.vwtk b{display:block}
|
|
2710
|
+
/* popup context slice 2: a Work item from the brief opens its source; the record folds behind Details */
|
|
2711
|
+
.wksrcp .wkmsg{margin:0 0 10px;font-size:var(--fs-3);line-height:1.5;overflow-wrap:anywhere}
|
|
2712
|
+
.wksrcp .wkq{margin:0 0 10px;padding:6px 12px;border-left:3px solid var(--hair);color:var(--ink-2);font-size:var(--fs-3);line-height:1.5}
|
|
2713
|
+
.wksrcp .wkref{margin:10px 0 2px}.wksrcp ul{margin:0 0 8px;padding-left:18px;font-size:var(--fs-3)}
|
|
2714
|
+
.wkdet summary{cursor:pointer;font:600 var(--t-micro) var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3)}
|
|
2715
|
+
.wkdet[open] summary{margin-bottom:10px}
|
|
2716
|
+
/* popup context slice 3: Claude's stored lead opens the conversation of a popup */
|
|
2717
|
+
.plead{margin:0 0 14px;padding:12px 14px;border-radius:12px;background:var(--well)}
|
|
2718
|
+
.plead p{margin:0 0 6px;font-size:var(--fs-3);line-height:1.5;overflow-wrap:anywhere}
|
|
2719
|
+
.plead .fine2{color:var(--ink-3)}
|
|
2720
|
+
.plead.none{display:flex;align-items:center;gap:10px;justify-content:space-between}.plead.none p{margin:0}
|
|
@@ -240,7 +240,9 @@ function cardHtml(r) {
|
|
|
240
240
|
function paneHtml(r) {
|
|
241
241
|
// as the mockup draws it: the record's path, its heading and one lead line, then its grid or sections
|
|
242
242
|
const p = r.dialog.pane, sel = SEL[r.key] || r.dialog.sel, o = (r.dialog.opts || []).find((x) => x.k === sel);
|
|
243
|
-
|
|
243
|
+
// the dialog head already shows the title and its line: the pane does not draw them a second time
|
|
244
|
+
const same = (a, b) => String(a || '').trim() === String(b || '').trim();
|
|
245
|
+
let h = `<p class="dpath">${esc(p.file || '')}</p>${p.h && !same(p.h, r.dialog.title || r.title) ? H1(p.h) : ''}${p.intro && !same(p.intro, r.dialog.sub || r.subject) ? P1(p.intro) : ''}`;
|
|
244
246
|
if (p.list) h = `<p class="dpath">planning/runs/evals.jsonl</p><ol class="stp">${r.dialog.items.map((x, k) => `<li><i>${k + 1}</i><span><b>${esc(x.t)}</b><small>${esc(x.m + ' · ' + x.s)}${x.lead ? '. ' + esc(x.lead) : ''}</small></span></li>`).join('')}</ol>`;
|
|
245
247
|
else if (p.optsDraft) h += H2('Evidence') + UL(p.evidence.filter((x) => x && x[1]).map(([k, v]) => k + ': ' + v)) + H2('Decision') + P1(o ? o.t + '. ' + o.draft : 'Choose an option to draft the entry.') + `<p class="xn">A draft. Nothing is written to the journal until you press Record.</p>`;
|
|
246
248
|
else h += (p.rows && p.rows.length ? kv(p.rows) : '') + (p.paras && p.paras.length ? (p.parasTitle ? H2(p.parasTitle) : '') + p.paras.map(P1).join('') : '') + `<p class="xn">The record as it stands. Nothing is drafted here.</p>`;
|
package/workspace/server.js
CHANGED
|
@@ -342,6 +342,32 @@ const accessKeys = require('./lib/access-keys');
|
|
|
342
342
|
const ONLINE = { settings: onlineMode.read(STATE), keys: null, keysTeam: null, fetchKeys: accessKeys.fetchCerts, find: onlineMode.findCloudflared,
|
|
343
343
|
lastRefusal: null }; // { reason, at } of the last refused sign-in: a fixed reason word only, never the assertion or a claim (D08)
|
|
344
344
|
const tunnel = onlineMode.createTunnel({ stateDir: STATE, find: () => ONLINE.find() });
|
|
345
|
+
// premium-viewer-share (D97): share links are served by share-server.js, a separate process on its own loopback port that reads only the
|
|
346
|
+
// share copies folder. This server starts it, restarts it when it exits, and stops it with itself. It answers the internet only when the PM's
|
|
347
|
+
// tunnel sends the share hostname to SHARE_PORT; the workspace's own hostname and its Access check are unchanged.
|
|
348
|
+
const shareStore = require('./lib/share-store');
|
|
349
|
+
const SHARE_PORT = Number(process.env.PMOS_SHARE_PORT) || (PORT + 1);
|
|
350
|
+
const SHARE = { child: null, stopped: false, timer: null };
|
|
351
|
+
function startShareServer() {
|
|
352
|
+
if (SHARE.child || SHARE.stopped || process.env.PMOS_SHARE_SERVER === 'off') return;
|
|
353
|
+
try {
|
|
354
|
+
SHARE.child = require('child_process').spawn(process.execPath, [path.join(__dirname, 'share-server.js')],
|
|
355
|
+
{ stdio: 'ignore', env: { PATH: process.env.PATH || '', PMOS_STATE_DIR: STATE, PMOS_SHARE_PORT: String(SHARE_PORT), PMOS_SHARE_PARENT: String(process.pid) } });
|
|
356
|
+
} catch { SHARE.child = null; return; }
|
|
357
|
+
const mine = SHARE.child;
|
|
358
|
+
mine.on('error', () => {});
|
|
359
|
+
mine.on('exit', () => { if (SHARE.child !== mine) return; SHARE.child = null; if (!SHARE.stopped && !SHARE.timer) { SHARE.timer = setTimeout(() => { SHARE.timer = null; startShareServer(); }, 5000); if (SHARE.timer.unref) SHARE.timer.unref(); } });
|
|
360
|
+
}
|
|
361
|
+
function stopShareServer() { SHARE.stopped = true; if (SHARE.timer) clearTimeout(SHARE.timer); const c = SHARE.child; SHARE.child = null; if (c) { try { c.kill('SIGTERM'); } catch { /* gone */ } } }
|
|
362
|
+
/** The hostname a share link names: PMOS_SHARE_HOST, else share.<the Online hostname's domain>, else null (Online is not set up). */
|
|
363
|
+
function shareHost() {
|
|
364
|
+
const env = String(process.env.PMOS_SHARE_HOST || '').trim().toLowerCase();
|
|
365
|
+
if (env) return remoteAccess.parsePublicHost(env).refused ? null : env;
|
|
366
|
+
const h = ONLINE.settings.host;
|
|
367
|
+
if (!h) return null;
|
|
368
|
+
const parts = h.split('.');
|
|
369
|
+
return 'share.' + (parts.length > 2 ? parts.slice(1).join('.') : h);
|
|
370
|
+
}
|
|
345
371
|
/** The public hostname the guards admit right now: the environment's, else the Online switch's while it is on. */
|
|
346
372
|
function publicHost() { return BIND.publicHost || (ONLINE.settings.on ? ONLINE.settings.host : null); }
|
|
347
373
|
/** True when this request is addressed to the Online switch's hostname, so the Access assertion decides it (D89). */
|
|
@@ -7527,6 +7553,43 @@ async function handleRequest(req, res) {
|
|
|
7527
7553
|
const r = chatFileLocate.locate({ path: url.searchParams.get('path') || '', roots: [...workspaces.values()].map((w) => ({ id: w.id, root: w.root })), base: base ? base.id : null, home: os.homedir() });
|
|
7528
7554
|
return json(res, r);
|
|
7529
7555
|
}
|
|
7556
|
+
/* ── premium-viewer-share (D97): share links. Listing is a read; making and turning off a link is a page press, never an agent session. ── */
|
|
7557
|
+
if (p === '/api/shares' && req.method === 'GET') {
|
|
7558
|
+
const host = shareHost();
|
|
7559
|
+
return json(res, { ok: true, host, days: shareStore.DAYS, shares: shareStore.list(STATE).map((x) => ({ ...x, url: host ? `https://${host}/s/${x.id}` : null })) });
|
|
7560
|
+
}
|
|
7561
|
+
if (p === '/api/shares/password' && req.method === 'GET') return json(res, { ok: true, password: shareStore.newPassword() });
|
|
7562
|
+
if ((p === '/api/shares' || p === '/api/shares/off') && req.method === 'POST') {
|
|
7563
|
+
if (req.headers['x-pmos-session']) return json(res, { ok: false, error: 'An agent session cannot make or turn off a share link. Only a press on the page does.' }, 403);
|
|
7564
|
+
let body = {};
|
|
7565
|
+
try { body = JSON.parse((await readBody(req)) || '{}'); } catch { return json(res, { ok: false, error: 'invalid JSON body' }, 400); }
|
|
7566
|
+
const g = pmGuard.requirePagePress(req, body);
|
|
7567
|
+
if (!g.ok) return json(res, { ok: false, error: g.error }, g.status);
|
|
7568
|
+
if (p === '/api/shares/off') {
|
|
7569
|
+
const id = String(body.id || '');
|
|
7570
|
+
if (!shareStore.ID_RX.test(id)) return json(res, { ok: false, error: 'no such link' }, 404);
|
|
7571
|
+
shareStore.remove(STATE, id);
|
|
7572
|
+
return json(res, { ok: true });
|
|
7573
|
+
}
|
|
7574
|
+
const host = shareHost();
|
|
7575
|
+
if (!host) return json(res, { ok: false, error: 'Share links use your Online hostname. Set up Online in Settings first, or set PMOS_SHARE_HOST.' }, 409);
|
|
7576
|
+
const w = getWs(body.ws);
|
|
7577
|
+
const rel = String(body.path || '');
|
|
7578
|
+
const got = w ? readTextDocWhy(w.root, rel) : { ok: false, reason: 'no such workspace' };
|
|
7579
|
+
if (!got.ok) return json(res, { ok: false, error: got.reason }, 404);
|
|
7580
|
+
// the local secret scan first: a key or token in the file blocks the link, and the answer names the rule, never the text (D08)
|
|
7581
|
+
const hits = require('./lib/secret-scan').scan(got.text);
|
|
7582
|
+
if (hits.length) return json(res, { ok: false, error: 'This file holds what looks like a secret (' + hits.join(', ') + '). Remove it, then share again.', secrets: hits }, 422);
|
|
7583
|
+
const name = path.basename(rel);
|
|
7584
|
+
const kind = got.kind === 'html' ? 'html' : got.kind === 'markdown' ? 'markdown' : 'text';
|
|
7585
|
+
let page;
|
|
7586
|
+
try { const F = await import('./public/pm/premium-vw-file.js'); page = kind === 'html' ? got.text : F.pageSrc({ name, kind, text: got.text }); }
|
|
7587
|
+
catch { return json(res, { ok: false, error: 'The copy could not be made.' }, 500); }
|
|
7588
|
+
const r = shareStore.create(STATE, { name, kind, page, file: got.text, days: Number(body.days), password: body.password == null || body.password === '' ? null : String(body.password) });
|
|
7589
|
+
if (!r.ok) return json(res, { ok: false, error: r.error }, 400);
|
|
7590
|
+
startShareServer();
|
|
7591
|
+
return json(res, { ok: true, id: r.id, ends: r.ends, url: `https://${host}/s/${r.id}` });
|
|
7592
|
+
}
|
|
7530
7593
|
if (p === '/api/doc/export') {
|
|
7531
7594
|
// A markdown file from the viewer's download menu as Word (premium-viewer-share D4). The same guard as GET /api/doc
|
|
7532
7595
|
// (readTextDocWhy: inside the workspace, text only), built in memory by lib/report-export.js. It writes nothing and is never cached.
|
|
@@ -10124,6 +10187,7 @@ if (require.main === module) {
|
|
|
10124
10187
|
for (const s of sessions.values()) if (s.pty) { try { persist(s); } catch {} }
|
|
10125
10188
|
for (const l of listeners) { try { l.close(); } catch {} }
|
|
10126
10189
|
try { tunnel.stop(); } catch {} // workspace-online-mode: the tunnel is this server's child and ends with it
|
|
10190
|
+
try { stopShareServer(); } catch {} // premium-viewer-share: so is the share server
|
|
10127
10191
|
try { fs.unlinkSync(PID_FILE); } catch {} // stop being discoverable the moment we stop serving
|
|
10128
10192
|
try { scheduleOwner.release(); } catch {} // another server can run the schedules at once
|
|
10129
10193
|
process.exit(0);
|
|
@@ -10159,6 +10223,7 @@ if (require.main === module) {
|
|
|
10159
10223
|
for (const line of remoteAccess.startupLines(BIND, PORT, { ansi: !!process.stdout.isTTY && !process.env.NO_COLOR })) console.log(line);
|
|
10160
10224
|
// workspace-online-mode: a workspace that stopped while Online was on comes back online (PRD O2)
|
|
10161
10225
|
applyOnline();
|
|
10226
|
+
if (shareStore.list(STATE).length) startShareServer(); // premium-viewer-share (D97): the share links' own server, on loopback, only while a link is open
|
|
10162
10227
|
if (ONLINE.settings.on && !BIND.publicHost) console.log(` online: https://${ONLINE.settings.host}/ (Cloudflare Access sign-in, tunnel ${ONLINE.settings.tunnel})`);
|
|
10163
10228
|
// bring in what another machine pushed while this one was off (D70 as amended); never on the request path
|
|
10164
10229
|
{ const t = setTimeout(() => { autoSync.startup().catch(() => {}); }, 3000); if (t.unref) t.unref(); }
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* share-server.js — the one PMOS server that answers someone with no PMOS login (premium-viewer-share slice 2, D97).
|
|
4
|
+
*
|
|
5
|
+
* It is a separate process from the workspace server, on its own loopback port, and it knows nothing of the workspace: no terminal, no
|
|
6
|
+
* API, no WebSocket, no repository, no token, no settings. It reads only the share copies folder (lib/share-store.js) and writes only a
|
|
7
|
+
* link's view count and wrong-password count there. The workspace server starts it and stops it. The PM's Cloudflare tunnel sends the
|
|
8
|
+
* share hostname (share.pm-os.app) here, with no Access application in front; the workspace hostname keeps its Access check.
|
|
9
|
+
*
|
|
10
|
+
* GET /robots.txt Disallow: /
|
|
11
|
+
* GET /s/<id> the password page, or the copy in a sandboxed frame with Download
|
|
12
|
+
* POST /s/<id> the password form (pw=…): a right password sets a cookie for this link only, for 12 hours
|
|
13
|
+
* GET /s/<id>/view the copy itself, under a sandbox CSP (only with a valid cookie when the link has a password)
|
|
14
|
+
* GET /s/<id>/file the file's own text as an attachment (the same rule)
|
|
15
|
+
* anything else 404
|
|
16
|
+
*
|
|
17
|
+
* Every answer: X-Robots-Tag noindex, Cache-Control no-store, Referrer-Policy no-referrer, nosniff, frame-ancestors limited. An unknown,
|
|
18
|
+
* ended or turned-off link reads "This link is no longer active" and names nothing. Nothing is logged (D08).
|
|
19
|
+
*
|
|
20
|
+
* PMOS_SHARE_PORT the port (required) PMOS_STATE_DIR the runtime state folder that holds shares/
|
|
21
|
+
* PMOS_SHARE_PARENT the workspace server's pid: the share server exits when that process is gone
|
|
22
|
+
*/
|
|
23
|
+
const http = require('http');
|
|
24
|
+
const store = require('./lib/share-store');
|
|
25
|
+
|
|
26
|
+
const DIR = process.env.PMOS_STATE_DIR;
|
|
27
|
+
const PORT = Number(process.env.PMOS_SHARE_PORT);
|
|
28
|
+
const HOST = '127.0.0.1';
|
|
29
|
+
|
|
30
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
31
|
+
const BASE_HEADERS = {
|
|
32
|
+
'X-Robots-Tag': 'noindex, nofollow, noarchive', 'Cache-Control': 'no-store, private', 'Referrer-Policy': 'no-referrer',
|
|
33
|
+
'X-Content-Type-Options': 'nosniff', 'Cross-Origin-Opener-Policy': 'same-origin', 'Permissions-Policy': 'camera=(), microphone=(), geolocation=()',
|
|
34
|
+
};
|
|
35
|
+
const PAGE_CSP = "default-src 'none'; style-src 'unsafe-inline'; frame-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'";
|
|
36
|
+
// the copy itself: the viewer's own sandbox (premium-vw-file.js FRAME_CSP), shown only inside its own page
|
|
37
|
+
const VIEW_CSP = (scripts) => `sandbox${scripts ? ' allow-scripts' : ''}; default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:; script-src ${scripts ? "'unsafe-inline'" : "'none'"}; frame-ancestors 'self'; base-uri 'none'; form-action 'none'`;
|
|
38
|
+
|
|
39
|
+
function send(res, status, body, headers = {}) {
|
|
40
|
+
res.writeHead(status, { ...BASE_HEADERS, 'Content-Type': 'text/html; charset=utf-8', 'Content-Security-Policy': PAGE_CSP, 'X-Frame-Options': 'DENY', ...headers });
|
|
41
|
+
res.end(body);
|
|
42
|
+
}
|
|
43
|
+
const STYLE = `<style>:root{color-scheme:light dark;--bg:#f6f6f4;--card:#fff;--ink:#14161f;--mut:#6e7486;--hair:rgba(20,24,40,.12);--solid:#14161f;--on:#fff;--bad:#be3434}
|
|
44
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0e1016;--card:#171a23;--ink:#f3f4f8;--mut:#9aa0b4;--hair:rgba(255,255,255,.12);--solid:#f3f4f8;--on:#14161f;--bad:#f06e6e}}
|
|
45
|
+
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.5 -apple-system,"Segoe UI",system-ui,sans-serif}
|
|
46
|
+
.box{max-width:340px;margin:18vh auto 0;padding:0 16px;text-align:center}h1{font-size:20px;margin:0 0 6px}p{color:var(--mut);margin:0 0 16px}
|
|
47
|
+
input{width:100%;font:inherit;padding:11px 12px;border-radius:12px;border:1px solid var(--hair);background:var(--card);color:var(--ink);margin:0 0 10px}
|
|
48
|
+
button,.btn{display:inline-block;width:100%;font:600 15px/1 inherit;padding:12px;border:0;border-radius:99px;background:var(--solid);color:var(--on);cursor:pointer;text-decoration:none}
|
|
49
|
+
.bad{color:var(--bad)}.wrap{display:flex;flex-direction:column;height:100vh;height:100dvh}iframe{flex:1;width:100%;border:0;background:#fff}
|
|
50
|
+
.bar{display:flex;gap:12px;align-items:center;padding:10px max(16px,env(safe-area-inset-left));border-top:1px solid var(--hair);font-size:13px;color:var(--mut);background:var(--card)}
|
|
51
|
+
.bar span{flex:1;min-width:0}.bar .btn{width:auto;padding:9px 16px;font-size:13px}</style>`;
|
|
52
|
+
const doc = (title, body) => `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex,nofollow,noarchive"><title>${esc(title)}</title>${STYLE}</head><body>${body}</body></html>`;
|
|
53
|
+
const gone = (res) => send(res, 404, doc('Link not active', '<div class="box"><h1>This link is no longer active</h1><p>Ask the person who sent it for a new one.</p></div>'));
|
|
54
|
+
const day = (iso) => new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' });
|
|
55
|
+
function lockPage(res, id, note, status = 200) {
|
|
56
|
+
// the password page names neither PMOS nor the file, so a link preview or a stranger learns nothing from it
|
|
57
|
+
send(res, status, doc('Protected page', `<div class="box"><h1>This page is protected</h1><p${note ? ' class="bad"' : ''}>${esc(note || 'Enter the password you were given.')}</p>`
|
|
58
|
+
+ `<form method="post" action="/s/${esc(id)}"><input type="password" name="pw" autocomplete="current-password" aria-label="Password" placeholder="Password" required autofocus><button type="submit">Open</button></form></div>`));
|
|
59
|
+
}
|
|
60
|
+
function cookieOf(req) {
|
|
61
|
+
const m = /(?:^|;\s*)s=([^;]+)/.exec(String(req.headers.cookie || ''));
|
|
62
|
+
return m ? decodeURIComponent(m[1]) : '';
|
|
63
|
+
}
|
|
64
|
+
function readForm(req) {
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
let n = 0; const parts = [];
|
|
67
|
+
req.on('data', (c) => { n += c.length; if (n > 2048) { req.destroy(); resolve(null); } else parts.push(c); });
|
|
68
|
+
req.on('end', () => { try { resolve(new URLSearchParams(Buffer.concat(parts).toString('utf8'))); } catch { resolve(null); } });
|
|
69
|
+
req.on('error', () => resolve(null));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function handle(req, res) {
|
|
74
|
+
let url;
|
|
75
|
+
try { url = new URL(req.url, 'http://share.invalid'); } catch { return send(res, 400, doc('Bad request', '')); }
|
|
76
|
+
const p = url.pathname;
|
|
77
|
+
if (req.method !== 'GET' && req.method !== 'HEAD' && req.method !== 'POST') return send(res, 405, doc('Not allowed', ''), { Allow: 'GET, POST' });
|
|
78
|
+
if (p === '/robots.txt' && req.method !== 'POST') { res.writeHead(200, { ...BASE_HEADERS, 'Content-Type': 'text/plain; charset=utf-8' }); return res.end('User-agent: *\nDisallow: /\n'); }
|
|
79
|
+
const m = /^\/s\/([A-Za-z0-9_-]{22})(\/view|\/file)?$/.exec(p);
|
|
80
|
+
if (!m) return send(res, 404, doc('Not found', '<div class="box"><h1>Not found</h1></div>'));
|
|
81
|
+
const id = m[1], part = m[2] || '';
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
const meta = store.get(DIR, id, now);
|
|
84
|
+
if (!meta) return gone(res);
|
|
85
|
+
const open = !meta.pw || store.verifyCookie(meta, cookieOf(req), now);
|
|
86
|
+
|
|
87
|
+
if (req.method === 'POST') {
|
|
88
|
+
if (part) return send(res, 405, doc('Not allowed', ''));
|
|
89
|
+
if (!meta.pw) { res.writeHead(303, { ...BASE_HEADERS, Location: '/s/' + id }); return res.end(); }
|
|
90
|
+
const form = await readForm(req);
|
|
91
|
+
const r = store.checkPassword(DIR, id, form ? form.get('pw') : '', now);
|
|
92
|
+
if (r.ok) {
|
|
93
|
+
const until = now + store.COOKIE_MS;
|
|
94
|
+
res.writeHead(303, { ...BASE_HEADERS, Location: '/s/' + id,
|
|
95
|
+
'Set-Cookie': `s=${encodeURIComponent(store.sign(meta, until))}; Path=/s/${id}; Max-Age=${store.COOKIE_MS / 1000}; HttpOnly; Secure; SameSite=Lax` });
|
|
96
|
+
return res.end();
|
|
97
|
+
}
|
|
98
|
+
if (r.locked) return lockPage(res, id, 'Too many wrong tries. Try again in 15 minutes.', 429);
|
|
99
|
+
return lockPage(res, id, `That password is not right. ${r.left} ${r.left === 1 ? 'try' : 'tries'} left before a 15-minute wait.`, 401);
|
|
100
|
+
}
|
|
101
|
+
if (!open) return part ? gone(res) : lockPage(res, id);
|
|
102
|
+
if (part === '/view') {
|
|
103
|
+
const page = store.readPart(DIR, id, 'page.html');
|
|
104
|
+
if (page == null) return gone(res);
|
|
105
|
+
res.writeHead(200, { ...BASE_HEADERS, 'Content-Type': 'text/html; charset=utf-8', 'Content-Security-Policy': VIEW_CSP(meta.kind === 'html'), 'X-Frame-Options': 'SAMEORIGIN' });
|
|
106
|
+
return res.end(req.method === 'HEAD' ? undefined : page);
|
|
107
|
+
}
|
|
108
|
+
if (part === '/file') {
|
|
109
|
+
const text = store.readPart(DIR, id, 'file');
|
|
110
|
+
if (text == null) return gone(res);
|
|
111
|
+
const name = meta.name.replace(/[^A-Za-z0-9._-]+/g, '-').slice(0, 120) || 'file.txt';
|
|
112
|
+
res.writeHead(200, { ...BASE_HEADERS, 'Content-Type': 'application/octet-stream', 'Content-Disposition': `attachment; filename="${name}"`, 'Content-Security-Policy': "default-src 'none'; sandbox" });
|
|
113
|
+
return res.end(req.method === 'HEAD' ? undefined : text);
|
|
114
|
+
}
|
|
115
|
+
if (req.method === 'GET') store.view(DIR, id, now);
|
|
116
|
+
return send(res, 200, doc(meta.name, `<div class="wrap"><iframe src="/s/${esc(id)}/view" title="${esc(meta.name)}" sandbox="${meta.kind === 'html' ? 'allow-scripts' : ''}" referrerpolicy="no-referrer"></iframe>`
|
|
117
|
+
+ `<div class="bar"><span>A shared copy, made ${esc(day(meta.made))}. The link ends ${esc(day(meta.ends))}.</span><a class="btn" href="/s/${esc(id)}/file" download>Download</a></div></div>`));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function start({ port = PORT, host = HOST } = {}) {
|
|
121
|
+
const server = http.createServer((req, res) => { handle(req, res).catch(() => { try { send(res, 500, doc('Error', '')); } catch { /* the socket is gone */ } }); });
|
|
122
|
+
server.listen(port, host);
|
|
123
|
+
return server;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (require.main === module) {
|
|
127
|
+
if (!DIR || !(PORT > 0)) { console.error('share-server: PMOS_STATE_DIR and PMOS_SHARE_PORT are required'); process.exit(2); }
|
|
128
|
+
const s = start();
|
|
129
|
+
s.on('error', (e) => { console.error('share-server: ' + (e.code === 'EADDRINUSE' ? `port ${PORT} is in use` : 'could not listen')); process.exit(1); });
|
|
130
|
+
process.on('SIGTERM', () => { s.close(); process.exit(0); });
|
|
131
|
+
// it lives only as long as the workspace server that started it: a parent killed without a goodbye leaves no share server behind
|
|
132
|
+
const parent = Number(process.env.PMOS_SHARE_PARENT);
|
|
133
|
+
if (parent > 0) setInterval(() => { try { process.kill(parent, 0); } catch { process.exit(0); } }, 5000).unref();
|
|
134
|
+
}
|
|
135
|
+
module.exports = { start, handle, VIEW_CSP, PAGE_CSP };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_comment": "
|
|
2
|
+
"_comment": "Download and share a file from the viewer (premium-viewer-share): the download icon and GET /api/doc/export; share links through lib/share-store.js, POST /api/shares and share-server.js (D97), with the guest's password page. Real server, 390 and 1280 wide.",
|
|
3
3
|
"seconds": {
|
|
4
|
-
"premium-viewer-download-test.js": 30
|
|
4
|
+
"premium-viewer-download-test.js": 30,
|
|
5
|
+
"premium-viewer-share-test.js": 40
|
|
5
6
|
},
|
|
6
7
|
"panels": [
|
|
7
|
-
"premium-viewer-download-test.js"
|
|
8
|
+
"premium-viewer-download-test.js",
|
|
9
|
+
"premium-viewer-share-test.js"
|
|
8
10
|
]
|
|
9
11
|
}
|