# SKILL — cowork-session-writeback

## Purpose

Auto-append a session summary to `01_Daily/{today}.md` at the end of every Cowork (or Claude Code) session. Closes the gap where manual daily-note appends per AI Team Protocol get missed when sessions end abruptly.

**Adopted from Hasibul Khan's `07 - Chat Diary/` auto-summarisation pattern per [[_System/Audits/Friend-Vault-Audit-2026-05-06]] Section 5 — "Hasibul → Rocky: auto-saved Chat Diary".**

## Trigger

Three trigger modes — Rocky chooses based on what his Cowork environment supports:

1. **Session-end hook** (preferred — env-dependent) — Cowork emits an end-of-session signal; this skill listens and writes back automatically. Requires Cowork-side hook support.
2. **Explicit invocation** — Rocky says "wrap this session" / "write back" / "log this"; skill runs immediately. Always available, manual.
3. **Scheduled curator pass** — Cowork's scheduled curator runs every N hours; if a session has been active and hasn't logged in `01_Daily/{today}.md`, this skill drafts an entry and queues it for Rocky's review. Lower fidelity than 1 or 2.

**Until Rocky wires trigger 1, run via 2 or 3.**

## Inputs

Required (auto-detected from session context):
- `agent` — the agent's name (e.g. `cowork`, `cowork-lfcs`, `claude-code-coo`, `claude-code-opsman`)
- `session_start_iso` — when the session began
- `session_end_iso` — when the session ended (or "now" for live invocation)
- `decisions_made` — array of decisions made this session (extracted from chat history)
- `blockers_hit` — array of blockers + current workarounds
- `insights` — offhand observations worth keeping
- `action_items` — what Rocky should do next
- `resume_notes` — what would be needed if Rocky picked this up in a month

Optional:
- `project_scope` — if the session work clearly belongs to a project (`10_RateRight`, `11_OpsMan_LFCS`, etc.) — drives whether to also append to `{project}/_Brain/_Log.md`
- `linked_files` — paths of files created or modified during the session

## Behaviour

1. **Determine today's daily note path:** `01_Daily/{YYYY-MM-DD}.md` (today in AEST per Rocky's vault convention).
2. **Check if daily note exists:**
   - If not, create from `_System/Templates/Daily.md` template.
   - If yes, prepare to append.
3. **Compose entry under standard heading:** `## HH:MM — {agent} — {short title}`. Time = session-end time (HH:MM AEST).
4. **Body content** (per `_System/CLAUDE.md` write protocol — terse, bullets, past tense):
   - **Decisions made (and why)** — bullets
   - **Blockers hit (and current workaround)** — bullets
   - **Insights / offhand thoughts worth keeping** — bullets
   - **Action items** — imperative bullets
   - **Resume notes** — what's needed to pick this up cold
5. **Append to daily note** — never edit prior entries (append-only hard rule).
6. **If `project_scope` set:** also append a one-liner to `{project}/_Brain/_Log.md` per AI Team Protocol write protocol:
   ```
   - YYYY-MM-DD HH:MM — {agent} — {one-line summary} → [[Daily/{today}#HH:MM]]
   ```
7. **Commit + push** per AI Team Protocol commit protocol:
   ```
   {agent}: {short summary}
   ```
8. **Output to user:** confirmation with paths written + commit hash.

## Files to read (in order)

```
HQ-Vault/_System/CLAUDE.md                   ← AI Team Protocol (write protocol section)
HQ-Vault/_System/Templates/Daily.md          ← daily note skeleton (used if today's note doesn't exist)
HQ-Vault/01_Daily/{today}.md                 ← target file (read to detect existing structure)
{project}/_Brain/_Log.md                     ← optional, if project_scope set
```

## Airtable behaviour

- **Reads:** none.
- **Writes:** none.
- **Idempotency:** if invoked twice in the same session, the second call detects the most recent entry by this agent in today's daily note (within 5 min of session_end_iso) and updates it rather than appending a duplicate.

## Output format

Plain text to user (or silent if running in scheduled mode):

```
✓ Session logged
  Daily: 01_Daily/{today}.md (entry at HH:MM under {agent})
  Project log: {project}/_Brain/_Log.md (one-liner appended)
  Commit: {hash} ({agent}: {short summary})
```

## Hard rules

- **Append-only.** Never edit prior entries in `01_Daily/{today}.md` or `_Log.md`. Per `_System/CLAUDE.md` Append-only rule.
- **No content invention.** If extracting decisions/blockers/insights from chat history is uncertain, label them as "🤖 inferred" and let Rocky correct. Never confidently fabricate session content.
- **Don't overwrite the daily note's existing structure.** If a daily note has prior entries from other agents (cowork-lfcs, claude-code-coo, etc.), append your entry AFTER the most recent existing entry — never reorder.
- **Don't fire if session was empty.** If chat history reveals no actual work (just conversation, no tool calls, no decisions), skip — don't pollute the daily note with empty entries. Per `_System/CLAUDE.md`: *"Don't pad logs to look thorough. 'Nothing changed' is a valid log entry."*
- **Respect lane rules.** Per AI Team Protocol: this skill writes to daily note + project log only. Does not touch project content files. Does not touch Airtable. Does not touch other agents' logs.

## Dependencies

- `_System/Templates/Daily.md` — daily note skeleton
- `_System/CLAUDE.md` — write protocol authority
- Cowork chat-history extraction capability (decisions / blockers / insights / actions surfaced from session transcript)

## Failure modes

| Failure | Detection | Recovery |
|---|---|---|
| Today's daily note doesn't exist | Pre-check before append | Create from template, then append |
| Append-only rule violation (would edit prior entry) | Pre-check edit operation | Abort, log to `_System/Conflicts.md`, surface to Rocky |
| Empty session detected | Pre-check chat history for decisions/actions | Skip silently, no log entry |
| Git commit fails | Catch on commit | Surface to Rocky, leave write in place (uncommitted), don't retry automatically |
| Two agents writing simultaneously | Append-only files almost never conflict per AI Team Protocol | If conflict: pull, merge (line-level), retry — both agents' content survives |
| Trigger 1 (session-end hook) not yet wired | Skill runs in trigger 2 (explicit) or 3 (scheduled) instead | Document in user-facing prompt: "Auto-trigger pending env wiring; running on explicit invocation" |

## Status (as of 2026-05-06)

- **Skill scaffolded:** SKILL.md written
- **Trigger 1 (session-end hook):** ⚠ env wiring required — Cowork-side hook support TBC
- **Trigger 2 (explicit):** ✓ available — invoke via "wrap this session" / "log this"
- **Trigger 3 (scheduled curator):** ⚠ depends on Cowork curator schedule — currently runs early morning + evening per `_System/CLAUDE.md` Lane rules
- **Chat-history extraction:** TBC — relies on Cowork providing structured access to session transcript. Workaround: Rocky pastes session summary explicitly when invoking trigger 2.

## Next steps for Rocky

1. **Confirm trigger 2 (explicit) works** — invoke this skill end of next session by saying "wrap this session" or similar
2. **Investigate trigger 1 (session-end hook)** — does Cowork's environment expose a session-end signal? If yes, wire to this skill
3. **Schedule trigger 3** — add to Cowork's curator pass cadence (early morning + evening per existing pattern)
4. **Test against the regression scenarios:**
   - Empty session → no entry written ✓
   - Live session with decisions → appended correctly ✓
   - Conflict with another agent's entry → both survive ✓
   - Daily note missing → created from template ✓

## Adoption from Hasibul's pattern

Hasibul's `07 - Chat Diary/` writes one auto-summarised file per session named `YYYY-MM-DD HH-MM — Topic Summary.md`. **Difference for Rocky:** instead of one-file-per-session, append to a single daily note (`01_Daily/{today}.md`) under timestamped headings — fits Rocky's existing AI Team Protocol write protocol. Same auto-capture intent; different filing structure.
