An unofficial terminal client for Tangled, optimized for humans and agents. tgcli.wisp.place
cli atproto go tangled
tg CONTRIBUTING.md
5.7 kB
Markdown

Contributing #

Before committing #

Development #

# Build
go build ./cmd/tg

# Test
go test ./...

Upstream integration tests #

internal/app/upstream_integration_test.go exercises real upstream services. It is opt-in and uses only Tangled Core's disposable *.tngl.boltless.dev localinfra endpoints and seeded Alice account. It creates records and Git repositories, removes them after successful checks, and leaves failures for inspection. Run it against a separate localinfra state directory.

Start upstream's localinfra stack with Knot, PDS, PLC, Hydrant, Bobbin, Pocket, Knotmirror, and Redis. Wait for the firehose connections and Bobbin coverage to become ready; HTTP health checks alone do not establish ingestion readiness. Upstream's localinfra/pc/README.md describes stack setup and fixture seeding. The fixture account is alice.pds.tngl.boltless.dev, with password password. This test uses password authentication and real PDS service-auth tokens.

Compile from this checkout before entering the Linux network namespace:

nix develop -c sh -c 'CGO_ENABLED=0 go test -c -tags upstream_integration -o /tmp/tg-upstream-integration.test ./internal/app'

Set core_checkout to the upstream checkout and stack_state to its isolated TNGL_STATE directory. Run the binary in the namespace that hosts the services:

nsenter --user --preserve-credentials --net --mount \
  -t "$(cat "$stack_state/run/ns.pid")" \
  env TG_UPSTREAM_INTEGRATION=1 \
  SSL_CERT_FILE="$core_checkout/localinfra/certs/root.crt" \
  /tmp/tg-upstream-integration.test -test.run TestUpstream -test.v

Git must be available in that environment with SHA-256 repository support. Without TG_UPSTREAM_INTEGRATION=1, the tagged tests skip. They are excluded from the ordinary package build and do not change CI.

To include live Spindle API checks, enable upstream's spindle profile and add TG_UPSTREAM_SPINDLE_INTEGRATION=1 to the test process environment. The PR fixture creates a dummy-engine workflow and checks manual trigger receipts, completion, archived logs, retry, listing, and cancellation of a finished run. The dummy engine does not execute the workflow's shell commands. Current upstream Spindle closes archived-log streams without confirming completion. The test checks the expected content and outcome and reports that known limitation in verbose output. See internal/tangledlex/README.md for the source and scope.

Nix #

Nix is a first-class citizen: the flake builds the package, runs the tests, and generates the shell completions and man pages. go build passing is not enough — verify changes with nix build before committing.

# Full package build (also runs go test ./...)
nix build

# Dev shell with Go and the treefmt formatters
nix develop

# Format Go, Nix, Markdown, and shell files
nix fmt

Without Nix, run the formatters nix fmt wraps directly: gofmt -w . for Go (ships with the Go toolchain), prettier --write . for Markdown, and alejandra . for Nix files.

Updating vendorHash #

The Nix package pins a vendorHash of the Go module dependencies in nix/tg.nix. Any change to go.mod or go.sum — adding, removing, or bumping a dependency — invalidates it, and nix build fails with a hash mismatch:

error: hash mismatch in fixed-output derivation:
         specified: sha256-AAAA...
            got:    sha256-BBBB...

Copy the got: hash into vendorHash in nix/tg.nix and re-run nix build. Do not commit dependency changes until the Nix build passes with the updated hash.

Documentation #

Docs are the Astro site in website/: hand-written pages in website/src/content/docs/ (the reference/commands/ pages are generated and gitignored, produced from help text by website/scripts/gen-commands.mjs, which needs the tg binary built first). Keep help text accurate. Build locally with cd website && bun install && bun run build.

Architecture #

  • cmd/tg/ — CLI entry point
  • internal/cli/ — Cobra command tree (repo, issue, pr); Viper-backed configuration
  • internal/gitutil/ — Git operations (clone, fetch, patch apply)
  • tangled/ — Typed client for the Bobbin API (api.tangled.org)
  • atproto/ — Identity resolution (handle ↔ DID, PDS discovery); OAuth session storage (system keyring)

Generated code #

internal/tangledlex/ is generated from the Tangled lexicons. Do not edit the .go files in that package by hand or via PR; they are produced by internal/tangledlex/generate-lexicons.sh and carry // Code generated ... headers. To add or update lexicons, modify schemas.txt (and the CBOR generator list in cborgen/main.go if needed) and run the update script. See internal/tangledlex/README.md for the full workflow.

Dependencies #