@agent-team-foundation/first-tree-hub 0.2.0 → 0.3.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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { A as loadRuntimeConfig, B as readConfigFile, C as stopPostgres, D as FirstTreeHubSDK, E as AgentSlot, F as agentConfigSchema, H as resetConfigMeta, I as clientConfigSchema, L as getConfigValue, M as createAdminUser, O as SdkError, P as DEFAULT_CONFIG_DIR, R as initConfig, T as AgentRuntime, U as serverConfigSchema, V as resetConfig, W as setConfigValue, _ as checkWebSocket, a as runMigrations, c as checkClientConfig, d as checkDocker, f as checkGitHubToken, g as checkServerReachable, h as checkServerHealth, i as promptMissingFields, j as registerBuiltinHandlers, k as getHandlerFactory, l as checkContextTreeRepo, m as checkServerConfig, o as checkAgentConfigs, p as checkNodeVersion, r as promptAddAgent, s as checkAgentTokens, t as startServer, u as checkDatabase, v as printResults, w as ClientRuntime, z as loadAgents } from "../core-CD3xEbyB.mjs";
2
+ import { A as SessionRegistry, B as clientConfigSchema, C as stopPostgres, D as DEFAULT_WORKSPACE_TTL_MS, E as AgentSlot, F as createAdminUser, G as resetConfig, H as initConfig, J as setConfigValue, K as resetConfigMeta, L as DEFAULT_CONFIG_DIR, M as getHandlerFactory, N as loadRuntimeConfig, O as FirstTreeHubSDK, P as registerBuiltinHandlers, R as DEFAULT_DATA_DIR, T as AgentRuntime, U as loadAgents, V as getConfigValue, W as readConfigFile, _ as checkWebSocket, a as runMigrations, c as checkClientConfig, d as checkDocker, f as checkGitHubToken, g as checkServerReachable, h as checkServerHealth, i as promptMissingFields, j as cleanWorkspaces, k as SdkError, l as checkContextTreeRepo, m as checkServerConfig, o as checkAgentConfigs, p as checkNodeVersion, q as serverConfigSchema, r as promptAddAgent, s as checkAgentTokens, t as startServer, u as checkDatabase, v as printResults, w as ClientRuntime, z as agentConfigSchema } from "../core-uG-Hkr9K.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { Command } from "commander";
5
- import { existsSync, mkdirSync, rmSync } from "node:fs";
5
+ import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
6
6
  import { join } from "node:path";
7
7
  //#region src/commands/admin.ts
8
8
  function registerAdminCommands(program) {
@@ -237,7 +237,7 @@ function registerClientCommands(program) {
237
237
  process.exit(1);
238
238
  }
239
239
  });
240
- client.command("remove <name>").description("Remove an agent instance").action((name) => {
240
+ client.command("remove <name>").description("Remove an agent instance and its runtime data").action((name) => {
241
241
  const agentDir = join(DEFAULT_CONFIG_DIR, "agents", name);
242
242
  if (!existsSync(agentDir)) {
243
243
  process.stderr.write(` Agent "${name}" not found.\n`);
@@ -247,6 +247,11 @@ function registerClientCommands(program) {
247
247
  recursive: true,
248
248
  force: true
249
249
  });
250
+ rmSync(join(DEFAULT_DATA_DIR, "workspaces", name), {
251
+ recursive: true,
252
+ force: true
253
+ });
254
+ rmSync(join(DEFAULT_DATA_DIR, "sessions", `${name}.json`), { force: true });
250
255
  process.stderr.write(` Agent "${name}" removed.\n`);
251
256
  });
252
257
  client.command("list").description("List configured agents").action(() => {
@@ -268,6 +273,28 @@ function registerClientCommands(program) {
268
273
  process.stderr.write(" No agents configured.\n");
269
274
  }
270
275
  });
276
+ client.command("workspace").description("Manage agent workspaces").command("clean [agent-name]").description("Remove stale workspace directories (older than TTL with no active session)").option("--ttl <days>", "TTL in days", String(DEFAULT_WORKSPACE_TTL_MS / (1440 * 60 * 1e3))).action((agentName, options) => {
277
+ const defaultDays = DEFAULT_WORKSPACE_TTL_MS / (1440 * 60 * 1e3);
278
+ const ttlMs = Number.parseInt(options?.ttl ?? String(defaultDays), 10) * 24 * 60 * 60 * 1e3;
279
+ const workspacesDir = join(DEFAULT_DATA_DIR, "workspaces");
280
+ if (!existsSync(workspacesDir)) {
281
+ process.stderr.write(" No workspaces found.\n");
282
+ return;
283
+ }
284
+ const agentNames = agentName ? [agentName] : readdirSync(workspacesDir);
285
+ let totalRemoved = 0;
286
+ for (const name of agentNames) {
287
+ const agentWorkspaceRoot = join(workspacesDir, name);
288
+ if (!existsSync(agentWorkspaceRoot)) continue;
289
+ const persisted = new SessionRegistry(join(DEFAULT_DATA_DIR, "sessions", `${name}.json`)).load();
290
+ const activeChatIds = /* @__PURE__ */ new Set();
291
+ for (const [chatId, data] of persisted) if (data.status !== "evicted") activeChatIds.add(chatId);
292
+ const removed = cleanWorkspaces(agentWorkspaceRoot, activeChatIds, ttlMs);
293
+ totalRemoved += removed.length;
294
+ for (const chatId of removed) process.stderr.write(` Removed: ${name}/${chatId}\n`);
295
+ }
296
+ process.stderr.write(` ${totalRemoved} workspace(s) cleaned.\n`);
297
+ });
271
298
  }
272
299
  //#endregion
273
300
  //#region src/commands/config.ts