castle-web-cli 0.4.57 → 0.4.58

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.
@@ -1,6 +1,7 @@
1
1
  export interface PromptMessage {
2
2
  role: "user" | "assistant";
3
3
  text: string;
4
+ interrupted?: boolean;
4
5
  }
5
6
  export interface PromptTask {
6
7
  id: string;
@@ -16,7 +17,7 @@ export declare function buildRouterPrompt(opts: {
16
17
  instruction: string;
17
18
  }): string;
18
19
  export declare function userTurnInstruction(opts: {
19
- text: string;
20
+ messages: string[];
20
21
  interruptedDraft?: string;
21
22
  attachments?: string[];
22
23
  }): string;
@@ -61,7 +61,14 @@ function renderTranscript(messages) {
61
61
  if (recent.length === 0)
62
62
  return "(no conversation yet)";
63
63
  return recent
64
- .map((m) => `${m.role === "user" ? "user" : "you"}: ${m.text}`)
64
+ .map((m) => {
65
+ if (m.role === "user")
66
+ return `user: ${m.text}`;
67
+ const label = m.interrupted
68
+ ? "you (interrupted draft -- not a complete reply)"
69
+ : "you";
70
+ return `${label}: ${m.text}`;
71
+ })
65
72
  .join("\n\n");
66
73
  }
67
74
  function renderTasks(tasks) {
@@ -94,9 +101,17 @@ Reply now, as "you" in the conversation. Plain reply text only -- no role prefix
94
101
  export function userTurnInstruction(opts) {
95
102
  const parts = [];
96
103
  if (opts.interruptedDraft?.trim()) {
97
- parts.push(`Your previous reply was interrupted mid-stream by the user's new message. Its draft so far (already shown to the user; NO tasks were spawned from it):\n\n${opts.interruptedDraft.trim()}\n\nContinue that line of work AND address the new message -- do both in this one reply, spawning whatever tasks are needed for either.`);
104
+ parts.push(`Your previous reply was interrupted mid-stream by the user's new message. Its draft so far (already shown to the user; NO tasks were spawned from it):\n\n${opts.interruptedDraft.trim()}\n\nContinue that line of work AND address the new message(s) -- do it all in this one reply, spawning whatever tasks are needed.`);
105
+ }
106
+ const msgs = opts.messages.filter((m) => m.trim());
107
+ if (msgs.length <= 1) {
108
+ parts.push(`The user just said:\n\n${msgs[0] ?? ""}`);
109
+ }
110
+ else {
111
+ parts.push(`The user sent these messages -- the earlier ones arrived while you were mid-reply and have NOT been answered yet. Address ALL of them in this one reply, in order. Exception: if a later message clearly clarifies, corrects, or takes back an earlier one, follow the later intent and don't redo work the user reversed. By default, cover every message:\n\n${msgs
112
+ .map((t, i) => `${i + 1}. ${t}`)
113
+ .join("\n\n")}`);
98
114
  }
99
- parts.push(`The user just said:\n\n${opts.text}`);
100
115
  if (opts.attachments && opts.attachments.length > 0) {
101
116
  parts.push(`The user attached image file(s), saved in the deck at: ${opts.attachments.join(", ")}. Open them with your read tool and take them into account; pass the paths along to task agents that need them.`);
102
117
  }
package/dist/agent.js CHANGED
@@ -793,7 +793,11 @@ function runRouterTurnIn(ctx, instruction) {
793
793
  deckLabel: ctx.deckLabel,
794
794
  messages: ctx.log.messages
795
795
  .filter((m) => m.role !== 'log' && m.id !== message.id && m.status !== 'streaming')
796
- .map((m) => ({ role: m.role, text: m.text })),
796
+ .map((m) => ({
797
+ role: m.role,
798
+ text: m.text,
799
+ interrupted: m.interrupted,
800
+ })),
797
801
  // Only the live board -- match what the user sees. Hide tasks that are
798
802
  // BOTH acknowledged AND finished; an active (running/waiting) task always
799
803
  // shows even if somehow acked, so nothing can ever go invisible mid-work.
@@ -1036,6 +1040,20 @@ export function createAgentServer(opts) {
1036
1040
  claudeModel: () => settings.claudeModel,
1037
1041
  }, instruction);
1038
1042
  }
1043
+ // User messages awaiting a reply: everything since the last COMPLETED (done,
1044
+ // not interrupted) assistant message. Usually just the latest, but a rapid
1045
+ // burst leaves several queued -- all must be addressed, not only the last.
1046
+ function pendingUserMessages() {
1047
+ let lastAnswered = -1;
1048
+ for (let i = messages.length - 1; i >= 0; i--) {
1049
+ const m = messages[i];
1050
+ if (m.role === 'assistant' && m.status === 'done' && !m.interrupted) {
1051
+ lastAnswered = i;
1052
+ break;
1053
+ }
1054
+ }
1055
+ return messages.slice(lastAnswered + 1).filter((m) => m.role === 'user');
1056
+ }
1039
1057
  function handleUserMessage(text, images) {
1040
1058
  userEpoch += 1;
1041
1059
  const interruptedDraft = interruptRouterRuns();
@@ -1051,10 +1069,15 @@ export function createAgentServer(opts) {
1051
1069
  if (attachments.length > 0)
1052
1070
  message.attachments = attachments;
1053
1071
  log.add(message);
1072
+ // Address every still-unanswered user message (this one plus any earlier
1073
+ // burst messages that interrupted prior turns), not just the latest.
1074
+ const pending = pendingUserMessages();
1054
1075
  runRouterTurn(userTurnInstruction({
1055
- text,
1076
+ messages: pending.map((m) => m.text),
1056
1077
  interruptedDraft: interruptedDraft || undefined,
1057
- attachments: attachments.map((name) => path.join('.castle', 'agent', 'attachments', name)),
1078
+ attachments: pending
1079
+ .flatMap((m) => m.attachments ?? [])
1080
+ .map((name) => path.join('.castle', 'agent', 'attachments', name)),
1058
1081
  }));
1059
1082
  }
1060
1083
  function handleTaskAck(id, rejected) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.57",
3
+ "version": "0.4.58",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "castle-web": "./dist/index.js"