@harborppm/cli 0.114.0 → 0.115.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/README.md +1 -1
- package/dist/app.mjs +1091 -384
- package/lib/cli.mjs +1 -1
- package/lib/format.mjs +94 -30
- package/package.json +1 -1
package/dist/app.mjs
CHANGED
|
@@ -671,205 +671,64 @@ function useHarbor(selector) {
|
|
|
671
671
|
return useStore(useDeps().store, selector);
|
|
672
672
|
}
|
|
673
673
|
|
|
674
|
-
// src/lib/
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
for (let n = 2;; n++) if (!taken.has(`${base}${n}`)) return `${base}${n}`;
|
|
686
|
-
}
|
|
687
|
-
/** Whether `a` has the better claim to the number both hold. */
|
|
688
|
-
function first$3(a, b, stored) {
|
|
689
|
-
const ka = kept(a, stored);
|
|
690
|
-
if (ka !== kept(b, stored)) return ka;
|
|
691
|
-
return made(a, b) <= 0;
|
|
674
|
+
// src/lib/account-deletion.ts
|
|
675
|
+
var FORMER_MEMBER;
|
|
676
|
+
var init_account_deletion = __esmMin((() => {
|
|
677
|
+
FORMER_MEMBER = "Former member";
|
|
678
|
+
}));
|
|
679
|
+
|
|
680
|
+
// src/lib/former-crew.ts
|
|
681
|
+
function isFormerCrew(person, gone) {
|
|
682
|
+
if (person.kind === "agent") return false;
|
|
683
|
+
if (person.name === "Former member" && !person.accountId) return true;
|
|
684
|
+
return Boolean(person.accountId && gone.includes(person.accountId));
|
|
692
685
|
}
|
|
686
|
+
var useFormerAccounts;
|
|
687
|
+
var init_former_crew = __esmMin((() => {
|
|
688
|
+
init_esm();
|
|
689
|
+
init_account_deletion();
|
|
690
|
+
useFormerAccounts = create$1(() => ({ ids: [] }));
|
|
691
|
+
}));
|
|
692
|
+
|
|
693
|
+
// src/lib/agent-check.ts
|
|
693
694
|
/**
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
* used its key already; otherwise the task made first does. Returns the same
|
|
698
|
-
* object when nothing needed doing.
|
|
695
|
+
* Who checks an agent's work on a task: whoever gave it the task, else
|
|
696
|
+
* whoever put the agent on the crew. A person still aboard, never an agent;
|
|
697
|
+
* null when there's nobody (the work still waits in In review).
|
|
699
698
|
*/
|
|
700
|
-
function
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
const ok = !!p.key && KEY.test(p.key) && !taken.has(p.key);
|
|
705
|
-
if (ok) taken.add(p.key);
|
|
706
|
-
return ok;
|
|
707
|
-
});
|
|
708
|
-
if (keeps.includes(false)) projects = projects.map((p, i) => {
|
|
709
|
-
if (keeps[i]) return p;
|
|
710
|
-
const key = projectKeyFor(p.name, taken);
|
|
711
|
-
taken.add(key);
|
|
712
|
-
return {
|
|
713
|
-
...p,
|
|
714
|
-
key
|
|
715
|
-
};
|
|
716
|
-
});
|
|
717
|
-
const byProject = /* @__PURE__ */ new Map();
|
|
718
|
-
for (const t of data.tasks) {
|
|
719
|
-
const list = byProject.get(t.projectId);
|
|
720
|
-
if (list) list.push(t);
|
|
721
|
-
else byProject.set(t.projectId, [t]);
|
|
699
|
+
function agentChecker(people, task, agent, gone = []) {
|
|
700
|
+
for (const id of [task.assignedBy, agent.addedById]) {
|
|
701
|
+
const p = id ? people.find((x) => x.id === id) : void 0;
|
|
702
|
+
if (p && p.kind !== "agent" && !isFormerCrew(p, gone)) return p;
|
|
722
703
|
}
|
|
723
|
-
|
|
724
|
-
for (const list of byProject.values()) {
|
|
725
|
-
let max = 0;
|
|
726
|
-
const holder = /* @__PURE__ */ new Map();
|
|
727
|
-
const loose = [];
|
|
728
|
-
for (const t of list) {
|
|
729
|
-
const n = t.number;
|
|
730
|
-
if (!Number.isInteger(n) || n < 1) {
|
|
731
|
-
loose.push(t);
|
|
732
|
-
continue;
|
|
733
|
-
}
|
|
734
|
-
const other = holder.get(n);
|
|
735
|
-
if (other) {
|
|
736
|
-
const [keep, move] = first$3(other, t, stored) ? [other, t] : [t, other];
|
|
737
|
-
holder.set(n, keep);
|
|
738
|
-
loose.push(move);
|
|
739
|
-
} else holder.set(n, t);
|
|
740
|
-
if (n > max) max = n;
|
|
741
|
-
}
|
|
742
|
-
if (loose.length === 0) continue;
|
|
743
|
-
loose.sort(made);
|
|
744
|
-
for (const t of loose) renumber.set(t.id, ++max);
|
|
745
|
-
}
|
|
746
|
-
if (projects === data.projects && renumber.size === 0) return data;
|
|
747
|
-
const tasks = renumber.size === 0 ? data.tasks : data.tasks.map((t) => renumber.has(t.id) ? {
|
|
748
|
-
...t,
|
|
749
|
-
number: renumber.get(t.id)
|
|
750
|
-
} : t);
|
|
751
|
-
return {
|
|
752
|
-
...data,
|
|
753
|
-
projects,
|
|
754
|
-
tasks
|
|
755
|
-
};
|
|
704
|
+
return null;
|
|
756
705
|
}
|
|
757
706
|
/**
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
...after,
|
|
783
|
-
projects
|
|
784
|
-
};
|
|
785
|
-
const was = byId(before.tasks);
|
|
786
|
-
const holders = /* @__PURE__ */ new Map();
|
|
787
|
-
for (const t of after.tasks) {
|
|
788
|
-
if (!Number.isInteger(t.number)) continue;
|
|
789
|
-
const k = `${t.projectId}:${t.number}`;
|
|
790
|
-
holders.set(k, (holders.get(k) ?? 0) + 1);
|
|
791
|
-
}
|
|
792
|
-
const keepsNumber = (t) => Number.isInteger(t.number) && holders.get(`${t.projectId}:${t.number}`) === 1;
|
|
793
|
-
const fresh = (t) => {
|
|
794
|
-
const old = was.get(t.id);
|
|
795
|
-
if (!old) return !keepsNumber(t);
|
|
796
|
-
return old.projectId !== t.projectId && old.number === t.number;
|
|
797
|
-
};
|
|
798
|
-
if (!after.tasks.some(fresh)) return projects === after.projects ? after : {
|
|
799
|
-
...after,
|
|
800
|
-
projects
|
|
801
|
-
};
|
|
802
|
-
const max = /* @__PURE__ */ new Map();
|
|
803
|
-
for (const t of after.tasks) {
|
|
804
|
-
if (fresh(t) || !Number.isInteger(t.number)) continue;
|
|
805
|
-
if (t.number > (max.get(t.projectId) ?? 0)) max.set(t.projectId, t.number);
|
|
806
|
-
}
|
|
807
|
-
const tasks = after.tasks.map((t) => {
|
|
808
|
-
if (!fresh(t)) return t;
|
|
809
|
-
const n = (max.get(t.projectId) ?? 0) + 1;
|
|
810
|
-
max.set(t.projectId, n);
|
|
811
|
-
return {
|
|
812
|
-
...t,
|
|
813
|
-
number: n
|
|
814
|
-
};
|
|
815
|
-
});
|
|
816
|
-
return {
|
|
817
|
-
...after,
|
|
818
|
-
projects,
|
|
819
|
-
tasks
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
/** "RR-42", or null for a task without a number yet. */
|
|
823
|
-
function taskKey(task, project) {
|
|
824
|
-
return project?.key && task.number ? `${project.key}-${task.number}` : null;
|
|
825
|
-
}
|
|
826
|
-
/** The task a key names ("rr-42" works too), or null. */
|
|
827
|
-
function findByKey(data, text) {
|
|
828
|
-
const m = KEY_TEXT.exec(text.trim());
|
|
829
|
-
if (!m) return null;
|
|
830
|
-
const project = data.projects.find((p) => p.key === m[1].toUpperCase());
|
|
831
|
-
if (!project) return null;
|
|
832
|
-
const n = Number(m[2]);
|
|
833
|
-
return data.tasks.find((t) => t.projectId === project.id && t.number === n) ?? null;
|
|
834
|
-
}
|
|
835
|
-
var MAX_KEY, KEY, made, kept, KEY_TEXT;
|
|
836
|
-
var init_task_keys = __esmMin((() => {
|
|
837
|
-
init_indexes();
|
|
838
|
-
MAX_KEY = 5;
|
|
839
|
-
KEY = /^[A-Z][A-Z0-9]{0,9}$/;
|
|
840
|
-
made = (a, b) => a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
841
|
-
kept = (t, stored) => {
|
|
842
|
-
const was = stored?.get(t.id);
|
|
843
|
-
return !!was && was.number === t.number && was.projectId === t.projectId;
|
|
844
|
-
};
|
|
845
|
-
KEY_TEXT = /^([A-Za-z][A-Za-z0-9]{0,9})-(\d{1,7})$/;
|
|
846
|
-
}));
|
|
847
|
-
|
|
848
|
-
// src/lib/agents.ts
|
|
849
|
-
/** What an agent should work on: its open tasks not yet waiting on review, in progress first, then most urgent and soonest. */
|
|
850
|
-
function agentQueue(data, agentId) {
|
|
851
|
-
return data.tasks.filter((t) => t.assigneeId === agentId && (t.status === "todo" || t.status === "doing" || t.status === "backlog")).sort((a, b) => 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"));
|
|
852
|
-
}
|
|
853
|
-
/** The agent an app means: the one named, else the only one on the crew. */
|
|
854
|
-
function pickAgent(people, key) {
|
|
855
|
-
const agents = people.filter(isAgent);
|
|
856
|
-
if (agents.length === 0) return "There are no agents on this harbor's crew yet. Someone adds one on People with Add an agent.";
|
|
857
|
-
if (!key) {
|
|
858
|
-
if (agents.length === 1) return agents[0];
|
|
859
|
-
return `This harbor has ${agents.length} agents (${agents.map((a) => a.name).join(", ")}). Say which with agent.`;
|
|
860
|
-
}
|
|
861
|
-
const k = key.trim().toLowerCase();
|
|
862
|
-
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(", ")}.`;
|
|
863
|
-
}
|
|
864
|
-
var isAgent, RANK$1;
|
|
865
|
-
var init_agents = __esmMin((() => {
|
|
707
|
+
* What moving a task by hand does to an agent's ask, which stands for one
|
|
708
|
+
* hand-in and only while it waits in In review: a person who finishes the
|
|
709
|
+
* task has checked it (approved, by them); moved anywhere else, the ask is
|
|
710
|
+
* withdrawn, so nobody approves work being redone and the next hand-in asks
|
|
711
|
+
* afresh. `undefined` leaves the approval as it is (a person's ask, an
|
|
712
|
+
* answer already given).
|
|
713
|
+
*/
|
|
714
|
+
function agentAskAfterMove(people, task, next, by, at) {
|
|
715
|
+
const a = task.approval;
|
|
716
|
+
if (!a || a.status !== "pending" || next === task.status || next === "review") return void 0;
|
|
717
|
+
if (!isAgent(people.find((p) => p.id === a.askedById))) return void 0;
|
|
718
|
+
if (next !== "done") return null;
|
|
719
|
+
const person = people.find((p) => p.id === by);
|
|
720
|
+
return person && !isAgent(person) ? {
|
|
721
|
+
...a,
|
|
722
|
+
approverId: by,
|
|
723
|
+
status: "approved",
|
|
724
|
+
note: null,
|
|
725
|
+
decidedAt: at
|
|
726
|
+
} : void 0;
|
|
727
|
+
}
|
|
728
|
+
var isAgent;
|
|
729
|
+
var init_agent_check = __esmMin((() => {
|
|
730
|
+
init_former_crew();
|
|
866
731
|
isAgent = (p) => p?.kind === "agent";
|
|
867
|
-
RANK$1 = {
|
|
868
|
-
urgent: 0,
|
|
869
|
-
high: 1,
|
|
870
|
-
medium: 2,
|
|
871
|
-
low: 3
|
|
872
|
-
};
|
|
873
732
|
}));
|
|
874
733
|
|
|
875
734
|
// src/lib/task-people.ts
|
|
@@ -915,7 +774,7 @@ function projectFiles(data, projectId, kind) {
|
|
|
915
774
|
}
|
|
916
775
|
var init_task_people = __esmMin((() => {
|
|
917
776
|
init_indexes();
|
|
918
|
-
|
|
777
|
+
init_agent_check();
|
|
919
778
|
}));
|
|
920
779
|
|
|
921
780
|
// node_modules/date-fns/constants.js
|
|
@@ -2708,6 +2567,180 @@ var init_board = __esmMin((() => {
|
|
|
2708
2567
|
];
|
|
2709
2568
|
}));
|
|
2710
2569
|
|
|
2570
|
+
// src/lib/task-keys.ts
|
|
2571
|
+
/** "Ridge Runner" → "RR", "Website" → "WEB", "Q4 launch plan" → "QLP". */
|
|
2572
|
+
function baseKey(name) {
|
|
2573
|
+
const words = name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^A-Za-z0-9 ]+/g, " ").split(/\s+/).filter((w) => /[A-Za-z]/.test(w));
|
|
2574
|
+
if (words.length === 0) return "P";
|
|
2575
|
+
return (words.length === 1 ? words[0].replace(/[^A-Za-z]/g, "").slice(0, 3) : words.map((w) => w.replace(/[^A-Za-z]/g, "")[0] ?? "").join("").slice(0, MAX_KEY)).toUpperCase() || "P";
|
|
2576
|
+
}
|
|
2577
|
+
/** A key for `name` that none of `taken` has: "RR", then "RR2", "RR3"… */
|
|
2578
|
+
function projectKeyFor(name, taken) {
|
|
2579
|
+
const base = baseKey(name);
|
|
2580
|
+
if (!taken.has(base)) return base;
|
|
2581
|
+
for (let n = 2;; n++) if (!taken.has(`${base}${n}`)) return `${base}${n}`;
|
|
2582
|
+
}
|
|
2583
|
+
/** Whether `a` has the better claim to the number both hold. */
|
|
2584
|
+
function first$3(a, b, stored) {
|
|
2585
|
+
const ka = kept(a, stored);
|
|
2586
|
+
if (ka !== kept(b, stored)) return ka;
|
|
2587
|
+
return made(a, b) <= 0;
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Every project keyed, every task numbered, no number given twice in a
|
|
2591
|
+
* project. When two tasks hold one number, a task already stored with it
|
|
2592
|
+
* (`stored`: the document before this write) keeps it, since people may have
|
|
2593
|
+
* used its key already; otherwise the task made first does. Returns the same
|
|
2594
|
+
* object when nothing needed doing.
|
|
2595
|
+
*/
|
|
2596
|
+
function settleKeys(data, stored) {
|
|
2597
|
+
let projects = data.projects;
|
|
2598
|
+
const taken = /* @__PURE__ */ new Set();
|
|
2599
|
+
const keeps = projects.map((p) => {
|
|
2600
|
+
const ok = !!p.key && KEY.test(p.key) && !taken.has(p.key);
|
|
2601
|
+
if (ok) taken.add(p.key);
|
|
2602
|
+
return ok;
|
|
2603
|
+
});
|
|
2604
|
+
if (keeps.includes(false)) projects = projects.map((p, i) => {
|
|
2605
|
+
if (keeps[i]) return p;
|
|
2606
|
+
const key = projectKeyFor(p.name, taken);
|
|
2607
|
+
taken.add(key);
|
|
2608
|
+
return {
|
|
2609
|
+
...p,
|
|
2610
|
+
key
|
|
2611
|
+
};
|
|
2612
|
+
});
|
|
2613
|
+
const byProject = /* @__PURE__ */ new Map();
|
|
2614
|
+
for (const t of data.tasks) {
|
|
2615
|
+
const list = byProject.get(t.projectId);
|
|
2616
|
+
if (list) list.push(t);
|
|
2617
|
+
else byProject.set(t.projectId, [t]);
|
|
2618
|
+
}
|
|
2619
|
+
const renumber = /* @__PURE__ */ new Map();
|
|
2620
|
+
for (const list of byProject.values()) {
|
|
2621
|
+
let max = 0;
|
|
2622
|
+
const holder = /* @__PURE__ */ new Map();
|
|
2623
|
+
const loose = [];
|
|
2624
|
+
for (const t of list) {
|
|
2625
|
+
const n = t.number;
|
|
2626
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
2627
|
+
loose.push(t);
|
|
2628
|
+
continue;
|
|
2629
|
+
}
|
|
2630
|
+
const other = holder.get(n);
|
|
2631
|
+
if (other) {
|
|
2632
|
+
const [keep, move] = first$3(other, t, stored) ? [other, t] : [t, other];
|
|
2633
|
+
holder.set(n, keep);
|
|
2634
|
+
loose.push(move);
|
|
2635
|
+
} else holder.set(n, t);
|
|
2636
|
+
if (n > max) max = n;
|
|
2637
|
+
}
|
|
2638
|
+
if (loose.length === 0) continue;
|
|
2639
|
+
loose.sort(made);
|
|
2640
|
+
for (const t of loose) renumber.set(t.id, ++max);
|
|
2641
|
+
}
|
|
2642
|
+
if (projects === data.projects && renumber.size === 0) return data;
|
|
2643
|
+
const tasks = renumber.size === 0 ? data.tasks : data.tasks.map((t) => renumber.has(t.id) ? {
|
|
2644
|
+
...t,
|
|
2645
|
+
number: renumber.get(t.id)
|
|
2646
|
+
} : t);
|
|
2647
|
+
return {
|
|
2648
|
+
...data,
|
|
2649
|
+
projects,
|
|
2650
|
+
tasks
|
|
2651
|
+
};
|
|
2652
|
+
}
|
|
2653
|
+
/**
|
|
2654
|
+
* The browser's half: number the tasks this change adds, and the ones it
|
|
2655
|
+
* moves to another project, after the highest number in their project. Old
|
|
2656
|
+
* tasks without a number are left for the server. Same object when nothing
|
|
2657
|
+
* was added or moved.
|
|
2658
|
+
*/
|
|
2659
|
+
function numberNewTasks(before, after) {
|
|
2660
|
+
if (after.tasks === before.tasks && after.projects === before.projects) return after;
|
|
2661
|
+
let projects = after.projects;
|
|
2662
|
+
if (projects !== before.projects) {
|
|
2663
|
+
const known = new Set(before.projects.map((p) => p.id));
|
|
2664
|
+
if (projects.some((p) => !known.has(p.id) && !p.key)) {
|
|
2665
|
+
const taken = new Set(projects.flatMap((p) => p.key ? [p.key] : []));
|
|
2666
|
+
projects = projects.map((p) => {
|
|
2667
|
+
if (known.has(p.id) || p.key) return p;
|
|
2668
|
+
const key = projectKeyFor(p.name, taken);
|
|
2669
|
+
taken.add(key);
|
|
2670
|
+
return {
|
|
2671
|
+
...p,
|
|
2672
|
+
key
|
|
2673
|
+
};
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
if (after.tasks === before.tasks) return projects === after.projects ? after : {
|
|
2678
|
+
...after,
|
|
2679
|
+
projects
|
|
2680
|
+
};
|
|
2681
|
+
const was = byId(before.tasks);
|
|
2682
|
+
const holders = /* @__PURE__ */ new Map();
|
|
2683
|
+
for (const t of after.tasks) {
|
|
2684
|
+
if (!Number.isInteger(t.number)) continue;
|
|
2685
|
+
const k = `${t.projectId}:${t.number}`;
|
|
2686
|
+
holders.set(k, (holders.get(k) ?? 0) + 1);
|
|
2687
|
+
}
|
|
2688
|
+
const keepsNumber = (t) => Number.isInteger(t.number) && holders.get(`${t.projectId}:${t.number}`) === 1;
|
|
2689
|
+
const fresh = (t) => {
|
|
2690
|
+
const old = was.get(t.id);
|
|
2691
|
+
if (!old) return !keepsNumber(t);
|
|
2692
|
+
return old.projectId !== t.projectId && old.number === t.number;
|
|
2693
|
+
};
|
|
2694
|
+
if (!after.tasks.some(fresh)) return projects === after.projects ? after : {
|
|
2695
|
+
...after,
|
|
2696
|
+
projects
|
|
2697
|
+
};
|
|
2698
|
+
const max = /* @__PURE__ */ new Map();
|
|
2699
|
+
for (const t of after.tasks) {
|
|
2700
|
+
if (fresh(t) || !Number.isInteger(t.number)) continue;
|
|
2701
|
+
if (t.number > (max.get(t.projectId) ?? 0)) max.set(t.projectId, t.number);
|
|
2702
|
+
}
|
|
2703
|
+
const tasks = after.tasks.map((t) => {
|
|
2704
|
+
if (!fresh(t)) return t;
|
|
2705
|
+
const n = (max.get(t.projectId) ?? 0) + 1;
|
|
2706
|
+
max.set(t.projectId, n);
|
|
2707
|
+
return {
|
|
2708
|
+
...t,
|
|
2709
|
+
number: n
|
|
2710
|
+
};
|
|
2711
|
+
});
|
|
2712
|
+
return {
|
|
2713
|
+
...after,
|
|
2714
|
+
projects,
|
|
2715
|
+
tasks
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
/** "RR-42", or null for a task without a number yet. */
|
|
2719
|
+
function taskKey(task, project) {
|
|
2720
|
+
return project?.key && task.number ? `${project.key}-${task.number}` : null;
|
|
2721
|
+
}
|
|
2722
|
+
/** The task a key names ("rr-42" works too), or null. */
|
|
2723
|
+
function findByKey(data, text) {
|
|
2724
|
+
const m = KEY_TEXT.exec(text.trim());
|
|
2725
|
+
if (!m) return null;
|
|
2726
|
+
const project = data.projects.find((p) => p.key === m[1].toUpperCase());
|
|
2727
|
+
if (!project) return null;
|
|
2728
|
+
const n = Number(m[2]);
|
|
2729
|
+
return data.tasks.find((t) => t.projectId === project.id && t.number === n) ?? null;
|
|
2730
|
+
}
|
|
2731
|
+
var MAX_KEY, KEY, made, kept, KEY_TEXT;
|
|
2732
|
+
var init_task_keys = __esmMin((() => {
|
|
2733
|
+
init_indexes();
|
|
2734
|
+
MAX_KEY = 5;
|
|
2735
|
+
KEY = /^[A-Z][A-Z0-9]{0,9}$/;
|
|
2736
|
+
made = (a, b) => a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
2737
|
+
kept = (t, stored) => {
|
|
2738
|
+
const was = stored?.get(t.id);
|
|
2739
|
+
return !!was && was.number === t.number && was.projectId === t.projectId;
|
|
2740
|
+
};
|
|
2741
|
+
KEY_TEXT = /^([A-Za-z][A-Za-z0-9]{0,9})-(\d{1,7})$/;
|
|
2742
|
+
}));
|
|
2743
|
+
|
|
2711
2744
|
// src/lib/first-voyage.ts
|
|
2712
2745
|
function isVoyageProject(projectId) {
|
|
2713
2746
|
return projectId === VOYAGE_PROJECT_ID;
|
|
@@ -4560,7 +4593,7 @@ const ZOOMS = [
|
|
|
4560
4593
|
const day$6 = (iso) => /* @__PURE__ */ new Date(`${iso.slice(0, 10)}T12:00:00`);
|
|
4561
4594
|
/** Names in the order people expect: "Phase 2" before "Phase 10". */
|
|
4562
4595
|
const byName = (a, b) => a.localeCompare(b, void 0, { numeric: true });
|
|
4563
|
-
const isoDay$
|
|
4596
|
+
const isoDay$4 = (d) => format(d, "yyyy-MM-dd");
|
|
4564
4597
|
/**
|
|
4565
4598
|
* Whole months, opening a month before today so what just happened stays in
|
|
4566
4599
|
* view; `shift` pages earlier (negative) or later by the zoom's step.
|
|
@@ -4574,15 +4607,15 @@ function roadmapWindow(zoom, today, shift = 0) {
|
|
|
4574
4607
|
const m = addMonths$1(first, i);
|
|
4575
4608
|
const next = addMonths$1(first, i + 1);
|
|
4576
4609
|
return {
|
|
4577
|
-
start: isoDay$
|
|
4610
|
+
start: isoDay$4(m),
|
|
4578
4611
|
label: format(m, i === 0 || m.getMonth() === 0 ? "MMM yyyy" : "MMM"),
|
|
4579
4612
|
left: differenceInCalendarDays(m, first) / days,
|
|
4580
4613
|
width: differenceInCalendarDays(next, m) / days
|
|
4581
4614
|
};
|
|
4582
4615
|
});
|
|
4583
4616
|
return {
|
|
4584
|
-
start: isoDay$
|
|
4585
|
-
end: isoDay$
|
|
4617
|
+
start: isoDay$4(first),
|
|
4618
|
+
end: isoDay$4(after),
|
|
4586
4619
|
days,
|
|
4587
4620
|
months
|
|
4588
4621
|
};
|
|
@@ -4597,7 +4630,7 @@ function at(iso, w) {
|
|
|
4597
4630
|
function span$1(start, end, w) {
|
|
4598
4631
|
if (!start || !end || end < w.start || start >= w.end) return null;
|
|
4599
4632
|
const from = start < w.start ? w.start : start;
|
|
4600
|
-
const until = end >= w.end ? w.end : isoDay$
|
|
4633
|
+
const until = end >= w.end ? w.end : isoDay$4(new Date(day$6(end).getTime() + 864e5));
|
|
4601
4634
|
const left = differenceInCalendarDays(day$6(from), day$6(w.start)) / w.days;
|
|
4602
4635
|
const right = differenceInCalendarDays(day$6(until), day$6(w.start)) / w.days;
|
|
4603
4636
|
return {
|
|
@@ -8301,7 +8334,7 @@ function planSetAt(project, tasks) {
|
|
|
8301
8334
|
for (const t of tasks) if (!first || t.createdAt < first) first = t.createdAt;
|
|
8302
8335
|
first = (first ?? project.startDate).slice(0, 10);
|
|
8303
8336
|
return {
|
|
8304
|
-
since: `${isoDay$
|
|
8337
|
+
since: `${isoDay$3(addDays(noon$2(first), 7))}T00:00:00`,
|
|
8305
8338
|
from: "start"
|
|
8306
8339
|
};
|
|
8307
8340
|
}
|
|
@@ -8313,7 +8346,7 @@ function planSetAt(project, tasks) {
|
|
|
8313
8346
|
function barnaclesOf(project, tasks, people, now, slip = null) {
|
|
8314
8347
|
const { since, from } = planSetAt(project, tasks);
|
|
8315
8348
|
const today = todayISO(now);
|
|
8316
|
-
const weekAgo = isoDay$
|
|
8349
|
+
const weekAgo = isoDay$3(addDays(noon$2(today), -7));
|
|
8317
8350
|
let planned = 0;
|
|
8318
8351
|
const added = [];
|
|
8319
8352
|
for (const t of tasks) if (t.createdAt > since) added.push(t);
|
|
@@ -8321,7 +8354,7 @@ function barnaclesOf(project, tasks, people, now, slip = null) {
|
|
|
8321
8354
|
const first = startOfWeek(noon$2(since), { weekStartsOn: 1 });
|
|
8322
8355
|
const span = Math.max(0, Math.floor(differenceInCalendarDays(noon$2(today), first) / 7));
|
|
8323
8356
|
const weeks = Array.from({ length: Math.min(span + 1, 104) }, (_, i) => ({
|
|
8324
|
-
week: isoDay$
|
|
8357
|
+
week: isoDay$3(addDays(first, i * 7)),
|
|
8325
8358
|
added: 0
|
|
8326
8359
|
}));
|
|
8327
8360
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -8405,7 +8438,7 @@ function barnaclesShort(b) {
|
|
|
8405
8438
|
function briefWorthy(b) {
|
|
8406
8439
|
return b.from === "baseline" && !b.caveat && b.added >= 3 && (b.share == null || b.share >= .15);
|
|
8407
8440
|
}
|
|
8408
|
-
var SETTLE_DAYS, THIN_PLANNED, THIN_WEEKS, BULK_SHARE, BULK_MIN, BRIEF_MIN_ADDED, BRIEF_MIN_SHARE, noon$2, isoDay$
|
|
8441
|
+
var SETTLE_DAYS, THIN_PLANNED, THIN_WEEKS, BULK_SHARE, BULK_MIN, BRIEF_MIN_ADDED, BRIEF_MIN_SHARE, noon$2, isoDay$3, plural$8;
|
|
8409
8442
|
var init_barnacles = __esmMin((() => {
|
|
8410
8443
|
init_date_fns();
|
|
8411
8444
|
init_format();
|
|
@@ -8418,7 +8451,7 @@ var init_barnacles = __esmMin((() => {
|
|
|
8418
8451
|
BRIEF_MIN_ADDED = 3;
|
|
8419
8452
|
BRIEF_MIN_SHARE = .15;
|
|
8420
8453
|
noon$2 = (iso) => /* @__PURE__ */ new Date(`${iso.slice(0, 10)}T12:00:00`);
|
|
8421
|
-
isoDay$
|
|
8454
|
+
isoDay$3 = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
8422
8455
|
plural$8 = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
8423
8456
|
}));
|
|
8424
8457
|
|
|
@@ -8945,7 +8978,7 @@ function windFor(late) {
|
|
|
8945
8978
|
function capital(s) {
|
|
8946
8979
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
8947
8980
|
}
|
|
8948
|
-
function list$
|
|
8981
|
+
function list$3(names) {
|
|
8949
8982
|
if (names.length <= 1) return names.join("");
|
|
8950
8983
|
return `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
|
|
8951
8984
|
}
|
|
@@ -8961,7 +8994,7 @@ function shippingForecast(data, opts) {
|
|
|
8961
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));
|
|
8962
8995
|
const opening = `And now the harbor forecast for ${opts.harborName?.trim() || "Harbor"}, issued at ${issuedAt(now)} on ${format(now, "EEEE d MMMM")}.`;
|
|
8963
8996
|
const gales = areas.filter((a) => a.health === "off-track").map((a) => a.name);
|
|
8964
|
-
const warnings = gales.length ? `There are warnings of gales in ${list$
|
|
8997
|
+
const warnings = gales.length ? `There are warnings of gales in ${list$3(gales)}.` : null;
|
|
8965
8998
|
const projectIds = new Set(data.projects.filter((p) => programs.some((g) => g.id === p.programId)).map((p) => p.id));
|
|
8966
8999
|
const tasks = data.tasks.filter((t) => projectIds.has(t.projectId));
|
|
8967
9000
|
const weekAgo = todayISO(subDays(now, 6));
|
|
@@ -8976,9 +9009,9 @@ function shippingForecast(data, opts) {
|
|
|
8976
9009
|
coda.push(`${capital(count$1(rest.length, "more area"))}, ${fair ? "fair, visibility good" : "mixed"}.`);
|
|
8977
9010
|
}
|
|
8978
9011
|
const port = programs.filter((p) => p.health === "done").map((p) => p.name);
|
|
8979
|
-
if (port.length) coda.push(`In port: ${list$
|
|
9012
|
+
if (port.length) coda.push(`In port: ${list$3(port)}.`);
|
|
8980
9013
|
const anchor = programs.filter((p) => p.health === "paused").map((p) => p.name);
|
|
8981
|
-
if (anchor.length) coda.push(`At anchor: ${list$
|
|
9014
|
+
if (anchor.length) coda.push(`At anchor: ${list$3(anchor)}.`);
|
|
8982
9015
|
const closing = areas.length || coda.length ? "That ends the harbor forecast." : "No programs at sea. That ends the harbor forecast.";
|
|
8983
9016
|
return {
|
|
8984
9017
|
opening,
|
|
@@ -12922,14 +12955,14 @@ const CREATED = {
|
|
|
12922
12955
|
decision: "recorded decision",
|
|
12923
12956
|
hold: "named what's holding it back:"
|
|
12924
12957
|
};
|
|
12925
|
-
const whole = new Intl.NumberFormat("en-US", {
|
|
12958
|
+
const whole$1 = new Intl.NumberFormat("en-US", {
|
|
12926
12959
|
style: "currency",
|
|
12927
12960
|
currency: "USD",
|
|
12928
12961
|
maximumFractionDigits: 0
|
|
12929
12962
|
});
|
|
12930
12963
|
function dollars(value) {
|
|
12931
12964
|
const n = Number(value ?? 0);
|
|
12932
|
-
return whole.format(Number.isFinite(n) ? n : 0);
|
|
12965
|
+
return whole$1.format(Number.isFinite(n) ? n : 0);
|
|
12933
12966
|
}
|
|
12934
12967
|
function day$3(value) {
|
|
12935
12968
|
return value ? shortDate(value) : "no date";
|
|
@@ -14002,8 +14035,8 @@ function inboxOf(data, personId, now = clockNow()) {
|
|
|
14002
14035
|
pings.push({
|
|
14003
14036
|
id: `task-approve:${task.id}:${shortHash(a.askedAt)}`,
|
|
14004
14037
|
kind: "approval",
|
|
14005
|
-
title: `${by ? firstName$3(by.name) : "Someone"} asked for your approval`,
|
|
14006
|
-
detail: `${where} · approve it, or ask for changes`,
|
|
14038
|
+
title: by?.kind === "agent" ? `${firstName$3(by.name)} handed in work for you to check` : `${by ? firstName$3(by.name) : "Someone"} asked for your approval`,
|
|
14039
|
+
detail: `${where} · approve it, or ${by?.kind === "agent" ? "send it back with a note" : "ask for changes"}`,
|
|
14007
14040
|
at: a.askedAt,
|
|
14008
14041
|
taskId: task.id,
|
|
14009
14042
|
personId: a.askedById,
|
|
@@ -14416,7 +14449,7 @@ function noTakerReason(data, fromId, today) {
|
|
|
14416
14449
|
function suggestTakers(data, fromId, items, now, today) {
|
|
14417
14450
|
const people = takers(data, fromId, today);
|
|
14418
14451
|
const ids = new Set(people.map((p) => p.id));
|
|
14419
|
-
const weekEnd = isoDay$
|
|
14452
|
+
const weekEnd = isoDay$2(addDays(startOfWeek(now, { weekStartsOn: 1 }), 6));
|
|
14420
14453
|
const room = new Map(people.map((p) => [p.id, p.weeklyCapacity ?? 5]));
|
|
14421
14454
|
const inProject = /* @__PURE__ */ new Map();
|
|
14422
14455
|
for (const t of data.tasks) {
|
|
@@ -14482,7 +14515,7 @@ function roomLabel(room) {
|
|
|
14482
14515
|
if (room <= 0) return "full this week";
|
|
14483
14516
|
return null;
|
|
14484
14517
|
}
|
|
14485
|
-
function isoDay$
|
|
14518
|
+
function isoDay$2(d) {
|
|
14486
14519
|
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
14487
14520
|
const day = String(d.getDate()).padStart(2, "0");
|
|
14488
14521
|
return `${d.getFullYear()}-${m}-${day}`;
|
|
@@ -14563,7 +14596,7 @@ init_handover();
|
|
|
14563
14596
|
const SOON_DAYS = 21;
|
|
14564
14597
|
/** This many open tasks in one project that only one person has touched read as their corner of it. */
|
|
14565
14598
|
const CLUSTER = 4;
|
|
14566
|
-
const isoDay = (d) => d.toISOString().slice(0, 10);
|
|
14599
|
+
const isoDay$1 = (d) => d.toISOString().slice(0, 10);
|
|
14567
14600
|
const md = (iso) => format(parseIso(iso), "MMM d");
|
|
14568
14601
|
/** Everyone a task has passed through. */
|
|
14569
14602
|
function taskHands(task, commentsBy, attachedBy) {
|
|
@@ -14598,8 +14631,8 @@ function byTask(rows, who) {
|
|
|
14598
14631
|
const plural$5 = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
14599
14632
|
/** Work only one person has touched, soonest-needed first. `scope` narrows it to some programs. */
|
|
14600
14633
|
function lifeboats(data, now, opts = {}) {
|
|
14601
|
-
const today = isoDay(now);
|
|
14602
|
-
const soon = isoDay(addDays(now, SOON_DAYS));
|
|
14634
|
+
const today = isoDay$1(now);
|
|
14635
|
+
const soon = isoDay$1(addDays(now, SOON_DAYS));
|
|
14603
14636
|
const people = byId(data.people);
|
|
14604
14637
|
const projects = byId(data.projects);
|
|
14605
14638
|
const programs = byId(data.programs);
|
|
@@ -14728,8 +14761,8 @@ function lifeboats(data, now, opts = {}) {
|
|
|
14728
14761
|
}
|
|
14729
14762
|
/** Who could be a second pair of hands: room this week, and already working nearby. */
|
|
14730
14763
|
function withSuggestions(data, lines, now) {
|
|
14731
|
-
const today = isoDay(now);
|
|
14732
|
-
const weekEnd = isoDay(addDays(startOfWeek(now, { weekStartsOn: 1 }), 6));
|
|
14764
|
+
const today = isoDay$1(now);
|
|
14765
|
+
const weekEnd = isoDay$1(addDays(startOfWeek(now, { weekStartsOn: 1 }), 6));
|
|
14733
14766
|
const people = data.people.filter((p) => p.kind !== "agent" && !isAway(p, today));
|
|
14734
14767
|
const room = new Map(people.map((p) => [p.id, p.weeklyCapacity ?? 5]));
|
|
14735
14768
|
const inProject = /* @__PURE__ */ new Map();
|
|
@@ -17659,7 +17692,7 @@ init_indexes();
|
|
|
17659
17692
|
init_load();
|
|
17660
17693
|
init_task_keys();
|
|
17661
17694
|
init_tide();
|
|
17662
|
-
const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
17695
|
+
const ISO_DAY$1 = /^\d{4}-\d{2}-\d{2}$/;
|
|
17663
17696
|
const MAX_ADD = 200;
|
|
17664
17697
|
/**
|
|
17665
17698
|
* The changes a saved dry dock holds, read tolerantly: it travels in the
|
|
@@ -17690,7 +17723,7 @@ function readDock(raw) {
|
|
|
17690
17723
|
break;
|
|
17691
17724
|
}
|
|
17692
17725
|
case "due":
|
|
17693
|
-
if (str("taskId") && (r.dueDate === null || ISO_DAY.test(str("dueDate") ?? ""))) out.push({
|
|
17726
|
+
if (str("taskId") && (r.dueDate === null || ISO_DAY$1.test(str("dueDate") ?? ""))) out.push({
|
|
17694
17727
|
kind: "due",
|
|
17695
17728
|
taskId: str("taskId"),
|
|
17696
17729
|
dueDate: str("dueDate")
|
|
@@ -17704,7 +17737,7 @@ function readDock(raw) {
|
|
|
17704
17737
|
});
|
|
17705
17738
|
break;
|
|
17706
17739
|
case "end":
|
|
17707
|
-
if (ISO_DAY.test(str("endDate") ?? "")) out.push({
|
|
17740
|
+
if (ISO_DAY$1.test(str("endDate") ?? "")) out.push({
|
|
17708
17741
|
kind: "end",
|
|
17709
17742
|
endDate: str("endDate")
|
|
17710
17743
|
});
|
|
@@ -18374,25 +18407,611 @@ function kindredProjects(data, project) {
|
|
|
18374
18407
|
at: done ?? p.endDate
|
|
18375
18408
|
});
|
|
18376
18409
|
}
|
|
18377
|
-
return scored.sort((a, b) => b.score - a.score || b.at.localeCompare(a.at)).map((s) => s.p);
|
|
18410
|
+
return scored.sort((a, b) => b.score - a.score || b.at.localeCompare(a.at)).map((s) => s.p);
|
|
18411
|
+
}
|
|
18412
|
+
/**
|
|
18413
|
+
* What the old salts say to this project: lessons from the finished projects
|
|
18414
|
+
* it looks like, leaving out any put away (or already taken) here. Nothing
|
|
18415
|
+
* for a finished project.
|
|
18416
|
+
*/
|
|
18417
|
+
function oldSalts(data, project) {
|
|
18418
|
+
if (project.health === "done" || isVoyageProject(project.id)) return [];
|
|
18419
|
+
const heard = new Set(project.saltsHeard ?? []);
|
|
18420
|
+
const out = [];
|
|
18421
|
+
let sources = 0;
|
|
18422
|
+
for (const p of kindredProjects(data, project).slice(0, 10)) {
|
|
18423
|
+
const fresh = lessonsOf(p, data).filter((l) => !heard.has(l.id));
|
|
18424
|
+
if (fresh.length === 0) continue;
|
|
18425
|
+
out.push(...fresh);
|
|
18426
|
+
if (++sources >= SOURCES) break;
|
|
18427
|
+
}
|
|
18428
|
+
return out.slice(0, 3);
|
|
18429
|
+
}
|
|
18430
|
+
|
|
18431
|
+
// src/lib/assignment.ts
|
|
18432
|
+
/**
|
|
18433
|
+
* Record who set a task's assignee and when. Only a change of assignee
|
|
18434
|
+
* stamps; clearing the assignee clears the stamp.
|
|
18435
|
+
*/
|
|
18436
|
+
function stampAssignment(before, next, by, at) {
|
|
18437
|
+
if (before && before.assigneeId === next.assigneeId) return next;
|
|
18438
|
+
if (!next.assigneeId) return {
|
|
18439
|
+
...next,
|
|
18440
|
+
assignedBy: null,
|
|
18441
|
+
assignedAt: null
|
|
18442
|
+
};
|
|
18443
|
+
return {
|
|
18444
|
+
...next,
|
|
18445
|
+
assignedBy: by,
|
|
18446
|
+
assignedAt: at
|
|
18447
|
+
};
|
|
18448
|
+
}
|
|
18449
|
+
var init_assignment = __esmMin((() => {}));
|
|
18450
|
+
|
|
18451
|
+
// src/lib/scuttle-rows.ts
|
|
18452
|
+
/** Whether it's scuttled: closed through Scuttle or sail and not raised since. */
|
|
18453
|
+
function isScuttled(project) {
|
|
18454
|
+
return Boolean(project.scuttled) && project.healthOverride === "done";
|
|
18455
|
+
}
|
|
18456
|
+
/**
|
|
18457
|
+
* Scuttle a project: Done by hand with the reason as its note, its open
|
|
18458
|
+
* tasks unassigned and undated (kept in `scuttled.freed`), and a decision on
|
|
18459
|
+
* the register. Null for a project that's already scuttled or gone, or a
|
|
18460
|
+
* blank why.
|
|
18461
|
+
*/
|
|
18462
|
+
function scuttleRows(data, projectId, why, byId, at, decisionId, context = "Closed through Scuttle or sail.") {
|
|
18463
|
+
const project = data.projects.find((p) => p.id === projectId);
|
|
18464
|
+
const reason = why.trim().slice(0, 600);
|
|
18465
|
+
if (!project || !reason || isScuttled(project)) return null;
|
|
18466
|
+
const freed = [];
|
|
18467
|
+
const tasks = [];
|
|
18468
|
+
for (const t of tasksOf(data.tasks, projectId)) {
|
|
18469
|
+
if (t.status === "done" || !t.assigneeId && !t.dueDate) continue;
|
|
18470
|
+
freed.push({
|
|
18471
|
+
taskId: t.id,
|
|
18472
|
+
assigneeId: t.assigneeId,
|
|
18473
|
+
dueDate: t.dueDate
|
|
18474
|
+
});
|
|
18475
|
+
tasks.push(stampAssignment(t, {
|
|
18476
|
+
...t,
|
|
18477
|
+
assigneeId: null,
|
|
18478
|
+
dueDate: null,
|
|
18479
|
+
touchedAt: at
|
|
18480
|
+
}, byId, at));
|
|
18481
|
+
}
|
|
18482
|
+
const decision = normalizeRaidItem({
|
|
18483
|
+
id: decisionId,
|
|
18484
|
+
kind: "decision",
|
|
18485
|
+
projectId,
|
|
18486
|
+
title: `Scuttle ${project.name}`,
|
|
18487
|
+
description: context,
|
|
18488
|
+
status: "decided",
|
|
18489
|
+
severity: "low",
|
|
18490
|
+
ownerId: byId,
|
|
18491
|
+
dueDate: null,
|
|
18492
|
+
resolution: "Stop the project. Its open tasks come off people’s lists.",
|
|
18493
|
+
rationale: reason,
|
|
18494
|
+
decidedById: byId,
|
|
18495
|
+
decidedAt: at,
|
|
18496
|
+
createdById: byId,
|
|
18497
|
+
createdAt: at,
|
|
18498
|
+
updatedAt: at,
|
|
18499
|
+
updates: []
|
|
18500
|
+
});
|
|
18501
|
+
return {
|
|
18502
|
+
project: {
|
|
18503
|
+
...project,
|
|
18504
|
+
health: "done",
|
|
18505
|
+
healthOverride: "done",
|
|
18506
|
+
healthNote: `Scuttled: ${reason}`,
|
|
18507
|
+
scuttled: {
|
|
18508
|
+
at,
|
|
18509
|
+
byId,
|
|
18510
|
+
why: reason,
|
|
18511
|
+
decisionId,
|
|
18512
|
+
freed
|
|
18513
|
+
}
|
|
18514
|
+
},
|
|
18515
|
+
tasks,
|
|
18516
|
+
decision
|
|
18517
|
+
};
|
|
18518
|
+
}
|
|
18519
|
+
/**
|
|
18520
|
+
* Raise a scuttled project: the scuttle cleared (the caller clears its Done), and each
|
|
18521
|
+
* freed task given back its person and date, unless someone has since given
|
|
18522
|
+
* it others, it's done, or the person has left the crew. Null when it isn't
|
|
18523
|
+
* scuttled.
|
|
18524
|
+
*/
|
|
18525
|
+
function raiseRows(data, projectId, at, byId) {
|
|
18526
|
+
const project = data.projects.find((p) => p.id === projectId);
|
|
18527
|
+
if (!project?.scuttled) return null;
|
|
18528
|
+
const people = new Set(data.people.map((p) => p.id));
|
|
18529
|
+
const byTask = new Map(project.scuttled.freed.map((f) => [f.taskId, f]));
|
|
18530
|
+
const tasks = [];
|
|
18531
|
+
for (const t of tasksOf(data.tasks, projectId)) {
|
|
18532
|
+
const f = byTask.get(t.id);
|
|
18533
|
+
if (!f || t.status === "done") continue;
|
|
18534
|
+
const assigneeId = !t.assigneeId && f.assigneeId && people.has(f.assigneeId) ? f.assigneeId : t.assigneeId;
|
|
18535
|
+
const dueDate = t.dueDate ?? f.dueDate;
|
|
18536
|
+
if (assigneeId === t.assigneeId && dueDate === t.dueDate) continue;
|
|
18537
|
+
tasks.push(stampAssignment(t, {
|
|
18538
|
+
...t,
|
|
18539
|
+
assigneeId,
|
|
18540
|
+
dueDate,
|
|
18541
|
+
touchedAt: at
|
|
18542
|
+
}, byId, at));
|
|
18543
|
+
}
|
|
18544
|
+
return {
|
|
18545
|
+
project: {
|
|
18546
|
+
...project,
|
|
18547
|
+
scuttled: null,
|
|
18548
|
+
voyageCall: {
|
|
18549
|
+
call: "sail",
|
|
18550
|
+
at,
|
|
18551
|
+
byId
|
|
18552
|
+
}
|
|
18553
|
+
},
|
|
18554
|
+
tasks
|
|
18555
|
+
};
|
|
18556
|
+
}
|
|
18557
|
+
var WHY_MAX;
|
|
18558
|
+
var init_scuttle_rows = __esmMin((() => {
|
|
18559
|
+
init_assignment();
|
|
18560
|
+
init_indexes();
|
|
18561
|
+
init_raid();
|
|
18562
|
+
WHY_MAX = 600;
|
|
18563
|
+
}));
|
|
18564
|
+
|
|
18565
|
+
// src/lib/sea-trial.ts
|
|
18566
|
+
init_date_fns();
|
|
18567
|
+
init_first_voyage();
|
|
18568
|
+
init_format();
|
|
18569
|
+
init_indexes();
|
|
18570
|
+
init_scuttle_rows();
|
|
18571
|
+
init_tide();
|
|
18572
|
+
const TRIAL_MAX_CHANGES = 30;
|
|
18573
|
+
const TRIAL_MAX_TASKS = 200;
|
|
18574
|
+
const TRIAL_MAX_WEEKS = 104;
|
|
18575
|
+
const TRIAL_MAX_CREW = 20;
|
|
18576
|
+
const NAME_MAX = 120;
|
|
18577
|
+
const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
18578
|
+
const whole = (v, min, max) => {
|
|
18579
|
+
const n = Math.round(Number(v));
|
|
18580
|
+
return Number.isFinite(n) && n >= min ? Math.min(max, n) : null;
|
|
18581
|
+
};
|
|
18582
|
+
/**
|
|
18583
|
+
* The changes a saved sea trial holds, read tolerantly: it travels in the
|
|
18584
|
+
* document, so anything that isn't a change Harbor knows is left out.
|
|
18585
|
+
*/
|
|
18586
|
+
function readTrial(raw) {
|
|
18587
|
+
if (!Array.isArray(raw)) return [];
|
|
18588
|
+
const out = [];
|
|
18589
|
+
for (const c of raw) {
|
|
18590
|
+
if (out.length >= 30) break;
|
|
18591
|
+
if (!c || typeof c !== "object") continue;
|
|
18592
|
+
const r = c;
|
|
18593
|
+
const str = (k) => typeof r[k] === "string" && r[k] ? r[k] : null;
|
|
18594
|
+
switch (r.kind) {
|
|
18595
|
+
case "start": {
|
|
18596
|
+
const name = str("name")?.trim().slice(0, NAME_MAX);
|
|
18597
|
+
const programId = str("programId");
|
|
18598
|
+
const tasks = whole(r.tasks, 1, 200);
|
|
18599
|
+
const weeks = whole(r.weeks, 1, 104);
|
|
18600
|
+
const crewIds = Array.isArray(r.crewIds) ? [...new Set(r.crewIds.filter((id) => typeof id === "string" && !!id))] : [];
|
|
18601
|
+
if (name && programId && tasks && weeks) out.push({
|
|
18602
|
+
kind: "start",
|
|
18603
|
+
name,
|
|
18604
|
+
programId,
|
|
18605
|
+
tasks,
|
|
18606
|
+
weeks,
|
|
18607
|
+
crewIds: crewIds.slice(0, 20)
|
|
18608
|
+
});
|
|
18609
|
+
break;
|
|
18610
|
+
}
|
|
18611
|
+
case "pause":
|
|
18612
|
+
case "stop":
|
|
18613
|
+
if (str("projectId")) out.push({
|
|
18614
|
+
kind: r.kind,
|
|
18615
|
+
projectId: str("projectId")
|
|
18616
|
+
});
|
|
18617
|
+
break;
|
|
18618
|
+
case "move": {
|
|
18619
|
+
const days = whole(r.days, 1, 5);
|
|
18620
|
+
const personId = str("personId");
|
|
18621
|
+
const from = str("fromProjectId");
|
|
18622
|
+
const to = str("toProjectId");
|
|
18623
|
+
if (personId && from && to && from !== to && days) out.push({
|
|
18624
|
+
kind: "move",
|
|
18625
|
+
personId,
|
|
18626
|
+
fromProjectId: from,
|
|
18627
|
+
toProjectId: to,
|
|
18628
|
+
days
|
|
18629
|
+
});
|
|
18630
|
+
break;
|
|
18631
|
+
}
|
|
18632
|
+
case "end": {
|
|
18633
|
+
const endDate = str("endDate");
|
|
18634
|
+
if (str("projectId") && endDate && ISO_DAY.test(endDate)) out.push({
|
|
18635
|
+
kind: "end",
|
|
18636
|
+
projectId: str("projectId"),
|
|
18637
|
+
endDate
|
|
18638
|
+
});
|
|
18639
|
+
break;
|
|
18640
|
+
}
|
|
18641
|
+
}
|
|
18642
|
+
}
|
|
18643
|
+
return out;
|
|
18644
|
+
}
|
|
18645
|
+
/** The projects a portfolio's sea trial can touch: its own, open ones (First voyage is practice). */
|
|
18646
|
+
function trialProjects(data, portfolioId) {
|
|
18647
|
+
const programs = new Set(data.programs.filter((p) => p.portfolioId === portfolioId).map((p) => p.id));
|
|
18648
|
+
return ownProjects(data.projects).filter((p) => programs.has(p.programId) && p.health !== "done");
|
|
18649
|
+
}
|
|
18650
|
+
/** The id a started project carries on the copy: its place among the changes. */
|
|
18651
|
+
const trialProjectId = (index) => `trial-${index}`;
|
|
18652
|
+
const isoDay = (d) => todayISO(d);
|
|
18653
|
+
/** The portfolio as it would be with the changes, on a copy. */
|
|
18654
|
+
function trialPlan(data, portfolioId, changes, now) {
|
|
18655
|
+
if (!data.portfolios.some((p) => p.id === portfolioId)) return null;
|
|
18656
|
+
const open = new Map(trialProjects(data, portfolioId).map((p) => [p.id, p]));
|
|
18657
|
+
const programs = new Map(data.programs.filter((p) => p.portfolioId === portfolioId).map((p) => [p.id, p]));
|
|
18658
|
+
const people = byId(data.people);
|
|
18659
|
+
const today = isoDay(now);
|
|
18660
|
+
const at = now.toISOString();
|
|
18661
|
+
const projects = /* @__PURE__ */ new Map();
|
|
18662
|
+
/** Per project, the tasks that replace its real ones. */
|
|
18663
|
+
const swapped = /* @__PURE__ */ new Map();
|
|
18664
|
+
const added = [];
|
|
18665
|
+
const startedProjects = [];
|
|
18666
|
+
const dock = /* @__PURE__ */ new Map();
|
|
18667
|
+
const touched = [];
|
|
18668
|
+
const started = /* @__PURE__ */ new Set();
|
|
18669
|
+
const touchedPeople = /* @__PURE__ */ new Set();
|
|
18670
|
+
const stale = [];
|
|
18671
|
+
/** A project stopped or paused earlier in the list can't take a later move. */
|
|
18672
|
+
const closed = /* @__PURE__ */ new Set();
|
|
18673
|
+
const touch = (id) => {
|
|
18674
|
+
if (!touched.includes(id)) touched.push(id);
|
|
18675
|
+
};
|
|
18676
|
+
const tasksNow = (id) => swapped.get(id) ?? tasksOf(data.tasks, id);
|
|
18677
|
+
const projectNow = (id) => projects.get(id) ?? open.get(id);
|
|
18678
|
+
changes.forEach((c, i) => {
|
|
18679
|
+
switch (c.kind) {
|
|
18680
|
+
case "start": {
|
|
18681
|
+
const program = programs.get(c.programId);
|
|
18682
|
+
const crew = c.crewIds.filter((id) => people.has(id));
|
|
18683
|
+
if (!program || crew.length !== c.crewIds.length) {
|
|
18684
|
+
stale.push(c);
|
|
18685
|
+
break;
|
|
18686
|
+
}
|
|
18687
|
+
const id = trialProjectId(i);
|
|
18688
|
+
startedProjects.push(startedProject(id, c, program, today));
|
|
18689
|
+
const span = c.weeks * 7;
|
|
18690
|
+
for (let n = 1; n <= c.tasks; n++) {
|
|
18691
|
+
const assigneeId = crew.length ? crew[(n - 1) % crew.length] : null;
|
|
18692
|
+
added.push({
|
|
18693
|
+
id: `${id}-${n}`,
|
|
18694
|
+
projectId: id,
|
|
18695
|
+
title: startTaskTitle(c.name, n),
|
|
18696
|
+
description: "",
|
|
18697
|
+
status: "todo",
|
|
18698
|
+
priority: "medium",
|
|
18699
|
+
assigneeId,
|
|
18700
|
+
dueDate: isoDay(addDays(/* @__PURE__ */ new Date(`${today}T12:00:00`), Math.ceil(n * span / c.tasks))),
|
|
18701
|
+
createdAt: at,
|
|
18702
|
+
completedAt: null,
|
|
18703
|
+
checklist: [],
|
|
18704
|
+
blockedById: null
|
|
18705
|
+
});
|
|
18706
|
+
}
|
|
18707
|
+
for (const p of crew) touchedPeople.add(p);
|
|
18708
|
+
started.add(id);
|
|
18709
|
+
touch(id);
|
|
18710
|
+
break;
|
|
18711
|
+
}
|
|
18712
|
+
case "pause":
|
|
18713
|
+
if (!open.has(c.projectId) || closed.has(c.projectId) || open.get(c.projectId).health === "paused") {
|
|
18714
|
+
stale.push(c);
|
|
18715
|
+
break;
|
|
18716
|
+
}
|
|
18717
|
+
projects.set(c.projectId, {
|
|
18718
|
+
...projectNow(c.projectId),
|
|
18719
|
+
health: "paused"
|
|
18720
|
+
});
|
|
18721
|
+
closed.add(c.projectId);
|
|
18722
|
+
touch(c.projectId);
|
|
18723
|
+
break;
|
|
18724
|
+
case "stop": {
|
|
18725
|
+
if (!open.has(c.projectId) || closed.has(c.projectId)) {
|
|
18726
|
+
stale.push(c);
|
|
18727
|
+
break;
|
|
18728
|
+
}
|
|
18729
|
+
const rows = scuttleRows({
|
|
18730
|
+
projects: [projectNow(c.projectId)],
|
|
18731
|
+
tasks: [...tasksNow(c.projectId)]
|
|
18732
|
+
}, c.projectId, STOP_WHY, "", at, "");
|
|
18733
|
+
if (!rows) {
|
|
18734
|
+
stale.push(c);
|
|
18735
|
+
break;
|
|
18736
|
+
}
|
|
18737
|
+
const freed = new Map(rows.tasks.map((t) => [t.id, t]));
|
|
18738
|
+
for (const t of tasksNow(c.projectId)) if (freed.has(t.id) && t.assigneeId) touchedPeople.add(t.assigneeId);
|
|
18739
|
+
swapped.set(c.projectId, tasksNow(c.projectId).map((t) => freed.get(t.id) ?? t));
|
|
18740
|
+
projects.set(c.projectId, rows.project);
|
|
18741
|
+
closed.add(c.projectId);
|
|
18742
|
+
touch(c.projectId);
|
|
18743
|
+
break;
|
|
18744
|
+
}
|
|
18745
|
+
case "move": {
|
|
18746
|
+
if (!people.has(c.personId) || !open.has(c.fromProjectId) || !open.has(c.toProjectId) || closed.has(c.fromProjectId) || closed.has(c.toProjectId)) {
|
|
18747
|
+
stale.push(c);
|
|
18748
|
+
break;
|
|
18749
|
+
}
|
|
18750
|
+
swapped.set(c.fromProjectId, tasksNow(c.fromProjectId).map((t) => t.assigneeId === c.personId && t.status !== "done" ? {
|
|
18751
|
+
...t,
|
|
18752
|
+
assigneeId: null
|
|
18753
|
+
} : t));
|
|
18754
|
+
const leaving = dock.get(c.fromProjectId) ?? [];
|
|
18755
|
+
if (!leaving.some((d) => d.kind === "release" && d.personId === c.personId)) dock.set(c.fromProjectId, [...leaving, {
|
|
18756
|
+
kind: "release",
|
|
18757
|
+
personId: c.personId
|
|
18758
|
+
}]);
|
|
18759
|
+
dock.set(c.toProjectId, [...dock.get(c.toProjectId) ?? [], {
|
|
18760
|
+
kind: "borrow",
|
|
18761
|
+
personId: c.personId,
|
|
18762
|
+
days: c.days
|
|
18763
|
+
}]);
|
|
18764
|
+
touchedPeople.add(c.personId);
|
|
18765
|
+
touch(c.fromProjectId);
|
|
18766
|
+
touch(c.toProjectId);
|
|
18767
|
+
break;
|
|
18768
|
+
}
|
|
18769
|
+
case "end":
|
|
18770
|
+
if (!open.has(c.projectId) || closed.has(c.projectId)) {
|
|
18771
|
+
stale.push(c);
|
|
18772
|
+
break;
|
|
18773
|
+
}
|
|
18774
|
+
projects.set(c.projectId, {
|
|
18775
|
+
...projectNow(c.projectId),
|
|
18776
|
+
endDate: c.endDate
|
|
18777
|
+
});
|
|
18778
|
+
touch(c.projectId);
|
|
18779
|
+
}
|
|
18780
|
+
});
|
|
18781
|
+
const pace = /* @__PURE__ */ new Map();
|
|
18782
|
+
for (const [id, list] of dock) pace.set(id, dockPace(open.get(id), tasksOf(data.tasks, id), list, now));
|
|
18783
|
+
const tasks = swapped.size === 0 && added.length === 0 ? data.tasks : [...data.tasks.filter((t) => !swapped.has(t.projectId)), ...swapped.values()].flat();
|
|
18784
|
+
if (added.length) tasks.push(...added);
|
|
18785
|
+
return {
|
|
18786
|
+
projects: projects.size === 0 && startedProjects.length === 0 ? data.projects : [...data.projects.map((p) => projects.get(p.id) ?? p), ...startedProjects],
|
|
18787
|
+
tasks,
|
|
18788
|
+
touched,
|
|
18789
|
+
started,
|
|
18790
|
+
pace,
|
|
18791
|
+
people: touchedPeople,
|
|
18792
|
+
stale
|
|
18793
|
+
};
|
|
18794
|
+
}
|
|
18795
|
+
const STOP_WHY = "Stopped from a what-if plan.";
|
|
18796
|
+
/** "Loyalty relaunch: task 3": a placeholder to rename once the project is real. */
|
|
18797
|
+
function startTaskTitle(name, n) {
|
|
18798
|
+
return `${name}: task ${n}`;
|
|
18799
|
+
}
|
|
18800
|
+
function startedProject(id, c, program, today) {
|
|
18801
|
+
return {
|
|
18802
|
+
id,
|
|
18803
|
+
programId: program.id,
|
|
18804
|
+
name: c.name,
|
|
18805
|
+
description: "",
|
|
18806
|
+
swatch: program.swatch,
|
|
18807
|
+
ownerId: program.ownerId,
|
|
18808
|
+
health: "on-track",
|
|
18809
|
+
startDate: today,
|
|
18810
|
+
endDate: isoDay(addDays(/* @__PURE__ */ new Date(`${today}T12:00:00`), c.weeks * 7)),
|
|
18811
|
+
budget: 0,
|
|
18812
|
+
spent: 0
|
|
18813
|
+
};
|
|
18814
|
+
}
|
|
18815
|
+
const likelyOf = (t) => t && t.kind === "forecast" ? t.likely : null;
|
|
18816
|
+
/** A forecast with no day in it: at this pace it doesn't finish inside two years. */
|
|
18817
|
+
const never$1 = (t) => !!t && t.kind === "forecast" && !t.likely;
|
|
18818
|
+
function finishLine(row) {
|
|
18819
|
+
const t = row.trial;
|
|
18820
|
+
if (row.started) return `Starts today, planned to finish ${shortDate(row.trialEnd)}. No pace to forecast from until its crew finishes some tasks.`;
|
|
18821
|
+
if (t.kind === "paused") return "Paused: no finish date while it rests.";
|
|
18822
|
+
if (t.kind === "done") return row.real?.kind === "done" ? "Nothing left open." : "Stopped: its open work is let go.";
|
|
18823
|
+
if (t.kind === "empty") return "No tasks yet.";
|
|
18824
|
+
if (t.kind === "no-pace") return "No pace to forecast from yet.";
|
|
18825
|
+
if (!t.likely) return "Not likely to finish in two years at this pace.";
|
|
18826
|
+
const was = likelyOf(row.real);
|
|
18827
|
+
const moved = row.shift == null ? was ? "" : "" : row.shift === 0 ? ", the same day as today's plan" : `, ${Math.abs(row.shift)} day${Math.abs(row.shift) === 1 ? "" : "s"} ${row.shift < 0 ? "sooner" : "later"}`;
|
|
18828
|
+
const end = t.likely > row.trialEnd ? ` That is after its end date, ${shortDate(row.trialEnd)}.` : row.trialEnd !== row.realEnd ? ` Its end date would be ${shortDate(row.trialEnd)}.` : "";
|
|
18829
|
+
return `Likely done ${shortDate(t.likely)}${moved}.${end}`;
|
|
18830
|
+
}
|
|
18831
|
+
/** Today's portfolio and the changed one side by side. */
|
|
18832
|
+
function trialCompare(data, portfolioId, changes, now) {
|
|
18833
|
+
const plan = trialPlan(data, portfolioId, changes, now);
|
|
18834
|
+
if (!plan) return null;
|
|
18835
|
+
const opts = tideOptions(data);
|
|
18836
|
+
const realProjects = byId(data.projects);
|
|
18837
|
+
const trialProjectsById = byId(plan.projects);
|
|
18838
|
+
const peopleById = byId(data.people);
|
|
18839
|
+
const projects = plan.touched.map((id) => {
|
|
18840
|
+
const project = trialProjectsById.get(id);
|
|
18841
|
+
const real = realProjects.get(id) ?? null;
|
|
18842
|
+
const started = plan.started.has(id);
|
|
18843
|
+
const pace = plan.pace.get(id) ?? 1;
|
|
18844
|
+
const realTide = real ? tideForecast(real, tasksOf(data.tasks, id), now, opts) : null;
|
|
18845
|
+
const trialTide = tideForecast(project, tasksOf(plan.tasks, id), now, {
|
|
18846
|
+
...opts,
|
|
18847
|
+
pace
|
|
18848
|
+
});
|
|
18849
|
+
const a = likelyOf(realTide);
|
|
18850
|
+
const b = likelyOf(trialTide);
|
|
18851
|
+
const base = {
|
|
18852
|
+
project,
|
|
18853
|
+
started,
|
|
18854
|
+
real: realTide,
|
|
18855
|
+
trial: trialTide,
|
|
18856
|
+
realEnd: real?.endDate ?? null,
|
|
18857
|
+
trialEnd: project.endDate,
|
|
18858
|
+
pace,
|
|
18859
|
+
shift: a && b ? differenceInCalendarDays(/* @__PURE__ */ new Date(`${b}T12:00:00`), /* @__PURE__ */ new Date(`${a}T12:00:00`)) : null
|
|
18860
|
+
};
|
|
18861
|
+
const lateBefore = !!a && !!real && a > real.endDate;
|
|
18862
|
+
const nowLate = !!b && b > project.endDate && !lateBefore || never$1(trialTide) && !never$1(realTide);
|
|
18863
|
+
return {
|
|
18864
|
+
...base,
|
|
18865
|
+
line: finishLine(base),
|
|
18866
|
+
nowLate
|
|
18867
|
+
};
|
|
18868
|
+
});
|
|
18869
|
+
const people = [];
|
|
18870
|
+
for (const id of plan.people) {
|
|
18871
|
+
const person = peopleById.get(id);
|
|
18872
|
+
if (!person) continue;
|
|
18873
|
+
const real = personLoadLine(data, person, now, opts.calendar);
|
|
18874
|
+
const trial = personLoadLine({ tasks: plan.tasks }, person, now, opts.calendar);
|
|
18875
|
+
people.push({
|
|
18876
|
+
person,
|
|
18877
|
+
real,
|
|
18878
|
+
trial,
|
|
18879
|
+
nowOver: !!trial && trial.over > 0 && !(real && real.over > 0)
|
|
18880
|
+
});
|
|
18881
|
+
}
|
|
18882
|
+
people.sort((x, y) => x.person.name.localeCompare(y.person.name));
|
|
18883
|
+
const rowOf = new Map(projects.map((r) => [r.project.id, r]));
|
|
18884
|
+
const goals = trialGoals(data, projects);
|
|
18885
|
+
const convoys = trialConvoys(data, rowOf);
|
|
18886
|
+
const notes = [];
|
|
18887
|
+
if (changes.some((c) => c.kind === "pause" && !plan.stale.includes(c))) notes.push("A paused project keeps its tasks with their owners and their due dates, so pausing by itself frees nobody. Stop it, or move people off it, to see their load change.");
|
|
18888
|
+
if (changes.some((c) => c.kind === "move" && !plan.stale.includes(c))) notes.push("Moving someone changes a crew's pace by their share of what it finished lately. With little finished work to read, the dates move less than you'd expect. Applying it takes their open tasks on the first project off them and, across programs, moves that share of their promised time; giving them tasks on the second is yours to do.");
|
|
18889
|
+
if (plan.started.size > 0) notes.push("A project started here gets placeholder tasks, shared out among its crew and due evenly up to its end date. That is what loads people in this comparison.");
|
|
18890
|
+
const comparison = {
|
|
18891
|
+
projects,
|
|
18892
|
+
people,
|
|
18893
|
+
goals,
|
|
18894
|
+
convoys,
|
|
18895
|
+
stale: plan.stale,
|
|
18896
|
+
notes
|
|
18897
|
+
};
|
|
18898
|
+
return {
|
|
18899
|
+
...comparison,
|
|
18900
|
+
summary: trialSummary(comparison, changes.length - plan.stale.length)
|
|
18901
|
+
};
|
|
18378
18902
|
}
|
|
18379
|
-
|
|
18380
|
-
|
|
18381
|
-
|
|
18382
|
-
|
|
18383
|
-
|
|
18384
|
-
|
|
18385
|
-
|
|
18386
|
-
const
|
|
18903
|
+
function trialGoals(data, rows) {
|
|
18904
|
+
const out = /* @__PURE__ */ new Map();
|
|
18905
|
+
const linked = /* @__PURE__ */ new Map();
|
|
18906
|
+
for (const portfolio of data.portfolios) for (const goal of portfolio.goals ?? []) for (const id of new Set(goal.keyResults.flatMap((k) => k.kind === "work" ? k.linkIds ?? [] : []))) linked.set(id, [...linked.get(id) ?? [], {
|
|
18907
|
+
portfolio,
|
|
18908
|
+
goal
|
|
18909
|
+
}]);
|
|
18910
|
+
const known = /* @__PURE__ */ new Set();
|
|
18911
|
+
for (const p of data.projects) known.add(p.id).add(p.programId);
|
|
18912
|
+
const taskLinked = [...linked.keys()].some((id) => !known.has(id));
|
|
18913
|
+
for (const row of rows) {
|
|
18914
|
+
if (row.started) continue;
|
|
18915
|
+
const p = row.project;
|
|
18916
|
+
const links = /* @__PURE__ */ new Map();
|
|
18917
|
+
for (const id of [p.id, p.programId]) for (const l of linked.get(id) ?? []) links.set(`${l.portfolio.id}:${l.goal.id}`, l);
|
|
18918
|
+
if (taskLinked) {
|
|
18919
|
+
for (const t of tasksOf(data.tasks, p.id)) if (t.status !== "done") for (const l of linked.get(t.id) ?? []) links.set(`${l.portfolio.id}:${l.goal.id}`, l);
|
|
18920
|
+
}
|
|
18921
|
+
for (const link of links.values()) {
|
|
18922
|
+
const { goal } = link;
|
|
18923
|
+
let line = null;
|
|
18924
|
+
const likely = likelyOf(row.trial);
|
|
18925
|
+
const was = likelyOf(row.real);
|
|
18926
|
+
if (row.trial.kind === "done" && row.real?.kind !== "done") line = `${p.name} stops, so its open work no longer moves this goal.`;
|
|
18927
|
+
else if (row.trial.kind === "paused" && row.real?.kind !== "paused") line = `${p.name} is paused, so this goal waits on it.`;
|
|
18928
|
+
else if (never$1(row.trial) && !never$1(row.real)) line = `${p.name} would not finish in two years at that pace, so this goal is at risk.`;
|
|
18929
|
+
else if (goal.due && likely && likely > goal.due && !(was && was > goal.due)) line = `${p.name} would likely finish ${shortDate(likely)}, after this goal is due (${shortDate(goal.due)}).`;
|
|
18930
|
+
else if (goal.due && likely && was && was > goal.due && likely <= goal.due) line = `${p.name} would likely finish ${shortDate(likely)}, back inside this goal's date (${shortDate(goal.due)}).`;
|
|
18931
|
+
if (!line) continue;
|
|
18932
|
+
const key = `${link.portfolio.id}:${goal.id}`;
|
|
18933
|
+
const have = out.get(key);
|
|
18934
|
+
if (have) have.lines.push(line);
|
|
18935
|
+
else out.set(key, {
|
|
18936
|
+
portfolio: link.portfolio,
|
|
18937
|
+
goal,
|
|
18938
|
+
lines: [line]
|
|
18939
|
+
});
|
|
18940
|
+
}
|
|
18941
|
+
}
|
|
18942
|
+
return [...out.values()];
|
|
18943
|
+
}
|
|
18944
|
+
function trialConvoys(data, rows) {
|
|
18387
18945
|
const out = [];
|
|
18388
|
-
|
|
18389
|
-
for (const
|
|
18390
|
-
|
|
18391
|
-
|
|
18392
|
-
|
|
18393
|
-
|
|
18946
|
+
const late = (date, by) => date ? differenceInCalendarDays(/* @__PURE__ */ new Date(`${date}T12:00:00`), /* @__PURE__ */ new Date(`${by}T12:00:00`)) : null;
|
|
18947
|
+
for (const asker of data.programs) for (const convoy of asker.convoys ?? []) {
|
|
18948
|
+
if (convoy.status !== "accepted" || !convoy.projectId) continue;
|
|
18949
|
+
const row = rows.get(convoy.projectId);
|
|
18950
|
+
if (!row || row.started) continue;
|
|
18951
|
+
const realLate = late(likelyOf(row.real) ?? (row.real?.kind === "done" ? null : row.realEnd), convoy.by);
|
|
18952
|
+
let trialLate;
|
|
18953
|
+
let line;
|
|
18954
|
+
const name = row.project.name;
|
|
18955
|
+
if (row.trial.kind === "done" && row.real?.kind !== "done") {
|
|
18956
|
+
trialLate = null;
|
|
18957
|
+
line = `${name} stops, so "${convoy.what}" would never reach ${asker.name}.`;
|
|
18958
|
+
} else if (row.trial.kind === "paused" && row.real?.kind !== "paused") {
|
|
18959
|
+
trialLate = null;
|
|
18960
|
+
line = `${name} is paused, so "${convoy.what}" for ${asker.name} has no date while it rests.`;
|
|
18961
|
+
} else if (never$1(row.trial) && !never$1(row.real)) {
|
|
18962
|
+
trialLate = null;
|
|
18963
|
+
line = `${name} would not finish in two years at that pace, so "${convoy.what}" for ${asker.name} has no date.`;
|
|
18964
|
+
} else {
|
|
18965
|
+
const trialDate = likelyOf(row.trial) ?? (row.trial.kind === "done" ? null : row.trialEnd);
|
|
18966
|
+
trialLate = late(trialDate, convoy.by);
|
|
18967
|
+
if (trialLate === realLate || trialDate == null) continue;
|
|
18968
|
+
const days = (n) => `${n} day${n === 1 ? "" : "s"}`;
|
|
18969
|
+
line = trialLate != null && trialLate > 0 ? `"${convoy.what}" would reach ${asker.name} about ${shortDate(trialDate)}, ${days(trialLate)} after the ${shortDate(convoy.by)} it was promised${realLate != null && realLate > 0 ? ` (today it is ${days(realLate)} late)` : " (today it is in time)"}.` : `"${convoy.what}" would reach ${asker.name} about ${shortDate(trialDate)}, in time for ${shortDate(convoy.by)}${realLate != null && realLate > 0 ? ` (today it is ${days(realLate)} late)` : ""}.`;
|
|
18970
|
+
}
|
|
18971
|
+
out.push({
|
|
18972
|
+
what: convoy.what,
|
|
18973
|
+
asker,
|
|
18974
|
+
project: row.project,
|
|
18975
|
+
by: convoy.by,
|
|
18976
|
+
realLate,
|
|
18977
|
+
trialLate,
|
|
18978
|
+
line
|
|
18979
|
+
});
|
|
18980
|
+
}
|
|
18981
|
+
return out;
|
|
18982
|
+
}
|
|
18983
|
+
function trialSummary(c, live) {
|
|
18984
|
+
if (live === 0) return "No changes to try yet.";
|
|
18985
|
+
const parts = [];
|
|
18986
|
+
for (const r of c.projects) parts.push(`${r.project.name}: ${r.line}`);
|
|
18987
|
+
const over = c.people.filter((p) => p.nowOver).map((p) => p.person.name);
|
|
18988
|
+
const lighter = c.people.filter((p) => p.real && p.trial && p.trial.cargo < p.real.cargo).map((p) => p.person.name);
|
|
18989
|
+
if (over.length) parts.push(`Past their load line with these changes: ${list$2(over)}.`);
|
|
18990
|
+
else if (c.people.length) parts.push("Nobody new goes past their load line.");
|
|
18991
|
+
if (lighter.length) parts.push(`Lighter load: ${list$2(lighter)}.`);
|
|
18992
|
+
for (const g of c.goals) parts.push(`Goal "${g.goal.title}": ${g.lines.join(" ")}`);
|
|
18993
|
+
for (const v of c.convoys) parts.push(`Promise: ${v.line}`);
|
|
18994
|
+
return parts.join(" ");
|
|
18995
|
+
}
|
|
18996
|
+
function list$2(names) {
|
|
18997
|
+
if (names.length <= 1) return names.join("");
|
|
18998
|
+
return `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
|
|
18999
|
+
}
|
|
19000
|
+
/** One change in words: "Pause Checkout redesign", "Move Sam from Mobile app to Loyalty, 3 days a week". */
|
|
19001
|
+
function describeTrialChange(c, data) {
|
|
19002
|
+
const project = (id) => byId(data.projects).get(id)?.name ?? "a project since removed";
|
|
19003
|
+
const person = (id) => byId(data.people).get(id)?.name ?? "someone who left";
|
|
19004
|
+
switch (c.kind) {
|
|
19005
|
+
case "start": {
|
|
19006
|
+
const program = byId(data.programs).get(c.programId)?.name ?? "a program since removed";
|
|
19007
|
+
const crew = c.crewIds.length ? ` with ${list$2(c.crewIds.map(person))}` : " with nobody on it yet";
|
|
19008
|
+
return `Start ${c.name} in ${program}: ${c.tasks} task${c.tasks === 1 ? "" : "s"} over ${c.weeks} week${c.weeks === 1 ? "" : "s"}${crew}`;
|
|
19009
|
+
}
|
|
19010
|
+
case "pause": return `Pause ${project(c.projectId)}`;
|
|
19011
|
+
case "stop": return `Stop ${project(c.projectId)}`;
|
|
19012
|
+
case "move": return `Move ${person(c.personId)} from ${project(c.fromProjectId)} to ${project(c.toProjectId)}, ${c.days === 5 ? "full time" : `${c.days} day${c.days === 1 ? "" : "s"} a week`}`;
|
|
19013
|
+
case "end": return `Move ${project(c.projectId)}'s end date to ${shortDate(c.endDate)}`;
|
|
18394
19014
|
}
|
|
18395
|
-
return out.slice(0, 3);
|
|
18396
19015
|
}
|
|
18397
19016
|
|
|
18398
19017
|
// src/lib/dock-order.ts
|
|
@@ -24512,6 +25131,32 @@ function movedText(m, healthLabel) {
|
|
|
24512
25131
|
return `${m.project.name}: ${bits.join(", ")}`;
|
|
24513
25132
|
}
|
|
24514
25133
|
|
|
25134
|
+
// src/lib/agents.ts
|
|
25135
|
+
init_agent_check();
|
|
25136
|
+
const RANK$1 = {
|
|
25137
|
+
urgent: 0,
|
|
25138
|
+
high: 1,
|
|
25139
|
+
medium: 2,
|
|
25140
|
+
low: 3
|
|
25141
|
+
};
|
|
25142
|
+
/** Sent back by the person who checked it, with a note saying what to change. */
|
|
25143
|
+
const sentBack = (t) => t.approval?.status === "changes_requested" && t.status !== "done" && t.status !== "review";
|
|
25144
|
+
/** 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. */
|
|
25145
|
+
function agentQueue(data, agentId) {
|
|
25146
|
+
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"));
|
|
25147
|
+
}
|
|
25148
|
+
/** The agent an app means: the one named, else the only one on the crew. */
|
|
25149
|
+
function pickAgent(people, key) {
|
|
25150
|
+
const agents = people.filter(isAgent);
|
|
25151
|
+
if (agents.length === 0) return "There are no agents on this harbor's crew yet. Someone adds one on People with Add an agent.";
|
|
25152
|
+
if (!key) {
|
|
25153
|
+
if (agents.length === 1) return agents[0];
|
|
25154
|
+
return `This harbor has ${agents.length} agents (${agents.map((a) => a.name).join(", ")}). Say which with agent.`;
|
|
25155
|
+
}
|
|
25156
|
+
const k = key.trim().toLowerCase();
|
|
25157
|
+
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(", ")}.`;
|
|
25158
|
+
}
|
|
25159
|
+
|
|
24515
25160
|
// src/lib/fog.ts
|
|
24516
25161
|
function latestBy(cache, items, key, at) {
|
|
24517
25162
|
const hit = cache.get(items);
|
|
@@ -24601,140 +25246,6 @@ var init_fog = __esmMin((() => {
|
|
|
24601
25246
|
fileCache = /* @__PURE__ */ new WeakMap();
|
|
24602
25247
|
}));
|
|
24603
25248
|
|
|
24604
|
-
// src/lib/assignment.ts
|
|
24605
|
-
/**
|
|
24606
|
-
* Record who set a task's assignee and when. Only a change of assignee
|
|
24607
|
-
* stamps; clearing the assignee clears the stamp.
|
|
24608
|
-
*/
|
|
24609
|
-
function stampAssignment(before, next, by, at) {
|
|
24610
|
-
if (before && before.assigneeId === next.assigneeId) return next;
|
|
24611
|
-
if (!next.assigneeId) return {
|
|
24612
|
-
...next,
|
|
24613
|
-
assignedBy: null,
|
|
24614
|
-
assignedAt: null
|
|
24615
|
-
};
|
|
24616
|
-
return {
|
|
24617
|
-
...next,
|
|
24618
|
-
assignedBy: by,
|
|
24619
|
-
assignedAt: at
|
|
24620
|
-
};
|
|
24621
|
-
}
|
|
24622
|
-
var init_assignment = __esmMin((() => {}));
|
|
24623
|
-
|
|
24624
|
-
// src/lib/scuttle-rows.ts
|
|
24625
|
-
/** Whether it's scuttled: closed through Scuttle or sail and not raised since. */
|
|
24626
|
-
function isScuttled(project) {
|
|
24627
|
-
return Boolean(project.scuttled) && project.healthOverride === "done";
|
|
24628
|
-
}
|
|
24629
|
-
/**
|
|
24630
|
-
* Scuttle a project: Done by hand with the reason as its note, its open
|
|
24631
|
-
* tasks unassigned and undated (kept in `scuttled.freed`), and a decision on
|
|
24632
|
-
* the register. Null for a project that's already scuttled or gone, or a
|
|
24633
|
-
* blank why.
|
|
24634
|
-
*/
|
|
24635
|
-
function scuttleRows(data, projectId, why, byId, at, decisionId, context = "Closed through Scuttle or sail.") {
|
|
24636
|
-
const project = data.projects.find((p) => p.id === projectId);
|
|
24637
|
-
const reason = why.trim().slice(0, 600);
|
|
24638
|
-
if (!project || !reason || isScuttled(project)) return null;
|
|
24639
|
-
const freed = [];
|
|
24640
|
-
const tasks = [];
|
|
24641
|
-
for (const t of tasksOf(data.tasks, projectId)) {
|
|
24642
|
-
if (t.status === "done" || !t.assigneeId && !t.dueDate) continue;
|
|
24643
|
-
freed.push({
|
|
24644
|
-
taskId: t.id,
|
|
24645
|
-
assigneeId: t.assigneeId,
|
|
24646
|
-
dueDate: t.dueDate
|
|
24647
|
-
});
|
|
24648
|
-
tasks.push(stampAssignment(t, {
|
|
24649
|
-
...t,
|
|
24650
|
-
assigneeId: null,
|
|
24651
|
-
dueDate: null,
|
|
24652
|
-
touchedAt: at
|
|
24653
|
-
}, byId, at));
|
|
24654
|
-
}
|
|
24655
|
-
const decision = normalizeRaidItem({
|
|
24656
|
-
id: decisionId,
|
|
24657
|
-
kind: "decision",
|
|
24658
|
-
projectId,
|
|
24659
|
-
title: `Scuttle ${project.name}`,
|
|
24660
|
-
description: context,
|
|
24661
|
-
status: "decided",
|
|
24662
|
-
severity: "low",
|
|
24663
|
-
ownerId: byId,
|
|
24664
|
-
dueDate: null,
|
|
24665
|
-
resolution: "Stop the project. Its open tasks come off people’s lists.",
|
|
24666
|
-
rationale: reason,
|
|
24667
|
-
decidedById: byId,
|
|
24668
|
-
decidedAt: at,
|
|
24669
|
-
createdById: byId,
|
|
24670
|
-
createdAt: at,
|
|
24671
|
-
updatedAt: at,
|
|
24672
|
-
updates: []
|
|
24673
|
-
});
|
|
24674
|
-
return {
|
|
24675
|
-
project: {
|
|
24676
|
-
...project,
|
|
24677
|
-
health: "done",
|
|
24678
|
-
healthOverride: "done",
|
|
24679
|
-
healthNote: `Scuttled: ${reason}`,
|
|
24680
|
-
scuttled: {
|
|
24681
|
-
at,
|
|
24682
|
-
byId,
|
|
24683
|
-
why: reason,
|
|
24684
|
-
decisionId,
|
|
24685
|
-
freed
|
|
24686
|
-
}
|
|
24687
|
-
},
|
|
24688
|
-
tasks,
|
|
24689
|
-
decision
|
|
24690
|
-
};
|
|
24691
|
-
}
|
|
24692
|
-
/**
|
|
24693
|
-
* Raise a scuttled project: the scuttle cleared (the caller clears its Done), and each
|
|
24694
|
-
* freed task given back its person and date, unless someone has since given
|
|
24695
|
-
* it others, it's done, or the person has left the crew. Null when it isn't
|
|
24696
|
-
* scuttled.
|
|
24697
|
-
*/
|
|
24698
|
-
function raiseRows(data, projectId, at, byId) {
|
|
24699
|
-
const project = data.projects.find((p) => p.id === projectId);
|
|
24700
|
-
if (!project?.scuttled) return null;
|
|
24701
|
-
const people = new Set(data.people.map((p) => p.id));
|
|
24702
|
-
const byTask = new Map(project.scuttled.freed.map((f) => [f.taskId, f]));
|
|
24703
|
-
const tasks = [];
|
|
24704
|
-
for (const t of tasksOf(data.tasks, projectId)) {
|
|
24705
|
-
const f = byTask.get(t.id);
|
|
24706
|
-
if (!f || t.status === "done") continue;
|
|
24707
|
-
const assigneeId = !t.assigneeId && f.assigneeId && people.has(f.assigneeId) ? f.assigneeId : t.assigneeId;
|
|
24708
|
-
const dueDate = t.dueDate ?? f.dueDate;
|
|
24709
|
-
if (assigneeId === t.assigneeId && dueDate === t.dueDate) continue;
|
|
24710
|
-
tasks.push(stampAssignment(t, {
|
|
24711
|
-
...t,
|
|
24712
|
-
assigneeId,
|
|
24713
|
-
dueDate,
|
|
24714
|
-
touchedAt: at
|
|
24715
|
-
}, byId, at));
|
|
24716
|
-
}
|
|
24717
|
-
return {
|
|
24718
|
-
project: {
|
|
24719
|
-
...project,
|
|
24720
|
-
scuttled: null,
|
|
24721
|
-
voyageCall: {
|
|
24722
|
-
call: "sail",
|
|
24723
|
-
at,
|
|
24724
|
-
byId
|
|
24725
|
-
}
|
|
24726
|
-
},
|
|
24727
|
-
tasks
|
|
24728
|
-
};
|
|
24729
|
-
}
|
|
24730
|
-
var WHY_MAX;
|
|
24731
|
-
var init_scuttle_rows = __esmMin((() => {
|
|
24732
|
-
init_assignment();
|
|
24733
|
-
init_indexes();
|
|
24734
|
-
init_raid();
|
|
24735
|
-
WHY_MAX = 600;
|
|
24736
|
-
}));
|
|
24737
|
-
|
|
24738
25249
|
// src/lib/scuttle.ts
|
|
24739
25250
|
init_date_fns();
|
|
24740
25251
|
init_fog();
|
|
@@ -25100,10 +25611,27 @@ function gapText(gap) {
|
|
|
25100
25611
|
function awaitingApproval(task) {
|
|
25101
25612
|
return Boolean(task?.approval && task.approval.status === "pending" && task.status !== "done");
|
|
25102
25613
|
}
|
|
25614
|
+
/** The patch that asks `approverId` to approve the task (again, after changes). */
|
|
25615
|
+
function askApprovalPatch(task, approverId, opts) {
|
|
25616
|
+
if (task.status === "done") throw new ApprovalError("It's already done.");
|
|
25617
|
+
if (approverId === opts.by) throw new ApprovalError("Ask someone else. Your own approval is just finishing it.");
|
|
25618
|
+
return { approval: {
|
|
25619
|
+
approverId,
|
|
25620
|
+
askedById: opts.by,
|
|
25621
|
+
askedAt: opts.at,
|
|
25622
|
+
status: "pending",
|
|
25623
|
+
note: null,
|
|
25624
|
+
decidedAt: null
|
|
25625
|
+
} };
|
|
25626
|
+
}
|
|
25103
25627
|
/** Open tasks waiting on this person's approval, oldest ask first. */
|
|
25104
25628
|
function approvalsWaitingOn(tasks, personId) {
|
|
25105
25629
|
return tasks.filter((t) => awaitingApproval(t) && t.approval.approverId === personId).sort((a, b) => a.approval.askedAt.localeCompare(b.approval.askedAt));
|
|
25106
25630
|
}
|
|
25631
|
+
var ApprovalError;
|
|
25632
|
+
var init_task_approval = __esmMin((() => {
|
|
25633
|
+
ApprovalError = class extends Error {};
|
|
25634
|
+
}));
|
|
25107
25635
|
|
|
25108
25636
|
// src/lib/mcp/tools.ts
|
|
25109
25637
|
init_project_messages();
|
|
@@ -25133,7 +25661,6 @@ init_date_text();
|
|
|
25133
25661
|
init_date_fns();
|
|
25134
25662
|
init_shipping_forecast();
|
|
25135
25663
|
init_handover();
|
|
25136
|
-
init_agents();
|
|
25137
25664
|
init_work();
|
|
25138
25665
|
init_task_people();
|
|
25139
25666
|
init_fog();
|
|
@@ -25142,6 +25669,7 @@ init_board();
|
|
|
25142
25669
|
init_swatches();
|
|
25143
25670
|
init_holidays();
|
|
25144
25671
|
init_soundings();
|
|
25672
|
+
init_task_approval();
|
|
25145
25673
|
/** A task's logged time for get_task: the total and the latest entries. */
|
|
25146
25674
|
function timeOut(t, people) {
|
|
25147
25675
|
const entries = entriesNewestFirst(t);
|
|
@@ -26178,7 +26706,7 @@ const HARBOR_TOOLS = [
|
|
|
26178
26706
|
tool({
|
|
26179
26707
|
name: "my_work",
|
|
26180
26708
|
title: "My work",
|
|
26181
|
-
description: "What's yours in a harbor: your open tasks (late first), open tasks others own that you're also on (alsoOn), what others are waiting on you for, the risks you own, and tasks waiting on your approval (approvalsToGive; answer with decide_approval)." + DATA_NOTE,
|
|
26709
|
+
description: "What's yours in a harbor: your open tasks (late first), open tasks others own that you're also on (alsoOn), what others are waiting on you for, the risks you own, and tasks waiting on your approval (approvalsToGive; answer with decide_approval, except an agent's hand-in, marked askedByAgent, which the person approves in Harbor itself)." + DATA_NOTE,
|
|
26182
26710
|
input: object({
|
|
26183
26711
|
harbor: harborArg,
|
|
26184
26712
|
limit: limitArg(50, 25)
|
|
@@ -26231,7 +26759,8 @@ const HARBOR_TOOLS = [
|
|
|
26231
26759
|
...taskKey(t, projects.get(t.projectId)) ? { key: taskKey(t, projects.get(t.projectId)) } : {},
|
|
26232
26760
|
title: t.title,
|
|
26233
26761
|
askedBy: nameOf$2(people, t.approval.askedById),
|
|
26234
|
-
asked: dayOf(t.approval.askedAt)
|
|
26762
|
+
asked: dayOf(t.approval.askedAt),
|
|
26763
|
+
...isAgent(people.get(t.approval.askedById)) ? { askedByAgent: true } : {}
|
|
26235
26764
|
}))
|
|
26236
26765
|
};
|
|
26237
26766
|
}
|
|
@@ -27308,7 +27837,7 @@ const HARBOR_TOOLS = [
|
|
|
27308
27837
|
tool({
|
|
27309
27838
|
name: "agent_work",
|
|
27310
27839
|
title: "Work for an agent on the crew",
|
|
27311
|
-
description: "If you are working as one of this harbor's agents (an AI crew member on People, like \"Claude\"), the tasks people have given it: in progress first, then most urgent and soonest, each with its notes, checklist and latest comments. Do the work the person running you agrees to, then call agent_update to say what you did; that moves the task to In review for a person to check. Never mark an agent's task Done. Tasks waiting for review are listed under forReview so you don't redo them." + DATA_NOTE,
|
|
27840
|
+
description: "If you are working as one of this harbor's agents (an AI crew member on People, like \"Claude\"), the tasks people have given it: in progress first, then most urgent and soonest, each with its notes, checklist and latest comments. Do the work the person running you agrees to, then call agent_update to say what you did; that moves the task to In review for a person to check. Never mark an agent's task Done. A task a person sent back comes first, with sentBack saying who, when and what to change: fix that before anything else. Tasks waiting for review are listed under forReview, with who was asked to check each, so you don't redo them. Pass agentId (or the agent's name) as agent when the crew has more than one; if you don't know which agent you are, ask the person." + DATA_NOTE,
|
|
27312
27841
|
input: object({
|
|
27313
27842
|
harbor: harborArg,
|
|
27314
27843
|
agent: string().max(200).optional().describe("The agent's name or id. Needed when the crew has more than one."),
|
|
@@ -27341,11 +27870,17 @@ const HARBOR_TOOLS = [
|
|
|
27341
27870
|
};
|
|
27342
27871
|
return {
|
|
27343
27872
|
agent: agent.name,
|
|
27873
|
+
agentId: agent.id,
|
|
27344
27874
|
addedBy: nameOf$2(people, agent.addedById),
|
|
27345
27875
|
total: queue.length,
|
|
27346
27876
|
tasks: queue.slice(0, input.limit).map((t) => ({
|
|
27347
27877
|
...line(t),
|
|
27348
27878
|
status: t.status,
|
|
27879
|
+
...sentBack(t) ? { sentBack: {
|
|
27880
|
+
by: nameOf$2(people, t.approval.approverId),
|
|
27881
|
+
at: t.approval.decidedAt,
|
|
27882
|
+
note: t.approval.note
|
|
27883
|
+
} } : {},
|
|
27349
27884
|
priority: t.priority,
|
|
27350
27885
|
due: dayOf(t.dueDate),
|
|
27351
27886
|
project: projects.get(t.projectId)?.name ?? null,
|
|
@@ -27361,7 +27896,10 @@ const HARBOR_TOOLS = [
|
|
|
27361
27896
|
})),
|
|
27362
27897
|
...webLink(ctx, { task: t.id })
|
|
27363
27898
|
})),
|
|
27364
|
-
forReview: data.tasks.filter((t) => t.assigneeId === agent.id && t.status === "review").map(
|
|
27899
|
+
forReview: data.tasks.filter((t) => t.assigneeId === agent.id && t.status === "review").map((t) => ({
|
|
27900
|
+
...line(t),
|
|
27901
|
+
...t.approval?.status === "pending" ? { waitingOn: nameOf$2(people, t.approval.approverId) } : {}
|
|
27902
|
+
})),
|
|
27365
27903
|
otherAgents: data.people.filter((p) => isAgent(p) && p.id !== agent.id).map((p) => p.name)
|
|
27366
27904
|
};
|
|
27367
27905
|
}
|
|
@@ -27632,6 +28170,133 @@ const HARBOR_TOOLS = [
|
|
|
27632
28170
|
}))
|
|
27633
28171
|
};
|
|
27634
28172
|
}
|
|
28173
|
+
}),
|
|
28174
|
+
tool({
|
|
28175
|
+
name: "what_if",
|
|
28176
|
+
title: "Try a what-if plan for a portfolio",
|
|
28177
|
+
description: "Sea trial: big moves tried on a copy of a portfolio, read against today's plan. Nothing is changed. Give `moves` (start a project with about how many tasks, over how many weeks, and who works on it; pause or stop a project; move a person from one project to another for some days a week; move a project's end date), or leave them out to read the what-if plan someone saved on the portfolio. Answers each touched project's likely finish today and with the moves, each touched person's load line before and after (open tasks due in the next 3 weeks against what they can close), the goals put at risk, the promises to other programs (convoys) that slip, any move that no longer fits, and a summary in sentences. Pausing keeps tasks with their owners; stopping lets them go." + DATA_NOTE,
|
|
28178
|
+
input: object({
|
|
28179
|
+
harbor: harborArg,
|
|
28180
|
+
portfolio: string().min(1).max(200).describe("Portfolio id or name."),
|
|
28181
|
+
moves: array(object({
|
|
28182
|
+
move: _enum([
|
|
28183
|
+
"start",
|
|
28184
|
+
"pause",
|
|
28185
|
+
"stop",
|
|
28186
|
+
"move",
|
|
28187
|
+
"end"
|
|
28188
|
+
]),
|
|
28189
|
+
project: string().max(200).optional().describe("Project id or name: the one to pause, stop or re-date, or the one a person leaves."),
|
|
28190
|
+
to: string().max(200).optional().describe("For move: the project the person joins."),
|
|
28191
|
+
person: string().max(200).optional().describe("For move: person id or name."),
|
|
28192
|
+
days: number().int().min(1).max(5).optional().describe("For move: days a week on the new project (default 3)."),
|
|
28193
|
+
endDate: string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("For end: the new end date."),
|
|
28194
|
+
name: string().max(120).optional().describe("For start: the new project's name."),
|
|
28195
|
+
program: string().max(200).optional().describe("For start: program id or name in this portfolio (optional when it has one)."),
|
|
28196
|
+
tasks: number().int().min(1).max(200).optional().describe("For start: about how many tasks (default 10)."),
|
|
28197
|
+
weeks: number().int().min(1).max(104).optional().describe("For start: over how many weeks (default 8)."),
|
|
28198
|
+
crew: array(string().max(200)).max(20).optional().describe("For start: who works on it, ids or names.")
|
|
28199
|
+
})).max(30).optional()
|
|
28200
|
+
}),
|
|
28201
|
+
run: (ctx, input) => {
|
|
28202
|
+
const { data } = ctx;
|
|
28203
|
+
const portfolio = findOne(data.portfolios, input.portfolio, "portfolio");
|
|
28204
|
+
const open = trialProjects(data, portfolio.id);
|
|
28205
|
+
const programs = data.programs.filter((p) => p.portfolioId === portfolio.id);
|
|
28206
|
+
const need = (v, what) => {
|
|
28207
|
+
if (v === void 0 || v === "") throw new ToolError(`That move needs ${what}.`);
|
|
28208
|
+
return v;
|
|
28209
|
+
};
|
|
28210
|
+
const project = (ref) => findOne(open, need(ref, "a project"), "open project in this portfolio").id;
|
|
28211
|
+
const person = (ref) => findOne(data.people, ref, "person").id;
|
|
28212
|
+
const changes = input.moves ? input.moves.map((m) => {
|
|
28213
|
+
switch (m.move) {
|
|
28214
|
+
case "start": return {
|
|
28215
|
+
kind: "start",
|
|
28216
|
+
name: need(m.name?.trim(), "a name"),
|
|
28217
|
+
programId: m.program ? findOne(programs, m.program, "program in this portfolio").id : programs.length === 1 ? programs[0].id : need(void 0, "a program"),
|
|
28218
|
+
tasks: m.tasks ?? 10,
|
|
28219
|
+
weeks: m.weeks ?? 8,
|
|
28220
|
+
crewIds: [...new Set((m.crew ?? []).map(person))]
|
|
28221
|
+
};
|
|
28222
|
+
case "pause":
|
|
28223
|
+
case "stop": return {
|
|
28224
|
+
kind: m.move,
|
|
28225
|
+
projectId: project(m.project)
|
|
28226
|
+
};
|
|
28227
|
+
case "move": {
|
|
28228
|
+
const from = project(m.project);
|
|
28229
|
+
const to = project(need(m.to, "a project to move to"));
|
|
28230
|
+
if (from === to) throw new ToolError("A move needs two different projects.");
|
|
28231
|
+
return {
|
|
28232
|
+
kind: "move",
|
|
28233
|
+
personId: person(need(m.person, "a person")),
|
|
28234
|
+
fromProjectId: from,
|
|
28235
|
+
toProjectId: to,
|
|
28236
|
+
days: m.days ?? 3
|
|
28237
|
+
};
|
|
28238
|
+
}
|
|
28239
|
+
case "end": return {
|
|
28240
|
+
kind: "end",
|
|
28241
|
+
projectId: project(m.project),
|
|
28242
|
+
endDate: need(m.endDate, "an end date")
|
|
28243
|
+
};
|
|
28244
|
+
}
|
|
28245
|
+
}) : readTrial(portfolio.seaTrial?.changes);
|
|
28246
|
+
const saved = !input.moves && portfolio.seaTrial ? portfolio.seaTrial : null;
|
|
28247
|
+
const cmp = trialCompare(data, portfolio.id, changes, ctx.now);
|
|
28248
|
+
const line = (l) => l ? {
|
|
28249
|
+
cargo: l.cargo,
|
|
28250
|
+
capacity: l.capacity,
|
|
28251
|
+
over: l.over,
|
|
28252
|
+
text: loadLineText(l)
|
|
28253
|
+
} : null;
|
|
28254
|
+
const likely = (t) => t && t.kind === "forecast" ? t.likely ?? null : null;
|
|
28255
|
+
return {
|
|
28256
|
+
portfolio: portfolio.name,
|
|
28257
|
+
...saved ? { saved: {
|
|
28258
|
+
by: data.people.find((p) => p.id === saved.savedBy)?.name ?? null,
|
|
28259
|
+
at: saved.savedAt
|
|
28260
|
+
} } : {},
|
|
28261
|
+
moves: changes.filter((c) => !cmp.stale.includes(c)).map((c) => describeTrialChange(c, data)),
|
|
28262
|
+
noLongerFits: cmp.stale.map((c) => describeTrialChange(c, data)),
|
|
28263
|
+
projects: cmp.projects.map((r) => ({
|
|
28264
|
+
project: r.project.name,
|
|
28265
|
+
...r.started ? { started: true } : {},
|
|
28266
|
+
today: r.started ? null : {
|
|
28267
|
+
state: r.real?.kind ?? null,
|
|
28268
|
+
likely: likely(r.real),
|
|
28269
|
+
endDate: r.realEnd
|
|
28270
|
+
},
|
|
28271
|
+
withMoves: {
|
|
28272
|
+
state: r.trial.kind,
|
|
28273
|
+
likely: likely(r.trial),
|
|
28274
|
+
endDate: r.trialEnd
|
|
28275
|
+
},
|
|
28276
|
+
daysMoved: r.shift,
|
|
28277
|
+
text: r.line
|
|
28278
|
+
})),
|
|
28279
|
+
people: cmp.people.map((r) => ({
|
|
28280
|
+
who: r.person.name,
|
|
28281
|
+
today: line(r.real),
|
|
28282
|
+
withMoves: line(r.trial),
|
|
28283
|
+
...r.nowOver ? { newlyOver: true } : {}
|
|
28284
|
+
})),
|
|
28285
|
+
goals: cmp.goals.map((g) => ({
|
|
28286
|
+
goal: g.goal.title,
|
|
28287
|
+
text: g.lines.join(" ")
|
|
28288
|
+
})),
|
|
28289
|
+
promises: cmp.convoys.map((v) => ({
|
|
28290
|
+
what: v.what,
|
|
28291
|
+
to: v.asker.name,
|
|
28292
|
+
from: v.project.name,
|
|
28293
|
+
by: v.by,
|
|
28294
|
+
text: v.line
|
|
28295
|
+
})),
|
|
28296
|
+
notes: cmp.notes,
|
|
28297
|
+
summary: cmp.summary
|
|
28298
|
+
};
|
|
28299
|
+
}
|
|
27635
28300
|
})
|
|
27636
28301
|
];
|
|
27637
28302
|
const TOOL_BY_NAME = new Map(HARBOR_TOOLS.map((t) => [t.name, t]));
|
|
@@ -28008,13 +28673,17 @@ function stamp() {
|
|
|
28008
28673
|
function initialsOf(name) {
|
|
28009
28674
|
return name.split(/\s+/).filter(Boolean).map((p) => p[0]).join("").slice(0, 2).toUpperCase();
|
|
28010
28675
|
}
|
|
28011
|
-
function withStatus(task, status) {
|
|
28676
|
+
function withStatus(task, status, mover) {
|
|
28012
28677
|
if (task.status === status) return task;
|
|
28013
28678
|
const next = {
|
|
28014
28679
|
...task,
|
|
28015
28680
|
status,
|
|
28016
28681
|
touchedAt: stamp()
|
|
28017
28682
|
};
|
|
28683
|
+
if (mover) {
|
|
28684
|
+
const ask = agentAskAfterMove(mover.people, task, status, mover.by, next.touchedAt);
|
|
28685
|
+
if (ask !== void 0) next.approval = ask;
|
|
28686
|
+
}
|
|
28018
28687
|
if (status === "done") next.completedAt = stamp();
|
|
28019
28688
|
else if (task.status === "done") {
|
|
28020
28689
|
next.completedAt = null;
|
|
@@ -28022,7 +28691,9 @@ function withStatus(task, status) {
|
|
|
28022
28691
|
}
|
|
28023
28692
|
return next;
|
|
28024
28693
|
}
|
|
28025
|
-
var init_shared = __esmMin((() => {
|
|
28694
|
+
var init_shared = __esmMin((() => {
|
|
28695
|
+
init_agent_check();
|
|
28696
|
+
}));
|
|
28026
28697
|
|
|
28027
28698
|
// src/lib/undo-state.ts
|
|
28028
28699
|
function clearUndo() {
|
|
@@ -28066,7 +28737,7 @@ function sessionSlice({ set, get, write }) {
|
|
|
28066
28737
|
if (get().currentUserId !== hit.id) set({ currentUserId: hit.id });
|
|
28067
28738
|
return hit.id;
|
|
28068
28739
|
}
|
|
28069
|
-
const named = personId ? get().people.find((p) => p.id === personId && !p.accountId) : null;
|
|
28740
|
+
const named = personId ? get().people.find((p) => p.id === personId && !p.accountId && p.kind !== "agent") : null;
|
|
28070
28741
|
if (named) {
|
|
28071
28742
|
set({
|
|
28072
28743
|
people: get().people.map((p) => p.id === named.id ? {
|
|
@@ -28983,6 +29654,7 @@ function nextOccurrence(task, id, today, createdAt, siblings = []) {
|
|
|
28983
29654
|
status: "todo",
|
|
28984
29655
|
dueDate,
|
|
28985
29656
|
milestoneId: null,
|
|
29657
|
+
approval: null,
|
|
28986
29658
|
...task.startDate ? { startDate: lead != null && lead >= 0 ? format(addDays(/* @__PURE__ */ new Date(`${dueDate}T12:00:00`), -lead), "yyyy-MM-dd") : null } : {},
|
|
28987
29659
|
createdAt,
|
|
28988
29660
|
completedAt: null,
|
|
@@ -29179,7 +29851,12 @@ function tasksSlice({ set, get, write }) {
|
|
|
29179
29851
|
};
|
|
29180
29852
|
if (next.startDate) next.startDate = fitStart(next.startDate, next.dueDate);
|
|
29181
29853
|
if (next.assigneeId && next.followerIds?.includes(next.assigneeId)) next.followerIds = alsoOnIds(next);
|
|
29854
|
+
if (!("approval" in patch) && patch.assigneeId !== void 0 && patch.assigneeId !== row.assigneeId && row.approval?.status === "changes_requested" && isAgent(get().people.find((p) => p.id === row.approval.askedById)) && !isAgent(get().people.find((p) => p.id === patch.assigneeId))) next.approval = null;
|
|
29182
29855
|
if (patch.status && patch.status !== row.status) {
|
|
29856
|
+
if (!("approval" in patch)) {
|
|
29857
|
+
const ask = agentAskAfterMove(get().people, row, patch.status, get().currentUserId, next.touchedAt);
|
|
29858
|
+
if (ask !== void 0) next.approval = ask;
|
|
29859
|
+
}
|
|
29183
29860
|
if (patch.status === "done" && !patch.completedAt) next.completedAt = stamp();
|
|
29184
29861
|
else if (row.status === "done" && patch.status !== "done") {
|
|
29185
29862
|
next.completedAt = null;
|
|
@@ -29224,7 +29901,10 @@ function tasksSlice({ set, get, write }) {
|
|
|
29224
29901
|
if (!opts?.allowOverCap && !isSubtask(task, get().tasks)) {
|
|
29225
29902
|
if (columnWip(get(), task.projectId, status, 1)) return;
|
|
29226
29903
|
}
|
|
29227
|
-
const nextRow = withStatus(task, status
|
|
29904
|
+
const nextRow = withStatus(task, status, {
|
|
29905
|
+
people: get().people,
|
|
29906
|
+
by: get().currentUserId
|
|
29907
|
+
});
|
|
29228
29908
|
if (status === "done" && isBlocked$1(task, get().tasks)) Object.assign(nextRow, blockersPatch([]));
|
|
29229
29909
|
const project = get().projects.find((p) => p.id === task.projectId);
|
|
29230
29910
|
const { task: finalRow, comments: autoComments } = applyAutomations(project, task, nextRow, {
|
|
@@ -29293,8 +29973,24 @@ function tasksSlice({ set, get, write }) {
|
|
|
29293
29973
|
const task = get().tasks.find((t) => t.id === taskId);
|
|
29294
29974
|
const text = body.trim();
|
|
29295
29975
|
if (!task || !text) return;
|
|
29296
|
-
if (task.status !== status) get().moveTask(taskId, status, { allowOverCap: opts?.allowOverCap });
|
|
29976
|
+
if (status !== "same" && task.status !== status) get().moveTask(taskId, status, { allowOverCap: opts?.allowOverCap });
|
|
29297
29977
|
const at = stamp();
|
|
29978
|
+
const moved = get().tasks.find((t) => t.id === taskId);
|
|
29979
|
+
const agent = get().people.find((p) => p.id === agentId);
|
|
29980
|
+
const waiting = awaitingApproval(moved);
|
|
29981
|
+
const gone = [...useFormerAccounts.getState().ids, ...opts?.gone ?? []];
|
|
29982
|
+
const asked = get().people.find((p) => p.id === moved?.approval?.approverId);
|
|
29983
|
+
const lost = waiting && isAgent(get().people.find((p) => p.id === moved.approval.askedById)) && (!asked || isFormerCrew(asked, gone));
|
|
29984
|
+
if (status === "review" && moved?.status === "review" && agent && (!waiting || lost)) {
|
|
29985
|
+
const checker = agentChecker(get().people, moved, agent, gone);
|
|
29986
|
+
if (checker) write({ tasks: get().tasks.map((t) => t.id === taskId ? {
|
|
29987
|
+
...t,
|
|
29988
|
+
...askApprovalPatch(t, checker.id, {
|
|
29989
|
+
by: agentId,
|
|
29990
|
+
at
|
|
29991
|
+
})
|
|
29992
|
+
} : t) });
|
|
29993
|
+
}
|
|
29298
29994
|
write({
|
|
29299
29995
|
comments: [...get().comments, {
|
|
29300
29996
|
id: uid("c"),
|
|
@@ -29302,7 +29998,9 @@ function tasksSlice({ set, get, write }) {
|
|
|
29302
29998
|
authorId: agentId,
|
|
29303
29999
|
body: text,
|
|
29304
30000
|
createdAt: at,
|
|
29305
|
-
mentionedIds: parseMentions(text, get().people).filter((id) => id !== agentId)
|
|
30001
|
+
mentionedIds: parseMentions(text, get().people).filter((id) => id !== agentId),
|
|
30002
|
+
...opts?.ranById ? { ranById: opts.ranById } : {},
|
|
30003
|
+
...opts?.via ? { via: opts.via } : {}
|
|
29306
30004
|
}],
|
|
29307
30005
|
people: get().people.map((p) => p.id === agentId ? {
|
|
29308
30006
|
...p,
|
|
@@ -29454,7 +30152,10 @@ function tasksSlice({ set, get, write }) {
|
|
|
29454
30152
|
const tick = new Set(ids);
|
|
29455
30153
|
const ticked = get().tasks.filter((t) => tick.has(t.id) && t.status !== "done");
|
|
29456
30154
|
if (ticked.length === 0) return;
|
|
29457
|
-
write({ tasks: get().tasks.map((t) => tick.has(t.id) && t.status !== "done" ? withStatus(t, "done"
|
|
30155
|
+
write({ tasks: get().tasks.map((t) => tick.has(t.id) && t.status !== "done" ? withStatus(t, "done", {
|
|
30156
|
+
people: get().people,
|
|
30157
|
+
by: get().currentUserId
|
|
30158
|
+
}) : t) });
|
|
29458
30159
|
for (const t of ticked) get().log(`ticked off “${t.title}” on First voyage`, `/projects/${t.projectId}`);
|
|
29459
30160
|
},
|
|
29460
30161
|
keepTasks: (ids) => {
|
|
@@ -29503,7 +30204,10 @@ function tasksSlice({ set, get, write }) {
|
|
|
29503
30204
|
if (!moved.has(row.id)) return row;
|
|
29504
30205
|
let next = applyBulk(row, change);
|
|
29505
30206
|
if ("status" in change) {
|
|
29506
|
-
next = withStatus(row, change.status
|
|
30207
|
+
next = withStatus(row, change.status, {
|
|
30208
|
+
people: s.people,
|
|
30209
|
+
by: s.currentUserId
|
|
30210
|
+
});
|
|
29507
30211
|
if (change.status === "done" && isBlocked$1(row, s.tasks)) Object.assign(next, blockersPatch([]));
|
|
29508
30212
|
}
|
|
29509
30213
|
const { task: automated, comments } = applyAutomations(projects.get(row.projectId), row, next, {
|
|
@@ -29624,6 +30328,9 @@ function tasksSlice({ set, get, write }) {
|
|
|
29624
30328
|
}
|
|
29625
30329
|
}
|
|
29626
30330
|
var init_tasks = __esmMin((() => {
|
|
30331
|
+
init_agent_check();
|
|
30332
|
+
init_former_crew();
|
|
30333
|
+
init_task_approval();
|
|
29627
30334
|
init_github_refs();
|
|
29628
30335
|
init_board();
|
|
29629
30336
|
init_automations();
|