monoban 1.1.0 → 1.3.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.
Files changed (3) hide show
  1. package/README.md +10 -1
  2. package/dist/index.mjs +1007 -50
  3. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -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);
@@ -5392,9 +5395,169 @@ const LIMITS = {
5392
5395
  projectNotes: 1e5,
5393
5396
  linksPerTask: 20,
5394
5397
  linkUrl: 2e3,
5395
- linkTitle: 200
5398
+ linkTitle: 200,
5399
+ /** A comment on a task, in characters. */
5400
+ commentBody: 2e4,
5401
+ commentsPerTask: 500
5396
5402
  };
5397
5403
  //#endregion
5404
+ //#region ../../packages/contract/src/dates.ts
5405
+ /**
5406
+ * Days, as tasks are scheduled: "2026-10-02", no time and no time zone. "Today" is the user's own: clients
5407
+ * work it out from their clock (today()) and send it, so the API never guesses a time zone.
5408
+ */
5409
+ const DAY_MS$1 = 864e5;
5410
+ const DAY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
5411
+ const WEEKDAYS = [
5412
+ "sunday",
5413
+ "monday",
5414
+ "tuesday",
5415
+ "wednesday",
5416
+ "thursday",
5417
+ "friday",
5418
+ "saturday"
5419
+ ];
5420
+ const MONTHS = [
5421
+ "january",
5422
+ "february",
5423
+ "march",
5424
+ "april",
5425
+ "may",
5426
+ "june",
5427
+ "july",
5428
+ "august",
5429
+ "september",
5430
+ "october",
5431
+ "november",
5432
+ "december"
5433
+ ];
5434
+ const SHORT_WEEKDAYS = [
5435
+ "Sun",
5436
+ "Mon",
5437
+ "Tue",
5438
+ "Wed",
5439
+ "Thu",
5440
+ "Fri",
5441
+ "Sat"
5442
+ ];
5443
+ const SHORT_MONTHS = [
5444
+ "Jan",
5445
+ "Feb",
5446
+ "Mar",
5447
+ "Apr",
5448
+ "May",
5449
+ "Jun",
5450
+ "Jul",
5451
+ "Aug",
5452
+ "Sep",
5453
+ "Oct",
5454
+ "Nov",
5455
+ "Dec"
5456
+ ];
5457
+ const pad = (n) => String(n).padStart(2, "0");
5458
+ const fromUtc = (ms) => {
5459
+ const d = new Date(ms);
5460
+ return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
5461
+ };
5462
+ /** Midnight UTC of a day: arithmetic on it never meets a daylight-saving change. */
5463
+ const utc = (day) => {
5464
+ const [, y, m, d] = DAY_PATTERN.exec(day) ?? [];
5465
+ return Date.UTC(Number(y), Number(m) - 1, Number(d));
5466
+ };
5467
+ /** Whether `value` is a real day ("2026-02-30" isn't). */
5468
+ function isDay(value) {
5469
+ return DAY_PATTERN.test(value) && fromUtc(utc(value)) === value;
5470
+ }
5471
+ /** Today, by this device's clock and time zone. */
5472
+ function today(now = /* @__PURE__ */ new Date()) {
5473
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
5474
+ }
5475
+ function addDays(day, days) {
5476
+ return fromUtc(utc(day) + days * DAY_MS$1);
5477
+ }
5478
+ /** How many days from `from` to `to` (negative when `to` is earlier). */
5479
+ function daysBetween(from, to) {
5480
+ return Math.round((utc(to) - utc(from)) / DAY_MS$1);
5481
+ }
5482
+ /** 0 is Sunday. */
5483
+ const weekday = (day) => new Date(utc(day)).getUTCDay();
5484
+ /** A day in a few characters, next to `today`: "today", "tomorrow", "yesterday", "Fri" (this week), "Oct 12". */
5485
+ function formatDay(day, now) {
5486
+ const diff = daysBetween(now, day);
5487
+ if (diff === 0) return "today";
5488
+ if (diff === 1) return "tomorrow";
5489
+ if (diff === -1) return "yesterday";
5490
+ if (diff > 1 && diff < 7) return SHORT_WEEKDAYS[weekday(day)];
5491
+ const d = new Date(utc(day));
5492
+ const month = `${SHORT_MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}`;
5493
+ return day.slice(0, 4) === now.slice(0, 4) ? month : `${month}, ${day.slice(0, 4)}`;
5494
+ }
5495
+ /** A day in full, for a heading: "Thu Oct 2" (with the year when it isn't this one). */
5496
+ function longDay(day, now) {
5497
+ const d = new Date(utc(day));
5498
+ const text = `${SHORT_WEEKDAYS[d.getUTCDay()]} ${SHORT_MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}`;
5499
+ return day.slice(0, 4) === now.slice(0, 4) ? text : `${text}, ${day.slice(0, 4)}`;
5500
+ }
5501
+ /** The weekday a word names, by its first letters ("fri", "tues"); -1 if none. */
5502
+ const weekdayOf = (word) => word.length >= 2 ? WEEKDAYS.findIndex((name) => name.startsWith(word)) : -1;
5503
+ /** The month a word names, by its first three letters or more ("oct", "october"); -1 if none. */
5504
+ const monthOf = (word) => word.length >= 3 ? MONTHS.findIndex((name) => name.startsWith(word)) : -1;
5505
+ /**
5506
+ * The day someone means, typed loosely, or null: "today", "tomorrow" ("tom"), "yesterday", a weekday ("fri":
5507
+ * the next one, today included; "next fri": after today), "next week" (Monday), "weekend" (Saturday),
5508
+ * "+3" or "3d" (days ahead), "2w", "oct 12" or "12 oct" (the next one; a year after it works too), or
5509
+ * "2026-10-12".
5510
+ */
5511
+ function parseDay(input, now) {
5512
+ const text = input.trim().toLowerCase().replace(/\s+/g, " ").replace(/,/g, "");
5513
+ if (!text) return null;
5514
+ if ([
5515
+ "today",
5516
+ "tod",
5517
+ "now"
5518
+ ].includes(text)) return now;
5519
+ if ([
5520
+ "tomorrow",
5521
+ "tom",
5522
+ "tmr",
5523
+ "tmrw"
5524
+ ].includes(text)) return addDays(now, 1);
5525
+ if (text === "yesterday") return addDays(now, -1);
5526
+ if (isDay(text)) return text;
5527
+ const ahead = /^\+?(\d{1,3}) ?(d|days?|w|weeks?)?$/.exec(text);
5528
+ if (ahead && (text.startsWith("+") || ahead[2])) {
5529
+ const n = Number(ahead[1]);
5530
+ return addDays(now, ahead[2]?.startsWith("w") ? n * 7 : n);
5531
+ }
5532
+ const next = (target, from) => addDays(now, from + (target - weekday(addDays(now, from)) + 7) % 7);
5533
+ if (text === "next week") return next(1, 1);
5534
+ if (text === "weekend") return next(6, 0);
5535
+ const [first = "", second] = text.split(" ");
5536
+ if (first === "next" && second && weekdayOf(second) >= 0) return next(weekdayOf(second), 1);
5537
+ if (!second && weekdayOf(first) >= 0) return next(weekdayOf(first), 0);
5538
+ const words = text.split(" ");
5539
+ const month = words.map(monthOf).find((m) => m >= 0) ?? -1;
5540
+ const numbers = words.filter((w) => /^\d{1,4}$/.test(w)).map(Number);
5541
+ if (month >= 0 && words.length <= 3 && words.length === numbers.length + 1) {
5542
+ const [date, year] = numbers;
5543
+ if (!date || date > 31) return null;
5544
+ const make = (y) => `${y}-${pad(month + 1)}-${pad(date)}`;
5545
+ if (year !== void 0) return year >= 1e3 && isDay(make(year)) ? make(year) : null;
5546
+ const thisYear = Number(now.slice(0, 4));
5547
+ const day = make(thisYear);
5548
+ if (!isDay(day)) return null;
5549
+ return day < now ? isDay(make(thisYear + 1)) ? make(thisYear + 1) : null : day;
5550
+ }
5551
+ return null;
5552
+ }
5553
+ /**
5554
+ * A project's Done column, as `monoban done` and the Today view read it: the one named Done (any case),
5555
+ * else the last. `columns` in board order.
5556
+ */
5557
+ function doneColumn(columns) {
5558
+ return columns.find((c) => c.name.trim().toLowerCase() === "done") ?? columns.at(-1);
5559
+ }
5560
+ //#endregion
5398
5561
  //#region ../../packages/contract/src/links.ts
5399
5562
  /** What a task's link points at. */
5400
5563
  const LINK_KINDS = [
@@ -5874,6 +6037,11 @@ const Version = string().regex(/^[A-Za-z0-9_-]{16}$/).describe("For If-Match; ch
5874
6037
  * into this form with normalizeRepo() first; the API only lowercases it.
5875
6038
  */
5876
6039
  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" });
6040
+ /** A day, without a time or a time zone: "2026-10-12". */
6041
+ const DaySchema = string().regex(/^\d{4}-\d{2}-\d{2}$/, "A day like 2026-10-12").refine(isDay, "Not a real day").meta({
6042
+ format: "date",
6043
+ example: "2026-10-12"
6044
+ });
5877
6045
  /** A Postgres uuid: any 8-4-4-4-12 hex id (not only RFC 9562 versions, which is what z.uuid() checks). */
5878
6046
  const IdSchema = guid();
5879
6047
  const ProjectSchema = object({
@@ -5890,6 +6058,8 @@ const ProjectSchema = object({
5890
6058
  repo: string().nullable(),
5891
6059
  /** The web board opens a task after you add it, so you can write its description. */
5892
6060
  openNewTasks: boolean(),
6061
+ /** Days a task stays in the Done column before it's archived (off the board); null: never. */
6062
+ archiveAfterDays: number$1().int().min(1).max(365).nullable(),
5893
6063
  createdAt: Timestamp,
5894
6064
  updatedAt: Timestamp
5895
6065
  }).meta({ id: "Project" });
@@ -5918,7 +6088,9 @@ strictObject({
5918
6088
  /** Link a GitHub repository; null unlinks. One project per repository (409 if another has it). */
5919
6089
  repo: RepoSchema.nullable().optional(),
5920
6090
  /** Open a task on the web board after adding it. */
5921
- openNewTasks: boolean().optional()
6091
+ openNewTasks: boolean().optional(),
6092
+ /** Days in Done before a task is archived (1–365); null: never. */
6093
+ archiveAfterDays: number$1().int().min(1).max(365).nullable().optional()
5922
6094
  }).refine((patch) => Object.keys(patch).length > 0, "Send at least one field to change").meta({
5923
6095
  id: "ProjectPatch",
5924
6096
  minProperties: 1
@@ -6035,6 +6207,21 @@ strictObject({
6035
6207
  */
6036
6208
  state: _enum(LINK_STATES).nullable().optional()
6037
6209
  }).meta({ id: "TaskLinkCreate" });
6210
+ /** A comment: Markdown, kept as written (not trimmed), and not blank. */
6211
+ const commentBody = string().min(1, "Required").max(LIMITS.commentBody).regex(/^[^\u0000]*$/, "Can't contain NUL characters");
6212
+ object({
6213
+ id: IdSchema,
6214
+ body: string(),
6215
+ /** What wrote it: `web`, `cli` or `api` (another client). */
6216
+ via: string().nullable(),
6217
+ version: Version,
6218
+ createdAt: Timestamp
6219
+ }).meta({ id: "TaskComment" });
6220
+ strictObject({
6221
+ /** Chosen by the client (a random uuid) so it can show the comment before the answer; 409 if taken. */
6222
+ id: IdSchema.optional(),
6223
+ body: commentBody
6224
+ }).meta({ id: "TaskCommentCreate" });
6038
6225
  strictObject({
6039
6226
  /** Chosen by the client (a random uuid) so it can show and edit the new item before the answer; 409 if taken. */
6040
6227
  id: IdSchema.optional(),
@@ -6044,7 +6231,9 @@ strictObject({
6044
6231
  columnId: IdSchema.optional(),
6045
6232
  /** Where it goes in the column; the end when left out. */
6046
6233
  position: PositionSchema.optional(),
6047
- tagIds: tagIds.optional()
6234
+ tagIds: tagIds.optional(),
6235
+ /** The day you plan to work on it. */
6236
+ scheduledOn: DaySchema.nullable().optional()
6048
6237
  }).meta({ id: "TaskCreate" });
6049
6238
  strictObject({
6050
6239
  title: taskTitle.optional(),
@@ -6054,11 +6243,27 @@ strictObject({
6054
6243
  /** New place in the column. */
6055
6244
  position: PositionSchema.optional(),
6056
6245
  /** Its tags from now on (all of them: the list replaces the old one). */
6057
- tagIds: tagIds.optional()
6246
+ tagIds: tagIds.optional(),
6247
+ /** The day you plan to work on it; null takes the date off. */
6248
+ scheduledOn: DaySchema.nullable().optional()
6058
6249
  }).refine((patch) => Object.keys(patch).length > 0, "Send at least one field to change").meta({
6059
6250
  id: "TaskPatch",
6060
6251
  minProperties: 1
6061
6252
  });
6253
+ strictObject({
6254
+ /** The project's key (MON). */
6255
+ project: ProjectKeySchema,
6256
+ /** A column of that project; left out: the one named like the task's column now (any case), else the first. */
6257
+ columnId: IdSchema.optional(),
6258
+ /** Where it goes in the column (with `columnId`); its end when left out. */
6259
+ position: PositionSchema.optional()
6260
+ }).refine((body) => body.position === void 0 || body.columnId !== void 0, {
6261
+ message: "position needs a columnId",
6262
+ path: ["position"]
6263
+ }).meta({
6264
+ id: "TaskTransfer",
6265
+ dependentRequired: { position: ["columnId"] }
6266
+ });
6062
6267
  strictObject({
6063
6268
  id: IdSchema,
6064
6269
  /** Optional (the path has it); if sent, it must match. */
@@ -6069,6 +6274,7 @@ strictObject({
6069
6274
  position: PositionSchema,
6070
6275
  /** Tags deleted since are left out. */
6071
6276
  tagIds: tagIds.optional(),
6277
+ scheduledOn: DaySchema.nullable().optional(),
6072
6278
  /** Its links, as DELETE returned them (only these fields are read). */
6073
6279
  links: array(object({
6074
6280
  url: linkUrl,
@@ -6077,6 +6283,8 @@ strictObject({
6077
6283
  checkedAt: Timestamp.nullable().optional()
6078
6284
  })).max(LIMITS.linksPerTask).optional(),
6079
6285
  createdAt: datetime({ offset: true }).optional(),
6286
+ /** When it came into its column, so an undone delete doesn't start its archive clock again. */
6287
+ columnSince: Timestamp.optional(),
6080
6288
  ref: string().optional(),
6081
6289
  version: string().optional(),
6082
6290
  updatedAt: string().optional()
@@ -6094,11 +6302,107 @@ const TaskSchema = object({
6094
6302
  tagIds: array(IdSchema),
6095
6303
  /** What's attached to it (pull requests, issues, pages), oldest first. They aren't part of its version. */
6096
6304
  links: array(TaskLinkSchema),
6305
+ /** The day you plan to work on it (not a deadline), or null. */
6306
+ scheduledOn: DaySchema.nullable(),
6307
+ /** When it came into its column. In the Done column for longer than its project's archiveAfterDays, it's archived. */
6308
+ columnSince: Timestamp,
6097
6309
  version: Version,
6098
6310
  createdAt: Timestamp,
6099
6311
  updatedAt: Timestamp
6100
6312
  }).meta({ id: "Task" });
6101
6313
  /**
6314
+ * A column or tag in a task's history: as it was named then (it may have been renamed or deleted since).
6315
+ * The column has no OpenAPI name: it's nullable in places, and a named schema would be nullable everywhere.
6316
+ */
6317
+ const EventColumn = object({
6318
+ id: IdSchema,
6319
+ name: string(),
6320
+ color: ColorSchema
6321
+ });
6322
+ /** Where a task was, or went, when it changed project: the project, the task's reference there, its column. */
6323
+ const EventPlace = object({
6324
+ project: object({
6325
+ id: IdSchema,
6326
+ key: string(),
6327
+ name: string()
6328
+ }),
6329
+ ref: string(),
6330
+ column: EventColumn
6331
+ }).meta({ id: "EventPlace" });
6332
+ const EventTag = object({
6333
+ id: IdSchema,
6334
+ name: string(),
6335
+ color: ColorSchema
6336
+ }).meta({ id: "EventTag" });
6337
+ const EventLink = object({
6338
+ id: IdSchema,
6339
+ url: string(),
6340
+ kind: _enum(LINK_KINDS),
6341
+ title: string(),
6342
+ state: _enum(LINK_STATES).nullable()
6343
+ }).meta({ id: "EventLink" });
6344
+ const event = (kind, shape) => object({
6345
+ /** Newer events have larger ids. */
6346
+ id: string().regex(/^[1-9][0-9]*$/),
6347
+ kind: literal(kind),
6348
+ ...shape,
6349
+ /** What made the change: `web`, `cli` or `api` (another client); null for what happened before history began. */
6350
+ via: string().nullable(),
6351
+ createdAt: Timestamp,
6352
+ /** Later than `createdAt` when a burst of changes merged into this event (typing, toggling tags). */
6353
+ updatedAt: Timestamp
6354
+ });
6355
+ discriminatedUnion("kind", [
6356
+ event("created", {
6357
+ /** Null for tasks made before history began. */
6358
+ column: EventColumn.nullable(),
6359
+ title: string().nullable(),
6360
+ tags: array(EventTag),
6361
+ /** The day it was made for, if it was made with one. */
6362
+ scheduledOn: DaySchema.nullable()
6363
+ }),
6364
+ event("moved", {
6365
+ from: EventColumn,
6366
+ to: EventColumn
6367
+ }),
6368
+ event("renamed", {
6369
+ from: string(),
6370
+ to: string()
6371
+ }),
6372
+ event("edited", {
6373
+ from: number$1().int().nonnegative(),
6374
+ to: number$1().int().nonnegative()
6375
+ }),
6376
+ event("tagged", {
6377
+ added: array(EventTag),
6378
+ removed: array(EventTag)
6379
+ }),
6380
+ event("linked", { link: EventLink }),
6381
+ event("unlinked", { link: EventLink }),
6382
+ event("link_state", {
6383
+ link: EventLink,
6384
+ from: _enum(LINK_STATES).nullable(),
6385
+ to: _enum(LINK_STATES).nullable()
6386
+ }),
6387
+ event("deleted", {
6388
+ title: string(),
6389
+ column: EventColumn.nullable()
6390
+ }),
6391
+ event("restored", { column: EventColumn.nullable() }),
6392
+ event("scheduled", {
6393
+ from: DaySchema.nullable(),
6394
+ to: DaySchema.nullable()
6395
+ }),
6396
+ event("transferred", {
6397
+ from: EventPlace,
6398
+ to: EventPlace
6399
+ }),
6400
+ event("commented", { comment: object({
6401
+ id: IdSchema,
6402
+ excerpt: string()
6403
+ }).meta({ id: "EventComment" }) })
6404
+ ]).meta({ id: "TaskEvent" });
6405
+ /**
6102
6406
  * Every list takes `?limit=` and `?cursor=` and answers `{ <items>: [...], nextCursor }` (keyset
6103
6407
  * pagination; see docs/PLAN-API-CLI.md §4.1). `nextCursor` is null on the last page.
6104
6408
  */
@@ -6106,16 +6410,56 @@ const PAGE_LIMIT = {
6106
6410
  default: 100,
6107
6411
  max: 200
6108
6412
  };
6109
- strictObject({
6413
+ /** Strict, like every request schema: a typo such as `?colum=backlog` is a 400, not a silently wider list. */
6414
+ const PageQuerySchema = strictObject({
6110
6415
  limit: number().int().min(1).max(PAGE_LIMIT.max).default(PAGE_LIMIT.default).describe("Items per page"),
6111
6416
  cursor: string().min(1).max(1024).optional().describe("`nextCursor` from the previous page")
6112
6417
  });
6418
+ PageQuerySchema.extend({
6419
+ from: DaySchema.describe("The first day (the client's today, for Today)"),
6420
+ to: DaySchema.optional().describe("The last day (`from` when left out); at most 62 days after `from`"),
6421
+ overdue: _enum(["true", "false"]).optional().describe("Also the tasks scheduled before `from` that aren't done (not in their project's Done column)")
6422
+ });
6423
+ /** Where a task is, for a list across projects: its project and column, and whether it's done. */
6424
+ const TaskPlace = {
6425
+ project: object({
6426
+ key: ProjectKeySchema,
6427
+ name: string(),
6428
+ icon: string().nullable(),
6429
+ color: ColorSchema
6430
+ }),
6431
+ column: object({
6432
+ id: IdSchema,
6433
+ name: string(),
6434
+ color: ColorSchema
6435
+ }),
6436
+ /** In its project's Done column (the one named Done, else the last). */
6437
+ done: boolean()
6438
+ };
6439
+ TaskSchema.extend({
6440
+ ...TaskPlace,
6441
+ scheduledOn: DaySchema
6442
+ }).meta({ id: "ScheduledTask" });
6443
+ /** The longest search, and the most words in it. */
6444
+ const SEARCH_LIMITS = {
6445
+ length: 200,
6446
+ words: 8
6447
+ };
6448
+ 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.`) });
6449
+ TaskSchema.extend({
6450
+ ...TaskPlace,
6451
+ /** Done long enough ago that its board leaves it out (its project's archive setting). */
6452
+ archived: boolean()
6453
+ }).meta({ id: "FoundTask" });
6113
6454
  object({
6114
6455
  project: ProjectSchema,
6115
6456
  columns: array(ColumnSchema),
6116
6457
  /** The tags its tasks can have: the project's own and the shared ones, by name. */
6117
6458
  tags: array(TagSchema),
6459
+ /** Its tasks, except the archived ones (`GET …/tasks?archived=true` lists those). */
6118
6460
  tasks: array(TaskSchema),
6461
+ /** How many archived tasks it leaves out. */
6462
+ archived: number$1().int().nonnegative(),
6119
6463
  /** More tasks than the board returns at once (2,000): load the rest from the paginated task list. */
6120
6464
  truncated: boolean()
6121
6465
  }).meta({ id: "Board" });
@@ -6769,6 +7113,130 @@ async function* pages(fetchPage) {
6769
7113
  } while (cursor);
6770
7114
  }
6771
7115
  //#endregion
7116
+ //#region ../../packages/contract/src/history.ts
7117
+ const KIND_NAMES = {
7118
+ pr: "PR ",
7119
+ issue: "issue ",
7120
+ commit: "commit ",
7121
+ url: ""
7122
+ };
7123
+ /** How a link is named in a task's history: "PR #54", "issue #3", "commit a1b2c3d", "figma.com". */
7124
+ function eventLinkName(link) {
7125
+ const number = parseLink(link.url)?.number ?? null;
7126
+ return `${KIND_NAMES[link.kind]}${linkLabel({
7127
+ ...link,
7128
+ number
7129
+ })}`;
7130
+ }
7131
+ /** What a pull request's or issue's new state says it did. */
7132
+ function stateVerb(from, to) {
7133
+ if (to === "open") return from === "merged" || from === "closed" ? "reopened" : "opened";
7134
+ if (to === "draft") return "drafted";
7135
+ return to ?? "updated";
7136
+ }
7137
+ const signed = (n) => n > 0 ? `+${n}` : `−${-n}`;
7138
+ /**
7139
+ * A history event in words, for a line: a verb ("moved") and what it did ("To do → In progress"). The web
7140
+ * draws some of it richer (column dots, tag chips); the words are the same.
7141
+ */
7142
+ function describeEvent(event, now = today()) {
7143
+ const day = (d) => formatDay(d, now);
7144
+ switch (event.kind) {
7145
+ case "created": {
7146
+ const tags = event.tags.map((t) => `#${t.name}`);
7147
+ const when = event.scheduledOn && `for ${day(event.scheduledOn)}`;
7148
+ return {
7149
+ verb: "created",
7150
+ detail: [
7151
+ event.column && `in ${event.column.name}`,
7152
+ ...tags,
7153
+ when
7154
+ ].filter(Boolean).join(" ")
7155
+ };
7156
+ }
7157
+ case "scheduled":
7158
+ if (!event.to) return {
7159
+ verb: "unscheduled",
7160
+ detail: event.from ? `(was ${day(event.from)})` : ""
7161
+ };
7162
+ return {
7163
+ verb: "scheduled",
7164
+ detail: event.from ? `${day(event.from)} → ${day(event.to)}` : `for ${day(event.to)}`
7165
+ };
7166
+ case "moved": return {
7167
+ verb: "moved",
7168
+ detail: `${event.from.name} → ${event.to.name}`
7169
+ };
7170
+ case "transferred": return {
7171
+ verb: "moved",
7172
+ detail: `${event.from.ref} → ${event.to.ref} (${event.to.project.name}, ${event.to.column.name})`
7173
+ };
7174
+ case "renamed": return {
7175
+ verb: "renamed",
7176
+ detail: `${event.from} → ${event.to}`
7177
+ };
7178
+ case "edited": {
7179
+ if (event.from === 0) return {
7180
+ verb: "edited",
7181
+ detail: `description (new, ${event.to} chars)`
7182
+ };
7183
+ if (event.to === 0) return {
7184
+ verb: "edited",
7185
+ detail: "description (cleared)"
7186
+ };
7187
+ const delta = event.to - event.from;
7188
+ return {
7189
+ verb: "edited",
7190
+ detail: delta ? `description (${signed(delta)} chars)` : "description"
7191
+ };
7192
+ }
7193
+ case "tagged": return {
7194
+ verb: "tagged",
7195
+ detail: [...event.added.map((t) => `+${t.name}`), ...event.removed.map((t) => `−${t.name}`)].join(" ")
7196
+ };
7197
+ case "linked":
7198
+ case "unlinked": {
7199
+ const { link } = event;
7200
+ return {
7201
+ verb: event.kind,
7202
+ detail: [eventLinkName(link), link.title].filter(Boolean).join(" ")
7203
+ };
7204
+ }
7205
+ case "link_state": {
7206
+ const was = event.from ? ` (was ${event.from})` : "";
7207
+ return {
7208
+ verb: stateVerb(event.from, event.to),
7209
+ detail: `${eventLinkName(event.link)}${was}`
7210
+ };
7211
+ }
7212
+ case "deleted": return {
7213
+ verb: "deleted",
7214
+ detail: event.column ? `from ${event.column.name}` : ""
7215
+ };
7216
+ case "restored": return {
7217
+ verb: "restored",
7218
+ detail: event.column ? `to ${event.column.name}` : ""
7219
+ };
7220
+ case "commented": return {
7221
+ verb: "commented",
7222
+ detail: event.comment.excerpt
7223
+ };
7224
+ }
7225
+ }
7226
+ const MINUTE = 6e4;
7227
+ /** How long ago, in a few characters, for a history line: "now", "5m", "3h", "2d", "5mo", "2y". */
7228
+ function eventAge(iso, now = Date.now()) {
7229
+ const minutes = Math.floor((now - new Date(iso).getTime()) / MINUTE);
7230
+ if (minutes < 1) return "now";
7231
+ if (minutes < 60) return `${minutes}m`;
7232
+ const hours = Math.floor(minutes / 60);
7233
+ if (hours < 24) return `${hours}h`;
7234
+ const days = Math.floor(hours / 24);
7235
+ if (days < 60) return `${days}d`;
7236
+ if (days < 730) return `${Math.floor(days / 30)}mo`;
7237
+ return `${Math.floor(days / 365)}y`;
7238
+ }
7239
+ //#endregion
6772
7240
  //#region ../../packages/contract/src/repo.ts
6773
7241
  /**
6774
7242
  * A project's linked repository, in the one form the database stores: github.com/<owner>/<repo>,
@@ -6846,10 +7314,20 @@ function matchColumn(columns, query) {
6846
7314
  choices: [...columns]
6847
7315
  };
6848
7316
  }
7317
+ const DAY_MS = 864e5;
7318
+ /**
7319
+ * Whether a task is archived: in its project's Done column (`doneColumnId`: doneColumn()) for longer
7320
+ * than the project's `archiveAfterDays` (null: never). The API applies the same rule when it reads.
7321
+ */
7322
+ function isArchived(task, doneColumnId, archiveAfterDays, now = Date.now()) {
7323
+ if (archiveAfterDays === null || !doneColumnId || task.columnId !== doneColumnId) return false;
7324
+ return Date.parse(task.columnSince) < now - archiveAfterDays * DAY_MS;
7325
+ }
7326
+ strictObject({ email: email().max(254).meta({ example: "ada@example.com" }) }).meta({ id: "WaitlistJoin" });
6849
7327
  //#endregion
6850
7328
  //#region src/version.ts
6851
7329
  /** This CLI's version, from package.json (set at build time by tsdown, and by vitest in tests). */
6852
- const VERSION = "1.1.0";
7330
+ const VERSION = "1.3.0";
6853
7331
  /** Sent as X-Monoban-Client, and shown in Devices & tokens. */
6854
7332
  const CLIENT = `cli/${VERSION}`;
6855
7333
  //#endregion
@@ -10178,6 +10656,18 @@ function git(cwd, ...args) {
10178
10656
  }, (err, stdout) => resolve(err ? null : stdout.trim()));
10179
10657
  });
10180
10658
  }
10659
+ /** Runs git in `cwd` and says what went wrong when it fails (git's own message). */
10660
+ function gitOrWhy(cwd, ...args) {
10661
+ return new Promise((resolve) => {
10662
+ execFile("git", args, {
10663
+ cwd,
10664
+ timeout: 15e3
10665
+ }, (err, _stdout, stderr) => resolve(err ? {
10666
+ ok: false,
10667
+ why: stderr.trim() || err.message
10668
+ } : { ok: true }));
10669
+ });
10670
+ }
10181
10671
  function clone(cwd = process.cwd()) {
10182
10672
  return {
10183
10673
  project: async () => await git(cwd, "config", "--local", "--get", "monoban.project") || null,
@@ -10196,7 +10686,13 @@ function clone(cwd = process.cwd()) {
10196
10686
  const name = await git(cwd, "rev-parse", "--abbrev-ref", "HEAD");
10197
10687
  return name && name !== "HEAD" ? name : null;
10198
10688
  },
10199
- root: async () => await git(cwd, "rev-parse", "--show-toplevel") || cwd
10689
+ root: async () => await git(cwd, "rev-parse", "--show-toplevel") || cwd,
10690
+ inClone: async () => await git(cwd, "rev-parse", "--is-inside-work-tree") === "true",
10691
+ branches: async () => (await git(cwd, "branch", "--list", "--format=%(refname:short)") ?? "").split("\n").filter(Boolean),
10692
+ switchTo: async (name, create) => {
10693
+ const result = await gitOrWhy(cwd, "switch", ...create ? ["-c", name] : [name]);
10694
+ return result.ok ? null : result.why;
10695
+ }
10200
10696
  };
10201
10697
  }
10202
10698
  //#endregion
@@ -10744,10 +11240,16 @@ function taskRefOf(ref) {
10744
11240
  if (!parsed) throw new CliError(`"${ref}" isn't a task like MON-12.`, EXIT.usage);
10745
11241
  return parsed;
10746
11242
  }
10747
- /** A task by its reference, with its ETag version (a 404 exits 5). */
10748
- async function taskByRef(api, ref) {
11243
+ /**
11244
+ * A task by its reference, with its ETag version (a 404 exits 5). A task that moved to another project is
11245
+ * found by its old reference too (a branch named after it still works); `ctx` says what it's called now.
11246
+ */
11247
+ async function taskByRef(api, ref, ctx) {
10749
11248
  const { key, number } = taskRefOf(ref);
10750
- return unwrap(api.GET("/v1/tasks/{ref}", { params: { path: { ref: `${key}-${number}` } } }));
11249
+ const asked = `${key}-${number}`;
11250
+ const task = await unwrap(api.GET("/v1/tasks/{ref}", { params: { path: { ref: asked } } }));
11251
+ if (task.ref !== asked) ctx?.err(`${asked} is ${task.ref} now: it moved to another project.`);
11252
+ return task;
10751
11253
  }
10752
11254
  /** The column `query` names (see matchColumn), or an error that lists the columns to choose from. */
10753
11255
  function findColumn(columns, query) {
@@ -10764,15 +11266,232 @@ function changedElsewhere(err, ref) {
10764
11266
  if (err instanceof ApiProblem && err.status === 412) throw new CliError(`${ref} changed elsewhere in the meantime. Run \`monoban show ${ref}\` and try again.`);
10765
11267
  throw err;
10766
11268
  }
10767
- /** A task as the CLI prints it in JSON: the API's fields plus its column's name and its tags' names. */
11269
+ /**
11270
+ * A task as the CLI prints it in JSON: the API's fields plus its column's name, whether that's the Done
11271
+ * column (doneColumn: named Done, else the last), and its tags' names.
11272
+ */
10768
11273
  const taskJson = (task, columns, tags) => ({
10769
11274
  ...task,
10770
11275
  column: columns.find((c) => c.id === task.columnId)?.name ?? null,
11276
+ done: task.columnId === doneColumn(columns)?.id,
10771
11277
  tags: tagsOfTask(task, tags).map((t) => t.name)
10772
11278
  });
10773
11279
  /** Where the web shows a project's board, or one task on it. */
10774
11280
  const boardUrl = (ctx, key, number) => `${ctx.webUrl}/p/${key}${number === void 0 ? "" : `?task=${number}`}`;
10775
11281
  //#endregion
11282
+ //#region src/commands/comments.ts
11283
+ /** `monoban comment MON-12 TEXT…`: a comment on the task (`-` reads it from stdin, Markdown and all). */
11284
+ async function comment(ctx, ref, words, options) {
11285
+ const body = words.length === 1 && words[0] === "-" ? (await ctx.readStdin()).replace(/\n$/, "") : words.join(" ");
11286
+ if (!body.trim()) throw new CliError("Nothing to say: give the text, or - to read it from stdin.", EXIT.usage);
11287
+ const api = apis(ctx).signedIn;
11288
+ const task = await taskByRef(api, ref, ctx);
11289
+ const { key, number } = taskRefOf(task.ref);
11290
+ const added = await unwrap(api.POST("/v1/projects/{key}/tasks/{number}/comments", {
11291
+ params: { path: {
11292
+ key,
11293
+ number
11294
+ } },
11295
+ body: { body }
11296
+ }));
11297
+ if (options.json) return ctx.out(JSON.stringify(added, null, 2));
11298
+ ctx.out(`Commented on ${task.ref}.`);
11299
+ }
11300
+ /** `monoban comments MON-12`: the latest comments (`-n`, 20 unless you say), oldest of them first. */
11301
+ async function comments(ctx, ref, options) {
11302
+ const count = options.number === void 0 ? 20 : Number(options.number);
11303
+ if (!Number.isInteger(count) || count < 1) throw new CliError("-n is how many comments to show: 1 or more.", EXIT.usage);
11304
+ const api = apis(ctx).signedIn;
11305
+ const task = await taskByRef(api, ref, ctx);
11306
+ const all = await commentsOf(api, task.ref);
11307
+ const shown = all.slice(-count);
11308
+ if (options.json) return ctx.out(JSON.stringify(shown, null, 2));
11309
+ if (!shown.length) {
11310
+ ctx.err(`${task.ref} has no comments yet. Add one with \`monoban comment ${task.ref} …\`.`);
11311
+ return;
11312
+ }
11313
+ for (const line of commentLines(shown, ctx.style)) ctx.out(line);
11314
+ if (all.length > shown.length) ctx.err(`Older comments too: -n ${all.length} shows all ${all.length}.`);
11315
+ }
11316
+ /** All of a task's comments, oldest first, a page at a time: a task has a few hundred at most. */
11317
+ async function commentsOf(api, ref) {
11318
+ const { key, number } = taskRefOf(ref);
11319
+ const all = [];
11320
+ let cursor;
11321
+ do {
11322
+ const page = await unwrap(api.GET("/v1/projects/{key}/tasks/{number}/comments", { params: {
11323
+ path: {
11324
+ key,
11325
+ number
11326
+ },
11327
+ query: {
11328
+ limit: PAGE_LIMIT.max,
11329
+ cursor
11330
+ }
11331
+ } }));
11332
+ all.push(...page.comments);
11333
+ cursor = page.nextCursor ?? void 0;
11334
+ } while (cursor);
11335
+ return all;
11336
+ }
11337
+ /** Each comment under a "── 2h · cli" rule, a blank line between them. */
11338
+ function commentLines(comments, { dim }, now = Date.now()) {
11339
+ return comments.flatMap((m, i) => [
11340
+ ...i ? [""] : [],
11341
+ dim(`── ${eventAge(m.createdAt, now)}${m.via ? ` · ${m.via}` : ""}`),
11342
+ ...m.body.replace(/\n+$/, "").split("\n")
11343
+ ]);
11344
+ }
11345
+ //#endregion
11346
+ //#region src/commands/history.ts
11347
+ /** The newest `count` events of a task (a page at a time), and whether it has older ones. */
11348
+ async function historyOf(api, ref, count) {
11349
+ const { key, number } = taskRefOf(ref);
11350
+ const events = [];
11351
+ let cursor;
11352
+ do {
11353
+ const limit = Math.min(count - events.length, PAGE_LIMIT.max);
11354
+ const page = await unwrap(api.GET("/v1/projects/{key}/tasks/{number}/history", { params: {
11355
+ path: {
11356
+ key,
11357
+ number
11358
+ },
11359
+ query: {
11360
+ limit,
11361
+ cursor
11362
+ }
11363
+ } }));
11364
+ events.push(...page.events);
11365
+ cursor = page.nextCursor ?? void 0;
11366
+ } while (cursor && events.length < count);
11367
+ return {
11368
+ events,
11369
+ more: cursor !== void 0
11370
+ };
11371
+ }
11372
+ /** One line per event, aligned: "2h moved To do → In progress cli". */
11373
+ function historyLines(events, { dim }, now = Date.now()) {
11374
+ const rows = events.map((e) => ({
11375
+ age: eventAge(e.updatedAt, now),
11376
+ ...describeEvent(e),
11377
+ via: e.via ?? ""
11378
+ }));
11379
+ const ageWidth = Math.max(0, ...rows.map((r) => r.age.length));
11380
+ const verbWidth = Math.max(0, ...rows.map((r) => r.verb.length));
11381
+ return rows.map((r) => {
11382
+ const via = r.via ? ` ${dim(r.via)}` : "";
11383
+ return `${dim(r.age.padStart(ageWidth))} ${r.verb.padEnd(verbWidth)} ${oneLine(r.detail)}${via}`.trimEnd();
11384
+ });
11385
+ }
11386
+ /** `monoban log MON-12`: what happened to a task, newest first (`-n` events, 20 unless you say). */
11387
+ async function log(ctx, ref, options) {
11388
+ const count = options.number === void 0 ? 20 : Number(options.number);
11389
+ if (!Number.isInteger(count) || count < 1) throw new CliError("-n is how many events to show: 1 or more.", EXIT.usage);
11390
+ const api = apis(ctx).signedIn;
11391
+ const { events, more } = await historyOf(api, ref, count);
11392
+ if (options.json) return ctx.out(JSON.stringify(events, null, 2));
11393
+ for (const line of historyLines(events, ctx.style)) ctx.out(line);
11394
+ if (more) ctx.err(`Older events too: -n ${count * 5} shows more.`);
11395
+ }
11396
+ //#endregion
11397
+ //#region src/commands/schedule.ts
11398
+ /** A day typed on the command line ("tomorrow", "fri", "2026-10-12"), or a usage error that shows how. */
11399
+ function dayArgument(input, now = today()) {
11400
+ const day = parseDay(input, now);
11401
+ 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);
11402
+ return day;
11403
+ }
11404
+ /**
11405
+ * `monoban today [DAY]`: the tasks planned for today (or DAY, or 7 days with --week) in every project, done
11406
+ * ones ticked. From today, the overdue ones come first: planned before and not done.
11407
+ */
11408
+ async function todayView(ctx, dayInput, options) {
11409
+ const now = today();
11410
+ const from = dayInput ? dayArgument(dayInput, now) : now;
11411
+ const to = options.week ? addDays(from, 6) : from;
11412
+ const api = apis(ctx).signedIn;
11413
+ const tasks = [];
11414
+ const query = {
11415
+ from,
11416
+ to,
11417
+ ...from === now && { overdue: "true" }
11418
+ };
11419
+ for await (const task of pages((cursor) => unwrap(api.GET("/v1/schedule", { params: { query: {
11420
+ ...query,
11421
+ cursor
11422
+ } } })).then((page) => ({
11423
+ items: page.tasks,
11424
+ nextCursor: page.nextCursor
11425
+ })))) tasks.push(task);
11426
+ if (options.json) return ctx.out(JSON.stringify(tasks, null, 2));
11427
+ const { bold, dim, color } = ctx.style;
11428
+ const late = tasks.filter((t) => t.scheduledOn < from);
11429
+ const planned = tasks.filter((t) => t.scheduledOn >= from);
11430
+ const name = options.week ? `Next 7 days from ${longDay(from, now)}` : headingOf(from, now);
11431
+ const done = planned.filter((t) => t.done).length;
11432
+ ctx.out(`${bold(name)} ${dim(planned.length ? `${done} of ${planned.length} done` : "nothing planned")}`);
11433
+ if (tasks.length === 0) {
11434
+ ctx.err(`Plan a task for it: monoban schedule MON-12 ${dayInput ?? "today"}`);
11435
+ return;
11436
+ }
11437
+ const refWidth = Math.max(...tasks.map((t) => t.ref.length));
11438
+ const columnWidth = Math.max(...tasks.map((t) => [...t.column.name].length));
11439
+ const line = (t, extra = "") => {
11440
+ const mark = t.done ? color("green", "✓") : " ";
11441
+ const column = `${t.column.name}${" ".repeat(columnWidth - [...t.column.name].length)}`;
11442
+ const title = t.done ? dim(oneLine(t.title)) : oneLine(t.title);
11443
+ return `${mark} ${t.ref.padEnd(refWidth)} ${dim(column)} ${title}${extra}`;
11444
+ };
11445
+ if (late.length) {
11446
+ ctx.out("");
11447
+ ctx.out(color("amber", `Overdue · ${late.length}`));
11448
+ for (const t of late) ctx.out(line(t, ` ${color("amber", `${daysBetween(t.scheduledOn, now)}d late`)}`));
11449
+ }
11450
+ for (let day = from; day <= to; day = addDays(day, 1)) {
11451
+ const of = planned.filter((t) => t.scheduledOn === day);
11452
+ if (options.week ? of.length === 0 : planned.length === 0) continue;
11453
+ if (options.week || late.length) {
11454
+ ctx.out("");
11455
+ ctx.out(bold(options.week ? headingOf(day, now) : name));
11456
+ }
11457
+ for (const t of of) ctx.out(line(t));
11458
+ }
11459
+ }
11460
+ /** "Today · Thu Oct 2", "Tomorrow · Fri Oct 3", or just "Mon Oct 12". */
11461
+ function headingOf(day, now) {
11462
+ const near = formatDay(day, now);
11463
+ const long = longDay(day, now);
11464
+ return [
11465
+ "today",
11466
+ "tomorrow",
11467
+ "yesterday"
11468
+ ].includes(near) ? `${near[0]?.toUpperCase()}${near.slice(1)} · ${long}` : long;
11469
+ }
11470
+ /** `monoban schedule MON-12 fri`: plans a task for a day; --clear takes its date off. */
11471
+ async function schedule(ctx, ref, dayInput, options) {
11472
+ 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);
11473
+ const now = today();
11474
+ const day = dayInput === void 0 ? null : dayArgument(dayInput, now);
11475
+ const api = apis(ctx).signedIn;
11476
+ const task = await taskByRef(api, ref, ctx);
11477
+ const { key, number } = taskRefOf(task.ref);
11478
+ const saved = task.scheduledOn === day ? task : await unwrap(api.PATCH("/v1/projects/{key}/tasks/{number}", {
11479
+ params: {
11480
+ path: {
11481
+ key,
11482
+ number
11483
+ },
11484
+ header: ifMatch(task.version)
11485
+ },
11486
+ body: { scheduledOn: day }
11487
+ })).catch((err) => changedElsewhere(err, task.ref));
11488
+ if (options.json) {
11489
+ const [columns, tags] = await Promise.all([columnsOf(api, key), saved.tagIds.length ? tagsOf(api, key) : []]);
11490
+ return ctx.out(JSON.stringify(taskJson(saved, columns, tags), null, 2));
11491
+ }
11492
+ ctx.out(day ? `${saved.ref} is planned for ${longDay(day, now)} (${formatDay(day, now)}).` : `${saved.ref} has no date now.`);
11493
+ }
11494
+ //#endregion
10776
11495
  //#region src/commands/board.ts
10777
11496
  const printJson$1 = (ctx, value) => ctx.out(JSON.stringify(value, null, 2));
10778
11497
  /** `monoban projects`: your projects, with their keys and repositories; * marks this folder's. */
@@ -10800,12 +11519,15 @@ async function projects(ctx, options) {
10800
11519
  }
10801
11520
  }
10802
11521
  const tasks = (p) => `${p.taskCount} ${p.taskCount === 1 ? "task" : "tasks"}`;
10803
- /** `monoban list [COLUMN…]`: the board, by column (every column, or the ones named); `--tag` keeps a tag's tasks. */
11522
+ /**
11523
+ * `monoban list [COLUMN…]`: the board, by column (every column, or the ones named); `--tag` keeps a tag's
11524
+ * tasks. `--archived`: the archived ones instead (done a while ago, off the board).
11525
+ */
10804
11526
  async function list(ctx, columnQueries, options) {
10805
11527
  const api = apis(ctx).signedIn;
10806
11528
  const key = await resolveProject(ctx, api, options.project);
10807
11529
  const board = await unwrap(api.GET("/v1/projects/{key}/board", { params: { path: { key } } }));
10808
- let tasks = board.truncated ? await allTasks(api, key) : board.tasks;
11530
+ let tasks = options.archived ? await allTasks(api, key, true) : board.truncated ? await allTasks(api, key) : board.tasks;
10809
11531
  if (options.tag !== void 0) {
10810
11532
  const tag = findTag(board.tags, options.tag);
10811
11533
  if (!tag) {
@@ -10814,19 +11536,23 @@ async function list(ctx, columnQueries, options) {
10814
11536
  }
10815
11537
  tasks = tasks.filter((t) => t.tagIds.includes(tag.id));
10816
11538
  }
10817
- const groups = (columnQueries.length ? [...new Set(columnQueries.map((q) => findColumn(board.columns, q)))] : board.columns).map((column) => ({
11539
+ 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) => ({
10818
11540
  column,
10819
11541
  tasks: tasks.filter((t) => t.columnId === column.id)
10820
11542
  }));
10821
11543
  if (options.json) return printJson$1(ctx, groups.flatMap((g) => g.tasks.map((t) => taskJson(t, board.columns, board.tags))));
10822
11544
  const { bold, dim } = ctx.style;
10823
11545
  const repo = board.project.repo ? ` · ${board.project.repo}` : "";
10824
- ctx.out(`${bold(board.project.name)} ${dim(`(${board.project.key})${repo}`)}`);
11546
+ ctx.out(`${bold(board.project.name)} ${dim(`(${board.project.key})${repo}`)}${options.archived ? " archived" : ""}`);
11547
+ 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"}.`);
10825
11548
  const rows = groups.flatMap((g) => g.tasks);
10826
11549
  const refWidth = Math.max(0, ...rows.map((t) => t.ref.length));
11550
+ const now = today();
11551
+ const done = doneColumn(board.columns)?.id;
10827
11552
  const meta = (t) => {
10828
11553
  const list = checklist(t.description);
10829
- return `${list ? `[${list.done}/${list.all}] ` : ""}${age(t.updatedAt).padStart(5)}`;
11554
+ const late = t.scheduledOn && t.columnId !== done && t.scheduledOn < now;
11555
+ return `${t.scheduledOn ? `@${formatDay(t.scheduledOn, now)}${late ? "!" : ""} ` : ""}${list ? `[${list.done}/${list.all}] ` : ""}${age(t.updatedAt).padStart(5)}`;
10830
11556
  };
10831
11557
  const metaWidth = Math.max(0, ...rows.map((t) => meta(t).length));
10832
11558
  const cell = (t, width) => titleCell(oneLine(t.title), tagsOfTask(t, board.tags), width, ctx.style);
@@ -10840,6 +11566,7 @@ async function list(ctx, columnQueries, options) {
10840
11566
  const pad = " ".repeat(Math.max(0, titleWidth - visibleLength(title)));
10841
11567
  ctx.out(` ${dim(t.ref.padEnd(refWidth))} ${title}${pad} ${dim(meta(t).padStart(metaWidth))}`.trimEnd());
10842
11568
  }
11569
+ if (!options.archived && board.archived > 0 && column.id === done && options.tag === void 0) ctx.out(dim(` + ${board.archived} archived (monoban list --archived)`));
10843
11570
  }
10844
11571
  }
10845
11572
  /**
@@ -10860,11 +11587,16 @@ function titleCell(title, tags, width, style) {
10860
11587
  }
10861
11588
  return truncate(title, width);
10862
11589
  }
10863
- async function allTasks(api, key) {
11590
+ /** A project's tasks, page by page: the ones on the board, or the archived ones. */
11591
+ async function allTasks(api, key, archived = false) {
10864
11592
  const all = [];
11593
+ const query = (cursor) => ({
11594
+ cursor,
11595
+ ...archived && { archived: "true" }
11596
+ });
10865
11597
  for await (const t of pages((cursor) => unwrap(api.GET("/v1/projects/{key}/tasks", { params: {
10866
11598
  path: { key },
10867
- query: { cursor }
11599
+ query: query(cursor)
10868
11600
  } })).then((page) => ({
10869
11601
  items: page.tasks,
10870
11602
  nextCursor: page.nextCursor
@@ -10875,18 +11607,29 @@ const ago = (iso) => {
10875
11607
  const a = age(iso);
10876
11608
  return a === "today" ? a : `${a} ago`;
10877
11609
  };
10878
- /** `monoban show MON-12`: a task in full. */
11610
+ /** How many history events and comments `show` ends with. */
11611
+ const SHOW_HISTORY = 3;
11612
+ const SHOW_COMMENTS = 2;
11613
+ /** `monoban show MON-12`: a task in full, and what happened to it last. */
10879
11614
  async function show(ctx, ref, options) {
10880
11615
  const api = apis(ctx).signedIn;
10881
- const task = await taskByRef(api, ref);
11616
+ const task = await taskByRef(api, ref, ctx);
10882
11617
  const key = taskRefOf(task.ref).key;
10883
- const [columns, tags] = await Promise.all([columnsOf(api, key), tagsFor(api, key, task)]);
11618
+ const [columns, tags, history, comments] = await Promise.all([
11619
+ columnsOf(api, key),
11620
+ tagsFor(api, key, task),
11621
+ options.json ? null : historyOf(api, task.ref, SHOW_HISTORY).catch(() => null),
11622
+ options.json ? null : commentsOf(api, task.ref).catch(() => null)
11623
+ ]);
10884
11624
  if (options.json) return printJson$1(ctx, taskJson(task, columns, tags));
10885
11625
  const { bold, dim } = ctx.style;
10886
- const column = columns.find((c) => c.id === task.columnId)?.name ?? "?";
11626
+ const doneId = doneColumn(columns)?.id;
11627
+ const archived = task.columnId === doneId && isArchived(task, doneId, (await unwrap(api.GET("/v1/projects/{key}", { params: { path: { key } } }))).project.archiveAfterDays);
11628
+ const column = `${columns.find((c) => c.id === task.columnId)?.name ?? "?"}${archived ? " · archived" : ""}`;
10887
11629
  const list = checklist(task.description);
10888
11630
  ctx.out(`${bold(task.ref)} ${bold(task.title)}`);
10889
- ctx.out(dim(`${column} · created ${ago(task.createdAt)} · updated ${ago(task.updatedAt)}`));
11631
+ const when = task.scheduledOn ? ` · ${planned(task, columns)}` : "";
11632
+ ctx.out(dim(`${column}${when} · created ${ago(task.createdAt)} · updated ${ago(task.updatedAt)}`));
10890
11633
  const own = tagsOfTask(task, tags);
10891
11634
  if (own.length) ctx.out(tagWords(own, ctx.style));
10892
11635
  if (list) ctx.out(dim(`Checklist ${list.done}/${list.all}`));
@@ -10901,6 +11644,25 @@ async function show(ctx, ref, options) {
10901
11644
  ctx.out("");
10902
11645
  ctx.out(task.description.trimEnd());
10903
11646
  }
11647
+ if (comments?.length) {
11648
+ const more = comments.length > SHOW_COMMENTS;
11649
+ ctx.out("");
11650
+ ctx.out(dim(more ? `Comments (all ${comments.length}: monoban comments ${task.ref})` : "Comments"));
11651
+ for (const line of commentLines(comments.slice(-2), ctx.style)) ctx.out(line && ` ${line}`);
11652
+ }
11653
+ if (history?.events.length) {
11654
+ ctx.out("");
11655
+ ctx.out(dim(history.more ? `History (all of it: monoban log ${task.ref})` : "History"));
11656
+ for (const line of historyLines(history.events, ctx.style)) ctx.out(` ${line}`);
11657
+ }
11658
+ }
11659
+ /** When a task is planned for: "for tomorrow", or "for Oct 1, 2d late" past it and not done. */
11660
+ function planned(task, columns) {
11661
+ if (!task.scheduledOn) return "";
11662
+ const now = today();
11663
+ const late = daysBetween(task.scheduledOn, now);
11664
+ const done = doneColumn(columns)?.id === task.columnId;
11665
+ return `for ${formatDay(task.scheduledOn, now)}${late > 0 && !done ? `, ${late}d late` : ""}`;
10904
11666
  }
10905
11667
  /** The project's tags, when `task` has any to name (else none: one request fewer). */
10906
11668
  const tagsFor = async (api, key, task) => task.tagIds.length ? tagsOf(api, key) : [];
@@ -10909,6 +11671,7 @@ async function add(ctx, title, options) {
10909
11671
  if (options.description !== void 0 && options.edit) throw new CliError("Use -d or -e, not both.", EXIT.usage);
10910
11672
  const names = options.tag ?? [];
10911
11673
  assertTagCount(new Set(names).size);
11674
+ const scheduledOn = options.date === void 0 ? void 0 : dayArgument(options.date);
10912
11675
  const api = apis(ctx).signedIn;
10913
11676
  const key = await resolveProject(ctx, api, options.project);
10914
11677
  const [columns, tags] = await Promise.all([columnsOf(api, key), names.length ? tagsOf(api, key) : []]);
@@ -10925,17 +11688,19 @@ async function add(ctx, title, options) {
10925
11688
  title,
10926
11689
  ...description ? { description } : {},
10927
11690
  ...column ? { columnId: column.id } : {},
10928
- ...tagIds.length ? { tagIds } : {}
11691
+ ...tagIds.length ? { tagIds } : {},
11692
+ ...scheduledOn ? { scheduledOn } : {}
10929
11693
  }
10930
11694
  }));
10931
11695
  if (options.json) return printJson$1(ctx, taskJson(task, columns, tags));
10932
11696
  const tagged = tagIds.length ? ` ${tagWords(tagsOfTask(task, tags), ctx.style)}` : "";
10933
- ctx.out(`Added ${task.ref} to ${column?.name ?? "the board"}: ${task.title}${tagged}`);
11697
+ const when = scheduledOn ? `, for ${formatDay(scheduledOn, today())}` : "";
11698
+ ctx.out(`Added ${task.ref} to ${column?.name ?? "the board"}${when}: ${task.title}${tagged}`);
10934
11699
  }
10935
11700
  /** `monoban tag MON-12 bug ui`: puts tags on a task (a name that isn't a tag yet becomes one). */
10936
11701
  async function tag(ctx, ref, names, options) {
10937
11702
  const api = apis(ctx).signedIn;
10938
- const task = await taskByRef(api, ref);
11703
+ const task = await taskByRef(api, ref, ctx);
10939
11704
  const key = taskRefOf(task.ref).key;
10940
11705
  const tags = await tagsOf(api, key);
10941
11706
  const adding = (await resolveTags(ctx, api, key, names, tags)).filter((t) => !task.tagIds.includes(t.id));
@@ -10953,7 +11718,7 @@ async function tag(ctx, ref, names, options) {
10953
11718
  /** `monoban untag MON-12 bug`: takes tags off a task (the tags themselves stay). */
10954
11719
  async function untag(ctx, ref, names, options) {
10955
11720
  const api = apis(ctx).signedIn;
10956
- const task = await taskByRef(api, ref);
11721
+ const task = await taskByRef(api, ref, ctx);
10957
11722
  const key = taskRefOf(task.ref).key;
10958
11723
  const tags = await tagsOf(api, key);
10959
11724
  const own = tagsOfTask(task, tags);
@@ -11001,17 +11766,49 @@ async function tags(ctx, options) {
11001
11766
  ctx.out(`${name} ${dim(where)} ${dim(count)}`);
11002
11767
  }
11003
11768
  }
11004
- /** `monoban move MON-12 done`: to the end of another column. */
11769
+ /**
11770
+ * `monoban move MON-12 in-progress`: to the end of another column. With `--to WEB`, to another project
11771
+ * (to the column you say, else the one named like its column, else the first), where it gets a new number.
11772
+ */
11005
11773
  async function move(ctx, ref, columnQuery, options) {
11006
11774
  const api = apis(ctx).signedIn;
11007
- const task = await taskByRef(api, ref);
11008
- const columns = await columnsOf(api, taskRefOf(task.ref).key);
11775
+ const task = await taskByRef(api, ref, ctx);
11776
+ const { key } = taskRefOf(task.ref);
11777
+ const to = options.to?.trim().toUpperCase();
11778
+ if (to && to !== key) return transfer(ctx, api, task, to, columnQuery, options);
11779
+ if (columnQuery === void 0) {
11780
+ if (to) throw new CliError(`${task.ref} is in ${to} already. Say a column to move it to.`, EXIT.usage);
11781
+ throw new CliError("Say where: monoban move MON-12 in-progress (or --to WEB, another project).", EXIT.usage);
11782
+ }
11783
+ const columns = await columnsOf(api, key);
11009
11784
  await moveTo(ctx, api, task, columns, findColumn(columns, columnQuery), options);
11010
11785
  }
11786
+ /** Moves a task to project `to` (its column `columnQuery`, if given). */
11787
+ async function transfer(ctx, api, task, to, columnQuery, options) {
11788
+ const columns = await columnsOf(api, to);
11789
+ const target = columnQuery === void 0 ? void 0 : findColumn(columns, columnQuery);
11790
+ const { key, number } = taskRefOf(task.ref);
11791
+ const moved = await unwrap(api.POST("/v1/projects/{key}/tasks/{number}/transfer", {
11792
+ params: {
11793
+ path: {
11794
+ key,
11795
+ number
11796
+ },
11797
+ header: ifMatch(task.version)
11798
+ },
11799
+ body: {
11800
+ project: to,
11801
+ ...target && { columnId: target.id }
11802
+ }
11803
+ })).catch((err) => changedElsewhere(err, task.ref));
11804
+ if (options.json) return printJson$1(ctx, taskJson(moved, columns, await tagsFor(api, to, moved)));
11805
+ const column = columns.find((c) => c.id === moved.columnId)?.name ?? "its first column";
11806
+ ctx.out(`Moved ${task.ref} to ${to}: it's ${moved.ref} now, in ${column}.`);
11807
+ }
11011
11808
  /** `monoban done MON-12`: to the column called Done, or else the last one. */
11012
11809
  async function done(ctx, ref, options) {
11013
11810
  const api = apis(ctx).signedIn;
11014
- const task = await taskByRef(api, ref);
11811
+ const task = await taskByRef(api, ref, ctx);
11015
11812
  const columns = await columnsOf(api, taskRefOf(task.ref).key);
11016
11813
  const target = columns.find((c) => c.name.trim().toLowerCase() === "done") ?? columns.at(-1);
11017
11814
  if (!target) throw new CliError(`${task.ref}'s project has no columns.`);
@@ -11045,7 +11842,7 @@ async function moveTo(ctx, api, task, columns, target, options) {
11045
11842
  */
11046
11843
  async function edit(ctx, ref, options) {
11047
11844
  const api = apis(ctx).signedIn;
11048
- const task = await taskByRef(api, ref);
11845
+ const task = await taskByRef(api, ref, ctx);
11049
11846
  const direct = options.title !== void 0 || options.description !== void 0;
11050
11847
  let text = "";
11051
11848
  let title;
@@ -11096,7 +11893,7 @@ async function edit(ctx, ref, options) {
11096
11893
  /** `monoban rm MON-12`: asks first, unless -y. */
11097
11894
  async function rm$1(ctx, ref, options) {
11098
11895
  const api = apis(ctx).signedIn;
11099
- const task = await taskByRef(api, ref);
11896
+ const task = await taskByRef(api, ref, ctx);
11100
11897
  if (!options.yes) {
11101
11898
  if (!ctx.tty.in) throw new CliError(`To delete ${task.ref} without a terminal to ask on, pass -y.`, EXIT.usage);
11102
11899
  if (!await ctx.confirm(`Delete ${task.ref} "${oneLine(task.title)}"?`)) {
@@ -11237,7 +12034,7 @@ async function attach(ctx, args, options) {
11237
12034
  if (!(err instanceof NoGh)) ctx.err(`Couldn't read it with gh (${err.message}); attaching it as it is.`);
11238
12035
  }
11239
12036
  const api = apis(ctx).signedIn;
11240
- const task = await taskByRef(api, ref);
12037
+ const task = await taskByRef(api, ref, ctx);
11241
12038
  const had = task.links.some((l) => l.url === parsed.url);
11242
12039
  const { key, number } = taskRefOf(task.ref);
11243
12040
  const title = options.title ?? item?.title;
@@ -11258,7 +12055,7 @@ async function attach(ctx, args, options) {
11258
12055
  /** `monoban detach MON-12 #54`: takes a link off (by its number, its URL, or where it points). */
11259
12056
  async function detach(ctx, ref, which, options) {
11260
12057
  const api = apis(ctx).signedIn;
11261
- const task = await taskByRef(api, ref);
12058
+ const task = await taskByRef(api, ref, ctx);
11262
12059
  const wanted = which.trim();
11263
12060
  const number = /^#?([1-9][0-9]*)$/.exec(wanted)?.[1];
11264
12061
  const url = parseLink(wanted)?.url;
@@ -11340,6 +12137,47 @@ async function notesEdit(ctx, options) {
11340
12137
  ctx.out(`Updated the notes of ${key}.`);
11341
12138
  }
11342
12139
  //#endregion
12140
+ //#region src/commands/search.ts
12141
+ /**
12142
+ * `monoban search login page`: the tasks with all of these words (in the title or description, as a tag, or
12143
+ * as the reference), in every project, the last changed first, archived ones too. `-n` of them, 30 unless
12144
+ * you say.
12145
+ */
12146
+ async function search(ctx, words, options) {
12147
+ const q = words.join(" ").trim();
12148
+ if (!q) throw new CliError("Say what to look for: monoban search login page", EXIT.usage);
12149
+ const count = options.number === void 0 ? 30 : Number(options.number);
12150
+ if (!Number.isInteger(count) || count < 1) throw new CliError("-n is how many tasks to show: 1 or more.", EXIT.usage);
12151
+ const api = apis(ctx).signedIn;
12152
+ const tasks = [];
12153
+ let cursor;
12154
+ do {
12155
+ const limit = Math.min(count - tasks.length, PAGE_LIMIT.max);
12156
+ const page = await unwrap(api.GET("/v1/search", { params: { query: {
12157
+ q,
12158
+ limit,
12159
+ cursor
12160
+ } } }));
12161
+ tasks.push(...page.tasks);
12162
+ cursor = page.nextCursor ?? void 0;
12163
+ } while (cursor && tasks.length < count);
12164
+ if (options.json) return ctx.out(JSON.stringify(tasks, null, 2));
12165
+ if (tasks.length === 0) {
12166
+ ctx.err(`No task has "${q}".`);
12167
+ return;
12168
+ }
12169
+ const { dim, color } = ctx.style;
12170
+ const refWidth = Math.max(...tasks.map((t) => t.ref.length));
12171
+ const columnWidth = Math.max(...tasks.map((t) => [...t.column.name].length));
12172
+ for (const t of tasks) {
12173
+ const mark = t.done ? color("green", "✓") : " ";
12174
+ const column = `${t.column.name}${" ".repeat(columnWidth - [...t.column.name].length)}`;
12175
+ const title = t.done ? dim(oneLine(t.title)) : oneLine(t.title);
12176
+ ctx.out(`${mark} ${t.ref.padEnd(refWidth)} ${dim(column)} ${title}${t.archived ? ` ${dim("archived")}` : ""}`);
12177
+ }
12178
+ if (cursor) ctx.err(`More tasks have it: -n ${count * 5} shows more.`);
12179
+ }
12180
+ //#endregion
11343
12181
  //#region src/skill.ts
11344
12182
  /** The coding agents `monoban setup` teaches monoban to. */
11345
12183
  const AGENTS = ["claude", "codex"];
@@ -11360,6 +12198,10 @@ const READ_ONLY = [
11360
12198
  "monoban list",
11361
12199
  "monoban ls",
11362
12200
  "monoban show",
12201
+ "monoban log",
12202
+ "monoban comments",
12203
+ "monoban today",
12204
+ "monoban search",
11363
12205
  "monoban tags",
11364
12206
  "monoban notes show"
11365
12207
  ];
@@ -11391,8 +12233,10 @@ plans into tasks on the board and to keep those tasks current while you work.
11391
12233
  that project. Otherwise \`monoban projects\` lists the keys; pass \`-p KEY\` to project commands. If it's
11392
12234
  unclear which project the work belongs to, ask. Suggest \`monoban link KEY\` to the user rather than
11393
12235
  running it (it changes the project).
11394
- 3. Read with \`--json\`: \`monoban list --json\` (every task, with its \`column\` and \`tags\`),
12236
+ 3. Read with \`--json\`: \`monoban list --json\` (every task, with its \`column\`, \`done\` and \`tags\`),
11395
12237
  \`monoban show MON-12 --json\`, \`monoban tags --json\`, and \`monoban notes show\` for the notes.
12238
+ \`monoban log MON-12\` shows what happened to a task, when, and through what (web or cli).
12239
+ \`monoban search WORDS\` finds a task in any project ("the login bug": \`monoban search login bug\`).
11396
12240
 
11397
12241
  If a command can't reach the API (a sandbox without network), ask the user to allow it; don't work around it.
11398
12242
 
@@ -11451,16 +12295,21 @@ shows one phase.
11451
12295
  Ask once before you start updating the board in a session ("Shall I keep MON-31…MON-35 up to date as I
11452
12296
  go?"). Once the user agrees:
11453
12297
 
11454
- - Starting a task: \`monoban move MON-31 "in progress"\` (columns match in any case, or by a unique prefix;
11455
- use the names \`monoban list\` shows).
12298
+ - Starting a task: \`monoban start MON-31\` in the repository: it checks out the task's branch (\`mon-31-…\`,
12299
+ made from the commit you're on, so be on the right base first) and moves it to In progress. Elsewhere,
12300
+ \`monoban move MON-31 "in progress"\` (columns match in any case, or by a unique prefix).
11456
12301
  - Ticking the checklist: read the description (\`monoban show MON-31 --json\`), change \`- [ ]\` to \`- [x]\`,
11457
12302
  and write the whole description back with \`monoban edit MON-31 -d -\` (stdin, a heredoc as above).
12303
+ - Worth telling whoever reads the task later (a decision, a blocker, what's left): \`monoban comment MON-31 -\`
12304
+ with the Markdown on stdin. Comments can't be edited, so keep them few and finished.
11458
12305
  - Opened a pull request for it: \`monoban attach MON-31 --pr\` right after \`gh pr create\` (on a branch named
11459
12306
  after the task, like \`mon-31-invoices\`, \`monoban attach --pr\` finds the task itself). The card shows it.
11460
12307
  - Finished: \`monoban done MON-31\`, when the work is really done by the user's standard (tests pass, merged,
11461
12308
  or whatever they said). If unsure, ask. After a merge, attach the pull request again
11462
12309
  (\`monoban attach MON-31 <its URL>\`) so the board shows it merged.
11463
12310
  - New work you discover: propose a task; don't add it silently.
12311
+ - Planning for a day: only when the user gives one ("do it Friday"): \`monoban schedule MON-31 fri\`. Their
12312
+ \`monoban today\` shows it then, and late until it's done. "What's on today?" is \`monoban today\`.
11464
12313
 
11465
12314
  "changed elsewhere" means someone edited the task since you read it: read it again, then retry once.
11466
12315
 
@@ -11477,16 +12326,24 @@ go?"). Once the user agrees:
11477
12326
  | Command | Does |
11478
12327
  | --- | --- |
11479
12328
  | \`monoban projects\` | the projects and their keys |
11480
- | \`monoban list [COLUMN…] [--tag TAG]\` | tasks by column |
12329
+ | \`monoban list [COLUMN…] [--tag TAG] [--archived]\` | tasks by column (--archived: the ones done long ago) |
11481
12330
  | \`monoban show MON-12\` | one task in full |
12331
+ | \`monoban log MON-12 [-n COUNT]\` | what happened to it, newest first |
12332
+ | \`monoban comments MON-12 [-n COUNT]\` | its latest comments |
12333
+ | \`monoban today [DAY] [--week]\` | what's planned for today (overdue first) in every project |
12334
+ | \`monoban search WORDS… [-n COUNT]\` | tasks with all the words, in every project, last changed first |
12335
+ | \`monoban schedule MON-12 DAY\` (or \`--clear\`) | plan it for a day: today, tomorrow, fri, +3, oct 12 |
11482
12336
  | \`monoban tags\` | the tags the project's tasks can have |
11483
12337
  | \`monoban notes show\` | the project's notes |
11484
- | \`monoban add "TITLE" [-c COLUMN] [-t TAG]… [-d TEXT \\| -d -]\` | add a task |
12338
+ | \`monoban add "TITLE" [-c COLUMN] [-t TAG]… [--date DAY] [-d TEXT \\| -d -]\` | add a task |
11485
12339
  | \`monoban edit MON-12 [--title TEXT] [-d TEXT \\| -d -]\` | replace its title or description |
11486
12340
  | \`monoban move MON-12 COLUMN\` | move it to the end of a column |
12341
+ | \`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) |
12342
+ | \`monoban start MON-12 [--no-branch]\` | check out its branch (mon-12-title) and move it to In progress |
11487
12343
  | \`monoban done MON-12\` | move it to Done |
11488
12344
  | \`monoban tag MON-12 TAG…\` / \`monoban untag MON-12 TAG…\` | put tags on it / take them off |
11489
12345
  | \`monoban attach MON-12 --pr\` or \`monoban attach MON-12 URL\` | attach this branch's pull request, or any link |
12346
+ | \`monoban comment MON-12 TEXT\` (or \`-\` for stdin) | comment on it, in Markdown |
11490
12347
  | \`monoban notes add TEXT\` (or \`-\` for stdin) | add lines at the end of the notes |
11491
12348
 
11492
12349
  Every command takes \`--json\`; project commands take \`-p KEY\`. \`monoban COMMAND --help\` has the rest.
@@ -11550,6 +12407,91 @@ async function setup(ctx, agent, options) {
11550
12407
  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".`);
11551
12408
  }
11552
12409
  //#endregion
12410
+ //#region src/commands/start.ts
12411
+ /** How long a branch name's words may be, after `mon-12-`. */
12412
+ const SLUG_LENGTH = 40;
12413
+ /** The branch for a task: `mon-12-import-boards-from-trello` (its ref, then its title's first words). */
12414
+ function branchName(ref, title) {
12415
+ const words = title.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
12416
+ const cut = words.length > SLUG_LENGTH ? words.slice(0, 41).replace(/-[^-]*$/, "") : words;
12417
+ return [ref.toLowerCase(), cut].filter(Boolean).join("-");
12418
+ }
12419
+ /**
12420
+ * The column where work happens: the one named In progress (or Doing, WIP…), else the one after the
12421
+ * first, unless that's Done. undefined when the board has none (Backlog and Done only).
12422
+ */
12423
+ function workColumn(columns) {
12424
+ const names = [
12425
+ "in progress",
12426
+ "in-progress",
12427
+ "doing",
12428
+ "wip",
12429
+ "started",
12430
+ "working",
12431
+ "active"
12432
+ ];
12433
+ const named = columns.find((c) => names.includes(c.name.trim().toLowerCase()));
12434
+ if (named) return named;
12435
+ const second = columns[1];
12436
+ return second && second !== doneColumn(columns) ? second : void 0;
12437
+ }
12438
+ /**
12439
+ * `monoban start MON-12`: work on a task. Checks out its branch (`mon-12-title`: made from the commit
12440
+ * you're on, or the one already there) and moves it to In progress, unless it's there or further on.
12441
+ * --no-branch and --no-move do half of it.
12442
+ */
12443
+ async function start(ctx, ref, options) {
12444
+ const api = apis(ctx).signedIn;
12445
+ let task = await taskByRef(api, ref, ctx);
12446
+ const { key, number } = taskRefOf(task.ref);
12447
+ const columns = await columnsOf(api, key);
12448
+ const lines = [];
12449
+ let branch = null;
12450
+ if (options.branch !== false) {
12451
+ 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);
12452
+ const current = await ctx.clone.branch();
12453
+ const own = (name) => taskOfBranch(name) === task.ref;
12454
+ if (own(current)) {
12455
+ branch = current;
12456
+ lines.push(`Already on ${branch}.`);
12457
+ } else {
12458
+ const existing = (await ctx.clone.branches()).find(own);
12459
+ branch = existing ?? branchName(task.ref, task.title);
12460
+ const why = await ctx.clone.switchTo(branch, !existing);
12461
+ if (why) throw new CliError(`git couldn't switch to ${branch}: ${why}`);
12462
+ lines.push(existing ? `Switched to ${branch}.` : `Switched to a new branch ${branch}.`);
12463
+ }
12464
+ }
12465
+ if (options.move !== false) {
12466
+ const target = workColumn(columns);
12467
+ const at = (t) => columns.findIndex((c) => c.id === t.columnId);
12468
+ const here = columns[at(task)];
12469
+ if (!target) lines.push(`${task.ref} stays in ${here?.name ?? "its column"}: the board has no In progress column.`);
12470
+ else if (at(task) >= columns.indexOf(target)) lines.push(`${task.ref} is in ${here?.name ?? "its column"} already.`);
12471
+ else {
12472
+ task = await unwrap(api.PATCH("/v1/projects/{key}/tasks/{number}", {
12473
+ params: {
12474
+ path: {
12475
+ key,
12476
+ number
12477
+ },
12478
+ header: ifMatch(task.version)
12479
+ },
12480
+ body: { columnId: target.id }
12481
+ })).catch((err) => changedElsewhere(err, task.ref));
12482
+ lines.push(`Moved ${task.ref}${here ? ` from ${here.name}` : ""} to ${target.name}.`);
12483
+ }
12484
+ }
12485
+ if (options.json) {
12486
+ const json = {
12487
+ ...taskJson(task, columns, await tagsFor(api, key, task)),
12488
+ branch
12489
+ };
12490
+ return ctx.out(JSON.stringify(json, null, 2));
12491
+ }
12492
+ for (const line of lines) ctx.out(line);
12493
+ }
12494
+ //#endregion
11553
12495
  //#region src/complete.ts
11554
12496
  /**
11555
12497
  * Shell completion (`monoban completion bash|zsh|fish`). The scripts are thin: on Tab they run
@@ -11565,6 +12507,7 @@ const SHELLS = [
11565
12507
  const VALUES = {
11566
12508
  project: "projects",
11567
12509
  key: "projects",
12510
+ to: "projects",
11568
12511
  column: "columns",
11569
12512
  columns: "columns",
11570
12513
  task: "tasks",
@@ -11579,11 +12522,13 @@ async function complete(root, words, lookup) {
11579
12522
  let command = root;
11580
12523
  let positionals = 0;
11581
12524
  let pending;
12525
+ let to;
11582
12526
  let project;
11583
12527
  let taskProject;
11584
12528
  let dashes = false;
11585
12529
  for (const word of words.slice(0, -1)) if (pending) {
11586
12530
  if (pending.attributeName() === "project") project = word;
12531
+ if (pending.attributeName() === "to") to = word;
11587
12532
  pending = void 0;
11588
12533
  } else if (!dashes && word === "--") dashes = true;
11589
12534
  else if (!dashes && word.startsWith("-") && word !== "-") {
@@ -11592,6 +12537,7 @@ async function complete(root, words, lookup) {
11592
12537
  if (option && takesValue(option)) {
11593
12538
  if (value === void 0) pending = option;
11594
12539
  else if (option.attributeName() === "project") project = value;
12540
+ else if (option.attributeName() === "to") to = value;
11595
12541
  }
11596
12542
  } else if (command.commands.length) {
11597
12543
  const next = command.commands.find((c) => c.name() === word || c.aliases().includes(word));
@@ -11602,7 +12548,11 @@ async function complete(root, words, lookup) {
11602
12548
  taskProject ??= parseTaskRef(word)?.key;
11603
12549
  }
11604
12550
  project ??= taskProject;
11605
- if (pending) return values(pending.attributeName(), pending.argChoices, lookup, project, current);
12551
+ const where = {
12552
+ project,
12553
+ columns: to ?? project
12554
+ };
12555
+ if (pending) return values(pending.attributeName(), pending.argChoices, lookup, where, current);
11606
12556
  if (!dashes && current.startsWith("-")) return help.visibleOptions(command).flatMap((o) => o.long ? [{
11607
12557
  value: o.long,
11608
12558
  description: o.description
@@ -11614,16 +12564,16 @@ async function complete(root, words, lookup) {
11614
12564
  const args = command.registeredArguments;
11615
12565
  const last = args.at(-1);
11616
12566
  const arg = args[positionals] ?? (last?.variadic ? last : void 0);
11617
- return arg ? values(arg.name(), arg.argChoices, lookup, project, current) : [];
12567
+ return arg ? values(arg.name(), arg.argChoices, lookup, where, current) : [];
11618
12568
  }
11619
- function values(name, choices, lookup, project, current) {
12569
+ function values(name, choices, lookup, { project, columns }, current) {
11620
12570
  if (choices) return choices.map((value) => ({
11621
12571
  value,
11622
12572
  description: ""
11623
12573
  }));
11624
12574
  switch (VALUES[name]) {
11625
12575
  case "projects": return lookup.projects();
11626
- case "columns": return lookup.columns(project);
12576
+ case "columns": return lookup.columns(columns);
11627
12577
  case "tasks": return lookup.tasks(/^([^-\s]+)-/.exec(current)?.[1] ?? project);
11628
12578
  case "tags": return lookup.tags(project);
11629
12579
  default: return [];
@@ -11799,7 +12749,7 @@ async function latestVersion(ctx) {
11799
12749
  async function upgrade(ctx, options, kind = thisInstall()) {
11800
12750
  const latest = await latestVersion(ctx);
11801
12751
  const { how, command } = UPGRADE[kind];
11802
- const outdated = latest !== null && newer(latest, "1.1.0");
12752
+ const outdated = latest !== null && newer(latest, "1.3.0");
11803
12753
  if (options.json) {
11804
12754
  ctx.out(JSON.stringify({
11805
12755
  version: VERSION,
@@ -11828,11 +12778,18 @@ function program(ctx) {
11828
12778
  cli.command("projects").description("List your projects and their keys").addOption(json()).action(async (options) => projects(await ctx(), options));
11829
12779
  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));
11830
12780
  cli.command("unlink").description("Undo `monoban link` for this clone's repository").addOption(json()).action(async (options) => unlink(await ctx(), options));
11831
- 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").addOption(project()).addOption(json()).action(async (columns, options) => list(await ctx(), columns, options));
12781
+ 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));
11832
12782
  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));
11833
- 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).addOption(project()).addOption(json()).action(async (title, options) => add(await ctx(), title, options));
11834
- 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").addOption(json()).action(async (ref, column, options) => move(await ctx(), ref, column, options));
12783
+ 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));
12784
+ cli.command("comment").argument("<task>", "like MON-12").argument("<text...>", "what to say, in Markdown (- reads it from stdin)").description("Comment on a task").addOption(json()).action(async (ref, words, options) => comment(await ctx(), ref, words, options));
12785
+ cli.command("comments").argument("<task>", "like MON-12").description("Show a task's latest comments, oldest of them first").option("-n, --number <count>", "how many comments (default 20)").addOption(json()).action(async (ref, options) => comments(await ctx(), ref, options));
12786
+ 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));
12787
+ 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));
12788
+ 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));
12789
+ 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));
12790
+ 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));
11835
12791
  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));
12792
+ 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));
11836
12793
  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));
11837
12794
  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));
11838
12795
  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));