@sema-agent/core 1.349.0 → 1.351.0

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.
@@ -679,6 +679,8 @@ export async function prepareTask(spec, deps, sessions, resume, _memorySelector,
679
679
  excludeTools: toolFaceSnapshot.exclude,
680
680
  deferTools: toolFaceSnapshot.defer,
681
681
  promptProfile,
682
+ ...(spec.additionalDirectories !== undefined ? { additionalDirectories: Object.freeze([...spec.additionalDirectories]) } : {}),
683
+ ...(spec.envFacts !== undefined ? { envFacts: { ...spec.envFacts } } : {}),
682
684
  getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
683
685
  parentCwd: taskRootPath,
684
686
  ...(centerAdoption !== undefined ? { centerArtifactDigest: centerAdoption.artifact.artifactDigest } : {}),
@@ -690,6 +692,21 @@ export async function prepareTask(spec, deps, sessions, resume, _memorySelector,
690
692
  ...(internals?.parentSessionId !== undefined ? { parentSessionId: internals.parentSessionId } : {}),
691
693
  ...(internals?.explicitAgentName !== undefined ? { spawnedAgentName: internals.explicitAgentName } : {}),
692
694
  ...(deps.rosterStore !== undefined ? { roster: deps.rosterStore } : {}),
695
+ ...(sessions.fork !== undefined
696
+ ? {
697
+ hostSessionFork: async () => {
698
+ const forked = (await sessions.fork(sessionId, spec.principal ?? null)) ?? null;
699
+ if (forked === null)
700
+ return null;
701
+ return {
702
+ sessionId: forked,
703
+ release: async () => {
704
+ await sessions.release?.(forked);
705
+ },
706
+ };
707
+ },
708
+ }
709
+ : {}),
693
710
  sessionId,
694
711
  ...(spec.backgroundScope !== undefined ? { backgroundScope: spec.backgroundScope } : {}),
695
712
  ...(deps.onBackgroundChildEvent ? { onBackgroundChildEvent: deps.onBackgroundChildEvent } : {}),
@@ -942,7 +959,16 @@ export async function prepareTask(spec, deps, sessions, resume, _memorySelector,
942
959
  }
943
960
  }
944
961
  if (spec.envFacts?.scratchpadDir) {
945
- const c = await executionEnv.canonicalPath(spec.envFacts.scratchpadDir);
962
+ let c = await executionEnv.canonicalPath(spec.envFacts.scratchpadDir);
963
+ if (!c.ok && c.error.code === "not_found") {
964
+ const marker = await executionEnv.joinPath([spec.envFacts.scratchpadDir, ".sema-scratchpad"]);
965
+ const exclusiveCreate = executionEnv.writeFileExclusive?.bind(executionEnv);
966
+ if (marker.ok && exclusiveCreate) {
967
+ const w = await exclusiveCreate(marker.value, "");
968
+ if (w.ok || w.error.code === "already_exists")
969
+ c = await executionEnv.canonicalPath(spec.envFacts.scratchpadDir);
970
+ }
971
+ }
946
972
  if (c.ok)
947
973
  additionalRootsCanonical.push(c.value);
948
974
  }
@@ -1033,6 +1059,7 @@ export async function prepareTask(spec, deps, sessions, resume, _memorySelector,
1033
1059
  ...(internals?.explicitAgentName !== undefined ? { senderName: internals.explicitAgentName } : {}),
1034
1060
  ...(internals?.parentRetainLedger !== undefined ? { siblingRetain: internals.parentRetainLedger } : {}),
1035
1061
  ...(deps.rosterStore !== undefined ? { roster: deps.rosterStore } : {}),
1062
+ ...(deps.onBackgroundChildEvent ? { onBackgroundChildEvent: deps.onBackgroundChildEvent } : {}),
1036
1063
  })));
1037
1064
  if (!(spec.tools ?? []).some((t) => t.name === AGENT_TRANSCRIPT_TOOL_NAME)) {
1038
1065
  tools.push(firstPartyOffload(createAgentTranscriptTool({