Skip to content

Commit 3827fc7

Browse files
committed
fix(hooks): address CodeRabbit review nits
- _project.ts: use cwd?.trim() || process.cwd() so a whitespace-only cwd doesn't pass through and produce a basename like " /path ". - notification.ts: runtime-guard data.cwd with typeof === "string" before passing to resolveProject; data is parsed from untyped JSON. - hook-project.test.ts: replace execSync("mkdir -p ...") with mkdirSync(sub, { recursive: true }) for platform portability.
1 parent 6c084a9 commit 3827fc7

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/hooks/_project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function resolveProject(cwd?: string): string {
2424
const explicit = process.env["AGENTMEMORY_PROJECT_NAME"];
2525
if (explicit && explicit.trim()) return explicit.trim();
2626

27-
const dir = cwd && cwd.trim() ? cwd : process.cwd();
27+
const dir = cwd?.trim() || process.cwd();
2828

2929
try {
3030
const top = execSync("git rev-parse --show-toplevel", {

src/hooks/notification.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ async function main() {
3434
if (data.notification_type !== "permission_prompt") return;
3535

3636
const sessionId = (data.session_id as string) || "unknown";
37-
const cwd = (data.cwd as string) || process.cwd();
37+
const cwd =
38+
typeof data.cwd === "string" && data.cwd.length > 0
39+
? data.cwd
40+
: process.cwd();
3841
const project = resolveProject(cwd);
3942

4043
try {

test/hook-project.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it } from "vitest";
2-
import { mkdtempSync, rmSync } from "node:fs";
2+
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join, basename } from "node:path";
55
import { execSync } from "node:child_process";
@@ -42,7 +42,7 @@ describe("resolveProject (#lesson-visibility-pt2)", () => {
4242
try {
4343
execSync("git init --quiet", { cwd: tmp });
4444
const sub = join(tmp, "src", "deep");
45-
execSync(`mkdir -p ${sub}`);
45+
mkdirSync(sub, { recursive: true });
4646
// When called from a subdirectory of the repo, project is still the
4747
// repo basename, not the subdirectory basename. This handles sessions
4848
// started inside subtrees (e.g. /repo/src/foo).

0 commit comments

Comments
 (0)