niahere 0.2.18 → 0.2.19

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.
@@ -8,7 +8,7 @@ Write here when:
8
8
  - I learned a preference, habit, or pattern worth remembering
9
9
  - A workaround was needed that future-me should know about
10
10
 
11
- Format: `- YYYY-MM-DD: what happened and what I learned`
11
+ Entries are grouped by date. Use `add_memory` tool to append, or edit directly.
12
12
 
13
13
  ---
14
14
 
@@ -0,0 +1,9 @@
1
+ # Rules
2
+
3
+ Custom instructions and behavioral overrides. Nia reads this file at the start of every session — edits take effect immediately without restart.
4
+
5
+ Add rules here to change how Nia behaves. Examples:
6
+
7
+ - "When asked for a standup, keep it to 1-2 lines"
8
+ - "Always use bullet points for status updates"
9
+ - "Never send messages longer than 3 sentences in Slack channels"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "niahere",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "A personal AI assistant daemon — scheduled jobs, chat across Telegram and Slack, persona system, and visual identity.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -8,6 +8,11 @@ import { log } from "../utils/log";
8
8
  import { getMcpServers } from "../mcp";
9
9
  import { classifyMime, validateAttachment, prepareImage } from "../utils/attachment";
10
10
 
11
+ /** Strip markdown backticks so sentinel tokens like [NO_REPLY] match even when the LLM wraps them. */
12
+ function cleanSentinel(text: string): string {
13
+ return text.replace(/`/g, "").trim();
14
+ }
15
+
11
16
  class SlackChannel implements Channel {
12
17
  name = "slack";
13
18
  private app: App | null = null;
@@ -364,7 +369,7 @@ class SlackChannel implements Channel {
364
369
  const reply = result.trim();
365
370
 
366
371
  // [NO_REPLY] or empty = agent chose not to respond (thread judgement)
367
- if (!reply || reply === "[NO_REPLY]") {
372
+ if (!reply || cleanSentinel(reply) === "[NO_REPLY]") {
368
373
  log.info({ channel: msg.channel, key }, "slack: agent chose not to reply");
369
374
  return;
370
375
  }
@@ -18,7 +18,7 @@ function loadFile(dir: string, name: string): string {
18
18
 
19
19
  export function loadIdentity(): string {
20
20
  const { selfDir } = getPaths();
21
- const files = ["identity.md", "owner.md", "soul.md"];
21
+ const files = ["identity.md", "owner.md", "soul.md", "rules.md"];
22
22
  return files.map((f) => loadFile(selfDir, f)).filter(Boolean).join("\n\n");
23
23
  }
24
24
 
@@ -427,8 +427,9 @@ export async function runInit(): Promise<void> {
427
427
  console.log(` \u2713 wrote ${selfFile("owner.md")}`);
428
428
  }
429
429
 
430
- // Soul and memory — only create if missing (user may have customized)
430
+ // Soul, rules, and memory — only create if missing (user may have customized)
431
431
  writeIfMissing(selfFile("soul.md"), loadTemplate("soul.md", vars), selfFile("soul.md"));
432
+ writeIfMissing(selfFile("rules.md"), loadTemplate("rules.md", vars), selfFile("rules.md"));
432
433
  writeIfMissing(selfFile("memory.md"), loadTemplate("memory.md", vars), selfFile("memory.md"));
433
434
 
434
435
  resetConfig();
package/src/mcp/server.ts CHANGED
@@ -84,6 +84,26 @@ export function createNiaMcpServer() {
84
84
  content: [{ type: "text" as const, text: await handlers.listMessages(args.limit, args.room) }],
85
85
  }),
86
86
  ),
87
+ tool(
88
+ "add_rule",
89
+ "Add a behavioral rule. Rules are loaded into every session and take effect without restart. Use for 'from now on' / 'always' / 'never' type instructions.",
90
+ {
91
+ rule: z.string().describe("The rule to add (e.g. 'stamp updates: 1-2 lines max, no preamble')"),
92
+ },
93
+ async (args) => ({
94
+ content: [{ type: "text" as const, text: handlers.addRule(args.rule) }],
95
+ }),
96
+ ),
97
+ tool(
98
+ "add_memory",
99
+ "Save a factual memory for future reference. Memories are read on demand, not loaded automatically. Use for things learned, preferences discovered, or context worth keeping.",
100
+ {
101
+ entry: z.string().describe("What to remember (e.g. 'Aman prefers short Slack messages in #tech')"),
102
+ },
103
+ async (args) => ({
104
+ content: [{ type: "text" as const, text: handlers.addMemory(args.entry) }],
105
+ }),
106
+ ),
87
107
  ],
88
108
  });
89
109
  }
package/src/mcp/tools.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { readFileSync, existsSync } from "fs";
1
+ import { readFileSync, writeFileSync, appendFileSync, existsSync } from "fs";
2
2
  import type { ScheduleType } from "../types";
3
- import { basename } from "path";
3
+ import { basename, join } from "path";
4
4
  import { Job, Message, Session } from "../db/models";
5
5
  import { computeInitialNextRun } from "../core/scheduler";
6
6
  import { getConfig } from "../utils/config";
7
+ import { getPaths } from "../utils/paths";
7
8
  import { getChannel } from "../channels/registry";
8
9
  import { log } from "../utils/log";
9
10
  import { classifyMime } from "../utils/attachment";
@@ -219,3 +220,29 @@ export async function listMessages(limit = 20, room?: string): Promise<string> {
219
220
  if (messages.length === 0) return "No messages found.";
220
221
  return JSON.stringify(messages, null, 2);
221
222
  }
223
+
224
+ export function addRule(rule: string): string {
225
+ const { selfDir } = getPaths();
226
+ const rulesPath = join(selfDir, "rules.md");
227
+ const line = `\n- ${rule}\n`;
228
+ appendFileSync(rulesPath, line, "utf8");
229
+ return `Rule added to rules.md. Takes effect on next new session.`;
230
+ }
231
+
232
+ export function addMemory(entry: string): string {
233
+ const { selfDir } = getPaths();
234
+ const memoryPath = join(selfDir, "memory.md");
235
+ const date = new Date().toISOString().slice(0, 10);
236
+ const header = `\n## ${date}`;
237
+
238
+ const existing = existsSync(memoryPath) ? readFileSync(memoryPath, "utf8") : "";
239
+ if (existing.includes(header)) {
240
+ // Append under existing date header
241
+ const updated = existing.replace(header, `${header}\n- ${entry}`);
242
+ writeFileSync(memoryPath, updated, "utf8");
243
+ } else {
244
+ // New date section
245
+ appendFileSync(memoryPath, `${header}\n- ${entry}\n`, "utf8");
246
+ }
247
+ return `Memory saved.`;
248
+ }
@@ -22,6 +22,8 @@ You have MCP tools for managing jobs directly — no need for shell commands:
22
22
  - **run_job** — trigger a job to run immediately
23
23
  - **send_message** — send a message to the user (via telegram, slack, or default channel). Supports `media_path` to send images/files.
24
24
  - **list_messages** — read recent chat history
25
+ - **add_rule** — save a behavioral rule (loaded into every session, no restart needed). Use when told "from now on", "always", "never", or "remember to always..."
26
+ - **add_memory** — save a factual memory (read on demand). Use when told "remember that...", or when you learn something surprising worth keeping
25
27
 
26
28
  Active hours: {{activeStart}}–{{activeEnd}} ({{timezone}}). Jobs respect this; crons (always=true) don't.
27
29
 
@@ -62,10 +64,22 @@ Your persona files live in {{selfDir}}/:
62
64
  - `identity.md` — your personality and voice
63
65
  - `owner.md` — info about who runs you
64
66
  - `soul.md` — how you work
65
- - `memory.md` — persistent learnings (read/write on demand, not loaded automatically)
67
+ - `rules.md` — behavioral overrides and custom instructions (loaded into every session, hot-reloads without restart)
68
+ - `memory.md` — persistent learnings (read on demand, not loaded automatically)
66
69
 
67
- Memory is NOT loaded into your context automatically. Read it when you need context, write to it when you learn something worth keeping.
70
+ ### Rules vs Memory
68
71
 
69
- - **Read** when: you're unsure about a preference, a past issue, or something you might have seen before.
70
- - **Write** when: something surprised you, you were corrected, or you found a workaround future-you should know.
71
- - Append with: `echo "- $(date +%Y-%m-%d): <what you learned>" >> {{selfDir}}/memory.md`
72
+ **Rules** (`rules.md`) = instructions for how to behave. Loaded into every session automatically.
73
+ - "stamp updates should be 1-2 lines max"
74
+ - "never send long messages in #tech"
75
+ - Use `add_rule` tool to add new rules, or edit the file directly.
76
+
77
+ **Memory** (`memory.md`) = facts and context. Read on demand when relevant.
78
+ - "2026-03-13: DB was down, Telegram send failed"
79
+ - "Aman prefers terminal over Slack for debugging"
80
+ - Use `add_memory` tool to save new memories.
81
+
82
+ **Which to use?**
83
+ - "From now on, do X" → rule
84
+ - "Remember that X happened" / "I prefer X" → memory
85
+ - If unsure, ask.
@@ -3,4 +3,6 @@
3
3
  You are executing a scheduled job. Be terse — execute the task and report the result. No small talk.
4
4
 
5
5
  - State the outcome first, then supporting details if needed.
6
- - If the job failed, report what went wrong clearly.
6
+ - If the job failed, report what went wrong clearly.
7
+ - When sending results to a channel (Slack, Telegram), keep it minimal. The recipient knows the context — just deliver the key info.
8
+ - Check rules.md for job-specific output instructions (e.g. brevity rules for specific jobs like stamp/standup).