sam-coder-cli 1.0.69 → 2.0.1

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,290 @@
1
+ /**
2
+ * Brainstorm Core - Models
3
+ *
4
+ * Data models for project configuration, agent configuration, and session state.
5
+ * Ported from Python to JavaScript.
6
+ */
7
+
8
+ const fs = require('fs').promises;
9
+ const path = require('path');
10
+
11
+ /**
12
+ * Agent configuration - defines an individual AI agent
13
+ */
14
+ class AgentConfig {
15
+ constructor({
16
+ id,
17
+ name,
18
+ description,
19
+ priority = 'MEDIUM',
20
+ inputs = [],
21
+ outputs = [],
22
+ technologies = [],
23
+ validationRules = [],
24
+ territory = []
25
+ }) {
26
+ this.id = id;
27
+ this.name = name;
28
+ this.description = description;
29
+ this.priority = priority; // 'LOW', 'MEDIUM', 'HIGH'
30
+ this.inputs = inputs;
31
+ this.outputs = outputs;
32
+ this.technologies = technologies;
33
+ this.validationRules = validationRules;
34
+ this.territory = territory;
35
+ }
36
+
37
+ toJSON() {
38
+ return {
39
+ id: this.id,
40
+ name: this.name,
41
+ description: this.description,
42
+ priority: this.priority,
43
+ inputs: this.inputs,
44
+ outputs: this.outputs,
45
+ technologies: this.technologies,
46
+ validationRules: this.validationRules,
47
+ territory: this.territory
48
+ };
49
+ }
50
+
51
+ static fromJSON(data) {
52
+ return new AgentConfig(data);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Project configuration - defines project-level details
58
+ */
59
+ class ProjectConfig {
60
+ constructor({
61
+ name,
62
+ description,
63
+ version = '1.0',
64
+ agents = [],
65
+ dataModel = {},
66
+ technologyStack = [],
67
+ governanceRules = [],
68
+ successCriteria = [],
69
+ directoryStructure = {},
70
+ inputFiles = []
71
+ }) {
72
+ this.name = name;
73
+ this.description = description;
74
+ this.version = version;
75
+ this.agents = agents.map(a => a instanceof AgentConfig ? a : new AgentConfig(a));
76
+ this.dataModel = dataModel;
77
+ this.technologyStack = technologyStack;
78
+ this.governanceRules = governanceRules;
79
+ this.successCriteria = successCriteria;
80
+ this.directoryStructure = directoryStructure;
81
+ this.inputFiles = inputFiles;
82
+ }
83
+
84
+ getAgent(id) {
85
+ return this.agents.find(a => a.id === id);
86
+ }
87
+
88
+ toJSON() {
89
+ return {
90
+ name: this.name,
91
+ description: this.description,
92
+ version: this.version,
93
+ agents: this.agents.map(a => a.toJSON()),
94
+ dataModel: this.dataModel,
95
+ technologyStack: this.technologyStack,
96
+ governanceRules: this.governanceRules,
97
+ successCriteria: this.successCriteria,
98
+ directoryStructure: this.directoryStructure,
99
+ inputFiles: this.inputFiles
100
+ };
101
+ }
102
+
103
+ static fromJSON(data) {
104
+ return new ProjectConfig({
105
+ ...data,
106
+ agents: (data.agents || []).map(a => AgentConfig.fromJSON(a))
107
+ });
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Session event - logs individual events within a session
113
+ */
114
+ class SessionEvent {
115
+ constructor({
116
+ timestamp = new Date().toISOString(),
117
+ eventType,
118
+ actor,
119
+ description,
120
+ affectedFiles = []
121
+ }) {
122
+ this.timestamp = timestamp;
123
+ this.eventType = eventType; // 'CREATED', 'UPDATED', 'EDITED', 'COMPLETED'
124
+ this.actor = actor;
125
+ this.description = description;
126
+ this.affectedFiles = affectedFiles;
127
+ }
128
+
129
+ toJSON() {
130
+ return {
131
+ timestamp: this.timestamp,
132
+ eventType: this.eventType,
133
+ actor: this.actor,
134
+ description: this.description,
135
+ affectedFiles: this.affectedFiles
136
+ };
137
+ }
138
+
139
+ static fromJSON(data) {
140
+ return new SessionEvent(data);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Brainstorm session - manages session state
146
+ */
147
+ class BrainstormSession {
148
+ constructor({
149
+ id,
150
+ project,
151
+ createdAt = new Date().toISOString(),
152
+ updatedAt = new Date().toISOString(),
153
+ status = 'ACTIVE',
154
+ agentsParticipating = [],
155
+ outputDirectory,
156
+ history = [],
157
+ fileVersions = {},
158
+ mutualSummary = null
159
+ }) {
160
+ this.id = id;
161
+ this.project = project instanceof ProjectConfig ? project : ProjectConfig.fromJSON(project);
162
+ this.createdAt = createdAt;
163
+ this.updatedAt = updatedAt;
164
+ this.status = status; // 'ACTIVE', 'COMPLETED', 'ARCHIVED'
165
+ this.agentsParticipating = agentsParticipating;
166
+ this.outputDirectory = outputDirectory;
167
+ this.history = history.map(e => e instanceof SessionEvent ? e : SessionEvent.fromJSON(e));
168
+ this.fileVersions = fileVersions;
169
+ this.mutualSummary = mutualSummary;
170
+ }
171
+
172
+ static create({ project, outputDirectory, agents = ['CLAUDE-1'] }) {
173
+ const session = new BrainstormSession({
174
+ id: `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
175
+ project,
176
+ outputDirectory,
177
+ agentsParticipating: agents
178
+ });
179
+
180
+ session.addEvent({
181
+ eventType: 'CREATED',
182
+ actor: 'BRAINSTORM',
183
+ description: `Brainstorm session created for project '${project.name}'`
184
+ });
185
+
186
+ return session;
187
+ }
188
+
189
+ addEvent({ eventType, actor, description, affectedFiles = [] }) {
190
+ this.history.push(new SessionEvent({
191
+ eventType,
192
+ actor,
193
+ description,
194
+ affectedFiles
195
+ }));
196
+ this.updatedAt = new Date().toISOString();
197
+ }
198
+
199
+ getFileVersion(fileName) {
200
+ return this.fileVersions[fileName] || 0;
201
+ }
202
+
203
+ incrementFileVersion(fileName) {
204
+ this.fileVersions[fileName] = (this.fileVersions[fileName] || 0) + 1;
205
+ return this.fileVersions[fileName];
206
+ }
207
+
208
+ toJSON() {
209
+ return {
210
+ id: this.id,
211
+ project: this.project.toJSON(),
212
+ createdAt: this.createdAt,
213
+ updatedAt: this.updatedAt,
214
+ status: this.status,
215
+ agentsParticipating: this.agentsParticipating,
216
+ outputDirectory: this.outputDirectory,
217
+ history: this.history.map(e => e.toJSON()),
218
+ fileVersions: this.fileVersions,
219
+ mutualSummary: this.mutualSummary
220
+ };
221
+ }
222
+
223
+ static fromJSON(data) {
224
+ return new BrainstormSession(data);
225
+ }
226
+
227
+ async save(filePath = null) {
228
+ const savePath = filePath || path.join(this.outputDirectory, 'SESSION.json');
229
+ await fs.writeFile(savePath, JSON.stringify(this.toJSON(), null, 2), 'utf-8');
230
+ return savePath;
231
+ }
232
+
233
+ static async load(filePath) {
234
+ const content = await fs.readFile(filePath, 'utf-8');
235
+ return BrainstormSession.fromJSON(JSON.parse(content));
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Session result - encapsulates outcome of operations
241
+ */
242
+ class SessionResult {
243
+ constructor({
244
+ success,
245
+ sessionId,
246
+ status,
247
+ summary,
248
+ filesGenerated = [],
249
+ errors = []
250
+ }) {
251
+ this.success = success;
252
+ this.sessionId = sessionId;
253
+ this.status = status;
254
+ this.summary = summary;
255
+ this.filesGenerated = filesGenerated;
256
+ this.errors = errors;
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Edit info - tracks edits made to completed files
262
+ */
263
+ class EditInfo {
264
+ constructor({
265
+ timestamp = new Date().toISOString(),
266
+ filePath,
267
+ editor,
268
+ description,
269
+ versionBefore,
270
+ versionAfter,
271
+ backupPath = null
272
+ }) {
273
+ this.timestamp = timestamp;
274
+ this.filePath = filePath;
275
+ this.editor = editor;
276
+ this.description = description;
277
+ this.versionBefore = versionBefore;
278
+ this.versionAfter = versionAfter;
279
+ this.backupPath = backupPath;
280
+ }
281
+ }
282
+
283
+ module.exports = {
284
+ AgentConfig,
285
+ ProjectConfig,
286
+ SessionEvent,
287
+ BrainstormSession,
288
+ SessionResult,
289
+ EditInfo
290
+ };