forge

module
v0.0.0-...-3e91960 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT

README

forge

A Cobra-based CLI built with Forge.

Quick start

# Install dependencies
task deps

# Build the binary into ./bin/forge
task build

# Run from source
go run ./cmd/forge version

# Or install onto $PATH
task install
forge version

Adding a subcommand

Each subcommand lives in its own file under cmd/forge/. The pattern mirrors version.go:

// cmd/forge/hello.go
package main

import (
	"fmt"

	"github.com/spf13/cobra"
)

var helloCmd = &cobra.Command{
	Use:   "hello [name]",
	Short: "Print a greeting",
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		name := "world"
		if len(args) > 0 {
			name = args[0]
		}
		fmt.Printf("hello, %s\n", name)
	},
}

func init() {
	rootCmd.AddCommand(helloCmd)
}

For larger commands, factor logic into internal/<package>/ and call it from the cobra Run function. forge add package <name> scaffolds an internal package with a contract interface and tests.

Task commands

Command Description
task build Build the CLI binary into ./bin/forge
task install Install the CLI into $GOBIN
task test Run go test ./...
task lint Run golangci-lint
task fmt Run goimports -w and go mod tidy
task vet Run go vet ./...
task clean Remove ./bin and coverage outputs

Run task --list (or just task) for the full set.

Project structure

forge/
├── cmd/forge/    # Cobra root + subcommands (each in its own file)
├── internal/         # Application packages (forge add package <name>)
├── pkg/config/       # Configuration types (extend as needed)
├── .reliant/         # Forge conventions, skills, project metadata
├── docs/adr/         # Architecture Decision Records
├── forge.yaml        # Forge project manifest (kind: cli)
├── go.mod
├── README.md
└── Taskfile.yml

Build flags

Stamp the binary's version, commit, and date at build time so forge version reports a real release rather than dev:

go build -trimpath -buildvcs=true \
  -ldflags="-X main.version=v1.0.0 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
  -o bin/forge ./cmd/forge

Directories

Path Synopsis
Package cli provides the public entry point for embedding Forge's CLI as a subcommand in other cobra-based CLIs.
Package cli provides the public entry point for embedding Forge's CLI as a subcommand in other cobra-based CLIs.
cmd
contractlint command
forge command
forge-mcp command
Command forge-mcp is a Model Context Protocol stdio server that reads gen/mcp/manifest.json and exposes every RPC tool the manifest declares to an MCP client (Claude Desktop, the official MCP Inspector, Cline, etc.).
Command forge-mcp is a Model Context Protocol stdio server that reads gen/mcp/manifest.json and exposes every RPC tool the manifest declares to an MCP client (Claude Desktop, the official MCP Inspector, Cline, etc.).
internal
buildinfo
Package buildinfo exposes the forge binary's version metadata to packages that cannot depend on internal/cli (to avoid import cycles).
Package buildinfo exposes the forge binary's version metadata to packages that cannot depend on internal/cli (to avoid import cycles).
buildtarget
Package buildtarget owns the per-service build dispatch for services whose source lives outside the project's Go module — sibling repos, third-party binaries, language runtimes forge doesn't natively build.
Package buildtarget owns the per-service build dispatch for services whose source lives outside the project's Go module — sibling repos, third-party binaries, language runtimes forge doesn't natively build.
checksums
Package checksums owns forge's file-ownership machinery: which bytes does forge certify as its own render, which files has the user taken over, and what may a generate run overwrite.
Package checksums owns forge's file-ownership machinery: which bytes does forge certify as its own render, which files has the user taken over, and what may a generate run overwrite.
cli
`forge generate accept-fork <path>...` — DEPRECATED alias for `forge disown`.
`forge generate accept-fork <path>...` — DEPRECATED alias for `forge disown`.
cli/add
Package add holds the `forge add` command group — the verbs that scaffold a new component (service / worker / operator / binary / frontend / webhook / package / adapter / library / handler-file / rpc / entity / crd / scenario) into an existing forge project.
Package add holds the `forge add` command group — the verbs that scaffold a new component (service / worker / operator / binary / frontend / webhook / package / adapter / library / handler-file / rpc / entity / crd / scenario) into an existing forge project.
cli/audit
Package audit holds the `forge audit` command group — a comprehensive snapshot of project state designed to orient an LLM (or human) without forcing them to grep ten different directories.
Package audit holds the `forge audit` command group — a comprehensive snapshot of project state designed to orient an LLM (or human) without forcing them to grep ten different directories.
cli/audittype
Package audittype holds the small, neutral value types shared by the `forge audit` command group (internal/cli/audit) and the internal/cli code that contributes audit categories it cannot compute without package-cli internals (the KCL-entity-typed ingress / external-builds categories, and friction.go's auditFriction).
Package audittype holds the small, neutral value types shared by the `forge audit` command group (internal/cli/audit) and the internal/cli code that contributes audit categories it cannot compute without package-cli internals (the KCL-entity-typed ingress / external-builds categories, and friction.go's auditFriction).
cli/backlog
Package backlog holds the `forge backlog` command group — list / add / close / open / migrate over the structured FORGE_BACKLOG.md.
Package backlog holds the `forge backlog` command group — list / add / close / open / migrate over the structured FORGE_BACKLOG.md.
cli/cmdutil
Package cmdutil holds cross-cutting helpers shared by forge's own CLI across MORE THAN ONE command group (internal/cli and its dir-nested subpackages).
Package cmdutil holds cross-cutting helpers shared by forge's own CLI across MORE THAN ONE command group (internal/cli and its dir-nested subpackages).
cli/component
Package component holds the `forge component` command group — list, search, and install UI components from forge's built-in component library.
Package component holds the `forge component` command group — list, search, and install UI components from forge's built-in component library.
cli/debug
Package debug holds the `forge debug` command group — a Delve-backed interactive debugger driver (start / break / continue / eval / ...).
Package debug holds the `forge debug` command group — a Delve-backed interactive debugger driver (start / break / continue / eval / ...).
cli/factory
Package factory carries the shared dependency set ("the factory") threaded through forge's own CLI command tree, plus the command REGISTRY that lets dir-nested command-group subpackages (internal/cli/add, internal/cli/lint, ...) attach to the root without a group↔root import cycle.
Package factory carries the shared dependency set ("the factory") threaded through forge's own CLI command tree, plus the command REGISTRY that lets dir-nested command-group subpackages (internal/cli/add, internal/cli/lint, ...) attach to the root without a group↔root import cycle.
cli/lint
Package lint holds the `forge lint` command group — the project linter pipeline (golangci / buf / frontend / forge-convention / scaffold / migration-safety / wire-coverage / authz-completeness …) plus the targeted single-rule flags and the --json aggregator.
Package lint holds the `forge lint` command group — the project linter pipeline (golangci / buf / frontend / forge-convention / scaffold / migration-safety / wire-coverage / authz-completeness …) plus the targeted single-rule flags and the --json aggregator.
cli/pack
Package pack holds the `forge pack` command group — manage installable packs (list / install / remove / info).
Package pack holds the `forge pack` command group — manage installable packs (list / install / remove / info).
cliutil
Package cliutil holds small helpers shared across forge's CLI surface.
Package cliutil holds small helpers shared across forge's CLI surface.
cluster
Package cluster owns the render-KCL → kubectl-apply → wait-rollouts pipeline that `forge deploy`, `forge cluster reload`, and the deploy phase of `forge up` all execute.
Package cluster owns the render-KCL → kubectl-apply → wait-rollouts pipeline that `forge deploy`, `forge cluster reload`, and the deploy phase of `forge up` all execute.
codegen
Package codegen renders Go source files for the canonical scaffolds forge produces: handler stubs, CRUD handlers, authorizer, auth/tenant middleware, bootstrap wiring, mock services, and config loaders.
Package codegen renders Go source files for the canonical scaffolds forge produces: handler stubs, CRUD handlers, authorizer, auth/tenant middleware, bootstrap wiring, mock services, and config loaders.
config
Package config defines the canonical forge.yaml types shared across forge.
Package config defines the canonical forge.yaml types shared across forge.
contractcheck
Package contractcheck inspects a project's internal/ tree for contract-shape violations.
Package contractcheck inspects a project's internal/ tree for contract-shape violations.
database
Code generated by forge.
Code generated by forge.
debug
Package debug wraps a Delve debugger so forge can drive a debugging session from the CLI / MCP layers.
Package debug wraps a Delve debugger so forge can drive a debugging session from the CLI / MCP layers.
deploytarget
Package deploytarget owns the per-service deploy dispatch — the surface that maps a rendered KCL Service.deploy block to a concrete pipeline that ships the service somewhere.
Package deploytarget owns the per-service deploy dispatch — the surface that maps a rendered KCL Service.deploy block to a concrete pipeline that ships the service somewhere.
docs
Package docs renders project documentation (markdown / hugo) from the project config, proto descriptors, and contract.go interfaces.
Package docs renders project documentation (markdown / hugo) from the project config, proto descriptors, and contract.go interfaces.
doctor
Package doctor runs health checks against a forge project's development stack: docker-compose services, app endpoints, the telemetry backends bundled in the lgtm container, and the Delve debugger when --debug is active.
Package doctor runs health checks against a forge project's development stack: docker-compose services, app endpoints, the telemetry backends bundled in the lgtm container, and the Delve debugger when --debug is active.
envutil
Package envutil holds the small, shared environment-handling helpers the build, deploy, and host-launch paths all need: a minimal .env parser and two env-overlay merges whose precedence is encoded in the name.
Package envutil holds the small, shared environment-handling helpers the build, deploy, and host-launch paths all need: a minimal .env parser and two env-overlay merges whose precedence is encoded in the name.
generator
Package generator: checksums shim.
Package generator: checksums shim.
generator/contract
Package contract drives the four *_gen.go files (mock, middleware, tracing, metrics) emitted from a single hand-written contract.go.
Package contract drives the four *_gen.go files (mock, middleware, tracing, metrics) emitted from a single hand-written contract.go.
hostlaunch
Package hostlaunch composes exec.Cmds for host-mode services and frontends, plus the small env-file helpers both call sites need.
Package hostlaunch composes exec.Cmds for host-mode services and frontends, plus the small env-file helpers both call sites need.
installkit
Package installkit holds the small set of genuinely-shared rendering primitives used by `internal/packs`.
Package installkit holds the small set of genuinely-shared rendering primitives used by `internal/packs`.
kclplugin
Package kclplugin registers forge's in-process KCL plugin namespace (kcl_plugin.forge.*), letting KCL pull host-runtime values during evaluation instead of forge having to pre-enumerate and inject them.
Package kclplugin registers forge's in-process KCL plugin namespace (kcl_plugin.forge.*), letting KCL pull host-runtime values during evaluation instead of forge having to pre-enumerate and inject them.
kclrender
Package kclrender is the single seam through which forge evaluates KCL.
Package kclrender is the single seam through which forge evaluates KCL.
linter/authzlint
Package authzlint is the generate-time completeness gate for forge's descriptor-driven authorization.
Package authzlint is the generate-time completeness gate for forge's descriptor-driven authorization.
linter/finding
Package finding is the single canonical home for the lint-finding vocabulary shared by every internal linter (forgeconv, scaffolds, migrationlint, frontendpacklint).
Package finding is the single canonical home for the lint-finding vocabulary shared by every internal linter (forgeconv, scaffolds, migrationlint, frontendpacklint).
linter/forgeconv
Package forgeconv implements lint rules that enforce forge codegen conventions on proto files.
Package forgeconv implements lint rules that enforce forge codegen conventions on proto files.
linter/frontendpacklint
Package frontendpacklint provides a soft-rule analyzer that flags frontend pack templates importing third-party UI libraries directly instead of wrapping the forge base component library.
Package frontendpacklint provides a soft-rule analyzer that flags frontend pack templates importing third-party UI libraries directly instead of wrapping the forge base component library.
linter/scaffolds
Package scaffolds — `forge lint --check-workarounds` rule.
Package scaffolds — `forge lint --check-workarounds` rule.
packs
Code generated by forge.
Code generated by forge.
projectstore
Package projectstore is the single read+mutate surface for a forge project's state.
Package projectstore is the single read+mutate surface for a forge project's state.
schemadef
Package schemadef projects a project's APPLIED database schema — db/migrations/*.up.sql executed in order against a REAL ephemeral postgres — into a typed model that code generation consumes.
Package schemadef projects a project's APPLIED database schema — db/migrations/*.up.sql executed in order against a REAL ephemeral postgres — into a typed model that code generation consumes.
secrets
Package secrets resolves declared secret REFERENCES (which live in git: EnvVar.secret_ref / secret_key) to secret VALUES (which never live in git) for one environment.
Package secrets resolves declared secret REFERENCES (which live in git: EnvVar.secret_ref / secret_key) to secret VALUES (which never live in git) for one environment.
statefile
Package statefile is the one place forge's JSON-record-under-.forge/state helpers live.
Package statefile is the one place forge's JSON-record-under-.forge/state helpers live.
templates
Package templates owns the embedded forge template tree and renders it into scaffolded code.
Package templates owns the embedded forge template tree and renders it into scaffolded code.
pkg module

Jump to

Keyboard shortcuts

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