@tryarcanist/cli 0.1.78 → 0.1.80
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/index.js +42 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -392,7 +392,15 @@ function sleep(ms) {
|
|
|
392
392
|
var MIN_WATCH_POLL_INTERVAL_MS = 1;
|
|
393
393
|
var DEFAULT_WATCH_POLL_INTERVAL_MS = 1e3;
|
|
394
394
|
var WATCH_REPLAY_PAGE_SIZE = 200;
|
|
395
|
-
var WATCH_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
395
|
+
var WATCH_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
396
|
+
"idle",
|
|
397
|
+
"completed",
|
|
398
|
+
"blocked",
|
|
399
|
+
"failed",
|
|
400
|
+
"stopped",
|
|
401
|
+
"stopped_resumable",
|
|
402
|
+
"archived"
|
|
403
|
+
]);
|
|
396
404
|
|
|
397
405
|
// src/uploads.ts
|
|
398
406
|
import { readFile } from "fs/promises";
|
|
@@ -708,11 +716,17 @@ function getRawSessionEventData(event) {
|
|
|
708
716
|
}
|
|
709
717
|
}
|
|
710
718
|
function normalizeRawSessionEvent(event) {
|
|
719
|
+
const data = getRawSessionEventData(event);
|
|
711
720
|
return {
|
|
721
|
+
raw: event,
|
|
712
722
|
type: getRawSessionEventKind(event),
|
|
713
|
-
data
|
|
723
|
+
data,
|
|
724
|
+
promptId: getRawSessionEventPromptId(event)
|
|
714
725
|
};
|
|
715
726
|
}
|
|
727
|
+
function normalizeRawSessionEvents(events) {
|
|
728
|
+
return events.map((event) => normalizeRawSessionEvent(event));
|
|
729
|
+
}
|
|
716
730
|
function shouldAppendTextDelta(existingText, incomingText) {
|
|
717
731
|
if (!incomingText) return false;
|
|
718
732
|
if (incomingText.length < DUPLICATE_TEXT_DELTA_MIN_CHARS) return true;
|
|
@@ -1106,8 +1120,7 @@ function applyTodoUpdate(data, state) {
|
|
|
1106
1120
|
}
|
|
1107
1121
|
function flattenSessionEvents(raw) {
|
|
1108
1122
|
const state = createFlattenState();
|
|
1109
|
-
for (const
|
|
1110
|
-
const normalized = normalizeRawSessionEvent(event);
|
|
1123
|
+
for (const normalized of normalizeRawSessionEvents(raw)) {
|
|
1111
1124
|
const { type } = normalized;
|
|
1112
1125
|
const data = normalized.data;
|
|
1113
1126
|
switch (type) {
|
|
@@ -1184,47 +1197,47 @@ function partitionEventsByPrompt(allEvents, promptIds) {
|
|
|
1184
1197
|
const promptSet = new Set(promptIds);
|
|
1185
1198
|
const buckets = new Map(promptIds.map((id) => [id, []]));
|
|
1186
1199
|
let currentPromptId = null;
|
|
1187
|
-
for (const event of allEvents) {
|
|
1188
|
-
const eventPromptId =
|
|
1200
|
+
for (const event of normalizeRawSessionEvents(allEvents)) {
|
|
1201
|
+
const eventPromptId = event.promptId;
|
|
1189
1202
|
const explicitPromptId = typeof eventPromptId === "string" && promptSet.has(eventPromptId) ? eventPromptId : null;
|
|
1190
|
-
if (
|
|
1203
|
+
if (event.type === "prompt_processing") {
|
|
1191
1204
|
currentPromptId = explicitPromptId;
|
|
1192
1205
|
}
|
|
1193
1206
|
const targetPromptId = explicitPromptId ?? currentPromptId;
|
|
1194
1207
|
if (targetPromptId) {
|
|
1195
1208
|
const bucket = buckets.get(targetPromptId);
|
|
1196
|
-
if (bucket) bucket.push(event);
|
|
1209
|
+
if (bucket) bucket.push(event.raw);
|
|
1197
1210
|
}
|
|
1198
1211
|
}
|
|
1199
1212
|
return buckets;
|
|
1200
1213
|
}
|
|
1201
|
-
function
|
|
1202
|
-
for (let index =
|
|
1203
|
-
const event =
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
const history = getRawSessionEventData(event)?.history;
|
|
1214
|
+
function getEmbeddedTerminalHistoryFromNormalized(normalizedEvents) {
|
|
1215
|
+
for (let index = normalizedEvents.length - 1; index >= 0; index--) {
|
|
1216
|
+
const event = normalizedEvents[index];
|
|
1217
|
+
if (event.type !== "prompt_completed" && event.type !== "prompt_failed") continue;
|
|
1218
|
+
const history = event.data?.history;
|
|
1207
1219
|
if (!Array.isArray(history) || history.length === 0) return null;
|
|
1208
1220
|
return history;
|
|
1209
1221
|
}
|
|
1210
1222
|
return null;
|
|
1211
1223
|
}
|
|
1212
1224
|
function promptActivityKey(event) {
|
|
1213
|
-
const data =
|
|
1225
|
+
const data = event.data;
|
|
1214
1226
|
return [
|
|
1215
|
-
|
|
1227
|
+
event.promptId ?? "",
|
|
1216
1228
|
typeof data?.phase === "string" ? data.phase : "",
|
|
1217
1229
|
typeof data?.detail === "string" ? data.detail : ""
|
|
1218
1230
|
].join("\0");
|
|
1219
1231
|
}
|
|
1220
1232
|
function agentProgressKey(event) {
|
|
1221
|
-
const data =
|
|
1222
|
-
return [
|
|
1233
|
+
const data = event.data;
|
|
1234
|
+
return [event.promptId ?? "", typeof data?.step === "string" ? data.step : ""].join("\0");
|
|
1223
1235
|
}
|
|
1224
1236
|
function resolveAuthoritativePromptEventsWithDiagnostics(raw) {
|
|
1225
|
-
const
|
|
1226
|
-
const
|
|
1227
|
-
const
|
|
1237
|
+
const normalizedRaw = normalizeRawSessionEvents(raw);
|
|
1238
|
+
const embeddedHistory = getEmbeddedTerminalHistoryFromNormalized(normalizedRaw);
|
|
1239
|
+
const durablePromptActivity = normalizedRaw.filter((event) => event.type === "prompt_activity");
|
|
1240
|
+
const durableAgentProgress = normalizedRaw.filter((event) => event.type === "agent_progress");
|
|
1228
1241
|
if (!embeddedHistory) {
|
|
1229
1242
|
return {
|
|
1230
1243
|
events: raw,
|
|
@@ -1241,8 +1254,9 @@ function resolveAuthoritativePromptEventsWithDiagnostics(raw) {
|
|
|
1241
1254
|
}
|
|
1242
1255
|
};
|
|
1243
1256
|
}
|
|
1244
|
-
const
|
|
1245
|
-
const
|
|
1257
|
+
const normalizedEmbeddedHistory = normalizeRawSessionEvents(embeddedHistory);
|
|
1258
|
+
const embeddedPromptActivity = normalizedEmbeddedHistory.filter((event) => event.type === "prompt_activity");
|
|
1259
|
+
const embeddedAgentProgress = normalizedEmbeddedHistory.filter((event) => event.type === "agent_progress");
|
|
1246
1260
|
const embeddedPromptActivityKeys = new Set(embeddedPromptActivity.map(promptActivityKey));
|
|
1247
1261
|
const embeddedAgentProgressKeys = new Set(embeddedAgentProgress.map(agentProgressKey));
|
|
1248
1262
|
const embeddedPromptActivityCount = embeddedPromptActivity.length;
|
|
@@ -1267,7 +1281,9 @@ function resolveAuthoritativePromptEventsWithDiagnostics(raw) {
|
|
|
1267
1281
|
embeddedAgentProgressKeys.add(key);
|
|
1268
1282
|
return true;
|
|
1269
1283
|
});
|
|
1270
|
-
const missingDurableSideChannelEvents = [...missingDurablePromptActivity, ...missingDurableAgentProgress]
|
|
1284
|
+
const missingDurableSideChannelEvents = [...missingDurablePromptActivity, ...missingDurableAgentProgress].map(
|
|
1285
|
+
(event) => event.raw
|
|
1286
|
+
);
|
|
1271
1287
|
return {
|
|
1272
1288
|
events: missingDurableSideChannelEvents.length > 0 ? [...missingDurableSideChannelEvents, ...embeddedHistory] : embeddedHistory,
|
|
1273
1289
|
diagnostics: {
|
|
@@ -1847,7 +1863,7 @@ async function waitForCreatedPrompt(sessionId, promptId, sessionUrl, pollInterva
|
|
|
1847
1863
|
createdPrompt = await fetchCreatedPromptStatus(config, sessionId, promptId);
|
|
1848
1864
|
}
|
|
1849
1865
|
if (!createdPrompt) {
|
|
1850
|
-
throw new CliError("server", `Prompt status was unavailable after session ${sessionId}
|
|
1866
|
+
throw new CliError("server", `Prompt status was unavailable after session ${sessionId} reached a terminal state.`, {
|
|
1851
1867
|
hint: `Inspect with: arcanist sessions transcript ${sessionId}`
|
|
1852
1868
|
});
|
|
1853
1869
|
}
|
|
@@ -1857,7 +1873,7 @@ async function waitForCreatedPrompt(sessionId, promptId, sessionUrl, pollInterva
|
|
|
1857
1873
|
if (createdPrompt.status !== "completed") {
|
|
1858
1874
|
throw new CliError(
|
|
1859
1875
|
"server",
|
|
1860
|
-
`Prompt ${createdPrompt.promptId} did not reach a terminal success state before session ${sessionId}
|
|
1876
|
+
`Prompt ${createdPrompt.promptId} did not reach a terminal success state before session ${sessionId} reached a terminal state (status: ${createdPrompt.status}).`,
|
|
1861
1877
|
{
|
|
1862
1878
|
hint: `Inspect with: arcanist sessions transcript ${sessionId}`
|
|
1863
1879
|
}
|