@stackmemoryai/stackmemory 0.5.4 → 0.5.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.
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Sweep Suggestion Script for Shell Integration
4
+ * Reads input from stdin and returns a suggestion
5
+ */
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+
10
+ const STATE_FILE = path.join(
11
+ process.env.HOME || '/tmp',
12
+ '.stackmemory',
13
+ 'sweep-state.json'
14
+ );
15
+
16
+ function loadState() {
17
+ try {
18
+ if (fs.existsSync(STATE_FILE)) {
19
+ return JSON.parse(fs.readFileSync(STATE_FILE, 'utf-8'));
20
+ }
21
+ } catch {
22
+ // Ignore
23
+ }
24
+ return { recentDiffs: [], fileContents: {} };
25
+ }
26
+
27
+ function getRecentFile(state) {
28
+ if (!state.recentDiffs || state.recentDiffs.length === 0) {
29
+ return null;
30
+ }
31
+ return state.recentDiffs[0]?.file_path;
32
+ }
33
+
34
+ function getFilename(filepath) {
35
+ if (!filepath) return null;
36
+ return path.basename(filepath);
37
+ }
38
+
39
+ function getSuggestion(userInput) {
40
+ const state = loadState();
41
+ const recentFile = getRecentFile(state);
42
+ const filename = getFilename(recentFile);
43
+
44
+ if (!filename) return null;
45
+
46
+ const input = userInput.toLowerCase().trim();
47
+
48
+ // Git commands - suggest based on recent file
49
+ if (input.startsWith('git commit')) {
50
+ if (input === 'git commit') {
51
+ return ` -m "Update ${filename}"`;
52
+ }
53
+ if (input === 'git commit -m') {
54
+ return ` "Update ${filename}"`;
55
+ }
56
+ if (input === 'git commit -m "') {
57
+ return `Update ${filename}"`;
58
+ }
59
+ }
60
+
61
+ if (input === 'git add') {
62
+ return ` ${recentFile}`;
63
+ }
64
+
65
+ if (input === 'git diff') {
66
+ return ` ${recentFile}`;
67
+ }
68
+
69
+ if (input === 'git log') {
70
+ return ` --oneline -10`;
71
+ }
72
+
73
+ // Action keywords at end
74
+ const actionPatterns = {
75
+ fix: ` the bug in ${filename}`,
76
+ add: ` feature to ${filename}`,
77
+ update: ` ${filename}`,
78
+ refactor: ` ${filename}`,
79
+ test: ` ${filename}`,
80
+ implement: ` in ${filename}`,
81
+ create: ` new function in ${filename}`,
82
+ delete: ` from ${filename}`,
83
+ remove: ` from ${filename}`,
84
+ edit: ` ${filename}`,
85
+ open: ` ${recentFile}`,
86
+ check: ` ${filename}`,
87
+ review: ` ${filename}`,
88
+ debug: ` ${filename}`,
89
+ };
90
+
91
+ for (const [keyword, suffix] of Object.entries(actionPatterns)) {
92
+ if (input.endsWith(keyword)) {
93
+ return suffix;
94
+ }
95
+ if (input.endsWith(keyword + ' ')) {
96
+ return suffix.trim();
97
+ }
98
+ }
99
+
100
+ // Preposition patterns
101
+ if (
102
+ input.endsWith(' in ') ||
103
+ input.endsWith(' to ') ||
104
+ input.endsWith(' for ')
105
+ ) {
106
+ return filename;
107
+ }
108
+
109
+ if (input.endsWith(' file ') || input.endsWith(' the ')) {
110
+ return filename;
111
+ }
112
+
113
+ // npm/node commands
114
+ if (input === 'npm run') {
115
+ return ' build';
116
+ }
117
+
118
+ if (input === 'npm test') {
119
+ return ` -- ${filename.replace(/\.[^/.]+$/, '')}`;
120
+ }
121
+
122
+ if (input === 'node') {
123
+ return ` ${recentFile}`;
124
+ }
125
+
126
+ // Cat/less/vim
127
+ if (
128
+ input === 'cat' ||
129
+ input === 'less' ||
130
+ input === 'vim' ||
131
+ input === 'code'
132
+ ) {
133
+ return ` ${recentFile}`;
134
+ }
135
+
136
+ return null;
137
+ }
138
+
139
+ async function main() {
140
+ let data = '';
141
+
142
+ process.stdin.setEncoding('utf8');
143
+
144
+ for await (const chunk of process.stdin) {
145
+ data += chunk;
146
+ }
147
+
148
+ const userInput = data.trim();
149
+
150
+ if (!userInput || userInput.length < 2) {
151
+ process.exit(0);
152
+ }
153
+
154
+ const suggestion = getSuggestion(userInput);
155
+
156
+ if (suggestion) {
157
+ console.log(suggestion);
158
+ }
159
+ }
160
+
161
+ main().catch(() => process.exit(0));