create-pmos 0.378.0 → 0.379.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 +13 -13
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/briefing-premium-test.js +1 -1
- package/workspace/changelog.json +12 -0
- package/workspace/guide/briefing-premium.md +13 -8
- package/workspace/lib/chat-files.js +50 -3
- package/workspace/lib/routes-briefing-premium.js +18 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-chat-attach-test.js +2 -3
- package/workspace/premium-chat-notes-test.js +146 -0
- package/workspace/public/pm/premium-attach.js +17 -6
- package/workspace/public/pm/premium-notes.js +227 -0
- package/workspace/public/pm/premium-shell.js +6 -6
- package/workspace/public/pm/premium-vw-notepad.css +41 -0
- package/workspace/public/pm/premium.css +1 -21
- package/workspace/test-lists/premium-chat-notes.json +13 -0
- package/workspace/premium-pad-test.js +0 -125
- package/workspace/public/pm/premium-pad.js +0 -89
- package/workspace/test-lists/premium-pad.json +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.379.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": {
|
|
@@ -32,6 +32,18 @@
|
|
|
32
32
|
"audit"
|
|
33
33
|
],
|
|
34
34
|
"pmosChanges": [
|
|
35
|
+
{
|
|
36
|
+
"v": "0.379.0",
|
|
37
|
+
"at": "2026-10-21T08:59:34.421Z",
|
|
38
|
+
"f": 2,
|
|
39
|
+
"prs": [
|
|
40
|
+
{
|
|
41
|
+
"n": 988,
|
|
42
|
+
"t": "Notes replace the Scratchpad in the premium chat",
|
|
43
|
+
"s": "Notes replace the Scratchpad in the premium chat"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
},
|
|
35
47
|
{
|
|
36
48
|
"v": "0.378.0",
|
|
37
49
|
"at": "2026-10-21T07:48:19.057Z",
|
|
@@ -309,18 +321,6 @@
|
|
|
309
321
|
"s": "There is no Agents tab."
|
|
310
322
|
}
|
|
311
323
|
]
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
"v": "0.359.0",
|
|
315
|
-
"at": "2026-10-20T13:30:13.743Z",
|
|
316
|
-
"f": 2,
|
|
317
|
-
"prs": [
|
|
318
|
-
{
|
|
319
|
-
"n": 958,
|
|
320
|
-
"t": "The phone rail returns to the bottom after the keyboard closes",
|
|
321
|
-
"s": "When a field loses focus or the keyboard closes, the bar goes back to the bottom of the screen and the dock back to the top."
|
|
322
|
-
}
|
|
323
|
-
]
|
|
324
324
|
}
|
|
325
325
|
]
|
|
326
326
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-21T08:59:30Z"}
|
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-21T08:59:30Z"}
|
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-21T08:59:30Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -414,7 +414,7 @@ const MOCKUP = path.join(__dirname, '..', 'prototype', 'premium-ux-concept', 'br
|
|
|
414
414
|
ok('W3 "Tomorrow" posts the key and the time, and closes the dialog', await until(() => posts.some((x) => x.path === '/api/briefing-premium/put-off' && x.body.key === 'decision:KC5' && x.body.until === 'tomorrow')) && await until(() => pg.evaluate(() => !document.querySelector('#dlg').classList.contains('on'))));
|
|
415
415
|
// slice 3: the read-only agent behind the reply box
|
|
416
416
|
await shut(); await openIdx(3);
|
|
417
|
-
ok('A1 the reply box has one Send to Claude button, 44 px, and no note button', await pg.evaluate(() => { const a = document.querySelector('#askGo'); const h = (e) => e.getBoundingClientRect().height; return !!a && h(a) >= 44 && /Send to Claude/.test(a.title) && !document.querySelector('#noteGo') &&
|
|
417
|
+
ok('A1 the reply box has one Send to Claude button, 44 px, and no note button', await pg.evaluate(() => { const a = document.querySelector('#askGo'); const h = (e) => e.getBoundingClientRect().height; return !!a && h(a) >= 44 && /Send to Claude/.test(a.title) && !document.querySelector('#noteGo') && ![...document.querySelector('#askF').childNodes].filter((n) => n.id !== 'plusM').some((n) => /note/i.test(n.textContent)); })); // the + menu's Notes item opens the notepad, not a note button
|
|
418
418
|
ok('A1b a hidden question box is not drawn (the Mentions dialog has no agent thread)', await pg.evaluate(() => { const f = document.querySelector('#askF'); if (!f) return false; f.hidden = true; const d = getComputedStyle(f).display; f.hidden = false; return d === 'none'; }));
|
|
419
419
|
answer = { status: 200, body: { ok: true, id: 'bq-1', state: 'working' } };
|
|
420
420
|
await pg.fill('#askIn', 'Why is KC5 on my list?');
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.379.0",
|
|
4
|
+
"at": "2026-10-21T08:59:34.421Z",
|
|
5
|
+
"f": 2,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 988,
|
|
9
|
+
"t": "Notes replace the Scratchpad in the premium chat",
|
|
10
|
+
"s": "Notes replace the Scratchpad in the premium chat"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
2
14
|
{
|
|
3
15
|
"v": "0.378.0",
|
|
4
16
|
"at": "2026-10-21T07:48:19.057Z",
|
|
@@ -427,19 +427,24 @@ The conversation beside every premium dialog is a real Claude Code session. Anyt
|
|
|
427
427
|
|
|
428
428
|
Sending and the option presses need the page's launch nonce, so an agent session cannot type into your chat.
|
|
429
429
|
|
|
430
|
-
###
|
|
430
|
+
### Notes
|
|
431
431
|
|
|
432
|
-
|
|
432
|
+
Notes is a notepad for each conversation. Open it from **+** › **Notes**. It opens in the viewer beside the conversation. On a phone, it opens on the viewer tab.
|
|
433
433
|
|
|
434
|
-
- The
|
|
435
|
-
-
|
|
436
|
-
-
|
|
437
|
-
- To
|
|
438
|
-
-
|
|
434
|
+
- A conversation can have more than one note. The head shows the title of the note (its first line) and how many notes there are. Press the title to see the list and pick a note. **Delete this note** is at the end of the list. It asks first.
|
|
435
|
+
- The **+** button in the head makes a new note.
|
|
436
|
+
- Each note is saved as you type, as a Markdown file on this machine (`chat-files/<conversation>/notes/`). It never goes into a repository. The head says **Saved**.
|
|
437
|
+
- To format, type a start at the beginning of a line and then a space: `#`, `##` or `###` for a heading, `-` for a bullet, `1.` for a numbered list and `[]` for a checkbox. Ctrl+B (Cmd+B on a Mac) makes text bold and Ctrl+I makes it italic. Press a checkbox to tick it.
|
|
438
|
+
- In a checkbox list, Enter makes the next checkbox. Enter on an empty checkbox ends the list.
|
|
439
|
+
- The two buttons at the bottom have icons only. Hold the pointer on a button to see its name.
|
|
440
|
+
- **Add selection to message** (the arrow into a line) puts the words you selected into the message box. With nothing selected, it puts the whole note there. Nothing is sent.
|
|
441
|
+
- **Share with Claude** (the arrow up out of a box) puts the note on your message as a file, like an attachment. Claude reads the note when you send. Your message shows it as a **Note** chip. Press the chip to open the note.
|
|
442
|
+
- The old Scratchpad text of a conversation becomes its first note when you open Notes. Nothing is lost.
|
|
443
|
+
- A dialog with no conversation has no Notes.
|
|
439
444
|
|
|
440
445
|
### Attach files and photos
|
|
441
446
|
|
|
442
|
-
Press **+** at the left of the message box. The menu has three items: **Add files or photos**, **Slash commands** and **
|
|
447
|
+
Press **+** at the left of the message box. The menu has three items: **Add files or photos**, **Slash commands** and **Notes**.
|
|
443
448
|
|
|
444
449
|
- **Add files or photos** opens the file chooser. You can pick more than one file. On a phone, the phone shows its own choices, such as Take Photo and Photo Library.
|
|
445
450
|
- On a computer, you can also drag a file onto the conversation, or paste a screenshot into the message box.
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* withFiles(text, paths) → the message with the closing line that names each file for Claude
|
|
9
9
|
* splitFiles(text) → { text, files: [path] } the same line read back, for the PM's bubble
|
|
10
10
|
* servable(runtimeDir, p) → { ok, file, size, type, inline } | { ok: false, … } GET /api/chat-file?path=
|
|
11
|
+
* listNotes / saveNote / removeNote Notes (premium-chat-notes): Markdown files in the same folder,
|
|
12
|
+
* under notes/, so Share with Claude names one like an attachment
|
|
11
13
|
*
|
|
12
14
|
* The files live in the workspace state folder, never in a repository, so nothing reaches git. The chat sessions start with
|
|
13
15
|
* the chat-files folder as an added directory, so Claude reads an attachment without a permission question. Nothing here
|
|
@@ -39,6 +41,10 @@ function cleanName(name) {
|
|
|
39
41
|
/** The stored name: a time prefix keeps two files of the same name apart and orders the folder. */
|
|
40
42
|
const storedName = (name, now = new Date()) => now.toISOString().replace(/[-:]/g, '').replace(/\..*$/, '') + '-' + cleanName(name);
|
|
41
43
|
const NAME_RE = /^\d{8}T\d{6}-[\w.-]{1,96}$/;
|
|
44
|
+
const NOTES = 'notes', NOTE_RE = /^n[0-9a-z]{6,16}$/, NOTE_MAX = 200000;
|
|
45
|
+
const notesDir = (runtimeDir, key) => path.join(dirOf(runtimeDir, key), NOTES);
|
|
46
|
+
/** A message may name a saved file, or a note as notes/<id>.md. */
|
|
47
|
+
const nameOk = (n) => NAME_RE.test(n) || (n.startsWith(NOTES + '/') && NOTE_RE.test(n.slice(NOTES.length + 1).replace(/\.md$/, '')) && n.endsWith('.md'));
|
|
42
48
|
|
|
43
49
|
function save({ runtimeDir, key, name, buf, now = new Date() }) {
|
|
44
50
|
if (!runtimeDir) return fail(409, 'this workspace has no state folder to keep the file in');
|
|
@@ -66,7 +72,7 @@ function pathsOf({ runtimeDir, key, names }) {
|
|
|
66
72
|
const dir = runtimeDir && key ? dirOf(runtimeDir, key) : null;
|
|
67
73
|
const paths = [];
|
|
68
74
|
for (const n of names) {
|
|
69
|
-
const f = dir &&
|
|
75
|
+
const f = dir && nameOk(String(n || '')) ? path.join(dir, String(n)) : null;
|
|
70
76
|
if (!f || !fs.existsSync(f)) return fail(400, 'A file on this message was not saved: ' + String(n || '').slice(0, 80));
|
|
71
77
|
paths.push(f);
|
|
72
78
|
}
|
|
@@ -89,11 +95,52 @@ function splitFiles(text) {
|
|
|
89
95
|
function servable(runtimeDir, p) {
|
|
90
96
|
if (!runtimeDir) return fail(404, 'no such file');
|
|
91
97
|
const root = path.resolve(rootOf(runtimeDir)), f = path.resolve(String(p || ''));
|
|
92
|
-
|
|
98
|
+
const att = path.dirname(path.dirname(f)) === root && NAME_RE.test(path.basename(f));
|
|
99
|
+
const note = path.basename(path.dirname(f)) === NOTES && path.dirname(path.dirname(path.dirname(f))) === root && NOTE_RE.test(path.basename(f, '.md')) && f.endsWith('.md');
|
|
100
|
+
if (!att && !note) return fail(404, 'no such file');
|
|
93
101
|
let st; try { st = fs.lstatSync(f); } catch { return fail(404, 'no such file'); }
|
|
94
102
|
if (!st.isFile()) return fail(404, 'no such file');
|
|
95
103
|
const type = KINDS[path.extname(f).toLowerCase()] || 'application/octet-stream';
|
|
96
104
|
return { ok: true, file: f, size: st.size, type, inline: INLINE.has(type) };
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
|
|
107
|
+
/** A note's title: its first line that has words, without the heading marks. Pure. */
|
|
108
|
+
function noteTitle(text) {
|
|
109
|
+
const l = String(text || '').split('\n').map((x) => x.replace(/^\s*(#{1,6}\s+|[-*+]\s+(\[[ xX]\]\s+)?|\d+[.)]\s+|>\s*)/, '').replace(/[*_`]/g, '').trim()).find(Boolean);
|
|
110
|
+
return (l || 'Untitled note').slice(0, 80);
|
|
111
|
+
}
|
|
112
|
+
/** The notes of a conversation, oldest first: { id, title, text, path, mtime }. */
|
|
113
|
+
function listNotes({ runtimeDir, key }) {
|
|
114
|
+
if (!runtimeDir || !key) return fail(400, 'key must name a conversation');
|
|
115
|
+
const dir = notesDir(runtimeDir, key);
|
|
116
|
+
let names = []; try { names = fs.readdirSync(dir); } catch { return { ok: true, notes: [] }; }
|
|
117
|
+
const notes = names.filter((n) => n.endsWith('.md') && NOTE_RE.test(n.slice(0, -3))).map((n) => {
|
|
118
|
+
const f = path.join(dir, n); let text = '', mtime = 0;
|
|
119
|
+
try { text = fs.readFileSync(f, 'utf8'); mtime = fs.statSync(f).mtimeMs; } catch { /* gone between the read and the list */ }
|
|
120
|
+
return { id: n.slice(0, -3), title: noteTitle(text), text, path: f, mtime };
|
|
121
|
+
});
|
|
122
|
+
notes.sort((a, b) => (a.id < b.id ? -1 : 1));
|
|
123
|
+
return { ok: true, notes };
|
|
124
|
+
}
|
|
125
|
+
/** Save a note. No id: a new note, named by the time so the list keeps the order they were made in. */
|
|
126
|
+
function saveNote({ runtimeDir, key, id, text, now = Date.now() }) {
|
|
127
|
+
if (!runtimeDir || !key) return fail(400, 'key must name a conversation');
|
|
128
|
+
const t = String(text == null ? '' : text);
|
|
129
|
+
if (t.length > NOTE_MAX) return fail(413, 'A note holds 200,000 characters at most.');
|
|
130
|
+
const dir = notesDir(runtimeDir, key);
|
|
131
|
+
let n = id == null || id === '' ? null : String(id);
|
|
132
|
+
if (n !== null && !NOTE_RE.test(n)) return fail(400, 'no such note');
|
|
133
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
134
|
+
if (n === null) { let k = now; do { n = 'n' + (k++).toString(36); } while (fs.existsSync(path.join(dir, n + '.md'))); }
|
|
135
|
+
const f = path.join(dir, n + '.md');
|
|
136
|
+
fs.writeFileSync(f, t);
|
|
137
|
+
return { ok: true, id: n, title: noteTitle(t), path: f, name: NOTES + '/' + n + '.md' };
|
|
138
|
+
}
|
|
139
|
+
function removeNote({ runtimeDir, key, id }) {
|
|
140
|
+
if (!runtimeDir || !key) return fail(400, 'key must name a conversation');
|
|
141
|
+
if (!NOTE_RE.test(String(id || ''))) return fail(400, 'no such note');
|
|
142
|
+
try { fs.unlinkSync(path.join(notesDir(runtimeDir, key), String(id) + '.md')); } catch { return fail(404, 'no such note'); }
|
|
143
|
+
return { ok: true };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = { MAX_BYTES, MAX_FILES, DIR, LEAD, rootOf, dirOf, cleanName, storedName, save, remove, pathsOf, withFiles, splitFiles, servable, noteTitle, listNotes, saveNote, removeNote };
|
|
@@ -122,6 +122,13 @@ function readRaw(req, max) {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
async function chatFile(req, res, url, ctx) {
|
|
125
|
+
if (url.pathname === '/api/chat-file/notes' && req.method === 'GET') { // premium-chat-notes: the conversation's notes, oldest first
|
|
126
|
+
const key = url.searchParams.get('key') || '';
|
|
127
|
+
if (!Ag.KEY_RE.test(key)) { ctx.json(res, { ok: false, error: 'key must name a row' }, 400); return true; }
|
|
128
|
+
const r = Files.listNotes({ runtimeDir: ctx.runtimeDir, key });
|
|
129
|
+
ctx.json(res, r.ok ? { ok: true, notes: r.notes.map((n) => ({ id: n.id, title: n.title, text: n.text, path: n.path, name: 'notes/' + n.id + '.md' })) } : { ok: false, error: r.error }, r.ok ? 200 : r.status);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
125
132
|
if (url.pathname === '/api/chat-file' && req.method === 'GET') {
|
|
126
133
|
const f = Files.servable(ctx.runtimeDir, url.searchParams.get('path'));
|
|
127
134
|
if (!f.ok) { ctx.json(res, { ok: false, error: f.error }, f.status); return true; }
|
|
@@ -135,6 +142,17 @@ async function chatFile(req, res, url, ctx) {
|
|
|
135
142
|
if (req.headers && req.headers['x-pmos-session']) { ctx.json(res, { ok: false, error: 'an agent session cannot attach a file to the PM\'s message' }, 403); return true; }
|
|
136
143
|
const g = guard.requirePagePress(req, {});
|
|
137
144
|
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
145
|
+
if (url.pathname === '/api/chat-file/notes' || url.pathname === '/api/chat-file/notes/remove') { // premium-chat-notes: save or delete one note
|
|
146
|
+
const got = await ctx.readJson(req);
|
|
147
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'body must be JSON' }, 400); return true; }
|
|
148
|
+
const b = got.body || {}, key = String(b.key || '');
|
|
149
|
+
if (!Ag.KEY_RE.test(key)) { ctx.json(res, { ok: false, error: 'key must name a row' }, 400); return true; }
|
|
150
|
+
let r;
|
|
151
|
+
try { r = url.pathname.endsWith('/remove') ? Files.removeNote({ runtimeDir: ctx.runtimeDir, key, id: b.id }) : Files.saveNote({ runtimeDir: ctx.runtimeDir, key, id: b.id, text: b.text }); }
|
|
152
|
+
catch (e) { r = { ok: false, status: 500, error: 'The note could not be saved: ' + String((e && e.message) || e).slice(0, 120) }; }
|
|
153
|
+
ctx.json(res, r.ok ? { ok: true, ...(r.id ? { id: r.id, title: r.title, path: r.path, name: r.name } : {}) } : { ok: false, error: r.error }, r.ok ? 200 : r.status);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
138
156
|
if (url.pathname === '/api/chat-file/remove') {
|
|
139
157
|
const got = await ctx.readJson(req);
|
|
140
158
|
if (!got.ok) { ctx.json(res, { ok: false, error: 'body must be JSON' }, 400); return true; }
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.379.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.379.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
|
@@ -66,7 +66,7 @@ const filesIn = () => { const d = path.join(T.STATE_DIR, 'chat-files'); const ou
|
|
|
66
66
|
ok('B1 the menu starts closed and no chip row shows', await page.isHidden('#plusM') && await page.isHidden('#attRow'));
|
|
67
67
|
await page.click('#askPlus');
|
|
68
68
|
ok('B1 the + opens a menu of three above the box', await page.isVisible('#plusM') && (await page.$$('#plusM [data-plus]')).length === 3 && await page.evaluate(() => document.querySelector('#plusM').getBoundingClientRect().bottom <= document.querySelector('#askIn').getBoundingClientRect().top + 8));
|
|
69
|
-
ok('B1 the menu names Add files or photos, Slash commands and
|
|
69
|
+
ok('B1 the menu names Add files or photos, Slash commands and Notes', /Add files or photos[\s\S]*Slash commands[\s\S]*Notes/.test(await page.textContent('#plusM')));
|
|
70
70
|
await shot(page, 'menu-1280-light');
|
|
71
71
|
await page.keyboard.press('Escape');
|
|
72
72
|
ok('B1 Escape closes the menu and leaves the dialog open', await page.isHidden('#plusM') && await page.evaluate(() => document.querySelector('#dlg').classList.contains('on')));
|
|
@@ -75,8 +75,7 @@ const filesIn = () => { const d = path.join(T.STATE_DIR, 'chat-files'); const ou
|
|
|
75
75
|
ok('B2 Slash commands puts / in the box and shows the commands', (await page.inputValue('#askIn')) === '/' && await page.isVisible('#slashM'));
|
|
76
76
|
await page.fill('#askIn', ''); await page.evaluate(() => document.querySelector('#askIn').dispatchEvent(new Event('input', { bubbles: true })));
|
|
77
77
|
await page.click('#askPlus'); await page.click('[data-plus="pad"]');
|
|
78
|
-
ok('B2
|
|
79
|
-
await page.click('#sPadT');
|
|
78
|
+
ok('B2 Notes opens the notepad in the viewer', !!(await until(async () => page.isVisible('#ntEd'))));
|
|
80
79
|
/* B3 */
|
|
81
80
|
await page.setInputFiles('#askFile', [{ name: 'Screenshot 1.41.39 PM.png', mimeType: 'image/png', buffer: PNG }, { name: 'Q4 roadmap.pdf', mimeType: 'application/pdf', buffer: Buffer.from('%PDF-1.4 test') }]);
|
|
82
81
|
ok('B3 two picked files show as two chips with their sizes once saved', !!(await until(async () => { const c = await chips(page); return c.length === 2 && c.every((x) => /KB/.test(x.meta)); })), JSON.stringify(await chips(page)));
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* premium-chat-notes-test.js — Notes for a premium chat conversation (initiative premium-chat-attach, N1-N7).
|
|
4
|
+
* Serves the real My work page from the real server with a fixture model; notes save through the real /api/chat-file/notes in a scratch state folder.
|
|
5
|
+
* N1 + › Notes opens the notepad in the viewer, the old Scratchpad text is the first note · N2 typed Markdown is saved as a .md file
|
|
6
|
+
* N3 a checkbox ticks · N4 New note and the list · N5 the buttons are icons with names · N6 Add selection · N7 Share with Claude puts the note on
|
|
7
|
+
* the message · N8 the bubble's note chip opens Notes · N9 Delete asks first · N10 phone, both themes */
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { spawn } = require('child_process');
|
|
11
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
12
|
+
const T = require('./test-run').configure({ name: 'premium-chat-notes' });
|
|
13
|
+
const WP = require('./lib/my-work-premium.js');
|
|
14
|
+
const F = require('./fixtures/my-work-premium-facts.js');
|
|
15
|
+
const lib = require('./lib/chat-files.js');
|
|
16
|
+
|
|
17
|
+
const BASE = T.BASE;
|
|
18
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
19
|
+
const until = async (fn, ms = 6000, step = 100) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
20
|
+
const results = [];
|
|
21
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + extra : ''}`); };
|
|
22
|
+
let srv = null; let browser = null;
|
|
23
|
+
const finish = async (code) => {
|
|
24
|
+
if (browser) await browser.close().catch(() => {});
|
|
25
|
+
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
26
|
+
T.killTmux();
|
|
27
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
28
|
+
console.log(`\n${results.length - bad}/${results.length} premium-chat-notes assertions passed`);
|
|
29
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
30
|
+
};
|
|
31
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
32
|
+
const SHOTS = process.env.NOTES_SHOTS || ''; // a folder: the suite also saves screenshots there for review
|
|
33
|
+
const shot = async (page, n) => { if (SHOTS) await page.screenshot({ path: path.join(SHOTS, n + '.png') }); };
|
|
34
|
+
const KEY = 'work:notes-1';
|
|
35
|
+
const notes = (key = KEY) => lib.listNotes({ runtimeDir: T.STATE_DIR, key }).notes;
|
|
36
|
+
|
|
37
|
+
(async () => {
|
|
38
|
+
const exe = findBrowser();
|
|
39
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
40
|
+
let chromium;
|
|
41
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
42
|
+
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
|
|
43
|
+
await T.waitForServer(BASE);
|
|
44
|
+
browser = await chromium.launch({ executablePath: exe });
|
|
45
|
+
const model = WP.build({ v: F.view(), now: F.NOW });
|
|
46
|
+
|
|
47
|
+
const open = async ({ w = 1280, h = 900, scheme = 'light' } = {}) => {
|
|
48
|
+
const ctx = await browser.newContext({ viewport: { width: w, height: h }, colorScheme: scheme });
|
|
49
|
+
const page = await ctx.newPage();
|
|
50
|
+
const errors = [], asks = [];
|
|
51
|
+
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
|
|
52
|
+
await page.route('**/api/my-work-premium', (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, state: 'ready', model, as_of: Date.now() }) }));
|
|
53
|
+
await page.route('**/api/briefing-premium/**', (r) => { const rq = r.request(); if (rq.method() !== 'GET') asks.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}') }); r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, turns: [], working: false }) }); });
|
|
54
|
+
await page.goto(BASE + '/premium-work.html', { waitUntil: 'domcontentloaded' });
|
|
55
|
+
await page.waitForFunction(() => document.querySelector('#dBody') !== null);
|
|
56
|
+
return { page, ctx, errors, asks };
|
|
57
|
+
};
|
|
58
|
+
const dlg = (page, key) => page.evaluate(async (key) => { const m = await import('/pm/premium-shell.js'); m.openDlg({ eye: 'Test', title: 'Notes test', say: 'Hello.', noteKey: key, html: '<p>detail</p>' }); m.setTab('chat'); }, key);
|
|
59
|
+
const close = (page) => page.evaluate(async () => { const m = await import('/pm/premium-shell.js'); m.closeDlg(); });
|
|
60
|
+
const openNotes = async (page) => { await page.click('#askPlus'); await page.click('[data-plus="pad"]'); return until(async () => page.isVisible('#ntEd')); };
|
|
61
|
+
const typeIn = async (page, s) => { await page.click('#ntEd'); await page.keyboard.type(s); };
|
|
62
|
+
|
|
63
|
+
// the old Scratchpad of this conversation, as the pad left it
|
|
64
|
+
await fetch(BASE + '/api/scratchpad', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: KEY, text: 'call Dana\nask about Q4' }) });
|
|
65
|
+
|
|
66
|
+
let { page, ctx, errors, asks } = await open();
|
|
67
|
+
await dlg(page, KEY);
|
|
68
|
+
/* N1 */
|
|
69
|
+
ok('N1 the + menu names Notes, not Scratchpad', /Notes/.test(await page.textContent('#plusM')) && !/Scratchpad/.test(await page.textContent('#plusM')));
|
|
70
|
+
ok('N1 the Scratchpad strip and its chip are gone', (await page.$('#sPad')) === null && (await page.$('#sPadT')) === null);
|
|
71
|
+
ok('N1 Notes opens in the viewer as a tab', !!(await openNotes(page)) && /Notes/.test(await page.textContent('#vTabs')));
|
|
72
|
+
ok('N1 the old Scratchpad text is the first note, line by line', !!(await until(async () => notes().length === 1)) && notes()[0].text === 'call Dana\n\nask about Q4' && /call Dana[\s\S]*ask about Q4/.test(await page.textContent('#ntEd')));
|
|
73
|
+
ok('N1 the pad is emptied once its text is a note', !!(await until(async () => { const r = await (await fetch(BASE + '/api/scratchpad?key=' + encodeURIComponent(KEY))).json(); return r.text === ''; })));
|
|
74
|
+
ok('N1 the note title shows in the head', (await page.textContent('#ntSw')).trim() === 'call Dana');
|
|
75
|
+
/* N2 */
|
|
76
|
+
await page.click('[data-nt="new"]');
|
|
77
|
+
ok('N2 New note shows an empty note with a hint', await page.evaluate(() => { const e = document.querySelector('#ntEd'); return !e.textContent.trim() && e.classList.contains('ph') && document.activeElement === e; }));
|
|
78
|
+
await page.keyboard.type('# Q4 review prep'); await page.keyboard.press('Enter');
|
|
79
|
+
await page.keyboard.type('Story for leadership'); await page.keyboard.press('Enter');
|
|
80
|
+
await page.keyboard.type('- Lead with the drop'); await page.keyboard.press('Enter'); await page.keyboard.press('Enter');
|
|
81
|
+
await page.keyboard.type('[] Pull Q3 numbers'); await page.keyboard.press('Enter'); await page.keyboard.type('Draft speaker notes');
|
|
82
|
+
const md = await until(async () => { const n = notes().find((x) => x.title === 'Q4 review prep'); return n && /Draft speaker notes/.test(n.text) ? n.text : null; });
|
|
83
|
+
ok('N2 typed Markdown starts are saved as Markdown', !!md && /^# Q4 review prep$/m.test(md) && /^Story for leadership$/m.test(md) && /^- Lead with the drop$/m.test(md) && /^- \[ \] Pull Q3 numbers$/m.test(md) && /^- \[ \] Draft speaker notes$/m.test(md), JSON.stringify(md));
|
|
84
|
+
ok('N2 the editor shows a heading, a bullet and two checkboxes', await page.evaluate(() => { const e = document.querySelector('#ntEd'); return !!e.querySelector('h1') && e.querySelectorAll('ul:not(.tasks) li').length === 1 && e.querySelectorAll('li.task input[type=checkbox]').length === 2; }));
|
|
85
|
+
ok('N2 the head says Saved', !!(await until(async () => (await page.textContent('#ntSt')) === 'Saved')));
|
|
86
|
+
/* N3 */
|
|
87
|
+
await page.click('#ntEd li.task input');
|
|
88
|
+
ok('N3 ticking a checkbox saves it as done', !!(await until(async () => /^- \[x\] Pull Q3 numbers$/m.test((notes().find((x) => x.title === 'Q4 review prep') || {}).text || ''))) && await page.evaluate(() => document.querySelector('#ntEd li.task').classList.contains('done')));
|
|
89
|
+
await shot(page, 'notes-1280-light');
|
|
90
|
+
/* N4 */
|
|
91
|
+
ok('N4 the head counts two notes', (await page.textContent('.ntn')).trim() === '2 notes');
|
|
92
|
+
await page.click('#ntSw');
|
|
93
|
+
ok('N4 the title opens the list, newest first, with Delete', await page.isVisible('#ntM') && (await page.$$eval('#ntM [data-ntgo]', (xs) => xs.map((x) => x.textContent))).join('|') === 'Q4 review prep|call Dana' && !!(await page.$('#ntM [data-ntdel]')));
|
|
94
|
+
await shot(page, 'list-1280-light');
|
|
95
|
+
await page.click('#ntM [data-ntgo]:nth-child(2)');
|
|
96
|
+
ok('N4 picking a note shows it', /call Dana/.test(await page.textContent('#ntEd')) && (await page.textContent('#ntSw')).trim() === 'call Dana');
|
|
97
|
+
/* N5 */
|
|
98
|
+
ok('N5 New note, Add selection and Share with Claude are icons with a name and a tooltip, no words', await page.evaluate(() => ['new', 'sel', 'share'].every((k) => { const b = document.querySelector(`[data-nt="${k}"]`); return b && !b.textContent.trim() && b.querySelector('svg') && b.getAttribute('aria-label') && b.title; })));
|
|
99
|
+
/* N6 */
|
|
100
|
+
await page.evaluate(() => { const p = [...document.querySelectorAll('#ntEd p')].find((x) => /ask about/.test(x.textContent)); const r = document.createRange(); r.selectNodeContents(p); getSelection().removeAllRanges(); getSelection().addRange(r); });
|
|
101
|
+
await page.click('[data-nt="sel"]');
|
|
102
|
+
ok('N6 Add selection puts only the selected words in the message box', (await page.inputValue('#askIn')) === 'ask about Q4', JSON.stringify(await page.inputValue('#askIn')));
|
|
103
|
+
ok('N6 nothing was sent', asks.length === 0);
|
|
104
|
+
/* N7 */
|
|
105
|
+
await page.fill('#askIn', 'Plan the deck from my note');
|
|
106
|
+
await page.click('#ntSw'); await page.click('#ntM [data-ntgo]:nth-child(1)');
|
|
107
|
+
await page.click('[data-nt="share"]');
|
|
108
|
+
ok('N7 Share with Claude puts the note on the message as a chip', !!(await until(async () => page.evaluate(() => { const c = document.querySelector('#attRow .atc'); return c && /Q4 review prep/.test(c.textContent) && /NOTE/.test(c.textContent); }))));
|
|
109
|
+
await shot(page, 'shared-1280-light');
|
|
110
|
+
await page.click('#askGo');
|
|
111
|
+
const ask = await until(async () => asks.find((a) => a.path.endsWith('/ask')));
|
|
112
|
+
const q4 = notes().find((x) => x.title === 'Q4 review prep');
|
|
113
|
+
ok('N7 send names the note as notes/<id>.md', !!ask && ask.body.text === 'Plan the deck from my note' && JSON.stringify(ask.body.files) === JSON.stringify(['notes/' + q4.id + '.md']), JSON.stringify(ask && ask.body));
|
|
114
|
+
const paths = lib.pathsOf({ runtimeDir: T.STATE_DIR, key: KEY, names: ask.body.files });
|
|
115
|
+
ok('N7 the name resolves to the note file Claude reads', paths.ok && paths.paths[0] === q4.path);
|
|
116
|
+
ok('N7 the note stays after the send', notes().length === 2);
|
|
117
|
+
/* N8 */
|
|
118
|
+
const line = lib.withFiles('Plan the deck from my note', paths.paths).replace(/\n/g, ' ');
|
|
119
|
+
await page.evaluate(async (text) => { const m = await import('/pm/premium-shell.js'); document.querySelector('#dBody .stream').innerHTML = m.sessionHtml({ state: 'conv', messages: [{ role: 'user', text }] }); }, line);
|
|
120
|
+
await page.click('#ntSw'); await page.click('#ntM [data-ntgo]:nth-child(2)');
|
|
121
|
+
await page.click('#dBody .turn.u .atc[data-att]');
|
|
122
|
+
ok('N8 the note chip in the PM\'s bubble opens that note', !!(await until(async () => (await page.textContent('#ntSw')).trim() === 'Q4 review prep')));
|
|
123
|
+
/* N9 */
|
|
124
|
+
await page.click('#ntSw'); await page.click('#ntM [data-ntdel]');
|
|
125
|
+
ok('N9 Delete asks first', await page.isVisible('.vcf'));
|
|
126
|
+
await page.click('.vcf button:has-text("Delete")');
|
|
127
|
+
ok('N9 Delete removes the note and shows the other', !!(await until(async () => notes().length === 1 && /call Dana/.test(await page.textContent('#ntEd')))));
|
|
128
|
+
await close(page);
|
|
129
|
+
ok('N1-N9 no page errors', errors.length === 0, errors.join(' | '));
|
|
130
|
+
await ctx.close();
|
|
131
|
+
|
|
132
|
+
/* N10 phone, both themes */
|
|
133
|
+
for (const scheme of ['light', 'dark']) {
|
|
134
|
+
({ page, ctx, errors } = await open({ w: 390, h: 844, scheme }));
|
|
135
|
+
await dlg(page, KEY);
|
|
136
|
+
ok(`N10 ${scheme}: Notes opens the viewer tab on a phone`, !!(await openNotes(page)));
|
|
137
|
+
await shot(page, 'notes-390-' + scheme);
|
|
138
|
+
ok(`N10 ${scheme}: the notepad fits the width`, await page.evaluate(() => { const w = innerWidth; return ['#ntEd', '.ntf', '.nth'].every((s) => { const r = document.querySelector(s).getBoundingClientRect(); return r.width > 0 && r.left >= 0 && r.right <= w + 1; }); }));
|
|
139
|
+
ok(`N10 ${scheme}: the icon buttons are 44px targets`, await page.evaluate(() => [...document.querySelectorAll('.ntic')].every((b) => b.getBoundingClientRect().height >= 44)));
|
|
140
|
+
await page.click('[data-nt="share"]');
|
|
141
|
+
ok(`N10 ${scheme}: Share with Claude goes back to the conversation with the chip`, !!(await until(async () => page.isVisible('#attRow .atc'))));
|
|
142
|
+
ok(`N10 ${scheme}: no page errors`, errors.length === 0, errors.join(' | '));
|
|
143
|
+
await ctx.close();
|
|
144
|
+
}
|
|
145
|
+
finish();
|
|
146
|
+
})();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* pm/premium-attach.js — files and photos on a premium chat message (initiative premium-chat-attach; PM, 2026-10-21: "Where is Add photos or file on PMOS?").
|
|
2
|
-
* A + at the left of the message box opens a small menu: Add files or photos, Slash commands,
|
|
2
|
+
* A + at the left of the message box opens a small menu: Add files or photos, Slash commands, Notes. A file can also be dropped on the chat or pasted
|
|
3
3
|
* into the box. Each file is saved at once through POST /api/chat-file (in the workspace state folder, never a repository) and shows as a chip above
|
|
4
4
|
* the text with ×. On send the ask route names each file's path for Claude in one closing line; the PM's bubble shows that line as chips, and a chip
|
|
5
5
|
* opens the file in the viewer: a photo as the picture, a PDF as the document, anything else as a download.
|
|
6
6
|
* attachMarkup() · attachRowMarkup() · mountAttach({ getKey, input, note, onSlash, onPad }) · attachNames() · clearAttach()
|
|
7
|
-
* splitFiles(text) · filesHtml(paths) · openAttachment(path) */
|
|
7
|
+
* splitFiles(text) · filesHtml(paths) · openAttachment(path) · attachSaved(f) (a note that Share with Claude puts on the message) */
|
|
8
8
|
import { pressFetch, pmPost } from './http.js';
|
|
9
9
|
import { vwOpen, vwStyle } from './premium-viewer.js';
|
|
10
10
|
|
|
@@ -25,7 +25,9 @@ export function splitFiles(text) {
|
|
|
25
25
|
return { text: t.slice(0, i).trim(), files: t.slice(i + LEAD.length).replace(/\]\s*$/, '').split(' | ').map((s) => s.trim()).filter(Boolean) };
|
|
26
26
|
}
|
|
27
27
|
/** The name a saved file had when the PM picked it: the folder and the time prefix go. Pure. */
|
|
28
|
-
export const shownName = (p) => String(p || '').split('/').pop().replace(/^\d{8}T\d{6}-/, '');
|
|
28
|
+
export const shownName = (p) => (isNote(p) ? 'Note' : String(p || '').split('/').pop().replace(/^\d{8}T\d{6}-/, ''));
|
|
29
|
+
/** A note shared from Notes (premium-notes.js): <conversation folder>/notes/<id>.md. Pure. */
|
|
30
|
+
export const isNote = (p) => /\/notes\/n[0-9a-z]{6,16}\.md$/.test(String(p || ''));
|
|
29
31
|
/** "214 KB", "1.8 MB". Pure. */
|
|
30
32
|
export const sizeText = (n) => (n >= 1048576 ? (n / 1048576).toFixed(1) + ' MB' : Math.max(1, Math.round(n / 1024)) + ' KB');
|
|
31
33
|
const extOf = (n) => ((/\.([A-Za-z0-9]{1,5})$/.exec(n || '') || [])[1] || 'file').toUpperCase();
|
|
@@ -34,7 +36,7 @@ export const fileUrl = (p) => '/api/chat-file?path=' + encodeURIComponent(p);
|
|
|
34
36
|
/** One chip as HTML. f: { name, path?, size?, state: 'saving'|'saved'|'sent', url? }. Pure. */
|
|
35
37
|
export function chipHtml(f, i) {
|
|
36
38
|
const img = IMG.test(f.name || '') && (f.url || f.path);
|
|
37
|
-
const th = img ? `<img class="ath" alt="" src="${esc(f.url || fileUrl(f.path))}">` : `<span class="ath atx">${esc(extOf(f.name))}</span>`;
|
|
39
|
+
const th = img ? `<img class="ath" alt="" src="${esc(f.url || fileUrl(f.path))}">` : `<span class="ath atx">${esc(f.note || isNote(f.path) ? 'NOTE' : extOf(f.name))}</span>`;
|
|
38
40
|
const meta = f.state === 'saving' ? 'Saving' : f.size ? sizeText(f.size) : '';
|
|
39
41
|
const body = `${th}<span class="atn"><b>${esc(f.name)}</b>${meta ? `<em>${esc(meta)}</em>` : ''}</span>`;
|
|
40
42
|
if (f.state === 'sent') return `<button type="button" class="atc" data-att="${esc(f.path)}" title="Open ${esc(f.name)} beside the conversation">${body}</button>`;
|
|
@@ -45,7 +47,7 @@ export const filesHtml = (paths) => (paths && paths.length ? `<div class="atrow
|
|
|
45
47
|
|
|
46
48
|
export const attachMarkup = () => `<button type="button" class="askplus" id="askPlus" aria-label="Add files, photos or commands" title="Add files, photos or commands" aria-haspopup="menu" aria-expanded="false" aria-controls="plusM" hidden>${PLUS}</button>`
|
|
47
49
|
+ `<div class="plusm" id="plusM" role="menu" aria-label="Add" hidden><button type="button" role="menuitem" data-plus="file">${CLIP}<span>Add files or photos</span><em>or drop, or paste</em></button>`
|
|
48
|
-
+ `<button type="button" role="menuitem" data-plus="slash">${SLASH}<span>Slash commands</span><em>/</em></button><button type="button" role="menuitem" data-plus="pad">${PEN}<span>
|
|
50
|
+
+ `<button type="button" role="menuitem" data-plus="slash">${SLASH}<span>Slash commands</span><em>/</em></button><button type="button" role="menuitem" data-plus="pad">${PEN}<span>Notes</span></button></div>`
|
|
49
51
|
+ `<input type="file" id="askFile" multiple hidden tabindex="-1" aria-hidden="true">`;
|
|
50
52
|
export const attachRowMarkup = () => '<div class="atrow" id="attRow" hidden></div>';
|
|
51
53
|
|
|
@@ -64,6 +66,7 @@ export function mountAttach({ getKey, input, note, onSlash, onPad }) {
|
|
|
64
66
|
if (!plus || !menu || !pick || !row) return;
|
|
65
67
|
const me = { files: [], key: getKey() };
|
|
66
68
|
const say = (t) => { if (note) note.textContent = t; };
|
|
69
|
+
me.say = say;
|
|
67
70
|
me.draw = () => { row.hidden = !me.files.length; row.innerHTML = me.files.map(chipHtml).join(''); };
|
|
68
71
|
A = me;
|
|
69
72
|
const sync = () => {
|
|
@@ -94,7 +97,7 @@ export function mountAttach({ getKey, input, note, onSlash, onPad }) {
|
|
|
94
97
|
const f = me.files[Number(b.dataset.attRm)]; if (!f) return;
|
|
95
98
|
me.files = me.files.filter((x) => x !== f); me.draw();
|
|
96
99
|
if (f.url) URL.revokeObjectURL(f.url);
|
|
97
|
-
if (f.saved) pmPost('/api/chat-file/remove', { key: me.key, name: f.saved }).catch(() => { /* left in the folder; nothing names it */ });
|
|
100
|
+
if (f.saved && !f.note) pmPost('/api/chat-file/remove', { key: me.key, name: f.saved }).catch(() => { /* left in the folder; nothing names it */ });
|
|
98
101
|
if (input) input.focus();
|
|
99
102
|
};
|
|
100
103
|
if (input) input.addEventListener('paste', (e) => {
|
|
@@ -125,6 +128,13 @@ export function mountAttach({ getKey, input, note, onSlash, onPad }) {
|
|
|
125
128
|
}
|
|
126
129
|
me.add = add;
|
|
127
130
|
}
|
|
131
|
+
/** A note already saved (Share with Claude): a chip like a saved file; × takes it off the message and keeps the note. */
|
|
132
|
+
export function attachSaved(f) {
|
|
133
|
+
if (!A || !f || !f.saved) return;
|
|
134
|
+
if (A.files.some((x) => x.saved === f.saved)) return;
|
|
135
|
+
if (A.files.length >= MAX_FILES) { if (A.say) A.say('A message takes ' + MAX_FILES + ' files at most.'); return; }
|
|
136
|
+
A.files.push({ name: f.name, size: f.size, state: 'saved', saved: f.saved, path: f.path, note: !!f.note }); A.draw();
|
|
137
|
+
}
|
|
128
138
|
/** A file dropped anywhere on the chat side. Call from the dialog's drop handler. */
|
|
129
139
|
export function dropFiles(list) { if (A && A.add) A.add([...list]); }
|
|
130
140
|
/** Re-read the key (the session list switched the conversation without redrawing the box). */
|
|
@@ -132,6 +142,7 @@ export function syncAttach() { if (A && A.sync) A.sync(); }
|
|
|
132
142
|
|
|
133
143
|
/** An attachment as a viewer tab: a photo as the picture, a PDF as the document, anything else by name with Download. */
|
|
134
144
|
export function openAttachment(p) {
|
|
145
|
+
if (isNote(p)) return import('./premium-notes.js').then((m) => m.openNotes(p.split('/').pop().replace(/\.md$/, '')));
|
|
135
146
|
vwStyle('doc');
|
|
136
147
|
const name = shownName(p), url = fileUrl(p);
|
|
137
148
|
const view = IMG.test(name) ? `<img class="atview" alt="${esc(name)}" src="${esc(url)}">`
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/* pm/premium-notes.js — Notes for a premium chat conversation (initiative premium-chat-attach, N1-N7; PM, 2026-10-21: "scratch pad can be converted
|
|
2
|
+
* into a proper notepad"). The Scratchpad strip above the message box is gone; Notes opens in the viewer (on a phone, the viewer tab).
|
|
3
|
+
* · several notes for each conversation, each a Markdown file in the conversation's folder (lib/chat-files.js, under notes/), saved as you type
|
|
4
|
+
* · light formatting typed as Markdown: "# " a heading, "- " a bullet, "1. " a numbered list, "[] " a checkbox; Ctrl+B bold, Ctrl+I italic
|
|
5
|
+
* · the head: the note's title with the list of notes (and Delete), how many, Saved, and New note
|
|
6
|
+
* · the foot: Add selection (the selected words, or the whole note, go into the message box; nothing is sent) and Share with Claude (the note
|
|
7
|
+
* goes on the message as a file, as an attachment does, and Claude reads it when the PM sends)
|
|
8
|
+
* The buttons carry no words, only an icon with a tooltip and a name (PM, 2026-10-21). The old Scratchpad text becomes the first note.
|
|
9
|
+
* mountNotes({ getKey, ws, input, note, show, toChat }) · openNotes(id?) · flushNotes()
|
|
10
|
+
* addToMessage(cur, add) · padToMd(text) · mdShortcut(line) · notesCount(n) pure */
|
|
11
|
+
import { pmGet, pmPost } from './http.js';
|
|
12
|
+
import { vwOpen, vwStyle, vwConfirm, vwClose } from './premium-viewer.js';
|
|
13
|
+
import { parseMd, toMd, toDom, fromDom } from './c3-md.js';
|
|
14
|
+
import { attachSaved } from './premium-attach.js';
|
|
15
|
+
|
|
16
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
17
|
+
const ic = (d) => `<svg class="i" viewBox="0 0 24 24"><path d="${d}"/></svg>`;
|
|
18
|
+
const I_NEW = ic('M12 5v14M5 12h14'), I_ADD = ic('M4 6h16M4 11h9M20 11v4a3 3 0 0 1-3 3H8M11 15l-3 3 3 3'), I_SHARE = ic('M12 15V3M7 8l5-5 5 5M5 13v7h14v-7');
|
|
19
|
+
const I_DOWN = ic('M6 9l6 6 6-6'), I_DEL = ic('M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3');
|
|
20
|
+
|
|
21
|
+
/** The message box after Add selection: the added text goes after what is already typed, on a new line. Pure. */
|
|
22
|
+
export function addToMessage(cur, add) {
|
|
23
|
+
const a = String(add || '').replace(/^\n+|\s+$/g, ''); if (!a) return String(cur || '');
|
|
24
|
+
const c = String(cur || '').replace(/\s+$/, '');
|
|
25
|
+
return c ? c + '\n' + a : a;
|
|
26
|
+
}
|
|
27
|
+
const LIST = /^\s*([-*+]|\d+[.)])\s/;
|
|
28
|
+
/** Old Scratchpad text as Markdown: each line stays a line (a blank line between two that are not list items), so nothing joins up. Pure. */
|
|
29
|
+
export function padToMd(text) {
|
|
30
|
+
const ls = String(text || '').replace(/\r/g, '').replace(/^\s*\n|\s+$/g, '').split('\n');
|
|
31
|
+
let out = '';
|
|
32
|
+
ls.forEach((l, i) => { if (i) out += LIST.test(l) && LIST.test(ls[i - 1]) ? '\n' : l.trim() && ls[i - 1].trim() ? '\n\n' : '\n'; out += l; });
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/** What a line typed so far turns into when it is a Markdown start and a space was just typed. Pure. */
|
|
36
|
+
export function mdShortcut(line) {
|
|
37
|
+
const t = String(line || '').replace(/ /g, ' ');
|
|
38
|
+
const h = /^(#{1,3}) $/.exec(t); if (h) return { kind: 'h' + h[1].length };
|
|
39
|
+
if (/^[-*] $/.test(t)) return { kind: 'ul' };
|
|
40
|
+
if (/^1[.)] $/.test(t)) return { kind: 'ol' };
|
|
41
|
+
if (/^\[ ?\] $/.test(t)) return { kind: 'task' };
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
export const notesCount = (n) => (n > 1 ? n + ' notes' : '');
|
|
45
|
+
|
|
46
|
+
let C = null; // what the shell gave: { getKey, ws, input, note, show, toChat }
|
|
47
|
+
const N = { key: null, notes: [], cur: null, ed: null, el: null, timer: null, dirty: false, chain: Promise.resolve(), state: '' };
|
|
48
|
+
|
|
49
|
+
export function mountNotes(ctx) { flushNotes(); C = ctx; N.key = null; N.notes = []; N.cur = null; N.ed = null; N.el = null; }
|
|
50
|
+
|
|
51
|
+
const noteOf = (id) => N.notes.find((n) => n.id === id) || null;
|
|
52
|
+
const textOf = () => (N.ed ? toMd(fromDom(N.ed)) : '');
|
|
53
|
+
function setState(s) { N.state = s; const e = N.el && N.el.querySelector('#ntSt'); if (e) e.textContent = s; }
|
|
54
|
+
/** Save the open note now (a switch, a share, the dialog closing). Resolves when the server has it. */
|
|
55
|
+
export function flushNotes() {
|
|
56
|
+
if (N.timer) { clearTimeout(N.timer); N.timer = null; }
|
|
57
|
+
if (!N.dirty || !N.key) return N.chain;
|
|
58
|
+
N.dirty = false;
|
|
59
|
+
const key = N.key, text = textOf(), id0 = N.cur;
|
|
60
|
+
N.chain = N.chain.then(async () => {
|
|
61
|
+
const id = id0 || N.cur || null; // a new note's first save, still on its way when this one was asked for, has named it by now
|
|
62
|
+
const r = await pmPost('/api/chat-file/notes', { key, id: id || undefined, text }).catch(() => null);
|
|
63
|
+
if (N.key !== key) return;
|
|
64
|
+
if (!r || !r.ok) { setState('Not saved'); N.dirty = true; return; }
|
|
65
|
+
let n = noteOf(r.id); if (!n) { n = { id: r.id }; N.notes.push(n); if (!N.cur) N.cur = r.id; }
|
|
66
|
+
Object.assign(n, { title: r.title, text, path: r.path, name: r.name });
|
|
67
|
+
if (!N.dirty) setState('Saved');
|
|
68
|
+
head();
|
|
69
|
+
});
|
|
70
|
+
return N.chain;
|
|
71
|
+
}
|
|
72
|
+
function later() { N.dirty = true; setState('Saving…'); if (N.timer) clearTimeout(N.timer); N.timer = setTimeout(flushNotes, 500); }
|
|
73
|
+
|
|
74
|
+
/** Open Notes in the viewer, on the note `id` when given, else the newest. */
|
|
75
|
+
export async function openNotes(id) {
|
|
76
|
+
const key = C && C.getKey(); if (!key) return;
|
|
77
|
+
await flushNotes();
|
|
78
|
+
if (N.key !== key) {
|
|
79
|
+
const r = await pmGet('/api/chat-file/notes?key=' + encodeURIComponent(key)).catch(() => null);
|
|
80
|
+
N.key = key; N.notes = r && r.ok ? r.notes : []; N.cur = null;
|
|
81
|
+
if (!N.notes.length) await claimPad(key);
|
|
82
|
+
}
|
|
83
|
+
N.cur = id && noteOf(id) ? id : N.cur && noteOf(N.cur) ? N.cur : (N.notes[N.notes.length - 1] || {}).id || null;
|
|
84
|
+
vwStyle('doc'); vwStyle('notepad');
|
|
85
|
+
vwOpen({ id: 'notes', title: 'Notes', icon: 'notes', render: draw });
|
|
86
|
+
if (C.show) C.show();
|
|
87
|
+
}
|
|
88
|
+
/* The old Scratchpad of this conversation becomes its first note, once: the pad is emptied after the note is saved. */
|
|
89
|
+
async function claimPad(key) {
|
|
90
|
+
const q = 'key=' + encodeURIComponent(key) + (C.ws ? '&ws=' + encodeURIComponent(C.ws) : '');
|
|
91
|
+
const p = await pmGet('/api/scratchpad?' + q).catch(() => null);
|
|
92
|
+
const text = p && p.ok && typeof p.text === 'string' ? p.text : '';
|
|
93
|
+
if (!text.trim()) return;
|
|
94
|
+
const md = padToMd(text);
|
|
95
|
+
const r = await pmPost('/api/chat-file/notes', { key, text: md }).catch(() => null);
|
|
96
|
+
if (!r || !r.ok) return;
|
|
97
|
+
N.notes.push({ id: r.id, title: r.title, text: md, path: r.path, name: r.name });
|
|
98
|
+
pmPost('/api/scratchpad', { key, ws: C.ws || undefined, text: '' }).catch(() => { /* the pad keeps a copy */ });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function headHtml() {
|
|
102
|
+
const n = noteOf(N.cur);
|
|
103
|
+
return `<div class="nth"><button type="button" class="ntsw" id="ntSw" aria-haspopup="menu" aria-expanded="false" title="Your notes in this conversation"><b>${esc(n ? n.title : 'New note')}</b>${I_DOWN}</button>`
|
|
104
|
+
+ `<span class="ntn">${esc(notesCount(N.notes.length))}</span><span class="gap"></span><span class="ntst" id="ntSt" role="status">${esc(N.state)}</span>`
|
|
105
|
+
+ `<button type="button" class="ntic" data-nt="new" aria-label="New note" title="New note">${I_NEW}</button></div>`;
|
|
106
|
+
}
|
|
107
|
+
function head() { const h = N.el && N.el.querySelector('.nth'); if (h) h.outerHTML = headHtml(); }
|
|
108
|
+
function draw(el) {
|
|
109
|
+
N.el = el; N.state = N.state === 'Saving…' ? N.state : '';
|
|
110
|
+
const n = noteOf(N.cur);
|
|
111
|
+
el.innerHTML = `<div class="ntpad">${headHtml()}<div class="ntmenu" id="ntM" role="menu" hidden></div>`
|
|
112
|
+
+ `<div class="ntd" id="ntEd" contenteditable="true" role="textbox" aria-multiline="true" aria-label="Note" spellcheck="true" data-ph="Write a note. Type # for a heading, - for a bullet, [] for a checkbox."></div>`
|
|
113
|
+
+ `<div class="ntf"><span class="ntw">This conversation · saved on this machine</span>`
|
|
114
|
+
+ `<button type="button" class="ntic" data-nt="sel" aria-label="Add selection to message" title="Add selection to message. Nothing is sent.">${I_ADD}</button>`
|
|
115
|
+
+ `<button type="button" class="ntic pri" data-nt="share" aria-label="Share with Claude" title="Share with Claude: the note goes on your message as a file">${I_SHARE}</button></div></div>`;
|
|
116
|
+
const ed = el.querySelector('#ntEd'); N.ed = ed;
|
|
117
|
+
ed.append(...toDom(parseMd(n ? n.text || '' : ''), document, { editable: true }));
|
|
118
|
+
empty();
|
|
119
|
+
el.onclick = onClick;
|
|
120
|
+
el.onmousedown = (e) => { if (e.target.closest('[data-nt="sel"]')) e.preventDefault(); }; // the selection stays while the button is pressed
|
|
121
|
+
ed.onfocus = () => { try { document.execCommand('defaultParagraphSeparator', false, 'p'); } catch { /* the browser's own */ } };
|
|
122
|
+
ed.oninput = (e) => { if (e.inputType === 'insertText' && e.data === ' ') shortcut(); empty(); later(); };
|
|
123
|
+
ed.onkeydown = onKey;
|
|
124
|
+
ed.onchange = (e) => { const b = e.target; if (b && b.type === 'checkbox') { b.toggleAttribute('checked', b.checked); const li = b.closest('li'); if (li) li.classList.toggle('done', b.checked); later(); } };
|
|
125
|
+
}
|
|
126
|
+
const empty = () => { if (N.ed) N.ed.classList.toggle('ph', !N.ed.textContent.trim() && !N.ed.querySelector('input,hr')); };
|
|
127
|
+
|
|
128
|
+
/* the block the caret is in: a direct child of the editor, or a list item */
|
|
129
|
+
function blockAt() {
|
|
130
|
+
const s = getSelection(); if (!s.rangeCount || !N.ed.contains(s.anchorNode)) return null;
|
|
131
|
+
let n = s.anchorNode;
|
|
132
|
+
while (n && n.parentNode !== N.ed && !(n.nodeType === 1 && n.tagName === 'LI')) n = n.parentNode;
|
|
133
|
+
return n && n !== N.ed ? n : null;
|
|
134
|
+
}
|
|
135
|
+
const caretIn = (node) => { const r = document.createRange(); r.selectNodeContents(node); r.collapse(true); const s = getSelection(); s.removeAllRanges(); s.addRange(r); };
|
|
136
|
+
function shortcut() {
|
|
137
|
+
const b = blockAt(); if (!b || b.tagName === 'LI' || /^H\d$/.test(b.tagName || '')) return;
|
|
138
|
+
const s = getSelection(), r = document.createRange(); r.setStart(b, 0); r.setEnd(s.anchorNode, s.anchorOffset);
|
|
139
|
+
if (r.toString() !== b.textContent) return; // only a start typed at the head of a line that holds nothing else
|
|
140
|
+
const m = mdShortcut(b.textContent); if (!m) return;
|
|
141
|
+
let x, at;
|
|
142
|
+
if (m.kind[0] === 'h') { x = document.createElement(m.kind); x.append(document.createElement('br')); at = x; }
|
|
143
|
+
else {
|
|
144
|
+
x = document.createElement(m.kind === 'ol' ? 'ol' : 'ul'); const li = document.createElement('li'); x.append(li); at = li;
|
|
145
|
+
if (m.kind === 'task') { x.className = 'tasks'; li.className = 'task'; li.append(box(), at = document.createElement('span')); }
|
|
146
|
+
at.append(document.createElement('br'));
|
|
147
|
+
}
|
|
148
|
+
b.replaceWith(x); caretIn(at);
|
|
149
|
+
}
|
|
150
|
+
function box() { const c = document.createElement('input'); c.type = 'checkbox'; c.setAttribute('aria-label', 'Done'); c.setAttribute('contenteditable', 'false'); return c; }
|
|
151
|
+
function onKey(e) {
|
|
152
|
+
if (e.key === 'Enter') { e.stopPropagation(); if (!e.shiftKey && taskEnter()) { e.preventDefault(); later(); } }
|
|
153
|
+
}
|
|
154
|
+
/* Enter in a checkbox item: a new checkbox item below, or, on an empty one, the list ends and a line starts */
|
|
155
|
+
function taskEnter() {
|
|
156
|
+
const li = blockAt(); if (!li || li.tagName !== 'LI' || !li.classList.contains('task')) return false;
|
|
157
|
+
const sp = li.querySelector(':scope > span') || li;
|
|
158
|
+
if (!sp.textContent.trim()) {
|
|
159
|
+
const ul = li.parentNode, p = document.createElement('p'); p.append(document.createElement('br'));
|
|
160
|
+
const rest = [...ul.children].slice([...ul.children].indexOf(li) + 1);
|
|
161
|
+
li.remove(); ul.after(p);
|
|
162
|
+
if (rest.length) { const u2 = ul.cloneNode(false); u2.append(...rest); p.after(u2); }
|
|
163
|
+
if (!ul.children.length) ul.remove();
|
|
164
|
+
caretIn(p); return true;
|
|
165
|
+
}
|
|
166
|
+
const s = getSelection(), r = document.createRange(); r.setStart(s.anchorNode, s.anchorOffset); r.setEnd(sp, sp.childNodes.length);
|
|
167
|
+
const tail = r.extractContents();
|
|
168
|
+
const n = document.createElement('li'); n.className = 'task'; const ns = document.createElement('span');
|
|
169
|
+
if (tail.textContent) ns.append(tail); else ns.append(document.createElement('br'));
|
|
170
|
+
n.append(box(), ns); li.after(n); caretIn(ns);
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function onClick(e) {
|
|
175
|
+
const sw = e.target.closest('#ntSw'); if (sw) { menu(); return; }
|
|
176
|
+
const m = e.target.closest('[data-ntgo]'); if (m) { closeMenu(); await flushNotes(); N.cur = m.dataset.ntgo; draw(N.el); return; }
|
|
177
|
+
if (e.target.closest('[data-ntdel]')) { closeMenu(); del(); return; }
|
|
178
|
+
const b = e.target.closest('[data-nt]'); if (!b) return;
|
|
179
|
+
if (b.dataset.nt === 'new') { await flushNotes(); N.cur = null; N.state = ''; draw(N.el); N.ed.focus(); return; }
|
|
180
|
+
if (b.dataset.nt === 'sel') addSel();
|
|
181
|
+
if (b.dataset.nt === 'share') share();
|
|
182
|
+
}
|
|
183
|
+
function menu() {
|
|
184
|
+
const m = N.el.querySelector('#ntM'), sw = N.el.querySelector('#ntSw');
|
|
185
|
+
if (!m.hidden) { closeMenu(); return; }
|
|
186
|
+
m.innerHTML = N.notes.slice().reverse().map((n) => `<button type="button" role="menuitem" data-ntgo="${esc(n.id)}"${n.id === N.cur ? ' aria-current="true"' : ''}>${esc(n.title)}</button>`).join('')
|
|
187
|
+
+ (noteOf(N.cur) ? `<button type="button" role="menuitem" class="ntdel" data-ntdel="1">${I_DEL}<span>Delete this note</span></button>` : '');
|
|
188
|
+
if (!m.innerHTML) m.innerHTML = '<p class="vwmut">No notes yet.</p>';
|
|
189
|
+
m.hidden = false; m.dataset.escLayer = '1'; sw.setAttribute('aria-expanded', 'true');
|
|
190
|
+
m.onkeydown = (e) => { if (e.key === 'Escape') { e.stopPropagation(); closeMenu(); sw.focus(); } };
|
|
191
|
+
const f = m.querySelector('button'); if (f) f.focus();
|
|
192
|
+
}
|
|
193
|
+
function closeMenu() { const m = N.el && N.el.querySelector('#ntM'); if (!m || m.hidden) return; m.hidden = true; delete m.dataset.escLayer; const sw = N.el.querySelector('#ntSw'); if (sw) sw.setAttribute('aria-expanded', 'false'); }
|
|
194
|
+
if (typeof document !== 'undefined') document.addEventListener('pointerdown', (e) => { if (N.el && !e.target.closest('#ntM,#ntSw')) closeMenu(); }, { capture: true });
|
|
195
|
+
async function del() {
|
|
196
|
+
const n = noteOf(N.cur); if (!n) return;
|
|
197
|
+
if (!(await vwConfirm(N.el, { text: `Delete "${n.title}"? It cannot be brought back.`, yes: 'Delete', no: 'Keep' }))) return;
|
|
198
|
+
if (N.timer) { clearTimeout(N.timer); N.timer = null; } N.dirty = false;
|
|
199
|
+
await N.chain;
|
|
200
|
+
const r = await pmPost('/api/chat-file/notes/remove', { key: N.key, id: n.id }).catch(() => null);
|
|
201
|
+
if (!r || !r.ok) { setState('Not deleted'); return; }
|
|
202
|
+
N.notes = N.notes.filter((x) => x !== n); N.cur = (N.notes[N.notes.length - 1] || {}).id || null; N.state = '';
|
|
203
|
+
draw(N.el);
|
|
204
|
+
}
|
|
205
|
+
function say(t) { if (C && C.note) C.note.textContent = t; }
|
|
206
|
+
function addSel() {
|
|
207
|
+
const input = C && C.input; if (!input || !N.ed) return;
|
|
208
|
+
const s = getSelection(), inEd = s.rangeCount && !s.isCollapsed && N.ed.contains(s.anchorNode);
|
|
209
|
+
const text = inEd ? s.toString() : textOf(); if (!text.trim()) { setState('Nothing to add'); return; }
|
|
210
|
+
input.value = addToMessage(input.value, text);
|
|
211
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
212
|
+
if (C.toChat) C.toChat();
|
|
213
|
+
input.focus(); try { input.setSelectionRange(input.value.length, input.value.length); } catch { /* none */ }
|
|
214
|
+
say(inEd ? 'The selection is in your message. Press send when it reads right.' : 'The note is in your message. Press send when it reads right.');
|
|
215
|
+
}
|
|
216
|
+
async function share() {
|
|
217
|
+
if (!N.ed || !textOf().trim()) { setState('Write something first'); return; }
|
|
218
|
+
N.dirty = true; await flushNotes();
|
|
219
|
+
const n = noteOf(N.cur); if (!n || !n.name) { setState('Not saved'); return; }
|
|
220
|
+
attachSaved({ name: n.title, saved: n.name, path: n.path, size: new Blob([n.text || '']).size, note: true });
|
|
221
|
+
if (C.toChat) C.toChat();
|
|
222
|
+
if (C.input) C.input.focus();
|
|
223
|
+
say('The note is on your message. Claude reads it when you send.');
|
|
224
|
+
}
|
|
225
|
+
/** The dialog switched conversation: the open Notes tab belonged to the old one. */
|
|
226
|
+
export function syncNotes() { const k = C && C.getKey(); if (N.key && k !== N.key) { flushNotes(); N.key = null; vwClose('notes'); } }
|
|
227
|
+
if (typeof addEventListener === 'function') addEventListener('pagehide', () => { flushNotes(); });
|
|
@@ -9,7 +9,7 @@ import { chipActs, openLive, openFocus, mountRecord, HL_LINE } from './premium-v
|
|
|
9
9
|
import { lineItems, behindOf, whenRead } from './freshness-words.js';
|
|
10
10
|
import { splitGoal, shownUser, goalBlockHtml, goalProgressHtml, slashMatches } from './goal-chat.js';
|
|
11
11
|
import { mdHtml, userHtml, toolLine, webKind } from './chat-md.js';
|
|
12
|
-
import {
|
|
12
|
+
import { mountNotes, openNotes, flushNotes, syncNotes } from './premium-notes.js';
|
|
13
13
|
import { attachMarkup, attachRowMarkup, mountAttach, attachNames, clearAttach, syncAttach, dropFiles, splitFiles, filesHtml, openAttachment } from './premium-attach.js';
|
|
14
14
|
import { railModel, railHtml, teaser, menuCount, loudestRow, factsOf, titleOf, endAsks, DOT, WORD } from './session-rail.js';
|
|
15
15
|
export const $ = (s, r = document) => r.querySelector(s);
|
|
@@ -293,9 +293,9 @@ export function openDlg(o) {
|
|
|
293
293
|
$('#oMain').innerHTML = o.pane || `<article class="paper doc">${o.html}</article>`; $('#oLab').textContent = o.label || 'Detail';
|
|
294
294
|
if (o.paneEmpty) $('#oMain').dataset.empty = '1'; else delete $('#oMain').dataset.empty; // a placeholder note is not a tab (premium-chat-viewer V2)
|
|
295
295
|
vwReset(); // extra viewer tabs belong to the dialog that opened them
|
|
296
|
-
$('#dBody').innerHTML = `<div class="stream" role="log">${o.stream || turnA(ptx(o.say))}</div><form class="askbar" id="askF"><div class="slashm" id="slashM" role="listbox" aria-label="Commands" hidden></div>${
|
|
297
|
-
|
|
298
|
-
mountAttach({ getKey: () => S.key, input: $('#askIn'), note: $('#askNote'), onSlash: () => { const i = $('#askIn'); if (!i.value.startsWith('/')) i.value = '/' + i.value; i.focus(); drawSlash(); growAsk(); }, onPad: () =>
|
|
296
|
+
$('#dBody').innerHTML = `<div class="stream" role="log">${o.stream || turnA(ptx(o.say))}</div><form class="askbar" id="askF"><div class="slashm" id="slashM" role="listbox" aria-label="Commands" hidden></div>${attachRowMarkup()}${attachMarkup()}<textarea id="askIn" rows="1" placeholder="Message Claude, or type /" maxlength="8000" autocomplete="off" enterkeyhint="send" aria-label="A message for Claude" aria-controls="slashM"></textarea><button type="submit" data-act="ask" id="askGo" aria-label="Send to Claude" title="Send to Claude"><svg class="i" viewBox="0 0 24 24"><path d="M5 12h14M13 6l6 6-6 6"/></svg></button></form><div class="askfoot"><p class="fine2" id="askNote">${CHAT_NOTE}</p></div>`;
|
|
297
|
+
mountNotes({ getKey: () => S.key, ws: new URLSearchParams(location.search).get('ws'), input: $('#askIn'), note: $('#askNote'), show: () => { if (!desk()) setTab('out'); }, toChat: () => { if (!desk()) setTab('chat'); } });
|
|
298
|
+
mountAttach({ getKey: () => S.key, input: $('#askIn'), note: $('#askNote'), onSlash: () => { const i = $('#askIn'); if (!i.value.startsWith('/')) i.value = '/' + i.value; i.focus(); drawSlash(); growAsk(); }, onPad: () => openNotes() });
|
|
299
299
|
quietNote();
|
|
300
300
|
$('#dlg').classList.toggle('cmp', o.compact !== false); $('#dlg').classList.remove('shrunk', 'tfull'); setFocus(false); // compact (every dialog unless it says compact: false): a short head on a phone that shrinks as the detail scrolls
|
|
301
301
|
$('#dlg').classList.remove('full'); setMode('split'); setTab('out'); // on a phone the dialog opens on the Detail tab and the Detail / Conversation switch brings the conversation, as the mockup draws it
|
|
@@ -325,7 +325,7 @@ export function setFocus(f) {
|
|
|
325
325
|
$('#dFocus').onclick = () => setFocus(!$('#dlg').classList.contains('focus'));
|
|
326
326
|
export function closeDlg() {
|
|
327
327
|
if (chatPage()) return;
|
|
328
|
-
clearTimeout(threadTimer); S.key = null;
|
|
328
|
+
clearTimeout(threadTimer); S.key = null; flushNotes(); railOnClose();
|
|
329
329
|
park();
|
|
330
330
|
$('#veil').classList.remove('on'); $$('.rail,main.stage,#dock').forEach((x) => { x.inert = false; });
|
|
331
331
|
$('#dlg').inert = true; document.documentElement.style.overflow = ''; $('#dlg').classList.remove('on');
|
|
@@ -1241,7 +1241,7 @@ function pickSession(id) {
|
|
|
1241
1241
|
const st = $('#dBody .stream'); if (st) clearHtml(st);
|
|
1242
1242
|
$('#askF').hidden = !!r.headless; $('#askIn').value = ''; $('#askIn').placeholder = r.key ? 'Message Claude, or type /' : 'Message this session';
|
|
1243
1243
|
if (r.key) { S.sid = null; S.key = r.key; loadThread(r.key); } else { S.key = null; S.sid = id; loadSid(id); }
|
|
1244
|
-
syncAttach();
|
|
1244
|
+
syncAttach(); syncNotes();
|
|
1245
1245
|
sessionCard(r); railDraw();
|
|
1246
1246
|
if (!r.key && desk()) vwOpenPane(true); // a session with no conversation of its own: its facts and Stop are in the viewer; the list the PM just used stays open
|
|
1247
1247
|
if (!desk()) setTab('chat');
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
:root{--fs-1:11px;--fs-2:12px;--fs-3:14px;--fs-4:16px;--fs-5:20px;--fs-6:28px}
|
|
2
|
+
/* premium-vw-notepad.css — Notes in the premium viewer (premium-notes.js; initiative premium-chat-attach N1-N7). Loaded once by vwStyle('notepad').
|
|
3
|
+
* Sizes are the console's six steps only (var(--fs-1..6)), weights 400/500/600, the page's own tokens otherwise. Checked by premium-console-type.test.js. */
|
|
4
|
+
.p-out>.obody.vw:not([hidden]):has(>.ntpad){flex:1;min-height:0;display:flex!important;flex-direction:column} /* the notepad fills the pane: the note scrolls, its foot stays */
|
|
5
|
+
.ntpad{flex:1;min-height:0;width:100%;display:flex;flex-direction:column;max-width:780px;margin:0 auto;position:relative}
|
|
6
|
+
.nth{display:flex;align-items:center;gap:8px;padding:2px 0 10px;border-bottom:1px solid var(--hair)}
|
|
7
|
+
.nth .gap{flex:1}
|
|
8
|
+
.ntsw{display:inline-flex;align-items:center;gap:4px;min-width:0;max-width:60%;min-height:34px;padding:0 6px;margin-left:-6px;border:0;border-radius:6px;background:none;color:var(--ink);font:600 var(--fs-3) var(--sans);cursor:pointer}
|
|
9
|
+
.ntsw b{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
10
|
+
.ntsw .i{width:15px;height:15px;flex:none}
|
|
11
|
+
.ntn,.ntst{font-size:var(--fs-2);color:var(--ink-3);white-space:nowrap}
|
|
12
|
+
.ntic{flex:none;width:36px;height:36px;display:inline-grid;place-items:center;border-radius:6px;border:1px solid var(--hair);background:var(--card-solid);color:var(--ink);cursor:pointer}
|
|
13
|
+
.ntic .i{width:17px;height:17px}
|
|
14
|
+
.ntic.pri{background:var(--solid);border-color:var(--solid);color:var(--on-solid)}
|
|
15
|
+
.ntmenu{position:absolute;top:42px;left:0;z-index:5;min-width:220px;max-width:min(340px,100%);max-height:320px;overflow:auto;padding:6px;border:1px solid var(--hair);border-radius:8px;background:var(--card-solid);box-shadow:var(--card-shadow);display:grid;gap:2px}
|
|
16
|
+
.ntmenu[hidden]{display:none}
|
|
17
|
+
.ntmenu button{display:flex;align-items:center;gap:8px;min-height:36px;padding:0 10px;border:0;border-radius:6px;background:none;color:var(--ink);font:400 var(--fs-3) var(--sans);text-align:left;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
18
|
+
.ntmenu button[aria-current]{font-weight:600}
|
|
19
|
+
.ntmenu .ntdel{color:var(--ink-2);border-top:1px solid var(--hair);border-radius:0;margin-top:4px}
|
|
20
|
+
.ntmenu .ntdel .i{width:15px;height:15px}
|
|
21
|
+
.ntd{flex:1;min-height:160px;overflow-y:auto;padding:16px 0;outline:0;font:400 var(--fs-4)/1.6 var(--sans);color:var(--ink);overflow-wrap:anywhere}
|
|
22
|
+
.ntd.ph::before{content:attr(data-ph);color:var(--ink-3);pointer-events:none;position:absolute}
|
|
23
|
+
.ntd>*:first-child{margin-top:0}
|
|
24
|
+
.ntd p{margin:0 0 8px}
|
|
25
|
+
.ntd h1{font-size:var(--fs-5);font-weight:600;margin:4px 0 10px}
|
|
26
|
+
.ntd h2{font-size:var(--fs-4);font-weight:600;margin:14px 0 6px}
|
|
27
|
+
.ntd h3{font-size:var(--fs-3);font-weight:600;margin:12px 0 4px;color:var(--ink-2)}
|
|
28
|
+
.ntd ul,.ntd ol{margin:0 0 8px;padding-left:22px}
|
|
29
|
+
.ntd ul.tasks{list-style:none;padding-left:0}
|
|
30
|
+
.ntd li{margin:2px 0}
|
|
31
|
+
.ntd li.task{display:flex;align-items:baseline;gap:8px}
|
|
32
|
+
.ntd li.task input{flex:none;width:16px;height:16px;margin:0;transform:translateY(2px);accent-color:var(--solid);cursor:pointer}
|
|
33
|
+
.ntd li.task.done>span{text-decoration:line-through;color:var(--ink-3)}
|
|
34
|
+
.ntd b,.ntd strong{font-weight:600}
|
|
35
|
+
.ntd code{font:400 var(--fs-2) var(--mono);background:var(--well);padding:1px 4px;border-radius:6px}
|
|
36
|
+
.ntd blockquote{margin:0 0 8px;padding-left:12px;border-left:3px solid var(--hair);color:var(--ink-2)}
|
|
37
|
+
.ntd a{color:var(--vw-lnk,inherit)}
|
|
38
|
+
.ntf{flex:none;display:flex;align-items:center;gap:8px;padding:10px 0 4px;border-top:1px solid var(--hair)}
|
|
39
|
+
.ntw{flex:1;min-width:0;font-size:var(--fs-2);color:var(--ink-3)}
|
|
40
|
+
@media (hover:hover){.ntsw:hover,.ntmenu button:hover,.ntic:not(.pri):hover{background:var(--well)}}
|
|
41
|
+
@media (max-width:999px),(pointer:coarse){.ntic{width:44px;height:44px}.ntsw{min-height:44px}.ntmenu button{min-height:44px}.ntw{display:none}.ntf{justify-content:flex-end}}
|
|
@@ -2529,29 +2529,9 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
|
|
|
2529
2529
|
.stease{height:44px}
|
|
2530
2530
|
}
|
|
2531
2531
|
|
|
2532
|
-
/* the
|
|
2532
|
+
/* the note under the message box */
|
|
2533
2533
|
.askfoot{display:flex;align-items:flex-start;gap:10px}
|
|
2534
2534
|
.askfoot .fine2{flex:1;min-width:0}
|
|
2535
|
-
.padt{flex:none;display:inline-flex;align-items:center;gap:6px;margin-top:2px;padding:5px 12px;border-radius:var(--r-chip);background:var(--well);color:var(--ink-2);font-size:var(--fs-2);font-weight:600;white-space:nowrap;min-height:30px}
|
|
2536
|
-
.padt[hidden]{display:none}
|
|
2537
|
-
.padt.on{background:var(--solid);color:var(--on-solid)}
|
|
2538
|
-
.padt svg{width:14px;height:14px}
|
|
2539
|
-
.padt em{font-style:normal;font-weight:500;opacity:.75}
|
|
2540
|
-
.spad{flex:1 0 100%;box-sizing:border-box;border-radius:var(--r-in);background:var(--well);overflow:hidden;margin-bottom:2px}
|
|
2541
|
-
.spad[hidden]{display:none}
|
|
2542
|
-
.spad-grip{height:14px;display:grid;place-items:center;cursor:ns-resize;touch-action:none}
|
|
2543
|
-
.spad-grip i{width:36px;height:4px;border-radius:9px;background:var(--ink-3);opacity:.35}
|
|
2544
|
-
.spad-grip:focus-visible{outline:0;box-shadow:inset 0 0 0 2px var(--b3)}
|
|
2545
|
-
.spad-h{display:flex;align-items:baseline;justify-content:space-between;gap:8px;padding:0 16px}
|
|
2546
|
-
.spad-h b{font-size:var(--fs-3);font-weight:600}
|
|
2547
|
-
.spad-h span{font-size:var(--fs-2);color:var(--ink-3);text-align:right}
|
|
2548
|
-
.askbar .spad textarea{flex:none;height:auto;min-height:0;max-height:none;border-radius:0;overflow-y:auto;display:block;width:100%;box-sizing:border-box;border:0;background:transparent;padding:6px 16px 8px;font:inherit;font-size:var(--fs-3);line-height:1.5;color:var(--ink);resize:none;outline:0}
|
|
2549
|
-
.askbar .spad textarea:focus{box-shadow:none}
|
|
2550
|
-
.spad:focus-within{box-shadow:0 0 0 2px var(--b3)}
|
|
2551
|
-
.spad-f{display:flex;justify-content:flex-end;padding:0 10px 10px}
|
|
2552
|
-
.askbar .spad-f .cta{width:auto;height:34px;min-height:34px;padding:0 14px;border-radius:var(--r-chip);display:inline-flex;font-size:var(--fs-2);background:var(--card);color:var(--ink)}
|
|
2553
|
-
.askbar .spad-f .cta:disabled{opacity:.5;cursor:not-allowed}
|
|
2554
|
-
@media (max-width:700px){.spad-h span{display:none}.askbar .spad textarea{font-size:var(--fs-4)}.padt{min-height:44px}}
|
|
2555
2535
|
/* Item fields at dialog level (PM, 2026-10-20): Edit ▾ and Done sit in the Detail / Conversation row; Edit opens the fields as a sheet over the body,
|
|
2556
2536
|
closed by default, so the conversation keeps the whole body. On a wide dialog the switch is not drawn, so the row holds the bar alone. */
|
|
2557
2537
|
.dlg.itm:not(.srl-open) #dTabs{display:flex!important;align-items:center;gap:8px;position:relative}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Initiative premium-chat-attach (N1-N7): Notes for a premium chat conversation, replacing the Scratchpad (the note store and the pure parts, and Notes in the viewer on the real page and server).",
|
|
3
|
+
"modules": [
|
|
4
|
+
"premium-chat-notes.test.js"
|
|
5
|
+
],
|
|
6
|
+
"panels": [
|
|
7
|
+
"premium-chat-notes-test.js"
|
|
8
|
+
],
|
|
9
|
+
"seconds": {
|
|
10
|
+
"premium-chat-notes.test.js": 1,
|
|
11
|
+
"premium-chat-notes-test.js": 30
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
/* premium-pad-test.js — the Scratchpad in the premium chat panel (initiative premium-chat-scratchpad).
|
|
4
|
-
* Serves the real My work page from the real server with a fixture model; the pad saves through the real /api/scratchpad in a scratch state folder.
|
|
5
|
-
* P1 the chip, pad closed · P2 open, type, saved for the row · P3 back after close and reload · P4 another row has its own pad
|
|
6
|
-
* P5 Add selection / Add to message fill the message box and send nothing · P6 no key, no pad · P7 the file name is a hash · P8 phone
|
|
7
|
-
*/
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
const { spawn } = require('child_process');
|
|
11
|
-
const { findBrowser } = require('./lib/find-browser');
|
|
12
|
-
const T = require('./test-run').configure({ name: 'premium-pad' });
|
|
13
|
-
const WP = require('./lib/my-work-premium.js');
|
|
14
|
-
const F = require('./fixtures/my-work-premium-facts.js');
|
|
15
|
-
|
|
16
|
-
const BASE = T.BASE;
|
|
17
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
18
|
-
const until = async (fn, ms = 6000, step = 100) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
19
|
-
const results = [];
|
|
20
|
-
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + extra : ''}`); };
|
|
21
|
-
let srv = null; let browser = null;
|
|
22
|
-
const finish = async (code) => {
|
|
23
|
-
if (browser) await browser.close().catch(() => {});
|
|
24
|
-
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
25
|
-
T.killTmux();
|
|
26
|
-
const bad = results.filter((x) => !x.cond).length;
|
|
27
|
-
console.log(`\n${results.length - bad}/${results.length} premium-pad assertions passed`);
|
|
28
|
-
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
29
|
-
};
|
|
30
|
-
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
31
|
-
const get = async (u) => (await fetch(BASE + u)).json();
|
|
32
|
-
const SHOTS = process.env.PAD_SHOTS || ''; // a folder: the suite also saves screenshots there for review
|
|
33
|
-
const shot = async (page, n) => { if (SHOTS) await page.screenshot({ path: path.join(SHOTS, n + '.png') }); };
|
|
34
|
-
const KEY = 'pad-test:row/../1', KEY2 = 'pad-test:row-2';
|
|
35
|
-
|
|
36
|
-
(async () => {
|
|
37
|
-
const exe = findBrowser();
|
|
38
|
-
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
39
|
-
let chromium;
|
|
40
|
-
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
41
|
-
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
|
|
42
|
-
await T.waitForServer(BASE);
|
|
43
|
-
browser = await chromium.launch({ executablePath: exe });
|
|
44
|
-
const model = WP.build({ v: F.view(), now: F.NOW });
|
|
45
|
-
|
|
46
|
-
const open = async ({ w = 1280, h = 900, ctx = null } = {}) => {
|
|
47
|
-
ctx = ctx || await browser.newContext({ viewport: { width: w, height: h } });
|
|
48
|
-
const page = await ctx.newPage();
|
|
49
|
-
const errors = [], asks = [];
|
|
50
|
-
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
|
|
51
|
-
await page.route('**/api/my-work-premium', (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, state: 'ready', model, as_of: Date.now() }) }));
|
|
52
|
-
await page.route('**/api/briefing-premium/**', (r) => { const rq = r.request(); if (rq.method() !== 'GET') asks.push(new URL(rq.url()).pathname); r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, turns: [], working: false }) }); });
|
|
53
|
-
await page.goto(BASE + '/premium-work.html', { waitUntil: 'domcontentloaded' });
|
|
54
|
-
await page.waitForFunction(() => document.querySelector('#dBody') !== null);
|
|
55
|
-
return { page, ctx, errors, asks };
|
|
56
|
-
};
|
|
57
|
-
const dlg = (page, key) => page.evaluate(async (key) => { const m = await import('/pm/premium-shell.js'); m.openDlg({ eye: 'Test', title: 'Pad test', say: 'Hello.', noteKey: key, html: '<p>detail</p>' }); }, key);
|
|
58
|
-
const close = (page) => page.evaluate(async () => { const m = await import('/pm/premium-shell.js'); m.closeDlg(); });
|
|
59
|
-
|
|
60
|
-
/* P1 */
|
|
61
|
-
let { page, ctx, errors, asks } = await open();
|
|
62
|
-
await dlg(page, KEY);
|
|
63
|
-
ok('P1 the Scratchpad chip is under the message box', await page.isVisible('#sPadT'));
|
|
64
|
-
ok('P1 the pad starts closed', await page.isHidden('#sPad'));
|
|
65
|
-
/* P2 */
|
|
66
|
-
await page.click('#sPadT');
|
|
67
|
-
ok('P2 the chip opens the pad and the pad has focus', await page.isVisible('#sPad') && await page.evaluate(() => document.activeElement && document.activeElement.id === 'sPadTa'));
|
|
68
|
-
ok('P2 the pad sits above the message box', await page.evaluate(() => document.querySelector('#sPad').getBoundingClientRect().bottom <= document.querySelector('#askIn').getBoundingClientRect().top + 1));
|
|
69
|
-
ok('P2 Add to message is off while the pad is empty', await page.isDisabled('#sPadAdd'));
|
|
70
|
-
await page.fill('#sPadTa', 'first line\nsecond keep this\nthird line');
|
|
71
|
-
ok('P2 typing saves the pad for this row', !!(await until(async () => (await get('/api/scratchpad?key=' + encodeURIComponent(KEY))).text === 'first line\nsecond keep this\nthird line')));
|
|
72
|
-
/* P5 */
|
|
73
|
-
await page.evaluate(() => { const t = document.querySelector('#sPadTa'); const a = t.value.indexOf('keep this'); t.focus(); t.setSelectionRange(a, a + 'keep this'.length); t.dispatchEvent(new Event('select')); });
|
|
74
|
-
ok('P5 with a selection the button reads Add selection to message', (await page.textContent('#sPadAdd')).trim() === 'Add selection to message');
|
|
75
|
-
await shot(page, 'build-select-1280-light');
|
|
76
|
-
await page.click('#sPadAdd');
|
|
77
|
-
ok('P5 only the selection goes into the message box', (await page.inputValue('#askIn')) === 'keep this');
|
|
78
|
-
ok('P5 the message box has focus and nothing was sent', await page.evaluate(() => document.activeElement.id === 'askIn') && asks.length === 0, JSON.stringify(asks));
|
|
79
|
-
ok('P5 the pad keeps its text', (await page.inputValue('#sPadTa')).includes('keep this'));
|
|
80
|
-
await page.evaluate(() => { const t = document.querySelector('#sPadTa'); t.setSelectionRange(0, 0); t.dispatchEvent(new Event('select')); });
|
|
81
|
-
await page.click('#sPadAdd');
|
|
82
|
-
const multi = await page.evaluate(() => document.querySelector('#askIn').tagName === 'TEXTAREA');
|
|
83
|
-
const want = 'keep this\nfirst line\nsecond keep this\nthird line';
|
|
84
|
-
ok('P5 Add to message adds the whole pad after what is typed', (await page.inputValue('#askIn')) === (multi ? want : want.replace(/\n/g, ' ')), JSON.stringify(await page.inputValue('#askIn')));
|
|
85
|
-
ok('P5 still nothing sent', asks.length === 0);
|
|
86
|
-
/* P3 */
|
|
87
|
-
await page.fill('#sPadTa', 'saved on close');
|
|
88
|
-
await close(page);
|
|
89
|
-
ok('P3 closing the dialog saves an edit at once', !!(await until(async () => (await get('/api/scratchpad?key=' + encodeURIComponent(KEY))).text === 'saved on close', 2000)));
|
|
90
|
-
await page.click('body').catch(() => {});
|
|
91
|
-
/* P4 */
|
|
92
|
-
await dlg(page, KEY2);
|
|
93
|
-
ok('P4 another row has its own, empty pad', (await page.inputValue('#sPadTa')) === '' && await page.isVisible('#sPad'));
|
|
94
|
-
await close(page);
|
|
95
|
-
await page.reload({ waitUntil: 'domcontentloaded' }); await page.waitForFunction(() => document.querySelector('#dBody') !== null);
|
|
96
|
-
await dlg(page, KEY);
|
|
97
|
-
ok('P3 after a reload the row\'s pad text is back and the pad is open as left', !!(await until(async () => (await page.inputValue('#sPadTa')) === 'saved on close')) && await page.isVisible('#sPad'));
|
|
98
|
-
await page.click('#sPadT');
|
|
99
|
-
ok('P3 closed, the chip says how many lines the pad holds', /1 line/.test(await page.textContent('#sPadT')) && await page.isHidden('#sPad'));
|
|
100
|
-
await close(page);
|
|
101
|
-
/* P6 */
|
|
102
|
-
await dlg(page, null);
|
|
103
|
-
ok('P6 a dialog with no conversation has no pad', await page.isHidden('#sPadT') && await page.isHidden('#sPad'));
|
|
104
|
-
await close(page);
|
|
105
|
-
/* P7 */
|
|
106
|
-
const files = []; const walk = (d) => { for (const n of fs.readdirSync(d, { withFileTypes: true })) { const f = path.join(d, n.name); if (n.isDirectory()) walk(f); else files.push(path.relative(T.STATE_DIR, f)); } };
|
|
107
|
-
try { walk(path.join(T.STATE_DIR, 'scratchpad')); } catch { /* none */ }
|
|
108
|
-
ok('P7 a row pad is filed under a hashed name, never the key', files.length > 0 && files.every((f) => /^scratchpad\/[^/]+\/row-[0-9a-f]{32}\.txt$/.test(f)), files.join(', '));
|
|
109
|
-
const bad = await fetch(BASE + '/api/scratchpad?key=', { method: 'GET' }); ok('P7 an empty key is refused', bad.status === 400);
|
|
110
|
-
ok('P1-P7 no page errors', errors.length === 0, errors.join(' | '));
|
|
111
|
-
await ctx.close();
|
|
112
|
-
|
|
113
|
-
/* P8 phone */
|
|
114
|
-
({ page, ctx, errors } = await open({ w: 390, h: 844 }));
|
|
115
|
-
await dlg(page, KEY);
|
|
116
|
-
await until(async () => (await page.inputValue('#sPadTa')) === 'saved on close');
|
|
117
|
-
await page.evaluate(async () => { const m = await import('/pm/premium-shell.js'); m.setTab('chat'); });
|
|
118
|
-
if (await page.isHidden('#sPad')) await page.click('#sPadT');
|
|
119
|
-
await shot(page, 'build-open-390-light');
|
|
120
|
-
ok('P8 on a phone the pad and chip fit the width', await page.evaluate(() => { const w = innerWidth; return ['#sPad', '#sPadT', '#askIn'].every((s) => { const r = document.querySelector(s).getBoundingClientRect(); return r.width > 0 && r.left >= 0 && r.right <= w + 1; }); }));
|
|
121
|
-
ok('P8 the chip is a 44px target on a phone', await page.evaluate(() => document.querySelector('#sPadT').getBoundingClientRect().height >= 44));
|
|
122
|
-
ok('P8 no page errors', errors.length === 0, errors.join(' | '));
|
|
123
|
-
await ctx.close();
|
|
124
|
-
finish();
|
|
125
|
-
})();
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/* pm/premium-pad.js — the Scratchpad in the premium chat panel (initiative premium-chat-scratchpad).
|
|
2
|
-
* The console's per-session pad (c3-session-term.js makePad), kept per conversation: one pad for each row's key, because a row's session
|
|
3
|
-
* starts with its first message and can end and start again. Saved on this machine through /api/scratchpad?key=… as you type.
|
|
4
|
-
* "Add to message" puts the pad text, or the selected part of it, into the message box. Nothing is sent; the pad keeps its text. */
|
|
5
|
-
import { pmGet, pmPost } from './http.js';
|
|
6
|
-
|
|
7
|
-
const OPEN_KEY = 'pmos.premium.pad.open', H_KEY = 'pmos.premium.pad.h';
|
|
8
|
-
export const PAD_H = 132, PAD_MIN = 64, PAD_STEP = 18;
|
|
9
|
-
const PEN = '<svg class="i" viewBox="0 0 24 24"><path d="M4 20h4L19 9l-4-4L4 16v4z"/><path d="M14 6l4 4"/></svg>';
|
|
10
|
-
|
|
11
|
-
/** The lines the pad holds, for the closed chip ("Scratchpad · 3 lines"). Blank lines at the ends do not count. Pure. */
|
|
12
|
-
export function padLines(text) { const t = String(text || '').replace(/^\s+|\s+$/g, ''); return t ? t.split('\n').length : 0; }
|
|
13
|
-
/** The message box after Add to message: the added text goes after what is already typed, on a new line. Pure. */
|
|
14
|
-
export function addToMessage(cur, add) {
|
|
15
|
-
const a = String(add || '').replace(/^\n+|\s+$/g, ''); if (!a) return String(cur || '');
|
|
16
|
-
const c = String(cur || '').replace(/\s+$/, '');
|
|
17
|
-
return c ? c + '\n' + a : a;
|
|
18
|
-
}
|
|
19
|
-
/** The pad height in px, kept between the minimum and 60% of the room. Pure. */
|
|
20
|
-
export function clampPadH(h, room) { const n = Math.round(Number(h)); const max = Math.max(PAD_MIN, Math.round((Number(room) || 600) * 0.6)); return Number.isFinite(n) ? Math.min(max, Math.max(PAD_MIN, n)) : PAD_H; }
|
|
21
|
-
|
|
22
|
-
const store = { get: (k) => { try { return localStorage.getItem(k); } catch { return null; } }, set: (k, v) => { try { localStorage.setItem(k, v); } catch { /* not remembered */ } } };
|
|
23
|
-
export const padMarkup = () => `<div class="spad" id="sPad" hidden><div class="spad-grip" id="sPadGrip" role="separator" aria-orientation="horizontal" tabindex="0" aria-label="Resize the scratchpad" title="Drag to resize the scratchpad. Double-click for the default size."><i></i></div><div class="spad-h"><b>Scratchpad</b><span>This conversation · saved on this machine</span></div><textarea id="sPadTa" aria-label="Scratchpad" placeholder="Notes for this conversation. Claude does not see them until you add them to a message." maxlength="200000"></textarea><div class="spad-f"><button type="button" class="cta alt sm" id="sPadAdd" disabled title="Put the text in the message box. Nothing is sent.">Add to message</button></div></div>`;
|
|
24
|
-
export const padChipMarkup = () => `<button type="button" class="padt" id="sPadT" aria-expanded="false" aria-controls="sPad" hidden>${PEN}<span>Scratchpad</span><em id="sPadN"></em></button>`;
|
|
25
|
-
|
|
26
|
-
let cur = null; // the pad on show: { key, ws, ta, flush }
|
|
27
|
-
/** Flush the open pad's unsaved text at once (the dialog closes, the page hides). */
|
|
28
|
-
export function flushPad() { if (cur) cur.flush(); }
|
|
29
|
-
|
|
30
|
-
/** Wire the pad that padMarkup() and padChipMarkup() drew into the dialog for the row `key`. No key: no conversation, so no pad. */
|
|
31
|
-
export function mountPad({ key, ws, input }) {
|
|
32
|
-
flushPad(); cur = null;
|
|
33
|
-
const box = document.getElementById('sPad'), chip = document.getElementById('sPadT');
|
|
34
|
-
if (!box || !chip) return;
|
|
35
|
-
if (!key) { chip.hidden = true; box.hidden = true; return; }
|
|
36
|
-
const ta = document.getElementById('sPadTa'), add = document.getElementById('sPadAdd'), grip = document.getElementById('sPadGrip'), n = document.getElementById('sPadN');
|
|
37
|
-
const q = 'key=' + encodeURIComponent(key) + (ws ? '&ws=' + encodeURIComponent(ws) : '');
|
|
38
|
-
let typed = false, timer = null, pending = null;
|
|
39
|
-
const me = { key, ws, ta };
|
|
40
|
-
me.flush = () => {
|
|
41
|
-
if (timer) { clearTimeout(timer); timer = null; }
|
|
42
|
-
if (pending === null) return;
|
|
43
|
-
const text = pending; pending = null;
|
|
44
|
-
pmPost('/api/scratchpad', { key, ws: ws || undefined, text }).catch(() => { /* the text stays in the box */ });
|
|
45
|
-
};
|
|
46
|
-
cur = me;
|
|
47
|
-
const sel = () => (ta.selectionEnd > ta.selectionStart ? ta.value.slice(ta.selectionStart, ta.selectionEnd) : '');
|
|
48
|
-
const sync = () => {
|
|
49
|
-
const s = sel().trim();
|
|
50
|
-
add.disabled = !ta.value.trim();
|
|
51
|
-
add.textContent = s ? 'Add selection to message' : 'Add to message';
|
|
52
|
-
const k = padLines(ta.value);
|
|
53
|
-
n.textContent = box.hidden && k ? ` · ${k} ${k === 1 ? 'line' : 'lines'}` : '';
|
|
54
|
-
};
|
|
55
|
-
const setOpen = (on) => {
|
|
56
|
-
box.hidden = !on; chip.classList.toggle('on', on); chip.setAttribute('aria-expanded', String(on));
|
|
57
|
-
chip.title = on ? 'Hide the scratchpad. The text is kept.' : 'Show the scratchpad';
|
|
58
|
-
sync();
|
|
59
|
-
};
|
|
60
|
-
let h = Number(store.get(H_KEY)) || 0;
|
|
61
|
-
const room = () => (document.getElementById('dBody') || document.body).clientHeight;
|
|
62
|
-
const applyH = () => { // the height is the box's own rows, as the console pad does, so no inline style
|
|
63
|
-
ta.rows = Math.max(2, Math.round((h || PAD_H) / (parseFloat(getComputedStyle(ta).lineHeight) || 21))); grip.setAttribute('aria-valuenow', String(h || PAD_H)); };
|
|
64
|
-
const setH = (v) => { h = clampPadH(v, room()); applyH(); };
|
|
65
|
-
const saveH = () => store.set(H_KEY, h ? String(h) : '');
|
|
66
|
-
chip.hidden = false;
|
|
67
|
-
chip.onclick = () => { const on = box.hidden; store.set(OPEN_KEY, on ? 'open' : 'closed'); setOpen(on); if (on) ta.focus(); };
|
|
68
|
-
ta.oninput = () => { typed = true; pending = ta.value; if (timer) clearTimeout(timer); timer = setTimeout(me.flush, 500); sync(); };
|
|
69
|
-
ta.onselect = sync; ta.onkeyup = sync; ta.onmouseup = sync;
|
|
70
|
-
ta.onkeydown = (e) => { if (e.key === 'Enter') e.stopPropagation(); }; // Enter is a new line in the pad, never a send
|
|
71
|
-
add.onclick = () => {
|
|
72
|
-
const text = sel() || ta.value; if (!text.trim() || !input) return;
|
|
73
|
-
const v = addToMessage(input.value, text);
|
|
74
|
-
input.value = input.tagName === 'TEXTAREA' ? v : v.replace(/[ \t]*\n[ \t]*/g, ' '); // a one-line box would drop the line breaks and join the words
|
|
75
|
-
input.dispatchEvent(new Event('input', { bubbles: true })); // the message box grows and the / menu reads it, as if typed
|
|
76
|
-
input.focus();
|
|
77
|
-
try { input.setSelectionRange(input.value.length, input.value.length); } catch { /* a box without a caret */ }
|
|
78
|
-
const note = document.getElementById('askNote'); if (note) note.textContent = 'Added to your message. Press send when it reads right. The pad keeps its text.';
|
|
79
|
-
};
|
|
80
|
-
let y0 = null, h0 = 0;
|
|
81
|
-
grip.onpointerdown = (e) => { y0 = e.clientY; h0 = h || PAD_H; try { grip.setPointerCapture(e.pointerId); } catch { /* none */ } };
|
|
82
|
-
grip.onpointermove = (e) => { if (y0 != null) setH(h0 + (y0 - e.clientY)); };
|
|
83
|
-
grip.onpointerup = grip.onpointercancel = () => { if (y0 == null) return; y0 = null; saveH(); };
|
|
84
|
-
grip.ondblclick = () => { h = 0; applyH(); saveH(); };
|
|
85
|
-
grip.onkeydown = (e) => { if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return; e.preventDefault(); setH((h || PAD_H) + (e.key === 'ArrowUp' ? PAD_STEP : -PAD_STEP)); saveH(); };
|
|
86
|
-
ta.value = ''; applyH(); setOpen(store.get(OPEN_KEY) === 'open');
|
|
87
|
-
pmGet('/api/scratchpad?' + q).then((r) => { if (cur === me && !typed && r && typeof r.text === 'string') { ta.value = r.text; sync(); } }).catch(() => { /* an empty pad */ });
|
|
88
|
-
}
|
|
89
|
-
if (typeof addEventListener === 'function') addEventListener('pagehide', flushPad);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"_comment": "Initiative premium-chat-scratchpad: the Scratchpad in the premium chat panel (pure parts, and the pad on the real page and server).",
|
|
3
|
-
"modules": [
|
|
4
|
-
"premium-pad.test.js"
|
|
5
|
-
],
|
|
6
|
-
"panels": [
|
|
7
|
-
"premium-pad-test.js"
|
|
8
|
-
],
|
|
9
|
-
"seconds": {
|
|
10
|
-
"premium-pad.test.js": 1,
|
|
11
|
-
"premium-pad-test.js": 40
|
|
12
|
-
}
|
|
13
|
-
}
|