Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
when it exposes `Exists` and `ReadFile` accessors. Docker and OpenSandbox
cases now grade the actual sandbox workspace instead of host paths, while
path confinement prevents these checks from escaping the workspace.
- Exclude the framework's prompt file from workspace diffs when an engine
receives its prompt through a file. Other files in the same directory
remain visible to the judge.
- Match environment variable names case-insensitively in the `none` runtime on
native Windows. A host `Path` and a configured or probed `PATH` were both
passed to the child, and which one it kept followed map order. Per-call
Expand Down
4 changes: 2 additions & 2 deletions internal/agent/claude_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (a *ClaudeCodeAgent) Run(ctx context.Context, rt Runtime, opts ExecOptions,
result, err := rt.Exec(ctx, cmd, opts)
sessionResult := a.buildSessionResult(ctx, rt, opts, instruction, start, result)
if sessionResult != nil {
sessionResult.PromptDelivery = promptDelivery
sessionResult.recordPromptDelivery(promptDelivery)
sessionResult.SessionID = sessionID
}
if providerErr := claudeProviderRunError(result, sessionResult); providerErr != nil {
Expand Down Expand Up @@ -588,7 +588,7 @@ func (a *ClaudeCodeAgent) RunTurn(ctx context.Context, rt Runtime, opts ExecOpti
result, err := rt.Exec(ctx, cmd, opts)
sessionResult := a.buildSessionResult(ctx, rt, opts, instruction, start, result)
if sessionResult != nil {
sessionResult.PromptDelivery = promptDelivery
sessionResult.recordPromptDelivery(promptDelivery)
sessionResult.SessionID = sessionID
}
return a.handleClaudeRunResult(sessionResult, result, err, sessionID, start)
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/codex.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ func (a *CodexAgent) Run(ctx context.Context, rt Runtime, opts ExecOptions, mess
result, err := rt.Exec(ctx, cmd, opts)
sessionResult, parseErr := a.buildSessionResult(ctx, rt, opts, instruction, start, result, runArtifactDir, lastMessagePath, stdoutPath)
if sessionResult != nil {
sessionResult.PromptDelivery = promptDelivery
sessionResult.recordPromptDelivery(promptDelivery)
}
if err != nil {
if sessionResult == nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/opencode.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ func (a *OpenCodeAgent) execute(ctx context.Context, rt Runtime, opts ExecOption
parsed.ExitCode = result.ExitCode
parsed.DurationMs = time.Since(start).Milliseconds()
parsed.Stderr = result.Stderr
parsed.PromptDelivery = delivery
parsed.Artifacts = &SessionArtifacts{}
parsed.recordPromptDelivery(delivery)
cleanupCtx, cleanupCancel := sessionCleanupContext(ctx)
defer cleanupCancel()
if artifact, err := persistSessionArtifact(cleanupCtx, rt, opts.ArtifactDir, "stdout.jsonl", result.Stdout); err == nil {
Expand Down
11 changes: 11 additions & 0 deletions internal/agent/prompt_delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ type promptCommandBuilder struct {
StdinFile func(string) string
}

func (r *SessionResult) recordPromptDelivery(delivery *PromptDeliveryMetadata) {
r.PromptDelivery = delivery
if delivery == nil || delivery.RuntimePath == "" {
return
}
if r.Artifacts == nil {
r.Artifacts = &SessionArtifacts{}
}
r.Artifacts.GeneratedFileSources = append(r.Artifacts.GeneratedFileSources, delivery.RuntimePath)
}

func deliverPrompt(ctx context.Context, rt Runtime, opts ExecOptions, instruction string, builder promptCommandBuilder) (string, *PromptDeliveryMetadata, error) {
threshold := promptInlineMaxBytes()
// MSYS2 bash can truncate quoted argv near 8 KiB when launched by a
Expand Down
7 changes: 7 additions & 0 deletions internal/agent/prompt_delivery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"path/filepath"
"slices"
"strings"
"testing"

Expand Down Expand Up @@ -246,11 +247,17 @@ func assertResumedPromptDelivery(t *testing.T, rt *resumedPromptRuntime, result
t.Fatalf("resume identity lost: %s", rt.command)
}
if mode == "inline" {
if result.Artifacts != nil && slices.Contains(result.Artifacts.GeneratedFileSources, filepath.Join(rt.Workspace(), ".skill-up", "prompts", "prompt.txt")) {
t.Fatal("inline delivery excluded a file it did not write")
}
if !strings.Contains(rt.command, shellQuote(prompt)) || rt.uploadedTarget != "" {
t.Fatalf("incorrect inline delivery: %s", rt.command)
}
return
}
if result.Artifacts == nil || !slices.Contains(result.Artifacts.GeneratedFileSources, rt.uploadedTarget) {
t.Fatalf("workspace diff exclusions omit the delivered prompt %q", rt.uploadedTarget)
}
assertResumedPromptFile(t, rt, engine, prompt, artifactDir)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/agent/qodercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (a *QoderCLIAgent) Run(ctx context.Context, rt Runtime, opts ExecOptions, m
sessionResult := a.buildSessionResult(ctx, rt, opts, instruction, start, result)
resultErr := qoderResultError(result.Stdout, result.Stderr, a.appliedModelName(ctx))
if sessionResult != nil {
sessionResult.PromptDelivery = promptDelivery
sessionResult.recordPromptDelivery(promptDelivery)
}
if err != nil {
if sessionResult == nil {
Expand Down Expand Up @@ -415,7 +415,7 @@ func (a *QoderCLIAgent) RunTurn(ctx context.Context, rt Runtime, opts ExecOption
resultErr := qoderResultError(result.Stdout, result.Stderr, a.appliedModelName(ctx))
if sessionResult != nil {
sessionResult.SessionID = sessionID
sessionResult.PromptDelivery = promptDelivery
sessionResult.recordPromptDelivery(promptDelivery)
}
if err != nil {
if sessionResult == nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/qwen_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (a *QwenCodeAgent) Run(ctx context.Context, rt Runtime, opts ExecOptions, m
result, err := rt.Exec(ctx, cmd, opts)
sessionResult := a.buildSessionResult(ctx, rt, opts, instruction, start, result)
if sessionResult != nil {
sessionResult.PromptDelivery = promptDelivery
sessionResult.recordPromptDelivery(promptDelivery)
}
if err != nil {
return sessionResult, fmt.Errorf("qwen_code run failed: %w", err)
Expand Down
74 changes: 74 additions & 0 deletions internal/evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,80 @@ func TestExecuteCase_AgentJudgeReceivesTranscriptAndWorkspaceDiff(t *testing.T)
}
}

func TestPrepareWorkspaceArtifacts_HidesOnlyDeliveredPromptFile(t *testing.T) {
for _, tc := range []struct {
name, threshold, mode string
wantPromptInDiff bool
}{
{name: "file delivery hides only the prompt", threshold: "0", mode: "file"},
{name: "inline delivery keeps the same path", threshold: "1048576", mode: "inline", wantPromptInDiff: true},
} {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("SKILL_UP_PROMPT_INLINE_MAX_BYTES", tc.threshold)
base := newApplyDiffRuntime(t)
if tc.mode == "inline" && base.Shell().GOOS == platform.GOOSWindows {
t.Skip("Windows always delivers prompts through a file")
}
diff, delivery := runQoderWithPromptDirWrites(t, base)
if delivery == nil || delivery.Mode != tc.mode {
t.Fatalf("prompt delivery = %+v, want mode %q", delivery, tc.mode)
}
if _, err := os.Stat(filepath.Join(base.Workspace(), ".skill-up", "prompts", "prompt.txt")); err != nil {
t.Fatalf("prompt path must exist in the workspace: %v", err)
}
if !strings.Contains(diff, "b/.skill-up/prompts/notes.txt") {
t.Fatalf("sibling of the prompt file missing from workspace diff:\n%s", diff)
}
if got := strings.Contains(diff, "b/.skill-up/prompts/prompt.txt"); got != tc.wantPromptInDiff {
t.Fatalf("prompt path in workspace diff = %t, want %t:\n%s", got, tc.wantPromptInDiff, diff)
}
})
}
}

// runQoderWithPromptDirWrites runs the real Qoder adapter between the
// evaluator's workspace snapshot and diff. The fake CLI writes a sibling of the
// prompt file and, when the prompt was not delivered there, the prompt path too.
func runQoderWithPromptDirWrites(t *testing.T, base runtime.Runtime) (string, *agent.PromptDeliveryMetadata) {
t.Helper()
promptDir := filepath.Join(base.Workspace(), ".skill-up", "prompts")
rt := &applyDiffTestRuntime{Runtime: base, upload: base.UploadFile}
rt.exec = func(ctx context.Context, command string, opts runtime.ExecOptions) (runtime.ExecResult, error) {
switch {
case strings.Contains(command, "qodercli --permission-mode="):
if err := os.MkdirAll(promptDir, 0o755); err != nil {
return runtime.ExecResult{}, err
}
if err := os.WriteFile(filepath.Join(promptDir, "notes.txt"), []byte("agent notes\n"), 0o600); err != nil {
return runtime.ExecResult{}, err
}
if _, err := os.Stat(filepath.Join(promptDir, "prompt.txt")); errors.Is(err, os.ErrNotExist) {
if err := os.WriteFile(filepath.Join(promptDir, "prompt.txt"), []byte("agent output\n"), 0o600); err != nil {
return runtime.ExecResult{}, err
}
}
return runtime.ExecResult{Stdout: `{"type":"result","result":"OK"}`}, nil
case strings.Contains(command, "git "):
return base.Exec(ctx, command, opts)
default:
// Session lookups would otherwise search the real home directory.
return runtime.ExecResult{}, nil
}
}

e := newTestEvaluator(EvalOptions{})
caseCfg := &config.CaseConfig{ID: "prompt-diff", Context: config.Context{Git: &config.GitContext{Init: true}}}
cleanup, finalize := e.prepareWorkspaceArtifacts(t.Context(), rt, caseCfg)
defer cleanup()
messages := []transcript.Message{{Role: transcript.RoleUser, Content: "write notes beside the prompt"}}
result, err := agent.NewQoderCLIAgent(agent.Config{}).Run(t.Context(), rt, agent.ExecOptions{ArtifactDir: t.TempDir()}, messages)
if err != nil {
t.Fatalf("qoder run: %v", err)
}
finalize(result)
return result.Artifacts.WorkspaceDiff, result.PromptDelivery
}

func TestSetupCaseEnvironmentAgentInstall(t *testing.T) {
t.Parallel()

Expand Down
Loading