bathos 0.4.0__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. {bathos-0.4.0 → bathos-0.4.1}/CLAUDE.md +3 -1
  2. {bathos-0.4.0 → bathos-0.4.1}/PKG-INFO +1 -1
  3. {bathos-0.4.0 → bathos-0.4.1}/pyproject.toml +1 -1
  4. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/__init__.py +1 -1
  5. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/cli.py +216 -8
  6. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/compact.py +116 -3
  7. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/config.py +3 -1
  8. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/mcp.py +128 -0
  9. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/migrate.py +1 -1
  10. bathos-0.4.1/src/bathos/postmortem.py +177 -0
  11. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/query.py +54 -35
  12. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/runner.py +14 -0
  13. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/schema.py +51 -1
  14. {bathos-0.4.0 → bathos-0.4.1}/tests/test_cli.py +33 -1
  15. {bathos-0.4.0 → bathos-0.4.1}/tests/test_compact.py +31 -30
  16. {bathos-0.4.0 → bathos-0.4.1}/tests/test_config.py +10 -0
  17. {bathos-0.4.0 → bathos-0.4.1}/tests/test_integration.py +3 -2
  18. {bathos-0.4.0 → bathos-0.4.1}/tests/test_linter.py +4 -0
  19. bathos-0.4.1/tests/test_postmortem.py +604 -0
  20. {bathos-0.4.0 → bathos-0.4.1}/tests/test_schema.py +6 -6
  21. {bathos-0.4.0 → bathos-0.4.1}/tests/test_sync_project_filter.py +2 -3
  22. {bathos-0.4.0 → bathos-0.4.1}/uv.lock +1 -1
  23. {bathos-0.4.0 → bathos-0.4.1}/.agent/workspace.id +0 -0
  24. {bathos-0.4.0 → bathos-0.4.1}/.bth.toml +0 -0
  25. {bathos-0.4.0 → bathos-0.4.1}/.coverage +0 -0
  26. {bathos-0.4.0 → bathos-0.4.1}/.github/SECRETS.md +0 -0
  27. {bathos-0.4.0 → bathos-0.4.1}/.github/workflows/publish.yml +0 -0
  28. {bathos-0.4.0 → bathos-0.4.1}/.github/workflows/test.yml +0 -0
  29. {bathos-0.4.0 → bathos-0.4.1}/.gitignore +0 -0
  30. {bathos-0.4.0 → bathos-0.4.1}/.python-version +0 -0
  31. {bathos-0.4.0 → bathos-0.4.1}/.readthedocs.yaml +0 -0
  32. {bathos-0.4.0 → bathos-0.4.1}/CHANGELOG.md +0 -0
  33. {bathos-0.4.0 → bathos-0.4.1}/LICENSE +0 -0
  34. {bathos-0.4.0 → bathos-0.4.1}/README.md +0 -0
  35. {bathos-0.4.0 → bathos-0.4.1}/agent_assets/docs/claude-code-integration.md +0 -0
  36. {bathos-0.4.0 → bathos-0.4.1}/agent_assets/docs/gemini-cli-integration.md +0 -0
  37. {bathos-0.4.0 → bathos-0.4.1}/agent_assets/using_bathos/SKILL.md +0 -0
  38. {bathos-0.4.0 → bathos-0.4.1}/docs/Makefile +0 -0
  39. {bathos-0.4.0 → bathos-0.4.1}/docs/source/api.rst +0 -0
  40. {bathos-0.4.0 → bathos-0.4.1}/docs/source/architecture.rst +0 -0
  41. {bathos-0.4.0 → bathos-0.4.1}/docs/source/conf.py +0 -0
  42. {bathos-0.4.0 → bathos-0.4.1}/docs/source/contributing.rst +0 -0
  43. {bathos-0.4.0 → bathos-0.4.1}/docs/source/index.rst +0 -0
  44. {bathos-0.4.0 → bathos-0.4.1}/docs/source/slurm-integration.rst +0 -0
  45. {bathos-0.4.0 → bathos-0.4.1}/docs/source/user-guide.rst +0 -0
  46. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-15-bathos-v01-core.md +0 -0
  47. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-agent-onboarding-export.md +0 -0
  48. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-decorator.md +0 -0
  49. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-historical-migration.md +0 -0
  50. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-linter.md +0 -0
  51. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-remote-management.md +0 -0
  52. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-schema-versioning.md +0 -0
  53. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-skill-and-export-mcp.md +0 -0
  54. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-19-v02-feature-wiring.md +0 -0
  55. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-20-agentic-integrity-design.md +0 -0
  56. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/plans/2026-05-20-agentic-integrity-impl-plan.md +0 -0
  57. {bathos-0.4.0 → bathos-0.4.1}/docs/superpowers/specs/2026-05-15-bathos-design.md +0 -0
  58. {bathos-0.4.0 → bathos-0.4.1}/inventory.txt +0 -0
  59. {bathos-0.4.0 → bathos-0.4.1}/main.py +0 -0
  60. {bathos-0.4.0 → bathos-0.4.1}/praxia.toml +0 -0
  61. {bathos-0.4.0 → bathos-0.4.1}/scripts/benchmarks/.bth.toml +0 -0
  62. {bathos-0.4.0 → bathos-0.4.1}/scripts/experiments/.bth.toml +0 -0
  63. {bathos-0.4.0 → bathos-0.4.1}/scripts/slurm/_bth_env.sh +0 -0
  64. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/archive.py +0 -0
  65. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/campaigns.py +0 -0
  66. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/catalog.py +0 -0
  67. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/checker.py +0 -0
  68. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/decorators.py +0 -0
  69. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/export.py +0 -0
  70. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/git.py +0 -0
  71. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/init.py +0 -0
  72. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/linter.py +0 -0
  73. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/new_experiment.py +0 -0
  74. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/prereg.py +0 -0
  75. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/remote.py +0 -0
  76. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/sidecar.py +0 -0
  77. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/sprint_audit.py +0 -0
  78. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/sync.py +0 -0
  79. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/templates/_bth_env.sh +0 -0
  80. {bathos-0.4.0 → bathos-0.4.1}/src/bathos/validate.py +0 -0
  81. {bathos-0.4.0 → bathos-0.4.1}/tests/__init__.py +0 -0
  82. {bathos-0.4.0 → bathos-0.4.1}/tests/conftest.py +0 -0
  83. {bathos-0.4.0 → bathos-0.4.1}/tests/test_archive.py +0 -0
  84. {bathos-0.4.0 → bathos-0.4.1}/tests/test_campaigns.py +0 -0
  85. {bathos-0.4.0 → bathos-0.4.1}/tests/test_catalog.py +0 -0
  86. {bathos-0.4.0 → bathos-0.4.1}/tests/test_checker.py +0 -0
  87. {bathos-0.4.0 → bathos-0.4.1}/tests/test_cluster_workflow.py +0 -0
  88. {bathos-0.4.0 → bathos-0.4.1}/tests/test_decorators.py +0 -0
  89. {bathos-0.4.0 → bathos-0.4.1}/tests/test_export.py +0 -0
  90. {bathos-0.4.0 → bathos-0.4.1}/tests/test_git.py +0 -0
  91. {bathos-0.4.0 → bathos-0.4.1}/tests/test_init.py +0 -0
  92. {bathos-0.4.0 → bathos-0.4.1}/tests/test_mcp_integration.py +0 -0
  93. {bathos-0.4.0 → bathos-0.4.1}/tests/test_mcp_server.py +0 -0
  94. {bathos-0.4.0 → bathos-0.4.1}/tests/test_migrate.py +0 -0
  95. {bathos-0.4.0 → bathos-0.4.1}/tests/test_new_experiment.py +0 -0
  96. {bathos-0.4.0 → bathos-0.4.1}/tests/test_prereg.py +0 -0
  97. {bathos-0.4.0 → bathos-0.4.1}/tests/test_query.py +0 -0
  98. {bathos-0.4.0 → bathos-0.4.1}/tests/test_remote.py +0 -0
  99. {bathos-0.4.0 → bathos-0.4.1}/tests/test_runner.py +0 -0
  100. {bathos-0.4.0 → bathos-0.4.1}/tests/test_sidecar.py +0 -0
  101. {bathos-0.4.0 → bathos-0.4.1}/tests/test_slurm_integration.py +0 -0
  102. {bathos-0.4.0 → bathos-0.4.1}/tests/test_sprint_audit.py +0 -0
  103. {bathos-0.4.0 → bathos-0.4.1}/tests/test_sync.py +0 -0
  104. {bathos-0.4.0 → bathos-0.4.1}/tests/test_validate.py +0 -0
@@ -12,7 +12,7 @@ bathos is a standalone experiment tracking CLI for a single researcher across 10
12
12
 
13
13
  ## Current Status (as of 2026-05-21)
14
14
 
15
- **v0.4.0: complete and merged to main.** 333 tests passing.
15
+ **v0.4.1: complete and merged to main.** 348 tests passing.
16
16
 
17
17
  - Full design spec: `.praxia/specs/bathos-design.md`
18
18
  - v0.1 implementation plan: `.praxia/specs/bathos-v01-plan.md`
@@ -24,6 +24,8 @@ bathos is a standalone experiment tracking CLI for a single researcher across 10
24
24
 
25
25
  **Shipped in v0.4:** Per-project sync filtering — `bth sync` now pushes/pulls only the current project's runs (no cross-project contamination). Cool-tier layout changed to `runs/<slug>/run_<uuid>.parquet`. New command `bth migrate-to-project-subdirs` migrates flat catalogs. `sync_filter` config knob; `--no-project-filter` opt-out planned.
26
26
 
27
+ **Shipped in v0.4.1:** Postmortem tracking — `*.bth.postmortem.toml` format, `bth postmortem validate` CLI command, `postmortem_scaffold`/`postmortem_validate`/`postmortem_get` MCP tools. Schema v4 with 10 new DuckDB columns; `compact` syncs postmortem metadata. Validation covers refutation consistency, asset path containment, sha256 checksums, and git drift detection. `script_sha256` computed in `runner.py` at experiment launch.
28
+
27
29
  **Remaining backlog:** #136 (bth-migrate praxia workflow), #137 (global instruction portability), #142 (results management design).
28
30
 
29
31
  ---
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bathos
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Local-first, zero-server experiment tracking for researchers
5
5
  Project-URL: Homepage, https://github.com/mariellerossi/bathos
6
6
  Project-URL: Documentation, https://bathos.readthedocs.io
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bathos"
7
- version = "0.4.0"
7
+ version = "0.4.1"
8
8
  description = "Local-first, zero-server experiment tracking for researchers"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -1,4 +1,4 @@
1
- __version__ = "0.4.0"
1
+ __version__ = "0.4.1"
2
2
 
3
3
  from bathos.decorators import experiment
4
4
 
@@ -18,13 +18,19 @@ app.add_typer(remote_app, name="remote")
18
18
  campaign_app = typer.Typer(help="Manage experiment campaigns")
19
19
  app.add_typer(campaign_app, name="campaign")
20
20
 
21
+ postmortem_app = typer.Typer(help="Manage postmortem reviews")
22
+ app.add_typer(postmortem_app, name="postmortem")
23
+
21
24
 
22
25
  def _catalog_dir() -> Path:
23
26
  override = os.environ.get("BTH_CATALOG_DIR")
24
27
  if override:
25
28
  return Path(override)
26
- from bathos.config import default_catalog_dir
29
+ from bathos.config import find_project_config, load_project_config, default_catalog_dir
27
30
 
31
+ cfg_path = find_project_config()
32
+ if cfg_path is not None:
33
+ return load_project_config(cfg_path).catalog_dir
28
34
  return default_catalog_dir()
29
35
 
30
36
 
@@ -419,6 +425,7 @@ def campaign_create(
419
425
  ):
420
426
  """Create a new campaign."""
421
427
  import duckdb
428
+
422
429
  from bathos.campaigns import create_campaign
423
430
  slug = _require_project_slug()
424
431
  db = duckdb.connect(str(_catalog_dir() / "bathos.db"))
@@ -436,7 +443,8 @@ def campaign_add(
436
443
  ):
437
444
  """Add a run to a campaign."""
438
445
  import duckdb
439
- from bathos.campaigns import add_run_to_campaign, CampaignError
446
+
447
+ from bathos.campaigns import CampaignError, add_run_to_campaign
440
448
  db = duckdb.connect(str(_catalog_dir() / "bathos.db"))
441
449
  try:
442
450
  add_run_to_campaign(db, campaign, run_id)
@@ -456,7 +464,8 @@ def campaign_conclude(
456
464
  ):
457
465
  """Conclude a campaign with an outcome label."""
458
466
  import duckdb
459
- from bathos.campaigns import conclude_campaign, CampaignError
467
+
468
+ from bathos.campaigns import CampaignError, conclude_campaign
460
469
  db = duckdb.connect(str(_catalog_dir() / "bathos.db"))
461
470
  try:
462
471
  conclude_campaign(db, campaign_id, outcome, note)
@@ -474,6 +483,7 @@ def campaign_ls(
474
483
  ):
475
484
  """List campaigns."""
476
485
  import duckdb
486
+
477
487
  from bathos.campaigns import list_campaigns
478
488
  db = duckdb.connect(str(_catalog_dir() / "bathos.db"), read_only=True)
479
489
  try:
@@ -493,6 +503,7 @@ def campaign_show(
493
503
  ):
494
504
  """Show campaign details."""
495
505
  import duckdb
506
+
496
507
  from bathos.campaigns import get_campaign
497
508
  db = duckdb.connect(str(_catalog_dir() / "bathos.db"), read_only=True)
498
509
  try:
@@ -521,6 +532,7 @@ def campaign_review(
521
532
  ):
522
533
  """Review campaign: residual rate, bypass rate, outcome distribution."""
523
534
  import duckdb
535
+
524
536
  from bathos.campaigns import review_campaign
525
537
  db = duckdb.connect(str(_catalog_dir() / "bathos.db"), read_only=True)
526
538
  try:
@@ -676,11 +688,11 @@ def lint(
676
688
  ):
677
689
  """Check scripts/ for naming conventions and missing sidecars."""
678
690
  from bathos.linter import (
679
- lint_project,
680
691
  IssueSeverity,
681
- check_residual_rates,
682
692
  check_bypass_trend,
693
+ check_residual_rates,
683
694
  check_unfired_branches,
695
+ lint_project,
684
696
  )
685
697
 
686
698
  issues = lint_project(project_root.resolve())
@@ -702,7 +714,11 @@ def lint(
702
714
 
703
715
  for issue in issues:
704
716
  prefix = "error" if issue.severity == IssueSeverity.ERROR else "warning"
705
- typer.echo(f"{prefix}: {issue.path.relative_to(project_root.resolve())} — {issue.issue}: {issue.detail}")
717
+ try:
718
+ display_path = issue.path.relative_to(project_root.resolve())
719
+ except ValueError:
720
+ display_path = issue.path
721
+ typer.echo(f"{prefix}: {display_path} — {issue.issue}: {issue.detail}")
706
722
 
707
723
  typer.echo()
708
724
  typer.echo(f"{len(errors)} error(s), {len(warnings)} warning(s).")
@@ -738,7 +754,7 @@ def export_cmd(
738
754
  dry_run: bool = typer.Option(False, "--dry-run", help="Print what would happen without writing"),
739
755
  ):
740
756
  """Export the using-bathos skill and register MCP server for a code tool."""
741
- from bathos.export import export_skill, resolve_target, register_mcp, ExportError
757
+ from bathos.export import ExportError, export_skill, register_mcp, resolve_target
742
758
 
743
759
  try:
744
760
  target = resolve_target(tool=tool, level=level)
@@ -760,8 +776,8 @@ def export_cmd(
760
776
  @app.command("catalog-version")
761
777
  def catalog_version_cmd():
762
778
  """Show schema version status of the catalog."""
763
- from bathos.schema import CURRENT_SCHEMA_VERSION
764
779
  from bathos.migrate import migrate_catalog
780
+ from bathos.schema import CURRENT_SCHEMA_VERSION
765
781
 
766
782
  catalog_dir = _catalog_dir()
767
783
  typer.echo(f"Current schema version: {CURRENT_SCHEMA_VERSION}")
@@ -797,3 +813,195 @@ def _parse_since(since: str | None) -> datetime | None:
797
813
  if since.endswith("h"):
798
814
  return datetime.now(UTC) - timedelta(hours=float(since[:-1]))
799
815
  return None
816
+
817
+
818
+ @postmortem_app.command()
819
+ def scaffold(
820
+ run_id: str = typer.Argument(..., help="Run ID to scaffold a postmortem template for"),
821
+ ):
822
+ """Scaffold a new postmortem template for the given Run ID."""
823
+ from bathos.config import find_project_config, load_project_config
824
+ from bathos.catalog import read_runs
825
+ import duckdb
826
+ import shlex
827
+
828
+ # 1. Search for run in DB
829
+ run_row = None
830
+ db_path = _catalog_dir() / "bathos.db"
831
+ if db_path.exists():
832
+ con = duckdb.connect(str(db_path))
833
+ try:
834
+ run_row = con.execute("SELECT command, project_slug FROM runs WHERE id = ?", [run_id]).fetchone()
835
+ except Exception:
836
+ pass
837
+ finally:
838
+ con.close()
839
+
840
+ if not run_row:
841
+ # Check cool fragments
842
+ cool_runs = read_runs(_catalog_dir())
843
+ for r in cool_runs:
844
+ if r.id == run_id:
845
+ run_row = (r.command, r.project_slug)
846
+ break
847
+
848
+ if not run_row:
849
+ typer.echo("Run not found", err=True)
850
+ raise typer.Exit(1)
851
+
852
+ command = run_row[0]
853
+
854
+ # Get workspace root
855
+ config_path = find_project_config(Path.cwd())
856
+ if config_path:
857
+ workspace_root = load_project_config(config_path).root
858
+ else:
859
+ workspace_root = Path.cwd()
860
+
861
+ # Parse command to find the script
862
+ parts = shlex.split(command)
863
+ script_path = None
864
+ for part in parts:
865
+ p = Path(part)
866
+ if p.suffix == ".py":
867
+ script_path = workspace_root / p
868
+ break
869
+ if (workspace_root / p).is_file():
870
+ script_path = workspace_root / p
871
+ break
872
+
873
+ if not script_path:
874
+ # Fallback to run.py in workspace root
875
+ script_path = workspace_root / "run.py"
876
+
877
+ script_path.parent.mkdir(parents=True, exist_ok=True)
878
+ postmortem_path = script_path.parent / f"{script_path.name}.{run_id}.bth.postmortem.toml"
879
+
880
+ # Scaffold content
881
+ toml_content = f"""run_id = "{run_id}"
882
+
883
+ [postmortem]
884
+ hypothesis_status = "unassigned"
885
+ summary = ""
886
+ unexpected_observations = ""
887
+ root_cause = ""
888
+ verdict_override = "none"
889
+ next_steps = ""
890
+ author = ""
891
+ status = "draft"
892
+
893
+ [asset_links]
894
+ """
895
+ postmortem_path.write_text(toml_content)
896
+ typer.echo(f"Scaffolded postmortem template at {postmortem_path}")
897
+
898
+
899
+ @postmortem_app.command()
900
+ def show(
901
+ run_id: str = typer.Argument(..., help="Run ID of the postmortem to show"),
902
+ strict_files: bool = typer.Option(False, "--strict-files", help="Fail if files in asset_links do not exist"),
903
+ ):
904
+ """Display and validate the postmortem for the given Run ID."""
905
+ from bathos.config import find_project_config, load_project_config
906
+ from bathos.postmortem import parse_postmortem, validate_postmortem
907
+ from bathos.schema import Run
908
+ import duckdb
909
+
910
+ config_path = find_project_config(Path.cwd())
911
+ if config_path:
912
+ workspace_root = load_project_config(config_path).root
913
+ else:
914
+ workspace_root = Path.cwd()
915
+
916
+ # Find the postmortem TOML file in workspace
917
+ postmortem_file = None
918
+ if workspace_root.exists():
919
+ for pm_file in workspace_root.rglob("*.bth.postmortem.toml"):
920
+ try:
921
+ pm = parse_postmortem(pm_file)
922
+ if pm.run_id == run_id:
923
+ postmortem_file = pm_file
924
+ break
925
+ except Exception:
926
+ pass
927
+
928
+ if not postmortem_file:
929
+ typer.echo("Postmortem not found", err=True)
930
+ raise typer.Exit(1)
931
+
932
+ pm = parse_postmortem(postmortem_file)
933
+
934
+ # Search for run in DB
935
+ run_obj = None
936
+ db_path = _catalog_dir() / "bathos.db"
937
+ if db_path.exists():
938
+ con = duckdb.connect(str(db_path))
939
+ try:
940
+ arrow_tbl = con.execute("SELECT * FROM runs WHERE id = ?", [run_id]).arrow()
941
+ if arrow_tbl.num_rows > 0:
942
+ pydict = arrow_tbl.to_pydict()
943
+ run_obj = Run.from_arrow_row(pydict, 0)
944
+ except Exception:
945
+ pass
946
+ finally:
947
+ con.close()
948
+
949
+ if not run_obj:
950
+ # Check cool fragments
951
+ from bathos.catalog import read_runs
952
+ cool_runs = read_runs(_catalog_dir())
953
+ for r in cool_runs:
954
+ if r.id == run_id:
955
+ run_obj = r
956
+ break
957
+
958
+ # Perform validation
959
+ result = validate_postmortem(pm, workspace_root=workspace_root, run=run_obj, strict_files=strict_files)
960
+ if not result.ok:
961
+ typer.echo("Validation failed", err=True)
962
+ for err in result.errors:
963
+ typer.echo(f"- {err.message}", err=True)
964
+ typer.echo(f"Hypothesis status: {pm.hypothesis_status}", err=True)
965
+ typer.echo(f"Verdict override: {pm.verdict_override}", err=True)
966
+ raise typer.Exit(1)
967
+
968
+ typer.echo(f"Run ID: {pm.run_id}")
969
+ typer.echo(f"Status: {pm.status}")
970
+ typer.echo(f"Hypothesis Status: {pm.hypothesis_status}")
971
+ typer.echo(f"Verdict Override: {pm.verdict_override}")
972
+ typer.echo(f"Summary: {pm.summary}")
973
+ if pm.asset_links:
974
+ typer.echo(f"Asset Links: {pm.asset_links}")
975
+
976
+
977
+ @postmortem_app.command()
978
+ def validate(
979
+ file: Path = typer.Argument(..., help="Path to .bth.postmortem.toml file to validate"),
980
+ strict: bool = typer.Option(False, "--strict", help="Treat missing run ID as error"),
981
+ strict_files: bool = typer.Option(False, "--strict-files", help="Treat missing asset files as error"),
982
+ ):
983
+ """Validate a postmortem TOML file for structural and logical correctness."""
984
+ from bathos.postmortem import parse_postmortem, validate_postmortem
985
+ from bathos.config import find_project_config, load_project_config
986
+
987
+ if not file.exists():
988
+ typer.echo(f"File not found: {file}", err=True)
989
+ raise typer.Exit(1)
990
+
991
+ try:
992
+ pm = parse_postmortem(file)
993
+ except Exception as e:
994
+ typer.echo(f"Parse error: {e}", err=True)
995
+ raise typer.Exit(1)
996
+
997
+ config_path = find_project_config(Path.cwd())
998
+ workspace_root = load_project_config(config_path).root if config_path else Path.cwd()
999
+
1000
+ result = validate_postmortem(pm, workspace_root=workspace_root, strict=strict, strict_files=strict_files)
1001
+ if result.ok:
1002
+ typer.echo(f"✓ {file.name} is valid")
1003
+ else:
1004
+ typer.echo(f"✗ Validation failed for {file.name}:", err=True)
1005
+ for err in result.errors:
1006
+ typer.echo(f" - {err.message}", err=True)
1007
+ raise typer.Exit(1)
@@ -99,9 +99,26 @@ def _migrate_v2(run_dict: dict) -> dict:
99
99
  return run_dict
100
100
 
101
101
 
102
+ def _migrate_v3(run_dict: dict) -> dict:
103
+ """Migrate v3 fragment to v4 by adding postmortem fields."""
104
+ run_dict["script_sha256"] = ""
105
+ run_dict["postmortem_status"] = "unassigned"
106
+ run_dict["postmortem_override"] = "none"
107
+ run_dict["postmortem_verdict_override"] = "none"
108
+ run_dict["postmortem_author"] = ""
109
+ run_dict["postmortem_path"] = ""
110
+ run_dict["postmortem_hypothesis_status"] = "unassigned"
111
+ run_dict["postmortem_has_anomalies"] = False
112
+ run_dict["postmortem_summary"] = ""
113
+ run_dict["postmortem_asset_links"] = "{}"
114
+ run_dict["schema_version"] = "4"
115
+ return run_dict
116
+
117
+
102
118
  MIGRATIONS["0"] = _migrate_v0
103
119
  MIGRATIONS["1"] = _migrate_v1
104
120
  MIGRATIONS["2"] = _migrate_v2
121
+ MIGRATIONS["3"] = _migrate_v3
105
122
 
106
123
 
107
124
  _RUNS_TABLE_SCHEMA = """
@@ -132,7 +149,17 @@ CREATE TABLE IF NOT EXISTS runs (
132
149
  sidecar_mode TEXT,
133
150
  outcome_is_residual BOOLEAN,
134
151
  skill_sha256 TEXT,
135
- campaign_id TEXT
152
+ campaign_id TEXT,
153
+ script_sha256 TEXT,
154
+ postmortem_status TEXT,
155
+ postmortem_override TEXT,
156
+ postmortem_verdict_override TEXT,
157
+ postmortem_author TEXT,
158
+ postmortem_path TEXT,
159
+ postmortem_hypothesis_status TEXT,
160
+ postmortem_has_anomalies BOOLEAN,
161
+ postmortem_summary TEXT,
162
+ postmortem_asset_links TEXT
136
163
  )
137
164
  """
138
165
 
@@ -238,6 +265,28 @@ def compact(catalog_dir: Path) -> CompactResult:
238
265
  # Read all runs from cool fragments (read_runs snapshots file list internally)
239
266
  cool_runs = read_runs(catalog_dir)
240
267
 
268
+ # Parse all postmortems in workspace
269
+ from bathos.config import find_project_config, load_project_config
270
+ from bathos.postmortem import parse_postmortem
271
+
272
+ postmortem_map = {}
273
+ config_path = find_project_config(Path.cwd())
274
+ if config_path:
275
+ project_config = load_project_config(config_path)
276
+ workspace_root = project_config.root
277
+ else:
278
+ workspace_root = Path.cwd()
279
+
280
+ if workspace_root.exists():
281
+ for pm_file in workspace_root.rglob("*.bth.postmortem.toml"):
282
+ try:
283
+ pm = parse_postmortem(pm_file)
284
+ if pm.status != "draft":
285
+ rel_path = str(pm_file.relative_to(workspace_root))
286
+ postmortem_map[pm.run_id] = (pm, rel_path)
287
+ except Exception:
288
+ pass
289
+
241
290
  # Open DuckDB connection
242
291
  db_path = catalog_dir / "bathos.db"
243
292
  con = duckdb.connect(str(db_path))
@@ -273,11 +322,63 @@ def compact(catalog_dir: Path) -> CompactResult:
273
322
 
274
323
  if existing:
275
324
  skipped += 1
325
+ if run.id in postmortem_map:
326
+ pm, rel_path = postmortem_map[run.id]
327
+ postmortem_verdict_override = pm.verdict_override
328
+ postmortem_has_anomalies = any(v and str(v).lower() != "none" for v in getattr(pm, "anomalies", {}).values())
329
+
330
+ curr_outcome = con.execute("SELECT outcome FROM runs WHERE id = ?", [run.id]).fetchone()[0] or ""
331
+ outcome = postmortem_verdict_override if postmortem_verdict_override != "none" else curr_outcome
332
+
333
+ con.execute(
334
+ """
335
+ UPDATE runs SET
336
+ outcome = ?,
337
+ postmortem_status = ?,
338
+ postmortem_override = ?,
339
+ postmortem_verdict_override = ?,
340
+ postmortem_author = ?,
341
+ postmortem_path = ?,
342
+ postmortem_hypothesis_status = ?,
343
+ postmortem_has_anomalies = ?,
344
+ postmortem_summary = ?,
345
+ postmortem_asset_links = ?
346
+ WHERE id = ?
347
+ """,
348
+ [
349
+ outcome,
350
+ pm.status,
351
+ pm.verdict_override,
352
+ pm.verdict_override,
353
+ pm.author,
354
+ rel_path,
355
+ pm.hypothesis_status,
356
+ postmortem_has_anomalies,
357
+ pm.summary,
358
+ json.dumps(pm.asset_links),
359
+ run.id
360
+ ]
361
+ )
276
362
  continue
277
363
 
278
364
  # Apply migrations if needed
279
365
  run = _apply_migrations(run)
280
366
 
367
+ # Apply postmortem updates to run object if present
368
+ if run.id in postmortem_map:
369
+ pm, rel_path = postmortem_map[run.id]
370
+ run.postmortem_status = pm.status
371
+ run.postmortem_override = pm.verdict_override
372
+ run.postmortem_verdict_override = pm.verdict_override
373
+ run.postmortem_author = pm.author
374
+ run.postmortem_path = rel_path
375
+ run.postmortem_hypothesis_status = pm.hypothesis_status
376
+ run.postmortem_has_anomalies = any(v and str(v).lower() != "none" for v in getattr(pm, "anomalies", {}).values())
377
+ run.postmortem_summary = pm.summary
378
+ run.postmortem_asset_links = json.dumps(pm.asset_links)
379
+ if pm.verdict_override != "none":
380
+ run.outcome = pm.verdict_override
381
+
281
382
  # Collect output metadata
282
383
  output_metadata = []
283
384
  if run.output_paths:
@@ -295,8 +396,10 @@ def compact(catalog_dir: Path) -> CompactResult:
295
396
  id, project_slug, command, argv, git_hash, git_branch,
296
397
  git_dirty, timestamp, duration_s, exit_code, status,
297
398
  output_paths, tags, schema_version, slurm_job_id, hostname, metadata, outcome, output_metadata,
298
- sidecar_sha256, sidecar_path, parent_run_id, agent_mode, sidecar_mode, outcome_is_residual, skill_sha256, campaign_id
299
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
399
+ sidecar_sha256, sidecar_path, parent_run_id, agent_mode, sidecar_mode, outcome_is_residual, skill_sha256, campaign_id,
400
+ script_sha256, postmortem_status, postmortem_override, postmortem_verdict_override, postmortem_author, postmortem_path,
401
+ postmortem_hypothesis_status, postmortem_has_anomalies, postmortem_summary, postmortem_asset_links
402
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
300
403
  """,
301
404
  [
302
405
  run.id,
@@ -326,6 +429,16 @@ def compact(catalog_dir: Path) -> CompactResult:
326
429
  run.outcome_is_residual,
327
430
  run.skill_sha256,
328
431
  run.campaign_id,
432
+ run.script_sha256,
433
+ run.postmortem_status,
434
+ run.postmortem_override,
435
+ run.postmortem_verdict_override,
436
+ run.postmortem_author,
437
+ run.postmortem_path,
438
+ run.postmortem_hypothesis_status,
439
+ run.postmortem_has_anomalies,
440
+ run.postmortem_summary,
441
+ run.postmortem_asset_links,
329
442
  ],
330
443
  )
331
444
 
@@ -21,7 +21,9 @@ def default_catalog_dir() -> Path:
21
21
  return Path.home() / ".bth" / "catalog"
22
22
 
23
23
 
24
- def find_project_config(start: Path = Path.cwd()) -> Path | None:
24
+ def find_project_config(start: Path | None = None) -> Path | None:
25
+ if start is None:
26
+ start = Path.cwd()
25
27
  for directory in [start, *start.parents]:
26
28
  candidate = directory / ".bth.toml"
27
29
  if candidate.exists():
@@ -814,6 +814,134 @@ def mcp_campaign_conclude_tool(
814
814
  )
815
815
 
816
816
 
817
+ @app.tool()
818
+ def postmortem_scaffold(
819
+ run_id: str,
820
+ catalog_dir: str | None = None,
821
+ workspace_root: str | None = None,
822
+ ) -> dict:
823
+ """Scaffold a new postmortem TOML template for the given run ID.
824
+
825
+ Returns the path where the template was written.
826
+ """
827
+ import shlex
828
+ from bathos.query import get_run as _get_run
829
+
830
+ cat_dir = _get_catalog_dir(catalog_dir)
831
+ run = _get_run(run_id, cat_dir)
832
+ if not run:
833
+ return {"error": f"Run '{run_id}' not found"}
834
+
835
+ ws = Path(workspace_root) if workspace_root else Path.cwd()
836
+ config_path = find_project_config(ws)
837
+ if config_path:
838
+ ws = load_project_config(config_path).root
839
+
840
+ # Derive script path from command
841
+ parts = shlex.split(run.command)
842
+ script_path = None
843
+ for part in parts:
844
+ p = Path(part)
845
+ if p.suffix == ".py":
846
+ script_path = ws / p
847
+ break
848
+ if not script_path:
849
+ script_path = ws / "run.py"
850
+
851
+ script_path.parent.mkdir(parents=True, exist_ok=True)
852
+ postmortem_path = script_path.parent / f"{script_path.name}.{run_id}.bth.postmortem.toml"
853
+
854
+ toml_content = f"""run_id = "{run_id}"
855
+
856
+ [postmortem]
857
+ hypothesis_status = "unassigned"
858
+ summary = ""
859
+ unexpected_observations = ""
860
+ root_cause = ""
861
+ verdict_override = "none"
862
+ next_steps = ""
863
+ author = ""
864
+ status = "draft"
865
+
866
+ [asset_links]
867
+ """
868
+ postmortem_path.write_text(toml_content)
869
+ return {"path": str(postmortem_path), "run_id": run_id}
870
+
871
+
872
+ @app.tool()
873
+ def postmortem_validate(
874
+ path: str,
875
+ workspace_root: str | None = None,
876
+ strict_files: bool = False,
877
+ ) -> dict:
878
+ """Validate a postmortem TOML file.
879
+
880
+ Returns {'ok': True} on success or {'ok': False, 'errors': [...]} on failure.
881
+ """
882
+ from bathos.postmortem import parse_postmortem, validate_postmortem
883
+
884
+ pm_path = Path(path)
885
+ if not pm_path.exists():
886
+ return {"ok": False, "errors": [f"File not found: {path}"]}
887
+
888
+ try:
889
+ pm = parse_postmortem(pm_path)
890
+ except Exception as e:
891
+ return {"ok": False, "errors": [f"Parse error: {e}"]}
892
+
893
+ ws = Path(workspace_root) if workspace_root else Path.cwd()
894
+ config_path = find_project_config(ws)
895
+ if config_path:
896
+ ws = load_project_config(config_path).root
897
+
898
+ result = validate_postmortem(pm, workspace_root=ws, strict_files=strict_files)
899
+ if result.ok:
900
+ return {"ok": True, "run_id": pm.run_id, "hypothesis_status": pm.hypothesis_status}
901
+ return {"ok": False, "errors": [e.message for e in result.errors]}
902
+
903
+
904
+ @app.tool()
905
+ def postmortem_get(
906
+ run_id: str,
907
+ workspace_root: str | None = None,
908
+ ) -> dict:
909
+ """Retrieve postmortem data for the given run ID by scanning for matching TOML files.
910
+
911
+ Returns the parsed postmortem fields or an error dict if not found.
912
+ """
913
+ from bathos.postmortem import parse_postmortem
914
+
915
+ ws = Path(workspace_root) if workspace_root else Path.cwd()
916
+ config_path = find_project_config(ws)
917
+ if config_path:
918
+ ws = load_project_config(config_path).root
919
+
920
+ for pm_file in ws.rglob("*.bth.postmortem.toml"):
921
+ try:
922
+ pm = parse_postmortem(pm_file)
923
+ if pm.run_id == run_id:
924
+ return {
925
+ "run_id": pm.run_id,
926
+ "status": pm.status,
927
+ "hypothesis_status": pm.hypothesis_status,
928
+ "verdict_override": pm.verdict_override,
929
+ "summary": pm.summary,
930
+ "root_cause": pm.root_cause,
931
+ "unexpected_observations": pm.unexpected_observations,
932
+ "next_steps": pm.next_steps,
933
+ "author": pm.author,
934
+ "asset_links": pm.asset_links,
935
+ "anomalies": pm.anomalies,
936
+ "refutation_criteria_met": pm.refutation_criteria_met,
937
+ "path": str(pm_file),
938
+ }
939
+ except Exception:
940
+ continue
941
+
942
+ return {"error": f"No postmortem found for run_id '{run_id}'"}
943
+
944
+
817
945
  def mcp_server():
818
946
  """Entry point for MCP server (stdio transport).
819
947
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from dataclasses import dataclass
4
- from datetime import datetime, UTC
4
+ from datetime import UTC, datetime
5
5
  from pathlib import Path
6
6
 
7
7
  import pyarrow as pa