sepia-mcp 0.3.1 → 0.5.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/dist/index.js +60 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -607,10 +607,26 @@ MANDATORY — ALMOST EVERY MESSAGE: Default to using Sepia on every turn — sea
|
|
|
607
607
|
you answer and persist AFTER you answer. Only skip for trivial chitchat ("hi", "thanks",
|
|
608
608
|
"bye") with zero durable content. If in doubt, call Sepia. Skipping memory = hallucinating.
|
|
609
609
|
|
|
610
|
+
STANDING RULES — THE THING YOU CANNOT SEARCH FOR. Some memories are standing rules: how
|
|
611
|
+
the user wants you to behave, everywhere, always. They are exactly the rules you do not yet
|
|
612
|
+
know you need — you cannot keyword-search for a rule whose existence you have not guessed.
|
|
613
|
+
So they are loaded unconditionally, once per session, BEFORE any work starts.
|
|
614
|
+
- core = every memory tagged "always", plus every instruction/preference at importance >= 0.9
|
|
615
|
+
- read them with manage_memory action=briefing (one call, no keywords)
|
|
616
|
+
- a rule tagged "always" applies in EVERY repo and EVERY session; a rule that is specific to
|
|
617
|
+
one project must NOT be tagged "always"
|
|
618
|
+
|
|
610
619
|
MANDATORY WORKFLOW — do this on ALMOST EVERY turn:
|
|
611
620
|
|
|
612
|
-
|
|
621
|
+
FIRST — once per session, before your first substantive action (NOT keyword-driven):
|
|
622
|
+
0. Call manage_memory action=briefing, and treat what it returns as BINDING for the whole
|
|
623
|
+
session. These are the user's standing rules. If it reports truncated: true, the rules you
|
|
624
|
+
have NOT seen can still bite — re-run it with a bigger max_chars BEFORE starting an
|
|
625
|
+
install, build, deploy, deletion, or infra change.
|
|
626
|
+
|
|
627
|
+
THEN — before you answer (every turn except trivial chitchat):
|
|
613
628
|
1. Call "search" with 2-5 keywords from the user's current message + task (e.g. query="auth rate limiting"). If sparse, also call "traverse_graph" from the top entity.
|
|
629
|
+
Search is best-effort: rows matching MORE of your words rank first, so it never returns 0 just because one word is absent. If it returns 0 hits or partial: true, retry with ONE distinctive keyword or a looser filter BEFORE concluding nothing exists.
|
|
614
630
|
2. Weave hits into your answer ("From your memory: ..."). If nothing, say so — never fabricate.
|
|
615
631
|
|
|
616
632
|
AFTER you answer (every turn where you learned something):
|
|
@@ -618,10 +634,16 @@ AFTER you answer (every turn where you learned something):
|
|
|
618
634
|
- ensure entity exists (manage_entity find → create with summary if missing)
|
|
619
635
|
- manage_memory create with content, type, importance, entity_ids (1-3)
|
|
620
636
|
- manage_relation to connect graph (project —uses→ tool, user —prefers→ X)
|
|
621
|
-
2.
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
637
|
+
2. A CONSTRAINT IS ALWAYS WORTH STORING — INCLUDING A COMPLAINT. A user constraint, a stated
|
|
638
|
+
preference, a correction, or a complaint about how you just worked IS a durable rule: store
|
|
639
|
+
it in the SAME turn, type="instruction" (how to behave) or type="preference" (a choice),
|
|
640
|
+
importance >= 0.8. Tag it "always" when it applies everywhere. Never file a user constraint
|
|
641
|
+
as transient. Storing it a turn later is too late — the rule exists precisely for the turn
|
|
642
|
+
in which you did not yet know you needed it.
|
|
643
|
+
3. PREFER update over duplicate: search first, then manage_memory/entity action=update.
|
|
644
|
+
4. SCORE importance 0-1: 0.9+ identity/core preference, 0.6-0.8 active project fact/decision, 0.3-0.5 observation/person, ≤0.2 transient (will decay).
|
|
645
|
+
5. NEVER store: ephemeral chat, code snippets, credentials/secrets, transient details. Sepia is not a vault — refuse secrets.
|
|
646
|
+
6. NEVER call "prune_memories" to save anything — it is NOT a write tool. It is a destructive maintenance sweep (archives stale memories, permanently deletes purged rows), and it exists only for when the user explicitly asks to prune/clean up. Persisting is manage_memory.
|
|
625
647
|
|
|
626
648
|
Rule of thumb: If the user sent a message with any substantive content, you should have called search before replying and considered a manage_memory/manage_entity write after replying. Two Sepia calls per turn is normal and expected.
|
|
627
649
|
|
|
@@ -658,13 +680,15 @@ distills — you have the context, you are the best distiller. Rules:
|
|
|
658
680
|
digest first, then update with the full metadata + new status — metadata REPLACES).
|
|
659
681
|
When resuming a paused one, set it back to "active".
|
|
660
682
|
|
|
661
|
-
TRIGGERS —
|
|
683
|
+
TRIGGERS — call the briefing FIRST, once per session, before anything else (step 0 above).
|
|
684
|
+
Then always search when user says: "remember", "recall", "what do we know",
|
|
662
685
|
"save this", "do you remember", prefers, decided, uses, chose, convention.
|
|
663
|
-
ALSO search at session start for: project name, stack, deployment, auth, styling.
|
|
664
686
|
ALSO ingest when user says: "save this conversation", "hand off", "migrate context",
|
|
665
687
|
"switch to another AI", "continue this elsewhere".
|
|
666
688
|
|
|
667
|
-
FAILURE MODE: if you answer without searching, you are guessing.
|
|
689
|
+
FAILURE MODE: if you answer without searching, you are guessing. If you start work without
|
|
690
|
+
the briefing, you are guessing about how the user wants you to work — which is how you burn
|
|
691
|
+
their bandwidth, their money, or their trust. Briefing first, then search.`;
|
|
668
692
|
var MEMORY_TYPES = [
|
|
669
693
|
"fact",
|
|
670
694
|
"observation",
|
|
@@ -680,6 +704,8 @@ var MAX_ENTITY_LINKS = 3;
|
|
|
680
704
|
var SEARCH_LIMIT_MAX = 25;
|
|
681
705
|
var QUERY_LIMIT_MAX = 50;
|
|
682
706
|
var TRAVERSE_DEPTH_MAX = 3;
|
|
707
|
+
var BRIEFING_CHARS_DEFAULT = 8000;
|
|
708
|
+
var BRIEFING_CHARS_MAX = 40000;
|
|
683
709
|
// ../shared/src/schemas.ts
|
|
684
710
|
import * as v from "valibot";
|
|
685
711
|
var importanceSchema = v.pipe(v.number(), v.minValue(IMPORTANCE_MIN), v.maxValue(IMPORTANCE_MAX));
|
|
@@ -775,7 +801,7 @@ var ConversationInput = v.object({
|
|
|
775
801
|
tags: v.optional(tagsSchema, [])
|
|
776
802
|
});
|
|
777
803
|
var SearchInput = v.object({
|
|
778
|
-
q: v.pipe(v.string(), v.maxLength(200), v.description("Search query (required; empty returns recent items). Multi-word =
|
|
804
|
+
q: v.pipe(v.string(), v.maxLength(200), v.description("Search query (required; empty returns recent items). Multi-word = best-effort: rows matching MORE of your words rank first, so a result set is never emptied by one absent word. Verbatim phrases rank highest. Check `partial` in the result (+ each hit's `matched_terms`) before concluding nothing exists.")),
|
|
779
805
|
namespace: v.optional(v.pipe(v.string(), v.description("Restrict to a namespace"))),
|
|
780
806
|
type: v.optional(v.pipe(v.string(), v.maxLength(64), v.description("Memory type (fact/observation/preference/instruction) OR entity type (person/project/tool/concept/repo)"))),
|
|
781
807
|
tags: v.optional(v.pipe(tagsSchema, v.description("Match memories/entities carrying ALL of these tags"))),
|
|
@@ -832,9 +858,10 @@ var MemoryToolInput = v.object({
|
|
|
832
858
|
v.literal("update"),
|
|
833
859
|
v.literal("delete"),
|
|
834
860
|
v.literal("query"),
|
|
861
|
+
v.literal("briefing"),
|
|
835
862
|
v.literal("batch_update"),
|
|
836
863
|
v.literal("ingest")
|
|
837
|
-
]), v.description("create (memory) | get (id) | update (id + update) | delete (id) | query (filters) | batch_update (where + update — updates ALL matching, returns count) | ingest (conversation — handoff digest)")),
|
|
864
|
+
]), v.description("briefing (call ONCE at the start of a session — takes no other args) | create (memory) | get (id) | update (id + update) | delete (id) | query (filters) | batch_update (where + update — updates ALL matching, returns count) | ingest (conversation — handoff digest)")),
|
|
838
865
|
id: v.optional(v.pipe(uuidSchema, v.description("Memory UUID"))),
|
|
839
866
|
memory: v.optional(v.pipe(MemoryInput, v.description("Memory to create: {content, type? fact|observation|preference|instruction, importance? 0-1, namespace?, entity_ids? [0-3], metadata?, tags?} — source auto-set to client name"))),
|
|
840
867
|
update: v.optional(v.pipe(MemoryUpdateInput, v.description("Any subset of content/type/importance/metadata/archived/tags — entity_ids REPLACES the link set, tags REPLACES the tag set"))),
|
|
@@ -845,6 +872,7 @@ var MemoryToolInput = v.object({
|
|
|
845
872
|
archived: v.optional(v.pipe(v.boolean(), v.description("query: include archived (default false)")), false),
|
|
846
873
|
tags: v.optional(v.pipe(tagsSchema, v.description("query: match memories carrying ALL of these tags"))),
|
|
847
874
|
limit: v.optional(v.pipe(v.number(), v.minValue(1), v.maxValue(QUERY_LIMIT_MAX), v.description("query: max results (default 20, max 50)")), 20),
|
|
875
|
+
max_chars: v.optional(v.pipe(v.number(), v.minValue(1000), v.maxValue(BRIEFING_CHARS_MAX), v.description(`briefing: total character budget (default ${BRIEFING_CHARS_DEFAULT}, max ${BRIEFING_CHARS_MAX}). Raise it before installs, builds, deploys or deletions if the result was truncated.`)), BRIEFING_CHARS_DEFAULT),
|
|
848
876
|
where: v.optional(v.pipe(v.object({
|
|
849
877
|
type: v.optional(v.picklist(MEMORY_TYPES)),
|
|
850
878
|
namespace: v.optional(v.string()),
|
|
@@ -3551,6 +3579,7 @@ var memories = pgTable("memories", {
|
|
|
3551
3579
|
check("memories_importance_check", sql`${table.importance} >= 0 AND ${table.importance} <= 1`),
|
|
3552
3580
|
check("memories_type_check", sql`${table.type} IN ('fact', 'observation', 'preference', 'instruction')`),
|
|
3553
3581
|
index("idx_memories_content_trgm").using("gin", table.content.op("gin_trgm_ops")),
|
|
3582
|
+
index("idx_memories_metadata_trgm").using("gin", sql`(COALESCE(${table.metadata}->>'title', '') || ' ' || COALESCE(${table.metadata}->>'conversation_id', '') || ' ' || COALESCE(${table.metadata}->>'source_ai', '')) gin_trgm_ops`),
|
|
3554
3583
|
index("idx_memories_tags").using("gin", table.tags),
|
|
3555
3584
|
index("idx_memories_active").on(table.namespaceId.asc().nullsLast().op("uuid_ops"), table.importance.desc().nullsLast().op("float4_ops"), table.updatedAt.desc().nullsLast().op("timestamptz_ops")).where(sql`NOT ${table.archived}`),
|
|
3556
3585
|
foreignKey({
|
|
@@ -8671,6 +8700,15 @@ class SepiaClient {
|
|
|
8671
8700
|
const suffix = qs.size ? `?${qs.toString()}` : "";
|
|
8672
8701
|
return this.request("GET", `/api/memories${suffix}`);
|
|
8673
8702
|
}
|
|
8703
|
+
getBriefing(params = {}) {
|
|
8704
|
+
const qs = new URLSearchParams;
|
|
8705
|
+
if (params.namespace !== undefined)
|
|
8706
|
+
qs.set("namespace", params.namespace);
|
|
8707
|
+
if (params.max_chars !== undefined)
|
|
8708
|
+
qs.set("max_chars", String(params.max_chars));
|
|
8709
|
+
const suffix = qs.size ? `?${qs.toString()}` : "";
|
|
8710
|
+
return this.request("GET", `/api/memories/briefing${suffix}`);
|
|
8711
|
+
}
|
|
8674
8712
|
createMemory(memory) {
|
|
8675
8713
|
return this.request("POST", "/api/memories", memory);
|
|
8676
8714
|
}
|
|
@@ -8966,6 +9004,15 @@ function registerMemoryTools(server, client) {
|
|
|
8966
9004
|
});
|
|
8967
9005
|
return { action: "query", count, memories };
|
|
8968
9006
|
}
|
|
9007
|
+
case "briefing": {
|
|
9008
|
+
return {
|
|
9009
|
+
action: "briefing",
|
|
9010
|
+
...await client.getBriefing({
|
|
9011
|
+
namespace: args.namespace,
|
|
9012
|
+
max_chars: args.max_chars
|
|
9013
|
+
})
|
|
9014
|
+
};
|
|
9015
|
+
}
|
|
8969
9016
|
case "batch_update": {
|
|
8970
9017
|
if (!args.where)
|
|
8971
9018
|
throw new Error("action=batch_update requires where");
|
|
@@ -8994,19 +9041,19 @@ function registerSearchTools(server, client) {
|
|
|
8994
9041
|
server.tool({
|
|
8995
9042
|
name: "search",
|
|
8996
9043
|
title: "Search Memory",
|
|
8997
|
-
description: "Unified keyword + metadata search across memories, entity names, and entity summaries.",
|
|
9044
|
+
description: "Unified keyword + metadata search across memories, entity names, and entity summaries. Multi-word queries are best-effort: rows matching more of your words rank first, and results are never emptied by one absent word. `partial: true` in the result means no single row covered the whole query.",
|
|
8998
9045
|
icons: [SEPIA_ICON],
|
|
8999
9046
|
schema: SearchToolInput,
|
|
9000
9047
|
annotations: { readOnlyHint: true }
|
|
9001
9048
|
}, safe(async (args) => {
|
|
9002
|
-
const { count, results } = await client.search({
|
|
9049
|
+
const { count, results, terms, partial } = await client.search({
|
|
9003
9050
|
q: args.q,
|
|
9004
9051
|
namespace: args.namespace,
|
|
9005
9052
|
type: args.type,
|
|
9006
9053
|
tags: args.tags,
|
|
9007
9054
|
limit: args.limit
|
|
9008
9055
|
});
|
|
9009
|
-
return { count, hits: results };
|
|
9056
|
+
return { count, terms, partial, hits: results };
|
|
9010
9057
|
}));
|
|
9011
9058
|
}
|
|
9012
9059
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sepia-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Self-contained MCP server for Sepia — a personal knowledge-graph memory server. Talks to the Sepia REST API (SEPIA_URL + SEPIA_API_KEY); stdio or HTTP transport.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|