Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions changes/feat-session-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Changed — may break callers

- **`tg session list` lists the profiles on this computer, and `tg account list` is gone** (WC-ACCT-12, WC-CMD-8).
It answers the same rows, takes the same query (`profile:`, `current:`) and needs no profile. There is no alias:
a script that runs `tg account list` must say `tg session list`. `account show`, `account update`,
`account sessions` and the rest of `account` stay.
- **The store moves to version 77** on its first open (cli-core 1.1.0 and 1.2.0). Like every store migration it only
goes forward.

### Added

- **`tg <profile> session status` says whether the profile is logged in, and as whom**, from this computer alone.
`--check` asks the messenger whether the session still works, and leaves the phone number out (`account show`
has it). From cli-core 1.3.0 (was 1.0.0).
2 changes: 1 addition & 1 deletion contracts/help.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Works with:
linear Linear issues and projects, searchable with your other WireCat data

Start here: tg personal setup (any profile name works)
tg account list your profiles and their logged-in accounts
tg session list your profiles and their logged-in accounts
Next: tg commands every command, by section
tg guide scenarios: command sequences for common tasks
tg help options output, offline, timeouts, dry run
Expand Down
32 changes: 23 additions & 9 deletions contracts/wirecat.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,37 @@
},
{
"path": [
"setup"
"session",
"status"
],
"summary": "set up Telegram and connect your agent",
"summary": "show whether this profile is logged in, and as whom",
"effects": {
"remote": "write",
"local": "write"
"remote": "read",
"local": "read"
}
},
{
"path": [
"account",
"session",
"list"
],
"summary": "profiles on this computer and their signed-in accounts",
"summary": "list the profiles on this computer and the account each is logged in as",
"effects": {
"remote": "read",
"remote": "none",
"local": "read"
},
"permission": "account.list",
"entity": "account_profile"
},
{
"path": [
"setup"
],
"summary": "set up Telegram and connect your agent",
"effects": {
"remote": "write",
"local": "write"
}
},
{
"path": [
"account",
Expand Down Expand Up @@ -7399,6 +7409,8 @@
"label",
"list",
"is",
"type",
"reach",
"chat",
"date",
"source",
Expand Down Expand Up @@ -7442,6 +7454,8 @@
"label",
"list",
"is",
"type",
"reach",
"chat",
"date",
"source",
Expand Down Expand Up @@ -7649,7 +7663,7 @@
"tagline": "Your Telegram account, searchable on your computer",
"profiles": {
"args": [
"account",
"session",
"list",
"--no-record",
"--json"
Expand Down
48 changes: 31 additions & 17 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tg [profile] [options] <resource> <verb> [arguments]
profile `work`. `TG_PROFILE` does the same for a whole shell session. **No profile is assumed**, not even
the only one: without either, a command that uses an account stops with exit 2 and lists the profiles on
this computer. Commands that use no
account (`--help`, `--version`, `commands`, `skill show`, `account list`, `config show`) run
account (`--help`, `--version`, `commands`, `skill show`, `session list`, `config show`) run
without one.

## Options for every command
Expand Down Expand Up @@ -82,6 +82,36 @@ tg session end

**Example:** `tg personal session end`

### `tg session status`

show whether this profile has a session on this computer and the account it was logged in as; --check asks the messenger whose the session is, without the phone number (`account show` has it)

```sh
tg session status [options]
```

| Option | What it does |
|---|---|
| `--check` | ask the messenger whether the session still works, and whose it is. |

**Example:** `tg personal session status`, `tg personal session status --check --json`

### `tg session list`

every account profile on this computer, and the account each is logged in as; a name that is only a bot is left out (`bot list` has it), one that is a bot too says `bot: true`; asks the messenger nothing

```sh
tg session list [query]
```

| Argument | | What it is |
|---|---|---|
| `query` | optional | field:value terms that narrow the list — the fields are below. |

**Returns:** account profile — profile, current, account, name, signed_in, bot; every field: tg commands info session list

**Example:** `tg session list`, `tg session list --json`

## `tg setup`

set up Telegram and connect your agent
Expand All @@ -104,22 +134,6 @@ tg setup [options]

the logged-in account

### `tg account list`

every account profile on this computer, and the account each is logged in as; a name that is only a bot is left out (`bot list` has it), one that is a bot too says `bot: true`; asks the messenger nothing

```sh
tg account list [query]
```

| Argument | | What it is |
|---|---|---|
| `query` | optional | field:value terms that narrow the list — the fields are below. |

**Returns:** account profile — profile, current, account, name, signed_in, bot; every field: tg commands info account list

**Example:** `tg personal account list`

### `tg account show`

who this profile is logged in as, with the phone number
Expand Down
6 changes: 4 additions & 2 deletions docs/dev/test-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ran it · ⛔ not tested offline, with the reason and where it is checked instea
Measured from the test run (`coverage/argv.jsonl`), not searched for — see
[TESTING.md](TESTING.md) for how, and for the states and failures that cut across commands.

**2413 ✅ · 155 ⛔ · 0 ❌** — 547 commands, 2021 options.
**2415 ✅ · 155 ⛔ · 0 ❌** — 548 commands, 2022 options.

| Command | Option | | Note |
|---|---|---|---|
Expand All @@ -16,11 +16,13 @@ Measured from the test run (`coverage/argv.jsonl`), not searched for — see
| `session start` | `--sms` | ✅ | |
| `session start` | `--answer-stdin` | ✅ | |
| `session end` | | ✅ | |
| `session status` | | ✅ | |
| `session status` | `--check` | ✅ | |
| `session list` | | ✅ | |
| `setup` | | ✅ | |
| `setup` | `--agent` | ✅ | |
| `setup` | `--app` | ✅ | |
| `setup` | `--method` | ✅ | |
| `account list` | | ✅ | |
| `account show` | | ✅ | |
| `account show` | `--hide-phone` | ✅ | |
| `account update` | | ✅ | |
Expand Down
2 changes: 1 addition & 1 deletion docs/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ of account settings.
The catalogue includes read and write commands, subject to the profile permissions and exclusions below. Read-only access is a choice you configure in those permissions. A few commands are never offered, and you run them in a
terminal:

- **Login and setup**: `setup`, `session start|end`, `complete`, `mcp config|add|check|revoke`,
- **Login and setup**: `setup`, `session start|status|list|end`, `complete`, `mcp config|add|check|revoke`,
`bot auth set|show|remove`, `bot mcp config`. An agent call cannot use them, or they need you at the keyboard.
`mcp` and `bot mcp` alone only print their help.
- **Removing an account**: `account remove` signs a profile out and forgets it on this computer, so only you start
Expand Down
4 changes: 2 additions & 2 deletions docs/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ settings, and how to switch to a bot.
| Give your agent fewer rights than you have | A profile with its own [permissions](permissions.md) |
| Keep an agent on that one profile | `TG_PROFILE_LOCK` ([profiles in login and sessions](sessions.md#profiles)) |
| Run a Telegram bot next to your account | A bot profile: `tg support bot api get-me` |
| See every profile on this computer | `tg account list` |
| See every profile on this computer | `tg session list` |

## Choose a profile

Expand All @@ -27,7 +27,7 @@ Put the profile name before the command:
tg work config show
```

`tg account list` shows every profile on this computer and the account each is logged in as;
`tg session list` shows every profile on this computer and the account each is logged in as;
`tg work session end` logs the profile `work` out.

A setting under `profiles.work` in the config file applies to that profile; values under `defaults`
Expand Down
4 changes: 2 additions & 2 deletions docs/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ If your account has a two-step password (2FA), `tg` asks for it after the scan.

```sh
tg personal account show # who this profile is logged in as
tg account list # every profile on this computer, and the account each is logged in as
tg session list # every profile on this computer, and the account each is logged in as
tg personal account sessions list # every device and app logged in to the account; ends nothing
tg personal session end # log out on Telegram's side, and delete the session file here
```
Expand Down Expand Up @@ -223,7 +223,7 @@ The order, first match wins: the first word, then `TG_PROFILE`. With
none of them, a command that uses an account stops with exit code `2` and lists the profiles on this
computer; with none there yet, it says to run `tg personal setup`. `tg` never picks one, not even the
only one. Commands that use no account run without a profile: `--help`, `--version`, `commands`,
`skill show`, `account list` and `config show`.
`skill show`, `session list` and `config show`.

A word that is not a command and has no command after it is an error that says so:

Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ tg personal account show --hide-phone # the same without the phone number
```

```sh
tg account list # every profile on this computer and the account each is logged in as
tg session list # every profile on this computer and the account each is logged in as
```

```sh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"dependencies": {
"@mtcute/node": "0.32.7",
"@wirecat/cli-base": "1.0.0",
"@wirecat/cli-core": "1.0.0",
"@wirecat/cli-core": "1.3.0",
"commander": "15.0.0",
"undici": "8.12.3",
"valibot": "1.5.0"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tg [profile] [options] <resource> <verb> [arguments]
profile \`work\`. \`TG_PROFILE\` does the same for a whole shell session. **No profile is assumed**, not even
the only one: without either, a command that uses an account stops with exit 2 and lists the profiles on
this computer. Commands that use no
account (\`--help\`, \`--version\`, \`commands\`, \`skill show\`, \`account list\`, \`config show\`) run
account (\`--help\`, \`--version\`, \`commands\`, \`skill show\`, \`session list\`, \`config show\`) run
without one.`,
globalHeading: "Options for every command",
globalIntro: "",
Expand Down
2 changes: 1 addition & 1 deletion skills/tg-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for a write to Telegram); `tg <command> --help` is shorter; `tg guide` lists sce

**The first word is the profile when it is not a command.** `tg work chats list` is profile `work`. There is
no `--profile` flag; `TG_PROFILE` does the same. No profile is assumed: without one, an account command exits
`2` and lists the profiles (`tg account list` shows them too). **Never pick one for the owner**; ask which,
`2` and lists the profiles (`tg session list` shows them too). **Never pick one for the owner**; ask which,
unless the task or `TG_PROFILE` says. `personal` below stands for the profile the owner chose.

## Answer a question from the chats
Expand Down
32 changes: 32 additions & 0 deletions src/commands/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,35 @@ describe("session end", () => {
},
)
})

describe("session status and session list", () => {
it("**says a profile with no session is not logged in**, even with --check, asking Telegram nothing", async () => {
const asked = () =>
scripted({
login: async () => {
throw new Error("must not ask Telegram")
},
})

for (const argv of [
["fresh", "session", "status", "--json=profile,signed_in,verified"],
["fresh", "session", "status", "--check", "--json=profile,signed_in,verified"],
]) {
const { code, stdout } = await tg(argv, { adapter: asked })
expect(code).toBe(0)
expect(JSON.parse(stdout.join("\n")).item).toMatchObject({ profile: "fresh", signed_in: false, verified: false })
}
})

it("**lists the profiles with no profile named**, and `account list` is gone", async () => {
const { TG_PROFILE: _, ...unnamed } = process.env

const listed = await tg(["session", "list", "--json=profile,account"], { env: unnamed })
const gone = await tg(["account", "list", "--json=profile"], { env: unnamed })

expect(listed.stderr).toEqual([])
expect(listed.code).toBe(0)
expect(Array.isArray(JSON.parse(listed.stdout.join("\n")).items)).toBe(true)
expect(gone.code).not.toBe(0)
})
})
4 changes: 3 additions & 1 deletion src/commands/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
environmentOf,
logsInOrOut,
mayRevoke,
messengerSessionCommands,
printItem,
REMOTE_WRITE,
refuseCommandName,
Expand All @@ -28,7 +29,7 @@ import { SHELL_OVERRIDES } from "../contract-overrides.js"
import { usesOwnersSession } from "../paths.js"
import { type ApiCredentials, parseApiHash, parseApiId } from "../telegram/credentials.js"
import { MY_TELEGRAM, registerApp } from "../telegram/registration.js"
import { type CommandContext, type Environment, forCommand } from "./context.js"
import { type CommandContext, type Environment, forCommand, TELEGRAM } from "./context.js"

/** `field` names the question for a window that answers it (`--answer-stdin`). */
type Ask = (prompt: string, echo: boolean, field: string) => Promise<string>
Expand Down Expand Up @@ -343,6 +344,7 @@ const sessionCommandDefinition = () => {
printItem(context, { profile: context.profile, ended: true })
})

for (const command of messengerSessionCommands(TELEGRAM)) session.addCommand(command)
return session
}

Expand Down
Loading