Skip to content

Commit f60e292

Browse files
authored
Merge pull request #555 from JohT/feature/introduce-neo4j-management-domain
Introduce neo4j management domain
2 parents e687b31 + 593815b commit f60e292

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1766
-882
lines changed
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](domains/neo4j-management/setupNeo4j.sh), [setupNeo4jInitialPassword.sh](domains/neo4j-management/setupNeo4jInitialPassword.sh), [configureNeo4j.sh](domains/neo4j-management/configureNeo4j.sh) *(pre-move locations: `scripts/setupNeo4j.sh`, `scripts/setupNeo4jInitialPassword.sh`, `scripts/configureNeo4j.sh`)*
12+
- [startNeo4j.sh](domains/neo4j-management/startNeo4j.sh), [stopNeo4j.sh](domains/neo4j-management/stopNeo4j.sh) *(pre-move locations: `scripts/startNeo4j.sh`, `scripts/stopNeo4j.sh`)*
13+
- [detectNeo4j.sh](domains/neo4j-management/detectNeo4j.sh), [detectNeo4jWindows.sh](domains/neo4j-management/detectNeo4jWindows.sh) *(pre-move locations: `scripts/detectNeo4j.sh`, `scripts/detectNeo4jWindows.sh`)*
14+
- [waitForNeo4jHttpFunctions.sh](domains/neo4j-management/waitForNeo4jHttpFunctions.sh), [useNeo4jHighMemoryProfile.sh](domains/neo4j-management/useNeo4jHighMemoryProfile.sh) *(pre-move locations: `scripts/waitForNeo4jHttpFunctions.sh`, `scripts/useNeo4jHighMemoryProfile.sh`)*
15+
- [testConfigureNeo4j.sh](domains/neo4j-management/testConfigureNeo4j.sh) *(pre-move location: `scripts/testConfigureNeo4j.sh`)*
16+
3a. Replace the pre-move scripts `scripts/startNeo4j.sh` and `scripts/stopNeo4j.sh` with **minimal redirect stubs** that forward to [domains/neo4j-management/startNeo4j.sh](domains/neo4j-management/startNeo4j.sh) and [domains/neo4j-management/stopNeo4j.sh](domains/neo4j-management/stopNeo4j.sh) 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. Do not change [SCRIPTS.md](SCRIPTS.md) its will be regenerated 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), [.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: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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: "is neo4j running | 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+
Always run the detect script first — do **not** attempt to read processes, ports, or any other signals manually before the script has been executed.
52+
53+
Determine the operating system. On **Windows** (WSL / Git Bash), run:
54+
55+
```shell
56+
./domains/neo4j-management/detectNeo4jWindows.sh
57+
```
58+
59+
On **Linux or macOS**, run:
60+
61+
```shell
62+
./domains/neo4j-management/detectNeo4j.sh
63+
```
64+
65+
If the script produces no output at all, run it a **second time** before drawing any conclusions. Only if the second run also returns nothing, treat it as equivalent to `Neo4j not running`.
66+
67+
The output is one of:
68+
69+
- `Neo4j not running`
70+
- `Neo4j running in <path> (workspace: <name>)` — workspace successfully identified
71+
- `Neo4j running in <path>` — path found but workspace could not be derived
72+
- `Neo4j running in (path undetermined)` — Neo4j is running but the path could not be read
73+
74+
#### Workspace identified `(workspace: <name>)`
75+
76+
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.
77+
78+
#### Path found but no workspace in parentheses
79+
80+
Neo4j is running outside the standard `temp/<workspace>/tools/...` layout.
81+
Ask the user if they know the workspace directory. If yes, `cd` into it and continue.
82+
If no — see [Troubleshooting guide](./references/troubleshooting.md) for manual stop and kill commands.
83+
84+
#### Path undetermined
85+
86+
Neo4j is running but the path cannot be read. Ask the user to run:
87+
88+
```shell
89+
ps -eo pid,command | grep -i neo4j | grep -v grep
90+
```
91+
92+
Once the path is identified, follow the "Path found" branch above or the [Troubleshooting guide](./references/troubleshooting.md).
93+
94+
### Step 2 — Decide Based on User Intent and Neo4j State
95+
96+
#### Neo4j is NOT running + user wants to start it
97+
98+
1. Ask the user which analysis workspace to use (e.g. `temp/my-project`) if not already known.
99+
2. `cd` into the analysis workspace directory.
100+
3. Prompt the user for the Neo4j password:
101+
> "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.)"
102+
103+
- If the user provides a password, generate the export command:
104+
```shell
105+
export NEO4J_INITIAL_PASSWORD=<provided-password>
106+
```
107+
- If the user skips, remind them to run the export themselves before starting:
108+
> "Please run `export NEO4J_INITIAL_PASSWORD=<your-password>` in your terminal before starting Neo4j."
109+
4. Start Neo4j:
110+
```shell
111+
./startNeo4j.sh
112+
```
113+
114+
#### Neo4j IS running + user wants to start a DIFFERENT workspace
115+
116+
**Strongly warn the user**: running two analysis workspaces against the same Neo4j instance corrupts data by mixing results from different projects.
117+
118+
Recommend stopping the current analysis first:
119+
120+
```shell
121+
cd <current-workspace>
122+
./stopNeo4j.sh
123+
```
124+
125+
Only proceed with starting the new workspace after the user confirms they have stopped the old one.
126+
127+
#### Neo4j IS running + user wants to stop it
128+
129+
`cd` into the workspace where Neo4j is running, then:
130+
131+
```shell
132+
./stopNeo4j.sh
133+
```
134+
135+
#### User reports memory issues
136+
137+
Apply the high-memory configuration template. Neo4j must be **stopped** first.
138+
139+
```shell
140+
cd <workspace>
141+
./stopNeo4j.sh
142+
./useNeo4jHighMemoryProfile.sh
143+
./startNeo4j.sh
144+
```
145+
146+
### Step 3 — Setup / Installation Requests
147+
148+
> **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).
149+
150+
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).
151+
152+
## Environment Variables
153+
154+
All are set automatically by `analyze.sh` in normal runs. For manual operation:
155+
156+
| Variable | Default | Required |
157+
|----------|---------|----------|
158+
| `NEO4J_INITIAL_PASSWORD` || **Yes** |
159+
| `NEO4J_VERSION` | `2026.01.4` | No |
160+
| `NEO4J_EDITION` | `community` | No |
161+
| `NEO4J_HTTP_PORT` | `7474` | No |
162+
| `TOOLS_DIRECTORY` | `tools` | No |
163+
164+
## Important Warnings
165+
166+
- **Stop Neo4j before switching projects.** Data from different projects will mix in the same database instance otherwise.
167+
- **`NEO4J_INITIAL_PASSWORD` must be set** before starting or setting up Neo4j.
168+
- Scripts expect to be run from the analysis workspace directory (where the `tools/` folder lives).
169+
- **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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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-CimInstance Win32_Process -Filter "Name='java.exe'" |
40+
Where-Object { $_.CommandLine -like '*neo4j*' } |
41+
Select-Object -ExpandProperty ProcessId |
42+
Stop-Process -Id
43+
```
44+
45+
## Path undetermined
46+
47+
Neo4j is running but the detect script could not read the path from the process.
48+
49+
**Step 1:** Ask the user to run the appropriate command to find the process:
50+
51+
```shell
52+
# Linux/macOS
53+
ps -eo pid,command | grep -i neo4j | grep -v grep
54+
```
55+
56+
```powershell
57+
# Windows PowerShell
58+
Get-CimInstance Win32_Process -Filter "Name='java.exe'" |
59+
Where-Object { $_.CommandLine -like '*neo4j*' } |
60+
Select-Object ProcessId, CommandLine
61+
```
62+
63+
**Step 2:** From the command output help the user identify the Neo4j home path:
64+
- Look for `--home-dir=<path>` in the command line (Neo4j 5+)
65+
- Or `-Dneo4j.home=<path>` (Neo4j 4)
66+
- Or a classpath entry ending in `/lib/*` — strip `/lib/*` to get the home
67+
68+
**Step 3:** Once the path is known, follow the "Path found but workspace unknown" section above.

0 commit comments

Comments
 (0)