@esparkman/pensieve 0.1.4 → 0.1.5
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.
- package/dist/index.js +57 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,6 +4,10 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { MemoryDatabase } from './database.js';
|
|
6
6
|
import { checkFieldsForSecrets, formatSecretWarning } from './security.js';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
9
|
+
import { existsSync, mkdirSync, copyFileSync, readdirSync, readFileSync } from 'fs';
|
|
10
|
+
import { homedir } from 'os';
|
|
7
11
|
// Initialize database
|
|
8
12
|
const db = new MemoryDatabase();
|
|
9
13
|
// Create MCP server
|
|
@@ -515,6 +519,57 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
515
519
|
};
|
|
516
520
|
}
|
|
517
521
|
});
|
|
522
|
+
// Install slash commands to user's ~/.claude/commands/ directory
|
|
523
|
+
function installCommands() {
|
|
524
|
+
try {
|
|
525
|
+
// Find the package's .claude/commands directory
|
|
526
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
527
|
+
const __dirname = dirname(__filename);
|
|
528
|
+
// Go up from dist/ to package root, then into .claude/commands
|
|
529
|
+
const packageCommandsDir = join(__dirname, '..', '.claude', 'commands');
|
|
530
|
+
if (!existsSync(packageCommandsDir)) {
|
|
531
|
+
// Commands directory not found in package - this is fine for dev mode
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
// Target directory
|
|
535
|
+
const userCommandsDir = join(homedir(), '.claude', 'commands');
|
|
536
|
+
// Create target directory if it doesn't exist
|
|
537
|
+
if (!existsSync(userCommandsDir)) {
|
|
538
|
+
mkdirSync(userCommandsDir, { recursive: true });
|
|
539
|
+
}
|
|
540
|
+
// Get all command files from package
|
|
541
|
+
const commandFiles = readdirSync(packageCommandsDir).filter(f => f.endsWith('.md'));
|
|
542
|
+
let installed = 0;
|
|
543
|
+
let updated = 0;
|
|
544
|
+
for (const file of commandFiles) {
|
|
545
|
+
const sourcePath = join(packageCommandsDir, file);
|
|
546
|
+
const targetPath = join(userCommandsDir, file);
|
|
547
|
+
// Read source content
|
|
548
|
+
const sourceContent = readFileSync(sourcePath, 'utf-8');
|
|
549
|
+
// Check if target exists and compare content
|
|
550
|
+
if (existsSync(targetPath)) {
|
|
551
|
+
const targetContent = readFileSync(targetPath, 'utf-8');
|
|
552
|
+
if (sourceContent !== targetContent) {
|
|
553
|
+
// Update if different
|
|
554
|
+
copyFileSync(sourcePath, targetPath);
|
|
555
|
+
updated++;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
// Install if missing
|
|
560
|
+
copyFileSync(sourcePath, targetPath);
|
|
561
|
+
installed++;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (installed > 0 || updated > 0) {
|
|
565
|
+
console.error(`[Pensieve] Commands: ${installed} installed, ${updated} updated in ~/.claude/commands/`);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
catch (error) {
|
|
569
|
+
// Non-fatal - just log and continue
|
|
570
|
+
console.error(`[Pensieve] Warning: Could not install commands: ${error instanceof Error ? error.message : String(error)}`);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
518
573
|
// Output prior context on startup
|
|
519
574
|
function outputPriorContext() {
|
|
520
575
|
const lastSession = db.getLastSession();
|
|
@@ -574,6 +629,8 @@ function outputPriorContext() {
|
|
|
574
629
|
}
|
|
575
630
|
// Start server
|
|
576
631
|
async function main() {
|
|
632
|
+
// Install slash commands to ~/.claude/commands/
|
|
633
|
+
installCommands();
|
|
577
634
|
const transport = new StdioServerTransport();
|
|
578
635
|
await server.connect(transport);
|
|
579
636
|
// Output prior context so Claude sees it automatically
|
package/package.json
CHANGED