@gamaze/hicortex 0.3.5 → 0.3.7

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/dist/index.js CHANGED
@@ -48,6 +48,7 @@ const node_fs_1 = require("node:fs");
48
48
  const node_os_1 = require("node:os");
49
49
  const embedder_js_1 = require("./embedder.js");
50
50
  const storage = __importStar(require("./storage.js"));
51
+ const seed_lesson_js_1 = require("./seed-lesson.js");
51
52
  const retrieval = __importStar(require("./retrieval.js"));
52
53
  const distiller_js_1 = require("./distiller.js");
53
54
  const consolidate_js_1 = require("./consolidate.js");
@@ -92,7 +93,7 @@ exports.default = {
92
93
  const consolidateHour = config.consolidateHour ?? 2;
93
94
  cancelConsolidation = (0, consolidate_js_1.scheduleConsolidation)(db, llm, embedder_js_1.embed, consolidateHour);
94
95
  // Seed the bootstrap lesson on first run
95
- await injectSeedLesson(db, log);
96
+ await (0, seed_lesson_js_1.injectSeedLesson)(db, log);
96
97
  // Auto-add tools to tools.allow if using a restrictive profile
97
98
  ensureToolsAllowed(log);
98
99
  // Log stats
@@ -501,45 +502,6 @@ function ensureToolsAllowed(log) {
501
502
  // Non-fatal
502
503
  }
503
504
  }
504
- // ---------------------------------------------------------------------------
505
- // Seed lesson — injected on first run, teaches the agent to self-improve
506
- // ---------------------------------------------------------------------------
507
- const SEED_LESSON = `## Lesson: 1% Daily Self-Improvement
508
-
509
- Self-improvement protocol: Review your sessions daily. Scan for mistakes, gaps, user corrections, and friction. Identify 1-2 issues maximum. Apply one targeted fix to your instruction files (AGENT.md, IDENTITY.md, TOOLS.md, SOUL.md, or CLAUDE.md). Never overcorrect — feedback is guidance, not emergency. One fix per issue. Never rewrite entire systems. Before changing something, ask: is this a real pattern or am I reacting to noise?
510
-
511
- The flywheel: Sessions → Hicortex captures → Nightly consolidation → Lessons generated → Lessons injected into your context → You apply one fix → Better sessions tomorrow.
512
-
513
- Use hicortex_lessons to check for new insights. If a lesson has high confidence, apply it. If medium, observe for one more day. If nothing needs fixing today, skip — that's fine.
514
-
515
- **Severity:** critical
516
- **Confidence:** high
517
- **Generated:** seed-lesson`;
518
- async function injectSeedLesson(database, log) {
519
- try {
520
- // Check if seed lesson already exists (match on unique content)
521
- const existing = storage.getLessons(database, 365);
522
- const hasSeed = existing.some((l) => l.content.includes("1% Daily Self-Improvement") ||
523
- l.source_agent === "hicortex/seed");
524
- if (hasSeed)
525
- return;
526
- // Embed and store
527
- const embedding = await (0, embedder_js_1.embed)(SEED_LESSON);
528
- storage.insertMemory(database, SEED_LESSON, embedding, {
529
- sourceAgent: "hicortex/seed",
530
- project: "global",
531
- memoryType: "lesson",
532
- baseStrength: 0.95,
533
- privacy: "WORK",
534
- });
535
- log("[hicortex] Seed lesson injected: Daily Self-Improvement Protocol");
536
- }
537
- catch (err) {
538
- // Non-fatal — log but don't crash the plugin
539
- const msg = err instanceof Error ? err.message : String(err);
540
- log(`[hicortex] Warning: could not inject seed lesson: ${msg}`);
541
- }
542
- }
543
505
  function formatToolResults(results) {
544
506
  if (results.length === 0) {
545
507
  return {
package/dist/init.js CHANGED
@@ -106,6 +106,11 @@ async function detect() {
106
106
  // ---------------------------------------------------------------------------
107
107
  function registerCcMcp(serverUrl) {
108
108
  try {
109
+ // Remove existing entry first (idempotent — ignore if not found)
110
+ try {
111
+ (0, node_child_process_1.execSync)("claude mcp remove hicortex 2>/dev/null", { encoding: "utf-8", stdio: "pipe" });
112
+ }
113
+ catch { /* not found */ }
109
114
  // Use claude CLI to register — it knows the correct config format and location
110
115
  (0, node_child_process_1.execSync)(`claude mcp add hicortex --transport sse ${serverUrl}/sse`, { encoding: "utf-8", stdio: "pipe" });
111
116
  console.log(` ✓ Registered MCP server via claude CLI`);
@@ -183,25 +188,38 @@ Becomes a call to hicortex_ingest with:
183
188
  name: hicortex-activate
184
189
  description: Activate a Hicortex license key for unlimited memory. Use after purchasing at hicortex.gamaze.com.
185
190
  argument-hint: <license-key>
186
- allowed-tools: Bash(mkdir:*), Bash(echo:*), mcp__hicortex__hicortex_ingest, mcp__hicortex__hicortex_search, mcp__hicortex__hicortex_context, mcp__hicortex__hicortex_lessons
191
+ allowed-tools: Bash(mkdir:*), Bash(echo:*), Bash(launchctl:*), Bash(systemctl:*), Bash(curl:*), mcp__hicortex__hicortex_ingest, mcp__hicortex__hicortex_search, mcp__hicortex__hicortex_context, mcp__hicortex__hicortex_lessons
187
192
  ---
188
193
 
189
194
  # Activate Hicortex License
190
195
 
191
196
  ## If key provided (e.g. /hicortex-activate hctx-abc123)
192
197
 
193
- Write the key to the config file:
198
+ 1. Write the key to the config file:
194
199
 
195
200
  \`\`\`bash
196
201
  mkdir -p ~/.hicortex
197
202
  echo '{ "licenseKey": "THE_KEY_HERE" }' > ~/.hicortex/config.json
198
203
  \`\`\`
199
204
 
200
- Then tell the user: "License activated! Hicortex now has unlimited memory. Restart the server to apply."
205
+ 2. Restart the server to apply:
201
206
 
202
- Provide the restart command for their platform:
203
- - macOS: \`launchctl kickstart -k gui/$(id -u)/com.gamaze.hicortex\`
204
- - Linux: \`systemctl --user restart hicortex\`
207
+ On macOS:
208
+ \`\`\`bash
209
+ launchctl kickstart -k gui/$(id -u)/com.gamaze.hicortex
210
+ \`\`\`
211
+
212
+ On Linux:
213
+ \`\`\`bash
214
+ systemctl --user restart hicortex
215
+ \`\`\`
216
+
217
+ 3. Verify the server is back:
218
+ \`\`\`bash
219
+ curl -s http://127.0.0.1:8787/health
220
+ \`\`\`
221
+
222
+ 4. Tell the user: "License activated! Hicortex now has unlimited memory."
205
223
 
206
224
  ## If no key provided
207
225
 
@@ -210,21 +228,32 @@ Tell them: "Get a license key at https://hicortex.gamaze.com/ — after purchase
210
228
  (0, node_fs_1.writeFileSync)((0, node_path_1.join)(CC_COMMANDS_DIR, "hicortex-activate.md"), activateContent);
211
229
  console.log(` ✓ Installed /learn and /hicortex-activate commands in ${CC_COMMANDS_DIR}`);
212
230
  }
213
- function getPackageVersion() {
231
+ /**
232
+ * Determine the npm package specifier for the daemon.
233
+ * Uses tag-based resolution so restarts pick up new versions automatically.
234
+ *
235
+ * Checks if the current version matches the npm `latest` tag.
236
+ * If not (e.g. running from @next), uses @gamaze/hicortex@next.
237
+ * If it does match latest, uses bare @gamaze/hicortex.
238
+ */
239
+ function getPackageSpec() {
214
240
  try {
215
- const pkgPath = (0, node_path_1.join)(__dirname, "..", "package.json");
216
- const pkg = JSON.parse((0, node_fs_1.readFileSync)(pkgPath, "utf-8"));
217
- return pkg.version ?? "latest";
218
- }
219
- catch {
220
- return "latest";
241
+ const currentVersion = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "..", "package.json"), "utf-8")).version;
242
+ const latestVersion = (0, node_child_process_1.execSync)("npm view @gamaze/hicortex version 2>/dev/null", {
243
+ encoding: "utf-8",
244
+ timeout: 5000,
245
+ }).trim();
246
+ if (currentVersion !== latestVersion) {
247
+ return "@gamaze/hicortex@next";
248
+ }
221
249
  }
250
+ catch { /* can't check — default to bare */ }
251
+ return "@gamaze/hicortex";
222
252
  }
223
253
  function installDaemon() {
224
254
  const os = (0, node_os_1.platform)();
225
255
  const npxPath = findNpxPath();
226
- const version = getPackageVersion();
227
- const packageSpec = `@gamaze/hicortex@${version}`;
256
+ const packageSpec = getPackageSpec();
228
257
  if (os === "darwin") {
229
258
  return installLaunchd(npxPath, packageSpec);
230
259
  }
@@ -60,6 +60,7 @@ const embedder_js_1 = require("./embedder.js");
60
60
  const storage = __importStar(require("./storage.js"));
61
61
  const retrieval = __importStar(require("./retrieval.js"));
62
62
  const consolidate_js_1 = require("./consolidate.js");
63
+ const seed_lesson_js_1 = require("./seed-lesson.js");
63
64
  // ---------------------------------------------------------------------------
64
65
  // Server state
65
66
  // ---------------------------------------------------------------------------
@@ -193,16 +194,16 @@ async function startServer(options = {}) {
193
194
  // Schedule nightly consolidation
194
195
  const consolidateHour = options.consolidateHour ?? 2;
195
196
  cancelConsolidation = (0, consolidate_js_1.scheduleConsolidation)(db, llm, embedder_js_1.embed, consolidateHour);
197
+ // Seed lesson on first run
198
+ await (0, seed_lesson_js_1.injectSeedLesson)(db);
196
199
  // Stats
197
200
  const stats = (0, db_js_1.getStats)(db, dbPath);
198
201
  console.log(`[hicortex] Ready: ${stats.memories} memories, ${stats.links} links, ` +
199
202
  `${Math.round(stats.db_size_bytes / 1024)} KB`);
200
- // Create MCP server
201
- const mcpServer = createMcpServer();
202
203
  // Express app
203
204
  const app = (0, express_1.default)();
204
205
  app.use(express_1.default.json());
205
- // SSE transport management
206
+ // SSE transport management — each connection gets its own McpServer instance
206
207
  const transports = new Map();
207
208
  // Health endpoint
208
209
  app.get("/health", (_req, res) => {
@@ -216,9 +217,10 @@ async function startServer(options = {}) {
216
217
  llm: `${llmConfig.provider}/${llmConfig.model}`,
217
218
  });
218
219
  });
219
- // SSE endpoint — client connects here to establish MCP session
220
+ // SSE endpoint — each connection gets its own McpServer + transport
220
221
  app.get("/sse", async (req, res) => {
221
222
  const transport = new sse_js_1.SSEServerTransport("/messages", res);
223
+ const mcpServer = createMcpServer();
222
224
  transports.set(transport.sessionId, transport);
223
225
  transport.onclose = () => {
224
226
  transports.delete(transport.sessionId);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Seed lesson — injected on first run, teaches agents to self-improve.
3
+ * Shared between OC plugin and CC MCP server.
4
+ */
5
+ import type Database from "better-sqlite3";
6
+ export declare const SEED_LESSON = "## Lesson: 1% Daily Self-Improvement\n\nSelf-improvement protocol: Review your sessions daily. Scan for mistakes, gaps, user corrections, and friction. Identify 1-2 issues maximum. Apply one targeted fix to your instruction files (AGENT.md, IDENTITY.md, TOOLS.md, SOUL.md, or CLAUDE.md). Never overcorrect \u2014 feedback is guidance, not emergency. One fix per issue. Never rewrite entire systems. Before changing something, ask: is this a real pattern or am I reacting to noise?\n\nThe flywheel: Sessions \u2192 Hicortex captures \u2192 Nightly consolidation \u2192 Lessons generated \u2192 Lessons injected into your context \u2192 You apply one fix \u2192 Better sessions tomorrow.\n\nUse hicortex_lessons to check for new insights. If a lesson has high confidence, apply it. If medium, observe for one more day. If nothing needs fixing today, skip \u2014 that's fine.\n\n**Severity:** critical\n**Confidence:** high\n**Generated:** seed-lesson";
7
+ export declare function injectSeedLesson(database: Database.Database, log?: (msg: string) => void): Promise<void>;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * Seed lesson — injected on first run, teaches agents to self-improve.
4
+ * Shared between OC plugin and CC MCP server.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.SEED_LESSON = void 0;
41
+ exports.injectSeedLesson = injectSeedLesson;
42
+ const embedder_js_1 = require("./embedder.js");
43
+ const storage = __importStar(require("./storage.js"));
44
+ exports.SEED_LESSON = `## Lesson: 1% Daily Self-Improvement
45
+
46
+ Self-improvement protocol: Review your sessions daily. Scan for mistakes, gaps, user corrections, and friction. Identify 1-2 issues maximum. Apply one targeted fix to your instruction files (AGENT.md, IDENTITY.md, TOOLS.md, SOUL.md, or CLAUDE.md). Never overcorrect — feedback is guidance, not emergency. One fix per issue. Never rewrite entire systems. Before changing something, ask: is this a real pattern or am I reacting to noise?
47
+
48
+ The flywheel: Sessions → Hicortex captures → Nightly consolidation → Lessons generated → Lessons injected into your context → You apply one fix → Better sessions tomorrow.
49
+
50
+ Use hicortex_lessons to check for new insights. If a lesson has high confidence, apply it. If medium, observe for one more day. If nothing needs fixing today, skip — that's fine.
51
+
52
+ **Severity:** critical
53
+ **Confidence:** high
54
+ **Generated:** seed-lesson`;
55
+ async function injectSeedLesson(database, log = console.log) {
56
+ try {
57
+ const existing = storage.getLessons(database, 365);
58
+ const hasSeed = existing.some((l) => l.content.includes("1% Daily Self-Improvement") ||
59
+ l.source_agent === "hicortex/seed");
60
+ if (hasSeed)
61
+ return;
62
+ const embedding = await (0, embedder_js_1.embed)(exports.SEED_LESSON);
63
+ storage.insertMemory(database, exports.SEED_LESSON, embedding, {
64
+ sourceAgent: "hicortex/seed",
65
+ project: "global",
66
+ memoryType: "lesson",
67
+ baseStrength: 0.95,
68
+ privacy: "WORK",
69
+ });
70
+ log("[hicortex] Seed lesson injected: Daily Self-Improvement Protocol");
71
+ }
72
+ catch (err) {
73
+ const msg = err instanceof Error ? err.message : String(err);
74
+ log(`[hicortex] Warning: could not inject seed lesson: ${msg}`);
75
+ }
76
+ }
@@ -2,7 +2,7 @@
2
2
  "id": "hicortex",
3
3
  "name": "Hicortex — Long-term Memory That Learns",
4
4
  "description": "Your agents remember past decisions, avoid repeated mistakes, and get smarter every day. Nightly reflection generates actionable lessons that automatically update agent behavior.",
5
- "version": "0.3.5",
5
+ "version": "0.3.7",
6
6
  "kind": "lifecycle",
7
7
  "skills": ["./skills/hicortex-memory", "./skills/hicortex-learn", "./skills/hicortex-activate"],
8
8
  "configSchema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamaze/hicortex",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Human-like memory for self-improving AI agents. Automatic capturing, nightly reflection, and cross-agent learning. Works with Claude Code and OpenClaw.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {