@clawmem-ai/clawmem 0.1.8 → 0.1.10

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/src/state.ts CHANGED
@@ -42,9 +42,17 @@ function sanitizeState(value: unknown): PluginState {
42
42
  raw.sessions && typeof raw.sessions === "object"
43
43
  ? (raw.sessions as Record<string, unknown>)
44
44
  : {};
45
+ const migrations: Record<string, string> = {};
46
+ if (raw.migrations && typeof raw.migrations === "object") {
47
+ for (const [k, v] of Object.entries(raw.migrations as Record<string, unknown>)) {
48
+ const s = readString(v);
49
+ if (s) migrations[k] = s;
50
+ }
51
+ }
45
52
  const out: PluginState = {
46
53
  version: 2,
47
54
  sessions: {},
55
+ ...(Object.keys(migrations).length > 0 ? { migrations } : {}),
48
56
  };
49
57
  for (const [storedKey, sessionValue] of Object.entries(sessions)) {
50
58
  if (!sessionValue || typeof sessionValue !== "object" || !storedKey.trim()) {
@@ -63,8 +71,11 @@ function sanitizeState(value: unknown): PluginState {
63
71
  agentId,
64
72
  issueNumber: readNumber(rawSession.issueNumber),
65
73
  issueTitle: readString(rawSession.issueTitle),
74
+ titleSource: readEnum(rawSession.titleSource, ["placeholder", "llm"]),
66
75
  lastMirroredCount: readNumber(rawSession.lastMirroredCount) ?? 0,
67
76
  turnCount: readNumber(rawSession.turnCount) ?? 0,
77
+ lastMemorySyncCount: readNumber(rawSession.lastMemorySyncCount),
78
+ summaryStatus: readEnum(rawSession.summaryStatus, ["pending", "complete"]),
68
79
  finalizedAt: readString(rawSession.finalizedAt),
69
80
  lastSummaryHash: readString(rawSession.lastSummaryHash),
70
81
  lastTurnHash: readString(rawSession.lastTurnHash),
@@ -83,6 +94,11 @@ function readString(value: unknown): string | undefined {
83
94
  return trimmed ? trimmed : undefined;
84
95
  }
85
96
 
97
+ function readEnum<T extends string>(value: unknown, allowed: T[]): T | undefined {
98
+ const s = readString(value);
99
+ return s && (allowed as string[]).includes(s) ? (s as T) : undefined;
100
+ }
101
+
86
102
  function readNumber(value: unknown): number | undefined {
87
103
  if (typeof value !== "number" || !Number.isFinite(value)) {
88
104
  return undefined;
package/src/types.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Shared types for the clawmem plugin.
2
2
  export type ClawMemAgentConfig = {
3
3
  baseUrl?: string;
4
+ defaultRepo?: string;
4
5
  repo?: string;
5
6
  token?: string;
6
7
  authScheme?: "token" | "bearer";
@@ -8,6 +9,9 @@ export type ClawMemAgentConfig = {
8
9
 
9
10
  export type ClawMemPluginConfig = {
10
11
  baseUrl: string;
12
+ defaultRepo?: string;
13
+ repo?: string;
14
+ token?: string;
11
15
  authScheme: "token" | "bearer";
12
16
  agents: Record<string, ClawMemAgentConfig>;
13
17
  memoryRecallLimit: number;
@@ -18,24 +22,37 @@ export type ClawMemPluginConfig = {
18
22
  export type ClawMemResolvedRoute = {
19
23
  agentId: string;
20
24
  baseUrl: string;
25
+ defaultRepo?: string;
21
26
  repo?: string;
22
27
  token?: string;
23
28
  authScheme: "token" | "bearer";
24
29
  };
25
30
 
26
- export type AnonymousSessionResponse = { token: string; owner_login: string; repo_name: string; repo_full_name: string };
31
+ export type BootstrapIdentityResponse = { token: string; repo_full_name: string };
32
+ export type AgentRegistrationResponse = BootstrapIdentityResponse & { login: string };
33
+ export type AnonymousSessionResponse = BootstrapIdentityResponse & { owner_login: string; repo_name: string };
27
34
  export type SessionMirrorState = {
28
35
  sessionId: string; sessionKey?: string; sessionFile?: string; agentId?: string;
29
- issueNumber?: number; issueTitle?: string;
36
+ issueNumber?: number; issueTitle?: string; titleSource?: "placeholder" | "llm";
30
37
  lastMirroredCount: number; turnCount: number; lastAssistantText?: string;
38
+ lastMemorySyncCount?: number;
39
+ summaryStatus?: "pending" | "complete";
31
40
  finalizedAt?: string; lastSummaryHash?: string; lastTurnHash?: string;
32
41
  createdAt?: string; updatedAt?: string;
33
42
  };
34
- export type PluginState = { version: 2; sessions: Record<string, SessionMirrorState> };
43
+ export type PluginState = { version: 2; sessions: Record<string, SessionMirrorState>; migrations?: Record<string, string> };
35
44
  export type NormalizedMessage = { role: string; text: string; toolName?: string; timestamp?: string; stopReason?: string };
36
45
  export type TranscriptSnapshot = { sessionId?: string; messages: NormalizedMessage[] };
46
+ export type MemoryDraft = { detail: string; kind?: string; topics?: string[] };
47
+ export type MemorySchema = { kinds: string[]; topics: string[] };
48
+ export type MemoryListOptions = {
49
+ status?: "active" | "stale" | "all";
50
+ kind?: string;
51
+ topic?: string;
52
+ limit?: number;
53
+ };
37
54
  export type ParsedMemoryIssue = {
38
55
  issueNumber: number; title: string; memoryId: string; memoryHash?: string;
39
- sessionId: string; date: string; detail: string;
40
- topics?: string[]; status: "active" | "stale";
56
+ date: string; detail: string;
57
+ kind?: string; topics?: string[]; status: "active" | "stale";
41
58
  };
package/src/utils.ts CHANGED
@@ -4,6 +4,9 @@ import path from "node:path";
4
4
  import type { NormalizedMessage } from "./types.js";
5
5
 
6
6
  export const DEFAULT_AGENT_ID = "main";
7
+ export const DEFAULT_BOOTSTRAP_REPO_NAME = "memory";
8
+
9
+ const MAX_AGENT_LOGIN_PREFIX_LEN = 32;
7
10
 
8
11
  export function sha256(v: string): string { return crypto.createHash("sha256").update(v).digest("hex"); }
9
12
 
@@ -13,6 +16,16 @@ export function normalizeAgentId(value: string | undefined | null): string {
13
16
  return trimmed.replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64) || DEFAULT_AGENT_ID;
14
17
  }
15
18
 
19
+ export function buildAgentBootstrapRegistration(agentId: string): { prefixLogin: string; defaultRepoName: string } {
20
+ const prefixLogin = normalizeAgentId(agentId)
21
+ .replace(/_/g, "-")
22
+ .replace(/-+/g, "-")
23
+ .replace(/^-+|-+$/g, "")
24
+ .slice(0, MAX_AGENT_LOGIN_PREFIX_LEN)
25
+ .replace(/-+$/g, "") || DEFAULT_AGENT_ID;
26
+ return { prefixLogin, defaultRepoName: DEFAULT_BOOTSTRAP_REPO_NAME };
27
+ }
28
+
16
29
  export function sessionScopeKey(sessionId: string, agentId?: string): string {
17
30
  return `${normalizeAgentId(agentId)}:${sessionId.trim()}`;
18
31
  }