vigthoria-cli 1.0.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 (75) hide show
  1. package/README.md +413 -0
  2. package/dist/commands/auth.d.ts +24 -0
  3. package/dist/commands/auth.d.ts.map +1 -0
  4. package/dist/commands/auth.js +194 -0
  5. package/dist/commands/auth.js.map +1 -0
  6. package/dist/commands/chat.d.ts +64 -0
  7. package/dist/commands/chat.d.ts.map +1 -0
  8. package/dist/commands/chat.js +596 -0
  9. package/dist/commands/chat.js.map +1 -0
  10. package/dist/commands/config.d.ts +25 -0
  11. package/dist/commands/config.d.ts.map +1 -0
  12. package/dist/commands/config.js +291 -0
  13. package/dist/commands/config.js.map +1 -0
  14. package/dist/commands/edit.d.ts +28 -0
  15. package/dist/commands/edit.d.ts.map +1 -0
  16. package/dist/commands/edit.js +257 -0
  17. package/dist/commands/edit.js.map +1 -0
  18. package/dist/commands/explain.d.ts +21 -0
  19. package/dist/commands/explain.d.ts.map +1 -0
  20. package/dist/commands/explain.js +98 -0
  21. package/dist/commands/explain.js.map +1 -0
  22. package/dist/commands/generate.d.ts +25 -0
  23. package/dist/commands/generate.d.ts.map +1 -0
  24. package/dist/commands/generate.js +155 -0
  25. package/dist/commands/generate.js.map +1 -0
  26. package/dist/commands/review.d.ts +24 -0
  27. package/dist/commands/review.d.ts.map +1 -0
  28. package/dist/commands/review.js +153 -0
  29. package/dist/commands/review.js.map +1 -0
  30. package/dist/index.d.ts +16 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +205 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/utils/api.d.ts +88 -0
  35. package/dist/utils/api.d.ts.map +1 -0
  36. package/dist/utils/api.js +431 -0
  37. package/dist/utils/api.js.map +1 -0
  38. package/dist/utils/config.d.ts +57 -0
  39. package/dist/utils/config.d.ts.map +1 -0
  40. package/dist/utils/config.js +167 -0
  41. package/dist/utils/config.js.map +1 -0
  42. package/dist/utils/files.d.ts +31 -0
  43. package/dist/utils/files.d.ts.map +1 -0
  44. package/dist/utils/files.js +217 -0
  45. package/dist/utils/files.js.map +1 -0
  46. package/dist/utils/logger.d.ts +23 -0
  47. package/dist/utils/logger.d.ts.map +1 -0
  48. package/dist/utils/logger.js +104 -0
  49. package/dist/utils/logger.js.map +1 -0
  50. package/dist/utils/session.d.ts +61 -0
  51. package/dist/utils/session.d.ts.map +1 -0
  52. package/dist/utils/session.js +172 -0
  53. package/dist/utils/session.js.map +1 -0
  54. package/dist/utils/tools.d.ts +145 -0
  55. package/dist/utils/tools.d.ts.map +1 -0
  56. package/dist/utils/tools.js +781 -0
  57. package/dist/utils/tools.js.map +1 -0
  58. package/install.sh +248 -0
  59. package/package.json +52 -0
  60. package/src/commands/auth.ts +225 -0
  61. package/src/commands/chat.ts +690 -0
  62. package/src/commands/config.ts +297 -0
  63. package/src/commands/edit.ts +310 -0
  64. package/src/commands/explain.ts +115 -0
  65. package/src/commands/generate.ts +177 -0
  66. package/src/commands/review.ts +186 -0
  67. package/src/index.ts +221 -0
  68. package/src/types/marked-terminal.d.ts +31 -0
  69. package/src/utils/api.ts +531 -0
  70. package/src/utils/config.ts +224 -0
  71. package/src/utils/files.ts +212 -0
  72. package/src/utils/logger.ts +125 -0
  73. package/src/utils/session.ts +167 -0
  74. package/src/utils/tools.ts +933 -0
  75. package/tsconfig.json +20 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Session Manager - Persist and resume conversations
3
+ * Similar to Claude Code's session persistence
4
+ */
5
+
6
+ import * as fs from 'fs';
7
+ import * as path from 'path';
8
+ import * as os from 'os';
9
+ import { ChatMessage } from './api.js';
10
+
11
+ export interface Session {
12
+ id: string;
13
+ name: string;
14
+ project: string;
15
+ model: string;
16
+ messages: ChatMessage[];
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ agentMode: boolean;
20
+ }
21
+
22
+ export class SessionManager {
23
+ private sessionsDir: string;
24
+
25
+ constructor() {
26
+ this.sessionsDir = path.join(os.homedir(), '.vigthoria', 'sessions');
27
+ this.ensureDir();
28
+ }
29
+
30
+ private ensureDir(): void {
31
+ if (!fs.existsSync(this.sessionsDir)) {
32
+ fs.mkdirSync(this.sessionsDir, { recursive: true });
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Generate unique session ID
38
+ */
39
+ private generateId(): string {
40
+ const timestamp = Date.now().toString(36);
41
+ const random = Math.random().toString(36).substring(2, 8);
42
+ return `${timestamp}-${random}`;
43
+ }
44
+
45
+ /**
46
+ * Create a new session
47
+ */
48
+ create(project: string, model: string, agentMode: boolean = false): Session {
49
+ const session: Session = {
50
+ id: this.generateId(),
51
+ name: `Session ${new Date().toLocaleString()}`,
52
+ project,
53
+ model,
54
+ messages: [],
55
+ createdAt: new Date().toISOString(),
56
+ updatedAt: new Date().toISOString(),
57
+ agentMode,
58
+ };
59
+
60
+ this.save(session);
61
+ return session;
62
+ }
63
+
64
+ /**
65
+ * Save session to disk
66
+ */
67
+ save(session: Session): void {
68
+ session.updatedAt = new Date().toISOString();
69
+ const filePath = path.join(this.sessionsDir, `${session.id}.json`);
70
+ fs.writeFileSync(filePath, JSON.stringify(session, null, 2), 'utf-8');
71
+ }
72
+
73
+ /**
74
+ * Load session by ID
75
+ */
76
+ load(id: string): Session | null {
77
+ const filePath = path.join(this.sessionsDir, `${id}.json`);
78
+
79
+ if (!fs.existsSync(filePath)) {
80
+ return null;
81
+ }
82
+
83
+ try {
84
+ const content = fs.readFileSync(filePath, 'utf-8');
85
+ return JSON.parse(content) as Session;
86
+ } catch {
87
+ return null;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Get the most recent session for a project
93
+ */
94
+ getLatest(project: string): Session | null {
95
+ const sessions = this.list();
96
+ const projectSessions = sessions
97
+ .filter(s => s.project === project)
98
+ .sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
99
+
100
+ return projectSessions.length > 0 ? this.load(projectSessions[0].id) : null;
101
+ }
102
+
103
+ /**
104
+ * List all sessions (metadata only)
105
+ */
106
+ list(): Omit<Session, 'messages'>[] {
107
+ const files = fs.readdirSync(this.sessionsDir)
108
+ .filter(f => f.endsWith('.json'));
109
+
110
+ return files.map(f => {
111
+ try {
112
+ const content = fs.readFileSync(path.join(this.sessionsDir, f), 'utf-8');
113
+ const session = JSON.parse(content) as Session;
114
+ // Return without messages for efficiency
115
+ const { messages, ...metadata } = session;
116
+ return { ...metadata, messages: [] };
117
+ } catch {
118
+ return null;
119
+ }
120
+ }).filter(Boolean) as Omit<Session, 'messages'>[];
121
+ }
122
+
123
+ /**
124
+ * Delete a session
125
+ */
126
+ delete(id: string): boolean {
127
+ const filePath = path.join(this.sessionsDir, `${id}.json`);
128
+
129
+ if (fs.existsSync(filePath)) {
130
+ fs.unlinkSync(filePath);
131
+ return true;
132
+ }
133
+
134
+ return false;
135
+ }
136
+
137
+ /**
138
+ * Clear all sessions
139
+ */
140
+ clearAll(): number {
141
+ const files = fs.readdirSync(this.sessionsDir)
142
+ .filter(f => f.endsWith('.json'));
143
+
144
+ files.forEach(f => fs.unlinkSync(path.join(this.sessionsDir, f)));
145
+ return files.length;
146
+ }
147
+
148
+ /**
149
+ * Add message to session
150
+ */
151
+ addMessage(session: Session, message: ChatMessage): void {
152
+ session.messages.push(message);
153
+ this.save(session);
154
+ }
155
+
156
+ /**
157
+ * Get session summary for display
158
+ */
159
+ getSummary(session: Session): string {
160
+ const userMessages = session.messages.filter(m => m.role === 'user');
161
+ const preview = userMessages.length > 0
162
+ ? userMessages[0].content.substring(0, 50) + '...'
163
+ : 'Empty session';
164
+
165
+ return `[${session.id}] ${preview} (${userMessages.length} messages)`;
166
+ }
167
+ }