Documentation
¶
Index ¶
- Constants
- func DetermineTargetRepo(config *RoutingConfig, userRole UserRole, repoPath string) string
- func ExtractPrefix(id string) string
- func ExtractProjectFromPath(path string) string
- func ResolveBeadsDirForID(ctx context.Context, id, currentBeadsDir string) (string, bool, error)
- func ResolveBeadsDirForRig(rigOrPrefix, currentBeadsDir string) (beadsDir string, prefix string, err error)
- func ResolveToExternalRef(id, beadsDir string) string
- type Route
- type RoutedStorage
- type RoutingConfig
- type UserRole
Constants ¶
const RoutesFileName = "routes.jsonl"
RoutesFileName is the name of the routes configuration file
Variables ¶
This section is empty.
Functions ¶
func DetermineTargetRepo ¶
func DetermineTargetRepo(config *RoutingConfig, userRole UserRole, repoPath string) string
DetermineTargetRepo determines which repo should receive a new issue based on routing configuration and user role
func ExtractPrefix ¶
ExtractPrefix extracts the prefix from an issue ID. For "gt-abc123", returns "gt-". For "bd-abc123", returns "bd-". Returns empty string if no prefix found.
func ExtractProjectFromPath ¶
ExtractProjectFromPath extracts the project name from a route path. For "beads/mayor/rig", returns "beads". For "gastown/crew/max", returns "gastown".
func ResolveBeadsDirForID ¶
ResolveBeadsDirForID determines which beads directory contains the given issue ID. It first checks the local beads directory, then consults routes.jsonl for prefix-based routing. If routes.jsonl is not found locally, it searches up to the town root.
Parameters:
- ctx: context for database operations
- id: the issue ID to look up
- currentBeadsDir: the current/local .beads directory path
Returns:
- beadsDir: the resolved .beads directory path
- routed: true if the ID was routed to a different directory
- err: any error encountered
func ResolveBeadsDirForRig ¶
func ResolveBeadsDirForRig(rigOrPrefix, currentBeadsDir string) (beadsDir string, prefix string, err error)
ResolveBeadsDirForRig returns the beads directory for a given rig identifier. This is used by --rig and --prefix flags to create issues in a different rig.
The input is forgiving - accepts any of:
- "beads", "gastown" (rig names)
- "bd-", "gt-" (exact prefixes)
- "bd", "gt" (prefixes without hyphen)
Parameters:
- rigOrPrefix: rig name or prefix in any format
- currentBeadsDir: the current .beads directory (used to find routes.jsonl)
Returns:
- beadsDir: the target .beads directory path
- prefix: the issue prefix for that rig (e.g., "bd-")
- err: error if rig not found or path doesn't exist
func ResolveToExternalRef ¶
ResolveToExternalRef attempts to convert a foreign issue ID to an external reference using routes.jsonl for prefix-based routing.
If the ID's prefix matches a route, returns "external:<project>:<id>". Otherwise, returns empty string (no route found).
Example: If routes.jsonl has {"prefix": "bd-", "path": "beads/mayor/rig"} then ResolveToExternalRef("bd-abc", beadsDir) returns "external:beads:bd-abc"
Types ¶
type Route ¶
type Route struct {
Prefix string `json:"prefix"` // Issue ID prefix (e.g., "gt-")
Path string `json:"path"` // Relative path to .beads directory
}
Route represents a prefix-to-path routing rule
func LoadRoutes ¶
LoadRoutes loads routes from routes.jsonl in the given beads directory. Returns an empty slice if the file doesn't exist.
func LookupRigByName ¶
LookupRigByName finds a route by rig name (first path component). For example, LookupRigByName("beads", beadsDir) would find the route with path "beads/mayor/rig" and return it.
Returns the matching route and true if found, or zero Route and false if not.
func LookupRigForgiving ¶
LookupRigForgiving finds a route using flexible matching. Accepts any of these formats and normalizes them:
- "bd-" (exact prefix)
- "bd" (prefix without hyphen, will try "bd-")
- "beads" (rig name)
This provides good agent UX - meet them where they are. It searches for routes.jsonl in the current beads dir first, then at the town level.
type RoutedStorage ¶
type RoutedStorage struct {
Storage storage.Storage
BeadsDir string
Routed bool // true if this is a routed (non-local) storage
}
RoutedStorage represents a storage connection that may have been routed to a different beads directory than the local one.
func GetRoutedStorageForID ¶
func GetRoutedStorageForID(ctx context.Context, id, currentBeadsDir string) (*RoutedStorage, error)
GetRoutedStorageForID returns a storage connection for the given issue ID. If the ID matches a route, it opens a connection to the routed database. Otherwise, it returns nil (caller should use their existing storage).
The caller is responsible for closing the returned RoutedStorage.
func (*RoutedStorage) Close ¶
func (rs *RoutedStorage) Close() error
Close closes the storage connection
type RoutingConfig ¶
type RoutingConfig struct {
Mode string // "auto" or "explicit"
DefaultRepo string // Default repo for new issues
MaintainerRepo string // Repo for maintainers (in auto mode)
ContributorRepo string // Repo for contributors (in auto mode)
ExplicitOverride string // Explicit --repo flag override
}
RoutingConfig defines routing rules for issues
type UserRole ¶
type UserRole string
UserRole represents whether the user is a maintainer or contributor
func DetectUserRole ¶
DetectUserRole determines if the user is a maintainer or contributor based on git configuration and repository permissions.
Detection strategy: 1. Check if user has push access to origin (git remote -v shows write URL) 2. Check git config for beads.role setting (explicit override) 3. Fall back to contributor if uncertain