Feat/pkg flowgo extraction#36
Merged
Merged
Conversation
added 3 commits
May 25, 2026 00:11
Add `brew install lassediercks/flowgo/flowgo` as the recommended macOS/Linux path, linking the homebrew-flowgo tap repo. Keeps `go install` as the alternative for Go users.
Splits the single-package main into a reusable library so downstream
consumers can compose flowgo's handlers onto their own HTTP mux
without copying code.
Layout:
- pkg/flowgo (library)
state.go — IndexHTML embed, Config, Configure, MCPHandler
mcp.go — MCP JSON-RPC handler + tool actions (was main)
workspace.go — Workspace, WorkspaceManager (was main)
mcp_test.go
- pkg/graph (library, expanded)
validate.go (moved from main; renamed validateGraph → Validate)
map.flowgo (test fixture)
validate_test.go
stroke_palette_test.go (moved from main; tests Parse/Serialize)
version_directive_test.go
- cmd/flowgo (binary)
main.go — flag parsing, single-file editor mode, version
serve.go — flowgo serve subcommand
naming.go, upgrade.go, version_check.go and tests
The MCP handler dropped its package-level serveMode / filePath / mu /
workspaces / serveCfg globals. They are now fields on pkg/flowgo.Config,
which the binary populates via flowgo.Configure. The handler reads
through that struct so consumers can configure backend behaviour
without touching pkg/flowgo internals.
dist/index.html moved to pkg/flowgo/dist/ so the library can embed
it directly via //go:embed.
Toolchain updates:
- vite.config.ts: outDir → pkg/flowgo/dist
- justfile: go run ./cmd/flowgo, find ./pkg/flowgo/dist/index.html
- .github/workflows/release-please.yml: go build … ./cmd/flowgo
- version_check.go: install hint → github.com/lassediercks/flowgo/cmd/flowgo
- package.json: now @flowgo/editor, exports map for downstream consumers
- .gitignore: anchor /flowgo (binary) so it doesn't also ignore pkg/flowgo
Behaviour-identical from a user's perspective:
- CLI commands (flowgo new, flowgo <file>, flowgo serve, flowgo upgrade,
flowgo version) unchanged.
- HTTP routes (/, /state, /save, /mcp, /version, /m/<id>) unchanged.
- .flowgo file format unchanged.
- MCP tool surface unchanged.
Behaviour-unchanged refactor that funnels every mutation seam in
the editor through a typed wrapper. Each call site now invokes a
typed mutator (mutatedBox, mutatedEdge, mutatedText, mutatedLine,
mutatedStroke, mutatedCurrentMap, mutatedDoc) instead of
scheduleSave() directly. Each mutator forwards to the wired
scheduleSave, so observable behaviour is identical.
The wrapper exists as a single injection point: downstream wiring
can replace what mutators do without having to audit the 26
mutation seams individually.
Migrated 26 call sites across 9 modules (align, attach, brush,
clipboard, edit, factories, keys, mouse, touch). Each site picks
the most specific mutator for what it actually changed:
deleteSelection → mutatedDoc (touches submaps), createBoxAt →
mutatedBox, paste → mutatedCurrentMap, edge add/remove →
mutatedEdge, and so on.
The scheduleSave field is dropped from 8 wireX binding interfaces;
main.ts wires the new mutations module once with
wireMutations({ scheduleSave: () => scheduleSave() }).
clipboard.test.ts switches to calling wireMutations directly in its
setup with a no-op scheduleSave; no other test surgery needed.
Bundle size: 103.41 KB (−243 bytes vs main). All 120 vitest tests
pass; tsc --noEmit clean; go test ./... clean; binary serves /state
and /save unchanged end-to-end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.