Skip to content

Report the logged-in user and emit login and logout - #10

Merged
thisnick merged 1 commit into
mainfrom
feat/login-identity-logout
Nov 10, 2026
Merged

thisnick merged 1 commit into
mainfrom
feat/login-identity-logout

Conversation

@thisnick

@thisnick thisnick commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Implements the three features Huan asked for before the first npm release: current-user information, the login event and the logout event. Builds on #9 (Node.js 26).

Current user

login still fires as soon as the phone confirms, with the account's username. A background profile lookup (one contact request for our own username) then gives contactPayload(currentUserId):

  • the nickname as name
  • the WeChat ID as weixin, when set
  • the avatar URL

Login never waits for the lookup and can't fail because of it. If the lookup fails, name falls back to the WeChat ID, then to the username. The example prints Logged in as <name>.

Logout

Each session emits logout exactly once:

Cause Reason
stop() puppet stop()
logout(reason): submits WeChat's logout request once (prepare_logout().submit()), then emits the given reason
WeChat rejects heartbeat or sync with -13 and also rejects one automatic renewal, e.g. after a sign-out from the phone WeChat ended the session, with no error
any other failure after login an error event, then Neo session failed

Before this, a session WeChat had ended only emitted error and left isLoggedIn true.

Other changes:

  • If the notification socket closes, Neo reconnects once and lets a heartbeat decide whether the session is still valid.
  • Sends never use renewal.
  • stop() now closes the native session, so its credentials are released right away.
  • After a logout the puppet stays started; stop and start it for a new QR.

Spotting -13 matches error text, the same rule the agent-wechat daemon uses. PendingLogout::submit is async-only, so the addon builds a single-thread tokio runtime just for that call. thisnick/agent-wechat#455 tracks typed errors and a blocking logout in wechat-protocol, so both can be swapped out later.

Example fix

The example's error handler read data, but wechaty-puppet always rewrites error events to { gerror }, so it printed undefined. It now prints the gerror message.

Validation

Offline:

  • Rust: Clippy with warnings as errors, plus 4 tests, including new ones for -13 detection and session close.
  • npm test and npm run test:package on Node 26: 7 tests, 4 of them new. They cover login before the profile, the nickname and fallback names, and one logout each for stop, logout(), a session WeChat ended, and an unexpected failure.

Live, on Linux x64 with an isolated test account:

  • The fresh QR login fired login immediately. contactPayload() returned the account's nickname and avatar about 1.2 s later.
  • A new ding was answered with dong.
  • Signing the device out from the phone produced one logout with reason WeChat ended the session and no error.

The bot-side logout() path, which submits WeChat's logout request, is covered by the scripted tests but hasn't been run against WeChat yet.

The spec's acceptance steps, the release-gate table and the README now describe this lifecycle.

🤖 Generated with Claude Code

Base automatically changed from chore/node-26-baseline to main November 10, 2026 22:25
The login event still fires as soon as the phone confirms, with the
account's username. A background profile lookup then gives
contactPayload(currentUserId) the nickname as name and the WeChat ID as
weixin, falling back to the WeChat ID or username if it fails. The
example prints "Logged in as <name>".

Each session now emits logout exactly once:
- stop(): "puppet stop()"
- logout(reason): submits WeChat's logout request once, then emits the
  reason
- WeChat rejects heartbeat or sync with -13 and rejects one automatic
  renewal: "WeChat ended the session", with no error event
- any other failure after login: an error event, then
  "Neo session failed"

Before, a session WeChat had ended only emitted error and left
isLoggedIn true. A closed notification socket now reconnects once and
lets a heartbeat decide. Stopping closes the native session so its
credentials are released right away.

The example's error handler read the deprecated data field, which
wechaty-puppet always replaces with gerror. It now prints the gerror
message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thisnick
thisnick force-pushed the feat/login-identity-logout branch from 789f4db to b9e35fb Compare November 10, 2026 22:26
@thisnick
thisnick merged commit aea74c7 into main Nov 10, 2026
11 checks passed
@thisnick
thisnick deleted the feat/login-identity-logout branch November 10, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant