Skip to content

A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.

fix(claude): 按 Claude Code 的 turnPosition 认轮次,别的会话发来的消息也算一轮

chipfightera63a49c9ce7e
diff --git a/plugin/src/claude-index.ts b/plugin/src/claude-index.ts
index c9062cc..0453724 100644
--- a/plugin/src/claude-index.ts
+++ b/plugin/src/claude-index.ts
@@ -113,9 +113,12 @@ export function activeChain(records: ClaudeRecord[]): ClaudeRecord[] {
}
// A prompt the user sent (or a delivery queued as one): not a tool result, not Claude Code's own meta message or a
-// compaction summary.
+// compaction summary. Claude Code 2.1.293 marks the record that starts a turn with turnPosition, also for a message
+// another session delivered (a meta record, origin "peer"); without that mark, a meta record starts none.
export function isPrompt(record: ClaudeRecord): boolean {
- if (record.type !== "user" || record.isMeta || record.isCompactSummary || record.toolUseResult !== undefined) return false;
+ if (record.type !== "user" || record.isCompactSummary || record.toolUseResult !== undefined) return false;
+ if (record.turnPosition && typeof record.turnPosition === "object") return true;
+ if (record.isMeta) return false;
const content = record.message?.content;
if (typeof content === "string") return true;
return Array.isArray(content) && content.some((block: Json) => block?.type !== "tool_result");
diff --git a/spike/src/claude-index.test.ts b/spike/src/claude-index.test.ts
index f1d50f3..ff757bd 100644
--- a/spike/src/claude-index.test.ts
+++ b/spike/src/claude-index.test.ts
@@ -103,3 +103,18 @@ test("a transcript is found by session id under projects/, and read again as it
assert.deepEqual(loadClaudeIndex(id, home).images.map((entry) => entry.id), ["IMG-001", "IMG-002"]);
assert.equal(loadClaudeIndex("22222222-2222-4333-8444-555555555555", home).images.length, 0);
});
+
+test("a prompt is a record Claude Code numbers as a turn (turnPosition), a message from another session included", () => {
+ const t = transcript();
+ t.prompt("first", { turnPosition: { promptIndex: 0, turnIndex: 1 } });
+ t.assistant(text("ok"));
+ // A delivery from another session is a meta record, but Claude Code counts it as the turn it starts.
+ t.prompt("Another Claude session sent a message: read c.png", { isMeta: true, origin: { kind: "peer" }, turnPosition: { promptIndex: 0, turnIndex: 2 } });
+ t.assistant({ type: "tool_use", id: "toolu_7", name: "Read", input: { file_path: "c.png" } });
+ t.toolResult("toolu_7", [image(pngC)]);
+ // A meta record without a turn of its own (Claude Code's own reminders) starts none.
+ t.prompt("<system-reminder>x</system-reminder>", { isMeta: true });
+ const index = buildClaudeIndex("s", t.records);
+ assert.equal(index.turns, 2);
+ assert.equal(index.images[0].turn, 2);
+});