@cleocode/caamp 2026.4.15 → 2026.4.17

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.
@@ -895,9 +895,24 @@ ${MARKER_END}`;
895
895
  * `spawnCommand` so callers see configuration errors early rather
896
896
  * than at child-exit time.
897
897
  *
898
+ * **Worktree isolation (T380/ADR-041 §D2)** — Pass a
899
+ * {@link SubagentSpawnOptions.worktree} handle to bind the spawned
900
+ * process to a physical git worktree. When set, this method:
901
+ * - Uses `worktree.path` as the child cwd.
902
+ * - Injects `CLEO_WORKTREE_ROOT`, `CLEO_WORKTREE_BRANCH`, and
903
+ * `CLEO_PROJECT_HASH` env vars so the child's path resolvers
904
+ * (including `getProjectRoot()` via `worktreeScope`) direct DB I/O
905
+ * to the correct worktree directory.
906
+ *
907
+ * The spawned worker MUST run the worktree guard defined in
908
+ * `packages/agents/cleo-subagent/AGENT.md §WORKTREE GUARD` as its
909
+ * first Bash call. That guard verifies the cwd binding was applied
910
+ * correctly before any file I/O occurs.
911
+ *
898
912
  * @param task - Subagent task specification.
899
- * @param opts - Per-call streaming and cleanup overrides.
913
+ * @param opts - Per-call streaming, cleanup, and worktree overrides.
900
914
  * @returns A live subagent handle.
915
+ * @task T380
901
916
  */
902
917
  async spawnSubagent(task, opts = {}) {
903
918
  const cmd = this.provider.capabilities.spawn.spawnCommand;
@@ -934,12 +949,19 @@ ${MARKER_END}`;
934
949
  }
935
950
  const startedAt = /* @__PURE__ */ new Date();
936
951
  const startedAtIso = startedAt.toISOString();
952
+ const worktreeCwd = opts.worktree?.path;
953
+ const worktreeEnv = opts.worktree !== void 0 ? {
954
+ CLEO_WORKTREE_ROOT: opts.worktree.path,
955
+ CLEO_WORKTREE_BRANCH: opts.worktree.branch,
956
+ CLEO_PROJECT_HASH: opts.worktree.projectHash
957
+ } : {};
958
+ const resolvedCwd = worktreeCwd ?? opts.cwd ?? task.cwd ?? process.cwd();
937
959
  const sessionHeader = {
938
960
  type: "session",
939
961
  version: 3,
940
962
  id: subagentId,
941
963
  timestamp: startedAtIso,
942
- cwd: opts.cwd ?? task.cwd ?? process.cwd(),
964
+ cwd: resolvedCwd,
943
965
  parentSession: task.parentSessionId ?? null,
944
966
  taskId,
945
967
  childSessionPath
@@ -949,8 +971,8 @@ ${MARKER_END}`;
949
971
  const baseArgs = cmd.slice(1);
950
972
  const args = [...baseArgs, task.prompt];
951
973
  const child = spawn(program, args, {
952
- cwd: opts.cwd ?? task.cwd,
953
- env: { ...process.env, ...task.env, ...opts.env },
974
+ cwd: worktreeCwd ?? opts.cwd ?? task.cwd,
975
+ env: { ...process.env, ...worktreeEnv, ...task.env, ...opts.env },
954
976
  stdio: ["ignore", "pipe", "pipe"]
955
977
  });
956
978
  let stdoutAccum = "";
@@ -4693,4 +4715,4 @@ export {
4693
4715
  discoverSkillsMulti,
4694
4716
  validateSkill
4695
4717
  };
4696
- //# sourceMappingURL=chunk-VD2JJXE7.js.map
4718
+ //# sourceMappingURL=chunk-K7AO3SE7.js.map