-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconsolidate-session.py
More file actions
executable file
·114 lines (96 loc) · 3.99 KB
/
Copy pathconsolidate-session.py
File metadata and controls
executable file
·114 lines (96 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
"""Session consolidation - close out a session and feed the brain.
Runs at session end ("good night"). Takes the session's decisions, learnings,
artifacts and pending items, and writes them into the vault: a session note,
log entries, recent.md changelog, and decision log entries (via the same
DEC-### convention as register-decision.py).
Usage:
python3 bin/consolidate-session.py \
--objective "what the session was about" \
--decisions "DEC-001|Title of decision" \
--learnings "learning one|learning two" \
--artifacts "/abs/path:what it is" \
--pending "open item|owner|deadline" \
[--vault PATH] [--dry-run]
Config:
BRAINSTACK_VAULT env var (default: ~/vault)
"""
import argparse
import os
import re
import sys
from datetime import datetime
from pathlib import Path
def get_vault(args) -> Path:
return Path(args.vault or os.environ.get("BRAINSTACK_VAULT", "~/vault")).expanduser()
def append(path: Path, text: str):
with path.open("a", encoding="utf-8") as f:
f.write(text)
def main():
ap = argparse.ArgumentParser(description="Session-end consolidation")
ap.add_argument("--objective", default="", help="session objective")
ap.add_argument("--decisions", default="", help="pipe-separated 'DEC-ID|title' items")
ap.add_argument("--learnings", default="", help="pipe-separated learnings")
ap.add_argument("--artifacts", default="", help="pipe-separated 'path:description' items")
ap.add_argument("--pending", default="", help="pipe-separated 'item|owner|deadline' items")
ap.add_argument("--vault", help="vault path (or BRAINSTACK_VAULT env)")
ap.add_argument("--dry-run", action="store_true")
args = ap.parse_args()
vault = get_vault(args)
if not vault.is_dir():
sys.exit(f"vault not found: {vault}")
now = datetime.now()
stamp = now.strftime("%Y-%m-%d %H:%M")
day = now.strftime("%Y-%m-%d")
# Build the session note
note = [f"# Session - {day}\n"]
if args.objective:
note.append(f"## Objective\n{args.objective}\n")
if args.learnings:
note.append("## Learnings")
for l in args.learnings.split("|"):
note.append(f"- {l.strip()}")
note.append("")
if args.decisions:
note.append("## Decisions")
for d in args.decisions.split("|"):
d = d.strip()
did, _, title = d.partition(" ")
note.append(f"- [[{did}]] {title}")
note.append("")
if args.pending:
note.append("## Pending")
for p in args.pending.split("|"):
parts = [x.strip() for x in p.split(",")]
item = parts[0] if parts else ""
owner = parts[1] if len(parts) > 1 else "?"
deadline = parts[2] if len(parts) > 2 else "?"
note.append(f"- [ ] {item} (owner: {owner}, by: {deadline})")
note.append("")
if args.artifacts:
note.append("## Artifacts")
for a in args.artifacts.split("|"):
path, _, desc = a.partition(":")
note.append(f"- `{path.strip()}` - {desc.strip()}")
note.append("")
session_dir = vault / "01-Wiki" / "Meeting-Notes"
session_file = session_dir / f"{day}-session.md"
body = "\n".join(note)
if args.dry_run:
print(f"[dry-run] would write {session_file}\n{body}")
return
session_dir.mkdir(parents=True, exist_ok=True)
if session_file.exists():
# Merge: only append if this is a different session (multi-session days)
append(session_file, "\n---\n\n" + body)
else:
session_file.write_text(body, encoding="utf-8")
# Log + changelog
append(vault / "log.md",
f"- **{stamp}** | Session consolidated: [[{day}-session]]\n")
recent = vault / "01-Wiki" / "now" / "recent.md"
if recent.exists():
append(recent, f"- **{stamp}** | Session consolidated: [[{day}-session]]\n")
print(f"session consolidated -> {session_file.relative_to(vault)}")
if __name__ == "__main__":
main()