@wayai/cli 0.3.280 → 0.3.281

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
@@ -27461,6 +27461,7 @@ var push_exports = {};
27461
27461
  __export(push_exports, {
27462
27462
  autoRenameAgentFiles: () => autoRenameAgentFiles,
27463
27463
  createAndPushNewHub: () => createAndPushNewHub,
27464
+ mergeSkippedToolEntries: () => mergeSkippedToolEntries,
27464
27465
  printErrors: () => printErrors,
27465
27466
  printLocalFileChanges: () => printLocalFileChanges,
27466
27467
  printSyncResult: () => printSyncResult,
@@ -27709,11 +27710,63 @@ async function autoRenameAgentFiles(client, hubId, hubFolder, organizationId, re
27709
27710
  }
27710
27711
  }
27711
27712
  }
27712
- async function syncAfterPush(client, hubId, hubFolder, organizationId) {
27713
+ function resolveHeld(id, name, held) {
27714
+ if (id && held?.some((h) => h.id === id)) return id;
27715
+ return held?.find((h) => name !== void 0 && h.name === name)?.id;
27716
+ }
27717
+ function entriesWithNoRow(entries, rows, identity2, pulled) {
27718
+ const keys = entries.map((entry) => identity2.key(entry, pulled));
27719
+ const rowKeys = new Set(rows.map((row) => identity2.rowKey(row)));
27720
+ const resolvedKeys = new Set(keys.filter((key) => key !== null));
27721
+ const unresolved = entries.filter((_, i) => keys[i] === null);
27722
+ const unresolvedTaken = /* @__PURE__ */ new Set();
27723
+ for (const tool of new Set(unresolved.map((entry) => identity2.tool(entry)))) {
27724
+ const named = new Set(unresolved.filter((entry) => identity2.tool(entry) === tool).map((entry) => identity2.label(entry)));
27725
+ const freeRows = rows.filter((row) => identity2.tool(row) === tool && !resolvedKeys.has(identity2.rowKey(row)));
27726
+ if (freeRows.length >= named.size) unresolvedTaken.add(tool);
27727
+ }
27728
+ return entries.filter((entry, i) => {
27729
+ const key = keys[i];
27730
+ return key === null ? !unresolvedTaken.has(identity2.tool(entry)) : !rowKeys.has(key);
27731
+ });
27732
+ }
27733
+ function mergeSkippedToolEntries(pulled, pushed) {
27734
+ const kept = [];
27735
+ for (const local of pushed.agents ?? []) {
27736
+ const remote = (pulled.agents ?? []).find((a) => local.id !== void 0 && a.id === local.id) ?? (pulled.agents ?? []).find((a) => a.name === local.name);
27737
+ const localTools = local.tools;
27738
+ if (!remote || !localTools) continue;
27739
+ const tools = remote.tools ?? {};
27740
+ const keep = (group) => {
27741
+ const identity2 = SKIPPABLE_ENTRY_IDENTITY[group];
27742
+ const rows = tools[group] ?? [];
27743
+ const missing = entriesWithNoRow(localTools[group] ?? [], rows, identity2, pulled);
27744
+ if (missing.length === 0) return;
27745
+ const replaced = new Set(missing.map(entryId).filter((id) => id !== void 0));
27746
+ const leftRows = rows.filter((row) => {
27747
+ const id = entryId(row);
27748
+ return id === void 0 || !replaced.has(id);
27749
+ });
27750
+ tools[group] = [...leftRows, ...missing];
27751
+ kept.push(...missing.map((entry) => `${local.name}: ${identity2.label(entry)}`));
27752
+ };
27753
+ keep("native");
27754
+ keep("delegation");
27755
+ keep("mcp");
27756
+ if (Object.keys(tools).length > 0) remote.tools = tools;
27757
+ }
27758
+ return kept;
27759
+ }
27760
+ async function syncAfterPush(client, hubId, hubFolder, pushed, organizationId) {
27713
27761
  try {
27714
27762
  const remoteConfig = await client.pull(hubId, organizationId);
27763
+ const kept = mergeSkippedToolEntries(remoteConfig, pushed);
27715
27764
  const delta = await materializeHubFolder(hubFolder, remoteConfig);
27716
27765
  printLocalFileChanges(delta);
27766
+ if (kept.length > 0) {
27767
+ console.log(`Kept ${kept.length} tool ${kept.length === 1 ? "entry" : "entries"} in this folder that this push did not write; push again once ${kept.length === 1 ? "it" : "they"} can be applied:`);
27768
+ for (const line of kept) console.log(` ${line}`);
27769
+ }
27717
27770
  const finalFolder = autoRenameHubFolder(hubFolder, remoteConfig.hub.name, remoteConfig.hub_environment, hubId, remoteConfig.preview_label, remoteConfig.branch_name);
27718
27771
  if (finalFolder !== hubFolder) {
27719
27772
  console.log(`Hub folder is now ${finalFolder}`);
@@ -27767,7 +27820,7 @@ async function pushSingleHub(client, hubId, hubFolder, autoConfirm, organization
27767
27820
  console.log("Pushing changes...");
27768
27821
  const result = await client.push(hubId, wireConfig, organizationId);
27769
27822
  printSyncResult(result);
27770
- await syncAfterPush(client, hubId, hubFolder, organizationId);
27823
+ await syncAfterPush(client, hubId, hubFolder, localConfig, organizationId);
27771
27824
  seedScopeIfEmpty("hubs", hubId);
27772
27825
  return true;
27773
27826
  }
@@ -27924,7 +27977,7 @@ async function pushCommand(args2) {
27924
27977
  assertScopeAllowsCreation("hubs", resolution.target.hub.hubName);
27925
27978
  await createAndPushNewHub(client, resolution.target.hub, { autoConfirm, label: label2, organizationId });
27926
27979
  }
27927
- var LOCAL_CHANGE_LIST_CAP;
27980
+ var LOCAL_CHANGE_LIST_CAP, nativeEntryName, entryId, SKIPPABLE_ENTRY_IDENTITY;
27928
27981
  var init_push = __esm({
27929
27982
  "src/commands/push.ts"() {
27930
27983
  "use strict";
@@ -27946,6 +27999,32 @@ var init_push = __esm({
27946
27999
  init_community_workspace();
27947
28000
  init_fs_safety();
27948
28001
  LOCAL_CHANGE_LIST_CAP = 20;
28002
+ nativeEntryName = (entry) => typeof entry === "string" ? entry : entry.name;
28003
+ entryId = (entry) => typeof entry === "string" ? void 0 : entry.id;
28004
+ SKIPPABLE_ENTRY_IDENTITY = {
28005
+ native: {
28006
+ key: (entry) => nativeEntryName(entry),
28007
+ rowKey: (row) => nativeEntryName(row),
28008
+ tool: (entry) => nativeEntryName(entry),
28009
+ label: (entry) => `native tool "${nativeEntryName(entry)}"`
28010
+ },
28011
+ delegation: {
28012
+ key: (entry, pulled) => {
28013
+ const target = entry.type === "agent" ? resolveHeld(entry.target_id, entry.target, pulled.agents) : entry.type === "team" ? resolveHeld(entry.target_id, entry.target, pulled.teams) : entry.target_id;
28014
+ if (target === void 0 && entry.type === "hub") return null;
28015
+ return `${entry.tool}:${entry.type}:${target ?? `name:${entry.target}`}`;
28016
+ },
28017
+ rowKey: (row) => `${row.tool}:${row.type}:${row.target_id ?? `name:${row.target}`}`,
28018
+ tool: (entry) => `${entry.tool}:${entry.type}`,
28019
+ label: (entry) => `${entry.tool} to ${entry.type} "${entry.target}"`
28020
+ },
28021
+ mcp: {
28022
+ key: (entry, pulled) => `${resolveHeld(entry.connection_id, entry.connection, pulled.connections) ?? `name:${entry.connection}`}:${entry.name}`,
28023
+ rowKey: (row) => `${row.connection_id ?? `name:${row.connection}`}:${row.name}`,
28024
+ tool: (entry) => entry.name,
28025
+ label: (entry) => `MCP tool "${entry.name}" on "${entry.connection ?? entry.connection_id}"`
28026
+ }
28027
+ };
27949
28028
  }
27950
28029
  });
27951
28030