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.
- package/README.md +413 -0
- package/dist/commands/auth.d.ts +24 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +194 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/chat.d.ts +64 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +596 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/config.d.ts +25 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +291 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/edit.d.ts +28 -0
- package/dist/commands/edit.d.ts.map +1 -0
- package/dist/commands/edit.js +257 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/explain.d.ts +21 -0
- package/dist/commands/explain.d.ts.map +1 -0
- package/dist/commands/explain.js +98 -0
- package/dist/commands/explain.js.map +1 -0
- package/dist/commands/generate.d.ts +25 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +155 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/review.d.ts +24 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +153 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +205 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/api.d.ts +88 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +431 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/config.d.ts +57 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +167 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/files.d.ts +31 -0
- package/dist/utils/files.d.ts.map +1 -0
- package/dist/utils/files.js +217 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/utils/logger.d.ts +23 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +104 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/session.d.ts +61 -0
- package/dist/utils/session.d.ts.map +1 -0
- package/dist/utils/session.js +172 -0
- package/dist/utils/session.js.map +1 -0
- package/dist/utils/tools.d.ts +145 -0
- package/dist/utils/tools.d.ts.map +1 -0
- package/dist/utils/tools.js +781 -0
- package/dist/utils/tools.js.map +1 -0
- package/install.sh +248 -0
- package/package.json +52 -0
- package/src/commands/auth.ts +225 -0
- package/src/commands/chat.ts +690 -0
- package/src/commands/config.ts +297 -0
- package/src/commands/edit.ts +310 -0
- package/src/commands/explain.ts +115 -0
- package/src/commands/generate.ts +177 -0
- package/src/commands/review.ts +186 -0
- package/src/index.ts +221 -0
- package/src/types/marked-terminal.d.ts +31 -0
- package/src/utils/api.ts +531 -0
- package/src/utils/config.ts +224 -0
- package/src/utils/files.ts +212 -0
- package/src/utils/logger.ts +125 -0
- package/src/utils/session.ts +167 -0
- package/src/utils/tools.ts +933 -0
- 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
|
+
}
|