slack-term 1.55.0 → 1.55.1
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 +4 -1
- package/dist/cli.js +223 -222
- package/package.json +1 -1
- package/ts/askPush.ts +28 -2
- package/ts/cli.ts +106 -21
- package/ts/sentlog.ts +23 -5
package/package.json
CHANGED
package/ts/askPush.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
// agent's pid, so slack-term can tell it directly.
|
|
9
9
|
import { spawnSync, type SpawnSyncReturns } from "node:child_process";
|
|
10
10
|
import { closeSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
11
|
-
import {
|
|
11
|
+
import { homedir, tmpdir } from "node:os";
|
|
12
|
+
import { dirname, resolve } from "node:path";
|
|
12
13
|
import { pidAlive } from "./sentlog.ts";
|
|
13
14
|
|
|
14
15
|
/** ay rejects messages over 1024 chars. */
|
|
@@ -21,12 +22,13 @@ function clip(s: string, n: number): string {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/** The one-line message the asker receives: link, answer, how, question. */
|
|
24
|
-
export function askPushMessage(p: { link: string; answer: string; how: string; question: string; freeText: boolean; collected?: boolean }): string {
|
|
25
|
+
export function askPushMessage(p: { link: string; answer: string; how: string; question: string; freeText: boolean; collected?: boolean; goneAsker?: number }): string {
|
|
25
26
|
const head = `[ask-answer] ${p.link} →`;
|
|
26
27
|
const ans = clip(p.answer, 300);
|
|
27
28
|
let tail = p.how ? ` (${p.how})` : "";
|
|
28
29
|
if (p.freeText) tail += " — a free-text reply, not a choice: the question stays open";
|
|
29
30
|
else if (p.collected) tail += " — collected ✅";
|
|
31
|
+
if (p.goneAsker) tail += ` — asked by pid ${p.goneAsker}, now gone: sent to this lane by its directory`;
|
|
30
32
|
const q = clip(p.question, PUSH_MAX - head.length - ans.length - tail.length - 8);
|
|
31
33
|
return `${head} ${ans}${tail}. Q: ${q}`.slice(0, PUSH_MAX);
|
|
32
34
|
}
|
|
@@ -61,6 +63,30 @@ export function notifyAgent(pid: number, msg: string, run: Run = runSync, parent
|
|
|
61
63
|
return undefined;
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
/** Agents ay knows, or none when ay is missing or says something else. */
|
|
67
|
+
export function liveAgents(run: Run = runSync): { pid: number; cwd: string; started_at?: number }[] {
|
|
68
|
+
const r = run(process.env.SLACK_TERM_AY || "ay", ["ls", "--json"]);
|
|
69
|
+
try {
|
|
70
|
+
const v = JSON.parse(r.stdout ?? "") as { pid?: unknown; cwd?: unknown; started_at?: unknown }[];
|
|
71
|
+
return Array.isArray(v)
|
|
72
|
+
? v.flatMap((a) => (typeof a.pid === "number" && typeof a.cwd === "string" ? [{ pid: a.pid, cwd: a.cwd, ...(typeof a.started_at === "number" ? { started_at: a.started_at } : {}) }] : []))
|
|
73
|
+
: [];
|
|
74
|
+
} catch {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The live agent that took over a gone asker's lane: a lane restarts in the
|
|
80
|
+
* same directory, with a new pid. The newest one there wins. A shared
|
|
81
|
+
* directory (temp, home) says nothing about who asked, so it matches nobody. */
|
|
82
|
+
export function laneAgent(cwd: string, agents: { pid: number; cwd: string; started_at?: number }[], alive: (pid: number) => boolean = pidAlive): number | undefined {
|
|
83
|
+
const dir = resolve(cwd);
|
|
84
|
+
const tmp = resolve(tmpdir());
|
|
85
|
+
if (dir === resolve(homedir()) || dir === tmp || dir.startsWith(`${tmp}/`)) return undefined;
|
|
86
|
+
const here = agents.filter((a) => resolve(a.cwd.replace(/^~(?=\/|$)/, homedir())) === dir && alive(a.pid));
|
|
87
|
+
return here.sort((a, b) => (b.started_at ?? 0) - (a.started_at ?? 0))[0]?.pid;
|
|
88
|
+
}
|
|
89
|
+
|
|
64
90
|
/** One push pass at a time per machine: a watcher and a one-off run must not
|
|
65
91
|
* both push the same answer. Returns a release function, or undefined when a
|
|
66
92
|
* live pass holds the lock (a dead holder's lock is taken over). */
|
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, notifyAgent } from "./askPush.ts";
|
|
19
|
+
import { acquirePushLock, askPushMessage, 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
|
|
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
} from "./poll.ts";
|
|
73
73
|
import { seedReactionsInOrder } from "./reactionSeed.ts";
|
|
74
74
|
import { buildListSchema, cellValue, completedColumn, findColumn, parseColumnSpec, parseListSchema, parseSets, type ListColumn } from "./lists.ts";
|
|
75
|
-
import { attributionEnabled, attributionMetadata, captureAttribution, markAskCollected, markAskDelivered, markAskPushed, parseSince, querySent, recordSent, SENT_LOG_UNAVAILABLE, sentDbPath, senderAlive, uncollectedAsks, type RecordSent, type SentKind, type SentRow } from "./sentlog.ts";
|
|
75
|
+
import { attributionEnabled, attributionMetadata, captureAttribution, markAskCollected, markAskDelivered, markAskIdentity, markAskPushed, markAskSettled, parseSince, querySent, recordSent, SENT_LOG_UNAVAILABLE, sentDbPath, senderAlive, uncollectedAsks, type RecordSent, type SentKind, type SentRow } from "./sentlog.ts";
|
|
76
76
|
import {
|
|
77
77
|
authTest,
|
|
78
78
|
authScopes,
|
|
@@ -4253,8 +4253,52 @@ interface AskPendingItem {
|
|
|
4253
4253
|
cursor?: string;
|
|
4254
4254
|
/** Set by `--push`: the pid that took the answer, and whether it was collected. */
|
|
4255
4255
|
pushed?: { pid: number; collected: boolean };
|
|
4256
|
+
/** Set by `--push`: why this answer reached nobody. */
|
|
4257
|
+
undelivered?: string;
|
|
4258
|
+
}
|
|
4259
|
+
|
|
4260
|
+
/** An ask logged before identities were recorded, from another bot's DM: this
|
|
4261
|
+
* run's bot gets channel_not_found. Finds the configured bot that can read it,
|
|
4262
|
+
* once per channel in a pass (`known`). */
|
|
4263
|
+
async function askFindIdentity(row: SentRow, botToken: string | undefined, known: Map<string, string | undefined>): Promise<string | undefined> {
|
|
4264
|
+
if (known.has(row.channel)) return known.get(row.channel);
|
|
4265
|
+
const loc = { channelId: row.channel, ts: row.ts, threadTs: row.thread_ts ?? undefined };
|
|
4266
|
+
const canRead = async (token: string | undefined): Promise<boolean | undefined> => {
|
|
4267
|
+
if (!token) return false;
|
|
4268
|
+
try {
|
|
4269
|
+
await askFetchAt(token, loc);
|
|
4270
|
+
return true;
|
|
4271
|
+
} catch (e: unknown) {
|
|
4272
|
+
if (e instanceof RateLimitError) throw e;
|
|
4273
|
+
return /channel_not_found|not_in_channel/.test(e instanceof Error ? e.message : String(e)) ? false : undefined;
|
|
4274
|
+
}
|
|
4275
|
+
};
|
|
4276
|
+
let who: string | undefined;
|
|
4277
|
+
if ((await canRead(botToken)) === false) {
|
|
4278
|
+
for (const [name, id] of listIdentities()) {
|
|
4279
|
+
if (id.kind !== "bot" || name === process.env.SLACK_TERM_IDENTITY) continue;
|
|
4280
|
+
const env = { ...process.env };
|
|
4281
|
+
if ("error" in applyIdentity(name, env)) continue;
|
|
4282
|
+
if (await canRead(env.SLACK_BOT_TOKEN)) { who = name; break; }
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
known.set(row.channel, who);
|
|
4286
|
+
return who;
|
|
4287
|
+
}
|
|
4288
|
+
|
|
4289
|
+
/** The tokens a logged question is read with: those of the identity it was
|
|
4290
|
+
* asked as, when that is not the one this run acts as. */
|
|
4291
|
+
function askRowTokens(row: SentRow, tokens: { user?: string; bot?: string; cookie?: string }): { user?: string; bot?: string; cookie?: string } | string {
|
|
4292
|
+
if (!row.identity || row.identity === process.env.SLACK_TERM_IDENTITY) return tokens;
|
|
4293
|
+
const env = { ...process.env };
|
|
4294
|
+
const r = applyIdentity(row.identity, env);
|
|
4295
|
+
if ("error" in r) return r.error;
|
|
4296
|
+
if (r.kind === "bot") return { bot: env.SLACK_BOT_TOKEN!, user: env.SLACK_TOKEN! };
|
|
4297
|
+
if (!env.SLACK_TOKEN) return `asked as @${row.identity}, a profile identity: run the pass as that identity`;
|
|
4298
|
+
return { user: env.SLACK_TOKEN };
|
|
4256
4299
|
}
|
|
4257
4300
|
|
|
4301
|
+
|
|
4258
4302
|
/** `slack ask --pending [--since 7d] [--json]` — questions THIS machine asked
|
|
4259
4303
|
* that somebody answered and nobody collected, grouped by the asking session,
|
|
4260
4304
|
* with whether that agent is still alive.
|
|
@@ -4275,6 +4319,8 @@ async function cmdAskPending(
|
|
|
4275
4319
|
sinceMs: number; json: boolean; channel?: string; push?: boolean; selfArgs?: string[];
|
|
4276
4320
|
/** `--watch`: only these questions (`channel:ts`), and print only what was pushed. */
|
|
4277
4321
|
only?: Set<string>; watch?: boolean;
|
|
4322
|
+
/** Show only answers that reached nobody. */
|
|
4323
|
+
undelivered?: boolean;
|
|
4278
4324
|
},
|
|
4279
4325
|
): Promise<void> {
|
|
4280
4326
|
// Never blocks: one look per question and no waiting out 429s. A throttled
|
|
@@ -4301,6 +4347,10 @@ async function cmdAskPending(
|
|
|
4301
4347
|
: tokens.bot ? (await selfIdentity(tokens.bot))?.team ?? "" : "";
|
|
4302
4348
|
const otherTeams = new Map<string, number>();
|
|
4303
4349
|
|
|
4350
|
+
const channelBots = new Map<string, string | undefined>();
|
|
4351
|
+
// Newest first: a pass stopped by a rate limit has then looked at the
|
|
4352
|
+
// questions most likely to be waited on, and an old backlog cannot starve them.
|
|
4353
|
+
rows.reverse();
|
|
4304
4354
|
for (const [i, row] of rows.entries()) {
|
|
4305
4355
|
if (row.team && currentTeam && row.team !== currentTeam) {
|
|
4306
4356
|
otherTeams.set(row.team, (otherTeams.get(row.team) ?? 0) + 1);
|
|
@@ -4308,17 +4358,26 @@ async function cmdAskPending(
|
|
|
4308
4358
|
}
|
|
4309
4359
|
const link = row.permalink || `${row.channel}:${row.ts}`;
|
|
4310
4360
|
const asBot = !!row.as_bot;
|
|
4311
|
-
const token = asBot ? tokens.bot : tokens.user;
|
|
4312
|
-
if (!token) {
|
|
4313
|
-
problems.push(`${link}: ${asBot ? "asked with --as-bot, but there is no bot token" : "no user token"}`);
|
|
4314
|
-
continue;
|
|
4315
|
-
}
|
|
4316
|
-
const cookie = asBot ? undefined : tokens.cookie;
|
|
4317
4361
|
// Resume from where the last delivery to a caller ended (an exit 5
|
|
4318
4362
|
// free-text reply), so that reply is not reported again — and the collect
|
|
4319
4363
|
// line carries the same cursor, so `--waitFor` does not re-deliver it.
|
|
4320
4364
|
const after = row.delivered_cursor ?? undefined;
|
|
4321
4365
|
try {
|
|
4366
|
+
if (!row.identity && asBot) {
|
|
4367
|
+
const who = await askFindIdentity(row, tokens.bot, channelBots);
|
|
4368
|
+
if (who) {
|
|
4369
|
+
row.identity = who;
|
|
4370
|
+
if (opts.push) markAskIdentity(row.channel, row.ts, who);
|
|
4371
|
+
}
|
|
4372
|
+
}
|
|
4373
|
+
const rowTokens = askRowTokens(row, tokens);
|
|
4374
|
+
if (typeof rowTokens === "string") { problems.push(`${link}: ${rowTokens}`); continue; }
|
|
4375
|
+
const token = asBot ? rowTokens.bot : rowTokens.user;
|
|
4376
|
+
if (!token) {
|
|
4377
|
+
problems.push(`${link}: ${asBot ? "asked with --as-bot, but there is no bot token" : "no user token"}`);
|
|
4378
|
+
continue;
|
|
4379
|
+
}
|
|
4380
|
+
const cookie = asBot ? undefined : rowTokens.cookie;
|
|
4322
4381
|
const loc = { channelId: row.channel, ts: row.ts, threadTs: row.thread_ts ?? undefined };
|
|
4323
4382
|
const got = await askFetchAt(token, loc, cookie);
|
|
4324
4383
|
if (!got.msg) { problems.push(`${link}: message not found (deleted?)`); continue; }
|
|
@@ -4326,15 +4385,16 @@ async function cmdAskPending(
|
|
|
4326
4385
|
const parsed = q.parsed;
|
|
4327
4386
|
// ✅ already stamped: some `--wait`/`--waitFor` collected it (another
|
|
4328
4387
|
// machine, another token, or a build before collection was logged).
|
|
4329
|
-
|
|
4330
|
-
if (parsed.kind === "
|
|
4388
|
+
// A push pass runs for good: what is settled is not read again.
|
|
4389
|
+
if (parsed.kind === "resolved") { count.resolved++; if (opts.push) markAskSettled(row.channel, row.ts, 0); continue; }
|
|
4390
|
+
if (parsed.kind === "void") { count.void++; if (opts.push) markAskSettled(row.channel, row.ts, ASK_EXIT_VOID); continue; }
|
|
4331
4391
|
if (parsed.kind === "other") { problems.push(`${link}: cannot be read as a \`slack ask\` question — ${askExplainReject(q.text)}`); continue; }
|
|
4332
4392
|
if (!q.audience.size && !q.broadcast) { problems.push(`${link}: the question is addressed to nobody`); continue; }
|
|
4333
4393
|
const ctx = askWaitCtxFrom(q, parsed, loc, { timeout: 0, link, asBot, json: false, cookie, after });
|
|
4334
4394
|
const poller = askPoller(token, ctx, true);
|
|
4335
4395
|
const found = await poller.poll();
|
|
4336
4396
|
const unchosen = poller.state.unchosen;
|
|
4337
|
-
if (poller.state.voided) { count.void++; continue; }
|
|
4397
|
+
if (poller.state.voided) { count.void++; if (opts.push) markAskSettled(row.channel, row.ts, ASK_EXIT_VOID); continue; }
|
|
4338
4398
|
const collect = askResumeCommand(link, asBot, after);
|
|
4339
4399
|
if (poller.state.explainNow.length) {
|
|
4340
4400
|
count.explain++;
|
|
@@ -4362,9 +4422,10 @@ async function cmdAskPending(
|
|
|
4362
4422
|
}
|
|
4363
4423
|
|
|
4364
4424
|
if (opts.push) askPushAll(pending, opts.selfArgs ?? [], problems);
|
|
4425
|
+
const reachedNobody = (it: AskPendingItem): boolean => !it.pushed && it.row.pushed_answer !== it.answer;
|
|
4365
4426
|
|
|
4366
4427
|
// A watcher's log carries what it did, not the whole list on every pass.
|
|
4367
|
-
const shown = opts.watch ? pending.filter((it) => it.pushed) : pending;
|
|
4428
|
+
const shown = opts.watch ? pending.filter((it) => it.pushed) : opts.undelivered ? pending.filter(reachedNobody) : pending;
|
|
4368
4429
|
if (opts.watch && !shown.length && !problems.length) return;
|
|
4369
4430
|
if (opts.json) {
|
|
4370
4431
|
for (const it of shown) {
|
|
@@ -4376,6 +4437,7 @@ async function cmdAskPending(
|
|
|
4376
4437
|
delivered_at: r.delivered_at ?? null,
|
|
4377
4438
|
collect: it.collect,
|
|
4378
4439
|
...(opts.push ? { pushed: it.pushed ?? null } : {}),
|
|
4440
|
+
...(it.undelivered ? { undelivered: it.undelivered } : {}),
|
|
4379
4441
|
}));
|
|
4380
4442
|
}
|
|
4381
4443
|
} else {
|
|
@@ -4396,6 +4458,7 @@ async function cmdAskPending(
|
|
|
4396
4458
|
console.log(` Q: ${stripTerminalControls(askFlatten(it.question))}`);
|
|
4397
4459
|
console.log(` A: ${stripTerminalControls(askFlatten(it.answer))} — ${stripTerminalControls(it.how)}${it.freeText ? " — not a decision" : ""}`);
|
|
4398
4460
|
console.log(` collect: ${stripTerminalControls(it.collect)}`);
|
|
4461
|
+
if (it.undelivered) console.log(` undelivered: ${stripTerminalControls(it.undelivered)}`);
|
|
4399
4462
|
if (it.pushed) console.log(` pushed to pid ${it.pushed.pid}${it.pushed.collected ? ", collected ✅" : ""}`);
|
|
4400
4463
|
}
|
|
4401
4464
|
}
|
|
@@ -4413,6 +4476,7 @@ async function cmdAskPending(
|
|
|
4413
4476
|
(count.explain ? `, ${count.explain} with an ℹ️ explain request` : "") +
|
|
4414
4477
|
(count.throttled ? `, ${count.throttled} not checked (rate-limited)` : "") +
|
|
4415
4478
|
(opts.push ? `, ${pending.filter((it) => it.pushed).length} pushed to the asker` : "") +
|
|
4479
|
+
(opts.undelivered ? `, ${pending.filter(reachedNobody).length} undelivered` : "") +
|
|
4416
4480
|
` — checked ${rows.length} uncollected question(s) (log: ${sentDbPath()})`,
|
|
4417
4481
|
);
|
|
4418
4482
|
}
|
|
@@ -4491,22 +4555,42 @@ function askPushAll(items: AskPendingItem[], selfArgs: string[], problems: strin
|
|
|
4491
4555
|
return;
|
|
4492
4556
|
}
|
|
4493
4557
|
try {
|
|
4558
|
+
let agents: ReturnType<typeof liveAgents> | undefined;
|
|
4494
4559
|
for (const it of items) {
|
|
4495
4560
|
const r = it.row;
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4561
|
+
const already = r.pushed_answer === it.answer;
|
|
4562
|
+
let pid = r.agent_pid ?? r.pid;
|
|
4563
|
+
// A decision already pushed whose collect failed last pass is only
|
|
4564
|
+
// collected now: the asker has it, the pill still shows open.
|
|
4565
|
+
if (!already) {
|
|
4566
|
+
const asker = pid;
|
|
4567
|
+
const target = it.alive ? asker : laneAgent(r.cwd, agents ??= liveAgents());
|
|
4568
|
+
if (target === undefined) {
|
|
4569
|
+
it.undelivered = `the asker (pid ${asker}) is gone and no live agent runs in ${r.cwd}`;
|
|
4570
|
+
continue;
|
|
4571
|
+
}
|
|
4572
|
+
const msg = askPushMessage({
|
|
4573
|
+
link: it.link, answer: it.answer, how: it.how, question: it.question, freeText: it.freeText, collected: !it.freeText,
|
|
4574
|
+
...(it.alive ? {} : { goneAsker: asker }),
|
|
4575
|
+
});
|
|
4576
|
+
const took = notifyAgent(target, msg);
|
|
4577
|
+
if (took === undefined) {
|
|
4578
|
+
it.undelivered = `pid ${target} did not take the push over ay — tried again next pass`;
|
|
4579
|
+
problems.push(`${it.link}: ${it.undelivered}`);
|
|
4580
|
+
continue;
|
|
4581
|
+
}
|
|
4582
|
+
pid = took;
|
|
4583
|
+
markAskPushed(r.channel, r.ts, it.answer);
|
|
4584
|
+
} else if (it.freeText) {
|
|
4501
4585
|
continue;
|
|
4502
4586
|
}
|
|
4503
|
-
markAskPushed(r.channel, r.ts, it.answer);
|
|
4504
4587
|
let collected = false;
|
|
4505
4588
|
if (it.freeText) {
|
|
4506
4589
|
markAskDelivered(r.channel, r.ts, it.answer, it.cursor ?? "");
|
|
4507
4590
|
} else {
|
|
4508
4591
|
const after = r.delivered_cursor ? [`--after=${r.delivered_cursor}`] : [];
|
|
4509
|
-
const
|
|
4592
|
+
const who = r.identity && r.identity !== process.env.SLACK_TERM_IDENTITY ? [`@${r.identity}`] : [];
|
|
4593
|
+
const c = spawnSync(process.execPath, [...process.argv.slice(1, 2), ...who, ...selfArgs, "ask", `--waitFor=${it.link}`, "--timeout", "0", ...(r.as_bot ? ["--as-bot"] : []), ...after],
|
|
4510
4594
|
{ encoding: "utf8", timeout: 120_000, stdio: ["ignore", "pipe", "pipe"] });
|
|
4511
4595
|
collected = c.status === 0;
|
|
4512
4596
|
if (!collected) problems.push(`${it.link}: pushed, but collecting it exited ${c.status ?? "on a signal"} — collect by hand: ${it.collect}`);
|
|
@@ -6977,7 +7061,8 @@ async function main(): Promise<void> {
|
|
|
6977
7061
|
.option("edit", { type: "string", describe: "Change an open question you posted: --edit=<permalink> [\"new question\" [choices…]] [--body …]. Rebuilt with the ask layout so collect still reads it. Options can change only while nobody has answered (then: --void=<link> --reask). Same --code gate." })
|
|
6978
7062
|
.option("ls", { type: "boolean", default: false, describe: "List the questions you posted (local sent-log) with their LIVE state: --state open|answered|void|all (default open), --stale 24h, --channel, --json. With --stale it prints the --void command that would retire them." })
|
|
6979
7063
|
.option("pending", { type: "boolean", default: false, describe: "List questions THIS machine asked (local sent-log) that somebody answered but nobody collected, grouped by the asking session, with whether that agent is still alive and the --waitFor line that collects each. Read-only unless --push: --since 7d, --channel, --json. Never waits out a rate limit: a throttled pass says how many it skipped." })
|
|
6980
|
-
.option("push", { type: "boolean", default: false, describe: "With --pending: send each answer to the agent that asked (ay send to the pid in the sent-log, or up to 3 of its parents), then collect a decision (✅, off this list); a free-text reply is marked delivered, the question stays open.
|
|
7064
|
+
.option("push", { type: "boolean", default: false, describe: "With --pending: send each answer to the agent that asked (ay send to the pid in the sent-log, or up to 3 of its parents), then collect a decision (✅, off this list); a free-text reply is marked delivered, the question stays open. A gone asker's answer goes to the newest live agent in the same directory (a restarted lane), else it stays listed. Each answer is pushed once." })
|
|
7065
|
+
.option("undelivered", { type: "boolean", default: false, describe: "With --pending: the sweep — only answers that have reached nobody yet. With --push, also why (asker gone and no live agent in its directory, or ay refused)." })
|
|
6981
7066
|
.option("watch", { type: "boolean", default: false, describe: "With --pending --push: keep running — a pass every --interval, and one for a question as soon as the relay rings for it (SLACK_RELAY_URL / SLACK_RELAY_TOKEN). Prints only what it pushed." })
|
|
6982
7067
|
.option("interval", { type: "number", default: 10, describe: "With --watch: minutes between full passes" })
|
|
6983
7068
|
.option("since", { type: "string", default: "7d", describe: "With --pending: how far back to look (30m, 2h, 7d, or an ISO date)" })
|
|
@@ -7027,7 +7112,7 @@ async function main(): Promise<void> {
|
|
|
7027
7112
|
console.error("Error: --watch keeps pushing answers — use it with --push.");
|
|
7028
7113
|
process.exit(ASK_EXIT_ERROR);
|
|
7029
7114
|
}
|
|
7030
|
-
const p: Parameters<typeof cmdAskPending>[1] = { sinceMs, json: !!argv.json, push: !!argv.push };
|
|
7115
|
+
const p: Parameters<typeof cmdAskPending>[1] = { sinceMs, json: !!argv.json, push: !!argv.push, undelivered: !!argv.undelivered };
|
|
7031
7116
|
if (argv.channel) p.channel = String(argv.channel);
|
|
7032
7117
|
// The collect run must read with the same workspace this one does.
|
|
7033
7118
|
if (argv.workspace) p.selfArgs = ["-w", String(argv.workspace)];
|
package/ts/sentlog.ts
CHANGED
|
@@ -74,6 +74,9 @@ export interface SentRow {
|
|
|
74
74
|
* the same answer is not pushed twice. */
|
|
75
75
|
pushed_at?: number | null;
|
|
76
76
|
pushed_answer?: string | null;
|
|
77
|
+
/** The `slack @<who>` identity it was asked as: a push pass reads the
|
|
78
|
+
* question with that token, whichever identity the pass itself runs as. */
|
|
79
|
+
identity?: string | null;
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
export function attributionEnabled(): boolean {
|
|
@@ -245,7 +248,8 @@ CREATE TABLE IF NOT EXISTS sent (
|
|
|
245
248
|
delivered_answer TEXT,
|
|
246
249
|
delivered_cursor TEXT,
|
|
247
250
|
pushed_at INTEGER,
|
|
248
|
-
pushed_answer TEXT
|
|
251
|
+
pushed_answer TEXT,
|
|
252
|
+
identity TEXT
|
|
249
253
|
);
|
|
250
254
|
CREATE INDEX IF NOT EXISTS sent_msg ON sent(channel, ts);
|
|
251
255
|
CREATE INDEX IF NOT EXISTS sent_at ON sent(sent_at);
|
|
@@ -268,7 +272,7 @@ export function openSentLog(): Db | undefined {
|
|
|
268
272
|
db.exec(SCHEMA);
|
|
269
273
|
// Columns added after the table first shipped. ALTER fails harmlessly when
|
|
270
274
|
// the column is already there.
|
|
271
|
-
for (const col of ["delivered_answer TEXT", "delivered_cursor TEXT", "pushed_at INTEGER", "pushed_answer TEXT"]) {
|
|
275
|
+
for (const col of ["delivered_answer TEXT", "delivered_cursor TEXT", "pushed_at INTEGER", "pushed_answer TEXT", "identity TEXT"]) {
|
|
272
276
|
try { db.exec(`ALTER TABLE sent ADD COLUMN ${col}`); } catch { /* exists */ }
|
|
273
277
|
}
|
|
274
278
|
return db;
|
|
@@ -302,12 +306,12 @@ export function recordSent(r: RecordSent): boolean {
|
|
|
302
306
|
try {
|
|
303
307
|
const a = r.attribution;
|
|
304
308
|
db.prepare(
|
|
305
|
-
`INSERT INTO sent (kind, team, channel, target, ts, thread_ts, permalink, text, sent_at, pid, agent_pid, host, cwd, git_branch, cli, session_id, as_bot)
|
|
306
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
309
|
+
`INSERT INTO sent (kind, team, channel, target, ts, thread_ts, permalink, text, sent_at, pid, agent_pid, host, cwd, git_branch, cli, session_id, as_bot, identity)
|
|
310
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
307
311
|
).run(
|
|
308
312
|
r.kind, r.team ?? null, r.channel, r.target ?? null, r.ts, r.threadTs ?? null, r.permalink ?? null, r.text,
|
|
309
313
|
Date.now(), a.pid, a.agentPid ?? null, a.host || null, a.cwd, a.gitBranch ?? null, a.cli ?? null, a.sessionId ?? null,
|
|
310
|
-
r.asBot ? 1 : 0,
|
|
314
|
+
r.asBot ? 1 : 0, process.env.SLACK_TERM_IDENTITY || null,
|
|
311
315
|
);
|
|
312
316
|
return true;
|
|
313
317
|
} catch (e: unknown) {
|
|
@@ -422,6 +426,20 @@ export function markAskPushed(channel: string, ts: string, answer: string): void
|
|
|
422
426
|
);
|
|
423
427
|
}
|
|
424
428
|
|
|
429
|
+
/** Which `slack @<who>` can read an ask logged before identities were recorded. */
|
|
430
|
+
export function markAskIdentity(channel: string, ts: string, identity: string): void {
|
|
431
|
+
updateLog(`UPDATE sent SET identity = ? WHERE kind = 'ask' AND channel = ? AND ts = ?`, identity, channel, ts);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** A push pass found the question already settled in Slack (✅ stamped
|
|
435
|
+
* elsewhere, or voided): nothing is left to look at, so later passes skip it. */
|
|
436
|
+
export function markAskSettled(channel: string, ts: string, exit: number): void {
|
|
437
|
+
updateLog(
|
|
438
|
+
`UPDATE sent SET collected_at = COALESCE(collected_at, ?), answer_exit = ? WHERE kind = 'ask' AND channel = ? AND ts = ?`,
|
|
439
|
+
Date.now(), exit, channel, ts,
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
425
443
|
/** Logged asks nobody has collected yet, oldest first. `undefined` when the
|
|
426
444
|
* log cannot be opened at all (no SQLite in this runtime). */
|
|
427
445
|
export function uncollectedAsks(sinceMs: number): SentRow[] | undefined {
|