You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go implementation of Cap URN (Capability Uniform Resource Names), built on Tagged URN.
Features
Required Direction Specifiers - in/out tags for input/output media types
Media URN Validation - Validates direction spec values are valid Media URNs
Special Pattern Values - * (must-have-any), ? (unspecified), ! (must-not-have)
Graded Specificity - Exact values score higher than wildcards
Cap Definitions - Full capability definitions with arguments, output, and metadata
Cap Matrix - Registry for capability lookup and matching
Cap Caller - Fluent API for invoking capabilities
Schema Validation - JSON Schema validation for arguments and outputs
Installation
go get github.com/machinefabric/capdag-go
Quick Start
package main
import (
"fmt""log""github.com/machinefabric/capdag-go"
)
funcmain() {
// Parse a Cap URNcap, err:=capdag.NewCapUrnFromString(`cap:in="media:binary";extract;out="media:object"`)
iferr!=nil {
log.Fatal(err)
}
fmt.Println("Input:", cap.GetInSpec()) // "media:binary"fmt.Println("Output:", cap.GetOutSpec()) // "media:object"fmt.Println("Has extract marker:", cap.HasMarkerTag("extract")) // true// Build a Cap URNbuilt:=capdag.NewCapUrnBuilder().
InSpec("media:void").
OutSpec("media:object").
Marker("generate").
Tag("target", "thumbnail").
MustBuild()
// Check matchingpattern, _:=capdag.NewCapUrnFromString(`cap:in="media:binary";extract;out="media:object"`)
ifcap.Accepts(pattern) {
fmt.Println("Cap matches pattern")
}
// Get specificity (graded scoring)fmt.Println("Specificity:", cap.Specificity())
}
Cap Definitions
// Create a full capability definitioncapDef:=&capdag.Cap{
Urn: cap,
Title: "PDF Text Extractor",
Args: []capdag.CapArg{
{Name: "pages", Type: "string", Description: "Page range (e.g., '1-5')"},
},
Output: &capdag.CapOutput{
Type: "text",
Description: "Extracted text content",
},
}
Cap Matrix (Registry)
// Create a capability registrymatrix:=capdag.NewCapMatrix()
// Register a capability with its handlermatrix.RegisterCapSet("my-cartridge", myHandler, []*capdag.Cap{capDef})
// Find matching capabilitiescaps, err:=matrix.FindCapSets(`cap:in="media:binary";extract;out=*`)
// Find the best match by specificityhost, cap, err:=matrix.FindBestCapSet(requestUrn)