@harborppm/cli 0.103.0 → 0.105.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/lib/cli.mjs CHANGED
@@ -11,7 +11,10 @@ import { login } from "./auth.mjs";
11
11
  import {
12
12
  DEFAULT_SERVER,
13
13
  forgetCredentials,
14
+ forgetLastDraft,
14
15
  readCredentials,
16
+ readLastDraft,
17
+ writeLastDraft,
15
18
  readSettings,
16
19
  writeCredentials,
17
20
  writeSettings,
@@ -260,6 +263,10 @@ export const HELP = `harbor: Harbor from the terminal
260
263
  harbor export harbor [--csv] the whole harbor as JSON (owners)
261
264
  harbor import FILE [--project P] [--portfolio P] [--no-people]
262
265
  add tasks from a CSV file
266
+ harbor draft "WORDS" --project P|--program P|--portfolio P [--add]
267
+ Harbor's AI drafts tasks, projects
268
+ or programs; harbor draft add adds
269
+ the last one
263
270
  harbor premortem PROJECT ["WHAT WENT WRONG"] [--start]
264
271
  a project's pre-mortem: start,
265
272
  answer or read it
@@ -591,6 +598,61 @@ export function dueDate(v, today = new Date()) {
591
598
  return todayLocal(d);
592
599
  }
593
600
 
601
+ /** Where `harbor draft` puts its draft, as draft_plan and add_plan take it. */
602
+ export function draftWhere(values, harbor) {
603
+ const base = harbor ? { harbor } : {};
604
+ if (values.new !== undefined) {
605
+ if (values.new === "program")
606
+ return { ...base, level: "projects", ...(values.portfolio ? { portfolio: values.portfolio } : {}) };
607
+ if (values.new === "portfolio") return { ...base, level: "programs" };
608
+ throw new HarborError("--new is program or portfolio.");
609
+ }
610
+ const given = ["project", "program", "portfolio"].filter((k) => values[k] !== undefined);
611
+ if (given.length !== 1)
612
+ throw new HarborError(
613
+ "Say where it goes: --project P (tasks), --program P (projects), --portfolio P (programs), or --new program|portfolio.",
614
+ );
615
+ const level = { project: "tasks", program: "projects", portfolio: "programs" }[given[0]];
616
+ return { ...base, level, into: values[given[0]] };
617
+ }
618
+
619
+ const draftDue = (days) => (days === 1 ? "due tomorrow" : `due in ${days} days`);
620
+
621
+ /** A draft_plan answer as an indented outline. */
622
+ export function draftText(r) {
623
+ const lines = [];
624
+ const where = r.into
625
+ ? ` for ${r.into}`
626
+ : r.level === "projects"
627
+ ? ` for a new program${r.portfolio ? ` in ${r.portfolio}` : ""}`
628
+ : r.level === "programs"
629
+ ? " for a new portfolio"
630
+ : "";
631
+ lines.push(`Drafted ${r.drafted}${where}:`);
632
+ if (!r.into && r.plan.name) {
633
+ lines.push("", `${r.plan.name}${r.plan.summary ? ` — ${r.plan.summary}` : ""}`);
634
+ }
635
+ const task = (t, pad) =>
636
+ `${pad}· ${t.title} (${draftDue(t.dueInDays)}${t.ownerName ? `, ${t.ownerName}` : ""})`;
637
+ const project = (p, pad) => {
638
+ lines.push(`${pad}${p.name}${p.summary ? ` — ${p.summary}` : ""}`);
639
+ for (const t of p.tasks ?? []) lines.push(task(t, `${pad} `));
640
+ };
641
+ if (r.plan.tasks) {
642
+ lines.push("");
643
+ for (const t of r.plan.tasks) lines.push(task(t, " "));
644
+ }
645
+ for (const p of r.plan.projects ?? []) {
646
+ lines.push("");
647
+ project(p, " ");
648
+ }
649
+ for (const g of r.plan.programs ?? []) {
650
+ lines.push("", ` ${g.name}${g.summary ? ` — ${g.summary}` : ""}`);
651
+ for (const p of g.projects ?? []) project(p, " ");
652
+ }
653
+ return lines.join("\n");
654
+ }
655
+
594
656
  /**
595
657
  * Each title read in plain words, as the website's new task box reads it:
596
658
  * "Book the venue @Quinn by Friday !high #Website". A flag given says that
@@ -1092,6 +1154,22 @@ const DETAIL = {
1092
1154
  " --json, rows is one object per row, keyed by column.",
1093
1155
  " harbor export harbor > cedar.json keeps a copy of everything.",
1094
1156
  ],
1157
+ draft: [
1158
+ ' harbor draft "WORDS" --project P drafts tasks for a project',
1159
+ ' harbor draft "WORDS" --program P drafts projects for a program, each',
1160
+ " with its first tasks",
1161
+ ' harbor draft "WORDS" --portfolio P drafts programs for a portfolio, with',
1162
+ " their projects and first tasks",
1163
+ ' harbor draft "WORDS" --new program [--portfolio P]',
1164
+ ' harbor draft "WORDS" --new portfolio drafts a new program or portfolio and',
1165
+ " what goes in it",
1166
+ " harbor draft add writes: adds the draft shown last",
1167
+ "",
1168
+ " Harbor's own AI drafts from your words and leaves out what's already",
1169
+ " there. Nothing is added until you run harbor draft add (or pass --add to",
1170
+ " draft and add in one go). --ends DAY says when it should all be done.",
1171
+ " Each draft uses one of the harbor's monthly AI drafts.",
1172
+ ],
1095
1173
  import: [
1096
1174
  " harbor import FILE --project P writes: adds the file's tasks",
1097
1175
  " harbor import FILE --portfolio P writes: makes projects as the file",
@@ -3397,6 +3475,46 @@ export async function run(argv, io = {}) {
3397
3475
  (r) => (asJson ? exportData(r) : r),
3398
3476
  );
3399
3477
  }
3478
+ case "draft": {
3479
+ const { positionals, values, harbor } = parse(
3480
+ spec(["add"], ["project", "program", "portfolio", "new", "ends"]),
3481
+ );
3482
+ if (positionals[0] === "add" && positionals.length === 1) {
3483
+ const last = await readLastDraft(env);
3484
+ if (!last?.plan)
3485
+ throw new HarborError('There\'s no draft to add. Run harbor draft "WORDS" first.');
3486
+ const result = await client.call("add_plan", { ...last.where, ...last.plan });
3487
+ await forgetLastDraft(env);
3488
+ out(asJson ? jsonText(result) : plain(result.added.says));
3489
+ return 0;
3490
+ }
3491
+ const brief = positionals.join(" ").trim();
3492
+ if (!brief)
3493
+ throw new HarborError(
3494
+ 'Say what the work is: harbor draft "launch the newsletter" --project NAME.',
3495
+ );
3496
+ const where = draftWhere(values, harbor);
3497
+ const drafted = await client.call("draft_plan", {
3498
+ ...where,
3499
+ brief,
3500
+ ...(values.ends ? { ends: dueDate(values.ends) } : {}),
3501
+ });
3502
+ const plan = { ...drafted.plan, ...(values.ends ? { ends: dueDate(values.ends) } : {}) };
3503
+ if (values.add) {
3504
+ const result = await client.call("add_plan", { ...where, ...plan });
3505
+ out(asJson ? jsonText({ drafted, ...result }) : plain(`${draftText(drafted)}\n\n${result.added.says}`));
3506
+ return 0;
3507
+ }
3508
+ await writeLastDraft({ where, plan }, env);
3509
+ out(
3510
+ asJson
3511
+ ? jsonText(drafted)
3512
+ : plain(
3513
+ `${draftText(drafted)}\n\nNothing is added yet. harbor draft add adds it; drafting again starts afresh.`,
3514
+ ),
3515
+ );
3516
+ return 0;
3517
+ }
3400
3518
  case "import": {
3401
3519
  const { positionals, values, harbor } = parse(spec(["no-people"], ["project", "portfolio"]));
3402
3520
  const [file, ...extra] = positionals;
package/lib/config.mjs CHANGED
@@ -59,3 +59,23 @@ export async function writeSettings(settings, env = process.env) {
59
59
  await mkdir(configDir(env), { recursive: true, mode: 0o700 });
60
60
  await writeFile(settingsFile(env), JSON.stringify(settings, null, 2));
61
61
  }
62
+
63
+ const draftFile = (env) => join(configDir(env), "last-draft.json");
64
+
65
+ /** The last draft `harbor draft` showed, for `harbor draft add`; null when there isn't one. */
66
+ export async function readLastDraft(env = process.env) {
67
+ try {
68
+ return JSON.parse(await readFile(draftFile(env), "utf8"));
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ export async function writeLastDraft(draft, env = process.env) {
75
+ await mkdir(configDir(env), { recursive: true, mode: 0o700 });
76
+ await writeFile(draftFile(env), JSON.stringify(draft, null, 2), { mode: 0o600 });
77
+ }
78
+
79
+ export async function forgetLastDraft(env = process.env) {
80
+ await rm(draftFile(env), { force: true });
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harborppm/cli",
3
- "version": "0.103.0",
3
+ "version": "0.105.0",
4
4
  "description": "Harbor from the terminal: a full-screen app with everything, plus commands for scripts and agents.",
5
5
  "keywords": [
6
6
  "harbor",