create-pmos 0.594.0 → 0.596.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.
@@ -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
- return { ok: true, s: { kind: 'every', every: String(s.every), work: !!s.work } };
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
- function slotsOfDay(s, dayMs, win) {
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 step = Number(s.every) || 60; const out = [];
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 newest TodoWrite list of the session (Claude Code's own plan of its turn): completed → done, in_progress → now,
8
- * pending → next. null when the session never wrote one: the chat then draws no checklist, never an invented one.
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 content → { start, end, calls, last }: what the transcript shows of it
82
- let doing = null; // the content of the step in progress now
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') { for (const c of content) if (c && c.type === 'tool_result' && c.tool_use_id) open.delete(c.tool_use_id); continue; }
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
- if (c.name === 'TodoWrite' && c.input && Array.isArray(c.input.todos)) {
93
- todos = c.input.todos; todosAt = r.timestamp || null; doing = null;
94
- for (const t of todos) {
95
- if (!t || !t.content) continue;
96
- const k = String(t.content), st = seen.get(k) || {};
97
- if (t.status === 'in_progress') { if (!st.start) st.start = r.timestamp || null; doing = k; }
98
- if (t.status === 'completed' && st.start && !st.end) st.end = r.timestamp || null;
99
- seen.set(k, st);
100
- }
101
- } else if (doing && c.name !== 'AskUserQuestion') { const st = seen.get(doing); st.calls = (st.calls || 0) + 1; st.last = { name: c.name, input: c.input }; }
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 && last.name !== 'TodoWrite' && last.name !== 'AskUserQuestion' ? changeOf(last.name, last.input, clean, root) : null;
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.594.0",
3
+ "version": "0.596.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.594.0",
9
+ "version": "0.596.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.594.0",
3
+ "version": "0.596.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -0,0 +1,67 @@
1
+ /* pm/cozy-conndir.js — Settings › Connectors as a directory (initiative connectors-directory; canvas CnA, CnB). Pure: no DOM, no fetch.
2
+ * CATS the category chips, All first
3
+ * CATALOG services a connector can be added for in the Claude account: id, name, category, what it does
4
+ * catOf(label) → the category of a connected connector by its name, 'other' when the catalog does not know it
5
+ * directory({ connected, signals, q, cat }) → { count, connected, forYou, all, empty }
6
+ * connected every connector the session has, each { name, label, id, cat }, filtered by the search and the chip. count is the
7
+ * number of connected rows before the filter, so the heading says how many you have, not how many match.
8
+ * forYou at most 3 services not connected yet, each with why: a link in your initiatives (signals) or what you already use
9
+ * all the rest of the catalog, not connected, not in For you
10
+ * letter(name) the letter tile on each row (the connector's own icon is not known to PMOS)
11
+ * PMOS holds no key or token: the + on a row opens the connector page of the Claude account, and PMOS notices the connector there. */
12
+ export const CATS = [['all', 'All'], ['mail', 'Mail and calendar'], ['chat', 'Chat'], ['tickets', 'Tickets'], ['code', 'Code'], ['docs', 'Docs and files'], ['design', 'Design'], ['analytics', 'Analytics']];
13
+
14
+ export const CATALOG = [
15
+ { id: 'gmail', name: 'Gmail', cat: 'mail', what: 'Read and search mail', re: /gmail/i },
16
+ { id: 'gcal', name: 'Google Calendar', cat: 'mail', what: 'Meetings and free time', re: /google.?calendar|gcal/i },
17
+ { id: 'teams', name: 'Microsoft Teams', cat: 'chat', what: 'Chats and channels', re: /teams/i },
18
+ { id: 'outlook', name: 'Microsoft 365', cat: 'mail', what: 'Outlook mail and calendar', re: /outlook|microsoft|m365|office/i },
19
+ { id: 'wispr', name: 'Wispr Flow', cat: 'mail', what: 'Meeting notes and transcripts', re: /wispr/i },
20
+ { id: 'slack', name: 'Slack', cat: 'chat', what: 'Channels, threads and mentions', re: /slack/i },
21
+ { id: 'intercom', name: 'Intercom', cat: 'chat', what: 'Customer conversations', re: /intercom/i },
22
+ { id: 'jira', name: 'Jira', cat: 'tickets', what: 'Issues, sprints and boards', re: /jira|atlassian/i },
23
+ { id: 'linear', name: 'Linear', cat: 'tickets', what: 'Issues and projects', re: /linear/i },
24
+ { id: 'asana', name: 'Asana', cat: 'tickets', what: 'Tasks and projects', re: /asana/i },
25
+ { id: 'github', name: 'GitHub', cat: 'code', what: 'Pull requests, issues and checks', re: /github/i },
26
+ { id: 'sentry', name: 'Sentry', cat: 'code', what: 'Errors and releases', re: /sentry/i },
27
+ { id: 'confluence', name: 'Confluence', cat: 'docs', what: 'Pages and spaces', re: /confluence/i },
28
+ { id: 'notion', name: 'Notion', cat: 'docs', what: 'Pages and databases', re: /notion/i },
29
+ { id: 'gdrive', name: 'Google Drive', cat: 'docs', what: 'Search, read and share files', re: /google.?drive|\bdrive\b|google.?docs|sheets|slides/i },
30
+ { id: 'box', name: 'Box', cat: 'docs', what: 'Files and folders', re: /\bbox\b/i },
31
+ { id: 'figma', name: 'Figma', cat: 'design', what: 'Designs and comments', re: /figma/i },
32
+ { id: 'miro', name: 'Miro', cat: 'design', what: 'Boards and stickies', re: /miro/i },
33
+ { id: 'canva', name: 'Canva', cat: 'design', what: 'Designs and brand kits', re: /canva/i },
34
+ { id: 'bigquery', name: 'BigQuery', cat: 'analytics', what: 'Query your data warehouse', re: /bigquery/i },
35
+ { id: 'hex', name: 'Hex', cat: 'analytics', what: 'Notebooks and data apps', re: /\bhex\b/i },
36
+ ];
37
+ const BY_ID = new Map(CATALOG.map((c) => [c.id, c]));
38
+ // what you already use → what goes with it (✦ For you, when no initiative links a service)
39
+ const PAIRS = { gmail: ['gcal', 'gdrive'], gcal: ['gmail'], outlook: ['teams'], slack: ['jira', 'github'], jira: ['confluence', 'github'], confluence: ['jira'],
40
+ github: ['linear', 'sentry'], linear: ['github'], notion: ['linear'], figma: ['miro'], gdrive: ['gmail'] };
41
+
42
+ const labelOf = (name) => String(name || '').replace(/^claude\.ai\s+/i, '').trim();
43
+ export const matchOf = (label) => CATALOG.find((c) => c.re.test(labelOf(label))) || null;
44
+ export const catOf = (label) => { const m = matchOf(label); return m ? m.cat : 'other'; };
45
+ export const letter = (name) => (labelOf(name).match(/[A-Za-z0-9]/) || ['?'])[0].toUpperCase();
46
+
47
+ const hit = (q, ...xs) => !q || xs.some((x) => String(x || '').toLowerCase().includes(q));
48
+
49
+ export function directory({ connected = [], signals = [], q = '', cat = 'all' } = {}) {
50
+ const query = String(q || '').trim().toLowerCase(), chip = CATS.some(([k]) => k === cat) ? cat : 'all';
51
+ const inCat = (c) => chip === 'all' || c === chip;
52
+ const mine = connected.map((c) => { const label = c.label || labelOf(c.name); const m = matchOf(label); return { ...c, label, id: m ? m.id : null, service: m ? m.name : '', cat: m ? m.cat : 'other', what: m ? m.what : '' }; });
53
+ const have = new Set(mine.map((c) => c.id).filter(Boolean));
54
+ // For you: services your initiatives link first (most links first), then what goes with what you use; never one you have
55
+ const why = new Map();
56
+ for (const s of Array.isArray(signals) ? signals : []) {
57
+ const id = s && (s.id || s); if (!BY_ID.has(id) || have.has(id) || why.has(id)) continue;
58
+ const n = s && s.n; why.set(id, n > 1 ? `Because ${n} initiatives link ${BY_ID.get(id).name}` : `Because an initiative links ${BY_ID.get(id).name}`);
59
+ }
60
+ for (const c of mine) for (const id of PAIRS[c.id] || []) if (!have.has(id) && !why.has(id)) why.set(id, 'Because you use ' + (BY_ID.get(c.id) || c).name);
61
+ const forYouIds = [...why.keys()].slice(0, 3);
62
+ const pick = (c) => inCat(c.cat) && hit(query, c.name, c.what, CATS.find(([k]) => k === c.cat)[1]);
63
+ const conn = mine.filter((c) => inCat(c.cat) && hit(query, c.label, c.name, c.service, c.what));
64
+ const forYou = forYouIds.map((id) => ({ ...BY_ID.get(id), why: why.get(id) })).filter(pick);
65
+ const all = CATALOG.filter((c) => !have.has(c.id) && !forYouIds.includes(c.id)).filter(pick);
66
+ return { count: mine.length, connected: conn, forYou, all, empty: !conn.length && !forYou.length && !all.length };
67
+ }
@@ -307,6 +307,31 @@
307
307
  .ev-st .ev-fold { border-top: 1px solid var(--cz-hair); border-bottom: 0; }
308
308
  .ev-st .ev-con-more { padding-left: 16px; border-left: 2px solid var(--cz-hair); margin-bottom: 12px; }
309
309
  @media (max-width: 760px) { .ev-st .ev-fr .ev-ib, .ev-st .ev-fr .ev-ib-sp { width: 44px; height: 44px; } }
310
+ /* Settings › Connectors as a directory (initiative connectors-directory; canvas CnA, CnB) */
311
+ .ev-st .ev-cn { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
312
+ .ev-st .ev-cn-search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 999px; background: var(--cz-well); color: var(--cz-ink3); }
313
+ .ev-st .ev-cn-search svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; flex: none; }
314
+ .ev-st .ev-cn-search input.ev-inp { background: transparent; padding: 0; height: 38px; }
315
+ .ev-st .ev-cn-search input.ev-inp:focus { outline: none; }
316
+ .ev-st .ev-cn-search:focus-within { outline: 2px solid var(--cz-blue); outline-offset: 1px; }
317
+ .ev-st .ev-cn-chips { display: flex; gap: 6px; flex-wrap: wrap; }
318
+ .ev-st .ev-cn-sec { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
319
+ .ev-st .ev-cn-note { margin: -6px 0 0; }
320
+ .ev-st .ev-cn-note svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; vertical-align: -2px; }
321
+ .ev-st .ev-cn-sec svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; vertical-align: -2px; }
322
+ .ev-st .ev-cn-grp { background: var(--cz-card); border: 1px solid var(--cz-hair); border-radius: 16px; padding: 0 14px; }
323
+ .ev-st .ev-cn-r { padding: 10px 0; }
324
+ .ev-st .ev-cn-lg { width: 36px; height: 36px; border-radius: 10px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--cz-well); color: var(--cz-ink); font-weight: var(--fw-strong); font-size: var(--fs-row); }
325
+ .ev-st .ev-cn-slot:empty { display: none; }
326
+ .ev-st .ev-cn-add { background: var(--cz-solid); color: var(--cz-onsolid); }
327
+ .ev-st .ev-cn-add:hover { background: var(--cz-solid); opacity: .88; }
328
+ .ev-st .ev-cn-ok { background: var(--cz-solid); color: var(--cz-onsolid); }
329
+ .ev-st .ev-cn-rec { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-top: 12px; border-radius: 16px; background: var(--cz-bluebg); }
330
+ .ev-st .ev-cn-rec p { margin: 2px 0 0; }
331
+ .ev-st .ev-cn-rec p svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; vertical-align: -2px; }
332
+ .ev-st .ev-cn-none { padding: 12px 0; margin: 0; }
333
+ .ev-st .ev-cn-foot { margin: 4px 0 0; }
334
+ @media (max-width: 760px) { .ev-st .ev-cn-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; } .ev-st .ev-cn-r .ev-ib, .ev-st .ev-cn-rec .ev-ib { width: 44px; height: 44px; } .ev-st .ev-cn-r { flex-wrap: nowrap; } }
310
335
 
311
336
  /* New for you's item Viewers (batch 18 items 2 and 2b, canvas OvA5Overlap, OvA6Given): the summary, then the two initiatives, the pick and ONE primary */
312
337
  .nv { display: flex; flex-direction: column; gap: 10px; }
@@ -398,3 +423,30 @@
398
423
  .cz .ev-ls { display: flex; flex-direction: column; gap: 2px; }
399
424
  .cz .ev-ls .ev-ms { color: var(--cz-late); }
400
425
  .cz .ev-ls .ev-nx { color: var(--cz-blueink); }
426
+ /* Settings › Connectors › Scheduled work (batch 31 item 2, agreed design SwC; pm/cozy-schedwork.js): the quiet entry, the list, and a
427
+ * job's page like the Claude app's scheduled task: Active, Next run, Repeats in one card, PMOS's ✦ rhythm, History, ▶ Read now */
428
+ .ev-st .ev-sw-ic { color: var(--cz-ink3); display: inline-flex; flex: none; }
429
+ .ev-st .ev-sw-entry .ev-sw-ic { margin-left: -16px; }
430
+ .ev-st .ev-sw-grp { padding: 14px 0 4px; }
431
+ .ev-st .ev-sw-what { margin: 0 0 10px; }
432
+ .ev-st .ev-sw-warn { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 10px; }
433
+ .ev-st .ev-sw-warn .ev-dot { margin-top: 8px; }
434
+ .ev-st .ev-sw-warn p { margin: 0; }
435
+ .ev-st .ev-sw-card { background: var(--cz-card); border: 1px solid var(--cz-hair); border-radius: 16px; padding: 2px 14px; }
436
+ .ev-st .ev-sw-card .ev-trow.ev-sw-kv { padding: 10px 0; min-height: 52px; box-sizing: border-box; flex-wrap: nowrap; }
437
+ .ev-st .ev-sw-card select.ev-inp { max-width: 220px; }
438
+ .ev-st .ev-sw-prop { display: flex; align-items: center; gap: 10px; margin: 10px 0 0; }
439
+ .ev-st .ev-sw-prop b { font-weight: var(--fw-strong); }
440
+ .ev-st .ev-sw-prop p { margin: 2px 0 0; color: var(--cz-ink2); }
441
+ .ev-st .ev-sw-hist { display: flex; flex-direction: column; }
442
+ .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); }
443
+ .ev-st .ev-sw-h:last-child { border-bottom: 0; }
444
+ .ev-st .ev-sw-h .ev-mut { text-align: right; min-width: 0; overflow-wrap: anywhere; }
445
+ .ev-st .ev-sw-run { display: flex; justify-content: flex-end; padding: 12px 0 4px; }
446
+ .ev-st .ev-ib.ev-sw-play { width: 48px; height: 48px; background: var(--cz-ink); color: var(--cz-card); }
447
+ .ev-st .ev-ib.ev-sw-play svg { fill: currentColor; width: 20px; height: 20px; }
448
+ .ev-st .ev-ib.ev-sw-play:hover { background: var(--cz-ink2); }
449
+ @media (max-width: 760px) { .ev-st .ev-sw-card select.ev-inp { max-width: 170px; } }
450
+ .ev-st input.ev-inp.ev-sw-at { flex: 0 0 auto; width: 120px; }
451
+ .ev-st .ev-sw-more { margin: 0 0 8px 30px; }
452
+ .ev-st .ev-sw-undo { border-bottom: 0; padding: 8px 0 0; }