@blockrun/franklin 3.32.1 → 3.34.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.
- package/README.md +23 -2
- package/dist/agent/approvals.d.ts +47 -0
- package/dist/agent/approvals.js +66 -0
- package/dist/agent/commands.js +230 -7
- package/dist/agent/compact.js +1 -1
- package/dist/agent/context.js +1 -1
- package/dist/agent/input-queue.d.ts +26 -0
- package/dist/agent/input-queue.js +65 -0
- package/dist/agent/loop.js +198 -5
- package/dist/agent/optimize.js +1 -1
- package/dist/agent/streaming-executor.d.ts +4 -0
- package/dist/agent/streaming-executor.js +52 -0
- package/dist/agent/tokens.js +2 -0
- package/dist/agent/tool-guard.d.ts +7 -0
- package/dist/agent/tool-guard.js +21 -0
- package/dist/agent/types.d.ts +26 -0
- package/dist/audit/approvals.d.ts +20 -0
- package/dist/audit/approvals.js +21 -0
- package/dist/commands/init.js +1 -1
- package/dist/commands/models.d.ts +11 -0
- package/dist/commands/models.js +157 -37
- package/dist/commands/start.d.ts +10 -1
- package/dist/commands/start.js +53 -1
- package/dist/events/types.d.ts +38 -1
- package/dist/gateway-models.d.ts +14 -2
- package/dist/gateway-models.js +8 -0
- package/dist/goal/engine.d.ts +39 -0
- package/dist/goal/engine.js +182 -0
- package/dist/goal/prompts.d.ts +16 -0
- package/dist/goal/prompts.js +206 -0
- package/dist/goal/runtime.d.ts +20 -0
- package/dist/goal/runtime.js +110 -0
- package/dist/goal/store.d.ts +22 -0
- package/dist/goal/store.js +79 -0
- package/dist/goal/types.d.ts +63 -0
- package/dist/goal/types.js +26 -0
- package/dist/hooks/loader.d.ts +19 -0
- package/dist/hooks/loader.js +115 -0
- package/dist/hooks/runner.d.ts +31 -0
- package/dist/hooks/runner.js +147 -0
- package/dist/hooks/types.d.ts +64 -0
- package/dist/hooks/types.js +35 -0
- package/dist/index.js +5 -1
- package/dist/learnings/extractor.js +1 -1
- package/dist/memory/capture.d.ts +40 -0
- package/dist/memory/capture.js +95 -0
- package/dist/memory/dream.d.ts +24 -0
- package/dist/memory/dream.js +147 -0
- package/dist/memory/indexer.d.ts +29 -0
- package/dist/memory/indexer.js +144 -0
- package/dist/memory/store.d.ts +50 -0
- package/dist/memory/store.js +163 -0
- package/dist/monitors/registry.d.ts +42 -0
- package/dist/monitors/registry.js +104 -0
- package/dist/panel/html.js +299 -0
- package/dist/panel/server.js +41 -0
- package/dist/pricing.js +4 -1
- package/dist/router/index.js +15 -9
- package/dist/router/vision.js +5 -4
- package/dist/scheduler/service.d.ts +24 -0
- package/dist/scheduler/service.js +44 -0
- package/dist/scheduler/store.d.ts +26 -0
- package/dist/scheduler/store.js +116 -0
- package/dist/scheduler/types.d.ts +36 -0
- package/dist/scheduler/types.js +31 -0
- package/dist/serve/agent-host.d.ts +63 -0
- package/dist/serve/agent-host.js +270 -0
- package/dist/serve/server.js +131 -2
- package/dist/session/live-registry.d.ts +32 -0
- package/dist/session/live-registry.js +83 -0
- package/dist/session/search.d.ts +6 -0
- package/dist/session/search.js +3 -3
- package/dist/session/storage.d.ts +6 -0
- package/dist/session/storage.js +6 -0
- package/dist/tools/goal.d.ts +7 -0
- package/dist/tools/goal.js +29 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/memory.js +14 -4
- package/dist/tools/moa.js +1 -1
- package/dist/tools/monitor.d.ts +11 -0
- package/dist/tools/monitor.js +96 -0
- package/dist/tools/scheduler.d.ts +12 -0
- package/dist/tools/scheduler.js +79 -0
- package/dist/tools/spend-tools.d.ts +33 -0
- package/dist/tools/spend-tools.js +114 -0
- package/dist/tools/tool-categories.js +7 -0
- package/dist/tools/trade-plan.d.ts +11 -0
- package/dist/tools/trade-plan.js +137 -0
- package/dist/tools/trading-execute.js +24 -0
- package/dist/trading/trade-plan.d.ts +75 -0
- package/dist/trading/trade-plan.js +290 -0
- package/dist/ui/app.js +54 -9
- package/dist/ui/model-picker.d.ts +40 -0
- package/dist/ui/model-picker.js +135 -25
- package/package.json +2 -2
- package/dist/agent/media-router.d.ts +0 -98
- package/dist/agent/media-router.js +0 -328
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
<h3>The AI agent with a wallet.</h3>
|
|
11
11
|
|
|
12
12
|
<p>
|
|
13
|
-
Other agents
|
|
13
|
+
Other agents just talk. Franklin Agent holds your USDC <em>and puts it to work</em> —<br>
|
|
14
|
+
trading, research, and autonomous tasks with real budgets, real guardrails, real outcomes.<br>
|
|
14
15
|
One wallet. Every model. Every paid API. Pay only for outcomes — not subscriptions.
|
|
15
16
|
</p>
|
|
16
17
|
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
|
|
43
44
|
## The pitch in one paragraph
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
Franklin Agent is an **autonomous economic agent** — an AI that holds a USDC wallet and spends it to get real work done, with **trading as its flagship arena**. It buys live market data, proposes trade plans you approve before a cent moves, pursues long-running goals across sessions, keeps a wallet-bound trading journal, and picks the best model per task from 55+ providers. You state an outcome and set a budget. Franklin Agent decides what to call, what to pay for, and when to stop. Every paid action routes through the [x402](https://x402.org) micropayment protocol and settles against your own wallet. No subscriptions. No API keys. No account. The wallet is the identity.
|
|
46
47
|
|
|
47
48
|
Built by the [BlockRun](https://blockrun.ai) team. Apache-2.0. TypeScript. Ships as one npm package.
|
|
48
49
|
|
|
@@ -186,6 +187,26 @@ Franklin is **chat-first**. You do not wire a DAG, configure six API keys, or co
|
|
|
186
187
|
|
|
187
188
|
Live data from CoinGecko. RSI, MACD, Bollinger, and volatility computed locally. No API key needed.
|
|
188
189
|
|
|
190
|
+
### 🛡️ Trades only move on YOUR approval
|
|
191
|
+
|
|
192
|
+
Real-money trades (Jupiter, 0x, Polymarket) are hard-gated behind a **trade plan**: the agent proposes a structured plan — venue, asset, size, slippage, stop condition, rationale, total spend — and nothing executes until you approve it. Approved budgets draw down per trade and expire in 15 minutes. This holds in every permission mode, `--trust` included. Add your own guardrails as [lifecycle hooks](docs/examples/hooks/) — daily spend caps, token blacklists, spend ledgers — that veto actions before money moves.
|
|
193
|
+
|
|
194
|
+
### 🎯 Autonomous goals with adversarial verification
|
|
195
|
+
|
|
196
|
+
```text
|
|
197
|
+
> /goal research the top 3 x402-compatible data APIs and produce a comparison
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Franklin plans the objective, works it across turns on its own, and — when it claims completion — a panel of **adversarial reviewers audits the evidence and refutes anything unsupported**. Bounded by a turn cap, a verification-round cap, and your `--max-spend`. Esc pauses at any time. Pair with `/loop 1h check funding rates` (durable scheduler) and the `Monitor` tool (live feeds delivered at turn boundaries) for always-on market coverage.
|
|
201
|
+
|
|
202
|
+
### 🧠 A memory that follows your wallet
|
|
203
|
+
|
|
204
|
+
Every trade journals itself: thesis on open, P&L on close, written to a **wallet-keyed trading journal** (`~/.blockrun/memory/trading-*/`) that any session can recall — "what was my SOL thesis?" just works, from any directory. Session learnings capture with `/flush`, consolidate with `/dream`, and inject automatically at session start.
|
|
205
|
+
|
|
206
|
+
### 🕹️ Mission control for your fleet
|
|
207
|
+
|
|
208
|
+
`franklin serve` + `franklin panel` → the **Agents** tab: dispatch one agent per strategy or market, watch them stream live, reply to any of them, and approve their trade plans and permission requests — all from one browser page. Sessions started in a terminal show up too.
|
|
209
|
+
|
|
189
210
|
### 🎨 Image generation
|
|
190
211
|
|
|
191
212
|
```text
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval broker — request/response correlation for anything that needs an
|
|
3
|
+
* explicit human decision: trade plans, remote permission prompts, ask-user
|
|
4
|
+
* questions surfaced to a dashboard.
|
|
5
|
+
*
|
|
6
|
+
* The requester parks on a Promise; whoever holds the other end (TUI prompt,
|
|
7
|
+
* panel client over WebSocket, headless auto-policy) resolves it by id. One
|
|
8
|
+
* broker per session.
|
|
9
|
+
*/
|
|
10
|
+
export interface ApprovalRequest {
|
|
11
|
+
requestId: string;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
kind: 'trade-plan' | 'tool-permission' | 'ask-user';
|
|
14
|
+
/** Short human-readable headline. */
|
|
15
|
+
title: string;
|
|
16
|
+
/** Full body — markdown-ish text rendered by the answering surface. */
|
|
17
|
+
description: string;
|
|
18
|
+
/** Answer choices. Free-text replies map to `message` on the decision. */
|
|
19
|
+
options: string[];
|
|
20
|
+
createdAt: number;
|
|
21
|
+
/** Undefined = wait indefinitely (interactive). */
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
/** Kind-specific payload (e.g. the TradePlan object). */
|
|
24
|
+
payload?: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface ApprovalDecision {
|
|
27
|
+
/** One of request.options, or 'timeout'. */
|
|
28
|
+
choice: string;
|
|
29
|
+
/** Free-text detail (e.g. requested changes). */
|
|
30
|
+
message?: string;
|
|
31
|
+
}
|
|
32
|
+
/** What a requester supplies — the broker (or harness) stamps id + createdAt. */
|
|
33
|
+
export type ApprovalRequestInput = Omit<ApprovalRequest, 'requestId' | 'createdAt'> & {
|
|
34
|
+
requestId?: string;
|
|
35
|
+
createdAt?: number;
|
|
36
|
+
};
|
|
37
|
+
export type ApprovalPromptFn = (req: ApprovalRequestInput) => Promise<ApprovalDecision>;
|
|
38
|
+
export declare class ApprovalBroker {
|
|
39
|
+
private pendingMap;
|
|
40
|
+
private listeners;
|
|
41
|
+
request(req: Omit<ApprovalRequest, 'requestId' | 'createdAt'>): Promise<ApprovalDecision>;
|
|
42
|
+
respond(requestId: string, decision: ApprovalDecision): boolean;
|
|
43
|
+
pending(): ApprovalRequest[];
|
|
44
|
+
onRequest(listener: (req: ApprovalRequest) => void): () => void;
|
|
45
|
+
/** Resolve everything as cancelled — session teardown. */
|
|
46
|
+
cancelAll(reason?: string): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval broker — request/response correlation for anything that needs an
|
|
3
|
+
* explicit human decision: trade plans, remote permission prompts, ask-user
|
|
4
|
+
* questions surfaced to a dashboard.
|
|
5
|
+
*
|
|
6
|
+
* The requester parks on a Promise; whoever holds the other end (TUI prompt,
|
|
7
|
+
* panel client over WebSocket, headless auto-policy) resolves it by id. One
|
|
8
|
+
* broker per session.
|
|
9
|
+
*/
|
|
10
|
+
import crypto from 'node:crypto';
|
|
11
|
+
export class ApprovalBroker {
|
|
12
|
+
pendingMap = new Map();
|
|
13
|
+
listeners = new Set();
|
|
14
|
+
request(req) {
|
|
15
|
+
const request = {
|
|
16
|
+
...req,
|
|
17
|
+
requestId: crypto.randomBytes(8).toString('hex'),
|
|
18
|
+
createdAt: Date.now(),
|
|
19
|
+
};
|
|
20
|
+
return new Promise(resolve => {
|
|
21
|
+
const entry = { request, resolve };
|
|
22
|
+
if (request.timeoutMs && request.timeoutMs > 0) {
|
|
23
|
+
entry.timer = setTimeout(() => {
|
|
24
|
+
this.pendingMap.delete(request.requestId);
|
|
25
|
+
resolve({ choice: 'timeout' });
|
|
26
|
+
}, request.timeoutMs);
|
|
27
|
+
entry.timer.unref?.();
|
|
28
|
+
}
|
|
29
|
+
this.pendingMap.set(request.requestId, entry);
|
|
30
|
+
for (const listener of this.listeners) {
|
|
31
|
+
try {
|
|
32
|
+
listener(request);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* listener errors must not break the request */
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
respond(requestId, decision) {
|
|
41
|
+
const entry = this.pendingMap.get(requestId);
|
|
42
|
+
if (!entry)
|
|
43
|
+
return false;
|
|
44
|
+
this.pendingMap.delete(requestId);
|
|
45
|
+
if (entry.timer)
|
|
46
|
+
clearTimeout(entry.timer);
|
|
47
|
+
entry.resolve(decision);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
pending() {
|
|
51
|
+
return [...this.pendingMap.values()].map(e => e.request);
|
|
52
|
+
}
|
|
53
|
+
onRequest(listener) {
|
|
54
|
+
this.listeners.add(listener);
|
|
55
|
+
return () => this.listeners.delete(listener);
|
|
56
|
+
}
|
|
57
|
+
/** Resolve everything as cancelled — session teardown. */
|
|
58
|
+
cancelAll(reason = 'session ended') {
|
|
59
|
+
for (const entry of this.pendingMap.values()) {
|
|
60
|
+
if (entry.timer)
|
|
61
|
+
clearTimeout(entry.timer);
|
|
62
|
+
entry.resolve({ choice: 'deny', message: reason });
|
|
63
|
+
}
|
|
64
|
+
this.pendingMap.clear();
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/agent/commands.js
CHANGED
|
@@ -229,14 +229,15 @@ const DIRECT_COMMANDS = {
|
|
|
229
229
|
`\n`;
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
ctx.onEvent({ kind: 'text_delta', text: `**
|
|
233
|
-
` **
|
|
234
|
-
` **
|
|
235
|
-
` **
|
|
232
|
+
ctx.onEvent({ kind: 'text_delta', text: `**Franklin Commands**\n\n` +
|
|
233
|
+
` **Autonomy:** /goal <objective> (verified autonomous goals) · /loop <interval> <prompt> (durable scheduler) · /goal status|pause|resume|clear\n` +
|
|
234
|
+
` **Memory:** /remember <note> /flush /dream /brain /learnings\n` +
|
|
235
|
+
` **Market:** /market [keyword] · /market info <slug> · /market run <slug> <input>\n` +
|
|
236
236
|
` **Session:** /plan /ultraplan /execute /compact /retry /sessions /resume /session-search /context /tasks /history /transcript\n` +
|
|
237
237
|
` **Power:** /ultrathink [query] /ultraplan /noplan /moa [query] /dump\n` +
|
|
238
|
-
` **Info:** /model /auto /wallet /cost /tokens /
|
|
239
|
-
` **
|
|
238
|
+
` **Info:** /model /auto /wallet /cost /tokens /mcp /doctor /version /bug /help\n` +
|
|
239
|
+
` **Dev tools:** /commit /review /test /fix /debug /explain /search /find /refactor /doc\n` +
|
|
240
|
+
` **Git:** /push /pr /undo /status /diff /log /branch /stash /unstash\n` +
|
|
240
241
|
` **UI:** /clear /exit\n` +
|
|
241
242
|
skillsBlock +
|
|
242
243
|
(ultrathinkOn ? `\n Ultrathink: ON\n` : '')
|
|
@@ -636,6 +637,228 @@ export async function handleSlashCommand(input, ctx) {
|
|
|
636
637
|
emitDone(ctx);
|
|
637
638
|
return { handled: true };
|
|
638
639
|
}
|
|
640
|
+
// /goal — cross-turn autonomous objective. `/goal <objective>` plans and
|
|
641
|
+
// starts it; status / pause / resume / clear manage it.
|
|
642
|
+
if (input === '/goal' || input.startsWith('/goal ')) {
|
|
643
|
+
const arg = input.slice('/goal'.length).trim();
|
|
644
|
+
const { getActiveGoal, setActiveGoal, updateActiveGoal, createGoal, savePlan, loadPlan } = await import('../goal/store.js');
|
|
645
|
+
const { runPlanner, mineNextStep } = await import('../goal/engine.js');
|
|
646
|
+
const { goalMaxTurns } = await import('../goal/types.js');
|
|
647
|
+
const { updateSessionMeta } = await import('../session/storage.js');
|
|
648
|
+
const active = getActiveGoal();
|
|
649
|
+
if (!arg || arg === 'status') {
|
|
650
|
+
if (!active) {
|
|
651
|
+
ctx.onEvent({ kind: 'text_delta', text: 'No active goal.\nUsage: /goal <objective> · /goal status · /goal pause · /goal resume · /goal clear\n' });
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
const nextStep = mineNextStep(loadPlan(active.id));
|
|
655
|
+
ctx.onEvent({ kind: 'text_delta', text: `Goal ${active.id} (${active.kind}) — ${active.status}\n` +
|
|
656
|
+
` Objective: ${active.objective}\n` +
|
|
657
|
+
` Turns used: ${active.turnsUsed}/${goalMaxTurns()} · verification rounds: ${active.rounds.length}\n` +
|
|
658
|
+
` Spend: $${active.budget.spentUsd.toFixed(4)}${active.budget.maxUsd ? ` / $${active.budget.maxUsd.toFixed(2)}` : ''}\n` +
|
|
659
|
+
(active.verifierGaps.length ? ` Open gaps:\n${active.verifierGaps.map(g => ` - ${g}`).join('\n')}\n` : '') +
|
|
660
|
+
(active.blockedReason ? ` Blocked: ${active.blockedReason}\n` : '') +
|
|
661
|
+
(nextStep ? ` Next step: ${nextStep}\n` : '')
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
emitDone(ctx);
|
|
665
|
+
return { handled: true };
|
|
666
|
+
}
|
|
667
|
+
if (arg === 'pause') {
|
|
668
|
+
if (active && (active.status === 'active' || active.status === 'verifying')) {
|
|
669
|
+
updateActiveGoal({ status: 'paused', blockedReason: 'paused by user' });
|
|
670
|
+
ctx.onEvent({ kind: 'text_delta', text: `Goal ${active.id} paused. /goal resume to continue.\n` });
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
ctx.onEvent({ kind: 'text_delta', text: 'No running goal to pause.\n' });
|
|
674
|
+
}
|
|
675
|
+
emitDone(ctx);
|
|
676
|
+
return { handled: true };
|
|
677
|
+
}
|
|
678
|
+
if (arg === 'resume') {
|
|
679
|
+
if (active && (active.status === 'paused' || active.status === 'blocked')) {
|
|
680
|
+
updateActiveGoal({ status: 'active', blockedReason: undefined });
|
|
681
|
+
emitDone(ctx);
|
|
682
|
+
return { handled: false, rewritten: 'Resume working the active goal from where it stopped. Address open verification gaps first.' };
|
|
683
|
+
}
|
|
684
|
+
ctx.onEvent({ kind: 'text_delta', text: 'No paused/blocked goal to resume.\n' });
|
|
685
|
+
emitDone(ctx);
|
|
686
|
+
return { handled: true };
|
|
687
|
+
}
|
|
688
|
+
if (arg === 'clear') {
|
|
689
|
+
if (active) {
|
|
690
|
+
updateActiveGoal({ status: 'abandoned' });
|
|
691
|
+
setActiveGoal(null);
|
|
692
|
+
updateSessionMeta(ctx.sessionId, { goalId: '' });
|
|
693
|
+
ctx.onEvent({ kind: 'text_delta', text: `Goal ${active.id} abandoned.\n` });
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
ctx.onEvent({ kind: 'text_delta', text: 'No active goal.\n' });
|
|
697
|
+
}
|
|
698
|
+
emitDone(ctx);
|
|
699
|
+
return { handled: true };
|
|
700
|
+
}
|
|
701
|
+
if (active && active.status !== 'completed' && active.status !== 'abandoned') {
|
|
702
|
+
ctx.onEvent({ kind: 'text_delta', text: `A goal is already active (${active.id}: ${active.objective.slice(0, 60)}). ` +
|
|
703
|
+
'Finish it or /goal clear before starting a new one.\n' });
|
|
704
|
+
emitDone(ctx);
|
|
705
|
+
return { handled: true };
|
|
706
|
+
}
|
|
707
|
+
// New objective: plan it, arm it, kick off the first working turn.
|
|
708
|
+
ctx.onEvent({ kind: 'text_delta', text: '*[goal] planning…*\n' });
|
|
709
|
+
try {
|
|
710
|
+
const abortCtl = new AbortController();
|
|
711
|
+
const engineCtx = {
|
|
712
|
+
client: ctx.client,
|
|
713
|
+
model: ctx.config.model,
|
|
714
|
+
capabilities: ctx.config.capabilities,
|
|
715
|
+
workingDir: ctx.config.workingDir ?? process.cwd(),
|
|
716
|
+
signal: abortCtl.signal,
|
|
717
|
+
};
|
|
718
|
+
const { kind, planMd } = await runPlanner(engineCtx, arg);
|
|
719
|
+
if (!planMd || planMd.length < 50) {
|
|
720
|
+
ctx.onEvent({ kind: 'text_delta', text: 'Goal planning produced no usable plan — try rephrasing the objective.\n' });
|
|
721
|
+
emitDone(ctx);
|
|
722
|
+
return { handled: true };
|
|
723
|
+
}
|
|
724
|
+
const goal = createGoal({ objective: arg, kind, maxUsd: ctx.config.maxSpendUsd });
|
|
725
|
+
savePlan(goal.id, planMd);
|
|
726
|
+
setActiveGoal(goal);
|
|
727
|
+
updateSessionMeta(ctx.sessionId, { goalId: goal.id });
|
|
728
|
+
ctx.onEvent({ kind: 'text_delta', text: `Goal ${goal.id} armed (${kind}).\n\n${planMd}\n\n` +
|
|
729
|
+
'*The agent now works this goal autonomously across turns. Esc pauses; /goal status inspects; /goal clear abandons.*\n' });
|
|
730
|
+
return {
|
|
731
|
+
handled: false,
|
|
732
|
+
rewritten: 'Begin working the active goal now: follow the goal plan in your context, starting with the first checklist item.',
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
catch (err) {
|
|
736
|
+
ctx.onEvent({ kind: 'text_delta', text: `Goal planning failed: ${err.message}\n` });
|
|
737
|
+
emitDone(ctx);
|
|
738
|
+
return { handled: true };
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
// /remember <note> — append a note to the workspace's curated memory.
|
|
742
|
+
if (input === '/remember' || input.startsWith('/remember ')) {
|
|
743
|
+
const note = input.slice('/remember'.length).trim();
|
|
744
|
+
if (!note) {
|
|
745
|
+
ctx.onEvent({ kind: 'text_delta', text: 'Usage: /remember <note> — saved to this workspace\'s MEMORY.md\n' });
|
|
746
|
+
emitDone(ctx);
|
|
747
|
+
return { handled: true };
|
|
748
|
+
}
|
|
749
|
+
const { appendUnderHeading, workspaceMemoryPath, memoryEnabled } = await import('../memory/store.js');
|
|
750
|
+
if (!memoryEnabled()) {
|
|
751
|
+
ctx.onEvent({ kind: 'text_delta', text: 'Memory is disabled (FRANKLIN_MEMORY=0).\n' });
|
|
752
|
+
emitDone(ctx);
|
|
753
|
+
return { handled: true };
|
|
754
|
+
}
|
|
755
|
+
const target = workspaceMemoryPath(ctx.config.workingDir ?? process.cwd());
|
|
756
|
+
appendUnderHeading(target, 'Notes', note);
|
|
757
|
+
ctx.onEvent({ kind: 'text_delta', text: `Memory saved to ${target}\n` });
|
|
758
|
+
emitDone(ctx);
|
|
759
|
+
return { handled: true };
|
|
760
|
+
}
|
|
761
|
+
// /flush — LLM capture of this session's durable learnings into a session log.
|
|
762
|
+
if (input === '/flush') {
|
|
763
|
+
const { flushSessionMemory } = await import('../memory/capture.js');
|
|
764
|
+
ctx.onEvent({ kind: 'text_delta', text: '*[memory] capturing durable learnings…*\n' });
|
|
765
|
+
try {
|
|
766
|
+
const written = await flushSessionMemory({
|
|
767
|
+
client: ctx.client,
|
|
768
|
+
model: ctx.config.model,
|
|
769
|
+
workDir: ctx.config.workingDir ?? process.cwd(),
|
|
770
|
+
sessionId: ctx.sessionId,
|
|
771
|
+
history: ctx.history,
|
|
772
|
+
});
|
|
773
|
+
ctx.onEvent({ kind: 'text_delta', text: written
|
|
774
|
+
? `Session learnings flushed to ${written}\n`
|
|
775
|
+
: 'Nothing durable to capture from this session.\n' });
|
|
776
|
+
}
|
|
777
|
+
catch (err) {
|
|
778
|
+
ctx.onEvent({ kind: 'text_delta', text: `Flush failed: ${err.message}\n` });
|
|
779
|
+
}
|
|
780
|
+
emitDone(ctx);
|
|
781
|
+
return { handled: true };
|
|
782
|
+
}
|
|
783
|
+
// /dream — consolidate accumulated session logs into curated MEMORY.md.
|
|
784
|
+
if (input === '/dream') {
|
|
785
|
+
const { runDream } = await import('../memory/dream.js');
|
|
786
|
+
ctx.onEvent({ kind: 'text_delta', text: '*[memory] consolidating…*\n' });
|
|
787
|
+
try {
|
|
788
|
+
const result = await runDream({
|
|
789
|
+
client: ctx.client,
|
|
790
|
+
model: ctx.config.model,
|
|
791
|
+
workDir: ctx.config.workingDir ?? process.cwd(),
|
|
792
|
+
force: true,
|
|
793
|
+
});
|
|
794
|
+
ctx.onEvent({ kind: 'text_delta', text: result.consolidated
|
|
795
|
+
? `Consolidated ${result.logsConsumed} session log(s) into curated memory.\n`
|
|
796
|
+
: `Nothing consolidated: ${result.reason}\n` });
|
|
797
|
+
}
|
|
798
|
+
catch (err) {
|
|
799
|
+
ctx.onEvent({ kind: 'text_delta', text: `Dream failed: ${err.message}\n` });
|
|
800
|
+
}
|
|
801
|
+
emitDone(ctx);
|
|
802
|
+
return { handled: true };
|
|
803
|
+
}
|
|
804
|
+
// /loop — durable recurring prompts. `/loop 5m check BTC price`,
|
|
805
|
+
// `/loop list`, `/loop cancel <id>`. Fires immediately, then repeats.
|
|
806
|
+
if (input === '/loop' || input.startsWith('/loop ')) {
|
|
807
|
+
const arg = input.slice('/loop'.length).trim();
|
|
808
|
+
const { createScheduledTask, deleteScheduledTask, listScheduledTasks } = await import('../scheduler/store.js');
|
|
809
|
+
const { parseInterval, formatInterval, MIN_INTERVAL_SEC } = await import('../scheduler/types.js');
|
|
810
|
+
if (!arg || arg === 'list') {
|
|
811
|
+
const tasks = listScheduledTasks();
|
|
812
|
+
if (tasks.length === 0) {
|
|
813
|
+
ctx.onEvent({ kind: 'text_delta', text: 'No scheduled loops.\n' +
|
|
814
|
+
'Usage: /loop <interval> <prompt> (interval like 90s, 5m, 2h, 1d; min 60s)\n' +
|
|
815
|
+
' /loop list · /loop cancel <id>\n'
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
const lines = tasks.map(t => ` ${t.id} · every ${formatInterval(t.intervalSec)} · fired ${t.firedCount}× · next ${new Date(t.nextFireAt).toLocaleString()}\n ${t.prompt.slice(0, 100)}`);
|
|
820
|
+
ctx.onEvent({ kind: 'text_delta', text: `${tasks.length} scheduled loop(s):\n${lines.join('\n')}\n` });
|
|
821
|
+
}
|
|
822
|
+
emitDone(ctx);
|
|
823
|
+
return { handled: true };
|
|
824
|
+
}
|
|
825
|
+
if (arg.startsWith('cancel')) {
|
|
826
|
+
const id = arg.slice('cancel'.length).trim();
|
|
827
|
+
const removed = id ? deleteScheduledTask(id) : false;
|
|
828
|
+
ctx.onEvent({ kind: 'text_delta', text: removed
|
|
829
|
+
? `Cancelled loop ${id}.\n`
|
|
830
|
+
: `Usage: /loop cancel <id> — see /loop list for ids.\n`
|
|
831
|
+
});
|
|
832
|
+
emitDone(ctx);
|
|
833
|
+
return { handled: true };
|
|
834
|
+
}
|
|
835
|
+
const m = arg.match(/^(\S+)\s+([\s\S]+)$/);
|
|
836
|
+
const intervalSec = m ? parseInterval(m[1]) : null;
|
|
837
|
+
if (!m || intervalSec === null) {
|
|
838
|
+
ctx.onEvent({ kind: 'text_delta', text: `Usage: /loop <interval> <prompt> — interval like 90s, 5m, 2h, 1d (min ${MIN_INTERVAL_SEC}s).\n`
|
|
839
|
+
});
|
|
840
|
+
emitDone(ctx);
|
|
841
|
+
return { handled: true };
|
|
842
|
+
}
|
|
843
|
+
const created = createScheduledTask({
|
|
844
|
+
prompt: m[2].trim(),
|
|
845
|
+
intervalSec,
|
|
846
|
+
sessionId: ctx.sessionId,
|
|
847
|
+
recurring: true,
|
|
848
|
+
durable: true,
|
|
849
|
+
fireImmediately: true,
|
|
850
|
+
});
|
|
851
|
+
if ('error' in created) {
|
|
852
|
+
ctx.onEvent({ kind: 'text_delta', text: `Could not schedule: ${created.error}\n` });
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
ctx.onEvent({ kind: 'text_delta', text: `Loop ${created.id} scheduled: every ${formatInterval(created.intervalSec)}, firing now and expiring ` +
|
|
856
|
+
`${new Date(created.expiresAt).toLocaleDateString()}. Cancel with /loop cancel ${created.id}.\n`
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
emitDone(ctx);
|
|
860
|
+
return { handled: true };
|
|
861
|
+
}
|
|
639
862
|
// /market [keyword | info <slug> | run <slug> <input>] — browse + hire paid
|
|
640
863
|
// skills from the BlockRun agent marketplace (business.blockrun.ai). Browsing
|
|
641
864
|
// and search are free GETs; `run` pays ONE standard x402 from the wallet.
|
|
@@ -1121,7 +1344,7 @@ export async function handleSlashCommand(input, ctx) {
|
|
|
1121
1344
|
...Object.keys(REWRITE_COMMANDS),
|
|
1122
1345
|
...ARG_COMMANDS.map(c => c.prefix.trim()),
|
|
1123
1346
|
...skillNames,
|
|
1124
|
-
'/branch', '/resume', '/model', '/auto', '/wallet', '/cost', '/help', '/clear', '/retry', '/exit', '/session-search', '/ssearch', '/failures', '/market',
|
|
1347
|
+
'/branch', '/resume', '/model', '/auto', '/wallet', '/cost', '/help', '/clear', '/retry', '/exit', '/session-search', '/ssearch', '/failures', '/market', '/loop', '/goal', '/remember', '/flush', '/dream',
|
|
1125
1348
|
];
|
|
1126
1349
|
const cmd = input.split(/\s/)[0];
|
|
1127
1350
|
const close = allCommands.filter(c => {
|
package/dist/agent/compact.js
CHANGED
|
@@ -464,7 +464,7 @@ function pickCompactionModel(primaryModel) {
|
|
|
464
464
|
return 'anthropic/claude-sonnet-4.6';
|
|
465
465
|
}
|
|
466
466
|
if (primaryModel.includes('sonnet') || primaryModel.includes('gpt-5.4') || primaryModel.includes('gpt-5.5') || primaryModel.includes('gemini-2.5-pro')) {
|
|
467
|
-
return 'anthropic/claude-haiku-4.5
|
|
467
|
+
return 'anthropic/claude-haiku-4.5';
|
|
468
468
|
}
|
|
469
469
|
if (primaryModel.includes('haiku') || primaryModel.includes('mini') || primaryModel.includes('nano')) {
|
|
470
470
|
return 'google/gemini-2.5-flash'; // Cheapest capable model
|
package/dist/agent/context.js
CHANGED
|
@@ -242,7 +242,7 @@ You run on the BlockRun AI Gateway. When the user asks you to "test the BlockRun
|
|
|
242
242
|
- \`GET /.well-known/x402\` — x402 resource list with prices
|
|
243
243
|
|
|
244
244
|
**LLM (POST, x402-paid)**
|
|
245
|
-
- \`POST /v1/chat/completions\` — OpenAI-compatible. Body: \`{ model, messages, stream?, tools?, max_tokens?, temperature? }\`. \`model\` MUST come from \`GET /v1/models\` (real frontier examples on the gateway
|
|
245
|
+
- \`POST /v1/chat/completions\` — OpenAI-compatible. Body: \`{ model, messages, stream?, tools?, max_tokens?, temperature? }\`. \`model\` MUST come from \`GET /v1/models\` (real frontier examples on the gateway, verified live 2026-07-14: \`anthropic/claude-sonnet-5\`, \`anthropic/claude-opus-4.8\`, \`deepseek/deepseek-v4-pro\`, \`zai/glm-5.2\`, \`xai/grok-4.5\`, \`nvidia/qwen3-next-80b-a3b-instruct\` (free)). Do NOT invent versions like \`openai/gpt-5.1\` or \`xai/grok-5\` — those don't exist; the gateway 400s with the valid list in the error body, so when in doubt fetch \`GET /v1/models\` first.
|
|
246
246
|
- \`POST /v1/messages\` — Anthropic-compatible. Body: \`{ model, messages, max_tokens, system?, tools? }\`.
|
|
247
247
|
|
|
248
248
|
**Media (POST, x402-paid; GET to poll async jobs)**
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input multiplexer — merges harness-injected inputs (scheduler firings,
|
|
3
|
+
* goal continuations) with the driver's own input source.
|
|
4
|
+
*
|
|
5
|
+
* Injected inputs are delivered ONLY at turn boundaries: the agent loop
|
|
6
|
+
* calls getUserInput() between turns and queued items win the race there.
|
|
7
|
+
* Nothing is ever pushed mid-turn — turn structure, permission prompts,
|
|
8
|
+
* and prompt-cache behavior stay intact.
|
|
9
|
+
*
|
|
10
|
+
* The base input promise is held across calls: when the driver is parked
|
|
11
|
+
* waiting for the user (interactive TUI, idle) and a scheduled prompt
|
|
12
|
+
* arrives, the injected item is returned immediately while the pending
|
|
13
|
+
* user input keeps waiting and is delivered at the next boundary. The
|
|
14
|
+
* user's typing is never dropped.
|
|
15
|
+
*/
|
|
16
|
+
export interface InputMultiplexer {
|
|
17
|
+
/** Drop-in replacement for the driver's getUserInput. */
|
|
18
|
+
getUserInput: () => Promise<string | null>;
|
|
19
|
+
/** Queue a synthetic input for the next turn boundary. */
|
|
20
|
+
enqueue: (text: string, opts?: {
|
|
21
|
+
priority?: boolean;
|
|
22
|
+
}) => void;
|
|
23
|
+
/** Number of injected inputs currently waiting. */
|
|
24
|
+
pending: () => number;
|
|
25
|
+
}
|
|
26
|
+
export declare function createInputMultiplexer(base: () => Promise<string | null>): InputMultiplexer;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input multiplexer — merges harness-injected inputs (scheduler firings,
|
|
3
|
+
* goal continuations) with the driver's own input source.
|
|
4
|
+
*
|
|
5
|
+
* Injected inputs are delivered ONLY at turn boundaries: the agent loop
|
|
6
|
+
* calls getUserInput() between turns and queued items win the race there.
|
|
7
|
+
* Nothing is ever pushed mid-turn — turn structure, permission prompts,
|
|
8
|
+
* and prompt-cache behavior stay intact.
|
|
9
|
+
*
|
|
10
|
+
* The base input promise is held across calls: when the driver is parked
|
|
11
|
+
* waiting for the user (interactive TUI, idle) and a scheduled prompt
|
|
12
|
+
* arrives, the injected item is returned immediately while the pending
|
|
13
|
+
* user input keeps waiting and is delivered at the next boundary. The
|
|
14
|
+
* user's typing is never dropped.
|
|
15
|
+
*/
|
|
16
|
+
export function createInputMultiplexer(base) {
|
|
17
|
+
const queue = [];
|
|
18
|
+
let pendingBase = null;
|
|
19
|
+
let baseDone = false;
|
|
20
|
+
// The loop is a single consumer — at most one getUserInput() outstanding,
|
|
21
|
+
// so one notifier slot suffices.
|
|
22
|
+
let queueNotify = null;
|
|
23
|
+
return {
|
|
24
|
+
getUserInput: async () => {
|
|
25
|
+
while (true) {
|
|
26
|
+
if (queue.length > 0)
|
|
27
|
+
return queue.shift();
|
|
28
|
+
if (baseDone)
|
|
29
|
+
return null;
|
|
30
|
+
if (!pendingBase)
|
|
31
|
+
pendingBase = base();
|
|
32
|
+
const arrival = new Promise(resolve => {
|
|
33
|
+
queueNotify = () => resolve('queued');
|
|
34
|
+
});
|
|
35
|
+
const raced = await Promise.race([
|
|
36
|
+
pendingBase.then(v => ({ base: v })),
|
|
37
|
+
arrival,
|
|
38
|
+
]);
|
|
39
|
+
queueNotify = null;
|
|
40
|
+
if (raced === 'queued')
|
|
41
|
+
continue; // loop re-checks the queue
|
|
42
|
+
pendingBase = null;
|
|
43
|
+
if (raced.base === null) {
|
|
44
|
+
baseDone = true;
|
|
45
|
+
// Base exhausted (EOF/quit) — flush late-queued items first.
|
|
46
|
+
if (queue.length > 0)
|
|
47
|
+
return queue.shift();
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return raced.base;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
enqueue: (text, opts) => {
|
|
54
|
+
const trimmed = text.trim();
|
|
55
|
+
if (!trimmed)
|
|
56
|
+
return;
|
|
57
|
+
if (opts?.priority)
|
|
58
|
+
queue.unshift(trimmed);
|
|
59
|
+
else
|
|
60
|
+
queue.push(trimmed);
|
|
61
|
+
queueNotify?.();
|
|
62
|
+
},
|
|
63
|
+
pending: () => queue.length,
|
|
64
|
+
};
|
|
65
|
+
}
|