Skip to content

Commit caa21b8

Browse files
authored
Merge pull request #205 from skulidropek/issue-198
fix(core): skip tmp dirs in recursive scans
2 parents 5182ee0 + 880fb9f commit caa21b8

12 files changed

Lines changed: 47 additions & 14 deletions

.githooks/pre-commit

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ node scripts/split-knowledge-large-files.js
99
while IFS= read -r -d '' knowledge_dir; do
1010
git add -A -- "$knowledge_dir"
1111
done < <(
12-
find . -type d \
13-
\( -name ".knowledge" -o -name ".knowlenge" \) \
14-
-not -path "*/.git/*" \
15-
-print0
12+
find . \
13+
\( -name ".git" -o -name "tmp" \) -type d -prune -o \
14+
\( -type d \( -name ".knowledge" -o -name ".knowlenge" \) -print0 \)
1615
)
1716

1817
# CHANGE: auto-stage AI agent config directories (.gemini, .claude, .codex)

packages/app/tests/hooks/pre-commit-ai-dirs.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ const AI_DIR_STAGING_SNIPPET = `for ai_dir in .gemini .claude .codex; do
9797
git add -A -- "$ai_dir"
9898
fi
9999
done`
100+
const KNOWLEDGE_TMP_PRUNE_SNIPPET = `find . \\
101+
\\( -name ".git" -o -name "tmp" \\) -type d -prune -o \\
102+
\\( -type d \\( -name ".knowledge" -o -name ".knowlenge" \\) -print0 \\)`
100103

101104
// Tests that require an isolated temp git repo
102105
describe("pre-commit hook (isolated repo)", () => {
@@ -182,6 +185,7 @@ describe("pre-commit hook (isolated repo)", () => {
182185
expect(hookContent).toContain(".claude")
183186
expect(hookContent).toContain(".codex")
184187
expect(hookContent).toContain(AI_DIR_STAGING_SNIPPET)
188+
expect(hookContent).toContain(KNOWLEDGE_TMP_PRUNE_SNIPPET)
185189
})
186190

187191
// INVARIANT: core.hooksPath = ".githooks" after setup
@@ -227,6 +231,7 @@ describe("committed hook files", () => {
227231
const content = fs.readFileSync(path.resolve(repoRoot, ".githooks/pre-commit"), "utf8")
228232

229233
expect(content).toContain(AI_DIR_STAGING_SNIPPET)
234+
expect(content).toContain(KNOWLEDGE_TMP_PRUNE_SNIPPET)
230235
expect(content.startsWith("#!/usr/bin/env bash\n")).toBe(true)
231236
expect(content).toContain("set -euo pipefail")
232237
})

packages/lib/src/usecases/auth-copy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type * as FileSystem from "@effect/platform/FileSystem"
33
import type * as Path from "@effect/platform/Path"
44
import { Effect } from "effect"
55

6+
const shouldSkipCopiedDir = (entry: string): boolean => entry === "tmp"
7+
68
const copyDirRecursive = (
79
fs: FileSystem.FileSystem,
810
path: Path.Path,
@@ -19,6 +21,9 @@ const copyDirRecursive = (
1921
for (const entry of entries) {
2022
const sourceEntry = path.join(sourcePath, entry)
2123
const targetEntry = path.join(targetPath, entry)
24+
if (shouldSkipCopiedDir(entry)) {
25+
continue
26+
}
2227
const entryInfo = yield* _(fs.stat(sourceEntry))
2328
if (entryInfo.type === "Directory") {
2429
yield* _(copyDirRecursive(fs, path, sourceEntry, targetEntry))

packages/lib/src/usecases/docker-git-config-search.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ type DockerGitConfigSearchState = {
1111
const isDockerGitConfig = (entry: string): boolean => entry.endsWith("docker-git.json")
1212

1313
const shouldSkipDir = (entry: string): boolean =>
14-
entry === ".git" || entry === ".orch" || entry === ".docker-git" || entry === ".cache" || entry === "node_modules"
14+
entry === ".git" ||
15+
entry === ".orch" ||
16+
entry === ".docker-git" ||
17+
entry === ".cache" ||
18+
entry === "node_modules" ||
19+
entry === "tmp"
1520

1621
const isNotFoundStatError = (error: PlatformError): boolean =>
1722
error._tag === "SystemError" && error.reason === "NotFound"

packages/lib/src/usecases/scrap-session-import.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ const prepareRepoForImport = (
159159
`git -c safe.directory="$SAFE" reset --hard ${shellEscape(ctx.manifest.repo.head)}`,
160160
"git -c safe.directory=\"$SAFE\" clean -fd",
161161
// Remove common heavy caches that are easy to rebuild with internet access.
162-
"find . -name node_modules -type d -prune -exec rm -rf '{}' + 2>/dev/null || true"
162+
String
163+
.raw`find . \( -name tmp -o -name .git \) -type d -prune -o -name node_modules -type d -prune -exec rm -rf '{}' + 2>/dev/null || true`
163164
].join("\n")
164165

165166
return runDockerExec(

packages/lib/tests/usecases/auth-sync.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,13 @@ describe("syncGithubAuthKeys", () => {
161161
const path = yield* _(Path.Path)
162162
const legacyClaudeDefault = path.join(root, ".orch", "auth", "claude", "default")
163163
const legacyTokenPath = path.join(legacyClaudeDefault, ".oauth-token")
164+
const ignoredTmpTokenPath = path.join(root, ".orch", "auth", "claude", "tmp", ".oauth-token")
164165
const expectedToken = "legacy-claude-token\n"
165166

166167
yield* _(fs.makeDirectory(legacyClaudeDefault, { recursive: true }))
167168
yield* _(fs.writeFileString(legacyTokenPath, expectedToken))
169+
yield* _(fs.makeDirectory(path.dirname(ignoredTmpTokenPath), { recursive: true }))
170+
yield* _(fs.writeFileString(ignoredTmpTokenPath, "ignored-claude-token\n"))
168171

169172
yield* _(
170173
migrateLegacyOrchLayout(root, {
@@ -186,7 +189,18 @@ describe("syncGithubAuthKeys", () => {
186189
".oauth-token"
187190
)
188191
const migratedToken = yield* _(fs.readFileString(migratedTokenPath))
192+
const migratedTmpTokenPath = path.join(
193+
root,
194+
".docker-git",
195+
".orch",
196+
"auth",
197+
"claude",
198+
"tmp",
199+
".oauth-token"
200+
)
201+
const hasMigratedTmpToken = yield* _(fs.exists(migratedTmpTokenPath))
189202
expect(migratedToken).toBe(expectedToken)
203+
expect(hasMigratedTmpToken).toBe(false)
190204
})
191205
).pipe(Effect.provide(NodeContext.layer)))
192206

packages/lib/tests/usecases/docker-git-config-search.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ describe("findDockerGitConfigPaths", () => {
4444
const ignoredOrch = path.join(root, "org/repo-a/.orch/docker-git.json")
4545
const ignoredRootCache = path.join(root, ".cache/packages/pnpm/store/v10/index/docker-git.json")
4646
const ignoredDockerGit = path.join(root, ".docker-git/.cache/git-mirrors/docker-git.json")
47+
const ignoredTmp = path.join(root, "org/tmp/repo-c/docker-git.json")
4748

4849
yield* _(writeFileWithParents(fs, path, includedMain))
4950
yield* _(writeFileWithParents(fs, path, includedNested))
5051
yield* _(writeFileWithParents(fs, path, ignoredGit))
5152
yield* _(writeFileWithParents(fs, path, ignoredOrch))
5253
yield* _(writeFileWithParents(fs, path, ignoredRootCache))
5354
yield* _(writeFileWithParents(fs, path, ignoredDockerGit))
55+
yield* _(writeFileWithParents(fs, path, ignoredTmp))
5456

5557
const found = yield* _(findDockerGitConfigPaths(fs, path, root))
5658
expect([...found].sort()).toEqual([includedMain, includedNested].sort())

scripts/repair-knowledge-history.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if (!Number.isFinite(count) || count <= 0) {
5454
// Run splitter + secret redaction after each commit is replayed, then amend if needed.
5555
const execCmd = [
5656
`node scripts/split-knowledge-large-files.js`,
57-
`while IFS= read -r -d '' knowledge_dir; do git add -A -- "$knowledge_dir"; done < <(find . -type d \\( -name ".knowledge" -o -name ".knowlenge" \\) -not -path "*/.git/*" -print0)`,
57+
`while IFS= read -r -d '' knowledge_dir; do git add -A -- "$knowledge_dir"; done < <(find . \\( -name ".git" -o -name "tmp" \\) -type d -prune -o \\( -type d \\( -name ".knowledge" -o -name ".knowlenge" \\) -print0 \\))`,
5858
`bash scripts/pre-commit-secret-guard.sh`,
5959
`if ! git diff --cached --quiet; then git commit --amend --no-edit --no-verify; fi`,
6060
].join(" && ");

scripts/session-backup-gist.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const {
4141
} = require("./session-backup-repo.js");
4242

4343
const SESSION_DIR_NAMES = [".codex", ".claude", ".qwen", ".gemini"];
44+
const SESSION_WALK_IGNORE_DIR_NAMES = new Set([".git", "node_modules", "tmp"]);
4445

4546
const isPathWithinParent = (targetPath, parentPath) => {
4647
const relative = path.relative(parentPath, targetPath);
@@ -366,7 +367,7 @@ const collectSessionFiles = (dirPath, baseName, verbose) => {
366367
const relPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
367368

368369
if (entry.isDirectory()) {
369-
if (entry.name === "node_modules" || entry.name === ".git") {
370+
if (SESSION_WALK_IGNORE_DIR_NAMES.has(entry.name)) {
370371
continue;
371372
}
372373
walk(fullPath, relPath);

scripts/session-backup-repo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const GH_GIT_CREDENTIAL_HELPER = "!gh auth git-credential";
1515
const CHUNK_MANIFEST_SUFFIX = ".chunks.json";
1616
const DOCKER_GIT_CONFIG_FILE = "docker-git.json";
1717
const GITHUB_ENV_KEYS = ["GITHUB_TOKEN", "GH_TOKEN"];
18+
const PROJECT_WALK_IGNORE_DIR_NAMES = new Set([".git", "node_modules", ".cache", "tmp"]);
1819

1920
const parseEnvText = (text) => {
2021
const entries = [];
@@ -90,7 +91,7 @@ const findDockerGitProjectForTarget = (projectsRoot, targetDir, log) => {
9091
if (!entry.isDirectory()) {
9192
continue;
9293
}
93-
if (entry.name === ".git" || entry.name === "node_modules" || entry.name === ".cache") {
94+
if (PROJECT_WALK_IGNORE_DIR_NAMES.has(entry.name)) {
9495
continue;
9596
}
9697
stack.push(path.join(currentDir, entry.name));

0 commit comments

Comments
 (0)