130 -> 96. forcetypeassert, predeclared and usetesting are now at zero.
Fanned out across four isolated worktrees partitioned by package so no
two workers could touch the same file: internal/tools (20 assertions),
internal/webui, internal/memory + internal/ratelimit, internal/secret.
Four stragglers outside those scopes fixed inline (internal/pairing,
internal/forge, internal/channels/telegram, internal/tools/mcp).
Unchecked type assertions became comma-ok with a t.Fatalf naming the
actual type. One site in a goroutine uses t.Errorf + return instead,
since t.Fatalf from a non-test goroutine is undefined behaviour.
predeclared renames chose names from meaning rather than adding a
suffix: max -> maxQueryLen, maxMatchLen, maxRequests, alphabetLen, and
nextBackoff's max -> ceiling. `real` -> `base` in the webui tests.
os.Setenv became t.Setenv, which restores on cleanup, so the paired
deferred Unsetenv calls went with it.
Note for future fan-outs: the agent worktrees branched from origin/main
(a7388a0), not from this branch, so every diff arrived based on a tree
without the phase 1 autofix. They were applied with `git apply --3way`
and the phase 1 changes to internal/memory/manager.go were verified to
survive — in particular the repaired `ctx, cancel =` assignment. A plain
`git apply` would have silently reverted it.
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// Package pairing implements device-pairing codes for gateway
|
|
// authorization: a short, human-typeable code an operator hands to a
|
|
// new chat user, which the daemon verifies before granting access.
|
|
package pairing
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"math/big"
|
|
)
|
|
|
|
// Alphabet is the set of characters a pairing code is drawn from: digits
|
|
// 2-9 and uppercase A-Z excluding I and O. It deliberately excludes 0,
|
|
// O, 1, and I -- characters humans commonly misread or mistype when
|
|
// copying a code from a screen.
|
|
const Alphabet = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
|
|
// CodeLength is the number of characters in a generated pairing code.
|
|
const CodeLength = 8
|
|
|
|
// GenerateCode returns a random CodeLength-character code drawn
|
|
// uniformly from Alphabet using crypto/rand.
|
|
func GenerateCode() (string, error) {
|
|
alphabetLen := big.NewInt(int64(len(Alphabet)))
|
|
code := make([]byte, CodeLength)
|
|
for i := range code {
|
|
n, err := rand.Int(rand.Reader, alphabetLen)
|
|
if err != nil {
|
|
return "", fmt.Errorf("pairing: generate code: %w", err)
|
|
}
|
|
code[i] = Alphabet[n.Int64()]
|
|
}
|
|
return string(code), nil
|
|
}
|