neurastream 0.3.26 → 0.3.28

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.
@@ -376,8 +376,12 @@ export function ompRunSource(root: string, cfg: Config): RunSource {
376
376
  };
377
377
  }
378
378
 
379
+ function ompSessionsRoot(cfg: Config): string {
380
+ return ((!cfg.adapter?.name || cfg.adapter.name === "omp") && cfg.adapter?.sessions) || join(cfg.paths.home, ".omp", "agent", "sessions");
381
+ }
382
+
379
383
  export function defaultRunSource(cfg: Config): RunSource {
380
- return ompRunSource(cfg.adapter?.sessions || join(cfg.paths.home, ".omp", "agent", "sessions"), cfg);
384
+ return ompRunSource(ompSessionsRoot(cfg), cfg);
381
385
  }
382
386
 
383
387
  /** The text of a user message: a string, or the text parts joined. */
@@ -444,7 +448,7 @@ export function ompOwnerTurns(root: string, since: number): OwnerTurn[] {
444
448
  }
445
449
 
446
450
  export function defaultOwnerTurns(cfg: Config, since: number): OwnerTurn[] {
447
- return ompOwnerTurns(cfg.adapter?.sessions || join(cfg.paths.home, ".omp", "agent", "sessions"), since);
451
+ return ompOwnerTurns(ompSessionsRoot(cfg), since);
448
452
  }
449
453
 
450
454
  /**
@@ -89,11 +89,17 @@ export function asCtx(v: unknown): HostCtx {
89
89
  // The agent envelope only ever carries kind/id strings (original extensions read just those);
90
90
  // cast fixes the envelope, every field below is checked before use.
91
91
  const agent = r.agent as { kind?: unknown; id?: unknown } | null | undefined;
92
- const out: HostCtx = { hasAgent: agent !== null && agent !== undefined };
93
- if (agent) {
92
+ const hasEnvelope = agent !== null && agent !== undefined;
93
+ const subEnv = process.env.NEURASTREAM_ROLE === "sub";
94
+ const out: HostCtx = { hasAgent: hasEnvelope || subEnv };
95
+ if (hasEnvelope) {
94
96
  if (typeof agent.kind === "string") out.kind = agent.kind;
95
97
  if (typeof agent.id === "string") out.id = agent.id;
96
98
  }
99
+ if (subEnv && (!hasEnvelope || out.kind === "main")) {
100
+ out.kind = "sub";
101
+ out.id = process.env.NEURASTREAM_AGENT_ID || "sub";
102
+ }
97
103
  if (typeof r.cwd === "string") out.cwd = r.cwd;
98
104
  // Harness-injected timer with the original main-guard signature (ctx.setInterval).
99
105
  const interval = r.setInterval as ((cb: () => void, ms: number) => unknown) | undefined;
@@ -130,7 +136,18 @@ export function asRolloverCtx(v: unknown): RolloverCtx | null {
130
136
  };
131
137
  }
132
138
 
139
+ /**
140
+ * Returns whether the current call context belongs to Main rather than a subagent.
141
+ * Always returns false when `NEURASTREAM_ROLE=sub` is active in the environment.
142
+ *
143
+ * Args:
144
+ * ctx (unknown): Untyped harness call context
145
+ *
146
+ * Returns:
147
+ * boolean: True when acting as Main
148
+ */
133
149
  export function isMain(ctx: unknown): boolean {
150
+ if (process.env.NEURASTREAM_ROLE === "sub") return false;
134
151
  const c = asCtx(ctx);
135
152
  return !c.hasAgent || c.kind === "main";
136
153
  }