pine2profit 0.0.0-stage โ†’ 1.1.0

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 (63) hide show
  1. package/README.md +243 -2
  2. package/build/.gitkeep +0 -0
  3. package/build/index.cjs +1152 -0
  4. package/build/index.mjs +1142 -0
  5. package/build/modules/frontend/build/.nojekyll +0 -0
  6. package/build/modules/frontend/build/404/index.html +1 -0
  7. package/build/modules/frontend/build/404.html +1 -0
  8. package/build/modules/frontend/build/_next/static/_d4V5OqT091alEqu95MT1/_buildManifest.js +1 -0
  9. package/build/modules/frontend/build/_next/static/_d4V5OqT091alEqu95MT1/_ssgManifest.js +1 -0
  10. package/build/modules/frontend/build/_next/static/chunks/11.78c5bec5897e1148.js +1 -0
  11. package/build/modules/frontend/build/_next/static/chunks/195.64632be71175c993.js +63 -0
  12. package/build/modules/frontend/build/_next/static/chunks/204.008bcbcf48844ee2.js +1 -0
  13. package/build/modules/frontend/build/_next/static/chunks/255-da04dc9178303a31.js +1 -0
  14. package/build/modules/frontend/build/_next/static/chunks/2738385b.306f7750ad5b8be4.js +372 -0
  15. package/build/modules/frontend/build/_next/static/chunks/338-31711140cb6d61e5.js +1 -0
  16. package/build/modules/frontend/build/_next/static/chunks/4bd1b696-c023c6e3521b1417.js +1 -0
  17. package/build/modules/frontend/build/_next/static/chunks/50e49f97.75feacc2b3cc7709.js +433 -0
  18. package/build/modules/frontend/build/_next/static/chunks/554.dd4ac9a0aff9b782.js +1 -0
  19. package/build/modules/frontend/build/_next/static/chunks/570-33c81efca66c4bc9.js +3 -0
  20. package/build/modules/frontend/build/_next/static/chunks/5957d0c3.7b96612772854e2d.js +2 -0
  21. package/build/modules/frontend/build/_next/static/chunks/619-f09bc47e24909021.js +1 -0
  22. package/build/modules/frontend/build/_next/static/chunks/7589b812.60f2b16513f3aa42.js +1 -0
  23. package/build/modules/frontend/build/_next/static/chunks/771.5c62ba94f930669e.js +1 -0
  24. package/build/modules/frontend/build/_next/static/chunks/796.4b04b2b64c066b03.js +1 -0
  25. package/build/modules/frontend/build/_next/static/chunks/897-b727cc7229802490.js +1 -0
  26. package/build/modules/frontend/build/_next/static/chunks/app/_not-found/page-b6d9300903c2ab41.js +1 -0
  27. package/build/modules/frontend/build/_next/static/chunks/app/layout-0da8bd54f47c9e1b.js +1 -0
  28. package/build/modules/frontend/build/_next/static/chunks/app/page-7ab911a70ef48cfe.js +1 -0
  29. package/build/modules/frontend/build/_next/static/chunks/app/run/page-42836fc705c46a59.js +1 -0
  30. package/build/modules/frontend/build/_next/static/chunks/c525c9ef.018edb9552a70fc2.js +143 -0
  31. package/build/modules/frontend/build/_next/static/chunks/e1865c21-8d63eb0f5b25cb0c.js +1 -0
  32. package/build/modules/frontend/build/_next/static/chunks/framework-28b60818f5cffd83.js +1 -0
  33. package/build/modules/frontend/build/_next/static/chunks/main-45ecedd1f28e3a74.js +1 -0
  34. package/build/modules/frontend/build/_next/static/chunks/main-app-4ff0bbe1b367fcb5.js +1 -0
  35. package/build/modules/frontend/build/_next/static/chunks/pages/_app-7d307437aca18ad4.js +1 -0
  36. package/build/modules/frontend/build/_next/static/chunks/pages/_error-cb2a52f75f2162e2.js +1 -0
  37. package/build/modules/frontend/build/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  38. package/build/modules/frontend/build/_next/static/chunks/webpack-bb5ccf34ea47f1d7.js +1 -0
  39. package/build/modules/frontend/build/_next/static/css/91363587ff8467b5.css +1 -0
  40. package/build/modules/frontend/build/_next/static/media/29b98dbfba401fa9-s.p.woff2 +0 -0
  41. package/build/modules/frontend/build/_next/static/media/313510e2713fb214-s.p.woff2 +0 -0
  42. package/build/modules/frontend/build/_next/static/media/558ca1a6aa3cb55e-s.p.woff2 +0 -0
  43. package/build/modules/frontend/build/_next/static/media/64d784ea54a4acde-s.woff2 +0 -0
  44. package/build/modules/frontend/build/_next/static/media/6d831b18ae5b01dc-s.woff2 +0 -0
  45. package/build/modules/frontend/build/_next/static/media/8048a25e80cc4179-s.woff2 +0 -0
  46. package/build/modules/frontend/build/_next/static/media/851c4691abdf3def-s.woff2 +0 -0
  47. package/build/modules/frontend/build/_next/static/media/87bc17f7c8b98e48-s.woff2 +0 -0
  48. package/build/modules/frontend/build/_next/static/media/982ceffe7b733b3b-s.p.woff2 +0 -0
  49. package/build/modules/frontend/build/_next/static/media/a6c19694cd327cd4-s.woff2 +0 -0
  50. package/build/modules/frontend/build/_next/static/media/a8a8dd7277bab4cf-s.woff2 +0 -0
  51. package/build/modules/frontend/build/_next/static/media/ac0e76ddaeeb7981-s.woff2 +0 -0
  52. package/build/modules/frontend/build/_next/static/media/b8bfb68ab9ab617c-s.woff2 +0 -0
  53. package/build/modules/frontend/build/_next/static/media/d76fe899475ae4d7-s.woff2 +0 -0
  54. package/build/modules/frontend/build/_next/static/media/e546cf32c9d4702c-s.woff2 +0 -0
  55. package/build/modules/frontend/build/_next/static/media/edc640959b0c7826-s.woff2 +0 -0
  56. package/build/modules/frontend/build/_next/static/media/ff71da380fbe67dd-s.woff2 +0 -0
  57. package/build/modules/frontend/build/icon.svg +1 -0
  58. package/build/modules/frontend/build/index.html +1 -0
  59. package/build/modules/frontend/build/index.txt +23 -0
  60. package/build/modules/frontend/build/run/index.html +1 -0
  61. package/build/modules/frontend/build/run/index.txt +23 -0
  62. package/package.json +93 -4
  63. package/types.d.ts +124 -0
package/README.md CHANGED
@@ -1,3 +1,244 @@
1
- # Temporary Holding Version
1
+ <img src="https://github.com/pine2profit/pine2profit/raw/refs/heads/main/assets/icon.svg" height="45px" align="right">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # ๐ŸŒฒ pine2profit
4
+
5
+ > Can money be made on this? A dashboard for an agent that loops over TradingView Pine Script indicators and strategies and answers that one question per script by trading its alerts on paper. The package is the static site plus a local server that serves your `data/` folder to it โ€” the same files go to GitHub Pages unchanged.
6
+
7
+ ![screenshot](https://raw.githubusercontent.com/pine2profit/pine2profit/HEAD/assets/screenshot.png)
8
+
9
+ [![npm](https://img.shields.io/npm/v/pine2profit.svg?style=flat-square)](https://npmjs.org/package/pine2profit)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue)]()
11
+ [![Next.js](https://img.shields.io/badge/Next.js-15-black)]()
12
+
13
+ ๐Ÿ™ **[GitHub](https://github.com/pine2profit/pine2profit)** ยท ๐Ÿ“– **`npx pine2profit --help`** prints the data contract with JSON examples
14
+
15
+ ---
16
+
17
+ ## ๐Ÿš€ Quick Start
18
+
19
+ ```bash
20
+ npx pine2profit <dir> # dir = the folder that contains data/
21
+ ```
22
+
23
+ Open http://localhost:60050. The site reads everything with plain `GET` from `data/`, so a data folder that works here works on GitHub Pages unchanged.
24
+
25
+ ## Filling the site with an agent
26
+
27
+ The package does not write `data/`. It is built so that an AI agent running in a loop can: the contract is a few flat files, and the server picks up every change on the next request (`Cache-Control: no-store`). A typical setup with Claude Code:
28
+
29
+ 1. **Start the preview** in the project folder and leave it running:
30
+
31
+ ```bash
32
+ mkdir -p project/data && npx pine2profit ./project
33
+ ```
34
+
35
+ An empty `index_1.jsonl` is a valid start. The folder is checked on every start and a single error refuses to start, so the agent never looks at a page that silently shows something wrong.
36
+
37
+ 2. **Give the agent the contract.** `npx pine2profit --help` prints it with JSON examples; paste the output into the agent's system prompt or `CLAUDE.md`, together with the question it has to answer for every script and the rule for writing the report. The agent needs to know four things:
38
+
39
+ - every script is an `id` (`[a-z0-9-]+`) and up to three files `data/<id>_messages.json`, `data/<id>_candles.json`, `data/<id>_pinescript.json`;
40
+ - one line per script is appended to the last `data/index_N.jsonl`; a later line with the same `id` replaces the earlier one, so an update is an append, never a rewrite;
41
+ - the report is markdown in `messages`; every claim about the chart carries a reference (`[[t:โ€ฆ]]`, `[[range:โ€ฆ]]`, `[[trade:N]]`) so the reader can click and see the bars;
42
+ - `head` in `_messages.json` repeats the index line.
43
+
44
+ 3. **Run the loop.** Each iteration: pick a script, run the backtest / paper check, write or update the three files, append the index line, run `npx pine2profit ./project --check` and fix what it reports. The agent can open http://localhost:60050/run/?id=<id> itself (or screenshot it) to check that the page renders what it wrote. Nothing has to be restarted.
45
+
46
+ 4. **Publish.** Commit `data/` next to the site build and push: GitHub Pages serves the same relative paths as the local server, so what the agent checked locally is what goes live.
47
+
48
+ For a long-running loop keep `index_N.jsonl` chunks around 1000 lines and start `index_{N+1}` when the last one is full; the site reads them in order and stops at the first missing file.
49
+
50
+ ## CLI
51
+
52
+ ```bash
53
+ npx pine2profit .
54
+ npx pine2profit ./project --port 8080
55
+ npx pine2profit /var/agent/project --host 127.0.0.1 --port 60050
56
+ npx pine2profit ./project --check # validate only, no server
57
+ npx pine2profit --help # the data contract with JSON examples
58
+ ```
59
+
60
+ | flag | default | |
61
+ |---|---|---|
62
+ | `--port <number>` | `CC_WWWROOT_PORT` or `60050` | HTTP port |
63
+ | `--host <string>` | `CC_WWWROOT_HOST` or `0.0.0.0` | bind address |
64
+ | `--check` | | validate `<dir>/data` and exit (0 = no errors, 1 = errors) without starting the server |
65
+ | `--help`, `--version` | | |
66
+
67
+ The server answers two things and nothing else โ€” no API, no POST:
68
+
69
+ - `GET /` โ€” the dashboard
70
+ - `GET /data/<file>` โ€” `<dir>/data/<file>` as is, `Cache-Control: no-store`, 404 when the file is missing
71
+
72
+ ### Startup check
73
+
74
+ Before listening, `<dir>/data` is validated against the contract below; `--check` runs the same validation on its own and exits, which is what the agent should call after every write. A single error refuses to start with exit code 1 and the list of problems (`file:line` for the index, `file path` inside JSON documents, at most 50 shown); warnings are printed and the server starts anyway.
75
+
76
+ | checked | error |
77
+ |---|---|
78
+ | `data/` exists, `index_1.jsonl` exists (an empty file is fine), index files are numbered without gaps | |
79
+ | every index line is JSON with the fields below | required field missing, wrong type or value, unknown field (a typo such as `tv_url` is reported with the right name) |
80
+ | every script in the index has `<id>_messages.json` and `<id>_candles.json` | missing file, invalid JSON |
81
+ | `<id>_messages.json` | `head` differs from the index line, bad `groups` or `messages` shape, a chart reference that points at nothing (`[[trade:99]]` without that trade, a range that ends before it starts, a date that does not parse) |
82
+ | `<id>_candles.json` | empty or non-numeric `bars`, time not growing, `high` below `low`, duplicate trade ids |
83
+ | `<id>_pinescript.json` (optional) | invalid JSON, `source` missing |
84
+ | warnings only | files for ids that are not in the index, files the site never reads, a missing `head` |
85
+
86
+ ## The data folder
87
+
88
+ Everything lives flat in `<dir>/data/`, no subfolders. `<id>` is a slug matching `[a-z0-9-]+` and prefixes every file of that script.
89
+
90
+ ```
91
+ data/
92
+ index_1.jsonl the list, ~1000 lines per file; index_2.jsonl, โ€ฆ continue it
93
+ sma-cross-20-50_messages.json the report text for one script
94
+ sma-cross-20-50_candles.json bars, trades and equity for the chart
95
+ sma-cross-20-50_pinescript.json the author's script and the trade rule (optional)
96
+ ```
97
+
98
+ Dollars are integers on a notional $10,000 account. Leave a field out when it is null.
99
+
100
+ ### `index_N.jsonl` โ€” the list
101
+
102
+ One JSON object per line, one script per object. The site reads `index_1`, then `index_2`, โ€ฆ and stops at the first 404. **A later line with the same `id` replaces the earlier one**, so append updates to the last file instead of rewriting old ones.
103
+
104
+ Required: `id`, `title`, `kind`, `verdict`, `updated`.
105
+
106
+ ```json
107
+ {"id":"sma-cross-20-50","title":"SMA Cross 20/50","kind":"strategy","subcategory":"trend-following","verdict":"NO","main":-2465,"paper":461,"paperTrades":3,"expected":[-599,181],"iterations":3,"updated":"2026-11-26","market":"BTCUSDT","timeframe":"1h","license":"MPL-2.0","author":"example_author","tvUrl":"https://www.tradingview.com/script/EXAMPLE02/","cycleStart":"2026-11-12","percentile":59,"reason":"12 months โˆ’$2,465; only 4/10 markets positive; not better than random entries (59th percentile)"}
108
+ ```
109
+
110
+ | field | type | meaning |
111
+ |---|---|---|
112
+ | `id` | string | slug, prefix of the script's other files |
113
+ | `title` | string | |
114
+ | `kind` | `indicator` \| `strategy` | |
115
+ | `subcategory` | string | any key โ€” the list builds its filter chips from the values it sees. Keys with a label on the site: indicators `trend oscillator volatility volume structure signals`; strategies `trend-following mean-reversion breakout grid-dca pattern-event composite` |
116
+ | `usable` | boolean | `false` = no signal is final at bar close. The page says "not tradeable" and shows no rule and no money numbers |
117
+ | `verdict` | `YES` \| `NO` \| `UNKNOWN` | |
118
+ | `main` | number | 12 months via alerts, $ |
119
+ | `paper`, `paperTrades` | number | paper journal since `cycleStart`: $ and trade count |
120
+ | `expected` | `[low, high]` | expected per month on $10,000 |
121
+ | `iterations` | number | default 1 |
122
+ | `updated` | `YYYY-MM-DD` | |
123
+ | `market`, `timeframe`, `license`, `author`, `tvUrl` | string | header chips and the author link |
124
+ | `cycleStart` | `YYYY-MM-DD` | drawn on the chart and on the P&L line |
125
+ | `percentile` | number | the rule's percentile against random entries |
126
+ | `reason` | string | one sentence under the verdict |
127
+
128
+ A script that is not tradeable:
129
+
130
+ ```json
131
+ {"id":"volume-pressure","title":"Volume Pressure Delta","kind":"indicator","subcategory":"volume","usable":false,"verdict":"NO","iterations":1,"updated":"2026-11-26","market":"BTCUSDT","timeframe":"1h","reason":"not tradeable: the signal depends on realtime tick data (varip)"}
132
+ ```
133
+
134
+ ### `<id>_messages.json` โ€” the report text
135
+
136
+ ```json
137
+ {
138
+ "head": {"id":"sma-cross-20-50","title":"SMA Cross 20/50","kind":"strategy","subcategory":"trend-following","verdict":"NO","main":-2465,"paper":461,"paperTrades":3,"expected":[-599,181],"iterations":3,"updated":"2026-11-26","market":"BTCUSDT","timeframe":"1h","license":"MPL-2.0","author":"example_author","tvUrl":"https://www.tradingview.com/script/EXAMPLE02/","cycleStart":"2026-11-12","percentile":59,"reason":"12 months โˆ’$2,465; only 4/10 markets positive; not better than random entries (59th percentile)"},
139
+ "groups": [
140
+ { "code": "A", "title": "What it is" },
141
+ { "code": "C", "title": "Money" },
142
+ { "code": "E", "title": "Iterations" }
143
+ ],
144
+ "messages": [
145
+ { "code": "A0", "title": "How to run it", "md": "Run it on **1h**. A typical trade: [[trade:1]]." },
146
+ { "code": "C2", "title": "The last 12 months", "md": "Window [[range:2025-11-12T00:00Z..2026-11-12T00:00Z]]: 97 trades, -$2,465." },
147
+ { "code": "E1", "title": "What happened since the previous iteration?", "md": "Three paper trades, +$461.", "iteration": 3, "date": "2026-11-26" },
148
+ { "code": "E1", "title": "What happened since the previous iteration?", "md": "First week on paper.", "iteration": 2, "date": "2026-11-19" }
149
+ ]
150
+ }
151
+ ```
152
+
153
+ - **`head`** repeats the index line with the same values, so a direct link to `/run/?id=<id>` renders the header without scanning the index.
154
+ - **`groups`** is the left navigation, in this order.
155
+ - **`messages`** render in file order; nothing is deduplicated โ€” put in the file what the page should show.
156
+
157
+ | message field | |
158
+ |---|---|
159
+ | `code` | optional; `A0`, `C7`, `E1`, `RISK2` โ€” shown on the block and in the navigation |
160
+ | `group` | optional; default: the leading letters of `code` (`A0` โ†’ `A`, `RISK2` โ†’ `RISK`) |
161
+ | `title` | |
162
+ | `md` | markdown |
163
+ | `iteration` | optional; consecutive messages with the same value form a dated section. Messages without it go under "Analysis" |
164
+ | `date` | optional; shown next to the section title |
165
+
166
+ A group that appears in messages but not in `groups` is shown with its code as the title; a group without messages is dropped. Inside a group the navigation items are the message codes, or the iteration numbers when every message of the group carries `iteration`. The site knows nothing about the letters โ€” any codes and titles work.
167
+
168
+ **Chart references** inside `md` become buttons that frame the chart:
169
+
170
+ ```
171
+ [[t:2026-11-12T14:00Z]] a bar
172
+ [[t:2026-11-12T14:00Z@41820]] a bar and a price
173
+ [[range:2026-11-01T00:00Z..2026-11-08T00:00Z]] a segment, both edges marked
174
+ [[trade:12]] a trade from <id>_candles.json
175
+ [see the breakout](ref:range:2026-11-01T00:00Z..2026-11-08T00:00Z) the same, as a link
176
+ ```
177
+
178
+ ### `<id>_candles.json` โ€” the chart
179
+
180
+ ```json
181
+ {
182
+ "timeframe": "1h",
183
+ "bars": [
184
+ { "time": 1732665600000, "open": 62000, "high": 62000, "low": 61498.5, "close": 61498.5, "volume": 377 },
185
+ { "time": 1732669200000, "open": 61498.5, "high": 61553.9, "low": 61201.0, "close": 61340.2, "volume": 412 }
186
+ ],
187
+ "trades": [
188
+ { "id": 1, "side": "long", "open_time": 1732928400000, "open_price": 61642.5, "close_time": 1732996800000, "close_price": 60510.8, "pnl_usd": -195.58 }
189
+ ],
190
+ "equity": [
191
+ { "time": 1732665600000, "backtest_usd": 0, "paper_usd": null },
192
+ { "time": 1732996800000, "backtest_usd": -195.58, "paper_usd": null }
193
+ ]
194
+ }
195
+ ```
196
+
197
+ | key | |
198
+ |---|---|
199
+ | `timeframe` | optional; falls back to the index line |
200
+ | `bars` | feed the chart; `time` in ms |
201
+ | `trades` | optional; label and frame `[[trade:N]]`. `close_time` / `close_price` are `null` while open |
202
+ | `equity` | optional; draws the P&L line โ€” no line without it |
203
+
204
+ No file at all: the page says "no candles for this script" and the text still renders.
205
+
206
+ ### `<id>_pinescript.json` โ€” optional
207
+
208
+ ```json
209
+ {
210
+ "source": "//@version=5\nindicator(\"EMA Ribbon\", overlay=true)\nplot(ta.ema(close, 20))\nplot(ta.ema(close, 50))",
211
+ "rule": "//@version=5\nstrategy(\"EMA Ribbon rule\", overlay=true, initial_capital=10000)\nif ta.crossover(ta.ema(close, 20), ta.ema(close, 50))\n strategy.entry(\"Long\", strategy.long)\nif ta.crossunder(ta.ema(close, 20), ta.ema(close, 50))\n strategy.close(\"Long\")"
212
+ }
213
+ ```
214
+
215
+ `source` is the author's script: shown read-only and run on the chart. `rule` is the trade rule as a Pine `strategy()`; its fills become the trade markers. No file โ†’ no code panel. No `rule` โ†’ the chart runs the author's script only.
216
+
217
+ ### A minimal data folder
218
+
219
+ ```
220
+ <dir>/data/index_1.jsonl
221
+ <dir>/data/sma-cross-20-50_messages.json
222
+ <dir>/data/sma-cross-20-50_candles.json
223
+ <dir>/data/sma-cross-20-50_pinescript.json
224
+ ```
225
+
226
+ ## Using the server from code
227
+
228
+ ```ts
229
+ import { serve, validate, setLogger, setConfig } from "pine2profit";
230
+
231
+ for await (const issue of validate("/path/to/project")) { // yields { level, file, line?, at?, message } as problems are found;
232
+ console.log(issue); // the folder is read one file at a time, whatever its size
233
+ }
234
+ const dispose = serve("0.0.0.0", 60050, "/path/to/project"); // serves /path/to/project/data; serve() itself does not validate
235
+ ```
236
+
237
+ The third argument wins over `CC_DATA_PATH`, which wins over `process.cwd()`.
238
+
239
+ | variable | default | |
240
+ |---|---|---|
241
+ | `CC_WWWROOT_HOST` | `0.0.0.0` | bind address |
242
+ | `CC_WWWROOT_PORT` | `60050` | port |
243
+ | `CC_DATA_PATH` | `process.cwd()` | folder that contains `data/` for `serve()` called without a path; the CLI always takes `<dir>` from the command line |
244
+ | `CC_WWWROOT_PATH` | bundled build | override of the static root |
package/build/.gitkeep ADDED
File without changes