memory-anywhere 0.0.0-stage → 0.5.1
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 +79 -2
- package/bin/memory-anywhere.mjs +59615 -0
- package/deploy/app.mjs +972 -0
- package/deploy/cdk.json +8 -0
- package/deploy/host/firstboot.sh +43 -0
- package/deploy/host/ma-updater.service +10 -0
- package/deploy/host/ma-updater.sh +252 -0
- package/deploy/host/ma-updater.timer +10 -0
- package/deploy/host/pins.env +24 -0
- package/deploy/host/release/first-store.sh +32 -0
- package/deploy/host/release/install.sh +249 -0
- package/deploy/host/release/libexec/ma-maint.sh +49 -0
- package/deploy/host/release/libexec/ma-selfcheck.sh +14 -0
- package/deploy/host/release/libexec/manifest-at.sh +42 -0
- package/deploy/host/release/libexec/outbox.sh +83 -0
- package/deploy/host/release/libexec/secrets.sh +15 -0
- package/deploy/host/release/tmpfiles.conf +13 -0
- package/deploy/host/release/units/caddy.service +26 -0
- package/deploy/host/release/units/litestream.service +28 -0
- package/deploy/host/release/units/ma-maint.service +7 -0
- package/deploy/host/release/units/ma-selfcheck.path +9 -0
- package/deploy/host/release/units/ma-selfcheck.service +9 -0
- package/deploy/host/release/units/memory-anywhere-outbox.path +9 -0
- package/deploy/host/release/units/memory-anywhere-outbox.service +21 -0
- package/deploy/host/release/units/memory-anywhere-secrets.service +25 -0
- package/deploy/host/release/units/memory-anywhere.service +35 -0
- package/deploy/release-keys/release.pub +2 -0
- package/package.json +28 -4
- package/plugins/claude-code/.claude-plugin/icon.png +0 -0
- package/plugins/claude-code/.claude-plugin/marketplace.json +12 -0
- package/plugins/claude-code/.claude-plugin/plugin.json +6 -0
- package/plugins/claude-code/.mcp.json +9 -0
- package/plugins/claude-code/README.md +11 -0
- package/plugins/claude-code/dist/memory-anywhere.mjs +59615 -0
- package/plugins/claude-code/hooks/hooks.json +30 -0
- package/plugins/claude-code/skills/memory-anywhere/SKILL.md +11 -0
- package/plugins/cursor/.cursor-plugin/plugin.json +6 -0
- package/plugins/cursor/dist/memory-anywhere.mjs +59615 -0
- package/plugins/cursor/rules/memory-anywhere.mdc +10 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ma-maint.service (root), started by ma-maint.timer at 04:15 owner local time
|
|
3
|
+
# (deployment-aws.md §4). It compacts the store when a purge left the flag
|
|
4
|
+
# maint/purge-pending, and every Sunday regardless, so no purged block stays in
|
|
5
|
+
# the database file or in later EBS snapshots:
|
|
6
|
+
#
|
|
7
|
+
# stop server and Litestream → maint --compact (VACUUM INTO, zero the old files and
|
|
8
|
+
# the WALs SQLite deleted, rename) → clear Litestream's metadata → start Litestream (fresh snapshot) and
|
|
9
|
+
# the server → delete the flag
|
|
10
|
+
#
|
|
11
|
+
# Requests in the minute or two it takes get STORE_UNAVAILABLE; coding tools spool.
|
|
12
|
+
set -euo pipefail
|
|
13
|
+
umask 007
|
|
14
|
+
|
|
15
|
+
# shellcheck source=/dev/null
|
|
16
|
+
. /etc/memory-anywhere/stack.env
|
|
17
|
+
|
|
18
|
+
DATA=/var/lib/memory-anywhere
|
|
19
|
+
FLAG="$DATA/maint/purge-pending"
|
|
20
|
+
SERVER=/opt/memory-anywhere/current/bin/memory-anywhere-server
|
|
21
|
+
|
|
22
|
+
log() { echo "ma-maint: $*"; }
|
|
23
|
+
|
|
24
|
+
# The updater's lock: never in parallel with an update, which also stops and starts
|
|
25
|
+
# the server. The updater skips its run while this holds it.
|
|
26
|
+
exec 9>/run/ma-updater.lock
|
|
27
|
+
flock -w 600 9 || { log "an update is still running; trying again tomorrow"; exit 1; }
|
|
28
|
+
|
|
29
|
+
weekday=$(TZ="${MA_OWNER_TZ:-UTC}" date +%u) # 7 = Sunday, in the owner's time zone
|
|
30
|
+
if [ ! -f "$FLAG" ] && [ "$weekday" != 7 ]; then
|
|
31
|
+
log "nothing to do (no purge since the last run, not Sunday)"
|
|
32
|
+
exit 0
|
|
33
|
+
fi
|
|
34
|
+
if [ ! -f "$DATA/store.db" ]; then
|
|
35
|
+
log "no store yet"
|
|
36
|
+
exit 0
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
log "compacting the store (${FLAG##*/}: $([ -f "$FLAG" ] && echo present || echo absent), weekday $weekday)"
|
|
40
|
+
systemctl stop memory-anywhere.service litestream.service
|
|
41
|
+
# Whatever happens below, the server and Litestream come back.
|
|
42
|
+
trap 'systemctl start litestream.service memory-anywhere.service' EXIT
|
|
43
|
+
|
|
44
|
+
runuser -u memory-anywhere -- "$SERVER" maint --compact --config /etc/memory-anywhere/server.toml
|
|
45
|
+
# Positions recorded for the replaced file must not be resumed (§4); systemd already
|
|
46
|
+
# removed /run/litestream when the unit stopped, and this makes sure.
|
|
47
|
+
rm -rf /run/litestream/store
|
|
48
|
+
rm -f "$FLAG"
|
|
49
|
+
log "done"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ma-selfcheck.service (root, eval stacks only): run suite S's on-instance checks
|
|
3
|
+
# for the pending request. When the request asks to compact first, run ma-maint now, as the
|
|
4
|
+
# night after a purge would, so "a purged canary after ma-maint" is checked without waiting
|
|
5
|
+
# for 04:15. ma-maint takes the updater's lock and stops and restarts the server itself.
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
REQUEST=/run/memory-anywhere/selfcheck/request.json
|
|
9
|
+
|
|
10
|
+
if [ -f "$REQUEST" ] && python3 -c 'import json, sys; sys.exit(0 if json.load(open(sys.argv[1])).get("compact") is True else 1)' "$REQUEST"; then
|
|
11
|
+
echo "ma-selfcheck: compacting first (ma-maint)"
|
|
12
|
+
/usr/local/libexec/memory-anywhere/ma-maint.sh
|
|
13
|
+
fi
|
|
14
|
+
exec /opt/memory-anywhere/current/bin/memory-anywhere-server selfcheck --config /etc/memory-anywhere/server.toml
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# manifest-at.sh <restore point or ""> <out file>: run as root before a restored start
|
|
3
|
+
# (deployment-aws.md §5.5), by host/release/first-store.sh and `ma-operator.sh restore`.
|
|
4
|
+
# Writes the newest daily manifest stored no later than the restore point (with "", the newest
|
|
5
|
+
# of all) to <out file>, or `null` when none was stored by then. The server checks the
|
|
6
|
+
# restored event chain against it (packages/server/src/ops/manifest.ts). If the bucket cannot
|
|
7
|
+
# be read the script fails, and so does the restore: it never starts without the check.
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
|
|
10
|
+
TO=${1?usage: manifest-at.sh <restore point or ""> <out file>}
|
|
11
|
+
OUT=${2:?usage: manifest-at.sh <restore point or ""> <out file>}
|
|
12
|
+
# shellcheck source=/dev/null
|
|
13
|
+
. "${MA_STACK_ENV:-/etc/memory-anywhere/stack.env}" # tests point MA_STACK_ENV elsewhere
|
|
14
|
+
# Named like the backup bucket (deploy/aws/lib/names.ts), as in libexec/outbox.sh.
|
|
15
|
+
BUCKET=${MA_BACKUP_BUCKET/-backup-/-manifest-}
|
|
16
|
+
|
|
17
|
+
listing=$(aws --region "$MA_REGION" s3api list-objects-v2 --bucket "$BUCKET" --prefix manifests/ --output json)
|
|
18
|
+
key=$(python3 -c '
|
|
19
|
+
import json, re, sys
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
|
|
22
|
+
def at(s):
|
|
23
|
+
return datetime.fromisoformat(s.replace("Z", "+00:00"))
|
|
24
|
+
|
|
25
|
+
to = sys.argv[1]
|
|
26
|
+
items = [i for i in (json.loads(sys.stdin.read() or "{}").get("Contents") or [])
|
|
27
|
+
if re.fullmatch(r"manifests/manifest-\d{4}-\d{2}-\d{2}\.json", i["Key"])]
|
|
28
|
+
if to:
|
|
29
|
+
items = [i for i in items if at(i["LastModified"]) <= at(to)]
|
|
30
|
+
print(max(items, key=lambda i: at(i["LastModified"]))["Key"] if items else "")' "$TO" <<<"$listing")
|
|
31
|
+
|
|
32
|
+
tmp="$OUT.tmp"
|
|
33
|
+
if [ -n "$key" ]; then
|
|
34
|
+
aws --region "$MA_REGION" s3 cp --only-show-errors "s3://$BUCKET/$key" "$tmp"
|
|
35
|
+
echo "manifest-at.sh: checking the restore against ${key#manifests/}"
|
|
36
|
+
else
|
|
37
|
+
echo null >"$tmp"
|
|
38
|
+
echo "manifest-at.sh: no manifest stored by the restore point; the chain check runs without one"
|
|
39
|
+
fi
|
|
40
|
+
if [ "$(id -u)" = 0 ]; then chown memory-anywhere:ma-data "$tmp"; fi
|
|
41
|
+
chmod 0660 "$tmp"
|
|
42
|
+
mv "$tmp" "$OUT"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# memory-anywhere-outbox.service (user ma-aws): act on each file the server wrote
|
|
3
|
+
# to /run/memory-anywhere/outbox, by name prefix, then delete it (deployment-aws.md §4).
|
|
4
|
+
# The server never holds AWS credentials; this fixed script is its only way out.
|
|
5
|
+
set -uo pipefail
|
|
6
|
+
umask 007
|
|
7
|
+
OUTBOX=/run/memory-anywhere/outbox
|
|
8
|
+
DROP=/run/memory-anywhere/inbox/drop
|
|
9
|
+
# The manifest bucket is named like the backup bucket (deploy/aws/lib/names.ts); deriving it keeps
|
|
10
|
+
# stack.env, and so the instance's user data, unchanged.
|
|
11
|
+
MANIFEST_BUCKET=${MA_BACKUP_BUCKET/-backup-/-manifest-}
|
|
12
|
+
aws_() { aws --region "$MA_REGION" "$@"; }
|
|
13
|
+
log() { echo "outbox: $*"; }
|
|
14
|
+
|
|
15
|
+
# handle <file> <name>: returns non-zero if any step fails. Steps are chained with
|
|
16
|
+
# && because `set -e` does not apply inside a function called as a condition.
|
|
17
|
+
handle() {
|
|
18
|
+
local f=$1 name=$2 id ulid json text
|
|
19
|
+
case "$name" in
|
|
20
|
+
setup-token)
|
|
21
|
+
json=$(python3 -c 'import json,sys; print(json.dumps({"Value": open(sys.argv[1]).read()}))' "$f") &&
|
|
22
|
+
aws_ ssm put-parameter --name "$MA_PREFIX/setup-token" --type SecureString --overwrite --cli-input-json "$json" >/dev/null &&
|
|
23
|
+
log "stored setup-token" ;;
|
|
24
|
+
setup-token.delete)
|
|
25
|
+
aws_ ssm delete-parameter --name "$MA_PREFIX/setup-token" >/dev/null 2>&1
|
|
26
|
+
log "deleted setup-token (or it was already gone)" ;;
|
|
27
|
+
alert-*.json)
|
|
28
|
+
id=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["id"])' "$f") &&
|
|
29
|
+
[[ "$id" =~ ^[a-z_]{1,40}$ ]] &&
|
|
30
|
+
aws_ sns publish --topic-arn "$MA_TOPIC_ARN" --subject "memory-anywhere $MA_STAGE: $id" --message "file://$f" >/dev/null &&
|
|
31
|
+
log "published alert $id" ;;
|
|
32
|
+
digest-*.json)
|
|
33
|
+
# The daily digest (operations.md §2): kinds, subjects (ids) and counts, never content.
|
|
34
|
+
[[ "$name" =~ ^digest-[0-9]{4}-[0-9]{2}-[0-9]{2}\.json$ ]] || { log "ignored a malformed digest name"; return 1; }
|
|
35
|
+
text=$(python3 -c '
|
|
36
|
+
import json, sys
|
|
37
|
+
d = json.load(open(sys.argv[1]))
|
|
38
|
+
lines = ["memory-anywhere digest for " + d["date"] + ": " + str(len(d["alerts"])) + " item(s).", ""]
|
|
39
|
+
for a in d["alerts"]:
|
|
40
|
+
lines.append("- " + a["kind"] + (" (" + a["subject"] + ")" if a["subject"] else "") + ": " + str(a["count"]) + " time(s), last " + a["last_at"])
|
|
41
|
+
lines += ["", "Open the admin UI (System) for details."]
|
|
42
|
+
print("\n".join(lines))' "$f") &&
|
|
43
|
+
aws_ sns publish --topic-arn "$MA_TOPIC_ARN" --subject "memory-anywhere $MA_STAGE: daily digest" --message "$text" >/dev/null &&
|
|
44
|
+
log "published the digest" ;;
|
|
45
|
+
acme-account-uri)
|
|
46
|
+
aws_ ssm put-parameter --name "$MA_PREFIX/acme/account-uri" --type String --overwrite --value "$(cat "$f")" >/dev/null &&
|
|
47
|
+
log "stored acme account uri" ;;
|
|
48
|
+
fetch-*)
|
|
49
|
+
ulid=${name#fetch-}
|
|
50
|
+
[[ "$ulid" =~ ^[0-9A-HJKMNP-TV-Z]{26}$ ]] || { log "ignored a malformed fetch request"; return 1; }
|
|
51
|
+
aws_ s3 cp --only-show-errors "s3://$MA_BACKUP_BUCKET/transfer/$ulid.age" "$DROP/$ulid.age" &&
|
|
52
|
+
chmod 0660 "$DROP/$ulid.age" &&
|
|
53
|
+
aws_ s3 rm --only-show-errors "s3://$MA_BACKUP_BUCKET/transfer/$ulid.age" &&
|
|
54
|
+
log "fetched transfer $ulid" ;;
|
|
55
|
+
manifest-fetch-*)
|
|
56
|
+
# The daily manifest check (ops/manifest.ts): the newest stored manifest, or null if none.
|
|
57
|
+
# Chosen by when S3 stored it, as for a restore (manifest-at.sh), so a name dated in the future
|
|
58
|
+
# cannot pin the check. A failed listing sends no answer: the job retries, it never skips the check.
|
|
59
|
+
ulid=${name#manifest-fetch-}
|
|
60
|
+
[[ "$ulid" =~ ^[0-9A-HJKMNP-TV-Z]{26}$ ]] || { log "ignored a malformed manifest fetch"; return 1; }
|
|
61
|
+
/usr/local/libexec/memory-anywhere/manifest-at.sh "" "$DROP/.manifest-$ulid.json" >/dev/null &&
|
|
62
|
+
chmod 0660 "$DROP/.manifest-$ulid.json" && mv "$DROP/.manifest-$ulid.json" "$DROP/manifest-$ulid.json" &&
|
|
63
|
+
log "fetched the newest manifest" ;;
|
|
64
|
+
manifest-*.json)
|
|
65
|
+
# Only today's (UTC): the server never writes another date.
|
|
66
|
+
[ "$name" = "manifest-$(date -u +%Y-%m-%d).json" ] || { log "ignored a manifest not dated today"; return 1; }
|
|
67
|
+
aws_ s3 cp --only-show-errors "$f" "s3://$MANIFEST_BUCKET/manifests/$name" &&
|
|
68
|
+
log "stored $name" ;;
|
|
69
|
+
*)
|
|
70
|
+
log "deleted an unknown outbox file (name not logged)" ;;
|
|
71
|
+
esac
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
shopt -s nullglob
|
|
75
|
+
for f in "$OUTBOX"/*; do
|
|
76
|
+
name=$(basename "$f")
|
|
77
|
+
# Dot files are writes in progress: the server writes .<name>.tmp and renames it into place.
|
|
78
|
+
case "$name" in .*) continue ;; esac
|
|
79
|
+
# Always remove the file, even on failure: a file left behind would re-trigger the
|
|
80
|
+
# path unit forever. Senders retry (setup-link renews again; alerts recur).
|
|
81
|
+
if ! handle "$f" "$name"; then log "failed to process an outbox file of type ${name%%[-.]*}"; fi
|
|
82
|
+
rm -f "$f"
|
|
83
|
+
done
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# memory-anywhere-secrets.service (user ma-aws): read <prefix>/llm/api_key into a
|
|
3
|
+
# staging file; ExecStartPost hands it to the server user (deployment-aws.md §4).
|
|
4
|
+
# A missing key is not an error: the server starts without LLM features.
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
umask 077
|
|
7
|
+
out=/run/ma-aws-secrets/secrets.env
|
|
8
|
+
if key=$(aws --region "$MA_REGION" ssm get-parameter --name "$MA_PREFIX/llm/api_key" --with-decryption \
|
|
9
|
+
--query Parameter.Value --output text 2>/dev/null); then
|
|
10
|
+
printf 'MA_LLM_API_KEY=%s\n' "$key" >"$out"
|
|
11
|
+
echo "secrets: LLM key loaded"
|
|
12
|
+
else
|
|
13
|
+
: >"$out"
|
|
14
|
+
echo "secrets: no LLM key set ($MA_PREFIX/llm/api_key); starting without it"
|
|
15
|
+
fi
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Runtime directories on tmpfs (deployment-aws.md §4). Recreated at every boot.
|
|
2
|
+
# Traversable but not listable by others, so ma-aws reaches the outbox and Caddy
|
|
3
|
+
# reaches the server's socket, http.sock (0660, group caddy: the server runs with
|
|
4
|
+
# caddy as its primary group; auth-and-security.md §9).
|
|
5
|
+
d /run/memory-anywhere 0751 memory-anywhere caddy -
|
|
6
|
+
# Outbox: the server (group memory-anywhere) writes, ma-aws (owner) reads and deletes.
|
|
7
|
+
d /run/memory-anywhere/outbox 2770 ma-aws memory-anywhere -
|
|
8
|
+
d /run/memory-anywhere/inbox 0751 memory-anywhere memory-anywhere -
|
|
9
|
+
# Drop directory: ma-aws writes fetched transfers, the server reads and deletes them.
|
|
10
|
+
d /run/memory-anywhere/inbox/drop 2770 ma-aws memory-anywhere -
|
|
11
|
+
d /run/memory-anywhere/inbox/key 0700 memory-anywhere memory-anywhere -
|
|
12
|
+
# Selfcheck requests (eval stacks): the server writes the purged canaries here, root reads them.
|
|
13
|
+
d /run/memory-anywhere/selfcheck 0700 memory-anywhere memory-anywhere -
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Caddy (TLS on 443, reverse proxy to the memory-anywhere socket)
|
|
3
|
+
After=network-online.target
|
|
4
|
+
Wants=network-online.target
|
|
5
|
+
|
|
6
|
+
[Service]
|
|
7
|
+
Type=notify
|
|
8
|
+
User=caddy
|
|
9
|
+
Group=caddy
|
|
10
|
+
ExecStart=/usr/local/bin/caddy run --environ --config /etc/caddy/Caddyfile --adapter caddyfile
|
|
11
|
+
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile --force
|
|
12
|
+
Environment=XDG_DATA_HOME=/var/lib/caddy XDG_CONFIG_HOME=/var/lib/caddy/config
|
|
13
|
+
StateDirectory=caddy
|
|
14
|
+
StateDirectoryMode=0700
|
|
15
|
+
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
|
16
|
+
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
|
17
|
+
NoNewPrivileges=yes
|
|
18
|
+
ProtectSystem=strict
|
|
19
|
+
ProtectHome=yes
|
|
20
|
+
PrivateTmp=yes
|
|
21
|
+
TimeoutStopSec=5s
|
|
22
|
+
LimitNOFILE=1048576
|
|
23
|
+
Restart=on-failure
|
|
24
|
+
|
|
25
|
+
[Install]
|
|
26
|
+
WantedBy=multi-user.target
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Litestream replication of the memory-anywhere store (deployment-aws.md §5.1)
|
|
3
|
+
After=network-online.target
|
|
4
|
+
Wants=network-online.target
|
|
5
|
+
# Nothing to replicate until a store exists.
|
|
6
|
+
ConditionPathExists=/var/lib/memory-anywhere/store.db
|
|
7
|
+
|
|
8
|
+
[Service]
|
|
9
|
+
Type=simple
|
|
10
|
+
User=litestream
|
|
11
|
+
Group=litestream
|
|
12
|
+
SupplementaryGroups=ma-data
|
|
13
|
+
ExecStart=/usr/local/bin/litestream replicate -config /etc/litestream.yml
|
|
14
|
+
# Metadata and LTX staging stay on tmpfs (/run/litestream), removed when the unit stops (§5.1).
|
|
15
|
+
RuntimeDirectory=litestream
|
|
16
|
+
RuntimeDirectoryMode=0700
|
|
17
|
+
MemorySwapMax=0
|
|
18
|
+
UMask=0007
|
|
19
|
+
Restart=always
|
|
20
|
+
RestartSec=5
|
|
21
|
+
NoNewPrivileges=yes
|
|
22
|
+
ProtectSystem=strict
|
|
23
|
+
ProtectHome=yes
|
|
24
|
+
PrivateTmp=yes
|
|
25
|
+
ReadWritePaths=/var/lib/memory-anywhere
|
|
26
|
+
|
|
27
|
+
[Install]
|
|
28
|
+
WantedBy=multi-user.target
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=memory-anywhere selfcheck: suite S's on-instance checks (eval stacks only)
|
|
3
|
+
|
|
4
|
+
[Service]
|
|
5
|
+
Type=oneshot
|
|
6
|
+
# Root: it probes IMDS as the server and Caddy users and reads the raw device and the swap file;
|
|
7
|
+
# on request it first compacts the store with ma-maint.
|
|
8
|
+
ExecStart=/usr/local/libexec/memory-anywhere/ma-selfcheck.sh
|
|
9
|
+
TimeoutStartSec=30min
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=memory-anywhere outbox helper
|
|
3
|
+
|
|
4
|
+
[Service]
|
|
5
|
+
Type=oneshot
|
|
6
|
+
User=ma-aws
|
|
7
|
+
Group=ma-aws
|
|
8
|
+
# The server writes outbox files 0660 with group memory-anywhere (the setgid directory's group).
|
|
9
|
+
SupplementaryGroups=memory-anywhere
|
|
10
|
+
# Files it writes in the setgid drop directory get group memory-anywhere from the directory.
|
|
11
|
+
RuntimeDirectory=ma-aws-outbox
|
|
12
|
+
RuntimeDirectoryMode=0700
|
|
13
|
+
Environment=HOME=/run/ma-aws-outbox
|
|
14
|
+
EnvironmentFile=/etc/memory-anywhere/stack.env
|
|
15
|
+
ExecStart=/usr/local/libexec/memory-anywhere/outbox.sh
|
|
16
|
+
UMask=0007
|
|
17
|
+
NoNewPrivileges=yes
|
|
18
|
+
ProtectSystem=strict
|
|
19
|
+
ProtectHome=yes
|
|
20
|
+
PrivateTmp=yes
|
|
21
|
+
ReadWritePaths=/run/memory-anywhere/outbox /run/memory-anywhere/inbox/drop
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=memory-anywhere secrets (LLM key from SSM into /run/memory-anywhere/secrets.env)
|
|
3
|
+
After=network-online.target systemd-tmpfiles-setup.service
|
|
4
|
+
Wants=network-online.target
|
|
5
|
+
|
|
6
|
+
[Service]
|
|
7
|
+
Type=oneshot
|
|
8
|
+
RemainAfterExit=yes
|
|
9
|
+
User=ma-aws
|
|
10
|
+
Group=ma-aws
|
|
11
|
+
EnvironmentFile=/etc/memory-anywhere/stack.env
|
|
12
|
+
ExecStart=/usr/local/libexec/memory-anywhere/secrets.sh
|
|
13
|
+
# '+': as root, hand the file to the server user (0400) and remove the staging copy.
|
|
14
|
+
ExecStartPost=+/bin/sh -c 'install -m 0400 -o memory-anywhere -g memory-anywhere /run/ma-aws-secrets/secrets.env /run/memory-anywhere/secrets.env && rm -f /run/ma-aws-secrets/secrets.env'
|
|
15
|
+
RuntimeDirectory=ma-aws-secrets
|
|
16
|
+
Environment=HOME=/run/ma-aws-secrets
|
|
17
|
+
RuntimeDirectoryMode=0700
|
|
18
|
+
UMask=0077
|
|
19
|
+
NoNewPrivileges=yes
|
|
20
|
+
ProtectSystem=strict
|
|
21
|
+
ProtectHome=yes
|
|
22
|
+
PrivateTmp=yes
|
|
23
|
+
|
|
24
|
+
[Install]
|
|
25
|
+
WantedBy=multi-user.target
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=memory-anywhere server
|
|
3
|
+
Requires=memory-anywhere-secrets.service
|
|
4
|
+
After=network-online.target memory-anywhere-secrets.service
|
|
5
|
+
|
|
6
|
+
[Service]
|
|
7
|
+
Type=simple
|
|
8
|
+
User=memory-anywhere
|
|
9
|
+
# Primary group caddy: the socket it creates is group caddy, mode 0660 (auth-and-security.md §9).
|
|
10
|
+
Group=caddy
|
|
11
|
+
SupplementaryGroups=memory-anywhere ma-data
|
|
12
|
+
EnvironmentFile=-/run/memory-anywhere/secrets.env
|
|
13
|
+
# One JSON line per request, ids and codes only (operations.md §1): the CloudWatch agent ships
|
|
14
|
+
# this file to the stage's log group, where the metric filters raise the alarms. systemd opens
|
|
15
|
+
# it before dropping privileges, so ProtectSystem=strict still holds.
|
|
16
|
+
StandardOutput=append:/var/log/memory-anywhere/server.log
|
|
17
|
+
StandardError=journal
|
|
18
|
+
ExecStart=/opt/memory-anywhere/current/bin/memory-anywhere-server start --config /etc/memory-anywhere/server.toml
|
|
19
|
+
Restart=always
|
|
20
|
+
RestartSec=2
|
|
21
|
+
UMask=0007
|
|
22
|
+
# Plaintext memory never reaches the swap file (deployment-aws.md §4).
|
|
23
|
+
MemorySwapMax=0
|
|
24
|
+
MemoryMax=1400M
|
|
25
|
+
NoNewPrivileges=yes
|
|
26
|
+
ProtectSystem=strict
|
|
27
|
+
ProtectHome=yes
|
|
28
|
+
PrivateTmp=yes
|
|
29
|
+
ReadWritePaths=/var/lib/memory-anywhere /run/memory-anywhere
|
|
30
|
+
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
|
|
31
|
+
CapabilityBoundingSet=
|
|
32
|
+
SystemCallFilter=@system-service
|
|
33
|
+
|
|
34
|
+
[Install]
|
|
35
|
+
WantedBy=multi-user.target
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memory-anywhere",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "One personal memory that all your AI apps share",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mema": "bin/memory-anywhere.mjs",
|
|
9
|
+
"memory-anywhere": "bin/memory-anywhere.mjs"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"deploy",
|
|
14
|
+
"plugins",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=24"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/raiden-02/memory-anywhere.git"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"aws-cdk": "2.1148.0",
|
|
27
|
+
"aws-cdk-lib": "2.275.0",
|
|
28
|
+
"constructs": "10.8.1"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "memory-anywhere",
|
|
3
|
+
"description": "The memory-anywhere plugin, installed from this PC by mema init",
|
|
4
|
+
"owner": { "name": "memory-anywhere" },
|
|
5
|
+
"plugins": [
|
|
6
|
+
{
|
|
7
|
+
"name": "memory-anywhere",
|
|
8
|
+
"source": "./",
|
|
9
|
+
"description": "Personal memory across AI apps"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# memory-anywhere for Claude Code
|
|
2
|
+
|
|
3
|
+
Gives Claude Code the user's personal memory, shared with their other AI apps.
|
|
4
|
+
|
|
5
|
+
- **Tools:** `memory_recall`, `memory_profile`, `memory_save`, `memory_forget` and `memory_status`, served by a local stdio
|
|
6
|
+
proxy (`dist/memory-anywhere.mjs mcp`) that relays to the user's own memory-anywhere store.
|
|
7
|
+
- **Hooks:** at session start the store's context for the current repository is added; each prompt is sent (redacted) only from
|
|
8
|
+
repositories the user enabled with `mema enable`, so the store can check quoted words.
|
|
9
|
+
- **Skill:** when to recall and when to save.
|
|
10
|
+
|
|
11
|
+
Install with `mema init`, which also sets up Codex and Cursor. Nothing is written into any repository.
|