@clawos-dev/clawd 0.2.191-beta.381.2ccc9ac → 0.2.191-beta.383.956b6ae

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/cli.cjs CHANGED
@@ -47586,12 +47586,13 @@ function inboxMcpConfigPath(dataDir) {
47586
47586
  async function writeInboxMcpConfig(args) {
47587
47587
  const cfgPath = inboxMcpConfigPath(args.dataDir);
47588
47588
  const content = {
47589
- _comment: "daemon \u542F\u52A8\u65F6\u81EA\u52A8\u751F\u6210\uFF1Bcc spawn \u901A\u8FC7 --mcp-config \u6CE8\u5165\u3002inbox/mcp-server.cjs \u662F daemon \u81EA\u5E26\u7684 stdio MCP server\uFF0C\u66B4\u9732 sendDm tool\uFF08persona \u53D7\u63A7\u53D1 P2P IM DM\uFF09\u3002",
47589
+ _comment: "daemon \u542F\u52A8\u65F6\u81EA\u52A8\u751F\u6210\uFF1Bcc spawn \u901A\u8FC7 --mcp-config \u6CE8\u5165\u3002inbox/mcp-server.cjs \u662F daemon \u81EA\u5E26\u7684 stdio MCP server\uFF0C\u66B4\u9732 sendDm tool\uFF08persona \u53D7\u63A7\u53D1 P2P IM DM\uFF09\u3002env.CLAWD_INBOX_LOG \u6307 server \u5199\u65E5\u5FD7\u7684 append \u6587\u4EF6\u8DEF\u5F84\u3002",
47590
47590
  mcpServers: {
47591
47591
  "clawd-inbox": {
47592
47592
  type: "stdio",
47593
47593
  command: "node",
47594
- args: [args.serverScriptPath]
47594
+ args: [args.serverScriptPath],
47595
+ ...args.logPath ? { env: { CLAWD_INBOX_LOG: args.logPath } } : {}
47595
47596
  }
47596
47597
  }
47597
47598
  };
@@ -53806,10 +53807,20 @@ function buildInboxHandlers(deps) {
53806
53807
  const d = deps.sendDmDeps;
53807
53808
  if (!d) throw new ClawdError(ERROR_CODES.INTERNAL, "inbox:sendDm not wired");
53808
53809
  if (!sessionId) {
53810
+ d?.logger?.warn("inbox.sendDm.rejected", { reason: "missing-session-id" });
53809
53811
  throw new ClawdError(ERROR_CODES.VALIDATION_ERROR, "inbox:sendDm requires sessionId");
53810
53812
  }
53811
53813
  const scope = d.getSessionScope(sessionId);
53814
+ d.logger?.info("inbox.sendDm.received", {
53815
+ sessionId,
53816
+ scopeKind: scope?.kind ?? "null",
53817
+ mode: scope && scope.kind === "persona" ? scope.mode : void 0,
53818
+ personaId: scope && scope.kind === "persona" ? scope.personaId : void 0,
53819
+ hasPeerDeviceId: Boolean(args.peerDeviceId),
53820
+ textLen: args.text.length
53821
+ });
53812
53822
  if (!scope || scope.kind !== "persona") {
53823
+ d.logger?.warn("inbox.sendDm.rejected", { sessionId, reason: "not-persona-session", scopeKind: scope?.kind ?? "null" });
53813
53824
  throw new ClawdError(ERROR_CODES.UNAUTHORIZED, "inbox:sendDm requires a persona session");
53814
53825
  }
53815
53826
  const origin = { kind: "persona", personaId: scope.personaId };
@@ -53817,6 +53828,12 @@ function buildInboxHandlers(deps) {
53817
53828
  const createdAt = d.now();
53818
53829
  if (scope.mode === "guest") {
53819
53830
  if (args.peerDeviceId && args.peerDeviceId !== d.ownerPrincipalId) {
53831
+ d.logger?.warn("inbox.sendDm.rejected", {
53832
+ sessionId,
53833
+ reason: "guest-non-owner-target",
53834
+ personaId: scope.personaId,
53835
+ target: args.peerDeviceId
53836
+ });
53820
53837
  throw new ClawdError(ERROR_CODES.UNAUTHORIZED, "guest-driven persona may only DM the owner");
53821
53838
  }
53822
53839
  const message2 = manager.postMessage({
@@ -53827,13 +53844,21 @@ function buildInboxHandlers(deps) {
53827
53844
  createdAt,
53828
53845
  origin
53829
53846
  });
53847
+ d.logger?.info("inbox.sendDm.delivered", { sessionId, mode: "guest", personaId: scope.personaId, peerDeviceId: scope.capId, id });
53830
53848
  return { response: { type: "inbox:sendDm:ok", message: message2 } };
53831
53849
  }
53832
53850
  if (!args.peerDeviceId) {
53851
+ d.logger?.warn("inbox.sendDm.rejected", { sessionId, reason: "owner-missing-peer", personaId: scope.personaId });
53833
53852
  throw new ClawdError(ERROR_CODES.VALIDATION_ERROR, "owner-driven sendDm requires peerDeviceId");
53834
53853
  }
53835
53854
  const contact = d.getContact(args.peerDeviceId);
53836
53855
  if (!contact) {
53856
+ d.logger?.warn("inbox.sendDm.rejected", {
53857
+ sessionId,
53858
+ reason: "unknown-contact",
53859
+ personaId: scope.personaId,
53860
+ peerDeviceId: args.peerDeviceId
53861
+ });
53837
53862
  throw new ClawdError(ERROR_CODES.VALIDATION_ERROR, `unknown contact: ${args.peerDeviceId}`);
53838
53863
  }
53839
53864
  const fwd = await d.forwardInboxPostToPeer({
@@ -53844,6 +53869,13 @@ function buildInboxHandlers(deps) {
53844
53869
  origin
53845
53870
  });
53846
53871
  if (!fwd.ok) {
53872
+ d.logger?.warn("inbox.sendDm.forward-failed", {
53873
+ sessionId,
53874
+ personaId: scope.personaId,
53875
+ peerDeviceId: args.peerDeviceId,
53876
+ id,
53877
+ error: fwd.error ?? "unknown"
53878
+ });
53847
53879
  throw new ClawdError(ERROR_CODES.INTERNAL, `deliver to peer failed: ${fwd.error ?? "unknown"}`);
53848
53880
  }
53849
53881
  const message = manager.postMessage({
@@ -53854,6 +53886,13 @@ function buildInboxHandlers(deps) {
53854
53886
  createdAt,
53855
53887
  origin
53856
53888
  });
53889
+ d.logger?.info("inbox.sendDm.delivered", {
53890
+ sessionId,
53891
+ mode: "owner",
53892
+ personaId: scope.personaId,
53893
+ peerDeviceId: args.peerDeviceId,
53894
+ id
53895
+ });
53857
53896
  return { response: { type: "inbox:sendDm:ok", message } };
53858
53897
  };
53859
53898
  return {
@@ -56364,7 +56403,8 @@ function buildMethodHandlers(deps) {
56364
56403
  },
56365
56404
  genId: () => (0, import_node_crypto17.randomUUID)(),
56366
56405
  now: () => Date.now(),
56367
- forwardInboxPostToPeer
56406
+ forwardInboxPostToPeer,
56407
+ logger: deps.logger
56368
56408
  }
56369
56409
  }),
56370
56410
  ...buildContactHandlers({
@@ -57504,13 +57544,16 @@ async function startDaemon(config) {
57504
57544
  const inboxServerScriptPath = inboxServerCandidates.find((p2) => import_node_fs42.default.existsSync(p2));
57505
57545
  let inboxMcpConfigPath2;
57506
57546
  if (inboxServerScriptPath) {
57547
+ const inboxLogPath = import_node_path54.default.join(config.dataDir, "inbox-mcp-server.log");
57507
57548
  inboxMcpConfigPath2 = await writeInboxMcpConfig({
57508
57549
  dataDir: config.dataDir,
57509
- serverScriptPath: inboxServerScriptPath
57550
+ serverScriptPath: inboxServerScriptPath,
57551
+ logPath: inboxLogPath
57510
57552
  });
57511
57553
  logger.info("inbox.mcp.json written", {
57512
57554
  path: inboxMcpConfigPath2,
57513
- server: inboxServerScriptPath
57555
+ server: inboxServerScriptPath,
57556
+ serverLog: inboxLogPath
57514
57557
  });
57515
57558
  } else {
57516
57559
  logger.warn(
@@ -4402,11 +4402,11 @@ var require_core = __commonJS({
4402
4402
  Ajv2.ValidationError = validation_error_1.default;
4403
4403
  Ajv2.MissingRefError = ref_error_1.default;
4404
4404
  exports2.default = Ajv2;
4405
- function checkOptions(checkOpts, options, msg, log = "error") {
4405
+ function checkOptions(checkOpts, options, msg, log2 = "error") {
4406
4406
  for (const key in checkOpts) {
4407
4407
  const opt = key;
4408
4408
  if (opt in options)
4409
- this.logger[log](`${msg}: option ${key}. ${checkOpts[opt]}`);
4409
+ this.logger[log2](`${msg}: option ${key}. ${checkOpts[opt]}`);
4410
4410
  }
4411
4411
  }
4412
4412
  function getSchEnv(keyRef) {
@@ -6874,12 +6874,12 @@ var require_dist = __commonJS({
6874
6874
  throw new Error(`Unknown format "${name}"`);
6875
6875
  return f;
6876
6876
  };
6877
- function addFormats(ajv, list, fs, exportName) {
6877
+ function addFormats(ajv, list, fs2, exportName) {
6878
6878
  var _a;
6879
6879
  var _b;
6880
6880
  (_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
6881
6881
  for (const f of list)
6882
- ajv.addFormat(f, fs[f]);
6882
+ ajv.addFormat(f, fs2[f]);
6883
6883
  }
6884
6884
  module2.exports = exports2 = formatsPlugin;
6885
6885
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -6893,6 +6893,7 @@ __export(mcp_server_exports, {
6893
6893
  handleSendDmCall: () => handleSendDmCall
6894
6894
  });
6895
6895
  module.exports = __toCommonJS(mcp_server_exports);
6896
+ var import_node_fs = __toESM(require("fs"), 1);
6896
6897
 
6897
6898
  // ../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
6898
6899
  var external_exports = {};
@@ -21107,19 +21108,38 @@ var StdioServerTransport = class {
21107
21108
  };
21108
21109
 
21109
21110
  // src/inbox/mcp-server.ts
21111
+ var INBOX_LOG = process.env.CLAWD_INBOX_LOG;
21112
+ function log(msg, info) {
21113
+ const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] inbox-mcp ${msg}${info ? " " + JSON.stringify(info) : ""}
21114
+ `;
21115
+ if (INBOX_LOG) {
21116
+ try {
21117
+ import_node_fs.default.appendFileSync(INBOX_LOG, line);
21118
+ return;
21119
+ } catch {
21120
+ }
21121
+ }
21122
+ try {
21123
+ process.stderr.write(line);
21124
+ } catch {
21125
+ }
21126
+ }
21110
21127
  async function handleSendDmCall(params, ctx = {}) {
21111
21128
  const daemonUrl = process.env.CLAWD_DAEMON_URL;
21112
21129
  const sessionId = process.env.CLAWD_SESSION_ID;
21113
21130
  if (!daemonUrl) {
21131
+ log("sendDm CLAWD_DAEMON_URL missing");
21114
21132
  return { content: [{ type: "text", text: "Error: CLAWD_DAEMON_URL not set; cannot call daemon." }], isError: true };
21115
21133
  }
21116
21134
  if (!sessionId) {
21135
+ log("sendDm CLAWD_SESSION_ID missing");
21117
21136
  return {
21118
21137
  content: [{ type: "text", text: "Error: CLAWD_SESSION_ID not set; sendDm can only run from a persona session." }],
21119
21138
  isError: true
21120
21139
  };
21121
21140
  }
21122
21141
  const f = ctx.fetch ?? fetch;
21142
+ log("sendDm pre-fetch", { hasPeerDeviceId: Boolean(params.peerDeviceId), textLen: params.text.length });
21123
21143
  let res;
21124
21144
  try {
21125
21145
  res = await f(`${daemonUrl}/api/rpc/inbox.sendDm`, {
@@ -21131,20 +21151,23 @@ async function handleSendDmCall(params, ctx = {}) {
21131
21151
  })
21132
21152
  });
21133
21153
  } catch (err) {
21134
- return {
21135
- content: [{ type: "text", text: `sendDm fetch failed: ${err instanceof Error ? err.message : String(err)}` }],
21136
- isError: true
21137
- };
21154
+ const msg = err instanceof Error ? err.message : String(err);
21155
+ log("sendDm fetch threw", { msg });
21156
+ return { content: [{ type: "text", text: `sendDm fetch failed: ${msg}` }], isError: true };
21138
21157
  }
21158
+ log("sendDm post-fetch", { status: res.status });
21139
21159
  let json;
21140
21160
  try {
21141
21161
  json = await res.json();
21142
21162
  } catch {
21163
+ log("sendDm non-JSON", { status: res.status });
21143
21164
  return { content: [{ type: "text", text: `sendDm RPC returned non-JSON: status ${res.status}` }], isError: true };
21144
21165
  }
21145
21166
  if (json.ok === false) {
21167
+ log("sendDm adapter error", { error: json.error, message: json.message });
21146
21168
  return { content: [{ type: "text", text: `sendDm failed: ${json.error}: ${json.message}` }], isError: true };
21147
21169
  }
21170
+ log("sendDm ok");
21148
21171
  return { content: [{ type: "text", text: JSON.stringify(json.result) }] };
21149
21172
  }
21150
21173
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.191-beta.381.2ccc9ac",
3
+ "version": "0.2.191-beta.383.956b6ae",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",