@monoes/monomindcli 2.5.1 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/design/design-monodesign.md +6 -6
- package/.claude/agents/github/repo-architect.md +3 -3
- package/.claude/agents/github/sync-coordinator.md +2 -2
- package/.claude/agents/specialists/integration-architect.md +4 -4
- package/.claude/commands/github/repo-architect.md +4 -4
- package/.claude/commands/github/sync-coordinator.md +2 -2
- package/.claude/commands/mastermind/_repeat.md +4 -4
- package/.claude/commands/mastermind/approvev1.md +4 -4
- package/.claude/commands/mastermind/architect.md +6 -6
- package/.claude/commands/mastermind/autodev.md +5 -5
- package/.claude/commands/mastermind/brain.md +2 -2
- package/.claude/commands/mastermind/build.md +6 -6
- package/.claude/commands/mastermind/code-review.md +2 -2
- package/.claude/commands/mastermind/content.md +6 -6
- package/.claude/commands/mastermind/createorg.md +4 -4
- package/.claude/commands/mastermind/createtask.md +3 -3
- package/.claude/commands/mastermind/debug.md +5 -5
- package/.claude/commands/mastermind/design.md +5 -5
- package/.claude/commands/mastermind/do.md +2 -2
- package/.claude/commands/mastermind/execute.md +5 -5
- package/.claude/commands/mastermind/finance.md +6 -6
- package/.claude/commands/mastermind/finish.md +5 -5
- package/.claude/commands/mastermind/idea.md +6 -6
- package/.claude/commands/mastermind/ideate.md +5 -5
- package/.claude/commands/mastermind/improve.md +6 -6
- package/.claude/commands/mastermind/marketing.md +6 -6
- package/.claude/commands/mastermind/master.md +54 -54
- package/.claude/commands/mastermind/ops.md +6 -6
- package/.claude/commands/mastermind/orgs.md +2 -2
- package/.claude/commands/mastermind/orgstatus.md +2 -2
- package/.claude/commands/mastermind/plan.md +5 -5
- package/.claude/commands/mastermind/receive-review.md +5 -5
- package/.claude/commands/mastermind/release.md +6 -6
- package/.claude/commands/mastermind/research.md +6 -6
- package/.claude/commands/mastermind/review.md +6 -6
- package/.claude/commands/mastermind/runorg.md +4 -4
- package/.claude/commands/mastermind/runorgv1.md +5 -5
- package/.claude/commands/mastermind/sales.md +6 -6
- package/.claude/commands/mastermind/skill-builder.md +5 -5
- package/.claude/commands/mastermind/stoporg.md +3 -3
- package/.claude/commands/mastermind/taskdev.md +5 -5
- package/.claude/commands/mastermind/tdd.md +5 -5
- package/.claude/commands/mastermind/techport.md +5 -5
- package/.claude/commands/mastermind/verify.md +5 -5
- package/.claude/commands/mastermind/worktree.md +5 -5
- package/.claude/helpers/control-start.cjs +30 -0
- package/.claude/helpers/event-logger.cjs +2 -2
- package/.claude/helpers/extras-registry.json +1 -1
- package/.claude/helpers/handlers/agent-start-handler.cjs +2 -2
- package/.claude/helpers/handlers/edit-handler.cjs +2 -2
- package/.claude/helpers/handlers/gates-handler.cjs +1 -1
- package/.claude/helpers/handlers/route-handler.cjs +1 -1
- package/.claude/helpers/handlers/session-handler.cjs +1 -1
- package/.claude/helpers/handlers/session-restore-handler.cjs +11 -11
- package/.claude/helpers/handlers/task-handler.cjs +2 -2
- package/.claude/helpers/hook-handler.cjs +8 -8
- package/.claude/helpers/utils/monograph.cjs +44 -12
- package/.claude/skills/{mastermind-skills/access.md → mastermind-access/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/activity.md → mastermind-activity/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/adapter-manager.md → mastermind-adapter-manager/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/adapters.md → mastermind-adapters/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/agent-detail.md → mastermind-agent-detail/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/agents.md → mastermind-agents/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/approval-detail.md → mastermind-approval-detail/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/approvev1.md → mastermind-approvev1/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/architect.md → mastermind-architect/SKILL.md} +7 -7
- package/.claude/skills/{mastermind-skills/autodev.md → mastermind-autodev/SKILL.md} +10 -10
- package/.claude/skills/{mastermind-skills/backup.md → mastermind-backup/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/bootstrap.md → mastermind-bootstrap/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/budgets.md → mastermind-budgets/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/build.md → mastermind-build/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/companies.md → mastermind-companies/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/content.md → mastermind-content/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/costs.md → mastermind-costs/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/createorg.md → mastermind-createorg/SKILL.md} +3 -3
- package/.claude/skills/{mastermind-skills/debug.md → mastermind-debug/SKILL.md} +4 -4
- package/.claude/skills/{mastermind-skills/_delegation.md → mastermind-delegation/SKILL.md} +1 -1
- package/.claude/skills/{mastermind-skills/design.md → mastermind-design/SKILL.md} +9 -9
- package/.claude/skills/{mastermind-skills/diagnose.md → mastermind-diagnose/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/env.md → mastermind-env/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/environments.md → mastermind-environments/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/execute.md → mastermind-execute/SKILL.md} +10 -10
- package/.claude/skills/{mastermind-skills/export.md → mastermind-export/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/finance.md → mastermind-finance/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/goal-detail.md → mastermind-goal-detail/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/goals.md → mastermind-goals/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/heartbeatv1.md → mastermind-heartbeatv1/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/idea.md → mastermind-idea/SKILL.md} +7 -7
- package/.claude/skills/{mastermind-skills/import.md → mastermind-import/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/inbox.md → mastermind-inbox/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/instance.md → mastermind-instance/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/instance-settings.md → mastermind-instance-settings/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/invite-landing.md → mastermind-invite-landing/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/invites.md → mastermind-invites/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/issue-detail.md → mastermind-issue-detail/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/issues.md → mastermind-issues/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/join-queue.md → mastermind-join-queue/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/liveness.md → mastermind-liveness/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/marketing.md → mastermind-marketing/SKILL.md} +8 -8
- package/.claude/skills/{mastermind-skills/memory.md → mastermind-memory/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/monitor.md → mastermind-monitor/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/my-issues.md → mastermind-my-issues/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/new-agent.md → mastermind-new-agent/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/ops.md → mastermind-ops/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/org-chart.md → mastermind-org-chart/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/org-settings.md → mastermind-org-settings/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/orgs.md → mastermind-orgs/SKILL.md} +1 -1
- package/.claude/skills/{mastermind-skills/orgstatus.md → mastermind-orgstatus/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/plan.md → mastermind-plan/SKILL.md} +7 -7
- package/.claude/skills/{mastermind-skills/plan-to-tasks.md → mastermind-plan-to-tasks/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/plugin-manager.md → mastermind-plugin-manager/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/plugin-settings.md → mastermind-plugin-settings/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/plugins.md → mastermind-plugins/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/profile.md → mastermind-profile/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/project-detail.md → mastermind-project-detail/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/project-workspace.md → mastermind-project-workspace/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/projects.md → mastermind-projects/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/_protocol.md → mastermind-protocol/SKILL.md} +3 -3
- package/.claude/skills/{mastermind-skills/release.md → mastermind-release/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/_repeat.md → mastermind-repeat/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/research.md → mastermind-research/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/review.md → mastermind-review/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/routine-detail.md → mastermind-routine-detail/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/routines.md → mastermind-routines/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/runorgv1.md → mastermind-runorgv1/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/sales.md → mastermind-sales/SKILL.md} +5 -5
- package/.claude/skills/{mastermind-skills/search.md → mastermind-search/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/secrets.md → mastermind-secrets/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/skill-builder.md → mastermind-skill-builder/SKILL.md} +16 -14
- package/.claude/skills/mastermind-skills/{skills.md → SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/stoporg.md → mastermind-stoporg/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/taskdev.md → mastermind-taskdev/SKILL.md} +6 -6
- package/.claude/skills/{mastermind-skills → mastermind-taskdev}/implementer-prompt.md +1 -1
- package/.claude/skills/{mastermind-skills/tasks.md → mastermind-tasks/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/tdd.md → mastermind-tdd/SKILL.md} +4 -4
- package/.claude/skills/{mastermind-skills/techport.md → mastermind-techport/SKILL.md} +6 -6
- package/.claude/skills/{mastermind-skills/threads.md → mastermind-threads/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/tree-control.md → mastermind-tree-control/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/verify.md → mastermind-verify/SKILL.md} +1 -1
- package/.claude/skills/{mastermind-skills/wiki.md → mastermind-wiki/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/workspace-detail.md → mastermind-workspace-detail/SKILL.md} +2 -2
- package/.claude/skills/{mastermind-skills/workspaces.md → mastermind-workspaces/SKILL.md} +2 -2
- package/.claude/skills/monodesign/SKILL.md +114 -190
- package/.claude/skills/monodesign/adapt.md +1 -1
- package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +4 -4
- package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +103 -0
- package/.claude/skills/monodesign/audit.md +1 -1
- package/.claude/skills/monodesign/craft.md +2 -2
- package/.claude/skills/monodesign/critique.md +1 -1
- package/.claude/skills/monodesign/init.md +30 -0
- package/.claude/skills/monodesign/layout.md +36 -0
- package/.claude/skills/monodesign/live.md +19 -44
- package/.claude/skills/monodesign/reference/adapt.md +122 -0
- package/.claude/skills/monodesign/reference/adapt.native.md +58 -0
- package/.claude/skills/monodesign/reference/android.md +40 -0
- package/.claude/skills/monodesign/reference/animate.md +39 -11
- package/.claude/skills/monodesign/reference/antipatterns-catalog.md +67 -16
- package/.claude/skills/monodesign/reference/audit.md +5 -3
- package/.claude/skills/monodesign/reference/audit.native.md +139 -0
- package/.claude/skills/monodesign/reference/bolder.md +71 -64
- package/.claude/skills/monodesign/reference/brand.md +12 -18
- package/.claude/skills/monodesign/reference/clarify.md +114 -0
- package/.claude/skills/monodesign/reference/codex.md +4 -6
- package/.claude/skills/monodesign/reference/colorize.md +108 -5
- package/.claude/skills/monodesign/reference/craft.md +70 -143
- package/.claude/skills/monodesign/reference/critique.md +635 -68
- package/.claude/skills/monodesign/reference/delight.md +1 -1
- package/.claude/skills/monodesign/reference/distill.md +1 -1
- package/.claude/skills/monodesign/reference/document.md +24 -22
- package/.claude/skills/monodesign/reference/extract.md +1 -1
- package/.claude/skills/monodesign/reference/hooks.md +22 -29
- package/.claude/skills/monodesign/reference/init.md +221 -0
- package/.claude/skills/monodesign/reference/interaction-design.md +0 -6
- package/.claude/skills/monodesign/reference/ios.md +45 -0
- package/.claude/skills/monodesign/reference/layout.md +57 -13
- package/.claude/skills/monodesign/reference/live.md +159 -71
- package/.claude/skills/monodesign/reference/overdrive.md +1 -1
- package/.claude/skills/monodesign/reference/personas.md +1 -1
- package/.claude/skills/monodesign/reference/polish.md +16 -8
- package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +1 -1
- package/.claude/skills/monodesign/reference/product.md +1 -3
- package/.claude/skills/monodesign/reference/quieter.md +1 -1
- package/.claude/skills/monodesign/reference/shape.md +27 -13
- package/.claude/skills/monodesign/reference/teach.md +6 -152
- package/.claude/skills/monodesign/reference/typeset.md +180 -3
- package/.claude/skills/monodesign/scripts/command-metadata.json +94 -0
- package/.claude/skills/monodesign/scripts/context-signals.mjs +260 -0
- package/.claude/skills/monodesign/scripts/context.mjs +1061 -0
- package/.claude/skills/monodesign/scripts/critique-storage.mjs +416 -0
- package/.claude/skills/monodesign/scripts/detect-csp.mjs +198 -0
- package/.claude/skills/monodesign/scripts/detect.mjs +33 -0
- package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +1962 -0
- package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +321 -0
- package/.claude/skills/monodesign/scripts/detector/design-system.mjs +814 -0
- package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +5601 -0
- package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +50 -0
- package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +259 -0
- package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +258 -0
- package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +636 -0
- package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +1015 -0
- package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +253 -0
- package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +198 -0
- package/.claude/skills/monodesign/scripts/detector/findings.mjs +12 -0
- package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +181 -0
- package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +373 -0
- package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +426 -0
- package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +198 -0
- package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +166 -0
- package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +563 -0
- package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +2995 -0
- package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +124 -0
- package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +101 -0
- package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +30 -0
- package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +148 -0
- package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +7 -0
- package/.claude/skills/monodesign/scripts/hook-admin.mjs +661 -0
- package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +516 -0
- package/.claude/skills/monodesign/scripts/hook-lib.mjs +1776 -0
- package/.claude/skills/monodesign/scripts/hook.mjs +61 -0
- package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +842 -0
- package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +69 -0
- package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +640 -0
- package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +129 -0
- package/.claude/skills/monodesign/scripts/lib/provider.mjs +4 -0
- package/.claude/skills/monodesign/scripts/lib/target-args.mjs +42 -0
- package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +50 -0
- package/.claude/skills/monodesign/scripts/live/completion.mjs +19 -0
- package/.claude/skills/monodesign/scripts/live/event-validation.mjs +137 -0
- package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +458 -0
- package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +939 -0
- package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +357 -0
- package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +152 -0
- package/.claude/skills/monodesign/scripts/live/session-store.mjs +293 -0
- package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +826 -0
- package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +274 -0
- package/.claude/skills/monodesign/scripts/live/ui-core.mjs +180 -0
- package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +36 -0
- package/.claude/skills/monodesign/scripts/live-accept.mjs +812 -0
- package/.claude/skills/monodesign/scripts/live-browser-dom.js +146 -0
- package/.claude/skills/monodesign/scripts/live-browser-session.js +123 -0
- package/.claude/skills/monodesign/scripts/live-browser.js +11240 -0
- package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +1241 -0
- package/.claude/skills/monodesign/scripts/live-complete.mjs +75 -0
- package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +683 -0
- package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +51 -0
- package/.claude/skills/monodesign/scripts/live-inject.mjs +583 -0
- package/.claude/skills/monodesign/scripts/live-insert.mjs +272 -0
- package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +363 -0
- package/.claude/skills/monodesign/scripts/live-poll.mjs +384 -0
- package/.claude/skills/monodesign/scripts/live-resume.mjs +94 -0
- package/.claude/skills/monodesign/scripts/live-server.mjs +1137 -0
- package/.claude/skills/monodesign/scripts/live-status.mjs +61 -0
- package/.claude/skills/monodesign/scripts/live-target.mjs +30 -0
- package/.claude/skills/monodesign/scripts/live-wrap.mjs +894 -0
- package/.claude/skills/monodesign/scripts/live.mjs +297 -0
- package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +14 -0
- package/.claude/skills/monodesign/scripts/palette.mjs +633 -0
- package/.claude/skills/monodesign/scripts/pin.mjs +221 -0
- package/.claude/skills/monodesign/teach.md +7 -58
- package/README.md +1 -1
- package/dist/src/commands/design-detect.d.ts +7 -1
- package/dist/src/commands/design-detect.d.ts.map +1 -1
- package/dist/src/commands/design-detect.js +131 -38
- package/dist/src/commands/design-detect.js.map +1 -1
- package/dist/src/commands/design-palette.d.ts +0 -1
- package/dist/src/commands/design-palette.d.ts.map +1 -1
- package/dist/src/commands/design-palette.js +2 -3
- package/dist/src/commands/design-palette.js.map +1 -1
- package/dist/src/commands/doc.d.ts.map +1 -1
- package/dist/src/commands/doc.js +72 -15
- package/dist/src/commands/doc.js.map +1 -1
- package/dist/src/commands/doctor-project-checks.d.ts +5 -1
- package/dist/src/commands/doctor-project-checks.d.ts.map +1 -1
- package/dist/src/commands/doctor-project-checks.js +24 -1
- package/dist/src/commands/doctor-project-checks.js.map +1 -1
- package/dist/src/commands/doctor.js +3 -3
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/hooks-workers.d.ts +1 -1
- package/dist/src/commands/hooks-workers.js +8 -8
- package/dist/src/commands/hooks-workers.js.map +1 -1
- package/dist/src/commands/init.js +2 -2
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/org.d.ts.map +1 -1
- package/dist/src/commands/org.js +109 -9
- package/dist/src/commands/org.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/claudemd-generator.js +5 -5
- package/dist/src/init/claudemd-generator.js.map +1 -1
- package/dist/src/init/executor.d.ts.map +1 -1
- package/dist/src/init/executor.js +17 -6
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/knowledge/document-pipeline.d.ts +2 -0
- package/dist/src/knowledge/document-pipeline.d.ts.map +1 -1
- package/dist/src/knowledge/document-pipeline.js +4 -1
- package/dist/src/knowledge/document-pipeline.js.map +1 -1
- package/dist/src/mcp-server.js +2 -2
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/hooks-intelligence.d.ts +1 -1
- package/dist/src/mcp-tools/hooks-intelligence.js +1 -1
- package/dist/src/mcp-tools/hooks-routing.js +2 -2
- package/dist/src/mcp-tools/hooks-routing.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +1 -1
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/knowledge-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/knowledge-tools.js +38 -7
- package/dist/src/mcp-tools/knowledge-tools.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.d.ts +8 -3
- package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +193 -31
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/memory/memory-bridge.d.ts +33 -0
- package/dist/src/memory/memory-bridge.d.ts.map +1 -1
- package/dist/src/memory/memory-bridge.js +166 -17
- package/dist/src/memory/memory-bridge.js.map +1 -1
- package/dist/src/memory/memory-kg.d.ts +186 -0
- package/dist/src/memory/memory-kg.d.ts.map +1 -0
- package/dist/src/memory/memory-kg.js +450 -0
- package/dist/src/memory/memory-kg.js.map +1 -0
- package/dist/src/memory/query-router.d.ts +44 -0
- package/dist/src/memory/query-router.d.ts.map +1 -0
- package/dist/src/memory/query-router.js +113 -0
- package/dist/src/memory/query-router.js.map +1 -0
- package/dist/src/orgrt/daemon.d.ts +18 -0
- package/dist/src/orgrt/daemon.d.ts.map +1 -1
- package/dist/src/orgrt/daemon.js +249 -12
- package/dist/src/orgrt/daemon.js.map +1 -1
- package/dist/src/orgrt/migrate.d.ts.map +1 -1
- package/dist/src/orgrt/migrate.js +7 -0
- package/dist/src/orgrt/migrate.js.map +1 -1
- package/dist/src/orgrt/policy.d.ts.map +1 -1
- package/dist/src/orgrt/policy.js +7 -0
- package/dist/src/orgrt/policy.js.map +1 -1
- package/dist/src/orgrt/session.d.ts +24 -1
- package/dist/src/orgrt/session.d.ts.map +1 -1
- package/dist/src/orgrt/session.js +18 -3
- package/dist/src/orgrt/session.js.map +1 -1
- package/dist/src/orgrt/templates.d.ts +1 -0
- package/dist/src/orgrt/templates.d.ts.map +1 -1
- package/dist/src/orgrt/templates.js +9 -4
- package/dist/src/orgrt/templates.js.map +1 -1
- package/dist/src/orgrt/types.d.ts +15 -0
- package/dist/src/orgrt/types.d.ts.map +1 -1
- package/dist/src/orgrt/types.js +2 -0
- package/dist/src/orgrt/types.js.map +1 -1
- package/dist/src/routing/embed-worker.js +1 -1
- package/dist/src/routing/embed-worker.js.map +1 -1
- package/dist/src/routing/llm-caller.js +1 -1
- package/dist/src/routing/route-layer-factory.js +1 -1
- package/dist/src/routing/route-layer-factory.js.map +1 -1
- package/dist/src/ui/dashboard.html +176 -26
- package/dist/src/ui/data/sessions/final-sess-001.jsonl +180 -180
- package/dist/src/ui/orgs.html +24 -0
- package/dist/src/ui/server.mjs +162 -12
- package/dist/src/update/checker.js +3 -3
- package/dist/src/update/checker.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -6
- /package/.claude/skills/{mastermind-skills/_agent-select.md → mastermind-agent-select/SKILL.md} +0 -0
- /package/.claude/skills/{mastermind-skills/finish.md → mastermind-finish/SKILL.md} +0 -0
- /package/.claude/skills/{mastermind-skills/_intake.md → mastermind-intake/SKILL.md} +0 -0
- /package/.claude/skills/{mastermind-skills → mastermind-marketing}/references/copywriting-frameworks.md +0 -0
- /package/.claude/skills/{mastermind-skills → mastermind-marketing}/references/persuasion-psychology.md +0 -0
- /package/.claude/skills/{mastermind-skills/monotask.md → mastermind-monotask/SKILL.md} +0 -0
- /package/.claude/skills/{mastermind-skills/receive-review.md → mastermind-receive-review/SKILL.md} +0 -0
- /package/.claude/skills/{mastermind-skills/runorg.md → mastermind-runorg/SKILL.md} +0 -0
- /package/.claude/skills/{mastermind-skills → mastermind-taskdev}/code-quality-reviewer-prompt.md +0 -0
- /package/.claude/skills/{mastermind-skills → mastermind-taskdev}/final-reviewer-prompt.md +0 -0
- /package/.claude/skills/{mastermind-skills → mastermind-taskdev}/spec-reviewer-prompt.md +0 -0
- /package/.claude/skills/{mastermind-skills/worktree.md → mastermind-worktree/SKILL.md} +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Knowledge Graph — entities, relations, and rules distilled from
|
|
3
|
+
* agent sessions and org runs (cognee-concept port, Phase 2 of
|
|
4
|
+
* docs/mastermind/2026-07-19-cognee-port-plan.md).
|
|
5
|
+
*
|
|
6
|
+
* Storage rides store A (memory-bridge) rather than a dedicated SQLite DB:
|
|
7
|
+
* nodes live in namespace `kg:nodes`, edges in `kg:edges`, distilled rules
|
|
8
|
+
* additionally in `rules` (so existing knowledge/injection surfaces find them).
|
|
9
|
+
* That buys embeddings, upsert, sql.js fallback, and the Phase 1
|
|
10
|
+
* feedback/frequency weighting for free — KG node ranking improves with use
|
|
11
|
+
* automatically.
|
|
12
|
+
*
|
|
13
|
+
* Identity is deterministic and NAME-ONLY (cognee's Entity.identity_fields):
|
|
14
|
+
* the entry KEY is `n:<normalized-name>`, so the same entity extracted from
|
|
15
|
+
* any session merges idempotently via upsert regardless of assigned type.
|
|
16
|
+
* Every write carries `origin_refs` so a bad ingest can be rolled back per
|
|
17
|
+
* run/session.
|
|
18
|
+
*
|
|
19
|
+
* // monolean: graph traversal is in-process over a full kg:edges list —
|
|
20
|
+
* // fine to ~10k edges; upgrade path is a real SQLite edges table with
|
|
21
|
+
* // indexed src/dst columns if orgs outgrow that.
|
|
22
|
+
*
|
|
23
|
+
* @module v1/cli/memory/memory-kg
|
|
24
|
+
*/
|
|
25
|
+
export declare const KG_NODES_NS = "kg:nodes";
|
|
26
|
+
export declare const KG_EDGES_NS = "kg:edges";
|
|
27
|
+
export declare const RULES_NS = "rules";
|
|
28
|
+
export interface KgNodeInput {
|
|
29
|
+
name: string;
|
|
30
|
+
/** Basic type, cognee-style ("Person", "Tool", "Service") — not over-specific. */
|
|
31
|
+
type?: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
nodeSet?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface KgEdgeInput {
|
|
36
|
+
source: string;
|
|
37
|
+
target: string;
|
|
38
|
+
/** snake_case relation name. */
|
|
39
|
+
relation: string;
|
|
40
|
+
/** One-sentence concrete fact using the endpoint names. */
|
|
41
|
+
description?: string;
|
|
42
|
+
sourceType?: string;
|
|
43
|
+
targetType?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface KgIngestResult {
|
|
46
|
+
success: boolean;
|
|
47
|
+
nodesAdded: number;
|
|
48
|
+
nodesMerged: number;
|
|
49
|
+
edgesAdded: number;
|
|
50
|
+
edgesMerged: number;
|
|
51
|
+
error?: string;
|
|
52
|
+
}
|
|
53
|
+
/** cognee DataPoint normalization: lowercase, spaces→_, strip apostrophes. */
|
|
54
|
+
export declare function normalizeName(name: string): string;
|
|
55
|
+
/** Identity is NAME-ONLY (cognee's Entity.identity_fields = ["name"]) — type
|
|
56
|
+
* lives in metadata. Including type in the key forked the same entity when
|
|
57
|
+
* the LLM said "Module" and the heuristic said "entity". */
|
|
58
|
+
export declare function nodeKey(_type: string, name: string): string;
|
|
59
|
+
/** Idempotently merge extracted nodes/edges into the KG. Same-name entities
|
|
60
|
+
* collapse onto one node (deterministic key + upsert); origin_refs accumulate
|
|
61
|
+
* so rollback can undo a single run's contribution. */
|
|
62
|
+
export declare function kgIngest(options: {
|
|
63
|
+
nodes: KgNodeInput[];
|
|
64
|
+
edges?: KgEdgeInput[];
|
|
65
|
+
/** Provenance: run id, session id, or doc hash this extraction came from. */
|
|
66
|
+
originRef: string;
|
|
67
|
+
dbPath?: string;
|
|
68
|
+
}): Promise<KgIngestResult>;
|
|
69
|
+
export interface RuleVerdict {
|
|
70
|
+
rule: string;
|
|
71
|
+
verdict: 'accepted' | 'already_known' | 'invalid';
|
|
72
|
+
similarTo?: string;
|
|
73
|
+
}
|
|
74
|
+
/** Stage-2 of cognee's curator/writer distillation: the CALLER (an LLM agent)
|
|
75
|
+
* proposes candidate rules; this accepts each unless a semantically
|
|
76
|
+
* near-identical rule exists (embedding dedup — deterministic keys can't
|
|
77
|
+
* collapse paraphrases). Accepted rules are stored both as KG nodes
|
|
78
|
+
* (node_set=rules) and as plain `rules`-namespace entries so the existing
|
|
79
|
+
* injection/search surfaces pick them up with zero new plumbing. */
|
|
80
|
+
export declare function kgIngestRules(options: {
|
|
81
|
+
rules: {
|
|
82
|
+
rule: string;
|
|
83
|
+
context?: string;
|
|
84
|
+
}[];
|
|
85
|
+
originRef: string;
|
|
86
|
+
dbPath?: string;
|
|
87
|
+
/** Similarity above which a candidate is already_known (default 0.78 —
|
|
88
|
+
* MiniLM paraphrases of the same rule commonly land 0.78-0.9; cognee's
|
|
89
|
+
* equivalent control is prompt-injected LLM judgment, which we approximate). */
|
|
90
|
+
dedupThreshold?: number;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
success: boolean;
|
|
93
|
+
verdicts: RuleVerdict[];
|
|
94
|
+
accepted: number;
|
|
95
|
+
error?: string;
|
|
96
|
+
}>;
|
|
97
|
+
/** List stored rules (for injection or review). */
|
|
98
|
+
export declare function kgListRules(options?: {
|
|
99
|
+
dbPath?: string;
|
|
100
|
+
limit?: number;
|
|
101
|
+
}): Promise<{
|
|
102
|
+
rule: string;
|
|
103
|
+
key: string;
|
|
104
|
+
}[]>;
|
|
105
|
+
export interface KgSearchResult {
|
|
106
|
+
success: boolean;
|
|
107
|
+
/** Rendered triplet lines, best first. */
|
|
108
|
+
context: string;
|
|
109
|
+
triplets: {
|
|
110
|
+
source: string;
|
|
111
|
+
relation: string;
|
|
112
|
+
target: string;
|
|
113
|
+
fact: string;
|
|
114
|
+
score: number;
|
|
115
|
+
}[];
|
|
116
|
+
seeds: {
|
|
117
|
+
name: string;
|
|
118
|
+
type: string;
|
|
119
|
+
description: string;
|
|
120
|
+
score: number;
|
|
121
|
+
id: string;
|
|
122
|
+
}[];
|
|
123
|
+
error?: string;
|
|
124
|
+
}
|
|
125
|
+
/** Vector-seed → neighborhood → triplet ranking (cognee's brute-force triplet
|
|
126
|
+
* search, scaled down). Seed scores already carry the Phase 1 feedback blend. */
|
|
127
|
+
export declare function kgSearch(options: {
|
|
128
|
+
query: string;
|
|
129
|
+
dbPath?: string;
|
|
130
|
+
limit?: number;
|
|
131
|
+
nodeSet?: string;
|
|
132
|
+
}): Promise<KgSearchResult>;
|
|
133
|
+
export declare function kgGlossary(options?: {
|
|
134
|
+
dbPath?: string;
|
|
135
|
+
limit?: number;
|
|
136
|
+
}): Promise<string[]>;
|
|
137
|
+
/** Delete every node/edge/rule whose ONLY origin is `originRef`. Elements with
|
|
138
|
+
* other origins survive (shared knowledge isn't destroyed by one bad run);
|
|
139
|
+
* their origin lists retain the ref — acceptable residue.
|
|
140
|
+
* // monolean: no origin-list rewrite — needs an update-by-id bridge API */
|
|
141
|
+
export declare function kgRollback(options: {
|
|
142
|
+
originRef: string;
|
|
143
|
+
dbPath?: string;
|
|
144
|
+
}): Promise<{
|
|
145
|
+
success: boolean;
|
|
146
|
+
deleted: number;
|
|
147
|
+
retained: number;
|
|
148
|
+
error?: string;
|
|
149
|
+
}>;
|
|
150
|
+
export interface ConsolidationCandidate {
|
|
151
|
+
name: string;
|
|
152
|
+
type: string;
|
|
153
|
+
description: string;
|
|
154
|
+
edgeCount: number;
|
|
155
|
+
/** Neighborhood facts to merge into one canonical description. */
|
|
156
|
+
neighborhood: string[];
|
|
157
|
+
}
|
|
158
|
+
/** Entities whose descriptions are stale relative to their connectivity —
|
|
159
|
+
* the LLM half runs in the LIVE agent: it rewrites each candidate's
|
|
160
|
+
* description from the neighborhood facts and resubmits via memory_kg_ingest
|
|
161
|
+
* (longer descriptions win on merge). No LLM here (fully local constraint). */
|
|
162
|
+
export declare function kgConsolidateCandidates(options?: {
|
|
163
|
+
dbPath?: string;
|
|
164
|
+
/** Minimum edges for a node to qualify (default 3). */
|
|
165
|
+
minEdges?: number;
|
|
166
|
+
limit?: number;
|
|
167
|
+
}): Promise<ConsolidationCandidate[]>;
|
|
168
|
+
export declare function kgStats(options?: {
|
|
169
|
+
dbPath?: string;
|
|
170
|
+
}): Promise<{
|
|
171
|
+
nodes: number;
|
|
172
|
+
edges: number;
|
|
173
|
+
rules: number;
|
|
174
|
+
}>;
|
|
175
|
+
/** Regex extraction for when no LLM is in the loop (memory-palace lineage):
|
|
176
|
+
* proper-noun phrases and `code identifiers` become entities, sentence
|
|
177
|
+
* co-occurrence becomes relates_to edges. Lower-trust by design — real
|
|
178
|
+
* entity/relation quality comes from the LLM path (memory_kg_ingest called
|
|
179
|
+
* by the live agent, or the org coordinator's org_learn tool). */
|
|
180
|
+
export declare function heuristicExtract(text: string, opts?: {
|
|
181
|
+
sourceName?: string;
|
|
182
|
+
}): {
|
|
183
|
+
nodes: KgNodeInput[];
|
|
184
|
+
edges: KgEdgeInput[];
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=memory-kg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-kg.d.ts","sourceRoot":"","sources":["../../../src/memory/memory-kg.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Knowledge Graph — entities, relations, and rules distilled from
|
|
3
|
+
* agent sessions and org runs (cognee-concept port, Phase 2 of
|
|
4
|
+
* docs/mastermind/2026-07-19-cognee-port-plan.md).
|
|
5
|
+
*
|
|
6
|
+
* Storage rides store A (memory-bridge) rather than a dedicated SQLite DB:
|
|
7
|
+
* nodes live in namespace `kg:nodes`, edges in `kg:edges`, distilled rules
|
|
8
|
+
* additionally in `rules` (so existing knowledge/injection surfaces find them).
|
|
9
|
+
* That buys embeddings, upsert, sql.js fallback, and the Phase 1
|
|
10
|
+
* feedback/frequency weighting for free — KG node ranking improves with use
|
|
11
|
+
* automatically.
|
|
12
|
+
*
|
|
13
|
+
* Identity is deterministic and NAME-ONLY (cognee's Entity.identity_fields):
|
|
14
|
+
* the entry KEY is `n:<normalized-name>`, so the same entity extracted from
|
|
15
|
+
* any session merges idempotently via upsert regardless of assigned type.
|
|
16
|
+
* Every write carries `origin_refs` so a bad ingest can be rolled back per
|
|
17
|
+
* run/session.
|
|
18
|
+
*
|
|
19
|
+
* // monolean: graph traversal is in-process over a full kg:edges list —
|
|
20
|
+
* // fine to ~10k edges; upgrade path is a real SQLite edges table with
|
|
21
|
+
* // indexed src/dst columns if orgs outgrow that.
|
|
22
|
+
*
|
|
23
|
+
* @module v1/cli/memory/memory-kg
|
|
24
|
+
*/
|
|
25
|
+
import { bridgeStoreEntry, bridgeSearchEntries, bridgeListEntries, bridgeGetEntry, bridgeDeleteEntry, } from './memory-bridge.js';
|
|
26
|
+
export const KG_NODES_NS = 'kg:nodes';
|
|
27
|
+
export const KG_EDGES_NS = 'kg:edges';
|
|
28
|
+
export const RULES_NS = 'rules';
|
|
29
|
+
const MAX_NAME_LEN = 200;
|
|
30
|
+
const MAX_DESC_LEN = 2000;
|
|
31
|
+
const MAX_LIST = 10_000;
|
|
32
|
+
/** cognee DataPoint normalization: lowercase, spaces→_, strip apostrophes. */
|
|
33
|
+
export function normalizeName(name) {
|
|
34
|
+
return String(name).trim().toLowerCase().replace(/['’]/g, '').replace(/\s+/g, '_').slice(0, MAX_NAME_LEN);
|
|
35
|
+
}
|
|
36
|
+
/** Identity is NAME-ONLY (cognee's Entity.identity_fields = ["name"]) — type
|
|
37
|
+
* lives in metadata. Including type in the key forked the same entity when
|
|
38
|
+
* the LLM said "Module" and the heuristic said "entity". */
|
|
39
|
+
export function nodeKey(_type, name) {
|
|
40
|
+
return `n:${normalizeName(name)}`;
|
|
41
|
+
}
|
|
42
|
+
function edgeKey(srcKey, relation, dstKey) {
|
|
43
|
+
return `e:${srcKey}|${normalizeName(relation)}|${dstKey}`;
|
|
44
|
+
}
|
|
45
|
+
// ── Ingest ──────────────────────────────────────────────────────────
|
|
46
|
+
/** Idempotently merge extracted nodes/edges into the KG. Same-name entities
|
|
47
|
+
* collapse onto one node (deterministic key + upsert); origin_refs accumulate
|
|
48
|
+
* so rollback can undo a single run's contribution. */
|
|
49
|
+
export async function kgIngest(options) {
|
|
50
|
+
const { originRef, dbPath } = options;
|
|
51
|
+
let nodesAdded = 0, nodesMerged = 0, edgesAdded = 0, edgesMerged = 0;
|
|
52
|
+
try {
|
|
53
|
+
const keyByName = new Map();
|
|
54
|
+
for (const n of (options.nodes ?? []).slice(0, 500)) {
|
|
55
|
+
if (!n?.name?.trim())
|
|
56
|
+
continue;
|
|
57
|
+
const type = n.type?.trim() || 'entity';
|
|
58
|
+
const key = nodeKey(type, n.name);
|
|
59
|
+
keyByName.set(normalizeName(n.name), key);
|
|
60
|
+
const desc = (n.description ?? '').slice(0, MAX_DESC_LEN);
|
|
61
|
+
const existing = await bridgeGetEntry({ key, namespace: KG_NODES_NS, dbPath });
|
|
62
|
+
if (existing?.found && existing.entry) {
|
|
63
|
+
const md = existing.entry.metadata;
|
|
64
|
+
const origins = Array.isArray(md.origin_refs) ? md.origin_refs : [];
|
|
65
|
+
if (!origins.includes(originRef))
|
|
66
|
+
origins.push(originRef);
|
|
67
|
+
// Prefer the richer description; never let a terse re-extraction erase detail.
|
|
68
|
+
const prevDesc = typeof md.description === 'string' ? md.description : '';
|
|
69
|
+
const bestDesc = desc.length > prevDesc.length ? desc : prevDesc;
|
|
70
|
+
// Keep the most specific type: a generic heuristic 'entity' never
|
|
71
|
+
// overwrites an LLM-assigned type.
|
|
72
|
+
const prevType = typeof md.type === 'string' ? md.type : 'entity';
|
|
73
|
+
const bestType = prevType.toLowerCase() !== 'entity' ? prevType : type;
|
|
74
|
+
await bridgeStoreEntry({
|
|
75
|
+
key,
|
|
76
|
+
value: `${n.name} — ${bestDesc || bestType}`,
|
|
77
|
+
namespace: KG_NODES_NS,
|
|
78
|
+
dbPath,
|
|
79
|
+
upsert: true,
|
|
80
|
+
tags: ['kg', normalizeName(bestType), ...(n.nodeSet ? [normalizeName(n.nodeSet)] : [])],
|
|
81
|
+
metadata: {
|
|
82
|
+
...md,
|
|
83
|
+
kg: 'node', type: bestType, name: n.name, description: bestDesc,
|
|
84
|
+
node_set: n.nodeSet ?? md.node_set ?? null,
|
|
85
|
+
origin_refs: origins.slice(-100),
|
|
86
|
+
version: (typeof md.version === 'number' ? md.version : 1) + 1,
|
|
87
|
+
valid_from: md.valid_from ?? Date.now(),
|
|
88
|
+
valid_to: null,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
nodesMerged++;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
await bridgeStoreEntry({
|
|
95
|
+
key,
|
|
96
|
+
value: `${n.name} — ${desc || type}`,
|
|
97
|
+
namespace: KG_NODES_NS,
|
|
98
|
+
dbPath,
|
|
99
|
+
upsert: true,
|
|
100
|
+
tags: ['kg', normalizeName(type), ...(n.nodeSet ? [normalizeName(n.nodeSet)] : [])],
|
|
101
|
+
metadata: {
|
|
102
|
+
kg: 'node', type, name: n.name, description: desc,
|
|
103
|
+
node_set: n.nodeSet ?? null,
|
|
104
|
+
origin_refs: [originRef],
|
|
105
|
+
version: 1,
|
|
106
|
+
valid_from: Date.now(),
|
|
107
|
+
valid_to: null,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
nodesAdded++;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const e of (options.edges ?? []).slice(0, 1000)) {
|
|
114
|
+
if (!e?.source?.trim() || !e?.target?.trim() || !e?.relation?.trim())
|
|
115
|
+
continue;
|
|
116
|
+
const srcKey = keyByName.get(normalizeName(e.source)) ?? nodeKey(e.sourceType ?? 'entity', e.source);
|
|
117
|
+
const dstKey = keyByName.get(normalizeName(e.target)) ?? nodeKey(e.targetType ?? 'entity', e.target);
|
|
118
|
+
const key = edgeKey(srcKey, e.relation, dstKey);
|
|
119
|
+
const desc = (e.description ?? '').slice(0, MAX_DESC_LEN);
|
|
120
|
+
const existing = await bridgeGetEntry({ key, namespace: KG_EDGES_NS, dbPath });
|
|
121
|
+
if (existing?.found && existing.entry) {
|
|
122
|
+
const md = existing.entry.metadata;
|
|
123
|
+
const origins = Array.isArray(md.origin_refs) ? md.origin_refs : [];
|
|
124
|
+
if (!origins.includes(originRef))
|
|
125
|
+
origins.push(originRef);
|
|
126
|
+
await bridgeStoreEntry({
|
|
127
|
+
key,
|
|
128
|
+
value: desc || `${e.source} ${e.relation} ${e.target}`,
|
|
129
|
+
namespace: KG_EDGES_NS,
|
|
130
|
+
dbPath,
|
|
131
|
+
upsert: true,
|
|
132
|
+
generateEmbeddingFlag: false,
|
|
133
|
+
tags: ['kg', normalizeName(e.relation)],
|
|
134
|
+
metadata: { ...md, origin_refs: origins.slice(-100) },
|
|
135
|
+
});
|
|
136
|
+
edgesMerged++;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
await bridgeStoreEntry({
|
|
140
|
+
key,
|
|
141
|
+
value: desc || `${e.source} ${e.relation} ${e.target}`,
|
|
142
|
+
namespace: KG_EDGES_NS,
|
|
143
|
+
dbPath,
|
|
144
|
+
upsert: true,
|
|
145
|
+
generateEmbeddingFlag: false,
|
|
146
|
+
tags: ['kg', normalizeName(e.relation)],
|
|
147
|
+
metadata: {
|
|
148
|
+
kg: 'edge', src: srcKey, dst: dstKey,
|
|
149
|
+
relation: normalizeName(e.relation),
|
|
150
|
+
source_name: e.source, target_name: e.target,
|
|
151
|
+
description: desc,
|
|
152
|
+
origin_refs: [originRef],
|
|
153
|
+
valid_from: Date.now(),
|
|
154
|
+
valid_to: null,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
edgesAdded++;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { success: true, nodesAdded, nodesMerged, edgesAdded, edgesMerged };
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
return {
|
|
164
|
+
success: false, nodesAdded, nodesMerged, edgesAdded, edgesMerged,
|
|
165
|
+
error: err instanceof Error ? err.message : String(err),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Stage-2 of cognee's curator/writer distillation: the CALLER (an LLM agent)
|
|
170
|
+
* proposes candidate rules; this accepts each unless a semantically
|
|
171
|
+
* near-identical rule exists (embedding dedup — deterministic keys can't
|
|
172
|
+
* collapse paraphrases). Accepted rules are stored both as KG nodes
|
|
173
|
+
* (node_set=rules) and as plain `rules`-namespace entries so the existing
|
|
174
|
+
* injection/search surfaces pick them up with zero new plumbing. */
|
|
175
|
+
export async function kgIngestRules(options) {
|
|
176
|
+
const verdicts = [];
|
|
177
|
+
const threshold = options.dedupThreshold ?? 0.78;
|
|
178
|
+
let accepted = 0;
|
|
179
|
+
try {
|
|
180
|
+
for (const r of (options.rules ?? []).slice(0, 50)) {
|
|
181
|
+
const rule = r?.rule?.trim();
|
|
182
|
+
if (!rule || rule.length < 8) {
|
|
183
|
+
verdicts.push({ rule: r?.rule ?? '', verdict: 'invalid' });
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const similar = await bridgeSearchEntries({
|
|
187
|
+
query: rule, namespace: RULES_NS, limit: 1, threshold, dbPath: options.dbPath,
|
|
188
|
+
});
|
|
189
|
+
const top = similar?.results?.[0];
|
|
190
|
+
// Dedup on the RAW cosine (from provenance), not the blended rank score —
|
|
191
|
+
// the Phase 1 feedback blend shifts scores and would corrupt the gate.
|
|
192
|
+
const rawScore = top?.provenance?.startsWith('semantic:')
|
|
193
|
+
? parseFloat(top.provenance.slice('semantic:'.length)) : top?.score ?? 0;
|
|
194
|
+
if (top && rawScore >= threshold) {
|
|
195
|
+
verdicts.push({ rule, verdict: 'already_known', similarTo: top.key });
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const key = `rule:${normalizeName(rule).slice(0, 120)}`;
|
|
199
|
+
await bridgeStoreEntry({
|
|
200
|
+
key, value: rule + (r.context ? `\n(context: ${r.context.slice(0, 500)})` : ''),
|
|
201
|
+
namespace: RULES_NS, dbPath: options.dbPath, upsert: true,
|
|
202
|
+
tags: ['rule'],
|
|
203
|
+
metadata: { origin_refs: [options.originRef], derived_from: options.originRef },
|
|
204
|
+
});
|
|
205
|
+
await kgIngest({
|
|
206
|
+
nodes: [{ name: rule.slice(0, MAX_NAME_LEN), type: 'Rule', description: rule, nodeSet: 'rules' }],
|
|
207
|
+
originRef: options.originRef,
|
|
208
|
+
dbPath: options.dbPath,
|
|
209
|
+
});
|
|
210
|
+
verdicts.push({ rule, verdict: 'accepted' });
|
|
211
|
+
accepted++;
|
|
212
|
+
}
|
|
213
|
+
return { success: true, verdicts, accepted };
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
return { success: false, verdicts, accepted, error: err instanceof Error ? err.message : String(err) };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** List stored rules (for injection or review). */
|
|
220
|
+
export async function kgListRules(options) {
|
|
221
|
+
const res = await bridgeListEntries({ namespace: RULES_NS, limit: options?.limit ?? 50, dbPath: options?.dbPath });
|
|
222
|
+
return (res?.entries ?? []).map(e => ({ rule: e.content, key: e.key }));
|
|
223
|
+
}
|
|
224
|
+
/** Vector-seed → neighborhood → triplet ranking (cognee's brute-force triplet
|
|
225
|
+
* search, scaled down). Seed scores already carry the Phase 1 feedback blend. */
|
|
226
|
+
export async function kgSearch(options) {
|
|
227
|
+
try {
|
|
228
|
+
const limit = options.limit ?? 8;
|
|
229
|
+
const seedsRes = await bridgeSearchEntries({
|
|
230
|
+
query: options.query, namespace: KG_NODES_NS, limit: 15, threshold: 0.25, dbPath: options.dbPath,
|
|
231
|
+
});
|
|
232
|
+
let seedResults = seedsRes?.results ?? [];
|
|
233
|
+
if (options.nodeSet) {
|
|
234
|
+
const ns = normalizeName(options.nodeSet);
|
|
235
|
+
seedResults = seedResults.filter(r => (r.tags ?? []).includes(ns));
|
|
236
|
+
}
|
|
237
|
+
if (!seedResults.length)
|
|
238
|
+
return { success: true, context: '', triplets: [], seeds: [] };
|
|
239
|
+
const seedScore = new Map();
|
|
240
|
+
for (const s of seedResults)
|
|
241
|
+
seedScore.set(s.key, s.score);
|
|
242
|
+
// Full edge scan (see monolean note in module header).
|
|
243
|
+
const edgesRes = await bridgeListEntries({ namespace: KG_EDGES_NS, limit: MAX_LIST, dbPath: options.dbPath });
|
|
244
|
+
const edges = (edgesRes?.entries ?? []).filter(e => {
|
|
245
|
+
const md = e.metadata;
|
|
246
|
+
return md?.kg === 'edge' && md.valid_to == null;
|
|
247
|
+
});
|
|
248
|
+
const triplets = edges
|
|
249
|
+
.map(e => {
|
|
250
|
+
const md = e.metadata;
|
|
251
|
+
const src = String(md.src ?? '');
|
|
252
|
+
const dst = String(md.dst ?? '');
|
|
253
|
+
const sSrc = seedScore.get(src) ?? 0;
|
|
254
|
+
const sDst = seedScore.get(dst) ?? 0;
|
|
255
|
+
if (sSrc === 0 && sDst === 0)
|
|
256
|
+
return null;
|
|
257
|
+
// Both endpoints seeded beats one; the unseeded endpoint contributes a
|
|
258
|
+
// neutral 0.35 so bridging edges from a strong seed still surface.
|
|
259
|
+
const score = (Math.max(sSrc, 0.35) + Math.max(sDst, 0.35)) / 2 + (sSrc > 0 && sDst > 0 ? 0.1 : 0);
|
|
260
|
+
return {
|
|
261
|
+
source: String(md.source_name ?? src),
|
|
262
|
+
relation: String(md.relation ?? 'related_to'),
|
|
263
|
+
target: String(md.target_name ?? dst),
|
|
264
|
+
fact: e.content,
|
|
265
|
+
score,
|
|
266
|
+
};
|
|
267
|
+
})
|
|
268
|
+
.filter((t) => !!t)
|
|
269
|
+
.sort((a, b) => b.score - a.score)
|
|
270
|
+
.slice(0, limit);
|
|
271
|
+
const seeds = seedResults.slice(0, limit).map(s => {
|
|
272
|
+
// metadata is not in search results; parse from rendered content "name — description"
|
|
273
|
+
const dash = s.content.indexOf(' — ');
|
|
274
|
+
return {
|
|
275
|
+
name: dash > 0 ? s.content.slice(0, dash) : s.key,
|
|
276
|
+
type: s.key.split(':')[1] ?? 'entity',
|
|
277
|
+
description: dash > 0 ? s.content.slice(dash + 3) : s.content,
|
|
278
|
+
score: s.score,
|
|
279
|
+
id: s.id,
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
const context = [
|
|
283
|
+
...triplets.map(t => `${t.source} —${t.relation}→ ${t.target}${t.fact && t.fact !== `${t.source} ${t.relation} ${t.target}` ? ` (${t.fact})` : ''}`),
|
|
284
|
+
...(triplets.length ? [] : seeds.map(s => `${s.name}: ${s.description}`)),
|
|
285
|
+
].join('\n');
|
|
286
|
+
return { success: true, context, triplets, seeds };
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
return { success: false, context: '', triplets: [], seeds: [], error: err instanceof Error ? err.message : String(err) };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// ── Glossary (anti-duplicate-entity injection for extraction prompts) ──
|
|
293
|
+
export async function kgGlossary(options) {
|
|
294
|
+
const res = await bridgeListEntries({ namespace: KG_NODES_NS, limit: MAX_LIST, dbPath: options?.dbPath });
|
|
295
|
+
const nodes = (res?.entries ?? [])
|
|
296
|
+
// Glossary is for ENTITY name reuse — rule prose and extraction-source
|
|
297
|
+
// Session nodes would drown it.
|
|
298
|
+
.filter(e => {
|
|
299
|
+
const md = e.metadata;
|
|
300
|
+
const t = String(md?.type ?? '').toLowerCase();
|
|
301
|
+
return md?.node_set !== 'rules' && t !== 'rule' && t !== 'session';
|
|
302
|
+
})
|
|
303
|
+
.map(e => {
|
|
304
|
+
const md = e.metadata;
|
|
305
|
+
const fw = typeof md.feedback_weight === 'number' ? md.feedback_weight : 0.5;
|
|
306
|
+
const freq = typeof md.frequency_weight === 'number' ? md.frequency_weight : 0;
|
|
307
|
+
const version = typeof md.version === 'number' ? md.version : 1;
|
|
308
|
+
return { name: String(md.name ?? e.key), rank: version + freq + fw };
|
|
309
|
+
})
|
|
310
|
+
.sort((a, b) => b.rank - a.rank);
|
|
311
|
+
const seen = new Set();
|
|
312
|
+
const out = [];
|
|
313
|
+
for (const n of nodes) {
|
|
314
|
+
const norm = normalizeName(n.name);
|
|
315
|
+
if (seen.has(norm))
|
|
316
|
+
continue;
|
|
317
|
+
seen.add(norm);
|
|
318
|
+
out.push(n.name);
|
|
319
|
+
if (out.length >= (options?.limit ?? 40))
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
return out;
|
|
323
|
+
}
|
|
324
|
+
// ── Rollback (per-origin bad-ingest recovery) ───────────────────────
|
|
325
|
+
/** Delete every node/edge/rule whose ONLY origin is `originRef`. Elements with
|
|
326
|
+
* other origins survive (shared knowledge isn't destroyed by one bad run);
|
|
327
|
+
* their origin lists retain the ref — acceptable residue.
|
|
328
|
+
* // monolean: no origin-list rewrite — needs an update-by-id bridge API */
|
|
329
|
+
export async function kgRollback(options) {
|
|
330
|
+
let deleted = 0, retained = 0;
|
|
331
|
+
try {
|
|
332
|
+
for (const ns of [KG_NODES_NS, KG_EDGES_NS, RULES_NS]) {
|
|
333
|
+
const res = await bridgeListEntries({ namespace: ns, limit: MAX_LIST, dbPath: options.dbPath });
|
|
334
|
+
for (const e of res?.entries ?? []) {
|
|
335
|
+
const origins = e.metadata?.origin_refs;
|
|
336
|
+
if (!Array.isArray(origins) || !origins.includes(options.originRef))
|
|
337
|
+
continue;
|
|
338
|
+
if (origins.length <= 1) {
|
|
339
|
+
const del = await bridgeDeleteEntry({ id: e.id, namespace: ns, dbPath: options.dbPath });
|
|
340
|
+
if (del?.deleted)
|
|
341
|
+
deleted++;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
retained++;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return { success: true, deleted, retained };
|
|
349
|
+
}
|
|
350
|
+
catch (err) {
|
|
351
|
+
return { success: false, deleted, retained, error: err instanceof Error ? err.message : String(err) };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/** Entities whose descriptions are stale relative to their connectivity —
|
|
355
|
+
* the LLM half runs in the LIVE agent: it rewrites each candidate's
|
|
356
|
+
* description from the neighborhood facts and resubmits via memory_kg_ingest
|
|
357
|
+
* (longer descriptions win on merge). No LLM here (fully local constraint). */
|
|
358
|
+
export async function kgConsolidateCandidates(options) {
|
|
359
|
+
const minEdges = options?.minEdges ?? 3;
|
|
360
|
+
const [nodesRes, edgesRes] = await Promise.all([
|
|
361
|
+
bridgeListEntries({ namespace: KG_NODES_NS, limit: MAX_LIST, dbPath: options?.dbPath }),
|
|
362
|
+
bridgeListEntries({ namespace: KG_EDGES_NS, limit: MAX_LIST, dbPath: options?.dbPath }),
|
|
363
|
+
]);
|
|
364
|
+
const edgesByNode = new Map();
|
|
365
|
+
for (const e of edgesRes?.entries ?? []) {
|
|
366
|
+
const md = e.metadata;
|
|
367
|
+
for (const end of [String(md.src ?? ''), String(md.dst ?? '')]) {
|
|
368
|
+
if (!end)
|
|
369
|
+
continue;
|
|
370
|
+
const list = edgesByNode.get(end) ?? [];
|
|
371
|
+
list.push(e.content);
|
|
372
|
+
edgesByNode.set(end, list);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return (nodesRes?.entries ?? [])
|
|
376
|
+
.map(n => {
|
|
377
|
+
const md = n.metadata;
|
|
378
|
+
const facts = edgesByNode.get(n.key) ?? [];
|
|
379
|
+
return {
|
|
380
|
+
name: String(md.name ?? n.key),
|
|
381
|
+
type: String(md.type ?? 'entity'),
|
|
382
|
+
description: String(md.description ?? ''),
|
|
383
|
+
edgeCount: facts.length,
|
|
384
|
+
neighborhood: facts.slice(0, 12),
|
|
385
|
+
};
|
|
386
|
+
})
|
|
387
|
+
// Cap the growth target at MAX_DESC_LEN — a very-high-degree node whose
|
|
388
|
+
// description is already at the cap can never "grow out" of candidacy and
|
|
389
|
+
// would otherwise permanently occupy a slot.
|
|
390
|
+
.filter(c => c.edgeCount >= minEdges && c.description.length < Math.min(40 * c.edgeCount, MAX_DESC_LEN))
|
|
391
|
+
.sort((a, b) => b.edgeCount - a.edgeCount)
|
|
392
|
+
.slice(0, options?.limit ?? 10);
|
|
393
|
+
}
|
|
394
|
+
// ── Stats ───────────────────────────────────────────────────────────
|
|
395
|
+
export async function kgStats(options) {
|
|
396
|
+
const [n, e, r] = await Promise.all([
|
|
397
|
+
bridgeListEntries({ namespace: KG_NODES_NS, limit: MAX_LIST, dbPath: options?.dbPath }),
|
|
398
|
+
bridgeListEntries({ namespace: KG_EDGES_NS, limit: MAX_LIST, dbPath: options?.dbPath }),
|
|
399
|
+
bridgeListEntries({ namespace: RULES_NS, limit: MAX_LIST, dbPath: options?.dbPath }),
|
|
400
|
+
]);
|
|
401
|
+
return { nodes: n?.total ?? 0, edges: e?.total ?? 0, rules: r?.total ?? 0 };
|
|
402
|
+
}
|
|
403
|
+
// ── Heuristic extraction (LLM-less fallback) ────────────────────────
|
|
404
|
+
/** Regex extraction for when no LLM is in the loop (memory-palace lineage):
|
|
405
|
+
* proper-noun phrases and `code identifiers` become entities, sentence
|
|
406
|
+
* co-occurrence becomes relates_to edges. Lower-trust by design — real
|
|
407
|
+
* entity/relation quality comes from the LLM path (memory_kg_ingest called
|
|
408
|
+
* by the live agent, or the org coordinator's org_learn tool). */
|
|
409
|
+
export function heuristicExtract(text, opts) {
|
|
410
|
+
const nodes = new Map();
|
|
411
|
+
const edges = [];
|
|
412
|
+
const src = String(text || '').slice(0, 50_000);
|
|
413
|
+
const sentences = src.split(/(?<=[.!?])\s+|\n+/).slice(0, 400);
|
|
414
|
+
const STOPWORDS = new Set(['The', 'This', 'That', 'These', 'Those', 'It', 'A', 'An', 'If', 'When', 'While', 'But', 'And', 'Or', 'For', 'Then', 'Also', 'Not', 'No', 'Yes', 'I', 'We', 'You', 'They', 'He', 'She', 'Run', 'Outcome', 'Assets', 'Goal', 'Org',
|
|
415
|
+
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December',
|
|
416
|
+
'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']);
|
|
417
|
+
for (const sentence of sentences) {
|
|
418
|
+
const found = [];
|
|
419
|
+
// Proper-noun phrases: consecutive Capitalized words (2-40 chars each).
|
|
420
|
+
for (const m of sentence.matchAll(/\b([A-Z][a-zA-Z0-9_-]{1,40}(?:\s+[A-Z][a-zA-Z0-9_-]{1,40}){0,3})\b/g)) {
|
|
421
|
+
const phrase = m[1];
|
|
422
|
+
if (STOPWORDS.has(phrase))
|
|
423
|
+
continue;
|
|
424
|
+
found.push(phrase);
|
|
425
|
+
}
|
|
426
|
+
// Code identifiers in backticks or dotted/slashed paths.
|
|
427
|
+
for (const m of sentence.matchAll(/`([^`\n]{2,80})`/g))
|
|
428
|
+
found.push(m[1]);
|
|
429
|
+
const uniq = [...new Set(found)].slice(0, 8);
|
|
430
|
+
for (const name of uniq) {
|
|
431
|
+
if (!nodes.has(normalizeName(name))) {
|
|
432
|
+
nodes.set(normalizeName(name), { name, type: /[./`(]/.test(name) ? 'CodeElement' : 'Entity', description: sentence.trim().slice(0, 300) });
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// Co-occurrence edges within a sentence (first mention chains to the rest).
|
|
436
|
+
for (let i = 1; i < uniq.length && i < 4; i++) {
|
|
437
|
+
edges.push({ source: uniq[0], target: uniq[i], relation: 'relates_to', description: sentence.trim().slice(0, 300) });
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (opts?.sourceName) {
|
|
441
|
+
const srcNode = { name: opts.sourceName, type: 'Session', description: 'extraction source' };
|
|
442
|
+
nodes.set(normalizeName(opts.sourceName), srcNode);
|
|
443
|
+
for (const n of [...nodes.values()].slice(0, 30)) {
|
|
444
|
+
if (n.name !== opts.sourceName)
|
|
445
|
+
edges.push({ source: n.name, target: opts.sourceName, relation: 'mentioned_in', sourceType: n.type, targetType: 'Session' });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return { nodes: [...nodes.values()].slice(0, 100), edges: edges.slice(0, 200) };
|
|
449
|
+
}
|
|
450
|
+
//# sourceMappingURL=memory-kg.js.map
|