@krapht/ork 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (71) hide show
  1. package/README.md +12 -7
  2. package/dist/__build_info__-D6mXC4cD.mjs +228 -0
  3. package/dist/apply-Mb0fNpCX.mjs +17 -0
  4. package/dist/argument-error-CihH46Le.mjs +27 -0
  5. package/dist/attach-C1OnxyMh.mjs +92 -0
  6. package/dist/attach-CEGbRg1D.mjs +1230 -0
  7. package/dist/bin.mjs +1312 -2390
  8. package/dist/brief-DH66xmj8.mjs +115 -0
  9. package/dist/{decide-CGyx9rv7.mjs → builtin-files-Cf-NZDqM.mjs} +3 -51
  10. package/dist/chips-BqcT58qr.mjs +43 -0
  11. package/dist/command-tree-CEkzWNy6.mjs +63 -0
  12. package/dist/{completion-CSU5vkEt.mjs → completion-DS0gCZRm.mjs} +200 -30
  13. package/dist/context-CGPh12HV.mjs +106 -0
  14. package/dist/detached-Dakw5RZj.mjs +38 -0
  15. package/dist/extra-arguments-BxQMXARO.mjs +13 -0
  16. package/dist/{find-D6Gj1sxg.mjs → find-BTikxc54.mjs} +2 -2
  17. package/dist/flags-C8yCq0j5.mjs +145 -0
  18. package/dist/follow-ups-CtlhHbwe.mjs +563 -0
  19. package/dist/format-BB4E-T6x.mjs +249 -0
  20. package/dist/{help-groups-BwYoAWsh.mjs → help-groups-BpRgBSTh.mjs} +42 -76
  21. package/dist/in-a-run-CbnKjO7t.mjs +27 -0
  22. package/dist/install-CWcpX5g4.mjs +211 -0
  23. package/dist/{limits-B1-DYc3d.mjs → limits-VQqsBoQk.mjs} +2 -2
  24. package/dist/{mcp-DE_EmyVm.mjs → mcp-wGfkMCVF.mjs} +6 -6
  25. package/dist/once-BHxSdZz_.mjs +112 -0
  26. package/dist/orphan-guard-BFKg8VSd.mjs +58 -0
  27. package/dist/output-B1kwo0YU.mjs +439 -0
  28. package/dist/outputs-text-CNTJ7Qq_.mjs +19 -0
  29. package/dist/{pause-CL6N_Xrj.mjs → pause-C_Wxh-KM.mjs} +7 -4
  30. package/dist/print-DNYzq4Rr.mjs +19 -0
  31. package/dist/project-records-XY3ku95x.mjs +233 -0
  32. package/dist/refusals-DQQX3AIb.mjs +116 -0
  33. package/dist/{relay-0SD0erwf.mjs → relay-BA6tsnpc.mjs} +2 -2
  34. package/dist/run-Bvvg-fiF.mjs +234 -0
  35. package/dist/run-DBUAq-Uu.mjs +1452 -0
  36. package/dist/send-nrKtak5F.mjs +105 -0
  37. package/dist/{src-Dujmvv4s.mjs → src-8cOPOgrT.mjs} +12523 -5507
  38. package/dist/{src-BbyEoMn4.mjs → src-CmEvHdju.mjs} +797 -233
  39. package/dist/src-D4JSymhK.mjs +3104 -0
  40. package/dist/{src-DOcK8Jfp.mjs → src-I_RyKu6_.mjs} +1022 -590
  41. package/dist/store-CDpk8Wtz.mjs +16 -0
  42. package/dist/ui/THIRD_PARTY_LICENSES.txt +612 -0
  43. package/dist/ui/assets/app--FijEXiJ.css +1 -0
  44. package/dist/ui/assets/app-BowhjEAe.js +112 -0
  45. package/dist/ui/assets/{index-9dFha9Qn.js → index-CrMa2oHB.js} +3 -3
  46. package/dist/ui/assets/theme-CdXvqTQ6.js +1 -0
  47. package/dist/ui/index.html +2 -2
  48. package/dist/{ui-CTmO2Xzu.mjs → ui-DY3Dnpho.mjs} +54 -25
  49. package/dist/usage-1VwSg_Qt.mjs +257 -0
  50. package/dist/validate-BxayjjkV.mjs +632 -0
  51. package/dist/verdict-CMvPCpWC.mjs +84 -0
  52. package/dist/{watch-CtbgDAcz.mjs → watch-CT0EtLPZ.mjs} +45 -17
  53. package/dist/{workflows-D1_WVukk.mjs → workflows-DHHi-APg.mjs} +30 -5
  54. package/dist/worktrees-CZvbHzbN.mjs +302 -0
  55. package/package.json +10 -8
  56. package/dist/__build_info__-fy6L1Mrd.mjs +0 -615
  57. package/dist/clean-DaHjs__2.mjs +0 -88
  58. package/dist/context-DT8MfEIR.mjs +0 -274
  59. package/dist/format-Dnfv8zMT.mjs +0 -427
  60. package/dist/in-a-run-pLAZeNys.mjs +0 -22
  61. package/dist/list-BrH8KRSJ.mjs +0 -110
  62. package/dist/output-BLQWD6MJ.mjs +0 -950
  63. package/dist/remove-BeGdqroy.mjs +0 -194
  64. package/dist/report-DK4LGqwF.mjs +0 -129
  65. package/dist/send-C8tunWhv.mjs +0 -163
  66. package/dist/src-CCUKRX51.mjs +0 -1204
  67. package/dist/ui/assets/app-BNT0SuIz.css +0 -1
  68. package/dist/ui/assets/app-T7wVAhgx.js +0 -67
  69. package/dist/ui/assets/theme-3xH5jxKs.js +0 -1
  70. package/dist/usage-DYUmP0i4.mjs +0 -419
  71. package/dist/worktrees-DdMYoNOC.mjs +0 -212
@@ -0,0 +1,563 @@
1
+ import { $n as isGithubIssueUrl, Cn as followUpProblem, Gr as placeFor, Kt as followUpListTable, Qn as followUpActions, Sn as deliverFollowUp, Yn as changeFollowUp, Zn as findFollowUp, _n as postFollowUpMessage, bn as recordPublished, mr as runGh, yn as markDue } from "./src-8cOPOgrT.mjs";
2
+ import { d as followUpsRule, f as refreshDue, n as flagValues } from "./run-DBUAq-Uu.mjs";
3
+ import { t as applyFilters } from "./apply-Mb0fNpCX.mjs";
4
+ import { n as unknownProjectRefusal } from "./refusals-DQQX3AIb.mjs";
5
+ import { t as findRun } from "./find-BTikxc54.mjs";
6
+ import { a as plain, c as write, l as writeErr, s as style } from "./output-B1kwo0YU.mjs";
7
+ import { t as refuseExtraArguments } from "./extra-arguments-BxQMXARO.mjs";
8
+ import { c as refuseUnknownFlags, i as readListArgs, n as filterArgs } from "./flags-C8yCq0j5.mjs";
9
+ import { t as printList } from "./print-DNYzq4Rr.mjs";
10
+ import { t as withStore } from "./store-CDpk8Wtz.mjs";
11
+ import { homedir } from "node:os";
12
+ import { defineCommand } from "citty";
13
+ // src/follow-ups/command.ts
14
+ /**
15
+ * @file What the `ork follow-ups` subcommands share: the flags, the project a
16
+ * call is about, and the due check every call runs first, in the user's
17
+ * store. A `gh` that fails only warns.
18
+ */
19
+ const json = {
20
+ type: "boolean",
21
+ description: "Print JSON",
22
+ default: false
23
+ };
24
+ const project = {
25
+ type: "string",
26
+ description: "A registered project's id (default: the one you are in)"
27
+ };
28
+ const idArg = {
29
+ type: "positional",
30
+ description: "A follow-up's id, or a prefix of one",
31
+ required: true
32
+ };
33
+ /** Says why, and makes the command exit 1. */
34
+ const fail = (message) => {
35
+ writeErr(message);
36
+ process.exitCode = 1;
37
+ };
38
+ /** The project a command is about, from `--project` or the folder. */
39
+ const placeOf = (store, key) => {
40
+ const projects = store.projects();
41
+ if (key === void 0) return placeFor(process.cwd(), projects);
42
+ const found = projects.find((p) => p.id === key || p.root === key);
43
+ if (found === void 0) {
44
+ fail(unknownProjectRefusal(key, projects.map((p) => p.id)));
45
+ return;
46
+ }
47
+ return placeFor(found.root, projects);
48
+ };
49
+ /** Runs `body` in the project, after the due check, in the user's store. */
50
+ const inProject = (key, body) => withStore(async (store) => {
51
+ const place = placeOf(store, key);
52
+ if (place === void 0) return;
53
+ await refreshDue(store, place.root, (line) => {
54
+ writeErr(style("dim", line));
55
+ });
56
+ await body(store, place);
57
+ });
58
+ /**
59
+ * Like `inProject`, for a list: `key` may be `all`, which gives every
60
+ * registered project's place. The due check runs for each.
61
+ */
62
+ const inProjects = (key, body) => withStore(async (store) => {
63
+ const projects = store.projects();
64
+ const places = key === "all" ? projects.map((p) => placeFor(p.root, projects)) : [placeOf(store, key)];
65
+ if (places.includes(void 0)) return;
66
+ const found = places.filter((place) => place !== void 0);
67
+ await Promise.all(found.map((place) => refreshDue(store, place.root, (line) => {
68
+ writeErr(style("dim", line));
69
+ })));
70
+ await body(store, found);
71
+ });
72
+ /** Runs `body` on the follow-up `id` names, or says why there is none. */
73
+ const withFollowUp = (args, body) => inProject(args.project, async (store, place) => {
74
+ const found = findFollowUp(store, place.root, args.id);
75
+ if (!found.ok) {
76
+ fail(found.error);
77
+ return;
78
+ }
79
+ await body(store, place, found.followUp);
80
+ });
81
+ /**
82
+ * The follow-ups several words name (`done a b`, `drop a,b`: a comma splits a
83
+ * word too), each once, or `undefined` after saying every word that failed and
84
+ * making the command exit 1; the caller then changes nothing.
85
+ */
86
+ const eachTarget = (words, resolve) => {
87
+ const named = [...new Set(words.flatMap((word) => word.split(",")).map((word) => word.trim()).filter((word) => word !== ""))];
88
+ if (named.length === 0) {
89
+ fail("Give a follow-up id.");
90
+ return;
91
+ }
92
+ const found = /* @__PURE__ */ new Map();
93
+ let failed = false;
94
+ for (const word of named) {
95
+ const one = resolve(word);
96
+ if (one.ok) for (const f of one.followUps) found.set(f.id, f);
97
+ else {
98
+ fail(one.error);
99
+ failed = true;
100
+ }
101
+ }
102
+ return failed ? void 0 : [...found.values()];
103
+ };
104
+ /**
105
+ * Like `withFollowUp`, for every id in `args._` (space or comma separated):
106
+ * `refused` says why one may not be changed, and any refusal stops the call.
107
+ */
108
+ const withFollowUps = (args, refused, body) => inProject(args.project, async (store, place) => {
109
+ const followUps = eachTarget(args._, (word) => {
110
+ const found = findFollowUp(store, place.root, word);
111
+ if (!found.ok) return found;
112
+ const why = refused(found.followUp);
113
+ return why === void 0 ? {
114
+ ok: true,
115
+ followUps: [found.followUp]
116
+ } : {
117
+ ok: false,
118
+ error: why
119
+ };
120
+ });
121
+ if (followUps !== void 0) await body(store, place, followUps);
122
+ });
123
+ // src/follow-ups/format.ts
124
+ /** The groups of the list, in the order they are shown. */
125
+ const GROUPS = [
126
+ {
127
+ status: "due",
128
+ title: "Due"
129
+ },
130
+ {
131
+ status: "waiting",
132
+ title: "Waiting"
133
+ },
134
+ {
135
+ status: "done",
136
+ title: "Done"
137
+ },
138
+ {
139
+ status: "dropped",
140
+ title: "Dropped"
141
+ }
142
+ ];
143
+ /** `agent` first, then the maintainer, other projects, then people. */
144
+ const FOR_ORDER = [
145
+ "agent",
146
+ "me",
147
+ "project:",
148
+ "person:"
149
+ ];
150
+ const forOrder = (value) => FOR_ORDER.findIndex((prefix) => value.startsWith(prefix));
151
+ /** The list's order within a status: by who it is for. */
152
+ const byFor = (a, b) => forOrder(a.for) - forOrder(b.for) || a.for.localeCompare(b.for);
153
+ /** A multi-line text, each line safe to print. */
154
+ const linesOf = (text) => text.split("\n").map((line) => plain(line));
155
+ const when = (f) => f.ref === void 0 ? f.due : `${f.due} ${f.ref}`;
156
+ /** One follow-up on one line; a short note when a run has taken it. */
157
+ const followUpLine = (f) => `${style("dim", f.id)} ${f.kind.padEnd(7)} ${plain(f.title)} ${style("dim", `(${plain(when(f))})`)}${f.takenBy === void 0 ? "" : style("dim", ` taken by ${plain(f.takenBy)}`)}`;
158
+ /** What to do with a draft: copy and send it, unless it is closed already. */
159
+ const draftHeading = (f, to) => f.status === "done" || f.status === "dropped" ? `Draft to ${to} (${f.status})` : `Draft to ${to}: copy it, send it, then \`ork follow-ups done ${f.id}\``;
160
+ /**
161
+ * The follow-ups grouped by status, then by `for`; the closed ones only with
162
+ * `all`. A line each, under a heading each.
163
+ */
164
+ const formatFollowUps = (followUps, all) => {
165
+ const lines = [];
166
+ for (const group of GROUPS) {
167
+ if (!all && group.status !== "due" && group.status !== "waiting") continue;
168
+ const inGroup = followUps.filter((f) => f.status === group.status).toSorted(byFor);
169
+ if (inGroup.length === 0) continue;
170
+ if (lines.length > 0) lines.push("");
171
+ lines.push(style("bold", `${group.title} (${String(inGroup.length)})`));
172
+ for (const kind of new Set(inGroup.map((f) => f.for))) {
173
+ lines.push(` ${style("cyan", `for ${plain(kind)}`)}`);
174
+ for (const f of inGroup.filter((one) => one.for === kind)) lines.push(` ${followUpLine(f)}`);
175
+ }
176
+ }
177
+ return lines.length === 0 ? [style("dim", "No follow-ups.")] : lines;
178
+ };
179
+ const fromLine = (f) => f.from.run === void 0 ? [] : [`from run ${plain(f.from.run)}${f.from.node === void 0 ? "" : `, node ${plain(f.from.node)}`}`];
180
+ /** One follow-up whole: its record, its draft and its steps, ready to copy. */
181
+ const formatFollowUp = (f) => [
182
+ `${style("bold", plain(f.title))} ${style("dim", f.id)}`,
183
+ `status ${f.status}${f.note === void 0 ? "" : ` (${plain(f.note)})`}, for ${plain(f.for)}, ${f.kind}, due ${plain(f.due)}`,
184
+ ...f.ref === void 0 ? [] : [`waits on ${plain(f.ref)}`],
185
+ ...f.takenBy === void 0 ? [] : [`taken by run ${plain(f.takenBy)}`],
186
+ ...fromLine(f),
187
+ ...f.where.length === 0 ? [] : [`files ${f.where.map((file) => plain(file)).join(", ")}`],
188
+ ...f.url === void 0 ? [] : [`kept at ${plain(f.url)}`],
189
+ ...f.body === "" ? [] : ["", ...linesOf(f.body)],
190
+ ...f.draft === void 0 ? [] : [
191
+ "",
192
+ style("bold", draftHeading(f, `${plain(f.draft.to)}${f.draft.channel === void 0 ? "" : ` (${plain(f.draft.channel)})`}`)),
193
+ ...linesOf(f.draft.text).map((line) => ` ${line}`)
194
+ ],
195
+ ...f.steps === void 0 ? [] : [
196
+ "",
197
+ style("bold", "Steps (Ork never runs them):"),
198
+ ...f.steps.flatMap((step, index) => [` ${String(index + 1)}. ${plain(step.text)}`, ...step.command === void 0 ? [] : [` ${plain(step.command)}`]])
199
+ ]
200
+ ];
201
+ // src/commands/follow-ups-act.ts
202
+ /**
203
+ * @file What `ork follow-ups` does to one follow-up: done (a message: sent),
204
+ * drop, reopen, make due, post a drafted GitHub comment, and `published`,
205
+ * which a workflow's step calls once its change is out. Posting goes through
206
+ * the person's own `gh` and only with `--confirm`, after showing the exact
207
+ * text; Ork never runs a task's commands.
208
+ */
209
+ /**
210
+ * `done`, `drop` or `reopen`: one change of status for each id given (space or
211
+ * comma separated), or why one can't be; any refusal changes none.
212
+ */
213
+ const closing = (action, description, verb) => defineCommand({
214
+ meta: {
215
+ name: action,
216
+ description
217
+ },
218
+ args: {
219
+ id: {
220
+ ...idArg,
221
+ description: "A follow-up's id, or a prefix of one; several allowed, space or comma separated"
222
+ },
223
+ project
224
+ },
225
+ run: ({ args }) => withFollowUps(args, (followUp) => {
226
+ const allowed = followUpActions(followUp)[action];
227
+ return allowed.ok ? void 0 : allowed.error;
228
+ }, (store, _place, followUps) => {
229
+ for (const followUp of followUps) {
230
+ const changed = changeFollowUp(store, followUp, action);
231
+ if (!changed.ok) {
232
+ fail(changed.error);
233
+ continue;
234
+ }
235
+ write(`${style("green", "✓")} ${verb} ${changed.followUp.id}: ${plain(changed.followUp.title)}`);
236
+ }
237
+ })
238
+ });
239
+ const due = defineCommand({
240
+ meta: {
241
+ name: "due",
242
+ description: "Make a waiting follow-up due now, or all of a run's (after a deploy, say)"
243
+ },
244
+ args: {
245
+ target: {
246
+ type: "positional",
247
+ description: "A follow-up's id (or a prefix), or a run id; several allowed, space or comma separated",
248
+ required: true
249
+ },
250
+ project
251
+ },
252
+ run: ({ args }) => inProject(args.project, (store, place) => {
253
+ const waiting = eachTarget(args._, (target) => {
254
+ const one = findFollowUp(store, place.root, target);
255
+ const run = findRun(store, target, "");
256
+ const runId = run.ok ? run.run.id : target;
257
+ const ready = (one.ok ? [one.followUp] : store.followUps(place.root).filter((f) => f.from.run === runId)).filter((f) => f.status === "waiting");
258
+ return ready.length === 0 ? {
259
+ ok: false,
260
+ error: `Nothing waiting under \`${target}\`: give a waiting follow-up's id, or a run that left some.`
261
+ } : {
262
+ ok: true,
263
+ followUps: ready
264
+ };
265
+ });
266
+ for (const f of waiting ?? []) for (const marked of markDue(store, place.root, f.id)) write(`${style("green", "✓")} due ${marked.id}: ${plain(marked.title)}`);
267
+ })
268
+ });
269
+ const post = defineCommand({
270
+ meta: {
271
+ name: "post",
272
+ description: "Post a message drafted for GitHub, as a comment through your own gh, with --confirm; without it, show what would be posted"
273
+ },
274
+ plugins: [refuseExtraArguments],
275
+ args: {
276
+ id: idArg,
277
+ confirm: {
278
+ type: "boolean",
279
+ description: "Yes: post exactly this text",
280
+ default: false
281
+ },
282
+ project
283
+ },
284
+ run: ({ args }) => withFollowUp(args, async (store, _place, followUp) => {
285
+ const allowed = followUpActions(followUp).post;
286
+ if (!allowed.ok) {
287
+ fail(allowed.error);
288
+ return;
289
+ }
290
+ const draft = followUp.draft;
291
+ if (!args.confirm && draft !== void 0) {
292
+ write(`Would post to ${plain(draft.to)} through your gh:`);
293
+ for (const line of draft.text.split("\n")) write(` ${plain(line)}`);
294
+ writeErr("Run again with --confirm to post it.");
295
+ return;
296
+ }
297
+ const posted = await postFollowUpMessage(followUp, {
298
+ rows: store,
299
+ gh: runGh,
300
+ confirmed: args.confirm,
301
+ home: homedir()
302
+ });
303
+ if (!posted.ok) {
304
+ fail(posted.error);
305
+ return;
306
+ }
307
+ write(`${style("green", "✓")} posted${posted.url === void 0 ? "" : ` ${posted.url}`}; done ${followUp.id}`);
308
+ })
309
+ });
310
+ const published = defineCommand({
311
+ meta: {
312
+ name: "published",
313
+ description: "Record that this run published a pull request or branch (a workflow step calls it): its follow-ups wait on it, and the ones it took are done"
314
+ },
315
+ plugins: [refuseExtraArguments],
316
+ args: { ref: {
317
+ type: "positional",
318
+ description: "The pull request URL or the branch",
319
+ required: true
320
+ } },
321
+ run: ({ args }) => withStore((store) => {
322
+ const runId = process.env["ORK_RUN"];
323
+ if (runId === void 0 || runId === "") {
324
+ fail("ork follow-ups published runs inside a run: ORK_RUN is not set.");
325
+ return;
326
+ }
327
+ const found = findRun(store, runId, "");
328
+ if (!found.ok) {
329
+ fail(found.error);
330
+ return;
331
+ }
332
+ const callers = [];
333
+ for (let parent = found.run.parent; parent !== void 0 && !callers.includes(parent); parent = store.lookup(parent).find((r) => r.id === parent)?.parent) callers.push(parent);
334
+ const recorded = recordPublished(store, {
335
+ project: found.run.project,
336
+ run: found.run.id,
337
+ ref: args.ref,
338
+ callers
339
+ });
340
+ write(`${style("green", "✓")} ${String(recorded.referenced.length)} follow-up(s) now wait on ${plain(args.ref)}; ${String(recorded.done.length)} done`);
341
+ })
342
+ });
343
+ // src/commands/follow-ups-add.ts
344
+ /**
345
+ * @file `ork follow-ups add`: a follow-up the maintainer adds by hand, with its
346
+ * `for`, `kind` and `due`, a message's draft or a task's steps. It is kept
347
+ * where the project's rule says, and one for another project goes into that
348
+ * project's list and, when a run is live there, to its session.
349
+ */
350
+ /** `text :: command` as a step; the command is optional. */
351
+ const stepOf = (raw) => {
352
+ const [text = "", command] = raw.split(" :: ", 2);
353
+ return command === void 0 ? { text: text.trim() } : {
354
+ text: text.trim(),
355
+ command: command.trim()
356
+ };
357
+ };
358
+ const defaultKind = (value) => {
359
+ if (value.startsWith("person:")) return "message";
360
+ return value === "agent" || value.startsWith("project:") ? "change" : "task";
361
+ };
362
+ const isKind = (value) => [
363
+ "change",
364
+ "message",
365
+ "task",
366
+ "check"
367
+ ].includes(value);
368
+ const isFor = (value) => /^(?:agent|me|project:.+|person:.+)$/u.test(value);
369
+ const isDue = (value) => /^(?:now|after-merge|after-deploy|\d+-\d+-\d+)$/u.test(value);
370
+ const add = defineCommand({
371
+ meta: {
372
+ name: "add",
373
+ description: "Add a follow-up: --for agent|me|project:<name>|person:<name>, --kind, --due"
374
+ },
375
+ args: {
376
+ title: {
377
+ type: "positional",
378
+ description: "What it is",
379
+ required: true
380
+ },
381
+ for: {
382
+ type: "string",
383
+ description: "agent, me, project:<name> or person:<name> (default: me)"
384
+ },
385
+ kind: {
386
+ type: "string",
387
+ description: "change, message, task or check (default: by --for)"
388
+ },
389
+ due: {
390
+ type: "string",
391
+ description: "now, after-merge, after-deploy or a YYYY-MM-DD date (default: now)"
392
+ },
393
+ body: {
394
+ type: "string",
395
+ description: "What and why"
396
+ },
397
+ where: {
398
+ type: "string",
399
+ description: "A file it is about (repeatable)"
400
+ },
401
+ ref: {
402
+ type: "string",
403
+ description: "The PR or branch it waits on"
404
+ },
405
+ to: {
406
+ type: "string",
407
+ description: "A message: who it is to (default: the person); for --channel github, the issue or PR URL"
408
+ },
409
+ channel: {
410
+ type: "string",
411
+ description: "A message: slack, email, github…"
412
+ },
413
+ text: {
414
+ type: "string",
415
+ description: "A message: its text, to send"
416
+ },
417
+ step: {
418
+ type: "string",
419
+ description: "A task's step, `text` or `text :: command` (repeatable); Ork never runs it"
420
+ },
421
+ project,
422
+ json
423
+ },
424
+ run: ({ args, rawArgs }) => inProject(args.project, async (store, place) => {
425
+ const recipient = args.for ?? "me";
426
+ const kind = args.kind ?? defaultKind(recipient);
427
+ if (!isKind(kind)) {
428
+ fail("--kind is change, message, task or check.");
429
+ return;
430
+ }
431
+ const due = args.due ?? "now";
432
+ if (!isFor(recipient) || !isDue(due)) {
433
+ fail(isFor(recipient) ? "--due is now, after-merge, after-deploy or a YYYY-MM-DD date." : "--for is agent, me, project:<name> or person:<name>.");
434
+ return;
435
+ }
436
+ if (kind === "message" && args.text === void 0) {
437
+ fail("a message needs --text.");
438
+ return;
439
+ }
440
+ if (args.channel === "github" && !isGithubIssueUrl(args.to ?? "")) {
441
+ fail("--channel github needs --to <the issue or pull request URL>, https://github.com/<owner>/<repo>/(issues|pull)/<n>.");
442
+ return;
443
+ }
444
+ const steps = flagValues(rawArgs, "--step").map((raw) => stepOf(raw));
445
+ const input = {
446
+ title: args.title,
447
+ for: recipient,
448
+ kind,
449
+ due,
450
+ where: flagValues(rawArgs, "--where"),
451
+ ...args.body === void 0 ? {} : { body: args.body },
452
+ ...args.ref === void 0 ? {} : { ref: args.ref },
453
+ ...args.text === void 0 ? {} : { draft: {
454
+ to: args.to ?? recipient.replace(/^person:/u, ""),
455
+ ...args.channel === void 0 ? {} : { channel: args.channel },
456
+ text: args.text
457
+ } },
458
+ ...steps.length === 0 ? {} : { steps }
459
+ };
460
+ const problem = followUpProblem(input);
461
+ if (problem !== null) {
462
+ fail(`${problem}.`);
463
+ return;
464
+ }
465
+ const rule = followUpsRule(place);
466
+ const delivered = await deliverFollowUp(input, {
467
+ store,
468
+ project: place.root,
469
+ ...rule === void 0 ? {} : { rule }
470
+ });
471
+ if (!delivered.ok) {
472
+ fail(delivered.error);
473
+ return;
474
+ }
475
+ if (args.json) {
476
+ write(JSON.stringify(delivered, void 0, 2));
477
+ return;
478
+ }
479
+ const { added, relayed } = delivered;
480
+ const { followUp } = added;
481
+ write(`${style("green", "✓")} ${added.merged ? "merged into" : "added"} ${followUp.id}: ${plain(followUp.title)}`);
482
+ if (added.note !== void 0) writeErr(style("dim", added.note));
483
+ if (added.merged && input.draft !== void 0 && followUp.draft !== void 0 && input.draft.text !== followUp.draft.text) write(style("dim", ` the new --text was not kept: ${followUp.id} keeps its first draft (see \`ork follow-ups show ${followUp.id}\`)`));
484
+ if (relayed !== void 0) write(style("dim", ` sent to ${relayed.node} of run ${relayed.run}, which is live in that project`));
485
+ })
486
+ });
487
+ // src/commands/follow-ups.ts
488
+ /**
489
+ * @file `ork follow-ups`: what shipped changes left for later, apart from
490
+ * feedback (specs/follow-ups.md): list and show them, add one, and mark one
491
+ * done, dropped, reopened or due, or post its drafted GitHub comment (in
492
+ * `follow-ups-act.ts`). Every call first moves what has come due, reading
493
+ * pull requests through the person's own `gh`; a `gh` that fails only warns.
494
+ */
495
+ /** What a list with no `--status` shows. */
496
+ const OPEN = /* @__PURE__ */ new Set(["due", "waiting"]);
497
+ /** The list's own order: due first, then waiting, done, dropped; then `byFor`. */
498
+ const RANK = {
499
+ due: 0,
500
+ waiting: 1,
501
+ done: 2,
502
+ dropped: 3
503
+ };
504
+ const followUps = defineCommand({
505
+ meta: {
506
+ name: "follow-ups",
507
+ description: "What shipped changes left for later: list, show, add, done, drop, reopen, due, post, published"
508
+ },
509
+ subCommands: {
510
+ list: defineCommand({
511
+ meta: {
512
+ name: "list",
513
+ description: "List the follow-ups, due first, then by who they are for"
514
+ },
515
+ plugins: [refuseUnknownFlags, refuseExtraArguments],
516
+ args: filterArgs(followUpListTable),
517
+ run: async ({ args }) => {
518
+ const given = args;
519
+ const asked = readListArgs(followUpListTable, given);
520
+ if (asked === void 0) return;
521
+ const { filter, limit } = asked;
522
+ const status = filter["status"];
523
+ await inProjects(filter["project"], (store, places) => {
524
+ const target = filter["for"]?.match(/^project:(.*)$/u)?.[1];
525
+ const ids = store.projects().map((p) => p.id);
526
+ if (target !== void 0 && !ids.includes(target)) {
527
+ fail(unknownProjectRefusal(target, ids));
528
+ return;
529
+ }
530
+ const stored = places.flatMap((place) => store.followUps(place.root));
531
+ const shown = applyFilters(followUpListTable, stored, filter).filter((f) => status !== void 0 || OPEN.has(f.status)).toSorted((a, b) => RANK[a.status] - RANK[b.status] || byFor(a, b)).slice(0, limit);
532
+ printList(shown, followUpListTable, given, (rows) => {
533
+ for (const line of formatFollowUps(rows, status !== void 0)) write(line);
534
+ });
535
+ });
536
+ }
537
+ }),
538
+ show: defineCommand({
539
+ meta: {
540
+ name: "show",
541
+ description: "Show a follow-up whole, with its draft and its steps to copy"
542
+ },
543
+ plugins: [refuseExtraArguments],
544
+ args: {
545
+ id: idArg,
546
+ project,
547
+ json
548
+ },
549
+ run: ({ args }) => withFollowUp(args, (_store, _place, followUp) => {
550
+ if (args.json) write(JSON.stringify(followUp, void 0, 2));
551
+ else for (const line of formatFollowUp(followUp)) write(line);
552
+ })
553
+ }),
554
+ add,
555
+ done: closing("done", "Mark a follow-up done; a message is done once you have sent it", "done"),
556
+ drop: closing("drop", "Drop a follow-up that no longer applies", "dropped"),
557
+ reopen: closing("reopen", "Bring a done or dropped follow-up back", "reopened"),
558
+ due,
559
+ post,
560
+ published
561
+ }
562
+ });
563
+ export { followUps };