# wild-work3/ww3-chatglm-cli architecture

> Architecture diagram of the GitHub repository wild-work3/ww3-chatglm-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wild-work3/ww3-chatglm-cli
- Repository: https://github.com/wild-work3/ww3-chatglm-cli

## Overview

chatglm-cli is a non-interactive Go CLI for ChatGLM’s private interfaces. Its main workflow reads a prompt, authenticates, streams conversation events as JSONL, and lets callers resume explicitly with a conversation ID. Separate command branches cover conversation management, account/model information, raw endpoint access, and image generation, including reference-image preparation and upload. The map reflects README-documented capabilities as well as sampled calls; unsampled command wiring is omitted where the excerpts do not establish it.

Main entry points: [`internal/cli/cli.go`](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cli.go) (Command dispatch), [`internal/cli/cmd_chat.go`](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_chat.go) (Chat command), [`internal/channel/imagesgen.go`](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/channel/imagesgen.go) (Image generation), [`internal/glm/client.go`](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/client.go) (HTTP API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI commands"]
  node_entry["CLI entry<br/>[main.go]"]
  node_commands["Command dispatch<br/>[cli.go]"]
  node_chatcmd["Chat command<br/>[cmd_chat.go]"]
  node_convcmd["Conversation commands<br/>[cmd_conv.go]"]
  node_infocmd["Account and model queries<br/>[cmd_info.go]"]
  node_rawcmd["Raw endpoint command<br/>[cmd_raw.go]"]
  node_imagecmd["Image command<br/>[cmd_chat.go]"]
end

subgraph group_glm["ChatGLM access"]
  node_credential["Credential loading<br/>[cred.go]"]
  node_auth["Token refresh<br/>[client.go]"]
  node_httpclient["HTTP API client<br/>[client.go]"]
  node_sse["SSE stream parsing<br/>[sse.go]"]
  node_chatgen["Chat generation<br/>[chatgen.go]"]
  node_convapi["Conversation history and control<br/>[history.go]"]
end

subgraph group_images["Image generation"]
  node_imagegen["Image generation<br/>[imagesgen.go]"]
  node_refsheet["Reference sheet builder<br/>[refsheet.go]"]
  node_upload["Image hosting upload<br/>[upload.go]"]
end

subgraph group_protocol["Output and IPC"]
  node_events["JSONL event output<br/>[jsonl.go]"]
  node_plugin["Plugin IPC runner<br/>[plugin.go]"]
end

node_user(("Human or agent"))
node_imagehost["Image hosting services"]
node_chatglm["ChatGLM service"]

node_user -->|"runs"| node_entry
node_entry -->|"starts"| node_commands
node_commands -->|"routes chat"| node_chatcmd
node_commands -->|"routes conv"| node_convcmd
node_commands -->|"routes info"| node_infocmd
node_commands -->|"routes raw"| node_rawcmd
node_chatcmd -->|"loads credentials"| node_credential
node_httpclient -->|"refreshes token"| node_auth
node_credential -->|"supplies credentials"| node_httpclient
node_chatcmd -->|"streams chat"| node_chatglm
node_chatcmd -.->|"parses stream"| node_sse
node_chatcmd -->|"emits JSONL"| node_events
node_convcmd -->|"reads and controls"| node_convapi
node_infocmd -->|"queries account data"| node_chatglm
node_rawcmd -.->|"sends endpoint request"| node_httpclient
node_imagecmd -->|"invokes image method"| node_plugin
node_plugin -.->|"dispatches method"| node_imagegen
node_imagegen -->|"builds reference sheet"| node_refsheet
node_imagegen -->|"uploads references"| node_upload
node_upload -->|"stores image"| node_imagehost
node_imagegen -->|"requests image generation"| node_chatglm
node_imagecmd -->|"emits progress"| node_events

click node_entry "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/cmd/glm2cli/main.go"
click node_commands "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cli.go"
click node_chatcmd "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_chat.go"
click node_convcmd "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_conv.go"
click node_infocmd "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_info.go"
click node_rawcmd "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_raw.go"
click node_credential "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/cred.go"
click node_auth "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/client.go"
click node_httpclient "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/client.go"
click node_sse "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/sse.go"
click node_chatgen "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/channel/chatgen.go"
click node_convapi "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/history.go"
click node_imagecmd "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_chat.go"
click node_imagegen "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/channel/imagesgen.go"
click node_refsheet "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/imgutil/refsheet.go"
click node_upload "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/imgutil/upload.go"
click node_events "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/protocol/jsonl/jsonl.go"
click node_plugin "https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/protocol/plugin/plugin.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_commands,node_chatcmd,node_convcmd,node_infocmd,node_rawcmd,node_imagecmd toneBlue
class node_credential,node_auth,node_httpclient,node_sse,node_chatgen,node_convapi toneAmber
class node_imagegen,node_refsheet,node_upload toneMint
class node_events,node_plugin toneRose
class node_user,node_imagehost,node_chatglm toneIndigo
```

## Components

### CLI commands

- [CLI entry](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/cmd/glm2cli/main.go): `cmd/glm2cli/main.go`
- [Command dispatch](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cli.go): `internal/cli/cli.go`
- [Chat command](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_chat.go): `internal/cli/cmd_chat.go`
- [Conversation commands](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_conv.go): `internal/cli/cmd_conv.go`
- [Account and model queries](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_info.go): `internal/cli/cmd_info.go`
- [Raw endpoint command](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_raw.go): `internal/cli/cmd_raw.go`
- [Image command](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/cli/cmd_chat.go): `internal/cli/cmd_chat.go`

### ChatGLM access

- [Credential loading](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/cred.go): `internal/glm/cred.go`
- [Token refresh](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/client.go): `internal/glm/client.go`
- [HTTP API client](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/client.go): `internal/glm/client.go`
- [SSE stream parsing](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/sse.go): `internal/glm/sse.go`
- [Chat generation](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/channel/chatgen.go): `internal/channel/chatgen.go`
- [Conversation history and control](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/glm/history.go): `internal/glm/history.go`

### Image generation

- [Image generation](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/channel/imagesgen.go): `internal/channel/imagesgen.go`
- [Reference sheet builder](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/imgutil/refsheet.go): `internal/imgutil/refsheet.go`
- [Image hosting upload](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/imgutil/upload.go): `internal/imgutil/upload.go`

### Output and IPC

- [JSONL event output](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/protocol/jsonl/jsonl.go): `internal/protocol/jsonl/jsonl.go`
- [Plugin IPC runner](https://github.com/wild-work3/ww3-chatglm-cli/blob/main/internal/protocol/plugin/plugin.go): `internal/protocol/plugin/plugin.go`

### Other components

- **Human or agent**
- **Image hosting services**
- **ChatGLM service**

## Connections

- Human or agent → CLI entry: runs (evidence: `README.md`)
- CLI entry → Command dispatch: starts (evidence: `cmd/glm2cli/main.go`)
- Command dispatch → Chat command: routes chat (evidence: `README.md`)
- Command dispatch → Conversation commands: routes conv (evidence: `README.md`)
- Command dispatch → Account and model queries: routes info (evidence: `README.md`)
- Command dispatch → Raw endpoint command: routes raw (evidence: `README.md`)
- Chat command → Credential loading: loads credentials (evidence: `README.md`)
- HTTP API client → Token refresh: refreshes token (evidence: `internal/glm/client.go`)
- Credential loading → HTTP API client: supplies credentials (evidence: `README.md`)
- Chat command → ChatGLM service: streams chat (evidence: `README.md`)
- Chat command → SSE stream parsing: parses stream
- Chat command → JSONL event output: emits JSONL (evidence: `README.md`)
- Conversation commands → Conversation history and control: reads and controls (evidence: `internal/cli/cmd_conv.go`)
- Account and model queries → ChatGLM service: queries account data (evidence: `README.md`)
- Raw endpoint command → HTTP API client: sends endpoint request
- Image command → Plugin IPC runner: invokes image method (evidence: `internal/cli/cmd_chat.go`)
- Plugin IPC runner → Image generation: dispatches method
- Image generation → Reference sheet builder: builds reference sheet (evidence: `internal/channel/imagesgen.go`)
- Image generation → Image hosting upload: uploads references (evidence: `README.md`)
- Image hosting upload → Image hosting services: stores image (evidence: `README.md`)
- Image generation → ChatGLM service: requests image generation (evidence: `README.md`)
- Image command → JSONL event output: emits progress (evidence: `README.md`)
