mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-10 02:24:35 +08:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -90,6 +90,55 @@ async function findWfsSessions(dir) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse timestamp from session name
|
||||
* Supports formats: WFS-xxx-20251128172537 or WFS-xxx-20251120-170640
|
||||
* @param {string} sessionName - Session directory name
|
||||
* @returns {string|null} - ISO date string or null
|
||||
*/
|
||||
function parseTimestampFromName(sessionName) {
|
||||
// Format: 14-digit timestamp (YYYYMMDDHHmmss)
|
||||
const match14 = sessionName.match(/(\d{14})$/);
|
||||
if (match14) {
|
||||
const ts = match14[1];
|
||||
return `${ts.slice(0,4)}-${ts.slice(4,6)}-${ts.slice(6,8)}T${ts.slice(8,10)}:${ts.slice(10,12)}:${ts.slice(12,14)}Z`;
|
||||
}
|
||||
|
||||
// Format: 8-digit date + 6-digit time separated by hyphen (YYYYMMDD-HHmmss)
|
||||
const match8_6 = sessionName.match(/(\d{8})-(\d{6})$/);
|
||||
if (match8_6) {
|
||||
const d = match8_6[1];
|
||||
const t = match8_6[2];
|
||||
return `${d.slice(0,4)}-${d.slice(4,6)}-${d.slice(6,8)}T${t.slice(0,2)}:${t.slice(2,4)}:${t.slice(4,6)}Z`;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Infer session type from session name pattern
|
||||
* @param {string} sessionName - Session directory name
|
||||
* @returns {string} - Inferred type
|
||||
*/
|
||||
function inferTypeFromName(sessionName) {
|
||||
const name = sessionName.toLowerCase();
|
||||
|
||||
if (name.includes('-review-') || name.includes('-code-review-')) {
|
||||
return 'review';
|
||||
}
|
||||
if (name.includes('-test-')) {
|
||||
return 'test';
|
||||
}
|
||||
if (name.includes('-docs-')) {
|
||||
return 'docs';
|
||||
}
|
||||
if (name.includes('-tdd-')) {
|
||||
return 'tdd';
|
||||
}
|
||||
|
||||
return 'workflow';
|
||||
}
|
||||
|
||||
/**
|
||||
* Read session data from workflow-session.json or create minimal from directory
|
||||
* @param {string} sessionPath - Path to session directory
|
||||
@@ -97,17 +146,27 @@ async function findWfsSessions(dir) {
|
||||
*/
|
||||
function readSessionData(sessionPath) {
|
||||
const sessionFile = join(sessionPath, 'workflow-session.json');
|
||||
const sessionName = basename(sessionPath);
|
||||
|
||||
if (existsSync(sessionFile)) {
|
||||
try {
|
||||
const data = JSON.parse(readFileSync(sessionFile, 'utf8'));
|
||||
|
||||
// Multi-level type detection: JSON type > workflow_type > infer from name
|
||||
let type = data.type || data.workflow_type || inferTypeFromName(sessionName);
|
||||
|
||||
// Normalize workflow_type values
|
||||
if (type === 'test_session') type = 'test';
|
||||
if (type === 'implementation') type = 'workflow';
|
||||
|
||||
return {
|
||||
session_id: data.session_id || basename(sessionPath),
|
||||
session_id: data.session_id || sessionName,
|
||||
project: data.project || data.description || '',
|
||||
status: data.status || 'active',
|
||||
created_at: data.created_at || data.initialized_at || null,
|
||||
created_at: data.created_at || data.initialized_at || data.timestamp || null,
|
||||
archived_at: data.archived_at || null,
|
||||
type: data.type || 'workflow'
|
||||
type: type,
|
||||
workflow_type: data.workflow_type || null // Keep original for reference
|
||||
};
|
||||
} catch {
|
||||
// Fall through to minimal session
|
||||
@@ -115,17 +174,34 @@ function readSessionData(sessionPath) {
|
||||
}
|
||||
|
||||
// Fallback: create minimal session from directory info
|
||||
// Try to extract timestamp from session name first
|
||||
const timestampFromName = parseTimestampFromName(sessionName);
|
||||
const inferredType = inferTypeFromName(sessionName);
|
||||
|
||||
try {
|
||||
const stats = statSync(sessionPath);
|
||||
return {
|
||||
session_id: basename(sessionPath),
|
||||
session_id: sessionName,
|
||||
project: '',
|
||||
status: 'unknown',
|
||||
created_at: stats.birthtime.toISOString(),
|
||||
created_at: timestampFromName || stats.birthtime.toISOString(),
|
||||
archived_at: null,
|
||||
type: 'workflow'
|
||||
type: inferredType,
|
||||
workflow_type: null
|
||||
};
|
||||
} catch {
|
||||
// Even if stat fails, return with name-extracted data
|
||||
if (timestampFromName) {
|
||||
return {
|
||||
session_id: sessionName,
|
||||
project: '',
|
||||
status: 'unknown',
|
||||
created_at: timestampFromName,
|
||||
archived_at: null,
|
||||
type: inferredType,
|
||||
workflow_type: null
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user