# Vikar Phase 1 AddOn — install & E2E test runbook (test box)

Phase 1 is **read-only chat**. This AddOn never trades, never changes a chart,
never enables a strategy. It logs in to the Vikar staging backend and chats.

There are two files that matter:

- `src/Vikar.cs` — the source of record.
- `package/Vikar.cs` — an identical copy; this is the file you install.

---

## 0. Before you start — set the API URL

The source ships with a placeholder backend URL:

```csharp
private const string ApiBaseUrl = "https://ninjagpt-api.PLACEHOLDER.workers.dev";
```

The desk replaces `ninjagpt-api.PLACEHOLDER.workers.dev` with the deployed
staging `workers.dev` URL before the test build is packaged. **Check the file
you received has no `PLACEHOLDER` left in it** (search the .cs). If it does,
stop and get the built file from the desk — do not guess the URL.

## 1. Install (raw .cs path — this IS the test install path)

1. Close NinjaTrader 8 if it is running (not strictly required, but the
   compile in step 4 is cleaner on a fresh start).
2. Copy `package/Vikar.cs` to:

   ```
   Documents\NinjaTrader 8\bin\Custom\AddOns\Vikar.cs
   ```

   Create the `AddOns` folder if it does not exist.
3. Start NinjaTrader 8.
4. **References — REQUIRED on a fresh box (both proven on the Lab box, Nov 24, 2026):**
   in the NinjaScript Editor, open the References dialog and add BOTH of these
   if they are not already in the Applied list, BEFORE compiling:
   - `C:\Program Files\NinjaTrader 8\bin\Newtonsoft.Json.dll` (JSON parsing)
   - `System.Security.dll` from the .NET Framework64 directory (DPAPI —
     the remembered-identity blob). In the dialog it appears in HintPath form.
   Without them the compile fails with CS0246 on the Newtonsoft types and
   the ProtectedData family respectively — these are install steps, not
   code defects.
5. Compile: open **New → NinjaScript Editor**, press **F5** (Compile).
   - NT's file watcher may auto-compile on its own when the file lands —
     either way, confirm the Output panel shows **no errors** mentioning
     `Vikar`.
   - If there are errors: copy the exact error lines (file, line, code) and
     send them back to the desk. Do not edit the file on the box except for
     the API-URL step the desk asked for. See `BUILD-NOTES.md` for the known
     friction points and their fixes.
6. Restart NinjaTrader once after the first clean compile (the Control
   Center menu is built at startup; a restart guarantees the AddOn's menu
   registration runs against a fresh Control Center).

## 2. Open the chat

1. In the **Control Center**, open the **New** menu.
2. Click **Vikar Chat**. A window titled "Vikar Chat" opens with the
   login view. (It docks as a tab in an NT workspace like any NTWindow.)

## 3. E2E test script — run it in this exact order

Use the staging test account the desk issued for this run. Note the credit
balance before you start (shown in the chat header after login, and on the
staging dashboard).

1. **Login (email + password).** Enter the test account email and password,
   click **Log in**.
   - Expect: the chat view opens; the header shows
     `email · plan · N credits`. A system line says you're logged in.
   - Also confirm the file
     `Documents\NinjaTrader 8\bin\Custom\Vikar\identity.bin` now exists —
     that is the DPAPI blob holding **email + licence key only**. It must
     NOT contain the password or a session token in plain text (it's
     encrypted; just confirm the file exists and is small).
2. **Ask a local (built-in) question.** Type:
   `What is Vikar?` — or another question the desk marks as built-in —
   and press **Enter**.
   - Expect: an answer appears; the credit count in the header does **not**
     change (built-in answers are free).
3. **Ask an AI question.** Type a question that needs the AI, e.g.
   `Explain an opening range breakout in plain words.` and press **Enter**.
   - Expect: a "Vikar is thinking…" bubble, then the AI's answer
     (polling can take up to ~60 s; staging is usually a few seconds).
   - Expect: **the credit count in the header drops by exactly 1.**
4. **Empty-credit state.** Ask the desk to set the test account to 0 credits
   (or drain it), then ask another AI question.
   - Expect the system message:
     "You're out of AI credits. Built-in answers still work — top up or
     upgrade when checkout opens at launch."
   - Expect: built-in questions still answer.
5. **Log out.** Click **Log out** in the header.
   - Expect: you're back on the login view with "You've been logged out."
   - The login view may pre-fill email/licence key (that's the DPAPI blob —
     by design). The password field must be **empty**.
6. **Logged-out state.** Reopen the window if you closed it; without logging
   in, confirm you see the login view (not the chat). Then log in again with
   the **licence key only** (paste the key, click **Use key**).
   - Expect: same chat view, same credit count as after step 4.
7. **Chart context (optional, read-only).** Open any chart, then ask:
   `What chart am I looking at?`
   - The message goes out with `{instrument, barPeriod}` attached. Nothing
     on the chart changes — no indicator appears, nothing is enabled. If
     the answer doesn't mention the chart, that's a backend/context note
     for the desk, not a failure of this AddOn — record what happened.

Record for each step: pass/fail + a screenshot of the chat window at steps
1, 3 (showing the dropped credit count) and 4. Send the record back with
any NinjaScript Editor error lines from step 1.4 if there were any.

## 4. Uninstall

1. Close NinjaTrader.
2. Delete `Documents\NinjaTrader 8\bin\Custom\AddOns\Vikar.cs`.
3. Optionally delete `Documents\NinjaTrader 8\bin\Custom\Vikar\`
   (the DPAPI identity blob).
4. Start NinjaTrader and compile once (F5 in the NinjaScript Editor) so NT
   rebuilds without the AddOn. The **New → Vikar Chat** menu item is
   gone.

## 5. What this AddOn stores on the machine — the whole list

| Thing | Where | Notes |
|---|---|---|
| Email + licence key | `bin\Custom\Vikar\identity.bin` | DPAPI-encrypted, CurrentUser scope |
| Session token | Memory only | Gone when NT closes; never on disk |
| Password | **Nowhere** | Typed, sent over HTTPS, forgotten |
| OpenAI API key | **Nowhere — not in this product's client at all** | Server-side only, behind the relay |
