@brainwav/diagram 1.0.5 → 1.0.7
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/package.json +2 -1
- package/scripts/refresh-diagram-context.sh +199 -0
- package/src/diagram.js +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brainwav/diagram",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Generate architecture diagrams from codebases",
|
|
5
5
|
"main": "src/diagram.js",
|
|
6
6
|
"bin": {
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"src/video.js",
|
|
52
52
|
"src/utils/commands.js",
|
|
53
53
|
"README.md",
|
|
54
|
+
"scripts/refresh-diagram-context.sh",
|
|
54
55
|
"LICENSE"
|
|
55
56
|
],
|
|
56
57
|
"engines": {
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# refresh-diagram-context.sh - Generate Mermaid diagrams and compact into AI context
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# scripts/refresh-diagram-context.sh --dry-run # Preview actions without changes
|
|
7
|
+
# scripts/refresh-diagram-context.sh --force # Execute refresh
|
|
8
|
+
#
|
|
9
|
+
# Outputs:
|
|
10
|
+
# .diagram/*.mmd - Individual Mermaid diagrams
|
|
11
|
+
# .diagram/context/diagram-context.md - Compacted context for AI agents
|
|
12
|
+
# .diagram/context/diagram-context.meta.json - Metadata with schema version
|
|
13
|
+
#
|
|
14
|
+
set -euo pipefail
|
|
15
|
+
|
|
16
|
+
# Configuration
|
|
17
|
+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
18
|
+
DIAGRAM_ENTRYPOINT="$REPO_ROOT/src/diagram.js"
|
|
19
|
+
DIAGRAMS_DIR="$REPO_ROOT/.diagram"
|
|
20
|
+
CONTEXT_DIR="$REPO_ROOT/.diagram/context"
|
|
21
|
+
CONTEXT_FILE="$CONTEXT_DIR/diagram-context.md"
|
|
22
|
+
META_FILE="$CONTEXT_DIR/diagram-context.meta.json"
|
|
23
|
+
SCHEMA_VERSION="1.0"
|
|
24
|
+
|
|
25
|
+
# State
|
|
26
|
+
DRY_RUN=false
|
|
27
|
+
FORCE=false
|
|
28
|
+
|
|
29
|
+
usage() {
|
|
30
|
+
cat <<'USAGE'
|
|
31
|
+
Usage:
|
|
32
|
+
scripts/refresh-diagram-context.sh --dry-run # Preview actions without changes
|
|
33
|
+
scripts/refresh-diagram-context.sh --force # Execute refresh
|
|
34
|
+
|
|
35
|
+
Options:
|
|
36
|
+
--dry-run Show what would be done without making changes
|
|
37
|
+
--force Execute the refresh (required for actual changes)
|
|
38
|
+
-h, --help Show this help message
|
|
39
|
+
|
|
40
|
+
Outputs:
|
|
41
|
+
.diagram/*.mmd Individual Mermaid diagrams
|
|
42
|
+
.diagram/context/diagram-context.md Compacted context for AI agents
|
|
43
|
+
.diagram/context/diagram-context.meta.json Metadata with schema version
|
|
44
|
+
USAGE
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
parse_args() {
|
|
48
|
+
while [[ $# -gt 0 ]]; do
|
|
49
|
+
case "$1" in
|
|
50
|
+
--dry-run)
|
|
51
|
+
DRY_RUN=true
|
|
52
|
+
shift
|
|
53
|
+
;;
|
|
54
|
+
--force)
|
|
55
|
+
FORCE=true
|
|
56
|
+
shift
|
|
57
|
+
;;
|
|
58
|
+
-h|--help)
|
|
59
|
+
usage
|
|
60
|
+
exit 0
|
|
61
|
+
;;
|
|
62
|
+
*)
|
|
63
|
+
echo "Unknown option: $1" >&2
|
|
64
|
+
usage >&2
|
|
65
|
+
exit 2
|
|
66
|
+
;;
|
|
67
|
+
esac
|
|
68
|
+
done
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
log() {
|
|
72
|
+
echo "[refresh] $1"
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
log_dry() {
|
|
76
|
+
echo "[dry-run] $1"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ensure_dirs() {
|
|
80
|
+
if [[ "$DRY_RUN" == "true" ]]; then
|
|
81
|
+
log_dry "Would use: $DIAGRAMS_DIR"
|
|
82
|
+
log_dry "Would create: $CONTEXT_DIR"
|
|
83
|
+
else
|
|
84
|
+
mkdir -p "$DIAGRAMS_DIR"
|
|
85
|
+
mkdir -p "$CONTEXT_DIR"
|
|
86
|
+
fi
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
generate_diagrams() {
|
|
90
|
+
if [[ "$DRY_RUN" == "true" ]]; then
|
|
91
|
+
log_dry "Would generate diagrams to: $DIAGRAMS_DIR"
|
|
92
|
+
log_dry " - All diagram types via 'diagram all'"
|
|
93
|
+
return 0
|
|
94
|
+
fi
|
|
95
|
+
|
|
96
|
+
if [[ "$FORCE" != "true" ]]; then
|
|
97
|
+
echo "Error: --force required to execute refresh" >&2
|
|
98
|
+
exit 1
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
log "Generating diagrams to: $DIAGRAMS_DIR"
|
|
102
|
+
|
|
103
|
+
# Use 'diagram all' command with .diagram output directory
|
|
104
|
+
node "$DIAGRAM_ENTRYPOINT" all "$REPO_ROOT" --output-dir "$DIAGRAMS_DIR"
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
compact_context() {
|
|
108
|
+
if [[ "$DRY_RUN" == "true" ]]; then
|
|
109
|
+
log_dry "Would compact diagrams into: $CONTEXT_FILE"
|
|
110
|
+
return 0
|
|
111
|
+
fi
|
|
112
|
+
|
|
113
|
+
log "Compacting diagrams into: $CONTEXT_FILE"
|
|
114
|
+
|
|
115
|
+
# Build header
|
|
116
|
+
cat > "$CONTEXT_FILE" <<'HEADER'
|
|
117
|
+
# Diagram Context Pack
|
|
118
|
+
|
|
119
|
+
Auto-generated architecture context from Mermaid diagrams.
|
|
120
|
+
Do not edit manually - regenerate with `scripts/refresh-diagram-context.sh --force`.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
HEADER
|
|
125
|
+
|
|
126
|
+
# Diagram types to include (matches diagram all output)
|
|
127
|
+
local diagram_types=("architecture" "dependency" "class" "sequence" "flow" "database" "user" "events" "auth" "security")
|
|
128
|
+
|
|
129
|
+
for dtype in "${diagram_types[@]}"; do
|
|
130
|
+
local mmd_file="$DIAGRAMS_DIR/${dtype}.mmd"
|
|
131
|
+
if [[ -f "$mmd_file" ]]; then
|
|
132
|
+
echo "## ${dtype^} Diagram" >> "$CONTEXT_FILE"
|
|
133
|
+
echo "" >> "$CONTEXT_FILE"
|
|
134
|
+
echo '```mermaid' >> "$CONTEXT_FILE"
|
|
135
|
+
cat "$mmd_file" >> "$CONTEXT_FILE"
|
|
136
|
+
echo '```' >> "$CONTEXT_FILE"
|
|
137
|
+
echo "" >> "$CONTEXT_FILE"
|
|
138
|
+
echo "---" >> "$CONTEXT_FILE"
|
|
139
|
+
echo "" >> "$CONTEXT_FILE"
|
|
140
|
+
fi
|
|
141
|
+
done
|
|
142
|
+
|
|
143
|
+
log "Context file created: $CONTEXT_FILE"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
write_metadata() {
|
|
147
|
+
if [[ "$DRY_RUN" == "true" ]]; then
|
|
148
|
+
log_dry "Would write metadata to: $META_FILE"
|
|
149
|
+
return 0
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
local timestamp
|
|
153
|
+
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
154
|
+
|
|
155
|
+
local diagram_count
|
|
156
|
+
diagram_count=$(find "$DIAGRAMS_DIR" -maxdepth 1 -name "*.mmd" -type f 2>/dev/null | wc -l | tr -d ' ')
|
|
157
|
+
|
|
158
|
+
cat > "$META_FILE" <<EOF
|
|
159
|
+
{
|
|
160
|
+
"schema_version": "$SCHEMA_VERSION",
|
|
161
|
+
"generated_at": "$timestamp",
|
|
162
|
+
"repo_root": "$REPO_ROOT",
|
|
163
|
+
"diagrams_dir": ".diagram",
|
|
164
|
+
"context_file": ".diagram/context/diagram-context.md",
|
|
165
|
+
"diagram_count": $diagram_count,
|
|
166
|
+
"diagram_types": ["architecture", "dependency", "class", "sequence", "flow", "database", "user", "events", "auth", "security"]
|
|
167
|
+
}
|
|
168
|
+
EOF
|
|
169
|
+
|
|
170
|
+
log "Metadata file created: $META_FILE"
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
main() {
|
|
174
|
+
parse_args "$@"
|
|
175
|
+
|
|
176
|
+
echo "== Diagram Context Refresh =="
|
|
177
|
+
echo "Repo: $REPO_ROOT"
|
|
178
|
+
echo "Dry-run: $DRY_RUN"
|
|
179
|
+
echo "Force: $FORCE"
|
|
180
|
+
echo ""
|
|
181
|
+
|
|
182
|
+
ensure_dirs
|
|
183
|
+
generate_diagrams
|
|
184
|
+
compact_context
|
|
185
|
+
write_metadata
|
|
186
|
+
|
|
187
|
+
if [[ "$DRY_RUN" == "true" ]]; then
|
|
188
|
+
echo ""
|
|
189
|
+
echo "Dry-run complete. Run with --force to execute."
|
|
190
|
+
else
|
|
191
|
+
echo ""
|
|
192
|
+
echo "Refresh complete."
|
|
193
|
+
echo " Diagrams: .diagram/"
|
|
194
|
+
echo " Context: .diagram/context/diagram-context.md"
|
|
195
|
+
echo " Metadata: .diagram/context/diagram-context.meta.json"
|
|
196
|
+
fi
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
main "$@"
|
package/src/diagram.js
CHANGED
|
@@ -1469,7 +1469,10 @@ program
|
|
|
1469
1469
|
.option('-d, --manifest-dir <dir>', 'Directory containing manifest.json', '.diagram')
|
|
1470
1470
|
.option('-o, --output <file>', 'Write summary JSON to a file')
|
|
1471
1471
|
.option('--require-types <list>', 'Require all listed diagram types, comma-separated')
|
|
1472
|
-
.option(
|
|
1472
|
+
.option(
|
|
1473
|
+
'--fail-on-placeholder',
|
|
1474
|
+
'Fail if any required diagram was a placeholder (or any placeholder if no required types are set)'
|
|
1475
|
+
)
|
|
1473
1476
|
.action(async (targetPath, options) => {
|
|
1474
1477
|
const root = resolveRootPathOrExit(targetPath);
|
|
1475
1478
|
const manifestDir = path.join(root, options.manifestDir || '.diagram');
|
|
@@ -1517,8 +1520,16 @@ program
|
|
|
1517
1520
|
process.exit(2);
|
|
1518
1521
|
}
|
|
1519
1522
|
|
|
1520
|
-
|
|
1521
|
-
|
|
1523
|
+
const placeholderTypesToCheck = required.length > 0
|
|
1524
|
+
? summary.placeholderTypes.filter((type) => required.includes(type))
|
|
1525
|
+
: summary.placeholderTypes;
|
|
1526
|
+
|
|
1527
|
+
if (options.failOnPlaceholder && placeholderTypesToCheck.length > 0) {
|
|
1528
|
+
console.error(
|
|
1529
|
+
chalk.yellow(
|
|
1530
|
+
`⚠️ Manifest includes ${placeholderTypesToCheck.length} required placeholder diagram(s): ${placeholderTypesToCheck.join(', ')}`
|
|
1531
|
+
)
|
|
1532
|
+
);
|
|
1522
1533
|
process.exit(2);
|
|
1523
1534
|
}
|
|
1524
1535
|
|