create-pmos 0.594.0 → 0.595.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 +26 -14
- 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 +25 -0
- package/workspace/fixtures/transcript-task-tools.jsonl +5 -0
- package/workspace/guide/notes.md +2 -2
- package/workspace/guide/scheduled-tasks-and-cli.md +3 -1
- package/workspace/guide/settings-and-switches.md +20 -1
- package/workspace/lib/calendar-events.js +5 -1
- package/workspace/lib/goal-chat.js +1 -1
- package/workspace/lib/refresh-run.js +23 -9
- package/workspace/lib/refresh.js +64 -19
- package/workspace/lib/schedule-cli.js +2 -2
- package/workspace/lib/schedule-logic.js +8 -2
- package/workspace/lib/transcript-steps.js +66 -17
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-ev.css +27 -0
- package/workspace/public/pm/cozy-evmodel.js +45 -6
- package/workspace/public/pm/cozy-schedwork.js +201 -0
- package/workspace/public/pm/cozy-settings.js +12 -4
- package/workspace/public/pm/cozy-vw-mtg.css +3 -0
- package/workspace/public/pm/premium-vw-doc.css +0 -3
- package/workspace/public/pm/small-vw.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.595.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,31 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.595.0",
|
|
38
|
+
"at": "2026-11-18T02:36:22.728Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1336,
|
|
43
|
+
"t": "Keep the meeting share popover's cozy fonts out of the console type check",
|
|
44
|
+
"s": "Keep the meeting share popover's cozy fonts out of the console type check",
|
|
45
|
+
"k": "fix"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"n": 1334,
|
|
49
|
+
"t": "Show a session's task list from TaskCreate/TaskUpdate",
|
|
50
|
+
"s": "Show a session's task list from TaskCreate/TaskUpdate",
|
|
51
|
+
"k": "fix"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"n": 1337,
|
|
55
|
+
"t": "Scheduled work shows how often and when next, and the PM sets it",
|
|
56
|
+
"s": "Scheduled work shows how often and when next, and the PM sets it",
|
|
57
|
+
"k": "new"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
},
|
|
36
61
|
{
|
|
37
62
|
"v": "0.594.0",
|
|
38
63
|
"at": "2026-11-18T02:08:44.140Z",
|
|
@@ -285,19 +310,6 @@
|
|
|
285
310
|
"k": "new"
|
|
286
311
|
}
|
|
287
312
|
]
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
"v": "0.575.0",
|
|
291
|
-
"at": "2026-11-16T11:43:16.900Z",
|
|
292
|
-
"f": 4,
|
|
293
|
-
"prs": [
|
|
294
|
-
{
|
|
295
|
-
"n": 1307,
|
|
296
|
-
"t": "A live meeting's agenda as 3 to 5 topics",
|
|
297
|
-
"s": "A live meeting's agenda as 3 to 5 topics",
|
|
298
|
-
"k": "new"
|
|
299
|
-
}
|
|
300
|
-
]
|
|
301
313
|
}
|
|
302
314
|
]
|
|
303
315
|
}
|
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-18T02:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T02:36:19Z"}
|
|
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-18T02:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T02:36:19Z"}
|
|
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-18T02:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T02:36:19Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.595.0",
|
|
4
|
+
"at": "2026-11-18T02:36:22.728Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1336,
|
|
9
|
+
"t": "Keep the meeting share popover's cozy fonts out of the console type check",
|
|
10
|
+
"s": "Keep the meeting share popover's cozy fonts out of the console type check",
|
|
11
|
+
"k": "fix"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"n": 1334,
|
|
15
|
+
"t": "Show a session's task list from TaskCreate/TaskUpdate",
|
|
16
|
+
"s": "Show a session's task list from TaskCreate/TaskUpdate",
|
|
17
|
+
"k": "fix"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"n": 1337,
|
|
21
|
+
"t": "Scheduled work shows how often and when next, and the PM sets it",
|
|
22
|
+
"s": "Scheduled work shows how often and when next, and the PM sets it",
|
|
23
|
+
"k": "new"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
2
27
|
{
|
|
3
28
|
"v": "0.594.0",
|
|
4
29
|
"at": "2026-11-18T02:08:44.140Z",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{"parentUuid":"redacted","isSidechain":false,"message":{"model":"redacted","id":"msg_redacted","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01BbbihWtz7wBTGd7RJMKqcK","name":"TaskCreate","input":{"subject":"Read task tools in transcript-steps","description":"Sample task to capture transcript format","activeForm":"Reading task tools"},"caller":{"type":"direct"}}],"container":null,"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"input_transformations":[],"diagnostics":null,"context_management":null},"toolInputStreamMs":795,"wireToolInputs":{"toolu_01BbbihWtz7wBTGd7RJMKqcK":{"subject":"Read task tools in transcript-steps","description":"Sample task to capture transcript format","activeForm":"Reading task tools"}},"serverClassifierRequest":"d9033f24-83f8-4a76-b09d-7e249cbe86e5","apiBlockIndex":1,"requestId":"redacted","requestedModel":"redacted","promptCacheRequested":"1h","type":"assistant","uuid":"redacted","timestamp":"2026-11-18T01:34:36.493Z","advisorModel":"redacted","effort":"medium","perTurnEffort":"medium","madeBy":"model","userType":"external","entrypoint":"remote_projects","cwd":"redacted","sessionId":"redacted","version":"2.1.327","gitBranch":"redacted"}
|
|
2
|
+
{"parentUuid":"redacted","isSidechain":false,"promptId":"redacted","type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_01BbbihWtz7wBTGd7RJMKqcK","type":"tool_result","content":"Task #1 created successfully: Read task tools in transcript-steps"}]},"uuid":"redacted","timestamp":"2026-11-18T01:34:36.520Z","toolUseResult":{"task":{"id":"1","subject":"Read task tools in transcript-steps","description":"Sample task to capture transcript format"}},"sourceToolAssistantUUID":"cd69d7d8-babd-4368-aed7-d684da36c322","permissionDecision":{"decision":"accept","source":"config"},"userType":"external","entrypoint":"remote_projects","cwd":"redacted","sessionId":"redacted","version":"2.1.327","gitBranch":"redacted"}
|
|
3
|
+
{"parentUuid":"redacted","isSidechain":false,"message":{"model":"redacted","id":"msg_redacted","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01GbD6GBFPq5HquRTySNf94c","name":"TaskUpdate","input":{"taskId":"1","status":"in_progress"},"caller":{"type":"direct"}}],"container":null,"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"input_transformations":[],"diagnostics":null,"context_management":null},"toolInputStreamMs":351,"wireToolInputs":{"toolu_01GbD6GBFPq5HquRTySNf94c":{"taskId":"1","status":"in_progress"}},"serverClassifierRequest":"5d9e04b1-b67c-49a5-bc34-82de33755a60","apiBlockIndex":0,"requestId":"redacted","requestedModel":"redacted","promptCacheRequested":"1h","type":"assistant","uuid":"redacted","timestamp":"2026-11-18T01:34:37.520Z","advisorModel":"redacted","effort":"medium","perTurnEffort":"medium","madeBy":"model","userType":"external","entrypoint":"remote_projects","cwd":"redacted","sessionId":"redacted","version":"2.1.327","gitBranch":"redacted"}
|
|
4
|
+
{"parentUuid":"redacted","isSidechain":false,"promptId":"redacted","type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_01GbD6GBFPq5HquRTySNf94c","type":"tool_result","content":"Updated task #1 status"}]},"uuid":"redacted","timestamp":"2026-11-18T01:34:37.550Z","toolUseResult":{"success":true,"taskId":"1","updatedFields":["status"],"statusChange":{"from":"pending","to":"in_progress"}},"sourceToolAssistantUUID":"6f18e661-8949-4b89-8fe8-1ea270973df2","permissionDecision":{"decision":"accept","source":"config"},"userType":"external","entrypoint":"remote_projects","cwd":"redacted","sessionId":"redacted","version":"2.1.327","gitBranch":"redacted"}
|
|
5
|
+
{"parentUuid":"redacted","isSidechain":false,"message":{"model":"redacted","id":"msg_redacted","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_redacted_bash","name":"Bash","input":{"command":"ls"},"caller":{"type":"direct"}}],"container":null,"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"input_transformations":[],"diagnostics":null,"context_management":null},"toolInputStreamMs":351,"wireToolInputs":{"toolu_01GbD6GBFPq5HquRTySNf94c":{"taskId":"1","status":"in_progress"}},"serverClassifierRequest":"5d9e04b1-b67c-49a5-bc34-82de33755a60","apiBlockIndex":0,"requestId":"redacted","requestedModel":"redacted","promptCacheRequested":"1h","type":"assistant","uuid":"redacted","timestamp":"2026-11-18T01:34:37.520Z","advisorModel":"redacted","effort":"medium","perTurnEffort":"medium","madeBy":"model","userType":"external","entrypoint":"remote_projects","cwd":"redacted","sessionId":"redacted","version":"2.1.327","gitBranch":"redacted"}
|
package/workspace/guide/notes.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Notes: record a meeting, and present while it records"
|
|
4
4
|
description: "Record a meeting on this machine, the notes caught and checked, presenting while it records, and the Chrome extension over Google Meet."
|
|
5
|
-
timestamp: 2026-11-
|
|
5
|
+
timestamp: 2026-11-18
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Notes
|
|
@@ -395,7 +395,7 @@ To take notes for a calendar event, open the meeting from Your day or the calend
|
|
|
395
395
|
|
|
396
396
|
You can share a meeting note with people who do not use PMOS. They get a read-only page. Nothing is sent for you.
|
|
397
397
|
|
|
398
|
-
1. Open a meeting that has notes. Press the share icon, next to **⋯**.
|
|
398
|
+
1. Open a meeting that has notes. Press the share icon, next to **⋯**. A popover opens under it, in the same fonts and colours as the meeting page.
|
|
399
399
|
2. Under **What goes out**, PMOS turns on Summary, Decisions, Next steps and Questions. Facts mentioned and Since the last one stay off. Press a chip to change it. The transcript, the recording and the screen shots never go out.
|
|
400
400
|
3. The **✦** row tells you what PMOS kept back. Press it to see the list:
|
|
401
401
|
- **Stays inside**: your own to-dos and rules, and lines about a team or a person who was not in the meeting. Press the eye on a line to let it go out.
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Scheduled tasks"
|
|
4
4
|
description: "How scheduled tasks run a skill in a terminal session, and their limits."
|
|
5
|
-
timestamp: 2026-11-
|
|
5
|
+
timestamp: 2026-11-18
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Scheduled tasks
|
|
9
9
|
|
|
10
10
|
A scheduled task runs a skill at a set time. The workspace starts a terminal session in the repository and types the skill into it.
|
|
11
11
|
|
|
12
|
+
A task repeats every hour (at the minute of its time), every day, every week, every 2 weeks or every month, or runs once. Settings › Connectors › **Scheduled work** lists your tasks with their next run, and each task's page turns it on or off, changes how often it repeats and runs it now.
|
|
13
|
+
|
|
12
14
|
## Limits
|
|
13
15
|
|
|
14
16
|
A schedule fires only while the workspace server runs. If the server is stopped, the workspace skips the missed slot. It does not catch up later. A one-time task has a 15-minute grace window.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Settings, switches and data freshness"
|
|
4
4
|
description: "What each section of Settings holds, every PMOS_ environment variable, and how the workspace keeps each source up to date."
|
|
5
|
-
timestamp: 2026-11-
|
|
5
|
+
timestamp: 2026-11-18
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Settings, switches and data freshness
|
|
@@ -331,6 +331,25 @@ On Home, the Board and Intelligence, the sources list is in **Settings › Conne
|
|
|
331
331
|
- A row that is well shows its name and when PMOS last read it, for example **Initiatives** · 3 h ago. A source that is old shows ↻ too, while PMOS reads it again by itself. When a read found nothing new, the row says **Checked 10:42 · same since 09:15**.
|
|
332
332
|
- PMOS's background work that failed, and Git sync when it fails, are rows of the same list. A failed read of a source is the reason on that source's row.
|
|
333
333
|
|
|
334
|
+
### Scheduled work: how often and when next
|
|
335
|
+
|
|
336
|
+
A source that PMOS reads on a schedule says how often and when it reads next on its row, for example **Calendar** · Every 30 min in working hours · next 10:00. When PMOS missed a read, because PMOS was not running or the computer slept, the row is amber and says when, for example **Read yesterday 17:31 · missed 09:00**, with ↻ to read it now. A source on time has no colour.
|
|
337
|
+
|
|
338
|
+
Press › on a row to open its page:
|
|
339
|
+
|
|
340
|
+
| Row | What it does |
|
|
341
|
+
|---|---|
|
|
342
|
+
| Active | On or off. Off: PMOS does not read it on its own. |
|
|
343
|
+
| Next run | When PMOS reads it next. |
|
|
344
|
+
| Repeats | Only when you press read, every 15 min, 30 min, hour, 2 hours or 4 hours, every day, working days, or once a week. A day-based choice has **At** (and **On** for once a week). |
|
|
345
|
+
| Working hours only | For the every-N choices: read only inside your working hours. |
|
|
346
|
+
| History | The last five runs, with the result. |
|
|
347
|
+
| ▶ | Read it now. |
|
|
348
|
+
|
|
349
|
+
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
|
+
|
|
351
|
+
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.
|
|
352
|
+
|
|
334
353
|
When all is well, there is no other line. ↻ in the Connectors header is **Refresh all**. The (i) button says what PMOS reads and that it never posts. The switches for what PMOS reads on its own, and the other connectors of your Claude session, are folded into one row: open it to see them. 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).
|
|
335
354
|
|
|
336
355
|
### When a source cannot be read: PMOS repairs it first
|
|
@@ -119,4 +119,8 @@ const eventsOn = (events, day) => listOf(events).filter((e) => e.date === day);
|
|
|
119
119
|
/** Today's meetings (the Record menu): eventsOn the local day of `now`. */
|
|
120
120
|
const todayOf = (events, now = Date.now()) => eventsOn(events, localDate(now));
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
/** How many meetings the local day of `dayMs` has: timed events shorter than 12 hours (an all-day event is not a meeting). The meeting-day
|
|
123
|
+
* rhythm of Settings › Connectors reads it (lib/refresh.js `busy`, batch 31 item 2). Pure. */
|
|
124
|
+
const meetingsOn = (events, dayMs) => eventsOn(events, localDate(dayMs)).filter((e) => e.minutes > 0 && e.minutes < 720).length;
|
|
125
|
+
|
|
126
|
+
module.exports = { readAll, oneEach, asEvent, localIso, todayOf, eventsOn, listOf, menuShape, meetingsOn };
|
|
@@ -72,7 +72,7 @@ function startMessage(draft) {
|
|
|
72
72
|
JSON.stringify(draft),
|
|
73
73
|
'Do whatever the goal needs, as the PM would. Do not stop to ask for approval, feedback or a choice: pick the sensible option yourself, say in one line what you chose, and go on. Merging follows the PM\'s standing rule (merge once required CI is green).',
|
|
74
74
|
'Stop for the PM only when the work cannot go on without them: a sign-in or secret only they have, or a message that goes to other people. Then do every other open point first, and end with needs-you and exactly what you need.',
|
|
75
|
-
'Keep your to-do list (TodoWrite) as the done points, word for word, one item each. Mark the one you work on in_progress, and mark it completed the moment it is met, so the PM sees each point tick as you go.',
|
|
75
|
+
'Keep your to-do list (TodoWrite, or TaskCreate and TaskUpdate) as the done points, word for word, one item each. Mark the one you work on in_progress, and mark it completed the moment it is met, so the PM sees each point tick as you go.',
|
|
76
76
|
'At the end of each message about this goal, add a fenced pmos-goal block: {"step":"progress","state":"working|done|needs-you","met":["done points met"],"open":["done points still open"]}. Copy each done point word for word. Report done only after you checked every point.',
|
|
77
77
|
// batch 22 item 13 (Wawan, 2026-11-01): "6 of 6 met" while the report the goal asked for was only proposed
|
|
78
78
|
'A done point that names a thing to make (a report, slides, a deck, a document) is met only when that thing exists where the PM reads it, opened and checked by you. A proposal, a plan or a draft waiting for a PM press does not meet it: that point stays open, and you end with needs-you and the one press.',
|
|
@@ -91,6 +91,17 @@ function create(host) {
|
|
|
91
91
|
}
|
|
92
92
|
const win = () => { const d = (host.proactive() || {}).dayCheck || {}; return { start: d.start || '08:00', end: d.end || '18:00' }; };
|
|
93
93
|
const quiet = () => { const q = (host.proactive() || {}).quiet; return q && q.start && q.end ? q : null; };
|
|
94
|
+
// batch 31 item 2: how many meetings a day has (the meeting-day rhythm of a schedule with `busy`); none when the host cannot say
|
|
95
|
+
// The calendar files of the state dir (lib/calendar-events.js) are read at most once a minute; a host may answer instead (tests).
|
|
96
|
+
let calAt = 0, calEvents = [];
|
|
97
|
+
const busyDay = (dayMs) => {
|
|
98
|
+
try {
|
|
99
|
+
if (host.busyDay) return Number(host.busyDay(dayMs)) || 0;
|
|
100
|
+
const CE = require('./calendar-events.js'), t = now();
|
|
101
|
+
if (Math.abs(t - calAt) > 60000) { calAt = t; try { calEvents = CE.readAll(dir, { now: t }); } catch { calEvents = []; } }
|
|
102
|
+
return CE.meetingsOn(calEvents, dayMs);
|
|
103
|
+
} catch { return 0; }
|
|
104
|
+
};
|
|
94
105
|
const log = () => R.foldLog(R.readLog(dir));
|
|
95
106
|
/* self-heal (feedback batch 26 item 7): one repair record per skill source that reads a tool, in <state>/source-heal.json */
|
|
96
107
|
const healFile = () => path.join(dir, H.FILE);
|
|
@@ -109,7 +120,7 @@ function create(host) {
|
|
|
109
120
|
if (st.waiting_since || st.pending) return 'waiting';
|
|
110
121
|
const src = R.BY_ID.get(id);
|
|
111
122
|
if (src && src.run === 'skill') {
|
|
112
|
-
const slot = R.lastSlot(x.s, t, win());
|
|
123
|
+
const slot = R.lastSlot(x.s, t, win(), busyDay);
|
|
113
124
|
if (slot != null && (st.last_slot == null || slot > st.last_slot) && t - slot < 2 * 3600 * 1000) return 'due';
|
|
114
125
|
}
|
|
115
126
|
return 'ok';
|
|
@@ -297,7 +308,7 @@ function create(host) {
|
|
|
297
308
|
for (const src of R.SOURCES.filter((x) => x.run === 'skill')) {
|
|
298
309
|
const cur = R.readState(dir);
|
|
299
310
|
const st = { ...(cur[src.id] || {}), running: running(cur[src.id]) };
|
|
300
|
-
const d = R.decide(src, st, { now: t, settings: set, rules, win: win(), quiet: quiet(), runningCount: runningCount(cur), inputState: inputStateFn(set, cur, t), first });
|
|
311
|
+
const d = R.decide(src, st, { now: t, settings: set, rules, win: win(), busyDay, quiet: quiet(), runningCount: runningCount(cur), inputState: inputStateFn(set, cur, t), first });
|
|
301
312
|
if (d.act === 'none') continue;
|
|
302
313
|
const ws = (set.sources[src.id] && set.sources[src.id].ws) || (st.pending && st.pending.ws) || host.homeWs();
|
|
303
314
|
if (d.act === 'skip') {
|
|
@@ -372,7 +383,7 @@ function create(host) {
|
|
|
372
383
|
const due = [];
|
|
373
384
|
for (const src of R.SOURCES.filter((x) => x.run === 'skill' && x.group === 'tools')) {
|
|
374
385
|
const st = { ...(cur[src.id] || {}), running: running(cur[src.id]) };
|
|
375
|
-
const d = R.decide(src, st, { now: t, settings: set, rules, win: win(), quiet: quiet(), runningCount: runningCount(cur), inputState: inputStateFn(set, cur, t), first });
|
|
386
|
+
const d = R.decide(src, st, { now: t, settings: set, rules, win: win(), busyDay, quiet: quiet(), runningCount: runningCount(cur), inputState: inputStateFn(set, cur, t), first });
|
|
376
387
|
if (d.act === 'start' && AUTO.has(d.trigger) && !d.pressed) due.push({ src, d, ws: (set.sources[src.id] && set.sources[src.id].ws) || host.homeWs() });
|
|
377
388
|
}
|
|
378
389
|
const byWs = new Map();
|
|
@@ -491,8 +502,8 @@ function create(host) {
|
|
|
491
502
|
if (id === 'repo' && typeof patch.on === 'boolean') { try { host.setRepoWatch(patch.on); } catch (e) { warn('repository watch', e); } }
|
|
492
503
|
R.writeSettings(dir, set);
|
|
493
504
|
// A schedule change starts the clock from now: a slot that passed before the change is not run late.
|
|
494
|
-
if (norm && id !== 'daycheck') { const st = R.readState(dir); const sl = R.lastSlot(norm.s, now(), win()); st[id] = { ...(st[id] || {}), last_slot: sl, retry_at: null }; R.writeState(dir, st); }
|
|
495
|
-
if (patch.on === true && src.run === 'skill') { const st = R.readState(dir); const sl = R.lastSlot(cur.s, now(), win()); st[id] = { ...(st[id] || {}), last_slot: sl }; R.writeState(dir, st); }
|
|
505
|
+
if (norm && id !== 'daycheck') { const st = R.readState(dir); const sl = R.lastSlot(norm.s, now(), win(), busyDay); st[id] = { ...(st[id] || {}), last_slot: sl, retry_at: null }; R.writeState(dir, st); }
|
|
506
|
+
if (patch.on === true && src.run === 'skill') { const st = R.readState(dir); const sl = R.lastSlot(cur.s, now(), win(), busyDay); st[id] = { ...(st[id] || {}), last_slot: sl }; R.writeState(dir, st); }
|
|
496
507
|
return { ok: true, source: id };
|
|
497
508
|
}
|
|
498
509
|
function setRules(patch) {
|
|
@@ -508,7 +519,7 @@ function create(host) {
|
|
|
508
519
|
if (id === 'brief' && set.sources.tools && !set.sources.tools.on) { set.sources.tools.on = true; if (ws && !set.sources.tools.ws) set.sources.tools.ws = ws; }
|
|
509
520
|
set.migrated = true;
|
|
510
521
|
R.writeSettings(dir, set);
|
|
511
|
-
if (!was) { const st = R.readState(dir); st[id] = { ...(st[id] || {}), last_slot: R.lastSlot(cur.s, now(), win()) }; R.writeState(dir, st); }
|
|
522
|
+
if (!was) { const st = R.readState(dir); st[id] = { ...(st[id] || {}), last_slot: R.lastSlot(cur.s, now(), win(), busyDay) }; R.writeState(dir, st); }
|
|
512
523
|
return !was;
|
|
513
524
|
}
|
|
514
525
|
|
|
@@ -587,7 +598,7 @@ function create(host) {
|
|
|
587
598
|
for (const [k, v] of Object.entries(state)) view[k] = { ...v, running: running(v) };
|
|
588
599
|
let fr = []; try { fr = host.freshRows(ws) || []; } catch { fr = []; }
|
|
589
600
|
const fresh = new Map(fr.filter((x) => FRESH_OF[x.id]).map((x) => [x.id, x]));
|
|
590
|
-
return R.rowsOf({ now: t, settings: set, state: view, log: log(), fresh, win: win(), quiet: quiet(), jobSchedule: host.jobSchedule || null, ws });
|
|
601
|
+
return R.rowsOf({ now: t, settings: set, state: view, log: log(), fresh, win: win(), busyDay, quiet: quiet(), jobSchedule: host.jobSchedule || null, ws });
|
|
591
602
|
}
|
|
592
603
|
function rows(ws) { const set = settings(); return { rules: set.rules, quiet: quiet(), window: win(), rows: rowsFor(ws, set, now()) }; }
|
|
593
604
|
/** What lib/freshness.js shows as a skill's schedule, now that the schedule lives here. */
|
|
@@ -595,8 +606,11 @@ function create(host) {
|
|
|
595
606
|
const id = R.SKILL_OF.get(skill); if (!id) return null;
|
|
596
607
|
const set = settings(); const x = set.sources[id]; const st = R.readState(dir)[id] || {};
|
|
597
608
|
const l = log().lastRun(id);
|
|
598
|
-
const next = x.on ? R.nextSlot(x.s, now(), win()) : null;
|
|
599
|
-
|
|
609
|
+
const next = x.on ? R.nextSlot(x.s, now(), win(), busyDay) : null;
|
|
610
|
+
const missed = x.on ? R.missedSlot(x.s, now(), win(), { lastStart: l && l.start_at ? Date.parse(l.start_at) : NaN, running: running(st) || !!st.pending || !!st.waiting_since, busyDay,
|
|
611
|
+
handled: st.last_slot, skipped: (slot) => log().runs(id, 5).some((y) => y.result === 'skipped' && Date.parse(y.start_at) >= slot) }) : null;
|
|
612
|
+
// batch 31 item 2: `refresh` names the Settings › Connectors item page; `missed_at` turns the row line amber and shows ↻
|
|
613
|
+
return { refresh: id, cadence: x.on ? R.textOf(x.s) : 'off', time: null, day: null, next_run: next ? new Date(next).toISOString() : null, missed_at: missed ? new Date(missed).toISOString() : null,
|
|
600
614
|
last_run: l ? l.start_at : null, last_status: l ? (l.result === 'failed' ? 'fail' : l.result === 'done' ? 'ok' : 'started') : st.last_result || null,
|
|
601
615
|
checked_at: st.seen && st.seen.at ? new Date(st.seen.at).toISOString() : null,
|
|
602
616
|
same_since: st.seen && st.seen.since && st.seen.at > st.seen.since ? new Date(st.seen.since).toISOString() : null };
|
package/workspace/lib/refresh.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* THE SETTINGS. <state>/refresh.json: { sources: { id: { on, s, ws } }, rules, migrated }. `s` is the schedule of a skill source:
|
|
9
9
|
* { kind: 'manual' } only when the PM presses Refresh
|
|
10
|
-
* { kind: 'every', every: '15'..'240', work } every N minutes from midnight; `work` keeps it inside the background working hours
|
|
10
|
+
* { kind: 'every', every: '15'..'240', work, busy? } every N minutes from midnight; `work` keeps it inside the background working hours;
|
|
11
|
+
* `busy` { every, meetings } reads more often on a day with that many meetings or more (batch 31 item 2:
|
|
12
|
+
* the ✦ "Read it more often on meeting days" the PM approves; the meeting count is host.busyDay)
|
|
11
13
|
* { kind: 'daily' | 'weekdays', times: ['HH:MM', …] } one to four times a day (weekdays: Monday to Friday)
|
|
12
14
|
* { kind: 'weekly', day: 'Mon'..'Sun', times: ['HH:MM'] }
|
|
13
15
|
* A job source keeps only `on` here; the day check's minutes live in the proactive settings (dayCheck.every), their one home.
|
|
@@ -33,6 +35,7 @@ const WAIT_MS = 30 * 60 * 1000; // a refresh waits at most this long fo
|
|
|
33
35
|
const LATE_MS = 15 * 60 * 1000; // a slot older than this when first seen was missed (PMOS was closed)
|
|
34
36
|
const FIRST_MS = 2 * 3600 * 1000; // harness-health: a scheduled run first refreshes its skill inputs whose last good read is older than this
|
|
35
37
|
const MAX_TIMES = 4;
|
|
38
|
+
const BUSY_MEETINGS = 3; // a meeting day: this many meetings or more (the ✦ rhythm proposal, batch 31 item 2)
|
|
36
39
|
|
|
37
40
|
/* The sources. `fresh` names the lib/freshness.js row whose age and detail this source shares; `copy` names the files a done run keeps. */
|
|
38
41
|
const SOURCES = Object.freeze([
|
|
@@ -121,7 +124,14 @@ function normalize(src, s) {
|
|
|
121
124
|
if (s.kind === 'manual') return { ok: true, s: { kind: 'manual' } };
|
|
122
125
|
if (s.kind === 'every') {
|
|
123
126
|
if (!EVERY.includes(String(s.every))) return { ok: false, error: 'every must be one of ' + EVERY.join(', ') + ' (minutes)' };
|
|
124
|
-
|
|
127
|
+
const out = { kind: 'every', every: String(s.every), work: !!s.work };
|
|
128
|
+
if (s.busy != null) {
|
|
129
|
+
const b = s.busy, n = Number(b && b.meetings);
|
|
130
|
+
if (!b || typeof b !== 'object' || !EVERY.includes(String(b.every))) return { ok: false, error: 'busy.every must be one of ' + EVERY.join(', ') + ' (minutes)' };
|
|
131
|
+
if (!(Number.isInteger(n) && n >= 1 && n <= 12)) return { ok: false, error: 'busy.meetings must be a whole number from 1 to 12' };
|
|
132
|
+
if (Number(b.every) < Number(out.every)) out.busy = { every: String(b.every), meetings: n }; // a busy rhythm slower than the usual one adds nothing
|
|
133
|
+
}
|
|
134
|
+
return { ok: true, s: out };
|
|
125
135
|
}
|
|
126
136
|
const times = cleanTimes(s.times);
|
|
127
137
|
if (!times.length) return { ok: false, error: 'times must hold one to four HH:MM times (24-hour)' };
|
|
@@ -138,11 +148,13 @@ const dayStart = (ms) => { const d = new Date(ms); d.setHours(0, 0, 0, 0); retur
|
|
|
138
148
|
const addDays = (ms, n) => { const d = new Date(ms); d.setDate(d.getDate() + n); return d.getTime(); };
|
|
139
149
|
const dayOk = (s, ms) => { const d = new Date(ms).getDay(); return s.kind === 'weekdays' ? d >= 1 && d <= 5 : s.kind === 'weekly' ? DAYS[d] === s.day : true; };
|
|
140
150
|
|
|
141
|
-
/** The slots of one day, in ms, ascending. `win` is { start, end } HH:MM, the background working hours.
|
|
142
|
-
|
|
151
|
+
/** The slots of one day, in ms, ascending. `win` is { start, end } HH:MM, the background working hours. `busyDay(dayMs)` → how many
|
|
152
|
+
* meetings that day has (a schedule with `busy` steps by busy.every on a day with busy.meetings or more). */
|
|
153
|
+
function slotsOfDay(s, dayMs, win, busyDay) {
|
|
143
154
|
if (!s || s.kind === 'manual') return [];
|
|
144
155
|
if (s.kind === 'every') {
|
|
145
|
-
const
|
|
156
|
+
const busy = s.busy && busyDay && (Number(busyDay(dayStart(dayMs))) || 0) >= s.busy.meetings;
|
|
157
|
+
const step = Number(busy ? s.busy.every : s.every) || 60; const out = [];
|
|
146
158
|
const lo = s.work && win ? minutesOf(win.start) : 0; const hi = s.work && win ? minutesOf(win.end) : 24 * 60;
|
|
147
159
|
for (let m = 0; m < 24 * 60; m += step) if (m >= lo && m < hi) out.push(dayStart(dayMs) + m * 60000);
|
|
148
160
|
// A clock change can shift a day; dayStart + minutes is near enough for minute slots.
|
|
@@ -152,23 +164,50 @@ function slotsOfDay(s, dayMs, win) {
|
|
|
152
164
|
return cleanTimes(s.times).map((t) => at(dayMs, t));
|
|
153
165
|
}
|
|
154
166
|
/** The most recent slot at or before `now`, in ms, or null (none in the last 8 days). */
|
|
155
|
-
function lastSlot(s, now, win) {
|
|
167
|
+
function lastSlot(s, now, win, busyDay) {
|
|
156
168
|
for (let k = 0; k < 8; k++) {
|
|
157
169
|
const day = addDays(dayStart(now), -k);
|
|
158
|
-
const hits = slotsOfDay(s, day, win).filter((x) => x <= now);
|
|
170
|
+
const hits = slotsOfDay(s, day, win, busyDay).filter((x) => x <= now);
|
|
159
171
|
if (hits.length) return hits[hits.length - 1];
|
|
160
172
|
}
|
|
161
173
|
return null;
|
|
162
174
|
}
|
|
163
175
|
/** The next slot strictly after `now`, in ms, or null. */
|
|
164
|
-
function nextSlot(s, now, win) {
|
|
176
|
+
function nextSlot(s, now, win, busyDay) {
|
|
165
177
|
for (let k = 0; k < 9; k++) {
|
|
166
178
|
const day = addDays(dayStart(now), k);
|
|
167
|
-
const hit = slotsOfDay(s, day, win).find((x) => x > now);
|
|
179
|
+
const hit = slotsOfDay(s, day, win, busyDay).find((x) => x > now);
|
|
168
180
|
if (hit != null) return hit;
|
|
169
181
|
}
|
|
170
182
|
return null;
|
|
171
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* The slot PMOS missed, in ms, or null (batch 31 item 2: the amber line and ↻ show only then). The newest slot more than LATE_MS old is
|
|
186
|
+
* missed when nothing is running, no run started at or after it, and the PM's own change did not pass it (turning the source on or a new
|
|
187
|
+
* schedule moves last_slot without a run; a slot the tick skipped stays missed): PMOS was closed or the computer slept, or the slot was skipped.
|
|
188
|
+
*/
|
|
189
|
+
function missedSlot(s, now, win, { lastStart, running, busyDay, handled, skipped } = {}) {
|
|
190
|
+
if (!s || s.kind === 'manual' || running) return null;
|
|
191
|
+
const slot = lastSlot(s, now - LATE_MS, win, busyDay); // the newest slot the tick has had its 15 minutes to start
|
|
192
|
+
if (slot == null) return null;
|
|
193
|
+
if (Number.isFinite(lastStart) && lastStart >= slot - 60000) return null;
|
|
194
|
+
// `handled` is the state's last_slot: a slot the PM's own change passed (turned on, a new schedule) is not missed; one the tick skipped is
|
|
195
|
+
if (Number.isFinite(handled) && handled >= slot && !(skipped && skipped(slot))) return null;
|
|
196
|
+
return slot;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* PMOS's ✦ rhythm proposal for a source, or null (batch 31 item 2, agreed design SwC). Calendar on an every-N schedule slower than
|
|
200
|
+
* 15 min, with no meeting-day rhythm yet, on a day with BUSY_MEETINGS meetings or more: read it every 15 min on such days.
|
|
201
|
+
* → { every, meetings, today, s } where `s` is the whole schedule the PM's ✓ saves.
|
|
202
|
+
*/
|
|
203
|
+
function proposalOf(src, set, now, busyDay) {
|
|
204
|
+
if (!src || src.id !== 'calendar' || !set || !set.on || !busyDay) return null;
|
|
205
|
+
const s = set.s;
|
|
206
|
+
if (!s || s.kind !== 'every' || s.busy || Number(s.every) <= 15) return null;
|
|
207
|
+
const today = Number(busyDay(dayStart(now))) || 0;
|
|
208
|
+
if (today < BUSY_MEETINGS) return null;
|
|
209
|
+
return { every: '15', meetings: BUSY_MEETINGS, today, s: { ...s, busy: { every: '15', meetings: BUSY_MEETINGS } } };
|
|
210
|
+
}
|
|
172
211
|
const inWindow = (now, win) => { if (!win) return true; const d = new Date(now); const m = d.getHours() * 60 + d.getMinutes(); return m >= minutesOf(win.start) && m < minutesOf(win.end); };
|
|
173
212
|
function inQuiet(now, quiet) {
|
|
174
213
|
if (!quiet || !quiet.start || !quiet.end) return false;
|
|
@@ -287,7 +326,7 @@ function decide(src, st, ctx) {
|
|
|
287
326
|
if (st.pending) return gateInputs(src, st, ctx, { trigger: st.pending.trigger || 'pressed', pressed: true });
|
|
288
327
|
// A retry of a failed run.
|
|
289
328
|
if (st.retry_at && now >= st.retry_at) return gateInputs(src, st, ctx, { trigger: 'retry', slot: st.last_slot || null });
|
|
290
|
-
const slot = lastSlot(set.s, now, ctx.win);
|
|
329
|
+
const slot = lastSlot(set.s, now, ctx.win, ctx.busyDay);
|
|
291
330
|
if (slot == null) return { act: 'none', why: 'no slot' };
|
|
292
331
|
if (st.last_slot != null && st.last_slot >= slot) return { act: 'none', why: 'done' };
|
|
293
332
|
// A slot from before the last start (a run pressed after it) is done too.
|
|
@@ -345,10 +384,11 @@ function sourceOfOrigin(origin, { skillOfSchedule } = {}) {
|
|
|
345
384
|
/* ── rows for the page ── */
|
|
346
385
|
/**
|
|
347
386
|
* One row per source for GET /api/refresh. → [row]
|
|
348
|
-
* opts { now, settings, state, log (folded: lastRun(id), runs(id, n)), fresh (Map id → freshness row), win, quiet, jobSchedule(id) → text|null, ws
|
|
387
|
+
* opts { now, settings, state, log (folded: lastRun(id), runs(id, n)), fresh (Map id → freshness row), win, quiet, jobSchedule(id) → text|null, ws,
|
|
388
|
+
* busyDay(dayMs) → meetings that day }
|
|
349
389
|
*/
|
|
350
390
|
function rowsOf(opts) {
|
|
351
|
-
const { now, settings, state, log, fresh, win } = opts;
|
|
391
|
+
const { now, settings, state, log, fresh, win, busyDay } = opts;
|
|
352
392
|
const rows = SOURCES.map((src) => {
|
|
353
393
|
const set = settings.sources[src.id]; const st = state[src.id] || {};
|
|
354
394
|
const last = log.lastRun(src.id);
|
|
@@ -363,8 +403,11 @@ function rowsOf(opts) {
|
|
|
363
403
|
else if (fr && fr.state === 'failed') stateName = 'failed';
|
|
364
404
|
else if (fr && fr.state === 'stale') stateName = 'old';
|
|
365
405
|
else if (!lastAt) stateName = 'never';
|
|
366
|
-
else stateName = staleOf(src, set, lastAt, now, win) ? 'old' : 'recent';
|
|
367
|
-
const next = set.on && src.run === 'skill' ? nextSlot(set.s, now, win) : null;
|
|
406
|
+
else stateName = staleOf(src, set, lastAt, now, win, busyDay) ? 'old' : 'recent';
|
|
407
|
+
const next = set.on && src.run === 'skill' ? nextSlot(set.s, now, win, busyDay) : null;
|
|
408
|
+
const lastStart = last && last.start_at ? Date.parse(last.start_at) : NaN;
|
|
409
|
+
const skipped = (slot) => (log.runs(src.id, 5) || []).some((x) => x.result === 'skipped' && Date.parse(x.start_at) >= slot);
|
|
410
|
+
const missed = set.on && src.run === 'skill' ? missedSlot(set.s, now, win, { lastStart, running: stateName === 'running' || stateName === 'waiting', busyDay, handled: st.last_slot, skipped }) : null;
|
|
368
411
|
return {
|
|
369
412
|
id: src.id, label: src.label, group: src.group, ic: src.ic, run: src.run, how: src.how, what: src.what, uses: src.uses.slice(), used_by: usedBy(src.id), impact: src.impact,
|
|
370
413
|
on: set.on, schedule: src.run === 'skill' || src.id === 'daycheck' ? set.s : null, default: src.def || null, ws: set.ws,
|
|
@@ -375,6 +418,8 @@ function rowsOf(opts) {
|
|
|
375
418
|
last: last ? { at: lastAt, start_at: last.start_at, result: last.result || (last.end_at ? 'done' : null), took_ms: last.took_ms != null ? last.took_ms : null,
|
|
376
419
|
got: last.got || (fr && fr.detail) || null, error: last.error || null, trigger: last.trigger || null, note: last.note || null } : (lastAt ? { at: lastAt, got: fr && fr.detail || null } : null),
|
|
377
420
|
next_at: next ? new Date(next).toISOString() : null,
|
|
421
|
+
missed_at: missed ? new Date(missed).toISOString() : null,
|
|
422
|
+
propose: proposalOf(src, set, now, busyDay),
|
|
378
423
|
waiting_for: st.waiting_for || [],
|
|
379
424
|
runs: log.runs(src.id, 5),
|
|
380
425
|
};
|
|
@@ -388,12 +433,12 @@ function rowsOf(opts) {
|
|
|
388
433
|
return rows;
|
|
389
434
|
}
|
|
390
435
|
/** Old: no refresh since the slot before the last one (a skill source), or older than a day (a job). */
|
|
391
|
-
function staleOf(src, set, lastAt, now, win) {
|
|
436
|
+
function staleOf(src, set, lastAt, now, win, busyDay) {
|
|
392
437
|
const t = Date.parse(lastAt); if (!Number.isFinite(t)) return false;
|
|
393
438
|
if (src.run === 'skill') {
|
|
394
439
|
const s = set.s; if (!s || s.kind === 'manual') return now - t > 26 * 3600000;
|
|
395
|
-
const l1 = lastSlot(s, now, win); if (l1 == null) return false;
|
|
396
|
-
const l0 = lastSlot(s, l1 - 1, win);
|
|
440
|
+
const l1 = lastSlot(s, now, win, busyDay); if (l1 == null) return false;
|
|
441
|
+
const l0 = lastSlot(s, l1 - 1, win, busyDay);
|
|
397
442
|
return l0 != null && t < l0;
|
|
398
443
|
}
|
|
399
444
|
if (src.run === 'change') return false;
|
|
@@ -405,7 +450,7 @@ const everyText = (v) => ({ 15: '15 min', 30: '30 min', 60: 'hour', 120: '2 hour
|
|
|
405
450
|
function textOf(s) {
|
|
406
451
|
if (!s) return '';
|
|
407
452
|
if (s.kind === 'manual') return 'Only when you press Refresh';
|
|
408
|
-
if (s.kind === 'every') return 'Every ' + everyText(s.every) + (s.work ? ', working hours only' : '');
|
|
453
|
+
if (s.kind === 'every') return 'Every ' + everyText(s.every) + (s.work ? ', working hours only' : '') + (s.busy ? '; every ' + everyText(s.busy.every) + ' on days with ' + s.busy.meetings + ' or more meetings' : '');
|
|
409
454
|
const t = (s.times || []).join(' and ');
|
|
410
455
|
if (s.kind === 'daily') return 'Daily at ' + t;
|
|
411
456
|
if (s.kind === 'weekdays') return 'Working days at ' + t;
|
|
@@ -526,6 +571,6 @@ function toCsv(runs) {
|
|
|
526
571
|
|
|
527
572
|
module.exports = {
|
|
528
573
|
SOURCES, BY_ID, SKILL_OF, SKILL_KINDS, EVERY, WAIT_MS, LATE_MS, FIRST_MS, RULE_DEFAULTS, RULE_OPTS,
|
|
529
|
-
usedBy, normalize, normalizeRules, withDefaults, migrate, retireLegacy, refreshFirst, lastSlot, nextSlot, slotsOfDay, inWindow, inQuiet, decide, jobGate, sourceOfOrigin, rowsOf, textOf,
|
|
574
|
+
BUSY_MEETINGS, usedBy, normalize, normalizeRules, withDefaults, migrate, retireLegacy, refreshFirst, lastSlot, nextSlot, missedSlot, proposalOf, slotsOfDay, inWindow, inQuiet, decide, jobGate, sourceOfOrigin, rowsOf, textOf,
|
|
530
575
|
files, readSettings, writeSettings, readState, writeState, newRun, append, readLog, foldLog, keepCopy, prune, toCsv,
|
|
531
576
|
};
|
|
@@ -64,7 +64,7 @@ function gitRoot(dir) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
function describe(s) {
|
|
67
|
-
const when = s.cadence === 'once' ? `once, ${s.date || '?'} at ${s.time || '09:00'}`
|
|
67
|
+
const when = s.cadence === 'hourly' ? `every hour at :${String(s.time || '00:00').slice(-2)}` : s.cadence === 'once' ? `once, ${s.date || '?'} at ${s.time || '09:00'}`
|
|
68
68
|
: s.cadence === 'weekly' ? `every ${s.day || 'Mon'} at ${s.time}`
|
|
69
69
|
: s.cadence === 'bi-weekly' ? `every other ${s.day || 'Mon'} at ${s.time}`
|
|
70
70
|
: s.cadence === 'monthly' ? `monthly on day ${s.dayOfMonth || 1} at ${s.time}`
|
|
@@ -155,7 +155,7 @@ async function run(argv, { call, say, cwd = process.cwd() }) {
|
|
|
155
155
|
say(`✓ skill "${created}" written (user skill). Review it: pmos skill show ${created}`);
|
|
156
156
|
}
|
|
157
157
|
if (!f.skill) return fail('say which skill: --skill <name> (pmos skill list), or --from-session / --from-file');
|
|
158
|
-
if (!f.cadence) return fail('say when: --cadence daily|weekly|bi-weekly|monthly|once (with --time HH:MM, --day, --day-of-month or --date)');
|
|
158
|
+
if (!f.cadence) return fail('say when: --cadence hourly|daily|weekly|bi-weekly|monthly|once (with --time HH:MM, --day, --day-of-month or --date)');
|
|
159
159
|
f.name = f.name || (created ? `${created}` : f.skill);
|
|
160
160
|
f.task = f.skill;
|
|
161
161
|
const r = await call('POST', '/api/schedules', { ...f, ws: w.id });
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
* what will fire. Window-based due-ness, NO catch-up (a missed slot is skipped, per the PRD): a
|
|
7
7
|
* schedule is due iff a scheduled slot falls in the interval (lastRun, now].
|
|
8
8
|
*
|
|
9
|
-
* A schedule: { cadence:'daily'|'weekly'|'bi-weekly'|'monthly', day:'Mon'..'Sun' (weekly/bi-weekly),
|
|
9
|
+
* A schedule: { cadence:'hourly'|'daily'|'weekly'|'bi-weekly'|'monthly', day:'Mon'..'Sun' (weekly/bi-weekly),
|
|
10
10
|
* dayOfMonth:1..28 (monthly), time:'HH:MM', enabled, lastRun:ISO|null }. Times are host-local (v1).
|
|
11
|
+
* `hourly` (batch 31 item 2, Scheduled work): every hour at the minute of `time` ('09:15' runs at :15 of every hour).
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; // JS getDay() index
|
|
14
|
-
const CADENCES = ['daily', 'weekly', 'bi-weekly', 'monthly', 'once']; // R11: `once` — one date and time, then it stays off
|
|
15
|
+
const CADENCES = ['hourly', 'daily', 'weekly', 'bi-weekly', 'monthly', 'once']; // R11: `once` — one date and time, then it stays off
|
|
15
16
|
const ONCE_GRACE_MS = 15 * 60 * 1000; // a one-off whose moment passed while nothing was running is MISSED, not caught up
|
|
16
17
|
|
|
17
18
|
function parseTime(t) {
|
|
@@ -25,6 +26,8 @@ function atTime(d, time) {
|
|
|
25
26
|
x.setHours(h, m, 0, 0);
|
|
26
27
|
return x;
|
|
27
28
|
}
|
|
29
|
+
/** This hour of `d`, at the minute of `time`. */
|
|
30
|
+
function atMinute(d, time) { const x = new Date(d); x.setMinutes(parseTime(time).m, 0, 0); return x; }
|
|
28
31
|
function dayIndex(day) { const i = DAYS.indexOf(String(day)); return i < 0 ? 1 : i; } // default Mon
|
|
29
32
|
|
|
30
33
|
// The most recent scheduled slot at or before `now` (Date), or null if none exists yet.
|
|
@@ -37,6 +40,7 @@ function onceSlot(schedule) {
|
|
|
37
40
|
function lastSlot(schedule, now) {
|
|
38
41
|
const cad = schedule.cadence;
|
|
39
42
|
if (cad === 'once') { const o = onceSlot(schedule); return o && o <= now ? o : null; }
|
|
43
|
+
if (cad === 'hourly') { const x = atMinute(now, schedule.time); return x <= now ? x : new Date(x.getTime() - 3600000); }
|
|
40
44
|
if (cad === 'daily') {
|
|
41
45
|
const today = atTime(now, schedule.time);
|
|
42
46
|
return today <= now ? today : addDays(today, -1);
|
|
@@ -63,6 +67,7 @@ function lastSlot(schedule, now) {
|
|
|
63
67
|
function nextSlot(schedule, now) {
|
|
64
68
|
const cad = schedule.cadence;
|
|
65
69
|
if (cad === 'once') { const o = onceSlot(schedule); return o && o > now ? o : null; }
|
|
70
|
+
if (cad === 'hourly') { const x = atMinute(now, schedule.time); return x > now ? x : new Date(x.getTime() + 3600000); }
|
|
66
71
|
if (cad === 'daily') {
|
|
67
72
|
const today = atTime(now, schedule.time);
|
|
68
73
|
return today > now ? today : addDays(today, 1);
|
|
@@ -134,6 +139,7 @@ function nextRun(schedule, now = new Date()) {
|
|
|
134
139
|
function humanCadence(schedule) {
|
|
135
140
|
const t = schedule.time || '09:00';
|
|
136
141
|
switch (schedule.cadence) {
|
|
142
|
+
case 'hourly': return `every hour at :${t.slice(-2)}`;
|
|
137
143
|
case 'daily': return `every day at ${t}`;
|
|
138
144
|
case 'weekly': return `every ${schedule.day || 'Mon'} at ${t}`;
|
|
139
145
|
case 'bi-weekly': return `every other ${schedule.day || 'Mon'} at ${t}`;
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
* readSteps(file, clean, root) → { steps: [{ text, state: done|now|next }] | null, stepsAt, change: { system, what, from, to, tool } | null }
|
|
6
6
|
*
|
|
7
|
-
* steps the
|
|
8
|
-
*
|
|
7
|
+
* steps the session's own plan of its turn, as Claude Code keeps it: the newest TodoWrite list, or the task list built by
|
|
8
|
+
* TaskCreate and TaskUpdate (newer Claude Code), whichever the session wrote last. completed → done, in_progress → now,
|
|
9
|
+
* pending → next; a deleted task leaves the list. A task's id comes from its TaskCreate result ("Task #3 created"),
|
|
10
|
+
* else from creation order. null when the session kept no list: the chat then draws no checklist, never an invented one.
|
|
9
11
|
* A step also carries what the transcript holds about it, and nothing more: a done step that was seen in progress has
|
|
10
12
|
* `sub` ("3 tool calls · 9s", its calls and the time from in progress to completed), and the step in progress has `call`, its
|
|
11
13
|
* newest tool call ("jira.search project = PAY"). Neither is set when the transcript does not show it.
|
|
@@ -74,45 +76,92 @@ function callLine(name, input, clean = (x) => x, root = null) {
|
|
|
74
76
|
}
|
|
75
77
|
const secs = (a, b) => { const t = (Date.parse(b) - Date.parse(a)) / 1000; return Number.isFinite(t) && t >= 0 ? (t < 60 ? Math.round(t) + 's' : t < 3600 ? Math.round(t / 60) + ' min' : Math.floor(t / 3600) + ' h ' + Math.round((t % 3600) / 60) + ' min') : ''; };
|
|
76
78
|
|
|
79
|
+
/** The steps and the open change from a transcript's text. Pure over the text. */
|
|
80
|
+
const TASK_TOOLS = new Set(['TodoWrite', 'TaskCreate', 'TaskUpdate', 'TaskList', 'TaskGet', 'TaskStop', 'AskUserQuestion']);
|
|
81
|
+
const taskIdOf = (c) => {
|
|
82
|
+
const t = c && c.task && c.task.id != null ? String(c.task.id) : '';
|
|
83
|
+
if (t) return t;
|
|
84
|
+
const txt = typeof c === 'string' ? c : Array.isArray(c) ? c.map((x) => (x && x.text) || '').join(' ') : '';
|
|
85
|
+
const m = /Task #(\w+) created/.exec(txt);
|
|
86
|
+
return m ? m[1] : '';
|
|
87
|
+
};
|
|
88
|
+
|
|
77
89
|
/** The steps and the open change from a transcript's text. Pure over the text. */
|
|
78
90
|
function stepsOf(raw, clean = (x) => x, root = null) {
|
|
79
91
|
let todos = null, todosAt = null;
|
|
80
92
|
const open = new Map();
|
|
81
|
-
const seen = new Map(); // a step's
|
|
82
|
-
let doing = null; // the
|
|
93
|
+
const seen = new Map(); // a step's key → { start, end, calls, last }: what the transcript shows of it
|
|
94
|
+
let doing = null; // the key of the step in progress now
|
|
95
|
+
const tasks = new Map(); // TaskCreate/TaskUpdate: task id → { key, content, activeForm, status }, in creation order
|
|
96
|
+
const pending = new Map();// a TaskCreate's tool_use id → the id it was given by creation order, until its result names the real one
|
|
97
|
+
let made = 0;
|
|
98
|
+
// one list, either kind: mark when a step starts and ends, and which step is in progress now
|
|
99
|
+
const take = (list, ts, keyOf) => {
|
|
100
|
+
todos = list; todosAt = ts || null; doing = null;
|
|
101
|
+
for (const t of list) {
|
|
102
|
+
if (!t || !t.content) continue;
|
|
103
|
+
const k = keyOf(t), st = seen.get(k) || {};
|
|
104
|
+
if (t.status === 'in_progress') { if (!st.start) st.start = ts || null; doing = k; }
|
|
105
|
+
if (t.status === 'completed' && st.start && !st.end) st.end = ts || null;
|
|
106
|
+
seen.set(k, st);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const fromTasks = (ts) => take([...tasks.values()].filter((t) => t.status !== 'deleted'), ts, (t) => t.key);
|
|
83
110
|
for (const line of String(raw || '').split('\n')) {
|
|
84
111
|
if (!line) continue;
|
|
85
112
|
let r; try { r = JSON.parse(line); } catch { continue; }
|
|
86
113
|
if (r.isSidechain) continue;
|
|
87
114
|
const content = r.message && Array.isArray(r.message.content) ? r.message.content : [];
|
|
88
|
-
if (r.type === 'user') {
|
|
115
|
+
if (r.type === 'user') {
|
|
116
|
+
for (const c of content) {
|
|
117
|
+
if (!c || c.type !== 'tool_result' || !c.tool_use_id) continue;
|
|
118
|
+
open.delete(c.tool_use_id);
|
|
119
|
+
if (pending.has(c.tool_use_id)) {
|
|
120
|
+
// the result names the task's real id: re-key the task when creation order guessed another one
|
|
121
|
+
const guess = pending.get(c.tool_use_id); pending.delete(c.tool_use_id);
|
|
122
|
+
const real = taskIdOf(r.toolUseResult) || taskIdOf(c.content);
|
|
123
|
+
if (real && real !== guess && tasks.has(guess) && !tasks.has(real)) {
|
|
124
|
+
const next = new Map(); for (const [id, t] of tasks) next.set(id === guess ? real : id, t); tasks.clear(); for (const [id, t] of next) tasks.set(id, t);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
89
130
|
if (r.type !== 'assistant') continue;
|
|
90
131
|
for (const c of content) {
|
|
91
132
|
if (!c || c.type !== 'tool_use') continue;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
133
|
+
const i = c.input && typeof c.input === 'object' ? c.input : {};
|
|
134
|
+
if (c.name === 'TodoWrite' && Array.isArray(i.todos)) {
|
|
135
|
+
take(i.todos, r.timestamp, (t) => String(t.content));
|
|
136
|
+
} else if (c.name === 'TaskCreate' && (i.subject || i.description)) {
|
|
137
|
+
// a task made after every task of the list is done or deleted starts a new list (the result's id re-keys it if needed)
|
|
138
|
+
if (tasks.size && [...tasks.values()].every((t) => t.status === 'completed' || t.status === 'deleted')) tasks.clear();
|
|
139
|
+
made++;
|
|
140
|
+
let id = String(made); while (tasks.has(id)) id = String(++made);
|
|
141
|
+
tasks.set(id, { key: 'task:' + made + ':' + String(i.subject || i.description), content: String(i.subject || i.description), activeForm: i.activeForm || '', status: 'pending' });
|
|
142
|
+
if (c.id) pending.set(c.id, id);
|
|
143
|
+
fromTasks(r.timestamp);
|
|
144
|
+
} else if (c.name === 'TaskUpdate' && i.taskId != null && tasks.has(String(i.taskId))) {
|
|
145
|
+
const t = tasks.get(String(i.taskId));
|
|
146
|
+
if (i.subject) t.content = String(i.subject);
|
|
147
|
+
if (i.activeForm) t.activeForm = String(i.activeForm);
|
|
148
|
+
if (['pending', 'in_progress', 'completed', 'deleted'].includes(i.status)) t.status = i.status;
|
|
149
|
+
fromTasks(r.timestamp);
|
|
150
|
+
} else if (doing && !TASK_TOOLS.has(c.name)) { const st = seen.get(doing); st.calls = (st.calls || 0) + 1; st.last = { name: c.name, input: c.input }; }
|
|
102
151
|
if (c.id) open.set(c.id, { name: c.name, input: c.input });
|
|
103
152
|
}
|
|
104
153
|
}
|
|
105
154
|
const steps = todos ? todos.slice(0, 12).map((t) => {
|
|
106
155
|
const s = { text: clean(cut(t && (t.status === 'in_progress' && t.activeForm ? t.activeForm : t.content), 140)),
|
|
107
156
|
state: t && t.status === 'completed' ? 'done' : t && t.status === 'in_progress' ? 'now' : 'next' };
|
|
108
|
-
const st = t && t.content ? seen.get(String(t.content)) : null;
|
|
157
|
+
const st = t && t.content ? seen.get(t.key || String(t.content)) : null;
|
|
109
158
|
if (st && s.state === 'done' && st.start && st.end) s.sub = [st.calls ? st.calls + (st.calls === 1 ? ' tool call' : ' tool calls') : '', secs(st.start, st.end)].filter(Boolean).join(' · ');
|
|
110
159
|
if (st && s.state === 'now' && st.last) s.call = callLine(st.last.name, st.last.input, clean, root);
|
|
111
160
|
if (!s.sub) delete s.sub;
|
|
112
161
|
return s;
|
|
113
162
|
}).filter((s) => s.text) : null;
|
|
114
163
|
let last = null; for (const [, v] of open) last = v;
|
|
115
|
-
const change = last &&
|
|
164
|
+
const change = last && !TASK_TOOLS.has(last.name) ? changeOf(last.name, last.input, clean, root) : null;
|
|
116
165
|
return { steps: steps && steps.length ? steps : null, stepsAt: todosAt, change };
|
|
117
166
|
}
|
|
118
167
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.595.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.595.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -398,3 +398,30 @@
|
|
|
398
398
|
.cz .ev-ls { display: flex; flex-direction: column; gap: 2px; }
|
|
399
399
|
.cz .ev-ls .ev-ms { color: var(--cz-late); }
|
|
400
400
|
.cz .ev-ls .ev-nx { color: var(--cz-blueink); }
|
|
401
|
+
/* Settings › Connectors › Scheduled work (batch 31 item 2, agreed design SwC; pm/cozy-schedwork.js): the quiet entry, the list, and a
|
|
402
|
+
* job's page like the Claude app's scheduled task: Active, Next run, Repeats in one card, PMOS's ✦ rhythm, History, ▶ Read now */
|
|
403
|
+
.ev-st .ev-sw-ic { color: var(--cz-ink3); display: inline-flex; flex: none; }
|
|
404
|
+
.ev-st .ev-sw-entry .ev-sw-ic { margin-left: -16px; }
|
|
405
|
+
.ev-st .ev-sw-grp { padding: 14px 0 4px; }
|
|
406
|
+
.ev-st .ev-sw-what { margin: 0 0 10px; }
|
|
407
|
+
.ev-st .ev-sw-warn { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 10px; }
|
|
408
|
+
.ev-st .ev-sw-warn .ev-dot { margin-top: 8px; }
|
|
409
|
+
.ev-st .ev-sw-warn p { margin: 0; }
|
|
410
|
+
.ev-st .ev-sw-card { background: var(--cz-card); border: 1px solid var(--cz-hair); border-radius: 16px; padding: 2px 14px; }
|
|
411
|
+
.ev-st .ev-sw-card .ev-trow.ev-sw-kv { padding: 10px 0; min-height: 52px; box-sizing: border-box; flex-wrap: nowrap; }
|
|
412
|
+
.ev-st .ev-sw-card select.ev-inp { max-width: 220px; }
|
|
413
|
+
.ev-st .ev-sw-prop { display: flex; align-items: center; gap: 10px; margin: 10px 0 0; }
|
|
414
|
+
.ev-st .ev-sw-prop b { font-weight: var(--fw-strong); }
|
|
415
|
+
.ev-st .ev-sw-prop p { margin: 2px 0 0; color: var(--cz-ink2); }
|
|
416
|
+
.ev-st .ev-sw-hist { display: flex; flex-direction: column; }
|
|
417
|
+
.ev-st .ev-sw-h { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--cz-hair); font-size: var(--fs-body); line-height: var(--lh-body); }
|
|
418
|
+
.ev-st .ev-sw-h:last-child { border-bottom: 0; }
|
|
419
|
+
.ev-st .ev-sw-h .ev-mut { text-align: right; min-width: 0; overflow-wrap: anywhere; }
|
|
420
|
+
.ev-st .ev-sw-run { display: flex; justify-content: flex-end; padding: 12px 0 4px; }
|
|
421
|
+
.ev-st .ev-ib.ev-sw-play { width: 48px; height: 48px; background: var(--cz-ink); color: var(--cz-card); }
|
|
422
|
+
.ev-st .ev-ib.ev-sw-play svg { fill: currentColor; width: 20px; height: 20px; }
|
|
423
|
+
.ev-st .ev-ib.ev-sw-play:hover { background: var(--cz-ink2); }
|
|
424
|
+
@media (max-width: 760px) { .ev-st .ev-sw-card select.ev-inp { max-width: 170px; } }
|
|
425
|
+
.ev-st input.ev-inp.ev-sw-at { flex: 0 0 auto; width: 120px; }
|
|
426
|
+
.ev-st .ev-sw-more { margin: 0 0 8px 30px; }
|
|
427
|
+
.ev-st .ev-sw-undo { border-bottom: 0; padding: 8px 0 0; }
|
|
@@ -106,12 +106,45 @@ export function clockOf(iso, now = Date.now()) {
|
|
|
106
106
|
return d.getDate() + ' ' + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
|
|
107
107
|
}
|
|
108
108
|
const short = (a) => a.replace(/ hours? ago$/, ' h ago');
|
|
109
|
+
const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
110
|
+
/** When a next run is: "10:00" today, "tomorrow 08:00", "Mon 08:00" this week, else "3 Nov 08:00" (batch 31 item 2). */
|
|
111
|
+
export function nextOf(iso, now = Date.now()) {
|
|
112
|
+
const d = new Date(iso || ''); if (Number.isNaN(d.getTime())) return '';
|
|
113
|
+
const n = new Date(now), day = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
114
|
+
const diff = Math.round((day(d) - day(n)) / 86400000), t = two_(d.getHours()) + ':' + two_(d.getMinutes());
|
|
115
|
+
if (d.getTime() <= now) return 'now';
|
|
116
|
+
if (diff <= 0) return t;
|
|
117
|
+
if (diff === 1) return 'tomorrow ' + t;
|
|
118
|
+
if (diff < 7) return WD[d.getDay()] + ' ' + t;
|
|
119
|
+
return d.getDate() + ' ' + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()] + ' ' + t;
|
|
120
|
+
}
|
|
121
|
+
/** A past moment with its time: "09:15" today, "yesterday 17:31", "3 Nov 09:00". */
|
|
122
|
+
export function atOf(iso, now = Date.now()) {
|
|
123
|
+
const c = clockOf(iso, now), d = new Date(iso || '');
|
|
124
|
+
return !c || /^\d\d:\d\d$/.test(c) ? c : c + ' ' + two_(d.getHours()) + ':' + two_(d.getMinutes());
|
|
125
|
+
}
|
|
126
|
+
/** A schedule in the row's words: "Every 30 min, working hours only" → "Every 30 min in working hours". */
|
|
127
|
+
export const everyLine = (text) => String(text || '').replace(/, working hours only/, ' in working hours').replace(/^Only when you press Refresh$/, 'Only when you press read');
|
|
128
|
+
/**
|
|
129
|
+
* The line under a scheduled source (batch 31 item 2, agreed design SwC): how often · next, quiet grey; or, when PMOS missed a read,
|
|
130
|
+
* "Read yesterday 17:31 · missed 09:00", amber with ↻. → { text, missed } | null when the row has no schedule.
|
|
131
|
+
*/
|
|
132
|
+
export function scheduleLine(s, now = Date.now()) {
|
|
133
|
+
const sch = s && s.schedule;
|
|
134
|
+
if (!sch || !sch.cadence) return null;
|
|
135
|
+
if (sch.cadence === 'off') return { text: 'Off', missed: false };
|
|
136
|
+
if (sch.missed_at) return { text: (s.as_of ? 'Read ' + atOf(s.as_of, now) : 'Never read') + ' · missed ' + atOf(sch.missed_at, now), missed: true };
|
|
137
|
+
const nx = sch.next_run ? nextOf(sch.next_run, now) : '';
|
|
138
|
+
return { text: everyLine(sch.cadence) + (nx ? ' · next ' + nx : ''), missed: false };
|
|
139
|
+
}
|
|
109
140
|
/**
|
|
110
141
|
* connectorRows(sources, health, now) → [{ id, name, trouble, why, when, act }] trouble rows first (needs you, then failed, then
|
|
111
142
|
* the other issues), then the quiet rows in the server's order.
|
|
112
143
|
* why the one reason (trouble), or "Checked 10:42 · same since 09:15" on a quiet row a measured read applies to, else ''
|
|
113
144
|
* when the time on a quiet row ('3 h ago', 'Watching', 'Not connected', 'Reading now'); '' when `why` carries the time
|
|
114
145
|
* act { kind: 'read' | 'open' | 'sec', label, href?, sec? } | null the one icon action
|
|
146
|
+
* job the Settings › Connectors item page of a scheduled source (lib/refresh.js id: calendar, jira, mywork, tracker, tools) or null
|
|
147
|
+
* Batch 31 item 2 (SwC): a scheduled source's quiet line says how often and when it reads next; a missed read turns the row amber with ↻.
|
|
115
148
|
*/
|
|
116
149
|
export function connectorRows(sources, health, now = Date.now()) {
|
|
117
150
|
const issues = (health && (health.level === 'warn' || health.level === 'bad') && health.issues) || [];
|
|
@@ -120,29 +153,35 @@ export function connectorRows(sources, health, now = Date.now()) {
|
|
|
120
153
|
const out = [];
|
|
121
154
|
for (const s of (sources || []).filter(Boolean)) {
|
|
122
155
|
const name = sourceName(s), h = s.heal, iss = bySrc.get(s.id);
|
|
156
|
+
const jobOf = s.schedule && s.schedule.refresh ? { job: s.schedule.refresh } : {}; // the Scheduled work page of this source (batch 31 item 2)
|
|
123
157
|
const read = { kind: 'read', label: 'Read ' + name + ' again' };
|
|
124
158
|
if (h && h.state === 'needs-you' && h.action) {
|
|
125
159
|
const a = h.action, dur = s.as_of ? ago(s.as_of, now).replace(/ ago$/, '') : '';
|
|
126
160
|
const why = [s.as_of ? 'Not read for ' + dur + '.' : 'Never read.', h.tried || (h.why ? 'The read ' + h.why + '.' : ''), a.read ? '' : a.how].filter(Boolean).join(' ');
|
|
127
|
-
out.push({ id: s.id, name, trouble: 1, why, when: '', act: a.read ? { ...read, label: a.label } : a.href ? { kind: 'open', label: a.label, href: a.href } : { kind: 'sec', label: a.label, sec: a.sec || 'claude' } });
|
|
161
|
+
out.push({ id: s.id, name, trouble: 1, why, when: '', act: a.read ? { ...read, label: a.label } : a.href ? { kind: 'open', label: a.label, href: a.href } : { kind: 'sec', label: a.label, sec: a.sec || 'claude' }, ...jobOf });
|
|
128
162
|
continue;
|
|
129
163
|
}
|
|
130
164
|
if (s.state === 'failed' || iss) {
|
|
131
165
|
const why = iss ? iss.why : 'Could not be read.';
|
|
132
166
|
const act = s.id === 'repository' ? (iss ? { kind: 'sec', label: 'Check the repository address', sec: 'workspaces' } : null) : read;
|
|
133
|
-
out.push({ id: s.id, name, trouble: 2, why, when: '', act });
|
|
167
|
+
out.push({ id: s.id, name, trouble: 2, why, when: '', act, ...jobOf });
|
|
134
168
|
continue;
|
|
135
169
|
}
|
|
136
170
|
const mend = h && h.state === 'repairing' && (s.state === 'stale' || s.state === 'never');
|
|
137
|
-
const sch = s.schedule || {};
|
|
171
|
+
const sch = s.schedule || {}, job = sch.refresh || null, line = scheduleLine(s, now);
|
|
172
|
+
if (line && line.missed && !mend && s.state !== 'building' && s.state !== 'off') {
|
|
173
|
+
out.push({ id: s.id, name, trouble: 4, why: line.text, when: '', act: read, ...(job ? { job } : {}) });
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
138
176
|
if (s.state === 'fresh' && sch.same_since && sch.checked_at) {
|
|
139
|
-
out.push({ id: s.id, name, trouble: 0, why: 'Checked ' + clockOf(sch.checked_at, now) + ' · same since ' + clockOf(sch.same_since, now), when: '', act: null });
|
|
177
|
+
out.push({ id: s.id, name, trouble: 0, why: 'Checked ' + clockOf(sch.checked_at, now) + ' · same since ' + clockOf(sch.same_since, now) + (sch.next_run ? ' · next ' + nextOf(sch.next_run, now) : ''), when: '', act: null, ...(job ? { job } : {}) });
|
|
140
178
|
continue;
|
|
141
179
|
}
|
|
142
180
|
const when = s.state === 'off' ? 'Not connected' : s.state === 'building' ? 'Reading now' : mend ? 'Reading again' : s.state === 'never' ? 'Never read'
|
|
143
181
|
: s.id === 'repository' && s.state === 'fresh' ? 'Watching' : short(ago(s.as_of, now)) || 'Never read';
|
|
144
|
-
|
|
145
|
-
|
|
182
|
+
// a source PMOS reads on a schedule shows ↻ only when it missed a read (above); one with no next read keeps ↻ while it is behind
|
|
183
|
+
const behind = (s.state === 'stale' || s.state === 'never') && s.id !== 'repository' && !mend && !sch.next_run;
|
|
184
|
+
out.push({ id: s.id, name, trouble: 0, why: line && !mend && s.state !== 'building' ? line.text : '', when, act: behind ? read : null, ...(job ? { job } : {}) });
|
|
146
185
|
}
|
|
147
186
|
for (const i of alone) out.push({ id: 'issue:' + i.key, name: i.name || 'Background work', trouble: 3, why: i.why, when: '', act: i.key === 'signedout' ? { kind: 'sec', label: 'Open Settings › PMOS', sec: 'claude' } : null });
|
|
148
187
|
return out.map((r, k) => ({ r, k })).sort((a, b) => (a.r.trouble || 9) - (b.r.trouble || 9) || a.k - b.k).map((x) => x.r);
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/* pm/cozy-schedwork.js — Scheduled work in Settings › Connectors (batch 31 item 2, agreed design SwC, Wawan 2026-11-18 "Build C").
|
|
2
|
+
*
|
|
3
|
+
* The row line under each source (how often · next, amber with ↻ only when a read was missed) is pm/cozy-evmodel.js scheduleLine. This
|
|
4
|
+
* module draws the two panels the rows open, inside the Connectors section (cozy-settings.js T.sub):
|
|
5
|
+
* list "Scheduled work": every source PMOS reads on a schedule, PMOS's own jobs and your own scheduled tasks, each with how
|
|
6
|
+
* often and when it runs next. One quiet entry under the sources opens it (swEntry).
|
|
7
|
+
* job:<id> one source or job (lib/refresh.js id), like the scheduled task page of the Claude app: Active, Next run, Repeats,
|
|
8
|
+
* Working hours only, PMOS's ✦ rhythm proposal (✓ saves it, ✕ hides it for today), History and ▶ Read now.
|
|
9
|
+
* task:<id> one of your scheduled tasks (schedules.json): Active, Next run, Repeats (Every hour is new), last run and ▶ Run now.
|
|
10
|
+
* Reads GET /api/refresh?ws= (lib/routes-refresh.js: rows with next_at, missed_at, propose, runs) and GET /api/schedules?all=1. Writes are
|
|
11
|
+
* the PM's presses: POST /api/refresh/source { id, on | schedule }, /api/refresh/run { id, ws }, /api/schedules/update, /api/schedules/run.
|
|
12
|
+
* PMOS proposes the rhythm; the PM approves it or picks another. Nothing here changes a schedule by itself.
|
|
13
|
+
* swLine(row, now) · repeatOpts(row) · taskLine(s, now) — pure, for the tests. */
|
|
14
|
+
import { pmGet, pmPost } from './http.js';
|
|
15
|
+
import { esc, svg, ICON, toast, wsParam } from './cozy-evui.js';
|
|
16
|
+
import { nextOf, atOf, everyLine } from './cozy-evmodel.js';
|
|
17
|
+
|
|
18
|
+
const CHEV = 'M10 7l5 5-5 5', BACK = 'M15 18l-6-6 6-6', PLAY = 'M8 5l11 7-11 7z', SPARK = 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z', CLOCK = 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 7v5l3 2';
|
|
19
|
+
const S = { rows: null, win: null, tasks: null, err: '', busy: false, from: '', undo: null };
|
|
20
|
+
const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* no storage */ } } };
|
|
21
|
+
const NOPE = (id) => 'pmos.sw.not-now.' + id;
|
|
22
|
+
const today = () => { const d = new Date(); return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate(); };
|
|
23
|
+
const ib = (attrs, label, d, cls = 'ev-ib') => `<button type="button" class="${cls}" ${attrs} aria-label="${esc(label)}" title="${esc(label)}">${svg(d, 18)}</button>`;
|
|
24
|
+
const swc = (on, attrs, label) => `<button type="button" class="ev-sw" role="switch" aria-checked="${!!on}" aria-label="${esc(label)}" ${attrs}>${on ? 'On' : 'Off'}</button>`;
|
|
25
|
+
const at = atOf;
|
|
26
|
+
const kv = (icon, k, v) => `<div class="ev-trow ev-sw-kv"><span class="ev-sw-ic" aria-hidden="true">${svg(icon, 18)}</span><span class="ev-grow">${esc(k)}</span>${v}</div>`;
|
|
27
|
+
|
|
28
|
+
/** The line under a row of the list: "Every 30 min in working hours · next 10:00", "Missed 09:00 · read yesterday", "Off". */
|
|
29
|
+
export function swLine(r, now = Date.now()) {
|
|
30
|
+
if (!r) return { text: '', missed: false };
|
|
31
|
+
if (!r.on) return { text: 'Off', missed: false };
|
|
32
|
+
if (r.missed_at) return { text: 'Missed ' + atOf(r.missed_at, now) + (r.last && r.last.at ? ' · read ' + atOf(r.last.at, now) : ' · never read'), missed: true };
|
|
33
|
+
if (r.state === 'running') return { text: 'Running now', missed: false };
|
|
34
|
+
const nx = r.next_at ? nextOf(r.next_at, now) : '';
|
|
35
|
+
if (!r.schedule_text && r.set_in) return { text: 'Set in ' + r.set_in.replace(/, /, ' › '), missed: false };
|
|
36
|
+
return { text: everyLine(r.schedule_text) + (nx ? ' · next ' + nx : ''), missed: false };
|
|
37
|
+
}
|
|
38
|
+
const EVERY_WORD = { 15: 'Every 15 min', 30: 'Every 30 min', 60: 'Every hour', 120: 'Every 2 hours', 240: 'Every 4 hours' };
|
|
39
|
+
/** The choices of Repeats for a row: [[value, label, selected]]: by the press, every 15 min to 4 hours, every day, working days, once a week.
|
|
40
|
+
* A day-based choice keeps its times (At) and day (On). */
|
|
41
|
+
export function repeatOpts(r) {
|
|
42
|
+
const s = r && r.schedule; if (!s) return [];
|
|
43
|
+
const cur = s.kind === 'every' ? 'every:' + s.every : s.kind;
|
|
44
|
+
const out = [];
|
|
45
|
+
if ((r.kinds || []).includes('manual')) out.push(['manual', 'Only when you press read', cur === 'manual']);
|
|
46
|
+
for (const v of r.every || []) out.push(['every:' + v, EVERY_WORD[v] || 'Every ' + v + ' min', cur === 'every:' + v]);
|
|
47
|
+
if ((r.kinds || []).includes('daily')) for (const [k, l] of [['daily', 'Every day'], ['weekdays', 'Working days'], ['weekly', 'Once a week']]) out.push([k, l, cur === k]);
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
const TASK_CAD = [['hourly', 'Every hour'], ['daily', 'Every day'], ['weekly', 'Every week'], ['bi-weekly', 'Every 2 weeks'], ['monthly', 'Every month']];
|
|
51
|
+
const DAYN = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
|
|
52
|
+
/** Your scheduled task in words: "Every hour at :15 · next 10:15", "Every Friday at 16:00 · next Fri 16:00", "Off". */
|
|
53
|
+
export function taskLine(s, now = Date.now()) {
|
|
54
|
+
if (!s) return '';
|
|
55
|
+
if (s.enabled === false) return 'Off';
|
|
56
|
+
const t = String(s.time || '09:00'), d = DAYN[s.day] || 'Monday';
|
|
57
|
+
const rep = s.cadence === 'hourly' ? 'Every hour at :' + t.slice(-2) : s.cadence === 'daily' ? 'Every day at ' + t : s.cadence === 'weekly' ? 'Every ' + d + ' at ' + t
|
|
58
|
+
: s.cadence === 'bi-weekly' ? 'Every other ' + d + ' at ' + t : s.cadence === 'monthly' ? 'On day ' + (s.dayOfMonth || 1) + ' of each month at ' + t : s.cadence === 'once' ? 'Once, ' + (s.date || '') + ' at ' + t : String(s.cadence || '');
|
|
59
|
+
const nx = s.next ? nextOf(s.next, now) : '';
|
|
60
|
+
return rep + (nx ? ' · next ' + nx : '');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Read the rows and your tasks. `draw` redraws Settings. */
|
|
64
|
+
export async function swLoad(draw) {
|
|
65
|
+
const ws = wsParam() || '';
|
|
66
|
+
const [r, t] = await Promise.all([pmGet('/api/refresh' + (ws ? '?ws=' + encodeURIComponent(ws) : '')), pmGet('/api/schedules?all=1')]);
|
|
67
|
+
S.rows = r && r.ok && Array.isArray(r.rows) ? r.rows : []; S.win = r && r.window ? r.window : null;
|
|
68
|
+
S.tasks = t && Array.isArray(t.schedules) ? t.schedules.filter((x) => !x.endedReason) : [];
|
|
69
|
+
S.err = !r || !r.ok ? 'The schedules could not be read' + (r && r.error ? ': ' + r.error : '') + '.' : '';
|
|
70
|
+
if (draw) draw();
|
|
71
|
+
}
|
|
72
|
+
export const swReset = () => { S.rows = null; S.tasks = null; S.err = ''; S.from = ''; };
|
|
73
|
+
const shown = () => (S.rows || []).filter((r) => r.run !== 'change');
|
|
74
|
+
/** The quiet entry under the sources: "Scheduled work · 9 jobs". */
|
|
75
|
+
export function swEntry() {
|
|
76
|
+
const n = S.rows ? shown().filter((r) => r.on).length + (S.tasks || []).filter((x) => x.enabled !== false).length : null;
|
|
77
|
+
return `<div class="ev-trow ev-fr ev-sw-entry"><span class="ev-gut"></span><span class="ev-sw-ic" aria-hidden="true">${svg(CLOCK, 18)}</span><div class="ev-tx ev-grow"><span>Scheduled work</span>${n != null ? `<p class="ev-small ev-mut">${n} ${n === 1 ? 'job runs' : 'jobs run'} on a schedule</p>` : ''}</div>`
|
|
78
|
+
+ ib('data-ev-sw="list"', 'Open Scheduled work', CHEV) + '</div>';
|
|
79
|
+
}
|
|
80
|
+
const head = (title, back, backLabel) => `<div class="ev-dr-hd">${ib(`data-ev-sw="${esc(back)}"`, backLabel, BACK)}<h4 class="ev-grow">${esc(title)}</h4></div>`;
|
|
81
|
+
|
|
82
|
+
function listHtml(now) {
|
|
83
|
+
const rows = shown();
|
|
84
|
+
const row = (r) => { const l = swLine(r, now); return `<div class="ev-trow ev-fr"><span class="ev-gut">${l.missed ? '<i class="ev-dot risk" aria-hidden="true"></i>' : ''}</span><div class="ev-tx ev-grow"><span>${esc(r.label)}</span><p class="ev-small ${l.missed ? 'ev-late' : 'ev-mut'}">${esc(l.text)}</p></div>${ib(`data-ev-sw="job:${esc(r.id)}" data-ev-sw-from="list"`, 'Open ' + r.label, CHEV)}</div>`; };
|
|
85
|
+
const grp = (label, list) => (list.length ? `<p class="ev-mlbl ev-sw-grp">${esc(label)}</p>` + list.join('') : '');
|
|
86
|
+
const tasks = (S.tasks || []).map((s) => `<div class="ev-trow ev-fr"><span class="ev-gut"></span><div class="ev-tx ev-grow"><span>${esc(s.name || s.skill)}</span><p class="ev-small ev-mut">${esc(taskLine(s, now))}</p></div>${ib(`data-ev-sw="task:${esc(s.id)}"`, 'Open ' + (s.name || s.skill), CHEV)}</div>`);
|
|
87
|
+
return head('Scheduled work', '', 'Back to Connectors')
|
|
88
|
+
+ (S.err ? `<p class="ev-small ev-mut">${esc(S.err)}</p>` : '')
|
|
89
|
+
+ grp('PMOS reads', rows.filter((r) => r.run === 'skill').map(row))
|
|
90
|
+
+ grp('PMOS’s own jobs', rows.filter((r) => r.run === 'job').map(row))
|
|
91
|
+
+ grp('Your scheduled tasks', tasks)
|
|
92
|
+
+ (S.tasks && !S.tasks.length ? '<p class="ev-small ev-mut">You have no scheduled tasks of your own.</p>' : '');
|
|
93
|
+
}
|
|
94
|
+
const RESULT = { done: 'done', failed: 'failed', skipped: 'skipped', interrupted: 'stopped', running: 'running' };
|
|
95
|
+
function jobHtml(r, now) {
|
|
96
|
+
const back = S.from === 'list' ? 'list' : '', backLabel = S.from === 'list' ? 'Back to Scheduled work' : 'Back to Connectors';
|
|
97
|
+
if (!r) return head('Scheduled work', back, backLabel) + '<p class="ev-small ev-mut">This job could not be read.</p>';
|
|
98
|
+
const s = r.schedule, skip = r.missed_at ? (r.runs || []).find((x) => x.result === 'skipped' && Date.parse(x.start_at) >= Date.parse(r.missed_at)) : null;
|
|
99
|
+
const warn = r.missed_at ? `<div class="ev-warn ev-line ev-sw-warn"><i class="ev-dot risk" aria-hidden="true"></i><p class="ev-grow">${esc((r.last && r.last.at ? 'Last read ' + at(r.last.at, now) + '. ' : 'Never read. ') + 'PMOS missed ' + atOf(r.missed_at, now) + (skip && skip.note ? ': ' + skip.note + '.' : ', because PMOS was not running then or your computer slept.'))}</p></div>` : '';
|
|
100
|
+
const opts = repeatOpts(r);
|
|
101
|
+
const rep = opts.length ? `<label class="ev-vh" for="evSwRep">Repeats</label><select id="evSwRep" class="ev-inp" data-ev-sw-rep="${esc(r.id)}"${S.busy ? ' disabled' : ''}>${opts.map(([v, l, on]) => `<option value="${esc(v)}"${on ? ' selected' : ''}>${esc(l)}</option>`).join('')}</select>`
|
|
102
|
+
: `<span class="ev-small ev-mut">${esc(everyLine(r.schedule_text) || 'Not set here')}</span>`;
|
|
103
|
+
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
|
104
|
+
const times = s && ['daily', 'weekdays', 'weekly'].includes(s.kind) ? kv(CLOCK, 'At', `<label class="ev-vh" for="evSwAt">At</label><input id="evSwAt" class="ev-inp ev-sw-at" type="time" value="${esc((s.times || ['09:00'])[0])}" data-ev-sw-at="${esc(r.id)}">`)
|
|
105
|
+
+ (s.kind === 'weekly' ? kv(ICON.cal, 'On', `<label class="ev-vh" for="evSwDay">On</label><select id="evSwDay" class="ev-inp" data-ev-sw-day="${esc(r.id)}">${DAYS.map((d) => `<option value="${d}"${s.day === d ? ' selected' : ''}>${esc(DAYN[d])}</option>`).join('')}</select>`) : '')
|
|
106
|
+
+ ((s.times || []).length > 1 ? `<p class="ev-small ev-mut ev-sw-more">Also at ${esc(s.times.slice(1).join(' and '))}.</p>` : '') : '';
|
|
107
|
+
const work = s && s.kind === 'every' && r.run === 'skill' ? kv(CLOCK, 'Working hours only' + (S.win ? ' (' + S.win.start + ' to ' + S.win.end + ')' : ''), swc(s.work, `data-ev-sw-work="${esc(r.id)}"`, 'Working hours only')) : '';
|
|
108
|
+
const nx = !r.on ? 'Off' : r.missed_at ? 'Now, when you press ▶' : r.state === 'running' ? 'Running now' : r.next_at ? nextOf(r.next_at, now) : r.run === 'skill' ? 'Only when you press' : everyLine(r.schedule_text) || '—';
|
|
109
|
+
const p = r.propose && store.get(NOPE(r.id)) !== today() ? r.propose : null;
|
|
110
|
+
const span = p && p.s.work && S.win ? ' from ' + S.win.start + ' to ' + S.win.end : '';
|
|
111
|
+
const prop = p ? `<div class="ev-card ev-sw-prop"><span class="ev-av sp" aria-hidden="true">${svg(SPARK, 15)}</span><div class="ev-grow"><b>Read it more often on meeting days</b><p class="ev-small">Every ${esc(p.every)} min${esc(span)} on days with ${p.meetings} or more meetings. Today has ${p.today}. Other days stay at ${esc(EVERY_WORD[p.s.every] ? EVERY_WORD[p.s.every].replace(/^Every /, '') : p.s.every + ' min')}.</p></div>`
|
|
112
|
+
+ ib(`data-ev-sw-nope="${esc(r.id)}"`, 'Not now', ICON.close) + ib(`data-ev-sw-yes="${esc(r.id)}"`, 'Use this', ICON.check, 'ev-ib ev-jl-pri') + '</div>' : '';
|
|
113
|
+
const runs = (r.runs || []).slice(0, 5).map((x) => `<div class="ev-sw-h"><span>${esc(at(x.start_at, now))}</span><span class="ev-mut">${esc([RESULT[x.result] || x.result || '', x.took_ms != null ? Math.max(1, Math.round(x.took_ms / 60000)) + ' min' : '', x.note || x.error || x.got || ''].filter(Boolean).join(' · '))}</span></div>`).join('');
|
|
114
|
+
const canRun = r.run === 'skill' || r.run === 'job';
|
|
115
|
+
return head(r.label, back, backLabel) + `<p class="ev-small ev-mut ev-sw-what">${esc(r.what || '')}</p>` + warn
|
|
116
|
+
+ `<div class="ev-sw-card">${kv(CLOCK, 'Active', swc(r.on, `data-ev-sw-on="${esc(r.id)}"`, r.label + ': active'))}${kv(ICON.cal, 'Next run', `<span class="ev-small ev-mut">${esc(nx)}</span>`)}${kv(ICON.refresh, 'Repeats', rep)}${times}${work}</div>`
|
|
117
|
+
+ (S.undo && S.undo.id === r.id ? `<div class="ev-trow ev-sw-undo"><p class="ev-small ev-grow">Saved. PMOS reads it more often on meeting days.</p><button type="button" class="ev-btn sm" data-ev-sw-undo="${esc(r.id)}">Undo</button></div>` : '')
|
|
118
|
+
+ prop
|
|
119
|
+
+ `<p class="ev-mlbl ev-sw-grp">History</p>` + (runs ? `<div class="ev-sw-hist">${runs}</div>` : '<p class="ev-small ev-mut">No runs yet.</p>')
|
|
120
|
+
+ (canRun ? `<div class="ev-sw-run">${ib(`data-ev-sw-run="${esc(r.id)}"`, r.run === 'skill' ? 'Read now' : 'Run now', PLAY, 'ev-ib ev-sw-play')}</div>` : '');
|
|
121
|
+
}
|
|
122
|
+
function taskHtml(s, now) {
|
|
123
|
+
if (!s) return head('Scheduled work', 'list', 'Back to Scheduled work') + '<p class="ev-small ev-mut">This task could not be read.</p>';
|
|
124
|
+
const cad = TASK_CAD.some(([v]) => v === s.cadence) ? TASK_CAD : TASK_CAD.concat([[s.cadence, s.cadence === 'once' ? 'Once' : s.cadence]]);
|
|
125
|
+
const rep = `<label class="ev-vh" for="evSwTask">Repeats</label><select id="evSwTask" class="ev-inp" data-ev-sw-cad="${esc(s.id)}"${S.busy ? ' disabled' : ''}>${cad.map(([v, l]) => `<option value="${esc(v)}"${v === s.cadence ? ' selected' : ''}>${esc(l)}</option>`).join('')}</select>`;
|
|
126
|
+
const nx = s.enabled === false ? 'Off' : s.next ? nextOf(s.next, now) : 'Not scheduled';
|
|
127
|
+
const last = s.lastRun ? at(s.lastRun, now) + ({ ok: ' · finished', fail: ' · did not finish', started: ' · started' }[s.lastStatus] || '') : '';
|
|
128
|
+
return head(s.name || s.skill, 'list', 'Back to Scheduled work') + `<p class="ev-small ev-mut ev-sw-what">${esc(taskLine({ ...s, next: null }, now))}. It runs ${esc(s.skill || s.task || '')}.</p>`
|
|
129
|
+
+ `<div class="ev-sw-card">${kv(CLOCK, 'Active', swc(s.enabled !== false, `data-ev-sw-ton="${esc(s.id)}"`, (s.name || s.skill) + ': active'))}${kv(ICON.cal, 'Next run', `<span class="ev-small ev-mut">${esc(nx)}</span>`)}${kv(ICON.refresh, 'Repeats', rep)}</div>`
|
|
130
|
+
+ `<p class="ev-mlbl ev-sw-grp">History</p>` + (last ? `<div class="ev-sw-hist"><div class="ev-sw-h"><span>${esc(last)}</span></div></div>` : '<p class="ev-small ev-mut">No runs yet.</p>')
|
|
131
|
+
+ `<div class="ev-sw-run">${ib(`data-ev-sw-trun="${esc(s.id)}"`, 'Run now', PLAY, 'ev-ib ev-sw-play')}</div>`;
|
|
132
|
+
}
|
|
133
|
+
/** The panel for `sub` ('sw:list', 'sw:job:<id>', 'sw:task:<id>'). */
|
|
134
|
+
export function swBody(sub) {
|
|
135
|
+
const k = String(sub || '').slice(3), now = Date.now();
|
|
136
|
+
if (S.rows === null) return head('Scheduled work', k === 'list' ? '' : 'list', 'Back') + '<p class="ev-small ev-mut">Reading the schedules.</p>';
|
|
137
|
+
if (k === 'list') return listHtml(now);
|
|
138
|
+
if (k.startsWith('job:')) return jobHtml(S.rows.find((r) => r.id === k.slice(4)), now);
|
|
139
|
+
if (k.startsWith('task:')) return taskHtml((S.tasks || []).find((x) => x.id === k.slice(5)), now);
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const said = (r, ok) => (r && r.ok ? ok : 'Not saved: ' + ((r && r.error) || 'the server did not answer') + '.');
|
|
144
|
+
/** A press inside Scheduled work. → true when it was one. `go(sub)` opens a panel ('' goes back to Connectors); `say(text)` the status line. */
|
|
145
|
+
export async function swPress(t, { go, say, draw }) {
|
|
146
|
+
const d = t.dataset;
|
|
147
|
+
if (d.evSw !== undefined) {
|
|
148
|
+
const k = d.evSw;
|
|
149
|
+
if (k === 'list' || k === '') S.from = '';
|
|
150
|
+
else S.from = d.evSwFrom || '';
|
|
151
|
+
go(k ? 'sw:' + k : '');
|
|
152
|
+
if (k && S.rows === null) swLoad(draw);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
const id = d.evSwOn || d.evSwWork || d.evSwYes || d.evSwNope || d.evSwRun || d.evSwTon || d.evSwTrun || d.evSwUndo;
|
|
156
|
+
if (!id) return false;
|
|
157
|
+
if (d.evSwNope) { store.set(NOPE(id), today()); say('Hidden for today. PMOS keeps the rhythm you have.'); draw(); return true; }
|
|
158
|
+
if (S.busy) return true;
|
|
159
|
+
S.busy = true;
|
|
160
|
+
try {
|
|
161
|
+
const r = (S.rows || []).find((x) => x.id === id);
|
|
162
|
+
if (d.evSwOn && r) { const on = !r.on, x = await pmPost('/api/refresh/source', { id, on }); say(said(x, on ? r.label + ' is on.' : r.label + ' is off. PMOS does not run it on its own.')); }
|
|
163
|
+
else if (d.evSwWork && r) { const x = await pmPost('/api/refresh/source', { id, schedule: { ...r.schedule, work: !r.schedule.work } }); say(said(x, r.schedule.work ? 'Saved. It runs all day.' : 'Saved. It runs in working hours only.')); }
|
|
164
|
+
else if (d.evSwYes && r && r.propose) { const old = r.schedule, x = await pmPost('/api/refresh/source', { id, schedule: r.propose.s }); if (x && x.ok) S.undo = { id, s: old }; say(said(x, 'Saved. PMOS reads ' + r.label + ' every ' + r.propose.every + ' min on meeting days.')); }
|
|
165
|
+
else if (d.evSwUndo && S.undo && S.undo.id === id) { const x = await pmPost('/api/refresh/source', { id, schedule: S.undo.s }); if (x && x.ok) S.undo = null; say(said(x, 'Undone. The rhythm is as it was.')); }
|
|
166
|
+
else if (d.evSwRun && r) { const x = await pmPost('/api/refresh/run', { id, ws: wsParam() || undefined }); say(x && x.ok ? (x.waiting ? 'It starts once ' + x.waiting.join(', ') + ' finish.' : 'Started. ' + r.label + ' runs now.') : 'It did not start: ' + ((x && x.error) || 'the server did not answer') + '.'); if (x && x.ok) toast('Started.'); }
|
|
167
|
+
else if (d.evSwTon) { const s = (S.tasks || []).find((y) => y.id === id); if (s) { const on = s.enabled === false, x = await pmPost('/api/schedules/update', { id, enabled: on }); say(said(x, on ? 'It runs on its schedule again.' : 'It is off.')); } }
|
|
168
|
+
else if (d.evSwTrun) { const x = await pmPost('/api/schedules/run', { id }); say(x && x.ok !== false ? 'Started.' : 'It did not start: ' + ((x && x.error) || 'the server did not answer') + '.'); }
|
|
169
|
+
} finally { S.busy = false; }
|
|
170
|
+
await swLoad(draw);
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
/** A change of Repeats. → true when it was one. */
|
|
174
|
+
export async function swChange(x, { say, draw }) {
|
|
175
|
+
const id = x.dataset.evSwRep || x.dataset.evSwCad || x.dataset.evSwAt || x.dataset.evSwDay;
|
|
176
|
+
if (!id) return false;
|
|
177
|
+
if (S.busy) return true;
|
|
178
|
+
S.busy = true;
|
|
179
|
+
try {
|
|
180
|
+
if (x.dataset.evSwRep) {
|
|
181
|
+
const r = (S.rows || []).find((y) => y.id === id); if (!r) return true;
|
|
182
|
+
const v = x.value, cur = r.schedule || {}, times = cur.times && cur.times.length ? cur.times : ['09:00'];
|
|
183
|
+
let sch;
|
|
184
|
+
if (x.dataset.evSwAt) { if (!/^\d\d:\d\d$/.test(v)) return true; sch = { ...cur, times: [v, ...times.slice(1).filter((y) => y !== v)] }; }
|
|
185
|
+
else if (x.dataset.evSwDay) sch = { ...cur, day: v };
|
|
186
|
+
else if (v === 'manual') sch = { kind: 'manual' };
|
|
187
|
+
else if (v.startsWith('every:')) sch = { kind: 'every', every: v.slice(6), work: cur.kind === 'every' ? !!cur.work : true, ...(cur.busy ? { busy: cur.busy } : {}) };
|
|
188
|
+
else sch = { kind: v, times: v === 'weekly' ? times.slice(0, 1) : times, ...(v === 'weekly' ? { day: cur.day || 'Mon' } : {}) };
|
|
189
|
+
const res = await pmPost('/api/refresh/source', { id, schedule: sch });
|
|
190
|
+
await swLoad();
|
|
191
|
+
const nr = (S.rows || []).find((y) => y.id === id);
|
|
192
|
+
say(said(res, 'Saved. ' + r.label + ': ' + (nr ? everyLine(nr.schedule_text).toLowerCase() : 'saved') + '.'));
|
|
193
|
+
} else {
|
|
194
|
+
const s = (S.tasks || []).find((y) => y.id === id); if (!s) return true;
|
|
195
|
+
const res = await pmPost('/api/schedules/update', { id, cadence: x.value });
|
|
196
|
+
say(said(res, 'Saved. ' + (TASK_CAD.find(([v]) => v === x.value) || [0, x.value])[1] + '.'));
|
|
197
|
+
}
|
|
198
|
+
} finally { S.busy = false; }
|
|
199
|
+
await swLoad(draw);
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
* where a measured read applies (SrSee R3). Claude's failed background work and the Git sync failure are rows too. ↻ in the
|
|
24
24
|
* header reads every source (POST /api/sources/refresh-all); (i) says what PMOS reads and that it never posts. The switches
|
|
25
25
|
* (what PMOS reads on its own, the connectors your sessions have; GET and POST /api/proactive/settings) fold into one row.
|
|
26
|
+
* Scheduled work (batch 31 item 2, agreed design SwC): a scheduled source's line says how often and when it reads next, amber
|
|
27
|
+
* with ↻ only when PMOS missed a read; › on the row opens its page (Active, Next run, Repeats, ✦ rhythm, History, ▶ Read now),
|
|
28
|
+
* and one quiet entry opens the Scheduled work list, your own scheduled tasks too (pm/cozy-schedwork.js; T.sub 'sw:…').
|
|
26
29
|
* Workspaces the repositories PMOS works in (GET and POST /api/workspaces, POST /api/workspaces/forget; the folder is never touched),
|
|
27
30
|
* then the row "Workflows ›" (U4; it was a section of its own that linked out): the stages each kind of initiative goes
|
|
28
31
|
* through (pm/wf-page.js, D99). It opens as a sub-panel here, the Settings dialog widened to the window (UI grill U1: the
|
|
@@ -46,6 +49,7 @@ import * as JL from './cozy-jl.js';
|
|
|
46
49
|
import { pmGet, pmPost, pressFetch } from './http.js';
|
|
47
50
|
import { esc, svg, ICON, toast, wsParam, wsQ } from './cozy-evui.js';
|
|
48
51
|
import { connectorRows, bannerOf } from './cozy-evmodel.js';
|
|
52
|
+
import * as SW from './cozy-schedwork.js';
|
|
49
53
|
import * as AD from './cozy-adler.js';
|
|
50
54
|
import * as SE from './cozy-seasons.js';
|
|
51
55
|
import { weeksOf, lineOf, storiesOf } from './upd-weeks.js';
|
|
@@ -203,8 +207,8 @@ function readsHtml() {
|
|
|
203
207
|
// one list, trouble first (CnA): the amber dot, the one reason and the one action on a trouble row; the name and the time on a quiet one
|
|
204
208
|
const rows = connectorRows(s.sources, s.health).map((x) => `<div class="ev-trow ev-fr${x.trouble ? ' ev-fr-t' : ''}" data-src="${esc(x.id)}"><span class="ev-gut">${x.trouble ? '<i class="ev-dot risk" aria-hidden="true"></i>' : ''}</span>`
|
|
205
209
|
+ `<div class="ev-tx ev-grow">${x.trouble ? `<b>${esc(x.name)}</b>` : `<span>${esc(x.name)}</span>`}${x.why ? `<p class="ev-small ev-why ${x.trouble ? 'ev-late' : 'ev-mut'}">${x.trouble ? '<span class="ev-vh">Needs a look: </span>' : ''}${esc(x.why)}</p>` : ''}${T.note[x.id] ? `<p class="ev-small" role="status">${esc(T.note[x.id])}</p>` : ''}</div>`
|
|
206
|
-
+ `${x.when ? `<span class="ev-small ev-mut">${esc(x.when)}</span>` : ''}${act(x)}</div>`).join('');
|
|
207
|
-
return `<div class="ev-reads">${rows}</div
|
|
210
|
+
+ `${x.when ? `<span class="ev-small ev-mut">${esc(x.when)}</span>` : ''}${act(x)}${x.job ? `<button type="button" class="ev-ib" data-ev-sw="job:${esc(x.job)}" aria-label="${esc('Open ' + x.name + ': how often and when it runs next')}" title="How often and when it runs next">${svg(CHEV, 18)}</button>` : ''}</div>`).join('');
|
|
211
|
+
return `<div class="ev-reads">${rows}</div>` + SW.swEntry();
|
|
208
212
|
}
|
|
209
213
|
/** The amber box at the top of Settings, only when the PM must act on a source (self-heal, feedback batch 26 item 7). While Claude
|
|
210
214
|
* reads a source again by itself, or after it did, there is no box. The box names the one action and links to the exact place:
|
|
@@ -219,6 +223,7 @@ function staleHtml() {
|
|
|
219
223
|
}
|
|
220
224
|
const INFO = 'PMOS reads these sources and never posts to them. A switch chooses only what PMOS reads on its own; your Claude sessions can use every connector.';
|
|
221
225
|
function connectors() {
|
|
226
|
+
if (T.sub && T.sub.startsWith('sw:')) return SW.swBody(T.sub);
|
|
222
227
|
const info = T.info ? `<p class="ev-small ev-mut ev-info" id="evConInfo">${esc(INFO)}</p>` : '';
|
|
223
228
|
if (T.src === null) return info + readsHtml() + '<p class="ev-small ev-mut">Reading the connectors.</p>';
|
|
224
229
|
const brief = Object.keys(SRC).filter((k) => k in T.src).map((k) => [SRC[k], trow(SRC[k], T.src[k] ? 'PMOS reads it on its own' : 'PMOS does not read it on its own', sw(T.src[k], `data-ev-src="${k}"`, SRC[k]))]);
|
|
@@ -388,7 +393,7 @@ function checksSec() {
|
|
|
388
393
|
}
|
|
389
394
|
const BODY = { general, claude: claudeSec, connectors, workspaces, updates };
|
|
390
395
|
// the old section names (deep links, other pages' calls): where their controls are now (U4)
|
|
391
|
-
const MOVED = { checks: ['claude', ''], adler: ['general', 'adler'], jl: ['general', 'jl'], dress: ['general', 'adler'], workflows: ['workspaces', 'workflows'] };
|
|
396
|
+
const MOVED = { scheduled: ['connectors', 'sw:list'], checks: ['claude', ''], adler: ['general', 'adler'], jl: ['general', 'jl'], dress: ['general', 'adler'], workflows: ['workspaces', 'workflows'] };
|
|
392
397
|
let disposeClaudeSetup = null;
|
|
393
398
|
function draw() {
|
|
394
399
|
const el = T.el; if (!el || el.hidden) return;
|
|
@@ -447,6 +452,7 @@ function mount() {
|
|
|
447
452
|
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && T.el && !T.el.hidden && !T.el.contains(e.target) && !(e.target.closest && e.target.closest('.wf-menu'))) { e.preventDefault(); e.stopPropagation(); if (!vwFirst()) closeSettings(); } }, true);
|
|
448
453
|
T.el.addEventListener('change', async (e) => {
|
|
449
454
|
const x = e.target;
|
|
455
|
+
if (await SW.swChange(x, { say: (m) => { T.msg = m; }, draw })) return;
|
|
450
456
|
if (x.matches('[data-ev-prof]')) {
|
|
451
457
|
const r = await pmPost('/api/profiles/prefer', { agent: 'claude', profile: x.value || null });
|
|
452
458
|
if (r && r.ok) { T.cl = { ...T.cl, prefs: { ...((T.cl && T.cl.prefs) || {}) } }; if (x.value) T.cl.prefs.claude = x.value; else delete T.cl.prefs.claude; }
|
|
@@ -524,6 +530,7 @@ async function press(e) {
|
|
|
524
530
|
draw(); return;
|
|
525
531
|
}
|
|
526
532
|
if (await JL.press(t, draw, (m) => { T.msg = m; })) return;
|
|
533
|
+
if (await SW.swPress(t, { go: (k) => { T.sub = k; T.msg = ''; draw(); const f = T.el.querySelector('.ev-dr-hd .ev-ib') || T.el.querySelector('[data-ev-sw="list"]'); if (f) f.focus(); }, say: (m) => { T.msg = m; }, draw })) return;
|
|
527
534
|
if (t.dataset.evRead || 'evReadall' in t.dataset) { readAgain(t.dataset.evRead || ''); return; }
|
|
528
535
|
if (T.busy) return;
|
|
529
536
|
T.busy = true; T.msg = '';
|
|
@@ -603,6 +610,7 @@ async function readAgain(id) {
|
|
|
603
610
|
}
|
|
604
611
|
async function load() {
|
|
605
612
|
readFresh();
|
|
613
|
+
SW.swLoad(draw);
|
|
606
614
|
pmGet('/api/autonomy/kinds').then((k) => { T.ck = k && k.ok ? k : { ok: false, error: (k && k.error) || '' }; draw(); }).catch(() => { T.ck = { ok: false }; draw(); });
|
|
607
615
|
pmGet('/api/artefacts/lessons').then((l) => { T.ls = l && l.ok ? l : null; draw(); }).catch(() => { T.ls = null; });
|
|
608
616
|
pmGet('/api/grill').then((g) => { T.gr = g && g.ok ? g : { ok: false, error: (g && g.error) || '' }; draw(); }).catch(() => { T.gr = { ok: false }; draw(); });
|
|
@@ -631,7 +639,7 @@ export function openSettings(section, o = {}) {
|
|
|
631
639
|
const m = MOVED[section];
|
|
632
640
|
if (m) { T.sec = m[0]; T.sub = m[1]; T.dress = section === 'dress'; } else if (section && BODY[section]) { T.sec = section; T.sub = ''; T.dress = false; }
|
|
633
641
|
else if (el.hidden) { T.sec = 'general'; T.sub = ''; T.dress = false; } // a fresh open with no section opens on General (R2), not on the section of the last visit
|
|
634
|
-
if (el.hidden) { const ae = document.activeElement; T.back = ae && ae !== document.body ? ae : null; T.ws = null; T.src = null; T.msg = ''; T.phase = ''; T.auto = false; T.wkOpen = new Set(); T.wkMore = new Set(); T.arc = false; T.fresh = null; T.note = {}; T.info = false; T.fold = false; T.dset = {}; T.cl = null; T.gr = null; T.np = null; T.ck = null; T.ls = null; JL.reset(); }
|
|
642
|
+
if (el.hidden) { const ae = document.activeElement; T.back = ae && ae !== document.body ? ae : null; T.ws = null; T.src = null; T.msg = ''; T.phase = ''; T.auto = false; T.wkOpen = new Set(); T.wkMore = new Set(); T.arc = false; T.fresh = null; T.note = {}; T.info = false; T.fold = false; T.dset = {}; T.cl = null; T.gr = null; T.np = null; T.ck = null; T.ls = null; JL.reset(); SW.swReset(); }
|
|
635
643
|
el.hidden = false; document.getElementById('evStScrim').hidden = false; el.setAttribute('data-esc-layer', '');
|
|
636
644
|
draw();
|
|
637
645
|
const f = el.querySelector('[aria-current="page"]'); if (f) f.focus();
|
|
@@ -530,3 +530,6 @@
|
|
|
530
530
|
.vzc-seg > button, .vzc-chips .vzm-chip { position: relative; overflow: visible; }
|
|
531
531
|
.vzc-seg > button::before, .vzc-chips .vzm-chip::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }
|
|
532
532
|
}
|
|
533
|
+
/* the meeting share popover (shareable-meeting-notes): on a cozy page that does not load premium.css or cozy-viewer.css (premium-viewer.html), it names the cozy tokens itself. It lives here, not in premium-vw-doc.css, because the console type check (premium-console-type S1) would turn --sans and --mono back to the console fonts */
|
|
534
|
+
.cz-vw-hd > .vwshp{--hair:var(--cz-hair);--ink:var(--cz-ink);--ink-2:var(--cz-ink2);--ink-3:var(--cz-ink3);--ember:var(--cz-blue);--card:var(--cz-card);--card-solid:var(--cz-card);
|
|
535
|
+
--well:var(--cz-well);--ok:var(--cz-ok);--bad:var(--cz-red);--sans:var(--cz-sans);--mono:var(--cz-mono);--card-shadow:var(--cz-lift);border-radius:18px;padding:10px;max-height:calc(100dvh - 140px);overflow:auto}
|
|
@@ -231,9 +231,6 @@ iframe.vwprint{position:fixed;right:0;bottom:0;width:1px;height:1px;border:0;opa
|
|
|
231
231
|
@media (prefers-reduced-motion:reduce){.vwsw::after{transition:none}}
|
|
232
232
|
/* a meeting's share popover (shareable-meeting-notes, design A plus the follow-up draft, Exploring 2): under the share icon beside ⋯ */
|
|
233
233
|
.cz-vw-hd:has(> .vwshp){position:relative}.cz-vw-hd > .vwshp{top:calc(100% + 2px);right:8px}
|
|
234
|
-
/* on a cozy page that does not load premium.css or cozy-viewer.css (premium-viewer.html), the popover names the cozy tokens itself */
|
|
235
|
-
.cz-vw-hd > .vwshp{--hair:var(--cz-hair);--ink:var(--cz-ink);--ink-2:var(--cz-ink2);--ink-3:var(--cz-ink3);--ember:var(--cz-blue);--card:var(--cz-card);--card-solid:var(--cz-card);
|
|
236
|
-
--well:var(--cz-well);--ok:var(--cz-ok);--bad:var(--cz-red);--sans:var(--cz-sans);--mono:var(--cz-mono);--card-shadow:var(--cz-lift);border-radius:18px;padding:10px;max-height:calc(100dvh - 140px);overflow:auto}
|
|
237
234
|
.vwshp:has(.vwmc){width:380px;max-width:min(380px,calc(100vw - 32px))}
|
|
238
235
|
.vwmc{display:flex;flex-wrap:wrap;gap:6px;padding:4px 8px}
|
|
239
236
|
.vwmchip,.vwmout{display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 12px;border-radius:999px;border:1px solid var(--hair);background:var(--card-solid);color:var(--ink);font:var(--fw-regular) var(--fs-body)/1.2 var(--sans);cursor:pointer}
|
|
@@ -90,6 +90,7 @@ export function repeatsOf(s) {
|
|
|
90
90
|
const t = /^\d{1,2}:\d{2}$/.test(String(s.time || '')) ? String(s.time).padStart(5, '0') : '';
|
|
91
91
|
const at = t ? ' at ' + t : '';
|
|
92
92
|
const day = DAYS[s.day] || 'Monday';
|
|
93
|
+
if (s.cadence === 'hourly') return 'Every hour' + (t ? ' at :' + t.slice(-2) : '');
|
|
93
94
|
if (s.cadence === 'daily') return 'Every day' + at;
|
|
94
95
|
if (s.cadence === 'weekly') return 'Every ' + day + at;
|
|
95
96
|
if (s.cadence === 'bi-weekly') return 'Every other ' + day + at;
|