@sema-agent/core 1.438.0 → 1.439.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.
@@ -15,6 +15,7 @@ import { delimitUntrusted, inlineUntrusted } from "../core/untrusted-text.js";
15
15
  import { boundedRedactedSummary } from "../core/untrusted-egress.js";
16
16
  import { uuidv7 } from "../internal/harness.js";
17
17
  import { addWorktree } from "../core/git-worktree-env.js";
18
+ import { shellQuote } from "../tools/fs/search.js";
18
19
  import { BG_AGENT_REAP_STOP_ERROR, DURABLE_AGENT_HANDLE_RE, DURABLE_AGENT_HEARTBEAT_MS, normalizeAgentName } from "../core/task-registry.js";
19
20
  import { canAccessAgentRecord } from "../core/background-agent-store.js";
20
21
  import { extractErrorCode } from "../brain/errors.js";
@@ -154,18 +155,29 @@ export function createSubagentWorktreeHelper(baseEnv, repoRoot) {
154
155
  destroy: { value: undefined, writable: true, configurable: true },
155
156
  }),
156
157
  });
157
- handles.set(worktreeDir, () => env.destroy());
158
+ const baseSha = await baseEnv
159
+ .exec("git rev-parse HEAD", { cwd: worktreeDir })
160
+ .then((r) => (r.ok && r.value.exitCode === 0 ? r.value.stdout.trim() : undefined))
161
+ .catch(() => undefined);
162
+ handles.set(worktreeDir, { destroy: () => env.destroy(), baseSha });
158
163
  return { worktreeDir };
159
164
  },
160
165
  async finish(worktreeDir) {
161
- const destroy = handles.get(worktreeDir);
166
+ const handle = handles.get(worktreeDir);
162
167
  handles.delete(worktreeDir);
168
+ let changed = true;
163
169
  const status = await baseEnv.exec("git status --porcelain", { cwd: worktreeDir });
164
- const unchanged = status.ok && status.value.exitCode === 0 && status.value.stdout.trim() === "";
165
- if (!unchanged)
170
+ if (status.ok && status.value.exitCode === 0 && handle?.baseSha !== undefined) {
171
+ const dirtyFiles = status.value.stdout.split("\n").filter((l) => l.trim() !== "").length;
172
+ const ahead = await baseEnv.exec(`git rev-list --count ${shellQuote(`${handle.baseSha}..HEAD`)}`, { cwd: worktreeDir });
173
+ const commits = ahead.ok && ahead.value.exitCode === 0 ? parseInt(ahead.value.stdout.trim(), 10) || 0 : -1;
174
+ if (commits >= 0)
175
+ changed = dirtyFiles > 0 || commits > 0;
176
+ }
177
+ if (changed)
166
178
  return "kept";
167
179
  try {
168
- await destroy?.();
180
+ await handle?.destroy();
169
181
  }
170
182
  catch {
171
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/core",
3
- "version": "1.438.0",
3
+ "version": "1.439.0",
4
4
  "description": "Stateless, task-oriented AI agent core",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",