Simplify: reuse prompt-join and settings-path helpers · Entire
Simplify: reuse prompt-join and settings-path helpers
54f7f52→main·
Soph·3w ago·6 files·+33 added/-31 removed
Quality pass (/simplify) findings:
- Export checkpoint.RedactedJoinedPrompts (was the private redactedJoinedPrompts) and call it from fsstore instead of inlining join+redact twice, so alternate backends produce identically-redacted prompt blobs through the canonical path.
- Extract settingsAbsPaths/worktreeSettingsPaths helpers in the settings package and use them from Load, loadForWorktreeRoot, and checkpointsSettingsPaths, removing the triplicated base+local path resolution.
No behavior change; full unit suite green.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
52172b38461aView transcript
Changes
6
cmd/entire/cli
checkpoint
fsstore
Mfsstore.go+2/-3
Mpersistent.go+2/-2
Mprompts.go+4/-3
Mprompts_test.go+1/-1
settings
Mcheckpoints.go+2/-12
Msettings.go+22/-10
31 unmodified lines
32
33
34
35
35
36
37
103 unmodified lines
141
142
143
145
144
145
146
147
25 unmodified lines
173
174
175
177
176
177
178
179
31 unmodified lines
cp "github.com/entireio/cli/api/checkpoint"
"github.com/entireio/cli/cmd/entire/cli/checkpoint"
"github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
"github.com/entireio/cli/redact"
// BackendType is the registry type name for the filesystem reference backend.
103 unmodified lines
SessionID: opts.SessionID,
Metadata: metadataFromWriteOptions(opts),
Transcript: opts.Transcript.Bytes(),
Prompts: redact.String(strings.Join(opts.Prompts, checkpoint.PromptSeparator)),
Prompts: checkpoint.RedactedJoinedPrompts(opts.Prompts),
}
sc.Sessions = upsertSession(sc.Sessions, session)
25 unmodified lines
// Replace semantics, but do not clobber sibling fields (matches the git
// store's stop-time transcript backfill).
sc.Sessions[idx].Transcript = opts.Transcript.Bytes()
sc.Sessions[idx].Prompts = redact.String(strings.Join(opts.Prompts, checkpoint.PromptSeparator))
sc.Sessions[idx].Prompts = checkpoint.RedactedJoinedPrompts(opts.Prompts)
if len(opts.SkillEvents) > 0 {
sc.Sessions[idx].Metadata.SkillEvents = opts.SkillEvents
}
```
Mcmd/entire/cli/checkpoint/fsstore/fsstore.go+2/-3
423 unmodified lines
424 425 426 427 427 428 429 430 1179 unmodified lines
1610 1611 1612 1613 1613 1614 1615 1616
423 unmodified lines
// Write prompts via the 7-layer pipeline. OPF runs only in the // pre-push rewrite path (manual_commit_opf_rewrite.go). if len(opts.Prompts) > 0 { promptContent := redactedJoinedPrompts(opts.Prompts) promptContent := RedactedJoinedPrompts(opts.Prompts) blobHash, err := CreateBlobFromContent(s.repo, []byte(promptContent)) if err != nil { return filePaths, err } 1179 unmodified lines
// Replace prompts with 7-layer-redacted content. if len(opts.Prompts) > 0 { promptContent := redactedJoinedPrompts(opts.Prompts) promptContent := RedactedJoinedPrompts(opts.Prompts) blobHash, err := CreateBlobFromContent(s.repo, []byte(promptContent)) if err != nil { return fmt.Errorf("failed to create prompt blob: %w", err) } ```
Mcmd/entire/cli/checkpoint/persistent.go+2/-2
27 unmodified lines
28
29
30
31
31
32
33
34
33
34
35
36
37
27 unmodified lines
return prompts
// redactedJoinedPrompts joins prompts and runs the 7-layer redaction
// RedactedJoinedPrompts joins prompts and runs the 7-layer redaction
// pipeline. OPF runs exclusively in the pre-push rewrite (not here),
// so the writer's hot path stays predictable.
func redactedJoinedPrompts(prompts []string) string {
// so the writer's hot path stays predictable. Exported so alternate
// persistent backends produce identically-redacted prompt blobs.
func RedactedJoinedPrompts(prompts []string) string {
return redact.String(strings.Join(prompts, PromptSeparator))
}
```
Mcmd/entire/cli/checkpoint/prompts.go+4/-3
30 unmodified lines
31 32 33 34 34 35 36 37
30 unmodified lines
// pipeline. OPF runs only in the pre-push rewrite path, never here. func TestRedactedJoinedPrompts_AppliesSafetyNet(t *testing.T) { t.Parallel() got := redactedJoinedPrompts([]string{"hello", "world"}) got := RedactedJoinedPrompts([]string{"hello", "world"}) assert.NotEmpty(t, got) assert.Contains(t, got, PromptSeparator) } ```
Mcmd/entire/cli/checkpoint/prompts_test.go+1/-1
7 unmodified lines
8
9
10
11
11
12
14
13
14
15
110 unmodified lines
126
127
128
131
129
130
133
134
135
136
137
138
139
140
141
131
132
7 unmodified lines
"fmt"
"log/slog"
"os"
"path/filepath"
"github.com/entireio/cli/cmd/entire/cli/logging"
"github.com/entireio/cli/cmd/entire/cli/paths"
// ErrInvalidCheckpointsConfig is returned when a present "checkpoints" settings
110 unmodified lines
// same way Load does (minus clone preferences, which carry no checkpoint config).
func checkpointsSettingsPaths(ctx context.Context) (base, local string) {
if worktreeRoot, ok := worktreeRootFromContext(ctx); ok {
return filepath.Join(worktreeRoot, EntireSettingsFile), filepath.Join(worktreeRoot, EntireSettingsLocalFile)
return worktreeSettingsPaths(worktreeRoot)
}
base, err := paths.AbsPath(ctx, EntireSettingsFile)
if err != nil {
base = EntireSettingsFile
}
local, err = paths.AbsPath(ctx, EntireSettingsLocalFile)
if err != nil {
local = EntireSettingsLocalFile
}
return base, local
return settingsAbsPaths(ctx)
}
```
Mcmd/entire/cli/settings/checkpoints.go+2/-12
376 unmodified lines
377 378 379 380 381 382 383 384 380 381 382 383 6 unmodified lines
390 391 392 397 393 394 395 396 397 398 399 400 401 402 399 403 404 405 406 407 408 409 410 411 402 412 413 414 415 416 417 418 406 419 420 421 422 1 unmodified line
424 425 426 414 427 428 429
376 unmodified lines
return loadForWorktreeRoot(ctx, worktreeRoot) }
// Get absolute paths for settings files settingsFileAbs, err := paths.AbsPath(ctx, EntireSettingsFile) if err != nil { settingsFileAbs = EntireSettingsFile // Fallback to relative } settingsFileAbs, localSettingsFileAbs := settingsAbsPaths(ctx) preferencesFileAbs := "" if path, prefErr := ClonePreferencesPath(ctx); prefErr == nil { preferencesFileAbs = path 6 unmodified lines
logging.Debug(ctx, "clone preferences path unresolved; skipping preferences layer", slog.String("error", prefErr.Error())) } localSettingsFileAbs, err := paths.AbsPath(ctx, EntireSettingsLocalFile)
return loadMergedSettings(settingsFileAbs, preferencesFileAbs, localSettingsFileAbs) }
// settingsAbsPaths resolves the base and local settings file paths relative to // the current working directory, falling back to the relative path when // absolute resolution fails. func settingsAbsPaths(ctx context.Context) (base, local string) { base, err := paths.AbsPath(ctx, EntireSettingsFile) if err != nil { localSettingsFileAbs = EntireSettingsLocalFile // Fallback to relative base = EntireSettingsFile // Fallback to relative } local, err = paths.AbsPath(ctx, EntireSettingsLocalFile) if err != nil { local = EntireSettingsLocalFile // Fallback to relative } return base, local }
return loadMergedSettings(settingsFileAbs, preferencesFileAbs, localSettingsFileAbs) // worktreeSettingsPaths resolves the base and local settings file paths under // an explicit worktree root. func worktreeSettingsPaths(worktreeRoot string) (base, local string) { return filepath.Join(worktreeRoot, EntireSettingsFile), filepath.Join(worktreeRoot, EntireSettingsLocalFile) }
func loadForWorktreeRoot(ctx context.Context, worktreeRoot string) (*EntireSettings, error) { settingsFileAbs := filepath.Join(worktreeRoot, EntireSettingsFile) settingsFileAbs, localSettingsFileAbs := worktreeSettingsPaths(worktreeRoot) preferencesFileAbs := "" if path, prefErr := clonePreferencesPathForWorktreeRoot(ctx, worktreeRoot); prefErr == nil { preferencesFileAbs = path 1 unmodified line
logging.Debug(ctx, "clone preferences path unresolved; skipping preferences layer", slog.String("error", prefErr.Error())) } localSettingsFileAbs := filepath.Join(worktreeRoot, EntireSettingsLocalFile) return loadMergedSettings(settingsFileAbs, preferencesFileAbs, localSettingsFileAbs) } ```