slack-term 1.55.2 → 1.57.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/ts/identity.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  // `slack @<who> <command> …` — name the identity a command acts as (11-02):
2
2
  // a bot (`@deploy-bot`, `@ops-bot`) or a person (`@alice`). Replaces --as-bot /
3
3
  // --as-user and env-file juggling. The names map to WHERE a token lives (an
4
- // env var, optionally in an env file, or a slack-term profile) — never to the
4
+ // env var, optionally in an env file, or a slack-hub profile) — never to the
5
5
  // token itself, which stays in the env/vault:
6
6
  //
7
- // identities: # .slack-term/settings.yml or ~/.config/slack-term/settings.yml
7
+ // identities: # .slack-hub/settings.yml or ~/.config/slack-hub/settings.yml
8
8
  // deploy-bot: { kind: bot, env_file: ~/.config/slack-cli/deploy-bot.env } # SLACK_BOT_TOKEN in it
9
9
  // ops-bot: { kind: bot, env_file: ~/.config/slack-cli/ops-bot.env }
10
10
  // alice: { kind: user, profile: acme } # slack auth profile
@@ -12,6 +12,7 @@
12
12
  // And the trap it closes (11-02: an agent's `slack ask` without --as-bot was
13
13
  // posted AS a person): a write that would go out as a person's session is refused
14
14
  // from inside an agent, or when several identities exist, unless it names one.
15
+ // From an agent, --as-user is not enough (11-12): it must name the person.
15
16
  import { readFileSync } from "node:fs";
16
17
  import { homedir } from "node:os";
17
18
  import { join } from "node:path";
@@ -23,7 +24,7 @@ export type Identity = {
23
24
  env?: string;
24
25
  /** An env file to read that var from; else the process environment. */
25
26
  env_file?: string;
26
- /** A user: a slack-term workspace profile (`slack auth ls`). */
27
+ /** A user: a slack-hub workspace profile (`slack auth ls`). */
27
28
  profile?: string;
28
29
  };
29
30
 
@@ -88,13 +89,13 @@ function readEnvFile(path: string): Record<string, string> {
88
89
  * error naming the known identities. */
89
90
  export function applyIdentity(who: string, env: NodeJS.ProcessEnv = process.env, ids = listIdentities()): { kind: "bot" | "user" } | { error: string } {
90
91
  const id = ids.get(who);
91
- const known = [...ids.keys()].sort().map((n) => `@${n}`).join(", ") || "(none: add `identities:` to .slack-term/settings.yml)";
92
+ const known = [...ids.keys()].sort().map((n) => `@${n}`).join(", ") || "(none: add `identities:` to .slack-hub/settings.yml)";
92
93
  if (!id) return { error: `unknown identity @${who}. Known: ${known}` };
93
94
  if (id.kind === "user" && id.profile && !id.env && !id.env_file) {
94
95
  env.SLACK_WORKSPACE = id.profile;
95
96
  delete env.SLACK_TOKEN;
96
97
  delete env.SLACK_BOT_TOKEN;
97
- env.SLACK_TERM_IDENTITY = who;
98
+ env.SLACK_HUB_IDENTITY = who;
98
99
  return { kind: "user" };
99
100
  }
100
101
  const name = id.env ?? (id.kind === "bot" ? "SLACK_BOT_TOKEN" : "SLACK_TOKEN");
@@ -114,7 +115,7 @@ export function applyIdentity(who: string, env: NodeJS.ProcessEnv = process.env,
114
115
  env.SLACK_TOKEN = token;
115
116
  delete env.SLACK_BOT_TOKEN;
116
117
  }
117
- env.SLACK_TERM_IDENTITY = who;
118
+ env.SLACK_HUB_IDENTITY = who;
118
119
  return { kind: id.kind };
119
120
  }
120
121
 
@@ -124,21 +125,31 @@ export function inAgent(env: NodeJS.ProcessEnv = process.env): string | undefine
124
125
  }
125
126
 
126
127
  /** Why a write that would post as a PERSON's session is refused, or null.
127
- * Allowed when it names an identity (`@who`), says --as-bot or --as-user, or
128
- * the active token is a bot's anyway. */
128
+ * Allowed when it names an identity (`@who`), says --as-bot, or the active
129
+ * token is a bot's anyway. `--as-user` is a person's own switch: inside an
130
+ * agent it no longer counts (11-12: lanes added it by habit, and their posts
131
+ * went out under the person's name). An agent that must act as a person names
132
+ * that person's identity (`slack @alice …`), so the command line says who, and
133
+ * the sent log records it. A person at a terminal keeps --as-user as is. */
129
134
  export function userSessionRefusal(o: {
130
135
  isWrite: boolean; who?: string | undefined; asBot: boolean; asUser: boolean; activeIsBot: boolean;
131
- agent?: string | undefined; identities: string[]; cmd: string;
136
+ agent?: string | undefined; identities: string[]; userIdentities?: string[]; cmd: string;
132
137
  }): string | null {
133
- if (!o.isWrite || o.who || o.asBot || o.asUser || o.activeIsBot) return null;
138
+ if (!o.isWrite || o.who || o.asBot || o.activeIsBot) return null;
139
+ const users = o.userIdentities ?? [];
140
+ if (o.asUser && !o.agent) return null; // a person at a terminal: their own call
134
141
  const names = o.identities.map((n) => `@${n}`).join(" | ");
135
- const pick = names ? ` Name who acts: slack ${o.identities[0] ? `@${o.identities[0]}` : "@<who>"} ${o.cmd} … (${names})` : " Add identities to .slack-term/settings.yml, then: slack @<who> " + o.cmd + " …";
142
+ const pick = names ? ` Name who acts: slack ${o.identities[0] ? `@${o.identities[0]}` : "@<who>"} ${o.cmd} … (${names})` : " Add identities to .slack-hub/settings.yml, then: slack @<who> " + o.cmd + " …";
136
143
  if (o.agent) {
144
+ const person = users.length
145
+ ? ` As a person, on purpose: slack @${users[0]} ${o.cmd} … (${users.map((n) => `@${n}`).join(" | ")})`
146
+ : " As a person, on purpose: add them to `identities:` (kind: user), then slack @<name> " + o.cmd + " …";
137
147
  return [
138
148
  `Error: refusing to post as the user session from inside an agent (${o.agent} is set): \`${o.cmd}\` would go out as a PERSON.`,
149
+ ...(o.asUser ? [" --as-user is not accepted from an agent: it hides whose name the post goes out under."] : []),
139
150
  pick,
140
151
  " As the app: add --as-bot",
141
- " As the person, on purpose: add --as-user",
152
+ person,
142
153
  ].join("\n");
143
154
  }
144
155
  if (o.identities.length >= 2) {
package/ts/inbox.ts CHANGED
@@ -1,4 +1,4 @@
1
- // .slack-term/ inbox and outbox: one file per message, written tmp + rename.
1
+ // .slack-hub/ inbox and outbox: one file per message, written tmp + rename.
2
2
  //
3
3
  // inbox/<channel>-<ts>.yml a text-only notification (who, where, text,
4
4
  // permalink; attachments only counted). Secrets are redacted before it is
package/ts/locales.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Language packs: locales/<lang>.json in the package, overridden key by key by
2
- // the nearest .slack-term/locales/<lang>.json. They hold only what slack-term
2
+ // the nearest .slack-hub/locales/<lang>.json. They hold only what slack-hub
3
3
  // posts to PEOPLE (slack ask's copy) and the patterns it looks for in their
4
4
  // messages (the choice-question hint); the CLI's own text is English, in code.
5
5
  //
package/ts/profiles.ts CHANGED
@@ -8,21 +8,22 @@
8
8
  // Token resolution order (no --workspace flag):
9
9
  // 1. process.env SLACK_TOKEN or SLACK_BOT_TOKEN
10
10
  // 2. process.env SLACK_MCP_XOXP_TOKEN (legacy, yields to profiles if any exist)
11
- // 3. Dir walk from cwd→$HOME: .slack-term/.env.local, then .env.local (modern env-file names only)
11
+ // 3. Dir walk from cwd→$HOME: .slack-hub/.env.local, then .env.local (modern env-file names only)
12
12
  // Note: cli.ts loadDotenvFiles() has already loaded cwd/.env.local into process.env (#1 catches
13
- // that case), so the walk's extra value is finding .slack-term/ variants and parent-dir files.
14
- // 4. ~/.slack-term/.env.local (global slack-term config)
13
+ // that case), so the walk's extra value is finding .slack-hub/ variants and parent-dir files.
14
+ // 4. ~/.slack-hub/.env.local (global slack-hub config)
15
15
  // 5. profiles.json via SLACK_WORKSPACE / lockfiles
16
16
  // 6. throw with auth help
17
17
  //
18
18
  // --workspace flag skips #2-4 and goes straight to profiles.json.
19
19
  //
20
20
  // Note: lockfiles and profiles.json use .slack-cli/ (older name); new per-dir token storage
21
- // uses .slack-term/ (current project name). Both coexist intentionally.
21
+ // uses .slack-hub/ (current project name; a legacy .slack-term/ is still read). Both coexist intentionally.
22
22
 
23
23
  import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync } from "node:fs";
24
24
  import { homedir } from "node:os";
25
25
  import { join, dirname } from "node:path";
26
+ import { LEGACY_SCOPE_DIR, preferExisting, SCOPE_DIR } from "./brand.ts";
26
27
 
27
28
  export type Profile = {
28
29
  token: string;
@@ -115,14 +116,14 @@ function readEnvFile(filePath: string): Record<string, string> {
115
116
  }
116
117
  }
117
118
 
118
- /** Walk from startDir up to $HOME checking .slack-term/.env.local then .env.local.
119
+ /** Walk from startDir up to $HOME checking .slack-hub/.env.local then .env.local.
119
120
  * Returns first value found for any of the given keys. */
120
121
  function walkDirEnv(startDir: string, keys: string[]): string | undefined {
121
122
  const homeDir = home();
122
123
  let dir = startDir;
123
124
 
124
125
  while (true) {
125
- for (const subdir of [join(dir, ".slack-term", ".env.local"), join(dir, ".env.local")]) {
126
+ for (const subdir of [join(dir, SCOPE_DIR, ".env.local"), join(dir, LEGACY_SCOPE_DIR, ".env.local"), join(dir, ".env.local")]) {
126
127
  const vars = readEnvFile(subdir);
127
128
  for (const key of keys) {
128
129
  if (vars[key]) return vars[key];
@@ -134,8 +135,8 @@ function walkDirEnv(startDir: string, keys: string[]): string | undefined {
134
135
  dir = parent;
135
136
  }
136
137
 
137
- // Global slack-term config — separate from the walk, checked after $HOME
138
- const globalVars = readEnvFile(join(homeDir, ".slack-term", ".env.local"));
138
+ // Global slack-hub config — separate from the walk, checked after $HOME
139
+ const globalVars = readEnvFile(preferExisting(join(homeDir, SCOPE_DIR, ".env.local"), join(homeDir, LEGACY_SCOPE_DIR, ".env.local")));
139
140
  for (const key of keys) {
140
141
  if (globalVars[key]) return globalVars[key];
141
142
  }
@@ -333,7 +334,7 @@ export function resolveToken(workspaceFlag?: string): string {
333
334
  " slack auth cookie — attach the xoxd cookie from Chrome (macOS/Windows)\n" +
334
335
  " slack auth firefox — attach the xoxd cookie from Firefox (all platforms)\n" +
335
336
  " slack auth token --token xoxp-... — paste an existing token\n" +
336
- " Or set SLACK_TOKEN=xoxp-... in .slack-term/.env.local",
337
+ " Or set SLACK_TOKEN=xoxp-... in .slack-hub/.env.local",
337
338
  );
338
339
  }
339
340
 
package/ts/redact.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Secret redaction for anything slack-term writes to disk (the .slack-term/
1
+ // Secret redaction for anything slack-hub writes to disk (the .slack-hub/
2
2
  // inbox/outbox): each secret becomes `[redacted:<rule id>]`, and the original
3
3
  // never touches the file. `slack read` fetches the real text live.
4
4
  //
package/ts/relay.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Client for the slack-term relay (worker/): a Cloudflare Worker that receives
1
+ // Client for the slack-hub relay (worker/): a Cloudflare Worker that receives
2
2
  // Slack's Events API and serves "doorbells" — {channel, ts, thread_ts}, never
3
3
  // message text — as a resumable stream. `slack stream` uses it to scan the one
4
4
  // channel a bell names within a second of the post, instead of waiting for its
@@ -75,7 +75,9 @@ export function parseSse(buf: string, emit: (event: string, data: string, id: st
75
75
  }
76
76
 
77
77
  /** The subprotocol the relay's /ws speaks; it echoes this one back. */
78
- export const WS_PROTOCOL = "slack-term-relay.v1";
78
+ export const WS_PROTOCOL = "slack-hub-relay.v1";
79
+ /** Also offered, so a relay deployed before the slack-hub rename still accepts us. */
80
+ export const LEGACY_WS_PROTOCOL = "slack-term-relay.v1";
79
81
 
80
82
  /** The subprotocol that carries the bearer token: subprotocols must be HTTP
81
83
  * tokens, so the token is base64url-encoded. */
@@ -152,7 +154,7 @@ function wsSubscribe(
152
154
  if (signal.aborted) return resolve(true);
153
155
  let ws: WebSocketLike;
154
156
  try {
155
- ws = new WS(`${base.replace(/^http/i, "ws")}/ws${resumeQuery(after)}`, [WS_PROTOCOL, bearerProtocol(token)]);
157
+ ws = new WS(`${base.replace(/^http/i, "ws")}/ws${resumeQuery(after)}`, [WS_PROTOCOL, LEGACY_WS_PROTOCOL, bearerProtocol(token)]);
156
158
  } catch {
157
159
  return resolve(false);
158
160
  }
package/ts/relayInit.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // `slack relay init` / `slack relay health`: set up and check the doorbell
2
2
  // relay without cloning this repo.
3
3
  //
4
- // The relay's code ships in the npm package as `slack-term/worker`
4
+ // The relay's code ships in the npm package as `slack-hub/worker`
5
5
  // (worker/src/), so a deployable Worker is a two-line re-export plus a
6
6
  // wrangler.jsonc. `init` writes that folder — local files only, no network,
7
7
  // nothing that touches Slack — and prints a fresh RELAY_TOKEN with the next
@@ -17,8 +17,8 @@ import pkg from "../package.json" with { type: "json" };
17
17
  export const WRANGLER_VERSION = "4.105.0";
18
18
  /** worker/wrangler.jsonc's compatibility_date. */
19
19
  export const COMPATIBILITY_DATE = "2026-07-01";
20
- export const DEFAULT_DIR = "slack-term-relay";
21
- export const RELAY_DOCS_URL = "https://github.com/snomiao/slack-term/blob/main/worker/README.md";
20
+ export const DEFAULT_DIR = "slack-hub-relay";
21
+ export const RELAY_DOCS_URL = "https://github.com/snomiao/slack-hub/blob/main/worker/README.md";
22
22
 
23
23
  /** A Workers script name: lowercase letters, digits and dashes, 1–63 chars,
24
24
  * no leading or trailing dash. */
@@ -35,25 +35,25 @@ export function workerNameFrom(dir: string): string {
35
35
  export type ScaffoldOptions = {
36
36
  /** Worker name; default: the directory's basename. */
37
37
  name?: string;
38
- /** The `slack-term` dependency spec; default: `^` this CLI's version (a source
38
+ /** The `slack-hub` dependency spec; default: `^` this CLI's version (a source
39
39
  * checkout carries a stale placeholder version; the range still resolves). */
40
- slackTerm?: string;
40
+ slackHub?: string;
41
41
  };
42
42
 
43
43
  /** The scaffold's files, relative path → content. */
44
- export function relayFiles(name: string, opts: { slackTerm?: string } = {}): Record<string, string> {
44
+ export function relayFiles(name: string, opts: { slackHub?: string } = {}): Record<string, string> {
45
45
  const packageJson = {
46
46
  name,
47
47
  private: true,
48
48
  type: "module",
49
49
  scripts: { deploy: "wrangler deploy", dev: "wrangler dev --local" },
50
- dependencies: { "slack-term": opts.slackTerm ?? `^${pkg.version}` },
50
+ dependencies: { "slack-hub": opts.slackHub ?? `^${pkg.version}` },
51
51
  devDependencies: { wrangler: WRANGLER_VERSION },
52
52
  engines: { node: ">=22" },
53
53
  };
54
54
  return {
55
55
  "package.json": `${JSON.stringify(packageJson, null, 2)}\n`,
56
- "wrangler.jsonc": `// slack-term relay: Slack Events API -> doorbells for \`slack stream\`.
56
+ "wrangler.jsonc": `// slack-hub relay: Slack Events API -> doorbells for \`slack stream\`.
57
57
  // Secrets (not in this file): wrangler secret put SLACK_SIGNING_SECRET / RELAY_TOKEN / SLACK_TEAM_ID (optional)
58
58
  {
59
59
  "$schema": "node_modules/wrangler/config-schema.json",
@@ -69,9 +69,9 @@ export function relayFiles(name: string, opts: { slackTerm?: string } = {}): Rec
69
69
  "observability": { "enabled": false }
70
70
  }
71
71
  `,
72
- "src/index.ts": `// The relay lives in the slack-term package. Relay (the Durable Object class)
72
+ "src/index.ts": `// The relay lives in the slack-hub package. Relay (the Durable Object class)
73
73
  // must be exported from this main module for the RELAY binding to find it.
74
- export { default, Relay } from "slack-term/worker";
74
+ export { default, Relay } from "slack-hub/worker";
75
75
  `,
76
76
  ".gitignore": "node_modules/\n.wrangler/\n.dev.vars*\n.env*\n",
77
77
  "README.md": readme(name),
@@ -109,9 +109,9 @@ export function nextSteps(name: string, token?: string): string {
109
109
  function readme(name: string): string {
110
110
  return `# ${name}
111
111
 
112
- A [slack-term](https://github.com/snomiao/slack-term) relay: a Cloudflare Worker
112
+ A [slack-hub](https://github.com/snomiao/slack-hub) relay: a Cloudflare Worker
113
113
  that turns Slack's Events API into a resumable doorbell stream for
114
- \`slack stream\`. The code is the \`slack-term/worker\` export; this folder only
114
+ \`slack stream\`. The code is the \`slack-hub/worker\` export; this folder only
115
115
  configures and deploys it. Created by \`slack relay init\`.
116
116
 
117
117
  ## Set up
@@ -123,7 +123,7 @@ where messages are posted.
123
123
 
124
124
  ## Update
125
125
 
126
- Bump \`slack-term\` in package.json, \`npm install\`, \`npx wrangler deploy\`.
126
+ Bump \`slack-hub\` in package.json, \`npm install\`, \`npx wrangler deploy\`.
127
127
  Storage survives redeploys; clients reconnect and resume.
128
128
 
129
129
  Details (endpoints, privacy, protocol): ${RELAY_DOCS_URL}
@@ -145,7 +145,7 @@ export function initRelay(
145
145
  if (!validWorkerName(name)) {
146
146
  return { ok: false, error: `invalid worker name "${name}": use lowercase letters, digits and dashes (1-63 chars, no leading/trailing dash)` };
147
147
  }
148
- const files = relayFiles(name, opts.slackTerm !== undefined ? { slackTerm: opts.slackTerm } : {});
148
+ const files = relayFiles(name, opts.slackHub !== undefined ? { slackHub: opts.slackHub } : {});
149
149
  const root = resolve(dir);
150
150
  const existing = Object.keys(files).filter((f) => existsSync(join(root, f)));
151
151
  if (existing.length && !opts.force) {
@@ -201,7 +201,7 @@ export async function relayHealth(
201
201
  try {
202
202
  json = JSON.parse(body) as typeof json;
203
203
  } catch {
204
- return { code: 1, out: `slack relay health: not a slack-term relay (non-JSON reply from ${target})` };
204
+ return { code: 1, out: `slack relay health: not a slack-hub relay (non-JSON reply from ${target})` };
205
205
  }
206
206
  return { code: json.ok === true ? 0 : 1, out: JSON.stringify(json, null, 2) };
207
207
  } catch (e) {
package/ts/scope.ts CHANGED
@@ -1,9 +1,9 @@
1
- // `.slack-term/` — per-directory state, found like `.git`: the nearest one
1
+ // `.slack-hub/` — per-directory state, found like `.git`: the nearest one
2
2
  // walking up from the cwd is the scope, so each lane's tree (or repo) owns its
3
3
  // own aliases and settings without a pid, an env var or a daemon. No
4
- // `.slack-term/` anywhere up the tree falls back to ~/.config/slack-term/.
4
+ // `.slack-hub/` anywhere up the tree falls back to ~/.config/slack-hub/.
5
5
  //
6
- // .slack-term/
6
+ // .slack-hub/
7
7
  // README.md what this is (written on init)
8
8
  // .gitignore "*" — nothing in here is ever committed
9
9
  // settings.yml written by people: prefix, channel, as_bot, subscriptions
@@ -17,25 +17,28 @@
17
17
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
18
18
  import { homedir } from "node:os";
19
19
  import { dirname, join, resolve } from "node:path";
20
+ import { hubEnv, LEGACY_SCOPE_DIR, namedDir, SCOPE_DIR, scopeDirIn } from "./brand.ts";
20
21
 
21
- export const SCOPE_DIR = ".slack-term";
22
+ export { SCOPE_DIR };
22
23
  export const SCOPE_SUBDIRS = ["inbox", "archived", "outbox", "sent"] as const;
23
24
 
24
25
  export type Scope = { dir: string; global: boolean };
25
26
 
26
- /** The global fallback: ~/.config/slack-term (SLACK_TERM_HOME overrides, for tests). */
27
+ /** The global fallback: ~/.config/slack-hub (SLACK_HUB_HOME overrides, for tests). */
27
28
  export function globalScopeDir(): string {
28
- return process.env.SLACK_TERM_HOME ?? join(homedir(), ".config", "slack-term");
29
+ return hubEnv("HOME") ?? namedDir(join(homedir(), ".config"));
29
30
  }
30
31
 
31
- /** The nearest `.slack-term/` at or above `cwd`, else the global one. */
32
+ /** The nearest `.slack-hub/` at or above `cwd`, else the global one. */
32
33
  export function findScope(cwd = process.cwd()): Scope {
33
34
  let d = resolve(cwd);
34
35
  for (;;) {
35
- const c = join(d, SCOPE_DIR);
36
- try {
37
- if (statSync(c).isDirectory()) return { dir: c, global: false };
38
- } catch { /* not here */ }
36
+ for (const name of [SCOPE_DIR, LEGACY_SCOPE_DIR]) {
37
+ const c = join(d, name);
38
+ try {
39
+ if (statSync(c).isDirectory()) return { dir: c, global: false };
40
+ } catch { /* not here */ }
41
+ }
39
42
  const up = dirname(d);
40
43
  if (up === d) break;
41
44
  d = up;
@@ -43,12 +46,12 @@ export function findScope(cwd = process.cwd()): Scope {
43
46
  return { dir: globalScopeDir(), global: true };
44
47
  }
45
48
 
46
- const README = `# .slack-term/
49
+ const README = `# .slack-hub/
47
50
 
48
- State for [slack-term](https://github.com/snomiao/slack-term) in this directory.
49
- \`slack\` uses the nearest \`.slack-term/\` walking up from where it runs (like
51
+ State for [slack-hub](https://github.com/snomiao/slack-hub) in this directory.
52
+ \`slack\` uses the nearest \`.slack-hub/\` walking up from where it runs (like
50
53
  \`.git\`), so everything below this directory shares it. Without one it uses
51
- ~/.config/slack-term/.
54
+ ~/.config/slack-hub/.
52
55
 
53
56
  Nothing here is committed: \`.gitignore\` holds \`*\`.
54
57
 
@@ -87,7 +90,7 @@ subscriptions count, \`slack alias set\` refuses (the owner uses \`--shared\`),
87
90
  slack alias who <channel> <ts> # which dirs subscribe a thread
88
91
  `;
89
92
 
90
- const SETTINGS = `# slack-term settings for this directory. settings.local.yml (written by
93
+ const SETTINGS = `# slack-hub settings for this directory. settings.local.yml (written by
91
94
  # \`slack alias\`) has the same keys and wins over this file.
92
95
  #
93
96
  # prefix: "[lane]" # put in front of every \`slack reply\`; never doubled
@@ -125,9 +128,9 @@ export type Settings = {
125
128
  owner?: string;
126
129
  };
127
130
 
128
- /** Create (or complete) `<parent>/.slack-term/`. Idempotent: existing files are kept. */
131
+ /** Create (or complete) `<parent>/.slack-hub/`. Idempotent: existing files are kept. */
129
132
  export function initScope(parent: string, settings: Omit<Settings, "subscriptions"> = {}): { dir: string; created: string[] } {
130
- const dir = join(resolve(parent), SCOPE_DIR);
133
+ const dir = scopeDirIn(resolve(parent));
131
134
  const created: string[] = [];
132
135
  mkdirSync(dir, { recursive: true });
133
136
  for (const sub of SCOPE_SUBDIRS) {
@@ -386,13 +389,13 @@ export class RestrictedError extends Error {
386
389
  }
387
390
  }
388
391
 
389
- // --- the registry: every .slack-term/ on this machine, for the relay fan-out ---
392
+ // --- the registry: every .slack-hub/ on this machine, for the relay fan-out ---
390
393
 
391
394
  function registryPath(): string {
392
395
  return join(globalScopeDir(), "scopes");
393
396
  }
394
397
 
395
- /** Remember `dir` (a .slack-term/ path) so a stream can deliver into it. */
398
+ /** Remember `dir` (a .slack-hub/ path) so a stream can deliver into it. */
396
399
  export function registerScope(dir: string): void {
397
400
  const p = registryPath();
398
401
  withFileLock(p, () => {
package/ts/sentlog.ts CHANGED
@@ -9,19 +9,20 @@
9
9
  // Two places, on purpose:
10
10
  // - a local SQLite log (~/.config/slack-cli/sent.sqlite), which `slack sent`
11
11
  // and `slack ask --pending` read;
12
- // - Slack message `metadata` (event_type `slack_term_sent`), invisible to
12
+ // - Slack message `metadata` (event_type `slack_hub_sent`), invisible to
13
13
  // readers but returned by the API, so a machine WITHOUT the log can still
14
14
  // attribute a message.
15
15
  //
16
16
  // Everything here is fail-soft. A message that was posted must never be
17
17
  // reported as failed because the bookkeeping about it failed.
18
18
  //
19
- // Opt out with SLACK_TERM_ATTRIBUTION=off (no log, no metadata).
19
+ // Opt out with SLACK_HUB_ATTRIBUTION=off (no log, no metadata).
20
20
 
21
21
  import { spawnSync } from "node:child_process";
22
22
  import { chmodSync, existsSync, mkdirSync } from "node:fs";
23
23
  import { homedir, hostname } from "node:os";
24
24
  import { basename, dirname, join } from "node:path";
25
+ import { hubEnv } from "./brand.ts";
25
26
 
26
27
  export type SentKind = "send" | "ask" | "edit" | "poll";
27
28
 
@@ -80,7 +81,7 @@ export interface SentRow {
80
81
  }
81
82
 
82
83
  export function attributionEnabled(): boolean {
83
- return !/^(0|off|false|no)$/i.test(process.env.SLACK_TERM_ATTRIBUTION ?? "");
84
+ return !/^(0|off|false|no)$/i.test(hubEnv("ATTRIBUTION") ?? "");
84
85
  }
85
86
 
86
87
  // --- attribution -------------------------------------------------------------
@@ -133,15 +134,15 @@ function positiveInt(s: string | undefined): number | undefined {
133
134
  * (`claude-code_<version>_agent`). Other CLIs are recognised by the process
134
135
  * name of an ancestor; their session ids are not read because their variable
135
136
  * names were not verified. A wrapper that knows better sets the overrides:
136
- * SLACK_TERM_AGENT_CLI, SLACK_TERM_AGENT_SESSION, SLACK_TERM_AGENT_PID. */
137
+ * SLACK_HUB_AGENT_CLI, SLACK_HUB_AGENT_SESSION, SLACK_HUB_AGENT_PID. */
137
138
  export function captureAttribution(env: NodeJS.ProcessEnv = process.env): Attribution {
138
139
  const a: Attribution = { pid: process.pid, host: safeHostname(), cwd: process.cwd() };
139
140
 
140
- let cli = env.SLACK_TERM_AGENT_CLI || undefined;
141
+ let cli = hubEnv("AGENT_CLI", env) || undefined;
141
142
  if (!cli && env.AI_AGENT) cli = env.AI_AGENT.split("_")[0] || undefined;
142
143
  if (!cli && env.CLAUDECODE === "1") cli = "claude-code";
143
144
 
144
- let agentPid = positiveInt(env.SLACK_TERM_AGENT_PID) ?? positiveInt(env.CLAUDE_PID);
145
+ let agentPid = positiveInt(hubEnv("AGENT_PID", env)) ?? positiveInt(env.CLAUDE_PID);
145
146
  if (!agentPid || !cli) {
146
147
  const anc = findAgentAncestor();
147
148
  if (anc) {
@@ -152,7 +153,7 @@ export function captureAttribution(env: NodeJS.ProcessEnv = process.env): Attrib
152
153
  if (cli) a.cli = cli;
153
154
  if (agentPid) a.agentPid = agentPid;
154
155
 
155
- const session = env.SLACK_TERM_AGENT_SESSION || env.CLAUDE_CODE_SESSION_ID;
156
+ const session = hubEnv("AGENT_SESSION", env) || env.CLAUDE_CODE_SESSION_ID;
156
157
  if (session) a.sessionId = session;
157
158
 
158
159
  const branch = gitBranch(a.cwd);
@@ -180,7 +181,7 @@ function gitBranch(cwd: string): string | undefined {
180
181
 
181
182
  /** Slack message metadata: invisible in the client, returned by the API
182
183
  * (`include_all_metadata`). Only defined fields — Slack rejects nulls. */
183
- export const METADATA_EVENT_TYPE = "slack_term_sent";
184
+ export const METADATA_EVENT_TYPE = "slack_hub_sent";
184
185
 
185
186
  export function attributionMetadata(kind: SentKind, a: Attribution): { event_type: string; event_payload: Record<string, string | number> } {
186
187
  const p: Record<string, string | number> = { kind, pid: a.pid, host: a.host, cwd: a.cwd };
@@ -198,7 +199,8 @@ interface Stmt { run(...p: unknown[]): unknown; all(...p: unknown[]): unknown[];
198
199
  interface Db { exec(sql: string): void; prepare(sql: string): Stmt; close(): void; }
199
200
 
200
201
  export function sentDbPath(): string {
201
- if (process.env.SLACK_TERM_SENT_DB) return process.env.SLACK_TERM_SENT_DB;
202
+ const db = hubEnv("SENT_DB");
203
+ if (db) return db;
202
204
  return join(process.env.HOME || homedir(), ".config", "slack-cli", "sent.sqlite");
203
205
  }
204
206
 
@@ -311,7 +313,7 @@ export function recordSent(r: RecordSent): boolean {
311
313
  ).run(
312
314
  r.kind, r.team ?? null, r.channel, r.target ?? null, r.ts, r.threadTs ?? null, r.permalink ?? null, r.text,
313
315
  Date.now(), a.pid, a.agentPid ?? null, a.host || null, a.cwd, a.gitBranch ?? null, a.cli ?? null, a.sessionId ?? null,
314
- r.asBot ? 1 : 0, process.env.SLACK_TERM_IDENTITY || null,
316
+ r.asBot ? 1 : 0, hubEnv("IDENTITY") || null,
315
317
  );
316
318
  return true;
317
319
  } catch (e: unknown) {
package/ts/stream.ts CHANGED
@@ -208,7 +208,7 @@ export type StreamOpts = {
208
208
  };
209
209
 
210
210
  /** Where the real-time setup is documented — the polling warning points here. */
211
- export const RELAY_DOCS = "https://github.com/snomiao/slack-term/blob/main/worker/README.md";
211
+ export const RELAY_DOCS = "https://github.com/snomiao/slack-hub/blob/main/worker/README.md";
212
212
 
213
213
  export const PHI = 1.618;
214
214
  /** Relay bells handled per turn of the loop before the poll gets a look in. */
package/worker/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # slack-term relay
1
+ # slack-hub relay
2
2
 
3
3
  A Cloudflare Worker that turns Slack's **Events API** into a resumable stream of
4
4
  *doorbells* for `slack stream`. Slack posts each event to the Worker; the Worker
@@ -45,7 +45,7 @@ all (an older relay, a proxy that strips upgrades, a runtime without
45
45
  | Path | Auth | What |
46
46
  |---|---|---|
47
47
  | `POST /slack/events` | Slack signing secret (`X-Slack-Signature`, ±5 min) | Answers `url_verification`; stores one bell per `message` / `app_mention` event. Acks with a single SQLite insert, well inside Slack's 3 s. Retries collapse on `(channel, ts)`. |
48
- | `GET /ws?after=<seq>&epoch=<e>` | Subprotocols `slack-term-relay.v1` **and** `bearer.<base64url($RELAY_TOKEN)>` (or `Authorization: Bearer`) | WebSocket (below). Rejected with 401 before the upgrade is accepted. |
48
+ | `GET /ws?after=<seq>&epoch=<e>` | Subprotocols `slack-hub-relay.v1` (or the pre-rename `slack-term-relay.v1`) **and** `bearer.<base64url($RELAY_TOKEN)>` (or `Authorization: Bearer`) | WebSocket (below). Rejected with 401 before the upgrade is accepted. |
49
49
  | `GET /stream?after=<seq>` | `Authorization: Bearer $RELAY_TOKEN` | SSE (kept for older clients). First an `event: hello` frame `{seq, gap, retention_sec}`, then the backlog after `seq`, then live `event: bell` frames (`id:` = seq). A keepalive comment goes out every 25 s. `Last-Event-ID` works as well as `?after`. Pass `&epoch=` from the last hello: the epoch names the relay's storage, so a client resuming against a reset relay is told `gap: true` and gets everything kept, even once the new numbers have passed its old seq. If `after` is omitted, the stream starts from now. `gap: true` means some bells after `after` are gone (expired, or the relay was reset): everything still kept is replayed, and the client should also catch up by polling. |
50
50
  | `GET /health` | Bearer | `{epoch, latest, oldest, clients, websocket_clients, sse_clients, retention_sec}` |
51
51
 
@@ -55,11 +55,11 @@ At most 16 clients (both kinds) at once; more get 503.
55
55
 
56
56
  **Auth.** The token is never put in the URL (query strings end up in logs).
57
57
  Node's built-in `WebSocket` cannot send an `Authorization` header, so the client
58
- offers two subprotocols — `Sec-WebSocket-Protocol: slack-term-relay.v1,
58
+ offers three subprotocols — `Sec-WebSocket-Protocol: slack-hub-relay.v1, slack-term-relay.v1,
59
59
  bearer.<base64url(token)>` (base64url because subprotocols must be HTTP tokens;
60
60
  the same scheme Kubernetes uses) — and the Worker compares the bearer one in
61
61
  constant time before the request reaches the Durable Object. The server
62
- selects only `slack-term-relay.v1`, never echoing the token.
62
+ selects only `slack-hub-relay.v1` (or `slack-term-relay.v1` for an old client), never echoing the token.
63
63
 
64
64
  **Messages** are JSON text, one per frame:
65
65
 
@@ -109,17 +109,17 @@ a hibernating object runs no timers.
109
109
 
110
110
  ### Without cloning (recommended)
111
111
 
112
- The relay ships in the npm package as `slack-term/worker`. Scaffold a Worker
112
+ The relay ships in the npm package as `slack-hub/worker`. Scaffold a Worker
113
113
  folder with the CLI:
114
114
 
115
115
  ```sh
116
- slack relay init my-relay # or: npx slack-term relay init my-relay
116
+ slack relay init my-relay # or: npx slack-hub relay init my-relay
117
117
  cd my-relay && npm install
118
118
  npx wrangler login # or CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID (below)
119
119
  npx wrangler deploy
120
120
  ```
121
121
 
122
- `init` writes `package.json` (slack-term as `^` the CLI's version, wrangler
122
+ `init` writes `package.json` (slack-hub as `^` the CLI's version, wrangler
123
123
  pinned), `wrangler.jsonc` (the same config as this folder's, with `--name` or
124
124
  the folder's name), `src/index.ts`, `.gitignore` and a `README.md`. It makes no
125
125
  network calls and refuses to overwrite existing files unless `--force`. It
@@ -130,15 +130,15 @@ as described below (run them from the new folder, with `npx wrangler`).
130
130
  Already have a Worker project? `src/index.ts` is just
131
131
 
132
132
  ```ts
133
- export { default, Relay } from "slack-term/worker";
133
+ export { default, Relay } from "slack-hub/worker";
134
134
  ```
135
135
 
136
136
  with a `RELAY` Durable Object binding to class `Relay` and a
137
137
  `new_sqlite_classes: ["Relay"]` migration — copy them from
138
138
  [`wrangler.jsonc`](wrangler.jsonc). `Env` is exported too, for typing.
139
- `@cloudflare/workers-types` is an optional peer dependency of slack-term.
139
+ `@cloudflare/workers-types` is an optional peer dependency of slack-hub.
140
140
 
141
- To update, bump `slack-term` in the folder's package.json and redeploy.
141
+ To update, bump `slack-hub` in the folder's package.json and redeploy.
142
142
 
143
143
  ### From a clone of this repo (contributors)
144
144
 
package/worker/src/hub.ts CHANGED
@@ -60,7 +60,11 @@ export interface Store {
60
60
  }
61
61
 
62
62
  /** The subprotocol a client must offer; the server echoes it back. */
63
- export const PROTOCOL = "slack-term-relay.v1";
63
+ export const PROTOCOL = "slack-hub-relay.v1";
64
+ /** Pre-rename name, still accepted from clients older than the slack-hub rename. */
65
+ export const LEGACY_PROTOCOL = "slack-term-relay.v1";
66
+ /** Accepted subprotocols, preferred first. */
67
+ export const PROTOCOLS: readonly string[] = [PROTOCOL, LEGACY_PROTOCOL];
64
68
  /** The other offered subprotocol carries the bearer: `bearer.<base64url(token)>`.
65
69
  * A header, not the URL: query strings end up in logs. */
66
70
  export const BEARER_PREFIX = "bearer.";
@@ -92,7 +96,7 @@ export function protocolAuthorized(header: string | null, token: string): boolea
92
96
  let ours = false;
93
97
  for (const p of header.split(",")) {
94
98
  const v = p.trim();
95
- if (v === PROTOCOL) ours = true;
99
+ if (PROTOCOLS.includes(v)) ours = true;
96
100
  if (safeEqual(v, want)) ok = true;
97
101
  }
98
102
  return ok && ours;
@@ -1,4 +1,4 @@
1
- // slack-term relay — a Cloudflare Worker that turns Slack's Events API into a
1
+ // slack-hub relay — a Cloudflare Worker that turns Slack's Events API into a
2
2
  // resumable doorbell stream for `slack stream`.
3
3
  //
4
4
  // Slack ──POST /slack/events──▶ Worker ──▶ Relay (Durable Object, SQLite)
@@ -238,8 +238,9 @@ export class Relay extends DurableObject<Env> {
238
238
  const [client, server] = Object.values(new WebSocketPair()) as [WebSocket, WebSocket];
239
239
  this.ctx.acceptWebSocket(server);
240
240
  hub.open(this.sock(server), from, hello, this.store, now);
241
- const offered = (req.headers.get("sec-websocket-protocol") ?? "").split(",").some((p) => p.trim() === hub.PROTOCOL);
242
- return new Response(null, { status: 101, webSocket: client, headers: offered ? { "sec-websocket-protocol": hub.PROTOCOL } : {} });
241
+ const offered = (req.headers.get("sec-websocket-protocol") ?? "").split(",").map((p) => p.trim());
242
+ const pick = hub.PROTOCOLS.find((p) => offered.includes(p));
243
+ return new Response(null, { status: 101, webSocket: client, headers: pick ? { "sec-websocket-protocol": pick } : {} });
243
244
  }
244
245
 
245
246
  const { readable, writable } = new TransformStream<Uint8Array, Uint8Array>();