-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsync_artifacts.sh
More file actions
executable file
·143 lines (125 loc) · 3.7 KB
/
Copy pathsync_artifacts.sh
File metadata and controls
executable file
·143 lines (125 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR="$ROOT_DIR"
TARGET=""
DRY_RUN=0
INCLUDE_HOME_BRAIN=1
# Read file extensions from single-source registry
REGISTRY="${ROOT_DIR}/docs/sisters-registry.json"
if [ -f "$REGISTRY" ] && command -v jq >/dev/null 2>&1; then
ARTIFACT_EXTS=($(jq -r '.sisters[].fileExtension' "$REGISTRY"))
else
echo "Warning: sisters-registry.json not found or jq missing, using fallback" >&2
ARTIFACT_EXTS=(.amem .avis .acb .aid .atime)
fi
# Build display string and find name args from registry
ARTIFACT_EXT_DISPLAY="$(IFS=', '; echo "${ARTIFACT_EXTS[*]}")"
FIND_NAME_ARGS=()
for ext in "${ARTIFACT_EXTS[@]}"; do
if [ ${#FIND_NAME_ARGS[@]} -gt 0 ]; then
FIND_NAME_ARGS+=("-o")
fi
FIND_NAME_ARGS+=("-name" "*${ext}")
done
usage() {
cat <<EOF
Usage: ./sync_artifacts.sh --target=<path-or-rsync-target> [options]
Syncs sister artifacts (${ARTIFACT_EXT_DISPLAY}) to a local or remote target.
Options:
--target=<value> Required. Example local path: /srv/agentra/artifacts
Example remote path: user@host:/srv/agentra/artifacts
--source=<dir> Source directory to scan (default: workspace root)
--no-home-brain Do not include ~/.brain.amem
--dry-run Preview what will sync
--help Show this help
Examples:
./sync_artifacts.sh --target=/srv/agentra/artifacts
./sync_artifacts.sh --target=ubuntu@10.0.0.8:/srv/agentra/artifacts
EOF
}
while (($#)); do
case "$1" in
--target=*)
TARGET="${1#*=}"
shift
;;
--source=*)
SOURCE_DIR="${1#*=}"
shift
;;
--no-home-brain)
INCLUDE_HOME_BRAIN=0
shift
;;
--dry-run)
DRY_RUN=1
shift
;;
--help|-h)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 1
;;
esac
done
if [[ -z "$TARGET" ]]; then
echo "Error: --target is required." >&2
usage >&2
exit 1
fi
if [[ ! -d "$SOURCE_DIR" ]]; then
echo "Error: source directory not found: $SOURCE_DIR" >&2
exit 1
fi
RSYNC_ARGS=(-av)
if [[ "$DRY_RUN" -eq 1 ]]; then
RSYNC_ARGS+=(--dry-run)
fi
echo "Syncing sister artifacts..."
echo " source: $SOURCE_DIR"
echo " target: $TARGET"
echo " include ~/.brain.amem: $([[ "$INCLUDE_HOME_BRAIN" -eq 1 ]] && echo yes || echo no)"
manifest_file="$(mktemp)"
cleanup() {
rm -f "$manifest_file"
}
trap cleanup EXIT
while IFS= read -r abs_path; do
rel_path="${abs_path#$SOURCE_DIR/}"
printf '%s\n' "$rel_path" >>"$manifest_file"
done < <(
find "$SOURCE_DIR" \
\( -path '*/.git/*' -o -path '*/target/*' -o -path '*/node_modules/*' -o -path '*/tests/fixtures/*' \) -prune \
-o -type f \( "${FIND_NAME_ARGS[@]}" \) -print
)
artifact_count="$(wc -l <"$manifest_file" | tr -d '[:space:]')"
if [[ "$artifact_count" == "0" ]]; then
echo "No artifacts found under source directory."
else
echo "Artifacts found: $artifact_count"
rsync "${RSYNC_ARGS[@]}" --files-from="$manifest_file" "$SOURCE_DIR"/ "$TARGET"/
fi
if [[ "$INCLUDE_HOME_BRAIN" -eq 1 && -f "$HOME/.brain.amem" ]]; then
BRAIN_ARGS=(-av)
if [[ "$DRY_RUN" -eq 1 ]]; then
BRAIN_ARGS+=(--dry-run)
fi
rsync "${BRAIN_ARGS[@]}" "$HOME/.brain.amem" "${TARGET%/}/.brain.amem"
fi
echo ""
echo "Sync complete."
echo "On the server, set:"
echo " export AGENTRA_RUNTIME_MODE=server"
echo " export AGENTIC_TOKEN=\"\$(openssl rand -hex 32)\""
echo " export AGENTRA_ARTIFACT_DIRS=\"<server-path-containing-synced-artifacts>\""
echo ""
echo "Then run preflight:"
echo " agentra server preflight --strict"
echo ""
echo "[next] Restart MCP host/client"
echo "[tip] Optional feedback: https://agentralabs.tech/docs/feedback"