opencastle 0.35.3 → 0.36.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/README.md +105 -145
- package/bin/cli.mjs +204 -63
- package/dist/cli/adapters/adapter-contract.test.d.ts +2 -0
- package/dist/cli/adapters/adapter-contract.test.d.ts.map +1 -0
- package/dist/cli/adapters/adapter-contract.test.js +53 -0
- package/dist/cli/adapters/adapter-contract.test.js.map +1 -0
- package/dist/cli/adapters/antigravity.d.ts +1 -1
- package/dist/cli/adapters/antigravity.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.d.ts +1 -1
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/codex.d.ts +1 -1
- package/dist/cli/adapters/codex.d.ts.map +1 -1
- package/dist/cli/adapters/cursor.d.ts +3 -20
- package/dist/cli/adapters/cursor.d.ts.map +1 -1
- package/dist/cli/adapters/cursor.js +27 -256
- package/dist/cli/adapters/cursor.js.map +1 -1
- package/dist/cli/adapters/opencode.d.ts +1 -1
- package/dist/cli/adapters/opencode.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.d.ts +53 -0
- package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -0
- package/dist/cli/adapters/rules-dir-base.js +309 -0
- package/dist/cli/adapters/rules-dir-base.js.map +1 -0
- package/dist/cli/adapters/rules-dir-base.test.d.ts +2 -0
- package/dist/cli/adapters/rules-dir-base.test.d.ts.map +1 -0
- package/dist/cli/adapters/rules-dir-base.test.js +203 -0
- package/dist/cli/adapters/rules-dir-base.test.js.map +1 -0
- package/dist/cli/adapters/single-file-base.d.ts +0 -14
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +250 -64
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +1 -1
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +151 -53
- package/dist/cli/adapters/vscode.js.map +1 -1
- package/dist/cli/adapters/windsurf.d.ts +3 -20
- package/dist/cli/adapters/windsurf.d.ts.map +1 -1
- package/dist/cli/adapters/windsurf.js +33 -264
- package/dist/cli/adapters/windsurf.js.map +1 -1
- package/dist/cli/add.d.ts +3 -0
- package/dist/cli/add.d.ts.map +1 -0
- package/dist/cli/add.js +113 -0
- package/dist/cli/add.js.map +1 -0
- package/dist/cli/agent-roster.test.d.ts +2 -0
- package/dist/cli/agent-roster.test.d.ts.map +1 -0
- package/dist/cli/agent-roster.test.js +192 -0
- package/dist/cli/agent-roster.test.js.map +1 -0
- package/dist/cli/boundary.test.d.ts +2 -0
- package/dist/cli/boundary.test.d.ts.map +1 -0
- package/dist/cli/boundary.test.js +209 -0
- package/dist/cli/boundary.test.js.map +1 -0
- package/dist/cli/convoy/artifacts.d.ts +2 -2
- package/dist/cli/convoy/artifacts.d.ts.map +1 -1
- package/dist/cli/convoy/artifacts.js +4 -4
- package/dist/cli/convoy/artifacts.js.map +1 -1
- package/dist/cli/convoy/built-in-gates.test.d.ts +2 -0
- package/dist/cli/convoy/built-in-gates.test.d.ts.map +1 -0
- package/dist/cli/convoy/built-in-gates.test.js +109 -0
- package/dist/cli/convoy/built-in-gates.test.js.map +1 -0
- package/dist/cli/convoy/contracts.d.ts +7 -0
- package/dist/cli/convoy/contracts.d.ts.map +1 -1
- package/dist/cli/convoy/contracts.js +48 -65
- package/dist/cli/convoy/contracts.js.map +1 -1
- package/dist/cli/convoy/contracts.test.js +44 -21
- package/dist/cli/convoy/contracts.test.js.map +1 -1
- package/dist/cli/convoy/crash-status.test.d.ts +2 -0
- package/dist/cli/convoy/crash-status.test.d.ts.map +1 -0
- package/dist/cli/convoy/crash-status.test.js +215 -0
- package/dist/cli/convoy/crash-status.test.js.map +1 -0
- package/dist/cli/convoy/dag-analysis.d.ts +0 -1
- package/dist/cli/convoy/dag-analysis.d.ts.map +1 -1
- package/dist/cli/convoy/dag-analysis.js +0 -3
- package/dist/cli/convoy/dag-analysis.js.map +1 -1
- package/dist/cli/convoy/engine.d.ts +1 -7
- package/dist/cli/convoy/engine.d.ts.map +1 -1
- package/dist/cli/convoy/engine.js +185 -239
- package/dist/cli/convoy/engine.js.map +1 -1
- package/dist/cli/convoy/engine.test.js +151 -50
- package/dist/cli/convoy/engine.test.js.map +1 -1
- package/dist/cli/convoy/event-schemas.d.ts +0 -4
- package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
- package/dist/cli/convoy/event-schemas.js +1 -1
- package/dist/cli/convoy/event-schemas.js.map +1 -1
- package/dist/cli/convoy/events.test.js.map +1 -1
- package/dist/cli/convoy/formula.d.ts +1 -1
- package/dist/cli/convoy/formula.d.ts.map +1 -1
- package/dist/cli/convoy/formula.test.js.map +1 -1
- package/dist/cli/convoy/gates.d.ts +47 -0
- package/dist/cli/convoy/gates.d.ts.map +1 -1
- package/dist/cli/convoy/gates.js +94 -0
- package/dist/cli/convoy/gates.js.map +1 -1
- package/dist/cli/convoy/health.d.ts +1 -1
- package/dist/cli/convoy/health.d.ts.map +1 -1
- package/dist/cli/convoy/ledger-paths.test.d.ts +2 -0
- package/dist/cli/convoy/ledger-paths.test.d.ts.map +1 -0
- package/dist/cli/convoy/ledger-paths.test.js +118 -0
- package/dist/cli/convoy/ledger-paths.test.js.map +1 -0
- package/dist/cli/convoy/lock.d.ts +0 -1
- package/dist/cli/convoy/lock.d.ts.map +1 -1
- package/dist/cli/convoy/lock.js +0 -3
- package/dist/cli/convoy/lock.js.map +1 -1
- package/dist/cli/convoy/lock.test.js.map +1 -1
- package/dist/cli/convoy/no-op-gate.test.d.ts +2 -0
- package/dist/cli/convoy/no-op-gate.test.d.ts.map +1 -0
- package/dist/cli/convoy/no-op-gate.test.js +135 -0
- package/dist/cli/convoy/no-op-gate.test.js.map +1 -0
- package/dist/cli/convoy/partition.d.ts +1 -1
- package/dist/cli/convoy/partition.d.ts.map +1 -1
- package/dist/cli/convoy/pipeline.d.ts +1 -1
- package/dist/cli/convoy/pipeline.d.ts.map +1 -1
- package/dist/cli/convoy/pipeline.js +1 -1
- package/dist/cli/convoy/pipeline.js.map +1 -1
- package/dist/cli/convoy/spec-builder.d.ts +0 -5
- package/dist/cli/convoy/spec-builder.d.ts.map +1 -1
- package/dist/cli/convoy/spec-builder.js +1 -4
- package/dist/cli/convoy/spec-builder.js.map +1 -1
- package/dist/cli/convoy/spec-builder.test.js +0 -3
- package/dist/cli/convoy/spec-builder.test.js.map +1 -1
- package/dist/cli/convoy/spec-types.d.ts +250 -0
- package/dist/cli/convoy/spec-types.d.ts.map +1 -0
- package/dist/cli/convoy/spec-types.js +16 -0
- package/dist/cli/convoy/spec-types.js.map +1 -0
- package/dist/cli/convoy/tdd-gate.js +1 -1
- package/dist/cli/convoy/tdd-gate.js.map +1 -1
- package/dist/cli/convoy/tdd-gate.test.js +5 -5
- package/dist/cli/convoy/tdd-gate.test.js.map +1 -1
- package/dist/cli/convoy/types.d.ts +2 -0
- package/dist/cli/convoy/types.d.ts.map +1 -1
- package/dist/cli/convoy/types.js.map +1 -1
- package/dist/cli/convoy-cmd.d.ts +3 -0
- package/dist/cli/convoy-cmd.d.ts.map +1 -0
- package/dist/cli/convoy-cmd.js +187 -0
- package/dist/cli/convoy-cmd.js.map +1 -0
- package/dist/cli/copy.d.ts +16 -0
- package/dist/cli/copy.d.ts.map +1 -1
- package/dist/cli/copy.js +87 -6
- package/dist/cli/copy.js.map +1 -1
- package/dist/cli/dashboard.d.ts.map +1 -1
- package/dist/cli/dashboard.js +6 -28
- package/dist/cli/dashboard.js.map +1 -1
- package/dist/cli/detect.d.ts +11 -0
- package/dist/cli/detect.d.ts.map +1 -1
- package/dist/cli/detect.js +51 -0
- package/dist/cli/detect.js.map +1 -1
- package/dist/cli/dispatcher.test.d.ts +2 -0
- package/dist/cli/dispatcher.test.d.ts.map +1 -0
- package/dist/cli/dispatcher.test.js +119 -0
- package/dist/cli/dispatcher.test.js.map +1 -0
- package/dist/cli/docs-accuracy.test.d.ts +2 -0
- package/dist/cli/docs-accuracy.test.d.ts.map +1 -0
- package/dist/cli/docs-accuracy.test.js +630 -0
- package/dist/cli/docs-accuracy.test.js.map +1 -0
- package/dist/cli/doctor-remedies.test.d.ts +2 -0
- package/dist/cli/doctor-remedies.test.d.ts.map +1 -0
- package/dist/cli/doctor-remedies.test.js +184 -0
- package/dist/cli/doctor-remedies.test.js.map +1 -0
- package/dist/cli/doctor.d.ts +30 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +741 -35
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/gitignore.d.ts +41 -12
- package/dist/cli/gitignore.d.ts.map +1 -1
- package/dist/cli/gitignore.js +544 -55
- package/dist/cli/gitignore.js.map +1 -1
- package/dist/cli/gitignore.property.test.d.ts +2 -0
- package/dist/cli/gitignore.property.test.d.ts.map +1 -0
- package/dist/cli/gitignore.property.test.js +360 -0
- package/dist/cli/gitignore.property.test.js.map +1 -0
- package/dist/cli/init-detect.test.d.ts +2 -0
- package/dist/cli/init-detect.test.d.ts.map +1 -0
- package/dist/cli/init-detect.test.js +145 -0
- package/dist/cli/init-detect.test.js.map +1 -0
- package/dist/cli/init.d.ts +30 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +522 -162
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.d.ts +1 -1
- package/dist/cli/init.test.js +59 -77
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/legacy-install.test.d.ts +2 -0
- package/dist/cli/legacy-install.test.d.ts.map +1 -0
- package/dist/cli/legacy-install.test.js +273 -0
- package/dist/cli/legacy-install.test.js.map +1 -0
- package/dist/cli/lesson.d.ts +0 -5
- package/dist/cli/lesson.d.ts.map +1 -1
- package/dist/cli/lesson.js +1 -1
- package/dist/cli/lesson.js.map +1 -1
- package/dist/cli/log.d.ts +0 -2
- package/dist/cli/log.d.ts.map +1 -1
- package/dist/cli/log.js +3 -3
- package/dist/cli/log.js.map +1 -1
- package/dist/cli/managed-block.d.ts +223 -0
- package/dist/cli/managed-block.d.ts.map +1 -0
- package/dist/cli/managed-block.js +822 -0
- package/dist/cli/managed-block.js.map +1 -0
- package/dist/cli/managed-block.property.test.d.ts +2 -0
- package/dist/cli/managed-block.property.test.d.ts.map +1 -0
- package/dist/cli/managed-block.property.test.js +290 -0
- package/dist/cli/managed-block.property.test.js.map +1 -0
- package/dist/cli/managed-block.test.d.ts +2 -0
- package/dist/cli/managed-block.test.d.ts.map +1 -0
- package/dist/cli/managed-block.test.js +633 -0
- package/dist/cli/managed-block.test.js.map +1 -0
- package/dist/cli/managed-paths.d.ts +46 -0
- package/dist/cli/managed-paths.d.ts.map +1 -0
- package/dist/cli/managed-paths.js +106 -0
- package/dist/cli/managed-paths.js.map +1 -0
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +51 -9
- package/dist/cli/manifest.js.map +1 -1
- package/dist/cli/mcp.d.ts +34 -1
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +232 -11
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cli/pipeline.d.ts.map +1 -1
- package/dist/cli/pipeline.js +8 -10
- package/dist/cli/pipeline.js.map +1 -1
- package/dist/cli/plan.d.ts.map +1 -1
- package/dist/cli/plan.js +5 -5
- package/dist/cli/plan.js.map +1 -1
- package/dist/cli/prompt.d.ts +14 -1
- package/dist/cli/prompt.d.ts.map +1 -1
- package/dist/cli/prompt.js +43 -4
- package/dist/cli/prompt.js.map +1 -1
- package/dist/cli/publish-workflow.test.d.ts +2 -0
- package/dist/cli/publish-workflow.test.d.ts.map +1 -0
- package/dist/cli/publish-workflow.test.js +72 -0
- package/dist/cli/publish-workflow.test.js.map +1 -0
- package/dist/cli/remove.d.ts +3 -0
- package/dist/cli/remove.d.ts.map +1 -0
- package/dist/cli/remove.js +401 -0
- package/dist/cli/remove.js.map +1 -0
- package/dist/cli/remove.test.d.ts +2 -0
- package/dist/cli/remove.test.d.ts.map +1 -0
- package/dist/cli/remove.test.js +445 -0
- package/dist/cli/remove.test.js.map +1 -0
- package/dist/cli/run/adapters/claude.d.ts +1 -1
- package/dist/cli/run/adapters/claude.d.ts.map +1 -1
- package/dist/cli/run/adapters/claude.js +13 -119
- package/dist/cli/run/adapters/claude.js.map +1 -1
- package/dist/cli/run/adapters/claude.test.js +31 -47
- package/dist/cli/run/adapters/claude.test.js.map +1 -1
- package/dist/cli/run/adapters/codex.d.ts +1 -1
- package/dist/cli/run/adapters/codex.d.ts.map +1 -1
- package/dist/cli/run/adapters/copilot.d.ts +1 -1
- package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
- package/dist/cli/run/adapters/cursor.d.ts +1 -1
- package/dist/cli/run/adapters/cursor.d.ts.map +1 -1
- package/dist/cli/run/adapters/index.d.ts +1 -1
- package/dist/cli/run/adapters/index.d.ts.map +1 -1
- package/dist/cli/run/adapters/opencode.d.ts +1 -1
- package/dist/cli/run/adapters/opencode.d.ts.map +1 -1
- package/dist/cli/run/executor.d.ts +1 -1
- package/dist/cli/run/executor.d.ts.map +1 -1
- package/dist/cli/run/executor.test.js +1 -2
- package/dist/cli/run/executor.test.js.map +1 -1
- package/dist/cli/run/reporter.d.ts +1 -1
- package/dist/cli/run/reporter.d.ts.map +1 -1
- package/dist/cli/run/schema.d.ts +1 -9
- package/dist/cli/run/schema.d.ts.map +1 -1
- package/dist/cli/run/schema.js +50 -50
- package/dist/cli/run/schema.js.map +1 -1
- package/dist/cli/run/schema.test.js +83 -4
- package/dist/cli/run/schema.test.js.map +1 -1
- package/dist/cli/run-finish.test.d.ts +2 -0
- package/dist/cli/run-finish.test.d.ts.map +1 -0
- package/dist/cli/run-finish.test.js +77 -0
- package/dist/cli/run-finish.test.js.map +1 -0
- package/dist/cli/run.d.ts +23 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +95 -120
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/stack-config.d.ts +27 -6
- package/dist/cli/stack-config.d.ts.map +1 -1
- package/dist/cli/stack-config.js +83 -6
- package/dist/cli/stack-config.js.map +1 -1
- package/dist/cli/status.d.ts +27 -0
- package/dist/cli/status.d.ts.map +1 -0
- package/dist/cli/status.js +380 -0
- package/dist/cli/status.js.map +1 -0
- package/dist/cli/status.test.d.ts +2 -0
- package/dist/cli/status.test.d.ts.map +1 -0
- package/dist/cli/status.test.js +218 -0
- package/dist/cli/status.test.js.map +1 -0
- package/dist/cli/sync-check.d.ts +38 -0
- package/dist/cli/sync-check.d.ts.map +1 -0
- package/dist/cli/sync-check.js +525 -0
- package/dist/cli/sync-check.js.map +1 -0
- package/dist/cli/sync-check.test.d.ts +2 -0
- package/dist/cli/sync-check.test.d.ts.map +1 -0
- package/dist/cli/sync-check.test.js +366 -0
- package/dist/cli/sync-check.test.js.map +1 -0
- package/dist/cli/sync.d.ts +3 -0
- package/dist/cli/sync.d.ts.map +1 -0
- package/dist/cli/sync.js +39 -0
- package/dist/cli/sync.js.map +1 -0
- package/dist/cli/tiers.d.ts +26 -0
- package/dist/cli/tiers.d.ts.map +1 -0
- package/dist/cli/tiers.js +50 -0
- package/dist/cli/tiers.js.map +1 -0
- package/dist/cli/tiers.test.d.ts +2 -0
- package/dist/cli/tiers.test.d.ts.map +1 -0
- package/dist/cli/tiers.test.js +268 -0
- package/dist/cli/tiers.test.js.map +1 -0
- package/dist/cli/types.d.ts +92 -231
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js +26 -0
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/unreadable-report.d.ts +18 -0
- package/dist/cli/unreadable-report.d.ts.map +1 -0
- package/dist/cli/unreadable-report.js +28 -0
- package/dist/cli/unreadable-report.js.map +1 -0
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +395 -64
- package/dist/cli/update.js.map +1 -1
- package/dist/cli/watch.d.ts +1 -1
- package/dist/cli/watch.d.ts.map +1 -1
- package/dist/cli/watch.js +1 -1
- package/dist/cli/watch.js.map +1 -1
- package/dist/orchestrator/plugins/astro/config.js +1 -1
- package/dist/orchestrator/plugins/astro/config.js.map +1 -1
- package/dist/orchestrator/plugins/chrome-devtools/config.js +1 -1
- package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
- package/dist/orchestrator/plugins/contentful/config.js +2 -2
- package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
- package/dist/orchestrator/plugins/convex/config.js +1 -1
- package/dist/orchestrator/plugins/convex/config.js.map +1 -1
- package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/netlify/config.js +0 -1
- package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
- package/dist/orchestrator/plugins/notion/config.js +1 -1
- package/dist/orchestrator/plugins/notion/config.js.map +1 -1
- package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/nx/config.js +0 -1
- package/dist/orchestrator/plugins/nx/config.js.map +1 -1
- package/dist/orchestrator/plugins/prisma/config.js +1 -1
- package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
- package/dist/orchestrator/plugins/resend/config.js +1 -1
- package/dist/orchestrator/plugins/resend/config.js.map +1 -1
- package/dist/orchestrator/plugins/sanity/config.js +2 -2
- package/dist/orchestrator/plugins/sanity/config.js.map +1 -1
- package/dist/orchestrator/plugins/slack/config.js +1 -1
- package/dist/orchestrator/plugins/slack/config.js.map +1 -1
- package/dist/orchestrator/plugins/strapi/config.js +2 -2
- package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
- package/dist/orchestrator/plugins/stripe/config.js +1 -1
- package/dist/orchestrator/plugins/stripe/config.js.map +1 -1
- package/dist/orchestrator/plugins/supabase/config.js +1 -1
- package/dist/orchestrator/plugins/supabase/config.js.map +1 -1
- package/dist/orchestrator/plugins/teams/config.js +1 -1
- package/dist/orchestrator/plugins/teams/config.js.map +1 -1
- package/dist/orchestrator/plugins/vercel/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/vercel/config.js +0 -4
- package/dist/orchestrator/plugins/vercel/config.js.map +1 -1
- package/package.json +10 -13
- package/src/cli/adapters/adapter-contract.test.ts +58 -0
- package/src/cli/adapters/cursor.ts +25 -409
- package/src/cli/adapters/rules-dir-base.test.ts +246 -0
- package/src/cli/adapters/rules-dir-base.ts +456 -0
- package/src/cli/adapters/single-file-base.ts +270 -66
- package/src/cli/adapters/vscode.ts +146 -50
- package/src/cli/adapters/windsurf.ts +32 -416
- package/src/cli/add.ts +125 -0
- package/src/cli/agent-roster.test.ts +209 -0
- package/src/cli/boundary.test.ts +221 -0
- package/src/cli/convoy/artifacts.ts +4 -4
- package/src/cli/convoy/built-in-gates.test.ts +117 -0
- package/src/cli/convoy/contracts.test.ts +51 -20
- package/src/cli/convoy/contracts.ts +50 -65
- package/src/cli/convoy/crash-status.test.ts +245 -0
- package/src/cli/convoy/dag-analysis.ts +0 -4
- package/src/cli/convoy/engine.test.ts +169 -51
- package/src/cli/convoy/engine.ts +231 -247
- package/src/cli/convoy/event-schemas.ts +1 -1
- package/src/cli/convoy/events.test.ts +1 -1
- package/src/cli/convoy/formula.test.ts +0 -1
- package/src/cli/convoy/formula.ts +1 -1
- package/src/cli/convoy/gates.ts +126 -0
- package/src/cli/convoy/health.test.ts +1 -1
- package/src/cli/convoy/health.ts +1 -1
- package/src/cli/convoy/ledger-paths.test.ts +138 -0
- package/src/cli/convoy/lock.test.ts +0 -1
- package/src/cli/convoy/lock.ts +0 -4
- package/src/cli/convoy/no-op-gate.test.ts +156 -0
- package/src/cli/convoy/partition.test.ts +1 -1
- package/src/cli/convoy/partition.ts +1 -1
- package/src/cli/convoy/pipeline.test.ts +1 -1
- package/src/cli/convoy/pipeline.ts +2 -2
- package/src/cli/convoy/spec-builder.test.ts +0 -3
- package/src/cli/convoy/spec-builder.ts +1 -4
- package/src/cli/convoy/spec-types.ts +286 -0
- package/src/cli/convoy/tdd-gate.test.ts +5 -5
- package/src/cli/convoy/tdd-gate.ts +1 -1
- package/src/cli/convoy/types.ts +3 -1
- package/src/cli/convoy-cmd.ts +216 -0
- package/src/cli/copy.ts +90 -6
- package/src/cli/dashboard.ts +6 -25
- package/src/cli/detect.ts +64 -0
- package/src/cli/dispatcher.test.ts +135 -0
- package/src/cli/docs-accuracy.test.ts +674 -0
- package/src/cli/doctor-remedies.test.ts +218 -0
- package/src/cli/doctor.ts +799 -35
- package/src/cli/gitignore.property.test.ts +425 -0
- package/src/cli/gitignore.ts +556 -60
- package/src/cli/init-detect.test.ts +182 -0
- package/src/cli/init.test.ts +60 -78
- package/src/cli/init.ts +580 -176
- package/src/cli/legacy-install.test.ts +324 -0
- package/src/cli/lesson.ts +1 -1
- package/src/cli/log.ts +3 -3
- package/src/cli/managed-block.property.test.ts +372 -0
- package/src/cli/managed-block.test.ts +755 -0
- package/src/cli/managed-block.ts +1011 -0
- package/src/cli/managed-paths.ts +117 -0
- package/src/cli/manifest.ts +50 -14
- package/src/cli/mcp.ts +249 -12
- package/src/cli/pipeline.ts +9 -11
- package/src/cli/plan.ts +7 -6
- package/src/cli/prompt.ts +45 -4
- package/src/cli/publish-workflow.test.ts +86 -0
- package/src/cli/remove.test.ts +530 -0
- package/src/cli/remove.ts +449 -0
- package/src/cli/run/adapters/claude.test.ts +37 -62
- package/src/cli/run/adapters/claude.ts +14 -148
- package/src/cli/run/adapters/codex.test.ts +1 -1
- package/src/cli/run/adapters/codex.ts +1 -1
- package/src/cli/run/adapters/copilot.test.ts +1 -1
- package/src/cli/run/adapters/copilot.ts +1 -1
- package/src/cli/run/adapters/cursor.test.ts +1 -1
- package/src/cli/run/adapters/cursor.ts +1 -1
- package/src/cli/run/adapters/index.ts +1 -1
- package/src/cli/run/adapters/opencode.test.ts +1 -1
- package/src/cli/run/adapters/opencode.ts +1 -1
- package/src/cli/run/executor.test.ts +3 -4
- package/src/cli/run/executor.ts +1 -1
- package/src/cli/run/reporter.ts +1 -1
- package/src/cli/run/schema.test.ts +94 -4
- package/src/cli/run/schema.ts +53 -52
- package/src/cli/run-finish.test.ts +91 -0
- package/src/cli/run.ts +112 -105
- package/src/cli/stack-config.ts +96 -7
- package/src/cli/status.test.ts +251 -0
- package/src/cli/status.ts +404 -0
- package/src/cli/sync-check.test.ts +435 -0
- package/src/cli/sync-check.ts +573 -0
- package/src/cli/sync.ts +44 -0
- package/src/cli/tiers.test.ts +294 -0
- package/src/cli/tiers.ts +63 -0
- package/src/cli/types.ts +109 -255
- package/src/cli/unreadable-report.ts +26 -0
- package/src/cli/update.ts +430 -67
- package/src/cli/watch.ts +2 -3
- package/src/dashboard/dist/data/convoy-list.json +1 -93
- package/src/dashboard/dist/data/overall-stats.json +15 -99
- package/src/dashboard/dist/index.html +47 -56
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/dashboard/public/data/convoy-list.json +1 -93
- package/src/dashboard/public/data/overall-stats.json +15 -99
- package/src/dashboard/scripts/generate-demo-db.ts +26 -20
- package/src/dashboard/seed-data/delegations.ndjson +35 -35
- package/src/dashboard/seed-data/events.ndjson +104 -104
- package/src/dashboard/seed-data/panels.ndjson +13 -13
- package/src/dashboard/seed-data/reviews.ndjson +6 -6
- package/src/dashboard/seed-data/sessions.ndjson +50 -50
- package/src/dashboard/src/pages/index.astro +45 -54
- package/src/orchestrator/agent-workflows/data-pipeline.md +4 -4
- package/src/orchestrator/agent-workflows/database-migration.md +3 -3
- package/src/orchestrator/agent-workflows/feature-implementation.md +3 -3
- package/src/orchestrator/agent-workflows/performance-optimization.md +1 -1
- package/src/orchestrator/agents/architect.agent.md +23 -42
- package/src/orchestrator/agents/content-engineer.agent.md +17 -27
- package/src/orchestrator/agents/data-engineer.agent.md +65 -0
- package/src/orchestrator/agents/developer.agent.md +23 -36
- package/src/orchestrator/agents/devops-expert.agent.md +31 -38
- package/src/orchestrator/agents/performance-expert.agent.md +25 -39
- package/src/orchestrator/agents/researcher.agent.md +18 -38
- package/src/orchestrator/agents/reviewer.agent.md +10 -12
- package/src/orchestrator/agents/security-expert.agent.md +24 -35
- package/src/orchestrator/agents/team-lead.agent.md +13 -19
- package/src/orchestrator/agents/testing-expert.agent.md +18 -35
- package/src/orchestrator/agents/ui-ux-expert.agent.md +25 -38
- package/src/orchestrator/agents/writer.agent.md +68 -0
- package/src/orchestrator/customizations/AGENT-EXPERTISE.md +7 -7
- package/src/orchestrator/customizations/AGENT-PERFORMANCE.md +1 -1
- package/src/orchestrator/customizations/agents/agent-registry.md +19 -20
- package/src/orchestrator/customizations/agents/skill-matrix.json +157 -60
- package/src/orchestrator/customizations/agents/skill-matrix.md +12 -12
- package/src/orchestrator/customizations/logs/README.md +10 -10
- package/src/orchestrator/customizations/project/tracker-config.md +2 -2
- package/src/orchestrator/instructions/general.instructions.md +29 -6
- package/src/orchestrator/plugins/astro/SKILL.md +16 -109
- package/src/orchestrator/plugins/astro/config.ts +1 -1
- package/src/orchestrator/plugins/chrome-devtools/SKILL.md +15 -128
- package/src/orchestrator/plugins/chrome-devtools/config.ts +1 -1
- package/src/orchestrator/plugins/cloudflare/SKILL.md +17 -95
- package/src/orchestrator/plugins/contentful/SKILL.md +15 -68
- package/src/orchestrator/plugins/contentful/config.ts +2 -2
- package/src/orchestrator/plugins/convex/SKILL.md +49 -133
- package/src/orchestrator/plugins/convex/config.ts +1 -1
- package/src/orchestrator/plugins/coolify/SKILL.md +18 -122
- package/src/orchestrator/plugins/cypress/SKILL.md +15 -66
- package/src/orchestrator/plugins/drizzle/SKILL.md +15 -112
- package/src/orchestrator/plugins/expo/SKILL.md +13 -101
- package/src/orchestrator/plugins/figma/SKILL.md +30 -47
- package/src/orchestrator/plugins/jira/SKILL.md +14 -58
- package/src/orchestrator/plugins/linear/SKILL.md +19 -75
- package/src/orchestrator/plugins/netlify/SKILL.md +18 -87
- package/src/orchestrator/plugins/netlify/config.ts +0 -1
- package/src/orchestrator/plugins/nextjs/SKILL.md +12 -58
- package/src/orchestrator/plugins/notion/SKILL.md +16 -46
- package/src/orchestrator/plugins/notion/config.ts +1 -1
- package/src/orchestrator/plugins/nx/SKILL.md +30 -114
- package/src/orchestrator/plugins/nx/config.ts +0 -1
- package/src/orchestrator/plugins/playwright/SKILL.md +23 -96
- package/src/orchestrator/plugins/prisma/SKILL.md +20 -68
- package/src/orchestrator/plugins/prisma/config.ts +1 -1
- package/src/orchestrator/plugins/resend/SKILL.md +15 -58
- package/src/orchestrator/plugins/resend/config.ts +1 -1
- package/src/orchestrator/plugins/sanity/SKILL.md +15 -54
- package/src/orchestrator/plugins/sanity/config.ts +2 -2
- package/src/orchestrator/plugins/sentry/SKILL.md +14 -81
- package/src/orchestrator/plugins/slack/SKILL.md +20 -56
- package/src/orchestrator/plugins/slack/config.ts +1 -1
- package/src/orchestrator/plugins/strapi/SKILL.md +19 -65
- package/src/orchestrator/plugins/strapi/config.ts +2 -2
- package/src/orchestrator/plugins/stripe/SKILL.md +18 -124
- package/src/orchestrator/plugins/stripe/config.ts +1 -1
- package/src/orchestrator/plugins/supabase/SKILL.md +22 -36
- package/src/orchestrator/plugins/supabase/config.ts +1 -1
- package/src/orchestrator/plugins/teams/SKILL.md +1 -1
- package/src/orchestrator/plugins/teams/config.ts +1 -1
- package/src/orchestrator/plugins/turborepo/SKILL.md +0 -2
- package/src/orchestrator/plugins/vercel/SKILL.md +1 -1
- package/src/orchestrator/plugins/vercel/config.ts +0 -4
- package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +1 -1
- package/src/orchestrator/prompts/bug-fix.prompt.md +1 -1
- package/src/orchestrator/prompts/generate-convoy.prompt.md +6 -7
- package/src/orchestrator/prompts/generate-prd.prompt.md +0 -4
- package/src/orchestrator/prompts/implement-feature.prompt.md +1 -1
- package/src/orchestrator/skills/accessibility-standards/SKILL.md +17 -87
- package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +6 -8
- package/src/orchestrator/skills/agent-hooks/SKILL.md +7 -7
- package/src/orchestrator/skills/agent-memory/SKILL.md +7 -8
- package/src/orchestrator/skills/api-patterns/SKILL.md +10 -68
- package/src/orchestrator/skills/code-commenting/SKILL.md +6 -71
- package/src/orchestrator/skills/context-map/REFERENCE.md +1 -2
- package/src/orchestrator/skills/context-map/SKILL.md +2 -2
- package/src/orchestrator/skills/data-engineering/SKILL.md +11 -43
- package/src/orchestrator/skills/decomposition/SKILL.md +2 -21
- package/src/orchestrator/skills/deployment-infrastructure/SKILL.md +14 -67
- package/src/orchestrator/skills/documentation-standards/SKILL.md +10 -102
- package/src/orchestrator/skills/fast-review/SKILL.md +3 -6
- package/src/orchestrator/skills/frontend-design/SKILL.md +14 -52
- package/src/orchestrator/skills/git-workflow/SKILL.md +6 -1
- package/src/orchestrator/skills/memory-merger/SKILL.md +1 -21
- package/src/orchestrator/skills/observability-logging/SKILL.md +8 -6
- package/src/orchestrator/skills/orchestration-protocols/REFERENCE.md +1 -1
- package/src/orchestrator/skills/orchestration-protocols/SKILL.md +13 -25
- package/src/orchestrator/skills/panel-majority-vote/REFERENCE.md +0 -2
- package/src/orchestrator/skills/panel-majority-vote/SKILL.md +4 -12
- package/src/orchestrator/skills/performance-optimization/SKILL.md +11 -68
- package/src/orchestrator/skills/project-consistency/SKILL.md +5 -17
- package/src/orchestrator/skills/react-development/SKILL.md +12 -64
- package/src/orchestrator/skills/security-hardening/SKILL.md +12 -140
- package/src/orchestrator/skills/self-improvement/SKILL.md +3 -4
- package/src/orchestrator/skills/seo-patterns/SKILL.md +12 -77
- package/src/orchestrator/skills/session-checkpoints/SKILL.md +4 -31
- package/src/orchestrator/skills/team-lead-reference/SKILL.md +4 -10
- package/src/orchestrator/skills/testing-workflow/SKILL.md +16 -98
- package/src/orchestrator/skills/validation-gates/SKILL.md +20 -16
- package/dist/cli/agents.d.ts +0 -3
- package/dist/cli/agents.d.ts.map +0 -1
- package/dist/cli/agents.js +0 -175
- package/dist/cli/agents.js.map +0 -1
- package/dist/cli/artifacts-cli.d.ts +0 -3
- package/dist/cli/artifacts-cli.d.ts.map +0 -1
- package/dist/cli/artifacts-cli.js +0 -36
- package/dist/cli/artifacts-cli.js.map +0 -1
- package/dist/cli/baselines.d.ts +0 -3
- package/dist/cli/baselines.d.ts.map +0 -1
- package/dist/cli/baselines.js +0 -151
- package/dist/cli/baselines.js.map +0 -1
- package/dist/cli/convoy/compaction.d.ts +0 -23
- package/dist/cli/convoy/compaction.d.ts.map +0 -1
- package/dist/cli/convoy/compaction.js +0 -117
- package/dist/cli/convoy/compaction.js.map +0 -1
- package/dist/cli/convoy/compaction.test.d.ts +0 -2
- package/dist/cli/convoy/compaction.test.d.ts.map +0 -1
- package/dist/cli/convoy/compaction.test.js +0 -205
- package/dist/cli/convoy/compaction.test.js.map +0 -1
- package/dist/cli/convoy/expertise.d.ts +0 -16
- package/dist/cli/convoy/expertise.d.ts.map +0 -1
- package/dist/cli/convoy/expertise.js +0 -121
- package/dist/cli/convoy/expertise.js.map +0 -1
- package/dist/cli/convoy/expertise.test.d.ts +0 -2
- package/dist/cli/convoy/expertise.test.d.ts.map +0 -1
- package/dist/cli/convoy/expertise.test.js +0 -96
- package/dist/cli/convoy/expertise.test.js.map +0 -1
- package/dist/cli/convoy/export.d.ts +0 -2
- package/dist/cli/convoy/export.d.ts.map +0 -1
- package/dist/cli/convoy/export.js +0 -10
- package/dist/cli/convoy/export.js.map +0 -1
- package/dist/cli/convoy/export.test.d.ts +0 -2
- package/dist/cli/convoy/export.test.d.ts.map +0 -1
- package/dist/cli/convoy/export.test.js +0 -10
- package/dist/cli/convoy/export.test.js.map +0 -1
- package/dist/cli/convoy/issues.d.ts +0 -8
- package/dist/cli/convoy/issues.d.ts.map +0 -1
- package/dist/cli/convoy/issues.js +0 -98
- package/dist/cli/convoy/issues.js.map +0 -1
- package/dist/cli/convoy/issues.test.d.ts +0 -2
- package/dist/cli/convoy/issues.test.d.ts.map +0 -1
- package/dist/cli/convoy/issues.test.js +0 -108
- package/dist/cli/convoy/issues.test.js.map +0 -1
- package/dist/cli/convoy/knowledge.d.ts +0 -5
- package/dist/cli/convoy/knowledge.d.ts.map +0 -1
- package/dist/cli/convoy/knowledge.js +0 -116
- package/dist/cli/convoy/knowledge.js.map +0 -1
- package/dist/cli/convoy/knowledge.test.d.ts +0 -2
- package/dist/cli/convoy/knowledge.test.d.ts.map +0 -1
- package/dist/cli/convoy/knowledge.test.js +0 -87
- package/dist/cli/convoy/knowledge.test.js.map +0 -1
- package/dist/cli/convoy/lessons.d.ts +0 -17
- package/dist/cli/convoy/lessons.d.ts.map +0 -1
- package/dist/cli/convoy/lessons.js +0 -149
- package/dist/cli/convoy/lessons.js.map +0 -1
- package/dist/cli/convoy/lessons.test.d.ts +0 -2
- package/dist/cli/convoy/lessons.test.d.ts.map +0 -1
- package/dist/cli/convoy/lessons.test.js +0 -135
- package/dist/cli/convoy/lessons.test.js.map +0 -1
- package/dist/cli/convoy/skill-refinement.d.ts +0 -39
- package/dist/cli/convoy/skill-refinement.d.ts.map +0 -1
- package/dist/cli/convoy/skill-refinement.js +0 -239
- package/dist/cli/convoy/skill-refinement.js.map +0 -1
- package/dist/cli/convoy/skill-refinement.test.d.ts +0 -2
- package/dist/cli/convoy/skill-refinement.test.d.ts.map +0 -1
- package/dist/cli/convoy/skill-refinement.test.js +0 -230
- package/dist/cli/convoy/skill-refinement.test.js.map +0 -1
- package/dist/cli/destroy.d.ts +0 -3
- package/dist/cli/destroy.d.ts.map +0 -1
- package/dist/cli/destroy.js +0 -82
- package/dist/cli/destroy.js.map +0 -1
- package/dist/cli/destroy.test.d.ts +0 -2
- package/dist/cli/destroy.test.d.ts.map +0 -1
- package/dist/cli/destroy.test.js +0 -116
- package/dist/cli/destroy.test.js.map +0 -1
- package/dist/cli/dispute.d.ts +0 -3
- package/dist/cli/dispute.d.ts.map +0 -1
- package/dist/cli/dispute.js +0 -25
- package/dist/cli/dispute.js.map +0 -1
- package/dist/cli/eject.d.ts +0 -3
- package/dist/cli/eject.d.ts.map +0 -1
- package/dist/cli/eject.js +0 -46
- package/dist/cli/eject.js.map +0 -1
- package/dist/cli/insights.d.ts +0 -3
- package/dist/cli/insights.d.ts.map +0 -1
- package/dist/cli/insights.js +0 -98
- package/dist/cli/insights.js.map +0 -1
- package/dist/cli/package-config.d.ts +0 -12
- package/dist/cli/package-config.d.ts.map +0 -1
- package/dist/cli/package-config.js +0 -37
- package/dist/cli/package-config.js.map +0 -1
- package/dist/cli/package.d.ts +0 -23
- package/dist/cli/package.d.ts.map +0 -1
- package/dist/cli/package.js +0 -293
- package/dist/cli/package.js.map +0 -1
- package/dist/cli/package.test.d.ts +0 -2
- package/dist/cli/package.test.d.ts.map +0 -1
- package/dist/cli/package.test.js +0 -236
- package/dist/cli/package.test.js.map +0 -1
- package/dist/cli/skills.d.ts +0 -3
- package/dist/cli/skills.d.ts.map +0 -1
- package/dist/cli/skills.js +0 -107
- package/dist/cli/skills.js.map +0 -1
- package/dist/cli/validate.d.ts +0 -3
- package/dist/cli/validate.d.ts.map +0 -1
- package/dist/cli/validate.js +0 -60
- package/dist/cli/validate.js.map +0 -1
- package/src/cli/agents.ts +0 -192
- package/src/cli/artifacts-cli.ts +0 -41
- package/src/cli/baselines.ts +0 -158
- package/src/cli/convoy/compaction.test.ts +0 -245
- package/src/cli/convoy/compaction.ts +0 -164
- package/src/cli/convoy/expertise.test.ts +0 -128
- package/src/cli/convoy/expertise.ts +0 -163
- package/src/cli/convoy/export.test.ts +0 -11
- package/src/cli/convoy/export.ts +0 -10
- package/src/cli/convoy/issues.test.ts +0 -144
- package/src/cli/convoy/issues.ts +0 -136
- package/src/cli/convoy/knowledge.test.ts +0 -101
- package/src/cli/convoy/knowledge.ts +0 -132
- package/src/cli/convoy/lessons.test.ts +0 -188
- package/src/cli/convoy/lessons.ts +0 -164
- package/src/cli/convoy/skill-refinement.test.ts +0 -277
- package/src/cli/convoy/skill-refinement.ts +0 -306
- package/src/cli/destroy.test.ts +0 -141
- package/src/cli/destroy.ts +0 -103
- package/src/cli/dispute.ts +0 -28
- package/src/cli/eject.ts +0 -61
- package/src/cli/insights.ts +0 -100
- package/src/cli/package-config.ts +0 -48
- package/src/cli/package.test.ts +0 -276
- package/src/cli/package.ts +0 -331
- package/src/cli/run/adapters/vendor.d.ts +0 -2
- package/src/cli/skills.ts +0 -121
- package/src/cli/validate.ts +0 -65
- package/src/dashboard/dist/data/convoys/demo-api-v2.json +0 -183
- package/src/dashboard/dist/data/convoys/demo-auth-revamp.json +0 -249
- package/src/dashboard/dist/data/convoys/demo-dashboard-ui.json +0 -342
- package/src/dashboard/dist/data/convoys/demo-data-pipeline.json +0 -193
- package/src/dashboard/dist/data/convoys/demo-deploy-ci.json +0 -157
- package/src/dashboard/dist/data/convoys/demo-docs-update.json +0 -158
- package/src/dashboard/dist/data/convoys/demo-perf-opt.json +0 -235
- package/src/dashboard/dist/data/events.ndjson +0 -115
- package/src/dashboard/public/data/convoys/demo-api-v2.json +0 -183
- package/src/dashboard/public/data/convoys/demo-auth-revamp.json +0 -249
- package/src/dashboard/public/data/convoys/demo-dashboard-ui.json +0 -342
- package/src/dashboard/public/data/convoys/demo-data-pipeline.json +0 -193
- package/src/dashboard/public/data/convoys/demo-deploy-ci.json +0 -157
- package/src/dashboard/public/data/convoys/demo-docs-update.json +0 -158
- package/src/dashboard/public/data/convoys/demo-perf-opt.json +0 -235
- package/src/dashboard/public/data/events.ndjson +0 -115
- package/src/dashboard/scripts/generate-seed-data.ts +0 -335
- package/src/orchestrator/agents/api-designer.agent.md +0 -52
- package/src/orchestrator/agents/copywriter.agent.md +0 -65
- package/src/orchestrator/agents/data-expert.agent.md +0 -56
- package/src/orchestrator/agents/database-engineer.agent.md +0 -55
- package/src/orchestrator/agents/documentation-writer.agent.md +0 -60
- package/src/orchestrator/agents/release-manager.agent.md +0 -56
- package/src/orchestrator/agents/seo-specialist.agent.md +0 -54
- package/src/orchestrator/agents/session-guard.agent.md +0 -57
- package/src/orchestrator/plugins/astro/REFERENCE.md +0 -5
- package/src/orchestrator/plugins/chrome-devtools/REFERENCE.md +0 -9
- package/src/orchestrator/plugins/cloudflare/references/deployment.md +0 -147
- package/src/orchestrator/plugins/cloudflare/references/storage.md +0 -118
- package/src/orchestrator/plugins/cloudflare/references/workers.md +0 -135
- package/src/orchestrator/plugins/contentful/REFERENCE.md +0 -16
- package/src/orchestrator/plugins/convex/references/auth-auth0.md +0 -116
- package/src/orchestrator/plugins/convex/references/auth-clerk.md +0 -113
- package/src/orchestrator/plugins/convex/references/auth-convex-auth.md +0 -143
- package/src/orchestrator/plugins/convex/references/auth-setup.md +0 -87
- package/src/orchestrator/plugins/convex/references/auth-workos.md +0 -114
- package/src/orchestrator/plugins/convex/references/components-advanced.md +0 -134
- package/src/orchestrator/plugins/convex/references/components.md +0 -171
- package/src/orchestrator/plugins/convex/references/function-budget.md +0 -232
- package/src/orchestrator/plugins/convex/references/hot-path-rules.md +0 -371
- package/src/orchestrator/plugins/convex/references/migrations-component.md +0 -170
- package/src/orchestrator/plugins/convex/references/migrations.md +0 -259
- package/src/orchestrator/plugins/convex/references/occ-conflicts.md +0 -126
- package/src/orchestrator/plugins/convex/references/performance-audit.md +0 -80
- package/src/orchestrator/plugins/convex/references/quickstart.md +0 -176
- package/src/orchestrator/plugins/convex/references/subscription-cost.md +0 -252
- package/src/orchestrator/plugins/coolify/references/applications.md +0 -65
- package/src/orchestrator/plugins/coolify/references/ci-cd-webhooks.md +0 -73
- package/src/orchestrator/plugins/coolify/references/databases-services.md +0 -57
- package/src/orchestrator/plugins/coolify/references/docker-compose.md +0 -121
- package/src/orchestrator/plugins/coolify/references/infrastructure.md +0 -77
- package/src/orchestrator/plugins/cypress/REFERENCE.md +0 -5
- package/src/orchestrator/plugins/drizzle/references/migrations.md +0 -112
- package/src/orchestrator/plugins/drizzle/references/query-patterns.md +0 -127
- package/src/orchestrator/plugins/drizzle/references/schema-patterns.md +0 -105
- package/src/orchestrator/plugins/expo/references/eas-build.md +0 -73
- package/src/orchestrator/plugins/expo/references/native-modules.md +0 -71
- package/src/orchestrator/plugins/expo/references/routing.md +0 -83
- package/src/orchestrator/plugins/figma/REFERENCE.md +0 -18
- package/src/orchestrator/plugins/jira/REFERENCE.md +0 -9
- package/src/orchestrator/plugins/netlify/REFERENCE.md +0 -33
- package/src/orchestrator/plugins/nextjs/REFERENCE.md +0 -73
- package/src/orchestrator/plugins/notion/TEMPLATES.md +0 -88
- package/src/orchestrator/plugins/nx/REFERENCE.md +0 -10
- package/src/orchestrator/plugins/playwright/REFERENCE.md +0 -12
- package/src/orchestrator/plugins/prisma/REFERENCE.md +0 -42
- package/src/orchestrator/plugins/resend/REFERENCE.md +0 -61
- package/src/orchestrator/plugins/sentry/references/error-patterns.md +0 -112
- package/src/orchestrator/plugins/sentry/references/performance.md +0 -66
- package/src/orchestrator/plugins/sentry/references/sdk-setup.md +0 -108
- package/src/orchestrator/plugins/slack/REFERENCE.md +0 -24
- package/src/orchestrator/plugins/strapi/REFERENCE.md +0 -35
- package/src/orchestrator/plugins/stripe/references/api-patterns.md +0 -57
- package/src/orchestrator/plugins/stripe/references/projects-setup.md +0 -30
- package/src/orchestrator/plugins/stripe/references/upgrade-guide.md +0 -105
- package/src/orchestrator/plugins/supabase/REFERENCE.md +0 -9
- package/src/orchestrator/plugins/teams/REFERENCE.md +0 -36
- package/src/orchestrator/plugins/trello/REFERENCE.md +0 -9
- package/src/orchestrator/plugins/turborepo/REFERENCE.md +0 -9
- package/src/orchestrator/skills/backbone-scaffolding/SKILL.md +0 -88
- package/src/orchestrator/snippets/base-output-contract.md +0 -14
- package/src/orchestrator/snippets/discovered-issues-policy.md +0 -15
- package/src/orchestrator/snippets/logging-mandatory.md +0 -11
- package/src/orchestrator/snippets/never-expose-secrets.md +0 -22
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
import { readFile, writeFile, rm } from 'node:fs/promises'
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Merge generated content into a file the user may already own.
|
|
6
|
+
*
|
|
7
|
+
* Root instruction files — CLAUDE.md, AGENTS.md, GEMINI.md,
|
|
8
|
+
* .github/copilot-instructions.md — are the one place where the user's own
|
|
9
|
+
* writing and the compiler's output share a file. The adapters used to resolve
|
|
10
|
+
* that by skipping: if the file existed, nothing was written. On the exact repo
|
|
11
|
+
* this tool is pitched at — one that already has a CLAUDE.md — that meant the
|
|
12
|
+
* instructions layer silently never installed.
|
|
13
|
+
*
|
|
14
|
+
* A marked block fixes both halves. The user's content is never touched, and
|
|
15
|
+
* the generated section can be replaced on every sync without diffing prose.
|
|
16
|
+
* Same convention as the .gitignore block, so there is one idea to learn.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export const BLOCK_START = '<!-- >>> OpenCastle managed — regenerated by `opencastle sync`, edits here are lost >>> -->'
|
|
20
|
+
export const BLOCK_END = '<!-- <<< OpenCastle managed <<< -->'
|
|
21
|
+
|
|
22
|
+
/** A byte-order mark, as bytes — see `withoutBom` and `markerOffsets`. */
|
|
23
|
+
const BOM_BYTES = Buffer.from('\ufeff', 'utf8').toString('latin1')
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Co-owned files are read and written as bytes, not as UTF-8 text.
|
|
27
|
+
*
|
|
28
|
+
* Everything outside our markers belongs to the user, including bytes that are
|
|
29
|
+
* not valid UTF-8. Decoding replaced each of them with U+FFFD and the encode on
|
|
30
|
+
* the way out made that permanent: `Café rules` came back as `Caf<EF BF BD>
|
|
31
|
+
* rules`, and in `.gitignore` a rule containing such a byte stopped matching —
|
|
32
|
+
* so the path it protected became committable, silently, with no backup.
|
|
33
|
+
*
|
|
34
|
+
* `latin1` is a byte-for-byte codec: one byte in, one code unit out, and back
|
|
35
|
+
* again unchanged whatever the bytes were. All the surgery here is offsets and
|
|
36
|
+
* ASCII-ish markers, so it works the same in that space — the markers just have
|
|
37
|
+
* to be converted too, since ours contains an em dash.
|
|
38
|
+
*/
|
|
39
|
+
const BLOCK_START_BYTES = Buffer.from(BLOCK_START, 'utf8').toString('latin1')
|
|
40
|
+
const BLOCK_END_BYTES = Buffer.from(BLOCK_END, 'utf8').toString('latin1')
|
|
41
|
+
|
|
42
|
+
/** Text we generated, as the bytes it should occupy on disk. */
|
|
43
|
+
function asBytes(text: string): string {
|
|
44
|
+
return Buffer.from(text, 'utf8').toString('latin1')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function readBytes(path: string): Promise<string> {
|
|
48
|
+
return (await readFile(path)).toString('latin1')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function writeBytes(path: string, bytes: string): Promise<void> {
|
|
52
|
+
await writeFile(path, Buffer.from(bytes, 'latin1'))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type MergeAction =
|
|
56
|
+
| 'created'
|
|
57
|
+
| 'updated'
|
|
58
|
+
| 'appended'
|
|
59
|
+
| 'adopted'
|
|
60
|
+
/** The end marker was missing; the block was rebuilt and the old file backed up. */
|
|
61
|
+
| 'repaired'
|
|
62
|
+
| 'unchanged'
|
|
63
|
+
|
|
64
|
+
export interface MergeResult {
|
|
65
|
+
action: MergeAction
|
|
66
|
+
/** True when the file held content the user wrote. */
|
|
67
|
+
preservedUserContent: boolean
|
|
68
|
+
/**
|
|
69
|
+
* The file keeps output from an older release above our block, which we could
|
|
70
|
+
* not safely remove because the user's own writing came first.
|
|
71
|
+
*/
|
|
72
|
+
staleGeneratedContent?: boolean
|
|
73
|
+
/** The file carries a start marker that opens no block. */
|
|
74
|
+
orphanMarker?: boolean
|
|
75
|
+
/** Markers with no block at all: nothing was written, a person is needed. */
|
|
76
|
+
severed?: boolean
|
|
77
|
+
/**
|
|
78
|
+
* More than one complete block *and* unpaired markers.
|
|
79
|
+
*
|
|
80
|
+
* The tool will not reduce this: cutting a block here can promote two strays
|
|
81
|
+
* into a pair around the user's own text. Reported so a person can resolve it,
|
|
82
|
+
* which is the same answer this module gives to any damage it cannot read.
|
|
83
|
+
*/
|
|
84
|
+
damaged?: boolean
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Fingerprints of a root file that an OpenCastle release before the markers
|
|
89
|
+
* generated in full.
|
|
90
|
+
*
|
|
91
|
+
* Without this, every existing install's first `sync` would treat its own old
|
|
92
|
+
* output as the user's writing, keep it, and append a second copy underneath —
|
|
93
|
+
* leaving a doubled file whose stale half still advertises agents and skills
|
|
94
|
+
* that no longer exist. These strings only ever came out of this tool.
|
|
95
|
+
*/
|
|
96
|
+
/**
|
|
97
|
+
* Sentences those releases opened their *body* with. Prose no one writes by
|
|
98
|
+
* accident, and never as a note to a teammate.
|
|
99
|
+
*/
|
|
100
|
+
const LEGACY_GENERATED_MARKERS = [
|
|
101
|
+
'All conventions, architecture, and project context are embedded below',
|
|
102
|
+
'All conventions, architecture, and project context live in',
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The banner those releases wrote, which only counts inside an HTML comment.
|
|
107
|
+
*
|
|
108
|
+
* `This file is managed by OpenCastle` is a sentence a person writes — "This
|
|
109
|
+
* file is managed by OpenCastle. Make your edits in `.opencastle/` instead." is
|
|
110
|
+
* a reasonable line for a human to put at the top of their own CLAUDE.md, and
|
|
111
|
+
* it was enough to have that file replaced wholesale. Our releases only ever
|
|
112
|
+
* emitted it as `<!-- ⚠️ This file is managed by OpenCastle. … -->`, so the
|
|
113
|
+
* comment is the part that makes it ours.
|
|
114
|
+
*/
|
|
115
|
+
const LEGACY_BANNER_MARKERS = ['This file is managed by OpenCastle']
|
|
116
|
+
|
|
117
|
+
/** Headers those releases opened the file with. */
|
|
118
|
+
const LEGACY_GENERATED_HEADERS = ['# Project Instructions', '# Copilot Instructions']
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A leading byte-order mark, removed before any of these predicates look.
|
|
122
|
+
*
|
|
123
|
+
* In byte space a BOM is three characters in front of the heading, so
|
|
124
|
+
* `# Project Instructions` stopped being the first line and every legacy test
|
|
125
|
+
* silently answered no: an upgrade neither adopted the file nor warned about
|
|
126
|
+
* it, just appended — 197 lines becoming 421, in silence — while `doctor`, still
|
|
127
|
+
* decoding as UTF-8 where the BOM is one invisible character, said the opposite
|
|
128
|
+
* about the same bytes. A one-byte cliff, and a fresh pair of interpreters.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
function withoutBom(text: string): string {
|
|
132
|
+
if (text.startsWith(BOM_BYTES)) return text.slice(BOM_BYTES.length)
|
|
133
|
+
return text.startsWith('\ufeff') ? text.slice(1) : text
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Lines, split the way `markerOffsets` splits them.
|
|
138
|
+
*
|
|
139
|
+
* `split('\n')` was the shared mistake in every predicate below. A file saved
|
|
140
|
+
* with classic-Mac endings has no `\n` in it at all, so it came back as one long
|
|
141
|
+
* line and no fingerprint could match — which meant a root file carrying the
|
|
142
|
+
* previous release's entire instruction set above our block was invisible to
|
|
143
|
+
* `sync`, `doctor`, `sync --check` and `status` alike. All four green, the
|
|
144
|
+
* assistant reading two contradictory instruction sets, and nothing to tell the
|
|
145
|
+
* user the older one was there. `markerOffsets` was taught the lone `\r` two
|
|
146
|
+
* rounds ago; the three readers beside it, built on the same bytes, were not.
|
|
147
|
+
*/
|
|
148
|
+
function contentLines(content: string): string[] {
|
|
149
|
+
return withoutBom(content).split(/\r\n|\n|\r/)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** First line with content, ignoring comments that are not our own banner. */
|
|
153
|
+
function firstMeaningfulLine(content: string): string {
|
|
154
|
+
for (const raw of contentLines(content)) {
|
|
155
|
+
const line = raw.trim()
|
|
156
|
+
if (!line) continue
|
|
157
|
+
if (line.startsWith('<!--')) {
|
|
158
|
+
if ([...LEGACY_GENERATED_MARKERS, ...LEGACY_BANNER_MARKERS].some((m) => line.includes(m))) {
|
|
159
|
+
return line
|
|
160
|
+
}
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
return line
|
|
164
|
+
}
|
|
165
|
+
return ''
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* True only when the file is generated all the way through.
|
|
170
|
+
*
|
|
171
|
+
* Matching a fingerprint anywhere is not enough, in two directions. People edit
|
|
172
|
+
* their generated CLAUDE.md to add house rules at the top — adopting that file
|
|
173
|
+
* deletes the rules, which is the loss the markers exist to prevent wearing a
|
|
174
|
+
* narrower disguise. And a hand-written file can quote "This file is managed by
|
|
175
|
+
* OpenCastle" in a note to teammates without being ours at all. A file that
|
|
176
|
+
* opens with someone else's writing is theirs: the block is appended instead,
|
|
177
|
+
* and the stale generated text stays visible, which is untidy but recoverable.
|
|
178
|
+
*/
|
|
179
|
+
function looksLikeLegacyGenerated(
|
|
180
|
+
content: string,
|
|
181
|
+
start = BLOCK_START,
|
|
182
|
+
end = BLOCK_END,
|
|
183
|
+
): boolean {
|
|
184
|
+
// A marker anywhere disqualifies the file, which is what the comment above
|
|
185
|
+
// has always claimed and what the code did not do.
|
|
186
|
+
//
|
|
187
|
+
// The fingerprints below are byte-for-byte the *current* release's own output
|
|
188
|
+
// — they have to be, or an upgrade would not recognise its predecessor — so
|
|
189
|
+
// "starts with our header and contains our phrase" is true of every file this
|
|
190
|
+
// tool has ever written, including one whose start marker a merge dropped
|
|
191
|
+
// yesterday. The old gate only asked whether a *complete* block was present.
|
|
192
|
+
// A torn file therefore looked pre-marker, was replaced wholesale, and the
|
|
193
|
+
// notes the user had added below the block went with it. The surviving end
|
|
194
|
+
// marker said exactly where our half stopped and was thrown away.
|
|
195
|
+
//
|
|
196
|
+
// Adoption is for a file with no markers at all. Anything else has a boundary
|
|
197
|
+
// we can read, and reading it is always better than guessing.
|
|
198
|
+
// Markers passed in, not defaulted. The callers work in byte space (see
|
|
199
|
+
// `asBytes`) and our start marker contains an em dash, so the defaults match
|
|
200
|
+
// nothing there — the gate silently passed and a file with a stray marker was
|
|
201
|
+
// adopted and deleted. A guard that cannot fire is worse than none, because
|
|
202
|
+
// the comment above says it did.
|
|
203
|
+
if (blockRegions(content, start, end).length > 0) return false
|
|
204
|
+
if (orphanMarkers(content, start, end).length > 0) return false
|
|
205
|
+
// The phrase has to *open a line*, not merely appear.
|
|
206
|
+
//
|
|
207
|
+
// Our old output began the sentence; a note to teammates does not — "Heads-up
|
|
208
|
+
// for new joiners: This file is managed by OpenCastle, so make your edits in
|
|
209
|
+
// .opencastle/" is a hand-written file that the substring test called ours
|
|
210
|
+
// and replaced wholesale. The heading alone is not a fingerprint either:
|
|
211
|
+
// `# Project Instructions` is a heading a person might reasonably write.
|
|
212
|
+
// Normalised the same way, so the banner comment our old releases opened
|
|
213
|
+
// with is recognised while a sentence that merely mentions us is not.
|
|
214
|
+
const first = firstMeaningfulLine(content)
|
|
215
|
+
const firstOpener = first.replace(/^<!--\s*/, '').replace(/^[^A-Za-z#]+/, '')
|
|
216
|
+
const startsGenerated =
|
|
217
|
+
LEGACY_GENERATED_HEADERS.includes(first) ||
|
|
218
|
+
[...LEGACY_GENERATED_MARKERS, ...LEGACY_BANNER_MARKERS].some((m) => firstOpener.startsWith(m))
|
|
219
|
+
return startsGenerated && hasLegacyOpeningLine(content)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Does some line *open* with one of the phrases those releases wrote?
|
|
224
|
+
*
|
|
225
|
+
* Opening, not merely containing. Our old output either began the line with the
|
|
226
|
+
* phrase or put it alone in a banner comment; a note to teammates has it in the
|
|
227
|
+
* middle of a sentence — "Heads-up for new joiners: This file is managed by
|
|
228
|
+
* OpenCastle, so make your edits in `.opencastle/`" — and the substring test
|
|
229
|
+
* called that file ours and replaced it wholesale.
|
|
230
|
+
*
|
|
231
|
+
* The banner is why a bare `startsWith` on the trimmed line is not enough: the
|
|
232
|
+
* real one reads `<!-- ⚠️ This file is managed by OpenCastle. … -->`, so the
|
|
233
|
+
* comment opener and any decoration in front of the words come off first.
|
|
234
|
+
*/
|
|
235
|
+
function hasLegacyOpeningLine(content: string): boolean {
|
|
236
|
+
return contentLines(content).some((line) => {
|
|
237
|
+
const trimmed = line.trim()
|
|
238
|
+
const inComment = trimmed.startsWith('<!--')
|
|
239
|
+
const opener = trimmed.replace(/^<!--\s*/, '').replace(/^[^A-Za-z#]+/, '')
|
|
240
|
+
if (LEGACY_GENERATED_MARKERS.some((m) => opener.startsWith(m))) return true
|
|
241
|
+
return inComment && LEGACY_BANNER_MARKERS.some((m) => opener.startsWith(m))
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Does this text carry a whole generated body from an older release?
|
|
247
|
+
*
|
|
248
|
+
* Both halves are required: a line that is one of our old headers, *and* one of
|
|
249
|
+
* the phrases those releases wrote underneath it. Either alone is wrong in a
|
|
250
|
+
* direction that has already shipped.
|
|
251
|
+
*
|
|
252
|
+
* Testing the phrase anywhere fired on a file that merely mentioned OpenCastle
|
|
253
|
+
* in a note to teammates. Testing only the *first* line — the correction — was
|
|
254
|
+
* worse, because the population this exists for is exactly the one whose first
|
|
255
|
+
* line is not ours: someone who added their own rules above the generated text
|
|
256
|
+
* and then upgraded. For them the predicate was false, so the warning never
|
|
257
|
+
* came, and their root file quietly ended up holding the previous release's
|
|
258
|
+
* whole instruction set above the new one, with `doctor`, `sync --check` and
|
|
259
|
+
* `status` all reporting health. Meanwhile it fired falsely on any file whose
|
|
260
|
+
* first heading happened to read `# Project Instructions`, telling that user to
|
|
261
|
+
* "delete everything above the OpenCastle block that you did not write" — every
|
|
262
|
+
* byte of which was theirs.
|
|
263
|
+
*
|
|
264
|
+
* Requiring both is what separates a file that contains our old output from one
|
|
265
|
+
* that talks about it.
|
|
266
|
+
*/
|
|
267
|
+
export function carriesLegacyBody(content: string): boolean {
|
|
268
|
+
const lines = contentLines(content).map((l) => l.trim())
|
|
269
|
+
const hasHeader = lines.some((l) => LEGACY_GENERATED_HEADERS.includes(l))
|
|
270
|
+
return hasHeader && hasLegacyOpeningLine(content)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Extract whatever sits outside the managed block. */
|
|
274
|
+
export function stripManagedBlock(content: string): string {
|
|
275
|
+
return stripAllBlocks(content)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Line-start offsets of every occurrence of `marker`, at column 0. */
|
|
279
|
+
function markerOffsets(content: string, marker: string): number[] {
|
|
280
|
+
// A leading byte-order mark does not make the first line stop being the first
|
|
281
|
+
// line. `withoutBom` was added to the legacy predicates and not here, and this
|
|
282
|
+
// is the reader that decides whether a block exists at all: on a fresh install
|
|
283
|
+
// the root file *is* the block, so `BLOCK_START` sits at offset 0, and three
|
|
284
|
+
// BOM bytes in front of it made `blockRegions` find nothing. `sync` then took
|
|
285
|
+
// the append path and wrote a second complete block — the file doubled to two
|
|
286
|
+
// full instruction sets, every surface went green over it, and `remove --all`
|
|
287
|
+
// left 20KB of this release's own output behind, described as an older
|
|
288
|
+
// release's. The untouched twin, one function away from the fix.
|
|
289
|
+
const bom = content.startsWith(BOM_BYTES)
|
|
290
|
+
? BOM_BYTES.length
|
|
291
|
+
: content.startsWith('\ufeff')
|
|
292
|
+
? 1
|
|
293
|
+
: 0
|
|
294
|
+
const out: number[] = []
|
|
295
|
+
let from = 0
|
|
296
|
+
for (;;) {
|
|
297
|
+
const at = content.indexOf(marker, from)
|
|
298
|
+
if (at === -1) return out
|
|
299
|
+
// `\r` as well as `\n`. A file saved with classic Mac line endings has no
|
|
300
|
+
// `\n` at all, so no marker was at a line start, no block was found, and
|
|
301
|
+
// `sync` appended a second one — 20KB becoming 40KB with every surface
|
|
302
|
+
// green. Round 17's BOM defect through a different alphabet entry, in the
|
|
303
|
+
// same reader.
|
|
304
|
+
if (at === bom || content[at - 1] === '\n' || content[at - 1] === '\r') out.push(at)
|
|
305
|
+
from = at + marker.length
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export interface BlockRegion {
|
|
310
|
+
/** Offset of BLOCK_START. */
|
|
311
|
+
start: number
|
|
312
|
+
/** Offset just past BLOCK_END. */
|
|
313
|
+
end: number
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Every *complete* block in the file, in order.
|
|
318
|
+
*
|
|
319
|
+
* Complete means a start marker with an end marker after it and no second start
|
|
320
|
+
* marker in between. A lone start marker is not a block and is deliberately not
|
|
321
|
+
* treated as one: two readers disagreed about what it meant — the writer took
|
|
322
|
+
* everything below it as ours and discarded it, the remover took only the marker
|
|
323
|
+
* line — so one deleted line could either weld a stale 20KB body into the user's
|
|
324
|
+
* file forever or delete prose the user had written below a marker they had
|
|
325
|
+
* merely quoted. Neither reading is safe when we cannot tell which is true, so
|
|
326
|
+
* the ambiguity is reported by `orphanMarkers` and acted on by nobody.
|
|
327
|
+
*
|
|
328
|
+
* No markdown analysis. Four rounds went into guessing, from the prose around a
|
|
329
|
+
* marker, whether it was ours; each guess was wrong somewhere, and every mistake
|
|
330
|
+
* ended the same way — conclude there is no block, append another, grow by 20KB
|
|
331
|
+
* a sync. The invariant is enforced instead: exactly one complete block per file.
|
|
332
|
+
*/
|
|
333
|
+
export function blockRegions(
|
|
334
|
+
content: string,
|
|
335
|
+
startMarker: string = BLOCK_START,
|
|
336
|
+
endMarker: string = BLOCK_END,
|
|
337
|
+
): BlockRegion[] {
|
|
338
|
+
const starts = markerOffsets(content, startMarker)
|
|
339
|
+
const ends = markerOffsets(content, endMarker)
|
|
340
|
+
const regions: BlockRegion[] = []
|
|
341
|
+
|
|
342
|
+
for (const [i, start] of starts.entries()) {
|
|
343
|
+
const next = starts[i + 1] ?? Infinity
|
|
344
|
+
const end = ends.find((e) => e > start && e < next)
|
|
345
|
+
if (end !== undefined) regions.push({ start, end: end + endMarker.length })
|
|
346
|
+
}
|
|
347
|
+
return regions
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Markers that belong to no block — damage, reported rather than interpreted. */
|
|
351
|
+
export function orphanMarkers(
|
|
352
|
+
content: string,
|
|
353
|
+
startMarker: string = BLOCK_START,
|
|
354
|
+
endMarker: string = BLOCK_END,
|
|
355
|
+
): number[] {
|
|
356
|
+
// Both orientations. Tracking only unmatched *starts* meant a file torn the
|
|
357
|
+
// other way — end marker surviving, start deleted — was never named by
|
|
358
|
+
// `doctor` and kept its whole generated body through an uninstall, while the
|
|
359
|
+
// `.gitignore` remover swept stray end markers all along. One format, two
|
|
360
|
+
// readers, again.
|
|
361
|
+
const regions = blockRegions(content, startMarker, endMarker)
|
|
362
|
+
const claimedStarts = new Set(regions.map((r) => r.start))
|
|
363
|
+
const claimedEnds = new Set(regions.map((r) => r.end - endMarker.length))
|
|
364
|
+
return [
|
|
365
|
+
...markerOffsets(content, startMarker).filter((at) => !claimedStarts.has(at)),
|
|
366
|
+
...markerOffsets(content, endMarker).filter((at) => !claimedEnds.has(at)),
|
|
367
|
+
].sort((a, b) => a - b)
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** How long the marker at `at` is — start and end markers differ in length. */
|
|
371
|
+
function markerLengthAt(content: string, at: number, start: string, end: string): number {
|
|
372
|
+
return content.startsWith(start, at) ? start.length : end.length
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Every complete block in the file. All of them are ours.
|
|
377
|
+
*
|
|
378
|
+
* There is no fence reading here, and the absence is the design.
|
|
379
|
+
*
|
|
380
|
+
* Six review rounds each produced a new way for a "is the user merely quoting
|
|
381
|
+
* this?" test to be wrong, and the failures were never small. Fence-adjacency,
|
|
382
|
+
* closed-pair scanning, masked-region scanning, and "the pair contains nothing
|
|
383
|
+
* but blocks" each fixed the previous one's counterexample and shipped its own.
|
|
384
|
+
* Between them they managed to: disown a block mid-file so `sync --check` went
|
|
385
|
+
* permanently red on a remedy that cleared nothing; let an upgrade append a
|
|
386
|
+
* *second* complete 20KB block that `--check`, `doctor` and `status` all called
|
|
387
|
+
* healthy, because the checker counted owned regions and agreed there was one;
|
|
388
|
+
* leave our entire body in the user's file after `remove --all`; and overwrite
|
|
389
|
+
* a line of the user's own prose whenever it shared a fence with the markers.
|
|
390
|
+
* Every one of those was a file an ordinary edit could produce.
|
|
391
|
+
*
|
|
392
|
+
* The markers are the contract, and they say so in their own text —
|
|
393
|
+
* "regenerated by `opencastle sync`, edits here are lost". A complete pair is
|
|
394
|
+
* this tool's, wherever it sits. Someone documenting the convention in a fenced
|
|
395
|
+
* example has that example's body regenerated, or removed as a duplicate with a
|
|
396
|
+
* backup written and a line of output saying so; their prose, their fence and
|
|
397
|
+
* their headings are untouched. That is a cost paid by about one repository, in
|
|
398
|
+
* exchange for the writer, the drift checker, the collapse and the uninstall
|
|
399
|
+
* finally sharing one reading of the word "ours".
|
|
400
|
+
*/
|
|
401
|
+
function ownedRegions(content: string): BlockRegion[] {
|
|
402
|
+
return blockRegions(content)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** The region we maintain: the last one, since every complete pair is ours. */
|
|
406
|
+
function maintainedRegion(content: string): BlockRegion | null {
|
|
407
|
+
const owned = ownedRegions(content)
|
|
408
|
+
return owned.length === 0 ? null : owned[owned.length - 1]
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Cut a block out, taking back only the newline that is certainly ours.
|
|
413
|
+
*
|
|
414
|
+
* The append path writes one newline between the user's content and the block,
|
|
415
|
+
* and the block ends with one. Reclaiming both unconditionally was wrong the
|
|
416
|
+
* moment a file held two blocks: the newline before the *second* one belongs to
|
|
417
|
+
* whatever precedes it, so taking it welded two lines together. In `.gitignore`
|
|
418
|
+
* that turned `.env.local` into part of a comment and stopped it being ignored;
|
|
419
|
+
* in a root file it moved the start marker off column 0, after which
|
|
420
|
+
* `blockRegions` found nothing while `hasManagedBlock` had already said yes, and
|
|
421
|
+
* `sync` threw — having already deleted the framework directories, so the
|
|
422
|
+
* install was left gutted.
|
|
423
|
+
*
|
|
424
|
+
* The block's own trailing newline is always ours. The one before it is taken
|
|
425
|
+
* only when doing so cannot join two lines: when nothing follows, or when what
|
|
426
|
+
* follows starts on its own line anyway.
|
|
427
|
+
*/
|
|
428
|
+
function cutBlock(content: string, start: number, end: number): string {
|
|
429
|
+
const before = content.slice(0, start)
|
|
430
|
+
const after = content.slice(end).replace(/^\r?\n/, '')
|
|
431
|
+
|
|
432
|
+
// Take back the blank line above the block, and only that.
|
|
433
|
+
//
|
|
434
|
+
// The append path writes `<their content>\n` before the block, so when their
|
|
435
|
+
// file ended in a newline the result has a blank line there — one we made,
|
|
436
|
+
// and one that has to go or every install/uninstall cycle adds another.
|
|
437
|
+
//
|
|
438
|
+
// The previous rule was "a newline, if what follows is empty or blank", which
|
|
439
|
+
// is the same text in two different situations. A file whose block was not
|
|
440
|
+
// placed by our append — merged in, hand-moved, written by a release from
|
|
441
|
+
// before the markers — has an ordinary line terminator there, belonging to
|
|
442
|
+
// the user, and we took it: `mine\n<block>` came back as `mine`, and
|
|
443
|
+
// `a\n<block>\n\nb\n` lost the blank line between a and b.
|
|
444
|
+
//
|
|
445
|
+
// Requiring a *blank* line narrows it to what we can actually recognise as
|
|
446
|
+
// ours. The one shape it gets wrong now is the reverse: a file that ended
|
|
447
|
+
// without a trailing newline gains one, because our append and a hand-placed
|
|
448
|
+
// block are byte-identical in that case and nothing in the file can tell them
|
|
449
|
+
// apart. Leaving a newline behind is the better half of an undecidable trade
|
|
450
|
+
// than deleting one of theirs.
|
|
451
|
+
//
|
|
452
|
+
// It cannot weld two lines together, which the round-9 version of this could:
|
|
453
|
+
// after removing one `\n` from a `\n\n`, `before` still ends in a newline.
|
|
454
|
+
if (before.endsWith('\n\n') || before.endsWith('\r\n\r\n')) {
|
|
455
|
+
return before.replace(/\r?\n$/, '') + after
|
|
456
|
+
}
|
|
457
|
+
return before + after
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Cut a stray marker line out, taking back only the newline that terminates it.
|
|
462
|
+
*
|
|
463
|
+
* Removing one from each side, as for a block, welded the user's surrounding
|
|
464
|
+
* lines together — the marker sits on its own line between two lines of theirs,
|
|
465
|
+
* and only its own terminator is ours.
|
|
466
|
+
*/
|
|
467
|
+
function cutLine(content: string, start: number, end: number): string {
|
|
468
|
+
return content.slice(0, start) + content.slice(end).replace(/^\r?\n/, '')
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export function hasManagedBlock(content: string): boolean {
|
|
472
|
+
return ownedRegions(content).length > 0
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* The managed block's body, or null when the file has none.
|
|
477
|
+
*
|
|
478
|
+
* The one reader. The drift checker used to compute this itself with a plain
|
|
479
|
+
* `indexOf`, and the two diverged — the writer maintaining one region while the
|
|
480
|
+
* checker compared another.
|
|
481
|
+
*/
|
|
482
|
+
export function extractManagedBlock(content: string): string | null {
|
|
483
|
+
const region = maintainedRegion(content)
|
|
484
|
+
if (!region) return null
|
|
485
|
+
return content.slice(region.start + BLOCK_START.length, region.end - BLOCK_END.length).trim()
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** How many complete blocks the file holds — more than one is drift. */
|
|
489
|
+
/**
|
|
490
|
+
* What state a co-owned file is in, and who can fix it.
|
|
491
|
+
*
|
|
492
|
+
* The one answer to that question. Five surfaces used to work it out for
|
|
493
|
+
* themselves — `sync`, `sync --check`, `doctor`, `status` and `remove`'s
|
|
494
|
+
* preview — and they disagreed in every combination the reviewers tried:
|
|
495
|
+
* `doctor` green while `sync` was about to delete the user's prose; `doctor`
|
|
496
|
+
* failing forever with a remedy that was a no-op; `sync --check` red on a state
|
|
497
|
+
* the writer refuses by design to change, prescribing the command that refuses;
|
|
498
|
+
* a remedy asserting "markers that do not pair up" about a file whose markers
|
|
499
|
+
* all paired. Each was fixed on its own and the next round found another pair
|
|
500
|
+
* that disagreed, because agreement was being maintained by hand.
|
|
501
|
+
*
|
|
502
|
+
* `fixable` is the fact the surfaces actually need: can any command clear this,
|
|
503
|
+
* or does it need a person? A red check whose remedy cannot work is worse than
|
|
504
|
+
* no check, and it is the failure this branch has shipped most often.
|
|
505
|
+
*/
|
|
506
|
+
/**
|
|
507
|
+
* `torn` is the only one of these that breaks nothing — the block is intact and
|
|
508
|
+
* every command works — so it is the only one weighted as a warning. The others
|
|
509
|
+
* are conditions a person has to see. They are distinct states rather than one
|
|
510
|
+
* shared shape because reusing `torn` for them made both inherit its weight the
|
|
511
|
+
* moment that weight changed.
|
|
512
|
+
*/
|
|
513
|
+
export type FileState =
|
|
514
|
+
| 'clean'
|
|
515
|
+
| 'doubled'
|
|
516
|
+
/** A stray marker *beside* an intact block: harmless, and usually documentation. */
|
|
517
|
+
| 'torn'
|
|
518
|
+
/** A stray marker and no block at all: our body is in there with no delimiter. */
|
|
519
|
+
| 'severed'
|
|
520
|
+
| 'unreducible'
|
|
521
|
+
| 'stale'
|
|
522
|
+
| 'unreadable'
|
|
523
|
+
|
|
524
|
+
export interface FileDiagnosis {
|
|
525
|
+
state: FileState
|
|
526
|
+
/** True when a command can clear it; false when only a person can. */
|
|
527
|
+
fixable: boolean
|
|
528
|
+
/** What to tell the user. Empty when there is nothing wrong. */
|
|
529
|
+
detail: string
|
|
530
|
+
/** The remedy, as a command when one works and as instructions when none does. */
|
|
531
|
+
fix: string
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export function diagnoseManagedFile(
|
|
535
|
+
content: string,
|
|
536
|
+
startMarker: string = BLOCK_START,
|
|
537
|
+
endMarker: string = BLOCK_END,
|
|
538
|
+
/**
|
|
539
|
+
* How to tell whether a body of ours is in this file.
|
|
540
|
+
*
|
|
541
|
+
* Defaulted to the root-file fingerprints, which is why `severed` could never
|
|
542
|
+
* fire for `.gitignore`: the writer refused to touch such a file while the
|
|
543
|
+
* classifier called it ordinary drift, so both surfaces prescribed a `sync`
|
|
544
|
+
* that printed "✓ Updated .gitignore" and changed nothing, forever. The
|
|
545
|
+
* writer already had the right predicate; it just was not the classifier's.
|
|
546
|
+
*/
|
|
547
|
+
bodyPresent: (text: string) => boolean = carriesLegacyBody,
|
|
548
|
+
): FileDiagnosis {
|
|
549
|
+
const blocks = blockRegions(content, startMarker, endMarker).length
|
|
550
|
+
const strays = orphanMarkers(content, startMarker, endMarker).length
|
|
551
|
+
|
|
552
|
+
if (blocks > 1 && strays > 0) {
|
|
553
|
+
// The writer will not reduce this: cutting a block here can bring a stray
|
|
554
|
+
// start marker next to a stray end marker and sweep the user's own text
|
|
555
|
+
// into the pair. No command will touch it, so no command may claim to.
|
|
556
|
+
return {
|
|
557
|
+
state: 'unreducible',
|
|
558
|
+
fixable: false,
|
|
559
|
+
detail: `holds ${blocks} OpenCastle blocks and ${strays} marker(s) that pair with nothing`,
|
|
560
|
+
fix: 'delete the blocks you do not want, keeping one start/end pair — this one needs a person',
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
if (blocks > 1) {
|
|
564
|
+
return {
|
|
565
|
+
state: 'doubled',
|
|
566
|
+
fixable: true,
|
|
567
|
+
detail: `holds ${blocks} OpenCastle blocks`,
|
|
568
|
+
fix: 'opencastle sync',
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
// A stray marker with no block is not the same as a stray marker beside one.
|
|
572
|
+
//
|
|
573
|
+
// With a block present the file is intact — the block is maintained, the
|
|
574
|
+
// stray is left alone, and the commonest source of that shape is a file
|
|
575
|
+
// documenting the convention. With *no* block, the markers that delimited our
|
|
576
|
+
// body are gone but the body is almost certainly still there: appending
|
|
577
|
+
// writes a second complete instruction set underneath the first, which is
|
|
578
|
+
// what `sync` did — 20KB becoming 40KB, two sets of rules for the assistant,
|
|
579
|
+
// and every surface reporting health because one valid block now existed.
|
|
580
|
+
// Calling both of these "torn" is what let the second inherit the first's
|
|
581
|
+
// "breaks nothing".
|
|
582
|
+
// And only when a body of ours is actually in there. A stray marker with no
|
|
583
|
+
// block *and no generated text* is someone documenting the convention before
|
|
584
|
+
// they have ever installed — refusing to write to that file would mean the
|
|
585
|
+
// tool could not install at all. What makes it severed is our body sitting
|
|
586
|
+
// there with its delimiters gone.
|
|
587
|
+
if (strays > 0 && blocks === 0 && bodyPresent(content)) {
|
|
588
|
+
return {
|
|
589
|
+
state: 'severed',
|
|
590
|
+
fixable: false,
|
|
591
|
+
detail: `has ${strays} OpenCastle marker(s) and no complete block — the text beside them` +
|
|
592
|
+
' is probably generated output with nothing to delimit it',
|
|
593
|
+
fix:
|
|
594
|
+
'restore the missing marker, or delete the generated text beside it —' +
|
|
595
|
+
' this one needs a person, and until then sync will not write to the file',
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (strays > 0) {
|
|
599
|
+
return {
|
|
600
|
+
state: 'torn',
|
|
601
|
+
fixable: false,
|
|
602
|
+
detail: `has ${strays} OpenCastle marker(s) that pair with nothing`,
|
|
603
|
+
fix:
|
|
604
|
+
'text beside that marker may be stale generated output, and only you can tell —' +
|
|
605
|
+
' remove it, or restore the missing marker; this one needs a person',
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return { state: 'clean', fixable: true, detail: '', fix: '' }
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export function countManagedBlocks(content: string): number {
|
|
612
|
+
// Owned, not total. Counting a quoted example as a block made `sync --check`
|
|
613
|
+
// permanently red on a file `collapseExtraBlocks` deliberately will not
|
|
614
|
+
// change — a failure whose prescribed fix could never clear it.
|
|
615
|
+
return ownedRegions(content).length
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function wrap(body: string): string {
|
|
619
|
+
return `${BLOCK_START}\n\n${body.trim()}\n\n${BLOCK_END}\n`
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const BACKUP_SUFFIX = '.opencastle-backup'
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Keep the previous contents beside a file we are about to change destructively.
|
|
626
|
+
* Taken at most once per run, so a second call cannot discard what the first saved.
|
|
627
|
+
*/
|
|
628
|
+
const backedUpThisRun = new Set<string>()
|
|
629
|
+
|
|
630
|
+
async function backUp(path: string, contents: string): Promise<void> {
|
|
631
|
+
// Once per run, so a second destructive step cannot discard what the first
|
|
632
|
+
// saved — but not once ever, which left a stale backup and no copy of what a
|
|
633
|
+
// later command actually replaced.
|
|
634
|
+
if (backedUpThisRun.has(path)) return
|
|
635
|
+
backedUpThisRun.add(path)
|
|
636
|
+
await writeBytes(`${path}${BACKUP_SUFFIX}`, contents)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Everything outside *every* block — what would be left if all of ours came out.
|
|
641
|
+
*
|
|
642
|
+
* The same function the uninstall uses, so "does this file hold anything of the
|
|
643
|
+
* user's" is answered the same way it will be acted on. It used to strip only the
|
|
644
|
+
* maintained block and then re-scan for strays — the two-pass shape that could
|
|
645
|
+
* promote a pair of orphans into a region and delete what lay between.
|
|
646
|
+
*/
|
|
647
|
+
function stripAllBlocks(content: string, start = BLOCK_START, end = BLOCK_END): string {
|
|
648
|
+
// What comes out is decided once, from the file as it stands, and the cuts
|
|
649
|
+
// are applied back to front so the offsets stay valid.
|
|
650
|
+
//
|
|
651
|
+
// Re-scanning after each cut looked equivalent and was not. Removing the
|
|
652
|
+
// block can bring a stray start marker above it next to a stray end marker
|
|
653
|
+
// below it, and the next scan reads that pair as a *new* complete block — so
|
|
654
|
+
// the user's text between the two strays went out with it. On a file torn on
|
|
655
|
+
// both sides (a "keep both sides" merge does this) `remove --all` deleted
|
|
656
|
+
// their content and then deleted the file for being empty. Found by seeded
|
|
657
|
+
// round-trip testing; no hand-written fixture had a file torn on both sides
|
|
658
|
+
// at once, which is why eight rounds of review walked past it.
|
|
659
|
+
return applyCuts(content, cutList(content, start, end))
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
interface Cut {
|
|
663
|
+
start: number
|
|
664
|
+
end: number
|
|
665
|
+
/** A marker line with no partner: take the line, never anything around it. */
|
|
666
|
+
lone: boolean
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** Every byte range removal is entitled to, computed against `content` alone. */
|
|
670
|
+
function cutList(content: string, start = BLOCK_START, end = BLOCK_END): Cut[] {
|
|
671
|
+
return [
|
|
672
|
+
...blockRegions(content, start, end).map((r) => ({ start: r.start, end: r.end, lone: false })),
|
|
673
|
+
...orphanMarkers(content, start, end).map((at) => ({
|
|
674
|
+
start: at,
|
|
675
|
+
end: at + markerLengthAt(content, at, start, end),
|
|
676
|
+
lone: true,
|
|
677
|
+
})),
|
|
678
|
+
].sort((a, b) => b.start - a.start)
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function applyCuts(content: string, cuts: Cut[]): string {
|
|
682
|
+
let text = content
|
|
683
|
+
for (const cut of cuts) {
|
|
684
|
+
text = cut.lone
|
|
685
|
+
? cutLine(text, cut.start, cut.end)
|
|
686
|
+
: cutBlock(text, cut.start, cut.end)
|
|
687
|
+
}
|
|
688
|
+
return text
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Write `body` into `path` as a managed block.
|
|
695
|
+
*
|
|
696
|
+
* - No file: write the block alone.
|
|
697
|
+
* - File with a block: replace only the block.
|
|
698
|
+
* - File this tool generated before markers existed: replace it wholesale.
|
|
699
|
+
* - Any other file: keep it verbatim, append the block.
|
|
700
|
+
*/
|
|
701
|
+
export async function writeManagedBlock(path: string, body: string): Promise<MergeResult> {
|
|
702
|
+
// Byte space from here down — see `asBytes`. Our own block is converted in;
|
|
703
|
+
// the user's half is never decoded, so nothing of theirs can be lost to a
|
|
704
|
+
// codec on the way through.
|
|
705
|
+
const block = asBytes(wrap(body))
|
|
706
|
+
const S = BLOCK_START_BYTES
|
|
707
|
+
const E = BLOCK_END_BYTES
|
|
708
|
+
|
|
709
|
+
if (!existsSync(path)) {
|
|
710
|
+
await writeBytes(path, block)
|
|
711
|
+
return { action: 'created', preservedUserContent: false }
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const existing = await readBytes(path)
|
|
715
|
+
|
|
716
|
+
// Any complete region is worth examining, not only one we already recognise
|
|
717
|
+
// as ours. Gating on `hasManagedBlock` — "is some region unquoted" — meant a
|
|
718
|
+
// block the fence classifier had mislabelled was never even considered, so
|
|
719
|
+
// the file went straight to the append path and gained a duplicate on every
|
|
720
|
+
// single sync.
|
|
721
|
+
//
|
|
722
|
+
// `current` is what is on disk from here on. The collapse below can write,
|
|
723
|
+
// and the append path further down must build on that rather than on the
|
|
724
|
+
// bytes we read at the top, or it silently reinstates what was collapsed.
|
|
725
|
+
const regions = blockRegions(existing, S, E)
|
|
726
|
+
const orphans = orphanMarkers(existing, S, E)
|
|
727
|
+
if (regions.length > 0) {
|
|
728
|
+
const keep = regions[regions.length - 1]
|
|
729
|
+
|
|
730
|
+
// Extra blocks are removed only when the file has no unpaired markers.
|
|
731
|
+
//
|
|
732
|
+
// Cutting a region in a file that also carries strays can bring a stray
|
|
733
|
+
// start marker next to a stray end marker, and the next scan reads that
|
|
734
|
+
// pair as a block of ours — with the user's text between the two strays
|
|
735
|
+
// inside it. `stripAllBlocks` was fixed by deciding its cuts once; that was
|
|
736
|
+
// not enough, because this function wrote the promoted file to disk and the
|
|
737
|
+
// *next* command re-scanned it. Deferring the deletion by one invocation is
|
|
738
|
+
// not preventing it.
|
|
739
|
+
//
|
|
740
|
+
// So: no cut. A file torn on both sides keeps both blocks, `sync --check`
|
|
741
|
+
// reports it, and `doctor` names it as something only a person can resolve
|
|
742
|
+
// — the same policy this module already applies to a lone marker. Guessing
|
|
743
|
+
// has cost the user their prose in three separate rounds.
|
|
744
|
+
const doomed = orphans.length === 0 ? regions.slice(0, -1) : []
|
|
745
|
+
|
|
746
|
+
// Every edit computed against `existing` and applied back to front, so no
|
|
747
|
+
// step ever reads a partly-cut file. This is the whole lesson of the last
|
|
748
|
+
// three rounds, stated once.
|
|
749
|
+
type Edit = { start: number; end: number; text?: string }
|
|
750
|
+
const edits: Edit[] = [
|
|
751
|
+
...doomed.map((r) => ({ start: r.start, end: r.end })),
|
|
752
|
+
{ start: keep.start, end: keep.end, text: block.trimEnd() },
|
|
753
|
+
].sort((a, b) => b.start - a.start)
|
|
754
|
+
|
|
755
|
+
let next = existing
|
|
756
|
+
for (const edit of edits) {
|
|
757
|
+
next =
|
|
758
|
+
edit.text === undefined
|
|
759
|
+
? cutBlock(next, edit.start, edit.end)
|
|
760
|
+
: next.slice(0, edit.start) + edit.text + next.slice(edit.end)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
const hadUserContent = stripAllBlocks(existing, S, E).trim().length > 0
|
|
764
|
+
const damaged = orphans.length > 0 && regions.length > 1
|
|
765
|
+
// Checked outside our own blocks, so the body we are about to write cannot
|
|
766
|
+
// match itself — and checked on this path at all, which it was not. The
|
|
767
|
+
// warning only ever fired while appending, so an upgrade announced the
|
|
768
|
+
// stale half once, at most, and never again on any later sync.
|
|
769
|
+
const stale = carriesLegacyBody(stripAllBlocks(existing, S, E))
|
|
770
|
+
if (next === existing) {
|
|
771
|
+
return {
|
|
772
|
+
action: 'unchanged',
|
|
773
|
+
preservedUserContent: hadUserContent,
|
|
774
|
+
...(orphans.length > 0 && { orphanMarker: true }),
|
|
775
|
+
...(damaged && { damaged: true }),
|
|
776
|
+
...(stale && { staleGeneratedContent: true }),
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (doomed.length > 0) await backUp(path, existing)
|
|
780
|
+
await writeBytes(path, next)
|
|
781
|
+
return {
|
|
782
|
+
action: doomed.length > 0 ? 'repaired' : 'updated',
|
|
783
|
+
preservedUserContent: hadUserContent,
|
|
784
|
+
...(orphans.length > 0 && { orphanMarker: true }),
|
|
785
|
+
...(damaged && { damaged: true }),
|
|
786
|
+
...(stale && { staleGeneratedContent: true }),
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const current = existing
|
|
791
|
+
|
|
792
|
+
if (looksLikeLegacyGenerated(current, S, E)) {
|
|
793
|
+
// The one operation here that discards anything: a previous release wrote
|
|
794
|
+
// this whole file, so replacing it is right — but if someone appended notes
|
|
795
|
+
// below the generated part, there is no marker to tell us where theirs
|
|
796
|
+
// began. Keep a copy next to it rather than being clever, and let the user
|
|
797
|
+
// decide.
|
|
798
|
+
await backUp(path, current)
|
|
799
|
+
await writeBytes(path, block)
|
|
800
|
+
return { action: 'adopted', preservedUserContent: false }
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// Never append into a severed file. Our body is in there with its delimiters
|
|
804
|
+
// gone, so a second one goes underneath the first and the assistant reads
|
|
805
|
+
// both. Nothing is written until a person resolves it.
|
|
806
|
+
if (orphanMarkers(current, S, E).length > 0 && carriesLegacyBody(current)) {
|
|
807
|
+
return {
|
|
808
|
+
action: 'unchanged',
|
|
809
|
+
preservedUserContent: current.trim().length > 0,
|
|
810
|
+
orphanMarker: true,
|
|
811
|
+
severed: true,
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// The user's file predates OpenCastle. Keep every byte of it — no trimming, no
|
|
816
|
+
// reflowing — and start the block on the next line.
|
|
817
|
+
// Exactly one newline between their content and our block, whether or not
|
|
818
|
+
// their file ended in one. Normalising first ("add a newline if missing, then
|
|
819
|
+
// a blank line") destroyed the information that it did not end in one, so the
|
|
820
|
+
// cut could never restore it and every round trip grew the file by a byte.
|
|
821
|
+
const preamble = current.length > 0 ? `${current}\n` : ''
|
|
822
|
+
await writeBytes(path, preamble + block)
|
|
823
|
+
return {
|
|
824
|
+
action: 'appended',
|
|
825
|
+
preservedUserContent: current.trim().length > 0,
|
|
826
|
+
// A start marker with no partner. We will not guess what it delimits, but
|
|
827
|
+
// the user should know their file has one, because the tool cannot maintain
|
|
828
|
+
// whatever sits below it and will not remove it on uninstall.
|
|
829
|
+
...(orphanMarkers(current, S, E).length > 0 && { orphanMarker: true }),
|
|
830
|
+
// Their own writing came first, so we appended rather than adopting — but
|
|
831
|
+
// the file also carries our old output somewhere below, and that stale half
|
|
832
|
+
// still names agents and skills that no longer exist. The agent reads both.
|
|
833
|
+
// Adoption exists to prevent exactly that, so when we decline to adopt, the
|
|
834
|
+
// user has to be told what is now doubled.
|
|
835
|
+
//
|
|
836
|
+
// Tested against the file's *opening* line, not against the whole file. A
|
|
837
|
+
// bare substring search fired on a CLAUDE.md that merely mentioned "This
|
|
838
|
+
// file is managed by OpenCastle" in a note to teammates, and the sync
|
|
839
|
+
// wording of the warning then told them to "delete everything above the
|
|
840
|
+
// OpenCastle block that you did not write" — advice that, followed, deletes
|
|
841
|
+
// their file. `looksLikeLegacyGenerated` was hardened against exactly this
|
|
842
|
+
// substring test two functions up; this line was the copy that was not.
|
|
843
|
+
...(carriesLegacyBody(current) && { staleGeneratedContent: true }),
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Undo only our half of a co-owned file.
|
|
849
|
+
*
|
|
850
|
+
* Removes the managed block. If the user wrote nothing else, the file is deleted;
|
|
851
|
+
* otherwise their content is kept. This is what `init` re-run, the orphaned-install
|
|
852
|
+
* overwrite, and `remove --all` must call instead of unlinking — those three paths
|
|
853
|
+
* treated merged files as wholly generated and destroyed people's own writing.
|
|
854
|
+
*/
|
|
855
|
+
/**
|
|
856
|
+
* What `stripManagedBlockFromFile` will do to this content, without doing it.
|
|
857
|
+
*
|
|
858
|
+
* Exists so `remove`'s preview and `remove` itself cannot disagree. They did:
|
|
859
|
+
* the preview assumed every co-owned file survives and printed "your own
|
|
860
|
+
* writing stays" over files that were about to be deleted.
|
|
861
|
+
*/
|
|
862
|
+
/**
|
|
863
|
+
* What `stripManagedBlockFromFile` would do to `path`, reading it the same way.
|
|
864
|
+
*
|
|
865
|
+
* The preview used to decode as UTF-8 while the action read bytes, and the two
|
|
866
|
+
* then disagreed about whether anything of the user's was left: a file whose
|
|
867
|
+
* user half was a single `0xA0` is whitespace to `trim()` in byte space and
|
|
868
|
+
* U+FFFD — not whitespace — in UTF-8 space. The preview promised "your own
|
|
869
|
+
* writing stays" and the action deleted the file, with no backup. One question,
|
|
870
|
+
* one reader, and the reader has to be the one that acts.
|
|
871
|
+
*/
|
|
872
|
+
export async function predictStripFile(path: string): Promise<{
|
|
873
|
+
outcome: 'stripped' | 'deleted'
|
|
874
|
+
legacyGenerated: boolean
|
|
875
|
+
/** A superseded instruction set of ours would still be there afterwards. */
|
|
876
|
+
staleRemains: boolean
|
|
877
|
+
}> {
|
|
878
|
+
const bytes = await readBytes(path)
|
|
879
|
+
const predicted = predictStrip(bytes, BLOCK_START_BYTES, BLOCK_END_BYTES)
|
|
880
|
+
return {
|
|
881
|
+
...predicted,
|
|
882
|
+
staleRemains:
|
|
883
|
+
predicted.outcome === 'stripped' &&
|
|
884
|
+
carriesLegacyBody(stripAllBlocks(bytes, BLOCK_START_BYTES, BLOCK_END_BYTES)),
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
export function predictStrip(
|
|
889
|
+
content: string,
|
|
890
|
+
start = BLOCK_START,
|
|
891
|
+
end = BLOCK_END,
|
|
892
|
+
): {
|
|
893
|
+
outcome: 'stripped' | 'deleted'
|
|
894
|
+
/** True when the file is ours from an older release, so a backup is written. */
|
|
895
|
+
legacyGenerated: boolean
|
|
896
|
+
} {
|
|
897
|
+
if (
|
|
898
|
+
blockRegions(content, start, end).length === 0 &&
|
|
899
|
+
looksLikeLegacyGenerated(content, start, end)
|
|
900
|
+
) {
|
|
901
|
+
return { outcome: 'deleted', legacyGenerated: true }
|
|
902
|
+
}
|
|
903
|
+
// The same reading `stripManagedBlockFromFile` takes, by calling the same
|
|
904
|
+
// function — the two diverged once by sharing a formula instead of a call.
|
|
905
|
+
const remainder = stripAllBlocks(content, start, end)
|
|
906
|
+
return {
|
|
907
|
+
outcome: remainder.trim().length === 0 ? 'deleted' : 'stripped',
|
|
908
|
+
// Only the legacy branch above writes a backup, so only it may claim one.
|
|
909
|
+
legacyGenerated: false,
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
export async function stripManagedBlockFromFile(
|
|
914
|
+
path: string,
|
|
915
|
+
): Promise<'deleted' | 'stripped' | 'absent'> {
|
|
916
|
+
if (!existsSync(path)) return 'absent'
|
|
917
|
+
// Bytes, as in the writer: the user's half is handed back exactly as found.
|
|
918
|
+
const existing = await readBytes(path)
|
|
919
|
+
|
|
920
|
+
// A start marker with no partner is left exactly where it is, minus the marker
|
|
921
|
+
// line itself.
|
|
922
|
+
//
|
|
923
|
+
// Three attempts at interpreting one have now shipped. Taking the body below
|
|
924
|
+
// it deleted prose someone had written under a marker they merely quoted.
|
|
925
|
+
// Taking nothing left 20KB of stale instructions after an uninstall. Splicing
|
|
926
|
+
// from the marker to the end of our block did both — it deleted the user's
|
|
927
|
+
// rules when the marker sat above the block, and duplicated their paragraphs
|
|
928
|
+
// when it sat below, because the two slices overlapped.
|
|
929
|
+
//
|
|
930
|
+
// "`remove` only runs on an install" justifies claiming the marker line, which
|
|
931
|
+
// is text we wrote. It does not justify claiming bytes on the far side of a
|
|
932
|
+
// block whose boundaries are known exactly. So: complete blocks and marker
|
|
933
|
+
// lines, both unambiguous, and nothing else — in every path, always.
|
|
934
|
+
//
|
|
935
|
+
// The cost is that a genuinely torn file keeps a stale body. That is paid in
|
|
936
|
+
// the open: `doctor` warns and names the file, because only a human can tell
|
|
937
|
+
// their text from ours once the marker is gone.
|
|
938
|
+
// A file a pre-marker release generated in full is unambiguous in a way a torn
|
|
939
|
+
// one is not: it carries no markers at all, and its whole contents are ours.
|
|
940
|
+
if (
|
|
941
|
+
blockRegions(existing, BLOCK_START_BYTES, BLOCK_END_BYTES).length === 0 &&
|
|
942
|
+
looksLikeLegacyGenerated(existing, BLOCK_START_BYTES, BLOCK_END_BYTES)
|
|
943
|
+
) {
|
|
944
|
+
await backUp(path, existing)
|
|
945
|
+
await rm(path, { force: true })
|
|
946
|
+
return 'deleted'
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const remainder = stripAllBlocks(existing, BLOCK_START_BYTES, BLOCK_END_BYTES)
|
|
950
|
+
if (remainder.trim().length === 0) {
|
|
951
|
+
await rm(path, { force: true })
|
|
952
|
+
return 'deleted'
|
|
953
|
+
}
|
|
954
|
+
// Written exactly as it came out. Appending a newline "to be tidy" meant a
|
|
955
|
+
// file that never ended in one came back a byte longer, which is not what
|
|
956
|
+
// "byte for byte" means.
|
|
957
|
+
await writeBytes(path, remainder)
|
|
958
|
+
return 'stripped'
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Record a root-file merge into a `CopyResults`, once, for every adapter.
|
|
963
|
+
*
|
|
964
|
+
* Five call sites across three adapter families each decided by hand which
|
|
965
|
+
* fields of the merge result to forward, and the answer differed at every one.
|
|
966
|
+
* `repaired` reached three of them, `damaged` reached one, and each omission
|
|
967
|
+
* meant the user was told nothing on the targets that missed it — including
|
|
968
|
+
* about the backup that is the only way to recover a collapse. Both were found
|
|
969
|
+
* by reviewers, one round apart, as separate bugs; they are the same bug, and
|
|
970
|
+
* it is the hand-wiring.
|
|
971
|
+
*
|
|
972
|
+
* A field added to `MergeResult` now reaches every adapter by construction.
|
|
973
|
+
*/
|
|
974
|
+
export function recordMerge(
|
|
975
|
+
results: {
|
|
976
|
+
copied: string[]
|
|
977
|
+
skipped: string[]
|
|
978
|
+
created: string[]
|
|
979
|
+
adopted?: string[]
|
|
980
|
+
repaired?: string[]
|
|
981
|
+
staleRoots?: string[]
|
|
982
|
+
tornRoots?: string[]
|
|
983
|
+
damagedRoots?: string[]
|
|
984
|
+
severedRoots?: string[]
|
|
985
|
+
},
|
|
986
|
+
path: string,
|
|
987
|
+
merge: MergeResult,
|
|
988
|
+
): void {
|
|
989
|
+
if (merge.staleGeneratedContent) (results.staleRoots ??= []).push(path)
|
|
990
|
+
if (merge.orphanMarker) (results.tornRoots ??= []).push(path)
|
|
991
|
+
if (merge.damaged) (results.damagedRoots ??= []).push(path)
|
|
992
|
+
// Set by the writer and read by nobody, so a root file `sync` had declined to
|
|
993
|
+
// write to was announced with the *torn* wording — "text beside it may be
|
|
994
|
+
// stale output; only you can tell" — beside "✓ Updated 0 framework files",
|
|
995
|
+
// while `doctor` and the gate both said plainly that nothing was written.
|
|
996
|
+
if (merge.severed) (results.severedRoots ??= []).push(path)
|
|
997
|
+
|
|
998
|
+
if (merge.action === 'adopted') {
|
|
999
|
+
results.created.push(path)
|
|
1000
|
+
;(results.adopted ??= []).push(path)
|
|
1001
|
+
} else if (merge.action === 'repaired') {
|
|
1002
|
+
results.created.push(path)
|
|
1003
|
+
;(results.repaired ??= []).push(path)
|
|
1004
|
+
} else if (merge.action === 'created') {
|
|
1005
|
+
results.created.push(path)
|
|
1006
|
+
} else if (merge.action === 'unchanged') {
|
|
1007
|
+
results.skipped.push(path)
|
|
1008
|
+
} else {
|
|
1009
|
+
results.copied.push(path)
|
|
1010
|
+
}
|
|
1011
|
+
}
|