@adhdev/daemon-core 0.9.76-rc.24 → 0.9.76-rc.26

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.mjs CHANGED
@@ -12296,7 +12296,7 @@ async function handleChatHistory(h, args) {
12296
12296
  }
12297
12297
  }
12298
12298
  async function handleReadChat(h, args) {
12299
- const provider = h.getProvider(args?.agentType);
12299
+ const provider = h.getProvider(args?.agentType || args?.providerType);
12300
12300
  const transport = getTargetTransport(h, provider);
12301
12301
  const historySessionId = getHistorySessionId(h, args);
12302
12302
  const _log = (msg) => LOG.debug("Command", `[read_chat] ${msg}`);
@@ -15260,7 +15260,19 @@ var CliProviderInstance = class {
15260
15260
  }
15261
15261
  }
15262
15262
  pushEvent(event) {
15263
- this.events.push(event);
15263
+ const enrichedEvent = {
15264
+ ...event,
15265
+ instanceId: typeof event.instanceId === "string" && event.instanceId.trim() ? event.instanceId : this.instanceId,
15266
+ targetSessionId: typeof event.targetSessionId === "string" && event.targetSessionId.trim() ? event.targetSessionId : this.instanceId,
15267
+ providerType: typeof event.providerType === "string" && event.providerType.trim() ? event.providerType : this.type,
15268
+ workspaceName: typeof event.workspaceName === "string" && event.workspaceName.trim() ? event.workspaceName : this.workingDir,
15269
+ providerSessionId: typeof event.providerSessionId === "string" && event.providerSessionId.trim() ? event.providerSessionId : this.providerSessionId
15270
+ };
15271
+ if (this.context?.emitProviderEvent) {
15272
+ this.context.emitProviderEvent(enrichedEvent);
15273
+ return;
15274
+ }
15275
+ this.events.push(enrichedEvent);
15264
15276
  }
15265
15277
  flushEvents() {
15266
15278
  const events = [...this.events];
@@ -20987,6 +20999,40 @@ function normalizeReleaseChannel(value) {
20987
20999
  function resolveUpgradeChannel(args) {
20988
21000
  return normalizeReleaseChannel(args?.channel) || normalizeReleaseChannel(args?.updatePolicy?.channel) || normalizeReleaseChannel(args?.npmTag) || normalizeReleaseChannel(loadConfig().updateChannel) || "stable";
20989
21001
  }
21002
+ function readProviderPriorityFromPolicy(policy) {
21003
+ const record = policy && typeof policy === "object" && !Array.isArray(policy) ? policy : {};
21004
+ const raw = record.providerPriority;
21005
+ if (!Array.isArray(raw)) return [];
21006
+ const seen = /* @__PURE__ */ new Set();
21007
+ return raw.map((type) => typeof type === "string" ? type.trim() : "").filter(Boolean).filter((type) => {
21008
+ if (seen.has(type)) return false;
21009
+ seen.add(type);
21010
+ return true;
21011
+ });
21012
+ }
21013
+ async function resolveProviderTypeFromPriority(args) {
21014
+ if (!args.providerPriority.length) {
21015
+ return { error: `Node '${args.nodeId}' has no providerPriority policy; pass cliType explicitly or configure node.policy.providerPriority` };
21016
+ }
21017
+ const failed = [];
21018
+ for (const requestedType of args.providerPriority) {
21019
+ const normalizedType = args.providerLoader.resolveAlias(requestedType);
21020
+ if (!args.providerLoader.isMachineProviderEnabled(normalizedType)) {
21021
+ failed.push(`${requestedType}: disabled`);
21022
+ continue;
21023
+ }
21024
+ const detected = await detectCLI(normalizedType, args.providerLoader, { includeVersion: false });
21025
+ args.providerLoader.setCliDetectionResults([{
21026
+ id: normalizedType,
21027
+ installed: !!detected,
21028
+ path: detected?.path
21029
+ }], false);
21030
+ args.onStatusChange?.();
21031
+ if (detected) return { providerType: normalizedType };
21032
+ failed.push(`${requestedType}: not detected`);
21033
+ }
21034
+ return { error: `No usable provider detected for node '${args.nodeId}' from providerPriority: ${failed.join("; ")}` };
21035
+ }
20990
21036
  function loadYamlModule() {
20991
21037
  return yaml;
20992
21038
  }
@@ -21822,7 +21868,13 @@ var DaemonCommandRouter = class {
21822
21868
  if (!workspace) return { success: false, error: "workspace required" };
21823
21869
  try {
21824
21870
  const { addNode: addNode3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
21825
- const node = addNode3(meshId, { workspace });
21871
+ const providerPriority = Array.isArray(args?.providerPriority) ? args.providerPriority.map((type) => typeof type === "string" ? type.trim() : "").filter(Boolean) : [];
21872
+ const readOnly = args?.readOnly === true;
21873
+ const policy = {
21874
+ ...readOnly ? { readOnly: true } : {},
21875
+ ...providerPriority.length ? { providerPriority } : {}
21876
+ };
21877
+ const node = addNode3(meshId, { workspace, ...policy ? { policy } : {} });
21826
21878
  if (!node) return { success: false, error: "Mesh not found" };
21827
21879
  return { success: true, node };
21828
21880
  } catch (e) {
@@ -21925,7 +21977,7 @@ var DaemonCommandRouter = class {
21925
21977
  // ─── Mesh Coordinator Launch ───
21926
21978
  case "launch_mesh_coordinator": {
21927
21979
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
21928
- const cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "claude-cli";
21980
+ let cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "";
21929
21981
  if (!meshId) return { success: false, error: "meshId required" };
21930
21982
  try {
21931
21983
  const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
@@ -21953,6 +22005,25 @@ var DaemonCommandRouter = class {
21953
22005
  }
21954
22006
  const workspace = typeof coordinatorNode.workspace === "string" ? coordinatorNode.workspace.trim() : "";
21955
22007
  if (!workspace) return { success: false, error: "Coordinator node workspace required", meshId, cliType };
22008
+ if (!cliType) {
22009
+ const resolved = await resolveProviderTypeFromPriority({
22010
+ nodeId: String(coordinatorNode.id || coordinatorNode.nodeId || preferredCoordinatorNodeId || "coordinator"),
22011
+ providerPriority: readProviderPriorityFromPolicy(coordinatorNode.policy),
22012
+ providerLoader: this.deps.providerLoader,
22013
+ onStatusChange: this.deps.onStatusChange
22014
+ });
22015
+ if (!resolved.providerType) {
22016
+ return {
22017
+ success: false,
22018
+ code: "mesh_coordinator_provider_priority_unusable",
22019
+ error: resolved.error || "No usable provider found from node providerPriority",
22020
+ meshId,
22021
+ cliType,
22022
+ workspace
22023
+ };
22024
+ }
22025
+ cliType = resolved.providerType;
22026
+ }
21956
22027
  const providerMeta = this.deps.providerLoader.resolve?.(cliType) || this.deps.providerLoader.getMeta(cliType);
21957
22028
  const coordinatorSetup = resolveMeshCoordinatorSetup({
21958
22029
  provider: providerMeta,
@@ -22267,6 +22338,12 @@ var DaemonStatusReporter = class {
22267
22338
  if (providerType) {
22268
22339
  payload.providerType = providerType;
22269
22340
  }
22341
+ if (typeof event.providerSessionId === "string" && event.providerSessionId.trim()) {
22342
+ payload.providerSessionId = event.providerSessionId.trim();
22343
+ }
22344
+ if (typeof event.workspaceName === "string" && event.workspaceName.trim()) {
22345
+ payload.workspaceName = event.workspaceName.trim();
22346
+ }
22270
22347
  if (typeof event.duration === "number" && Number.isFinite(event.duration)) {
22271
22348
  payload.duration = event.duration;
22272
22349
  }
@@ -23514,7 +23591,10 @@ var ProviderInstanceManager = class {
23514
23591
  this.instances.get(id).dispose();
23515
23592
  }
23516
23593
  this.instances.set(id, instance);
23517
- await instance.init(context);
23594
+ await instance.init({
23595
+ ...context,
23596
+ emitProviderEvent: (event) => this.emitProviderEvent(instance.type, id, event)
23597
+ });
23518
23598
  }
23519
23599
  /**
23520
23600
  * Instance remove
@@ -23676,6 +23756,17 @@ var ProviderInstanceManager = class {
23676
23756
  onEvent(listener) {
23677
23757
  this.eventListeners.push(listener);
23678
23758
  }
23759
+ emitProviderEvent(providerType, instanceId, event) {
23760
+ const payload = {
23761
+ ...event,
23762
+ providerType,
23763
+ instanceId: typeof event.instanceId === "string" && event.instanceId.trim() ? event.instanceId : instanceId,
23764
+ targetSessionId: typeof event.targetSessionId === "string" && event.targetSessionId.trim() ? event.targetSessionId : instanceId
23765
+ };
23766
+ for (const listener of this.eventListeners) {
23767
+ listener(payload);
23768
+ }
23769
+ }
23679
23770
  emitPendingEvents(providerType, state, extra = {}) {
23680
23771
  for (const event of state.pendingEvents) {
23681
23772
  for (const listener of this.eventListeners) {