From b5a8bb8e12f90be0dd34422ded0ed9d7a35a4b27 Mon Sep 17 00:00:00 2001 From: Danil Pismenny Date: Tue, 21 Jul 2026 18:23:02 +0500 Subject: [PATCH] chore: move Go CLI into tools --- .github/workflows/ci.yml | 5 +++++ .github/workflows/release.yml | 8 +++++++ AGENTS.md | 4 ++-- docs/adoption.md | 8 +++---- docs/development.md | 22 ++++++++++++------- docs/memory-bank-lint.md | 6 ++--- docs/memory-bank.md | 6 ++--- .goreleaser.yml => tools/.goreleaser.yml | 0 {cmd => tools/cmd}/memory-bank-lint/main.go | 2 +- {cmd => tools/cmd}/memory-bank/main.go | 2 +- go.mod => tools/go.mod | 2 +- go.sum => tools/go.sum | 0 {internal => tools/internal}/cli/cli.go | 6 ++--- {internal => tools/internal}/cli/cli_test.go | 2 +- {internal => tools/internal}/lint/audit.go | 0 .../internal}/lint/audit_test.go | 0 {internal => tools/internal}/lint/markdown.go | 0 {internal => tools/internal}/lint/report.go | 0 .../lint/testdata/expected-report.json | 0 .../testdata/repository/memory-bank/README.md | 0 .../testdata/repository/memory-bank/orphan.md | 0 .../repository/memory-bank/section/README.md | 0 .../repository/memory-bank/section/child.md | 0 .../memory-bank/section/deep/README.md | 0 .../memory-bank/section/deep/leaf.md | 0 {internal => tools/internal}/lint/types.go | 0 .../internal}/ownership/classify.go | 0 .../internal}/ownership/classify_test.go | 0 .../internal}/ownership/lock.go | 0 .../internal}/ownership/path.go | 0 .../ownership/plan_regression_test.go | 0 .../internal}/ownership/secure_path_unix.go | 0 .../ownership/secure_path_unix_test.go | 0 .../ownership/secure_path_windows.go | 0 .../internal}/ownership/source.go | 0 .../internal}/ownership/source_test.go | 0 .../internal}/ownership/symlink_test.go | 0 .../internal}/ownership/topology.go | 0 .../internal}/ownership/transaction_test.go | 0 .../internal}/ownership/types.go | 0 .../internal}/ownership/update.go | 0 .../internal}/ownership/update_test.go | 0 .../internal}/repository/root.go | 0 .../internal}/repository/root_test.go | 0 44 files changed, 46 insertions(+), 27 deletions(-) rename .goreleaser.yml => tools/.goreleaser.yml (100%) rename {cmd => tools/cmd}/memory-bank-lint/main.go (75%) rename {cmd => tools/cmd}/memory-bank/main.go (72%) rename go.mod => tools/go.mod (51%) rename go.sum => tools/go.sum (100%) rename {internal => tools/internal}/cli/cli.go (98%) rename {internal => tools/internal}/cli/cli_test.go (99%) rename {internal => tools/internal}/lint/audit.go (100%) rename {internal => tools/internal}/lint/audit_test.go (100%) rename {internal => tools/internal}/lint/markdown.go (100%) rename {internal => tools/internal}/lint/report.go (100%) rename {internal => tools/internal}/lint/testdata/expected-report.json (100%) rename {internal => tools/internal}/lint/testdata/repository/memory-bank/README.md (100%) rename {internal => tools/internal}/lint/testdata/repository/memory-bank/orphan.md (100%) rename {internal => tools/internal}/lint/testdata/repository/memory-bank/section/README.md (100%) rename {internal => tools/internal}/lint/testdata/repository/memory-bank/section/child.md (100%) rename {internal => tools/internal}/lint/testdata/repository/memory-bank/section/deep/README.md (100%) rename {internal => tools/internal}/lint/testdata/repository/memory-bank/section/deep/leaf.md (100%) rename {internal => tools/internal}/lint/types.go (100%) rename {internal => tools/internal}/ownership/classify.go (100%) rename {internal => tools/internal}/ownership/classify_test.go (100%) rename {internal => tools/internal}/ownership/lock.go (100%) rename {internal => tools/internal}/ownership/path.go (100%) rename {internal => tools/internal}/ownership/plan_regression_test.go (100%) rename {internal => tools/internal}/ownership/secure_path_unix.go (100%) rename {internal => tools/internal}/ownership/secure_path_unix_test.go (100%) rename {internal => tools/internal}/ownership/secure_path_windows.go (100%) rename {internal => tools/internal}/ownership/source.go (100%) rename {internal => tools/internal}/ownership/source_test.go (100%) rename {internal => tools/internal}/ownership/symlink_test.go (100%) rename {internal => tools/internal}/ownership/topology.go (100%) rename {internal => tools/internal}/ownership/transaction_test.go (100%) rename {internal => tools/internal}/ownership/types.go (100%) rename {internal => tools/internal}/ownership/update.go (100%) rename {internal => tools/internal}/ownership/update_test.go (100%) rename {internal => tools/internal}/repository/root.go (100%) rename {internal => tools/internal}/repository/root_test.go (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e20aa2..590f4ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,9 +24,11 @@ jobs: - name: Run tests run: go test -count=1 -race ./... + working-directory: tools - name: Run vet run: go vet ./... + working-directory: tools - name: Check formatting run: | @@ -37,6 +39,7 @@ jobs: gofmt -d . exit 1 fi + working-directory: tools - name: Build and run validator env: @@ -49,6 +52,7 @@ jobs: "$RUNNER_TEMP/memory-bank" lint --json > "$RUNNER_TEMP/memory-bank.json" "$RUNNER_TEMP/memory-bank-lint" --json > "$RUNNER_TEMP/memory-bank-lint.json" cmp "$RUNNER_TEMP/memory-bank.json" "$RUNNER_TEMP/memory-bank-lint.json" + working-directory: tools release-config: runs-on: ubuntu-latest @@ -68,3 +72,4 @@ jobs: distribution: goreleaser version: "~> v2" args: check + workdir: tools diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8677980..34dd83a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,6 +29,14 @@ jobs: distribution: goreleaser version: "~> v2" args: release --clean + workdir: tools env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} + + - name: Publish Go module tag + env: + RELEASE_TAG: ${{ github.ref_name }} + run: | + git tag "tools/${RELEASE_TAG}" + git push origin "tools/${RELEASE_TAG}" diff --git a/AGENTS.md b/AGENTS.md index d639d7b..6eee4da 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,8 +20,8 @@ - `rg --files memory-bank` для проверки структуры и имён файлов; - `memory-bank lint` для аудита ссылок, reachability и expected README-индексов внутри `memory-bank/`; -- `go test -count=1 -race ./...` для проверки валидатора и его JSON-контракта без test cache; -- `go vet ./...` для статической проверки Go-кода; +- `go test -count=1 -race ./...` из `tools/` для проверки валидатора и его JSON-контракта без test cache; +- `go vet ./...` из `tools/` для статической проверки Go-кода; - `git diff --check` для поиска лишних пробелов и conflict markers; - `sed -n '1,120p' path/to/doc.md` для быстрой проверки frontmatter и заголовков; - `rg -n "PROJECT_SPECIFIC_TERM" memory-bank` с реальными терминами downstream-проекта, чтобы убедиться, что project-specific детали не протекли обратно в шаблон. diff --git a/docs/adoption.md b/docs/adoption.md index bce44a3..193789b 100644 --- a/docs/adoption.md +++ b/docs/adoption.md @@ -1,6 +1,6 @@ # Внедрение Memory Bank в проект -Этот документ описывает, как подключить Memory Bank к существующему или новому проекту. В downstream-проект устанавливается каталог `memory-bank/`, а внутри него создаётся служебный `memory-bank/.lock`; dev-инфраструктура этого репозитория (`cmd/`, `.github/`, `.goreleaser.yml`, `go.mod`, `docs/`) не является частью шаблона приложения. Lock создаёт `memory-bank init`, а не upstream template. Его нужно коммитить: он хранит версию источника и ownership-границу для безопасных обновлений. +Этот документ описывает, как подключить Memory Bank к существующему или новому проекту. В downstream-проект устанавливается каталог `memory-bank/`, а внутри него создаётся служебный `memory-bank/.lock`; dev-инфраструктура этого репозитория (`tools/`, `.github/`, `docs/`) не является частью шаблона приложения. Lock создаёт `memory-bank init`, а не upstream template. Его нужно коммитить: он хранит версию источника и ownership-границу для безопасных обновлений. ## Что копировать @@ -120,7 +120,7 @@ codex --search \ Для локального аудита установите `memory-bank` как внешний бинарник: ```bash -go install github.com/dapi/memory-bank/cmd/memory-bank@latest +go install github.com/dapi/memory-bank/tools/cmd/memory-bank@latest ``` После этого из любого места внутри downstream Git-репозитория: @@ -133,7 +133,7 @@ memory-bank lint ## Подключить CI -CI-проверка Memory Bank должна быть opt-in в downstream-проекте. Не копируйте `.github/workflows/ci.yml` из этого репозитория: он предназначен для разработки самого шаблона и собирает локальный Go CLI из `cmd/memory-bank`. +CI-проверка Memory Bank должна быть opt-in в downstream-проекте. Не копируйте `.github/workflows/ci.yml` из этого репозитория: он предназначен для разработки самого шаблона и собирает локальный Go CLI из `tools/cmd/memory-bank`. Перед подключением выберите конкретный release tag или commit CLI. Если оставить `@latest`, новая версия `memory-bank` сможет изменить результат проверки без изменений в downstream-репозитории. @@ -167,7 +167,7 @@ jobs: cache: false - name: Install memory-bank - run: go install "github.com/dapi/memory-bank/cmd/memory-bank@${MEMORY_BANK_VERSION}" + run: go install "github.com/dapi/memory-bank/tools/cmd/memory-bank@${MEMORY_BANK_VERSION}" - name: Audit Memory Bank run: memory-bank lint diff --git a/docs/development.md b/docs/development.md index c66682c..803a8a0 100644 --- a/docs/development.md +++ b/docs/development.md @@ -7,15 +7,19 @@ CLI разделён на тонкие entrypoint'ы и переиспользуемые внутренние пакеты: ```text -cmd/memory-bank/ основной entrypoint -cmd/memory-bank-lint/ compatibility entrypoint -internal/cli/ subcommands, flags и общий output/error contract -internal/lint/ audit-движок, отчёт и testdata -internal/repository/ общий repo root discovery +tools/ + go.mod самостоятельный Go-модуль CLI + cmd/memory-bank/ основной entrypoint + cmd/memory-bank-lint/ compatibility entrypoint + internal/cli/ subcommands, flags и общий output/error contract + internal/lint/ audit-движок, отчёт и testdata + internal/repository/ общий repo root discovery ``` Оба бинарника вызывают `internal/cli`; lint-семантика и JSON contract принадлежат `internal/lint`. Новые команды добавляются в общий dispatcher `memory-bank`, а не отдельными бинарниками. +CLI публикуется как вложенный Go-модуль `github.com/dapi/memory-bank/tools`. Release workflow запускается по обычному тегу `vX.Y.Z`, а после успешной публикации создаёт соответствующий module tag `tools/vX.Y.Z`, который требуется командам `go install` и `go run`. + ## Локальная разработка Требуется Go версии `1.21` или новее. `rg` используется для быстрой проверки структуры шаблона. @@ -24,27 +28,29 @@ internal/repository/ общий repo root discovery ```bash rg --files memory-bank +cd tools gofmt -w $(rg --files cmd internal -g '*.go') go test -count=1 -race ./... go vet ./... go run ./cmd/memory-bank lint +cd .. git diff --check ``` Если проверка запускается не из Git-репозитория или нужно проверить другой checkout: ```bash -go run ./cmd/memory-bank lint --repo-root /path/to/repository +(cd tools && go run ./cmd/memory-bank lint --repo-root /path/to/repository) ``` ## Изменение JSON-контракта -Golden report для CLI лежит в `internal/lint/testdata/expected-report.json`. +Golden report для CLI лежит в `tools/internal/lint/testdata/expected-report.json`. Меняйте его только если contract отчёта изменился намеренно. После такого изменения проверьте: ```bash -go test ./... +(cd tools && go test ./...) ``` ## Документационный шаблон diff --git a/docs/memory-bank-lint.md b/docs/memory-bank-lint.md index 5ca85da..4d34d05 100644 --- a/docs/memory-bank-lint.md +++ b/docs/memory-bank-lint.md @@ -17,7 +17,7 @@ Для регулярных проверок установите CLI один раз. Требуется Go версии `1.21` или новее: ```bash -go install github.com/dapi/memory-bank/cmd/memory-bank-lint@latest +go install github.com/dapi/memory-bank/tools/cmd/memory-bank-lint@latest ``` `go install` помещает бинарник в `GOBIN` или `GOPATH/bin`; этот каталог должен находиться в `PATH`. Повторите ту же команду, чтобы обновить CLI до актуальной версии. @@ -33,7 +33,7 @@ command -v memory-bank-lint Если репозиторий уже клонирован и нужно установить версию из текущего checkout: ```bash -go install ./cmd/memory-bank-lint +(cd tools && go install ./cmd/memory-bank-lint) ``` ## Запуск @@ -82,7 +82,7 @@ memory-bank-lint \ Для разовой проверки без установки CLI: ```bash -go run github.com/dapi/memory-bank/cmd/memory-bank-lint@latest +go run github.com/dapi/memory-bank/tools/cmd/memory-bank-lint@latest ``` Установку из GitHub Releases или через Homebrew используйте только после фактической публикации соответствующих release assets и Cask; если их ещё нет, используйте `go install`. diff --git a/docs/memory-bank.md b/docs/memory-bank.md index 1a69668..f48352f 100644 --- a/docs/memory-bank.md +++ b/docs/memory-bank.md @@ -21,7 +21,7 @@ Ownership-контракт, классы файлов и atomic update policy о Для регулярных проверок установите CLI один раз. Требуется Go версии `1.21` или новее: ```bash -go install github.com/dapi/memory-bank/cmd/memory-bank@latest +go install github.com/dapi/memory-bank/tools/cmd/memory-bank@latest ``` `go install` помещает бинарник в `GOBIN` или `GOPATH/bin`; этот каталог должен находиться в `PATH`. Повторите ту же команду, чтобы обновить CLI до актуальной версии. @@ -37,7 +37,7 @@ command -v memory-bank Если репозиторий уже клонирован и нужно установить версию из текущего checkout: ```bash -go install ./cmd/memory-bank +(cd tools && go install ./cmd/memory-bank) ``` ## Запуск @@ -86,7 +86,7 @@ memory-bank lint \ Для разовой проверки без установки CLI: ```bash -go run github.com/dapi/memory-bank/cmd/memory-bank@latest lint +go run github.com/dapi/memory-bank/tools/cmd/memory-bank@latest lint ``` Установку из GitHub Releases или через Homebrew используйте только после фактической публикации соответствующих release assets и Cask; если их ещё нет, используйте `go install`. diff --git a/.goreleaser.yml b/tools/.goreleaser.yml similarity index 100% rename from .goreleaser.yml rename to tools/.goreleaser.yml diff --git a/cmd/memory-bank-lint/main.go b/tools/cmd/memory-bank-lint/main.go similarity index 75% rename from cmd/memory-bank-lint/main.go rename to tools/cmd/memory-bank-lint/main.go index fac833e..ee6d01e 100644 --- a/cmd/memory-bank-lint/main.go +++ b/tools/cmd/memory-bank-lint/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/dapi/memory-bank/internal/cli" + "github.com/dapi/memory-bank/tools/internal/cli" ) var version = "dev" diff --git a/cmd/memory-bank/main.go b/tools/cmd/memory-bank/main.go similarity index 72% rename from cmd/memory-bank/main.go rename to tools/cmd/memory-bank/main.go index 7139d13..a98da23 100644 --- a/cmd/memory-bank/main.go +++ b/tools/cmd/memory-bank/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/dapi/memory-bank/internal/cli" + "github.com/dapi/memory-bank/tools/internal/cli" ) var version = "dev" diff --git a/go.mod b/tools/go.mod similarity index 51% rename from go.mod rename to tools/go.mod index fa7dabf..3c17138 100644 --- a/go.mod +++ b/tools/go.mod @@ -1,4 +1,4 @@ -module github.com/dapi/memory-bank +module github.com/dapi/memory-bank/tools go 1.21 diff --git a/go.sum b/tools/go.sum similarity index 100% rename from go.sum rename to tools/go.sum diff --git a/internal/cli/cli.go b/tools/internal/cli/cli.go similarity index 98% rename from internal/cli/cli.go rename to tools/internal/cli/cli.go index ab1c2b9..06a3b60 100644 --- a/internal/cli/cli.go +++ b/tools/internal/cli/cli.go @@ -10,9 +10,9 @@ import ( "path/filepath" "sort" - "github.com/dapi/memory-bank/internal/lint" - "github.com/dapi/memory-bank/internal/ownership" - "github.com/dapi/memory-bank/internal/repository" + "github.com/dapi/memory-bank/tools/internal/lint" + "github.com/dapi/memory-bank/tools/internal/ownership" + "github.com/dapi/memory-bank/tools/internal/repository" ) const ( diff --git a/internal/cli/cli_test.go b/tools/internal/cli/cli_test.go similarity index 99% rename from internal/cli/cli_test.go rename to tools/internal/cli/cli_test.go index dc41b7d..1ee62b6 100644 --- a/internal/cli/cli_test.go +++ b/tools/internal/cli/cli_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/dapi/memory-bank/internal/lint" + "github.com/dapi/memory-bank/tools/internal/lint" ) func testRepository(t *testing.T) string { diff --git a/internal/lint/audit.go b/tools/internal/lint/audit.go similarity index 100% rename from internal/lint/audit.go rename to tools/internal/lint/audit.go diff --git a/internal/lint/audit_test.go b/tools/internal/lint/audit_test.go similarity index 100% rename from internal/lint/audit_test.go rename to tools/internal/lint/audit_test.go diff --git a/internal/lint/markdown.go b/tools/internal/lint/markdown.go similarity index 100% rename from internal/lint/markdown.go rename to tools/internal/lint/markdown.go diff --git a/internal/lint/report.go b/tools/internal/lint/report.go similarity index 100% rename from internal/lint/report.go rename to tools/internal/lint/report.go diff --git a/internal/lint/testdata/expected-report.json b/tools/internal/lint/testdata/expected-report.json similarity index 100% rename from internal/lint/testdata/expected-report.json rename to tools/internal/lint/testdata/expected-report.json diff --git a/internal/lint/testdata/repository/memory-bank/README.md b/tools/internal/lint/testdata/repository/memory-bank/README.md similarity index 100% rename from internal/lint/testdata/repository/memory-bank/README.md rename to tools/internal/lint/testdata/repository/memory-bank/README.md diff --git a/internal/lint/testdata/repository/memory-bank/orphan.md b/tools/internal/lint/testdata/repository/memory-bank/orphan.md similarity index 100% rename from internal/lint/testdata/repository/memory-bank/orphan.md rename to tools/internal/lint/testdata/repository/memory-bank/orphan.md diff --git a/internal/lint/testdata/repository/memory-bank/section/README.md b/tools/internal/lint/testdata/repository/memory-bank/section/README.md similarity index 100% rename from internal/lint/testdata/repository/memory-bank/section/README.md rename to tools/internal/lint/testdata/repository/memory-bank/section/README.md diff --git a/internal/lint/testdata/repository/memory-bank/section/child.md b/tools/internal/lint/testdata/repository/memory-bank/section/child.md similarity index 100% rename from internal/lint/testdata/repository/memory-bank/section/child.md rename to tools/internal/lint/testdata/repository/memory-bank/section/child.md diff --git a/internal/lint/testdata/repository/memory-bank/section/deep/README.md b/tools/internal/lint/testdata/repository/memory-bank/section/deep/README.md similarity index 100% rename from internal/lint/testdata/repository/memory-bank/section/deep/README.md rename to tools/internal/lint/testdata/repository/memory-bank/section/deep/README.md diff --git a/internal/lint/testdata/repository/memory-bank/section/deep/leaf.md b/tools/internal/lint/testdata/repository/memory-bank/section/deep/leaf.md similarity index 100% rename from internal/lint/testdata/repository/memory-bank/section/deep/leaf.md rename to tools/internal/lint/testdata/repository/memory-bank/section/deep/leaf.md diff --git a/internal/lint/types.go b/tools/internal/lint/types.go similarity index 100% rename from internal/lint/types.go rename to tools/internal/lint/types.go diff --git a/internal/ownership/classify.go b/tools/internal/ownership/classify.go similarity index 100% rename from internal/ownership/classify.go rename to tools/internal/ownership/classify.go diff --git a/internal/ownership/classify_test.go b/tools/internal/ownership/classify_test.go similarity index 100% rename from internal/ownership/classify_test.go rename to tools/internal/ownership/classify_test.go diff --git a/internal/ownership/lock.go b/tools/internal/ownership/lock.go similarity index 100% rename from internal/ownership/lock.go rename to tools/internal/ownership/lock.go diff --git a/internal/ownership/path.go b/tools/internal/ownership/path.go similarity index 100% rename from internal/ownership/path.go rename to tools/internal/ownership/path.go diff --git a/internal/ownership/plan_regression_test.go b/tools/internal/ownership/plan_regression_test.go similarity index 100% rename from internal/ownership/plan_regression_test.go rename to tools/internal/ownership/plan_regression_test.go diff --git a/internal/ownership/secure_path_unix.go b/tools/internal/ownership/secure_path_unix.go similarity index 100% rename from internal/ownership/secure_path_unix.go rename to tools/internal/ownership/secure_path_unix.go diff --git a/internal/ownership/secure_path_unix_test.go b/tools/internal/ownership/secure_path_unix_test.go similarity index 100% rename from internal/ownership/secure_path_unix_test.go rename to tools/internal/ownership/secure_path_unix_test.go diff --git a/internal/ownership/secure_path_windows.go b/tools/internal/ownership/secure_path_windows.go similarity index 100% rename from internal/ownership/secure_path_windows.go rename to tools/internal/ownership/secure_path_windows.go diff --git a/internal/ownership/source.go b/tools/internal/ownership/source.go similarity index 100% rename from internal/ownership/source.go rename to tools/internal/ownership/source.go diff --git a/internal/ownership/source_test.go b/tools/internal/ownership/source_test.go similarity index 100% rename from internal/ownership/source_test.go rename to tools/internal/ownership/source_test.go diff --git a/internal/ownership/symlink_test.go b/tools/internal/ownership/symlink_test.go similarity index 100% rename from internal/ownership/symlink_test.go rename to tools/internal/ownership/symlink_test.go diff --git a/internal/ownership/topology.go b/tools/internal/ownership/topology.go similarity index 100% rename from internal/ownership/topology.go rename to tools/internal/ownership/topology.go diff --git a/internal/ownership/transaction_test.go b/tools/internal/ownership/transaction_test.go similarity index 100% rename from internal/ownership/transaction_test.go rename to tools/internal/ownership/transaction_test.go diff --git a/internal/ownership/types.go b/tools/internal/ownership/types.go similarity index 100% rename from internal/ownership/types.go rename to tools/internal/ownership/types.go diff --git a/internal/ownership/update.go b/tools/internal/ownership/update.go similarity index 100% rename from internal/ownership/update.go rename to tools/internal/ownership/update.go diff --git a/internal/ownership/update_test.go b/tools/internal/ownership/update_test.go similarity index 100% rename from internal/ownership/update_test.go rename to tools/internal/ownership/update_test.go diff --git a/internal/repository/root.go b/tools/internal/repository/root.go similarity index 100% rename from internal/repository/root.go rename to tools/internal/repository/root.go diff --git a/internal/repository/root_test.go b/tools/internal/repository/root_test.go similarity index 100% rename from internal/repository/root_test.go rename to tools/internal/repository/root_test.go