duclaw-cli 1.8.4 → 1.8.6

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/bundle.js CHANGED
@@ -30242,7 +30242,7 @@ function printHelp() {
30242
30242
  `);
30243
30243
  }
30244
30244
  function printVersion() {
30245
- console.log(`duclaw-cli v${true ? "1.8.4" : "unknown"}`);
30245
+ console.log(`duclaw-cli v${true ? "1.8.6" : "unknown"}`);
30246
30246
  }
30247
30247
  function getDuclawTemplate() {
30248
30248
  return {
@@ -50206,7 +50206,6 @@ var userKeyPatterns = [
50206
50206
  ];
50207
50207
  var conversationKeyPattern = { match: "agent:mem:*", prefix: "agent:mem:" };
50208
50208
  var dateSegmentPattern = /^\d{8}$/;
50209
- var MAIN_MANAGER_USER_ID = "__main_manager__";
50210
50209
  var isPlausibleUserId = (userId) => {
50211
50210
  if (!userId) return false;
50212
50211
  if (userId.length > 240) return false;
@@ -50334,7 +50333,6 @@ var collectCompactSummaries = async (userId) => {
50334
50333
  };
50335
50334
  var isMailboxScopedUserId = (userId) => userId === "manager" || userId.includes("::") || userId.startsWith("cron-") || userId.startsWith("kanban:goal:");
50336
50335
  var classifyMemoryUser = (userId) => {
50337
- if (userId === MAIN_MANAGER_USER_ID) return "main-manager";
50338
50336
  if (userId.startsWith("kanban:")) return "kanban";
50339
50337
  if (userId.includes("::")) return "department";
50340
50338
  if (userId.startsWith("oc_") || userId.startsWith("chat_")) return "chat";
@@ -50362,12 +50360,7 @@ var collectManagerRelatedUserIds = (userId) => {
50362
50360
  return [userId];
50363
50361
  }
50364
50362
  };
50365
- var collectMainManagerScopeUserIds = async () => {
50366
- const { userIds } = await collectUserIds();
50367
- return Array.from(new Set(userIds.filter((id) => id !== MAIN_MANAGER_USER_ID && !isMailboxScopedUserId(id))));
50368
- };
50369
50363
  var collectMemoryScopeUserIds = async (userId) => {
50370
- if (userId === MAIN_MANAGER_USER_ID) return collectMainManagerScopeUserIds();
50371
50364
  return collectManagerRelatedUserIds(userId);
50372
50365
  };
50373
50366
  var aggregateMemorySummaries = async (userId, localConversationUserIds) => {
@@ -50392,7 +50385,6 @@ var aggregateMemorySummaries = async (userId, localConversationUserIds) => {
50392
50385
  const memoryCount = details.reduce((sum, detail) => sum + detail.memoryCount, 0);
50393
50386
  return {
50394
50387
  userId,
50395
- displayName: userId === MAIN_MANAGER_USER_ID ? "Main Manager \u6C47\u603B" : void 0,
50396
50388
  kind: classifyMemoryUser(userId),
50397
50389
  memoryCount,
50398
50390
  hasMemory: memoryCount > 0,
@@ -50400,8 +50392,7 @@ var aggregateMemorySummaries = async (userId, localConversationUserIds) => {
50400
50392
  hasConversation: details.some((detail) => detail.hasConversation),
50401
50393
  lastDreamAt: Math.max(0, ...details.map((detail) => detail.lastDreamAt ?? 0)) || null,
50402
50394
  lastActivityAt: Math.max(0, ...details.map((detail) => detail.lastActivityAt ?? 0)) || null,
50403
- relatedUserIds: relatedUserIds.length > 0 && (userId === MAIN_MANAGER_USER_ID || relatedUserIds.length > 1) ? relatedUserIds : void 0,
50404
- isAggregate: userId === MAIN_MANAGER_USER_ID || relatedUserIds.length > 1 || void 0
50395
+ relatedUserIds: relatedUserIds.length > 1 ? relatedUserIds : void 0
50405
50396
  };
50406
50397
  };
50407
50398
  var collectUserIds = async () => {
@@ -50422,6 +50413,54 @@ var collectUserIds = async () => {
50422
50413
  }
50423
50414
  return { userIds: Array.from(userIds), localConversationUserIds };
50424
50415
  };
50416
+ var dateKeyInShanghai = (timestamp) => new Date(timestamp).toLocaleString("sv-SE", {
50417
+ timeZone: "Asia/Shanghai",
50418
+ year: "numeric",
50419
+ month: "2-digit",
50420
+ day: "2-digit"
50421
+ }).replace(/-/g, "");
50422
+ var messageToAgentLogEntry = (message, index) => ({
50423
+ index,
50424
+ role: message.role,
50425
+ blocks: message.content.map((block) => {
50426
+ if (block.type === "text") return { type: "text", text: block.text };
50427
+ if (block.type === "tool_use") {
50428
+ return {
50429
+ type: "tool_use",
50430
+ id: block.id,
50431
+ name: block.name,
50432
+ input: block.input
50433
+ };
50434
+ }
50435
+ if (block.type === "tool_result") {
50436
+ return {
50437
+ type: "tool_result",
50438
+ toolUseId: block.tool_use_id,
50439
+ content: typeof block.content === "string" ? block.content.slice(0, 4e3) : JSON.stringify(block.content).slice(0, 4e3)
50440
+ };
50441
+ }
50442
+ return { type: "unknown" };
50443
+ })
50444
+ });
50445
+ var collectConversationMessages = async (userId, limit = 300) => {
50446
+ const storageConf = { url: process.env.REDIS_URL };
50447
+ const storage = createRuntimeStorage(storageConf);
50448
+ const now = Date.now();
50449
+ const byDate = [];
50450
+ for (let i = 0; i < 7; i++) {
50451
+ const dateStr = dateKeyInShanghai(now - i * 864e5);
50452
+ const messages = await getMessages(storage, userId, limit, dateStr);
50453
+ if (messages.length > 0) byDate.push(...messages);
50454
+ }
50455
+ const fallback = byDate.length > 0 ? [] : await getMessages(storage, userId, limit);
50456
+ const seen = /* @__PURE__ */ new Set();
50457
+ return [...byDate, ...fallback].filter((message) => {
50458
+ const key = `${message.role}:${message.timestamp ?? ""}:${JSON.stringify(message.content).slice(0, 80)}`;
50459
+ if (seen.has(key)) return false;
50460
+ seen.add(key);
50461
+ return true;
50462
+ });
50463
+ };
50425
50464
  var memoryRoutes = new Hono2();
50426
50465
  memoryRoutes.get("/memory/users", async (c) => {
50427
50466
  try {
@@ -50429,17 +50468,35 @@ memoryRoutes.get("/memory/users", async (c) => {
50429
50468
  const summaries = await Promise.all(userIds.map(
50430
50469
  (userId) => aggregateMemorySummaries(userId, localConversationUserIds)
50431
50470
  ));
50432
- if (userIds.length > 0) {
50433
- summaries.unshift(await aggregateMemorySummaries(MAIN_MANAGER_USER_ID, localConversationUserIds));
50434
- }
50435
50471
  summaries.sort(
50436
- (a, b) => Number(b.userId === MAIN_MANAGER_USER_ID) - Number(a.userId === MAIN_MANAGER_USER_ID) || (b.lastActivityAt ?? 0) - (a.lastActivityAt ?? 0) || a.userId.localeCompare(b.userId)
50472
+ (a, b) => (b.lastActivityAt ?? 0) - (a.lastActivityAt ?? 0) || a.userId.localeCompare(b.userId)
50437
50473
  );
50438
50474
  return c.json(summaries);
50439
50475
  } catch (err) {
50440
50476
  return c.json({ error: err.message || "Failed to list memory users" }, 500);
50441
50477
  }
50442
50478
  });
50479
+ memoryRoutes.get("/memory/context-sources", async (c) => {
50480
+ try {
50481
+ loadEnv();
50482
+ const limit = Math.min(Number(c.req.query("limit")) || 300, 500);
50483
+ const { userIds } = await collectUserIds();
50484
+ const sources = (await Promise.all(userIds.map(async (userId) => {
50485
+ const messages = await collectConversationMessages(userId, limit);
50486
+ if (messages.length === 0) return null;
50487
+ return {
50488
+ userId,
50489
+ displayName: void 0,
50490
+ kind: classifyMemoryUser(userId) ?? "user",
50491
+ messageCount: messages.length,
50492
+ agentLogs: messages.map(messageToAgentLogEntry)
50493
+ };
50494
+ }))).filter((source) => !!source).sort((a, b) => b.messageCount - a.messageCount || a.userId.localeCompare(b.userId));
50495
+ return c.json({ sources });
50496
+ } catch (err) {
50497
+ return c.json({ error: err.message || "Failed to list context sources" }, 500);
50498
+ }
50499
+ });
50443
50500
  memoryRoutes.get("/memory", async (c) => {
50444
50501
  const userId = requireUserId(c.req.query("userId"));
50445
50502
  if (!userId) return c.json({ error: "userId is required" }, 400);
@@ -50682,7 +50739,7 @@ var systemRoutes = new Hono2();
50682
50739
  var startTime = Date.now();
50683
50740
  systemRoutes.get("/system/info", (c) => {
50684
50741
  return c.json({
50685
- version: true ? "1.8.4" : "unknown",
50742
+ version: true ? "1.8.6" : "unknown",
50686
50743
  uptime: Math.floor((Date.now() - startTime) / 1e3),
50687
50744
  env: process.env.NODE_ENV || "development",
50688
50745
  nodeVersion: process.version