From 00787d68e466c838448179d42b73157bcef3c4e1 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Sat, 28 Mar 2026 23:23:54 -0400 Subject: [PATCH] fix(ck): preserve display names and harden git helpers --- skills/ck/commands/save.mjs | 2 +- skills/ck/commands/shared.mjs | 14 ++++++++------ skills/ck/hooks/session-start.mjs | 14 +++++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/skills/ck/commands/save.mjs b/skills/ck/commands/save.mjs index dc60efc4..0d25029c 100644 --- a/skills/ck/commands/save.mjs +++ b/skills/ck/commands/save.mjs @@ -79,7 +79,7 @@ if (isInit) { // Update projects.json projects[projectPath] = { - name: contextDir, + name, contextDir, lastUpdated: today(), }; diff --git a/skills/ck/commands/shared.mjs b/skills/ck/commands/shared.mjs index 73ae6521..49a36363 100644 --- a/skills/ck/commands/shared.mjs +++ b/skills/ck/commands/shared.mjs @@ -8,7 +8,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from 'fs'; import { resolve, basename } from 'path'; import { homedir } from 'os'; -import { execSync } from 'child_process'; +import { spawnSync } from 'child_process'; import { randomBytes } from 'crypto'; // ─── Paths ──────────────────────────────────────────────────────────────────── @@ -144,11 +144,13 @@ export function shortId() { function runGit(args, cwd) { try { - return execSync(`git -C "${cwd}" ${args}`, { + const result = spawnSync('git', ['-C', cwd, ...args], { timeout: 3000, stdio: 'pipe', encoding: 'utf8', - }).trim(); + }); + if (result.status !== 0) return null; + return result.stdout.trim(); } catch { return null; } @@ -156,7 +158,7 @@ function runGit(args, cwd) { export function gitLogSince(projectPath, sinceDate) { if (!sinceDate) return null; - return runGit(`log --oneline --since="${sinceDate}"`, projectPath); + return runGit(['log', '--oneline', `--since=${sinceDate}`], projectPath); } export function gitSummary(projectPath, sinceDate) { @@ -166,9 +168,9 @@ export function gitSummary(projectPath, sinceDate) { if (commits === 0) return null; // Count unique files changed: use a separate runGit call to avoid nested shell substitution - const countStr = runGit(`rev-list --count HEAD --since="${sinceDate}"`, projectPath); + const countStr = runGit(['rev-list', '--count', 'HEAD', `--since=${sinceDate}`], projectPath); const revCount = countStr ? parseInt(countStr, 10) : commits; - const diff = runGit(`diff --shortstat HEAD~${Math.min(revCount, 50)}..HEAD`, projectPath); + const diff = runGit(['diff', '--shortstat', `HEAD~${Math.min(revCount, 50)}..HEAD`], projectPath); if (diff) { const filesMatch = diff.match(/(\d+) file/); diff --git a/skills/ck/hooks/session-start.mjs b/skills/ck/hooks/session-start.mjs index 10f87f23..c3ecee66 100644 --- a/skills/ck/hooks/session-start.mjs +++ b/skills/ck/hooks/session-start.mjs @@ -17,7 +17,7 @@ import { readFileSync, writeFileSync, existsSync } from 'fs'; import { resolve } from 'path'; import { homedir } from 'os'; -import { execSync } from 'child_process'; +import { spawnSync } from 'child_process'; const CK_HOME = resolve(homedir(), '.claude', 'ck'); const PROJECTS_FILE = resolve(CK_HOME, 'projects.json'); @@ -47,10 +47,14 @@ function stalenessIcon(dateStr) { function gitLogSince(projectPath, sinceDate) { if (!sinceDate || !existsSync(resolve(projectPath, '.git'))) return null; try { - const result = execSync(`git -C "${projectPath}" log --oneline --since="${sinceDate}"`, { - timeout: 3000, stdio: 'pipe', encoding: 'utf8', - }).trim(); - const commits = result.split('\n').filter(Boolean).length; + const result = spawnSync( + 'git', + ['-C', projectPath, 'log', '--oneline', `--since=${sinceDate}`], + { timeout: 3000, stdio: 'pipe', encoding: 'utf8' }, + ); + if (result.status !== 0) return null; + const output = result.stdout.trim(); + const commits = output.split('\n').filter(Boolean).length; return commits > 0 ? `${commits} commit${commits !== 1 ? 's' : ''} since last session` : null; } catch { return null; } }