diff --git a/docs/internal/runner.md b/docs/internal/runner.md index 0e12629..03ab213 100644 --- a/docs/internal/runner.md +++ b/docs/internal/runner.md @@ -43,9 +43,8 @@ hash. It retains its early request-ID check before direct-session normalization. Referenced message content and static template syntax were captured when the engine was built. -`InspectPrompt` selects captured metadata through an optional repository -capability, falling back to the full definition and existing hash resolution -for internal repositories without it. It returns owned metadata without +`InspectPrompt` selects captured metadata directly from the repository. It +returns owned metadata without rendering templates or touching profile, artifact, schema, renderer, validator, admission, or model collaborators. The root [`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 snapshot with the supplied caller variables and normalized direct-session bypass; it does not resolve target readiness or enter the preparation -pipeline. Missing snapshot capability is a prompt-load failure rather than a -source fallback. The root +pipeline. An unavailable captured snapshot is a prompt-load failure. The root [`Engine.InspectRequirements`](../../requirements.go) GoDoc owns the public operation's exact contract. diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index e2cd351..3921ba5 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -119,6 +119,11 @@ presence, prepared-payload freezing, session, and structured-dispatch assertions ## 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`, `internal/usecase/{runner,prompt_inspection,profile_inspection,requirements_inspection}.go`, `internal/configuration/prompts.go` and `targets.go`. diff --git a/internal/configuration/prompts.go b/internal/configuration/prompts.go index f5fe9dd..392b10d 100644 --- a/internal/configuration/prompts.go +++ b/internal/configuration/prompts.go @@ -329,12 +329,6 @@ func (state *loaded) GetPromptInspection(ctx context.Context, id string) (*domai 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. func (state *loaded) GetCompiledTemplates(id string) (prompt.CompiledTemplates, bool) { if state == nil { diff --git a/internal/profile/repository.go b/internal/profile/repository.go index 0d535a2..cfd6a59 100644 --- a/internal/profile/repository.go +++ b/internal/profile/repository.go @@ -13,4 +13,5 @@ var ErrProfileNotFound = errors.New("execution profile not found") // Repository selects execution profiles from a captured index. type Repository interface { GetProfile(ctx context.Context, id string) (*domain.ExecutionProfile, error) + GetProfileIdentity(ctx context.Context, id string) (string, error) } diff --git a/internal/promptdef/repository.go b/internal/promptdef/repository.go index 44d8a71..812d7a5 100644 --- a/internal/promptdef/repository.go +++ b/internal/promptdef/repository.go @@ -5,6 +5,7 @@ import ( "errors" "go.maximumdirect.net/promptkit/internal/domain" + "go.maximumdirect.net/promptkit/internal/prompt" ) // 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. 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) } diff --git a/internal/usecase/profile_inspection.go b/internal/usecase/profile_inspection.go index 1b1dee9..e9bddc3 100644 --- a/internal/usecase/profile_inspection.go +++ b/internal/usecase/profile_inspection.go @@ -15,10 +15,6 @@ type resolvedProfileSelection struct { profile *domain.ExecutionProfile } -type profileIdentityRepository interface { - GetProfileIdentity(context.Context, string) (string, error) -} - func (r *Runner) profileLookupID(profileID string) (string, error) { if strings.TrimSpace(profileID) == "" { 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 { return "", err } - if indexed, ok := r.profiles.(profileIdentityRepository); ok { - identity, err := indexed.GetProfileIdentity(ctx, lookupID) - if err != nil { - return "", profileLookupError(err) - } - return identity, nil - } - selection, err := r.resolveProfileSelection(ctx, lookupID) + identity, err := r.profiles.GetProfileIdentity(ctx, lookupID) if err != nil { - return "", err + return "", profileLookupError(err) } - return selection.id, nil + return identity, nil } func normalizeResolvedExecutionTarget(target domain.ExecutionTarget) (domain.ExecutionTarget, error) { diff --git a/internal/usecase/prompt_inspection.go b/internal/usecase/prompt_inspection.go index 47477ee..6019306 100644 --- a/internal/usecase/prompt_inspection.go +++ b/internal/usecase/prompt_inspection.go @@ -13,10 +13,6 @@ type resolvedPromptDefinition struct { hash string } -type promptInspectionRepository interface { - GetPromptInspection(context.Context, string) (*domain.PromptInspection, error) -} - func (r *Runner) resolvePromptDefinition(ctx context.Context, promptID string) (*resolvedPromptDefinition, error) { if strings.TrimSpace(promptID) == "" { 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) } - var definition *domain.PromptDefinition - 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) - } + definition, hash, err := r.promptDefs.GetPromptSnapshot(ctx, promptID) if err != nil { 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) } - 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 } @@ -58,29 +39,14 @@ func (r *Runner) resolvePromptInspection(ctx context.Context, promptID string) ( if r == nil || r.promptDefs == nil { return nil, fmt.Errorf("%w: prompt repository is not configured", ErrPromptLoad) } - if indexed, ok := r.promptDefs.(promptInspectionRepository); ok { - 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) + inspection, err := r.promptDefs.GetPromptInspection(ctx, promptID) if err != nil { - return nil, err + return nil, promptLookupError(err) } - definition := selection.definition - return &domain.PromptInspection{ - PromptID: definition.ID, - PromptHash: selection.hash, - DefaultProfileID: definition.DefaultProfile, - Inputs: append([]domain.PromptInput(nil), definition.Inputs...), - OutputContract: definition.Validation, - }, nil + if inspection == nil { + return nil, fmt.Errorf("%w: prompt repository returned nil inspection", ErrPromptLoad) + } + return inspection, nil } // InspectPrompt resolves one explicit prompt without execution work. diff --git a/internal/usecase/requirements_inspection.go b/internal/usecase/requirements_inspection.go index a33eee7..d9a8d0f 100644 --- a/internal/usecase/requirements_inspection.go +++ b/internal/usecase/requirements_inspection.go @@ -18,10 +18,6 @@ type RequirementInspectionRequest struct { SessionID string } -type requirementSnapshotRepository interface { - GetRequirementSnapshot(id string) (prompt.RequirementSnapshot, bool) -} - // InspectRequirements discovers prompt inputs and caller variables without // loading artifacts or performing execution preparation. func (r *Runner) InspectRequirements( @@ -61,11 +57,7 @@ func (r *Runner) InspectRequirements( return nil, &OperationError{Category: ErrPromptLoad, Cause: err} } - repository, ok := r.promptDefs.(requirementSnapshotRepository) - if !ok { - return nil, fmt.Errorf("%w: prompt repository does not provide captured requirement snapshots", ErrPromptLoad) - } - snapshot, ok := repository.GetRequirementSnapshot(selection.PromptID) + snapshot, ok := r.promptDefs.GetRequirementSnapshot(selection.PromptID) if !ok { return nil, fmt.Errorf("%w: captured requirement snapshot is unavailable", ErrPromptLoad) } diff --git a/internal/usecase/runner.go b/internal/usecase/runner.go index 487388a..7ba4438 100644 --- a/internal/usecase/runner.go +++ b/internal/usecase/runner.go @@ -707,7 +707,3 @@ func buildOutputArtifact(content string, format domain.OutputFormat) domain.Arti Hash: hex.EncodeToString(hash[:]), } } - -func hashPromptDefinition(def *domain.PromptDefinition) (string, error) { - return promptdef.HashDefinition(def) -}