slack-term 1.55.1 → 1.55.2
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/dist/cli.js +216 -216
- package/package.json +1 -1
- package/ts/askPush.ts +20 -2
- package/ts/cli.ts +34 -10
package/package.json
CHANGED
package/ts/askPush.ts
CHANGED
|
@@ -21,9 +21,27 @@ function clip(s: string, n: number): string {
|
|
|
21
21
|
return one.length <= n ? one : `${one.slice(0, n - 1)}…`;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/** An answer this much older than its push is labelled late. */
|
|
25
|
+
export const PUSH_LATE_MS = 60 * 60_000;
|
|
26
|
+
|
|
27
|
+
function utc(ms: number): string {
|
|
28
|
+
return `${new Date(ms).toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `[ask-answer]`, or — for an answer that is not new (a backfill, a lane that
|
|
32
|
+
* was down) — `[ask-answer, late: …]` with when it was given. A pill press
|
|
33
|
+
* carries no time in Slack, so a late one says when the question was asked. */
|
|
34
|
+
export function askPushTag(askedAtMs: number, answeredAtMs: number | undefined, nowMs = Date.now()): string {
|
|
35
|
+
const since = answeredAtMs ?? askedAtMs;
|
|
36
|
+
if (nowMs - since < PUSH_LATE_MS) return "[ask-answer]";
|
|
37
|
+
return answeredAtMs !== undefined
|
|
38
|
+
? `[ask-answer, late: answered ${utc(answeredAtMs)}]`
|
|
39
|
+
: `[ask-answer, late: asked ${utc(askedAtMs)}, pressed since]`;
|
|
40
|
+
}
|
|
41
|
+
|
|
24
42
|
/** The one-line message the asker receives: link, answer, how, question. */
|
|
25
|
-
export function askPushMessage(p: { link: string; answer: string; how: string; question: string; freeText: boolean; collected?: boolean; goneAsker?: number }): string {
|
|
26
|
-
const head =
|
|
43
|
+
export function askPushMessage(p: { link: string; answer: string; how: string; question: string; freeText: boolean; collected?: boolean; goneAsker?: number; tag?: string }): string {
|
|
44
|
+
const head = `${p.tag ?? "[ask-answer]"} ${p.link} →`;
|
|
27
45
|
const ans = clip(p.answer, 300);
|
|
28
46
|
let tail = p.how ? ` (${p.how})` : "";
|
|
29
47
|
if (p.freeText) tail += " — a free-text reply, not a choice: the question stays open";
|
package/ts/cli.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { cmdAuthLogin, cmdAuthLoginChrome, cmdAuthChrome, cmdAuthFirefox, cmdAut
|
|
|
16
16
|
import { cmdTail, parseSince as parseDuration } from "./tail.ts";
|
|
17
17
|
import { phiDelay, runStream, webClient, type StreamMatch } from "./stream.ts";
|
|
18
18
|
import { relaySubscriber, relayTransport } from "./relay.ts";
|
|
19
|
-
import { acquirePushLock, askPushMessage, laneAgent, liveAgents, notifyAgent } from "./askPush.ts";
|
|
19
|
+
import { acquirePushLock, askPushMessage, askPushTag, laneAgent, liveAgents, notifyAgent } from "./askPush.ts";
|
|
20
20
|
import { DEFAULT_DIR, initRelay, initReport, relayHealth } from "./relayInit.ts";
|
|
21
21
|
import { agentCommands } from "./agent.ts";
|
|
22
22
|
|
|
@@ -4251,6 +4251,8 @@ interface AskPendingItem {
|
|
|
4251
4251
|
collect: string;
|
|
4252
4252
|
/** Where a delivery of this free-text reply ends (`--after` for the next look). */
|
|
4253
4253
|
cursor?: string;
|
|
4254
|
+
/** When the answer was given (a reply's ts); unknown for a pill press. */
|
|
4255
|
+
answeredTs?: string;
|
|
4254
4256
|
/** Set by `--push`: the pid that took the answer, and whether it was collected. */
|
|
4255
4257
|
pushed?: { pid: number; collected: boolean };
|
|
4256
4258
|
/** Set by `--push`: why this answer reached nobody. */
|
|
@@ -4321,8 +4323,12 @@ async function cmdAskPending(
|
|
|
4321
4323
|
only?: Set<string>; watch?: boolean;
|
|
4322
4324
|
/** Show only answers that reached nobody. */
|
|
4323
4325
|
undelivered?: boolean;
|
|
4326
|
+
/** `--watch`: questions already looked at in this round (`channel:ts`),
|
|
4327
|
+
* skipped unless asked within the last day. */
|
|
4328
|
+
skip?: Set<string>;
|
|
4324
4329
|
},
|
|
4325
|
-
): Promise<
|
|
4330
|
+
): Promise<{ checked: string[]; throttled: boolean }> {
|
|
4331
|
+
const checked: string[] = [];
|
|
4326
4332
|
// Never blocks: one look per question and no waiting out 429s. A throttled
|
|
4327
4333
|
// pass says how many it skipped; the next pass picks them up.
|
|
4328
4334
|
setRateLimitWait(0);
|
|
@@ -4331,8 +4337,10 @@ async function cmdAskPending(
|
|
|
4331
4337
|
console.error(`Error: ${SENT_LOG_UNAVAILABLE}\n (${sentDbPath()})`);
|
|
4332
4338
|
process.exit(ASK_EXIT_ERROR);
|
|
4333
4339
|
}
|
|
4340
|
+
const recent = Date.now() - 24 * 3600_000;
|
|
4334
4341
|
const rows = all.filter((r) =>
|
|
4335
|
-
(!opts.channel || r.channel === opts.channel || r.target === opts.channel) && (!opts.only || opts.only.has(`${r.channel}:${r.ts}`))
|
|
4342
|
+
(!opts.channel || r.channel === opts.channel || r.target === opts.channel) && (!opts.only || opts.only.has(`${r.channel}:${r.ts}`)) &&
|
|
4343
|
+
(!opts.skip || r.sent_at >= recent || !opts.skip.has(`${r.channel}:${r.ts}`)));
|
|
4336
4344
|
const pending: AskPendingItem[] = [];
|
|
4337
4345
|
const count = { unanswered: 0, ambiguous: 0, resolved: 0, void: 0, explain: 0, throttled: 0 };
|
|
4338
4346
|
/** Open questions someone pressed ℹ️ on — reported only: the thread note is
|
|
@@ -4358,6 +4366,7 @@ async function cmdAskPending(
|
|
|
4358
4366
|
}
|
|
4359
4367
|
const link = row.permalink || `${row.channel}:${row.ts}`;
|
|
4360
4368
|
const asBot = !!row.as_bot;
|
|
4369
|
+
checked.push(`${row.channel}:${row.ts}`);
|
|
4361
4370
|
// Resume from where the last delivery to a caller ended (an exit 5
|
|
4362
4371
|
// free-text reply), so that reply is not reported again — and the collect
|
|
4363
4372
|
// line carries the same cursor, so `--waitFor` does not re-deliver it.
|
|
@@ -4402,9 +4411,9 @@ async function cmdAskPending(
|
|
|
4402
4411
|
}
|
|
4403
4412
|
const base = { row, link, question: parsed.question, collect, alive: senderAlive(row) };
|
|
4404
4413
|
if (found) {
|
|
4405
|
-
pending.push({ ...base, answer: found.answer, how: found.how, freeText: false });
|
|
4414
|
+
pending.push({ ...base, answer: found.answer, how: found.how, freeText: false, ...(found.ts ? { answeredTs: found.ts } : {}) });
|
|
4406
4415
|
} else if (unchosen && !unchosen.ambiguous && unchosen.text !== row.delivered_answer) {
|
|
4407
|
-
pending.push({ ...base, answer: unchosen.text, how: "reply (not a choice)", freeText: true, cursor: askNextCursor(row.ts, after, unchosen.ts) });
|
|
4416
|
+
pending.push({ ...base, answer: unchosen.text, how: "reply (not a choice)", freeText: true, cursor: askNextCursor(row.ts, after, unchosen.ts), answeredTs: unchosen.ts });
|
|
4408
4417
|
} else if (unchosen?.ambiguous) {
|
|
4409
4418
|
count.ambiguous++;
|
|
4410
4419
|
} else {
|
|
@@ -4413,6 +4422,7 @@ async function cmdAskPending(
|
|
|
4413
4422
|
} catch (e: unknown) {
|
|
4414
4423
|
if (e instanceof RateLimitError) {
|
|
4415
4424
|
// Probing on would only collect more 429s for the same method.
|
|
4425
|
+
checked.pop(); // not looked at: the next round starts with it
|
|
4416
4426
|
count.throttled = rows.length - i;
|
|
4417
4427
|
problems.push(`rate-limited by Slack (${e.message}): ${count.throttled} question(s) not checked this pass`);
|
|
4418
4428
|
break;
|
|
@@ -4426,7 +4436,8 @@ async function cmdAskPending(
|
|
|
4426
4436
|
|
|
4427
4437
|
// A watcher's log carries what it did, not the whole list on every pass.
|
|
4428
4438
|
const shown = opts.watch ? pending.filter((it) => it.pushed) : opts.undelivered ? pending.filter(reachedNobody) : pending;
|
|
4429
|
-
|
|
4439
|
+
const result = { checked, throttled: count.throttled > 0 };
|
|
4440
|
+
if (opts.watch && !shown.length && !problems.length) return result;
|
|
4430
4441
|
if (opts.json) {
|
|
4431
4442
|
for (const it of shown) {
|
|
4432
4443
|
const r = it.row;
|
|
@@ -4479,6 +4490,7 @@ async function cmdAskPending(
|
|
|
4479
4490
|
(opts.undelivered ? `, ${pending.filter(reachedNobody).length} undelivered` : "") +
|
|
4480
4491
|
` — checked ${rows.length} uncollected question(s) (log: ${sentDbPath()})`,
|
|
4481
4492
|
);
|
|
4493
|
+
return result;
|
|
4482
4494
|
}
|
|
4483
4495
|
|
|
4484
4496
|
/** `ask --pending --push --watch`: a push pass every `intervalMs`, and — when
|
|
@@ -4486,7 +4498,7 @@ async function cmdAskPending(
|
|
|
4486
4498
|
* soon as the relay rings for it (a reaction on it, or a reply in its
|
|
4487
4499
|
* thread), so a pressed pill reaches the asker in seconds. The relay only
|
|
4488
4500
|
* sees the relay app's channels; the interval covers the rest. */
|
|
4489
|
-
async function askPushWatch(run: (only?: Set<string>) => Promise<
|
|
4501
|
+
async function askPushWatch(run: (only?: Set<string>) => Promise<unknown>, sinceMs: () => number, intervalMs: number | (() => number)): Promise<never> {
|
|
4490
4502
|
let busy = false;
|
|
4491
4503
|
const queued = new Set<string>();
|
|
4492
4504
|
let full = true;
|
|
@@ -4538,7 +4550,7 @@ async function askPushWatch(run: (only?: Set<string>) => Promise<void>, sinceMs:
|
|
|
4538
4550
|
for (;;) {
|
|
4539
4551
|
full = true;
|
|
4540
4552
|
await kick();
|
|
4541
|
-
await new Promise((r) => setTimeout(r, intervalMs));
|
|
4553
|
+
await new Promise((r) => setTimeout(r, typeof intervalMs === "number" ? intervalMs : intervalMs()));
|
|
4542
4554
|
}
|
|
4543
4555
|
}
|
|
4544
4556
|
|
|
@@ -4572,6 +4584,7 @@ function askPushAll(items: AskPendingItem[], selfArgs: string[], problems: strin
|
|
|
4572
4584
|
const msg = askPushMessage({
|
|
4573
4585
|
link: it.link, answer: it.answer, how: it.how, question: it.question, freeText: it.freeText, collected: !it.freeText,
|
|
4574
4586
|
...(it.alive ? {} : { goneAsker: asker }),
|
|
4587
|
+
tag: askPushTag(r.sent_at, it.answeredTs ? Number(it.answeredTs) * 1000 : undefined),
|
|
4575
4588
|
});
|
|
4576
4589
|
const took = notifyAgent(target, msg);
|
|
4577
4590
|
if (took === undefined) {
|
|
@@ -7123,10 +7136,21 @@ async function main(): Promise<void> {
|
|
|
7123
7136
|
process.exit(ASK_EXIT_ERROR);
|
|
7124
7137
|
}
|
|
7125
7138
|
const since = String(argv.since);
|
|
7139
|
+
// A round: full passes until every question has been looked at
|
|
7140
|
+
// once. A pass cut short by a rate limit leaves the rest to the
|
|
7141
|
+
// next one instead of starting over from the newest (which left
|
|
7142
|
+
// most of a long backlog unread on every pass).
|
|
7143
|
+
const round = new Set<string>();
|
|
7126
7144
|
await askPushWatch(
|
|
7127
|
-
(only) =>
|
|
7145
|
+
async (only) => {
|
|
7146
|
+
const r = await cmdAskPending(tokens, { ...p, sinceMs: parseSince(since) ?? sinceMs, watch: true, ...(only ? { only } : { skip: round }) });
|
|
7147
|
+
if (only) return;
|
|
7148
|
+
if (r.throttled) for (const k of r.checked) round.add(k);
|
|
7149
|
+
else round.clear();
|
|
7150
|
+
},
|
|
7128
7151
|
() => parseSince(since) ?? sinceMs,
|
|
7129
|
-
|
|
7152
|
+
// Mid-round, the next pass comes sooner: a 429 window is a minute.
|
|
7153
|
+
() => (round.size ? Math.min(2, min) : min) * 60_000,
|
|
7130
7154
|
);
|
|
7131
7155
|
}
|
|
7132
7156
|
try {
|