agent-relay 3.1.10 → 3.1.12

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.
Files changed (93) hide show
  1. package/bin/agent-relay-broker-darwin-arm64 +0 -0
  2. package/bin/agent-relay-broker-darwin-x64 +0 -0
  3. package/bin/agent-relay-broker-linux-arm64 +0 -0
  4. package/bin/agent-relay-broker-linux-x64 +0 -0
  5. package/dist/index.cjs +2 -2
  6. package/dist/src/cli/bootstrap.d.ts.map +1 -1
  7. package/dist/src/cli/bootstrap.js +2 -0
  8. package/dist/src/cli/bootstrap.js.map +1 -1
  9. package/dist/src/cli/commands/connect.d.ts +3 -0
  10. package/dist/src/cli/commands/connect.d.ts.map +1 -0
  11. package/dist/src/cli/commands/connect.js +18 -0
  12. package/dist/src/cli/commands/connect.js.map +1 -0
  13. package/dist/src/cli/lib/auth-ssh.d.ts.map +1 -1
  14. package/dist/src/cli/lib/auth-ssh.js +22 -270
  15. package/dist/src/cli/lib/auth-ssh.js.map +1 -1
  16. package/dist/src/cli/lib/broker-lifecycle.d.ts.map +1 -1
  17. package/dist/src/cli/lib/broker-lifecycle.js +33 -0
  18. package/dist/src/cli/lib/broker-lifecycle.js.map +1 -1
  19. package/dist/src/cli/lib/connect-daytona.d.ts +15 -0
  20. package/dist/src/cli/lib/connect-daytona.d.ts.map +1 -0
  21. package/dist/src/cli/lib/connect-daytona.js +217 -0
  22. package/dist/src/cli/lib/connect-daytona.js.map +1 -0
  23. package/dist/src/cli/lib/ssh-interactive.d.ts +41 -0
  24. package/dist/src/cli/lib/ssh-interactive.d.ts.map +1 -0
  25. package/dist/src/cli/lib/ssh-interactive.js +320 -0
  26. package/dist/src/cli/lib/ssh-interactive.js.map +1 -0
  27. package/install.sh +2 -1
  28. package/package.json +13 -10
  29. package/packages/acp-bridge/package.json +2 -2
  30. package/packages/config/dist/cli-auth-config.d.ts +2 -0
  31. package/packages/config/dist/cli-auth-config.d.ts.map +1 -1
  32. package/packages/config/dist/cli-auth-config.js +1 -0
  33. package/packages/config/dist/cli-auth-config.js.map +1 -1
  34. package/packages/config/package.json +1 -1
  35. package/packages/config/src/cli-auth-config.ts +3 -0
  36. package/packages/hooks/package.json +4 -4
  37. package/packages/memory/package.json +2 -2
  38. package/packages/openclaw/dist/__tests__/gateway-control.test.js +13 -13
  39. package/packages/openclaw/dist/__tests__/gateway-control.test.js.map +1 -1
  40. package/packages/openclaw/dist/__tests__/gateway-poll-fallback.test.d.ts +2 -0
  41. package/packages/openclaw/dist/__tests__/gateway-poll-fallback.test.d.ts.map +1 -0
  42. package/packages/openclaw/dist/__tests__/gateway-poll-fallback.test.js +369 -0
  43. package/packages/openclaw/dist/__tests__/gateway-poll-fallback.test.js.map +1 -0
  44. package/packages/openclaw/dist/__tests__/gateway-threads.test.js +57 -16
  45. package/packages/openclaw/dist/__tests__/gateway-threads.test.js.map +1 -1
  46. package/packages/openclaw/dist/__tests__/ws-client.test.js +2 -0
  47. package/packages/openclaw/dist/__tests__/ws-client.test.js.map +1 -1
  48. package/packages/openclaw/dist/config.d.ts +2 -0
  49. package/packages/openclaw/dist/config.d.ts.map +1 -1
  50. package/packages/openclaw/dist/config.js +99 -12
  51. package/packages/openclaw/dist/config.js.map +1 -1
  52. package/packages/openclaw/dist/gateway.d.ts +56 -2
  53. package/packages/openclaw/dist/gateway.d.ts.map +1 -1
  54. package/packages/openclaw/dist/gateway.js +819 -127
  55. package/packages/openclaw/dist/gateway.js.map +1 -1
  56. package/packages/openclaw/dist/runtime/openclaw-config.d.ts +2 -0
  57. package/packages/openclaw/dist/runtime/openclaw-config.d.ts.map +1 -1
  58. package/packages/openclaw/dist/runtime/openclaw-config.js +1 -1
  59. package/packages/openclaw/dist/runtime/openclaw-config.js.map +1 -1
  60. package/packages/openclaw/dist/runtime/setup.d.ts +0 -2
  61. package/packages/openclaw/dist/runtime/setup.d.ts.map +1 -1
  62. package/packages/openclaw/dist/runtime/setup.js +53 -8
  63. package/packages/openclaw/dist/runtime/setup.js.map +1 -1
  64. package/packages/openclaw/dist/types.d.ts +28 -0
  65. package/packages/openclaw/dist/types.d.ts.map +1 -1
  66. package/packages/openclaw/package.json +2 -2
  67. package/packages/openclaw/skill/SKILL.md +150 -44
  68. package/packages/openclaw/src/__tests__/gateway-control.test.ts +14 -14
  69. package/packages/openclaw/src/__tests__/gateway-poll-fallback.test.ts +467 -0
  70. package/packages/openclaw/src/__tests__/gateway-threads.test.ts +73 -23
  71. package/packages/openclaw/src/__tests__/ws-client.test.ts +71 -51
  72. package/packages/openclaw/src/config.ts +121 -12
  73. package/packages/openclaw/src/gateway.ts +1155 -252
  74. package/packages/openclaw/src/runtime/openclaw-config.ts +3 -1
  75. package/packages/openclaw/src/runtime/setup.ts +57 -16
  76. package/packages/openclaw/src/types.ts +31 -0
  77. package/packages/openclaw/test/vitest.setup.ts +1 -0
  78. package/packages/policy/package.json +2 -2
  79. package/packages/sdk/dist/__tests__/unit.test.js +131 -129
  80. package/packages/sdk/dist/__tests__/unit.test.js.map +1 -1
  81. package/packages/sdk/dist/relay.js +1 -1
  82. package/packages/sdk/dist/workflows/runner.d.ts.map +1 -1
  83. package/packages/sdk/dist/workflows/runner.js +5 -3
  84. package/packages/sdk/dist/workflows/runner.js.map +1 -1
  85. package/packages/sdk/package.json +2 -2
  86. package/packages/sdk/src/__tests__/unit.test.ts +142 -157
  87. package/packages/sdk/src/relay.ts +1 -1
  88. package/packages/sdk/src/workflows/runner.ts +12 -9
  89. package/packages/sdk-py/pyproject.toml +1 -1
  90. package/packages/telemetry/package.json +1 -1
  91. package/packages/trajectory/package.json +2 -2
  92. package/packages/user-directory/package.json +2 -2
  93. package/packages/utils/package.json +2 -2
@@ -8,6 +8,8 @@ export interface OpenClawConfigOptions {
8
8
  openclawHome?: string;
9
9
  /** Default workspace path (default: ~/.openclaw/workspace). */
10
10
  workspacePath?: string;
11
+ /** Config filename override (e.g. 'clawdbot.json'). Defaults to 'openclaw.json'. */
12
+ configFilename?: string;
11
13
  /** MCP servers to include. Keys are server names, values are MCP server configs. */
12
14
  mcpServers?: Record<string, { command: string; args: string[]; env?: Record<string, string> }>;
13
15
  }
@@ -20,7 +22,7 @@ export async function writeOpenClawConfig(options: OpenClawConfigOptions): Promi
20
22
  const home = options.openclawHome ?? join(process.env.HOME ?? '/home/node', '.openclaw');
21
23
  await mkdir(home, { recursive: true });
22
24
 
23
- const configPath = join(home, 'openclaw.json');
25
+ const configPath = join(home, options.configFilename ?? 'openclaw.json');
24
26
  let config: Record<string, unknown> = {};
25
27
 
26
28
  try {
@@ -1,16 +1,13 @@
1
1
  import { join } from 'node:path';
2
- import { unlink } from 'node:fs/promises';
2
+ import { readdir, unlink } from 'node:fs/promises';
3
3
  import { existsSync } from 'node:fs';
4
4
 
5
5
  import { normalizeModelRef } from '../identity/model.js';
6
6
  import { convertCodexAuth } from '../auth/converter.js';
7
7
  import { writeOpenClawConfig } from './openclaw-config.js';
8
8
  import { patchOpenClawDist, clearJitCache } from './patch.js';
9
- import {
10
- generateSoulMd,
11
- generateIdentityMd,
12
- ensureWorkspace,
13
- } from '../identity/files.js';
9
+ import { ensureWorkspace } from '../identity/files.js';
10
+ import { openclawHome as resolveOpenclawHome, openclawConfigFilename } from '../config.js';
14
11
 
15
12
  export interface RuntimeSetupOptions {
16
13
  /** Raw model string (e.g. "gpt-5.3-codex"). Defaults to env OPENCLAW_MODEL. */
@@ -23,8 +20,6 @@ export interface RuntimeSetupOptions {
23
20
  role?: string;
24
21
  /** OpenClaw dist directory for patching. Defaults to /usr/lib/node_modules/openclaw/dist. */
25
22
  openclawDistDir?: string;
26
- /** Home directory. Defaults to $HOME. */
27
- homeDir?: string;
28
23
  }
29
24
 
30
25
  /**
@@ -38,7 +33,8 @@ export async function runtimeSetup(options: RuntimeSetupOptions = {}): Promise<{
38
33
  agentName: string;
39
34
  workspaceId: string;
40
35
  }> {
41
- const home = options.homeDir ?? process.env.HOME ?? '/home/node';
36
+ // Resolve OpenClaw home using canonical precedence (OPENCLAW_CONFIG_PATH > OPENCLAW_HOME > probe)
37
+ const ocHome = resolveOpenclawHome();
42
38
  const model = options.model ?? process.env.OPENCLAW_MODEL ?? 'openai-codex/gpt-5.3-codex';
43
39
  const name = options.name ?? process.env.OPENCLAW_NAME ?? process.env.AGENT_NAME ?? 'agent';
44
40
  const workspaceId = options.workspaceId ?? process.env.OPENCLAW_WORKSPACE_ID ?? 'unknown';
@@ -47,8 +43,8 @@ export async function runtimeSetup(options: RuntimeSetupOptions = {}): Promise<{
47
43
  const distDirCandidates = options.openclawDistDir
48
44
  ? [options.openclawDistDir]
49
45
  : [
50
- '/usr/lib/node_modules/openclaw/dist', // Global npm (ClawRunner sandbox)
51
- '/app/dist', // Vanilla Docker image
46
+ '/usr/lib/node_modules/openclaw/dist', // Global npm (ClawRunner sandbox)
47
+ '/app/dist', // Vanilla Docker image
52
48
  '/usr/local/lib/node_modules/openclaw/dist', // Global npm (macOS/other)
53
49
  ];
54
50
  const distDir = distDirCandidates.find((d) => existsSync(d)) ?? distDirCandidates[0];
@@ -57,14 +53,15 @@ export async function runtimeSetup(options: RuntimeSetupOptions = {}): Promise<{
57
53
  const { preferredProvider } = await convertCodexAuth();
58
54
  const modelRef = normalizeModelRef(model, preferredProvider);
59
55
 
60
- // 2. Write openclaw.json config
56
+ // 2. Write config (openclaw.json or clawdbot.json depending on variant)
61
57
  await writeOpenClawConfig({
62
58
  modelRef,
63
- openclawHome: join(home, '.openclaw'),
59
+ openclawHome: ocHome,
60
+ configFilename: openclawConfigFilename(ocHome),
64
61
  });
65
62
 
66
63
  // 3. Write identity files in workspace
67
- const wsDir = join(home, '.openclaw', 'workspace');
64
+ const wsDir = join(ocHome, 'workspace');
68
65
  await ensureWorkspace({
69
66
  workspacePath: wsDir,
70
67
  workspaceId,
@@ -79,11 +76,55 @@ export async function runtimeSetup(options: RuntimeSetupOptions = {}): Promise<{
79
76
  await unlink(bootstrapPath);
80
77
  }
81
78
 
82
- // 4. Patch OpenClaw dist
79
+ // 4. Remove stale session lock files from previous runs
80
+ await clearStaleLocks(ocHome);
81
+
82
+ // 5. Patch OpenClaw dist
83
83
  await patchOpenClawDist(distDir, modelRef);
84
84
 
85
- // 5. Clear JIT cache
85
+ // 6. Clear JIT cache
86
86
  await clearJitCache();
87
87
 
88
88
  return { modelRef, agentName: name, workspaceId };
89
89
  }
90
+
91
+ /**
92
+ * Remove stale .lock files from OpenClaw session directories.
93
+ *
94
+ * OpenClaw creates per-session lock files at ~/.openclaw/agents/<name>/sessions/<uuid>.jsonl.lock.
95
+ * If the process dies uncleanly, stale locks prevent new sessions from starting
96
+ * ("session file locked (timeout 10000ms)"). Since runtime-setup runs before the
97
+ * gateway starts, no legitimate locks should exist — all locks are stale.
98
+ */
99
+ async function clearStaleLocks(openclawHome: string): Promise<void> {
100
+ const agentsDir = join(openclawHome, 'agents');
101
+ if (!existsSync(agentsDir)) return;
102
+
103
+ try {
104
+ const agentNames = await readdir(agentsDir, { withFileTypes: true });
105
+ let cleared = 0;
106
+
107
+ for (const agent of agentNames) {
108
+ if (!agent.isDirectory()) continue;
109
+ const sessionsDir = join(agentsDir, agent.name, 'sessions');
110
+ if (!existsSync(sessionsDir)) continue;
111
+
112
+ const files = await readdir(sessionsDir);
113
+ for (const file of files) {
114
+ if (file.endsWith('.lock')) {
115
+ await unlink(join(sessionsDir, file))
116
+ .then(() => {
117
+ cleared++;
118
+ })
119
+ .catch(() => {});
120
+ }
121
+ }
122
+ }
123
+
124
+ if (cleared > 0) {
125
+ process.stderr.write(`[runtime-setup] Cleared ${cleared} stale session lock(s)\n`);
126
+ }
127
+ } catch {
128
+ // Non-fatal — session lock cleanup is best-effort
129
+ }
130
+ }
@@ -1,6 +1,35 @@
1
1
  /** Default port for the local OpenClaw gateway WebSocket API. */
2
2
  export const DEFAULT_OPENCLAW_GATEWAY_PORT = 18789;
3
3
 
4
+ export interface GatewayPollFallbackProbeConfig {
5
+ /** Whether background WS recovery probes should run while polling. */
6
+ enabled?: boolean;
7
+ /** How often to attempt WS recovery probes. */
8
+ intervalMs?: number;
9
+ /** How long WS must stay healthy before promotion back to WS. */
10
+ stableGraceMs?: number;
11
+ }
12
+
13
+ export interface GatewayPollFallbackConfig {
14
+ /** Enable HTTP long-poll fallback when Relaycast WS is unhealthy. */
15
+ enabled?: boolean;
16
+ /** Consecutive WS failures before switching to poll mode. */
17
+ wsFailureThreshold?: number;
18
+ /** Long-poll wait time in seconds. */
19
+ timeoutSeconds?: number;
20
+ /** Maximum events to request per poll. */
21
+ limit?: number;
22
+ /** Initial cursor used when no persisted cursor exists yet. */
23
+ initialCursor?: string;
24
+ /** Background WS recovery probe settings. */
25
+ probeWs?: GatewayPollFallbackProbeConfig;
26
+ }
27
+
28
+ export interface GatewayTransportConfig {
29
+ /** WS -> HTTP long-poll fallback settings for inbound Relaycast events. */
30
+ pollFallback?: GatewayPollFallbackConfig;
31
+ }
32
+
4
33
  export interface GatewayConfig {
5
34
  /** Relaycast workspace API key (rk_live_*). */
6
35
  apiKey: string;
@@ -14,6 +43,8 @@ export interface GatewayConfig {
14
43
  openclawGatewayToken?: string;
15
44
  /** OpenClaw gateway port (default: 18789). */
16
45
  openclawGatewayPort?: number;
46
+ /** Optional inbound transport tuning. */
47
+ transport?: GatewayTransportConfig;
17
48
  }
18
49
 
19
50
  export interface InboundMessage {
@@ -0,0 +1 @@
1
+ // Package-local Vitest setup shim.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/policy",
3
- "version": "3.1.10",
3
+ "version": "3.1.12",
4
4
  "description": "Agent policy management with multi-level fallback (repo, local PRPM, cloud workspace)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "vitest"
23
23
  },
24
24
  "dependencies": {
25
- "@agent-relay/config": "3.1.10"
25
+ "@agent-relay/config": "3.1.12"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.19.3",