@staff0rd/assist 0.704.3 → 0.704.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.
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.704.3",
9
+ version: "0.704.5",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -40912,11 +40912,13 @@ function ensureProjectDirExists(dir, sessionId) {
40912
40912
 
40913
40913
  // src/commands/sessions/shared/normalizeUser.ts
40914
40914
  var INTERRUPT_PREFIX = "[Request interrupted";
40915
+ var TASK_NOTIFICATION = "<task-notification>";
40915
40916
  function normalizeUser(entry) {
40916
40917
  const content = asRecord(entry.message)?.content;
40917
- if (typeof content === "string")
40918
- return isInterruptText(content) ? { kind: "interrupt" } : { kind: "user" };
40918
+ if (typeof content === "string") return normalizeUserText(content);
40919
40919
  if (!Array.isArray(content)) return { kind: "user" };
40920
+ if (content.length === 1 && asRecord(content[0])?.type === "text")
40921
+ return normalizeUserText(asRecord(content[0])?.text);
40920
40922
  const toolResultIds = [];
40921
40923
  let hasInterrupt = false;
40922
40924
  let hasNonToolResult = false;
@@ -40938,6 +40940,12 @@ function normalizeUser(entry) {
40938
40940
  function asRecord(value) {
40939
40941
  return value && typeof value === "object" ? value : null;
40940
40942
  }
40943
+ function normalizeUserText(text18) {
40944
+ if (isInterruptText(text18)) return { kind: "interrupt" };
40945
+ if (typeof text18 === "string" && text18.trimStart().startsWith(TASK_NOTIFICATION))
40946
+ return { kind: "taskNotification" };
40947
+ return { kind: "user" };
40948
+ }
40941
40949
  function isInterruptText(value) {
40942
40950
  return typeof value === "string" && value.startsWith(INTERRUPT_PREFIX);
40943
40951
  }
@@ -40975,6 +40983,10 @@ function asRecord2(value) {
40975
40983
  // src/commands/sessions/shared/deriveTranscriptStatus.ts
40976
40984
  var ASK_USER_QUESTION2 = "AskUserQuestion";
40977
40985
  var TURN_END_STOP_REASONS = /* @__PURE__ */ new Set(["end_turn", "stop_sequence"]);
40986
+ var NON_DECISIVE_KINDS = /* @__PURE__ */ new Set([
40987
+ "toolResult",
40988
+ "taskNotification"
40989
+ ]);
40978
40990
  function deriveTranscriptStatus(entries, opts = {}) {
40979
40991
  const events = normalizeTranscriptEvents(entries);
40980
40992
  const lastIdx = lastDecisiveIndex(events);
@@ -40982,7 +40994,7 @@ function deriveTranscriptStatus(entries, opts = {}) {
40982
40994
  const ev = events[lastIdx];
40983
40995
  if (ev.kind === "interrupt") return "waiting";
40984
40996
  if (ev.kind === "user") return "running";
40985
- if (ev.kind === "toolResult") return null;
40997
+ if (ev.kind === "toolResult" || ev.kind === "taskNotification") return null;
40986
40998
  if (ev.stopReason != null && TURN_END_STOP_REASONS.has(ev.stopReason))
40987
40999
  return "waiting";
40988
41000
  if (opts.permissionActive) return "waiting";
@@ -40994,7 +41006,7 @@ function deriveTranscriptStatus(entries, opts = {}) {
40994
41006
  }
40995
41007
  function lastDecisiveIndex(events) {
40996
41008
  for (let i = events.length - 1; i >= 0; i--)
40997
- if (events[i].kind !== "toolResult") return i;
41009
+ if (!NON_DECISIVE_KINDS.has(events[i].kind)) return i;
40998
41010
  return -1;
40999
41011
  }
41000
41012
  function resolvedToolUseIds(events, afterIdx) {
@@ -42138,32 +42150,76 @@ function daemonRestartPrompt(backgroundTaskIds) {
42138
42150
  return `${preamble} It killed ${backgroundTaskIds.length} background task(s) that were still running (${backgroundTaskIds.join(", ")}); their output files end where the kill landed, with no exit code. Treat them as killed by the restart, not as interrupted by the user, and restart any of them that should still be running.`;
42139
42151
  }
42140
42152
 
42153
+ // src/commands/sessions/shared/asRecord.ts
42154
+ function asRecord4(value) {
42155
+ return value && typeof value === "object" ? value : null;
42156
+ }
42157
+
42158
+ // src/commands/sessions/shared/deliberatelyStoppedTaskIds.ts
42159
+ var STOP_TOOLS = /* @__PURE__ */ new Set(["KillShell", "KillBash", "TaskStop"]);
42160
+ function deliberatelyStoppedTaskIds(entry) {
42161
+ if (entry.type !== "assistant") return [];
42162
+ const content = asRecord4(entry.message)?.content;
42163
+ if (!Array.isArray(content)) return [];
42164
+ const ids = [];
42165
+ for (const block of content) {
42166
+ const b = asRecord4(block);
42167
+ if (b?.type !== "tool_use" || !STOP_TOOLS.has(String(b.name))) continue;
42168
+ const input = asRecord4(b.input);
42169
+ const id = input?.task_id ?? input?.shell_id ?? input?.bash_id;
42170
+ if (typeof id === "string") ids.push(id);
42171
+ }
42172
+ return ids;
42173
+ }
42174
+
42175
+ // src/commands/sessions/shared/notifiedTasks.ts
42176
+ var NOTIFICATION = /<task-notification>([\s\S]*?)<\/task-notification>/g;
42177
+ var TASK_ID = /<task-id>([^<]+)<\/task-id>/;
42178
+ var STATUS = /<status>([^<]+)<\/status>/;
42179
+ function notifiedTasks(entry) {
42180
+ const text18 = taskNotificationText(entry);
42181
+ if (!text18) return [];
42182
+ const tasks = [];
42183
+ for (const [, body] of text18.matchAll(NOTIFICATION)) {
42184
+ const id = body.match(TASK_ID)?.[1];
42185
+ if (id) tasks.push({ id, status: body.match(STATUS)?.[1]?.trim() });
42186
+ }
42187
+ return tasks;
42188
+ }
42189
+ function taskNotificationText(entry) {
42190
+ const content = asRecord4(entry.message)?.content ?? entry.content;
42191
+ return typeof content === "string" && content.includes("<task-notification>") ? content : void 0;
42192
+ }
42193
+
42141
42194
  // src/commands/sessions/shared/unfinishedBackgroundTasks.ts
42142
- var TASK_ID = /<task-id>([^<]+)<\/task-id>/g;
42195
+ var KILLED_STATUSES = /* @__PURE__ */ new Set(["killed", "stopped"]);
42143
42196
  function unfinishedBackgroundTasks(entries) {
42144
42197
  const inFlight2 = /* @__PURE__ */ new Set();
42198
+ const killedAwaitingTurn = /* @__PURE__ */ new Set();
42145
42199
  for (const entry of entries) {
42146
42200
  const started = startedTaskId(entry);
42147
42201
  if (started) inFlight2.add(started);
42148
- for (const notified of notifiedTaskIds(entry)) inFlight2.delete(notified);
42202
+ for (const finished2 of selfFinishedTaskIds(entry))
42203
+ inFlight2.delete(finished2);
42204
+ for (const killed of killedTaskIds(entry)) killedAwaitingTurn.add(killed);
42205
+ for (const stopped of deliberatelyStoppedTaskIds(entry))
42206
+ inFlight2.delete(stopped);
42207
+ if (entry.type === "assistant") {
42208
+ for (const handled of killedAwaitingTurn) inFlight2.delete(handled);
42209
+ killedAwaitingTurn.clear();
42210
+ }
42149
42211
  }
42150
42212
  return [...inFlight2];
42151
42213
  }
42214
+ function killedTaskIds(entry) {
42215
+ return notifiedTasks(entry).filter(({ status: status3 }) => status3 && KILLED_STATUSES.has(status3)).map(({ id }) => id);
42216
+ }
42152
42217
  function startedTaskId(entry) {
42153
42218
  const result = asRecord4(entry.toolUseResult);
42154
42219
  return typeof result?.backgroundTaskId === "string" ? result.backgroundTaskId : void 0;
42155
42220
  }
42156
- function notifiedTaskIds(entry) {
42157
- const text18 = taskNotificationText(entry);
42158
- if (!text18) return [];
42159
- return [...text18.matchAll(TASK_ID)].map((match) => match[1]);
42160
- }
42161
- function taskNotificationText(entry) {
42162
- const content = asRecord4(entry.message)?.content ?? entry.content;
42163
- return typeof content === "string" && content.includes("<task-notification>") ? content : void 0;
42164
- }
42165
- function asRecord4(value) {
42166
- return value && typeof value === "object" ? value : null;
42221
+ function selfFinishedTaskIds(entry) {
42222
+ return notifiedTasks(entry).filter(({ status: status3 }) => !(status3 && KILLED_STATUSES.has(status3))).map(({ id }) => id);
42167
42223
  }
42168
42224
 
42169
42225
  // src/commands/sessions/daemon/interruptedBackgroundTasks.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.704.3",
3
+ "version": "0.704.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {