@johngalt5/bsv-overlay 0.2.4 → 0.2.6
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/SKILL.md +19 -8
- package/index.ts +45 -6
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -78,15 +78,26 @@ overlay({
|
|
|
78
78
|
})
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
###
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
### Automatic Triggering
|
|
82
|
+
|
|
83
|
+
The background service monitors incoming requests. When a new service request arrives,
|
|
84
|
+
a cron job automatically wakes you with a notification. You should then:
|
|
85
|
+
|
|
86
|
+
1. Call `overlay({ action: "pending-requests" })` to see what needs handling
|
|
87
|
+
2. For each pending request, use your full capabilities to process it:
|
|
88
|
+
- **code-review**: Review the code with your analysis capabilities, check the PR on GitHub
|
|
89
|
+
- **web-research**: Use `web_search` to research the topic thoroughly
|
|
86
90
|
- **translate**: Translate using your language capabilities
|
|
87
|
-
- **
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
- **tell-joke**: Generate a genuinely funny joke
|
|
92
|
+
- **code-develop**: Generate code, implement the feature, open a PR
|
|
93
|
+
- **roulette**: Run the roulette game logic
|
|
94
|
+
- **memory-store**: Handle key-value storage operations
|
|
95
|
+
- **api-proxy**: Make the requested API call
|
|
96
|
+
3. Call `fulfill` with the result — include `requestId`, `recipientKey`, and `serviceId` from the pending request
|
|
97
|
+
4. The plugin sends the response back and marks it complete
|
|
98
|
+
|
|
99
|
+
### Important: Always fulfill promptly
|
|
100
|
+
Requesters are waiting and have already paid. Process requests as soon as you're notified.
|
|
90
101
|
|
|
91
102
|
### Service Request Processing
|
|
92
103
|
|
package/index.ts
CHANGED
|
@@ -147,12 +147,28 @@ function startBackgroundService(env, cliPath, logger) {
|
|
|
147
147
|
backgroundProcess = proc;
|
|
148
148
|
|
|
149
149
|
proc.stdout?.on('data', (data) => {
|
|
150
|
-
// Log incoming service fulfillments
|
|
151
150
|
const lines = data.toString().split('\n').filter(Boolean);
|
|
152
151
|
for (const line of lines) {
|
|
153
152
|
try {
|
|
154
153
|
const event = JSON.parse(line);
|
|
155
154
|
logger?.debug?.(`[bsv-overlay] ${event.event || event.type || 'message'}:`, JSON.stringify(event).slice(0, 200));
|
|
155
|
+
|
|
156
|
+
// Detect queued-for-agent events and write alert file
|
|
157
|
+
if (event.action === 'queued-for-agent' && event.serviceId) {
|
|
158
|
+
const alertDir = path.join(process.env.HOME || '', '.clawdbot', 'bsv-overlay');
|
|
159
|
+
const alertPath = path.join(alertDir, 'pending-alert.jsonl');
|
|
160
|
+
try {
|
|
161
|
+
fs.mkdirSync(alertDir, { recursive: true });
|
|
162
|
+
fs.appendFileSync(alertPath, JSON.stringify({
|
|
163
|
+
requestId: event.id,
|
|
164
|
+
serviceId: event.serviceId,
|
|
165
|
+
from: event.from,
|
|
166
|
+
satoshis: event.satoshisReceived,
|
|
167
|
+
ts: Date.now(),
|
|
168
|
+
}) + '\n');
|
|
169
|
+
logger?.info?.(`[bsv-overlay] ⚡ Incoming ${event.serviceId} request from ${event.from?.slice(0, 12)}... — queued for agent`);
|
|
170
|
+
} catch {}
|
|
171
|
+
}
|
|
156
172
|
} catch {}
|
|
157
173
|
}
|
|
158
174
|
});
|
|
@@ -472,21 +488,39 @@ export default function register(api) {
|
|
|
472
488
|
});
|
|
473
489
|
}, { commands: ["overlay"] });
|
|
474
490
|
|
|
475
|
-
// Auto-setup
|
|
491
|
+
// Auto-setup + auto-register on startup (best-effort, non-fatal, fire-and-forget)
|
|
476
492
|
(async () => {
|
|
477
493
|
try {
|
|
478
494
|
const config = pluginConfig;
|
|
479
495
|
const walletDir = config?.walletDir || path.join(process.env.HOME || '', '.clawdbot', 'bsv-wallet');
|
|
480
496
|
const identityFile = path.join(walletDir, 'wallet-identity.json');
|
|
497
|
+
const env = buildEnvironment(config || {});
|
|
498
|
+
const cliPath = path.join(__dirname, 'scripts', 'overlay-cli.mjs');
|
|
499
|
+
|
|
500
|
+
// Step 1: Create wallet if missing
|
|
481
501
|
if (!fs.existsSync(identityFile)) {
|
|
482
502
|
api.log?.info?.('[bsv-overlay] No wallet found — running auto-setup...');
|
|
483
|
-
const env = buildEnvironment(config || {});
|
|
484
|
-
const cliPath = path.join(__dirname, 'scripts', 'overlay-cli.mjs');
|
|
485
503
|
await execFileAsync('node', [cliPath, 'setup'], { env });
|
|
486
|
-
api.log?.info?.('[bsv-overlay] Wallet initialized.
|
|
504
|
+
api.log?.info?.('[bsv-overlay] Wallet initialized.');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Step 2: Auto-register if wallet exists, has balance, and not yet registered
|
|
508
|
+
const regPath = path.join(process.env.HOME || '', '.clawdbot', 'bsv-overlay', 'registration.json');
|
|
509
|
+
if (fs.existsSync(identityFile) && !fs.existsSync(regPath)) {
|
|
510
|
+
const balResult = await execFileAsync('node', [cliPath, 'balance'], { env });
|
|
511
|
+
const balOutput = parseCliOutput(balResult.stdout);
|
|
512
|
+
const balance = balOutput?.data?.walletBalance || 0;
|
|
513
|
+
if (balance >= 1000) {
|
|
514
|
+
api.log?.info?.('[bsv-overlay] Wallet funded but not registered — auto-registering...');
|
|
515
|
+
const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
|
|
516
|
+
const regOutput = parseCliOutput(regResult.stdout);
|
|
517
|
+
if (regOutput.success) {
|
|
518
|
+
api.log?.info?.('[bsv-overlay] Auto-registered on overlay network!');
|
|
519
|
+
}
|
|
520
|
+
}
|
|
487
521
|
}
|
|
488
522
|
} catch (err: any) {
|
|
489
|
-
api.log?.debug?.('[bsv-overlay] Auto-setup skipped:', err.message);
|
|
523
|
+
api.log?.debug?.('[bsv-overlay] Auto-setup/register skipped:', err.message);
|
|
490
524
|
}
|
|
491
525
|
})();
|
|
492
526
|
}
|
|
@@ -1009,6 +1043,11 @@ async function handlePendingRequests(env, cliPath) {
|
|
|
1009
1043
|
const result = await execFileAsync('node', [cliPath, 'service-queue'], { env });
|
|
1010
1044
|
const output = parseCliOutput(result.stdout);
|
|
1011
1045
|
if (!output.success) throw new Error(`Queue check failed: ${output.error}`);
|
|
1046
|
+
|
|
1047
|
+
// Clear the alert file since we're checking now
|
|
1048
|
+
const alertPath = path.join(process.env.HOME || '', '.clawdbot', 'bsv-overlay', 'pending-alert.jsonl');
|
|
1049
|
+
try { if (fs.existsSync(alertPath)) fs.unlinkSync(alertPath); } catch {}
|
|
1050
|
+
|
|
1012
1051
|
return output.data;
|
|
1013
1052
|
}
|
|
1014
1053
|
|