Skip to content

Commit 7db1ad7

Browse files
committed
chatlog: add --subject and --open; tasks prompt subject and open file; pre-push clipboard guard (CID + preview containment); keep clipboard auto-append off by default
1 parent 6925381 commit 7db1ad7

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

.githooks/pre-push

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,42 @@ append_from_file() {
3232

3333
append_from_clipboard() {
3434
if command -v pbpaste >/dev/null 2>&1 || command -v xclip >/dev/null 2>&1 || command -v xsel >/dev/null 2>&1; then
35-
bash "$APPENDER" --from-clipboard --label "$LABEL (Clipboard)" || true
36-
git add "$CHAT_FILE" || true
35+
TMP_CLIP=$(mktemp)
36+
# capture clipboard and normalize
37+
if command -v pbpaste >/dev/null 2>&1; then
38+
pbpaste | tr -d '\r' > "$TMP_CLIP"
39+
elif command -v xclip >/dev/null 2>&1; then
40+
xclip -o -selection clipboard | tr -d '\r' > "$TMP_CLIP"
41+
else
42+
xsel --clipboard --output | tr -d '\r' > "$TMP_CLIP"
43+
fi
44+
45+
if [[ -s "$TMP_CLIP" ]]; then
46+
# Skip if exact CID already present (idempotent path)
47+
if command -v shasum >/dev/null 2>&1; then
48+
CID=$(shasum -a 256 "$TMP_CLIP" | awk '{print $1}')
49+
elif command -v openssl >/dev/null 2>&1; then
50+
CID=$(openssl dgst -sha256 -r "$TMP_CLIP" | awk '{print $1}')
51+
else
52+
CID=""
53+
fi
54+
if [[ -n "$CID" && -f "$CHAT_FILE" ]] && grep -q "^\[CID:$CID\]$" "$CHAT_FILE"; then
55+
echo "[pre-push] Clipboard content already recorded (CID:$CID); skipping."
56+
rm -f "$TMP_CLIP"; return
57+
fi
58+
# Tail containment check: if a preview chunk is already in chatlog, skip
59+
if [[ -f "$CHAT_FILE" ]]; then
60+
PREVIEW=$(head -c 256 "$TMP_CLIP")
61+
if [[ -n "$PREVIEW" ]] && grep -Fq -- "$PREVIEW" "$CHAT_FILE"; then
62+
echo "[pre-push] Clipboard content appears already present in chatlog; skipping."
63+
rm -f "$TMP_CLIP"; return
64+
fi
65+
fi
66+
# Append from file to avoid re-reading clipboard in appender
67+
bash "$APPENDER" --from-file "$TMP_CLIP" --label "$LABEL (Clipboard)" || true
68+
git add "$CHAT_FILE" || true
69+
fi
70+
rm -f "$TMP_CLIP" || true
3771
fi
3872
}
3973

.vscode/tasks.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@
66
"label": "Append Chatlog (Clipboard)",
77
"type": "shell",
88
"command": "bash",
9-
"args": ["tools/append-chatlog.sh", "--from-clipboard", "--commit"],
9+
"args": [
10+
"tools/append-chatlog.sh",
11+
"--from-clipboard",
12+
"--label",
13+
"${input:chatlogLabel}",
14+
"--subject",
15+
"${input:chatlogSubject}",
16+
"--open"
17+
],
1018
"problemMatcher": []
1119
},
1220
{
1321
"label": "Append Chatlog (Stdin)",
1422
"type": "shell",
1523
"command": "bash",
16-
"args": ["-lc", "tools/append-chatlog.sh --commit"],
24+
"args": [
25+
"-lc",
26+
"tools/append-chatlog.sh --label '${input:chatlogLabel}' --subject '${input:chatlogSubject}' --open"
27+
],
1728
"options": {
1829
"presentation": {
1930
"reveal": "always",
@@ -46,7 +57,8 @@
4657
"--label",
4758
"${input:chatlogLabel}",
4859
"--subject",
49-
"${input:chatlogSubject}"
60+
"${input:chatlogSubject}",
61+
"--open"
5062
],
5163
"problemMatcher": []
5264
},
@@ -61,7 +73,8 @@
6173
"--label",
6274
"${input:chatlogLabel}",
6375
"--subject",
64-
"${input:chatlogSubject}"
76+
"${input:chatlogSubject}",
77+
"--open"
6578
],
6679
"problemMatcher": []
6780
},
@@ -71,7 +84,7 @@
7184
"command": "bash",
7285
"args": [
7386
"-lc",
74-
"tools/append-chatlog.sh --from-clipboard --label '${input:chatlogLabel}' --subject '${input:chatlogSubject}' && (command -v code >/dev/null && code -r docs/chatlog.md || open docs/chatlog.md)"
87+
"tools/append-chatlog.sh --from-clipboard --label '${input:chatlogLabel}' --subject '${input:chatlogSubject}' --open"
7588
],
7689
"problemMatcher": []
7790
},

tools/CHATLOG_USAGE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Each append block adds:
3838
3939
Appended on 2025-09-06 16:55:00 UTC
4040
[CID:<sha256>] [LABEL:<optional>]
41+
Subject: <optional subject when provided>
4142
4243
<pasted content>
4344
```
@@ -67,12 +68,15 @@ bash tools/install-hooks.sh
6768

6869
Behavior:
6970
- If `docs/pending_chat_append.txt` exists and has content, it is appended (label “Pre-push”) and then removed.
70-
- If `AUTO_APPEND_CLIPBOARD=1` is set in `.chatlogrc` (repo root) or env, the clipboard is appended (label “Pre-push (Clipboard)”).
71+
- If `AUTO_APPEND_CLIPBOARD=1` is set in `.chatlogrc` (repo root) or env, the clipboard is appended (label “Pre-push (Clipboard)”) with safety checks:
72+
- Skips if the clipboard content’s CID already exists in the chatlog.
73+
- Skips if a 256‑char preview is already present in the chatlog (tail containment check).
7174
- After appending, the hook stages `docs/chatlog.md` so it’s included in your push if committed.
7275

7376
Notes:
7477
- Hooks are local; they don’t travel with pushes. The installer sets `core.hooksPath=.githooks` in your local repo config.
7578
- The hook is non-interactive and safe to ignore if you don’t use the pending/clipboard features.
79+
- Recommended defaults: Use queued file appends or the VS Code tasks; keep clipboard auto‑append disabled unless you need it.
7680

7781
## Notes & Recommendations
7882

tools/append-chatlog.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ TITLE="iAvro Forgiving Typing Project — Chat Log"
1313
FORCE_APPEND=0
1414
LABEL=""
1515
SUBJECT=""
16+
OPEN_AFTER=0
1617

1718
usage() {
1819
cat <<EOF
19-
Usage: $0 [--from-file <path> | --from-clipboard] [--label <text>] [--subject <text>] [--commit] [--force]
20+
Usage: $0 [--from-file <path> | --from-clipboard] [--label <text>] [--subject <text>] [--open] [--commit] [--force]
2021
2122
Examples:
2223
# Append from clipboard (copy chat text first)
@@ -44,6 +45,8 @@ while [[ $# -gt 0 ]]; do
4445
LABEL="${2:-}"; shift 2;;
4546
--subject)
4647
SUBJECT="${2:-}"; shift 2;;
48+
--open)
49+
OPEN_AFTER=1; shift;;
4750
--help|-h)
4851
usage; exit 0;;
4952
*)
@@ -138,3 +141,12 @@ if [[ $DO_COMMIT -eq 1 ]]; then
138141
echo "Not a git repo; skipping commit." >&2
139142
fi
140143
fi
144+
145+
# Optionally open the chatlog for review (interactive flows only)
146+
if [[ $OPEN_AFTER -eq 1 ]]; then
147+
if command -v code >/dev/null 2>&1; then
148+
code -r "$FILE" || true
149+
elif [[ "$OSTYPE" == darwin* ]]; then
150+
open "$FILE" || true
151+
fi
152+
fi

0 commit comments

Comments
 (0)