wps-events
- Repo stars 21,000
- Author updated Live
- Author repo waveterm
- Domain
- Engineering
- Compatible agents
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- Trust score
- 88 / 100 · community maintained
- Author / version / license
- @wavetermdev · no license declared
- Token usage
- Lean
- Setup complexity
- Plug-and-play
- External API key
- Not required
- Operating systems
- Unspecified (assume cross-platform)
- Runtime requirements
- No special requirements
- Permissions
-
- Read-only
- Write / modify
- Network behavior
- Local-only
- Install commands
- 26 variants
Profile is derived at build time from SKILL.md and install vectors. Subject to drift from author intent.
Heads up: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: wps-events
description: Guide for working with Wave Terminal's WPS (Wave PubSub) event system. Use when implementing new…
category: engineering
runtime: no special runtime
---
# wps-events output preview
## PART A: Task fit
- Use case: Guide for working with Wave Terminal's WPS (Wave PubSub) event system. Use when implementing new event types, publishing events, subscribing to events, or adding asynchronous communication between components..
- Inputs: target material, constraints, expected output, and acceptance criteria.
- Evidence boundary: follow “Overview / Key Files / Event Structure” and do not present inference as author intent.
## PART B: Execution result
- **01** The card summarizes the use case; runtime output centers on “Guide for working with Wave Terminal's WPS (Wave PubSub) event system. Use when implementing new event types, publishing events, subscribing to events, or adding asynchronous communication between components.”.
- **02** When the source has headings, the agent prioritizes “Overview / Key Files / Event Structure” so the result follows the author’s structure.
- **03** Typical output includes task judgment, concrete steps, required commands or file edits, validation, and follow-up options.
- **04** Risk context follows the fingerprint: read files, write/modify files; mostly runs locally; usually needs no extra API key.
## Running Rules
- read files, write/modify files; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding scope.
- Return the result, validation criteria, and next iteration options. The source does not require a stable slash command. After installation, invoke the skill by name and describe the task.
Name target files or source material, expected output, forbidden changes, and whether network or shell access is allowed. Permission fingerprint: read files, write/modify files.
Start with a small task and check whether the result follows “Overview / Key Files / Event Structure”. Inspect diffs, logs, previews, or tests before expanding scope.
Confirm the final output includes a concrete result, evidence, and next action. If it stays generic, tighten inputs, boundaries, and acceptance criteria.
---
name: wps-events
description: Guide for working with Wave Terminal's WPS (Wave PubSub) event system. Use when implementing new…
category: engineering
source: wavetermdev/waveterm
---
# wps-events
## When to use
- Guide for working with Wave Terminal's WPS (Wave PubSub) event system. Use when implementing new event types, publishi…
- Use it when the task has clear inputs, repeatable steps, and validation criteria.
## What to provide
- Target material, scope, expected result, and forbidden changes.
- Whether network, commands, file writes, or external services are allowed.
## Execution rules
- Organize steps around “Overview / Key Files / Event Structure” and keep inference separate from source facts.
- read files, write/modify files; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding the task.
## Output requirements
- Return the deliverable, key evidence, validation method, and next action.
- Mark missing information as unknown; do not invent commands, platforms, or dependencies. The author source anchors workflow facts; repository files anchor sources and commands; Fluxly only adds fit, limitations, and quality judgment.
skill "wps-events" {
input -> user goal + target files + boundaries + acceptance criteria
context -> Overview / Key Files / Event Structure
rules -> SKILL.md triggers / order / output contract
runtime -> no special runtime | read files, write/modify files | mostly runs locally
guardrails -> usually needs no extra API key + small-sample validation + diff/log review
output -> copyable result + checklist + next iteration
} WPS Events Guide
Overview
WPS (Wave PubSub) is Wave Terminal's publish-subscribe event system that enables different parts of the application to communicate asynchronously. The system uses a broker pattern to route events from publishers to subscribers based on event types and scopes.
Key Files
pkg/wps/wpstypes.go- Event type constants and data structurespkg/wps/wps.go- Broker implementation and core logicpkg/wcore/wcore.go- Example usage patterns
Event Structure
Events in WPS have the following structure:
type WaveEvent struct {
Event string `json:"event"` // Event type constant
Scopes []string `json:"scopes,omitempty"` // Optional scopes for targeted delivery
Sender string `json:"sender,omitempty"` // Optional sender identifier
Persist int `json:"persist,omitempty"` // Number of events to persist in history
Data any `json:"data,omitempty"` // Event payload
}
Adding a New Event Type
Step 1: Define the Event Constant
Add your event type constant to pkg/wps/wpstypes.go:
const (
Event_BlockClose = "blockclose"
Event_ConnChange = "connchange"
// ... other events ...
Event_YourNewEvent = "your:newevent" // type: YourEventData (or "none" if no data)
)
Naming Convention:
- Use descriptive PascalCase for the constant name with
Event_prefix - Use lowercase with colons for the string value (e.g., "namespace:eventname")
- Group related events with the same namespace prefix
- Always add a
// type: <TypeName>comment; use// type: noneif no data is sent
Step 2: Add to AllEvents
Add your new constant to the AllEvents slice in pkg/wps/wpstypes.go:
var AllEvents []string = []string{
// ... existing events ...
Event_YourNewEvent,
}
Step 3: Register in WaveEventDataTypes (REQUIRED)
You must add an entry to WaveEventDataTypes in pkg/tsgen/tsgenevent.go. This drives TypeScript type generation for the event's data field:
var WaveEventDataTypes = map[string]reflect.Type{
// ... existing entries ...
wps.Event_YourNewEvent: reflect.TypeOf(YourEventData{}), // value type
// wps.Event_YourNewEvent: reflect.TypeOf((*YourEventData)(nil)), // pointer type
// wps.Event_YourNewEvent: nil, // no data (type: none)
}
- Use
reflect.TypeOf(YourType{})for value types - Use
reflect.TypeOf((*YourType)(nil))for pointer types - Use
nilif no data is sent for the event
Step 4: Define Event Data Structure (Optional)
If your event carries structured data, define a type for it:
type YourEventData struct {
Field1 string `json:"field1"`
Field2 int `json:"field2"`
}
Step 5: Expose Type to Frontend (If Needed)
If your event data type isn't already exposed via an RPC call, you need to add it to pkg/tsgen/tsgen.go so TypeScript types are generated:
// add extra types to generate here
var ExtraTypes = []any{
waveobj.ORef{},
// ... other types ...
uctypes.RateLimitInfo{}, // Example: already added
YourEventData{}, // Add your new type here
}
Then run code generation:
task generate
This will update frontend/types/gotypes.d.ts with TypeScript definitions for your type, ensuring type safety in the frontend when handling these events.
Publishing Events
Basic Publishing
To publish an event, use the global broker:
import "github.com/wavetermdev/waveterm/pkg/wps"
wps.Broker.Publish(wps.WaveEvent{
Event: wps.Event_YourNewEvent,
Data: yourData,
})
Publishing with Scopes
Scopes allow targeted event delivery. Subscribers can filter events by scope:
wps.Broker.Publish(wps.WaveEvent{
Event: wps.Event_WaveObjUpdate,
Scopes: []string{oref.String()}, // Target specific object
Data: updateData,
})
Publishing in a Goroutine
To avoid blocking the caller, publish events asynchronously:
go func() {
wps.Broker.Publish(wps.WaveEvent{
Event: wps.Event_YourNewEvent,
Data: data,
})
}()
When to use goroutines:
- When publishing from performance-critical code paths
- When the event is informational and doesn't need immediate delivery
- When publishing from code that holds locks (to prevent deadlocks)
Event Persistence
Events can be persisted in memory for late subscribers:
wps.Broker.Publish(wps.WaveEvent{
Event: wps.Event_YourNewEvent,
Persist: 100, // Keep last 100 events
Data: data,
})
Complete Example: Rate Limit Updates
This example shows how rate limit information is published when AI chat responses include rate limit headers.
1. Define the Event Type
In pkg/wps/wpstypes.go:
const (
// ... other events ...
Event_WaveAIRateLimit = "waveai:ratelimit"
)
2. Publish the Event
In pkg/aiusechat/usechat.go:
import "github.com/wavetermdev/waveterm/pkg/wps"
func updateRateLimit(info *uctypes.RateLimitInfo) {
if info == nil {
return
}
rateLimitLock.Lock()
defer rateLimitLock.Unlock()
globalRateLimitInfo = info
// Publish event in goroutine to avoid blocking
go func() {
wps.Broker.Publish(wps.WaveEvent{
Event: wps.Event_WaveAIRateLimit,
Data: info, // RateLimitInfo struct
})
}()
}
3. Subscribe to the Event (Frontend)
In the frontend, subscribe to events via WebSocket:
// Subscribe to rate limit updates
const subscription = {
event: "waveai:ratelimit",
allscopes: true, // Receive all rate limit events
};
Subscribing to Events
From Go Code
// Subscribe to all events of a type
wps.Broker.Subscribe(routeId, wps.SubscriptionRequest{
Event: wps.Event_YourNewEvent,
AllScopes: true,
})
// Subscribe to specific scopes
wps.Broker.Subscribe(routeId, wps.SubscriptionRequest{
Event: wps.Event_WaveObjUpdate,
Scopes: []string{"workspace:123"},
})
// Unsubscribe
wps.Broker.Unsubscribe(routeId, wps.Event_YourNewEvent)
Scope Matching
Scopes support wildcard matching:
*matches a single scope segment**matches multiple scope segments
// Subscribe to all workspace events
wps.Broker.Subscribe(routeId, wps.SubscriptionRequest{
Event: wps.Event_WaveObjUpdate,
Scopes: []string{"workspace:*"},
})
Best Practices
Use Namespaces: Prefix event names with a namespace (e.g.,
waveai:,workspace:,block:)Don't Block: Use goroutines when publishing from performance-critical code or while holding locks
Type-Safe Data: Define struct types for event data rather than using maps
Scope Wisely: Use scopes to limit event delivery and reduce unnecessary processing
Document Events: Add comments explaining when events are fired and what data they carry
Consider Persistence: Use
Persistfor events that late subscribers might need (like status updates). This is normally not used. We normally do a live RPC call to get the current value and then subscribe for updates.
Common Event Patterns
Status Updates
wps.Broker.Publish(wps.WaveEvent{
Event: wps.Event_ControllerStatus,
Scopes: []string{blockId},
Persist: 1, // Keep only latest status
Data: statusData,
})
Object Updates
wps.Broker.Publish(wps.WaveEvent{
Event: wps.Event_WaveObjUpdate,
Scopes: []string{oref.String()},
Data: waveobj.WaveObjUpdate{
UpdateType: waveobj.UpdateType_Update,
OType: obj.GetOType(),
OID: waveobj.GetOID(obj),
Obj: obj,
},
})
Batch Updates
// Helper function for multiple updates
func (b *BrokerType) SendUpdateEvents(updates waveobj.UpdatesRtnType) {
for _, update := range updates {
b.Publish(WaveEvent{
Event: Event_WaveObjUpdate,
Scopes: []string{waveobj.MakeORef(update.OType, update.OID).String()},
Data: update,
})
}
}
Debugging
To debug event flow:
- Check broker subscription map:
wps.Broker.SubMap - View persisted events:
wps.Broker.ReadEventHistory(eventType, scope, maxItems) - Add logging in publish/subscribe methods
- Monitor WebSocket traffic in browser dev tools
Quick Reference
When adding a new event:
- Add event constant to
pkg/wps/wpstypes.gowith a// type: <TypeName>comment (usenoneif no data) - Add the constant to
AllEventsinpkg/wps/wpstypes.go - REQUIRED: Add an entry to
WaveEventDataTypesinpkg/tsgen/tsgenevent.go— usenilfor events with no data - Define event data structure (if needed)
- Add data type to
pkg/tsgen/tsgen.gofor frontend use (if not already exposed via RPC) - Run
task generateto update TypeScript types - Publish events using
wps.Broker.Publish() - Use goroutines for non-blocking publish when appropriate
- Subscribe to events in relevant components
Decide Fit First
Design Intent
How To Use It
Boundaries And Review