@mnemonik/shared 1.0.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/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @mnemonik/shared - Shared constants and utilities
3
+ *
4
+ * This package provides a single source of truth for constants
5
+ * that need to be shared across Mnemonik packages.
6
+ */
7
+
8
+ export { MCP_INSTRUCTIONS, MCP_INSTRUCTIONS_RAW, getMcpInstructions } from './instructions.js';
9
+ export { USAGE_GUIDE } from './usageGuide.js';
10
+ export { CodeScanner, type CodeChunk, type ScanOptions } from './codeScanner.js';
11
+ export {
12
+ FileSystemReader,
13
+ getFileSystemReader,
14
+ type ScanFilesResult,
15
+ type ChangedFilesResult,
16
+ type FileData,
17
+ } from './FileSystemReader.js';
@@ -0,0 +1,55 @@
1
+ /**
2
+ * MCP Instructions - Persistent agent guidance
3
+ *
4
+ * This is the SINGLE SOURCE OF TRUTH for MCP instructions.
5
+ * Shared instruction content imported by the server.
6
+ *
7
+ * Version: 2.92
8
+ * Updated: 2026-02-24
9
+ *
10
+ * v2.93: Code mode permanent — all memory operations via memory_tools sandbox.
11
+ * memory_add, file_context etc. are now mnemonik.* methods, not standalone tools.
12
+ *
13
+ * v2.92: Zero-cooperation rewrite. Context auto-loads if session_bootstrap is skipped.
14
+ * Session summaries are auto-saved if agent doesn't call mnemonik.memory_add().
15
+ * Instructions drastically simplified — the server handles the workflow now.
16
+ *
17
+ * v2.80: Token-optimised rewrite (superseded by v2.92).
18
+ */
19
+
20
+ const INSTRUCTIONS_CONTENT = `You have Mnemonik, a persistent memory system for this project.
21
+
22
+ First call, every session: session_bootstrap. Read the mnemonik skill (from available_skills) for the full workflow.
23
+ After bootstrap: execute _directive.message actions immediately (scanner daemon check is mandatory).
24
+
25
+ Proactively call memory_search before starting new work — avoids rediscovering known patterns and contradicting past decisions.
26
+ Proactively call file_context before editing any file — loads past bugs, decisions, and gotchas for that file.
27
+ Proactively call checkpoint after making changes or decisions worth keeping — your context is ephemeral and checkpoint is the only way decisions survive across sessions and context compaction. Do not wait for the user to say "done" or "thanks".
28
+
29
+ When mnemonik.file_context({ filePaths, cwd }) returns linkedDocs with driftStatus 'stale', update docs then call mnemonik.docs({ action: 'resolve', docPath, cwd }).
30
+
31
+ Skip: formatting-only, trivial one-line, mechanical refactors, git ops, tests.
32
+ Save: architectural decisions, bug root causes, user preferences, discovered patterns, multi-file changes.`;
33
+
34
+ /**
35
+ * Get MCP instructions, respecting MNEMONIK_INSTRUCTIONS_ENABLED env var.
36
+ * Set MNEMONIK_INSTRUCTIONS_ENABLED=false to disable for testing.
37
+ */
38
+ export function getMcpInstructions(): string {
39
+ if (typeof process !== 'undefined' && process.env?.MNEMONIK_INSTRUCTIONS_ENABLED === 'false') {
40
+ return '';
41
+ }
42
+ return INSTRUCTIONS_CONTENT;
43
+ }
44
+
45
+ /**
46
+ * Raw instructions content (always returns the content, ignores env var).
47
+ * Use getMcpInstructions() for production code.
48
+ */
49
+ export const MCP_INSTRUCTIONS_RAW = INSTRUCTIONS_CONTENT;
50
+
51
+ /**
52
+ * Default export for convenience.
53
+ * Note: This respects the MNEMONIK_INSTRUCTIONS_ENABLED env var.
54
+ */
55
+ export const MCP_INSTRUCTIONS = getMcpInstructions();
package/src/logger.ts ADDED
@@ -0,0 +1,7 @@
1
+ export const debug = (_msg: string, _ctx?: Record<string, unknown>): void => {};
2
+ export const info = (msg: string, ctx?: Record<string, unknown>): void => {
3
+ console.log(`[info] ${msg}`, ctx ? JSON.stringify(ctx) : '');
4
+ };
5
+ export const warn = (msg: string, ctx?: Record<string, unknown>): void => {
6
+ console.warn(`[warn] ${msg}`, ctx ? JSON.stringify(ctx) : '');
7
+ };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Mnemonik Usage Guide - Procedural workflow guidance for agents
3
+ *
4
+ * This is the SINGLE SOURCE OF TRUTH for the usage guide.
5
+ * Shared usage guide content imported by the server.
6
+ *
7
+ * Version: 2.80
8
+ * Updated: 2026-02-20 - Aligned with instructions/rules/skill v2.80
9
+ *
10
+ * This guide focuses on HOW to use Mnemonik effectively, not WHAT tools exist.
11
+ * Tool schemas already tell agents what's available - they need the workflow.
12
+ */
13
+
14
+ export const USAGE_GUIDE = `# Mnemonik Workflow Guide (v2.80)
15
+
16
+ ## Workflow
17
+
18
+ session_bootstrap → memory_search → file_context → [work] → memory_add → memory_state
19
+
20
+ ## Tool Selection by Stage
21
+
22
+ ### Session start
23
+ - session_bootstrap: loads context, policies, pending tasks (call once, first thing)
24
+ - memory_search: search by task domain; set workflowContext (feature_implementation, debugging, exploration, policy_review)
25
+ - projects: resolve project IDs if context unclear
26
+ - policy: review safety rules
27
+
28
+ ### Before editing files
29
+ - file_context: fetch memories for the file — call for EVERY file you edit
30
+ - memory_search: second search scoped to file/module if needed
31
+ - docs(action: 'links'): check doc couplings for the file
32
+
33
+ ### During implementation
34
+ - memory_get: retrieve specific memory by id
35
+ - memory_update: refine memory created this session
36
+ - memory_info: query history, provenance, confidence breakdown, links, graph
37
+ - assist: get tool guidance if uncertain
38
+
39
+ ### After significant work
40
+ - memory_add: save decisions, outcomes, patterns, bug root causes
41
+ - memory_state: reinforce (memory helped), supersede (replace outdated), deprecate, penalize, dispute
42
+ - tasks: mark tasks in progress or complete
43
+ - docs(action: 'drift'): check for stale documentation after code changes
44
+ - docs(action: 'resolve'): mark stale docs as fixed after updating them
45
+
46
+ ### Diagnostics
47
+ - doctor: when tool calls fail or behavior is inconsistent
48
+ - scanner: refresh embeddings, trigger scans, check drift
49
+
50
+ ## Skip conditions
51
+
52
+ Skip memory tools for: formatting-only edits, trivial one-line changes, mechanical refactors, git operations, running tests.
53
+
54
+ ## Completion gate
55
+
56
+ Never tell the user significant work is done without calling memory_add first in the same response. Changes made + responding next = completion. "Progress updates" count.
57
+
58
+ ## Memory search tips
59
+
60
+ - Query should include task intent + key entities
61
+ - Set workflowContext when you know the phase
62
+ - Use currentFile to boost file-linked memories
63
+ - Use filterOnly:true only for narrow filters (no embedding, requires >=1 filter)
64
+
65
+ ## Proactive heuristics
66
+
67
+ - Long sessions: re-run memory_search after switching topics
68
+ - Conflicting info: use memory_state to supersede/dispute
69
+ - High-impact changes: save memory immediately after verification
70
+ - When file_context returns linkedDocs with driftStatus 'stale': update docs then docs(action: 'resolve')
71
+
72
+ ## Anti-fade (every ~10 tool calls)
73
+
74
+ Check: (1) memory_search before work? (2) file_context before edit? (3) memory_add after completing? No session_bootstrap? Call it now.
75
+ `;
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }