@borgee/agents-host 0.2.0 → 0.2.2

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.
@@ -0,0 +1,46 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { homedir } from 'node:os';
3
+ import { join, resolve } from 'node:path';
4
+ const SINGLE_AGENT_HOME_ROOT = '.borgee';
5
+ const AGENTS_HOST_ROOT = 'agents-host';
6
+ const SINGLE_AGENT_NAMESPACE = 'single-agent';
7
+ const MANAGED_STATE_DIRNAME = '.state';
8
+ const STATE_ROOT_LABEL_MAX_LENGTH = 48;
9
+ function encodeSegment(value) {
10
+ return encodeURIComponent(value);
11
+ }
12
+ function sanitizeStateRootLabel(agentKey) {
13
+ const sanitized = encodeSegment(agentKey)
14
+ .toLowerCase()
15
+ .replace(/%/g, '-')
16
+ .replace(/[^a-z0-9._-]+/g, '-')
17
+ .replace(/-+/g, '-')
18
+ .replace(/^-|-$/g, '')
19
+ .slice(0, STATE_ROOT_LABEL_MAX_LENGTH);
20
+ return sanitized.length > 0 ? sanitized : 'agent';
21
+ }
22
+ function hashStateRootKey(agentKey) {
23
+ return createHash('sha256').update(agentKey).digest('hex').slice(0, 12);
24
+ }
25
+ export function resolveSingleAgentStateRoot(env = process.env, resolvedHomeDir = homedir()) {
26
+ const home = env.HOME?.trim() || resolvedHomeDir.trim();
27
+ if (!home) {
28
+ throw new Error('Unable to resolve a user home directory for agents-host state');
29
+ }
30
+ return join(home, SINGLE_AGENT_HOME_ROOT, AGENTS_HOST_ROOT, SINGLE_AGENT_NAMESPACE);
31
+ }
32
+ export function resolveManagedStateRoot(rootPath) {
33
+ return join(resolve(rootPath), MANAGED_STATE_DIRNAME);
34
+ }
35
+ export function resolveLocalConfigAgentStateRoot(rootPath, agentKey) {
36
+ return join(resolveManagedStateRoot(rootPath), `${sanitizeStateRootLabel(agentKey)}-${hashStateRootKey(agentKey)}`);
37
+ }
38
+ export function resolveAgentCursorPath(stateRootDir, agentId) {
39
+ return join(stateRootDir, `bpp-cursor-${encodeSegment(agentId)}.json`);
40
+ }
41
+ export function resolveClaudeSessionMapPath(stateRootDir, agentId) {
42
+ return join(stateRootDir, `claude-channel-sessions-${encodeSegment(agentId)}.json`);
43
+ }
44
+ export function resolveCopilotSessionMapPath(stateRootDir, agentId) {
45
+ return join(stateRootDir, `copilot-channel-sessions-${encodeSegment(agentId)}.json`);
46
+ }
package/dist/types.d.ts CHANGED
@@ -8,6 +8,8 @@ export interface ProviderCommandConfig {
8
8
  }
9
9
  export interface ProviderRuntimeConfig extends ProviderCommandConfig {
10
10
  provider: ProviderKind;
11
+ stateRootDir: string;
12
+ resolveStableAgentId?: () => string | undefined;
11
13
  }
12
14
  export interface HostedAgentConfig {
13
15
  agentApiKey: string;
@@ -16,6 +18,7 @@ export interface HostedAgentConfig {
16
18
  }
17
19
  export interface AgentsHostConfig extends ProviderCommandConfig {
18
20
  borgeeBaseUrl: string;
21
+ stateRootDir: string;
19
22
  agent: HostedAgentConfig;
20
23
  }
21
24
  export interface LocalHostConfigFile {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@borgee/agents-host",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -8,7 +8,7 @@
8
8
  "type": "module",
9
9
  "description": "Minimal local agents host: connects a local Claude/Copilot CLI to a Borgee agent over @borgee/plugin-sdk",
10
10
  "bin": {
11
- "agents-host": "./dist/cli.js"
11
+ "agents-host": "dist/cli.js"
12
12
  },
13
13
  "files": [
14
14
  "dist",
@@ -20,19 +20,6 @@
20
20
  "directory": "packages/agents-host"
21
21
  },
22
22
  "license": "MIT",
23
- "dependencies": {
24
- "@agentclientprotocol/sdk": "^1.2.1",
25
- "cross-spawn": "^7.0.6",
26
- "yaml": "^2.8.1",
27
- "@borgee/plugin-sdk": "0.1.2"
28
- },
29
- "devDependencies": {
30
- "@types/cross-spawn": "^6.0.6",
31
- "@types/node": "^24.3.0",
32
- "tsx": "^4.20.5",
33
- "typescript": "^5.9.3",
34
- "vitest": "^4.1.5"
35
- },
36
23
  "scripts": {
37
24
  "predev": "pnpm --filter @borgee/plugin-sdk build",
38
25
  "dev": "tsx src/index.ts",
@@ -46,5 +33,18 @@
46
33
  "pretest": "pnpm --filter @borgee/plugin-sdk build",
47
34
  "test": "vitest run --testTimeout=10000",
48
35
  "pretypecheck": "pnpm --filter @borgee/plugin-sdk build"
36
+ },
37
+ "dependencies": {
38
+ "@agentclientprotocol/sdk": "^1.2.1",
39
+ "@borgee/plugin-sdk": "0.1.5",
40
+ "cross-spawn": "^7.0.6",
41
+ "yaml": "^2.8.1"
42
+ },
43
+ "devDependencies": {
44
+ "@types/cross-spawn": "^6.0.6",
45
+ "@types/node": "^24.3.0",
46
+ "tsx": "^4.20.5",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.1.5"
49
49
  }
50
- }
50
+ }