@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,336 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrajectoryStore = void 0;
|
|
4
|
+
const EMPTY_TOKENS = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } };
|
|
5
|
+
function rowToEvent(row) {
|
|
6
|
+
return {
|
|
7
|
+
id: row.id,
|
|
8
|
+
projectID: row.project_id,
|
|
9
|
+
sessionID: row.session_id,
|
|
10
|
+
turnID: row.turn_id,
|
|
11
|
+
seq: row.seq,
|
|
12
|
+
eventType: row.event_type,
|
|
13
|
+
toolName: row.tool_name ?? undefined,
|
|
14
|
+
callID: row.call_id ?? undefined,
|
|
15
|
+
toolState: row.tool_state ?? undefined,
|
|
16
|
+
agent: row.agent ?? undefined,
|
|
17
|
+
model: row.model ?? undefined,
|
|
18
|
+
inputSummary: row.input_summary ?? undefined,
|
|
19
|
+
outputSummary: row.output_summary ?? undefined,
|
|
20
|
+
error: row.error ?? undefined,
|
|
21
|
+
tokens: row.tokens ? JSON.parse(row.tokens) : undefined,
|
|
22
|
+
cost: row.cost ?? undefined,
|
|
23
|
+
finish: row.finish ?? undefined,
|
|
24
|
+
timeMs: row.time_ms,
|
|
25
|
+
durationMs: row.duration_ms ?? undefined,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function rowToTurn(row) {
|
|
29
|
+
return {
|
|
30
|
+
projectID: row.project_id,
|
|
31
|
+
sessionID: row.session_id,
|
|
32
|
+
turnID: row.turn_id,
|
|
33
|
+
turnStartMs: row.turn_start_ms,
|
|
34
|
+
turnEndMs: row.turn_end_ms,
|
|
35
|
+
durationMs: row.duration_ms,
|
|
36
|
+
toolCount: row.tool_count,
|
|
37
|
+
toolErrorCount: row.tool_error_count,
|
|
38
|
+
reasoningCount: row.reasoning_count,
|
|
39
|
+
agentSwitchCount: row.agent_switch_count,
|
|
40
|
+
tokens: row.tokens ? JSON.parse(row.tokens) : { ...EMPTY_TOKENS },
|
|
41
|
+
cost: row.cost,
|
|
42
|
+
finish: row.finish,
|
|
43
|
+
model: row.model,
|
|
44
|
+
provider: row.provider ?? null,
|
|
45
|
+
agent: row.agent,
|
|
46
|
+
userText: row.user_text,
|
|
47
|
+
assistantText: row.assistant_text ?? undefined,
|
|
48
|
+
workerRole: row.worker_role ?? undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
class TrajectoryStore {
|
|
52
|
+
db;
|
|
53
|
+
projectID;
|
|
54
|
+
constructor(db, projectID) {
|
|
55
|
+
this.db = db;
|
|
56
|
+
this.projectID = projectID;
|
|
57
|
+
}
|
|
58
|
+
get rawDb() {
|
|
59
|
+
return this.db.db;
|
|
60
|
+
}
|
|
61
|
+
recordEvent(evt) {
|
|
62
|
+
this.rawDb
|
|
63
|
+
.prepare(`INSERT INTO trajectory_events
|
|
64
|
+
(project_id, session_id, turn_id, seq, event_type, tool_name, call_id, tool_state,
|
|
65
|
+
agent, model, input_summary, output_summary, error, tokens, cost, finish, time_ms, duration_ms)
|
|
66
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`)
|
|
67
|
+
.run(evt.projectID, evt.sessionID, evt.turnID, evt.seq, evt.eventType, evt.toolName ?? null, evt.callID ?? null, evt.toolState ?? null, evt.agent ?? null, evt.model ?? null, evt.inputSummary ?? null, evt.outputSummary ?? null, evt.error ?? null, evt.tokens ? JSON.stringify(evt.tokens) : null, evt.cost ?? null, evt.finish ?? null, evt.timeMs, evt.durationMs ?? null);
|
|
68
|
+
}
|
|
69
|
+
upsertTurn(turn) {
|
|
70
|
+
this.rawDb
|
|
71
|
+
.prepare(`INSERT INTO trajectory_turns
|
|
72
|
+
(project_id, session_id, turn_id, turn_start_ms, turn_end_ms, duration_ms,
|
|
73
|
+
tool_count, tool_error_count, reasoning_count, agent_switch_count,
|
|
74
|
+
tokens, cost, finish, model, provider, agent, user_text, assistant_text, worker_role)
|
|
75
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|
76
|
+
ON CONFLICT(session_id, turn_id) DO UPDATE SET
|
|
77
|
+
turn_end_ms = excluded.turn_end_ms,
|
|
78
|
+
duration_ms = excluded.duration_ms,
|
|
79
|
+
tool_count = excluded.tool_count,
|
|
80
|
+
tool_error_count = excluded.tool_error_count,
|
|
81
|
+
reasoning_count = excluded.reasoning_count,
|
|
82
|
+
agent_switch_count = excluded.agent_switch_count,
|
|
83
|
+
tokens = excluded.tokens,
|
|
84
|
+
cost = excluded.cost,
|
|
85
|
+
finish = excluded.finish,
|
|
86
|
+
model = excluded.model,
|
|
87
|
+
provider = excluded.provider,
|
|
88
|
+
agent = excluded.agent,
|
|
89
|
+
user_text = excluded.user_text,
|
|
90
|
+
assistant_text = excluded.assistant_text,
|
|
91
|
+
worker_role = COALESCE(excluded.worker_role, trajectory_turns.worker_role)`)
|
|
92
|
+
.run(turn.projectID, turn.sessionID, turn.turnID, turn.turnStartMs, turn.turnEndMs, turn.durationMs, turn.toolCount, turn.toolErrorCount, turn.reasoningCount, turn.agentSwitchCount, JSON.stringify(turn.tokens), turn.cost, turn.finish, turn.model, turn.provider ?? null, turn.agent, turn.userText, turn.assistantText ?? null, turn.workerRole ?? null);
|
|
93
|
+
}
|
|
94
|
+
getSessionTrajectory(sessionID, opts) {
|
|
95
|
+
const turns = this.rawDb
|
|
96
|
+
.prepare(`SELECT * FROM trajectory_turns WHERE session_id = ?
|
|
97
|
+
${opts.beforeTurn !== undefined ? 'AND turn_id < ?' : ''}
|
|
98
|
+
ORDER BY turn_id DESC LIMIT ?`)
|
|
99
|
+
.all(...(opts.beforeTurn !== undefined ? [sessionID, opts.beforeTurn, opts.limit] : [sessionID, opts.limit]));
|
|
100
|
+
if (turns.length === 0) {
|
|
101
|
+
const allEvents = this.rawDb
|
|
102
|
+
.prepare('SELECT * FROM trajectory_events WHERE session_id = ? ORDER BY turn_id ASC, seq ASC')
|
|
103
|
+
.all(sessionID);
|
|
104
|
+
if (allEvents.length === 0) {
|
|
105
|
+
return { turns: [], events: [] };
|
|
106
|
+
}
|
|
107
|
+
return { turns: [], events: allEvents.map(rowToEvent) };
|
|
108
|
+
}
|
|
109
|
+
const turnIDs = turns.map((t) => t.turn_id);
|
|
110
|
+
const placeholders = turnIDs.map(() => '?').join(',');
|
|
111
|
+
const events = this.rawDb
|
|
112
|
+
.prepare(`SELECT * FROM trajectory_events
|
|
113
|
+
WHERE session_id = ? AND turn_id IN (${placeholders})
|
|
114
|
+
ORDER BY turn_id ASC, seq ASC`)
|
|
115
|
+
.all(sessionID, ...turnIDs).map(rowToEvent);
|
|
116
|
+
return {
|
|
117
|
+
turns: turns.map(rowToTurn),
|
|
118
|
+
events,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
nextTurnId(sessionID) {
|
|
122
|
+
const row = this.rawDb
|
|
123
|
+
.prepare('SELECT COALESCE(MAX(turn_id), 0) AS m FROM trajectory_turns WHERE session_id = ?')
|
|
124
|
+
.get(sessionID);
|
|
125
|
+
return row.m + 1;
|
|
126
|
+
}
|
|
127
|
+
currentTurnId(sessionID) {
|
|
128
|
+
const row = this.rawDb
|
|
129
|
+
.prepare('SELECT COALESCE(MAX(turn_id), 0) AS m FROM trajectory_turns WHERE session_id = ?')
|
|
130
|
+
.get(sessionID);
|
|
131
|
+
return row.m;
|
|
132
|
+
}
|
|
133
|
+
deleteSession(sessionID) {
|
|
134
|
+
this.rawDb.prepare('DELETE FROM trajectory_events WHERE session_id = ?').run(sessionID);
|
|
135
|
+
this.rawDb.prepare('DELETE FROM trajectory_turns WHERE session_id = ?').run(sessionID);
|
|
136
|
+
}
|
|
137
|
+
pruneOlderThan(days) {
|
|
138
|
+
const cutoff = Math.floor(Date.now() / 1000) - days * 86400;
|
|
139
|
+
this.rawDb.prepare(`
|
|
140
|
+
DELETE FROM trajectory_events WHERE created_at < ?
|
|
141
|
+
AND session_id NOT IN (SELECT session_id FROM goal_sessions)
|
|
142
|
+
`).run(cutoff);
|
|
143
|
+
this.rawDb.prepare(`
|
|
144
|
+
DELETE FROM trajectory_turns WHERE created_at < ?
|
|
145
|
+
AND session_id NOT IN (SELECT session_id FROM goal_sessions)
|
|
146
|
+
`).run(cutoff);
|
|
147
|
+
}
|
|
148
|
+
getSessionTokenSummary(sessionID) {
|
|
149
|
+
const turns = this.rawDb
|
|
150
|
+
.prepare('SELECT tokens, cost FROM trajectory_turns WHERE session_id = ?')
|
|
151
|
+
.all(sessionID);
|
|
152
|
+
const total = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } };
|
|
153
|
+
let totalCost = 0;
|
|
154
|
+
for (const row of turns) {
|
|
155
|
+
const t = row.tokens ? JSON.parse(row.tokens) : EMPTY_TOKENS;
|
|
156
|
+
total.input += t.input || 0;
|
|
157
|
+
total.output += t.output || 0;
|
|
158
|
+
total.reasoning += t.reasoning || 0;
|
|
159
|
+
total.cache.read += t.cache?.read || 0;
|
|
160
|
+
total.cache.write += t.cache?.write || 0;
|
|
161
|
+
totalCost += row.cost || 0;
|
|
162
|
+
}
|
|
163
|
+
const count = turns.length;
|
|
164
|
+
const avg = count > 0
|
|
165
|
+
? {
|
|
166
|
+
input: Math.round(total.input / count),
|
|
167
|
+
output: Math.round(total.output / count),
|
|
168
|
+
reasoning: Math.round(total.reasoning / count),
|
|
169
|
+
cache: {
|
|
170
|
+
read: Math.round(total.cache.read / count),
|
|
171
|
+
write: Math.round(total.cache.write / count),
|
|
172
|
+
},
|
|
173
|
+
}
|
|
174
|
+
: { ...EMPTY_TOKENS };
|
|
175
|
+
return { totalTokens: total, totalCost, turnCount: count, avgTokensPerTurn: avg };
|
|
176
|
+
}
|
|
177
|
+
getProjectTokenSummary(projectID) {
|
|
178
|
+
const rows = this.rawDb
|
|
179
|
+
.prepare('SELECT tokens, cost, session_id FROM trajectory_turns WHERE project_id = ?')
|
|
180
|
+
.all(projectID);
|
|
181
|
+
const total = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } };
|
|
182
|
+
let totalCost = 0;
|
|
183
|
+
const sessions = new Set();
|
|
184
|
+
for (const row of rows) {
|
|
185
|
+
const t = row.tokens ? JSON.parse(row.tokens) : EMPTY_TOKENS;
|
|
186
|
+
total.input += t.input || 0;
|
|
187
|
+
total.output += t.output || 0;
|
|
188
|
+
total.reasoning += t.reasoning || 0;
|
|
189
|
+
total.cache.read += t.cache?.read || 0;
|
|
190
|
+
total.cache.write += t.cache?.write || 0;
|
|
191
|
+
totalCost += row.cost || 0;
|
|
192
|
+
sessions.add(row.session_id);
|
|
193
|
+
}
|
|
194
|
+
return { totalTokens: total, totalCost, turnCount: rows.length, sessionCount: sessions.size };
|
|
195
|
+
}
|
|
196
|
+
getGlobalTokenSummary() {
|
|
197
|
+
const rows = this.rawDb
|
|
198
|
+
.prepare('SELECT tokens, cost, session_id FROM trajectory_turns')
|
|
199
|
+
.all();
|
|
200
|
+
const total = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } };
|
|
201
|
+
let totalCost = 0;
|
|
202
|
+
const sessions = new Set();
|
|
203
|
+
for (const row of rows) {
|
|
204
|
+
const t = row.tokens ? JSON.parse(row.tokens) : EMPTY_TOKENS;
|
|
205
|
+
total.input += t.input || 0;
|
|
206
|
+
total.output += t.output || 0;
|
|
207
|
+
total.reasoning += t.reasoning || 0;
|
|
208
|
+
total.cache.read += t.cache?.read || 0;
|
|
209
|
+
total.cache.write += t.cache?.write || 0;
|
|
210
|
+
totalCost += row.cost || 0;
|
|
211
|
+
sessions.add(row.session_id);
|
|
212
|
+
}
|
|
213
|
+
return { totalTokens: total, totalCost, turnCount: rows.length, sessionCount: sessions.size };
|
|
214
|
+
}
|
|
215
|
+
getMemoryTokenSummary() {
|
|
216
|
+
const rows = this.rawDb
|
|
217
|
+
.prepare('SELECT tokens, cost, session_id, worker_role FROM trajectory_turns WHERE worker_role IS NOT NULL')
|
|
218
|
+
.all();
|
|
219
|
+
const total = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } };
|
|
220
|
+
let totalCost = 0;
|
|
221
|
+
const sessions = new Set();
|
|
222
|
+
const byRole = {};
|
|
223
|
+
for (const row of rows) {
|
|
224
|
+
const t = row.tokens ? JSON.parse(row.tokens) : EMPTY_TOKENS;
|
|
225
|
+
total.input += t.input || 0;
|
|
226
|
+
total.output += t.output || 0;
|
|
227
|
+
total.reasoning += t.reasoning || 0;
|
|
228
|
+
total.cache.read += t.cache?.read || 0;
|
|
229
|
+
total.cache.write += t.cache?.write || 0;
|
|
230
|
+
totalCost += row.cost || 0;
|
|
231
|
+
sessions.add(row.session_id);
|
|
232
|
+
const role = row.worker_role || 'unknown';
|
|
233
|
+
if (!byRole[role]) {
|
|
234
|
+
byRole[role] = {
|
|
235
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
236
|
+
cost: 0,
|
|
237
|
+
turns: 0,
|
|
238
|
+
sessions: new Set(),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const r = byRole[role];
|
|
242
|
+
r.tokens.input += t.input || 0;
|
|
243
|
+
r.tokens.output += t.output || 0;
|
|
244
|
+
r.tokens.reasoning += t.reasoning || 0;
|
|
245
|
+
r.tokens.cache.read += t.cache?.read || 0;
|
|
246
|
+
r.tokens.cache.write += t.cache?.write || 0;
|
|
247
|
+
r.cost += row.cost || 0;
|
|
248
|
+
r.turns++;
|
|
249
|
+
r.sessions.add(row.session_id);
|
|
250
|
+
}
|
|
251
|
+
const byRoleResult = {};
|
|
252
|
+
for (const [role, data] of Object.entries(byRole)) {
|
|
253
|
+
byRoleResult[role] = {
|
|
254
|
+
totalTokens: data.tokens,
|
|
255
|
+
totalCost: data.cost,
|
|
256
|
+
turnCount: data.turns,
|
|
257
|
+
sessionCount: data.sessions.size,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return { totalTokens: total, totalCost, turnCount: rows.length, sessionCount: sessions.size, byRole: byRoleResult };
|
|
261
|
+
}
|
|
262
|
+
getProviderCostInWindow(provider, cutoffMs) {
|
|
263
|
+
const row = this.rawDb
|
|
264
|
+
.prepare('SELECT SUM(cost) as total FROM trajectory_turns WHERE provider = ? AND turn_start_ms >= ?')
|
|
265
|
+
.get(provider, cutoffMs);
|
|
266
|
+
return row?.total || 0;
|
|
267
|
+
}
|
|
268
|
+
getProviderTotalCost(provider) {
|
|
269
|
+
const row = this.rawDb
|
|
270
|
+
.prepare('SELECT SUM(cost) as total FROM trajectory_turns WHERE provider = ?')
|
|
271
|
+
.get(provider);
|
|
272
|
+
return row?.total || 0;
|
|
273
|
+
}
|
|
274
|
+
getProviderTokensInWindow(provider, cutoffMs) {
|
|
275
|
+
const rows = this.rawDb
|
|
276
|
+
.prepare('SELECT tokens FROM trajectory_turns WHERE provider = ? AND turn_start_ms >= ?')
|
|
277
|
+
.all(provider, cutoffMs);
|
|
278
|
+
return this.aggregateTokens(rows);
|
|
279
|
+
}
|
|
280
|
+
getProviderTotalTokens(provider) {
|
|
281
|
+
const rows = this.rawDb
|
|
282
|
+
.prepare('SELECT tokens FROM trajectory_turns WHERE provider = ?')
|
|
283
|
+
.all(provider);
|
|
284
|
+
return this.aggregateTokens(rows);
|
|
285
|
+
}
|
|
286
|
+
aggregateTokens(rows) {
|
|
287
|
+
const total = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } };
|
|
288
|
+
for (const row of rows) {
|
|
289
|
+
const t = row.tokens ? JSON.parse(row.tokens) : EMPTY_TOKENS;
|
|
290
|
+
total.input += t.input || 0;
|
|
291
|
+
total.output += t.output || 0;
|
|
292
|
+
total.reasoning += t.reasoning || 0;
|
|
293
|
+
total.cache.read += t.cache?.read || 0;
|
|
294
|
+
total.cache.write += t.cache?.write || 0;
|
|
295
|
+
}
|
|
296
|
+
return total;
|
|
297
|
+
}
|
|
298
|
+
getProviderEarliestTurnInWindow(provider, cutoffMs) {
|
|
299
|
+
const row = this.rawDb
|
|
300
|
+
.prepare('SELECT MIN(turn_start_ms) as earliest FROM trajectory_turns WHERE provider = ? AND turn_start_ms >= ?')
|
|
301
|
+
.get(provider, cutoffMs);
|
|
302
|
+
return row?.earliest || null;
|
|
303
|
+
}
|
|
304
|
+
getDistinctProviders() {
|
|
305
|
+
const rows = this.rawDb
|
|
306
|
+
.prepare('SELECT DISTINCT provider FROM trajectory_turns WHERE provider IS NOT NULL')
|
|
307
|
+
.all();
|
|
308
|
+
return rows.map(r => r.provider);
|
|
309
|
+
}
|
|
310
|
+
getModelUsageStats(sinceEpochSec) {
|
|
311
|
+
const rows = this.rawDb
|
|
312
|
+
.prepare(`SELECT provider, model, COUNT(*) AS turns,
|
|
313
|
+
SUM(CAST(json_extract(tokens,'$.input') AS INTEGER)) AS input,
|
|
314
|
+
SUM(CAST(json_extract(tokens,'$.output') AS INTEGER)) AS output,
|
|
315
|
+
SUM(CAST(json_extract(tokens,'$.reasoning') AS INTEGER)) AS reasoning,
|
|
316
|
+
SUM(CAST(json_extract(tokens,'$.cache.read') AS INTEGER)) AS cache_read,
|
|
317
|
+
SUM(CAST(json_extract(tokens,'$.cache.write') AS INTEGER)) AS cache_write
|
|
318
|
+
FROM trajectory_turns
|
|
319
|
+
WHERE model IS NOT NULL${sinceEpochSec !== null ? ' AND created_at >= ?' : ''}
|
|
320
|
+
GROUP BY provider, model
|
|
321
|
+
ORDER BY (COALESCE(input,0)+COALESCE(output,0)+COALESCE(reasoning,0)+COALESCE(cache_read,0)+COALESCE(cache_write,0)) DESC`)
|
|
322
|
+
.all(...(sinceEpochSec !== null ? [sinceEpochSec] : []));
|
|
323
|
+
return rows.map((r) => ({
|
|
324
|
+
provider: r.provider ?? null,
|
|
325
|
+
model: r.model,
|
|
326
|
+
turns: r.turns,
|
|
327
|
+
tokens: {
|
|
328
|
+
input: r.input || 0,
|
|
329
|
+
output: r.output || 0,
|
|
330
|
+
reasoning: r.reasoning || 0,
|
|
331
|
+
cache: { read: r.cache_read || 0, write: r.cache_write || 0 },
|
|
332
|
+
},
|
|
333
|
+
}));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
exports.TrajectoryStore = TrajectoryStore;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRAJECTORY_EVENT_TYPES = void 0;
|
|
4
|
+
exports.TRAJECTORY_EVENT_TYPES = [
|
|
5
|
+
'tool_start',
|
|
6
|
+
'tool_update',
|
|
7
|
+
'tool_end',
|
|
8
|
+
'reasoning_start',
|
|
9
|
+
'reasoning_end',
|
|
10
|
+
'agent_switch',
|
|
11
|
+
'model_switch',
|
|
12
|
+
'step_finish',
|
|
13
|
+
'turn_start',
|
|
14
|
+
'turn_end',
|
|
15
|
+
'text_start',
|
|
16
|
+
'text_end',
|
|
17
|
+
];
|
|
@@ -0,0 +1,131 @@
|
|
|
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.startTray = startTray;
|
|
37
|
+
exports.stopTray = stopTray;
|
|
38
|
+
const child_process_1 = require("child_process");
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const os = __importStar(require("os"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const TRAY_PID_FILE = path.join(os.homedir(), '.config', 'mafw', 'tray.pid');
|
|
43
|
+
const TRAY_SCRIPT = path.join(__dirname, 'tray.ps1');
|
|
44
|
+
let trayProcess = null;
|
|
45
|
+
function writePid(pid) {
|
|
46
|
+
try {
|
|
47
|
+
fs.writeFileSync(TRAY_PID_FILE, String(pid));
|
|
48
|
+
}
|
|
49
|
+
catch { }
|
|
50
|
+
}
|
|
51
|
+
function readPid() {
|
|
52
|
+
try {
|
|
53
|
+
if (!fs.existsSync(TRAY_PID_FILE))
|
|
54
|
+
return null;
|
|
55
|
+
const pid = Number(fs.readFileSync(TRAY_PID_FILE, 'utf-8').trim());
|
|
56
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function isAlive(pid) {
|
|
63
|
+
try {
|
|
64
|
+
process.kill(pid, 0);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function startTray(port) {
|
|
72
|
+
if (process.platform !== 'win32')
|
|
73
|
+
return;
|
|
74
|
+
if (process.env.MAFW_TRAY_ENABLED === '0' || process.env.MAFW_TRAY_ENABLED === 'false')
|
|
75
|
+
return;
|
|
76
|
+
if (trayProcess)
|
|
77
|
+
return;
|
|
78
|
+
if (!fs.existsSync(TRAY_SCRIPT))
|
|
79
|
+
return;
|
|
80
|
+
// Clear any stale tray left over from a hard-killed previous gateway.
|
|
81
|
+
const stalePid = readPid();
|
|
82
|
+
if (stalePid && isAlive(stalePid)) {
|
|
83
|
+
try {
|
|
84
|
+
process.kill(stalePid);
|
|
85
|
+
}
|
|
86
|
+
catch { }
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
fs.unlinkSync(TRAY_PID_FILE);
|
|
90
|
+
}
|
|
91
|
+
catch { }
|
|
92
|
+
const child = (0, child_process_1.spawn)('powershell.exe', [
|
|
93
|
+
'-NoProfile',
|
|
94
|
+
'-STA',
|
|
95
|
+
'-WindowStyle', 'Hidden',
|
|
96
|
+
'-ExecutionPolicy', 'Bypass',
|
|
97
|
+
'-File', TRAY_SCRIPT,
|
|
98
|
+
'-Port', String(port),
|
|
99
|
+
'-PidFile', TRAY_PID_FILE,
|
|
100
|
+
], { windowsHide: true });
|
|
101
|
+
trayProcess = child;
|
|
102
|
+
child.on('exit', (code) => {
|
|
103
|
+
if (trayProcess === child)
|
|
104
|
+
trayProcess = null;
|
|
105
|
+
if (code !== 0) {
|
|
106
|
+
console.log(`[Tray] tray exited with code ${code}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
child.on('error', (err) => {
|
|
110
|
+
console.log(`[Tray] failed to start tray: ${err.message}`);
|
|
111
|
+
trayProcess = null;
|
|
112
|
+
});
|
|
113
|
+
console.log('[Tray] started on port ' + port);
|
|
114
|
+
}
|
|
115
|
+
function stopTray() {
|
|
116
|
+
const pid = readPid();
|
|
117
|
+
if (pid && isAlive(pid)) {
|
|
118
|
+
try {
|
|
119
|
+
process.kill(pid);
|
|
120
|
+
}
|
|
121
|
+
catch { }
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
fs.unlinkSync(TRAY_PID_FILE);
|
|
125
|
+
}
|
|
126
|
+
catch { }
|
|
127
|
+
if (trayProcess) {
|
|
128
|
+
trayProcess.kill();
|
|
129
|
+
trayProcess = null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# MAFW Gateway system tray (Windows only)
|
|
2
|
+
# Spawned by the gateway: powershell -NoProfile -STA -WindowStyle Hidden -ExecutionPolicy Bypass -File tray.ps1 -Port <port> -PidFile <path>
|
|
3
|
+
param(
|
|
4
|
+
[int]$Port = 3000,
|
|
5
|
+
[string]$PidFile = ""
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
9
|
+
Add-Type -AssemblyName System.Drawing
|
|
10
|
+
[System.Windows.Forms.Application]::EnableVisualStyles()
|
|
11
|
+
|
|
12
|
+
# Draw a simple icon programmatically so no binary asset is needed.
|
|
13
|
+
function New-MafwIcon {
|
|
14
|
+
$bmp = New-Object System.Drawing.Bitmap 32, 32
|
|
15
|
+
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
|
16
|
+
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
|
17
|
+
$g.Clear([System.Drawing.Color]::Transparent)
|
|
18
|
+
$bg = New-Object System.Drawing.SolidBrush ([System.Drawing.Color]::FromArgb(255, 80, 120, 255))
|
|
19
|
+
$g.FillEllipse($bg, 1, 1, 30, 30)
|
|
20
|
+
$fg = New-Object System.Drawing.SolidBrush ([System.Drawing.Color]::White)
|
|
21
|
+
$font = New-Object System.Drawing.Font "Segoe UI", 16, ([System.Drawing.FontStyle]::Bold)
|
|
22
|
+
$sf = New-Object System.Drawing.StringFormat
|
|
23
|
+
$sf.Alignment = [System.Drawing.StringAlignment]::Center
|
|
24
|
+
$sf.LineAlignment = [System.Drawing.StringAlignment]::Center
|
|
25
|
+
$rect = New-Object System.Drawing.RectangleF 2, 2, 28, 28
|
|
26
|
+
$g.DrawString("M", $font, $fg, $rect, $sf)
|
|
27
|
+
$handle = $bmp.GetHicon()
|
|
28
|
+
$icon = [System.Drawing.Icon]::FromHandle($handle)
|
|
29
|
+
$g.Dispose()
|
|
30
|
+
$bmp.Dispose()
|
|
31
|
+
return $icon
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
$script:Tray = $null
|
|
35
|
+
$script:ExitRequested = $false
|
|
36
|
+
|
|
37
|
+
function Show-Dashboard {
|
|
38
|
+
try { Start-Process "http://localhost:$Port/" } catch {}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function Stop-Gateway {
|
|
42
|
+
try { Start-Process "mafw" -ArgumentList "stop" -WindowStyle Hidden } catch {}
|
|
43
|
+
# The gateway kills this tray on shutdown; exit anyway as a fallback.
|
|
44
|
+
[System.Windows.Forms.Application]::Exit()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
$tray = New-Object System.Windows.Forms.NotifyIcon
|
|
48
|
+
$tray.Icon = New-MafwIcon
|
|
49
|
+
$tray.Text = "MAFW Gateway - http://localhost:$Port"
|
|
50
|
+
$tray.Visible = $true
|
|
51
|
+
|
|
52
|
+
$openItem = New-Object System.Windows.Forms.MenuItem "Open Dashboard"
|
|
53
|
+
$openItem.add_Click({ Show-Dashboard })
|
|
54
|
+
$stopItem = New-Object System.Windows.Forms.MenuItem "Stop Gateway"
|
|
55
|
+
$stopItem.add_Click({ Stop-Gateway })
|
|
56
|
+
$exitItem = New-Object System.Windows.Forms.MenuItem "Exit Tray"
|
|
57
|
+
$exitItem.add_Click({
|
|
58
|
+
$tray.Visible = $false
|
|
59
|
+
$tray.Dispose()
|
|
60
|
+
[System.Windows.Forms.Application]::Exit()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
$menu = New-Object System.Windows.Forms.ContextMenu
|
|
64
|
+
$menu.MenuItems.AddRange(@($openItem, $stopItem, $exitItem))
|
|
65
|
+
$tray.ContextMenu = $menu
|
|
66
|
+
$tray.add_DoubleClick({ Show-Dashboard })
|
|
67
|
+
|
|
68
|
+
# Write our own PID so the gateway can clean us up on shutdown.
|
|
69
|
+
if ($PidFile) {
|
|
70
|
+
try { Set-Content -LiteralPath $PidFile -Value $PID -Encoding ASCII } catch {}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# Self-cleanup: if the gateway dies without telling us (e.g. hard kill on
|
|
74
|
+
# Windows), exit after a few failed health checks.
|
|
75
|
+
$healthFailures = 0
|
|
76
|
+
$healthTimer = New-Object System.Windows.Forms.Timer
|
|
77
|
+
$healthTimer.Interval = 5000
|
|
78
|
+
$healthTimer.add_Tick({
|
|
79
|
+
try {
|
|
80
|
+
$resp = Invoke-WebRequest -Uri "http://127.0.0.1:$Port/health" -UseBasicParsing -TimeoutSec 3
|
|
81
|
+
$healthFailures = 0
|
|
82
|
+
} catch {
|
|
83
|
+
$healthFailures++
|
|
84
|
+
if ($healthFailures -ge 5) {
|
|
85
|
+
$healthTimer.Stop()
|
|
86
|
+
$tray.Visible = $false
|
|
87
|
+
$tray.Dispose()
|
|
88
|
+
[System.Windows.Forms.Application]::Exit()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
$healthTimer.Start()
|
|
93
|
+
|
|
94
|
+
[System.Windows.Forms.Application]::Run()
|
|
95
|
+
$tray.Visible = $false
|
|
96
|
+
$tray.Dispose()
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Builtin usage plugin: Command Code GOAT (token-plan type — 5h / 7d $ windows + monthly credits)
|
|
2
|
+
module.exports = {
|
|
3
|
+
name: 'commandcode',
|
|
4
|
+
type: 'token-plan',
|
|
5
|
+
plan: 'GOAT',
|
|
6
|
+
async fetch(ctx) {
|
|
7
|
+
const cookie = ctx.cookie('commandcode');
|
|
8
|
+
if (!cookie) return null;
|
|
9
|
+
try {
|
|
10
|
+
const res = await ctx.fetch('https://api.commandcode.ai/internal/billing/credits', {
|
|
11
|
+
headers: { 'Cookie': cookie },
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok) {
|
|
14
|
+
ctx.log.warn('[CommandCodePlugin] HTTP ' + res.status);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const body = await res.json();
|
|
18
|
+
const windowLimits = body?.windowLimits ?? body?.credits?.windowLimits;
|
|
19
|
+
if (!windowLimits) return null;
|
|
20
|
+
|
|
21
|
+
const windows = [];
|
|
22
|
+
for (const [key, label] of [['fiveHour', '5h'], ['weekly', '7d']]) {
|
|
23
|
+
const w = windowLimits[key];
|
|
24
|
+
const cap = num(w?.cap);
|
|
25
|
+
if (cap === undefined || cap <= 0) continue;
|
|
26
|
+
const used = num(w?.used) ?? 0;
|
|
27
|
+
const pct = Math.round((used / cap) * 100);
|
|
28
|
+
const resetMs = w?.resetAt ? Date.parse(w.resetAt) : undefined;
|
|
29
|
+
windows.push({
|
|
30
|
+
window: label,
|
|
31
|
+
used: Math.round(used * 100) / 100,
|
|
32
|
+
limit: Math.round(cap * 100) / 100,
|
|
33
|
+
unit: '$',
|
|
34
|
+
pct,
|
|
35
|
+
resetAt: Number.isFinite(resetMs) ? resetMs : undefined,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const monthlyCredits = num(body?.credits?.monthlyCredits);
|
|
40
|
+
if (monthlyCredits !== undefined) {
|
|
41
|
+
windows.push({
|
|
42
|
+
window: 'month',
|
|
43
|
+
used: monthlyCredits,
|
|
44
|
+
limit: 0,
|
|
45
|
+
unit: '$',
|
|
46
|
+
pct: 0,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (windows.length === 0) return null;
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
name: 'commandcode',
|
|
53
|
+
type: 'token-plan',
|
|
54
|
+
plan: 'GOAT',
|
|
55
|
+
windows,
|
|
56
|
+
};
|
|
57
|
+
} catch (err) {
|
|
58
|
+
ctx.log.warn('[CommandCodePlugin] fetch failed: ' + (err.message || err));
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function num(v) {
|
|
65
|
+
if (typeof v === 'number' && Number.isFinite(v)) return v;
|
|
66
|
+
if (typeof v === 'string' && v.trim() !== '') {
|
|
67
|
+
const n = Number(v);
|
|
68
|
+
if (Number.isFinite(n)) return n;
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|