toon-memory 2.4.1 → 2.4.3

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.
@@ -91,9 +91,8 @@ function atomicWrite(file, content) {
91
91
  }
92
92
 
93
93
  // src/lib/sessions.ts
94
- import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, readdirSync, unlinkSync as unlinkSync2 } from "fs";
94
+ import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, readdirSync, unlinkSync as unlinkSync2, statSync as statSync2 } from "fs";
95
95
  import { join } from "path";
96
- import { execSync } from "child_process";
97
96
  var SESSION_TTL_MS = 10 * 60 * 1e3;
98
97
  var PRUNE_STALE_MS = 10 * 60 * 1e3;
99
98
  function sessionDir() {
@@ -119,12 +118,23 @@ function currentBranch() {
119
118
  return process.env.TOON_MEMORY_BRANCH.trim();
120
119
  }
121
120
  try {
122
- const branch = execSync("git rev-parse --abbrev-ref HEAD", {
123
- encoding: "utf-8",
124
- timeout: 2e3,
125
- stdio: ["ignore", "pipe", "ignore"]
126
- }).trim();
127
- return branch || "unknown";
121
+ let gitDir = join(process.cwd(), ".git");
122
+ if (existsSync2(gitDir) && !statSync2(gitDir).isDirectory()) {
123
+ const pointer = readFileSync2(gitDir, "utf-8").trim();
124
+ if (pointer.startsWith("gitdir:")) {
125
+ const target = pointer.slice(7).trim();
126
+ gitDir = target.startsWith("/") ? target : join(process.cwd(), target);
127
+ }
128
+ }
129
+ const headPath = join(gitDir, "HEAD");
130
+ if (!existsSync2(headPath)) return "unknown";
131
+ const head = readFileSync2(headPath, "utf-8").trim();
132
+ if (head.startsWith("ref:")) {
133
+ const ref = head.slice(4).trim();
134
+ const parts = ref.split("/");
135
+ return parts[parts.length - 1] || "unknown";
136
+ }
137
+ return head ? head.slice(0, 7) : "unknown";
128
138
  } catch {
129
139
  return "unknown";
130
140
  }
@@ -2,9 +2,8 @@
2
2
  import { readFileSync as readFileSync2 } from "fs";
3
3
 
4
4
  // src/lib/sessions.ts
5
- import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync } from "fs";
5
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync, statSync } from "fs";
6
6
  import { join } from "path";
7
- import { execSync } from "child_process";
8
7
  var SESSION_TTL_MS = 10 * 60 * 1e3;
9
8
  var PRUNE_STALE_MS = 10 * 60 * 1e3;
10
9
  function isAlive(pid) {
@@ -39,12 +38,23 @@ function currentBranch() {
39
38
  return process.env.TOON_MEMORY_BRANCH.trim();
40
39
  }
41
40
  try {
42
- const branch = execSync("git rev-parse --abbrev-ref HEAD", {
43
- encoding: "utf-8",
44
- timeout: 2e3,
45
- stdio: ["ignore", "pipe", "ignore"]
46
- }).trim();
47
- return branch || "unknown";
41
+ let gitDir = join(process.cwd(), ".git");
42
+ if (existsSync(gitDir) && !statSync(gitDir).isDirectory()) {
43
+ const pointer = readFileSync(gitDir, "utf-8").trim();
44
+ if (pointer.startsWith("gitdir:")) {
45
+ const target = pointer.slice(7).trim();
46
+ gitDir = target.startsWith("/") ? target : join(process.cwd(), target);
47
+ }
48
+ }
49
+ const headPath = join(gitDir, "HEAD");
50
+ if (!existsSync(headPath)) return "unknown";
51
+ const head = readFileSync(headPath, "utf-8").trim();
52
+ if (head.startsWith("ref:")) {
53
+ const ref = head.slice(4).trim();
54
+ const parts = ref.split("/");
55
+ return parts[parts.length - 1] || "unknown";
56
+ }
57
+ return head ? head.slice(0, 7) : "unknown";
48
58
  } catch {
49
59
  return "unknown";
50
60
  }
package/dist/cli/setup.js CHANGED
@@ -72,6 +72,22 @@ function extractProjectDeps(root) {
72
72
  var __dirname = dirname(fileURLToPath(import.meta.url));
73
73
  var projectRoot = process.cwd();
74
74
  var sourceDir = join2(__dirname, "..", "..", "src");
75
+ function resolvePackageJson() {
76
+ let dir = __dirname;
77
+ while (true) {
78
+ const candidate = join2(dir, "package.json");
79
+ if (existsSync2(candidate)) {
80
+ try {
81
+ const p = JSON.parse(readFileSync2(candidate, "utf-8"));
82
+ if (p && p.name === "toon-memory") return candidate;
83
+ } catch {
84
+ }
85
+ }
86
+ const parent = dirname(dir);
87
+ if (parent === dir) return null;
88
+ dir = parent;
89
+ }
90
+ }
75
91
  var HOME = process.env.HOME || process.env.USERPROFILE || "~";
76
92
  var MEMORY_DIR = join2(projectRoot, ".toon-memory", "memory");
77
93
  var CAPTURE_JS = join2(__dirname, "capture.js");
@@ -681,12 +697,15 @@ function uninstall() {
681
697
  }
682
698
  function status() {
683
699
  console.log("\n\u{1F9E0} toon-memory status\n");
684
- try {
685
- const pkg = JSON.parse(readFileSync2(join2(__dirname, "..", "package.json"), "utf-8"));
686
- console.log(`Version: ${pkg.version}`);
687
- } catch {
688
- console.log("Version: unknown");
700
+ const pkgPath = resolvePackageJson();
701
+ let version = "unknown";
702
+ if (pkgPath) {
703
+ try {
704
+ version = JSON.parse(readFileSync2(pkgPath, "utf-8")).version;
705
+ } catch {
706
+ }
689
707
  }
708
+ console.log(`Version: ${version}`);
690
709
  const memoryFile = join2(MEMORY_DIR, "data.toon");
691
710
  if (existsSync2(memoryFile)) {
692
711
  const data = readFileSync2(memoryFile, "utf-8");
@@ -753,8 +772,8 @@ function status() {
753
772
  function upgrade() {
754
773
  console.log("\n\u{1F9E0} toon-memory upgrade\n");
755
774
  try {
756
- const pkg = JSON.parse(readFileSync2(join2(__dirname, "..", "package.json"), "utf-8"));
757
- const currentVersion = pkg.version;
775
+ const pkgPath = resolvePackageJson();
776
+ const currentVersion = pkgPath ? JSON.parse(readFileSync2(pkgPath, "utf-8")).version : "unknown";
758
777
  console.log(`Current version: ${currentVersion}`);
759
778
  console.log("\nTo upgrade, run:");
760
779
  console.log(" npm install -g toon-memory@latest");
package/mcp/server.js CHANGED
@@ -27739,9 +27739,8 @@ function readUnderLock(file2, encoding = "utf-8") {
27739
27739
  }
27740
27740
 
27741
27741
  // src/lib/sessions.ts
27742
- import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, readdirSync, unlinkSync as unlinkSync2 } from "fs";
27742
+ import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, readdirSync, unlinkSync as unlinkSync2, statSync as statSync2 } from "fs";
27743
27743
  import { join } from "path";
27744
- import { execSync } from "child_process";
27745
27744
  var SESSION_TTL_MS = 10 * 60 * 1e3;
27746
27745
  var PRUNE_STALE_MS = 10 * 60 * 1e3;
27747
27746
  function isAlive2(pid) {
@@ -27769,12 +27768,23 @@ function currentBranch() {
27769
27768
  return process.env.TOON_MEMORY_BRANCH.trim();
27770
27769
  }
27771
27770
  try {
27772
- const branch = execSync("git rev-parse --abbrev-ref HEAD", {
27773
- encoding: "utf-8",
27774
- timeout: 2e3,
27775
- stdio: ["ignore", "pipe", "ignore"]
27776
- }).trim();
27777
- return branch || "unknown";
27771
+ let gitDir = join(process.cwd(), ".git");
27772
+ if (existsSync2(gitDir) && !statSync2(gitDir).isDirectory()) {
27773
+ const pointer = readFileSync2(gitDir, "utf-8").trim();
27774
+ if (pointer.startsWith("gitdir:")) {
27775
+ const target = pointer.slice(7).trim();
27776
+ gitDir = target.startsWith("/") ? target : join(process.cwd(), target);
27777
+ }
27778
+ }
27779
+ const headPath = join(gitDir, "HEAD");
27780
+ if (!existsSync2(headPath)) return "unknown";
27781
+ const head = readFileSync2(headPath, "utf-8").trim();
27782
+ if (head.startsWith("ref:")) {
27783
+ const ref = head.slice(4).trim();
27784
+ const parts = ref.split("/");
27785
+ return parts[parts.length - 1] || "unknown";
27786
+ }
27787
+ return head ? head.slice(0, 7) : "unknown";
27778
27788
  } catch {
27779
27789
  return "unknown";
27780
27790
  }
@@ -28398,7 +28408,7 @@ function consolidateEntries() {
28398
28408
  return { removed: duplicates.length, kept: order.length, duplicates };
28399
28409
  }
28400
28410
  var server = new McpServer(
28401
- { name: "toon-memory", version: "2.4.1" },
28411
+ { name: "toon-memory", version: "2.4.3" },
28402
28412
  { capabilities: { tools: { listChanged: true }, resources: { listChanged: true } } }
28403
28413
  );
28404
28414
  server.registerResource(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toon-memory",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "MCP server giving AI coding agents offline, token-efficient persistent memory — recall decisions, patterns, and bugs across sessions with 68.5% fewer tokens than re-reading context. No LLM, no server; works with 15+ agents.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli/setup.ts CHANGED
@@ -8,6 +8,26 @@ import { extractProjectDeps } from "../lib/vocab"
8
8
  const __dirname = dirname(fileURLToPath(import.meta.url))
9
9
  const projectRoot = process.cwd()
10
10
  const sourceDir = join(__dirname, "..", "..", "src")
11
+
12
+ /** Resolve this package's package.json by walking up from the module location.
13
+ * Setup logic may run from dist/cli/setup.js, so a fixed relative path is wrong. */
14
+ function resolvePackageJson(): string | null {
15
+ let dir = __dirname
16
+ while (true) {
17
+ const candidate = join(dir, "package.json")
18
+ if (existsSync(candidate)) {
19
+ try {
20
+ const p = JSON.parse(readFileSync(candidate, "utf-8"))
21
+ if (p && p.name === "toon-memory") return candidate
22
+ } catch {
23
+ // ignore and keep walking
24
+ }
25
+ }
26
+ const parent = dirname(dir)
27
+ if (parent === dir) return null
28
+ dir = parent
29
+ }
30
+ }
11
31
  const HOME = process.env.HOME || process.env.USERPROFILE || "~"
12
32
 
13
33
  /** Shared memory directory (agent-agnostic) */
@@ -865,12 +885,16 @@ function status(): void {
865
885
  console.log("\n🧠 toon-memory status\n")
866
886
 
867
887
  // Check npm package
868
- try {
869
- const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"))
870
- console.log(`Version: ${pkg.version}`)
871
- } catch {
872
- console.log("Version: unknown")
888
+ const pkgPath = resolvePackageJson()
889
+ let version = "unknown"
890
+ if (pkgPath) {
891
+ try {
892
+ version = JSON.parse(readFileSync(pkgPath, "utf-8")).version
893
+ } catch {
894
+ // keep "unknown"
895
+ }
873
896
  }
897
+ console.log(`Version: ${version}`)
874
898
 
875
899
  // Check memory file
876
900
  const memoryFile = join(MEMORY_DIR, "data.toon")
@@ -960,8 +984,8 @@ function upgrade(): void {
960
984
  console.log("\n🧠 toon-memory upgrade\n")
961
985
 
962
986
  try {
963
- const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"))
964
- const currentVersion = pkg.version
987
+ const pkgPath = resolvePackageJson()
988
+ const currentVersion = pkgPath ? JSON.parse(readFileSync(pkgPath, "utf-8")).version : "unknown"
965
989
 
966
990
  console.log(`Current version: ${currentVersion}`)
967
991
  console.log("\nTo upgrade, run:")
@@ -1,6 +1,5 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync, statSync } from "fs"
2
2
  import { join } from "path"
3
- import { execSync } from "child_process"
4
3
 
5
4
  /**
6
5
  * File-based multi-session coordination — no server, no network, no LLM.
@@ -74,18 +73,31 @@ export function resolveSessionId(payload: Record<string, unknown> = {}): string
74
73
  return `proc-${process.pid}-${Math.random().toString(36).slice(2, 10)}`
75
74
  }
76
75
 
77
- /** Detect the current git branch; falls back to env or "unknown". */
76
+ /** Detect the current git branch by reading .git/HEAD directly (no shell). */
78
77
  export function currentBranch(): string {
79
78
  if (process.env.TOON_MEMORY_BRANCH && process.env.TOON_MEMORY_BRANCH.trim()) {
80
79
  return process.env.TOON_MEMORY_BRANCH.trim()
81
80
  }
82
81
  try {
83
- const branch = execSync("git rev-parse --abbrev-ref HEAD", {
84
- encoding: "utf-8",
85
- timeout: 2000,
86
- stdio: ["ignore", "pipe", "ignore"],
87
- }).trim()
88
- return branch || "unknown"
82
+ let gitDir = join(process.cwd(), ".git")
83
+ // .git may be a file pointing at the real git dir (worktrees).
84
+ if (existsSync(gitDir) && !statSync(gitDir).isDirectory()) {
85
+ const pointer = readFileSync(gitDir, "utf-8").trim()
86
+ if (pointer.startsWith("gitdir:")) {
87
+ const target = pointer.slice(7).trim()
88
+ gitDir = target.startsWith("/") ? target : join(process.cwd(), target)
89
+ }
90
+ }
91
+ const headPath = join(gitDir, "HEAD")
92
+ if (!existsSync(headPath)) return "unknown"
93
+ const head = readFileSync(headPath, "utf-8").trim()
94
+ if (head.startsWith("ref:")) {
95
+ const ref = head.slice(4).trim()
96
+ const parts = ref.split("/")
97
+ return parts[parts.length - 1] || "unknown"
98
+ }
99
+ // Detached HEAD: HEAD holds a commit hash.
100
+ return head ? head.slice(0, 7) : "unknown"
89
101
  } catch {
90
102
  return "unknown"
91
103
  }
package/src/mcp/server.ts CHANGED
@@ -599,7 +599,7 @@ function consolidateEntries(): { removed: number; kept: number; duplicates: stri
599
599
  }
600
600
 
601
601
  const server = new McpServer(
602
- { name: "toon-memory", version: "2.4.1" },
602
+ { name: "toon-memory", version: "2.4.3" },
603
603
  { capabilities: { tools: { listChanged: true }, resources: { listChanged: true } } }
604
604
  )
605
605