prjct-cli 0.34.0 → 0.35.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.
@@ -0,0 +1,499 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // core/infrastructure/command-installer.ts
32
+ var command_installer_exports = {};
33
+ __export(command_installer_exports, {
34
+ CommandInstaller: () => CommandInstaller,
35
+ default: () => command_installer_default,
36
+ installDocs: () => installDocs,
37
+ installGlobalConfig: () => installGlobalConfig
38
+ });
39
+ module.exports = __toCommonJS(command_installer_exports);
40
+ var import_promises = __toESM(require("fs/promises"));
41
+ var import_path2 = __toESM(require("path"));
42
+ var import_os = __toESM(require("os"));
43
+
44
+ // core/utils/version.ts
45
+ var import_fs = __toESM(require("fs"));
46
+ var import_path = __toESM(require("path"));
47
+ var cachedVersion = null;
48
+ var cachedPackageJson = null;
49
+ var cachedPackageRoot = null;
50
+ function getPackageRoot() {
51
+ if (cachedPackageRoot) {
52
+ return cachedPackageRoot;
53
+ }
54
+ let currentDir = __dirname;
55
+ for (let i = 0; i < 5; i++) {
56
+ const packageJsonPath = import_path.default.join(currentDir, "package.json");
57
+ if (import_fs.default.existsSync(packageJsonPath)) {
58
+ try {
59
+ const pkg = JSON.parse(import_fs.default.readFileSync(packageJsonPath, "utf-8"));
60
+ if (pkg.name === "prjct-cli") {
61
+ cachedPackageRoot = currentDir;
62
+ return currentDir;
63
+ }
64
+ } catch (_error) {
65
+ }
66
+ }
67
+ currentDir = import_path.default.dirname(currentDir);
68
+ }
69
+ cachedPackageRoot = import_path.default.join(__dirname, "..", "..", "..");
70
+ return cachedPackageRoot;
71
+ }
72
+ __name(getPackageRoot, "getPackageRoot");
73
+ function getVersion() {
74
+ if (cachedVersion) {
75
+ return cachedVersion;
76
+ }
77
+ try {
78
+ const packageJsonPath = import_path.default.join(getPackageRoot(), "package.json");
79
+ const packageJson = JSON.parse(import_fs.default.readFileSync(packageJsonPath, "utf-8"));
80
+ cachedVersion = packageJson.version;
81
+ cachedPackageJson = packageJson;
82
+ return cachedVersion;
83
+ } catch (error) {
84
+ console.error("Failed to read version from package.json:", error.message);
85
+ return "0.0.0";
86
+ }
87
+ }
88
+ __name(getVersion, "getVersion");
89
+ var VERSION = getVersion();
90
+ var PACKAGE_ROOT = getPackageRoot();
91
+
92
+ // core/types/fs.ts
93
+ function isNotFoundError(error) {
94
+ return error?.code === "ENOENT";
95
+ }
96
+ __name(isNotFoundError, "isNotFoundError");
97
+
98
+ // core/infrastructure/command-installer.ts
99
+ async function installDocs() {
100
+ try {
101
+ const docsDir = import_path2.default.join(import_os.default.homedir(), ".prjct-cli", "docs");
102
+ const templateDocsDir = import_path2.default.join(getPackageRoot(), "templates/global/docs");
103
+ await import_promises.default.mkdir(docsDir, { recursive: true });
104
+ const docFiles = await import_promises.default.readdir(templateDocsDir);
105
+ for (const file of docFiles) {
106
+ if (file.endsWith(".md")) {
107
+ const srcPath = import_path2.default.join(templateDocsDir, file);
108
+ const destPath = import_path2.default.join(docsDir, file);
109
+ const content = await import_promises.default.readFile(srcPath, "utf-8");
110
+ await import_promises.default.writeFile(destPath, content, "utf-8");
111
+ }
112
+ }
113
+ return { success: true };
114
+ } catch (error) {
115
+ return { success: false, error: error.message };
116
+ }
117
+ }
118
+ __name(installDocs, "installDocs");
119
+ async function installGlobalConfig(claudeConfigPath, detectClaude) {
120
+ const claudeDetected = await detectClaude();
121
+ if (!claudeDetected) {
122
+ return {
123
+ success: false,
124
+ error: "Claude not detected",
125
+ action: "skipped"
126
+ };
127
+ }
128
+ try {
129
+ const claudeDir = import_path2.default.join(import_os.default.homedir(), ".claude");
130
+ await import_promises.default.mkdir(claudeDir, { recursive: true });
131
+ const globalConfigPath = import_path2.default.join(claudeDir, "CLAUDE.md");
132
+ const templatePath = import_path2.default.join(getPackageRoot(), "templates/global/CLAUDE.md");
133
+ const templateContent = await import_promises.default.readFile(templatePath, "utf-8");
134
+ let existingContent = "";
135
+ let fileExists = false;
136
+ try {
137
+ existingContent = await import_promises.default.readFile(globalConfigPath, "utf-8");
138
+ fileExists = true;
139
+ } catch (error) {
140
+ if (isNotFoundError(error)) {
141
+ fileExists = false;
142
+ } else {
143
+ throw error;
144
+ }
145
+ }
146
+ if (!fileExists) {
147
+ await import_promises.default.writeFile(globalConfigPath, templateContent, "utf-8");
148
+ return {
149
+ success: true,
150
+ action: "created",
151
+ path: globalConfigPath
152
+ };
153
+ } else {
154
+ const startMarker = "<!-- prjct:start - DO NOT REMOVE THIS MARKER -->";
155
+ const endMarker = "<!-- prjct:end - DO NOT REMOVE THIS MARKER -->";
156
+ const hasMarkers = existingContent.includes(startMarker) && existingContent.includes(endMarker);
157
+ if (!hasMarkers) {
158
+ const updatedContent = existingContent + "\n\n" + templateContent;
159
+ await import_promises.default.writeFile(globalConfigPath, updatedContent, "utf-8");
160
+ return {
161
+ success: true,
162
+ action: "appended",
163
+ path: globalConfigPath
164
+ };
165
+ } else {
166
+ const beforeMarker = existingContent.substring(0, existingContent.indexOf(startMarker));
167
+ const afterMarker = existingContent.substring(
168
+ existingContent.indexOf(endMarker) + endMarker.length
169
+ );
170
+ const prjctSection = templateContent.substring(
171
+ templateContent.indexOf(startMarker),
172
+ templateContent.indexOf(endMarker) + endMarker.length
173
+ );
174
+ const updatedContent = beforeMarker + prjctSection + afterMarker;
175
+ await import_promises.default.writeFile(globalConfigPath, updatedContent, "utf-8");
176
+ return {
177
+ success: true,
178
+ action: "updated",
179
+ path: globalConfigPath
180
+ };
181
+ }
182
+ }
183
+ } catch (error) {
184
+ return {
185
+ success: false,
186
+ error: error.message,
187
+ action: "failed"
188
+ };
189
+ }
190
+ }
191
+ __name(installGlobalConfig, "installGlobalConfig");
192
+ var CommandInstaller = class {
193
+ static {
194
+ __name(this, "CommandInstaller");
195
+ }
196
+ homeDir;
197
+ claudeCommandsPath;
198
+ claudeConfigPath;
199
+ templatesDir;
200
+ constructor() {
201
+ this.homeDir = import_os.default.homedir();
202
+ this.claudeCommandsPath = import_path2.default.join(this.homeDir, ".claude", "commands", "p");
203
+ this.claudeConfigPath = import_path2.default.join(this.homeDir, ".claude");
204
+ this.templatesDir = import_path2.default.join(getPackageRoot(), "templates", "commands");
205
+ }
206
+ /**
207
+ * Detect if Claude is installed
208
+ */
209
+ async detectClaude() {
210
+ try {
211
+ await import_promises.default.access(this.claudeConfigPath);
212
+ return true;
213
+ } catch (error) {
214
+ if (isNotFoundError(error)) {
215
+ return false;
216
+ }
217
+ throw error;
218
+ }
219
+ }
220
+ /**
221
+ * Get list of command files to install
222
+ */
223
+ async getCommandFiles() {
224
+ try {
225
+ const files = await import_promises.default.readdir(this.templatesDir);
226
+ return files.filter((f) => f.endsWith(".md"));
227
+ } catch (error) {
228
+ return [
229
+ "init.md",
230
+ "now.md",
231
+ "done.md",
232
+ "ship.md",
233
+ "next.md",
234
+ "idea.md",
235
+ "recap.md",
236
+ "progress.md",
237
+ "stuck.md",
238
+ "context.md",
239
+ "analyze.md",
240
+ "sync.md",
241
+ "roadmap.md",
242
+ "task.md",
243
+ "git.md",
244
+ "fix.md",
245
+ "test.md",
246
+ "cleanup.md",
247
+ "design.md"
248
+ ];
249
+ }
250
+ }
251
+ /**
252
+ * Install commands to Claude
253
+ */
254
+ async installCommands() {
255
+ const claudeDetected = await this.detectClaude();
256
+ if (!claudeDetected) {
257
+ return {
258
+ success: false,
259
+ error: "Claude not detected. Please install Claude Code or Claude Desktop first."
260
+ };
261
+ }
262
+ try {
263
+ await this.installRouter();
264
+ await import_promises.default.mkdir(this.claudeCommandsPath, { recursive: true });
265
+ const commandFiles = await this.getCommandFiles();
266
+ const installed = [];
267
+ const errors = [];
268
+ for (const file of commandFiles) {
269
+ try {
270
+ const sourcePath = import_path2.default.join(this.templatesDir, file);
271
+ const destPath = import_path2.default.join(this.claudeCommandsPath, file);
272
+ const content = await import_promises.default.readFile(sourcePath, "utf-8");
273
+ await import_promises.default.writeFile(destPath, content, "utf-8");
274
+ installed.push(file.replace(".md", ""));
275
+ } catch (error) {
276
+ errors.push({ file, error: error.message });
277
+ }
278
+ }
279
+ return {
280
+ success: true,
281
+ installed,
282
+ errors,
283
+ path: this.claudeCommandsPath
284
+ };
285
+ } catch (error) {
286
+ return {
287
+ success: false,
288
+ error: error.message
289
+ };
290
+ }
291
+ }
292
+ /**
293
+ * Uninstall commands from Claude
294
+ */
295
+ async uninstallCommands() {
296
+ try {
297
+ const commandFiles = await this.getCommandFiles();
298
+ const uninstalled = [];
299
+ const errors = [];
300
+ for (const file of commandFiles) {
301
+ try {
302
+ const filePath = import_path2.default.join(this.claudeCommandsPath, file);
303
+ await import_promises.default.unlink(filePath);
304
+ uninstalled.push(file.replace(".md", ""));
305
+ } catch (error) {
306
+ if (error.code !== "ENOENT") {
307
+ errors.push({ file, error: error.message });
308
+ }
309
+ }
310
+ }
311
+ try {
312
+ await import_promises.default.rmdir(this.claudeCommandsPath);
313
+ } catch (error) {
314
+ }
315
+ return {
316
+ success: true,
317
+ uninstalled,
318
+ errors
319
+ };
320
+ } catch (error) {
321
+ return {
322
+ success: false,
323
+ error: error.message
324
+ };
325
+ }
326
+ }
327
+ /**
328
+ * Check if commands are already installed
329
+ */
330
+ async checkInstallation() {
331
+ const claudeDetected = await this.detectClaude();
332
+ if (!claudeDetected) {
333
+ return {
334
+ installed: false,
335
+ claudeDetected: false
336
+ };
337
+ }
338
+ try {
339
+ await import_promises.default.access(this.claudeCommandsPath);
340
+ const files = await import_promises.default.readdir(this.claudeCommandsPath);
341
+ const installedCommands = files.filter((f) => f.endsWith(".md")).map((f) => f.replace(".md", ""));
342
+ return {
343
+ installed: installedCommands.length > 0,
344
+ claudeDetected: true,
345
+ commands: installedCommands,
346
+ path: this.claudeCommandsPath
347
+ };
348
+ } catch (error) {
349
+ if (isNotFoundError(error)) {
350
+ return {
351
+ installed: false,
352
+ claudeDetected: true,
353
+ commands: []
354
+ };
355
+ }
356
+ throw error;
357
+ }
358
+ }
359
+ /**
360
+ * Update commands (reinstall with latest templates)
361
+ */
362
+ async updateCommands() {
363
+ console.log("Updating commands with latest templates...");
364
+ const result = await this.installCommands();
365
+ if (result.success && result.installed) {
366
+ console.log(`Updated ${result.installed.length} commands`);
367
+ }
368
+ return result;
369
+ }
370
+ /**
371
+ * Install to all detected editors (alias for installCommands)
372
+ */
373
+ async installToAll() {
374
+ return await this.installCommands();
375
+ }
376
+ /**
377
+ * Get installation path for Claude commands
378
+ */
379
+ getInstallPath() {
380
+ return this.claudeCommandsPath;
381
+ }
382
+ /**
383
+ * Verify command template exists
384
+ */
385
+ async verifyTemplate(commandName) {
386
+ try {
387
+ const templatePath = import_path2.default.join(this.templatesDir, `${commandName}.md`);
388
+ await import_promises.default.access(templatePath);
389
+ return true;
390
+ } catch (error) {
391
+ if (isNotFoundError(error)) {
392
+ return false;
393
+ }
394
+ throw error;
395
+ }
396
+ }
397
+ /**
398
+ * Install the p.md router to ~/.claude/commands/
399
+ * This enables the "p. task" natural language trigger
400
+ * Claude Code bug #2422 prevents subdirectory slash command discovery
401
+ */
402
+ async installRouter() {
403
+ try {
404
+ const routerSource = import_path2.default.join(this.templatesDir, "p.md");
405
+ const routerDest = import_path2.default.join(this.homeDir, ".claude", "commands", "p.md");
406
+ const content = await import_promises.default.readFile(routerSource, "utf-8");
407
+ await import_promises.default.writeFile(routerDest, content, "utf-8");
408
+ return true;
409
+ } catch (error) {
410
+ if (isNotFoundError(error)) {
411
+ return false;
412
+ }
413
+ throw error;
414
+ }
415
+ }
416
+ /**
417
+ * Sync commands - intelligent update that detects and removes orphans
418
+ */
419
+ async syncCommands() {
420
+ const claudeDetected = await this.detectClaude();
421
+ if (!claudeDetected) {
422
+ return {
423
+ success: false,
424
+ error: "Claude not detected",
425
+ added: 0,
426
+ updated: 0,
427
+ removed: 0
428
+ };
429
+ }
430
+ try {
431
+ await this.installRouter();
432
+ await import_promises.default.mkdir(this.claudeCommandsPath, { recursive: true });
433
+ const templateFiles = await this.getCommandFiles();
434
+ let installedFiles = [];
435
+ try {
436
+ installedFiles = await import_promises.default.readdir(this.claudeCommandsPath);
437
+ installedFiles = installedFiles.filter((f) => f.endsWith(".md"));
438
+ } catch (error) {
439
+ if (isNotFoundError(error)) {
440
+ installedFiles = [];
441
+ } else {
442
+ throw error;
443
+ }
444
+ }
445
+ const results = {
446
+ success: true,
447
+ added: 0,
448
+ updated: 0,
449
+ removed: 0,
450
+ errors: []
451
+ };
452
+ for (const file of templateFiles) {
453
+ try {
454
+ const sourcePath = import_path2.default.join(this.templatesDir, file);
455
+ const destPath = import_path2.default.join(this.claudeCommandsPath, file);
456
+ const exists = installedFiles.includes(file);
457
+ const content = await import_promises.default.readFile(sourcePath, "utf-8");
458
+ await import_promises.default.writeFile(destPath, content, "utf-8");
459
+ if (!exists) {
460
+ results.added++;
461
+ } else {
462
+ results.updated++;
463
+ }
464
+ } catch (error) {
465
+ results.errors.push({ file, error: error.message });
466
+ }
467
+ }
468
+ return results;
469
+ } catch (error) {
470
+ return {
471
+ success: false,
472
+ error: error.message,
473
+ added: 0,
474
+ updated: 0,
475
+ removed: 0
476
+ };
477
+ }
478
+ }
479
+ /**
480
+ * Install or update global CLAUDE.md configuration
481
+ */
482
+ async installGlobalConfig() {
483
+ return installGlobalConfig(this.claudeConfigPath, () => this.detectClaude());
484
+ }
485
+ /**
486
+ * Install documentation files to ~/.prjct-cli/docs/
487
+ */
488
+ async installDocs() {
489
+ return installDocs();
490
+ }
491
+ };
492
+ var commandInstaller = new CommandInstaller();
493
+ var command_installer_default = commandInstaller;
494
+ // Annotate the CommonJS export names for ESM import in node:
495
+ 0 && (module.exports = {
496
+ CommandInstaller,
497
+ installDocs,
498
+ installGlobalConfig
499
+ });
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // core/infrastructure/editors-config.ts
32
+ var editors_config_exports = {};
33
+ __export(editors_config_exports, {
34
+ default: () => editors_config_default
35
+ });
36
+ module.exports = __toCommonJS(editors_config_exports);
37
+ var import_promises = __toESM(require("fs/promises"));
38
+ var import_path = __toESM(require("path"));
39
+ var import_os = __toESM(require("os"));
40
+ var EditorsConfig = class {
41
+ static {
42
+ __name(this, "EditorsConfig");
43
+ }
44
+ homeDir;
45
+ configDir;
46
+ configFile;
47
+ constructor() {
48
+ this.homeDir = import_os.default.homedir();
49
+ this.configDir = import_path.default.join(this.homeDir, ".prjct-cli", "config");
50
+ this.configFile = import_path.default.join(this.configDir, "installed-editors.json");
51
+ }
52
+ /**
53
+ * Ensure config directory exists
54
+ */
55
+ async ensureConfigDir() {
56
+ try {
57
+ await import_promises.default.mkdir(this.configDir, { recursive: true });
58
+ } catch (error) {
59
+ console.error("[editors-config] Error creating config directory:", error.message);
60
+ }
61
+ }
62
+ /**
63
+ * Load installation configuration
64
+ */
65
+ async loadConfig() {
66
+ try {
67
+ const content = await import_promises.default.readFile(this.configFile, "utf-8");
68
+ return JSON.parse(content);
69
+ } catch (error) {
70
+ if (error.code === "ENOENT") {
71
+ return null;
72
+ }
73
+ console.error("[editors-config] Error loading config:", error.message);
74
+ return null;
75
+ }
76
+ }
77
+ /**
78
+ * Save installation configuration
79
+ */
80
+ async saveConfig(version, claudePath) {
81
+ try {
82
+ await this.ensureConfigDir();
83
+ const config = {
84
+ version,
85
+ editor: "claude",
86
+ lastInstall: (/* @__PURE__ */ new Date()).toISOString(),
87
+ path: claudePath
88
+ };
89
+ await import_promises.default.writeFile(this.configFile, JSON.stringify(config, null, 2), "utf-8");
90
+ return true;
91
+ } catch (error) {
92
+ console.error("[editors-config] Error saving config:", error.message);
93
+ return false;
94
+ }
95
+ }
96
+ /**
97
+ * Get last installed version
98
+ */
99
+ async getLastVersion() {
100
+ const config = await this.loadConfig();
101
+ return config ? config.version : null;
102
+ }
103
+ /**
104
+ * Check if version has changed since last install
105
+ */
106
+ async hasVersionChanged(currentVersion) {
107
+ const lastVersion = await this.getLastVersion();
108
+ return lastVersion !== null && lastVersion !== currentVersion;
109
+ }
110
+ /**
111
+ * Update version in configuration
112
+ */
113
+ async updateVersion(version) {
114
+ try {
115
+ const config = await this.loadConfig();
116
+ if (!config) {
117
+ return false;
118
+ }
119
+ config.version = version;
120
+ config.lastInstall = (/* @__PURE__ */ new Date()).toISOString();
121
+ await import_promises.default.writeFile(this.configFile, JSON.stringify(config, null, 2), "utf-8");
122
+ return true;
123
+ } catch (error) {
124
+ console.error("[editors-config] Error updating version:", error.message);
125
+ return false;
126
+ }
127
+ }
128
+ /**
129
+ * Check if config file exists
130
+ */
131
+ async configExists() {
132
+ try {
133
+ await import_promises.default.access(this.configFile);
134
+ return true;
135
+ } catch (_error) {
136
+ return false;
137
+ }
138
+ }
139
+ /**
140
+ * Delete configuration file
141
+ * Used during uninstallation to clean up tracking data
142
+ */
143
+ async deleteConfig() {
144
+ try {
145
+ const exists = await this.configExists();
146
+ if (exists) {
147
+ await import_promises.default.unlink(this.configFile);
148
+ }
149
+ return true;
150
+ } catch (error) {
151
+ console.error("[editors-config] Error deleting config:", error.message);
152
+ return false;
153
+ }
154
+ }
155
+ };
156
+ var editorsConfig = new EditorsConfig();
157
+ var editors_config_default = editorsConfig;