@lovelybunch/api 1.0.69-alpha.11 → 1.0.69-alpha.14

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/lib/git.js CHANGED
@@ -138,21 +138,28 @@ export async function pushCurrent() {
138
138
  try {
139
139
  const tokenRecord = await readGithubToken();
140
140
  if (tokenRecord && isGithubTokenValid(tokenRecord)) {
141
+ console.log('[git] Found valid GitHub token, ensuring it\'s in credential helper');
141
142
  // Ensure token is stored in credential helper
142
143
  try {
143
144
  await storeCredentials('x-access-token', tokenRecord.token);
145
+ console.log('[git] Successfully stored token in credential helper');
144
146
  }
145
147
  catch (credError) {
146
148
  // Log but don't fail - credential helper might already have it
147
- console.log('[git] Note: Could not update credential helper:', credError?.message);
149
+ console.error('[git] Failed to store token in credential helper:', credError?.message);
148
150
  }
149
151
  }
152
+ else {
153
+ console.log('[git] No valid GitHub token found');
154
+ }
150
155
  }
151
156
  catch (tokenError) {
152
157
  // Log but don't fail - might not be using GitHub auth
153
- console.log('[git] Note: Could not read GitHub token:', tokenError);
158
+ console.error('[git] Error reading GitHub token:', tokenError);
154
159
  }
160
+ console.log('[git] Executing git push...');
155
161
  const { stdout } = await runGit(['push'], { timeout: 30000 }); // 30 second timeout for push
162
+ console.log('[git] Push completed successfully');
156
163
  return stdout;
157
164
  }
158
165
  export async function pullCurrent(strategy = 'rebase') {
@@ -26,7 +26,18 @@ export class JobScheduler {
26
26
  return;
27
27
  const jobs = await this.store.listJobs();
28
28
  for (const job of jobs) {
29
- await this.register(job);
29
+ // Skip corrupted jobs (jobs with _error field)
30
+ if (job._error) {
31
+ console.warn(`Skipping corrupted job ${job.id}: ${job._error}`);
32
+ continue;
33
+ }
34
+ try {
35
+ await this.register(job);
36
+ }
37
+ catch (error) {
38
+ console.error(`Failed to register job ${job.id}:`, error);
39
+ // Continue with other jobs even if one fails
40
+ }
30
41
  }
31
42
  this.initialized = true;
32
43
  }
@@ -8,6 +8,7 @@ export declare class JobStore {
8
8
  private getJobFilePath;
9
9
  listJobs(): Promise<ScheduledJob[]>;
10
10
  getJob(id: string): Promise<ScheduledJob | null>;
11
+ private createErrorJob;
11
12
  saveJob(job: ScheduledJob, bodyContent?: string): Promise<void>;
12
13
  deleteJob(id: string): Promise<boolean>;
13
14
  appendRun(jobId: string, run: ScheduledJobRun): Promise<ScheduledJob>;
@@ -90,15 +90,53 @@ export class JobStore {
90
90
  try {
91
91
  const filePath = await this.getJobFilePath(id);
92
92
  const content = await fs.readFile(filePath, 'utf-8');
93
+ // Handle empty files
94
+ if (!content || content.trim().length === 0) {
95
+ return this.createErrorJob(id, 'Job file is empty');
96
+ }
93
97
  const { data, content: body } = matter(content);
98
+ // Validate that we have at least an id field
99
+ if (!data || typeof data !== 'object' || !data.id) {
100
+ return this.createErrorJob(id, 'Job file is missing required id field');
101
+ }
94
102
  return this.fromFrontmatter(data, body);
95
103
  }
96
104
  catch (error) {
97
105
  if (error?.code === 'ENOENT')
98
106
  return null;
99
- throw error;
107
+ // Handle parsing errors (e.g., invalid YAML, corrupted frontmatter)
108
+ const errorMessage = error?.message || 'Unknown error parsing job file';
109
+ return this.createErrorJob(id, errorMessage);
100
110
  }
101
111
  }
112
+ createErrorJob(id, errorMessage) {
113
+ const now = new Date();
114
+ return {
115
+ id,
116
+ name: id,
117
+ description: undefined,
118
+ prompt: '',
119
+ model: 'anthropic/claude-sonnet-4',
120
+ status: 'paused',
121
+ schedule: {
122
+ type: 'interval',
123
+ hours: 6,
124
+ daysOfWeek: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
125
+ },
126
+ metadata: {
127
+ createdAt: now,
128
+ updatedAt: now,
129
+ lastRunAt: undefined,
130
+ nextRunAt: undefined,
131
+ },
132
+ runs: [],
133
+ tags: [],
134
+ contextPaths: [],
135
+ // Store error in a way that won't break serialization
136
+ // We'll use a special tag to mark error jobs
137
+ _error: errorMessage
138
+ };
139
+ }
102
140
  async saveJob(job, bodyContent = '') {
103
141
  const filePath = await this.getJobFilePath(job.id);
104
142
  const normalizedJob = {
@@ -138,34 +176,118 @@ export class JobStore {
138
176
  if (!data?.id) {
139
177
  throw new Error('Scheduled job is missing required id field');
140
178
  }
179
+ // Validate and sanitize fields to prevent issues with corrupted data
141
180
  const createdAt = toDate(data.metadata?.createdAt) ?? new Date();
142
181
  const updatedAt = toDate(data.metadata?.updatedAt) ?? createdAt;
182
+ // Validate schedule structure
183
+ let schedule;
184
+ if (data.schedule && typeof data.schedule === 'object') {
185
+ if (data.schedule.type === 'cron') {
186
+ const cronSchedule = data.schedule;
187
+ if (typeof cronSchedule.expression === 'string' && cronSchedule.expression.trim()) {
188
+ schedule = {
189
+ type: 'cron',
190
+ expression: cronSchedule.expression.trim(),
191
+ timezone: typeof cronSchedule.timezone === 'string' ? cronSchedule.timezone : undefined,
192
+ description: typeof cronSchedule.description === 'string' ? cronSchedule.description : undefined,
193
+ };
194
+ }
195
+ else {
196
+ // Invalid cron schedule, fall back to default
197
+ schedule = {
198
+ type: 'interval',
199
+ hours: 6,
200
+ daysOfWeek: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
201
+ };
202
+ }
203
+ }
204
+ else {
205
+ const intervalSchedule = data.schedule;
206
+ const hours = typeof intervalSchedule.hours === 'number' && intervalSchedule.hours >= 1
207
+ ? intervalSchedule.hours
208
+ : 6;
209
+ const daysOfWeek = Array.isArray(intervalSchedule.daysOfWeek)
210
+ ? intervalSchedule.daysOfWeek.filter((day) => typeof day === 'string' && ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'].includes(day.toLowerCase()))
211
+ : ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
212
+ schedule = {
213
+ type: 'interval',
214
+ hours,
215
+ daysOfWeek: daysOfWeek.length > 0 ? daysOfWeek : ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'],
216
+ anchorHour: typeof intervalSchedule.anchorHour === 'number' && intervalSchedule.anchorHour >= 0 && intervalSchedule.anchorHour <= 23
217
+ ? intervalSchedule.anchorHour
218
+ : undefined,
219
+ };
220
+ }
221
+ }
222
+ else {
223
+ schedule = {
224
+ type: 'interval',
225
+ hours: 6,
226
+ daysOfWeek: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
227
+ };
228
+ }
229
+ // Validate and sanitize runs
143
230
  const runs = Array.isArray(data.runs)
144
- ? data.runs.map((run) => ({
145
- id: run.id ?? `run-${randomUUID()}`,
146
- jobId: data.id,
147
- trigger: run.trigger,
148
- status: run.status,
149
- startedAt: toDate(run.startedAt) ?? new Date(),
150
- finishedAt: toDate(run.finishedAt),
151
- outputPath: run.outputPath,
152
- summary: run.summary,
153
- error: run.error,
154
- cliCommand: run.cliCommand,
155
- }))
231
+ ? data.runs
232
+ .filter((run) => run && typeof run === 'object')
233
+ .map((run) => {
234
+ const startedAt = toDate(run.startedAt);
235
+ if (!startedAt) {
236
+ // Skip runs with invalid dates
237
+ return null;
238
+ }
239
+ return {
240
+ id: typeof run.id === 'string' ? run.id : `run-${randomUUID()}`,
241
+ jobId: data.id,
242
+ trigger: (run.trigger === 'manual' || run.trigger === 'scheduled') ? run.trigger : 'manual',
243
+ status: (['pending', 'running', 'succeeded', 'failed'].includes(run.status)) ? run.status : 'pending',
244
+ startedAt,
245
+ finishedAt: toDate(run.finishedAt),
246
+ outputPath: typeof run.outputPath === 'string' ? run.outputPath : undefined,
247
+ summary: typeof run.summary === 'string' ? run.summary : undefined,
248
+ error: typeof run.error === 'string' ? run.error : undefined,
249
+ cliCommand: typeof run.cliCommand === 'string' ? run.cliCommand : undefined,
250
+ };
251
+ })
252
+ .filter((run) => run !== null)
253
+ : [];
254
+ // Validate and sanitize string fields
255
+ const name = typeof data.name === 'string' && data.name.trim()
256
+ ? data.name.trim().slice(0, 500) // Limit length
257
+ : data.id;
258
+ const description = typeof data.description === 'string'
259
+ ? data.description.slice(0, 1000) // Limit length
260
+ : undefined;
261
+ const prompt = typeof data.prompt === 'string'
262
+ ? data.prompt.trim() || body.trim()
263
+ : body.trim();
264
+ const model = typeof data.model === 'string' && data.model.trim()
265
+ ? data.model.trim()
266
+ : 'anthropic/claude-sonnet-4';
267
+ const status = (data.status === 'active' || data.status === 'paused')
268
+ ? data.status
269
+ : 'paused';
270
+ // Validate arrays
271
+ const tags = Array.isArray(data.tags)
272
+ ? data.tags.filter((tag) => typeof tag === 'string').slice(0, 50)
273
+ : [];
274
+ const contextPaths = Array.isArray(data.contextPaths)
275
+ ? data.contextPaths.filter((path) => typeof path === 'string').slice(0, 100)
156
276
  : [];
277
+ const agentIds = Array.isArray(data.agentIds)
278
+ ? data.agentIds.filter((id) => typeof id === 'string').slice(0, 50)
279
+ : undefined;
280
+ const mcpServers = Array.isArray(data.mcpServers)
281
+ ? data.mcpServers.filter((server) => typeof server === 'string').slice(0, 50)
282
+ : undefined;
157
283
  return {
158
284
  id: data.id,
159
- name: data.name || data.id,
160
- description: data.description,
161
- prompt: data.prompt || body.trim(),
162
- model: data.model || 'anthropic/claude-sonnet-4',
163
- status: data.status || 'paused',
164
- schedule: data.schedule ?? {
165
- type: 'interval',
166
- hours: 6,
167
- daysOfWeek: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
168
- },
285
+ name,
286
+ description,
287
+ prompt,
288
+ model,
289
+ status,
290
+ schedule,
169
291
  metadata: {
170
292
  createdAt,
171
293
  updatedAt,
@@ -173,11 +295,11 @@ export class JobStore {
173
295
  nextRunAt: toDate(data.metadata?.nextRunAt),
174
296
  },
175
297
  runs,
176
- tags: data.tags ?? [],
177
- contextPaths: data.contextPaths ?? [],
178
- agentId: data.agentId,
179
- agentIds: data.agentIds,
180
- mcpServers: data.mcpServers,
298
+ tags,
299
+ contextPaths,
300
+ agentId: typeof data.agentId === 'string' ? data.agentId : undefined,
301
+ agentIds,
302
+ mcpServers,
181
303
  };
182
304
  }
183
305
  toFrontmatter(job) {
@@ -1,11 +1,11 @@
1
1
  import { Context } from 'hono';
2
- export declare function GET(c: Context): Promise<(Response & import("hono").TypedResponse<string, import("hono/utils/http-status").ContentfulStatusCode, "text">) | (Response & import("hono").TypedResponse<{
2
+ export declare function GET(c: Context): Promise<(Response & import("hono").TypedResponse<{
3
3
  success: false;
4
4
  error: {
5
5
  code: string;
6
6
  message: string;
7
7
  };
8
- }, 404, "json">) | (Response & import("hono").TypedResponse<{
8
+ }, 404, "json">) | (Response & import("hono").TypedResponse<string, import("hono/utils/http-status").ContentfulStatusCode, "text">) | (Response & import("hono").TypedResponse<{
9
9
  success: false;
10
10
  error: {
11
11
  code: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovelybunch/api",
3
- "version": "1.0.69-alpha.11",
3
+ "version": "1.0.69-alpha.14",
4
4
  "type": "module",
5
5
  "main": "dist/server-with-static.js",
6
6
  "exports": {
@@ -36,9 +36,9 @@
36
36
  "dependencies": {
37
37
  "@hono/node-server": "^1.13.7",
38
38
  "@hono/node-ws": "^1.0.6",
39
- "@lovelybunch/core": "^1.0.69-alpha.11",
40
- "@lovelybunch/mcp": "^1.0.69-alpha.11",
41
- "@lovelybunch/types": "^1.0.69-alpha.11",
39
+ "@lovelybunch/core": "^1.0.69-alpha.14",
40
+ "@lovelybunch/mcp": "^1.0.69-alpha.14",
41
+ "@lovelybunch/types": "^1.0.69-alpha.14",
42
42
  "arctic": "^1.9.2",
43
43
  "bcrypt": "^5.1.1",
44
44
  "cookie": "^0.6.0",