@openagents-org/agent-launcher 0.2.202 → 0.2.204

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.
@@ -583,8 +583,14 @@ function buildApiSkillsPrompt({ endpoint, workspaceId, token, agentName, channel
583
583
  `"hour":8,"minute":0,` +
584
584
  `"network":"${workspaceId}",` +
585
585
  `"source":"openagents:${agentName}"}'\`\n\n` +
586
- '**List active routines:**\n' +
586
+ '**List routines (active + paused):**\n' +
587
587
  `\`${curl} -s -H "${h}" "${baseUrl}/v1/routines?network=${workspaceId}"\`\n\n` +
588
+ '**Edit a routine** (only the fields you send change — this keeps the ' +
589
+ 'routine\'s id and history, so prefer it over cancel-and-recreate). ' +
590
+ '`status` is `active` or `paused`:\n' +
591
+ `\`${curl} -s -X PATCH -H "${h}" -H "Content-Type: application/json" ` +
592
+ `${baseUrl}/v1/routines/ROUTINE_ID -d '{"hour":9,"minute":30,` +
593
+ `"network":"${workspaceId}"}'\`\n\n` +
588
594
  '**Cancel a routine:**\n' +
589
595
  `\`${curl} -s -X DELETE -H "${h}" ${baseUrl}/v1/routines/ROUTINE_ID\`\n`
590
596
  );
@@ -720,6 +726,7 @@ function buildClaudeMcpToolBlock() {
720
726
  'Use workspace_put_todos to track your progress. ALWAYS create a to-do list when given multiple tasks or multi-step work.\n' +
721
727
  'Use workspace_create_timer to set a reminder that wakes you up later.\n' +
722
728
  'Use workspace_create_routine to set up recurring scheduled tasks (e.g. daily reviews).\n' +
729
+ 'Use workspace_update_routine to change an existing routine — its schedule, task or paused state — instead of cancelling and recreating it.\n' +
723
730
  'Use workspace_send_notification to send a notification to the workspace inbox when you complete a task or have important results.\n' +
724
731
  'Use workspace_request_approval BEFORE deploying, spending money, emailing customers, deleting data, or any irreversible action; it blocks until a person decides. If it returns PENDING, stop and end your turn — the decision arrives as a message in the thread.\n' +
725
732
  'Use workspace_write_knowledge to create or update shared knowledge base entries that persist across conversations.\n' +
package/src/config.js CHANGED
@@ -175,8 +175,14 @@ class Config {
175
175
  }
176
176
  }
177
177
 
178
+ /**
179
+ * Queue a line for the daemon, which reads and deletes the file every 200ms.
180
+ * Appended, not overwritten: two commands landing inside one poll (a Start
181
+ * clicked in the launcher and a heartbeat nudge from a workspace page) both
182
+ * have to arrive.
183
+ */
178
184
  writeCommand(cmd) {
179
- fs.writeFileSync(this.cmdFile, cmd + '\n', 'utf-8');
185
+ fs.appendFileSync(this.cmdFile, cmd + '\n', 'utf-8');
180
186
  }
181
187
 
182
188
  getLogs(agentName, lines = 200) {
package/src/daemon.js CHANGED
@@ -910,9 +910,8 @@ async _runNodeCommand(n, cmd) {
910
910
  if (rc2.code !== 0) throw new Error(rc2.stderr || rc2.stdout || 'connect failed');
911
911
  } else {
912
912
  // Restart in-process. `agn stop` + `agn start` both round-trip
913
- // through daemon.cmd, and writeCommand() OVERWRITES that file — the
914
- // start could clobber the unread stop (agent keeps the stale env) or
915
- // interleave with the poll so the agent stops and never restarts.
913
+ // through daemon.cmd, and the pair can interleave with the poll so
914
+ // the agent stops and never restarts.
916
915
  this._saveNodeAgentEnv(name, type, args);
917
916
  await this.restartAgent(name);
918
917
  }
@@ -1953,6 +1952,11 @@ async _runNodeCommand(n, cmd) {
1953
1952
  } else if (cmd === 'reload') {
1954
1953
  this._log('Command: reload');
1955
1954
  this._reload();
1955
+ } else if (cmd === 'heartbeat') {
1956
+ // A workspace page in the launcher just queued a command for this
1957
+ // device: heartbeat now so it is picked up, instead of on the next
1958
+ // 10s tick. Not logged — it carries nothing worth a line.
1959
+ this._nodeHeartbeat().catch(() => {});
1956
1960
  }
1957
1961
  }
1958
1962
  } catch {}
package/src/env.js CHANGED
@@ -203,15 +203,36 @@ function modelKeys(agentType, registry) {
203
203
  }
204
204
 
205
205
  /**
206
- * The part of <type>.env an agent runs on. All of it for an agent on a key.
207
- * A signed-in agent takes none of its keys, and none of its model either:
208
- * that model was picked for the key's endpoint (a relay's
209
- * openai-gpt-oss-20b), which the account behind a sign-in does not serve.
210
- * Its model is the one in its own env, else the CLI's default.
206
+ * Whether the agent's own env carries a key (not just an endpoint).
207
+ */
208
+ function hasOwnKey(agentType, registry, agentEnv) {
209
+ if (!agentEnv) return false;
210
+ for (const key of credentialKeys(agentType, registry)) {
211
+ if (/BASE_URL$/.test(key)) continue;
212
+ if (String(agentEnv[key] == null ? '' : agentEnv[key]).trim()) return true;
213
+ }
214
+ return false;
215
+ }
216
+
217
+ /**
218
+ * The part of <type>.env an agent runs on. All of it for an agent that brings
219
+ * no credentials of its own.
220
+ *
221
+ * A signed-in agent, or one with a key of its own, takes none of the type's
222
+ * keys or endpoints, and none of its model either: that model was picked for
223
+ * the type key's endpoint (a relay's openai-gpt-oss-20b), which neither the
224
+ * account behind a sign-in nor the agent's own provider serves. Resolution
225
+ * maps the generic LLM_* names over the provider ones, so a relay left in
226
+ * <type>.env used to override an agent configured for DeepSeek: its
227
+ * LLM_BASE_URL and LLM_MODEL became PI_BASE_URL and PI_MODEL, and the agent's
228
+ * key went to the relay. Its model is the one in its own env, else the CLI's
229
+ * default.
211
230
  */
212
231
  function typeEnvFor(agentType, typeEnv, registry, agentEnv) {
213
- if (!isCliLogin(agentEnv)) return typeEnv;
214
- const out = stripForCliLogin(agentType, typeEnv, registry, agentEnv);
232
+ const signedIn = isCliLogin(agentEnv);
233
+ if (!signedIn && !hasOwnKey(agentType, registry, agentEnv)) return typeEnv;
234
+ const out = { ...typeEnv };
235
+ for (const key of credentialKeys(agentType, registry)) delete out[key];
215
236
  for (const key of modelKeys(agentType, registry)) delete out[key];
216
237
  return out;
217
238
  }
package/src/mcp-server.js CHANGED
@@ -412,9 +412,39 @@ function buildToolDefs(disabledModules) {
412
412
  },
413
413
  {
414
414
  name: 'workspace_list_routines',
415
- description: 'List active routines in the current channel.',
415
+ description: 'List routines in the current channel, active and paused.',
416
416
  inputSchema: { type: 'object', properties: {} },
417
417
  },
418
+ {
419
+ name: 'workspace_update_routine',
420
+ description: 'Edit an existing routine instead of cancelling and recreating it (which would lose its id and run history). Only the fields you pass change. Use status to pause a routine and resume it later.',
421
+ inputSchema: {
422
+ type: 'object',
423
+ properties: {
424
+ routine_id: { type: 'string', description: 'Routine ID to edit (from workspace_list_routines)' },
425
+ name: { type: 'string', description: 'New human-readable label' },
426
+ message: { type: 'string', description: 'New trigger message. Changing it regenerates the routine context unless you also pass context.' },
427
+ context: { type: 'string', description: 'New comprehensive context posted each time the routine fires. Pass this whenever you change what the routine is for.' },
428
+ hour: { type: 'integer', description: 'Daily mode: hour in UTC (0-23). Omit if using interval_minutes.' },
429
+ minute: { type: 'integer', description: 'Daily mode: minute (0-59). Omit if using interval_minutes.' },
430
+ days: {
431
+ type: 'array',
432
+ items: { type: 'integer' },
433
+ description: 'Daily mode: days of week to fire (0=Mon, 6=Sun). Omit to keep the current days.',
434
+ },
435
+ interval_minutes: {
436
+ type: 'integer',
437
+ description: 'Interval mode: fire every N minutes (1-1440). Mutually exclusive with hour/minute.',
438
+ },
439
+ status: {
440
+ type: 'string',
441
+ enum: ['active', 'paused'],
442
+ description: 'Pause a routine (stops firing, stays listed) or resume it. Cancelling is workspace_cancel_routine.',
443
+ },
444
+ },
445
+ required: ['routine_id'],
446
+ },
447
+ },
418
448
  {
419
449
  name: 'workspace_cancel_routine',
420
450
  description: 'Cancel a recurring routine by its ID.',
@@ -1088,7 +1118,7 @@ class McpServer {
1088
1118
  case 'workspace_list_routines': {
1089
1119
  const data = await this.ws.listRoutines(this.workspaceId, this.channelName, this.token);
1090
1120
  const routines = (data && data.routines) || [];
1091
- if (!routines.length) return text('No active routines.');
1121
+ if (!routines.length) return text('No routines.');
1092
1122
  const lines = routines.map((r) => {
1093
1123
  let when;
1094
1124
  if (r.schedule_interval_minutes != null) {
@@ -1097,11 +1127,38 @@ class McpServer {
1097
1127
  when = `at ${String(r.schedule_hour).padStart(2,'0')}:${String(r.schedule_minute).padStart(2,'0')} UTC` +
1098
1128
  (r.schedule_days ? ` [days: ${r.schedule_days.join(',')}]` : ' (daily)');
1099
1129
  }
1100
- return `- ${r.id}: "${r.name}" ${when} — next: ${r.next_fires_at} (by ${r.created_by})`;
1130
+ const state = r.status && r.status !== 'active' ? ` [${r.status}]` : '';
1131
+ return `- ${r.id}: "${r.name}"${state} ${when} — next: ${r.next_fires_at} (by ${r.created_by})`;
1101
1132
  });
1102
1133
  return text(lines.join('\n'));
1103
1134
  }
1104
1135
 
1136
+ case 'workspace_update_routine': {
1137
+ const updated = await this.ws.updateRoutine(
1138
+ this.workspaceId, this.token, args.routine_id,
1139
+ {
1140
+ name: args.name,
1141
+ message: args.message,
1142
+ context: args.context,
1143
+ hour: args.hour,
1144
+ minute: args.minute,
1145
+ days: args.days,
1146
+ interval_minutes: args.interval_minutes,
1147
+ status: args.status,
1148
+ },
1149
+ );
1150
+ let when;
1151
+ if (updated.schedule_interval_minutes != null) {
1152
+ when = `every ${updated.schedule_interval_minutes} min`;
1153
+ } else {
1154
+ const daysStr = updated.schedule_days ? `days [${updated.schedule_days.join(',')}]` : 'every day';
1155
+ when = `at ${String(updated.schedule_hour).padStart(2,'0')}:${String(updated.schedule_minute).padStart(2,'0')} UTC, ${daysStr}`;
1156
+ }
1157
+ return text(
1158
+ `Routine updated: "${updated.name}" ${when} — status ${updated.status}, next: ${updated.next_fires_at} (id: ${updated.id})`,
1159
+ );
1160
+ }
1161
+
1105
1162
  case 'workspace_cancel_routine': {
1106
1163
  await this.ws.cancelRoutine(this.workspaceId, this.token, args.routine_id);
1107
1164
  return text(`Routine cancelled: ${args.routine_id}`);
@@ -970,6 +970,30 @@ class WorkspaceClient {
970
970
  return data.data || data;
971
971
  }
972
972
 
973
+ /**
974
+ * Edit a routine in place. Only the fields passed are changed; the schedule
975
+ * keeps the same either/or rule as creation (`interval_minutes`, or
976
+ * `hour`/`minute`/`days`). `status` is 'active' | 'paused' — cancelling
977
+ * still goes through `cancelRoutine`.
978
+ */
979
+ async updateRoutine(workspaceId, token, routineId, { name, message, context, hour, minute, days, interval_minutes, source, status } = {}) {
980
+ const body = { network: workspaceId };
981
+ if (name != null) body.name = name;
982
+ if (message != null) body.message = message;
983
+ if (context != null) body.context = context;
984
+ if (source != null) body.source = source;
985
+ if (status != null) body.status = status;
986
+ if (interval_minutes != null) {
987
+ body.interval_minutes = interval_minutes;
988
+ } else {
989
+ if (hour != null) body.hour = hour;
990
+ if (minute != null) body.minute = minute;
991
+ if (days != null) body.days = days;
992
+ }
993
+ const data = await this._patch(`/v1/routines/${routineId}`, body, this._wsHeaders(token));
994
+ return data.data || data;
995
+ }
996
+
973
997
  async cancelRoutine(workspaceId, token, routineId) {
974
998
  const data = await this._delete(`/v1/routines/${routineId}`, this._wsHeaders(token));
975
999
  return data.data || data;
@@ -1407,12 +1431,20 @@ class WorkspaceClient {
1407
1431
  try {
1408
1432
  const parsed = JSON.parse(data);
1409
1433
  if (res.statusCode >= 400) {
1410
- reject(new Error(parsed.message || `HTTP ${res.statusCode}`));
1434
+ const err = new Error(parsed.message || `HTTP ${res.statusCode}`);
1435
+ // Callers act on it: removeAgentFromWorkspace takes a 404 as
1436
+ // "already gone". Without it that check never matched, and an
1437
+ // agent whose membership was already removed could not be
1438
+ // deleted at all ("Member not found").
1439
+ err.status = res.statusCode;
1440
+ reject(err);
1411
1441
  } else {
1412
1442
  resolve(parsed);
1413
1443
  }
1414
1444
  } catch {
1415
- reject(new Error(`Invalid response: ${data.slice(0, 200)}`));
1445
+ const err = new Error(`Invalid response: ${data.slice(0, 200)}`);
1446
+ if (res.statusCode >= 400) err.status = res.statusCode;
1447
+ reject(err);
1416
1448
  }
1417
1449
  });
1418
1450
  });