Repository navigation
refactor: organize tools/ into a distilly package without changing any command - #212
Open
titanwings wants to merge 4 commits into
Open
titanwings wants to merge 4 commits into
titanwings wants to merge 4 commits into
Conversation
Records each script's --help options, subcommands and public names, and checks them from the repository and from a freshly installed copy. Also checks that every tools/ path named in SKILL.md, prompts and the install guides exists. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N65qP8LxH1kiQynvqf5JLf
The four collectors read and wrote their ~/.distilly config with four copies of the same code; feishu_browser and the DingTalk collector each had the Chrome profile lookup; owner_profile and owner_sources each resolved the OpenClaw workspace. They now call tools/distilly/core. Module names that tests and callers use (CONFIG_PATH, load_config, get_default_chrome_profile, openclaw_workspace, ...) stay in place. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N65qP8LxH1kiQynvqf5JLf
…write and install layers
Implementations now live in tools/distilly/:
core/ config, credentials, hosts, paths, chrome
collect/ feishu/{auto,mcp,browser,export}, dingtalk, slack, mailbox,
owner_sources, research/{xquik,subtitles,transcribe}
profile/ presets, schema, owner, research_merge, quality
write/ writer, versions
install/ creator, generated, claude
Every old script and module path under tools/ and tools/research/ is
kept as a short entry point. Run as a script it calls the package's
main(); imported, it replaces itself with the package module, so
existing imports and mock.patch targets keep working. The four
sys.path.insert lines are gone because running tools/<script>.py
already puts tools/ on the import path.
install_generated_skill.py and install_generated_skill_common.py now
share one module, install/generated.py.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N65qP8LxH1kiQynvqf5JLf
…over generated hosts write/writer.py was 719 lines covering templates, rendering, patch merging, corrections, storage, host installs and the CLI. Rendering now lives in write/render.py and patch/correction handling in write/patch.py; the writer re-exports those names so tools/skill_writer.py importers keep working. The OpenClaw and Codex install branches after create/update were two copies of the same code; they are one loop over a small host table. The flags, defaults and printed lines are unchanged. tests/test_generated_output_golden.py records a full run (create, update, correction, rollback, list, every installer) made with the code before this refactor and checks the refactored code writes the same files and prints the same output. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N65qP8LxH1kiQynvqf5JLf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Tianyi · project thread
Summary
Before:
tools/held 19 flat scripts. Four collectors each had their own copy of the config read/write code and their ownsys.path.insert. The Chrome-profile and OpenClaw-workspace lookups were each written twice, andskill_writer.py(719 lines) covered templates, rendering, patching, corrections, storage, host installs and the CLI all at once.After: the code lives in a
tools/distilly/package with layers:core/(config, credentials, hosts, paths, chrome),collect/,profile/,write/andinstall/. Every script and module path undertools/andtools/research/still exists as a short entry point. SKILL.md, prompts, INSTALL guides, the npm installer and the existing imports work unchanged.How: each old path is now about 6 lines. Run as a script, it calls the package's
main(). Imported, it replaces itself insys.moduleswith the package module, soimport skill_writerandmock.patch.object(feishu_auto_collector, ...)reach the real code. Runningpython3 tools/<script>.pyalready putstools/on the import path, so the package needs no path edits. The installers already copiedtools/whole, so the package ships automatically.Changes
One commit per phase. CI is green on each commit, so any of them can be reverted on its own.
tests/test_cli_contract.py)--helpoptions, its subcommands and its public names.tools/path named in SKILL.md, prompts and INSTALL exists.tools/distilly/core/config.pyholds the collectors'~/.distillyconfig read/write, with the legacy~/.colleague-skillfallback and mode 0600.chrome.pyholds the Chrome profile lookup.paths.pyholds the OpenClaw workspace lookup.CONFIG_PATH,load_config,get_default_chrome_profileandopenclaw_workspacestay on each module.__main__blocks.sys.path.insertlines are gone.install_generated_skill.pyandinstall_generated_skill_common.pynow shareinstall/generated.py.write/render.py(templates and rendering) andwrite/patch.py(patch merge and corrections) were split out of the writer. The writer re-exports their names.tests/test_generated_output_golden.py. It records a full run with the pre-refactor code: create, update, correction, rollback, list, every installer and two error paths, writing 70 files and printing 19 outputs. It then checks that the refactored code writes the same files and prints the same output.Not in this PR:
get_tenant_tokenon the collector module itself, so moving them would need test changes. I left them for a separate decision.distillycommand and the Feishu/Lark wording (phases 4 and 5).Motivation
Make
tools/easier to read and change without breaking any existing command, skill flow, collector or generated skill. Plan and diagrams: https://claude.ai/artifact/Nk9ci88xFF9W5PuNFovZe5Testing
python -m unittest discover -s tests -p 'test_*.py': 134 tests OK on Python 3.13 and on Python 3.9.25, withrequirements.txtandrequirements-optional.txtinstalled. Base dot-skill has 123 tests; this PR adds 11.python -m compileall tools/andruff check tools/ tests/pass.pypinyininstalled.node bin/distilly.mjs --check-packagepasses.HOME=<tmp> node bin/distilly.mjs install codexsucceeds. From the installed copy,owner_sources.py discover --jsonandinstall_distilly.py --host pi --dry-runboth run.Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01N65qP8LxH1kiQynvqf5JLf
Generated by Claude Code