clementine-agent 1.18.179 → 1.18.180

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.
@@ -186,6 +186,17 @@ export declare class CronScheduler {
186
186
  */
187
187
  private dispatchContextForJobName;
188
188
  private dispatchContextForBackgroundTask;
189
+ /**
190
+ * Mirror a background-task message (start / done / failed) into the
191
+ * originating chat session's memory. Without this, bg: tasks finish,
192
+ * deliver their result to Discord/Slack, and then the very next chat
193
+ * turn comes back to an assistant that has zero memory of any of it —
194
+ * the user asks "fix the site you just deployed" and gets "I don't see
195
+ * any record of a Netlify site." injectContext writes into both the
196
+ * pending-context map (visible to the next SDK turn) and the memory
197
+ * store (searchable later by the assistant).
198
+ */
199
+ private mirrorBackgroundTaskToChat;
189
200
  /** Same idea for workflows. Workflows can be agent-scoped via WorkflowDefinition.agentSlug. */
190
201
  private dispatchContextForWorkflow;
191
202
  private runJob;
@@ -944,6 +944,30 @@ export class CronScheduler {
944
944
  ctx.agentSlug = task.fromAgent;
945
945
  return ctx;
946
946
  }
947
+ /**
948
+ * Mirror a background-task message (start / done / failed) into the
949
+ * originating chat session's memory. Without this, bg: tasks finish,
950
+ * deliver their result to Discord/Slack, and then the very next chat
951
+ * turn comes back to an assistant that has zero memory of any of it —
952
+ * the user asks "fix the site you just deployed" and gets "I don't see
953
+ * any record of a Netlify site." injectContext writes into both the
954
+ * pending-context map (visible to the next SDK turn) and the memory
955
+ * store (searchable later by the assistant).
956
+ */
957
+ mirrorBackgroundTaskToChat(sessionKey, userTextPlaceholder, assistantText) {
958
+ if (!sessionKey)
959
+ return;
960
+ try {
961
+ this.gateway.injectContext(sessionKey, userTextPlaceholder, assistantText, {
962
+ pending: false,
963
+ model: 'bg-task',
964
+ countExchange: true,
965
+ });
966
+ }
967
+ catch (err) {
968
+ logger.debug({ err, sessionKey }, 'Failed to mirror background task message into chat memory');
969
+ }
970
+ }
947
971
  /** Same idea for workflows. Workflows can be agent-scoped via WorkflowDefinition.agentSlug. */
948
972
  dispatchContextForWorkflow(name) {
949
973
  const wf = this.workflowDefs.find(w => w.name === name);
@@ -1915,9 +1939,15 @@ export class CronScheduler {
1915
1939
  lastNotifiedAt: new Date().toISOString(),
1916
1940
  progressMessageCount: 0,
1917
1941
  });
1942
+ const startMessage = `**Background task ${started.id} started** — ${started.prompt.slice(0, 120).replace(/\s+/g, ' ')}${started.prompt.length > 120 ? '...' : ''}\n\nI'll update you every 15 minutes or when it finishes.`;
1918
1943
  this.dispatcher
1919
- .send(`**Background task ${started.id} started** — ${started.prompt.slice(0, 120).replace(/\s+/g, ' ')}${started.prompt.length > 120 ? '...' : ''}\n\nI'll update you every 15 minutes or when it finishes.`, this.dispatchContextForBackgroundTask(started))
1944
+ .send(startMessage, this.dispatchContextForBackgroundTask(started))
1920
1945
  .catch((err) => logger.debug({ err, id: started.id }, 'Failed to dispatch background task start'));
1946
+ // Mirror the start announcement into the originating chat session's
1947
+ // memory so the assistant remembers it has a task running. Without
1948
+ // this, the next chat turn the user sends comes back to a session
1949
+ // that has no idea any bg: work was ever queued.
1950
+ this.mirrorBackgroundTaskToChat(started.sessionKey, `[Background task ${started.id} queued: ${started.prompt.slice(0, 200)}]`, startMessage);
1921
1951
  // Don't await — fire-and-forget. The 3s tick continues to scan.
1922
1952
  const maxHours = Math.max(0.05, started.maxMinutes / 60);
1923
1953
  const progressTimer = setInterval(() => {
@@ -1956,9 +1986,14 @@ export class CronScheduler {
1956
1986
  const completed = loadBackgroundTask(started.id) ?? started;
1957
1987
  const deliveryHead = `**Background task ${started.id} done** — ${started.prompt.slice(0, 100).replace(/\s+/g, ' ')}${started.prompt.length > 100 ? '...' : ''}\n\n`;
1958
1988
  const body = (result ?? '').slice(0, 1500);
1989
+ const deliveryMessage = deliveryHead + body;
1959
1990
  this.dispatcher
1960
- .send(deliveryHead + body, this.dispatchContextForBackgroundTask(completed))
1991
+ .send(deliveryMessage, this.dispatchContextForBackgroundTask(completed))
1961
1992
  .catch((err) => logger.debug({ err, id: started.id }, 'Failed to dispatch background task result'));
1993
+ // Mirror into chat memory so a follow-up like "fix the site"
1994
+ // doesn't get a blank stare — the assistant needs to remember
1995
+ // it just deployed something and where it lives.
1996
+ this.mirrorBackgroundTaskToChat(completed.sessionKey, `[Background task ${completed.id} delivered: ${started.prompt.slice(0, 200)}]`, deliveryMessage);
1962
1997
  }).catch((err) => {
1963
1998
  clearInterval(progressTimer);
1964
1999
  const errStr = String(err).slice(0, 500);
@@ -1969,9 +2004,13 @@ export class CronScheduler {
1969
2004
  logger.warn({ err: saveErr, id: started.id }, 'Failed to mark background task failed');
1970
2005
  }
1971
2006
  const failed = loadBackgroundTask(started.id) ?? started;
2007
+ const failMessage = `**Background task ${started.id} failed** — ${errStr.slice(0, 200)}`;
1972
2008
  this.dispatcher
1973
- .send(`**Background task ${started.id} failed** — ${errStr.slice(0, 200)}`, this.dispatchContextForBackgroundTask(failed))
2009
+ .send(failMessage, this.dispatchContextForBackgroundTask(failed))
1974
2010
  .catch(() => { });
2011
+ // Mirror failures too — the next chat turn should know the task
2012
+ // died rather than silently pretending it never happened.
2013
+ this.mirrorBackgroundTaskToChat(failed.sessionKey, `[Background task ${failed.id} failed: ${started.prompt.slice(0, 200)}]`, failMessage);
1975
2014
  });
1976
2015
  }
1977
2016
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clementine-agent",
3
- "version": "1.18.179",
3
+ "version": "1.18.180",
4
4
  "description": "Clementine — Personal AI Assistant (TypeScript)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",