jg-agent-hq 10.5.1 → 10.5.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 10.5.3
4
+
5
+ - Leave a Claude subagent's stream frames, which name the Agent call that started it, out of a session's live items and turns. History leaves the subagent's sidechain out, so its prompt, tool calls and results stayed `awaiting-flush` after the session's answer, its prompt read as the operator's message, and a background subagent's frames after the session's turn started a turn of Claude's own that never ended, which held the next message as starting. A subagent's tool results still settle the approvals it asked for.
6
+
7
+ ## 10.5.2
8
+
9
+ - Show a Claude tool result made of content blocks, such as a browser tool's caption and screenshot, as its text, with each image as `[Image]`. Such results used to read `[Native tool_result]`.
10
+
3
11
  ## 10.5.1
4
12
 
5
13
  - Read a compacted Claude session to the start of its conversation. A compaction starts a new chain whose boundary has no parent and names the record before it as its logical parent, and history used to stop there. Every indexed transcript is indexed again after the upgrade.
package/api/README.md CHANGED
@@ -241,7 +241,7 @@ The existing SQLite worker incrementally records file identity, complete-line of
241
241
 
242
242
  Current-chain membership and turn starts are indexed as metadata. Ordinary item and turn continuations seek those indexes; they do not walk the full chain per page. A changed branch rebuilds membership before exposing that revision. Repeated native message identities can replace content while retaining their parent; a changed parent for the same identity is an unsupported format.
243
243
 
244
- Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item and turn continuations. Only the current parent-linked conversation chain is returned. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
244
+ Selected history reads refresh only that file, retain incomplete tails, and detect truncation or replaced identity. Changed branch/file revisions invalidate item and turn continuations. Only the current parent-linked conversation chain is returned. Text is reread from the native file for the selected page and normalized as plain text. Thinking blocks are left out, and a record holding only thinking is hidden, as are `<task-notification>` records and a subagent's sidechain records. Live items leave a subagent's stream frames out likewise, and those frames start no turn, though a subagent's tool results still settle the approvals it asked for. Compaction summaries, `<local-command-stdout>` output and interruption markers are `notice` items, and a slash command is a `user-message` reading `/name args`. A `!` shell input and its output are `command` items, the output's `callId` being the input's UUID. A tool call shows its native name and input, with the block's ID as `callId`, which is null for a record calling several tools; its result is a `tool` item carrying that ID, `failed` when it has `is_error` and `succeeded` otherwise. An Edit or Write result whose metadata has a `filePath` and a `structuredPatch` is a `file-change` item reading the path and its patch lines, or a created file's content, every line of which counts as added. A result Claude Code saved to a file reads `Output too large (<size>), saved to a file` followed by its preview, without the file's path. A result made of content blocks, such as a screenshot with its caption, reads as its text blocks, each image as `[Image]`. Other non-text content has explicit native block labels. The index stores each entry's presented kind and visibility, so evidence kind filters match `items` and hidden records never shorten a page. An unknown record containing content is returned as an `unsupported` item when its identity and chain are trustworthy; it cannot imply an agent response, idle state or completion. Each selected page reads at most 4 MiB of record bytes beyond its first record and returns at most 4 MiB of serialized item presentation, so a large-text page can contain fewer rows than its requested limit.
245
245
 
246
246
  File timestamps and records do not prove that a native process is idle or a turn completed. Claude file-backed thread and turn states are therefore `unknown`, with no invented completion timestamp. Explicit native custom titles are preserved; a missing title remains null. A turn starts at a message the operator sends, including a slash command; task notifications, compaction summaries, local command output, interruption markers and `!` shell records belong to the turn before them. Grouping follows parent links and is not an authoritative execution boundary. A compaction starts a new chain whose first record names the record before it, so history reads on past the compaction to the start of the conversation.
247
247
 
@@ -5,7 +5,12 @@ import { RecordSchema, toClaudeItem } from '../history/index.js';
5
5
  import { MAX_RESULT_BYTES } from '../../../contracts/index.js';
6
6
  import { toTurnResult } from '../../results/index.js';
7
7
  import { createClaudePrompt } from './permissions.js';
8
- const FrameSchema = z.object({ type: z.string(), session_id: z.string().optional() });
8
+ const FrameSchema = z.object({
9
+ type: z.string(),
10
+ session_id: z.string().optional(),
11
+ // the Agent call whose subagent a frame comes from, which history keeps out of the session
12
+ parent_tool_use_id: z.string().nullish(),
13
+ });
9
14
  const MessageSchema = z.object({
10
15
  uuid: z.string().min(1).max(4096),
11
16
  message: z.object({ role: z.string(), content: z.unknown() }),
@@ -135,6 +140,26 @@ const endTurn = (session, events) => {
135
140
  session.previews.clear();
136
141
  session.requests.clear();
137
142
  };
143
+ /** Settles the approvals a user frame's tool results answer, as Claude ran or refused each tool. */
144
+ const resolveRequests = (session, message, events) => {
145
+ const results = ToolResultsSchema.safeParse(message.message.content);
146
+ if (!results.success)
147
+ return;
148
+ for (const result of results.data) {
149
+ if (result.type !== 'tool_result' || !result.tool_use_id)
150
+ continue;
151
+ for (const [id, request] of session.requests)
152
+ if (request.toolId === result.tool_use_id) {
153
+ events?.observe({
154
+ kind: 'request-resolved',
155
+ provider: 'claude',
156
+ nativeThreadId: session.id,
157
+ requestId: request.scopedId,
158
+ });
159
+ session.requests.delete(id);
160
+ }
161
+ }
162
+ };
138
163
  /**
139
164
  * Normalizes native stream evidence without retaining another conversation buffer. A turn frame
140
165
  * that arrives while no turn is active, and isn't the waiting input's replay, starts a turn of
@@ -146,6 +171,17 @@ export const receiveClaudeMessage = (session, raw, events) => {
146
171
  const frame = FrameSchema.parse(raw);
147
172
  if (frame.session_id && frame.session_id !== session.id)
148
173
  unavailable();
174
+ /*
175
+ * A subagent's frames name the Agent call that started it. History leaves its sidechain out, so
176
+ * they show no live item, start no turn and hold no result, even after the session's turn ended
177
+ * while a background subagent runs on; its tool results still settle the approvals it asked for.
178
+ */
179
+ if (frame.parent_tool_use_id &&
180
+ (frame.type === 'user' || frame.type === 'assistant' || frame.type === 'stream_event')) {
181
+ if (frame.type === 'user')
182
+ resolveRequests(session, MessageSchema.parse(raw), events);
183
+ return;
184
+ }
149
185
  if (frame.type === 'user' || frame.type === 'assistant') {
150
186
  const message = MessageSchema.parse(raw);
151
187
  const isReplay = frame.type === 'user' && session.input !== undefined && message.uuid === session.input.id;
@@ -208,24 +244,8 @@ export const receiveClaudeMessage = (session, raw, events) => {
208
244
  }
209
245
  if (item)
210
246
  events?.item(session.id, item, true, replacedIds);
211
- if (frame.type === 'user') {
212
- const results = ToolResultsSchema.safeParse(message.message.content);
213
- if (results.success)
214
- for (const result of results.data) {
215
- if (result.type !== 'tool_result' || !result.tool_use_id)
216
- continue;
217
- for (const [id, request] of session.requests)
218
- if (request.toolId === result.tool_use_id) {
219
- events?.observe({
220
- kind: 'request-resolved',
221
- provider: 'claude',
222
- nativeThreadId: session.id,
223
- requestId: request.scopedId,
224
- });
225
- session.requests.delete(id);
226
- }
227
- }
228
- }
247
+ if (frame.type === 'user')
248
+ resolveRequests(session, message, events);
229
249
  }
230
250
  else if (frame.type === 'stream_event') {
231
251
  const turn = getActiveTurn(session) ?? startNativeTurn(session, events);
@@ -161,8 +161,23 @@ const COMMAND = /^<command-(?:message|name)>/;
161
161
  const COMMAND_NAME = /<command-name>\/?([^<]*)<\/command-name>/;
162
162
  const COMMAND_ARGS = /<command-args>([\s\S]*?)<\/command-args>/;
163
163
  const PERSISTED_OUTPUT = /^<persisted-output>\nOutput too large \(([^)\n]{1,64})\)\. Full output saved to: [^\n]*\n\nPreview \([^)\n]*\):\n([\s\S]*?)\n?<\/persisted-output>([\s\S]*)$/;
164
- /** Shows a result saved to a file as its size and preview, without the file's path. */
164
+ // a part of a tool result made of content blocks, as the CLI shows it, with an image as [Image]
165
+ const toResultPartText = (part) => {
166
+ const block = BlockSchema.safeParse(part).data;
167
+ if (!block)
168
+ return UNSUPPORTED;
169
+ if (block.type === 'text')
170
+ return block.text ?? '';
171
+ return block.type === 'image' ? '[Image]' : `[Native ${block.type}]`;
172
+ };
173
+ /**
174
+ * Shows a tool result as the CLI does: its text, the parts of one made of content blocks, such as
175
+ * a screenshot's caption and image, and one saved to a file as its size and preview, without the
176
+ * file's path.
177
+ */
165
178
  const toResultText = (block) => {
179
+ if (Array.isArray(block.content))
180
+ return block.content.map(toResultPartText).join('\n');
166
181
  if (typeof block.content !== 'string')
167
182
  return `[Native ${block.type}]`;
168
183
  const persisted = PERSISTED_OUTPUT.exec(block.content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jg-agent-hq",
3
- "version": "10.5.1",
3
+ "version": "10.5.3",
4
4
  "description": "Native Claude Code and Codex session control, history, usage and recoverable local storage for Node.js apps.",
5
5
  "type": "module",
6
6
  "license": "MIT",