-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathClearLog.bat
More file actions
135 lines (121 loc) · 3.47 KB
/
Copy pathClearLog.bat
File metadata and controls
135 lines (121 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@echo off
setlocal EnableExtensions EnableDelayedExpansion
rem Clears diagnostic logs and disposable run artifacts under the active memories root.
rem Node memory, archives, runtime state, configuration, and user-created assets are preserved.
cd /d "%~dp0"
set "MEMORIES_ROOT=%CD%\memories"
set "DRY_RUN=0"
:parse_args
if "%~1"=="" goto args_parsed
if /I "%~1"=="--root" (
if "%~2"=="" (
echo [ERROR] --root requires a directory path.
exit /b 2
)
set "MEMORIES_ROOT=%~2"
shift
shift
goto parse_args
)
if /I "%~1"=="--dry-run" set "DRY_RUN=1"
if /I "%~1"=="/dry-run" set "DRY_RUN=1"
shift
goto parse_args
:args_parsed
for %%I in ("%MEMORIES_ROOT%") do set "MEMORIES_ROOT=%%~fI"
if not exist "%MEMORIES_ROOT%\" (
echo [ERROR] memories folder does not exist: "%MEMORIES_ROOT%"
exit /b 2
)
for %%I in ("%MEMORIES_ROOT%\..") do set "PARENT_ROOT=%%~fI"
if /I "%PARENT_ROOT%"=="%MEMORIES_ROOT%" (
echo [ERROR] refusing to clear logs from a filesystem root: "%MEMORIES_ROOT%"
exit /b 2
)
set /a MATCHED=0
set /a DELETED=0
set /a FAILED=0
call :scan_pattern "runtime_events.jsonl"
call :scan_pattern "runtime_events.jsonl.lock"
call :scan_pattern "runtime.events.jsonl"
call :scan_pattern "runtime.events.jsonl.lock"
call :scan_pattern "runner.events.jsonl"
call :scan_pattern "runner.events.jsonl.lock"
call :scan_pattern "responses_payloads.jsonl"
call :scan_pattern "responses_payloads.jsonl.*.bak"
call :scan_node_files
call :scan_pattern "log.txt"
call :scan_http_debug
call :scan_named_directories "tasks"
call :scan_named_directories "tool_artifacts"
if "%DRY_RUN%"=="1" (
echo Dry run complete. Matched !MATCHED! log files.
exit /b 0
)
echo Cleared !DELETED! log files. Failed !FAILED! files. Matched !MATCHED! files.
if !FAILED! GTR 0 exit /b 1
exit /b 0
:scan_pattern
echo [SCAN] %~1
for /R "%MEMORIES_ROOT%" %%F in (%~1) do (
if exist "%%~fF" if not exist "%%~fF\" call :process_file "%%~fF"
)
exit /b 0
:scan_node_files
echo [SCAN] node runtime history
for /D %%G in ("%MEMORIES_ROOT%\*") do (
for /D %%N in ("%%~fG\*") do (
for %%L in (
"context_artifacts.jsonl"
"context_artifacts.jsonl.lock"
"agent_context_history.json"
"agent_turn_context.json"
"analysis_verification.json"
"analysis_report.md"
"analysis_report_appendix.md"
"task_direction.json"
"task_direction.json.lock"
) do (
if exist "%%~fN\%%~L" call :process_file "%%~fN\%%~L"
)
)
)
exit /b 0
:scan_http_debug
set "DEBUG_ROOT=%MEMORIES_ROOT%\_http_debug"
echo [SCAN] _http_debug
if not exist "%DEBUG_ROOT%\" exit /b 0
for /R "%DEBUG_ROOT%" %%F in (*) do (
if exist "%%~fF" if not exist "%%~fF\" call :process_file "%%~fF"
)
if "%DRY_RUN%"=="0" rmdir /S /Q "%DEBUG_ROOT%" 2>nul
exit /b 0
:scan_named_directories
echo [SCAN] %~1 directories
for /D /R "%MEMORIES_ROOT%" %%D in (%~1) do (
if exist "%%~fD\" call :process_directory "%%~fD"
)
exit /b 0
:process_directory
for /R "%~1" %%F in (*) do (
if exist "%%~fF" if not exist "%%~fF\" call :process_file "%%~fF"
)
if "%DRY_RUN%"=="0" (
rmdir /S /Q "%~1" 2>nul
if exist "%~1\" (
set /a FAILED+=1
echo [ERROR] Failed to delete directory: %~1
)
)
exit /b 0
:process_file
set /a MATCHED+=1
if "%DRY_RUN%"=="1" exit /b 0
del /F /Q /A "%~1" >nul 2>&1
if errorlevel 1 (
set /a FAILED+=1
echo [ERROR] Failed to delete: %~1
) else (
set /a DELETED+=1
)
exit /b 0