sinapse-ai 1.19.1 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/CLAUDE.md +2 -2
- package/.claude/hooks/enforce-delegation.cjs +32 -36
- package/.claude/rules/agent-handoff.md +10 -21
- package/.claude/rules/mandatory-delegation.md +1 -1
- package/.claude/rules/token-economy.md +12 -5
- package/.sinapse-ai/constitution.md +2 -0
- package/.sinapse-ai/core/atlas/flows-pt.js +6 -0
- package/.sinapse-ai/core/atlas/flows.js +7 -0
- package/.sinapse-ai/core/atlas/render-markdown.js +8 -0
- package/.sinapse-ai/core/doctor/checks/constitution-consistency.js +7 -0
- package/.sinapse-ai/core/execution/autonomous-build-loop.js +10 -4
- package/.sinapse-ai/core/execution/build-orchestrator.js +104 -2
- package/.sinapse-ai/core/execution/context-injector.js +2 -0
- package/.sinapse-ai/core/execution/parallel-executor.js +2 -0
- package/.sinapse-ai/core/execution/parallel-monitor.js +2 -0
- package/.sinapse-ai/core/execution/rate-limit-manager.js +2 -0
- package/.sinapse-ai/core/execution/result-aggregator.js +2 -0
- package/.sinapse-ai/core/execution/semantic-merge-engine.js +2 -0
- package/.sinapse-ai/core/execution/wave-executor.js +2 -0
- package/.sinapse-ai/core/health-check/checks/project/constitution-consistency.js +12 -1
- package/.sinapse-ai/core/orchestration/cli-commands.js +121 -4
- package/.sinapse-ai/core/orchestration/executors/epic-4-executor.js +25 -4
- package/.sinapse-ai/core/orchestration/executors/epic-6-executor.js +53 -2
- package/.sinapse-ai/core/orchestration/gate-evaluator.js +78 -3
- package/.sinapse-ai/core/orchestration/index.js +3 -0
- package/.sinapse-ai/core/orchestration/master-orchestrator.js +116 -18
- package/.sinapse-ai/core/synapse/context/context-tracker.js +118 -11
- package/.sinapse-ai/core/synapse/engine.js +18 -3
- package/.sinapse-ai/core/synapse/layers/l0-constitution.js +189 -8
- package/.sinapse-ai/core/synapse/output/formatter.js +65 -25
- package/.sinapse-ai/core-config.yaml +8 -1
- package/.sinapse-ai/data/entity-registry.yaml +69 -68
- package/.sinapse-ai/development/agents/developer.md +18 -34
- package/.sinapse-ai/development/agents/snps-orqx.md +5 -5
- package/.sinapse-ai/development/agents/sprint-lead.md +20 -36
- package/.sinapse-ai/development/scripts/agent-exit-hooks.js +13 -4
- package/.sinapse-ai/infrastructure/integrations/ai-providers/README.md +2 -2
- package/.sinapse-ai/install-manifest.yaml +73 -73
- package/.sinapse-ai/product/templates/activation-instructions-template.md +72 -185
- package/.sinapse-ai/product/templates/ide-rules/claude-rules.md +45 -274
- package/.sinapse-ai/product/templates/statusline/agent-badges.json +2 -2
- package/.sinapse-ai/product/templates/statusline/statusline-script.js +5 -3
- package/.sinapse-ai/workflow-intelligence/engine/wave-analyzer.js +8 -0
- package/CHANGELOG.md +42 -1
- package/README.md +10 -0
- package/bin/cli.js +29 -0
- package/bin/commands/help.js +5 -0
- package/bin/commands/uninstall.js +5 -0
- package/bin/postinstall.js +7 -0
- package/bin/sinapse.js +149 -1
- package/docs/framework/atlas/OPERATING-ATLAS.md +3 -3
- package/docs/framework/atlas/atlas-data.json +6 -6
- package/docs/framework/atlas/atlas.html +2 -2
- package/docs/framework/source-tree.md +1 -1
- package/docs/framework/workflow-engine-status.md +70 -0
- package/docs/guides/ade-guide.md +4 -2
- package/docs/guides/api-reference.md +2 -0
- package/docs/guides/permission-modes.md +2 -0
- package/docs/guides/user-guide.md +21 -7
- package/docs/guides/workflows/AUTO-WORKTREE-WORKFLOW.md +2 -2
- package/docs/pt/architecture/ade-architecture.md +2 -0
- package/docs/pt/architecture/high-level-architecture.md +1 -1
- package/docs/pt/guides/ade-guide.md +4 -2
- package/docs/pt/guides/api-reference.md +2 -0
- package/docs/pt/guides/permission-modes.md +2 -0
- package/docs/pt/guides/user-guide.md +21 -7
- package/docs/pt/platforms/claude-code.md +2 -2
- package/docs/sinapse-workflows/auto-worktree-workflow.md +2 -2
- package/package.json +1 -1
- package/packages/installer/src/config/configure-environment.js +6 -0
- package/packages/installer/src/config/templates/core-config-template.js +43 -1
- package/packages/installer/src/installer/synapse-runtime-installer.js +148 -0
- package/packages/installer/src/wizard/i18n.js +294 -0
- package/packages/installer/src/wizard/index.js +26 -0
- package/packages/installer/src/wizard/validation/troubleshooting-system.js +60 -131
- package/scripts/bracket-report.js +103 -0
- package/scripts/validate-agent-codenames.js +168 -37
- package/scripts/validate-install-docs.js +23 -2
- package/sinapse/agents/sinapse-orqx.md +3 -3
- package/sinapse/agents/snps-orqx.md +3 -3
- package/sinapse/knowledge-base/routing-catalog.md +1 -1
- package/sinapse/tasks/diagnose-and-route.md +1 -1
- package/squads/claude-code-mastery/CHANGELOG.md +1 -1
- package/squads/claude-code-mastery/README.md +6 -6
- package/squads/claude-code-mastery/agents/claude-mastery-chief.md +7 -7
- package/squads/claude-code-mastery/agents/roadmap-sentinel.md +9 -9
- package/squads/claude-code-mastery/agents/swarm-orqx.md +5 -5
- package/squads/claude-code-mastery/data/claude-code-quick-ref.yaml +1 -1
- package/squads/claude-code-mastery/knowledge-base/claude-code-internals-deep.md +4 -4
- package/squads/claude-code-mastery/knowledge-base/claude-code-internals-reference.md +4 -4
- package/squads/claude-code-mastery/tasks/create-agent-definition.md +6 -6
- package/squads/claude-code-mastery/tasks/create-team-topology.md +3 -3
- package/squads/claude-code-mastery/tasks/diagnose.md +1 -1
- package/squads/claude-code-mastery/tasks/parallel-decomposition.md +1 -1
- package/squads/claude-code-mastery/tasks/worktree-strategy.md +1 -1
- package/squads/squad-animations/README.md +1 -1
- package/squads/squad-animations/agents/animation-interpreter.md +5 -5
- package/squads/squad-animations/agents/animations-orqx.md +6 -6
- package/squads/squad-animations/squad.yaml +1 -1
- package/squads/squad-animations/tasks/analyze-reference-animation.md +1 -1
- package/squads/squad-animations/tasks/build-animation-brief.md +1 -1
- package/squads/squad-animations/tasks/create-animation-storyboard.md +1 -1
- package/squads/squad-animations/tasks/cross-reference-brand-system.md +1 -1
- package/squads/squad-animations/tasks/extract-animation-intent.md +1 -1
- package/squads/squad-animations/tasks/generate-motion-vocabulary.md +1 -1
- package/squads/squad-animations/tasks/identify-website-animation.md +1 -1
- package/squads/squad-animations/tasks/interpret-animation-prompt.md +1 -1
- package/squads/squad-animations/tasks/refine-animation-specification.md +1 -1
- package/squads/squad-animations/tasks/translate-feeling-to-parameters.md +1 -1
- package/squads/squad-animations/tasks/validate-animation-feasibility.md +1 -1
- package/squads/squad-animations/workflows/prompt-to-animation-cycle.yaml +2 -2
- package/squads/squad-brand/agents/brand-auditor.md +1 -1
- package/squads/squad-brand/agents/brand-compiler.md +1 -1
- package/squads/squad-brand/agents/brand-motion-vfx.md +5 -5
- package/squads/squad-brand/agents/brand-orqx.md +2 -2
- package/squads/squad-brand/agents/brand-sonic-designer.md +1 -1
- package/squads/squad-brand/squad.yaml +1 -1
- package/squads/squad-brand/tasks/create-animation-library.md +1 -1
- package/squads/squad-brand/tasks/create-brand-characters.md +2 -2
- package/squads/squad-brand/tasks/create-event-branding.md +2 -2
- package/squads/squad-brand/tasks/create-micro-interactions.md +1 -1
- package/squads/squad-brand/tasks/create-page-transitions.md +1 -1
- package/squads/squad-brand/tasks/create-video-templates.md +1 -1
- package/squads/squad-brand/tasks/create-web-templates.md +1 -1
- package/squads/squad-brand/tasks/define-motion-language.md +1 -1
- package/squads/squad-brand/tasks/design-dynamic-identity-system.md +2 -2
- package/squads/squad-brand/tasks/design-illustration-system.md +1 -1
- package/squads/squad-commercial/README.md +3 -3
- package/squads/squad-commercial/agents/commercial-orqx.md +8 -8
- package/squads/squad-commercial/agents/cs-crm-specialist.md +3 -3
- package/squads/squad-commercial/agents/cs-revops-analyst.md +3 -3
- package/squads/squad-commercial/agents/cs-sales-closer.md +1 -1
- package/squads/squad-commercial/knowledge-base/commercial-analytics-reporting.md +7 -7
- package/squads/squad-commercial/knowledge-base/sales-revenue-master-reference.md +1 -1
- package/squads/squad-commercial/squad.yaml +3 -3
- package/squads/squad-commercial/tasks/analyze-revenue-leaks.md +2 -2
- package/squads/squad-commercial/tasks/audit-commercial-tech-stack.md +1 -1
- package/squads/squad-commercial/tasks/audit-crm-data.md +1 -1
- package/squads/squad-commercial/tasks/build-deal-scoring-model.md +1 -1
- package/squads/squad-commercial/tasks/build-forecasting-model.md +1 -1
- package/squads/squad-commercial/tasks/build-pipeline-dashboard.md +2 -2
- package/squads/squad-commercial/tasks/build-unit-economics-model.md +1 -1
- package/squads/squad-commercial/tasks/conduct-commercial-retrospective.md +2 -2
- package/squads/squad-commercial/tasks/conduct-deal-review.md +1 -1
- package/squads/squad-commercial/tasks/conduct-win-loss-analysis.md +1 -1
- package/squads/squad-commercial/tasks/configure-activity-tracking.md +1 -1
- package/squads/squad-commercial/tasks/configure-crm-integrations.md +1 -1
- package/squads/squad-commercial/tasks/configure-pipeline-stages.md +1 -1
- package/squads/squad-commercial/tasks/coordinate-revenue-cycle.md +1 -1
- package/squads/squad-commercial/tasks/create-commercial-brief.md +2 -2
- package/squads/squad-commercial/tasks/create-revenue-dashboard.md +1 -1
- package/squads/squad-commercial/tasks/design-lead-routing.md +1 -1
- package/squads/squad-commercial/tasks/design-quota-model.md +1 -1
- package/squads/squad-commercial/tasks/execute-save-play.md +1 -1
- package/squads/squad-commercial/tasks/manage-commercial-handoffs.md +1 -1
- package/squads/squad-commercial/tasks/manage-pipeline-forecast.md +3 -3
- package/squads/squad-commercial/tasks/monitor-pipeline-health.md +1 -1
- package/squads/squad-commercial/tasks/monitor-saas-metrics.md +1 -1
- package/squads/squad-commercial/tasks/plan-sales-capacity.md +1 -1
- package/squads/squad-commercial/tasks/plan-territory-mapping.md +1 -1
- package/squads/squad-commercial/tasks/review-revenue-architecture.md +2 -2
- package/squads/squad-commercial/tasks/run-quarterly-commercial-review.md +3 -3
- package/squads/squad-commercial/tasks/select-commercial-workflow.md +1 -1
- package/squads/squad-commercial/tasks/setup-outreach-sequences.md +1 -1
- package/squads/squad-commercial/templates/offer-brief-template.md +2 -2
- package/squads/squad-commercial/workflows/new-offer-launch.yaml +2 -2
- package/squads/squad-commercial/workflows/quarterly-commercial-review.yaml +1 -1
- package/squads/squad-commercial/workflows/revenue-forecasting-cycle.yaml +2 -2
- package/squads/squad-content/README.md +1 -1
- package/squads/squad-content/agents/content-analyst.md +4 -4
- package/squads/squad-content/agents/content-engineer.md +2 -2
- package/squads/squad-content/agents/content-governor.md +1 -1
- package/squads/squad-content/agents/content-orqx.md +6 -6
- package/squads/squad-content/agents/editorial-strategist.md +5 -5
- package/squads/squad-content/agents/platform-specialist.md +1 -1
- package/squads/squad-content/agents/signal-intelligence.md +4 -4
- package/squads/squad-content/checklists/editorial-planning-checklist.md +1 -1
- package/squads/squad-content/checklists/onboarding-setup-checklist.md +2 -2
- package/squads/squad-content/knowledge-base/ai-native-content-loop.md +2 -2
- package/squads/squad-content/knowledge-base/content-governance-principles.md +2 -2
- package/squads/squad-content/knowledge-base/cross-squad-integration-protocol.md +1 -1
- package/squads/squad-content/knowledge-base/signal-intelligence-v2.md +1 -1
- package/squads/squad-content/knowledge-base/task-ownership-map.md +5 -5
- package/squads/squad-content/squad.yaml +2 -2
- package/squads/squad-content/tasks/alert-opportunity-windows.md +6 -6
- package/squads/squad-content/tasks/analyze-content-performance.md +2 -2
- package/squads/squad-content/tasks/batch-content-production.md +1 -1
- package/squads/squad-content/tasks/benchmark-against-competitors.md +1 -1
- package/squads/squad-content/tasks/coordinate-cross-squad.md +1 -1
- package/squads/squad-content/tasks/create-content-governance.md +1 -1
- package/squads/squad-content/tasks/create-editorial-calendar.md +1 -1
- package/squads/squad-content/tasks/curate-ugc-signals.md +2 -2
- package/squads/squad-content/tasks/define-big-idea.md +1 -1
- package/squads/squad-content/tasks/define-content-kpis.md +1 -1
- package/squads/squad-content/tasks/flag-content-for-amplification.md +2 -2
- package/squads/squad-content/tasks/generate-content-report.md +3 -3
- package/squads/squad-content/tasks/manage-content-sprint.md +1 -1
- package/squads/squad-content/tasks/measure-content-roi.md +3 -3
- package/squads/squad-content/tasks/orchestrate-content-pipeline.md +2 -2
- package/squads/squad-content/tasks/plan-content-sprint.md +3 -3
- package/squads/squad-content/tasks/predict-content-performance.md +2 -2
- package/squads/squad-content/tasks/scan-daily-signals.md +2 -2
- package/squads/squad-content/tasks/triage-content-requests.md +1 -1
- package/squads/squad-content/tasks/triage-urgent-signal.md +1 -1
- package/squads/squad-content/templates/signal-alert-template.md +2 -2
- package/squads/squad-content/templates/weekly-briefing-template.md +1 -1
- package/squads/squad-content/workflows/content-audit-cycle.yaml +1 -1
- package/squads/squad-content/workflows/content-creation-cycle.yaml +3 -3
- package/squads/squad-content/workflows/editorial-planning-cycle.yaml +3 -3
- package/squads/squad-content/workflows/onboarding-content-cycle.yaml +3 -3
- package/squads/squad-content/workflows/performance-feedback-loop.yaml +3 -3
- package/squads/squad-content/workflows/signal-to-content-cycle.yaml +5 -5
- package/squads/squad-copy/README.md +4 -4
- package/squads/squad-copy/agents/ad-copywriter.md +4 -4
- package/squads/squad-copy/agents/copy-orqx.md +3 -3
- package/squads/squad-copy/agents/copy-strategist.md +5 -5
- package/squads/squad-copy/agents/direct-response-writer.md +3 -3
- package/squads/squad-copy/agents/email-sequence-strategist.md +1 -1
- package/squads/squad-copy/agents/funnel-copywriter.md +3 -3
- package/squads/squad-copy/agents/headline-specialist.md +1 -1
- package/squads/squad-copy/agents/proof-architect.md +3 -3
- package/squads/squad-copy/squad.yaml +3 -3
- package/squads/squad-copy/tasks/build-proof-stack.md +3 -3
- package/squads/squad-copy/tasks/craft-cta-variations.md +2 -2
- package/squads/squad-copy/tasks/craft-email-nurture-sequence.md +2 -2
- package/squads/squad-copy/tasks/craft-objection-handlers.md +1 -1
- package/squads/squad-copy/tasks/craft-social-media-hooks.md +1 -1
- package/squads/squad-copy/tasks/create-cart-abandonment-sequence.md +2 -2
- package/squads/squad-copy/tasks/create-customer-story.md +2 -2
- package/squads/squad-copy/tasks/create-email-campaign.md +2 -2
- package/squads/squad-copy/tasks/create-mechanism-copy.md +4 -4
- package/squads/squad-copy/tasks/create-opening-hooks.md +1 -1
- package/squads/squad-copy/tasks/create-ugc-script.md +2 -2
- package/squads/squad-copy/tasks/create-urgency-scarcity-framework.md +1 -1
- package/squads/squad-copy/tasks/create-welcome-sequence.md +2 -2
- package/squads/squad-copy/tasks/design-headline-ab-tests.md +1 -1
- package/squads/squad-copy/tasks/design-trigger-sequence.md +1 -1
- package/squads/squad-copy/tasks/design-welcome-series.md +2 -2
- package/squads/squad-copy/tasks/optimize-existing-copy.md +2 -2
- package/squads/squad-copy/tasks/optimize-funnel-conversion-copy.md +2 -2
- package/squads/squad-copy/tasks/optimize-pricing-framing.md +2 -2
- package/squads/squad-copy/tasks/write-ad-copy-google.md +2 -2
- package/squads/squad-copy/tasks/write-ad-copy-social.md +2 -2
- package/squads/squad-copy/tasks/write-ad-copy-variations.md +4 -4
- package/squads/squad-copy/tasks/write-case-study.md +2 -2
- package/squads/squad-copy/tasks/write-comparison-piece.md +2 -2
- package/squads/squad-copy/tasks/write-email-sequence.md +1 -1
- package/squads/squad-copy/tasks/write-email-subject-lines.md +1 -1
- package/squads/squad-copy/tasks/write-funnel-copy-sequence.md +4 -4
- package/squads/squad-copy/tasks/write-landing-page-copy.md +2 -2
- package/squads/squad-copy/tasks/write-launch-sequence.md +2 -2
- package/squads/squad-copy/tasks/write-opt-in-page.md +2 -2
- package/squads/squad-copy/tasks/write-product-narrative.md +2 -2
- package/squads/squad-copy/tasks/write-retargeting-copy.md +2 -2
- package/squads/squad-copy/tasks/write-sales-letter.md +1 -1
- package/squads/squad-copy/tasks/write-social-proof-section.md +1 -1
- package/squads/squad-copy/tasks/write-subheadlines-and-deck-copy.md +1 -1
- package/squads/squad-copy/tasks/write-upsell-copy.md +2 -2
- package/squads/squad-copy/tasks/write-vsl-script.md +3 -3
- package/squads/squad-copy/tasks/write-whitepaper-persuasive.md +2 -2
- package/squads/squad-copy/workflows/campaign-copy-cycle.yaml +4 -4
- package/squads/squad-copy/workflows/conversion-copy-sprint.yaml +6 -6
- package/squads/squad-copy/workflows/sales-copy-pipeline.yaml +4 -4
- package/squads/squad-design/README.md +6 -6
- package/squads/squad-design/agents/cro-persuasion.md +3 -3
- package/squads/squad-design/agents/design-orqx.md +17 -17
- package/squads/squad-design/agents/dx-accessibility-specialist.md +5 -5
- package/squads/squad-design/agents/dx-design-system-architect.md +8 -8
- package/squads/squad-design/agents/dx-frontend-engineer.md +7 -7
- package/squads/squad-design/agents/dx-interaction-designer.md +6 -6
- package/squads/squad-design/agents/dx-performance-engineer.md +3 -3
- package/squads/squad-design/agents/dx-ui-designer.md +7 -7
- package/squads/squad-design/agents/dx-ux-strategist.md +7 -7
- package/squads/squad-design/agents/platform-aesthetic-director.md +11 -11
- package/squads/squad-design/agents/premium-packaging-strategist.md +2 -2
- package/squads/squad-design/agents/product-surface-director.md +1 -1
- package/squads/squad-design/squad.yaml +6 -6
- package/squads/squad-design/tasks/analyze-javascript-bundles.md +1 -1
- package/squads/squad-design/tasks/audit-core-web-vitals.md +1 -1
- package/squads/squad-design/tasks/audit-design-system-health.md +1 -1
- package/squads/squad-design/tasks/audit-motion-performance.md +1 -1
- package/squads/squad-design/tasks/certify-accessibility-compliance.md +2 -2
- package/squads/squad-design/tasks/compose-screen-layouts.md +3 -3
- package/squads/squad-design/tasks/conduct-competitive-ux-analysis.md +1 -1
- package/squads/squad-design/tasks/conduct-dx-quality-gate.md +3 -3
- package/squads/squad-design/tasks/conduct-usability-heuristic-review.md +1 -1
- package/squads/squad-design/tasks/conduct-visual-qa.md +1 -1
- package/squads/squad-design/tasks/conduct-wcag-audit.md +1 -1
- package/squads/squad-design/tasks/configure-cdn-strategy.md +1 -1
- package/squads/squad-design/tasks/configure-token-export-pipeline.md +1 -1
- package/squads/squad-design/tasks/create-a11y-remediation-plan.md +4 -4
- package/squads/squad-design/tasks/create-color-system.md +2 -2
- package/squads/squad-design/tasks/create-component-governance.md +1 -1
- package/squads/squad-design/tasks/create-component-tokens.md +2 -2
- package/squads/squad-design/tasks/create-dark-light-themes.md +3 -3
- package/squads/squad-design/tasks/create-easing-curve-library.md +1 -1
- package/squads/squad-design/tasks/create-empty-error-states.md +1 -1
- package/squads/squad-design/tasks/create-error-boundary-patterns.md +1 -1
- package/squads/squad-design/tasks/create-illustration-style.md +1 -1
- package/squads/squad-design/tasks/create-mobile-first-designs.md +2 -2
- package/squads/squad-design/tasks/create-motion-documentation.md +1 -1
- package/squads/squad-design/tasks/create-motion-tokens.md +2 -2
- package/squads/squad-design/tasks/create-primitive-tokens.md +1 -1
- package/squads/squad-design/tasks/create-responsive-grid-system.md +1 -1
- package/squads/squad-design/tasks/create-screen-reader-specs.md +1 -1
- package/squads/squad-design/tasks/create-scroll-animation-patterns.md +1 -1
- package/squads/squad-design/tasks/create-semantic-tokens.md +1 -1
- package/squads/squad-design/tasks/create-storybook-documentation-standards.md +1 -1
- package/squads/squad-design/tasks/create-user-personas.md +1 -1
- package/squads/squad-design/tasks/create-ux-principles.md +1 -1
- package/squads/squad-design/tasks/create-wireframe-brief.md +2 -2
- package/squads/squad-design/tasks/define-atomic-hierarchy.md +2 -2
- package/squads/squad-design/tasks/define-content-hierarchy.md +2 -2
- package/squads/squad-design/tasks/define-motion-principles.md +4 -4
- package/squads/squad-design/tasks/define-performance-budgets.md +1 -1
- package/squads/squad-design/tasks/define-token-taxonomy.md +2 -2
- package/squads/squad-design/tasks/design-accessible-form-patterns.md +2 -2
- package/squads/squad-design/tasks/design-component-api-contracts.md +3 -3
- package/squads/squad-design/tasks/design-component-visual-states.md +4 -4
- package/squads/squad-design/tasks/design-dashboard-layouts.md +1 -1
- package/squads/squad-design/tasks/design-duration-scale.md +1 -1
- package/squads/squad-design/tasks/design-feedback-animations.md +2 -2
- package/squads/squad-design/tasks/design-focus-management.md +1 -1
- package/squads/squad-design/tasks/design-form-patterns.md +2 -2
- package/squads/squad-design/tasks/design-icon-system.md +1 -1
- package/squads/squad-design/tasks/design-information-architecture.md +2 -2
- package/squads/squad-design/tasks/design-landing-page-ui.md +3 -3
- package/squads/squad-design/tasks/design-loading-choreography.md +1 -1
- package/squads/squad-design/tasks/design-multi-brand-theming.md +1 -1
- package/squads/squad-design/tasks/design-page-transitions.md +1 -1
- package/squads/squad-design/tasks/design-spacing-scale.md +3 -3
- package/squads/squad-design/tasks/design-typography-scale.md +3 -3
- package/squads/squad-design/tasks/design-user-flows.md +2 -2
- package/squads/squad-design/tasks/design-visual-hierarchy.md +2 -2
- package/squads/squad-design/tasks/eliminate-render-blocking.md +1 -1
- package/squads/squad-design/tasks/extract-critical-css.md +1 -1
- package/squads/squad-design/tasks/govern-third-party-scripts.md +1 -1
- package/squads/squad-design/tasks/implement-authentication-ui.md +1 -1
- package/squads/squad-design/tasks/implement-component-library.md +4 -4
- package/squads/squad-design/tasks/implement-form-system.md +2 -2
- package/squads/squad-design/tasks/implement-reduced-motion.md +3 -3
- package/squads/squad-design/tasks/implement-responsive-layouts.md +1 -1
- package/squads/squad-design/tasks/implement-routing-strategy.md +1 -1
- package/squads/squad-design/tasks/map-dark-mode-tokens.md +3 -3
- package/squads/squad-design/tasks/map-user-journeys.md +2 -2
- package/squads/squad-design/tasks/migrate-legacy-design-system.md +1 -1
- package/squads/squad-design/tasks/monitor-performance-regression.md +1 -1
- package/squads/squad-design/tasks/optimize-font-loading.md +1 -1
- package/squads/squad-design/tasks/optimize-image-pipeline.md +1 -1
- package/squads/squad-design/tasks/orchestrate-dx-pipeline.md +2 -2
- package/squads/squad-design/tasks/plan-ux-research-sprint.md +1 -1
- package/squads/squad-design/tasks/produce-design-handoff-specs.md +4 -4
- package/squads/squad-design/tasks/review-aria-patterns.md +1 -1
- package/squads/squad-design/tasks/setup-performance-ci-gates.md +1 -1
- package/squads/squad-design/tasks/setup-storybook-integration.md +1 -1
- package/squads/squad-design/tasks/spec-gesture-interactions.md +1 -1
- package/squads/squad-design/tasks/spec-micro-interactions.md +2 -2
- package/squads/squad-design/tasks/synthesize-user-research.md +2 -2
- package/squads/squad-design/tasks/test-keyboard-navigation.md +1 -1
- package/squads/squad-design/tasks/validate-ux-with-testing.md +1 -1
- package/squads/squad-design/tasks/verify-color-contrast.md +2 -2
- package/squads/squad-design/templates/a11y-audit-report-template.md +1 -1
- package/squads/squad-design/templates/design-handoff-template.md +1 -1
- package/squads/squad-design/templates/performance-budget-template.md +1 -1
- package/squads/squad-design/templates/ux-research-plan-template.md +1 -1
- package/squads/squad-design/workflows/a11y-compliance-cycle.yaml +8 -8
- package/squads/squad-design/workflows/design-system-build-cycle.yaml +12 -12
- package/squads/squad-design/workflows/landing-page-sprint.yaml +10 -10
- package/squads/squad-design/workflows/performance-remediation-cycle.yaml +6 -6
- package/squads/squad-design/workflows/ux-research-sprint.yaml +8 -8
- package/squads/squad-design/workflows/zero-to-digital-product-cycle.yaml +16 -16
- package/squads/squad-finance/README.md +1 -1
- package/squads/squad-finance/agents/budget-controller.md +1 -1
- package/squads/squad-finance/agents/cost-optimizer.md +2 -2
- package/squads/squad-finance/agents/finance-orqx.md +4 -4
- package/squads/squad-finance/agents/fiscal-compliance-br.md +4 -4
- package/squads/squad-finance/agents/forecast-strategist.md +6 -6
- package/squads/squad-finance/agents/pricing-strategist.md +3 -3
- package/squads/squad-finance/agents/profitability-analyst.md +1 -1
- package/squads/squad-finance/agents/revenue-analyst.md +1 -1
- package/squads/squad-finance/checklists/monthly-close-checklist.md +1 -1
- package/squads/squad-finance/checklists/quarterly-review-checklist.md +1 -1
- package/squads/squad-finance/squad.yaml +2 -2
- package/squads/squad-finance/tasks/analyze-price-sensitivity.md +1 -1
- package/squads/squad-finance/tasks/benchmark-competitor-pricing.md +1 -1
- package/squads/squad-finance/tasks/calculate-rate-card.md +1 -1
- package/squads/squad-finance/tasks/coordinate-quarterly-review.md +2 -2
- package/squads/squad-finance/tasks/create-proposal-pricing.md +1 -1
- package/squads/squad-finance/tasks/design-service-tiers.md +1 -1
- package/squads/squad-finance/tasks/design-value-based-pricing.md +1 -1
- package/squads/squad-finance/tasks/manage-financial-calendar.md +1 -1
- package/squads/squad-finance/tasks/model-pricing-scenario.md +1 -1
- package/squads/squad-finance/tasks/optimize-rate-realization.md +1 -1
- package/squads/squad-finance/tasks/simulate-pricing-impact.md +1 -1
- package/squads/squad-finance/tasks/track-pricing-performance.md +1 -1
- package/squads/squad-paidmedia/README.md +4 -4
- package/squads/squad-paidmedia/agents/campaign-analyst.md +6 -6
- package/squads/squad-paidmedia/agents/creative-strategist.md +2 -2
- package/squads/squad-paidmedia/agents/cro-specialist.md +5 -5
- package/squads/squad-paidmedia/agents/google-ads-specialist.md +2 -2
- package/squads/squad-paidmedia/agents/meta-ads-specialist.md +6 -6
- package/squads/squad-paidmedia/agents/paidmedia-orqx.md +6 -6
- package/squads/squad-paidmedia/agents/performance-engineer.md +2 -2
- package/squads/squad-paidmedia/agents/pm-creative-performance-analyst.md +2 -2
- package/squads/squad-paidmedia/knowledge-base/routing-catalog.md +21 -21
- package/squads/squad-paidmedia/squad.yaml +4 -4
- package/squads/squad-paidmedia/tasks/allocate-cross-channel-budget.md +1 -1
- package/squads/squad-paidmedia/tasks/allocate-meta-budget.md +2 -2
- package/squads/squad-paidmedia/tasks/analyze-audience-performance.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-content-performance.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-conversion-funnel.md +2 -2
- package/squads/squad-paidmedia/tasks/analyze-creative-effectiveness.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-keyword-rankings.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-landing-page.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-local-keywords.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-local-market.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-reviews-strategy.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-top-pages.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-traffic-sources.md +1 -1
- package/squads/squad-paidmedia/tasks/analyze-user-behavior.md +1 -1
- package/squads/squad-paidmedia/tasks/audit-conversion-tracking.md +1 -1
- package/squads/squad-paidmedia/tasks/audit-gmb-location.md +1 -1
- package/squads/squad-paidmedia/tasks/audit-meta-ads-account.md +1 -1
- package/squads/squad-paidmedia/tasks/audit-sitemap-health.md +1 -1
- package/squads/squad-paidmedia/tasks/build-audience-architecture.md +2 -2
- package/squads/squad-paidmedia/tasks/build-creative-scorecard.md +1 -1
- package/squads/squad-paidmedia/tasks/calculate-sample-size.md +1 -1
- package/squads/squad-paidmedia/tasks/check-indexing-status.md +1 -1
- package/squads/squad-paidmedia/tasks/create-scaling-roadmap.md +1 -1
- package/squads/squad-paidmedia/tasks/design-campaign-structure.md +2 -2
- package/squads/squad-paidmedia/tasks/design-progressive-profiling.md +1 -1
- package/squads/squad-paidmedia/tasks/detect-creative-fatigue.md +1 -1
- package/squads/squad-paidmedia/tasks/execute-launch-checklist.md +1 -1
- package/squads/squad-paidmedia/tasks/generate-monthly-report.md +1 -1
- package/squads/squad-paidmedia/tasks/generate-search-performance-overview.md +1 -1
- package/squads/squad-paidmedia/tasks/generate-weekly-summary.md +1 -1
- package/squads/squad-paidmedia/tasks/manage-pixel-capi-health.md +1 -1
- package/squads/squad-paidmedia/tasks/manage-scaling-roadmap.md +1 -1
- package/squads/squad-paidmedia/tasks/measure-activation-rate.md +1 -1
- package/squads/squad-paidmedia/tasks/optimize-ad-set-targeting.md +2 -2
- package/squads/squad-paidmedia/tasks/optimize-form-conversion.md +1 -1
- package/squads/squad-paidmedia/tasks/optimize-onboarding-activation.md +1 -1
- package/squads/squad-paidmedia/tasks/optimize-page-conversion.md +1 -1
- package/squads/squad-paidmedia/tasks/optimize-signup-flow.md +1 -1
- package/squads/squad-paidmedia/tasks/plan-customer-engagement.md +1 -1
- package/squads/squad-paidmedia/tasks/run-ab-test.md +1 -1
- package/squads/squad-paidmedia/tasks/run-creative-test.md +1 -1
- package/squads/squad-paidmedia/tasks/track-gmb-performance-trends.md +1 -1
- package/squads/squad-paidmedia/tasks/triage-campaign-issues.md +1 -1
- package/squads/squad-product/README.md +2 -2
- package/squads/squad-product/agents/product-orqx.md +4 -4
- package/squads/squad-product/agents/ps-delivery-manager.md +2 -2
- package/squads/squad-product/agents/ps-product-ops-specialist.md +2 -2
- package/squads/squad-product/squad.yaml +2 -2
- package/squads/squad-product/tasks/audit-product-tool-stack.md +1 -1
- package/squads/squad-product/tasks/build-product-knowledge-base.md +1 -1
- package/squads/squad-product/tasks/calculate-sprint-velocity.md +1 -1
- package/squads/squad-product/tasks/configure-feature-flag-rollout.md +1 -1
- package/squads/squad-product/tasks/create-product-artifact-template.md +1 -1
- package/squads/squad-product/tasks/create-product-onboarding-runbook.md +3 -3
- package/squads/squad-product/tasks/create-product-playbook.md +2 -2
- package/squads/squad-product/tasks/document-product-process.md +1 -1
- package/squads/squad-product/tasks/execute-feature-launch-checklist.md +1 -1
- package/squads/squad-product/tasks/facilitate-sprint-retrospective.md +1 -1
- package/squads/squad-product/tasks/generate-product-health-report.md +2 -2
- package/squads/squad-product/tasks/maintain-decision-log-system.md +1 -1
- package/squads/squad-product/tasks/manage-sprint-capacity-planning.md +1 -1
- package/squads/squad-product/tasks/map-cross-functional-dependencies.md +1 -1
- package/squads/squad-product/tasks/prepare-product-handoff-package.md +4 -4
- package/squads/squad-product/tasks/run-product-operations-audit.md +1 -1
- package/squads/squad-product/tasks/run-shape-up-betting-table.md +1 -1
- package/squads/squad-product/tasks/run-sprint-planning-session.md +1 -1
- package/squads/squad-product/tasks/scope-agency-mvp.md +1 -1
- package/squads/squad-product/tasks/setup-new-client-product-operations.md +1 -1
- package/squads/squad-product/tasks/standardize-cross-client-metrics.md +1 -1
- package/squads/squad-product/tasks/triage-technical-debt-backlog.md +1 -1
- package/squads/squad-product/tasks/write-release-notes.md +1 -1
- package/squads/squad-research/README.md +3 -3
- package/squads/squad-research/agents/audience-intelligence.md +9 -9
- package/squads/squad-research/agents/competitive-intelligence.md +1 -1
- package/squads/squad-research/agents/data-synthesizer.md +11 -11
- package/squads/squad-research/agents/deep-researcher.md +2 -2
- package/squads/squad-research/agents/market-analyst.md +9 -9
- package/squads/squad-research/agents/research-orqx.md +4 -4
- package/squads/squad-research/agents/trend-forecaster.md +2 -2
- package/squads/squad-research/knowledge-base/agentic-second-brain-reference.md +1 -1
- package/squads/squad-research/knowledge-base/community-platforms-reference.md +1 -1
- package/squads/squad-research/knowledge-base/cross-squad-integration-protocol.md +1 -1
- package/squads/squad-research/knowledge-base/multi-agent-research-methodology.md +3 -3
- package/squads/squad-research/squad.yaml +3 -3
- package/squads/squad-research/tasks/analyze-audience-behavior.md +2 -2
- package/squads/squad-research/tasks/analyze-audience-psychographics.md +2 -2
- package/squads/squad-research/tasks/analyze-competitor-pricing.md +1 -1
- package/squads/squad-research/tasks/analyze-industry-trends.md +2 -2
- package/squads/squad-research/tasks/analyze-macro-forces.md +1 -1
- package/squads/squad-research/tasks/analyze-pricing-landscape.md +2 -2
- package/squads/squad-research/tasks/analyze-social-listening.md +2 -2
- package/squads/squad-research/tasks/analyze-value-chain.md +2 -2
- package/squads/squad-research/tasks/answer-strategic-question.md +1 -1
- package/squads/squad-research/tasks/assess-market-maturity.md +2 -2
- package/squads/squad-research/tasks/build-audience-persona.md +2 -2
- package/squads/squad-research/tasks/build-data-narrative.md +2 -2
- package/squads/squad-research/tasks/compile-competitive-dossier.md +2 -2
- package/squads/squad-research/tasks/conduct-deep-research.md +1 -1
- package/squads/squad-research/tasks/conduct-jobs-to-be-done.md +2 -2
- package/squads/squad-research/tasks/create-empathy-map.md +2 -2
- package/squads/squad-research/tasks/create-executive-briefing.md +2 -2
- package/squads/squad-research/tasks/create-insight-deck.md +2 -2
- package/squads/squad-research/tasks/create-research-dossier.md +1 -1
- package/squads/squad-research/tasks/create-research-repository.md +2 -2
- package/squads/squad-research/tasks/create-swot-analysis.md +4 -4
- package/squads/squad-research/tasks/design-survey.md +2 -2
- package/squads/squad-research/tasks/evaluate-market-entry.md +2 -2
- package/squads/squad-research/tasks/evaluate-regulatory-landscape.md +2 -2
- package/squads/squad-research/tasks/forecast-industry-trends.md +2 -2
- package/squads/squad-research/tasks/forecast-market-growth.md +2 -2
- package/squads/squad-research/tasks/generate-actionable-recommendations.md +2 -2
- package/squads/squad-research/tasks/identify-market-segments.md +3 -3
- package/squads/squad-research/tasks/map-audience-ecosystem.md +2 -2
- package/squads/squad-research/tasks/map-audience-journey.md +2 -2
- package/squads/squad-research/tasks/map-industry-ecosystem.md +2 -2
- package/squads/squad-research/tasks/map-market-opportunity.md +2 -2
- package/squads/squad-research/tasks/map-pain-gain-matrix.md +2 -2
- package/squads/squad-research/tasks/map-strategic-implications.md +2 -2
- package/squads/squad-research/tasks/orchestrate-research-pipeline.md +4 -4
- package/squads/squad-research/tasks/predict-market-shifts.md +1 -1
- package/squads/squad-research/tasks/profile-ideal-customer.md +2 -2
- package/squads/squad-research/tasks/run-porter-five-forces.md +1 -1
- package/squads/squad-research/tasks/run-scenario-planning.md +1 -1
- package/squads/squad-research/tasks/segment-audience.md +2 -2
- package/squads/squad-research/tasks/size-market-tam-sam-som.md +2 -2
- package/squads/squad-research/tasks/synthesize-multi-source.md +1 -1
- package/squads/squad-research/tasks/synthesize-research-report.md +2 -2
- package/squads/squad-research/tasks/validate-persona-with-data.md +2 -2
- package/squads/squad-research/tasks/visualize-research-data.md +2 -2
- package/squads/squad-research/templates/audience-persona-template.md +1 -1
- package/squads/squad-research/templates/competitive-dossier-template.md +1 -1
- package/squads/squad-research/templates/market-analysis-template.md +1 -1
- package/squads/squad-research/workflows/audience-intelligence-cycle.yaml +12 -12
- package/squads/squad-research/workflows/competitive-intelligence-cycle.yaml +2 -2
- package/squads/squad-research/workflows/deep-research-cycle.yaml +2 -2
- package/squads/squad-research/workflows/full-research-sprint.yaml +8 -8
- package/squads/squad-research/workflows/market-analysis-cycle.yaml +12 -12
- package/squads/squad-research/workflows/trend-forecasting-cycle.yaml +2 -2
- package/.sinapse-ai/lib/build.json +0 -1
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* per bracket for the SynapseEngine orchestrator.
|
|
7
7
|
*
|
|
8
8
|
* Reads model context window from core-config.yaml → models.registry.
|
|
9
|
+
* Also exposes shouldCompact() — a dual-trigger (percent + absolute)
|
|
10
|
+
* compaction signal, independent of the bracket ladder above.
|
|
9
11
|
*
|
|
10
12
|
* @module core/synapse/context/context-tracker
|
|
11
|
-
* @version 1.
|
|
13
|
+
* @version 1.2.0
|
|
12
14
|
* @created Story SYN-3 - Context Bracket Tracker
|
|
15
|
+
* @updated Story onda2-p4 - dual-trigger compaction signal (audit AF-20260702 item 2.12)
|
|
13
16
|
*/
|
|
14
17
|
|
|
15
18
|
const fs = require('fs');
|
|
@@ -24,25 +27,44 @@ const path = require('path');
|
|
|
24
27
|
* - DEPLETED: 25-40% remaining (reinforcement injection)
|
|
25
28
|
* - CRITICAL: 0-25% remaining (warning + handoff prep)
|
|
26
29
|
*
|
|
30
|
+
* Token budgets recalibrated by Story onda1-s2 (audit AF-20260702 item 1.6)
|
|
31
|
+
* to the REAL floors of the context-diet regime, measured 2026-07-02 with
|
|
32
|
+
* the real formatter against the real .synapse/constitution (96 rules):
|
|
33
|
+
*
|
|
34
|
+
* - Turn 1 (prompt_count=0 → always FRESH at ~100%): the FULL Constitution
|
|
35
|
+
* is PROTECTED and measures 7,226 chars ≈ 1,807 tokens (section alone);
|
|
36
|
+
* whole <synapse-rules> block ≈ 7,324 chars ≈ 1,831 tokens. FRESH=2000
|
|
37
|
+
* covers this floor with headroom for CONTEXT rules / AGENT section.
|
|
38
|
+
* (The old FRESH=800 was structurally unreachable — 2.3x over, silent.)
|
|
39
|
+
* - Turns 2+ (constitution emitted as reminder ≤ 1,000 chars ≈ ≤ 250
|
|
40
|
+
* tokens): the PROTECTED floor drops to ~200-300 tokens. MODERATE /
|
|
41
|
+
* DEPLETED / CRITICAL can only occur on turns 2+ (bracket is derived
|
|
42
|
+
* from prompt_count), so they are sized for reminder + AGENT rules
|
|
43
|
+
* (+ memory hints at DEPLETED+, + handoff warning at CRITICAL).
|
|
44
|
+
*
|
|
45
|
+
* Overflow is now SIGNALED (never silent) — see formatter.enforceTokenBudget()
|
|
46
|
+
* and the [BUDGET OVERFLOW] output marker + metrics.budget in engine.js.
|
|
47
|
+
*
|
|
27
48
|
* @type {Object.<string, {min: number, max: number, tokenBudget: number}>}
|
|
28
49
|
*/
|
|
29
50
|
const BRACKETS = {
|
|
30
|
-
FRESH: { min: 60, max: 100, tokenBudget:
|
|
31
|
-
MODERATE: { min: 40, max: 60, tokenBudget:
|
|
32
|
-
DEPLETED: { min: 25, max: 40, tokenBudget:
|
|
33
|
-
CRITICAL: { min: 0, max: 25, tokenBudget:
|
|
51
|
+
FRESH: { min: 60, max: 100, tokenBudget: 2000 },
|
|
52
|
+
MODERATE: { min: 40, max: 60, tokenBudget: 800 },
|
|
53
|
+
DEPLETED: { min: 25, max: 40, tokenBudget: 1000 },
|
|
54
|
+
CRITICAL: { min: 0, max: 25, tokenBudget: 1200 },
|
|
34
55
|
};
|
|
35
56
|
|
|
36
57
|
/**
|
|
37
58
|
* Token budget constants per bracket (shorthand access).
|
|
59
|
+
* Values mirror BRACKETS — see the measurement basis documented above.
|
|
38
60
|
*
|
|
39
61
|
* @type {Object.<string, number>}
|
|
40
62
|
*/
|
|
41
63
|
const TOKEN_BUDGETS = {
|
|
42
|
-
FRESH:
|
|
43
|
-
MODERATE:
|
|
44
|
-
DEPLETED:
|
|
45
|
-
CRITICAL:
|
|
64
|
+
FRESH: 2000,
|
|
65
|
+
MODERATE: 800,
|
|
66
|
+
DEPLETED: 1000,
|
|
67
|
+
CRITICAL: 1200,
|
|
46
68
|
};
|
|
47
69
|
|
|
48
70
|
/**
|
|
@@ -53,8 +75,21 @@ const TOKEN_BUDGETS = {
|
|
|
53
75
|
const XML_SAFETY_MULTIPLIER = 1.2;
|
|
54
76
|
|
|
55
77
|
/**
|
|
56
|
-
* Default configuration values.
|
|
57
|
-
*
|
|
78
|
+
* Default configuration values — the FALLBACK only.
|
|
79
|
+
*
|
|
80
|
+
* The EFFECTIVE maxContext is derived from
|
|
81
|
+
* `models.registry[models.active].contextWindow` in core-config.yaml via
|
|
82
|
+
* getModelConfig() below (reused as-is by estimateContextPercent() and
|
|
83
|
+
* shouldCompact() — one read path, no duplication/cycle). These DEFAULTS
|
|
84
|
+
* apply only when the config file, the `models` section, or the active
|
|
85
|
+
* registry entry is missing/invalid.
|
|
86
|
+
*
|
|
87
|
+
* As of Story onda2-p4 (audit AF-20260702 item 2.12), that fallback path is
|
|
88
|
+
* still what REAL `npx sinapse-ai install` outputs hit: the shipped
|
|
89
|
+
* core-config.yaml template has no `models` section, so installed projects
|
|
90
|
+
* fall back to 200000 even when the user's actual model has a 1M window.
|
|
91
|
+
* Adding that section to the install template is a separate, deliberate
|
|
92
|
+
* decision (P8/DEC-01) — intentionally not part of this story.
|
|
58
93
|
*/
|
|
59
94
|
const DEFAULTS = Object.freeze({
|
|
60
95
|
avgTokensPerPrompt: 1500,
|
|
@@ -206,6 +241,75 @@ function estimateContextPercent(promptCount, options = {}) {
|
|
|
206
241
|
return Math.max(0, Math.min(100, percent));
|
|
207
242
|
}
|
|
208
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Absolute ceiling (tokens) of live conversation history before compaction
|
|
246
|
+
* is recommended — independent of window size.
|
|
247
|
+
*
|
|
248
|
+
* Story onda2-p4 (audit AF-20260702 item 2.12): a pure percentage trigger
|
|
249
|
+
* does not scale to 1M-token windows — 60% of a 1M window is 600,000
|
|
250
|
+
* tokens of live history, far past the point where instruction coherence
|
|
251
|
+
* degrades ("context amnesia", see .claude/rules/token-economy.md §1,
|
|
252
|
+
* measured/calibrated for the 200K window). This constant is the midpoint
|
|
253
|
+
* of the 150-180K range the audit recommended as the interim absolute cap
|
|
254
|
+
* while the 1M-window trigger itself remains pending real measurement.
|
|
255
|
+
*
|
|
256
|
+
* @type {number}
|
|
257
|
+
*/
|
|
258
|
+
const COMPACTION_ABSOLUTE_CEILING = 165000;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Percentage of the active context window used before compaction is
|
|
262
|
+
* recommended — mirrors token-economy.md §1 ("Auto-compact: 60%").
|
|
263
|
+
*
|
|
264
|
+
* @type {number}
|
|
265
|
+
*/
|
|
266
|
+
const COMPACTION_PERCENT_TRIGGER = 0.6;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Determine whether compaction is recommended right now.
|
|
270
|
+
*
|
|
271
|
+
* DUAL trigger (Story onda2-p4 / audit item 2.12): fires at whichever
|
|
272
|
+
* comes first — COMPACTION_PERCENT_TRIGGER (60%) of the active context
|
|
273
|
+
* window, or the absolute COMPACTION_ABSOLUTE_CEILING (~165K tokens of
|
|
274
|
+
* live history). Reads maxContext/avgTokensPerPrompt from getModelConfig()
|
|
275
|
+
* — the SAME registry-aware source estimateContextPercent() uses, no
|
|
276
|
+
* duplicate read path — overridable via options for testing.
|
|
277
|
+
*
|
|
278
|
+
* Equivalence at today's real windows: real installs fall back to the 200K
|
|
279
|
+
* DEFAULTS (see DEFAULTS above), where 60% of 200K is 120,000 tokens —
|
|
280
|
+
* always smaller than the 165K ceiling. The percent trigger always wins
|
|
281
|
+
* there, so behavior is IDENTICAL to the pre-existing 60%-of-window rule
|
|
282
|
+
* (zero regression). Above ~275K (COMPACTION_ABSOLUTE_CEILING /
|
|
283
|
+
* COMPACTION_PERCENT_TRIGGER) — e.g. the 1M registry entries — the
|
|
284
|
+
* absolute ceiling wins and compaction is recommended far earlier than a
|
|
285
|
+
* naive 60%-of-window rule would allow.
|
|
286
|
+
*
|
|
287
|
+
* @param {number} promptCount - Number of prompts in the current session
|
|
288
|
+
* @param {Object} [options={}] - Configuration options (override config values, mirrors estimateContextPercent)
|
|
289
|
+
* @param {number} [options.avgTokensPerPrompt] - Average tokens per prompt
|
|
290
|
+
* @param {number} [options.maxContext] - Maximum context window size in tokens
|
|
291
|
+
* @returns {boolean} True when compaction is recommended now
|
|
292
|
+
*/
|
|
293
|
+
function shouldCompact(promptCount, options = {}) {
|
|
294
|
+
const modelConfig = getModelConfig();
|
|
295
|
+
const {
|
|
296
|
+
avgTokensPerPrompt = modelConfig.avgTokensPerPrompt,
|
|
297
|
+
maxContext = modelConfig.maxContext,
|
|
298
|
+
} = options;
|
|
299
|
+
|
|
300
|
+
if (typeof promptCount !== 'number' || isNaN(promptCount) || promptCount < 0) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (maxContext <= 0) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const usedTokens = promptCount * avgTokensPerPrompt * XML_SAFETY_MULTIPLIER;
|
|
309
|
+
const triggerTokens = Math.min(maxContext * COMPACTION_PERCENT_TRIGGER, COMPACTION_ABSOLUTE_CEILING);
|
|
310
|
+
return usedTokens >= triggerTokens;
|
|
311
|
+
}
|
|
312
|
+
|
|
209
313
|
/**
|
|
210
314
|
* Get the maximum token budget for injection at the given bracket.
|
|
211
315
|
*
|
|
@@ -280,6 +384,7 @@ function resetModelConfigCache(basePath = null) {
|
|
|
280
384
|
module.exports = {
|
|
281
385
|
calculateBracket,
|
|
282
386
|
estimateContextPercent,
|
|
387
|
+
shouldCompact,
|
|
283
388
|
getTokenBudget,
|
|
284
389
|
getActiveLayers,
|
|
285
390
|
needsHandoffWarning,
|
|
@@ -290,5 +395,7 @@ module.exports = {
|
|
|
290
395
|
TOKEN_BUDGETS,
|
|
291
396
|
DEFAULTS,
|
|
292
397
|
XML_SAFETY_MULTIPLIER,
|
|
398
|
+
COMPACTION_ABSOLUTE_CEILING,
|
|
399
|
+
COMPACTION_PERCENT_TRIGGER,
|
|
293
400
|
};
|
|
294
401
|
|
|
@@ -25,6 +25,7 @@ const {
|
|
|
25
25
|
const { buildLayerContext } = require('./context/context-builder');
|
|
26
26
|
|
|
27
27
|
const { formatSynapseRules } = require('./output/formatter');
|
|
28
|
+
const { estimateTokens } = require('./utils/tokens');
|
|
28
29
|
const { MemoryBridge } = require('./memory/memory-bridge');
|
|
29
30
|
|
|
30
31
|
// ---------------------------------------------------------------------------
|
|
@@ -383,9 +384,6 @@ class SynapseEngine {
|
|
|
383
384
|
metrics.totalEnd = process.hrtime.bigint();
|
|
384
385
|
const summary = metrics.getSummary();
|
|
385
386
|
|
|
386
|
-
// Persist hook metrics (fire-and-forget)
|
|
387
|
-
this._persistHookMetrics(summary, bracket, mergedConfig);
|
|
388
|
-
|
|
389
387
|
// 4. Format output
|
|
390
388
|
const xml = formatSynapseRules(
|
|
391
389
|
results,
|
|
@@ -398,6 +396,21 @@ class SynapseEngine {
|
|
|
398
396
|
needsHandoffWarning(bracket),
|
|
399
397
|
);
|
|
400
398
|
|
|
399
|
+
// Story onda1-s2: honest budget accounting — measure the EMITTED block
|
|
400
|
+
// against the bracket budget and expose it in metrics (never silent;
|
|
401
|
+
// the formatter also renders a [BUDGET OVERFLOW] marker in the output).
|
|
402
|
+
const emittedTokens = estimateTokens(xml);
|
|
403
|
+
summary.budget = {
|
|
404
|
+
bracket,
|
|
405
|
+
tokenBudget: typeof tokenBudget === 'number' && tokenBudget > 0 ? tokenBudget : null,
|
|
406
|
+
emittedTokens,
|
|
407
|
+
overBudget: typeof tokenBudget === 'number' && tokenBudget > 0 && emittedTokens > tokenBudget,
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// Persist hook metrics (fire-and-forget) — after budget accounting so
|
|
411
|
+
// the persisted system log carries the overflow signal
|
|
412
|
+
this._persistHookMetrics(summary, bracket, mergedConfig);
|
|
413
|
+
|
|
401
414
|
return { xml, metrics: summary, bracket };
|
|
402
415
|
}
|
|
403
416
|
|
|
@@ -427,6 +440,8 @@ class SynapseEngine {
|
|
|
427
440
|
layersSkipped: summary.layers_skipped,
|
|
428
441
|
layersErrored: summary.layers_errored,
|
|
429
442
|
totalRules: summary.total_rules,
|
|
443
|
+
// Story onda1-s2: budget overflow signal persisted in the system log
|
|
444
|
+
budget: summary.budget || null,
|
|
430
445
|
perLayer: {},
|
|
431
446
|
timestamp: new Date().toISOString(),
|
|
432
447
|
};
|
|
@@ -1,24 +1,95 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* L0 Constitution Layer Processor
|
|
3
3
|
*
|
|
4
|
-
* Injects the
|
|
4
|
+
* Injects the Constitutional articles as NON-NEGOTIABLE rules.
|
|
5
5
|
* ALWAYS_ON — processes regardless of session state.
|
|
6
6
|
* Rules are loaded from the .synapse/constitution domain file.
|
|
7
7
|
*
|
|
8
|
+
* Context diet (Story onda1-s2 — audit AF-20260702 item 1.1 CRITICAL):
|
|
9
|
+
* - FIRST prompt of a session (prompt_count === 0 at injection time — the
|
|
10
|
+
* session-manager increments prompt_count AFTER the engine runs, see
|
|
11
|
+
* hook-runtime.js → updateSession): emits the FULL constitution block,
|
|
12
|
+
* exactly as before.
|
|
13
|
+
* - Prompts 2+ (prompt_count >= 1): emits a short reminder (formatted
|
|
14
|
+
* [CONSTITUTION] section <= REMINDER_MAX_CHARS) containing the article
|
|
15
|
+
* titles table + a MANDATORY pointer to the granular source
|
|
16
|
+
* `.synapse/constitution` (the CLAUDE.md 11-article table is NOT a
|
|
17
|
+
* substitute for the granular rules — adversarial-review ressalva).
|
|
18
|
+
* - New session (prompt_count resets to 0) → full block again.
|
|
19
|
+
* - FAIL-SAFE: if prompt_count is unreadable (missing session, corrupted
|
|
20
|
+
* value, non-integer, negative) OR the reminder cannot be built (no
|
|
21
|
+
* article titles detected), the FULL block is emitted. A read error must
|
|
22
|
+
* never degrade to LESS enforcement.
|
|
23
|
+
*
|
|
24
|
+
* Measured with the real formatter against the real .synapse/constitution
|
|
25
|
+
* (2026-07-02): full section = 7,226 chars ≈ 1,807 tokens (96 rules);
|
|
26
|
+
* reminder section ≈ 700 chars ≈ ~175 tokens (~90% reduction per turn 2+).
|
|
27
|
+
*
|
|
8
28
|
* @module core/synapse/layers/l0-constitution
|
|
9
|
-
* @version 1.
|
|
29
|
+
* @version 1.1.0
|
|
10
30
|
* @created Story SYN-4 - Layer Processors L0-L3
|
|
31
|
+
* @updated Story onda1-s2 - Context diet (full block only on 1st prompt)
|
|
11
32
|
*/
|
|
12
33
|
|
|
13
34
|
const path = require('path');
|
|
14
35
|
const { loadDomainFile } = require('../domain/domain-loader');
|
|
15
36
|
const LayerProcessor = require('./layer-processor');
|
|
16
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Max size (chars) of the FORMATTED [CONSTITUTION] reminder section
|
|
40
|
+
* (header + indented rules), per AC2 of Story onda1-s2.
|
|
41
|
+
* @type {number}
|
|
42
|
+
*/
|
|
43
|
+
const REMINDER_MAX_CHARS = 1000;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Mirror of the section header rendered by output/formatter.js
|
|
47
|
+
* formatConstitution(). Used only to size-guard the reminder against
|
|
48
|
+
* REMINDER_MAX_CHARS with the exact final layout.
|
|
49
|
+
* @type {string}
|
|
50
|
+
*/
|
|
51
|
+
const SECTION_HEADER = '[CONSTITUTION] (NON-NEGOTIABLE)';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Article title lines in the constitution domain file end with their
|
|
55
|
+
* severity marker, e.g. "CLI First (NON-NEGOTIABLE)". Granular rules
|
|
56
|
+
* instead START with "MUST:", "MUST NOT:", "SHOULD:", "EXCEPTION:".
|
|
57
|
+
*/
|
|
58
|
+
const ARTICLE_TITLE_RE = /\((NON-NEGOTIABLE|MUST|SHOULD)\)$/;
|
|
59
|
+
const GRANULAR_PREFIX_RE = /^(MUST|SHOULD|EXCEPTION)\b/;
|
|
60
|
+
|
|
61
|
+
/** Canonical pointer to the granular source (MANDATORY in the reminder). */
|
|
62
|
+
const GRANULAR_SOURCE = '.synapse/constitution';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Convert a positive integer to a roman numeral (article numbering).
|
|
66
|
+
*
|
|
67
|
+
* @param {number} num - Positive integer (1-3999)
|
|
68
|
+
* @returns {string} Roman numeral
|
|
69
|
+
*/
|
|
70
|
+
function toRoman(num) {
|
|
71
|
+
const table = [
|
|
72
|
+
[1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],
|
|
73
|
+
[100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],
|
|
74
|
+
[10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],
|
|
75
|
+
];
|
|
76
|
+
let n = num;
|
|
77
|
+
let out = '';
|
|
78
|
+
for (const [value, symbol] of table) {
|
|
79
|
+
while (n >= value) {
|
|
80
|
+
out += symbol;
|
|
81
|
+
n -= value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
17
87
|
/**
|
|
18
88
|
* L0 Constitution Processor
|
|
19
89
|
*
|
|
20
90
|
* Loads constitution domain file and validates nonNegotiable flag in manifest.
|
|
21
|
-
* Returns all constitutional rules
|
|
91
|
+
* Returns all constitutional rules (1st prompt) or a compact reminder with a
|
|
92
|
+
* pointer to the granular source (prompts 2+) as an array of strings.
|
|
22
93
|
*
|
|
23
94
|
* @extends LayerProcessor
|
|
24
95
|
*/
|
|
@@ -30,18 +101,19 @@ class L0ConstitutionProcessor extends LayerProcessor {
|
|
|
30
101
|
/**
|
|
31
102
|
* Load constitution rules from domain file.
|
|
32
103
|
*
|
|
33
|
-
* ALWAYS_ON: processes regardless of session state
|
|
104
|
+
* ALWAYS_ON: processes regardless of session state (the layer always
|
|
105
|
+
* emits — only the SHAPE changes between full block and reminder).
|
|
34
106
|
* Validates that the constitution domain has nonNegotiable: true in manifest.
|
|
35
107
|
*
|
|
36
108
|
* @param {object} context
|
|
37
109
|
* @param {string} context.prompt - Current prompt text
|
|
38
|
-
* @param {object} context.session - Session state
|
|
110
|
+
* @param {object} context.session - Session state (SYN-2 schema; prompt_count used here)
|
|
39
111
|
* @param {object} context.config - Config with synapsePath and manifest
|
|
40
112
|
* @param {object[]} context.previousLayers - Results from previous layers
|
|
41
113
|
* @returns {{ rules: string[], metadata: object } | null}
|
|
42
114
|
*/
|
|
43
115
|
process(context) {
|
|
44
|
-
const { config } = context;
|
|
116
|
+
const { config, session } = context;
|
|
45
117
|
const { synapsePath, manifest } = config;
|
|
46
118
|
|
|
47
119
|
// Find constitution domain in manifest
|
|
@@ -66,16 +138,125 @@ class L0ConstitutionProcessor extends LayerProcessor {
|
|
|
66
138
|
// Validate nonNegotiable flag
|
|
67
139
|
const nonNegotiable = domain ? domain.nonNegotiable === true : false;
|
|
68
140
|
|
|
141
|
+
// Context diet (Story onda1-s2): full block on the 1st prompt of the
|
|
142
|
+
// session; compact reminder on prompts 2+. FAIL-SAFE: any unreadable
|
|
143
|
+
// prompt_count → full block (never degrade enforcement on read errors).
|
|
144
|
+
const { promptCount, reliable } = this._resolvePromptCount(session);
|
|
145
|
+
let emittedRules = rules;
|
|
146
|
+
let constitutionMode = 'full';
|
|
147
|
+
|
|
148
|
+
if (reliable && promptCount >= 1) {
|
|
149
|
+
const reminder = this._buildReminderRules(rules);
|
|
150
|
+
if (reminder) {
|
|
151
|
+
emittedRules = reminder;
|
|
152
|
+
constitutionMode = 'reminder';
|
|
153
|
+
}
|
|
154
|
+
// reminder === null → keep the full block (fail-safe)
|
|
155
|
+
}
|
|
156
|
+
|
|
69
157
|
return {
|
|
70
|
-
rules,
|
|
158
|
+
rules: emittedRules,
|
|
71
159
|
metadata: {
|
|
72
160
|
layer: 0,
|
|
73
161
|
source: 'constitution',
|
|
74
162
|
nonNegotiable,
|
|
163
|
+
constitutionMode,
|
|
164
|
+
totalRules: rules.length,
|
|
75
165
|
},
|
|
76
166
|
};
|
|
77
167
|
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Resolve prompt_count from the session with strict validation.
|
|
171
|
+
*
|
|
172
|
+
* prompt_count semantics (session-manager.js): the counter is incremented
|
|
173
|
+
* AFTER each processed prompt, so at injection time the FIRST prompt of a
|
|
174
|
+
* session sees prompt_count === 0.
|
|
175
|
+
*
|
|
176
|
+
* FAIL-SAFE contract: any value that is not a non-negative integer is
|
|
177
|
+
* treated as UNRELIABLE and the caller emits the FULL block. This covers
|
|
178
|
+
* missing session file / corrupted JSON (hook-runtime already falls back
|
|
179
|
+
* to { prompt_count: 0 }), missing field, NaN, floats and negatives.
|
|
180
|
+
*
|
|
181
|
+
* @param {object|null|undefined} session - Session state
|
|
182
|
+
* @returns {{ promptCount: number, reliable: boolean }}
|
|
183
|
+
* @private
|
|
184
|
+
*/
|
|
185
|
+
_resolvePromptCount(session) {
|
|
186
|
+
if (!session || typeof session !== 'object') {
|
|
187
|
+
return { promptCount: 0, reliable: false };
|
|
188
|
+
}
|
|
189
|
+
const raw = session.prompt_count;
|
|
190
|
+
if (typeof raw !== 'number' || !Number.isInteger(raw) || raw < 0) {
|
|
191
|
+
return { promptCount: 0, reliable: false };
|
|
192
|
+
}
|
|
193
|
+
return { promptCount: raw, reliable: true };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Build the compact reminder emitted on prompts 2+.
|
|
198
|
+
*
|
|
199
|
+
* Content: lead line + article titles table (derived DYNAMICALLY from the
|
|
200
|
+
* loaded rules — no hardcoded article list, so regenerating the
|
|
201
|
+
* constitution keeps the reminder in sync) + mandatory pointer to the
|
|
202
|
+
* granular source (.synapse/constitution).
|
|
203
|
+
*
|
|
204
|
+
* Size guard: the FORMATTED section (header + 2-space indented lines,
|
|
205
|
+
* mirroring output/formatter.js formatConstitution) must fit in
|
|
206
|
+
* REMINDER_MAX_CHARS. Falls back to progressively more compact layouts;
|
|
207
|
+
* the pointer line is NEVER dropped.
|
|
208
|
+
*
|
|
209
|
+
* @param {string[]} rules - Full granular rule list
|
|
210
|
+
* @returns {string[]|null} Reminder rules, or null when no article titles
|
|
211
|
+
* could be detected (caller falls back to the full block — fail-safe)
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
_buildReminderRules(rules) {
|
|
215
|
+
const titles = rules.filter(rule =>
|
|
216
|
+
typeof rule === 'string'
|
|
217
|
+
&& ARTICLE_TITLE_RE.test(rule.trim())
|
|
218
|
+
&& !GRANULAR_PREFIX_RE.test(rule.trim()),
|
|
219
|
+
).map(rule => rule.trim());
|
|
220
|
+
|
|
221
|
+
// Fail-safe: cannot summarize → caller emits the full block
|
|
222
|
+
if (titles.length === 0) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const lead = 'Constitution ativa — TODOS os artigos abaixo seguem em vigor neste turno:';
|
|
227
|
+
const pointer = `Fonte completa: as ${rules.length} regras granulares estão em ${GRANULAR_SOURCE} — `
|
|
228
|
+
+ 'este lembrete NÃO substitui a fonte granular; consulte-a na dúvida.';
|
|
229
|
+
|
|
230
|
+
// Layout 1: one numbered title per line
|
|
231
|
+
let candidate = [lead, ...titles.map((t, i) => `${toRoman(i + 1)}. ${t}`), pointer];
|
|
232
|
+
if (this._formattedSectionLength(candidate) <= REMINDER_MAX_CHARS) {
|
|
233
|
+
return candidate;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Layout 2: all titles on a single separated line
|
|
237
|
+
candidate = [lead, titles.join(' · '), pointer];
|
|
238
|
+
if (this._formattedSectionLength(candidate) <= REMINDER_MAX_CHARS) {
|
|
239
|
+
return candidate;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Layout 3: hard-truncate the titles line to fit (pointer always kept)
|
|
243
|
+
const fixedLength = this._formattedSectionLength([lead, '', pointer]);
|
|
244
|
+
const room = Math.max(0, REMINDER_MAX_CHARS - fixedLength - 1); // -1 for the ellipsis
|
|
245
|
+
const titlesLine = titles.join(' · ').slice(0, room) + '…';
|
|
246
|
+
return [lead, titlesLine, pointer];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Exact length of the [CONSTITUTION] section as the formatter renders it
|
|
251
|
+
* (header line + each rule prefixed with two spaces, newline separated).
|
|
252
|
+
*
|
|
253
|
+
* @param {string[]} lines - Candidate reminder lines
|
|
254
|
+
* @returns {number} Rendered section length in chars
|
|
255
|
+
* @private
|
|
256
|
+
*/
|
|
257
|
+
_formattedSectionLength(lines) {
|
|
258
|
+
return [SECTION_HEADER, ...lines.map(l => ` ${l}`)].join('\n').length;
|
|
259
|
+
}
|
|
78
260
|
}
|
|
79
261
|
|
|
80
262
|
module.exports = L0ConstitutionProcessor;
|
|
81
|
-
|
|
@@ -378,44 +378,65 @@ function formatSummary(results, _metrics) {
|
|
|
378
378
|
// Token Budget Enforcement
|
|
379
379
|
// ---------------------------------------------------------------------------
|
|
380
380
|
|
|
381
|
+
/** Sections that are never removed by budget truncation. */
|
|
382
|
+
const PROTECTED_SECTIONS = new Set(['CONTEXT_BRACKET', 'CONSTITUTION', 'AGENT']);
|
|
383
|
+
|
|
384
|
+
/** Truncation priority: removed first when over budget. */
|
|
385
|
+
const TRUNCATION_ORDER = [
|
|
386
|
+
'SUMMARY',
|
|
387
|
+
'KEYWORD',
|
|
388
|
+
'MEMORY_HINTS',
|
|
389
|
+
'SQUAD',
|
|
390
|
+
'STAR_COMMANDS',
|
|
391
|
+
'DEVMODE',
|
|
392
|
+
'TASK',
|
|
393
|
+
'WORKFLOW',
|
|
394
|
+
];
|
|
395
|
+
|
|
381
396
|
/**
|
|
382
397
|
* Enforce a token budget by removing sections from the end.
|
|
383
398
|
*
|
|
384
399
|
* Truncation order (last removed first): SUMMARY, KEYWORD, SQUAD,
|
|
385
400
|
* STAR_COMMANDS, TASK, WORKFLOW. CONSTITUTION and AGENT are never removed.
|
|
386
401
|
*
|
|
402
|
+
* Story onda1-s2 (audit AF-20260702 item 1.6): the result is now a
|
|
403
|
+
* STRUCTURED object — overflow is signaled, never silent. When the
|
|
404
|
+
* PROTECTED sections alone exceed the budget, `overBudget` is true and
|
|
405
|
+
* formatSynapseRules() renders a visible [BUDGET OVERFLOW] warning; the
|
|
406
|
+
* engine also persists the signal in hook metrics.
|
|
407
|
+
*
|
|
387
408
|
* @param {string[]} sections - Ordered section strings
|
|
388
409
|
* @param {string[]} sectionIds - Corresponding section identifiers
|
|
389
410
|
* @param {number} tokenBudget - Max tokens allowed
|
|
390
|
-
* @returns {
|
|
411
|
+
* @returns {{
|
|
412
|
+
* sections: string[],
|
|
413
|
+
* sectionIds: string[],
|
|
414
|
+
* totalTokens: number,
|
|
415
|
+
* tokenBudget: number,
|
|
416
|
+
* overBudget: boolean,
|
|
417
|
+
* removed: string[]
|
|
418
|
+
* }} Filtered sections + structured budget signal
|
|
391
419
|
*/
|
|
392
420
|
function enforceTokenBudget(sections, sectionIds, tokenBudget) {
|
|
393
|
-
if (!tokenBudget || tokenBudget <= 0) {
|
|
394
|
-
return sections;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// Sections that should never be removed
|
|
398
|
-
const PROTECTED = new Set(['CONTEXT_BRACKET', 'CONSTITUTION', 'AGENT']);
|
|
399
|
-
|
|
400
|
-
// Truncation priority: remove from end first
|
|
401
|
-
const TRUNCATION_ORDER = [
|
|
402
|
-
'SUMMARY',
|
|
403
|
-
'KEYWORD',
|
|
404
|
-
'MEMORY_HINTS',
|
|
405
|
-
'SQUAD',
|
|
406
|
-
'STAR_COMMANDS',
|
|
407
|
-
'DEVMODE',
|
|
408
|
-
'TASK',
|
|
409
|
-
'WORKFLOW',
|
|
410
|
-
];
|
|
411
|
-
|
|
412
421
|
const result = [...sections];
|
|
413
422
|
const ids = [...sectionIds];
|
|
423
|
+
const removed = [];
|
|
424
|
+
|
|
425
|
+
if (!tokenBudget || tokenBudget <= 0) {
|
|
426
|
+
return {
|
|
427
|
+
sections: result,
|
|
428
|
+
sectionIds: ids,
|
|
429
|
+
totalTokens: estimateTokens(result.join('\n\n')),
|
|
430
|
+
tokenBudget: 0,
|
|
431
|
+
overBudget: false,
|
|
432
|
+
removed,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
414
435
|
|
|
415
436
|
let totalTokens = estimateTokens(result.join('\n\n'));
|
|
416
437
|
|
|
417
438
|
if (totalTokens <= tokenBudget) {
|
|
418
|
-
return result;
|
|
439
|
+
return { sections: result, sectionIds: ids, totalTokens, tokenBudget, overBudget: false, removed };
|
|
419
440
|
}
|
|
420
441
|
|
|
421
442
|
// Remove sections in truncation order
|
|
@@ -425,14 +446,22 @@ function enforceTokenBudget(sections, sectionIds, tokenBudget) {
|
|
|
425
446
|
}
|
|
426
447
|
|
|
427
448
|
const idx = ids.indexOf(sectionToRemove);
|
|
428
|
-
if (idx !== -1 && !
|
|
449
|
+
if (idx !== -1 && !PROTECTED_SECTIONS.has(sectionToRemove)) {
|
|
429
450
|
result.splice(idx, 1);
|
|
430
451
|
ids.splice(idx, 1);
|
|
452
|
+
removed.push(sectionToRemove);
|
|
431
453
|
totalTokens = estimateTokens(result.join('\n\n'));
|
|
432
454
|
}
|
|
433
455
|
}
|
|
434
456
|
|
|
435
|
-
return
|
|
457
|
+
return {
|
|
458
|
+
sections: result,
|
|
459
|
+
sectionIds: ids,
|
|
460
|
+
totalTokens,
|
|
461
|
+
tokenBudget,
|
|
462
|
+
overBudget: totalTokens > tokenBudget,
|
|
463
|
+
removed,
|
|
464
|
+
};
|
|
436
465
|
}
|
|
437
466
|
|
|
438
467
|
// ---------------------------------------------------------------------------
|
|
@@ -544,8 +573,19 @@ function formatSynapseRules(results, bracket, contextPercent, session, devmode,
|
|
|
544
573
|
sectionIds.push('SUMMARY');
|
|
545
574
|
}
|
|
546
575
|
|
|
547
|
-
// Token budget enforcement
|
|
548
|
-
const
|
|
576
|
+
// Token budget enforcement (structured — Story onda1-s2)
|
|
577
|
+
const budgetResult = enforceTokenBudget(sections, sectionIds, tokenBudget);
|
|
578
|
+
const finalSections = [...budgetResult.sections];
|
|
579
|
+
|
|
580
|
+
// Budget overflow signal: when the PROTECTED sections alone exceed the
|
|
581
|
+
// bracket budget, say so IN the output — never silently over-deliver.
|
|
582
|
+
if (budgetResult.overBudget) {
|
|
583
|
+
finalSections.push(
|
|
584
|
+
'[BUDGET OVERFLOW]\n'
|
|
585
|
+
+ ` WARN: emitted ~${budgetResult.totalTokens} tokens > budget ${budgetResult.tokenBudget} (${bracket}). `
|
|
586
|
+
+ 'Protected sections (Constitution/Agent) alone exceed this bracket\'s token budget.',
|
|
587
|
+
);
|
|
588
|
+
}
|
|
549
589
|
|
|
550
590
|
// Wrap in <synapse-rules> tags
|
|
551
591
|
const body = finalSections.join('\n\n');
|
|
@@ -398,11 +398,18 @@ boundary:
|
|
|
398
398
|
# Consumed by .sinapse-ai/core/synapse/context/context-tracker.js (getModelConfig).
|
|
399
399
|
# active selects which registry entry drives estimateContextPercent.
|
|
400
400
|
models:
|
|
401
|
-
active: claude-
|
|
401
|
+
active: claude-fable-5
|
|
402
402
|
registry:
|
|
403
|
+
claude-fable-5:
|
|
404
|
+
contextWindow: 1000000
|
|
405
|
+
avgTokensPerPrompt: 2000
|
|
403
406
|
claude-opus-4-8:
|
|
404
407
|
contextWindow: 1000000
|
|
405
408
|
avgTokensPerPrompt: 2000
|
|
409
|
+
claude-sonnet-5:
|
|
410
|
+
# conservative default — verify against official docs before relying on 1M
|
|
411
|
+
contextWindow: 200000
|
|
412
|
+
avgTokensPerPrompt: 1500
|
|
406
413
|
claude-sonnet-4-6:
|
|
407
414
|
contextWindow: 1000000
|
|
408
415
|
avgTokensPerPrompt: 1500
|