create-pmos 0.277.0 → 0.279.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.
@@ -1,8 +1,10 @@
1
1
  /* pm/premium-work.js — the premium My work page (initiative briefing-premium-work, slice 4). Reads GET /api/my-work-premium and draws the model
2
2
  * lib/my-work-premium.js builds from the list the Work page reads: the hero, "On your plate", With agents, Waiting on others, the dock and the standard dialog.
3
- * Every press goes to the Work page's own route under /api/pm-items; this file adds no writer. A control with nothing honest to write stays off and says why. */
3
+ * Every press goes to the Work page's own route under /api/pm-items, /api/pm-jobs or /api/my-work; this file adds no writer. A control with nothing honest to write stays off and says why.
4
+ * My work depth (initiative premium-work-depth): the dialog's tool row (Edit, Who does each step, Not before, Someday), the Focus bar and its jobs, the agent on an item
5
+ * (draft, stop, edit, post after a confirm, send back, try again), and keys and swipe on the rows. */
4
6
  import { pmPost } from './http.js';
5
- import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, turnU, ptx, CHECK, S } from './premium-shell.js';
7
+ import { $, $$, esc, openDlg, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, turnU, ptx, CHECK, RM, S } from './premium-shell.js';
6
8
 
7
9
  let M = null; // the model
8
10
  let openR = null; // the row whose dialog is open
@@ -15,6 +17,13 @@ const GLYPH = {
15
17
  };
16
18
  const glyph = (src) => GLYPH[src] || '<circle cx="12" cy="12" r="4"/>';
17
19
  wireRail('work');
20
+ const WS = new URLSearchParams(location.search).get('ws') || '';
21
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
22
+ const dayLabel = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso || ''); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
23
+ const addIso = (iso, n) => new Date(Date.parse(iso + 'T00:00:00Z') + n * 86400000).toISOString().slice(0, 10);
24
+ const nextMonday = (iso) => addIso(iso, ((1 - new Date(iso + 'T00:00:00Z').getUTCDay() + 7) % 7) || 7);
25
+ const hhmm = (iso) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? '' : String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
26
+ const SVG = { sun: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2"/>', moon: '<path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/>', eye: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>' };
18
27
 
19
28
  /* ── hero and header ───────────────────────────────────────────────────────────────────────────────────── */
20
29
  function drawHero() {
@@ -28,6 +37,8 @@ function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textConten
28
37
  /* ── the plate ─────────────────────────────────────────────────────────────────────────────────────────── */
29
38
  function rowHtml(r, o = {}) {
30
39
  const inbox = r.list === 'inbox' || r.list === 'tray', sm = o.sm;
40
+ const sd = sm ? null : sideOf(r);
41
+ const desc = sd ? ` aria-description="${esc((sd.r ? 'Right arrow: ' + sd.r.label + '. ' : '') + (sd.l ? 'Left arrow: ' + sd.l.label + '. ' : '') + 'J and K move between rows.')}"` : '';
31
42
  let lead;
32
43
  if (sm === 'ag') lead = `<span class="ags${r.agent === 'ready' ? ' ready' : ''}">${r.agent === 'ready' ? ICO('<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>') : r.agent === 'failed' ? ICO('<path d="M12 8v5M12 16.5v.5"/><circle cx="12" cy="12" r="9"/>') : '<span class="spin"></span>'}</span>`;
33
44
  else if (sm === 'wait') lead = `<span class="avp" aria-hidden="true">${esc(((r.sub.match(/waiting on (\S)/) || [])[1] || '·'))}</span>`;
@@ -36,7 +47,7 @@ function rowHtml(r, o = {}) {
36
47
  else lead = `<button class="wck" data-ck="${esc(r.id)}" aria-pressed="false" aria-label="Mark done: ${esc(r.title)}">${CHECK}</button>`;
37
48
  const meta = r.chip ? `<span class="wm"><span class="due${r.overdue ? ' od' : ''}">${esc(r.chip)}</span></span>` : '';
38
49
  const state = sm === 'ag' ? ' · ' + ({ ready: 'draft ready to review', failed: 'the run failed', queued: 'queued', working: 'working', sending: 'sending' }[r.agent] || '') : '';
39
- return `<div class="wrw"><div class="wrow${sm ? ' sm' : ''}${inbox ? ' inb' : ''}${o.first ? ' first' : ''}" data-key="${esc(r.key)}">${lead}<button class="wrh" aria-haspopup="dialog"><span class="wtx"><span class="wtit">${esc(r.title)}${o.first ? '<em class="tgf">Do this first</em>' : ''}</span><span class="ws">${esc(r.sub)}${esc(state)}</span></span>${meta}</button></div></div>`;
50
+ return `<div class="wrw"><div class="wrow${sm ? ' sm' : ''}${inbox ? ' inb' : ''}${o.first ? ' first' : ''}" data-key="${esc(r.key)}">${lead}<button class="wrh" aria-haspopup="dialog"${desc}><span class="wtx"><span class="wtit">${esc(r.title)}${o.first ? '<em class="tgf">Do this first</em>' : ''}${r.focus ? '<em class="xfc">Focus</em>' : ''}</span><span class="ws">${esc(r.sub)}${esc(state)}</span></span>${meta}</button></div></div>`;
40
51
  }
41
52
  function drawPlate() {
42
53
  const P = M.plate;
@@ -78,22 +89,102 @@ function drawReview() {
78
89
  $('#revCap').textContent = R.n + ' ' + (R.n === 1 ? 'item' : 'items');
79
90
  $('#revTxt').innerHTML = `<b>${R.n}</b> ${R.n === 1 ? 'item has' : 'items have'} sat untouched for ${R.days} days. Open one to keep it or let it go.`;
80
91
  }
81
- function draw() { drawHero(); drawPlate(); drawTray(); drawAgents(); drawWaiting(); drawReview(); drawDock(); onScroll(); }
92
+ function draw() { drawHero(); drawFocus(); drawPlate(); drawTray(); drawAgents(); drawWaiting(); drawReview(); drawDock(); onScroll(); backFocus(); }
82
93
  const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || null;
83
94
 
84
- /* ── the dialog: detail first, the presses of the Work page, the read-only agent beside it ─────────────────── */
95
+ /* ── the dialog: detail first, the presses of the Work page, the tool row, the agent, the read-only agent beside it ─────────────────── */
85
96
  const NOTYET = [['later-today', 'Later today'], ['tomorrow', 'Tomorrow'], ['next-week', 'Next week']];
86
- function cardHtml(r) {
87
- const d = r.dialog, w = d.write, a = w.actions, err = '<p class="nodef err" id="cardErr" role="alert" hidden></p>';
88
- const move = [a.includes('flag') ? ['flag', 'Do today'] : null, a.includes('park') ? ['park', 'Later'] : null].filter(Boolean);
89
- return `<div class="acard" id="card"><p class="ct">What you can do</p>`
97
+ const WHO = [['you', 'You'], ['agent-drafts', 'Agent drafts'], ['agent-does', 'Agent does']];
98
+ const PRIS = ['P1', 'P2', 'P3', ''];
99
+ let dlgKind = null; // 'item' | 'fjobs': what the open dialog shows
100
+ let ui = {}; // what is typed or opened in the item dialog; kept across a redraw
101
+ const freshUi = () => ({ xp: null, ed: null, dd: '', sn: '', ask: null, body: null, editing: false, confirm: false, back: false, note: '', wo: '' });
102
+ const dlgOpen = () => $('#dlg').classList.contains('on');
103
+ const paras = (t) => String(t || '').split(/\n{2,}/).filter((x) => x.trim()).map((x) => `<p>${esc(x.trim()).replace(/\n/g, '<br>')}</p>`).join('');
104
+
105
+ /* the agent block: one state, the controls that state allows, and nothing is posted before the confirm */
106
+ function agentHtml(r) {
107
+ const a = r.dialog.agent;
108
+ if (!a) return '';
109
+ const w = a.where || 'anyone', dr = a.draft;
110
+ const draftBox = dr && dr.body ? `<div class="agdraft"><p class="agtag">Agent draft · not checked</p>${paras(dr.body)}</div>` : dr && dr.summary ? `<div class="agdraft"><p class="agtag">Agent draft · not checked</p><p>${esc(dr.summary)}</p></div>` : '';
111
+ let h = '';
112
+ if (a.state === 'suggest') {
113
+ h = `<p class="nodef">${a.mine ? 'The agent can draft a first version of this for you. You read it here. Nothing leaves PMOS.' : `The agent can draft this for you. You read it here first. Nothing goes to ${esc(w)} until you post it.`}</p>`
114
+ + `<label class="whyl" for="agAsk">What the agent will do</label><input id="agAsk" maxlength="500" autocomplete="off" value="${esc(ui.ask == null ? a.ask : ui.ask)}">`
115
+ + `<div class="cact two"><button class="cta" data-p="ag-brief"><span>Let the agent draft this</span></button></div>`;
116
+ } else if (a.state === 'queued' || a.state === 'working' || a.state === 'sending') {
117
+ const line = a.state === 'queued' ? 'Queued. The agent starts as soon as a session is free. You can close this page.'
118
+ : a.state === 'sending' ? `Posting to ${esc(w)}. A session does exactly the step you approved and nothing else.`
119
+ : 'The agent is working on it. You can close this page: the item keeps its state.' + (a.started_at ? ' Started at ' + esc(hhmm(a.started_at)) + '.' : '');
120
+ h = `<p class="nodef" role="status">${line}</p>${draftBox}${a.state === 'sending' ? '' : '<div class="cact two"><button class="cta alt" data-p="ag-stop"><span>Stop</span></button></div>'}`;
121
+ } else if (a.state === 'ready') {
122
+ const step = dr && dr.step;
123
+ h = `<p class="nodef">${step ? 'Draft ready. The step has not run.' : `Draft ready. Nothing went to ${esc(a.mine ? 'anyone' : w)}.`}</p>`;
124
+ if (ui.editing) h += `<label class="whyl" for="agBody">Your text for the draft</label><textarea class="ta" id="agBody" rows="8">${esc(ui.body == null ? (dr && dr.body) || '' : ui.body)}</textarea><p class="nodef">${a.mine ? 'Your version replaces the draft here.' : step ? 'The step then uses your version.' : 'Post then sends your version.'}</p>`;
125
+ else h += draftBox;
126
+ if (ui.confirm) {
127
+ const txt = ui.editing && ui.body != null ? ui.body : (dr && dr.body) || (dr && dr.summary) || '';
128
+ h += `<div class="xcon" role="group" aria-label="Confirm"><p><b>${step ? 'Do this step?' : `Post this to ${esc(w)} as you?`}</b></p>`
129
+ + (step ? `<p>A new session with Chrome does exactly this step and nothing else:</p><p class="xq">${esc(step)}</p>` : `<p>Exactly this text goes:</p><p class="xq">${esc(txt).replace(/\n/g, '<br>')}</p>`)
130
+ + `<div class="cact two"><button class="cta" data-p="ag-go"><span>${step ? 'Do the step now' : `Post it to ${esc(w)} now`}</span></button><button class="cta alt" data-p="ag-no"><span>Not yet</span></button></div></div>`;
131
+ } else {
132
+ h += '<div class="cact two">';
133
+ if (!a.mine || step) h += `<button class="cta" data-p="ag-post"><span>${step ? 'Do the step' : `Post it to ${esc(w)}`}</span></button>`;
134
+ h += `<button class="cta alt" data-p="ag-edit" aria-expanded="${ui.editing}"><span>${ui.editing ? 'Use the agent’s text' : 'Edit the draft'}</span></button>`;
135
+ if (ui.editing) h += `<button class="cta alt" data-p="ag-save"><span>Save my version</span></button>`;
136
+ h += `<button class="cta alt" data-p="ag-back" aria-expanded="${ui.back}"><span>Send it back with a note</span></button><button class="cta alt" data-p="ag-done"><span>Mark it done</span></button></div>`;
137
+ if (ui.back) h += `<label class="whyl" for="agNote">Tell the agent what to change</label><textarea class="ta" id="agNote" rows="3" maxlength="500">${esc(ui.note)}</textarea><div class="cact two"><button class="cta" data-p="ag-sendback"${ui.note.trim() ? '' : ' disabled'}><span>Send it back</span></button></div><p class="nodef">The agent drafts it again. ${a.mine ? 'Nothing leaves PMOS.' : `Nothing goes to ${esc(w)} or to anyone.`}</p>`;
138
+ }
139
+ } else if (a.state === 'failed') {
140
+ h = `<p class="nodef" role="status">${a.asks && a.error ? esc(a.error.charAt(0).toUpperCase() + a.error.slice(1)) + ' Nothing was sent.' : `The agent stopped${a.error ? ': ' + esc(a.error) : '.'} Nothing was sent.`}</p>${draftBox}`
141
+ + `<div class="cact two"><button class="cta" data-p="ag-retry"><span>Try again</span></button><button class="cta alt" data-p="ag-stop"><span>Stop</span></button></div>`;
142
+ } else if (a.state === 'sent') {
143
+ h = `<p class="nodef" role="status">${a.mine ? 'The draft is kept on this item.' : `You posted it to ${esc(w)}${a.sent_at ? ' at ' + esc(hhmm(a.sent_at)) : ''}.`}${a.link ? ` <a href="${esc(a.link)}" target="_blank" rel="noopener">Open what was posted</a>` : ''}</p>${draftBox}`;
144
+ }
145
+ return h ? `<div class="agblk" data-state="${esc(a.state)}"><p class="ct">The agent</p>${h}</div>` : '';
146
+ }
147
+
148
+ /* the tool row: Edit, Who does each step, Not before, Someday, and the panel of the one that is open */
149
+ function toolsHtml(r) {
150
+ const d = r.dialog, x = ui.xp || '', S = d.steps || [], nb = d.defer && d.defer > M.today ? d.defer : null;
151
+ const b = (k, l) => `<button class="xtb" data-p="xt" data-k="${k}" aria-expanded="${x === k}">${l}</button>`;
152
+ let h = `<div class="xtools" role="group" aria-label="More for this item">${b('edit', 'Edit')}${b('steps', 'Who does each step' + (S.length ? ' · ' + S.length : ''))}${b('defer', nb ? 'From ' + esc(dayLabel(nb)) : 'Not before…')}<button class="xtb" data-p="xt" data-k="someday" aria-pressed="${d.someday}">${d.someday ? 'In Someday' : 'Someday'}</button></div>`;
153
+ if (x === 'edit') {
154
+ const e = ui.ed || (ui.ed = { title: d.edit.title, due: d.edit.due, priority: d.edit.priority, wo: d.edit.waiting_on, job: d.edit.job }), ro = !!d.edit.title_ro;
155
+ h += `<div class="xpan"><label class="xf"><span>Title</span><input id="xeT" maxlength="250" value="${esc(e.title)}"${ro ? ' disabled' : ''}></label>${ro ? `<p class="note">${esc(d.edit.title_ro)}</p>` : ''}`
156
+ + `<label class="xf"><span>Due</span><input type="date" id="xeD" value="${esc(e.due)}"></label>`
157
+ + `<div class="xf"><span>Priority</span><span class="seg2" role="group" aria-label="Priority">${PRIS.map((p) => `<button data-p="xpri" data-v="${p}" aria-pressed="${e.priority === p}">${p || 'None'}</button>`).join('')}</span></div>`
158
+ + `<label class="xf"><span>Waiting on</span><input id="xeW" maxlength="80" value="${esc(e.wo)}" placeholder="A name moves it to Waiting"></label>`
159
+ + `<label class="xf"><span>Job</span><select id="xeJ"><option value="">No job</option>${(M.jobs || []).map((j) => `<option value="${esc(j.id)}"${e.job === j.id ? ' selected' : ''}>${esc(j.name)}</option>`).join('')}</select></label>`
160
+ + `<div class="cact two"><button class="cta" data-p="xsave">${CHECK}<span>Save</span></button><button class="cta alt" data-p="xt" data-k="edit"><span>Cancel</span></button></div></div>`;
161
+ }
162
+ if (x === 'steps') {
163
+ h += `<div class="xpan"><ul class="xsteps">${S.map((s) => `<li><span class="xst">${esc(s.text)}</span><span class="seg2" role="group" aria-label="Who does: ${esc(s.text)}">${WHO.map(([k, l]) => `<button data-p="xwho" data-sid="${esc(s.id)}" data-v="${k}" aria-pressed="${s.who === k}">${l}</button>`).join('')}</span></li>`).join('') || '<li class="note">No steps yet.</li>'}</ul>`
164
+ + `<p class="note">A step that sends something to a person is only ever drafted by the agent. You release it.</p>`
165
+ + `<div class="xadd"><input id="xsIn" maxlength="200" placeholder="Add a step" aria-label="A new step" value="${esc(ui.sn)}"><button class="cta alt" data-p="xsadd">Add</button></div></div>`;
166
+ }
167
+ if (x === 'defer') {
168
+ const dd = ui.dd || '';
169
+ h += `<div class="xpan"><p class="note">It leaves your lists until that day.</p><span class="seg2" role="group" aria-label="Quick dates"><button data-p="xdq" data-v="${addIso(M.today, 1)}">Tomorrow</button><button data-p="xdq" data-v="${nextMonday(M.today)}">Monday</button><button data-p="xdq" data-v="${addIso(M.today, 7)}">In a week</button></span>`
170
+ + `<label class="xf"><span>Or a date</span><input type="date" id="xdD" min="${addIso(M.today, 1)}" value="${esc(dd)}"></label>`
171
+ + `<div class="cact two"><button class="cta" data-p="xdgo"${dd ? '' : ' disabled'}>${CHECK}<span>Not before ${dd ? esc(dayLabel(dd)) : 'that day'}</span></button>${d.defer ? '<button class="cta alt" data-p="xdclr"><span>Clear the date</span></button>' : ''}</div></div>`;
172
+ }
173
+ return h;
174
+ }
175
+ function cardInner(r) {
176
+ const d = r.dialog, a = d.write.actions;
177
+ const move = a.includes('flag') ? [['flag', 'Do today']] : [];
178
+ return agentHtml(r) + `<p class="ct">What you can do</p>`
90
179
  + `<div class="cact two"><button class="cta" data-p="done">${CHECK}<span>Done</span></button>${a.includes('keep') ? '<button class="cta quiet" data-p="keep"><span>Keep it</span></button>' : ''}</div>`
91
180
  + `<div class="mv2">Not yet <span class="seg2">${NOTYET.map(([k, t]) => `<button data-p="notyet" data-when="${k}">${t}</button>`).join('')}</span></div>`
92
181
  + (move.length ? `<div class="mv2">Move to <span class="seg2">${move.map(([k, t]) => `<button data-p="${k}">${t}</button>`).join('')}</span></div>` : '')
93
- + (a.includes('waiting') ? `<label class="whyl" for="wOn">Waiting on someone</label><div class="cact two"><input id="wOn" class="why one" maxlength="80" placeholder="A name" autocomplete="off"><button class="cta quiet" data-p="waiting" id="wBtn" disabled><span>Wait for them</span></button></div>` : '')
182
+ + toolsHtml(r)
183
+ + (a.includes('waiting') ? `<label class="whyl" for="wOn">Waiting on someone</label><div class="cact two"><input id="wOn" class="why one" maxlength="80" placeholder="A name" autocomplete="off" value="${esc(ui.wo)}"><button class="cta quiet" data-p="waiting" id="wBtn"${ui.wo.trim() ? '' : ' disabled'}><span>Wait for them</span></button></div>` : '')
94
184
  + `<div class="cact"><button class="cta quiet" data-p="remove"><span>Drop it</span></button></div>`
95
- + `${r.agent ? `<p class="nodef" id="holdWhy">${esc(d.hold)}</p>` : ''}${err}</div>`;
185
+ + '<p class="nodef err" id="cardErr" role="alert" hidden></p>';
96
186
  }
187
+ const cardHtml = (r) => `<div class="acard" id="card">${cardInner(r)}</div>`;
97
188
  function paneHtml(r) {
98
189
  const p = r.dialog.pane;
99
190
  let h = `<p class="dpath">${esc(p.file)}</p>`; // the dialog heading above already names the item and its source
@@ -103,50 +194,235 @@ function paneHtml(r) {
103
194
  }
104
195
  function openRow(r) {
105
196
  if (!r) return;
106
- openR = r; const d = r.dialog;
197
+ openR = r; dlgKind = 'item'; ui = freshUi(); const d = r.dialog;
107
198
  openDlg({ eye: d.eye + ' · real data', title: r.title, sub: r.sub, say: d.say, stream: turnA(logHtml(d)) + turnA(ptx(d.say)) + cardHtml(r), noteKey: r.key, pane: paneHtml(r), label: d.pane.label });
108
199
  loadThread(r.key);
109
200
  setTimeout(() => { const b = $('#dBody'); b.scrollTop = b.scrollHeight; }, 120);
110
201
  }
202
+ /* redraw the card from what the model and the typed state hold; `sel` is the control to focus again */
203
+ function paint(sel) {
204
+ const c = $('#card'); if (!c || !openR) return;
205
+ c.innerHTML = cardInner(openR);
206
+ if (sel) { const f = $(sel, c); if (f) f.focus(); }
207
+ }
111
208
  function showErr(msg) { const e = $('#cardErr'); if (!e) { toast(msg); return; } e.textContent = msg; e.hidden = false; }
209
+ const sigOf = (r) => JSON.stringify([r.dialog.agent, r.dialog.steps, r.dialog.defer, r.dialog.someday, r.dialog.edit, r.dialog.write.actions]);
210
+ /* after a new model: a dialog that is open follows its row, and redraws only when the row's own record changed */
211
+ function refreshOpen() {
212
+ const n = rowOf(openR.key);
213
+ if (!n) { closeDlg(); openR = null; return; }
214
+ const changed = sigOf(n) !== sigOf(openR);
215
+ openR = n;
216
+ if (changed) paint();
217
+ }
112
218
 
113
- /* a press: the page waits for the route's answer; a refusal shows its reason and changes nothing */
114
- const ROUTE = { done: 'done', notyet: 'notyet', flag: 'flag', park: 'park', waiting: 'waiting', remove: 'remove', keep: 'keep' };
115
- async function press(kind, id, extra) {
116
- const body = { id, ...(extra || {}) };
117
- if (kind === 'flag') body.flagged = true;
118
- return pmPost('/api/pm-items/' + ROUTE[kind], body);
119
- }
120
- const SAID = { done: 'Marked done.', notyet: 'Put off. It comes back by itself.', flag: 'Moved to Today.', park: 'Moved to Later.', waiting: 'Now waiting.', remove: 'Dropped.', keep: 'Kept.' };
219
+ /* a press: the page waits for the route's answer; a refusal shows its reason and changes nothing.
220
+ * o = { send(): the route's answer, say: string | (res) => string, undo(): the reverse press, keep: stay in the dialog, list: pressed on a row, not in the dialog, focus: selector } */
221
+ const post = (path, body) => pmPost(path, body);
121
222
  function toastUndo(msg, undo) {
122
223
  const t = $('#toast'); t.innerHTML = `${esc(msg)} <button class="undo" type="button">Undo</button>`; t.classList.add('on');
123
224
  const b = $('.undo', t); b.onclick = async () => { t.classList.remove('on'); const r = await undo(); if (!r || r.ok !== true) toast((r && r.error) || 'It could not be undone.'); await load(); };
124
225
  clearTimeout(toastUndo.t); toastUndo.t = setTimeout(() => t.classList.remove('on'), 8000);
125
226
  }
126
- async function doPress(kind, id, extra, undo) {
127
- const btns = $$('#card button'); btns.forEach((b) => { b.disabled = true; });
128
- const res = await press(kind, id, extra);
129
- if (!res || res.ok !== true) { btns.forEach((b) => { b.disabled = false; }); wSync(); showErr((res && res.error) || 'The press was not recorded.'); return false; }
130
- closeDlg(); openR = null;
131
- if (undo) toastUndo(SAID[kind], undo); else toast(SAID[kind]);
132
- await load(); return true;
227
+ async function commit(o) {
228
+ if (!o.list) $$('#card button').forEach((b) => { b.disabled = true; });
229
+ const res = await o.send();
230
+ if (!res || res.ok !== true) {
231
+ const msg = (res && res.error) || 'The press was not recorded.';
232
+ if (o.list) toast(msg); else { paint(); showErr(msg); }
233
+ return false;
234
+ }
235
+ const said = typeof o.say === 'function' ? o.say(res) : o.say;
236
+ if (o.keep) {
237
+ await load(); paint(o.focus); if (said) toast(said);
238
+ } else {
239
+ if (!o.list) { closeDlg(); openR = null; }
240
+ if (o.undo) toastUndo(said, o.undo); else toast(said);
241
+ await load();
242
+ }
243
+ return true;
244
+ }
245
+ const SAID = { done: 'Marked done.', notyet: 'Put off. It comes back by itself.', flag: 'Moved to Today.', waiting: 'Now waiting.', remove: 'Dropped.', keep: 'Kept.' };
246
+ const reopen = (id) => () => post('/api/pm-items/reopen', { id });
247
+ const doneP = (r, o = {}) => commit({ ...o, send: () => post('/api/pm-items/done', { id: r.id, ...(o.how ? { how: o.how } : {}) }), say: o.say || SAID.done, undo: reopen(r.id) });
248
+ const deferP = (r, until, o = {}) => commit({ ...o, send: () => post('/api/pm-items/defer', { id: r.id, until }),
249
+ say: until ? `Not before ${dayLabel(until)}. It leaves your lists until then.` : 'Date cleared.', undo: () => post('/api/pm-items/defer', { id: r.id, until: r.dialog.defer || null }) });
250
+ const somedayP = (r, o = {}) => commit({ ...o, send: () => post(r.dialog.someday ? '/api/pm-items/unpark' : '/api/pm-items/someday', { id: r.id }),
251
+ say: r.dialog.someday ? 'Brought back.' : 'Moved to Someday.', undo: () => post(r.dialog.someday ? '/api/pm-items/someday' : '/api/pm-items/unpark', { id: r.id }) });
252
+ const todayP = (r, o = {}) => commit({ ...o, send: () => post('/api/pm-items/flag', { id: r.id, flagged: true }), say: SAID.flag, undo: () => post('/api/pm-items/flag', { id: r.id, flagged: false }) });
253
+
254
+ /* the edit: only what changed; Undo writes the old values back through the same routes */
255
+ function saveEdit(r) {
256
+ const o = r.dialog.edit, e = ui.ed, id = r.id, fields = {}, old = {};
257
+ const t = e.title.trim();
258
+ if (!o.title_ro && t && t !== o.title) { fields.title = t; old.title = o.title; }
259
+ if (e.due !== o.due) { fields.due = e.due || null; old.due = o.due || null; }
260
+ if (e.priority !== o.priority) { fields.priority = e.priority || null; old.priority = o.priority || null; }
261
+ if (e.job !== o.job) { fields.job = e.job || null; old.job = o.job || null; }
262
+ const wo = e.wo.trim(), woChanged = wo !== o.waiting_on;
263
+ if (!Object.keys(fields).length && !woChanged) { showErr('Nothing changed.'); return; }
264
+ return commit({
265
+ send: async () => {
266
+ let res = { ok: true };
267
+ if (Object.keys(fields).length) res = await post('/api/pm-items/edit', { id, fields });
268
+ if (res && res.ok === true && woChanged) res = await post('/api/pm-items/waiting', { id, on: wo || null });
269
+ return res;
270
+ },
271
+ say: woChanged && wo ? `Saved. It now waits on ${wo}.` : 'Saved.',
272
+ undo: async () => {
273
+ let res = { ok: true };
274
+ if (Object.keys(old).length) res = await post('/api/pm-items/edit', { id, fields: old });
275
+ if (res && res.ok === true && woChanged) res = await post('/api/pm-items/waiting', { id, on: o.waiting_on || null });
276
+ return res;
277
+ },
278
+ });
133
279
  }
134
- const wSync = () => { const b = $('#wBtn'); if (b) b.disabled = !(($('#wOn') || {}).value || '').trim(); };
135
- $('#dBody').addEventListener('input', (e) => { if (e.target.id === 'wOn') wSync(); });
280
+
281
+ /* the dialog's clicks */
282
+ function dlgClick(b, r) {
283
+ const id = r.id, k = b.dataset.p, d = r.dialog, a = d.agent || {};
284
+ switch (k) {
285
+ case 'notyet': return commit({ send: () => post('/api/pm-items/notyet', { id, when: b.dataset.when }), say: SAID.notyet });
286
+ case 'waiting': return commit({ send: () => post('/api/pm-items/waiting', { id, on: ($('#wOn').value || '').trim() }), say: SAID.waiting });
287
+ case 'done': return doneP(r);
288
+ case 'remove': return commit({ send: () => post('/api/pm-items/remove', { id }), say: SAID.remove, undo: () => post('/api/pm-items/undo', { id }) });
289
+ case 'flag': return todayP(r);
290
+ case 'keep': return commit({ send: () => post('/api/pm-items/keep', { id }), say: SAID.keep });
291
+ case 'xt': {
292
+ const t = b.dataset.k;
293
+ if (t === 'someday') return somedayP(r);
294
+ ui.xp = ui.xp === t ? null : t; if (t === 'edit') ui.ed = null;
295
+ return paint(ui.xp ? `.xpan input:not([disabled]),.xpan button` : `[data-k="${t}"]`);
296
+ }
297
+ case 'xpri': ui.ed.priority = b.dataset.v; return paint(`[data-p="xpri"][data-v="${b.dataset.v}"]`);
298
+ case 'xsave': return saveEdit(r);
299
+ case 'xwho': return commit({ keep: true, focus: `[data-p="xwho"][data-sid="${b.dataset.sid}"][data-v="${b.dataset.v}"]`, send: () => post('/api/pm-items/steps/who', { step_id: b.dataset.sid, who: b.dataset.v }),
300
+ say: (res) => (res.forced ? 'Set to Agent drafts: it sends something to a person.' : 'Step set to ' + (WHO.find((x) => x[0] === (res.who || b.dataset.v)) || [0, b.dataset.v])[1] + '.') });
301
+ case 'xsadd': {
302
+ const text = ui.sn.trim(); if (!text) { $('#xsIn').focus(); return null; }
303
+ return commit({ keep: true, focus: '#xsIn', send: async () => { const res = await post('/api/pm-items/steps/add', { id, text }); if (res && res.ok === true) { ui.sn = ''; ui.addedForced = !!res.forced; } return res; },
304
+ say: () => (ui.addedForced ? 'Step added as Agent drafts: it sends something to a person.' : 'Step added.') });
305
+ }
306
+ case 'xdq': return deferP(r, b.dataset.v);
307
+ case 'xdgo': return ui.dd ? deferP(r, ui.dd) : null;
308
+ case 'xdclr': return deferP(r, null);
309
+ case 'ag-brief': {
310
+ const own = (($('#agAsk') || {}).value || '').trim();
311
+ return commit({ keep: true, send: () => post('/api/my-work/act', { action: 'brief', item: id, instruction: own || a.ask, ws: WS }),
312
+ say: a.mine ? 'Handed to the agent. Its draft stays here in PMOS.' : `Handed to the agent. Nothing goes to ${a.where} until you post it.` });
313
+ }
314
+ case 'ag-stop': return commit({ keep: true, send: () => post('/api/my-work/stop', { item: id }), say: 'Stopped. Nothing was kept.' });
315
+ case 'ag-retry': return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'retry' }), say: 'The agent tries again.' });
316
+ case 'ag-edit': ui.editing = !ui.editing; ui.confirm = false; if (ui.editing && ui.body == null) ui.body = (a.draft && a.draft.body) || ''; return paint(ui.editing ? '#agBody' : '[data-p="ag-edit"]');
317
+ case 'ag-save': return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'edit', body: ui.body }), say: a.mine ? 'Saved. The draft stays here.' : `Saved. Post sends your text to ${a.where}.` });
318
+ case 'ag-post': ui.confirm = true; return paint('[data-p="ag-go"]');
319
+ case 'ag-no': ui.confirm = false; return paint('[data-p="ag-post"]');
320
+ case 'ag-go': {
321
+ const body = { item: id, action: 'approve' };
322
+ if (ui.editing && ui.body != null && ui.body !== ((a.draft && a.draft.body) || '')) body.body = ui.body;
323
+ return commit({ keep: true, send: () => post('/api/my-work/decide', body), say: a.draft && a.draft.step ? 'Approved. A session with Chrome does exactly this step.' : 'Approved. A session posts exactly this text.' }).then((ok) => { if (ok) { ui.confirm = false; paint(); } return ok; });
324
+ }
325
+ case 'ag-back': ui.back = !ui.back; return paint(ui.back ? '#agNote' : '[data-p="ag-back"]');
326
+ case 'ag-sendback': {
327
+ const note = ui.note.trim(); if (!note) { showErr('Say what to change first: type a note, then send it back.'); return null; }
328
+ return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'revise', note }), say: 'Sent back with your note. The agent drafts it again.' }).then((ok) => { if (ok) { ui.back = false; ui.note = ''; paint(); } return ok; });
329
+ }
330
+ case 'ag-done': return doneP(r, { how: 'agent', say: 'Done. Nothing was posted.' });
331
+ default: return null;
332
+ }
333
+ }
334
+ const FIELD = { xeT: 'title', xeD: 'due', xeW: 'wo', xeJ: 'job' };
335
+ $('#dBody').addEventListener('input', (e) => {
336
+ const t = e.target, id = t.id;
337
+ if (id === 'wOn') { ui.wo = t.value; const b = $('#wBtn'); if (b) b.disabled = !t.value.trim(); }
338
+ else if (ui.ed && FIELD[id]) ui.ed[FIELD[id]] = t.value;
339
+ else if (id === 'xsIn') ui.sn = t.value;
340
+ else if (id === 'xdD') { ui.dd = t.value; const g = $('[data-p="xdgo"]'); if (g) { g.disabled = !t.value; g.lastChild.textContent = 'Not before ' + (t.value ? dayLabel(t.value) : 'that day'); } }
341
+ else if (id === 'agAsk') ui.ask = t.value;
342
+ else if (id === 'agBody') ui.body = t.value;
343
+ else if (id === 'agNote') { ui.note = t.value; const g = $('[data-p="ag-sendback"]'); if (g) g.disabled = !t.value.trim(); }
344
+ });
345
+ $('#dBody').addEventListener('change', (e) => { if (ui.ed && e.target.id === 'xeJ') ui.ed.job = e.target.value; });
136
346
  $('#dBody').addEventListener('click', (e) => {
137
347
  const lt = e.target.closest('#logT');
138
348
  if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); return; }
139
349
  const b = e.target.closest('[data-p]');
140
- if (!b || b.disabled || !openR) return;
141
- const id = openR.id, k = b.dataset.p;
142
- if (k === 'notyet') doPress('notyet', id, { when: b.dataset.when });
143
- else if (k === 'waiting') doPress('waiting', id, { on: ($('#wOn').value || '').trim() });
144
- else if (k === 'done') doPress('done', id, null, () => pmPost('/api/pm-items/reopen', { id }));
145
- else if (k === 'remove') doPress('remove', id, null, () => pmPost('/api/pm-items/undo', { id }));
146
- else doPress(k, id);
350
+ if (!b || b.disabled || !openR || dlgKind !== 'item') return;
351
+ dlgClick(b, openR);
352
+ });
353
+
354
+ /* ── Focus and jobs: the bar under the add line, and its dialog ─────────────────────────────────────────────────────────────── */
355
+ const fBody = (f) => ({ key: f.key, title: f.title, why: f.why, item_ids: f.item_ids, job: f.job || null });
356
+ function drawFocus() {
357
+ let h = $('#xFocus');
358
+ if (!h) { $('#tx').insertAdjacentHTML('afterend', '<div id="xFocus" class="xfo" role="group" aria-label="Focus today"></div>'); h = $('#xFocus'); }
359
+ const F = M.focus, nx = F.suggestions[0], acc = F.accepted;
360
+ h.innerHTML = '<span class="label">Focus</span>' + (nx
361
+ ? `<span class="xfot"><b>${esc(nx.title)}</b><small>Suggested · ${esc(nx.why)}</small></span><span class="xfob"><button class="cta" data-xf="acc">${CHECK}<span>Accept</span></button><button class="cta alt" data-xf="more"><span>${acc.length ? acc.length + ' in focus · ' : ''}See all</span></button></span>`
362
+ : `<span class="xfot"><b>${acc.length ? acc.map((a) => esc(a.title)).join(' · ') : 'Nothing to suggest'}</b><small>${acc.length ? 'Your focus today' : 'Nothing more to suggest today'}</small></span><span class="xfob"><button class="cta alt" data-xf="more"><span>${acc.length ? 'Change' : 'Jobs'}</span></button></span>`);
363
+ }
364
+ const titleOfKey = (k) => {
365
+ const m = /^(job|item):(.+)$/.exec(k || '');
366
+ if (!m) return 'A suggestion';
367
+ if (m[1] === 'job') { const j = (M.jobs || []).find((x) => x.id === m[2]); return j ? j.name : 'A job'; }
368
+ const r = rowOf('work:' + m[2]); return r ? r.title : 'An item';
369
+ };
370
+ function focusDlgHtml() {
371
+ const F = M.focus, titles = (ids) => ids.map((i) => { const r = rowOf('work:' + i); return r ? r.title : null; }).filter(Boolean);
372
+ const card = (f, state) => `<div class="xit${state === 'no' ? ' decided' : ''}"><span class="xt">${esc(f.title)}</span>${f.why ? `<p class="xwhy">${esc(f.why)}</p>` : ''}${f.item_ids && f.item_ids.length ? `<p>${esc(titles(f.item_ids).join(' · '))}</p>` : ''}<div class="xacts">`
373
+ + (state === 'acc' ? `<p class="xdone">${CHECK}<span>In focus today.</span></p><button class="cta alt" data-fx="clr" data-k="${esc(f.key)}"><span>Clear</span></button>`
374
+ : state === 'no' ? `<p class="xdone"><span>Not today.</span></p><button class="cta alt" data-fx="clr" data-k="${esc(f.key)}"><span>Clear</span></button>`
375
+ : `<button class="cta" data-fx="acc" data-k="${esc(f.key)}">${CHECK}<span>Accept</span></button><button class="cta alt" data-fx="no" data-k="${esc(f.key)}"><span>Not today</span></button>`) + '</div></div>';
376
+ const rows = F.accepted.map((f) => card(f, 'acc')).concat(F.suggestions.map((f) => card(f, 'sug')), F.dismissed.map((k) => card({ key: k, title: titleOfKey(k), why: '', item_ids: [] }, 'no')));
377
+ const jobs = (M.jobs || []).map((j) => `<div class="xit"><span class="xt">${esc(j.name)}</span><p class="xwhy">When ${esc(j.when)}, I want ${esc(j.want)}, so ${esc(j.so)}.</p><p class="xwhy">${j.open} open ${j.open === 1 ? 'item' : 'items'}</p></div>`).join('');
378
+ const ok = /when .+,\s*i want .+,\s*so .+/i.test(ui.job || '');
379
+ return '<p class="xwhy" style="margin:0 0 6px">PMOS suggests at most three, from your Today list: overdue first, then due today. Rules only, no model call.</p>'
380
+ + `<div class="xlist">${rows.join('') || '<p class="note">Nothing is in Today, so there is nothing to suggest.</p>'}</div>`
381
+ + '<h3 class="d2">Your jobs</h3>' + `<div class="xlist">${jobs || '<p class="note">You have no jobs yet. A job is something that matters to you, which items can serve.</p>'}</div>`
382
+ + `<div class="xit"><span class="xt">Add a job</span><input id="xjIn" maxlength="300" placeholder="When …, I want …, so …" aria-label="A new job: when, I want, so" value="${esc(ui.job || '')}"><div class="xacts"><button class="cta" data-fx="jadd"${ok ? '' : ' disabled'}><span>Add the job</span></button></div></div>`
383
+ + '<p class="note" style="margin-top:14px">Focus starts empty each day. Give an item a job from its Edit panel.</p>';
384
+ }
385
+ function drawFocusDlg() { const o = $('#oMain'); if (o && dlgKind === 'fjobs') o.innerHTML = `<article class="paper doc">${focusDlgHtml()}</article>`; }
386
+ function openFocus() {
387
+ openR = null; dlgKind = 'fjobs'; ui = freshUi();
388
+ const n = M.focus.suggestions.length;
389
+ const say = n ? `I suggest ${n} ${n === 1 ? 'thing' : 'things'} to focus on today, grouped by the job they serve. Accept the ones you will do; Not today hides one until tomorrow.` : 'Nothing is in Today, so there is nothing to suggest. Your jobs are below.';
390
+ openDlg({ eye: 'My work · real data', title: 'Focus and jobs', sub: 'Today · ' + n + ' suggested', say, stream: turnA(ptx(say)), noteKey: 'focus:today', pane: '<article class="paper doc"></article>', label: 'Focus and jobs' });
391
+ $('#askF').hidden = true; setMode('detail'); drawFocusDlg();
392
+ }
393
+ async function focusPress(kind, key) {
394
+ const F = M.focus, f = F.suggestions.concat(F.accepted).find((x) => x.key === key);
395
+ const call = (path, body) => async () => { const res = await post(path, body); if (res && res.ok === true) { await load(); drawFocusDlg(); } else toast((res && res.error) || 'The press was not recorded.'); return res; };
396
+ if (kind === 'acc' && f) { const body = fBody(f); const res = await call('/api/pm-items/focus/accept', body)(); if (res && res.ok === true) toastUndo('In focus today.', async () => post('/api/pm-items/focus/clear', { key })); return; }
397
+ if (kind === 'no') { const res = await call('/api/pm-items/focus/dismiss', { key })(); if (res && res.ok === true) toastUndo('Not suggested again today.', async () => post('/api/pm-items/focus/clear', { key })); return; }
398
+ if (kind === 'clr') { const was = F.accepted.find((x) => x.key === key); const res = await call('/api/pm-items/focus/clear', { key })(); if (res && res.ok === true) { if (was) toastUndo('Cleared.', async () => post('/api/pm-items/focus/accept', fBody(was))); else toast('Cleared.'); } }
399
+ }
400
+ $('#oMain').addEventListener('input', (e) => { if (e.target.id !== 'xjIn') return; ui.job = e.target.value; const g = $('[data-fx="jadd"]'); if (g) g.disabled = !/when .+,\s*i want .+,\s*so .+/i.test(ui.job); });
401
+ $('#oMain').addEventListener('click', async (e) => {
402
+ const b = e.target.closest('[data-fx]'); if (!b || b.disabled || dlgKind !== 'fjobs') return;
403
+ const k = b.dataset.fx;
404
+ if (k === 'jadd') {
405
+ const line = (ui.job || '').trim(); b.disabled = true;
406
+ const res = await post('/api/pm-jobs/add', { line });
407
+ if (!res || res.ok !== true) { b.disabled = false; toast((res && res.error) || 'The job was not added.'); return; }
408
+ ui.job = ''; await load(); drawFocusDlg();
409
+ toastUndo('Job added.', async () => post('/api/pm-jobs/delete', { id: res.job.id }));
410
+ return;
411
+ }
412
+ focusPress(k, b.dataset.k);
413
+ });
414
+ document.addEventListener('click', async (e) => {
415
+ const b = e.target.closest('#xFocus [data-xf]'); if (!b) return;
416
+ if (b.dataset.xf === 'more') { openFocus(); return; }
417
+ const nx = M.focus.suggestions[0]; if (!nx) return;
418
+ b.disabled = true;
419
+ const res = await post('/api/pm-items/focus/accept', fBody(nx));
420
+ if (!res || res.ok !== true) { b.disabled = false; toast((res && res.error) || 'The press was not recorded.'); return; }
421
+ toastUndo('In focus today.', async () => post('/api/pm-items/focus/clear', { key: nx.key }));
422
+ await load(); const n = $('#xFocus button'); if (n) n.focus();
147
423
  });
148
424
 
149
- /* ── the list: a check marks done, a row opens its dialog ────────────────────────────────────────────────── */
425
+ /* ── the list: a check marks done, a row opens its dialog, keys and swipe act on a row ───────────────────────────────────── */
150
426
  $('#plateBody').addEventListener('click', async (e) => { await listClick(e); });
151
427
  $('#agl').addEventListener('click', (e) => { listClick(e); });
152
428
  $('#waitBody').addEventListener('click', (e) => { listClick(e); });
@@ -165,6 +441,76 @@ async function listClick(e) {
165
441
  }
166
442
  $('#revBtn').onclick = () => { const id = (M.review.ids || [])[0]; const r = (M.rows || []).find((x) => x.id === id); if (r) openRow(r); };
167
443
 
444
+ /* what a row does on its right and left: the same as the arrow keys and the drag. A row in Waiting has none. */
445
+ function sideOf(r) {
446
+ if (!r || r.list === 'waiting') return null;
447
+ const o = { list: true };
448
+ if (r.list === 'today') return {
449
+ r: r.agent === 'ready' ? { label: 'Review', ic: SVG.eye, fn: () => openRow(r) } : { label: 'Done', ic: null, fn: () => doneP(r, o) },
450
+ l: { label: 'Tomorrow', ic: SVG.moon, fn: () => deferP(r, addIso(M.today, 1), o) },
451
+ };
452
+ return { r: { label: 'In Today', ic: SVG.sun, fn: () => todayP(r, o) }, l: r.list === 'someday' ? null : { label: 'Someday', ic: SVG.moon, fn: () => somedayP(r, o) } };
453
+ }
454
+ let refocus = null; // the row to focus again once the list is drawn: { box, key, i }
455
+ function rowAct(r, side, box, i) {
456
+ const s = sideOf(r), a = s && s[side];
457
+ if (!a) return;
458
+ refocus = { box, key: r.key, i };
459
+ a.fn();
460
+ }
461
+ const rowsIn = (box) => $$('.wrow:not(.sm) .wrh', $(box));
462
+ function backFocus() {
463
+ if (!refocus) return;
464
+ const f = refocus; refocus = null;
465
+ const L = rowsIn(f.box), el = $(`${f.box} .wrow[data-key="${f.key}"] .wrh`) || L[Math.min(f.i, L.length - 1)];
466
+ if (el) el.focus();
467
+ }
468
+ for (const box of ['#plateBody', '#trayBody']) {
469
+ const root = $(box);
470
+ root.addEventListener('keydown', (e) => {
471
+ const h = e.target.closest && e.target.closest('.wrh');
472
+ if (!h || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
473
+ const L = rowsIn(box), i = L.indexOf(h);
474
+ if (i < 0) return;
475
+ if (e.key === 'j' || e.key === 'k') { e.preventDefault(); const n = L[i + (e.key === 'j' ? 1 : -1)]; if (n) n.focus(); return; }
476
+ if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') { e.preventDefault(); rowAct(rowOf(h.closest('.wrow').dataset.key), e.key === 'ArrowRight' ? 'r' : 'l', box, i); }
477
+ });
478
+ /* the drag: locks to sideways after 8 px, hands a vertical move of more than 12 px back to the page, acts past 90 px */
479
+ let sw = null, sup = 0; const TH = 90;
480
+ root.addEventListener('pointerdown', (e) => {
481
+ const r = e.target.closest('.wrow:not(.sm)');
482
+ if (!r || e.button > 0 || e.target.closest('.wck')) return;
483
+ const row = rowOf(r.dataset.key); if (!row || !sideOf(row)) return;
484
+ sw = { r, row, x: e.clientX, y: e.clientY, on: false, dx: 0, id: e.pointerId };
485
+ });
486
+ root.addEventListener('pointermove', (e) => {
487
+ if (!sw || e.pointerId !== sw.id) return;
488
+ const dx = e.clientX - sw.x, dy = e.clientY - sw.y;
489
+ if (!sw.on) {
490
+ if (Math.abs(dy) > 12 && Math.abs(dy) > Math.abs(dx)) { sw = null; return; }
491
+ if (Math.abs(dx) < 8 || Math.abs(dy) > Math.abs(dx)) return;
492
+ sw.on = true; try { sw.r.setPointerCapture(e.pointerId); } catch { /* none */ }
493
+ sw.w = sw.r.closest('.wrw'); sw.w.classList.add('xsw'); sw.w.insertAdjacentHTML('afterbegin', '<div class="xrv" aria-hidden="true"></div>'); sw.rv = $('.xrv', sw.w); sw.r.classList.add('xdr');
494
+ }
495
+ sw.dx = dx;
496
+ const side = dx > 0 ? 'r' : 'l', a = sideOf(sw.row)[side];
497
+ sw.rv.className = 'xrv ' + side;
498
+ sw.rv.innerHTML = a ? (a.ic ? `<svg class="i" viewBox="0 0 24 24">${a.ic}</svg>` : CHECK) + '<span>' + esc(a.label) + '</span>' : '';
499
+ sw.rv.style.setProperty('--d', RM ? (Math.abs(dx) >= TH && a ? 1 : 0) : a ? Math.min(1, Math.abs(dx) / TH) : 0);
500
+ if (!RM) sw.r.style.setProperty('--dx', dx * 0.55 + 'px');
501
+ });
502
+ const end = (e) => {
503
+ if (!sw) return;
504
+ const s = sw; sw = null;
505
+ if (!s.on) return;
506
+ sup = Date.now();
507
+ s.r.classList.remove('xdr'); s.r.style.removeProperty('--dx'); if (s.rv) s.rv.remove(); if (s.w) s.w.classList.remove('xsw');
508
+ if (e.type !== 'pointercancel' && Math.abs(s.dx) > TH) rowAct(s.row, s.dx > 0 ? 'r' : 'l', box, rowsIn(box).findIndex((h) => h.closest('.wrow') === s.r));
509
+ };
510
+ root.addEventListener('pointerup', end); root.addEventListener('pointercancel', end);
511
+ root.addEventListener('click', (e) => { if (Date.now() - sup < 120) { e.stopPropagation(); e.preventDefault(); } }, true);
512
+ }
513
+
168
514
  /* ── add: one line, read by the Work page's own parser ─────────────────────────────────────────────────────── */
169
515
  $('#cap').addEventListener('submit', async (e) => {
170
516
  e.preventDefault();
@@ -193,6 +539,9 @@ async function load() {
193
539
  return;
194
540
  }
195
541
  M = r.model; draw();
542
+ const mine = dlgOpen() && ((dlgKind === 'item' && openR && S.key === openR.key) || (dlgKind === 'fjobs' && S.key === 'focus:today'));
543
+ if (mine && dlgKind === 'item') refreshOpen(); else if (mine) drawFocusDlg();
196
544
  }
545
+ setInterval(() => { if (M && M.agents && M.agents.counts.running > 0 && !document.hidden) load(); }, 15000); // an agent's state changes without a press
197
546
  $('#brief').textContent = 'Reading your list.';
198
547
  load();
@@ -527,6 +527,51 @@ a.round{color:inherit;text-decoration:none}
527
527
  .avp{width:34px;height:34px;border-radius:50%;background:var(--b3);display:grid;place-items:center;font:650 12.5px var(--mono);color:var(--ink)}
528
528
  .nud{font-size:12.5px;font-weight:650;color:var(--ember-ink)}
529
529
  .nud.ok{color:var(--ok)}
530
+ /* ── My work depth (initiative premium-work-depth): Focus, the tool row, its panels, the agent block, swipe ─────────────── */
531
+ .xfo{display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin:20px 0 4px;padding:12px 14px;border-radius:var(--r-in);background:var(--well)}
532
+ .xfo .label{flex:0 0 auto}
533
+ .xfot{flex:1 1 180px;min-width:0}.xfot b{display:block;font-size:15px;font-weight:650;line-height:1.3;overflow-wrap:anywhere}.xfot small{display:block;font-size:12.5px;color:var(--ink-3);margin-top:2px}
534
+ .xfob{display:flex;gap:8px;flex-wrap:wrap}
535
+ .xfo .cta,.xacts .cta,.xpan .cta,.agblk .cta{min-height:44px;height:auto;padding:0 18px}
536
+ .xfc{font:600 11px var(--mono);font-style:normal;letter-spacing:.06em;text-transform:uppercase;color:var(--ink-2);background:var(--well);padding:2px 8px;border-radius:999px;margin-left:8px;vertical-align:2px;white-space:nowrap}
537
+ .xtools{display:flex;gap:6px;flex-wrap:wrap}
538
+ .xtb{min-height:44px;padding:0 14px;border-radius:999px;background:var(--card);font-size:12.5px;font-weight:650;color:var(--ink-2);transition:background .25s,color .25s}
539
+ .xtb:hover{color:var(--ink)}
540
+ .xtb[aria-expanded="true"],.xtb[aria-pressed="true"]{background:var(--solid);color:var(--on-solid)}
541
+ .xpan{padding:14px;border-radius:14px;background:var(--card);display:grid;gap:12px}
542
+ .xf{display:grid;gap:6px;min-width:0}
543
+ .xf>span:first-child{font:600 12.5px var(--mono);letter-spacing:.06em;text-transform:uppercase;color:var(--ink-3)}
544
+ .xpan input,.xpan select,.agblk input{width:100%;min-height:44px;padding:8px 12px;border:0;border-radius:12px;background:var(--well);color:var(--ink);font:inherit;font-size:15px;box-shadow:inset 0 0 0 1.5px var(--hair)}
545
+ .xpan input:disabled{opacity:.6}
546
+ .xpan .note{margin:0}
547
+ .xsteps{list-style:none;margin:0;padding:0;display:grid;gap:12px}
548
+ .xsteps li{display:grid;gap:6px;padding-bottom:12px;border-bottom:1px solid var(--hair)}
549
+ .xsteps .xst{font-size:15px;font-weight:550;color:var(--ink);overflow-wrap:anywhere}
550
+ .xadd{display:flex;gap:8px}.xadd input{flex:1}
551
+ .xpan .seg2 button{background:var(--well)}
552
+ .xpan .seg2 button[aria-pressed="true"]{background:var(--solid);color:var(--on-solid)}
553
+ .xit{padding:16px 0;border-top:1px solid var(--hair)}
554
+ .xlist>.xit:first-child{border-top:0;padding-top:4px}
555
+ .xit .xt{display:block;font-size:15px;font-weight:650;line-height:1.35;color:var(--ink);overflow-wrap:anywhere}
556
+ .xit p{margin:4px 0}.xit .xwhy,.xwhy{font-size:var(--t-small);color:var(--ink-3)}
557
+ .xit.decided .xt{opacity:.62}
558
+ .xacts{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}
559
+ .xdone{display:flex;gap:8px;align-items:flex-start;font-size:var(--t-small);color:var(--ink-2);margin-top:10px;line-height:1.5}
560
+ .xdone svg{width:16px;height:16px;color:var(--ok);flex:0 0 auto;margin-top:2px}
561
+ .xit input{display:block;width:100%;min-height:44px;margin-top:10px;padding:10px 12px;border:0;border-radius:12px;background:var(--well);color:var(--ink);font:inherit;font-size:15px;box-shadow:inset 0 0 0 1.5px var(--hair)}
562
+ .agblk{display:grid;gap:12px;padding-bottom:14px;border-bottom:1px solid var(--hair)}
563
+ .agblk .nodef{margin:0}
564
+ .agdraft{padding:14px;border-radius:14px;background:var(--card);display:grid;gap:6px}
565
+ .agdraft p{margin:0;font-size:15px;line-height:1.5;overflow-wrap:anywhere}.agdraft .agtag{font-size:var(--t-micro)}
566
+ .xcon{padding:14px;border-radius:14px;background:var(--card);box-shadow:inset 0 0 0 1.5px var(--ember);display:grid;gap:10px}
567
+ .xcon p{margin:0;font-size:15px;line-height:1.5}.xcon .xq{padding-left:12px;border-left:2px solid var(--hair);color:var(--ink);overflow-wrap:anywhere}
568
+ .wrw.xsw{position:relative}
569
+ .wrow{touch-action:pan-y}
570
+ .xrv{position:absolute;top:0;bottom:0;left:-12px;right:-12px;display:flex;align-items:center;gap:8px;padding:0 18px;border-radius:var(--r-in);background:var(--well);font-size:12.5px;font-weight:650;color:var(--ink);opacity:var(--d,0)}
571
+ .xrv.l{justify-content:flex-end}.xrv svg{width:16px;height:16px}
572
+ .wrow.xdr{position:relative;z-index:1;background:var(--card-solid);transform:translateX(var(--dx,0px));transition:none}
573
+ @media (prefers-reduced-motion:reduce){.wrow.xdr{transform:none}.xrv{z-index:2}}
574
+ /* ── end My work depth ───────────────────────────────────────────────────────────────────────────────────────────── */
530
575
  /* dialogs for my work */
531
576
  .ta{width:100%;border:0;border-radius:14px;background:var(--card);padding:12px 14px;font:inherit;font-size:15px;line-height:1.5;color:var(--ink);resize:vertical;min-height:96px;outline:0;box-shadow:inset 0 0 0 1.5px var(--b3)}
532
577
  .ta:focus{box-shadow:inset 0 0 0 2px var(--ink)}
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Initiative premium-work-depth: the premium My work page's deeper presses (edit, steps, Not before, Someday, Focus and jobs, the agent, keys and swipe), with request recording and the real routes on a scratch state folder.",
3
+ "panels": [
4
+ "premium-work-depth-test.js"
5
+ ],
6
+ "seconds": {
7
+ "premium-work-depth-test.js": 150
8
+ }
9
+ }