Skip to content

Commit 880fb9f

Browse files
committed
fix(core): skip tmp dirs in recursive scans
1 parent 39aa7db commit 880fb9f

10 files changed

Lines changed: 39 additions & 13 deletions

File tree

.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/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

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));

scripts/setup-pre-commit-hook.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ node scripts/split-knowledge-large-files.js
2929
while IFS= read -r -d '' knowledge_dir; do
3030
git add -A -- "$knowledge_dir"
3131
done < <(
32-
find . -type d \\
33-
\\( -name ".knowledge" -o -name ".knowlenge" \\) \\
34-
-not -path "*/.git/*" \\
35-
-print0
32+
find . \\
33+
\\( -name ".git" -o -name "tmp" \\) -type d -prune -o \\
34+
\\( -type d \\( -name ".knowledge" -o -name ".knowlenge" \\) -print0 \\)
3635
)
3736
3837
# CHANGE: auto-stage AI agent config directories (.gemini, .claude, .codex)

scripts/split-knowledge-large-files.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require("node:path");
55

66
const MAX_BYTES = 99 * 1000 * 1000;
77
const KNOWLEDGE_DIR_NAMES = new Set([".knowledge", ".knowlenge"]);
8-
const WALK_IGNORE_DIR_NAMES = new Set([".git", "node_modules"]);
8+
const WALK_IGNORE_DIR_NAMES = new Set([".git", "node_modules", "tmp"]);
99
const MANIFEST_SUFFIX = ".chunks.json";
1010
const CHUNK_BYTES = 1024 * 1024;
1111

@@ -85,6 +85,7 @@ const walk = (dir) => {
8585
for (const entry of entries) {
8686
const fullPath = path.join(dir, entry.name);
8787
if (entry.isDirectory()) {
88+
if (WALK_IGNORE_DIR_NAMES.has(entry.name)) continue;
8889
walk(fullPath);
8990
continue;
9091
}

0 commit comments

Comments
 (0)