Checkpoint commit covering concurrent work across several archie-core-abg epics to avoid losing in-progress state: - Memory manager (18.7-18.16): background sync pipeline, prefetch with timeout, memory-write notification, threat scanning, shutdown drain with abandoned-write tracking, frozen snapshot pattern. Wired ScanContent and NotifyMemoryToolWrite into HandleToolCall so scanning and notification actually apply to writes, not just exist as unused primitives. - Fixed a literal unresolved merge-conflict that had been committed to internal/memory/scrubber/scrubber.go. - Tool provider/registry, MCP client/transport (stdio, HTTP, SSE), multimodal results, disclosure. - Pairing device auth store, rate limiting. - Gateway compression, session store, tasks. - Various workflow, plugin host, and agentexec updates.
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) {
|
|
max := big.NewInt(int64(len(Alphabet)))
|
|
code := make([]byte, CodeLength)
|
|
for i := range code {
|
|
n, err := rand.Int(rand.Reader, max)
|
|
if err != nil {
|
|
return "", fmt.Errorf("pairing: generate code: %w", err)
|
|
}
|
|
code[i] = Alphabet[n.Int64()]
|
|
}
|
|
return string(code), nil
|
|
}
|