clay-server 4.3.0-beta.4 → 4.3.0-beta.5

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.
@@ -19,7 +19,7 @@ function getToolDefs(handlers, options) {
19
19
  description: "Delegate one concrete follow-up task to the existing visible Split Worker. This tool is exposed only after the user has configured and accepted an exact pair. A completed turn does not end the Split Worker session: reuse the same Split Worker for follow-up implementation and corrections instead of taking over its work. Detached completions are pushed back automatically. A delegated turn cannot delegate back, so keep orchestration one hop deep.",
20
20
  inputSchema: buildShape({
21
21
  message: { type: "string", description: "The complete task or question for the partner." },
22
- wait: { type: "boolean", description: "Wait for the partner's turn to finish. Defaults to true." },
22
+ wait: { type: "boolean", description: "Wait for the partner's turn to finish. Defaults to false; set true for an explicit blocking wait." },
23
23
  timeoutSeconds: { type: "number", description: "Maximum wait in seconds, from 1 to 900. Defaults to 300." },
24
24
  operationId: { type: "string", description: "Optional stable id for this delegation. Reusing it within the same human turn returns the original operation instead of sending twice." },
25
25
  taskId: { type: "string", description: "Optional stable task id for generation and completion correlation." },
@@ -28,7 +28,7 @@ function getToolDefs(handlers, options) {
28
28
  },
29
29
  {
30
30
  name: "read_partner",
31
- description: "Read the Split Worker's current status and recent conversation turns, plus the same bounded capacity report partner_status returns. Use this for an interim check after a non-waiting delegation or timeout; completed results are pushed automatically.",
31
+ description: "Read the Split Worker's current status and recent conversation turns, plus the same bounded capacity report partner_status returns. Use only for a requested status, concrete failure or stall diagnosis, or capacity/queue decision; do not poll routinely. Completed results are pushed automatically.",
32
32
  inputSchema: buildShape({
33
33
  lastTurns: { type: "number", description: "Number of recent user-message-delimited turns, from 0 to 5. Use 0 for status only. Defaults to 1." },
34
34
  }),
@@ -76,7 +76,13 @@ var DRIVER_CORE = [
76
76
  "ambiguous and a visible pair exists, prefer the visible Split Worker. If review or user feedback requires",
77
77
  "corrections to the Split Worker's implementation, delegate a follow-up turn to that Split Worker instead of",
78
78
  "editing its files yourself. If a non-waiting delegation finishes later, Clay pushes the result back and",
79
- "resumes you automatically. You also decide the Split Worker's tool-permission requests when they arise;",
79
+ "resumes you automatically. send_to_partner returns immediately by default; set wait to true only when you",
80
+ "explicitly need the final result in the same tool call. Do useful independent work after a non-waiting",
81
+ "delegation, then yield for Clay's automatic completion callback; do not poll read_partner or partner_status,",
82
+ "or sleep while waiting. Use those reads only for a user-requested status, concrete failure or stall diagnosis,",
83
+ "capacity/reuse decision, or exact queue inspection before mutation. Do not send the same correction as both",
84
+ "a live message and a queued task; consolidate review feedback into one bounded follow-up. You also decide",
85
+ "the Split Worker's tool-permission requests when they arise;",
80
86
  "approve only what falls inside the task the user authorized. Integrate and verify the final outcome. Do not",
81
87
  "search the project for implementations of these tools, and do not delegate work that must be performed",
82
88
  "sequentially in this same session.",
package/lib/sessions.js CHANGED
@@ -230,7 +230,7 @@ function createSessionManager(opts) {
230
230
  }
231
231
 
232
232
  function appendToSessionFile(session, obj) {
233
- if (!session.cliSessionId) return;
233
+ if (!session.cliSessionId) return true;
234
234
  session.lastActivity = Date.now();
235
235
  try {
236
236
  var afPath = sessionFilePath(session.cliSessionId);
@@ -238,8 +238,10 @@ function createSessionManager(opts) {
238
238
  if (process.platform !== "win32") {
239
239
  try { fs.chmodSync(afPath, 0o600); } catch (chmodErr) {}
240
240
  }
241
+ return true;
241
242
  } catch(e) {
242
243
  console.error("[session] Failed to append to session file:", e.message);
244
+ return false;
243
245
  }
244
246
  }
245
247
 
@@ -1031,7 +1033,7 @@ function createSessionManager(opts) {
1031
1033
  var outgoingObj = clientObj || obj;
1032
1034
  if (!outgoingObj._ts) outgoingObj._ts = obj._ts;
1033
1035
  session.history.push(obj);
1034
- appendToSessionFile(session, obj);
1036
+ if (appendToSessionFile(session, obj) === false) return false;
1035
1037
  // Per-session out-of-band subscribers mirror mate session events into
1036
1038
  // a parallel UI without joining the project's
1037
1039
  // ws clients set). Subscribers receive the same obj that goes to ws
@@ -1087,6 +1089,33 @@ function createSessionManager(opts) {
1087
1089
  }
1088
1090
  // Notify server for cross-project unread tracking
1089
1091
  if (obj.type === "done") onSessionDone(session);
1092
+ return true;
1093
+ }
1094
+
1095
+ function sendAndRecordDurably(session, obj, clientObj) {
1096
+ if (!session || !session.cliSessionId) return false;
1097
+ var saved;
1098
+ try { saved = doSendAndRecord(session, obj, clientObj); }
1099
+ catch (error) {
1100
+ var exact = JSON.stringify(obj);
1101
+ if (hasDurableSessionRecord(session, function (record) { return JSON.stringify(record) === exact; })) return true;
1102
+ if (session.history[session.history.length - 1] === obj) session.history.pop();
1103
+ throw error;
1104
+ }
1105
+ if (saved === false && session.history[session.history.length - 1] === obj) session.history.pop();
1106
+ return saved === true;
1107
+ }
1108
+
1109
+ function hasDurableSessionRecord(session, predicate) {
1110
+ if (!session || !session.cliSessionId || typeof predicate !== "function") return false;
1111
+ try {
1112
+ var lines = fs.readFileSync(sessionFilePath(session.cliSessionId), "utf8").split("\n");
1113
+ for (var i = lines.length - 1; i >= 0; i--) {
1114
+ if (!lines[i]) continue;
1115
+ try { if (predicate(JSON.parse(lines[i]))) return true; } catch (error) {}
1116
+ }
1117
+ } catch (error) {}
1118
+ return false;
1090
1119
  }
1091
1120
 
1092
1121
  function resumeSession(cliSessionId, opts, targetWs) {
@@ -1384,6 +1413,8 @@ function createSessionManager(opts) {
1384
1413
  saveSessionFile: saveSessionFile,
1385
1414
  appendToSessionFile: appendToSessionFile,
1386
1415
  sendAndRecord: doSendAndRecord,
1416
+ sendAndRecordDurably: sendAndRecordDurably,
1417
+ hasDurableSessionRecord: hasDurableSessionRecord,
1387
1418
  subscribeSession: function (localId, cb) {
1388
1419
  var session = sessions.get(localId);
1389
1420
  if (!session) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clay-server",
3
- "version": "4.3.0-beta.4",
3
+ "version": "4.3.0-beta.5",
4
4
  "description": "Self-hosted team workspace for Claude Code and Codex. Multi-user, browser-based, with persistent AI mates.",
5
5
  "bin": {
6
6
  "clay-server": "./bin/cli.js"