text
stringlengths
0
1.47k
static int target_can_contain_sessions(const bof_triage_target_t *target) {
if (!target_is_directory(target)) return 0;
if (target_family_is(target, "sessions") || target_family_is(target, "history")) return 1;
return target_family_is(target, "workspace") && (target_tool_is(target, "claude_code") || target_tool_is(target, "cursor"));
}
static void scan_session_candidates(void) {
int i;
inline_memset(g_top_sessions, 0, sizeof(g_top_sessions));
inline_memset(g_session_artifact_counts, 0, sizeof(g_session_artifact_counts));
g_top_session_count = 0;
g_session_entries_scanned = 0;
g_session_scan_partial = 0;
g_session_scan_stop = 0;
for (i = 0; i < g_bof_triage_target_count && !g_session_scan_stop; i++) {
const bof_triage_target_t *target = &g_bof_triage_targets[i];
if (target_can_contain_sessions(target)) {
int j;
int seen = 0;
for (j = 0; j < i; j++) {
if (target_can_contain_sessions(&g_bof_triage_targets[j]) &&
target_tool_is(&g_bof_triage_targets[j], target->tool) &&
wide_path_compare_ci(g_bof_triage_targets[j].path, target->path) == 0) { seen = 1; break; }
}
if (!seen) walk_session_files(target->tool, target->path, 0);
}
else if (target_is_file(target) && session_file_recognized(target->tool, target->path)) {
WIN32_FIND_DATAW find_data;
HANDLE find_handle;
inline_memset(&find_data, 0, sizeof(find_data));
find_handle = KERNEL32$FindFirstFileW(target->path, &find_data);
if (find_handle != INVALID_HANDLE_VALUE) {
if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) consider_session_candidate(target->tool, target->path, &find_data);
KERNEL32$FindClose(find_handle);
} else {
g_session_scan_partial = 1;
}
}
}
}
static void record_bof_triage_target(
const char *tool,
const char *family,
const char *type,
const wchar_t *path,
int priority_tier,
const char *parser_hint,
long long size_bytes,
long long child_count,
int auto_select
) {
bof_triage_target_t *target;
if (g_bof_triage_target_count >= MAX_BOF_TRIAGE_TARGETS) {
g_bof_triage_target_overflow = 1;
return;
}
target = &g_bof_triage_targets[g_bof_triage_target_count++];
target->priority_tier = priority_tier;
target->auto_select = auto_select;
target->size_bytes = size_bytes;
target->child_count = child_count;
target->tool = tool;
target->family = family;
target->type = type;
target->parser_hint = parser_hint;
copy_wide_path(target->path, path, BL_MAX_PATH_LEN);
}
static int wide_path_token_is_boundary(wchar_t value) {
return value == 0 || value == L'/' || value == L'\\' || value == L'.' || value == L'_' || value == L'-';
}
static int wide_contains_ascii_token_ci(const wchar_t *text, const char *needle, int needle_len) {
int i;
int j;
int text_len;
if (!text || !needle || needle_len <= 0) {
return 0;
}
text_len = (int)inline_wcslen(text);
if (needle_len > text_len) {
return 0;
}
for (i = 0; i <= text_len - needle_len; i++) {
if (i > 0 && !wide_path_token_is_boundary(text[i - 1])) {
continue;
}
for (j = 0; j < needle_len; j++) {
if ((wchar_t)ascii_lower((unsigned char)needle[j]) != wide_lower(text[i + j])) {
break;
}
}
if (j == needle_len && wide_path_token_is_boundary(text[i + needle_len])) {
return 1;
}
}
return 0;
}