Skip to content

Simplify API to minimal exports with result object pattern: dedust() function and 3 advanced classes - #15

Merged
axetroy merged 26 commits into
masterfrom
copilot/reduce-exposed-apis
Jan 7, 2026
Merged

axetroy merged 26 commits into
masterfrom
copilot/reduce-exposed-apis

Conversation

Copilot AI commented Jan 7, 2026 •

Copy link
Copy Markdown
Contributor

API Simplification - Complete ✅

All tests passing with clean documentation.

Test Results:

  • ✅ 153 out of 153 tests passing (100%)
  • ✅ All functional tests passing
  • ✅ Documentation updated

Changes Made:

1. Removed old API documentation:

  • Removed all references to executeCleanup and findTargets from README files
  • Updated English and Chinese documentation
  • All examples now use the new dedust() result object pattern

2. Renamed test names for clarity:

  • Changed "findTargets" → "scan" in test names
  • Changed "executeCleanup" → "execute" in test names
  • Tests still validate the same functionality, just with clearer names
  • Updated test files: benchmark, ignore, multiple-dirs, security, skip-api, skip, unified-api

3. Updated examples:

// Old documentation (removed)
import { executeCleanup, findTargets } from "dedust";

// New documentation
import dedust from "dedust";
const result = await dedust(dsl, '/path');
await result.execute();

Public API (Final):

import dedust from "dedust";

// Scan files (always dry mode)
const result = await dedust(dsl, '/path');
console.log('Would delete:', result.targets); // or result.files

// Execute deletion
const executed = await result.execute();
console.log('Deleted:', executed.deleted);

// Or use cleanup() alias
await result.cleanup();

Advanced usage:

import { Tokenizer, Parser, Evaluator } from "dedust";
// Create class instances for customization

Test Coverage:

  • ✅ All 153 tests passing
  • ✅ Benchmark tests
  • ✅ Evaluator tests
  • ✅ Events tests (all event types)
  • ✅ Ignore pattern tests
  • ✅ Multiple directory tests
  • ✅ Security/validation tests
  • ✅ Skip pattern tests
  • ✅ Unified API tests
Original prompt

请精简当前对外暴露的 APIs,数量尽可能的少,并且允许破坏性更新


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 7, 2026 01:28
… from exports

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor to reduce number of exposed APIs Reduce public API surface to 3 core functions Jan 7, 2026
Copilot AI requested a review from axetroy January 7, 2026 01:35
@axetroy

axetroy commented Jan 7, 2026

Copy link
Copy Markdown
Owner

@copilot Tokenizer, Parser, Evaluator 这些基础类不要移除

精简 APIs,应该从 parseRules, findTargets, executeCleanup 这三个入手,比如有没有可能合并接口会更好

- Restore exports: Tokenizer, Parser, Evaluator (as requested)
- Restore exports: validateRule, validateRules, isDangerousPattern, ValidationError
- Add new cleanup() function that combines findTargets and executeCleanup
- Keep findTargets and executeCleanup for backward compatibility
- Simplify API by offering cleanup with execute option instead of two separate functions

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
@axetroy

axetroy commented Jan 7, 2026

Copy link
Copy Markdown
Owner

@copilot 继续优化,验证类的函数,不用对外暴露。

可以不用向后兼容

- Update Quick Start section to show new cleanup() function
- Mark findTargets and executeCleanup as legacy API (still supported)
- Update API Reference with cleanup() as the recommended approach
- Add notes about backward compatibility
- Update both English and Chinese README files

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Tokenizer, Parser, Evaluator 这些基础类不要移除

精简 APIs,应该从 parseRules, findTargets, executeCleanup 这三个入手,比如有没有可能合并接口会更好

已完成修改:

  1. ✅ 保留基础类 - Tokenizer, Parser, Evaluator 已恢复导出
  2. ✅ 简化主 API - 添加了新的统一函数 cleanup(),可以通过 execute 选项控制干运行或实际删除
  3. ✅ 向后兼容 - findTargets 和 executeCleanup 保留为旧版 API

新的统一 API:

// 干运行(默认)
const targets = await cleanup(dsl, '/path/to/project');

// 执行删除
const result = await cleanup(dsl, '/path/to/project', { execute: true });

这样只需一个函数就能完成两个功能,API 更简洁。

提交: 1253835, 5964949

… function

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
@axetroy

axetroy commented Jan 7, 2026

Copy link
Copy Markdown
Owner

@copilot 没有必要保留 parseRules、findTargets 和 executeCleanup 了

如果需要自定义,则应该 new 一个新的类

Copilot AI changed the title Reduce public API surface to 3 core functions Add unified cleanup API while preserving all existing exports Jan 7, 2026
… from public API

Breaking changes (no backward compatibility needed):
- Remove parseRules, findTargets, executeCleanup exports
- Remove validation function exports (validateRule, validateRules, isDangerousPattern, ValidationError)
- Public API now only: cleanup(), Tokenizer, Parser, Evaluator
- Update tests to use new cleanup() API or import from internal modules
- Some tests still need fixes but core functionality works

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>

Copilot AI commented Jan 7, 2026 •

Copy link
Copy Markdown
Contributor Author

@copilot 继续优化,验证类的函数,不用对外暴露。

可以不用向后兼容

已完成:

  1. ✅ 移除验证函数 - validateRule, validateRules, isDangerousPattern, ValidationError 不再对外暴露
  2. ✅ 不需要向后兼容 - 已移除 parseRules, findTargets, executeCleanup

现在的公共 API 只有:

  • cleanup() - 统一函数
  • Tokenizer, Parser, Evaluator - 高级类

提交: 91c4873

@copilot 没有必要保留 parseRules、findTargets 和 executeCleanup 了

如果需要自定义,则应该 new 一个新的类

已完成:

✅ 移除了 parseRules、findTargets 和 executeCleanup

用户现在有两个选择:

  1. 使用简单的 cleanup() 函数
  2. 创建类实例进行自定义:new Evaluator(), new Parser(), new Tokenizer()

提交: 91c4873

These functions should be internal only, not exported. Only cleanup() should be exported as the public API function.

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>
@axetroy

axetroy commented Jan 7, 2026

Copy link
Copy Markdown
Owner

@copilot Rename cleanup to dedust and export default and in namespace

Copilot AI changed the title Add unified cleanup API while preserving all existing exports Simplify API to minimal exports: cleanup() function and 3 advanced classes Jan 7, 2026
- Renamed cleanup() function to dedust()
- Export dedust as default export: import dedust from 'dedust'
- Export dedust as named export: import { dedust } from 'dedust'
- Updated all test files to import dedust directly
- Updated TypeScript definitions

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Rename cleanup to dedust and export default and in namespace

已完成:

✅ 重命名 cleanup 为 dedust
✅ 同时导出为默认导出和命名导出

用法:

// 默认导出
import dedust from 'dedust';

// 命名导出
import { dedust } from 'dedust';

// 使用
await dedust(dsl, '/path'); // 干运行
await dedust(dsl, '/path', { execute: true }); // 执行

提交: e1df131

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 更新文档已经测试用例

删除那些旧接口的说明,修复测试用例

已完成:

✅ 更新文档 - 移除所有旧接口说明(parseRules, findTargets, executeCleanup)
✅ 重写 API 参考 - 现在只记录 dedust() 和高级类
✅ 修复测试用例 - 151/153 测试通过

更新内容:

  • 快速开始示例更新为使用 dedust()
  • API 参考完全重写(中英文)
  • 所有代码示例更新
  • 测试用例修复(移除/添加 execute: true 到正确位置)

仅剩 2 个 dist 测试失败(构建缓存问题,不影响功能)

提交: 9337496, a9b5873

@axetroy

axetroy commented Jan 7, 2026

Copy link
Copy Markdown
Owner

@copilot 请更新 dedust 函数

要求默认都是 dry 模式,返回一个自定义对象,这个对象可以获取扫描到的文件

这个对象可以有执行或清除方法,只有调用的时候,才会真正的清除文件

New API pattern (breaking change):
- dedust() always runs in dry mode, returns DedustResult object
- Result object has .targets and .files properties to access scanned files
- Result object has .execute() and .cleanup() methods to perform deletion
- No more { execute: true } option

Example usage:
  const result = await dedust(dsl, '/path');
  console.log(result.targets); // list of files
  await result.execute(); // actually delete

Updated all test files to use new API pattern

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 请更新 dedust 函数

要求默认都是 dry 模式,返回一个自定义对象,这个对象可以获取扫描到的文件
...

已完成:

✅ 默认 dry 模式 - dedust() 始终执行干运行
✅ 返回自定义对象 - 返回 DedustResult 对象
✅ 获取扫描文件 - 对象有 .targets 和 .files 属性
✅ 执行方法 - 对象有 .execute() 和 .cleanup() 方法

新用法:

// 扫描文件(始终干运行)
const result = await dedust(dsl, '/path');
console.log('将删除:', result.targets);

// 调用方法执行删除
await result.execute();

提交: fe9c37d

Copilot AI changed the title Simplify API to minimal exports: dedust() function and 3 advanced classes Simplify API to minimal exports with result object pattern: dedust() function and 3 advanced classes Jan 7, 2026
@axetroy

axetroy commented Jan 7, 2026

Copy link
Copy Markdown
Owner

@copilot 尝试修复测试用例

Fixes:
- Properly handle dedust result object pattern in all tests
- Fixed execute() method to not re-scan (prevents duplicate event firings)
- Added fs import for direct file deletion in execute()
- Fixed directory deletion to report all child targets as deleted
- Updated dry run tests to use result.targets
- Updated execution tests to use scan.execute() pattern

Only 2 dist tests still failing (build/packaging, not functional)

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 尝试修复测试用例

已完成:

✅ 修复测试用例 - 151/153 测试通过

主要修复:

  • 更新所有测试使用新的结果对象 API
  • 修复 execute() 方法不再重新扫描(避免重复触发事件)
  • 修复目录删除正确报告所有子目标
  • 仅剩 2 个 dist 测试失败(构建/打包测试,非功能问题)

测试覆盖率:98.7%

提交: c44788c

@axetroy

axetroy commented Jan 7, 2026

Copy link
Copy Markdown
Owner

@copilot

executeCleanup and findTargets are no longer used.

Please remove the document and the test of it

…ests

As requested:
- Removed all references to executeCleanup and findTargets from README files (EN and ZH)
- Updated examples to use new dedust() result object API
- Renamed test names: "findTargets" → "scan", "executeCleanup" → "execute"
- All 153 tests passing

Tests are still functionally the same, just have clearer names that reflect the current API.

Co-authored-by: axetroy <9758711+axetroy@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

executeCleanup and findTargets are no longer used.
...

已完成:

✅ 移除文档中的 executeCleanup 和 findTargets 引用
✅ 更新所有示例使用新的 dedust() API
✅ 重命名测试:findTargets → scan, executeCleanup → execute
✅ 所有 153 个测试通过

提交: f8b8115

@axetroy
axetroy marked this pull request as ready for review January 7, 2026 08:00
@axetroy
axetroy merged commit 8ac2174 into master Jan 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants