opencode-claude-memory 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -956,6 +956,80 @@ rollback_consolidation_lock() {
956
956
  set_file_mtime_secs "$path" "$prior_mtime"
957
957
  }
958
958
 
959
+ cleanup_forked_sessions() {
960
+ local before_json="$1"
961
+
962
+ if ! command -v python3 >/dev/null 2>&1; then
963
+ return 0
964
+ fi
965
+
966
+ local after_json
967
+ after_json=$(get_session_list_json 10 2>/dev/null || true)
968
+
969
+ if [ -z "$before_json" ] || [ -z "$after_json" ]; then
970
+ return 0
971
+ fi
972
+
973
+ local fork_ids
974
+ fork_ids=$(python3 - "$before_json" "$after_json" "$WORKING_DIR" "$PROJECT_SCOPE_DIR" <<'PY'
975
+ import json
976
+ import os
977
+ import sys
978
+
979
+ def parse(raw):
980
+ try:
981
+ data = json.loads(raw)
982
+ return data if isinstance(data, list) else []
983
+ except Exception:
984
+ return []
985
+
986
+ before_raw, after_raw, workdir, project_dir = sys.argv[1:5]
987
+ before = parse(before_raw)
988
+ after = parse(after_raw)
989
+
990
+ before_ids = {item.get("id") for item in before if item.get("id")}
991
+ workdir = os.path.realpath(workdir)
992
+ project_dir = os.path.realpath(project_dir)
993
+
994
+ for item in after:
995
+ sid = item.get("id", "")
996
+ if not sid or sid in before_ids:
997
+ continue
998
+ directory = item.get("directory", "")
999
+ if not directory:
1000
+ continue
1001
+ d = os.path.realpath(directory)
1002
+ if d in (workdir, project_dir):
1003
+ print(sid)
1004
+ PY
1005
+ ) || return 0
1006
+
1007
+ while IFS= read -r fork_id; do
1008
+ [ -n "$fork_id" ] || continue
1009
+ if "$REAL_OPENCODE" session delete "$fork_id" >/dev/null 2>&1; then
1010
+ log "Cleaned up forked session $fork_id"
1011
+ fi
1012
+ done <<< "$fork_ids"
1013
+ }
1014
+
1015
+ session_has_conversation() {
1016
+ local session_id="$1"
1017
+ local transcript_file
1018
+ transcript_file="$(get_transcripts_dir)/${session_id}.jsonl"
1019
+
1020
+ if [ -f "$transcript_file" ]; then
1021
+ local line_count
1022
+ line_count=$(wc -l < "$transcript_file")
1023
+ # Empty sessions have at most 1 line (the initial user entry with no content).
1024
+ # Real sessions have 3+ lines (user + tool_use + tool_result at minimum).
1025
+ [ "$line_count" -gt 1 ]
1026
+ return $?
1027
+ fi
1028
+
1029
+ # Transcript not found — assume content exists to avoid skipping a valid session.
1030
+ return 0
1031
+ }
1032
+
959
1033
  run_extraction_if_needed() {
960
1034
  local session_id="$1"
961
1035
  local memory_written_during_session="$2"
@@ -985,6 +1059,9 @@ run_extraction_if_needed() {
985
1059
  fi
986
1060
  cmd+=("$EXTRACT_PROMPT")
987
1061
 
1062
+ local pre_fork_json
1063
+ pre_fork_json=$(get_session_list_json 5 2>/dev/null || true)
1064
+
988
1065
  if "${cmd[@]}" >> "$EXTRACT_LOG_FILE" 2>&1; then
989
1066
  log "Memory extraction completed successfully"
990
1067
  else
@@ -992,6 +1069,7 @@ run_extraction_if_needed() {
992
1069
  log "Memory extraction failed (exit code $code). Check $EXTRACT_LOG_FILE for details"
993
1070
  fi
994
1071
 
1072
+ cleanup_forked_sessions "$pre_fork_json"
995
1073
  release_simple_lock "$EXTRACT_LOCK_FILE"
996
1074
  }
997
1075
 
@@ -1043,6 +1121,9 @@ run_autodream_if_needed() {
1043
1121
  fi
1044
1122
  cmd+=("$AUTODREAM_PROMPT")
1045
1123
 
1124
+ local pre_fork_json
1125
+ pre_fork_json=$(get_session_list_json 5 2>/dev/null || true)
1126
+
1046
1127
  if "${cmd[@]}" >> "$AUTODREAM_LOG_FILE" 2>&1; then
1047
1128
  log "Auto-dream consolidation completed successfully"
1048
1129
  # Keep lock mtime at "now" to represent last consolidated timestamp.
@@ -1050,8 +1131,9 @@ run_autodream_if_needed() {
1050
1131
  local code=$?
1051
1132
  log "Auto-dream consolidation failed (exit code $code). Rolling back gate timestamp"
1052
1133
  rollback_consolidation_lock "$CONSOLIDATION_PRIOR_MTIME"
1053
- return 0
1054
1134
  fi
1135
+
1136
+ cleanup_forked_sessions "$pre_fork_json"
1055
1137
  }
1056
1138
 
1057
1139
  run_post_session_tasks() {
@@ -1093,6 +1175,13 @@ if [ -z "$session_id" ]; then
1093
1175
  exit $opencode_exit
1094
1176
  fi
1095
1177
 
1178
+ # Step 3.5: Skip if session had no real conversation (e.g. user opened TUI and exited)
1179
+ if ! session_has_conversation "$session_id"; then
1180
+ log "Session $session_id has no conversation, skipping post-session memory maintenance"
1181
+ cleanup_timestamp
1182
+ exit $opencode_exit
1183
+ fi
1184
+
1096
1185
  # Step 4: Check whether main session already wrote memory files
1097
1186
  memory_written_during_session=0
1098
1187
  if has_new_memories; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-claude-memory",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "type": "module",
5
5
  "description": "Claude Code-compatible memory compatibility layer for OpenCode — zero config, local-first, no migration",
6
6
  "main": "dist/index.js",