Repository navigation
Expand file tree
/
Copy pathagent_write_docs.sh
More file actions
69 lines (51 loc) · 2.21 KB
/
Copy pathagent_write_docs.sh
File metadata and controls
69 lines (51 loc) · 2.21 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
#!/bin/bash
# Define the path to the undoc.json file
UNDOC_FILE="/app/reports/undoc.json"
# Define the output directory for generated documentation
OUTPUT_DIR="/app/docs/auto"
# Ensure the output directory exists
mkdir -p "$OUTPUT_DIR" || { echo "Error: Could not create output directory $OUTPUT_DIR"; exit 1; }
# Check if undoc.json exists
if [ ! -f "$UNDOC_FILE" ]; then
echo "Error: $UNDOC_FILE not found."
exit 1
fi
# Read and parse undoc.json to get the list of undocumented files
# Use jq to extract the 'file' value from each object in the JSON array
UNDOC_FILES=$(jq -r '.[].file' "$UNDOC_FILE")
# Check if jq command was successful
if [ $? -ne 0 ]; then
echo "Error: Failed to parse $UNDOC_FILE with jq. Is jq installed and the JSON valid?"
exit 1
fi
# Loop through each undocumented file
echo "$UNDOC_FILES" | while IFS= read -r file; do
echo "Processing file: $file"
# Extract the base module name from the file path (remove directory and .py extension)
module=$(basename "$file" .py)
# Define the output markdown file path
output_md="$OUTPUT_DIR/$module.md"
# Generate documentation using the claude command
echo "Generating documentation for module: $module"
# Read API key from Docker secret and set environment variable
# Read API key from Docker secret and set environment variable
export CLAUDE_API_KEY=$(cat /run/secrets/claude_api_key)
# Export CLAUDE_MODEL environment variable (should be set on host)
export CLAUDE_MODEL="$CLAUDE_MODEL"
claude -p "Write a markdown page for module $module: overview, API table, usage examples." > "$output_md"
# Check if the claude command was successful
if [ $? -ne 0 ]; then
echo "Warning: Failed to generate documentation for $file. Skipping linting."
continue # Skip linting and move to the next file
fi
# Lint the generated markdown file
echo "Linting generated documentation: $output_md"
markdownlint -f "$output_md"
# Check if the markdownlint command was successful
if [ $? -ne 0 ]; then
echo "Warning: markdownlint failed for $output_md. Please check the file manually."
# Continue processing other files even if linting fails for one
fi
done
echo "Documentation generation and linting process completed."
exit 0