@ai-digital-factory/lmt-cli 0.1.1 → 0.1.3

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 (3) hide show
  1. package/README.md +45 -18
  2. package/dist/index.js +711 -199
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -20,6 +20,16 @@ npm list --global @ai-digital-factory/lmt-cli --depth=0
20
20
 
21
21
  The package includes the non-secret Origins, Gate scopes, and SMS endpoint. Choose `--env dev` for the deployed dev service, or `--env local` for a running local stack. Only `local` and `dev` are supported; `prod` is rejected. Installing the CLI does not start services or provision credentials.
22
22
 
23
+ ## Candle Export for Runner
24
+
25
+ With a saved Operator Session, request one instrument and optional IST date:
26
+
27
+ ```sh
28
+ lmt candle-export NSE:IDEA --date 2026-10-23 --env dev --profile runner --timeout 2m
29
+ ```
30
+
31
+ Omitting `--date` asks Broker for the exchange's latest completed trading session, accounting for holidays and Finalization Grace. The stdout JSON `candleExport` contains the immutable Hosted URL, filename, resolved identity/date, source availability, reference-fetch metadata, and comparison counts. Missing data or Zerodha authentication is explained in the workbook. Export does not start Zerodha login or token recovery. Local/dev only; see `lmt --help` for exit conventions.
32
+
23
33
  ## Quick start: interactive dev login
24
34
 
25
35
  1. Obtain your Operator Login username and password. For headless login and Operator Session validation, also obtain an SMS read credential authorized to read `live-market-terminal-operator-directory` in the selected Gate scope from your administrator.
@@ -37,7 +47,7 @@ The package includes the non-secret Origins, Gate scopes, and SMS endpoint. Choo
37
47
  ```
38
48
 
39
49
  Enter your Operator Login username and password when prompted. This interactive login uses the credentials you enter; it does not require reading them from SMS. A valid saved session resumes automatically.
40
- 4. Use the menu to **Login with Zerodha**, **Check Operator Session**, **Validate Operator Session**, or **Logout Operator Session**. Zerodha login prompts for the current six-digit OTP. Validation requires the provisioned SMS credential.
50
+ 4. Use the menu to **Login with Zerodha**, **Check Operator Session**, **Validate Operator Session**, **Validate Zerodha Session**, **Resume Zerodha Validation**, or **Logout Operator Session**. Zerodha login prompts for the current six-digit OTP. Validation requires the provisioned SMS credential.
41
51
 
42
52
  Press Enter to submit each prompt. At the Operator password prompt, Escape returns to the username; Ctrl+U clears either field. Passwords remain masked. Press Ctrl+C to exit the terminal; use the logout command or menu action when you want to revoke the Operator Session.
43
53
 
@@ -72,37 +82,48 @@ Replace the path with an owner-readable credential file supplied by your secret-
72
82
 
73
83
  ## Headless Zerodha login
74
84
 
75
- First establish an Operator Session with `lmt login` or interactive login using the same environment and profile. Zerodha credentials stay on Broker. Submit the current six-digit OTP:
85
+ First establish the Operator Session with `login`. Zerodha credentials stay on Broker. Headless Zerodha login uses one two-step flow, matching Web: start login first, then obtain the OTP from Kite and submit it to that exact attempt.
76
86
 
77
- ```sh
78
- lmt zerodha login --env dev --profile my-dev-session --otp CURRENT_OTP
79
- lmt zerodha status --env dev --profile my-dev-session
80
- ```
87
+ 1. Start the Zerodha Login Attempt:
81
88
 
82
- Replace `CURRENT_OTP` with the actual six-digit code. `zerodha login` starts or resumes the profile's login attempt and verifies the resulting Zerodha Session through Gate. The OTP is not stored or included in JSON results or diagnostics; it is passed as a command argument. `--otp-stdin` is unsupported.
89
+ ```sh
90
+ lmt zerodha login --env dev --profile my-dev-session
91
+ ```
83
92
 
84
- To start the challenge before obtaining the OTP:
93
+ When Zerodha requests the OTP, the command returns `outcome: "blocked"`, `reason: "awaiting_otp"`, exit code `4`, and `zerodha.attemptId`. This is the expected handoff to obtain the OTP from Kite.
85
94
 
86
- ```sh
87
- lmt zerodha login --env dev --profile my-dev-session
88
- ```
95
+ 2. Copy that attempt ID and submit the current six-digit OTP:
96
+
97
+ ```sh
98
+ # Bash: mask entry, disable tracing, and send through the builtin printf pipe.
99
+ set +x
100
+ IFS= read -r -s -p 'Kite OTP: ' otp_value
101
+ printf '\n' >&2
102
+ printf '%s\n' "$otp_value" | lmt zerodha otp --env dev --profile my-dev-session --attempt ATTEMPT_ID --otp-stdin
103
+ unset otp_value
104
+ ```
105
+
106
+ Replace `ATTEMPT_ID` with `zerodha.attemptId` from step 1 and enter the code obtained after the challenge at the masked prompt. Use the same environment and profile in both steps. Success requires verification of the resulting Zerodha Session through Gate. OTPs are excluded from JSON results and diagnostics and never stored.
89
107
 
90
- When human input is needed, this returns `outcome: "blocked"`, `reason: "awaiting_otp"`, and exit code `4`. Repeat `zerodha login` with `--otp CURRENT_OTP` once the code is available. Attempt IDs are remembered automatically for the selected profile and target.
108
+ From the monorepo root, use `pnpm -s cli:headless` in place of `lmt`. Both `local` and `dev` are supported.
91
109
 
92
- Additional commands for an existing attempt:
110
+ To inspect the attempt or verify the session:
93
111
 
94
112
  ```sh
95
- lmt zerodha observe --env dev --profile my-dev-session
96
- lmt zerodha otp --env dev --profile my-dev-session --otp CURRENT_OTP
113
+ lmt zerodha observe --env dev --profile my-dev-session --attempt ATTEMPT_ID
114
+ lmt zerodha status --env dev --profile my-dev-session
97
115
  ```
98
116
 
99
- `observe` and `otp` optionally accept `--attempt ID` to override the remembered attempt. Invalid OTPs report Broker's rejection message and retry count. Successful login, Operator logout, and Operator Session replacement or rejection clear the remembered attempt.
117
+ `--attempt ID` is required for `zerodha otp` and `zerodha observe`. The CLI does not remember attempt IDs. Existing saved attempt IDs are ignored and removed on the next profile-store write; saved cookies and the SMS credential remain usable. Argument-based `--otp CODE` and `--otp=CODE` are rejected before credential or network access. Migrate scripts to explicitly selected `--otp-stdin`; provide one six-digit line through a protected pipe and close it. Terminal input, extra lines, more than eight bytes, and unfinished input past `--timeout` are rejected. There is no single-pass login or automatic resume. See [protected OTP migration and local/dev smoke steps](docs/protected-otp.md).
118
+
119
+ An expired, canceled, replaced, or failed attempt fails without starting a new login or submitting the OTP to another attempt. Explicitly run `zerodha login` again, obtain the new challenge's OTP, and submit it using the new attempt ID. A rejected OTP that leaves the attempt active returns `awaiting_otp` with Broker's rejection message and retry count; retry `zerodha otp` with a fresh code and the same ID. Every command remains noninteractive and honors `--timeout`.
120
+
100
121
 
101
122
  ## Profiles and local use
102
123
 
103
124
  Profiles save Client Identity and Operator Session cookies across invocations. Sessions are isolated by profile, environment, canonical Origin, and configured Operator. Profile names must be 1–64 letters, digits, dots, underscores, or hyphens, starting with a letter or digit.
104
125
 
105
- Storage is `~/.lmt/secrets.pem`: a protected JSON file containing the shared SMS credential, per-profile cookies, and pending Zerodha attempt IDs. The CLI enforces owner-only permissions and migrates legacy storage automatically. Do not share this file or include it in logs or version control.
126
+ Storage is `~/.lmt/secrets.pem`: a protected JSON file containing the shared SMS credential and per-profile cookies. The CLI enforces owner-only permissions and migrates legacy storage automatically. Do not share this file or include it in logs or version control.
106
127
 
107
128
  For local use, first start Web, Gate, and Broker from a configured source checkout with `pnpm dev:local` in `live-market-terminal/`. The installed CLI uses the bundled canonical local Origin (`http://127.0.0.1:5173`) through Web's `/api` proxy; it does not fall back to a different port. The CLI's SMS read credential is separate from the service credential used by Gate and Broker.
108
129
 
@@ -121,7 +142,7 @@ Headless commands write one versioned JSON object per line to stdout; diagnostic
121
142
  | `1` | Action failure | Read the diagnostic; check SMS permissions or service reachability. |
122
143
  | `2` | Invalid invocation or target | Check `lmt --help`; supply `local` or `dev` and a valid profile. |
123
144
  | `3` | Operator Login required | Run `login` or interactive login with the same environment and profile. |
124
- | `4` | Validation blocked or Zerodha awaiting OTP | Read `reason`; for `awaiting_otp`, repeat Zerodha login with the current OTP. |
145
+ | `4` | Validation blocked or Zerodha awaiting OTP | Read `reason`; for `awaiting_otp`, obtain the Kite OTP and run `zerodha otp --attempt ID --otp-stdin`. |
125
146
 
126
147
  Actions default to 30 seconds; validation defaults to 2 minutes. Headless actions and validation accept a finite deadline between 1 millisecond and 10 minutes:
127
148
 
@@ -178,3 +199,9 @@ To reproduce the packaging checks from the repository root:
178
199
  tarball=$(bash .github/scripts/pack-lmt-cli.sh /tmp/lmt-cli-package)
179
200
  node .github/scripts/test-lmt-cli-package.mjs "$tarball"
180
201
  ```
202
+
203
+ ### Zerodha validation
204
+
205
+ `lmt validate zerodha-session --env local --profile NAME` starts a new Broker-owned attempt and returns an attributed blocked report when a human OTP is needed. Resume with the same profile and explicit `--attempt ID`; add `--otp-stdin` to submit the protected human code. Without that flag, the supplied attempt is only observed. A pass requires authoritative attempt state followed by a hard session check; status alone does not pass the scenario. The resulting session stays available on the caller profile.
206
+
207
+ Interactive **Validate Zerodha Session** runs the same scenario with masked OTP input and a visible report. **Resume Zerodha Validation** asks for an explicit attempt ID. Fresh validation can replace the Operator's active Broker attempt and successful login can refresh its shared token. CLI profile isolation does not isolate that shared state. See [local/dev validation smoke steps and recorded prerequisites](ZERODHA-SMOKE.md).