toon-memory 3.2.0 → 3.3.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 +6 -0
- package/dist/cli/setup.js +50 -8
- package/mcp/server.js +44858 -29673
- package/package.json +5 -2
- package/src/cli/constants.ts +4 -0
- package/src/mcp/prompts.ts +1 -1
- package/src/mcp/resources.ts +21 -2
- package/src/mcp/server.ts +22 -3
- package/src/mcp/tools.ts +31 -1
- package/src/viewer/d3.v7.min.js +2 -0
- package/src/viewer/data.ts +1 -2
- package/src/viewer/html.ts +48 -6
package/src/viewer/data.ts
CHANGED
|
@@ -6,8 +6,7 @@ export function buildViewerData(): ViewerData {
|
|
|
6
6
|
const data = readMemory()
|
|
7
7
|
const entries = parseEntries(data)
|
|
8
8
|
if (entries.length === 0) {
|
|
9
|
-
|
|
10
|
-
process.exit(0)
|
|
9
|
+
return { nodes: [], edges: [], categories: {}, tagCounts: {}, totalEntries: 0 }
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
const graph = buildGraph(entries)
|
package/src/viewer/html.ts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
import { readFileSync } from "fs"
|
|
2
|
+
import { resolve, dirname } from "path"
|
|
3
|
+
import { fileURLToPath } from "url"
|
|
1
4
|
import { ViewerData, COLORS } from "./types"
|
|
2
5
|
|
|
6
|
+
const d3Src = (() => {
|
|
7
|
+
try {
|
|
8
|
+
const dir = dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
return readFileSync(resolve(dir, "../src/viewer/d3.v7.min.js"), "utf-8")
|
|
10
|
+
} catch {
|
|
11
|
+
try {
|
|
12
|
+
const dir = dirname(fileURLToPath(import.meta.url))
|
|
13
|
+
return readFileSync(resolve(dir, "d3.v7.min.js"), "utf-8")
|
|
14
|
+
} catch {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
})()
|
|
19
|
+
|
|
3
20
|
export function generateHtml(viewerData: ViewerData): string {
|
|
4
21
|
const jsonData = JSON.stringify(viewerData)
|
|
22
|
+
const d3Tag = d3Src
|
|
23
|
+
? `<script>${d3Src}<\/script>`
|
|
24
|
+
: `<script src="https://d3js.org/d3.v7.min.js"><\/script>`
|
|
5
25
|
|
|
6
26
|
return `<!DOCTYPE html>
|
|
7
27
|
<html lang="en">
|
|
@@ -9,7 +29,8 @@ export function generateHtml(viewerData: ViewerData): string {
|
|
|
9
29
|
<meta charset="UTF-8">
|
|
10
30
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
31
|
<title>toon-memory viewer</title>
|
|
12
|
-
<script
|
|
32
|
+
<script>window.__MCP_UI__=window.__MCP_UI__||{invoke:()=>Promise.resolve({})}<\/script>
|
|
33
|
+
${d3Tag}
|
|
13
34
|
<style>
|
|
14
35
|
*{box-sizing:border-box;margin:0;padding:0}
|
|
15
36
|
:root{
|
|
@@ -19,7 +40,7 @@ export function generateHtml(viewerData: ViewerData): string {
|
|
|
19
40
|
--pink:#ec4899;--cyan:#06b6d4;
|
|
20
41
|
}
|
|
21
42
|
html,body{height:100%;font-family:system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text);overflow:hidden}
|
|
22
|
-
.app{display:grid;grid-template-rows:auto 1fr;height:
|
|
43
|
+
.app{display:grid;grid-template-rows:auto 1fr;height:100%}
|
|
23
44
|
header{display:flex;align-items:center;justify-content:space-between;padding:0.75rem 1.5rem;border-bottom:1px solid var(--border);background:var(--bg2)}
|
|
24
45
|
header h1{font-size:1.1rem;font-weight:700;background:linear-gradient(135deg,var(--brand),var(--pink));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
|
|
25
46
|
header .meta{display:flex;gap:1rem;font-size:0.8rem;color:var(--muted)}
|
|
@@ -57,7 +78,7 @@ header .meta span{display:flex;align-items:center;gap:0.3rem}
|
|
|
57
78
|
.tab-content{flex:1;overflow:hidden;position:relative}
|
|
58
79
|
.tab-panel{display:none;width:100%;height:100%;overflow:auto}
|
|
59
80
|
.tab-panel.active{display:block}
|
|
60
|
-
.graph-container{width:100%;height:100%;background:var(--bg);position:relative}
|
|
81
|
+
.graph-container{width:100%;height:100%;min-height:300px;background:var(--bg);position:relative}
|
|
61
82
|
.graph-container::before{content:'';position:absolute;inset:0;background-image:radial-gradient(var(--border) 1px,transparent 1px);background-size:24px 24px;opacity:0.3;pointer-events:none;z-index:0}
|
|
62
83
|
.graph-container svg{width:100%;height:100%;position:relative;z-index:1}
|
|
63
84
|
.node-circle{cursor:pointer;transition:r 0.2s ease,opacity 0.2s ease,filter 0.2s ease,stroke 0.2s ease}
|
|
@@ -445,8 +466,11 @@ function renderTimeline() {
|
|
|
445
466
|
// --- Graph ---
|
|
446
467
|
const graph = (function() {
|
|
447
468
|
const container = document.getElementById('graphContainer');
|
|
448
|
-
|
|
449
|
-
const
|
|
469
|
+
let _impl = null;
|
|
470
|
+
const safe = (name, ...args) => { if (_impl && _impl[name]) return _impl[name](...args); };
|
|
471
|
+
const initGraph = () => {
|
|
472
|
+
const width = Math.max(container.clientWidth, 400);
|
|
473
|
+
const height = Math.max(container.clientHeight, 300);
|
|
450
474
|
const svg = d3.select(container).append('svg').attr('width', '100%').attr('height', '100%');
|
|
451
475
|
|
|
452
476
|
const defs = svg.append('defs');
|
|
@@ -820,12 +844,25 @@ const graph = (function() {
|
|
|
820
844
|
selectEntry(d); hideTooltip();
|
|
821
845
|
});
|
|
822
846
|
|
|
823
|
-
|
|
847
|
+
_impl = { highlightNode, highlightSearch, centerOn, resize: () => {
|
|
824
848
|
const w = container.clientWidth;
|
|
825
849
|
const h = container.clientHeight;
|
|
826
850
|
simulation.force('center', d3.forceCenter(w / 2, h / 2).strength(centerStrength));
|
|
827
851
|
simulation.alpha(0.3).restart();
|
|
828
852
|
}};
|
|
853
|
+
};
|
|
854
|
+
if (container.clientWidth > 0 && container.clientHeight > 0) {
|
|
855
|
+
initGraph();
|
|
856
|
+
} else {
|
|
857
|
+
const ro = new ResizeObserver(() => {
|
|
858
|
+
if (container.clientWidth > 0 && container.clientHeight > 0) {
|
|
859
|
+
ro.disconnect();
|
|
860
|
+
initGraph();
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
ro.observe(container);
|
|
864
|
+
}
|
|
865
|
+
return { highlightNode: (...a) => safe('highlightNode', ...a), highlightSearch: (...a) => safe('highlightSearch', ...a), centerOn: (...a) => safe('centerOn', ...a), resize: (...a) => safe('resize', ...a) };
|
|
829
866
|
})();
|
|
830
867
|
|
|
831
868
|
// --- Keyboard Shortcuts ---
|
|
@@ -874,6 +911,11 @@ document.getElementById('reloadBtn').addEventListener('click', () => location.re
|
|
|
874
911
|
document.addEventListener('keydown', (e) => {
|
|
875
912
|
if (e.key === 'r' && !e.metaKey && !e.ctrlKey && !e.target.closest('input,textarea')) location.reload();
|
|
876
913
|
});
|
|
914
|
+
|
|
915
|
+
// MCP Apps: expose a global so the host can detect the viewer is ready
|
|
916
|
+
if (window.parent !== window) {
|
|
917
|
+
console.log('toon-memory viewer running in MCP Apps iframe');
|
|
918
|
+
}
|
|
877
919
|
<\/script>
|
|
878
920
|
</body>
|
|
879
921
|
</html>`
|