Skip to content

Commit 80df432

Browse files
committed
Introduce neo4j-management domain
1 parent dd35c1b commit 80df432

30 files changed

Lines changed: 963 additions & 310 deletions
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Plan: Introduce neo4j-management Domain
2+
3+
Create `domains/neo4j-management/` containing all scripts, configs, and tests for installing, configuring, starting, and stopping Neo4j. Move 15 files (10 shell scripts + 5 configuration templates) into the domain. Keep profiles in `scripts/profiles/` and jQAssistant YAML templates in `scripts/configuration/`. Update all references. Create a README with agent-friendly examples.
4+
5+
---
6+
7+
### Phase 1 — Create Domain Structure & Move Files
8+
9+
1. Create `domains/neo4j-management/` with a `configuration/` subdirectory
10+
2. Move **10 shell scripts** from `scripts/``domains/neo4j-management/`:
11+
- [setupNeo4j.sh](scripts/setupNeo4j.sh), [setupNeo4jInitialPassword.sh](scripts/setupNeo4jInitialPassword.sh), [configureNeo4j.sh](scripts/configureNeo4j.sh)
12+
- [startNeo4j.sh](scripts/startNeo4j.sh), [stopNeo4j.sh](scripts/stopNeo4j.sh)
13+
- [detectNeo4j.sh](scripts/detectNeo4j.sh), [detectNeo4jWindows.sh](scripts/detectNeo4jWindows.sh)
14+
- [waitForNeo4jHttpFunctions.sh](scripts/waitForNeo4jHttpFunctions.sh), [useNeo4jHighMemoryProfile.sh](scripts/useNeo4jHighMemoryProfile.sh)
15+
- [testConfigureNeo4j.sh](scripts/testConfigureNeo4j.sh)
16+
3a. Replace [scripts/startNeo4j.sh](scripts/startNeo4j.sh) and [scripts/stopNeo4j.sh](scripts/stopNeo4j.sh) with **minimal redirect stubs** for backward compatibility with existing projects that have forwarding scripts pointing to the old location. The stubs must not be referenced by any new code; they exist solely to avoid breaking old workspaces. Each stub contains only:
17+
```bash
18+
#!/usr/bin/env bash
19+
# Deprecated: moved to domains/neo4j-management/. This stub exists for backward compatibility only.
20+
source "$(dirname -- "${BASH_SOURCE[0]}")/../domains/neo4j-management/$(basename -- "${BASH_SOURCE[0]}")" "${@}"
21+
```
22+
3. Move **5 neo4j.conf templates** from `scripts/configuration/``domains/neo4j-management/configuration/`:
23+
- `template-neo4j.conf`, `template-neo4j-high-memory.conf`, `template-neo4j-low-memory.conf`, `template-neo4j-v4.conf`, `template-neo4j-v4-low-memory.conf`
24+
25+
### Phase 2 — Update Internal References (within moved scripts)
26+
27+
4. Add `NEO4J_MANAGEMENT_DIR` resolution to each moved script (same pattern as `DOMAIN_SCRIPT_DIR` in other domains), keeping a `SCRIPTS_DIR` fallback for shared utilities like `download.sh` and `operatingSystemFunctions.sh`
28+
5. Update `configureNeo4j.sh` — resolve config templates from `domains/neo4j-management/configuration/` instead of `scripts/configuration/`
29+
6. Update `setupNeo4j.sh` — source `configureNeo4j.sh` and `setupNeo4jInitialPassword.sh` from co-located directory
30+
7. Update the moved `startNeo4j.sh` and `stopNeo4j.sh` in the domain — source `waitForNeo4jHttpFunctions.sh` from the co-located directory
31+
8. Update `useNeo4jHighMemoryProfile.sh` — source `configureNeo4j.sh` from co-located directory
32+
9. Update `testConfigureNeo4j.sh` — source `configureNeo4j.sh` from co-located directory
33+
34+
### Phase 3 — Update External Callers
35+
36+
10. Update [scripts/analysis/analyze.sh](scripts/analysis/analyze.sh) — source `setupNeo4j.sh`, `startNeo4j.sh`, `stopNeo4j.sh` from `${DOMAINS_DIRECTORY}/neo4j-management/` (already resolves `DOMAINS_DIRECTORY`) *(critical path)*
37+
11. Update [init.sh](init.sh) — change forwarding script paths for `startNeo4j.sh` and `stopNeo4j.sh` from `./../../scripts/` to `./../../domains/neo4j-management/`. The redirect stubs in `scripts/` ensure old workspaces (where `init.sh` was already run before this change) still work without any manual migration.
38+
12. Check [scripts/resetAndScan.sh](scripts/resetAndScan.sh) — references `template-neo4j` for jQAssistant YAML path resolution; verify this is about jQAssistant templates (which stay) not neo4j.conf templates
39+
40+
### Phase 4 — Update Documentation
41+
42+
13. Update [COMMANDS.md](COMMANDS.md) — fix links to `setupNeo4j.sh`, `configureNeo4j.sh`, `stopNeo4j.sh`, `useNeo4jHighMemoryProfile.sh`, and configuration template references
43+
14. Update [README.md](README.md) — fix `useNeo4jHighMemoryProfile.sh` usage examples (lines ~304–307)
44+
15. Update [.github/prompts/plan-coding_agent_instructions.prompt.md](.github/prompts/plan-coding_agent_instructions.prompt.md) — fix `startNeo4j.sh` reference
45+
16. Update [scripts/SCRIPTS.md](scripts/SCRIPTS.md) — remove moved script entries (or regenerate via `generateScriptReference.sh`)
46+
17. Add [CHANGELOG.md](CHANGELOG.md) entry for the domain creation
47+
48+
### Phase 5 — Verify Renovate Patterns
49+
50+
18. Verify [renovate.json](renovate.json) — 5 regex managers use `^scripts/profiles/Neo4j-latest.*\\.sh$` and `^scripts/[^/]*\\.sh$`. Since profiles stay in `scripts/profiles/`, no changes needed unless moved scripts contain `NEO4J_VERSION:-` defaults (unlikely — those are in profiles). *Parallel with Phase 4.*
51+
52+
### Phase 6 — Create README.md
53+
54+
19. Create `domains/neo4j-management/README.md` with:
55+
- Purpose & scope (install, configure, start, stop Neo4j)
56+
- Prerequisites (Java, `jq`, `NEO4J_INITIAL_PASSWORD`)
57+
- Quick-start examples for setting up, starting, stopping Neo4j
58+
- Environment variables reference
59+
- Configuration templates explanation
60+
- Agent-friendly structured instructions for future AGENTS.md / skill usage
61+
62+
---
63+
64+
### Relevant Files
65+
66+
**Move (15 files):** 10 scripts from `scripts/` + 5 templates from `scripts/configuration/` (listed above)
67+
68+
**Create (1 file):** `domains/neo4j-management/README.md`
69+
70+
**Replace with redirect stubs (2 files):** `scripts/startNeo4j.sh`, `scripts/stopNeo4j.sh` — replaced in-place with minimal stubs that forward to the domain; not deleted
71+
72+
**Update (9–11 files):** [analyze.sh](scripts/analysis/analyze.sh), [init.sh](init.sh), [scripts/runTests.sh](scripts/runTests.sh), [COMMANDS.md](COMMANDS.md), [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [scripts/SCRIPTS.md](scripts/SCRIPTS.md), [.github/prompts/plan-coding_agent_instructions.prompt.md](.github/prompts/plan-coding_agent_instructions.prompt.md), possibly [scripts/resetAndScan.sh](scripts/resetAndScan.sh) and [renovate.json](renovate.json)
73+
74+
**Stay in place:** All 11 profile scripts, 5 jQAssistant YAML templates, all query function scripts, `scripts/startNeo4j.sh` (as stub), `scripts/stopNeo4j.sh` (as stub)
75+
76+
---
77+
78+
### Verification
79+
80+
1. Update [scripts/runTests.sh](scripts/runTests.sh) — it currently discovers tests with `find "${SCRIPTS_DIR}" -type f -name 'test*.sh'`, searching only the `scripts/` directory. Extend it to also search `domains/` so that `testConfigureNeo4j.sh` in its new location is picked up automatically (and any future domain-level tests are discovered too).
81+
2. Run `./scripts/runTests.sh` from the repository root — verify that `testConfigureNeo4j.sh` is discovered and executed from its new domain location, and that all other tests still pass.
82+
3. Run `shellcheck` on all moved scripts
83+
4. Grep for old paths (`scripts/setupNeo4j|scripts/configureNeo4j|scripts/detectNeo4j|scripts/waitForNeo4j|scripts/useNeo4jHighMemory|scripts/setupNeo4jInitialPassword|scripts/testConfigureNeo4j`) — no stale references should remain. `scripts/startNeo4j.sh` and `scripts/stopNeo4j.sh` are intentionally kept as redirect stubs, so references to them from *outside* this repository (e.g., old workspace forwarding scripts) are expected and acceptable.
84+
5. Verify `init.sh` forwarding scripts point to new locations
85+
6. Verify Renovate regex patterns still match profile files
86+
87+
---
88+
89+
### Decisions
90+
91+
- **Profiles stay in `scripts/profiles/`** — they also contain jQAssistant settings (separate concern)
92+
- **jQAssistant YAML templates stay in `scripts/configuration/`** — not neo4j-specific
93+
- **No COPIED_FILES.md** — files are moved, not copied (clean cut)
94+
- **testConfigureNeo4j.sh moves** into the domain
95+
- **init.sh paths updated directly** — forwarding scripts created by `init.sh` point to the domain going forward
96+
- **`scripts/startNeo4j.sh` and `scripts/stopNeo4j.sh` replaced with redirect stubs** — they forward to the domain implementation; not referenced by any pipeline code after the change, but kept so old project workspaces (already initialised before this change) continue to work without migration
97+
- **No domain entry-point scripts** (`*Csv.sh`, `*Python.sh`) — this domain is infrastructure, not report generation
98+
99+
---
100+
101+
### Pros and Cons: Moving Query Functions
102+
103+
The query execution infrastructure (`executeQueryFunctions.sh`, `executeQuery.sh`, `parseCsvFunctions.sh`, `projectionFunctions.sh`) was evaluated for inclusion:
104+
105+
**Pros of moving:**
106+
- Cohesive grouping — all Neo4j interaction in one place
107+
- Agent-friendly — a single domain to fully operate Neo4j
108+
- Cleaner `scripts/` directory
109+
110+
**Cons of moving:**
111+
- **30+ consumer files need path changes** — every report script, every domain script, `prepareAnalysis.sh`, `importGit.sh`
112+
- **Cross-domain coupling** — other domains would now depend on neo4j-management, breaking vertical-slice independence where each domain only depends on `scripts/`
113+
- **Mixing concerns** — management (lifecycle) and query execution (runtime API) are different layers
114+
- **No benefit to consumers** — the functions are already a stable, well-abstracted API
115+
116+
**Recommendation:** Don't move query functions now. Keep neo4j-management focused on lifecycle management. Query functions could become a separate `neo4j-query-api` domain later if desired.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
name: neo4j-management
3+
description: "Manage a local Neo4j database for code graph analysis. Use when: starting Neo4j, stopping Neo4j, detecting if Neo4j is running, checking Neo4j status, answering 'Is Neo4j running?', 'Is Neo4j currently running?', 'where is Neo4j running?', increasing Neo4j memory, switching analysis workspace, troubleshooting Neo4j, setting up Neo4j."
4+
argument-hint: "detect | start [workspace] | stop | memory | setup"
5+
---
6+
7+
# Neo4j Management
8+
9+
Manage the local Neo4j graph database lifecycle: detect, start, stop, reconfigure memory.
10+
11+
**Quick reference:**
12+
13+
| Action | Script | Typical trigger |
14+
|--------|--------|-----------------|
15+
| Detect | `detectNeo4j.sh` / `detectNeo4jWindows.sh` | First step always |
16+
| Start | `startNeo4j.sh` | Neo4j not running |
17+
| Stop | `stopNeo4j.sh` | Free resources, switch workspace |
18+
| Memory | `useNeo4jHighMemoryProfile.sh` | Out-of-memory or slow queries |
19+
| Setup | Use `analyze.sh` (see [GETTING_STARTED](../../GETTING_STARTED.md)) | New installation |
20+
21+
## When to Use
22+
23+
- User asks to start, stop, or check on Neo4j
24+
- User wants to switch to a different analysis workspace
25+
- User runs into memory issues (heap, page cache) and wants to increase Neo4j memory
26+
- User asks to set up or install Neo4j
27+
28+
## Domain Scripts
29+
30+
The scripts live in `domains/neo4j-management/`. **Detection scripts** (`detectNeo4j.sh`, `detectNeo4jWindows.sh`) inspect the process table and can be run from **any directory**, including the repository root. **Start/stop/configure scripts** must be run from the **analysis workspace directory** (e.g. `temp/my-project`).
31+
32+
| Script | Purpose |
33+
|--------|---------|
34+
| `detectNeo4j.sh` | Detect if Neo4j is running (Linux/macOS) |
35+
| `detectNeo4jWindows.sh` | Detect if Neo4j is running (WSL/Git Bash on Windows) |
36+
| `startNeo4j.sh` | Start Neo4j and wait until queryable |
37+
| `stopNeo4j.sh` | Stop Neo4j gracefully |
38+
| `useNeo4jHighMemoryProfile.sh` | Reconfigure with high-memory template |
39+
| `configureNeo4j.sh` | Apply a configuration template |
40+
41+
### Internal scripts — do NOT use directly
42+
43+
- `setupNeo4jInitialPassword.sh`
44+
- `waitForNeo4jHttpFunctions.sh`
45+
- `testConfigureNeo4j.sh`
46+
47+
## Procedure
48+
49+
### Step 1 — Detect if Neo4j Is Running
50+
51+
Determine the operating system. On **Windows** (WSL / Git Bash), run:
52+
53+
```shell
54+
./domains/neo4j-management/detectNeo4jWindows.sh
55+
```
56+
57+
On **Linux or macOS**, run:
58+
59+
```shell
60+
./domains/neo4j-management/detectNeo4j.sh
61+
```
62+
63+
The output is one of:
64+
65+
- `Neo4j not running`
66+
- `Neo4j running in <path> (workspace: <name>)` — workspace successfully identified
67+
- `Neo4j running in <path>` — path found but workspace could not be derived
68+
- `Neo4j running in (path undetermined)` — Neo4j is running but the path could not be read
69+
70+
#### Workspace identified `(workspace: <name>)`
71+
72+
The analysis workspace directory is the path **before** the `/tools` segment. For example, if the path is `/Users/me/repo/temp/my-project/tools/neo4j-community-2026.01.4`, the workspace is `/Users/me/repo/temp/my-project`. Inform the user and `cd` into that directory.
73+
74+
#### Path found but no workspace in parentheses
75+
76+
Neo4j is running outside the standard `temp/<workspace>/tools/...` layout.
77+
Ask the user if they know the workspace directory. If yes, `cd` into it and continue.
78+
If no — see [Troubleshooting guide](./references/troubleshooting.md) for manual stop and kill commands.
79+
80+
#### Path undetermined
81+
82+
Neo4j is running but the path cannot be read. Ask the user to run:
83+
84+
```shell
85+
ps -eo pid,command | grep -i neo4j | grep -v grep
86+
```
87+
88+
Once the path is identified, follow the "Path found" branch above or the [Troubleshooting guide](./references/troubleshooting.md).
89+
90+
### Step 2 — Decide Based on User Intent and Neo4j State
91+
92+
#### Neo4j is NOT running + user wants to start it
93+
94+
1. Ask the user which analysis workspace to use (e.g. `temp/my-project`) if not already known.
95+
2. `cd` into the analysis workspace directory.
96+
3. Prompt the user for the Neo4j password:
97+
> "What is your `NEO4J_INITIAL_PASSWORD`? (You can skip this if you prefer to set it yourself in the terminal — just type `skip` or press Enter.)"
98+
99+
- If the user provides a password, generate the export command:
100+
```shell
101+
export NEO4J_INITIAL_PASSWORD=<provided-password>
102+
```
103+
- If the user skips, remind them to run the export themselves before starting:
104+
> "Please run `export NEO4J_INITIAL_PASSWORD=<your-password>` in your terminal before starting Neo4j."
105+
4. Start Neo4j:
106+
```shell
107+
./startNeo4j.sh
108+
```
109+
110+
#### Neo4j IS running + user wants to start a DIFFERENT workspace
111+
112+
**Strongly warn the user**: running two analysis workspaces against the same Neo4j instance corrupts data by mixing results from different projects.
113+
114+
Recommend stopping the current analysis first:
115+
116+
```shell
117+
cd <current-workspace>
118+
./stopNeo4j.sh
119+
```
120+
121+
Only proceed with starting the new workspace after the user confirms they have stopped the old one.
122+
123+
#### Neo4j IS running + user wants to stop it
124+
125+
`cd` into the workspace where Neo4j is running, then:
126+
127+
```shell
128+
./stopNeo4j.sh
129+
```
130+
131+
#### User reports memory issues
132+
133+
Apply the high-memory configuration template. Neo4j must be **stopped** first.
134+
135+
```shell
136+
cd <workspace>
137+
./stopNeo4j.sh
138+
./useNeo4jHighMemoryProfile.sh
139+
./startNeo4j.sh
140+
```
141+
142+
### Step 3 — Setup / Installation Requests
143+
144+
> **Always recommend using `analyze.sh` first.** It handles download, installation, configuration, start, and stop automatically via profiles. Point the user to the [GETTING_STARTED guide](../../GETTING_STARTED.md).
145+
146+
Only assist with a manual `setupNeo4j.sh` invocation if the user can explain a concrete reason why the automated `analyze.sh` workflow does not fit their needs (e.g. custom Neo4j version, enterprise edition, non-standard directory layout).
147+
148+
## Environment Variables
149+
150+
All are set automatically by `analyze.sh` in normal runs. For manual operation:
151+
152+
| Variable | Default | Required |
153+
|----------|---------|----------|
154+
| `NEO4J_INITIAL_PASSWORD` || **Yes** |
155+
| `NEO4J_VERSION` | `2026.01.4` | No |
156+
| `NEO4J_EDITION` | `community` | No |
157+
| `NEO4J_HTTP_PORT` | `7474` | No |
158+
| `TOOLS_DIRECTORY` | `tools` | No |
159+
160+
## Important Warnings
161+
162+
- **Stop Neo4j before switching projects.** Data from different projects will mix in the same database instance otherwise.
163+
- **`NEO4J_INITIAL_PASSWORD` must be set** before starting or setting up Neo4j.
164+
- Scripts expect to be run from the analysis workspace directory (where the `tools/` folder lives).
165+
- **Docker is not supported.** Detection and management scripts rely on native process inspection (`ps`) and do not detect or manage Neo4j running inside a Docker container.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Neo4j Management — Troubleshooting
2+
3+
Reference for edge cases where Neo4j is running but the analysis workspace cannot be determined automatically.
4+
5+
## Path found but workspace unknown
6+
7+
Neo4j is running in a path that does not follow the standard `temp/<workspace>/tools/...` layout.
8+
9+
**Step 1:** Ask the user:
10+
11+
> "Neo4j is running in `<path>` but I could not determine the analysis workspace automatically. Do you know which workspace directory this belongs to?"
12+
13+
- If the user provides the workspace → `cd` into it and continue normally with `startNeo4j.sh` / `stopNeo4j.sh`.
14+
15+
**Step 2:** If the user does not know or says Neo4j is running outside the pipeline, help with manual control:
16+
17+
Locate the `bin/` directory inside the detected path (contains `neo4j` or `neo4j.bat`), then:
18+
19+
```shell
20+
# Stop (Linux/macOS)
21+
NEO4J_HOME=<path> <path>/bin/neo4j stop
22+
23+
# Stop (Windows, Git Bash or CMD)
24+
<path>\bin\neo4j.bat stop
25+
```
26+
27+
If the command above fails:
28+
29+
```shell
30+
# Linux/macOS — find the PID and send SIGTERM
31+
kill $(ps -eo pid,command | grep -i neo4j | grep -v grep | awk '{print $1}')
32+
33+
# Force kill if process does not stop after ~30 s
34+
kill -9 $(ps -eo pid,command | grep -i neo4j | grep -v grep | awk '{print $1}')
35+
```
36+
37+
```powershell
38+
# Windows PowerShell — find and stop Neo4j process
39+
Get-Process -Name java | Where-Object { $_.CommandLine -like '*neo4j*' } | Stop-Process
40+
```
41+
42+
## Path undetermined
43+
44+
Neo4j is running but the detect script could not read the path from the process.
45+
46+
**Step 1:** Ask the user to run the appropriate command to find the process:
47+
48+
```shell
49+
# Linux/macOS
50+
ps -eo pid,command | grep -i neo4j | grep -v grep
51+
```
52+
53+
```powershell
54+
# Windows PowerShell
55+
Get-CimInstance Win32_Process -Filter "Name='java.exe'" |
56+
Where-Object { $_.CommandLine -like '*neo4j*' } |
57+
Select-Object ProcessId, CommandLine
58+
```
59+
60+
**Step 2:** From the command output help the user identify the Neo4j home path:
61+
- Look for `--home-dir=<path>` in the command line (Neo4j 5+)
62+
- Or `-Dneo4j.home=<path>` (Neo4j 4)
63+
- Or a classpath entry ending in `/lib/*` — strip `/lib/*` to get the home
64+
65+
**Step 3:** Once the path is known, follow the "Path found but workspace unknown" section above.

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
This document describes the changes to the Code Graph Analysis Pipeline. The changes are grouped by version and date. The latest version is at the top.
44

5+
## (unreleased) Introduce neo4j-management domain
6+
7+
### ✨ Highlight
8+
9+
* Introduce `domains/neo4j-management/` as a vertical-slice domain that owns all Neo4j lifecycle management (install, configure, start, stop).
10+
11+
### 🚀 Features
12+
13+
* Move Neo4j management scripts from `scripts/` to `domains/neo4j-management/`:
14+
`setupNeo4j.sh`, `setupNeo4jInitialPassword.sh`, `configureNeo4j.sh`, `startNeo4j.sh`, `stopNeo4j.sh`,
15+
`detectNeo4j.sh`, `detectNeo4jWindows.sh`, `waitForNeo4jHttpFunctions.sh`, `useNeo4jHighMemoryProfile.sh`, `testConfigureNeo4j.sh`
16+
* Move Neo4j configuration templates from `scripts/configuration/` to `domains/neo4j-management/configuration/`:
17+
`template-neo4j.conf`, `template-neo4j-high-memory.conf`, `template-neo4j-low-memory.conf`, `template-neo4j-v4.conf`, `template-neo4j-v4-low-memory.conf`
18+
* Keep `scripts/startNeo4j.sh` and `scripts/stopNeo4j.sh` as **backward-compatible redirect stubs** so existing analysis workspaces continue to work without migration.
19+
* Extend `runTests.sh` to also discover and run test scripts in `domains/` subdirectories.
20+
521
## v3.5.0 Select analysis domain and npm dev dependency awareness
622

723
### ✨ Highlight

0 commit comments

Comments
 (0)