minnimemory 1.0.0-beta.1

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.
Files changed (59) hide show
  1. package/LICENSE +39 -0
  2. package/README.md +824 -0
  3. package/dist/bench.d.ts +98 -0
  4. package/dist/bench.js +142 -0
  5. package/dist/benchReport.d.ts +12 -0
  6. package/dist/benchReport.js +128 -0
  7. package/dist/bounds.d.ts +40 -0
  8. package/dist/bounds.js +44 -0
  9. package/dist/cli.d.ts +15 -0
  10. package/dist/cli.js +503 -0
  11. package/dist/compile.d.ts +187 -0
  12. package/dist/compile.js +516 -0
  13. package/dist/discover.d.ts +125 -0
  14. package/dist/discover.js +520 -0
  15. package/dist/doctor.d.ts +9 -0
  16. package/dist/doctor.js +67 -0
  17. package/dist/episodic.d.ts +47 -0
  18. package/dist/episodic.js +130 -0
  19. package/dist/hook.d.ts +45 -0
  20. package/dist/hook.js +104 -0
  21. package/dist/index.d.ts +18 -0
  22. package/dist/index.js +18 -0
  23. package/dist/init.d.ts +125 -0
  24. package/dist/init.js +475 -0
  25. package/dist/instructions.d.ts +60 -0
  26. package/dist/instructions.js +270 -0
  27. package/dist/mcp.d.ts +109 -0
  28. package/dist/mcp.js +252 -0
  29. package/dist/mcpServer.d.ts +136 -0
  30. package/dist/mcpServer.js +997 -0
  31. package/dist/paths.d.ts +25 -0
  32. package/dist/paths.js +47 -0
  33. package/dist/recall.d.ts +113 -0
  34. package/dist/recall.js +256 -0
  35. package/dist/recallDir.d.ts +50 -0
  36. package/dist/recallDir.js +187 -0
  37. package/dist/reorganize.d.ts +62 -0
  38. package/dist/reorganize.js +216 -0
  39. package/dist/report.d.ts +16 -0
  40. package/dist/report.js +204 -0
  41. package/dist/router.d.ts +141 -0
  42. package/dist/router.js +314 -0
  43. package/dist/rules.d.ts +32 -0
  44. package/dist/rules.js +651 -0
  45. package/dist/scan.d.ts +110 -0
  46. package/dist/scan.js +173 -0
  47. package/dist/text.d.ts +158 -0
  48. package/dist/text.js +395 -0
  49. package/dist/tokenizer.d.ts +26 -0
  50. package/dist/tokenizer.js +69 -0
  51. package/dist/types.d.ts +156 -0
  52. package/dist/types.js +17 -0
  53. package/dist/version.d.ts +7 -0
  54. package/dist/version.js +7 -0
  55. package/dist/writeProtocol.d.ts +19 -0
  56. package/dist/writeProtocol.js +45 -0
  57. package/examples/CLAUDE.md +75 -0
  58. package/examples/README.md +7 -0
  59. package/package.json +52 -0
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Wires the MCP tools onto a server instance. Kept separate from recall.ts so the pure logic
3
+ * (loadManifest, rankOnDemandFiles, recall, outlineOf) is testable without an SDK, a transport, or Zod
4
+ * in the loop at all.
5
+ *
6
+ * Two profiles, because a tool definition is charged to the client's prefix on every turn
7
+ * whether or not it is ever called. `basic` (default) is four verbs that match what a
8
+ * developer actually does with a memory setup - check it, optimize it, sync it, recall from it -
9
+ * instead of the nine build-layer tools (scan/doctor/plan/apply/update/reorganize plus
10
+ * recall/modules/outline) a client had to hold before this split, whether or not the session
11
+ * ever touched most of them. `full` keeps today's nine, unchanged in name, schema and
12
+ * behaviour, for maintainers and for an agent driving a folder reorganization directly.
13
+ *
14
+ * The basic surface also depends on the workspace phase, probed once per launch by
15
+ * detectPhase() in discover.ts (a stat on `.minnimemory/`, nothing read): a "setup" root (not
16
+ * compiled) registers check, plus optimize with --allow-write; a "compiled" root registers
17
+ * recall, plus sync with --allow-write. Each launch holds two tools at most, never four. The
18
+ * phase is fixed for the life of the process: a session that compiles mid-way relaunches to get
19
+ * the compiled surface. `full` ignores phase.
20
+ *
21
+ * Real per-turn cost of each `tools/list` response (Research/TokenTest/tool_cost.mjs, tokenizer approx-v2),
22
+ * measured 2026-09-15:
23
+ *
24
+ * profile phase launch tools tokens
25
+ * basic (default) setup (none) check 368
26
+ * basic setup --allow-write check, optimize 1,025
27
+ * basic compiled (none) recall 329
28
+ * basic compiled --allow-write recall, sync 605
29
+ * full any --profile full recall, modules, outline, 1,666
30
+ * scan, doctor, plan
31
+ * full any --profile full --allow-write + apply, update, reorganize 2,668
32
+ *
33
+ * (the earlier basic figures of 696 read-only and 1,589 --allow-write were for the pre-phase
34
+ * surface that held all four verbs per launch; superseded by this table)
35
+ *
36
+ * Gating is by registration, not by a runtime refusal inside the handler. An unregistered tool
37
+ * costs nothing and cannot be called; a registered tool that always answers "disabled" still
38
+ * costs its full definition every turn - that was about 1,080 tokens of permanently-refusing
39
+ * write tools on every read-only server before the original three/setup/write split this
40
+ * replaces.
41
+ *
42
+ * `check`, `optimize`, `sync` and basic's `recall` are one handler each over the same doctor(),
43
+ * planInit(), init(), scanMemoryDir() and reorganize.ts's applyPlan() the full profile's nine
44
+ * tools already call - no logic is duplicated here, only the surface is smaller:
45
+ * check merges doctor() + plan(), always returning the doctor half; the compile-plan
46
+ * half is added when planInit() succeeds and left out, with one line saying why,
47
+ * when it throws InitError (a memory directory, an index file, already compiled).
48
+ * optimize decides compilable-file vs memory-directory from discover()'s own shape, not from
49
+ * an argument: a file goes through init() (apply, or update when already compiled);
50
+ * a directory returns scanMemoryDir() facts plus an instruction block until called
51
+ * again with ops, which then go through reorganize.ts's applyPlan().
52
+ * sync runs doctor() restricted to MM010 (drift) and, only when something drifted, calls
53
+ * init() with update: true - the same re-apply update() already does.
54
+ * recall folds today's modules() (no query) and outline() (headingsOnly) into one tool
55
+ * alongside its own section-retrieval behaviour, unchanged when a query is given.
56
+ *
57
+ * This is still the "full-control" MCP shape from DESIGN.md section 6 - read tools for the
58
+ * doctor/init-plan judgment, write tools gated behind an explicit flag - built as
59
+ * `optimize`/`sync` (basic) or `apply`/`update` (full) rather than a single "update_module",
60
+ * because the shipped mechanism recompiles a whole workspace from its stub and OnDemandMemory
61
+ * files on disk, not one OnDemandMemory file in isolation.
62
+ */
63
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
64
+ /** What each mode adds, in registration order. Exported so tests, CLI help and docs quote one list. */
65
+ export declare const SERVE_TOOLS: readonly ["recall", "modules", "outline"];
66
+ export declare const SETUP_TOOLS: readonly ["scan", "doctor", "plan"];
67
+ export declare const WRITE_TOOLS: readonly ["apply", "update", "reorganize"];
68
+ /** The `basic` profile's tools, in registration order, as the union across both workspace
69
+ * phases; no single launch registers all of either list. A setup root gets check (and optimize
70
+ * with --allow-write), a compiled root gets recall (and sync with --allow-write). */
71
+ export declare const BASIC_READ_TOOLS: readonly ["check", "recall"];
72
+ export declare const BASIC_WRITE_TOOLS: readonly ["optimize", "sync"];
73
+ export interface McpServerOptions {
74
+ /**
75
+ * "basic" (default) or "full". basic registers by workspace phase (detectPhase in discover.ts,
76
+ * probed once per launch): on a setup root `check`, plus `optimize` with --allow-write; on a
77
+ * compiled root `recall`, plus `sync` with --allow-write. full registers today's nine tools:
78
+ * recall/modules/outline and scan/doctor/plan always, plus apply/update/reorganize with
79
+ * --allow-write. A tool definition is charged every turn, so a per-turn retrieval client
80
+ * should not carry more than it needs.
81
+ */
82
+ profile?: "basic" | "full";
83
+ /**
84
+ * Adds the write tools: `optimize`/`sync` (basic) or `apply`/`update`/`reorganize` (full).
85
+ * Default false: a fresh `mcp` invocation is read-only, matching the locked "default stays
86
+ * read-only" decision - full-control write access is opt-in per launch, never the default a
87
+ * client silently inherits.
88
+ */
89
+ allowWrite?: boolean;
90
+ /**
91
+ * Let doctor/plan/scan (and check/optimize, their basic-profile equivalents) follow `@path`
92
+ * imports outside the root. A launch flag with no tool argument behind it on purpose: whether
93
+ * to read files elsewhere on this machine is the operator's call, and a connected client
94
+ * asking nicely is not consent.
95
+ */
96
+ followExternalImports?: boolean;
97
+ /**
98
+ * Let doctor/plan/apply/update/scan (and check/optimize) see the operator's OS-level Claude
99
+ * Code auto-memory folder, and allow "auto-memory" as a target where that tool resolves one
100
+ * (2026-09-13 audit round 2, D2). Separate from `followExternalImports`: reading the
101
+ * operator's own memory and following an `@path` an imported file names are different reaches,
102
+ * and each flag does one thing. A launch flag with no tool argument behind it, same reasoning
103
+ * as `followExternalImports`.
104
+ */
105
+ includeAutoMemory?: boolean;
106
+ }
107
+ /**
108
+ * Content returned by recall/outline is memory-file text, and a memory file can be written by
109
+ * whoever wrote the repo. It arrives in a model's context looking exactly like trusted memory,
110
+ * so it is fenced and labelled as data. Same posture this project already applies to live app
111
+ * state in its own PCTuner agent, which fences the block and says plainly that instructions
112
+ * inside it are not to be followed.
113
+ *
114
+ * Deliberately short: this is a token-optimisation tool, so the framing is one header and one
115
+ * footer per response, roughly thirty tokens, not a paragraph per unit.
116
+ */
117
+ export declare const DATA_OPEN: string;
118
+ export declare const DATA_CLOSE = "\n=== END RETRIEVED MEMORY ===";
119
+ export declare function createMcpServer(root: string, options?: McpServerOptions): McpServer;
120
+ /**
121
+ * Shown to a client that connects while the CLI's `mcp` command is stashed (see cli.ts). No
122
+ * tools are registered - per this file's own header comment, a tool that only ever refuses
123
+ * still costs its full definition every turn, so the honest zero-cost shape while disabled is no
124
+ * tools at all, with the reason carried in the spec's `instructions` field instead.
125
+ */
126
+ export declare const DISABLED_MESSAGE = "Currently Disabled For Research and Testing. Learn more: https://minniai.com";
127
+ /**
128
+ * A zero-tool MCP server that only completes the handshake and states DISABLED_MESSAGE.
129
+ *
130
+ * Declares the tools capability with an explicit empty list, rather than leaving it entirely
131
+ * undeclared (`McpServer` only declares it once `registerTool` is called, which never happens
132
+ * here). Confirmed live in the 2026-09-10 audit: an undeclared capability makes `tools/list`
133
+ * answer JSON-RPC -32601 "Method not found", which many hosts treat as a broken/failed server -
134
+ * exactly the opposite of "connects cleanly and says why there's nothing here".
135
+ */
136
+ export declare function createDisabledMcpServer(): McpServer;