u-foo 3.1.1 → 3.1.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
|
@@ -269,6 +269,19 @@ and `agent_handle`. Include the handle in heartbeat, activity, send, receive,
|
|
|
269
269
|
acknowledgement, report, and unregister calls. The handle is an ownership
|
|
270
270
|
capability: do not send it to peers or print it in reports.
|
|
271
271
|
|
|
272
|
+
For a new external registration, ufoo assigns both the subscriber's
|
|
273
|
+
eight-character session suffix and its automatic `<agent-prefix>-<number>`
|
|
274
|
+
nickname on the server, using the same identity generators as wrapper launches.
|
|
275
|
+
A Cursor MCP registration with `agent_type: "cursor"`, for example, receives
|
|
276
|
+
`cursor:<8-hex>` and `cursor-N`; the model selected inside Cursor does not
|
|
277
|
+
replace the Cursor Agent type.
|
|
278
|
+
A stable `client_instance_id` recovers that same identity after a transport
|
|
279
|
+
restart; even when that value is a UUID, it is not used as the subscriber
|
|
280
|
+
suffix. Legacy MCP subscribers whose suffix is the client UUID are superseded
|
|
281
|
+
by the short server-assigned identity on their next registration. MCP Agents
|
|
282
|
+
cannot self-assign or update these identity fields; an explicit operator rename
|
|
283
|
+
remains available through the controller/CLI rename path.
|
|
284
|
+
|
|
272
285
|
- **Codex App:** call MCP `wait_for_message` in the foreground with
|
|
273
286
|
the registered subscriber and handle, `after_seq: 0`, and
|
|
274
287
|
`timeout_seconds: 0`. The tool call stays pending inside the dedicated
|
package/package.json
CHANGED
|
@@ -362,6 +362,7 @@ function isMetaActive(meta) {
|
|
|
362
362
|
function normalizeAgentTypeAlias(value = "") {
|
|
363
363
|
const text = String(value || "").trim().toLowerCase();
|
|
364
364
|
if (!text) return "";
|
|
365
|
+
if (text === "cursor") return "cursor";
|
|
365
366
|
if (text === "codex") return "codex";
|
|
366
367
|
if (text === "claude" || text === "claude-code") return "claude-code";
|
|
367
368
|
if (text === "agy") return "agy";
|
|
@@ -45,6 +45,16 @@ function normalizeBusAgentType(agentType = "") {
|
|
|
45
45
|
return value;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function assertServerOwnedExternalIdentity(args = {}, fields = [], operation = "register_agent") {
|
|
49
|
+
const field = fields.find((name) => Object.prototype.hasOwnProperty.call(args, name));
|
|
50
|
+
if (!field) return;
|
|
51
|
+
const err = new Error(
|
|
52
|
+
`${operation} ${field} is server-assigned; use the subscriber and nickname returned by ufoo`
|
|
53
|
+
);
|
|
54
|
+
err.code = "external_identity_field_forbidden";
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
function ensureBusLoaded(projectRoot) {
|
|
49
59
|
const bus = new EventBus(projectRoot);
|
|
50
60
|
bus.ensureBus();
|
|
@@ -72,14 +82,14 @@ function resolveSubscriberArg(args = {}) {
|
|
|
72
82
|
return subscriber;
|
|
73
83
|
}
|
|
74
84
|
|
|
75
|
-
function createSessionId() {
|
|
76
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
85
|
function createCryptoSessionId() {
|
|
80
86
|
return crypto.randomBytes(4).toString("hex");
|
|
81
87
|
}
|
|
82
88
|
|
|
89
|
+
function isServerAllocatedExternalSessionId(sessionId = "") {
|
|
90
|
+
return /^[0-9a-f]{8}$/.test(String(sessionId || ""));
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
function createAgentHandle() {
|
|
84
94
|
return crypto.randomBytes(32).toString("base64url");
|
|
85
95
|
}
|
|
@@ -174,7 +184,9 @@ async function registerAgentFull(projectRoot, args = {}, options = {}) {
|
|
|
174
184
|
).trim();
|
|
175
185
|
const bus = ensureBusLoaded(projectRoot);
|
|
176
186
|
|
|
177
|
-
//
|
|
187
|
+
// Wrapper launches may provide resume metadata. External MCP registrations
|
|
188
|
+
// recover only through client_instance_id; otherwise the server owns the
|
|
189
|
+
// short session id so subscriber shapes stay consistent across launch modes.
|
|
178
190
|
let sessionId;
|
|
179
191
|
const explicitSessionId = String(args.session_id || args.sessionId || "").trim();
|
|
180
192
|
const reuseSession = args.reuseSession && typeof args.reuseSession === "object"
|
|
@@ -187,14 +199,18 @@ async function registerAgentFull(projectRoot, args = {}, options = {}) {
|
|
|
187
199
|
const reuseProviderSessionId = typeof reuseSession?.providerSessionId === "string"
|
|
188
200
|
? reuseSession.providerSessionId.trim() : "";
|
|
189
201
|
|
|
190
|
-
const
|
|
191
|
-
? Object.entries(bus.busData.agents || {}).
|
|
202
|
+
const clientInstanceEntries = !validateParentPid && clientInstanceId
|
|
203
|
+
? Object.entries(bus.busData.agents || {}).filter(([, meta]) => (
|
|
192
204
|
meta
|
|
193
205
|
&& meta.mcp_bridge === true
|
|
194
|
-
&& meta.agent_type === agentType
|
|
195
206
|
&& meta.mcp_client_instance_id === clientInstanceId
|
|
196
207
|
))
|
|
197
|
-
:
|
|
208
|
+
: [];
|
|
209
|
+
const recoveredEntry = clientInstanceEntries.find(([subscriber, meta]) => (
|
|
210
|
+
meta.agent_type === agentType
|
|
211
|
+
&& subscriber.startsWith(`${agentType}:`)
|
|
212
|
+
&& isServerAllocatedExternalSessionId(subscriber.slice(agentType.length + 1))
|
|
213
|
+
));
|
|
198
214
|
const recoveredSubscriber = recoveredEntry ? recoveredEntry[0] : "";
|
|
199
215
|
const recoveredSessionId = recoveredSubscriber.startsWith(`${agentType}:`)
|
|
200
216
|
? recoveredSubscriber.slice(agentType.length + 1)
|
|
@@ -202,12 +218,16 @@ async function registerAgentFull(projectRoot, args = {}, options = {}) {
|
|
|
202
218
|
|
|
203
219
|
if (recoveredSessionId) {
|
|
204
220
|
sessionId = recoveredSessionId;
|
|
205
|
-
} else if (explicitSessionId) {
|
|
221
|
+
} else if (validateParentPid && explicitSessionId) {
|
|
206
222
|
sessionId = explicitSessionId;
|
|
207
|
-
} else if (
|
|
223
|
+
} else if (
|
|
224
|
+
validateParentPid
|
|
225
|
+
&& reuseSessionId
|
|
226
|
+
&& reuseSubscriberId === `${agentType}:${reuseSessionId}`
|
|
227
|
+
) {
|
|
208
228
|
sessionId = reuseSessionId;
|
|
209
229
|
} else {
|
|
210
|
-
sessionId =
|
|
230
|
+
sessionId = createCryptoSessionId();
|
|
211
231
|
}
|
|
212
232
|
|
|
213
233
|
// parentPid validation
|
|
@@ -284,6 +304,20 @@ async function registerAgentFull(projectRoot, args = {}, options = {}) {
|
|
|
284
304
|
extendMcpAgentLease(meta);
|
|
285
305
|
}
|
|
286
306
|
if (hostCapabilities) meta.mcp_capabilities = hostCapabilities;
|
|
307
|
+
const supersededSubscribers = [];
|
|
308
|
+
if (!validateParentPid && clientInstanceId) {
|
|
309
|
+
for (const [previousSubscriber, previousMeta] of clientInstanceEntries) {
|
|
310
|
+
if (previousSubscriber === subscriber) continue;
|
|
311
|
+
const revokedAt = nowIso();
|
|
312
|
+
previousMeta.mcp_revoked_at = revokedAt;
|
|
313
|
+
previousMeta.mcp_lease_expires_at = revokedAt;
|
|
314
|
+
previousMeta.mcp_superseded_by = subscriber;
|
|
315
|
+
await bus.subscriberManager.leave(previousSubscriber);
|
|
316
|
+
previousMeta.status = "inactive";
|
|
317
|
+
previousMeta.activity_state = "";
|
|
318
|
+
supersededSubscribers.push(previousSubscriber);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
287
321
|
bus.saveBusData();
|
|
288
322
|
notifyDaemonRefresh(projectRoot);
|
|
289
323
|
return {
|
|
@@ -301,6 +335,7 @@ async function registerAgentFull(projectRoot, args = {}, options = {}) {
|
|
|
301
335
|
lease_expires_at: meta.mcp_lease_expires_at,
|
|
302
336
|
client_instance_id: clientInstanceId,
|
|
303
337
|
recovered: Boolean(recoveredSubscriber),
|
|
338
|
+
...(supersededSubscribers.length > 0 ? { superseded_subscribers: supersededSubscribers } : {}),
|
|
304
339
|
} : {}),
|
|
305
340
|
reuseProviderSessionId,
|
|
306
341
|
skipSessionResolve: !!args.skipSessionResolve,
|
|
@@ -308,6 +343,18 @@ async function registerAgentFull(projectRoot, args = {}, options = {}) {
|
|
|
308
343
|
}
|
|
309
344
|
|
|
310
345
|
async function registerAgent(projectRoot, args = {}) {
|
|
346
|
+
if (!String(args.agent_type || args.agentType || "").trim()) {
|
|
347
|
+
const err = new Error("register_agent requires agent_type for canonical identity allocation");
|
|
348
|
+
err.code = "external_agent_type_required";
|
|
349
|
+
throw err;
|
|
350
|
+
}
|
|
351
|
+
assertServerOwnedExternalIdentity(args, [
|
|
352
|
+
"session_id",
|
|
353
|
+
"sessionId",
|
|
354
|
+
"nickname",
|
|
355
|
+
"scoped_nickname",
|
|
356
|
+
"scopedNickname",
|
|
357
|
+
]);
|
|
311
358
|
return registerAgentFull(projectRoot, args, {
|
|
312
359
|
validateParentPid: false,
|
|
313
360
|
checkNicknameConflicts: false,
|
|
@@ -360,13 +407,14 @@ async function publishActivityState(projectRoot, args = {}) {
|
|
|
360
407
|
}
|
|
361
408
|
|
|
362
409
|
async function updateAgentMetadata(projectRoot, args = {}) {
|
|
410
|
+
assertServerOwnedExternalIdentity(args, [
|
|
411
|
+
"nickname",
|
|
412
|
+
"scoped_nickname",
|
|
413
|
+
"scopedNickname",
|
|
414
|
+
], "update_agent_metadata");
|
|
363
415
|
const subscriber = resolveSubscriberArg(args);
|
|
364
416
|
const bus = ensureBusLoaded(projectRoot);
|
|
365
417
|
const meta = assertAgentHandle(bus, subscriber, args);
|
|
366
|
-
const nickname = String(args.nickname || "").trim();
|
|
367
|
-
if (nickname) {
|
|
368
|
-
await bus.subscriberManager.rename(subscriber, nickname);
|
|
369
|
-
}
|
|
370
418
|
const metadata = args.metadata && typeof args.metadata === "object" ? args.metadata : {};
|
|
371
419
|
if (Object.keys(metadata).length > 0) {
|
|
372
420
|
meta.mcp_metadata = {
|
|
@@ -631,7 +679,6 @@ module.exports = {
|
|
|
631
679
|
ensureBusLoaded,
|
|
632
680
|
assertSubscriberExists,
|
|
633
681
|
resolveSubscriberArg,
|
|
634
|
-
createSessionId,
|
|
635
682
|
createAgentHandle,
|
|
636
683
|
hashAgentHandle,
|
|
637
684
|
assertAgentHandle,
|
|
@@ -73,6 +73,7 @@ function sleep(ms) {
|
|
|
73
73
|
function normalizeBusAgentType(agentType = "") {
|
|
74
74
|
const value = String(agentType || "").trim().toLowerCase();
|
|
75
75
|
if (!value) return "claude-code";
|
|
76
|
+
if (value === "cursor") return "cursor";
|
|
76
77
|
if (value === "codex") return "codex";
|
|
77
78
|
if (value === "claude" || value === "claude-code") return "claude-code";
|
|
78
79
|
if (value === "agy" || value === "antigravity") return "agy";
|
|
@@ -51,16 +51,16 @@ const CUSTOM_TOOL_DEFINITIONS = Object.freeze([
|
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
name: "register_agent",
|
|
54
|
-
description: "Register an externally launched Agent only when its shell has no wrapper-provided UFOO_SUBSCRIBER_ID.",
|
|
54
|
+
description: "Register an externally launched Agent only when its shell has no wrapper-provided UFOO_SUBSCRIBER_ID. ufoo assigns the subscriber id and nickname with the same format used by wrapper launches (for example, cursor:<8-hex> and cursor-N).",
|
|
55
55
|
input_schema: {
|
|
56
56
|
type: "object",
|
|
57
|
-
required: ["project_root"],
|
|
57
|
+
required: ["project_root", "agent_type"],
|
|
58
58
|
properties: {
|
|
59
59
|
project_root: { type: "string" },
|
|
60
|
-
agent_type: {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
agent_type: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "Agent family used as the subscriber and automatic nickname prefix, such as cursor, codex, claude, agy, grok, kimi, or ucode.",
|
|
63
|
+
},
|
|
64
64
|
launch_mode: { type: "string" },
|
|
65
65
|
capabilities: { type: "object", additionalProperties: true },
|
|
66
66
|
client_instance_id: {
|
|
@@ -107,7 +107,7 @@ const CUSTOM_TOOL_DEFINITIONS = Object.freeze([
|
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
109
|
name: "update_agent_metadata",
|
|
110
|
-
description: "Update
|
|
110
|
+
description: "Update caller-owned MCP metadata in the project bus.",
|
|
111
111
|
input_schema: {
|
|
112
112
|
type: "object",
|
|
113
113
|
required: ["project_root", "subscriber", "agent_handle"],
|
|
@@ -115,7 +115,6 @@ const CUSTOM_TOOL_DEFINITIONS = Object.freeze([
|
|
|
115
115
|
project_root: { type: "string" },
|
|
116
116
|
subscriber: { type: "string" },
|
|
117
117
|
agent_handle: { type: "string" },
|
|
118
|
-
nickname: { type: "string" },
|
|
119
118
|
metadata: { type: "object", additionalProperties: true },
|
|
120
119
|
},
|
|
121
120
|
additionalProperties: false,
|