@harborppm/cli 0.102.0 → 0.103.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 +2 -1
- package/dist/app.mjs +172 -0
- package/lib/cli.mjs +164 -6
- package/lib/format.mjs +56 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -216,6 +216,7 @@ harbor import FILE [--project P] [--portfolio P] [--no-people]
|
|
|
216
216
|
harbor premortem PROJECT ["WHAT WENT WRONG"] [--start]
|
|
217
217
|
harbor voyage PROJECT ["YOUR LINE"]
|
|
218
218
|
harbor messages PROJECT ["TEXT"] [--limit N] | messages PROJECT --edit "TEXT" [--message ID]
|
|
219
|
+
harbor chat TASK|PROJECT|PROGRAM ["TEXT"] [--reply N] [--watch]
|
|
219
220
|
harbor note PROJECT ["NOTE"] [--opens DATE|--milestone NAME|--off-track]
|
|
220
221
|
harbor sound TASK [--answer DAYS|--ask NAMES|--settle DAYS] [--why TEXT]
|
|
221
222
|
harbor soundings [PROJECT]
|
|
@@ -269,7 +270,7 @@ A task has one owner (`--assignee`), who answers for it and whose load it counts
|
|
|
269
270
|
|
|
270
271
|
`harbor limit RR` prints how many tasks each of a board's columns takes at once; `harbor limit RR doing 8` changes one (1 to 20, or `none` for no limit), if you own the harbor. `harbor projects --json` carries each board's `limits` too.
|
|
271
272
|
|
|
272
|
-
`harbor premortem` runs a pre-mortem with your crew: `--start` asks everyone "it's after the end date and this project failed: what happened?", each person adds answers alone for five minutes, and then the answers show together on the project's Risks & issues tab, where each becomes a risk in one click. On its own it prints the question and the answers you can see. Once a project is Done, `harbor voyage` prints its voyage log (planned against actual dates, the biggest slips, the risks that came true, who closed the most, and the crew's lines) and adds yours. `harbor messages PROJECT` reads a project's Messages tab, one conversation for the whole project, and `harbor messages PROJECT "TEXT"` writes to it; `@Name` sends it to that person's Inbox. `harbor note` leaves a note for later on a project: it stays sealed (the crew sees only that it's there and who left it) until its day, until one of the program's milestones is reached, or until the project turns Off track, and then it opens at the top of the project and in the brief. `harbor sound TASK --ask crew` takes a sounding: it asks you, the task's owner and whoever has open work on its project how many working days the task will take (`--ask "Sam,Priya"` picks who). Each person answers alone with `harbor sound TASK --answer 4 --why "…"`, and nobody sees the others' numbers until everyone has; then `harbor sound TASK` shows the spread, an estimate when the guesses are close, or "talk about this first" when they're far apart, and `--settle DAYS` records what you agreed. `harbor soundings` lists them, the ones waiting on your answer first. `harbor goals` lists each portfolio's goals, off track first, with each key result's progress. `harbor goal "TITLE" --new` sets one, and `harbor goal "GOAL"` reads or changes one: `--owner`, `--due`, `--why`, `--link "Ridge Runner"` to count a program, project or task toward it, `--kr "Stores signed" --target 40` to add a number key result and `--kr "Stores signed" --at 12` to move it. `harbor milestones` lists a program's milestones soonest first, with how many of their tasks are done, who signs them off and what they wait on; `harbor milestone "NAME" --new --program P --due DATE` adds one, and `harbor milestone "NAME"` moves (`--due`), renames, ticks (`--reached`), sets who signs it off (`--signs-off`), or, if it's yours to sign, `--approve`s it or asks for `--changes`. `harbor reports` prints the Reports page's dashboards, each chart as its numbers. `harbor messages PROJECT --edit "TEXT"` fixes your latest message there. `harbor ashore` lists the public holidays and time away in the next eight weeks; `--country US,GB` sets whose holidays the harbor takes and `--person NAME --country DE` one person's own, which the forecast and the weekly load then count as days off.
|
|
273
|
+
`harbor premortem` runs a pre-mortem with your crew: `--start` asks everyone "it's after the end date and this project failed: what happened?", each person adds answers alone for five minutes, and then the answers show together on the project's Risks & issues tab, where each becomes a risk in one click. On its own it prints the question and the answers you can see. Once a project is Done, `harbor voyage` prints its voyage log (planned against actual dates, the biggest slips, the risks that came true, who closed the most, and the crew's lines) and adds yours. `harbor messages PROJECT` reads a project's Messages tab, one conversation for the whole project, and `harbor messages PROJECT "TEXT"` writes to it; `@Name` sends it to that person's Inbox. `harbor chat` is the same for any piece of work: `harbor chat RR-42` reads a task's comments, `harbor chat Footwear` a program's messages, `harbor chat Footwear "TEXT" --reply 2` replies under message [2], and `--watch` follows the conversation live, printing new lines as they come; in a terminal, type a line to post it. `harbor note` leaves a note for later on a project: it stays sealed (the crew sees only that it's there and who left it) until its day, until one of the program's milestones is reached, or until the project turns Off track, and then it opens at the top of the project and in the brief. `harbor sound TASK --ask crew` takes a sounding: it asks you, the task's owner and whoever has open work on its project how many working days the task will take (`--ask "Sam,Priya"` picks who). Each person answers alone with `harbor sound TASK --answer 4 --why "…"`, and nobody sees the others' numbers until everyone has; then `harbor sound TASK` shows the spread, an estimate when the guesses are close, or "talk about this first" when they're far apart, and `--settle DAYS` records what you agreed. `harbor soundings` lists them, the ones waiting on your answer first. `harbor goals` lists each portfolio's goals, off track first, with each key result's progress. `harbor goal "TITLE" --new` sets one, and `harbor goal "GOAL"` reads or changes one: `--owner`, `--due`, `--why`, `--link "Ridge Runner"` to count a program, project or task toward it, `--kr "Stores signed" --target 40` to add a number key result and `--kr "Stores signed" --at 12` to move it. `harbor milestones` lists a program's milestones soonest first, with how many of their tasks are done, who signs them off and what they wait on; `harbor milestone "NAME" --new --program P --due DATE` adds one, and `harbor milestone "NAME"` moves (`--due`), renames, ticks (`--reached`), sets who signs it off (`--signs-off`), or, if it's yours to sign, `--approve`s it or asks for `--changes`. `harbor reports` prints the Reports page's dashboards, each chart as its numbers. `harbor messages PROJECT --edit "TEXT"` fixes your latest message there. `harbor ashore` lists the public holidays and time away in the next eight weeks; `--country US,GB` sets whose holidays the harbor takes and `--person NAME --country DE` one person's own, which the forecast and the weekly load then count as days off.
|
|
273
274
|
|
|
274
275
|
`harbor brief --say` turns the brief into the BBC's Shipping Forecast: each program an area, wind for late work, visibility for health, gale warnings for anything off track. It prints the forecast and speaks it with your computer's own voice (`say` on a Mac, Windows' speech, or `espeak-ng` on Linux, which you may need to install). With `--json` it prints the forecast and stays quiet.
|
|
275
276
|
|
package/dist/app.mjs
CHANGED
|
@@ -6918,6 +6918,28 @@ function messagesIn(reflections, place) {
|
|
|
6918
6918
|
return (reflections ?? []).filter((r) => inPlace(r, place)).sort(oldestFirst);
|
|
6919
6919
|
}
|
|
6920
6920
|
/**
|
|
6921
|
+
* A conversation as threads, in the order each began. An answer whose
|
|
6922
|
+
* message was deleted stands on its own, so nobody's words go missing.
|
|
6923
|
+
*/
|
|
6924
|
+
function threadsOf(messages) {
|
|
6925
|
+
const sorted = [...messages].sort(oldestFirst);
|
|
6926
|
+
const byId = new Map(sorted.map((m) => [m.id, m]));
|
|
6927
|
+
const rootOf = (m) => {
|
|
6928
|
+
const parent = m.replyToId ? byId.get(m.replyToId) : void 0;
|
|
6929
|
+
return parent && parent.id !== m.id && !parent.replyToId ? parent.id : null;
|
|
6930
|
+
};
|
|
6931
|
+
const threads = /* @__PURE__ */ new Map();
|
|
6932
|
+
for (const m of sorted) if (!rootOf(m)) threads.set(m.id, {
|
|
6933
|
+
message: m,
|
|
6934
|
+
replies: []
|
|
6935
|
+
});
|
|
6936
|
+
for (const m of sorted) {
|
|
6937
|
+
const root = rootOf(m);
|
|
6938
|
+
if (root) threads.get(root).replies.push(m);
|
|
6939
|
+
}
|
|
6940
|
+
return [...threads.values()];
|
|
6941
|
+
}
|
|
6942
|
+
/**
|
|
6921
6943
|
* The message an answer hangs under: the one asked for, or, for an answer
|
|
6922
6944
|
* to an answer, that answer's own message. Null when it isn't a message in
|
|
6923
6945
|
* the same conversation.
|
|
@@ -24271,6 +24293,128 @@ function notesOf(ctx, p) {
|
|
|
24271
24293
|
};
|
|
24272
24294
|
}) };
|
|
24273
24295
|
}
|
|
24296
|
+
const CHAT_KINDS = [
|
|
24297
|
+
"task",
|
|
24298
|
+
"project",
|
|
24299
|
+
"program"
|
|
24300
|
+
];
|
|
24301
|
+
const exactlyNamed = (items, want) => {
|
|
24302
|
+
const w = want.trim().toLowerCase();
|
|
24303
|
+
return items.filter((i) => i.id === want.trim() || i.name.trim().toLowerCase() === w || i.key?.toLowerCase() === w);
|
|
24304
|
+
};
|
|
24305
|
+
/**
|
|
24306
|
+
* The chat `on` names: a task by key or id, a project, or a program, by name,
|
|
24307
|
+
* key or id. With no `kind`, a task key wins, then an exact project or
|
|
24308
|
+
* program name, then the nearest project name, then the nearest program's.
|
|
24309
|
+
* A project and a program with the very same name need `kind`.
|
|
24310
|
+
*/
|
|
24311
|
+
function chatTarget(data, on, kind) {
|
|
24312
|
+
const asTask = (t) => {
|
|
24313
|
+
const project = data.projects.find((p) => p.id === t.projectId);
|
|
24314
|
+
return {
|
|
24315
|
+
kind: "task",
|
|
24316
|
+
task: t,
|
|
24317
|
+
name: t.title,
|
|
24318
|
+
key: taskKey(t, project) ?? null,
|
|
24319
|
+
project: project?.name ?? null
|
|
24320
|
+
};
|
|
24321
|
+
};
|
|
24322
|
+
const asProject = (p) => ({
|
|
24323
|
+
kind: "project",
|
|
24324
|
+
place: {
|
|
24325
|
+
kind: "project",
|
|
24326
|
+
id: p.id
|
|
24327
|
+
},
|
|
24328
|
+
name: p.name
|
|
24329
|
+
});
|
|
24330
|
+
const asProgram = (p) => ({
|
|
24331
|
+
kind: "program",
|
|
24332
|
+
place: {
|
|
24333
|
+
kind: "program",
|
|
24334
|
+
id: p.id
|
|
24335
|
+
},
|
|
24336
|
+
name: p.name
|
|
24337
|
+
});
|
|
24338
|
+
if (kind === "task") return asTask(taskByRef(data, on));
|
|
24339
|
+
if (kind === "project") return asProject(findOne(data.projects, on, "project"));
|
|
24340
|
+
if (kind === "program") return asProgram(findOne(data.programs, on, "program"));
|
|
24341
|
+
const task = data.tasks.find((x) => x.id === on.trim()) ?? findByKey(data, on);
|
|
24342
|
+
if (task) return asTask(task);
|
|
24343
|
+
const projects = exactlyNamed(data.projects, on);
|
|
24344
|
+
const programs = exactlyNamed(data.programs, on);
|
|
24345
|
+
if (projects.length && programs.length) throw new ToolError(`A project and a program are both called "${on.trim()}". Say which: kind project or kind program.`);
|
|
24346
|
+
if (programs.length && !projects.length) return asProgram(findOne(data.programs, on, "program"));
|
|
24347
|
+
try {
|
|
24348
|
+
return asProject(findOne(data.projects, on, "project"));
|
|
24349
|
+
} catch (err) {
|
|
24350
|
+
if (!(err instanceof ToolError) || !/^No project matches/.test(err.message)) throw err;
|
|
24351
|
+
}
|
|
24352
|
+
try {
|
|
24353
|
+
return asProgram(findOne(data.programs, on, "program"));
|
|
24354
|
+
} catch (err) {
|
|
24355
|
+
if (!(err instanceof ToolError) || !/^No program matches/.test(err.message)) throw err;
|
|
24356
|
+
throw new ToolError(`Nothing to chat on called "${on.trim()}": no task key, project or program matches. Try a task key like RR-42, or a project's or program's name.`);
|
|
24357
|
+
}
|
|
24358
|
+
}
|
|
24359
|
+
/** Every line of a chat, oldest first: a task's comments, or a conversation's messages with their numbers. */
|
|
24360
|
+
function chatLines(data, target) {
|
|
24361
|
+
if (target.kind === "task") return data.comments.filter((c) => c.taskId === target.task.id).sort((a, b) => a.createdAt.localeCompare(b.createdAt)).map((c, i) => ({
|
|
24362
|
+
id: c.id,
|
|
24363
|
+
n: i + 1,
|
|
24364
|
+
authorId: c.authorId,
|
|
24365
|
+
body: c.body,
|
|
24366
|
+
at: c.createdAt,
|
|
24367
|
+
editedAt: c.editedAt ?? null,
|
|
24368
|
+
mentionedIds: c.mentionedIds ?? []
|
|
24369
|
+
}));
|
|
24370
|
+
const threads = threadsOf(messagesIn(data.reflections, target.place));
|
|
24371
|
+
const number = new Map(threads.map((t, i) => [t.message.id, i + 1]));
|
|
24372
|
+
const lines = [];
|
|
24373
|
+
for (const t of threads) for (const m of [t.message, ...t.replies]) {
|
|
24374
|
+
const root = m === t.message ? null : t.message.id;
|
|
24375
|
+
lines.push({
|
|
24376
|
+
id: m.id,
|
|
24377
|
+
...root ? { replyTo: {
|
|
24378
|
+
id: root,
|
|
24379
|
+
n: number.get(root)
|
|
24380
|
+
} } : { n: number.get(m.id) },
|
|
24381
|
+
authorId: m.authorId,
|
|
24382
|
+
body: m.body,
|
|
24383
|
+
at: m.createdAt,
|
|
24384
|
+
editedAt: m.editedAt ?? null,
|
|
24385
|
+
mentionedIds: m.mentionedIds ?? []
|
|
24386
|
+
});
|
|
24387
|
+
}
|
|
24388
|
+
return lines.sort((a, b) => a.at.localeCompare(b.at));
|
|
24389
|
+
}
|
|
24390
|
+
/** A chat as the tools give it back: where, and each line with names for ids. */
|
|
24391
|
+
function chatAnswer(data, target, lines) {
|
|
24392
|
+
const people = byId(data.people);
|
|
24393
|
+
return {
|
|
24394
|
+
on: {
|
|
24395
|
+
kind: target.kind,
|
|
24396
|
+
name: target.name,
|
|
24397
|
+
...target.kind === "task" ? {
|
|
24398
|
+
taskId: target.task.id,
|
|
24399
|
+
...target.key ? { key: target.key } : {}
|
|
24400
|
+
} : { id: target.place.id },
|
|
24401
|
+
...target.kind === "task" && target.project ? { project: target.project } : {}
|
|
24402
|
+
},
|
|
24403
|
+
messages: lines.map((l) => ({
|
|
24404
|
+
id: l.id,
|
|
24405
|
+
...l.n ? { n: l.n } : {},
|
|
24406
|
+
from: nameOf$2(people, l.authorId),
|
|
24407
|
+
at: l.at,
|
|
24408
|
+
...l.editedAt ? { edited: l.editedAt } : {},
|
|
24409
|
+
...l.replyTo ? {
|
|
24410
|
+
replyTo: l.replyTo.n,
|
|
24411
|
+
replyToId: l.replyTo.id
|
|
24412
|
+
} : {},
|
|
24413
|
+
body: l.body,
|
|
24414
|
+
...l.mentionedIds.length ? { mentions: l.mentionedIds.map((id) => nameOf$2(people, id)) } : {}
|
|
24415
|
+
}))
|
|
24416
|
+
};
|
|
24417
|
+
}
|
|
24274
24418
|
const HARBOR_TOOLS = [
|
|
24275
24419
|
tool({
|
|
24276
24420
|
name: "harbor_overview",
|
|
@@ -25239,6 +25383,34 @@ const HARBOR_TOOLS = [
|
|
|
25239
25383
|
};
|
|
25240
25384
|
}
|
|
25241
25385
|
}),
|
|
25386
|
+
tool({
|
|
25387
|
+
name: "read_chat",
|
|
25388
|
+
title: "Read the chat on a task, project or program",
|
|
25389
|
+
description: "The conversation on one piece of work, oldest first: a task's comments (on: its key, like RR-42), a project's messages or a program's messages (on: its name). Each line has who wrote it, when, whether it was edited, who it @mentions, and its number n (messages that answer another carry replyTo, that message's number, instead). since leaves out lines written before it, for checking what's new; limit keeps the newest (default 50; more says how many earlier ones were left out). post_chat writes one." + DATA_NOTE,
|
|
25390
|
+
input: object({
|
|
25391
|
+
harbor: harborArg,
|
|
25392
|
+
on: string().min(1).max(200).describe("A task key or id, or a project's or program's name."),
|
|
25393
|
+
kind: _enum(CHAT_KINDS).optional().describe("Only when a project and a program share the name."),
|
|
25394
|
+
since: string().max(40).optional().describe("An ISO time: only lines written after it."),
|
|
25395
|
+
limit: number().int().min(1).max(500).optional()
|
|
25396
|
+
}),
|
|
25397
|
+
run: (ctx, input) => {
|
|
25398
|
+
const { data } = ctx;
|
|
25399
|
+
const target = chatTarget(data, input.on, input.kind);
|
|
25400
|
+
let lines = chatLines(data, target);
|
|
25401
|
+
if (input.since) {
|
|
25402
|
+
const since = Date.parse(input.since);
|
|
25403
|
+
if (!Number.isFinite(since)) throw new ToolError(`since takes an ISO time, not "${input.since}".`);
|
|
25404
|
+
lines = lines.filter((l) => Date.parse(l.at) > since);
|
|
25405
|
+
}
|
|
25406
|
+
const limit = input.limit ?? 50;
|
|
25407
|
+
const shown = lines.slice(-limit);
|
|
25408
|
+
return {
|
|
25409
|
+
...chatAnswer(data, target, shown),
|
|
25410
|
+
...lines.length > shown.length ? { more: lines.length - shown.length } : {}
|
|
25411
|
+
};
|
|
25412
|
+
}
|
|
25413
|
+
}),
|
|
25242
25414
|
tool({
|
|
25243
25415
|
name: "list_soundings",
|
|
25244
25416
|
title: "Soundings",
|
package/lib/cli.mjs
CHANGED
|
@@ -34,6 +34,9 @@ import {
|
|
|
34
34
|
premortemText,
|
|
35
35
|
notesText,
|
|
36
36
|
messagesText,
|
|
37
|
+
chatText,
|
|
38
|
+
chatLineText,
|
|
39
|
+
chatWhere,
|
|
37
40
|
charterText,
|
|
38
41
|
landfallText,
|
|
39
42
|
loadLineCliText,
|
|
@@ -265,6 +268,10 @@ export const HELP = `harbor: Harbor from the terminal
|
|
|
265
268
|
harbor messages PROJECT ["TEXT"] [--limit N]
|
|
266
269
|
a project's messages, or write
|
|
267
270
|
one (@Name tells them)
|
|
271
|
+
harbor chat TASK|PROJECT|PROGRAM ["TEXT"] [--reply N] [--watch]
|
|
272
|
+
the conversation on a task,
|
|
273
|
+
project or program: read it,
|
|
274
|
+
write in it, or follow it live
|
|
268
275
|
harbor messages PROJECT --edit "TEXT" [--message ID]
|
|
269
276
|
fix your latest message (or that
|
|
270
277
|
one) in its project
|
|
@@ -409,6 +416,9 @@ function banner(io, env, words) {
|
|
|
409
416
|
}
|
|
410
417
|
|
|
411
418
|
const THEMES = ["auto", "light", "dark"];
|
|
419
|
+
/** harbor chat --watch asks this often while people are talking, and slows to the most once it's quiet. */
|
|
420
|
+
const CHAT_POLL_MS = 5_000;
|
|
421
|
+
const CHAT_POLL_MAX_MS = 30_000;
|
|
412
422
|
|
|
413
423
|
const COMMON = { flags: ["json", "help"], options: ["harbor"] };
|
|
414
424
|
const spec = (flags = [], options = [], repeat = []) => ({
|
|
@@ -970,14 +980,16 @@ const DETAIL = {
|
|
|
970
980
|
" harbor shore PROGRAM --url URL writes: posts go to this Slack, Discord,",
|
|
971
981
|
" Teams or Google Chat webhook address",
|
|
972
982
|
" harbor shore PROGRAM --on KINDS writes: turns posts on; KINDS are",
|
|
973
|
-
" forecast, health and
|
|
983
|
+
" forecast, health, notes and messages,",
|
|
984
|
+
" with commas",
|
|
974
985
|
" harbor shore PROGRAM --off KINDS writes: turns them off",
|
|
975
986
|
" harbor shore PROGRAM --test writes: sends a test post",
|
|
976
987
|
" harbor shore PROGRAM --remove writes: stops posting and forgets the",
|
|
977
988
|
" address",
|
|
978
989
|
"",
|
|
979
990
|
" forecast is the morning harbor forecast, health a line when the program or",
|
|
980
|
-
" one of its projects changes health, notes a note for later when it opens
|
|
991
|
+
" one of its projects changes health, notes a note for later when it opens,",
|
|
992
|
+
" messages each new message or reply on the program or its projects.",
|
|
981
993
|
" Every post links back to Harbor. A new channel posts nothing until you turn",
|
|
982
994
|
" something on. The address is a secret: once saved, only a hint of it shows.",
|
|
983
995
|
],
|
|
@@ -1461,6 +1473,24 @@ const DETAIL = {
|
|
|
1461
1473
|
" it explains. The weekly brief names projects that grew a lot since",
|
|
1462
1474
|
" their baseline.",
|
|
1463
1475
|
],
|
|
1476
|
+
chat: [
|
|
1477
|
+
" harbor chat RR-42 reads a task's comments",
|
|
1478
|
+
' harbor chat "Ridge Runner" reads a project\'s messages',
|
|
1479
|
+
" harbor chat Footwear reads a program's messages",
|
|
1480
|
+
' harbor chat RR-42 "TEXT" writes: comments on the task',
|
|
1481
|
+
' harbor chat Footwear "TEXT" --reply 2 writes: replies under message [2]',
|
|
1482
|
+
" harbor chat Footwear --watch follows it live: new lines print as",
|
|
1483
|
+
" they come; in a terminal, type a",
|
|
1484
|
+
' line to post it, "/r N text" to',
|
|
1485
|
+
" reply, Ctrl+C to stop",
|
|
1486
|
+
"",
|
|
1487
|
+
" A task key goes to its comments; a name to that project's messages, or",
|
|
1488
|
+
" the program's when no project has it (--project or --program says which",
|
|
1489
|
+
" when both do). Messages are numbered [1], [2]… with their replies under",
|
|
1490
|
+
" them. @Name sends it to that person's Inbox. Reading shows the newest 50;",
|
|
1491
|
+
" --limit N shows up to 500. --watch asks every 5 seconds while people are",
|
|
1492
|
+
" talking and every 30 once it's quiet.",
|
|
1493
|
+
],
|
|
1464
1494
|
messages: [
|
|
1465
1495
|
" harbor messages PROJECT reads a project's Messages tab",
|
|
1466
1496
|
' harbor messages PROJECT "TEXT" writes: posts to everyone on it',
|
|
@@ -2700,9 +2730,11 @@ export async function run(argv, io = {}) {
|
|
|
2700
2730
|
.split(",")
|
|
2701
2731
|
.map((k) => k.trim().toLowerCase())
|
|
2702
2732
|
.filter(Boolean);
|
|
2703
|
-
const bad = list.find((k) => !["forecast", "health", "notes"].includes(k));
|
|
2733
|
+
const bad = list.find((k) => !["forecast", "health", "notes", "messages"].includes(k));
|
|
2704
2734
|
if (bad || !list.length)
|
|
2705
|
-
throw new HarborError(
|
|
2735
|
+
throw new HarborError(
|
|
2736
|
+
`--${flag} takes forecast, health, notes or messages, with commas between.`,
|
|
2737
|
+
);
|
|
2706
2738
|
return list;
|
|
2707
2739
|
};
|
|
2708
2740
|
const on = kinds("on");
|
|
@@ -2742,10 +2774,11 @@ export async function run(argv, io = {}) {
|
|
|
2742
2774
|
forecast: "morning forecast",
|
|
2743
2775
|
health: "health changes",
|
|
2744
2776
|
notes: "notes when they open",
|
|
2777
|
+
messages: "messages",
|
|
2745
2778
|
};
|
|
2746
|
-
const posts = ["forecast", "health", "notes"].filter((k) => r.hook[k]).map((k) => label[k]);
|
|
2779
|
+
const posts = ["forecast", "health", "notes", "messages"].filter((k) => r.hook[k]).map((k) => label[k]);
|
|
2747
2780
|
const lines = [
|
|
2748
|
-
`${r.program} posts to ${r.hook.service} (${r.hook.hint}): ${posts.length ? posts.join(", ") : "nothing yet; --on forecast,health,notes turns posts on"}.`,
|
|
2781
|
+
`${r.program} posts to ${r.hook.service} (${r.hook.hint}): ${posts.length ? posts.join(", ") : "nothing yet; --on forecast,health,notes,messages turns posts on"}.`,
|
|
2749
2782
|
];
|
|
2750
2783
|
if (r.hook.failures > 0)
|
|
2751
2784
|
lines.push(
|
|
@@ -4067,6 +4100,131 @@ export async function run(argv, io = {}) {
|
|
|
4067
4100
|
throw new HarborError("--limit is a whole number from 1 to 500.");
|
|
4068
4101
|
return call("list_messages", { harbor, project, ...(limit ? { limit } : {}) }, messagesText);
|
|
4069
4102
|
}
|
|
4103
|
+
case "chat": {
|
|
4104
|
+
const { positionals, values, harbor } = parse(
|
|
4105
|
+
spec(["watch", "task", "project", "program"], ["limit", "reply"]),
|
|
4106
|
+
);
|
|
4107
|
+
const [on, ...words] = positionals;
|
|
4108
|
+
if (!on)
|
|
4109
|
+
throw new HarborError(
|
|
4110
|
+
'Give a task key, project or program, and a message if you\'re writing one: harbor chat RR-42 "TEXT".',
|
|
4111
|
+
);
|
|
4112
|
+
const kinds = ["task", "project", "program"].filter((k) => values[k]);
|
|
4113
|
+
if (kinds.length > 1) throw new HarborError("Say one of --task, --project or --program.");
|
|
4114
|
+
const where = { harbor, on, ...(kinds[0] ? { kind: kinds[0] } : {}) };
|
|
4115
|
+
const quoted = /\s/.test(on) ? `"${on}"` : on;
|
|
4116
|
+
const body = words.join(" ").trim();
|
|
4117
|
+
const limit = values.limit ? Number(values.limit) : undefined;
|
|
4118
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 500))
|
|
4119
|
+
throw new HarborError("--limit is a whole number from 1 to 500.");
|
|
4120
|
+
const post = (text, replyTo) =>
|
|
4121
|
+
client
|
|
4122
|
+
.call("post_chat", { ...where, body: text, ...(replyTo ? { replyTo } : {}) })
|
|
4123
|
+
.catch((err) => {
|
|
4124
|
+
if (err instanceof HarborError) throw new HarborError(hint(err.message));
|
|
4125
|
+
throw err;
|
|
4126
|
+
});
|
|
4127
|
+
if (body && !values.watch) {
|
|
4128
|
+
if (values.limit) throw new HarborError("--limit is for reading; leave it off when you write.");
|
|
4129
|
+
const r = await post(body, values.reply);
|
|
4130
|
+
if (asJson) {
|
|
4131
|
+
out(jsonText(r));
|
|
4132
|
+
return 0;
|
|
4133
|
+
}
|
|
4134
|
+
const m = r.posted.message;
|
|
4135
|
+
const what = m.replyTo ? `Replied to [${m.replyTo}]` : r.posted.kind === "task" ? "Commented" : `Posted [${m.n}]`;
|
|
4136
|
+
out(plain(`${what} on ${chatWhere(r.posted)}${r.mentioned?.length ? `; told ${r.mentioned.join(", ")}` : ""}.`));
|
|
4137
|
+
return 0;
|
|
4138
|
+
}
|
|
4139
|
+
if (values.reply && !body) throw new HarborError("--reply goes with the words to post.");
|
|
4140
|
+
const read = (n) => client.call("read_chat", { ...where, limit: n }).catch((err) => {
|
|
4141
|
+
if (err instanceof HarborError) throw new HarborError(hint(err.message));
|
|
4142
|
+
throw err;
|
|
4143
|
+
});
|
|
4144
|
+
if (!values.watch) {
|
|
4145
|
+
const r = await read(limit ?? 50);
|
|
4146
|
+
out(asJson ? jsonText(r) : plain(chatText(r, quoted)));
|
|
4147
|
+
return 0;
|
|
4148
|
+
}
|
|
4149
|
+
// --watch: what's there, then each new line as it comes, until Ctrl+C.
|
|
4150
|
+
// It asks every few seconds (no open connection), more slowly while
|
|
4151
|
+
// nothing's said. In a terminal, a line you type is posted; "/r N text"
|
|
4152
|
+
// replies to message N.
|
|
4153
|
+
if (asJson) throw new HarborError("--watch prints lines as they come; leave --json off.");
|
|
4154
|
+
if (body) {
|
|
4155
|
+
const r = await post(body, values.reply);
|
|
4156
|
+
out(plain(`Posted on ${chatWhere(r.posted)}.`));
|
|
4157
|
+
}
|
|
4158
|
+
const first = await read(limit ?? 20);
|
|
4159
|
+
out(plain(chatText(first, quoted)));
|
|
4160
|
+
const seen = new Set(first.messages.map((m) => m.id));
|
|
4161
|
+
const terminal = io.terminal ?? Boolean(process.stdout.isTTY && process.stdin.isTTY);
|
|
4162
|
+
const sleep = io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
|
|
4163
|
+
const task = first.on.kind === "task";
|
|
4164
|
+
out(
|
|
4165
|
+
plain(
|
|
4166
|
+
terminal
|
|
4167
|
+
? `Watching ${chatWhere(first.on)}. Type a line and Enter to post${task ? "" : ', "/r N text" to reply to [N]'}; Ctrl+C stops.`
|
|
4168
|
+
: `Watching ${chatWhere(first.on)}; Ctrl+C stops.`,
|
|
4169
|
+
),
|
|
4170
|
+
);
|
|
4171
|
+
let typing = null;
|
|
4172
|
+
let stopped = false;
|
|
4173
|
+
let delay = CHAT_POLL_MS;
|
|
4174
|
+
if (terminal && (io.stdin ?? process.stdin).isTTY !== false) {
|
|
4175
|
+
const { createInterface } = await import("node:readline");
|
|
4176
|
+
typing = createInterface({ input: io.stdin ?? process.stdin, terminal: false });
|
|
4177
|
+
typing.on("close", () => {
|
|
4178
|
+
stopped = true;
|
|
4179
|
+
});
|
|
4180
|
+
typing.on("line", (line) => {
|
|
4181
|
+
const text = line.trim();
|
|
4182
|
+
if (!text) return;
|
|
4183
|
+
if (text === "/q" || text === "/quit") {
|
|
4184
|
+
typing.close();
|
|
4185
|
+
return;
|
|
4186
|
+
}
|
|
4187
|
+
const reply = /^\/r(?:eply)?\s+(\d+)\s+([\s\S]+)$/.exec(text);
|
|
4188
|
+
if (/^\/r(?:eply)?\b/.test(text) && !reply) {
|
|
4189
|
+
out('To reply: /r N text, where N is the message\'s number in [ ].');
|
|
4190
|
+
return;
|
|
4191
|
+
}
|
|
4192
|
+
post(reply ? reply[2] : text, reply ? reply[1] : undefined).then(
|
|
4193
|
+
(r) => {
|
|
4194
|
+
seen.add(r.posted.message.id);
|
|
4195
|
+
delay = CHAT_POLL_MS;
|
|
4196
|
+
out(plain(` (posted${r.posted.message.n ? ` as [${r.posted.message.n}]` : ""})`));
|
|
4197
|
+
},
|
|
4198
|
+
(err) => out(plain(` Not posted: ${err instanceof Error ? err.message : String(err)}`)),
|
|
4199
|
+
);
|
|
4200
|
+
});
|
|
4201
|
+
}
|
|
4202
|
+
let rounds = io.watchRounds ?? Infinity;
|
|
4203
|
+
try {
|
|
4204
|
+
while (!stopped && rounds-- > 0) {
|
|
4205
|
+
await sleep(delay);
|
|
4206
|
+
if (stopped) break;
|
|
4207
|
+
let r;
|
|
4208
|
+
try {
|
|
4209
|
+
r = await read(50);
|
|
4210
|
+
} catch (err) {
|
|
4211
|
+
// A dropped connection waits and tries again; anything else stops.
|
|
4212
|
+
if (err instanceof HarborError) throw err;
|
|
4213
|
+
delay = CHAT_POLL_MAX_MS;
|
|
4214
|
+
continue;
|
|
4215
|
+
}
|
|
4216
|
+
const fresh = r.messages.filter((m) => !seen.has(m.id));
|
|
4217
|
+
for (const m of fresh) {
|
|
4218
|
+
seen.add(m.id);
|
|
4219
|
+
out(plain(chatLineText(m)));
|
|
4220
|
+
}
|
|
4221
|
+
delay = fresh.length ? CHAT_POLL_MS : Math.min(CHAT_POLL_MAX_MS, Math.round(delay * 1.5));
|
|
4222
|
+
}
|
|
4223
|
+
} finally {
|
|
4224
|
+
typing?.close();
|
|
4225
|
+
}
|
|
4226
|
+
return 0;
|
|
4227
|
+
}
|
|
4070
4228
|
case "watch": {
|
|
4071
4229
|
const { positionals, values, harbor } = parse(spec(["bell", "once"], ["project", "since"]));
|
|
4072
4230
|
none(positionals);
|
package/lib/format.mjs
CHANGED
|
@@ -1436,6 +1436,62 @@ export function messagesText(r) {
|
|
|
1436
1436
|
].join("\n\n");
|
|
1437
1437
|
}
|
|
1438
1438
|
|
|
1439
|
+
/** Where a chat is, as its heading says it: "RR-42 Call the printer", "Ridge Runner", "Footwear (program)". */
|
|
1440
|
+
export function chatWhere(on) {
|
|
1441
|
+
if (on.kind === "task") return on.key ? `${on.key} ${on.name}` : on.name;
|
|
1442
|
+
return on.kind === "program" ? `${on.name} (program)` : on.name;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
const chatStamp = (m) => `${m.at.slice(0, 16).replace("T", " ")}${m.edited ? " (edited)" : ""}`;
|
|
1446
|
+
|
|
1447
|
+
/** One new line while watching: "[3] Mara · 2026-11-08 14:10: Launch moved", a reply with ↳. */
|
|
1448
|
+
export function chatLineText(m) {
|
|
1449
|
+
const body = m.body.replace(/\s*\n\s*/g, " / ");
|
|
1450
|
+
const lead = m.replyTo ? ` ↳ [${m.replyTo}]` : m.n ? `[${m.n}]` : "";
|
|
1451
|
+
return `${lead ? `${lead} ` : ""}${m.from ?? "Someone"} · ${chatStamp(m)}: ${body}`;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/** read_chat: the conversation, each message with its number and its replies under it. */
|
|
1455
|
+
export function chatText(r, quoted) {
|
|
1456
|
+
const where = chatWhere(r.on);
|
|
1457
|
+
const list = r.messages ?? [];
|
|
1458
|
+
const task = r.on.kind === "task";
|
|
1459
|
+
const noun = task ? "comments" : "messages";
|
|
1460
|
+
if (!list.length)
|
|
1461
|
+
return `No ${noun} on ${where} yet. harbor chat ${quoted} "TEXT" writes the first.`;
|
|
1462
|
+
const out = [`${where} · ${noun}`];
|
|
1463
|
+
if (r.more)
|
|
1464
|
+
out.push(
|
|
1465
|
+
`${r.more} earlier ${r.more === 1 ? "line" : "lines"} left out (--limit N shows more).`,
|
|
1466
|
+
);
|
|
1467
|
+
const indent = (text, pad) => text.replace(/\n/g, `\n${pad}`);
|
|
1468
|
+
const shown = new Set(list.filter((m) => m.n).map((m) => m.n));
|
|
1469
|
+
// Replies whose message is older than the lines shown come first, saying what they answer.
|
|
1470
|
+
for (const m of list.filter((x) => x.replyTo && !shown.has(x.replyTo)))
|
|
1471
|
+
out.push(
|
|
1472
|
+
"",
|
|
1473
|
+
` ↳ to [${m.replyTo}] ${m.from ?? "Someone"} · ${chatStamp(m)}`,
|
|
1474
|
+
` ${indent(m.body, " ")}`,
|
|
1475
|
+
);
|
|
1476
|
+
for (const m of list.filter((x) => !x.replyTo)) {
|
|
1477
|
+
out.push(
|
|
1478
|
+
"",
|
|
1479
|
+
`${task ? "" : `[${m.n}] `}${m.from ?? "Someone"} · ${chatStamp(m)}`,
|
|
1480
|
+
` ${indent(m.body, " ")}`,
|
|
1481
|
+
);
|
|
1482
|
+
for (const reply of list.filter((x) => x.replyTo === m.n))
|
|
1483
|
+
out.push(
|
|
1484
|
+
` ↳ ${reply.from ?? "Someone"} · ${chatStamp(reply)}`,
|
|
1485
|
+
` ${indent(reply.body, " ")}`,
|
|
1486
|
+
);
|
|
1487
|
+
}
|
|
1488
|
+
if (!task) {
|
|
1489
|
+
const first = list.find((m) => m.n)?.n;
|
|
1490
|
+
if (first) out.push("", `--reply ${first} answers message [${first}].`);
|
|
1491
|
+
}
|
|
1492
|
+
return out.join("\n");
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1439
1495
|
const SIGN_OFF = {
|
|
1440
1496
|
pending: "waiting on the sign-off",
|
|
1441
1497
|
approved: "signed off",
|