opencode-claude-memory 1.3.0 → 1.4.0
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.
- package/README.md +4 -0
- package/bin/opencode-memory +31 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,6 +110,7 @@ The shell hook defines an `opencode()` function that delegates to `opencode-memo
|
|
|
110
110
|
6. It evaluates the auto-dream gate (default: at least 24h since last consolidation and 5 touched sessions)
|
|
111
111
|
7. If the gate passes, it runs a background consolidation pass to merge/prune memories
|
|
112
112
|
8. Maintenance runs **in the background** unless `OPENCODE_MEMORY_FOREGROUND=1`
|
|
113
|
+
9. Terminal maintenance logs are shown in foreground mode by default, or can be forced on/off with `OPENCODE_MEMORY_TERMINAL_LOG=1|0`
|
|
113
114
|
|
|
114
115
|
### Compatibility details
|
|
115
116
|
|
|
@@ -156,6 +157,7 @@ Yes. Set `OPENCODE_MEMORY_AUTODREAM=0`. You can also tune gates with:
|
|
|
156
157
|
|
|
157
158
|
- `OPENCODE_MEMORY_EXTRACT` (default `1`): set `0` to disable automatic memory extraction
|
|
158
159
|
- `OPENCODE_MEMORY_FOREGROUND` (default `0`): set `1` to run maintenance in foreground
|
|
160
|
+
- `OPENCODE_MEMORY_TERMINAL_LOG` (default `foreground-only`): set `1` to force terminal logs on, `0` to force them off
|
|
159
161
|
- `OPENCODE_MEMORY_MODEL`: override model used for extraction
|
|
160
162
|
- `OPENCODE_MEMORY_AGENT`: override agent used for extraction
|
|
161
163
|
- `OPENCODE_MEMORY_AUTODREAM` (default `1`): set `0` to disable auto-dream consolidation
|
|
@@ -170,6 +172,8 @@ Logs are written to `$TMPDIR/opencode-memory-logs/`:
|
|
|
170
172
|
- `extract-*.log`: automatic memory extraction
|
|
171
173
|
- `dream-*.log`: auto-dream consolidation
|
|
172
174
|
|
|
175
|
+
By default, terminal log lines are only printed when maintenance runs in foreground (`OPENCODE_MEMORY_FOREGROUND=1`). Background runs stay quiet unless you explicitly set `OPENCODE_MEMORY_TERMINAL_LOG=1`.
|
|
176
|
+
|
|
173
177
|
### Concurrency safety
|
|
174
178
|
|
|
175
179
|
Lock files prevent concurrent extraction/consolidation runs per project root. Stale locks are cleaned up automatically.
|
package/bin/opencode-memory
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
# Environment variables:
|
|
27
27
|
# OPENCODE_MEMORY_EXTRACT=0 — Disable post-session extraction
|
|
28
28
|
# OPENCODE_MEMORY_FOREGROUND=1 — Run maintenance in foreground (debug)
|
|
29
|
+
# OPENCODE_MEMORY_TERMINAL_LOG=1|0 — Force-enable/disable terminal logs (default: foreground only)
|
|
29
30
|
# OPENCODE_MEMORY_MODEL=... — Extraction model override
|
|
30
31
|
# OPENCODE_MEMORY_AGENT=... — Extraction agent override
|
|
31
32
|
# OPENCODE_MEMORY_AUTODREAM=0 — Disable auto-dream consolidation
|
|
@@ -164,6 +165,7 @@ REAL_OPENCODE="$(find_real_opencode)"
|
|
|
164
165
|
|
|
165
166
|
EXTRACT_ENABLED="${OPENCODE_MEMORY_EXTRACT:-1}"
|
|
166
167
|
FOREGROUND="${OPENCODE_MEMORY_FOREGROUND:-0}"
|
|
168
|
+
LOG_ENABLED="${OPENCODE_MEMORY_TERMINAL_LOG:-}"
|
|
167
169
|
EXTRACT_MODEL="${OPENCODE_MEMORY_MODEL:-}"
|
|
168
170
|
EXTRACT_AGENT="${OPENCODE_MEMORY_AGENT:-}"
|
|
169
171
|
|
|
@@ -177,6 +179,14 @@ AUTODREAM_STALE_LOCK_SECS=$((60 * 60))
|
|
|
177
179
|
|
|
178
180
|
WORKING_DIR="${OPENCODE_MEMORY_DIR:-$(pwd)}"
|
|
179
181
|
|
|
182
|
+
TMP_BASE_DIR="${TMPDIR:-/tmp}"
|
|
183
|
+
while [ "$TMP_BASE_DIR" != "/" ] && [ "${TMP_BASE_DIR%/}" != "$TMP_BASE_DIR" ]; do
|
|
184
|
+
TMP_BASE_DIR="${TMP_BASE_DIR%/}"
|
|
185
|
+
done
|
|
186
|
+
if [ -z "$TMP_BASE_DIR" ]; then
|
|
187
|
+
TMP_BASE_DIR="/"
|
|
188
|
+
fi
|
|
189
|
+
|
|
180
190
|
# Scope lock files at project root granularity (not per-subdirectory).
|
|
181
191
|
PROJECT_SCOPE_DIR="$WORKING_DIR"
|
|
182
192
|
if git -C "$WORKING_DIR" rev-parse --show-toplevel >/dev/null 2>&1; then
|
|
@@ -186,7 +196,7 @@ fi
|
|
|
186
196
|
PROJECT_KEY="$(printf '%s' "$PROJECT_SCOPE_DIR" | cksum | awk '{print $1}')"
|
|
187
197
|
|
|
188
198
|
# Lock files (prevent concurrent work on the same project)
|
|
189
|
-
LOCK_DIR="$
|
|
199
|
+
LOCK_DIR="$TMP_BASE_DIR/opencode-memory-locks"
|
|
190
200
|
mkdir -p "$LOCK_DIR"
|
|
191
201
|
EXTRACT_LOCK_FILE="$LOCK_DIR/${PROJECT_KEY}.extract.lock"
|
|
192
202
|
|
|
@@ -195,7 +205,7 @@ mkdir -p "$STATE_DIR"
|
|
|
195
205
|
CONSOLIDATION_LOCK_FILE="$STATE_DIR/${PROJECT_KEY}.consolidate-lock"
|
|
196
206
|
|
|
197
207
|
# Logs
|
|
198
|
-
LOG_DIR="$
|
|
208
|
+
LOG_DIR="$TMP_BASE_DIR/opencode-memory-logs"
|
|
199
209
|
mkdir -p "$LOG_DIR"
|
|
200
210
|
TASK_LOG_PREFIX="$(date +%Y%m%d-%H%M%S)-${PROJECT_KEY}"
|
|
201
211
|
EXTRACT_LOG_FILE="$LOG_DIR/extract-${TASK_LOG_PREFIX}.log"
|
|
@@ -287,7 +297,17 @@ EOF
|
|
|
287
297
|
# Helper Functions
|
|
288
298
|
# ============================================================================
|
|
289
299
|
|
|
300
|
+
should_log() {
|
|
301
|
+
if [ -n "$LOG_ENABLED" ]; then
|
|
302
|
+
[ "$LOG_ENABLED" = "1" ]
|
|
303
|
+
return $?
|
|
304
|
+
fi
|
|
305
|
+
|
|
306
|
+
[ "$FOREGROUND" = "1" ]
|
|
307
|
+
}
|
|
308
|
+
|
|
290
309
|
log() {
|
|
310
|
+
should_log || return 0
|
|
291
311
|
echo "[opencode-memory] $*" >&2
|
|
292
312
|
}
|
|
293
313
|
|
|
@@ -295,6 +315,15 @@ is_positive_int() {
|
|
|
295
315
|
[[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -gt 0 ]
|
|
296
316
|
}
|
|
297
317
|
|
|
318
|
+
is_bool_flag() {
|
|
319
|
+
[ "$1" = "0" ] || [ "$1" = "1" ]
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if [ -n "$LOG_ENABLED" ] && ! is_bool_flag "$LOG_ENABLED"; then
|
|
323
|
+
echo "[opencode-memory] Invalid OPENCODE_MEMORY_TERMINAL_LOG=$LOG_ENABLED, expected 0 or 1; defaulting to foreground-only logging" >&2
|
|
324
|
+
LOG_ENABLED=""
|
|
325
|
+
fi
|
|
326
|
+
|
|
298
327
|
if ! is_positive_int "$AUTODREAM_MIN_HOURS"; then
|
|
299
328
|
log "Invalid OPENCODE_MEMORY_AUTODREAM_MIN_HOURS=$AUTODREAM_MIN_HOURS, using default 24"
|
|
300
329
|
AUTODREAM_MIN_HOURS=24
|
package/package.json
CHANGED