@11agents/cli 0.1.12 → 0.1.13

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": "@11agents/cli",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "11agents local runtime and telemetry CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -96,6 +96,41 @@ function createRetryState() {
96
96
  return { failures: 0 }
97
97
  }
98
98
 
99
+ async function heartbeatRegisteredRuntime(registration, flags, deps) {
100
+ const config = configFromFlags(flags)
101
+ const machineKey = registration?.machine?.machine_key || machineOverride(flags) || ''
102
+ if (!machineKey) return null
103
+ return deps.requestJson('/api/runtime/machines/heartbeat', {
104
+ method: 'POST',
105
+ body: {
106
+ machine_key: machineKey,
107
+ runtime_providers: (registration?.runtimes || []).map(runtime => runtime.provider).filter(Boolean),
108
+ health: {
109
+ heartbeat_at: new Date().toISOString(),
110
+ },
111
+ },
112
+ config,
113
+ })
114
+ }
115
+
116
+ async function runWithRuntimeHeartbeat(operation, registration, flags, deps, heartbeatIntervalMs) {
117
+ const intervalMs = Math.max(10, Math.min(Number(heartbeatIntervalMs) || 15000, 60000))
118
+ const timer = setInterval(() => {
119
+ heartbeatRegisteredRuntime(registration, flags, deps).catch(error => {
120
+ deps.log(JSON.stringify({
121
+ warning: 'runtime heartbeat during task failed',
122
+ error: errorMessage(error),
123
+ }, null, 2))
124
+ })
125
+ }, intervalMs)
126
+ timer.unref?.()
127
+ try {
128
+ return await operation()
129
+ } finally {
130
+ clearInterval(timer)
131
+ }
132
+ }
133
+
99
134
  async function runWithDaemonRetry(label, operation, deps, retryState) {
100
135
  while (true) {
101
136
  try {
@@ -906,7 +941,7 @@ function defaultTaskHandler(flags, deps) {
906
941
  }
907
942
  }
908
943
 
909
- async function claimAndRunRuntimeTasks(registration, flags, deps, handlerModule, retryState = createRetryState()) {
944
+ async function claimAndRunRuntimeTasks(registration, flags, deps, handlerModule, retryState = createRetryState(), heartbeatIntervalMs = 15000) {
910
945
  if (!handlerModule) return 0
911
946
  const config = configFromFlags(flags)
912
947
  const machineKey = registration?.machine?.machine_key || machineOverride(flags) || ''
@@ -968,7 +1003,13 @@ async function claimAndRunRuntimeTasks(registration, flags, deps, handlerModule,
968
1003
  executionContext = await prepareRuntimeTask(runtimeTask, flags, deps, config)
969
1004
  runtimeTask.execution_context = executionContext
970
1005
  try {
971
- completion = await handlerModule.handleRuntimeTask(runtimeTask)
1006
+ completion = await runWithRuntimeHeartbeat(
1007
+ () => handlerModule.handleRuntimeTask(runtimeTask),
1008
+ registration,
1009
+ flags,
1010
+ deps,
1011
+ heartbeatIntervalMs
1012
+ )
972
1013
  } catch (error) {
973
1014
  completion = {
974
1015
  comment: error instanceof Error ? error.message : String(error),
@@ -1063,7 +1104,7 @@ export async function startRuntimeDaemon(flags = {}, deps = {}) {
1063
1104
  const retryState = createRetryState()
1064
1105
  let registration = await runWithDaemonRetry('register runtime', () => registerRuntime(flags, resolvedDeps), resolvedDeps, retryState)
1065
1106
  await syncRuntimeProjectMetadataBestEffort(flags, resolvedDeps)
1066
- await claimAndRunRuntimeTasks(registration, flags, resolvedDeps, handlerModule, retryState)
1107
+ await claimAndRunRuntimeTasks(registration, flags, resolvedDeps, handlerModule, retryState, heartbeatIntervalMs)
1067
1108
  if (once) return
1068
1109
 
1069
1110
  let lastScan = Date.now()
@@ -1082,7 +1123,7 @@ export async function startRuntimeDaemon(flags = {}, deps = {}) {
1082
1123
  lastHeartbeat = now
1083
1124
  }
1084
1125
  if (now - lastTaskPoll >= taskIntervalMs) {
1085
- await claimAndRunRuntimeTasks(registration, flags, resolvedDeps, handlerModule, retryState)
1126
+ await claimAndRunRuntimeTasks(registration, flags, resolvedDeps, handlerModule, retryState, heartbeatIntervalMs)
1086
1127
  lastTaskPoll = now
1087
1128
  }
1088
1129
  if (now - lastProjectRefresh >= projectRefreshIntervalMs) {