monoban 1.0.0 → 1.2.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 +27 -1
- package/dist/index.mjs +1769 -75
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { homedir, hostname, tmpdir } from "node:os";
|
|
3
3
|
import path, { dirname, join } from "node:path";
|
|
4
|
-
import { mkdir, mkdtemp, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { mkdir, mkdtemp, open, readFile, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import childProcess, { execFile, spawn, spawnSync } from "node:child_process";
|
|
6
6
|
import { EventEmitter } from "node:events";
|
|
7
7
|
import fs, { realpathSync } from "node:fs";
|
|
@@ -1021,7 +1021,7 @@ const uuid = (version) => {
|
|
|
1021
1021
|
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
1022
1022
|
};
|
|
1023
1023
|
/** Practical email validation */
|
|
1024
|
-
const email = /^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
1024
|
+
const email$1 = /^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
1025
1025
|
const _emoji$1 = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
1026
1026
|
function emoji() {
|
|
1027
1027
|
return new RegExp(_emoji$1, "u");
|
|
@@ -1559,7 +1559,7 @@ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
|
|
|
1559
1559
|
$ZodStringFormat.init(inst, def);
|
|
1560
1560
|
});
|
|
1561
1561
|
const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
|
|
1562
|
-
def.pattern ?? (def.pattern = email);
|
|
1562
|
+
def.pattern ?? (def.pattern = email$1);
|
|
1563
1563
|
$ZodStringFormat.init(inst, def);
|
|
1564
1564
|
});
|
|
1565
1565
|
function canParseURL(input) {
|
|
@@ -4827,6 +4827,9 @@ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
|
|
|
4827
4827
|
$ZodEmail.init(inst, def);
|
|
4828
4828
|
ZodStringFormat.init(inst, def);
|
|
4829
4829
|
});
|
|
4830
|
+
function email(params) {
|
|
4831
|
+
return /* @__PURE__ */ _email(ZodEmail, params);
|
|
4832
|
+
}
|
|
4830
4833
|
const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
|
|
4831
4834
|
$ZodGUID.init(inst, def);
|
|
4832
4835
|
ZodStringFormat.init(inst, def);
|
|
@@ -5367,7 +5370,7 @@ function number(params) {
|
|
|
5367
5370
|
}
|
|
5368
5371
|
//#endregion
|
|
5369
5372
|
//#region ../../packages/contract/src/board.ts
|
|
5370
|
-
/** Column and
|
|
5373
|
+
/** Column, project and tag colours. Keep in sync with the --c-* tokens (web) and the checks on columns.color, projects.color and tags.color. */
|
|
5371
5374
|
const COLORS = [
|
|
5372
5375
|
"grey",
|
|
5373
5376
|
"blue",
|
|
@@ -5385,9 +5388,250 @@ const LIMITS = {
|
|
|
5385
5388
|
/** Highest WIP limit the API accepts (the database only needs it positive). */
|
|
5386
5389
|
wipLimit: 999,
|
|
5387
5390
|
taskTitle: 200,
|
|
5388
|
-
taskDescription: 2e4
|
|
5391
|
+
taskDescription: 2e4,
|
|
5392
|
+
tagName: 24,
|
|
5393
|
+
tagsPerTask: 10,
|
|
5394
|
+
/** A project's notes, in characters. */
|
|
5395
|
+
projectNotes: 1e5,
|
|
5396
|
+
linksPerTask: 20,
|
|
5397
|
+
linkUrl: 2e3,
|
|
5398
|
+
linkTitle: 200
|
|
5389
5399
|
};
|
|
5390
5400
|
//#endregion
|
|
5401
|
+
//#region ../../packages/contract/src/dates.ts
|
|
5402
|
+
/**
|
|
5403
|
+
* Days, as tasks are scheduled: "2026-10-02", no time and no time zone. "Today" is the user's own: clients
|
|
5404
|
+
* work it out from their clock (today()) and send it, so the API never guesses a time zone.
|
|
5405
|
+
*/
|
|
5406
|
+
const DAY_MS$1 = 864e5;
|
|
5407
|
+
const DAY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
5408
|
+
const WEEKDAYS = [
|
|
5409
|
+
"sunday",
|
|
5410
|
+
"monday",
|
|
5411
|
+
"tuesday",
|
|
5412
|
+
"wednesday",
|
|
5413
|
+
"thursday",
|
|
5414
|
+
"friday",
|
|
5415
|
+
"saturday"
|
|
5416
|
+
];
|
|
5417
|
+
const MONTHS = [
|
|
5418
|
+
"january",
|
|
5419
|
+
"february",
|
|
5420
|
+
"march",
|
|
5421
|
+
"april",
|
|
5422
|
+
"may",
|
|
5423
|
+
"june",
|
|
5424
|
+
"july",
|
|
5425
|
+
"august",
|
|
5426
|
+
"september",
|
|
5427
|
+
"october",
|
|
5428
|
+
"november",
|
|
5429
|
+
"december"
|
|
5430
|
+
];
|
|
5431
|
+
const SHORT_WEEKDAYS = [
|
|
5432
|
+
"Sun",
|
|
5433
|
+
"Mon",
|
|
5434
|
+
"Tue",
|
|
5435
|
+
"Wed",
|
|
5436
|
+
"Thu",
|
|
5437
|
+
"Fri",
|
|
5438
|
+
"Sat"
|
|
5439
|
+
];
|
|
5440
|
+
const SHORT_MONTHS = [
|
|
5441
|
+
"Jan",
|
|
5442
|
+
"Feb",
|
|
5443
|
+
"Mar",
|
|
5444
|
+
"Apr",
|
|
5445
|
+
"May",
|
|
5446
|
+
"Jun",
|
|
5447
|
+
"Jul",
|
|
5448
|
+
"Aug",
|
|
5449
|
+
"Sep",
|
|
5450
|
+
"Oct",
|
|
5451
|
+
"Nov",
|
|
5452
|
+
"Dec"
|
|
5453
|
+
];
|
|
5454
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
5455
|
+
const fromUtc = (ms) => {
|
|
5456
|
+
const d = new Date(ms);
|
|
5457
|
+
return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
|
5458
|
+
};
|
|
5459
|
+
/** Midnight UTC of a day: arithmetic on it never meets a daylight-saving change. */
|
|
5460
|
+
const utc = (day) => {
|
|
5461
|
+
const [, y, m, d] = DAY_PATTERN.exec(day) ?? [];
|
|
5462
|
+
return Date.UTC(Number(y), Number(m) - 1, Number(d));
|
|
5463
|
+
};
|
|
5464
|
+
/** Whether `value` is a real day ("2026-02-30" isn't). */
|
|
5465
|
+
function isDay(value) {
|
|
5466
|
+
return DAY_PATTERN.test(value) && fromUtc(utc(value)) === value;
|
|
5467
|
+
}
|
|
5468
|
+
/** Today, by this device's clock and time zone. */
|
|
5469
|
+
function today(now = /* @__PURE__ */ new Date()) {
|
|
5470
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
5471
|
+
}
|
|
5472
|
+
function addDays(day, days) {
|
|
5473
|
+
return fromUtc(utc(day) + days * DAY_MS$1);
|
|
5474
|
+
}
|
|
5475
|
+
/** How many days from `from` to `to` (negative when `to` is earlier). */
|
|
5476
|
+
function daysBetween(from, to) {
|
|
5477
|
+
return Math.round((utc(to) - utc(from)) / DAY_MS$1);
|
|
5478
|
+
}
|
|
5479
|
+
/** 0 is Sunday. */
|
|
5480
|
+
const weekday = (day) => new Date(utc(day)).getUTCDay();
|
|
5481
|
+
/** A day in a few characters, next to `today`: "today", "tomorrow", "yesterday", "Fri" (this week), "Oct 12". */
|
|
5482
|
+
function formatDay(day, now) {
|
|
5483
|
+
const diff = daysBetween(now, day);
|
|
5484
|
+
if (diff === 0) return "today";
|
|
5485
|
+
if (diff === 1) return "tomorrow";
|
|
5486
|
+
if (diff === -1) return "yesterday";
|
|
5487
|
+
if (diff > 1 && diff < 7) return SHORT_WEEKDAYS[weekday(day)];
|
|
5488
|
+
const d = new Date(utc(day));
|
|
5489
|
+
const month = `${SHORT_MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}`;
|
|
5490
|
+
return day.slice(0, 4) === now.slice(0, 4) ? month : `${month}, ${day.slice(0, 4)}`;
|
|
5491
|
+
}
|
|
5492
|
+
/** A day in full, for a heading: "Thu Oct 2" (with the year when it isn't this one). */
|
|
5493
|
+
function longDay(day, now) {
|
|
5494
|
+
const d = new Date(utc(day));
|
|
5495
|
+
const text = `${SHORT_WEEKDAYS[d.getUTCDay()]} ${SHORT_MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}`;
|
|
5496
|
+
return day.slice(0, 4) === now.slice(0, 4) ? text : `${text}, ${day.slice(0, 4)}`;
|
|
5497
|
+
}
|
|
5498
|
+
/** The weekday a word names, by its first letters ("fri", "tues"); -1 if none. */
|
|
5499
|
+
const weekdayOf = (word) => word.length >= 2 ? WEEKDAYS.findIndex((name) => name.startsWith(word)) : -1;
|
|
5500
|
+
/** The month a word names, by its first three letters or more ("oct", "october"); -1 if none. */
|
|
5501
|
+
const monthOf = (word) => word.length >= 3 ? MONTHS.findIndex((name) => name.startsWith(word)) : -1;
|
|
5502
|
+
/**
|
|
5503
|
+
* The day someone means, typed loosely, or null: "today", "tomorrow" ("tom"), "yesterday", a weekday ("fri":
|
|
5504
|
+
* the next one, today included; "next fri": after today), "next week" (Monday), "weekend" (Saturday),
|
|
5505
|
+
* "+3" or "3d" (days ahead), "2w", "oct 12" or "12 oct" (the next one; a year after it works too), or
|
|
5506
|
+
* "2026-10-12".
|
|
5507
|
+
*/
|
|
5508
|
+
function parseDay(input, now) {
|
|
5509
|
+
const text = input.trim().toLowerCase().replace(/\s+/g, " ").replace(/,/g, "");
|
|
5510
|
+
if (!text) return null;
|
|
5511
|
+
if ([
|
|
5512
|
+
"today",
|
|
5513
|
+
"tod",
|
|
5514
|
+
"now"
|
|
5515
|
+
].includes(text)) return now;
|
|
5516
|
+
if ([
|
|
5517
|
+
"tomorrow",
|
|
5518
|
+
"tom",
|
|
5519
|
+
"tmr",
|
|
5520
|
+
"tmrw"
|
|
5521
|
+
].includes(text)) return addDays(now, 1);
|
|
5522
|
+
if (text === "yesterday") return addDays(now, -1);
|
|
5523
|
+
if (isDay(text)) return text;
|
|
5524
|
+
const ahead = /^\+?(\d{1,3}) ?(d|days?|w|weeks?)?$/.exec(text);
|
|
5525
|
+
if (ahead && (text.startsWith("+") || ahead[2])) {
|
|
5526
|
+
const n = Number(ahead[1]);
|
|
5527
|
+
return addDays(now, ahead[2]?.startsWith("w") ? n * 7 : n);
|
|
5528
|
+
}
|
|
5529
|
+
const next = (target, from) => addDays(now, from + (target - weekday(addDays(now, from)) + 7) % 7);
|
|
5530
|
+
if (text === "next week") return next(1, 1);
|
|
5531
|
+
if (text === "weekend") return next(6, 0);
|
|
5532
|
+
const [first = "", second] = text.split(" ");
|
|
5533
|
+
if (first === "next" && second && weekdayOf(second) >= 0) return next(weekdayOf(second), 1);
|
|
5534
|
+
if (!second && weekdayOf(first) >= 0) return next(weekdayOf(first), 0);
|
|
5535
|
+
const words = text.split(" ");
|
|
5536
|
+
const month = words.map(monthOf).find((m) => m >= 0) ?? -1;
|
|
5537
|
+
const numbers = words.filter((w) => /^\d{1,4}$/.test(w)).map(Number);
|
|
5538
|
+
if (month >= 0 && words.length <= 3 && words.length === numbers.length + 1) {
|
|
5539
|
+
const [date, year] = numbers;
|
|
5540
|
+
if (!date || date > 31) return null;
|
|
5541
|
+
const make = (y) => `${y}-${pad(month + 1)}-${pad(date)}`;
|
|
5542
|
+
if (year !== void 0) return year >= 1e3 && isDay(make(year)) ? make(year) : null;
|
|
5543
|
+
const thisYear = Number(now.slice(0, 4));
|
|
5544
|
+
const day = make(thisYear);
|
|
5545
|
+
if (!isDay(day)) return null;
|
|
5546
|
+
return day < now ? isDay(make(thisYear + 1)) ? make(thisYear + 1) : null : day;
|
|
5547
|
+
}
|
|
5548
|
+
return null;
|
|
5549
|
+
}
|
|
5550
|
+
/**
|
|
5551
|
+
* A project's Done column, as `monoban done` and the Today view read it: the one named Done (any case),
|
|
5552
|
+
* else the last. `columns` in board order.
|
|
5553
|
+
*/
|
|
5554
|
+
function doneColumn(columns) {
|
|
5555
|
+
return columns.find((c) => c.name.trim().toLowerCase() === "done") ?? columns.at(-1);
|
|
5556
|
+
}
|
|
5557
|
+
//#endregion
|
|
5558
|
+
//#region ../../packages/contract/src/links.ts
|
|
5559
|
+
/** What a task's link points at. */
|
|
5560
|
+
const LINK_KINDS = [
|
|
5561
|
+
"pr",
|
|
5562
|
+
"issue",
|
|
5563
|
+
"commit",
|
|
5564
|
+
"url"
|
|
5565
|
+
];
|
|
5566
|
+
/** A pull request's or an issue's state, as whoever attached it last saw it. */
|
|
5567
|
+
const LINK_STATES = [
|
|
5568
|
+
"open",
|
|
5569
|
+
"draft",
|
|
5570
|
+
"merged",
|
|
5571
|
+
"closed"
|
|
5572
|
+
];
|
|
5573
|
+
const GITHUB = /^\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/([A-Za-z0-9._-]{1,100})\/(pull|issues|commit)\/([0-9A-Fa-f]+)(?:\/|$)/;
|
|
5574
|
+
/**
|
|
5575
|
+
* What a link someone gave points at, or null if it isn't a web link (http or https; "github.com/o/r/pull/54"
|
|
5576
|
+
* without a scheme is https). A GitHub pull request, issue or commit is stored as its canonical URL
|
|
5577
|
+
* (https://github.com/o/r/pull/54, without /files, a query or a #fragment); any other page as given.
|
|
5578
|
+
*/
|
|
5579
|
+
function parseLink(input) {
|
|
5580
|
+
const given = input.trim();
|
|
5581
|
+
if (!given || /[\s\p{Cc}]/u.test(given)) return null;
|
|
5582
|
+
let url;
|
|
5583
|
+
try {
|
|
5584
|
+
url = new URL(/^[a-z][a-z0-9+.-]*:/i.test(given) ? given : `https://${given}`);
|
|
5585
|
+
} catch {
|
|
5586
|
+
return null;
|
|
5587
|
+
}
|
|
5588
|
+
if (url.protocol !== "https:" && url.protocol !== "http:" || !url.hostname.includes(".")) return null;
|
|
5589
|
+
const host = url.hostname.toLowerCase().replace(/^www\./, "");
|
|
5590
|
+
const plain = url.port === "" && url.username === "" && url.password === "";
|
|
5591
|
+
const match = host === "github.com" && plain ? GITHUB.exec(url.pathname) : null;
|
|
5592
|
+
if (match) {
|
|
5593
|
+
const [, owner = "", name = "", type, id = ""] = match;
|
|
5594
|
+
const repo = `github.com/${owner}/${name}`.toLowerCase();
|
|
5595
|
+
const base = `https://github.com/${owner}/${name}`;
|
|
5596
|
+
if (type === "commit" && /^[0-9a-f]{7,40}$/i.test(id)) return {
|
|
5597
|
+
url: `${base}/commit/${id.toLowerCase()}`,
|
|
5598
|
+
kind: "commit",
|
|
5599
|
+
repo,
|
|
5600
|
+
number: null,
|
|
5601
|
+
sha: id.toLowerCase()
|
|
5602
|
+
};
|
|
5603
|
+
if (type !== "commit" && /^[1-9][0-9]{0,8}$/.test(id)) {
|
|
5604
|
+
const kind = type === "pull" ? "pr" : "issue";
|
|
5605
|
+
return {
|
|
5606
|
+
url: `${base}/${type}/${id}`,
|
|
5607
|
+
kind,
|
|
5608
|
+
repo,
|
|
5609
|
+
number: Number(id),
|
|
5610
|
+
sha: null
|
|
5611
|
+
};
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5614
|
+
const href = url.href;
|
|
5615
|
+
return href.length > LIMITS.linkUrl ? null : {
|
|
5616
|
+
url: href,
|
|
5617
|
+
kind: "url",
|
|
5618
|
+
repo: null,
|
|
5619
|
+
number: null,
|
|
5620
|
+
sha: null
|
|
5621
|
+
};
|
|
5622
|
+
}
|
|
5623
|
+
/** How a link is named in a line: "#54", "a1b2c3d", or the page's host ("figma.com"). */
|
|
5624
|
+
function linkLabel(link) {
|
|
5625
|
+
if (link.number !== null) return `#${link.number}`;
|
|
5626
|
+
const parsed = parseLink(link.url);
|
|
5627
|
+
if (parsed?.sha) return parsed.sha.slice(0, 7);
|
|
5628
|
+
try {
|
|
5629
|
+
return new URL(link.url).hostname.replace(/^www\./, "");
|
|
5630
|
+
} catch {
|
|
5631
|
+
return link.url;
|
|
5632
|
+
}
|
|
5633
|
+
}
|
|
5634
|
+
//#endregion
|
|
5391
5635
|
//#region ../../node_modules/.pnpm/fractional-indexing@4.0.0/node_modules/fractional-indexing/src/index.js
|
|
5392
5636
|
const BASE_62_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
5393
5637
|
const BASE_52_DIGITS = BASE_62_DIGITS.slice(10);
|
|
@@ -5731,7 +5975,6 @@ function parseIcon(input) {
|
|
|
5731
5975
|
if (!value || /[\p{C}\s]/u.test(value.replace(/[\u200d\ufe0f\u{e0020}-\u{e007f}]/gu, ""))) return null;
|
|
5732
5976
|
return (segmenter ? [...segmenter.segment(value)].length : [...value].length) === 1 && [...value].length <= 16 ? value : null;
|
|
5733
5977
|
}
|
|
5734
|
-
COLORS.filter((c) => c !== "grey");
|
|
5735
5978
|
/** "mon-12" / "MON-12" → { key: "MON", number: 12 }; null if it isn't a task reference. */
|
|
5736
5979
|
function parseTaskRef(ref) {
|
|
5737
5980
|
const match = /^([A-Za-z][A-Za-z0-9]{1,4})-([1-9][0-9]{0,8})$/.exec(ref.trim());
|
|
@@ -5742,6 +5985,26 @@ function parseTaskRef(ref) {
|
|
|
5742
5985
|
};
|
|
5743
5986
|
}
|
|
5744
5987
|
//#endregion
|
|
5988
|
+
//#region ../../packages/contract/src/tags.ts
|
|
5989
|
+
/** One word, not starting with - or # (the CLI and the board filter read those). Same as the check on tags.name. */
|
|
5990
|
+
const TAG_NAME_PATTERN = /^[^\s#-]\S*$/;
|
|
5991
|
+
/**
|
|
5992
|
+
* The tag name for what someone typed: spaces become dashes ("needs review" → "needs-review"),
|
|
5993
|
+
* leading - and # go, and it is cut to the limit. "" if nothing is left.
|
|
5994
|
+
*/
|
|
5995
|
+
function tagName(input) {
|
|
5996
|
+
return [...input.trim().replace(/\s+/g, "-").replace(/^[-#]+/, "")].slice(0, LIMITS.tagName).join("");
|
|
5997
|
+
}
|
|
5998
|
+
/** The tag called `name`, in any case (with or without a leading #). */
|
|
5999
|
+
function findTag(tags, name) {
|
|
6000
|
+
const wanted = name.trim().replace(/^#/, "").toLowerCase();
|
|
6001
|
+
return tags.find((t) => t.name.toLowerCase() === wanted);
|
|
6002
|
+
}
|
|
6003
|
+
/** Tags in the order they're shown: by name, in any case. */
|
|
6004
|
+
function sortTags(tags) {
|
|
6005
|
+
return [...tags].sort((a, b) => a.name.localeCompare(b.name, "en", { sensitivity: "base" }) || (a.name < b.name ? -1 : 1));
|
|
6006
|
+
}
|
|
6007
|
+
//#endregion
|
|
5745
6008
|
//#region ../../packages/contract/src/schemas.ts
|
|
5746
6009
|
/**
|
|
5747
6010
|
* The API's data shapes. The API validates requests with them and describes responses with them;
|
|
@@ -5771,6 +6034,11 @@ const Version = string().regex(/^[A-Za-z0-9_-]{16}$/).describe("For If-Match; ch
|
|
|
5771
6034
|
* into this form with normalizeRepo() first; the API only lowercases it.
|
|
5772
6035
|
*/
|
|
5773
6036
|
const RepoSchema = string().regex(/^github\.com\/[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/, "A repository like github.com/owner/repo").overwrite((v) => v.toLowerCase()).refine((v) => !/\/\.\.?$/.test(v), "Not a repository name").meta({ example: "github.com/thiagodmont/monoban" });
|
|
6037
|
+
/** A day, without a time or a time zone: "2026-10-12". */
|
|
6038
|
+
const DaySchema = string().regex(/^\d{4}-\d{2}-\d{2}$/, "A day like 2026-10-12").refine(isDay, "Not a real day").meta({
|
|
6039
|
+
format: "date",
|
|
6040
|
+
example: "2026-10-12"
|
|
6041
|
+
});
|
|
5774
6042
|
/** A Postgres uuid: any 8-4-4-4-12 hex id (not only RFC 9562 versions, which is what z.uuid() checks). */
|
|
5775
6043
|
const IdSchema = guid();
|
|
5776
6044
|
const ProjectSchema = object({
|
|
@@ -5785,6 +6053,10 @@ const ProjectSchema = object({
|
|
|
5785
6053
|
taskCount: number$1().int().nonnegative(),
|
|
5786
6054
|
/** The GitHub repository it's linked to, if any. */
|
|
5787
6055
|
repo: string().nullable(),
|
|
6056
|
+
/** The web board opens a task after you add it, so you can write its description. */
|
|
6057
|
+
openNewTasks: boolean(),
|
|
6058
|
+
/** Days a task stays in the Done column before it's archived (off the board); null: never. */
|
|
6059
|
+
archiveAfterDays: number$1().int().min(1).max(365).nullable(),
|
|
5788
6060
|
createdAt: Timestamp,
|
|
5789
6061
|
updatedAt: Timestamp
|
|
5790
6062
|
}).meta({ id: "Project" });
|
|
@@ -5811,7 +6083,11 @@ strictObject({
|
|
|
5811
6083
|
/** New place in the project list (a key between the neighbours). */
|
|
5812
6084
|
position: PositionSchema.optional(),
|
|
5813
6085
|
/** Link a GitHub repository; null unlinks. One project per repository (409 if another has it). */
|
|
5814
|
-
repo: RepoSchema.nullable().optional()
|
|
6086
|
+
repo: RepoSchema.nullable().optional(),
|
|
6087
|
+
/** Open a task on the web board after adding it. */
|
|
6088
|
+
openNewTasks: boolean().optional(),
|
|
6089
|
+
/** Days in Done before a task is archived (1–365); null: never. */
|
|
6090
|
+
archiveAfterDays: number$1().int().min(1).max(365).nullable().optional()
|
|
5815
6091
|
}).refine((patch) => Object.keys(patch).length > 0, "Send at least one field to change").meta({
|
|
5816
6092
|
id: "ProjectPatch",
|
|
5817
6093
|
minProperties: 1
|
|
@@ -5854,11 +6130,80 @@ object({
|
|
|
5854
6130
|
/** How many tasks moved (to the end of that column, in their order). */
|
|
5855
6131
|
moved: number$1().int().nonnegative()
|
|
5856
6132
|
}).meta({ id: "ColumnDeleted" });
|
|
6133
|
+
/** A tag's name: one word (no spaces), not starting with - or #. Unique, in any case, among the tags a board offers. */
|
|
6134
|
+
const TagNameSchema = text().min(1, "Required").max(LIMITS.tagName).regex(TAG_NAME_PATTERN, "One word (no spaces), not starting with - or #").refine((v) => !/[\u0000-\u001f\u007f]/.test(v), "Can't contain control characters");
|
|
6135
|
+
const TagSchema = object({
|
|
6136
|
+
id: IdSchema,
|
|
6137
|
+
name: string(),
|
|
6138
|
+
color: ColorSchema,
|
|
6139
|
+
/** The project it belongs to; null: shared by all your projects. */
|
|
6140
|
+
project: ProjectKeySchema.nullable(),
|
|
6141
|
+
version: Version,
|
|
6142
|
+
/** How many tasks have it (in every project, for a shared tag). */
|
|
6143
|
+
taskCount: number$1().int().nonnegative(),
|
|
6144
|
+
createdAt: Timestamp
|
|
6145
|
+
}).meta({ id: "Tag" });
|
|
6146
|
+
strictObject({
|
|
6147
|
+
/** Chosen by the client (a random uuid) so it can show and use the new tag before the answer; 409 if taken. */
|
|
6148
|
+
id: IdSchema.optional(),
|
|
6149
|
+
name: TagNameSchema,
|
|
6150
|
+
/** The least used colour when left out. */
|
|
6151
|
+
color: ColorSchema.optional(),
|
|
6152
|
+
/** The project it belongs to (its key), or null to share it with all your projects. */
|
|
6153
|
+
project: ProjectKeySchema.nullable()
|
|
6154
|
+
}).meta({ id: "TagCreate" });
|
|
6155
|
+
strictObject({
|
|
6156
|
+
name: TagNameSchema.optional(),
|
|
6157
|
+
color: ColorSchema.optional(),
|
|
6158
|
+
/**
|
|
6159
|
+
* Share it with all your projects (null), or keep it to one project (its key). A tag can move to a
|
|
6160
|
+
* project only if every task it is on is in that project (409 otherwise).
|
|
6161
|
+
*/
|
|
6162
|
+
project: ProjectKeySchema.nullable().optional()
|
|
6163
|
+
}).refine((patch) => Object.keys(patch).length > 0, "Send at least one field to change").meta({
|
|
6164
|
+
id: "TagPatch",
|
|
6165
|
+
minProperties: 1
|
|
6166
|
+
});
|
|
6167
|
+
/** A task's tags: ids of its project's tags or shared ones, at most 10, each once. */
|
|
6168
|
+
const tagIds = array(IdSchema).max(LIMITS.tagsPerTask).refine((ids) => new Set(ids.map((id) => id.toLowerCase())).size === ids.length, "Each tag once").meta({ uniqueItems: true });
|
|
5857
6169
|
const taskTitle = text().min(1, "Required").max(LIMITS.taskTitle);
|
|
5858
6170
|
/** Markdown; kept as written (not trimmed). */
|
|
5859
6171
|
const taskDescription = string().max(LIMITS.taskDescription).regex(/^[^\u0000]*$/, "Can't contain NUL characters");
|
|
5860
6172
|
string().regex(/^[A-Za-z][A-Za-z0-9]{1,4}-[1-9][0-9]{0,8}$/, "A task reference like MON-12").meta({ example: "MON-12" });
|
|
5861
6173
|
number().int().min(1).max(2147483647);
|
|
6174
|
+
/**
|
|
6175
|
+
* A web page attached to a task: a pull request, an issue, a commit, or any other page. The kind, repo and
|
|
6176
|
+
* number come from the URL (parseLink); the title and state are what the client that attached it knew.
|
|
6177
|
+
*/
|
|
6178
|
+
const TaskLinkSchema = object({
|
|
6179
|
+
id: IdSchema,
|
|
6180
|
+
url: string(),
|
|
6181
|
+
kind: _enum(LINK_KINDS),
|
|
6182
|
+
title: string(),
|
|
6183
|
+
/** A pull request's or an issue's state, when it was read (`checkedAt`); null if nobody said. */
|
|
6184
|
+
state: _enum(LINK_STATES).nullable(),
|
|
6185
|
+
/** github.com/owner/repo, for GitHub links. */
|
|
6186
|
+
repo: string().nullable(),
|
|
6187
|
+
/** A pull request's or an issue's number. */
|
|
6188
|
+
number: number$1().int().positive().nullable(),
|
|
6189
|
+
checkedAt: Timestamp.nullable(),
|
|
6190
|
+
version: Version,
|
|
6191
|
+
createdAt: Timestamp
|
|
6192
|
+
}).meta({ id: "TaskLink" });
|
|
6193
|
+
const linkUrl = string().trim().min(1, "Required").max(LIMITS.linkUrl).describe("An http(s) link; github.com/o/r/pull/54 without a scheme is https");
|
|
6194
|
+
const linkTitle = text().max(LIMITS.linkTitle).regex(/^[^\u0000-\u001f\u007f]*$/, "One line");
|
|
6195
|
+
strictObject({
|
|
6196
|
+
/** For a new link, chosen by the client (a random uuid) so it can show and remove it before the answer. */
|
|
6197
|
+
id: IdSchema.optional(),
|
|
6198
|
+
url: linkUrl,
|
|
6199
|
+
/** Left out: keeps the title it has (none for a new link). */
|
|
6200
|
+
title: linkTitle.optional(),
|
|
6201
|
+
/**
|
|
6202
|
+
* Left out: keeps the state it has. Pull requests: open, draft, merged or closed; issues: open or
|
|
6203
|
+
* closed; other links have none (400).
|
|
6204
|
+
*/
|
|
6205
|
+
state: _enum(LINK_STATES).nullable().optional()
|
|
6206
|
+
}).meta({ id: "TaskLinkCreate" });
|
|
5862
6207
|
strictObject({
|
|
5863
6208
|
/** Chosen by the client (a random uuid) so it can show and edit the new item before the answer; 409 if taken. */
|
|
5864
6209
|
id: IdSchema.optional(),
|
|
@@ -5867,7 +6212,10 @@ strictObject({
|
|
|
5867
6212
|
/** The project's first column when left out. */
|
|
5868
6213
|
columnId: IdSchema.optional(),
|
|
5869
6214
|
/** Where it goes in the column; the end when left out. */
|
|
5870
|
-
position: PositionSchema.optional()
|
|
6215
|
+
position: PositionSchema.optional(),
|
|
6216
|
+
tagIds: tagIds.optional(),
|
|
6217
|
+
/** The day you plan to work on it. */
|
|
6218
|
+
scheduledOn: DaySchema.nullable().optional()
|
|
5871
6219
|
}).meta({ id: "TaskCreate" });
|
|
5872
6220
|
strictObject({
|
|
5873
6221
|
title: taskTitle.optional(),
|
|
@@ -5875,11 +6223,29 @@ strictObject({
|
|
|
5875
6223
|
/** Move to another column (to its end, unless you also give a position). */
|
|
5876
6224
|
columnId: IdSchema.optional(),
|
|
5877
6225
|
/** New place in the column. */
|
|
5878
|
-
position: PositionSchema.optional()
|
|
6226
|
+
position: PositionSchema.optional(),
|
|
6227
|
+
/** Its tags from now on (all of them: the list replaces the old one). */
|
|
6228
|
+
tagIds: tagIds.optional(),
|
|
6229
|
+
/** The day you plan to work on it; null takes the date off. */
|
|
6230
|
+
scheduledOn: DaySchema.nullable().optional()
|
|
5879
6231
|
}).refine((patch) => Object.keys(patch).length > 0, "Send at least one field to change").meta({
|
|
5880
6232
|
id: "TaskPatch",
|
|
5881
6233
|
minProperties: 1
|
|
5882
6234
|
});
|
|
6235
|
+
strictObject({
|
|
6236
|
+
/** The project's key (MON). */
|
|
6237
|
+
project: ProjectKeySchema,
|
|
6238
|
+
/** A column of that project; left out: the one named like the task's column now (any case), else the first. */
|
|
6239
|
+
columnId: IdSchema.optional(),
|
|
6240
|
+
/** Where it goes in the column (with `columnId`); its end when left out. */
|
|
6241
|
+
position: PositionSchema.optional()
|
|
6242
|
+
}).refine((body) => body.position === void 0 || body.columnId !== void 0, {
|
|
6243
|
+
message: "position needs a columnId",
|
|
6244
|
+
path: ["position"]
|
|
6245
|
+
}).meta({
|
|
6246
|
+
id: "TaskTransfer",
|
|
6247
|
+
dependentRequired: { position: ["columnId"] }
|
|
6248
|
+
});
|
|
5883
6249
|
strictObject({
|
|
5884
6250
|
id: IdSchema,
|
|
5885
6251
|
/** Optional (the path has it); if sent, it must match. */
|
|
@@ -5888,7 +6254,19 @@ strictObject({
|
|
|
5888
6254
|
title: taskTitle,
|
|
5889
6255
|
description: taskDescription,
|
|
5890
6256
|
position: PositionSchema,
|
|
6257
|
+
/** Tags deleted since are left out. */
|
|
6258
|
+
tagIds: tagIds.optional(),
|
|
6259
|
+
scheduledOn: DaySchema.nullable().optional(),
|
|
6260
|
+
/** Its links, as DELETE returned them (only these fields are read). */
|
|
6261
|
+
links: array(object({
|
|
6262
|
+
url: linkUrl,
|
|
6263
|
+
title: linkTitle,
|
|
6264
|
+
state: _enum(LINK_STATES).nullable(),
|
|
6265
|
+
checkedAt: Timestamp.nullable().optional()
|
|
6266
|
+
})).max(LIMITS.linksPerTask).optional(),
|
|
5891
6267
|
createdAt: datetime({ offset: true }).optional(),
|
|
6268
|
+
/** When it came into its column, so an undone delete doesn't start its archive clock again. */
|
|
6269
|
+
columnSince: Timestamp.optional(),
|
|
5892
6270
|
ref: string().optional(),
|
|
5893
6271
|
version: string().optional(),
|
|
5894
6272
|
updatedAt: string().optional()
|
|
@@ -5902,11 +6280,107 @@ const TaskSchema = object({
|
|
|
5902
6280
|
title: string(),
|
|
5903
6281
|
description: string(),
|
|
5904
6282
|
position: PositionSchema,
|
|
6283
|
+
/** Its tags' ids (see the board's `tags`), sorted. */
|
|
6284
|
+
tagIds: array(IdSchema),
|
|
6285
|
+
/** What's attached to it (pull requests, issues, pages), oldest first. They aren't part of its version. */
|
|
6286
|
+
links: array(TaskLinkSchema),
|
|
6287
|
+
/** The day you plan to work on it (not a deadline), or null. */
|
|
6288
|
+
scheduledOn: DaySchema.nullable(),
|
|
6289
|
+
/** When it came into its column. In the Done column for longer than its project's archiveAfterDays, it's archived. */
|
|
6290
|
+
columnSince: Timestamp,
|
|
5905
6291
|
version: Version,
|
|
5906
6292
|
createdAt: Timestamp,
|
|
5907
6293
|
updatedAt: Timestamp
|
|
5908
6294
|
}).meta({ id: "Task" });
|
|
5909
6295
|
/**
|
|
6296
|
+
* A column or tag in a task's history: as it was named then (it may have been renamed or deleted since).
|
|
6297
|
+
* The column has no OpenAPI name: it's nullable in places, and a named schema would be nullable everywhere.
|
|
6298
|
+
*/
|
|
6299
|
+
const EventColumn = object({
|
|
6300
|
+
id: IdSchema,
|
|
6301
|
+
name: string(),
|
|
6302
|
+
color: ColorSchema
|
|
6303
|
+
});
|
|
6304
|
+
/** Where a task was, or went, when it changed project: the project, the task's reference there, its column. */
|
|
6305
|
+
const EventPlace = object({
|
|
6306
|
+
project: object({
|
|
6307
|
+
id: IdSchema,
|
|
6308
|
+
key: string(),
|
|
6309
|
+
name: string()
|
|
6310
|
+
}),
|
|
6311
|
+
ref: string(),
|
|
6312
|
+
column: EventColumn
|
|
6313
|
+
}).meta({ id: "EventPlace" });
|
|
6314
|
+
const EventTag = object({
|
|
6315
|
+
id: IdSchema,
|
|
6316
|
+
name: string(),
|
|
6317
|
+
color: ColorSchema
|
|
6318
|
+
}).meta({ id: "EventTag" });
|
|
6319
|
+
const EventLink = object({
|
|
6320
|
+
id: IdSchema,
|
|
6321
|
+
url: string(),
|
|
6322
|
+
kind: _enum(LINK_KINDS),
|
|
6323
|
+
title: string(),
|
|
6324
|
+
state: _enum(LINK_STATES).nullable()
|
|
6325
|
+
}).meta({ id: "EventLink" });
|
|
6326
|
+
const event = (kind, shape) => object({
|
|
6327
|
+
/** Newer events have larger ids. */
|
|
6328
|
+
id: string().regex(/^[1-9][0-9]*$/),
|
|
6329
|
+
kind: literal(kind),
|
|
6330
|
+
...shape,
|
|
6331
|
+
/** What made the change: `web`, `cli` or `api` (another client); null for what happened before history began. */
|
|
6332
|
+
via: string().nullable(),
|
|
6333
|
+
createdAt: Timestamp,
|
|
6334
|
+
/** Later than `createdAt` when a burst of changes merged into this event (typing, toggling tags). */
|
|
6335
|
+
updatedAt: Timestamp
|
|
6336
|
+
});
|
|
6337
|
+
discriminatedUnion("kind", [
|
|
6338
|
+
event("created", {
|
|
6339
|
+
/** Null for tasks made before history began. */
|
|
6340
|
+
column: EventColumn.nullable(),
|
|
6341
|
+
title: string().nullable(),
|
|
6342
|
+
tags: array(EventTag),
|
|
6343
|
+
/** The day it was made for, if it was made with one. */
|
|
6344
|
+
scheduledOn: DaySchema.nullable()
|
|
6345
|
+
}),
|
|
6346
|
+
event("moved", {
|
|
6347
|
+
from: EventColumn,
|
|
6348
|
+
to: EventColumn
|
|
6349
|
+
}),
|
|
6350
|
+
event("renamed", {
|
|
6351
|
+
from: string(),
|
|
6352
|
+
to: string()
|
|
6353
|
+
}),
|
|
6354
|
+
event("edited", {
|
|
6355
|
+
from: number$1().int().nonnegative(),
|
|
6356
|
+
to: number$1().int().nonnegative()
|
|
6357
|
+
}),
|
|
6358
|
+
event("tagged", {
|
|
6359
|
+
added: array(EventTag),
|
|
6360
|
+
removed: array(EventTag)
|
|
6361
|
+
}),
|
|
6362
|
+
event("linked", { link: EventLink }),
|
|
6363
|
+
event("unlinked", { link: EventLink }),
|
|
6364
|
+
event("link_state", {
|
|
6365
|
+
link: EventLink,
|
|
6366
|
+
from: _enum(LINK_STATES).nullable(),
|
|
6367
|
+
to: _enum(LINK_STATES).nullable()
|
|
6368
|
+
}),
|
|
6369
|
+
event("deleted", {
|
|
6370
|
+
title: string(),
|
|
6371
|
+
column: EventColumn.nullable()
|
|
6372
|
+
}),
|
|
6373
|
+
event("restored", { column: EventColumn.nullable() }),
|
|
6374
|
+
event("scheduled", {
|
|
6375
|
+
from: DaySchema.nullable(),
|
|
6376
|
+
to: DaySchema.nullable()
|
|
6377
|
+
}),
|
|
6378
|
+
event("transferred", {
|
|
6379
|
+
from: EventPlace,
|
|
6380
|
+
to: EventPlace
|
|
6381
|
+
})
|
|
6382
|
+
]).meta({ id: "TaskEvent" });
|
|
6383
|
+
/**
|
|
5910
6384
|
* Every list takes `?limit=` and `?cursor=` and answers `{ <items>: [...], nextCursor }` (keyset
|
|
5911
6385
|
* pagination; see docs/PLAN-API-CLI.md §4.1). `nextCursor` is null on the last page.
|
|
5912
6386
|
*/
|
|
@@ -5914,17 +6388,76 @@ const PAGE_LIMIT = {
|
|
|
5914
6388
|
default: 100,
|
|
5915
6389
|
max: 200
|
|
5916
6390
|
};
|
|
5917
|
-
|
|
6391
|
+
/** Strict, like every request schema: a typo such as `?colum=backlog` is a 400, not a silently wider list. */
|
|
6392
|
+
const PageQuerySchema = strictObject({
|
|
5918
6393
|
limit: number().int().min(1).max(PAGE_LIMIT.max).default(PAGE_LIMIT.default).describe("Items per page"),
|
|
5919
6394
|
cursor: string().min(1).max(1024).optional().describe("`nextCursor` from the previous page")
|
|
5920
6395
|
});
|
|
6396
|
+
PageQuerySchema.extend({
|
|
6397
|
+
from: DaySchema.describe("The first day (the client's today, for Today)"),
|
|
6398
|
+
to: DaySchema.optional().describe("The last day (`from` when left out); at most 62 days after `from`"),
|
|
6399
|
+
overdue: _enum(["true", "false"]).optional().describe("Also the tasks scheduled before `from` that aren't done (not in their project's Done column)")
|
|
6400
|
+
});
|
|
6401
|
+
/** Where a task is, for a list across projects: its project and column, and whether it's done. */
|
|
6402
|
+
const TaskPlace = {
|
|
6403
|
+
project: object({
|
|
6404
|
+
key: ProjectKeySchema,
|
|
6405
|
+
name: string(),
|
|
6406
|
+
icon: string().nullable(),
|
|
6407
|
+
color: ColorSchema
|
|
6408
|
+
}),
|
|
6409
|
+
column: object({
|
|
6410
|
+
id: IdSchema,
|
|
6411
|
+
name: string(),
|
|
6412
|
+
color: ColorSchema
|
|
6413
|
+
}),
|
|
6414
|
+
/** In its project's Done column (the one named Done, else the last). */
|
|
6415
|
+
done: boolean()
|
|
6416
|
+
};
|
|
6417
|
+
TaskSchema.extend({
|
|
6418
|
+
...TaskPlace,
|
|
6419
|
+
scheduledOn: DaySchema
|
|
6420
|
+
}).meta({ id: "ScheduledTask" });
|
|
6421
|
+
/** The longest search, and the most words in it. */
|
|
6422
|
+
const SEARCH_LIMITS = {
|
|
6423
|
+
length: 200,
|
|
6424
|
+
words: 8
|
|
6425
|
+
};
|
|
6426
|
+
PageQuerySchema.extend({ q: string().trim().min(1).max(SEARCH_LIMITS.length).regex(/^[^\u0000]*$/).describe(`Words, all of which a task must have (any case): in its title or description, as its tag's name, or as its reference (\`MON-12\`). At most ${SEARCH_LIMITS.words} words.`) });
|
|
6427
|
+
TaskSchema.extend({
|
|
6428
|
+
...TaskPlace,
|
|
6429
|
+
/** Done long enough ago that its board leaves it out (its project's archive setting). */
|
|
6430
|
+
archived: boolean()
|
|
6431
|
+
}).meta({ id: "FoundTask" });
|
|
5921
6432
|
object({
|
|
5922
6433
|
project: ProjectSchema,
|
|
5923
6434
|
columns: array(ColumnSchema),
|
|
6435
|
+
/** The tags its tasks can have: the project's own and the shared ones, by name. */
|
|
6436
|
+
tags: array(TagSchema),
|
|
6437
|
+
/** Its tasks, except the archived ones (`GET …/tasks?archived=true` lists those). */
|
|
5924
6438
|
tasks: array(TaskSchema),
|
|
6439
|
+
/** How many archived tasks it leaves out. */
|
|
6440
|
+
archived: number$1().int().nonnegative(),
|
|
5925
6441
|
/** More tasks than the board returns at once (2,000): load the rest from the paginated task list. */
|
|
5926
6442
|
truncated: boolean()
|
|
5927
6443
|
}).meta({ id: "Board" });
|
|
6444
|
+
/** Notes text: kept as written (not trimmed). */
|
|
6445
|
+
const notesText = string().max(LIMITS.projectNotes).regex(/^[^\u0000]*$/, "Can't contain NUL characters");
|
|
6446
|
+
object({
|
|
6447
|
+
text: string(),
|
|
6448
|
+
version: Version,
|
|
6449
|
+
/** Null until the notes are first written. */
|
|
6450
|
+
updatedAt: Timestamp.nullable()
|
|
6451
|
+
}).meta({ id: "Notes" });
|
|
6452
|
+
strictObject({
|
|
6453
|
+
text: notesText.optional(),
|
|
6454
|
+
/** Added on a line of its own (after a newline, unless the notes are empty or end with one). */
|
|
6455
|
+
append: notesText.min(1).optional()
|
|
6456
|
+
}).refine((patch) => patch.text === void 0 !== (patch.append === void 0), "Send either text or append").meta({
|
|
6457
|
+
id: "NotesPatch",
|
|
6458
|
+
minProperties: 1,
|
|
6459
|
+
maxProperties: 1
|
|
6460
|
+
});
|
|
5928
6461
|
/** Every error response (RFC 9457, `application/problem+json`). */
|
|
5929
6462
|
const ProblemSchema = object({
|
|
5930
6463
|
type: string(),
|
|
@@ -6558,6 +7091,126 @@ async function* pages(fetchPage) {
|
|
|
6558
7091
|
} while (cursor);
|
|
6559
7092
|
}
|
|
6560
7093
|
//#endregion
|
|
7094
|
+
//#region ../../packages/contract/src/history.ts
|
|
7095
|
+
const KIND_NAMES = {
|
|
7096
|
+
pr: "PR ",
|
|
7097
|
+
issue: "issue ",
|
|
7098
|
+
commit: "commit ",
|
|
7099
|
+
url: ""
|
|
7100
|
+
};
|
|
7101
|
+
/** How a link is named in a task's history: "PR #54", "issue #3", "commit a1b2c3d", "figma.com". */
|
|
7102
|
+
function eventLinkName(link) {
|
|
7103
|
+
const number = parseLink(link.url)?.number ?? null;
|
|
7104
|
+
return `${KIND_NAMES[link.kind]}${linkLabel({
|
|
7105
|
+
...link,
|
|
7106
|
+
number
|
|
7107
|
+
})}`;
|
|
7108
|
+
}
|
|
7109
|
+
/** What a pull request's or issue's new state says it did. */
|
|
7110
|
+
function stateVerb(from, to) {
|
|
7111
|
+
if (to === "open") return from === "merged" || from === "closed" ? "reopened" : "opened";
|
|
7112
|
+
if (to === "draft") return "drafted";
|
|
7113
|
+
return to ?? "updated";
|
|
7114
|
+
}
|
|
7115
|
+
const signed = (n) => n > 0 ? `+${n}` : `−${-n}`;
|
|
7116
|
+
/**
|
|
7117
|
+
* A history event in words, for a line: a verb ("moved") and what it did ("To do → In progress"). The web
|
|
7118
|
+
* draws some of it richer (column dots, tag chips); the words are the same.
|
|
7119
|
+
*/
|
|
7120
|
+
function describeEvent(event, now = today()) {
|
|
7121
|
+
const day = (d) => formatDay(d, now);
|
|
7122
|
+
switch (event.kind) {
|
|
7123
|
+
case "created": {
|
|
7124
|
+
const tags = event.tags.map((t) => `#${t.name}`);
|
|
7125
|
+
const when = event.scheduledOn && `for ${day(event.scheduledOn)}`;
|
|
7126
|
+
return {
|
|
7127
|
+
verb: "created",
|
|
7128
|
+
detail: [
|
|
7129
|
+
event.column && `in ${event.column.name}`,
|
|
7130
|
+
...tags,
|
|
7131
|
+
when
|
|
7132
|
+
].filter(Boolean).join(" ")
|
|
7133
|
+
};
|
|
7134
|
+
}
|
|
7135
|
+
case "scheduled":
|
|
7136
|
+
if (!event.to) return {
|
|
7137
|
+
verb: "unscheduled",
|
|
7138
|
+
detail: event.from ? `(was ${day(event.from)})` : ""
|
|
7139
|
+
};
|
|
7140
|
+
return {
|
|
7141
|
+
verb: "scheduled",
|
|
7142
|
+
detail: event.from ? `${day(event.from)} → ${day(event.to)}` : `for ${day(event.to)}`
|
|
7143
|
+
};
|
|
7144
|
+
case "moved": return {
|
|
7145
|
+
verb: "moved",
|
|
7146
|
+
detail: `${event.from.name} → ${event.to.name}`
|
|
7147
|
+
};
|
|
7148
|
+
case "transferred": return {
|
|
7149
|
+
verb: "moved",
|
|
7150
|
+
detail: `${event.from.ref} → ${event.to.ref} (${event.to.project.name}, ${event.to.column.name})`
|
|
7151
|
+
};
|
|
7152
|
+
case "renamed": return {
|
|
7153
|
+
verb: "renamed",
|
|
7154
|
+
detail: `${event.from} → ${event.to}`
|
|
7155
|
+
};
|
|
7156
|
+
case "edited": {
|
|
7157
|
+
if (event.from === 0) return {
|
|
7158
|
+
verb: "edited",
|
|
7159
|
+
detail: `description (new, ${event.to} chars)`
|
|
7160
|
+
};
|
|
7161
|
+
if (event.to === 0) return {
|
|
7162
|
+
verb: "edited",
|
|
7163
|
+
detail: "description (cleared)"
|
|
7164
|
+
};
|
|
7165
|
+
const delta = event.to - event.from;
|
|
7166
|
+
return {
|
|
7167
|
+
verb: "edited",
|
|
7168
|
+
detail: delta ? `description (${signed(delta)} chars)` : "description"
|
|
7169
|
+
};
|
|
7170
|
+
}
|
|
7171
|
+
case "tagged": return {
|
|
7172
|
+
verb: "tagged",
|
|
7173
|
+
detail: [...event.added.map((t) => `+${t.name}`), ...event.removed.map((t) => `−${t.name}`)].join(" ")
|
|
7174
|
+
};
|
|
7175
|
+
case "linked":
|
|
7176
|
+
case "unlinked": {
|
|
7177
|
+
const { link } = event;
|
|
7178
|
+
return {
|
|
7179
|
+
verb: event.kind,
|
|
7180
|
+
detail: [eventLinkName(link), link.title].filter(Boolean).join(" ")
|
|
7181
|
+
};
|
|
7182
|
+
}
|
|
7183
|
+
case "link_state": {
|
|
7184
|
+
const was = event.from ? ` (was ${event.from})` : "";
|
|
7185
|
+
return {
|
|
7186
|
+
verb: stateVerb(event.from, event.to),
|
|
7187
|
+
detail: `${eventLinkName(event.link)}${was}`
|
|
7188
|
+
};
|
|
7189
|
+
}
|
|
7190
|
+
case "deleted": return {
|
|
7191
|
+
verb: "deleted",
|
|
7192
|
+
detail: event.column ? `from ${event.column.name}` : ""
|
|
7193
|
+
};
|
|
7194
|
+
case "restored": return {
|
|
7195
|
+
verb: "restored",
|
|
7196
|
+
detail: event.column ? `to ${event.column.name}` : ""
|
|
7197
|
+
};
|
|
7198
|
+
}
|
|
7199
|
+
}
|
|
7200
|
+
const MINUTE = 6e4;
|
|
7201
|
+
/** How long ago, in a few characters, for a history line: "now", "5m", "3h", "2d", "5mo", "2y". */
|
|
7202
|
+
function eventAge(iso, now = Date.now()) {
|
|
7203
|
+
const minutes = Math.floor((now - new Date(iso).getTime()) / MINUTE);
|
|
7204
|
+
if (minutes < 1) return "now";
|
|
7205
|
+
if (minutes < 60) return `${minutes}m`;
|
|
7206
|
+
const hours = Math.floor(minutes / 60);
|
|
7207
|
+
if (hours < 24) return `${hours}h`;
|
|
7208
|
+
const days = Math.floor(hours / 24);
|
|
7209
|
+
if (days < 60) return `${days}d`;
|
|
7210
|
+
if (days < 730) return `${Math.floor(days / 30)}mo`;
|
|
7211
|
+
return `${Math.floor(days / 365)}y`;
|
|
7212
|
+
}
|
|
7213
|
+
//#endregion
|
|
6561
7214
|
//#region ../../packages/contract/src/repo.ts
|
|
6562
7215
|
/**
|
|
6563
7216
|
* A project's linked repository, in the one form the database stores: github.com/<owner>/<repo>,
|
|
@@ -6635,10 +7288,20 @@ function matchColumn(columns, query) {
|
|
|
6635
7288
|
choices: [...columns]
|
|
6636
7289
|
};
|
|
6637
7290
|
}
|
|
7291
|
+
const DAY_MS = 864e5;
|
|
7292
|
+
/**
|
|
7293
|
+
* Whether a task is archived: in its project's Done column (`doneColumnId`: doneColumn()) for longer
|
|
7294
|
+
* than the project's `archiveAfterDays` (null: never). The API applies the same rule when it reads.
|
|
7295
|
+
*/
|
|
7296
|
+
function isArchived(task, doneColumnId, archiveAfterDays, now = Date.now()) {
|
|
7297
|
+
if (archiveAfterDays === null || !doneColumnId || task.columnId !== doneColumnId) return false;
|
|
7298
|
+
return Date.parse(task.columnSince) < now - archiveAfterDays * DAY_MS;
|
|
7299
|
+
}
|
|
7300
|
+
strictObject({ email: email().max(254).meta({ example: "ada@example.com" }) }).meta({ id: "WaitlistJoin" });
|
|
6638
7301
|
//#endregion
|
|
6639
7302
|
//#region src/version.ts
|
|
6640
7303
|
/** This CLI's version, from package.json (set at build time by tsdown, and by vitest in tests). */
|
|
6641
|
-
const VERSION = "1.
|
|
7304
|
+
const VERSION = "1.2.0";
|
|
6642
7305
|
/** Sent as X-Monoban-Client, and shown in Devices & tokens. */
|
|
6643
7306
|
const CLIENT = `cli/${VERSION}`;
|
|
6644
7307
|
//#endregion
|
|
@@ -9967,6 +10630,18 @@ function git(cwd, ...args) {
|
|
|
9967
10630
|
}, (err, stdout) => resolve(err ? null : stdout.trim()));
|
|
9968
10631
|
});
|
|
9969
10632
|
}
|
|
10633
|
+
/** Runs git in `cwd` and says what went wrong when it fails (git's own message). */
|
|
10634
|
+
function gitOrWhy(cwd, ...args) {
|
|
10635
|
+
return new Promise((resolve) => {
|
|
10636
|
+
execFile("git", args, {
|
|
10637
|
+
cwd,
|
|
10638
|
+
timeout: 15e3
|
|
10639
|
+
}, (err, _stdout, stderr) => resolve(err ? {
|
|
10640
|
+
ok: false,
|
|
10641
|
+
why: stderr.trim() || err.message
|
|
10642
|
+
} : { ok: true }));
|
|
10643
|
+
});
|
|
10644
|
+
}
|
|
9970
10645
|
function clone(cwd = process.cwd()) {
|
|
9971
10646
|
return {
|
|
9972
10647
|
project: async () => await git(cwd, "config", "--local", "--get", "monoban.project") || null,
|
|
@@ -9980,6 +10655,80 @@ function clone(cwd = process.cwd()) {
|
|
|
9980
10655
|
remember: async (key) => await git(cwd, "config", "--local", "monoban.project", key) !== null,
|
|
9981
10656
|
forget: async () => {
|
|
9982
10657
|
await git(cwd, "config", "--local", "--unset", "monoban.project");
|
|
10658
|
+
},
|
|
10659
|
+
branch: async () => {
|
|
10660
|
+
const name = await git(cwd, "rev-parse", "--abbrev-ref", "HEAD");
|
|
10661
|
+
return name && name !== "HEAD" ? name : null;
|
|
10662
|
+
},
|
|
10663
|
+
root: async () => await git(cwd, "rev-parse", "--show-toplevel") || cwd,
|
|
10664
|
+
inClone: async () => await git(cwd, "rev-parse", "--is-inside-work-tree") === "true",
|
|
10665
|
+
branches: async () => (await git(cwd, "branch", "--list", "--format=%(refname:short)") ?? "").split("\n").filter(Boolean),
|
|
10666
|
+
switchTo: async (name, create) => {
|
|
10667
|
+
const result = await gitOrWhy(cwd, "switch", ...create ? ["-c", name] : [name]);
|
|
10668
|
+
return result.ok ? null : result.why;
|
|
10669
|
+
}
|
|
10670
|
+
};
|
|
10671
|
+
}
|
|
10672
|
+
//#endregion
|
|
10673
|
+
//#region src/github.ts
|
|
10674
|
+
/** `gh` isn't installed. */
|
|
10675
|
+
var NoGh = class extends CliError {
|
|
10676
|
+
constructor() {
|
|
10677
|
+
super("That needs the GitHub CLI (gh), signed in: https://cli.github.com");
|
|
10678
|
+
this.name = "NoGh";
|
|
10679
|
+
}
|
|
10680
|
+
};
|
|
10681
|
+
function gh(cwd, args) {
|
|
10682
|
+
return new Promise((resolve, reject) => {
|
|
10683
|
+
execFile("gh", args, {
|
|
10684
|
+
cwd,
|
|
10685
|
+
timeout: 15e3
|
|
10686
|
+
}, (err, stdout, stderr) => {
|
|
10687
|
+
if (err?.code === "ENOENT") return reject(new NoGh());
|
|
10688
|
+
if (err) return reject(new CliError(`gh: ${String(stderr).trim().split("\n")[0] || err.message}`));
|
|
10689
|
+
try {
|
|
10690
|
+
resolve(JSON.parse(String(stdout)));
|
|
10691
|
+
} catch {
|
|
10692
|
+
reject(new CliError("gh answered something that isn't JSON."));
|
|
10693
|
+
}
|
|
10694
|
+
});
|
|
10695
|
+
});
|
|
10696
|
+
}
|
|
10697
|
+
/** OPEN, CLOSED, MERGED (and a draft pull request) → monoban's states. */
|
|
10698
|
+
function stateOf(state, isDraft = false) {
|
|
10699
|
+
if (state === "MERGED") return "merged";
|
|
10700
|
+
if (state === "CLOSED") return "closed";
|
|
10701
|
+
return isDraft ? "draft" : "open";
|
|
10702
|
+
}
|
|
10703
|
+
function github(cwd = process.cwd()) {
|
|
10704
|
+
return {
|
|
10705
|
+
pullRequest: async (ref) => {
|
|
10706
|
+
const pr = await gh(cwd, [
|
|
10707
|
+
"pr",
|
|
10708
|
+
"view",
|
|
10709
|
+
...ref ? [ref] : [],
|
|
10710
|
+
"--json",
|
|
10711
|
+
"url,title,state,isDraft"
|
|
10712
|
+
]);
|
|
10713
|
+
return {
|
|
10714
|
+
url: pr.url,
|
|
10715
|
+
title: pr.title,
|
|
10716
|
+
state: stateOf(pr.state, pr.isDraft)
|
|
10717
|
+
};
|
|
10718
|
+
},
|
|
10719
|
+
issue: async (ref) => {
|
|
10720
|
+
const issue = await gh(cwd, [
|
|
10721
|
+
"issue",
|
|
10722
|
+
"view",
|
|
10723
|
+
ref,
|
|
10724
|
+
"--json",
|
|
10725
|
+
"url,title,state"
|
|
10726
|
+
]);
|
|
10727
|
+
return {
|
|
10728
|
+
url: issue.url,
|
|
10729
|
+
title: issue.title,
|
|
10730
|
+
state: stateOf(issue.state)
|
|
10731
|
+
};
|
|
9983
10732
|
}
|
|
9984
10733
|
};
|
|
9985
10734
|
}
|
|
@@ -9999,6 +10748,16 @@ function openBrowser(url, platform = process.platform) {
|
|
|
9999
10748
|
}
|
|
10000
10749
|
//#endregion
|
|
10001
10750
|
//#region src/output.ts
|
|
10751
|
+
/** The palette (tags, columns, projects) in the terminal's own 16 colours, so its theme decides the shade. */
|
|
10752
|
+
const ANSI = {
|
|
10753
|
+
grey: 90,
|
|
10754
|
+
blue: 34,
|
|
10755
|
+
amber: 33,
|
|
10756
|
+
green: 32,
|
|
10757
|
+
violet: 35,
|
|
10758
|
+
red: 31,
|
|
10759
|
+
cyan: 36
|
|
10760
|
+
};
|
|
10002
10761
|
function colorEnabled(env, isTTY) {
|
|
10003
10762
|
return isTTY && !env.NO_COLOR && env.TERM !== "dumb";
|
|
10004
10763
|
}
|
|
@@ -10006,7 +10765,8 @@ function style(enabled) {
|
|
|
10006
10765
|
const sgr = (on, off) => (s) => enabled ? `\x1b[${on}m${s}\x1b[${off}m` : s;
|
|
10007
10766
|
return {
|
|
10008
10767
|
bold: sgr(1, 22),
|
|
10009
|
-
dim: sgr(2, 22)
|
|
10768
|
+
dim: sgr(2, 22),
|
|
10769
|
+
color: (color, s) => sgr(ANSI[color], 39)(s)
|
|
10010
10770
|
};
|
|
10011
10771
|
}
|
|
10012
10772
|
const DAY = 864e5;
|
|
@@ -10088,7 +10848,8 @@ async function createContext(env = process.env, overrides = {}) {
|
|
|
10088
10848
|
edit: overrides.edit ?? ((text, name) => editInEditor(text, name, env)),
|
|
10089
10849
|
readStdin: overrides.readStdin ?? (() => readAll()),
|
|
10090
10850
|
openUrl: overrides.openUrl ?? ((url) => openBrowser(url)),
|
|
10091
|
-
clone: overrides.clone ?? clone()
|
|
10851
|
+
clone: overrides.clone ?? clone(),
|
|
10852
|
+
github: overrides.github ?? github()
|
|
10092
10853
|
};
|
|
10093
10854
|
}
|
|
10094
10855
|
const apis = (ctx) => ({
|
|
@@ -10366,6 +11127,50 @@ async function columnsOf(api, key) {
|
|
|
10366
11127
|
})))) all.push(c);
|
|
10367
11128
|
return all;
|
|
10368
11129
|
}
|
|
11130
|
+
/** The tags a project's tasks can have (its own and the shared ones), by name. */
|
|
11131
|
+
async function tagsOf(api, key) {
|
|
11132
|
+
const all = [];
|
|
11133
|
+
for await (const t of pages((cursor) => unwrap(api.GET("/v1/tags", { params: { query: {
|
|
11134
|
+
project: key,
|
|
11135
|
+
cursor
|
|
11136
|
+
} } })).then((page) => ({
|
|
11137
|
+
items: page.tags,
|
|
11138
|
+
nextCursor: page.nextCursor
|
|
11139
|
+
})))) all.push(t);
|
|
11140
|
+
return sortTags(all);
|
|
11141
|
+
}
|
|
11142
|
+
/** A task's tags, by name (ids it has that aren't in `tags` are left out). */
|
|
11143
|
+
function tagsOfTask(task, tags) {
|
|
11144
|
+
return sortTags(tags.filter((t) => task.tagIds.includes(t.id)));
|
|
11145
|
+
}
|
|
11146
|
+
/** "#bug #ui", each in its colour. */
|
|
11147
|
+
const tagWords = (tags, style) => tags.map((t) => style.color(t.color, `#${t.name}`)).join(" ");
|
|
11148
|
+
/**
|
|
11149
|
+
* The tags `names` mean in project `key` (any case, a leading # or not). A name that isn't a tag yet
|
|
11150
|
+
* becomes one of the project's, and stderr says so. `tags` gets the new ones too.
|
|
11151
|
+
*/
|
|
11152
|
+
async function resolveTags(ctx, api, key, names, tags) {
|
|
11153
|
+
const found = [];
|
|
11154
|
+
for (const given of names) {
|
|
11155
|
+
const name = tagName(given);
|
|
11156
|
+
if (!name) throw new CliError(`"${given}" isn't a tag name: use a word, like bug.`, EXIT.usage);
|
|
11157
|
+
let tag = findTag(tags, name);
|
|
11158
|
+
if (!tag) {
|
|
11159
|
+
tag = await unwrap(api.POST("/v1/tags", { body: {
|
|
11160
|
+
name,
|
|
11161
|
+
project: key
|
|
11162
|
+
} }));
|
|
11163
|
+
tags.push(tag);
|
|
11164
|
+
ctx.err(`Created tag #${tag.name} in ${key}.`);
|
|
11165
|
+
}
|
|
11166
|
+
if (!found.includes(tag)) found.push(tag);
|
|
11167
|
+
}
|
|
11168
|
+
return found;
|
|
11169
|
+
}
|
|
11170
|
+
/** A usage error before the API would refuse more than 10 tags. */
|
|
11171
|
+
function assertTagCount(count) {
|
|
11172
|
+
if (count > LIMITS.tagsPerTask) throw new CliError(`A task can have at most ${LIMITS.tagsPerTask} tags.`, EXIT.usage);
|
|
11173
|
+
}
|
|
10369
11174
|
/** Your project linked to `repo` (github.com/o/r), if any. */
|
|
10370
11175
|
async function projectForRepo(api, repo) {
|
|
10371
11176
|
return (await unwrap(api.GET("/v1/projects", { params: { query: { repo } } }))).projects[0] ?? null;
|
|
@@ -10409,10 +11214,16 @@ function taskRefOf(ref) {
|
|
|
10409
11214
|
if (!parsed) throw new CliError(`"${ref}" isn't a task like MON-12.`, EXIT.usage);
|
|
10410
11215
|
return parsed;
|
|
10411
11216
|
}
|
|
10412
|
-
/**
|
|
10413
|
-
|
|
11217
|
+
/**
|
|
11218
|
+
* A task by its reference, with its ETag version (a 404 exits 5). A task that moved to another project is
|
|
11219
|
+
* found by its old reference too (a branch named after it still works); `ctx` says what it's called now.
|
|
11220
|
+
*/
|
|
11221
|
+
async function taskByRef(api, ref, ctx) {
|
|
10414
11222
|
const { key, number } = taskRefOf(ref);
|
|
10415
|
-
|
|
11223
|
+
const asked = `${key}-${number}`;
|
|
11224
|
+
const task = await unwrap(api.GET("/v1/tasks/{ref}", { params: { path: { ref: asked } } }));
|
|
11225
|
+
if (task.ref !== asked) ctx?.err(`${asked} is ${task.ref} now: it moved to another project.`);
|
|
11226
|
+
return task;
|
|
10416
11227
|
}
|
|
10417
11228
|
/** The column `query` names (see matchColumn), or an error that lists the columns to choose from. */
|
|
10418
11229
|
function findColumn(columns, query) {
|
|
@@ -10429,22 +11240,172 @@ function changedElsewhere(err, ref) {
|
|
|
10429
11240
|
if (err instanceof ApiProblem && err.status === 412) throw new CliError(`${ref} changed elsewhere in the meantime. Run \`monoban show ${ref}\` and try again.`);
|
|
10430
11241
|
throw err;
|
|
10431
11242
|
}
|
|
10432
|
-
/** A task as the CLI prints it in JSON: the API's fields plus its column's name. */
|
|
10433
|
-
const taskJson = (task, columns) => ({
|
|
11243
|
+
/** A task as the CLI prints it in JSON: the API's fields plus its column's name and its tags' names. */
|
|
11244
|
+
const taskJson = (task, columns, tags) => ({
|
|
10434
11245
|
...task,
|
|
10435
|
-
column: columns.find((c) => c.id === task.columnId)?.name ?? null
|
|
11246
|
+
column: columns.find((c) => c.id === task.columnId)?.name ?? null,
|
|
11247
|
+
tags: tagsOfTask(task, tags).map((t) => t.name)
|
|
10436
11248
|
});
|
|
10437
11249
|
/** Where the web shows a project's board, or one task on it. */
|
|
10438
11250
|
const boardUrl = (ctx, key, number) => `${ctx.webUrl}/p/${key}${number === void 0 ? "" : `?task=${number}`}`;
|
|
10439
11251
|
//#endregion
|
|
11252
|
+
//#region src/commands/history.ts
|
|
11253
|
+
/** The newest `count` events of a task (a page at a time), and whether it has older ones. */
|
|
11254
|
+
async function historyOf(api, ref, count) {
|
|
11255
|
+
const { key, number } = taskRefOf(ref);
|
|
11256
|
+
const events = [];
|
|
11257
|
+
let cursor;
|
|
11258
|
+
do {
|
|
11259
|
+
const limit = Math.min(count - events.length, PAGE_LIMIT.max);
|
|
11260
|
+
const page = await unwrap(api.GET("/v1/projects/{key}/tasks/{number}/history", { params: {
|
|
11261
|
+
path: {
|
|
11262
|
+
key,
|
|
11263
|
+
number
|
|
11264
|
+
},
|
|
11265
|
+
query: {
|
|
11266
|
+
limit,
|
|
11267
|
+
cursor
|
|
11268
|
+
}
|
|
11269
|
+
} }));
|
|
11270
|
+
events.push(...page.events);
|
|
11271
|
+
cursor = page.nextCursor ?? void 0;
|
|
11272
|
+
} while (cursor && events.length < count);
|
|
11273
|
+
return {
|
|
11274
|
+
events,
|
|
11275
|
+
more: cursor !== void 0
|
|
11276
|
+
};
|
|
11277
|
+
}
|
|
11278
|
+
/** One line per event, aligned: "2h moved To do → In progress cli". */
|
|
11279
|
+
function historyLines(events, { dim }, now = Date.now()) {
|
|
11280
|
+
const rows = events.map((e) => ({
|
|
11281
|
+
age: eventAge(e.updatedAt, now),
|
|
11282
|
+
...describeEvent(e),
|
|
11283
|
+
via: e.via ?? ""
|
|
11284
|
+
}));
|
|
11285
|
+
const ageWidth = Math.max(0, ...rows.map((r) => r.age.length));
|
|
11286
|
+
const verbWidth = Math.max(0, ...rows.map((r) => r.verb.length));
|
|
11287
|
+
return rows.map((r) => {
|
|
11288
|
+
const via = r.via ? ` ${dim(r.via)}` : "";
|
|
11289
|
+
return `${dim(r.age.padStart(ageWidth))} ${r.verb.padEnd(verbWidth)} ${oneLine(r.detail)}${via}`.trimEnd();
|
|
11290
|
+
});
|
|
11291
|
+
}
|
|
11292
|
+
/** `monoban log MON-12`: what happened to a task, newest first (`-n` events, 20 unless you say). */
|
|
11293
|
+
async function log(ctx, ref, options) {
|
|
11294
|
+
const count = options.number === void 0 ? 20 : Number(options.number);
|
|
11295
|
+
if (!Number.isInteger(count) || count < 1) throw new CliError("-n is how many events to show: 1 or more.", EXIT.usage);
|
|
11296
|
+
const api = apis(ctx).signedIn;
|
|
11297
|
+
const { events, more } = await historyOf(api, ref, count);
|
|
11298
|
+
if (options.json) return ctx.out(JSON.stringify(events, null, 2));
|
|
11299
|
+
for (const line of historyLines(events, ctx.style)) ctx.out(line);
|
|
11300
|
+
if (more) ctx.err(`Older events too: -n ${count * 5} shows more.`);
|
|
11301
|
+
}
|
|
11302
|
+
//#endregion
|
|
11303
|
+
//#region src/commands/schedule.ts
|
|
11304
|
+
/** A day typed on the command line ("tomorrow", "fri", "2026-10-12"), or a usage error that shows how. */
|
|
11305
|
+
function dayArgument(input, now = today()) {
|
|
11306
|
+
const day = parseDay(input, now);
|
|
11307
|
+
if (!day) throw new CliError(`"${input}" isn't a day. Try today, tomorrow, fri, next week, +3, oct 12 or 2026-10-12.`, EXIT.usage);
|
|
11308
|
+
return day;
|
|
11309
|
+
}
|
|
11310
|
+
/**
|
|
11311
|
+
* `monoban today [DAY]`: the tasks planned for today (or DAY, or 7 days with --week) in every project, done
|
|
11312
|
+
* ones ticked. From today, the overdue ones come first: planned before and not done.
|
|
11313
|
+
*/
|
|
11314
|
+
async function todayView(ctx, dayInput, options) {
|
|
11315
|
+
const now = today();
|
|
11316
|
+
const from = dayInput ? dayArgument(dayInput, now) : now;
|
|
11317
|
+
const to = options.week ? addDays(from, 6) : from;
|
|
11318
|
+
const api = apis(ctx).signedIn;
|
|
11319
|
+
const tasks = [];
|
|
11320
|
+
const query = {
|
|
11321
|
+
from,
|
|
11322
|
+
to,
|
|
11323
|
+
...from === now && { overdue: "true" }
|
|
11324
|
+
};
|
|
11325
|
+
for await (const task of pages((cursor) => unwrap(api.GET("/v1/schedule", { params: { query: {
|
|
11326
|
+
...query,
|
|
11327
|
+
cursor
|
|
11328
|
+
} } })).then((page) => ({
|
|
11329
|
+
items: page.tasks,
|
|
11330
|
+
nextCursor: page.nextCursor
|
|
11331
|
+
})))) tasks.push(task);
|
|
11332
|
+
if (options.json) return ctx.out(JSON.stringify(tasks, null, 2));
|
|
11333
|
+
const { bold, dim, color } = ctx.style;
|
|
11334
|
+
const late = tasks.filter((t) => t.scheduledOn < from);
|
|
11335
|
+
const planned = tasks.filter((t) => t.scheduledOn >= from);
|
|
11336
|
+
const name = options.week ? `Next 7 days from ${longDay(from, now)}` : headingOf(from, now);
|
|
11337
|
+
const done = planned.filter((t) => t.done).length;
|
|
11338
|
+
ctx.out(`${bold(name)} ${dim(planned.length ? `${done} of ${planned.length} done` : "nothing planned")}`);
|
|
11339
|
+
if (tasks.length === 0) {
|
|
11340
|
+
ctx.err(`Plan a task for it: monoban schedule MON-12 ${dayInput ?? "today"}`);
|
|
11341
|
+
return;
|
|
11342
|
+
}
|
|
11343
|
+
const refWidth = Math.max(...tasks.map((t) => t.ref.length));
|
|
11344
|
+
const columnWidth = Math.max(...tasks.map((t) => [...t.column.name].length));
|
|
11345
|
+
const line = (t, extra = "") => {
|
|
11346
|
+
const mark = t.done ? color("green", "✓") : " ";
|
|
11347
|
+
const column = `${t.column.name}${" ".repeat(columnWidth - [...t.column.name].length)}`;
|
|
11348
|
+
const title = t.done ? dim(oneLine(t.title)) : oneLine(t.title);
|
|
11349
|
+
return `${mark} ${t.ref.padEnd(refWidth)} ${dim(column)} ${title}${extra}`;
|
|
11350
|
+
};
|
|
11351
|
+
if (late.length) {
|
|
11352
|
+
ctx.out("");
|
|
11353
|
+
ctx.out(color("amber", `Overdue · ${late.length}`));
|
|
11354
|
+
for (const t of late) ctx.out(line(t, ` ${color("amber", `${daysBetween(t.scheduledOn, now)}d late`)}`));
|
|
11355
|
+
}
|
|
11356
|
+
for (let day = from; day <= to; day = addDays(day, 1)) {
|
|
11357
|
+
const of = planned.filter((t) => t.scheduledOn === day);
|
|
11358
|
+
if (options.week ? of.length === 0 : planned.length === 0) continue;
|
|
11359
|
+
if (options.week || late.length) {
|
|
11360
|
+
ctx.out("");
|
|
11361
|
+
ctx.out(bold(options.week ? headingOf(day, now) : name));
|
|
11362
|
+
}
|
|
11363
|
+
for (const t of of) ctx.out(line(t));
|
|
11364
|
+
}
|
|
11365
|
+
}
|
|
11366
|
+
/** "Today · Thu Oct 2", "Tomorrow · Fri Oct 3", or just "Mon Oct 12". */
|
|
11367
|
+
function headingOf(day, now) {
|
|
11368
|
+
const near = formatDay(day, now);
|
|
11369
|
+
const long = longDay(day, now);
|
|
11370
|
+
return [
|
|
11371
|
+
"today",
|
|
11372
|
+
"tomorrow",
|
|
11373
|
+
"yesterday"
|
|
11374
|
+
].includes(near) ? `${near[0]?.toUpperCase()}${near.slice(1)} · ${long}` : long;
|
|
11375
|
+
}
|
|
11376
|
+
/** `monoban schedule MON-12 fri`: plans a task for a day; --clear takes its date off. */
|
|
11377
|
+
async function schedule(ctx, ref, dayInput, options) {
|
|
11378
|
+
if (dayInput === void 0 === !options.clear) throw new CliError("Say a day (monoban schedule MON-12 tomorrow), or --clear to take the date off.", EXIT.usage);
|
|
11379
|
+
const now = today();
|
|
11380
|
+
const day = dayInput === void 0 ? null : dayArgument(dayInput, now);
|
|
11381
|
+
const api = apis(ctx).signedIn;
|
|
11382
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11383
|
+
const { key, number } = taskRefOf(task.ref);
|
|
11384
|
+
const saved = task.scheduledOn === day ? task : await unwrap(api.PATCH("/v1/projects/{key}/tasks/{number}", {
|
|
11385
|
+
params: {
|
|
11386
|
+
path: {
|
|
11387
|
+
key,
|
|
11388
|
+
number
|
|
11389
|
+
},
|
|
11390
|
+
header: ifMatch(task.version)
|
|
11391
|
+
},
|
|
11392
|
+
body: { scheduledOn: day }
|
|
11393
|
+
})).catch((err) => changedElsewhere(err, task.ref));
|
|
11394
|
+
if (options.json) {
|
|
11395
|
+
const [columns, tags] = await Promise.all([columnsOf(api, key), saved.tagIds.length ? tagsOf(api, key) : []]);
|
|
11396
|
+
return ctx.out(JSON.stringify(taskJson(saved, columns, tags), null, 2));
|
|
11397
|
+
}
|
|
11398
|
+
ctx.out(day ? `${saved.ref} is planned for ${longDay(day, now)} (${formatDay(day, now)}).` : `${saved.ref} has no date now.`);
|
|
11399
|
+
}
|
|
11400
|
+
//#endregion
|
|
10440
11401
|
//#region src/commands/board.ts
|
|
10441
|
-
const printJson = (ctx, value) => ctx.out(JSON.stringify(value, null, 2));
|
|
11402
|
+
const printJson$1 = (ctx, value) => ctx.out(JSON.stringify(value, null, 2));
|
|
10442
11403
|
/** `monoban projects`: your projects, with their keys and repositories; * marks this folder's. */
|
|
10443
11404
|
async function projects(ctx, options) {
|
|
10444
11405
|
const api = apis(ctx).signedIn;
|
|
10445
11406
|
const all = await allProjects(api);
|
|
10446
11407
|
const here = await folderProject(ctx, api);
|
|
10447
|
-
if (options.json) return printJson(ctx, all.map((p) => ({
|
|
11408
|
+
if (options.json) return printJson$1(ctx, all.map((p) => ({
|
|
10448
11409
|
...p,
|
|
10449
11410
|
current: p.key === here
|
|
10450
11411
|
})));
|
|
@@ -10464,45 +11425,84 @@ async function projects(ctx, options) {
|
|
|
10464
11425
|
}
|
|
10465
11426
|
}
|
|
10466
11427
|
const tasks = (p) => `${p.taskCount} ${p.taskCount === 1 ? "task" : "tasks"}`;
|
|
10467
|
-
/**
|
|
11428
|
+
/**
|
|
11429
|
+
* `monoban list [COLUMN…]`: the board, by column (every column, or the ones named); `--tag` keeps a tag's
|
|
11430
|
+
* tasks. `--archived`: the archived ones instead (done a while ago, off the board).
|
|
11431
|
+
*/
|
|
10468
11432
|
async function list(ctx, columnQueries, options) {
|
|
10469
11433
|
const api = apis(ctx).signedIn;
|
|
10470
11434
|
const key = await resolveProject(ctx, api, options.project);
|
|
10471
11435
|
const board = await unwrap(api.GET("/v1/projects/{key}/board", { params: { path: { key } } }));
|
|
10472
|
-
|
|
10473
|
-
|
|
11436
|
+
let tasks = options.archived ? await allTasks(api, key, true) : board.truncated ? await allTasks(api, key) : board.tasks;
|
|
11437
|
+
if (options.tag !== void 0) {
|
|
11438
|
+
const tag = findTag(board.tags, options.tag);
|
|
11439
|
+
if (!tag) {
|
|
11440
|
+
const names = board.tags.map((t) => t.name).join(", ");
|
|
11441
|
+
throw new CliError(`No tag "${options.tag}" in ${key}. ${names ? `The tags are: ${names}.` : "It has no tags yet."}`, EXIT.notFound);
|
|
11442
|
+
}
|
|
11443
|
+
tasks = tasks.filter((t) => t.tagIds.includes(tag.id));
|
|
11444
|
+
}
|
|
11445
|
+
const groups = (columnQueries.length ? [...new Set(columnQueries.map((q) => findColumn(board.columns, q)))] : options.archived ? board.columns.filter((c) => tasks.some((t) => t.columnId === c.id)) : board.columns).map((column) => ({
|
|
10474
11446
|
column,
|
|
10475
11447
|
tasks: tasks.filter((t) => t.columnId === column.id)
|
|
10476
11448
|
}));
|
|
10477
|
-
if (options.json) return printJson(ctx, groups.flatMap((g) => g.tasks.map((t) => taskJson(t, board.columns))));
|
|
11449
|
+
if (options.json) return printJson$1(ctx, groups.flatMap((g) => g.tasks.map((t) => taskJson(t, board.columns, board.tags))));
|
|
10478
11450
|
const { bold, dim } = ctx.style;
|
|
10479
11451
|
const repo = board.project.repo ? ` · ${board.project.repo}` : "";
|
|
10480
|
-
ctx.out(`${bold(board.project.name)} ${dim(`(${board.project.key})${repo}`)}`);
|
|
11452
|
+
ctx.out(`${bold(board.project.name)} ${dim(`(${board.project.key})${repo}`)}${options.archived ? " archived" : ""}`);
|
|
11453
|
+
if (options.archived && tasks.length === 0) ctx.err(board.project.archiveAfterDays === null ? "Nothing archived: this project keeps its done tasks on the board." : `Nothing archived yet: tasks go after ${board.project.archiveAfterDays} days in ${doneColumn(board.columns)?.name ?? "Done"}.`);
|
|
10481
11454
|
const rows = groups.flatMap((g) => g.tasks);
|
|
10482
11455
|
const refWidth = Math.max(0, ...rows.map((t) => t.ref.length));
|
|
11456
|
+
const now = today();
|
|
11457
|
+
const done = doneColumn(board.columns)?.id;
|
|
10483
11458
|
const meta = (t) => {
|
|
10484
11459
|
const list = checklist(t.description);
|
|
10485
|
-
|
|
11460
|
+
const late = t.scheduledOn && t.columnId !== done && t.scheduledOn < now;
|
|
11461
|
+
return `${t.scheduledOn ? `@${formatDay(t.scheduledOn, now)}${late ? "!" : ""} ` : ""}${list ? `[${list.done}/${list.all}] ` : ""}${age(t.updatedAt).padStart(5)}`;
|
|
10486
11462
|
};
|
|
10487
11463
|
const metaWidth = Math.max(0, ...rows.map((t) => meta(t).length));
|
|
10488
|
-
const
|
|
10489
|
-
const titleWidth = Number.isFinite(ctx.tty.width) ? Math.max(10, ctx.tty.width - (2 + refWidth + 2 + 2 + metaWidth)) : Math.max(0, ...
|
|
11464
|
+
const cell = (t, width) => titleCell(oneLine(t.title), tagsOfTask(t, board.tags), width, ctx.style);
|
|
11465
|
+
const titleWidth = Number.isFinite(ctx.tty.width) ? Math.max(10, ctx.tty.width - (2 + refWidth + 2 + 2 + metaWidth)) : Math.max(0, ...rows.map((t) => visibleLength(cell(t, Number.POSITIVE_INFINITY))));
|
|
10490
11466
|
for (const { column, tasks: inColumn } of groups) {
|
|
10491
11467
|
const count = column.wipLimit ? `${inColumn.length}/${column.wipLimit}` : String(inColumn.length);
|
|
10492
11468
|
ctx.out("");
|
|
10493
11469
|
ctx.out(`${bold(column.name)} ${dim(count)}`);
|
|
10494
11470
|
for (const t of inColumn) {
|
|
10495
|
-
const title =
|
|
11471
|
+
const title = cell(t, titleWidth);
|
|
10496
11472
|
const pad = " ".repeat(Math.max(0, titleWidth - visibleLength(title)));
|
|
10497
11473
|
ctx.out(` ${dim(t.ref.padEnd(refWidth))} ${title}${pad} ${dim(meta(t).padStart(metaWidth))}`.trimEnd());
|
|
10498
11474
|
}
|
|
11475
|
+
if (!options.archived && board.archived > 0 && column.id === done && options.tag === void 0) ctx.out(dim(` + ${board.archived} archived (monoban list --archived)`));
|
|
10499
11476
|
}
|
|
10500
11477
|
}
|
|
10501
|
-
|
|
11478
|
+
/**
|
|
11479
|
+
* A title and its tags ("Fix login #bug #ui") in `width` characters: the title is cut first, down to
|
|
11480
|
+
* 10 characters; then tags that don't fit are left out and counted ("+2").
|
|
11481
|
+
*/
|
|
11482
|
+
function titleCell(title, tags, width, style) {
|
|
11483
|
+
if (tags.length === 0) return truncate(title, width);
|
|
11484
|
+
const titleLength = [...title].length;
|
|
11485
|
+
for (let shown = tags.length; shown >= 0; shown--) {
|
|
11486
|
+
const hidden = tags.length - shown;
|
|
11487
|
+
const room = width - [...tags.slice(0, shown).map((t) => `#${t.name}`), ...hidden ? [`+${hidden}`] : []].join(" ").length - 2;
|
|
11488
|
+
if (room >= Math.min(titleLength, 10) || shown === 0) {
|
|
11489
|
+
const extra = hidden ? ` ${style.dim(`+${hidden}`)}` : "";
|
|
11490
|
+
const text = shown ? `${tagWords(tags.slice(0, shown), style)}${extra}` : style.dim(`+${hidden}`);
|
|
11491
|
+
return room > 0 ? `${truncate(title, room)} ${text}` : truncate(title, width);
|
|
11492
|
+
}
|
|
11493
|
+
}
|
|
11494
|
+
return truncate(title, width);
|
|
11495
|
+
}
|
|
11496
|
+
/** A project's tasks, page by page: the ones on the board, or the archived ones. */
|
|
11497
|
+
async function allTasks(api, key, archived = false) {
|
|
10502
11498
|
const all = [];
|
|
11499
|
+
const query = (cursor) => ({
|
|
11500
|
+
cursor,
|
|
11501
|
+
...archived && { archived: "true" }
|
|
11502
|
+
});
|
|
10503
11503
|
for await (const t of pages((cursor) => unwrap(api.GET("/v1/projects/{key}/tasks", { params: {
|
|
10504
11504
|
path: { key },
|
|
10505
|
-
query:
|
|
11505
|
+
query: query(cursor)
|
|
10506
11506
|
} })).then((page) => ({
|
|
10507
11507
|
items: page.tasks,
|
|
10508
11508
|
nextCursor: page.nextCursor
|
|
@@ -10513,64 +11513,209 @@ const ago = (iso) => {
|
|
|
10513
11513
|
const a = age(iso);
|
|
10514
11514
|
return a === "today" ? a : `${a} ago`;
|
|
10515
11515
|
};
|
|
10516
|
-
/**
|
|
11516
|
+
/** How many history events `show` ends with. */
|
|
11517
|
+
const SHOW_HISTORY = 3;
|
|
11518
|
+
/** `monoban show MON-12`: a task in full, and what happened to it last. */
|
|
10517
11519
|
async function show(ctx, ref, options) {
|
|
10518
11520
|
const api = apis(ctx).signedIn;
|
|
10519
|
-
const task = await taskByRef(api, ref);
|
|
10520
|
-
const
|
|
10521
|
-
|
|
11521
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11522
|
+
const key = taskRefOf(task.ref).key;
|
|
11523
|
+
const [columns, tags, history] = await Promise.all([
|
|
11524
|
+
columnsOf(api, key),
|
|
11525
|
+
tagsFor(api, key, task),
|
|
11526
|
+
options.json ? null : historyOf(api, task.ref, SHOW_HISTORY).catch(() => null)
|
|
11527
|
+
]);
|
|
11528
|
+
if (options.json) return printJson$1(ctx, taskJson(task, columns, tags));
|
|
10522
11529
|
const { bold, dim } = ctx.style;
|
|
10523
|
-
const
|
|
11530
|
+
const doneId = doneColumn(columns)?.id;
|
|
11531
|
+
const archived = task.columnId === doneId && isArchived(task, doneId, (await unwrap(api.GET("/v1/projects/{key}", { params: { path: { key } } }))).project.archiveAfterDays);
|
|
11532
|
+
const column = `${columns.find((c) => c.id === task.columnId)?.name ?? "?"}${archived ? " · archived" : ""}`;
|
|
10524
11533
|
const list = checklist(task.description);
|
|
10525
11534
|
ctx.out(`${bold(task.ref)} ${bold(task.title)}`);
|
|
10526
|
-
|
|
11535
|
+
const when = task.scheduledOn ? ` · ${planned(task, columns)}` : "";
|
|
11536
|
+
ctx.out(dim(`${column}${when} · created ${ago(task.createdAt)} · updated ${ago(task.updatedAt)}`));
|
|
11537
|
+
const own = tagsOfTask(task, tags);
|
|
11538
|
+
if (own.length) ctx.out(tagWords(own, ctx.style));
|
|
10527
11539
|
if (list) ctx.out(dim(`Checklist ${list.done}/${list.all}`));
|
|
11540
|
+
if (task.links.length) {
|
|
11541
|
+
const width = Math.max(...task.links.map((l) => linkLabel(l).length));
|
|
11542
|
+
for (const l of task.links) {
|
|
11543
|
+
const state = l.state ? ` ${dim(l.state)}` : "";
|
|
11544
|
+
ctx.out(`${linkLabel(l).padEnd(width)} ${l.title || dim(l.url)}${state}`);
|
|
11545
|
+
}
|
|
11546
|
+
}
|
|
10528
11547
|
if (task.description.trim()) {
|
|
10529
11548
|
ctx.out("");
|
|
10530
11549
|
ctx.out(task.description.trimEnd());
|
|
10531
11550
|
}
|
|
11551
|
+
if (history?.events.length) {
|
|
11552
|
+
ctx.out("");
|
|
11553
|
+
ctx.out(dim(history.more ? `History (all of it: monoban log ${task.ref})` : "History"));
|
|
11554
|
+
for (const line of historyLines(history.events, ctx.style)) ctx.out(` ${line}`);
|
|
11555
|
+
}
|
|
10532
11556
|
}
|
|
10533
|
-
/**
|
|
11557
|
+
/** When a task is planned for: "for tomorrow", or "for Oct 1, 2d late" past it and not done. */
|
|
11558
|
+
function planned(task, columns) {
|
|
11559
|
+
if (!task.scheduledOn) return "";
|
|
11560
|
+
const now = today();
|
|
11561
|
+
const late = daysBetween(task.scheduledOn, now);
|
|
11562
|
+
const done = doneColumn(columns)?.id === task.columnId;
|
|
11563
|
+
return `for ${formatDay(task.scheduledOn, now)}${late > 0 && !done ? `, ${late}d late` : ""}`;
|
|
11564
|
+
}
|
|
11565
|
+
/** The project's tags, when `task` has any to name (else none: one request fewer). */
|
|
11566
|
+
const tagsFor = async (api, key, task) => task.tagIds.length ? tagsOf(api, key) : [];
|
|
11567
|
+
/** `monoban add "title"`: a new task, at the end of the first column (or of `-c column`), with `-t` tags. */
|
|
10534
11568
|
async function add(ctx, title, options) {
|
|
10535
11569
|
if (options.description !== void 0 && options.edit) throw new CliError("Use -d or -e, not both.", EXIT.usage);
|
|
11570
|
+
const names = options.tag ?? [];
|
|
11571
|
+
assertTagCount(new Set(names).size);
|
|
11572
|
+
const scheduledOn = options.date === void 0 ? void 0 : dayArgument(options.date);
|
|
10536
11573
|
const api = apis(ctx).signedIn;
|
|
10537
11574
|
const key = await resolveProject(ctx, api, options.project);
|
|
10538
|
-
const columns = await columnsOf(api, key);
|
|
11575
|
+
const [columns, tags] = await Promise.all([columnsOf(api, key), names.length ? tagsOf(api, key) : []]);
|
|
10539
11576
|
const column = options.column ? findColumn(columns, options.column) : columns[0];
|
|
10540
11577
|
let description = options.description;
|
|
10541
11578
|
if (description === "-") description = await ctx.readStdin();
|
|
10542
11579
|
if (options.edit) description = await ctx.edit("", `${key}-new`);
|
|
10543
11580
|
description = description?.trimEnd();
|
|
11581
|
+
const tagIds = (await resolveTags(ctx, api, key, names, tags)).map((t) => t.id);
|
|
11582
|
+
assertTagCount(tagIds.length);
|
|
10544
11583
|
const task = await unwrap(api.POST("/v1/projects/{key}/tasks", {
|
|
10545
11584
|
params: { path: { key } },
|
|
10546
11585
|
body: {
|
|
10547
11586
|
title,
|
|
10548
11587
|
...description ? { description } : {},
|
|
10549
|
-
...column ? { columnId: column.id } : {}
|
|
11588
|
+
...column ? { columnId: column.id } : {},
|
|
11589
|
+
...tagIds.length ? { tagIds } : {},
|
|
11590
|
+
...scheduledOn ? { scheduledOn } : {}
|
|
10550
11591
|
}
|
|
10551
11592
|
}));
|
|
10552
|
-
if (options.json) return printJson(ctx, taskJson(task, columns));
|
|
10553
|
-
|
|
11593
|
+
if (options.json) return printJson$1(ctx, taskJson(task, columns, tags));
|
|
11594
|
+
const tagged = tagIds.length ? ` ${tagWords(tagsOfTask(task, tags), ctx.style)}` : "";
|
|
11595
|
+
const when = scheduledOn ? `, for ${formatDay(scheduledOn, today())}` : "";
|
|
11596
|
+
ctx.out(`Added ${task.ref} to ${column?.name ?? "the board"}${when}: ${task.title}${tagged}`);
|
|
11597
|
+
}
|
|
11598
|
+
/** `monoban tag MON-12 bug ui`: puts tags on a task (a name that isn't a tag yet becomes one). */
|
|
11599
|
+
async function tag(ctx, ref, names, options) {
|
|
11600
|
+
const api = apis(ctx).signedIn;
|
|
11601
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11602
|
+
const key = taskRefOf(task.ref).key;
|
|
11603
|
+
const tags = await tagsOf(api, key);
|
|
11604
|
+
const adding = (await resolveTags(ctx, api, key, names, tags)).filter((t) => !task.tagIds.includes(t.id));
|
|
11605
|
+
if (adding.length === 0) {
|
|
11606
|
+
if (options.json) return printJson$1(ctx, taskJson(task, await columnsOf(api, key), tags));
|
|
11607
|
+
ctx.err(`${task.ref} already has ${names.length > 1 ? "those tags" : "that tag"}.`);
|
|
11608
|
+
return;
|
|
11609
|
+
}
|
|
11610
|
+
const tagIds = [...task.tagIds, ...adding.map((t) => t.id)];
|
|
11611
|
+
assertTagCount(tagIds.length);
|
|
11612
|
+
const updated = await setTags(api, task, tagIds);
|
|
11613
|
+
if (options.json) return printJson$1(ctx, taskJson(updated, await columnsOf(api, key), tags));
|
|
11614
|
+
ctx.out(`Tagged ${task.ref} ${tagWords(adding, ctx.style)}.`);
|
|
10554
11615
|
}
|
|
10555
|
-
/** `monoban
|
|
11616
|
+
/** `monoban untag MON-12 bug`: takes tags off a task (the tags themselves stay). */
|
|
11617
|
+
async function untag(ctx, ref, names, options) {
|
|
11618
|
+
const api = apis(ctx).signedIn;
|
|
11619
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11620
|
+
const key = taskRefOf(task.ref).key;
|
|
11621
|
+
const tags = await tagsOf(api, key);
|
|
11622
|
+
const own = tagsOfTask(task, tags);
|
|
11623
|
+
const removing = names.map((name) => {
|
|
11624
|
+
const found = findTag(own, name);
|
|
11625
|
+
if (found) return found;
|
|
11626
|
+
const has = own.length ? `Its tags: ${own.map((t) => t.name).join(", ")}.` : "It has no tags.";
|
|
11627
|
+
throw new CliError(`${task.ref} has no tag "${name}". ${has}`, EXIT.usage);
|
|
11628
|
+
});
|
|
11629
|
+
const updated = await setTags(api, task, task.tagIds.filter((id) => !removing.some((t) => t.id === id)));
|
|
11630
|
+
if (options.json) return printJson$1(ctx, taskJson(updated, await columnsOf(api, key), tags));
|
|
11631
|
+
ctx.out(`Took ${tagWords([...new Set(removing)], ctx.style)} off ${task.ref}.`);
|
|
11632
|
+
}
|
|
11633
|
+
/** A task's tags from now on, only if nobody changed the task since we read it. */
|
|
11634
|
+
function setTags(api, task, tagIds) {
|
|
11635
|
+
const { key, number } = taskRefOf(task.ref);
|
|
11636
|
+
return unwrap(api.PATCH("/v1/projects/{key}/tasks/{number}", {
|
|
11637
|
+
params: {
|
|
11638
|
+
path: {
|
|
11639
|
+
key,
|
|
11640
|
+
number
|
|
11641
|
+
},
|
|
11642
|
+
header: ifMatch(task.version)
|
|
11643
|
+
},
|
|
11644
|
+
body: { tagIds }
|
|
11645
|
+
})).catch((err) => changedElsewhere(err, task.ref));
|
|
11646
|
+
}
|
|
11647
|
+
/** `monoban tags`: the tags a project's tasks can have: its own and the shared ones. */
|
|
11648
|
+
async function tags(ctx, options) {
|
|
11649
|
+
const api = apis(ctx).signedIn;
|
|
11650
|
+
const key = await resolveProject(ctx, api, options.project);
|
|
11651
|
+
const all = await tagsOf(api, key);
|
|
11652
|
+
if (options.json) return printJson$1(ctx, all);
|
|
11653
|
+
if (all.length === 0) {
|
|
11654
|
+
ctx.err(`${key} has no tags yet. Add one with \`monoban tag ${key}-1 NAME\`.`);
|
|
11655
|
+
return;
|
|
11656
|
+
}
|
|
11657
|
+
const { dim } = ctx.style;
|
|
11658
|
+
const nameWidth = Math.max(...all.map((t) => [...t.name].length + 1));
|
|
11659
|
+
const whereWidth = Math.max(...all.map((t) => (t.project ?? "shared").length));
|
|
11660
|
+
for (const t of all) {
|
|
11661
|
+
const name = tagWords([t], ctx.style) + " ".repeat(nameWidth - [...t.name].length - 1);
|
|
11662
|
+
const where = (t.project ?? "shared").padEnd(whereWidth);
|
|
11663
|
+
const count = `${t.taskCount} ${t.taskCount === 1 ? "task" : "tasks"}`;
|
|
11664
|
+
ctx.out(`${name} ${dim(where)} ${dim(count)}`);
|
|
11665
|
+
}
|
|
11666
|
+
}
|
|
11667
|
+
/**
|
|
11668
|
+
* `monoban move MON-12 in-progress`: to the end of another column. With `--to WEB`, to another project
|
|
11669
|
+
* (to the column you say, else the one named like its column, else the first), where it gets a new number.
|
|
11670
|
+
*/
|
|
10556
11671
|
async function move(ctx, ref, columnQuery, options) {
|
|
10557
11672
|
const api = apis(ctx).signedIn;
|
|
10558
|
-
const task = await taskByRef(api, ref);
|
|
10559
|
-
const
|
|
11673
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11674
|
+
const { key } = taskRefOf(task.ref);
|
|
11675
|
+
const to = options.to?.trim().toUpperCase();
|
|
11676
|
+
if (to && to !== key) return transfer(ctx, api, task, to, columnQuery, options);
|
|
11677
|
+
if (columnQuery === void 0) {
|
|
11678
|
+
if (to) throw new CliError(`${task.ref} is in ${to} already. Say a column to move it to.`, EXIT.usage);
|
|
11679
|
+
throw new CliError("Say where: monoban move MON-12 in-progress (or --to WEB, another project).", EXIT.usage);
|
|
11680
|
+
}
|
|
11681
|
+
const columns = await columnsOf(api, key);
|
|
10560
11682
|
await moveTo(ctx, api, task, columns, findColumn(columns, columnQuery), options);
|
|
10561
11683
|
}
|
|
11684
|
+
/** Moves a task to project `to` (its column `columnQuery`, if given). */
|
|
11685
|
+
async function transfer(ctx, api, task, to, columnQuery, options) {
|
|
11686
|
+
const columns = await columnsOf(api, to);
|
|
11687
|
+
const target = columnQuery === void 0 ? void 0 : findColumn(columns, columnQuery);
|
|
11688
|
+
const { key, number } = taskRefOf(task.ref);
|
|
11689
|
+
const moved = await unwrap(api.POST("/v1/projects/{key}/tasks/{number}/transfer", {
|
|
11690
|
+
params: {
|
|
11691
|
+
path: {
|
|
11692
|
+
key,
|
|
11693
|
+
number
|
|
11694
|
+
},
|
|
11695
|
+
header: ifMatch(task.version)
|
|
11696
|
+
},
|
|
11697
|
+
body: {
|
|
11698
|
+
project: to,
|
|
11699
|
+
...target && { columnId: target.id }
|
|
11700
|
+
}
|
|
11701
|
+
})).catch((err) => changedElsewhere(err, task.ref));
|
|
11702
|
+
if (options.json) return printJson$1(ctx, taskJson(moved, columns, await tagsFor(api, to, moved)));
|
|
11703
|
+
const column = columns.find((c) => c.id === moved.columnId)?.name ?? "its first column";
|
|
11704
|
+
ctx.out(`Moved ${task.ref} to ${to}: it's ${moved.ref} now, in ${column}.`);
|
|
11705
|
+
}
|
|
10562
11706
|
/** `monoban done MON-12`: to the column called Done, or else the last one. */
|
|
10563
11707
|
async function done(ctx, ref, options) {
|
|
10564
11708
|
const api = apis(ctx).signedIn;
|
|
10565
|
-
const task = await taskByRef(api, ref);
|
|
11709
|
+
const task = await taskByRef(api, ref, ctx);
|
|
10566
11710
|
const columns = await columnsOf(api, taskRefOf(task.ref).key);
|
|
10567
11711
|
const target = columns.find((c) => c.name.trim().toLowerCase() === "done") ?? columns.at(-1);
|
|
10568
11712
|
if (!target) throw new CliError(`${task.ref}'s project has no columns.`);
|
|
10569
11713
|
await moveTo(ctx, api, task, columns, target, options);
|
|
10570
11714
|
}
|
|
10571
11715
|
async function moveTo(ctx, api, task, columns, target, options) {
|
|
11716
|
+
const json = async (t) => printJson$1(ctx, taskJson(t, columns, await tagsFor(api, taskRefOf(t.ref).key, t)));
|
|
10572
11717
|
if (task.columnId === target.id) {
|
|
10573
|
-
if (options.json) return
|
|
11718
|
+
if (options.json) return json(task);
|
|
10574
11719
|
ctx.out(`${task.ref} is already in ${target.name}.`);
|
|
10575
11720
|
return;
|
|
10576
11721
|
}
|
|
@@ -10586,16 +11731,29 @@ async function moveTo(ctx, api, task, columns, target, options) {
|
|
|
10586
11731
|
},
|
|
10587
11732
|
body: { columnId: target.id }
|
|
10588
11733
|
})).catch((err) => changedElsewhere(err, task.ref));
|
|
10589
|
-
if (options.json) return
|
|
11734
|
+
if (options.json) return json(moved);
|
|
10590
11735
|
ctx.out(`Moved ${task.ref}${from ? ` from ${from}` : ""} to ${target.name}.`);
|
|
10591
11736
|
}
|
|
10592
|
-
/**
|
|
11737
|
+
/**
|
|
11738
|
+
* `monoban edit MON-12`: the title (first line) and description in $EDITOR; or, without an editor
|
|
11739
|
+
* (scripts, agents), `--title` and `-d` (`-` reads it from stdin) replace what they name.
|
|
11740
|
+
*/
|
|
10593
11741
|
async function edit(ctx, ref, options) {
|
|
10594
11742
|
const api = apis(ctx).signedIn;
|
|
10595
|
-
const task = await taskByRef(api, ref);
|
|
10596
|
-
const
|
|
10597
|
-
|
|
10598
|
-
|
|
11743
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11744
|
+
const direct = options.title !== void 0 || options.description !== void 0;
|
|
11745
|
+
let text = "";
|
|
11746
|
+
let title;
|
|
11747
|
+
let description;
|
|
11748
|
+
if (direct) {
|
|
11749
|
+
title = (options.title ?? task.title).trim();
|
|
11750
|
+
description = options.description === void 0 ? task.description.trimEnd() : (options.description === "-" ? await ctx.readStdin() : options.description).trimEnd();
|
|
11751
|
+
if (!title) throw new CliError("The title can't be empty.", EXIT.usage);
|
|
11752
|
+
} else {
|
|
11753
|
+
text = await ctx.edit(taskText(task.title, task.description), task.ref);
|
|
11754
|
+
({title, description} = parseTaskText(text));
|
|
11755
|
+
if (!title) throw new CliError("The title (the first line) is empty, so nothing changed.");
|
|
11756
|
+
}
|
|
10599
11757
|
const patch = {
|
|
10600
11758
|
...title !== task.title ? { title } : {},
|
|
10601
11759
|
...description !== task.description.trimEnd() ? { description } : {}
|
|
@@ -10618,17 +11776,22 @@ async function edit(ctx, ref, options) {
|
|
|
10618
11776
|
body: patch
|
|
10619
11777
|
}));
|
|
10620
11778
|
} catch (err) {
|
|
10621
|
-
|
|
10622
|
-
|
|
11779
|
+
if (!direct || options.description === "-") {
|
|
11780
|
+
const draft = direct ? taskText(title, description) : text;
|
|
11781
|
+
ctx.err(`Your text is saved in ${await keepDraft(draft, task.ref)}.`);
|
|
11782
|
+
}
|
|
10623
11783
|
changedElsewhere(err, task.ref);
|
|
10624
11784
|
}
|
|
10625
|
-
if (options.json)
|
|
11785
|
+
if (options.json) {
|
|
11786
|
+
const [columns, tags] = await Promise.all([columnsOf(api, key), tagsFor(api, key, updated)]);
|
|
11787
|
+
return printJson$1(ctx, taskJson(updated, columns, tags));
|
|
11788
|
+
}
|
|
10626
11789
|
ctx.out(`Updated ${task.ref}.`);
|
|
10627
11790
|
}
|
|
10628
11791
|
/** `monoban rm MON-12`: asks first, unless -y. */
|
|
10629
11792
|
async function rm$1(ctx, ref, options) {
|
|
10630
11793
|
const api = apis(ctx).signedIn;
|
|
10631
|
-
const task = await taskByRef(api, ref);
|
|
11794
|
+
const task = await taskByRef(api, ref, ctx);
|
|
10632
11795
|
if (!options.yes) {
|
|
10633
11796
|
if (!ctx.tty.in) throw new CliError(`To delete ${task.ref} without a terminal to ask on, pass -y.`, EXIT.usage);
|
|
10634
11797
|
if (!await ctx.confirm(`Delete ${task.ref} "${oneLine(task.title)}"?`)) {
|
|
@@ -10644,7 +11807,7 @@ async function rm$1(ctx, ref, options) {
|
|
|
10644
11807
|
},
|
|
10645
11808
|
header: ifMatch(task.version)
|
|
10646
11809
|
} })).catch((err) => changedElsewhere(err, task.ref));
|
|
10647
|
-
if (options.json) return printJson(ctx, deleted);
|
|
11810
|
+
if (options.json) return printJson$1(ctx, deleted);
|
|
10648
11811
|
ctx.out(`Deleted ${task.ref}.`);
|
|
10649
11812
|
}
|
|
10650
11813
|
/** `monoban open [MON-12]`: the task, or the board, in the browser (and the link on stdout). */
|
|
@@ -10693,7 +11856,7 @@ async function link(ctx, key, options) {
|
|
|
10693
11856
|
body: { repo }
|
|
10694
11857
|
})).catch((err) => projectChanged(err, target.key));
|
|
10695
11858
|
await ctx.clone.remember(linked.key);
|
|
10696
|
-
if (options.json) return printJson(ctx, linked);
|
|
11859
|
+
if (options.json) return printJson$1(ctx, linked);
|
|
10697
11860
|
const was = target.repo && target.repo !== repo ? ` (instead of ${target.repo})` : "";
|
|
10698
11861
|
ctx.out(`Linked ${linked.key} to ${repo}${was}. Commands in this clone now use ${linked.key}.`);
|
|
10699
11862
|
}
|
|
@@ -10716,7 +11879,7 @@ async function unlink(ctx, options) {
|
|
|
10716
11879
|
body: { repo: null }
|
|
10717
11880
|
})).catch((err) => projectChanged(err, linked.key));
|
|
10718
11881
|
await ctx.clone.forget();
|
|
10719
|
-
if (options.json) return printJson(ctx, project ?? null);
|
|
11882
|
+
if (options.json) return printJson$1(ctx, project ?? null);
|
|
10720
11883
|
ctx.out(linked ? `Unlinked ${linked.key} from ${origin?.repo}.` : `This clone no longer uses ${remembered}.`);
|
|
10721
11884
|
}
|
|
10722
11885
|
function projectChanged(err, key) {
|
|
@@ -10724,11 +11887,509 @@ function projectChanged(err, key) {
|
|
|
10724
11887
|
throw err;
|
|
10725
11888
|
}
|
|
10726
11889
|
//#endregion
|
|
11890
|
+
//#region src/commands/links.ts
|
|
11891
|
+
const printJson = (ctx, value) => ctx.out(JSON.stringify(value, null, 2));
|
|
11892
|
+
/** "#54 "Add invoices" (open)": a link as a message names it. */
|
|
11893
|
+
function linkWords(link) {
|
|
11894
|
+
return [
|
|
11895
|
+
linkLabel(link),
|
|
11896
|
+
link.title && `"${link.title}"`,
|
|
11897
|
+
link.state && `(${link.state})`
|
|
11898
|
+
].filter(Boolean).join(" ");
|
|
11899
|
+
}
|
|
11900
|
+
/** The task a branch is named after: mon-12-invoices → MON-12. */
|
|
11901
|
+
function taskOfBranch(branch) {
|
|
11902
|
+
const match = branch ? /(?:^|[^A-Za-z0-9])([A-Za-z][A-Za-z0-9]{1,4}-[1-9][0-9]{0,8})(?![0-9])/.exec(branch) : null;
|
|
11903
|
+
const parsed = match?.[1] ? parseTaskRef(match[1]) : null;
|
|
11904
|
+
return parsed ? `${parsed.key}-${parsed.number}` : null;
|
|
11905
|
+
}
|
|
11906
|
+
/**
|
|
11907
|
+
* `monoban attach [MON-12] [URL]`: a link on a task. `--pr` is this branch's pull request, read with `gh`
|
|
11908
|
+
* (so its title and state come along); a GitHub pull request or issue URL is read with `gh` too, when it
|
|
11909
|
+
* can be. Without a task, the one the branch is named after. Attaching a link again refreshes it.
|
|
11910
|
+
*/
|
|
11911
|
+
async function attach(ctx, args, options) {
|
|
11912
|
+
let ref;
|
|
11913
|
+
let url;
|
|
11914
|
+
for (const arg of args) if (!url && parseLink(arg)) url = arg;
|
|
11915
|
+
else if (!ref) ref = arg;
|
|
11916
|
+
else throw new CliError(`"${arg}" isn't a web link.`, EXIT.usage);
|
|
11917
|
+
if (url && options.pr) throw new CliError("Give a link or --pr, not both.", EXIT.usage);
|
|
11918
|
+
if (!url && !options.pr) throw new CliError(`${ref && !parseTaskRef(ref) ? `"${ref}" isn't a web link. ` : ""}Give a link, or --pr for this branch's pull request.`, EXIT.usage);
|
|
11919
|
+
ref ??= taskOfBranch(await ctx.clone.branch()) ?? void 0;
|
|
11920
|
+
if (!ref) throw new CliError("Which task? Name it (`monoban attach MON-12 …`), or run it on a branch named after it (mon-12-…).", EXIT.usage);
|
|
11921
|
+
taskRefOf(ref);
|
|
11922
|
+
let item = null;
|
|
11923
|
+
if (options.pr) {
|
|
11924
|
+
item = await ctx.github.pullRequest();
|
|
11925
|
+
url = item.url;
|
|
11926
|
+
}
|
|
11927
|
+
const parsed = parseLink(url);
|
|
11928
|
+
if (!parsed) throw new CliError(`"${url}" isn't a web link.`, EXIT.usage);
|
|
11929
|
+
if (!item && (parsed.kind === "pr" || parsed.kind === "issue")) try {
|
|
11930
|
+
item = await (parsed.kind === "pr" ? ctx.github.pullRequest(parsed.url) : ctx.github.issue(parsed.url));
|
|
11931
|
+
} catch (err) {
|
|
11932
|
+
if (!(err instanceof NoGh)) ctx.err(`Couldn't read it with gh (${err.message}); attaching it as it is.`);
|
|
11933
|
+
}
|
|
11934
|
+
const api = apis(ctx).signedIn;
|
|
11935
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11936
|
+
const had = task.links.some((l) => l.url === parsed.url);
|
|
11937
|
+
const { key, number } = taskRefOf(task.ref);
|
|
11938
|
+
const title = options.title ?? item?.title;
|
|
11939
|
+
const link = await unwrap(api.POST("/v1/projects/{key}/tasks/{number}/links", {
|
|
11940
|
+
params: { path: {
|
|
11941
|
+
key,
|
|
11942
|
+
number
|
|
11943
|
+
} },
|
|
11944
|
+
body: {
|
|
11945
|
+
url: parsed.url,
|
|
11946
|
+
...title !== void 0 && { title },
|
|
11947
|
+
...item && { state: item.state }
|
|
11948
|
+
}
|
|
11949
|
+
}));
|
|
11950
|
+
if (options.json) return printJson(ctx, link);
|
|
11951
|
+
ctx.out(`${had ? "Updated" : "Attached"} ${linkWords(link)} ${had ? "on" : "to"} ${task.ref}.`);
|
|
11952
|
+
}
|
|
11953
|
+
/** `monoban detach MON-12 #54`: takes a link off (by its number, its URL, or where it points). */
|
|
11954
|
+
async function detach(ctx, ref, which, options) {
|
|
11955
|
+
const api = apis(ctx).signedIn;
|
|
11956
|
+
const task = await taskByRef(api, ref, ctx);
|
|
11957
|
+
const wanted = which.trim();
|
|
11958
|
+
const number = /^#?([1-9][0-9]*)$/.exec(wanted)?.[1];
|
|
11959
|
+
const url = parseLink(wanted)?.url;
|
|
11960
|
+
const found = task.links.filter((l) => number ? l.number === Number(number) : l.url === url || l.id === wanted || linkLabel(l) === wanted);
|
|
11961
|
+
if (found.length !== 1) {
|
|
11962
|
+
const has = task.links.length ? `Its links: ${task.links.map(linkLabel).join(", ")}.` : "It has no links.";
|
|
11963
|
+
throw new CliError(`${found.length ? `"${wanted}" could be ${found.map((l) => l.url).join(" or ")}: give the URL.` : `${task.ref} has no link "${wanted}".`} ${found.length ? "" : has}`.trim(), found.length ? EXIT.usage : EXIT.notFound);
|
|
11964
|
+
}
|
|
11965
|
+
const link = found[0];
|
|
11966
|
+
const { key, number: n } = taskRefOf(task.ref);
|
|
11967
|
+
const removed = await unwrap(api.DELETE("/v1/projects/{key}/tasks/{number}/links/{linkId}", { params: {
|
|
11968
|
+
path: {
|
|
11969
|
+
key,
|
|
11970
|
+
number: n,
|
|
11971
|
+
linkId: link.id
|
|
11972
|
+
},
|
|
11973
|
+
header: ifMatch(link.version)
|
|
11974
|
+
} })).catch((err) => changedElsewhere(err, task.ref));
|
|
11975
|
+
if (options.json) return printJson(ctx, removed);
|
|
11976
|
+
ctx.out(`Removed ${linkLabel(link)} from ${task.ref}.`);
|
|
11977
|
+
}
|
|
11978
|
+
//#endregion
|
|
11979
|
+
//#region src/commands/notes.ts
|
|
11980
|
+
const printNotes = (ctx, key, notes) => ctx.out(JSON.stringify({
|
|
11981
|
+
project: key,
|
|
11982
|
+
...notes
|
|
11983
|
+
}, null, 2));
|
|
11984
|
+
/** `monoban notes`: the project's notes as they are, for reading, a pager or a pipe. */
|
|
11985
|
+
async function notesShow(ctx, options) {
|
|
11986
|
+
const api = apis(ctx).signedIn;
|
|
11987
|
+
const key = await resolveProject(ctx, api, options.project);
|
|
11988
|
+
const notes = await unwrap(api.GET("/v1/projects/{key}/notes", { params: { path: { key } } }));
|
|
11989
|
+
if (options.json) return printNotes(ctx, key, notes);
|
|
11990
|
+
if (!notes.text) {
|
|
11991
|
+
ctx.err(`${key} has no notes yet. Add a line with \`monoban notes add …\`, or write them with \`monoban notes edit\`.`);
|
|
11992
|
+
return;
|
|
11993
|
+
}
|
|
11994
|
+
ctx.out(notes.text.replace(/\n$/, ""));
|
|
11995
|
+
}
|
|
11996
|
+
/** `monoban notes add TEXT…`: a line at the end of the notes (`-` reads it from stdin). */
|
|
11997
|
+
async function notesAdd(ctx, words, options) {
|
|
11998
|
+
const text = words.length === 1 && words[0] === "-" ? (await ctx.readStdin()).replace(/\n$/, "") : words.join(" ");
|
|
11999
|
+
if (!text.trim()) throw new CliError("Nothing to add: give the text, or - to read it from stdin.", EXIT.usage);
|
|
12000
|
+
const api = apis(ctx).signedIn;
|
|
12001
|
+
const key = await resolveProject(ctx, api, options.project);
|
|
12002
|
+
const notes = await unwrap(api.PATCH("/v1/projects/{key}/notes", {
|
|
12003
|
+
params: { path: { key } },
|
|
12004
|
+
body: { append: text }
|
|
12005
|
+
}));
|
|
12006
|
+
if (options.json) return printNotes(ctx, key, notes);
|
|
12007
|
+
ctx.out(`Added to the notes of ${key}.`);
|
|
12008
|
+
}
|
|
12009
|
+
/** `monoban notes edit`: the notes in $EDITOR, saved only if nobody changed them in the meantime. */
|
|
12010
|
+
async function notesEdit(ctx, options) {
|
|
12011
|
+
const api = apis(ctx).signedIn;
|
|
12012
|
+
const key = await resolveProject(ctx, api, options.project);
|
|
12013
|
+
const notes = await unwrap(api.GET("/v1/projects/{key}/notes", { params: { path: { key } } }));
|
|
12014
|
+
const text = await ctx.edit(notes.text, `${key}-notes`);
|
|
12015
|
+
if (text === notes.text) {
|
|
12016
|
+
ctx.err(`No changes to the notes of ${key}.`);
|
|
12017
|
+
return;
|
|
12018
|
+
}
|
|
12019
|
+
let saved;
|
|
12020
|
+
try {
|
|
12021
|
+
saved = await unwrap(api.PATCH("/v1/projects/{key}/notes", {
|
|
12022
|
+
params: {
|
|
12023
|
+
path: { key },
|
|
12024
|
+
header: ifMatch(notes.version)
|
|
12025
|
+
},
|
|
12026
|
+
body: { text }
|
|
12027
|
+
}));
|
|
12028
|
+
} catch (err) {
|
|
12029
|
+
const draft = await keepDraft(text, `${key}-notes`);
|
|
12030
|
+
ctx.err(`Your text is saved in ${draft}.`);
|
|
12031
|
+
if (err instanceof ApiProblem && err.status === 412) throw new CliError(`The notes of ${key} changed elsewhere in the meantime. Run \`monoban notes edit\` again.`);
|
|
12032
|
+
throw err;
|
|
12033
|
+
}
|
|
12034
|
+
if (options.json) return printNotes(ctx, key, saved);
|
|
12035
|
+
ctx.out(`Updated the notes of ${key}.`);
|
|
12036
|
+
}
|
|
12037
|
+
//#endregion
|
|
12038
|
+
//#region src/commands/search.ts
|
|
12039
|
+
/**
|
|
12040
|
+
* `monoban search login page`: the tasks with all of these words (in the title or description, as a tag, or
|
|
12041
|
+
* as the reference), in every project, the last changed first, archived ones too. `-n` of them, 30 unless
|
|
12042
|
+
* you say.
|
|
12043
|
+
*/
|
|
12044
|
+
async function search(ctx, words, options) {
|
|
12045
|
+
const q = words.join(" ").trim();
|
|
12046
|
+
if (!q) throw new CliError("Say what to look for: monoban search login page", EXIT.usage);
|
|
12047
|
+
const count = options.number === void 0 ? 30 : Number(options.number);
|
|
12048
|
+
if (!Number.isInteger(count) || count < 1) throw new CliError("-n is how many tasks to show: 1 or more.", EXIT.usage);
|
|
12049
|
+
const api = apis(ctx).signedIn;
|
|
12050
|
+
const tasks = [];
|
|
12051
|
+
let cursor;
|
|
12052
|
+
do {
|
|
12053
|
+
const limit = Math.min(count - tasks.length, PAGE_LIMIT.max);
|
|
12054
|
+
const page = await unwrap(api.GET("/v1/search", { params: { query: {
|
|
12055
|
+
q,
|
|
12056
|
+
limit,
|
|
12057
|
+
cursor
|
|
12058
|
+
} } }));
|
|
12059
|
+
tasks.push(...page.tasks);
|
|
12060
|
+
cursor = page.nextCursor ?? void 0;
|
|
12061
|
+
} while (cursor && tasks.length < count);
|
|
12062
|
+
if (options.json) return ctx.out(JSON.stringify(tasks, null, 2));
|
|
12063
|
+
if (tasks.length === 0) {
|
|
12064
|
+
ctx.err(`No task has "${q}".`);
|
|
12065
|
+
return;
|
|
12066
|
+
}
|
|
12067
|
+
const { dim, color } = ctx.style;
|
|
12068
|
+
const refWidth = Math.max(...tasks.map((t) => t.ref.length));
|
|
12069
|
+
const columnWidth = Math.max(...tasks.map((t) => [...t.column.name].length));
|
|
12070
|
+
for (const t of tasks) {
|
|
12071
|
+
const mark = t.done ? color("green", "✓") : " ";
|
|
12072
|
+
const column = `${t.column.name}${" ".repeat(columnWidth - [...t.column.name].length)}`;
|
|
12073
|
+
const title = t.done ? dim(oneLine(t.title)) : oneLine(t.title);
|
|
12074
|
+
ctx.out(`${mark} ${t.ref.padEnd(refWidth)} ${dim(column)} ${title}${t.archived ? ` ${dim("archived")}` : ""}`);
|
|
12075
|
+
}
|
|
12076
|
+
if (cursor) ctx.err(`More tasks have it: -n ${count * 5} shows more.`);
|
|
12077
|
+
}
|
|
12078
|
+
//#endregion
|
|
12079
|
+
//#region src/skill.ts
|
|
12080
|
+
/** The coding agents `monoban setup` teaches monoban to. */
|
|
12081
|
+
const AGENTS = ["claude", "codex"];
|
|
12082
|
+
const AGENT_NAMES = {
|
|
12083
|
+
claude: "Claude Code",
|
|
12084
|
+
codex: "Codex"
|
|
12085
|
+
};
|
|
12086
|
+
/** Marks a SKILL.md that `monoban setup` wrote, so running it again may replace it. */
|
|
12087
|
+
const MARKER = "<!-- Written by `monoban setup`";
|
|
12088
|
+
const DESCRIPTION = "Plan and track work on the user's monoban.dev kanban board with the `monoban` CLI. Use when planning a feature or any multi-step change (offer to break the plan into board tasks, tagged by phase), when the user mentions monoban, their board or a task like MON-12, asks what to work on next, or is working on a task that is on the board.";
|
|
12089
|
+
/**
|
|
12090
|
+
* Commands Claude Code may run without asking: they only read. (`Bash(x *)` matches a bare `x` too, and
|
|
12091
|
+
* Claude Code checks each part of a pipe or `&&` on its own.) Anything that writes still asks.
|
|
12092
|
+
*/
|
|
12093
|
+
const READ_ONLY = [
|
|
12094
|
+
"monoban whoami",
|
|
12095
|
+
"monoban projects",
|
|
12096
|
+
"monoban list",
|
|
12097
|
+
"monoban ls",
|
|
12098
|
+
"monoban show",
|
|
12099
|
+
"monoban log",
|
|
12100
|
+
"monoban today",
|
|
12101
|
+
"monoban search",
|
|
12102
|
+
"monoban tags",
|
|
12103
|
+
"monoban notes show"
|
|
12104
|
+
];
|
|
12105
|
+
/** The skill's SKILL.md for `agent`: frontmatter for that agent, then the same instructions. */
|
|
12106
|
+
function skillFile(agent) {
|
|
12107
|
+
return `${[
|
|
12108
|
+
"---",
|
|
12109
|
+
"name: monoban",
|
|
12110
|
+
`description: ${JSON.stringify(DESCRIPTION)}`,
|
|
12111
|
+
...agent === "claude" ? [`allowed-tools: ${READ_ONLY.map((c) => `Bash(${c} *)`).join(" ")}`] : [],
|
|
12112
|
+
"---"
|
|
12113
|
+
].join("\n")}\n\n${MARKER} (monoban ${VERSION}). Run it again to update this file. -->\n\n${BODY}`;
|
|
12114
|
+
}
|
|
12115
|
+
const BODY = `# monoban
|
|
12116
|
+
|
|
12117
|
+
monoban.dev is the user's keyboard-first kanban board, and \`monoban\` is its command line. Use it to turn
|
|
12118
|
+
plans into tasks on the board and to keep those tasks current while you work.
|
|
12119
|
+
|
|
12120
|
+
- A **project** has a key (\`MON\`), columns the user named (often Backlog, In progress, In review, Done),
|
|
12121
|
+
tags, and one free-text **notes** file (\`notes.md\` in the web app).
|
|
12122
|
+
- A **task** is \`MON-12\`: a title, a Markdown description, tags, links (pull requests, pages), and a column. \`- [ ]\` / \`- [x]\` lines in
|
|
12123
|
+
the description are its checklist; the board shows the progress (\`[2/5]\`).
|
|
12124
|
+
|
|
12125
|
+
## First
|
|
12126
|
+
|
|
12127
|
+
1. \`monoban whoami\`. Exit code 4 means not signed in: ask the user to run \`monoban login\` themselves (it
|
|
12128
|
+
opens a browser). Never sign in for them, and never read, print or ask for tokens.
|
|
12129
|
+
2. Which project: in a repository linked with \`monoban link\` (or with \`MONOBAN_PROJECT\` set) commands use
|
|
12130
|
+
that project. Otherwise \`monoban projects\` lists the keys; pass \`-p KEY\` to project commands. If it's
|
|
12131
|
+
unclear which project the work belongs to, ask. Suggest \`monoban link KEY\` to the user rather than
|
|
12132
|
+
running it (it changes the project).
|
|
12133
|
+
3. Read with \`--json\`: \`monoban list --json\` (every task, with its \`column\` and \`tags\`),
|
|
12134
|
+
\`monoban show MON-12 --json\`, \`monoban tags --json\`, and \`monoban notes show\` for the notes.
|
|
12135
|
+
\`monoban log MON-12\` shows what happened to a task, when, and through what (web or cli).
|
|
12136
|
+
\`monoban search WORDS\` finds a task in any project ("the login bug": \`monoban search login bug\`).
|
|
12137
|
+
|
|
12138
|
+
If a command can't reach the API (a sandbox without network), ask the user to allow it; don't work around it.
|
|
12139
|
+
|
|
12140
|
+
## When you make a plan: offer tasks
|
|
12141
|
+
|
|
12142
|
+
When you plan work with several steps (a feature, a migration, a refactor), offer to put it on the board.
|
|
12143
|
+
|
|
12144
|
+
1. Read the board first (\`monoban list --json\`, \`monoban tags\`), so you reuse existing tasks and tags
|
|
12145
|
+
instead of adding duplicates.
|
|
12146
|
+
2. **Propose, don't create.** Show the breakdown, grouped by phase, and ask before writing anything:
|
|
12147
|
+
|
|
12148
|
+
\`\`\`
|
|
12149
|
+
Add these 5 tasks to MON?
|
|
12150
|
+
phase-1 Add the invoices table and its API route
|
|
12151
|
+
phase-1 Show invoices on the account page
|
|
12152
|
+
phase-2 Email a receipt when an invoice is paid
|
|
12153
|
+
phase-2 Let users download an invoice as a PDF
|
|
12154
|
+
phase-3 Remove the old billing page
|
|
12155
|
+
\`\`\`
|
|
12156
|
+
|
|
12157
|
+
The user may change, drop or reorder tasks. Create them only after they agree.
|
|
12158
|
+
3. Create them in order (each goes to the end of the first column, or of \`-c COLUMN\`):
|
|
12159
|
+
|
|
12160
|
+
\`\`\`sh
|
|
12161
|
+
monoban add "Add the invoices table and its API route" -t phase-1 -d - <<'EOF'
|
|
12162
|
+
Why: invoices live in Stripe only, so the account page can't list them.
|
|
12163
|
+
|
|
12164
|
+
- [ ] migration for invoices
|
|
12165
|
+
- [ ] GET /v1/invoices, with tests
|
|
12166
|
+
EOF
|
|
12167
|
+
\`\`\`
|
|
12168
|
+
|
|
12169
|
+
4. Say which refs you created (\`MON-31\`…\`MON-35\`). If the user wants it, keep a short summary of the plan
|
|
12170
|
+
in the project's notes: \`monoban notes add -\` appends stdin as the last lines.
|
|
12171
|
+
|
|
12172
|
+
Good tasks:
|
|
12173
|
+
- One reviewable change each (about a commit or a pull request), not every small step: small steps go in
|
|
12174
|
+
the task's checklist.
|
|
12175
|
+
- Titles are short and imperative ("Add…", "Fix…", "Remove…"), at most ${LIMITS.taskTitle} characters.
|
|
12176
|
+
- The description says why, and ends with a checklist of what "done" means.
|
|
12177
|
+
|
|
12178
|
+
## Phases are tags
|
|
12179
|
+
|
|
12180
|
+
Tag each task with its phase: \`phase-1\`, \`phase-2\`, … in the order the work should happen, one phase tag
|
|
12181
|
+
per task. A tag that doesn't exist yet is created in the project on first use. \`monoban list --tag phase-2\`
|
|
12182
|
+
shows one phase.
|
|
12183
|
+
|
|
12184
|
+
- If \`monoban tags\` shows phase tags still on unfinished tasks from an earlier plan, say so in your
|
|
12185
|
+
proposal and ask whether to continue the numbering or reuse them.
|
|
12186
|
+
- Other tags are fine alongside (\`bug\`, \`api\`); reuse the project's existing ones. A tag is one word
|
|
12187
|
+
(no spaces, not starting with \`-\` or \`#\`), at most ${LIMITS.tagName} characters; a task has at most
|
|
12188
|
+
${LIMITS.tagsPerTask} tags.
|
|
12189
|
+
|
|
12190
|
+
## While you work
|
|
12191
|
+
|
|
12192
|
+
Ask once before you start updating the board in a session ("Shall I keep MON-31…MON-35 up to date as I
|
|
12193
|
+
go?"). Once the user agrees:
|
|
12194
|
+
|
|
12195
|
+
- Starting a task: \`monoban start MON-31\` in the repository: it checks out the task's branch (\`mon-31-…\`,
|
|
12196
|
+
made from the commit you're on, so be on the right base first) and moves it to In progress. Elsewhere,
|
|
12197
|
+
\`monoban move MON-31 "in progress"\` (columns match in any case, or by a unique prefix).
|
|
12198
|
+
- Ticking the checklist: read the description (\`monoban show MON-31 --json\`), change \`- [ ]\` to \`- [x]\`,
|
|
12199
|
+
and write the whole description back with \`monoban edit MON-31 -d -\` (stdin, a heredoc as above).
|
|
12200
|
+
- Opened a pull request for it: \`monoban attach MON-31 --pr\` right after \`gh pr create\` (on a branch named
|
|
12201
|
+
after the task, like \`mon-31-invoices\`, \`monoban attach --pr\` finds the task itself). The card shows it.
|
|
12202
|
+
- Finished: \`monoban done MON-31\`, when the work is really done by the user's standard (tests pass, merged,
|
|
12203
|
+
or whatever they said). If unsure, ask. After a merge, attach the pull request again
|
|
12204
|
+
(\`monoban attach MON-31 <its URL>\`) so the board shows it merged.
|
|
12205
|
+
- New work you discover: propose a task; don't add it silently.
|
|
12206
|
+
- Planning for a day: only when the user gives one ("do it Friday"): \`monoban schedule MON-31 fri\`. Their
|
|
12207
|
+
\`monoban today\` shows it then, and late until it's done. "What's on today?" is \`monoban today\`.
|
|
12208
|
+
|
|
12209
|
+
"changed elsewhere" means someone edited the task since you read it: read it again, then retry once.
|
|
12210
|
+
|
|
12211
|
+
## Rules
|
|
12212
|
+
|
|
12213
|
+
- Never delete a task (\`monoban rm\`) unless the user asked to delete that task.
|
|
12214
|
+
- Avoid interactive commands: \`monoban edit\` without \`--title\`/\`-d\` and \`monoban notes edit\` open an
|
|
12215
|
+
editor, \`monoban login\` a browser, and \`monoban rm\` asks for confirmation. Use flags and stdin.
|
|
12216
|
+
- Results are on stdout, messages on stderr. Exit codes: 0 ok, 1 error, 2 usage, 4 not signed in,
|
|
12217
|
+
5 not found.
|
|
12218
|
+
|
|
12219
|
+
## Commands
|
|
12220
|
+
|
|
12221
|
+
| Command | Does |
|
|
12222
|
+
| --- | --- |
|
|
12223
|
+
| \`monoban projects\` | the projects and their keys |
|
|
12224
|
+
| \`monoban list [COLUMN…] [--tag TAG] [--archived]\` | tasks by column (--archived: the ones done long ago) |
|
|
12225
|
+
| \`monoban show MON-12\` | one task in full |
|
|
12226
|
+
| \`monoban log MON-12 [-n COUNT]\` | what happened to it, newest first |
|
|
12227
|
+
| \`monoban today [DAY] [--week]\` | what's planned for today (overdue first) in every project |
|
|
12228
|
+
| \`monoban search WORDS… [-n COUNT]\` | tasks with all the words, in every project, last changed first |
|
|
12229
|
+
| \`monoban schedule MON-12 DAY\` (or \`--clear\`) | plan it for a day: today, tomorrow, fri, +3, oct 12 |
|
|
12230
|
+
| \`monoban tags\` | the tags the project's tasks can have |
|
|
12231
|
+
| \`monoban notes show\` | the project's notes |
|
|
12232
|
+
| \`monoban add "TITLE" [-c COLUMN] [-t TAG]… [--date DAY] [-d TEXT \\| -d -]\` | add a task |
|
|
12233
|
+
| \`monoban edit MON-12 [--title TEXT] [-d TEXT \\| -d -]\` | replace its title or description |
|
|
12234
|
+
| \`monoban move MON-12 COLUMN\` | move it to the end of a column |
|
|
12235
|
+
| \`monoban move MON-12 --to KEY [COLUMN]\` | move it to another project (it gets a new ref there: say it; the old one still finds it) |
|
|
12236
|
+
| \`monoban start MON-12 [--no-branch]\` | check out its branch (mon-12-title) and move it to In progress |
|
|
12237
|
+
| \`monoban done MON-12\` | move it to Done |
|
|
12238
|
+
| \`monoban tag MON-12 TAG…\` / \`monoban untag MON-12 TAG…\` | put tags on it / take them off |
|
|
12239
|
+
| \`monoban attach MON-12 --pr\` or \`monoban attach MON-12 URL\` | attach this branch's pull request, or any link |
|
|
12240
|
+
| \`monoban notes add TEXT\` (or \`-\` for stdin) | add lines at the end of the notes |
|
|
12241
|
+
|
|
12242
|
+
Every command takes \`--json\`; project commands take \`-p KEY\`. \`monoban COMMAND --help\` has the rest.
|
|
12243
|
+
`;
|
|
12244
|
+
//#endregion
|
|
12245
|
+
//#region src/commands/setup.ts
|
|
12246
|
+
/** Where each agent looks for skills: in your home folder, or in a repository (`--project`). */
|
|
12247
|
+
const FOLDER = {
|
|
12248
|
+
claude: ".claude",
|
|
12249
|
+
codex: ".agents"
|
|
12250
|
+
};
|
|
12251
|
+
/**
|
|
12252
|
+
* The skill's file: ~/.claude/skills/monoban/SKILL.md (or ~/.agents/… for Codex), or with --project the
|
|
12253
|
+
* same at the top of the repository; and how to show it ("~/.claude/…", or ".claude/…" in the repository).
|
|
12254
|
+
*/
|
|
12255
|
+
async function skillPath(ctx, agent, project = false) {
|
|
12256
|
+
const base = project ? await ctx.clone.root() : ctx.env.HOME || homedir();
|
|
12257
|
+
const inside = join(FOLDER[agent], "skills", "monoban", "SKILL.md");
|
|
12258
|
+
return {
|
|
12259
|
+
path: join(base, inside),
|
|
12260
|
+
shown: project ? inside : join("~", inside)
|
|
12261
|
+
};
|
|
12262
|
+
}
|
|
12263
|
+
const read = (path) => readFile(path, "utf8").catch((err) => {
|
|
12264
|
+
if (err.code === "ENOENT") return null;
|
|
12265
|
+
throw err;
|
|
12266
|
+
});
|
|
12267
|
+
/**
|
|
12268
|
+
* `monoban setup claude|codex`: installs the monoban skill, which teaches the agent the CLI, to offer a
|
|
12269
|
+
* plan as board tasks (phases as tags) and to keep them current. Running it again updates the skill;
|
|
12270
|
+
* a SKILL.md it didn't write is replaced only with --force.
|
|
12271
|
+
*/
|
|
12272
|
+
async function setup(ctx, agent, options) {
|
|
12273
|
+
const name = AGENT_NAMES[agent];
|
|
12274
|
+
const content = skillFile(agent);
|
|
12275
|
+
if (options.print) return ctx.out(content.trimEnd());
|
|
12276
|
+
const { path, shown } = await skillPath(ctx, agent, options.project);
|
|
12277
|
+
const existing = await read(path);
|
|
12278
|
+
const ours = existing?.includes("<!-- Written by `monoban setup`") ?? false;
|
|
12279
|
+
const report = (action, message) => options.json ? ctx.out(JSON.stringify({
|
|
12280
|
+
agent,
|
|
12281
|
+
path,
|
|
12282
|
+
action
|
|
12283
|
+
}, null, 2)) : ctx.out(message);
|
|
12284
|
+
if (existing !== null && !ours && !options.force) throw new CliError(`${shown} is a monoban skill that \`monoban setup\` didn't write. Pass --force to ${options.remove ? "remove" : "replace"} it.`);
|
|
12285
|
+
if (options.remove) {
|
|
12286
|
+
if (existing === null) {
|
|
12287
|
+
if (options.json) return report("none", "");
|
|
12288
|
+
return ctx.err(`The monoban skill isn't installed for ${name} at ${shown}.`);
|
|
12289
|
+
}
|
|
12290
|
+
await rm(path);
|
|
12291
|
+
await rmdir(dirname(path)).catch(() => {});
|
|
12292
|
+
return report("removed", `Removed the monoban skill for ${name}: ${shown}.`);
|
|
12293
|
+
}
|
|
12294
|
+
if (existing === content) return report("unchanged", `The monoban skill for ${name} is up to date: ${shown}.`);
|
|
12295
|
+
await mkdir(dirname(path), { recursive: true });
|
|
12296
|
+
await writeFile(path, content);
|
|
12297
|
+
report(existing === null ? "installed" : "updated", `${existing === null ? "Installed" : "Updated"} the monoban skill for ${name}: ${shown}.`);
|
|
12298
|
+
if (options.json) return;
|
|
12299
|
+
if (agent === "claude") ctx.err(`It lets Claude run commands that only read (${READ_ONLY.map((c) => c.slice(8)).join(", ")}) without asking.`);
|
|
12300
|
+
ctx.err(options.project ? `Commit it so everyone working in this repository gets it. New ${name} sessions use it.` : `New ${name} sessions use it, in any repository. Ask one to plan something, or say "put it on monoban".`);
|
|
12301
|
+
}
|
|
12302
|
+
//#endregion
|
|
12303
|
+
//#region src/commands/start.ts
|
|
12304
|
+
/** How long a branch name's words may be, after `mon-12-`. */
|
|
12305
|
+
const SLUG_LENGTH = 40;
|
|
12306
|
+
/** The branch for a task: `mon-12-import-boards-from-trello` (its ref, then its title's first words). */
|
|
12307
|
+
function branchName(ref, title) {
|
|
12308
|
+
const words = title.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
12309
|
+
const cut = words.length > SLUG_LENGTH ? words.slice(0, 41).replace(/-[^-]*$/, "") : words;
|
|
12310
|
+
return [ref.toLowerCase(), cut].filter(Boolean).join("-");
|
|
12311
|
+
}
|
|
12312
|
+
/**
|
|
12313
|
+
* The column where work happens: the one named In progress (or Doing, WIP…), else the one after the
|
|
12314
|
+
* first, unless that's Done. undefined when the board has none (Backlog and Done only).
|
|
12315
|
+
*/
|
|
12316
|
+
function workColumn(columns) {
|
|
12317
|
+
const names = [
|
|
12318
|
+
"in progress",
|
|
12319
|
+
"in-progress",
|
|
12320
|
+
"doing",
|
|
12321
|
+
"wip",
|
|
12322
|
+
"started",
|
|
12323
|
+
"working",
|
|
12324
|
+
"active"
|
|
12325
|
+
];
|
|
12326
|
+
const named = columns.find((c) => names.includes(c.name.trim().toLowerCase()));
|
|
12327
|
+
if (named) return named;
|
|
12328
|
+
const second = columns[1];
|
|
12329
|
+
return second && second !== doneColumn(columns) ? second : void 0;
|
|
12330
|
+
}
|
|
12331
|
+
/**
|
|
12332
|
+
* `monoban start MON-12`: work on a task. Checks out its branch (`mon-12-title`: made from the commit
|
|
12333
|
+
* you're on, or the one already there) and moves it to In progress, unless it's there or further on.
|
|
12334
|
+
* --no-branch and --no-move do half of it.
|
|
12335
|
+
*/
|
|
12336
|
+
async function start(ctx, ref, options) {
|
|
12337
|
+
const api = apis(ctx).signedIn;
|
|
12338
|
+
let task = await taskByRef(api, ref, ctx);
|
|
12339
|
+
const { key, number } = taskRefOf(task.ref);
|
|
12340
|
+
const columns = await columnsOf(api, key);
|
|
12341
|
+
const lines = [];
|
|
12342
|
+
let branch = null;
|
|
12343
|
+
if (options.branch !== false) {
|
|
12344
|
+
if (!await ctx.clone.inClone()) throw new CliError("Not in a git clone, so there's no branch to make. Run it in the repository, or with --no-branch.", EXIT.usage);
|
|
12345
|
+
const current = await ctx.clone.branch();
|
|
12346
|
+
const own = (name) => taskOfBranch(name) === task.ref;
|
|
12347
|
+
if (own(current)) {
|
|
12348
|
+
branch = current;
|
|
12349
|
+
lines.push(`Already on ${branch}.`);
|
|
12350
|
+
} else {
|
|
12351
|
+
const existing = (await ctx.clone.branches()).find(own);
|
|
12352
|
+
branch = existing ?? branchName(task.ref, task.title);
|
|
12353
|
+
const why = await ctx.clone.switchTo(branch, !existing);
|
|
12354
|
+
if (why) throw new CliError(`git couldn't switch to ${branch}: ${why}`);
|
|
12355
|
+
lines.push(existing ? `Switched to ${branch}.` : `Switched to a new branch ${branch}.`);
|
|
12356
|
+
}
|
|
12357
|
+
}
|
|
12358
|
+
if (options.move !== false) {
|
|
12359
|
+
const target = workColumn(columns);
|
|
12360
|
+
const at = (t) => columns.findIndex((c) => c.id === t.columnId);
|
|
12361
|
+
const here = columns[at(task)];
|
|
12362
|
+
if (!target) lines.push(`${task.ref} stays in ${here?.name ?? "its column"}: the board has no In progress column.`);
|
|
12363
|
+
else if (at(task) >= columns.indexOf(target)) lines.push(`${task.ref} is in ${here?.name ?? "its column"} already.`);
|
|
12364
|
+
else {
|
|
12365
|
+
task = await unwrap(api.PATCH("/v1/projects/{key}/tasks/{number}", {
|
|
12366
|
+
params: {
|
|
12367
|
+
path: {
|
|
12368
|
+
key,
|
|
12369
|
+
number
|
|
12370
|
+
},
|
|
12371
|
+
header: ifMatch(task.version)
|
|
12372
|
+
},
|
|
12373
|
+
body: { columnId: target.id }
|
|
12374
|
+
})).catch((err) => changedElsewhere(err, task.ref));
|
|
12375
|
+
lines.push(`Moved ${task.ref}${here ? ` from ${here.name}` : ""} to ${target.name}.`);
|
|
12376
|
+
}
|
|
12377
|
+
}
|
|
12378
|
+
if (options.json) {
|
|
12379
|
+
const json = {
|
|
12380
|
+
...taskJson(task, columns, await tagsFor(api, key, task)),
|
|
12381
|
+
branch
|
|
12382
|
+
};
|
|
12383
|
+
return ctx.out(JSON.stringify(json, null, 2));
|
|
12384
|
+
}
|
|
12385
|
+
for (const line of lines) ctx.out(line);
|
|
12386
|
+
}
|
|
12387
|
+
//#endregion
|
|
10727
12388
|
//#region src/complete.ts
|
|
10728
12389
|
/**
|
|
10729
12390
|
* Shell completion (`monoban completion bash|zsh|fish`). The scripts are thin: on Tab they run
|
|
10730
12391
|
* `monoban __complete -- WORD… CURRENT`, which prints one `value<TAB>description` per line. Commands and
|
|
10731
|
-
* options come from the command tree; project keys, columns and
|
|
12392
|
+
* options come from the command tree; project keys, columns, tasks and tags from the API (when signed in).
|
|
10732
12393
|
*/
|
|
10733
12394
|
const SHELLS = [
|
|
10734
12395
|
"bash",
|
|
@@ -10739,9 +12400,12 @@ const SHELLS = [
|
|
|
10739
12400
|
const VALUES = {
|
|
10740
12401
|
project: "projects",
|
|
10741
12402
|
key: "projects",
|
|
12403
|
+
to: "projects",
|
|
10742
12404
|
column: "columns",
|
|
10743
12405
|
columns: "columns",
|
|
10744
|
-
task: "tasks"
|
|
12406
|
+
task: "tasks",
|
|
12407
|
+
tag: "tags",
|
|
12408
|
+
tags: "tags"
|
|
10745
12409
|
};
|
|
10746
12410
|
const takesValue = (option) => option.required || option.optional;
|
|
10747
12411
|
/** What can come next, for `words` (everything after `monoban`, the last one being the word being typed). */
|
|
@@ -10751,11 +12415,13 @@ async function complete(root, words, lookup) {
|
|
|
10751
12415
|
let command = root;
|
|
10752
12416
|
let positionals = 0;
|
|
10753
12417
|
let pending;
|
|
12418
|
+
let to;
|
|
10754
12419
|
let project;
|
|
10755
12420
|
let taskProject;
|
|
10756
12421
|
let dashes = false;
|
|
10757
12422
|
for (const word of words.slice(0, -1)) if (pending) {
|
|
10758
12423
|
if (pending.attributeName() === "project") project = word;
|
|
12424
|
+
if (pending.attributeName() === "to") to = word;
|
|
10759
12425
|
pending = void 0;
|
|
10760
12426
|
} else if (!dashes && word === "--") dashes = true;
|
|
10761
12427
|
else if (!dashes && word.startsWith("-") && word !== "-") {
|
|
@@ -10764,6 +12430,7 @@ async function complete(root, words, lookup) {
|
|
|
10764
12430
|
if (option && takesValue(option)) {
|
|
10765
12431
|
if (value === void 0) pending = option;
|
|
10766
12432
|
else if (option.attributeName() === "project") project = value;
|
|
12433
|
+
else if (option.attributeName() === "to") to = value;
|
|
10767
12434
|
}
|
|
10768
12435
|
} else if (command.commands.length) {
|
|
10769
12436
|
const next = command.commands.find((c) => c.name() === word || c.aliases().includes(word));
|
|
@@ -10774,7 +12441,11 @@ async function complete(root, words, lookup) {
|
|
|
10774
12441
|
taskProject ??= parseTaskRef(word)?.key;
|
|
10775
12442
|
}
|
|
10776
12443
|
project ??= taskProject;
|
|
10777
|
-
|
|
12444
|
+
const where = {
|
|
12445
|
+
project,
|
|
12446
|
+
columns: to ?? project
|
|
12447
|
+
};
|
|
12448
|
+
if (pending) return values(pending.attributeName(), pending.argChoices, lookup, where, current);
|
|
10778
12449
|
if (!dashes && current.startsWith("-")) return help.visibleOptions(command).flatMap((o) => o.long ? [{
|
|
10779
12450
|
value: o.long,
|
|
10780
12451
|
description: o.description
|
|
@@ -10786,17 +12457,18 @@ async function complete(root, words, lookup) {
|
|
|
10786
12457
|
const args = command.registeredArguments;
|
|
10787
12458
|
const last = args.at(-1);
|
|
10788
12459
|
const arg = args[positionals] ?? (last?.variadic ? last : void 0);
|
|
10789
|
-
return arg ? values(arg.name(), arg.argChoices, lookup,
|
|
12460
|
+
return arg ? values(arg.name(), arg.argChoices, lookup, where, current) : [];
|
|
10790
12461
|
}
|
|
10791
|
-
function values(name, choices, lookup, project, current) {
|
|
12462
|
+
function values(name, choices, lookup, { project, columns }, current) {
|
|
10792
12463
|
if (choices) return choices.map((value) => ({
|
|
10793
12464
|
value,
|
|
10794
12465
|
description: ""
|
|
10795
12466
|
}));
|
|
10796
12467
|
switch (VALUES[name]) {
|
|
10797
12468
|
case "projects": return lookup.projects();
|
|
10798
|
-
case "columns": return lookup.columns(
|
|
12469
|
+
case "columns": return lookup.columns(columns);
|
|
10799
12470
|
case "tasks": return lookup.tasks(/^([^-\s]+)-/.exec(current)?.[1] ?? project);
|
|
12471
|
+
case "tags": return lookup.tags(project);
|
|
10800
12472
|
default: return [];
|
|
10801
12473
|
}
|
|
10802
12474
|
}
|
|
@@ -10835,7 +12507,11 @@ function apiLookup(ctx, deadlineMs = 2e3) {
|
|
|
10835
12507
|
value: t.ref,
|
|
10836
12508
|
description: `${t.title} (${columns.get(t.columnId)})`
|
|
10837
12509
|
}));
|
|
10838
|
-
}
|
|
12510
|
+
},
|
|
12511
|
+
tags: async (project) => (await tagsOf(api, await resolveProject(ctx, api, project))).map((t) => ({
|
|
12512
|
+
value: t.name,
|
|
12513
|
+
description: t.project ? `${t.project} only` : "shared"
|
|
12514
|
+
}))
|
|
10839
12515
|
};
|
|
10840
12516
|
}
|
|
10841
12517
|
/** `monoban __complete`: the lines for the shell. Quiet on any error (not signed in, offline…). */
|
|
@@ -10966,7 +12642,7 @@ async function latestVersion(ctx) {
|
|
|
10966
12642
|
async function upgrade(ctx, options, kind = thisInstall()) {
|
|
10967
12643
|
const latest = await latestVersion(ctx);
|
|
10968
12644
|
const { how, command } = UPGRADE[kind];
|
|
10969
|
-
const outdated = latest !== null && newer(latest, "1.
|
|
12645
|
+
const outdated = latest !== null && newer(latest, "1.2.0");
|
|
10970
12646
|
if (options.json) {
|
|
10971
12647
|
ctx.out(JSON.stringify({
|
|
10972
12648
|
version: VERSION,
|
|
@@ -10988,22 +12664,40 @@ function program(ctx) {
|
|
|
10988
12664
|
const cli = new Command("monoban").description("monoban.dev from your terminal: a keyboard-first kanban board.").version(VERSION, "-v, --version").showHelpAfterError("(run `monoban --help` for usage)").exitOverride();
|
|
10989
12665
|
const json = () => new Option("--json", "print JSON");
|
|
10990
12666
|
const project = () => new Option("-p, --project <key>", "the project (else $MONOBAN_PROJECT, or your only project)");
|
|
12667
|
+
const collect = (value, previous = []) => [...previous, value];
|
|
10991
12668
|
cli.command("login").description("Sign in: approve in your browser, with --device a code on any other device, or --with-token (CI)").option("--device", "sign in with a code (for SSH, containers, or no browser)").option("--browser", "open the browser even over SSH").option("--with-token", "use a personal access token (for CI), read from stdin").action(async (options) => login(await ctx(), options));
|
|
10992
12669
|
cli.command("logout").description("Sign out, here and on the server").action(async () => logout(await ctx()));
|
|
10993
12670
|
cli.command("whoami").description("Show who you're signed in as").addOption(json()).action(async (options) => whoami(await ctx(), options));
|
|
10994
12671
|
cli.command("projects").description("List your projects and their keys").addOption(json()).action(async (options) => projects(await ctx(), options));
|
|
10995
12672
|
cli.command("link").argument("[key]", "the project (else the one already linked, or your only one)").description("Link a project to this clone's GitHub repository, so commands here use it").addOption(json()).action(async (key, options) => link(await ctx(), key, options));
|
|
10996
12673
|
cli.command("unlink").description("Undo `monoban link` for this clone's repository").addOption(json()).action(async (options) => unlink(await ctx(), options));
|
|
10997
|
-
cli.command("list").alias("ls").argument("[columns...]", "only these columns (any case; a prefix works: `back`, `inp`)").description("Show the board's tasks by column").addOption(project()).addOption(json()).action(async (columns, options) => list(await ctx(), columns, options));
|
|
10998
|
-
cli.command("show").argument("<task>", "like MON-12").description("Show a task: title, column, checklist and description").addOption(json()).action(async (ref, options) => show(await ctx(), ref, options));
|
|
10999
|
-
cli.command("
|
|
11000
|
-
cli.command("
|
|
12674
|
+
cli.command("list").alias("ls").argument("[columns...]", "only these columns (any case; a prefix works: `back`, `inp`)").description("Show the board's tasks by column").option("-t, --tag <tag>", "only tasks with this tag").option("--archived", "the archived tasks instead (done a while ago, off the board)").addOption(project()).addOption(json()).action(async (columns, options) => list(await ctx(), columns, options));
|
|
12675
|
+
cli.command("show").argument("<task>", "like MON-12").description("Show a task: title, column, tags, checklist and description").addOption(json()).action(async (ref, options) => show(await ctx(), ref, options));
|
|
12676
|
+
cli.command("log").argument("<task>", "like MON-12").description("Show what happened to a task, newest first: created, moved, edited, tags, links").option("-n, --number <count>", "how many events (default 20)").addOption(json()).action(async (ref, options) => log(await ctx(), ref, options));
|
|
12677
|
+
cli.command("add").argument("<title>").description("Add a task (to the end of the first column, or of -c)").option("-c, --column <column>", "the column to add it to").option("-d, --description <text>", "its description (- reads it from stdin)").option("-e, --edit", "write the description in $EDITOR").option("-t, --tag <tag>", "a tag (repeat for more; a new name makes a tag)", collect).option("--date <day>", "the day to do it: today, tomorrow, fri, +3, oct 12…").addOption(project()).addOption(json()).action(async (title, options) => add(await ctx(), title, options));
|
|
12678
|
+
cli.command("today").argument("[day]", "another day: tomorrow, fri, oct 12, 2026-10-12…").description("Show what's planned for today in every project (overdue first), or for another day").option("-w, --week", "the 7 days from it").addOption(json()).action(async (day, options) => todayView(await ctx(), day, options));
|
|
12679
|
+
cli.command("search").argument("<words...>", "all of them: in the title or description, a tag, or a reference like MON-12").description("Find tasks in every project, the last changed first").option("-n, --number <count>", "how many tasks (default 30)").addOption(json()).action(async (words, options) => search(await ctx(), words, options));
|
|
12680
|
+
cli.command("schedule").argument("<task>", "like MON-12").argument("[day]", "today, tomorrow, fri, next week, +3, oct 12, 2026-10-12…").description("Plan a task for a day (it shows in `monoban today` then), or take its date off with --clear").option("--clear", "take the date off").addOption(json()).action(async (ref, day, options) => schedule(await ctx(), ref, day, options));
|
|
12681
|
+
cli.command("move").argument("<task>", "like MON-12").argument("[column]", "where to (any case; a prefix works)").description("Move a task to the end of another column, or (--to) to another project").option("--to <project>", "another project's key: the task gets a number there (MON-12 becomes WEB-7)").addOption(json()).action(async (ref, column, options) => move(await ctx(), ref, column, options));
|
|
11001
12682
|
cli.command("done").argument("<task>", "like MON-12").description("Move a task to Done (or the last column)").addOption(json()).action(async (ref, options) => done(await ctx(), ref, options));
|
|
11002
|
-
cli.command("
|
|
12683
|
+
cli.command("start").argument("<task>", "like MON-12").description("Start a task: check out its branch (mon-12-title, made from the commit you're on) and move it to In progress").option("--no-branch", "only move it").option("--no-move", "only check out its branch").addOption(json()).action(async (ref, options) => start(await ctx(), ref, options));
|
|
12684
|
+
cli.command("edit").argument("<task>", "like MON-12").description("Edit a task's title (the first line) and description in $EDITOR, or set them with --title and -d").option("--title <text>", "a new title (no editor)").option("-d, --description <text>", "a new description, replacing it (- reads it from stdin; no editor)").addOption(json()).action(async (ref, options) => edit(await ctx(), ref, options));
|
|
11003
12685
|
cli.command("rm").argument("<task>", "like MON-12").description("Delete a task (asks first)").option("-y, --yes", "don't ask").addOption(json()).action(async (ref, options) => rm$1(await ctx(), ref, options));
|
|
12686
|
+
cli.command("tag").argument("<task>", "like MON-12").argument("<tags...>", "tag names (a new name makes a tag in the task's project)").description("Put tags on a task").addOption(json()).action(async (ref, names, options) => tag(await ctx(), ref, names, options));
|
|
12687
|
+
cli.command("untag").argument("<task>", "like MON-12").argument("<tags...>", "tag names").description("Take tags off a task").addOption(json()).action(async (ref, names, options) => untag(await ctx(), ref, names, options));
|
|
12688
|
+
cli.command("attach").argument("[task]", "like MON-12 (else the one this branch is named after: mon-12-…)").argument("[link]", "a pull request, an issue, a commit, or any page").description("Attach a link to a task (again: refresh it); --pr attaches this branch's pull request").option("--pr", "this branch's pull request, with its title and state (needs gh)").option("--title <text>", "its title (a pull request's or an issue's comes from gh)").addOption(json()).action(async (task, link, options) => attach(await ctx(), [task, link].filter((a) => a !== void 0), options));
|
|
12689
|
+
cli.command("detach").argument("<task>", "like MON-12").argument("<link>", "#54, or its URL").description("Take a link off a task").addOption(json()).action(async (ref, link, options) => detach(await ctx(), ref, link, options));
|
|
12690
|
+
cli.command("tags").description("List the tags a project's tasks can have: its own and the shared ones").addOption(project()).addOption(json()).action(async (options) => tags(await ctx(), options));
|
|
12691
|
+
const notes = cli.command("notes").description("A project's notes: print them, add a line, or edit them in $EDITOR");
|
|
12692
|
+
notes.command("show", { isDefault: true }).description("Print the notes (the default)").addOption(project()).addOption(json()).action(async (options) => notesShow(await ctx(), options));
|
|
12693
|
+
notes.command("add").argument("<text...>", "the line to add (- reads it from stdin)").description("Add a line at the end of the notes").addOption(project()).addOption(json()).action(async (words, options) => notesAdd(await ctx(), words, options));
|
|
12694
|
+
notes.command("edit").description("Edit the notes in $EDITOR").addOption(project()).addOption(json()).action(async (options) => notesEdit(await ctx(), options));
|
|
11004
12695
|
cli.command("open").argument("[task]", "like MON-12").description("Open the board, or a task, in the browser").addOption(project()).action(async (ref, options) => open$1(await ctx(), ref, options));
|
|
12696
|
+
cli.command("setup").addArgument(new Argument("<agent>", "which agent: claude (Claude Code) or codex").choices(AGENTS)).description("Teach a coding agent monoban: a skill to plan work as tasks (phases as tags) and keep them current").option("--project", "install it in this repository (to commit), not for you in every one").option("--print", "print the skill instead of installing it").option("--remove", "remove the skill").option("-f, --force", "replace (or remove) a skill monoban didn't write").addOption(json()).addHelpText("after", `
|
|
12697
|
+
It goes in ~/.claude/skills/monoban (Claude Code) or ~/.agents/skills/monoban (Codex); with --project,
|
|
12698
|
+
in .claude/skills or .agents/skills at the top of this repository. Run it again after upgrading monoban.`).action(async (agent, options) => setup(await ctx(), agent, options));
|
|
11005
12699
|
cli.command("upgrade").description("Check for a newer version, and say how to install it (Homebrew, npm…)").addOption(json()).action(async (options) => upgrade(await ctx(), options));
|
|
11006
|
-
cli.command("completion").addArgument(new Argument("<shell>", "bash, zsh or fish").choices(SHELLS)).description("Print the script that makes Tab complete commands, projects, columns and
|
|
12700
|
+
cli.command("completion").addArgument(new Argument("<shell>", "bash, zsh or fish").choices(SHELLS)).description("Print the script that makes Tab complete commands, projects, columns, tasks and tags").addHelpText("after", `
|
|
11007
12701
|
Load it in your shell:
|
|
11008
12702
|
bash in ~/.bashrc: eval "$(monoban completion bash)"
|
|
11009
12703
|
zsh in ~/.zshrc: eval "$(monoban completion zsh)" (after compinit)
|