soltask 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +398 -2
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +344 -0
- package/dist/client.d.ts +131 -0
- package/dist/client.js +879 -0
- package/dist/commands/actions.d.ts +26 -0
- package/dist/commands/actions.js +1181 -0
- package/dist/commands/auth.d.ts +10 -0
- package/dist/commands/auth.js +489 -0
- package/dist/commands/drafts.d.ts +22 -0
- package/dist/commands/drafts.js +736 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +10 -0
- package/dist/commands/meta.d.ts +4 -0
- package/dist/commands/meta.js +195 -0
- package/dist/commands/read.d.ts +24 -0
- package/dist/commands/read.js +1106 -0
- package/dist/commands/watch.d.ts +2 -0
- package/dist/commands/watch.js +397 -0
- package/dist/config.d.ts +86 -0
- package/dist/config.js +365 -0
- package/dist/context.d.ts +70 -0
- package/dist/context.js +1 -0
- package/dist/domain.d.ts +311 -0
- package/dist/domain.js +747 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +40 -0
- package/dist/fsutil.d.ts +35 -0
- package/dist/fsutil.js +243 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/output.d.ts +27 -0
- package/dist/output.js +74 -0
- package/dist/types.d.ts +254 -0
- package/dist/types.js +1 -0
- package/dist/util.d.ts +32 -0
- package/dist/util.js +116 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +13 -0
- package/package.json +63 -4
|
@@ -0,0 +1,1106 @@
|
|
|
1
|
+
import { OPEN_COLUMNS, PRIORITIES, PUBLIC_TEMPLATES, REASONS, TASK_KINDS, TEMPLATES, agentStatus, canStart, createNameResolver, resolveTaskRef, } from "../domain.js";
|
|
2
|
+
import { CliError, EXIT_OK, EXIT_RUNTIME, EXIT_VALIDATION } from "../errors.js";
|
|
3
|
+
import { displayText, emitJson, errOut, formatTable, formatTimestamp, out } from "../output.js";
|
|
4
|
+
import { formatRelativeAge, oneLine, parsePositiveInt, splitCsvList, stripControls, truncate, } from "../util.js";
|
|
5
|
+
import { PROGRAM } from "../version.js";
|
|
6
|
+
const ALL_COLUMNS = ["backlog", "queued", "working", "needs", "shipping", "done", "canceled"];
|
|
7
|
+
const COLUMN_SET = new Set(ALL_COLUMNS);
|
|
8
|
+
const PRIORITY_RANK = { low: 0, normal: 1, high: 2, urgent: 3 };
|
|
9
|
+
const AGENT_STATUS_KINDS = ["down", "working", "idle", "away", "key"];
|
|
10
|
+
const AGENT_STATUS_SET = new Set(AGENT_STATUS_KINDS);
|
|
11
|
+
const MAX_ACTIVITY_LIMIT = 200;
|
|
12
|
+
const DEFAULT_ACTIVITY_LIMIT = 30;
|
|
13
|
+
const EVENT_BODY_PREVIEW_MAX = 500;
|
|
14
|
+
/** Parses repeatable/CSV `--col` values (supporting `open` alias) with strict validation. */
|
|
15
|
+
export function parseColumnFilter(rawItems) {
|
|
16
|
+
const tokens = splitCsvList(rawItems).map((item) => item.toLowerCase());
|
|
17
|
+
if (tokens.length === 0) {
|
|
18
|
+
return { cols: null, serverCol: undefined };
|
|
19
|
+
}
|
|
20
|
+
const cols = new Set();
|
|
21
|
+
let usedAlias = false;
|
|
22
|
+
for (const token of tokens) {
|
|
23
|
+
if (token === "open") {
|
|
24
|
+
usedAlias = true;
|
|
25
|
+
for (const col of OPEN_COLUMNS) {
|
|
26
|
+
cols.add(col);
|
|
27
|
+
}
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (!COLUMN_SET.has(token)) {
|
|
31
|
+
throw new CliError(`Invalid column '${token}'. Valid columns: ${[...ALL_COLUMNS, "open"].join(", ")}.`, { exitCode: EXIT_VALIDATION });
|
|
32
|
+
}
|
|
33
|
+
cols.add(token);
|
|
34
|
+
}
|
|
35
|
+
const only = cols.size === 1 && !usedAlias ? [...cols][0] : undefined;
|
|
36
|
+
return { cols, serverCol: only };
|
|
37
|
+
}
|
|
38
|
+
/** Fetches community views from `/api/communities`, waiting for cold communities when `--wait-live` is set. */
|
|
39
|
+
export async function fetchCommunities(ctx, targetIds) {
|
|
40
|
+
const client = ctx.client();
|
|
41
|
+
if (ctx.global.waitLive) {
|
|
42
|
+
const waited = await client.waitUntilLive(targetIds);
|
|
43
|
+
return waited.communities;
|
|
44
|
+
}
|
|
45
|
+
return client.communities();
|
|
46
|
+
}
|
|
47
|
+
/** Emits a stderr warning in text mode for any community whose sync status is not `live`. */
|
|
48
|
+
export function warnUnhealthyCommunities(ctx, statuses) {
|
|
49
|
+
if (ctx.global.json) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
for (const item of statuses) {
|
|
53
|
+
if (item.status !== "live") {
|
|
54
|
+
errOut(`Warning: community ${displayText(item.id)} is ${item.status} (lag ${item.lagSeconds}s); pass --wait-live to wait.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Resolves a task reference across `--community` or all configured communities. */
|
|
59
|
+
export async function resolveTaskAcrossCommunities(ctx, ref) {
|
|
60
|
+
const configured = ctx.community();
|
|
61
|
+
const communities = await fetchCommunities(ctx, configured !== undefined ? [configured] : undefined);
|
|
62
|
+
const targetIds = configured !== undefined ? [configured] : communities.map((c) => c.id);
|
|
63
|
+
const client = ctx.client();
|
|
64
|
+
const responses = await Promise.all(targetIds.map(async (id) => {
|
|
65
|
+
const res = await client.request("GET", "/api/tasks", { query: { community: id } });
|
|
66
|
+
return { id, body: res.body };
|
|
67
|
+
}));
|
|
68
|
+
const allTasks = responses.flatMap((entry) => entry.body.tasks);
|
|
69
|
+
const task = resolveTaskRef(ref, allTasks);
|
|
70
|
+
const matchedResponse = responses.find((entry) => entry.id === task.community);
|
|
71
|
+
const syncStatus = matchedResponse !== undefined
|
|
72
|
+
? {
|
|
73
|
+
id: task.community,
|
|
74
|
+
status: matchedResponse.body.status.state,
|
|
75
|
+
lagSeconds: matchedResponse.body.status.lagSeconds,
|
|
76
|
+
}
|
|
77
|
+
: undefined;
|
|
78
|
+
return { task, communities, syncStatus };
|
|
79
|
+
}
|
|
80
|
+
function splitTrailingDigits(value) {
|
|
81
|
+
let end = value.length;
|
|
82
|
+
while (end > 0) {
|
|
83
|
+
const code = value.charCodeAt(end - 1);
|
|
84
|
+
if (code < 48 || code > 57) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
end -= 1;
|
|
88
|
+
}
|
|
89
|
+
if (end === value.length) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return { prefix: value.slice(0, end).toLowerCase(), num: Number(value.slice(end)) };
|
|
93
|
+
}
|
|
94
|
+
function compareNaturalKey(a, b) {
|
|
95
|
+
const partsA = splitTrailingDigits(a);
|
|
96
|
+
const partsB = splitTrailingDigits(b);
|
|
97
|
+
if (partsA !== null && partsB !== null) {
|
|
98
|
+
if (partsA.prefix !== partsB.prefix) {
|
|
99
|
+
return partsA.prefix.localeCompare(partsB.prefix);
|
|
100
|
+
}
|
|
101
|
+
if (partsA.num !== partsB.num) {
|
|
102
|
+
return partsA.num - partsB.num;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return a.localeCompare(b, undefined, { sensitivity: "base" });
|
|
106
|
+
}
|
|
107
|
+
function parseValidatedList(flag, rawItems, validSet, validLabel) {
|
|
108
|
+
const tokens = splitCsvList(rawItems).map((item) => item.toLowerCase());
|
|
109
|
+
if (tokens.length === 0) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const result = new Set();
|
|
113
|
+
for (const token of tokens) {
|
|
114
|
+
if (!validSet.has(token)) {
|
|
115
|
+
throw new CliError(`Invalid --${flag} value '${token}'. Valid values: ${validLabel}.`, {
|
|
116
|
+
exitCode: EXIT_VALIDATION,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
result.add(token);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
function syncSummariesFor(targetIds, communities) {
|
|
124
|
+
const byId = new Map(communities.map((c) => [c.id, c]));
|
|
125
|
+
const summaries = [];
|
|
126
|
+
for (const id of targetIds) {
|
|
127
|
+
const found = byId.get(id);
|
|
128
|
+
if (found !== undefined) {
|
|
129
|
+
summaries.push({ id: found.id, status: found.status, lagSeconds: found.lagSeconds });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return summaries;
|
|
133
|
+
}
|
|
134
|
+
function isTemplateAvailable(template, communities) {
|
|
135
|
+
if (template.channel === null) {
|
|
136
|
+
return communities.some((community) => community.channels.some((channel) => Object.values(channel.people).some((rule) => canStart(rule))));
|
|
137
|
+
}
|
|
138
|
+
return communities.some((community) => community.channels.some((channel) => channel.slug === template.channel));
|
|
139
|
+
}
|
|
140
|
+
function nextCommandForTask(task) {
|
|
141
|
+
const type = task.reason?.type;
|
|
142
|
+
switch (type) {
|
|
143
|
+
case "approve":
|
|
144
|
+
return `${PROGRAM} approve ${task.key}`;
|
|
145
|
+
case "answer":
|
|
146
|
+
return `${PROGRAM} answer ${task.key} --text "<reply>"`;
|
|
147
|
+
case "publish":
|
|
148
|
+
return `${PROGRAM} publish ${task.key}`;
|
|
149
|
+
case "decide":
|
|
150
|
+
return `${PROGRAM} decide ${task.key} <accepted|rejected|done> --reason "<reason>"`;
|
|
151
|
+
case "nudge":
|
|
152
|
+
return `${PROGRAM} nudge ${task.key}`;
|
|
153
|
+
case "retry":
|
|
154
|
+
return `${PROGRAM} retry ${task.key}`;
|
|
155
|
+
case "unblock":
|
|
156
|
+
return `${PROGRAM} unblock ${task.key} --text "<what you did>"`;
|
|
157
|
+
case undefined:
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function fetchResolvers(ctx, communityIds) {
|
|
162
|
+
const client = ctx.client();
|
|
163
|
+
const entries = await Promise.all(communityIds.map(async (id) => {
|
|
164
|
+
const [agentsRes, peopleRes] = await Promise.all([
|
|
165
|
+
client.request("GET", "/api/agents", { query: { community: id } }),
|
|
166
|
+
client.request("GET", "/api/people", { query: { community: id } }),
|
|
167
|
+
]);
|
|
168
|
+
return [id, createNameResolver(agentsRes.body.agents, peopleRes.body.people, id)];
|
|
169
|
+
}));
|
|
170
|
+
return new Map(entries);
|
|
171
|
+
}
|
|
172
|
+
/** `communities [--channels]` */
|
|
173
|
+
async function cmdCommunities(ctx) {
|
|
174
|
+
const communities = await fetchCommunities(ctx);
|
|
175
|
+
const summaries = communities.map((c) => ({
|
|
176
|
+
id: c.id,
|
|
177
|
+
status: c.status,
|
|
178
|
+
lagSeconds: c.lagSeconds,
|
|
179
|
+
}));
|
|
180
|
+
warnUnhealthyCommunities(ctx, summaries);
|
|
181
|
+
if (ctx.global.json) {
|
|
182
|
+
emitJson({ communities });
|
|
183
|
+
return EXIT_OK;
|
|
184
|
+
}
|
|
185
|
+
if (communities.length === 0) {
|
|
186
|
+
out("No communities configured.");
|
|
187
|
+
return EXIT_OK;
|
|
188
|
+
}
|
|
189
|
+
out(formatTable(["COMMUNITY", "STATUS", "LAG", "CHANNELS", "RELAY"], communities.map((c) => [c.id, c.status, `${c.lagSeconds}s`, c.channels.length, c.relay])));
|
|
190
|
+
if (ctx.flag("channels")) {
|
|
191
|
+
for (const community of communities) {
|
|
192
|
+
out("");
|
|
193
|
+
out(`Channels in ${displayText(community.id)}:`);
|
|
194
|
+
if (community.channels.length === 0) {
|
|
195
|
+
out(" (none)");
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
out(formatTable(["CHANNEL", "ID", "VISIBILITY", "ENTRY AGENTS"], community.channels.map((channel) => {
|
|
199
|
+
const entries = Object.entries(channel.people)
|
|
200
|
+
.filter(([, rule]) => canStart(rule))
|
|
201
|
+
.map(([agentId]) => agentId);
|
|
202
|
+
return [`#${channel.slug}`, channel.id, channel.visibility, entries.length > 0 ? entries.join(", ") : "-"];
|
|
203
|
+
})));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return EXIT_OK;
|
|
208
|
+
}
|
|
209
|
+
/** `overview` */
|
|
210
|
+
async function cmdOverview(ctx) {
|
|
211
|
+
const client = ctx.client();
|
|
212
|
+
const configured = ctx.community();
|
|
213
|
+
let targetIds;
|
|
214
|
+
if (configured !== undefined) {
|
|
215
|
+
if (ctx.global.waitLive) {
|
|
216
|
+
await client.waitUntilLive([configured]);
|
|
217
|
+
}
|
|
218
|
+
targetIds = [configured];
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
const communities = await fetchCommunities(ctx);
|
|
222
|
+
targetIds = communities.map((c) => c.id);
|
|
223
|
+
}
|
|
224
|
+
const [taskResponses, draftsRes] = await Promise.all([
|
|
225
|
+
Promise.all(targetIds.map(async (id) => {
|
|
226
|
+
const res = await client.request("GET", "/api/tasks", { query: { community: id } });
|
|
227
|
+
return { id, body: res.body };
|
|
228
|
+
})),
|
|
229
|
+
client.request("GET", "/api/drafts"),
|
|
230
|
+
]);
|
|
231
|
+
const draftCounts = new Map();
|
|
232
|
+
for (const draft of draftsRes.body.drafts) {
|
|
233
|
+
draftCounts.set(draft.community, (draftCounts.get(draft.community) ?? 0) + 1);
|
|
234
|
+
}
|
|
235
|
+
const totals = {
|
|
236
|
+
backlog: 0,
|
|
237
|
+
queued: 0,
|
|
238
|
+
working: 0,
|
|
239
|
+
needs: 0,
|
|
240
|
+
shipping: 0,
|
|
241
|
+
done: 0,
|
|
242
|
+
canceled: 0,
|
|
243
|
+
for_me: 0,
|
|
244
|
+
total: 0,
|
|
245
|
+
};
|
|
246
|
+
const rows = taskResponses.map(({ id, body }) => {
|
|
247
|
+
const counts = {
|
|
248
|
+
backlog: draftCounts.get(id) ?? 0,
|
|
249
|
+
queued: 0,
|
|
250
|
+
working: 0,
|
|
251
|
+
needs: 0,
|
|
252
|
+
shipping: 0,
|
|
253
|
+
done: 0,
|
|
254
|
+
canceled: 0,
|
|
255
|
+
for_me: 0,
|
|
256
|
+
total: 0,
|
|
257
|
+
};
|
|
258
|
+
for (const task of body.tasks) {
|
|
259
|
+
counts[task.col] += 1;
|
|
260
|
+
if (task.forMe) {
|
|
261
|
+
counts.for_me += 1;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
counts.total =
|
|
265
|
+
counts.backlog +
|
|
266
|
+
counts.queued +
|
|
267
|
+
counts.working +
|
|
268
|
+
counts.needs +
|
|
269
|
+
counts.shipping +
|
|
270
|
+
counts.done +
|
|
271
|
+
counts.canceled;
|
|
272
|
+
totals.backlog += counts.backlog;
|
|
273
|
+
totals.queued += counts.queued;
|
|
274
|
+
totals.working += counts.working;
|
|
275
|
+
totals.needs += counts.needs;
|
|
276
|
+
totals.shipping += counts.shipping;
|
|
277
|
+
totals.done += counts.done;
|
|
278
|
+
totals.canceled += counts.canceled;
|
|
279
|
+
totals.for_me += counts.for_me;
|
|
280
|
+
totals.total += counts.total;
|
|
281
|
+
return {
|
|
282
|
+
id,
|
|
283
|
+
status: body.status.state,
|
|
284
|
+
lagSeconds: body.status.lagSeconds,
|
|
285
|
+
...counts,
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
warnUnhealthyCommunities(ctx, rows);
|
|
289
|
+
if (ctx.global.json) {
|
|
290
|
+
emitJson({ communities: rows, totals });
|
|
291
|
+
return EXIT_OK;
|
|
292
|
+
}
|
|
293
|
+
if (rows.length === 0) {
|
|
294
|
+
out("No communities configured.");
|
|
295
|
+
return EXIT_OK;
|
|
296
|
+
}
|
|
297
|
+
const tableRows = rows.map((row) => [
|
|
298
|
+
row.id,
|
|
299
|
+
row.status,
|
|
300
|
+
row.backlog,
|
|
301
|
+
row.queued,
|
|
302
|
+
row.working,
|
|
303
|
+
row.needs,
|
|
304
|
+
row.for_me,
|
|
305
|
+
row.shipping,
|
|
306
|
+
row.done,
|
|
307
|
+
row.total,
|
|
308
|
+
]);
|
|
309
|
+
if (rows.length > 1) {
|
|
310
|
+
tableRows.push([
|
|
311
|
+
"TOTAL",
|
|
312
|
+
"-",
|
|
313
|
+
totals.backlog,
|
|
314
|
+
totals.queued,
|
|
315
|
+
totals.working,
|
|
316
|
+
totals.needs,
|
|
317
|
+
totals.for_me,
|
|
318
|
+
totals.shipping,
|
|
319
|
+
totals.done,
|
|
320
|
+
totals.total,
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
out(formatTable(["COMMUNITY", "STATUS", "BACKLOG", "QUEUED", "WORKING", "NEEDS", "FOR ME", "SHIPPING", "DONE", "TOTAL"], tableRows));
|
|
324
|
+
return EXIT_OK;
|
|
325
|
+
}
|
|
326
|
+
/** `templates [TEMPLATE_ID] [--all] [--check]` */
|
|
327
|
+
async function cmdTemplates(ctx) {
|
|
328
|
+
const singleArg = ctx.positionals[0];
|
|
329
|
+
let singleTemplate;
|
|
330
|
+
if (singleArg !== undefined) {
|
|
331
|
+
const key = singleArg.trim().toLowerCase();
|
|
332
|
+
if (!Object.hasOwn(TEMPLATES, key)) {
|
|
333
|
+
throw new CliError(`Unknown template '${singleArg}'. Valid templates: ${Object.keys(TEMPLATES).join(", ")}.`, { exitCode: EXIT_VALIDATION });
|
|
334
|
+
}
|
|
335
|
+
singleTemplate = TEMPLATES[key];
|
|
336
|
+
}
|
|
337
|
+
const explicitCommunity = ctx.global.community;
|
|
338
|
+
const shouldCheck = ctx.flag("check") || explicitCommunity !== undefined;
|
|
339
|
+
let checkedCommunities;
|
|
340
|
+
if (shouldCheck) {
|
|
341
|
+
const allCommunities = await fetchCommunities(ctx, explicitCommunity !== undefined ? [explicitCommunity] : undefined);
|
|
342
|
+
if (explicitCommunity !== undefined) {
|
|
343
|
+
const matched = allCommunities.filter((c) => c.id === explicitCommunity);
|
|
344
|
+
if (matched.length === 0) {
|
|
345
|
+
throw new CliError(`Community not found: ${explicitCommunity}`, {
|
|
346
|
+
exitCode: EXIT_RUNTIME,
|
|
347
|
+
payload: { ok: false, error: "not_found", status: 404, message: `Community not found: ${explicitCommunity}` },
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
checkedCommunities = matched;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
checkedCommunities = allCommunities;
|
|
354
|
+
}
|
|
355
|
+
warnUnhealthyCommunities(ctx, checkedCommunities.map((c) => ({ id: c.id, status: c.status, lagSeconds: c.lagSeconds })));
|
|
356
|
+
}
|
|
357
|
+
const syncPayload = checkedCommunities !== undefined
|
|
358
|
+
? {
|
|
359
|
+
communities: checkedCommunities.map((c) => ({
|
|
360
|
+
id: c.id,
|
|
361
|
+
status: c.status,
|
|
362
|
+
lagSeconds: c.lagSeconds,
|
|
363
|
+
})),
|
|
364
|
+
}
|
|
365
|
+
: {};
|
|
366
|
+
if (singleTemplate !== undefined) {
|
|
367
|
+
const available = checkedCommunities !== undefined ? isTemplateAvailable(singleTemplate, checkedCommunities) : undefined;
|
|
368
|
+
const item = available === undefined ? { ...singleTemplate } : { ...singleTemplate, available };
|
|
369
|
+
if (ctx.global.json) {
|
|
370
|
+
emitJson({ template: item, ...syncPayload });
|
|
371
|
+
return EXIT_OK;
|
|
372
|
+
}
|
|
373
|
+
out(`Template: ${displayText(singleTemplate.name)} (${singleTemplate.id})`);
|
|
374
|
+
out(`Channel: ${singleTemplate.channel === null ? "(any)" : `#${singleTemplate.channel}`}`);
|
|
375
|
+
out(`Entry: ${singleTemplate.entry ?? "(any startable agent)"}`);
|
|
376
|
+
if (singleTemplate.budget !== undefined) {
|
|
377
|
+
out(`Budget: ${singleTemplate.budget} messages`);
|
|
378
|
+
}
|
|
379
|
+
if (available !== undefined) {
|
|
380
|
+
out(`Available: ${available ? "yes" : "no"}`);
|
|
381
|
+
}
|
|
382
|
+
out(`Blurb: ${displayText(singleTemplate.blurb)}`);
|
|
383
|
+
out(`Approver: ${displayText(singleTemplate.approver)}`);
|
|
384
|
+
out(`Outcome: ${displayText(singleTemplate.outcome)}`);
|
|
385
|
+
if (singleTemplate.stall !== undefined) {
|
|
386
|
+
out(`Stall: after ${singleTemplate.stall.minutes}m in ${singleTemplate.stall.stages.join(", ")}, ` +
|
|
387
|
+
`nudge ${singleTemplate.stall.nudgeName} (${singleTemplate.stall.nudge})`);
|
|
388
|
+
}
|
|
389
|
+
if (singleTemplate.quiet !== undefined) {
|
|
390
|
+
out(`Quiet: transitions ${singleTemplate.quiet.from} -> ${singleTemplate.quiet.to} after ${singleTemplate.quiet.hours}h`);
|
|
391
|
+
}
|
|
392
|
+
out("");
|
|
393
|
+
out("Stages:");
|
|
394
|
+
out(formatTable(["STAGE", "LABEL", "COLUMN"], singleTemplate.stages.map(([stageId, label, col]) => [stageId, label, col])));
|
|
395
|
+
return EXIT_OK;
|
|
396
|
+
}
|
|
397
|
+
const showAll = ctx.flag("all");
|
|
398
|
+
const ids = showAll ? Object.keys(TEMPLATES) : PUBLIC_TEMPLATES;
|
|
399
|
+
const items = ids.map((id) => {
|
|
400
|
+
const tpl = TEMPLATES[id];
|
|
401
|
+
const available = checkedCommunities !== undefined ? isTemplateAvailable(tpl, checkedCommunities) : undefined;
|
|
402
|
+
return available === undefined ? { ...tpl } : { ...tpl, available };
|
|
403
|
+
});
|
|
404
|
+
if (ctx.global.json) {
|
|
405
|
+
emitJson({ templates: items, task_kinds: TASK_KINDS, ...syncPayload });
|
|
406
|
+
return EXIT_OK;
|
|
407
|
+
}
|
|
408
|
+
const headers = checkedCommunities !== undefined
|
|
409
|
+
? ["TEMPLATE", "NAME", "CHANNEL", "ENTRY", "APPROVER", "AVAILABLE"]
|
|
410
|
+
: ["TEMPLATE", "NAME", "CHANNEL", "ENTRY", "APPROVER"];
|
|
411
|
+
out(formatTable(headers, items.map((item) => [
|
|
412
|
+
item.id,
|
|
413
|
+
item.name,
|
|
414
|
+
item.channel === null ? "(any)" : `#${item.channel}`,
|
|
415
|
+
item.entry ?? "(any)",
|
|
416
|
+
item.approver,
|
|
417
|
+
...("available" in item ? [item.available ? "yes" : "no"] : []),
|
|
418
|
+
])));
|
|
419
|
+
if (showAll) {
|
|
420
|
+
out("");
|
|
421
|
+
for (const item of items) {
|
|
422
|
+
out(`${item.id}: ${displayText(item.blurb)}`);
|
|
423
|
+
out(` Outcome: ${displayText(item.outcome)}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return EXIT_OK;
|
|
427
|
+
}
|
|
428
|
+
/** `list [options]` */
|
|
429
|
+
async function cmdList(ctx) {
|
|
430
|
+
const { cols, serverCol } = parseColumnFilter(ctx.optList("col"));
|
|
431
|
+
const templateSet = parseValidatedList("template", ctx.optList("template"), new Set(Object.keys(TEMPLATES)), Object.keys(TEMPLATES).join(", "));
|
|
432
|
+
const reasonSet = parseValidatedList("reason", ctx.optList("reason"), new Set(Object.keys(REASONS)), Object.keys(REASONS).join(", "));
|
|
433
|
+
const prioritySet = parseValidatedList("priority", ctx.optList("priority"), new Set(PRIORITIES), PRIORITIES.join(", "));
|
|
434
|
+
const labels = splitCsvList(ctx.optList("label")).map((label) => label.toLowerCase());
|
|
435
|
+
const rawChannel = ctx.opt("channel");
|
|
436
|
+
if (rawChannel?.trim() === "") {
|
|
437
|
+
throw new CliError("--channel cannot be empty.", { exitCode: EXIT_VALIDATION });
|
|
438
|
+
}
|
|
439
|
+
const channelNeedle = rawChannel?.trim();
|
|
440
|
+
const rawLimit = ctx.opt("limit");
|
|
441
|
+
const limit = rawLimit !== undefined ? parsePositiveInt("limit", rawLimit) : undefined;
|
|
442
|
+
const sortField = (ctx.opt("sort") ?? "last");
|
|
443
|
+
const rawQ = ctx.opt("q");
|
|
444
|
+
const qText = rawQ?.trim() ?? "";
|
|
445
|
+
const mine = ctx.flag("mine");
|
|
446
|
+
const forMeOnly = ctx.flag("for-me");
|
|
447
|
+
const compact = ctx.flag("compact");
|
|
448
|
+
const client = ctx.client();
|
|
449
|
+
const configured = ctx.community();
|
|
450
|
+
let communitiesList = [];
|
|
451
|
+
let targetIds;
|
|
452
|
+
if (configured !== undefined) {
|
|
453
|
+
if (ctx.global.waitLive || channelNeedle !== undefined) {
|
|
454
|
+
communitiesList = await fetchCommunities(ctx, [configured]);
|
|
455
|
+
}
|
|
456
|
+
targetIds = [configured];
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
communitiesList = await fetchCommunities(ctx);
|
|
460
|
+
targetIds = communitiesList.map((c) => c.id);
|
|
461
|
+
}
|
|
462
|
+
const baseQuery = {};
|
|
463
|
+
if (serverCol !== undefined) {
|
|
464
|
+
baseQuery["col"] = serverCol;
|
|
465
|
+
}
|
|
466
|
+
if (qText !== "") {
|
|
467
|
+
baseQuery["q"] = qText;
|
|
468
|
+
}
|
|
469
|
+
if (mine) {
|
|
470
|
+
baseQuery["mine"] = "1";
|
|
471
|
+
}
|
|
472
|
+
const responses = await Promise.all(targetIds.map(async (id) => {
|
|
473
|
+
const res = await client.request("GET", "/api/tasks", {
|
|
474
|
+
query: { community: id, ...baseQuery },
|
|
475
|
+
});
|
|
476
|
+
return { id, body: res.body };
|
|
477
|
+
}));
|
|
478
|
+
const syncSummaries = responses.map(({ id, body }) => ({
|
|
479
|
+
id,
|
|
480
|
+
status: body.status.state,
|
|
481
|
+
lagSeconds: body.status.lagSeconds,
|
|
482
|
+
}));
|
|
483
|
+
warnUnhealthyCommunities(ctx, syncSummaries);
|
|
484
|
+
const communityMap = new Map(communitiesList.map((c) => [c.id, c]));
|
|
485
|
+
const channelIdLower = channelNeedle?.toLowerCase();
|
|
486
|
+
const channelSlugLower = channelNeedle?.replace(/^#/, "").toLowerCase();
|
|
487
|
+
const qLower = qText.toLowerCase();
|
|
488
|
+
const filtered = responses
|
|
489
|
+
.flatMap((entry) => entry.body.tasks)
|
|
490
|
+
.filter((task) => {
|
|
491
|
+
if (cols !== null && !cols.has(task.col)) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
if (channelNeedle !== undefined) {
|
|
495
|
+
const comm = communityMap.get(task.community);
|
|
496
|
+
const ch = comm?.channels.find((item) => item.id === task.channel);
|
|
497
|
+
const idMatch = task.channel.toLowerCase() === channelIdLower;
|
|
498
|
+
const slugMatch = ch !== undefined && ch.slug.toLowerCase() === channelSlugLower;
|
|
499
|
+
if (!idMatch && !slugMatch) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (templateSet !== null && !templateSet.has(task.template)) {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
if (reasonSet !== null && (task.reason === undefined || !reasonSet.has(task.reason.type))) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
if (prioritySet !== null && !prioritySet.has(task.priority)) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
if (labels.length > 0) {
|
|
513
|
+
const taskLabels = new Set(task.labels.map((item) => item.toLowerCase()));
|
|
514
|
+
if (!labels.every((want) => taskLabels.has(want))) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (qLower !== "") {
|
|
519
|
+
const hit = task.title.toLowerCase().includes(qLower) ||
|
|
520
|
+
task.key.toLowerCase().includes(qLower) ||
|
|
521
|
+
task.labels.some((item) => item.toLowerCase().includes(qLower)) ||
|
|
522
|
+
(task.stageLabel?.toLowerCase().includes(qLower) ?? false);
|
|
523
|
+
if (!hit) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (forMeOnly && !task.forMe) {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
return true;
|
|
531
|
+
});
|
|
532
|
+
filtered.sort((a, b) => {
|
|
533
|
+
switch (sortField) {
|
|
534
|
+
case "last":
|
|
535
|
+
return b.last - a.last || compareNaturalKey(a.key, b.key);
|
|
536
|
+
case "since":
|
|
537
|
+
return b.since - a.since || compareNaturalKey(a.key, b.key);
|
|
538
|
+
case "priority":
|
|
539
|
+
return PRIORITY_RANK[b.priority] - PRIORITY_RANK[a.priority] || b.last - a.last || compareNaturalKey(a.key, b.key);
|
|
540
|
+
case "key":
|
|
541
|
+
return compareNaturalKey(a.key, b.key);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
const total = filtered.length;
|
|
545
|
+
const tasks = limit !== undefined ? filtered.slice(0, limit) : filtered;
|
|
546
|
+
if (ctx.global.json) {
|
|
547
|
+
const jsonTasks = compact
|
|
548
|
+
? tasks.map((task) => ({
|
|
549
|
+
key: task.key,
|
|
550
|
+
community: task.community,
|
|
551
|
+
col: task.col,
|
|
552
|
+
stage: task.stage,
|
|
553
|
+
reason: task.reason ?? null,
|
|
554
|
+
forMe: task.forMe,
|
|
555
|
+
priority: task.priority,
|
|
556
|
+
title: task.title,
|
|
557
|
+
last: task.last,
|
|
558
|
+
}))
|
|
559
|
+
: tasks;
|
|
560
|
+
emitJson({ tasks: jsonTasks, communities: syncSummaries, total });
|
|
561
|
+
return EXIT_OK;
|
|
562
|
+
}
|
|
563
|
+
if (tasks.length === 0) {
|
|
564
|
+
out("No tasks match.");
|
|
565
|
+
return EXIT_OK;
|
|
566
|
+
}
|
|
567
|
+
const multi = targetIds.length > 1;
|
|
568
|
+
const formatReason = (task) => {
|
|
569
|
+
if (task.reason === undefined) {
|
|
570
|
+
return "-";
|
|
571
|
+
}
|
|
572
|
+
return task.forMe ? `${task.reason.type} (you)` : task.reason.type;
|
|
573
|
+
};
|
|
574
|
+
if (compact) {
|
|
575
|
+
const headers = multi ? ["KEY", "COMMUNITY", "COL", "REASON", "TITLE"] : ["KEY", "COL", "REASON", "TITLE"];
|
|
576
|
+
out(formatTable(headers, tasks.map((task) => [
|
|
577
|
+
task.key,
|
|
578
|
+
...(multi ? [task.community] : []),
|
|
579
|
+
task.col,
|
|
580
|
+
formatReason(task),
|
|
581
|
+
truncate(oneLine(task.title), 60),
|
|
582
|
+
])));
|
|
583
|
+
return EXIT_OK;
|
|
584
|
+
}
|
|
585
|
+
const headers = multi
|
|
586
|
+
? ["KEY", "COMMUNITY", "COL", "STAGE", "REASON", "PRIORITY", "TITLE", "UPDATED"]
|
|
587
|
+
: ["KEY", "COL", "STAGE", "REASON", "PRIORITY", "TITLE", "UPDATED"];
|
|
588
|
+
out(formatTable(headers, tasks.map((task) => [
|
|
589
|
+
task.key,
|
|
590
|
+
...(multi ? [task.community] : []),
|
|
591
|
+
task.col,
|
|
592
|
+
task.stageLabel ?? task.stage ?? "-",
|
|
593
|
+
formatReason(task),
|
|
594
|
+
task.priority,
|
|
595
|
+
truncate(oneLine(task.title), 60),
|
|
596
|
+
formatRelativeAge(task.last),
|
|
597
|
+
])));
|
|
598
|
+
return EXIT_OK;
|
|
599
|
+
}
|
|
600
|
+
/** `inbox [--for-me] [--compact] [--limit N]` */
|
|
601
|
+
async function cmdInbox(ctx) {
|
|
602
|
+
const forMeOnly = ctx.flag("for-me");
|
|
603
|
+
const compact = ctx.flag("compact");
|
|
604
|
+
const rawLimit = ctx.opt("limit");
|
|
605
|
+
const limit = rawLimit !== undefined ? parsePositiveInt("limit", rawLimit) : undefined;
|
|
606
|
+
const client = ctx.client();
|
|
607
|
+
const configured = ctx.community();
|
|
608
|
+
let targetIds;
|
|
609
|
+
if (configured !== undefined) {
|
|
610
|
+
if (ctx.global.waitLive) {
|
|
611
|
+
await client.waitUntilLive([configured]);
|
|
612
|
+
}
|
|
613
|
+
targetIds = [configured];
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
const communities = await fetchCommunities(ctx);
|
|
617
|
+
targetIds = communities.map((c) => c.id);
|
|
618
|
+
}
|
|
619
|
+
const responses = await Promise.all(targetIds.map(async (id) => {
|
|
620
|
+
const res = await client.request("GET", "/api/tasks", {
|
|
621
|
+
query: { community: id, col: "needs" },
|
|
622
|
+
});
|
|
623
|
+
return { id, body: res.body };
|
|
624
|
+
}));
|
|
625
|
+
const syncSummaries = responses.map(({ id, body }) => ({
|
|
626
|
+
id,
|
|
627
|
+
status: body.status.state,
|
|
628
|
+
lagSeconds: body.status.lagSeconds,
|
|
629
|
+
}));
|
|
630
|
+
warnUnhealthyCommunities(ctx, syncSummaries);
|
|
631
|
+
const needsTasks = responses
|
|
632
|
+
.flatMap((entry) => entry.body.tasks)
|
|
633
|
+
.filter((task) => task.col === "needs" && (!forMeOnly || task.forMe));
|
|
634
|
+
const communitiesWithItems = [...new Set(needsTasks.map((task) => task.community))];
|
|
635
|
+
const resolvers = await fetchResolvers(ctx, communitiesWithItems);
|
|
636
|
+
const waitingAt = (task) => task.reason?.at ?? task.since;
|
|
637
|
+
const sortOldestFirst = (a, b) => waitingAt(a) - waitingAt(b) || compareNaturalKey(a.key, b.key);
|
|
638
|
+
const forMeAll = needsTasks.filter((task) => task.forMe).sort(sortOldestFirst);
|
|
639
|
+
const waitingAll = forMeOnly ? [] : needsTasks.filter((task) => !task.forMe).sort(sortOldestFirst);
|
|
640
|
+
const forMeSlice = limit !== undefined ? forMeAll.slice(0, limit) : forMeAll;
|
|
641
|
+
const remaining = limit !== undefined ? Math.max(0, limit - forMeSlice.length) : undefined;
|
|
642
|
+
const waitingSlice = remaining !== undefined ? waitingAll.slice(0, remaining) : waitingAll;
|
|
643
|
+
const enrich = (task) => {
|
|
644
|
+
const resolver = resolvers.get(task.community);
|
|
645
|
+
const byName = task.reason !== undefined ? (resolver?.name(task.reason.by) ?? task.reason.by) : null;
|
|
646
|
+
return {
|
|
647
|
+
...task,
|
|
648
|
+
by_name: byName,
|
|
649
|
+
waiting_since: waitingAt(task),
|
|
650
|
+
next_command: nextCommandForTask(task),
|
|
651
|
+
};
|
|
652
|
+
};
|
|
653
|
+
const forMeItems = forMeSlice.map(enrich);
|
|
654
|
+
const waitingItems = waitingSlice.map(enrich);
|
|
655
|
+
const total = forMeItems.length + waitingItems.length;
|
|
656
|
+
if (ctx.global.json) {
|
|
657
|
+
emitJson({
|
|
658
|
+
for_me: forMeItems,
|
|
659
|
+
waiting_on_others: waitingItems,
|
|
660
|
+
total,
|
|
661
|
+
communities: syncSummaries,
|
|
662
|
+
});
|
|
663
|
+
return EXIT_OK;
|
|
664
|
+
}
|
|
665
|
+
if (total === 0) {
|
|
666
|
+
out("Inbox is clear.");
|
|
667
|
+
return EXIT_OK;
|
|
668
|
+
}
|
|
669
|
+
const headers = compact
|
|
670
|
+
? ["KEY", "COMMUNITY", "WAITING", "REASON", "BY", "PRIORITY", "TITLE"]
|
|
671
|
+
: ["KEY", "COMMUNITY", "WAITING", "REASON", "BY", "PRIORITY", "TITLE", "NEXT"];
|
|
672
|
+
const toRows = (items) => items.map((item) => [
|
|
673
|
+
item.key,
|
|
674
|
+
item.community,
|
|
675
|
+
formatRelativeAge(item.waiting_since),
|
|
676
|
+
item.reason?.type ?? "-",
|
|
677
|
+
item.by_name ?? "-",
|
|
678
|
+
item.priority,
|
|
679
|
+
truncate(oneLine(item.title), 50),
|
|
680
|
+
...(compact ? [] : [item.next_command ?? "-"]),
|
|
681
|
+
]);
|
|
682
|
+
out(`For you (${forMeItems.length})`);
|
|
683
|
+
if (forMeItems.length > 0) {
|
|
684
|
+
out(formatTable(headers, toRows(forMeItems)));
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
out(" (none)");
|
|
688
|
+
}
|
|
689
|
+
if (!forMeOnly) {
|
|
690
|
+
out("");
|
|
691
|
+
out(`Waiting on others (${waitingItems.length})`);
|
|
692
|
+
if (waitingItems.length > 0) {
|
|
693
|
+
out(formatTable(headers, toRows(waitingItems)));
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
out(" (none)");
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return EXIT_OK;
|
|
700
|
+
}
|
|
701
|
+
/** `show <TASK_REF> [--tail N] [--full] [--raw]` */
|
|
702
|
+
async function cmdShow(ctx) {
|
|
703
|
+
const ref = ctx.positionals[0] ?? "";
|
|
704
|
+
const rawTail = ctx.opt("tail");
|
|
705
|
+
const tail = rawTail !== undefined ? parsePositiveInt("tail", rawTail) : undefined;
|
|
706
|
+
const full = ctx.flag("full");
|
|
707
|
+
const rawMode = ctx.flag("raw");
|
|
708
|
+
const { task: matched, communities, syncStatus } = await resolveTaskAcrossCommunities(ctx, ref);
|
|
709
|
+
if (syncStatus !== undefined) {
|
|
710
|
+
warnUnhealthyCommunities(ctx, [syncStatus]);
|
|
711
|
+
}
|
|
712
|
+
const client = ctx.client();
|
|
713
|
+
const [detailRes, agentsRes, peopleRes] = await Promise.all([
|
|
714
|
+
client.request("GET", `/api/tasks/${encodeURIComponent(matched.community)}/${encodeURIComponent(matched.root)}`),
|
|
715
|
+
client.request("GET", "/api/agents", { query: { community: matched.community } }),
|
|
716
|
+
client.request("GET", "/api/people", { query: { community: matched.community } }),
|
|
717
|
+
]);
|
|
718
|
+
const { task, events } = detailRes.body;
|
|
719
|
+
const communityView = communities.find((c) => c.id === task.community);
|
|
720
|
+
const channel = communityView?.channels.find((ch) => ch.id === task.channel) ?? null;
|
|
721
|
+
const resolver = createNameResolver(agentsRes.body.agents, peopleRes.body.people, task.community);
|
|
722
|
+
const agentPubkeys = new Set(agentsRes.body.agents
|
|
723
|
+
.map((agent) => agent.pubkey)
|
|
724
|
+
.filter((pubkey) => pubkey !== null)
|
|
725
|
+
.map((pubkey) => pubkey.toLowerCase()));
|
|
726
|
+
const personPubkeys = new Set(peopleRes.body.people.map((person) => person.pubkey.toLowerCase()));
|
|
727
|
+
const roleOf = (pubkey) => {
|
|
728
|
+
const lower = pubkey.toLowerCase();
|
|
729
|
+
if (agentPubkeys.has(lower)) {
|
|
730
|
+
return "agent";
|
|
731
|
+
}
|
|
732
|
+
if (personPubkeys.has(lower)) {
|
|
733
|
+
return "person";
|
|
734
|
+
}
|
|
735
|
+
return "unknown";
|
|
736
|
+
};
|
|
737
|
+
const sortedEvents = [...events].sort((a, b) => a.created_at - b.created_at);
|
|
738
|
+
const totalEvents = sortedEvents.length;
|
|
739
|
+
const displayedEvents = tail !== undefined ? sortedEvents.slice(-tail) : sortedEvents;
|
|
740
|
+
const resolvedNames = {};
|
|
741
|
+
const recordName = (idOrPubkey) => {
|
|
742
|
+
if (idOrPubkey !== null && idOrPubkey !== undefined && idOrPubkey !== "") {
|
|
743
|
+
resolvedNames[idOrPubkey] = resolver.name(idOrPubkey);
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
recordName(task.requester);
|
|
747
|
+
for (const activeActor of task.active) {
|
|
748
|
+
recordName(activeActor);
|
|
749
|
+
}
|
|
750
|
+
const openReason = task.reason ?? task.state.reason ?? undefined;
|
|
751
|
+
if (openReason !== undefined) {
|
|
752
|
+
recordName(openReason.by);
|
|
753
|
+
recordName(openReason.blocked);
|
|
754
|
+
for (const target of openReason.forWho) {
|
|
755
|
+
recordName(target);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
for (const ev of sortedEvents) {
|
|
759
|
+
recordName(ev.pubkey);
|
|
760
|
+
}
|
|
761
|
+
if (ctx.global.json) {
|
|
762
|
+
const jsonEvents = rawMode
|
|
763
|
+
? displayedEvents.map((ev) => ({
|
|
764
|
+
...ev,
|
|
765
|
+
author: resolver.name(ev.pubkey),
|
|
766
|
+
role: roleOf(ev.pubkey),
|
|
767
|
+
}))
|
|
768
|
+
: displayedEvents.map((ev) => ({
|
|
769
|
+
id: ev.id,
|
|
770
|
+
pubkey: ev.pubkey,
|
|
771
|
+
author: resolver.name(ev.pubkey),
|
|
772
|
+
role: roleOf(ev.pubkey),
|
|
773
|
+
created_at: ev.created_at,
|
|
774
|
+
content: ev.content,
|
|
775
|
+
}));
|
|
776
|
+
emitJson({
|
|
777
|
+
task,
|
|
778
|
+
channel,
|
|
779
|
+
events: jsonEvents,
|
|
780
|
+
...(tail !== undefined ? { total_events: totalEvents } : {}),
|
|
781
|
+
resolved_names: resolvedNames,
|
|
782
|
+
...(syncStatus !== undefined ? { sync_status: syncStatus } : {}),
|
|
783
|
+
});
|
|
784
|
+
return EXIT_OK;
|
|
785
|
+
}
|
|
786
|
+
out(`Key: ${displayText(task.key)}`);
|
|
787
|
+
out(`Title: ${displayText(task.title)}`);
|
|
788
|
+
out(`Community: ${displayText(task.community)}`);
|
|
789
|
+
out(`Channel: ${channel !== null ? `#${displayText(channel.slug)} (${displayText(channel.id)})` : displayText(task.channel)}`);
|
|
790
|
+
out(`Template: ${displayText(task.template)}`);
|
|
791
|
+
const stageText = task.stage !== null
|
|
792
|
+
? ` / Stage: ${displayText(task.stageLabel ?? task.stage)} (${displayText(task.stage)})`
|
|
793
|
+
: "";
|
|
794
|
+
out(`Column: ${displayText(task.col)}${stageText}`);
|
|
795
|
+
out(`Priority: ${displayText(task.priority)}`);
|
|
796
|
+
out(`Labels: ${task.labels.length > 0 ? task.labels.map((label) => displayText(label)).join(", ") : "-"}`);
|
|
797
|
+
out(`Requester: ${task.requester !== null ? displayText(resolver.name(task.requester)) : "-"}`);
|
|
798
|
+
const linkParts = [];
|
|
799
|
+
if (task.links.mr !== undefined) {
|
|
800
|
+
linkParts.push(`mr=${displayText(task.links.mr)}`);
|
|
801
|
+
}
|
|
802
|
+
if (task.links.pipeline !== undefined) {
|
|
803
|
+
linkParts.push(`pipeline=${displayText(task.links.pipeline)}`);
|
|
804
|
+
}
|
|
805
|
+
if (task.links.path !== undefined) {
|
|
806
|
+
linkParts.push(`path=${displayText(task.links.path)}`);
|
|
807
|
+
}
|
|
808
|
+
if (linkParts.length > 0) {
|
|
809
|
+
out(`Links: ${linkParts.join(", ")}`);
|
|
810
|
+
}
|
|
811
|
+
out(`Active: ${task.active.length > 0 ? task.active.map((actor) => displayText(resolver.name(actor))).join(", ") : "-"}`);
|
|
812
|
+
if (openReason !== undefined) {
|
|
813
|
+
const details = [`by ${displayText(resolver.name(openReason.by))}`];
|
|
814
|
+
if (openReason.cardId !== undefined) {
|
|
815
|
+
details.push(`cardId=${displayText(openReason.cardId)}`);
|
|
816
|
+
}
|
|
817
|
+
if (openReason.level !== undefined) {
|
|
818
|
+
details.push(`level=${openReason.level}`);
|
|
819
|
+
}
|
|
820
|
+
if (openReason.need !== undefined) {
|
|
821
|
+
details.push(`need=${openReason.need}`);
|
|
822
|
+
}
|
|
823
|
+
if (openReason.blocked !== undefined) {
|
|
824
|
+
details.push(`blocked=${displayText(resolver.name(openReason.blocked))}`);
|
|
825
|
+
}
|
|
826
|
+
if (openReason.until !== undefined) {
|
|
827
|
+
details.push(`until=${formatTimestamp(openReason.until)}`);
|
|
828
|
+
}
|
|
829
|
+
out(`Reason: ${openReason.type} - ${displayText(openReason.label)} (${details.join(", ")})`);
|
|
830
|
+
}
|
|
831
|
+
out("");
|
|
832
|
+
const countNote = tail !== undefined && totalEvents > displayedEvents.length
|
|
833
|
+
? `${displayedEvents.length} of ${totalEvents}`
|
|
834
|
+
: String(displayedEvents.length);
|
|
835
|
+
out(`Thread (${countNote} events):`);
|
|
836
|
+
if (displayedEvents.length === 0) {
|
|
837
|
+
out(" (no events)");
|
|
838
|
+
return EXIT_OK;
|
|
839
|
+
}
|
|
840
|
+
for (const ev of displayedEvents) {
|
|
841
|
+
const author = displayText(resolver.name(ev.pubkey));
|
|
842
|
+
const role = roleOf(ev.pubkey);
|
|
843
|
+
const sanitized = stripControls(ev.content);
|
|
844
|
+
const body = full ? sanitized : truncate(sanitized, EVENT_BODY_PREVIEW_MAX);
|
|
845
|
+
out(`[${formatTimestamp(ev.created_at)}] ${author} (${role}): ${body}`);
|
|
846
|
+
if (rawMode) {
|
|
847
|
+
out(` id=${ev.id} kind=${ev.kind} tags=${JSON.stringify(ev.tags)}`);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return EXIT_OK;
|
|
851
|
+
}
|
|
852
|
+
/** `agents [--status S] [--channel C] [--kind K] [--q TEXT]` */
|
|
853
|
+
async function cmdAgents(ctx) {
|
|
854
|
+
const statusSet = parseValidatedList("status", ctx.optList("status"), AGENT_STATUS_SET, AGENT_STATUS_KINDS.join(", "));
|
|
855
|
+
const rawChannel = ctx.opt("channel");
|
|
856
|
+
if (rawChannel?.trim() === "") {
|
|
857
|
+
throw new CliError("--channel cannot be empty.", { exitCode: EXIT_VALIDATION });
|
|
858
|
+
}
|
|
859
|
+
const channelSlug = rawChannel?.trim().replace(/^#/, "").toLowerCase();
|
|
860
|
+
const kindFilter = ctx.opt("kind")?.trim().toLowerCase();
|
|
861
|
+
const qLower = ctx.opt("q")?.trim().toLowerCase() ?? "";
|
|
862
|
+
const configured = ctx.community();
|
|
863
|
+
const allCommunities = await fetchCommunities(ctx, configured !== undefined ? [configured] : undefined);
|
|
864
|
+
const targetIds = configured !== undefined ? [configured] : allCommunities.map((c) => c.id);
|
|
865
|
+
const syncSummaries = syncSummariesFor(targetIds, allCommunities);
|
|
866
|
+
const client = ctx.client();
|
|
867
|
+
const responses = await Promise.all(targetIds.map(async (id) => {
|
|
868
|
+
const res = await client.request("GET", "/api/agents", { query: { community: id } });
|
|
869
|
+
return { id, agents: res.body.agents };
|
|
870
|
+
}));
|
|
871
|
+
warnUnhealthyCommunities(ctx, syncSummaries);
|
|
872
|
+
const enriched = responses
|
|
873
|
+
.flatMap(({ id, agents }) => agents.map((agent) => {
|
|
874
|
+
const computed = agentStatus(agent);
|
|
875
|
+
return {
|
|
876
|
+
...agent,
|
|
877
|
+
community: id,
|
|
878
|
+
status: computed.kind,
|
|
879
|
+
status_label: computed.label,
|
|
880
|
+
};
|
|
881
|
+
}))
|
|
882
|
+
.filter((agent) => {
|
|
883
|
+
if (statusSet !== null && !statusSet.has(agent.status)) {
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
if (channelSlug !== undefined && !agent.channels.some((ch) => ch.toLowerCase() === channelSlug)) {
|
|
887
|
+
return false;
|
|
888
|
+
}
|
|
889
|
+
if (kindFilter !== undefined && kindFilter !== "" && agent.kind.toLowerCase() !== kindFilter) {
|
|
890
|
+
return false;
|
|
891
|
+
}
|
|
892
|
+
if (qLower !== "") {
|
|
893
|
+
const hit = agent.id.toLowerCase().includes(qLower) ||
|
|
894
|
+
agent.name.toLowerCase().includes(qLower) ||
|
|
895
|
+
agent.description.toLowerCase().includes(qLower) ||
|
|
896
|
+
agent.home.toLowerCase().includes(qLower) ||
|
|
897
|
+
agent.channels.some((ch) => ch.toLowerCase().includes(qLower));
|
|
898
|
+
if (!hit) {
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
return true;
|
|
903
|
+
});
|
|
904
|
+
if (ctx.global.json) {
|
|
905
|
+
emitJson({ agents: enriched, communities: syncSummaries });
|
|
906
|
+
return EXIT_OK;
|
|
907
|
+
}
|
|
908
|
+
if (enriched.length === 0) {
|
|
909
|
+
out("No agents match.");
|
|
910
|
+
return EXIT_OK;
|
|
911
|
+
}
|
|
912
|
+
const multi = targetIds.length > 1;
|
|
913
|
+
const headers = multi
|
|
914
|
+
? ["COMMUNITY", "ID", "NAME", "STATUS", "KIND", "HOME", "TASKS", "CHECKED"]
|
|
915
|
+
: ["ID", "NAME", "STATUS", "KIND", "HOME", "TASKS", "CHECKED"];
|
|
916
|
+
out(formatTable(headers, enriched.map((agent) => [
|
|
917
|
+
...(multi ? [agent.community] : []),
|
|
918
|
+
agent.id,
|
|
919
|
+
agent.name,
|
|
920
|
+
agent.status,
|
|
921
|
+
agent.kind,
|
|
922
|
+
agent.home,
|
|
923
|
+
agent.tasks.length > 0 ? agent.tasks.join(", ") : "-",
|
|
924
|
+
agent.checked !== null ? `${formatRelativeAge(agent.checked.at)} (${agent.checked.revision.slice(0, 7)})` : "-",
|
|
925
|
+
])));
|
|
926
|
+
return EXIT_OK;
|
|
927
|
+
}
|
|
928
|
+
/** `activity [--limit N]` */
|
|
929
|
+
async function cmdActivity(ctx) {
|
|
930
|
+
const rawLimit = ctx.opt("limit");
|
|
931
|
+
const limit = rawLimit !== undefined ? parsePositiveInt("limit", rawLimit) : DEFAULT_ACTIVITY_LIMIT;
|
|
932
|
+
if (limit > MAX_ACTIVITY_LIMIT) {
|
|
933
|
+
throw new CliError(`--limit must be at most ${MAX_ACTIVITY_LIMIT}.`, { exitCode: EXIT_VALIDATION });
|
|
934
|
+
}
|
|
935
|
+
const configured = ctx.community();
|
|
936
|
+
const allCommunities = await fetchCommunities(ctx, configured !== undefined ? [configured] : undefined);
|
|
937
|
+
const targetIds = configured !== undefined ? [configured] : allCommunities.map((c) => c.id);
|
|
938
|
+
const syncSummaries = syncSummariesFor(targetIds, allCommunities);
|
|
939
|
+
const client = ctx.client();
|
|
940
|
+
const responses = await Promise.all(targetIds.map(async (id) => {
|
|
941
|
+
const res = await client.request("GET", "/api/activity", {
|
|
942
|
+
query: { community: id, limit },
|
|
943
|
+
});
|
|
944
|
+
return { id, items: res.body.items };
|
|
945
|
+
}));
|
|
946
|
+
warnUnhealthyCommunities(ctx, syncSummaries);
|
|
947
|
+
const merged = responses
|
|
948
|
+
.flatMap(({ id, items }) => items.map((item) => ({ community: id, item })))
|
|
949
|
+
.sort((a, b) => b.item.event.created_at - a.item.event.created_at)
|
|
950
|
+
.slice(0, limit);
|
|
951
|
+
const communitiesWithActivity = [...new Set(merged.map((entry) => entry.community))];
|
|
952
|
+
const resolvers = await fetchResolvers(ctx, communitiesWithActivity);
|
|
953
|
+
const enriched = merged.map(({ community, item }) => {
|
|
954
|
+
const resolver = resolvers.get(community);
|
|
955
|
+
return {
|
|
956
|
+
...item,
|
|
957
|
+
community,
|
|
958
|
+
author_name: resolver?.name(item.event.pubkey) ?? item.event.pubkey,
|
|
959
|
+
};
|
|
960
|
+
});
|
|
961
|
+
if (ctx.global.json) {
|
|
962
|
+
emitJson({ items: enriched, communities: syncSummaries });
|
|
963
|
+
return EXIT_OK;
|
|
964
|
+
}
|
|
965
|
+
if (enriched.length === 0) {
|
|
966
|
+
out("No recent activity.");
|
|
967
|
+
return EXIT_OK;
|
|
968
|
+
}
|
|
969
|
+
const multi = targetIds.length > 1;
|
|
970
|
+
const headers = multi
|
|
971
|
+
? ["TIME", "COMMUNITY", "TASK", "AUTHOR", "KIND", "SUMMARY"]
|
|
972
|
+
: ["TIME", "TASK", "AUTHOR", "KIND", "SUMMARY"];
|
|
973
|
+
out(formatTable(headers, enriched.map((entry) => [
|
|
974
|
+
formatTimestamp(entry.event.created_at),
|
|
975
|
+
...(multi ? [entry.community] : []),
|
|
976
|
+
entry.task.key,
|
|
977
|
+
entry.author_name,
|
|
978
|
+
entry.event.kind,
|
|
979
|
+
truncate(oneLine(entry.event.content), 80),
|
|
980
|
+
])));
|
|
981
|
+
return EXIT_OK;
|
|
982
|
+
}
|
|
983
|
+
export const readCommands = [
|
|
984
|
+
{
|
|
985
|
+
name: "communities",
|
|
986
|
+
summary: "List configured communities, sync health, and optional channel details",
|
|
987
|
+
usage: "communities [--channels]",
|
|
988
|
+
options: {
|
|
989
|
+
channels: { type: "boolean", description: "Include per-channel visibility and startable entry agents" },
|
|
990
|
+
},
|
|
991
|
+
positionals: { min: 0, max: 0 },
|
|
992
|
+
handler: cmdCommunities,
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
name: "overview",
|
|
996
|
+
summary: "Show task and draft counts per community",
|
|
997
|
+
usage: "overview",
|
|
998
|
+
positionals: { min: 0, max: 0 },
|
|
999
|
+
handler: cmdOverview,
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
name: "templates",
|
|
1003
|
+
summary: "List workflow templates and task kinds (offline by default)",
|
|
1004
|
+
usage: "templates [TEMPLATE_ID] [--all] [--check]",
|
|
1005
|
+
options: {
|
|
1006
|
+
all: { type: "boolean", description: "Include internal templates and detailed blurb/outcome lines" },
|
|
1007
|
+
check: { type: "boolean", description: "Check template availability against the server's channels" },
|
|
1008
|
+
},
|
|
1009
|
+
positionals: { min: 0, max: 1 },
|
|
1010
|
+
handler: cmdTemplates,
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
name: "list",
|
|
1014
|
+
summary: "List and filter tasks across one or all communities",
|
|
1015
|
+
usage: "list [options]",
|
|
1016
|
+
options: {
|
|
1017
|
+
col: {
|
|
1018
|
+
type: "string",
|
|
1019
|
+
multiple: true,
|
|
1020
|
+
placeholder: "COLS",
|
|
1021
|
+
description: "Filter by column (backlog, queued, working, needs, shipping, done, canceled, open)",
|
|
1022
|
+
},
|
|
1023
|
+
channel: { type: "string", placeholder: "SELECTOR", description: "Filter by channel ID or #slug" },
|
|
1024
|
+
template: { type: "string", multiple: true, placeholder: "ID", description: "Filter by template ID" },
|
|
1025
|
+
reason: { type: "string", multiple: true, placeholder: "TYPE", description: "Filter by open reason type" },
|
|
1026
|
+
priority: {
|
|
1027
|
+
type: "string",
|
|
1028
|
+
multiple: true,
|
|
1029
|
+
placeholder: "LEVEL",
|
|
1030
|
+
description: "Filter by priority (low, normal, high, urgent)",
|
|
1031
|
+
},
|
|
1032
|
+
label: {
|
|
1033
|
+
type: "string",
|
|
1034
|
+
multiple: true,
|
|
1035
|
+
placeholder: "LABEL",
|
|
1036
|
+
description: "Filter by label (case-insensitive; tasks must carry all specified labels)",
|
|
1037
|
+
},
|
|
1038
|
+
q: { type: "string", placeholder: "TEXT", description: "Search title, key, labels, and stage label" },
|
|
1039
|
+
mine: { type: "boolean", description: "Only show tasks requested by or waiting on you" },
|
|
1040
|
+
"for-me": { type: "boolean", description: "Only show tasks currently waiting on you" },
|
|
1041
|
+
compact: { type: "boolean", description: "Show compact columns or compact JSON fields" },
|
|
1042
|
+
limit: { type: "string", placeholder: "N", description: "Cap the number of tasks returned after sorting" },
|
|
1043
|
+
sort: {
|
|
1044
|
+
type: "string",
|
|
1045
|
+
placeholder: "FIELD",
|
|
1046
|
+
choices: ["last", "since", "priority", "key"],
|
|
1047
|
+
default: "last",
|
|
1048
|
+
description: "Sort order",
|
|
1049
|
+
},
|
|
1050
|
+
},
|
|
1051
|
+
positionals: { min: 0, max: 0 },
|
|
1052
|
+
handler: cmdList,
|
|
1053
|
+
},
|
|
1054
|
+
{
|
|
1055
|
+
name: "inbox",
|
|
1056
|
+
summary: "Show tasks needing attention, grouped by waiting on you vs others",
|
|
1057
|
+
usage: "inbox [--for-me] [--compact] [--limit N]",
|
|
1058
|
+
options: {
|
|
1059
|
+
"for-me": { type: "boolean", description: "Only show tasks currently waiting on you" },
|
|
1060
|
+
compact: { type: "boolean", description: "Omit the next-command hint column in text output" },
|
|
1061
|
+
limit: { type: "string", placeholder: "N", description: "Cap the number of inbox items returned" },
|
|
1062
|
+
},
|
|
1063
|
+
positionals: { min: 0, max: 0 },
|
|
1064
|
+
handler: cmdInbox,
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
name: "show",
|
|
1068
|
+
summary: "Display full task metadata and chronological thread timeline",
|
|
1069
|
+
usage: "show <TASK_REF> [--tail N] [--full] [--raw]",
|
|
1070
|
+
options: {
|
|
1071
|
+
tail: { type: "string", placeholder: "N", description: "Show only the last N thread events" },
|
|
1072
|
+
full: { type: "boolean", description: "Do not truncate long event bodies in text output" },
|
|
1073
|
+
raw: { type: "boolean", description: "Include raw Nostr event fields (id, kind, tags, sig)" },
|
|
1074
|
+
},
|
|
1075
|
+
positionals: { min: 1, max: 1 },
|
|
1076
|
+
handler: cmdShow,
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
name: "agents",
|
|
1080
|
+
summary: "List agents and their live operational status",
|
|
1081
|
+
usage: "agents [--status S] [--channel C] [--kind K] [--q TEXT]",
|
|
1082
|
+
options: {
|
|
1083
|
+
status: {
|
|
1084
|
+
type: "string",
|
|
1085
|
+
multiple: true,
|
|
1086
|
+
placeholder: "STATUS",
|
|
1087
|
+
description: "Filter by status (down, working, idle, away, key)",
|
|
1088
|
+
},
|
|
1089
|
+
channel: { type: "string", placeholder: "SLUG", description: "Filter by channel slug" },
|
|
1090
|
+
kind: { type: "string", placeholder: "KIND", description: "Filter by agent kind" },
|
|
1091
|
+
q: { type: "string", placeholder: "TEXT", description: "Search id, name, description, home, or channels" },
|
|
1092
|
+
},
|
|
1093
|
+
positionals: { min: 0, max: 0 },
|
|
1094
|
+
handler: cmdAgents,
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
name: "activity",
|
|
1098
|
+
summary: "Show recent thread activity across one or all communities",
|
|
1099
|
+
usage: "activity [--limit N]",
|
|
1100
|
+
options: {
|
|
1101
|
+
limit: { type: "string", placeholder: "N", default: "30", description: "Maximum activity items to return (1-200)" },
|
|
1102
|
+
},
|
|
1103
|
+
positionals: { min: 0, max: 0 },
|
|
1104
|
+
handler: cmdActivity,
|
|
1105
|
+
},
|
|
1106
|
+
];
|