@ian2018cs/agenthub 0.1.75 → 0.1.76

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ian2018cs/agenthub",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "description": "A web-based UI for AI Agents",
5
5
  "type": "module",
6
6
  "main": "server/index.js",
@@ -5,7 +5,7 @@ import path from 'path';
5
5
  import { spawn } from 'child_process';
6
6
  import AdmZip from 'adm-zip';
7
7
  import { getUserPaths, getPublicPaths } from '../services/user-directories.js';
8
- import { scanAgents, ensureAgentRepo, incrementPatchVersion, publishAgentToRepo, invalidateAgentCache } from '../services/system-agent-repo.js';
8
+ import { scanAgents, ensureAgentRepo, incrementPatchVersion, publishAgentToRepo } from '../services/system-agent-repo.js';
9
9
  import { ensureSystemRepo, SYSTEM_REPO_URL } from '../services/system-repo.js';
10
10
  import { ensureSystemMcpRepo, SYSTEM_MCP_REPO_URL } from '../services/system-mcp-repo.js';
11
11
  import { addProjectManually, loadProjectConfig, saveProjectConfig } from '../projects.js';
@@ -1310,7 +1310,7 @@ router.post('/submissions/:id/approve', async (req, res) => {
1310
1310
  if (updateAllUsers) {
1311
1311
  // Force-update all users who have this agent installed
1312
1312
  try {
1313
- const freshAgents = await scanAgents(true);
1313
+ const freshAgents = await scanAgents();
1314
1314
  const publishedAgent = freshAgents.find(a =>
1315
1315
  a.dirName === submission.agent_name || a.name === submission.agent_name
1316
1316
  );
@@ -7,13 +7,6 @@ export const SYSTEM_AGENT_REPO_URL = 'git@git.amberweather.com:mcp-server/hupoer
7
7
  export const SYSTEM_AGENT_REPO_OWNER = 'mcp-server';
8
8
  export const SYSTEM_AGENT_REPO_NAME = 'hupoer-agents';
9
9
 
10
- // ─── In-memory cache ──────────────────────────────────────────────────────────
11
- const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
12
- let agentCache = { agents: null, cachedAt: 0 };
13
-
14
- export function invalidateAgentCache() {
15
- agentCache = { agents: null, cachedAt: 0 };
16
- }
17
10
 
18
11
  function runGit(args, cwd = null) {
19
12
  return new Promise((resolve, reject) => {
@@ -42,7 +35,7 @@ function getRepoPath() {
42
35
  }
43
36
 
44
37
  /**
45
- * Ensure the agent repo is cloned locally. If already present, tries to pull.
38
+ * Ensure the agent repo is cloned locally. Does NOT pull; call pullAgentRepo() explicitly.
46
39
  * Returns the path to the local clone.
47
40
  */
48
41
  export async function ensureAgentRepo() {
@@ -50,12 +43,6 @@ export async function ensureAgentRepo() {
50
43
 
51
44
  try {
52
45
  await fs.access(repoPath);
53
- // Already cloned — try to pull latest
54
- try {
55
- await runGit(['pull', '--ff-only'], repoPath);
56
- } catch (err) {
57
- console.log('[AgentRepo] Failed to pull, using existing clone:', err.message);
58
- }
59
46
  } catch {
60
47
  // Not yet cloned
61
48
  await fs.mkdir(path.dirname(repoPath), { recursive: true });
@@ -71,6 +58,19 @@ export async function ensureAgentRepo() {
71
58
  return repoPath;
72
59
  }
73
60
 
61
+ /**
62
+ * Pull latest from remote. Called explicitly on user-triggered refresh.
63
+ */
64
+ export async function pullAgentRepo() {
65
+ const repoPath = getRepoPath();
66
+ try {
67
+ await runGit(['pull', '--ff-only'], repoPath);
68
+ } catch (err) {
69
+ console.log('[AgentRepo] Failed to pull:', err.message);
70
+ throw err;
71
+ }
72
+ }
73
+
74
74
  /**
75
75
  * Parse agent.yaml from an agent directory.
76
76
  * Returns the parsed metadata object or null if invalid.
@@ -161,23 +161,25 @@ async function parseAgentYaml(agentDir) {
161
161
 
162
162
  /**
163
163
  * Scan the agent repo for available agents.
164
- * @param {boolean} force - When true, always git pull and re-scan (bypasses cache).
165
- * When false (default), returns cached result if < 5 min old.
164
+ * @param {boolean} pull - When true, git pull before scanning (e.g. user-triggered refresh).
165
+ * When false (default), read directly from local disk fast path.
166
166
  * Returns array of agent metadata objects.
167
167
  */
168
- export async function scanAgents(force = false) {
169
- // Return cached result if fresh and not forced
170
- if (!force && agentCache.agents !== null && Date.now() - agentCache.cachedAt < CACHE_TTL_MS) {
171
- return agentCache.agents;
172
- }
173
-
168
+ export async function scanAgents(pull = false) {
174
169
  let repoPath;
175
170
  try {
176
171
  repoPath = await ensureAgentRepo();
177
172
  } catch (err) {
178
173
  console.error('[AgentRepo] Could not access agent repo:', err.message);
179
- // Return stale cache on network error rather than empty list
180
- return agentCache.agents ?? [];
174
+ return [];
175
+ }
176
+
177
+ if (pull) {
178
+ try {
179
+ await pullAgentRepo();
180
+ } catch (err) {
181
+ console.warn('[AgentRepo] Pull failed, scanning existing local data:', err.message);
182
+ }
181
183
  }
182
184
 
183
185
  const agents = [];
@@ -211,7 +213,6 @@ export async function scanAgents(force = false) {
211
213
  });
212
214
  }
213
215
 
214
- agentCache = { agents, cachedAt: Date.now() };
215
216
  return agents;
216
217
  }
217
218