@allternit/gizzi-code 1.0.0 → 1.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.
- package/bin/gizzi +4 -0
- package/bin/gizzi-ink +5 -0
- package/package.json +137 -31
- package/src/Tool.ts +26 -0
- package/src/bootstrap/state.ts +165 -322
- package/src/commands.ts +209 -0
- package/src/context/QueuedMessageContext.tsx +63 -0
- package/src/context/fpsMetrics.tsx +30 -0
- package/src/context/mailbox.tsx +38 -0
- package/src/context/modalContext.tsx +58 -0
- package/src/context/notifications.tsx +240 -0
- package/src/context/overlayContext.tsx +151 -0
- package/src/context/promptOverlayContext.tsx +125 -0
- package/src/context/stats.tsx +220 -0
- package/src/context/voice.tsx +88 -0
- package/src/hooks/useCanUseTool.ts +11 -0
- package/src/hooks/useExitOnCtrlCD.ts +40 -187
- package/src/hooks/useExitOnCtrlCDWithKeybindings.ts +68 -0
- package/src/hooks/useKeybinding.ts +68 -209
- package/src/hooks/useTerminalSize.ts +31 -99
- package/src/hooks.ts +37 -0
- package/src/ink.ts +204 -0
- package/src/main.ts +7 -0
- package/src/types/command.ts +216 -0
- package/src/types/connectorText.ts +39 -0
- package/src/types/fileSuggestion.ts +15 -0
- package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +865 -0
- package/src/types/generated/events_mono/common/v1/auth.ts +100 -0
- package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +223 -0
- package/src/types/generated/google/protobuf/timestamp.ts +187 -0
- package/src/types/hooks.ts +319 -0
- package/src/types/ids.ts +44 -0
- package/src/types/logs.ts +331 -0
- package/src/types/merged/index.ts +5 -0
- package/src/types/merged/message.ts +552 -0
- package/src/types/message.ts +927 -186
- package/src/types/messageQueueTypes.ts +21 -0
- package/src/types/notebook.ts +72 -0
- package/src/types/permissions.ts +447 -0
- package/src/types/plugin.ts +363 -0
- package/src/types/statusLine.ts +15 -0
- package/src/types/textInputTypes.ts +387 -0
- package/src/types/tools.ts +149 -0
- package/src/types/utils.ts +20 -0
- package/src/utils/advisor.ts +12 -0
- package/src/utils/api.ts +29 -0
- package/src/utils/array.ts +7 -0
- package/src/utils/attachments.ts +60 -0
- package/src/utils/auth.ts +3 -0
- package/src/utils/claudeInChrome/chromeNativeHost.ts +15 -0
- package/src/utils/claudeInChrome/common.ts +12 -0
- package/src/utils/claudeInChrome/mcpServer.ts +15 -0
- package/src/utils/computerUse/common.ts +19 -0
- package/src/utils/computerUse/mcpServer.ts +15 -0
- package/src/utils/config.ts +35 -0
- package/src/utils/context.ts +19 -0
- package/src/utils/cwd.ts +3 -0
- package/src/utils/debug.ts +3 -0
- package/src/utils/earlyInput.ts +7 -0
- package/src/utils/effort.ts +13 -0
- package/src/utils/embeddedTools.ts +12 -0
- package/src/utils/envUtils.ts +3 -0
- package/src/utils/errors.ts +3 -0
- package/src/utils/execFileNoThrow.ts +24 -0
- package/src/utils/feature-flags.ts +112 -0
- package/src/utils/file.ts +3 -0
- package/src/utils/fileHistory.ts +17 -0
- package/src/utils/fingerprint.ts +7 -0
- package/src/utils/format.ts +75 -305
- package/src/utils/frontmatterParser.ts +33 -0
- package/src/utils/fsOperations.ts +31 -0
- package/src/utils/fullscreen.ts +40 -350
- package/src/utils/git.ts +15 -0
- package/src/utils/imageResizer.ts +30 -0
- package/src/utils/lazySchema.ts +9 -0
- package/src/utils/log.ts +3 -0
- package/src/utils/markdownConfigLoader.ts +12 -0
- package/src/utils/messages.ts +13 -0
- package/src/utils/migration.ts +137 -0
- package/src/utils/model/providers.ts +15 -0
- package/src/utils/path.ts +3 -0
- package/src/utils/permissions/PermissionResult.ts +14 -0
- package/src/utils/permissions/autoModeState.ts +12 -0
- package/src/utils/permissions/filesystem.ts +12 -0
- package/src/utils/plugins/loadPluginOutputStyles.ts +12 -0
- package/src/utils/plugins/schemas.ts +25 -0
- package/src/utils/process.ts +16 -0
- package/src/utils/sandbox/sandbox-adapter.ts +19 -0
- package/src/utils/sessionStorage.ts +238 -472
- package/src/utils/settings/constants.ts +10 -0
- package/src/utils/settings/settings.ts +19 -0
- package/src/utils/settings/types.ts +18 -0
- package/src/utils/shell/shellToolUtils.ts +9 -0
- package/src/utils/sinks.ts +11 -0
- package/src/utils/sleep.ts +7 -0
- package/src/utils/sliceAnsi.ts +7 -0
- package/src/utils/slowOperations.ts +3 -0
- package/src/utils/startupProfiler.ts +11 -0
- package/src/utils/stringUtils.ts +106 -0
- package/src/utils/systemPromptType.ts +9 -0
- package/src/utils/teleport/api.ts +15 -0
- package/src/utils/textHighlighting.ts +16 -0
- package/src/utils/theme.ts +17 -0
- package/src/utils/thinking.ts +58 -0
- package/src/utils/tokens.ts +11 -0
- package/src/utils/toolResultStorage.ts +17 -0
- package/src/utils/worktreeModeEnabled.ts +7 -0
- package/WORKSPACE_INTEGRATION.md +0 -290
- package/chat-sessions/sessions-index.json +0 -98
- package/package.json.original +0 -31
- package/package.json.publish +0 -47
- package/src/bootstrap/state.d.ts +0 -169
- package/src/bootstrap/state.js +0 -261
- package/src/context/pack-builder.d.ts +0 -24
- package/src/context/pack-builder.js +0 -281
- package/src/hooks/useExitOnCtrlCD.d.ts +0 -86
- package/src/hooks/useExitOnCtrlCD.js +0 -130
- package/src/hooks/useKeybinding.d.ts +0 -89
- package/src/hooks/useKeybinding.js +0 -163
- package/src/hooks/useTerminalSize.d.ts +0 -41
- package/src/hooks/useTerminalSize.js +0 -90
- package/src/index.d.ts +0 -23
- package/src/index.js +0 -24
- package/src/runtime/brand/brand.d.ts +0 -488
- package/src/runtime/brand/brand.js +0 -464
- package/src/runtime/brand/brand.ts +0 -667
- package/src/runtime/services/tokenEstimation.d.ts +0 -187
- package/src/runtime/services/tokenEstimation.js +0 -423
- package/src/runtime/services/tokenEstimation.ts +0 -547
- package/src/runtime/tools/Tool.d.ts +0 -239
- package/src/runtime/tools/Tool.js +0 -285
- package/src/runtime/tools/Tool.ts +0 -524
- package/src/scheduler/TaskScheduler.d.ts +0 -98
- package/src/scheduler/TaskScheduler.js +0 -201
- package/src/scheduler/TaskScheduler.ts +0 -259
- package/src/state/AppStateStore.d.ts +0 -347
- package/src/state/AppStateStore.js +0 -439
- package/src/state/AppStateStore.ts +0 -658
- package/src/state/WorkspaceStateStore.d.ts +0 -43
- package/src/state/WorkspaceStateStore.js +0 -224
- package/src/state/WorkspaceStateStore.ts +0 -297
- package/src/types/message.d.ts +0 -190
- package/src/types/message.js +0 -77
- package/src/utils/format.d.ts +0 -126
- package/src/utils/format.js +0 -230
- package/src/utils/fullscreen.d.ts +0 -161
- package/src/utils/fullscreen.js +0 -277
- package/src/utils/sessionStorage.d.ts +0 -210
- package/src/utils/sessionStorage.js +0 -435
- package/src/watcher/WorkspaceWatcher.d.ts +0 -70
- package/src/watcher/WorkspaceWatcher.js +0 -191
- package/src/watcher/WorkspaceWatcher.ts +0 -251
- package/src/workspace/loader.d.ts +0 -30
- package/src/workspace/loader.js +0 -117
- package/src/workspace/types.d.ts +0 -91
- package/src/workspace/types.js +0 -7
- package/threads/thread_1775361175022.json +0 -9
- package/tsconfig.json +0 -14
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gizzi Task Scheduler
|
|
3
|
-
*
|
|
4
|
-
* Manages recurring tasks from HEARTBEAT.md
|
|
5
|
-
* - Daily tasks: Run every 24 hours
|
|
6
|
-
* - Weekly tasks: Run every 7 days
|
|
7
|
-
* - Monthly tasks: Run every 30 days
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Calculate next run time based on frequency
|
|
11
|
-
*/
|
|
12
|
-
function calculateNextRun(frequency, fromTimestamp = Date.now()) {
|
|
13
|
-
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
14
|
-
switch (frequency) {
|
|
15
|
-
case 'daily':
|
|
16
|
-
return fromTimestamp + ONE_DAY;
|
|
17
|
-
case 'weekly':
|
|
18
|
-
return fromTimestamp + 7 * ONE_DAY;
|
|
19
|
-
case 'monthly':
|
|
20
|
-
return fromTimestamp + 30 * ONE_DAY;
|
|
21
|
-
default:
|
|
22
|
-
return fromTimestamp + ONE_DAY;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Task Scheduler for Gizzi
|
|
27
|
-
*/
|
|
28
|
-
export class TaskScheduler {
|
|
29
|
-
constructor(options) {
|
|
30
|
-
this.jobs = new Map();
|
|
31
|
-
this.intervalId = null;
|
|
32
|
-
this.checkIntervalMs = 60000; // 1 minute
|
|
33
|
-
this.isRunning = false;
|
|
34
|
-
this.checkIntervalMs = options?.checkIntervalMs || 60000;
|
|
35
|
-
this.onTaskExecute = options?.onTaskExecute;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Start the scheduler
|
|
39
|
-
*/
|
|
40
|
-
start() {
|
|
41
|
-
if (this.isRunning) {
|
|
42
|
-
console.log('[TaskScheduler] Already running');
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
console.log(`[TaskScheduler] Starting with ${this.checkIntervalMs}ms interval`);
|
|
46
|
-
this.isRunning = true;
|
|
47
|
-
this.intervalId = setInterval(() => {
|
|
48
|
-
this.checkAndExecuteJobs();
|
|
49
|
-
}, this.checkIntervalMs);
|
|
50
|
-
// Initial check
|
|
51
|
-
this.checkAndExecuteJobs();
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Stop the scheduler
|
|
55
|
-
*/
|
|
56
|
-
stop() {
|
|
57
|
-
if (this.intervalId) {
|
|
58
|
-
clearInterval(this.intervalId);
|
|
59
|
-
this.intervalId = null;
|
|
60
|
-
}
|
|
61
|
-
this.isRunning = false;
|
|
62
|
-
console.log('[TaskScheduler] Stopped');
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Register tasks from HEARTBEAT.md
|
|
66
|
-
*/
|
|
67
|
-
registerTasks(agentId, tasks) {
|
|
68
|
-
// Remove existing jobs for this agent
|
|
69
|
-
for (const [id, job] of this.jobs) {
|
|
70
|
-
if (job.agentId === agentId) {
|
|
71
|
-
this.jobs.delete(id);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Add recurring tasks (not startup tasks)
|
|
75
|
-
for (const task of tasks) {
|
|
76
|
-
if (task.frequency === 'startup')
|
|
77
|
-
continue;
|
|
78
|
-
const jobId = `${agentId}_${task.id}`;
|
|
79
|
-
const job = {
|
|
80
|
-
id: jobId,
|
|
81
|
-
taskId: task.id,
|
|
82
|
-
agentId,
|
|
83
|
-
frequency: task.frequency,
|
|
84
|
-
nextRunAt: calculateNextRun(task.frequency),
|
|
85
|
-
enabled: true,
|
|
86
|
-
};
|
|
87
|
-
this.jobs.set(jobId, job);
|
|
88
|
-
console.log(`[TaskScheduler] Registered job ${jobId}, next run: ${new Date(job.nextRunAt).toISOString()}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Unregister all tasks for an agent
|
|
93
|
-
*/
|
|
94
|
-
unregisterAgentTasks(agentId) {
|
|
95
|
-
for (const [id, job] of this.jobs) {
|
|
96
|
-
if (job.agentId === agentId) {
|
|
97
|
-
this.jobs.delete(id);
|
|
98
|
-
console.log(`[TaskScheduler] Unregistered job ${id}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Get all jobs
|
|
104
|
-
*/
|
|
105
|
-
getJobs() {
|
|
106
|
-
return Array.from(this.jobs.values());
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Get jobs for a specific agent
|
|
110
|
-
*/
|
|
111
|
-
getJobsForAgent(agentId) {
|
|
112
|
-
return Array.from(this.jobs.values()).filter(job => job.agentId === agentId);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Get jobs that are due for execution
|
|
116
|
-
*/
|
|
117
|
-
getDueJobs() {
|
|
118
|
-
const now = Date.now();
|
|
119
|
-
return Array.from(this.jobs.values()).filter(job => job.enabled && job.nextRunAt <= now);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Get scheduler status
|
|
123
|
-
*/
|
|
124
|
-
getStatus() {
|
|
125
|
-
const jobs = Array.from(this.jobs.values());
|
|
126
|
-
const enabledJobs = jobs.filter(j => j.enabled);
|
|
127
|
-
const nextJob = enabledJobs.length > 0
|
|
128
|
-
? enabledJobs.sort((a, b) => a.nextRunAt - b.nextRunAt)[0]
|
|
129
|
-
: null;
|
|
130
|
-
return {
|
|
131
|
-
isRunning: this.isRunning,
|
|
132
|
-
totalJobs: jobs.length,
|
|
133
|
-
dueJobs: this.getDueJobs().length,
|
|
134
|
-
nextJob,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Enable a job
|
|
139
|
-
*/
|
|
140
|
-
enableJob(jobId) {
|
|
141
|
-
const job = this.jobs.get(jobId);
|
|
142
|
-
if (job) {
|
|
143
|
-
job.enabled = true;
|
|
144
|
-
job.nextRunAt = calculateNextRun(job.frequency);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Disable a job
|
|
149
|
-
*/
|
|
150
|
-
disableJob(jobId) {
|
|
151
|
-
const job = this.jobs.get(jobId);
|
|
152
|
-
if (job) {
|
|
153
|
-
job.enabled = false;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Record job execution
|
|
158
|
-
*/
|
|
159
|
-
recordExecution(jobId, success) {
|
|
160
|
-
const job = this.jobs.get(jobId);
|
|
161
|
-
if (job) {
|
|
162
|
-
job.lastRunAt = Date.now();
|
|
163
|
-
job.nextRunAt = calculateNextRun(job.frequency);
|
|
164
|
-
console.log(`[TaskScheduler] Job ${jobId} executed: ${success ? 'success' : 'failed'}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Check and execute due jobs
|
|
169
|
-
*/
|
|
170
|
-
async checkAndExecuteJobs() {
|
|
171
|
-
const dueJobs = this.getDueJobs();
|
|
172
|
-
if (dueJobs.length === 0)
|
|
173
|
-
return;
|
|
174
|
-
console.log(`[TaskScheduler] ${dueJobs.length} jobs due for execution`);
|
|
175
|
-
for (const job of dueJobs) {
|
|
176
|
-
await this.executeJob(job);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Execute a single job
|
|
181
|
-
*/
|
|
182
|
-
async executeJob(job) {
|
|
183
|
-
console.log(`[TaskScheduler] Executing job ${job.id}`);
|
|
184
|
-
try {
|
|
185
|
-
if (this.onTaskExecute) {
|
|
186
|
-
await this.onTaskExecute(job);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
// Default execution - just log
|
|
190
|
-
console.log(`[TaskScheduler] Would execute: ${job.taskId}`);
|
|
191
|
-
}
|
|
192
|
-
this.recordExecution(job.id, true);
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
console.error(`[TaskScheduler] Job ${job.id} failed:`, error);
|
|
196
|
-
this.recordExecution(job.id, false);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// Export singleton instance
|
|
201
|
-
export const taskScheduler = new TaskScheduler();
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gizzi Task Scheduler
|
|
3
|
-
*
|
|
4
|
-
* Manages recurring tasks from HEARTBEAT.md
|
|
5
|
-
* - Daily tasks: Run every 24 hours
|
|
6
|
-
* - Weekly tasks: Run every 7 days
|
|
7
|
-
* - Monthly tasks: Run every 30 days
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export type TaskFrequency = 'startup' | 'daily' | 'weekly' | 'monthly';
|
|
11
|
-
|
|
12
|
-
export interface ScheduledTask {
|
|
13
|
-
id: string;
|
|
14
|
-
action: string;
|
|
15
|
-
frequency: TaskFrequency;
|
|
16
|
-
completed: boolean;
|
|
17
|
-
lastRun?: Date;
|
|
18
|
-
nextRun?: Date;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SchedulerJob {
|
|
22
|
-
id: string;
|
|
23
|
-
taskId: string;
|
|
24
|
-
agentId: string;
|
|
25
|
-
frequency: TaskFrequency;
|
|
26
|
-
nextRunAt: number;
|
|
27
|
-
lastRunAt?: number;
|
|
28
|
-
enabled: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Calculate next run time based on frequency
|
|
33
|
-
*/
|
|
34
|
-
function calculateNextRun(frequency: TaskFrequency, fromTimestamp: number = Date.now()): number {
|
|
35
|
-
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
36
|
-
|
|
37
|
-
switch (frequency) {
|
|
38
|
-
case 'daily':
|
|
39
|
-
return fromTimestamp + ONE_DAY;
|
|
40
|
-
case 'weekly':
|
|
41
|
-
return fromTimestamp + 7 * ONE_DAY;
|
|
42
|
-
case 'monthly':
|
|
43
|
-
return fromTimestamp + 30 * ONE_DAY;
|
|
44
|
-
default:
|
|
45
|
-
return fromTimestamp + ONE_DAY;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Task Scheduler for Gizzi
|
|
51
|
-
*/
|
|
52
|
-
export class TaskScheduler {
|
|
53
|
-
private jobs: Map<string, SchedulerJob> = new Map();
|
|
54
|
-
private intervalId: NodeJS.Timeout | null = null;
|
|
55
|
-
private checkIntervalMs: number = 60000; // 1 minute
|
|
56
|
-
private isRunning: boolean = false;
|
|
57
|
-
private onTaskExecute?: (task: SchedulerJob) => Promise<void>;
|
|
58
|
-
|
|
59
|
-
constructor(options?: {
|
|
60
|
-
checkIntervalMs?: number;
|
|
61
|
-
onTaskExecute?: (task: SchedulerJob) => Promise<void>;
|
|
62
|
-
}) {
|
|
63
|
-
this.checkIntervalMs = options?.checkIntervalMs || 60000;
|
|
64
|
-
this.onTaskExecute = options?.onTaskExecute;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Start the scheduler
|
|
69
|
-
*/
|
|
70
|
-
start(): void {
|
|
71
|
-
if (this.isRunning) {
|
|
72
|
-
console.log('[TaskScheduler] Already running');
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
console.log(`[TaskScheduler] Starting with ${this.checkIntervalMs}ms interval`);
|
|
77
|
-
this.isRunning = true;
|
|
78
|
-
|
|
79
|
-
this.intervalId = setInterval(() => {
|
|
80
|
-
this.checkAndExecuteJobs();
|
|
81
|
-
}, this.checkIntervalMs);
|
|
82
|
-
|
|
83
|
-
// Initial check
|
|
84
|
-
this.checkAndExecuteJobs();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Stop the scheduler
|
|
89
|
-
*/
|
|
90
|
-
stop(): void {
|
|
91
|
-
if (this.intervalId) {
|
|
92
|
-
clearInterval(this.intervalId);
|
|
93
|
-
this.intervalId = null;
|
|
94
|
-
}
|
|
95
|
-
this.isRunning = false;
|
|
96
|
-
console.log('[TaskScheduler] Stopped');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Register tasks from HEARTBEAT.md
|
|
101
|
-
*/
|
|
102
|
-
registerTasks(agentId: string, tasks: ScheduledTask[]): void {
|
|
103
|
-
// Remove existing jobs for this agent
|
|
104
|
-
for (const [id, job] of this.jobs) {
|
|
105
|
-
if (job.agentId === agentId) {
|
|
106
|
-
this.jobs.delete(id);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Add recurring tasks (not startup tasks)
|
|
111
|
-
for (const task of tasks) {
|
|
112
|
-
if (task.frequency === 'startup') continue;
|
|
113
|
-
|
|
114
|
-
const jobId = `${agentId}_${task.id}`;
|
|
115
|
-
const job: SchedulerJob = {
|
|
116
|
-
id: jobId,
|
|
117
|
-
taskId: task.id,
|
|
118
|
-
agentId,
|
|
119
|
-
frequency: task.frequency,
|
|
120
|
-
nextRunAt: calculateNextRun(task.frequency),
|
|
121
|
-
enabled: true,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
this.jobs.set(jobId, job);
|
|
125
|
-
console.log(`[TaskScheduler] Registered job ${jobId}, next run: ${new Date(job.nextRunAt).toISOString()}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Unregister all tasks for an agent
|
|
131
|
-
*/
|
|
132
|
-
unregisterAgentTasks(agentId: string): void {
|
|
133
|
-
for (const [id, job] of this.jobs) {
|
|
134
|
-
if (job.agentId === agentId) {
|
|
135
|
-
this.jobs.delete(id);
|
|
136
|
-
console.log(`[TaskScheduler] Unregistered job ${id}`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Get all jobs
|
|
143
|
-
*/
|
|
144
|
-
getJobs(): SchedulerJob[] {
|
|
145
|
-
return Array.from(this.jobs.values());
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Get jobs for a specific agent
|
|
150
|
-
*/
|
|
151
|
-
getJobsForAgent(agentId: string): SchedulerJob[] {
|
|
152
|
-
return Array.from(this.jobs.values()).filter(job => job.agentId === agentId);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Get jobs that are due for execution
|
|
157
|
-
*/
|
|
158
|
-
getDueJobs(): SchedulerJob[] {
|
|
159
|
-
const now = Date.now();
|
|
160
|
-
return Array.from(this.jobs.values()).filter(
|
|
161
|
-
job => job.enabled && job.nextRunAt <= now
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Get scheduler status
|
|
167
|
-
*/
|
|
168
|
-
getStatus(): {
|
|
169
|
-
isRunning: boolean;
|
|
170
|
-
totalJobs: number;
|
|
171
|
-
dueJobs: number;
|
|
172
|
-
nextJob: SchedulerJob | null;
|
|
173
|
-
} {
|
|
174
|
-
const jobs = Array.from(this.jobs.values());
|
|
175
|
-
const enabledJobs = jobs.filter(j => j.enabled);
|
|
176
|
-
const nextJob = enabledJobs.length > 0
|
|
177
|
-
? enabledJobs.sort((a, b) => a.nextRunAt - b.nextRunAt)[0]
|
|
178
|
-
: null;
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
isRunning: this.isRunning,
|
|
182
|
-
totalJobs: jobs.length,
|
|
183
|
-
dueJobs: this.getDueJobs().length,
|
|
184
|
-
nextJob,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Enable a job
|
|
190
|
-
*/
|
|
191
|
-
enableJob(jobId: string): void {
|
|
192
|
-
const job = this.jobs.get(jobId);
|
|
193
|
-
if (job) {
|
|
194
|
-
job.enabled = true;
|
|
195
|
-
job.nextRunAt = calculateNextRun(job.frequency);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Disable a job
|
|
201
|
-
*/
|
|
202
|
-
disableJob(jobId: string): void {
|
|
203
|
-
const job = this.jobs.get(jobId);
|
|
204
|
-
if (job) {
|
|
205
|
-
job.enabled = false;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Record job execution
|
|
211
|
-
*/
|
|
212
|
-
recordExecution(jobId: string, success: boolean): void {
|
|
213
|
-
const job = this.jobs.get(jobId);
|
|
214
|
-
if (job) {
|
|
215
|
-
job.lastRunAt = Date.now();
|
|
216
|
-
job.nextRunAt = calculateNextRun(job.frequency);
|
|
217
|
-
console.log(`[TaskScheduler] Job ${jobId} executed: ${success ? 'success' : 'failed'}`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Check and execute due jobs
|
|
223
|
-
*/
|
|
224
|
-
private async checkAndExecuteJobs(): Promise<void> {
|
|
225
|
-
const dueJobs = this.getDueJobs();
|
|
226
|
-
|
|
227
|
-
if (dueJobs.length === 0) return;
|
|
228
|
-
|
|
229
|
-
console.log(`[TaskScheduler] ${dueJobs.length} jobs due for execution`);
|
|
230
|
-
|
|
231
|
-
for (const job of dueJobs) {
|
|
232
|
-
await this.executeJob(job);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Execute a single job
|
|
238
|
-
*/
|
|
239
|
-
private async executeJob(job: SchedulerJob): Promise<void> {
|
|
240
|
-
console.log(`[TaskScheduler] Executing job ${job.id}`);
|
|
241
|
-
|
|
242
|
-
try {
|
|
243
|
-
if (this.onTaskExecute) {
|
|
244
|
-
await this.onTaskExecute(job);
|
|
245
|
-
} else {
|
|
246
|
-
// Default execution - just log
|
|
247
|
-
console.log(`[TaskScheduler] Would execute: ${job.taskId}`);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
this.recordExecution(job.id, true);
|
|
251
|
-
} catch (error) {
|
|
252
|
-
console.error(`[TaskScheduler] Job ${job.id} failed:`, error);
|
|
253
|
-
this.recordExecution(job.id, false);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Export singleton instance
|
|
259
|
-
export const taskScheduler = new TaskScheduler();
|