Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
]

[workspace.package]
version = "2026.10329.110"
version = "2026.10330.108"
edition = "2024"
license = "AGPL-3.0-only"
authors = ["TrueNine"]
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-darwin-arm64",
"version": "2026.10329.110",
"version": "2026.10330.108",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-darwin-x64",
"version": "2026.10329.110",
"version": "2026.10330.108",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-linux-arm64-gnu",
"version": "2026.10329.110",
"version": "2026.10330.108",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-linux-x64-gnu",
"version": "2026.10329.110",
"version": "2026.10330.108",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-win32-x64-msvc",
"version": "2026.10329.110",
"version": "2026.10330.108",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@truenine/memory-sync-cli",
"type": "module",
"version": "2026.10329.110",
"version": "2026.10330.108",
"description": "TrueNine Memory Synchronization CLI",
"author": "TrueNine",
"license": "AGPL-3.0-only",
Expand Down
9 changes: 1 addition & 8 deletions cli/scripts/benchmark-cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ delete process.env['VITEST']
delete process.env['VITEST_WORKER_ID']

const cleanupModule = await import('../src/commands/CleanupUtils')
const fallbackModule = await import('../src/commands/CleanupUtils.fallback')
const pluginCore = await import('../src/plugins/plugin-core')

function createMockLogger(): ILogger {
Expand Down Expand Up @@ -136,15 +135,9 @@ async function main(): Promise<void> {
const iterations = 25

process.stdout.write(`cleanup benchmark iterations=${iterations}\n`)
const fallbackAvg = await measure('fallback-plan', iterations, async () => {
await fallbackModule.collectDeletionTargets([plugin], cleanCtx)
})
const nativeAvg = await measure('native-plan', iterations, async () => {
await measure('native-plan', iterations, async () => {
await cleanupModule.collectDeletionTargets([plugin], cleanCtx)
})

const delta = nativeAvg - fallbackAvg
process.stdout.write(`delta=${delta.toFixed(2)}ms (${((delta / fallbackAvg) * 100).toFixed(2)}%)\n`)
}
finally {
fs.rmSync(tempDir, {recursive: true, force: true})
Expand Down
30 changes: 17 additions & 13 deletions cli/scripts/cleanup-native-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ delete process.env['VITEST']
delete process.env['VITEST_WORKER_ID']

const cleanupModule = await import('../src/commands/CleanupUtils')
const fallbackModule = await import('../src/commands/CleanupUtils.fallback')
const pluginCore = await import('../src/plugins/plugin-core')

function createMockLogger(): ILogger {
Expand Down Expand Up @@ -106,21 +105,18 @@ async function main(): Promise<void> {
const cleanCtx = createCleanContext(workspaceDir)

const nativePlan = await cleanupModule.collectDeletionTargets([plugin], cleanCtx)
const fallbackPlan = await fallbackModule.collectDeletionTargets([plugin], cleanCtx)

const sortPaths = (value: {filesToDelete: string[], dirsToDelete: string[], excludedScanGlobs: string[]}) => ({
...value,
filesToDelete: [...value.filesToDelete].sort(),
dirsToDelete: [...value.dirsToDelete].sort(),
excludedScanGlobs: [...value.excludedScanGlobs].sort()
})

if (JSON.stringify(sortPaths(nativePlan)) !== JSON.stringify(sortPaths(fallbackPlan))) {
throw new Error(`Native cleanup plan mismatch.\nNative: ${JSON.stringify(nativePlan, null, 2)}\nFallback: ${JSON.stringify(fallbackPlan, null, 2)}`)
expectSetEqual(nativePlan.filesToDelete, [rootOutput, childOutput], 'native cleanup plan files')
expectSetEqual(nativePlan.dirsToDelete, [
legacySkillDir,
path.join(workspaceDir, 'project-a', 'commands'),
path.join(workspaceDir, 'project-a')
], 'native cleanup plan directories')
if (nativePlan.violations.length > 0 || nativePlan.conflicts.length > 0) {
throw new Error(`Unexpected native cleanup plan: ${JSON.stringify(nativePlan, null, 2)}`)
}

const result = await cleanupModule.performCleanup([plugin], cleanCtx, createMockLogger())
if (result.deletedFiles !== 2 || result.deletedDirs !== 1 || result.errors.length > 0) {
if (result.deletedFiles !== 2 || result.deletedDirs !== 3 || result.errors.length > 0) {
throw new Error(`Unexpected native cleanup result: ${JSON.stringify(result, null, 2)}`)
}

Expand All @@ -138,4 +134,12 @@ async function main(): Promise<void> {
}
}

function expectSetEqual(actual: readonly string[], expected: readonly string[], label: string): void {
const actualSorted = [...actual].sort()
const expectedSorted = [...expected].sort()
if (JSON.stringify(actualSorted) !== JSON.stringify(expectedSorted)) {
throw new Error(`Unexpected ${label}: ${JSON.stringify(actualSorted)} !== ${JSON.stringify(expectedSorted)}`)
}
}

await main()
97 changes: 97 additions & 0 deletions cli/src/cleanup/empty-directories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import type * as fs from 'node:fs'
import {resolveAbsolutePath} from '../ProtectedDeletionGuard'

const EMPTY_DIRECTORY_SCAN_EXCLUDED_BASENAMES = new Set([
'.git',
'node_modules',
'dist',
'target',
'.next',
'.turbo',
'coverage',
'.nyc_output',
'.cache',
'.vite',
'.vite-temp',
'.pnpm-store',
'.yarn',
'.idea',
'.vscode'
])

export interface WorkspaceEmptyDirectoryPlan {
readonly emptyDirsToDelete: string[]
}

export interface WorkspaceEmptyDirectoryPlannerOptions {
readonly fs: typeof import('node:fs')
readonly path: typeof import('node:path')
readonly workspaceDir: string
readonly filesToDelete: readonly string[]
readonly dirsToDelete: readonly string[]
}

function shouldSkipEmptyDirectoryTree(
nodePath: typeof import('node:path'),
workspaceDir: string,
currentDir: string
): boolean {
if (currentDir === workspaceDir) return false
return EMPTY_DIRECTORY_SCAN_EXCLUDED_BASENAMES.has(nodePath.basename(currentDir))
}

export function planWorkspaceEmptyDirectoryCleanup(
options: WorkspaceEmptyDirectoryPlannerOptions
): WorkspaceEmptyDirectoryPlan {
const workspaceDir = resolveAbsolutePath(options.workspaceDir)
const filesToDelete = new Set(options.filesToDelete.map(resolveAbsolutePath))
const dirsToDelete = new Set(options.dirsToDelete.map(resolveAbsolutePath))
const emptyDirsToDelete = new Set<string>()

const collectEmptyDirectories = (currentDir: string): boolean => {
if (dirsToDelete.has(currentDir)) return true
if (shouldSkipEmptyDirectoryTree(options.path, workspaceDir, currentDir)) return false

let entries: fs.Dirent[]
try {
entries = options.fs.readdirSync(currentDir, {withFileTypes: true})
}
catch {
return false
}

let hasRetainedEntries = false

for (const entry of entries) {
const entryPath = resolveAbsolutePath(options.path.join(currentDir, entry.name))

if (dirsToDelete.has(entryPath)) continue

if (entry.isDirectory()) {
if (shouldSkipEmptyDirectoryTree(options.path, workspaceDir, entryPath)) {
hasRetainedEntries = true
continue
}

if (collectEmptyDirectories(entryPath)) {
emptyDirsToDelete.add(entryPath)
continue
}

hasRetainedEntries = true
continue
}

if (filesToDelete.has(entryPath)) continue
hasRetainedEntries = true
}

return !hasRetainedEntries
}

collectEmptyDirectories(workspaceDir)

return {
emptyDirsToDelete: [...emptyDirsToDelete].sort((a, b) => a.localeCompare(b))
}
}
9 changes: 6 additions & 3 deletions cli/src/commands/CleanupUtils.adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const nativeBindingMocks = vi.hoisted(() => ({

vi.mock('../core/native-binding', () => ({
getNativeBinding: () => ({
...globalThis.__TNMSC_TEST_NATIVE_BINDING__,
planCleanup: nativeBindingMocks.planCleanup,
performCleanup: nativeBindingMocks.performCleanup
})
Expand Down Expand Up @@ -88,18 +89,20 @@ describe('cleanupUtils native adapter', () => {
nativeBindingMocks.planCleanup.mockReturnValue(JSON.stringify({
filesToDelete: ['/tmp/project-a/AGENTS.md'],
dirsToDelete: ['/tmp/.codex/skills/legacy'],
emptyDirsToDelete: ['/tmp/.codex/skills'],
violations: [],
conflicts: [],
excludedScanGlobs: ['**/.git/**']
}))
nativeBindingMocks.performCleanup.mockReturnValue(JSON.stringify({
deletedFiles: 1,
deletedDirs: 1,
deletedDirs: 2,
errors: [],
violations: [],
conflicts: [],
filesToDelete: ['/tmp/project-a/AGENTS.md'],
dirsToDelete: ['/tmp/.codex/skills/legacy'],
emptyDirsToDelete: ['/tmp/.codex/skills'],
excludedScanGlobs: ['**/.git/**']
}))

Expand All @@ -113,7 +116,7 @@ describe('cleanupUtils native adapter', () => {
const plan = await collectDeletionTargets([plugin], cleanCtx)
expect(plan).toEqual({
filesToDelete: ['/tmp/project-a/AGENTS.md'],
dirsToDelete: ['/tmp/.codex/skills/legacy'],
dirsToDelete: ['/tmp/.codex/skills', '/tmp/.codex/skills/legacy'],
violations: [],
conflicts: [],
excludedScanGlobs: ['**/.git/**']
Expand All @@ -136,7 +139,7 @@ describe('cleanupUtils native adapter', () => {
const result = await performCleanup([plugin], cleanCtx, createMockLogger())
expect(result).toEqual({
deletedFiles: 1,
deletedDirs: 1,
deletedDirs: 2,
errors: [],
violations: [],
conflicts: []
Expand Down
Loading
Loading