Require captured repository lookups

This commit is contained in:
2026-11-05 19:55:10 +00:00
parent 0dec3dcec0
commit 90f796aef7
9 changed files with 24 additions and 80 deletions

View File

@@ -43,9 +43,8 @@ hash. It retains its early request-ID check before direct-session
normalization. Referenced message content and static template syntax were normalization. Referenced message content and static template syntax were
captured when the engine was built. captured when the engine was built.
`InspectPrompt` selects captured metadata through an optional repository `InspectPrompt` selects captured metadata directly from the repository. It
capability, falling back to the full definition and existing hash resolution returns owned metadata without
for internal repositories without it. It returns owned metadata without
rendering templates or touching profile, artifact, schema, renderer, validator, rendering templates or touching profile, artifact, schema, renderer, validator,
admission, or model collaborators. The root admission, or model collaborators. The root
[`Engine.InspectPrompt`](../../engine.go) GoDoc owns the public operation's [`Engine.InspectPrompt`](../../engine.go) GoDoc owns the public operation's
@@ -57,8 +56,7 @@ snapshot by the selected prompt ID. The analyzer receives only
those identity fields rather than an execution definition. It analyzes the those identity fields rather than an execution definition. It analyzes the
snapshot with the supplied caller variables and normalized direct-session snapshot with the supplied caller variables and normalized direct-session
bypass; it does not resolve target readiness or enter the preparation bypass; it does not resolve target readiness or enter the preparation
pipeline. Missing snapshot capability is a prompt-load failure rather than a pipeline. An unavailable captured snapshot is a prompt-load failure. The root
source fallback. The root
[`Engine.InspectRequirements`](../../requirements.go) GoDoc owns the public [`Engine.InspectRequirements`](../../requirements.go) GoDoc owns the public
operation's exact contract. operation's exact contract.

View File

@@ -119,6 +119,11 @@ presence, prepared-payload freezing, session, and structured-dispatch assertions
## Stage 3: Require Captured Repository Operations ## Stage 3: Require Captured Repository Operations
**Completed:** Repository interfaces require captured definitions, metadata,
requirements, and profile identity; the alternate lookups and hash wrapper
were removed. Go 1.27.3 `go build ./...` passed with the real configuration
snapshot. Use-case test fixture compilation is deferred to the next stage.
**Finding:** 3. **Files:** `internal/promptdef/repository.go`, `internal/profile/repository.go`, **Finding:** 3. **Files:** `internal/promptdef/repository.go`, `internal/profile/repository.go`,
`internal/usecase/{runner,prompt_inspection,profile_inspection,requirements_inspection}.go`, `internal/usecase/{runner,prompt_inspection,profile_inspection,requirements_inspection}.go`,
`internal/configuration/prompts.go` and `targets.go`. `internal/configuration/prompts.go` and `targets.go`.

View File

@@ -329,12 +329,6 @@ func (state *loaded) GetPromptInspection(ctx context.Context, id string) (*domai
return ownPromptInspection(entry.inspection), nil return ownPromptInspection(entry.inspection), nil
} }
// GetPromptDefinition implements the runner's prompt lookup boundary.
func (state *loaded) GetPromptDefinition(ctx context.Context, id string) (*domain.PromptDefinition, error) {
definition, _, err := state.GetPromptSnapshot(ctx, id)
return definition, err
}
// GetCompiledTemplates returns construction-time parses for one prompt ID. // GetCompiledTemplates returns construction-time parses for one prompt ID.
func (state *loaded) GetCompiledTemplates(id string) (prompt.CompiledTemplates, bool) { func (state *loaded) GetCompiledTemplates(id string) (prompt.CompiledTemplates, bool) {
if state == nil { if state == nil {

View File

@@ -13,4 +13,5 @@ var ErrProfileNotFound = errors.New("execution profile not found")
// Repository selects execution profiles from a captured index. // Repository selects execution profiles from a captured index.
type Repository interface { type Repository interface {
GetProfile(ctx context.Context, id string) (*domain.ExecutionProfile, error) GetProfile(ctx context.Context, id string) (*domain.ExecutionProfile, error)
GetProfileIdentity(ctx context.Context, id string) (string, error)
} }

View File

@@ -5,6 +5,7 @@ import (
"errors" "errors"
"go.maximumdirect.net/promptkit/internal/domain" "go.maximumdirect.net/promptkit/internal/domain"
"go.maximumdirect.net/promptkit/internal/prompt"
) )
// ErrPromptDefinitionNotFound identifies an absent captured prompt definition. // ErrPromptDefinitionNotFound identifies an absent captured prompt definition.
@@ -12,5 +13,7 @@ var ErrPromptDefinitionNotFound = errors.New("prompt definition not found")
// Repository selects prompt definitions from a captured index. // Repository selects prompt definitions from a captured index.
type Repository interface { type Repository interface {
GetPromptDefinition(ctx context.Context, id string) (*domain.PromptDefinition, error) GetPromptSnapshot(ctx context.Context, id string) (*domain.PromptDefinition, string, error)
GetPromptInspection(ctx context.Context, id string) (*domain.PromptInspection, error)
GetRequirementSnapshot(id string) (prompt.RequirementSnapshot, bool)
} }

View File

@@ -15,10 +15,6 @@ type resolvedProfileSelection struct {
profile *domain.ExecutionProfile profile *domain.ExecutionProfile
} }
type profileIdentityRepository interface {
GetProfileIdentity(context.Context, string) (string, error)
}
func (r *Runner) profileLookupID(profileID string) (string, error) { func (r *Runner) profileLookupID(profileID string) (string, error) {
if strings.TrimSpace(profileID) == "" { if strings.TrimSpace(profileID) == "" {
return "", fmt.Errorf("%w: profile id is required", ErrInvalidRequest) return "", fmt.Errorf("%w: profile id is required", ErrInvalidRequest)
@@ -61,18 +57,11 @@ func (r *Runner) resolveProfileIdentity(ctx context.Context, profileID string) (
if err != nil { if err != nil {
return "", err return "", err
} }
if indexed, ok := r.profiles.(profileIdentityRepository); ok { identity, err := r.profiles.GetProfileIdentity(ctx, lookupID)
identity, err := indexed.GetProfileIdentity(ctx, lookupID)
if err != nil {
return "", profileLookupError(err)
}
return identity, nil
}
selection, err := r.resolveProfileSelection(ctx, lookupID)
if err != nil { if err != nil {
return "", err return "", profileLookupError(err)
} }
return selection.id, nil return identity, nil
} }
func normalizeResolvedExecutionTarget(target domain.ExecutionTarget) (domain.ExecutionTarget, error) { func normalizeResolvedExecutionTarget(target domain.ExecutionTarget) (domain.ExecutionTarget, error) {

View File

@@ -13,10 +13,6 @@ type resolvedPromptDefinition struct {
hash string hash string
} }
type promptInspectionRepository interface {
GetPromptInspection(context.Context, string) (*domain.PromptInspection, error)
}
func (r *Runner) resolvePromptDefinition(ctx context.Context, promptID string) (*resolvedPromptDefinition, error) { func (r *Runner) resolvePromptDefinition(ctx context.Context, promptID string) (*resolvedPromptDefinition, error) {
if strings.TrimSpace(promptID) == "" { if strings.TrimSpace(promptID) == "" {
return nil, fmt.Errorf("%w: prompt id is required", ErrInvalidRequest) return nil, fmt.Errorf("%w: prompt id is required", ErrInvalidRequest)
@@ -25,16 +21,7 @@ func (r *Runner) resolvePromptDefinition(ctx context.Context, promptID string) (
return nil, fmt.Errorf("%w: prompt repository is not configured", ErrPromptLoad) return nil, fmt.Errorf("%w: prompt repository is not configured", ErrPromptLoad)
} }
var definition *domain.PromptDefinition definition, hash, err := r.promptDefs.GetPromptSnapshot(ctx, promptID)
var hash string
var err error
if indexed, ok := r.promptDefs.(interface {
GetPromptSnapshot(context.Context, string) (*domain.PromptDefinition, string, error)
}); ok {
definition, hash, err = indexed.GetPromptSnapshot(ctx, promptID)
} else {
definition, err = r.promptDefs.GetPromptDefinition(ctx, promptID)
}
if err != nil { if err != nil {
return nil, promptLookupError(err) return nil, promptLookupError(err)
} }
@@ -42,12 +29,6 @@ func (r *Runner) resolvePromptDefinition(ctx context.Context, promptID string) (
return nil, fmt.Errorf("%w: prompt repository returned nil definition", ErrPromptLoad) return nil, fmt.Errorf("%w: prompt repository returned nil definition", ErrPromptLoad)
} }
if hash == "" {
hash, err = hashPromptDefinition(definition)
if err != nil {
return nil, fmt.Errorf("%w: failed to hash prompt definition: %v", ErrPromptLoad, err)
}
}
return &resolvedPromptDefinition{definition: definition, hash: hash}, nil return &resolvedPromptDefinition{definition: definition, hash: hash}, nil
} }
@@ -58,29 +39,14 @@ func (r *Runner) resolvePromptInspection(ctx context.Context, promptID string) (
if r == nil || r.promptDefs == nil { if r == nil || r.promptDefs == nil {
return nil, fmt.Errorf("%w: prompt repository is not configured", ErrPromptLoad) return nil, fmt.Errorf("%w: prompt repository is not configured", ErrPromptLoad)
} }
if indexed, ok := r.promptDefs.(promptInspectionRepository); ok { inspection, err := r.promptDefs.GetPromptInspection(ctx, promptID)
inspection, err := indexed.GetPromptInspection(ctx, promptID)
if err != nil {
return nil, promptLookupError(err)
}
if inspection == nil {
return nil, fmt.Errorf("%w: prompt repository returned nil inspection", ErrPromptLoad)
}
return inspection, nil
}
selection, err := r.resolvePromptDefinition(ctx, promptID)
if err != nil { if err != nil {
return nil, err return nil, promptLookupError(err)
} }
definition := selection.definition if inspection == nil {
return &domain.PromptInspection{ return nil, fmt.Errorf("%w: prompt repository returned nil inspection", ErrPromptLoad)
PromptID: definition.ID, }
PromptHash: selection.hash, return inspection, nil
DefaultProfileID: definition.DefaultProfile,
Inputs: append([]domain.PromptInput(nil), definition.Inputs...),
OutputContract: definition.Validation,
}, nil
} }
// InspectPrompt resolves one explicit prompt without execution work. // InspectPrompt resolves one explicit prompt without execution work.

View File

@@ -18,10 +18,6 @@ type RequirementInspectionRequest struct {
SessionID string SessionID string
} }
type requirementSnapshotRepository interface {
GetRequirementSnapshot(id string) (prompt.RequirementSnapshot, bool)
}
// InspectRequirements discovers prompt inputs and caller variables without // InspectRequirements discovers prompt inputs and caller variables without
// loading artifacts or performing execution preparation. // loading artifacts or performing execution preparation.
func (r *Runner) InspectRequirements( func (r *Runner) InspectRequirements(
@@ -61,11 +57,7 @@ func (r *Runner) InspectRequirements(
return nil, &OperationError{Category: ErrPromptLoad, Cause: err} return nil, &OperationError{Category: ErrPromptLoad, Cause: err}
} }
repository, ok := r.promptDefs.(requirementSnapshotRepository) snapshot, ok := r.promptDefs.GetRequirementSnapshot(selection.PromptID)
if !ok {
return nil, fmt.Errorf("%w: prompt repository does not provide captured requirement snapshots", ErrPromptLoad)
}
snapshot, ok := repository.GetRequirementSnapshot(selection.PromptID)
if !ok { if !ok {
return nil, fmt.Errorf("%w: captured requirement snapshot is unavailable", ErrPromptLoad) return nil, fmt.Errorf("%w: captured requirement snapshot is unavailable", ErrPromptLoad)
} }

View File

@@ -707,7 +707,3 @@ func buildOutputArtifact(content string, format domain.OutputFormat) domain.Arti
Hash: hex.EncodeToString(hash[:]), Hash: hex.EncodeToString(hash[:]),
} }
} }
func hashPromptDefinition(def *domain.PromptDefinition) (string, error) {
return promptdef.HashDefinition(def)
}