-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuacp
More file actions
executable file
·271 lines (228 loc) · 8.22 KB
/
uacp
File metadata and controls
executable file
·271 lines (228 loc) · 8.22 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
################################################################################
# UACP - Unified Agentic Context Protocol
# A modular command-line tool for managing AI agent contexts
#
# Version: 3.2.0
# Author: OG-Ken
# Repository: https://github.com/OG-Ken/UACP
################################################################################
# ============================================================================
# CONFIGURATION
# ============================================================================
UACP_VERSION="3.2.0"
UACP_DIR=".ai"
# Get script directory for template files (follow symlinks)
if [ -L "${BASH_SOURCE[0]}" ]; then
SCRIPT_PATH=$(readlink "${BASH_SOURCE[0]}")
SCRIPT_DIR="$( cd "$( dirname "$SCRIPT_PATH" )" && pwd )"
else
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
fi
TEMPLATE_DIR="$SCRIPT_DIR/templates"
# ============================================================================
# HELPER FUNCTIONS
# ============================================================================
# Print error message and exit
error() {
echo "Error: $1" >&2
exit 1
}
# Print success message
success() {
echo "✓ $1"
}
# Print info message
info() {
echo "$1"
}
# Load template file and substitute variables
load_template() {
local template_name="$1"
local template_file="$TEMPLATE_DIR/$template_name"
if [ ! -f "$template_file" ]; then
error "Template not found: $template_file"
fi
cat "$template_file"
}
# Print usage/help
show_help() {
cat <<EOF
UACP v${UACP_VERSION} - Unified Agentic Context Protocol
USAGE:
uacp <command> [options] [arguments]
uacp -<flag> [arguments]
COMMANDS:
init [project_name] Initialize UACP in current directory
version Show version information
help Show this help message
OPTIONS:
-h, --help Show help
-v, --version Show version
EXAMPLES:
uacp init Initialize with directory name
uacp init "MyProject" Initialize with custom name
uacp -init Alternative syntax
uacp version Show version
DIRECTORY STRUCTURE:
.ai/
├── context.md Project rules and structure
├── memory/ Active state and tasks
├── templates/ File patterns and examples
├── artifacts/ Generated outputs
└── tmp/ Experimental work
TEMPLATES:
Templates are stored in: $TEMPLATE_DIR
Modify these files to customize UACP structure for all new projects.
For more information, visit: https://github.com/OG-Ken/UACP
EOF
}
# ============================================================================
# COMMAND FUNCTIONS
# Each command is self-contained for easy modification
# ============================================================================
# ----------------------------------------------------------------------------
# Command: init
# Initialize UACP structure in current directory
# ----------------------------------------------------------------------------
cmd_init() {
local project_name=""
local options=""
# Parse arguments for init command
while [[ $# -gt 0 ]]; do
case $1 in
-claudeonly)
options="$options claudeonly"
shift
;;
-*)
error "Unknown option for init: $1"
;;
*)
project_name="$1"
shift
;;
esac
done
# Default to directory name if not provided
if [ -z "$project_name" ]; then
project_name=$(basename "$PWD")
fi
info "Initializing UACP v${UACP_VERSION} for '$project_name'..."
# 1. Create Directory Structure
mkdir -p "$UACP_DIR/memory"
mkdir -p "$UACP_DIR/artifacts"
mkdir -p "$UACP_DIR/templates"
mkdir -p "$UACP_DIR/tmp"
success "Created $UACP_DIR directory structure"
# 2. Generate context.md from template
load_template "context.md" | sed "s/{{PROJECT_NAME}}/$project_name/g" > "$UACP_DIR/context.md"
success "Generated $UACP_DIR/context.md"
# 3. Copy templates to project
cp "$TEMPLATE_DIR/task.md" "$UACP_DIR/templates/"
cp "$TEMPLATE_DIR/session_log.md" "$UACP_DIR/templates/"
cp "$TEMPLATE_DIR/context_summary.md" "$UACP_DIR/templates/"
success "Generated templates"
# 4. Generate pointer files from template
local pointer_content
pointer_content=$(load_template "pointer.md")
# Handle -claudeonly option
if [[ "$options" == *"claudeonly"* ]]; then
echo "$pointer_content" > claude.md
success "Generated pointer file (claude.md only)"
else
echo "$pointer_content" > claude.md
echo "$pointer_content" > gemini.md
echo "$pointer_content" > agents.md
echo "$pointer_content" > open-code.md
success "Generated pointer files (claude.md, gemini.md, agents.md, open-code.md)"
fi
# 5. Create initial memory from template
if [ ! -f "$UACP_DIR/memory/task.md" ]; then
load_template "initial_task.md" > "$UACP_DIR/memory/task.md"
success "Created initial memory/task.md"
else
info " [SKIP] memory/task.md already exists"
fi
# 6. Generate .gitignore from template (ignores .ai/ by default)
if [ ! -f ".gitignore" ]; then
load_template "gitignore.md" > ".gitignore"
touch "$UACP_DIR/tmp/.gitkeep"
success "Generated .gitignore"
else
info " [SKIP] .gitignore already exists"
fi
# 7. Success summary
echo ""
info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
success "UACP v${UACP_VERSION} Initialization Complete!"
info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
info "Next Steps:"
info " 1. Read claude.md, gemini.md, agents.md, or open-code.md"
info " 2. Update .ai/memory/task.md with your project goals"
info " 3. Update .ai/context.md with project-specific information"
echo ""
info "Note: The .ai/ directory is gitignored by default for privacy."
info " Modify .gitignore if you want to commit AI context to your repo."
echo ""
info "Directory Structure:"
info " .ai/"
info " ├── context.md (Project rules and structure)"
info " ├── memory/ (Active state and tasks)"
info " ├── templates/ (File patterns and examples)"
info " ├── artifacts/ (Generated outputs)"
info " └── tmp/ (Experimental work)"
echo ""
}
# ----------------------------------------------------------------------------
# Command: version
# Show version information
# ----------------------------------------------------------------------------
cmd_version() {
cat <<EOF
UACP v${UACP_VERSION}
Unified Agentic Context Protocol
A filesystem-based context management system for AI agents.
Repository: https://github.com/OG-Ken/UACP
Templates: $TEMPLATE_DIR
EOF
}
# ============================================================================
# ARGUMENT PARSER
# Handles both "uacp command" and "uacp -flag" styles
# ============================================================================
parse_arguments() {
# No arguments - show help
if [ $# -eq 0 ]; then
show_help
exit 0
fi
# Parse first argument
case $1 in
# Commands (subcommand style)
init)
shift
cmd_init "$@"
;;
version|--version|-v)
cmd_version
;;
help|--help|-h)
show_help
;;
# Flags (flag style - for backwards compatibility)
-init)
shift
cmd_init "$@"
;;
# Unknown command
*)
error "Unknown command: $1\nRun 'uacp help' for usage information."
;;
esac
}
# ============================================================================
# MAIN EXECUTION
# ============================================================================
parse_arguments "$@"