mini-trellis 0.1.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 (186) hide show
  1. package/COPYRIGHT +20 -0
  2. package/LICENSE +235 -0
  3. package/README.md +66 -0
  4. package/bin/mini-trellis.js +3 -0
  5. package/dist/cli/index.d.ts +3 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +153 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/commands/init.d.ts +19 -0
  10. package/dist/commands/init.d.ts.map +1 -0
  11. package/dist/commands/init.js +401 -0
  12. package/dist/commands/init.js.map +1 -0
  13. package/dist/commands/mem.d.ts +30 -0
  14. package/dist/commands/mem.d.ts.map +1 -0
  15. package/dist/commands/mem.js +412 -0
  16. package/dist/commands/mem.js.map +1 -0
  17. package/dist/commands/migrate.d.ts +40 -0
  18. package/dist/commands/migrate.d.ts.map +1 -0
  19. package/dist/commands/migrate.js +272 -0
  20. package/dist/commands/migrate.js.map +1 -0
  21. package/dist/commands/uninstall.d.ts +11 -0
  22. package/dist/commands/uninstall.d.ts.map +1 -0
  23. package/dist/commands/uninstall.js +135 -0
  24. package/dist/commands/uninstall.js.map +1 -0
  25. package/dist/commands/upgrade.d.ts +28 -0
  26. package/dist/commands/upgrade.d.ts.map +1 -0
  27. package/dist/commands/upgrade.js +84 -0
  28. package/dist/commands/upgrade.js.map +1 -0
  29. package/dist/configurators/claude.d.ts +3 -0
  30. package/dist/configurators/claude.d.ts.map +1 -0
  31. package/dist/configurators/claude.js +62 -0
  32. package/dist/configurators/claude.js.map +1 -0
  33. package/dist/configurators/codex.d.ts +3 -0
  34. package/dist/configurators/codex.d.ts.map +1 -0
  35. package/dist/configurators/codex.js +21 -0
  36. package/dist/configurators/codex.js.map +1 -0
  37. package/dist/configurators/index.d.ts +24 -0
  38. package/dist/configurators/index.d.ts.map +1 -0
  39. package/dist/configurators/index.js +80 -0
  40. package/dist/configurators/index.js.map +1 -0
  41. package/dist/configurators/opencode.d.ts +2 -0
  42. package/dist/configurators/opencode.d.ts.map +1 -0
  43. package/dist/configurators/opencode.js +62 -0
  44. package/dist/configurators/opencode.js.map +1 -0
  45. package/dist/configurators/pi.d.ts +2 -0
  46. package/dist/configurators/pi.d.ts.map +1 -0
  47. package/dist/configurators/pi.js +18 -0
  48. package/dist/configurators/pi.js.map +1 -0
  49. package/dist/configurators/shared.d.ts +147 -0
  50. package/dist/configurators/shared.d.ts.map +1 -0
  51. package/dist/configurators/shared.js +377 -0
  52. package/dist/configurators/shared.js.map +1 -0
  53. package/dist/configurators/workflow.d.ts +15 -0
  54. package/dist/configurators/workflow.d.ts.map +1 -0
  55. package/dist/configurators/workflow.js +46 -0
  56. package/dist/configurators/workflow.js.map +1 -0
  57. package/dist/constants/paths.d.ts +74 -0
  58. package/dist/constants/paths.d.ts.map +1 -0
  59. package/dist/constants/paths.js +83 -0
  60. package/dist/constants/paths.js.map +1 -0
  61. package/dist/constants/version.d.ts +9 -0
  62. package/dist/constants/version.d.ts.map +1 -0
  63. package/dist/constants/version.js +15 -0
  64. package/dist/constants/version.js.map +1 -0
  65. package/dist/index.d.ts +9 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +9 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/templates/claude/index.d.ts +11 -0
  70. package/dist/templates/claude/index.d.ts.map +1 -0
  71. package/dist/templates/claude/index.js +17 -0
  72. package/dist/templates/claude/index.js.map +1 -0
  73. package/dist/templates/claude/settings.json +40 -0
  74. package/dist/templates/codex/config.toml +39 -0
  75. package/dist/templates/codex/hooks.json +15 -0
  76. package/dist/templates/codex/index.d.ts +11 -0
  77. package/dist/templates/codex/index.d.ts.map +1 -0
  78. package/dist/templates/codex/index.js +22 -0
  79. package/dist/templates/codex/index.js.map +1 -0
  80. package/dist/templates/common/bundled-skills/mini-trellis-session-insight/SKILL.md +37 -0
  81. package/dist/templates/common/bundled-skills/mini-trellis-session-insight/references/cli-quick-reference.md +36 -0
  82. package/dist/templates/common/bundled-skills/mini-trellis-session-insight/references/triggering-patterns.md +93 -0
  83. package/dist/templates/common/commands/remember.md +22 -0
  84. package/dist/templates/common/index.d.ts +48 -0
  85. package/dist/templates/common/index.d.ts.map +1 -0
  86. package/dist/templates/common/index.js +104 -0
  87. package/dist/templates/common/index.js.map +1 -0
  88. package/dist/templates/common/skills/update-spec.md +16 -0
  89. package/dist/templates/extract.d.ts +40 -0
  90. package/dist/templates/extract.d.ts.map +1 -0
  91. package/dist/templates/extract.js +106 -0
  92. package/dist/templates/extract.js.map +1 -0
  93. package/dist/templates/markdown/agents.md +15 -0
  94. package/dist/templates/markdown/index.d.ts +10 -0
  95. package/dist/templates/markdown/index.d.ts.map +1 -0
  96. package/dist/templates/markdown/index.js +18 -0
  97. package/dist/templates/markdown/index.js.map +1 -0
  98. package/dist/templates/markdown/research-readme.md +9 -0
  99. package/dist/templates/markdown/spec/guides/index.md.txt +5 -0
  100. package/dist/templates/markdown/spec/guides/mini-memory.md.txt +30 -0
  101. package/dist/templates/markdown/workspace-index.md +23 -0
  102. package/dist/templates/opencode/lib/context-visibility.js +148 -0
  103. package/dist/templates/opencode/lib/session-utils.js +394 -0
  104. package/dist/templates/opencode/lib/trellis-context.js +627 -0
  105. package/dist/templates/opencode/package.json +5 -0
  106. package/dist/templates/opencode/plugins/session-start.js +65 -0
  107. package/dist/templates/pi/extensions/mini-trellis/index.ts.txt +170 -0
  108. package/dist/templates/pi/index.d.ts +4 -0
  109. package/dist/templates/pi/index.d.ts.map +1 -0
  110. package/dist/templates/pi/index.js +9 -0
  111. package/dist/templates/pi/index.js.map +1 -0
  112. package/dist/templates/pi/settings.json +9 -0
  113. package/dist/templates/shared-hooks/index.d.ts +13 -0
  114. package/dist/templates/shared-hooks/index.d.ts.map +1 -0
  115. package/dist/templates/shared-hooks/index.js +26 -0
  116. package/dist/templates/shared-hooks/index.js.map +1 -0
  117. package/dist/templates/shared-hooks/session-start.py +676 -0
  118. package/dist/templates/template-utils.d.ts +26 -0
  119. package/dist/templates/template-utils.d.ts.map +1 -0
  120. package/dist/templates/template-utils.js +64 -0
  121. package/dist/templates/template-utils.js.map +1 -0
  122. package/dist/templates/trellis/config.yaml +34 -0
  123. package/dist/templates/trellis/gitattributes.txt +9 -0
  124. package/dist/templates/trellis/gitignore.txt +32 -0
  125. package/dist/templates/trellis/index.d.ts +8 -0
  126. package/dist/templates/trellis/index.d.ts.map +1 -0
  127. package/dist/templates/trellis/index.js +16 -0
  128. package/dist/templates/trellis/index.js.map +1 -0
  129. package/dist/templates/trellis/scripts/__init__.py +5 -0
  130. package/dist/templates/trellis/scripts/add_session.py +1545 -0
  131. package/dist/templates/trellis/scripts/common/__init__.py +94 -0
  132. package/dist/templates/trellis/scripts/common/active_task.py +855 -0
  133. package/dist/templates/trellis/scripts/common/cli_adapter.py +950 -0
  134. package/dist/templates/trellis/scripts/common/config.py +482 -0
  135. package/dist/templates/trellis/scripts/common/developer.py +192 -0
  136. package/dist/templates/trellis/scripts/common/git.py +203 -0
  137. package/dist/templates/trellis/scripts/common/git_context.py +106 -0
  138. package/dist/templates/trellis/scripts/common/io.py +160 -0
  139. package/dist/templates/trellis/scripts/common/log.py +45 -0
  140. package/dist/templates/trellis/scripts/common/packages_context.py +238 -0
  141. package/dist/templates/trellis/scripts/common/paths.py +543 -0
  142. package/dist/templates/trellis/scripts/common/safe_commit.py +322 -0
  143. package/dist/templates/trellis/scripts/common/session_context.py +708 -0
  144. package/dist/templates/trellis/scripts/common/task_context.py +470 -0
  145. package/dist/templates/trellis/scripts/common/task_queue.py +188 -0
  146. package/dist/templates/trellis/scripts/common/task_store.py +1930 -0
  147. package/dist/templates/trellis/scripts/common/task_utils.py +498 -0
  148. package/dist/templates/trellis/scripts/common/tasks.py +122 -0
  149. package/dist/templates/trellis/scripts/common/trellis_config.py +239 -0
  150. package/dist/templates/trellis/scripts/common/types.py +110 -0
  151. package/dist/templates/trellis/scripts/common/workflow_phase.py +242 -0
  152. package/dist/templates/trellis/scripts/get_context.py +16 -0
  153. package/dist/templates/trellis/scripts/init_developer.py +51 -0
  154. package/dist/types/ai-tools.d.ts +30 -0
  155. package/dist/types/ai-tools.d.ts.map +1 -0
  156. package/dist/types/ai-tools.js +89 -0
  157. package/dist/types/ai-tools.js.map +1 -0
  158. package/dist/utils/atomic-write.d.ts +12 -0
  159. package/dist/utils/atomic-write.d.ts.map +1 -0
  160. package/dist/utils/atomic-write.js +30 -0
  161. package/dist/utils/atomic-write.js.map +1 -0
  162. package/dist/utils/cwd-guard.d.ts +38 -0
  163. package/dist/utils/cwd-guard.d.ts.map +1 -0
  164. package/dist/utils/cwd-guard.js +62 -0
  165. package/dist/utils/cwd-guard.js.map +1 -0
  166. package/dist/utils/file-writer.d.ts +36 -0
  167. package/dist/utils/file-writer.d.ts.map +1 -0
  168. package/dist/utils/file-writer.js +204 -0
  169. package/dist/utils/file-writer.js.map +1 -0
  170. package/dist/utils/managed-paths.d.ts +5 -0
  171. package/dist/utils/managed-paths.d.ts.map +1 -0
  172. package/dist/utils/managed-paths.js +51 -0
  173. package/dist/utils/managed-paths.js.map +1 -0
  174. package/dist/utils/managed-removal.d.ts +42 -0
  175. package/dist/utils/managed-removal.d.ts.map +1 -0
  176. package/dist/utils/managed-removal.js +223 -0
  177. package/dist/utils/managed-removal.js.map +1 -0
  178. package/dist/utils/posix.d.ts +13 -0
  179. package/dist/utils/posix.d.ts.map +1 -0
  180. package/dist/utils/posix.js +15 -0
  181. package/dist/utils/posix.js.map +1 -0
  182. package/dist/utils/uninstall-scrubbers.d.ts +66 -0
  183. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -0
  184. package/dist/utils/uninstall-scrubbers.js +417 -0
  185. package/dist/utils/uninstall-scrubbers.js.map +1 -0
  186. package/package.json +80 -0
@@ -0,0 +1,89 @@
1
+ /**
2
+ * AI Tool Types and Registry — mini-trellis v1 hosts only.
3
+ */
4
+ export const AI_TOOLS = {
5
+ "claude-code": {
6
+ name: "Claude Code",
7
+ templateDirs: ["common", "claude"],
8
+ configDir: ".claude",
9
+ cliFlag: "claude",
10
+ defaultChecked: true,
11
+ hasPythonHooks: true,
12
+ templateContext: {
13
+ cmdRefPrefix: "/mini-trellis:",
14
+ executorAI: "Bash scripts or Task calls",
15
+ userActionLabel: "Slash commands",
16
+ agentCapable: true,
17
+ hasHooks: true,
18
+ cliFlag: "claude",
19
+ },
20
+ },
21
+ opencode: {
22
+ name: "OpenCode",
23
+ templateDirs: ["common", "opencode"],
24
+ configDir: ".opencode",
25
+ cliFlag: "opencode",
26
+ defaultChecked: false,
27
+ hasPythonHooks: false,
28
+ templateContext: {
29
+ cmdRefPrefix: "/mini-trellis:",
30
+ executorAI: "Bash scripts or Task calls",
31
+ userActionLabel: "Slash commands",
32
+ agentCapable: true,
33
+ hasHooks: true,
34
+ cliFlag: "opencode",
35
+ },
36
+ },
37
+ codex: {
38
+ name: "Codex",
39
+ templateDirs: ["common", "codex"],
40
+ configDir: ".codex",
41
+ supportsAgentSkills: true,
42
+ cliFlag: "codex",
43
+ defaultChecked: false,
44
+ hasPythonHooks: true,
45
+ templateContext: {
46
+ cmdRefPrefix: "$",
47
+ executorAI: "Bash scripts or tool calls",
48
+ userActionLabel: "Skills",
49
+ agentCapable: true,
50
+ hasHooks: true,
51
+ cliFlag: "codex",
52
+ },
53
+ },
54
+ pi: {
55
+ name: "Pi Agent",
56
+ templateDirs: ["common", "pi"],
57
+ configDir: ".pi",
58
+ supportsAgentSkills: true,
59
+ cliFlag: "pi",
60
+ defaultChecked: false,
61
+ hasPythonHooks: false,
62
+ templateContext: {
63
+ cmdRefPrefix: "/mini-trellis-",
64
+ executorAI: "Bash scripts or tool calls",
65
+ userActionLabel: "Slash commands",
66
+ agentCapable: true,
67
+ hasHooks: true,
68
+ cliFlag: "pi",
69
+ },
70
+ },
71
+ };
72
+ export function getToolConfig(tool) {
73
+ return AI_TOOLS[tool];
74
+ }
75
+ export function getManagedPaths(tool) {
76
+ const config = AI_TOOLS[tool];
77
+ const paths = [config.configDir];
78
+ if (config.supportsAgentSkills) {
79
+ paths.push(".agents/skills");
80
+ }
81
+ if (config.extraManagedPaths) {
82
+ paths.push(...config.extraManagedPaths);
83
+ }
84
+ return paths;
85
+ }
86
+ export function getTemplateDirs(tool) {
87
+ return AI_TOOLS[tool].templateDirs;
88
+ }
89
+ //# sourceMappingURL=ai-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-tools.js","sourceRoot":"","sources":["../../src/types/ai-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AA6BH,MAAM,CAAC,MAAM,QAAQ,GAAiC;IACpD,aAAa,EAAE;QACb,IAAI,EAAE,aAAa;QACnB,YAAY,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAClC,SAAS,EAAE,SAAS;QACpB,OAAO,EAAE,QAAQ;QACjB,cAAc,EAAE,IAAI;QACpB,cAAc,EAAE,IAAI;QACpB,eAAe,EAAE;YACf,YAAY,EAAE,gBAAgB;YAC9B,UAAU,EAAE,4BAA4B;YACxC,eAAe,EAAE,gBAAgB;YACjC,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,QAAQ;SAClB;KACF;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,UAAU;QAChB,YAAY,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC;QACpC,SAAS,EAAE,WAAW;QACtB,OAAO,EAAE,UAAU;QACnB,cAAc,EAAE,KAAK;QACrB,cAAc,EAAE,KAAK;QACrB,eAAe,EAAE;YACf,YAAY,EAAE,gBAAgB;YAC9B,UAAU,EAAE,4BAA4B;YACxC,eAAe,EAAE,gBAAgB;YACjC,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,UAAU;SACpB;KACF;IACD,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,YAAY,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;QACjC,SAAS,EAA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Y;IAC1C,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;AACrC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Write a file atomically: stream into a temp file in the same directory,
3
+ * then rename it over the target. A crash, Ctrl-C, or ENOSPC mid-write
4
+ * leaves the original file intact (or absent) — never truncated or
5
+ * half-written. The temp file shares the target's directory so the rename
6
+ * stays on one filesystem and is therefore atomic.
7
+ *
8
+ * On failure the temp file is removed on a best-effort basis and the
9
+ * original error is re-thrown.
10
+ */
11
+ export declare function writeFileAtomic(filePath: string, data: string | Uint8Array): void;
12
+ //# sourceMappingURL=atomic-write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atomic-write.d.ts","sourceRoot":"","sources":["../../src/utils/atomic-write.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GAAG,UAAU,GACxB,IAAI,CAcN"}
@@ -0,0 +1,30 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ /**
4
+ * Write a file atomically: stream into a temp file in the same directory,
5
+ * then rename it over the target. A crash, Ctrl-C, or ENOSPC mid-write
6
+ * leaves the original file intact (or absent) — never truncated or
7
+ * half-written. The temp file shares the target's directory so the rename
8
+ * stays on one filesystem and is therefore atomic.
9
+ *
10
+ * On failure the temp file is removed on a best-effort basis and the
11
+ * original error is re-thrown.
12
+ */
13
+ export function writeFileAtomic(filePath, data) {
14
+ const dir = path.dirname(filePath);
15
+ const tmp = path.join(dir, `.${path.basename(filePath)}.${process.pid}.tmp`);
16
+ try {
17
+ fs.writeFileSync(tmp, data);
18
+ fs.renameSync(tmp, filePath);
19
+ }
20
+ catch (err) {
21
+ try {
22
+ fs.rmSync(tmp, { force: true });
23
+ }
24
+ catch {
25
+ // best-effort cleanup; surface the original write error
26
+ }
27
+ throw err;
28
+ }
29
+ }
30
+ //# sourceMappingURL=atomic-write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atomic-write.js","sourceRoot":"","sources":["../../src/utils/atomic-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAgB,EAChB,IAAyB;IAEzB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;IAC7E,IAAI,CAAC;QACH,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC5B,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC;YACH,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,wDAAwD;QAC1D,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Homedir guard for destructive commands (init, uninstall).
3
+ *
4
+ * Running `trellis init` / `trellis uninstall` in `$HOME` is catastrophic:
5
+ * platforms like Claude Code, Codex, OpenCode all store global runtime data
6
+ * (`.claude/projects/<sanitized-cwd>/*.jsonl` chat history, `.codex/sessions/`,
7
+ * `.opencode/` caches, etc.) directly in the user's home directory. If
8
+ * trellis manages the same `.{platform}/` config dirs and the hash manifest
9
+ * picks up runtime data, uninstall would later unlink it.
10
+ *
11
+ * Subdirectories of home (`~/Documents/projects/foo/`) are NOT blocked — only
12
+ * exact-home match.
13
+ *
14
+ * Bypass: `TRELLIS_ALLOW_HOMEDIR=1`.
15
+ */
16
+ /**
17
+ * Returns true if `process.cwd()` is exactly the user's home directory.
18
+ *
19
+ * Uses `realpathSync.native()` on both sides so symlinks, `..` segments, and
20
+ * case differences (Windows) don't confuse the comparison. On Windows the
21
+ * comparison is also case-insensitive — `C:\Users\Alice` matches
22
+ * `c:\users\alice`.
23
+ *
24
+ * Permissive on lookup failure: if realpath fails for any reason (broken
25
+ * symlink, EACCES, etc.) we return false so a safety check doesn't crash
26
+ * the command.
27
+ */
28
+ export declare function isCwdHomedir(): boolean;
29
+ /**
30
+ * Error message printed by destructive project-state commands when the
31
+ * homedir guard trips.
32
+ */
33
+ export declare function homedirGuardMessage(commandName: "init" | "migrate" | "uninstall" | "ablate" | "restore"): string;
34
+ /**
35
+ * Returns true when the bypass env var is set.
36
+ */
37
+ export declare function homedirBypassEnabled(): boolean;
38
+ //# sourceMappingURL=cwd-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cwd-guard.d.ts","sourceRoot":"","sources":["../../src/utils/cwd-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAYtC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GACnE,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Homedir guard for destructive commands (init, uninstall).
3
+ *
4
+ * Running `trellis init` / `trellis uninstall` in `$HOME` is catastrophic:
5
+ * platforms like Claude Code, Codex, OpenCode all store global runtime data
6
+ * (`.claude/projects/<sanitized-cwd>/*.jsonl` chat history, `.codex/sessions/`,
7
+ * `.opencode/` caches, etc.) directly in the user's home directory. If
8
+ * trellis manages the same `.{platform}/` config dirs and the hash manifest
9
+ * picks up runtime data, uninstall would later unlink it.
10
+ *
11
+ * Subdirectories of home (`~/Documents/projects/foo/`) are NOT blocked — only
12
+ * exact-home match.
13
+ *
14
+ * Bypass: `TRELLIS_ALLOW_HOMEDIR=1`.
15
+ */
16
+ import { realpathSync } from "node:fs";
17
+ import * as os from "node:os";
18
+ /**
19
+ * Returns true if `process.cwd()` is exactly the user's home directory.
20
+ *
21
+ * Uses `realpathSync.native()` on both sides so symlinks, `..` segments, and
22
+ * case differences (Windows) don't confuse the comparison. On Windows the
23
+ * comparison is also case-insensitive — `C:\Users\Alice` matches
24
+ * `c:\users\alice`.
25
+ *
26
+ * Permissive on lookup failure: if realpath fails for any reason (broken
27
+ * symlink, EACCES, etc.) we return false so a safety check doesn't crash
28
+ * the command.
29
+ */
30
+ export function isCwdHomedir() {
31
+ try {
32
+ let cwd = realpathSync.native(process.cwd());
33
+ let home = realpathSync.native(os.homedir());
34
+ if (process.platform === "win32") {
35
+ cwd = cwd.toLowerCase();
36
+ home = home.toLowerCase();
37
+ }
38
+ return cwd === home;
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ }
44
+ /**
45
+ * Error message printed by destructive project-state commands when the
46
+ * homedir guard trips.
47
+ */
48
+ export function homedirGuardMessage(commandName) {
49
+ return (`✗ Refusing to run \`mini-trellis ${commandName}\` in your home directory.\n\n` +
50
+ `mini-trellis manages platform config dirs like .claude/, .codex/, .opencode/, which\n` +
51
+ `in your home directory also contain runtime data from those CLIs (chat history,\n` +
52
+ `session JSONLs, caches). Running here can wipe that data.\n\n` +
53
+ `Run mini-trellis from your project directory instead. If you really want to run in\n` +
54
+ `$HOME, set TRELLIS_ALLOW_HOMEDIR=1.`);
55
+ }
56
+ /**
57
+ * Returns true when the bypass env var is set.
58
+ */
59
+ export function homedirBypassEnabled() {
60
+ return process.env.TRELLIS_ALLOW_HOMEDIR === "1";
61
+ }
62
+ //# sourceMappingURL=cwd-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cwd-guard.js","sourceRoot":"","sources":["../../src/utils/cwd-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY;IAC1B,IAAI,CAAC;QACH,IAAI,GAAG,GAAG,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC7C,IAAI,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACjC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;YACxB,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;QACD,OAAO,GAAG,KAAK,IAAI,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,WAAoE;IAEpE,OAAO,CACL,oCAAoC,WAAW,gCAAgC;QAC/E,uFAAuF;QACvF,mFAAmF;QACnF,+DAA+D;QAC/D,sFAAsF;QACtF,qCAAqC,CACtC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,GAAG,CAAC;AACnD,CAAC"}
@@ -0,0 +1,36 @@
1
+ export type WriteMode = "ask" | "force" | "skip" | "append";
2
+ export interface WriteOptions {
3
+ mode: WriteMode;
4
+ }
5
+ export declare function setWriteMode(mode: WriteMode): void;
6
+ export declare function getWriteMode(): WriteMode;
7
+ /**
8
+ * Begin recording every write into the returned Set. Calls accumulate into the
9
+ * same set until `stopRecordingWrites` runs. POSIX relative paths (relative to
10
+ * `cwd`) are stored, matching `.template-hashes.json` keys.
11
+ *
12
+ * Nested recording sessions are NOT supported — the caller must ensure
13
+ * `stopRecordingWrites` runs before the next `startRecordingWrites`. Failure
14
+ * is silent (the second `start` replaces the first set), so callers should
15
+ * always pair start/stop in try/finally.
16
+ */
17
+ export declare function startRecordingWrites(cwd: string): Set<string>;
18
+ /** End recording. Subsequent writes are not captured until `start` is called again. */
19
+ export declare function stopRecordingWrites(): void;
20
+ /**
21
+ * Write file with conflict handling
22
+ * - If file doesn't exist: write directly
23
+ * - If file exists and content is identical: skip silently
24
+ * - If file exists and mode is 'force': overwrite
25
+ * - If file exists and mode is 'skip': skip
26
+ * - If file exists and mode is 'append': append to end
27
+ * - If file exists and mode is 'ask': prompt user
28
+ */
29
+ export declare function writeFile(filePath: string, content: string, options?: {
30
+ executable?: boolean;
31
+ }): Promise<boolean>;
32
+ /**
33
+ * Ensure directory exists
34
+ */
35
+ export declare function ensureDir(dirPath: string): void;
36
+ //# sourceMappingURL=file-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-writer.d.ts","sourceRoot":"","sources":["../../src/utils/file-writer.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE5D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;CACjB;AASD,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAElD;AAED,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAkBD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAK7D;AAED,uFAAuF;AACvF,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAsCD;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GACjC,OAAO,CAAC,OAAO,CAAC,CA0HlB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE/C"}
@@ -0,0 +1,204 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import chalk from "chalk";
4
+ import inquirer from "inquirer";
5
+ import { writeFileAtomic } from "./atomic-write.js";
6
+ import { toPosix } from "./posix.js";
7
+ // Global write mode (set from CLI options)
8
+ let globalWriteMode = "ask";
9
+ export function setWriteMode(mode) {
10
+ globalWriteMode = mode;
11
+ }
12
+ export function getWriteMode() {
13
+ return globalWriteMode;
14
+ }
15
+ // ---------------------------------------------------------------------------
16
+ // Write recording
17
+ //
18
+ // `trellis init` uses recording to capture exactly which files were actually
19
+ // written this run (vs skipped because they already existed). The captured
20
+ // set is what `.template-hashes.json` should contain — NOT a blind directory
21
+ // walk of `.codex/` / `.claude/` / etc, which would include user-owned files
22
+ // that pre-dated init. See `pruneOrphanManifestKeys` for the self-heal side
23
+ // of the same contract.
24
+ // ---------------------------------------------------------------------------
25
+ /** When recording is active, every actual `writeFile` disk write appends here. */
26
+ let writeRecorder = null;
27
+ /** Project root used to convert absolute write paths to POSIX-relative keys. */
28
+ let writeRecorderRoot = null;
29
+ /**
30
+ * Begin recording every write into the returned Set. Calls accumulate into the
31
+ * same set until `stopRecordingWrites` runs. POSIX relative paths (relative to
32
+ * `cwd`) are stored, matching `.template-hashes.json` keys.
33
+ *
34
+ * Nested recording sessions are NOT supported — the caller must ensure
35
+ * `stopRecordingWrites` runs before the next `startRecordingWrites`. Failure
36
+ * is silent (the second `start` replaces the first set), so callers should
37
+ * always pair start/stop in try/finally.
38
+ */
39
+ export function startRecordingWrites(cwd) {
40
+ const sink = new Set();
41
+ writeRecorder = sink;
42
+ writeRecorderRoot = cwd;
43
+ return sink;
44
+ }
45
+ /** End recording. Subsequent writes are not captured until `start` is called again. */
46
+ export function stopRecordingWrites() {
47
+ writeRecorder = null;
48
+ writeRecorderRoot = null;
49
+ }
50
+ /** Record a successful write. Called internally by `writeFile`. */
51
+ function recordWrite(absPath) {
52
+ if (!writeRecorder || !writeRecorderRoot)
53
+ return;
54
+ const rel = path.relative(writeRecorderRoot, absPath);
55
+ // Defensive: skip writes outside cwd (no meaningful manifest key).
56
+ if (rel.startsWith("..") || path.isAbsolute(rel))
57
+ return;
58
+ writeRecorder.add(toPosix(rel));
59
+ }
60
+ /**
61
+ * Get relative path from cwd for display
62
+ */
63
+ function getRelativePath(filePath) {
64
+ const cwd = process.cwd();
65
+ const relativePath = path.relative(cwd, filePath);
66
+ return relativePath || path.basename(filePath);
67
+ }
68
+ /**
69
+ * Append content to file
70
+ */
71
+ function appendToFile(filePath, content, options) {
72
+ const existingContent = fs.readFileSync(filePath, "utf-8");
73
+ const newContent = existingContent.endsWith("\n")
74
+ ? existingContent + content
75
+ : existingContent + "\n" + content;
76
+ writeFileAtomic(filePath, newContent);
77
+ if (options?.executable) {
78
+ fs.chmodSync(filePath, "755");
79
+ }
80
+ }
81
+ /**
82
+ * Write file with conflict handling
83
+ * - If file doesn't exist: write directly
84
+ * - If file exists and content is identical: skip silently
85
+ * - If file exists and mode is 'force': overwrite
86
+ * - If file exists and mode is 'skip': skip
87
+ * - If file exists and mode is 'append': append to end
88
+ * - If file exists and mode is 'ask': prompt user
89
+ */
90
+ export async function writeFile(filePath, content, options) {
91
+ const exists = fs.existsSync(filePath);
92
+ const displayPath = getRelativePath(filePath);
93
+ if (!exists) {
94
+ // File doesn't exist, write directly
95
+ writeFileAtomic(filePath, content);
96
+ if (options?.executable) {
97
+ fs.chmodSync(filePath, "755");
98
+ }
99
+ recordWrite(filePath);
100
+ return true;
101
+ }
102
+ // File exists, check if content is identical
103
+ const existingContent = fs.readFileSync(filePath, "utf-8");
104
+ if (existingContent === content) {
105
+ // Content identical, but no disk write happened. Do not record it for
106
+ // init-time manifests: pre-existing user files can legitimately be
107
+ // byte-identical to a Trellis template and still not be Trellis-owned.
108
+ return false;
109
+ }
110
+ // File exists with different content, handle based on mode.
111
+ // Non-TTY (CI, pipes, scripted runs): never prompt — fall back to skip
112
+ // rather than crash with ERR_USE_AFTER_CLOSE if a CLI flag forgot to call
113
+ // setWriteMode. Layer-level safety net for the init.ts mapping.
114
+ const mode = globalWriteMode === "ask" && !process.stdin.isTTY
115
+ ? "skip"
116
+ : globalWriteMode;
117
+ if (mode === "force") {
118
+ writeFileAtomic(filePath, content);
119
+ if (options?.executable) {
120
+ fs.chmodSync(filePath, "755");
121
+ }
122
+ console.log(chalk.yellow(` ↻ Overwritten: ${displayPath}`));
123
+ recordWrite(filePath);
124
+ return true;
125
+ }
126
+ if (mode === "skip") {
127
+ console.log(chalk.gray(` ○ Skipped: ${displayPath} (already exists)`));
128
+ // Skipped: trellis did NOT write this file — caller should not track it
129
+ // in the manifest. This is the AGENTS.md skip-existing case.
130
+ return false;
131
+ }
132
+ if (mode === "append") {
133
+ appendToFile(filePath, content, options);
134
+ console.log(chalk.blue(` + Appended: ${displayPath}`));
135
+ // Append: trellis added trellis content to a user-owned file. Tracking
136
+ // is risky here (uninstall would unlink the whole file), so we do NOT
137
+ // record appended files. Users on `--append` get a fresh manifest miss
138
+ // on next update; that's the safer default.
139
+ return true;
140
+ }
141
+ // mode === 'ask': Interactive prompt
142
+ const { action } = await inquirer.prompt([
143
+ {
144
+ type: "list",
145
+ name: "action",
146
+ message: `File "${displayPath}" already exists. What would you like to do?`,
147
+ choices: [
148
+ { name: "Skip (keep existing)", value: "skip" },
149
+ { name: "Overwrite", value: "overwrite" },
150
+ { name: "Append to end", value: "append" },
151
+ { name: "Skip all remaining conflicts", value: "skip-all" },
152
+ { name: "Overwrite all remaining conflicts", value: "overwrite-all" },
153
+ { name: "Append all remaining conflicts", value: "append-all" },
154
+ ],
155
+ },
156
+ ]);
157
+ if (action === "skip") {
158
+ console.log(chalk.gray(` ○ Skipped: ${displayPath}`));
159
+ return false;
160
+ }
161
+ if (action === "overwrite") {
162
+ writeFileAtomic(filePath, content);
163
+ if (options?.executable) {
164
+ fs.chmodSync(filePath, "755");
165
+ }
166
+ console.log(chalk.yellow(` ↻ Overwritten: ${displayPath}`));
167
+ recordWrite(filePath);
168
+ return true;
169
+ }
170
+ if (action === "append") {
171
+ appendToFile(filePath, content, options);
172
+ console.log(chalk.blue(` + Appended: ${displayPath}`));
173
+ return true;
174
+ }
175
+ if (action === "skip-all") {
176
+ globalWriteMode = "skip";
177
+ console.log(chalk.gray(` ○ Skipped: ${displayPath}`));
178
+ return false;
179
+ }
180
+ if (action === "overwrite-all") {
181
+ globalWriteMode = "force";
182
+ writeFileAtomic(filePath, content);
183
+ if (options?.executable) {
184
+ fs.chmodSync(filePath, "755");
185
+ }
186
+ console.log(chalk.yellow(` ↻ Overwritten: ${displayPath}`));
187
+ recordWrite(filePath);
188
+ return true;
189
+ }
190
+ if (action === "append-all") {
191
+ globalWriteMode = "append";
192
+ appendToFile(filePath, content, options);
193
+ console.log(chalk.blue(` + Appended: ${displayPath}`));
194
+ return true;
195
+ }
196
+ return false;
197
+ }
198
+ /**
199
+ * Ensure directory exists
200
+ */
201
+ export function ensureDir(dirPath) {
202
+ fs.mkdirSync(dirPath, { recursive: true });
203
+ }
204
+ //# sourceMappingURL=file-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-writer.js","sourceRoot":"","sources":["../../src/utils/file-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAYrC,2CAA2C;AAC3C,IAAI,eAAe,GAAc,KA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Remove empty managed parents without deleting a managed root directory. */
4
+ export declare function cleanupEmptyDirs(cwd: string, dirPath: string): void;
5
+ //# sourceMappingURL=managed-paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-paths.d.ts","sourceRoot":"","sources":["../../src/utils/managed-paths.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAC5D,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AAExD,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAqDnE"}
@@ -0,0 +1,51 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { isManagedPath, isManagedRootDir } from "../configurators/index.js";
4
+ export const TRELLIS_BLOCK_START = "<!-- TRELLIS:START -->";
5
+ export const TRELLIS_BLOCK_END = "<!-- TRELLIS:END -->";
6
+ /** Remove empty managed parents without deleting a managed root directory. */
7
+ export function cleanupEmptyDirs(cwd, dirPath) {
8
+ const dirPosix = dirPath.replace(/\\/g, "/");
9
+ const segments = dirPosix.split("/");
10
+ if (path.posix.isAbsolute(dirPosix) ||
11
+ segments.some((segment) => segment === "" || segment === "." || segment === "..") ||
12
+ !isManagedPath(dirPosix) ||
13
+ isManagedRootDir(dirPosix)) {
14
+ return;
15
+ }
16
+ const canonicalCwd = fs.realpathSync(cwd);
17
+ const fullPath = path.resolve(canonicalCwd, ...segments);
18
+ const relative = path.relative(canonicalCwd, fullPath);
19
+ if (relative === "" ||
20
+ relative === ".." ||
21
+ relative.startsWith(`..${path.sep}`) ||
22
+ path.isAbsolute(relative)) {
23
+ return;
24
+ }
25
+ if (!fs.existsSync(fullPath))
26
+ return;
27
+ try {
28
+ const canonicalFullPath = fs.realpathSync(fullPath);
29
+ const canonicalRelative = path.relative(canonicalCwd, canonicalFullPath);
30
+ if (canonicalRelative === "" ||
31
+ canonicalRelative === ".." ||
32
+ canonicalRelative.startsWith(`..${path.sep}`) ||
33
+ path.isAbsolute(canonicalRelative)) {
34
+ return;
35
+ }
36
+ const stat = fs.lstatSync(fullPath);
37
+ if (!stat.isDirectory() || stat.isSymbolicLink())
38
+ return;
39
+ if (fs.readdirSync(fullPath).length === 0) {
40
+ fs.rmdirSync(fullPath);
41
+ const parent = path.posix.dirname(dirPosix);
42
+ if (parent !== "." && parent !== dirPosix && !isManagedRootDir(parent)) {
43
+ cleanupEmptyDirs(cwd, parent);
44
+ }
45
+ }
46
+ }
47
+ catch {
48
+ // Cleanup is best-effort; permission/race failures leave the directory.
49
+ }
50
+ }
51
+ //# sourceMappingURL=managed-paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-paths.js","sourceRoot":"","sources":["../../src/utils/managed-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAC5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAExD,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,OAAe;IAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAErC,IACE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC;QAC/B,QAAQ,CAAC,IAAI,CACX,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,CACnE;QACD,CAAC,aAAa,CAAC,QAAQ,CAAC;QACxB,gBAAgB,CAAC,QAAQ,CAAC,EAC1B,C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,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC5C,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;gBACvE,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,wEAAwE;IAC1E,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Ownership-aware removal planning for `uninstall`.
3
+ * Paths come from the current platform template maps, not a hash manifest.
4
+ */
5
+ import fs from "node:fs";
6
+ import { type ScrubResult } from "./uninstall-scrubbers.js";
7
+ export interface StructuredFileSpec {
8
+ posixPath: string;
9
+ reason: string;
10
+ scrub: (content: string, deletedPaths: readonly string[]) => ScrubResult;
11
+ }
12
+ export interface PlannedDeletion {
13
+ posixPath: string;
14
+ absPath: string;
15
+ missing: boolean;
16
+ }
17
+ export interface PlannedModification {
18
+ posixPath: string;
19
+ absPath: string;
20
+ reason: string;
21
+ result: ScrubResult;
22
+ }
23
+ export interface ManagedRemovalPlan {
24
+ deletions: PlannedDeletion[];
25
+ modifications: PlannedModification[];
26
+ removeTrellisDir: boolean;
27
+ allPosixPaths: string[];
28
+ }
29
+ export interface BuildManagedRemovalPlanOptions {
30
+ strictPaths?: boolean;
31
+ }
32
+ export declare function lstatIfPresent(absPath: string): fs.Stats | null;
33
+ export declare function validateManagedRelativePath(posixPath: string): void;
34
+ export declare function assertSafeManagedPath(projectRoot: string, posixPath: string): string;
35
+ export declare function buildStructuredFileSpecs(): Map<string, StructuredFileSpec>;
36
+ export declare function buildManagedRemovalPlan(cwd: string, hashes: Record<string, string>, options?: BuildManagedRemovalPlanOptions): ManagedRemovalPlan;
37
+ export declare function executeManagedRemovalPlan(cwd: string, plan: ManagedRemovalPlan): {
38
+ deletedFiles: number;
39
+ modifiedFiles: number;
40
+ deletedDirs: number;
41
+ };
42
+ //# sourceMappingURL=managed-removal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-removal.d.ts","sourceRoot":"","sources":["../../src/utils/managed-removal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AAKzB,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,0BAA0B,CAAC;AAOlC,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,MAAM,EAAE,KAAK,WAAW,CAAC;CAC1E;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACrC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,8BAA8B;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,EAAE,CAAC,KAAK,GAAG,IAAI,CAO/D;AAsBD,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAwBnE;AAED,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,MAAM,CAqBR;AAED,wBAAgB,wBAAwB,IAAI,GAAG,CAAC,MAAM,EA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