agentlife 2.4.3 → 2.4.5

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 (2) hide show
  1. package/dist/index.js +56 -136
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
2
2
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
3
 
4
4
  // index.ts
5
- import { homedir as homedir12 } from "node:os";
5
+ import { homedir as homedir13 } from "node:os";
6
6
  import * as path16 from "node:path";
7
7
  import { existsSync as existsSync6 } from "node:fs";
8
8
 
@@ -1110,11 +1110,13 @@ Triggered when the orchestrator routes a "create X agent" / "track Y for me" / n
1110
1110
  - \`USER.md\` — domain-specific user facts (name, timezone, language + domain knowledge). Read the user's other USER.md files for identity; don't invent.
1111
1111
  - \`HEARTBEAT.md\` — periodic check instructions, or empty placeholder \`# Keep empty to skip\`.
1112
1112
  4. **Register the agent via \`exec\`**:
1113
- \`exec openclaw gateway call agentlife.createAgent --params '{"id":"{agentId}","name":"{Name}","model":"{model}","workspace":"/abs/path","description":"one sentence","tools":{"profile":"full"},"identity":{"name":"{Name}","emoji":"{emoji}"}}'\`
1113
+ \`exec openclaw gateway call agentlife.createAgent --params '{"id":"{agentId}","name":"{Name}","model":"{model}","workspace":"/abs/path","description":"one sentence","tools":{"profile":"full","alsoAllow":["agentlife_push"]},"identity":{"name":"{Name}","emoji":"{emoji}"}}'\`
1114
1114
  - Description drives the orchestrator's routing — make it specific (domains, actions, data types).
1115
- - \`tools: {profile:"full"}\` for agents needing exec/web/write. \`{allow:["agentlife_push"]}\` for widget-only agents.
1116
- - The plugin deterministically renders a \`{agentId}-intro\` widget the moment \`agentlife.createAgent\` returns — you do not push one yourself.
1117
- 5. **Hand off**: \`delete {domain}-building\`, then emit \`done\`.
1115
+ - \`tools: {profile:"full", alsoAllow:["agentlife_push"]}\` for agents needing every core tool plus widget push. \`{allow:["agentlife_push"]}\` for widget-only agents.
1116
+ 5. **Hand off in ONE final turn, all in this order, before \`done\`:**
1117
+ a. Push ONE actionable first widget for the newly-created agent under a surfaceId you own (\`{agentId}-today\`, \`{agentId}-start\`, similar). It must invite the FIRST user interaction — an input prompt, a starter metric with a CTA, a question the user can answer right now. NEVER an identity/confirmation card ("Agent ready", "Welcome to X"). The plugin no longer pushes a placeholder intro widget; this first push IS the dashboard's anchor for the new agent.
1118
+ b. \`delete {domain}-building\` — the loading widget from step 1.
1119
+ c. Emit \`done\`.
1118
1120
 
1119
1121
  ## Writing AGENTS.md (for the specialist you create)
1120
1122
 
@@ -1245,7 +1247,7 @@ var PROVISIONED_AGENTS = [
1245
1247
  id: "agentlife-builder",
1246
1248
  name: "AgentLife Builder",
1247
1249
  agentsMd: BUILDER_AGENTS_MD,
1248
- tools: { allow: ["*", "agentlife_push"] }
1250
+ tools: { profile: "full", alsoAllow: ["agentlife_push"] }
1249
1251
  },
1250
1252
  {
1251
1253
  id: "supervisor",
@@ -1438,26 +1440,7 @@ async function provisionAgents(state, cfg, runtime, log) {
1438
1440
  globalAllowWritten = true;
1439
1441
  }
1440
1442
  }
1441
- const currentAlsoAllow = Array.isArray(rawCfgForVisibility?.tools?.alsoAllow) ? rawCfgForVisibility.tools.alsoAllow : [];
1442
- let alsoAllowWritten = false;
1443
- if (!currentAlsoAllow.includes("agentlife_push")) {
1444
- try {
1445
- let backup = {};
1446
- try {
1447
- backup = JSON.parse(readFileSync(backupPath, "utf-8"));
1448
- } catch {}
1449
- if (backup.toolsAlsoAllow === undefined) {
1450
- backup.toolsAlsoAllow = [...currentAlsoAllow];
1451
- writeFileSync(backupPath, JSON.stringify(backup, null, 2) + `
1452
- `, "utf-8");
1453
- }
1454
- } catch {}
1455
- if (!rawCfgForVisibility.tools)
1456
- rawCfgForVisibility.tools = {};
1457
- rawCfgForVisibility.tools.alsoAllow = [...currentAlsoAllow, "agentlife_push"];
1458
- alsoAllowWritten = true;
1459
- }
1460
- if (visibilityWritten || a2aWritten || globalAllowWritten || alsoAllowWritten) {
1443
+ if (visibilityWritten || a2aWritten || globalAllowWritten) {
1461
1444
  writeFileSync(configPath, JSON.stringify(rawCfgForVisibility, null, 2) + `
1462
1445
  `, "utf-8");
1463
1446
  configChanged = true;
@@ -1467,8 +1450,6 @@ async function provisionAgents(state, cfg, runtime, log) {
1467
1450
  log("[agentlife] set tools.agentToAgent.enabled=true (cross-agent sends)");
1468
1451
  if (globalAllowWritten)
1469
1452
  log('[agentlife] added "*" to tools.allow (unblock exec/read/write for provisioned agents)');
1470
- if (alsoAllowWritten)
1471
- log("[agentlife] added agentlife_push to tools.alsoAllow (tool-policy pipeline intersection pass-through)");
1472
1453
  }
1473
1454
  if (configChanged) {
1474
1455
  const configPath2 = path3.join(os.homedir(), ".openclaw", "openclaw.json");
@@ -2747,91 +2728,13 @@ function snapshotOnboarding(state, runtime) {
2747
2728
  }
2748
2729
 
2749
2730
  // render-widgets.ts
2750
- function recentActivityCount(state, agentId, sinceMs) {
2751
- if (!state.historyDb)
2752
- return 0;
2753
- try {
2754
- const row = state.historyDb.prepare("SELECT COUNT(*) as c FROM activity_log WHERE agentId = ? AND ts > ?").get(agentId, sinceMs);
2755
- return row?.c ?? 0;
2756
- } catch {
2757
- return 0;
2758
- }
2759
- }
2760
- function pendingFollowupCount(state, agentId) {
2761
- if (!state.historyDb)
2762
- return 0;
2763
- try {
2764
- const row = state.historyDb.prepare("SELECT COUNT(*) as c FROM followups WHERE agentId = ? AND status = 'pending'").get(agentId);
2765
- return row?.c ?? 0;
2766
- } catch {
2767
- return 0;
2768
- }
2769
- }
2770
- function sanitizeDslString(s) {
2771
- return s.replace(/"/g, "'").replace(/[\r\n]+/g, " ").slice(0, 120);
2772
- }
2773
- function composeAgentIntroDsl(opts) {
2774
- const surfaceId = `${opts.agentId}-intro`;
2775
- const title = `${opts.emoji} ${opts.name}`;
2776
- const desc = sanitizeDslString(opts.description || `Your ${opts.name} agent, ready to track and act.`);
2777
- const activeBadge = opts.activityCount > 0 ? "Active" : "Ready";
2778
- const activeColor = opts.activityCount > 0 ? "#10B981" : "#6366F1";
2779
- return [
2780
- `surface ${surfaceId} size=m`,
2781
- ` card`,
2782
- ` column`,
2783
- ` text "${sanitizeDslString(title)}" h3`,
2784
- ` text "${desc}" body`,
2785
- ` divider`,
2786
- ` row distribute=spaceBetween`,
2787
- ` metric "Actions (7d)" "${opts.activityCount}"`,
2788
- ` metric "Upcoming" "${opts.followupCount}"`,
2789
- ` badge "${activeBadge}" color=${activeColor} outlined`,
2790
- `goal: ${opts.name} — track progress toward user's first real outcome`,
2791
- `followup: +24h "Check if the user interacted with the ${opts.name} agent. If yes, summarize progress. If not, push a gentle prompt relevant to the domain."`,
2792
- `context: {"agentId":"${opts.agentId}","domain":"${opts.agentId}","phase":"intro","autoRendered":true}`
2793
- ].join(`
2794
- `);
2795
- }
2796
- function agentEmoji(runtime, agentId) {
2797
- const cfg = runtime.config.loadConfig();
2798
- const list = cfg?.agents?.list ?? [];
2799
- const found = list.find((a) => a?.id === agentId);
2800
- return found?.identity?.emoji ?? "\uD83C\uDFAF";
2801
- }
2802
- function renderAgentWidget(state, runtime, agentId, log) {
2803
- if (!userAgentIds(runtime).includes(agentId))
2804
- return;
2805
- const entry = state.agentRegistry.get(agentId);
2806
- if (!entry) {
2807
- log(`[render-widgets] ${agentId}: no registry entry, skipping`);
2808
- return;
2809
- }
2810
- const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
2811
- const dsl = composeAgentIntroDsl({
2812
- agentId,
2813
- name: entry.name,
2814
- description: entry.description ?? "",
2815
- emoji: agentEmoji(runtime, agentId),
2816
- activityCount: recentActivityCount(state, agentId, sevenDaysAgo),
2817
- followupCount: pendingFollowupCount(state, agentId)
2818
- });
2819
- pluginPushSurface(state, { agentId, dsl });
2820
- log(`[render-widgets] rendered ${agentId}-intro`);
2821
- }
2822
2731
  function renderAllAgentWidgets(state, runtime, log) {
2823
2732
  if (isOnboarding(state, runtime)) {
2824
2733
  log("[render-widgets] onboarding active — rendering welcome widget");
2825
2734
  renderWelcomeWidget(state, log);
2826
2735
  return;
2827
2736
  }
2828
- for (const id of userAgentIds(runtime)) {
2829
- try {
2830
- renderAgentWidget(state, runtime, id, log);
2831
- } catch (e) {
2832
- log(`[render-widgets] ${id} render failed: ${e?.message ?? e}`);
2833
- }
2834
- }
2737
+ log("[render-widgets] onboarding complete — no plugin-pushed widgets; specialists own their surfaces");
2835
2738
  }
2836
2739
  var WELCOME_SURFACE_ID = "welcome";
2837
2740
  var WELCOME_INPUT_SURFACE_ID = "welcome-input";
@@ -2851,12 +2754,12 @@ Each turn:
2851
2754
  - updated \`context: {"phase":"welcome","turn":N+1,"answers":[...]}\`
2852
2755
  - goal + followup unchanged
2853
2756
  Respond \`done\`.
2854
- 3. Enough → create the generalist:
2757
+ 3. Enough → create the generalist and hand off the dashboard:
2855
2758
  - Workspace under \`$HOME/.openclaw/workspace-{id}\` (id = slugified short name or "me")
2856
2759
  - \`AGENTS.md\` — generalist scope covering mentioned domains; Data Schema must include a \`domain TEXT NOT NULL\` column on every user-data table so future split by domain is trivial; add self-evolution clause ("when activity_log rows for one domain exceed a natural threshold, push a split-suggest widget")
2857
2760
  - \`SOUL.md\`, \`IDENTITY.md\`, \`USER.md\` (user's own words), \`HEARTBEAT.md\` (empty)
2858
- - \`exec openclaw gateway call agentlife.createAgent --params '{...}'\` with \`tools: {profile:"full"}\`. Plugin auto-deletes welcome + welcome-input and renders {id}-intro — do NOT push an intro.
2859
- - Respond \`done\`.
2761
+ - \`exec openclaw gateway call agentlife.createAgent --params '{...}'\` with \`tools: {profile:"full", alsoAllow:["agentlife_push"]}\`. Plugin auto-deletes welcome + welcome-input on success.
2762
+ - **Final step, same turn, before \`done\`:** push ONE actionable first widget for the newly-created agent — an input prompt ("Log your first meal", "Enter today's weight"), a starter metric, or an inviting CTA that owns a surfaceId like \`{id}-today\` / \`{id}-start\`. This is what the user sees when onboarding ends; it MUST invite interaction, not just announce existence. Then delete your \`{domain}-building\` loading widget. Then emit \`done\`.
2860
2763
  `;
2861
2764
  function renderWelcomeWidget(state, log) {
2862
2765
  const welcomeDsl = [
@@ -2898,14 +2801,6 @@ function deleteWelcomeWidget(state, log) {
2898
2801
  log(`[render-widgets] deleted ${id}`);
2899
2802
  }
2900
2803
  }
2901
- if (state.runCommand) {
2902
- const deleteParams = JSON.stringify({ key: ONBOARDING_SESSION_KEY, deleteTranscript: true });
2903
- state.runCommand(["openclaw", "gateway", "call", "sessions.delete", "--params", deleteParams], { timeoutMs: 1e4 }).then(() => {
2904
- log(`[render-widgets] deleted onboarding session`);
2905
- }).catch((e) => {
2906
- console.log("[agentlife] onboarding session delete skipped: %s", e?.message);
2907
- });
2908
- }
2909
2804
  }
2910
2805
 
2911
2806
  // services/surfaces-init.ts
@@ -6166,6 +6061,7 @@ ${dashboardState}` : ONBOARDING_PLAYBOOK : dashboardState;
6166
6061
 
6167
6062
  // gateway/agents.ts
6168
6063
  import * as fs8 from "node:fs";
6064
+ import * as os7 from "node:os";
6169
6065
  import * as path11 from "node:path";
6170
6066
  function registerAgentGateway(api, state2) {
6171
6067
  api.registerGatewayMethod("agentlife.createAgent", async ({ params, respond }) => {
@@ -6256,10 +6152,9 @@ function registerAgentGateway(api, state2) {
6256
6152
  configFields.push("identity");
6257
6153
  if (!existing && userAgentIds(api.runtime).includes(id)) {
6258
6154
  try {
6259
- renderAgentWidget(state2, api.runtime, id, console.log);
6260
6155
  deleteWelcomeWidget(state2, console.log);
6261
6156
  } catch (e) {
6262
- console.warn("[agentlife] renderAgentWidget failed for %s: %s", id, e?.message);
6157
+ console.warn("[agentlife] deleteWelcomeWidget failed for %s: %s", id, e?.message);
6263
6158
  }
6264
6159
  }
6265
6160
  respond(true, { status, id, name, model, workspace, description, ...configFields.length ? { configFields } : {} });
@@ -6275,7 +6170,7 @@ function registerAgentGateway(api, state2) {
6275
6170
  respond(false, { error: "cannot delete provisioned agent" });
6276
6171
  return;
6277
6172
  }
6278
- const cleanup = { sessions: 0, cronJobs: 0, historyRows: 0, agentDbDeleted: false };
6173
+ const cleanup = { sessions: 0, cronJobs: 0, historyRows: 0, agentDbDeleted: false, workspaceDeleted: false, stateDeleted: false };
6279
6174
  if (state2.runCommand) {
6280
6175
  try {
6281
6176
  const sessResult = await state2.runCommand(["openclaw", "gateway", "call", "sessions.list"], { timeoutMs: 1e4 });
@@ -6336,8 +6231,33 @@ function registerAgentGateway(api, state2) {
6336
6231
  }
6337
6232
  const cfg = api.runtime.config.loadConfig();
6338
6233
  const currentList = cfg.agents?.list ?? [];
6234
+ const existingEntry = currentList.find((a) => a.id === id);
6339
6235
  const filtered = currentList.filter((a) => a.id !== id);
6340
6236
  const removedFromConfig = filtered.length < currentList.length;
6237
+ const openclawHome = path11.join(os7.homedir(), ".openclaw");
6238
+ const stateDir = path11.join(openclawHome, "agents", id);
6239
+ if (stateDir.startsWith(path11.join(openclawHome, "agents") + path11.sep)) {
6240
+ try {
6241
+ if (fs8.existsSync(stateDir)) {
6242
+ fs8.rmSync(stateDir, { recursive: true, force: true });
6243
+ cleanup.stateDeleted = true;
6244
+ }
6245
+ } catch (e) {
6246
+ console.warn("[agentlife] deleteAgent: failed to delete state dir:", e?.message);
6247
+ }
6248
+ }
6249
+ const defaultWorkspace = path11.join(openclawHome, `workspace-${id}`);
6250
+ const workspaceToDelete = typeof existingEntry?.workspace === "string" && existingEntry.workspace.trim() ? path11.resolve(existingEntry.workspace) : defaultWorkspace;
6251
+ if (workspaceToDelete.startsWith(openclawHome + path11.sep) && workspaceToDelete !== openclawHome) {
6252
+ try {
6253
+ if (fs8.existsSync(workspaceToDelete)) {
6254
+ fs8.rmSync(workspaceToDelete, { recursive: true, force: true });
6255
+ cleanup.workspaceDeleted = true;
6256
+ }
6257
+ } catch (e) {
6258
+ console.warn("[agentlife] deleteAgent: failed to delete workspace dir:", e?.message);
6259
+ }
6260
+ }
6341
6261
  if (removedFromConfig) {
6342
6262
  const updatedCfg = {
6343
6263
  ...cfg,
@@ -6352,7 +6272,7 @@ function registerAgentGateway(api, state2) {
6352
6272
  if (removedFromRegistry) {
6353
6273
  await saveRegistryToDisk(state2);
6354
6274
  }
6355
- console.log("[agentlife] deleted agent: %s (config=%s, registry=%s, sessions=%d, cron=%d, historyRows=%d, agentDb=%s)", id, removedFromConfig, removedFromRegistry, cleanup.sessions, cleanup.cronJobs, cleanup.historyRows, cleanup.agentDbDeleted);
6275
+ console.log("[agentlife] deleted agent: %s (config=%s, registry=%s, sessions=%d, cron=%d, historyRows=%d, agentDb=%s, state=%s, workspace=%s)", id, removedFromConfig, removedFromRegistry, cleanup.sessions, cleanup.cronJobs, cleanup.historyRows, cleanup.agentDbDeleted, cleanup.stateDeleted, cleanup.workspaceDeleted);
6356
6276
  respond(true, { status: "deleted", id, removedFromConfig, removedFromRegistry, cleanup });
6357
6277
  });
6358
6278
  api.registerGatewayMethod("agentlife.agents", ({ respond }) => {
@@ -6972,10 +6892,10 @@ function registerAutomationsGateway(api, state2) {
6972
6892
  // gateway/admin.ts
6973
6893
  import * as fs9 from "node:fs/promises";
6974
6894
  import * as fsSync4 from "node:fs";
6975
- import * as os7 from "node:os";
6895
+ import * as os8 from "node:os";
6976
6896
  import * as path12 from "node:path";
6977
6897
  function pluginConfigPath() {
6978
- return path12.join(os7.homedir(), ".openclaw", "agentlife", "plugin-config.json");
6898
+ return path12.join(os8.homedir(), ".openclaw", "agentlife", "plugin-config.json");
6979
6899
  }
6980
6900
  function readPluginConfig() {
6981
6901
  try {
@@ -7084,7 +7004,7 @@ function registerAdminGateway(api, state2) {
7084
7004
  api.registerGatewayMethod("agentlife.uninstall", async ({ respond }) => {
7085
7005
  try {
7086
7006
  const cleaned = [];
7087
- const baseDir = state2.agentlifeStateDir ?? path12.join(os7.homedir(), ".openclaw", "agentlife");
7007
+ const baseDir = state2.agentlifeStateDir ?? path12.join(os8.homedir(), ".openclaw", "agentlife");
7088
7008
  const identity = loadDeviceIdentity();
7089
7009
  if (!identity) {
7090
7010
  cleaned.push("server deprovision skipped (no device identity)");
@@ -7190,7 +7110,7 @@ function registerAdminGateway(api, state2) {
7190
7110
  for (const agent of PROVISIONED_AGENTS) {
7191
7111
  if (agent.existingAgent)
7192
7112
  continue;
7193
- const wsDir = agent.workspaceDir ?? path12.join(os7.homedir(), ".openclaw", `workspace-${agent.id}`);
7113
+ const wsDir = agent.workspaceDir ?? path12.join(os8.homedir(), ".openclaw", `workspace-${agent.id}`);
7194
7114
  try {
7195
7115
  await fs9.rm(wsDir, { recursive: true, force: true });
7196
7116
  cleaned.push(`deleted workspace ${agent.id}`);
@@ -7451,10 +7371,10 @@ import {
7451
7371
 
7452
7372
  // gateway/config-utils.ts
7453
7373
  import * as fs10 from "node:fs";
7454
- import * as os8 from "node:os";
7374
+ import * as os9 from "node:os";
7455
7375
  import * as path13 from "node:path";
7456
7376
  function configPath() {
7457
- return path13.join(os8.homedir(), ".openclaw", "openclaw.json");
7377
+ return path13.join(os9.homedir(), ".openclaw", "openclaw.json");
7458
7378
  }
7459
7379
  function readConfig() {
7460
7380
  try {
@@ -7470,10 +7390,10 @@ function writeConfig(cfg) {
7470
7390
 
7471
7391
  // gateway/providers.ts
7472
7392
  import * as fs11 from "node:fs";
7473
- import * as os9 from "node:os";
7393
+ import * as os10 from "node:os";
7474
7394
  import * as path14 from "node:path";
7475
7395
  function siblingAgentDirs() {
7476
- const root = path14.join(os9.homedir(), ".openclaw", "agents");
7396
+ const root = path14.join(os10.homedir(), ".openclaw", "agents");
7477
7397
  let entries;
7478
7398
  try {
7479
7399
  entries = fs11.readdirSync(root, { withFileTypes: true });
@@ -7558,8 +7478,8 @@ function readOAuthExpiries() {
7558
7478
  const result = new Map;
7559
7479
  const fs12 = __require("node:fs");
7560
7480
  const path15 = __require("node:path");
7561
- const os10 = __require("node:os");
7562
- const agentsDir = path15.join(os10.homedir(), ".openclaw", "agents");
7481
+ const os11 = __require("node:os");
7482
+ const agentsDir = path15.join(os11.homedir(), ".openclaw", "agents");
7563
7483
  let entries;
7564
7484
  try {
7565
7485
  entries = fs12.readdirSync(agentsDir);
@@ -7851,10 +7771,10 @@ ${result?.stderr ?? ""}`;
7851
7771
 
7852
7772
  // gateway/models-config.ts
7853
7773
  import * as fs12 from "node:fs";
7854
- import * as os10 from "node:os";
7774
+ import * as os11 from "node:os";
7855
7775
  import * as path15 from "node:path";
7856
7776
  function pluginConfigPath2() {
7857
- return path15.join(os10.homedir(), ".openclaw", "agentlife", "plugin-config.json");
7777
+ return path15.join(os11.homedir(), ".openclaw", "agentlife", "plugin-config.json");
7858
7778
  }
7859
7779
  function readPluginConfig2() {
7860
7780
  try {
@@ -8011,7 +7931,7 @@ var stopQualityCheckPoller = null;
8011
7931
  var stopCloudflared = null;
8012
7932
  function resolveInternalModel(api) {
8013
7933
  try {
8014
- const pluginCfgPath = path16.join(homedir12(), ".openclaw", "agentlife", "plugin-config.json");
7934
+ const pluginCfgPath = path16.join(homedir13(), ".openclaw", "agentlife", "plugin-config.json");
8015
7935
  try {
8016
7936
  const raw = __require("node:fs").readFileSync(pluginCfgPath, "utf-8");
8017
7937
  const pluginCfg = JSON.parse(raw);
@@ -8047,7 +7967,7 @@ function register(api) {
8047
7967
  return;
8048
7968
  }
8049
7969
  registered = true;
8050
- const fallbackDir = path16.join(homedir12(), ".openclaw", "agentlife");
7970
+ const fallbackDir = path16.join(homedir13(), ".openclaw", "agentlife");
8051
7971
  const state2 = {
8052
7972
  surfaceDb: null,
8053
7973
  agentRegistry: new Map,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentlife",
3
- "version": "2.4.3",
3
+ "version": "2.4.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "bun build index.ts --outfile dist/index.js --target node --external openclaw/plugin-sdk",