claude-launchpad 1.3.0 → 1.4.0
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/README.md +2 -2
- package/dist/{chunk-UJP5PJTA.js → chunk-ADZ45KHX.js} +3 -3
- package/dist/{chunk-V4NXT4KB.js → chunk-DXDOVWOA.js} +64 -8
- package/dist/chunk-DXDOVWOA.js.map +1 -0
- package/dist/{chunk-N6X3E5AX.js → chunk-F6SLV2FR.js} +24 -5
- package/dist/chunk-F6SLV2FR.js.map +1 -0
- package/dist/{chunk-AR64LWGW.js → chunk-RJEPJ4JE.js} +25 -4
- package/dist/chunk-RJEPJ4JE.js.map +1 -0
- package/dist/{chunk-YXPJDIMK.js → chunk-UQOBOHKN.js} +33 -2
- package/dist/chunk-UQOBOHKN.js.map +1 -0
- package/dist/{chunk-J765H3HZ.js → chunk-WOC2PKT2.js} +2 -2
- package/dist/{chunk-F5PNKQKW.js → chunk-YZ53W47Z.js} +7 -2
- package/dist/chunk-YZ53W47Z.js.map +1 -0
- package/dist/cli.js +24 -13
- package/dist/cli.js.map +1 -1
- package/dist/commands/memory/server.js +5 -5
- package/dist/{context-VAXF3EW3.js → context-NCV46PTY.js} +6 -6
- package/dist/{install-M3JWBGMK.js → install-DORMJYCU.js} +6 -6
- package/dist/install-DORMJYCU.js.map +1 -0
- package/dist/{pull-ZQFCMK46.js → pull-UYLUGILU.js} +9 -9
- package/dist/{push-5ZJNWAE7.js → push-HWXJGSTL.js} +40 -17
- package/dist/push-HWXJGSTL.js.map +1 -0
- package/dist/{require-deps-QW2IU6I3.js → require-deps-RUXTMQUV.js} +3 -3
- package/dist/{stats-NPXPJNBO.js → stats-DFV24AJW.js} +7 -7
- package/dist/{sync-clean-JQLVE4WU.js → sync-clean-GFX5F55E.js} +2 -2
- package/dist/{sync-status-IYG7ZYC5.js → sync-status-VXMDWDRG.js} +9 -9
- package/dist/{tui-74FMIMUM.js → tui-ELOJ37ZA.js} +5 -5
- package/package.json +1 -1
- package/dist/chunk-AR64LWGW.js.map +0 -1
- package/dist/chunk-F5PNKQKW.js.map +0 -1
- package/dist/chunk-N6X3E5AX.js.map +0 -1
- package/dist/chunk-V4NXT4KB.js.map +0 -1
- package/dist/chunk-YXPJDIMK.js.map +0 -1
- package/dist/install-M3JWBGMK.js.map +0 -1
- package/dist/push-5ZJNWAE7.js.map +0 -1
- /package/dist/{chunk-UJP5PJTA.js.map → chunk-ADZ45KHX.js.map} +0 -0
- /package/dist/{chunk-J765H3HZ.js.map → chunk-WOC2PKT2.js.map} +0 -0
- /package/dist/{context-VAXF3EW3.js.map → context-NCV46PTY.js.map} +0 -0
- /package/dist/{pull-ZQFCMK46.js.map → pull-UYLUGILU.js.map} +0 -0
- /package/dist/{require-deps-QW2IU6I3.js.map → require-deps-RUXTMQUV.js.map} +0 -0
- /package/dist/{stats-NPXPJNBO.js.map → stats-DFV24AJW.js.map} +0 -0
- /package/dist/{sync-clean-JQLVE4WU.js.map → sync-clean-GFX5F55E.js.map} +0 -0
- /package/dist/{sync-status-IYG7ZYC5.js.map → sync-status-VXMDWDRG.js.map} +0 -0
- /package/dist/{tui-74FMIMUM.js.map → tui-ELOJ37ZA.js.map} +0 -0
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
MEMORY_TYPES,
|
|
9
9
|
RELATION_TYPES,
|
|
10
10
|
coerceStringArray
|
|
11
|
-
} from "../../chunk-
|
|
11
|
+
} from "../../chunk-YZ53W47Z.js";
|
|
12
12
|
import {
|
|
13
13
|
detectProject
|
|
14
14
|
} from "../../chunk-NAW47BYA.js";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
MemoryRepo,
|
|
17
17
|
RelationRepo,
|
|
18
18
|
SearchRepo
|
|
19
|
-
} from "../../chunk-
|
|
19
|
+
} from "../../chunk-DXDOVWOA.js";
|
|
20
20
|
import {
|
|
21
21
|
SCORING_WEIGHTS,
|
|
22
22
|
closeDatabase,
|
|
@@ -24,9 +24,9 @@ import {
|
|
|
24
24
|
loadConfig,
|
|
25
25
|
migrate,
|
|
26
26
|
resolveDataDir
|
|
27
|
-
} from "../../chunk-
|
|
28
|
-
import "../../chunk-
|
|
29
|
-
import "../../chunk-
|
|
27
|
+
} from "../../chunk-RJEPJ4JE.js";
|
|
28
|
+
import "../../chunk-WOC2PKT2.js";
|
|
29
|
+
import "../../chunk-UQOBOHKN.js";
|
|
30
30
|
|
|
31
31
|
// src/commands/memory/server.ts
|
|
32
32
|
import { createRequire } from "module";
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
} from "./chunk-NAW47BYA.js";
|
|
9
9
|
import {
|
|
10
10
|
initStorage
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-ADZ45KHX.js";
|
|
12
|
+
import "./chunk-DXDOVWOA.js";
|
|
13
13
|
import {
|
|
14
14
|
DEFAULT_DECAY_PARAMS,
|
|
15
15
|
INJECTION_COLD_START_RAMP_END,
|
|
@@ -22,9 +22,9 @@ import {
|
|
|
22
22
|
RECENCY_HALF_LIFE,
|
|
23
23
|
TYPE_INJECTION_BONUS,
|
|
24
24
|
estimateTokens
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-RJEPJ4JE.js";
|
|
26
|
+
import "./chunk-WOC2PKT2.js";
|
|
27
|
+
import "./chunk-UQOBOHKN.js";
|
|
28
28
|
|
|
29
29
|
// src/commands/memory/subcommands/context.ts
|
|
30
30
|
import { readFileSync, writeFileSync } from "fs";
|
|
@@ -439,4 +439,4 @@ async function runContext(opts) {
|
|
|
439
439
|
export {
|
|
440
440
|
runContext
|
|
441
441
|
};
|
|
442
|
-
//# sourceMappingURL=context-
|
|
442
|
+
//# sourceMappingURL=context-NCV46PTY.js.map
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
loadConfig,
|
|
6
6
|
migrate,
|
|
7
7
|
resolveDataDir
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-RJEPJ4JE.js";
|
|
9
|
+
import "./chunk-WOC2PKT2.js";
|
|
10
10
|
import {
|
|
11
11
|
getMemoryPlacement,
|
|
12
12
|
log,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
readSettingsLocalJson,
|
|
15
15
|
writeSettingsJson,
|
|
16
16
|
writeSettingsLocalJson
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-UQOBOHKN.js";
|
|
18
18
|
|
|
19
19
|
// src/commands/memory/subcommands/install.ts
|
|
20
20
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
@@ -155,7 +155,7 @@ function addSessionEndPushHook(hooks) {
|
|
|
155
155
|
});
|
|
156
156
|
if (alreadyHooked) return hooks;
|
|
157
157
|
const entry = {
|
|
158
|
-
hooks: [{ type: "command", command: "claude-launchpad memory push -y >/dev/null 2>&1
|
|
158
|
+
hooks: [{ type: "command", command: "claude-launchpad memory push -y >/dev/null 2>&1; exit 0" }]
|
|
159
159
|
};
|
|
160
160
|
log.info("Session end: memories will auto-push to GitHub Gist");
|
|
161
161
|
return { ...hooks, SessionEnd: [...sessionEndHooks, entry] };
|
|
@@ -181,7 +181,7 @@ function addToolPermissions(settings) {
|
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
183
|
async function ensureNativeDeps() {
|
|
184
|
-
const { cwdRequire } = await import("./require-deps-
|
|
184
|
+
const { cwdRequire } = await import("./require-deps-RUXTMQUV.js");
|
|
185
185
|
try {
|
|
186
186
|
cwdRequire("better-sqlite3");
|
|
187
187
|
return;
|
|
@@ -308,4 +308,4 @@ export {
|
|
|
308
308
|
detectExistingSetup,
|
|
309
309
|
runInstall
|
|
310
310
|
};
|
|
311
|
-
//# sourceMappingURL=install-
|
|
311
|
+
//# sourceMappingURL=install-DORMJYCU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/memory/subcommands/install.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { execSync } from 'node:child_process';\nimport { createDatabase, closeDatabase } from '../storage/database.js';\nimport { migrate } from '../storage/migrator.js';\nimport { loadConfig, resolveDataDir } from '../config.js';\nimport { readSettingsJson, writeSettingsJson, readSettingsLocalJson, writeSettingsLocalJson } from '../../../lib/settings.js';\nimport { getMemoryPlacement } from '../../../lib/memory-placement.js';\nimport { log } from '../../../lib/output.js';\nimport type { MemoryPlacement } from '../../../types/index.js';\n\nfunction isGhAuthenticated(): boolean {\n try {\n execSync('gh auth status', { stdio: 'pipe', timeout: 5000 });\n return true;\n } catch {\n return false;\n }\n}\n\ninterface InstallOpts {\n readonly dbPath?: string;\n}\n\nexport async function runInstall(opts: InstallOpts): Promise<void> {\n log.blank();\n log.step('Setting up your knowledge base');\n log.blank();\n\n // Step 0: Ensure native deps are installed globally\n await ensureNativeDeps();\n\n // Prompt for placement before any config writes\n const placement = await getMemoryPlacement(process.cwd());\n\n const config = loadConfig(opts.dbPath ? { dataDir: opts.dbPath } : undefined);\n const dataDir = resolveDataDir(config.dataDir);\n\n // Step 1: Database\n log.step('[1/5] Creating knowledge base...');\n if (!existsSync(dataDir)) {\n mkdirSync(dataDir, { recursive: true });\n }\n const db = createDatabase({ dataDir });\n migrate(db);\n closeDatabase(db);\n log.success(`Knowledge base created at ${dataDir}/memory.db`);\n\n // Step 2: Configure Claude Code settings\n log.step('[2/5] Connecting to Claude Code...');\n await configureSettings(process.cwd(), placement);\n\n // Step 3: Register MCP server (project scope for shared, local scope for local)\n log.step('[3/5] Enabling memory tools...');\n const mcpScope = placement === \"local\" ? \"local\" : \"project\";\n const registered = registerMcpServer(mcpScope);\n if (registered) {\n log.success('Memory tools available in Claude Code');\n } else {\n log.warn('Could not enable memory tools automatically.');\n log.info(`Run: claude mcp add --scope ${mcpScope} agentic-memory -- npx claude-launchpad memory serve`);\n }\n\n // Step 4: CLAUDE.md + skills\n log.step('[4/5] Adding instructions...');\n const guidanceAdded = injectClaudeMdGuidance(process.cwd(), placement);\n if (guidanceAdded) {\n const label = placement === \"local\" ? \".claude/CLAUDE.md\" : \"CLAUDE.md\";\n log.success(`${label} updated with memory instructions`);\n }\n if (placement === \"shared\") {\n const skillsInstalled = installSkills(process.cwd());\n if (skillsInstalled > 0) {\n log.success(`Installed ${skillsInstalled} skill(s) to .claude/skills/`);\n }\n }\n\n log.blank();\n log.success('Knowledge base is ready. Claude will now remember across sessions.');\n log.info('Restart your Claude Code session to activate.');\n\n // Sync guidance\n if (isGhAuthenticated()) {\n log.info('Cross-device sync available. Run `memory push` to back up, or it auto-syncs each session.');\n } else {\n log.blank();\n log.info('Recommended: install the GitHub CLI for cross-device memory sync:');\n log.step(' https://cli.github.com/');\n log.step(' gh auth login');\n }\n log.blank();\n}\n\nexport function detectExistingSetup(projectDir: string): MemoryPlacement | null {\n // Check local CLAUDE.md\n try {\n const localClaude = readFileSync(join(projectDir, '.claude', 'CLAUDE.md'), 'utf-8');\n if (localClaude.includes('## Memory') || localClaude.includes('agentic-memory')) return \"local\";\n } catch { /* not found */ }\n\n // Check root CLAUDE.md\n try {\n const rootClaude = readFileSync(join(projectDir, 'CLAUDE.md'), 'utf-8');\n if (rootClaude.includes('## Memory (agentic-memory)')) return \"shared\";\n } catch { /* not found */ }\n\n return null;\n}\n\nasync function configureSettings(projectDir: string, placement: MemoryPlacement): Promise<void> {\n const read = placement === \"local\" ? readSettingsLocalJson : readSettingsJson;\n const write = placement === \"local\" ? writeSettingsLocalJson : writeSettingsJson;\n const settings = await read(projectDir);\n\n // Disable built-in auto-memory\n log.info('Built-in auto-memory disabled (replaced by knowledge base)');\n\n // Build hooks immutably — always add sync hooks (they fail silently without gh)\n const baseHooks = (settings['hooks'] ?? {}) as Record<string, unknown[]>;\n const withPull = addSessionStartPullHook(baseHooks);\n const withContext = addSessionStartHook(withPull);\n const withPush = addSessionEndPushHook(withContext);\n\n // Build permissions immutably\n const withPermissions = addToolPermissions(settings);\n\n const updated = {\n ...withPermissions,\n autoMemoryEnabled: false,\n hooks: withPush,\n };\n\n await write(projectDir, updated);\n const target = placement === \"local\" ? \"settings.local.json\" : \"settings.json\";\n log.success(`Claude Code configured in ${target}`);\n}\n\nfunction addSessionStartPullHook(hooks: Record<string, unknown[]>): Record<string, unknown[]> {\n const sessionStartHooks = (hooks['SessionStart'] ?? []) as Record<string, unknown>[];\n const alreadyHooked = sessionStartHooks.some((h) => {\n const innerHooks = h['hooks'] as Record<string, unknown>[] | undefined;\n return innerHooks?.some(\n ih => typeof ih['command'] === 'string' && (ih['command'] as string).includes('memory pull'),\n );\n });\n\n if (alreadyHooked) return hooks;\n\n // Insert at the beginning so pull runs before context injection\n const entry = {\n matcher: 'startup',\n hooks: [{ type: 'command', command: 'claude-launchpad memory pull -y 2>/dev/null; exit 0' }],\n };\n log.info('Session start: memories will auto-pull from GitHub Gist');\n return { ...hooks, SessionStart: [entry, ...sessionStartHooks] };\n}\n\nfunction addSessionStartHook(hooks: Record<string, unknown[]>): Record<string, unknown[]> {\n const sessionStartHooks = (hooks['SessionStart'] ?? []) as Record<string, unknown>[];\n const hookCommand = 'npx claude-launchpad memory context --json 2>/dev/null; exit 0';\n\n const alreadyHooked = sessionStartHooks.some((h) => {\n const innerHooks = h['hooks'] as Record<string, unknown>[] | undefined;\n return innerHooks?.some(\n ih => typeof ih['command'] === 'string' && (ih['command'] as string).includes('claude-launchpad memory context'),\n );\n });\n\n if (alreadyHooked) return hooks;\n\n const entry = {\n matcher: 'startup|resume',\n hooks: [{ type: 'command', command: hookCommand }],\n };\n log.info('Session start: Claude will recall relevant context automatically');\n return { ...hooks, SessionStart: [...sessionStartHooks, entry] };\n}\n\nfunction addSessionEndPushHook(hooks: Record<string, unknown[]>): Record<string, unknown[]> {\n const sessionEndHooks = (hooks['SessionEnd'] ?? []) as Record<string, unknown>[];\n const alreadyHooked = sessionEndHooks.some((h) => {\n const innerHooks = h['hooks'] as Record<string, unknown>[] | undefined;\n return innerHooks?.some(\n ih => typeof ih['command'] === 'string' && (ih['command'] as string).includes('memory push'),\n );\n });\n\n if (alreadyHooked) return hooks;\n\n const entry = {\n hooks: [{ type: 'command', command: 'claude-launchpad memory push -y >/dev/null 2>&1; exit 0' }],\n };\n log.info('Session end: memories will auto-push to GitHub Gist');\n return { ...hooks, SessionEnd: [...sessionEndHooks, entry] };\n}\n\nfunction addToolPermissions(settings: Record<string, unknown>): Record<string, unknown> {\n const permissions = (settings['permissions'] ?? {}) as Record<string, unknown>;\n const allowList = (permissions['allow'] ?? []) as readonly string[];\n\n const memoryTools = [\n 'mcp__agentic-memory__memory_store',\n 'mcp__agentic-memory__memory_search',\n 'mcp__agentic-memory__memory_recent',\n 'mcp__agentic-memory__memory_forget',\n 'mcp__agentic-memory__memory_relate',\n 'mcp__agentic-memory__memory_stats',\n 'mcp__agentic-memory__memory_update',\n ];\n\n const missing = memoryTools.filter((t) => !allowList.includes(t));\n if (missing.length === 0) return settings;\n\n log.info(`${missing.length} memory tools auto-approved`);\n return {\n ...settings,\n permissions: { ...permissions, allow: [...allowList, ...missing] },\n };\n}\n\nasync function ensureNativeDeps(): Promise<void> {\n const { cwdRequire } = await import('../utils/require-deps.js');\n try {\n cwdRequire('better-sqlite3');\n return;\n } catch {\n // Not installed — install globally\n }\n\n log.step('Installing required database libraries...');\n try {\n execSync('npm install -g better-sqlite3 sqlite-vec', { stdio: 'pipe', timeout: 120000 });\n log.success('Database libraries installed');\n } catch {\n log.error('Could not install database libraries automatically.');\n log.blank();\n log.info('Install manually:');\n log.step(' npm install -g better-sqlite3 sqlite-vec');\n log.blank();\n log.info('Requires a C++ compiler (Xcode on macOS, build-essential on Linux).');\n process.exit(1);\n }\n}\n\nfunction registerMcpServer(scope: \"project\" | \"local\"): boolean {\n try {\n const existing = execSync('claude mcp list', { stdio: 'pipe', timeout: 10000, encoding: 'utf-8' });\n if (existing.includes('agentic-memory')) {\n log.info('Memory tools already registered');\n return true;\n }\n execSync(\n `claude mcp add --scope ${scope} agentic-memory -- npx claude-launchpad memory serve`,\n { stdio: 'pipe', timeout: 10000 },\n );\n return true;\n } catch {\n return false;\n }\n}\n\nconst MEMORY_GUIDANCE = `\n## Memory (agentic-memory)\nThis project uses **agentic-memory** for persistent memory across sessions.\n- **DO NOT** use the built-in auto-memory system (~/.claude/projects/*/memory/)\n- Memory context is **automatically injected** at session start via SessionStart hook - no need to call memory_recent manually\n- Use \\`memory_search\\` to find specific memories by keyword\n- Use \\`memory_store\\` to save decisions, gotchas, and learnings worth remembering\n- Use \\`memory_stats\\` to check memory health\n- **STORE IMMEDIATELY** when: a dependency strategy changes, an architecture decision is made, a convention is established, a bug pattern is discovered, or a feature is killed/added\n`;\n\nfunction injectClaudeMdGuidance(projectDir: string, placement: MemoryPlacement): boolean {\n const claudeMdPath = placement === \"local\"\n ? join(projectDir, '.claude', 'CLAUDE.md')\n : join(projectDir, 'CLAUDE.md');\n\n let content = '';\n try {\n content = readFileSync(claudeMdPath, 'utf-8');\n } catch {\n if (placement !== \"local\") return false;\n // Create local .claude/CLAUDE.md\n mkdirSync(join(projectDir, '.claude'), { recursive: true });\n content = '# Local Claude Config\\n';\n }\n\n if (content.includes('## Memory (agentic-memory)')) {\n return false;\n }\n\n const updated = content.trimEnd() + '\\n' + MEMORY_GUIDANCE;\n writeFileSync(claudeMdPath, updated, 'utf-8');\n return true;\n}\n\nconst MIGRATE_MEMORY_SKILL = `---\nname: lp-migrate-memory\ndescription: Migrate legacy Claude Code auto-memory files (~/.claude/projects/*/memory/*.md) into agentic-memory. Use when setting up agentic-memory on a project that already has built-in memories.\nallowed-tools: Read, Glob, Grep, mcp__agentic-memory__memory_store, mcp__agentic-memory__memory_search\n---\n\n# Migrate Legacy Claude Code Memories\n\nMigrate memory files from Claude Code's built-in auto-memory system into agentic-memory.\n\n## Steps\n\n1. **Find legacy memory files** for this project:\n - Scan \\`~/.claude/projects/*/memory/*.md\\` for directories whose slug matches the current project path\n - The slug format is the absolute path with \\`/\\` replaced by \\`-\\` and leading \\`-\\` (e.g. \\`-Users-john-projects-myapp\\`)\n - Also check \\`~/.claude/projects/*/memory/team/*.md\\` for team memories\n\n2. **For each memory file found**, read it and parse:\n - YAML frontmatter: \\`name\\`, \\`description\\`, \\`type\\` (user/feedback/project/reference)\n - Body content (everything after the frontmatter closing \\`---\\`)\n - Skip \\`MEMORY.md\\` (it's just an index file, not a memory)\n\n3. **Before storing**, check for duplicates:\n - Call \\`memory_search\\` with the memory description or first 100 chars of content\n - If a close match exists (same topic), skip it and report\n\n4. **Map types and store** each memory via \\`memory_store\\`:\n - \\`user\\` -> type: \\`semantic\\`, tags: [\\`user\\`, \\`migrated\\`], importance: 0.7\n - \\`feedback\\` -> type: \\`semantic\\`, tags: [\\`feedback\\`, \\`migrated\\`], importance: 0.8\n - \\`project\\` -> type: \\`semantic\\`, tags: [\\`project\\`, \\`migrated\\`], importance: 0.6\n - \\`reference\\` -> type: \\`semantic\\`, tags: [\\`reference\\`, \\`migrated\\`], importance: 0.5\n - Use the frontmatter \\`name\\` as the title\n - Use the body content as the memory content\n - Set source: \\`import\\`\n - Adjust importance up/down based on the content (decisions and gotchas deserve higher importance)\n\n5. **Report results**: list what was migrated, what was skipped (duplicates), and what failed\n\n## Important\n\n- Do NOT delete the original files - the user can do that manually after verifying\n- Do NOT migrate content that is purely derived from code (architecture, file structure) - it belongs in CLAUDE.md, not memory\n- If unsure about a memory's value, migrate it anyway - the decay system will naturally prune low-value memories over time\n`;\n\nconst SKILLS: Readonly<Record<string, string>> = {\n 'lp-migrate-memory': MIGRATE_MEMORY_SKILL,\n};\n\nfunction installSkills(projectDir: string): number {\n const skillsDir = join(projectDir, '.claude', 'skills');\n let installed = 0;\n\n for (const [name, content] of Object.entries(SKILLS)) {\n const skillDir = join(skillsDir, name);\n const skillPath = join(skillDir, 'SKILL.md');\n\n if (existsSync(skillPath)) continue;\n\n mkdirSync(skillDir, { rec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A;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6C7B,IAAM,SAA2C;AAAA,EAC/C,qBAAqB;AACvB;AAEA,SAAS,cAAc,YAA4B;AACjD,QAAM,YAAY,KAAK,YAAY,WAAW,QAAQ;AACtD,MAAI,YAAY;AAEhB,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACpD,UAAM,WAAW,KAAK,WAAW,IAAI;AACrC,UAAM,YAAY,KAAK,UAAU,UAAU;AAE3C,QAAI,WAAW,SAAS,EAAG;AAE3B,cAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AACvC,kBAAc,WAAW,QAAQ,UAAU,GAAG,OAAO;AACrD;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
mergeFromRemote,
|
|
4
4
|
parsePayload
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-F6SLV2FR.js";
|
|
6
6
|
import {
|
|
7
7
|
assertGhAvailable,
|
|
8
8
|
filenameToProject,
|
|
@@ -11,19 +11,19 @@ import {
|
|
|
11
11
|
projectToFilename,
|
|
12
12
|
readGistFile
|
|
13
13
|
} from "./chunk-3UJYOWGF.js";
|
|
14
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-YZ53W47Z.js";
|
|
15
15
|
import {
|
|
16
16
|
detectProject
|
|
17
17
|
} from "./chunk-NAW47BYA.js";
|
|
18
18
|
import {
|
|
19
19
|
initStorage
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-ADZ45KHX.js";
|
|
21
|
+
import "./chunk-DXDOVWOA.js";
|
|
22
|
+
import "./chunk-RJEPJ4JE.js";
|
|
23
|
+
import "./chunk-WOC2PKT2.js";
|
|
24
24
|
import {
|
|
25
25
|
log
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-UQOBOHKN.js";
|
|
27
27
|
|
|
28
28
|
// src/commands/memory/subcommands/pull.ts
|
|
29
29
|
async function runPull(opts) {
|
|
@@ -33,7 +33,7 @@ async function runPull(opts) {
|
|
|
33
33
|
log.error("No sync gist found. Run `memory push` first.");
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
const { requireMemoryDeps } = await import("./require-deps-
|
|
36
|
+
const { requireMemoryDeps } = await import("./require-deps-RUXTMQUV.js");
|
|
37
37
|
await requireMemoryDeps();
|
|
38
38
|
const ctx = initStorage();
|
|
39
39
|
try {
|
|
@@ -137,4 +137,4 @@ function printResult(result, project) {
|
|
|
137
137
|
export {
|
|
138
138
|
runPull
|
|
139
139
|
};
|
|
140
|
-
//# sourceMappingURL=pull-
|
|
140
|
+
//# sourceMappingURL=pull-UYLUGILU.js.map
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
memoryToSyncRow,
|
|
4
4
|
mergeFromRemote,
|
|
5
|
-
parsePayload
|
|
6
|
-
|
|
5
|
+
parsePayload,
|
|
6
|
+
tombstoneToSyncRow
|
|
7
|
+
} from "./chunk-F6SLV2FR.js";
|
|
7
8
|
import {
|
|
8
9
|
assertGhAvailable,
|
|
9
10
|
createGist,
|
|
@@ -12,30 +13,31 @@ import {
|
|
|
12
13
|
readGistFile,
|
|
13
14
|
updateGistFiles
|
|
14
15
|
} from "./chunk-3UJYOWGF.js";
|
|
15
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-YZ53W47Z.js";
|
|
16
17
|
import {
|
|
17
18
|
detectProject
|
|
18
19
|
} from "./chunk-NAW47BYA.js";
|
|
19
20
|
import {
|
|
20
21
|
initStorage
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
22
|
+
} from "./chunk-ADZ45KHX.js";
|
|
23
|
+
import "./chunk-DXDOVWOA.js";
|
|
24
|
+
import "./chunk-RJEPJ4JE.js";
|
|
25
|
+
import "./chunk-WOC2PKT2.js";
|
|
25
26
|
import {
|
|
26
27
|
log
|
|
27
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-UQOBOHKN.js";
|
|
28
29
|
|
|
29
30
|
// src/commands/memory/subcommands/push.ts
|
|
30
31
|
import { hostname } from "os";
|
|
31
32
|
import { confirm } from "@inquirer/prompts";
|
|
32
|
-
function buildPayload(memories, relations) {
|
|
33
|
+
function buildPayload(memories, relations, tombstones) {
|
|
33
34
|
return {
|
|
34
|
-
version:
|
|
35
|
+
version: 2,
|
|
35
36
|
machine_id: hostname(),
|
|
36
37
|
pushed_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
37
38
|
memories,
|
|
38
|
-
relations
|
|
39
|
+
relations,
|
|
40
|
+
tombstones
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
43
|
function filterRelations(allRelations, memoryIds) {
|
|
@@ -48,7 +50,7 @@ function filterRelations(allRelations, memoryIds) {
|
|
|
48
50
|
}
|
|
49
51
|
async function runPush(opts) {
|
|
50
52
|
assertGhAvailable();
|
|
51
|
-
const { requireMemoryDeps } = await import("./require-deps-
|
|
53
|
+
const { requireMemoryDeps } = await import("./require-deps-RUXTMQUV.js");
|
|
52
54
|
await requireMemoryDeps();
|
|
53
55
|
const ctx = initStorage();
|
|
54
56
|
try {
|
|
@@ -75,13 +77,18 @@ async function pushProject(ctx, allRelations, syncConfig, opts) {
|
|
|
75
77
|
if (remote) mergeFromRemote(ctx.memoryRepo, ctx.relationRepo, remote);
|
|
76
78
|
}
|
|
77
79
|
const memories = ctx.memoryRepo.getAllForSync(project);
|
|
78
|
-
|
|
80
|
+
const tombstones = ctx.memoryRepo.getTombstonesByProject(project);
|
|
81
|
+
if (memories.length === 0 && tombstones.length === 0) {
|
|
79
82
|
log.warn(`No memories found for "${project}". Nothing to push.`);
|
|
80
83
|
return;
|
|
81
84
|
}
|
|
82
85
|
const memoryIds = new Set(memories.map((m) => m.id));
|
|
83
86
|
const relations = filterRelations(allRelations, memoryIds);
|
|
84
|
-
const json = JSON.stringify(
|
|
87
|
+
const json = JSON.stringify(
|
|
88
|
+
buildPayload(memories.map(memoryToSyncRow), relations, tombstones.map(tombstoneToSyncRow)),
|
|
89
|
+
null,
|
|
90
|
+
2
|
|
91
|
+
);
|
|
85
92
|
if (!syncConfig) {
|
|
86
93
|
if (!opts.yes && !await confirmCreate()) return;
|
|
87
94
|
createGist(filename, json);
|
|
@@ -96,17 +103,23 @@ async function pushProject(ctx, allRelations, syncConfig, opts) {
|
|
|
96
103
|
}
|
|
97
104
|
async function pushAll(ctx, allRelations, syncConfig, opts) {
|
|
98
105
|
const allMemories = ctx.memoryRepo.getAllForSync();
|
|
99
|
-
|
|
106
|
+
const allTombstones = ctx.memoryRepo.getAllTombstones();
|
|
107
|
+
if (allMemories.length === 0 && allTombstones.length === 0) {
|
|
100
108
|
log.warn("No memories found. Nothing to push.");
|
|
101
109
|
return;
|
|
102
110
|
}
|
|
103
111
|
const byProject = groupByProject(allMemories);
|
|
112
|
+
const tombstonesByProject = groupTombstonesByProject(allTombstones);
|
|
113
|
+
for (const project of tombstonesByProject.keys()) {
|
|
114
|
+
if (!byProject.has(project)) byProject.set(project, []);
|
|
115
|
+
}
|
|
104
116
|
const files = {};
|
|
105
117
|
for (const [project, memories] of byProject) {
|
|
106
118
|
const memoryIds = new Set(memories.map((m) => m.id));
|
|
107
119
|
const relations = filterRelations(allRelations, memoryIds);
|
|
120
|
+
const tombstones = tombstonesByProject.get(project) ?? [];
|
|
108
121
|
files[projectToFilename(project)] = JSON.stringify(
|
|
109
|
-
buildPayload(memories.map(memoryToSyncRow), relations),
|
|
122
|
+
buildPayload(memories.map(memoryToSyncRow), relations, tombstones.map(tombstoneToSyncRow)),
|
|
110
123
|
null,
|
|
111
124
|
2
|
|
112
125
|
);
|
|
@@ -137,6 +150,16 @@ function groupByProject(memories) {
|
|
|
137
150
|
}
|
|
138
151
|
return byProject;
|
|
139
152
|
}
|
|
153
|
+
function groupTombstonesByProject(tombstones) {
|
|
154
|
+
const byProject = /* @__PURE__ */ new Map();
|
|
155
|
+
for (const t of tombstones) {
|
|
156
|
+
const key = t.project ?? "_global";
|
|
157
|
+
const list = byProject.get(key) ?? [];
|
|
158
|
+
list.push(t);
|
|
159
|
+
byProject.set(key, list);
|
|
160
|
+
}
|
|
161
|
+
return byProject;
|
|
162
|
+
}
|
|
140
163
|
async function confirmCreate() {
|
|
141
164
|
const proceed = await confirm({
|
|
142
165
|
message: "Create a private GitHub Gist for memory sync?",
|
|
@@ -148,4 +171,4 @@ async function confirmCreate() {
|
|
|
148
171
|
export {
|
|
149
172
|
runPush
|
|
150
173
|
};
|
|
151
|
-
//# sourceMappingURL=push-
|
|
174
|
+
//# sourceMappingURL=push-HWXJGSTL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/memory/subcommands/push.ts"],"sourcesContent":["import { hostname } from 'node:os';\nimport { confirm } from '@inquirer/prompts';\nimport { log } from '../../../lib/output.js';\nimport { initStorage } from './init-storage.js';\nimport type { StorageContext } from './init-storage.js';\nimport {\n assertGhAvailable,\n loadSyncConfig,\n createGist,\n readGistFile,\n updateGistFiles,\n projectToFilename,\n} from '../utils/gist-transport.js';\nimport { mergeFromRemote, memoryToSyncRow, tombstoneToSyncRow, parsePayload } from '../utils/sync-merge.js';\nimport type { Memory, SyncPayload, SyncRelationRow, SyncTombstone, Tombstone } from '../types.js';\nimport { detectProject } from '../utils/project.js';\n\ninterface PushOpts {\n readonly all?: boolean;\n readonly yes?: boolean;\n}\n\nfunction buildPayload(\n memories: readonly ReturnType<typeof memoryToSyncRow>[],\n relations: readonly SyncRelationRow[],\n tombstones: readonly SyncTombstone[],\n): SyncPayload {\n return {\n version: 2,\n machine_id: hostname(),\n pushed_at: new Date().toISOString(),\n memories,\n relations,\n tombstones,\n };\n}\n\nfunction filterRelations(\n allRelations: readonly { sourceId: string; targetId: string; relationType: string; createdAt: string }[],\n memoryIds: ReadonlySet<string>,\n): readonly SyncRelationRow[] {\n return allRelations\n .filter((r) => memoryIds.has(r.sourceId) && memoryIds.has(r.targetId))\n .map((r) => ({\n source_id: r.sourceId,\n target_id: r.targetId,\n relation_type: r.relationType as SyncRelationRow['relation_type'],\n created_at: r.createdAt,\n }));\n}\n\nexport async function runPush(opts: PushOpts): Promise<void> {\n assertGhAvailable();\n\n const { requireMemoryDeps } = await import('../utils/require-deps.js');\n await requireMemoryDeps();\n const ctx = initStorage();\n\n try {\n const syncConfig = loadSyncConfig();\n const allRelations = ctx.relationRepo.getAll();\n\n if (opts.all) {\n await pushAll(ctx, allRelations, syncConfig, opts);\n } else {\n await pushProject(ctx, allRelations, syncConfig, opts);\n }\n } finally {\n ctx.close();\n }\n}\n\nasync function pushProject(\n ctx: StorageContext,\n allRelations: readonly { sourceId: string; targetId: string; relationType: string; createdAt: string }[],\n syncConfig: { gistId: string } | null,\n opts: PushOpts,\n): Promise<void> {\n const project = detectProject(process.cwd());\n if (!project) {\n log.error('Could not detect project. Run from a project directory or use --all.');\n return;\n }\n\n const filename = projectToFilename(project);\n\n // Pull-before-push for this project\n if (syncConfig) {\n const remote = parsePayload(readGistFile(syncConfig.gistId, filename));\n if (remote) mergeFromRemote(ctx.memoryRepo, ctx.relationRepo, remote);\n }\n\n const memories = ctx.memoryRepo.getAllForSync(project);\n const tombstones = ctx.memoryRepo.getTombstonesByProject(project);\n\n if (memories.length === 0 && tombstones.length === 0) {\n log.warn(`No memories found for \"${project}\". Nothing to push.`);\n return;\n }\n\n const memoryIds = new Set(memories.map((m) => m.id));\n const relations = filterRelations(allRelations, memoryIds);\n const json = JSON.stringify(\n buildPayload(memories.map(memoryToSyncRow), relations, tombstones.map(tombstoneToSyncRow)),\n null,\n 2,\n );\n\n if (!syncConfig) {\n if (!opts.yes && !(await confirmCreate())) return;\n createGist(filename, json);\n } else {\n updateGistFiles(syncConfig.gistId, { [filename]: json });\n }\n\n log.blank();\n log.step('Push complete');\n log.info(`Project: ${project} (${memories.length} memories)`);\n log.info(`Relations: ${relations.length}`);\n log.blank();\n}\n\nasync function pushAll(\n ctx: StorageContext,\n allRelations: readonly { sourceId: string; targetId: string; relationType: string; createdAt: string }[],\n syncConfig: { gistId: string } | null,\n opts: PushOpts,\n): Promise<void> {\n const allMemories = ctx.memoryRepo.getAllForSync();\n const allTombstones = ctx.memoryRepo.getAllTombstones();\n\n if (allMemories.length === 0 && allTombstones.length === 0) {\n log.warn('No memories found. Nothing to push.');\n return;\n }\n\n const byProject = groupByProject(allMemories);\n const tombstonesByProject = groupTombstonesByProject(allTombstones);\n\n // Ensure every project with tombstones-only state still produces a file.\n for (const project of tombstonesByProject.keys()) {\n if (!byProject.has(project)) byProject.set(project, []);\n }\n\n const files: Record<string, string> = {};\n for (const [project, memories] of byProject) {\n const memoryIds = new Set(memories.map((m) => m.id));\n const relations = filterRelations(allRelations, memoryIds);\n const tombstones = tombstonesByProject.get(project) ?? [];\n files[projectToFilename(project)] = JSON.stringify(\n buildPayload(memories.map(memoryToSyncRow), relations, tombstones.map(tombstoneToSyncRow)),\n null,\n 2,\n );\n }\n\n if (!syncConfig) {\n if (!opts.yes && !(await confirmCreate())) return;\n const entries = Object.entries(files);\n const gistId = createGist(entries[0]![0], entries[0]![1]);\n if (entries.length > 1) {\n updateGistFiles(gistId, Object.fromEntries(entries.slice(1)));\n }\n } else {\n updateGistFiles(syncConfig.gistId, files);\n }\n\n log.blank();\n log.step('Push complete');\n log.info(`Projects: ${byProject.size}`);\n log.info(`Memories: ${allMemories.length}`);\n log.blank();\n}\n\nfunction groupByProject(memories: readonly Memory[]): Map<string, Memory[]> {\n const byProject = new Map<string, Memory[]>();\n for (const m of memories) {\n const key = m.project ?? '_global';\n const list = byProject.get(key) ?? [];\n list.push(m);\n byProject.set(key, list);\n }\n return byProject;\n}\n\nfunction groupTombstonesByProject(tombstones: readonly Tombstone[]): Map<string, Tombstone[]> {\n const byProject = new Map<string, Tombstone[]>();\n for (const t of tombstones) {\n const key = t.project ?? '_global';\n const list = byProject.get(key) ?? [];\n list.push(t);\n byProject.set(key, list);\n }\n return byProject;\n}\n\nasync function confirmCreate(): Promise<boolean> {\n const proceed = await confirm({\n message: 'Create a private GitHub Gist for memory sync?',\n default: true,\n });\n if (!proceed) log.info('Skipped.');\n return proceed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAqBxB,SAAS,aACP,UACA,WACA,YACa;AACb,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY,SAAS;AAAA,IACrB,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,gBACP,cACA,WAC4B;AAC5B,SAAO,aACJ,OAAO,CAAC,MAAM,UAAU,IAAI,EAAE,QAAQ,KAAK,UAAU,IAAI,EAAE,QAAQ,CAAC,EACpE,IAAI,CAAC,OAAO;AAAA,IACX,WAAW,EAAE;AAAA,IACb,WAAW,EAAE;AAAA,IACb,eAAe,EAAE;AAAA,IACjB,YAAY,EAAE;AAAA,EAChB,EAAE;AACN;AAEA,eAAsB,QAAQ,MAA+B;AAC3D,oBAAkB;AAElB,QAAM,EAAE,kBAAkB,IAAI,MAAM,OAAO,4BAA0B;AACrE,QAAM,kBAAkB;AACxB,QAAM,MAAM,YAAY;AAExB,MAAI;AACF,UAAM,aAAa,eAAe;AAClC,UAAM,eAAe,IAAI,aAAa,OAAO;AAE7C,QAAI,KAAK,KAAK;AACZ,YAAM,QAAQ,KAAK,cAAc,YAAY,IAAI;AAAA,IACnD,OAAO;AACL,Y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AE;AACvC,MAAI,KAAK,cAAc,YAAY,MAAM,EAAE;AAC3C,MAAI,MAAM;AACZ;AAEA,SAAS,eAAe,UAAoD;AAC1E,QAAM,YAAY,oBAAI,IAAsB;AAC5C,aAAW,KAAK,UAAU;AACxB,UAAM,MAAM,EAAE,WAAW;AACzB,UAAM,OAAO,UAAU,IAAI,GAAG,KAAK,CAAC;AACpC,SAAK,KAAK,CAAC;AACX,cAAU,IAAI,KAAK,IAAI;AAAA,EACzB;AACA,SAAO;AACT;AAEA,SAAS,yBAAyB,YAA4D;AAC5F,QAAM,YAAY,oBAAI,IAAyB;AAC/C,aAAW,KAAK,YAAY;AAC1B,UAAM,MAAM,EAAE,WAAW;AACzB,UAAM,OAAO,UAAU,IAAI,GAAG,KAAK,CAAC;AACpC,SAAK,KAAK,CAAC;AACX,cAAU,IAAI,KAAK,IAAI;AAAA,EACzB;AACA,SAAO;AACT;AAEA,eAAe,gBAAkC;AAC/C,QAAM,UAAU,MAAM,QAAQ;AAAA,IAC5B,SAAS;AAAA,IACT,SAAS;AAAA,EACX,CAAC;AACD,MAAI,CAAC,QAAS,KAAI,KAAK,UAAU;AACjC,SAAO;AACT;","names":[]}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
cwdRequire,
|
|
4
4
|
requireMemoryDeps
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-WOC2PKT2.js";
|
|
6
|
+
import "./chunk-UQOBOHKN.js";
|
|
7
7
|
export {
|
|
8
8
|
cwdRequire,
|
|
9
9
|
requireMemoryDeps
|
|
10
10
|
};
|
|
11
|
-
//# sourceMappingURL=require-deps-
|
|
11
|
+
//# sourceMappingURL=require-deps-RUXTMQUV.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
initStorage
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-ADZ45KHX.js";
|
|
5
|
+
import "./chunk-DXDOVWOA.js";
|
|
6
|
+
import "./chunk-RJEPJ4JE.js";
|
|
7
|
+
import "./chunk-WOC2PKT2.js";
|
|
8
8
|
import {
|
|
9
9
|
log
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-UQOBOHKN.js";
|
|
11
11
|
|
|
12
12
|
// src/commands/memory/subcommands/stats.ts
|
|
13
13
|
import { existsSync, statSync } from "fs";
|
|
@@ -18,7 +18,7 @@ function formatBytes(bytes) {
|
|
|
18
18
|
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
19
19
|
}
|
|
20
20
|
async function runStats(opts) {
|
|
21
|
-
const { requireMemoryDeps } = await import("./require-deps-
|
|
21
|
+
const { requireMemoryDeps } = await import("./require-deps-RUXTMQUV.js");
|
|
22
22
|
await requireMemoryDeps();
|
|
23
23
|
const ctx = initStorage(opts.dbPath);
|
|
24
24
|
try {
|
|
@@ -72,4 +72,4 @@ async function runStats(opts) {
|
|
|
72
72
|
export {
|
|
73
73
|
runStats
|
|
74
74
|
};
|
|
75
|
-
//# sourceMappingURL=stats-
|
|
75
|
+
//# sourceMappingURL=stats-DFV24AJW.js.map
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./chunk-3UJYOWGF.js";
|
|
10
10
|
import {
|
|
11
11
|
log
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-UQOBOHKN.js";
|
|
13
13
|
|
|
14
14
|
// src/commands/memory/subcommands/sync-clean.ts
|
|
15
15
|
import { confirm } from "@inquirer/prompts";
|
|
@@ -50,4 +50,4 @@ async function runSyncClean(project, opts) {
|
|
|
50
50
|
export {
|
|
51
51
|
runSyncClean
|
|
52
52
|
};
|
|
53
|
-
//# sourceMappingURL=sync-clean-
|
|
53
|
+
//# sourceMappingURL=sync-clean-GFX5F55E.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
parsePayload
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-F6SLV2FR.js";
|
|
5
5
|
import {
|
|
6
6
|
assertGhAvailable,
|
|
7
7
|
filenameToProject,
|
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
loadSyncConfig,
|
|
10
10
|
readGistFile
|
|
11
11
|
} from "./chunk-3UJYOWGF.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-YZ53W47Z.js";
|
|
13
13
|
import {
|
|
14
14
|
initStorage
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-ADZ45KHX.js";
|
|
16
|
+
import "./chunk-DXDOVWOA.js";
|
|
17
|
+
import "./chunk-RJEPJ4JE.js";
|
|
18
|
+
import "./chunk-WOC2PKT2.js";
|
|
19
19
|
import {
|
|
20
20
|
log
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-UQOBOHKN.js";
|
|
22
22
|
|
|
23
23
|
// src/commands/memory/subcommands/sync-status.ts
|
|
24
24
|
async function runSyncStatus() {
|
|
@@ -28,7 +28,7 @@ async function runSyncStatus() {
|
|
|
28
28
|
log.error("No sync gist found. Run `memory push` first.");
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const { requireMemoryDeps } = await import("./require-deps-
|
|
31
|
+
const { requireMemoryDeps } = await import("./require-deps-RUXTMQUV.js");
|
|
32
32
|
await requireMemoryDeps();
|
|
33
33
|
const ctx = initStorage();
|
|
34
34
|
try {
|
|
@@ -67,4 +67,4 @@ async function runSyncStatus() {
|
|
|
67
67
|
export {
|
|
68
68
|
runSyncStatus
|
|
69
69
|
};
|
|
70
|
-
//# sourceMappingURL=sync-status-
|
|
70
|
+
//# sourceMappingURL=sync-status-VXMDWDRG.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
MemoryRepo,
|
|
4
4
|
RelationRepo,
|
|
5
5
|
SearchRepo
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DXDOVWOA.js";
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_DECAY_PARAMS,
|
|
9
9
|
closeDatabase,
|
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
loadConfig,
|
|
12
12
|
migrate,
|
|
13
13
|
resolveDataDir
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-RJEPJ4JE.js";
|
|
15
|
+
import "./chunk-WOC2PKT2.js";
|
|
16
|
+
import "./chunk-UQOBOHKN.js";
|
|
17
17
|
|
|
18
18
|
// src/commands/memory/dashboard/tui.tsx
|
|
19
19
|
import { render } from "ink";
|
|
@@ -1306,4 +1306,4 @@ async function startTui(options) {
|
|
|
1306
1306
|
export {
|
|
1307
1307
|
startTui
|
|
1308
1308
|
};
|
|
1309
|
-
//# sourceMappingURL=tui-
|
|
1309
|
+
//# sourceMappingURL=tui-ELOJ37ZA.js.map
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/memory/config.ts","../src/commands/memory/storage/database.ts","../src/commands/memory/storage/migrations/001-initial.ts","../src/commands/memory/storage/migrations/002-add-project.ts","../src/commands/memory/storage/migrations/003-add-content-hash.ts","../src/commands/memory/storage/migrator.ts"],"sourcesContent":["import { z } from 'zod';\nimport { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { homedir } from 'node:os';\nimport type { DecayParams } from './types.js';\n\n// ── Config Schema ─────────────────────────────────────────────\n\nconst ConfigSchema = z.object({\n dataDir: z.string().default('~/.agentic-memory'),\n injectionBudget: z.number().int().min(100).max(20000).default(3000),\n consolidationInterval: z.number().int().min(1).default(10),\n enableReranker: z.boolean().default(true),\n logLevel: z.enum(['debug', 'info', 'warn', 'error']).default('warn'),\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\n\n// ── Defaults ──────────────────────────────────────────────────\n\nexport const DEFAULT_CONFIG: Config = {\n dataDir: '~/.agentic-memory',\n injectionBudget: 3000,\n consolidationInterval: 10,\n enableReranker: true,\n logLevel: 'warn',\n};\n\nexport const DEFAULT_DECAY_PARAMS: DecayParams = {\n tauByType: {\n working: 0, // cleared each session, tau irrelevant\n episodic: 30, // fast decay (was 60, cognitive science: unrehearsed episodes fade in ~30d)\n semantic: 540, // slow decay (was 365, extracted facts are stable for years)\n procedural: 730, // near-permanent\n pattern: 180, // medium decay\n },\n accessModifiers: [\n { maxCount: 3, multiplier: 1.0 },\n { maxCount: 10, multiplier: 2.0 },\n { maxCount: Infinity, multiplier: 4.0 },\n ],\n relationModifier: {\n connectedThreshold: 3,\n connectedMultiplier: 1.8, // higher tau = slower decay for connected memories\n isolatedMultiplier: 0.8, // lower tau = slightly faster decay for isolated memories\n highlyConnectedThreshold: 6,\n highlyConnectedMultiplier: 2.5, // near-immune: ~2.5x longer effective half-life\n },\n importanceFloor: 0.05,\n pruneThreshold: 0.1,\n pruneMinAgeDays: 90,\n};\n\nexport const SCORING_WEIGHTS = {\n text: 0.35,\n importance: 0.20,\n recency: 0.20,\n access: 0.10,\n context: 0.15,\n} as const;\n\n// ── Injection Algorithm Constants ──────────────────────────────\n\nexport const INJECTION_WEIGHTS = {\n context: 0.30,\n value: 0.25,\n importance: 0.20,\n recency: 0.15,\n typeBonus: 0.05,\n noise: 0.05,\n} as const;\n\nexport const TYPE_INJECTION_BONUS: Record<string, number> = {\n procedural: 1.0,\n pattern: 0.8,\n semantic: 0.6,\n episodic: 0.3,\n working: 0.0,\n};\n\nexport const RECENCY_HALF_LIFE: Record<string, number> = {\n working: 1,\n episodic: 7,\n pattern: 14,\n semantic: 30,\n procedural: 90,\n};\n\nexport const INJECTION_MIN_SCORE = 0.25;\nexport const INJECTION_COLD_START_THRESHOLD = 5;\nexport const INJECTION_COLD_START_RAMP_END = 20;\nexport const INJECTION_HEADER_TOKENS = 50;\nexport const INJECTION_MAX_SAME_TYPE_FULL = 2;\nexport const INJECTION_PINNED_BUDGET_PCT = 0.10;\n\n// ── Config Loader ─────────────────────────────────────────────\n\nexport function resolveDataDir(dataDir: string): string {\n if (dataDir.startsWith('~')) {\n return join(homedir(), dataDir.slice(1));\n }\n return dataDir;\n}\n\nexport function loadConfig(overrides?: Partial<Config>): Config {\n const envOverrides: Record<string, unknown> = {};\n\n const envBudget = process.env['AGENTIC_MEMORY_INJECTION_BUDGET'];\n if (envBudget !== undefined) {\n envOverrides['injectionBudget'] = parseInt(envBudget, 10);\n }\n\n const envLogLevel = process.env['AGENTIC_MEMORY_LOG_LEVEL'];\n if (envLogLevel !== undefined) {\n envOverrides['logLevel'] = envLogLevel;\n }\n\n const envDataDir = process.env['AGENTIC_MEMORY_DATA_DIR'];\n if (envDataDir !== undefined) {\n envOverrides['dataDir'] = envDataDir;\n }\n\n // Try loading config.json from data dir\n let fileConfig: Record<string, unknown> = {};\n const baseDir = resolveDataDir(overrides?.dataDir ?? envOverrides['dataDir'] as string ?? DEFAULT_CONFIG.dataDir);\n try {\n const raw = readFileSync(join(baseDir, 'config.json'), 'utf-8');\n fileConfig = JSON.parse(raw) as Record<string, unknown>;\n } catch (err) {\n const isNotFound = err instanceof Error && 'code' in err && (err as NodeJS.ErrnoException).code === 'ENOENT';\n if (!isNotFound) {\n // Malformed JSON or permissions error - warn, don't silently ignore\n console.error('[agentic-memory] Failed to load config.json:', err instanceof Error ? err.message : err);\n }\n }\n\n const merged = { ...DEFAULT_CONFIG, ...fileConfig, ...envOverrides, ...overrides };\n return ConfigSchema.parse(merged);\n}\n\n// ── Token Estimation ──────────────────────────────────────────\n\nexport function estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n","import type DatabaseConstructor from 'better-sqlite3';\nimport { resolveDataDir } from '../config.js';\nimport { mkdirSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { cwdRequire } from '../utils/require-deps.js';\n\nexport interface DatabaseOptions {\n readonly dbPath?: string; // full path override (e.g. ':memory:' for tests)\n readonly dataDir?: string; // resolved data dir (default ~/.agentic-memory)\n}\n\nexport function createDatabase(options: DatabaseOptions = {}): DatabaseConstructor.Database {\n const dbPath = options.dbPath ?? resolveDbPath(options.dataDir);\n\n if (dbPath !== ':memory:') {\n mkdirSync(dirname(dbPath), { recursive: true });\n }\n\n const Database = cwdRequire('better-sqlite3') as typeof DatabaseConstructor;\n const sqliteVec = cwdRequire('sqlite-vec') as { load: (db: DatabaseConstructor.Database) => void };\n\n const db = new Database(dbPath);\n\n // Load sqlite-vec extension\n sqliteVec.load(db);\n\n // Configure PRAGMAs (order matters: foreign_keys before any ops, journal_mode is persistent)\n db.pragma('journal_mode = WAL');\n db.pragma('busy_timeout = 5000');\n db.pragma('foreign_keys = ON');\n db.pragma('cache_size = -64000');\n db.pragma('mmap_size = 268435456');\n db.pragma('synchronous = NORMAL');\n db.pragma('temp_store = MEMORY');\n db.pragma('journal_size_limit = 33554432');\n\n return db;\n}\n\nexport function closeDatabase(db: DatabaseConstructor.Database): void {\n try {\n db.pragma('wal_checkpoint(TRUNCATE)');\n } catch {\n // Checkpoint may fail on :memory: - that's fine\n }\n db.close();\n}\n\nfunction resolveDbPath(dataDir?: string): string {\n const dir = resolveDataDir(dataDir ?? '~/.agentic-memory');\n return join(dir, 'memory.db');\n}\n","import type Database from 'better-sqlite3';\n\nexport const version = 1;\n\nexport function up(db: Database.Database): void {\n db.exec(`\n CREATE TABLE IF NOT EXISTS meta (\n key TEXT PRIMARY KEY,\n value TEXT\n );\n\n CREATE TABLE IF NOT EXISTS memories (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL CHECK(type IN ('episodic','semantic','procedural','working','pattern')),\n title TEXT,\n content TEXT NOT NULL,\n context TEXT,\n source TEXT CHECK(source IN ('manual','session_end','consolidation','hook','import')),\n tags TEXT NOT NULL DEFAULT '[]',\n importance REAL NOT NULL DEFAULT 0.5 CHECK(importance >= 0.0 AND importance <= 1.0),\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n access_count INTEGER NOT NULL DEFAULT 0 CHECK(access_count >= 0),\n last_accessed TEXT,\n injection_count INTEGER NOT NULL DEFAULT 0 CHECK(injection_count >= 0),\n embedding BLOB\n );\n\n CREATE TABLE IF NOT EXISTS relations (\n source_id TEXT NOT NULL REFERENCES memories(id) ON DELETE CASCADE,\n target_id TEXT NOT NULL REFERENCES memories(id) ON DELETE CASCADE,\n relation_type TEXT NOT NULL CHECK(relation_type IN (\n 'relates_to','depends_on','contradicts','extends','implements','derived_from'\n )),\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n PRIMARY KEY (source_id, target_id, relation_type)\n );\n\n -- FTS5 external content (no data duplication)\n CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(\n title, content, tags,\n content=memories,\n content_rowid=rowid,\n tokenize='porter unicode61'\n );\n\n -- FTS5 sync triggers\n CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN\n INSERT INTO memories_fts(rowid, title, content, tags)\n VALUES (new.rowid, new.title, new.content, new.tags);\n END;\n\n CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN\n INSERT INTO memories_fts(memories_fts, rowid, title, content, tags)\n VALUES ('delete', old.rowid, old.title, old.content, old.tags);\n END;\n\n CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN\n INSERT INTO memories_fts(memories_fts, rowid, title, content, tags)\n VALUES ('delete', old.rowid, old.title, old.content, old.tags);\n INSERT INTO memories_fts(rowid, title, content, tags)\n VALUES (new.rowid, new.title, new.content, new.tags);\n END;\n\n -- Vector search (synced manually in application code)\n CREATE VIRTUAL TABLE IF NOT EXISTS memories_vec USING vec0(\n memory_id TEXT PRIMARY KEY,\n embedding float[384] distance_metric=cosine\n );\n\n -- Indexes\n CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);\n CREATE INDEX IF NOT EXISTS idx_memories_importance ON memories(importance);\n CREATE INDEX IF NOT EXISTS idx_memories_created_at ON memories(created_at);\n CREATE INDEX IF NOT EXISTS idx_relations_target ON relations(target_id);\n `);\n}\n","import type Database from 'better-sqlite3';\n\nexport const version = 2;\n\nexport function up(db: Database.Database): void {\n db.exec(`\n ALTER TABLE memories ADD COLUMN project TEXT;\n CREATE INDEX IF NOT EXISTS idx_memories_project ON memories(project);\n `);\n}\n","import { createHash } from 'node:crypto';\nimport type Database from 'better-sqlite3';\n\nexport const version = 3;\n\nexport function up(db: Database.Database): void {\n db.exec('ALTER TABLE memories ADD COLUMN content_hash TEXT');\n\n // Backfill existing rows with SHA-256 hashes\n const rows = db.prepare('SELECT id, content FROM memories ORDER BY updated_at DESC').all() as { id: string; content: string }[];\n const update = db.prepare('UPDATE memories SET content_hash = ? WHERE id = ?');\n const remove = db.prepare('DELETE FROM memories WHERE id = ?');\n\n // Track seen hashes — keep the most recently updated, remove older duplicates\n const seen = new Set<string>();\n for (const row of rows) {\n const hash = createHash('sha256').update(row.content).digest('hex');\n if (seen.has(hash)) {\n remove.run(row.id);\n } else {\n seen.add(hash);\n update.run(hash, row.id);\n }\n }\n\n db.exec('CREATE UNIQUE INDEX IF NOT EXISTS idx_memories_content_hash ON memories(content_hash)');\n}\n","import type Database from 'better-sqlite3';\nimport * as migration001 from './migrations/001-initial.js';\nimport * as migration002 from './migrations/002-add-project.js';\nimport * as migration003 from './migrations/003-add-content-hash.js';\n\ninterface Migration {\n readonly version: number;\n readonly up: (db: Database.Database) => void;\n}\n\nconst migrations: readonly Migration[] = [\n migration001,\n migration002,\n migration003,\n];\n\nexport function getSchemaVersion(db: Database.Database): number {\n try {\n const row = db.prepare(\"SELECT value FROM meta WHERE key = 'schema_version'\").get() as\n { value: string } | undefined;\n return row ? parseInt(row.value, 10) : 0;\n } catch {\n return 0;\n }\n}\n\nexport function migrate(db: Database.Database): void {\n const current = getSchemaVersion(db);\n const pending = migrations.filter(m => m.version > current);\n\n if (pending.length === 0) return;\n\n const runMigrations = db.transaction(() => {\n for (const m of pending) {\n m.up(db);\n db.prepare(\"INSERT OR REPLACE INTO meta (key, value) VALUES ('schema_version', ?)\")\n .run(String(m.version));\n }\n });\n\n runMigrations();\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,SAAS;AAClB,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AACrB,SAAS,eAAe;AAKxB,IAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,SAAS,EAAE,OAAO,EAAE,QAAQ,mBAAmB;AAAA,EAC/C,iBAAiB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,IAAI,GAAK,EAAE,QAAQ,GAAI;AAAA,EAClE,uBAAuB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE;AAAA,EACzD,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACxC,UAAU,EAAE,KAAK,CAAC,SAAS,QAAQ,QAAQ,OAAO,CAAC,EAAE,QAAQ,MAAM;AACrE,CAAC;AAMM,IAAM,iBAAyB;AAAA,EACpC,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,uBAAuB;AAAA,EACvB,gBAAgB;AAAA,EAChB,UAAU;AACZ;AAEO,IAAM,uBAAoC;AAAA,EAC/C,WAAW;AAAA,IACT,SAAS;AAAA;AAAA,IACT,UAAU;AAAA;AAAA,IACV,UAAU;AAAA;AAAA,IACV,YAAY;AAAA;AAAA,IACZ,SAAS;AAAA;AAAA,EACX;AAAA,EACA,iBAAiB;AAAA,IACf,EAAE,UAAU,GAAG,YAAY,EAAI;AAAA,IAC/B,EAAE,UAAU,IAAI,YAAY,EAAI;AAAA,IAChC,EAAE,UAAU,UAAU,YAAY,EAAI;AAAA,EACxC;AAAA,EACA,kBAAkB;AAAA,IAChB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AAC7B,aAAW,OAAO,MAAM;AACtB,UAAM,OAAO,WAAW,QAAQ,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,KAAK;AAClE,QAAI,KAAK,IAAI,IAAI,GAAG;AAClB,aAAO,IAAI,IAAI,EAAE;AAAA,IACnB,OAAO;AACL,WAAK,IAAI,IAAI;AACb,aAAO,IAAI,MAAM,IAAI,EAAE;AAAA,IACzB;AAAA,EACF;AAEA,KAAG,KAAK,uFAAuF;AACjG;;;AChBA,IAAM,aAAmC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,iBAAiB,IAA+B;AAC9D,MAAI;AACF,UAAM,MAAM,GAAG,QAAQ,qDAAqD,EAAE,IAAI;AAElF,WAAO,MAAM,SAAS,IAAI,OAAO,EAAE,IAAI;AAAA,EACzC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,QAAQ,IAA6B;AACnD,QAAM,UAAU,iBAAiB,EAAE;AACnC,QAAM,UAAU,WAAW,OAAO,OAAK,EAAE,UAAU,OAAO;AAE1D,MAAI,QAAQ,WAAW,EAAG;AAE1B,QAAM,gBAAgB,GAAG,YAAY,MAAM;AACzC,eAAW,KAAK,SAAS;AACvB,QAAE,GAAG,EAAE;AACP,SAAG,QAAQ,uEAAuE,EAC/E,IAAI,OAAO,EAAE,OAAO,CAAC;AAAA,IAC1B;AAAA,EACF,CAAC;AAED,gBAAc;AAChB;","names":["join","join","up","version","up","version"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/memory/types.ts"],"sourcesContent":["import { z } from 'zod';\n\n// ── MCP Harness Coercion ─────────────────────────────────────\n// Claude Code's MCP harness sometimes serializes arrays as JSON-encoded strings\n// (e.g. tags arrives as '[\"tag1\",\"tag2\"]' instead of [\"tag1\",\"tag2\"]).\n// This preprocess step accepts both forms.\nexport const coerceStringArray = z.preprocess((val) => {\n if (Array.isArray(val)) return val;\n if (typeof val === 'string') {\n try {\n const parsed = JSON.parse(val);\n if (Array.isArray(parsed)) return parsed;\n } catch { /* not JSON, treat as single-element array */ }\n return val.trim() ? [val] : [];\n }\n return val;\n}, z.array(z.string()));\n\n// ── Memory Types ──────────────────────────────────────────────\n\nexport const MEMORY_TYPES = ['working', 'episodic', 'semantic', 'procedural', 'pattern'] as const;\nexport type MemoryType = typeof MEMORY_TYPES[number];\n\nexport const MEMORY_SOURCES = ['manual', 'session_end', 'consolidation', 'hook', 'import'] as const;\nexport type MemorySource = typeof MEMORY_SOURCES[number];\n\nexport const RELATION_TYPES = [\n 'relates_to', 'depends_on', 'contradicts', 'extends', 'implements', 'derived_from',\n] as const;\nexport type RelationType = typeof RELATION_TYPES[number];\n\n// ── Core Entities ─────────────────────────────────────────────\n\nexport interface Memory {\n readonly id: string;\n readonly type: MemoryType;\n readonly title: string | null;\n readonly content: string;\n readonly context: string | null;\n readonly source: MemorySource | null;\n readonly project: string | null;\n readonly tags: readonly string[];\n readonly importance: number;\n readonly createdAt: string;\n readonly updatedAt: string;\n readonly accessCount: number;\n readonly lastAccessed: string | null;\n readonly injectionCount: number;\n}\n\nexport interface Relation {\n readonly sourceId: string;\n readonly targetId: string;\n readonly relationType: RelationType;\n readonly createdAt: string;\n}\n\n// ── Search Types ──────────────────────────────────────────────\n\nexport interface SearchResult {\n readonly memory: Memory;\n readonly score: number;\n readonly explanation: string;\n}\n\nexport interface FtsMatch {\n readonly rowid: number;\n readonly memoryId: string;\n readonly rank: number;\n}\n\nexport interface ScoredCandidate {\n readonly memoryId: string;\n readonly textScore: number;\n readonly importanceScore: number;\n readonly recencyScore: number;\n readonly accessScore: number;\n readonly contextScore: number;\n readonly composite: number;\n}\n\n// ── Decay Parameters ──────────────────────────────────────────\n\nexport interface DecayParams {\n readonly tauByType: Record<MemoryType, number>;\n readonly accessModifiers: readonly { readonly maxCount: number; readonly multiplier: number }[];\n readonly relationModifier: {\n readonly connectedThreshold: number;\n readonly connectedMultiplier: number;\n readonly isolatedMultiplier: number;\n readonly highlyConnectedThreshold: number;\n readonly highlyConnectedMultiplier: number;\n };\n readonly importanceFloor: number;\n readonly pruneThreshold: number;\n readonly pruneMinAgeDays: number;\n}\n\n// ── Input Schemas (for MCP tools) ─────────────────────────────\n\nexport const StoreInputSchema = z.object({\n type: z.enum(MEMORY_TYPES),\n content: z.string().min(1),\n title: z.string().max(200).optional(),\n tags: coerceStringArray.pipe(z.array(z.string()).max(20)).default([]),\n importance: z.number().min(0).max(1).default(0.5),\n context: z.string().optional(),\n source: z.enum(MEMORY_SOURCES).default('manual'),\n project: z.string().max(200).optional(),\n});\nexport type StoreInput = z.infer<typeof StoreInputSchema>;\n\nexport const SearchInputSchema = z.object({\n query: z.string().min(1).max(500),\n id: z.string().optional(),\n type: z.enum(MEMORY_TYPES).optional(),\n tags: coerceStringArray.pipe(z.array(z.string()).max(10)).optional(),\n limit: z.number().int().min(1).max(50).default(10),\n min_importance: z.number().min(0).max(1).default(0),\n project: z.string().max(200).optional(),\n});\nexport type SearchInput = z.infer<typeof SearchInputSchema>;\n\nexport const ForgetInputSchema = z.object({\n id: z.string(),\n hard_delete: z.boolean().default(false),\n});\nexport type ForgetInput = z.infer<typeof ForgetInputSchema>;\n\nexport const RelateInputSchema = z.object({\n source_id: z.string(),\n target_id: z.string(),\n relation_type: z.enum(RELATION_TYPES),\n});\nexport type RelateInput = z.infer<typeof RelateInputSchema>;\n\n// ── Sync Types ───────────────────────────────────────────────\n\nexport interface SyncPayload {\n readonly version: number;\n readonly machine_id: string;\n readonly pushed_at: string;\n readonly memories: readonly SyncMemoryRow[];\n readonly relations: readonly SyncRelationRow[];\n}\n\nexport interface SyncMemoryRow {\n readonly id: string;\n readonly type: MemoryType;\n readonly title: string | null;\n readonly content: string;\n readonly context: string | null;\n readonly source: MemorySource | null;\n readonly project: string | null;\n readonly tags: readonly string[];\n readonly importance: number;\n readonly access_count: number;\n readonly injection_count: number;\n readonly created_at: string;\n readonly updated_at: string;\n readonly last_accessed: string | null;\n}\n\nexport interface SyncRelationRow {\n readonly source_id: string;\n readonly target_id: string;\n readonly relation_type: RelationType;\n readonly created_at: string;\n}\n\nexport const SyncPayloadSchema = z.object({\n version: z.number(),\n machine_id: z.string(),\n pushed_at: z.string(),\n memories: z.array(z.object({\n id: z.string(),\n type: z.enum(MEMORY_TYPES),\n title: z.string().nullable(),\n content: z.string(),\n context: z.string().nullable(),\n source: z.enum(MEMORY_SOURCES).nullable(),\n project: z.string().nullable(),\n tags: z.array(z.string()),\n importance: z.number(),\n access_count: z.number(),\n injection_count: z.number(),\n created_at: z.string(),\n updated_at: z.string(),\n last_accessed: z.string().nullable(),\n })),\n relations: z.array(z.object({\n source_id: z.string(),\n target_id: z.string(),\n relation_type: z.enum(RELATION_TYPES),\n created_at: z.string(),\n })),\n});\n\nexport interface SyncConfig {\n readonly gistId: string;\n}\n\nexport interface MergeResult {\n readonly inserted: number;\n readonly updated: number;\n readonly relationsAdded: number;\n}\n\n// ── Stats ─────────────────────────────────────────────────────\n\nexport interface MemoryStats {\n readonly totalMemories: number;\n readonly byType: Record<MemoryType, number>;\n readonly totalRelations: number;\n readonly dbSizeBytes: number;\n readonly oldestMemory: string | null;\n readonly newestMemory: string | null;\n readonly topInjected: readonly { readonly id: string; readonly title: string | null; readonly injectionCount: number }[];\n}\n"],"mappings":";;;AAAA,SAAS,SAAS;AAMX,IAAM,oBAAoB,EAAE,WAAW,CAAC,QAAQ;AACrD,MAAI,MAAM,QAAQ,GAAG,EAAG,QAAO;AAC/B,MAAI,OAAO,QAAQ,UAAU;AAC3B,QAAI;AACF,YAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,UAAI,MAAM,QAAQ,MAAM,EAAG,QAAO;AAAA,IACpC,QAAQ;AAAA,IAAgD;AACxD,WAAO,IAAI,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;AAAA,EAC/B;AACA,SAAO;AACT,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAIf,IAAM,eAAe,CAAC,WAAW,YAAY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|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/memory/utils/sync-merge.ts"],"sourcesContent":["import { SyncPayloadSchema } from '../types.js';\nimport type { Memory, SyncPayload, SyncMemoryRow, MergeResult, RelationType } from '../types.js';\nimport type { MemoryRepo } from '../storage/memory-repo.js';\nimport type { RelationRepo } from '../storage/relation-repo.js';\n\nfunction memoryToSyncRow(m: Memory): SyncMemoryRow {\n return {\n id: m.id,\n type: m.type,\n title: m.title,\n content: m.content,\n context: m.context,\n source: m.source,\n project: m.project,\n tags: [...m.tags],\n importance: m.importance,\n access_count: m.accessCount,\n injection_count: m.injectionCount,\n created_at: m.createdAt,\n updated_at: m.updatedAt,\n last_accessed: m.lastAccessed,\n };\n}\n\nexport { memoryToSyncRow };\n\nexport function parsePayload(raw: string | null): SyncPayload | null {\n if (!raw || raw === 'null') return null;\n try { return SyncPayloadSchema.parse(JSON.parse(raw)); }\n catch { return null; }\n}\n\nexport function mergeFromRemote(\n memoryRepo: MemoryRepo,\n relationRepo: RelationRepo,\n payload: SyncPayload,\n): MergeResult {\n let inserted = 0;\n let updated = 0;\n let relationsAdded = 0;\n\n const memories = payload.memories;\n\n for (const remote of memories) {\n const local = memoryRepo.getById(remote.id);\n if (!local) {\n memoryRepo.upsertFromSync(remote);\n inserted++;\n } else if (remote.updated_at > local.updatedAt) {\n memoryRepo.upsertFromSync(remote);\n updated++;\n }\n }\n\n const localIds = new Set(memoryRepo.getAll().map((m) => m.id));\n const relations = payload.relations.filter(\n (r) => localIds.has(r.source_id) && localIds.has(r.target_id),\n );\n\n for (const rel of relations) {\n const added = relationRepo.create(\n rel.source_id,\n rel.target_id,\n rel.relation_type as RelationType,\n );\n if (added) relationsAdded++;\n }\n\n return { inserted, updated, relationsAdded };\n}\n"],"mappings":";;;;;;AAKA,SAAS,gBAAgB,GAA0B;AACjD,SAAO;AAAA,IACL,IAAI,EAAE;AAAA,IACN,MAAM,EAAE;AAAA,IACR,OAAO,EAAE;AA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