Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions .github/workflows/context-snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Context Snapshot (mARCHCode)

on:
Expand All @@ -22,15 +21,19 @@ jobs:
python-version: "3.11"

- name: Install deps
run: pip install pyyaml
run: |
python -m pip install --upgrade pip
python -m pip install pyyaml

- name: Create dirs
run: mkdir -p scripts .archcode
run: |
mkdir -p scripts .archcode

- name: Write context_snapshot.py
shell: bash
run: |
cat > scripts/context_snapshot.py <<'PY'
#!/usr/bin/env python3
from __future__ import annotations
"""
Minimal context snapshot (stable)
Expand Down Expand Up @@ -298,7 +301,7 @@ jobs:
- name: Generate HTML page + true TiddlyWiki .tid (no truncation)
shell: bash
run: |
python - <<'PY'
cat > .archcode/_context_snapshot_html_builder.py <<'PY'
import yaml, html, sys, json
from pathlib import Path
from datetime import datetime
Expand Down Expand Up @@ -332,24 +335,20 @@ jobs:
</style>
"""

# ---- build the HTML *fragment* (for TiddlyWiki) ----
frag = []
frag.append(f"<h1>Context Snapshot — {proj or '—'}</h1>")

# metadata
frag.append("<div class='box'><h2>Métadonnées</h2><ul class='meta'>")
for k in ("root","generated_at","python","platform","files_count","py_files_count","ignored_dirs"):
v = meta.get(k, "")
if isinstance(v, (list, tuple)): v = ", ".join(map(str, v))
frag.append(f"<li><strong>{html.escape(str(k))}</strong>: {html.escape(str(v))}</li>")
frag.append("</ul></div>")

# tree
frag.append("<div class='box'><h2>Arbre du projet</h2><pre>")
frag.append(html.escape(s.get("tree","") or ""))
frag.append("</pre></div>")

# files
files = s.get("files") or []
frag.append(f"<div class='box'><h2>Fichiers ({len(files)})</h2>")
for f in files:
Expand All @@ -371,7 +370,7 @@ jobs:

if defs:
frag.append(f"<div><strong>Defs ({ndefs})</strong><ul>")
for d in defs: # pas de limite: on affiche tout
for d in defs:
q = d.get("qualname","")
ln = d.get("lineno","")
params = d.get("params") or []
Expand All @@ -395,29 +394,24 @@ jobs:
frag.append(li)
frag.append("</ul></div>")
frag.append("</details>")
frag.append("</div>") # end files
frag.append("</div>")

fragment_html = CSS + "\n" + "\n".join(frag)

# ---- write standalone HTML page ----
full_html = "<!doctype html>\n<html><head><meta charset='utf-8'><title>Context Snapshot — %s</title></head><body>%s</body></html>" % (proj, fragment_html)
out_html.write_text(full_html, encoding="utf-8")

# ---- write true TiddlyWiki .tid ----
# TiddlyWiki single-tiddler format: header fields, blank line, then content.
# We store the *fragment* only (no <html> wrapper), as 'text/html' type.
def tw_timestamp(dt):
# YYYYMMDDhhmmssmmm (UTC)
return dt.strftime("%Y%m%d%H%M%S") + f"{dt.microsecond//1000:03d}"

now = datetime.utcnow()
title = f"Context Snapshot — {meta.get('project') or '-'}"
header = [
f"title: {title}",
"tags: mARCHCode Snapshot",
f"created: {tw_timestamp(now)}",
f"modified: {tw_timestamp(now)}",
"type: text/html",
f"title: {title}",
"tags: mARCHCode Snapshot",
f"created: {tw_timestamp(now)}",
f"modified: {tw_timestamp(now)}",
"type: text/html",
]
out_tid.write_text("\n".join(header) + "\n\n" + fragment_html, encoding="utf-8")

Expand Down
Loading