@arp-protocol/cli 0.0.3 → 0.0.4

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.
@@ -64,7 +64,8 @@ function withMcpServer(config, name, entry) {
64
64
  var CLAUDE_HOOKS = {
65
65
  shape: "nested",
66
66
  events: [
67
- { name: "PostToolUse", matcher: "*" },
67
+ { name: "PostToolUse", matcher: "^(?!Skill$)" },
68
+ { name: "PostToolUse", matcher: "Skill", sync: true, timeout: 5 },
68
69
  { name: "PostToolUseFailure", matcher: "*", sync: true },
69
70
  { name: "PreToolUse", matcher: "Bash", sync: true, timeout: 15, if: "Bash(*skills*)" },
70
71
  { name: "Stop", sync: true, timeout: 10 }
@@ -356,8 +357,17 @@ function claudeMcpSteps(env, commands, project, remove, allowCli) {
356
357
  jsonStep(files.mcp, (config) => withMcpServer(config, SERVER_NAME, remove ? null : mcpEntry(commands.mcp, false)), remove ? "mcpServers.arp removed" : `mcpServers.arp → ${commands.mcp.command} ${commands.mcp.args.join(" ")}`, (config) => serversOf(config)[SERVER_NAME])
357
358
  ];
358
359
  }
360
+ function waitedLabel(event) {
361
+ if (event.sync !== true)
362
+ return "";
363
+ if (event.if !== undefined)
364
+ return " (waited on, Bash skills installs only)";
365
+ if (event.matcher !== undefined && event.matcher !== "*")
366
+ return ` (waited on, ${event.matcher} calls only)`;
367
+ return " (waited on)";
368
+ }
359
369
  function claudeHookStep(env, commands, project, remove) {
360
- return jsonStep(claudeFiles(env, project).settings, (settings) => withHooks(settings, CLAUDE_HOOKS, remove ? null : commands.hook, commands.hookFile), remove ? `hooks: arp removed from ${eventNames(CLAUDE_HOOKS).join(", ")}` : `hooks: arp on ${CLAUDE_HOOKS.events.map((event) => `${event.name}${event.sync !== true ? "" : event.if === undefined ? " (waited on)" : " (waited on, Bash skills installs only)"}`).join(", ")}`, (settings) => hooksOf(settings, CLAUDE_HOOKS, commands.hookFile));
370
+ return jsonStep(claudeFiles(env, project).settings, (settings) => withHooks(settings, CLAUDE_HOOKS, remove ? null : commands.hook, commands.hookFile), remove ? `hooks: arp removed from ${eventNames(CLAUDE_HOOKS).join(", ")}` : `hooks: arp on ${CLAUDE_HOOKS.events.map((event) => `${event.name}${waitedLabel(event)}`).join(", ")}`, (settings) => hooksOf(settings, CLAUDE_HOOKS, commands.hookFile));
361
371
  }
362
372
  var CLAUDE_HOOKS_SEEN_FROM = [2, 1, 316];
363
373
  function claudeVersionCheck(env) {
@@ -7,7 +7,8 @@ import {
7
7
  loopConfig,
8
8
  sponsorApproval,
9
9
  writeLine
10
- } from "./cli-10wacn76.js";
10
+ } from "./cli-8m56jsfx.js";
11
+ import"./cli-7c393v47.js";
11
12
  import"./cli-00qp1sj2.js";
12
13
  import"./cli-n4qagybd.js";
13
14
  import {
@@ -22,11 +23,13 @@ import {
22
23
  needShapeProblem,
23
24
  normaliseCategoryLabel,
24
25
  readDomainTree,
26
+ redactEndpointUrl,
25
27
  resolveDomain,
26
28
  transfersIn,
27
29
  x402NetworksFrom,
28
30
  x402Reading
29
- } from "./cli-wev0jgf7.js";
31
+ } from "./cli-wer26exb.js";
32
+ import"./cli-zehr6kdx.js";
30
33
  import"./cli-0gsbnq5w.js";
31
34
  import"./cli-fbwpcfvp.js";
32
35
  import"./cli-mhzh9z8k.js";
@@ -58,8 +61,22 @@ function lineFromArgs(args, env = process.env) {
58
61
  }
59
62
  if (args.paymentTx !== undefined && !/^0x[0-9a-fA-F]{64}$/.test(args.paymentTx))
60
63
  return new Error("--payment-tx is a 32-byte transaction hash");
61
- if (args.paymentTx !== undefined && !isExactEndpointUrl(args.toolUrl)) {
62
- return new Error("with --payment-tx, --tool is the exact URL you paid, scheme included, as you called it");
64
+ const terms = termsFromArgs(args);
65
+ if (terms instanceof Error)
66
+ return terms;
67
+ if (args.reason === "no-delivery" && args.paymentTx === undefined) {
68
+ return new Error("--reason no-delivery means paid, nothing received: it takes --payment-tx and --network");
69
+ }
70
+ let toolUrl = args.toolUrl;
71
+ if (args.paymentTx !== undefined) {
72
+ if (!isExactEndpointUrl(args.toolUrl)) {
73
+ return new Error("with --payment-tx, --tool is the exact URL you paid, scheme included, as you called it");
74
+ }
75
+ try {
76
+ toolUrl = redactEndpointUrl(args.toolUrl);
77
+ } catch (error) {
78
+ return error instanceof Error ? error : new Error(String(error));
79
+ }
63
80
  }
64
81
  if (args.parent !== undefined && args.domain === undefined)
65
82
  return new Error("--parent and --why add a --domain");
@@ -85,15 +102,42 @@ function lineFromArgs(args, env = process.env) {
85
102
  return new Error("--needs and --with name a skill's word; a paid endpoint has no SKILL.md");
86
103
  }
87
104
  return {
88
- toolUrl: args.toolUrl,
105
+ toolUrl,
89
106
  outcome: args.outcome,
90
107
  ...args.domain === undefined ? {} : { domain: args.domain },
91
108
  ...args.reason === undefined ? {} : { reason: args.reason },
92
109
  ...args.parent === undefined || args.why === undefined ? {} : { newDomain: { parent: args.parent, why: args.why.trim() } },
93
110
  ...args.paymentTx === undefined || args.network === undefined ? {} : { payment: { network: args.network, txHash: args.paymentTx.toLowerCase() } },
111
+ ...terms === null ? {} : { terms },
94
112
  ...need === undefined ? {} : { need }
95
113
  };
96
114
  }
115
+ var TERMS_FLAGS = ["--pay-to", "--asset", "--price", "--terms-at"];
116
+ function termsFromArgs(args) {
117
+ const given = [args.payTo, args.asset, args.price, args.termsAt];
118
+ if (args.paymentTx === undefined) {
119
+ return given.every((value) => value === undefined) ? null : new Error(`${TERMS_FLAGS.join(", ")} follow --payment-tx`);
120
+ }
121
+ if (given.some((value) => value === undefined)) {
122
+ return new Error(`with --payment-tx, name the terms the 402 gave and you paid against: ${TERMS_FLAGS.join(" ")}`);
123
+ }
124
+ const { payTo, asset, price, termsAt } = args;
125
+ if (!/^0x[0-9a-fA-F]{40}$/.test(payTo))
126
+ return new Error("--pay-to is the 402's payTo address");
127
+ if (!/^0x[0-9a-fA-F]{40}$/.test(asset))
128
+ return new Error("--asset is the 402's asset address");
129
+ if (!/^[1-9][0-9]{0,77}$/.test(price))
130
+ return new Error("--price is the 402's amount, a positive integer in the asset's smallest unit");
131
+ const receivedAt = /^[0-9]+$/.test(termsAt) ? Number(termsAt) : Math.floor(Date.parse(termsAt) / 1000);
132
+ if (!Number.isSafeInteger(receivedAt) || receivedAt <= 0)
133
+ return new Error("--terms-at is when the 402 was received: unix seconds or ISO 8601");
134
+ if (receivedAt > Math.floor(Date.now() / 1000) + 300)
135
+ return new Error("--terms-at is in the future");
136
+ return { payTo, asset, price, receivedAt };
137
+ }
138
+ function matchesTerms(payment, terms) {
139
+ return payment.transfers.some((transfer) => transfer.payTo.toLowerCase() === terms.payTo.toLowerCase() && transfer.asset.toLowerCase() === terms.asset.toLowerCase() && BigInt(transfer.amount) >= BigInt(terms.price));
140
+ }
97
141
  async function readLinePayment(input, reading) {
98
142
  if (input.payment === undefined)
99
143
  return null;
@@ -125,6 +169,11 @@ async function writeLineChecked(steps, input) {
125
169
  if (steps.payments === undefined)
126
170
  throw new Error("this build reads no payment network");
127
171
  payment = await readLinePayment(input, steps.payments);
172
+ if (input.terms === undefined)
173
+ throw new Error("a line with a payment names the terms it paid against");
174
+ if (payment !== null && !matchesTerms(payment, input.terms)) {
175
+ throw new Error(`no transfer in ${input.payment.txHash} pays ${input.terms.payTo} at least ${input.terms.price} of ${input.terms.asset}: check --pay-to, --asset and --price`);
176
+ }
128
177
  }
129
178
  if (input.domain !== undefined) {
130
179
  const domain = normaliseCategoryLabel(input.domain);
@@ -9,7 +9,8 @@ import {
9
9
  normaliseEndpoint,
10
10
  parseAgentRegistry,
11
11
  validateHandshakeRequest
12
- } from "./cli-wev0jgf7.js";
12
+ } from "./cli-wer26exb.js";
13
+ import"./cli-zehr6kdx.js";
13
14
  import"./cli-0gsbnq5w.js";
14
15
  import"./cli-fbwpcfvp.js";
15
16
  import {
@@ -18,7 +18,8 @@ import {
18
18
  normaliseEndpoint,
19
19
  parseEther,
20
20
  signHireReceipt
21
- } from "./cli-wev0jgf7.js";
21
+ } from "./cli-wer26exb.js";
22
+ import"./cli-zehr6kdx.js";
22
23
  import"./cli-0gsbnq5w.js";
23
24
  import {
24
25
  ERC8004_REGISTRY