@allternit/gizzi-code 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 (64) hide show
  1. package/WORKSPACE_INTEGRATION.md +290 -0
  2. package/chat-sessions/sessions-index.json +98 -0
  3. package/package.json +43 -0
  4. package/package.json.original +31 -0
  5. package/package.json.publish +47 -0
  6. package/src/bootstrap/state.d.ts +169 -0
  7. package/src/bootstrap/state.js +261 -0
  8. package/src/bootstrap/state.ts +371 -0
  9. package/src/context/pack-builder.d.ts +24 -0
  10. package/src/context/pack-builder.js +281 -0
  11. package/src/context/pack-builder.ts +334 -0
  12. package/src/hooks/useExitOnCtrlCD.d.ts +86 -0
  13. package/src/hooks/useExitOnCtrlCD.js +130 -0
  14. package/src/hooks/useExitOnCtrlCD.ts +202 -0
  15. package/src/hooks/useKeybinding.d.ts +89 -0
  16. package/src/hooks/useKeybinding.js +163 -0
  17. package/src/hooks/useKeybinding.ts +226 -0
  18. package/src/hooks/useTerminalSize.d.ts +41 -0
  19. package/src/hooks/useTerminalSize.js +90 -0
  20. package/src/hooks/useTerminalSize.ts +117 -0
  21. package/src/index.d.ts +23 -0
  22. package/src/index.js +24 -0
  23. package/src/index.ts +132 -0
  24. package/src/runtime/brand/brand.d.ts +488 -0
  25. package/src/runtime/brand/brand.js +464 -0
  26. package/src/runtime/brand/brand.ts +667 -0
  27. package/src/runtime/services/tokenEstimation.d.ts +187 -0
  28. package/src/runtime/services/tokenEstimation.js +423 -0
  29. package/src/runtime/services/tokenEstimation.ts +547 -0
  30. package/src/runtime/tools/Tool.d.ts +239 -0
  31. package/src/runtime/tools/Tool.js +285 -0
  32. package/src/runtime/tools/Tool.ts +524 -0
  33. package/src/scheduler/TaskScheduler.d.ts +98 -0
  34. package/src/scheduler/TaskScheduler.js +201 -0
  35. package/src/scheduler/TaskScheduler.ts +259 -0
  36. package/src/state/AppStateStore.d.ts +347 -0
  37. package/src/state/AppStateStore.js +439 -0
  38. package/src/state/AppStateStore.ts +658 -0
  39. package/src/state/WorkspaceStateStore.d.ts +43 -0
  40. package/src/state/WorkspaceStateStore.js +224 -0
  41. package/src/state/WorkspaceStateStore.ts +297 -0
  42. package/src/types/message.d.ts +190 -0
  43. package/src/types/message.js +77 -0
  44. package/src/types/message.ts +277 -0
  45. package/src/utils/format.d.ts +126 -0
  46. package/src/utils/format.js +230 -0
  47. package/src/utils/format.ts +336 -0
  48. package/src/utils/fullscreen.d.ts +161 -0
  49. package/src/utils/fullscreen.js +277 -0
  50. package/src/utils/fullscreen.ts +382 -0
  51. package/src/utils/sessionStorage.d.ts +210 -0
  52. package/src/utils/sessionStorage.js +435 -0
  53. package/src/utils/sessionStorage.ts +559 -0
  54. package/src/watcher/WorkspaceWatcher.d.ts +70 -0
  55. package/src/watcher/WorkspaceWatcher.js +191 -0
  56. package/src/watcher/WorkspaceWatcher.ts +251 -0
  57. package/src/workspace/loader.d.ts +30 -0
  58. package/src/workspace/loader.js +117 -0
  59. package/src/workspace/loader.ts +171 -0
  60. package/src/workspace/types.d.ts +91 -0
  61. package/src/workspace/types.js +7 -0
  62. package/src/workspace/types.ts +122 -0
  63. package/threads/thread_1775361175022.json +9 -0
  64. package/tsconfig.json +14 -0
@@ -0,0 +1,201 @@
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();
@@ -0,0 +1,259 @@
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();