Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Agent Note: Decoupling `nsgo game` from NSGo via `cmd/nsgo-game` and `internal/gamecli`

Status: implemented

## Problem

NSGo previously shipped a hardcoded built-in `nsgo game` command (`cmd/nsgo/gamecommand.go`) that knew `github.com/nsgo-dev/game/packages/game/cmd/game`, pinned a game release version, and read `NSGO_GAME_VERSION` when invoked outside a Go module. That coupled the core `nsgo` CLI to `nsgo-dev/game`'s repository layout and release schedule.

Removing that built-in leaves `nsgo game` to NSGo's generic extension mechanism:

1. Inside a module whose `go.mod` declares `tool github.com/nsgo-dev/game/packages/game/cmd/game`, `nsgo game <args>` automatically runs `go tool github.com/nsgo-dev/game/packages/game/cmd/game <args>`.
2. Outside a module (such as before scaffolding a project with `nsgo game new`), `nsgo game <args>` looks up an executable named `nsgo-game` on `PATH`.

`packages/game/cmd/game` installs a binary named `game`, not `nsgo-game`, so outside-a-module `nsgo game` could not find an installed extension binary without a `cmd/nsgo-game` package.

## Decision

Extract the entire CLI implementation (including `_templates/` and `testdata/`) from `packages/game/cmd/game` into `packages/game/internal/gamecli`, exposing `gamecli.Main()` and `gamecli.Run(args []string) int`, and wire two tiny `main` packages to it:

- `packages/game/cmd/game`: thin wrapper calling `gamecli.Main()`, preserving the module `tool` path (`github.com/nsgo-dev/game/packages/game/cmd/game`) for `go tool game`, in-module `nsgo game`, and zero-install `go run github.com/nsgo-dev/game/packages/game/cmd/game@latest`.
- `packages/game/cmd/nsgo-game`: thin wrapper calling `gamecli.Main()`, providing `go install github.com/nsgo-dev/game/packages/game/cmd/nsgo-game@latest` so `nsgo game` works outside a Go module via `PATH` discovery.

`packages/game/internal/gamecli` sits at the exact same directory depth below the repository root (4 levels) as `packages/game/cmd/game`, so all relative repository paths in tests (`reference_test.go`, `templates_test.go`, `library_test.go`, `skill_e2e_test.go`, `navmesh_test.go`, `playtest_test.go`, `replay_test.go`) remain unchanged. `packages/game/conformance_test.go`'s `notFormats` allowlist moves from `cmd/game` to `internal/gamecli`, and `docs/{en,zh}/stability.md` plus `skills/nsgo-game/references/packages.md` register `game/cmd/nsgo-game` as `Experimental`.

This partly supersedes the built-in dispatch mechanism recorded in [nsgo game as the documented form](../../implemented/process/2026-11-25-nsgo-game-main-form.md): `nsgo game` stays the documented CLI form, while dispatch now relies exclusively on NSGo's generic extension mechanism rather than a hardcoded built-in in `nsgo`.

## Alternatives considered

- **Keep the hardcoded `nsgo game` built-in in `nsgo-dev/nsgo`** — Avoids a one-time `go install .../cmd/nsgo-game@latest` for outside-a-module `nsgo game`, which was why the earlier note ([nsgo game as the documented form](../../implemented/process/2026-11-25-nsgo-game-main-form.md)) accepted it. Rejected because it permanently couples `nsgo` to `nsgo-dev/game`'s module path, version pinning, and `NSGO_GAME_VERSION` override.
- **Rename `packages/game/cmd/game` to `packages/game/cmd/nsgo-game`** — Avoids adding a second `cmd/` package and an `internal/gamecli` package. Rejected because it breaks every existing project's `tool github.com/nsgo-dev/game/packages/game/cmd/game`, `go tool game` (used by the editor, workflows, MCP configs, and Git merge drivers), and `go run .../cmd/game@latest`.
- **Tell users outside a module to only use `go run .../cmd/game@latest` with no `cmd/nsgo-game`** — Avoids maintaining a second binary entrypoint. Rejected because users who already run `nsgo game` inside projects expect `nsgo game new` to work outside a project too once installed, matching standard `git-<subcommand>` / `nsgo-<subcommand>` PATH extensions.

## Consequences

- **Benefits**: `nsgo` has zero compile-time or runtime coupling to `nsgo-dev/game`; `cmd/game` and `cmd/nsgo-game` share 100% of CLI code via `internal/gamecli`; existing `go tool game`, `go.mod` `tool` directives, and `go run .../cmd/game@latest` remain completely compatible.
- **Costs**: Running `nsgo game` outside a Go module requires a one-time `go install github.com/nsgo-dev/game/packages/game/cmd/nsgo-game@latest` (or using `go run github.com/nsgo-dev/game/packages/game/cmd/game@latest` directly); contributors updating embedded project templates now copy into `packages/game/internal/gamecli/_templates/projects/<name>` instead of `packages/game/cmd/game/_templates/projects/<name>`.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ The game layer's command was documented only as `go tool game`, a second entry p

## Decision

The docs (`docs/en`, `docs/zh`), the agent skill (`skills/nsgo-game`) and the READMEs that show the command write it as `nsgo game <command>`. `docs/en/cli.md#install` says it is a command of `nsgo` since v0.3.3, that a project's own `nsgo` tool needs v0.3.3 or later as well since an `nsgo` of another version hands a project's commands to the project's, and that `go tool game` runs the same command in a project. `packages/game`, every template's `go.mod.tmpl` (and its copy under `cmd/game/_templates`), the examples and the agent-eval fixtures require NSGo v0.3.4 for that reason (#1126), rather than v0.3.3, which skips depth-tested draws into a window's own depth buffer (nsgo-dev/nsgo#2395), so a project made from any template runs `nsgo game` with no extra step. The generated command reference (`cmd/game/reference.go`) prints each usage line as `nsgo game …`; the command's own help and errors keep `game …`, true under either name.
The docs (`docs/en`, `docs/zh`), the agent skill (`skills/nsgo-game`) and the READMEs that show the command write it as `nsgo game <command>`. `docs/en/cli.md#install` says it runs through `nsgo` since v0.3.3, that a project's own `nsgo` tool needs v0.3.3 or later as well since an `nsgo` of another version hands a project's commands to the project's, and that `go tool game` runs the same command in a project. `packages/game`, every template's `go.mod.tmpl` (and its copy under `internal/gamecli/_templates`), the examples and the agent-eval fixtures require NSGo v0.3.4 for that reason (#1126), rather than v0.3.3, which skips depth-tested draws into a window's own depth buffer (nsgo-dev/nsgo#2395), so a project made from any template runs `nsgo game` with no extra step. The generated command reference (`internal/gamecli/reference.go`) prints each usage line as `nsgo game …`; the command's own help and errors keep `game …`, true under either name.

What runs the command itself stays `go tool game`: the editor's Run button (`editor/run_game.go`), the workflows and the benchmark baseline's note, as they must work without an `nsgo` on `PATH`. The game module adds no command for `nsgo`: the project templates' `go.mod` already declare the `game` tool that `nsgo game` runs.
What runs the command itself stays `go tool game`: the editor's Run button (`editor/run_game.go`), the workflows and the benchmark baseline's note, as they must work without an `nsgo` on `PATH`. The built-in `nsgo game` dispatch and "no extra command" part of this decision were later superseded by [decoupling `nsgo game` via `cmd/nsgo-game` and `internal/gamecli`](../../implemented/architecture/2026-11-27-nsgo-game-extension-decoupling.md), while `nsgo game` remains the documented form.

## Alternatives considered

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
CLOUDSAVE_POSTGRES_DSN: postgres://postgres:accounts-ci@127.0.0.1:5432/postgres?sslmode=disable
run: go tool nsgo test ./cloudsave/sqlstore/...

# Lists one matrix entry per template game new offers, from the template directories on disk: starter in template/template and every other template in template/<name>/template, which TestTemplatesMatchTemplateModules keeps the same as the registry in packages/game/cmd/game/templates.go. Adding a template therefore needs no edit here.
# Lists one matrix entry per template game new offers, from the template directories on disk: starter in template/template and every other template in template/<name>/template, which TestTemplatesMatchTemplateModules keeps the same as the registry in packages/game/internal/gamecli/templates.go. Adding a template therefore needs no edit here.
template-list:
name: List the templates
runs-on: depot-ubuntu-24.04
Expand Down
7 changes: 7 additions & 0 deletions changelog.d/nsgo-game-extension-binary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Added

- `game/cmd/nsgo-game`: add the `nsgo-game` extension binary entrypoint (`go install github.com/nsgo-dev/game/packages/game/cmd/nsgo-game@latest`) so `nsgo game` works outside a Go module through NSGo's generic extension mechanism.

### Changed

- `game/cmd/game`: move the shared CLI implementation into `game/internal/gamecli` so `cmd/game` and `cmd/nsgo-game` share one entrypoint, and update CLI, template, getting-started, stability and agent skill docs for NSGo's extension-based `nsgo game` dispatch without a built-in command in `nsgo`.
2 changes: 1 addition & 1 deletion docs/en/cli-reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Command Reference

<!-- Code generated from the game command's definitions by `go tool nsgo test ./cmd/game -run TestReference -update` in packages/game. DO NOT EDIT. -->
<!-- Code generated from the game command's definitions by `go tool nsgo test ./internal/gamecli -run TestReference -update` in packages/game. DO NOT EDIT. -->

Every subcommand of `nsgo game`, which `go tool game` runs alike, with its usage line and flags, generated from the commands' definitions so it always matches `game help`. [Command Line](cli.md) shows how to install the command, what each subcommand is for and how to set up shell completion.

Expand Down
15 changes: 11 additions & 4 deletions docs/en/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@

## Install

Run the command as `nsgo game`, a command of NSGo's own `nsgo` since v0.3.3 (nsgo-dev/nsgo#2366). Install `nsgo` once, with Homebrew (`brew install nsgo-dev/tap/nsgo`), with the install script on macOS and Linux (`curl -fsSL https://nsgo.dev/install.sh | sh`) or with Go on any system (`go install github.com/nsgo-dev/nsgo/cmd/nsgo@latest`), as [NSGo's setup](https://nsgo.dev/docs/getting-started/#install-nsgo) describes. In a project, `nsgo game` runs the `game` tool the module's `go.mod` declares:
Run the command as `nsgo game` through NSGo's extension mechanism (since NSGo v0.3.3). Install `nsgo` once, with Homebrew (`brew install nsgo-dev/tap/nsgo`), with the install script on macOS and Linux (`curl -fsSL https://nsgo.dev/install.sh | sh`) or with Go on any system (`go install github.com/nsgo-dev/nsgo/cmd/nsgo@latest`), as [NSGo's setup](https://nsgo.dev/docs/getting-started/#install-nsgo) describes. In a project whose `go.mod` declares the `game` tool, `nsgo game` automatically runs that module's pinned tool (`go tool github.com/nsgo-dev/game/packages/game/cmd/game`):

```sh
go get -tool github.com/nsgo-dev/game/packages/game/cmd/game
nsgo game help
```

The `tool` line in `go.mod` pins the command to the module's version of the game layer, so everyone working on the game runs the same one. A project created with [`game new`](#new) has it already. An `nsgo` of another version than the one the project's `go.mod` pins runs the project's own instead, so the project's `nsgo` tool needs v0.3.3 or later too; every template's `go.mod` and the game layer itself require v0.3.4, the first release whose software renderer and surface depth buffer draw 3D scenes right. Outside a project, such as to create one, `nsgo game` runs the game layer's release made for that `nsgo` with `go run`, with nothing else to install.
The `tool` line in `go.mod` pins the command to the module's version of the game layer, so everyone working on the game runs the same one. A project created with [`game new`](#new) has it already. An `nsgo` of another version than the one the project's `go.mod` pins runs the project's own instead, so the project's `nsgo` tool needs v0.3.3 or later too; every template's `go.mod` and the game layer itself require v0.3.4, the first release whose software renderer and surface depth buffer draw 3D scenes right.

`go tool game` runs the same command in a project without an installed `nsgo`, and `go run github.com/nsgo-dev/game/packages/game/cmd/game@latest` does anywhere.
Outside a project, such as before creating one with `nsgo game new`, install the `nsgo-game` extension binary once on `PATH` so `nsgo game` finds it:

```sh
go install github.com/nsgo-dev/game/packages/game/cmd/nsgo-game@latest
nsgo game new mygame
```

Or run `go run github.com/nsgo-dev/game/packages/game/cmd/game@latest` directly anywhere with nothing to install. Inside a project, `go tool game` also runs the same command without an installed `nsgo`.

## Commands

Expand Down Expand Up @@ -193,7 +200,7 @@ nsgo game new -list

Writes a project from a template into the directory named, creating it if needed, and prints each file's path. It then runs `go get -tool github.com/nsgo-dev/game/packages/game/cmd/game@<version>` and `go mod tidy` there, which need the Go module proxy, so the project requires that version of the game layer and has the `game` tool beside the `nsgo` tool, and builds and runs with `go tool nsgo dev` without edits.

The game is named after the directory unless `-name` gives a name (letters, digits, spaces, `-` and `_`, starting with a letter), which `game.yaml` and `nsgo.yaml` hold as `name`, with `id` derived from it as `dev.nsgo.<name in lower case without spaces or punctuation>`. The module path is the name in lower case with its words joined by `-` unless `-module` gives one. A module path that is a standard-library package's, such as `time` for a game called Time, is refused because the project could not build, so such a game needs `-module`, such as `-module example.com/time`. `-version` is the version of the game layer to require, such as `v0.4.0`, a commit or `latest`; by default it is the version of the command running, so `go run …@v0.4.0 new`, or `nsgo game new` with `NSGO_GAME_VERSION=v0.4.0` outside a project, creates a project on `v0.4.0`, and `latest` when the command was built from a checkout of this repository. `-template` chooses the template, `starter` by default, and an unknown name is refused with the names there are. `-list` prints each template's name, the default marked, beside a line saying what it is, and creates nothing. [Templates](templates.md) lists them with the module `nsgo init -template` takes for each, and describes how a template is laid out and how to add one.
The game is named after the directory unless `-name` gives a name (letters, digits, spaces, `-` and `_`, starting with a letter), which `game.yaml` and `nsgo.yaml` hold as `name`, with `id` derived from it as `dev.nsgo.<name in lower case without spaces or punctuation>`. The module path is the name in lower case with its words joined by `-` unless `-module` gives one. A module path that is a standard-library package's, such as `time` for a game called Time, is refused because the project could not build, so such a game needs `-module`, such as `-module example.com/time`. `-version` is the version of the game layer to require, such as `v0.4.0`, a commit or `latest`; by default it is the version of the command running, so `go run …@v0.4.0 new`, or an `nsgo-game` installed at `v0.4.0`, creates a project on `v0.4.0`, and `latest` when the command was built from a checkout of this repository. `-template` chooses the template, `starter` by default, and an unknown name is refused with the names there are. `-list` prints each template's name, the default marked, beside a line saying what it is, and creates nothing. [Templates](templates.md) lists them with the module `nsgo init -template` takes for each, and describes how a template is laid out and how to add one.

`new` writes nothing when any file it would write already exists in the directory, and fails with 1. Every template includes `.gitattributes` registering `*.scene.yaml` and `*.scene.yml` with the `nsgo-scene` merge driver, and when the directory already holds a `.git` repository, `new` also configures the local Git driver automatically (otherwise run `go tool game merge -setup` after `git init`). When `go get` or `go mod tidy` fails, such as without a network, the files stay where they are written, and the error names the commands left to run in the directory to finish the project: both `go get -tool …` and `go mod tidy` when `go get` failed, and `go mod tidy` alone when it failed.

Expand Down
2 changes: 1 addition & 1 deletion docs/en/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cd mygame
go tool nsgo dev
```

`go run github.com/nsgo-dev/game/packages/game/cmd/game@latest new mygame` does the same without `nsgo`.
`nsgo game` outside a project uses the `nsgo-game` extension binary on `PATH` (install once with `go install github.com/nsgo-dev/game/packages/game/cmd/nsgo-game@latest`), or `go run github.com/nsgo-dev/game/packages/game/cmd/game@latest new mygame` does the same directly with nothing to install. Inside the created project, `nsgo game` automatically runs the module's pinned `game` tool.

The starter includes an animated sprite, tap-to-score input, and tests. Its settings live in `game.yaml`, the [project file](project.md), which `nsgo.yaml` mirrors. `new` names the game after its directory in both files' `name` and `id` and in the module path; `-name` and `-module` choose others, such as `-module example.com/mygame`. [Command Line](cli.md#new) describes every flag, and `-template` starts from another of the [templates](templates.md), which `new -list` lists. Change the identifier to your own before you ship the game: edit the game's name and identifier in `game.yaml`, then run `go run github.com/nsgo-dev/game/packages/game/cmd/gameproject sync` to write them into `nsgo.yaml`.

Expand Down
1 change: 1 addition & 0 deletions docs/en/stability.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Paths are relative to `github.com/nsgo-dev/game/packages`. The table is checked
| `game/cmd/gameapi` | Experimental | |
| `game/cmd/gameproject` | Experimental | [Project File](project.md) |
| `game/cmd/gameschema` | Experimental | [Schemas for YAML files](schemas.md) |
| `game/cmd/nsgo-game` | Experimental | [Command Line](cli.md) |
| `game/cmd/sizecheck` | Experimental | [Package Size Budgets](package-size-budgets.md) |
| `game/cmd/wasmprobe` | Experimental | [Package Size Budgets](package-size-budgets.md) |
| `game/cutscene` | Experimental | [cutscene](cutscene.md) |
Expand Down
Loading
Loading