@adhdev/daemon-core 0.9.82-rc.269 → 0.9.82-rc.270

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
@@ -26,6 +26,15 @@ var __copyProps = (to, from, except, desc) => {
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
27
 
28
28
  // src/repo-mesh-types.ts
29
+ function resolveDelegatedWorkerAutoApprove(meshPolicy, nodePolicy) {
30
+ if (typeof nodePolicy?.delegatedWorkerAutoApprove === "boolean") {
31
+ return nodePolicy.delegatedWorkerAutoApprove;
32
+ }
33
+ if (typeof meshPolicy?.delegatedWorkerAutoApprove === "boolean") {
34
+ return meshPolicy.delegatedWorkerAutoApprove;
35
+ }
36
+ return true;
37
+ }
29
38
  var DEFAULT_MESH_POLICY;
30
39
  var init_repo_mesh_types = __esm({
31
40
  "src/repo-mesh-types.ts"() {
@@ -39,6 +48,7 @@ var init_repo_mesh_types = __esm({
39
48
  dirtyWorkspaceBehavior: "warn",
40
49
  maxParallelTasks: 2,
41
50
  spawnedSessionVisibility: "visible",
51
+ delegatedWorkerAutoApprove: true,
42
52
  sessionCleanupOnNodeRemove: "preserve",
43
53
  autoFastForward: { enabled: true },
44
54
  maxTaskRetries: 1
@@ -260,10 +270,10 @@ function readInjected(value) {
260
270
  }
261
271
  function getDaemonBuildInfo() {
262
272
  if (cached) return cached;
263
- const commit = readInjected(true ? "025d8bef81a66e7b44a5ba5d5a04e063db46db4e" : void 0) ?? "unknown";
264
- const commitShort = readInjected(true ? "025d8bef" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
265
- const version = readInjected(true ? "0.9.82-rc.269" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
266
- const builtAt = readInjected(true ? "2026-06-14T22:11:38.134Z" : void 0);
273
+ const commit = readInjected(true ? "7004ebf6e270fbcb990f3fd66542fd77db0eeea0" : void 0) ?? "unknown";
274
+ const commitShort = readInjected(true ? "7004ebf6" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
275
+ const version = readInjected(true ? "0.9.82-rc.270" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
276
+ const builtAt = readInjected(true ? "2026-06-14T23:52:09.523Z" : void 0);
267
277
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
268
278
  return cached;
269
279
  }
@@ -6154,6 +6164,23 @@ function sameDaemonId(a, b) {
6154
6164
  const cb = canonicalDaemonId(b);
6155
6165
  return ca !== "" && ca === cb;
6156
6166
  }
6167
+ function buildMeshWorkerRelayStamp(currentSettings, meshContext) {
6168
+ if (!meshContext) return void 0;
6169
+ const settings = currentSettings && typeof currentSettings === "object" ? currentSettings : {};
6170
+ const stamp = {};
6171
+ const meshId = readNonEmptyString2(meshContext.meshId);
6172
+ if (meshId && !readNonEmptyString2(settings.meshNodeFor)) stamp.meshNodeFor = meshId;
6173
+ const nodeId = readNonEmptyString2(meshContext.nodeId);
6174
+ if (nodeId && !readNonEmptyString2(settings.meshNodeId)) stamp.meshNodeId = nodeId;
6175
+ const coordinatorDaemonId = readNonEmptyString2(meshContext.coordinatorDaemonId);
6176
+ if (coordinatorDaemonId && !readNonEmptyString2(settings.meshCoordinatorDaemonId)) {
6177
+ stamp.meshCoordinatorDaemonId = coordinatorDaemonId;
6178
+ }
6179
+ if ((meshId || nodeId || coordinatorDaemonId) && settings.launchedByCoordinator !== true) {
6180
+ stamp.launchedByCoordinator = true;
6181
+ }
6182
+ return Object.keys(stamp).length > 0 ? stamp : void 0;
6183
+ }
6157
6184
  function resolveEventSessionId(event, fallback) {
6158
6185
  return readNonEmptyString2(event.targetSessionId) || readNonEmptyString2(event.sessionId) || readNonEmptyString2(event.instanceId) || readNonEmptyString2(fallback);
6159
6186
  }
@@ -7469,7 +7496,14 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
7469
7496
  try {
7470
7497
  const inst = components.instanceManager.getInstance(sessionId);
7471
7498
  if (inst && typeof inst.updateSettings === "function") {
7472
- inst.updateSettings({ meshNodeFor: meshId, meshNodeId: nodeId, launchedByCoordinator: true });
7499
+ const localDaemonId = readNonEmptyString2(loadConfig().machineId);
7500
+ inst.updateSettings({
7501
+ meshNodeFor: meshId,
7502
+ meshNodeId: nodeId,
7503
+ launchedByCoordinator: true,
7504
+ autoApprove: resolveDelegatedWorkerAutoApprove(mesh?.policy, node?.policy),
7505
+ ...localDaemonId ? { meshCoordinatorDaemonId: localDaemonId } : {}
7506
+ });
7473
7507
  }
7474
7508
  } catch {
7475
7509
  }
@@ -7758,6 +7792,10 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
7758
7792
  meshNodeFor: meshId,
7759
7793
  meshNodeId: nodeId,
7760
7794
  spawnedSessionVisibility: mesh?.policy?.spawnedSessionVisibility || "hidden",
7795
+ // Coordinator-dispatched worker: auto-approve unless mesh/node policy
7796
+ // opts out (default true). Lands in settingsOverride and beats the
7797
+ // global per-provider-type autoApprove config (see shouldAutoApprove).
7798
+ autoApprove: resolveDelegatedWorkerAutoApprove(mesh?.policy, node?.policy),
7761
7799
  launchedByCoordinator: true,
7762
7800
  autoLaunchedForQueueTaskId: task.id
7763
7801
  }
@@ -8298,6 +8336,9 @@ function injectMeshSystemMessage(components, args) {
8298
8336
  meshNodeFor: args.meshId,
8299
8337
  meshNodeId: node.id,
8300
8338
  spawnedSessionVisibility: mesh?.policy?.spawnedSessionVisibility || "hidden",
8339
+ // Coordinator-dispatched recovery relaunch: same auto-approve
8340
+ // policy as the primary worker launch path.
8341
+ autoApprove: resolveDelegatedWorkerAutoApprove(mesh?.policy, node?.policy),
8301
8342
  launchedByCoordinator: true
8302
8343
  }
8303
8344
  }).catch((e) => LOG.error("MeshRecovery", `Failed to auto-relaunch session for ${node.id}: ${e?.message}`));
@@ -8528,6 +8569,7 @@ var init_mesh_events_coordinator = __esm({
8528
8569
  init_mesh_runtime_store();
8529
8570
  init_mesh_events_pending();
8530
8571
  init_mesh_routing();
8572
+ init_repo_mesh_types();
8531
8573
  init_mesh_events_stale();
8532
8574
  init_mesh_events_utils();
8533
8575
  REMOTE_IDLE_SESSION_TTL_MS = 5 * 60 * 1e3;
@@ -13657,25 +13699,36 @@ function resolveSections(sectionsObj, lines) {
13657
13699
  let to = total;
13658
13700
  if (sec.anchor !== void 0) {
13659
13701
  try {
13660
- const re = new RegExp(sec.anchor, sec.anchor_flags ?? "");
13661
- const prevRe = sec.anchor_context?.prev !== void 0 ? new RegExp(sec.anchor_context.prev, sec.anchor_context.prev_flags ?? "") : null;
13662
- const nextRe = sec.anchor_context?.next !== void 0 ? new RegExp(sec.anchor_context.next, sec.anchor_context.next_flags ?? "") : null;
13663
- const matches = (i) => re.test(lines[i]) && (prevRe === null || i > 0 && prevRe.test(lines[i - 1])) && (nextRe === null || i < total - 1 && nextRe.test(lines[i + 1]));
13702
+ const anchorPatterns = Array.isArray(sec.anchor) ? sec.anchor : [sec.anchor];
13703
+ const sharedCtx = Array.isArray(sec.anchor_context) ? null : sec.anchor_context ?? null;
13704
+ const ctxList = Array.isArray(sec.anchor_context) ? sec.anchor_context : anchorPatterns.map(() => sharedCtx);
13705
+ const candidates = anchorPatterns.map((pattern, k) => {
13706
+ const ctx = ctxList[k] ?? null;
13707
+ return {
13708
+ re: new RegExp(pattern, sec.anchor_flags ?? ""),
13709
+ prevRe: ctx?.prev !== void 0 ? new RegExp(ctx.prev, ctx.prev_flags ?? "") : null,
13710
+ nextRe: ctx?.next !== void 0 ? new RegExp(ctx.next, ctx.next_flags ?? "") : null
13711
+ };
13712
+ });
13713
+ const matchesCandidate = (c, i) => c.re.test(lines[i]) && (c.prevRe === null || i > 0 && c.prevRe.test(lines[i - 1])) && (c.nextRe === null || i < total - 1 && c.nextRe.test(lines[i + 1]));
13664
13714
  let idx = -1;
13665
- if (sec.anchor_last) {
13666
- for (let i = total - 1; i >= 0; i--) {
13667
- if (matches(i)) {
13668
- idx = i;
13669
- break;
13715
+ for (const c of candidates) {
13716
+ if (sec.anchor_last) {
13717
+ for (let i = total - 1; i >= 0; i--) {
13718
+ if (matchesCandidate(c, i)) {
13719
+ idx = i;
13720
+ break;
13721
+ }
13670
13722
  }
13671
- }
13672
- } else {
13673
- for (let i = 0; i < total; i++) {
13674
- if (matches(i)) {
13675
- idx = i;
13676
- break;
13723
+ } else {
13724
+ for (let i = 0; i < total; i++) {
13725
+ if (matchesCandidate(c, i)) {
13726
+ idx = i;
13727
+ break;
13728
+ }
13677
13729
  }
13678
13730
  }
13731
+ if (idx !== -1) break;
13679
13732
  }
13680
13733
  if (idx !== -1) {
13681
13734
  from = idx;
@@ -29146,8 +29199,19 @@ var FsmDriver = class {
29146
29199
  this.stateEnteredAt = now;
29147
29200
  this.prevStateAt = now;
29148
29201
  this.adapter.start();
29202
+ this.scheduleSpawnPrime();
29149
29203
  this.scheduleWakeForState();
29150
29204
  }
29205
+ scheduleSpawnPrime() {
29206
+ const seqs = this.spec.send_on_spawn;
29207
+ if (!Array.isArray(seqs) || seqs.length === 0) return;
29208
+ const delay = Math.max(0, this.spec.send_on_spawn_delay_ms ?? 250);
29209
+ setTimeout(() => {
29210
+ for (const seq of seqs) {
29211
+ if (typeof seq === "string" && seq.length > 0) this.adapter.send_keys(seq);
29212
+ }
29213
+ }, delay);
29214
+ }
29151
29215
  dispatch(cmd) {
29152
29216
  switch (cmd.kind) {
29153
29217
  case "send_message":
@@ -29335,6 +29399,7 @@ var FsmDriver = class {
29335
29399
  this.commitTransition(ev.fired, now, ev);
29336
29400
  this.emitStateChanged(forceEmit);
29337
29401
  this.scheduleWakeForState();
29402
+ this.maybeMarkReady();
29338
29403
  return;
29339
29404
  }
29340
29405
  this.emitStateChanged(forceEmit);
@@ -39309,6 +39374,7 @@ import * as yaml3 from "js-yaml";
39309
39374
  init_mesh_coordinator();
39310
39375
  init_mesh_events();
39311
39376
  init_mesh_routing();
39377
+ init_mesh_events_utils();
39312
39378
  init_mesh_host_ownership();
39313
39379
  init_mesh_fast_forward();
39314
39380
 
@@ -44211,6 +44277,27 @@ ${hintLines.join("\n")}` : "",
44211
44277
  return this.deps.cliManager.handleCliCommand(cmd, args);
44212
44278
  }
44213
44279
  case "agent_command": {
44280
+ {
44281
+ const dispatchSessionId = readStringValue(args?.targetSessionId, args?.sessionId, args?.instanceId);
44282
+ const dispatchMeshContext = args?.meshContext;
44283
+ if (dispatchSessionId && dispatchMeshContext) {
44284
+ try {
44285
+ const inst = this.deps.instanceManager.getInstance(dispatchSessionId);
44286
+ if (inst && typeof inst.updateSettings === "function") {
44287
+ const stamp = buildMeshWorkerRelayStamp(
44288
+ inst.getState?.()?.settings,
44289
+ {
44290
+ meshId: dispatchMeshContext.meshId,
44291
+ nodeId: dispatchMeshContext.nodeId,
44292
+ coordinatorDaemonId: dispatchMeshContext.coordinatorDaemonId
44293
+ }
44294
+ );
44295
+ if (stamp) inst.updateSettings(stamp);
44296
+ }
44297
+ } catch {
44298
+ }
44299
+ }
44300
+ }
44214
44301
  const agentResult = await this.deps.cliManager.handleCliCommand(cmd, args);
44215
44302
  const meshCtx = args?.meshContext;
44216
44303
  const dispatchNodeId = readStringValue(meshCtx?.nodeId);
@@ -55826,6 +55913,7 @@ export {
55826
55913
  resolveChatMessageKind,
55827
55914
  resolveCurrentGlobalInstallSurface,
55828
55915
  resolveDebugRuntimeConfig,
55916
+ resolveDelegatedWorkerAutoApprove,
55829
55917
  resolveDeliveryDecision,
55830
55918
  resolveGitRepository,
55831
55919
  resolveMeshHostStatus,