@harborppm/cli 0.117.0 → 0.119.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app.mjs CHANGED
@@ -2567,6 +2567,186 @@ var init_board = __esmMin((() => {
2567
2567
  ];
2568
2568
  }));
2569
2569
 
2570
+ // src/lib/cascade.ts
2571
+ /** What deleting a portfolio, program, or project takes with it, and the data left behind. Pure. */
2572
+ function cascadeDelete(data, kind, id) {
2573
+ const portfolioIds = new Set(kind === "portfolio" ? [id] : []);
2574
+ const programIds = new Set(kind === "program" ? [id] : data.programs.filter((p) => portfolioIds.has(p.portfolioId)).map((p) => p.id));
2575
+ const projectIds = new Set(kind === "project" ? [id] : data.projects.filter((p) => programIds.has(p.programId)).map((p) => p.id));
2576
+ const taskIds = new Set(data.tasks.filter((t) => projectIds.has(t.projectId)).map((t) => t.id));
2577
+ const milestones = data.milestones.filter((m) => !programIds.has(m.programId)).map((m) => withoutBlockers(m, projectIds));
2578
+ const goneMilestones = new Set(data.milestones.filter((m) => programIds.has(m.programId)).map((m) => m.id));
2579
+ const constraints = (data.constraints ?? []).filter((c) => !programIds.has(c.programId));
2580
+ const raidItems = data.raidItems.filter((r) => !(r.portfolioId && portfolioIds.has(r.portfolioId)) && !(r.programId && programIds.has(r.programId)) && !(r.projectId && projectIds.has(r.projectId)));
2581
+ const boardConfigs = Object.fromEntries(Object.entries(data.boardConfigs ?? {}).filter(([k]) => !projectIds.has(k)));
2582
+ return {
2583
+ data: {
2584
+ portfolios: data.portfolios.filter((p) => !portfolioIds.has(p.id)),
2585
+ programs: data.programs.filter((p) => !programIds.has(p.id)).map((p) => withoutBlockers(p, programIds)),
2586
+ projects: data.projects.filter((p) => !projectIds.has(p.id)).map((p) => withoutBlockers(p, projectIds)),
2587
+ tasks: data.tasks.filter((t) => !taskIds.has(t.id)).map((t) => withoutBlockers(t, taskIds)),
2588
+ milestones,
2589
+ constraints,
2590
+ raidItems,
2591
+ comments: data.comments.filter((c) => !taskIds.has(c.taskId)),
2592
+ attachments: (data.attachments ?? []).filter((a) => !taskIds.has(a.taskId)),
2593
+ boardConfigs,
2594
+ ropes: (data.ropes ?? []).map((r) => ({
2595
+ ...r,
2596
+ taskIds: r.taskIds.filter((t) => !taskIds.has(t))
2597
+ })),
2598
+ spendEntries: (data.spendEntries ?? []).filter((e) => !projectIds.has(e.projectId)),
2599
+ reflections: (data.reflections ?? []).filter((r) => !projectIds.has(r.projectId) && !(r.programId && programIds.has(r.programId)) && !(r.thanksFor?.kind === "milestone" && goneMilestones.has(r.thanksFor.id)))
2600
+ },
2601
+ counts: {
2602
+ programs: programIds.size,
2603
+ projects: projectIds.size,
2604
+ tasks: taskIds.size,
2605
+ milestones: data.milestones.length - milestones.length,
2606
+ raidItems: data.raidItems.length - raidItems.length,
2607
+ constraints: (data.constraints ?? []).length - constraints.length
2608
+ }
2609
+ };
2610
+ }
2611
+ /** "2 projects, 14 tasks, 3 milestones and 2 risks or issues" — or "" when nothing else goes. */
2612
+ function cascadeSummary(counts, kind) {
2613
+ const bits = [];
2614
+ const n = (count, one, many) => count > 0 ? `${count} ${count === 1 ? one : many}` : null;
2615
+ if (kind === "portfolio") bits.push(n(counts.programs, "program", "programs") ?? "");
2616
+ if (kind !== "project") bits.push(n(counts.projects, "project", "projects") ?? "");
2617
+ bits.push(n(counts.tasks, "task", "tasks") ?? "");
2618
+ bits.push(n(counts.milestones, "milestone", "milestones") ?? "");
2619
+ bits.push(n(counts.raidItems, "logged risk, issue or decision", "logged risks, issues and decisions") ?? "");
2620
+ const list = bits.filter(Boolean);
2621
+ if (list.length === 0) return "";
2622
+ if (list.length === 1) return list[0];
2623
+ return `${list.slice(0, -1).join(", ")} and ${list.at(-1)}`;
2624
+ }
2625
+ /** `data` with the cut links put back, wherever both ends exist again. */
2626
+ function relink(data, links) {
2627
+ const out = {};
2628
+ const exists = (key) => new Set(data[key].map((r) => r.id));
2629
+ const targetOf = {
2630
+ programs: "programs",
2631
+ projects: "projects",
2632
+ tasks: "tasks",
2633
+ milestones: "projects"
2634
+ };
2635
+ for (const key of [
2636
+ "programs",
2637
+ "projects",
2638
+ "tasks",
2639
+ "milestones"
2640
+ ]) {
2641
+ const cut = links.blockers[key];
2642
+ if (!cut) continue;
2643
+ const there = exists(targetOf[key]);
2644
+ out[key] = data[key].map((row) => {
2645
+ const was = cut[row.id];
2646
+ if (!was) return row;
2647
+ const ids = [.../* @__PURE__ */ new Set([...was, ...blockerIds(row)])].filter((id) => there.has(id));
2648
+ return ids.length === blockerIds(row).length ? row : {
2649
+ ...row,
2650
+ ...blockersPatch(ids)
2651
+ };
2652
+ });
2653
+ }
2654
+ if (Object.keys(links.focus).length) {
2655
+ const tasks = exists("tasks");
2656
+ out.ropes = (data.ropes ?? []).map((r) => {
2657
+ const lost = links.focus[`${r.personId}|${r.date}`];
2658
+ if (!lost) return r;
2659
+ const back = lost.filter((id) => tasks.has(id) && !r.taskIds.includes(id));
2660
+ return back.length ? {
2661
+ ...r,
2662
+ taskIds: [...r.taskIds, ...back]
2663
+ } : r;
2664
+ });
2665
+ }
2666
+ return out;
2667
+ }
2668
+ var init_cascade = __esmMin((() => {
2669
+ init_blockers();
2670
+ }));
2671
+
2672
+ // src/lib/sample-ids.ts
2673
+ function isSampleId(id) {
2674
+ return typeof id === "string" && id.startsWith("sample-");
2675
+ }
2676
+ /** Whether the harbor still holds the sample portfolio. */
2677
+ function hasSample(data) {
2678
+ return data.portfolios.some((p) => p.id === SAMPLE_PORTFOLIO_ID);
2679
+ }
2680
+ /**
2681
+ * The harbor with the sample taken out: its portfolio and everything under
2682
+ * it (as deleting the portfolio takes it), any sample program or project
2683
+ * moved elsewhere, and its made-up people. Work of the owner's own that
2684
+ * named one of those people as owner keeps going, with the owner in their
2685
+ * place, or nobody where nobody is allowed. Returns only the collections it
2686
+ * changed, ready for the store's write.
2687
+ */
2688
+ function withoutSample(data) {
2689
+ let doc = data;
2690
+ const cut = (kind, id) => {
2691
+ doc = {
2692
+ ...doc,
2693
+ ...cascadeDelete(doc, kind, id).data
2694
+ };
2695
+ };
2696
+ if (hasSample(doc)) cut("portfolio", SAMPLE_PORTFOLIO_ID);
2697
+ for (const p of doc.programs.filter((g) => isSampleId(g.id))) cut("program", p.id);
2698
+ for (const p of doc.projects.filter((j) => isSampleId(j.id))) cut("project", p.id);
2699
+ const gone = new Set(doc.people.filter((p) => isSampleId(p.id)).map((p) => p.id));
2700
+ const me = doc.currentUserId;
2701
+ const owner = (id) => gone.has(id) ? me : id;
2702
+ const maybe = (id) => id && gone.has(id) ? null : id ?? null;
2703
+ return {
2704
+ portfolios: doc.portfolios.map((p) => gone.has(p.ownerId) || p.goals?.some((g) => g.ownerId && gone.has(g.ownerId)) ? {
2705
+ ...p,
2706
+ ownerId: owner(p.ownerId),
2707
+ ...p.goals ? { goals: p.goals.map((g) => ({
2708
+ ...g,
2709
+ ownerId: maybe(g.ownerId)
2710
+ })) } : {}
2711
+ } : p),
2712
+ programs: doc.programs.map((p) => gone.has(p.ownerId) ? {
2713
+ ...p,
2714
+ ownerId: me
2715
+ } : p),
2716
+ projects: doc.projects.map((p) => gone.has(p.ownerId) ? {
2717
+ ...p,
2718
+ ownerId: me
2719
+ } : p),
2720
+ tasks: doc.tasks.filter((t) => !isSampleId(t.id)).map((t) => t.assigneeId && gone.has(t.assigneeId) ? {
2721
+ ...t,
2722
+ assigneeId: null
2723
+ } : t),
2724
+ milestones: doc.milestones.filter((m) => !isSampleId(m.id)).map((m) => m.approverId && gone.has(m.approverId) ? {
2725
+ ...m,
2726
+ approverId: null
2727
+ } : m),
2728
+ raidItems: doc.raidItems.filter((r) => !isSampleId(r.id)).map((r) => r.ownerId && gone.has(r.ownerId) ? {
2729
+ ...r,
2730
+ ownerId: null
2731
+ } : r),
2732
+ comments: doc.comments.filter((c) => !isSampleId(c.id)),
2733
+ people: doc.people.filter((p) => !gone.has(p.id)),
2734
+ constraints: doc.constraints,
2735
+ attachments: doc.attachments,
2736
+ boardConfigs: doc.boardConfigs,
2737
+ ropes: doc.ropes,
2738
+ ...doc.spendEntries ? { spendEntries: doc.spendEntries } : {},
2739
+ ...doc.reflections ? { reflections: doc.reflections } : {},
2740
+ activity: doc.activity.filter((a) => !a.href?.includes(`/${SAMPLE_PREFIX}`))
2741
+ };
2742
+ }
2743
+ var SAMPLE_PREFIX, SAMPLE_PORTFOLIO_ID;
2744
+ var init_sample_ids = __esmMin((() => {
2745
+ init_cascade();
2746
+ SAMPLE_PREFIX = "sample-";
2747
+ SAMPLE_PORTFOLIO_ID = "sample-portfolio";
2748
+ }));
2749
+
2570
2750
  // src/lib/task-keys.ts
2571
2751
  /** "Ridge Runner" → "RR", "Website" → "WEB", "Q4 launch plan" → "QLP". */
2572
2752
  function baseKey(name) {
@@ -2750,6 +2930,15 @@ function ownProjects(projects) {
2750
2930
  return projects.filter((p) => !isVoyageProject(p.id));
2751
2931
  }
2752
2932
  /**
2933
+ * The projects a harbor's people brought: without First voyage and without
2934
+ * the sample portfolio's (src/lib/sample-portfolio.ts). For the questions
2935
+ * about a new harbor's own start (its first project, where a new task goes,
2936
+ * the first-week list, the funnel), not for what the harbor's pages show.
2937
+ */
2938
+ function realProjects(projects) {
2939
+ return projects.filter((p) => !isVoyageProject(p.id) && !isSampleId(p.id));
2940
+ }
2941
+ /**
2753
2942
  * The harbor as anyone outside it may see it: First voyage is practice, so
2754
2943
  * share links, their embeds and the Monday letter to stakeholders leave it
2755
2944
  * out, with its tasks, risks and spend, from what they show and count.
@@ -2775,11 +2964,11 @@ function voyageTicks(data, signals) {
2775
2964
  if (!data.projects.some((p) => isVoyageProject(p.id))) return [];
2776
2965
  const open = data.tasks.filter((t) => SEEDED.has(t.id) && t.status !== "done" && t.assigneeId === data.currentUserId);
2777
2966
  if (open.length === 0) return [];
2778
- const own = (t) => !SEEDED.has(t.id);
2967
+ const own = (t) => !SEEDED.has(t.id) && !isSampleId(t.id);
2779
2968
  const done = {
2780
2969
  task: data.tasks.some(own),
2781
- move: data.tasks.some((t) => MOVED.includes(t.status) || own(t) && t.status === "done"),
2782
- crew: data.people.length > 1,
2970
+ move: data.tasks.some((t) => !isSampleId(t.id) && (MOVED.includes(t.status) || own(t) && t.status === "done")),
2971
+ crew: data.people.filter((p) => !isSampleId(p.id)).length > 1,
2783
2972
  terminal: signals.apps?.some((a) => a === "Harbor CLI") ?? false,
2784
2973
  agent: signals.apps?.some((a) => a !== "Harbor CLI") ?? false,
2785
2974
  wrap: false
@@ -2788,6 +2977,7 @@ function voyageTicks(data, signals) {
2788
2977
  }
2789
2978
  var VOYAGE_PROJECT_ID, STEPS, voyageTaskId, VOYAGE_NO_FORECAST, MOVED, SEEDED;
2790
2979
  var init_first_voyage = __esmMin((() => {
2980
+ init_sample_ids();
2791
2981
  VOYAGE_PROJECT_ID = "voyage";
2792
2982
  STEPS = [
2793
2983
  {
@@ -2928,6 +3118,7 @@ function weekPlan(data, personId, monday) {
2928
3118
  date,
2929
3119
  items,
2930
3120
  hours,
3121
+ doneHours: items.reduce((sum, i) => sum + (i.task.status === "done" ? i.hours : 0), 0),
2931
3122
  over: hours > dayHours
2932
3123
  };
2933
3124
  });
@@ -3034,112 +3225,9 @@ function trialDaysLeft(trialEndsAt, now = /* @__PURE__ */ new Date()) {
3034
3225
  return Math.ceil(ms / 864e5);
3035
3226
  }
3036
3227
 
3037
- // src/lib/cascade.ts
3038
- /** What deleting a portfolio, program, or project takes with it, and the data left behind. Pure. */
3039
- function cascadeDelete(data, kind, id) {
3040
- const portfolioIds = new Set(kind === "portfolio" ? [id] : []);
3041
- const programIds = new Set(kind === "program" ? [id] : data.programs.filter((p) => portfolioIds.has(p.portfolioId)).map((p) => p.id));
3042
- const projectIds = new Set(kind === "project" ? [id] : data.projects.filter((p) => programIds.has(p.programId)).map((p) => p.id));
3043
- const taskIds = new Set(data.tasks.filter((t) => projectIds.has(t.projectId)).map((t) => t.id));
3044
- const milestones = data.milestones.filter((m) => !programIds.has(m.programId)).map((m) => withoutBlockers(m, projectIds));
3045
- const goneMilestones = new Set(data.milestones.filter((m) => programIds.has(m.programId)).map((m) => m.id));
3046
- const constraints = (data.constraints ?? []).filter((c) => !programIds.has(c.programId));
3047
- const raidItems = data.raidItems.filter((r) => !(r.portfolioId && portfolioIds.has(r.portfolioId)) && !(r.programId && programIds.has(r.programId)) && !(r.projectId && projectIds.has(r.projectId)));
3048
- const boardConfigs = Object.fromEntries(Object.entries(data.boardConfigs ?? {}).filter(([k]) => !projectIds.has(k)));
3049
- return {
3050
- data: {
3051
- portfolios: data.portfolios.filter((p) => !portfolioIds.has(p.id)),
3052
- programs: data.programs.filter((p) => !programIds.has(p.id)).map((p) => withoutBlockers(p, programIds)),
3053
- projects: data.projects.filter((p) => !projectIds.has(p.id)).map((p) => withoutBlockers(p, projectIds)),
3054
- tasks: data.tasks.filter((t) => !taskIds.has(t.id)).map((t) => withoutBlockers(t, taskIds)),
3055
- milestones,
3056
- constraints,
3057
- raidItems,
3058
- comments: data.comments.filter((c) => !taskIds.has(c.taskId)),
3059
- attachments: (data.attachments ?? []).filter((a) => !taskIds.has(a.taskId)),
3060
- boardConfigs,
3061
- ropes: (data.ropes ?? []).map((r) => ({
3062
- ...r,
3063
- taskIds: r.taskIds.filter((t) => !taskIds.has(t))
3064
- })),
3065
- spendEntries: (data.spendEntries ?? []).filter((e) => !projectIds.has(e.projectId)),
3066
- reflections: (data.reflections ?? []).filter((r) => !projectIds.has(r.projectId) && !(r.programId && programIds.has(r.programId)) && !(r.thanksFor?.kind === "milestone" && goneMilestones.has(r.thanksFor.id)))
3067
- },
3068
- counts: {
3069
- programs: programIds.size,
3070
- projects: projectIds.size,
3071
- tasks: taskIds.size,
3072
- milestones: data.milestones.length - milestones.length,
3073
- raidItems: data.raidItems.length - raidItems.length,
3074
- constraints: (data.constraints ?? []).length - constraints.length
3075
- }
3076
- };
3077
- }
3078
- /** "2 projects, 14 tasks, 3 milestones and 2 risks or issues" — or "" when nothing else goes. */
3079
- function cascadeSummary(counts, kind) {
3080
- const bits = [];
3081
- const n = (count, one, many) => count > 0 ? `${count} ${count === 1 ? one : many}` : null;
3082
- if (kind === "portfolio") bits.push(n(counts.programs, "program", "programs") ?? "");
3083
- if (kind !== "project") bits.push(n(counts.projects, "project", "projects") ?? "");
3084
- bits.push(n(counts.tasks, "task", "tasks") ?? "");
3085
- bits.push(n(counts.milestones, "milestone", "milestones") ?? "");
3086
- bits.push(n(counts.raidItems, "logged risk, issue or decision", "logged risks, issues and decisions") ?? "");
3087
- const list = bits.filter(Boolean);
3088
- if (list.length === 0) return "";
3089
- if (list.length === 1) return list[0];
3090
- return `${list.slice(0, -1).join(", ")} and ${list.at(-1)}`;
3091
- }
3092
- /** `data` with the cut links put back, wherever both ends exist again. */
3093
- function relink(data, links) {
3094
- const out = {};
3095
- const exists = (key) => new Set(data[key].map((r) => r.id));
3096
- const targetOf = {
3097
- programs: "programs",
3098
- projects: "projects",
3099
- tasks: "tasks",
3100
- milestones: "projects"
3101
- };
3102
- for (const key of [
3103
- "programs",
3104
- "projects",
3105
- "tasks",
3106
- "milestones"
3107
- ]) {
3108
- const cut = links.blockers[key];
3109
- if (!cut) continue;
3110
- const there = exists(targetOf[key]);
3111
- out[key] = data[key].map((row) => {
3112
- const was = cut[row.id];
3113
- if (!was) return row;
3114
- const ids = [.../* @__PURE__ */ new Set([...was, ...blockerIds(row)])].filter((id) => there.has(id));
3115
- return ids.length === blockerIds(row).length ? row : {
3116
- ...row,
3117
- ...blockersPatch(ids)
3118
- };
3119
- });
3120
- }
3121
- if (Object.keys(links.focus).length) {
3122
- const tasks = exists("tasks");
3123
- out.ropes = (data.ropes ?? []).map((r) => {
3124
- const lost = links.focus[`${r.personId}|${r.date}`];
3125
- if (!lost) return r;
3126
- const back = lost.filter((id) => tasks.has(id) && !r.taskIds.includes(id));
3127
- return back.length ? {
3128
- ...r,
3129
- taskIds: [...r.taskIds, ...back]
3130
- } : r;
3131
- });
3132
- }
3133
- return out;
3134
- }
3135
- var init_cascade = __esmMin((() => {
3136
- init_blockers();
3137
- }));
3138
-
3139
3228
  // src/lib/forecast.ts
3140
- init_cascade();
3141
3229
  init_date_fns();
3142
- const day$9 = (iso) => /* @__PURE__ */ new Date(`${iso}T12:00:00`);
3230
+ const day$10 = (iso) => /* @__PURE__ */ new Date(`${iso}T12:00:00`);
3143
3231
  /**
3144
3232
  * A straight-line estimate at completion from the burn so far: spend divided
3145
3233
  * by the share of the schedule elapsed. Null before anything is spent or
@@ -3148,8 +3236,8 @@ const day$9 = (iso) => /* @__PURE__ */ new Date(`${iso}T12:00:00`);
3148
3236
  */
3149
3237
  function forecastAtCompletion(item, now) {
3150
3238
  if (item.spent <= 0) return null;
3151
- const total = differenceInCalendarDays(day$9(item.endDate), day$9(item.startDate)) + 1;
3152
- const gone = differenceInCalendarDays(now, day$9(item.startDate)) + 1;
3239
+ const total = differenceInCalendarDays(day$10(item.endDate), day$10(item.startDate)) + 1;
3240
+ const gone = differenceInCalendarDays(now, day$10(item.startDate)) + 1;
3153
3241
  if (total <= 0 || gone <= 0) return null;
3154
3242
  const elapsed = Math.min(1, gone / total);
3155
3243
  const eac = Math.round(item.spent / elapsed);
@@ -4396,7 +4484,7 @@ init_tide();
4396
4484
  init_raid();
4397
4485
  init_flow();
4398
4486
  init_date_fns();
4399
- const day$8 = (iso) => /* @__PURE__ */ new Date(`${iso}T12:00:00`);
4487
+ const day$9 = (iso) => /* @__PURE__ */ new Date(`${iso}T12:00:00`);
4400
4488
  function monthKey(iso) {
4401
4489
  return iso.slice(0, 7);
4402
4490
  }
@@ -4412,7 +4500,7 @@ function monthsBetween(from, to) {
4412
4500
  return out;
4413
4501
  }
4414
4502
  function daysIn(key) {
4415
- return getDaysInMonth(day$8(`${key}-01`));
4503
+ return getDaysInMonth(day$9(`${key}-01`));
4416
4504
  }
4417
4505
  /** How many of the schedule's days fall in `key`. */
4418
4506
  function overlapDays(key, start, end) {
@@ -4420,7 +4508,7 @@ function overlapDays(key, start, end) {
4420
4508
  const lastDay = `${key}-${String(daysIn(key)).padStart(2, "0")}`;
4421
4509
  const from = start > first ? start : first;
4422
4510
  const to = end < lastDay ? end : lastDay;
4423
- return to < from ? 0 : differenceInCalendarDays(day$8(to), day$8(from)) + 1;
4511
+ return to < from ? 0 : differenceInCalendarDays(day$9(to), day$9(from)) + 1;
4424
4512
  }
4425
4513
  /**
4426
4514
  * The budget spread straight across the schedule: each month gets the share
@@ -4430,7 +4518,7 @@ function overlapDays(key, start, end) {
4430
4518
  function evenPhasing(project) {
4431
4519
  const end = project.endDate < project.startDate ? project.startDate : project.endDate;
4432
4520
  const months = monthsBetween(project.startDate, end);
4433
- const total = differenceInCalendarDays(day$8(end), day$8(project.startDate)) + 1;
4521
+ const total = differenceInCalendarDays(day$9(end), day$9(project.startDate)) + 1;
4434
4522
  const out = {};
4435
4523
  let placed = 0;
4436
4524
  months.forEach((k, i) => {
@@ -4537,7 +4625,7 @@ function hasBaseline(p) {
4537
4625
  /** Days the end has moved past the baseline end; negative when it came in. Null without a baseline. */
4538
4626
  function slipDays(p) {
4539
4627
  if (!p.baselineEnd) return null;
4540
- return differenceInCalendarDays(day$7(p.endDate), day$7(p.baselineEnd));
4628
+ return differenceInCalendarDays(day$8(p.endDate), day$8(p.baselineEnd));
4541
4629
  }
4542
4630
  /**
4543
4631
  * The projects with the current dates committed as their baseline; ones that
@@ -4559,10 +4647,10 @@ function slipLabel(p) {
4559
4647
  const n = Math.abs(slip);
4560
4648
  return slip > 0 ? `slipped ${n} day${n === 1 ? "" : "s"}` : `${n} day${n === 1 ? "" : "s"} early`;
4561
4649
  }
4562
- var day$7;
4650
+ var day$8;
4563
4651
  var init_baseline = __esmMin((() => {
4564
4652
  init_date_fns();
4565
- day$7 = (iso) => /* @__PURE__ */ new Date(`${iso}T12:00:00`);
4653
+ day$8 = (iso) => /* @__PURE__ */ new Date(`${iso}T12:00:00`);
4566
4654
  }));
4567
4655
 
4568
4656
  // src/lib/roadmap.ts
@@ -4590,7 +4678,7 @@ const ZOOMS = [
4590
4678
  step: 3
4591
4679
  }
4592
4680
  ];
4593
- const day$6 = (iso) => /* @__PURE__ */ new Date(`${iso.slice(0, 10)}T12:00:00`);
4681
+ const day$7 = (iso) => /* @__PURE__ */ new Date(`${iso.slice(0, 10)}T12:00:00`);
4594
4682
  /** Names in the order people expect: "Phase 2" before "Phase 10". */
4595
4683
  const byName = (a, b) => a.localeCompare(b, void 0, { numeric: true });
4596
4684
  const isoDay$4 = (d) => format(d, "yyyy-MM-dd");
@@ -4600,7 +4688,7 @@ const isoDay$4 = (d) => format(d, "yyyy-MM-dd");
4600
4688
  */
4601
4689
  function roadmapWindow(zoom, today, shift = 0) {
4602
4690
  const z = ZOOMS.find((x) => x.id === zoom) ?? ZOOMS[1];
4603
- const first = addMonths$1(startOfMonth(day$6(today)), -1 + shift * z.step);
4691
+ const first = addMonths$1(startOfMonth(day$7(today)), -1 + shift * z.step);
4604
4692
  const after = addMonths$1(first, z.months);
4605
4693
  const days = differenceInCalendarDays(after, first);
4606
4694
  const months = Array.from({ length: z.months }, (_, i) => {
@@ -4624,15 +4712,15 @@ function roadmapWindow(zoom, today, shift = 0) {
4624
4712
  function at(iso, w) {
4625
4713
  if (!iso) return null;
4626
4714
  if (iso < w.start || iso >= w.end) return null;
4627
- return differenceInCalendarDays(day$6(iso), day$6(w.start)) / w.days;
4715
+ return differenceInCalendarDays(day$7(iso), day$7(w.start)) / w.days;
4628
4716
  }
4629
4717
  /** A bar for a start–end span, clipped to the window; null when it's wholly outside. */
4630
4718
  function span$1(start, end, w) {
4631
4719
  if (!start || !end || end < w.start || start >= w.end) return null;
4632
4720
  const from = start < w.start ? w.start : start;
4633
- const until = end >= w.end ? w.end : isoDay$4(new Date(day$6(end).getTime() + 864e5));
4634
- const left = differenceInCalendarDays(day$6(from), day$6(w.start)) / w.days;
4635
- const right = differenceInCalendarDays(day$6(until), day$6(w.start)) / w.days;
4721
+ const until = end >= w.end ? w.end : isoDay$4(new Date(day$7(end).getTime() + 864e5));
4722
+ const left = differenceInCalendarDays(day$7(from), day$7(w.start)) / w.days;
4723
+ const right = differenceInCalendarDays(day$7(until), day$7(w.start)) / w.days;
4636
4724
  return {
4637
4725
  left,
4638
4726
  width: Math.max(right - left, 1 / w.days),
@@ -5209,6 +5297,7 @@ init_date_text();
5209
5297
  init_first_voyage();
5210
5298
  init_indexes();
5211
5299
  init_subtasks();
5300
+ init_cascade();
5212
5301
  init_tide();
5213
5302
  init_format();
5214
5303
  init_spend();
@@ -7954,7 +8043,83 @@ function wipOverflowing(data, projectId) {
7954
8043
  const review = mine.filter((t) => t.status === "review").length;
7955
8044
  return doing > 3 || review > 2;
7956
8045
  }
8046
+ function idOf(value) {
8047
+ if (!value) return 0;
8048
+ let id = objectIds.get(value);
8049
+ if (id === void 0) objectIds.set(value, id = nextObjectId++);
8050
+ return id;
8051
+ }
8052
+ function calendarOf(data) {
8053
+ const kept = calendars.get(data.people);
8054
+ if (kept && kept.workCalendar === data.workCalendar) return kept.calendar;
8055
+ const calendar = workCalendar({
8056
+ people: data.people,
8057
+ workCalendar: data.workCalendar
8058
+ });
8059
+ calendars.set(data.people, {
8060
+ workCalendar: data.workCalendar,
8061
+ calendar
8062
+ });
8063
+ return calendar;
8064
+ }
8065
+ /**
8066
+ * The forecast's chance (0 to 1) that a project finishes by its end date,
8067
+ * the same number its Forecast tab shows; null when there's no forecast to
8068
+ * go by (no open work, too little finished lately, paused or done).
8069
+ */
8070
+ function forecastChance(project, data, now) {
8071
+ if (project.health === "paused" || project.health === "done" || !project.endDate) return null;
8072
+ const tasks = tasksOf(data.tasks, project.id);
8073
+ let open = 0;
8074
+ for (const t of tasks) if (t.status !== "done") open++;
8075
+ if (open === 0) return null;
8076
+ const weekly = weeklyFinished(tasks, project.startDate, now);
8077
+ if (weekly.reduce((a, b) => a + b, 0) < 5) return null;
8078
+ let sig = "";
8079
+ for (const t of tasks) if (t.status !== "done") sig += `${t.id}:${t.status}:${t.dueDate ?? ""}:${t.assigneeId ?? ""};`;
8080
+ const key = [
8081
+ iso$3(now),
8082
+ project.startDate,
8083
+ project.endDate,
8084
+ weekly.join(","),
8085
+ idOf(data.reflections),
8086
+ idOf(data.people),
8087
+ idOf(data.workCalendar),
8088
+ sig
8089
+ ].join("|");
8090
+ const kept = chanceKept.get(project.id);
8091
+ if (kept?.key === key) return kept.chance;
8092
+ const tide = tideForecast(project, tasks, now, {
8093
+ reflections: data.reflections,
8094
+ calendar: calendarOf(data)
8095
+ });
8096
+ const chance = tide.kind === "forecast" ? tide.chanceByEnd : null;
8097
+ if (chanceKept.size > 5e3) chanceKept.clear();
8098
+ chanceKept.set(project.id, {
8099
+ key,
8100
+ chance
8101
+ });
8102
+ return chance;
8103
+ }
8104
+ function forecastTrack(chance) {
8105
+ if (chance == null) return "on-track";
8106
+ if (chance < .15) return "off-track";
8107
+ if (chance < .5) return "at-risk";
8108
+ return "on-track";
8109
+ }
8110
+ /**
8111
+ * The rules, then the forecast: a project the rules call on track (or at
8112
+ * risk) reads worse when its forecast gives it under even odds of finishing
8113
+ * by its end date. The forecast only ever makes it worse: a late task is a
8114
+ * late task, whatever the pace says.
8115
+ */
7957
8116
  function deriveProjectHealth(project, data, now) {
8117
+ const rules = ruleProjectHealth(project, data, now);
8118
+ if (rules === "off-track") return rules;
8119
+ return worstTrack([rules, forecastTrack(forecastChance(project, data, now))]);
8120
+ }
8121
+ /** Health from late work, end dates, blockers and crowded boards, before the forecast. */
8122
+ function ruleProjectHealth(project, data, now) {
7958
8123
  const tasks = tasksOf(data.tasks, project.id);
7959
8124
  const open = tasks.filter(incomplete);
7960
8125
  const maxOverdue = open.map((t) => daysOverdue(t.dueDate, now)).reduce((a, b) => Math.max(a, b), 0);
@@ -8102,7 +8267,7 @@ function programLateCount(programId, data, now) {
8102
8267
  for (const p of data.projects) if (p.programId === programId) late += lateTasksOf([...tasksOf(data.tasks, p.id)], now).length;
8103
8268
  return late;
8104
8269
  }
8105
- var iso$3, overdueDay, overdueByDue, untilDay, untilByDate;
8270
+ var iso$3, overdueDay, overdueByDue, untilDay, untilByDate, FORECAST_AT_RISK, FORECAST_OFF_TRACK, FORECAST_MIN_FINISHED, chanceKept, objectIds, nextObjectId, calendars;
8106
8271
  var init_derived_health = __esmMin((() => {
8107
8272
  init_date_fns();
8108
8273
  init_date_text();
@@ -8110,6 +8275,8 @@ var init_derived_health = __esmMin((() => {
8110
8275
  init_indexes();
8111
8276
  init_health_history();
8112
8277
  init_clock();
8278
+ init_holidays();
8279
+ init_tide();
8113
8280
  iso$3 = (d) => {
8114
8281
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
8115
8282
  };
@@ -8117,6 +8284,13 @@ var init_derived_health = __esmMin((() => {
8117
8284
  overdueByDue = /* @__PURE__ */ new Map();
8118
8285
  untilDay = "";
8119
8286
  untilByDate = /* @__PURE__ */ new Map();
8287
+ FORECAST_AT_RISK = .5;
8288
+ FORECAST_OFF_TRACK = .15;
8289
+ FORECAST_MIN_FINISHED = 5;
8290
+ chanceKept = /* @__PURE__ */ new Map();
8291
+ objectIds = /* @__PURE__ */ new WeakMap();
8292
+ nextObjectId = 1;
8293
+ calendars = /* @__PURE__ */ new WeakMap();
8120
8294
  }));
8121
8295
 
8122
8296
  // src/lib/bottle-rules.ts
@@ -8193,7 +8367,7 @@ function bottleState(note, ctx) {
8193
8367
  /** "opens on Nov 14", "opens when Factory buy-off is reached", "opens if Ridge Runner launch turns Off track" */
8194
8368
  function opensText(opens, ctx) {
8195
8369
  if (!opens) return "open now";
8196
- if (opens.on === "date") return `opens on ${day$5(opens.date)}`;
8370
+ if (opens.on === "date") return `opens on ${day$6(opens.date)}`;
8197
8371
  if (opens.on === "milestone") {
8198
8372
  const m = ctx.milestones.find((x) => x.id === opens.milestoneId);
8199
8373
  return m ? `opens when ${m.name} is reached` : "opens when its milestone is reached";
@@ -8227,7 +8401,7 @@ function freshlyOpened(data, projects, now) {
8227
8401
  }
8228
8402
  return out.sort((a, b) => (b.state.openedOn ?? "").localeCompare(a.state.openedOn ?? ""));
8229
8403
  }
8230
- var BOTTLE_FRESH_DAYS, isBottle, sealed, day$5;
8404
+ var BOTTLE_FRESH_DAYS, isBottle, sealed, day$6;
8231
8405
  var init_bottle = __esmMin((() => {
8232
8406
  init_date_fns();
8233
8407
  init_date_text();
@@ -8239,7 +8413,7 @@ var init_bottle = __esmMin((() => {
8239
8413
  open: false,
8240
8414
  openedOn: null
8241
8415
  };
8242
- day$5 = (iso) => format(parseIso(iso.slice(0, 10)), "MMM d");
8416
+ day$6 = (iso) => format(parseIso(iso.slice(0, 10)), "MMM d");
8243
8417
  }));
8244
8418
 
8245
8419
  // src/lib/decisions.ts
@@ -8991,7 +9165,7 @@ function shippingForecast(data, opts) {
8991
9165
  const { now } = opts;
8992
9166
  const today = todayISO(now);
8993
9167
  const programs = data.programs.filter((p) => !opts.portfolioId || p.portfolioId === opts.portfolioId);
8994
- const areas = programs.filter((p) => ORDER[p.health] != null).sort((a, b) => (ORDER[a.health] ?? 9) - (ORDER[b.health] ?? 9) || a.endDate.localeCompare(b.endDate)).map((program) => area(data, program, now, today));
9168
+ const areas = programs.filter((p) => ORDER$1[p.health] != null).sort((a, b) => (ORDER$1[a.health] ?? 9) - (ORDER$1[b.health] ?? 9) || a.endDate.localeCompare(b.endDate)).map((program) => area(data, program, now, today));
8995
9169
  const opening = `And now the harbor forecast for ${opts.harborName?.trim() || "Harbor"}, issued at ${issuedAt(now)} on ${format(now, "EEEE d MMMM")}.`;
8996
9170
  const gales = areas.filter((a) => a.health === "off-track").map((a) => a.name);
8997
9171
  const warnings = gales.length ? `There are warnings of gales in ${list$3(gales)}.` : null;
@@ -9065,7 +9239,7 @@ function area(data, program, now, today) {
9065
9239
  force: wind.force
9066
9240
  };
9067
9241
  }
9068
- var FORECAST_AREAS, WORDS, VISIBILITY, ORDER;
9242
+ var FORECAST_AREAS, WORDS, VISIBILITY, ORDER$1;
9069
9243
  var init_shipping_forecast = __esmMin((() => {
9070
9244
  init_date_fns();
9071
9245
  init_derived_health();
@@ -9096,7 +9270,7 @@ var init_shipping_forecast = __esmMin((() => {
9096
9270
  "at-risk": "moderate",
9097
9271
  "off-track": "poor"
9098
9272
  };
9099
- ORDER = {
9273
+ ORDER$1 = {
9100
9274
  "off-track": 0,
9101
9275
  "at-risk": 1,
9102
9276
  "on-track": 2
@@ -10629,8 +10803,8 @@ init_blockers();
10629
10803
  init_date_text();
10630
10804
  init_premortem();
10631
10805
  init_thanks();
10632
- const day$4 = (iso) => parseIso(localDay(iso));
10633
- const between = (a, b) => differenceInCalendarDays(day$4(b), day$4(a));
10806
+ const day$5 = (iso) => parseIso(localDay(iso));
10807
+ const between = (a, b) => differenceInCalendarDays(day$5(b), day$5(a));
10634
10808
  function voyageLog(data, projectId) {
10635
10809
  const project = data.projects.find((p) => p.id === projectId);
10636
10810
  if (!project) return null;
@@ -10697,7 +10871,7 @@ function voyageLog(data, projectId) {
10697
10871
  };
10698
10872
  }
10699
10873
  const plural$7 = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
10700
- const md$1 = (iso) => format(day$4(iso), "MMM d");
10874
+ const md$1 = (iso) => format(day$5(iso), "MMM d");
10701
10875
  /** The three numbers at the top: how late, how much work, how many risks came true. */
10702
10876
  function voyageStats(log) {
10703
10877
  const happened = log.risks.filter((r) => r.happened).length;
@@ -10976,6 +11150,19 @@ const WHEN = [
10976
11150
  ].join("|");
10977
11151
  const LEAD$1 = "(?:by|due|due on|due by|on|before|until|till)";
10978
11152
  /** The day a phrase names, or null when it names none. */
11153
+ /**
11154
+ * The one person a name key ("sam", "samrivera", loosened) means: the full
11155
+ * name, else the first name, else (three letters or more) the one name it
11156
+ * starts. Two people who fit means nobody.
11157
+ */
11158
+ function personForKey(key, people) {
11159
+ const full = people.filter((p) => loose(p.name) === key);
11160
+ if (full.length === 1) return full[0];
11161
+ const first = people.filter((p) => loose(p.name.split(/\s+/)[0] ?? "") === key);
11162
+ if (first.length === 1) return first[0];
11163
+ const begins = people.filter((p) => loose(p.name).startsWith(key));
11164
+ return key.length >= 3 && begins.length === 1 ? begins[0] : null;
11165
+ }
10979
11166
  function dayFromWords(phrase, today) {
10980
11167
  const p = phrase.toLowerCase().replace(/\s+/g, " ").replace(/^on /, "").trim();
10981
11168
  if (p === "today" || p === "tonight") return today;
@@ -11090,14 +11277,7 @@ function readTaskWords(input, ctx) {
11090
11277
  let owner = null;
11091
11278
  const nobody = [];
11092
11279
  if (!skip.has("owner")) {
11093
- const byKey = (key) => {
11094
- const full = ctx.people.filter((p) => loose(p.name) === key);
11095
- if (full.length === 1) return full[0];
11096
- const first = ctx.people.filter((p) => loose(p.name.split(/\s+/)[0] ?? "") === key);
11097
- if (first.length === 1) return first[0];
11098
- const begins = ctx.people.filter((p) => loose(p.name).startsWith(key));
11099
- return key.length >= 3 && begins.length === 1 ? begins[0] : null;
11100
- };
11280
+ const byKey = (key) => personForKey(key, ctx.people);
11101
11281
  for (const m of text.matchAll(/(?:^|\s)@([\p{L}\p{N}._-]+)/gu)) {
11102
11282
  const start = m.index + (m[0].length - m[0].trimStart().length);
11103
11283
  const end = m.index + m[0].length;
@@ -13078,7 +13258,7 @@ function dollars(value) {
13078
13258
  const n = Number(value ?? 0);
13079
13259
  return whole$1.format(Number.isFinite(n) ? n : 0);
13080
13260
  }
13081
- function day$3(value) {
13261
+ function day$4(value) {
13082
13262
  return value ? shortDate(value) : "no date";
13083
13263
  }
13084
13264
  /** Whole days from one ISO day to another. */
@@ -13166,15 +13346,15 @@ function describeEvent(e, names) {
13166
13346
  };
13167
13347
  case "dueDate": return {
13168
13348
  action: "moved the due date of",
13169
- detail: `from ${day$3(from)} to ${day$3(to)}${slip(from, to)}`
13349
+ detail: `from ${day$4(from)} to ${day$4(to)}${slip(from, to)}`
13170
13350
  };
13171
13351
  case "startDate": return {
13172
13352
  action: "moved the start of",
13173
- detail: `from ${day$3(from)} to ${day$3(to)}${slip(from, to)}`
13353
+ detail: `from ${day$4(from)} to ${day$4(to)}${slip(from, to)}`
13174
13354
  };
13175
13355
  case "endDate": return {
13176
13356
  action: "moved the end of",
13177
- detail: `from ${day$3(from)} to ${day$3(to)}${slip(from, to)}`
13357
+ detail: `from ${day$4(from)} to ${day$4(to)}${slip(from, to)}`
13178
13358
  };
13179
13359
  case "budget": return {
13180
13360
  action: "changed the budget of",
@@ -13462,11 +13642,11 @@ function HistoryView({ active, width, height, go }) {
13462
13642
  // src/lib/daily-digest.ts
13463
13643
  /**
13464
13644
  * The projects a scope covers; a person's are the ones they lead, sit under,
13465
- * or have a task in. First voyage is practice, so its tasks, talk and
13466
- * health never count as what changed.
13645
+ * or have a task in. First voyage is practice and the sample portfolio is
13646
+ * made up, so their tasks, talk and health never count as what changed.
13467
13647
  */
13468
13648
  function projectsIn(data, scope) {
13469
- const own = ownProjects(data.projects);
13649
+ const own = realProjects(data.projects);
13470
13650
  if (scope.kind === "harbor") return own;
13471
13651
  if (scope.kind === "program") return own.filter((p) => p.programId === scope.id);
13472
13652
  const led = new Set(data.programs.filter((p) => p.ownerId === scope.id).map((p) => p.id));
@@ -13755,7 +13935,7 @@ init_date_fns();
13755
13935
  init_date_text();
13756
13936
  init_indexes();
13757
13937
  init_tide();
13758
- const day$2 = (iso) => parseIso(iso.slice(0, 10));
13938
+ const day$3 = (iso) => parseIso(iso.slice(0, 10));
13759
13939
  /** When a convoy looks like arriving, and how that was read. */
13760
13940
  function expectedOf(data, convoy, now) {
13761
13941
  const project = convoy.projectId ? byId(data.projects).get(convoy.projectId) ?? null : null;
@@ -13793,7 +13973,7 @@ function convoyRows(data, now) {
13793
13973
  for (const asker of data.programs) for (const convoy of asker.convoys ?? []) {
13794
13974
  const giver = programs.get(convoy.toProgramId) ?? null;
13795
13975
  const { expected, basis, project } = expectedOf(data, convoy, now);
13796
- const late = expected ? differenceInCalendarDays(day$2(expected), day$2(convoy.by)) : null;
13976
+ const late = expected ? differenceInCalendarDays(day$3(expected), day$3(convoy.by)) : null;
13797
13977
  out.push({
13798
13978
  convoy,
13799
13979
  asker,
@@ -13849,7 +14029,7 @@ const MONTHS = [
13849
14029
  ];
13850
14030
  /** "Dec 12". */
13851
14031
  function shortDay(iso) {
13852
- const d = day$2(iso);
14032
+ const d = day$3(iso);
13853
14033
  return Number.isNaN(d.getTime()) ? iso : `${MONTHS[d.getMonth()]} ${d.getDate()}`;
13854
14034
  }
13855
14035
  /** Who should hear about a convoy: its program's owner and whoever asked or answered. */
@@ -14413,6 +14593,314 @@ function InboxView({ active, width, height, go }) {
14413
14593
  });
14414
14594
  }
14415
14595
 
14596
+ // src/lib/agents.ts
14597
+ init_agent_check();
14598
+ const RANK$1 = {
14599
+ urgent: 0,
14600
+ high: 1,
14601
+ medium: 2,
14602
+ low: 3
14603
+ };
14604
+ /** Sent back by the person who checked it, with a note saying what to change. */
14605
+ const sentBack = (t) => t.approval?.status === "changes_requested" && t.status !== "done" && t.status !== "review";
14606
+ /** What an agent should work on: its open tasks not yet waiting on review, what was sent back first, then in progress, then most urgent and soonest. */
14607
+ function agentQueue(data, agentId) {
14608
+ return data.tasks.filter((t) => t.assigneeId === agentId && (t.status === "todo" || t.status === "doing" || t.status === "backlog")).sort((a, b) => Number(sentBack(b)) - Number(sentBack(a)) || Number(b.status === "doing") - Number(a.status === "doing") || Number(a.status === "backlog") - Number(b.status === "backlog") || RANK$1[a.priority] - RANK$1[b.priority] || (a.dueDate ?? "9999").localeCompare(b.dueDate ?? "9999"));
14609
+ }
14610
+ /** The agent an app means: the one named, else the only one on the crew. */
14611
+ function pickAgent(people, key) {
14612
+ const agents = people.filter(isAgent);
14613
+ if (agents.length === 0) return "There are no agents on this harbor's crew yet. Someone adds one on People with Add an agent.";
14614
+ if (!key) {
14615
+ if (agents.length === 1) return agents[0];
14616
+ return `This harbor has ${agents.length} agents (${agents.map((a) => a.name).join(", ")}). Say which with agent.`;
14617
+ }
14618
+ const k = key.trim().toLowerCase();
14619
+ return agents.find((a) => a.id === key.trim() || a.name.trim().toLowerCase() === k) ?? `No agent called "${key}". The crew's agents: ${agents.map((a) => a.name).join(", ")}.`;
14620
+ }
14621
+
14622
+ // src/lib/agents-page.ts
14623
+ init_agent_check();
14624
+ init_format();
14625
+ /** The agent a task belongs to: the one it's assigned to, else the one that handed it in. */
14626
+ function agentOf(task, agents) {
14627
+ return (task.assigneeId ? agents.get(task.assigneeId) : void 0) ?? (task.approval ? agents.get(task.approval.askedById) : void 0);
14628
+ }
14629
+ function agentsView(data, me, now, filter = {}) {
14630
+ const agents = data.people.filter(isAgent);
14631
+ const byAgent = new Map(agents.map((a) => [a.id, a]));
14632
+ const view = {
14633
+ agents,
14634
+ needsYou: [],
14635
+ withOthers: [],
14636
+ working: [],
14637
+ sentBack: [],
14638
+ doneToday: []
14639
+ };
14640
+ if (agents.length === 0) return view;
14641
+ const latest = /* @__PURE__ */ new Map();
14642
+ for (const c of data.comments) {
14643
+ if (!byAgent.has(c.authorId)) continue;
14644
+ const key = `${c.taskId} ${c.authorId}`;
14645
+ const had = latest.get(key);
14646
+ if (!had || had.createdAt < c.createdAt) latest.set(key, c);
14647
+ }
14648
+ const today = todayISO(now);
14649
+ for (const task of data.tasks) {
14650
+ const agent = agentOf(task, byAgent);
14651
+ if (!agent) continue;
14652
+ if (filter.agent && agent.id !== filter.agent) continue;
14653
+ if (filter.project && task.projectId !== filter.project) continue;
14654
+ const note = latest.get(`${task.id} ${agent.id}`) ?? null;
14655
+ const done = task.status === "done";
14656
+ const row = {
14657
+ task,
14658
+ agent,
14659
+ note,
14660
+ late: !done && !!task.dueDate && task.dueDate < today
14661
+ };
14662
+ const a = task.approval;
14663
+ if (done) {
14664
+ if (a?.status === "approved" && a.decidedAt && localDay(a.decidedAt) === today) view.doneToday.push(row);
14665
+ } else if (task.status === "review" && a?.status === "pending") (a.approverId === me ? view.needsYou : view.withOthers).push(row);
14666
+ else if (sentBack(task) && task.assigneeId === agent.id && task.status !== "doing") {
14667
+ const since = a?.decidedAt ?? "";
14668
+ if (!note || note.createdAt <= since) view.sentBack.push(row);
14669
+ } else if (task.status === "doing" && task.assigneeId === agent.id) view.working.push(row);
14670
+ }
14671
+ const asked = (r) => r.task.approval?.askedAt ?? "";
14672
+ const decided = (r) => r.task.approval?.decidedAt ?? "";
14673
+ view.needsYou.sort((x, y) => asked(x).localeCompare(asked(y)));
14674
+ view.withOthers.sort((x, y) => asked(x).localeCompare(asked(y)));
14675
+ view.sentBack.sort((x, y) => decided(x).localeCompare(decided(y)));
14676
+ view.doneToday.sort((x, y) => decided(y).localeCompare(decided(x)));
14677
+ view.working.sort((x, y) => Number(y.late) - Number(x.late) || (x.note?.createdAt ?? "").localeCompare(y.note?.createdAt ?? ""));
14678
+ return view;
14679
+ }
14680
+ /** A comment's body as one short line for a row. */
14681
+ function noteLine(body, max = 140) {
14682
+ const line = body.replace(/\s+/g, " ").trim();
14683
+ return line.length > max ? `${line.slice(0, max - 1).trimEnd()}…` : line;
14684
+ }
14685
+
14686
+ // src/lib/task-approval.ts
14687
+ /** Waits on its approver now: asked, not yet answered, and not done. */
14688
+ function awaitingApproval(task) {
14689
+ return Boolean(task?.approval && task.approval.status === "pending" && task.status !== "done");
14690
+ }
14691
+ /** The patch that asks `approverId` to approve the task (again, after changes). */
14692
+ function askApprovalPatch(task, approverId, opts) {
14693
+ if (task.status === "done") throw new ApprovalError("It's already done.");
14694
+ if (approverId === opts.by) throw new ApprovalError("Ask someone else. Your own approval is just finishing it.");
14695
+ return { approval: {
14696
+ approverId,
14697
+ askedById: opts.by,
14698
+ askedAt: opts.at,
14699
+ status: "pending",
14700
+ note: null,
14701
+ decidedAt: null
14702
+ } };
14703
+ }
14704
+ /**
14705
+ * The approver's answer as a patch: approving finishes the task; asking for
14706
+ * changes needs a note saying what, and leaves the task open.
14707
+ */
14708
+ function decideApprovalPatch(task, decision, opts) {
14709
+ const a = task.approval;
14710
+ if (!a) throw new ApprovalError("Nobody asked for approval on this task.");
14711
+ if (a.approverId !== opts.by) throw new ApprovalError("Only the person asked can approve it.");
14712
+ const note = (opts.note ?? "").replace(/\s+/g, " ").trim().slice(0, 500);
14713
+ if (decision === "changes" && !note) throw new ApprovalError("Say what should change.");
14714
+ const approval = {
14715
+ ...a,
14716
+ status: decision === "approve" ? "approved" : "changes_requested",
14717
+ note: note || null,
14718
+ decidedAt: opts.at
14719
+ };
14720
+ if (decision === "approve") return task.status !== "done" ? {
14721
+ approval,
14722
+ status: "done"
14723
+ } : { approval };
14724
+ return opts.askerIsAgent && task.status === "review" ? {
14725
+ approval,
14726
+ status: "todo"
14727
+ } : { approval };
14728
+ }
14729
+ /** Open tasks waiting on this person's approval, oldest ask first. */
14730
+ function approvalsWaitingOn(tasks, personId) {
14731
+ return tasks.filter((t) => awaitingApproval(t) && t.approval.approverId === personId).sort((a, b) => a.approval.askedAt.localeCompare(b.approval.askedAt));
14732
+ }
14733
+ var APPROVAL_NOTE_MAX, ApprovalError;
14734
+ var init_task_approval = __esmMin((() => {
14735
+ APPROVAL_NOTE_MAX = 500;
14736
+ ApprovalError = class extends Error {};
14737
+ }));
14738
+
14739
+ // src/tui/views/agents.tsx
14740
+ init_date_text();
14741
+ init_indexes();
14742
+ init_task_approval();
14743
+ init_task_keys();
14744
+ const TITLE = {
14745
+ needsYou: "For you to check",
14746
+ withOthers: "With someone else",
14747
+ working: "In play",
14748
+ sentBack: "Sent back, not picked up",
14749
+ doneToday: "Approved today"
14750
+ };
14751
+ const ORDER = [
14752
+ "needsYou",
14753
+ "withOthers",
14754
+ "working",
14755
+ "sentBack",
14756
+ "doneToday"
14757
+ ];
14758
+ /**
14759
+ * The website's Agents page in the terminal (lib/agents-page.ts): every
14760
+ * agent's work across the harbor. a approves the work picked for you to
14761
+ * check, s sends it back with a one-line note, Enter opens the task.
14762
+ */
14763
+ function AgentsView({ active, width, height, go }) {
14764
+ const { store } = useDeps();
14765
+ const people = useHarbor((s) => s.people);
14766
+ const tasks = useHarbor((s) => s.tasks);
14767
+ const comments = useHarbor((s) => s.comments);
14768
+ const projects = useHarbor((s) => s.projects);
14769
+ const me = useHarbor((s) => s.currentUserId);
14770
+ const view = useMemo(() => agentsView({
14771
+ people,
14772
+ tasks,
14773
+ comments
14774
+ }, me, /* @__PURE__ */ new Date()), [
14775
+ people,
14776
+ tasks,
14777
+ comments,
14778
+ me
14779
+ ]);
14780
+ const lines = useMemo(() => {
14781
+ const out = [];
14782
+ for (const kind of ORDER) {
14783
+ const rows = view[kind];
14784
+ if (!rows.length) continue;
14785
+ out.push({
14786
+ kind: "head",
14787
+ title: TITLE[kind],
14788
+ n: rows.length
14789
+ });
14790
+ for (const row of rows) out.push({
14791
+ kind: "row",
14792
+ of: kind,
14793
+ row
14794
+ });
14795
+ }
14796
+ return out;
14797
+ }, [view]);
14798
+ const rows = lines.filter((l) => l.kind === "row");
14799
+ const [at, setAt] = useState(0);
14800
+ const picked = rows[Math.min(at, rows.length - 1)];
14801
+ const projectsById = byId(projects);
14802
+ const decide = (row, decision, note = "") => {
14803
+ try {
14804
+ const patch = decideApprovalPatch(row.task, decision, {
14805
+ by: me,
14806
+ at: (/* @__PURE__ */ new Date()).toISOString(),
14807
+ note,
14808
+ askerIsAgent: true
14809
+ });
14810
+ store.getState().updateTask(row.task.id, patch, { allowOverCap: true });
14811
+ go.notify(decision === "approve" ? `Approved “${row.task.title}”, and finished it.` : `Sent “${row.task.title}” back to ${row.agent.name} with your note.`);
14812
+ } catch (e) {
14813
+ if (!(e instanceof ApprovalError)) throw e;
14814
+ go.notify(e.message);
14815
+ }
14816
+ };
14817
+ useInput((input, key) => {
14818
+ if (key.upArrow || input === "k") setAt((i) => step$1(i, -1, rows.length));
14819
+ else if (key.downArrow || input === "j") setAt((i) => step$1(i, 1, rows.length));
14820
+ else if (key.return && picked) go.openTask(picked.row.task.id);
14821
+ else if ((input === "a" || input === "s") && picked) {
14822
+ if (picked.of !== "needsYou") return go.notify("Only work handed in for you to check can be approved or sent back.");
14823
+ if (input === "a") decide(picked.row, "approve");
14824
+ else go.ask("What should change?", (text) => {
14825
+ if (text.trim()) decide(picked.row, "changes", text);
14826
+ });
14827
+ }
14828
+ }, { isActive: active });
14829
+ if (view.agents.length === 0) return /* @__PURE__ */ jsxs(Box, {
14830
+ flexDirection: "column",
14831
+ width,
14832
+ height,
14833
+ paddingX: 1,
14834
+ children: [/* @__PURE__ */ jsx(Heading, { children: "Agents" }), /* @__PURE__ */ jsx(Text, {
14835
+ color: theme.muted,
14836
+ wrap: "wrap",
14837
+ children: "No agents on the crew yet. Add one on the website's People page (Add an agent), then connect Claude or Claude Code to it. Its work shows here for you to approve."
14838
+ })]
14839
+ });
14840
+ const selectedLine = picked ? lines.indexOf(picked) : 0;
14841
+ const shown = windowOf(lines, selectedLine, Math.max(1, height - 2));
14842
+ return /* @__PURE__ */ jsxs(Box, {
14843
+ flexDirection: "column",
14844
+ width,
14845
+ height,
14846
+ paddingX: 1,
14847
+ children: [
14848
+ /* @__PURE__ */ jsx(Heading, {
14849
+ right: `${view.needsYou.length} for you · ${view.working.length} in play · a approves · s sends back`,
14850
+ children: "Agents"
14851
+ }),
14852
+ lines.length === 0 ? /* @__PURE__ */ jsx(Text, {
14853
+ color: theme.muted,
14854
+ children: "Nothing from the agents right now."
14855
+ }) : null,
14856
+ shown.items.map((line, i) => {
14857
+ if (line.kind === "head") return /* @__PURE__ */ jsxs(Text, {
14858
+ bold: true,
14859
+ children: [
14860
+ i > 0 ? "\n" : "",
14861
+ line.title,
14862
+ " ",
14863
+ /* @__PURE__ */ jsx(Text, {
14864
+ color: theme.muted,
14865
+ children: line.n
14866
+ })
14867
+ ]
14868
+ }, `h-${line.title}`);
14869
+ const { task, agent, note, late } = line.row;
14870
+ const on = active && line === picked;
14871
+ const key = taskKey(task, projectsById.get(task.projectId));
14872
+ const said = line.of === "sentBack" ? task.approval?.note : line.of === "doneToday" ? null : note?.body;
14873
+ const when = line.of === "needsYou" || line.of === "withOthers" ? task.approval?.askedAt : line.of === "working" ? note?.createdAt : task.approval?.decidedAt;
14874
+ return /* @__PURE__ */ jsxs(Text, {
14875
+ color: on ? theme.selected : void 0,
14876
+ bold: on,
14877
+ wrap: "truncate-end",
14878
+ children: [
14879
+ on ? "› " : " ",
14880
+ key ? /* @__PURE__ */ jsx(Text, {
14881
+ color: theme.muted,
14882
+ children: key.padEnd(8)
14883
+ }) : null,
14884
+ task.title,
14885
+ /* @__PURE__ */ jsxs(Text, {
14886
+ color: theme.muted,
14887
+ children: [
14888
+ ` · ${agent.name}`,
14889
+ late ? /* @__PURE__ */ jsx(Text, {
14890
+ color: theme.coral,
14891
+ children: " · late"
14892
+ }) : null,
14893
+ when ? ` · ${timeAgo(parseIso(when))}` : "",
14894
+ said ? ` · “${noteLine(said, 80)}”` : ""
14895
+ ]
14896
+ })
14897
+ ]
14898
+ }, task.id);
14899
+ })
14900
+ ]
14901
+ });
14902
+ }
14903
+
14416
14904
  // src/lib/load.ts
14417
14905
  /** Open tasks for one person, bucketed by the week they are due, plus what is already late or has no date. */
14418
14906
  function weeklyLoad(tasks, personId, now, weeks = 6, calendar) {
@@ -14711,7 +15199,7 @@ init_handover();
14711
15199
  const SOON_DAYS = 21;
14712
15200
  /** This many open tasks in one project that only one person has touched read as their corner of it. */
14713
15201
  const CLUSTER = 4;
14714
- const isoDay$1 = (d) => d.toISOString().slice(0, 10);
15202
+ const isoDay$1 = (d) => format(d, "yyyy-MM-dd");
14715
15203
  const md = (iso) => format(parseIso(iso), "MMM d");
14716
15204
  /** Everyone a task has passed through. */
14717
15205
  function taskHands(task, commentsBy, attachedBy) {
@@ -17227,7 +17715,7 @@ function HarborSwitch({ harbors, current, width, onPick, onClose }) {
17227
17715
  const HELP$1 = [
17228
17716
  ["0–9 / Tab", "the screens / between the sidebar and a screen"],
17229
17717
  [":", "anything: a screen, something new, a name"],
17230
- ["/ H C G O", "find a task / harbor / crew / goals / reports"],
17718
+ ["/ H C G O I", "find a task / harbor / crew / goals / reports / agents"],
17231
17719
  ["↑↓ or j k", "move; ←→ or h l across columns and lists"],
17232
17720
  ["Enter / Esc", "open / back"],
17233
17721
  ["n", "new: a task, or what the screen lists"],
@@ -17596,6 +18084,7 @@ init_format();
17596
18084
  const PAGES = {
17597
18085
  today: "/today",
17598
18086
  inbox: "/inbox",
18087
+ agents: "/agents",
17599
18088
  chat: "/chat",
17600
18089
  week: "/week",
17601
18090
  brief: "/brief",
@@ -24500,7 +24989,7 @@ init_format();
24500
24989
  init_indexes();
24501
24990
  const noon$1 = (iso) => /* @__PURE__ */ new Date(`${iso.slice(0, 10)}T12:00:00`);
24502
24991
  const days$2 = (from, to) => differenceInCalendarDays(noon$1(to), noon$1(from));
24503
- const later = (a, b) => !a ? b : !b ? a : a >= b ? a : b;
24992
+ const later$1 = (a, b) => !a ? b : !b ? a : a >= b ? a : b;
24504
24993
  const open = (t) => t.status !== "done";
24505
24994
  /** True when `a` finishes later than `b`, or as late behind a longer line. */
24506
24995
  const beats = (a, b) => !b || a.finish > b.finish || a.finish === b.finish && a.depth > b.depth;
@@ -24523,10 +25012,10 @@ function finishes(all, today) {
24523
25012
  const w = walk(b);
24524
25013
  if (w.finish && beats(w, behind)) behind = w;
24525
25014
  }
24526
- const own = t.dueDate ? later(t.dueDate.slice(0, 10), today) : null;
25015
+ const own = t.dueDate ? later$1(t.dueDate.slice(0, 10), today) : null;
24527
25016
  onPath.delete(t.id);
24528
25017
  const out = {
24529
- finish: later(own, behind?.finish ?? null),
25018
+ finish: later$1(own, behind?.finish ?? null),
24530
25019
  depth: (behind?.depth ?? 0) + 1
24531
25020
  };
24532
25021
  memo.set(t.id, out);
@@ -24647,7 +25136,7 @@ function milestonePole(milestone, data, now) {
24647
25136
  return [{
24648
25137
  project,
24649
25138
  pole,
24650
- finish: pole.kind === "chain" ? later(pole.finish, end) ?? end : end
25139
+ finish: pole.kind === "chain" ? later$1(pole.finish, end) ?? end : end
24651
25140
  }];
24652
25141
  });
24653
25142
  if (runs.length === 0) return {
@@ -24981,7 +25470,7 @@ const SIMILAR_MIN = 3;
24981
25470
  /** A finished task that took longer than this sat somewhere; it counts as this long. */
24982
25471
  const SIMILAR_CAP = 15;
24983
25472
  const firstName$1 = (name) => name.trim().split(/\s+/)[0] || name;
24984
- const day$1 = (iso) => iso ? iso.slice(0, 10) : null;
25473
+ const day$2 = (iso) => iso ? iso.slice(0, 10) : null;
24985
25474
  function quantile(sorted, q) {
24986
25475
  const at = (sorted.length - 1) * q;
24987
25476
  const lo = Math.floor(at);
@@ -24997,7 +25486,7 @@ function pilotDate(task, data, localToday, at) {
24997
25486
  const owner = byId(data.people).get(task.assigneeId);
24998
25487
  if (!owner || owner.kind === "agent") return null;
24999
25488
  const today = at ? todayFor(owner, at, localToday) : localToday;
25000
- const chosen = day$1(task.dueDate);
25489
+ const chosen = day$2(task.dueDate);
25001
25490
  let underWay = 0;
25002
25491
  const dated = [];
25003
25492
  const finished = [];
@@ -25007,14 +25496,14 @@ function pilotDate(task, data, localToday, at) {
25007
25496
  if (t.projectId === task.projectId && t.completedAt) finished.push(t);
25008
25497
  continue;
25009
25498
  }
25010
- const due = day$1(t.dueDate);
25499
+ const due = day$2(t.dueDate);
25011
25500
  if (t.status === "doing" || t.status === "review") underWay += 1;
25012
25501
  else if (due) dated.push(due);
25013
25502
  }
25014
25503
  const perDay = Math.max(.2, (owner.weeklyCapacity ?? 5) / 5);
25015
25504
  let similar = null;
25016
25505
  if (finished.length >= SIMILAR_MIN) {
25017
- const took = finished.sort((a, b) => b.completedAt < a.completedAt ? -1 : 1).slice(0, SIMILAR).map((t) => Math.min(SIMILAR_CAP, Math.max(1, workingDaysBetween(day$1(t.createdAt), day$1(t.completedAt))))).sort((a, b) => a - b);
25506
+ const took = finished.sort((a, b) => b.completedAt < a.completedAt ? -1 : 1).slice(0, SIMILAR).map((t) => Math.min(SIMILAR_CAP, Math.max(1, workingDaysBetween(day$2(t.createdAt), day$2(t.completedAt))))).sort((a, b) => a - b);
25018
25507
  similar = {
25019
25508
  low: Math.round(quantile(took, .25)),
25020
25509
  high: Math.round(quantile(took, .75)),
@@ -25022,7 +25511,7 @@ function pilotDate(task, data, localToday, at) {
25022
25511
  };
25023
25512
  }
25024
25513
  const ownDays = Math.min(5, Math.max(1, similar?.low ?? 1));
25025
- const backOn = isAway(owner, today) ? day$1(owner.away.until) : null;
25514
+ const backOn = isAway(owner, today) ? day$2(owner.away.until) : null;
25026
25515
  const start = backOn && backOn > today ? dayBefore(backOn) : today;
25027
25516
  const tasks = byId(data.tasks);
25028
25517
  const projects = byId(data.projects);
@@ -25033,7 +25522,7 @@ function pilotDate(task, data, localToday, at) {
25033
25522
  for (const id of blockers) {
25034
25523
  const b = tasks.get(id);
25035
25524
  if (!b || b.status === "done") continue;
25036
- const due = day$1(b.dueDate);
25525
+ const due = day$2(b.dueDate);
25037
25526
  if (!due) {
25038
25527
  undated ??= b;
25039
25528
  continue;
@@ -25102,7 +25591,7 @@ const plural$3 = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
25102
25591
  /** The line under the date: "Dana's queue says Nov 12 at the earliest", or, with no date yet, "Dana could likely have this by Nov 12". */
25103
25592
  function pilotHeadline(p, chosen, you = false) {
25104
25593
  const who = you ? "You" : firstName$1(p.owner.name);
25105
- if (!day$1(chosen)) return `${who} could likely have this by ${shortDate(p.earliest)}`;
25594
+ if (!day$2(chosen)) return `${who} could likely have this by ${shortDate(p.earliest)}`;
25106
25595
  return `${you ? "Your" : `${who}'s`} queue says ${shortDate(p.earliest)} at the earliest`;
25107
25596
  }
25108
25597
  /** Why: the queue, time away, what it waits on, and how long similar tasks took. */
@@ -25174,7 +25663,7 @@ function lastLooked(mark, data, personId) {
25174
25663
  init_date_text();
25175
25664
  init_indexes();
25176
25665
  init_task_keys();
25177
- const day = (iso) => parseIso(iso.slice(0, 10));
25666
+ const day$1 = (iso) => parseIso(iso.slice(0, 10));
25178
25667
  const daysBetween = dayGap;
25179
25668
  /** Their projects: ones they lead, in a program they lead, or with a task of theirs. */
25180
25669
  function projectsOf(data, personId) {
@@ -25189,10 +25678,11 @@ function dueText(task, today) {
25189
25678
  if (d === 0) return "due today";
25190
25679
  if (d < 0) return `${-d} day${d === -1 ? "" : "s"} late`;
25191
25680
  if (d === 1) return "due tomorrow";
25192
- return `due ${format(day(task.dueDate), "EEE, MMM d")}`;
25681
+ return `due ${format(day$1(task.dueDate), "EEE, MMM d")}`;
25193
25682
  }
25194
25683
  /** What a person needs to hear about since `when.since`, as of `today` (YYYY-MM-DD). */
25195
- function welcomeBack(data, personId, when, today) {
25684
+ function welcomeBack(data, personId, when, today, shown = []) {
25685
+ const below = new Set(shown);
25196
25686
  const since = when.since;
25197
25687
  const people = byId(data.people);
25198
25688
  const projects = projectsOf(data, personId);
@@ -25233,12 +25723,27 @@ function welcomeBack(data, personId, when, today) {
25233
25723
  }
25234
25724
  moved.sort((a, b) => Number(Boolean(b.health)) - Number(Boolean(a.health)) || b.done - a.done);
25235
25725
  const look = [];
25726
+ const more = [];
25236
25727
  const seen = /* @__PURE__ */ new Set();
25728
+ const skipped = {
25729
+ late: 0,
25730
+ due: 0
25731
+ };
25237
25732
  const push = (item) => {
25238
25733
  const id = item.taskId ?? item.raidId ?? item.text;
25239
- if (look.length >= 3 || seen.has(id)) return;
25240
- seen.add(id);
25241
- look.push(item);
25734
+ if (seen.has(id)) return;
25735
+ if (item.taskId && below.has(item.taskId) && (item.kind === "late" || item.kind === "due")) {
25736
+ seen.add(id);
25737
+ skipped[item.kind] += 1;
25738
+ return;
25739
+ }
25740
+ if (look.length < 3) {
25741
+ seen.add(id);
25742
+ look.push(item);
25743
+ } else if (item.kind !== "decision") {
25744
+ seen.add(id);
25745
+ more.push(item);
25746
+ }
25242
25747
  };
25243
25748
  for (const h of handed) {
25244
25749
  const by = first(h.by);
@@ -25276,13 +25781,32 @@ function welcomeBack(data, personId, when, today) {
25276
25781
  decisions,
25277
25782
  moved: moved.slice(0, 6),
25278
25783
  lookFirst: look,
25784
+ moreLook: more,
25785
+ skipped,
25279
25786
  quiet: !handed.length && !decisions.length && !moved.length && !look.length
25280
25787
  };
25281
25788
  }
25789
+ const MORE_WORDS = {
25790
+ handed: "handed to you",
25791
+ late: "late",
25792
+ due: "due soon",
25793
+ decision: "decided"
25794
+ };
25795
+ /** "4 more late", "5 more: 3 late, 2 due soon"; null when nothing more. */
25796
+ function moreText(more) {
25797
+ if (!more.length) return null;
25798
+ const counts = /* @__PURE__ */ new Map();
25799
+ for (const m of more) {
25800
+ const word = MORE_WORDS[m.kind];
25801
+ counts.set(word, (counts.get(word) ?? 0) + 1);
25802
+ }
25803
+ if (counts.size === 1) return `${more.length} more ${[...counts.keys()][0]}`;
25804
+ return `${more.length} more: ${[...counts].map(([w, n]) => `${n} ${w}`).join(", ")}`;
25805
+ }
25282
25806
  /** "Welcome back, Priya · away Oct 3 to Oct 17", or "· 5 days since you last looked". */
25283
25807
  function welcomeTitle(w, name, today) {
25284
25808
  const hi = name ? `Welcome back, ${name}` : "Welcome back";
25285
- if (w.when.why === "away") return `${hi} · away ${format(day(w.when.since), "MMM d")} to ${format(day(today), "MMM d")}`;
25809
+ if (w.when.why === "away") return `${hi} · away ${format(day$1(w.when.since), "MMM d")} to ${format(day$1(today), "MMM d")}`;
25286
25810
  return `${hi} · ${w.when.days} days since you last looked`;
25287
25811
  }
25288
25812
  /** "Checkout v3: 4 done, 2 added, now At risk (was On track)". */
@@ -25295,32 +25819,6 @@ function movedText(m, healthLabel) {
25295
25819
  return `${m.project.name}: ${bits.join(", ")}`;
25296
25820
  }
25297
25821
 
25298
- // src/lib/agents.ts
25299
- init_agent_check();
25300
- const RANK$1 = {
25301
- urgent: 0,
25302
- high: 1,
25303
- medium: 2,
25304
- low: 3
25305
- };
25306
- /** Sent back by the person who checked it, with a note saying what to change. */
25307
- const sentBack = (t) => t.approval?.status === "changes_requested" && t.status !== "done" && t.status !== "review";
25308
- /** What an agent should work on: its open tasks not yet waiting on review, what was sent back first, then in progress, then most urgent and soonest. */
25309
- function agentQueue(data, agentId) {
25310
- return data.tasks.filter((t) => t.assigneeId === agentId && (t.status === "todo" || t.status === "doing" || t.status === "backlog")).sort((a, b) => Number(sentBack(b)) - Number(sentBack(a)) || Number(b.status === "doing") - Number(a.status === "doing") || Number(a.status === "backlog") - Number(b.status === "backlog") || RANK$1[a.priority] - RANK$1[b.priority] || (a.dueDate ?? "9999").localeCompare(b.dueDate ?? "9999"));
25311
- }
25312
- /** The agent an app means: the one named, else the only one on the crew. */
25313
- function pickAgent(people, key) {
25314
- const agents = people.filter(isAgent);
25315
- if (agents.length === 0) return "There are no agents on this harbor's crew yet. Someone adds one on People with Add an agent.";
25316
- if (!key) {
25317
- if (agents.length === 1) return agents[0];
25318
- return `This harbor has ${agents.length} agents (${agents.map((a) => a.name).join(", ")}). Say which with agent.`;
25319
- }
25320
- const k = key.trim().toLowerCase();
25321
- return agents.find((a) => a.id === key.trim() || a.name.trim().toLowerCase() === k) ?? `No agent called "${key}". The crew's agents: ${agents.map((a) => a.name).join(", ")}.`;
25322
- }
25323
-
25324
25822
  // src/lib/fog.ts
25325
25823
  function latestBy(cache, items, key, at) {
25326
25824
  const hit = cache.get(items);
@@ -25780,33 +26278,346 @@ function gapText(gap) {
25780
26278
  return `${called}; the numbers have said ${WORD[gap.rules]} for the last ${weeksText(gap.days)}.`;
25781
26279
  }
25782
26280
 
25783
- // src/lib/task-approval.ts
25784
- /** Waits on its approver now: asked, not yet answered, and not done. */
25785
- function awaitingApproval(task) {
25786
- return Boolean(task?.approval && task.approval.status === "pending" && task.status !== "done");
26281
+ // src/lib/wbs-move.ts
26282
+ var wbs_move_exports = /* @__PURE__ */ __exportAll({
26283
+ applyMove: () => applyMove,
26284
+ moveProblem: () => moveProblem,
26285
+ orderPlans: () => orderPlans,
26286
+ orderTasks: () => orderTasks
26287
+ });
26288
+ /** Ranked first, in rank order; the rest after, as `fallback` orders them (stable). */
26289
+ function byRank(list, fallback) {
26290
+ const at = new Map(list.map((x, i) => [x.id, i]));
26291
+ return [...list].sort((a, b) => {
26292
+ const ra = a.wbsRank ?? Infinity;
26293
+ const rb = b.wbsRank ?? Infinity;
26294
+ if (ra !== rb) return ra - rb;
26295
+ if (fallback) {
26296
+ const f = fallback(a, b);
26297
+ if (f) return f;
26298
+ }
26299
+ return at.get(a.id) - at.get(b.id);
26300
+ });
26301
+ }
26302
+ /** The task a link really points at as its parent (subtasks.ts's rule, without the import). */
26303
+ function realParent(t, index) {
26304
+ const p = t.parentTaskId ? index.get(t.parentTaskId) : void 0;
26305
+ if (!p || p.id === t.id || p.projectId !== t.projectId || p.parentTaskId) return null;
26306
+ return p;
25787
26307
  }
25788
- /** The patch that asks `approverId` to approve the task (again, after changes). */
25789
- function askApprovalPatch(task, approverId, opts) {
25790
- if (task.status === "done") throw new ApprovalError("It's already done.");
25791
- if (approverId === opts.by) throw new ApprovalError("Ask someone else. Your own approval is just finishing it.");
25792
- return { approval: {
25793
- approverId,
25794
- askedById: opts.by,
25795
- askedAt: opts.at,
25796
- status: "pending",
25797
- note: null,
25798
- decidedAt: null
25799
- } };
26308
+ /** The subtasks under `parent`, in list order. */
26309
+ function subsOf(parent, tasks, index) {
26310
+ if (realParent(parent, index)) return [];
26311
+ return (childrenByParent(tasks).get(parent.id) ?? []).filter((t) => t.projectId === parent.projectId && t.id !== parent.id);
25800
26312
  }
25801
- /** Open tasks waiting on this person's approval, oldest ask first. */
25802
- function approvalsWaitingOn(tasks, personId) {
25803
- return tasks.filter((t) => awaitingApproval(t) && t.approval.approverId === personId).sort((a, b) => a.approval.askedAt.localeCompare(b.approval.askedAt));
26313
+ /** The tasks that stand on their own in a project. */
26314
+ function topOf(projectId, tasks, index) {
26315
+ return tasksOf(tasks, projectId).filter((t) => !realParent(t, index));
25804
26316
  }
25805
- var ApprovalError;
25806
- var init_task_approval = __esmMin((() => {
25807
- ApprovalError = class extends Error {};
26317
+ /** Why this move can't be made, in a sentence; null when it can. */
26318
+ function moveProblem(doc, move) {
26319
+ if (move.kind === "program") {
26320
+ if (!doc.programs.some((p) => p.id === move.id)) return "That program isn't here any more.";
26321
+ return null;
26322
+ }
26323
+ if (move.kind === "project") {
26324
+ if (!doc.projects.some((p) => p.id === move.id)) return "That project isn't here any more.";
26325
+ if (!doc.programs.some((p) => p.id === move.into)) return "That program isn't here any more.";
26326
+ return null;
26327
+ }
26328
+ const index = byId(doc.tasks);
26329
+ const task = index.get(move.id);
26330
+ if (!task) return "That task isn't here any more.";
26331
+ const parent = move.into.kind === "task" ? index.get(move.into.id) : void 0;
26332
+ if (move.into.kind === "task" && !parent) return "That task isn't here any more.";
26333
+ const projectId = parent ? parent.projectId : move.into.id;
26334
+ if (!doc.projects.some((p) => p.id === projectId)) return "That project isn't here any more.";
26335
+ const locked = lockedFields(task);
26336
+ if (projectId !== task.projectId && locked.includes("projectId")) return "This task is kept in step from another tool, so it stays in its project.";
26337
+ const parentNow = realParent(task, index)?.id ?? null;
26338
+ if ((parent?.id ?? null) !== parentNow && locked.includes("parentTaskId")) return "This task is kept in step from Jira, which says what it sits under.";
26339
+ if (!parent) return null;
26340
+ if (parent.id === task.id) return "A task can't go inside itself.";
26341
+ if (realParent(parent, index)) return "That task is already a subtask; subtasks go one level deep.";
26342
+ if (subsOf(task, doc.tasks, index).length > 0) return "This task has subtasks of its own, so it can't go inside another.";
26343
+ if (subsOf(parent, doc.tasks, index).filter((t) => t.id !== task.id).length >= 50) return `A task can hold up to ${50} subtasks.`;
26344
+ return null;
26345
+ }
26346
+ /** `list` with `item` put before `before` (or last), each given its place as its rank. */
26347
+ function ranked(list, item, before) {
26348
+ const rest = list.filter((x) => x.id !== item.id);
26349
+ const at = before ? rest.findIndex((x) => x.id === before) : -1;
26350
+ rest.splice(at < 0 ? rest.length : at, 0, item);
26351
+ return new Map(rest.map((x, i) => [x.id, i + 1]));
26352
+ }
26353
+ /**
26354
+ * The rows the move changes, or null when it changes nothing (or can't be
26355
+ * made: ask `moveProblem` for why). A task moved to another project takes its
26356
+ * subtasks with it, as moving it from its drawer does; one kept in step from
26357
+ * another tool can't leave, so it stands alone where it was.
26358
+ */
26359
+ function applyMove(doc, move, now) {
26360
+ if (moveProblem(doc, move)) return null;
26361
+ if (move.kind === "program") {
26362
+ const program = doc.programs.find((p) => p.id === move.id);
26363
+ const ranks = ranked(orderPlans(doc.programs.filter((p) => p.portfolioId === move.into)), program, move.before);
26364
+ let changed = false;
26365
+ const programs = doc.programs.map((p) => {
26366
+ const rank = ranks.get(p.id);
26367
+ if (rank === void 0) return p;
26368
+ const portfolioId = p.id === program.id ? move.into : p.portfolioId;
26369
+ if (p.wbsRank === rank && p.portfolioId === portfolioId) return p;
26370
+ changed = true;
26371
+ return {
26372
+ ...p,
26373
+ wbsRank: rank,
26374
+ portfolioId
26375
+ };
26376
+ });
26377
+ return changed ? { programs } : null;
26378
+ }
26379
+ if (move.kind === "project") {
26380
+ const project = doc.projects.find((p) => p.id === move.id);
26381
+ const ranks = ranked(orderPlans(doc.projects.filter((p) => p.programId === move.into)), project, move.before);
26382
+ let changed = false;
26383
+ const projects = doc.projects.map((p) => {
26384
+ const rank = ranks.get(p.id);
26385
+ if (rank === void 0) return p;
26386
+ const programId = p.id === project.id ? move.into : p.programId;
26387
+ if (p.wbsRank === rank && p.programId === programId) return p;
26388
+ changed = true;
26389
+ return {
26390
+ ...p,
26391
+ wbsRank: rank,
26392
+ programId
26393
+ };
26394
+ });
26395
+ return changed ? { projects } : null;
26396
+ }
26397
+ const index = byId(doc.tasks);
26398
+ const task = index.get(move.id);
26399
+ const parent = move.into.kind === "task" ? index.get(move.into.id) : null;
26400
+ const projectId = parent ? parent.projectId : move.into.id;
26401
+ const parentTaskId = parent?.id ?? null;
26402
+ const ranks = ranked(parent ? orderTasks(subsOf(parent, doc.tasks, index)) : orderTasks(topOf(projectId, doc.tasks, index)), task, move.before);
26403
+ const under = projectId !== task.projectId ? subsOf(task, doc.tasks, index) : [];
26404
+ const carried = new Set(under.filter((t) => !lockedFields(t).includes("projectId")).map((t) => t.id));
26405
+ const leftBehind = new Set(under.filter((t) => !carried.has(t.id)).map((t) => t.id));
26406
+ let changed = false;
26407
+ const tasks = doc.tasks.map((t) => {
26408
+ if (t.id === task.id) {
26409
+ const rank = ranks.get(t.id);
26410
+ const parentNow = realParent(t, index)?.id ?? null;
26411
+ if (t.projectId === projectId && parentNow === parentTaskId && t.wbsRank === rank) return t;
26412
+ changed = true;
26413
+ return {
26414
+ ...t,
26415
+ projectId,
26416
+ parentTaskId,
26417
+ wbsRank: rank,
26418
+ touchedAt: now
26419
+ };
26420
+ }
26421
+ if (carried.has(t.id)) {
26422
+ changed = true;
26423
+ return {
26424
+ ...t,
26425
+ projectId,
26426
+ touchedAt: now
26427
+ };
26428
+ }
26429
+ if (leftBehind.has(t.id)) {
26430
+ changed = true;
26431
+ return {
26432
+ ...t,
26433
+ parentTaskId: null
26434
+ };
26435
+ }
26436
+ const rank = ranks.get(t.id);
26437
+ if (rank === void 0 || t.wbsRank === rank) return t;
26438
+ changed = true;
26439
+ return {
26440
+ ...t,
26441
+ wbsRank: rank
26442
+ };
26443
+ });
26444
+ return changed ? { tasks } : null;
26445
+ }
26446
+ var byStart, orderTasks, orderPlans;
26447
+ var init_wbs_move = __esmMin((() => {
26448
+ init_indexes();
26449
+ init_rollup_lock();
26450
+ init_subtasks();
26451
+ byStart = (a, b) => (a.startDate || "").localeCompare(b.startDate || "") || a.name.localeCompare(b.name);
26452
+ orderTasks = (list) => byRank(list);
26453
+ orderPlans = (list) => byRank(list, byStart);
25808
26454
  }));
25809
26455
 
26456
+ // src/lib/wbs.ts
26457
+ init_indexes();
26458
+ init_rollup_lock();
26459
+ init_task_keys();
26460
+ init_wbs_move();
26461
+ const day = (iso) => iso ? iso.slice(0, 10) : null;
26462
+ const earlier = (a, b) => !a ? b : !b ? a : a < b ? a : b;
26463
+ const later = (a, b) => !a ? b : !b ? a : a > b ? a : b;
26464
+ function lockOf(t) {
26465
+ const locked = lockedFields(t);
26466
+ if (!locked.includes("projectId")) return void 0;
26467
+ return locked.includes("parentTaskId") ? "all" : "project";
26468
+ }
26469
+ function taskNode(t, kind, code, level, project, subs, today) {
26470
+ const lateOf = (x) => x.status !== "done" && x.dueDate && day(x.dueDate) < today ? 1 : 0;
26471
+ const children = orderTasks(subs).map((s, i) => taskNode(s, "subtask", `${code}.${i + 1}`, level + 1, project, [], today));
26472
+ let start = day(t.startDate);
26473
+ let end = day(t.dueDate);
26474
+ if (children.length) {
26475
+ start = earlier(start, end);
26476
+ for (const c of children) {
26477
+ start = earlier(earlier(start, c.start), c.end);
26478
+ end = later(later(end, c.end), c.start);
26479
+ }
26480
+ }
26481
+ const doneSubs = children.filter((c) => c.finished).length;
26482
+ return {
26483
+ kind,
26484
+ id: t.id,
26485
+ code,
26486
+ level,
26487
+ title: t.title,
26488
+ key: taskKey(t, project) ?? void 0,
26489
+ ownerId: t.assigneeId,
26490
+ start,
26491
+ end,
26492
+ runsPast: false,
26493
+ done: children.length ? doneSubs : t.status === "done" ? 1 : 0,
26494
+ total: children.length || 1,
26495
+ late: lateOf(t) + children.reduce((n, c) => n + c.late, 0),
26496
+ status: t.status,
26497
+ finished: t.status === "done",
26498
+ projectId: t.projectId,
26499
+ locked: lockOf(t),
26500
+ children
26501
+ };
26502
+ }
26503
+ function projectNode(p, code, level, doc, today) {
26504
+ const index = byId(doc.tasks);
26505
+ const kids = childrenByParent(doc.tasks);
26506
+ const all = tasksByProject(doc.tasks).get(p.id) ?? [];
26507
+ const parentOf = (t) => {
26508
+ const q = t.parentTaskId ? index.get(t.parentTaskId) : void 0;
26509
+ return q && q.id !== t.id && q.projectId === t.projectId && !q.parentTaskId ? q : null;
26510
+ };
26511
+ const children = orderTasks(all.filter((t) => !parentOf(t))).map((t, i) => {
26512
+ const subs = (kids.get(t.id) ?? []).filter((s) => s.projectId === p.id && s.id !== t.id);
26513
+ return taskNode(t, "task", code ? `${code}.${i + 1}` : `${i + 1}`, level + 1, p, subs, today);
26514
+ });
26515
+ let latest = null;
26516
+ for (const c of children) latest = later(latest, c.end);
26517
+ const end = day(p.endDate);
26518
+ const done = all.filter((t) => t.status === "done").length;
26519
+ return {
26520
+ kind: "project",
26521
+ id: p.id,
26522
+ code,
26523
+ level,
26524
+ title: p.name,
26525
+ key: p.key,
26526
+ ownerId: p.ownerId || null,
26527
+ start: day(p.startDate),
26528
+ end,
26529
+ runsPast: Boolean(end && latest && latest > end),
26530
+ done,
26531
+ total: all.length,
26532
+ late: children.reduce((n, c) => n + c.late, 0),
26533
+ health: p.health,
26534
+ finished: p.health === "done",
26535
+ children
26536
+ };
26537
+ }
26538
+ /** A node that adds up its children's tasks. */
26539
+ function summed(base) {
26540
+ let done = 0;
26541
+ let total = 0;
26542
+ let late = 0;
26543
+ for (const c of base.children) {
26544
+ done += c.done;
26545
+ total += c.total;
26546
+ late += c.late;
26547
+ }
26548
+ return {
26549
+ ...base,
26550
+ done,
26551
+ total,
26552
+ late
26553
+ };
26554
+ }
26555
+ function programNode(g, code, level, doc, today) {
26556
+ const children = orderPlans(doc.projects.filter((p) => p.programId === g.id)).map((p, i) => projectNode(p, code ? `${code}.${i + 1}` : `${i + 1}`, level + 1, doc, today));
26557
+ let latest = null;
26558
+ for (const c of children) latest = later(latest, later(c.end, latestUnder(c)));
26559
+ const end = day(g.endDate);
26560
+ return summed({
26561
+ kind: "program",
26562
+ id: g.id,
26563
+ code,
26564
+ level,
26565
+ title: g.name,
26566
+ ownerId: g.ownerId || null,
26567
+ start: day(g.startDate),
26568
+ end,
26569
+ runsPast: Boolean(end && latest && latest > end),
26570
+ health: g.health,
26571
+ finished: g.health === "done",
26572
+ children
26573
+ });
26574
+ }
26575
+ /** The latest end among a node's children, all the way down. */
26576
+ function latestUnder(n) {
26577
+ let out = null;
26578
+ for (const c of n.children) out = later(out, later(c.end, latestUnder(c)));
26579
+ return out;
26580
+ }
26581
+ /**
26582
+ * The breakdown of one portfolio, program or project, or null when it isn't
26583
+ * there. `today` is "YYYY-MM-DD", for what's late.
26584
+ */
26585
+ function buildBreakdown(doc, root, today) {
26586
+ if (root.kind === "project") {
26587
+ const p = doc.projects.find((x) => x.id === root.id);
26588
+ return p ? projectNode(p, "", 0, doc, today) : null;
26589
+ }
26590
+ if (root.kind === "program") {
26591
+ const g = doc.programs.find((x) => x.id === root.id);
26592
+ return g ? programNode(g, "", 0, doc, today) : null;
26593
+ }
26594
+ const f = doc.portfolios.find((x) => x.id === root.id);
26595
+ if (!f) return null;
26596
+ const children = orderPlans(doc.programs.filter((g) => g.portfolioId === f.id)).map((g, i) => programNode(g, `${i + 1}`, 1, doc, today));
26597
+ let start = null;
26598
+ let end = null;
26599
+ for (const c of children) {
26600
+ start = earlier(start, c.start);
26601
+ end = later(end, c.end);
26602
+ }
26603
+ return summed({
26604
+ kind: "portfolio",
26605
+ id: f.id,
26606
+ code: "",
26607
+ level: 0,
26608
+ title: f.name,
26609
+ ownerId: f.ownerId || null,
26610
+ start,
26611
+ end,
26612
+ runsPast: false,
26613
+ health: f.health,
26614
+ finished: f.health === "done",
26615
+ children
26616
+ });
26617
+ }
26618
+ /** Whole percent done; 0 with nothing to count. */
26619
+ const percentDone = (n) => n.total > 0 ? Math.round(n.done / n.total * 100) : 0;
26620
+
25810
26621
  // src/lib/mcp/tools.ts
25811
26622
  init_project_messages();
25812
26623
  init_daily_digest();
@@ -26528,6 +27339,60 @@ function chatAnswer(data, target, lines) {
26528
27339
  }))
26529
27340
  };
26530
27341
  }
27342
+ /** The portfolio, program or project a breakdown is asked of; a name that's two kinds asks which. */
27343
+ function breakdownTarget(data, of, kind) {
27344
+ const lists = {
27345
+ project: data.projects,
27346
+ program: data.programs,
27347
+ portfolio: data.portfolios
27348
+ };
27349
+ if (kind) return {
27350
+ kind,
27351
+ id: findOne(lists[kind], of, kind).id
27352
+ };
27353
+ const want = of.trim().toLowerCase();
27354
+ const exact = [
27355
+ "project",
27356
+ "program",
27357
+ "portfolio"
27358
+ ].flatMap((k) => lists[k].filter((i) => i.id === of.trim() || i.name.trim().toLowerCase() === want || i.key?.toLowerCase() === want).map((i) => ({
27359
+ kind: k,
27360
+ id: i.id
27361
+ })));
27362
+ const kinds = new Set(exact.map((e) => e.kind));
27363
+ if (kinds.size > 1) throw new ToolError(`"${of.trim()}" is a ${[...kinds].join(" and a ")}; say which with kind.`);
27364
+ if (exact.length) return {
27365
+ kind: exact[0].kind,
27366
+ id: findOne(lists[exact[0].kind], of, exact[0].kind).id
27367
+ };
27368
+ for (const k of [
27369
+ "project",
27370
+ "program",
27371
+ "portfolio"
27372
+ ]) try {
27373
+ return {
27374
+ kind: k,
27375
+ id: findOne(lists[k], of, k).id
27376
+ };
27377
+ } catch (e) {
27378
+ if (!(e instanceof ToolError) || !/^No /.test(e.message)) throw e;
27379
+ }
27380
+ throw new ToolError(`No portfolio, program or project called "${of.trim()}".`);
27381
+ }
27382
+ /** The lines under `root`, top to bottom, `depth` levels down; with `open`, nothing finished or under it. */
27383
+ function breakdownLines(root, depth, open) {
27384
+ const out = [];
27385
+ const walk = (n) => {
27386
+ for (const c of n.children) {
27387
+ if (open && c.finished) continue;
27388
+ if (depth && c.level - root.level > depth) continue;
27389
+ out.push(c);
27390
+ walk(c);
27391
+ }
27392
+ };
27393
+ walk(root);
27394
+ return out;
27395
+ }
26531
27396
  const HARBOR_TOOLS = [
26532
27397
  tool({
26533
27398
  name: "harbor_overview",
@@ -27002,7 +27867,7 @@ const HARBOR_TOOLS = [
27002
27867
  tool({
27003
27868
  name: "catch_up",
27004
27869
  title: "While you were away",
27005
- description: "The catch-up the website and the terminal app open on after time away or a few days unseen (while you were away): tasks handed to the person since then and by whom, decisions made on their projects without them, what moved on their projects (done, added, health changes), and the three to look at first. It counts from the start of time away they were marked for once its return date has come, else from since (when they last looked; any ISO date or moment), else the last 7 days. Reading it doesn't clear the catch-up anywhere." + DATA_NOTE,
27870
+ description: "The catch-up the website and the terminal app open on after time away or a few days unseen (while you were away): tasks handed to the person since then and by whom, decisions made on their projects without them, what moved on their projects (done, added, health changes), and the three to look at first (lookFirstMore counts the late, due-soon and handed-over tasks that didn't fit). It counts from the start of time away they were marked for once its return date has come, else from since (when they last looked; any ISO date or moment), else the last 7 days. Reading it doesn't clear the catch-up anywhere." + DATA_NOTE,
27006
27871
  input: object({
27007
27872
  harbor: harborArg,
27008
27873
  since: string().regex(/^\d{4}-\d{2}-\d{2}/, "a date as YYYY-MM-DD, or an ISO moment").max(40).optional().describe("When the person last looked, YYYY-MM-DD or an ISO moment.")
@@ -27037,6 +27902,11 @@ const HARBOR_TOOLS = [
27037
27902
  ...l.taskId ? { taskId: l.taskId } : {},
27038
27903
  ...l.raidId ? { raidId: l.raidId } : {}
27039
27904
  })),
27905
+ ...w.moreLook.length ? { lookFirstMore: {
27906
+ late: w.moreLook.filter((l) => l.kind === "late").length,
27907
+ due: w.moreLook.filter((l) => l.kind === "due").length,
27908
+ handed: w.moreLook.filter((l) => l.kind === "handed").length
27909
+ } } : {},
27040
27910
  handed: w.handed.map(({ task, by }) => ({
27041
27911
  id: task.id,
27042
27912
  ...keyOf(task) ? { key: keyOf(task) } : {},
@@ -28121,6 +28991,77 @@ const HARBOR_TOOLS = [
28121
28991
  };
28122
28992
  }
28123
28993
  }),
28994
+ tool({
28995
+ name: "agents_overview",
28996
+ title: "Every agent's work",
28997
+ description: "The harbor's Agents page as data: across every project, the agents' work handed in to the person for review (needsYou, oldest first, each with the agent's latest note), handed in to someone else (withOthers), in progress (working, late first), sent back and not picked up again (sentBack), and approved today (doneToday). Filter with agent and project. The person approves or sends back with decide_approval." + DATA_NOTE,
28998
+ input: object({
28999
+ harbor: harborArg,
29000
+ agent: string().max(200).optional().describe("One agent's name or id."),
29001
+ project: string().max(200).optional().describe("Project id, key or name, for one only."),
29002
+ limit: limitArg(50, 20)
29003
+ }),
29004
+ run: (ctx, input) => {
29005
+ const { data } = ctx;
29006
+ if (!data.people.some(isAgent)) return {
29007
+ agents: [],
29008
+ note: "There are no agents on this harbor's crew yet. Someone adds one on People with Add an agent."
29009
+ };
29010
+ const agent = input.agent ? pickAgent(data.people, input.agent) : null;
29011
+ if (typeof agent === "string") throw new ToolError(agent);
29012
+ const project = input.project ? findOne(data.projects, input.project, "project") : null;
29013
+ const view = agentsView(data, data.currentUserId, /* @__PURE__ */ new Date(), {
29014
+ ...agent ? { agent: agent.id } : {},
29015
+ ...project ? { project: project.id } : {}
29016
+ });
29017
+ const people = byId(data.people);
29018
+ const projects = byId(data.projects);
29019
+ const rows = (list) => list.slice(0, input.limit).map((r) => {
29020
+ const key = taskKey(r.task, projects.get(r.task.projectId));
29021
+ const a = r.task.approval;
29022
+ return {
29023
+ id: r.task.id,
29024
+ ...key ? { key } : {},
29025
+ title: r.task.title,
29026
+ agent: r.agent.name,
29027
+ project: projects.get(r.task.projectId)?.name ?? null,
29028
+ ...r.late ? { late: true } : {},
29029
+ due: dayOf(r.task.dueDate),
29030
+ ...r.note ? { agentNote: {
29031
+ at: r.note.createdAt,
29032
+ body: r.note.body
29033
+ } } : {},
29034
+ ...a && a.status === "pending" ? {
29035
+ askedAt: a.askedAt,
29036
+ waitingOn: nameOf$2(people, a.approverId)
29037
+ } : {},
29038
+ ...a && a.status !== "pending" ? {
29039
+ decidedAt: a.decidedAt,
29040
+ by: nameOf$2(people, a.approverId),
29041
+ ...a.note ? { note: a.note } : {}
29042
+ } : {},
29043
+ ...webLink(ctx, { task: r.task.id })
29044
+ };
29045
+ });
29046
+ return {
29047
+ agents: view.agents.map((a) => ({
29048
+ id: a.id,
29049
+ name: a.name,
29050
+ lastReported: a.lastSeenAt ?? null
29051
+ })),
29052
+ counts: {
29053
+ needsYou: view.needsYou.length,
29054
+ working: view.working.length,
29055
+ doneToday: view.doneToday.length
29056
+ },
29057
+ needsYou: rows(view.needsYou),
29058
+ withOthers: rows(view.withOthers),
29059
+ working: rows(view.working),
29060
+ sentBack: rows(view.sentBack),
29061
+ doneToday: rows(view.doneToday)
29062
+ };
29063
+ }
29064
+ }),
28124
29065
  tool({
28125
29066
  name: "fog",
28126
29067
  title: "Tasks in fog",
@@ -28388,6 +29329,58 @@ const HARBOR_TOOLS = [
28388
29329
  };
28389
29330
  }
28390
29331
  }),
29332
+ tool({
29333
+ name: "work_breakdown",
29334
+ title: "Work breakdown",
29335
+ description: "A portfolio, program or project as its work breakdown (the website's Breakdown view): one numbered line per program, project, task and subtask under it (1, 1.1, 1.1.2), each with its owner, dates, tasks done of all and how many are late, rolled up from under it. Numbers count from the thing asked for and include finished work, so they match the website's. `of` names it; `kind` settles a name that's both a project and a program. `depth` keeps to that many levels; `open` leaves finished work out." + DATA_NOTE,
29336
+ input: object({
29337
+ harbor: harborArg,
29338
+ of: string().min(1).max(200).describe("Portfolio, program or project: id, key or name."),
29339
+ kind: _enum([
29340
+ "portfolio",
29341
+ "program",
29342
+ "project"
29343
+ ]).optional(),
29344
+ depth: number().int().min(1).max(4).optional().describe("Levels to show, 1 being its children."),
29345
+ open: boolean().default(false).describe("Leave finished work out (numbers stay)."),
29346
+ limit: limitArg(1e3, 300),
29347
+ offset: offsetArg
29348
+ }),
29349
+ run: (ctx, input) => {
29350
+ const { data } = ctx;
29351
+ const root = breakdownTarget(data, input.of, input.kind);
29352
+ const tree = buildBreakdown(data, root, todayISO(ctx.now));
29353
+ const people = byId(data.people);
29354
+ const all = breakdownLines(tree, input.depth, input.open);
29355
+ return {
29356
+ of: {
29357
+ kind: tree.kind,
29358
+ name: tree.title
29359
+ },
29360
+ done: tree.done,
29361
+ tasks: tree.total,
29362
+ late: tree.late,
29363
+ lines: all.slice(input.offset, input.offset + input.limit).map((n) => ({
29364
+ wbs: n.code,
29365
+ level: n.level - tree.level,
29366
+ kind: n.kind,
29367
+ name: n.title,
29368
+ ...n.key && (n.kind === "task" || n.kind === "subtask") ? { key: n.key } : {},
29369
+ owner: nameOf$2(people, n.ownerId),
29370
+ start: n.start,
29371
+ end: n.end,
29372
+ ...n.status ? { status: n.status } : n.finished ? { status: "done" } : {},
29373
+ ...n.kind === "task" && n.children.length ? { subtasks: n.children.length } : {},
29374
+ done: n.done,
29375
+ tasks: n.total,
29376
+ percent: percentDone(n),
29377
+ ...n.late ? { late: n.late } : {},
29378
+ ...n.runsPast ? { runsPastEnd: true } : {}
29379
+ })),
29380
+ more: all.length > input.offset + input.limit
29381
+ };
29382
+ }
29383
+ }),
28391
29384
  tool({
28392
29385
  name: "what_if",
28393
29386
  title: "Try a what-if plan for a portfolio",
@@ -29086,8 +30079,9 @@ var init_session = __esmMin((() => {
29086
30079
  /**
29087
30080
  * The few things a new harbor needs in its first week, in the order they
29088
30081
  * matter: a first project, a real name on the account, a confirmed email,
29089
- * and someone else aboard. Today lists the ones not done. Someone who
29090
- * joined is asked only for their name and their email.
30082
+ * someone else aboard, and an AI app connected. Today lists the ones not
30083
+ * done. Someone who joined is asked only for their name, their email and
30084
+ * the AI app, which is theirs, not the harbor's.
29091
30085
  *
29092
30086
  * The placeholder program ("The work") isn't on the list: it gives way to
29093
30087
  * the first program anyone makes, so naming it is never a chore to set.
@@ -29100,7 +30094,7 @@ var init_session = __esmMin((() => {
29100
30094
  function starterProgram(data) {
29101
30095
  const program = data.programs.find((p) => p.name.trim() === STARTER_PROGRAM);
29102
30096
  if (!program) return null;
29103
- return ownProjects(data.projects).some((p) => p.programId === program.id) || data.milestones.some((m) => m.programId === program.id) || data.raidItems.some((r) => r.programId === program.id) ? null : program;
30097
+ return realProjects(data.projects).some((p) => p.programId === program.id) || data.milestones.some((m) => m.programId === program.id) || data.raidItems.some((r) => r.programId === program.id) ? null : program;
29104
30098
  }
29105
30099
  var init_first_week = __esmMin((() => {
29106
30100
  init_first_voyage();
@@ -29527,6 +30521,19 @@ function hierarchySlice({ get, write }) {
29527
30521
  const program = get().programs.find((p) => p.id === programId);
29528
30522
  get().log(`moved ${ids.length} project${ids.length === 1 ? "" : "s"} to ${program?.name ?? "a program"}`, `/programs/${programId}`);
29529
30523
  },
30524
+ placeInBreakdown: async (move) => {
30525
+ const { applyMove, moveProblem } = await Promise.resolve().then(() => (init_wbs_move(), wbs_move_exports));
30526
+ const s = get();
30527
+ const problem = moveProblem(s, move);
30528
+ if (problem) return problem;
30529
+ const rows = applyMove(s, move, stamp());
30530
+ if (!rows) return null;
30531
+ write(rows);
30532
+ const name = move.kind === "task" ? s.tasks.find((t) => t.id === move.id)?.title : move.kind === "project" ? s.projects.find((p) => p.id === move.id)?.name : s.programs.find((p) => p.id === move.id)?.name;
30533
+ const where = move.kind === "task" ? move.into.kind === "task" ? `/projects/${s.tasks.find((t) => t.id === move.into.id)?.projectId ?? ""}` : `/projects/${move.into.id}` : move.kind === "project" ? `/programs/${move.into}` : `/portfolios/${move.into}`;
30534
+ get().log(`moved “${name ?? "an item"}” in the breakdown`, where);
30535
+ return null;
30536
+ },
29530
30537
  restoreRows: (rows, links) => {
29531
30538
  const state = get();
29532
30539
  const back = (current, add) => {
@@ -29613,6 +30620,34 @@ function hierarchySlice({ get, write }) {
29613
30620
  get().log(`removed ${kind} “${name ?? id}”`);
29614
30621
  return counts;
29615
30622
  },
30623
+ clearSample: () => {
30624
+ const state = get();
30625
+ if (!hasSample(state) && !state.people.some((p) => isSampleId(p.id))) return false;
30626
+ write({
30627
+ ...withoutSample(state),
30628
+ selectedTaskId: null
30629
+ });
30630
+ get().log("cleared the sample portfolio", "/portfolios");
30631
+ return true;
30632
+ },
30633
+ addSamplePortfolio: (withSample) => {
30634
+ const state = get();
30635
+ if (hasSample(state)) return false;
30636
+ const next = withSample(state, todayISO());
30637
+ write({
30638
+ people: next.people,
30639
+ portfolios: next.portfolios,
30640
+ programs: next.programs,
30641
+ projects: next.projects,
30642
+ milestones: next.milestones,
30643
+ tasks: next.tasks,
30644
+ raidItems: next.raidItems,
30645
+ comments: next.comments,
30646
+ boardConfigs: next.boardConfigs
30647
+ });
30648
+ get().log("added the sample portfolio", `/portfolios/${SAMPLE_PORTFOLIO_ID}`);
30649
+ return true;
30650
+ },
29616
30651
  setBoardConfig: (projectId, config) => {
29617
30652
  write({ boardConfigs: {
29618
30653
  ...get().boardConfigs ?? {},
@@ -29662,6 +30697,7 @@ var init_hierarchy = __esmMin((() => {
29662
30697
  init_format();
29663
30698
  init_empty();
29664
30699
  init_first_week();
30700
+ init_sample_ids();
29665
30701
  SMALL_IMPORT = 20;
29666
30702
  }));
29667
30703
 
@@ -30017,7 +31053,7 @@ function tasksSlice({ set, get, write }) {
30017
31053
  ...t,
30018
31054
  id,
30019
31055
  createdAt: stamp(),
30020
- createdById: get().currentUserId || null,
31056
+ createdById: t.createdById ?? (get().currentUserId || null),
30021
31057
  completedAt: t.status === "done" ? t.completedAt ?? stamp() : null,
30022
31058
  checklist: t.checklist ?? [],
30023
31059
  ..."parentTaskId" in t ? { parentTaskId } : {},
@@ -34482,7 +35518,8 @@ function WelcomeView({ when, active, width, height, go, onDone }) {
34482
35518
  }, { isActive: active });
34483
35519
  const [hello, ...rest] = welcomeTitle(w, name, day).split(" · ");
34484
35520
  const label = (h) => HEALTH_LABEL$1[h];
34485
- const room = Math.max(0, height - 6 - look.length);
35521
+ const more = moreText(w.moreLook);
35522
+ const room = Math.max(0, height - 6 - look.length - (more ? 1 : 0));
34486
35523
  const lines = [
34487
35524
  ...w.decisions.length ? [{
34488
35525
  head: true,
@@ -34531,6 +35568,16 @@ function WelcomeView({ when, active, width, height, go, onDone }) {
34531
35568
  ]
34532
35569
  }, l.taskId ?? l.raidId ?? l.text);
34533
35570
  }),
35571
+ more ? /* @__PURE__ */ jsxs(Text, {
35572
+ color: theme.muted,
35573
+ wrap: "truncate-end",
35574
+ children: [
35575
+ " ",
35576
+ "And ",
35577
+ more,
35578
+ ", all on Today"
35579
+ ]
35580
+ }) : null,
34534
35581
  lines.map((l, i) => l.head ? /* @__PURE__ */ jsx(Box, {
34535
35582
  marginTop: 1,
34536
35583
  children: /* @__PURE__ */ jsx(Text, {
@@ -38200,14 +39247,19 @@ const NAV = [
38200
39247
  {
38201
39248
  screen: "reports",
38202
39249
  label: "Reports"
39250
+ },
39251
+ {
39252
+ screen: "agents",
39253
+ label: "Agents"
38203
39254
  }
38204
39255
  ];
38205
- /** The keys past 0 that open a sidebar screen: C the crew, W your week, G goals, O reports. */
39256
+ /** The keys past 0 that open a sidebar screen: C the crew, W your week, G goals, O reports, I agents. */
38206
39257
  const LETTER_KEYS = [
38207
39258
  "C",
38208
39259
  "W",
38209
39260
  "G",
38210
- "O"
39261
+ "O",
39262
+ "I"
38211
39263
  ];
38212
39264
  /** The screens where n makes something: a task, or what the screen lists. */
38213
39265
  const N_MAKES = /* @__PURE__ */ new Set([
@@ -38461,6 +39513,7 @@ function App({ ui, startIn }) {
38461
39513
  if (input === "W") return goScreen("week");
38462
39514
  if (input === "G") return goScreen("goals");
38463
39515
  if (input === "O") return goScreen("reports");
39516
+ if (input === "I") return goScreen("agents");
38464
39517
  if (input === "r" && page?.kind !== "bridge") {
38465
39518
  sync.retryNow();
38466
39519
  return notify("Saving now.");
@@ -38784,6 +39837,7 @@ function App({ ui, startIn }) {
38784
39837
  else if (screen === "week") screenNode = /* @__PURE__ */ jsx(WeekView, { ...viewProps });
38785
39838
  else if (screen === "goals") screenNode = /* @__PURE__ */ jsx(GoalsView, { ...viewProps });
38786
39839
  else if (screen === "reports") screenNode = /* @__PURE__ */ jsx(ReportsView, { ...viewProps });
39840
+ else if (screen === "agents") screenNode = /* @__PURE__ */ jsx(AgentsView, { ...viewProps });
38787
39841
  else screenNode = /* @__PURE__ */ jsx(HistoryView, { ...viewProps });
38788
39842
  return /* @__PURE__ */ jsxs(Box, {
38789
39843
  flexDirection: "column",