Skip to content

Commit e5cc3a0

Browse files
frristclaude
andauthored
refactor(capabilities): inline datamodel structs into parent packages (#21)
Each capability exposed its wire structs through a parent-package alias to a `<cap>/datamodel/` subpackage: // capabilities/blob/add.go type AddArguments = bdm.AddArgumentsModel The split solved a real problem: `bindcap.Arguments` requires CBOR codec methods, those methods are what `cbor-gen` produces, and the parent package couldn't compile against itself before codegen ran. Putting the wire structs in a separate package broke that bootstrap cleanly. The indirection has accumulated costs worth addressing now: - The aliases are pure renames (Foo = otherpkg.FooModel), which we've been trying to avoid elsewhere in the codebase. - The `Model` suffix leaks back through struct field declarations. `args.Metadata` reads as `Metadata` at the call site, but hover-types and error messages still surface `MetadataModel` because the field is declared with the suffixed name. A recent piri refactor surfaced a confusing type mismatch where the alias chain took a while to untangle. - Each capability duplicates the same `datamodel/` boilerplate (a `gen/` subfolder, generator entry point, generated codecs). This change inlines each `<cap>/datamodel/` into its parent and drops the rename aliases. The codegen bootstrap is preserved with a build tag: binding files carry `//go:build !codegen` and the generator runs with `-tags codegen`, so during codegen only the wire types compile (no bindcap dependency). The generator post-processes its output to re-inject the tag, keeping subsequent runs stale-safe. The top-level `capabilities/datamodel.UnitModel` becomes `capabilities.Unit`. Per-op `OK` aliases that resolved to `UnitModel` are kept as within-package aliases (e.g. `type AddOK = capabilities.Unit`) to preserve operation-named labels at type-parameter call sites like `bindexec.Response[*blob.AddOK]`. Additionally, `capabilities.MustNew` wraps `bindcap.New` and panics on construction error. The previous `var Foo, _ = bindcap.New(...)` pattern silently dropped errors that, for hardcoded commands and options, can only ever be programmer bugs — failing at package init is strictly safer than discovering it later via nil dereference. External impact: only the sprue repo imports an inner datamodel package directly (two test files using `access/datamodel.CapabilityRequestModel`). Those need to update alongside the libforge bump — change the import path and drop the `Model` suffix. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 935195a commit e5cc3a0

136 files changed

Lines changed: 3074 additions & 1798 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 33 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

capabilities/access/claim.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
package access
1+
//go:build !codegen
22

3-
import (
4-
adm "github.com/fil-forge/libforge/capabilities/access/datamodel"
5-
cdm "github.com/fil-forge/libforge/capabilities/datamodel"
6-
"github.com/fil-forge/ucantone/validator/bindcap"
7-
)
3+
package access
84

9-
type (
10-
ClaimArguments = cdm.UnitModel
11-
ClaimOK = adm.ClaimOKModel
12-
)
5+
import "github.com/fil-forge/libforge/capabilities"
136

147
const ClaimCommand = "/access/claim"
158

9+
type ClaimArguments = capabilities.Unit
10+
1611
// Claim can be invoked by an agent to claim a set of delegations from the
1712
// account.
18-
var Claim, _ = bindcap.New[*ClaimArguments](ClaimCommand)
13+
var Claim = capabilities.MustNew[*ClaimArguments](ClaimCommand)

capabilities/access/confirm.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
//go:build !codegen
2+
13
package access
24

35
import (
4-
adm "github.com/fil-forge/libforge/capabilities/access/datamodel"
6+
"github.com/fil-forge/libforge/capabilities"
57
"github.com/fil-forge/ucantone/errors"
6-
"github.com/fil-forge/ucantone/validator/bindcap"
78
)
89

9-
type (
10-
ConfirmArguments = adm.ConfirmArgumentsModel
11-
ConfirmOK = adm.ConfirmOKModel
12-
)
10+
// ConfirmOK mirrors ClaimOK — confirming an access request grants the same
11+
// shape of delegations bundle as claiming them.
12+
type ConfirmOK = ClaimOK
1313

1414
// ConfirmMetaKey is the key in metadata in any delegation created by a
1515
// successful access request. The value is a link back to the `/access/confirm`
@@ -19,7 +19,7 @@ const ConfirmMetaKey = "accessConfirm"
1919
const ConfirmCommand = "/access/confirm"
2020

2121
// Confirm can be invoked by an agent to confirm an access request.
22-
var Confirm, _ = bindcap.New[*ConfirmArguments](ConfirmCommand)
22+
var Confirm = capabilities.MustNew[*ConfirmArguments](ConfirmCommand)
2323

2424
const (
2525
InvalidAccessConfirmSubjectErrorName = "InvalidAccessConfirmSubject"

capabilities/access/datamodel/claim.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

capabilities/access/datamodel/confirm.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

capabilities/access/datamodel/delegate.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

capabilities/access/datamodel/gen/main.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

capabilities/access/datamodel/request.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)