How pyichiban/chatglm-cli works
chatglm-cli is a Go command-line client for chatglm.cn’s private IDE interface, also usable as a channel plugin. Its primary workflow is prompt input → chat command → streamed upstream response → JSONL events on stdout; callers explicitly pass a conversation ID to continue a conversation. Separate commands provide conversation management, account/model information, authentication, raw endpoint access, and image generation, including reference-image composition and upload. The graph reflects documented workflows and sampled call sites; unsampled implementation details are represented only where the README documents the capability.
Main entry points: client.go GLM API client · cli.go Command dispatcher · channel.go Channel core · imagesgen.go Plugin image generation
Components 22
CLI and commands
- CLI entry
cmd/glm2cli/main.go - Command dispatcher
internal/cli/cli.go - Chat command
internal/cli/cmd_chat.go - Conversation commands
internal/cli/cmd_conv.go - Info commands
internal/cli/cmd_info.go - Channel commands
internal/cli/cmd_channel.go - Raw endpoint command
internal/cli/cmd_raw.go
Plugin channel
- Plugin registry
internal/protocol/plugin/plugin.go - Channel core
internal/channel/channel.go - Plugin chat generation
internal/channel/chatgen.go - Plugin image generation
internal/channel/imagesgen.go - Auth and operations
internal/channel/ops.go
GLM integration
- GLM API client
internal/glm/client.go - Credential handling
internal/glm/cred.go
Protocol and images
- JSONL event contract
internal/glm/event.go - JSONL framing
internal/protocol/jsonl/jsonl.go - Plugin RPC
internal/protocol/rpc/client.go - Reference image tools
internal/imgutil/refsheet.go - Image upload
internal/imgutil/upload.go
Other components
- Human or agent
- chatglm.cn service
- Image hosting services
Connections 29
- Human or agent → CLI entry: runs command
README.md - CLI entry → Command dispatcher: starts
cmd/glm2cli/main.go - Command dispatcher → Chat command: dispatches
internal/cli/cli.go - Command dispatcher → Conversation commands: dispatches
internal/cli/cli.go - Command dispatcher → Info commands: dispatches
internal/cli/cli.go - Command dispatcher → Channel commands: dispatches
internal/cli/cli.go - Command dispatcher → Raw endpoint command: dispatches
internal/cli/cli.go - Chat command → GLM API client: streams chat
internal/cli/cmd_chat.go - GLM API client → chatglm.cn service: sends requests
README.md - GLM API client → JSONL event contract: parses stream
- Chat command → JSONL event contract: emits events
- JSONL event contract → Human or agent: writes JSONL
README.md - Conversation commands → GLM API client: manages conversations
internal/cli/cmd_conv.go - Info commands → GLM API client: queries account and models
internal/cli/cmd_info.go - Raw endpoint command → GLM API client: calls endpoints
internal/cli/cmd_raw.go - Channel commands → Plugin registry: serves plugin methods
internal/cli/cmd_channel.go - Plugin registry → Channel core: dispatches methods
internal/channel/channel.go - Channel core → Plugin chat generation: handles chat generation
internal/channel/chatgen.go - Channel core → Plugin image generation: handles image generation
internal/channel/imagesgen.go - Channel core → Auth and operations: handles auth and operations
internal/channel/ops.go - Plugin chat generation → GLM API client: streams upstream chat
internal/channel/chatgen.go - Plugin image generation → GLM API client: requests image generation
internal/channel/imagesgen.go - Plugin image generation → Reference image tools: builds reference sheet
internal/channel/imagesgen.go - Plugin image generation → Image upload: uploads references
README.md - Image upload → Image hosting services: uploads image data
README.md - Auth and operations → Credential handling: manages credentials
internal/channel/ops.go - Credential handling → chatglm.cn service: authenticates requests
README.md - Plugin registry → Plugin RPC: serves JSONL RPC
internal/protocol/plugin/plugin.go - Plugin RPC → JSONL framing: encodes frames
internal/protocol/rpc/client.go