@iamem/amem 0.1.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/LICENSE +21 -0
- package/README.md +534 -0
- package/dist/activity.d.ts +27 -0
- package/dist/activity.js +202 -0
- package/dist/api/routes.d.ts +31 -0
- package/dist/api/routes.js +1345 -0
- package/dist/attest.d.ts +52 -0
- package/dist/attest.js +192 -0
- package/dist/backup-schedule.d.ts +25 -0
- package/dist/backup-schedule.js +216 -0
- package/dist/capture.d.ts +34 -0
- package/dist/capture.js +257 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1007 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.js +334 -0
- package/dist/crypto.d.ts +39 -0
- package/dist/crypto.js +166 -0
- package/dist/db.d.ts +192 -0
- package/dist/db.js +666 -0
- package/dist/draft-quality.d.ts +19 -0
- package/dist/draft-quality.js +85 -0
- package/dist/embed.d.ts +76 -0
- package/dist/embed.js +331 -0
- package/dist/estimate.d.ts +32 -0
- package/dist/estimate.js +69 -0
- package/dist/freshness.d.ts +15 -0
- package/dist/freshness.js +93 -0
- package/dist/hook.d.ts +16 -0
- package/dist/hook.js +177 -0
- package/dist/hygiene-schedule.d.ts +28 -0
- package/dist/hygiene-schedule.js +221 -0
- package/dist/hygiene.d.ts +61 -0
- package/dist/hygiene.js +196 -0
- package/dist/install/claude.d.ts +6 -0
- package/dist/install/claude.js +69 -0
- package/dist/install/cursor.d.ts +7 -0
- package/dist/install/cursor.js +80 -0
- package/dist/install/hosts.d.ts +21 -0
- package/dist/install/hosts.js +186 -0
- package/dist/install/skills.d.ts +8 -0
- package/dist/install/skills.js +67 -0
- package/dist/it-pack.d.ts +20 -0
- package/dist/it-pack.js +84 -0
- package/dist/kinds.d.ts +18 -0
- package/dist/kinds.js +106 -0
- package/dist/license.d.ts +48 -0
- package/dist/license.js +172 -0
- package/dist/mcp.d.ts +40 -0
- package/dist/mcp.js +435 -0
- package/dist/paths.d.ts +11 -0
- package/dist/paths.js +55 -0
- package/dist/personal.d.ts +7 -0
- package/dist/personal.js +44 -0
- package/dist/platforms.d.ts +11 -0
- package/dist/platforms.js +32 -0
- package/dist/policy.d.ts +46 -0
- package/dist/policy.js +254 -0
- package/dist/prefs.d.ts +6 -0
- package/dist/prefs.js +11 -0
- package/dist/proposal.d.ts +90 -0
- package/dist/proposal.js +376 -0
- package/dist/publish.d.ts +28 -0
- package/dist/publish.js +57 -0
- package/dist/remember-contract.d.ts +23 -0
- package/dist/remember-contract.js +117 -0
- package/dist/repo-identity.d.ts +15 -0
- package/dist/repo-identity.js +82 -0
- package/dist/rules-sync.d.ts +7 -0
- package/dist/rules-sync.js +47 -0
- package/dist/savings-export.d.ts +49 -0
- package/dist/savings-export.js +141 -0
- package/dist/scan.d.ts +16 -0
- package/dist/scan.js +109 -0
- package/dist/search.d.ts +25 -0
- package/dist/search.js +150 -0
- package/dist/service.d.ts +20 -0
- package/dist/service.js +254 -0
- package/dist/shop.d.ts +9 -0
- package/dist/shop.js +15 -0
- package/dist/ui/server.d.ts +21 -0
- package/dist/ui/server.js +268 -0
- package/dist/vault.d.ts +25 -0
- package/dist/vault.js +42 -0
- package/dist/workspace-setup.d.ts +8 -0
- package/dist/workspace-setup.js +55 -0
- package/docs/agent-install-prompt.md +41 -0
- package/docs/backlog.md +59 -0
- package/docs/enterprise-endpoint.md +98 -0
- package/docs/license.md +54 -0
- package/docs/npm-release.md +38 -0
- package/docs/remember-contract.md +42 -0
- package/package.json +64 -0
- package/scripts/mdm-offboard.sh +14 -0
- package/skills/amem-bootstrap/SKILL.md +83 -0
- package/skills/amem-update-working-memory/SKILL.md +54 -0
- package/templates/cursor-rule.mdc +23 -0
- package/templates/mdm/co.amem.managed.plist +33 -0
- package/templates/policy.deny-default.toml +20 -0
- package/templates/policy.example.toml +22 -0
- package/ui-static/app.js +3966 -0
- package/ui-static/index.html +178 -0
- package/ui-static/orbit.js +389 -0
- package/ui-static/styles.css +2411 -0
package/dist/activity.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { estimateMsSaved, eventKind } from "./estimate.js";
|
|
2
|
+
export function speedForEvent(e) {
|
|
3
|
+
const kind = e.kind === "local_hit" || e.kind === "server_trip"
|
|
4
|
+
? e.kind
|
|
5
|
+
: eventKind(e.claims_count);
|
|
6
|
+
return {
|
|
7
|
+
kind,
|
|
8
|
+
estimatedMsSaved: e.estimated_ms_saved ??
|
|
9
|
+
estimateMsSaved({ anchorsCount: e.anchors_count, claimsCount: e.claims_count }),
|
|
10
|
+
localMs: e.local_ms ?? null,
|
|
11
|
+
anchorsCount: e.anchors_count,
|
|
12
|
+
claimsCount: e.claims_count,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function llmId(platform) {
|
|
16
|
+
return `llm.${platform || "unknown"}`;
|
|
17
|
+
}
|
|
18
|
+
function sessionNodeId(platform, sessionId) {
|
|
19
|
+
return `session.${platform}.${sessionId}`;
|
|
20
|
+
}
|
|
21
|
+
function shortSession(id) {
|
|
22
|
+
if (!id || id === "unknown")
|
|
23
|
+
return "unknown session";
|
|
24
|
+
return id.length > 14 ? `${id.slice(0, 8)}…` : id;
|
|
25
|
+
}
|
|
26
|
+
export function buildActivityGraph(input) {
|
|
27
|
+
const nodes = [];
|
|
28
|
+
const links = [];
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
const seenLinks = new Set();
|
|
31
|
+
const push = (node) => {
|
|
32
|
+
if (seen.has(node.id))
|
|
33
|
+
return;
|
|
34
|
+
seen.add(node.id);
|
|
35
|
+
nodes.push(node);
|
|
36
|
+
};
|
|
37
|
+
const link = (from, to, kind) => {
|
|
38
|
+
const key = `${from}|${to}|${kind}`;
|
|
39
|
+
if (seenLinks.has(key))
|
|
40
|
+
return;
|
|
41
|
+
seenLinks.add(key);
|
|
42
|
+
links.push({ from, to, kind });
|
|
43
|
+
};
|
|
44
|
+
const events = input.events.slice(0, 24);
|
|
45
|
+
const platforms = new Set();
|
|
46
|
+
for (const e of events)
|
|
47
|
+
platforms.add(e.platform || "unknown");
|
|
48
|
+
for (const s of input.sessions)
|
|
49
|
+
platforms.add(s.platform || "unknown");
|
|
50
|
+
if (platforms.size === 0)
|
|
51
|
+
return { nodes, links };
|
|
52
|
+
push({
|
|
53
|
+
id: "amem.local",
|
|
54
|
+
type: "amem",
|
|
55
|
+
label: "amem",
|
|
56
|
+
detail: { title: "Local memory", path: "~/.amem" },
|
|
57
|
+
});
|
|
58
|
+
push({
|
|
59
|
+
id: "server.remote",
|
|
60
|
+
type: "server",
|
|
61
|
+
label: "Model / tools",
|
|
62
|
+
detail: {
|
|
63
|
+
title: "Remote trip",
|
|
64
|
+
note: "Prompt still goes to the LLM. This node is a miss: amem had nothing useful, so the agent had to explore.",
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
for (const platform of [...platforms].sort()) {
|
|
68
|
+
const pid = llmId(platform);
|
|
69
|
+
push({
|
|
70
|
+
id: pid,
|
|
71
|
+
type: "llm",
|
|
72
|
+
label: platform,
|
|
73
|
+
detail: { platform, title: `${platform} agent` },
|
|
74
|
+
});
|
|
75
|
+
link("amem.local", pid, "serves");
|
|
76
|
+
}
|
|
77
|
+
const platformList = [...platforms].sort();
|
|
78
|
+
for (let i = 0; i < platformList.length; i++) {
|
|
79
|
+
for (let j = i + 1; j < platformList.length; j++) {
|
|
80
|
+
link(llmId(platformList[i]), llmId(platformList[j]), "shared-memory");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const sessionStats = new Map();
|
|
84
|
+
const rememberSession = (platform, sessionId, lastSeen) => {
|
|
85
|
+
const id = sessionNodeId(platform, sessionId);
|
|
86
|
+
const cur = sessionStats.get(id) ?? {
|
|
87
|
+
platform,
|
|
88
|
+
sessionId,
|
|
89
|
+
hits: 0,
|
|
90
|
+
trips: 0,
|
|
91
|
+
ms: 0,
|
|
92
|
+
lastSeen,
|
|
93
|
+
};
|
|
94
|
+
if (lastSeen > cur.lastSeen)
|
|
95
|
+
cur.lastSeen = lastSeen;
|
|
96
|
+
sessionStats.set(id, cur);
|
|
97
|
+
return cur;
|
|
98
|
+
};
|
|
99
|
+
for (const s of input.sessions) {
|
|
100
|
+
rememberSession(s.platform, s.session_id, s.last_seen);
|
|
101
|
+
}
|
|
102
|
+
for (const e of events) {
|
|
103
|
+
const speed = speedForEvent(e);
|
|
104
|
+
const sid = e.session_id || "unknown";
|
|
105
|
+
const stat = rememberSession(e.platform || "unknown", sid, e.created_at);
|
|
106
|
+
if (speed.kind === "local_hit") {
|
|
107
|
+
stat.hits += 1;
|
|
108
|
+
stat.ms += speed.estimatedMsSaved;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
stat.trips += 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const rankedSessions = [...sessionStats.values()]
|
|
115
|
+
.sort((a, b) => b.lastSeen.localeCompare(a.lastSeen))
|
|
116
|
+
.slice(0, 8);
|
|
117
|
+
for (const s of rankedSessions) {
|
|
118
|
+
const id = sessionNodeId(s.platform, s.sessionId);
|
|
119
|
+
push({
|
|
120
|
+
id,
|
|
121
|
+
type: "session",
|
|
122
|
+
label: shortSession(s.sessionId),
|
|
123
|
+
detail: {
|
|
124
|
+
platform: s.platform,
|
|
125
|
+
sessionId: s.sessionId,
|
|
126
|
+
hits: s.hits,
|
|
127
|
+
trips: s.trips,
|
|
128
|
+
estimatedMsSaved: s.ms,
|
|
129
|
+
lastSeen: s.lastSeen,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
link(llmId(s.platform), id, "session");
|
|
133
|
+
}
|
|
134
|
+
const allowedSessions = new Set(rankedSessions.map((s) => sessionNodeId(s.platform, s.sessionId)));
|
|
135
|
+
let tripCount = 0;
|
|
136
|
+
let hitCount = 0;
|
|
137
|
+
for (const e of events) {
|
|
138
|
+
const speed = speedForEvent(e);
|
|
139
|
+
const sid = sessionNodeId(e.platform || "unknown", e.session_id || "unknown");
|
|
140
|
+
if (!allowedSessions.has(sid))
|
|
141
|
+
continue;
|
|
142
|
+
let claimIds = [];
|
|
143
|
+
try {
|
|
144
|
+
claimIds = JSON.parse(e.claim_ids);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
claimIds = [];
|
|
148
|
+
}
|
|
149
|
+
if (speed.kind === "local_hit") {
|
|
150
|
+
if (hitCount >= 12)
|
|
151
|
+
continue;
|
|
152
|
+
hitCount += 1;
|
|
153
|
+
const id = `hit.${e.id}`;
|
|
154
|
+
push({
|
|
155
|
+
id,
|
|
156
|
+
type: "local_hit",
|
|
157
|
+
label: "local hit",
|
|
158
|
+
detail: {
|
|
159
|
+
query: e.query,
|
|
160
|
+
created_at: e.created_at,
|
|
161
|
+
platform: e.platform,
|
|
162
|
+
localMs: speed.localMs,
|
|
163
|
+
estimatedMsSaved: speed.estimatedMsSaved,
|
|
164
|
+
estimatedTokensSaved: e.estimated_tokens_saved,
|
|
165
|
+
anchorsCount: speed.anchorsCount,
|
|
166
|
+
claimsCount: speed.claimsCount,
|
|
167
|
+
claimIds,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
link(sid, id, "local");
|
|
171
|
+
for (const claimId of claimIds.slice(0, 4)) {
|
|
172
|
+
link(id, claimId, "used");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (tripCount >= 12)
|
|
177
|
+
continue;
|
|
178
|
+
tripCount += 1;
|
|
179
|
+
const id = `trip.${e.id}`;
|
|
180
|
+
push({
|
|
181
|
+
id,
|
|
182
|
+
type: "server_trip",
|
|
183
|
+
label: "miss",
|
|
184
|
+
detail: {
|
|
185
|
+
query: e.query,
|
|
186
|
+
created_at: e.created_at,
|
|
187
|
+
platform: e.platform,
|
|
188
|
+
note: "No keyword match. Fallback facts may still have been injected; the model call still happened.",
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
link(sid, id, "trip");
|
|
192
|
+
link(id, "server.remote", "trip");
|
|
193
|
+
link(llmId(e.platform || "unknown"), "server.remote", "trip");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const server = nodes.find((n) => n.id === "server.remote");
|
|
197
|
+
if (server) {
|
|
198
|
+
server.detail.trips = tripCount;
|
|
199
|
+
server.detail.hits = hitCount;
|
|
200
|
+
}
|
|
201
|
+
return { nodes, links };
|
|
202
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type UsageEventRow } from "../db.js";
|
|
2
|
+
import { buildContext } from "../context.js";
|
|
3
|
+
export type ApiRequest = {
|
|
4
|
+
method: string;
|
|
5
|
+
pathname: string;
|
|
6
|
+
searchParams: URLSearchParams;
|
|
7
|
+
body: unknown;
|
|
8
|
+
cwd: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const API_FEATURES: readonly ["vault", "license", "embed", "recipe", "backup", "shop"];
|
|
11
|
+
export declare function normalizeApiPath(pathname: string): string;
|
|
12
|
+
export declare function apiHealth(): {
|
|
13
|
+
ok: true;
|
|
14
|
+
version: string;
|
|
15
|
+
features: string[];
|
|
16
|
+
};
|
|
17
|
+
export type ApiResponse = {
|
|
18
|
+
status: number;
|
|
19
|
+
body: unknown;
|
|
20
|
+
};
|
|
21
|
+
export declare function handleApi(req: ApiRequest): ApiResponse;
|
|
22
|
+
export declare function logContextUsage(input: {
|
|
23
|
+
repoId: string;
|
|
24
|
+
platform: string;
|
|
25
|
+
sessionId?: string;
|
|
26
|
+
query: string;
|
|
27
|
+
}): {
|
|
28
|
+
markdown: string;
|
|
29
|
+
event: UsageEventRow;
|
|
30
|
+
packet: ReturnType<typeof buildContext>;
|
|
31
|
+
};
|