create-pmos 0.600.0 → 0.602.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 -27
- 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/agent-capabilities.md +7 -7
- package/workspace/guide/settings-and-switches.md +24 -0
- package/workspace/lib/bg-queue.js +1 -0
- package/workspace/lib/event-relay.js +202 -0
- package/workspace/lib/job-graph.js +1 -0
- package/workspace/lib/live-round.js +30 -8
- package/workspace/lib/proto-runtime.js +39 -5
- package/workspace/lib/refresh-run.js +171 -30
- package/workspace/lib/refresh.js +107 -20
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-lab.js +10 -6
- package/workspace/lib/routes-refresh.js +12 -4
- package/workspace/lib/routes-relay.js +29 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-ev.css +9 -0
- package/workspace/public/pm/cozy-evmodel.js +14 -0
- package/workspace/public/pm/cozy-proto.css +66 -17
- package/workspace/public/pm/cozy-proto.js +224 -56
- package/workspace/public/pm/cozy-relay.js +80 -0
- package/workspace/public/pm/cozy-schedwork.js +52 -19
- package/workspace/public/pm/cozy-settings.js +11 -3
- package/workspace/public/pm/home-chat.js +4 -0
- package/workspace/server.js +15 -6
- package/workspace/skills/sources-read.skill +1 -1
- package/workspace/test-lists/event-relay.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.602.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.602.0",
|
|
38
|
+
"at": "2026-11-18T08:21:52.461Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1344,
|
|
43
|
+
"t": "Prototype like Figma: pages, screens, layers, an inspector, and Play with the flow beside it",
|
|
44
|
+
"s": "Prototype like Figma: pages, screens, layers, an inspector, and Play with the flow beside it",
|
|
45
|
+
"k": "new"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"v": "0.601.0",
|
|
51
|
+
"at": "2026-11-18T07:30:23.248Z",
|
|
52
|
+
"f": 4,
|
|
53
|
+
"prs": [
|
|
54
|
+
{
|
|
55
|
+
"n": 1338,
|
|
56
|
+
"t": "Signed event relay for GitHub and Jira; an event only starts a read",
|
|
57
|
+
"s": "Signed event relay for GitHub and Jira; an event only starts a read",
|
|
58
|
+
"k": "new"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"n": 1342,
|
|
62
|
+
"t": "Your tools as one row per service, and a stuck read says why",
|
|
63
|
+
"s": "Your tools as one row per service, and a stuck read says why",
|
|
64
|
+
"k": "new"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
36
68
|
{
|
|
37
69
|
"v": "0.600.0",
|
|
38
70
|
"at": "2026-11-18T06:46:12.110Z",
|
|
@@ -284,32 +316,6 @@
|
|
|
284
316
|
"k": "fix"
|
|
285
317
|
}
|
|
286
318
|
]
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
"v": "0.582.0",
|
|
290
|
-
"at": "2026-11-17T02:50:44.770Z",
|
|
291
|
-
"f": 4,
|
|
292
|
-
"prs": [
|
|
293
|
-
{
|
|
294
|
-
"n": 1313,
|
|
295
|
-
"t": "The meeting companion offers a live round (live round W2)",
|
|
296
|
-
"s": "The meeting companion offers a live round (live round W2)",
|
|
297
|
-
"k": "new"
|
|
298
|
-
}
|
|
299
|
-
]
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
"v": "0.581.0",
|
|
303
|
-
"at": "2026-11-17T02:30:27.550Z",
|
|
304
|
-
"f": 4,
|
|
305
|
-
"prs": [
|
|
306
|
-
{
|
|
307
|
-
"n": 1314,
|
|
308
|
-
"t": "Live round from the initiative chat",
|
|
309
|
-
"s": "Live round from the initiative chat",
|
|
310
|
-
"k": "new"
|
|
311
|
-
}
|
|
312
|
-
]
|
|
313
319
|
}
|
|
314
320
|
]
|
|
315
321
|
}
|
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-18T08:21:48Z"}
|
|
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-18T08:21:48Z"}
|
|
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-18T08:21:48Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.602.0",
|
|
4
|
+
"at": "2026-11-18T08:21:52.461Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1344,
|
|
9
|
+
"t": "Prototype like Figma: pages, screens, layers, an inspector, and Play with the flow beside it",
|
|
10
|
+
"s": "Prototype like Figma: pages, screens, layers, an inspector, and Play with the flow beside it",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"v": "0.601.0",
|
|
17
|
+
"at": "2026-11-18T07:30:23.248Z",
|
|
18
|
+
"f": 4,
|
|
19
|
+
"prs": [
|
|
20
|
+
{
|
|
21
|
+
"n": 1338,
|
|
22
|
+
"t": "Signed event relay for GitHub and Jira; an event only starts a read",
|
|
23
|
+
"s": "Signed event relay for GitHub and Jira; an event only starts a read",
|
|
24
|
+
"k": "new"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"n": 1342,
|
|
28
|
+
"t": "Your tools as one row per service, and a stuck read says why",
|
|
29
|
+
"s": "Your tools as one row per service, and a stuck read says why",
|
|
30
|
+
"k": "new"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
2
34
|
{
|
|
3
35
|
"v": "0.600.0",
|
|
4
36
|
"at": "2026-11-18T06:46:12.110Z",
|
|
@@ -195,16 +195,16 @@ Not proven yet: the compare view's Production and Design columns stay left out u
|
|
|
195
195
|
You can ask to see an idea at any moment: alone while you work on an initiative, or with stakeholders in the room. It works like design work with Claude Code: you say what you want, PMOS makes or changes the one prototype, the Viewer shows it, and the chat says what changed.
|
|
196
196
|
|
|
197
197
|
1. **Ask in the initiative's chat.** Say, for example, "prototype this" or "mock this up". PMOS starts one prototype at once. Nothing to press. It opens in the Viewer beside the chat as soon as it opens and renders in a headless browser, in about a minute. The chat answers with a **Version 1** tag and says what was made and for whom. Tap a Version tag to show that version again.
|
|
198
|
-
2. **The Viewer is one canvas.**
|
|
199
|
-
- **
|
|
200
|
-
- **
|
|
201
|
-
- **Page copy
|
|
202
|
-
-
|
|
198
|
+
2. **The Viewer is one canvas, like a design tool.** The prototype is in the middle, at its own size. Three panels sit around it:
|
|
199
|
+
- **Pages, screens and layers** (left). A page is one format or page of the prototype, for example "One Raffles Place LED". A page has screens: its states, for example "Default" and "Sponsor sold". Layers lists the blocks of the screen shown. Tap a screen to show it, or tap a layer to select it. Press [ to hide or show this panel.
|
|
200
|
+
- **Exact values** (right): the inspector for the selected layer. Set its text, font, size, weight, line height, letter spacing, colour, fill, corner, padding and alignment. The prototype changes at once. PMOS keeps the change with the version, and the next version keeps it. The chat shows one quiet line, for example "You set Temperature to 56px · Bold. Kept as yours." The undo press in the panel clears that layer's changes. Press ] to hide or show the inspector.
|
|
201
|
+
- **Page copy, The flow and Who does what**: one press each in the toolbar, closed by default. One opens at a time, in the inspector's place. Page copy lists every word on the screen: edit a line in place. The flow shows screens as cards, decisions as diamonds and branches to the other scenarios: tap a screen to see it, or a side branch to play that scenario. Who does what is a swimlane with arrows between the steps. A press with a dot, or a panel that says **Updated**, is what the last version changed.
|
|
202
|
+
- Zoom out, zoom in and fit are in the toolbar. The design opens on the latest version: the toolbar says **Latest · version n**.
|
|
203
203
|
3. **Change it in one sentence.** For example, "make the alert orange". PMOS makes the next version of the prototype and its flow, swimlane and copy, and the chat says what changed, then "Also updated: step 3, the swimlane and the copy". ‹ › in the toolbar walks the versions. On an older version, **Back to latest** returns, and **Continue from version n** makes your next change start from that version.
|
|
204
|
-
4. **
|
|
204
|
+
4. **Select, then say.** Select (V) is on when the Viewer opens. Tap a block in the prototype, or a layer in the list. It is selected in both places, its exact values show in the inspector, and it goes into the chat box as a chip, for example "Temperature". Your next sentence changes that block. Sliders that the version offers for it (spacing, corner radius, colour) show under the prototype.
|
|
205
205
|
5. **Comment.** Press Comment (C) and tap an element. Write the comment, then send it to PMOS as the next change, or keep it for the team. A kept comment stays pinned, with **Make this change** beside it.
|
|
206
206
|
6. **Draw or attach an image.** Press Draw (D), sketch over the prototype, then attach the sketch. It goes with your next message. An image you attach does the same. PMOS builds from it (its layout, hierarchy and colours) unless your words say otherwise, for example "only the colours".
|
|
207
|
-
7. **Play.** Press Play to run the prototype
|
|
207
|
+
7. **Play.** Press Play to run the prototype through a path of the flow. It shows only the prototype, with no design notes. Pick where it plays: on a phone, on a desktop, or at its own size. The flow sits beside it: pick a path, and tap a step to go there. ← and → move a step, and so do the arrows under the prototype. On a screen with taps, tap where the user would tap; a tap that misses shows where to tap. Restart is under the prototype. Stop (Esc) goes back to the design.
|
|
208
208
|
8. **Several versions only when you ask.** Say "show me 3 ways" (or "two options"). PMOS picks that many directions and shows them in a tray. Tap one to preview it, then keep it (✓) or close the tray (✕).
|
|
209
209
|
9. **The initiative's prototype.** The newest version made from the chat is the initiative's prototype. It is the one entry under **Prototype & design** on the initiative page (above Documents), and the **Prototype** line on its Experiment card. Both open it in the Viewer. Older rounds stay in the Viewer's history, not on the page. Your edits in the Viewer are part of that version. Earlier versions stay in ‹ ›. PMOS never keeps a round by itself. A round of several ways, or one started from a terminal (a test), becomes the prototype only when you keep it with ✓ in the Viewer; the grill then runs once on it. ✕ drops a round, and you can say why.
|
|
210
210
|
10. **The chat knows the prototype.** Every message in the initiative's chat tells PMOS which version is current, where its files are, and the one command that makes the next version. So "Improve the prototype based on the PRD" or "Rebuild A from this list" makes the next version in the Viewer. When no version is current yet, the chat gets the list of recent versions with the command to continue each one (`--of <round>`), and asks you which one if it is not clear. The chat never writes a loose HTML file.
|
|
@@ -346,6 +346,20 @@ Press › on a row to open its page. A change you make there shows on the Connec
|
|
|
346
346
|
| History | The last five runs, with the result. |
|
|
347
347
|
| ▶ | Read it now. |
|
|
348
348
|
|
|
349
|
+
**Your tools, one row per service.** Mail, Slack, Wispr Flow, Confluence, GitHub, Drive, Figma and Your websites each have their own row, so each can have its own rhythm. On a service's page, **Repeats** has **Same as Your tools**, which is the default. Services due at the same minute share one session. Jira mentions are read with every read of Your tools.
|
|
350
|
+
|
|
351
|
+
**When a read is stuck.** A read that does not end says why on its row, for example **Stuck since 10:00 · waiting for your permission**. Its page says how to fix it, with two buttons:
|
|
352
|
+
|
|
353
|
+
| Reason | What to do |
|
|
354
|
+
|---|---|
|
|
355
|
+
| Waiting for your permission | A background read cannot ask you. Open the session and allow it, or stop it and read again. |
|
|
356
|
+
| Waiting for your answer | Open the session and answer it, or stop it and read again. |
|
|
357
|
+
| Still reading after N min | Nothing, usually. PMOS stops it at 30 min. |
|
|
358
|
+
| Signed out | Sign in again in Settings › PMOS. PMOS ends the read at once. |
|
|
359
|
+
| The session was gone | Nothing. PMOS restarted or the computer slept, and the next read starts on time. |
|
|
360
|
+
|
|
361
|
+
↗ opens the session. ■ is **Stop and read again**: it stops the read and starts the same services again. A read of a tool that has not ended after 30 minutes is stopped by itself, and History says why. A stuck service holds back only itself: the other services keep their rhythm.
|
|
362
|
+
|
|
349
363
|
On a day with 3 or more meetings, PMOS proposes ✦ **Read it more often on meeting days**: Calendar every 15 min on such days, other days as set. Nothing changes until you press ✓. **Undo** puts the old rhythm back, and ✕ hides the proposal for today.
|
|
350
364
|
|
|
351
365
|
The **Scheduled work** row under the sources lists everything that runs on a schedule: what PMOS reads, PMOS's own jobs (the day check, the initiative driver, signals) and your own scheduled tasks, each with its next run. Your own tasks can repeat every hour, every day, every week, every 2 weeks or every month.
|
|
@@ -365,6 +379,16 @@ PMOS cannot add a connector, because it keeps no passwords or keys. To connect a
|
|
|
365
379
|
3. PMOS checks every 5 seconds for 2 minutes. When it sees the connector, it says so. If it does not see it in that time, the connector shows when your next session starts.
|
|
366
380
|
4. When a new connector appears, a ✦ card says what PMOS proposes to read from it. Nothing reads it until you press ✓. ✕ means not now. When a source needs you, the Connectors tab has an amber dot, an amber box at the top of the other Settings sections names it, and the place menu opens Settings at Connectors. PMOS repairs the other problems by itself, so you do not see a box for them (see below).
|
|
367
381
|
|
|
382
|
+
### Listening: GitHub and Jira tell PMOS when something changes
|
|
383
|
+
|
|
384
|
+
At the end of Settings › Connectors, **Listening** has a row for GitHub and a row for Jira. A service with no listening set up is read on its schedule, as before. To make PMOS read a service within a minute of a change, even while this computer sleeps:
|
|
385
|
+
|
|
386
|
+
1. Press the bell on the row. PMOS makes an address and a secret on the central host and shows the steps.
|
|
387
|
+
2. Copy the address and the secret, and paste them into a new webhook in GitHub (repository or organization Settings › Webhooks) or Jira (Settings › System › WebHooks).
|
|
388
|
+
3. The row then says **Listening** and shows when the last event came. The last events are listed under the rows.
|
|
389
|
+
|
|
390
|
+
An event only starts a read of that service: GitHub starts the read of your tools, and Jira starts the Jira read and the read of work assigned to you. A read that you turned off stays off. An event never changes your records, never accepts or merges work, and PMOS keeps only its kind, its id, its time and the item it is about (D110). To stop, press the crossed-out bell: the address and its queue are deleted on the host. Listening needs the central host address that Board publishing uses.
|
|
391
|
+
|
|
368
392
|
### When a source cannot be read: PMOS repairs it first
|
|
369
393
|
|
|
370
394
|
You do not need to watch the sources. When a source that is on is past its limit, never read, or its last read failed, PMOS reads it again by itself, without a press. Calendar, Jira, My work, tracker items and Your tools are each repaired this way.
|
|
@@ -70,6 +70,7 @@ const JOBS = Object.freeze([
|
|
|
70
70
|
{ id: 'refresh', step: 2, label: 'Data refresh' },
|
|
71
71
|
{ id: 'reports', step: 2, label: 'Report schedules' },
|
|
72
72
|
{ id: 'sync', step: 2, label: 'Git sync', ai: false },
|
|
73
|
+
{ id: 'relay', step: 2, label: 'Event relay', ai: false }, // D110: pulls the signed event queue; an event only starts a read (lib/event-relay.js)
|
|
73
74
|
{ id: 'meeting-prewarm', step: 2, label: 'Prototypes before a meeting' }, // lib/live-round-meeting.js: round 1 waits at minute 0
|
|
74
75
|
{ id: 'driver', step: 3, label: 'Initiative Driver' },
|
|
75
76
|
{ id: 'goal-loops', step: 3, label: 'Goal loops' }, // D106: the rounds of a long-running goal (lib/goal-loop.js)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* event-relay.js — the workspace's side of the signed event relay (initiative event-relay; D110). An event is a doorbell, never a door.
|
|
3
|
+
*
|
|
4
|
+
* THE CONTRACT with the host (board-host/src/relay.js):
|
|
5
|
+
* POST <host>/api/relay/hooks Bearer <relay key> { source } -> { ok, id, url, secret, source }
|
|
6
|
+
* DELETE <host>/api/relay/hooks/<id> Bearer <relay key> -> { ok }
|
|
7
|
+
* GET <host>/api/relay/events?after=n Bearer <relay key> -> { ok, events: [{ seq, source, kind, id, at, key }], cursor }
|
|
8
|
+
* The host is the D103 host: the same address as board publishing (lib/boards-host.js hostOrigin / addressOf).
|
|
9
|
+
*
|
|
10
|
+
* THE STATE, <runtime state>/event-relay/state.json (mode 0600; never a record, never logged, the key never leaves for the browser):
|
|
11
|
+
* { key, sources: { github?: { id, url, secret, made }, jira?: {…} }, cursor, seen: [eid…200], recent: [{ source, kind, key, at }…20],
|
|
12
|
+
* last: { at, ok, error? }, rang: { source: iso } }
|
|
13
|
+
*
|
|
14
|
+
* THE DOORBELL (D110 point 5). pull() hands each source that had events to ring(readId) ONCE per pull, for the reads in READS. That is all an
|
|
15
|
+
* event can do: ring is lib/refresh-run.js runNow in the server, the same read the schedule starts. This module writes only its own state file.
|
|
16
|
+
*
|
|
17
|
+
* SOURCES · READS · KEEP_MS
|
|
18
|
+
* status(dir, { env }) -> { host, sources: { github: { listening, url, made, last }, jira: … }, recent, last } (no secret)
|
|
19
|
+
* steps(dir, source) -> { ok, source, url, secret, steps: [sentence] } | { ok: false, error } for the PM to paste
|
|
20
|
+
* setup(dir, source, { fetch, env, now }) -> { ok, …steps(dir, source) } | { ok: false, error, status }
|
|
21
|
+
* stop(dir, source, { fetch, env }) -> { ok } | { ok: false, error }
|
|
22
|
+
* pull(dir, { fetch, env, now, ring }) -> { ok, events: n, rang: [readId] } | { ok: true, idle: true } | { ok: false, error }
|
|
23
|
+
* puller({ dir, refreshRun, register }) -> { tick } the background job; register(tick) hands it to the queue
|
|
24
|
+
* doorbell(refreshRun) -> ring: (readId) => refreshRun.runNow(readId) when that read is on, else { ok: false, skipped: 'off' }
|
|
25
|
+
*/
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
const crypto = require('crypto');
|
|
29
|
+
const boardsHost = require('./boards-host.js');
|
|
30
|
+
|
|
31
|
+
const SOURCES = Object.freeze(['github', 'jira']);
|
|
32
|
+
const LABEL = Object.freeze({ github: 'GitHub', jira: 'Jira' });
|
|
33
|
+
/** Which lib/refresh.js reads an event starts. GitHub is read through "Your tools" (sources-read); Jira by the Jira and work-assigned reads. */
|
|
34
|
+
const READS = Object.freeze({ github: Object.freeze(['tools']), jira: Object.freeze(['jira', 'mywork']) });
|
|
35
|
+
const KEEP_MS = 7 * 24 * 60 * 60 * 1000;
|
|
36
|
+
const TIMEOUT_MS = 15000;
|
|
37
|
+
|
|
38
|
+
const fileOf = (dir) => path.join(dir, 'event-relay', 'state.json');
|
|
39
|
+
|
|
40
|
+
function readState(dir) {
|
|
41
|
+
try {
|
|
42
|
+
const s = JSON.parse(fs.readFileSync(fileOf(dir), 'utf8'));
|
|
43
|
+
return { key: typeof s.key === 'string' ? s.key : null, sources: s.sources && typeof s.sources === 'object' ? s.sources : {}, cursor: Number(s.cursor) || 0,
|
|
44
|
+
seen: Array.isArray(s.seen) ? s.seen : [], recent: Array.isArray(s.recent) ? s.recent : [], last: s.last || null, rang: s.rang && typeof s.rang === 'object' ? s.rang : {} };
|
|
45
|
+
} catch { return { key: null, sources: {}, cursor: 0, seen: [], recent: [], last: null, rang: {} }; }
|
|
46
|
+
}
|
|
47
|
+
function writeState(dir, st) {
|
|
48
|
+
const f = fileOf(dir);
|
|
49
|
+
fs.mkdirSync(path.dirname(f), { recursive: true, mode: 0o700 });
|
|
50
|
+
const tmp = f + '.' + process.pid + '.' + crypto.randomBytes(4).toString('hex') + '.tmp';
|
|
51
|
+
fs.writeFileSync(tmp, JSON.stringify(st), { mode: 0o600 });
|
|
52
|
+
fs.renameSync(tmp, f);
|
|
53
|
+
}
|
|
54
|
+
const originOf = (dir, env) => boardsHost.hostOrigin(boardsHost.addressOf(dir, env || process.env));
|
|
55
|
+
|
|
56
|
+
/** One request to the host. Never throws. */
|
|
57
|
+
async function call(origin, method, p, key, body, fetchFn) {
|
|
58
|
+
const f = fetchFn || (typeof fetch === 'function' ? fetch : null);
|
|
59
|
+
if (!f) return { ok: false, error: 'This computer cannot reach the host.' };
|
|
60
|
+
const ctl = typeof AbortController === 'function' ? new AbortController() : null;
|
|
61
|
+
const timer = ctl ? setTimeout(() => ctl.abort(), TIMEOUT_MS) : null;
|
|
62
|
+
try {
|
|
63
|
+
const res = await f(origin + p, { method, redirect: 'error', signal: ctl ? ctl.signal : undefined,
|
|
64
|
+
headers: Object.assign({ Authorization: 'Bearer ' + key, Accept: 'application/json' }, body ? { 'Content-Type': 'application/json' } : {}),
|
|
65
|
+
body: body ? JSON.stringify(body) : undefined });
|
|
66
|
+
let j = null; try { j = await res.json(); } catch { /* not JSON */ }
|
|
67
|
+
if (!res.ok || !j || j.ok === false) return { ok: false, status: res.status, error: (j && typeof j.error === 'string' && j.error.slice(0, 200)) || 'The host refused the request (' + res.status + ').' };
|
|
68
|
+
return { ok: true, body: j };
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return { ok: false, error: e && e.name === 'AbortError' ? 'The host did not answer in time.' : 'The host could not be reached.' };
|
|
71
|
+
} finally { if (timer) clearTimeout(timer); }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The exact steps the PM follows in the other service. Sentences only; PMOS sends nothing to GitHub or Jira. */
|
|
75
|
+
function stepsFor(source, url, secret) {
|
|
76
|
+
if (source === 'github') return [
|
|
77
|
+
'In GitHub, open the repository (or the organization), then Settings › Webhooks › Add webhook.',
|
|
78
|
+
'Payload URL: ' + url,
|
|
79
|
+
'Content type: application/json.',
|
|
80
|
+
'Secret: paste the secret shown here.',
|
|
81
|
+
'Events: choose "Let me select individual events" and tick Pull requests, Issues, Pushes and Releases. Keep Active on, then Add webhook.',
|
|
82
|
+
'GitHub sends a ping at once. When PMOS shows it under Listening, the address works.',
|
|
83
|
+
];
|
|
84
|
+
return [
|
|
85
|
+
'In Jira, open Settings › System › WebHooks (you need to be a Jira admin), then Create a WebHook.',
|
|
86
|
+
'URL: ' + url,
|
|
87
|
+
'Secret: paste the secret shown here.',
|
|
88
|
+
'Events: tick Issue created, updated and deleted. You can limit it with a JQL filter such as project = PMOS.',
|
|
89
|
+
'Save. The next change to an issue shows under Listening.',
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function steps(dir, source) {
|
|
94
|
+
if (!SOURCES.includes(source)) return { ok: false, status: 400, error: 'PMOS listens to GitHub and Jira.' };
|
|
95
|
+
const s = readState(dir).sources[source];
|
|
96
|
+
if (!s) return { ok: false, status: 404, error: LABEL[source] + ' is not set up to send events yet.' };
|
|
97
|
+
return { ok: true, source, url: s.url, secret: s.secret, steps: stepsFor(source, s.url, s.secret) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function status(dir, { env } = {}) {
|
|
101
|
+
const st = readState(dir);
|
|
102
|
+
const sources = {};
|
|
103
|
+
for (const id of SOURCES) {
|
|
104
|
+
const s = st.sources[id];
|
|
105
|
+
sources[id] = s ? { listening: true, url: s.url, made: s.made, last: st.rang[id] || null, reads: READS[id] } : { listening: false, reads: READS[id] };
|
|
106
|
+
}
|
|
107
|
+
return { host: !!originOf(dir, env), sources, recent: st.recent.slice(0, 10), last: st.last };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const noHost = { ok: false, status: 409, error: 'Listening for events needs the central host. Set its address under Board › Publish (or PMOS_BOARDS_HOST), then try again.' };
|
|
111
|
+
|
|
112
|
+
async function setup(dir, source, opts = {}) {
|
|
113
|
+
if (!SOURCES.includes(source)) return { ok: false, status: 400, error: 'PMOS listens to GitHub and Jira.' };
|
|
114
|
+
const origin = originOf(dir, opts.env); if (!origin) return noHost;
|
|
115
|
+
const st = readState(dir);
|
|
116
|
+
if (!st.key) { st.key = crypto.randomBytes(32).toString('base64url'); writeState(dir, st); }
|
|
117
|
+
const r = await call(origin, 'POST', '/api/relay/hooks', st.key, { source }, opts.fetch);
|
|
118
|
+
if (!r.ok) return r;
|
|
119
|
+
const b = r.body;
|
|
120
|
+
if (typeof b.id !== 'string' || typeof b.secret !== 'string' || b.secret.length < 20 || typeof b.url !== 'string' || !b.url.startsWith(origin + '/hook/')) return { ok: false, status: 502, error: 'The host sent an answer this workspace does not accept.' };
|
|
121
|
+
const cur = readState(dir);
|
|
122
|
+
cur.key = st.key;
|
|
123
|
+
cur.sources[source] = { id: b.id, url: b.url, secret: b.secret, made: new Date(opts.now || Date.now()).toISOString() };
|
|
124
|
+
writeState(dir, cur);
|
|
125
|
+
return steps(dir, source);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function stop(dir, source, opts = {}) {
|
|
129
|
+
if (!SOURCES.includes(source)) return { ok: false, status: 400, error: 'PMOS listens to GitHub and Jira.' };
|
|
130
|
+
const st = readState(dir); const s = st.sources[source];
|
|
131
|
+
if (!s) return { ok: true };
|
|
132
|
+
const origin = originOf(dir, opts.env);
|
|
133
|
+
if (origin && st.key) {
|
|
134
|
+
const r = await call(origin, 'DELETE', '/api/relay/hooks/' + encodeURIComponent(s.id), st.key, null, opts.fetch);
|
|
135
|
+
if (!r.ok && r.status !== 404) return r;
|
|
136
|
+
}
|
|
137
|
+
const cur = readState(dir); delete cur.sources[source]; delete cur.rang[source]; cur.recent = cur.recent.filter((e) => e.source !== source);
|
|
138
|
+
writeState(dir, cur);
|
|
139
|
+
return { ok: true };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Pull the queue once and ring the doorbell. A source rings once per pull however many events it had; a delivery already seen does not ring;
|
|
143
|
+
* an event older than 7 days is dropped. ring(readId) is the only effect outside this module's state file. */
|
|
144
|
+
async function pull(dir, opts = {}) {
|
|
145
|
+
const st = readState(dir);
|
|
146
|
+
const live = SOURCES.filter((s) => st.sources[s]);
|
|
147
|
+
if (!st.key || !live.length) return { ok: true, idle: true };
|
|
148
|
+
const origin = originOf(dir, opts.env); if (!origin) return noHost;
|
|
149
|
+
const t = opts.now || Date.now();
|
|
150
|
+
const r = await call(origin, 'GET', '/api/relay/events?after=' + st.cursor, st.key, null, opts.fetch);
|
|
151
|
+
const cur = readState(dir);
|
|
152
|
+
if (!r.ok) { cur.last = { at: new Date(t).toISOString(), ok: false, error: r.error }; writeState(dir, cur); return r; }
|
|
153
|
+
const events = Array.isArray(r.body.events) ? r.body.events : [];
|
|
154
|
+
const seen = new Set(cur.seen);
|
|
155
|
+
const fresh = [];
|
|
156
|
+
for (const e of events) {
|
|
157
|
+
if (!e || !live.includes(e.source)) continue;
|
|
158
|
+
const at = Date.parse(e.at); if (!Number.isFinite(at) || t - at > KEEP_MS) continue;
|
|
159
|
+
const id = String(e.id || ''); if (!id || seen.has(id)) continue;
|
|
160
|
+
seen.add(id);
|
|
161
|
+
fresh.push({ source: e.source, kind: String(e.kind || '').slice(0, 80), key: String(e.key || '').slice(0, 160), at: new Date(at).toISOString(), id });
|
|
162
|
+
}
|
|
163
|
+
const rang = [];
|
|
164
|
+
const ring = typeof opts.ring === 'function' ? opts.ring : null;
|
|
165
|
+
for (const src of live) {
|
|
166
|
+
if (!fresh.some((e) => e.source === src)) continue;
|
|
167
|
+
cur.rang[src] = new Date(t).toISOString();
|
|
168
|
+
if (!ring) continue;
|
|
169
|
+
for (const readId of READS[src]) { try { const x = ring(readId, src); if (!x || x.ok !== false || x.status === 409) rang.push(readId); } catch { /* the next event rings again */ } }
|
|
170
|
+
}
|
|
171
|
+
const cursor = Number(r.body.cursor); if (Number.isFinite(cursor) && cursor > cur.cursor) cur.cursor = cursor;
|
|
172
|
+
cur.seen = [...seen].slice(-200);
|
|
173
|
+
cur.recent = fresh.map(({ source, kind, key, at }) => ({ source, kind, key, at })).reverse().concat(cur.recent).filter((e) => t - Date.parse(e.at) <= KEEP_MS).slice(0, 20);
|
|
174
|
+
cur.last = { at: new Date(t).toISOString(), ok: true };
|
|
175
|
+
writeState(dir, cur);
|
|
176
|
+
return { ok: true, events: fresh.length, rang };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The ring the server hands pull(): start the read through the refresh engine (lib/refresh-run.js), the same read the schedule starts.
|
|
180
|
+
* A read the PM turned off stays off: the doorbell does not turn it on. */
|
|
181
|
+
function doorbell(refreshRun) {
|
|
182
|
+
return (readId) => {
|
|
183
|
+
const set = refreshRun.settings(); const s = set && set.sources && set.sources[readId];
|
|
184
|
+
if (!s || s.on !== true) return { ok: false, skipped: 'off' };
|
|
185
|
+
return refreshRun.runNow(readId, {});
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The background job: registers one tick with the queue (lib/bg-queue.js job 'relay'). A tick pulls once; a pull still going skips the tick. */
|
|
190
|
+
function puller({ dir, refreshRun, register, fetch: fetchFn, env } = {}) {
|
|
191
|
+
let busy = false;
|
|
192
|
+
const tick = () => {
|
|
193
|
+
if (busy) return null;
|
|
194
|
+
const rr = typeof refreshRun === 'function' ? refreshRun() : refreshRun;
|
|
195
|
+
busy = true;
|
|
196
|
+
return pull(dir, { fetch: fetchFn, env, ring: rr ? doorbell(rr) : null }).catch(() => ({ ok: false })).finally(() => { busy = false; });
|
|
197
|
+
};
|
|
198
|
+
if (typeof register === 'function') register(tick);
|
|
199
|
+
return { tick };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
module.exports = { SOURCES, LABEL, READS, KEEP_MS, readState, status, steps, stepsFor, setup, stop, pull, doorbell, puller };
|
|
@@ -136,6 +136,7 @@ const JOBS = Object.freeze([
|
|
|
136
136
|
q('refresh', 'lib/refresh.js', ['<runtime>/refresh-log.jsonl'], ['connectors']),
|
|
137
137
|
q('reports', 'lib/routes-report-setups.js', ['<state>/report-setups.jsonl', '<state>/ready-reports.jsonl'], ['<state>/report-setups.jsonl']),
|
|
138
138
|
q('sync', 'lib/auto-sync.js', [], ['git'], 'git only: no model and no ledger'),
|
|
139
|
+
q('relay', 'lib/event-relay.js', [], ['the central host'], 'D110: no model and no ledger; it keeps its own state file (event-relay/state.json) and an event only starts a read of its source through the refresh engine, never a record'),
|
|
139
140
|
q('driver', 'lib/driver.js', ['<state>/driver.jsonl'], ['initiative records', 'jira']),
|
|
140
141
|
q('goal-loops', 'lib/goal-loop.js', ['<runtime>/goal-loops.jsonl'], ['<runtime>/goal-loops.jsonl'], 'D106: each round is a run started through the capacity governor; the run writes its own records'),
|
|
141
142
|
q('finder', 'lib/report-finder.js', ['<state>/report-setups.jsonl'], ['connectors']),
|
|
@@ -242,11 +242,12 @@ function promptOf(o) {
|
|
|
242
242
|
} else if (o.alone) L.push('', 'This is the one version the PM sees: make the plainest honest version of the idea, not a showcase.');
|
|
243
243
|
else L.push('', `Your direction, ${o.key}: ${one(o.title, 200)}. Other runs take the other directions: keep yours clearly different.`);
|
|
244
244
|
if (o.point && (o.point.el || o.point.label)) L.push('', `The PM pointed at one element: ${o.point.el ? 'data-el="' + one(o.point.el, 60) + '"' : ''}${o.point.label ? ' ("' + one(o.point.label, 80) + '")' : ''}. Their words are about that element: change it, and only what must follow from it.`);
|
|
245
|
-
const ed = o.edits || {}, ec = Object.entries(ed.copy || {}), ev = Object.entries(ed.vars || {});
|
|
246
|
-
if (ec.length || ev.length) {
|
|
245
|
+
const ed = o.edits || {}, ec = Object.entries(ed.copy || {}), ev = Object.entries(ed.vars || {}), es = Object.entries(ed.styles || {});
|
|
246
|
+
if (ec.length || ev.length || es.length) {
|
|
247
247
|
L.push('', 'The PM edited the last version in place. Keep these exactly, unless their words change them:');
|
|
248
248
|
for (const [k, v] of ec.slice(0, 40)) L.push(`- the text of data-copy="${k}": ${one(v, 200)}`);
|
|
249
249
|
for (const [k, v] of ev.slice(0, 20)) L.push(`- the CSS variable ${k}: ${one(v, 40)} (set it in :root)`);
|
|
250
|
+
for (const [k, v] of es.slice(0, 30)) L.push(`- the style of data-el="${k}": ${Object.entries(v).map(([p, x]) => STYLE_OK[p][0] + ': ' + x).join('; ')} (write it in the page's CSS for that element)`);
|
|
250
251
|
}
|
|
251
252
|
// the design sprint's good practice, silent (Wawan 2026-11-17: "the design sprint runs in silent"): a target user, one question, real
|
|
252
253
|
// content, Goldilocks fidelity. Never a step the PM has to fill in.
|
|
@@ -257,8 +258,9 @@ function promptOf(o) {
|
|
|
257
258
|
' - One self-contained HTML page: inline CSS only, no script, no network, no image files. Real draft copy, never lorem ipsum or a placeholder.',
|
|
258
259
|
` - In <head>, one line for the PM: <meta name="pmos-changed" content="…"> with ONE short sentence of what ${o.base ? 'you changed' : 'you made and for whom'}, in plain words, under 140 characters.`,
|
|
259
260
|
' - Each screen is a <section data-screen="<id>" data-label="<screen name>">; the first one is where the user starts. PMOS shows one screen at a time.',
|
|
261
|
+
' - When several screens are states of one page or format (default, sponsor sold, rain alert), give each data-page="<that page\'s name>": the PM sees them as one page with its screens.',
|
|
260
262
|
' - What the user taps to move on carries data-go="<screen id>" (a button, a row, a link with href="#<screen id>").',
|
|
261
|
-
' - Every
|
|
263
|
+
' - Every visible block the PM may select and restyle (each heading, line of text, card, list, button, image, region) carries data-el="<short-id>" and data-label="<its name in plain words>".',
|
|
262
264
|
' - Every piece of visible text the PM may edit is in an element with data-copy="<key>" (unique keys, kebab-case, the text only inside it).',
|
|
263
265
|
' - Spacing, corner radius and colour warmth read CSS custom properties set in :root (for example --gap, --radius, --accent), so a slider can change them.',
|
|
264
266
|
' - Pin it to the viewport: the main card is max-width 390px and width 100%, nothing wider than the screen, no horizontal scroll at 390px. At desk width it sits centred.',
|
|
@@ -367,15 +369,35 @@ function partsAt(abs) {
|
|
|
367
369
|
const l = lanesOf(rd('lanes.json'), { screens: out.flow ? new Set(out.flow.screens.map((x) => x.id)) : null }); if (!l.error) out.lanes = l;
|
|
368
370
|
const t = tweaksOf(rd('tweaks.json')); if (!t.error && t.tweaks.length) out.tweaks = t;
|
|
369
371
|
const c = rd('copy.json'); if (isObj(c)) out.copy = c;
|
|
370
|
-
const e = editsOf(rd('edits.json')); if (Object.keys(e.copy).length || Object.keys(e.vars).length) out.edits = e;
|
|
372
|
+
const e = editsOf(rd('edits.json')); if (Object.keys(e.copy).length || Object.keys(e.vars).length || Object.keys(e.styles).length) out.edits = e;
|
|
371
373
|
return out;
|
|
372
374
|
}
|
|
373
|
-
/**
|
|
375
|
+
/** The inspector's fields (design "Prototype like Figma", Wawan "build" 2026-11-18): the key edits.json keeps, the CSS property it sets,
|
|
376
|
+
* and what a value may look like. */
|
|
377
|
+
const STYLE_OK = {
|
|
378
|
+
family: ['font-family', /^[A-Za-z0-9 ,"'-]{1,80}$/], size: ['font-size', /^\d{1,3}(\.\d{1,2})?px$/], weight: ['font-weight', /^[1-9]00$/],
|
|
379
|
+
line: ['line-height', /^\d(\.\d{1,2})?$/], spacing: ['letter-spacing', /^-?\d{1,2}(\.\d{1,2})?px$/], color: ['color', /^#[0-9a-f]{6}$/i],
|
|
380
|
+
fill: ['background-color', /^(#[0-9a-f]{6}|transparent)$/i], corner: ['border-radius', /^\d{1,3}px$/], padding: ['padding', /^\d{1,3}px( \d{1,3}px)?$/],
|
|
381
|
+
align: ['text-align', /^(left|center|right)$/],
|
|
382
|
+
};
|
|
383
|
+
/** PURE. edits.json (the PM's in-place copy edits, tweaks and inspector styles, POST /api/lab/edit) →
|
|
384
|
+
* { copy: { key: text }, vars: { --var: value }, styles: { el: { field: value } } } (fields: STYLE_OK). A bad field or value is left out. */
|
|
374
385
|
function editsOf(j) {
|
|
375
|
-
const copy = {}, vars = {};
|
|
386
|
+
const copy = {}, vars = {}, styles = {};
|
|
376
387
|
if (isObj(j) && isObj(j.copy)) for (const [k, v] of Object.entries(j.copy).slice(0, 80)) if (/^[A-Za-z0-9][A-Za-z0-9_.-]{0,59}$/.test(k) && typeof v === 'string') copy[k] = one(v, 300);
|
|
377
388
|
if (isObj(j) && isObj(j.vars)) for (const [k, v] of Object.entries(j.vars).slice(0, 12)) if (/^--[a-z][a-z0-9-]{0,40}$/i.test(k) && /^-?\d{1,4}(\.\d{1,3})?(px|rem|em|%|deg)?$/.test(String(v))) vars[k] = String(v);
|
|
378
|
-
|
|
389
|
+
if (isObj(j) && isObj(j.styles)) for (const [el, ps] of Object.entries(j.styles).slice(0, 60)) {
|
|
390
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,59}$/.test(el) || !isObj(ps)) continue;
|
|
391
|
+
const o = {};
|
|
392
|
+
for (const [k, v] of Object.entries(ps)) if (STYLE_OK[k] && typeof v === 'string' && STYLE_OK[k][1].test(v)) o[k] = v;
|
|
393
|
+
if (Object.keys(o).length) styles[el] = o;
|
|
394
|
+
}
|
|
395
|
+
return { copy, vars, styles };
|
|
396
|
+
}
|
|
397
|
+
/** PURE. What one element's styles say, for the chat and the prompt: "56px · Bold · #FFFFFF". */
|
|
398
|
+
function styleWords(ps) {
|
|
399
|
+
const W = { 100: 'Thin', 200: 'Extra light', 300: 'Light', 400: 'Regular', 500: 'Medium', 600: 'Semibold', 700: 'Bold', 800: 'Extra bold', 900: 'Black' };
|
|
400
|
+
return Object.entries(ps || {}).map(([k, v]) => (k === 'weight' ? W[v] || v : k === 'size' || k === 'color' ? v : k + ' ' + v)).join(' · ');
|
|
379
401
|
}
|
|
380
402
|
|
|
381
403
|
/** The one sentence a version says about itself: <meta name="pmos-changed" content="…"> in its head, or ''. */
|
|
@@ -716,5 +738,5 @@ function stopRound(id) { return inst ? inst.stop(id) : { ok: false, error: NOT_R
|
|
|
716
738
|
function status() { return inst ? inst.status() : []; }
|
|
717
739
|
|
|
718
740
|
module.exports = { JOB, ORIGIN, STALL_MS, progressOf, KEYS, DEFAULT_DIRECTIONS, ONE_DIRECTION, PARTS, FROM, marksOf, intentOf, parseDirs, askOf, waiting, baseOf, currentOf: PR.currentOf, contextOf, scaffoldOf, promptOf, saidOf, roundLine,
|
|
719
|
-
flowOf, lanesOf, tweaksOf, copyOf, changesOf, partsAt, editsOf,
|
|
741
|
+
flowOf, lanesOf, tweaksOf, copyOf, changesOf, partsAt, editsOf, styleWords, STYLE_OK,
|
|
720
742
|
create, install, round, startNow, proposeNow, cancel, stopRound, dropCard, running, status };
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* data-screen one screen shows at a time; the first is the start data-go a tap moves to that screen
|
|
8
8
|
* data-el what the PM can point at, comment on or tap in Play data-label its name in plain words
|
|
9
9
|
* data-copy text the Page copy card edits in place :root vars what Tweaks change
|
|
10
|
-
* Parent → frame { pmos: 1, t }: mode (view | point | comment | play), screen, copy, copyAll, vars, hint, sel, pins.
|
|
11
|
-
* Frame → parent { pmos: 1, t }: ready (screens, els, copy), screen, point
|
|
10
|
+
* Parent → frame { pmos: 1, t }: mode (view | point | comment | play), screen, copy, copyAll, vars, styles (the inspector's, all of them), hint, sel, pins.
|
|
11
|
+
* Frame → parent { pmos: 1, t }: ready (screens with their data-page, els with their screen and copy key, copy), screen, point (with looks: the
|
|
12
|
+
* selected element's current styles), looks (after styles), pin, tap.
|
|
12
13
|
*
|
|
13
14
|
* withRuntime(html) → html with the runtime's <script> before </body> (or at the end) */
|
|
14
15
|
function runtime() {
|
|
@@ -32,7 +33,36 @@ function runtime() {
|
|
|
32
33
|
post({ t: 'screen', id: on.getAttribute('data-screen') });
|
|
33
34
|
};
|
|
34
35
|
var elOf = function (n) { return n && n.closest ? n.closest('[data-el]') : null; };
|
|
35
|
-
var info = function (e) {
|
|
36
|
+
var info = function (e) {
|
|
37
|
+
if (!e) return { el: '', label: '' };
|
|
38
|
+
var sc = e.closest('[data-screen]'), cp = e.hasAttribute('data-copy') ? e : e.querySelector('[data-copy]');
|
|
39
|
+
return { el: e.getAttribute('data-el') || '', label: e.getAttribute('data-label') || (e.textContent || '').trim().slice(0, 40), screen: sc ? sc.getAttribute('data-screen') || '' : '', copy: cp ? cp.getAttribute('data-copy') || '' : '' };
|
|
40
|
+
};
|
|
41
|
+
// the inspector (design "Prototype like Figma"): what the selected element looks like now, as the values it edits
|
|
42
|
+
var CSS = { family: 'font-family', size: 'font-size', weight: 'font-weight', line: 'line-height', spacing: 'letter-spacing', color: 'color', fill: 'background-color', corner: 'border-radius', padding: 'padding', align: 'text-align' };
|
|
43
|
+
var hex = function (c) { var m = /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/.exec(c || ''); if (!m) return c || ''; if (m[4] === '0') return 'transparent'; return '#' + [m[1], m[2], m[3]].map(function (x) { return ('0' + Number(x).toString(16)).slice(-2); }).join(''); };
|
|
44
|
+
var looks = function (e) {
|
|
45
|
+
var cs = getComputedStyle(e), o = {}, fs = parseFloat(cs.fontSize) || 16, bg = e, fill = 'transparent';
|
|
46
|
+
o.family = (cs.fontFamily || '').split(',')[0].replace(/["']/g, '').trim();
|
|
47
|
+
o.size = Math.round(fs) + 'px'; o.weight = String(Math.round((parseInt(cs.fontWeight, 10) || 400) / 100) * 100);
|
|
48
|
+
o.line = cs.lineHeight === 'normal' ? '1.2' : String(Math.round((parseFloat(cs.lineHeight) / fs) * 100) / 100);
|
|
49
|
+
o.spacing = cs.letterSpacing === 'normal' ? '0px' : Math.round(parseFloat(cs.letterSpacing) * 10) / 10 + 'px';
|
|
50
|
+
o.color = hex(cs.color); o.fill = hex(cs.backgroundColor);
|
|
51
|
+
// the colour picker needs a colour: a see-through fill shows what is behind it
|
|
52
|
+
while (bg && fill === 'transparent') { fill = hex(getComputedStyle(bg).backgroundColor); bg = bg.parentElement; }
|
|
53
|
+
o.fillPick = /^#/.test(fill) ? fill : '#ffffff';
|
|
54
|
+
o.corner = Math.round(parseFloat(cs.borderTopLeftRadius) || 0) + 'px'; o.padding = Math.round(parseFloat(cs.paddingTop) || 0) + 'px ' + Math.round(parseFloat(cs.paddingLeft) || 0) + 'px';
|
|
55
|
+
o.align = /center|right/.test(cs.textAlign) ? cs.textAlign : 'left';
|
|
56
|
+
return o;
|
|
57
|
+
};
|
|
58
|
+
var styled = [];
|
|
59
|
+
var applyStyles = function (all) {
|
|
60
|
+
styled.forEach(function (x) { x.e.style.removeProperty(x.p); }); styled = [];
|
|
61
|
+
Object.keys(all || {}).forEach(function (id) {
|
|
62
|
+
var e = document.querySelector('[data-el="' + String(id).replace(/[^A-Za-z0-9_-]/g, '') + '"]'); if (!e) return;
|
|
63
|
+
Object.keys(all[id] || {}).forEach(function (k) { var p = CSS[k]; if (!p) return; e.style.setProperty(p, String(all[id][k]), 'important'); styled.push({ e: e, p: p }); });
|
|
64
|
+
});
|
|
65
|
+
};
|
|
36
66
|
var hov = null;
|
|
37
67
|
document.addEventListener('mouseover', function (ev) {
|
|
38
68
|
if (mode !== 'point' && mode !== 'comment') return;
|
|
@@ -41,7 +71,7 @@ function runtime() {
|
|
|
41
71
|
}, true);
|
|
42
72
|
document.addEventListener('click', function (ev) {
|
|
43
73
|
var e = elOf(ev.target), go = ev.target.closest && ev.target.closest('[data-go],a[href^="#"]');
|
|
44
|
-
if (mode === 'point') { ev.preventDefault(); ev.stopPropagation(); if (!e) return; sel(e.getAttribute('data-el')); var i = info(e); i.t = 'point'; post(i); return; }
|
|
74
|
+
if (mode === 'point') { ev.preventDefault(); ev.stopPropagation(); if (!e) return; sel(e.getAttribute('data-el')); var i = info(e); i.t = 'point'; i.looks = looks(e); post(i); return; }
|
|
45
75
|
if (mode === 'comment') {
|
|
46
76
|
ev.preventDefault(); ev.stopPropagation();
|
|
47
77
|
var h = Math.max(1, document.documentElement.scrollHeight), w = Math.max(1, document.documentElement.clientWidth), c = info(e);
|
|
@@ -85,12 +115,16 @@ function runtime() {
|
|
|
85
115
|
(m.els || []).forEach(function (id) { var e = document.querySelector('[data-el="' + String(id).replace(/[^A-Za-z0-9_-]/g, '') + '"]'); if (e) e.classList.add('pmos-hint'); });
|
|
86
116
|
setTimeout(function () { Array.prototype.forEach.call(document.querySelectorAll('.pmos-hint'), function (x) { x.classList.remove('pmos-hint'); }); }, 1600);
|
|
87
117
|
} else if (m.t === 'sel') sel(m.el);
|
|
118
|
+
else if (m.t === 'styles') {
|
|
119
|
+
applyStyles(m.styles);
|
|
120
|
+
var se = document.querySelector('.pmos-sel'); if (se) post({ t: 'looks', el: se.getAttribute('data-el') || '', looks: looks(se) });
|
|
121
|
+
}
|
|
88
122
|
else if (m.t === 'pins') pins(m.pins);
|
|
89
123
|
});
|
|
90
124
|
var start = function () {
|
|
91
125
|
var all = screens(); if (all.length) all[0].classList.add('pmos-on');
|
|
92
126
|
var copy = {}; Array.prototype.forEach.call(document.querySelectorAll('[data-copy]'), function (x) { var k = x.getAttribute('data-copy'); if (!(k in copy)) copy[k] = (x.textContent || '').trim(); });
|
|
93
|
-
post({ t: 'ready', screens: all.map(function (s) { return { id: s.getAttribute('data-screen'), label: s.getAttribute('data-label') || '' }; }),
|
|
127
|
+
post({ t: 'ready', screens: all.map(function (s) { return { id: s.getAttribute('data-screen'), label: s.getAttribute('data-label') || '', page: s.getAttribute('data-page') || '' }; }),
|
|
94
128
|
els: Array.prototype.map.call(document.querySelectorAll('[data-el]'), function (e) { return info(e); }), copy: copy });
|
|
95
129
|
};
|
|
96
130
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start); else start();
|