@synergenius/flow-weaver-pack-weaver 0.8.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/LICENSE +204 -0
- package/README.md +167 -0
- package/dist/bot/agent-provider.d.ts +34 -0
- package/dist/bot/agent-provider.d.ts.map +1 -0
- package/dist/bot/agent-provider.js +218 -0
- package/dist/bot/agent-provider.js.map +1 -0
- package/dist/bot/ai-client.d.ts +15 -0
- package/dist/bot/ai-client.d.ts.map +1 -0
- package/dist/bot/ai-client.js +128 -0
- package/dist/bot/ai-client.js.map +1 -0
- package/dist/bot/approvals.d.ts +22 -0
- package/dist/bot/approvals.d.ts.map +1 -0
- package/dist/bot/approvals.js +187 -0
- package/dist/bot/approvals.js.map +1 -0
- package/dist/bot/audit-logger.d.ts +5 -0
- package/dist/bot/audit-logger.d.ts.map +1 -0
- package/dist/bot/audit-logger.js +42 -0
- package/dist/bot/audit-logger.js.map +1 -0
- package/dist/bot/audit-store.d.ts +13 -0
- package/dist/bot/audit-store.d.ts.map +1 -0
- package/dist/bot/audit-store.js +59 -0
- package/dist/bot/audit-store.js.map +1 -0
- package/dist/bot/bot-agent-channel.d.ts +46 -0
- package/dist/bot/bot-agent-channel.d.ts.map +1 -0
- package/dist/bot/bot-agent-channel.js +58 -0
- package/dist/bot/bot-agent-channel.js.map +1 -0
- package/dist/bot/cli-provider.d.ts +29 -0
- package/dist/bot/cli-provider.d.ts.map +1 -0
- package/dist/bot/cli-provider.js +132 -0
- package/dist/bot/cli-provider.js.map +1 -0
- package/dist/bot/cli-stream-parser.d.ts +11 -0
- package/dist/bot/cli-stream-parser.d.ts.map +1 -0
- package/dist/bot/cli-stream-parser.js +53 -0
- package/dist/bot/cli-stream-parser.js.map +1 -0
- package/dist/bot/cost-store.d.ts +18 -0
- package/dist/bot/cost-store.d.ts.map +1 -0
- package/dist/bot/cost-store.js +81 -0
- package/dist/bot/cost-store.js.map +1 -0
- package/dist/bot/cost-tracker.d.ts +18 -0
- package/dist/bot/cost-tracker.d.ts.map +1 -0
- package/dist/bot/cost-tracker.js +60 -0
- package/dist/bot/cost-tracker.js.map +1 -0
- package/dist/bot/cron-parser.d.ts +5 -0
- package/dist/bot/cron-parser.d.ts.map +1 -0
- package/dist/bot/cron-parser.js +141 -0
- package/dist/bot/cron-parser.js.map +1 -0
- package/dist/bot/cron-scheduler.d.ts +12 -0
- package/dist/bot/cron-scheduler.d.ts.map +1 -0
- package/dist/bot/cron-scheduler.js +43 -0
- package/dist/bot/cron-scheduler.js.map +1 -0
- package/dist/bot/dashboard.d.ts +34 -0
- package/dist/bot/dashboard.d.ts.map +1 -0
- package/dist/bot/dashboard.js +602 -0
- package/dist/bot/dashboard.js.map +1 -0
- package/dist/bot/design-checker.d.ts +24 -0
- package/dist/bot/design-checker.d.ts.map +1 -0
- package/dist/bot/design-checker.js +269 -0
- package/dist/bot/design-checker.js.map +1 -0
- package/dist/bot/file-lock.d.ts +7 -0
- package/dist/bot/file-lock.d.ts.map +1 -0
- package/dist/bot/file-lock.js +64 -0
- package/dist/bot/file-lock.js.map +1 -0
- package/dist/bot/file-validator.d.ts +10 -0
- package/dist/bot/file-validator.d.ts.map +1 -0
- package/dist/bot/file-validator.js +27 -0
- package/dist/bot/file-validator.js.map +1 -0
- package/dist/bot/file-watcher.d.ts +24 -0
- package/dist/bot/file-watcher.d.ts.map +1 -0
- package/dist/bot/file-watcher.js +98 -0
- package/dist/bot/file-watcher.js.map +1 -0
- package/dist/bot/fw-api.d.ts +8 -0
- package/dist/bot/fw-api.d.ts.map +1 -0
- package/dist/bot/fw-api.js +12 -0
- package/dist/bot/fw-api.js.map +1 -0
- package/dist/bot/genesis-prompt-context.d.ts +31 -0
- package/dist/bot/genesis-prompt-context.d.ts.map +1 -0
- package/dist/bot/genesis-prompt-context.js +121 -0
- package/dist/bot/genesis-prompt-context.js.map +1 -0
- package/dist/bot/genesis-store.d.ts +28 -0
- package/dist/bot/genesis-store.d.ts.map +1 -0
- package/dist/bot/genesis-store.js +154 -0
- package/dist/bot/genesis-store.js.map +1 -0
- package/dist/bot/index.d.ts +38 -0
- package/dist/bot/index.d.ts.map +1 -0
- package/dist/bot/index.js +37 -0
- package/dist/bot/index.js.map +1 -0
- package/dist/bot/notifications.d.ts +20 -0
- package/dist/bot/notifications.d.ts.map +1 -0
- package/dist/bot/notifications.js +215 -0
- package/dist/bot/notifications.js.map +1 -0
- package/dist/bot/pipeline-runner.d.ts +22 -0
- package/dist/bot/pipeline-runner.d.ts.map +1 -0
- package/dist/bot/pipeline-runner.js +263 -0
- package/dist/bot/pipeline-runner.js.map +1 -0
- package/dist/bot/provider-registry.d.ts +26 -0
- package/dist/bot/provider-registry.d.ts.map +1 -0
- package/dist/bot/provider-registry.js +175 -0
- package/dist/bot/provider-registry.js.map +1 -0
- package/dist/bot/run-store.d.ts +25 -0
- package/dist/bot/run-store.d.ts.map +1 -0
- package/dist/bot/run-store.js +156 -0
- package/dist/bot/run-store.js.map +1 -0
- package/dist/bot/runner.d.ts +13 -0
- package/dist/bot/runner.d.ts.map +1 -0
- package/dist/bot/runner.js +244 -0
- package/dist/bot/runner.js.map +1 -0
- package/dist/bot/session-state.d.ts +19 -0
- package/dist/bot/session-state.d.ts.map +1 -0
- package/dist/bot/session-state.js +65 -0
- package/dist/bot/session-state.js.map +1 -0
- package/dist/bot/steering.d.ts +13 -0
- package/dist/bot/steering.d.ts.map +1 -0
- package/dist/bot/steering.js +40 -0
- package/dist/bot/steering.js.map +1 -0
- package/dist/bot/step-executor.d.ts +10 -0
- package/dist/bot/step-executor.d.ts.map +1 -0
- package/dist/bot/step-executor.js +30 -0
- package/dist/bot/step-executor.js.map +1 -0
- package/dist/bot/system-prompt.d.ts +19 -0
- package/dist/bot/system-prompt.d.ts.map +1 -0
- package/dist/bot/system-prompt.js +222 -0
- package/dist/bot/system-prompt.js.map +1 -0
- package/dist/bot/task-queue.d.ts +26 -0
- package/dist/bot/task-queue.d.ts.map +1 -0
- package/dist/bot/task-queue.js +98 -0
- package/dist/bot/task-queue.js.map +1 -0
- package/dist/bot/types.d.ts +478 -0
- package/dist/bot/types.d.ts.map +1 -0
- package/dist/bot/types.js +2 -0
- package/dist/bot/types.js.map +1 -0
- package/dist/bot/utils.d.ts +2 -0
- package/dist/bot/utils.d.ts.map +1 -0
- package/dist/bot/utils.js +20 -0
- package/dist/bot/utils.js.map +1 -0
- package/dist/bot/watch-daemon.d.ts +19 -0
- package/dist/bot/watch-daemon.d.ts.map +1 -0
- package/dist/bot/watch-daemon.js +178 -0
- package/dist/bot/watch-daemon.js.map +1 -0
- package/dist/bot/web-approval.d.ts +19 -0
- package/dist/bot/web-approval.d.ts.map +1 -0
- package/dist/bot/web-approval.js +207 -0
- package/dist/bot/web-approval.js.map +1 -0
- package/dist/cli-bridge.d.ts +2 -0
- package/dist/cli-bridge.d.ts.map +1 -0
- package/dist/cli-bridge.js +30 -0
- package/dist/cli-bridge.js.map +1 -0
- package/dist/cli-handlers.d.ts +79 -0
- package/dist/cli-handlers.d.ts.map +1 -0
- package/dist/cli-handlers.js +1335 -0
- package/dist/cli-handlers.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +749 -0
- package/dist/cli.js.map +1 -0
- package/dist/docs/docs/weaver-config.md +135 -0
- package/dist/docs/weaver-config.md +141 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-tools.d.ts +13 -0
- package/dist/mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools.js +197 -0
- package/dist/mcp-tools.js.map +1 -0
- package/dist/node-types/abort-task.d.ts +15 -0
- package/dist/node-types/abort-task.d.ts.map +1 -0
- package/dist/node-types/abort-task.js +28 -0
- package/dist/node-types/abort-task.js.map +1 -0
- package/dist/node-types/approval-gate.d.ts +18 -0
- package/dist/node-types/approval-gate.d.ts.map +1 -0
- package/dist/node-types/approval-gate.js +80 -0
- package/dist/node-types/approval-gate.js.map +1 -0
- package/dist/node-types/bot-report.d.ts +20 -0
- package/dist/node-types/bot-report.d.ts.map +1 -0
- package/dist/node-types/bot-report.js +67 -0
- package/dist/node-types/bot-report.js.map +1 -0
- package/dist/node-types/build-context.d.ts +16 -0
- package/dist/node-types/build-context.d.ts.map +1 -0
- package/dist/node-types/build-context.js +64 -0
- package/dist/node-types/build-context.js.map +1 -0
- package/dist/node-types/detect-provider.d.ts +17 -0
- package/dist/node-types/detect-provider.d.ts.map +1 -0
- package/dist/node-types/detect-provider.js +71 -0
- package/dist/node-types/detect-provider.js.map +1 -0
- package/dist/node-types/exec-validate-retry.d.ts +17 -0
- package/dist/node-types/exec-validate-retry.d.ts.map +1 -0
- package/dist/node-types/exec-validate-retry.js +147 -0
- package/dist/node-types/exec-validate-retry.js.map +1 -0
- package/dist/node-types/execute-plan.d.ts +26 -0
- package/dist/node-types/execute-plan.d.ts.map +1 -0
- package/dist/node-types/execute-plan.js +120 -0
- package/dist/node-types/execute-plan.js.map +1 -0
- package/dist/node-types/execute-target.d.ts +16 -0
- package/dist/node-types/execute-target.d.ts.map +1 -0
- package/dist/node-types/execute-target.js +238 -0
- package/dist/node-types/execute-target.js.map +1 -0
- package/dist/node-types/fix-errors.d.ts +24 -0
- package/dist/node-types/fix-errors.d.ts.map +1 -0
- package/dist/node-types/fix-errors.js +49 -0
- package/dist/node-types/fix-errors.js.map +1 -0
- package/dist/node-types/genesis-apply-retry.d.ts +27 -0
- package/dist/node-types/genesis-apply-retry.d.ts.map +1 -0
- package/dist/node-types/genesis-apply-retry.js +97 -0
- package/dist/node-types/genesis-apply-retry.js.map +1 -0
- package/dist/node-types/genesis-apply.d.ts +29 -0
- package/dist/node-types/genesis-apply.d.ts.map +1 -0
- package/dist/node-types/genesis-apply.js +76 -0
- package/dist/node-types/genesis-apply.js.map +1 -0
- package/dist/node-types/genesis-approve.d.ts +19 -0
- package/dist/node-types/genesis-approve.d.ts.map +1 -0
- package/dist/node-types/genesis-approve.js +59 -0
- package/dist/node-types/genesis-approve.js.map +1 -0
- package/dist/node-types/genesis-check-stabilize.d.ts +16 -0
- package/dist/node-types/genesis-check-stabilize.d.ts.map +1 -0
- package/dist/node-types/genesis-check-stabilize.js +32 -0
- package/dist/node-types/genesis-check-stabilize.js.map +1 -0
- package/dist/node-types/genesis-check-threshold.d.ts +15 -0
- package/dist/node-types/genesis-check-threshold.d.ts.map +1 -0
- package/dist/node-types/genesis-check-threshold.js +29 -0
- package/dist/node-types/genesis-check-threshold.js.map +1 -0
- package/dist/node-types/genesis-commit.d.ts +17 -0
- package/dist/node-types/genesis-commit.d.ts.map +1 -0
- package/dist/node-types/genesis-commit.js +59 -0
- package/dist/node-types/genesis-commit.js.map +1 -0
- package/dist/node-types/genesis-compile-validate.d.ts +26 -0
- package/dist/node-types/genesis-compile-validate.d.ts.map +1 -0
- package/dist/node-types/genesis-compile-validate.js +60 -0
- package/dist/node-types/genesis-compile-validate.js.map +1 -0
- package/dist/node-types/genesis-diff-fingerprint.d.ts +15 -0
- package/dist/node-types/genesis-diff-fingerprint.d.ts.map +1 -0
- package/dist/node-types/genesis-diff-fingerprint.js +59 -0
- package/dist/node-types/genesis-diff-fingerprint.js.map +1 -0
- package/dist/node-types/genesis-diff-workflow.d.ts +15 -0
- package/dist/node-types/genesis-diff-workflow.d.ts.map +1 -0
- package/dist/node-types/genesis-diff-workflow.js +67 -0
- package/dist/node-types/genesis-diff-workflow.js.map +1 -0
- package/dist/node-types/genesis-escrow-grace.d.ts +15 -0
- package/dist/node-types/genesis-escrow-grace.d.ts.map +1 -0
- package/dist/node-types/genesis-escrow-grace.js +52 -0
- package/dist/node-types/genesis-escrow-grace.js.map +1 -0
- package/dist/node-types/genesis-escrow-migrate.d.ts +21 -0
- package/dist/node-types/genesis-escrow-migrate.d.ts.map +1 -0
- package/dist/node-types/genesis-escrow-migrate.js +116 -0
- package/dist/node-types/genesis-escrow-migrate.js.map +1 -0
- package/dist/node-types/genesis-escrow-recover.d.ts +15 -0
- package/dist/node-types/genesis-escrow-recover.d.ts.map +1 -0
- package/dist/node-types/genesis-escrow-recover.js +90 -0
- package/dist/node-types/genesis-escrow-recover.js.map +1 -0
- package/dist/node-types/genesis-escrow-stage.d.ts +17 -0
- package/dist/node-types/genesis-escrow-stage.d.ts.map +1 -0
- package/dist/node-types/genesis-escrow-stage.js +86 -0
- package/dist/node-types/genesis-escrow-stage.js.map +1 -0
- package/dist/node-types/genesis-escrow-validate.d.ts +17 -0
- package/dist/node-types/genesis-escrow-validate.d.ts.map +1 -0
- package/dist/node-types/genesis-escrow-validate.js +110 -0
- package/dist/node-types/genesis-escrow-validate.js.map +1 -0
- package/dist/node-types/genesis-load-config.d.ts +17 -0
- package/dist/node-types/genesis-load-config.d.ts.map +1 -0
- package/dist/node-types/genesis-load-config.js +36 -0
- package/dist/node-types/genesis-load-config.js.map +1 -0
- package/dist/node-types/genesis-observe.d.ts +18 -0
- package/dist/node-types/genesis-observe.d.ts.map +1 -0
- package/dist/node-types/genesis-observe.js +103 -0
- package/dist/node-types/genesis-observe.js.map +1 -0
- package/dist/node-types/genesis-propose.d.ts +17 -0
- package/dist/node-types/genesis-propose.d.ts.map +1 -0
- package/dist/node-types/genesis-propose.js +69 -0
- package/dist/node-types/genesis-propose.js.map +1 -0
- package/dist/node-types/genesis-report.d.ts +20 -0
- package/dist/node-types/genesis-report.d.ts.map +1 -0
- package/dist/node-types/genesis-report.js +87 -0
- package/dist/node-types/genesis-report.js.map +1 -0
- package/dist/node-types/genesis-snapshot.d.ts +15 -0
- package/dist/node-types/genesis-snapshot.d.ts.map +1 -0
- package/dist/node-types/genesis-snapshot.js +26 -0
- package/dist/node-types/genesis-snapshot.js.map +1 -0
- package/dist/node-types/genesis-try-apply.d.ts +18 -0
- package/dist/node-types/genesis-try-apply.d.ts.map +1 -0
- package/dist/node-types/genesis-try-apply.js +142 -0
- package/dist/node-types/genesis-try-apply.js.map +1 -0
- package/dist/node-types/genesis-update-history.d.ts +15 -0
- package/dist/node-types/genesis-update-history.d.ts.map +1 -0
- package/dist/node-types/genesis-update-history.js +70 -0
- package/dist/node-types/genesis-update-history.js.map +1 -0
- package/dist/node-types/genesis-validate-proposal.d.ts +16 -0
- package/dist/node-types/genesis-validate-proposal.d.ts.map +1 -0
- package/dist/node-types/genesis-validate-proposal.js +109 -0
- package/dist/node-types/genesis-validate-proposal.js.map +1 -0
- package/dist/node-types/git-ops.d.ts +15 -0
- package/dist/node-types/git-ops.d.ts.map +1 -0
- package/dist/node-types/git-ops.js +69 -0
- package/dist/node-types/git-ops.js.map +1 -0
- package/dist/node-types/index.d.ts +37 -0
- package/dist/node-types/index.d.ts.map +1 -0
- package/dist/node-types/index.js +37 -0
- package/dist/node-types/index.js.map +1 -0
- package/dist/node-types/load-config.d.ts +17 -0
- package/dist/node-types/load-config.d.ts.map +1 -0
- package/dist/node-types/load-config.js +27 -0
- package/dist/node-types/load-config.js.map +1 -0
- package/dist/node-types/plan-task.d.ts +17 -0
- package/dist/node-types/plan-task.d.ts.map +1 -0
- package/dist/node-types/plan-task.js +55 -0
- package/dist/node-types/plan-task.js.map +1 -0
- package/dist/node-types/read-workflow.d.ts +15 -0
- package/dist/node-types/read-workflow.d.ts.map +1 -0
- package/dist/node-types/read-workflow.js +60 -0
- package/dist/node-types/read-workflow.js.map +1 -0
- package/dist/node-types/receive-task.d.ts +20 -0
- package/dist/node-types/receive-task.d.ts.map +1 -0
- package/dist/node-types/receive-task.js +69 -0
- package/dist/node-types/receive-task.js.map +1 -0
- package/dist/node-types/report.d.ts +14 -0
- package/dist/node-types/report.d.ts.map +1 -0
- package/dist/node-types/report.js +25 -0
- package/dist/node-types/report.js.map +1 -0
- package/dist/node-types/resolve-target.d.ts +16 -0
- package/dist/node-types/resolve-target.d.ts.map +1 -0
- package/dist/node-types/resolve-target.js +67 -0
- package/dist/node-types/resolve-target.js.map +1 -0
- package/dist/node-types/route-task.d.ts +14 -0
- package/dist/node-types/route-task.d.ts.map +1 -0
- package/dist/node-types/route-task.js +22 -0
- package/dist/node-types/route-task.js.map +1 -0
- package/dist/node-types/send-notify.d.ts +14 -0
- package/dist/node-types/send-notify.d.ts.map +1 -0
- package/dist/node-types/send-notify.js +71 -0
- package/dist/node-types/send-notify.js.map +1 -0
- package/dist/node-types/validate-result.d.ts +24 -0
- package/dist/node-types/validate-result.d.ts.map +1 -0
- package/dist/node-types/validate-result.js +38 -0
- package/dist/node-types/validate-result.js.map +1 -0
- package/dist/templates/index.d.ts +5 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +4 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/weaver-bot-template.d.ts +11 -0
- package/dist/templates/weaver-bot-template.d.ts.map +1 -0
- package/dist/templates/weaver-bot-template.js +99 -0
- package/dist/templates/weaver-bot-template.js.map +1 -0
- package/dist/templates/weaver-template.d.ts +11 -0
- package/dist/templates/weaver-template.d.ts.map +1 -0
- package/dist/templates/weaver-template.js +53 -0
- package/dist/templates/weaver-template.js.map +1 -0
- package/dist/workflows/genesis-task.d.ts +62 -0
- package/dist/workflows/genesis-task.d.ts.map +1 -0
- package/dist/workflows/genesis-task.js +64 -0
- package/dist/workflows/genesis-task.js.map +1 -0
- package/dist/workflows/index.d.ts +4 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +4 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/weaver-bot-batch.d.ts +49 -0
- package/dist/workflows/weaver-bot-batch.d.ts.map +1 -0
- package/dist/workflows/weaver-bot-batch.js +49 -0
- package/dist/workflows/weaver-bot-batch.js.map +1 -0
- package/dist/workflows/weaver-bot-session.d.ts +65 -0
- package/dist/workflows/weaver-bot-session.d.ts.map +1 -0
- package/dist/workflows/weaver-bot-session.js +68 -0
- package/dist/workflows/weaver-bot-session.js.map +1 -0
- package/dist/workflows/weaver-bot.d.ts +61 -0
- package/dist/workflows/weaver-bot.d.ts.map +1 -0
- package/dist/workflows/weaver-bot.js +61 -0
- package/dist/workflows/weaver-bot.js.map +1 -0
- package/dist/workflows/weaver.d.ts +24 -0
- package/dist/workflows/weaver.d.ts.map +1 -0
- package/dist/workflows/weaver.js +28 -0
- package/dist/workflows/weaver.js.map +1 -0
- package/flowweaver.manifest.json +1001 -0
- package/package.json +78 -0
- package/src/bot/agent-provider.ts +273 -0
- package/src/bot/ai-client.ts +153 -0
- package/src/bot/approvals.ts +273 -0
- package/src/bot/audit-logger.ts +45 -0
- package/src/bot/audit-store.ts +69 -0
- package/src/bot/bot-agent-channel.ts +99 -0
- package/src/bot/cli-provider.ts +169 -0
- package/src/bot/cli-stream-parser.ts +59 -0
- package/src/bot/cost-store.ts +92 -0
- package/src/bot/cost-tracker.ts +72 -0
- package/src/bot/cron-parser.ts +153 -0
- package/src/bot/cron-scheduler.ts +48 -0
- package/src/bot/dashboard.ts +658 -0
- package/src/bot/design-checker.ts +327 -0
- package/src/bot/file-lock.ts +73 -0
- package/src/bot/file-validator.ts +41 -0
- package/src/bot/file-watcher.ts +103 -0
- package/src/bot/fw-api.ts +18 -0
- package/src/bot/genesis-prompt-context.ts +135 -0
- package/src/bot/genesis-store.ts +180 -0
- package/src/bot/index.ts +127 -0
- package/src/bot/notifications.ts +263 -0
- package/src/bot/pipeline-runner.ts +324 -0
- package/src/bot/provider-registry.ts +236 -0
- package/src/bot/run-store.ts +169 -0
- package/src/bot/runner.ts +311 -0
- package/src/bot/session-state.ts +73 -0
- package/src/bot/steering.ts +44 -0
- package/src/bot/step-executor.ts +34 -0
- package/src/bot/system-prompt.ts +280 -0
- package/src/bot/task-queue.ts +111 -0
- package/src/bot/types.ts +571 -0
- package/src/bot/utils.ts +17 -0
- package/src/bot/watch-daemon.ts +203 -0
- package/src/bot/web-approval.ts +240 -0
- package/src/cli-bridge.ts +41 -0
- package/src/cli-handlers.ts +1445 -0
- package/src/docs/weaver-config.md +135 -0
- package/src/index.ts +177 -0
- package/src/mcp-tools.ts +274 -0
- package/src/node-types/abort-task.ts +31 -0
- package/src/node-types/approval-gate.ts +95 -0
- package/src/node-types/bot-report.ts +82 -0
- package/src/node-types/build-context.ts +65 -0
- package/src/node-types/detect-provider.ts +77 -0
- package/src/node-types/exec-validate-retry.ts +170 -0
- package/src/node-types/execute-plan.ts +130 -0
- package/src/node-types/execute-target.ts +256 -0
- package/src/node-types/fix-errors.ts +63 -0
- package/src/node-types/genesis-apply-retry.ts +133 -0
- package/src/node-types/genesis-apply.ts +96 -0
- package/src/node-types/genesis-approve.ts +73 -0
- package/src/node-types/genesis-check-stabilize.ts +37 -0
- package/src/node-types/genesis-check-threshold.ts +34 -0
- package/src/node-types/genesis-commit.ts +71 -0
- package/src/node-types/genesis-compile-validate.ts +77 -0
- package/src/node-types/genesis-diff-fingerprint.ts +67 -0
- package/src/node-types/genesis-diff-workflow.ts +71 -0
- package/src/node-types/genesis-escrow-grace.ts +62 -0
- package/src/node-types/genesis-escrow-migrate.ts +138 -0
- package/src/node-types/genesis-escrow-recover.ts +99 -0
- package/src/node-types/genesis-escrow-stage.ts +104 -0
- package/src/node-types/genesis-escrow-validate.ts +120 -0
- package/src/node-types/genesis-load-config.ts +44 -0
- package/src/node-types/genesis-observe.ts +119 -0
- package/src/node-types/genesis-propose.ts +86 -0
- package/src/node-types/genesis-report.ts +95 -0
- package/src/node-types/genesis-snapshot.ts +30 -0
- package/src/node-types/genesis-try-apply.ts +165 -0
- package/src/node-types/genesis-update-history.ts +72 -0
- package/src/node-types/genesis-validate-proposal.ts +124 -0
- package/src/node-types/git-ops.ts +72 -0
- package/src/node-types/index.ts +36 -0
- package/src/node-types/load-config.ts +27 -0
- package/src/node-types/plan-task.ts +66 -0
- package/src/node-types/read-workflow.ts +68 -0
- package/src/node-types/receive-task.ts +92 -0
- package/src/node-types/report.ts +25 -0
- package/src/node-types/resolve-target.ts +64 -0
- package/src/node-types/route-task.ts +25 -0
- package/src/node-types/send-notify.ts +75 -0
- package/src/node-types/validate-result.ts +49 -0
- package/src/templates/index.ts +5 -0
- package/src/templates/weaver-bot-template.ts +106 -0
- package/src/workflows/genesis-task.ts +91 -0
- package/src/workflows/index.ts +3 -0
- package/src/workflows/weaver-bot-batch.ts +65 -0
- package/src/workflows/weaver-bot.ts +79 -0
- package/templates.js +1 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GenesisConfig, GenesisProposal, GenesisImpactLevel, GenesisContext } from '../bot/types.js';
|
|
2
|
+
|
|
3
|
+
const IMPACT_ORDER: Record<GenesisImpactLevel, number> = {
|
|
4
|
+
COSMETIC: 0,
|
|
5
|
+
MINOR: 1,
|
|
6
|
+
BREAKING: 2,
|
|
7
|
+
CRITICAL: 3,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Compares the proposal's impact level against the configured approval
|
|
12
|
+
* threshold to decide if human approval is required.
|
|
13
|
+
*
|
|
14
|
+
* @flowWeaver nodeType
|
|
15
|
+
* @expression
|
|
16
|
+
* @label Genesis Check Threshold
|
|
17
|
+
* @input ctx [order:0] - Genesis context (JSON)
|
|
18
|
+
* @output ctx [order:0] - Genesis context with approvalRequired (JSON)
|
|
19
|
+
* @output onFailure [hidden]
|
|
20
|
+
*/
|
|
21
|
+
export function genesisCheckThreshold(ctx: string): { ctx: string } {
|
|
22
|
+
const context = JSON.parse(ctx) as GenesisContext;
|
|
23
|
+
const config = JSON.parse(context.genesisConfigJson) as GenesisConfig;
|
|
24
|
+
const proposal = JSON.parse(context.proposalJson!) as GenesisProposal;
|
|
25
|
+
|
|
26
|
+
const proposalLevel = IMPACT_ORDER[proposal.impactLevel] ?? 0;
|
|
27
|
+
const thresholdLevel = IMPACT_ORDER[config.approvalThreshold] ?? 0;
|
|
28
|
+
const approvalRequired = proposalLevel >= thresholdLevel;
|
|
29
|
+
|
|
30
|
+
console.log(`\x1b[36m→ Impact ${proposal.impactLevel} vs threshold ${config.approvalThreshold}: approval ${approvalRequired ? 'required' : 'not required'}\x1b[0m`);
|
|
31
|
+
|
|
32
|
+
context.approvalRequired = approvalRequired;
|
|
33
|
+
return { ctx: JSON.stringify(context) };
|
|
34
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import type { GenesisConfig, GenesisContext } from '../bot/types.js';
|
|
5
|
+
import { GenesisStore } from '../bot/genesis-store.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Commits the modified workflow to git if approved, or restores from
|
|
9
|
+
* the snapshot if rejected. Commit messages are prefixed with "genesis:".
|
|
10
|
+
*
|
|
11
|
+
* @flowWeaver nodeType
|
|
12
|
+
* @label Genesis Commit
|
|
13
|
+
* @input ctx [order:0] - Genesis context (JSON)
|
|
14
|
+
* @output ctx [order:0] - Genesis context with commitResultJson (JSON)
|
|
15
|
+
* @output onSuccess [order:-2] - On Success
|
|
16
|
+
* @output onFailure [order:-1] [hidden] - On Failure
|
|
17
|
+
*/
|
|
18
|
+
export async function genesisCommit(
|
|
19
|
+
execute: boolean,
|
|
20
|
+
ctx: string,
|
|
21
|
+
): Promise<{
|
|
22
|
+
onSuccess: boolean; onFailure: boolean;
|
|
23
|
+
ctx: string;
|
|
24
|
+
}> {
|
|
25
|
+
const context = JSON.parse(ctx) as GenesisContext;
|
|
26
|
+
|
|
27
|
+
if (!execute) {
|
|
28
|
+
context.commitResultJson = JSON.stringify({ committed: false, reason: 'dry run' });
|
|
29
|
+
return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { env } = context;
|
|
33
|
+
const config = JSON.parse(context.genesisConfigJson) as GenesisConfig;
|
|
34
|
+
const targetPath = path.resolve(env.projectDir, config.targetWorkflow);
|
|
35
|
+
|
|
36
|
+
if (!context.approved) {
|
|
37
|
+
// Restore from snapshot
|
|
38
|
+
const store = new GenesisStore(env.projectDir);
|
|
39
|
+
const snapshot = store.loadSnapshot(context.snapshotPath!);
|
|
40
|
+
if (snapshot) {
|
|
41
|
+
fs.writeFileSync(targetPath, snapshot, 'utf-8');
|
|
42
|
+
console.log('\x1b[33m→ Restored from snapshot (not approved)\x1b[0m');
|
|
43
|
+
}
|
|
44
|
+
context.commitResultJson = JSON.stringify({ committed: false, reason: 'not approved' });
|
|
45
|
+
return { onSuccess: false, onFailure: true, ctx: JSON.stringify(context) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
execFileSync('git', ['add', targetPath], {
|
|
50
|
+
cwd: env.projectDir,
|
|
51
|
+
encoding: 'utf-8',
|
|
52
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const message = `genesis: evolve ${path.basename(config.targetWorkflow)}`;
|
|
56
|
+
execFileSync('git', ['commit', '-m', message], {
|
|
57
|
+
cwd: env.projectDir,
|
|
58
|
+
encoding: 'utf-8',
|
|
59
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
console.log(`\x1b[32m→ Committed: ${message}\x1b[0m`);
|
|
63
|
+
context.commitResultJson = JSON.stringify({ committed: true, message });
|
|
64
|
+
return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
|
|
65
|
+
} catch (err: unknown) {
|
|
66
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
67
|
+
console.error(`\x1b[31m→ Commit failed: ${msg}\x1b[0m`);
|
|
68
|
+
context.commitResultJson = JSON.stringify({ committed: false, reason: msg });
|
|
69
|
+
return { onSuccess: false, onFailure: true, ctx: JSON.stringify(context) };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import type { WeaverEnv, GenesisConfig } from '../bot/types.js';
|
|
5
|
+
import { GenesisStore } from '../bot/genesis-store.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Runs flow-weaver validate and compile on the target workflow after
|
|
9
|
+
* operations have been applied. On failure, restores from the snapshot
|
|
10
|
+
* and fires the failure path.
|
|
11
|
+
*
|
|
12
|
+
* @flowWeaver nodeType
|
|
13
|
+
* @label Genesis Compile & Validate
|
|
14
|
+
* @input env [order:0] - Weaver environment bundle
|
|
15
|
+
* @input genesisConfigJson [order:1] - Genesis configuration (JSON)
|
|
16
|
+
* @input snapshotPath [order:2] - Path to the pre-apply snapshot
|
|
17
|
+
* @input applyResultJson [order:3] - Apply result (JSON)
|
|
18
|
+
* @output env [order:0] - Weaver environment bundle (pass-through)
|
|
19
|
+
* @output genesisConfigJson [order:1] - Genesis configuration (pass-through)
|
|
20
|
+
* @output snapshotPath [order:2] - Path to the snapshot (pass-through)
|
|
21
|
+
* @output onSuccess [order:-2] - On Success
|
|
22
|
+
* @output onFailure [order:-1] - On Failure
|
|
23
|
+
*/
|
|
24
|
+
export async function genesisCompileValidate(
|
|
25
|
+
execute: boolean,
|
|
26
|
+
env: WeaverEnv,
|
|
27
|
+
genesisConfigJson: string,
|
|
28
|
+
snapshotPath: string,
|
|
29
|
+
applyResultJson: string,
|
|
30
|
+
): Promise<{
|
|
31
|
+
onSuccess: boolean; onFailure: boolean;
|
|
32
|
+
env: WeaverEnv;
|
|
33
|
+
genesisConfigJson: string;
|
|
34
|
+
snapshotPath: string;
|
|
35
|
+
}> {
|
|
36
|
+
if (!execute) {
|
|
37
|
+
return { onSuccess: true, onFailure: false, env, genesisConfigJson, snapshotPath };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const config = JSON.parse(genesisConfigJson) as GenesisConfig;
|
|
41
|
+
const targetPath = path.resolve(env.projectDir, config.targetWorkflow);
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
// Validate
|
|
45
|
+
execFileSync('flow-weaver', ['validate', targetPath], {
|
|
46
|
+
cwd: env.projectDir,
|
|
47
|
+
encoding: 'utf-8',
|
|
48
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
49
|
+
timeout: 30_000,
|
|
50
|
+
});
|
|
51
|
+
console.log('\x1b[32m→ Validation passed\x1b[0m');
|
|
52
|
+
|
|
53
|
+
// Compile
|
|
54
|
+
execFileSync('flow-weaver', ['compile', targetPath], {
|
|
55
|
+
cwd: env.projectDir,
|
|
56
|
+
encoding: 'utf-8',
|
|
57
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
58
|
+
timeout: 60_000,
|
|
59
|
+
});
|
|
60
|
+
console.log('\x1b[32m→ Compilation passed\x1b[0m');
|
|
61
|
+
|
|
62
|
+
return { onSuccess: true, onFailure: false, env, genesisConfigJson, snapshotPath };
|
|
63
|
+
} catch (err: unknown) {
|
|
64
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
65
|
+
console.error(`\x1b[31m→ Compile/validate failed: ${msg}\x1b[0m`);
|
|
66
|
+
|
|
67
|
+
// Restore from snapshot
|
|
68
|
+
const store = new GenesisStore(env.projectDir);
|
|
69
|
+
const snapshot = store.loadSnapshot(snapshotPath);
|
|
70
|
+
if (snapshot) {
|
|
71
|
+
fs.writeFileSync(targetPath, snapshot, 'utf-8');
|
|
72
|
+
console.log('\x1b[33m→ Restored from snapshot\x1b[0m');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { onSuccess: false, onFailure: true, env, genesisConfigJson, snapshotPath };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { GenesisFingerprint, GenesisContext } from '../bot/types.js';
|
|
2
|
+
import { GenesisStore } from '../bot/genesis-store.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compares the current project fingerprint against the last saved one,
|
|
6
|
+
* producing a diff summary of file and state changes.
|
|
7
|
+
*
|
|
8
|
+
* @flowWeaver nodeType
|
|
9
|
+
* @expression
|
|
10
|
+
* @label Genesis Diff Fingerprint
|
|
11
|
+
* @input ctx [order:0] - Genesis context (JSON)
|
|
12
|
+
* @output ctx [order:0] - Genesis context with diffJson (JSON)
|
|
13
|
+
* @output onFailure [hidden]
|
|
14
|
+
*/
|
|
15
|
+
export function genesisDiffFingerprint(ctx: string): { ctx: string } {
|
|
16
|
+
const context = JSON.parse(ctx) as GenesisContext;
|
|
17
|
+
const { env } = context;
|
|
18
|
+
const store = new GenesisStore(env.projectDir);
|
|
19
|
+
const current = JSON.parse(context.fingerprintJson!) as GenesisFingerprint;
|
|
20
|
+
const last = store.getLastFingerprint();
|
|
21
|
+
|
|
22
|
+
const addedFiles: string[] = [];
|
|
23
|
+
const removedFiles: string[] = [];
|
|
24
|
+
const modifiedFiles: string[] = [];
|
|
25
|
+
let gitChanged = false;
|
|
26
|
+
let workflowsChanged = false;
|
|
27
|
+
|
|
28
|
+
if (!last) {
|
|
29
|
+
const diff = {
|
|
30
|
+
addedFiles: Object.keys(current.files),
|
|
31
|
+
removedFiles: [],
|
|
32
|
+
modifiedFiles: [],
|
|
33
|
+
gitChanged: true,
|
|
34
|
+
workflowsChanged: true,
|
|
35
|
+
};
|
|
36
|
+
context.diffJson = JSON.stringify(diff);
|
|
37
|
+
return { ctx: JSON.stringify(context) };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const [file, hash] of Object.entries(current.files)) {
|
|
41
|
+
if (!(file in last.files)) {
|
|
42
|
+
addedFiles.push(file);
|
|
43
|
+
} else if (last.files[file] !== hash) {
|
|
44
|
+
modifiedFiles.push(file);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const file of Object.keys(last.files)) {
|
|
48
|
+
if (!(file in current.files)) {
|
|
49
|
+
removedFiles.push(file);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
gitChanged = current.gitBranch !== last.gitBranch || current.gitCommit !== last.gitCommit;
|
|
54
|
+
|
|
55
|
+
const currentWfs = [...current.existingWorkflows].sort().join(',');
|
|
56
|
+
const lastWfs = [...last.existingWorkflows].sort().join(',');
|
|
57
|
+
workflowsChanged = currentWfs !== lastWfs || current.workflowHash !== last.workflowHash;
|
|
58
|
+
|
|
59
|
+
const diff = { addedFiles, removedFiles, modifiedFiles, gitChanged, workflowsChanged };
|
|
60
|
+
const hasChanges = addedFiles.length > 0 || removedFiles.length > 0 ||
|
|
61
|
+
modifiedFiles.length > 0 || gitChanged || workflowsChanged;
|
|
62
|
+
|
|
63
|
+
console.log(`\x1b[36m→ Diff: +${addedFiles.length} -${removedFiles.length} ~${modifiedFiles.length}, git=${gitChanged}, wf=${workflowsChanged}\x1b[0m`);
|
|
64
|
+
|
|
65
|
+
context.diffJson = JSON.stringify(diff);
|
|
66
|
+
return { ctx: JSON.stringify(context) };
|
|
67
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import type { GenesisConfig, GenesisContext } from '../bot/types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Runs flow-weaver diff between the snapshot and the current target
|
|
8
|
+
* workflow to produce a human-readable diff of workflow changes.
|
|
9
|
+
*
|
|
10
|
+
* @flowWeaver nodeType
|
|
11
|
+
* @expression
|
|
12
|
+
* @label Genesis Diff Workflow
|
|
13
|
+
* @input ctx [order:0] - Genesis context (JSON)
|
|
14
|
+
* @output ctx [order:0] - Genesis context with workflowDiffJson (JSON)
|
|
15
|
+
* @output onFailure [hidden]
|
|
16
|
+
*/
|
|
17
|
+
export function genesisDiffWorkflow(ctx: string): { ctx: string } {
|
|
18
|
+
const context = JSON.parse(ctx) as GenesisContext;
|
|
19
|
+
const config = JSON.parse(context.genesisConfigJson) as GenesisConfig;
|
|
20
|
+
const targetPath = path.resolve(context.env.projectDir, config.targetWorkflow);
|
|
21
|
+
|
|
22
|
+
let diffOutput = '';
|
|
23
|
+
|
|
24
|
+
// Try semantic diff via flow-weaver first
|
|
25
|
+
try {
|
|
26
|
+
diffOutput = execFileSync('flow-weaver', ['diff', context.snapshotPath!, targetPath], {
|
|
27
|
+
cwd: context.env.projectDir,
|
|
28
|
+
encoding: 'utf-8',
|
|
29
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
30
|
+
timeout: 30_000,
|
|
31
|
+
}).trim();
|
|
32
|
+
} catch (err: unknown) {
|
|
33
|
+
if (err && typeof err === 'object' && 'stdout' in err) {
|
|
34
|
+
diffOutput = String((err as { stdout: string }).stdout).trim();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Fallback to basic text diff if semantic diff failed
|
|
39
|
+
if (!diffOutput && context.snapshotPath) {
|
|
40
|
+
try {
|
|
41
|
+
const snapshotContent = fs.readFileSync(context.snapshotPath, 'utf-8');
|
|
42
|
+
const currentContent = fs.readFileSync(targetPath, 'utf-8');
|
|
43
|
+
|
|
44
|
+
if (snapshotContent === currentContent) {
|
|
45
|
+
diffOutput = '(no changes)';
|
|
46
|
+
} else {
|
|
47
|
+
diffOutput = execFileSync('git', ['diff', '--no-index', '--no-color', context.snapshotPath, targetPath], {
|
|
48
|
+
cwd: context.env.projectDir,
|
|
49
|
+
encoding: 'utf-8',
|
|
50
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
51
|
+
timeout: 10_000,
|
|
52
|
+
}).trim();
|
|
53
|
+
}
|
|
54
|
+
} catch (err: unknown) {
|
|
55
|
+
// git diff exits 1 when files differ (that's normal)
|
|
56
|
+
if (err && typeof err === 'object' && 'stdout' in err) {
|
|
57
|
+
const stdout = String((err as { stdout: string }).stdout).trim();
|
|
58
|
+
if (stdout) diffOutput = stdout;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!diffOutput) {
|
|
64
|
+
diffOutput = '(diff unavailable)';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(`\x1b[36m→ Workflow diff: ${diffOutput.split('\n').length} lines\x1b[0m`);
|
|
68
|
+
|
|
69
|
+
context.workflowDiffJson = JSON.stringify({ diff: diffOutput });
|
|
70
|
+
return { ctx: JSON.stringify(context) };
|
|
71
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import type { GenesisContext, GenesisConfig } from '../bot/types.js';
|
|
3
|
+
import { GenesisStore } from '../bot/genesis-store.js';
|
|
4
|
+
import { rollbackFromBackup } from './genesis-escrow-migrate.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Handles escrow grace period tracking at the end of each cycle.
|
|
8
|
+
* Decrements grace on success, triggers rollback on failure, and
|
|
9
|
+
* clears escrow once the grace period completes.
|
|
10
|
+
*
|
|
11
|
+
* @flowWeaver nodeType
|
|
12
|
+
* @expression
|
|
13
|
+
* @label Genesis Escrow Grace
|
|
14
|
+
* @input ctx [order:0] - Genesis context (JSON)
|
|
15
|
+
* @output ctx [order:0] - Genesis context (JSON)
|
|
16
|
+
*/
|
|
17
|
+
export function genesisEscrowGrace(ctx: string): { ctx: string } {
|
|
18
|
+
const context = JSON.parse(ctx) as GenesisContext;
|
|
19
|
+
const { env } = context;
|
|
20
|
+
const config = JSON.parse(context.genesisConfigJson) as GenesisConfig;
|
|
21
|
+
|
|
22
|
+
if (!config.selfEvolve) {
|
|
23
|
+
return { ctx: JSON.stringify(context) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const store = new GenesisStore(env.projectDir);
|
|
27
|
+
const token = store.loadEscrowToken();
|
|
28
|
+
|
|
29
|
+
if (!token || token.phase !== 'migrated' || token.graceRemaining <= 0) {
|
|
30
|
+
return { ctx: JSON.stringify(context) };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const packRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..', '..');
|
|
34
|
+
|
|
35
|
+
// Cycle failed during grace: rollback
|
|
36
|
+
if (context.error) {
|
|
37
|
+
rollbackFromBackup(store, token, packRoot, `Grace cycle failed: ${context.error}`);
|
|
38
|
+
return { ctx: JSON.stringify(context) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Cycle succeeded: decrement grace
|
|
42
|
+
token.graceRemaining--;
|
|
43
|
+
token.graceCycleIds.push(context.cycleId);
|
|
44
|
+
store.saveEscrowToken(token);
|
|
45
|
+
|
|
46
|
+
console.log(`\x1b[36m→ Grace period: ${token.graceRemaining} cycle(s) remaining\x1b[0m`);
|
|
47
|
+
|
|
48
|
+
if (token.graceRemaining <= 0) {
|
|
49
|
+
store.appendSelfMigration({
|
|
50
|
+
migrationId: token.migrationId,
|
|
51
|
+
cycleId: token.cycleId,
|
|
52
|
+
timestamp: new Date().toISOString(),
|
|
53
|
+
affectedFiles: token.affectedFiles,
|
|
54
|
+
outcome: 'grace-cleared',
|
|
55
|
+
graceCompleted: true,
|
|
56
|
+
});
|
|
57
|
+
store.clearEscrow();
|
|
58
|
+
console.log('\x1b[32m→ Grace period complete, self-modification accepted\x1b[0m');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { ctx: JSON.stringify(context) };
|
|
62
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import type { GenesisContext, EscrowToken } from '../bot/types.js';
|
|
4
|
+
import { GenesisStore } from '../bot/genesis-store.js';
|
|
5
|
+
import { withFileLock } from '../bot/file-lock.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Copies staged files to their actual pack locations, completing the
|
|
9
|
+
* self-modification migration. Uses a file lock to prevent concurrent access.
|
|
10
|
+
*
|
|
11
|
+
* @flowWeaver nodeType
|
|
12
|
+
* @label Genesis Escrow Migrate
|
|
13
|
+
* @input ctx [order:0] - Genesis context (JSON)
|
|
14
|
+
* @output ctx [order:0] - Genesis context with migration result (JSON)
|
|
15
|
+
* @output onSuccess [order:-2] - On Success
|
|
16
|
+
* @output onFailure [order:-1] [hidden] - On Failure
|
|
17
|
+
*/
|
|
18
|
+
export async function genesisEscrowMigrate(
|
|
19
|
+
execute: boolean,
|
|
20
|
+
ctx: string,
|
|
21
|
+
): Promise<{
|
|
22
|
+
onSuccess: boolean; onFailure: boolean;
|
|
23
|
+
ctx: string;
|
|
24
|
+
}> {
|
|
25
|
+
const context = JSON.parse(ctx) as GenesisContext;
|
|
26
|
+
const { env } = context;
|
|
27
|
+
const store = new GenesisStore(env.projectDir);
|
|
28
|
+
const token = store.loadEscrowToken();
|
|
29
|
+
|
|
30
|
+
if (!execute) {
|
|
31
|
+
context.escrowResultJson = JSON.stringify({ migrated: false, reason: 'dry run' });
|
|
32
|
+
return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!token || token.phase !== 'validated') {
|
|
36
|
+
// No validated escrow: pass through (not an error, just nothing to migrate)
|
|
37
|
+
return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const packRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..', '..');
|
|
41
|
+
const lockPath = path.join(env.projectDir, '.genesis', 'escrow', 'migrate');
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await withFileLock(lockPath, () => {
|
|
45
|
+
// Re-read token inside lock to confirm state
|
|
46
|
+
const lockedToken = store.loadEscrowToken();
|
|
47
|
+
if (!lockedToken || lockedToken.phase !== 'validated') {
|
|
48
|
+
throw new Error('Token state changed during lock acquisition');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
lockedToken.phase = 'migrating';
|
|
52
|
+
store.saveEscrowToken(lockedToken);
|
|
53
|
+
|
|
54
|
+
// Copy each staged file to actual location
|
|
55
|
+
for (const relFile of lockedToken.affectedFiles) {
|
|
56
|
+
const stagedPath = store.getEscrowStagedPath(relFile);
|
|
57
|
+
const destPath = path.resolve(packRoot, relFile);
|
|
58
|
+
|
|
59
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
60
|
+
fs.copyFileSync(stagedPath, destPath);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
lockedToken.phase = 'migrated';
|
|
64
|
+
lockedToken.migratedAt = new Date().toISOString();
|
|
65
|
+
store.saveEscrowToken(lockedToken);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log(`\x1b[32m→ Escrow migration complete: ${token.affectedFiles.length} file(s) swapped\x1b[0m`);
|
|
69
|
+
context.escrowResultJson = JSON.stringify({
|
|
70
|
+
migrated: true,
|
|
71
|
+
migrationId: token.migrationId,
|
|
72
|
+
files: token.affectedFiles,
|
|
73
|
+
});
|
|
74
|
+
return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
|
|
75
|
+
} catch (err: unknown) {
|
|
76
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
77
|
+
console.error(`\x1b[31m→ Escrow migration failed: ${msg}\x1b[0m`);
|
|
78
|
+
|
|
79
|
+
// Attempt rollback
|
|
80
|
+
rollbackFromBackup(store, token, packRoot, `Migration failed: ${msg}`);
|
|
81
|
+
|
|
82
|
+
context.error = `Escrow migration failed: ${msg}`;
|
|
83
|
+
return { onSuccess: false, onFailure: true, ctx: JSON.stringify(context) };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Restore all affected files from backup, or delete newly-created files. */
|
|
88
|
+
export function rollbackFromBackup(
|
|
89
|
+
store: GenesisStore,
|
|
90
|
+
token: EscrowToken,
|
|
91
|
+
packRoot: string,
|
|
92
|
+
reason: string,
|
|
93
|
+
): void {
|
|
94
|
+
for (const relFile of token.affectedFiles) {
|
|
95
|
+
const backupPath = store.getEscrowBackupPath(relFile);
|
|
96
|
+
const destPath = path.resolve(packRoot, relFile);
|
|
97
|
+
|
|
98
|
+
if (fs.existsSync(backupPath)) {
|
|
99
|
+
// Verify backup integrity
|
|
100
|
+
try {
|
|
101
|
+
const actualHash = GenesisStore.hashFile(backupPath);
|
|
102
|
+
const expectedHash = token.backupFileHashes[relFile];
|
|
103
|
+
if (expectedHash && actualHash !== expectedHash) {
|
|
104
|
+
console.error(`\x1b[31m→ Backup integrity check failed for ${relFile}\x1b[0m`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
console.error(`\x1b[31m→ Cannot read backup for ${relFile}\x1b[0m`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
112
|
+
fs.copyFileSync(backupPath, destPath);
|
|
113
|
+
} else if (fs.existsSync(destPath) && !token.backupFileHashes[relFile]) {
|
|
114
|
+
// File was newly created during migration (no backup), remove it
|
|
115
|
+
try { fs.unlinkSync(destPath); } catch { /* ignore */ }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Update token
|
|
120
|
+
const fullToken = store.loadEscrowToken();
|
|
121
|
+
if (fullToken) {
|
|
122
|
+
fullToken.phase = 'rolled-back';
|
|
123
|
+
fullToken.rollbackReason = reason;
|
|
124
|
+
store.saveEscrowToken(fullToken);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
store.appendSelfMigration({
|
|
128
|
+
migrationId: token.migrationId,
|
|
129
|
+
cycleId: token.cycleId,
|
|
130
|
+
timestamp: new Date().toISOString(),
|
|
131
|
+
affectedFiles: token.affectedFiles,
|
|
132
|
+
outcome: 'rolled-back',
|
|
133
|
+
graceCompleted: false,
|
|
134
|
+
rollbackReason: reason,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
console.log(`\x1b[33m→ Rolled back migration ${token.migrationId}: ${reason}\x1b[0m`);
|
|
138
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import type { GenesisContext, GenesisConfig } from '../bot/types.js';
|
|
4
|
+
import { GenesisStore } from '../bot/genesis-store.js';
|
|
5
|
+
import { rollbackFromBackup } from './genesis-escrow-migrate.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Checks for interrupted escrow migrations (crash recovery) and sets
|
|
9
|
+
* grace-period context flags for downstream nodes. Runs early in the
|
|
10
|
+
* workflow so propose and other nodes can see the escrow state.
|
|
11
|
+
*
|
|
12
|
+
* @flowWeaver nodeType
|
|
13
|
+
* @expression
|
|
14
|
+
* @label Genesis Escrow Recover
|
|
15
|
+
* @input ctx [order:0] - Genesis context (JSON)
|
|
16
|
+
* @output ctx [order:0] - Genesis context with escrow state flags (JSON)
|
|
17
|
+
*/
|
|
18
|
+
export function genesisEscrowRecover(ctx: string): { ctx: string } {
|
|
19
|
+
const context = JSON.parse(ctx) as GenesisContext;
|
|
20
|
+
const { env } = context;
|
|
21
|
+
const config = JSON.parse(context.genesisConfigJson) as GenesisConfig;
|
|
22
|
+
|
|
23
|
+
if (!config.selfEvolve) {
|
|
24
|
+
context.escrowGraceLocked = false;
|
|
25
|
+
return { ctx: JSON.stringify(context) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const store = new GenesisStore(env.projectDir);
|
|
29
|
+
|
|
30
|
+
// Check if max failures exceeded (disables self-evolution for this cycle)
|
|
31
|
+
const maxFailures = config.selfEvolveMaxFailures ?? 3;
|
|
32
|
+
const failureCount = store.getSelfFailureCount();
|
|
33
|
+
if (failureCount >= maxFailures) {
|
|
34
|
+
console.log(`\x1b[33m→ Self-evolution disabled: ${failureCount} consecutive failures (max ${maxFailures})\x1b[0m`);
|
|
35
|
+
context.escrowGraceLocked = true;
|
|
36
|
+
context.escrowGraceRemaining = 0;
|
|
37
|
+
return { ctx: JSON.stringify(context) };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const token = store.loadEscrowToken();
|
|
41
|
+
|
|
42
|
+
if (!token) {
|
|
43
|
+
context.escrowGraceLocked = false;
|
|
44
|
+
return { ctx: JSON.stringify(context) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const packRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..', '..');
|
|
48
|
+
|
|
49
|
+
// Crash recovery: process died mid-swap
|
|
50
|
+
if (token.phase === 'migrating') {
|
|
51
|
+
console.log('\x1b[33m→ Detected interrupted migration, checking file integrity...\x1b[0m');
|
|
52
|
+
|
|
53
|
+
let needsRollback = false;
|
|
54
|
+
for (const relFile of token.affectedFiles) {
|
|
55
|
+
const absFile = path.resolve(packRoot, relFile);
|
|
56
|
+
if (!fs.existsSync(absFile)) {
|
|
57
|
+
needsRollback = true;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const currentHash = GenesisStore.hashFile(absFile);
|
|
61
|
+
const stagedHash = token.stagedFileHashes[relFile];
|
|
62
|
+
const backupHash = token.backupFileHashes[relFile];
|
|
63
|
+
if (currentHash !== stagedHash && currentHash !== backupHash) {
|
|
64
|
+
needsRollback = true;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (needsRollback) {
|
|
70
|
+
console.log('\x1b[33m→ Inconsistent state, rolling back...\x1b[0m');
|
|
71
|
+
rollbackFromBackup(store, token, packRoot, 'Crash recovery: inconsistent file state');
|
|
72
|
+
} else {
|
|
73
|
+
// Check if all files match staged (migration was actually complete)
|
|
74
|
+
const allStaged = token.affectedFiles.every(f => {
|
|
75
|
+
const absFile = path.resolve(packRoot, f);
|
|
76
|
+
return fs.existsSync(absFile) && GenesisStore.hashFile(absFile) === token.stagedFileHashes[f];
|
|
77
|
+
});
|
|
78
|
+
if (allStaged) {
|
|
79
|
+
token.phase = 'migrated';
|
|
80
|
+
token.migratedAt = new Date().toISOString();
|
|
81
|
+
store.saveEscrowToken(token);
|
|
82
|
+
console.log('\x1b[32m→ Migration was complete, advancing to grace period\x1b[0m');
|
|
83
|
+
} else {
|
|
84
|
+
rollbackFromBackup(store, token, packRoot, 'Crash recovery: partial migration');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Set grace state for downstream nodes
|
|
90
|
+
const current = store.loadEscrowToken();
|
|
91
|
+
if (current && current.phase === 'migrated' && current.graceRemaining > 0) {
|
|
92
|
+
context.escrowGraceLocked = true;
|
|
93
|
+
context.escrowGraceRemaining = current.graceRemaining;
|
|
94
|
+
} else {
|
|
95
|
+
context.escrowGraceLocked = false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return { ctx: JSON.stringify(context) };
|
|
99
|
+
}
|