diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index fa22b13b5..a20716a17 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": "e47ea43be9bce75b6659b087008304205104e06b07e524f9b245ee428fac9bf3", + "registryDigest": "46430f60743bc5472e75bb0913cdd602c2df1c7ea2674427da096603c4abc275", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/skills/ck/commands/resume.mjs b/skills/ck/commands/resume.mjs index ddde764b1..493f9f0ac 100644 --- a/skills/ck/commands/resume.mjs +++ b/skills/ck/commands/resume.mjs @@ -9,8 +9,7 @@ */ import { existsSync } from 'fs'; -import { resolve } from 'path'; -import { resolveContext, renderBriefingBox } from './shared.mjs'; +import { resolveContext, renderBriefingBox, samePath } from './shared.mjs'; const arg = process.argv[2]; const cwd = process.env.PWD || process.cwd(); @@ -25,7 +24,7 @@ if (!resolved) { const { context, projectPath } = resolved; // Attempt to cd to the project path -if (projectPath && resolve(projectPath) !== resolve(cwd)) { +if (projectPath && !samePath(projectPath, cwd)) { if (existsSync(projectPath)) { console.log(`→ cd ${projectPath}`); } else { diff --git a/skills/ck/commands/shared.mjs b/skills/ck/commands/shared.mjs index c076dd0b7..d224a6ef0 100644 --- a/skills/ck/commands/shared.mjs +++ b/skills/ck/commands/shared.mjs @@ -45,10 +45,15 @@ export function writeProjects(projects) { writeJson(PROJECTS_FILE, projects); } +export function samePath(a, b) { + const key = p => (process.platform === 'win32' ? resolve(p).toLowerCase() : resolve(p)); + return key(a) === key(b); +} + export function findProject(projects, projectPath) { const key = Object.hasOwn(projects, projectPath) ? projectPath - : Object.keys(projects).find(p => resolve(p) === resolve(projectPath)); + : Object.keys(projects).find(p => samePath(p, projectPath)); return key === undefined ? null : { path: key, ...projects[key] }; } @@ -357,7 +362,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 = resolve(e.path) === resolve(cwd); + const isHere = samePath(e.path, 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 679ac5afa..eefd3702c 100644 --- a/skills/ck/hooks/session-start.mjs +++ b/skills/ck/hooks/session-start.mjs @@ -19,6 +19,7 @@ import { resolve, dirname } from 'path'; import { homedir } from 'os'; import { spawnSync } from 'child_process'; import { fileURLToPath } from 'url'; +import { findProject } from '../commands/shared.mjs'; const CK_HOME = resolve(homedir(), '.claude', 'ck'); const PROJECTS_FILE = resolve(CK_HOME, 'projects.json'); @@ -97,8 +98,7 @@ function main() { : ''; const projects = readJson(PROJECTS_FILE) || {}; - const key = Object.hasOwn(projects, cwd) ? cwd : Object.keys(projects).find(p => resolve(p) === resolve(cwd)); - const entry = projects[key]; + const entry = findProject(projects, cwd); // 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 a230bc23d..336f45443 100644 --- a/tests/skills/ck-paths.test.js +++ b/tests/skills/ck-paths.test.js @@ -141,10 +141,25 @@ async function runTests() { } })) passed++; else failed++; + if (await test('SessionStart does not brief a registration that does not match the directory', async () => { + const ctx = tempEnv(); + try { + const ckHome = path.join(ctx.home, '.claude', 'ck'); + fs.mkdirSync(path.join(ckHome, 'contexts', 'other'), { recursive: true }); + fs.writeFileSync(path.join(ckHome, 'contexts', 'other', 'context.json'), JSON.stringify({ version: 2, name: 'other', sessions: [] })); + fs.writeFileSync(path.join(ckHome, 'projects.json'), JSON.stringify({ undefined: { name: 'other', contextDir: 'other' } })); + const hook = runCk(ctx, 'hooks/session-start.mjs', [], ctx.env, {}); + assert.strictEqual(hook.status, 0, hook.stderr); + assert.ok(!JSON.parse(hook.stdout).additionalContext.includes('ck: other |'), 'SessionStart briefed an unrelated project'); + } finally { + fs.rmSync(ctx.root, { recursive: true, force: true }); + } + })) 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 () => { + if (await test('a project registered from Git Bash (C:/...) is found from PowerShell (C:\\...) and in another letter case', async () => { const ctx = tempEnv(); try { const gitBashPath = ctx.project.replaceAll('\\', '/'); @@ -152,16 +167,18 @@ async function runTests() { 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'); + for (const [label, env] of [['PowerShell', powerShellEnv], ['lower case', { ...ctx.env, PWD: ctx.project.toLowerCase() }]]) { + assert.strictEqual(JSON.parse(runCk(ctx, 'commands/init.mjs', [], env).stdout).alreadyRegistered, true, `${label}: init did not find the project`); + const save = runCk(ctx, 'commands/save.mjs', [], env, { summary: `saved from ${label}`, leftOff: `${label} parser` }); + assert.strictEqual(save.status, 0, save.stdout + save.stderr); + assert.ok(runCk(ctx, 'commands/list.mjs', [], env).stdout.includes('bobs-app <-'), `${label}: list does not mark the current project`); + const resume = runCk(ctx, 'commands/resume.mjs', [], env); + assert.strictEqual(resume.status, 0, resume.stdout + resume.stderr); + assert.ok(resume.stdout.includes(`${label} parser`), `${label}: resume did not show the saved session`); + assert.ok(!resume.stdout.includes('→ cd'), `${label}: resume asks to cd into the current directory`); + const hook = runCk(ctx, 'hooks/session-start.mjs', [], env, {}); + assert.ok(JSON.parse(hook.stdout).additionalContext.includes('ck: bobs-app |'), `${label}: 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); @@ -176,9 +193,10 @@ async function runTests() { const ctx = tempEnv(); try { const ckHome = path.join(ctx.home, '.claude', 'ck'); + const gitBashPath = ctx.project.replaceAll('\\', '/'); const { PWD: _pwd, ...powerShellEnv } = ctx.env; const projects = {}; - for (const [name, projectPath] of [['git-bash', ctx.project.replaceAll('\\', '/')], ['powershell', ctx.project]]) { + for (const [name, projectPath] of [['git-bash', gitBashPath], ['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: [] })); @@ -189,8 +207,14 @@ async function runTests() { 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]); + assert.ok(runCk(ctx, 'commands/resume.mjs', [], powerShellEnv).stdout.includes('RESUMING: powershell'), 'resume picked the other registration'); const hook = runCk(ctx, 'hooks/session-start.mjs', [], powerShellEnv, {}); assert.ok(JSON.parse(hook.stdout).additionalContext.includes('ck: powershell |'), 'SessionStart picked the other registration'); + + const forget = runCk(ctx, 'commands/forget.mjs', [], powerShellEnv); + assert.strictEqual(forget.status, 0, forget.stdout + forget.stderr); + assert.deepStrictEqual(fs.readdirSync(path.join(ckHome, 'contexts')), ['git-bash']); + assert.deepStrictEqual(Object.keys(JSON.parse(fs.readFileSync(path.join(ckHome, 'projects.json'), 'utf8'))), [gitBashPath]); } finally { fs.rmSync(ctx.root, { recursive: true, force: true }); }