a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package graph
|
|
|
|
import "strings"
|
|
|
|
// IsProxyNode reports whether n is a cross-daemon proxy-edge node —
|
|
// identified by its struct fields, NOT its ID shape. Distinct from
|
|
// IsStub(id) (the stdlib/builtin/module string predicate): a proxy node
|
|
// is keyed under the "remote:<slug>~..." origin namespace, which IsStub
|
|
// does not recognise. Proxy nodes are excluded from graph_stats / BM25 /
|
|
// communities / analyzers and never persisted to the durable store.
|
|
func IsProxyNode(n *Node) bool {
|
|
return n != nil && n.Stub && n.Origin != ""
|
|
}
|
|
|
|
// proxyIDPrefix is the origin-namespace marker for a proxy node id.
|
|
const proxyIDPrefix = "remote:"
|
|
|
|
// proxyIDSep separates the origin segment from the remote's native id.
|
|
const proxyIDSep = "~"
|
|
|
|
// ProxyNodeID composes the origin-namespaced id for a remote symbol so a
|
|
// remote node can never alias a local id, even when two daemons share a
|
|
// repo prefix: "remote:<slug>~<remoteRepoPrefix>/<file>::<sym>".
|
|
func ProxyNodeID(slug, remoteID string) string {
|
|
return proxyIDPrefix + slug + proxyIDSep + remoteID
|
|
}
|
|
|
|
// IsProxyID reports whether id is an origin-namespaced proxy id.
|
|
func IsProxyID(id string) bool {
|
|
if !strings.HasPrefix(id, proxyIDPrefix) {
|
|
return false
|
|
}
|
|
return strings.Contains(id[len(proxyIDPrefix):], proxyIDSep)
|
|
}
|
|
|
|
// ProxyOriginSlug returns the <slug> of a proxy id, or "" if id is not a
|
|
// proxy id.
|
|
func ProxyOriginSlug(id string) string {
|
|
if !strings.HasPrefix(id, proxyIDPrefix) {
|
|
return ""
|
|
}
|
|
rest := id[len(proxyIDPrefix):]
|
|
i := strings.Index(rest, proxyIDSep)
|
|
if i < 0 {
|
|
return ""
|
|
}
|
|
return rest[:i]
|
|
}
|
|
|
|
// ProxyRemoteID returns the remote's native id encoded in a proxy id, or
|
|
// "" if id is not a proxy id.
|
|
func ProxyRemoteID(id string) string {
|
|
if !strings.HasPrefix(id, proxyIDPrefix) {
|
|
return ""
|
|
}
|
|
rest := id[len(proxyIDPrefix):]
|
|
i := strings.Index(rest, proxyIDSep)
|
|
if i < 0 {
|
|
return ""
|
|
}
|
|
return rest[i+len(proxyIDSep):]
|
|
}
|