Skip to content

Feat/pkg flowgo extraction#36

Merged
lassediercks merged 3 commits into
mainfrom
feat/pkg-flowgo-extraction
May 26, 2026
Merged

Feat/pkg flowgo extraction#36
lassediercks merged 3 commits into
mainfrom
feat/pkg-flowgo-extraction

Conversation

@lassediercks

Copy link
Copy Markdown
Owner

No description provided.

Lasse Diercks 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.
@lassediercks lassediercks merged commit 926931b into main May 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant