@agimon-ai/po-git 0.0.0-alpha.153 → 0.0.0-alpha.154

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.
@@ -477,6 +477,15 @@ function progressResult(action, label) {
477
477
  details: { action }
478
478
  };
479
479
  }
480
+ /** Tools that only read, so the checkout cannot have moved under them. */
481
+ const READ_ONLY_TOOLS = /* @__PURE__ */ new Set([
482
+ "read",
483
+ "grep",
484
+ "find",
485
+ "ls",
486
+ "discover",
487
+ "load_skill"
488
+ ]);
480
489
  function createGitSession({ context, host: serverHost, agent, signal }) {
481
490
  if (serverHost.context.directEvents === void 0) throw new Error("Git server plugin requires the session direct event bus.");
482
491
  if (serverHost.context.sessionId === void 0) throw new Error("Git server plugin requires a session identity.");
@@ -517,7 +526,7 @@ function createGitSession({ context, host: serverHost, agent, signal }) {
517
526
  };
518
527
  const hooks = [{
519
528
  event: "tool_execution_end",
520
- handle: changed
529
+ handle: (event, execution) => READ_ONLY_TOOLS.has(event.toolName) ? void 0 : changed(event, execution)
521
530
  }, {
522
531
  event: "agent_settled",
523
532
  handle: changed
@@ -1839,8 +1848,9 @@ const GIT_CHANGES_TYPE = "git_changes";
1839
1848
  * - Apart from the worktrees channel. Worktrees are repository management;
1840
1849
  * this is the session's own code change.
1841
1850
  * - Push, not poll. The session's server plugin publishes a "changed" event
1842
- * after every tool call and settled turn; recounts are coalesced to one in
1843
- * flight plus one rerun, so a burst of tool calls costs at most two.
1851
+ * after every tool call that can write and every settled turn; a recount
1852
+ * waits for a quiet moment, so a burst of tool calls costs one, and runs one
1853
+ * in flight plus one rerun.
1844
1854
  * - One sync command per session. A rebase and a push must never overlap.
1845
1855
  * - Auth is read fresh for each command from the session's workspace, and goes
1846
1856
  * only into that command's git child.
@@ -1849,6 +1859,8 @@ const GIT_CHANGES_TYPE = "git_changes";
1849
1859
  * - Echoing git output. Failures go through classifyGitFailure, which matches
1850
1860
  * stderr and drops it, because a remote URL in it can carry a token.
1851
1861
  */
1862
+ /** Each recount spawns several git processes and walks the worktree for untracked files. */
1863
+ const REFRESH_DELAY_MS = 1500;
1852
1864
  function payloadOf$1(state) {
1853
1865
  return {
1854
1866
  ...state.changes === void 0 ? {} : { changes: state.changes },
@@ -1900,6 +1912,8 @@ function createGitChangesChannel(options = {}) {
1900
1912
  const inFlight = /* @__PURE__ */ new Set();
1901
1913
  const rerun = /* @__PURE__ */ new Set();
1902
1914
  const busy = /* @__PURE__ */ new Set();
1915
+ const delayed = /* @__PURE__ */ new Map();
1916
+ const refreshDelayMs = options.refreshDelayMs ?? REFRESH_DELAY_MS;
1903
1917
  /** The base the session's own worktree was created from, when it has one. */
1904
1918
  const recordedBaseRef = async (scope) => {
1905
1919
  try {
@@ -1945,6 +1959,16 @@ function createGitChangesChannel(options = {}) {
1945
1959
  if (rerun.delete(sessionId)) refresh(sessionId);
1946
1960
  });
1947
1961
  };
1962
+ /** Recounts once the session has been quiet for a moment. */
1963
+ const refreshSoon = (sessionId) => {
1964
+ clearTimeout(delayed.get(sessionId));
1965
+ const timer = setTimeout(() => {
1966
+ delayed.delete(sessionId);
1967
+ refresh(sessionId);
1968
+ }, refreshDelayMs);
1969
+ timer.unref?.();
1970
+ delayed.set(sessionId, timer);
1971
+ };
1948
1972
  const run = async (scope, command) => {
1949
1973
  const workspaceRoot = scope.sessionContext?.workspaceRoot ?? scope.cwd;
1950
1974
  const base = await recordedBaseRef(scope);
@@ -1967,12 +1991,14 @@ function createGitChangesChannel(options = {}) {
1967
1991
  scopes.set(scope.sessionId, scope);
1968
1992
  refresh(scope.sessionId);
1969
1993
  const unsubscribe = host.directEvents.subscribe(require_worktreeOperations.GIT_SESSION_CHANGED_EVENT, scope.sessionId, (payload) => {
1970
- if (require_worktreeOperations.isSessionChangedEvent(payload)) refresh(scope.sessionId);
1994
+ if (require_worktreeOperations.isSessionChangedEvent(payload)) refreshSoon(scope.sessionId);
1971
1995
  });
1972
1996
  subscriptions.set(scope.sessionId, unsubscribe);
1973
1997
  },
1974
1998
  sessionRemoved(sessionId) {
1975
1999
  subscriptions.get(sessionId)?.();
2000
+ clearTimeout(delayed.get(sessionId));
2001
+ delayed.delete(sessionId);
1976
2002
  subscriptions.delete(sessionId);
1977
2003
  scopes.delete(sessionId);
1978
2004
  latest.delete(sessionId);
@@ -1981,6 +2007,8 @@ function createGitChangesChannel(options = {}) {
1981
2007
  },
1982
2008
  close() {
1983
2009
  for (const unsubscribe of subscriptions.values()) unsubscribe();
2010
+ for (const timer of delayed.values()) clearTimeout(timer);
2011
+ delayed.clear();
1984
2012
  subscriptions.clear();
1985
2013
  scopes.clear();
1986
2014
  latest.clear();