squish-memory 1.0.2 → 1.1.5
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/.env.example +130 -0
- package/CHANGELOG.md +55 -0
- package/README.md +150 -287
- package/config/hooks/claude-code-hooks.json +39 -0
- package/config/hooks/cursor-hooks.json +30 -0
- package/config/hooks/opencode-hooks.json +30 -0
- package/config/hooks/windsurf-hooks.json +30 -0
- package/config/mcp-mode-semantics.json +23 -21
- package/config/plugin-manifest.json +101 -152
- package/{plugin.json → config/plugin.json} +2 -2
- package/config/settings.json +52 -51
- package/{commands → core/commands}/init.md +39 -39
- package/dist/config.d.ts +28 -4
- package/dist/config.js +97 -29
- package/dist/core/adapters/config/claude-code.d.ts +45 -0
- package/dist/core/adapters/config/claude-code.js +113 -0
- package/dist/core/adapters/config/cursor.d.ts +26 -0
- package/dist/core/adapters/config/cursor.js +74 -0
- package/dist/core/adapters/config/opencode.d.ts +23 -0
- package/dist/core/adapters/config/opencode.js +73 -0
- package/dist/core/adapters/config/windsurf.d.ts +26 -0
- package/dist/core/adapters/config/windsurf.js +74 -0
- package/dist/core/adapters/index.d.ts +45 -0
- package/dist/core/adapters/index.js +84 -0
- package/dist/core/adapters/scripts/install-adapter.d.ts +19 -0
- package/dist/core/adapters/scripts/install-adapter.js +149 -0
- package/dist/core/adapters/timeline.d.ts +23 -0
- package/dist/core/adapters/timeline.js +88 -0
- package/dist/core/adapters/types.d.ts +157 -0
- package/dist/core/adapters/types.js +50 -0
- package/dist/{algorithms → core/algorithms}/analytics/token-estimator.d.ts +1 -1
- package/dist/{algorithms → core/algorithms}/analytics/token-estimator.js +3 -3
- package/dist/{algorithms → core/algorithms}/detection/semantic-ranker.d.ts +1 -1
- package/dist/{algorithms → core/algorithms}/detection/semantic-ranker.js +1 -1
- package/dist/{algorithms → core/algorithms}/detection/two-stage-detector.d.ts +1 -1
- package/dist/{algorithms → core/algorithms}/detection/two-stage-detector.js +7 -10
- package/dist/{algorithms → core/algorithms}/handlers/approve-merge.js +4 -4
- package/dist/{algorithms → core/algorithms}/handlers/detect-duplicates.js +3 -3
- package/dist/{algorithms → core/algorithms}/handlers/get-stats.js +3 -3
- package/dist/{algorithms → core/algorithms}/handlers/list-proposals.js +3 -3
- package/dist/{algorithms → core/algorithms}/handlers/preview-merge.js +3 -3
- package/dist/{algorithms → core/algorithms}/handlers/reject-merge.js +3 -3
- package/dist/{algorithms → core/algorithms}/handlers/reverse-merge.js +3 -3
- package/dist/core/algorithms/index.d.ts +21 -0
- package/dist/core/algorithms/index.js +26 -0
- package/dist/core/algorithms/operations/cache-maintenance.d.ts +12 -0
- package/dist/core/algorithms/operations/cache-maintenance.js +157 -0
- package/dist/{algorithms → core/algorithms}/safety/safety-checks.d.ts +1 -1
- package/dist/{algorithms → core/algorithms}/strategies/merge-strategies.d.ts +19 -1
- package/dist/{algorithms → core/algorithms}/strategies/merge-strategies.js +74 -123
- package/dist/core/algorithms/types.d.ts +133 -0
- package/dist/core/algorithms/types.js +5 -0
- package/dist/core/associations.d.ts +1 -2
- package/dist/core/associations.js +1 -2
- package/dist/core/autosave.d.ts +19 -0
- package/dist/core/autosave.js +16 -0
- package/dist/{commands → core/commands}/managed-sync.js +5 -5
- package/dist/core/commands/mcp-server.js +739 -0
- package/dist/core/context/agent-context.d.ts +106 -0
- package/dist/core/context/agent-context.js +274 -0
- package/dist/core/{context-paging.d.ts → context/context-paging.d.ts} +2 -12
- package/dist/core/{context-paging.js → context/context-paging.js} +19 -39
- package/dist/core/context/context-window.d.ts +40 -0
- package/dist/core/context/context-window.js +177 -0
- package/dist/core/context/context.js +22 -0
- package/dist/core/embeddings.d.ts +1 -1
- package/dist/core/embeddings.js +54 -2
- package/dist/core/error-handling.d.ts +63 -0
- package/dist/core/error-handling.js +173 -0
- package/dist/core/external-folder/index.d.ts +102 -0
- package/dist/core/external-folder/index.js +294 -0
- package/dist/core/hooks/agent-hooks.d.ts +74 -0
- package/dist/core/hooks/agent-hooks.js +244 -0
- package/dist/core/hooks/auto-tagger.d.ts +19 -0
- package/dist/core/hooks/auto-tagger.js +155 -0
- package/dist/core/hooks/capture-filter.d.ts +41 -0
- package/dist/core/hooks/capture-filter.js +128 -0
- package/dist/core/index.d.ts +6 -6
- package/dist/core/index.js +6 -6
- package/dist/core/{agent-memory.js → ingestion/agent-memory.js} +5 -7
- package/dist/core/{core-memory.js → ingestion/core-memory.js} +4 -4
- package/dist/core/ingestion/learnings.d.ts +57 -0
- package/dist/core/ingestion/learnings.js +202 -0
- package/dist/core/lib/db-client.d.ts +114 -0
- package/dist/core/lib/db-client.js +130 -0
- package/dist/core/lib/schemas.d.ts +129 -0
- package/dist/core/lib/schemas.js +87 -0
- package/dist/core/{utils.d.ts → lib/utils.d.ts} +1 -0
- package/dist/core/{utils.js → lib/utils.js} +31 -15
- package/dist/core/lib/validation.d.ts +38 -0
- package/dist/core/lib/validation.js +151 -0
- package/dist/core/lifecycle.d.ts +7 -0
- package/dist/core/lifecycle.js +140 -20
- package/dist/core/local-embeddings.d.ts +6 -1
- package/dist/core/local-embeddings.js +6 -15
- package/dist/core/logger.js +7 -1
- package/dist/core/mcp/tools.js +35 -3
- package/dist/core/memory/categorizer.js +1 -0
- package/dist/core/memory/conflict-detector.js +1 -1
- package/dist/core/memory/consolidation.d.ts +1 -10
- package/dist/core/memory/consolidation.js +2 -11
- package/dist/core/memory/context-collector.js +1 -1
- package/dist/core/memory/edit-workflow.js +1 -1
- package/dist/core/memory/entity-resolver.js +7 -7
- package/dist/core/memory/fact-extractor.js +12 -12
- package/dist/core/memory/feedback-tracker.js +1 -1
- package/dist/core/memory/hooks.d.ts +88 -0
- package/dist/core/memory/hooks.js +174 -0
- package/dist/core/memory/hybrid-retrieval.js +2 -2
- package/dist/core/memory/hybrid-search.d.ts +1 -6
- package/dist/core/memory/hybrid-search.js +70 -84
- package/dist/core/memory/importance.d.ts +8 -13
- package/dist/core/memory/importance.js +47 -74
- package/dist/core/memory/loader.d.ts +31 -0
- package/dist/core/memory/loader.js +141 -0
- package/dist/core/memory/markdown/markdown-storage.d.ts +72 -0
- package/dist/core/memory/markdown/markdown-storage.js +243 -0
- package/dist/core/memory/memories.d.ts +12 -4
- package/dist/core/memory/memories.js +192 -180
- package/dist/core/memory/memory-lifecycle.d.ts +8 -0
- package/dist/core/memory/memory-lifecycle.js +55 -0
- package/dist/core/memory/migrate.d.ts +21 -0
- package/dist/core/memory/migrate.js +134 -0
- package/dist/core/memory/normalization.d.ts +22 -0
- package/dist/core/memory/normalization.js +26 -0
- package/dist/core/memory/progressive-disclosure.js +1 -1
- package/dist/core/memory/query-rewriter.js +9 -9
- package/dist/core/memory/serialization.d.ts +4 -0
- package/dist/core/memory/serialization.js +49 -0
- package/dist/core/memory/stats.d.ts +5 -0
- package/dist/core/memory/stats.js +63 -12
- package/dist/core/memory/temporal-facts.js +21 -0
- package/dist/core/memory/write-gate.js +1 -1
- package/dist/core/obsidian-vault.d.ts +30 -0
- package/dist/core/obsidian-vault.js +94 -0
- package/dist/core/places/index.d.ts +14 -0
- package/dist/core/places/index.js +14 -0
- package/dist/core/places/memory-places.d.ts +68 -0
- package/dist/core/places/memory-places.js +261 -0
- package/dist/core/places/places.d.ts +88 -0
- package/dist/core/places/places.js +314 -0
- package/dist/core/places/rules.d.ts +74 -0
- package/dist/core/places/rules.js +240 -0
- package/dist/core/places/walking.d.ts +56 -0
- package/dist/core/places/walking.js +121 -0
- package/dist/core/projects.d.ts +5 -0
- package/dist/core/projects.js +39 -18
- package/dist/core/responses.d.ts +96 -0
- package/dist/core/responses.js +122 -0
- package/dist/core/scheduler/cron-scheduler.js +29 -7
- package/dist/core/scheduler/index.d.ts +1 -1
- package/dist/core/scheduler/index.js +1 -1
- package/dist/core/scheduler/job-runner.js +1 -1
- package/dist/core/search/conversations.js +40 -42
- package/dist/core/search/entities.js +6 -9
- package/dist/core/search/graph-boost.d.ts +7 -0
- package/dist/core/search/graph-boost.js +23 -0
- package/dist/core/search/qmd-search.js +4 -4
- package/dist/core/security/encrypt.d.ts +6 -0
- package/dist/core/security/encrypt.js +47 -0
- package/dist/core/{governance.d.ts → security/governance.d.ts} +6 -1
- package/dist/core/security/governance.js +79 -0
- package/dist/core/session/auto-load.js +6 -6
- package/dist/core/session/index.d.ts +1 -1
- package/dist/core/session/index.js +1 -1
- package/dist/core/session/self-iteration-job.d.ts +20 -0
- package/dist/core/session/self-iteration-job.js +282 -0
- package/dist/core/session/session-hooks.d.ts +18 -0
- package/dist/core/session/session-hooks.js +58 -0
- package/dist/core/session-hooks/self-iteration-job.js +35 -35
- package/dist/core/{cache.js → storage/cache.js} +2 -2
- package/dist/core/sync/qmd-sync.d.ts +1 -13
- package/dist/core/sync/qmd-sync.js +1 -13
- package/dist/core/toon.d.ts +43 -0
- package/dist/core/toon.js +160 -0
- package/dist/core/utils/memory-operations.js +1 -1
- package/dist/core/utils/vector-operations.d.ts +71 -0
- package/dist/core/utils/vector-operations.js +129 -0
- package/dist/db/adapter.d.ts +3 -3
- package/dist/db/adapter.js +99 -88
- package/dist/db/bootstrap.js +820 -522
- package/dist/{drizzle → db/drizzle}/schema-sqlite.d.ts +74 -25
- package/dist/{drizzle → db/drizzle}/schema-sqlite.js +91 -24
- package/dist/{drizzle → db/drizzle}/schema.d.ts +79 -32
- package/dist/{drizzle → db/drizzle}/schema.js +106 -35
- package/dist/db/drizzle.config.d.ts +3 -0
- package/dist/db/drizzle.config.js +12 -0
- package/dist/db/index.d.ts +1 -5
- package/dist/db/index.js +51 -8
- package/dist/db/neon.d.ts +8 -0
- package/dist/db/neon.js +20 -0
- package/dist/db/schema/index.d.ts +40 -0
- package/dist/db/schema/index.js +105 -0
- package/dist/db/schema/tables/context-sessions.d.ts +9 -0
- package/dist/db/schema/tables/context-sessions.js +37 -0
- package/dist/db/schema/tables/conversations.d.ts +9 -0
- package/dist/db/schema/tables/conversations.js +47 -0
- package/dist/db/schema/tables/core-memory.d.ts +9 -0
- package/dist/db/schema/tables/core-memory.js +41 -0
- package/dist/db/schema/tables/entities.d.ts +9 -0
- package/dist/db/schema/tables/entities.js +39 -0
- package/dist/db/schema/tables/entity-relations.d.ts +9 -0
- package/dist/db/schema/tables/entity-relations.js +31 -0
- package/dist/db/schema/tables/learnings.d.ts +9 -0
- package/dist/db/schema/tables/learnings.js +66 -0
- package/dist/db/schema/tables/memories.d.ts +9 -0
- package/dist/db/schema/tables/memories.js +161 -0
- package/dist/db/schema/tables/memory-associations.d.ts +9 -0
- package/dist/db/schema/tables/memory-associations.js +39 -0
- package/dist/db/schema/tables/memory-hash-cache.d.ts +9 -0
- package/dist/db/schema/tables/memory-hash-cache.js +29 -0
- package/dist/db/schema/tables/memory-merge-history.d.ts +9 -0
- package/dist/db/schema/tables/memory-merge-history.js +33 -0
- package/dist/db/schema/tables/memory-merge-proposals.d.ts +9 -0
- package/dist/db/schema/tables/memory-merge-proposals.js +39 -0
- package/dist/db/schema/tables/messages.d.ts +9 -0
- package/dist/db/schema/tables/messages.js +41 -0
- package/dist/db/schema/tables/namespaces.d.ts +9 -0
- package/dist/db/schema/tables/namespaces.js +37 -0
- package/dist/db/schema/tables/projects.d.ts +9 -0
- package/dist/db/schema/tables/projects.js +31 -0
- package/dist/db/schema/tables/users.d.ts +9 -0
- package/dist/db/schema/tables/users.js +27 -0
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +2 -2
- package/dist/db/supabase.d.ts +9 -0
- package/dist/db/supabase.js +24 -0
- package/dist/index.d.ts +2 -14
- package/dist/index.js +1320 -640
- package/dist/vendor/sql.js/sql-wasm.wasm +0 -0
- package/dist/webui/server.d.ts +5 -0
- package/dist/{api/web/web.js → webui/server.js} +511 -508
- package/generated/mcp/manifest.json +1 -1
- package/{.mcp.json → mcp.json.example} +1 -1
- package/package.json +159 -181
- package/scripts/README.md +60 -0
- package/scripts/copy-runtime-assets.mjs +26 -0
- package/scripts/generate-mcp.mjs +264 -264
- package/scripts/github-release.sh +4 -4
- package/scripts/install-claude-code.sh +85 -0
- package/scripts/install-cursor.sh +56 -0
- package/scripts/install-hooks.sh +73 -0
- package/scripts/install-interactive.mjs +357 -677
- package/scripts/install-opencode.sh +75 -0
- package/scripts/install-windsurf.sh +67 -0
- package/skills/squish-memory/SKILL.md +104 -114
- package/skills/squish-memory/{install.mjs → scripts/install.mjs} +2 -2
- package/skills/squish-memory/{install.sh → scripts/install.sh} +2 -2
- package/skills/squish-memory/write_skill.js +2 -0
- package/.claude-plugin/marketplace.json +0 -20
- package/.claude-plugin/plugin.json +0 -32
- package/.env.mcp.example +0 -60
- package/QUICK-START.md +0 -71
- package/bin/squish-add.mjs +0 -32
- package/bin/squish-rm.mjs +0 -21
- package/commands/observe.md +0 -5
- package/dist/api/web/index.d.ts +0 -3
- package/dist/api/web/index.js +0 -4
- package/dist/api/web/web-server.d.ts +0 -3
- package/dist/api/web/web-server.js +0 -6
- package/dist/api/web/web.d.ts +0 -4
- package/dist/commands/mcp-server.js +0 -393
- package/dist/core/context.js +0 -24
- package/dist/core/governance.js +0 -64
- package/dist/core/observations.d.ts +0 -26
- package/dist/core/observations.js +0 -110
- package/dist/core/requirements.d.ts +0 -20
- package/dist/core/requirements.js +0 -35
- package/hooks/hooks.json +0 -52
- package/hooks/post-tool-use.js +0 -26
- package/hooks/session-end.js +0 -28
- package/hooks/session-start.js +0 -33
- package/hooks/user-prompt-submit.js +0 -26
- package/hooks/utils.js +0 -153
- package/npx-installer.js +0 -208
- package/packages/plugin-claude-code/README.md +0 -73
- package/packages/plugin-claude-code/dist/plugin-wrapper.d.ts +0 -35
- package/packages/plugin-claude-code/dist/plugin-wrapper.js +0 -191
- package/packages/plugin-claude-code/package.json +0 -31
- package/packages/plugin-openclaw/README.md +0 -70
- package/packages/plugin-openclaw/dist/index.d.ts +0 -49
- package/packages/plugin-openclaw/dist/index.js +0 -262
- package/packages/plugin-openclaw/openclaw.plugin.json +0 -94
- package/packages/plugin-openclaw/package.json +0 -31
- package/packages/plugin-opencode/install.mjs +0 -217
- package/packages/plugin-opencode/package.json +0 -21
- package/scripts/db/check-db.mjs +0 -88
- package/scripts/db/fix-all-columns.mjs +0 -52
- package/scripts/db/fix-schema-all.mjs +0 -55
- package/scripts/db/fix-schema-full.mjs +0 -46
- package/scripts/db/fix-schema.mjs +0 -38
- package/scripts/db/init-db.mjs +0 -13
- package/scripts/db/recreate-db.mjs +0 -14
- package/scripts/install-mcp.mjs +0 -116
- package/scripts/install-web.sh +0 -120
- package/scripts/install.mjs +0 -340
- package/scripts/openclaw-bootstrap.mjs +0 -127
- package/scripts/package-release.sh +0 -71
- package/scripts/test/test-all-systems.mjs +0 -139
- package/scripts/test/test-memory-system.mjs +0 -139
- package/scripts/test/test-v0.5.0.mjs +0 -210
- package/skills/memory-guide/SKILL.md +0 -332
- package/skills/squish-cli/SKILL.md +0 -240
- package/skills/squish-mcp/SKILL.md +0 -355
- package/skills/squish-memory/claude-desktop.json +0 -12
- package/skills/squish-memory/openclaw.json +0 -13
- package/skills/squish-memory/opencode.json +0 -14
- package/skills/squish-memory/skill.json +0 -32
- /package/{commands → core/commands}/context-paging.md +0 -0
- /package/{commands → core/commands}/context-status.md +0 -0
- /package/{commands → core/commands}/context.md +0 -0
- /package/{commands → core/commands}/core-memory.md +0 -0
- /package/{commands → core/commands}/health.md +0 -0
- /package/{commands → core/commands}/merge.md +0 -0
- /package/{commands → core/commands}/recall.md +0 -0
- /package/{commands → core/commands}/remember.md +0 -0
- /package/{commands → core/commands}/search.md +0 -0
- /package/dist/{algorithms → core/algorithms}/detection/hash-filters.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/detection/hash-filters.js +0 -0
- /package/dist/{algorithms → core/algorithms}/handlers/approve-merge.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/handlers/detect-duplicates.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/handlers/get-stats.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/handlers/list-proposals.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/handlers/preview-merge.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/handlers/reject-merge.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/handlers/reverse-merge.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/safety/safety-checks.js +0 -0
- /package/dist/{algorithms → core/algorithms}/utils/response-builder.d.ts +0 -0
- /package/dist/{algorithms → core/algorithms}/utils/response-builder.js +0 -0
- /package/dist/{commands → core/commands}/managed-sync.d.ts +0 -0
- /package/dist/{commands → core/commands}/mcp-server.d.ts +0 -0
- /package/dist/core/{context.d.ts → context/context.d.ts} +0 -0
- /package/dist/core/{agent-memory.d.ts → ingestion/agent-memory.d.ts} +0 -0
- /package/dist/core/{core-memory.d.ts → ingestion/core-memory.d.ts} +0 -0
- /package/dist/core/{privacy.d.ts → security/privacy.d.ts} +0 -0
- /package/dist/core/{privacy.js → security/privacy.js} +0 -0
- /package/dist/core/{secret-detector.d.ts → security/secret-detector.d.ts} +0 -0
- /package/dist/core/{secret-detector.js → security/secret-detector.js} +0 -0
- /package/dist/core/{cache.d.ts → storage/cache.d.ts} +0 -0
- /package/dist/core/{database.d.ts → storage/database.d.ts} +0 -0
- /package/dist/core/{database.js → storage/database.js} +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walking Interface - Sequential memory retrieval through places
|
|
3
|
+
*
|
|
4
|
+
* Implements Method of Loci walking through memory places:
|
|
5
|
+
* - Walk single place to get memories in order
|
|
6
|
+
* - Walk all places for full tour
|
|
7
|
+
* - Token budget handling with TOON compression
|
|
8
|
+
*/
|
|
9
|
+
import { getProjectPlaces } from './places.js';
|
|
10
|
+
import { getPlaceMemories } from './memory-places.js';
|
|
11
|
+
import { getMemory } from '../memory/memories.js';
|
|
12
|
+
import { compressForContext } from '../toon.js';
|
|
13
|
+
import { logger } from '../logger.js';
|
|
14
|
+
/**
|
|
15
|
+
* Walk through a single place
|
|
16
|
+
*/
|
|
17
|
+
export async function walkPlace(projectId, placeType, options = {}) {
|
|
18
|
+
const { tokenBudget = 170, maxMemoriesPerPlace = 10, includePurpose = true, compressWithToon = false } = options;
|
|
19
|
+
// Get the place
|
|
20
|
+
const places = await getProjectPlaces(projectId);
|
|
21
|
+
const place = places.find(p => p.placeType === placeType);
|
|
22
|
+
if (!place) {
|
|
23
|
+
logger.warn(`[Walking] Place not found: ${placeType}`);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
// Get memory IDs for this place
|
|
27
|
+
const memoryIds = await getPlaceMemories(place.id, maxMemoriesPerPlace);
|
|
28
|
+
// Get full memories
|
|
29
|
+
const memories = [];
|
|
30
|
+
let totalTokens = 0;
|
|
31
|
+
for (const memoryId of memoryIds) {
|
|
32
|
+
const memory = await getMemory(memoryId);
|
|
33
|
+
if (!memory)
|
|
34
|
+
continue;
|
|
35
|
+
let content = memory.content || '';
|
|
36
|
+
// Compress with TOON if requested
|
|
37
|
+
if (compressWithToon && content) {
|
|
38
|
+
content = compressForContext(content);
|
|
39
|
+
}
|
|
40
|
+
const tokenEstimate = Math.ceil(content.length / 4); // rough token estimate
|
|
41
|
+
if (totalTokens + tokenEstimate > tokenBudget) {
|
|
42
|
+
// Would exceed budget - stop adding
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
memories.push({
|
|
46
|
+
id: memory.id,
|
|
47
|
+
content,
|
|
48
|
+
type: memory.type,
|
|
49
|
+
tags: memory.tags || [],
|
|
50
|
+
createdAt: memory.createdAt || '',
|
|
51
|
+
});
|
|
52
|
+
totalTokens += tokenEstimate;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
place,
|
|
56
|
+
memories,
|
|
57
|
+
totalTokens,
|
|
58
|
+
truncated: memories.length < memoryIds.length,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Walk through all places in loci order
|
|
63
|
+
*/
|
|
64
|
+
export async function walkAllPlaces(projectId, options = {}) {
|
|
65
|
+
const places = await getProjectPlaces(projectId);
|
|
66
|
+
const results = [];
|
|
67
|
+
for (const place of places) {
|
|
68
|
+
const walkResult = await walkPlace(projectId, place.placeType, options);
|
|
69
|
+
if (walkResult && walkResult.memories.length > 0) {
|
|
70
|
+
results.push(walkResult);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
logger.info(`[Walking] Walked ${results.length} places for project ${projectId}`);
|
|
74
|
+
return results;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Quick tour - just place names and purposes (minimal tokens)
|
|
78
|
+
*/
|
|
79
|
+
export async function quickTour(projectId) {
|
|
80
|
+
const places = await getProjectPlaces(projectId);
|
|
81
|
+
return {
|
|
82
|
+
places: places.map(p => ({
|
|
83
|
+
name: p.name,
|
|
84
|
+
purpose: p.purpose || '',
|
|
85
|
+
memoryCount: p.memoryCount,
|
|
86
|
+
})),
|
|
87
|
+
totalMemories: places.reduce((sum, p) => sum + p.memoryCount, 0),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get context summary for a place (for injection)
|
|
92
|
+
*/
|
|
93
|
+
export async function getPlaceContext(projectId, placeType, maxTokens = 50) {
|
|
94
|
+
const walkResult = await walkPlace(projectId, placeType, {
|
|
95
|
+
tokenBudget: maxTokens,
|
|
96
|
+
compressWithToon: true,
|
|
97
|
+
});
|
|
98
|
+
if (!walkResult || walkResult.memories.length === 0) {
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
const lines = walkResult.memories.map((m, i) => `${i + 1}. [${m.type}] ${m.content.substring(0, 100)}`);
|
|
102
|
+
return `## ${walkResult.place.name}\n${lines.join('\n')}`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Full context for session start (all places)
|
|
106
|
+
*/
|
|
107
|
+
export async function getFullWalkingContext(projectId, maxTokens = 170) {
|
|
108
|
+
const results = await walkAllPlaces(projectId, {
|
|
109
|
+
tokenBudget: Math.floor(maxTokens / 7), // Distribute across 7 places
|
|
110
|
+
compressWithToon: true,
|
|
111
|
+
});
|
|
112
|
+
if (results.length === 0) {
|
|
113
|
+
return 'No memories yet. Start building your spatial memory!';
|
|
114
|
+
}
|
|
115
|
+
const sections = results.map(r => {
|
|
116
|
+
const lines = r.memories.slice(0, 3).map((m, i) => ` ${i + 1}. ${m.content.substring(0, 60)}...`).join('\n');
|
|
117
|
+
return `## ${r.place.name}\n${lines}`;
|
|
118
|
+
});
|
|
119
|
+
return sections.join('\n\n');
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=walking.js.map
|
package/dist/core/projects.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export interface ProjectRecord {
|
|
|
7
7
|
}
|
|
8
8
|
export declare function getProjectByPath(path: string): Promise<ProjectRecord | null>;
|
|
9
9
|
export declare function ensureProject(path?: string): Promise<ProjectRecord | null>;
|
|
10
|
+
export declare class ProjectNotFoundError extends Error {
|
|
11
|
+
constructor(path: string);
|
|
12
|
+
}
|
|
13
|
+
export declare function requireProject(path: string): Promise<ProjectRecord>;
|
|
14
|
+
export declare function getOrCreateProject(path?: string): Promise<ProjectRecord | null>;
|
|
10
15
|
export declare function getAllProjects(): Promise<ProjectRecord[]>;
|
|
11
16
|
export declare function getProjectById(id: string): Promise<ProjectRecord | null>;
|
|
12
17
|
//# sourceMappingURL=projects.d.ts.map
|
package/dist/core/projects.js
CHANGED
|
@@ -3,9 +3,8 @@ import { randomUUID } from 'crypto';
|
|
|
3
3
|
import { eq } from 'drizzle-orm';
|
|
4
4
|
import { getDb } from '../db/index.js';
|
|
5
5
|
import { getSchema } from '../db/schema.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { createDatabaseClient } from './database.js';
|
|
6
|
+
import { serializeMetadata, deserializeMetadata } from './memory/serialization.js';
|
|
7
|
+
import { createDatabaseClient } from './storage/database.js';
|
|
9
8
|
export async function getProjectByPath(path) {
|
|
10
9
|
try {
|
|
11
10
|
const db = createDatabaseClient(await getDb());
|
|
@@ -31,26 +30,48 @@ export async function ensureProject(path) {
|
|
|
31
30
|
const id = randomUUID();
|
|
32
31
|
const name = basename(path) || path;
|
|
33
32
|
const metadata = { source: 'mcp' };
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
await db.insert(schema.projects).values({
|
|
34
|
+
id,
|
|
35
|
+
name,
|
|
36
|
+
path,
|
|
37
|
+
metadata: serializeMetadata(metadata),
|
|
38
|
+
});
|
|
39
|
+
return { id, name, path, metadata };
|
|
40
|
+
}
|
|
41
|
+
export class ProjectNotFoundError extends Error {
|
|
42
|
+
constructor(path) {
|
|
43
|
+
super(`Project not found: ${path}`);
|
|
44
|
+
this.name = 'ProjectNotFoundError';
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
metadata: toSqliteJson(metadata),
|
|
48
|
-
});
|
|
46
|
+
}
|
|
47
|
+
export async function requireProject(path) {
|
|
48
|
+
const project = await getProjectByPath(path);
|
|
49
|
+
if (!project) {
|
|
50
|
+
throw new ProjectNotFoundError(path);
|
|
49
51
|
}
|
|
52
|
+
return project;
|
|
53
|
+
}
|
|
54
|
+
export async function getOrCreateProject(path) {
|
|
55
|
+
if (!path)
|
|
56
|
+
return null;
|
|
57
|
+
const existing = await getProjectByPath(path);
|
|
58
|
+
if (existing)
|
|
59
|
+
return existing;
|
|
60
|
+
const db = createDatabaseClient(await getDb());
|
|
61
|
+
const schema = await getSchema();
|
|
62
|
+
const id = randomUUID();
|
|
63
|
+
const name = basename(path) || path;
|
|
64
|
+
const metadata = { source: 'mcp' };
|
|
65
|
+
await db.insert(schema.projects).values({
|
|
66
|
+
id,
|
|
67
|
+
name,
|
|
68
|
+
path,
|
|
69
|
+
metadata: serializeMetadata(metadata),
|
|
70
|
+
});
|
|
50
71
|
return { id, name, path, metadata };
|
|
51
72
|
}
|
|
52
73
|
function normalizeProject(row) {
|
|
53
|
-
const metadata =
|
|
74
|
+
const metadata = deserializeMetadata(row.metadata ?? null);
|
|
54
75
|
return {
|
|
55
76
|
id: row.id,
|
|
56
77
|
name: row.name,
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ResponseFormatter - Unified response formatting for all Squish output contexts
|
|
3
|
+
* @module core/responses
|
|
4
|
+
*/
|
|
5
|
+
export type ResponseStatus = 'ok' | 'error';
|
|
6
|
+
export interface BaseResponse<T = unknown> {
|
|
7
|
+
status: ResponseStatus;
|
|
8
|
+
message?: string;
|
|
9
|
+
data?: T;
|
|
10
|
+
error?: string;
|
|
11
|
+
timestamp?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PaginatedResponse<T> extends BaseResponse<T[]> {
|
|
14
|
+
count: number;
|
|
15
|
+
total?: number;
|
|
16
|
+
page?: number;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Format options for web responses
|
|
21
|
+
*/
|
|
22
|
+
export interface WebFormatOptions {
|
|
23
|
+
statusCode?: number;
|
|
24
|
+
pagination?: {
|
|
25
|
+
total: number;
|
|
26
|
+
page: number;
|
|
27
|
+
limit: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Unified response formatter for all Squish output contexts
|
|
32
|
+
*/
|
|
33
|
+
export declare class ResponseFormatter {
|
|
34
|
+
/**
|
|
35
|
+
* Generate ISO timestamp
|
|
36
|
+
*/
|
|
37
|
+
private static getTimestamp;
|
|
38
|
+
/**
|
|
39
|
+
* Build base response with timestamp
|
|
40
|
+
*/
|
|
41
|
+
private static buildBase;
|
|
42
|
+
/**
|
|
43
|
+
* Format response for CLI output (pretty-printed JSON)
|
|
44
|
+
*/
|
|
45
|
+
static cli<T>(data: T, message?: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Format error for CLI and exit process
|
|
48
|
+
*/
|
|
49
|
+
static cliError(error: Error): never;
|
|
50
|
+
/**
|
|
51
|
+
* Format successful response for Web API
|
|
52
|
+
*/
|
|
53
|
+
static web<T>(data: T, message?: string, options?: WebFormatOptions): {
|
|
54
|
+
status: number;
|
|
55
|
+
body: BaseResponse<T>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Format error response for Web API
|
|
59
|
+
*/
|
|
60
|
+
static webError(error: Error, options?: {
|
|
61
|
+
statusCode?: number;
|
|
62
|
+
log?: boolean;
|
|
63
|
+
}): {
|
|
64
|
+
status: number;
|
|
65
|
+
body: BaseResponse;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Format response for MCP tools
|
|
69
|
+
*/
|
|
70
|
+
static mcp<T>(data: T, message?: string): {
|
|
71
|
+
content: Array<{
|
|
72
|
+
type: string;
|
|
73
|
+
text: string;
|
|
74
|
+
}>;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Format error for MCP tools (throws McpError)
|
|
78
|
+
*/
|
|
79
|
+
static mcpError(error: Error, context?: string): never;
|
|
80
|
+
/**
|
|
81
|
+
* Format response for algorithm handlers
|
|
82
|
+
*/
|
|
83
|
+
static algorithm<T>(data: T, message: string, options?: {
|
|
84
|
+
ok?: boolean;
|
|
85
|
+
error?: string;
|
|
86
|
+
}): BaseResponse<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Convenience method for success responses
|
|
89
|
+
*/
|
|
90
|
+
static success<T>(data: T, message?: string): BaseResponse<T>;
|
|
91
|
+
/**
|
|
92
|
+
* Convenience method for failure responses
|
|
93
|
+
*/
|
|
94
|
+
static failure(message: string, error?: Error | string): BaseResponse;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ResponseFormatter - Unified response formatting for all Squish output contexts
|
|
3
|
+
* @module core/responses
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Unified response formatter for all Squish output contexts
|
|
7
|
+
*/
|
|
8
|
+
export class ResponseFormatter {
|
|
9
|
+
/**
|
|
10
|
+
* Generate ISO timestamp
|
|
11
|
+
*/
|
|
12
|
+
static getTimestamp() {
|
|
13
|
+
return new Date().toISOString();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build base response with timestamp
|
|
17
|
+
*/
|
|
18
|
+
static buildBase(status, message, data, error) {
|
|
19
|
+
return {
|
|
20
|
+
status,
|
|
21
|
+
message,
|
|
22
|
+
data,
|
|
23
|
+
error,
|
|
24
|
+
timestamp: this.getTimestamp(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// CLI Formatters
|
|
28
|
+
/**
|
|
29
|
+
* Format response for CLI output (pretty-printed JSON)
|
|
30
|
+
*/
|
|
31
|
+
static cli(data, message) {
|
|
32
|
+
const response = this.buildBase(data instanceof Error ? 'error' : 'ok', message, data);
|
|
33
|
+
return JSON.stringify(response, null, 2);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Format error for CLI and exit process
|
|
37
|
+
*/
|
|
38
|
+
static cliError(error) {
|
|
39
|
+
const response = this.buildBase('error', error.message, undefined, error.message);
|
|
40
|
+
console.error(JSON.stringify(response, null, 2));
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
// Web API Formatters
|
|
44
|
+
/**
|
|
45
|
+
* Format successful response for Web API
|
|
46
|
+
*/
|
|
47
|
+
static web(data, message, options) {
|
|
48
|
+
const body = this.buildBase('ok', message, data);
|
|
49
|
+
// Add pagination metadata if provided
|
|
50
|
+
if (options?.pagination) {
|
|
51
|
+
body.count = options.pagination.total;
|
|
52
|
+
body.total = options.pagination.total;
|
|
53
|
+
body.page = options.pagination.page;
|
|
54
|
+
body.limit = options.pagination.limit;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
status: options?.statusCode ?? 200,
|
|
58
|
+
body,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Format error response for Web API
|
|
63
|
+
*/
|
|
64
|
+
static webError(error, options) {
|
|
65
|
+
const statusCode = options?.statusCode ?? 500;
|
|
66
|
+
const body = this.buildBase('error', error.message, undefined, error.message);
|
|
67
|
+
if (options?.log !== false) {
|
|
68
|
+
console.error(`[Web API Error ${statusCode}]:`, error.message);
|
|
69
|
+
}
|
|
70
|
+
return { status: statusCode, body };
|
|
71
|
+
}
|
|
72
|
+
// MCP Formatters
|
|
73
|
+
/**
|
|
74
|
+
* Format response for MCP tools
|
|
75
|
+
*/
|
|
76
|
+
static mcp(data, message) {
|
|
77
|
+
const response = this.buildBase('ok', message, data);
|
|
78
|
+
return {
|
|
79
|
+
content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Format error for MCP tools (throws McpError)
|
|
84
|
+
*/
|
|
85
|
+
static mcpError(error, context) {
|
|
86
|
+
const message = context ? `${context}: ${error.message}` : error.message;
|
|
87
|
+
const response = this.buildBase('error', message, undefined, message);
|
|
88
|
+
// Import McpError dynamically to avoid requiring @modelcontextprotocol/sdk in non-MCP contexts
|
|
89
|
+
try {
|
|
90
|
+
const { McpError, ErrorCode } = require('@modelcontextprotocol/sdk/types.js');
|
|
91
|
+
throw new McpError(ErrorCode.InternalError, JSON.stringify(response));
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
// If McpError is not available, throw a standard error with MCP-formatted message
|
|
95
|
+
const mcpError = new Error(JSON.stringify(response));
|
|
96
|
+
mcpError.name = 'McpError';
|
|
97
|
+
throw mcpError;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Algorithm Handler Formatters
|
|
101
|
+
/**
|
|
102
|
+
* Format response for algorithm handlers
|
|
103
|
+
*/
|
|
104
|
+
static algorithm(data, message, options) {
|
|
105
|
+
const isOk = options?.ok !== false;
|
|
106
|
+
return this.buildBase(isOk ? 'ok' : 'error', message, isOk ? data : undefined, options?.error);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Convenience method for success responses
|
|
110
|
+
*/
|
|
111
|
+
static success(data, message) {
|
|
112
|
+
return this.buildBase('ok', message, data);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Convenience method for failure responses
|
|
116
|
+
*/
|
|
117
|
+
static failure(message, error) {
|
|
118
|
+
const errorMessage = error instanceof Error ? error.message : error;
|
|
119
|
+
return this.buildBase('error', message, undefined, errorMessage);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** Cron Scheduler - Persistent cron-based job scheduling with fallback support */
|
|
2
2
|
import cron from 'node-cron';
|
|
3
3
|
import { selfIterationHandler } from '../session-hooks/self-iteration-job.js';
|
|
4
|
+
import { runLifecycleMaintenance } from '../lifecycle.js';
|
|
4
5
|
import { logger } from '../logger.js';
|
|
5
6
|
import { config } from '../../config.js';
|
|
6
7
|
import { getDb } from '../../db/index.js';
|
|
7
|
-
import { maintenanceJobs, maintenanceJobHistory } from '../../drizzle/schema-sqlite.js';
|
|
8
|
+
import { maintenanceJobs, maintenanceJobHistory } from '../../db/drizzle/schema-sqlite.js';
|
|
8
9
|
import { eq } from 'drizzle-orm';
|
|
9
10
|
const jobHandlers = new Map();
|
|
10
11
|
const activeTasks = new Map();
|
|
@@ -14,6 +15,20 @@ export function registerJobHandler(jobName, handler) {
|
|
|
14
15
|
}
|
|
15
16
|
// Register self-iteration job handler
|
|
16
17
|
registerJobHandler('self_iteration', selfIterationHandler);
|
|
18
|
+
// Decay job handler - runs lifecycle maintenance (decay, tier updates, eviction)
|
|
19
|
+
const decayHandler = async (context) => {
|
|
20
|
+
const stats = await runLifecycleMaintenance();
|
|
21
|
+
return {
|
|
22
|
+
recordsProcessed: stats.decayed + stats.expired + stats.evicted,
|
|
23
|
+
summary: {
|
|
24
|
+
decayed: stats.decayed,
|
|
25
|
+
expired: stats.expired,
|
|
26
|
+
evicted: stats.evicted,
|
|
27
|
+
tierChanges: stats.tierChanges,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
registerJobHandler('decay_maintenance', decayHandler);
|
|
17
32
|
export async function initializeScheduler() {
|
|
18
33
|
if (!config.cronEnabled) {
|
|
19
34
|
logger.info('[Scheduler] Cron scheduling disabled, using heartbeat fallback');
|
|
@@ -42,6 +57,13 @@ export async function initializeScheduler() {
|
|
|
42
57
|
}
|
|
43
58
|
async function ensureDefaultJobs(db) {
|
|
44
59
|
const defaultJobs = [
|
|
60
|
+
{
|
|
61
|
+
jobName: 'decay_maintenance',
|
|
62
|
+
jobType: 'hourly',
|
|
63
|
+
cronExpression: '0 * * * *', // Run every hour at :00
|
|
64
|
+
enabled: true,
|
|
65
|
+
jobConfig: { applyDecay: true, updateTiers: true, evictOld: true },
|
|
66
|
+
},
|
|
45
67
|
{
|
|
46
68
|
jobName: 'nightly_maintenance',
|
|
47
69
|
jobType: 'nightly',
|
|
@@ -110,12 +132,12 @@ async function ensureDefaultJobs(db) {
|
|
|
110
132
|
logger.warn(`[Scheduler] Drizzle insert failed, using raw SQL: ${insertError.message}`);
|
|
111
133
|
const rawDb = db.$client;
|
|
112
134
|
if (rawDb && typeof rawDb.prepare === 'function') {
|
|
113
|
-
const stmt = rawDb.prepare(`
|
|
114
|
-
INSERT INTO maintenance_jobs
|
|
115
|
-
(id, job_name, job_type, cron_expression, enabled, job_config,
|
|
116
|
-
total_runs, success_count, failure_count, last_run_at, next_run_at,
|
|
117
|
-
last_run_duration, last_run_status, last_run_error)
|
|
118
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
135
|
+
const stmt = rawDb.prepare(`
|
|
136
|
+
INSERT INTO maintenance_jobs
|
|
137
|
+
(id, job_name, job_type, cron_expression, enabled, job_config,
|
|
138
|
+
total_runs, success_count, failure_count, last_run_at, next_run_at,
|
|
139
|
+
last_run_duration, last_run_status, last_run_error)
|
|
140
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
119
141
|
`);
|
|
120
142
|
stmt.run(crypto.randomUUID(), job.jobName, job.jobType, job.cronExpression, job.enabled ? 1 : 0, JSON.stringify(job.jobConfig), 0, 0, 0, null, null, null, null, null);
|
|
121
143
|
}
|
|
@@ -5,7 +5,7 @@ import { runLifecycleMaintenance } from '../lifecycle.js';
|
|
|
5
5
|
import { pruneWeakAssociations } from '../associations.js';
|
|
6
6
|
import { pruneOldSummaries } from '../summarization.js';
|
|
7
7
|
import { getDb } from '../../db/index.js';
|
|
8
|
-
import { memories, memoryFeedback } from '../../drizzle/schema-sqlite.js';
|
|
8
|
+
import { memories, memoryFeedback } from '../../db/drizzle/schema-sqlite.js';
|
|
9
9
|
import { eq, and, gt, lt } from 'drizzle-orm';
|
|
10
10
|
export async function runNightlyJob(context) {
|
|
11
11
|
const summary = {};
|
|
@@ -2,10 +2,10 @@ import { and, desc, eq, gte, lte } from 'drizzle-orm';
|
|
|
2
2
|
import { getDb } from '../../db/index.js';
|
|
3
3
|
import { getSchema } from '../../db/schema.js';
|
|
4
4
|
import { config } from '../../config.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { createDatabaseClient } from '
|
|
8
|
-
import { normalizeTimestamp, clampLimit } from '
|
|
5
|
+
import { requireProject } from '../../core/projects.js';
|
|
6
|
+
import { deserializeMetadata } from '../../core/memory/serialization.js';
|
|
7
|
+
import { createDatabaseClient } from '../storage/database.js';
|
|
8
|
+
import { normalizeTimestamp, clampLimit } from '../lib/utils.js';
|
|
9
9
|
export async function searchConversations(input) {
|
|
10
10
|
const limit = clampLimit(input.limit, 5, 1, 50);
|
|
11
11
|
if (config.isTeamMode) {
|
|
@@ -19,10 +19,8 @@ export async function getRecentConversations(input) {
|
|
|
19
19
|
const limit = clampLimit(input.n, 3, 1, 50);
|
|
20
20
|
const whereParts = [];
|
|
21
21
|
if (input.project) {
|
|
22
|
-
const project = await
|
|
23
|
-
|
|
24
|
-
whereParts.push(eq(schema.conversations.projectId, project.id));
|
|
25
|
-
}
|
|
22
|
+
const project = await requireProject(input.project);
|
|
23
|
+
whereParts.push(eq(schema.conversations.projectId, project.id));
|
|
26
24
|
}
|
|
27
25
|
if (input.before) {
|
|
28
26
|
whereParts.push(lte(schema.conversations.startedAt, new Date(input.before)));
|
|
@@ -46,24 +44,24 @@ async function searchConversationsSqlite(input, limit) {
|
|
|
46
44
|
params.push(input.role);
|
|
47
45
|
}
|
|
48
46
|
params.push(limit);
|
|
49
|
-
const statement = sqlite.prepare(`
|
|
50
|
-
SELECT DISTINCT
|
|
51
|
-
c.id as id,
|
|
52
|
-
c.project_id as projectId,
|
|
53
|
-
c.session_id as sessionId,
|
|
54
|
-
c.title as title,
|
|
55
|
-
c.summary as summary,
|
|
56
|
-
c.message_count as messageCount,
|
|
57
|
-
c.token_count as tokenCount,
|
|
58
|
-
c.started_at as startedAt,
|
|
59
|
-
c.ended_at as endedAt,
|
|
60
|
-
c.metadata as metadata
|
|
61
|
-
FROM conversations c
|
|
62
|
-
JOIN messages m ON m.conversation_id = c.id
|
|
63
|
-
JOIN messages_fts ON messages_fts.rowid = m.rowid
|
|
64
|
-
WHERE ${where}
|
|
65
|
-
ORDER BY c.started_at DESC
|
|
66
|
-
LIMIT ?
|
|
47
|
+
const statement = sqlite.prepare(`
|
|
48
|
+
SELECT DISTINCT
|
|
49
|
+
c.id as id,
|
|
50
|
+
c.project_id as projectId,
|
|
51
|
+
c.session_id as sessionId,
|
|
52
|
+
c.title as title,
|
|
53
|
+
c.summary as summary,
|
|
54
|
+
c.message_count as messageCount,
|
|
55
|
+
c.token_count as tokenCount,
|
|
56
|
+
c.started_at as startedAt,
|
|
57
|
+
c.ended_at as endedAt,
|
|
58
|
+
c.metadata as metadata
|
|
59
|
+
FROM conversations c
|
|
60
|
+
JOIN messages m ON m.conversation_id = c.id
|
|
61
|
+
JOIN messages_fts ON messages_fts.rowid = m.rowid
|
|
62
|
+
WHERE ${where}
|
|
63
|
+
ORDER BY c.started_at DESC
|
|
64
|
+
LIMIT ?
|
|
67
65
|
`);
|
|
68
66
|
const rows = statement.all(...params);
|
|
69
67
|
return rows.map((row) => normalizeConversation(row));
|
|
@@ -77,26 +75,26 @@ async function searchConversationsPostgres(input, limit) {
|
|
|
77
75
|
whereParts.push(`m.role = $${values.length}`);
|
|
78
76
|
}
|
|
79
77
|
values.push(limit);
|
|
80
|
-
const rows = await db.$client.query(`SELECT DISTINCT ON (c.id)
|
|
81
|
-
c.id as "id",
|
|
82
|
-
c.project_id as "projectId",
|
|
83
|
-
c.session_id as "sessionId",
|
|
84
|
-
c.title as "title",
|
|
85
|
-
c.summary as "summary",
|
|
86
|
-
c.message_count as "messageCount",
|
|
87
|
-
c.token_count as "tokenCount",
|
|
88
|
-
c.started_at as "startedAt",
|
|
89
|
-
c.ended_at as "endedAt",
|
|
90
|
-
c.metadata as "metadata"
|
|
91
|
-
FROM conversations c
|
|
92
|
-
JOIN messages m ON m.conversation_id = c.id
|
|
93
|
-
WHERE ${whereParts.join(' AND ')}
|
|
94
|
-
ORDER BY c.id, c.started_at DESC
|
|
78
|
+
const rows = await db.$client.query(`SELECT DISTINCT ON (c.id)
|
|
79
|
+
c.id as "id",
|
|
80
|
+
c.project_id as "projectId",
|
|
81
|
+
c.session_id as "sessionId",
|
|
82
|
+
c.title as "title",
|
|
83
|
+
c.summary as "summary",
|
|
84
|
+
c.message_count as "messageCount",
|
|
85
|
+
c.token_count as "tokenCount",
|
|
86
|
+
c.started_at as "startedAt",
|
|
87
|
+
c.ended_at as "endedAt",
|
|
88
|
+
c.metadata as "metadata"
|
|
89
|
+
FROM conversations c
|
|
90
|
+
JOIN messages m ON m.conversation_id = c.id
|
|
91
|
+
WHERE ${whereParts.join(' AND ')}
|
|
92
|
+
ORDER BY c.id, c.started_at DESC
|
|
95
93
|
LIMIT $${values.length}`, values);
|
|
96
94
|
return rows.rows.map((row) => normalizeConversation(row));
|
|
97
95
|
}
|
|
98
96
|
function normalizeConversation(row) {
|
|
99
|
-
const metadata =
|
|
97
|
+
const metadata = deserializeMetadata(row.metadata ?? null);
|
|
100
98
|
return {
|
|
101
99
|
id: row.id,
|
|
102
100
|
projectId: row.projectId ?? row.project_id ?? null,
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { desc, eq } from 'drizzle-orm';
|
|
2
2
|
import { getDb } from '../../db/index.js';
|
|
3
3
|
import { getSchema } from '../../db/schema.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { normalizeTimestamp } from '../../core/utils.js';
|
|
4
|
+
import { requireProject } from '../../core/projects.js';
|
|
5
|
+
import { deserializeMetadata } from '../../core/memory/serialization.js';
|
|
6
|
+
import { createDatabaseClient } from '../storage/database.js';
|
|
7
|
+
import { normalizeTimestamp } from '../lib/utils.js';
|
|
9
8
|
export async function getEntitiesForProject(projectPath, limit) {
|
|
10
9
|
const db = createDatabaseClient(await getDb());
|
|
11
10
|
const schema = await getSchema();
|
|
12
|
-
const project = await
|
|
13
|
-
if (!project)
|
|
14
|
-
return [];
|
|
11
|
+
const project = await requireProject(projectPath);
|
|
15
12
|
const rows = await db.select().from(schema.entities)
|
|
16
13
|
.where(eq(schema.entities.projectId, project.id))
|
|
17
14
|
.orderBy(desc(schema.entities.createdAt))
|
|
@@ -19,7 +16,7 @@ export async function getEntitiesForProject(projectPath, limit) {
|
|
|
19
16
|
return rows.map((row) => normalizeEntity(row));
|
|
20
17
|
}
|
|
21
18
|
function normalizeEntity(row) {
|
|
22
|
-
const properties =
|
|
19
|
+
const properties = deserializeMetadata(row.properties ?? null);
|
|
23
20
|
return {
|
|
24
21
|
id: row.id,
|
|
25
22
|
projectId: row.projectId ?? row.project_id ?? null,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute a simple graph boost for a set of memory IDs.
|
|
3
|
+
* For each memory, sum (weight * coactivationCount) of outgoing associations.
|
|
4
|
+
* Returns a map from memoryId to boost value (default 0).
|
|
5
|
+
*/
|
|
6
|
+
export declare function computeGraphBoost(memoryIds: string[]): Promise<Record<string, number>>;
|
|
7
|
+
//# sourceMappingURL=graph-boost.d.ts.map
|