@tryglen/cli 0.26.1 → 0.26.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/_utils/build-turn-body.d.ts +2 -0
- package/dist/_utils/build-turn-body.js.map +1 -1
- package/dist/_utils/config.d.ts +1 -0
- package/dist/_utils/config.js +1 -0
- package/dist/_utils/config.js.map +1 -1
- package/dist/_utils/extract-claude-segments.d.ts +2 -0
- package/dist/_utils/extract-claude-segments.js +53 -0
- package/dist/_utils/extract-claude-segments.js.map +1 -0
- package/dist/_utils/extract-codex-segments.d.ts +2 -0
- package/dist/_utils/extract-codex-segments.js +74 -0
- package/dist/_utils/extract-codex-segments.js.map +1 -0
- package/dist/_utils/extract-pi-segments.d.ts +2 -0
- package/dist/_utils/extract-pi-segments.js +37 -0
- package/dist/_utils/extract-pi-segments.js.map +1 -0
- package/dist/_utils/install-receipt.d.ts +8 -0
- package/dist/_utils/install-receipt.js +42 -1
- package/dist/_utils/install-receipt.js.map +1 -1
- package/dist/_utils/parse-claude-transcript.js +29 -5
- package/dist/_utils/parse-claude-transcript.js.map +1 -1
- package/dist/_utils/parse-codex-transcript.js +46 -8
- package/dist/_utils/parse-codex-transcript.js.map +1 -1
- package/dist/_utils/parse-pi-transcript.js +85 -8
- package/dist/_utils/parse-pi-transcript.js.map +1 -1
- package/dist/_utils/parse-transcript.d.ts +3 -0
- package/dist/_utils/parse-transcript.js +38 -2
- package/dist/_utils/parse-transcript.js.map +1 -1
- package/dist/_utils/post-route.d.ts +3 -1
- package/dist/_utils/post-route.js +2 -2
- package/dist/_utils/post-route.js.map +1 -1
- package/dist/_utils/report-cli-install.d.ts +2 -0
- package/dist/_utils/report-cli-install.js +17 -0
- package/dist/_utils/report-cli-install.js.map +1 -0
- package/dist/_utils/transcript-turns.d.ts +8 -1
- package/dist/_utils/transcript-turns.js +146 -2
- package/dist/_utils/transcript-turns.js.map +1 -1
- package/dist/commands/ingest.js +12 -1
- package/dist/commands/ingest.js.map +1 -1
- package/dist/commands/install.js +14 -4
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/login.js +2 -0
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/takeover/_utils/write-codex-desktop-session.d.ts +3 -3
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { extractPiSegments } from "./extract-pi-segments.js";
|
|
1
2
|
import { normalizeTranscriptTimestamp } from "./normalize-transcript-timestamp.js";
|
|
2
3
|
const parseLine = (line) => {
|
|
3
4
|
try {
|
|
@@ -13,6 +14,68 @@ const parseLine = (line) => {
|
|
|
13
14
|
const messageOf = (e) => e.message !== null && typeof e.message === "object"
|
|
14
15
|
? e.message
|
|
15
16
|
: null;
|
|
17
|
+
const str = (v) => (typeof v === "string" ? v : "");
|
|
18
|
+
// A pi `toolResult`/`bashExecution` message's output text: toolResult's
|
|
19
|
+
// `content` is a string OR an array of {text} blocks; bashExecution's
|
|
20
|
+
// `output` is always a flat string.
|
|
21
|
+
const outputTextOf = (content) => {
|
|
22
|
+
if (typeof content === "string")
|
|
23
|
+
return content;
|
|
24
|
+
if (Array.isArray(content))
|
|
25
|
+
return content
|
|
26
|
+
.filter((p) => typeof p?.text === "string")
|
|
27
|
+
.map((p) => p.text)
|
|
28
|
+
.join("\n");
|
|
29
|
+
return "";
|
|
30
|
+
};
|
|
31
|
+
// toolResult/bashExecution are separate pi ENTRY types (not content blocks
|
|
32
|
+
// inside a message), so they cannot flow through extractPiSegments — build
|
|
33
|
+
// their tool_result segment directly from the entry's message payload.
|
|
34
|
+
const toolResultSegmentOf = (message) => {
|
|
35
|
+
if (message.role === "toolResult") {
|
|
36
|
+
const output = outputTextOf(message.content);
|
|
37
|
+
return {
|
|
38
|
+
kind: "tool_result",
|
|
39
|
+
text: output.slice(0, 200),
|
|
40
|
+
jsonContent: {
|
|
41
|
+
toolCallId: str(message.toolCallId),
|
|
42
|
+
output,
|
|
43
|
+
isError: message.isError === true,
|
|
44
|
+
raw: message,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (message.role === "bashExecution") {
|
|
49
|
+
const output = str(message.output);
|
|
50
|
+
return {
|
|
51
|
+
kind: "tool_result",
|
|
52
|
+
text: output.slice(0, 200),
|
|
53
|
+
jsonContent: {
|
|
54
|
+
output,
|
|
55
|
+
command: str(message.command),
|
|
56
|
+
exitCode: message.exitCode ?? null,
|
|
57
|
+
raw: message,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
// Append a lifted tool_result segment onto the trailing assistant message
|
|
64
|
+
// (toolResult/bashExecution entries always follow the assistant turn that
|
|
65
|
+
// invoked them). If there is no trailing assistant message yet, start one
|
|
66
|
+
// carrying only segments — Task 6's segment-only-message handling lets it
|
|
67
|
+
// survive downstream folding with an empty `text`.
|
|
68
|
+
const appendToolResultSegment = (messages, segment) => {
|
|
69
|
+
const last = messages[messages.length - 1];
|
|
70
|
+
if (last && last.role === "assistant") {
|
|
71
|
+
messages[messages.length - 1] = {
|
|
72
|
+
...last,
|
|
73
|
+
segments: [...(last.segments ?? []), segment],
|
|
74
|
+
};
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
messages.push({ role: "assistant", text: "", segments: [segment] });
|
|
78
|
+
};
|
|
16
79
|
// Text of a pi message: a plain string (typical human prompt) or the
|
|
17
80
|
// concatenated `text` content blocks (assistant output; thinking/toolCall/
|
|
18
81
|
// image blocks are not conversation text).
|
|
@@ -65,12 +128,14 @@ const activeBranch = (entries) => {
|
|
|
65
128
|
// Parse one pi session file (~/.pi/agent/sessions/<munged-cwd>/
|
|
66
129
|
// <timestamp>_<uuid>.jsonl) into the normalized transcript shape. The first
|
|
67
130
|
// line is a {type:"session"} header carrying the session id and cwd; entry
|
|
68
|
-
// lines wrap AgentMessages ({type:"message", id, parentId, message}).
|
|
69
|
-
// user/assistant messages are conversation text
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
131
|
+
// lines wrap AgentMessages ({type:"message", id, parentId, message}).
|
|
132
|
+
// user/assistant messages are conversation text; toolResult/bashExecution are
|
|
133
|
+
// separate entry types (not content blocks) whose output is lifted onto the
|
|
134
|
+
// preceding assistant message as a tool_result segment. Custom-role messages
|
|
135
|
+
// are extension-injected context (glen's own per-turn recall arrives as
|
|
136
|
+
// customType "glen-context"; importing it would feed glen's output back in as
|
|
137
|
+
// memory). Tolerant by design: unknown entry types, missing fields, and
|
|
138
|
+
// unparseable lines are skipped, never fatal.
|
|
74
139
|
const parsePiTranscript = (lines, fallbackSessionId) => {
|
|
75
140
|
const entries = lines.map(parseLine).filter((e) => e !== null);
|
|
76
141
|
const header = entries.find((e) => e.type === "session");
|
|
@@ -78,28 +143,40 @@ const parsePiTranscript = (lines, fallbackSessionId) => {
|
|
|
78
143
|
if (e.type !== "message")
|
|
79
144
|
return false;
|
|
80
145
|
const role = messageOf(e)?.role;
|
|
81
|
-
return role === "user" ||
|
|
146
|
+
return (role === "user" ||
|
|
147
|
+
role === "assistant" ||
|
|
148
|
+
role === "toolResult" ||
|
|
149
|
+
role === "bashExecution");
|
|
82
150
|
});
|
|
83
151
|
const messages = [];
|
|
84
152
|
for (const e of conversation) {
|
|
85
153
|
const message = messageOf(e);
|
|
86
154
|
if (!message)
|
|
87
155
|
continue;
|
|
156
|
+
if (message.role === "toolResult" || message.role === "bashExecution") {
|
|
157
|
+
const segment = toolResultSegmentOf(message);
|
|
158
|
+
if (segment)
|
|
159
|
+
appendToolResultSegment(messages, segment);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
88
162
|
const occurredAt = normalizeTranscriptTimestamp(e.timestamp);
|
|
163
|
+
const segments = extractPiSegments(message);
|
|
89
164
|
if (message.role === "user")
|
|
90
165
|
messages.push({
|
|
91
166
|
role: "user",
|
|
92
167
|
text: textOf(message.content),
|
|
93
168
|
...(occurredAt ? { occurredAt } : {}),
|
|
169
|
+
...(segments.length > 0 ? { segments } : {}),
|
|
94
170
|
});
|
|
95
171
|
else
|
|
96
172
|
messages.push({
|
|
97
173
|
role: "assistant",
|
|
98
174
|
text: textOf(message.content),
|
|
99
175
|
...(occurredAt ? { occurredAt } : {}),
|
|
176
|
+
...(segments.length > 0 ? { segments } : {}),
|
|
100
177
|
});
|
|
101
178
|
}
|
|
102
|
-
if (messages.every((m) => m.text.trim() === ""))
|
|
179
|
+
if (messages.every((m) => m.text.trim() === "" && (m.segments?.length ?? 0) === 0))
|
|
103
180
|
return null;
|
|
104
181
|
// Assistant messages carry the model that produced them; the last one wins
|
|
105
182
|
// (the model can change mid-session via /model).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-pi-transcript.js","sourceRoot":"","sources":["../../src/_utils/parse-pi-transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"parse-pi-transcript.js","sourceRoot":"","sources":["../../src/_utils/parse-pi-transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AASnF,MAAM,SAAS,GAAG,CAAC,IAAY,EAAgB,EAAE;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;QAC3C,OAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ;YAClD,CAAC,CAAE,MAAgB;YACnB,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,CAAQ,EAAgB,EAAE,CAC3C,CAAC,CAAC,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,OAAO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,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;SAC/B,IAAI,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IAEnD,OAAO;QACL,SAAS,EACP,CAAC,OAAO,MAAM,EAAE,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YACxD,iBAAiB;QACnB,KAAK,EAAE,IAAI;QACX,GAAG,EAAE,OAAO,MAAM,EAAE,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;QAC7D,MAAM,EAAE,SAAS;QACjB,KAAK,EAAE,SAAS;QAChB,QAAQ;KACT,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Segment } from "./transcript-turns.js";
|
|
1
2
|
type TranscriptResult = {
|
|
2
3
|
readonly priorAssistant: string | null;
|
|
3
4
|
readonly nextUserMessageIndex: number;
|
|
@@ -5,6 +6,8 @@ type TranscriptResult = {
|
|
|
5
6
|
readonly user: string;
|
|
6
7
|
readonly assistant: string;
|
|
7
8
|
readonly userMessageIndex: number;
|
|
9
|
+
readonly userSegments?: Segment[];
|
|
10
|
+
readonly assistantSegments?: Segment[];
|
|
8
11
|
} | null;
|
|
9
12
|
};
|
|
10
13
|
declare const parseTranscript: (lines: readonly string[]) => TranscriptResult;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { extractClaudeSegments } from "./extract-claude-segments.js";
|
|
1
2
|
const extractText = (content) => {
|
|
2
3
|
if (typeof content === "string")
|
|
3
4
|
return content;
|
|
@@ -11,6 +12,26 @@ const extractText = (content) => {
|
|
|
11
12
|
const roleOf = (e) => e?.message?.role ??
|
|
12
13
|
e?.role;
|
|
13
14
|
const contentOf = (e) => extractText(e?.message?.content ?? e?.content);
|
|
15
|
+
const messageObjOf = (e) => e?.message ?? e ?? {};
|
|
16
|
+
// Claude returns tool OUTPUTS as their own `user`-role lines: a top-level
|
|
17
|
+
// `toolUseResult` field, or a `tool_result` block in the content array.
|
|
18
|
+
const isToolResultLine = (e) => {
|
|
19
|
+
const m = messageObjOf(e);
|
|
20
|
+
if (e.toolUseResult !== undefined)
|
|
21
|
+
return true;
|
|
22
|
+
const content = m.content;
|
|
23
|
+
return (Array.isArray(content) &&
|
|
24
|
+
content.some((p) => p?.type === "tool_result"));
|
|
25
|
+
};
|
|
26
|
+
// Aggregate every assistant block + lifted tool_result across [promptIndex..end]
|
|
27
|
+
// — the full completed turn's tool I/O, matching the import parser.
|
|
28
|
+
const spanAssistantSegments = (span) => span.flatMap((e) => {
|
|
29
|
+
if (roleOf(e) === "assistant")
|
|
30
|
+
return extractClaudeSegments(messageObjOf(e));
|
|
31
|
+
if (isToolResultLine(e))
|
|
32
|
+
return extractClaudeSegments(messageObjOf(e)).filter((s) => s.kind === "tool_result");
|
|
33
|
+
return [];
|
|
34
|
+
});
|
|
14
35
|
const parseLine = (l) => {
|
|
15
36
|
const r = (() => {
|
|
16
37
|
try {
|
|
@@ -41,19 +62,34 @@ const parseTranscript = (lines) => {
|
|
|
41
62
|
const assistantIndex = lastIndexOfRole(messages, "assistant");
|
|
42
63
|
if (assistantIndex < 0)
|
|
43
64
|
return null;
|
|
44
|
-
const
|
|
65
|
+
const priorMessages = messages.slice(0, assistantIndex);
|
|
66
|
+
// The completed turn's "user prompt" is the last user line that is NOT
|
|
67
|
+
// a tool-result line (tool outputs arrive as their own user-role lines).
|
|
68
|
+
const userIndex = (() => {
|
|
69
|
+
const reversedIndex = [...priorMessages]
|
|
70
|
+
.reverse()
|
|
71
|
+
.findIndex((e) => roleOf(e) === "user" && !isToolResultLine(e));
|
|
72
|
+
return reversedIndex < 0 ? -1 : priorMessages.length - 1 - reversedIndex;
|
|
73
|
+
})();
|
|
45
74
|
if (userIndex < 0)
|
|
46
75
|
return null;
|
|
47
76
|
const userMessage = messages[userIndex];
|
|
48
77
|
const assistantMessage = messages[assistantIndex];
|
|
49
78
|
if (!userMessage || !assistantMessage)
|
|
50
79
|
return null;
|
|
80
|
+
const span = messages.slice(userIndex);
|
|
81
|
+
// userMessageIndex feeds the Stop-hook idempotency key and MUST keep its
|
|
82
|
+
// pre-Task-6 value: the last user line of ANY type before the assistant
|
|
83
|
+
// (not the filtered, non-tool-result userIndex above).
|
|
84
|
+
const originalUserIndex = lastIndexOfRole(priorMessages, "user");
|
|
51
85
|
return {
|
|
52
86
|
user: contentOf(userMessage),
|
|
53
87
|
assistant: contentOf(assistantMessage),
|
|
54
88
|
userMessageIndex: messages
|
|
55
|
-
.slice(0,
|
|
89
|
+
.slice(0, originalUserIndex + 1)
|
|
56
90
|
.filter((e) => roleOf(e) === "user").length,
|
|
91
|
+
userSegments: extractClaudeSegments(messageObjOf(userMessage)),
|
|
92
|
+
assistantSegments: spanAssistantSegments(span),
|
|
57
93
|
};
|
|
58
94
|
})();
|
|
59
95
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-transcript.js","sourceRoot":"","sources":["../../src/_utils/parse-transcript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-transcript.js","sourceRoot":"","sources":["../../src/_utils/parse-transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAerE,MAAM,WAAW,GAAG,CAAC,OAAgB,EAAU,EAAE;IAC/C,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAAuC,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,MAAM,CAAC;SACtE,GAAG,CAAC,CAAC,CA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D;QACvD,MAAM,iBAAiB,GAAG,eAAe,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QACjE,OAAO;YACL,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC;YAC5B,SAAS,EAAE,SAAS,CAAC,gBAAgB,CAAC;YACtC,gBAAgB,EAAE,QAAQ;iBACvB,KAAK,CAAC,CAAC,EAAE,iBAAiB,GAAG,CAAC,CAAC;iBAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,MAAM;YAC7C,YAAY,EAAE,qBAAqB,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;YAC9D,iBAAiB,EAAE,qBAAqB,CAAC,IAAI,CAAC;SAC/C,CAAC;IACJ,CAAC,CAAC,EAAE,CAAC;IACL,OAAO;QACL,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/D,oBAAoB;QACpB,aAAa;KACd,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type CliError } from "./cli-error.js";
|
|
2
2
|
import { type Result } from "./result.js";
|
|
3
|
-
declare const postRoute: (url: string, body: Record<string, unknown
|
|
3
|
+
declare const postRoute: (url: string, body: Record<string, unknown>, options?: {
|
|
4
|
+
readonly reexecOn426?: boolean;
|
|
5
|
+
}) => Promise<Result<Record<string, unknown>, CliError>>;
|
|
4
6
|
export { postRoute };
|
|
@@ -11,7 +11,7 @@ import { cliVersion } from "./version.js";
|
|
|
11
11
|
// headers + 426/401/403 handling. The HTTP bridge maps typed errors to
|
|
12
12
|
// statuses + a JSON { error } body, so CONFLICT/NOT_FOUND surfaces its
|
|
13
13
|
// message instead of an opaque 500.
|
|
14
|
-
const postRoute = async (url, body) => {
|
|
14
|
+
const postRoute = async (url, body, options = {}) => {
|
|
15
15
|
void maybeSpawnBackgroundUpdate();
|
|
16
16
|
const creds = await readCredentials();
|
|
17
17
|
if (!creds)
|
|
@@ -32,7 +32,7 @@ const postRoute = async (url, body) => {
|
|
|
32
32
|
why: res.error.detail,
|
|
33
33
|
remedy: networkRemedy(res.error),
|
|
34
34
|
}));
|
|
35
|
-
if (res.value.status === 426)
|
|
35
|
+
if (res.value.status === 426 && options.reexecOn426 !== false)
|
|
36
36
|
handle426AndReexec(process.argv.slice(2));
|
|
37
37
|
if (res.value.status === 401 || res.value.status === 403) {
|
|
38
38
|
if (res.value.rawText.includes("no active organization"))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-route.js","sourceRoot":"","sources":["../../src/_utils/post-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAe,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,yEAAyE;AACzE,uEAAuE;AACvE,uEAAuE;AACvE,oCAAoC;AACpC,MAAM,SAAS,GAAG,KAAK,EACrB,GAAW,EACX,IAA6B,
|
|
1
|
+
{"version":3,"file":"post-route.js","sourceRoot":"","sources":["../../src/_utils/post-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,MAAM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gBAC3B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,6BAA6B,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG;YACtD,MAAM,EACJ,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,GAAG;gBACtB,CAAC,CAAC,6EAA6E;gBAC/E,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,GAAG;oBACxB,CAAC,CAAC,6DAA6D;oBAC/D,CAAC,CAAC,0EAA0E;SACnF,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,CAAE,GAAG,CAAC,KAAK,CAAC,IAAuC,IAAI,EAAE,CAAC,CAAC;AACtE,CAAC,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { config } from "./config.js";
|
|
2
|
+
import { installReceipt } from "./install-receipt.js";
|
|
3
|
+
import { postRoute } from "./post-route.js";
|
|
4
|
+
const reportCliInstall = async () => {
|
|
5
|
+
const pending = (await installReceipt.read())?.pendingInstall;
|
|
6
|
+
if (!pending)
|
|
7
|
+
return "none";
|
|
8
|
+
const posted = await postRoute(config.recordCliInstallUrl, pending, {
|
|
9
|
+
reexecOn426: false,
|
|
10
|
+
});
|
|
11
|
+
if (!posted.ok)
|
|
12
|
+
return "pending";
|
|
13
|
+
const cleared = await installReceipt.clearPendingInstall();
|
|
14
|
+
return cleared.ok ? "reported" : "pending";
|
|
15
|
+
};
|
|
16
|
+
export { reportCliInstall };
|
|
17
|
+
//# sourceMappingURL=report-cli-install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-cli-install.js","sourceRoot":"","sources":["../../src/_utils/report-cli-install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;IAClC,MAAM,OAAO,GAAG,CAAC,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC,EAAE,cAAc,CAAC;IAC9D,IAAI,CAAC,OAAO;QAAE,OAAO,MAAe,CAAC;IACrC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,mBAAmB,EAAE,OAAO,EAAE;QAClE,WAAW,EAAE,KAAK;KACnB,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,SAAkB,CAAC;IAC1C,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,mBAAmB,EAAE,CAAC;IAC3D,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,CAAE,UAAoB,CAAC,CAAC,CAAE,SAAmB,CAAC;AACnE,CAAC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
type Segment = {
|
|
2
|
+
readonly kind: "text" | "thinking" | "tool_call" | "tool_result" | "compaction";
|
|
3
|
+
readonly text?: string;
|
|
4
|
+
readonly jsonContent?: Record<string, unknown>;
|
|
5
|
+
};
|
|
1
6
|
type TranscriptMessage = {
|
|
2
7
|
readonly role: "user" | "assistant";
|
|
3
8
|
readonly text: string;
|
|
4
9
|
readonly occurredAt?: string;
|
|
10
|
+
readonly segments?: readonly Segment[];
|
|
5
11
|
};
|
|
6
12
|
type ParsedTranscript = {
|
|
7
13
|
readonly sessionId: string;
|
|
@@ -15,7 +21,8 @@ type TranscriptTurn = readonly {
|
|
|
15
21
|
readonly role: "user" | "assistant";
|
|
16
22
|
readonly content: string;
|
|
17
23
|
readonly occurredAt?: string;
|
|
24
|
+
readonly segments?: readonly Segment[];
|
|
18
25
|
}[];
|
|
19
26
|
declare const buildTranscriptTurns: (messages: readonly TranscriptMessage[]) => TranscriptTurn[];
|
|
20
27
|
export { buildTranscriptTurns };
|
|
21
|
-
export type { TranscriptMessage, ParsedTranscript, TranscriptTurn };
|
|
28
|
+
export type { TranscriptMessage, ParsedTranscript, TranscriptTurn, Segment };
|
|
@@ -4,6 +4,139 @@ const MAX_MESSAGE_CHARS = 30_000;
|
|
|
4
4
|
const truncate = (text) => text.length <= MAX_MESSAGE_CHARS
|
|
5
5
|
? text
|
|
6
6
|
: `${text.slice(0, MAX_MESSAGE_CHARS)}\n… [truncated by glen import]`;
|
|
7
|
+
const MAX_SEGMENT_CHARS = 30_000;
|
|
8
|
+
// Mirrors the server's per-message payload cap (src/server/memory/ingest —
|
|
9
|
+
// segments are stored on the message payload). Enforced below in
|
|
10
|
+
// boundSegmentsPayload so an oversized message never 400s the whole turn.
|
|
11
|
+
const MAX_PAYLOAD_CHARS = 1_000_000;
|
|
12
|
+
const TRUNCATION_MARKER = "… [truncated by glen]";
|
|
13
|
+
// Deep-truncates every string leaf inside an arbitrary JSON value (recursing
|
|
14
|
+
// into arrays and plain objects, leaving other value types untouched). Used
|
|
15
|
+
// to bound jsonContent, whose heaviest leaves (tool output/input, and the
|
|
16
|
+
// full `raw` block a Write embeds) are otherwise unbounded.
|
|
17
|
+
const truncateJsonStrings = (value, maxChars) => {
|
|
18
|
+
if (typeof value === "string")
|
|
19
|
+
return value.length > maxChars
|
|
20
|
+
? `${value.slice(0, maxChars)}\n${TRUNCATION_MARKER}`
|
|
21
|
+
: value;
|
|
22
|
+
if (Array.isArray(value))
|
|
23
|
+
return value.map((v) => truncateJsonStrings(v, maxChars));
|
|
24
|
+
if (value !== null && typeof value === "object")
|
|
25
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [
|
|
26
|
+
k,
|
|
27
|
+
truncateJsonStrings(v, maxChars),
|
|
28
|
+
]));
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
31
|
+
const truncateSegment = (s) => {
|
|
32
|
+
const withText = s.text !== undefined && s.text.length > MAX_SEGMENT_CHARS
|
|
33
|
+
? {
|
|
34
|
+
...s,
|
|
35
|
+
text: `${s.text.slice(0, MAX_SEGMENT_CHARS)}\n${TRUNCATION_MARKER}`,
|
|
36
|
+
}
|
|
37
|
+
: s;
|
|
38
|
+
return withText.jsonContent !== undefined
|
|
39
|
+
? {
|
|
40
|
+
...withText,
|
|
41
|
+
jsonContent: truncateJsonStrings(withText.jsonContent, MAX_SEGMENT_CHARS),
|
|
42
|
+
}
|
|
43
|
+
: withText;
|
|
44
|
+
};
|
|
45
|
+
// Drops the `raw` key from every segment's jsonContent — it's redundant with
|
|
46
|
+
// the normalized output/input and is the biggest single contributor to an
|
|
47
|
+
// oversized payload.
|
|
48
|
+
const dropRawFromSegments = (segments) => segments.map((s) => {
|
|
49
|
+
if (s.jsonContent === undefined || !("raw" in s.jsonContent))
|
|
50
|
+
return s;
|
|
51
|
+
const { raw: _raw, ...rest } = s.jsonContent;
|
|
52
|
+
return { ...s, jsonContent: rest };
|
|
53
|
+
});
|
|
54
|
+
// Re-truncates jsonContent string leaves AND thinking-segment text to a
|
|
55
|
+
// smaller cap, recursively halving the cap until the serialized payload fits
|
|
56
|
+
// or the cap bottoms out. Never touches a text segment's prose, and never
|
|
57
|
+
// touches a tool_call's `name` (only jsonContent leaves are re-capped, and
|
|
58
|
+
// `name` lives outside jsonContent in practice — segments carry it inside
|
|
59
|
+
// jsonContent alongside output/input, so we re-cap the whole jsonContent
|
|
60
|
+
// object uniformly; the `name` field is short and unaffected by the cap).
|
|
61
|
+
const RECAP_FLOOR_CHARS = 1_000;
|
|
62
|
+
const recapSegments = (segments, capChars) => segments.map((s) => {
|
|
63
|
+
const withJson = s.jsonContent !== undefined
|
|
64
|
+
? {
|
|
65
|
+
...s,
|
|
66
|
+
jsonContent: truncateJsonStrings(s.jsonContent, capChars),
|
|
67
|
+
}
|
|
68
|
+
: s;
|
|
69
|
+
return withJson.kind === "thinking" &&
|
|
70
|
+
withJson.text !== undefined &&
|
|
71
|
+
withJson.text.length > capChars
|
|
72
|
+
? {
|
|
73
|
+
...withJson,
|
|
74
|
+
text: `${withJson.text.slice(0, capChars)}\n${TRUNCATION_MARKER}`,
|
|
75
|
+
}
|
|
76
|
+
: withJson;
|
|
77
|
+
});
|
|
78
|
+
const fitsBudget = (segments) => JSON.stringify(segments).length <= MAX_PAYLOAD_CHARS;
|
|
79
|
+
// Recursively halves the recap cap until the payload fits the budget or the
|
|
80
|
+
// cap bottoms out at RECAP_FLOOR_CHARS — never mutates, always returns a new
|
|
81
|
+
// array (or the input array's shape via a pure recursive call).
|
|
82
|
+
const shrinkToFit = (segments, capChars) => {
|
|
83
|
+
const recapped = recapSegments(segments, capChars);
|
|
84
|
+
if (fitsBudget(recapped) || capChars <= RECAP_FLOOR_CHARS)
|
|
85
|
+
return recapped;
|
|
86
|
+
return shrinkToFit(recapped, Math.floor(capChars / 2));
|
|
87
|
+
};
|
|
88
|
+
// Last-resort guarantee (FIX B2): shrinkToFit is best-effort — it stops at
|
|
89
|
+
// RECAP_FLOOR_CHARS even if the payload is still over budget (a message with
|
|
90
|
+
// a very large NUMBER of segments can exceed the cap even with every string
|
|
91
|
+
// leaf floored, since the leaves were never the problem). Drop whole
|
|
92
|
+
// segments, least-valuable first, until the payload fits. `kind:"text"`
|
|
93
|
+
// (prose) is NEVER dropped — the order below only ever removes tool
|
|
94
|
+
// call/result/thinking/compaction segments. Pure recursion, no mutation.
|
|
95
|
+
const DROP_ORDER = [
|
|
96
|
+
"tool_result",
|
|
97
|
+
"compaction",
|
|
98
|
+
"thinking",
|
|
99
|
+
"tool_call",
|
|
100
|
+
];
|
|
101
|
+
// Drops every segment of `kind` in one pass (never touches `text`), then
|
|
102
|
+
// recurses to the next-least-valuable kind if still over budget.
|
|
103
|
+
const dropByKind = (segments, kinds) => {
|
|
104
|
+
if (fitsBudget(segments))
|
|
105
|
+
return [...segments];
|
|
106
|
+
const [kind, ...rest] = kinds;
|
|
107
|
+
if (!kind)
|
|
108
|
+
return truncateFromEnd(segments);
|
|
109
|
+
const dropped = segments.filter((s) => s.kind !== kind);
|
|
110
|
+
return dropByKind(dropped, rest);
|
|
111
|
+
};
|
|
112
|
+
// Absolute final step: even with every non-text segment dropped, pathological
|
|
113
|
+
// prose (e.g. one enormous text segment) could still exceed the cap. Truncate
|
|
114
|
+
// the segments array from the end (never touching the text CONTENT of a kept
|
|
115
|
+
// segment) until it fits, or nothing is left.
|
|
116
|
+
const truncateFromEnd = (segments) => {
|
|
117
|
+
if (segments.length === 0 || fitsBudget(segments))
|
|
118
|
+
return [...segments];
|
|
119
|
+
return truncateFromEnd(segments.slice(0, -1));
|
|
120
|
+
};
|
|
121
|
+
// Enforces the per-message TOTAL payload budget: drop `raw` first (the
|
|
122
|
+
// biggest contributor), then progressively re-truncate jsonContent/thinking
|
|
123
|
+
// text until under budget or the recap cap floors out, then — if STILL over
|
|
124
|
+
// budget — drop whole non-text segments (least-valuable kind first), and as
|
|
125
|
+
// an absolute last resort truncate the segments array itself. Prose
|
|
126
|
+
// (`kind:"text"`) segment text and tool_call `name` are never touched, and no
|
|
127
|
+
// `kind:"text"` segment is ever dropped by dropByKind. Pure — always returns a
|
|
128
|
+
// new array whose serialized length is <= MAX_PAYLOAD_CHARS.
|
|
129
|
+
const boundSegmentsPayload = (segments) => {
|
|
130
|
+
if (fitsBudget(segments))
|
|
131
|
+
return [...segments];
|
|
132
|
+
const withoutRaw = dropRawFromSegments(segments);
|
|
133
|
+
if (fitsBudget(withoutRaw))
|
|
134
|
+
return withoutRaw;
|
|
135
|
+
const shrunk = shrinkToFit(withoutRaw, MAX_SEGMENT_CHARS / 2);
|
|
136
|
+
if (fitsBudget(shrunk))
|
|
137
|
+
return shrunk;
|
|
138
|
+
return dropByKind(shrunk, DROP_ORDER);
|
|
139
|
+
};
|
|
7
140
|
const earliestTimestamp = (a, b) => (!a ? b : !b ? a : a < b ? a : b);
|
|
8
141
|
// Group a transcript's messages into turns mirroring live capture: fold
|
|
9
142
|
// consecutive same-role messages (an assistant reply split across transcript
|
|
@@ -14,20 +147,28 @@ const buildTranscriptTurns = (messages) => {
|
|
|
14
147
|
const folded = [];
|
|
15
148
|
for (const m of messages) {
|
|
16
149
|
const text = m.text.trim();
|
|
17
|
-
if (!text)
|
|
150
|
+
if (!text && (!m.segments || m.segments.length === 0))
|
|
18
151
|
continue;
|
|
19
152
|
const last = folded[folded.length - 1];
|
|
20
153
|
if (last && last.role === m.role) {
|
|
21
|
-
last.content =
|
|
154
|
+
last.content = [last.content, text].filter(Boolean).join("\n\n");
|
|
22
155
|
const occurredAt = earliestTimestamp(last.occurredAt, m.occurredAt);
|
|
23
156
|
if (occurredAt)
|
|
24
157
|
last.occurredAt = occurredAt;
|
|
158
|
+
if (m.segments) {
|
|
159
|
+
if (!last.segments)
|
|
160
|
+
last.segments = [];
|
|
161
|
+
last.segments = [...last.segments, ...m.segments];
|
|
162
|
+
}
|
|
25
163
|
}
|
|
26
164
|
else
|
|
27
165
|
folded.push({
|
|
28
166
|
role: m.role,
|
|
29
167
|
content: text,
|
|
30
168
|
...(m.occurredAt ? { occurredAt: m.occurredAt } : {}),
|
|
169
|
+
...(m.segments && m.segments.length > 0
|
|
170
|
+
? { segments: [...m.segments] }
|
|
171
|
+
: {}),
|
|
31
172
|
});
|
|
32
173
|
}
|
|
33
174
|
const turns = [];
|
|
@@ -35,6 +176,9 @@ const buildTranscriptTurns = (messages) => {
|
|
|
35
176
|
role: f.role,
|
|
36
177
|
content: truncate(f.content),
|
|
37
178
|
...(f.occurredAt ? { occurredAt: f.occurredAt } : {}),
|
|
179
|
+
...(f.segments && f.segments.length > 0
|
|
180
|
+
? { segments: boundSegmentsPayload(f.segments.map(truncateSegment)) }
|
|
181
|
+
: {}),
|
|
38
182
|
}))) {
|
|
39
183
|
const last = turns[turns.length - 1];
|
|
40
184
|
// Roles alternate after folding, so appending an assistant message to the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transcript-turns.js","sourceRoot":"","sources":["../../src/_utils/transcript-turns.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transcript-turns.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C,EAAE,CAAC;QACrD,GAAG,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YACrC,CAAC,CAAC,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,EAAE;YACrE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC,EAAE,CAAC;QACJ,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACrC,0EAA0E;QAC1E,mEAAmE;QACnE,uDAAuD;QACvD,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;YAC3C,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/commands/ingest.js
CHANGED
|
@@ -297,10 +297,21 @@ const ingest = async (agent) => {
|
|
|
297
297
|
sessionId: event.session_id,
|
|
298
298
|
nextUserMessageIndex: `stop:${transcript.completedTurn.userMessageIndex}`,
|
|
299
299
|
messages: [
|
|
300
|
-
{
|
|
300
|
+
{
|
|
301
|
+
role: "user",
|
|
302
|
+
content: transcript.completedTurn.user,
|
|
303
|
+
...(transcript.completedTurn.userSegments?.length
|
|
304
|
+
? { segments: transcript.completedTurn.userSegments }
|
|
305
|
+
: {}),
|
|
306
|
+
},
|
|
301
307
|
{
|
|
302
308
|
role: "assistant",
|
|
303
309
|
content: transcript.completedTurn.assistant,
|
|
310
|
+
...(transcript.completedTurn.assistantSegments?.length
|
|
311
|
+
? {
|
|
312
|
+
segments: transcript.completedTurn.assistantSegments,
|
|
313
|
+
}
|
|
314
|
+
: {}),
|
|
304
315
|
},
|
|
305
316
|
],
|
|
306
317
|
...(additionalContext !== undefined
|