@oh-my-pi/cli 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 (89) hide show
  1. package/.github/workflows/ci.yml +32 -0
  2. package/.github/workflows/publish.yml +42 -0
  3. package/CHECK.md +352 -0
  4. package/README.md +224 -0
  5. package/biome.json +29 -0
  6. package/bun.lock +50 -0
  7. package/dist/cli.d.ts +3 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +3941 -0
  10. package/dist/commands/create.d.ts +9 -0
  11. package/dist/commands/create.d.ts.map +1 -0
  12. package/dist/commands/doctor.d.ts +10 -0
  13. package/dist/commands/doctor.d.ts.map +1 -0
  14. package/dist/commands/enable.d.ts +13 -0
  15. package/dist/commands/enable.d.ts.map +1 -0
  16. package/dist/commands/info.d.ts +9 -0
  17. package/dist/commands/info.d.ts.map +1 -0
  18. package/dist/commands/init.d.ts +8 -0
  19. package/dist/commands/init.d.ts.map +1 -0
  20. package/dist/commands/install.d.ts +13 -0
  21. package/dist/commands/install.d.ts.map +1 -0
  22. package/dist/commands/link.d.ts +10 -0
  23. package/dist/commands/link.d.ts.map +1 -0
  24. package/dist/commands/list.d.ts +9 -0
  25. package/dist/commands/list.d.ts.map +1 -0
  26. package/dist/commands/outdated.d.ts +9 -0
  27. package/dist/commands/outdated.d.ts.map +1 -0
  28. package/dist/commands/search.d.ts +9 -0
  29. package/dist/commands/search.d.ts.map +1 -0
  30. package/dist/commands/uninstall.d.ts +9 -0
  31. package/dist/commands/uninstall.d.ts.map +1 -0
  32. package/dist/commands/update.d.ts +9 -0
  33. package/dist/commands/update.d.ts.map +1 -0
  34. package/dist/commands/why.d.ts +9 -0
  35. package/dist/commands/why.d.ts.map +1 -0
  36. package/dist/conflicts.d.ts +21 -0
  37. package/dist/conflicts.d.ts.map +1 -0
  38. package/dist/index.d.ts +20 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/manifest.d.ts +81 -0
  41. package/dist/manifest.d.ts.map +1 -0
  42. package/dist/migrate.d.ts +9 -0
  43. package/dist/migrate.d.ts.map +1 -0
  44. package/dist/npm.d.ts +77 -0
  45. package/dist/npm.d.ts.map +1 -0
  46. package/dist/paths.d.ts +27 -0
  47. package/dist/paths.d.ts.map +1 -0
  48. package/dist/symlinks.d.ts +33 -0
  49. package/dist/symlinks.d.ts.map +1 -0
  50. package/package.json +36 -0
  51. package/plugins/metal-theme/README.md +13 -0
  52. package/plugins/metal-theme/omp.json +8 -0
  53. package/plugins/metal-theme/package.json +14 -0
  54. package/plugins/metal-theme/themes/metal.json +79 -0
  55. package/plugins/subagents/README.md +25 -0
  56. package/plugins/subagents/agents/explore.md +71 -0
  57. package/plugins/subagents/agents/planner.md +51 -0
  58. package/plugins/subagents/agents/reviewer.md +53 -0
  59. package/plugins/subagents/agents/task.md +46 -0
  60. package/plugins/subagents/commands/architect-plan.md +9 -0
  61. package/plugins/subagents/commands/implement-with-critic.md +10 -0
  62. package/plugins/subagents/commands/implement.md +10 -0
  63. package/plugins/subagents/omp.json +15 -0
  64. package/plugins/subagents/package.json +21 -0
  65. package/plugins/subagents/tools/task/index.ts +1019 -0
  66. package/scripts/bump-version.sh +52 -0
  67. package/scripts/publish.sh +35 -0
  68. package/src/cli.ts +167 -0
  69. package/src/commands/create.ts +153 -0
  70. package/src/commands/doctor.ts +217 -0
  71. package/src/commands/enable.ts +105 -0
  72. package/src/commands/info.ts +84 -0
  73. package/src/commands/init.ts +42 -0
  74. package/src/commands/install.ts +327 -0
  75. package/src/commands/link.ts +108 -0
  76. package/src/commands/list.ts +71 -0
  77. package/src/commands/outdated.ts +76 -0
  78. package/src/commands/search.ts +60 -0
  79. package/src/commands/uninstall.ts +73 -0
  80. package/src/commands/update.ts +112 -0
  81. package/src/commands/why.ts +105 -0
  82. package/src/conflicts.ts +84 -0
  83. package/src/index.ts +53 -0
  84. package/src/manifest.ts +212 -0
  85. package/src/migrate.ts +181 -0
  86. package/src/npm.ts +150 -0
  87. package/src/paths.ts +72 -0
  88. package/src/symlinks.ts +199 -0
  89. package/tsconfig.json +24 -0
@@ -0,0 +1,199 @@
1
+ import { existsSync, lstatSync } from "node:fs";
2
+ import { mkdir, readlink, rm, symlink } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+ import chalk from "chalk";
5
+ import type { OmpInstallEntry, PluginPackageJson } from "./manifest.js";
6
+ import { getPluginSourceDir } from "./manifest.js";
7
+ import { PI_CONFIG_DIR } from "./paths.js";
8
+
9
+ export interface SymlinkResult {
10
+ created: string[];
11
+ errors: string[];
12
+ }
13
+
14
+ /**
15
+ * Create symlinks for a plugin's omp.install entries
16
+ */
17
+ export async function createPluginSymlinks(
18
+ pluginName: string,
19
+ pkgJson: PluginPackageJson,
20
+ global = true,
21
+ verbose = true,
22
+ ): Promise<SymlinkResult> {
23
+ const result: SymlinkResult = { created: [], errors: [] };
24
+ const sourceDir = getPluginSourceDir(pluginName, global);
25
+
26
+ if (!pkgJson.omp?.install?.length) {
27
+ if (verbose) {
28
+ console.log(chalk.dim(" No omp.install entries found"));
29
+ }
30
+ return result;
31
+ }
32
+
33
+ for (const entry of pkgJson.omp.install) {
34
+ try {
35
+ const src = join(sourceDir, entry.src);
36
+ const dest = join(PI_CONFIG_DIR, entry.dest);
37
+
38
+ // Check if source exists
39
+ if (!existsSync(src)) {
40
+ result.errors.push(`Source not found: ${entry.src}`);
41
+ if (verbose) {
42
+ console.log(chalk.yellow(` ⚠ Source not found: ${entry.src}`));
43
+ }
44
+ continue;
45
+ }
46
+
47
+ // Create parent directory
48
+ await mkdir(dirname(dest), { recursive: true });
49
+
50
+ // Remove existing symlink/file if it exists
51
+ try {
52
+ await rm(dest, { force: true, recursive: true });
53
+ } catch {}
54
+
55
+ // Create symlink
56
+ await symlink(src, dest);
57
+ result.created.push(entry.dest);
58
+
59
+ if (verbose) {
60
+ console.log(chalk.dim(` Linked: ${entry.dest} → ${entry.src}`));
61
+ }
62
+ } catch (err) {
63
+ const msg = `Failed to link ${entry.dest}: ${(err as Error).message}`;
64
+ result.errors.push(msg);
65
+ if (verbose) {
66
+ console.log(chalk.red(` ✗ ${msg}`));
67
+ }
68
+ }
69
+ }
70
+
71
+ return result;
72
+ }
73
+
74
+ /**
75
+ * Remove symlinks for a plugin's omp.install entries
76
+ */
77
+ export async function removePluginSymlinks(
78
+ _pluginName: string,
79
+ pkgJson: PluginPackageJson,
80
+ verbose = true,
81
+ ): Promise<SymlinkResult> {
82
+ const result: SymlinkResult = { created: [], errors: [] };
83
+
84
+ if (!pkgJson.omp?.install?.length) {
85
+ return result;
86
+ }
87
+
88
+ for (const entry of pkgJson.omp.install) {
89
+ const dest = join(PI_CONFIG_DIR, entry.dest);
90
+
91
+ try {
92
+ if (existsSync(dest)) {
93
+ await rm(dest, { force: true, recursive: true });
94
+ result.created.push(entry.dest);
95
+ if (verbose) {
96
+ console.log(chalk.dim(` Removed: ${entry.dest}`));
97
+ }
98
+ }
99
+ } catch (err) {
100
+ const msg = `Failed to remove ${entry.dest}: ${(err as Error).message}`;
101
+ result.errors.push(msg);
102
+ if (verbose) {
103
+ console.log(chalk.yellow(` ⚠ ${msg}`));
104
+ }
105
+ }
106
+ }
107
+
108
+ return result;
109
+ }
110
+
111
+ /**
112
+ * Check symlink health for a plugin
113
+ */
114
+ export async function checkPluginSymlinks(
115
+ pluginName: string,
116
+ pkgJson: PluginPackageJson,
117
+ global = true,
118
+ ): Promise<{ valid: string[]; broken: string[]; missing: string[] }> {
119
+ const result = { valid: [] as string[], broken: [] as string[], missing: [] as string[] };
120
+ const sourceDir = getPluginSourceDir(pluginName, global);
121
+
122
+ if (!pkgJson.omp?.install?.length) {
123
+ return result;
124
+ }
125
+
126
+ for (const entry of pkgJson.omp.install) {
127
+ const src = join(sourceDir, entry.src);
128
+ const dest = join(PI_CONFIG_DIR, entry.dest);
129
+
130
+ if (!existsSync(dest)) {
131
+ result.missing.push(entry.dest);
132
+ continue;
133
+ }
134
+
135
+ try {
136
+ const stats = lstatSync(dest);
137
+ if (stats.isSymbolicLink()) {
138
+ const _target = await readlink(dest);
139
+ if (existsSync(src)) {
140
+ result.valid.push(entry.dest);
141
+ } else {
142
+ result.broken.push(entry.dest);
143
+ }
144
+ } else {
145
+ // Not a symlink, might be a file that was overwritten
146
+ result.broken.push(entry.dest);
147
+ }
148
+ } catch {
149
+ result.broken.push(entry.dest);
150
+ }
151
+ }
152
+
153
+ return result;
154
+ }
155
+
156
+ /**
157
+ * Get plugin name from an installed symlink destination
158
+ */
159
+ export async function getPluginForSymlink(
160
+ dest: string,
161
+ installedPlugins: Map<string, PluginPackageJson>,
162
+ ): Promise<string | null> {
163
+ for (const [name, pkgJson] of installedPlugins) {
164
+ if (pkgJson.omp?.install) {
165
+ for (const entry of pkgJson.omp.install) {
166
+ if (entry.dest === dest) {
167
+ return name;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ return null;
173
+ }
174
+
175
+ /**
176
+ * Find all symlinks installed by plugins and trace them back
177
+ */
178
+ export async function traceInstalledFile(
179
+ filePath: string,
180
+ installedPlugins: Map<string, PluginPackageJson>,
181
+ ): Promise<{ plugin: string; entry: OmpInstallEntry } | null> {
182
+ // Normalize the path relative to PI_CONFIG_DIR
183
+ let relativePath = filePath;
184
+ if (filePath.startsWith(PI_CONFIG_DIR)) {
185
+ relativePath = filePath.slice(PI_CONFIG_DIR.length + 1);
186
+ }
187
+
188
+ for (const [name, pkgJson] of installedPlugins) {
189
+ if (pkgJson.omp?.install) {
190
+ for (const entry of pkgJson.omp.install) {
191
+ if (entry.dest === relativePath) {
192
+ return { plugin: name, entry };
193
+ }
194
+ }
195
+ }
196
+ }
197
+
198
+ return null;
199
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "Node16",
5
+ "lib": ["ES2022"],
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "declaration": true,
11
+ "declarationMap": true,
12
+ "sourceMap": true,
13
+ "inlineSources": true,
14
+ "inlineSourceMap": false,
15
+ "moduleResolution": "Node16",
16
+ "resolveJsonModule": true,
17
+ "allowImportingTsExtensions": false,
18
+ "outDir": "./dist",
19
+ "rootDir": "./src",
20
+ "types": ["node", "bun-types"]
21
+ },
22
+ "include": ["src/**/*"],
23
+ "exclude": ["node_modules", "dist"]
24
+ }