daily-focus 1.2.0-dev.9 → 2.0.0-dev.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/public/app.js CHANGED
@@ -1110,6 +1110,24 @@ function postObjective(objective, blocker) {
1110
1110
  function postListCalendars() {
1111
1111
  return postJson("/api/calendars/list", {});
1112
1112
  }
1113
+ function postSetupAnswer(step, answer) {
1114
+ return post("/api/onboarding/answer", { step, answer });
1115
+ }
1116
+ function postSetupRevise(step, text, draft) {
1117
+ return post("/api/onboarding/revise", { step, text, draft });
1118
+ }
1119
+ function postSetupDetect() {
1120
+ return post("/api/onboarding/detect");
1121
+ }
1122
+ function postSetupRetry(step) {
1123
+ return post("/api/onboarding/retry", { step });
1124
+ }
1125
+ function postSetupFinish() {
1126
+ return post("/api/onboarding/finish");
1127
+ }
1128
+ async function fetchSetupSources() {
1129
+ return jsonFrom(await fetch("/api/onboarding/sources"), "GET /api/onboarding/sources");
1130
+ }
1113
1131
 
1114
1132
  // client/state.ts
1115
1133
  var VIEWS = ["today", "board", "tickets", "settings"];
@@ -1144,7 +1162,14 @@ function createUi(initial = {}) {
1144
1162
  settingsError: y3(initial.settingsError ?? null),
1145
1163
  settingsSaving: y3(initial.settingsSaving ?? false),
1146
1164
  texts: y3(initial.texts ?? {}),
1147
- calendars: y3(initial.calendars ?? null)
1165
+ calendars: y3(initial.calendars ?? null),
1166
+ setupDrafts: y3(initial.setupDrafts ?? /* @__PURE__ */ new Map()),
1167
+ setupEditing: y3(initial.setupEditing ?? null),
1168
+ setupConfirm: y3(initial.setupConfirm ?? null),
1169
+ setupBusy: y3(initial.setupBusy ?? null),
1170
+ setupError: y3(initial.setupError ?? null),
1171
+ setupTell: y3(initial.setupTell ?? /* @__PURE__ */ new Map()),
1172
+ setupSources: y3(initial.setupSources ?? null)
1148
1173
  };
1149
1174
  }
1150
1175
  function isView(value) {
@@ -1666,7 +1691,7 @@ async function loadSettings() {
1666
1691
  showToast(`Could not load the settings: ${err.message}`);
1667
1692
  }
1668
1693
  }
1669
- async function sendSettings(values, fromDraft) {
1694
+ async function sendSettings(values) {
1670
1695
  if (ui.settingsSaving.value) return;
1671
1696
  n2(() => {
1672
1697
  ui.settingsSaving.value = true;
@@ -1676,17 +1701,14 @@ async function sendSettings(values, fromDraft) {
1676
1701
  const page = await postSettings(values);
1677
1702
  n2(() => {
1678
1703
  ui.settings.value = page;
1679
- if (fromDraft) {
1680
- const draft = new Map(ui.settingsDraft.value);
1681
- for (const [key, value] of Object.entries(values)) if (draft.get(key) === value) draft.delete(key);
1682
- ui.settingsDraft.value = draft;
1683
- }
1704
+ const draft = new Map(ui.settingsDraft.value);
1705
+ for (const [key, value] of Object.entries(values)) if (draft.get(key) === value) draft.delete(key);
1706
+ ui.settingsDraft.value = draft;
1684
1707
  });
1685
1708
  restartToast(page);
1686
1709
  if (page.restart === "waiting") void followRestart();
1687
1710
  } catch (err) {
1688
- if (fromDraft) ui.settingsError.value = err.message;
1689
- else showToast(`Could not save: ${err.message}`);
1711
+ ui.settingsError.value = err.message;
1690
1712
  } finally {
1691
1713
  ui.settingsSaving.value = false;
1692
1714
  }
@@ -1764,6 +1786,60 @@ async function listCalendars() {
1764
1786
  ui.calendars.value = err.message;
1765
1787
  }
1766
1788
  }
1789
+ async function setupRequest(step, send) {
1790
+ if (ui.setupBusy.value) return false;
1791
+ n2(() => {
1792
+ ui.setupBusy.value = step;
1793
+ ui.setupError.value = null;
1794
+ });
1795
+ try {
1796
+ adoptState(await send());
1797
+ return true;
1798
+ } catch (err) {
1799
+ ui.setupError.value = { step, message: err.message };
1800
+ return false;
1801
+ } finally {
1802
+ ui.setupBusy.value = null;
1803
+ }
1804
+ }
1805
+ function forgetDraft(step) {
1806
+ if (!ui.setupDrafts.value.has(step)) return;
1807
+ const next = new Map(ui.setupDrafts.value);
1808
+ next.delete(step);
1809
+ ui.setupDrafts.value = next;
1810
+ }
1811
+ async function answerSetup(step, answer) {
1812
+ if (!await setupRequest(step, () => postSetupAnswer(step, answer))) return;
1813
+ n2(() => {
1814
+ forgetDraft(step);
1815
+ if (ui.setupEditing.value === step) ui.setupEditing.value = null;
1816
+ if (ui.setupConfirm.value === step) ui.setupConfirm.value = null;
1817
+ ui.setupSources.value = null;
1818
+ });
1819
+ afterRender(() => {
1820
+ const heading = document.querySelector('.onboarding__card[data-current="true"] h2');
1821
+ heading?.focus({ preventScroll: true });
1822
+ heading?.closest(".onboarding__card")?.scrollIntoView({ block: "center", behavior: "smooth" });
1823
+ });
1824
+ }
1825
+ async function reviseSetup(step, text, draft) {
1826
+ if (!await setupRequest(step, () => postSetupRevise(step, text, draft))) return;
1827
+ n2(() => {
1828
+ forgetDraft(step);
1829
+ if (ui.setupConfirm.value === step) ui.setupConfirm.value = null;
1830
+ const tell = new Map(ui.setupTell.value);
1831
+ tell.delete(step);
1832
+ ui.setupTell.value = tell;
1833
+ });
1834
+ }
1835
+ async function loadSetupSources() {
1836
+ ui.setupSources.value = "loading";
1837
+ try {
1838
+ ui.setupSources.value = await fetchSetupSources();
1839
+ } catch (err) {
1840
+ ui.setupSources.value = { error: err.message };
1841
+ }
1842
+ }
1767
1843
  function openSettings(section2 = null) {
1768
1844
  if (ui.view.value !== "settings") {
1769
1845
  try {
@@ -1897,14 +1973,39 @@ var handlers = {
1897
1973
  ui.settingsDraft.value = /* @__PURE__ */ new Map();
1898
1974
  ui.settingsError.value = null;
1899
1975
  }),
1900
- saveSettings: (keys) => void sendSettings(Object.fromEntries([...ui.settingsDraft.value].filter(([key]) => !keys || keys.includes(key))), true),
1901
- chooseSettings: (values) => void sendSettings(values, false),
1976
+ saveSettings: () => void sendSettings(Object.fromEntries(ui.settingsDraft.value)),
1902
1977
  loadText: (name) => void loadText(name),
1903
1978
  editText: (name, text) => patchText(name, { draft: text }),
1904
1979
  saveText: (name, overwrite) => void saveText(name, overwrite),
1905
1980
  reloadText: (name) => void loadText(name),
1906
1981
  saveObjective: (objective, blocker) => void saveObjective(objective, blocker),
1907
- listCalendars: () => void listCalendars()
1982
+ listCalendars: () => void listCalendars(),
1983
+ answerSetup: (step, answer) => void answerSetup(step, answer),
1984
+ editSetupDraft: (step, answer, version) => {
1985
+ if (answer === null) return forgetDraft(step);
1986
+ const next = new Map(ui.setupDrafts.value);
1987
+ next.set(step, { version, answer });
1988
+ ui.setupDrafts.value = next;
1989
+ },
1990
+ editSetupStep: (step) => n2(() => {
1991
+ ui.setupEditing.value = step;
1992
+ ui.setupError.value = null;
1993
+ }),
1994
+ confirmSetup: (step) => {
1995
+ ui.setupConfirm.value = step;
1996
+ },
1997
+ editSetupTell: (step, text) => {
1998
+ const next = new Map(ui.setupTell.value);
1999
+ next.set(step, text);
2000
+ ui.setupTell.value = next;
2001
+ },
2002
+ reviseSetup: (step, text, draft) => void reviseSetup(step, text, draft),
2003
+ retrySetup: (step) => void setupRequest(step, () => postSetupRetry(step)),
2004
+ detectSetup: () => void setupRequest("detect", () => postSetupDetect()),
2005
+ finishSetup: () => void setupRequest("finish", () => postSetupFinish()).then((finished) => {
2006
+ if (finished && state.value?.restart === "waiting") void followRestart();
2007
+ }),
2008
+ loadSetupSources: () => void loadSetupSources()
1908
2009
  };
1909
2010
 
1910
2011
  // client/format.ts
@@ -2378,10 +2479,11 @@ function agentRunBanner(run, state2, handlers2) {
2378
2479
  }
2379
2480
  };
2380
2481
  if (run.status === "running") {
2482
+ const helping = (run.steps ?? []).filter((step) => step.subagent && step.state === "running").length;
2381
2483
  return bannerNode(
2382
2484
  "info",
2383
2485
  "i",
2384
- `The morning agent is writing a new brief, started ${relativeTime(run.startedAt, now)}.`,
2486
+ `The morning agent is writing a new brief, started ${relativeTime(run.startedAt, now)}` + (helping ? `, with ${helping} ${helping === 1 ? "subagent" : "subagents"} at work.` : "."),
2385
2487
  [el("button", { type: "button", class: "button banner__action", onClick: () => handlers2.stopAgent() }, "Stop")],
2386
2488
  strip
2387
2489
  );
@@ -2550,7 +2652,8 @@ function ItemRow({ item, state: state2, ui: ui2, handlers: handlers2 }) {
2550
2652
  { class: "item__body" },
2551
2653
  el("p", { class: "item__title" }, title),
2552
2654
  renderMeta(item, state2, now),
2553
- item.detail ? el("p", { class: "item__detail" }, renderMarkdown(item.detail)) : null
2655
+ item.detail ? el("p", { class: "item__detail" }, renderMarkdown(item.detail)) : null,
2656
+ renderAhead(item.id, state2)
2554
2657
  ),
2555
2658
  renderActions(item, ui2, handlers2),
2556
2659
  ui2.menuFor.value === item.id ? renderSnoozeMenu(item, now, handlers2) : null
@@ -2614,6 +2717,38 @@ function rowPillTexts(row, state2) {
2614
2717
  function rowPills(row, state2) {
2615
2718
  return rowPillTexts(row, state2).map(([cls, text]) => el("span", { class: cls }, text));
2616
2719
  }
2720
+ var READING = {
2721
+ "assess-review": "Reading the review\u2026",
2722
+ "explain-ci": "Reading the failing checks\u2026"
2723
+ };
2724
+ function renderAhead(id, state2) {
2725
+ const auto = state2.assistant?.auto;
2726
+ const keys = auto?.rows?.[id];
2727
+ if (!auto || !keys?.length) return null;
2728
+ const turn = (state2.assistant.items?.[id]?.turns ?? []).findLast((candidate) => candidate.auto !== null && keys.includes(candidate.auto));
2729
+ const mark = el("span", { class: "item__ahead-mark", "aria-hidden": "true" }, "\u2726");
2730
+ if (!turn) {
2731
+ return auto.enabled && auto.usedToday >= auto.limit ? el("p", { class: "item__ahead item__ahead--quiet" }, mark, `Not answered ahead: today's ${auto.limit} are used.`) : null;
2732
+ }
2733
+ if (turn.status === "running") {
2734
+ return el("p", { class: "item__ahead item__ahead--quiet", "data-status": "running" }, mark, READING[turn.action ?? ""] ?? "Reading\u2026");
2735
+ }
2736
+ if (turn.status === "failed") {
2737
+ return el("p", { class: "item__ahead item__ahead--quiet" }, mark, "Could not answer ahead; the panel says why.");
2738
+ }
2739
+ const verdict = turn.status === "done" ? verdictLine(turn.reply) : "";
2740
+ if (!verdict) return null;
2741
+ return el(
2742
+ "p",
2743
+ { class: "item__ahead", title: `Answered ahead ${relativeTime(turn.endedAt ?? turn.startedAt, new Date(state2.now))}. Open the panel for the whole answer.` },
2744
+ mark,
2745
+ renderMarkdown(verdict)
2746
+ );
2747
+ }
2748
+ function verdictLine(reply) {
2749
+ const line = reply.split("\n").find((candidate) => candidate.trim() !== "") ?? "";
2750
+ return line.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*•]\s+|\d+[.)]\s+)/, "").trim();
2751
+ }
2617
2752
  function renderActions(item, ui2, handlers2) {
2618
2753
  const buttons = [];
2619
2754
  const act = (id, action) => () => handlers2.onAction(id, action);
@@ -2907,7 +3042,8 @@ function PullRow({ item: row, state: state2, ui: ui2, handlers: handlers2 }) {
2907
3042
  ),
2908
3043
  renderPullMeta(row, state2, now),
2909
3044
  renderPullReasons(row, now),
2910
- renderCancelledChecks(row)
3045
+ renderCancelledChecks(row),
3046
+ renderAhead(row.id, state2)
2911
3047
  ),
2912
3048
  renderPullActions(row, ui2, handlers2),
2913
3049
  ui2.menuFor.value === row.id ? renderSnoozeMenu(row, now, handlers2, { indefinite: false }) : null
@@ -3800,6 +3936,7 @@ function describeWhen(value, now) {
3800
3936
  return `${named ? day : date && date.getFullYear() === now.getFullYear() ? formatShortDay(value) : formatDay(value)} at ${formatTime(value)}`;
3801
3937
  }
3802
3938
  function runReport(run, ui2, handlers2) {
3939
+ if (run.steps?.length) return runWork(run, ui2, handlers2);
3803
3940
  const messages = run.messages ?? (run.report ? [run.report] : []);
3804
3941
  const running = run.status === "running";
3805
3942
  const earlier = !running && messages.length && messages.at(-1) === run.report ? messages.slice(0, -1) : messages;
@@ -3858,6 +3995,92 @@ function runReport(run, ui2, handlers2) {
3858
3995
  ) : null
3859
3996
  );
3860
3997
  }
3998
+ function runWork(run, ui2, handlers2) {
3999
+ const running = run.status === "running";
4000
+ if (running) {
4001
+ return el(
4002
+ "section",
4003
+ { class: "flyout__section" },
4004
+ el("h3", { class: "flyout__label" }, "What it is doing"),
4005
+ runSteps(run, run.steps, null, ui2, handlers2)
4006
+ );
4007
+ }
4008
+ const last = run.steps.findLast((step) => step.by === null && step.kind === "message");
4009
+ const steps2 = last && sameWords(last.text, run.report) ? run.steps.filter((step) => step !== last) : run.steps;
4010
+ const handoffs = steps2.filter((step) => step.subagent).length;
4011
+ return el(
4012
+ "section",
4013
+ { class: "flyout__section" },
4014
+ el("h3", { class: "flyout__label" }, run.status === "done" ? "Its report" : "What it said last"),
4015
+ run.report ? el("div", { class: "assistant__reply" }, renderMarkdownBlocks(run.report)) : el("p", { class: "flyout__empty" }, "It said nothing."),
4016
+ steps2.length ? el(
4017
+ "details",
4018
+ { class: "agent-run__list" },
4019
+ el(
4020
+ "summary",
4021
+ null,
4022
+ `How it got there, in ${steps2.length} ${steps2.length === 1 ? "step" : "steps"}` + (handoffs ? `, with ${handoffs} ${handoffs === 1 ? "subagent" : "subagents"}` : "")
4023
+ ),
4024
+ runSteps(run, steps2, null, ui2, handlers2)
4025
+ ) : null
4026
+ );
4027
+ }
4028
+ var NESTING = 4;
4029
+ function runSteps(run, steps2, by, ui2, handlers2, depth = 0) {
4030
+ const own = steps2.filter((step) => step.by === by);
4031
+ return el(
4032
+ "ol",
4033
+ { class: "assistant__steps agent-run__steps" },
4034
+ own.length ? null : el("li", { class: "assistant__step assistant__step--message" }, "Nothing yet."),
4035
+ own.map((step, index) => {
4036
+ if (step.kind === "message") {
4037
+ return el("li", { key: index, class: "agent-run__said" }, renderMarkdownBlocks(step.text));
4038
+ }
4039
+ if (step.subagent && depth < NESTING) return runHandoff(run, steps2, step, ui2, handlers2, depth, index);
4040
+ return el(
4041
+ "li",
4042
+ { key: index, class: "assistant__step", "data-state": step.state },
4043
+ el("span", { class: "assistant__step-text" }, step.text),
4044
+ step.detail ? el("code", { class: "assistant__step-detail", title: step.detail }, step.detail) : null
4045
+ );
4046
+ })
4047
+ );
4048
+ }
4049
+ function runHandoff(run, steps2, step, ui2, handlers2, depth, index) {
4050
+ const id = step.subagent;
4051
+ const own = steps2.filter((candidate) => candidate.by === id);
4052
+ const latest = own.at(-1);
4053
+ const calls = own.filter((candidate) => candidate.kind === "tool").length;
4054
+ const doing = step.state === "running" ? latest ? latest.kind === "message" ? firstLine(latest.text) : latest.text : "starting" : `${calls} ${calls === 1 ? "step" : "steps"}`;
4055
+ const key = `${run.id}:${id}`;
4056
+ const fallback = step.state === "running";
4057
+ const open = ui2.messageOpen.value.has(key) ? ui2.messageOpen.value.get(key) : fallback;
4058
+ return el(
4059
+ "li",
4060
+ { key: index, class: "assistant__step agent-run__handoff", "data-state": step.state },
4061
+ el(
4062
+ "details",
4063
+ {
4064
+ open,
4065
+ // As the message folds do: a toggle back to the default is forgotten.
4066
+ onToggle: (event) => {
4067
+ const isOpen = event.currentTarget.open;
4068
+ handlers2.toggleMessage(key, isOpen === fallback ? null : isOpen);
4069
+ }
4070
+ },
4071
+ el(
4072
+ "summary",
4073
+ null,
4074
+ el("span", { class: "assistant__step-text" }, `Subagent: ${step.detail ?? "unnamed"}`),
4075
+ el("span", { class: "assistant__step-detail" }, doing)
4076
+ ),
4077
+ runSteps(run, steps2, id, ui2, handlers2, depth + 1)
4078
+ )
4079
+ );
4080
+ }
4081
+ function sameWords(a4, b4) {
4082
+ return a4.replace(/\s+/g, " ").trim() === b4.replace(/\s+/g, " ").trim();
4083
+ }
3861
4084
  function runStatus(run, now, handlers2) {
3862
4085
  if (run.status === "running") {
3863
4086
  return el(
@@ -4225,6 +4448,7 @@ function renderAssistantTurn(turn, label, handlers2) {
4225
4448
  const action = turn.action ? label.get(turn.action) : null;
4226
4449
  const extra = action && turn.request.startsWith(action.request) ? turn.request.slice(action.request.length).trim() : null;
4227
4450
  const asked = action ? [el("strong", null, action.label), extra ? ` \u2014 ${extra}` : ""] : [turn.request];
4451
+ if (turn.auto) asked.push(el("span", { class: "assistant__auto", title: "The dashboard asked this on its own, when the pull request started waiting on you." }, " \xB7 asked ahead"));
4228
4452
  const { body, created } = turn.status === "done" ? splitCreated(turn.reply) : { body: turn.reply, created: [] };
4229
4453
  const status = turn.status === "failed" ? el("p", { class: "assistant__status assistant__status--bad" }, `Failed: ${turn.error}`) : turn.status === "aborted" ? el("p", { class: "assistant__status" }, `Stopped: ${turn.error}`) : null;
4230
4454
  return el(
@@ -4245,35 +4469,35 @@ function renderAssistantTurn(turn, label, handlers2) {
4245
4469
  );
4246
4470
  }
4247
4471
  function renderWork(turn) {
4248
- const steps = turn.steps ?? [];
4472
+ const steps2 = turn.steps ?? [];
4249
4473
  if (turn.status === "running") {
4250
4474
  return el(
4251
4475
  "div",
4252
4476
  { class: "assistant__work" },
4253
4477
  el("p", { class: "assistant__status assistant__status--working" }, "Working \xB7 ", k(Elapsed, { since: turn.startedAt })),
4254
- steps.length ? renderSteps(steps) : null
4478
+ steps2.length ? renderSteps(steps2) : null
4255
4479
  );
4256
4480
  }
4257
4481
  const took = durationBetween(turn.startedAt, turn.endedAt);
4258
- if (!steps.length) return took ? el("p", { class: "assistant__took" }, `Answered in ${took}`) : null;
4259
- const failed = steps.filter((step2) => step2.state === "failed").length;
4482
+ if (!steps2.length) return took ? el("p", { class: "assistant__took" }, `Answered in ${took}`) : null;
4483
+ const failed = steps2.filter((step) => step.state === "failed").length;
4260
4484
  const summary = [
4261
4485
  took ? `${turn.status === "done" ? "Worked" : "Ran"} for ${took}` : null,
4262
- `${steps.length} ${steps.length === 1 ? "step" : "steps"}`,
4486
+ `${steps2.length} ${steps2.length === 1 ? "step" : "steps"}`,
4263
4487
  failed ? `${failed} failed` : null
4264
4488
  ].filter(Boolean).join(" \xB7 ");
4265
- return el("details", { class: "assistant__work", open: turn.status === "failed" }, el("summary", null, summary), renderSteps(steps));
4489
+ return el("details", { class: "assistant__work", open: turn.status === "failed" }, el("summary", null, summary), renderSteps(steps2));
4266
4490
  }
4267
- function renderSteps(steps) {
4491
+ function renderSteps(steps2) {
4268
4492
  return el(
4269
4493
  "ol",
4270
4494
  { class: "assistant__steps" },
4271
- steps.map(
4272
- (step2, index) => step2.kind === "message" ? el("li", { key: index, class: "assistant__step assistant__step--message" }, renderMarkdown(step2.text.trim())) : el(
4495
+ steps2.map(
4496
+ (step, index) => step.kind === "message" ? el("li", { key: index, class: "assistant__step assistant__step--message" }, renderMarkdown(step.text.trim())) : el(
4273
4497
  "li",
4274
- { key: index, class: "assistant__step", "data-state": step2.state },
4275
- el("span", { class: "assistant__step-text" }, step2.text),
4276
- step2.detail ? el("code", { class: "assistant__step-detail", title: step2.detail }, step2.detail) : null
4498
+ { key: index, class: "assistant__step", "data-state": step.state },
4499
+ el("span", { class: "assistant__step-text" }, step.text),
4500
+ step.detail ? el("code", { class: "assistant__step-detail", title: step.detail }, step.detail) : null
4277
4501
  )
4278
4502
  )
4279
4503
  );
@@ -4299,6 +4523,430 @@ function splitCreated(reply) {
4299
4523
  return { body: created.length ? kept.join("\n").trim() : reply, created };
4300
4524
  }
4301
4525
 
4526
+ // client/onboarding.ts
4527
+ var SECONDS_PER_STEP = 20;
4528
+ function OnboardingView({ state: state2, ui: ui2, handlers: handlers2 }) {
4529
+ const flow = state2.onboarding;
4530
+ const open = flow.steps.filter((step) => step.status === "open");
4531
+ const editing = ui2.setupEditing.value;
4532
+ h2(() => {
4533
+ if (!flow.detected) handlers2.detectSetup();
4534
+ }, [flow.detected]);
4535
+ return el(
4536
+ "div",
4537
+ { class: "onboarding" },
4538
+ el(
4539
+ "header",
4540
+ { class: "onboarding__bar" },
4541
+ el("span", { class: "onboarding__name" }, "Daily Focus"),
4542
+ progress(flow)
4543
+ ),
4544
+ el(
4545
+ "main",
4546
+ { class: "onboarding__column", id: "main" },
4547
+ flow.steps.length > 0 && flow.steps.every((step) => step.status === "open") && flow.steps[0].id === flow.current ? el(
4548
+ "p",
4549
+ { class: "onboarding__lede" },
4550
+ "Each morning an agent reads your mail, calendar, pull requests and the rest, and writes a short brief of what needs doing today. A few questions get it ready; most are answered already, so confirm or change them."
4551
+ ) : null,
4552
+ el(
4553
+ "ol",
4554
+ { class: "onboarding__thread" },
4555
+ flow.steps.map((step) => {
4556
+ if (step.id === flow.current || step.id === editing) {
4557
+ return el("li", { key: step.id }, k(StepCard, { step, ui: ui2, handlers: handlers2, current: step.id === flow.current }));
4558
+ }
4559
+ if (step.status === "open") return null;
4560
+ return el("li", { key: step.id }, doneRow(step, handlers2, ui2.setupBusy.value !== null));
4561
+ }),
4562
+ flow.current === null ? el("li", { key: "finish" }, k(FinishCard, { flow, ui: ui2, handlers: handlers2 })) : ahead(flow, open)
4563
+ )
4564
+ )
4565
+ );
4566
+ }
4567
+ function progress(flow) {
4568
+ const total = flow.steps.length + 1;
4569
+ const left = flow.steps.filter((step) => step.status === "open").length;
4570
+ const seconds = left * SECONDS_PER_STEP;
4571
+ const text = flow.current === null ? "Ready when you are" : seconds < 60 ? "Under a minute left" : seconds < 120 ? "About a minute left" : `About ${Math.round(seconds / 60)} minutes left`;
4572
+ const done = total - left - (flow.current === null ? 0 : 1);
4573
+ return el(
4574
+ "div",
4575
+ { class: "onboarding__progress" },
4576
+ el(
4577
+ "div",
4578
+ { class: "onboarding__track", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": total, "aria-valuenow": done, "aria-label": "Setup" },
4579
+ el("i", { style: { width: `${Math.round(done / total * 100)}%` } })
4580
+ ),
4581
+ el("span", null, text)
4582
+ );
4583
+ }
4584
+ function doneRow(step, handlers2, busy) {
4585
+ return el(
4586
+ "div",
4587
+ { class: "onboarding__done", "data-status": step.status, "data-step": step.id },
4588
+ el("span", { class: "onboarding__dot", "aria-hidden": "true" }),
4589
+ el("span", { class: "onboarding__summary" }, step.summary ?? `${step.topic[0].toUpperCase()}${step.topic.slice(1)}: decide later.`),
4590
+ el("button", { type: "button", class: "onboarding__change", disabled: busy, onClick: () => handlers2.editSetupStep(step.id) }, "Change")
4591
+ );
4592
+ }
4593
+ function ahead(flow, open) {
4594
+ const rest = open.filter((step) => step.id !== flow.current);
4595
+ const looking = rest.find((step) => step.proposal?.status === "working");
4596
+ const topics = rest.filter((step) => step !== looking).map((step) => step.topic);
4597
+ const later = topics.length > 4 ? [...topics.slice(0, 3), `${topics.length - 3} more`] : topics;
4598
+ return el(
4599
+ "li",
4600
+ { key: "ahead", class: "onboarding__ahead" },
4601
+ looking ? el(
4602
+ "div",
4603
+ { class: "onboarding__next" },
4604
+ el("span", { class: "onboarding__dot onboarding__dot--looking", "aria-hidden": "true" }),
4605
+ el("p", null, `Next, ${looking.topic}. It's already looking:`),
4606
+ steps(looking)
4607
+ ) : null,
4608
+ el(
4609
+ "p",
4610
+ { class: "onboarding__then" },
4611
+ el("span", { class: "onboarding__dot onboarding__dot--later", "aria-hidden": "true" }),
4612
+ later.length ? `Then ${listed([...later, "your first brief"])}.` : "Then your first brief."
4613
+ )
4614
+ );
4615
+ }
4616
+ function steps(step, count = 3) {
4617
+ const shown = (step.proposal?.steps ?? []).filter((s4) => s4.kind === "tool").slice(-count);
4618
+ const waiting = step.proposal?.status === "working" && !shown.some((s4) => s4.state === "running");
4619
+ return el(
4620
+ "ul",
4621
+ { class: "onboarding__steps" },
4622
+ shown.map((s4, index) => el("li", { key: index, "data-state": s4.state, title: s4.detail ?? void 0 }, s4.text)),
4623
+ waiting ? el("li", { key: "waiting", "data-state": "running" }, shown.length ? "Writing its answer\u2026" : "Starting\u2026") : null
4624
+ );
4625
+ }
4626
+ function listed(names) {
4627
+ if (names.length <= 1) return names.join("");
4628
+ return `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
4629
+ }
4630
+ function baseAnswer(step) {
4631
+ if (step.answer && step.answer.later !== true) return step.answer;
4632
+ return {
4633
+ choices: Object.fromEntries(step.card.choices.map((choice) => [choice.id, choice.selected])),
4634
+ fields: Object.fromEntries(step.card.fields.map((field) => [field.id, field.value]))
4635
+ };
4636
+ }
4637
+ function StepCard({ step, ui: ui2, handlers: handlers2, current }) {
4638
+ const saved = ui2.setupDrafts.value.get(step.id);
4639
+ const draft = saved?.answer ?? baseAnswer(step);
4640
+ const stale = saved !== void 0 && saved.version !== step.card.version;
4641
+ const busy = ui2.setupBusy.value !== null;
4642
+ const error = ui2.setupError.value?.step === step.id ? ui2.setupError.value.message : null;
4643
+ const editing = ui2.setupEditing.value === step.id;
4644
+ const proposal = step.proposal;
4645
+ const looking = proposal?.status === "working";
4646
+ const edit = (next) => handlers2.editSetupDraft(step.id, next, saved?.version ?? step.card.version);
4647
+ const tell = ui2.setupTell.value.get(step.id) ?? "";
4648
+ const empty = step.card.choices.every((choice) => choice.options.length === 0) && step.card.fields.length === 0;
4649
+ const conversation = proposal?.conversation ?? [];
4650
+ const revising = conversation.at(-1)?.from === "you";
4651
+ const confirming = looking && ui2.setupConfirm.value === step.id;
4652
+ const held = busy ? "Saving your last answer\u2026" : empty && looking ? "Still looking; this fills in when it is done" : empty && step.card.problem?.blocking ? "Fix what it says above, or decide later" : null;
4653
+ return el(
4654
+ "section",
4655
+ { class: "onboarding__card", "data-current": String(current), "data-step": step.id, "aria-labelledby": `setup-${step.id}` },
4656
+ el("span", { class: "onboarding__dot onboarding__dot--open", "aria-hidden": "true" }),
4657
+ el("h2", { id: `setup-${step.id}`, tabIndex: -1 }, step.title),
4658
+ conversation.length ? el(
4659
+ "ol",
4660
+ { class: "onboarding__talk" },
4661
+ conversation.map(
4662
+ (line, index) => line.from === "it" ? el("li", { key: index, class: "onboarding__why" }, sparkle(), el("span", null, line.text)) : el("li", { key: index, class: "onboarding__said" }, line.text)
4663
+ )
4664
+ ) : step.card.why && !(looking && empty) ? el("p", { class: "onboarding__why" }, sparkle(), el("span", null, step.card.why)) : null,
4665
+ looking ? el(
4666
+ "div",
4667
+ { class: "onboarding__looking", role: "status" },
4668
+ revising ? null : el("p", null, empty ? `Looking into ${step.topic}\u2026` : "Still looking. You can answer now, or wait for its pick."),
4669
+ steps(step)
4670
+ ) : null,
4671
+ // Under what it said, so a reply reads as one, and what comes back lands here too.
4672
+ step.card.revisable && !looking ? el(
4673
+ "form",
4674
+ {
4675
+ class: "onboarding__tell",
4676
+ onSubmit: (event) => {
4677
+ event.preventDefault();
4678
+ if (tell.trim() && !busy) handlers2.reviseSetup(step.id, tell, draft);
4679
+ }
4680
+ },
4681
+ el("input", {
4682
+ type: "text",
4683
+ value: tell,
4684
+ "aria-label": step.card.reply ?? "Tell it what to change",
4685
+ placeholder: step.card.reply ?? "Tell it what to change",
4686
+ onInput: (event) => handlers2.editSetupTell(step.id, event.currentTarget.value)
4687
+ }),
4688
+ el("button", { type: "submit", class: "button", disabled: busy || tell.trim() === "" }, "Send")
4689
+ ) : null,
4690
+ proposal?.status === "failed" ? el(
4691
+ "p",
4692
+ { class: "onboarding__note" },
4693
+ `It couldn't look into this: ${proposal.error}. `,
4694
+ el("button", { type: "button", class: "link-button", disabled: busy, onClick: () => handlers2.retrySetup(step.id) }, "Try again")
4695
+ ) : null,
4696
+ stale ? el(
4697
+ "p",
4698
+ { class: "onboarding__note" },
4699
+ "It has a new suggestion since you started changing this. ",
4700
+ el("button", { type: "button", class: "link-button", onClick: () => handlers2.editSetupDraft(step.id, null, 0) }, "Use it")
4701
+ ) : null,
4702
+ step.card.problem?.blocking ? problem(step, busy, handlers2) : null,
4703
+ el(
4704
+ "form",
4705
+ {
4706
+ class: "onboarding__form",
4707
+ onSubmit: (event) => {
4708
+ event.preventDefault();
4709
+ if (busy) return;
4710
+ if (looking && !confirming) return handlers2.confirmSetup(step.id);
4711
+ handlers2.answerSetup(step.id, draft);
4712
+ }
4713
+ },
4714
+ // Fields first: a card with both asks for the few words before the list.
4715
+ step.card.fields.length ? el(
4716
+ "div",
4717
+ { class: "onboarding__fields" },
4718
+ step.card.fields.map(
4719
+ (field) => fieldView(field, draft.fields[field.id] ?? "", (value) => edit({ ...draft, fields: { ...draft.fields, [field.id]: value } }))
4720
+ )
4721
+ ) : null,
4722
+ step.card.choices.map(
4723
+ (choice) => k(ChoiceView, {
4724
+ choice,
4725
+ picked: draft.choices[choice.id] ?? [],
4726
+ onPick: (values) => edit({ ...draft, choices: { ...draft.choices, [choice.id]: values } })
4727
+ })
4728
+ ),
4729
+ step.card.problem && !step.card.problem.blocking ? problem(step, busy, handlers2) : null,
4730
+ error ? el("p", { class: "onboarding__error", role: "alert" }, error) : null,
4731
+ confirming ? el(
4732
+ "div",
4733
+ { class: "onboarding__actions onboarding__confirm", role: "alert" },
4734
+ el("p", null, revising ? "It\u2019s still working on your change." : "It\u2019s still filling this in.", " Continue with what\u2019s here, and stop it?"),
4735
+ el("button", { type: "submit", class: "button button--primary", disabled: busy }, "Continue without it"),
4736
+ el("button", { type: "button", class: "button onboarding__quiet", onClick: () => handlers2.confirmSetup(null) }, "Wait for it")
4737
+ ) : el(
4738
+ "div",
4739
+ { class: "onboarding__actions" },
4740
+ el(
4741
+ "button",
4742
+ { type: "submit", class: "button button--primary", disabled: held !== null, title: held ?? void 0 },
4743
+ ui2.setupBusy.value === step.id ? "Saving\u2026" : step.card.empty && step.card.fields.every((field) => !(draft.fields[field.id] ?? "").trim()) ? step.card.empty : "Continue"
4744
+ ),
4745
+ step.card.later ? el(
4746
+ "button",
4747
+ { type: "button", class: "button onboarding__quiet", disabled: busy, onClick: () => handlers2.answerSetup(step.id, { later: true }) },
4748
+ step.card.later
4749
+ ) : null,
4750
+ editing ? el("button", { type: "button", class: "button onboarding__quiet", onClick: () => handlers2.editSetupStep(null) }, "Cancel") : null
4751
+ )
4752
+ )
4753
+ );
4754
+ }
4755
+ function problem(step, busy, handlers2) {
4756
+ const found = step.card.problem;
4757
+ return el(
4758
+ "div",
4759
+ { class: "onboarding__problem", "data-blocking": String(found.blocking) },
4760
+ el("p", null, found.message),
4761
+ found.links?.length ? el(
4762
+ "p",
4763
+ { class: "onboarding__links" },
4764
+ found.links.map((link) => el("a", { key: link.url, href: link.url, target: "_blank", rel: "noopener" }, link.label))
4765
+ ) : null,
4766
+ found.command ? el("pre", null, el("code", null, found.command)) : null,
4767
+ el("button", { type: "button", class: "button", disabled: busy, onClick: () => handlers2.retrySetup(step.id) }, "Check again")
4768
+ );
4769
+ }
4770
+ function sparkle() {
4771
+ return el(
4772
+ "svg",
4773
+ { class: "onboarding__sparkle", width: 14, height: 14, viewBox: "0 0 14 14", "aria-hidden": "true" },
4774
+ el("path", { d: "M7 0l1.6 5.4L14 7l-5.4 1.6L7 14l-1.6-5.4L0 7l5.4-1.6z", fill: "currentColor" })
4775
+ );
4776
+ }
4777
+ function ChoiceView({ choice, picked, onPick }) {
4778
+ const [adding, setAdding] = d2(false);
4779
+ const [typed, setTyped] = d2("");
4780
+ const known = new Set(choice.options.map((option) => option.value));
4781
+ const own = picked.filter((value) => !known.has(value));
4782
+ const toggle = (value) => {
4783
+ if (!choice.multiple) return onPick([value]);
4784
+ onPick(picked.includes(value) ? picked.filter((v4) => v4 !== value) : [...picked, value]);
4785
+ };
4786
+ const add = () => {
4787
+ const value = typed.trim();
4788
+ if (value) onPick(choice.multiple ? [...picked.filter((v4) => v4 !== value), value] : [value]);
4789
+ setTyped("");
4790
+ setAdding(false);
4791
+ };
4792
+ const adder = choice.custom ? adding ? el(
4793
+ "div",
4794
+ { class: "onboarding__add" },
4795
+ el("input", {
4796
+ type: "text",
4797
+ value: typed,
4798
+ placeholder: choice.custom,
4799
+ "aria-label": choice.custom,
4800
+ ref: (input) => input?.focus(),
4801
+ onInput: (event) => setTyped(event.currentTarget.value),
4802
+ onKeyDown: (event) => {
4803
+ if (event.key === "Enter") {
4804
+ event.preventDefault();
4805
+ add();
4806
+ }
4807
+ if (event.key === "Escape") setAdding(false);
4808
+ }
4809
+ }),
4810
+ el("button", { type: "button", class: "button", onClick: add }, "Add")
4811
+ ) : el("button", { type: "button", class: "onboarding__add-button", onClick: () => setAdding(true) }, choice.multiple ? choice.custom : "Other\u2026") : null;
4812
+ const label = choice.label ? el("legend", { class: "onboarding__legend" }, choice.label) : null;
4813
+ const rows = choice.multiple || choice.options.some((option) => option.detail);
4814
+ if (!rows) {
4815
+ return el(
4816
+ "fieldset",
4817
+ { class: "onboarding__choice" },
4818
+ label,
4819
+ el(
4820
+ "div",
4821
+ { class: "onboarding__pills", role: "radiogroup" },
4822
+ [...choice.options, ...own.map((value) => ({ value, label: value, detail: null, group: null }))].map(
4823
+ (option) => el(
4824
+ "button",
4825
+ {
4826
+ type: "button",
4827
+ key: option.value,
4828
+ role: "radio",
4829
+ class: "onboarding__pill",
4830
+ "aria-checked": String(picked.includes(option.value)),
4831
+ onClick: () => toggle(option.value)
4832
+ },
4833
+ option.label
4834
+ )
4835
+ ),
4836
+ adder
4837
+ )
4838
+ );
4839
+ }
4840
+ const groups = /* @__PURE__ */ new Map();
4841
+ for (const option of choice.options) groups.set(option.group, [...groups.get(option.group) ?? [], option]);
4842
+ if (own.length) groups.set("Added by you", own.map((value) => ({ value, label: value, detail: null, group: "Added by you" })));
4843
+ return el(
4844
+ "fieldset",
4845
+ { class: "onboarding__choice" },
4846
+ label,
4847
+ el(
4848
+ "div",
4849
+ { class: "onboarding__list" },
4850
+ [...groups].map(
4851
+ ([group, options]) => el(
4852
+ "div",
4853
+ { class: "onboarding__group", key: group ?? "" },
4854
+ group ? el("p", { class: "onboarding__group-name" }, group) : null,
4855
+ options.map(
4856
+ (option) => el(
4857
+ "label",
4858
+ { class: "onboarding__option", key: option.value },
4859
+ el("input", {
4860
+ type: choice.multiple ? "checkbox" : "radio",
4861
+ name: choice.id,
4862
+ checked: picked.includes(option.value),
4863
+ onChange: () => toggle(option.value)
4864
+ }),
4865
+ el("span", { class: "onboarding__box", "data-kind": choice.multiple ? "check" : "radio", "aria-hidden": "true" }),
4866
+ el("span", { class: "onboarding__option-text" }, option.label, option.detail ? el("small", null, option.detail) : null)
4867
+ )
4868
+ )
4869
+ )
4870
+ ),
4871
+ choice.options.length === 0 && own.length === 0 && !choice.custom ? el("p", { class: "onboarding__none" }, "Nothing to choose from.") : null,
4872
+ adder ? el("div", { class: "onboarding__adder" }, adder) : null
4873
+ )
4874
+ );
4875
+ }
4876
+ function fieldView(field, value, onInput) {
4877
+ return el(
4878
+ "div",
4879
+ { class: "onboarding__field", key: field.id },
4880
+ el(
4881
+ "label",
4882
+ null,
4883
+ el("span", { class: "onboarding__field-label" }, field.label),
4884
+ el("input", {
4885
+ type: "text",
4886
+ value,
4887
+ placeholder: field.placeholder ?? void 0,
4888
+ onInput: (event) => onInput(event.currentTarget.value)
4889
+ })
4890
+ ),
4891
+ field.help ? el("small", null, field.help) : null,
4892
+ // Offered, never filled in: a click puts one in the field, to edit or keep.
4893
+ field.suggestions?.length ? el(
4894
+ "ul",
4895
+ { class: "onboarding__suggestions" },
4896
+ field.suggestions.map(
4897
+ (suggestion) => el(
4898
+ "li",
4899
+ { key: suggestion.text },
4900
+ el(
4901
+ "button",
4902
+ { type: "button", "aria-pressed": String(value === suggestion.text), onClick: () => onInput(suggestion.text) },
4903
+ el("span", null, suggestion.text),
4904
+ suggestion.detail ? el("small", null, suggestion.detail) : null
4905
+ )
4906
+ )
4907
+ )
4908
+ ) : null
4909
+ );
4910
+ }
4911
+ function FinishCard({ flow, ui: ui2, handlers: handlers2 }) {
4912
+ const writes = flow.steps.find((step) => step.id === "cli")?.status === "answered";
4913
+ const busy = ui2.setupBusy.value !== null;
4914
+ const error = (ui2.setupError.value?.step === "finish" ? ui2.setupError.value.message : null) ?? flow.error;
4915
+ const sources = ui2.setupSources.value;
4916
+ return el(
4917
+ "section",
4918
+ { class: "onboarding__card onboarding__finish", "data-current": "true", "aria-labelledby": "setup-finish" },
4919
+ el("span", { class: "onboarding__dot onboarding__dot--open", "aria-hidden": "true" }),
4920
+ el("h2", { id: "setup-finish", tabIndex: -1 }, writes ? "Ready for your first brief" : "Ready to finish"),
4921
+ el(
4922
+ "p",
4923
+ { class: "onboarding__why" },
4924
+ writes ? "It takes a few minutes, and you can watch it work. After that it runs by itself, and everything here can be changed in Settings." : "Without an agent there is no brief to write yet. Choose one in Settings when you are ready; the boards work meanwhile."
4925
+ ),
4926
+ el(
4927
+ "details",
4928
+ {
4929
+ class: "onboarding__preview",
4930
+ onToggle: (event) => {
4931
+ if (event.currentTarget.open && sources === null) handlers2.loadSetupSources();
4932
+ }
4933
+ },
4934
+ el("summary", null, "What the morning agent reads each morning"),
4935
+ sources === null || sources === "loading" ? el("p", null, "Loading\u2026") : "error" in sources ? el("p", null, `Could not show it: ${sources.error}`) : sources.kept ? el("p", null, "Your source list is already written, and setup leaves it as it is.") : sources.text ? el("pre", null, sources.text) : el("p", null, "Nothing yet: the agent briefs from what it can reach, and says what it missed.")
4936
+ ),
4937
+ error ? el("p", { class: "onboarding__error", role: "alert" }, error) : null,
4938
+ el(
4939
+ "div",
4940
+ { class: "onboarding__actions" },
4941
+ el(
4942
+ "button",
4943
+ { type: "button", class: "button button--primary", disabled: busy, onClick: () => handlers2.finishSetup() },
4944
+ ui2.setupBusy.value === "finish" ? "Saving\u2026" : writes ? "Write my first brief" : "Finish setup"
4945
+ )
4946
+ )
4947
+ );
4948
+ }
4949
+
4302
4950
  // client/settings.ts
4303
4951
  var VIEW_NAME = {
4304
4952
  today: "Today",
@@ -4373,7 +5021,7 @@ function objectiveCard(state2, ui2, handlers2) {
4373
5021
  )
4374
5022
  );
4375
5023
  }
4376
- function objectiveForm(objective, blocker, handlers2, label = "Save objective") {
5024
+ function objectiveForm(objective, blocker, handlers2) {
4377
5025
  return el(
4378
5026
  "form",
4379
5027
  {
@@ -4404,7 +5052,7 @@ ${blocker}`,
4404
5052
  el("span", { class: "field__label" }, "Blocked on (optional)"),
4405
5053
  el("input", { class: "field__input", name: "blocker", defaultValue: blocker, placeholder: "What is in the way today, if anything", autocomplete: "off" })
4406
5054
  ),
4407
- el("div", { class: "objective-form__actions" }, el("button", { type: "submit", class: "button button--primary" }, label))
5055
+ el("div", { class: "objective-form__actions" }, el("button", { type: "submit", class: "button button--primary" }, "Save objective"))
4408
5056
  );
4409
5057
  }
4410
5058
  function sourcesCard(state2, ui2, handlers2) {
@@ -4480,7 +5128,7 @@ function flagValue(raw) {
4480
5128
  }
4481
5129
  function settingField(setting, draft, handlers2) {
4482
5130
  const id = `setting-${setting.key}`;
4483
- const locked = setting.source === "environment";
5131
+ const locked = setting.source === "fixed";
4484
5132
  const value = shownValue(setting, draft);
4485
5133
  const onChange = (event) => {
4486
5134
  const next = event.currentTarget.value;
@@ -4488,13 +5136,13 @@ function settingField(setting, draft, handlers2) {
4488
5136
  };
4489
5137
  let input;
4490
5138
  if (setting.kind === "choice" || setting.kind === "flag") {
4491
- const choices2 = setting.kind === "flag" ? [{ value: "on", label: "On" }, { value: "off", label: "Off" }] : setting.choices ?? [];
5139
+ const choices = setting.kind === "flag" ? [{ value: "on", label: "On" }, { value: "off", label: "Off" }] : setting.choices ?? [];
4492
5140
  const current = setting.kind === "flag" ? flagValue(value) : value;
4493
5141
  input = el(
4494
5142
  "select",
4495
5143
  { class: "field__input", id, disabled: locked, value: current, onChange },
4496
5144
  el("option", { value: "" }, `Default: ${setting.fallback}`),
4497
- choices2.map((choice) => el("option", { value: choice.value, key: choice.value }, choice.label))
5145
+ choices.map((choice) => el("option", { value: choice.value, key: choice.value }, choice.label))
4498
5146
  );
4499
5147
  } else {
4500
5148
  input = el("input", {
@@ -4510,7 +5158,7 @@ function settingField(setting, draft, handlers2) {
4510
5158
  onInput: onChange
4511
5159
  });
4512
5160
  }
4513
- const note = setting.source === "environment" ? "Set in the environment this dashboard was started with, which wins over this page." : setting.source === "dotenv" && !draft.has(setting.key) ? "From the .env file. Saving a value here takes its place." : null;
5161
+ const note = locked ? "Fixed in the demo, so that nothing in it runs." : null;
4514
5162
  return el(
4515
5163
  "div",
4516
5164
  { class: "field", key: setting.key, "data-changed": String(draft.has(setting.key)) },
@@ -4533,9 +5181,9 @@ function calendarPicker(state2, ui2, handlers2, settings) {
4533
5181
  );
4534
5182
  }
4535
5183
  const setting = settings.find((entry) => entry.key === "DAILY_FOCUS_CALENDARS");
4536
- if (!setting || setting.source === "environment") return null;
5184
+ if (!setting || setting.source === "fixed") return null;
4537
5185
  const chosen = shownValue(setting, ui2.settingsDraft.value).split(",").map((name) => name.trim()).filter(Boolean);
4538
- const listed = ui2.calendars.value;
5186
+ const listed2 = ui2.calendars.value;
4539
5187
  const toggle = (title, on) => {
4540
5188
  const others = chosen.filter((name) => name.toLowerCase() !== title.toLowerCase());
4541
5189
  const next = on ? [...others, title] : others;
@@ -4545,11 +5193,11 @@ function calendarPicker(state2, ui2, handlers2, settings) {
4545
5193
  "div",
4546
5194
  { class: "calendar-picker" },
4547
5195
  el("button", { type: "button", class: "button", onClick: () => handlers2.listCalendars() }, "List the calendars on this Mac"),
4548
- typeof listed === "string" ? el("p", { class: "settings-card__warning" }, listed) : null,
4549
- Array.isArray(listed) ? el(
5196
+ typeof listed2 === "string" ? el("p", { class: "settings-card__warning" }, listed2) : null,
5197
+ Array.isArray(listed2) ? el(
4550
5198
  "ul",
4551
5199
  { class: "calendar-picker__list" },
4552
- listed.map(
5200
+ listed2.map(
4553
5201
  (entry) => el(
4554
5202
  "li",
4555
5203
  { key: `${entry.title}
@@ -4592,248 +5240,57 @@ function saveBar(ui2, handlers2) {
4592
5240
  }
4593
5241
 
4594
5242
  // client/setup.ts
4595
- var CLI_LABEL = { claude: "Claude Code", codex: "Codex" };
4596
- function SetupCard({ state: state2, ui: ui2, handlers: handlers2 }) {
4597
- const setup = state2.setup;
5243
+ function FirstBriefCard({ state: state2, handlers: handlers2 }) {
4598
5244
  const agent = state2.agentRun;
4599
- const running = agent.last?.status === "running";
4600
- const placeholders = setup.sources.exists && setup.sources.placeholders > 0;
4601
- return el(
4602
- "section",
4603
- { class: "setup", id: "setup", "aria-labelledby": "setup-title" },
4604
- el("h2", { class: "setup__title", id: "setup-title" }, "Set up your morning brief"),
4605
- el(
4606
- "p",
4607
- { class: "setup__lede" },
4608
- "Each morning an agent reads your mail, calendar, pull requests and the rest, and writes a short brief of what needs to get done today. The steps below get it ready for its first run. Everything here can be changed later in ",
4609
- el("button", { type: "button", class: "link-button", onClick: () => handlers2.openSettings() }, "Settings"),
4610
- "."
4611
- ),
4612
- el(
4613
- "ol",
4614
- { class: "setup__steps" },
4615
- step(
4616
- setup.profileChosen,
4617
- "What should it brief?",
4618
- setup.profileChosen ? el("p", null, setup.profile === "personal" ? "Your personal life." : "Your work.") : [
4619
- el(
4620
- "p",
4621
- null,
4622
- "Work, or home: mail, family calendars, reminders and messages. Run a second dashboard for the other one."
4623
- ),
4624
- // A choice, so neither answer is drawn as the one to pick.
4625
- choices([
4626
- ["Work", () => handlers2.chooseSettings({ DAILY_FOCUS_PROFILE: "work" })],
4627
- ["Personal life", () => handlers2.chooseSettings({ DAILY_FOCUS_PROFILE: "personal" })]
4628
- ])
4629
- ]
4630
- ),
4631
- step(
4632
- Boolean(state2.focus?.objective),
4633
- "What are you trying to achieve?",
4634
- state2.focus?.objective ? el("p", null, state2.focus.objective) : [
4635
- el("p", null, "The agent ranks the day against it. Leave it for now if nothing stands out."),
4636
- objectiveForm("", "", handlers2, "Set objective")
4637
- ]
4638
- ),
4639
- step(
4640
- agent.cli !== null,
4641
- "Which agent writes the brief?",
4642
- agent.cli ? [
4643
- el(
4644
- "p",
4645
- null,
4646
- `${CLI_LABEL[agent.cli]}. ` + (agent.schedule ? `After the first brief, it runs by itself each scheduled morning at ${agent.schedule.at}. ` : "It runs when you press refresh. ") + "It has to be logged in; the first run says if it is not."
4647
- ),
4648
- agentAdvanced(agent.cli, ui2, handlers2)
4649
- ] : agentChoice(state2, handlers2)
4650
- ),
4651
- step(setup.sources.exists && setup.sources.placeholders === 0, "Who are you, and where should it look?", sourcesStep(state2, ui2, handlers2)),
4652
- step(null, "What else should the dashboard show?", boards(state2, handlers2)),
4653
- step(
4654
- null,
4655
- "Your first brief",
4656
- [
4657
- el(
4658
- "p",
4659
- null,
4660
- running ? "The morning agent is writing it now. Click the banner above to watch." : 'The morning agent writes it now, which takes a few minutes, and from then on by itself every scheduled morning. When it is done, click "updated \u2026 ago" at the top to read its report: what it found, and anything it could not reach.' + (setup.sources.exists ? "" : " Without a source list it briefs from what it can reach on its own, and says what it missed.")
4661
- ),
4662
- placeholders ? el("p", { class: "setup__note setup__note--todo" }, "Replace the source list's placeholders first, or the agent goes looking for them.") : null,
4663
- el(
4664
- "button",
4665
- {
4666
- type: "button",
4667
- class: "button button--primary",
4668
- disabled: !agent.enabled || running || state2.restart === "waiting" || placeholders,
4669
- title: !agent.enabled ? "Choose the agent first" : placeholders ? "Replace the source list's placeholders first" : void 0,
4670
- onClick: () => handlers2.runAgent()
4671
- },
4672
- running ? "Running\u2026" : "Run the morning agent now"
4673
- )
4674
- ]
4675
- )
4676
- )
4677
- );
4678
- }
4679
- function step(done, title, body) {
4680
- return el(
4681
- "li",
4682
- { class: "setup__step", "data-done": done === null ? void 0 : String(done) },
4683
- el(
4684
- "span",
4685
- { class: "setup__mark", "aria-label": done === null ? void 0 : done ? "Done" : "To do" },
4686
- done === null ? "\xB7" : done ? "\u2713" : "\u25CB"
4687
- ),
4688
- el("div", { class: "setup__body" }, el("h3", { class: "setup__step-title" }, title), body)
4689
- );
4690
- }
4691
- function choices(options) {
4692
- return el(
4693
- "div",
4694
- { class: "setup__choices" },
4695
- options.map(([label, onClick, title]) => el("button", { type: "button", class: "button", key: label, title, onClick }, label))
4696
- );
4697
- }
4698
- function agentChoice(state2, handlers2) {
4699
- const found = ["claude", "codex"].filter((cli) => state2.setup.clis[cli]);
4700
- if (found.length === 0) {
4701
- return [
4702
- el(
4703
- "p",
4704
- null,
4705
- "The brief is written by a coding-agent CLI you already use. Install ",
4706
- el("a", { href: "https://code.claude.com/docs", target: "_blank", rel: "noopener" }, "Claude Code"),
4707
- " or the ",
4708
- el("a", { href: "https://developers.openai.com/codex/cli", target: "_blank", rel: "noopener" }, "Codex CLI"),
4709
- ", log in, and restart the dashboard; it looks for both each time it starts."
4710
- )
5245
+ const last = agent.last;
5246
+ const running = last?.status === "running";
5247
+ const restarting = state2.restart === "waiting";
5248
+ let title;
5249
+ let text;
5250
+ let actions;
5251
+ if (restarting) {
5252
+ title = "Saving your settings";
5253
+ text = "The dashboard restarts to apply them, then starts on your first brief.";
5254
+ actions = [];
5255
+ } else if (!agent.enabled) {
5256
+ title = "Choose who writes your brief";
5257
+ text = "Each morning a coding-agent CLI you already use writes it: Claude Code or Codex. The boards work meanwhile.";
5258
+ actions = [el("button", { type: "button", class: "button button--primary", onClick: () => handlers2.openSettings("agent") }, "Choose in Settings")];
5259
+ } else if (running) {
5260
+ title = "Writing your first brief";
5261
+ text = "The morning agent is reading your mail, calendar and the rest. It takes a few minutes; the brief appears here when it is done.";
5262
+ actions = [el("button", { type: "button", class: "button", onClick: () => handlers2.openRun(last.id) }, "Watch it work")];
5263
+ } else if (last && last.status !== "done") {
5264
+ title = "Your first brief didn\u2019t finish";
5265
+ text = last.status === "aborted" ? "It was stopped before it wrote a brief." : last.error ? `The run failed: ${last.error}.` : "The run stopped before it wrote a brief.";
5266
+ actions = [
5267
+ el("button", { type: "button", class: "button button--primary", onClick: () => handlers2.runAgent() }, "Try again"),
5268
+ el("button", { type: "button", class: "button", onClick: () => handlers2.openRun(last.id) }, "Read its report")
4711
5269
  ];
5270
+ } else if (last) {
5271
+ title = "Your first brief didn\u2019t arrive";
5272
+ text = "The run finished without a brief this dashboard could read. Its report says why.";
5273
+ actions = [
5274
+ el("button", { type: "button", class: "button button--primary", onClick: () => handlers2.runAgent() }, "Run it again"),
5275
+ el("button", { type: "button", class: "button", onClick: () => handlers2.openRun(last.id) }, "Read its report")
5276
+ ];
5277
+ } else {
5278
+ title = "Write your first brief";
5279
+ text = "It takes a few minutes. After that it runs by itself each scheduled morning.";
5280
+ actions = [el("button", { type: "button", class: "button button--primary", onClick: () => handlers2.runAgent() }, "Write it now")];
4712
5281
  }
4713
- return [
4714
- el("p", null, "The dashboard runs a coding-agent CLI you already use, headless, each morning. Found on this machine:"),
4715
- choices(
4716
- found.map(
4717
- (cli) => [`Use ${CLI_LABEL[cli]}`, () => handlers2.chooseSettings({ DAILY_FOCUS_AGENT: cli }), state2.setup.clis[cli] ?? void 0]
4718
- )
4719
- )
4720
- ];
4721
- }
4722
- var AGENT_ADVANCED = "setup:agent-advanced";
4723
- function agentAdvanced(cli, ui2, handlers2) {
4724
- const keys = ["DAILY_FOCUS_AGENT_MODEL", "DAILY_FOCUS_AGENT_EFFORT", ...cli === "claude" ? ["DAILY_FOCUS_AGENT_TOOLS"] : []];
4725
- const page = ui2.settings.value;
4726
- const draft = ui2.settingsDraft.value;
4727
- const changed = keys.some((key) => draft.has(key));
4728
- const error = changed ? ui2.settingsError.value : null;
4729
- return el(
4730
- "details",
4731
- {
4732
- class: "setup__advanced",
4733
- open: ui2.openDrawers.value.has(AGENT_ADVANCED),
4734
- onToggle: (event) => {
4735
- const open = event.currentTarget.open;
4736
- if (open && !ui2.settings.peek()) handlers2.loadSettings();
4737
- handlers2.toggleDrawer(AGENT_ADVANCED, open);
4738
- }
4739
- },
4740
- el("summary", null, cli === "claude" ? "Advanced: model, effort and tools" : "Advanced: model and effort"),
4741
- page ? [
4742
- ...keys.flatMap((key) => {
4743
- const setting = page.settings.find((entry) => entry.key === key);
4744
- return setting ? [settingField(setting, draft, handlers2)] : [];
4745
- }),
4746
- error ? el("p", { class: "setup__note setup__note--todo", role: "alert" }, error) : null,
4747
- el(
4748
- "div",
4749
- { class: "setup__advanced-actions" },
4750
- el(
4751
- "button",
4752
- { type: "button", class: "button", disabled: !changed || ui2.settingsSaving.value, onClick: () => handlers2.saveSettings(keys) },
4753
- ui2.settingsSaving.value ? "Saving\u2026" : "Save"
4754
- )
4755
- )
4756
- ] : el("p", null, "Loading the settings\u2026")
4757
- );
4758
- }
4759
- var SOURCES_EDITOR = "setup:sources";
4760
- function sourcesStep(state2, ui2, handlers2) {
4761
- const sources = state2.setup.sources;
4762
- const open = ui2.openDrawers.value.has(SOURCES_EDITOR);
4763
- const toggle = () => {
4764
- if (!open && !ui2.texts.value.sources) handlers2.loadText("sources");
4765
- handlers2.toggleDrawer(SOURCES_EDITOR, !open);
4766
- };
4767
- return [
4768
- el(
4769
- "p",
4770
- null,
4771
- "A short list the agent reads every morning. First who you are: your name as meeting notes write it, your email and your GitHub login, so it can tell your to-dos from everyone else's. Then where to look: which calendars, mailboxes and documents are yours."
4772
- ),
4773
- sources.exists ? el(
4774
- "p",
4775
- { class: sources.placeholders > 0 ? "setup__note setup__note--todo" : "setup__note" },
4776
- sources.placeholders > 0 ? `It still has ${sources.placeholders} of the template's placeholders. Replace them, or delete what doesn't apply.` : "Written."
4777
- ) : el("p", { class: "setup__note" }, "It starts from a template, with what gh and git know about you already filled in."),
4778
- el(
4779
- "button",
4780
- { type: "button", class: "button", "aria-expanded": String(open), onClick: toggle },
4781
- open ? "Close" : sources.exists ? "Edit it" : "Write it"
4782
- ),
4783
- open ? el("div", { class: "setup__editor" }, textEditor("sources", ui2.texts.value.sources, handlers2, "sources.md")) : null
4784
- ];
4785
- }
4786
- var HEALTH_MARK = { ok: "\u2713", checking: "\u2026", problem: "!", todo: "\u25CB" };
4787
- var HEALTH_LABEL = {
4788
- ok: "Connected",
4789
- checking: "Checking",
4790
- problem: "Not working",
4791
- todo: "To do"
4792
- };
4793
- function boardHealth(board, via, service) {
4794
- if (board.reason) return ["problem", board.reason.message];
4795
- if (board.fetchedAt) return ["ok", `Connected, through ${via}.`];
4796
- return ["checking", `Checking ${service} through ${via}\u2026`];
4797
- }
4798
- function boards(state2, handlers2) {
4799
- const rows = [];
4800
- const off = (key, label) => el("button", { type: "button", class: "button", onClick: () => handlers2.chooseSettings({ [key]: "off" }) }, `Turn off ${label}`);
4801
- if (state2.board.enabled) {
4802
- rows.push(boardRow("Pull requests", ...boardHealth(state2.board, "gh", "GitHub"), off("DAILY_FOCUS_GITHUB", "the pull request board")));
4803
- }
4804
- if (state2.tickets.enabled) {
4805
- rows.push(boardRow("Jira tickets", ...boardHealth(state2.tickets, "acli", "Jira"), off("DAILY_FOCUS_JIRA", "the Jira board")));
4806
- }
4807
- const calendar = state2.setup.calendar;
4808
- if (calendar.supported && state2.agendaSource) {
4809
- const live = state2.agendaSource.live;
4810
- const [health, text] = !calendar.built ? ["todo", `Needs the calendar helper: run ${calendar.buildCommand} once. Until then the agenda uses the brief.`] : calendar.chosen === 0 ? ["todo", "No calendars chosen yet. Choose them, and the agenda follows them live."] : live ? ["ok", `Connected, reading ${calendar.chosen} ${calendar.chosen === 1 ? "calendar" : "calendars"} from Calendar.app.`] : state2.agendaSource.problem ? ["problem", state2.agendaSource.problem] : ["checking", "Checking Calendar.app\u2026"];
4811
- rows.push(
4812
- boardRow(
4813
- "Calendar",
4814
- health,
4815
- text,
4816
- calendar.built && calendar.chosen === 0 ? el("button", { type: "button", class: "button", onClick: () => handlers2.openSettings("calendar") }, "Choose calendars") : off("DAILY_FOCUS_CALENDAR", "the live agenda")
4817
- )
4818
- );
4819
- }
4820
- if (rows.length === 0) return el("p", null, "Nothing else is switched on. The boards can be turned on in Settings.");
4821
- return el("ul", { class: "setup__boards" }, rows);
4822
- }
4823
- function boardRow(name, health, text, action) {
4824
5282
  return el(
4825
- "li",
4826
- { class: "setup__board", "data-health": health, key: name },
4827
- el("span", { class: "setup__board-mark", "aria-label": HEALTH_LABEL[health], title: HEALTH_LABEL[health] }, HEALTH_MARK[health]),
4828
- el("span", { class: "setup__board-name" }, name),
4829
- el("span", { class: "setup__board-text" }, text),
4830
- action
5283
+ "section",
5284
+ { class: "first-brief", id: "first-brief", "aria-labelledby": "first-brief-title", "data-state": running ? "running" : "idle" },
5285
+ el("h2", { class: "first-brief__title", id: "first-brief-title" }, title),
5286
+ el("p", { class: "first-brief__text" }, text),
5287
+ actions.length ? el("div", { class: "first-brief__actions" }, actions) : null
4831
5288
  );
4832
5289
  }
4833
5290
 
4834
5291
  // client/today.ts
4835
5292
  function TodayView({ state: state2, ui: ui2, handlers: handlers2 }) {
4836
- if (state2.setup?.needed) return [k(SetupCard, { state: state2, ui: ui2, handlers: handlers2 })];
5293
+ if (state2.setup?.needed) return [k(FirstBriefCard, { state: state2, handlers: handlers2 })];
4837
5294
  return [renderObjective(state2, handlers2), renderStats(state2), renderHeadline(state2), renderSections(state2, ui2, handlers2)];
4838
5295
  }
4839
5296
  function renderObjective(state2, handlers2 = null) {
@@ -4890,15 +5347,15 @@ function focusTimeStat(agenda, now) {
4890
5347
  const tone = minutes === 0 ? "critical" : minutes < 60 ? "critical" : null;
4891
5348
  return stat("Focus time left", minutes === 0 ? "None" : formatDuration(minutes), tone, `Day ends ${agenda.dayEnd}`);
4892
5349
  }
4893
- function objectiveStat(progress) {
4894
- if (!progress) return null;
4895
- if (progress.workingDaysSince === null) {
5350
+ function objectiveStat(progress2) {
5351
+ if (!progress2) return null;
5352
+ if (progress2.workingDaysSince === null) {
4896
5353
  return stat("Since objective progress", "\u2014", null, "Nothing recorded yet");
4897
5354
  }
4898
- const days = progress.workingDaysSince;
5355
+ const days = progress2.workingDaysSince;
4899
5356
  const tone = days === 0 ? "good" : days >= 3 ? "critical" : null;
4900
5357
  const value = days === 0 ? "Today" : days === 1 ? "1 day" : `${days} days`;
4901
- return stat("Since objective progress", value, tone, progress.lastTitle);
5358
+ return stat("Since objective progress", value, tone, progress2.lastTitle);
4902
5359
  }
4903
5360
  function renderHeadline(state2) {
4904
5361
  const headline = state2.brief.headline;
@@ -4953,6 +5410,7 @@ function App({ ui: ui2, handlers: handlers2 }) {
4953
5410
  const view = ui2.view.value;
4954
5411
  const run = current ? detailRun(current, ui2) : null;
4955
5412
  const row = current && !run ? detailRow(current, ui2) : null;
5413
+ if (current?.onboarding) return [k(OnboardingView, { state: current, ui: ui2, handlers: handlers2 }), k(Toast, { ui: ui2, handlers: handlers2 })];
4956
5414
  return [
4957
5415
  el("a", { class: "skip-link", href: "#main" }, "Skip to content"),
4958
5416
  k(Header, { state: current, ui: ui2, handlers: handlers2 }),
@@ -5116,12 +5574,12 @@ function installKeyboard(handlers2) {
5116
5574
  }
5117
5575
  const item = selectedItem();
5118
5576
  if (!item) return;
5119
- const boardRow2 = ui.view.value !== "today";
5577
+ const boardRow = ui.view.value !== "today";
5120
5578
  const status = "status" in item ? item.status : null;
5121
5579
  switch (event.key) {
5122
5580
  case "e":
5123
5581
  event.preventDefault();
5124
- if (!boardRow2 && status === "open") handlers2.onAction(item.id, "done");
5582
+ if (!boardRow && status === "open") handlers2.onAction(item.id, "done");
5125
5583
  break;
5126
5584
  case "s":
5127
5585
  event.preventDefault();
@@ -5129,7 +5587,7 @@ function installKeyboard(handlers2) {
5129
5587
  break;
5130
5588
  case "x":
5131
5589
  event.preventDefault();
5132
- if (!boardRow2 && status === "open") handlers2.onAction(item.id, "dismiss");
5590
+ if (!boardRow && status === "open") handlers2.onAction(item.id, "dismiss");
5133
5591
  break;
5134
5592
  case "n":
5135
5593
  event.preventDefault();
@@ -5159,6 +5617,9 @@ R(k(App, { ui, handlers }), root);
5159
5617
  j3(() => {
5160
5618
  document.body.dataset.view = ui.view.value;
5161
5619
  });
5620
+ j3(() => {
5621
+ document.body.dataset.onboarding = String(Boolean(state.value?.onboarding));
5622
+ });
5162
5623
  j3(() => {
5163
5624
  document.body.dataset.offline = String(ui.connectionError.value !== null);
5164
5625
  });