@jack200714/mafw 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/mafw/.backup-v61/parametric/base-skill-manifest.yaml +2 -0
- package/.opencode/mafw/STATUS.md +6 -0
- package/.opencode/mafw/ledger.md +20 -0
- package/.opencode/mafw/memory/.harmonic_index.json +28 -0
- package/.opencode/mafw/memory/.review_queue.json +1 -0
- package/.opencode/mafw/memory/tier3/parametric.json +13 -0
- package/.opencode/mafw/memory/tier3/test-goal.json +19 -0
- package/.opencode/mafw/memory-index.json +6 -0
- package/.opencode/mafw/parametric/base-skill-manifest.yaml +2 -0
- package/.opencode/mafw/waves.json +4 -0
- package/.opencode/opencode.json +3 -0
- package/.opencode/plugins/mafw-plugin.ts +8 -0
- package/.opencode/skills/banner-design/SKILL.md +196 -0
- package/.opencode/skills/banner-design/references/banner-sizes-and-styles.md +118 -0
- package/.opencode/skills/brand/SKILL.md +97 -0
- package/.opencode/skills/brand/references/approval-checklist.md +169 -0
- package/.opencode/skills/brand/references/asset-organization.md +157 -0
- package/.opencode/skills/brand/references/brand-guideline-template.md +140 -0
- package/.opencode/skills/brand/references/color-palette-management.md +186 -0
- package/.opencode/skills/brand/references/consistency-checklist.md +94 -0
- package/.opencode/skills/brand/references/logo-usage-rules.md +185 -0
- package/.opencode/skills/brand/references/messaging-framework.md +85 -0
- package/.opencode/skills/brand/references/typography-specifications.md +214 -0
- package/.opencode/skills/brand/references/update.md +118 -0
- package/.opencode/skills/brand/references/visual-identity.md +96 -0
- package/.opencode/skills/brand/references/voice-framework.md +88 -0
- package/.opencode/skills/brand/scripts/extract-colors.cjs +341 -0
- package/.opencode/skills/brand/scripts/inject-brand-context.cjs +349 -0
- package/.opencode/skills/brand/scripts/sync-brand-to-tokens.cjs +248 -0
- package/.opencode/skills/brand/scripts/tests/test_sync_brand_to_tokens.py +52 -0
- package/.opencode/skills/brand/scripts/validate-asset.cjs +387 -0
- package/.opencode/skills/brand/templates/brand-guidelines-starter.md +275 -0
- package/.opencode/skills/design/SKILL.md +313 -0
- package/.opencode/skills/design/data/cip/deliverables.csv +51 -0
- package/.opencode/skills/design/data/cip/industries.csv +21 -0
- package/.opencode/skills/design/data/cip/mockup-contexts.csv +21 -0
- package/.opencode/skills/design/data/cip/styles.csv +21 -0
- package/.opencode/skills/design/data/icon/styles.csv +16 -0
- package/.opencode/skills/design/data/logo/colors.csv +56 -0
- package/.opencode/skills/design/data/logo/industries.csv +56 -0
- package/.opencode/skills/design/data/logo/styles.csv +56 -0
- package/.opencode/skills/design/references/banner-sizes-and-styles.md +118 -0
- package/.opencode/skills/design/references/cip-deliverable-guide.md +95 -0
- package/.opencode/skills/design/references/cip-design.md +121 -0
- package/.opencode/skills/design/references/cip-prompt-engineering.md +84 -0
- package/.opencode/skills/design/references/cip-style-guide.md +68 -0
- package/.opencode/skills/design/references/design-routing.md +207 -0
- package/.opencode/skills/design/references/icon-design.md +122 -0
- package/.opencode/skills/design/references/logo-color-psychology.md +101 -0
- package/.opencode/skills/design/references/logo-design.md +92 -0
- package/.opencode/skills/design/references/logo-prompt-engineering.md +158 -0
- package/.opencode/skills/design/references/logo-style-guide.md +109 -0
- package/.opencode/skills/design/references/slides-copywriting-formulas.md +84 -0
- package/.opencode/skills/design/references/slides-create.md +4 -0
- package/.opencode/skills/design/references/slides-html-template.md +295 -0
- package/.opencode/skills/design/references/slides-layout-patterns.md +137 -0
- package/.opencode/skills/design/references/slides-strategies.md +94 -0
- package/.opencode/skills/design/references/slides.md +42 -0
- package/.opencode/skills/design/references/social-photos-design.md +329 -0
- package/.opencode/skills/design/scripts/cip/core.py +215 -0
- package/.opencode/skills/design/scripts/cip/generate.py +484 -0
- package/.opencode/skills/design/scripts/cip/render-html.py +424 -0
- package/.opencode/skills/design/scripts/cip/search.py +127 -0
- package/.opencode/skills/design/scripts/icon/generate.py +487 -0
- package/.opencode/skills/design/scripts/logo/core.py +175 -0
- package/.opencode/skills/design/scripts/logo/generate.py +362 -0
- package/.opencode/skills/design/scripts/logo/search.py +114 -0
- package/.opencode/skills/design-system/SKILL.md +244 -0
- package/.opencode/skills/design-system/data/slide-backgrounds.csv +11 -0
- package/.opencode/skills/design-system/data/slide-charts.csv +26 -0
- package/.opencode/skills/design-system/data/slide-color-logic.csv +14 -0
- package/.opencode/skills/design-system/data/slide-copy.csv +26 -0
- package/.opencode/skills/design-system/data/slide-layout-logic.csv +16 -0
- package/.opencode/skills/design-system/data/slide-layouts.csv +26 -0
- package/.opencode/skills/design-system/data/slide-strategies.csv +16 -0
- package/.opencode/skills/design-system/data/slide-typography.csv +15 -0
- package/.opencode/skills/design-system/references/component-specs.md +236 -0
- package/.opencode/skills/design-system/references/component-tokens.md +214 -0
- package/.opencode/skills/design-system/references/primitive-tokens.md +203 -0
- package/.opencode/skills/design-system/references/semantic-tokens.md +215 -0
- package/.opencode/skills/design-system/references/states-and-variants.md +241 -0
- package/.opencode/skills/design-system/references/tailwind-integration.md +251 -0
- package/.opencode/skills/design-system/references/token-architecture.md +224 -0
- package/.opencode/skills/design-system/scripts/embed-tokens.cjs +99 -0
- package/.opencode/skills/design-system/scripts/fetch-background.py +317 -0
- package/.opencode/skills/design-system/scripts/generate-slide.py +770 -0
- package/.opencode/skills/design-system/scripts/generate-tokens.cjs +205 -0
- package/.opencode/skills/design-system/scripts/html-token-validator.py +327 -0
- package/.opencode/skills/design-system/scripts/search-slides.py +218 -0
- package/.opencode/skills/design-system/scripts/slide-token-validator.py +35 -0
- package/.opencode/skills/design-system/scripts/slide_search_core.py +453 -0
- package/.opencode/skills/design-system/scripts/tests/test_validate_tokens.py +48 -0
- package/.opencode/skills/design-system/scripts/validate-tokens.cjs +246 -0
- package/.opencode/skills/design-system/templates/design-tokens-starter.json +143 -0
- package/.opencode/skills/frontend-design/LICENSE.txt +21 -0
- package/.opencode/skills/frontend-design/SKILL.md +115 -0
- package/.opencode/skills/mafw-automation-interview/SKILL.md +43 -0
- package/.opencode/skills/mafw-cli-scanner/SKILL.md +37 -0
- package/.opencode/skills/mafw-compression-verifier/SKILL.md +52 -0
- package/.opencode/skills/mafw-desktop-inspector/SKILL.md +170 -0
- package/.opencode/skills/mafw-execute/SKILL.md +62 -0
- package/.opencode/skills/mafw-gateway-restart/SKILL.md +87 -0
- package/.opencode/skills/mafw-github-scanner/SKILL.md +38 -0
- package/.opencode/skills/mafw-goal/SKILL.md +76 -0
- package/.opencode/skills/mafw-interview/SKILL.md +68 -0
- package/.opencode/skills/mafw-memory-extractor/SKILL.md +65 -0
- package/.opencode/skills/mafw-plan/SKILL.md +58 -0
- package/.opencode/skills/mafw-review/SKILL.md +85 -0
- package/.opencode/skills/runtime-plugin-authoring/SKILL.md +791 -0
- package/.opencode/skills/slides/SKILL.md +40 -0
- package/.opencode/skills/slides/references/copywriting-formulas.md +84 -0
- package/.opencode/skills/slides/references/create.md +4 -0
- package/.opencode/skills/slides/references/html-template.md +295 -0
- package/.opencode/skills/slides/references/layout-patterns.md +137 -0
- package/.opencode/skills/slides/references/slide-strategies.md +94 -0
- package/.opencode/skills/ui-styling/LICENSE.txt +202 -0
- package/.opencode/skills/ui-styling/SKILL.md +324 -0
- package/.opencode/skills/ui-styling/references/canvas-design-system.md +320 -0
- package/.opencode/skills/ui-styling/references/shadcn-accessibility.md +471 -0
- package/.opencode/skills/ui-styling/references/shadcn-components.md +424 -0
- package/.opencode/skills/ui-styling/references/shadcn-theming.md +373 -0
- package/.opencode/skills/ui-styling/references/tailwind-customization.md +483 -0
- package/.opencode/skills/ui-styling/references/tailwind-responsive.md +382 -0
- package/.opencode/skills/ui-styling/references/tailwind-utilities.md +455 -0
- package/.opencode/skills/ui-styling/scripts/requirements.txt +17 -0
- package/.opencode/skills/ui-styling/scripts/shadcn_add.py +308 -0
- package/.opencode/skills/ui-styling/scripts/tailwind_config_gen.py +473 -0
- package/.opencode/skills/ui-styling/scripts/tests/coverage-ui.json +1 -0
- package/.opencode/skills/ui-styling/scripts/tests/requirements.txt +3 -0
- package/.opencode/skills/ui-styling/scripts/tests/test_shadcn_add.py +266 -0
- package/.opencode/skills/ui-styling/scripts/tests/test_tailwind_config_gen.py +394 -0
- package/.opencode/skills/ui-ux-pro-max/SKILL.md +388 -0
- package/.opencode/skills/ui-ux-pro-max/data/app-interface.csv +31 -0
- package/.opencode/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/.opencode/skills/ui-ux-pro-max/data/colors.csv +193 -0
- package/.opencode/skills/ui-ux-pro-max/data/google-fonts.csv +1924 -0
- package/.opencode/skills/ui-ux-pro-max/data/icons.csv +106 -0
- package/.opencode/skills/ui-ux-pro-max/data/landing.csv +35 -0
- package/.opencode/skills/ui-ux-pro-max/data/motion.csv +17 -0
- package/.opencode/skills/ui-ux-pro-max/data/products.csv +193 -0
- package/.opencode/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/angular.csv +51 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/avalonia.csv +57 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/javafx.csv +76 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +71 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/uno.csv +60 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/uwp.csv +56 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/winui.csv +60 -0
- package/.opencode/skills/ui-ux-pro-max/data/stacks/wpf.csv +57 -0
- package/.opencode/skills/ui-ux-pro-max/data/styles.csv +85 -0
- package/.opencode/skills/ui-ux-pro-max/data/typography.csv +75 -0
- package/.opencode/skills/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
- package/.opencode/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.opencode/skills/ui-ux-pro-max/scripts/core.py +464 -0
- package/.opencode/skills/ui-ux-pro-max/scripts/design_system.py +1479 -0
- package/.opencode/skills/ui-ux-pro-max/scripts/search.py +162 -0
- package/.opencode/skills/ui-ux-pro-max/scripts/tests/test_core.py +134 -0
- package/.opencode/skills/ui-ux-pro-max/scripts/tests/test_design_system_mode.py +159 -0
- package/.opencode/skills/ui-ux-pro-max/scripts/validate_data.py +114 -0
- package/LICENSE +21 -0
- package/README.md +199 -0
- package/bin/mafw.js +436 -0
- package/dist/hooks/bash-python-guide.d.ts +4 -0
- package/dist/hooks/bash-python-guide.d.ts.map +1 -0
- package/dist/hooks/bash-python-guide.js +67 -0
- package/dist/hooks/bash-python-guide.js.map +1 -0
- package/dist/hooks/handoff.d.ts +9 -0
- package/dist/hooks/handoff.d.ts.map +1 -0
- package/dist/hooks/handoff.js +8 -0
- package/dist/hooks/handoff.js.map +1 -0
- package/dist/hooks/hook-manager.d.ts +32 -0
- package/dist/hooks/hook-manager.d.ts.map +1 -0
- package/dist/hooks/hook-manager.js +91 -0
- package/dist/hooks/hook-manager.js.map +1 -0
- package/dist/hooks/llm-after.d.ts +8 -0
- package/dist/hooks/llm-after.d.ts.map +1 -0
- package/dist/hooks/llm-after.js +8 -0
- package/dist/hooks/llm-after.js.map +1 -0
- package/dist/hooks/media-ingest.d.ts +43 -0
- package/dist/hooks/media-ingest.d.ts.map +1 -0
- package/dist/hooks/media-ingest.js +269 -0
- package/dist/hooks/media-ingest.js.map +1 -0
- package/dist/hooks/memory-guide.d.ts +3 -0
- package/dist/hooks/memory-guide.d.ts.map +1 -0
- package/dist/hooks/memory-guide.js +47 -0
- package/dist/hooks/memory-guide.js.map +1 -0
- package/dist/hooks/observation-capture.d.ts +17 -0
- package/dist/hooks/observation-capture.d.ts.map +1 -0
- package/dist/hooks/observation-capture.js +20 -0
- package/dist/hooks/observation-capture.js.map +1 -0
- package/dist/hooks/session-compacting.d.ts +6 -0
- package/dist/hooks/session-compacting.d.ts.map +1 -0
- package/dist/hooks/session-compacting.js +6 -0
- package/dist/hooks/session-compacting.js.map +1 -0
- package/dist/hooks/session-ending.d.ts +20 -0
- package/dist/hooks/session-ending.d.ts.map +1 -0
- package/dist/hooks/session-ending.js +113 -0
- package/dist/hooks/session-ending.js.map +1 -0
- package/dist/hooks/session-recall.d.ts +2 -0
- package/dist/hooks/session-recall.d.ts.map +1 -0
- package/dist/hooks/session-recall.js +103 -0
- package/dist/hooks/session-recall.js.map +1 -0
- package/dist/hooks/session-start.d.ts +9 -0
- package/dist/hooks/session-start.d.ts.map +1 -0
- package/dist/hooks/session-start.js +42 -0
- package/dist/hooks/session-start.js.map +1 -0
- package/dist/hooks/tool-before.d.ts +10 -0
- package/dist/hooks/tool-before.d.ts.map +1 -0
- package/dist/hooks/tool-before.js +6 -0
- package/dist/hooks/tool-before.js.map +1 -0
- package/dist/hooks/tool-executed.d.ts +19 -0
- package/dist/hooks/tool-executed.d.ts.map +1 -0
- package/dist/hooks/tool-executed.js +12 -0
- package/dist/hooks/tool-executed.js.map +1 -0
- package/dist/hooks/user-profile.d.ts +2 -0
- package/dist/hooks/user-profile.d.ts.map +1 -0
- package/dist/hooks/user-profile.js +30 -0
- package/dist/hooks/user-profile.js.map +1 -0
- package/dist/hooks/user-prompt.d.ts +9 -0
- package/dist/hooks/user-prompt.d.ts.map +1 -0
- package/dist/hooks/user-prompt.js +8 -0
- package/dist/hooks/user-prompt.js.map +1 -0
- package/dist/hooks/voice-guide.d.ts +8 -0
- package/dist/hooks/voice-guide.d.ts.map +1 -0
- package/dist/hooks/voice-guide.js +101 -0
- package/dist/hooks/voice-guide.js.map +1 -0
- package/dist/plugin.d.ts +55 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +342 -0
- package/dist/plugin.js.map +1 -0
- package/dist/tools/add-memory.d.ts +17 -0
- package/dist/tools/add-memory.d.ts.map +1 -0
- package/dist/tools/add-memory.js +60 -0
- package/dist/tools/add-memory.js.map +1 -0
- package/dist/tools/media-ask.d.ts +14 -0
- package/dist/tools/media-ask.d.ts.map +1 -0
- package/dist/tools/media-ask.js +224 -0
- package/dist/tools/media-ask.js.map +1 -0
- package/dist/tools/media-speak.d.ts +16 -0
- package/dist/tools/media-speak.d.ts.map +1 -0
- package/dist/tools/media-speak.js +78 -0
- package/dist/tools/media-speak.js.map +1 -0
- package/dist/tools/media-upload.d.ts +14 -0
- package/dist/tools/media-upload.d.ts.map +1 -0
- package/dist/tools/media-upload.js +155 -0
- package/dist/tools/media-upload.js.map +1 -0
- package/dist/tools/python-exec.d.ts +13 -0
- package/dist/tools/python-exec.d.ts.map +1 -0
- package/dist/tools/python-exec.js +99 -0
- package/dist/tools/python-exec.js.map +1 -0
- package/dist/tools/python-restart.d.ts +11 -0
- package/dist/tools/python-restart.d.ts.map +1 -0
- package/dist/tools/python-restart.js +33 -0
- package/dist/tools/python-restart.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +23 -0
- package/dist/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/utils/circuit-breaker.js +75 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/config-loader.d.ts +20 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +194 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/fallback.d.ts +7 -0
- package/dist/utils/fallback.d.ts.map +1 -0
- package/dist/utils/fallback.js +20 -0
- package/dist/utils/fallback.js.map +1 -0
- package/dist/utils/git.d.ts +24 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +71 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/github.d.ts +37 -0
- package/dist/utils/github.d.ts.map +1 -0
- package/dist/utils/github.js +53 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/global-path.d.ts +2 -0
- package/dist/utils/global-path.d.ts.map +1 -0
- package/dist/utils/global-path.js +32 -0
- package/dist/utils/global-path.js.map +1 -0
- package/dist/utils/logger.d.ts +6 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +69 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/obs-capture.d.ts +7 -0
- package/dist/utils/obs-capture.d.ts.map +1 -0
- package/dist/utils/obs-capture.js +49 -0
- package/dist/utils/obs-capture.js.map +1 -0
- package/dist/utils/retry.d.ts +11 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +45 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/self-wiring.d.ts +13 -0
- package/dist/utils/self-wiring.d.ts.map +1 -0
- package/dist/utils/self-wiring.js +86 -0
- package/dist/utils/self-wiring.js.map +1 -0
- package/dist/utils/state.d.ts +106 -0
- package/dist/utils/state.d.ts.map +1 -0
- package/dist/utils/state.js +166 -0
- package/dist/utils/state.js.map +1 -0
- package/dist/utils/status.d.ts +47 -0
- package/dist/utils/status.d.ts.map +1 -0
- package/dist/utils/status.js +147 -0
- package/dist/utils/status.js.map +1 -0
- package/dist/utils/ttl-map.d.ts +17 -0
- package/dist/utils/ttl-map.d.ts.map +1 -0
- package/dist/utils/ttl-map.js +67 -0
- package/dist/utils/ttl-map.js.map +1 -0
- package/gateway/dist/automation-engine.js +729 -0
- package/gateway/dist/chat/chat-sessions.js +95 -0
- package/gateway/dist/chat/graph-runner.js +76 -0
- package/gateway/dist/chat/index.js +7 -0
- package/gateway/dist/chat/intent-classifier.js +23 -0
- package/gateway/dist/config.js +416 -0
- package/gateway/dist/core/auth.js +96 -0
- package/gateway/dist/core/budget-guard.js +52 -0
- package/gateway/dist/core/compression/bm25-index.js +176 -0
- package/gateway/dist/core/compression/compression-pipeline.js +157 -0
- package/gateway/dist/core/compression/compression-strategy-selector.js +32 -0
- package/gateway/dist/core/compression/compression-verifier.js +79 -0
- package/gateway/dist/core/compression/diff-compressor.js +69 -0
- package/gateway/dist/core/compression/hybrid-compressor.js +104 -0
- package/gateway/dist/core/compression/lesson-compactor.js +114 -0
- package/gateway/dist/core/compression/memory-index.js +190 -0
- package/gateway/dist/core/compression/observation-classifier.js +41 -0
- package/gateway/dist/core/compression/observation-deduplicator.js +43 -0
- package/gateway/dist/core/compression/rrf-fusion.js +63 -0
- package/gateway/dist/core/compression/session-pruner.js +137 -0
- package/gateway/dist/core/compression/token-budget-allocator.js +141 -0
- package/gateway/dist/core/compression/vector-index.js +117 -0
- package/gateway/dist/core/compression/zero-token-compressor.js +80 -0
- package/gateway/dist/core/cost/cognitive-router.js +41 -0
- package/gateway/dist/core/cost/cost-estimator.js +63 -0
- package/gateway/dist/core/cost/types.js +19 -0
- package/gateway/dist/core/engine/degradation.js +159 -0
- package/gateway/dist/core/engine/goal-worktree-manager.js +131 -0
- package/gateway/dist/core/engine/lesson-manager.js +222 -0
- package/gateway/dist/core/engine/optimistic-sync.js +100 -0
- package/gateway/dist/core/engine/phase-orchestrator.js +153 -0
- package/gateway/dist/core/engine/report-generator.js +131 -0
- package/gateway/dist/core/engine/state-lock.js +91 -0
- package/gateway/dist/core/engine/task-branch-manager.js +102 -0
- package/gateway/dist/core/engine/wave-dependency.js +67 -0
- package/gateway/dist/core/engine/wave-executor.js +112 -0
- package/gateway/dist/core/goal-budget.js +63 -0
- package/gateway/dist/core/graph/entity-extractor.js +53 -0
- package/gateway/dist/core/graph/graph-searcher.js +120 -0
- package/gateway/dist/core/graph/knowledge-graph-manager.js +138 -0
- package/gateway/dist/core/graph/relation-inferencer.js +67 -0
- package/gateway/dist/core/graph/types.js +2 -0
- package/gateway/dist/core/hooks/handoff.js +7 -0
- package/gateway/dist/core/hooks/hook-manager.js +91 -0
- package/gateway/dist/core/hooks/llm-after.js +7 -0
- package/gateway/dist/core/hooks/observation-capture.js +19 -0
- package/gateway/dist/core/hooks/session-compacting.js +5 -0
- package/gateway/dist/core/hooks/session-ending.js +123 -0
- package/gateway/dist/core/hooks/session-start.js +51 -0
- package/gateway/dist/core/hooks/tool-before.js +5 -0
- package/gateway/dist/core/hooks/tool-executed.js +11 -0
- package/gateway/dist/core/hooks/user-prompt.js +7 -0
- package/gateway/dist/core/index.js +119 -0
- package/gateway/dist/core/langchain/agent-adapter.js +39 -0
- package/gateway/dist/core/langchain/index.js +12 -0
- package/gateway/dist/core/langchain/memory.js +35 -0
- package/gateway/dist/core/langchain/node-runner.js +115 -0
- package/gateway/dist/core/langchain/retriever.js +28 -0
- package/gateway/dist/core/langgraph/checkpointer.js +200 -0
- package/gateway/dist/core/langgraph/graph.js +57 -0
- package/gateway/dist/core/langgraph/index.js +25 -0
- package/gateway/dist/core/langgraph/loop-state.js +71 -0
- package/gateway/dist/core/langgraph/nodes/archive.node.js +27 -0
- package/gateway/dist/core/langgraph/nodes/execute.node.js +5 -0
- package/gateway/dist/core/langgraph/nodes/plan.node.js +101 -0
- package/gateway/dist/core/langgraph/nodes/review.node.js +89 -0
- package/gateway/dist/core/langgraph/nodes/sync.node.js +70 -0
- package/gateway/dist/core/langgraph/review-parser.js +35 -0
- package/gateway/dist/core/langgraph/signature-detector.js +23 -0
- package/gateway/dist/core/manager/goal-snapshot.js +73 -0
- package/gateway/dist/core/manager/milestone-push.js +81 -0
- package/gateway/dist/core/manager/question-ledger.js +121 -0
- package/gateway/dist/core/manager/system-rule-templates.js +76 -0
- package/gateway/dist/core/mcp/tools.js +562 -0
- package/gateway/dist/core/mcp/validator.js +165 -0
- package/gateway/dist/core/mcp-server.js +86 -0
- package/gateway/dist/core/memory/abstraction-distiller.js +44 -0
- package/gateway/dist/core/memory/cognitive-graph.js +103 -0
- package/gateway/dist/core/memory/energy-system.js +69 -0
- package/gateway/dist/core/memory/extractor.js +164 -0
- package/gateway/dist/core/memory/harmonic-index.js +530 -0
- package/gateway/dist/core/memory/harmonic-types.js +6 -0
- package/gateway/dist/core/memory/injector.js +111 -0
- package/gateway/dist/core/memory/l5-store.js +141 -0
- package/gateway/dist/core/memory/matcher.js +66 -0
- package/gateway/dist/core/memory/merger.js +95 -0
- package/gateway/dist/core/memory/migrate-v6.1.js +133 -0
- package/gateway/dist/core/memory/minhash-merger.js +195 -0
- package/gateway/dist/core/memory/observation-service.js +87 -0
- package/gateway/dist/core/memory/privacy-filter.js +163 -0
- package/gateway/dist/core/memory/reranker.js +208 -0
- package/gateway/dist/core/memory/review-scheduler.js +100 -0
- package/gateway/dist/core/memory/salience-perceptor.js +24 -0
- package/gateway/dist/core/memory/store.js +284 -0
- package/gateway/dist/core/memory/t1-store.js +183 -0
- package/gateway/dist/core/memory/t1-to-t2-compressor.js +119 -0
- package/gateway/dist/core/memory/validator.js +66 -0
- package/gateway/dist/core/plugin.js +902 -0
- package/gateway/dist/core/skills/mafw-execute/entry.js +226 -0
- package/gateway/dist/core/skills/mafw-goal/entry.js +203 -0
- package/gateway/dist/core/skills/mafw-plan/entry.js +184 -0
- package/gateway/dist/core/skills/mafw-review/entry.js +200 -0
- package/gateway/dist/core/storage/file-storage.js +120 -0
- package/gateway/dist/core/storage/sqlite-storage.js +205 -0
- package/gateway/dist/core/storage/types.js +2 -0
- package/gateway/dist/core/tools/archive-worktree.js +208 -0
- package/gateway/dist/core/tools/remote-cli.js +106 -0
- package/gateway/dist/core/tools/run-ask-user.js +79 -0
- package/gateway/dist/core/tools/run-execute-wave.js +32 -0
- package/gateway/dist/core/tools/run-plan.js +42 -0
- package/gateway/dist/core/tools/run-record-feedback.js +55 -0
- package/gateway/dist/core/tools/run-review.js +46 -0
- package/gateway/dist/core/tools/write-lesson.js +97 -0
- package/gateway/dist/core/utils/circuit-breaker.js +74 -0
- package/gateway/dist/core/utils/config-loader.js +203 -0
- package/gateway/dist/core/utils/fallback.js +19 -0
- package/gateway/dist/core/utils/git.js +70 -0
- package/gateway/dist/core/utils/github.js +52 -0
- package/gateway/dist/core/utils/global-path.js +41 -0
- package/gateway/dist/core/utils/logger.js +71 -0
- package/gateway/dist/core/utils/retry.js +44 -0
- package/gateway/dist/core/utils/state.js +175 -0
- package/gateway/dist/core/utils/status.js +156 -0
- package/gateway/dist/cost/service.js +17 -0
- package/gateway/dist/dashboard/api.js +1156 -0
- package/gateway/dist/dashboard/public/assets/index-DOXm39dm.css +1 -0
- package/gateway/dist/dashboard/public/index.html +13 -0
- package/gateway/dist/dashboard/server.js +140 -0
- package/gateway/dist/dashboard/types.js +2 -0
- package/gateway/dist/desktop-client.js +124 -0
- package/gateway/dist/eval-endpoint.js +219 -0
- package/gateway/dist/event-bus.js +7 -0
- package/gateway/dist/feedback/anchor-promotion.js +99 -0
- package/gateway/dist/feedback/deferred-memory.js +13 -0
- package/gateway/dist/feedback/miss-attribution.js +20 -0
- package/gateway/dist/graph/anchor-graph-store.js +113 -0
- package/gateway/dist/graph/anchor-graph.js +48 -0
- package/gateway/dist/health.js +53 -0
- package/gateway/dist/heartbeat.js +109 -0
- package/gateway/dist/index.js +6377 -0
- package/gateway/dist/interceptors/memory-injector.js +79 -0
- package/gateway/dist/ledger.js +121 -0
- package/gateway/dist/loop-monitor.js +74 -0
- package/gateway/dist/mcp/handlers/add-memory.js +113 -0
- package/gateway/dist/mcp/handlers/ask-user.js +63 -0
- package/gateway/dist/mcp/handlers/commit-heuristic.js +19 -0
- package/gateway/dist/mcp/handlers/create-goal.js +83 -0
- package/gateway/dist/mcp/handlers/desktop-click.js +18 -0
- package/gateway/dist/mcp/handlers/desktop-get-state.js +15 -0
- package/gateway/dist/mcp/handlers/desktop-navigate.js +18 -0
- package/gateway/dist/mcp/handlers/desktop-screenshot.js +16 -0
- package/gateway/dist/mcp/handlers/desktop-scroll.js +19 -0
- package/gateway/dist/mcp/handlers/desktop-type.js +19 -0
- package/gateway/dist/mcp/handlers/draft-automation-rule.js +45 -0
- package/gateway/dist/mcp/handlers/get-automation-history.js +15 -0
- package/gateway/dist/mcp/handlers/get-automation-rule.js +26 -0
- package/gateway/dist/mcp/handlers/get-axioms.js +14 -0
- package/gateway/dist/mcp/handlers/get-deltas.js +77 -0
- package/gateway/dist/mcp/handlers/get-memory.js +67 -0
- package/gateway/dist/mcp/handlers/get-model-route.js +16 -0
- package/gateway/dist/mcp/handlers/get-triage-item.js +17 -0
- package/gateway/dist/mcp/handlers/list-automation-rules.js +24 -0
- package/gateway/dist/mcp/handlers/list-triage-items.js +14 -0
- package/gateway/dist/mcp/handlers/load-state.js +54 -0
- package/gateway/dist/mcp/handlers/manager-answer-question.js +67 -0
- package/gateway/dist/mcp/handlers/manager-cancel-goal.js +58 -0
- package/gateway/dist/mcp/handlers/manager-get-evidence.js +57 -0
- package/gateway/dist/mcp/handlers/manager-get-goal-status.js +58 -0
- package/gateway/dist/mcp/handlers/manager-list-goals.js +60 -0
- package/gateway/dist/mcp/handlers/manager-list-pending-questions.js +67 -0
- package/gateway/dist/mcp/handlers/manager-set-goal.js +78 -0
- package/gateway/dist/mcp/handlers/merge-memory.js +184 -0
- package/gateway/dist/mcp/handlers/pin-memory.js +53 -0
- package/gateway/dist/mcp/handlers/propose-triage-decision.js +38 -0
- package/gateway/dist/mcp/handlers/record-feedback.js +59 -0
- package/gateway/dist/mcp/handlers/resolve-merge.js +92 -0
- package/gateway/dist/mcp/handlers/restart-agent.js +22 -0
- package/gateway/dist/mcp/handlers/run-automation.js +28 -0
- package/gateway/dist/mcp/handlers/search-hybrid.js +181 -0
- package/gateway/dist/mcp/handlers/supersede-memory.js +47 -0
- package/gateway/dist/mcp/handlers/update-state.js +59 -0
- package/gateway/dist/mcp/handlers/validate-rule.js +39 -0
- package/gateway/dist/mcp/sse-transport.js +97 -0
- package/gateway/dist/mcp/streamable-endpoint.js +98 -0
- package/gateway/dist/mcp/tool-registry.js +630 -0
- package/gateway/dist/media/media-agent.js +755 -0
- package/gateway/dist/media/media-plugin-loader.js +254 -0
- package/gateway/dist/media/media-runtime-executor.js +227 -0
- package/gateway/dist/media/media-service.js +199 -0
- package/gateway/dist/media/pi-adapter.js +159 -0
- package/gateway/dist/media/plugin-context.js +14 -0
- package/gateway/dist/media/tts-service.js +173 -0
- package/gateway/dist/memory/abstraction-matcher.js +28 -0
- package/gateway/dist/memory/consolidation-service.js +209 -0
- package/gateway/dist/memory/derived-terms.js +50 -0
- package/gateway/dist/memory/embedding-provider.js +330 -0
- package/gateway/dist/memory/embedding-runtime.js +174 -0
- package/gateway/dist/memory/event-log.js +84 -0
- package/gateway/dist/memory/gateway-db.js +465 -0
- package/gateway/dist/memory/harmonic-file-store.js +338 -0
- package/gateway/dist/memory/llamacpp-provider.js +370 -0
- package/gateway/dist/memory/okf-index-renderer.js +61 -0
- package/gateway/dist/memory/okf-migrator.js +71 -0
- package/gateway/dist/memory/okf-parser.js +57 -0
- package/gateway/dist/memory/okf-writer.js +107 -0
- package/gateway/dist/memory/service.js +81 -0
- package/gateway/dist/memory/t1-db.js +139 -0
- package/gateway/dist/memory/unmerge-cleanup.js +82 -0
- package/gateway/dist/memory/vector-store.js +246 -0
- package/gateway/dist/memory/write-queue.js +31 -0
- package/gateway/dist/metrics/collector.js +28 -0
- package/gateway/dist/mobile/device-store.js +123 -0
- package/gateway/dist/mobile/mdns-advertiser.js +55 -0
- package/gateway/dist/mobile/media-proxy.js +292 -0
- package/gateway/dist/mobile/pairing.js +139 -0
- package/gateway/dist/mobile/push-gateway.js +126 -0
- package/gateway/dist/mobile/tts-artifact.js +43 -0
- package/gateway/dist/opencode-adapter.js +241 -0
- package/gateway/dist/orchestration/outcome-recorder.js +218 -0
- package/gateway/dist/orchestration/policy.js +57 -0
- package/gateway/dist/orchestration/registry.js +47 -0
- package/gateway/dist/plugins/hub.js +188 -0
- package/gateway/dist/poll.js +110 -0
- package/gateway/dist/python/kernel-service.js +762 -0
- package/gateway/dist/recall/constraints-migrate.js +108 -0
- package/gateway/dist/recall/data-dir-migrate.js +120 -0
- package/gateway/dist/recall/gateway-db-migrate.js +134 -0
- package/gateway/dist/recall/index-scan.js +437 -0
- package/gateway/dist/recall/inject-format.js +222 -0
- package/gateway/dist/recall/legacy-t1-archive.js +86 -0
- package/gateway/dist/recall/memory-worker.js +128 -0
- package/gateway/dist/recall/pipeline-rules.js +76 -0
- package/gateway/dist/recall/recall-context.js +297 -0
- package/gateway/dist/recall/reflect-cursor.js +50 -0
- package/gateway/dist/recall/reflection.js +318 -0
- package/gateway/dist/recall/session-worker-pool.js +100 -0
- package/gateway/dist/recall/stale-verify.js +72 -0
- package/gateway/dist/recall/step-inject.js +173 -0
- package/gateway/dist/recall/time-anchor.js +143 -0
- package/gateway/dist/recall/ttl-map.js +72 -0
- package/gateway/dist/recall/turn-completion.js +44 -0
- package/gateway/dist/recall/turn-pipeline.js +150 -0
- package/gateway/dist/recovery.js +158 -0
- package/gateway/dist/resources/sdk-session.js +202 -0
- package/gateway/dist/retrieval/guided-retriever.js +131 -0
- package/gateway/dist/retrieval/idf-stats.js +31 -0
- package/gateway/dist/routes/embedding-config.js +100 -0
- package/gateway/dist/routes/goal-sessions.js +45 -0
- package/gateway/dist/routes/manager-rotate.js +55 -0
- package/gateway/dist/routes/media-switch.js +78 -0
- package/gateway/dist/routes/model-config.js +132 -0
- package/gateway/dist/routes/note-board.js +51 -0
- package/gateway/dist/routes/permission.js +43 -0
- package/gateway/dist/routes/pinned-recall.js +36 -0
- package/gateway/dist/routes/plugins.js +77 -0
- package/gateway/dist/routes/restart-agent.js +28 -0
- package/gateway/dist/routes/runtime-switch.js +80 -0
- package/gateway/dist/routes/session-branch.js +63 -0
- package/gateway/dist/routes/session-mutations.js +58 -0
- package/gateway/dist/routes/session-summarize.js +49 -0
- package/gateway/dist/routes/usage-plugins.js +251 -0
- package/gateway/dist/runtime/agent-definition.js +2 -0
- package/gateway/dist/runtime/auth.js +80 -0
- package/gateway/dist/runtime/completion-http.js +97 -0
- package/gateway/dist/runtime/contract.js +37 -0
- package/gateway/dist/runtime/loader.js +240 -0
- package/gateway/dist/runtime/normalize.js +59 -0
- package/gateway/dist/runtime/opencode-runtime.js +336 -0
- package/gateway/dist/runtime/pi/pi-agent-config.js +294 -0
- package/gateway/dist/runtime/pi/pi-approval-bridge.js +44 -0
- package/gateway/dist/runtime/pi/pi-approval-extension.js +62 -0
- package/gateway/dist/runtime/pi/pi-events.js +122 -0
- package/gateway/dist/runtime/pi/pi-messages.js +20 -0
- package/gateway/dist/runtime/pi/pi-provider.js +19 -0
- package/gateway/dist/runtime/pi/pi-session-storage.js +44 -0
- package/gateway/dist/runtime/pi/pi-session.js +328 -0
- package/gateway/dist/runtime/plugins/pi-runtime.js +285 -0
- package/gateway/dist/runtime/serve-for-runtime.js +22 -0
- package/gateway/dist/runtime/serve-sidecar.js +164 -0
- package/gateway/dist/runtime/serve-supervisor.js +80 -0
- package/gateway/dist/self-update.js +309 -0
- package/gateway/dist/skills/manager-agent-config.js +37 -0
- package/gateway/dist/skills/manager-identity.js +11 -0
- package/gateway/dist/skills/memory-curator-agent.js +55 -0
- package/gateway/dist/trajectory/api.js +154 -0
- package/gateway/dist/trajectory/backfill-provider.js +41 -0
- package/gateway/dist/trajectory/collector.js +337 -0
- package/gateway/dist/trajectory/trajectory-store.js +336 -0
- package/gateway/dist/trajectory/types.js +17 -0
- package/gateway/dist/tray/index.js +131 -0
- package/gateway/dist/tray/tray.ps1 +96 -0
- package/gateway/dist/types.js +2 -0
- package/gateway/dist/usage/builtin-plugins/commandcode.js +71 -0
- package/gateway/dist/usage/builtin-plugins/deepseek.js +56 -0
- package/gateway/dist/usage/builtin-plugins/gateway.js +127 -0
- package/gateway/dist/usage/builtin-plugins/kimi-for-coding.js +93 -0
- package/gateway/dist/usage/builtin-plugins/kimi.js +48 -0
- package/gateway/dist/usage/builtin-plugins/opencode-go.js +54 -0
- package/gateway/dist/usage/builtin-plugins/openrouter.js +48 -0
- package/gateway/dist/usage/builtin-plugins/siliconflow-cn.js +49 -0
- package/gateway/dist/usage/builtin-plugins/zhipuai-coding-plan.js +44 -0
- package/gateway/dist/usage/model-prices.js +39 -0
- package/gateway/dist/usage/model-stats.js +21 -0
- package/gateway/dist/usage/plugin-context.js +79 -0
- package/gateway/dist/usage/plugin-loader.js +280 -0
- package/gateway/dist/usage/templates.js +227 -0
- package/gateway/dist/usage/types.js +2 -0
- package/gateway/dist/usage/usage-poller.js +216 -0
- package/gateway/package.json +37 -0
- package/package.json +78 -0
- package/packages/tui/dist/cli.js +4664 -0
|
@@ -0,0 +1,1156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DashboardAPI = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const yaml = __importStar(require("js-yaml"));
|
|
40
|
+
const config_1 = require("../config");
|
|
41
|
+
class DashboardAPI {
|
|
42
|
+
projectDir;
|
|
43
|
+
mafwDir;
|
|
44
|
+
scheduler;
|
|
45
|
+
opencodeClient;
|
|
46
|
+
compressSessionId;
|
|
47
|
+
constructor(projectDir = '.', scheduler, opencodeClient) {
|
|
48
|
+
this.projectDir = projectDir;
|
|
49
|
+
this.mafwDir = path.join(projectDir, config_1.config.paths.mafwDir);
|
|
50
|
+
this.scheduler = scheduler;
|
|
51
|
+
this.opencodeClient = opencodeClient || null;
|
|
52
|
+
this.compressSessionId = null;
|
|
53
|
+
}
|
|
54
|
+
async getClient() {
|
|
55
|
+
return this.opencodeClient;
|
|
56
|
+
}
|
|
57
|
+
async handle(req, res) {
|
|
58
|
+
res.setHeader('Content-Type', 'application/json');
|
|
59
|
+
res.setHeader('Access-Control-Allow-Origin', config_1.config.server.cors.origin);
|
|
60
|
+
res.setHeader('Access-Control-Allow-Methods', config_1.config.server.cors.methods);
|
|
61
|
+
res.setHeader('Access-Control-Allow-Headers', config_1.config.server.cors.headers);
|
|
62
|
+
if (req.method === 'OPTIONS') {
|
|
63
|
+
res.writeHead(204);
|
|
64
|
+
res.end();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const url = req.url || '/';
|
|
69
|
+
const parsedUrl = new URL(url, `http://${req.headers.host || 'localhost'}`);
|
|
70
|
+
const pathname = parsedUrl.pathname;
|
|
71
|
+
const method = req.method || 'GET';
|
|
72
|
+
// GET /api/health
|
|
73
|
+
if (pathname === '/api/health' && method === 'GET') {
|
|
74
|
+
const result = { status: 'ok' };
|
|
75
|
+
res.writeHead(200);
|
|
76
|
+
res.end(JSON.stringify(result));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// GET /api/config — return effective config
|
|
80
|
+
if (pathname === '/api/config' && method === 'GET') {
|
|
81
|
+
res.writeHead(200);
|
|
82
|
+
res.end(JSON.stringify(config_1.config.raw));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// PUT /api/config — persist config overrides
|
|
86
|
+
if (pathname === '/api/config' && method === 'PUT') {
|
|
87
|
+
const body = await this.readBody(req);
|
|
88
|
+
const overrides = JSON.parse(body);
|
|
89
|
+
const configPath = path.join(this.mafwDir, 'config.yaml');
|
|
90
|
+
const dir = path.dirname(configPath);
|
|
91
|
+
if (!fs.existsSync(dir))
|
|
92
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
93
|
+
const yamlStr = yaml.dump(overrides, { indent: 2, lineWidth: 120, noRefs: true, sortKeys: true });
|
|
94
|
+
fs.writeFileSync(configPath, yamlStr, 'utf-8');
|
|
95
|
+
res.writeHead(200);
|
|
96
|
+
res.end(JSON.stringify({ success: true }));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// GET /api/goals
|
|
100
|
+
if (pathname === '/api/goals' && method === 'GET') {
|
|
101
|
+
const goals = await this.getGoals();
|
|
102
|
+
res.writeHead(200);
|
|
103
|
+
res.end(JSON.stringify(goals));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// GET /api/memory/search?query=&goalId=
|
|
107
|
+
if (pathname === '/api/memory/search' && method === 'GET') {
|
|
108
|
+
const query = parsedUrl.searchParams.get('query') || '';
|
|
109
|
+
const goalId = parsedUrl.searchParams.get('goalId') || '';
|
|
110
|
+
const result = await this.searchMemory(goalId, query);
|
|
111
|
+
res.writeHead(200);
|
|
112
|
+
res.end(JSON.stringify(result));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// GET /api/memory/energy-distribution?goalId=
|
|
116
|
+
if (pathname === '/api/memory/energy-distribution' && method === 'GET') {
|
|
117
|
+
const goalId = parsedUrl.searchParams.get('goalId') || undefined;
|
|
118
|
+
const result = await this.getEnergyDistribution(goalId);
|
|
119
|
+
res.writeHead(200);
|
|
120
|
+
res.end(JSON.stringify(result));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// GET /api/goals/:id/loops/:loop
|
|
124
|
+
const loopMatch = pathname.match(/^\/api\/goals\/([^/]+)\/loops\/(\d+)$/);
|
|
125
|
+
if (loopMatch && method === 'GET') {
|
|
126
|
+
const [, goalId, loop] = loopMatch;
|
|
127
|
+
const result = await this.getSessionReplay(goalId, parseInt(loop, 10));
|
|
128
|
+
res.writeHead(200);
|
|
129
|
+
res.end(JSON.stringify(result));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// GET /api/goals/:id/loops
|
|
133
|
+
const loopsMatch = pathname.match(/^\/api\/goals\/([^/]+)\/loops$/);
|
|
134
|
+
if (loopsMatch && method === 'GET') {
|
|
135
|
+
const [, goalId] = loopsMatch;
|
|
136
|
+
const result = await this.getGoalLoops(goalId);
|
|
137
|
+
res.writeHead(200);
|
|
138
|
+
res.end(JSON.stringify(result));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// GET /api/goals/:id
|
|
142
|
+
const goalMatch = pathname.match(/^\/api\/goals\/([^/]+)$/);
|
|
143
|
+
if (goalMatch && method === 'GET') {
|
|
144
|
+
const [, goalId] = goalMatch;
|
|
145
|
+
const result = await this.getGoalDetail(goalId);
|
|
146
|
+
res.writeHead(200);
|
|
147
|
+
res.end(JSON.stringify(result));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// GET /api/memory/:goalId/:tier
|
|
151
|
+
const memoryTierMatch = pathname.match(/^\/api\/memory\/([^/]+)\/([^/]+)$/);
|
|
152
|
+
if (memoryTierMatch && method === 'GET') {
|
|
153
|
+
const [, goalId, tier] = memoryTierMatch;
|
|
154
|
+
const result = await this.getMemory(goalId, tier);
|
|
155
|
+
res.writeHead(200);
|
|
156
|
+
res.end(JSON.stringify(result));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// GET /api/memory/:goalId
|
|
160
|
+
const memoryMatch = pathname.match(/^\/api\/memory\/([^/]+)$/);
|
|
161
|
+
if (memoryMatch && method === 'GET') {
|
|
162
|
+
const [, goalId] = memoryMatch;
|
|
163
|
+
const result = await this.getMemory(goalId);
|
|
164
|
+
res.writeHead(200);
|
|
165
|
+
res.end(JSON.stringify(result));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// GET /api/stats
|
|
169
|
+
if (pathname === '/api/stats' && method === 'GET') {
|
|
170
|
+
const result = await this.getStats();
|
|
171
|
+
res.writeHead(200);
|
|
172
|
+
res.end(JSON.stringify(result));
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// GET /api/sessions
|
|
176
|
+
if (pathname === '/api/sessions' && method === 'GET') {
|
|
177
|
+
const result = await this.getSessions();
|
|
178
|
+
res.writeHead(200);
|
|
179
|
+
res.end(JSON.stringify(result));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// GET /api/sessions/:id/metrics
|
|
183
|
+
const sessionMetricsMatch = pathname.match(/^\/api\/sessions\/([^/]+)\/metrics$/);
|
|
184
|
+
if (sessionMetricsMatch && method === 'GET') {
|
|
185
|
+
const [, sessionId] = sessionMetricsMatch;
|
|
186
|
+
const result = await this.getSessionMetrics(sessionId);
|
|
187
|
+
if (result === null) {
|
|
188
|
+
res.writeHead(404);
|
|
189
|
+
res.end(JSON.stringify({ error: 'Session not found' }));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
res.writeHead(200);
|
|
193
|
+
res.end(JSON.stringify(result));
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// GET /api/costs/summary
|
|
198
|
+
if (pathname === '/api/costs/summary' && method === 'GET') {
|
|
199
|
+
const result = await this.getCostSummary();
|
|
200
|
+
res.writeHead(200);
|
|
201
|
+
res.end(JSON.stringify(result));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// GET /api/costs/:goalId
|
|
205
|
+
const costGoalMatch = pathname.match(/^\/api\/costs\/([^/]+)$/);
|
|
206
|
+
if (costGoalMatch && method === 'GET') {
|
|
207
|
+
const [, goalId] = costGoalMatch;
|
|
208
|
+
const loop = parsedUrl.searchParams.get('loop') || undefined;
|
|
209
|
+
const result = await this.getCosts(goalId, loop ? parseInt(loop, 10) : undefined);
|
|
210
|
+
res.writeHead(200);
|
|
211
|
+
res.end(JSON.stringify(result));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// POST /api/gateway/pause — pause a goal
|
|
215
|
+
if (pathname === '/api/gateway/pause' && method === 'POST') {
|
|
216
|
+
const body = await this.readBody(req);
|
|
217
|
+
const { goalId } = JSON.parse(body);
|
|
218
|
+
const result = await this.gatewayControl('pause', goalId);
|
|
219
|
+
res.writeHead(200);
|
|
220
|
+
res.end(JSON.stringify(result));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// POST /api/gateway/resume — resume a goal
|
|
224
|
+
if (pathname === '/api/gateway/resume' && method === 'POST') {
|
|
225
|
+
const body = await this.readBody(req);
|
|
226
|
+
const { goalId } = JSON.parse(body);
|
|
227
|
+
const result = await this.gatewayControl('resume', goalId);
|
|
228
|
+
res.writeHead(200);
|
|
229
|
+
res.end(JSON.stringify(result));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
// POST /api/gateway/cancel — cancel a goal
|
|
233
|
+
if (pathname === '/api/gateway/cancel' && method === 'POST') {
|
|
234
|
+
const body = await this.readBody(req);
|
|
235
|
+
const { goalId } = JSON.parse(body);
|
|
236
|
+
const result = await this.gatewayControl('cancel', goalId);
|
|
237
|
+
res.writeHead(200);
|
|
238
|
+
res.end(JSON.stringify(result));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
// POST /api/gateway/checkpoint — save checkpoint for all running goals
|
|
242
|
+
if (pathname === '/api/gateway/checkpoint' && method === 'POST') {
|
|
243
|
+
const result = await this.gatewayControl('checkpoint');
|
|
244
|
+
res.writeHead(200);
|
|
245
|
+
res.end(JSON.stringify(result));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// POST /api/gateway/rollback — rollback to last checkpoint
|
|
249
|
+
if (pathname === '/api/gateway/rollback' && method === 'POST') {
|
|
250
|
+
const body = await this.readBody(req);
|
|
251
|
+
const { goalId } = JSON.parse(body);
|
|
252
|
+
const result = await this.gatewayControl('rollback', goalId);
|
|
253
|
+
res.writeHead(200);
|
|
254
|
+
res.end(JSON.stringify(result));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
// GET /api/alignment?goalId=
|
|
258
|
+
if (pathname === '/api/alignment' && method === 'GET') {
|
|
259
|
+
const goalId = parsedUrl.searchParams.get('goalId') || undefined;
|
|
260
|
+
const result = await this.getAlignment(goalId);
|
|
261
|
+
res.writeHead(200);
|
|
262
|
+
res.end(JSON.stringify(result));
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
// POST /api/feedback — record user feedback
|
|
266
|
+
if (pathname === '/api/feedback' && method === 'POST') {
|
|
267
|
+
const body = await this.readBody(req);
|
|
268
|
+
const input = JSON.parse(body);
|
|
269
|
+
const result = await this.recordFeedback(input);
|
|
270
|
+
res.writeHead(200);
|
|
271
|
+
res.end(JSON.stringify(result));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
// GET /api/feedback — list all feedback for timeline
|
|
275
|
+
if (pathname === '/api/feedback' && method === 'GET') {
|
|
276
|
+
const result = await this.listFeedback();
|
|
277
|
+
res.writeHead(200);
|
|
278
|
+
res.end(JSON.stringify(result));
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
// POST /api/user-answers/:questionId
|
|
282
|
+
const answerMatch = pathname.match(/^\/api\/user-answers\/([^/]+)$/);
|
|
283
|
+
if (answerMatch && method === 'POST') {
|
|
284
|
+
const [, questionId] = answerMatch;
|
|
285
|
+
const body = await this.readBody(req);
|
|
286
|
+
const { answer } = JSON.parse(body);
|
|
287
|
+
const ok = this.recordAnswer(questionId, answer);
|
|
288
|
+
res.writeHead(ok ? 200 : 404);
|
|
289
|
+
res.end(JSON.stringify({ success: ok }));
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// POST /api/alignment — save user weight preferences
|
|
293
|
+
if (pathname === '/api/alignment' && method === 'POST') {
|
|
294
|
+
const body = await this.readBody(req);
|
|
295
|
+
const weights = JSON.parse(body);
|
|
296
|
+
const weightsPath = path.join(this.mafwDir, 'user-weights.json');
|
|
297
|
+
fs.writeFileSync(weightsPath, JSON.stringify(weights, null, 2), 'utf-8');
|
|
298
|
+
res.writeHead(200);
|
|
299
|
+
res.end(JSON.stringify({ success: true }));
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
// POST /api/llm/compress — LLM compression proxy
|
|
303
|
+
if (pathname === '/api/llm/compress' && method === 'POST') {
|
|
304
|
+
const body = await this.readBody(req);
|
|
305
|
+
const { observations, model } = JSON.parse(body);
|
|
306
|
+
const result = await this.llmCompress(observations || [], model);
|
|
307
|
+
res.writeHead(200);
|
|
308
|
+
res.end(JSON.stringify(result));
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// GET /api/l5/axioms
|
|
312
|
+
if (pathname === '/api/l5/axioms' && method === 'GET') {
|
|
313
|
+
const topK = parseInt(parsedUrl.searchParams.get('topK') || '10', 10);
|
|
314
|
+
const { L5Store } = require('../core/memory/l5-store');
|
|
315
|
+
const store = new L5Store();
|
|
316
|
+
const result = store.getTop(topK);
|
|
317
|
+
res.writeHead(200);
|
|
318
|
+
res.end(JSON.stringify(result));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
// GET /api/l5/heuristics
|
|
322
|
+
if (pathname === '/api/l5/heuristics' && method === 'GET') {
|
|
323
|
+
const { L5Store } = require('../core/memory/l5-store');
|
|
324
|
+
const store = new L5Store();
|
|
325
|
+
const heuristics = store.loadHeuristics();
|
|
326
|
+
res.writeHead(200);
|
|
327
|
+
res.end(JSON.stringify({ heuristics }));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
res.writeHead(404);
|
|
331
|
+
res.end(JSON.stringify({ error: 'Not found' }));
|
|
332
|
+
}
|
|
333
|
+
catch (err) {
|
|
334
|
+
res.writeHead(500);
|
|
335
|
+
res.end(JSON.stringify({ error: err.message || 'Internal server error' }));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async llmCompress(observations, model) {
|
|
339
|
+
const prompt = `Analyze the following agent observations and extract structured memories.
|
|
340
|
+
Return JSON only:
|
|
341
|
+
{
|
|
342
|
+
"narrative": "summary of what happened",
|
|
343
|
+
"facts": ["specific fact 1", "specific fact 2"],
|
|
344
|
+
"concepts": ["keyword1", "keyword2"],
|
|
345
|
+
"energy": 0.5
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
Observations:
|
|
349
|
+
${observations.map((o, i) => `[${i + 1}] ${o}`).join('\n')}`;
|
|
350
|
+
const systemPrompt = 'You are a memory compression system. Extract structured memories from observations. Return ONLY valid JSON.';
|
|
351
|
+
try {
|
|
352
|
+
const client = await this.getClient();
|
|
353
|
+
if (!this.compressSessionId) {
|
|
354
|
+
const session = await client.session.create({ directory: this.projectDir });
|
|
355
|
+
this.compressSessionId = session.id;
|
|
356
|
+
}
|
|
357
|
+
const result = await client.session.prompt({
|
|
358
|
+
sessionID: this.compressSessionId,
|
|
359
|
+
parts: [{ type: 'text', text: prompt }],
|
|
360
|
+
system: systemPrompt,
|
|
361
|
+
noReply: false,
|
|
362
|
+
...(model ? {
|
|
363
|
+
model: { providerID: 'opencode', modelID: model }
|
|
364
|
+
} : {}),
|
|
365
|
+
});
|
|
366
|
+
const text = result.parts
|
|
367
|
+
?.filter((p) => p.type === 'text')
|
|
368
|
+
.map((p) => p.text)
|
|
369
|
+
.join('\n') || '';
|
|
370
|
+
return this.parseLLMResponse(text);
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
return { narrative: 'Compression failed: ' + err.message, facts: [], concepts: [], energy: 0.3 };
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
parseLLMResponse(text) {
|
|
377
|
+
try {
|
|
378
|
+
const parsed = JSON.parse(text);
|
|
379
|
+
return { narrative: parsed.narrative || '', facts: Array.isArray(parsed.facts) ? parsed.facts : [], concepts: Array.isArray(parsed.concepts) ? parsed.concepts : [], energy: typeof parsed.energy === 'number' ? parsed.energy : 0.5 };
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
return { narrative: text.slice(0, 200), facts: [], concepts: [], energy: 0.5 };
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
async recordFeedback(input) {
|
|
386
|
+
const { recordFeedback } = require('./core/tools/run-record-feedback');
|
|
387
|
+
return recordFeedback(input);
|
|
388
|
+
}
|
|
389
|
+
async listFeedback() {
|
|
390
|
+
const dir = path.join(this.mafwDir, 'user-feedback');
|
|
391
|
+
if (!fs.existsSync(dir))
|
|
392
|
+
return [];
|
|
393
|
+
const all = [];
|
|
394
|
+
const goals = fs.readdirSync(dir);
|
|
395
|
+
for (const goal of goals) {
|
|
396
|
+
const goalDir = path.join(dir, goal);
|
|
397
|
+
if (!fs.statSync(goalDir).isDirectory())
|
|
398
|
+
continue;
|
|
399
|
+
for (const file of fs.readdirSync(goalDir).filter(f => f.endsWith('.json'))) {
|
|
400
|
+
try {
|
|
401
|
+
all.push(JSON.parse(fs.readFileSync(path.join(goalDir, file), 'utf-8')));
|
|
402
|
+
}
|
|
403
|
+
catch { }
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return all.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
407
|
+
}
|
|
408
|
+
async gatewayControl(action, goalId) {
|
|
409
|
+
const stateDir = path.join(this.mafwDir, 'state');
|
|
410
|
+
if (!fs.existsSync(stateDir))
|
|
411
|
+
return { success: false, error: 'No state directory' };
|
|
412
|
+
if (action === 'checkpoint') {
|
|
413
|
+
const { RecoveryManager } = require('./core/recovery');
|
|
414
|
+
const recovery = new RecoveryManager(this.projectDir);
|
|
415
|
+
const files = fs.readdirSync(stateDir).filter(f => f.endsWith('.json'));
|
|
416
|
+
let count = 0;
|
|
417
|
+
for (const file of files) {
|
|
418
|
+
try {
|
|
419
|
+
const state = JSON.parse(fs.readFileSync(path.join(stateDir, file), 'utf-8'));
|
|
420
|
+
recovery.saveCheckpoint(state.goalId, state.loop || 1, { phase: state.phase, currentWave: state.currentWave });
|
|
421
|
+
count++;
|
|
422
|
+
}
|
|
423
|
+
catch { }
|
|
424
|
+
}
|
|
425
|
+
return { success: true, message: `Checkpoint saved for ${count} goal(s)` };
|
|
426
|
+
}
|
|
427
|
+
if (!goalId)
|
|
428
|
+
return { success: false, error: 'goalId required' };
|
|
429
|
+
const statePath = path.join(stateDir, `${goalId}.json`);
|
|
430
|
+
if (!fs.existsSync(statePath))
|
|
431
|
+
return { success: false, error: 'Goal not found' };
|
|
432
|
+
try {
|
|
433
|
+
const state = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
|
|
434
|
+
switch (action) {
|
|
435
|
+
case 'pause':
|
|
436
|
+
state._resumePhase = state.phase;
|
|
437
|
+
state.phase = 'PAUSED';
|
|
438
|
+
state.nextAction = 'PAUSED';
|
|
439
|
+
break;
|
|
440
|
+
case 'resume':
|
|
441
|
+
state.phase = state._resumePhase || state.phase;
|
|
442
|
+
state.nextAction = state._resumePhase === 'PLANNING' ? 'CREATE_PLAN_SESSION' :
|
|
443
|
+
state._resumePhase === 'EXECUTING' ? 'CREATE_EXECUTE_SESSION' :
|
|
444
|
+
state._resumePhase === 'REVIEWING' ? 'CREATE_REVIEW_SESSION' : 'WAIT_PHASE_COMPLETE';
|
|
445
|
+
delete state._resumePhase;
|
|
446
|
+
break;
|
|
447
|
+
case 'cancel':
|
|
448
|
+
state.phase = 'FAILED';
|
|
449
|
+
state.nextAction = 'CANCELLED';
|
|
450
|
+
break;
|
|
451
|
+
case 'rollback': {
|
|
452
|
+
const { RecoveryManager } = require('./core/recovery');
|
|
453
|
+
const recovery = new RecoveryManager(this.projectDir);
|
|
454
|
+
const cp = recovery.findLastCheckpoint(goalId);
|
|
455
|
+
if (cp) {
|
|
456
|
+
await recovery.restoreLoop(goalId, state.loop || 1);
|
|
457
|
+
state.phase = 'PLANNING';
|
|
458
|
+
state.nextAction = 'CREATE_PLAN_SESSION';
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
return { success: false, error: 'No checkpoint found' };
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
default:
|
|
466
|
+
return { success: false, error: 'Unknown action' };
|
|
467
|
+
}
|
|
468
|
+
state.updatedAt = new Date().toISOString();
|
|
469
|
+
const tmpPath = statePath + '.tmp';
|
|
470
|
+
fs.writeFileSync(tmpPath, JSON.stringify(state, null, 2), 'utf-8');
|
|
471
|
+
fs.renameSync(tmpPath, statePath);
|
|
472
|
+
return { success: true, message: `${action} successful` };
|
|
473
|
+
}
|
|
474
|
+
catch (err) {
|
|
475
|
+
return { success: false, error: err.message };
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
async getAlignment(goalId) {
|
|
479
|
+
const weights = { speed: 0.3, quality: 0.5, cost: 0.2 };
|
|
480
|
+
let actualWeights = { speed: 0.35, quality: 0.45, cost: 0.2 };
|
|
481
|
+
let score = 80;
|
|
482
|
+
if (goalId) {
|
|
483
|
+
// Try to read goal-specific weights from state or request
|
|
484
|
+
const requestPath = path.join(this.mafwDir, 'requests', `${goalId}.json`);
|
|
485
|
+
if (fs.existsSync(requestPath)) {
|
|
486
|
+
try {
|
|
487
|
+
const req = JSON.parse(fs.readFileSync(requestPath, 'utf-8'));
|
|
488
|
+
const p = req.priority || 'normal';
|
|
489
|
+
if (p === 'high') {
|
|
490
|
+
weights.speed = 0.5;
|
|
491
|
+
weights.quality = 0.3;
|
|
492
|
+
weights.cost = 0.2;
|
|
493
|
+
}
|
|
494
|
+
if (p === 'low') {
|
|
495
|
+
weights.speed = 0.2;
|
|
496
|
+
weights.quality = 0.3;
|
|
497
|
+
weights.cost = 0.5;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
catch { }
|
|
501
|
+
}
|
|
502
|
+
// Derive actual weights from cost data
|
|
503
|
+
const costPath = path.join(this.mafwDir, 'cost', `${goalId}.json`);
|
|
504
|
+
if (fs.existsSync(costPath)) {
|
|
505
|
+
try {
|
|
506
|
+
const records = JSON.parse(fs.readFileSync(costPath, 'utf-8'));
|
|
507
|
+
if (Array.isArray(records) && records.length > 0) {
|
|
508
|
+
const totalCost = records.reduce((s, r) => s + (r.estimatedCost || 0), 0);
|
|
509
|
+
if (totalCost > 0) {
|
|
510
|
+
const planCost = records.filter(r => r.toolName === 'mafw_search_hybrid').reduce((s, r) => s + (r.estimatedCost || 0), 0);
|
|
511
|
+
const reviewCost = records.filter(r => r.toolName === 'mafw_review').reduce((s, r) => s + (r.estimatedCost || 0), 0);
|
|
512
|
+
const executeCost = totalCost - planCost - reviewCost;
|
|
513
|
+
actualWeights = {
|
|
514
|
+
speed: totalCost > 0 ? parseFloat((executeCost / totalCost).toFixed(2)) : 0,
|
|
515
|
+
quality: totalCost > 0 ? parseFloat((reviewCost / totalCost).toFixed(2)) : 0,
|
|
516
|
+
cost: totalCost > 0 ? parseFloat((planCost / totalCost).toFixed(2)) : 0
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
catch { }
|
|
522
|
+
}
|
|
523
|
+
// Compute alignment score: 1 - Σ|userWeight - actualWeight| / 2
|
|
524
|
+
const diff = Math.abs(weights.speed - actualWeights.speed) + Math.abs(weights.quality - actualWeights.quality) + Math.abs(weights.cost - actualWeights.cost);
|
|
525
|
+
score = Math.round((1 - diff / 2) * 100);
|
|
526
|
+
}
|
|
527
|
+
return { weights, actualWeights, score };
|
|
528
|
+
}
|
|
529
|
+
recordAnswer(questionId, answer) {
|
|
530
|
+
const dir = path.join(this.mafwDir, 'user-questions');
|
|
531
|
+
const p = path.join(dir, `${questionId}.json`);
|
|
532
|
+
if (fs.existsSync(p)) {
|
|
533
|
+
const data = JSON.parse(fs.readFileSync(p, 'utf-8'));
|
|
534
|
+
data.answered = true;
|
|
535
|
+
data.answer = answer;
|
|
536
|
+
data.answeredAt = new Date().toISOString();
|
|
537
|
+
fs.writeFileSync(p, JSON.stringify(data, null, 2), 'utf-8');
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
// legacy: questions previously stored under user-questions/{goalId}/
|
|
541
|
+
if (!fs.existsSync(dir))
|
|
542
|
+
return false;
|
|
543
|
+
const goals = fs.readdirSync(dir);
|
|
544
|
+
for (const goal of goals) {
|
|
545
|
+
const lp = path.join(dir, goal, `${questionId}.json`);
|
|
546
|
+
if (fs.existsSync(lp)) {
|
|
547
|
+
const data = JSON.parse(fs.readFileSync(lp, 'utf-8'));
|
|
548
|
+
data.answered = true;
|
|
549
|
+
data.answer = answer;
|
|
550
|
+
data.answeredAt = new Date().toISOString();
|
|
551
|
+
fs.writeFileSync(lp, JSON.stringify(data, null, 2), 'utf-8');
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
async getGoals() {
|
|
558
|
+
// Prefer runtime data
|
|
559
|
+
if (this.scheduler) {
|
|
560
|
+
return this.getGoalsFromRuntime();
|
|
561
|
+
}
|
|
562
|
+
return this.getGoalsFromFS();
|
|
563
|
+
}
|
|
564
|
+
getGoalsFromRuntime() {
|
|
565
|
+
return Array.from(this.scheduler.activeGoals.values()).map((state) => {
|
|
566
|
+
const activeSessions = Object.entries(state.sessions || {})
|
|
567
|
+
.filter(([, s]) => s?.active)
|
|
568
|
+
.map(([id]) => id);
|
|
569
|
+
return {
|
|
570
|
+
goalId: state.goalId,
|
|
571
|
+
phase: state.phase,
|
|
572
|
+
nextAction: state.nextAction,
|
|
573
|
+
loop: state.loop,
|
|
574
|
+
currentWave: state.currentWave,
|
|
575
|
+
totalWaves: state.totalWaves,
|
|
576
|
+
updatedAt: state.updatedAt,
|
|
577
|
+
sessions: activeSessions.length,
|
|
578
|
+
sessionId: activeSessions[0] || undefined
|
|
579
|
+
};
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
async getGoalsFromFS() {
|
|
583
|
+
const stateDir = path.join(this.mafwDir, 'state');
|
|
584
|
+
if (!fs.existsSync(stateDir))
|
|
585
|
+
return [];
|
|
586
|
+
const files = fs.readdirSync(stateDir).filter(f => f.endsWith('.json'));
|
|
587
|
+
const goals = [];
|
|
588
|
+
for (const file of files) {
|
|
589
|
+
try {
|
|
590
|
+
const statePath = path.join(stateDir, file);
|
|
591
|
+
const state = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
|
|
592
|
+
const activeSessions = Object.entries(state.sessions || {})
|
|
593
|
+
.filter(([, s]) => s?.active)
|
|
594
|
+
.map(([id]) => id);
|
|
595
|
+
goals.push({
|
|
596
|
+
goalId: state.goalId,
|
|
597
|
+
phase: state.phase,
|
|
598
|
+
nextAction: state.nextAction,
|
|
599
|
+
loop: state.loop,
|
|
600
|
+
currentWave: state.currentWave,
|
|
601
|
+
totalWaves: state.totalWaves,
|
|
602
|
+
updatedAt: state.updatedAt,
|
|
603
|
+
sessions: activeSessions.length,
|
|
604
|
+
sessionId: activeSessions[0] || undefined
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
catch {
|
|
608
|
+
// skip malformed files
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return goals;
|
|
612
|
+
}
|
|
613
|
+
async getGoalDetail(goalId) {
|
|
614
|
+
const stateDir = path.join(this.mafwDir, 'state');
|
|
615
|
+
const requestsDir = path.join(this.mafwDir, 'requests');
|
|
616
|
+
const wavesPath = path.join(this.mafwDir, 'waves.json');
|
|
617
|
+
const statePath = path.join(stateDir, `${goalId}.json`);
|
|
618
|
+
const requestPath = path.join(requestsDir, `${goalId}.json`);
|
|
619
|
+
const detail = { goalId };
|
|
620
|
+
if (fs.existsSync(statePath)) {
|
|
621
|
+
detail.state = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
|
|
622
|
+
}
|
|
623
|
+
if (fs.existsSync(requestPath)) {
|
|
624
|
+
detail.request = JSON.parse(fs.readFileSync(requestPath, 'utf-8'));
|
|
625
|
+
}
|
|
626
|
+
if (fs.existsSync(wavesPath)) {
|
|
627
|
+
detail.waves = JSON.parse(fs.readFileSync(wavesPath, 'utf-8'));
|
|
628
|
+
}
|
|
629
|
+
return detail;
|
|
630
|
+
}
|
|
631
|
+
async getGoalLoops(goalId) {
|
|
632
|
+
const reviewsDir = path.join(this.mafwDir, 'reviews');
|
|
633
|
+
if (!fs.existsSync(reviewsDir))
|
|
634
|
+
return [];
|
|
635
|
+
const files = fs.readdirSync(reviewsDir)
|
|
636
|
+
.filter(f => f.startsWith(goalId) && f.endsWith('.json'))
|
|
637
|
+
.sort();
|
|
638
|
+
const loops = [];
|
|
639
|
+
for (const file of files) {
|
|
640
|
+
try {
|
|
641
|
+
const reviewPath = path.join(reviewsDir, file);
|
|
642
|
+
const review = JSON.parse(fs.readFileSync(reviewPath, 'utf-8'));
|
|
643
|
+
const loopMatch = file.match(/loop-(\d+)/);
|
|
644
|
+
const loopNum = loopMatch ? parseInt(loopMatch[1], 10) : loops.length + 1;
|
|
645
|
+
loops.push({
|
|
646
|
+
loop: loopNum,
|
|
647
|
+
verdict: review.verdict,
|
|
648
|
+
file: file
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
// skip
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return loops;
|
|
656
|
+
}
|
|
657
|
+
async getMemory(goalId, tier) {
|
|
658
|
+
const lessonsDir = path.join(this.mafwDir, 'lessons');
|
|
659
|
+
const parametricDir = path.join(this.mafwDir, 'parametric');
|
|
660
|
+
const entries = [];
|
|
661
|
+
const tierCounts = { L5: 0, T4: 0, T3: 0, T2: 0, T1: 0 };
|
|
662
|
+
const scanDir = (dir, sourceLabel) => {
|
|
663
|
+
if (!fs.existsSync(dir))
|
|
664
|
+
return;
|
|
665
|
+
const files = fs.readdirSync(dir).filter(f => f.endsWith('.yml') || f.endsWith('.yaml') || f.endsWith('.json'));
|
|
666
|
+
for (const file of files) {
|
|
667
|
+
const content = fs.readFileSync(path.join(dir, file), 'utf-8');
|
|
668
|
+
let tierLabel = sourceLabel;
|
|
669
|
+
if (file.startsWith('L5') || sourceLabel === 'L5')
|
|
670
|
+
tierLabel = 'L5';
|
|
671
|
+
else if (sourceLabel === 'procedural' || file.startsWith('T4'))
|
|
672
|
+
tierLabel = 'T4';
|
|
673
|
+
else if (sourceLabel === 'semantic' || file.startsWith('T3'))
|
|
674
|
+
tierLabel = 'T3';
|
|
675
|
+
else if (file.includes('L2'))
|
|
676
|
+
tierLabel = 'L2';
|
|
677
|
+
else if (file.includes('L3') || file.includes('constraint') || file.includes('prompt'))
|
|
678
|
+
tierLabel = 'L3';
|
|
679
|
+
// Map to user-facing tier labels
|
|
680
|
+
let displayTier = 'T1';
|
|
681
|
+
if (tierLabel === 'L5' || sourceLabel === 'L5')
|
|
682
|
+
displayTier = 'L5';
|
|
683
|
+
else if (tierLabel === 'T4' || tierLabel === 'procedural' || tierLabel === 'pattern')
|
|
684
|
+
displayTier = 'T4';
|
|
685
|
+
else if (tierLabel === 'T3' || tierLabel === 'semantic' || tierLabel === 'fact')
|
|
686
|
+
displayTier = 'T3';
|
|
687
|
+
else if (tierLabel === 'L2' || tierLabel === 'lesson' || tierLabel === 'T2')
|
|
688
|
+
displayTier = 'T2';
|
|
689
|
+
else if (tierLabel === 'L3' || tierLabel === 'L3_constraint' || tierLabel === 'L3_prompt')
|
|
690
|
+
displayTier = 'L3';
|
|
691
|
+
tierCounts[displayTier] = (tierCounts[displayTier] || 0) + 1;
|
|
692
|
+
entries.push({ file, tier: displayTier, content: content.substring(0, 500), path: path.join(dir, file) });
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
const costDir = path.join(this.mafwDir, 'cost');
|
|
696
|
+
if (fs.existsSync(costDir)) {
|
|
697
|
+
const costFiles = fs.readdirSync(costDir).filter(f => f.endsWith('.json'));
|
|
698
|
+
for (const f of costFiles) {
|
|
699
|
+
tierCounts.T1 = (tierCounts.T1 || 0) + 1;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
scanDir(lessonsDir, 'L2');
|
|
703
|
+
scanDir(parametricDir, 'parametric');
|
|
704
|
+
if (tier) {
|
|
705
|
+
const filtered = entries.filter(i => i.tier === tier || i.tier.toLowerCase() === tier.toLowerCase());
|
|
706
|
+
return { tiers: tierCounts, entries: filtered, total: filtered.length };
|
|
707
|
+
}
|
|
708
|
+
return { tiers: tierCounts, entries, total: entries.length };
|
|
709
|
+
}
|
|
710
|
+
async searchMemory(goalId, query) {
|
|
711
|
+
const memResult = await this.getMemory(goalId);
|
|
712
|
+
const allItems = memResult.entries || [];
|
|
713
|
+
if (!query)
|
|
714
|
+
return { query, results: allItems };
|
|
715
|
+
const lowerQuery = query.toLowerCase();
|
|
716
|
+
const results = allItems.filter((item) => {
|
|
717
|
+
const content = item.content ? item.content.toLowerCase() : '';
|
|
718
|
+
const file = item.file ? item.file.toLowerCase() : '';
|
|
719
|
+
return content.includes(lowerQuery) || file.includes(lowerQuery);
|
|
720
|
+
});
|
|
721
|
+
return {
|
|
722
|
+
query,
|
|
723
|
+
total: results.length,
|
|
724
|
+
results: results.slice(0, 50)
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
async getEnergyDistribution(goalId) {
|
|
728
|
+
const memResult = goalId ? await this.getMemory(goalId) : await this.getMemory('');
|
|
729
|
+
const items = memResult.entries || [];
|
|
730
|
+
let critical = 0, high = 0, medium = 0, low = 0;
|
|
731
|
+
for (const item of items) {
|
|
732
|
+
const content = item.content || '';
|
|
733
|
+
const energyScore = (content.match(/energy/i) || []).length +
|
|
734
|
+
(content.match(/critical/i) || []).length * 3 +
|
|
735
|
+
(content.match(/high/i) || []).length * 2 +
|
|
736
|
+
(content.match(/medium/i) || []).length;
|
|
737
|
+
if (energyScore >= 5)
|
|
738
|
+
critical++;
|
|
739
|
+
else if (energyScore >= 3)
|
|
740
|
+
high++;
|
|
741
|
+
else if (energyScore >= 1)
|
|
742
|
+
medium++;
|
|
743
|
+
else
|
|
744
|
+
low++;
|
|
745
|
+
}
|
|
746
|
+
return { critical, high, medium, low, total: memResult.total || items.length };
|
|
747
|
+
}
|
|
748
|
+
async getSessionReplay(goalId, loop) {
|
|
749
|
+
const events = [];
|
|
750
|
+
const lessonsDir = path.join(this.mafwDir, 'lessons');
|
|
751
|
+
const receiptsDir = path.join(this.mafwDir, 'receipts');
|
|
752
|
+
const reviewsDir = path.join(this.mafwDir, 'reviews');
|
|
753
|
+
const addFile = (dir, label) => {
|
|
754
|
+
if (!fs.existsSync(dir))
|
|
755
|
+
return;
|
|
756
|
+
const files = fs.readdirSync(dir)
|
|
757
|
+
.filter(f => f.startsWith(goalId) && f.includes(`loop-${loop}`));
|
|
758
|
+
for (const file of files) {
|
|
759
|
+
try {
|
|
760
|
+
const content = fs.readFileSync(path.join(dir, file), 'utf-8');
|
|
761
|
+
events.push({
|
|
762
|
+
type: label,
|
|
763
|
+
file,
|
|
764
|
+
timestamp: new Date().toISOString(),
|
|
765
|
+
content: content.substring(0, 1000)
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
catch { /* skip */ }
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
addFile(lessonsDir, 'lesson');
|
|
772
|
+
addFile(receiptsDir, 'receipt');
|
|
773
|
+
addFile(reviewsDir, 'review');
|
|
774
|
+
return events;
|
|
775
|
+
}
|
|
776
|
+
async getStats() {
|
|
777
|
+
// Prefer runtime scheduler data
|
|
778
|
+
if (this.scheduler) {
|
|
779
|
+
return this.getStatsFromRuntime();
|
|
780
|
+
}
|
|
781
|
+
return this.getStatsFromFS();
|
|
782
|
+
}
|
|
783
|
+
getStatsFromRuntime() {
|
|
784
|
+
const goals = Array.from(this.scheduler.activeGoals.values());
|
|
785
|
+
const activeGoalCount = goals.filter((g) => g.nextAction !== 'COMPLETED' && g.nextAction !== 'FAILED').length;
|
|
786
|
+
const loopsToday = goals.reduce((sum, g) => sum + (g.loop || 0), 0);
|
|
787
|
+
const wavesToday = goals.reduce((sum, g) => sum + (g.currentWave || 0), 0);
|
|
788
|
+
const activeSessions = goals.filter((g) => Object.values(g.sessions || {}).some((s) => s?.active)).length;
|
|
789
|
+
// Compute total duration from state file timestamps
|
|
790
|
+
const timestamps = goals
|
|
791
|
+
.map(g => g.updatedAt ? new Date(g.updatedAt).getTime() : 0)
|
|
792
|
+
.filter(t => t > 0);
|
|
793
|
+
const earliest = timestamps.length > 0 ? Math.min(...timestamps) : Date.now() - 3600000;
|
|
794
|
+
const totalDurationMinutes = Math.round((Date.now() - earliest) / 60000);
|
|
795
|
+
// Compute memory entries from FS
|
|
796
|
+
const mafwDir = path.join(this.projectDir, '.mafw');
|
|
797
|
+
let l1Count = 0, l2Count = 0, l3Count = 0, totalMemory = 0;
|
|
798
|
+
const lessonsDir = path.join(mafwDir, 'lessons');
|
|
799
|
+
const parametricDir = path.join(mafwDir, 'parametric');
|
|
800
|
+
const countFiles = (dir) => {
|
|
801
|
+
if (!fs.existsSync(dir))
|
|
802
|
+
return;
|
|
803
|
+
for (const file of fs.readdirSync(dir)) {
|
|
804
|
+
totalMemory++;
|
|
805
|
+
if (file.endsWith('.yml') || file.endsWith('.yaml'))
|
|
806
|
+
l2Count++;
|
|
807
|
+
else if (file.includes('constraint') || file.includes('prompt'))
|
|
808
|
+
l3Count++;
|
|
809
|
+
else
|
|
810
|
+
l1Count++;
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
countFiles(lessonsDir);
|
|
814
|
+
countFiles(parametricDir);
|
|
815
|
+
const memoryEntries = totalMemory;
|
|
816
|
+
const memoryL1 = l1Count;
|
|
817
|
+
const memoryL2 = l2Count;
|
|
818
|
+
const memoryL3 = l3Count;
|
|
819
|
+
// Compute loop success rate from FS reviews
|
|
820
|
+
let passed = 0, total = 0;
|
|
821
|
+
const reviewsDir = path.join(mafwDir, 'reviews');
|
|
822
|
+
if (fs.existsSync(reviewsDir)) {
|
|
823
|
+
for (const file of fs.readdirSync(reviewsDir).filter(f => f.endsWith('.json'))) {
|
|
824
|
+
try {
|
|
825
|
+
const review = JSON.parse(fs.readFileSync(path.join(reviewsDir, file), 'utf-8'));
|
|
826
|
+
total++;
|
|
827
|
+
if (review.verdict === 'passed' || review.verdict === 'approved')
|
|
828
|
+
passed++;
|
|
829
|
+
}
|
|
830
|
+
catch { }
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
for (const g of goals) {
|
|
834
|
+
total++;
|
|
835
|
+
if (g.nextAction === 'COMPLETED')
|
|
836
|
+
passed++;
|
|
837
|
+
}
|
|
838
|
+
const loopSuccessRate = total > 0 ? Math.round((passed / total) * 100) : 0;
|
|
839
|
+
// Agent workload from cost data
|
|
840
|
+
const agentPcts = this.computeAgentPcts();
|
|
841
|
+
return {
|
|
842
|
+
activeGoals: activeGoalCount,
|
|
843
|
+
loopsToday,
|
|
844
|
+
wavesToday,
|
|
845
|
+
activeSessions,
|
|
846
|
+
serveRunning: this.scheduler.serveRunning,
|
|
847
|
+
totalDuration: `${Math.floor(totalDurationMinutes / 60)}h ${totalDurationMinutes % 60}m`,
|
|
848
|
+
totalDurationMinutes,
|
|
849
|
+
memoryEntries,
|
|
850
|
+
memoryL1,
|
|
851
|
+
memoryL2,
|
|
852
|
+
memoryL3,
|
|
853
|
+
loopSuccessRate,
|
|
854
|
+
avgWavesPerLoop: 0,
|
|
855
|
+
...agentPcts
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
computeAgentPcts() {
|
|
859
|
+
const costDir = path.join(this.mafwDir, 'cost');
|
|
860
|
+
if (!fs.existsSync(costDir)) {
|
|
861
|
+
return { planAgentPct: 0, executeAgentPct: 0, reviewAgentPct: 0, toolAgentPct: 0, totalAgentCalls: 0 };
|
|
862
|
+
}
|
|
863
|
+
const toolCounts = {};
|
|
864
|
+
const files = fs.readdirSync(costDir).filter(f => f.endsWith('.json'));
|
|
865
|
+
for (const file of files) {
|
|
866
|
+
try {
|
|
867
|
+
const records = JSON.parse(fs.readFileSync(path.join(costDir, file), 'utf-8'));
|
|
868
|
+
for (const r of (Array.isArray(records) ? records : [])) {
|
|
869
|
+
const name = r.toolName || 'unknown';
|
|
870
|
+
toolCounts[name] = (toolCounts[name] || 0) + 1;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
catch { }
|
|
874
|
+
}
|
|
875
|
+
const total = Object.values(toolCounts).reduce((a, b) => a + b, 0);
|
|
876
|
+
if (total === 0) {
|
|
877
|
+
return { planAgentPct: 0, executeAgentPct: 0, reviewAgentPct: 0, toolAgentPct: 0, totalAgentCalls: 0 };
|
|
878
|
+
}
|
|
879
|
+
const getPct = (name) => Math.round(((toolCounts[name] || 0) / total) * 100);
|
|
880
|
+
// Map tool names to agent types
|
|
881
|
+
const planTools = (toolCounts['mafw_search_hybrid'] || 0) + (toolCounts['mafw_get_deltas'] || 0);
|
|
882
|
+
const executeTools = (toolCounts['file_edit'] || 0) + (toolCounts['file_write'] || 0);
|
|
883
|
+
const reviewTools = (toolCounts['mafw_review'] || 0) + (toolCounts['mafw_ask_user'] || 0) + (toolCounts['mafw_record_feedback'] || 0);
|
|
884
|
+
const otherTools = total - planTools - executeTools - reviewTools;
|
|
885
|
+
return {
|
|
886
|
+
planAgentPct: total > 0 ? Math.round((planTools / total) * 100) : 0,
|
|
887
|
+
executeAgentPct: total > 0 ? Math.round((executeTools / total) * 100) : 0,
|
|
888
|
+
reviewAgentPct: total > 0 ? Math.round((reviewTools / total) * 100) : 0,
|
|
889
|
+
toolAgentPct: total > 0 ? Math.round((otherTools / total) * 100) : 0,
|
|
890
|
+
totalAgentCalls: total
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
async getStatsFromFS() {
|
|
894
|
+
const stateDir = path.join(this.mafwDir, 'state');
|
|
895
|
+
const reviewsDir = path.join(this.mafwDir, 'reviews');
|
|
896
|
+
const lessonsDir = path.join(this.mafwDir, 'lessons');
|
|
897
|
+
const parametricDir = path.join(this.mafwDir, 'parametric');
|
|
898
|
+
const states = [];
|
|
899
|
+
if (fs.existsSync(stateDir)) {
|
|
900
|
+
const files = fs.readdirSync(stateDir).filter(f => f.endsWith('.json'));
|
|
901
|
+
for (const file of files) {
|
|
902
|
+
try {
|
|
903
|
+
const state = JSON.parse(fs.readFileSync(path.join(stateDir, file), 'utf-8'));
|
|
904
|
+
states.push(state);
|
|
905
|
+
}
|
|
906
|
+
catch { /* skip */ }
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
const activeGoals = states.filter(s => s.nextAction !== 'COMPLETED' && s.nextAction !== 'FAILED').length;
|
|
910
|
+
const loopsToday = states.reduce((sum, s) => sum + (s.loop || 0), 0);
|
|
911
|
+
const wavesToday = states.reduce((sum, s) => sum + (s.currentWave || 0), 0);
|
|
912
|
+
const activeSessions = states.filter(s => {
|
|
913
|
+
const sessions = s.sessions;
|
|
914
|
+
if (!sessions)
|
|
915
|
+
return false;
|
|
916
|
+
return Object.values(sessions).some((ses) => ses && ses.status === 'active');
|
|
917
|
+
}).length;
|
|
918
|
+
const timestamps = states
|
|
919
|
+
.map(s => s.updatedAt ? new Date(s.updatedAt).getTime() : 0)
|
|
920
|
+
.filter(t => t > 0);
|
|
921
|
+
const earliest = timestamps.length > 0 ? Math.min(...timestamps) : Date.now() - 3600000;
|
|
922
|
+
const totalDurationMinutes = Math.round((Date.now() - earliest) / 60000);
|
|
923
|
+
let l1Count = 0, l2Count = 0, l3Count = 0, totalMemory = 0;
|
|
924
|
+
const countFiles = (dir) => {
|
|
925
|
+
if (!fs.existsSync(dir))
|
|
926
|
+
return;
|
|
927
|
+
const files = fs.readdirSync(dir);
|
|
928
|
+
for (const file of files) {
|
|
929
|
+
totalMemory++;
|
|
930
|
+
if (file.endsWith('.yml') || file.endsWith('.yaml'))
|
|
931
|
+
l2Count++;
|
|
932
|
+
else if (file.includes('constraint') || file.includes('prompt'))
|
|
933
|
+
l3Count++;
|
|
934
|
+
else
|
|
935
|
+
l1Count++;
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
countFiles(lessonsDir);
|
|
939
|
+
countFiles(parametricDir);
|
|
940
|
+
const memoryEntries = totalMemory;
|
|
941
|
+
const memoryL1 = l1Count;
|
|
942
|
+
const memoryL2 = l2Count;
|
|
943
|
+
const memoryL3 = l3Count;
|
|
944
|
+
let passed = 0, total = 0;
|
|
945
|
+
if (fs.existsSync(reviewsDir)) {
|
|
946
|
+
const reviewFiles = fs.readdirSync(reviewsDir).filter(f => f.endsWith('.json'));
|
|
947
|
+
for (const file of reviewFiles) {
|
|
948
|
+
try {
|
|
949
|
+
const review = JSON.parse(fs.readFileSync(path.join(reviewsDir, file), 'utf-8'));
|
|
950
|
+
total++;
|
|
951
|
+
if (review.verdict === 'passed' || review.verdict === 'approved')
|
|
952
|
+
passed++;
|
|
953
|
+
}
|
|
954
|
+
catch { /* skip */ }
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
for (const s of states) {
|
|
958
|
+
if (s.nextAction === 'COMPLETED')
|
|
959
|
+
passed++;
|
|
960
|
+
total++;
|
|
961
|
+
}
|
|
962
|
+
const loopSuccessRate = total > 0 ? Math.round((passed / total) * 100) : 0;
|
|
963
|
+
const goalsWithWaves = states.filter(s => s.totalWaves != null);
|
|
964
|
+
const avgWavesPerLoop = goalsWithWaves.length > 0
|
|
965
|
+
? parseFloat((goalsWithWaves.reduce((sum, s) => sum + s.totalWaves, 0) / goalsWithWaves.length).toFixed(1))
|
|
966
|
+
: 0;
|
|
967
|
+
return {
|
|
968
|
+
activeGoals,
|
|
969
|
+
loopsToday,
|
|
970
|
+
wavesToday,
|
|
971
|
+
activeSessions,
|
|
972
|
+
totalDuration: `${Math.floor(totalDurationMinutes / 60)}h ${totalDurationMinutes % 60}m`,
|
|
973
|
+
totalDurationMinutes,
|
|
974
|
+
memoryEntries,
|
|
975
|
+
memoryL1,
|
|
976
|
+
memoryL2,
|
|
977
|
+
memoryL3,
|
|
978
|
+
loopSuccessRate,
|
|
979
|
+
avgWavesPerLoop,
|
|
980
|
+
...this.computeAgentPcts()
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
async getSessions() {
|
|
984
|
+
// Prefer runtime data
|
|
985
|
+
if (this.scheduler) {
|
|
986
|
+
return this.getSessionsFromRuntime();
|
|
987
|
+
}
|
|
988
|
+
return this.getSessionsFromFS();
|
|
989
|
+
}
|
|
990
|
+
getSessionsFromRuntime() {
|
|
991
|
+
const sessions = [];
|
|
992
|
+
for (const [, state] of this.scheduler.activeGoals) {
|
|
993
|
+
for (const [phase, session] of Object.entries(state.sessions || {})) {
|
|
994
|
+
const s = session;
|
|
995
|
+
if (s?.active) {
|
|
996
|
+
const idleMs = s.createdAt ? Date.now() - new Date(s.createdAt).getTime() : 0;
|
|
997
|
+
const idleSec = Math.floor(idleMs / 1000);
|
|
998
|
+
sessions.push({
|
|
999
|
+
id: s.id, goalId: state.goalId, agent: phase,
|
|
1000
|
+
status: 'active', idle: idleSec < 60 ? `${idleSec}s` : `${Math.floor(idleSec / 60)}m ${idleSec % 60}s`,
|
|
1001
|
+
phase
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
return sessions;
|
|
1007
|
+
}
|
|
1008
|
+
async getSessionsFromFS() {
|
|
1009
|
+
const stateDir = path.join(this.mafwDir, 'state');
|
|
1010
|
+
if (!fs.existsSync(stateDir))
|
|
1011
|
+
return [];
|
|
1012
|
+
const sessions = [];
|
|
1013
|
+
const files = fs.readdirSync(stateDir).filter(f => f.endsWith('.json'));
|
|
1014
|
+
for (const file of files) {
|
|
1015
|
+
try {
|
|
1016
|
+
const state = JSON.parse(fs.readFileSync(path.join(stateDir, file), 'utf-8'));
|
|
1017
|
+
const goalId = state.goalId || path.basename(file, '.json');
|
|
1018
|
+
const sesObj = state.sessions;
|
|
1019
|
+
if (!sesObj)
|
|
1020
|
+
continue;
|
|
1021
|
+
for (const [sesId, ses] of Object.entries(sesObj)) {
|
|
1022
|
+
const s = ses;
|
|
1023
|
+
if (s && s.status === 'active') {
|
|
1024
|
+
const updatedAt = s.updatedAt || state.updatedAt;
|
|
1025
|
+
const idleMs = updatedAt ? Date.now() - new Date(updatedAt).getTime() : 0;
|
|
1026
|
+
const idleSec = Math.floor(idleMs / 1000);
|
|
1027
|
+
const idle = idleSec < 60 ? `${idleSec}s` : `${Math.floor(idleSec / 60)}m ${idleSec % 60}s`;
|
|
1028
|
+
sessions.push({
|
|
1029
|
+
id: sesId,
|
|
1030
|
+
projectDir: s.projectDir || s.project_dir || state.projectDir || '',
|
|
1031
|
+
agent: s.phase || s.agent || state.nextAction || 'default',
|
|
1032
|
+
status: 'active',
|
|
1033
|
+
idle,
|
|
1034
|
+
goalId,
|
|
1035
|
+
phase: s.phase || s.agent || state.phase || 'idle'
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
catch { /* skip */ }
|
|
1041
|
+
}
|
|
1042
|
+
return sessions;
|
|
1043
|
+
}
|
|
1044
|
+
async getSessionMetrics(sessionId) {
|
|
1045
|
+
const stateDir = path.join(this.mafwDir, 'state');
|
|
1046
|
+
if (!fs.existsSync(stateDir))
|
|
1047
|
+
return null;
|
|
1048
|
+
const files = fs.readdirSync(stateDir).filter(f => f.endsWith('.json'));
|
|
1049
|
+
for (const file of files) {
|
|
1050
|
+
try {
|
|
1051
|
+
const state = JSON.parse(fs.readFileSync(path.join(stateDir, file), 'utf-8'));
|
|
1052
|
+
const sesObj = state.sessions;
|
|
1053
|
+
if (!sesObj)
|
|
1054
|
+
continue;
|
|
1055
|
+
if (sesObj[sessionId]) {
|
|
1056
|
+
const ses = sesObj[sessionId];
|
|
1057
|
+
const createdAt = ses.createdAt || ses.startedAt || state.updatedAt || new Date().toISOString();
|
|
1058
|
+
const uptimeMs = Date.now() - new Date(createdAt).getTime();
|
|
1059
|
+
const uptimeSec = Math.floor(uptimeMs / 1000);
|
|
1060
|
+
const uptime = `${Math.floor(uptimeSec / 60)}m ${uptimeSec % 60}s`;
|
|
1061
|
+
// Estimate token usage from cost data if available
|
|
1062
|
+
let totalTokens = 0;
|
|
1063
|
+
const costPath = path.join(this.mafwDir, 'cost', `${state.goalId || 'unknown'}.json`);
|
|
1064
|
+
if (fs.existsSync(costPath)) {
|
|
1065
|
+
try {
|
|
1066
|
+
const records = JSON.parse(fs.readFileSync(costPath, 'utf-8'));
|
|
1067
|
+
if (Array.isArray(records)) {
|
|
1068
|
+
totalTokens = records.reduce((s, r) => s + (r.estimatedTokens || 0), 0);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
catch { }
|
|
1072
|
+
}
|
|
1073
|
+
return {
|
|
1074
|
+
uptime,
|
|
1075
|
+
uptimeSeconds: uptimeSec,
|
|
1076
|
+
sseReconnects: 0,
|
|
1077
|
+
messagesSent: state.loop || 1,
|
|
1078
|
+
totalTokens
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
catch { /* skip */ }
|
|
1083
|
+
}
|
|
1084
|
+
return null;
|
|
1085
|
+
}
|
|
1086
|
+
readBody(req) {
|
|
1087
|
+
return new Promise((resolve, reject) => {
|
|
1088
|
+
let body = '';
|
|
1089
|
+
req.on('data', (chunk) => body += chunk);
|
|
1090
|
+
req.on('end', () => resolve(body));
|
|
1091
|
+
req.on('error', reject);
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
async getCosts(goalId, loop) {
|
|
1095
|
+
const costDir = path.join(this.mafwDir, 'cost');
|
|
1096
|
+
const filePath = path.join(costDir, `${goalId}.json`);
|
|
1097
|
+
if (!fs.existsSync(filePath)) {
|
|
1098
|
+
return { totalTokens: 0, totalCost: 0, byWave: [], byTool: [] };
|
|
1099
|
+
}
|
|
1100
|
+
try {
|
|
1101
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
1102
|
+
const records = JSON.parse(raw);
|
|
1103
|
+
return this.aggregateCosts(records, loop);
|
|
1104
|
+
}
|
|
1105
|
+
catch {
|
|
1106
|
+
return { totalTokens: 0, totalCost: 0, byWave: [], byTool: [] };
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
async getCostSummary() {
|
|
1110
|
+
const costDir = path.join(this.mafwDir, 'cost');
|
|
1111
|
+
if (!fs.existsSync(costDir)) {
|
|
1112
|
+
return { totalTokens: 0, totalCost: 0, totalGoals: 0, daily: [], weekly: [] };
|
|
1113
|
+
}
|
|
1114
|
+
const files = fs.readdirSync(costDir).filter(f => f.endsWith('.json'));
|
|
1115
|
+
let totalTokens = 0;
|
|
1116
|
+
let totalCost = 0;
|
|
1117
|
+
for (const file of files) {
|
|
1118
|
+
try {
|
|
1119
|
+
const records = JSON.parse(fs.readFileSync(path.join(costDir, file), 'utf-8'));
|
|
1120
|
+
totalTokens += records.reduce((s, r) => s + (r.estimatedTokens || 0), 0);
|
|
1121
|
+
totalCost += records.reduce((s, r) => s + (r.estimatedCost || 0), 0);
|
|
1122
|
+
}
|
|
1123
|
+
catch { }
|
|
1124
|
+
}
|
|
1125
|
+
return { totalTokens, totalCost, totalGoals: files.length };
|
|
1126
|
+
}
|
|
1127
|
+
aggregateCosts(records, loop) {
|
|
1128
|
+
let filtered = records;
|
|
1129
|
+
if (loop !== undefined) {
|
|
1130
|
+
filtered = filtered.filter((r) => r.loopNum === loop);
|
|
1131
|
+
}
|
|
1132
|
+
if (filtered.length === 0) {
|
|
1133
|
+
return { totalTokens: 0, totalCost: 0, byWave: [], byTool: [] };
|
|
1134
|
+
}
|
|
1135
|
+
const waveMap = new Map();
|
|
1136
|
+
const toolMap = new Map();
|
|
1137
|
+
for (const r of filtered) {
|
|
1138
|
+
const wn = r.waveNum ?? 0;
|
|
1139
|
+
const we = waveMap.get(wn) || { tokens: 0, cost: 0 };
|
|
1140
|
+
we.tokens += r.estimatedTokens || 0;
|
|
1141
|
+
we.cost += r.estimatedCost || 0;
|
|
1142
|
+
waveMap.set(wn, we);
|
|
1143
|
+
const te = toolMap.get(r.toolName) || { tokens: 0, cost: 0 };
|
|
1144
|
+
te.tokens += r.estimatedTokens || 0;
|
|
1145
|
+
te.cost += r.estimatedCost || 0;
|
|
1146
|
+
toolMap.set(r.toolName, te);
|
|
1147
|
+
}
|
|
1148
|
+
return {
|
|
1149
|
+
totalTokens: filtered.reduce((s, r) => s + (r.estimatedTokens || 0), 0),
|
|
1150
|
+
totalCost: filtered.reduce((s, r) => s + (r.estimatedCost || 0), 0),
|
|
1151
|
+
byWave: Array.from(waveMap.entries()).map(([waveNum, d]) => ({ waveNum, ...d })),
|
|
1152
|
+
byTool: Array.from(toolMap.entries()).map(([toolName, d]) => ({ toolName, ...d }))
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
exports.DashboardAPI = DashboardAPI;
|