# CLAUDE.md — imagej-elphel

## Project overview
This repository contains Elphel plugins for **ImageJ 1.x**.
It is a **Maven project** (`pom.xml`) and is typically developed and tested
inside **Eclipse** using ImageJ run/debug configurations.

Target branch: `foliage-gpu`

## Build
Preferred build commands:

- Fast build (skip tests):
  ```bash
  mvn -DskipTests clean package
  ```

- Full build with tests:
  ```bash
  mvn clean package
  ```

Do not run Maven with interactive prompts.

## Tests
- Run all tests:
  ```bash
  mvn test
  ```

- Run a single test:
  ```bash
  mvn -Dtest=TestClassName test
  ```

If no relevant tests exist, state that explicitly.

## Running / debugging
- Prefer **running from Eclipse** using existing Run/Debug configurations.
- These plugins are usually exercised inside an ImageJ instance, not via a
  standalone CLI.
- If execution is required outside Eclipse, ask the user which ImageJ
  launcher, main class, JVM arguments, and plugin path should be used.

Do not invent run configurations.

### Eclipse run configuration
- Name: Eyesis_Correction
- Main class: com.elphel.imagej.correction.Eyesis_Correction
- VM arguments:
  ```
  -Xmx80000m
  -ea
  -Dawt.useSystemAAFontSettings=lcd
  -Dswing.aatext=true
  ```
- Runtime JRE: JavaSE-1.8 (OpenJDK 11)

## Coding conventions
- Do **not** reformat unrelated files.
- Keep changes minimal and localized.
- Preserve public APIs unless explicitly asked to change them.
- Match existing style and naming conventions.

## Dependencies
- Changes to `pom.xml` must be justified.
- Keep dependency versions consistent with existing project constraints.
- Avoid introducing new dependencies unless necessary.

## Repo hygiene
- Do not commit generated artifacts.
- Explain behavioral changes clearly.
- Prefer incremental commits if changes are non-trivial.

## Before proposing changes
- Ensure:
  ```bash
  mvn -DskipTests clean package
  ```
  succeeds.
- If tests exist, run them.
- Summarize:
  - what was changed
  - why it was changed
  - how to verify it (especially inside ImageJ)

## Interaction style
- Ask for clarification if requirements are ambiguous.
- Avoid assumptions about GPU availability or ImageJ runtime environment.

## User-specific notes
- Do not change source or data files unless explicitly asked; debugging depends on external data state.
- Always provide a diff for any changes made.
- `attic/CODEX/SHARED/` is a standalone Git repo (`git@git.elphel.com:elphelint/codex-shared.git`);
  after changes there, commit and push in that repo, and mention if SHARED push is pending.
- SHARED local path on this machine: `/home/elphel/git/imagej-elphel/attic/CODEX/SHARED`
- If SHARED is missing on a machine, clone with:
  ```bash
  git clone git@git.elphel.com:elphelint/codex-shared.git <workspace>/attic/CODEX/SHARED
  ```
- Access to `community.elphel.com` must go through jump host `elphel@192.168.0.107` (do not connect directly).
  - Direct form: `ssh -J elphel@192.168.0.107 root@community.elphel.com` (or `elphel5@community.elphel.com`)
  - Nested form: `ssh elphel@192.168.0.107` then `ssh root@community.elphel.com`
- For `codex@elphel.com` mail tasks:
  - `attic/codex-elphel/scripts/email_fetch.py` and `attic/codex-elphel/scripts/email_send.py`
    auto-load local mail settings from `~/.config/elphel-mail.env` when present.
  - Keep secrets only in that local file with mode `0600`; do not put credentials in Git-tracked files.
  - Trusted outgoing path uses `community.elphel.com` sendmail via the jump host above.
- When Andrey ends a message with a trailing `\`, treat it as "not finished"; reply briefly if needed
  but do not take actions or run commands yet.

## Claude workspace
- Claude-specific artifacts (opinions, HOWTOs, analysis outputs) live in `attic/CLAUDE/`.
- `attic/CLAUDE/bin/` contains Claude helper scripts (see below).
- Per-session memory: `/home/elphel/.claude/projects/-home-elphel-git-imagej-elphel/memory/`
- The SHARED handoff repo (`attic/CODEX/SHARED/handoffs/`) is readable for cross-agent context.

## Cross-agent consultation

### "consult Codex" — Claude calls Codex
When the user's prompt contains **"consult Codex"** (any capitalisation), do the following
instead of (or in addition to) answering directly:

1. Run Codex on the same question using the Bash tool:
   ```bash
   codex exec -s read-only -C /home/elphel/git/imagej-elphel \
     -o /tmp/codex_opinion_<timestamp>.md \
     "<question + embedded context>"
   ```
2. Read the output file.
3. Present a synthesis in three sections:
   - **Both agree** — points where both agents recommend the same thing
   - **Codex-only** — what Codex raised that Claude did not
   - **Claude-only** — what Claude raised that Codex did not

### "dual opinion" / "second opinion" — full parallel run
For an explicit side-by-side comparison, run the helper script:
```bash
attic/CLAUDE/bin/dual-opinion.sh [-f file...] "question"
# or with a question file:
attic/CLAUDE/bin/dual-opinion.sh -q question.md [-f file...]
```
Output is saved under `attic/CLAUDE/opinions/<timestamp>/`.

### Claude daemon (for Codex to call Claude)
`attic/CLAUDE/bin/claude_daemon.sh` is a file-watching daemon that lets Codex (or any
sandboxed tool) query Claude without needing direct access to the claude binary.

- **Start**: `attic/CLAUDE/bin/claude_daemon.sh --background`
- **Stop**:  `attic/CLAUDE/bin/claude_daemon.sh --stop`
- **Status**: `attic/CLAUDE/bin/claude_daemon.sh --status`
- **systemd**: install `attic/CLAUDE/claude-daemon.service` to start on login

Codex invokes it via: `attic/CLAUDE/bin/ask_claude.sh [-f file...] "question"`
