@drafthq/draft 3.0.0 → 3.1.5

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.
Files changed (47) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +3 -3
  3. package/bin/README.md +4 -7
  4. package/core/shared/condensation.md +8 -8
  5. package/core/shared/draft-context-loading.md +5 -9
  6. package/core/shared/graph-query.md +36 -30
  7. package/core/shared/graph-usage-report.md +1 -1
  8. package/core/shared/pattern-learning.md +2 -2
  9. package/core/shared/red-flags.md +3 -3
  10. package/core/templates/ai-context.md +1 -1
  11. package/core/templates/architecture.md +3 -3
  12. package/integrations/agents/AGENTS.md +165 -142
  13. package/integrations/copilot/.github/copilot-instructions.md +165 -142
  14. package/package.json +1 -1
  15. package/scripts/lib.sh +1 -3
  16. package/scripts/tools/adr-index.sh +2 -2
  17. package/scripts/tools/check-scope-conflicts.sh +2 -2
  18. package/scripts/tools/check-skill-line-caps.sh +2 -2
  19. package/scripts/tools/cycle-detect.sh +5 -1
  20. package/scripts/tools/diff-templates-vs-tracks.sh +2 -2
  21. package/scripts/tools/fix-whitespace.sh +15 -9
  22. package/scripts/tools/graph-arch.sh +72 -0
  23. package/scripts/tools/graph-impact.sh +1 -0
  24. package/scripts/tools/graph-init.sh +3 -3
  25. package/scripts/tools/graph-snapshot.sh +52 -51
  26. package/scripts/tools/hotspot-rank.sh +2 -0
  27. package/scripts/tools/manage-symlinks.sh +1 -1
  28. package/scripts/tools/parse-reports.sh +1 -1
  29. package/scripts/tools/verify-doc-anchors.sh +2 -2
  30. package/scripts/tools/verify-graph-binary.sh +1 -1
  31. package/skills/GRAPH.md +2 -2
  32. package/skills/bughunt/SKILL.md +1 -1
  33. package/skills/debug/SKILL.md +3 -3
  34. package/skills/decompose/SKILL.md +5 -5
  35. package/skills/deep-review/SKILL.md +2 -2
  36. package/skills/deploy-checklist/SKILL.md +2 -2
  37. package/skills/graph/SKILL.md +1 -1
  38. package/skills/implement/SKILL.md +1 -1
  39. package/skills/init/SKILL.md +62 -42
  40. package/skills/init/references/architecture-spec.md +12 -11
  41. package/skills/learn/SKILL.md +5 -5
  42. package/skills/quick-review/SKILL.md +3 -3
  43. package/skills/review/SKILL.md +7 -7
  44. package/skills/tech-debt/SKILL.md +2 -2
  45. package/scripts/tools/okf-bundle.sh +0 -141
  46. package/scripts/tools/okf-check.sh +0 -137
  47. package/scripts/tools/okf-emit.sh +0 -161
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drafthq/draft",
3
- "version": "3.0.0",
3
+ "version": "3.1.5",
4
4
  "description": "Context-Driven Development for AI coding agents — install Draft into Claude Code, Cursor, Codex, or opencode.",
5
5
  "bin": {
6
6
  "draft": "cli/bin/draft.js"
package/scripts/lib.sh CHANGED
@@ -158,11 +158,9 @@ TOOLS=(
158
158
  "mermaid-from-graph.sh"
159
159
  "graph-snapshot.sh"
160
160
  "graph-init.sh"
161
- "okf-emit.sh"
162
- "okf-bundle.sh"
163
- "okf-check.sh"
164
161
  "graph-impact.sh"
165
162
  "graph-callers.sh"
163
+ "graph-arch.sh"
166
164
  "validate-frontmatter.sh"
167
165
  # Foundations hygiene/verification tools
168
166
  "check-graph-usage-report.sh"
@@ -84,7 +84,7 @@ while IFS= read -r -d '' file; do
84
84
 
85
85
  # If no title in frontmatter, fallback to first H1.
86
86
  if [[ -z "$title" ]]; then
87
- title="$(grep -m1 '^# ' "$file" 2>/dev/null | sed 's/^#\s*//' || true)"
87
+ title="$(grep -m1 '^# ' "$file" 2>/dev/null | sed 's/^#[[:space:]]*//' || true)"
88
88
  fi
89
89
 
90
90
  tracks=()
@@ -108,7 +108,7 @@ while IFS= read -r -d '' file; do
108
108
  "$(json_escape "$status")" \
109
109
  "$(json_escape "$file")" \
110
110
  "$tr_json"
111
- done < <(find "$ROOT" -maxdepth 2 -type f -name '*.md' -print0 2>/dev/null | sort -z)
111
+ done < <(find "$ROOT" -maxdepth 2 -type f -name '*.md' 2>/dev/null | sort | tr '\n' '\0')
112
112
 
113
113
  if $first; then
114
114
  printf ']}\n'
@@ -112,7 +112,7 @@ emit() {
112
112
  if ((EMIT_JSON)); then
113
113
  printf '{"conflict_count": %d, "conflicts": [\n' "$conflict_count"
114
114
  local first=1 c track kind detail
115
- for c in "${conflicts[@]}"; do
115
+ for c in ${conflicts[@]+"${conflicts[@]}"}; do
116
116
  IFS='|' read -r track kind detail <<< "$c"
117
117
  if ((first)); then first=0; else printf ',\n'; fi
118
118
  printf ' {"track":"%s","kind":"%s","detail":"%s"}' \
@@ -127,7 +127,7 @@ emit() {
127
127
  printf 'SCOPE: %d conflict(s) across %d track(s).\n' \
128
128
  "$conflict_count" "${#TRACK_PATHS[@]}" >&2
129
129
  local c track kind detail
130
- for c in "${conflicts[@]}"; do
130
+ for c in ${conflicts[@]+"${conflicts[@]}"}; do
131
131
  IFS='|' read -r track kind detail <<< "$c"
132
132
  printf ' [%s] %s — %s\n' "$kind" "$track" "$detail" >&2
133
133
  done
@@ -78,7 +78,7 @@ emit() {
78
78
  printf '{"over_cap_count": %d, "global_cap": %d, "findings": [\n' \
79
79
  "$over_count" "$GLOBAL_CAP"
80
80
  local first=1 v name lines cap
81
- for v in "${findings[@]}"; do
81
+ for v in ${findings[@]+"${findings[@]}"}; do
82
82
  IFS='|' read -r name lines cap <<< "$v"
83
83
  if ((first)); then first=0; else printf ',\n'; fi
84
84
  printf ' {"skill":"%s","lines":%d,"cap":%d}' \
@@ -100,7 +100,7 @@ emit() {
100
100
  "$over_count" "$mode"
101
101
  fi
102
102
  local v name lines cap
103
- for v in "${findings[@]}"; do
103
+ for v in ${findings[@]+"${findings[@]}"}; do
104
104
  IFS='|' read -r name lines cap <<< "$v"
105
105
  if ((ENFORCE)); then
106
106
  printf ' %s: %d lines (cap %d)\n' "$name" "$lines" "$cap" >&2
@@ -68,7 +68,11 @@ Q3="MATCH (a:Function)-[:CALLS]->(b:Function)-[:CALLS]->(c:Function)-[:CALLS]->(
68
68
  R2="$(memory_cli query_graph "{\"project\":\"$PROJECT\",\"query\":\"$Q2\"}" || echo '{}')"
69
69
  R3="$(memory_cli query_graph "{\"project\":\"$PROJECT\",\"query\":\"$Q3\"}" || echo '{}')"
70
70
 
71
- jq -n --argjson r2 "${R2:-{\}}" --argjson r3 "${R3:-{\}}" '
71
+ # Guard against empty/non-JSON engine output so --argjson never aborts the script.
72
+ echo "$R2" | jq -e . >/dev/null 2>&1 || R2='{}'
73
+ echo "$R3" | jq -e . >/dev/null 2>&1 || R3='{}'
74
+
75
+ jq -n --argjson r2 "$R2" --argjson r3 "$R3" '
72
76
  {
73
77
  cycles: (((($r2.rows) // []) + (($r3.rows) // []))),
74
78
  source: "memory-graph"
@@ -146,7 +146,7 @@ emit_records() {
146
146
  if ((EMIT_JSON)); then
147
147
  printf '{"drift_count": %d, "records": [\n' "$drift_count"
148
148
  local first=1
149
- for r in "${drift_records[@]}"; do
149
+ for r in ${drift_records[@]+"${drift_records[@]}"}; do
150
150
  local track kind detail
151
151
  IFS='|' read -r track kind detail <<< "$r"
152
152
  if ((first)); then first=0; else printf ',\n'; fi
@@ -163,7 +163,7 @@ emit_records() {
163
163
  printf 'DRIFT: %d defect(s) across %d track(s).\n' \
164
164
  "$drift_count" "${#TRACK_PATHS[@]}" >&2
165
165
  local r track kind detail
166
- for r in "${drift_records[@]}"; do
166
+ for r in ${drift_records[@]+"${drift_records[@]}"}; do
167
167
  IFS='|' read -r track kind detail <<< "$r"
168
168
  printf ' [%s] %s — %s\n' "$kind" "$track" "$detail" >&2
169
169
  done
@@ -54,6 +54,11 @@ fix_file() {
54
54
  return 2
55
55
  fi
56
56
 
57
+ # Empty file: nothing to normalize (avoid writing a spurious newline).
58
+ if [[ ! -s "$file" ]]; then
59
+ return 1
60
+ fi
61
+
57
62
  local original
58
63
  original="$(cat "$file")"
59
64
 
@@ -66,18 +71,19 @@ fix_file() {
66
71
  | sed -e :a -e '/^\n*$/{$d;N;ba}'
67
72
  )"$'\n'
68
73
 
69
- if [[ "$fixed" == "$original" ]]; then
70
- return 1 # already clean
71
- fi
72
-
74
+ # Compare the bytes we would write against the file on disk — NOT the
75
+ # command-substitution copies (which strip then re-add the trailing newline,
76
+ # so they could never compare equal). This keeps fix_file idempotent.
73
77
  local _tmp
74
78
  _tmp="$(mktemp "${file}.XXXXXX")"
75
- if printf '%s' "$fixed" > "$_tmp"; then
76
- mv -f "$_tmp" "$file"
77
- else
79
+ printf '%s' "$fixed" > "$_tmp" || { rm -f "$_tmp"; return 2; }
80
+
81
+ if cmp -s "$_tmp" "$file"; then
78
82
  rm -f "$_tmp"
79
- return 2
83
+ return 1 # already clean — no change on disk
80
84
  fi
85
+
86
+ mv -f "$_tmp" "$file"
81
87
  return 0
82
88
  }
83
89
 
@@ -109,7 +115,7 @@ case "$1" in
109
115
  fi
110
116
  while IFS= read -r -d '' f; do
111
117
  TARGETS+=("$f")
112
- done < <(find "$TRACK_DIR" -maxdepth 1 -name "*.md" -print0 | sort -z)
118
+ done < <(find "$TRACK_DIR" -maxdepth 1 -name "*.md" | sort | tr '\n' '\0')
113
119
  ;;
114
120
  --draft)
115
121
  REPO_ROOT="${2:-$(pwd)}"
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ # graph-arch.sh — emit the architecture view from the knowledge graph.
3
+ #
4
+ # The engine-only replacement for the old committed architecture.json. Resolves
5
+ # the codebase-memory-mcp engine, indexes the repo on demand, auto-resolves the
6
+ # project, and prints the full get_architecture(all) JSON to stdout — node labels,
7
+ # edge types, languages, packages (fan-in/out), entry points, routes, hotspots,
8
+ # boundaries, layers, clusters, file tree. Pipe to jq to slice the field you need:
9
+ #
10
+ # scripts/tools/graph-arch.sh --repo . | jq '.packages'
11
+ # scripts/tools/graph-arch.sh --repo . | jq '.routes'
12
+ #
13
+ # The engine binary is usually NOT on $PATH; this wrapper resolves it (via
14
+ # _lib.sh:find_memory_bin) so callers never invoke `codebase-memory-mcp` directly.
15
+ #
16
+ # Usage: scripts/tools/graph-arch.sh [--repo DIR]
17
+ # Output: the architecture JSON object on success; {"source":"unavailable"} on failure.
18
+ # Exit codes: 0 OK, 1 invocation error, 2 graph engine/data unavailable.
19
+ set -euo pipefail
20
+
21
+ # shellcheck source=_lib.sh
22
+ source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
23
+
24
+ REPO="."
25
+
26
+ usage() {
27
+ cat <<'EOF'
28
+ graph-arch.sh — architecture view (packages, routes, layers, hotspots) from the graph.
29
+
30
+ Usage:
31
+ scripts/tools/graph-arch.sh [--repo DIR]
32
+
33
+ Flags:
34
+ --repo DIR Repository root (default: cwd).
35
+ --help Show this help.
36
+
37
+ Output: the get_architecture(all) JSON object on success. Pipe to jq to slice it
38
+ (`| jq '.packages'`, `| jq '.routes'`, …). Emits {"source":"unavailable"} and exits 2
39
+ when the graph engine is unavailable.
40
+ EOF
41
+ }
42
+
43
+ while [[ $# -gt 0 ]]; do
44
+ case "$1" in
45
+ --repo) REPO="$2"; shift 2;;
46
+ --help|-h) usage; exit 0;;
47
+ *) echo "Unknown flag: $1" >&2; usage >&2; exit 1;;
48
+ esac
49
+ done
50
+
51
+ if [[ ! -d "$REPO" ]]; then
52
+ echo "ERROR: --repo '$REPO' is not a directory" >&2
53
+ exit 1
54
+ fi
55
+
56
+ REPO_ABS="$(cd "$REPO" && pwd)"
57
+ SELF_REPO="$(cd "$(dirname "$0")/../.." && pwd)"
58
+
59
+ unavailable() { echo '{"source":"unavailable"}'; exit 2; }
60
+
61
+ find_memory_bin "$REPO_ABS" "$SELF_REPO" || unavailable
62
+ command -v jq >/dev/null 2>&1 || unavailable
63
+
64
+ PROJECT="$(memory_ensure_index "$REPO_ABS" || true)"
65
+ [[ -n "$PROJECT" ]] || unavailable
66
+
67
+ ARCH_JSON="$(memory_cli get_architecture "{\"project\":\"$PROJECT\",\"aspects\":[\"all\"]}" || true)"
68
+ [[ -n "$ARCH_JSON" ]] || unavailable
69
+
70
+ # Validate it parses and looks like an architecture object before emitting.
71
+ echo "$ARCH_JSON" | jq -e '.total_nodes != null' >/dev/null 2>&1 || unavailable
72
+ echo "$ARCH_JSON" | jq '.'
@@ -54,6 +54,7 @@ done
54
54
 
55
55
  [[ -d "$REPO" ]] || { echo "ERROR: --repo '$REPO' is not a directory" >&2; exit 1; }
56
56
  [[ -n "$FILE" || -n "$SYMBOL" ]] || { echo "ERROR: provide --file or --symbol" >&2; usage >&2; exit 1; }
57
+ [[ "$DEPTH" =~ ^[0-9]+$ ]] || { echo "ERROR: --depth must be a non-negative integer" >&2; exit 1; }
57
58
 
58
59
  REPO_ABS="$(cd "$REPO" && pwd)"
59
60
  SELF_REPO="$(cd "$(dirname "$0")/../.." && pwd)"
@@ -104,8 +104,8 @@ engine_unavailable() {
104
104
  exit 2
105
105
  }
106
106
 
107
- # Build a committed snapshot for a repo dir; returns graph-snapshot's exit code.
108
- # Snapshot progress goes to stderr so stdout stays clean for --json consumers.
107
+ # Index a repo dir and write its schema.yaml gate marker; returns graph-snapshot's exit code.
108
+ # Progress goes to stderr so stdout stays clean for --json consumers.
109
109
  build_snapshot() {
110
110
  local rc=0
111
111
  "$TOOLS_DIR/graph-snapshot.sh" --repo "$1" 1>&2 || rc=$?
@@ -134,7 +134,7 @@ write_root_link() {
134
134
  [[ -n "$root_project" ]] || root_project="unknown"
135
135
  fi
136
136
  root_commit="$(git -C "$ROOT_ABS" rev-parse --verify --quiet HEAD 2>/dev/null || echo none)"
137
- ts="$(date -Iseconds 2>/dev/null || date)"
137
+ ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
138
138
  cat > "$mod_graph/root-link.json" <<EOF
139
139
  {
140
140
  "root_graph": "$rel",
@@ -1,19 +1,23 @@
1
1
  #!/usr/bin/env bash
2
- # graph-snapshot.sh — materialize a lightweight, committed knowledge-graph snapshot.
2
+ # graph-snapshot.sh — index the repo into the local graph engine and write the
3
+ # committed gate marker (schema.yaml).
3
4
  #
4
- # In the codebase-memory-mcp model, Claude Code skills query the engine live
5
- # (on-demand indexing into ~/.cache). This snapshot exists for the two cases
6
- # that cannot run the engine: PR-reviewable graph state, and the Copilot/Gemini
7
- # integrations (which read committed files, not MCP). It is small and derived —
8
- # git remains the source of truth.
5
+ # Draft is engine-only and opinionated: structural truth lives in the local
6
+ # codebase-memory-mcp engine, queried on demand via the `graph-*.sh` wrappers
7
+ # (which shell out to `codebase-memory-mcp cli <tool>`). There is no committed
8
+ # machine-readable mirror of the graph no architecture.json, hotspots.jsonl,
9
+ # *.mermaid, or okf/ bundle. Those were lossy, went stale on the next commit, and
10
+ # duplicated what the engine serves precisely and live. Git remains the source of
11
+ # truth; the engine is the structural index over it.
9
12
  #
10
- # Writes under <repo>/draft/graph/:
11
- # schema.yaml engine + project metadata + counts (gates skill graph use)
12
- # architecture.json raw get_architecture(all) output
13
- # hotspots.jsonl fan-in-ranked symbols, one JSON object per line
14
- # module-deps.mermaid co-change coupling diagram
15
- # proto-map.mermaid detected-route diagram
16
- # okf/ Open Knowledge Format bundle (portable markdown mirror)
13
+ # Writes one file under <repo>/draft/graph/:
14
+ # schema.yaml engine + project metadata + index counts. Its presence is the
15
+ # GATE that tells skills the graph engine is wired for this repo
16
+ # (see core/shared/graph-query.md Pre-Check). It carries no graph
17
+ # data every structural query goes to the live engine.
18
+ #
19
+ # Re-running on a repo that still has an old fat snapshot prunes the stale
20
+ # committed artifacts, migrating it to the thin model.
17
21
  #
18
22
  # Usage: scripts/tools/graph-snapshot.sh [--repo DIR] [--out DIR]
19
23
  # Exit codes: 0 OK, 1 invocation error, 2 graph engine unavailable.
@@ -28,17 +32,21 @@ OUT_DIR=""
28
32
 
29
33
  usage() {
30
34
  cat <<'EOF'
31
- graph-snapshot.sh — write a committed knowledge-graph snapshot to draft/graph/.
35
+ graph-snapshot.sh — index the repo and write the draft/graph/ gate marker.
36
+
37
+ Indexes the repository into the local graph engine and writes draft/graph/schema.yaml
38
+ (the gate + provenance marker). It writes NO committed graph data — structural
39
+ queries run live against the engine via the graph-*.sh wrappers.
32
40
 
33
41
  Usage:
34
42
  scripts/tools/graph-snapshot.sh [--repo DIR] [--out DIR]
35
43
 
36
44
  Flags:
37
45
  --repo DIR Repository root (default: cwd).
38
- --out DIR Snapshot dir (default: <repo>/draft/graph).
46
+ --out DIR Gate-marker dir (default: <repo>/draft/graph).
39
47
  --help Show this help.
40
48
 
41
- Exit 0 on success, 2 when the graph engine is unavailable (no snapshot written).
49
+ Exit 0 on success, 2 when the graph engine is unavailable (nothing written).
42
50
  EOF
43
51
  }
44
52
 
@@ -57,51 +65,44 @@ REPO_ABS="$(cd "$REPO" && pwd)"
57
65
  SELF_REPO="$(cd "$TOOLS_DIR/../.." && pwd)"
58
66
  OUT="${OUT_DIR:-$REPO_ABS/draft/graph}"
59
67
 
60
- find_memory_bin "$REPO_ABS" "$SELF_REPO" || { echo "graph engine unavailable — no snapshot written" >&2; exit 2; }
61
- command -v jq >/dev/null 2>&1 || { echo "jq required for snapshot" >&2; exit 2; }
68
+ find_memory_bin "$REPO_ABS" "$SELF_REPO" || { echo "graph engine unavailable — nothing written" >&2; exit 2; }
69
+ command -v jq >/dev/null 2>&1 || { echo "jq required" >&2; exit 2; }
62
70
 
71
+ # Index on demand; this is the valuable side-effect — it ensures the engine holds
72
+ # a current index of the repo so live queries resolve.
63
73
  PROJECT="$(memory_ensure_index "$REPO_ABS" || true)"
64
- [[ -n "$PROJECT" ]] || { echo "could not index repo — no snapshot written" >&2; exit 2; }
74
+ [[ -n "$PROJECT" ]] || { echo "could not index repo — nothing written" >&2; exit 2; }
65
75
 
66
76
  mkdir -p "$OUT"
67
77
 
68
- # 1. architecture.json (full get_architecture)
69
- ARCH="$(memory_cli get_architecture "{\"project\":\"$PROJECT\",\"aspects\":[\"all\"]}" || echo '{}')"
70
- echo "$ARCH" | jq '.' > "$OUT/architecture.json"
71
-
72
- # 2. hotspots.jsonl (one object per line)
73
- "$TOOLS_DIR/hotspot-rank.sh" --repo "$REPO_ABS" 2>/dev/null \
74
- | jq -c '.hotspots[]?' > "$OUT/hotspots.jsonl" || true
75
-
76
- # 3. mermaid diagrams (best-effort; tools emit a stub + exit 2 if empty)
77
- "$TOOLS_DIR/mermaid-from-graph.sh" --repo "$REPO_ABS" --diagram module-deps > "$OUT/module-deps.mermaid" 2>/dev/null || true
78
- "$TOOLS_DIR/mermaid-from-graph.sh" --repo "$REPO_ABS" --diagram proto-map > "$OUT/proto-map.mermaid" 2>/dev/null || true
79
-
80
- # 4. OKF bundle (best-effort) portable Open Knowledge Format mirror of the graph.
81
- "$TOOLS_DIR/okf-emit.sh" --repo "$REPO_ABS" --snapshot "$OUT" --out "$OUT/okf" >/dev/null 2>&1 || true
82
-
83
- # 5. schema.yaml — metadata + gate for skill graph use
84
- NODES="$(echo "$ARCH" | jq -r '.total_nodes // 0')"
85
- EDGES="$(echo "$ARCH" | jq -r '.total_edges // 0')"
86
- HOTN="$(wc -l < "$OUT/hotspots.jsonl" | tr -d ' ')"
78
+ # Prune any stale fat-snapshot artifacts from a prior (pre-engine-only) run so a
79
+ # re-index migrates the repo to the thin model.
80
+ rm -f "$OUT/architecture.json" "$OUT/hotspots.jsonl" \
81
+ "$OUT/module-deps.mermaid" "$OUT/proto-map.mermaid" 2>/dev/null || true
82
+ rm -rf "$OUT/okf" 2>/dev/null || true
83
+
84
+ # schema.yaml provenance + gate. Counts are point-of-index provenance only;
85
+ # the live engine is authoritative.
86
+ STATUS_JSON="$(memory_cli index_status "{\"project\":\"$PROJECT\"}" || echo '{}')"
87
+ # Tolerate field-name variation AND non-JSON output across engine versions;
88
+ # counts are provenance only and must never abort the gate-marker write.
89
+ NODES="$(echo "$STATUS_JSON" | jq -r '.nodes // .node_count // .total_nodes // 0' 2>/dev/null || echo 0)"
90
+ EDGES="$(echo "$STATUS_JSON" | jq -r '.edges // .edge_count // .total_edges // 0' 2>/dev/null || echo 0)"
87
91
  VER="$("$MEMORY_BIN" --version 2>/dev/null | awk '{print $NF}' || echo unknown)"
88
92
  cat > "$OUT/schema.yaml" <<EOF
89
- # Draft knowledge-graph snapshotgenerated by scripts/tools/graph-snapshot.sh
90
- # Derived from the codebase-memory-mcp engine; git remains source of truth.
93
+ # Draft graph gate marker written by scripts/tools/graph-snapshot.sh
94
+ # Draft is engine-only: this file carries NO graph data. Its presence signals that
95
+ # the local codebase-memory-mcp engine is wired for this repo. Query the engine
96
+ # live via the graph-*.sh wrappers (or \`codebase-memory-mcp cli <tool>\`).
97
+ # Counts below are point-of-index provenance; the live engine is authoritative.
91
98
  engine: codebase-memory-mcp
92
99
  engine_version: "$VER"
93
100
  project: "$PROJECT"
94
- generated_at: "$(date -Iseconds 2>/dev/null || date)"
95
- nodes: $NODES
96
- edges: $EDGES
97
- hotspots: $HOTN
98
- artifacts:
99
- - architecture.json
100
- - hotspots.jsonl
101
- - module-deps.mermaid
102
- - proto-map.mermaid
103
- - okf/
101
+ generated_at: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
102
+ indexed_nodes: $NODES
103
+ indexed_edges: $EDGES
104
+ access: engine-live
104
105
  EOF
105
106
 
106
- echo "Snapshot written to $OUT (nodes=$NODES edges=$EDGES hotspots=$HOTN)"
107
+ echo "Indexed $PROJECT and wrote gate marker to $OUT/schema.yaml (nodes=$NODES edges=$EDGES)"
107
108
  exit 0
@@ -48,6 +48,8 @@ while [[ $# -gt 0 ]]; do
48
48
  esac
49
49
  done
50
50
 
51
+ [[ "$TOP" =~ ^[0-9]+$ ]] || { echo "ERROR: --top must be a non-negative integer" >&2; exit 1; }
52
+
51
53
  if [[ ! -d "$REPO" ]]; then
52
54
  echo "ERROR: --repo '$REPO' is not a directory" >&2
53
55
  exit 1
@@ -74,7 +74,7 @@ while IFS= read -r -d '' f; do
74
74
  # File-only (not symlink we already manage)
75
75
  if [[ -L "$f" ]]; then continue; fi
76
76
  newest="$base"
77
- done < <(find "$DIR" -maxdepth 1 -name "$pattern" -print0 | sort -z)
77
+ done < <(find "$DIR" -maxdepth 1 -name "$pattern" | sort | tr '\n' '\0')
78
78
 
79
79
  if [[ -z "$newest" ]]; then
80
80
  echo "No matching $pattern files in $DIR" >&2
@@ -105,7 +105,7 @@ while IFS= read -r -d '' file; do
105
105
  "$([[ -n "$track_id" ]] && echo "\"$(json_escape "$track_id")\"" || echo "null")" \
106
106
  "$(json_escape "$generated_at")" \
107
107
  "${crit:-0}" "${high:-0}" "${med:-0}" "${low:-0}" "${info:-0}"
108
- done < <(find "$ROOT" -type f -name '*-report-*.md' -print0 2>/dev/null | sort -z)
108
+ done < <(find "$ROOT" -type f -name '*-report-*.md' 2>/dev/null | sort | tr '\n' '\0')
109
109
 
110
110
  if $first; then
111
111
  printf ']\n'
@@ -177,7 +177,7 @@ emit() {
177
177
  if ((EMIT_JSON)); then
178
178
  printf '{"violation_count": %d, "violations": [\n' "$violation_count"
179
179
  local first=1 v track kind file line detail
180
- for v in "${violations[@]}"; do
180
+ for v in ${violations[@]+"${violations[@]}"}; do
181
181
  IFS='|' read -r track kind file line detail <<< "$v"
182
182
  if ((first)); then first=0; else printf ',\n'; fi
183
183
  printf ' {"track":"%s","kind":"%s","file":"%s","line":%s,"detail":"%s"}' \
@@ -192,7 +192,7 @@ emit() {
192
192
  printf 'ANCHORS: %d violation(s) across %d track(s).\n' \
193
193
  "$violation_count" "${#TRACK_PATHS[@]}" >&2
194
194
  local v track kind file line detail
195
- for v in "${violations[@]}"; do
195
+ for v in ${violations[@]+"${violations[@]}"}; do
196
196
  IFS='|' read -r track kind file line detail <<< "$v"
197
197
  printf ' [%s] %s/%s:%s — %s\n' "$kind" "$track" "$file" "$line" "$detail" >&2
198
198
  done
@@ -141,7 +141,7 @@ if [[ -d "$REPO/draft" ]]; then
141
141
  mkdir -p "$REPO/draft"
142
142
  cat > "$REPO/draft/.graph-binary-report.json" <<EOF
143
143
  {
144
- "detected_at": "$(date -Iseconds 2>/dev/null || date)",
144
+ "detected_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
145
145
  "engine_bin": "$(json_escape "$MEMORY_BIN")",
146
146
  "source": "$(json_escape "$SOURCE")",
147
147
  "arch": "$(json_escape "$ARCH")",
package/skills/GRAPH.md CHANGED
@@ -301,8 +301,8 @@ init → learn → (updates guardrails.md)
301
301
  init ──────────► │ architecture.md ──► .ai-context.md │
302
302
  │ product.md tech-stack.md guardrails.md │
303
303
  │ workflow.md tracks.md tech-debt.md │
304
- │ graph/ (module-graph, hotspots, proto,
305
- module-deps.mermaid, proto-map..)
304
+ │ graph/ (schema.yaml gate; all data queried
305
+ live via codebase-memory-mcp engine)
306
306
  └──────────────────┬──────────────────────────┘
307
307
  │ read by all skills
308
308
  ┌───────────────────────────┼───────────────────────┐
@@ -68,7 +68,7 @@ Read and follow the base procedure in `core/shared/draft-context-loading.md`.
68
68
  - **Leverage Storage Topology** — Identify data loss risks at each tier (cache eviction without writeback, event log gaps, missing archive)
69
69
  - **Leverage Consistency Boundaries** — Find bugs at eventual consistency seams (stale reads, lost events, missing reconciliation)
70
70
  - **Leverage Failure Recovery Matrix** — Verify idempotency claims, check for partial failure states without recovery paths
71
- - **Leverage Graph Data** (if `draft/graph/` exists) — Read `architecture.json` (`.packages`) for dependency awareness. Flag dependencies on unexpected modules. Flag code in modules involved in dependency cycles as higher risk. Use `hotspots.jsonl` to prioritize analysis of high-complexity, high-fanIn files. See `core/shared/graph-query.md`.
71
+ - **Leverage Graph Data** (if `draft/graph/` exists) — Query `scripts/tools/graph-arch.sh --repo .` for dependency awareness. Flag dependencies on unexpected modules. Flag code in modules involved in dependency cycles as higher risk. Run `scripts/tools/hotspot-rank.sh --repo .` to prioritize analysis of high-complexity, high-fanIn files. See `core/shared/graph-query.md`.
72
72
  - **Leverage Learned Anti-Patterns** — If `draft/guardrails.md` exists, read the `## Learned Anti-Patterns` section. During the bug sweep, when a bug matches a learned anti-pattern, prefix the report entry with `[KNOWN-ANTI-PATTERN: {pattern name}]`. This distinguishes recurring documented patterns from newly discovered bugs, and signals that a systemic fix may be needed rather than a one-off patch.
73
73
 
74
74
  ### 2. Confirm Scope
@@ -11,10 +11,10 @@ You are conducting a structured debugging session following systematic investiga
11
11
 
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. During Steps 3–4 (Isolate, Diagnose):
13
13
 
14
- 1. Locate the suspect file's module via `draft/graph/architecture.json` (`.packages`) before tracing data flow.
14
+ 1. Locate the suspect file's module via `scripts/tools/graph-arch.sh --repo .` before tracing data flow.
15
15
  2. Use `scripts/tools/graph-callers.sh --repo . --symbol <fn>` to enumerate call sites of suspect functions — not `grep`.
16
16
  3. Use `scripts/tools/graph-impact.sh --repo . --file <path>` to size the blast radius before proposing a fix.
17
- 4. Cross-check `draft/graph/hotspots.jsonl` to know whether the file is high-fanIn (any fix needs extra caution).
17
+ 4. Run `scripts/tools/hotspot-rank.sh --repo .` to know whether the file is high-fanIn (any fix needs extra caution).
18
18
 
19
19
  Filesystem `grep` is reserved for source-text scans (literal error strings, stack-trace symbols when the graph misses). Use the fallback sentence on graph miss.
20
20
 
@@ -62,7 +62,7 @@ Key context for debugging:
62
62
  - `.ai-context.md` — Module boundaries, data flows, invariants (crucial for tracing)
63
63
  - `tech-stack.md` — Language-specific debugging tools and techniques
64
64
  - `guardrails.md` — Known anti-patterns that may be causing the issue
65
- - `draft/graph/` (MANDATORY when present) — Load `architecture.json` for dependency/module context and `hotspots.jsonl` for complexity awareness. Use `scripts/tools/graph-callers.sh --repo . --symbol <fn>` to find all callers, and `scripts/tools/graph-impact.sh --repo . --file <path>` to size blast radius before any fix. See [core/shared/graph-query.md](../../core/shared/graph-query.md).
65
+ - `draft/graph/` (MANDATORY when present) — Query `scripts/tools/graph-arch.sh --repo .` for dependency/module context and `scripts/tools/hotspot-rank.sh --repo .` for complexity awareness. Use `scripts/tools/graph-callers.sh --repo . --symbol <fn>` to find all callers, and `scripts/tools/graph-impact.sh --repo . --file <path>` to size blast radius before any fix. See [core/shared/graph-query.md](../../core/shared/graph-query.md).
66
66
 
67
67
  ## Step 1: Parse Arguments
68
68
 
@@ -11,8 +11,8 @@ You are decomposing a project or track into modules with clear responsibilities,
11
11
 
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Module identification (Step 3) and dependency mapping (Step 4) **start from the graph**:
13
13
 
14
- 1. Load `draft/graph/architecture.json` (`.packages`) for the authoritative module list and fan-in/out.
15
- 2. Load `draft/graph/hotspots.jsonl` to identify candidate modules to split.
14
+ 1. Query `scripts/tools/graph-arch.sh --repo .` for the authoritative module list and fan-in/out.
15
+ 2. Run `scripts/tools/hotspot-rank.sh --repo .` to identify candidate modules to split.
16
16
  3. Use `scripts/tools/graph-callers.sh`/`graph-impact.sh` on demand for symbols/callers inside a candidate module.
17
17
  4. Run `scripts/tools/cycle-detect.sh --repo .` to enumerate existing cycles before proposing new boundaries.
18
18
 
@@ -156,10 +156,10 @@ ls -d src/*/ lib/*/ app/*/ packages/*/ 2>/dev/null
156
156
 
157
157
  When graph data is available, the graph is the **primary** (not optional) source for module discovery — manual scanning above is reserved for the graph-miss fallback path:
158
158
 
159
- - **Module boundaries**: Read `draft/graph/architecture.json` (`.packages`, `.languages`) — module list with node counts and per-language file counts
159
+ - **Module boundaries**: Query `scripts/tools/graph-arch.sh --repo .` — module list with node counts and per-language file counts
160
160
  - **Dependency edges**: Weighted inter-module dependencies with exact include counts — replaces manual import tracing
161
161
  - **Cycle detection**: Circular dependency paths already computed — use for identifying tight coupling and decomposition candidates
162
- - **Hotspots**: Load `draft/graph/hotspots.jsonl` — high-complexity files that may need further decomposition
162
+ - **Hotspots**: Run `scripts/tools/hotspot-rank.sh --repo .` — high-complexity files that may need further decomposition
163
163
  - **Per-module detail**: query `scripts/tools/graph-callers.sh`/`graph-impact.sh` for symbol/call detail within modules of interest
164
164
 
165
165
  This data is deterministic and exhaustive. The manual scanning recipes above only run **after** the graph misses on the concept the user named — and the miss must be reported in the Graph Usage Report footer. See [core/shared/graph-query.md](../../core/shared/graph-query.md) §Concept-to-Files Recipe.
@@ -615,7 +615,7 @@ When decomposition involves breaking a monolith, choosing module boundaries, or
615
615
 
616
616
  Before printing the completion announcement, internally verify and report:
617
617
 
618
- 1. **Graph files queried** — which JSONL files were loaded (e.g. `architecture.json, hotspots.jsonl` and tools like `cycle-detect.sh`).
618
+ 1. **Graph data queried** — which live-engine tools were invoked (e.g. `get_architecture`, `hotspot-rank.sh`, `cycle-detect.sh`).
619
619
  2. **Layer 1 files deliberately skipped** — list any `.ai-context.md` sections, `tech-stack.md`, `product.md`, `workflow.md` you skipped as irrelevant to this decomposition. Be explicit; do not silently skip.
620
620
  3. **Filesystem grep fallback justification** — for every `grep`/`find` run, state the concept it searched for and quote the graph-miss sentence.
621
621
  4. **Citation Gate audit** — scan every Citation column in the generated component table, dependencies table, and LLD class table. Report:
@@ -11,10 +11,10 @@ Perform an exhaustive end-to-end lifecycle review of a service, component, or mo
11
11
 
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Deep-review uses the graph to **narrow review scope** — a key 30–50% scope reduction:
13
13
 
14
- 1. Use `scripts/tools/graph-impact.sh`/`graph-callers.sh` and `architecture.json` for the audited module's structure — do not enumerate via `find`.
14
+ 1. Use `scripts/tools/graph-impact.sh`/`graph-callers.sh` and `scripts/tools/graph-arch.sh --repo .` for the audited module's structure — do not enumerate via `find`.
15
15
  2. Run `scripts/tools/graph-impact.sh --repo . --file <each-changed-file>` per file in the diff (or per file in the module if no diff) to obtain the affected module set deterministically.
16
16
  3. Run `scripts/tools/cycle-detect.sh --repo .` and flag any cycle that includes the audited module as Architecture Resilience finding.
17
- 4. Cross-check `draft/graph/hotspots.jsonl` to identify high-fanIn files inside the module — these get deeper inspection.
17
+ 4. Run `scripts/tools/hotspot-rank.sh --repo .` to identify high-fanIn files inside the module — these get deeper inspection.
18
18
 
19
19
  Filesystem `grep` is reserved for source-text scans (API contract strings, secret patterns, log message audits). Module enumeration and caller tracing go through the graph.
20
20
 
@@ -12,8 +12,8 @@ You are generating a pre-deployment verification checklist customized to this pr
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Use the graph to validate module boundaries before the deploy:
13
13
 
14
14
  1. For each file in the deploy diff, run `scripts/tools/graph-impact.sh --repo . --file <path>` to enumerate the modules affected — flag any module **not** declared in `hld.md` §Detailed Design as a deployment-scope miss.
15
- 2. Run `scripts/tools/cycle-detect.sh --repo .` (and read `draft/graph/architecture.json` for the module overview) to ensure no fresh cycles were introduced after HLD sign-off.
16
- 3. Load `draft/graph/hotspots.jsonl` — any hotspot in the diff escalates the Resiliency row of Phase 0.
15
+ 2. Run `scripts/tools/cycle-detect.sh --repo .` (and query `scripts/tools/graph-arch.sh --repo .` for the module overview) to ensure no fresh cycles were introduced after HLD sign-off.
16
+ 3. Run `scripts/tools/hotspot-rank.sh --repo .` — any hotspot in the diff escalates the Resiliency row of Phase 0.
17
17
 
18
18
  Filesystem `grep` is reserved for source-text scans (migration file names, flag-key strings). Module/impact discovery goes through the graph.
19
19
 
@@ -55,7 +55,7 @@ echo "Engine: $ENGINE"
55
55
 
56
56
  ## Step 3: Build / refresh the snapshot
57
57
 
58
- One call resolves the engine, indexes the repo (incrementally on refresh), and writes the committed snapshot under `<repo>/draft/graph/` — `schema.yaml`, `architecture.json`, `hotspots.jsonl`, `module-deps.mermaid`, `proto-map.mermaid`, and an Open Knowledge Format bundle under `okf/` (a portable, vendor-neutral markdown mirror of the graph`index.md` + one cross-linked `modules/<name>.md` concept per module).
58
+ One call resolves the engine, indexes the repo (incrementally on refresh), and updates the gate marker `<repo>/draft/graph/schema.yaml` (engine metadata + point-of-index counts; `access: engine-live`). All structural graph data is queried live from the engineno snapshot files are committed beyond `schema.yaml`.
59
59
 
60
60
  ```bash
61
61
  scripts/tools/graph-snapshot.sh --repo "$REPO_ABS"
@@ -133,7 +133,7 @@ If one of these applies, route directly to the specialist workflow and stop this
133
133
  - Keep matching invariants as **active constraints** for this task — these govern code generation, not just review
134
134
  - If invariants reference lock ordering, fail-closed behavior, or data integrity rules: these are non-negotiable during implementation
135
135
  9. **Load graph context** (if `draft/graph/schema.yaml` exists):
136
- - Read `draft/graph/hotspots.jsonl` — check if any files this task will modify appear as hotspots
136
+ - Run `scripts/tools/hotspot-rank.sh --repo .` — check if any files this task will modify appear as hotspots
137
137
  - If modifying a hotspot file (high fanIn), warn: "This task modifies {file} (fanIn={N}). Changes here affect many downstream files. Consider running a graph impact query."
138
138
  - Query `scripts/tools/graph-impact.sh`/`graph-callers.sh` for the module(s) being modified — gives file-level dependency context
139
139
  - See `core/shared/graph-query.md` for on-demand query subroutines (callers, impact)