tribunal-kit 9.0.2 → 9.2.3
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/.agent/agents/backend-specialist.md +1 -1
- package/.agent/agents/code-archaeologist.md +1 -1
- package/.agent/agents/database-architect.md +1 -1
- package/.agent/agents/debugger.md +1 -1
- package/.agent/agents/devops-engineer.md +1 -1
- package/.agent/agents/documentation-writer.md +1 -1
- package/.agent/agents/explorer-agent.md +1 -1
- package/.agent/agents/game-developer.md +1 -1
- package/.agent/agents/minimalist-reviewer.md +1 -1
- package/.agent/agents/mobile-developer.md +1 -1
- package/.agent/agents/orchestrator.md +44 -2
- package/.agent/agents/penetration-tester.md +1 -1
- package/.agent/agents/performance-optimizer.md +1 -1
- package/.agent/agents/product-manager.md +1 -1
- package/.agent/agents/product-owner.md +1 -1
- package/.agent/agents/project-planner.md +1 -1
- package/.agent/agents/qa-automation-engineer.md +1 -1
- package/.agent/agents/seo-specialist.md +1 -1
- package/.agent/agents/test-engineer.md +1 -1
- package/.agent/config/claude.json +1 -1
- package/.agent/config/plugin.json +1 -1
- package/.agent/history/architecture-explorer.html +352 -0
- package/.agent/history/architecture-graph.yaml +181 -1
- package/.agent/history/graph-cache.json +323 -13
- package/.agent/history/integrity_manifest.json +3937 -299
- package/.agent/history/memory/.memory.idx +50 -50
- package/.agent/history/snapshots/.opencode__plugins__tribunal.js.json +12 -0
- package/.agent/history/snapshots/.pi__extensions__tribunal.ts.json +12 -0
- package/.agent/history/snapshots/bin__adapter-install.js.json +1 -1
- package/.agent/history/snapshots/bin__mcp-server.js.json +4 -2
- package/.agent/history/snapshots/bin__proxy-server.js.json +1 -1
- package/.agent/history/snapshots/bin__spawn-agent.js.json +1 -1
- package/.agent/history/snapshots/bin__wrapper.js.json +1 -1
- package/.agent/history/snapshots/eslint.config.js.json +1 -1
- package/.agent/history/snapshots/hooks__session-start.js.json +11 -0
- package/.agent/history/snapshots/scripts__apply-version.js.json +11 -0
- package/.agent/history/snapshots/scripts__audit_skill_sdo.js.json +11 -0
- package/.agent/history/snapshots/scripts__clean-pycache.js.json +11 -0
- package/.agent/history/snapshots/scripts__context_compiler.js.json +17 -0
- package/.agent/history/snapshots/scripts__modernize_skills.js.json +11 -0
- package/.agent/history/snapshots/scripts__package-cores.js.json +12 -0
- package/.agent/history/snapshots/scripts__skill_enhancement_engine.js.json +11 -0
- package/.agent/history/snapshots/scripts__sync-skills.js.json +11 -0
- package/.agent/history/snapshots/scripts__telemetry_gc.js.json +11 -0
- package/.agent/history/snapshots/scripts__validate-payload.js.json +1 -1
- package/.agent/history/snapshots/test__integration__browser_cli.test.js.json +12 -0
- package/.agent/history/snapshots/test__integration__sync_status.test.js.json +1 -1
- package/.agent/history/snapshots/test__unit__ast_context_loader.test.js.json +12 -0
- package/.agent/history/snapshots/test__unit__browser_case_bridge.test.js.json +11 -0
- package/.agent/history/snapshots/test__unit__browser_discovery.test.js.json +10 -0
- package/.agent/history/snapshots/test__unit__browser_idpi.test.js.json +10 -0
- package/.agent/history/snapshots/test__unit__browser_sentinel.test.js.json +11 -0
- package/.agent/history/snapshots/test__unit__browser_synapse.test.js.json +10 -0
- package/.agent/history/snapshots/test__unit__browser_trimmer.test.js.json +10 -0
- package/.agent/history/snapshots/test__unit__context_compiler.test.js.json +26 -0
- package/.agent/history/snapshots/test__unit__init.test.js.json +1 -1
- package/.agent/history/snapshots/test__unit__learn.test.js.json +1 -1
- package/.agent/history/snapshots/test__unit__mcp_server.test.js.json +1 -1
- package/.agent/history/snapshots/test__unit__platform_download_audit.test.js.json +11 -0
- package/.agent/history/snapshots/test__unit__prompt_compiler.test.js.json +10 -0
- package/.agent/history/snapshots/test__unit__sdd_integration.test.js.json +12 -0
- package/.agent/history/snapshots/test__unit__stress.test.js.json +1 -1
- package/.agent/history/snapshots/test__unit__token_budget_broker.test.js.json +10 -0
- package/.agent/history/snapshots/test__unit__tui.test.js.json +10 -0
- package/.agent/routing_index.json +266 -1531
- package/.agent/rules/kernel.md +86 -0
- package/.agent/scripts/_utils.js +78 -0
- package/.agent/scripts/browser_audit.js +13 -5
- package/.agent/scripts/bundle_analyzer.js +7 -3
- package/.agent/scripts/context_broker.js +0 -8
- package/.agent/scripts/context_compiler.js +1106 -3
- package/.agent/scripts/dependency_analyzer.js +16 -16
- package/.agent/scripts/guardrail_engine.js +48 -11
- package/.agent/scripts/inner_loop_validator.js +1 -1
- package/.agent/scripts/memory_engine.js +490 -329
- package/.agent/scripts/payload_schemas.js +18 -0
- package/.agent/scripts/pipeline_engine.js +29 -105
- package/.agent/scripts/schema_validator.js +2 -1
- package/.agent/scripts/swarm_dispatcher.js +148 -46
- package/.agent/scripts/test_runner.js +1 -2
- package/.agent/skill_topic_map.json +71 -22
- package/.agent/skills/12-principles-of-animation/SKILL.md +1 -76
- package/.agent/skills/60fps-animation/SKILL.md +4 -77
- package/.agent/skills/accessible-animation/SKILL.md +9 -86
- package/.agent/skills/adapt/SKILL.md +1 -76
- package/.agent/skills/advanced-rag-pipelines/SKILL.md +1 -76
- package/.agent/skills/agent-organizer/SKILL.md +1 -76
- package/.agent/skills/agentic-patterns/SKILL.md +1 -76
- package/.agent/skills/agentic-workflows-2026/SKILL.md +1 -75
- package/.agent/skills/ai-app-hardening/SKILL.md +1 -75
- package/.agent/skills/ai-prompt-injection-defense/SKILL.md +1 -76
- package/.agent/skills/animation-on-scroll/SKILL.md +16 -87
- package/.agent/skills/animation-systems/SKILL.md +15 -90
- package/.agent/skills/antfu-conventions/SKILL.md +0 -75
- package/.agent/skills/api-patterns/SKILL.md +1 -76
- package/.agent/skills/api-security-auditor/SKILL.md +1 -76
- package/.agent/skills/app-builder/SKILL.md +1 -76
- package/.agent/skills/appflow-wireframe/SKILL.md +1 -78
- package/.agent/skills/apple-design/SKILL.md +1 -76
- package/.agent/skills/architecture/SKILL.md +1 -76
- package/.agent/skills/audit-and-fix/SKILL.md +41 -77
- package/.agent/skills/authentication-best-practices/SKILL.md +1 -76
- package/.agent/skills/backend-security-expert/SKILL.md +1 -76
- package/.agent/skills/baseline-ui/SKILL.md +1 -76
- package/.agent/skills/bash-linux/SKILL.md +1 -76
- package/.agent/skills/behavioral-modes/SKILL.md +1 -76
- package/.agent/skills/better-colors/SKILL.md +1 -76
- package/.agent/skills/better-typography/SKILL.md +1 -75
- package/.agent/skills/better-ui/SKILL.md +18 -81
- package/.agent/skills/bolder/SKILL.md +1 -76
- package/.agent/skills/brainstorming/SKILL.md +1 -75
- package/.agent/skills/browser-audit/SKILL.md +15 -83
- package/.agent/skills/browser-native-ai/SKILL.md +1 -76
- package/.agent/skills/build-primitive/SKILL.md +1 -76
- package/.agent/skills/building-native-ui/SKILL.md +1 -76
- package/.agent/skills/cicd-pro/SKILL.md +1 -76
- package/.agent/skills/clarify/SKILL.md +1 -76
- package/.agent/skills/clean-code/SKILL.md +1 -76
- package/.agent/skills/cloud-architect/SKILL.md +1 -76
- package/.agent/skills/cobejs/SKILL.md +1 -76
- package/.agent/skills/code-review-checklist/SKILL.md +1 -76
- package/.agent/skills/codebase-design/SKILL.md +1 -76
- package/.agent/skills/colorize/SKILL.md +1 -76
- package/.agent/skills/compact-landing/SKILL.md +1 -76
- package/.agent/skills/company-logos/SKILL.md +1 -76
- package/.agent/skills/config-validator/SKILL.md +1 -76
- package/.agent/skills/containerization-pro/SKILL.md +1 -76
- package/.agent/skills/context-engineering-pro/SKILL.md +1 -75
- package/.agent/skills/create-design-md/SKILL.md +1 -76
- package/.agent/skills/critique/SKILL.md +1 -76
- package/.agent/skills/csharp-developer/SKILL.md +1 -76
- package/.agent/skills/data-validation-schemas/SKILL.md +1 -76
- package/.agent/skills/database-design/SKILL.md +1 -76
- package/.agent/skills/delight/SKILL.md +1 -76
- package/.agent/skills/deployment-procedures/SKILL.md +1 -76
- package/.agent/skills/design-lab/SKILL.md +0 -75
- package/.agent/skills/devops-engineer/SKILL.md +1 -76
- package/.agent/skills/devops-incident-responder/SKILL.md +1 -76
- package/.agent/skills/diagnosing-bugs/SKILL.md +0 -75
- package/.agent/skills/distill/SKILL.md +1 -76
- package/.agent/skills/documentation-templates/SKILL.md +1 -76
- package/.agent/skills/domain-modeling/SKILL.md +1 -76
- package/.agent/skills/duckdb-analytical-sql/SKILL.md +1 -75
- package/.agent/skills/edge-ai-mobile/SKILL.md +1 -75
- package/.agent/skills/edge-computing/SKILL.md +1 -76
- package/.agent/skills/emil-design-eng/SKILL.md +1 -76
- package/.agent/skills/error-resilience/SKILL.md +1 -76
- package/.agent/skills/expo-router-v4/SKILL.md +1 -75
- package/.agent/skills/extract-design-system/SKILL.md +1 -76
- package/.agent/skills/fabel-protocol/SKILL.md +1 -76
- package/.agent/skills/fixing-accessibility/SKILL.md +1 -76
- package/.agent/skills/fixing-metadata/SKILL.md +1 -76
- package/.agent/skills/fixing-motion-performance/SKILL.md +1 -76
- package/.agent/skills/framer-motion-expert/SKILL.md +1 -76
- package/.agent/skills/frontend-design/SKILL.md +1 -76
- package/.agent/skills/frontend-security-expert/SKILL.md +1 -76
- package/.agent/skills/game-design-expert/SKILL.md +1 -76
- package/.agent/skills/game-engineering-expert/SKILL.md +1 -76
- package/.agent/skills/generative-ui-expert/SKILL.md +1 -76
- package/.agent/skills/geo-fundamentals/SKILL.md +1 -76
- package/.agent/skills/git-pro/SKILL.md +1 -76
- package/.agent/skills/github-operations/SKILL.md +1 -76
- package/.agent/skills/gpt-taste/SKILL.md +1 -76
- package/.agent/skills/gsap-core/SKILL.md +1 -76
- package/.agent/skills/gsap-frameworks/SKILL.md +1 -76
- package/.agent/skills/gsap-performance/SKILL.md +1 -76
- package/.agent/skills/gsap-plugins/SKILL.md +1 -76
- package/.agent/skills/gsap-react/SKILL.md +1 -76
- package/.agent/skills/gsap-scrolltrigger/SKILL.md +1 -76
- package/.agent/skills/gsap-timeline/SKILL.md +1 -76
- package/.agent/skills/gsap-utils/SKILL.md +1 -76
- package/.agent/skills/harden/SKILL.md +1 -76
- package/.agent/skills/harness-protocol/SKILL.md +1 -76
- package/.agent/skills/i18n-localization/SKILL.md +1 -76
- package/.agent/skills/impeccable/SKILL.md +1 -76
- package/.agent/skills/improve-codebase-architecture/SKILL.md +1 -76
- package/.agent/skills/improve-ui/SKILL.md +1 -76
- package/.agent/skills/intelligent-routing/SKILL.md +2 -87
- package/.agent/skills/knowledge-graph/SKILL.md +1 -76
- package/.agent/skills/landing-page/SKILL.md +1 -76
- package/.agent/skills/lint-and-validate/SKILL.md +1 -76
- package/.agent/skills/llm-engineering/SKILL.md +1 -76
- package/.agent/skills/local-first/SKILL.md +1 -76
- package/.agent/skills/local-first-architecture/SKILL.md +1 -76
- package/.agent/skills/lottie-animation/SKILL.md +1 -76
- package/.agent/skills/marquee-loop/SKILL.md +1 -76
- package/.agent/skills/masked-reveal/SKILL.md +1 -76
- package/.agent/skills/mcp-builder/SKILL.md +1 -76
- package/.agent/skills/micro-interaction/SKILL.md +19 -87
- package/.agent/skills/mobile-design/SKILL.md +1 -76
- package/.agent/skills/monorepo-management/SKILL.md +1 -76
- package/.agent/skills/morphing-icons/SKILL.md +1 -76
- package/.agent/skills/motion-engineering/SKILL.md +1 -76
- package/.agent/skills/nextjs-react-expert/SKILL.md +1 -76
- package/.agent/skills/nodejs-best-practices/SKILL.md +1 -76
- package/.agent/skills/observability/SKILL.md +1 -76
- package/.agent/skills/opentelemetry-observability/SKILL.md +1 -75
- package/.agent/skills/page-transition-animation/SKILL.md +1 -76
- package/.agent/skills/parallel-agents/SKILL.md +1 -76
- package/.agent/skills/performance-profiling/SKILL.md +1 -76
- package/.agent/skills/plan-writing/SKILL.md +1 -76
- package/.agent/skills/platform-engineer/SKILL.md +1 -76
- package/.agent/skills/platform-engineering-opentofu/SKILL.md +1 -75
- package/.agent/skills/playwright-ai-e2e/SKILL.md +1 -75
- package/.agent/skills/playwright-best-practices/SKILL.md +1 -76
- package/.agent/skills/polish/SKILL.md +1 -76
- package/.agent/skills/powershell-windows/SKILL.md +1 -76
- package/.agent/skills/pricing-page/SKILL.md +1 -76
- package/.agent/skills/product-aware-heuristics/SKILL.md +1 -76
- package/.agent/skills/progressive-blur/SKILL.md +1 -76
- package/.agent/skills/project-idioms/SKILL.md +1 -76
- package/.agent/skills/property-based-testing/SKILL.md +1 -75
- package/.agent/skills/python-patterns/SKILL.md +1 -76
- package/.agent/skills/python-pro/SKILL.md +1 -76
- package/.agent/skills/quieter/SKILL.md +1 -76
- package/.agent/skills/react-doctor/SKILL.md +1 -76
- package/.agent/skills/react-specialist/SKILL.md +1 -76
- package/.agent/skills/readme-builder/SKILL.md +1 -76
- package/.agent/skills/realtime-patterns/SKILL.md +1 -76
- package/.agent/skills/red-team-tactics/SKILL.md +1 -76
- package/.agent/skills/redesign-skill/SKILL.md +1 -76
- package/.agent/skills/review-animations/SKILL.md +1 -76
- package/.agent/skills/rust-pro/SKILL.md +1 -76
- package/.agent/skills/seo-fundamentals/SKILL.md +1 -76
- package/.agent/skills/server-management/SKILL.md +1 -76
- package/.agent/skills/shadcn-ui-expert/SKILL.md +1 -76
- package/.agent/skills/shape/SKILL.md +1 -76
- package/.agent/skills/skill-creator/SKILL.md +127 -86
- package/.agent/skills/soft-skill/SKILL.md +1 -76
- package/.agent/skills/sounds-on-the-web/SKILL.md +1 -76
- package/.agent/skills/sql-pro/SKILL.md +1 -76
- package/.agent/skills/supabase-postgres-best-practices/SKILL.md +1 -76
- package/.agent/skills/svg-animation/SKILL.md +1 -76
- package/.agent/skills/swiftui-expert/SKILL.md +1 -76
- package/.agent/skills/swiss-design/SKILL.md +1 -76
- package/.agent/skills/system-design-pro/SKILL.md +1 -76
- package/.agent/skills/systematic-debugging/SKILL.md +2 -76
- package/.agent/skills/systematic-debugging/condition-based-waiting.md +14 -9
- package/.agent/skills/systematic-debugging/defense-in-depth.md +9 -3
- package/.agent/skills/systematic-debugging/root-cause-tracing.md +14 -0
- package/.agent/skills/tailwind-patterns/SKILL.md +1 -76
- package/.agent/skills/taste-skill/SKILL.md +1 -76
- package/.agent/skills/tdd-workflow/SKILL.md +8 -82
- package/.agent/skills/test-result-analyzer/SKILL.md +1 -76
- package/.agent/skills/testing-patterns/SKILL.md +1 -76
- package/.agent/skills/thermo-nuclear-code-quality-review/SKILL.md +1 -76
- package/.agent/skills/thinking-protocol/SKILL.md +1 -77
- package/.agent/skills/to-spring-or-not-to-spring/SKILL.md +1 -76
- package/.agent/skills/transitions-dev/SKILL.md +1 -76
- package/.agent/skills/trend-researcher/SKILL.md +1 -76
- package/.agent/skills/typescript-advanced/SKILL.md +1 -76
- package/.agent/skills/typeset/SKILL.md +1 -76
- package/.agent/skills/ui-reasoning-engine/SKILL.md +1 -76
- package/.agent/skills/ui-skill-packs/SKILL.md +1 -76
- package/.agent/skills/ui-skills-root/SKILL.md +1 -76
- package/.agent/skills/ui-ux-pro-max/SKILL.md +1 -76
- package/.agent/skills/ui-ux-researcher/SKILL.md +1 -76
- package/.agent/skills/vector-search-pgvector/SKILL.md +1 -75
- package/.agent/skills/verification-before-completion/SKILL.md +20 -91
- package/.agent/skills/vue-expert/SKILL.md +1 -76
- package/.agent/skills/vulnerability-scanner/SKILL.md +1 -76
- package/.agent/skills/web-accessibility-auditor/SKILL.md +1 -76
- package/.agent/skills/web-design-guidelines/SKILL.md +1 -76
- package/.agent/skills/web-quality-audit/SKILL.md +1 -76
- package/.agent/skills/webapp-testing/SKILL.md +1 -76
- package/.agent/skills/webgpu-performance/SKILL.md +1 -76
- package/.agent/skills/whimsy-injector/SKILL.md +1 -76
- package/.agent/skills/workflow-optimizer/SKILL.md +1 -76
- package/.agent/skills/zero-trust-passkeys/SKILL.md +1 -75
- package/.agent/templates/DESIGN.md +312 -290
- package/.agent/templates/sdd/task-reviewer-prompt.md +2 -2
- package/.agent/workflows/audit-live.md +4 -3
- package/.agent/workflows/brainstorm.md +1 -0
- package/.agent/workflows/context.md +9 -7
- package/.agent/workflows/generate.md +1 -1
- package/.agent/workflows/minimal.md +3 -2
- package/.agent/workflows/orchestrate.md +1 -1
- package/.agent/workflows/plan.md +1 -1
- package/.agent/workflows/review-ai.md +1 -1
- package/.agent/workflows/sdd.md +15 -0
- package/.agent/workflows/skill-enhancement-engine.md +17 -21
- package/.agent/workflows/super-prompt.md +25 -24
- package/.agent/workflows/swarm.md +1 -1
- package/.agent/workflows/tribunal-backend.md +1 -1
- package/.agent/workflows/tribunal-cicd.md +1 -1
- package/.agent/workflows/tribunal-database.md +1 -1
- package/.agent/workflows/tribunal-frontend.md +1 -1
- package/.agent/workflows/tribunal-full.md +9 -9
- package/.agent/workflows/tribunal-mobile.md +1 -1
- package/.agent/workflows/tribunal-speed.md +1 -1
- package/.agent/workflows/tribunal-ui.md +1 -1
- package/.agents/skills/12-principles-of-animation/SKILL.md +1 -76
- package/.agents/skills/60fps-animation/SKILL.md +4 -77
- package/.agents/skills/accessible-animation/SKILL.md +9 -86
- package/.agents/skills/adapt/SKILL.md +1 -76
- package/.agents/skills/advanced-rag-pipelines/SKILL.md +1 -76
- package/.agents/skills/agent-organizer/SKILL.md +1 -76
- package/.agents/skills/agentic-patterns/SKILL.md +1 -76
- package/.agents/skills/agentic-workflows-2026/SKILL.md +1 -75
- package/.agents/skills/ai-app-hardening/SKILL.md +1 -75
- package/.agents/skills/ai-prompt-injection-defense/SKILL.md +1 -76
- package/.agents/skills/animation-on-scroll/SKILL.md +16 -87
- package/.agents/skills/animation-systems/SKILL.md +15 -90
- package/.agents/skills/antfu-conventions/SKILL.md +0 -75
- package/.agents/skills/api-patterns/SKILL.md +1 -76
- package/.agents/skills/api-security-auditor/SKILL.md +1 -76
- package/.agents/skills/app-builder/SKILL.md +1 -76
- package/.agents/skills/appflow-wireframe/SKILL.md +1 -78
- package/.agents/skills/apple-design/SKILL.md +1 -76
- package/.agents/skills/architecture/SKILL.md +1 -76
- package/.agents/skills/audit-and-fix/SKILL.md +41 -77
- package/.agents/skills/authentication-best-practices/SKILL.md +1 -76
- package/.agents/skills/backend-security-expert/SKILL.md +1 -76
- package/.agents/skills/baseline-ui/SKILL.md +1 -76
- package/.agents/skills/bash-linux/SKILL.md +1 -76
- package/.agents/skills/behavioral-modes/SKILL.md +1 -76
- package/.agents/skills/better-colors/SKILL.md +1 -76
- package/.agents/skills/better-typography/SKILL.md +1 -75
- package/.agents/skills/better-ui/SKILL.md +18 -81
- package/.agents/skills/bolder/SKILL.md +1 -76
- package/.agents/skills/brainstorming/SKILL.md +1 -75
- package/.agents/skills/browser-audit/SKILL.md +15 -83
- package/.agents/skills/browser-native-ai/SKILL.md +1 -76
- package/.agents/skills/build-primitive/SKILL.md +1 -76
- package/.agents/skills/building-native-ui/SKILL.md +1 -76
- package/.agents/skills/cicd-pro/SKILL.md +1 -76
- package/.agents/skills/clarify/SKILL.md +1 -76
- package/.agents/skills/clean-code/SKILL.md +1 -76
- package/.agents/skills/cloud-architect/SKILL.md +1 -76
- package/.agents/skills/cobejs/SKILL.md +1 -76
- package/.agents/skills/code-review-checklist/SKILL.md +1 -76
- package/.agents/skills/codebase-design/SKILL.md +1 -76
- package/.agents/skills/colorize/SKILL.md +1 -76
- package/.agents/skills/compact-landing/SKILL.md +1 -76
- package/.agents/skills/company-logos/SKILL.md +1 -76
- package/.agents/skills/config-validator/SKILL.md +1 -76
- package/.agents/skills/containerization-pro/SKILL.md +1 -76
- package/.agents/skills/context-engineering-pro/SKILL.md +1 -75
- package/.agents/skills/create-design-md/SKILL.md +1 -76
- package/.agents/skills/critique/SKILL.md +1 -76
- package/.agents/skills/csharp-developer/SKILL.md +1 -76
- package/.agents/skills/data-validation-schemas/SKILL.md +1 -76
- package/.agents/skills/database-design/SKILL.md +1 -76
- package/.agents/skills/delight/SKILL.md +1 -76
- package/.agents/skills/deployment-procedures/SKILL.md +1 -76
- package/.agents/skills/design-lab/SKILL.md +0 -75
- package/.agents/skills/devops-engineer/SKILL.md +1 -76
- package/.agents/skills/devops-incident-responder/SKILL.md +1 -76
- package/.agents/skills/diagnosing-bugs/SKILL.md +0 -75
- package/.agents/skills/distill/SKILL.md +1 -76
- package/.agents/skills/documentation-templates/SKILL.md +1 -76
- package/.agents/skills/domain-modeling/SKILL.md +1 -76
- package/.agents/skills/duckdb-analytical-sql/SKILL.md +1 -75
- package/.agents/skills/edge-ai-mobile/SKILL.md +1 -75
- package/.agents/skills/edge-computing/SKILL.md +1 -76
- package/.agents/skills/emil-design-eng/SKILL.md +1 -76
- package/.agents/skills/error-resilience/SKILL.md +1 -76
- package/.agents/skills/expo-router-v4/SKILL.md +1 -75
- package/.agents/skills/extract-design-system/SKILL.md +1 -76
- package/.agents/skills/fabel-protocol/SKILL.md +1 -76
- package/.agents/skills/fixing-accessibility/SKILL.md +1 -76
- package/.agents/skills/fixing-metadata/SKILL.md +1 -76
- package/.agents/skills/fixing-motion-performance/SKILL.md +1 -76
- package/.agents/skills/framer-motion-expert/SKILL.md +1 -76
- package/.agents/skills/frontend-design/SKILL.md +1 -76
- package/.agents/skills/frontend-security-expert/SKILL.md +1 -76
- package/.agents/skills/game-design-expert/SKILL.md +1 -76
- package/.agents/skills/game-engineering-expert/SKILL.md +1 -76
- package/.agents/skills/generative-ui-expert/SKILL.md +1 -76
- package/.agents/skills/geo-fundamentals/SKILL.md +1 -76
- package/.agents/skills/git-pro/SKILL.md +1 -76
- package/.agents/skills/github-operations/SKILL.md +1 -76
- package/.agents/skills/gpt-taste/SKILL.md +1 -76
- package/.agents/skills/gsap-core/SKILL.md +1 -76
- package/.agents/skills/gsap-frameworks/SKILL.md +1 -76
- package/.agents/skills/gsap-performance/SKILL.md +1 -76
- package/.agents/skills/gsap-plugins/SKILL.md +1 -76
- package/.agents/skills/gsap-react/SKILL.md +1 -76
- package/.agents/skills/gsap-scrolltrigger/SKILL.md +1 -76
- package/.agents/skills/gsap-timeline/SKILL.md +1 -76
- package/.agents/skills/gsap-utils/SKILL.md +1 -76
- package/.agents/skills/harden/SKILL.md +1 -76
- package/.agents/skills/harness-protocol/SKILL.md +1 -76
- package/.agents/skills/i18n-localization/SKILL.md +1 -76
- package/.agents/skills/impeccable/SKILL.md +1 -76
- package/.agents/skills/improve-codebase-architecture/SKILL.md +1 -76
- package/.agents/skills/improve-ui/SKILL.md +1 -76
- package/.agents/skills/intelligent-routing/SKILL.md +2 -87
- package/.agents/skills/knowledge-graph/SKILL.md +1 -76
- package/.agents/skills/landing-page/SKILL.md +1 -76
- package/.agents/skills/lint-and-validate/SKILL.md +1 -76
- package/.agents/skills/llm-engineering/SKILL.md +1 -76
- package/.agents/skills/local-first/SKILL.md +1 -76
- package/.agents/skills/local-first-architecture/SKILL.md +1 -76
- package/.agents/skills/lottie-animation/SKILL.md +1 -76
- package/.agents/skills/marquee-loop/SKILL.md +1 -76
- package/.agents/skills/masked-reveal/SKILL.md +1 -76
- package/.agents/skills/mcp-builder/SKILL.md +1 -76
- package/.agents/skills/micro-interaction/SKILL.md +19 -87
- package/.agents/skills/mobile-design/SKILL.md +1 -76
- package/.agents/skills/monorepo-management/SKILL.md +1 -76
- package/.agents/skills/morphing-icons/SKILL.md +1 -76
- package/.agents/skills/motion-engineering/SKILL.md +1 -76
- package/.agents/skills/nextjs-react-expert/SKILL.md +1 -76
- package/.agents/skills/nodejs-best-practices/SKILL.md +1 -76
- package/.agents/skills/observability/SKILL.md +1 -76
- package/.agents/skills/opentelemetry-observability/SKILL.md +1 -75
- package/.agents/skills/page-transition-animation/SKILL.md +1 -76
- package/.agents/skills/parallel-agents/SKILL.md +1 -76
- package/.agents/skills/performance-profiling/SKILL.md +1 -76
- package/.agents/skills/plan-writing/SKILL.md +1 -76
- package/.agents/skills/platform-engineer/SKILL.md +1 -76
- package/.agents/skills/platform-engineering-opentofu/SKILL.md +1 -75
- package/.agents/skills/playwright-ai-e2e/SKILL.md +1 -75
- package/.agents/skills/playwright-best-practices/SKILL.md +1 -76
- package/.agents/skills/polish/SKILL.md +1 -76
- package/.agents/skills/powershell-windows/SKILL.md +1 -76
- package/.agents/skills/pricing-page/SKILL.md +1 -76
- package/.agents/skills/product-aware-heuristics/SKILL.md +1 -76
- package/.agents/skills/progressive-blur/SKILL.md +1 -76
- package/.agents/skills/project-idioms/SKILL.md +1 -76
- package/.agents/skills/property-based-testing/SKILL.md +1 -75
- package/.agents/skills/python-patterns/SKILL.md +1 -76
- package/.agents/skills/python-pro/SKILL.md +1 -76
- package/.agents/skills/quieter/SKILL.md +1 -76
- package/.agents/skills/react-doctor/SKILL.md +1 -76
- package/.agents/skills/react-specialist/SKILL.md +1 -76
- package/.agents/skills/readme-builder/SKILL.md +1 -76
- package/.agents/skills/realtime-patterns/SKILL.md +1 -76
- package/.agents/skills/red-team-tactics/SKILL.md +1 -76
- package/.agents/skills/redesign-skill/SKILL.md +1 -76
- package/.agents/skills/review-animations/SKILL.md +1 -76
- package/.agents/skills/rust-pro/SKILL.md +1 -76
- package/.agents/skills/seo-fundamentals/SKILL.md +1 -76
- package/.agents/skills/server-management/SKILL.md +1 -76
- package/.agents/skills/shadcn-ui-expert/SKILL.md +1 -76
- package/.agents/skills/shape/SKILL.md +1 -76
- package/.agents/skills/skill-creator/SKILL.md +127 -86
- package/.agents/skills/soft-skill/SKILL.md +1 -76
- package/.agents/skills/sounds-on-the-web/SKILL.md +1 -76
- package/.agents/skills/sql-pro/SKILL.md +1 -76
- package/.agents/skills/supabase-postgres-best-practices/SKILL.md +1 -76
- package/.agents/skills/svg-animation/SKILL.md +1 -76
- package/.agents/skills/swiftui-expert/SKILL.md +1 -76
- package/.agents/skills/swiss-design/SKILL.md +1 -76
- package/.agents/skills/system-design-pro/SKILL.md +1 -76
- package/.agents/skills/systematic-debugging/SKILL.md +2 -76
- package/.agents/skills/systematic-debugging/condition-based-waiting.md +14 -9
- package/.agents/skills/systematic-debugging/defense-in-depth.md +9 -3
- package/.agents/skills/systematic-debugging/root-cause-tracing.md +14 -0
- package/.agents/skills/tailwind-patterns/SKILL.md +1 -76
- package/.agents/skills/taste-skill/SKILL.md +1 -76
- package/.agents/skills/tdd-workflow/SKILL.md +8 -82
- package/.agents/skills/test-result-analyzer/SKILL.md +1 -76
- package/.agents/skills/testing-patterns/SKILL.md +1 -76
- package/.agents/skills/thermo-nuclear-code-quality-review/SKILL.md +1 -76
- package/.agents/skills/thinking-protocol/SKILL.md +1 -77
- package/.agents/skills/to-spring-or-not-to-spring/SKILL.md +1 -76
- package/.agents/skills/transitions-dev/SKILL.md +1 -76
- package/.agents/skills/trend-researcher/SKILL.md +1 -76
- package/.agents/skills/typescript-advanced/SKILL.md +1 -76
- package/.agents/skills/typeset/SKILL.md +1 -76
- package/.agents/skills/ui-reasoning-engine/SKILL.md +1 -76
- package/.agents/skills/ui-skill-packs/SKILL.md +1 -76
- package/.agents/skills/ui-skills-root/SKILL.md +1 -76
- package/.agents/skills/ui-ux-pro-max/SKILL.md +1 -76
- package/.agents/skills/ui-ux-researcher/SKILL.md +1 -76
- package/.agents/skills/vector-search-pgvector/SKILL.md +1 -75
- package/.agents/skills/verification-before-completion/SKILL.md +20 -91
- package/.agents/skills/vue-expert/SKILL.md +1 -76
- package/.agents/skills/vulnerability-scanner/SKILL.md +1 -76
- package/.agents/skills/web-accessibility-auditor/SKILL.md +1 -76
- package/.agents/skills/web-design-guidelines/SKILL.md +1 -76
- package/.agents/skills/web-quality-audit/SKILL.md +1 -76
- package/.agents/skills/webapp-testing/SKILL.md +1 -76
- package/.agents/skills/webgpu-performance/SKILL.md +1 -76
- package/.agents/skills/whimsy-injector/SKILL.md +1 -76
- package/.agents/skills/workflow-optimizer/SKILL.md +1 -76
- package/.agents/skills/zero-trust-passkeys/SKILL.md +1 -75
- package/.codex-plugin/plugin.json +1 -5
- package/.kimi-plugin/plugin.json +1 -5
- package/.opencode/INSTALL.md +1 -0
- package/.opencode/plugins/tribunal.js +15 -6
- package/.pi/extensions/tribunal.ts +26 -29
- package/AGENTS.md +15 -13
- package/CLAUDE.md +3 -1
- package/README.md +23 -16
- package/bin/adapter-install.js +1 -1
- package/bin/mcp-server.js +88 -58
- package/bin/wrapper.js +22 -2
- package/dist/commands/init.js +25 -11
- package/dist/tui/banner.js +77 -77
- package/gemini-extension.json +1 -1
- package/package.json +13 -10
- package/plugin.json +1 -1
- package/scripts/apply-version.js +2 -2
- package/scripts/audit_skill_sdo.js +6 -4
- package/scripts/context_compiler.js +256 -83
- package/scripts/modernize_skills.js +25 -11
- package/scripts/package-cores.js +4 -1
- package/scripts/skill_enhancement_engine.js +212 -77
- package/scripts/telemetry_gc.js +156 -0
- package/scripts/validate-payload.js +1 -6
- package/skills/12-principles-of-animation/SKILL.md +1 -76
- package/skills/60fps-animation/SKILL.md +4 -77
- package/skills/accessible-animation/SKILL.md +9 -86
- package/skills/adapt/SKILL.md +1 -76
- package/skills/advanced-rag-pipelines/SKILL.md +1 -76
- package/skills/agent-organizer/SKILL.md +1 -76
- package/skills/agentic-patterns/SKILL.md +1 -76
- package/skills/agentic-workflows-2026/SKILL.md +1 -75
- package/skills/ai-app-hardening/SKILL.md +1 -75
- package/skills/ai-prompt-injection-defense/SKILL.md +1 -76
- package/skills/animation-on-scroll/SKILL.md +16 -87
- package/skills/animation-systems/SKILL.md +15 -90
- package/skills/antfu-conventions/SKILL.md +0 -75
- package/skills/api-patterns/SKILL.md +1 -76
- package/skills/api-security-auditor/SKILL.md +1 -76
- package/skills/app-builder/SKILL.md +1 -76
- package/skills/appflow-wireframe/SKILL.md +1 -78
- package/skills/apple-design/SKILL.md +1 -76
- package/skills/architecture/SKILL.md +1 -76
- package/skills/audit-and-fix/SKILL.md +41 -77
- package/skills/authentication-best-practices/SKILL.md +1 -76
- package/skills/backend-security-expert/SKILL.md +1 -76
- package/skills/baseline-ui/SKILL.md +1 -76
- package/skills/bash-linux/SKILL.md +1 -76
- package/skills/behavioral-modes/SKILL.md +1 -76
- package/skills/better-colors/SKILL.md +1 -76
- package/skills/better-typography/SKILL.md +1 -75
- package/skills/better-ui/SKILL.md +18 -81
- package/skills/bolder/SKILL.md +1 -76
- package/skills/brainstorming/SKILL.md +1 -75
- package/skills/browser-audit/SKILL.md +15 -83
- package/skills/browser-native-ai/SKILL.md +1 -76
- package/skills/build-primitive/SKILL.md +1 -76
- package/skills/building-native-ui/SKILL.md +1 -76
- package/skills/cicd-pro/SKILL.md +1 -76
- package/skills/clarify/SKILL.md +1 -76
- package/skills/clean-code/SKILL.md +1 -76
- package/skills/cloud-architect/SKILL.md +1 -76
- package/skills/cobejs/SKILL.md +1 -76
- package/skills/code-review-checklist/SKILL.md +1 -76
- package/skills/codebase-design/SKILL.md +1 -76
- package/skills/colorize/SKILL.md +1 -76
- package/skills/compact-landing/SKILL.md +1 -76
- package/skills/company-logos/SKILL.md +1 -76
- package/skills/config-validator/SKILL.md +1 -76
- package/skills/containerization-pro/SKILL.md +1 -76
- package/skills/context-engineering-pro/SKILL.md +1 -75
- package/skills/create-design-md/SKILL.md +1 -76
- package/skills/critique/SKILL.md +1 -76
- package/skills/csharp-developer/SKILL.md +1 -76
- package/skills/data-validation-schemas/SKILL.md +1 -76
- package/skills/database-design/SKILL.md +1 -76
- package/skills/delight/SKILL.md +1 -76
- package/skills/deployment-procedures/SKILL.md +1 -76
- package/skills/design-lab/SKILL.md +0 -75
- package/skills/devops-engineer/SKILL.md +1 -76
- package/skills/devops-incident-responder/SKILL.md +1 -76
- package/skills/diagnosing-bugs/SKILL.md +0 -75
- package/skills/distill/SKILL.md +1 -76
- package/skills/documentation-templates/SKILL.md +1 -76
- package/skills/domain-modeling/SKILL.md +1 -76
- package/skills/duckdb-analytical-sql/SKILL.md +1 -75
- package/skills/edge-ai-mobile/SKILL.md +1 -75
- package/skills/edge-computing/SKILL.md +1 -76
- package/skills/emil-design-eng/SKILL.md +1 -76
- package/skills/error-resilience/SKILL.md +1 -76
- package/skills/expo-router-v4/SKILL.md +1 -75
- package/skills/extract-design-system/SKILL.md +1 -76
- package/skills/fabel-protocol/SKILL.md +1 -76
- package/skills/fixing-accessibility/SKILL.md +1 -76
- package/skills/fixing-metadata/SKILL.md +1 -76
- package/skills/fixing-motion-performance/SKILL.md +1 -76
- package/skills/framer-motion-expert/SKILL.md +1 -76
- package/skills/frontend-design/SKILL.md +1 -76
- package/skills/frontend-security-expert/SKILL.md +1 -76
- package/skills/game-design-expert/SKILL.md +1 -76
- package/skills/game-engineering-expert/SKILL.md +1 -76
- package/skills/generative-ui-expert/SKILL.md +1 -76
- package/skills/geo-fundamentals/SKILL.md +1 -76
- package/skills/git-pro/SKILL.md +1 -76
- package/skills/github-operations/SKILL.md +1 -76
- package/skills/gpt-taste/SKILL.md +1 -76
- package/skills/gsap-core/SKILL.md +1 -76
- package/skills/gsap-frameworks/SKILL.md +1 -76
- package/skills/gsap-performance/SKILL.md +1 -76
- package/skills/gsap-plugins/SKILL.md +1 -76
- package/skills/gsap-react/SKILL.md +1 -76
- package/skills/gsap-scrolltrigger/SKILL.md +1 -76
- package/skills/gsap-timeline/SKILL.md +1 -76
- package/skills/gsap-utils/SKILL.md +1 -76
- package/skills/harden/SKILL.md +1 -76
- package/skills/harness-protocol/SKILL.md +1 -76
- package/skills/i18n-localization/SKILL.md +1 -76
- package/skills/impeccable/SKILL.md +1 -76
- package/skills/improve-codebase-architecture/SKILL.md +1 -76
- package/skills/improve-ui/SKILL.md +1 -76
- package/skills/intelligent-routing/SKILL.md +2 -87
- package/skills/knowledge-graph/SKILL.md +1 -76
- package/skills/landing-page/SKILL.md +1 -76
- package/skills/lint-and-validate/SKILL.md +1 -76
- package/skills/llm-engineering/SKILL.md +1 -76
- package/skills/local-first/SKILL.md +1 -76
- package/skills/local-first-architecture/SKILL.md +1 -76
- package/skills/lottie-animation/SKILL.md +1 -76
- package/skills/marquee-loop/SKILL.md +1 -76
- package/skills/masked-reveal/SKILL.md +1 -76
- package/skills/mcp-builder/SKILL.md +1 -76
- package/skills/micro-interaction/SKILL.md +19 -87
- package/skills/mobile-design/SKILL.md +1 -76
- package/skills/monorepo-management/SKILL.md +1 -76
- package/skills/morphing-icons/SKILL.md +1 -76
- package/skills/motion-engineering/SKILL.md +1 -76
- package/skills/nextjs-react-expert/SKILL.md +1 -76
- package/skills/nodejs-best-practices/SKILL.md +1 -76
- package/skills/observability/SKILL.md +1 -76
- package/skills/opentelemetry-observability/SKILL.md +1 -75
- package/skills/page-transition-animation/SKILL.md +1 -76
- package/skills/parallel-agents/SKILL.md +1 -76
- package/skills/performance-profiling/SKILL.md +1 -76
- package/skills/plan-writing/SKILL.md +1 -76
- package/skills/platform-engineer/SKILL.md +1 -76
- package/skills/platform-engineering-opentofu/SKILL.md +1 -75
- package/skills/playwright-ai-e2e/SKILL.md +1 -75
- package/skills/playwright-best-practices/SKILL.md +1 -76
- package/skills/polish/SKILL.md +1 -76
- package/skills/powershell-windows/SKILL.md +1 -76
- package/skills/pricing-page/SKILL.md +1 -76
- package/skills/product-aware-heuristics/SKILL.md +1 -76
- package/skills/progressive-blur/SKILL.md +1 -76
- package/skills/project-idioms/SKILL.md +1 -76
- package/skills/property-based-testing/SKILL.md +1 -75
- package/skills/python-patterns/SKILL.md +1 -76
- package/skills/python-pro/SKILL.md +1 -76
- package/skills/quieter/SKILL.md +1 -76
- package/skills/react-doctor/SKILL.md +1 -76
- package/skills/react-specialist/SKILL.md +1 -76
- package/skills/readme-builder/SKILL.md +1 -76
- package/skills/realtime-patterns/SKILL.md +1 -76
- package/skills/red-team-tactics/SKILL.md +1 -76
- package/skills/redesign-skill/SKILL.md +1 -76
- package/skills/review-animations/SKILL.md +1 -76
- package/skills/rust-pro/SKILL.md +1 -76
- package/skills/seo-fundamentals/SKILL.md +1 -76
- package/skills/server-management/SKILL.md +1 -76
- package/skills/shadcn-ui-expert/SKILL.md +1 -76
- package/skills/shape/SKILL.md +1 -76
- package/skills/skill-creator/SKILL.md +127 -86
- package/skills/soft-skill/SKILL.md +1 -76
- package/skills/sounds-on-the-web/SKILL.md +1 -76
- package/skills/sql-pro/SKILL.md +1 -76
- package/skills/supabase-postgres-best-practices/SKILL.md +1 -76
- package/skills/svg-animation/SKILL.md +1 -76
- package/skills/swiftui-expert/SKILL.md +1 -76
- package/skills/swiss-design/SKILL.md +1 -76
- package/skills/system-design-pro/SKILL.md +1 -76
- package/skills/systematic-debugging/SKILL.md +2 -76
- package/skills/systematic-debugging/condition-based-waiting.md +14 -9
- package/skills/systematic-debugging/defense-in-depth.md +9 -3
- package/skills/systematic-debugging/root-cause-tracing.md +14 -0
- package/skills/tailwind-patterns/SKILL.md +1 -76
- package/skills/taste-skill/SKILL.md +1 -76
- package/skills/tdd-workflow/SKILL.md +8 -82
- package/skills/test-result-analyzer/SKILL.md +1 -76
- package/skills/testing-patterns/SKILL.md +1 -76
- package/skills/thermo-nuclear-code-quality-review/SKILL.md +1 -76
- package/skills/thinking-protocol/SKILL.md +1 -77
- package/skills/to-spring-or-not-to-spring/SKILL.md +1 -76
- package/skills/transitions-dev/SKILL.md +1 -76
- package/skills/trend-researcher/SKILL.md +1 -76
- package/skills/typescript-advanced/SKILL.md +1 -76
- package/skills/typeset/SKILL.md +1 -76
- package/skills/ui-reasoning-engine/SKILL.md +1 -76
- package/skills/ui-skill-packs/SKILL.md +1 -76
- package/skills/ui-skills-root/SKILL.md +1 -76
- package/skills/ui-ux-pro-max/SKILL.md +1 -76
- package/skills/ui-ux-researcher/SKILL.md +1 -76
- package/skills/vector-search-pgvector/SKILL.md +1 -75
- package/skills/verification-before-completion/SKILL.md +20 -91
- package/skills/vue-expert/SKILL.md +1 -76
- package/skills/vulnerability-scanner/SKILL.md +1 -76
- package/skills/web-accessibility-auditor/SKILL.md +1 -76
- package/skills/web-design-guidelines/SKILL.md +1 -76
- package/skills/web-quality-audit/SKILL.md +1 -76
- package/skills/webapp-testing/SKILL.md +1 -76
- package/skills/webgpu-performance/SKILL.md +1 -76
- package/skills/whimsy-injector/SKILL.md +1 -76
- package/skills/workflow-optimizer/SKILL.md +1 -76
- package/skills/zero-trust-passkeys/SKILL.md +1 -75
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* memory_engine.js — Tribunal Kit 4-Type Taxonomy Persistent Memory Engine
|
|
4
4
|
* ==============================================================================
|
|
5
|
-
*
|
|
5
|
+
* Persistent, file-backed memory storage with atomic locking, budget-constrained
|
|
6
|
+
* recall, and human-readable MEMORY.md projection.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* - working: Session scratch (cleared on restart)
|
|
8
|
+
* Fully unified and cross-compatible with:
|
|
9
|
+
* - Rust Core: crates/core/src/commands/memory.rs
|
|
10
|
+
* - TypeScript CLI: dist/commands/memory.js
|
|
11
|
+
* - Tribunal MCP Server
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Memory Types:
|
|
14
|
+
* - semantic: Permanent project facts and rules (no expiration)
|
|
15
|
+
* - procedural: How-to recipes and steps (no expiration)
|
|
16
|
+
* - episodic: Session events and decisions (auto-decays after 30 days)
|
|
17
|
+
* - working: Current session scratchpad (cleared on gc/session reset)
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* const { results } = mem.recall('typescript', 2000);
|
|
19
|
+
* Storage Architecture:
|
|
20
|
+
* - Index: .agent/history/memory/.memory.idx (atomic JSON index)
|
|
21
|
+
* - Projection: .agent/history/memory/MEMORY.md (human-readable markdown)
|
|
22
|
+
* - Lock: .agent/history/memory/.memory.idx.lock
|
|
24
23
|
*
|
|
25
|
-
* Zero external dependencies beyond
|
|
24
|
+
* Zero external dependencies beyond native Node.js core modules.
|
|
26
25
|
*/
|
|
27
26
|
|
|
28
27
|
'use strict';
|
|
@@ -30,120 +29,117 @@
|
|
|
30
29
|
const fs = require('fs');
|
|
31
30
|
const path = require('path');
|
|
32
31
|
|
|
33
|
-
//
|
|
34
|
-
let Database = null;
|
|
35
|
-
try {
|
|
36
|
-
Database = require('better-sqlite3');
|
|
37
|
-
} catch (_err) {
|
|
38
|
-
// Fallback to in-memory storage if better-sqlite3 not available
|
|
39
|
-
console.warn('[Memory] better-sqlite3 not available, using in-memory fallback');
|
|
40
|
-
}
|
|
32
|
+
// ─── Constants & Configuration ────────────────────────────────────────────────
|
|
41
33
|
|
|
42
|
-
|
|
34
|
+
const MEMORY_DIR = path.join('history', 'memory');
|
|
35
|
+
const INDEX_FILE = '.memory.idx';
|
|
36
|
+
const PROJECTION_FILE = 'MEMORY.md';
|
|
37
|
+
const MAX_ENTRIES = 500;
|
|
38
|
+
const EPISODIC_TTL_DAYS = 30;
|
|
39
|
+
const DEFAULT_BUDGET = 2000;
|
|
43
40
|
|
|
44
41
|
const MEMORY_TYPES = {
|
|
45
|
-
SEMANTIC: 'semantic',
|
|
46
|
-
PROCEDURAL: 'procedural',
|
|
47
|
-
EPISODIC: 'episodic',
|
|
48
|
-
WORKING: 'working',
|
|
42
|
+
SEMANTIC: 'semantic',
|
|
43
|
+
PROCEDURAL: 'procedural',
|
|
44
|
+
EPISODIC: 'episodic',
|
|
45
|
+
WORKING: 'working',
|
|
49
46
|
};
|
|
50
47
|
|
|
51
48
|
const VALID_TYPES = Object.values(MEMORY_TYPES);
|
|
52
49
|
|
|
53
|
-
|
|
50
|
+
const TYPE_PRIORITY = {
|
|
51
|
+
semantic: 1.0,
|
|
52
|
+
procedural: 0.9,
|
|
53
|
+
episodic: 0.7,
|
|
54
|
+
working: 0.5,
|
|
55
|
+
};
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
constructor() {
|
|
57
|
-
this.memories = new Map();
|
|
58
|
-
this.nextId = 1;
|
|
59
|
-
}
|
|
57
|
+
// ─── Utility Helpers ──────────────────────────────────────────────────────────
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
function estimateTokens(text) {
|
|
60
|
+
if (!text) return 0;
|
|
61
|
+
return Math.ceil(text.length / 4);
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// INSERT
|
|
68
|
-
if (sql.includes('INSERT INTO memories')) {
|
|
69
|
-
const [type, content, tags, priority, expiresAt] = params;
|
|
70
|
-
const id = self.nextId++;
|
|
71
|
-
self.memories.set(id, {
|
|
72
|
-
id,
|
|
73
|
-
type,
|
|
74
|
-
content,
|
|
75
|
-
tags: JSON.parse(tags),
|
|
76
|
-
priority,
|
|
77
|
-
created_at: new Date().toISOString(),
|
|
78
|
-
accessed_at: new Date().toISOString(),
|
|
79
|
-
expires_at: expiresAt,
|
|
80
|
-
access_count: 0,
|
|
81
|
-
});
|
|
82
|
-
return { lastInsertRowid: id, changes: 1 };
|
|
83
|
-
}
|
|
84
|
-
// UPDATE
|
|
85
|
-
if (sql.includes('UPDATE memories')) {
|
|
86
|
-
for (const [_id, mem] of self.memories) {
|
|
87
|
-
mem.accessed_at = new Date().toISOString();
|
|
88
|
-
mem.access_count++;
|
|
89
|
-
}
|
|
90
|
-
return { changes: self.memories.size };
|
|
91
|
-
}
|
|
92
|
-
// DELETE
|
|
93
|
-
if (sql.includes('DELETE FROM memories')) {
|
|
94
|
-
const before = self.memories.size;
|
|
95
|
-
for (const [id, mem] of self.memories) {
|
|
96
|
-
if (
|
|
97
|
-
mem.type === 'episodic' &&
|
|
98
|
-
mem.expires_at &&
|
|
99
|
-
new Date(mem.expires_at) < new Date()
|
|
100
|
-
) {
|
|
101
|
-
self.memories.delete(id);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return { changes: before - self.memories.size };
|
|
105
|
-
}
|
|
106
|
-
return { changes: 0 };
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
all(...params) {
|
|
110
|
-
const [query] = params;
|
|
111
|
-
const results = [];
|
|
112
|
-
|
|
113
|
-
for (const [_id, mem] of self.memories) {
|
|
114
|
-
// Filter expired
|
|
115
|
-
if (mem.expires_at && new Date(mem.expires_at) < new Date()) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Calculate score
|
|
120
|
-
const relevance = (
|
|
121
|
-
mem.content.toLowerCase().match(new RegExp(query.toLowerCase(), 'g')) || []
|
|
122
|
-
).length;
|
|
123
|
-
const daysSinceAccess =
|
|
124
|
-
(Date.now() - new Date(mem.accessed_at).getTime()) / (1000 * 60 * 60 * 24);
|
|
125
|
-
const score = relevance * 3.0 + daysSinceAccess * -0.1 + mem.priority;
|
|
126
|
-
|
|
127
|
-
results.push({ ...mem, score });
|
|
128
|
-
}
|
|
64
|
+
function nowEpochStr() {
|
|
65
|
+
return `${Math.floor(Date.now() / 1000)}Z`;
|
|
66
|
+
}
|
|
129
67
|
|
|
130
|
-
|
|
131
|
-
|
|
68
|
+
function daysSince(ts) {
|
|
69
|
+
if (!ts) return 0;
|
|
70
|
+
const created = parseInt(String(ts).replace('Z', ''), 10) || 0;
|
|
71
|
+
const now = Math.floor(Date.now() / 1000);
|
|
72
|
+
return Math.max(0, Math.floor((now - created) / 86400));
|
|
73
|
+
}
|
|
132
74
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
75
|
+
// ─── Lock Management ──────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
function acquireLock(indexPath) {
|
|
78
|
+
const lockPath = indexPath + '.lock';
|
|
79
|
+
const maxRetries = 10;
|
|
80
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
81
|
+
try {
|
|
82
|
+
const fd = fs.openSync(lockPath, 'wx');
|
|
83
|
+
fs.closeSync(fd);
|
|
84
|
+
return lockPath;
|
|
85
|
+
} catch (err) {
|
|
86
|
+
if (err.code !== 'EEXIST') {
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
const waitBuf = new Int32Array(new SharedArrayBuffer(4));
|
|
90
|
+
Atomics.wait(waitBuf, 0, 0, 50);
|
|
91
|
+
}
|
|
138
92
|
}
|
|
139
93
|
|
|
140
|
-
|
|
141
|
-
|
|
94
|
+
// Check for stale lock (older than 10s)
|
|
95
|
+
try {
|
|
96
|
+
const stats = fs.statSync(lockPath);
|
|
97
|
+
if (Date.now() - stats.mtimeMs > 10000) {
|
|
98
|
+
fs.unlinkSync(lockPath);
|
|
99
|
+
const fd = fs.openSync(lockPath, 'wx');
|
|
100
|
+
fs.closeSync(fd);
|
|
101
|
+
return lockPath;
|
|
102
|
+
}
|
|
103
|
+
} catch {}
|
|
104
|
+
|
|
105
|
+
throw new Error('Could not acquire lock for memory index');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function releaseLock(lockPath) {
|
|
109
|
+
try {
|
|
110
|
+
if (lockPath && fs.existsSync(lockPath)) {
|
|
111
|
+
fs.unlinkSync(lockPath);
|
|
112
|
+
}
|
|
113
|
+
} catch {}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ─── Scoring Engine ───────────────────────────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
function computeScore(entry, query) {
|
|
119
|
+
if (!query || !entry.content) return 0;
|
|
120
|
+
const queryLower = query.toLowerCase();
|
|
121
|
+
const contentLower = entry.content.toLowerCase();
|
|
122
|
+
|
|
123
|
+
let relevance = 0;
|
|
124
|
+
if (contentLower.includes(queryLower)) {
|
|
125
|
+
relevance = 1.0;
|
|
126
|
+
} else if (entry.tags && entry.tags.some(t => t.toLowerCase().includes(queryLower))) {
|
|
127
|
+
relevance = 0.8;
|
|
128
|
+
} else if (queryLower.split(/\s+/).some(word => word.length > 2 && contentLower.includes(word))) {
|
|
129
|
+
relevance = 0.3;
|
|
142
130
|
}
|
|
143
131
|
|
|
144
|
-
|
|
145
|
-
|
|
132
|
+
if (relevance === 0) return 0;
|
|
133
|
+
|
|
134
|
+
const priority = entry.priority != null ? entry.priority : (TYPE_PRIORITY[entry.memory_type] || 0.5);
|
|
135
|
+
let recency = 0;
|
|
136
|
+
if (entry.memory_type === 'episodic') {
|
|
137
|
+
const age = daysSince(entry.created_at);
|
|
138
|
+
recency = Math.exp(-age / 30);
|
|
146
139
|
}
|
|
140
|
+
const freqBoost = Math.max(0, Math.log(entry.access_count || 1)) * 0.05;
|
|
141
|
+
|
|
142
|
+
return (relevance * priority) + recency + freqBoost;
|
|
147
143
|
}
|
|
148
144
|
|
|
149
145
|
// ─── Memory Engine Class ──────────────────────────────────────────────────────
|
|
@@ -151,300 +147,436 @@ class InMemoryStore {
|
|
|
151
147
|
class MemoryEngine {
|
|
152
148
|
/**
|
|
153
149
|
* Initialize the Memory Engine.
|
|
154
|
-
* @param {string} agentDir - Path to .agent/ directory
|
|
155
|
-
* @param {object} options - Configuration options
|
|
150
|
+
* @param {string} agentDir - Path to .agent/ directory or workspace root
|
|
151
|
+
* @param {object} [options] - Configuration options
|
|
156
152
|
*/
|
|
157
153
|
constructor(agentDir, options = {}) {
|
|
158
|
-
|
|
159
|
-
|
|
154
|
+
let resolved = path.resolve(agentDir || process.cwd());
|
|
155
|
+
// Auto-detect .agent directory if parent workspace given
|
|
156
|
+
if (!resolved.endsWith('.agent') && !resolved.endsWith('.agent' + path.sep)) {
|
|
157
|
+
const nested = path.join(resolved, '.agent');
|
|
158
|
+
if (fs.existsSync(nested) && fs.statSync(nested).isDirectory()) {
|
|
159
|
+
resolved = nested;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.agentDir = resolved;
|
|
164
|
+
this.memoryDir = path.join(this.agentDir, MEMORY_DIR);
|
|
165
|
+
this.indexPath = path.join(this.memoryDir, INDEX_FILE);
|
|
166
|
+
this.projectionPath = path.join(this.memoryDir, PROJECTION_FILE);
|
|
160
167
|
this.options = {
|
|
161
|
-
defaultTTL:
|
|
162
|
-
|
|
168
|
+
defaultTTL: EPISODIC_TTL_DAYS * 24 * 60 * 60 * 1000,
|
|
169
|
+
maxEntries: MAX_ENTRIES,
|
|
163
170
|
...options,
|
|
164
171
|
};
|
|
165
172
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (!fs.existsSync(historyDir)) {
|
|
169
|
-
fs.mkdirSync(historyDir, { recursive: true });
|
|
173
|
+
if (!fs.existsSync(this.memoryDir)) {
|
|
174
|
+
fs.mkdirSync(this.memoryDir, { recursive: true });
|
|
170
175
|
}
|
|
171
|
-
|
|
172
|
-
// Initialize database
|
|
173
|
-
this.db = this.initDatabase();
|
|
174
|
-
this.initSchema();
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
/**
|
|
178
|
-
*
|
|
179
|
+
* Load index from disk safely.
|
|
180
|
+
* @returns {{ version: number, entries: Array<object>, next_id: number }}
|
|
179
181
|
*/
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
return
|
|
182
|
+
loadIndex() {
|
|
183
|
+
if (!fs.existsSync(this.indexPath)) {
|
|
184
|
+
return { version: 1, entries: [], next_id: 1 };
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const content = fs.readFileSync(this.indexPath, 'utf8');
|
|
188
|
+
return JSON.parse(content);
|
|
189
|
+
} catch {
|
|
190
|
+
return { version: 1, entries: [], next_id: 1 };
|
|
183
191
|
}
|
|
184
|
-
return new InMemoryStore();
|
|
185
192
|
}
|
|
186
193
|
|
|
187
194
|
/**
|
|
188
|
-
*
|
|
195
|
+
* Atomically persist index to disk.
|
|
196
|
+
* @param {object} index
|
|
189
197
|
*/
|
|
190
|
-
|
|
191
|
-
this.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
content TEXT NOT NULL,
|
|
196
|
-
tags TEXT,
|
|
197
|
-
priority REAL DEFAULT 1.0,
|
|
198
|
-
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
199
|
-
accessed_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
200
|
-
expires_at TEXT,
|
|
201
|
-
access_count INTEGER DEFAULT 0
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);
|
|
205
|
-
CREATE INDEX IF NOT EXISTS idx_memories_accessed ON memories(accessed_at);
|
|
206
|
-
`);
|
|
198
|
+
saveIndex(index) {
|
|
199
|
+
fs.mkdirSync(this.memoryDir, { recursive: true });
|
|
200
|
+
const tmpPath = this.indexPath + '.tmp';
|
|
201
|
+
fs.writeFileSync(tmpPath, JSON.stringify(index, null, 2), 'utf8');
|
|
202
|
+
fs.renameSync(tmpPath, this.indexPath);
|
|
207
203
|
}
|
|
208
204
|
|
|
209
205
|
/**
|
|
210
206
|
* Store a new memory entry.
|
|
211
|
-
* @param {string} type -
|
|
207
|
+
* @param {string} type - 'semantic' | 'procedural' | 'episodic' | 'working'
|
|
212
208
|
* @param {string} content - Memory content
|
|
213
|
-
* @param {string[]} tags - Searchable tags
|
|
214
|
-
* @param {object} options - Additional options (priority,
|
|
209
|
+
* @param {string[]} [tags] - Searchable tags
|
|
210
|
+
* @param {object} [options] - Additional options (priority, source, sessionId)
|
|
215
211
|
* @returns {{ id: number, type: string, token_estimate: number }}
|
|
216
212
|
*/
|
|
217
213
|
store(type, content, tags = [], options = {}) {
|
|
218
|
-
// Validate type
|
|
219
214
|
if (!VALID_TYPES.includes(type)) {
|
|
220
215
|
throw new Error(`Invalid memory type: "${type}". Must be one of: ${VALID_TYPES.join(', ')}`);
|
|
221
216
|
}
|
|
222
217
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
throw new Error('Memory content must be a non-empty string');
|
|
218
|
+
if (!content || typeof content !== 'string' || content.trim().length === 0) {
|
|
219
|
+
throw new Error('Memory content cannot be empty');
|
|
226
220
|
}
|
|
227
221
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
222
|
+
const lockPath = acquireLock(this.indexPath);
|
|
223
|
+
try {
|
|
224
|
+
const index = this.loadIndex();
|
|
225
|
+
|
|
226
|
+
// Enforce capacity (500)
|
|
227
|
+
if (index.entries.length >= this.options.maxEntries) {
|
|
228
|
+
index.entries = index.entries.filter(e => e.memory_type !== 'working');
|
|
229
|
+
if (index.entries.length >= this.options.maxEntries) {
|
|
230
|
+
index.entries = index.entries.filter(e => {
|
|
231
|
+
if (e.memory_type === 'episodic') {
|
|
232
|
+
return daysSince(e.created_at) < EPISODIC_TTL_DAYS;
|
|
233
|
+
}
|
|
234
|
+
return true;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
if (index.entries.length >= this.options.maxEntries) {
|
|
238
|
+
throw new Error(`Memory at capacity (${this.options.maxEntries}). Run: tk memory gc`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
234
241
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
242
|
+
const now = nowEpochStr();
|
|
243
|
+
const nextId = index.next_id || (index.entries.length > 0 ? Math.max(...index.entries.map(e => e.id)) + 1 : 1);
|
|
244
|
+
const cleanTags = Array.isArray(tags)
|
|
245
|
+
? tags.filter(t => typeof t === 'string' && t.trim().length > 0).map(t => t.trim())
|
|
246
|
+
: [];
|
|
247
|
+
|
|
248
|
+
const entry = {
|
|
249
|
+
id: nextId,
|
|
250
|
+
memory_type: type,
|
|
251
|
+
content: content.trim(),
|
|
252
|
+
tags: cleanTags,
|
|
253
|
+
created_at: now,
|
|
254
|
+
last_accessed: now,
|
|
255
|
+
access_count: 0,
|
|
256
|
+
token_estimate: estimateTokens(content),
|
|
257
|
+
source: options.source || (type === 'working' ? 'session' : 'manual'),
|
|
258
|
+
session_id: options.sessionId || options.session_id || null,
|
|
259
|
+
priority: typeof options.priority === 'number' ? options.priority : 1.0,
|
|
260
|
+
};
|
|
240
261
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
content,
|
|
244
|
-
JSON.stringify(tags),
|
|
245
|
-
options.priority || 1.0,
|
|
246
|
-
expiresAt,
|
|
247
|
-
);
|
|
262
|
+
index.entries.push(entry);
|
|
263
|
+
index.next_id = nextId + 1;
|
|
248
264
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
265
|
+
this.saveIndex(index);
|
|
266
|
+
this.generateProjection(index);
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
id: entry.id,
|
|
270
|
+
type: entry.memory_type,
|
|
271
|
+
token_estimate: entry.token_estimate,
|
|
272
|
+
};
|
|
273
|
+
} finally {
|
|
274
|
+
releaseLock(lockPath);
|
|
275
|
+
}
|
|
254
276
|
}
|
|
255
277
|
|
|
256
278
|
/**
|
|
257
|
-
* Recall memories matching a query
|
|
279
|
+
* Recall memories matching a query within a token budget.
|
|
258
280
|
* @param {string} query - Search query
|
|
259
|
-
* @param {number} budget -
|
|
260
|
-
* @returns {{ results:
|
|
281
|
+
* @param {number} [budget] - Token budget (default 2000)
|
|
282
|
+
* @returns {{ results: Array<object>, tokens_used: number, budget: number }}
|
|
261
283
|
*/
|
|
262
|
-
recall(query, budget =
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
284
|
+
recall(query, budget = DEFAULT_BUDGET) {
|
|
285
|
+
const lockPath = acquireLock(this.indexPath);
|
|
286
|
+
try {
|
|
287
|
+
const index = this.loadIndex();
|
|
288
|
+
|
|
289
|
+
const scored = index.entries
|
|
290
|
+
.map(entry => ({ entry, score: computeScore(entry, query) }))
|
|
291
|
+
.filter(s => s.score > 0)
|
|
292
|
+
.sort((a, b) => b.score - a.score);
|
|
293
|
+
|
|
294
|
+
let totalTokens = 0;
|
|
295
|
+
const results = [];
|
|
296
|
+
let indexModified = false;
|
|
297
|
+
|
|
298
|
+
for (const { entry, score } of scored) {
|
|
299
|
+
if (totalTokens + entry.token_estimate > budget) break;
|
|
300
|
+
totalTokens += entry.token_estimate;
|
|
301
|
+
|
|
302
|
+
entry.last_accessed = nowEpochStr();
|
|
303
|
+
entry.access_count = (entry.access_count || 0) + 1;
|
|
304
|
+
indexModified = true;
|
|
305
|
+
|
|
306
|
+
results.push({
|
|
307
|
+
id: entry.id,
|
|
308
|
+
memory_type: entry.memory_type,
|
|
309
|
+
content: entry.content,
|
|
310
|
+
tags: entry.tags || [],
|
|
311
|
+
priority: entry.priority != null ? entry.priority : 1.0,
|
|
312
|
+
score,
|
|
313
|
+
token_estimate: entry.token_estimate,
|
|
314
|
+
created_at: entry.created_at,
|
|
315
|
+
last_accessed: entry.last_accessed,
|
|
316
|
+
access_count: entry.access_count,
|
|
295
317
|
});
|
|
296
|
-
usedTokens += tokens;
|
|
297
|
-
|
|
298
|
-
// Update access stats
|
|
299
|
-
this.db
|
|
300
|
-
.prepare(
|
|
301
|
-
`
|
|
302
|
-
UPDATE memories
|
|
303
|
-
SET accessed_at = CURRENT_TIMESTAMP, access_count = access_count + 1
|
|
304
|
-
WHERE id = ?
|
|
305
|
-
`,
|
|
306
|
-
)
|
|
307
|
-
.run(mem.id);
|
|
308
318
|
}
|
|
309
|
-
}
|
|
310
319
|
|
|
311
|
-
|
|
320
|
+
if (indexModified) {
|
|
321
|
+
this.saveIndex(index);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return { results, tokens_used: totalTokens, budget };
|
|
325
|
+
} finally {
|
|
326
|
+
releaseLock(lockPath);
|
|
327
|
+
}
|
|
312
328
|
}
|
|
313
329
|
|
|
314
330
|
/**
|
|
315
|
-
*
|
|
316
|
-
* @param {number} id
|
|
331
|
+
* Retrieve a specific memory entry by ID.
|
|
332
|
+
* @param {number} id
|
|
317
333
|
* @returns {object|null}
|
|
318
334
|
*/
|
|
319
335
|
get(id) {
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
`,
|
|
325
|
-
)
|
|
326
|
-
.get(id);
|
|
327
|
-
|
|
328
|
-
if (!mem) return null;
|
|
336
|
+
const targetId = Number(id);
|
|
337
|
+
const index = this.loadIndex();
|
|
338
|
+
const entry = index.entries.find(e => e.id === targetId);
|
|
339
|
+
if (!entry) return null;
|
|
329
340
|
|
|
330
341
|
return {
|
|
331
|
-
id:
|
|
332
|
-
memory_type:
|
|
333
|
-
content:
|
|
334
|
-
tags:
|
|
335
|
-
priority:
|
|
336
|
-
created_at:
|
|
337
|
-
|
|
338
|
-
access_count:
|
|
339
|
-
|
|
342
|
+
id: entry.id,
|
|
343
|
+
memory_type: entry.memory_type,
|
|
344
|
+
content: entry.content,
|
|
345
|
+
tags: entry.tags || [],
|
|
346
|
+
priority: entry.priority != null ? entry.priority : 1.0,
|
|
347
|
+
created_at: entry.created_at,
|
|
348
|
+
last_accessed: entry.last_accessed,
|
|
349
|
+
access_count: entry.access_count || 0,
|
|
350
|
+
token_estimate: entry.token_estimate,
|
|
351
|
+
source: entry.source,
|
|
352
|
+
session_id: entry.session_id,
|
|
340
353
|
};
|
|
341
354
|
}
|
|
342
355
|
|
|
343
356
|
/**
|
|
344
|
-
* Delete a memory by ID.
|
|
345
|
-
* @param {number} id
|
|
346
|
-
* @returns {boolean} True if deleted
|
|
357
|
+
* Delete a memory entry by ID.
|
|
358
|
+
* @param {number} id
|
|
359
|
+
* @returns {boolean} True if deleted, false if not found
|
|
347
360
|
*/
|
|
348
361
|
delete(id) {
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
362
|
+
const targetId = Number(id);
|
|
363
|
+
const lockPath = acquireLock(this.indexPath);
|
|
364
|
+
try {
|
|
365
|
+
const index = this.loadIndex();
|
|
366
|
+
const before = index.entries.length;
|
|
367
|
+
index.entries = index.entries.filter(e => e.id !== targetId);
|
|
368
|
+
|
|
369
|
+
if (index.entries.length === before) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
this.saveIndex(index);
|
|
374
|
+
this.generateProjection(index);
|
|
375
|
+
return true;
|
|
376
|
+
} finally {
|
|
377
|
+
releaseLock(lockPath);
|
|
378
|
+
}
|
|
358
379
|
}
|
|
359
380
|
|
|
360
381
|
/**
|
|
361
|
-
* Clear all working memories (session
|
|
382
|
+
* Clear all working memories (session scratchpad).
|
|
383
|
+
* @returns {number} Number of cleared entries
|
|
362
384
|
*/
|
|
363
385
|
clearWorking() {
|
|
364
|
-
this.
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
386
|
+
const lockPath = acquireLock(this.indexPath);
|
|
387
|
+
try {
|
|
388
|
+
const index = this.loadIndex();
|
|
389
|
+
const before = index.entries.length;
|
|
390
|
+
index.entries = index.entries.filter(e => e.memory_type !== 'working');
|
|
391
|
+
const removed = before - index.entries.length;
|
|
392
|
+
|
|
393
|
+
if (removed > 0) {
|
|
394
|
+
this.saveIndex(index);
|
|
395
|
+
this.generateProjection(index);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return removed;
|
|
399
|
+
} finally {
|
|
400
|
+
releaseLock(lockPath);
|
|
401
|
+
}
|
|
371
402
|
}
|
|
372
403
|
|
|
373
404
|
/**
|
|
374
|
-
*
|
|
405
|
+
* Expire old memories and perform garbage collection.
|
|
406
|
+
* Clears all working memories and episodic memories older than 30 days.
|
|
407
|
+
* @returns {{ working_removed: number, episodic_removed: number, before: number, after: number }}
|
|
375
408
|
*/
|
|
376
409
|
expire() {
|
|
377
|
-
this.
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
410
|
+
const lockPath = acquireLock(this.indexPath);
|
|
411
|
+
try {
|
|
412
|
+
const index = this.loadIndex();
|
|
413
|
+
const before = index.entries.length;
|
|
414
|
+
|
|
415
|
+
let workingRemoved = 0;
|
|
416
|
+
let episodicRemoved = 0;
|
|
417
|
+
|
|
418
|
+
index.entries = index.entries.filter(e => {
|
|
419
|
+
if (e.memory_type === 'working') {
|
|
420
|
+
workingRemoved++;
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
if (e.memory_type === 'episodic' && daysSince(e.created_at) >= EPISODIC_TTL_DAYS) {
|
|
424
|
+
episodicRemoved++;
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
return true;
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
this.saveIndex(index);
|
|
431
|
+
this.generateProjection(index);
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
working_removed: workingRemoved,
|
|
435
|
+
episodic_removed: episodicRemoved,
|
|
436
|
+
before,
|
|
437
|
+
after: index.entries.length,
|
|
438
|
+
};
|
|
439
|
+
} finally {
|
|
440
|
+
releaseLock(lockPath);
|
|
441
|
+
}
|
|
385
442
|
}
|
|
386
443
|
|
|
387
444
|
/**
|
|
388
|
-
*
|
|
445
|
+
* Alias for expire() to match CLI terminology.
|
|
389
446
|
*/
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
`
|
|
394
|
-
SELECT
|
|
395
|
-
type,
|
|
396
|
-
COUNT(*) as count,
|
|
397
|
-
SUM(length(content)) as total_chars
|
|
398
|
-
FROM memories
|
|
399
|
-
WHERE expires_at IS NULL OR expires_at > datetime('now')
|
|
400
|
-
GROUP BY type
|
|
401
|
-
`,
|
|
402
|
-
)
|
|
403
|
-
.all();
|
|
404
|
-
|
|
405
|
-
const result = {
|
|
406
|
-
total: 0,
|
|
407
|
-
by_type: {},
|
|
408
|
-
};
|
|
447
|
+
gc() {
|
|
448
|
+
return this.expire();
|
|
449
|
+
}
|
|
409
450
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
451
|
+
/**
|
|
452
|
+
* Compute memory statistics.
|
|
453
|
+
* @returns {object}
|
|
454
|
+
*/
|
|
455
|
+
stats() {
|
|
456
|
+
const index = this.loadIndex();
|
|
457
|
+
const total = index.entries.length;
|
|
458
|
+
const semantic = index.entries.filter(e => e.memory_type === 'semantic').length;
|
|
459
|
+
const procedural = index.entries.filter(e => e.memory_type === 'procedural').length;
|
|
460
|
+
const episodic = index.entries.filter(e => e.memory_type === 'episodic').length;
|
|
461
|
+
const working = index.entries.filter(e => e.memory_type === 'working').length;
|
|
462
|
+
const totalTokens = index.entries.reduce((sum, e) => sum + (e.token_estimate || 0), 0);
|
|
463
|
+
|
|
464
|
+
const byType = {};
|
|
465
|
+
for (const type of VALID_TYPES) {
|
|
466
|
+
const typeEntries = index.entries.filter(e => e.memory_type === type);
|
|
467
|
+
const typeChars = typeEntries.reduce((sum, e) => sum + (e.content ? e.content.length : 0), 0);
|
|
468
|
+
const typeTokens = typeEntries.reduce((sum, e) => sum + (e.token_estimate || 0), 0);
|
|
469
|
+
byType[type] = {
|
|
470
|
+
count: typeEntries.length,
|
|
471
|
+
total_chars: typeChars,
|
|
472
|
+
estimated_tokens: typeTokens,
|
|
416
473
|
};
|
|
417
474
|
}
|
|
418
475
|
|
|
419
|
-
return
|
|
476
|
+
return {
|
|
477
|
+
total,
|
|
478
|
+
semantic,
|
|
479
|
+
procedural,
|
|
480
|
+
episodic,
|
|
481
|
+
working,
|
|
482
|
+
total_tokens: totalTokens,
|
|
483
|
+
capacity: this.options.maxEntries,
|
|
484
|
+
by_type: byType,
|
|
485
|
+
};
|
|
420
486
|
}
|
|
421
487
|
|
|
422
488
|
/**
|
|
423
|
-
*
|
|
489
|
+
* Generate human-readable Markdown projection (MEMORY.md).
|
|
490
|
+
* @param {object} [index]
|
|
491
|
+
* @returns {string} Absolute path to projection file
|
|
424
492
|
*/
|
|
425
|
-
|
|
426
|
-
if (
|
|
427
|
-
|
|
493
|
+
generateProjection(index) {
|
|
494
|
+
if (!index) index = this.loadIndex();
|
|
495
|
+
|
|
496
|
+
let md = '# 🧠 Tribunal Memory Index\n';
|
|
497
|
+
md += '> Auto-generated by `tribunal-kit memory export`. Do not edit manually.\n';
|
|
498
|
+
|
|
499
|
+
const sem = index.entries.filter(e => e.memory_type === 'semantic');
|
|
500
|
+
const proc = index.entries.filter(e => e.memory_type === 'procedural');
|
|
501
|
+
const ep = index.entries.filter(e => e.memory_type === 'episodic');
|
|
502
|
+
const work = index.entries.filter(e => e.memory_type === 'working');
|
|
503
|
+
|
|
504
|
+
md += `> Entries: ${index.entries.length} | Semantic: ${sem.length} | Procedural: ${proc.length} | Episodic: ${ep.length} | Working: ${work.length}\n\n`;
|
|
505
|
+
|
|
506
|
+
if (sem.length > 0) {
|
|
507
|
+
md += '## SEMANTIC (Permanent Facts)\n';
|
|
508
|
+
md += '| ID | Content | Tags | Source | Created |\n';
|
|
509
|
+
md += '|----|---------|------|--------|---------|\n';
|
|
510
|
+
for (const e of sem) {
|
|
511
|
+
md += `| ${e.id} | ${e.content.replace(/\|/g, '\\|')} | ${(e.tags || []).join(', ')} | ${e.source || 'manual'} | ${e.created_at} |\n`;
|
|
512
|
+
}
|
|
513
|
+
md += '\n';
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (proc.length > 0) {
|
|
517
|
+
md += '## PROCEDURAL (How-To Recipes)\n';
|
|
518
|
+
md += '| ID | Content | Tags | Source | Created |\n';
|
|
519
|
+
md += '|----|---------|------|--------|---------|\n';
|
|
520
|
+
for (const e of proc) {
|
|
521
|
+
md += `| ${e.id} | ${e.content.replace(/\|/g, '\\|')} | ${(e.tags || []).join(', ')} | ${e.source || 'manual'} | ${e.created_at} |\n`;
|
|
522
|
+
}
|
|
523
|
+
md += '\n';
|
|
428
524
|
}
|
|
525
|
+
|
|
526
|
+
if (ep.length > 0) {
|
|
527
|
+
md += '## EPISODIC (Session History — auto-decays after 30 days)\n';
|
|
528
|
+
md += '| ID | Content | Tags | Source | Created | Days Remaining |\n';
|
|
529
|
+
md += '|----|---------|------|--------|---------|----------------|\n';
|
|
530
|
+
for (const e of ep) {
|
|
531
|
+
const remaining = Math.max(0, EPISODIC_TTL_DAYS - daysSince(e.created_at));
|
|
532
|
+
md += `| ${e.id} | ${e.content.replace(/\|/g, '\\|')} | ${(e.tags || []).join(', ')} | ${e.source || 'manual'} | ${e.created_at} | ${remaining} |\n`;
|
|
533
|
+
}
|
|
534
|
+
md += '\n';
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (work.length > 0) {
|
|
538
|
+
md += '## WORKING (Current Session — cleared on GC)\n';
|
|
539
|
+
md += '| ID | Content | Tags | Session |\n';
|
|
540
|
+
md += '|----|---------|------|---------|\n';
|
|
541
|
+
for (const e of work) {
|
|
542
|
+
md += `| ${e.id} | ${e.content.replace(/\|/g, '\\|')} | ${(e.tags || []).join(', ')} | ${e.session_id || '—'} |\n`;
|
|
543
|
+
}
|
|
544
|
+
md += '\n';
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (index.entries.length === 0) {
|
|
548
|
+
md += '*No memories recorded yet. Run `tk memory store` to add your first memory.*\n';
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
fs.mkdirSync(path.dirname(this.projectionPath), { recursive: true });
|
|
552
|
+
fs.writeFileSync(this.projectionPath, md, 'utf8');
|
|
553
|
+
|
|
554
|
+
return this.projectionPath;
|
|
429
555
|
}
|
|
430
556
|
|
|
431
|
-
|
|
557
|
+
/**
|
|
558
|
+
* Export the markdown projection text.
|
|
559
|
+
* @returns {string}
|
|
560
|
+
*/
|
|
561
|
+
export() {
|
|
562
|
+
this.generateProjection();
|
|
563
|
+
return fs.readFileSync(this.projectionPath, 'utf8');
|
|
564
|
+
}
|
|
432
565
|
|
|
433
566
|
/**
|
|
434
|
-
* Estimate token count
|
|
435
|
-
*
|
|
567
|
+
* Estimate token count.
|
|
568
|
+
* @param {string} text
|
|
569
|
+
* @returns {number}
|
|
436
570
|
*/
|
|
437
571
|
estimateTokens(text) {
|
|
438
|
-
|
|
439
|
-
return Math.ceil(text.length / 4);
|
|
572
|
+
return estimateTokens(text);
|
|
440
573
|
}
|
|
441
574
|
|
|
442
575
|
/**
|
|
443
|
-
*
|
|
576
|
+
* Close connection (no-op for file-backed storage, preserved for API parity).
|
|
444
577
|
*/
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
return (text.match(/\b[a-zA-Z_][a-zA-Z0-9_]{2,}\b/g) || []).map(t => t.toLowerCase());
|
|
578
|
+
close() {
|
|
579
|
+
// No-op for file-backed engine
|
|
448
580
|
}
|
|
449
581
|
}
|
|
450
582
|
|
|
@@ -454,6 +586,8 @@ module.exports = {
|
|
|
454
586
|
MemoryEngine,
|
|
455
587
|
MEMORY_TYPES,
|
|
456
588
|
VALID_TYPES,
|
|
589
|
+
TYPE_PRIORITY,
|
|
590
|
+
estimateTokens,
|
|
457
591
|
};
|
|
458
592
|
|
|
459
593
|
// ─── CLI Entry Point ───────────────────────────────────────────────────────────
|
|
@@ -466,18 +600,20 @@ if (require.main === module) {
|
|
|
466
600
|
\x1b[1mmemory_engine.js\x1b[0m — Tribunal Kit 4-Type Taxonomy Persistent Memory Engine
|
|
467
601
|
|
|
468
602
|
\x1b[1mUsage:\x1b[0m
|
|
469
|
-
node .agent/scripts/memory_engine.js store <type> <content> [--tags tag1,tag2]
|
|
603
|
+
node .agent/scripts/memory_engine.js store <type> <content> [--tags tag1,tag2] [--source manual]
|
|
470
604
|
node .agent/scripts/memory_engine.js recall <query> [--budget 2000]
|
|
471
605
|
node .agent/scripts/memory_engine.js get <id>
|
|
472
606
|
node .agent/scripts/memory_engine.js delete <id>
|
|
473
607
|
node .agent/scripts/memory_engine.js stats
|
|
474
608
|
node .agent/scripts/memory_engine.js expire
|
|
609
|
+
node .agent/scripts/memory_engine.js gc
|
|
610
|
+
node .agent/scripts/memory_engine.js export
|
|
475
611
|
|
|
476
612
|
\x1b[1mMemory Types:\x1b[0m
|
|
477
613
|
semantic — Permanent facts (no expiration)
|
|
478
614
|
procedural — How-to recipes (no expiration)
|
|
479
615
|
episodic — Events with 30-day TTL
|
|
480
|
-
working — Session scratch (cleared on
|
|
616
|
+
working — Session scratch (cleared on GC)
|
|
481
617
|
|
|
482
618
|
\x1b[1mExamples:\x1b[0m
|
|
483
619
|
node .agent/scripts/memory_engine.js store semantic "User prefers TypeScript strict mode" --tags typescript,preference
|
|
@@ -487,11 +623,15 @@ if (require.main === module) {
|
|
|
487
623
|
process.exit(0);
|
|
488
624
|
}
|
|
489
625
|
|
|
490
|
-
|
|
491
|
-
|
|
626
|
+
let agentDir = null;
|
|
627
|
+
try {
|
|
628
|
+
const { findAgentDir } = require('./_utils');
|
|
629
|
+
agentDir = findAgentDir();
|
|
630
|
+
} catch (_) {
|
|
631
|
+
agentDir = path.resolve(process.cwd(), '.agent');
|
|
632
|
+
}
|
|
492
633
|
|
|
493
634
|
const mem = new MemoryEngine(agentDir);
|
|
494
|
-
|
|
495
635
|
const command = args[0];
|
|
496
636
|
|
|
497
637
|
try {
|
|
@@ -504,8 +644,10 @@ if (require.main === module) {
|
|
|
504
644
|
tagsIdx !== -1 && args[tagsIdx + 1]
|
|
505
645
|
? args[tagsIdx + 1].split(',').map(t => t.trim())
|
|
506
646
|
: [];
|
|
647
|
+
const sourceIdx = args.indexOf('--source');
|
|
648
|
+
const source = sourceIdx !== -1 && args[sourceIdx + 1] ? args[sourceIdx + 1] : undefined;
|
|
507
649
|
|
|
508
|
-
const result = mem.store(type, content, tags);
|
|
650
|
+
const result = mem.store(type, content, tags, { source });
|
|
509
651
|
console.log(
|
|
510
652
|
`\x1b[32m✓\x1b[0m Memory stored: #${result.id} (${result.type}, ~${result.token_estimate} tokens)`,
|
|
511
653
|
);
|
|
@@ -514,6 +656,10 @@ if (require.main === module) {
|
|
|
514
656
|
|
|
515
657
|
case 'recall': {
|
|
516
658
|
const query = args[1];
|
|
659
|
+
if (!query) {
|
|
660
|
+
console.error('\x1b[31m✖ Missing search query\x1b[0m');
|
|
661
|
+
process.exit(1);
|
|
662
|
+
}
|
|
517
663
|
const budgetIdx = args.indexOf('--budget');
|
|
518
664
|
const budget =
|
|
519
665
|
budgetIdx !== -1 && args[budgetIdx + 1] ? parseInt(args[budgetIdx + 1], 10) : 2000;
|
|
@@ -524,7 +670,7 @@ if (require.main === module) {
|
|
|
524
670
|
);
|
|
525
671
|
for (const entry of results) {
|
|
526
672
|
console.log(`- **[${entry.memory_type.toUpperCase()}]** #${entry.id}: ${entry.content}`);
|
|
527
|
-
if (entry.tags.length > 0) console.log(` _(${entry.tags.join(', ')})_`);
|
|
673
|
+
if (entry.tags && entry.tags.length > 0) console.log(` _(${entry.tags.join(', ')})_`);
|
|
528
674
|
}
|
|
529
675
|
break;
|
|
530
676
|
}
|
|
@@ -562,9 +708,24 @@ if (require.main === module) {
|
|
|
562
708
|
break;
|
|
563
709
|
}
|
|
564
710
|
|
|
711
|
+
case 'gc':
|
|
565
712
|
case 'expire': {
|
|
566
|
-
mem.expire();
|
|
567
|
-
console.log(
|
|
713
|
+
const res = mem.expire();
|
|
714
|
+
console.log(
|
|
715
|
+
`\x1b[32m✓\x1b[0m Memory GC complete: ${res.working_removed} working, ${res.episodic_removed} episodic removed (${res.before} -> ${res.after})`,
|
|
716
|
+
);
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
case 'clear-working': {
|
|
721
|
+
const cleared = mem.clearWorking();
|
|
722
|
+
console.log(`\x1b[32m✓\x1b[0m Cleared ${cleared} working memory entries`);
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
case 'export': {
|
|
727
|
+
const proj = mem.export();
|
|
728
|
+
console.log(proj);
|
|
568
729
|
break;
|
|
569
730
|
}
|
|
570
731
|
|