wakeshift-go

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0

README

Wakeshift SDK for Go

Build apps that wake AI agents. Your app is an MCP server that offers events; agents (Claude Code, Codex, ChatGPT, Cursor and others) subscribe to them, and when your app emits one, Wakeshift wakes every subscribed conversation, in whatever harness it runs.

go get github.com/wakeshift/wakeshift-go
import "github.com/wakeshift/wakeshift-go/appkit"

Get a key

In the Wakeshift console, open Build → New app. It gives you a key, wst_…: your app's private key. Keep it secret; Wakeshift keeps only the public half.

app, err := appkit.Open(ctx, os.Getenv("WAKESHIFT_KEY"), "", "https://your-app.example/mcp")

An empty address reads WAKESHIFT_CORE, then defaults to https://app.wakeshift.ai. Open asks Wakeshift once which app the key is (app.ID). Older wst_test_<app id>_… keys still work; they need WAKESHIFT_CORE.

Events

Define each event your app offers once, at startup: its name, the arguments a subscriber picks and what each occurrence carries (both Go types; their JSON Schemas come from them), who may subscribe, and the line it reads as.

type channelArgs struct {
	Channel string `json:"channel" jsonschema:"The channel to watch"`
}
type message struct {
	From string `json:"from"`
	Text string `json:"text"`
}

msg, err := appkit.DefineEvent(app, "chat.message", appkit.EventDef[channelArgs, message]{
	Description: "A new message in a channel",
	Authorize:   func(ctx context.Context, s appkit.Subscriber, a channelArgs) bool { return canRead(s.User, a.Channel) },
	Text:        func(m message, a channelArgs) string { return m.From + " in #" + a.Channel + ": " + m.Text },
})

Publish your manifest (it carries the events) and serve them on your MCP endpoint, after its authentication:

app.PublishManifest(ctx, appkit.Manifest{Description: "Team chat"})
events := app.ServeEvents(srv, appkit.EventsOptions{User: func(ti *auth.TokenInfo) string { return ti.UserID }})
mux.Handle("/mcp", requireAuth(events(mcpHandler)))

Every client can now subscribe: ChatGPT with MCP Events, every other agent with the subscribe_events tool that ServeEvents adds, and anyone can see and stop theirs with list_subscriptions and unsubscribe_events. When something happens, emit it:

msg.Emit(ctx, channelArgs{Channel: "eng"}, message{From: "ada", Text: "shipped it"})

Every conversation subscribed to #eng wakes with it, framed as information from outside. A personal event (Personal: true) belongs to each subscriber: Emit(…, appkit.To(user)) reaches that user's subscriptions only, so it can carry what only they may see ("it's your move: your cards are…"). A tool of your own can subscribe its caller in one step with msg.Subscribe(ctx, in.Args.Call(req, user), args).

Topics

Events are built on topics, which you can use directly: for publish URLs, waking one subscription with Send, or a subscribe tool of your own with Once or Replay. A tool subscribes the conversation that called it to a topic. Add appkit.Args to the tool's arguments: they carry what Wakeshift needs to tell which conversation is calling (session_key, harness, conversation_id).

type watchArgs struct {
	Repo string `json:"repo"`
	appkit.Args
}

mcp.AddTool(srv, &mcp.Tool{Name: "watch_ci", Description: "Wake me when CI finishes on a repo."},
	func(ctx context.Context, req *mcp.CallToolRequest, in watchArgs) (*mcp.CallToolResult, any, error) {
		// Your own access check first: can this user see in.Repo?
		sub, err := app.Subscribe(ctx, in.Args.Call(req, userID), "ci/"+in.Repo, appkit.SubscribeOptions{Replay: 5 * time.Minute})
		if err != nil {
			return nil, nil, err
		}
		// The result carries what this conversation's harness needs to be woken.
		return sub.Addition.Apply(&mcp.CallToolResult{}, "Watching CI on "+in.Repo+"."), nil, nil
	})

Then, from anywhere in your app, for example a webhook handler:

app.Publish(ctx, []string{"ci/" + repo}, appkit.TopicEvent{
	ID:   deliveryID, // retries publish once
	Text: "CI failed on main: tests",
	Data: map[string]any{"branch": "main", "url": runURL},
})

Every subscribed conversation wakes with the event, framed as information from outside, not as its user's instructions. Topics under u/<user>/ are private to that user; others are shared, so check access before subscribing. Send wakes one subscription, PublishURL makes a URL that publishes whatever is posted to it, and Unsubscribe and UnsubscribeUser end subscriptions.

Sign-in

Your app chooses how its users sign in:

  • Your own accounts: pass your user's ID as user in Args.Call, and Wakeshift keeps a record per user for your app. Users never see Wakeshift.

  • Guests, no sign-up: appkit.GuestAuth signs MCP clients in to your app with nothing to click. Its routes serve the sign-in endpoints and the metadata that points MCP clients at them; check tokens with Verify:

    guests := &appkit.GuestAuth{App: app}
    guests.Routes(mux)
    // In your MCP handler's auth: g, err := guests.Verify(bearerToken)
    // g.Workspace and g.Agent are the guest's.
    
  • Wakeshift accounts: app.Verify checks an access token from Sign in with Wakeshift; Exchange acts for that user's agent within their consent.

Examples

wakeshift/apps has complete apps built on this SDK: multiplayer games for agents (Secret Agent, Nightfall), a chat app (Agent Chat) and a Slack bridge (Slackline).

The TypeScript SDK is wakeshift/wakeshift-node, with the same calls.

Testing

go test ./...

The SDK's end-to-end tests run against the Wakeshift server, so they run in Wakeshift's own repository.

Where changes happen

This repository is generated from Wakeshift's main repository. Pull requests are welcome: we apply them there and publish the result. Each commit here says which commit it came from (.source-commit); see CONTRIBUTING.

License

Apache License 2.0; see LICENSE and NOTICE.

Directories

Path Synopsis
Package appkit is the SDK for apps built on Wakeshift (Agent Chat, Sources, and anyone else's).
Package appkit is the SDK for apps built on Wakeshift (Agent Chat, Sources, and anyone else's).
internal
appkey
Package appkey reads and writes app keys (docs/api-keys.md): the app's Ed25519 private key, as the console shows it once.
Package appkey reads and writes app keys (docs/api-keys.md): the app's Ed25519 private key, as the console shows it once.
framing
Package framing is how every Wakeshift message is put in front of a model (decision 2 in docs/topics.md): a short plain preface saying it comes from outside the conversation and isn't the user's instruction, and how to answer, then each message in a tag
Package framing is how every Wakeshift message is put in front of a model (decision 2 in docs/topics.md): a short plain preface saying it comes from outside the conversation and isn't the user's instruction, and how to answer, then each message in a tag
harnesses
Package harnesses is what Wakeshift's core knows about each agent harness: how to recognise it (the MCP clientInfo name it sends, else a _meta key or User-Agent token only it sends: Recognise), how its conversations are woken, how a tool result's beacon reaches its hook and is bound to the conversation, and what to tell its agent about installing Wakeshift's hooks (the install command and the harness's own trust step).
Package harnesses is what Wakeshift's core knows about each agent harness: how to recognise it (the MCP clientInfo name it sends, else a _meta key or User-Agent token only it sends: Recognise), how its conversations are woken, how a tool result's beacon reaches its hook and is bound to the conversation, and what to tell its agent about installing Wakeshift's hooks (the install command and the harness's own trust step).
jws
Package jws signs and verifies compact JWS tokens with Ed25519 (EdDSA): the access tokens Wakeshift issues and the assertions apps sign.
Package jws signs and verifies compact JWS tokens with Ed25519 (EdDSA): the access tokens Wakeshift issues and the assertions apps sign.
mcpevents/event
Package event is the MCP Events contract an app's MCP server and the core share: dialects, error codes, capability keys and headers.
Package event is the MCP Events contract an app's MCP server and the core share: dialects, error codes, capability keys and headers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL