@agimon-ai/po-git 0.0.0-alpha.152 → 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.
@@ -470,6 +470,15 @@ function progressResult(action, label) {
470
470
  details: { action }
471
471
  };
472
472
  }
473
+ /** Tools that only read, so the checkout cannot have moved under them. */
474
+ const READ_ONLY_TOOLS = /* @__PURE__ */ new Set([
475
+ "read",
476
+ "grep",
477
+ "find",
478
+ "ls",
479
+ "discover",
480
+ "load_skill"
481
+ ]);
473
482
  function createGitSession({ context, host: serverHost, agent, signal }) {
474
483
  if (serverHost.context.directEvents === void 0) throw new Error("Git server plugin requires the session direct event bus.");
475
484
  if (serverHost.context.sessionId === void 0) throw new Error("Git server plugin requires a session identity.");
@@ -510,7 +519,7 @@ function createGitSession({ context, host: serverHost, agent, signal }) {
510
519
  };
511
520
  const hooks = [{
512
521
  event: "tool_execution_end",
513
- handle: changed
522
+ handle: (event, execution) => READ_ONLY_TOOLS.has(event.toolName) ? void 0 : changed(event, execution)
514
523
  }, {
515
524
  event: "agent_settled",
516
525
  handle: changed
@@ -1832,8 +1841,9 @@ const GIT_CHANGES_TYPE = "git_changes";
1832
1841
  * - Apart from the worktrees channel. Worktrees are repository management;
1833
1842
  * this is the session's own code change.
1834
1843
  * - Push, not poll. The session's server plugin publishes a "changed" event
1835
- * after every tool call and settled turn; recounts are coalesced to one in
1836
- * flight plus one rerun, so a burst of tool calls costs at most two.
1844
+ * after every tool call that can write and every settled turn; a recount
1845
+ * waits for a quiet moment, so a burst of tool calls costs one, and runs one
1846
+ * in flight plus one rerun.
1837
1847
  * - One sync command per session. A rebase and a push must never overlap.
1838
1848
  * - Auth is read fresh for each command from the session's workspace, and goes
1839
1849
  * only into that command's git child.
@@ -1842,6 +1852,8 @@ const GIT_CHANGES_TYPE = "git_changes";
1842
1852
  * - Echoing git output. Failures go through classifyGitFailure, which matches
1843
1853
  * stderr and drops it, because a remote URL in it can carry a token.
1844
1854
  */
1855
+ /** Each recount spawns several git processes and walks the worktree for untracked files. */
1856
+ const REFRESH_DELAY_MS = 1500;
1845
1857
  function payloadOf$1(state) {
1846
1858
  return {
1847
1859
  ...state.changes === void 0 ? {} : { changes: state.changes },
@@ -1893,6 +1905,8 @@ function createGitChangesChannel(options = {}) {
1893
1905
  const inFlight = /* @__PURE__ */ new Set();
1894
1906
  const rerun = /* @__PURE__ */ new Set();
1895
1907
  const busy = /* @__PURE__ */ new Set();
1908
+ const delayed = /* @__PURE__ */ new Map();
1909
+ const refreshDelayMs = options.refreshDelayMs ?? REFRESH_DELAY_MS;
1896
1910
  /** The base the session's own worktree was created from, when it has one. */
1897
1911
  const recordedBaseRef = async (scope) => {
1898
1912
  try {
@@ -1938,6 +1952,16 @@ function createGitChangesChannel(options = {}) {
1938
1952
  if (rerun.delete(sessionId)) refresh(sessionId);
1939
1953
  });
1940
1954
  };
1955
+ /** Recounts once the session has been quiet for a moment. */
1956
+ const refreshSoon = (sessionId) => {
1957
+ clearTimeout(delayed.get(sessionId));
1958
+ const timer = setTimeout(() => {
1959
+ delayed.delete(sessionId);
1960
+ refresh(sessionId);
1961
+ }, refreshDelayMs);
1962
+ timer.unref?.();
1963
+ delayed.set(sessionId, timer);
1964
+ };
1941
1965
  const run = async (scope, command) => {
1942
1966
  const workspaceRoot = scope.sessionContext?.workspaceRoot ?? scope.cwd;
1943
1967
  const base = await recordedBaseRef(scope);
@@ -1960,12 +1984,14 @@ function createGitChangesChannel(options = {}) {
1960
1984
  scopes.set(scope.sessionId, scope);
1961
1985
  refresh(scope.sessionId);
1962
1986
  const unsubscribe = host.directEvents.subscribe(GIT_SESSION_CHANGED_EVENT, scope.sessionId, (payload) => {
1963
- if (isSessionChangedEvent(payload)) refresh(scope.sessionId);
1987
+ if (isSessionChangedEvent(payload)) refreshSoon(scope.sessionId);
1964
1988
  });
1965
1989
  subscriptions.set(scope.sessionId, unsubscribe);
1966
1990
  },
1967
1991
  sessionRemoved(sessionId) {
1968
1992
  subscriptions.get(sessionId)?.();
1993
+ clearTimeout(delayed.get(sessionId));
1994
+ delayed.delete(sessionId);
1969
1995
  subscriptions.delete(sessionId);
1970
1996
  scopes.delete(sessionId);
1971
1997
  latest.delete(sessionId);
@@ -1974,6 +2000,8 @@ function createGitChangesChannel(options = {}) {
1974
2000
  },
1975
2001
  close() {
1976
2002
  for (const unsubscribe of subscriptions.values()) unsubscribe();
2003
+ for (const timer of delayed.values()) clearTimeout(timer);
2004
+ delayed.clear();
1977
2005
  subscriptions.clear();
1978
2006
  scopes.clear();
1979
2007
  latest.clear();