feat(kit)!: a Kit profile names one Kit image, a workload or a published set
kitrun ran the first Kit of a profile's list as the container image, so every mixin's layers (its tools, skills and staged context) were dropped without a refusal. A profile's `kit` is now one digest-pinned reference: a workload Kit, or a published Kit set, which the Kit spec's frontend merges from a workload and its mixins into one image. archie composes no Kits itself, and a bare mixin is refused with a pointer to publishing a set. kit.Compose had no production caller left and is removed. BREAKING CHANGE: `[containers.profiles.X] kit` and the agent-profiles document's `kit` are a string, not a list. A stored list fails to decode and must be rewritten as the one workload or set reference. Part of archie-core-egkf.6.
This commit is contained in:
1 parent
e9e52c1f1f
commit
608403c1f9
11 files changed
+68
-85
No files matched your search
@@ -34,7 +34,7 @@ type containerRuntimePolicies struct {
|
||||
// agentProfile is one named execution environment as the document writes it.
|
||||
type agentProfile struct {
|
||||
Image string `json:"image,omitempty"`
|
||||
Kit []string `json:"kit,omitempty"`
|
||||
Kit string `json:"kit,omitempty"`
|
||||
Adapter string `json:"adapter,omitempty"`
|
||||
Tools []string `json:"tools,omitempty"`
|
||||
}
|
||||
|
||||
@@ -957,10 +957,11 @@ func (c ContainerConfig) ValidateCredentialBindings() error {
|
||||
type AgentProfile struct {
|
||||
// Image is the container image; empty means [containers].image.
|
||||
Image string `toml:"image" yaml:"image"`
|
||||
// Kit makes this a harness profile: the workload Kit, then its mixins,
|
||||
// each pinned by digest. The task container is the workload's image and
|
||||
// every agent stage runs on its CLI. Exclusive with Image.
|
||||
Kit []string `toml:"kit" yaml:"kit"`
|
||||
// Kit makes this a harness profile: one workload Kit or published Kit
|
||||
// set, pinned by digest. Mixins are composed by publishing a set, which
|
||||
// merges their layers into one image. The task container runs that
|
||||
// image and every agent stage runs on its CLI. Exclusive with Image.
|
||||
Kit string `toml:"kit" yaml:"kit"`
|
||||
// Adapter names the output adapter reading the Kit's CLI; empty runs it
|
||||
// with no capture tools and no usage.
|
||||
Adapter string `toml:"adapter" yaml:"adapter"`
|
||||
@@ -988,7 +989,7 @@ func (c ContainerConfig) Profile(name string) (AgentProfile, error) {
|
||||
}
|
||||
|
||||
// IsKit reports whether the profile runs a Kit harness.
|
||||
func (p AgentProfile) IsKit() bool { return len(p.Kit) > 0 }
|
||||
func (p AgentProfile) IsKit() bool { return p.Kit != "" }
|
||||
|
||||
// ValidateProfiles rejects a profile with an empty name, an empty tool
|
||||
// name, or a Kit that is not pinned by digest or also names an image.
|
||||
@@ -1012,10 +1013,8 @@ func ValidateAgentProfiles(profiles map[string]AgentProfile) error {
|
||||
case !p.IsKit() && p.Adapter != "":
|
||||
return fmt.Errorf("containers.profiles.%s: adapter needs a kit", name)
|
||||
}
|
||||
for _, ref := range p.Kit {
|
||||
if !strings.Contains(ref, "@sha256:") {
|
||||
return fmt.Errorf("containers.profiles.%s.kit: %q must be pinned by digest", name, ref)
|
||||
}
|
||||
if p.IsKit() && !strings.Contains(p.Kit, "@sha256:") {
|
||||
return fmt.Errorf("containers.profiles.%s.kit: %q must be pinned by digest", name, p.Kit)
|
||||
}
|
||||
for _, tool := range p.Tools {
|
||||
if strings.TrimSpace(tool) == "" {
|
||||
|
||||
@@ -43,16 +43,15 @@ func TestContainerProfileResolution(t *testing.T) {
|
||||
func TestKitProfiles(t *testing.T) {
|
||||
const pinned = "docker/claude-code-kit@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
||||
c := ContainerConfig{Image: "archie-agent:1", Profiles: map[string]AgentProfile{
|
||||
"claude": {Kit: []string{pinned}, Adapter: "claude-code"},
|
||||
"claude": {Kit: pinned, Adapter: "claude-code"},
|
||||
}}
|
||||
p, err := c.Profile("claude")
|
||||
if err != nil || p.Image != "" || !p.IsKit() {
|
||||
t.Fatalf("Profile() = %+v, %v; a Kit profile must not inherit the agent image", p, err)
|
||||
}
|
||||
for name, bad := range map[string]AgentProfile{
|
||||
"image and kit": {Image: "archie-agent:1", Kit: []string{pinned}},
|
||||
"unpinned kit": {Kit: []string{"docker/claude-code-kit:latest"}},
|
||||
"unpinned mixin": {Kit: []string{pinned, "me/setup:1"}},
|
||||
"image and kit": {Image: "archie-agent:1", Kit: pinned},
|
||||
"unpinned kit": {Kit: "docker/claude-code-kit:latest"},
|
||||
"adapter without a kit": {Adapter: "claude-code"},
|
||||
} {
|
||||
c := ContainerConfig{Profiles: map[string]AgentProfile{"p": bad}}
|
||||
|
||||
@@ -2364,9 +2364,9 @@ func TestPinTaskProfileRefusesCapturesTheHarnessCannotServe(t *testing.T) {
|
||||
d, s, _ := daemonWithNATS(t)
|
||||
cfg := d.Cfg.Get()
|
||||
cfg.Containers.Profiles = map[string]config.AgentProfile{
|
||||
"serves-captures": {Kit: []string{"kit@sha256:ab"}, Adapter: agentexec.AdapterClaudeCode},
|
||||
"no-captures": {Kit: []string{"kit@sha256:ab"}, Adapter: agentexec.AdapterCodex},
|
||||
"no-adapter": {Kit: []string{"kit@sha256:ab"}},
|
||||
"serves-captures": {Kit: "kit@sha256:ab", Adapter: agentexec.AdapterClaudeCode},
|
||||
"no-captures": {Kit: "kit@sha256:ab", Adapter: agentexec.AdapterCodex},
|
||||
"no-adapter": {Kit: "kit@sha256:ab"},
|
||||
}
|
||||
d.Cfg.Set(cfg)
|
||||
d.WorkflowDefinitions = &workflowDefinitionsStub{collection: workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{
|
||||
@@ -2427,7 +2427,7 @@ func TestWorkflowCallGivesACalleeItsOwnProfile(t *testing.T) {
|
||||
cfg := d.Cfg.Get()
|
||||
cfg.Containers.Profiles = map[string]config.AgentProfile{
|
||||
"net": {Image: "agent-net:1"},
|
||||
"contain": {Kit: []string{"contain-kit@sha256:ab"}, Adapter: agentexec.AdapterClaudeCode},
|
||||
"contain": {Kit: "contain-kit@sha256:ab", Adapter: agentexec.AdapterClaudeCode},
|
||||
}
|
||||
d.Cfg.Set(cfg)
|
||||
d.WorkflowDefinitions = &workflowDefinitionsStub{collection: workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{
|
||||
@@ -2607,7 +2607,7 @@ func TestKitProfileRunsTheTaskOnItsHarness(t *testing.T) {
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
|
||||
profile := config.AgentProfile{Kit: []string{"kit@sha256:ab"}, Adapter: agentexec.AdapterClaudeCode}
|
||||
profile := config.AgentProfile{Kit: "kit@sha256:ab", Adapter: agentexec.AdapterClaudeCode}
|
||||
d.runKitTask(ctx, task, config.Repo{Owner: "acme", Name: "widget", Base: "main"}, t.TempDir(), profile)
|
||||
|
||||
select {
|
||||
@@ -2618,8 +2618,8 @@ func TestKitProfileRunsTheTaskOnItsHarness(t *testing.T) {
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("archied did not publish a taskrun request")
|
||||
}
|
||||
if !slices.Equal(launcher.got.Kit, profile.Kit) || launcher.got.Adapter != profile.Adapter {
|
||||
t.Fatalf("launch request %+v, want the profile's kits and adapter", launcher.got)
|
||||
if launcher.got.Kit != profile.Kit || launcher.got.Adapter != profile.Adapter {
|
||||
t.Fatalf("launch request %+v, want the profile's kit and adapter", launcher.got)
|
||||
}
|
||||
for _, e := range launcher.got.WorkerEnv {
|
||||
if strings.Contains(e, "sk-real") {
|
||||
@@ -2666,7 +2666,7 @@ func TestRunKitTaskThreadsGateRetriesToTheLauncher(t *testing.T) {
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
|
||||
d.runKitTask(ctx, task, config.Repo{Owner: "acme", Name: "widget", Base: "main"}, t.TempDir(),
|
||||
config.AgentProfile{Kit: []string{"kit@sha256:ab"}, Adapter: agentexec.AdapterClaudeCode})
|
||||
config.AgentProfile{Kit: "kit@sha256:ab", Adapter: agentexec.AdapterClaudeCode})
|
||||
|
||||
if launcher.got.GateRetries != 4 {
|
||||
t.Fatalf("launch request GateRetries = %d, want the workflow's declared 4", launcher.got.GateRetries)
|
||||
|
||||
@@ -125,25 +125,15 @@ func Admit(d *spec.Descriptor) (*Plan, error) {
|
||||
return plan, nil
|
||||
}
|
||||
|
||||
// Compose merges one workload Kit and its mixins, in the order given, and
|
||||
// admits the result. archie drives a harness headlessly, so the composition
|
||||
// must carry an agent-sessions prompt verb.
|
||||
func Compose(contributions []spec.Contribution) (*Plan, error) {
|
||||
merged, err := spec.Merge(contributions, MergeOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return FromMerge(merged)
|
||||
}
|
||||
|
||||
// MergeOptions are the options every composition archie runs is merged with.
|
||||
var MergeOptions = spec.MergeOptions{ContextPath: contextPath}
|
||||
|
||||
// FromMerge admits an already-merged composition, such as one the Kit spec's
|
||||
// fetch package assembled from a registry.
|
||||
// FromMerge admits the profile's Kit as the Kit spec's fetch package read it:
|
||||
// a workload Kit or a published Kit set, never a bare mixin. archie drives a
|
||||
// harness headlessly, so it must carry an agent-sessions prompt verb.
|
||||
func FromMerge(merged *spec.MergeResult) (*Plan, error) {
|
||||
if merged.Descriptor.Kind != spec.KindWorkload {
|
||||
return nil, errors.New("kit composition has no workload: a harness needs exactly one base kit")
|
||||
return nil, errors.New("kit is a mixin: publish a Kit set composing it with a workload Kit, and name the set")
|
||||
}
|
||||
plan, err := Admit(merged.Descriptor)
|
||||
if err != nil {
|
||||
|
||||
@@ -162,45 +162,41 @@ func TestRefusalNamesTheCapability(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompose(t *testing.T) {
|
||||
// admit reads one Kit the way the launcher does: merged alone, then admitted.
|
||||
func admit(t *testing.T, c spec.Contribution) (*Plan, error) {
|
||||
t.Helper()
|
||||
merged, err := spec.Merge([]spec.Contribution{c}, MergeOptions)
|
||||
if err != nil {
|
||||
t.Fatalf("Merge: %v", err)
|
||||
}
|
||||
return FromMerge(merged)
|
||||
}
|
||||
|
||||
func TestFromMerge(t *testing.T) {
|
||||
workload := spec.Contribution{Reference: "workload", Descriptor: descriptor(t, spec.KindWorkload, sessions)}
|
||||
mixin := spec.Contribution{Reference: "mixin", Descriptor: descriptor(t, spec.KindMixin, `
|
||||
- type: com.docker.sandbox/network-policy@1
|
||||
config: {runtime: {allow: [api.example.com]}}
|
||||
- type: com.docker.sandbox/credential@1
|
||||
config:
|
||||
service: example
|
||||
phase: runtime
|
||||
apiKey: {name: EXAMPLE_KEY, proxyManaged: true, inject: [{domain: api.example.com, header: x-api-key, format: "%s"}]}`)}
|
||||
config: {runtime: {allow: [api.example.com]}}`)}
|
||||
bareWorkload := spec.Contribution{Reference: "bare", Descriptor: descriptor(t, spec.KindWorkload, `
|
||||
- type: com.docker.sandbox/resources@1
|
||||
config: {memory: 1g}`)}
|
||||
|
||||
t.Run("a workload and its mixins compose into one plan", func(t *testing.T) {
|
||||
plan, err := Compose([]spec.Contribution{workload, mixin})
|
||||
if err != nil {
|
||||
t.Fatalf("Compose: %v", err)
|
||||
}
|
||||
if !spec.HasCapability(plan.Capabilities, typeCredential) {
|
||||
t.Fatal("the mixin's credential did not reach the plan")
|
||||
}
|
||||
if plan.Sessions == nil || len(plan.Sessions.Prompt) == 0 {
|
||||
t.Fatal("the plan carries no headless prompt verb")
|
||||
}
|
||||
})
|
||||
plan, err := admit(t, workload)
|
||||
if err != nil || plan.Sessions == nil || len(plan.Sessions.Prompt) == 0 {
|
||||
t.Fatalf("admit(workload) = %+v, %v; want a plan with a headless prompt verb", plan, err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
contributions []spec.Contribution
|
||||
want string
|
||||
name string
|
||||
kit spec.Contribution
|
||||
want string
|
||||
}{
|
||||
{"no workload", []spec.Contribution{mixin}, "no workload"},
|
||||
{"no headless prompt verb", []spec.Contribution{bareWorkload}, "agent-sessions"},
|
||||
{"two workloads", []spec.Contribution{workload, bareWorkload}, "workload"},
|
||||
{"a bare mixin", mixin, "publish a Kit set"},
|
||||
{"no headless prompt verb", bareWorkload, "agent-sessions"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name+" is refused", func(t *testing.T) {
|
||||
_, err := Compose(tt.contributions)
|
||||
_, err := admit(t, tt.kit)
|
||||
if err == nil || !strings.Contains(err.Error(), tt.want) {
|
||||
t.Fatalf("error %v, want one mentioning %q", err, tt.want)
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ const launchKit = `
|
||||
|
||||
func plan(t *testing.T) *Plan {
|
||||
t.Helper()
|
||||
p, err := Compose([]spec.Contribution{{Reference: "kit", Descriptor: descriptor(t, spec.KindWorkload, launchKit)}})
|
||||
p, err := admit(t, spec.Contribution{Reference: "kit", Descriptor: descriptor(t, spec.KindWorkload, launchKit)})
|
||||
if err != nil {
|
||||
t.Fatalf("Compose: %v", err)
|
||||
t.Fatalf("admit: %v", err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -73,7 +73,8 @@ type Request struct {
|
||||
// Execution keys the task's Kit volumes and names its container and
|
||||
// network.
|
||||
Execution string
|
||||
Kit []string
|
||||
// Kit is the digest-pinned workload Kit or published Kit set.
|
||||
Kit string
|
||||
Adapter string
|
||||
WorkDir string
|
||||
WorkerEnv []string
|
||||
@@ -106,9 +107,9 @@ type Run struct {
|
||||
execution string
|
||||
}
|
||||
|
||||
// Launch composes the request's Kits and starts its container.
|
||||
// Launch reads the request's Kit and starts its container.
|
||||
func (l *Launcher) Launch(ctx context.Context, req Request) (*Run, error) {
|
||||
if len(req.Kit) == 0 {
|
||||
if req.Kit == "" {
|
||||
return nil, errors.New("kit profile names no kit")
|
||||
}
|
||||
adapter, ok := agentexec.LookupHarnessAdapter(req.Adapter)
|
||||
@@ -158,7 +159,7 @@ func (l *Launcher) Launch(ctx context.Context, req Request) (*Run, error) {
|
||||
}
|
||||
run.Container, err = l.Pool.AcquireKit(ctx, container.KitSpec{
|
||||
Name: "archie-kit-" + req.Execution,
|
||||
Image: req.Kit[0],
|
||||
Image: req.Kit,
|
||||
Network: run.network,
|
||||
Worker: []string{agentPath},
|
||||
WorkerEnv: req.WorkerEnv,
|
||||
@@ -234,22 +235,18 @@ func (l *Launcher) release(run *Run) {
|
||||
l.Proxy.Revoke(run.token)
|
||||
}
|
||||
|
||||
// compose assembles the profile's Kits and reads the workload image's
|
||||
// config, the first Kit being the workload.
|
||||
func (l *Launcher) compose(ctx context.Context, refs []string) (*kit.Plan, kit.ImageConfig, error) {
|
||||
reqs := make([]fetch.Request, len(refs))
|
||||
for i, ref := range refs {
|
||||
reqs[i] = fetch.Request{Reference: ref}
|
||||
}
|
||||
// compose reads the profile's Kit and the config of the image it runs.
|
||||
func (l *Launcher) compose(ctx context.Context, ref string) (*kit.Plan, kit.ImageConfig, error) {
|
||||
reqs := []fetch.Request{{Reference: ref}}
|
||||
merged, err := l.Fetch.Assemble(ctx, reqs, kit.MergeOptions)
|
||||
if err != nil {
|
||||
return nil, kit.ImageConfig{}, fmt.Errorf("assemble kits: %w", err)
|
||||
return nil, kit.ImageConfig{}, fmt.Errorf("read kit: %w", err)
|
||||
}
|
||||
plan, err := kit.FromMerge(merged.MergeResult)
|
||||
if err != nil {
|
||||
return nil, kit.ImageConfig{}, err
|
||||
}
|
||||
img, err := l.imageConfig(ctx, refs[0])
|
||||
img, err := l.imageConfig(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, kit.ImageConfig{}, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user