slack-term 1.55.2 → 1.55.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slack-term",
3
- "version": "1.55.2",
3
+ "version": "1.55.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/snomiao/slack-term.git"
package/ts/cli.ts CHANGED
@@ -3693,11 +3693,15 @@ async function cmdAsk(token: string, args: AskArgs): Promise<void> {
3693
3693
  // Same silent-delivery footgun as `send`: Slack never notifies you about your
3694
3694
  // own message, so a question asked in your own DM is delivered and then never
3695
3695
  // seen — and `--wait` would sit there until it timed out.
3696
+ // From an agent it is refused (11-12: an agent holding the person's session
3697
+ // posted it under their name); a person at a terminal is only warned.
3698
+ const agent = inAgent();
3696
3699
  if (!args.asBot && !!selfId && counterpart === selfId) {
3697
3700
  console.error(
3698
- `Warning: "${args.target}" is a DM to yourself — Slack will NOT notify you of your own message.\n` +
3699
- ` To reach yourself with a notification, ask as the bot: slack ask '${args.target}' '...' --as-bot`,
3701
+ `${agent ? "Error" : "Warning"}: "${args.target}" is a DM to yourself — Slack will NOT notify you of your own message.\n` +
3702
+ ` To reach yourself with a notification, ask as the bot: slack @<bot> ask '${args.target}' '...' (or --as-bot)`,
3700
3703
  );
3704
+ if (agent) process.exit(ASK_EXIT_ERROR);
3701
3705
  }
3702
3706
 
3703
3707
  // --- who may answer -------------------------------------------------------
@@ -3730,6 +3734,18 @@ async function cmdAsk(token: string, args: AskArgs): Promise<void> {
3730
3734
  // and posting anyway would silently drop someone the caller meant to ask.
3731
3735
  askRefuseUnresolved(unresolved);
3732
3736
 
3737
+ // An agent asking the person whose session it holds (11-12: it tagged that
3738
+ // person in the bot's DM, so the question went out under the name of the
3739
+ // one it asked). The bot asks the person; a person asks others.
3740
+ const taggedSelf = !!selfId && (resolved.some((r) => r.userId === selfId) || new RegExp(`<@${selfId}(?:\\|[^>]*)?>`).test(`${question}\n${body}`));
3741
+ if (agent && !args.asBot && taggedSelf) {
3742
+ console.error(
3743
+ `Error: \`ask\` would post as you (${selfId}) a question addressed to you — the asker and the one asked are the same person.\n` +
3744
+ ` To ask yourself, ask as the bot: slack @<bot> ask '${args.target}' '${args.question}' (or --as-bot)\n` +
3745
+ ` To ask someone else as yourself, tag them, not you.`,
3746
+ );
3747
+ process.exit(ASK_EXIT_ERROR);
3748
+ }
3733
3749
  const broadcast = broadcastKinds.size > 0;
3734
3750
  // Tagging yourself grants nothing — your own reactions are the seeds.
3735
3751
  const audience = new Set(resolved.map((r) => r.userId).filter((id) => id !== selfId));
@@ -6130,7 +6146,7 @@ async function main(): Promise<void> {
6130
6146
  process.exit(1);
6131
6147
  })
6132
6148
  .option("workspace", { alias: "w", type: "string", describe: "Workspace name" })
6133
- .option("as-user", { type: "boolean", describe: "Act as the user session on purpose (needed for writes from inside an agent, or when several identities exist)" })
6149
+ .option("as-user", { type: "boolean", describe: "Act as the user session on purpose (not accepted for writes from inside an agent: name the person with slack @<who>)" })
6134
6150
  .middleware(async (argv) => {
6135
6151
  const cmd = String((argv._ ?? [])[0] ?? "");
6136
6152
  // `@bot`: commands that have --as-bot act as the bot; `@user`: never.
@@ -6159,11 +6175,13 @@ async function main(): Promise<void> {
6159
6175
  console.error(refusal);
6160
6176
  process.exit(2);
6161
6177
  }
6178
+ const ids = listIdentities();
6162
6179
  const user = userSessionRefusal({
6163
6180
  isWrite: isWriteCommand(argv._ ?? []) && !isReadMode(argv._ ?? [], argv as Record<string, unknown>),
6164
6181
  who, asBot: argv["as-bot"] === true, asUser: argv["as-user"] === true,
6165
6182
  activeIsBot: active.startsWith("xoxb-"),
6166
- agent: inAgent(), identities: [...listIdentities().keys()].sort(),
6183
+ agent: inAgent(), identities: [...ids.keys()].sort(),
6184
+ userIdentities: [...ids].filter(([, id]) => id.kind === "user").map(([n]) => n).sort(),
6167
6185
  cmd: (argv._ ?? []).slice(0, 2).join(" "),
6168
6186
  });
6169
6187
  if (user) {
package/ts/identity.ts CHANGED
@@ -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";
@@ -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
142
  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 + " …";
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) {