---
name: check-session
description: >
  (What) Read-only session status — counters, active/pending WPs.
  (When) After /init-session, or anytime human asks for status.
  (Why) Project state visibility. (How) alarm.md + work-plan/ + git log → status report.
metadata:
  author: David Seo of GEM².AI
  version: 11.0.0-draft
allowed-tools:
  - Read
  - Bash(git *)
  - Bash(date *)
---

(* TPMN SKILL — check-session *)

(* === Input === *)
A ≜ [
  project_slug: 𝕊,
  session_started_at: 𝕊,              (* ISO8601 — from init-session's alarm.md timestamp *)
  alarm_path: ".gem-squared/alarm.md",
  work_plan_dir: ".gem-squared/work-plan/"
]

(* === Output === *)
B ≜ [
  project_slug: 𝕊,
  checked_at: 𝕊,                      (* ISO8601 — when this check was performed *)
  counters: 𝕊,                        (* e.g., "PENDING:2 | IN_PROGRESS:1 | COMPLETED:55 | DECOMPOSED:0 | ABORTED:0" *)
  active_works: Seq(𝕊)?,              (* WP titles currently IN_PROGRESS *)
  pending_works: Seq(𝕊)?,             (* WP titles waiting to start *)
  recent_commits: Seq(𝕊)?             (* last 5 git commits — session context *)
]

(* === Precondition === *)
P ≜ project_slug ≠ ⊥
    ∧ alarm_path exists

(* === Transform === *)
F ≜ <<
  1. Read local state:
       Read alarm.md → parse STATUS counter line.
       Scan work-plan/*.md → extract STATUS from each WP file header.
       Classify: active_works (IN_PROGRESS), pending_works (PENDING).
       git log --oneline -5 → recent_commits (session context for human).
  2. Output B as human-readable summary:
       Show: counters, active_works, pending_works, recent_commits.
>>

(* === Constraint === *)
CONSTRAINT ≜ [
  ⊢ Strictly read-only — NEVER modifies any file,
  ⊢ NEVER starts or resumes work — status reporting only
]

(* === Invariant === *)
INV ≜ [
  ⊢ Zero side effects — filesystem unchanged after execution,
  ⊢ Output is current snapshot — no caching between invocations,
  ⊢ Output is self-sufficient — human can make routing decisions from local state alone,
  ⊢ git log provides session context
]

(* === Post-Execution Routing === *)
Routing ≜ [
  active_works ≠ ∅     → /proceed-work (resume interrupted work),
  pending_works ≠ ∅    → ask human which to proceed,
  all_clear = ⊤        → /plan-work or ask human for new work
]
