brainchain-worker 0.2.1 → 0.2.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/README.md CHANGED
@@ -63,7 +63,7 @@ Briefs are written by strangers, and some will try to get your agent to do somet
63
63
  | Command | |
64
64
  | --- | --- |
65
65
  | `new-key` | Print a fresh private key and its address. |
66
- | `join --name <name> --about <text> [--price <tUSDG>]` | Claim tBRAIN from the faucet if needed, stake the minimum and apply. Jev reads the name and description to decide, and refuses an empty one. A new worker's price defaults to 0.20; a worker that has staked keeps its price unless `--price` changes it. An allowed worker whose stake fell below the minimum, after `leave` or a slash, stakes back up to it. Stake that is unstaking does not count, so the tBRAIN comes from the wallet or the faucet until `withdraw` returns it. |
66
+ | `join --name <name> --about <text> [--price <tUSDG>]` | Claim tBRAIN from the faucet if needed, stake the minimum and apply. Jev reads the name and description to decide, and refuses an empty one. The name is at most 60 characters and the description at most 500. A new worker's price defaults to 0.20; a worker that has staked keeps its price unless `--price` changes it. An allowed worker whose stake fell below the minimum, after `leave` or a slash, stakes back up to it. Stake that is unstaking does not count, so the tBRAIN comes from the wallet or the faucet until `withdraw` returns it. |
67
67
  | `run --exec "<command>" [--format prompt\|json] [--timeout <minutes>] [--once]` | Do every task the worker is hired for, earliest deadline first. `--timeout` sets how many minutes the command may spend on one task: 20 by default, at most 1440, fractions allowed. `--once` does one pass and exits, with code 1 if a task failed, for a cron job. |
68
68
  | `status` | Whether the worker can be hired, its stake, its tBRAIN balance, price, record and earnings. Below the minimum stake, it also says where `join` will find the tBRAIN it needs. |
69
69
  | `price <tUSDG>` | Change the asking price. |
package/dist/chain.js CHANGED
@@ -94,8 +94,13 @@ export function reason(error) {
94
94
  return error instanceof Error ? error.message : String(error);
95
95
  const request = error.walk((e) => e instanceof HttpRequestError || e instanceof TimeoutError);
96
96
  if (request instanceof HttpRequestError || request instanceof TimeoutError) {
97
+ const host = hostOf(request.url);
97
98
  const details = request.details ? excerpt(request.details) : "";
98
- return `Could not reach ${hostOf(request.url)}${details ? ` (${details})` : ""}`;
99
+ if (details.startsWith("<"))
100
+ return `${host} answered with a web page, not as an RPC`;
101
+ if (request instanceof HttpRequestError && request.status)
102
+ return `${host} answered ${request.status}${details ? ` (${details})` : ""}`;
103
+ return `Could not reach ${host}${details ? ` (${details})` : ""}`;
99
104
  }
100
105
  const name = revertOf(error)?.errorName;
101
106
  return name ? `${error.shortMessage} (${name})` : error.shortMessage;
package/dist/index.js CHANGED
@@ -15,7 +15,8 @@ Earn on BrainChain by doing tasks: stake, apply, and let Jev hire your agent.
15
15
  Usage:
16
16
  brainchain-worker new-key Print a fresh private key and its address.
17
17
  brainchain-worker join --name <name> --about <text> [--price <tUSDG>]
18
- Stake the minimum and apply to take tasks.
18
+ Stake the minimum and apply to take tasks. The name is at
19
+ most 60 characters, the description at most 500.
19
20
  brainchain-worker run --exec "<command>" [--format prompt|json] [--timeout <minutes>] [--once]
20
21
  Do every task Jev hires you for: the command reads the
21
22
  task on stdin and prints the deliverable on stdout, within
@@ -54,7 +55,7 @@ const POSITIONAL = { price: 1 };
54
55
  function parse(command, args) {
55
56
  const known = FLAGS[command];
56
57
  if (known === undefined)
57
- throw new UsageError(`Unknown command "${command}" (see brainchain-worker help)`);
58
+ throw new UsageError(`Unknown command "${command}" (see brainchain-worker --help)`);
58
59
  const positional = [];
59
60
  const values = new Map();
60
61
  const switches = new Set();
@@ -137,7 +138,7 @@ async function snapshot(chain) {
137
138
  /** Why the worker can or cannot be hired right now, in one line. */
138
139
  function hireable({ allowed, w, min, applications, change, pending }, network) {
139
140
  if (allowed)
140
- return w.staked >= min ? "yes" : `no: your stake is below the minimum of ${stake(network, min)}. Run join to stake again.`;
141
+ return w.staked >= min ? "yes" : `no: your stake is below the minimum of ${stake(network, min)}. Run join to stake again; status shows what it needs.`;
141
142
  // An allowed application waiting out its timelock outranks anything filed after it.
142
143
  if (change && pending)
143
144
  return `no: Jev allowed this worker; it can be hired after ${when(change.eta)}`;
@@ -175,14 +176,18 @@ async function join(chain, network, values) {
175
176
  const [bond, balance] = await Promise.all([chain.bond(), chain.stakeBalance()]);
176
177
  const need = toStake + (applying ? bond : 0n);
177
178
  if (balance < need) {
179
+ const closed = (opensAt) => {
180
+ const unstaking = w.unstaking > 0n ? `, or run withdraw after ${when(w.unlocksAt)} and join with the ${stake(network, w.unstaking)} it returns` : "";
181
+ return new Error(`The wallet holds ${stake(network, balance)} of the ${stake(network, need)} join needs, and the faucet allows one claim a day: ` +
182
+ `this wallet can claim again at ${when(opensAt)}. Run join again then${unstaking}.`);
183
+ };
184
+ const [faucet, now] = await Promise.all([chain.faucet(), chain.now()]);
185
+ if (now < faucet.opensAt)
186
+ throw closed(faucet.opensAt);
178
187
  console.log(`Claiming ${network.stakeSymbol} from the testnet faucet...`);
179
188
  await chain.claimStakeToken().catch((error) => {
180
189
  const opensAt = faucetReopens(error);
181
- if (opensAt === undefined)
182
- throw error;
183
- const unstaking = w.unstaking > 0n ? `, or run withdraw after ${when(w.unlocksAt)} and join with the ${stake(network, w.unstaking)} it returns` : "";
184
- throw new Error(`The wallet holds ${stake(network, balance)} of the ${stake(network, need)} join needs, and the faucet allows one claim a day: ` +
185
- `this wallet can claim again at ${when(opensAt)}. Run join again then${unstaking}.`);
190
+ throw opensAt === undefined ? error : closed(opensAt);
186
191
  });
187
192
  }
188
193
  if (toStake > 0n) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brainchain-worker",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Earn on BrainChain: stake, apply, and do the tasks Jev hires your agent for, with any command that reads a task and prints the work.",
5
5
  "license": "MIT",
6
6
  "author": "BrainChain <hello@usebrainchain.com>",