@synergenius/flowweaver-pack-weaver 0.6.1 → 0.7.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 (168) hide show
  1. package/dist/bot/ai-client.d.ts +1 -0
  2. package/dist/bot/ai-client.d.ts.map +1 -1
  3. package/dist/bot/ai-client.js +52 -1
  4. package/dist/bot/ai-client.js.map +1 -1
  5. package/dist/bot/audit-logger.d.ts +5 -0
  6. package/dist/bot/audit-logger.d.ts.map +1 -0
  7. package/dist/bot/audit-logger.js +42 -0
  8. package/dist/bot/audit-logger.js.map +1 -0
  9. package/dist/bot/audit-store.d.ts +13 -0
  10. package/dist/bot/audit-store.d.ts.map +1 -0
  11. package/dist/bot/audit-store.js +59 -0
  12. package/dist/bot/audit-store.js.map +1 -0
  13. package/dist/bot/cli-provider.d.ts +1 -0
  14. package/dist/bot/cli-provider.d.ts.map +1 -1
  15. package/dist/bot/cli-provider.js +86 -22
  16. package/dist/bot/cli-provider.js.map +1 -1
  17. package/dist/bot/cli-stream-parser.d.ts +11 -0
  18. package/dist/bot/cli-stream-parser.d.ts.map +1 -0
  19. package/dist/bot/cli-stream-parser.js +53 -0
  20. package/dist/bot/cli-stream-parser.js.map +1 -0
  21. package/dist/bot/file-validator.d.ts +1 -1
  22. package/dist/bot/file-validator.d.ts.map +1 -1
  23. package/dist/bot/file-validator.js +13 -27
  24. package/dist/bot/file-validator.js.map +1 -1
  25. package/dist/bot/fw-api.d.ts +8 -0
  26. package/dist/bot/fw-api.d.ts.map +1 -0
  27. package/dist/bot/fw-api.js +12 -0
  28. package/dist/bot/fw-api.js.map +1 -0
  29. package/dist/bot/runner.d.ts +2 -1
  30. package/dist/bot/runner.d.ts.map +1 -1
  31. package/dist/bot/runner.js +8 -0
  32. package/dist/bot/runner.js.map +1 -1
  33. package/dist/bot/step-executor.d.ts +3 -2
  34. package/dist/bot/step-executor.d.ts.map +1 -1
  35. package/dist/bot/step-executor.js +9 -30
  36. package/dist/bot/step-executor.js.map +1 -1
  37. package/dist/bot/system-prompt.d.ts +13 -1
  38. package/dist/bot/system-prompt.d.ts.map +1 -1
  39. package/dist/bot/system-prompt.js +28 -22
  40. package/dist/bot/system-prompt.js.map +1 -1
  41. package/dist/bot/types.d.ts +9 -1
  42. package/dist/bot/types.d.ts.map +1 -1
  43. package/dist/cli-bridge.d.ts.map +1 -1
  44. package/dist/cli-bridge.js +2 -1
  45. package/dist/cli-bridge.js.map +1 -1
  46. package/dist/cli-handlers.d.ts +2 -1
  47. package/dist/cli-handlers.d.ts.map +1 -1
  48. package/dist/cli-handlers.js +69 -0
  49. package/dist/cli-handlers.js.map +1 -1
  50. package/dist/node-types/approval-gate.d.ts.map +1 -1
  51. package/dist/node-types/approval-gate.js +4 -0
  52. package/dist/node-types/approval-gate.js.map +1 -1
  53. package/dist/node-types/exec-validate-retry.d.ts.map +1 -1
  54. package/dist/node-types/exec-validate-retry.js +10 -4
  55. package/dist/node-types/exec-validate-retry.js.map +1 -1
  56. package/dist/node-types/execute-plan.js +1 -1
  57. package/dist/node-types/execute-plan.js.map +1 -1
  58. package/dist/node-types/git-ops.d.ts.map +1 -1
  59. package/dist/node-types/git-ops.js +2 -0
  60. package/dist/node-types/git-ops.js.map +1 -1
  61. package/dist/node-types/plan-task.d.ts.map +1 -1
  62. package/dist/node-types/plan-task.js +9 -1
  63. package/dist/node-types/plan-task.js.map +1 -1
  64. package/dist/node-types/send-notify.d.ts.map +1 -1
  65. package/dist/node-types/send-notify.js +4 -1
  66. package/dist/node-types/send-notify.js.map +1 -1
  67. package/dist/node-types/validate-result.d.ts +2 -2
  68. package/dist/node-types/validate-result.d.ts.map +1 -1
  69. package/dist/node-types/validate-result.js +2 -2
  70. package/dist/node-types/validate-result.js.map +1 -1
  71. package/dist/workflows/weaver-bot-batch.d.ts +4 -1
  72. package/dist/workflows/weaver-bot-batch.d.ts.map +1 -1
  73. package/dist/workflows/weaver-bot-batch.js +1 -1
  74. package/dist/workflows/weaver-bot-batch.js.map +1 -1
  75. package/dist/workflows/weaver-bot.d.ts +4 -1
  76. package/dist/workflows/weaver-bot.d.ts.map +1 -1
  77. package/dist/workflows/weaver-bot.js +1 -1
  78. package/dist/workflows/weaver-bot.js.map +1 -1
  79. package/flowweaver.manifest.json +1 -1
  80. package/package.json +3 -2
  81. package/src/bot/agent-provider.ts +273 -0
  82. package/src/bot/ai-client.ts +109 -0
  83. package/src/bot/approvals.ts +273 -0
  84. package/src/bot/audit-logger.ts +45 -0
  85. package/src/bot/audit-store.ts +69 -0
  86. package/src/bot/bot-agent-channel.ts +99 -0
  87. package/src/bot/cli-provider.ts +169 -0
  88. package/src/bot/cli-stream-parser.ts +59 -0
  89. package/src/bot/cost-store.ts +92 -0
  90. package/src/bot/cost-tracker.ts +72 -0
  91. package/src/bot/cron-parser.ts +153 -0
  92. package/src/bot/cron-scheduler.ts +48 -0
  93. package/src/bot/dashboard.ts +658 -0
  94. package/src/bot/design-checker.ts +327 -0
  95. package/src/bot/file-lock.ts +73 -0
  96. package/src/bot/file-validator.ts +41 -0
  97. package/src/bot/file-watcher.ts +103 -0
  98. package/src/bot/fw-api.ts +18 -0
  99. package/src/bot/genesis-prompt-context.ts +135 -0
  100. package/src/bot/genesis-store.ts +180 -0
  101. package/src/bot/index.ts +127 -0
  102. package/src/bot/notifications.ts +263 -0
  103. package/src/bot/pipeline-runner.ts +324 -0
  104. package/src/bot/provider-registry.ts +236 -0
  105. package/src/bot/run-store.ts +169 -0
  106. package/src/bot/runner.ts +311 -0
  107. package/src/bot/session-state.ts +73 -0
  108. package/src/bot/steering.ts +44 -0
  109. package/src/bot/step-executor.ts +34 -0
  110. package/src/bot/system-prompt.ts +280 -0
  111. package/src/bot/task-queue.ts +111 -0
  112. package/src/bot/types.ts +571 -0
  113. package/src/bot/utils.ts +17 -0
  114. package/src/bot/watch-daemon.ts +203 -0
  115. package/src/bot/web-approval.ts +240 -0
  116. package/src/cli-bridge.ts +41 -0
  117. package/src/cli-handlers.ts +1271 -0
  118. package/src/docs/weaver-config.md +135 -0
  119. package/src/index.ts +173 -0
  120. package/src/mcp-tools.ts +274 -0
  121. package/src/node-types/abort-task.ts +31 -0
  122. package/src/node-types/approval-gate.ts +75 -0
  123. package/src/node-types/bot-report.ts +82 -0
  124. package/src/node-types/build-context.ts +65 -0
  125. package/src/node-types/detect-provider.ts +75 -0
  126. package/src/node-types/exec-validate-retry.ts +175 -0
  127. package/src/node-types/execute-plan.ts +130 -0
  128. package/src/node-types/execute-target.ts +267 -0
  129. package/src/node-types/fix-errors.ts +68 -0
  130. package/src/node-types/genesis-apply-retry.ts +138 -0
  131. package/src/node-types/genesis-apply.ts +96 -0
  132. package/src/node-types/genesis-approve.ts +73 -0
  133. package/src/node-types/genesis-check-stabilize.ts +37 -0
  134. package/src/node-types/genesis-check-threshold.ts +34 -0
  135. package/src/node-types/genesis-commit.ts +71 -0
  136. package/src/node-types/genesis-compile-validate.ts +77 -0
  137. package/src/node-types/genesis-diff-fingerprint.ts +67 -0
  138. package/src/node-types/genesis-diff-workflow.ts +71 -0
  139. package/src/node-types/genesis-escrow-grace.ts +62 -0
  140. package/src/node-types/genesis-escrow-migrate.ts +138 -0
  141. package/src/node-types/genesis-escrow-recover.ts +99 -0
  142. package/src/node-types/genesis-escrow-stage.ts +104 -0
  143. package/src/node-types/genesis-escrow-validate.ts +120 -0
  144. package/src/node-types/genesis-load-config.ts +44 -0
  145. package/src/node-types/genesis-observe.ts +119 -0
  146. package/src/node-types/genesis-propose.ts +97 -0
  147. package/src/node-types/genesis-report.ts +95 -0
  148. package/src/node-types/genesis-snapshot.ts +30 -0
  149. package/src/node-types/genesis-try-apply.ts +165 -0
  150. package/src/node-types/genesis-update-history.ts +72 -0
  151. package/src/node-types/genesis-validate-proposal.ts +124 -0
  152. package/src/node-types/git-ops.ts +72 -0
  153. package/src/node-types/index.ts +36 -0
  154. package/src/node-types/load-config.ts +27 -0
  155. package/src/node-types/plan-task.ts +77 -0
  156. package/src/node-types/read-workflow.ts +68 -0
  157. package/src/node-types/receive-task.ts +92 -0
  158. package/src/node-types/report.ts +25 -0
  159. package/src/node-types/resolve-target.ts +64 -0
  160. package/src/node-types/route-task.ts +25 -0
  161. package/src/node-types/send-notify.ts +75 -0
  162. package/src/node-types/validate-result.ts +49 -0
  163. package/src/templates/index.ts +5 -0
  164. package/src/templates/weaver-bot-template.ts +106 -0
  165. package/src/workflows/genesis-task.ts +91 -0
  166. package/src/workflows/index.ts +3 -0
  167. package/src/workflows/weaver-bot-batch.ts +65 -0
  168. package/src/workflows/weaver-bot.ts +79 -0
@@ -0,0 +1,571 @@
1
+ export type ProviderName = 'anthropic' | 'claude-cli' | 'copilot-cli' | (string & {});
2
+
3
+ export interface ProviderInfo {
4
+ type: 'anthropic' | 'claude-cli' | 'copilot-cli';
5
+ model?: string;
6
+ maxTokens?: number;
7
+ apiKey?: string;
8
+ }
9
+
10
+ export interface WeaverEnv {
11
+ projectDir: string;
12
+ config: WeaverConfig;
13
+ providerType: string;
14
+ providerInfo: ProviderInfo;
15
+ }
16
+
17
+ export interface BotProviderConfig {
18
+ name: ProviderName;
19
+ model?: string;
20
+ maxTokens?: number;
21
+ module?: string;
22
+ options?: Record<string, unknown>;
23
+ }
24
+
25
+ // --- Provider Registry (F5) ---
26
+
27
+ export interface ProviderMetadata {
28
+ displayName: string;
29
+ description?: string;
30
+ source: 'built-in' | 'npm' | 'local';
31
+ requiredEnvVars?: string[];
32
+ detectCliCommand?: string;
33
+ }
34
+
35
+ export interface ProviderFactoryConfig {
36
+ model?: string;
37
+ maxTokens?: number;
38
+ options?: Record<string, unknown>;
39
+ }
40
+
41
+ export type ProviderFactory = (config: ProviderFactoryConfig) => BotAgentProvider | Promise<BotAgentProvider>;
42
+
43
+ export interface ProviderModule {
44
+ createProvider: ProviderFactory;
45
+ metadata?: ProviderMetadata;
46
+ }
47
+
48
+ export interface ToolDefinition {
49
+ name: string;
50
+ description: string;
51
+ input_schema: Record<string, unknown>;
52
+ }
53
+
54
+ export interface ToolUseResult {
55
+ toolName: string;
56
+ toolInput: Record<string, unknown>;
57
+ }
58
+
59
+ export interface StreamChunk {
60
+ type: 'text' | 'tool_use' | 'usage' | 'done';
61
+ text?: string;
62
+ toolUse?: ToolUseResult;
63
+ usage?: TokenUsage;
64
+ }
65
+
66
+ export interface BotAgentProvider {
67
+ decide(request: {
68
+ agentId: string;
69
+ context: Record<string, unknown>;
70
+ prompt: string;
71
+ }): Promise<Record<string, unknown>>;
72
+ stream?(request: {
73
+ agentId: string;
74
+ context: Record<string, unknown>;
75
+ prompt: string;
76
+ }): AsyncIterable<StreamChunk>;
77
+ decideWithTools?(request: {
78
+ agentId: string;
79
+ context: Record<string, unknown>;
80
+ prompt: string;
81
+ tools: ToolDefinition[];
82
+ }): Promise<{ result: Record<string, unknown>; toolCalls?: ToolUseResult[] }>;
83
+ onUsage?: OnUsageCallback;
84
+ }
85
+
86
+ export type ApprovalMode = 'auto' | 'prompt' | 'webhook' | 'timeout-auto' | 'web';
87
+
88
+ export interface BotApprovalConfig {
89
+ mode: ApprovalMode;
90
+ timeoutSeconds?: number;
91
+ webhookUrl?: string;
92
+ webPort?: number;
93
+ webOpen?: boolean;
94
+ }
95
+
96
+ export interface BotNotifyConfig {
97
+ channel: 'discord' | 'slack' | 'webhook';
98
+ url: string;
99
+ events?: NotificationEventType[];
100
+ headers?: Record<string, string>;
101
+ }
102
+
103
+ export type NotificationEventType =
104
+ | 'workflow-start'
105
+ | 'workflow-complete'
106
+ | 'cycle-start'
107
+ | 'cycle-complete'
108
+ | 'approval-needed'
109
+ | 'error'
110
+ | 'pipeline-start'
111
+ | 'pipeline-complete'
112
+ | 'stage-start'
113
+ | 'stage-complete'
114
+ | 'bot-task-start'
115
+ | 'bot-task-complete'
116
+ | 'bot-plan-ready'
117
+ | 'bot-step-complete'
118
+ | 'bot-validation-failed'
119
+ | 'bot-fix-attempt'
120
+ | 'bot-session-start'
121
+ | 'bot-session-end'
122
+ | 'bot-steering-received';
123
+
124
+ export interface NotificationEvent {
125
+ type: NotificationEventType;
126
+ workflowFile?: string;
127
+ cycle?: number;
128
+ projectDir: string;
129
+ summary?: string;
130
+ proposal?: Record<string, unknown>;
131
+ diff?: Record<string, unknown>;
132
+ outcome?: string;
133
+ error?: string;
134
+ pipelineName?: string;
135
+ stageId?: string;
136
+ completedStages?: number;
137
+ totalStages?: number;
138
+ }
139
+
140
+ export type ExecutionEventType = 'node-start' | 'node-complete' | 'node-error';
141
+
142
+ export interface ExecutionEvent {
143
+ type: ExecutionEventType;
144
+ nodeId: string;
145
+ nodeType?: string;
146
+ timestamp: number;
147
+ durationMs?: number;
148
+ error?: string;
149
+ }
150
+
151
+ export interface BotConfig {
152
+ provider: 'auto' | ProviderName | BotProviderConfig;
153
+ approval?: 'auto' | 'prompt' | 'webhook' | 'timeout-auto' | 'web' | BotApprovalConfig;
154
+ notify?: BotNotifyConfig | BotNotifyConfig[];
155
+ target?: string;
156
+ }
157
+
158
+ /** Standalone Weaver config (same schema as BotConfig, used in .weaver.json) */
159
+ export type WeaverConfig = BotConfig;
160
+
161
+ export interface WorkflowResult {
162
+ success: boolean;
163
+ summary: string;
164
+ outcome: string;
165
+ functionName?: string;
166
+ executionTime?: number;
167
+ cost?: RunCostSummary;
168
+ }
169
+
170
+ // --- History (F2) ---
171
+
172
+ export type RunOutcome = 'completed' | 'failed' | 'error' | 'skipped';
173
+
174
+ export interface RunRecord {
175
+ id: string;
176
+ workflowFile: string;
177
+ startedAt: string;
178
+ finishedAt: string;
179
+ durationMs: number;
180
+ success: boolean;
181
+ outcome: RunOutcome;
182
+ summary: string;
183
+ functionName?: string;
184
+ executionTime?: number;
185
+ params?: Record<string, unknown>;
186
+ dryRun: boolean;
187
+ provider?: string;
188
+ pipelineName?: string;
189
+ stageName?: string;
190
+ }
191
+
192
+ export interface RunFilter {
193
+ workflowFile?: string;
194
+ outcome?: RunOutcome;
195
+ success?: boolean;
196
+ since?: string;
197
+ before?: string;
198
+ limit?: number;
199
+ }
200
+
201
+ export interface RetentionPolicy {
202
+ maxRecords?: number;
203
+ maxAgeDays?: number;
204
+ }
205
+
206
+ // --- Cost Tracking (F7) ---
207
+
208
+ export interface TokenUsage {
209
+ inputTokens: number;
210
+ outputTokens: number;
211
+ cacheCreationInputTokens?: number;
212
+ cacheReadInputTokens?: number;
213
+ }
214
+
215
+ export type OnUsageCallback = (step: string, model: string, usage: TokenUsage) => void;
216
+
217
+ export interface RunCostEntry {
218
+ step: string;
219
+ model: string;
220
+ usage: TokenUsage;
221
+ estimatedCost: number;
222
+ timestamp: number;
223
+ }
224
+
225
+ export interface RunCostSummary {
226
+ entries: RunCostEntry[];
227
+ totalInputTokens: number;
228
+ totalOutputTokens: number;
229
+ totalCost: number;
230
+ model: string;
231
+ provider: string;
232
+ }
233
+
234
+ export interface CostRecord {
235
+ timestamp: number;
236
+ workflowFile: string;
237
+ provider: string;
238
+ model: string;
239
+ inputTokens: number;
240
+ outputTokens: number;
241
+ estimatedCost: number;
242
+ steps: number;
243
+ }
244
+
245
+ export interface CostSummary {
246
+ totalCost: number;
247
+ totalInputTokens: number;
248
+ totalOutputTokens: number;
249
+ totalRuns: number;
250
+ byModel: Record<string, { runs: number; inputTokens: number; outputTokens: number; cost: number }>;
251
+ }
252
+
253
+ // --- Watch/Cron (F4) ---
254
+
255
+ export type CronExpression = string;
256
+
257
+ export interface ParsedCron {
258
+ minute: CronField;
259
+ hour: CronField;
260
+ dayOfMonth: CronField;
261
+ month: CronField;
262
+ dayOfWeek: CronField;
263
+ source: string;
264
+ }
265
+
266
+ export interface CronField {
267
+ type: 'wildcard' | 'list';
268
+ values: number[];
269
+ }
270
+
271
+ export type TriggerSource = 'file-change' | 'cron';
272
+
273
+ export interface WatchDaemonOptions {
274
+ filePath: string;
275
+ watchFile: boolean;
276
+ cron?: CronExpression;
277
+ debounceMs: number;
278
+ logFile?: string;
279
+ verbose: boolean;
280
+ params?: Record<string, unknown>;
281
+ config?: WeaverConfig;
282
+ quiet: boolean;
283
+ }
284
+
285
+ export interface WatchDaemonState {
286
+ running: boolean;
287
+ lastRun: Date | null;
288
+ lastTrigger: TriggerSource | null;
289
+ lastResult: WorkflowResult | null;
290
+ runCount: number;
291
+ errorCount: number;
292
+ startedAt: Date;
293
+ queued: boolean;
294
+ }
295
+
296
+ // --- Pipelines (F1) ---
297
+
298
+ export type StageCondition = 'on-success' | 'on-failure' | 'always';
299
+ export type StageStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped' | 'cancelled';
300
+
301
+ export interface PipelineStage {
302
+ id: string;
303
+ workflow: string;
304
+ label?: string;
305
+ dependsOn?: string[];
306
+ condition?: StageCondition;
307
+ params?: Record<string, unknown>;
308
+ timeoutSeconds?: number;
309
+ }
310
+
311
+ export interface PipelineConfig {
312
+ version: 1;
313
+ name: string;
314
+ description?: string;
315
+ stages: PipelineStage[];
316
+ failFast?: boolean;
317
+ defaultTimeoutSeconds?: number;
318
+ config?: WeaverConfig;
319
+ }
320
+
321
+ export interface StageResult {
322
+ id: string;
323
+ status: StageStatus;
324
+ workflowResult: WorkflowResult | null;
325
+ durationMs: number;
326
+ error?: string;
327
+ wave: number;
328
+ }
329
+
330
+ export interface PipelineResult {
331
+ success: boolean;
332
+ outcome: string;
333
+ durationMs: number;
334
+ stages: Record<string, StageResult>;
335
+ stageOrder: string[];
336
+ }
337
+
338
+ // --- Dashboard (F3) ---
339
+
340
+ export type DashboardEventType = ExecutionEventType | 'workflow-start' | 'workflow-complete' | 'workflow-error' | 'approval-pending' | 'approval-resolved';
341
+ export type DashboardNodeStatus = 'pending' | 'running' | 'succeeded' | 'failed';
342
+
343
+ export interface DashboardEvent {
344
+ type: DashboardEventType;
345
+ timestamp: number;
346
+ nodeId?: string;
347
+ nodeType?: string;
348
+ durationMs?: number;
349
+ error?: string;
350
+ summary?: string;
351
+ approval?: { id: string; prompt: string; context: Record<string, unknown> };
352
+ }
353
+
354
+ export interface DashboardNodeState {
355
+ nodeId: string;
356
+ nodeType?: string;
357
+ status: DashboardNodeStatus;
358
+ startedAt?: number;
359
+ completedAt?: number;
360
+ durationMs?: number;
361
+ error?: string;
362
+ }
363
+
364
+ export interface DashboardServerOptions {
365
+ port: number;
366
+ open: boolean;
367
+ keepAlive: boolean;
368
+ keepAliveSeconds: number;
369
+ }
370
+
371
+ // --- Bot Task Types ---
372
+
373
+ export type BotNotificationEventType =
374
+ | 'bot-task-start'
375
+ | 'bot-task-complete'
376
+ | 'bot-plan-ready'
377
+ | 'bot-step-complete'
378
+ | 'bot-validation-failed'
379
+ | 'bot-fix-attempt'
380
+ | 'bot-session-start'
381
+ | 'bot-session-end'
382
+ | 'bot-steering-received';
383
+
384
+ export interface BotTask {
385
+ instruction: string;
386
+ mode: 'create' | 'modify' | 'read' | 'batch';
387
+ targets?: string[];
388
+ options?: { template?: string; batchCount?: number; dryRun?: boolean };
389
+ }
390
+
391
+ export interface BotPlanStep {
392
+ id: string;
393
+ operation: string;
394
+ description: string;
395
+ args: Record<string, unknown>;
396
+ }
397
+
398
+ export interface BotPlan {
399
+ steps: BotPlanStep[];
400
+ summary: string;
401
+ }
402
+
403
+ export interface BotValidationResult {
404
+ file: string;
405
+ valid: boolean;
406
+ errors: string[];
407
+ warnings: string[];
408
+ }
409
+
410
+ export interface BotExecutionResult {
411
+ success: boolean;
412
+ filesModified: string[];
413
+ filesCreated: string[];
414
+ stepsCompleted: number;
415
+ stepsTotal: number;
416
+ errors: string[];
417
+ output: string;
418
+ }
419
+
420
+ // --- Genesis Self-Evolution ---
421
+
422
+ export type GenesisImpactLevel = 'COSMETIC' | 'MINOR' | 'BREAKING' | 'CRITICAL';
423
+ export type GenesisOperationType =
424
+ | 'addNode' | 'removeNode' | 'addConnection' | 'removeConnection' | 'implementNode'
425
+ | 'selfModifyWorkflow' | 'selfModifyNodeType' | 'selfModifyModule';
426
+
427
+ export interface GenesisConfig {
428
+ intent: string;
429
+ focus: string[];
430
+ constraints: string[];
431
+ approvalThreshold: GenesisImpactLevel;
432
+ budgetPerCycle: number;
433
+ stabilize: boolean;
434
+ targetWorkflow: string;
435
+ maxCyclesPerRun: number;
436
+ selfEvolve?: boolean;
437
+ selfEvolveGracePeriod?: number;
438
+ selfEvolveMaxFailures?: number;
439
+ selfEvolveBudget?: number;
440
+ }
441
+
442
+ export interface GenesisOperation {
443
+ type: GenesisOperationType;
444
+ args: { file?: string; nodeId?: string; nodeType?: string; from?: string; to?: string; content?: string };
445
+ costUnits: number;
446
+ rationale: string;
447
+ }
448
+
449
+ export interface GenesisProposal {
450
+ operations: GenesisOperation[];
451
+ totalCost: number;
452
+ impactLevel: GenesisImpactLevel;
453
+ summary: string;
454
+ rationale: string;
455
+ }
456
+
457
+ export interface GenesisFingerprint {
458
+ timestamp: string;
459
+ files: Record<string, string>;
460
+ packageJson: Record<string, unknown> | null;
461
+ gitBranch: string | null;
462
+ gitCommit: string | null;
463
+ workflowHash: string;
464
+ existingWorkflows: string[];
465
+ }
466
+
467
+ export interface GenesisCycleRecord {
468
+ id: string;
469
+ timestamp: string;
470
+ durationMs: number;
471
+ fingerprint: GenesisFingerprint;
472
+ proposal: GenesisProposal | null;
473
+ outcome: 'applied' | 'rolled-back' | 'rejected' | 'stabilized' | 'no-change' | 'error';
474
+ diffSummary: string | null;
475
+ approvalRequired: boolean;
476
+ approved: boolean | null;
477
+ error: string | null;
478
+ snapshotFile: string | null;
479
+ }
480
+
481
+ export interface GenesisHistory {
482
+ configHash: string;
483
+ cycles: GenesisCycleRecord[];
484
+ }
485
+
486
+ export interface WeaverContext {
487
+ env: WeaverEnv;
488
+ targetPath?: string;
489
+ taskJson?: string;
490
+ hasTask?: boolean;
491
+ contextBundle?: string;
492
+ planJson?: string;
493
+ rejectionReason?: string;
494
+ resultJson?: string;
495
+ validationResultJson?: string;
496
+ filesModified?: string;
497
+ allValid?: boolean;
498
+ gitResultJson?: string;
499
+ }
500
+
501
+ export interface GenesisContext {
502
+ env: WeaverEnv;
503
+ genesisConfigJson: string;
504
+ cycleId: string;
505
+ fingerprintJson?: string;
506
+ diffJson?: string;
507
+ stabilized?: boolean;
508
+ proposalJson?: string;
509
+ snapshotPath?: string;
510
+ applyResultJson?: string;
511
+ workflowDiffJson?: string;
512
+ approvalRequired?: boolean;
513
+ approved?: boolean;
514
+ commitResultJson?: string;
515
+ cycleRecordJson?: string;
516
+ workflowDescription?: string;
517
+ startTimeMs?: number;
518
+ error?: string;
519
+ hasSelfModifyOps?: boolean;
520
+ selfModifyOpsJson?: string;
521
+ escrowResultJson?: string;
522
+ escrowGraceLocked?: boolean;
523
+ escrowGraceRemaining?: number;
524
+ }
525
+
526
+ // --- Escrow (Self-Modify) ---
527
+
528
+ export type EscrowPhase = 'staged' | 'validated' | 'migrating' | 'migrated' | 'rolled-back';
529
+
530
+ export interface EscrowToken {
531
+ migrationId: string;
532
+ cycleId: string;
533
+ stagedAt: string;
534
+ phase: EscrowPhase;
535
+ affectedFiles: string[];
536
+ stagedFileHashes: Record<string, string>;
537
+ backupFileHashes: Record<string, string>;
538
+ validationResult?: { compiled: boolean; validated: boolean; error?: string };
539
+ migratedAt?: string;
540
+ rollbackReason?: string;
541
+ ownerPid: number;
542
+ graceRemaining: number;
543
+ graceCycleIds: string[];
544
+ }
545
+
546
+ export interface GenesisSelfMigrationRecord {
547
+ migrationId: string;
548
+ cycleId: string;
549
+ timestamp: string;
550
+ affectedFiles: string[];
551
+ outcome: 'migrated' | 'rolled-back' | 'grace-cleared';
552
+ graceCompleted: boolean;
553
+ rollbackReason?: string;
554
+ }
555
+
556
+ // --- Audit Events ---
557
+
558
+ export type AuditEventType =
559
+ | 'run-start' | 'plan-created' | 'approval-decision'
560
+ | 'step-start' | 'step-complete' | 'validation-run'
561
+ | 'fix-attempt' | 'git-operation' | 'notification-sent'
562
+ | 'run-complete';
563
+
564
+ export interface AuditEvent {
565
+ type: AuditEventType;
566
+ timestamp: string;
567
+ runId: string;
568
+ data?: Record<string, unknown>;
569
+ }
570
+
571
+ export type AuditEventCallback = (event: AuditEvent) => void;
@@ -0,0 +1,17 @@
1
+ import { exec } from 'node:child_process';
2
+
3
+ export function openBrowser(url: string): void {
4
+ let cmd: string;
5
+ if (process.platform === 'darwin') {
6
+ cmd = `open "${url}"`;
7
+ } else if (process.platform === 'win32') {
8
+ // Windows 'start' treats the first quoted string as a window title,
9
+ // so we pass an empty title before the URL
10
+ cmd = `start "" "${url}"`;
11
+ } else {
12
+ cmd = `xdg-open "${url}"`;
13
+ }
14
+ exec(cmd, (err) => {
15
+ if (err) console.log(`[weaver] Could not open browser. Visit: ${url}`);
16
+ });
17
+ }