@fidacy/openclaw-plugin 0.5.1 → 0.5.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/index.js CHANGED
@@ -4229,9 +4229,109 @@ import { createHash as createHash2 } from "node:crypto";
4229
4229
 
4230
4230
  // src/evidence.ts
4231
4231
  import { createHash } from "node:crypto";
4232
- import { appendFileSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
4232
+ import { appendFileSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
4233
+ import { join as join2 } from "node:path";
4234
+
4235
+ // ../mcp/src/config.ts
4236
+ import { randomUUID } from "node:crypto";
4233
4237
  import { homedir } from "node:os";
4234
4238
  import { join } from "node:path";
4239
+ import {
4240
+ existsSync,
4241
+ mkdirSync,
4242
+ readFileSync,
4243
+ writeFileSync
4244
+ } from "node:fs";
4245
+ function hasEngineKey(keyOverride) {
4246
+ return Boolean((keyOverride ?? process.env.FIDACY_ENGINE_API_KEY ?? "").trim());
4247
+ }
4248
+ function configDir() {
4249
+ return process.env.FIDACY_CONFIG_DIR ?? join(homedir(), ".fidacy");
4250
+ }
4251
+ function configPath() {
4252
+ return join(configDir(), "config.json");
4253
+ }
4254
+ function auditLogPath() {
4255
+ if (process.env.FIDACY_AUDIT_PATH) return process.env.FIDACY_AUDIT_PATH;
4256
+ const dir = join(configDir(), "audit");
4257
+ try {
4258
+ mkdirSync(dir, { recursive: true, mode: 448 });
4259
+ } catch {
4260
+ }
4261
+ return join(dir, "audit.log");
4262
+ }
4263
+ function readConfig() {
4264
+ const p = configPath();
4265
+ if (!existsSync(p)) return null;
4266
+ try {
4267
+ const raw = JSON.parse(readFileSync(p, "utf8"));
4268
+ if (!raw || typeof raw.anon_id !== "string") return null;
4269
+ return {
4270
+ anon_id: raw.anon_id,
4271
+ tier: raw.tier === "paid" ? "paid" : "free",
4272
+ api_key: typeof raw.api_key === "string" ? raw.api_key : null,
4273
+ mandate: raw.mandate,
4274
+ // Install-state passthrough: dropping these on a read→write cycle would
4275
+ // reset every once-per-install nudge into an every-time nag.
4276
+ created_at: typeof raw.created_at === "string" ? raw.created_at : void 0,
4277
+ nudges: raw.nudges && typeof raw.nudges === "object" ? raw.nudges : void 0,
4278
+ decisions_count: typeof raw.decisions_count === "number" ? raw.decisions_count : void 0,
4279
+ hosted_lapsed_at: typeof raw.hosted_lapsed_at === "string" ? raw.hosted_lapsed_at : void 0,
4280
+ operator_email: typeof raw.operator_email === "string" ? raw.operator_email : void 0,
4281
+ registered_email: typeof raw.registered_email === "string" ? raw.registered_email : void 0
4282
+ };
4283
+ } catch {
4284
+ return null;
4285
+ }
4286
+ }
4287
+ function writeConfig(cfg) {
4288
+ const dir = configDir();
4289
+ mkdirSync(dir, { recursive: true, mode: 448 });
4290
+ writeFileSync(configPath(), JSON.stringify(cfg, null, 2), { mode: 384 });
4291
+ }
4292
+ function ensureState() {
4293
+ const existing = readConfig();
4294
+ if (existing) return { config: existing, firstRun: false };
4295
+ const config = {
4296
+ anon_id: randomUUID(),
4297
+ tier: "free",
4298
+ api_key: null,
4299
+ mandate: { payees: [], categories: ["*"], currency: "USD", perTxMax: 2500, maxTotal: 1e4 },
4300
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
4301
+ };
4302
+ try {
4303
+ writeConfig(config);
4304
+ } catch {
4305
+ }
4306
+ return { config, firstRun: true };
4307
+ }
4308
+ var DEMO_PAYEE = "fidacy:demo";
4309
+ function resolveMandateRules(cfg) {
4310
+ const m = cfg?.mandate ?? {};
4311
+ const envList = (v) => v === void 0 ? void 0 : v.split(",").map((s) => s.trim()).filter(Boolean);
4312
+ const envNum = (name, v) => {
4313
+ if (v === void 0 || v.trim() === "") return void 0;
4314
+ const n = Number(v);
4315
+ if (!Number.isFinite(n) || n <= 0) {
4316
+ console.error(
4317
+ `[fidacy] ${name}="${v}" is not a positive number, so it cannot be enforced as a cap. Ignoring it and using the safe default. Write digits only, with no thousands separator, currency symbol or unit (e.g. ${name}=2500).`
4318
+ );
4319
+ return void 0;
4320
+ }
4321
+ return n;
4322
+ };
4323
+ const fileNum = (v) => typeof v === "number" && Number.isFinite(v) && v > 0 ? v : void 0;
4324
+ const payees = envList(process.env.FIDACY_ALLOW_PAYEES) ?? m.payees ?? [];
4325
+ return {
4326
+ payees: payees.includes(DEMO_PAYEE) ? payees : [...payees, DEMO_PAYEE],
4327
+ categories: envList(process.env.FIDACY_ALLOW_CATEGORIES) ?? m.categories ?? ["*"],
4328
+ currency: process.env.FIDACY_CURRENCY ?? m.currency ?? "USD",
4329
+ perTxMax: envNum("FIDACY_PER_TX_MAX", process.env.FIDACY_PER_TX_MAX) ?? fileNum(m.perTxMax) ?? 2500,
4330
+ maxTotal: envNum("FIDACY_MAX_TOTAL", process.env.FIDACY_MAX_TOTAL) ?? fileNum(m.maxTotal) ?? 1e4
4331
+ };
4332
+ }
4333
+
4334
+ // src/evidence.ts
4235
4335
  var GENESIS = "fidacy.observer.v1";
4236
4336
  var sha256 = (s) => createHash("sha256").update(s).digest("hex");
4237
4337
  function canonical(obj) {
@@ -4245,14 +4345,14 @@ function genesisHead() {
4245
4345
  return sha256(GENESIS);
4246
4346
  }
4247
4347
  function fidacyDir() {
4248
- return join(process.env.FIDACY_HOME ?? join(homedir(), ".fidacy"), "sessions");
4348
+ return join2(configDir(), "sessions");
4249
4349
  }
4250
4350
  function writeSessionLog(sessionId, actions, head, meta) {
4251
4351
  try {
4252
4352
  const dir = fidacyDir();
4253
- mkdirSync(dir, { recursive: true, mode: 448 });
4353
+ mkdirSync2(dir, { recursive: true, mode: 448 });
4254
4354
  const safe = sessionId.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 80) || "session";
4255
- const path = join(dir, `${safe}.json`);
4355
+ const path = join2(dir, `${safe}.json`);
4256
4356
  const body = {
4257
4357
  v: "fidacy.observer.v1",
4258
4358
  recipe: 'h_0 = sha256("fidacy.observer.v1"); h_i = sha256(h_prev + "|" + sha256(canonical(action)))',
@@ -4261,7 +4361,7 @@ function writeSessionLog(sessionId, actions, head, meta) {
4261
4361
  ...meta,
4262
4362
  actions
4263
4363
  };
4264
- writeFileSync(path, JSON.stringify(body, null, 2), { mode: 384 });
4364
+ writeFileSync2(path, JSON.stringify(body, null, 2), { mode: 384 });
4265
4365
  return path;
4266
4366
  } catch {
4267
4367
  return null;
@@ -4270,8 +4370,8 @@ function writeSessionLog(sessionId, actions, head, meta) {
4270
4370
  function queuePending(head, sessionId, at, total = 0, byCategory = {}) {
4271
4371
  try {
4272
4372
  const dir = fidacyDir();
4273
- mkdirSync(dir, { recursive: true, mode: 448 });
4274
- appendFileSync(join(dir, "pending-anchors.jsonl"), JSON.stringify({ head, sessionId, at, total, byCategory }) + "\n", {
4373
+ mkdirSync2(dir, { recursive: true, mode: 448 });
4374
+ appendFileSync(join2(dir, "pending-anchors.jsonl"), JSON.stringify({ head, sessionId, at, total, byCategory }) + "\n", {
4275
4375
  mode: 384
4276
4376
  });
4277
4377
  } catch {
@@ -4279,15 +4379,15 @@ function queuePending(head, sessionId, at, total = 0, byCategory = {}) {
4279
4379
  }
4280
4380
  function takePending(limit = 50) {
4281
4381
  const dir = fidacyDir();
4282
- const path = join(dir, "pending-anchors.jsonl");
4283
- const taken = join(dir, "pending-anchors.taking");
4382
+ const path = join2(dir, "pending-anchors.jsonl");
4383
+ const taken = join2(dir, "pending-anchors.taking");
4284
4384
  try {
4285
4385
  renameSync(path, taken);
4286
4386
  } catch {
4287
4387
  return [];
4288
4388
  }
4289
4389
  try {
4290
- const lines = readFileSync(taken, "utf8").split("\n").filter(Boolean);
4390
+ const lines = readFileSync2(taken, "utf8").split("\n").filter(Boolean);
4291
4391
  const out = [];
4292
4392
  for (const line of lines.slice(-limit)) {
4293
4393
  try {
@@ -4301,7 +4401,7 @@ function takePending(limit = 50) {
4301
4401
  return [];
4302
4402
  } finally {
4303
4403
  try {
4304
- writeFileSync(taken, "");
4404
+ writeFileSync2(taken, "");
4305
4405
  } catch {
4306
4406
  }
4307
4407
  }
@@ -4586,7 +4686,7 @@ function sha2562(input) {
4586
4686
  import fs from "node:fs";
4587
4687
 
4588
4688
  // ../firewall/dist/core.js
4589
- import { randomUUID } from "node:crypto";
4689
+ import { randomUUID as randomUUID2 } from "node:crypto";
4590
4690
 
4591
4691
  // ../firewall/dist/evaluate.js
4592
4692
  function fold(s) {
@@ -4770,7 +4870,7 @@ var DevFidacyCore = class {
4770
4870
  return this.mandate;
4771
4871
  }
4772
4872
  async decide(req, subject) {
4773
- const decisionId = randomUUID();
4873
+ const decisionId = randomUUID2();
4774
4874
  const ts2 = (/* @__PURE__ */ new Date()).toISOString();
4775
4875
  const invalid = validateRequest(req);
4776
4876
  if (invalid) {
@@ -4966,107 +5066,8 @@ var FileAuditStore = class {
4966
5066
  // ../mcp/src/core.ts
4967
5067
  import { statSync } from "node:fs";
4968
5068
 
4969
- // ../mcp/src/config.ts
4970
- import { randomUUID as randomUUID2 } from "node:crypto";
4971
- import { homedir as homedir2 } from "node:os";
4972
- import { join as join2 } from "node:path";
4973
- import {
4974
- existsSync,
4975
- mkdirSync as mkdirSync2,
4976
- readFileSync as readFileSync2,
4977
- writeFileSync as writeFileSync2
4978
- } from "node:fs";
4979
- function hasEngineKey(keyOverride) {
4980
- return Boolean((keyOverride ?? process.env.FIDACY_ENGINE_API_KEY ?? "").trim());
4981
- }
4982
- function configDir() {
4983
- return process.env.FIDACY_CONFIG_DIR ?? join2(homedir2(), ".fidacy");
4984
- }
4985
- function configPath() {
4986
- return join2(configDir(), "config.json");
4987
- }
4988
- function auditLogPath() {
4989
- if (process.env.FIDACY_AUDIT_PATH) return process.env.FIDACY_AUDIT_PATH;
4990
- const dir = join2(configDir(), "audit");
4991
- try {
4992
- mkdirSync2(dir, { recursive: true, mode: 448 });
4993
- } catch {
4994
- }
4995
- return join2(dir, "audit.log");
4996
- }
4997
- function readConfig() {
4998
- const p = configPath();
4999
- if (!existsSync(p)) return null;
5000
- try {
5001
- const raw = JSON.parse(readFileSync2(p, "utf8"));
5002
- if (!raw || typeof raw.anon_id !== "string") return null;
5003
- return {
5004
- anon_id: raw.anon_id,
5005
- tier: raw.tier === "paid" ? "paid" : "free",
5006
- api_key: typeof raw.api_key === "string" ? raw.api_key : null,
5007
- mandate: raw.mandate,
5008
- // Install-state passthrough: dropping these on a read→write cycle would
5009
- // reset every once-per-install nudge into an every-time nag.
5010
- created_at: typeof raw.created_at === "string" ? raw.created_at : void 0,
5011
- nudges: raw.nudges && typeof raw.nudges === "object" ? raw.nudges : void 0,
5012
- decisions_count: typeof raw.decisions_count === "number" ? raw.decisions_count : void 0,
5013
- hosted_lapsed_at: typeof raw.hosted_lapsed_at === "string" ? raw.hosted_lapsed_at : void 0,
5014
- operator_email: typeof raw.operator_email === "string" ? raw.operator_email : void 0,
5015
- registered_email: typeof raw.registered_email === "string" ? raw.registered_email : void 0
5016
- };
5017
- } catch {
5018
- return null;
5019
- }
5020
- }
5021
- function writeConfig(cfg) {
5022
- const dir = configDir();
5023
- mkdirSync2(dir, { recursive: true, mode: 448 });
5024
- writeFileSync2(configPath(), JSON.stringify(cfg, null, 2), { mode: 384 });
5025
- }
5026
- function ensureState() {
5027
- const existing = readConfig();
5028
- if (existing) return { config: existing, firstRun: false };
5029
- const config = {
5030
- anon_id: randomUUID2(),
5031
- tier: "free",
5032
- api_key: null,
5033
- mandate: { payees: [], categories: ["*"], currency: "USD", perTxMax: 2500, maxTotal: 1e4 },
5034
- created_at: (/* @__PURE__ */ new Date()).toISOString()
5035
- };
5036
- try {
5037
- writeConfig(config);
5038
- } catch {
5039
- }
5040
- return { config, firstRun: true };
5041
- }
5042
- var DEMO_PAYEE = "fidacy:demo";
5043
- function resolveMandateRules(cfg) {
5044
- const m = cfg?.mandate ?? {};
5045
- const envList = (v) => v === void 0 ? void 0 : v.split(",").map((s) => s.trim()).filter(Boolean);
5046
- const envNum = (name, v) => {
5047
- if (v === void 0 || v.trim() === "") return void 0;
5048
- const n = Number(v);
5049
- if (!Number.isFinite(n) || n <= 0) {
5050
- console.error(
5051
- `[fidacy] ${name}="${v}" is not a positive number, so it cannot be enforced as a cap. Ignoring it and using the safe default. Write digits only, with no thousands separator, currency symbol or unit (e.g. ${name}=2500).`
5052
- );
5053
- return void 0;
5054
- }
5055
- return n;
5056
- };
5057
- const fileNum = (v) => typeof v === "number" && Number.isFinite(v) && v > 0 ? v : void 0;
5058
- const payees = envList(process.env.FIDACY_ALLOW_PAYEES) ?? m.payees ?? [];
5059
- return {
5060
- payees: payees.includes(DEMO_PAYEE) ? payees : [...payees, DEMO_PAYEE],
5061
- categories: envList(process.env.FIDACY_ALLOW_CATEGORIES) ?? m.categories ?? ["*"],
5062
- currency: process.env.FIDACY_CURRENCY ?? m.currency ?? "USD",
5063
- perTxMax: envNum("FIDACY_PER_TX_MAX", process.env.FIDACY_PER_TX_MAX) ?? fileNum(m.perTxMax) ?? 2500,
5064
- maxTotal: envNum("FIDACY_MAX_TOTAL", process.env.FIDACY_MAX_TOTAL) ?? fileNum(m.maxTotal) ?? 1e4
5065
- };
5066
- }
5067
-
5068
5069
  // ../mcp/src/telemetry.ts
5069
- var CLIENT_VERSION = true ? "0.5.1" : "dev";
5070
+ var CLIENT_VERSION = true ? "0.5.2" : "dev";
5070
5071
  function bandOf(amount) {
5071
5072
  if (typeof amount !== "number" || !Number.isFinite(amount) || amount <= 0) return void 0;
5072
5073
  if (amount < 10) return "lt10";
@@ -5254,7 +5255,7 @@ function requestUpgrade() {
5254
5255
  }
5255
5256
 
5256
5257
  // ../mcp/src/provision.ts
5257
- var CLIENT_VERSION2 = true ? "0.5.1" : "dev";
5258
+ var CLIENT_VERSION2 = true ? "0.5.2" : "dev";
5258
5259
  function provisionEnabled() {
5259
5260
  const v = (process.env.FIDACY_DISABLE_PROVISION ?? "").trim().toLowerCase();
5260
5261
  return !(v === "1" || v === "true" || v === "yes");
@@ -5396,7 +5397,7 @@ function trialCountdownLine(keyOverride) {
5396
5397
  }
5397
5398
 
5398
5399
  // ../mcp/src/register.ts
5399
- var CLIENT_VERSION3 = true ? "0.5.1" : "dev";
5400
+ var CLIENT_VERSION3 = true ? "0.5.2" : "dev";
5400
5401
  function endpoint3() {
5401
5402
  const base = (process.env.FIDACY_ENGINE_URL ?? "https://api.fidacy.com").replace(/\/$/, "");
5402
5403
  return `${base}/v1/register`;
@@ -3,7 +3,7 @@
3
3
  "name": "Fidacy AI Agent Firewall",
4
4
  "description": "A signed, independently-verifiable verdict on every money-moving agent action. Blocks wrong/lookalike payee, over-cap, and duplicate-invoice fraud before money moves. Non-custodial, local-first, deny-by-default.",
5
5
  "icon": "https://fidacy.com/logo.png",
6
- "version": "0.5.1",
6
+ "version": "0.5.2",
7
7
  "contracts": {
8
8
  "tools": [
9
9
  "request_payment",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fidacy/openclaw-plugin",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Fidacy payment firewall as a native OpenClaw plugin: signed, verifiable verdicts on every money-moving agent action, in-process (no MCP subprocess).",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Fidacy (ZeepCode Group Technology LLC) <hello@fidacy.com> (https://fidacy.com)",