diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 48081c3fb..fa22b13b5 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "6f213dc845937b4093bc018d041b25b538d88d78451b9d799ad614989b360ee4", + "registryDigest": "e47ea43be9bce75b6659b087008304205104e06b07e524f9b245ee428fac9bf3", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/skills/ck/commands/init.mjs b/skills/ck/commands/init.mjs index fd25bf2d2..5b35dfdad 100644 --- a/skills/ck/commands/init.mjs +++ b/skills/ck/commands/init.mjs @@ -10,7 +10,7 @@ import { readFileSync, existsSync } from 'fs'; import { resolve, basename } from 'path'; -import { readProjects } from './shared.mjs'; +import { readProjects, findProject } from './shared.mjs'; const cwd = process.env.PWD || process.cwd(); const projects = readProjects(); @@ -23,7 +23,7 @@ const output = { goal: null, constraints: [], repo: null, - alreadyRegistered: !!projects[cwd], + alreadyRegistered: !!findProject(projects, cwd), }; function readFile(filename) { diff --git a/skills/ck/commands/resume.mjs b/skills/ck/commands/resume.mjs index 605f10491..ddde764b1 100644 --- a/skills/ck/commands/resume.mjs +++ b/skills/ck/commands/resume.mjs @@ -9,6 +9,7 @@ */ import { existsSync } from 'fs'; +import { resolve } from 'path'; import { resolveContext, renderBriefingBox } from './shared.mjs'; const arg = process.argv[2]; @@ -24,7 +25,7 @@ if (!resolved) { const { context, projectPath } = resolved; // Attempt to cd to the project path -if (projectPath && projectPath !== cwd) { +if (projectPath && resolve(projectPath) !== resolve(cwd)) { if (existsSync(projectPath)) { console.log(`→ cd ${projectPath}`); } else { diff --git a/skills/ck/commands/save.mjs b/skills/ck/commands/save.mjs index 715154432..871c25c98 100644 --- a/skills/ck/commands/save.mjs +++ b/skills/ck/commands/save.mjs @@ -20,7 +20,7 @@ import { readFileSync, mkdirSync, writeFileSync } from 'fs'; import { resolve } from 'path'; import { createHash } from 'crypto'; import { - readProjects, writeProjects, loadContext, saveContext, + readProjects, writeProjects, findProject, loadContext, saveContext, today, shortId, gitSummary, nativeMemoryDir, CURRENT_SESSION, } from './shared.mjs'; @@ -53,6 +53,7 @@ if (isInit) { } const projects = readProjects(); + const registered = findProject(projects, projectPath); // Derive contextDir (lowercase, spaces→dashes, deduplicate). Names with no // ASCII letters/digits (e.g. "Проект") fall back to a stable path hash, so @@ -61,7 +62,7 @@ if (isInit) { || `project-${createHash('sha256').update(projectPath).digest('hex').slice(0, 8)}`; let suffix = 2; const existingDirs = Object.values(projects).map(p => p.contextDir); - while (existingDirs.includes(contextDir) && projects[projectPath]?.contextDir !== contextDir) { + while (existingDirs.includes(contextDir) && registered?.contextDir !== contextDir) { contextDir = `${contextDir.replace(/-\d+$/, '')}-${suffix++}`; } @@ -82,7 +83,7 @@ if (isInit) { saveContext(contextDir, context); // Update projects.json - projects[projectPath] = { + projects[registered?.path ?? projectPath] = { name, contextDir, lastUpdated: today(), @@ -98,7 +99,7 @@ if (isInit) { // SAVE MODE: record a session // ───────────────────────────────────────────────────────────────────────────── const projects = readProjects(); -const projectEntry = projects[cwd]; +const projectEntry = findProject(projects, cwd); if (!projectEntry) { console.log("This project isn't registered yet. Run /ck:init first."); @@ -158,7 +159,7 @@ if (goal && goal !== context.goal) { saveContext(contextDir, context); // Update projects.json timestamp -projects[cwd].lastUpdated = today(); +projects[projectEntry.path].lastUpdated = today(); writeProjects(projects); // ── Write to native memory ──────────────────────────────────────────────────── diff --git a/skills/ck/commands/shared.mjs b/skills/ck/commands/shared.mjs index eaac041dd..c076dd0b7 100644 --- a/skills/ck/commands/shared.mjs +++ b/skills/ck/commands/shared.mjs @@ -45,6 +45,13 @@ export function writeProjects(projects) { writeJson(PROJECTS_FILE, projects); } +export function findProject(projects, projectPath) { + const key = Object.hasOwn(projects, projectPath) + ? projectPath + : Object.keys(projects).find(p => resolve(p) === resolve(projectPath)); + return key === undefined ? null : { path: key, ...projects[key] }; +} + // ─── Context I/O ────────────────────────────────────────────────────────────── export function contextPath(contextDir) { @@ -78,11 +85,11 @@ export function resolveContext(arg, cwd) { if (!arg) { // Match by cwd - const entry = projects[cwd]; + const entry = findProject(projects, cwd); if (!entry) return null; const context = loadContext(entry.contextDir); if (!context) return null; - return { name: entry.name, contextDir: entry.contextDir, projectPath: cwd, context }; + return { name: entry.name, contextDir: entry.contextDir, projectPath: entry.path, context }; } // Collect all contexts sorted alphabetically by contextDir @@ -350,7 +357,7 @@ export function renderListTable(entries, cwd, _todayStr) { // entries: [{name, contextDir, path, context, lastUpdated}] // Sorted alphabetically by contextDir before calling const rows = entries.map((e, i) => { - const isHere = e.path === cwd; + const isHere = resolve(e.path) === resolve(cwd); const latest = e.context?.sessions?.[e.context.sessions.length - 1] || {}; const when = daysAgoLabel(latest.date); const icon = stalenessIcon(latest.date); diff --git a/skills/ck/hooks/session-start.mjs b/skills/ck/hooks/session-start.mjs index 47d3623b7..679ac5afa 100644 --- a/skills/ck/hooks/session-start.mjs +++ b/skills/ck/hooks/session-start.mjs @@ -97,7 +97,8 @@ function main() { : ''; const projects = readJson(PROJECTS_FILE) || {}; - const entry = projects[cwd]; + const key = Object.hasOwn(projects, cwd) ? cwd : Object.keys(projects).find(p => resolve(p) === resolve(cwd)); + const entry = projects[key]; // Read previous session BEFORE overwriting current-session.json const prevSession = readJson(CURRENT_SESSION); diff --git a/tests/skills/ck-paths.test.js b/tests/skills/ck-paths.test.js index c85c5d40b..a230bc23d 100644 --- a/tests/skills/ck-paths.test.js +++ b/tests/skills/ck-paths.test.js @@ -56,6 +56,12 @@ function runDocumentedSave(marker, placeholder, payload, ctx) { return spawnSync('bash', ['-c', script], { cwd: ctx.project, env: ctx.env, encoding: 'utf8' }); } +function runCk(ctx, script, args, env, payload) { + return spawnSync(process.execPath, [path.join(SKILL_DIR, script), ...args], { + cwd: ctx.project, env, input: payload === undefined ? '' : JSON.stringify(payload), encoding: 'utf8', + }); +} + async function runTests() { console.log('\n=== Testing ck path handling ===\n'); @@ -135,6 +141,62 @@ async function runTests() { } })) passed++; else failed++; + if (process.platform !== 'win32') { + console.log(' - skipped Git Bash and PowerShell path form tests off Windows'); + } else { + if (await test('a project registered from Git Bash (C:/...) is the same project from PowerShell (C:\\...)', async () => { + const ctx = tempEnv(); + try { + const gitBashPath = ctx.project.replaceAll('\\', '/'); + const { PWD: _pwd, ...powerShellEnv } = ctx.env; + const init = runCk(ctx, 'commands/save.mjs', ['--init'], { ...ctx.env, PWD: gitBashPath }, { name: 'bobs-app', path: gitBashPath }); + assert.strictEqual(init.status, 0, init.stdout + init.stderr); + + assert.strictEqual(JSON.parse(runCk(ctx, 'commands/init.mjs', [], powerShellEnv).stdout).alreadyRegistered, true); + const save = runCk(ctx, 'commands/save.mjs', [], powerShellEnv, { summary: 'saved from PowerShell' }); + assert.strictEqual(save.status, 0, save.stdout + save.stderr); + assert.ok(runCk(ctx, 'commands/list.mjs', [], powerShellEnv).stdout.includes('bobs-app <-'), 'list does not mark the current project'); + const resume = runCk(ctx, 'commands/resume.mjs', [], powerShellEnv); + assert.strictEqual(resume.status, 0, resume.stdout + resume.stderr); + assert.ok(resume.stdout.includes('RESUMING: bobs-app'), 'resume did not show the project briefing'); + assert.ok(!resume.stdout.includes('→ cd'), 'resume asks to cd into the current directory'); + const hook = runCk(ctx, 'hooks/session-start.mjs', [], powerShellEnv, {}); + assert.ok(JSON.parse(hook.stdout).additionalContext.includes('ck: bobs-app |'), 'SessionStart did not find the project'); + + const reinit = runCk(ctx, 'commands/save.mjs', ['--init'], powerShellEnv, { name: 'bobs-app', path: ctx.project }); + assert.strictEqual(reinit.status, 0, reinit.stdout + reinit.stderr); + const projects = JSON.parse(fs.readFileSync(path.join(ctx.home, '.claude', 'ck', 'projects.json'), 'utf8')); + assert.deepStrictEqual(Object.keys(projects), [gitBashPath]); + } finally { + fs.rmSync(ctx.root, { recursive: true, force: true }); + } + })) passed++; else failed++; + + if (await test('when both spellings of a folder are registered, the exact one is used', async () => { + const ctx = tempEnv(); + try { + const ckHome = path.join(ctx.home, '.claude', 'ck'); + const { PWD: _pwd, ...powerShellEnv } = ctx.env; + const projects = {}; + for (const [name, projectPath] of [['git-bash', ctx.project.replaceAll('\\', '/')], ['powershell', ctx.project]]) { + projects[projectPath] = { name, contextDir: name, lastUpdated: '2026-01-01' }; + fs.mkdirSync(path.join(ckHome, 'contexts', name), { recursive: true }); + fs.writeFileSync(path.join(ckHome, 'contexts', name, 'context.json'), JSON.stringify({ version: 2, name, path: projectPath, sessions: [] })); + } + fs.writeFileSync(path.join(ckHome, 'projects.json'), JSON.stringify(projects)); + + const save = runCk(ctx, 'commands/save.mjs', [], powerShellEnv, { summary: 'saved from PowerShell' }); + assert.strictEqual(save.status, 0, save.stdout + save.stderr); + const sessions = name => JSON.parse(fs.readFileSync(path.join(ckHome, 'contexts', name, 'context.json'), 'utf8')).sessions.length; + assert.deepStrictEqual([sessions('git-bash'), sessions('powershell')], [0, 1]); + const hook = runCk(ctx, 'hooks/session-start.mjs', [], powerShellEnv, {}); + assert.ok(JSON.parse(hook.stdout).additionalContext.includes('ck: powershell |'), 'SessionStart picked the other registration'); + } finally { + fs.rmSync(ctx.root, { recursive: true, force: true }); + } + })) passed++; else failed++; + } + console.log(`\nPassed: ${passed}`); console.log(`Failed: ${failed}`); process.exitCode = failed > 0 ? 1 : 0;