slack-term 1.57.1 → 1.58.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/dist/cli.js +278 -271
- package/package.json +15 -7
- package/ts/ask.ts +41 -0
- package/ts/askPush.ts +21 -17
- package/ts/asyncArgs.ts +21 -0
- package/ts/cli.ts +275 -36
- package/ts/profiles.ts +19 -7
- package/ts/slack.ts +124 -11
- package/worker/src/index.ts +27 -0
- package/worker/src/router/admin.ts +80 -0
- package/worker/src/router/core.ts +1222 -0
- package/worker/src/router/do.ts +355 -0
- package/worker/src/router/fetch.ts +76 -0
- package/worker/src/router/intake.ts +82 -0
- package/worker/src/router/wire.ts +401 -0
- package/worker/src/slack.ts +3 -2
- package/worker/README.md +0 -216
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slack-term",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.58.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/snomiao/slack-hub.git"
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"@types/bun": "latest",
|
|
17
17
|
"@types/node": "^22",
|
|
18
18
|
"@types/yargs": "^17.0.35",
|
|
19
|
-
"@
|
|
20
|
-
"@vitest/coverage-istanbul": "4.1.10",
|
|
19
|
+
"@vitest/coverage-istanbul": "4.1.11",
|
|
21
20
|
"semantic-release": "^24",
|
|
21
|
+
"tsrs": "0.25.0-ts7.1.0-beta",
|
|
22
22
|
"typescript": "^5.6",
|
|
23
|
-
"vitest": "4.1.
|
|
23
|
+
"vitest": "4.1.11"
|
|
24
24
|
},
|
|
25
25
|
"bin": {
|
|
26
26
|
"slack": "./ts/cli.ts"
|
|
@@ -64,9 +64,10 @@
|
|
|
64
64
|
"scripts": {
|
|
65
65
|
"dev": "bun run ts/cli.ts",
|
|
66
66
|
"build": "bun build ts/cli.ts --target=node --outfile dist/cli.js --minify",
|
|
67
|
-
"typecheck": "
|
|
67
|
+
"typecheck": "tsrs --noEmit",
|
|
68
68
|
"typecheck:tsc": "tsc --noEmit",
|
|
69
|
-
"typecheck:worker": "bun install --cwd worker --frozen-lockfile &&
|
|
69
|
+
"typecheck:worker": "bun install --cwd worker --frozen-lockfile && tsrs --noEmit -p worker && tsrs --noEmit -p worker/test",
|
|
70
|
+
"test:worker": "bun install --cwd worker --frozen-lockfile && cd worker && node node_modules/vitest/vitest.mjs run",
|
|
70
71
|
"test": "bun test tests/ --timeout 90000 --parallel=2",
|
|
71
72
|
"test:watch": "bun test tests/ --timeout 90000 --isolate --watch",
|
|
72
73
|
"test:parity": "bash tests/parity.sh",
|
|
@@ -76,7 +77,7 @@
|
|
|
76
77
|
"scan-pii:all": "bash .githooks/pre-commit --all",
|
|
77
78
|
"prepare": "git config core.hooksPath .githooks 2>/dev/null || true",
|
|
78
79
|
"prepublishOnly": "bun run scan-pii:all && bun run typecheck && bun run build",
|
|
79
|
-
"test:coverage": "vitest run --coverage --exclude tests/parity.test.ts --no-file-parallelism"
|
|
80
|
+
"test:coverage": "vitest run --coverage --exclude tests/parity.test.ts --exclude 'tests/parity/**' --no-file-parallelism"
|
|
80
81
|
},
|
|
81
82
|
"type": "module",
|
|
82
83
|
"dependencies": {
|
|
@@ -89,5 +90,12 @@
|
|
|
89
90
|
"@cloudflare/workers-types": {
|
|
90
91
|
"optional": true
|
|
91
92
|
}
|
|
93
|
+
},
|
|
94
|
+
"rustify": {
|
|
95
|
+
"mode": "hybrid",
|
|
96
|
+
"bins": {
|
|
97
|
+
"slack": "slack"
|
|
98
|
+
},
|
|
99
|
+
"rootEnv": "SLACK_HUB_PACKAGE_ROOT"
|
|
92
100
|
}
|
|
93
101
|
}
|
package/ts/ask.ts
CHANGED
|
@@ -868,3 +868,44 @@ export function askNextPollDelay(prevMs: number, elapsedMs: number): number {
|
|
|
868
868
|
const cap = elapsedMs < ASK_POLL.fastWindowMs ? ASK_POLL.fastMaxMs : ASK_POLL.slowMaxMs;
|
|
869
869
|
return Math.min(Math.max(prevMs, ASK_POLL.minMs) * ASK_POLL.phi, cap);
|
|
870
870
|
}
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
/** `--timeout` for ask: plain seconds, a duration (90s / 30m / 2h / 1d), or
|
|
874
|
+
* forever|never|inf (= Infinity). undefined when it is none of those. */
|
|
875
|
+
export function parseAskTimeout(v: unknown): number | undefined {
|
|
876
|
+
const t = String(v ?? "").trim().toLowerCase();
|
|
877
|
+
if (["forever", "never", "inf", "infinity"].includes(t)) return Infinity;
|
|
878
|
+
if (/^\d+(\.\d+)?$/.test(t)) return Number(t);
|
|
879
|
+
const m = t.match(/^(\d+(?:\.\d+)?)(s|m|h|d)$/);
|
|
880
|
+
return m ? Number(m[1]) * { s: 1, m: 60, h: 3600, d: 86400 }[m[2] as "s" | "m" | "h" | "d"] : undefined;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/** Pull `--choices` out of the raw args after `ask` (`--choices=A|B`,
|
|
884
|
+
* `--choices A|B`, repeatable; split on |), and refuse `--question` /
|
|
885
|
+
* `--target`. All three name POSITIONALS, so yargs' .strict() takes them as
|
|
886
|
+
* known flags and lets the positional silently win — a question asked with
|
|
887
|
+
* --choices="A|B" went out with no buttons. Done before yargs sees the args:
|
|
888
|
+
* `rest` is the args with the --choices flags removed. */
|
|
889
|
+
export function askPositionalFlags(args: string[]): { choices: string[]; rest: string[] } | { error: string } {
|
|
890
|
+
const raw: string[] = [];
|
|
891
|
+
const rest: string[] = [];
|
|
892
|
+
for (let i = 0; i < args.length; i++) {
|
|
893
|
+
const a = args[i]!;
|
|
894
|
+
if (a === "--") { rest.push(...args.slice(i)); break; }
|
|
895
|
+
const m = a.match(/^--(choices|question|target)(?:=(.*))?$/s);
|
|
896
|
+
if (!m) { rest.push(a); continue; }
|
|
897
|
+
if (m[1] !== "choices") return { error: `--${m[1]} is not a flag: the ${m[1]} is positional — slack ask <target> "<question>" [choice…]` };
|
|
898
|
+
const val = m[2] ?? args[++i];
|
|
899
|
+
if (val === undefined || (m[2] === undefined && val.startsWith("--"))) return { error: "--choices needs a value, e.g. --choices \"Yes|No\" (or pass the choices as arguments after the question)" };
|
|
900
|
+
raw.push(val);
|
|
901
|
+
}
|
|
902
|
+
return { choices: raw.flatMap((v) => v.split("|")).map((c) => c.trim()).filter(Boolean), rest };
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/** "3600s" reads badly for the long waits --timeout now allows. */
|
|
906
|
+
export function askFormatTimeout(sec: number): string {
|
|
907
|
+
if (!Number.isFinite(sec)) return "forever";
|
|
908
|
+
if (sec >= 3600 && sec % 3600 === 0) return `${sec / 3600}h`;
|
|
909
|
+
if (sec >= 60 && sec % 60 === 0) return `${sec / 60}m`;
|
|
910
|
+
return `${sec}s`;
|
|
911
|
+
}
|
package/ts/askPush.ts
CHANGED
|
@@ -7,20 +7,14 @@
|
|
|
7
7
|
// lives here instead. The sent-log already holds the asking
|
|
8
8
|
// agent's pid, so slack-hub can tell it directly.
|
|
9
9
|
import { spawnSync, type SpawnSyncReturns } from "node:child_process";
|
|
10
|
-
import { closeSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { closeSync, chmodSync, mkdirSync, mkdtempSync, openSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { homedir, tmpdir } from "node:os";
|
|
12
|
-
import { dirname, resolve } from "node:path";
|
|
12
|
+
import { dirname, join, resolve } from "node:path";
|
|
13
13
|
import { pidAlive } from "./sentlog.ts";
|
|
14
14
|
import { hubEnv } from "./brand.ts";
|
|
15
15
|
|
|
16
16
|
/** ay rejects messages over 1024 chars. */
|
|
17
|
-
export const PUSH_MAX =
|
|
18
|
-
|
|
19
|
-
function clip(s: string, n: number): string {
|
|
20
|
-
const one = s.split(/\s+/).filter(Boolean).join(" ");
|
|
21
|
-
if (n <= 1) return "";
|
|
22
|
-
return one.length <= n ? one : `${one.slice(0, n - 1)}…`;
|
|
23
|
-
}
|
|
17
|
+
export const PUSH_MAX = 850;
|
|
24
18
|
|
|
25
19
|
/** An answer this much older than its push is labelled late. */
|
|
26
20
|
export const PUSH_LATE_MS = 60 * 60_000;
|
|
@@ -43,13 +37,13 @@ export function askPushTag(askedAtMs: number, answeredAtMs: number | undefined,
|
|
|
43
37
|
/** The one-line message the asker receives: link, answer, how, question. */
|
|
44
38
|
export function askPushMessage(p: { link: string; answer: string; how: string; question: string; freeText: boolean; collected?: boolean; goneAsker?: number; tag?: string }): string {
|
|
45
39
|
const head = `${p.tag ?? "[ask-answer]"} ${p.link} →`;
|
|
46
|
-
const ans =
|
|
40
|
+
const ans = p.answer;
|
|
47
41
|
let tail = p.how ? ` (${p.how})` : "";
|
|
48
42
|
if (p.freeText) tail += " — a free-text reply, not a choice: the question stays open";
|
|
49
43
|
else if (p.collected) tail += " — collected ✅";
|
|
50
44
|
if (p.goneAsker) tail += ` — asked by pid ${p.goneAsker}, now gone: sent to this lane by its directory`;
|
|
51
|
-
const q =
|
|
52
|
-
return `${head} ${ans}${tail}. Q: ${q}
|
|
45
|
+
const q = p.question.split(/\s+/).filter(Boolean).join(" ");
|
|
46
|
+
return `${head} ${ans}${tail}. Q: ${q}`;
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
type Run = (cmd: string, args: string[]) => Pick<SpawnSyncReturns<string>, "status" | "stdout" | "stderr" | "error">;
|
|
@@ -71,9 +65,19 @@ export function parentPid(pid: number): number {
|
|
|
71
65
|
* parents are tried too. Returns the pid that took it, or undefined. QUEUED
|
|
72
66
|
* and NOT SUBMITTED count as delivered: both reach the agent, and treating
|
|
73
67
|
* them as failures re-sent the same answer on every pass. */
|
|
74
|
-
export function notifyAgent(pid: number, msg: string, run: Run = runSync, parent = parentPid): number | undefined {
|
|
68
|
+
export function notifyAgent(pid: number, msg: string, run: Run = runSync, parent = parentPid, stateDir = join(process.env.XDG_STATE_HOME || join(homedir(), ".local", "state"), "slack-hub", "ask-inbox")): number | undefined {
|
|
69
|
+
let delivery = msg;
|
|
70
|
+
if (msg.length > PUSH_MAX) {
|
|
71
|
+
mkdirSync(stateDir, { recursive: true, mode: 0o700 });
|
|
72
|
+
chmodSync(stateDir, 0o700);
|
|
73
|
+
const dir = mkdtempSync(join(stateDir, "answer-"));
|
|
74
|
+
const file = join(dir, "message.txt");
|
|
75
|
+
writeFileSync(file, msg, { mode: 0o600 });
|
|
76
|
+
delivery = `[ask-answer] Full answer and question: ${JSON.stringify(file)}`;
|
|
77
|
+
if (delivery.length > PUSH_MAX) return undefined;
|
|
78
|
+
}
|
|
75
79
|
for (let i = 0; i < 4 && pid > 1; i++, pid = parent(pid)) {
|
|
76
|
-
const r = run(hubEnv("AY") || "ay", ["send", String(pid), "--force",
|
|
80
|
+
const r = run(hubEnv("AY") || "ay", ["send", String(pid), "--force", delivery]);
|
|
77
81
|
if (r.error) return undefined; // no ay on this machine
|
|
78
82
|
const out = `${r.stdout ?? ""}${r.stderr ?? ""}`;
|
|
79
83
|
if (/no agent matched/i.test(out)) continue;
|
|
@@ -95,15 +99,15 @@ export function liveAgents(run: Run = runSync): { pid: number; cwd: string; star
|
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
98
|
-
/** The live agent that took over a gone asker's lane: a lane restarts in the
|
|
99
|
-
* same directory, with a new pid.
|
|
102
|
+
/** The unique live agent that took over a gone asker's lane: a lane restarts in the
|
|
103
|
+
* same directory, with a new pid. Ambiguous successors are left undelivered. A shared
|
|
100
104
|
* directory (temp, home) says nothing about who asked, so it matches nobody. */
|
|
101
105
|
export function laneAgent(cwd: string, agents: { pid: number; cwd: string; started_at?: number }[], alive: (pid: number) => boolean = pidAlive): number | undefined {
|
|
102
106
|
const dir = resolve(cwd);
|
|
103
107
|
const tmp = resolve(tmpdir());
|
|
104
108
|
if (dir === resolve(homedir()) || dir === tmp || dir.startsWith(`${tmp}/`)) return undefined;
|
|
105
109
|
const here = agents.filter((a) => resolve(a.cwd.replace(/^~(?=\/|$)/, homedir())) === dir && alive(a.pid));
|
|
106
|
-
return here.
|
|
110
|
+
return here.length === 1 ? here[0]!.pid : undefined;
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
/** One push pass at a time per machine: a watcher and a one-off run must not
|
package/ts/asyncArgs.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Remove queue options while preserving the command's end-of-options boundary. */
|
|
2
|
+
export function asyncCommandArgs(args: string[]): { enabled: boolean; args: string[]; callback: string | null } {
|
|
3
|
+
const forwarded: string[] = [];
|
|
4
|
+
let enabled = false;
|
|
5
|
+
let help = false;
|
|
6
|
+
let callback: string | null = null;
|
|
7
|
+
for (let i = 0; i < args.length; i++) {
|
|
8
|
+
const arg = args[i]!;
|
|
9
|
+
if (arg === "--") { forwarded.push(...args.slice(i)); break; }
|
|
10
|
+
if (arg === "--async-callback") {
|
|
11
|
+
if (i + 1 === args.length || args[i + 1] === "--") throw new Error("--async-callback needs a command");
|
|
12
|
+
callback = args[++i]!;
|
|
13
|
+
} else if (arg.startsWith("--async-callback=")) callback = arg.slice("--async-callback=".length);
|
|
14
|
+
else if (arg === "--async") enabled = true;
|
|
15
|
+
else {
|
|
16
|
+
if (arg === "--help" || arg === "-h") help = true;
|
|
17
|
+
forwarded.push(arg);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return { enabled: enabled && !help, args: forwarded, callback };
|
|
21
|
+
}
|