@adhdev/daemon-core 0.9.76-rc.25 → 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
@@ -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
  }
@@ -21931,7 +21977,7 @@ var DaemonCommandRouter = class {
21931
21977
  // ─── Mesh Coordinator Launch ───
21932
21978
  case "launch_mesh_coordinator": {
21933
21979
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
21934
- const cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "claude-cli";
21980
+ let cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "";
21935
21981
  if (!meshId) return { success: false, error: "meshId required" };
21936
21982
  try {
21937
21983
  const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
@@ -21959,6 +22005,25 @@ var DaemonCommandRouter = class {
21959
22005
  }
21960
22006
  const workspace = typeof coordinatorNode.workspace === "string" ? coordinatorNode.workspace.trim() : "";
21961
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
+ }
21962
22027
  const providerMeta = this.deps.providerLoader.resolve?.(cliType) || this.deps.providerLoader.getMeta(cliType);
21963
22028
  const coordinatorSetup = resolveMeshCoordinatorSetup({
21964
22029
  provider: providerMeta,
@@ -22273,6 +22338,12 @@ var DaemonStatusReporter = class {
22273
22338
  if (providerType) {
22274
22339
  payload.providerType = providerType;
22275
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
+ }
22276
22347
  if (typeof event.duration === "number" && Number.isFinite(event.duration)) {
22277
22348
  payload.duration = event.duration;
22278
22349
  }
@@ -23520,7 +23591,10 @@ var ProviderInstanceManager = class {
23520
23591
  this.instances.get(id).dispose();
23521
23592
  }
23522
23593
  this.instances.set(id, instance);
23523
- await instance.init(context);
23594
+ await instance.init({
23595
+ ...context,
23596
+ emitProviderEvent: (event) => this.emitProviderEvent(instance.type, id, event)
23597
+ });
23524
23598
  }
23525
23599
  /**
23526
23600
  * Instance remove
@@ -23682,6 +23756,17 @@ var ProviderInstanceManager = class {
23682
23756
  onEvent(listener) {
23683
23757
  this.eventListeners.push(listener);
23684
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
+ }
23685
23770
  emitPendingEvents(providerType, state, extra = {}) {
23686
23771
  for (const event of state.pendingEvents) {
23687
23772
  for (const listener of this.eventListeners) {