@spfunctions/cli 1.1.0 → 1.1.2
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.
- package/dist/commands/agent.js +54 -11
- package/package.json +9 -5
package/dist/commands/agent.js
CHANGED
|
@@ -571,17 +571,60 @@ async function agentCommand(thesisId, opts) {
|
|
|
571
571
|
},
|
|
572
572
|
},
|
|
573
573
|
];
|
|
574
|
-
// ── System prompt
|
|
575
|
-
|
|
574
|
+
// ── System prompt builder ──────────────────────────────────────────────────
|
|
575
|
+
function buildSystemPrompt(ctx) {
|
|
576
|
+
const edgesSummary = ctx.edges
|
|
577
|
+
?.sort((a, b) => Math.abs(b.edge) - Math.abs(a.edge))
|
|
578
|
+
.slice(0, 5)
|
|
579
|
+
.map((e) => ` ${(e.market || '').slice(0, 40)} | ${e.venue || 'kalshi'} | mkt ${e.marketPrice}\u00A2 \u2192 thesis ${e.thesisPrice}\u00A2 | edge ${e.edge > 0 ? '+' : ''}${e.edge} | ${e.orderbook?.liquidityScore || '?'}`)
|
|
580
|
+
.join('\n') || ' (no edge data)';
|
|
581
|
+
const nodesSummary = ctx.causalTree?.nodes
|
|
582
|
+
?.filter((n) => n.depth === 0)
|
|
583
|
+
.map((n) => ` ${n.id} ${(n.label || '').slice(0, 40)} \u2014 ${Math.round(n.probability * 100)}%`)
|
|
584
|
+
.join('\n') || ' (no causal tree)';
|
|
585
|
+
const conf = typeof ctx.confidence === 'number'
|
|
586
|
+
? Math.round(ctx.confidence * 100)
|
|
587
|
+
: (typeof ctx.confidence === 'string' ? parseInt(ctx.confidence) : 0);
|
|
588
|
+
return `You are a prediction market trading assistant. Your job is not to please the user \u2014 it is to help them see reality clearly and make correct trading decisions.
|
|
576
589
|
|
|
577
|
-
|
|
578
|
-
Confidence: ${confidencePct}%
|
|
579
|
-
Status: ${latestContext.status}
|
|
580
|
-
Thesis ID: ${latestContext.thesisId || resolvedThesisId}
|
|
590
|
+
## Your analytical framework
|
|
581
591
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
592
|
+
Each thesis has a causal tree. Every node is a causal hypothesis with a probability. Nodes have causal relationships \u2014 when upstream nodes change, downstream nodes follow.
|
|
593
|
+
|
|
594
|
+
Edge = thesis-implied price - actual market price. Positive edge means the market underprices this event. Negative edge means overpriced. Contracts with large edges AND good liquidity are the most tradeable.
|
|
595
|
+
|
|
596
|
+
executableEdge is the real edge after subtracting the bid-ask spread. A contract with a big theoretical edge but wide spread may not be worth entering.
|
|
597
|
+
|
|
598
|
+
Short-term markets (weekly/monthly contracts) settle into hard data that calibrates the long-term thesis. Don't use them to bet (outcomes are nearly known) \u2014 use them to verify whether causal tree node probabilities are accurate.
|
|
599
|
+
|
|
600
|
+
## Your behavioral rules
|
|
601
|
+
|
|
602
|
+
- Think before calling tools. If the data is already in context, don't re-fetch.
|
|
603
|
+
- If the user asks about positions, check if Kalshi is configured first. If not, say so directly.
|
|
604
|
+
- If the user says "note this" or mentions a news event, inject a signal. Don't ask "should I note this?"
|
|
605
|
+
- If the user says "evaluate" or "run it", trigger immediately. Don't confirm.
|
|
606
|
+
- Don't end every response with "anything else?" \u2014 the user will ask when they want to.
|
|
607
|
+
- If you notice an edge narrowing or disappearing, say so proactively. Don't only report good news.
|
|
608
|
+
- If a causal tree node probability seriously contradicts the market price, point it out.
|
|
609
|
+
- Use Chinese if the user writes in Chinese, English if they write in English.
|
|
610
|
+
- Align tables. Be precise with numbers to the cent.
|
|
611
|
+
|
|
612
|
+
## Current thesis state
|
|
613
|
+
|
|
614
|
+
Thesis: ${ctx.thesis || ctx.rawThesis || 'N/A'}
|
|
615
|
+
ID: ${ctx.thesisId || resolvedThesisId}
|
|
616
|
+
Confidence: ${conf}%
|
|
617
|
+
Status: ${ctx.status}
|
|
618
|
+
|
|
619
|
+
Top-level causal tree nodes:
|
|
620
|
+
${nodesSummary}
|
|
621
|
+
|
|
622
|
+
Top 5 edges by magnitude:
|
|
623
|
+
${edgesSummary}
|
|
624
|
+
|
|
625
|
+
${ctx.lastEvaluation?.summary ? `Latest evaluation summary: ${ctx.lastEvaluation.summary.slice(0, 300)}` : ''}`;
|
|
626
|
+
}
|
|
627
|
+
const systemPrompt = buildSystemPrompt(latestContext);
|
|
585
628
|
// ── Create Agent ───────────────────────────────────────────────────────────
|
|
586
629
|
const agent = new Agent({
|
|
587
630
|
initialState: {
|
|
@@ -844,10 +887,10 @@ Do NOT make up data. Always call tools to get current state.`;
|
|
|
844
887
|
const newContext = await sfClient.getContext(newId);
|
|
845
888
|
resolvedThesisId = newContext.thesisId || newId;
|
|
846
889
|
latestContext = newContext;
|
|
847
|
-
// Build new system prompt
|
|
890
|
+
// Build new system prompt using the rich builder
|
|
891
|
+
const newSysPrompt = buildSystemPrompt(newContext);
|
|
848
892
|
const newConf = typeof newContext.confidence === 'number'
|
|
849
893
|
? Math.round(newContext.confidence * 100) : 0;
|
|
850
|
-
const newSysPrompt = `You are a SimpleFunctions prediction market trading assistant.\n\nCurrent thesis: ${newContext.thesis || newContext.rawThesis || 'N/A'}\nConfidence: ${newConf}%\nStatus: ${newContext.status}\nThesis ID: ${resolvedThesisId}\n\nYou have six tools available. Use them when you need real-time data. Answer directly when you don't.\nBe concise. Use Chinese if the user writes in Chinese, English if they write in English.\nDo NOT make up data. Always call tools to get current state.`;
|
|
851
894
|
// Load saved session or start fresh
|
|
852
895
|
const saved = loadSession(resolvedThesisId);
|
|
853
896
|
if (saved?.messages?.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spfunctions/cli",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "Prediction market intelligence CLI. Causal thesis model, 24/7 Kalshi/Polymarket scan, live orderbook, edge detection. Interactive agent mode with tool calling.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sf": "./dist/index.js"
|
|
7
7
|
},
|
|
@@ -26,11 +26,15 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"keywords": [
|
|
29
|
-
"prediction-
|
|
30
|
-
"thesis-agent",
|
|
29
|
+
"prediction-market",
|
|
31
30
|
"kalshi",
|
|
32
31
|
"polymarket",
|
|
33
|
-
"
|
|
32
|
+
"trading",
|
|
33
|
+
"cli",
|
|
34
|
+
"agent",
|
|
35
|
+
"orderbook",
|
|
36
|
+
"market-intelligence",
|
|
37
|
+
"edge-detection"
|
|
34
38
|
],
|
|
35
39
|
"license": "MIT",
|
|
36
40
|
"repository": {
|