create-pmos 0.473.0 → 0.475.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.
Files changed (51) hide show
  1. package/README.md +5 -3
  2. package/bin/create-pmos.js +23 -1
  3. package/install.ps1 +2 -1
  4. package/install.sh +6 -1
  5. package/package.json +27 -27
  6. package/payload/KIT-VERSION +1 -1
  7. package/payload/planning/evals/eval-calibration.md +1 -1
  8. package/payload/planning/okrs/health-budgets.md +1 -1
  9. package/payload/state/discoveries.md +1 -1
  10. package/workspace/README.md +1 -1
  11. package/workspace/bin/pmos.js +1 -1
  12. package/workspace/changelog.json +26 -0
  13. package/workspace/fixtures/fake-claude-onboard.js +48 -0
  14. package/workspace/guide/briefing-premium.md +2 -7
  15. package/workspace/guide/index.md +2 -2
  16. package/workspace/guide/launcher.md +14 -32
  17. package/workspace/guide/layout.md +1 -1
  18. package/workspace/guide/published-board.md +1 -1
  19. package/workspace/guide/settings.md +3 -3
  20. package/workspace/guide/welcome.md +64 -21
  21. package/workspace/lib/claude-readiness.js +143 -0
  22. package/workspace/lib/engine/calendar-import.js +5 -0
  23. package/workspace/lib/freshness.js +5 -3
  24. package/workspace/lib/launcher-cli.js +83 -8
  25. package/workspace/lib/onboarding-progress.js +36 -0
  26. package/workspace/lib/project-onboard.js +363 -0
  27. package/workspace/lib/route-modules.js +2 -0
  28. package/workspace/lib/routes-onboard.js +188 -0
  29. package/workspace/lib/routes-onboarding.js +5 -4
  30. package/workspace/lib/routes-setup.js +88 -0
  31. package/workspace/package-lock.json +2 -2
  32. package/workspace/package.json +1 -1
  33. package/workspace/project-onboard-flow-test.js +135 -0
  34. package/workspace/public/pm/cozy-claude-setup.js +90 -0
  35. package/workspace/public/pm/cozy-onboard.css +60 -0
  36. package/workspace/public/pm/cozy-onboard.js +226 -0
  37. package/workspace/public/pm/cozy-settings.js +8 -2
  38. package/workspace/public/pm/home-app.js +10 -0
  39. package/workspace/public/pm/premium-first.js +1 -1
  40. package/workspace/public/pm/premium-welcome-model.js +1 -1
  41. package/workspace/public/pm/premium-welcome.js +107 -62
  42. package/workspace/public/pm/premium.css +16 -0
  43. package/workspace/public/pm/readonly.js +1 -1
  44. package/workspace/public/pm/setup-checklist.js +22 -0
  45. package/workspace/public/premium.html +1 -0
  46. package/workspace/server.js +28 -6
  47. package/workspace/skills/calendar-sync.skill +1 -1
  48. package/workspace/test-files.json +6 -3
  49. package/workspace/test-lists/briefing-premium.json +1 -3
  50. package/workspace/test-lists/claude-onboarding-build.json +9 -0
  51. package/workspace/premium-welcome-test.js +0 -219
@@ -1,11 +1,7 @@
1
- /* pm/premium-welcome.js — the premium Welcome page (initiative premium-welcome). Three steps, then the premium Briefing.
2
- * About you → Your sources → What PMOS found → (Import) /premium.html?first=<import id>
3
- * Routes (lib/routes-onboarding.js): GET /api/onboarding/status | structure, POST /api/onboarding/scan | apply | dismiss. About you saves with
4
- * POST /api/proactive/settings, the route console Settings uses. Scan starts each ticked tool (POST /api/sources/refresh, or the brief sources and
5
- * POST /api/proactive/goals/plan) and then scans the folder. Presses carry the launch nonce through pm/http.js; the page writes nothing itself.
6
- * Text taken from the scanned folder is untrusted: every value goes through esc() and no quoted file text is shown. The pure half is premium-welcome-model.js. */
1
+ /* Guided Claude setup, explicit work reads, and reviewed folder imports. */
7
2
  import { pmGet, pmPost } from './http.js';
8
3
  import * as W from './premium-welcome-model.js';
4
+ import { mountClaudeSetup, signInTerminal } from './cozy-claude-setup.js';
9
5
  import { adlerScene, prefs as adPrefs } from './cozy-adler.js'; // Adler says hello once (batch 16 item 2, canvas AdH6), and reads with his glasses on
10
6
 
11
7
  const $ = (s, r = document) => r.querySelector(s);
@@ -15,7 +11,7 @@ const params = new URLSearchParams(location.search);
15
11
  { const t = params.get('theme') || store.get('pmos.c3.theme'); if (t === 'light' || t === 'dark') document.documentElement.dataset.theme = t; }
16
12
 
17
13
  const S = {
18
- ws: params.get('ws') || '', folder: null, added: [], step: 'about', busy: '', error: '', note: '',
14
+ ws: params.get('ws') || '', folder: null, added: [], step: 'claude', ready: false, manual: false, review: null, permissionSession: null, setup: {}, readRows: [], readItems: [], item: null, draft: { title: '', due: '', request_id: crypto.randomUUID() }, busy: '', error: '', note: '',
19
15
  about: { name: '', role: '', work: '', duties: '' }, pick: {}, sources: {},
20
16
  look: null, structure: null, checked: {}, titles: {}, boardOf: {}, edit: {}, answers: {}, skipped: {}, defs: false,
21
17
  };
@@ -41,48 +37,62 @@ async function run(label, fn) {
41
37
  S.busy = ''; draw();
42
38
  }
43
39
  const go = (step) => { S.step = step; S.error = ''; draw(true); };
44
- const saveAbout = () => run('about', async () => {
45
- const r = await pmPost('/api/proactive/settings', W.aboutBody(S.about));
46
- if (!r || !r.ok) { fail(r, 'Saving what you told PMOS'); return; }
47
- S.step = 'sources';
48
- });
49
40
  const addFolder = () => run('add', async () => {
50
41
  const p = await pmPost('/api/pick-folder', {});
51
42
  if (!p || !p.ok) { if (p && p.cancelled) return; S.note = (p && p.unsupported) ? 'This system has no folder chooser. Start pmos in the folder instead.' : ''; if (!S.note) fail(p, 'Choosing a folder'); return; }
52
43
  const w = await pmPost('/api/workspaces', { root: p.root, name: p.root.split(/[\\/]/).filter(Boolean).pop(), focus: false });
53
44
  if (!w || !w.workspace) { fail(w, 'Adding the folder'); return; }
54
- if (!S.added.some((a) => a.id === w.workspace.id) && w.workspace.id !== S.ws) S.added.push({ id: w.workspace.id, name: w.workspace.name, root: w.workspace.root });
45
+ S.ws = w.workspace.id; S.folder = { name: w.workspace.name, root: w.workspace.root }; S.added = []; S.step = 'sources'; await remember();
55
46
  });
56
47
  /* Each ticked tool is its own read-only agent session. A tool that cannot start says why on its row and does not stop the folder scan. */
57
- async function startTools() {
58
- const plan = W.toolPlan(S.pick);
59
- if (plan.brief.length) {
60
- const on = await pmPost('/api/proactive/settings', W.briefBody(plan.brief));
61
- const r = on && on.ok ? await pmPost('/api/proactive/goals/plan', { ws: S.ws }) : on;
62
- for (const x of plan.brief) S.sources[x.source] = r && r.ok ? { started: true } : { error: (r && r.error) || 'Starting the read did not work.' };
63
- }
64
- for (const x of plan.refresh) {
65
- const r = await pmPost('/api/sources/refresh', { ws: S.ws, source: x.source });
66
- S.sources[x.source] = r && r.ok ? { started: true } : { error: (r && r.error) || 'Starting the read did not work.' };
48
+ const setupPost = (verb, body = {}) => pmPost('/api/setup/' + verb, { ws: S.ws, ...body });
49
+ let disposeClaude = null;
50
+ const remember = () => { clearTimeout(S.saveTimer); return setupPost('progress', { step: S.step, manual: S.manual, draft: S.draft, review: S.review }); };
51
+ async function readTools() {
52
+ const check = await pmGet('/api/setup/state?ws=' + encodeURIComponent(S.ws));
53
+ if (!check || !check.ok || !check.claude.status.ready) { S.error = 'Check and use a Claude profile before reading a work tool.'; return; }
54
+ for (const source of ['calendar', 'my-work'].filter(k => S.pick[k])) {
55
+ const r = await setupPost('read', { source });
56
+ if (!r || !r.ok) S.error = (r && r.error) || 'The read could not start.';
67
57
  }
58
+ await refreshSetup();
59
+ }
60
+ async function refreshSetup() {
61
+ const r = await pmGet('/api/setup/state?ws=' + encodeURIComponent(S.ws));
62
+ if (!r || !r.ok) return;
63
+ S.setup = r.progress; S.readRows = r.sources || []; S.ready = !!r.claude.status.ready;
64
+ S.readItems = S.readRows.filter(r => r.state === 'complete').flatMap(r => r.preview || []).map(title => ({ title }));
68
65
  }
66
+ async function finish() {
67
+ const r = await setupPost('finish', { skip_import: !!(S.structure && !W.counts(S.structure, S).n) });
68
+ if (!r || !r.ok) { fail(r, 'Finishing setup'); return; }
69
+ location.assign('/?ws=' + encodeURIComponent(S.ws));
70
+ }
71
+ const addTask = () => run('task', async () => {
72
+ await remember();
73
+ const r = await setupPost('task', S.draft);
74
+ if (!r || !r.ok) { fail(r, 'Adding the task'); return; }
75
+ S.item = r.item; S.setup = r.progress; S.review = 'task'; S.step = 'found'; await remember();
76
+ });
69
77
  const scan = () => run('scan', async () => {
70
- await startTools();
78
+ await remember();
71
79
  const r = await pmPost('/api/onboarding/scan', { ws: S.ws, extra_roots: S.added.map((a) => a.root) });
72
80
  if (!r || !r.ok) { fail(r, 'The scan'); return; }
73
81
  const st = await pmGet(`/api/onboarding/structure?ws=${encodeURIComponent(S.ws)}`);
74
82
  if (!st || !st.ok) { fail(st, 'Reading the portfolio'); return; }
75
83
  S.look = r.first_look; S.structure = st; S.boardOf = {}; S.edit = {}; S.answers = {}; S.skipped = {}; S.defs = false;
76
84
  Object.assign(S, W.startChoices(st));
77
- S.step = 'found';
85
+ S.review = 'folder'; S.step = 'found'; await remember();
78
86
  });
79
87
  const importNow = () => {
80
88
  if (!W.counts(S.structure, S).n) return;
81
89
  run('apply', async () => {
90
+ if (S.imported) { await finish(); return; }
82
91
  const r = await pmPost('/api/onboarding/apply', W.applyBody(S.ws, S.structure, S));
83
92
  if (!r || !r.ok) { fail(r, 'The import'); return; }
93
+ S.imported = true;
84
94
  try { sessionStorage.setItem(W.FIRST_KEY, JSON.stringify(S.sources)); } catch { /* no storage */ }
85
- location.assign('/premium.html?ws=' + encodeURIComponent(S.ws) + '&first=' + encodeURIComponent(r.import_id));
95
+ await finish();
86
96
  });
87
97
  };
88
98
  // "Not now": Welcome stops opening on its own for this folder (`pmos welcome` still opens it), then the premium Briefing opens
@@ -97,36 +107,10 @@ const btn = (act, label, o = {}) => `<button class="wl-btn${o.alt ? ' alt' : ''}
97
107
  const foot = (left, right) => `<div class="wl-foot"><div>${left}</div><div class="r">${right}</div></div>`;
98
108
  const err = () => (S.error ? `<p class="wl-err" role="alert">${esc(S.error)}</p>` : '');
99
109
 
100
- function viewAbout() {
101
- const a = S.about;
102
- const f = (k, text, hint, max) => `<label>${text}<input data-f="${k}" maxlength="${max}" value="${esc(a[k])}" placeholder="${esc(hint)}" autocomplete="off"></label>`;
103
- return `<div class="wl-ad">${adlerScene('morning', 'needs-you', { label: 'Adler says hello', dress: true })}</div>${adPrefs()['adler.amount'] === 'off' ? '' : '<p class="wl-hi">Hi, I’m Adler. I do the boring bits, so you get the calls only you can make.</p>'}<h1 id="wlH" tabindex="-1">Welcome to PMOS</h1><p class="wl-lede">Tell PMOS who you are, so your Briefing knows what matters to you. Every field is optional, and you can change them later in the console's Settings.</p>
104
- <div class="wl-f">${f('name', 'Your name', 'For example: Dana', 40)}${f('role', 'Your role', 'For example: Senior PM, Payments', 80)}${f('work', 'What you do', 'In one line, for example: I run checkout and the payment methods', 200)}
105
- <label>Your job description<textarea data-f="duties" maxlength="1000" placeholder="What you own, decide and deliver. Paste it from your job description if you have one.">${esc(a.duties)}</textarea></label></div>${err()}`
106
- + foot('', btn('about', 'Continue', { busy: 'about', busyText: 'Saving' }));
107
- }
108
-
109
110
  function toolRow(x) {
110
111
  const on = !!S.pick[x.source], st = S.sources[x.source] || {};
111
112
  return `<li><button type="button" class="wl-row" data-w="tool" data-k="${esc(x.source)}" aria-pressed="${on}"${dis(S.busy)}><span class="wl-ic">${I[x.source] || ''}</span><span><b>${esc(x.name)}</b><small>${esc(x.adds)}</small>${st.error ? `<small class="wl-bad" role="alert">${esc(st.error)}</small>` : ''}</span><span class="wl-tog">${on ? 'Read it' : 'Off'}</span></button></li>`;
112
113
  }
113
- function viewSources() {
114
- const f = S.folder || { name: '', root: '' };
115
- const n = W.TOOLS.filter((x) => S.pick[x.source]).length;
116
- const rows = [`<li class="wl-row"><span class="wl-ic">${I.folder}</span><span><b>${esc(f.name || 'This folder')}</b><span class="path">${esc(f.root)}</span></span><span class="chip">this folder</span></li>`]
117
- .concat(S.added.map((a) => `<li class="wl-row"><span class="wl-ic">${I.folder}</span><span><b>${esc(a.name)}</b><span class="path">${esc(a.root)}</span></span><span></span></li>`)).join('');
118
- if (S.busy === 'scan') {
119
- return `<div class="wl-ad">${adlerScene('think', 'thinking', { label: false, dress: true })}</div><h1 id="wlH" tabindex="-1">Reading ${esc(f.name || 'your folder')}</h1><p class="wl-lede">A large folder can take a minute or two. The rest of PMOS keeps working.</p>
120
- <div class="wl-scan" role="status"><div>${spin('Starting the tools you ticked, then reading the folder')}</div></div>`;
121
- }
122
- return `<h1 id="wlH" tabindex="-1">Where does your work live?</h1><p class="wl-lede">PMOS reads your folders and the tools you tick, then shows you your initiatives, your documents and what needs you first.</p>
123
- <p class="wl-sec">Folders<span class="chip mono">${1 + S.added.length}</span></p><ul class="wl-list">${rows}</ul>
124
- <div class="wl-add">${btn('folder', 'Add another folder', { alt: true, lead: I.plus, busy: 'add', busyText: 'Waiting for the chooser' })}</div>${S.note ? `<p class="note">${esc(S.note)}</p>` : ''}
125
- <p class="wl-sec">Tools<span class="chip">optional</span></p><ul class="wl-list">${W.TOOLS.map(toolRow).join('')}</ul>
126
- <p class="note wl-lock">${I.lock}<span>Reads only. PMOS writes nothing in your folders or your tools, and sends nothing out. Your agent reads the tools you tick with your own connection.</span></p>${err()}`
127
- + foot(btn('back', 'Back', { alt: true }), btn('scan', n ? `Scan the folder and read ${W.plural(n, 'tool', 'tools')}` : 'Scan this folder', { busy: 'scan' }));
128
- }
129
-
130
114
  function rowView(r) {
131
115
  const id = r.proposal_id, ed = !!S.edit[id], on = !!S.checked[id], t = S.titles[id];
132
116
  const docs = (r.docs || []).length;
@@ -145,7 +129,7 @@ function questionInputs() {
145
129
  return `<div class="wl-q"><b>${esc(q.text)}</b>${input}<button type="button" class="wgo" data-w="skipq" data-id="${esc(q.id)}" aria-pressed="${q.skipped}">${q.skipped ? 'Skipped. Use the default' : 'Skip'}</button></div>`;
146
130
  }).join('');
147
131
  }
148
- function viewFound() {
132
+ function viewPortfolio() {
149
133
  const L = S.look || {}, c = W.counts(S.structure, S), all = W.rowsOf(S.structure), found = W.findingsOf(L), defs = W.defaultsView(S.structure, S);
150
134
  const boards = S.structure.boards.map((b) => {
151
135
  const mine = all.filter((r) => W.boardOfRow(r, S) === b.key);
@@ -161,8 +145,43 @@ ${defs.length ? `<div class="wl-add">${btn('defs', S.defs ? 'Done' : 'Change the
161
145
  + foot(btn('back', 'Back', { alt: true }), btn('import', esc(W.importText(c)), { busy: 'apply', busyText: 'Importing', off: !c.n }));
162
146
  }
163
147
 
164
- const VIEWS = { about: viewAbout, sources: viewSources, found: viewFound };
148
+ function viewClaude() {
149
+ return '<h1 id="wlH" tabindex="-1">Give PMOS a Claude login</h1><p class="wl-lede">Connect Claude, add your work, then review and start.</p><div id="wlClaude"></div>';
150
+ }
151
+ function readSummary() {
152
+ return S.readRows.map(r => `<p class="wl-source-progress"><b>${r.id === 'my-work' ? 'Jira' : 'Calendar'}</b>: ${esc({ reading: 'Reading with the selected Claude profile…', complete: 'Read complete' + (r.count === 0 ? ' · No items returned in this scope' : r.count != null ? ' · ' + r.count + ' items' : ''), failed: 'The read failed. Check this profile’s source permissions.', interrupted: 'Read interrupted. Try reading this source again.' }[r.state])}${r.read_at ? ' · ' + esc(new Date(r.read_at).toLocaleString()) : ''} · profile: ${esc(r.profile)}</p>`).join('');
153
+ }
154
+ function viewSources() {
155
+ return `<h1 id="wlH" tabindex="-1">Where should we start?</h1><p class="wl-lede">Choose a project folder, read a connected tool, or add one real task.</p>
156
+ <p class="wl-sec">Project folder</p><p>${esc(S.folder && S.folder.name)} <span class="path">${esc(S.folder && S.folder.root)}</span></p>
157
+ ${btn('folder', 'Choose another folder', { alt: true })} ${btn('scan', 'Scan this folder', { busy: 'scan', busyText: 'Scanning' })}
158
+ <p class="note">The folder scan runs locally. You review the proposed initiatives before importing them.</p>
159
+ <p class="wl-sec">Work tools</p><p class="note">Jira reads open items assigned to your connected account. Calendar reads today and the next 14 days. Connector access is checked by the actual read. Other connections stay in Settings.</p>
160
+ <ul class="wl-list">${W.TOOLS.filter(x => ['calendar', 'my-work'].includes(x.source)).map(toolRow).join('')}</ul>
161
+ ${btn('read', 'Read selected tools', { off: !S.ready || !['calendar', 'my-work'].some(k => S.pick[k]), busy: 'read', busyText: 'Starting the read' })}
162
+ ${!S.ready ? '<p class="note">Connect and check Claude before reading a work tool. Manual tasks and folder scans still work.</p>' : ''}${readSummary()}
163
+ ${btn('permissions', 'Open Claude connections and permissions', { alt: true })}${S.permissionSession ? '<p>Use this profile’s Claude session to connect your tool and review its read permissions. Then retry the read above.</p><div id="wlPermissions" class="cs-term" aria-label="Claude connections terminal"></div>' : ''}
164
+ ${S.readRows.some(r => r.state === 'complete') ? btn('review', 'Review the read') : ''}
165
+ <p class="note">These reads do not create a recurring schedule.</p>
166
+ <p class="wl-sec">Or add one task</p><div class="wl-first-task"><label>What needs your attention?<input data-f="taskTitle" maxlength="500" value="${esc(S.draft.title)}" autocomplete="off"></label><label>Due date (optional)<input data-f="taskDue" type="date" value="${esc(S.draft.due)}"></label></div>
167
+ ${btn('task', 'Add my task', { off: !S.draft.title.trim(), busy: 'task', busyText: 'Adding' })}${err()}
168
+ ${foot(btn('back', 'Back', { alt: true }), '')}`;
169
+ }
170
+ function viewFound() {
171
+ if (S.imported) return '<h1 id="wlH" tabindex="-1">Your work is already imported</h1><p>Open Home to use it, or go back to add a task.</p>' + err() + btn('finish', 'Open Home') + btn('back', 'Add work', { alt: true });
172
+ if (S.structure) {
173
+ const html = viewPortfolio();
174
+ return W.counts(S.structure, S).n ? html : html + '<p>The folder scan finished. No initiatives are selected for import.</p>' + btn('finish', 'Open Home') + btn('back', 'Add a task instead', { alt: true });
175
+ }
176
+ if (S.review !== 'sources' && (S.item || S.setup.item)) {
177
+ const item = S.item || S.setup.item;
178
+ return `<h1 id="wlH" tabindex="-1">Your first task is ready</h1><p class="wl-lede">${esc(item.title)}</p><p>${item.due ? 'Due ' + esc(item.due) : 'Added to Today'}</p><p>Open it on Home to set a date, mark it done, or brief Claude when connected.</p>${err()}${foot(btn('back', 'Add more work', { alt: true }), btn('finish', 'Open Home'))}`;
179
+ }
180
+ return `<h1 id="wlH" tabindex="-1">Here’s what PMOS found</h1>${readSummary()}${S.readItems.length ? '<ul class="wl-list">' + S.readItems.map(i => '<li>' + esc(i.title || i.key || 'Work item') + '</li>').join('') + '</ul>' : '<p>A completed read may contain no open items in this scope. Review your sources on Home or add a task.</p>'}${err()}${foot(btn('back', 'Add or change work', { alt: true }), btn('finish', 'Use these reads and open Home'))}`;
181
+ }
182
+ const VIEWS = { claude: viewClaude, sources: viewSources, found: viewFound };
165
183
  function draw(focusHead) {
184
+ if (disposeClaude) { disposeClaude(); disposeClaude = null; }
166
185
  const at = Math.max(0, W.STEPS.findIndex(([k]) => k === S.step));
167
186
  $('#wlSteps').innerHTML = W.STEPS.map(([, t], i) => `<li data-s="${i < at ? 'done' : i === at ? 'now' : 'todo'}"${i === at ? ' aria-current="step"' : ''}><b><i></i></b><span>${esc(t)}</span></li>`).join('');
168
187
  $('#wlCount').textContent = `Set up · step ${at + 1} of ${W.STEPS.length}`;
@@ -171,6 +190,11 @@ function draw(focusHead) {
171
190
  const y = scrollY;
172
191
  $('#wlCard').innerHTML = VIEWS[S.step]();
173
192
  $('#wlCard').setAttribute('aria-busy', S.busy ? 'true' : 'false');
193
+ if (S.step === 'claude' && S.ws) disposeClaude = mountClaudeSetup($('#wlClaude'), { ws: S.ws,
194
+ onReady: async () => { S.ready = true; S.manual = false; S.step = 'sources'; await remember(); draw(true); },
195
+ onManual: async () => { S.manual = true; S.step = 'sources'; await remember(); draw(true); } });
196
+ const permissionTerminal = $('#wlPermissions');
197
+ if (permissionTerminal && S.permissionSession) signInTerminal(permissionTerminal, S.permissionSession).then(stop => { disposeClaude = stop; }).catch(() => { permissionTerminal.textContent = 'The terminal could not load. Reload and reopen it.'; });
174
198
  if (focusHead) { const h = $('#wlH'); if (h) h.focus({ preventScroll: true }); scrollTo(0, 0); }
175
199
  else {
176
200
  scrollTo(0, y);
@@ -185,11 +209,15 @@ function draw(focusHead) {
185
209
  document.addEventListener('click', (e) => {
186
210
  const b = e.target.closest('[data-w]'); if (!b || b.disabled || !b.closest('#wlRoot')) return;
187
211
  const a = b.dataset.w, id = b.dataset.id;
188
- if (a === 'about') saveAbout();
189
- else if (a === 'back') go(S.step === 'found' ? 'sources' : 'about');
212
+ if (a === 'back') { S.structure = null; go(S.step === 'found' ? 'sources' : 'claude'); remember(); }
190
213
  else if (a === 'folder') addFolder();
191
214
  else if (a === 'tool') { S.pick[b.dataset.k] = !S.pick[b.dataset.k]; draw(); }
192
215
  else if (a === 'scan') scan();
216
+ else if (a === 'task') addTask();
217
+ else if (a === 'read') run('read', readTools);
218
+ else if (a === 'permissions') run('permissions', async () => { const state = await pmGet('/api/setup/state?ws=' + encodeURIComponent(S.ws)); const r = await setupPost('login', { profile: state && state.claude && state.claude.selected, purpose: 'permissions' }); if (r && r.ok) S.permissionSession = r.session; else fail(r, 'Opening Claude connections'); });
219
+ else if (a === 'review') { S.review = 'sources'; S.step = 'found'; S.structure = null; remember(); draw(true); }
220
+ else if (a === 'finish') run('finish', finish);
193
221
  else if (a === 'inc') { S.checked[id] = !S.checked[id]; if (!S.checked[id]) S.edit[id] = false; draw(); }
194
222
  else if (a === 'edit') { S.edit[id] = !S.edit[id]; draw(); }
195
223
  else if (a === 'defs') { S.defs = !S.defs; draw(); }
@@ -200,7 +228,13 @@ document.addEventListener('click', (e) => {
200
228
  const card = $('#wlCard');
201
229
  card.addEventListener('input', (e) => {
202
230
  const t = e.target, f = t.dataset && t.dataset.f; if (!f) return;
203
- if (W.FIELDS.includes(f)) S.about[f] = t.value;
231
+ if (f === 'taskTitle' || f === 'taskDue') {
232
+ if (S.setup.task_request_id === S.draft.request_id) S.draft.request_id = crypto.randomUUID();
233
+ S.draft[f === 'taskTitle' ? 'title' : 'due'] = t.value;
234
+ const add = document.querySelector('[data-w="task"]'); if (add) add.disabled = !S.draft.title.trim();
235
+ clearTimeout(S.saveTimer); S.saveTimer = setTimeout(remember, 400);
236
+ }
237
+ else if (W.FIELDS.includes(f)) S.about[f] = t.value;
204
238
  else if (f === 'title') S.titles[t.dataset.id] = t.value;
205
239
  else if (f === 'answer') {
206
240
  const q = ((S.structure && S.structure.questions) || []).find((x) => x.id === t.dataset.id);
@@ -220,17 +254,28 @@ async function start() {
220
254
  const all = (list && list.workspaces) || [];
221
255
  const mine = all.find((w) => w.id === S.ws) || (!S.ws ? all[0] : null);
222
256
  if (!mine) { S.error = 'This folder is not open in PMOS. Start pmos in the folder, then reload.'; $('#wlCard').setAttribute('aria-busy', 'false'); draw(); return; }
223
- S.ws = mine.id; S.folder = { name: mine.name, root: mine.root };
257
+ S.ws = mine.id; await refreshSetup();
258
+ S.step = W.STEPS.some(([k]) => k === S.setup.step) ? S.setup.step : 'claude';
259
+ if (S.setup.draft) S.draft = S.setup.draft;
260
+ S.manual = !!S.setup.manual; S.review = S.setup.review || null;
261
+ S.folder = { name: mine.name, root: mine.root };
224
262
  const st = await pmGet(`/api/onboarding/status?ws=${encodeURIComponent(S.ws)}`);
225
- if (st && st.ok && st.state === 'imported') {
226
- const live = (st.imports || []).filter((i) => !i.retracted).pop();
227
- if (live) { location.replace('/premium.html?ws=' + encodeURIComponent(S.ws) + '&first=' + encodeURIComponent(live.import_id)); return; }
228
- }
263
+ S.imported = !!(st && st.ok && st.state === 'imported');
264
+ if (W.STEPS.some(([k]) => k === params.get('step'))) S.step = params.get('step');
229
265
  S.about = W.aboutOf(await pmGet('/api/proactive/settings'));
230
266
  if (params.get('step') === 'found') { // back from "Undo this import": the scan is still on disk, but its first-look sentence is not, so the page does not show one
231
267
  const sr = await pmGet(`/api/onboarding/structure?ws=${encodeURIComponent(S.ws)}`);
232
268
  if (sr && sr.ok) { S.structure = sr; Object.assign(S, W.startChoices(sr)); S.step = 'found'; } else fail(sr, 'Reading the portfolio');
233
269
  }
270
+ if (S.step === 'found' && !S.setup.item) {
271
+ const sr = await pmGet('/api/onboarding/structure?ws=' + encodeURIComponent(S.ws));
272
+ if (sr && sr.ok) { S.structure = sr; Object.assign(S, W.startChoices(sr)); }
273
+ }
234
274
  draw(true);
235
275
  }
276
+ setInterval(async () => {
277
+ if (!S.ws || !S.readRows.some(r => r.state === 'reading') || S.busy) return;
278
+ const before = JSON.stringify(S.readRows); await refreshSetup();
279
+ if (before !== JSON.stringify(S.readRows) && S.step !== 'claude') draw();
280
+ }, 3000);
236
281
  start();
@@ -2696,3 +2696,19 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
2696
2696
  .ctxmore[open]>summary{display:none}
2697
2697
  .ctxmore>.ctxc{display:contents}
2698
2698
  .ctxmore:not([open])>.ctxc{display:none}
2699
+
2700
+ /* Claude-ready onboarding: shared sign-in panel and persistent setup checklist. */
2701
+ .cs-panel { display: grid; gap: 14px; max-width: 100%; }
2702
+ .cs-panel p { margin: 0; }
2703
+ .cs-label { display: grid; gap: 6px; }
2704
+ .cs-label select { max-width: 100%; min-height: 44px; color: inherit; background: inherit; border: 1px solid currentColor; border-radius: 8px; padding: 8px; }
2705
+ .cs-actions { display: flex; flex-wrap: wrap; gap: 8px; }
2706
+ .cs-term { height: 320px; width: 100%; min-width: 0; overflow: hidden; }
2707
+ .cs-term .xterm { height: 100%; }
2708
+ .cs-checklist { padding: 16px; margin: 8px; border: 1px solid currentColor; border-radius: 12px; font-size:var(--fs-3); }
2709
+ .cs-checklist p { margin: 8px 0; }
2710
+ .cs-checklist a { display: inline-block; min-height: 44px; padding: 10px 0; color: inherit; text-decoration: underline; }
2711
+ .wl-first-task { display: grid; gap: 12px; margin: 16px 0; }
2712
+ .wl-first-task label { display: grid; gap: 6px; }
2713
+ .wl-first-task input { min-height: 44px; width: 100%; box-sizing: border-box; }
2714
+ .wl-source-progress { margin: 12px 0; }
@@ -35,7 +35,7 @@ const REMOVE = [
35
35
  '.po-grip', '.bd-nxa',
36
36
  '#bdChipset > :not(.tg-lgd)', '#askDates', '.tg-ft',
37
37
  '.cz-vw-ib[aria-label="Discuss in chat"]', '.cz-vw-ib[aria-label="More"]', '.iv-addp', '.iv-prog', '.iv-plus', '.iv-car', '.iv-scgn', '.iv-gx-a',
38
- '.ab-lk', '[data-ivs-view="kanban"]', '.ivs-cols', '.ivs-h:has(+ .ivs-cols)', '[data-ivs-more]', '.iv-tasks:has(.iv-q)', '.iv-th .iv-ib', '.iv-th .iv-plus',
38
+ '.ab-lk', '[data-ivs-view="kanban"]', '.ivs-cols', '.ivs-h:has(+ .ivs-cols)', '[data-ivs-more]', '.iv-tasks .ig-emp', '.iv-tasks .ivk-h', '.iv-tasks .ig-read', '.iv-th .iv-ib', '.iv-th .iv-plus',
39
39
  ];
40
40
  /** Controls whose words are the content (a title, a date, a name, a program's milestone in the Deliveries lane): set as plain text, same look. A program's
41
41
  * milestone opens the program's charter in the workspace; a share does not hold the charter. */
@@ -0,0 +1,22 @@
1
+ /* setup-checklist.js — exact-profile repair on Home (initiative claude-onboarding-build). Zero is silence: the card shows only when the
2
+ * Claude login PMOS saved has really failed (signed out, gone, unreachable, refused). "Not checked since the restart" is normal and shows
3
+ * nothing. Its one action reopens the setup conversation at the login test, for that same profile; PMOS never switches accounts itself. */
4
+ import { pmGet } from './http.js';
5
+ const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
6
+ const BROKEN = new Set(['signed_out', 'profile_missing', 'missing_cli', 'account', 'network', 'unsupported', 'save_failed', 'changed', 'unknown']);
7
+ export function mountSetupChecklist() {
8
+ const el = document.createElement('aside'); el.className = 'ut-card cs-checklist'; el.hidden = true; el.setAttribute('aria-label', 'Claude login');
9
+ let stopped = false;
10
+ async function refresh() {
11
+ if (stopped || document.hidden) return;
12
+ const r = await pmGet('/api/onboard/state');
13
+ const st = r && r.ok && r.claude && r.claude.status;
14
+ if (!st || !BROKEN.has(st.state)) { el.hidden = true; return; }
15
+ el.hidden = false;
16
+ el.innerHTML = `<b>Claude needs attention</b><p>${esc(st.message)}</p><a class="ut-btn sm" href="/premium.html?onboard=1">Test the login again</a>`;
17
+ }
18
+ refresh(); const timer = setInterval(refresh, 60000);
19
+ window.addEventListener('focus', refresh);
20
+ window.addEventListener('beforeunload', () => { stopped = true; clearInterval(timer); window.removeEventListener('focus', refresh); }, { once: true });
21
+ return el;
22
+ }
@@ -23,6 +23,7 @@
23
23
  <link rel="stylesheet" href="/pm/cozy-today.css" />
24
24
  <link rel="stylesheet" href="/pm/home-impact.css" />
25
25
  <link rel="stylesheet" href="/pm/cozy-panel.css" />
26
+ <link rel="stylesheet" href="/pm/cozy-onboard.css" />
26
27
  </head>
27
28
  <body class="cz cz-home">
28
29
  <header class="hm-top" id="hmTop">
@@ -537,11 +537,11 @@ function writeAutoFlags(flags) {
537
537
  catch (e) { warnWriteFail('auto-session-flags.json', e); return `the flags could not be saved — ${String((e && e.code) || 'write failed')}`; }
538
538
  }
539
539
  // The default profile for an agent, for a start the PM pressed that named no profile at all (`undefined`). An explicit
540
- // null means "no profile" and is never replaced. A remembered id that no longer reads yields undefined: the start then
541
- // runs with no profile and says nothing it did not do, rather than failing on a preference the PM did not just choose.
540
+ // null means "no profile" and is never replaced. Preserve a missing remembered id so spawn refuses
541
+ // the unavailable setup rather than silently using another account.
542
542
  function defaultProfileFor(agent) {
543
543
  const id = readPrefs()[agent];
544
- return typeof id === 'string' && id && resolveProfileForSpawn(id).ok ? id : undefined;
544
+ return typeof id === 'string' && id ? id : undefined;
545
545
  }
546
546
  // The merged environment a session actually runs under. The overlay goes ON TOP of sessionEnv(),
547
547
  // AFTER the marker-stripping (R3) — never instead of it, or a profile would silently re-enable the
@@ -4252,6 +4252,23 @@ function resolveProfileForSpawn(id) {
4252
4252
  /* The type of work a session is doing (0.55.1): the dock shows it under the session's name. Set by what started the
4253
4253
  * session (a skill, a schedule) or chosen by the PM; changed later from the session's ⋯ sheet. Optional: a session
4254
4254
  * with none shows nothing, and a session started before this field existed restores with none. */
4255
+ const claudeSetup = require('./lib/claude-readiness').create({
4256
+ stateDir: STATE, home: os.homedir(), readProfiles: readProfilesNow, readPrefs,
4257
+ envFor: sessionEnvWithProfile,
4258
+ savePreference: (id) => { const p = readPrefs(); p.claude = id; return writePrefs(p); },
4259
+ });
4260
+ claudeSetup.ensureOwn = () => require('./lib/own-profile').ensure(os.homedir(), profilesLib.profilesDir(os.homedir()));
4261
+ claudeSetup.login = (id, ws, purpose, cwd) => {
4262
+ const candidate = claudeSetup.candidate(id);
4263
+ if (!candidate) return { ok: false, error: 'Choose an available Claude profile.' };
4264
+ let pinned;
4265
+ try { pinned = claudeSetup.pinDefault(candidate); } catch { return { ok: false, error: 'The selected configuration could not be saved for sign-in.' }; }
4266
+ const origin = purpose === 'permissions' ? 'onboarding-permissions' : 'onboarding-login';
4267
+ const live = [...sessions.values()].find(s => s.origin === origin && s.profile === pinned && s.state !== 'exited');
4268
+ const s = live || spawnSession({ agent: 'claude', profile: pinned, ws, ...(cwd ? { cwd } : {}), name: purpose === 'permissions' ? 'Claude connections and permissions' : 'Claude sign-in', origin, launchFlags: purpose === 'permissions' ? [] : [{ flag: '--safe-mode' }] });
4269
+ return s && s.state !== 'exited' ? { ok: true, session: s.id, profile: pinned } : { ok: false, error: 'Claude could not start. Check its installation and this profile.' };
4270
+ };
4271
+
4255
4272
  const WORK_TYPES = Object.freeze(['research', 'prototype', 'prd', 'build', 'review', 'report', 'general']);
4256
4273
  const workTypeOrNull = (v) => (WORK_TYPES.includes(String(v || '').toLowerCase()) ? String(v).toLowerCase() : null);
4257
4274
 
@@ -4424,6 +4441,7 @@ function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDi
4424
4441
  : `exited (code ${code})`;
4425
4442
  // What the Sessions card says about this run (lib/routes-runs.js): the agent's own first line, or the real reason it failed.
4426
4443
  s.outcome = headlessLib.outcomeOf(r, { code, signal, timedOut, stopped: !!s.stoppedByPm, timeoutMin });
4444
+ if (s.outcome.auth) claudeSetup.invalidate(s.profile);
4427
4445
  if (!s.outcome.ok && err.trim() && !r.ok) s.outcome.why += ' ' + err.trim().split('\n').filter(Boolean).pop().slice(0, 200);
4428
4446
  if (s.note !== 'exited (code 0)') say(`\x1b[38;5;203m[${s.note}]\x1b[0m\n`);
4429
4447
  // agent-orchestrator: a failed run that hit the Claude usage limit holds new orchestrator starts until the reset it names (lib/orchestrator-quota.js).
@@ -4491,6 +4509,8 @@ function spawnSessionInner({ name, agent, cwd, ws, origin, initialInput, profile
4491
4509
  const cmd = isShell ? (commandExists(SHELL) ? SHELL : 'sh') : agent;
4492
4510
  // a session's working directory is confined to its OWN workspace root (R3)
4493
4511
  let workdir = cwd && insideRoot(root, path.resolve(root, cwd)) ? path.resolve(root, cwd) : root;
4512
+ // claude-onboarding-build: the first sign-in happens before any project exists, so it runs in its own empty folder under the state directory.
4513
+ if (origin === 'onboarding-login' && cwd && path.isAbsolute(cwd) && insideRoot(STATE, cwd) && isDir(cwd)) workdir = cwd;
4494
4514
  // horizon-scan: the web run reads untrusted pages, so it runs in an empty scratch folder and never in the repository. Only a headless run may ask for it.
4495
4515
  if (scratch) {
4496
4516
  if (!(initialInput && headlessLib.WEB_KINDS.includes(headlessLib.kindFor({ agent, origin: tag })))) return exitedSession({ id, ws: w ? w.id : wsId(SELF_ROOT), root, name: (name && String(name).trim()) || agent, agent, origin: tag, profile: null, profileRefusal: null, plan_item: null, token: sessionToken }, root, 'a scratch folder is only for a background web scan run');
@@ -6884,8 +6904,10 @@ async function handleRequest(req, res) {
6884
6904
  }, (e) => { res.writeHead(500); res.end(String(e && e.message)); });
6885
6905
  });
6886
6906
  }
6887
- if (p === '/welcome' || p === '/welcome.html') {
6888
- res.writeHead(302, { Location: '/premium-welcome.html' + url.search, 'Cache-Control': 'no-store' });
6907
+ // claude-onboarding-build: first run is a conversation in Home now. The old Welcome pages (/welcome and the three-step /premium-welcome.html)
6908
+ // open Home's project setup; their old query (?ws=, ?step=) has nothing left to say there.
6909
+ if (p === '/welcome' || p === '/welcome.html' || p === '/premium-welcome' || p === '/premium-welcome.html') {
6910
+ res.writeHead(302, { Location: '/premium.html?onboard=1', 'Cache-Control': 'no-store' });
6889
6911
  return res.end();
6890
6912
  }
6891
6913
  const PAGES = { '/': 'premium.html', '/index.html': 'premium.html', '/premium': 'premium.html', '/premium.html': 'premium.html', '/premium-board': 'premium-board.html', '/premium-board.html': 'premium-board.html', '/premium-intelligence': 'premium-intelligence.html', '/premium-intelligence.html': 'premium-intelligence.html', '/premium-insights': 'premium-intelligence.html', '/premium-insights.html': 'premium-intelligence.html', '/premium-welcome': 'premium-welcome.html', '/premium-welcome.html': 'premium-welcome.html', '/premium-viewer': 'premium-viewer.html', '/premium-viewer.html': 'premium-viewer.html', '/premium-rec': 'premium-rec.html', '/premium-rec.html': 'premium-rec.html', '/premium-workflows': 'premium-workflows.html', '/premium-workflows.html': 'premium-workflows.html' };
@@ -10438,7 +10460,7 @@ async function handleRequest(req, res) {
10438
10460
  // meeting-notes Run 1: the Notes routes keep notes in the per-user runtime directory and start the agent-summary session.
10439
10461
  if (req.method === 'POST' && !(req.headers && req.headers['x-pmos-session'])) orchGate.touch(); // agent-orchestrator: a page press by the PM
10440
10462
  if (await routeModules.dispatch(req, res, url, { orchestrator: { gate: orchGate, running: () => orchSpawn.running(), health: orchHealth, keepRate: orchKeepRate }, proposalRuns, metricDraftRuns, metricReadRuns, metricReadHours, tellGoalAlert: goalAlertTell, json, readBody, getWs, invalidateNeedsAgg, boardCache, consoleState, stateDirFor, sessionList, initiativeIndex,
10441
- runtimeDir: STATE, homeRoot: HOME_ENABLED ? SELF_ROOT : null, spawnSession, jevModelOpts, sendToSession, endSupersededRuns, proSettings,
10463
+ runtimeDir: STATE, claudeSetup, registerWorkspace, pickFolder, broadcast, workspaceList: () => [...workspaces.values()], homeRoot: HOME_ENABLED ? SELF_ROOT : null, spawnSession, jevModelOpts, sendToSession, endSupersededRuns, proSettings,
10442
10464
  // premium-chat-session: every premium chat panel is an interactive Claude Code session the PM talks to (text as typed, `/` kept)
10443
10465
  chatSessions,
10444
10466
  // report-workspace: the schedule store a recurring report registers its draft-only schedule in, a skill's body, and the stop of a headless run
@@ -27,6 +27,6 @@ Procedure:
27
27
  `{"id", "title", "start", "end", "attendees": ["Display Name", …], "initiative": "<initiative id or null>"}`
28
28
  `id` is the calendar's own id for that event (for a repeating meeting, the id of that one occurrence). Use the same id on every run, never a made-up one: PMOS keeps one copy per id. If an id changes anyway, the window import removes the old copy.
29
29
  `start` and `end` are ISO times with the offset, for example `2026-10-12T09:00:00+07:00`. An all-day event has the date only.
30
- 3. Run `pmos calendar import --from <scratch>/calendar.json --sensitivity internal --window <today>..<day 14>`, with both days as `YYYY-MM-DD`. The window makes PMOS drop a saved event in those days that is not in the file, so a meeting that moved, was declined or was cancelled leaves its old slot. If it refuses the file, fix what it names and run it once more.
30
+ 3. Run `pmos calendar import --from <scratch>/calendar.json --sensitivity internal --window <today>..<day 14>`, with both days as `YYYY-MM-DD`. If the calendar was reached successfully and returned no meetings, omit `--window` and import the empty list once; this records the read without removing saved meetings. The window makes PMOS drop a saved event in those days that is not in the file, so a meeting that moved, was declined or was cancelled leaves its old slot. If it refuses the file, fix what it names and run it once more.
31
31
  4. Delete the scratch file.
32
32
  5. Report in four short lists: Imported (the count, and the first and last day), Left out (the count of private events), Not reached, and Needs you (only when something blocked the pull).
@@ -119,7 +119,10 @@
119
119
  "needs-overdue.test.js",
120
120
  "briefing-scope.test.js",
121
121
  "settings-store.test.js",
122
- "priority.test.js"
122
+ "priority.test.js",
123
+ "claude-readiness.test.js",
124
+ "setup-routes.test.js",
125
+ "project-onboard.test.js"
123
126
  ],
124
127
  "panels": [
125
128
  "pm-r7-test.js",
@@ -129,8 +132,7 @@
129
132
  "pm-r25-test.js",
130
133
  "pm-r26-test.js"
131
134
  ],
132
- "ui": [
133
- ],
135
+ "ui": [],
134
136
  "seconds": {
135
137
  "test.js": 48,
136
138
  "proactive.test.js": 4,
@@ -182,6 +184,7 @@
182
184
  "session-rail.test.js": 1,
183
185
  "briefing-premium-metrics.test.js": 1,
184
186
  "premium-welcome.test.js": 1,
187
+ "project-onboard.test.js": 3,
185
188
  "calendar-events.test.js": 1,
186
189
  "calendar-supersede.test.js": 1,
187
190
  "tracker-read.test.js": 1,
@@ -1,5 +1,5 @@
1
1
  {
2
- "_comment": "Initiative briefing-premium: the premium Briefing page, served from a fixture model, checked against the mockup; and its reply box against the real server with a stub claude.",
2
+ "_comment": "Initiative briefing-premium: the premium Briefing page, served from a fixture model, checked against the mockup; and its reply box against the real server with a stub claude. premium-welcome-test.js is retired (initiative claude-onboarding-build): /premium-welcome.html now redirects to the Home setup conversation, which project-onboard-flow-test.js covers.",
3
3
  "panels": [
4
4
  "briefing-premium-test.js",
5
5
  "briefing-premium-work-test.js",
@@ -15,7 +15,6 @@
15
15
  "home-other-product-test.js",
16
16
  "briefing-premium-sources-test.js",
17
17
  "briefing-premium-metrics-test.js",
18
- "premium-welcome-test.js",
19
18
  "briefing-premium-agent-server.test.js"
20
19
  ],
21
20
  "seconds": {
@@ -32,7 +31,6 @@
32
31
  "briefing-premium-products-test.js": 90,
33
32
  "briefing-premium-sources-test.js": 90,
34
33
  "briefing-premium-metrics-test.js": 120,
35
- "premium-welcome-test.js": 120,
36
34
  "briefing-premium-agent-server.test.js": 40,
37
35
  "home-other-product-test.js": 60
38
36
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Initiative claude-onboarding-build: the project-first setup conversation in the Cozy Home, against the real server with a fixture claude (no live account or connector).",
3
+ "panels": [
4
+ "project-onboard-flow-test.js"
5
+ ],
6
+ "seconds": {
7
+ "project-onboard-flow-test.js": 90
8
+ }
9
+ }