clawt 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.claude/agent-memory/docs-sync-updater/MEMORY.md +48 -0
  2. package/.claude/agents/docs-sync-updater.md +128 -0
  3. package/CLAUDE.md +71 -0
  4. package/README.md +168 -0
  5. package/dist/index.js +923 -0
  6. package/dist/postinstall.js +71 -0
  7. package/docs/spec.md +710 -0
  8. package/package.json +38 -0
  9. package/scripts/postinstall.ts +116 -0
  10. package/src/commands/create.ts +49 -0
  11. package/src/commands/list.ts +45 -0
  12. package/src/commands/merge.ts +142 -0
  13. package/src/commands/remove.ts +127 -0
  14. package/src/commands/run.ts +310 -0
  15. package/src/commands/validate.ts +137 -0
  16. package/src/constants/branch.ts +6 -0
  17. package/src/constants/config.ts +8 -0
  18. package/src/constants/exitCodes.ts +9 -0
  19. package/src/constants/index.ts +6 -0
  20. package/src/constants/messages.ts +61 -0
  21. package/src/constants/paths.ts +14 -0
  22. package/src/constants/terminal.ts +13 -0
  23. package/src/errors/index.ts +20 -0
  24. package/src/index.ts +55 -0
  25. package/src/logger/index.ts +34 -0
  26. package/src/types/claudeCode.ts +14 -0
  27. package/src/types/command.ts +39 -0
  28. package/src/types/config.ts +7 -0
  29. package/src/types/index.ts +5 -0
  30. package/src/types/taskResult.ts +31 -0
  31. package/src/types/worktree.ts +7 -0
  32. package/src/utils/branch.ts +51 -0
  33. package/src/utils/config.ts +35 -0
  34. package/src/utils/formatter.ts +67 -0
  35. package/src/utils/fs.ts +28 -0
  36. package/src/utils/git.ts +243 -0
  37. package/src/utils/index.ts +35 -0
  38. package/src/utils/prompt.ts +18 -0
  39. package/src/utils/shell.ts +53 -0
  40. package/src/utils/validation.ts +48 -0
  41. package/src/utils/worktree.ts +107 -0
  42. package/tsconfig.json +17 -0
  43. package/tsup.config.ts +25 -0
@@ -0,0 +1,71 @@
1
+ // scripts/postinstall.ts
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
3
+ import { join as join2 } from "path";
4
+ import { homedir as homedir2 } from "os";
5
+
6
+ // src/constants/paths.ts
7
+ import { homedir } from "os";
8
+ import { join } from "path";
9
+ var CLAWT_HOME = join(homedir(), ".clawt");
10
+ var CONFIG_PATH = join(CLAWT_HOME, "config.json");
11
+ var LOGS_DIR = join(CLAWT_HOME, "logs");
12
+ var WORKTREES_DIR = join(CLAWT_HOME, "worktrees");
13
+
14
+ // src/constants/config.ts
15
+ var DEFAULT_CONFIG = {
16
+ autoDeleteBranch: false,
17
+ /** 默认 Claude Code CLI 启动指令,用于不传 --tasks 时在 worktree 中打开交互式界面 */
18
+ claudeCodeCommand: "claude"
19
+ };
20
+
21
+ // scripts/postinstall.ts
22
+ var CLAWT_HOME2 = join2(homedir2(), ".clawt");
23
+ var CONFIG_PATH2 = join2(CLAWT_HOME2, "config.json");
24
+ var LOGS_DIR2 = join2(CLAWT_HOME2, "logs");
25
+ var WORKTREES_DIR2 = join2(CLAWT_HOME2, "worktrees");
26
+ function ensureDirectory(dirPath) {
27
+ if (!existsSync(dirPath)) {
28
+ mkdirSync(dirPath, { recursive: true });
29
+ }
30
+ }
31
+ function loadExistingConfig(configPath) {
32
+ if (!existsSync(configPath)) {
33
+ return null;
34
+ }
35
+ try {
36
+ const raw = readFileSync(configPath, "utf-8");
37
+ return JSON.parse(raw);
38
+ } catch {
39
+ return null;
40
+ }
41
+ }
42
+ function mergeConfig(existing, defaults) {
43
+ const merged = {};
44
+ for (const key of Object.keys(defaults)) {
45
+ merged[key] = key in existing ? existing[key] : defaults[key];
46
+ }
47
+ return merged;
48
+ }
49
+ function writeConfig(configPath, config, message) {
50
+ writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
51
+ console.log(message);
52
+ }
53
+ function syncConfig(configPath, defaultConfig) {
54
+ const existing = loadExistingConfig(configPath);
55
+ if (!existing) {
56
+ writeConfig(configPath, defaultConfig, `\u2713 \u5DF2\u521B\u5EFA\u9ED8\u8BA4\u914D\u7F6E\u6587\u4EF6: ${configPath}`);
57
+ return;
58
+ }
59
+ const merged = mergeConfig(existing, defaultConfig);
60
+ if (JSON.stringify(existing) !== JSON.stringify(merged)) {
61
+ writeConfig(configPath, merged, `\u2713 \u5DF2\u66F4\u65B0\u914D\u7F6E\u6587\u4EF6: ${configPath}`);
62
+ }
63
+ }
64
+ function init() {
65
+ ensureDirectory(CLAWT_HOME2);
66
+ ensureDirectory(LOGS_DIR2);
67
+ ensureDirectory(WORKTREES_DIR2);
68
+ syncConfig(CONFIG_PATH2, DEFAULT_CONFIG);
69
+ console.log("\u2713 clawt \u521D\u59CB\u5316\u5B8C\u6210");
70
+ }
71
+ init();