diff --git a/docs/internal/workspace.md b/docs/internal/workspace.md index 63f7aa3..8fa8393 100644 --- a/docs/internal/workspace.md +++ b/docs/internal/workspace.md @@ -42,7 +42,7 @@ bundle path supplied by `internal/artifacts`. Exact physical paths belong in Prepared references delivered to Notarius use session-durable paths owned by `internal/artifacts` beneath -`cache/notarius/references//`. These verified +`inputs/references//`. These verified content-addressed snapshots are outside run-local layout, survive ordinary published-run cleanup, and are excluded from publish and restore enumeration. diff --git a/docs/operations.md b/docs/operations.md index 23653d2..7972456 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -707,12 +707,12 @@ Durable session paths: - `audio/**` - `transcripts/**` - `artifacts/**` -- `previous/**` +- `inputs/previous/**` - `reports/**` - `logs/**` - `config/**` - `runs/**` -- `cache/notarius/references//` +- `inputs/references//` `manifest.json` is the versioned session-progress document. Narratio accepts only `narratio.session-manifest.v2`. Do not edit unsupported session state to diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index c0d31e3..8265b8c 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -153,6 +153,13 @@ runner and restore entry points, not just the version comparison function. ## Stage 3 — Define the canonical workspace paths +**Complete.** Commit: `Define canonical session workspace paths`. +Verification: focused path-model, layout, reference-snapshot, and run-local tests +passed with Go 1.27.4. The broader `internal/stage` test run still has two +publication failures because previous-session publication enumeration uses the +old path; its migration belongs to Stage 18. Root reports/config paths remain +temporarily in use by producers until their routing changes in later stages. + **Read:** roadmap “Final layout and ownership”; [Workspace Internals](../internal/workspace.md). Entry points: `internal/artifacts/paths.go`, layout creation in its local store, `internal/config` path constants, and `internal/stage/run_local.go`. diff --git a/internal/artifacts/local.go b/internal/artifacts/local.go index 5b13940..29f9c23 100644 --- a/internal/artifacts/local.go +++ b/internal/artifacts/local.go @@ -76,12 +76,10 @@ func (s *LocalStore) ensureLayout(paths SessionPaths) (SessionPaths, error) { paths.AudioDir, paths.TranscriptsDir, paths.TranscriptsRawDir, - paths.TranscriptsTrimmedDir, paths.ArtifactsDir, paths.ReportsDir, paths.ConfigDir, paths.LogsDir, - paths.CurrentDir, paths.RunsDir, paths.PreviousDir, paths.PreviousArtifactsDir, diff --git a/internal/artifacts/local_test.go b/internal/artifacts/local_test.go index 5229a7e..4a8ff6a 100644 --- a/internal/artifacts/local_test.go +++ b/internal/artifacts/local_test.go @@ -23,12 +23,10 @@ func TestEnsureLayoutCreatesExpectedDirectories(t *testing.T) { checkDirExists(t, paths.AudioDir) checkDirExists(t, paths.TranscriptsDir) checkDirExists(t, paths.TranscriptsRawDir) - checkDirExists(t, paths.TranscriptsTrimmedDir) checkDirExists(t, paths.ArtifactsDir) checkDirExists(t, paths.ReportsDir) checkDirExists(t, paths.ConfigDir) checkDirExists(t, paths.LogsDir) - checkDirExists(t, paths.CurrentDir) checkDirExists(t, paths.RunsDir) checkDirExists(t, paths.PreviousDir) checkDirExists(t, paths.PreviousArtifactsDir) diff --git a/internal/artifacts/paths.go b/internal/artifacts/paths.go index e920db1..59953d1 100644 --- a/internal/artifacts/paths.go +++ b/internal/artifacts/paths.go @@ -14,28 +14,27 @@ const sha256HexLength = 64 // SessionPaths contains canonical local paths for one session work directory. type SessionPaths struct { - WorkspaceRoot string - CampaignID string - SessionID string - Root string - InputsDir string - AudioDir string - TranscriptsDir string - TranscriptsRawDir string - TranscriptsTrimmedDir string - ArtifactsDir string - ReportsDir string - ConfigDir string - LogsDir string - CurrentDir string - RunsDir string - PreviousDir string - CacheDir string - PreviousManifestPath string - PreviousArtifactsDir string - ManifestPath string - LockPath string - RestoreMarkerPath string + WorkspaceRoot string + CampaignID string + SessionID string + Root string + InputsDir string + AudioDir string + TranscriptsDir string + TranscriptsRawDir string + ArtifactsDir string + ReportsDir string + ConfigDir string + LogsDir string + DebugDir string + ReferencesDir string + RunsDir string + PreviousDir string + PreviousManifestPath string + PreviousArtifactsDir string + ManifestPath string + LockPath string + RestoreMarkerPath string } // SessionValidationPolishDir identifies the temporary destination-probe namespace. @@ -66,7 +65,7 @@ func SessionRunsDirForCampaign(rootDir, campaign, sessionID string) string { // SessionPreviousDirForCampaign returns the canonical previous-session state directory. func SessionPreviousDirForCampaign(rootDir, campaign, sessionID string) string { - return filepath.Join(SessionWorkDirForCampaign(rootDir, campaign, sessionID), config.PathPreviousDirSegment) + return filepath.Join(SessionWorkDirForCampaign(rootDir, campaign, sessionID), config.PathInputsDirSegment, config.PathPreviousDirSegment) } // SessionPreviousManifestPathForCampaign returns the canonical previous-session manifest cache path. @@ -101,6 +100,24 @@ func SessionRunStageDirForCampaign(rootDir, campaign, sessionID, runID, stageNam return filepath.Join(SessionRunRootForCampaign(rootDir, campaign, sessionID, runID), stageName) } +// SessionRunLogsDir and SessionRunDebugDir locate diagnostics for an attempt. +func SessionRunLogsDir(paths SessionPaths, runID, stageName string) string { + return filepath.Join(paths.RunsDir, runID, stageName, "logs") +} + +func SessionRunDebugDir(paths SessionPaths, runID, stageName string) string { + return filepath.Join(paths.RunsDir, runID, stageName, "debug") +} + +// SessionLatestLogsPath and SessionLatestDebugPath locate managed navigation views. +func SessionLatestLogsPath(paths SessionPaths, stageName string) string { + return filepath.Join(paths.LogsDir, stageName) +} + +func SessionLatestDebugPath(paths SessionPaths, stageName string) string { + return filepath.Join(paths.DebugDir, stageName) +} + // SessionRunExtractDirForCampaign returns the invocation-local extraction directory. func SessionRunExtractDirForCampaign(rootDir, campaign, sessionID, runID string) string { return SessionRunStageDirForCampaign(rootDir, campaign, sessionID, runID, "extract") @@ -124,7 +141,7 @@ func SessionRunNotariusOutputRootForCampaign(rootDir, campaign, sessionID, runID // SessionNotariusReferenceCacheDir returns the stable cache root for verified // reference snapshots supplied to Notarius. func SessionNotariusReferenceCacheDir(paths SessionPaths) string { - return filepath.Join(paths.CacheDir, "notarius", "references") + return paths.ReferencesDir } // SessionNotariusReferenceSnapshotPath returns the content-addressed path for @@ -280,27 +297,26 @@ func buildSessionPaths(workspaceRoot, campaign, sessionID string) SessionPaths { func buildSessionPathsFromRoot(workspaceRoot, campaign, sessionID, root string) SessionPaths { return SessionPaths{ - WorkspaceRoot: workspaceRoot, - CampaignID: campaign, - SessionID: sessionID, - Root: root, - InputsDir: filepath.Join(root, config.PathInputsDirSegment), - AudioDir: filepath.Join(root, config.PathAudioDirSegment), - TranscriptsDir: filepath.Join(root, config.PathTranscriptsSegment), - TranscriptsRawDir: filepath.Join(root, filepath.FromSlash(config.PathTranscriptsRaw)), - TranscriptsTrimmedDir: filepath.Join(root, filepath.FromSlash(config.PathTranscriptsTrimmed)), - ArtifactsDir: filepath.Join(root, config.PathArtifactsDirSegment), - ReportsDir: filepath.Join(root, config.PathReportsDirSegment), - ConfigDir: filepath.Join(root, config.PathConfigDirSegment), - LogsDir: filepath.Join(root, config.PathLogsDirSegment), - CurrentDir: filepath.Join(root, config.PathCurrentDirSegment), - RunsDir: filepath.Join(root, config.PathRunsDirSegment), - PreviousDir: filepath.Join(root, config.PathPreviousDirSegment), - CacheDir: filepath.Join(root, config.PathCacheDirSegment), - PreviousManifestPath: filepath.Join(root, config.PathPreviousDirSegment, config.PathManifestFile), - PreviousArtifactsDir: filepath.Join(root, config.PathPreviousDirSegment, config.PathArtifactsDirSegment), - ManifestPath: filepath.Join(root, config.PathManifestFile), - LockPath: filepath.Join(root, config.PathLockFile), - RestoreMarkerPath: filepath.Join(root, ".restore-incomplete.json"), + WorkspaceRoot: workspaceRoot, + CampaignID: campaign, + SessionID: sessionID, + Root: root, + InputsDir: filepath.Join(root, config.PathInputsDirSegment), + AudioDir: filepath.Join(root, config.PathAudioDirSegment), + TranscriptsDir: filepath.Join(root, config.PathTranscriptsSegment), + TranscriptsRawDir: filepath.Join(root, filepath.FromSlash(config.PathTranscriptsRaw)), + ArtifactsDir: filepath.Join(root, config.PathArtifactsDirSegment), + ReportsDir: filepath.Join(root, config.PathReportsDirSegment), + ConfigDir: filepath.Join(root, config.PathConfigDirSegment), + LogsDir: filepath.Join(root, config.PathLogsDirSegment), + DebugDir: filepath.Join(root, "debug"), + ReferencesDir: filepath.Join(root, config.PathInputsDirSegment, "references"), + RunsDir: filepath.Join(root, config.PathRunsDirSegment), + PreviousDir: filepath.Join(root, config.PathInputsDirSegment, config.PathPreviousDirSegment), + PreviousManifestPath: filepath.Join(root, config.PathInputsDirSegment, config.PathPreviousDirSegment, config.PathManifestFile), + PreviousArtifactsDir: filepath.Join(root, config.PathInputsDirSegment, config.PathPreviousDirSegment, config.PathArtifactsDirSegment), + ManifestPath: filepath.Join(root, config.PathManifestFile), + LockPath: filepath.Join(root, config.PathLockFile), + RestoreMarkerPath: filepath.Join(root, ".restore-incomplete.json"), } } diff --git a/internal/artifacts/paths_model_test.go b/internal/artifacts/paths_model_test.go index 8323416..de2842a 100644 --- a/internal/artifacts/paths_model_test.go +++ b/internal/artifacts/paths_model_test.go @@ -1,11 +1,40 @@ package artifacts import ( + "os" "path/filepath" "strings" "testing" ) +func TestCanonicalSessionLayout(t *testing.T) { + root := t.TempDir() + store := NewLocalStore(root) + paths, err := store.EnsureLayoutFor("campaign", "session") + if err != nil { + t.Fatal(err) + } + for name, got := range map[string]string{ + "inputs": paths.InputsDir, "audio": paths.AudioDir, "transcripts": paths.TranscriptsDir, + "transcripts/raw": paths.TranscriptsRawDir, "artifacts": paths.ArtifactsDir, + "inputs/previous": paths.PreviousDir, "inputs/references": paths.ReferencesDir, + "logs": paths.LogsDir, "debug": paths.DebugDir, "runs": paths.RunsDir, + "logs/polish": SessionLatestLogsPath(paths, "polish"), + "debug/polish": SessionLatestDebugPath(paths, "polish"), + "runs/run/polish/logs": SessionRunLogsDir(paths, "run", "polish"), + "runs/run/polish/debug": SessionRunDebugDir(paths, "run", "polish"), + } { + if want := filepath.Join(paths.Root, filepath.FromSlash(name)); got != want { + t.Errorf("%s = %q, want %q", name, got, want) + } + } + for _, name := range []string{"transcripts/trimmed", "current", "runs/run", "logs/polish", "debug/polish"} { + if _, err := os.Lstat(filepath.Join(paths.Root, filepath.FromSlash(name))); !os.IsNotExist(err) { + t.Errorf("%s exists or inaccessible: %v", name, err) + } + } +} + func TestSessionWorkDirForCampaign(t *testing.T) { root := "/tmp/workspace" got := SessionWorkDirForCampaign(root, "forsaken", "2026-04-19") @@ -74,7 +103,7 @@ func TestSessionNotariusReferenceSnapshotPath(t *testing.T) { if err != nil { t.Fatalf("SessionNotariusReferenceSnapshotPath() error = %v", err) } - wantRoot := filepath.Join(paths.Root, "cache", "notarius", "references") + wantRoot := filepath.Join(paths.Root, "inputs", "references") if root := SessionNotariusReferenceCacheDir(paths); root != wantRoot { t.Fatalf("SessionNotariusReferenceCacheDir() = %q, want %q", root, wantRoot) } @@ -107,25 +136,25 @@ func TestSessionNotariusReferenceSnapshotPathRejectsUnsafeIdentity(t *testing.T) func TestSessionPreviousPathsForCampaign(t *testing.T) { root := "/tmp/workspace" previousDir := SessionPreviousDirForCampaign(root, "forsaken", "2026-04-19") - wantPreviousDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous") + wantPreviousDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous") if previousDir != wantPreviousDir { t.Fatalf("SessionPreviousDirForCampaign() = %q, want %q", previousDir, wantPreviousDir) } manifestPath := SessionPreviousManifestPathForCampaign(root, "forsaken", "2026-04-19") - wantManifestPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous", "manifest.json") + wantManifestPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous", "manifest.json") if manifestPath != wantManifestPath { t.Fatalf("SessionPreviousManifestPathForCampaign() = %q, want %q", manifestPath, wantManifestPath) } artifactsDir := SessionPreviousArtifactsDirForCampaign(root, "forsaken", "2026-04-19") - wantArtifactsDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous", "artifacts") + wantArtifactsDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous", "artifacts") if artifactsDir != wantArtifactsDir { t.Fatalf("SessionPreviousArtifactsDirForCampaign() = %q, want %q", artifactsDir, wantArtifactsDir) } artifactPath := mustSessionPreviousArtifactPathForCampaign(t, root, "forsaken", "2026-04-19", "session_recap.md") - wantArtifactPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous", "artifacts", "session_recap.md") + wantArtifactPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous", "artifacts", "session_recap.md") if artifactPath != wantArtifactPath { t.Fatalf("mustSessionPreviousArtifactPathForCampaign(t, ) = %q, want %q", artifactPath, wantArtifactPath) } diff --git a/internal/config/defaults.go b/internal/config/defaults.go index e8c0714..f7279ce 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -67,15 +67,12 @@ const ( PathAudioDirSegment = "audio" PathTranscriptsSegment = "transcripts" PathTranscriptsRaw = "transcripts/raw" - PathTranscriptsTrimmed = "transcripts/trimmed" PathArtifactsDirSegment = "artifacts" PathReportsDirSegment = "reports" PathConfigDirSegment = "config" PathLogsDirSegment = "logs" - PathCurrentDirSegment = "current" PathRunsDirSegment = "runs" PathPreviousDirSegment = "previous" - PathCacheDirSegment = "cache" PathManifestFile = "manifest.json" PathLockFile = ".lock" PathTranscriptBase = artifactmodel.TranscriptPathBase diff --git a/internal/stage/extract_references.go b/internal/stage/extract_references.go index 6ccabc0..88df9e0 100644 --- a/internal/stage/extract_references.go +++ b/internal/stage/extract_references.go @@ -147,7 +147,7 @@ func absoluteExtractSnapshotPaths(paths artifacts.SessionPaths) (artifacts.Sessi if err != nil { return paths, fmt.Errorf("resolve snapshot session root: %w", err) } - paths.CacheDir, err = filepath.Abs(paths.CacheDir) + paths.ReferencesDir, err = filepath.Abs(paths.ReferencesDir) if err != nil { return paths, fmt.Errorf("resolve snapshot cache root: %w", err) } diff --git a/internal/stage/run_local.go b/internal/stage/run_local.go index 48971c1..1ebb566 100644 --- a/internal/stage/run_local.go +++ b/internal/stage/run_local.go @@ -103,7 +103,8 @@ func runLocalPathForCanonical(layout runStageLayout, sessionPaths artifacts.Sess if err != nil { return "", fmt.Errorf("derive session-relative path for %q: %w", cleanCanonical, err) } - if rel == config.PathPreviousDirSegment || strings.HasPrefix(rel, config.PathPreviousDirSegment+"/") { + previous := config.PathInputsDirSegment + "/" + config.PathPreviousDirSegment + if rel == previous || strings.HasPrefix(rel, previous+"/") { return cleanCanonical, nil } localPath, err := pathsafe.JoinSlashRelativeUnderRoot(layout.OutputsDir, rel) diff --git a/internal/stage/run_local_test.go b/internal/stage/run_local_test.go index 357e223..2d4fce3 100644 --- a/internal/stage/run_local_test.go +++ b/internal/stage/run_local_test.go @@ -45,7 +45,7 @@ func TestRunLocalPathForCanonicalKeepsPreviousStateSessionDurable(t *testing.T) t.Fatalf("mkdir outputs dir: %v", err) } - canonical := filepath.Join(sessionRoot, "previous", "artifacts", "session_recap.md") + canonical := filepath.Join(sessionRoot, "inputs", "previous", "artifacts", "session_recap.md") got, err := runLocalPathForCanonical(layout, artifacts.SessionPaths{Root: sessionRoot}, canonical) if err != nil { t.Fatalf("runLocalPathForCanonical() error = %v", err)