portable-agent-layer 0.84.4 → 0.84.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/package.json +1 -1
- package/src/hooks/lib/transcript.ts +32 -2
package/package.json
CHANGED
|
@@ -31,15 +31,44 @@ function claudeCodeEntryText(msg: { content?: unknown }): string {
|
|
|
31
31
|
return "";
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
interface CodexPayload {
|
|
35
|
+
role?: string;
|
|
36
|
+
content?: unknown;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const CODEX_INJECTED_CONTEXT = ["# AGENTS.md instructions", "<environment_context>"];
|
|
40
|
+
|
|
41
|
+
function isCodexInjectedContext(text: string): boolean {
|
|
42
|
+
return CODEX_INJECTED_CONTEXT.some((prefix) => text.startsWith(prefix));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function codexTexts(content: unknown): string[] {
|
|
46
|
+
if (!Array.isArray(content)) return [];
|
|
47
|
+
return content
|
|
48
|
+
.map((part) => part?.text)
|
|
49
|
+
.filter((text): text is string => typeof text === "string" && text.length > 0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function codexMessage(payload: CodexPayload | undefined): Message | null {
|
|
53
|
+
const role = payload?.role;
|
|
54
|
+
if (role !== "user" && role !== "assistant") return null;
|
|
55
|
+
const texts = codexTexts(payload?.content).filter(
|
|
56
|
+
(text) => !isCodexInjectedContext(text)
|
|
57
|
+
);
|
|
58
|
+
return texts.length > 0 ? { role, content: texts.join(" ") } : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
34
61
|
// Claude Code tags transcript lines `type: "user"|"assistant"` with the text
|
|
35
62
|
// under `message.content`. VS Code Copilot's own event log instead uses
|
|
36
63
|
// `type: "user.message"|"assistant.message"` with a flat `data.content`
|
|
37
|
-
// string
|
|
64
|
+
// string. Codex nests each message as a `response_item` payload.
|
|
38
65
|
function parseTranscriptEntry(entry: {
|
|
39
66
|
type?: string;
|
|
40
67
|
message?: { content?: unknown };
|
|
41
68
|
data?: { content?: unknown };
|
|
69
|
+
payload?: CodexPayload;
|
|
42
70
|
}): Message | null {
|
|
71
|
+
if (entry.type === "response_item") return codexMessage(entry.payload);
|
|
43
72
|
if (entry.type === "user" || entry.type === "assistant") {
|
|
44
73
|
const text = claudeCodeEntryText(entry.message ?? {});
|
|
45
74
|
return text ? { role: entry.type, content: text } : null;
|
|
@@ -55,7 +84,8 @@ function parseTranscriptEntry(entry: {
|
|
|
55
84
|
/**
|
|
56
85
|
* Read an agent transcript JSONL file and extract user/assistant messages.
|
|
57
86
|
* Supports Claude Code's `{type:"user"|"assistant", message:{content}}` shape
|
|
58
|
-
*
|
|
87
|
+
* VS Code Copilot's `{type:"user.message"|"assistant.message", data:{content}}` shape,
|
|
88
|
+
* and Codex's `{type:"response_item", payload:{type:"message", role, content}}` shape.
|
|
59
89
|
*/
|
|
60
90
|
export function readTranscriptFile(path: string): Message[] {
|
|
61
91
|
try {
|