create-pmos 0.738.0 → 0.740.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 +33 -45
- package/payload/AGENTS.md +1 -0
- 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/changelog.json +32 -0
- package/workspace/guide/cli.md +10 -0
- package/workspace/guide/layout.md +3 -1
- package/workspace/lib/glossary-cli.js +94 -0
- package/workspace/lib/glossary.js +112 -0
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-glossary.js +29 -0
- package/workspace/lib/routes-search.js +12 -3
- package/workspace/lib/search-ask.js +174 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-ev.css +6 -0
- package/workspace/public/pm/cozy-nav.js +2 -0
- package/workspace/public/pm/cozy-search.js +22 -3
- package/workspace/public/pm/cozy-today-page.css +3 -3
- package/workspace/public/pm/glossary.js +250 -0
- package/workspace/task-card-test.js +16 -0
- package/workspace/test-lists/product-glossary.json +9 -0
- package/workspace/test-lists/search-answers-questions.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.740.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": {
|
|
@@ -33,6 +33,38 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.740.0",
|
|
38
|
+
"at": "2026-11-23T08:20:40.488Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1654,
|
|
43
|
+
"t": "A product's own words show their meaning on hover, on every page (A386)",
|
|
44
|
+
"s": "A product's own words show their meaning on hover, on every page (A386)",
|
|
45
|
+
"k": "new"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"v": "0.739.0",
|
|
51
|
+
"at": "2026-11-23T07:58:34.158Z",
|
|
52
|
+
"f": 4,
|
|
53
|
+
"prs": [
|
|
54
|
+
{
|
|
55
|
+
"n": 1649,
|
|
56
|
+
"t": "Ctrl K answers a question from your own files, with its sources",
|
|
57
|
+
"s": "Ctrl K answers a question from your own files, with its sources",
|
|
58
|
+
"k": "new"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"n": 1651,
|
|
62
|
+
"t": "Open questions styles use tokens (open-questions-today, Checker C6)",
|
|
63
|
+
"s": "Open questions styles use tokens (open-questions-today, Checker C6)",
|
|
64
|
+
"k": "fix"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
36
68
|
{
|
|
37
69
|
"v": "0.738.0",
|
|
38
70
|
"at": "2026-11-23T07:20:29.240Z",
|
|
@@ -398,50 +430,6 @@
|
|
|
398
430
|
"k": "new"
|
|
399
431
|
}
|
|
400
432
|
]
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
"v": "0.715.0",
|
|
404
|
-
"at": "2026-11-22T20:02:36.257Z",
|
|
405
|
-
"f": 4,
|
|
406
|
-
"prs": [
|
|
407
|
-
{
|
|
408
|
-
"n": 1581,
|
|
409
|
-
"t": "The ? list is sized by tokens and uses Komorebi parts only (Checker K5, action-keys)",
|
|
410
|
-
"s": "The ?",
|
|
411
|
-
"k": "fix"
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
"n": 1582,
|
|
415
|
-
"t": "Key hints step back once a key is learned (A480)",
|
|
416
|
-
"s": "Key hints step back once a key is learned (A480)",
|
|
417
|
-
"k": "new"
|
|
418
|
-
},
|
|
419
|
-
{
|
|
420
|
-
"n": 1584,
|
|
421
|
-
"t": "Set a task's sprint and priority in place, with one Undo (job #1563)",
|
|
422
|
-
"s": "Set a task's sprint and priority in place, with one Undo (job #1563)",
|
|
423
|
-
"k": "new"
|
|
424
|
-
}
|
|
425
|
-
]
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
"v": "0.714.0",
|
|
429
|
-
"at": "2026-11-22T18:31:53.842Z",
|
|
430
|
-
"f": 4,
|
|
431
|
-
"prs": [
|
|
432
|
-
{
|
|
433
|
-
"n": 1578,
|
|
434
|
-
"t": "One key each for approve, open, next sprint, park and Undo, plus a ? list (job #1577)",
|
|
435
|
-
"s": "One key each for approve, open, next sprint, park and Undo, plus a ?",
|
|
436
|
-
"k": "new"
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
"n": 1579,
|
|
440
|
-
"t": "One next step on a page that has nothing in it yet (A474)",
|
|
441
|
-
"s": "One next step on a page that has nothing in it yet (A474)",
|
|
442
|
-
"k": "new"
|
|
443
|
-
}
|
|
444
|
-
]
|
|
445
433
|
}
|
|
446
434
|
]
|
|
447
435
|
}
|
package/payload/AGENTS.md
CHANGED
|
@@ -113,6 +113,7 @@ The PM talks to you from an initiative's popup in the workspace. PMOS acts by it
|
|
|
113
113
|
- **The merge ✦ ("7 references and 2 retros can each be one artefact. Merge them?").** The popup derives it from the files: it shows while several different files of one kind belong to the initiative. When you merge files, put `superseded_by: <path of the merged file>` in the frontmatter of each old file. The Artefacts list then shows the merged file, folds each old file under it as an earlier version, and the ✦ goes away by itself. Delete nothing.
|
|
114
114
|
- **The case card (Problem, Goal, Done when).** It reads the Experiment and Done test artefacts first, then the record's Problem, Goal and Done test sections. When the PM says yes to a case line, save it where the card reads it: `pmos artefacts set experiment:<id> experiment why --text "<problem>"`, `pmos artefacts set experiment:<id> experiment hypothesis --text "<goal>"`, and `pmos artefacts set experiment:<id> done-test check --text "<one check>"` once for each check. `pmos why` and `pmos ready check` read the same lines.
|
|
115
115
|
- **The Positioning part of the Strategy card.** When the PM agrees a positioning statement or key message, keep it with `pmos positioning keep --text "<line>" --cites <keys> [--kind positioning]`, citing the strategy lines it comes from (`pmos positioning strategy` lists the keys). Drop one with `pmos positioning drop <id>`. The Board shows what these write.
|
|
116
|
+
- **The product glossary (a word's meaning on hover).** When the PM asks to explain, add or change one of the product's own words ("add MAGW to the glossary"), run `pmos glossary set <term> "<meaning>"` in the product's repository; `pmos glossary remove <term>` takes one out and `pmos glossary` lists them. Every page reads the same file and shows the meaning on hover, or on a long press on a phone.
|
|
116
117
|
- **A program's card (For, Goal).** After the PM's yes, run `pmos program charter <program id> --why "<what it is for>"` or `--goal "<goal>"` in the repository where the program was made. Its Done when comes from the last milestone and the target date.
|
|
117
118
|
- **The ✦ that drafts missing documents.** Save a PRD as a file the record names in `prd_path:`, a rubric in `rubric_path:`, and the done test with `pmos artefacts set experiment:<id> done-test check`. A file that nothing names does not show in the Artefacts list.
|
|
118
119
|
- **A stage's dates on the timeline.** A stage's bar runs from the earliest start to the latest end of its tasks (a task with no start counts from its due date). To change a stage's dates, change the dates of its tasks, with the PM's yes. Do not edit the workflow history to move a bar.
|
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-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-23T08:20:36Z"}
|
|
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-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-23T08:20:36Z"}
|
|
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-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-23T08:20:36Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.740.0",
|
|
4
|
+
"at": "2026-11-23T08:20:40.488Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1654,
|
|
9
|
+
"t": "A product's own words show their meaning on hover, on every page (A386)",
|
|
10
|
+
"s": "A product's own words show their meaning on hover, on every page (A386)",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"v": "0.739.0",
|
|
17
|
+
"at": "2026-11-23T07:58:34.158Z",
|
|
18
|
+
"f": 4,
|
|
19
|
+
"prs": [
|
|
20
|
+
{
|
|
21
|
+
"n": 1649,
|
|
22
|
+
"t": "Ctrl K answers a question from your own files, with its sources",
|
|
23
|
+
"s": "Ctrl K answers a question from your own files, with its sources",
|
|
24
|
+
"k": "new"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"n": 1651,
|
|
28
|
+
"t": "Open questions styles use tokens (open-questions-today, Checker C6)",
|
|
29
|
+
"s": "Open questions styles use tokens (open-questions-today, Checker C6)",
|
|
30
|
+
"k": "fix"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
2
34
|
{
|
|
3
35
|
"v": "0.738.0",
|
|
4
36
|
"at": "2026-11-23T07:20:29.240Z",
|
package/workspace/guide/cli.md
CHANGED
|
@@ -278,6 +278,16 @@ The idle lab run uses only the first three commands:
|
|
|
278
278
|
- `pmos lab critic checks [--root <dir>]`: the checks the critic uses for the product in that folder. No server is needed.
|
|
279
279
|
- `pmos lab critic label <run> <n> real|noise`: your word on finding `n` of a critic run. `pmos lab critic stats` counts the runs, the findings, and how many you called real or noise.
|
|
280
280
|
|
|
281
|
+
### pmos glossary: the product's own words, explained on every page
|
|
282
|
+
|
|
283
|
+
Run it in the product's repository, or pass `--root <dir>`. It writes the product's records folder on disk, needs no running workspace and sends nothing.
|
|
284
|
+
|
|
285
|
+
- `pmos glossary` (or `pmos glossary list`) lists the words and what they mean. `--json` prints them for a script.
|
|
286
|
+
- `pmos glossary set <term> <meaning…>` adds a word or changes its meaning, for example `pmos glossary set OTP "One-time password"`. A word is at most 40 characters and a meaning at most 200, each on one line. A word written with a capital letter (OTP) is found in that case only; an all-lowercase word (paywall) is found in any case.
|
|
287
|
+
- `pmos glossary remove <term>` takes a word out.
|
|
288
|
+
- On every workspace page, the words of the products you show get a faint dotted underline. Hover over one, or press and hold it on a phone, to see what it means. When you show more than one product, the card names whose word it is.
|
|
289
|
+
- `pmos glossary uses [--days 7]` prints how many meanings were shown on this computer in the last days, from the local use log. Its last line is the number.
|
|
290
|
+
|
|
281
291
|
### pmos questions: every open question in one list
|
|
282
292
|
|
|
283
293
|
Run it in the product's repository, or pass `--root <dir>`. It changes nothing, takes no default and sends nothing.
|
|
@@ -86,7 +86,7 @@ What you do not finish is carried to the next day, and the badge says for how lo
|
|
|
86
86
|
|
|
87
87
|
Findings that fit no initiative (the Lab) are ✦ rows in the log. ✓ keeps one and starts an initiative from it. ✕ drops it.
|
|
88
88
|
|
|
89
|
-
**Open questions in Decide.** The **Decide** tab also lists every question that is not answered yet, across all initiatives, in two groups. **Waiting on you · n · oldest first** has the questions only you can answer: a plan change PMOS holds for want of a source, a drafted ticket's open gaps, a sign-off, and the drafts PMOS filed that nobody kept or dropped (one row per initiative, for example "4 drafts on Faster checkout wait on you"). **Waiting on others · n** has the questions a teammate must answer, each starting with their name. Each row says its initiative and its kind, and under it what PMOS does if nobody answers ("If nobody answers by 7 Dec, PMOS drops the drafts; nothing on the plan changes.") or why it has no default ("No default: …"). The badge says how many days it waited; it turns red after 14 days. Press a row, or its arrow, to open the initiative and answer there. On a teammate's row, the speech icon writes a short reminder in the chat for you to read and send; nothing is sent by itself. A question whose default is due today is also a row in the log. The Overview says how many wait on you and the oldest. When nothing waits, there is no group, and the Decide tab shows only when it has lines. The phone shows the same groups in the Decide filter. `pmos questions` prints the same list in a terminal (see the [Command reference](cli.md)).
|
|
89
|
+
**Open questions in Decide.** The **Decide** tab also lists every question that is not answered yet, across all initiatives, in two groups. **Waiting on you · n · oldest first** has the questions only you can answer: a plan change PMOS holds for want of a source, a drafted ticket's open gaps, a sign-off, and the drafts PMOS filed that nobody kept or dropped (one row per initiative, for example "4 drafts on Faster checkout wait on you"). **Waiting on others · n** has the questions a teammate must answer, each starting with their name. Each row says its initiative and its kind, and under it what PMOS does if nobody answers ("If nobody answers by 7 Dec, PMOS drops the drafts; nothing on the plan changes.") or why it has no default ("No default: …"). The badge says how many days it waited; it turns red after 14 days. Press a row, or its arrow, to open the initiative and answer there. On a teammate's row, the speech icon writes a short reminder in the chat for you to read and send; nothing is sent by itself. A question whose default is due today is also a row in the log. The Overview says how many wait on you and the oldest. When nothing waits, there is no group, and the Decide tab shows only when it has lines. The phone shows the same groups in the Decide filter, each headed in small capitals like the log's own heading. `pmos questions` prints the same list in a terminal (see the [Command reference](cli.md)).
|
|
90
90
|
|
|
91
91
|
The agenda lists the day's events in time order, each with its start time, and a red line with the time now between the past and the next ones. Past events are dashed. The next event says how soon it starts ("in 20 min"). A meeting with a call has a play button: one press joins the call and starts the recording. It shows your meetings, the reports that go out today at their time, your own events, and focus time: the free time from now until the next meeting, held for the first row of your log, in a dashed box. Focus time is only ever a gap before a meeting: it never runs past the last one. Press the focus time to open that row. A day with no meeting or event shows one quiet line, for example "No events today · 9 h free". **Events** at the top right opens the Events page. "PMOS did" is not on Today; it moves to Routine.
|
|
92
92
|
|
|
@@ -278,6 +278,8 @@ The Board shows initiatives by stage, with programs, a timeline and a list. Inte
|
|
|
278
278
|
|
|
279
279
|
When the words you type in Search point clearly to one thing, the first row is the answer: one sentence from your own files, then where it came from. Type an initiative's name and the answer is its goal, with its check date. Ask "when is the pilot launch" and the answer is the sentence in your plan that holds the date. Press Enter on the answer to open its source. PMOS copies the sentence as it is written and does not write it. When no one sentence holds all your words, or two initiatives match equally, there is no answer row, and the matches show as before.
|
|
280
280
|
|
|
281
|
+
When you type a question, such as "why do some customers still use a spreadsheet instead of the app?", and no one sentence holds all your words, the first row says "Finding an answer in your work…". After a few seconds it shows a short answer, written only from passages of your own files, and the names of the files it used. Press Enter on the answer to open the first of them. To go deeper, pick "Ask PMOS" in the next row. When your files do not answer the question, the row goes away and the matches stay.
|
|
282
|
+
|
|
281
283
|
## Keys
|
|
282
284
|
|
|
283
285
|
| Key | What it does |
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* glossary-cli.js — `pmos glossary …`: a product's own words and what they mean (bet A386, initiative glossary-hover; lib/glossary.js).
|
|
3
|
+
*
|
|
4
|
+
* pmos glossary [list] [--json] [--root <dir>] the words, sorted
|
|
5
|
+
* pmos glossary set <term> <meaning…> [--root <dir>] add a word or change its meaning; every page shows it on hover
|
|
6
|
+
* pmos glossary remove <term> [--root <dir>] take a word out
|
|
7
|
+
* pmos glossary uses [--days 7] meanings shown on this computer in the last days; the last line is the number
|
|
8
|
+
*
|
|
9
|
+
* It writes the product's records folder on disk (the same file the workspace reads), so it needs no running server, and the page shows
|
|
10
|
+
* the change the next time it loads. Exit codes: 0 done, 1 refused (the reason is printed), 2 usage. */
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { execFileSync } = require('child_process');
|
|
14
|
+
const G = require('./glossary.js');
|
|
15
|
+
|
|
16
|
+
const COMMANDS = { glossary: ['list', 'set', 'remove', 'uses'] };
|
|
17
|
+
const USAGE = [
|
|
18
|
+
'usage: pmos glossary [list|set|remove|uses] — the product\'s own words; every page shows a word\'s meaning on hover (a long press on a phone)',
|
|
19
|
+
' pmos glossary the words and what they mean',
|
|
20
|
+
' pmos glossary set <term> <meaning…> add a word or change its meaning, for example: pmos glossary set OTP "One-time password"',
|
|
21
|
+
' pmos glossary remove <term> take a word out',
|
|
22
|
+
' pmos glossary uses [--days 7] how many meanings were shown on this computer; the last line is the number',
|
|
23
|
+
' every command: [--root <dir>] [--json]',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
function repoRoot(cwd) {
|
|
27
|
+
try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
|
|
28
|
+
catch { return cwd; }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parse(argv) {
|
|
32
|
+
const pos = []; const flags = {};
|
|
33
|
+
for (let i = 0; i < argv.length; i++) {
|
|
34
|
+
const a = argv[i];
|
|
35
|
+
if (a === '--root' || a === '--days') flags[a.slice(2)] = argv[++i];
|
|
36
|
+
else if (a.startsWith('--root=')) flags.root = a.slice(7);
|
|
37
|
+
else if (a.startsWith('--days=')) flags.days = a.slice(7);
|
|
38
|
+
else if (a.startsWith('--')) flags[a.slice(2)] = true;
|
|
39
|
+
else if (a === '-h') flags.help = true;
|
|
40
|
+
else pos.push(a);
|
|
41
|
+
}
|
|
42
|
+
return { pos, flags };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Date.now(), runtimeDir = null } = {}) {
|
|
46
|
+
const { pos, flags } = parse(argv[0] === 'glossary' ? argv.slice(1) : argv.slice());
|
|
47
|
+
if (flags.help || pos[0] === 'help') { for (const l of USAGE) say(l); return 0; }
|
|
48
|
+
const cmd = pos[0] || 'list';
|
|
49
|
+
if (!COMMANDS.glossary.includes(cmd)) { say(`✗ ${cmd} is not a command of pmos glossary`); for (const l of USAGE) say(l); return 2; }
|
|
50
|
+
const json = !!flags.json;
|
|
51
|
+
|
|
52
|
+
if (cmd === 'uses') {
|
|
53
|
+
const days = flags.days === undefined ? 7 : Number(flags.days);
|
|
54
|
+
if (!Number.isInteger(days) || days < 1 || days > 30) { say('✗ --days is a whole number from 1 to 30'); return 2; }
|
|
55
|
+
let lines = [];
|
|
56
|
+
try { const dir = runtimeDir || require('./state-root.js').defaultRoot({ env: process.env }); lines = require('./use-log.js').readLines(dir); } catch { lines = []; }
|
|
57
|
+
const n = G.uses(lines, days, now);
|
|
58
|
+
if (json) { say(JSON.stringify({ ok: true, days, uses: n })); return 0; }
|
|
59
|
+
say(`${G.TAG} ${n} meaning${n === 1 ? '' : 's'} shown in the last ${days} day${days === 1 ? '' : 's'} on this computer.`);
|
|
60
|
+
say(String(n));
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (flags.root === true || flags.root === '') { say('✗ --root needs a value'); return 2; }
|
|
65
|
+
const root = path.resolve(flags.root || repoRoot(cwd));
|
|
66
|
+
let isDir = false; try { isDir = fs.statSync(root).isDirectory(); } catch { isDir = false; }
|
|
67
|
+
if (!isDir) { say(`✗ ${root} is not a directory`); return 1; }
|
|
68
|
+
const dir = G.dirOf(root);
|
|
69
|
+
|
|
70
|
+
if (cmd === 'list') {
|
|
71
|
+
const terms = G.read(dir);
|
|
72
|
+
if (json) { say(JSON.stringify({ ok: true, terms })); return 0; }
|
|
73
|
+
if (!terms.length) say('The glossary is empty. Add a word: pmos glossary set <term> <meaning>');
|
|
74
|
+
for (const t of terms) say(`${t.term}: ${t.meaning}`);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
if (cmd === 'set') {
|
|
78
|
+
if (pos.length < 3) { say('✗ give the word and its meaning: pmos glossary set <term> <meaning…>'); return 2; }
|
|
79
|
+
const r = G.set(dir, pos[1], pos.slice(2).join(' '), now);
|
|
80
|
+
if (!r.ok) { say('✗ ' + r.error); return 1; }
|
|
81
|
+
if (json) { say(JSON.stringify(r)); return 0; }
|
|
82
|
+
say(`✓ ${r.term} is in the glossary. Every page shows its meaning on hover.`);
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
// remove
|
|
86
|
+
if (pos.length !== 2) { say('✗ give one word: pmos glossary remove <term> (quote a word with spaces)'); return 2; }
|
|
87
|
+
const r = G.remove(dir, pos[1], now);
|
|
88
|
+
if (!r.ok) { say('✗ ' + r.error); return 1; }
|
|
89
|
+
if (json) { say(JSON.stringify(r)); return 0; }
|
|
90
|
+
say(`✓ ${r.term} is out of the glossary.`);
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* glossary.js — a product's glossary of its own words (bet A386, initiative glossary-hover). THE ONE WRITER and THE ONE FOLD of
|
|
3
|
+
* glossary.jsonl. `pmos glossary` (lib/glossary-cli.js) writes it, GET /api/glossary (lib/routes-glossary.js) reads it for the page,
|
|
4
|
+
* and pm/glossary.js shows a word's meaning on hover (a long press on a phone) on every page.
|
|
5
|
+
*
|
|
6
|
+
* read(dir) → [{ term, meaning, at }] the current words, sorted by term (any case)
|
|
7
|
+
* set(dir, term, meaning, now) → { ok, term, terms } | { ok: false, error } adds a word or changes its meaning
|
|
8
|
+
* remove(dir, term, now) → { ok, term, terms } | { ok: false, error } takes a word out (an empty meaning line)
|
|
9
|
+
* checkTerm(term) · checkMeaning(meaning) → '' when good, else the reason
|
|
10
|
+
* dirOf(root) → the records folder of the product checkout at `root`
|
|
11
|
+
* uses(lines, days, now) → how many meanings were shown (use-log `glossary-show`) in the last `days` days PURE
|
|
12
|
+
*
|
|
13
|
+
* WHERE. `dir` is the product's records folder (lib/records-dir.js): planning/records in the PMOS repo, pmos/state/records in a kit
|
|
14
|
+
* product. The file is append-only: one line { at, term, meaning } per change; an empty meaning takes the word out. The last line for a
|
|
15
|
+
* word wins, and a word is matched with any case, so "otp" changes "OTP" (and the new spelling is kept).
|
|
16
|
+
* Log lines say [glossary]. Nothing is sent anywhere. */
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
const FILE = 'glossary.jsonl';
|
|
21
|
+
const MAX_TERM = 40;
|
|
22
|
+
const MAX_MEANING = 200;
|
|
23
|
+
const MAX_TERMS = 300;
|
|
24
|
+
const SHOW = 'glossary-show'; // the use-log control a meaning shown is noted under (pm/glossary.js)
|
|
25
|
+
const TAG = '[glossary]';
|
|
26
|
+
const say = (s) => { try { console.log(TAG + ' ' + s); } catch { /* no console */ } };
|
|
27
|
+
const one = (v) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim();
|
|
28
|
+
const keyOf = (t) => one(t).toLowerCase();
|
|
29
|
+
|
|
30
|
+
function checkTerm(term) {
|
|
31
|
+
const t = one(term);
|
|
32
|
+
if (!t) return 'Name the word.';
|
|
33
|
+
if (t.length > MAX_TERM) return `A word is at most ${MAX_TERM} characters.`;
|
|
34
|
+
if (!/[\p{L}\p{N}]/u.test(t)) return 'A word needs a letter or a digit.';
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function checkMeaning(meaning) {
|
|
39
|
+
const m = one(meaning);
|
|
40
|
+
if (!m) return 'Say what the word means.';
|
|
41
|
+
if (m.length > MAX_MEANING) return `A meaning is at most ${MAX_MEANING} characters.`;
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const fileOf = (dir) => (dir ? path.join(dir, FILE) : null);
|
|
46
|
+
|
|
47
|
+
function readLines(dir) {
|
|
48
|
+
const f = fileOf(dir);
|
|
49
|
+
if (!f) return [];
|
|
50
|
+
let text = '';
|
|
51
|
+
try { text = fs.readFileSync(f, 'utf8'); } catch { return []; }
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const l of text.split('\n')) {
|
|
54
|
+
if (!l.trim()) continue;
|
|
55
|
+
try { const o = JSON.parse(l); if (o && typeof o === 'object' && typeof o.term === 'string') out.push(o); } catch { /* a torn line is skipped */ }
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function read(dir) {
|
|
61
|
+
const by = new Map();
|
|
62
|
+
for (const l of readLines(dir)) {
|
|
63
|
+
const k = keyOf(l.term);
|
|
64
|
+
if (!k) continue;
|
|
65
|
+
const m = one(l.meaning);
|
|
66
|
+
if (m) by.set(k, { term: one(l.term), meaning: m, at: l.at || null });
|
|
67
|
+
else by.delete(k);
|
|
68
|
+
}
|
|
69
|
+
return [...by.values()].sort((a, b) => a.term.localeCompare(b.term, 'en', { sensitivity: 'base' }));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function append(dir, line) {
|
|
73
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
74
|
+
fs.appendFileSync(fileOf(dir), JSON.stringify(line) + '\n');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function set(dir, term, meaning, now = Date.now()) {
|
|
78
|
+
if (!dir) return { ok: false, error: 'This product has no records folder.' };
|
|
79
|
+
const bad = checkTerm(term) || checkMeaning(meaning);
|
|
80
|
+
if (bad) return { ok: false, error: bad };
|
|
81
|
+
const t = one(term), had = read(dir);
|
|
82
|
+
if (!had.some((x) => keyOf(x.term) === keyOf(t)) && had.length >= MAX_TERMS) return { ok: false, error: `A glossary holds at most ${MAX_TERMS} words. Remove one first.` };
|
|
83
|
+
try { append(dir, { at: new Date(now).toISOString(), term: t, meaning: one(meaning) }); } catch (e) { return { ok: false, error: 'could not save the word: ' + ((e && e.message) || e) }; }
|
|
84
|
+
const terms = read(dir);
|
|
85
|
+
say(`set ${t} (${terms.length} words)`);
|
|
86
|
+
return { ok: true, term: t, terms };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function remove(dir, term, now = Date.now()) {
|
|
90
|
+
if (!dir) return { ok: false, error: 'This product has no records folder.' };
|
|
91
|
+
const bad = checkTerm(term);
|
|
92
|
+
if (bad) return { ok: false, error: bad };
|
|
93
|
+
const hit = read(dir).find((x) => keyOf(x.term) === keyOf(term));
|
|
94
|
+
if (!hit) return { ok: false, error: `${one(term)} is not in the glossary.` };
|
|
95
|
+
try { append(dir, { at: new Date(now).toISOString(), term: hit.term, meaning: '' }); } catch (e) { return { ok: false, error: 'could not remove the word: ' + ((e && e.message) || e) }; }
|
|
96
|
+
const terms = read(dir);
|
|
97
|
+
say(`removed ${hit.term} (${terms.length} words)`);
|
|
98
|
+
return { ok: true, term: hit.term, terms };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The records folder of the product checkout at `root` (scripts/signals/layout-paths.js, as lib/records-dir.js does). */
|
|
102
|
+
function dirOf(root) {
|
|
103
|
+
try { const { repoScript } = require('./repo-script.js'); return require(repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; }
|
|
104
|
+
catch { return path.join(root, 'planning', 'records'); }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function uses(lines, days = 7, now = Date.now()) {
|
|
108
|
+
const cut = now - days * 864e5;
|
|
109
|
+
return (lines || []).filter((l) => l && l.kind === 'use' && l.control === SHOW && Date.parse(l.at) >= cut && Date.parse(l.at) <= now + 864e5).length;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = { FILE, MAX_TERM, MAX_MEANING, MAX_TERMS, SHOW, TAG, checkTerm, checkMeaning, readLines, read, set, remove, dirOf, uses };
|
|
@@ -130,6 +130,9 @@ const VERBS = Object.freeze({
|
|
|
130
130
|
// Not a pm-os-absorb verb (run: null): initiative design-drift-guard added it through the same table.
|
|
131
131
|
design: Object.freeze({ module: 'design-cli.js', run: null, guide: 'cli.md',
|
|
132
132
|
help: 'pmos design drift — which pages are built from your design system and which drift from it, read from git (pmos design help)' }),
|
|
133
|
+
// Not a pm-os-absorb verb (run: null): initiative glossary-hover (bet A386) added it through the same table.
|
|
134
|
+
glossary: Object.freeze({ module: 'glossary-cli.js', run: null, guide: 'cli.md',
|
|
135
|
+
help: 'pmos glossary [list|set|remove|uses] — the product\'s own words; every page shows a word\'s meaning on hover (pmos glossary help)' }),
|
|
133
136
|
// Not a pm-os-absorb verb (run: null): initiative page-fix-count-first (bet A462) added it through the same table.
|
|
134
137
|
pages: Object.freeze({ module: 'pages-cli.js', run: null, guide: 'cli.md',
|
|
135
138
|
help: 'pmos pages [show|check] — each page\'s fixes, reverts and restores in the last 14 days, and a feature change that adds to a page that keeps breaking (pmos pages help)' }),
|
|
@@ -51,6 +51,7 @@ const MODULES = Object.freeze([
|
|
|
51
51
|
'routes-doc-health', // console3 B2: the six document health checks, recomputed from text
|
|
52
52
|
'routes-outbox', // console3 B3: the outbox queue, hash-bound confirm (no channel connected)
|
|
53
53
|
'routes-waiting', // home-your-move-waiting: Waiting on others, derived from records, with its exit rule
|
|
54
|
+
'routes-glossary', // glossary-hover (A386): the glossary of the products a page shows (read only; pmos glossary writes it)
|
|
54
55
|
'routes-open-questions', // open-questions-register (A420): one register of every unanswered question, with owner, age and default
|
|
55
56
|
'routes-calendar-views', // console3 C2: Day/Week/Month/Quarter/Year cells, Gantt and the strategy lens (read-only)
|
|
56
57
|
'routes-events-place', // events-place (nav slice 6): every date PMOS holds, grouped Late / Today / Coming up, and the PM's fixed marks and noes (events/marks.jsonl; page-press POST)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-glossary.js — the glossary of the products a page shows (bet A386, initiative glossary-hover; lib/glossary.js, pm/glossary.js).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/glossary?ws=<id>[,<id>…] → { ok, terms: [{ term, meaning, ws }] } no ws: the home product
|
|
5
|
+
*
|
|
6
|
+
* Read only: `pmos glossary set|remove` writes the same file (glossary.jsonl in each product's records folder), so a word the chat adds
|
|
7
|
+
* shows on the next page load. An unknown product is left out. Nothing is sent anywhere. */
|
|
8
|
+
const G = require('./glossary.js');
|
|
9
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
prefixes: ['/api/glossary'],
|
|
13
|
+
handle: async (req, res, url, ctx) => {
|
|
14
|
+
if (url.pathname !== '/api/glossary') return false;
|
|
15
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
16
|
+
const asked = String(url.searchParams.get('ws') || '').split(',').map((s) => s.trim()).filter(Boolean).slice(0, 20);
|
|
17
|
+
const ids = [];
|
|
18
|
+
for (const id of asked.length ? asked : [null]) {
|
|
19
|
+
let w = null;
|
|
20
|
+
try { w = ctx.getWs ? ctx.getWs(id) : null; } catch { w = null; }
|
|
21
|
+
if (!w || !w.id || (id && w.id !== id)) continue; // getWs gives the home product for an unknown id: leave it out
|
|
22
|
+
if (!ids.includes(w.id)) ids.push(w.id);
|
|
23
|
+
}
|
|
24
|
+
const terms = [];
|
|
25
|
+
for (const ws of ids) for (const t of G.read(recordsDirFor(ctx, ws))) terms.push({ term: t.term, meaning: t.meaning, ws });
|
|
26
|
+
ctx.json(res, { ok: true, terms });
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* GET /api/find?q=<words>&ws=<id>&wt=<id,id> → { ok, q, worktrees, counts, results, more, answer? } wt: the worktrees to search (none: all)
|
|
5
5
|
* answer: one sentence from the user's own files with its source (lib/search-answer.js); absent when nothing is clear
|
|
6
|
+
* GET /api/search-ask?q=<question>&ws=<id> → { ok, answer, why? } a question's answer (lib/search-ask.js): the copied sentence when there is
|
|
7
|
+
* one, else one written by a read-only PMOS session from passages of the user's files, with those files as its sources (search-answers-questions)
|
|
6
8
|
* GET /api/find/file?ws=<id>&wt=<id>&path=<p> → { ok, wt, branch, main, path, text, mtime } one file of a listed worktree, for the Viewer
|
|
7
9
|
*
|
|
8
|
-
* Read-only: nothing here writes
|
|
10
|
+
* Read-only: nothing here writes. Only /api/search-ask starts a session (the existing read-only ask kind); nothing else calls anything outside this machine. The repository is the workspace's own (ws, else the home one). */
|
|
9
11
|
const Search = require('./search-index.js');
|
|
10
12
|
const Answer = require('./search-answer.js'); // the answer first, with its source (search-answers-first)
|
|
11
13
|
|
|
@@ -15,10 +17,10 @@ function wsOf(ctx, id) {
|
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
module.exports = {
|
|
18
|
-
prefixes: ['/api/find'],
|
|
20
|
+
prefixes: ['/api/find', '/api/search-ask'],
|
|
19
21
|
handle: async (req, res, url, ctx) => {
|
|
20
22
|
const p = url.pathname;
|
|
21
|
-
if (p !== '/api/find' && p !== '/api/find/file') return false;
|
|
23
|
+
if (p !== '/api/find' && p !== '/api/find/file' && p !== '/api/search-ask') return false;
|
|
22
24
|
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
23
25
|
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
24
26
|
if (!w || !w.root) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
@@ -27,6 +29,13 @@ module.exports = {
|
|
|
27
29
|
ctx.json(res, r.ok ? r : { ok: false, error: r.error }, r.ok ? 200 : r.status || 400);
|
|
28
30
|
return true;
|
|
29
31
|
}
|
|
32
|
+
if (p === '/api/search-ask') {
|
|
33
|
+
let r;
|
|
34
|
+
try { r = await require('./search-ask.js').answer(ctx, { root: w.root, q: url.searchParams.get('q') || '' }); }
|
|
35
|
+
catch (e) { r = { ok: true, answer: null, why: 'the answer could not be made' }; }
|
|
36
|
+
ctx.json(res, { ws: w.id, q: String(url.searchParams.get('q') || '').trim(), ...r });
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
30
39
|
let notes = [];
|
|
31
40
|
try { const l = ctx.runtimeDir ? require('./notes.js').list(ctx.runtimeDir) : null; notes = l && l.ok ? l.notes : []; } catch { notes = []; }
|
|
32
41
|
const only = (url.searchParams.get('wt') || '').split(',').map((x) => x.trim()).filter(Boolean);
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* search-ask.js — Search answers questions (initiative search-answers-questions; done test planning/done-tests/search-answers-questions.md).
|
|
3
|
+
*
|
|
4
|
+
* isQuestion(q) → true when q ends with "?" or starts with a question word, and has 3 words or more PURE
|
|
5
|
+
* passages({ root, q }) → [{ n, path, title, kind, text }] READ-ONLY. The lines of the main checkout's tracked Markdown
|
|
6
|
+
* files that hold the most key words of q (git grep), best 2 per file, at most 10 in all.
|
|
7
|
+
* promptOf(q, list) · parse(text, list) the session's prompt, and its answer read back ({ text, used: [passage] } | null) PURE
|
|
8
|
+
* answer(ctx, { root, q }) → { ok: true, answer: { text, facts, made: true, source, sources } } | { ok: true, answer: null, why }
|
|
9
|
+
*
|
|
10
|
+
* Search answers first (lib/search-answer.js) answers only with a sentence that holds EVERY key word, so a "why" or "how" question is
|
|
11
|
+
* almost never answered there. This is the next step for a question: one normal PMOS session (`claude -p`, the existing read-only
|
|
12
|
+
* `briefing-ask:` ask kind, no tools, the same path as the Library's find by meaning) reads the question and the passages, and answers in
|
|
13
|
+
* at most two sentences from the passages only, naming the ones it used. The sources are those passages' files, so every answer says where
|
|
14
|
+
* it came from. The passages say nothing about it: no answer (zero is silence). Answers are kept 10 minutes. Nothing is written or sent.
|
|
15
|
+
* Tests inject ctx.askClaude(prompt, { job, key }) → Promise<string|null>. */
|
|
16
|
+
const { execFileSync } = require('child_process');
|
|
17
|
+
const crypto = require('crypto');
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const Search = require('./search-index.js');
|
|
21
|
+
const { wordsOf } = require('./library-find.js');
|
|
22
|
+
|
|
23
|
+
const QWORDS = /^\s*(why|how|what|whats|what's|who|whom|whose|when|where|which|is|are|was|were|do|does|did|can|could|should|would|will|has|have|had)\b/i;
|
|
24
|
+
/** A question: it ends with "?" or starts with a question word, and has 3 words or more. Pure. */
|
|
25
|
+
function isQuestion(q) {
|
|
26
|
+
const s = String(q || '').trim();
|
|
27
|
+
if (s.split(/\s+/).filter(Boolean).length < 3) return false;
|
|
28
|
+
return /\?\s*$/.test(s) || QWORDS.test(s);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const MAX = 10, PER_FILE = 2;
|
|
32
|
+
const clip = (s, n) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
|
|
33
|
+
const plain = (l) => String(l || '').replace(/^\s*\|\s*|\s*\|\s*$/g, '').replace(/\s*\|\s*/g, ' · ').replace(/^\s*(?:#+|[-*+>]|\d+[.)])\s*/, '').replace(/\*\*|__|`|\[([^\]]*)\]\([^)]*\)/g, (m, a) => a || '').trim();
|
|
34
|
+
const reOf = (w) => new RegExp('(^|[^a-z0-9])' + w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
|
|
35
|
+
|
|
36
|
+
function grep(root, words) {
|
|
37
|
+
const args = ['grep', '-I', '-i', '-n', '--no-color'];
|
|
38
|
+
for (const w of words) args.push('-e', w);
|
|
39
|
+
args.push('--', '*.md');
|
|
40
|
+
try { return execFileSync('git', args, { cwd: root, encoding: 'utf8', timeout: 8000, maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] }); }
|
|
41
|
+
catch (e) { return (e && typeof e.stdout === 'string') ? e.stdout : ''; } // git grep exits 1 when nothing matches
|
|
42
|
+
}
|
|
43
|
+
/** The front matter of a file ends at this line (0 when it has none). */
|
|
44
|
+
function fmEnd(root, rel, cache) {
|
|
45
|
+
if (cache.has(rel)) return cache.get(rel);
|
|
46
|
+
let end = 0;
|
|
47
|
+
try {
|
|
48
|
+
const head = fs.readFileSync(path.join(root, rel), 'utf8').slice(0, 8192).split('\n');
|
|
49
|
+
if (head[0] === '---') { const i = head.indexOf('---', 1); end = i > 0 ? i + 1 : 0; }
|
|
50
|
+
} catch { end = 0; }
|
|
51
|
+
cache.set(rel, end);
|
|
52
|
+
return end;
|
|
53
|
+
}
|
|
54
|
+
function titleOf(root, rel) {
|
|
55
|
+
try { return Search.titleOf(fs.readFileSync(path.join(root, rel), 'utf8').slice(0, 8192), path.basename(rel)); } catch { return path.basename(rel, '.md'); }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The best passages for q in the main checkout, best first. READ-ONLY. */
|
|
59
|
+
function passages({ root, q } = {}) {
|
|
60
|
+
const words = wordsOf(q);
|
|
61
|
+
if (!root || !words.length) return [];
|
|
62
|
+
const need = Math.min(2, words.length);
|
|
63
|
+
const fm = new Map(), hits = [], df = new Map(); // df: the files a word is in, so a rare word ("scarlet") weighs more than a common one ("user")
|
|
64
|
+
for (const raw of grep(root, words).split('\n')) {
|
|
65
|
+
const m = /^(.+?):(\d+):(.*)$/.exec(raw); if (!m) continue;
|
|
66
|
+
const [, rel, ln, line] = m;
|
|
67
|
+
if (Number(ln) <= fmEnd(root, rel, fm)) continue; // a frontmatter line is not a passage
|
|
68
|
+
const t = plain(line);
|
|
69
|
+
if (t.length < 20) continue;
|
|
70
|
+
const have = words.filter((w) => reOf(w).test(t));
|
|
71
|
+
if (have.length < need) continue;
|
|
72
|
+
hits.push({ rel, t, have });
|
|
73
|
+
for (const w of have) { let s = df.get(w); if (!s) { s = new Set(); df.set(w, s); } s.add(rel); }
|
|
74
|
+
}
|
|
75
|
+
const nFiles = new Set(hits.map((h) => h.rel)).size || 1;
|
|
76
|
+
const weight = (w) => 1 + Math.log((nFiles + 1) / ((df.get(w) || new Set()).size + 0.5));
|
|
77
|
+
const byFile = new Map();
|
|
78
|
+
for (const h of hits) {
|
|
79
|
+
const score = h.have.reduce((a, w) => a + weight(w), 0) * 100 - Math.min(h.t.length, 400) / 10;
|
|
80
|
+
let f = byFile.get(h.rel); if (!f) { f = { rel: h.rel, lines: [], best: 0 }; byFile.set(h.rel, f); }
|
|
81
|
+
f.lines.push({ t: h.t, score }); f.best = Math.max(f.best, score);
|
|
82
|
+
}
|
|
83
|
+
const files = [...byFile.values()].sort((a, b) => (b.best - a.best) || a.rel.localeCompare(b.rel));
|
|
84
|
+
const out = [];
|
|
85
|
+
for (const f of files) {
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
for (const l of f.lines.sort((a, b) => b.score - a.score)) {
|
|
88
|
+
if (out.length >= MAX || seen.size >= PER_FILE) break;
|
|
89
|
+
const text = clip(l.t, 320); if (seen.has(text)) continue;
|
|
90
|
+
seen.add(text);
|
|
91
|
+
out.push({ n: out.length + 1, path: f.rel, title: titleOf(root, f.rel), kind: Search.kindOf(f.rel), text });
|
|
92
|
+
}
|
|
93
|
+
if (out.length >= MAX) break;
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function promptOf(q, list) {
|
|
99
|
+
return [
|
|
100
|
+
'You answer a product manager\'s question from passages of their own files. Do not use any tool. Answer with JSON only.',
|
|
101
|
+
`The question: "${clip(q, 300)}"`,
|
|
102
|
+
'The passages, each with the file it comes from:',
|
|
103
|
+
list.map((p) => `${p.n}. [${clip(p.title, 100)}] ${p.text}`).join('\n'),
|
|
104
|
+
'Answer the question in one or two short, plain sentences, using ONLY what the passages say. Do not guess and do not add facts.',
|
|
105
|
+
'Name the numbers of the passages you used. If the passages do not answer the question, answer null.',
|
|
106
|
+
'Answer: {"answer":"<one or two sentences>","used":[<passage numbers>]} or {"answer":null}',
|
|
107
|
+
].join('\n\n');
|
|
108
|
+
}
|
|
109
|
+
/** The session's answer read back: { text, used: [passage] } with only passages of the list, or null. Pure. */
|
|
110
|
+
function parse(text, list) {
|
|
111
|
+
const t = String(text || '');
|
|
112
|
+
const at = t.indexOf('{'), end = t.lastIndexOf('}');
|
|
113
|
+
if (at < 0 || end < at) return null;
|
|
114
|
+
let o; try { o = JSON.parse(t.slice(at, end + 1)); } catch { return null; }
|
|
115
|
+
const a = o && typeof o.answer === 'string' ? o.answer.replace(/\s+/g, ' ').trim() : '';
|
|
116
|
+
if (!a) return null;
|
|
117
|
+
const used = [];
|
|
118
|
+
for (const k of Array.isArray(o.used) ? o.used : []) { const p = list.find((x) => x.n === Number(k)); if (p && !used.includes(p)) used.push(p); }
|
|
119
|
+
if (!used.length) return null; // an answer that names no passage has no source: it is not shown
|
|
120
|
+
return { text: clip(a, 400), used };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* ── the session ── */
|
|
124
|
+
const MODEL = 'claude-sonnet-5-5';
|
|
125
|
+
const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read' }]);
|
|
126
|
+
const TIMEOUT_MS = 60000;
|
|
127
|
+
const KEEP_MS = 10 * 60000;
|
|
128
|
+
const kept = new Map(); // key → { at, value }
|
|
129
|
+
|
|
130
|
+
function viaSession(ctx, prompt, key) {
|
|
131
|
+
if (typeof ctx.askClaude === 'function') return Promise.resolve(ctx.askClaude(prompt, { job: 'search-ask', key })).catch(() => null);
|
|
132
|
+
const headless = require('./headless.js');
|
|
133
|
+
const origin = 'briefing-ask:search-ask:' + key;
|
|
134
|
+
if (typeof ctx.spawnSession !== 'function' || headless.kindFor({ agent: 'claude', origin }) !== 'ask') return Promise.resolve(null);
|
|
135
|
+
return new Promise((resolve) => {
|
|
136
|
+
let settled = false; const done = (v) => { if (settled) return; settled = true; clearTimeout(t); resolve(v); };
|
|
137
|
+
const t = setTimeout(() => done(null), TIMEOUT_MS);
|
|
138
|
+
let s = null;
|
|
139
|
+
try {
|
|
140
|
+
s = ctx.spawnSession({ name: 'search: answer a question', agent: 'claude', origin, initialInput: prompt,
|
|
141
|
+
modelAsk: { explicit: { model: MODEL, effort: 'low' } }, launchFlags: LEAN.map((f) => ({ ...f })),
|
|
142
|
+
onDone: (d) => { const r = d && d.result; done(r && r.ok && !r.isError ? String(r.text || '') : null); } });
|
|
143
|
+
} catch { s = null; }
|
|
144
|
+
if (!s || s.state === 'exited') done(null);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const log = (given) => { try { console.log(given ? '[search-ask] given' : '[search-ask] none'); } catch { /* no console */ } };
|
|
148
|
+
const none = (why) => { log(false); return { ok: true, answer: null, why }; };
|
|
149
|
+
|
|
150
|
+
/** The answer to a question: the copied sentence when there is one (no session), else one written from the passages, with its sources. */
|
|
151
|
+
async function answer(ctx, { root, q } = {}) {
|
|
152
|
+
q = String(q || '').slice(0, 300).trim();
|
|
153
|
+
if (!isQuestion(q)) return none('not a question');
|
|
154
|
+
let copied = null;
|
|
155
|
+
try { const A = require('./search-answer.js'); copied = A.find({ root, q }).answer || null; } catch { copied = null; }
|
|
156
|
+
if (copied) { log(true); return { ok: true, answer: copied }; }
|
|
157
|
+
const list = passages({ root, q });
|
|
158
|
+
if (!list.length) return none('nothing in your files holds these words');
|
|
159
|
+
const key = crypto.createHash('sha1').update(root + '\n' + q + '\n' + list.map((p) => p.path + p.text).join('\n')).digest('hex').slice(0, 12);
|
|
160
|
+
const k = kept.get(key);
|
|
161
|
+
if (k && Date.now() - k.at < KEEP_MS) { log(!!k.value.answer); return k.value; }
|
|
162
|
+
const text = await viaSession(ctx || {}, promptOf(q, list), key);
|
|
163
|
+
if (text == null) return none('PMOS could not start a session to answer');
|
|
164
|
+
const p = parse(text, list);
|
|
165
|
+
const value = p ? { ok: true, answer: { text: p.text, facts: [], made: true, source: srcOf(p.used[0]), sources: dedupe(p.used).map(srcOf) } } : { ok: true, answer: null, why: 'your files do not answer this' };
|
|
166
|
+
kept.set(key, { at: Date.now(), value });
|
|
167
|
+
if (kept.size > 50) kept.delete(kept.keys().next().value);
|
|
168
|
+
log(!!value.answer);
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
const srcOf = (p) => ({ kind: p.kind, title: p.title, path: p.path, wt: 'main', main: true });
|
|
172
|
+
const dedupe = (used) => { const seen = new Set(); return used.filter((p) => !seen.has(p.path) && seen.add(p.path)).slice(0, 3); };
|
|
173
|
+
|
|
174
|
+
module.exports = { isQuestion, passages, promptOf, parse, answer, _kept: kept };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.740.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.740.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -556,3 +556,9 @@ body.pm-focus.cz-railon { --cz-railx: var(--space-16); }
|
|
|
556
556
|
body.pm-focus .cz-pop-card { inset: 0; border-radius: 0; }
|
|
557
557
|
.pm-focus-bar { position: fixed; top: var(--space-8); right: var(--space-8); z-index: 1000; }
|
|
558
558
|
.pm-focus-bar .pm-focus-leave { background: var(--card); color: var(--ink); box-shadow: var(--lift); }
|
|
559
|
+
|
|
560
|
+
/* ── the product glossary (pm/glossary.js, bet A386): its words carry a faint dotted underline (a CSS highlight, the page's markup is
|
|
561
|
+
* untouched), and a hover or a long press shows a small Komorebi card with the word and its meaning. Tokens only. ── */
|
|
562
|
+
::highlight(pm-term) { text-decoration: underline dotted; text-underline-offset: var(--space-4); } /* the text's own colour: --muted means another thing inside .c3 */
|
|
563
|
+
.gl-tip.pm-ds { position: fixed; z-index: 90; max-width: min(calc(var(--space-64) * 5), calc(100vw - var(--space-16))); background: var(--card); color: var(--ink); border-radius: var(--radius-md); box-shadow: var(--lift); padding: var(--space-8) var(--space-12); font-size: var(--fs-meta); line-height: var(--lh-meta); left: var(--fr-gl-x, 0); top: var(--fr-gl-y, 0); pointer-events: auto; }
|
|
564
|
+
.gl-tip.pm-ds .gl-m { margin: var(--space-4) 0 0; }
|
|
@@ -46,6 +46,7 @@ import './draft-keep.js'; // forms-keep-drafts: every text box on every page k
|
|
|
46
46
|
import { pmPost } from './http.js'; // Adler (batch 16 item 2): every toast carries his S face; Settings > Adler is read once
|
|
47
47
|
import { startUseLog } from './use-log.js'; // bet A466: every page mounts the menu, so the menu starts the local use log (this computer only)
|
|
48
48
|
import { startActionKeys } from './action-keys.js'; // bet A477: y o s p z act on the item under the pointer, ? lists the keys
|
|
49
|
+
import { startGlossary } from './glossary.js'; // bet A386: a product's own words show their meaning on hover (a long press on a phone)
|
|
49
50
|
import { startFocusMode } from './focus-mode.js'; // bet A335: f shows only the item under the pointer and its chat; f again puts the page back
|
|
50
51
|
|
|
51
52
|
/* The six places (slice 1). A place shows once it has an href: Events, Library and Routine get theirs when their slice ships. Until then
|
|
@@ -206,6 +207,7 @@ export function mountNav(here, doc = document, opts = {}) {
|
|
|
206
207
|
startUseLog(doc);
|
|
207
208
|
startActionKeys(doc);
|
|
208
209
|
startFocusMode(doc);
|
|
210
|
+
startGlossary(doc);
|
|
209
211
|
const fab = w.querySelector('#czFab'), menu = w.querySelector('#czMenu'), scrim = w.querySelector('#czScrim');
|
|
210
212
|
const draw = () => {
|
|
211
213
|
N.rail = railOn();
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* Esc closes. On a phone it is the whole screen.
|
|
9
9
|
* Above everything, when the words clearly point to one thing, one answer: a sentence copied from the user's own files, with its source
|
|
10
10
|
* and the check date when it is an initiative (search-answers-first, lib/search-answer.js). ↵ on it opens the source. No answer: no row.
|
|
11
|
+
* A question with no such sentence (search-answers-questions): the first row says "Finding an answer in your work…" while
|
|
12
|
+
* GET /api/search-ask runs (one read-only PMOS session answers from passages of the user's files, lib/search-ask.js), then shows that
|
|
13
|
+
* answer and the files it came from. "Ask PMOS" stays the next row, to go deeper. No answer: the row goes away.
|
|
11
14
|
* openSearch({ go?, q?, scope? }) go: the page's own opener ({ ini } | { ses } | { doc }), used before a page change
|
|
12
15
|
* scope: the page Search opens from (UI grill U2: one search; the Board's and Intelligence's own find boxes are gone). { name, hits(q) }
|
|
13
16
|
* where hits returns [{ label, rows: [{ id?, title, sub?, tag?, icon?, open() }] }]: the page's own groups, drawn first ("On this Board ·
|
|
@@ -25,8 +28,11 @@ import { adler } from './cozy-adler.js'; // session names A: the PM's name win
|
|
|
25
28
|
|
|
26
29
|
const PHONE = 760;
|
|
27
30
|
const isPhone = () => innerWidth <= PHONE;
|
|
28
|
-
const S = { el: null, q: '', kind: 'all', scope: null, at: 0, rows: [], res: null, busy: false, err: '', wt: null, back: null, go: null, seq: 0, boards: null, sessions: null, t: 0 };
|
|
31
|
+
const S = { ask: null, el: null, q: '', kind: 'all', scope: null, at: 0, rows: [], res: null, busy: false, err: '', wt: null, back: null, go: null, seq: 0, boards: null, sessions: null, t: 0 };
|
|
29
32
|
const KIND_ICON = { initiative: ICON.flag, document: ICON.doc, slides: ICON.slides, report: ICON.report, artifact: ICON.design, file: ICON.file, meeting: ICON.meet, session: ICON.session };
|
|
33
|
+
/** A question: it ends with "?" or starts with a question word, and has 3 words or more (the same rule as lib/search-ask.js isQuestion). */
|
|
34
|
+
const QW = /^\s*(why|how|what|whats|what's|who|whom|whose|when|where|which|is|are|was|were|do|does|did|can|could|should|would|will|has|have|had)\b/i;
|
|
35
|
+
const isQuestion = (q) => String(q || '').trim().split(/\s+/).filter(Boolean).length >= 3 && (/\?\s*$/.test(String(q).trim()) || QW.test(q));
|
|
30
36
|
async function getj(p) { try { const r = await fetch(p, { credentials: 'same-origin' }); const j = await r.json().catch(() => null); return j || { ok: false, error: 'the server did not answer' }; } catch { return { ok: false, error: 'the server did not answer' }; } }
|
|
31
37
|
|
|
32
38
|
function mount() {
|
|
@@ -92,6 +98,13 @@ async function run() {
|
|
|
92
98
|
S.busy = false;
|
|
93
99
|
if (!r.ok) { S.err = r.error || 'the server did not answer'; draw(); return; }
|
|
94
100
|
S.res = r; draw();
|
|
101
|
+
// search-answers-questions: a question the copied sentence did not answer gets an answer written from the user's own files
|
|
102
|
+
if (!r.answer && isQuestion(q) && !(S.ask && S.ask.q === q)) {
|
|
103
|
+
S.ask = { q, busy: true, answer: null }; draw();
|
|
104
|
+
const a = await getj('/api/search-ask?q=' + encodeURIComponent(q) + wsQ('&'));
|
|
105
|
+
if (!S.ask || S.ask.q !== q) return;
|
|
106
|
+
S.ask = { q, busy: false, answer: a && a.ok && a.answer && a.answer.source ? a.answer : null }; draw();
|
|
107
|
+
}
|
|
95
108
|
}
|
|
96
109
|
|
|
97
110
|
/** Every row the palette shows for the query: the search's results, the board's initiatives and the sessions that match, each once. */
|
|
@@ -145,8 +158,11 @@ function drawList() {
|
|
|
145
158
|
const groups = own.concat(searchGroups(rows, { phone: isPhone() }));
|
|
146
159
|
const ask = q.length >= 2 ? { kind: 'ask', title: q } : null;
|
|
147
160
|
// search-answers-first: the answer, with its source, is the first row; only for the words it answered and on All
|
|
148
|
-
const
|
|
161
|
+
const A0 = S.res && S.res.answer && S.kind === 'all' && q.length >= 2 && String(S.res.q || '').trim() === q ? S.res.answer : null;
|
|
162
|
+
const made = !A0 && S.kind === 'all' && S.ask && S.ask.q === q ? S.ask : null; // search-answers-questions: the written answer, or its wait
|
|
163
|
+
const A = A0 || (made && made.answer);
|
|
149
164
|
const ansRow = A && A.source ? { kind: 'answer', answer: A } : null;
|
|
165
|
+
const waiting = !ansRow && made && made.busy;
|
|
150
166
|
// chief-of-staff C5: the one chat is the first row of Search; a page's own find (U2 scope) keeps its own hits first, then the chat
|
|
151
167
|
const ownRows = own.flatMap((g) => g.rows);
|
|
152
168
|
S.rows = (ansRow ? [ansRow] : []).concat(ownRows, ask ? [ask] : [], groups.slice(own.length).flatMap((g) => g.rows));
|
|
@@ -154,6 +170,7 @@ function drawList() {
|
|
|
154
170
|
let h = '', i = 0;
|
|
155
171
|
const askHtml = () => `<button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}">${svg(ICON.chat, 18)}<span class="ev-t">Ask PMOS: <b>“${esc(q)}”</b></span><span class="ev-k">${onHome() ? 'In the chat' : 'Opens the chat here'}</span></button>`;
|
|
156
172
|
if (ansRow && !S.err) { h += answerHtml(ansRow.answer, i); i++; }
|
|
173
|
+
else if (waiting && !S.err) h += `<p class="ev-sp-empty" role="status">Finding an answer in your work…</p>`;
|
|
157
174
|
// the page's own groups first (UI grill U2): what Search itself could not read is said after them
|
|
158
175
|
own.forEach((g) => { h += `<p class="ev-mlbl">${esc(g.label)}</p>` + g.rows.map((r) => rowHtml(r, i++)).join(''); });
|
|
159
176
|
if (ask) { h += askHtml(); i++; }
|
|
@@ -182,7 +199,9 @@ const dayOf = (iso) => { const d = new Date(String(iso) + 'T00:00:00'); return i
|
|
|
182
199
|
function answerHtml(a, i) {
|
|
183
200
|
const src = a.source, kind = { initiative: 'initiative', document: 'document', report: 'report', slides: 'slides' }[src.kind] || 'file';
|
|
184
201
|
const facts = (a.facts || []).filter((f) => f.key === 'check' && dayOf(f.date)).map((f) => 'Check ' + dayOf(f.date));
|
|
185
|
-
const from =
|
|
202
|
+
const from = a.made && Array.isArray(a.sources) && a.sources.length
|
|
203
|
+
? 'From ' + a.sources.map((x) => x.title || x.path).join(', ') // written from these files (search-answers-questions)
|
|
204
|
+
: 'From ' + (src.title || src.path) + ' (' + kind + (src.main === false ? ', draft in ' + (src.branch || src.wt) : '') + ')';
|
|
186
205
|
// the plain wrapper keeps the row as tall as its lines: the list is a flex column and would squeeze the button to its min-height
|
|
187
206
|
return `<div role="none"><button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}" aria-label="${esc(a.text + ' ' + facts.concat(from).join(' · '))}">${svg(KIND_ICON[src.kind] || ICON.doc, 18)}<span><b>${esc(a.text)}</b><br><span class="ev-small ev-mut">${esc(facts.concat(from).join(' · '))}</span></span></button></div>`;
|
|
188
207
|
}
|
|
@@ -116,7 +116,7 @@ button.td-ev:focus-visible { outline: none; box-shadow: var(--glow); }
|
|
|
116
116
|
.tdp-rec i { width: 9px; height: 9px; border-radius: 50%; background: var(--cz-dot-red); }
|
|
117
117
|
/* Today's log */
|
|
118
118
|
.tdp-lh { display: flex; align-items: center; justify-content: space-between; gap: var(--space-12); padding: 18px 0 10px; border-bottom: 1px solid var(--cz-hair); }
|
|
119
|
-
.tdp-lh h2 { font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: .08em; text-transform: uppercase; color: var(--cz-ink2); line-height: var(--lh-label); }
|
|
119
|
+
.tdp-lh h2, .tdp-gh { font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: .08em; text-transform: uppercase; color: var(--cz-ink2); line-height: var(--lh-label); }
|
|
120
120
|
.tdp-f { position: relative; display: inline-flex; align-items: center; gap: 2px; color: var(--cz-ink3); }
|
|
121
121
|
.tdp-f select { appearance: none; -webkit-appearance: none; border: 0; background: none; font: inherit; font-size: var(--fs-row); color: var(--cz-ink3); padding: 6px 18px 6px 6px; min-height: 36px; text-align: right; }
|
|
122
122
|
.tdp-f svg { position: absolute; right: 0; pointer-events: none; }
|
|
@@ -176,8 +176,8 @@ button.td-ev:focus-visible { outline: none; box-shadow: var(--glow); }
|
|
|
176
176
|
}
|
|
177
177
|
/* open-questions-today (A420, board QuestionsA): the Decide tab's two groups; the line under a row says what PMOS does if nobody answers */
|
|
178
178
|
.oq-r .oq-u { display: flex; align-items: flex-start; gap: var(--space-4); }
|
|
179
|
-
.oq-r .oq-u .pm-ic { flex: none; margin-top:
|
|
179
|
+
.oq-r .oq-u .pm-ic { flex: none; margin-top: calc(var(--space-4) / 2); }
|
|
180
180
|
@media (max-width: 760px) {
|
|
181
|
-
.tdp-gh { padding:
|
|
181
|
+
.tdp-gh { padding: var(--space-16) 0 var(--space-8); }
|
|
182
182
|
.tdp-m.oq-u.d { color: var(--cz-blueink); }
|
|
183
183
|
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/* pm/glossary.js — a product's own words explain themselves on every page (bet A386, initiative glossary-hover; the store is
|
|
2
|
+
* lib/glossary.js, written by `pmos glossary`, read through GET /api/glossary).
|
|
3
|
+
*
|
|
4
|
+
* The words of the products the page shows (the product pick, pm/cozy-pick.js) get a faint dotted underline. A hover over one, or a long
|
|
5
|
+
* press on a phone, shows a small card: the word, what it means and, when more than one product is shown, whose word it is.
|
|
6
|
+
* The underline is the browser's CSS highlight (::highlight(pm-term) in cozy-ev.css), so the page's own markup is never changed; a browser
|
|
7
|
+
* without CSS highlights shows no underline and the hover still works. Text in inputs, editable text, code, terminals, the menu and the
|
|
8
|
+
* card itself is left alone. Each meaning shown is noted once on this computer (pm/use-log.js noteUse `glossary-show`, no text).
|
|
9
|
+
*
|
|
10
|
+
* startGlossary(doc) called once by the menu (pm/cozy-nav.js mountNav), which every page mounts; a second call does nothing,
|
|
11
|
+
* and so does a call in a browser a script drives (navigator.webdriver)
|
|
12
|
+
* matcherOf(terms) PURE: the matcher for [{ term, meaning, ws }] → { find(text), entries(key) } or null when there are none
|
|
13
|
+
* findTerms(text, terms) PURE: [{ start, end, text, key }] whole words; a term with a capital letter matches that case only,
|
|
14
|
+
* an all-lowercase term any case; the longer term wins where two overlap
|
|
15
|
+
* tipHtml(entries, o) PURE: the card's markup; o.names: show each product's name, o.nameOf(ws) the name
|
|
16
|
+
* skipped(el) true when the text under `el` is left alone (SKIP) */
|
|
17
|
+
import { pmGet } from './http.js';
|
|
18
|
+
import { readPick } from './cozy-pick.js';
|
|
19
|
+
import { productName } from './scope-chip.js';
|
|
20
|
+
import { noteUse } from './use-log.js';
|
|
21
|
+
|
|
22
|
+
export const SKIP = 'input, textarea, select, code, pre, script, style, noscript, svg, [contenteditable=""], [contenteditable="true"], [role="textbox"], .xterm, #czNav, .gl-tip';
|
|
23
|
+
export const HL = 'pm-term';
|
|
24
|
+
export const SHOW = 'glossary-show';
|
|
25
|
+
const MAX_NODES = 5000;
|
|
26
|
+
const MAX_HITS = 800;
|
|
27
|
+
const HOVER_MS = 250;
|
|
28
|
+
const PRESS_MS = 450;
|
|
29
|
+
const AGAIN_MS = 10000; // the same word shown again within this time is not counted again
|
|
30
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
|
31
|
+
const reEsc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
32
|
+
const keyOf = (t) => String(t || '').replace(/\s+/g, ' ').trim().toLowerCase();
|
|
33
|
+
const say = (s) => { try { console.info('[glossary] ' + s); } catch { /* no console */ } };
|
|
34
|
+
|
|
35
|
+
/** PURE. The matcher for a list of words, or null when there are none. */
|
|
36
|
+
export function matcherOf(terms) {
|
|
37
|
+
const by = new Map();
|
|
38
|
+
for (const t of terms || []) {
|
|
39
|
+
const k = keyOf(t && t.term);
|
|
40
|
+
if (!k || !String((t && t.meaning) || '').trim()) continue;
|
|
41
|
+
if (!by.has(k)) by.set(k, []);
|
|
42
|
+
by.get(k).push(t);
|
|
43
|
+
}
|
|
44
|
+
if (!by.size) return null;
|
|
45
|
+
const cs = new Set(), ci = new Set();
|
|
46
|
+
for (const list of by.values()) for (const t of list) {
|
|
47
|
+
const w = String(t.term).replace(/\s+/g, ' ').trim();
|
|
48
|
+
(/\p{Lu}/u.test(w) ? cs : ci).add(w);
|
|
49
|
+
}
|
|
50
|
+
const alt = (set) => [...set].sort((a, b) => b.length - a.length).map((w) => reEsc(w).replace(/ /g, '\\s+')).join('|');
|
|
51
|
+
const wrap = (set, flags) => (set.size ? new RegExp('(?<![\\p{L}\\p{N}])(?:' + alt(set) + ')(?![\\p{L}\\p{N}])', flags) : null);
|
|
52
|
+
const res = [wrap(cs, 'gu'), wrap(ci, 'giu')].filter(Boolean);
|
|
53
|
+
const find = (text) => {
|
|
54
|
+
const s = String(text || '');
|
|
55
|
+
if (!s.trim()) return [];
|
|
56
|
+
const hits = [];
|
|
57
|
+
for (const re of res) { re.lastIndex = 0; let m; while ((m = re.exec(s))) { hits.push({ start: m.index, end: m.index + m[0].length, text: m[0], key: keyOf(m[0]) }); if (!m[0].length) re.lastIndex++; } }
|
|
58
|
+
hits.sort((a, b) => a.start - b.start || (b.end - b.start) - (a.end - a.start));
|
|
59
|
+
const out = [];
|
|
60
|
+
for (const h of hits) {
|
|
61
|
+
const last = out[out.length - 1];
|
|
62
|
+
if (last && h.start < last.end) { if (h.end - h.start > last.end - last.start) out[out.length - 1] = h; continue; }
|
|
63
|
+
out.push(h);
|
|
64
|
+
}
|
|
65
|
+
return out.filter((h) => by.has(h.key));
|
|
66
|
+
};
|
|
67
|
+
return { find, entries: (k) => by.get(keyOf(k)) || [], size: by.size };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** PURE. The words found in `text`. */
|
|
71
|
+
export function findTerms(text, terms) { const m = matcherOf(terms); return m ? m.find(text) : []; }
|
|
72
|
+
|
|
73
|
+
/** PURE. The card for one word: its meaning per product (one line each when two products use the same word). */
|
|
74
|
+
export function tipHtml(entries, o = {}) {
|
|
75
|
+
const list = (entries || []).filter((e) => e && e.term && e.meaning);
|
|
76
|
+
if (!list.length) return '';
|
|
77
|
+
const nameOf = o.nameOf || ((ws) => ws);
|
|
78
|
+
const rows = list.map((e) => `<p class="gl-m">${o.names && e.ws ? `<span class="pm-meta">${esc(nameOf(e.ws))}</span> ` : ''}${esc(e.meaning)}</p>`).join('');
|
|
79
|
+
return `<div class="pm-ds gl-tip" role="tooltip" id="glTip"><b class="pm-h-sm">${esc(list[0].term)}</b>${rows}</div>`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const skipped = (el) => !!(el && el.closest && el.closest(SKIP));
|
|
83
|
+
|
|
84
|
+
let started = false;
|
|
85
|
+
const S = { doc: null, M: null, names: false, nodes: new Map(), ranges: [], tip: null, at: null, hoverT: 0, hideT: 0, pressT: 0, press: null, eat: false, shown: new Map(), scanT: 0, mo: null };
|
|
86
|
+
|
|
87
|
+
function botNow() { try { return !!(typeof navigator !== 'undefined' && navigator.webdriver); } catch { return false; } }
|
|
88
|
+
|
|
89
|
+
/** Find the words in the page's text and underline them. */
|
|
90
|
+
function scan() {
|
|
91
|
+
const doc = S.doc;
|
|
92
|
+
S.nodes = new Map(); S.ranges = [];
|
|
93
|
+
if (!S.M || !doc.body) { paint(); return; }
|
|
94
|
+
const win = doc.defaultView;
|
|
95
|
+
const walker = doc.createTreeWalker(doc.body, 4 /* SHOW_TEXT */, { acceptNode: (n) => (n.nodeValue && n.nodeValue.trim() && n.parentElement && !skipped(n.parentElement) ? 1 : 2) });
|
|
96
|
+
let n, seen = 0, hits = 0;
|
|
97
|
+
while ((n = walker.nextNode()) && seen++ < MAX_NODES && hits < MAX_HITS) {
|
|
98
|
+
const found = S.M.find(n.nodeValue);
|
|
99
|
+
if (!found.length) continue;
|
|
100
|
+
S.nodes.set(n, found);
|
|
101
|
+
for (const h of found) {
|
|
102
|
+
if (hits++ >= MAX_HITS) break;
|
|
103
|
+
try { const r = doc.createRange(); r.setStart(n, h.start); r.setEnd(n, h.end); S.ranges.push({ r, key: h.key }); } catch { /* the node changed */ }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
paint(win);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function paint(win = S.doc && S.doc.defaultView) {
|
|
110
|
+
try {
|
|
111
|
+
if (!win || !win.CSS || !win.CSS.highlights || typeof win.Highlight !== 'function') return;
|
|
112
|
+
if (S.ranges.length) win.CSS.highlights.set(HL, new win.Highlight(...S.ranges.map((x) => x.r)));
|
|
113
|
+
else win.CSS.highlights.delete(HL);
|
|
114
|
+
} catch { /* no highlights: the hover still works */ }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const inRect = (x, y, b) => x >= b.left - 1 && x <= b.right + 1 && y >= b.top - 1 && y <= b.bottom + 1;
|
|
118
|
+
|
|
119
|
+
/** The word under a point, or null. */
|
|
120
|
+
function hitAt(x, y) {
|
|
121
|
+
const doc = S.doc;
|
|
122
|
+
let node = null, off = -1;
|
|
123
|
+
try {
|
|
124
|
+
if (doc.caretPositionFromPoint) { const p = doc.caretPositionFromPoint(x, y); if (p) { node = p.offsetNode; off = p.offset; } }
|
|
125
|
+
else if (doc.caretRangeFromPoint) { const r = doc.caretRangeFromPoint(x, y); if (r) { node = r.startContainer; off = r.startOffset; } }
|
|
126
|
+
} catch { node = null; }
|
|
127
|
+
const tryRange = (r, key) => { for (const b of r.getClientRects()) if (inRect(x, y, b)) return { r, key, box: r.getBoundingClientRect() }; return null; };
|
|
128
|
+
if (node && S.nodes.has(node)) {
|
|
129
|
+
for (const h of S.nodes.get(node)) {
|
|
130
|
+
if (off < h.start || off > h.end) continue;
|
|
131
|
+
const x2 = S.ranges.find((q) => q.r.startContainer === node && q.r.startOffset === h.start);
|
|
132
|
+
const got = x2 && tryRange(x2.r, x2.key);
|
|
133
|
+
if (got) return got;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
if (node) return null;
|
|
138
|
+
for (const q of S.ranges) { const got = tryRange(q.r, q.key); if (got) return got; } // no caret API: look through the words
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function show(hit) {
|
|
143
|
+
const doc = S.doc;
|
|
144
|
+
const html = tipHtml(S.M.entries(hit.key), { names: S.names, nameOf: (ws) => productName(ws, ws) });
|
|
145
|
+
if (!html) return;
|
|
146
|
+
hide();
|
|
147
|
+
const wrap = doc.createElement('div');
|
|
148
|
+
wrap.innerHTML = html;
|
|
149
|
+
const tip = wrap.firstElementChild;
|
|
150
|
+
doc.body.appendChild(tip);
|
|
151
|
+
const win = doc.defaultView, vw = win.innerWidth || 1280, vh = win.innerHeight || 800;
|
|
152
|
+
const tb = tip.getBoundingClientRect(), b = hit.box;
|
|
153
|
+
const left = Math.max(8, Math.min(b.left, vw - tb.width - 8));
|
|
154
|
+
const below = b.bottom + 6 + tb.height <= vh;
|
|
155
|
+
tip.style.setProperty('--fr-gl-x', left + 'px'); // run-time geometry only; the card's look is in cozy-ev.css
|
|
156
|
+
tip.style.setProperty('--fr-gl-y', (below ? b.bottom + 6 : Math.max(8, b.top - tb.height - 6)) + 'px');
|
|
157
|
+
S.tip = tip; S.at = hit.key;
|
|
158
|
+
const last = S.shown.get(hit.key) || 0, now = Date.now();
|
|
159
|
+
if (now - last > AGAIN_MS) { S.shown.set(hit.key, now); noteUse(SHOW); say('shown'); }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function hide() { if (S.tip) { S.tip.remove(); S.tip = null; S.at = null; } }
|
|
163
|
+
|
|
164
|
+
let moveQ = null, moveF = 0;
|
|
165
|
+
function onMove(e) {
|
|
166
|
+
if (e.pointerType && e.pointerType !== 'mouse') return;
|
|
167
|
+
moveQ = { clientX: e.clientX, clientY: e.clientY, target: e.target };
|
|
168
|
+
if (moveF) return;
|
|
169
|
+
const w = S.doc.defaultView, raf = w && w.requestAnimationFrame ? (f) => w.requestAnimationFrame(f) : (f) => setTimeout(f, 16);
|
|
170
|
+
moveF = raf(() => { moveF = 0; const q = moveQ; moveQ = null; if (q) onPoint(q); });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function onPoint(e) {
|
|
174
|
+
if (S.tip && e.target && e.target.closest && e.target.closest('.gl-tip')) { clearTimeout(S.hideT); return; }
|
|
175
|
+
const hit = S.M ? hitAt(e.clientX, e.clientY) : null;
|
|
176
|
+
clearTimeout(S.hoverT);
|
|
177
|
+
if (hit) {
|
|
178
|
+
clearTimeout(S.hideT);
|
|
179
|
+
if (S.at === hit.key && S.tip) return;
|
|
180
|
+
S.hoverT = setTimeout(() => show(hit), HOVER_MS);
|
|
181
|
+
} else if (S.tip) {
|
|
182
|
+
clearTimeout(S.hideT);
|
|
183
|
+
S.hideT = setTimeout(hide, 150);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function onTouchStart(e) {
|
|
188
|
+
if (S.tip && !(e.target && e.target.closest && e.target.closest('.gl-tip'))) hide();
|
|
189
|
+
clearTimeout(S.pressT);
|
|
190
|
+
if (!S.M || !e.touches || e.touches.length !== 1) return;
|
|
191
|
+
const t = e.touches[0];
|
|
192
|
+
S.press = { x: t.clientX, y: t.clientY };
|
|
193
|
+
S.pressT = setTimeout(() => {
|
|
194
|
+
const hit = hitAt(S.press.x, S.press.y);
|
|
195
|
+
if (hit) { S.eat = true; show(hit); }
|
|
196
|
+
}, PRESS_MS);
|
|
197
|
+
}
|
|
198
|
+
function onTouchMove(e) {
|
|
199
|
+
const t = e.touches && e.touches[0];
|
|
200
|
+
if (S.press && t && Math.hypot(t.clientX - S.press.x, t.clientY - S.press.y) > 10) clearTimeout(S.pressT);
|
|
201
|
+
}
|
|
202
|
+
function onTouchEnd() { clearTimeout(S.pressT); }
|
|
203
|
+
// the press that showed a meaning does not also open the row under it, nor the phone's own menu
|
|
204
|
+
function eatClick(e) { if (S.eat) { S.eat = false; e.preventDefault(); e.stopPropagation(); } }
|
|
205
|
+
function eatMenu(e) { if (S.eat) e.preventDefault(); }
|
|
206
|
+
|
|
207
|
+
async function load() {
|
|
208
|
+
let ws = [];
|
|
209
|
+
try { const P = await readPick(); ws = P ? P.products.filter((p) => p.on).map((p) => p.ws) : []; } catch { ws = []; }
|
|
210
|
+
const r = await Promise.resolve(pmGet('/api/glossary' + (ws.length ? '?ws=' + encodeURIComponent(ws.join(',')) : ''))).catch(() => null);
|
|
211
|
+
const terms = r && r.ok && Array.isArray(r.terms) ? r.terms : [];
|
|
212
|
+
S.M = matcherOf(terms);
|
|
213
|
+
S.names = new Set(terms.map((t) => t.ws)).size > 1;
|
|
214
|
+
scan();
|
|
215
|
+
watch();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function watch() {
|
|
219
|
+
const doc = S.doc, win = doc.defaultView;
|
|
220
|
+
if (S.mo || !S.M || !win || typeof win.MutationObserver !== 'function') return;
|
|
221
|
+
S.mo = new win.MutationObserver((list) => {
|
|
222
|
+
const ours = (n) => !!(n && n.nodeType === 1 && n.classList && n.classList.contains('gl-tip'));
|
|
223
|
+
// the card coming and going, or a change inside it, is not a change of the page's text
|
|
224
|
+
if (list.every((m) => (m.target && m.target.closest && m.target.closest('.gl-tip')) || (m.type === 'childList' && [...m.addedNodes, ...m.removedNodes].every(ours)))) return;
|
|
225
|
+
clearTimeout(S.scanT);
|
|
226
|
+
S.scanT = setTimeout(scan, 500);
|
|
227
|
+
});
|
|
228
|
+
S.mo.observe(doc.body, { childList: true, subtree: true, characterData: true });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function startGlossary(doc = typeof document !== 'undefined' ? document : null) {
|
|
232
|
+
if (started || !doc || !doc.body) return false;
|
|
233
|
+
if (botNow()) return false; // a browser a script drives: no underline, no meanings, nothing noted
|
|
234
|
+
started = true;
|
|
235
|
+
S.doc = doc;
|
|
236
|
+
const win = doc.defaultView;
|
|
237
|
+
doc.addEventListener('pointermove', onMove, { passive: true });
|
|
238
|
+
doc.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
239
|
+
doc.addEventListener('touchmove', onTouchMove, { passive: true });
|
|
240
|
+
doc.addEventListener('touchend', onTouchEnd, { passive: true });
|
|
241
|
+
doc.defaultView.addEventListener('click', eatClick, true); // capture on the window: runs before the row's own press
|
|
242
|
+
doc.addEventListener('contextmenu', eatMenu, true);
|
|
243
|
+
doc.addEventListener('keydown', (e) => { if (e.key === 'Escape') hide(); });
|
|
244
|
+
if (win) {
|
|
245
|
+
win.addEventListener('scroll', hide, { passive: true, capture: true });
|
|
246
|
+
win.addEventListener('pp:changed', () => { load(); });
|
|
247
|
+
}
|
|
248
|
+
load();
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
@@ -224,6 +224,19 @@ async function pure() {
|
|
|
224
224
|
ok('D4 the second tap sets the due day and closes the picker', await until(() => last(A, '/api/boards/tasks/edit').body.due === '2026-11-01') && await until(() => p.evaluate((c) => !document.querySelector(c + ' .tkc-dp'), C)));
|
|
225
225
|
await p.click(C + ' [data-tkc="dates"]');
|
|
226
226
|
await until(() => p.evaluate((c) => !!document.querySelector(c + ' .tkc-dp'), C));
|
|
227
|
+
// the keys: one day of the grid takes the focus (the start), the arrows move it, Enter picks it
|
|
228
|
+
await p.focus(C + ' .tkc-dp .rp-g [tabindex="0"]');
|
|
229
|
+
const kf = await p.evaluate(() => (document.activeElement || {}).dataset && document.activeElement.dataset.rpDay);
|
|
230
|
+
await p.keyboard.press('ArrowLeft'); await p.keyboard.press('ArrowUp');
|
|
231
|
+
const km = await p.evaluate(() => (document.activeElement || {}).dataset && document.activeElement.dataset.rpDay);
|
|
232
|
+
await p.keyboard.press('Enter');
|
|
233
|
+
ok('D4 the keys: the start day has the focus, the arrows move it a day and a week, Enter sets the start and the due day is next', kf === '2026-10-31' && km === '2026-10-23'
|
|
234
|
+
&& await until(() => last(A, '/api/boards/tasks/edit').body.start === '2026-10-23') && await until(() => p.evaluate((c) => { const e = document.querySelector(c + ' .tkc-dp [data-rp-end="due"]'); return !!e && e.classList.contains('on'); }, C)), JSON.stringify({ kf, km, last: last(A, '/api/boards/tasks/edit') }));
|
|
235
|
+
// typing: a day written in an end's field, then Enter, sets that end
|
|
236
|
+
await p.fill(C + ' .tkc-dp [data-rp-end="due"] .rp-in', '5 Nov'); await p.keyboard.press('Enter');
|
|
237
|
+
ok('D4 a day typed in Due ("5 Nov") and Enter sets the due day and closes the picker', await until(() => last(A, '/api/boards/tasks/edit').body.due === '2026-11-05') && await until(() => p.evaluate((c) => !document.querySelector(c + ' .tkc-dp'), C)), JSON.stringify(last(A, '/api/boards/tasks/edit')));
|
|
238
|
+
await p.click(C + ' [data-tkc="dates"]');
|
|
239
|
+
await until(() => p.evaluate((c) => !!document.querySelector(c + ' .tkc-dp'), C));
|
|
227
240
|
await p.mouse.click(5, 5);
|
|
228
241
|
ok('D4 a press outside closes the picker', await until(() => p.evaluate((c) => !document.querySelector(c + ' .tkc-dp'), C)));
|
|
229
242
|
// owner
|
|
@@ -339,6 +352,9 @@ async function pure() {
|
|
|
339
352
|
await p.click(C + ' [data-tkc="dates"]');
|
|
340
353
|
const dp = await until(() => p.evaluate((c) => { const pop = document.querySelector(c + ' .tkc-dp'); if (!pop) return null; const r = pop.getBoundingClientRect(); return r.right <= innerWidth + 1 && r.left >= -1; }, C));
|
|
341
354
|
ok('D12 the picker stays on the screen', dp === true);
|
|
355
|
+
// on a phone the days are thumb-sized: each day's mark at least 42 px, the grid with no sideways scroll
|
|
356
|
+
const ph = await p.evaluate((c) => { const d = [...document.querySelectorAll(c + ' .tkc-dp .rp-g .rp-d span')]; const r = d.map((x) => x.getBoundingClientRect()); return { n: d.length, w: Math.min(...r.map((x) => x.width)), h: Math.min(...r.map((x) => x.height)), over: document.documentElement.scrollWidth > innerWidth + 1 }; }, C);
|
|
357
|
+
ok('D12 the phone: every day is at least 42 px, and nothing scrolls sideways', ph.n >= 28 && ph.w >= 42 && ph.h >= 42 && !ph.over, JSON.stringify(ph));
|
|
342
358
|
await shot(p, 'task-phone-390-dark');
|
|
343
359
|
ok('D12 the page raised no error', A.errors.length === 0, A.errors.join(' | '));
|
|
344
360
|
await A.ctx.close();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "initiative glossary-hover (bet A386): a product's own words explain themselves on hover; the store, matcher, pmos glossary, GET /api/glossary and the page's parts on scratch folders (no server, network or browser).",
|
|
3
|
+
"modules": [
|
|
4
|
+
"product-glossary.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"product-glossary.test.js": 2
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Initiative search-answers-questions: a question typed in Search gets a short answer written from passages of the user's files, with its sources. The passages, the route and the silence run in node with a made-up session; the row in pm/cozy-search.js has no browser test (TESTS rule: no new browser tests).",
|
|
3
|
+
"modules": [
|
|
4
|
+
"search-ask.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"search-ask.test.js": 2
|
|
8
|
+
}
|
|
9
|
+
}
|