@cydm/pie 1.0.34 → 1.0.35
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/cli.js +57 -15
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -43962,7 +43962,7 @@ import * as path29 from "path";
|
|
|
43962
43962
|
|
|
43963
43963
|
// src/cli-args.ts
|
|
43964
43964
|
var FLAGS_WITH_VALUES = /* @__PURE__ */ new Set(["--session-id", "--extension-path"]);
|
|
43965
|
-
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["--raw-output", "--json-output", "--json-events"]);
|
|
43965
|
+
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["--raw-output", "--json-output", "--json-events", "--resume-required"]);
|
|
43966
43966
|
var HELP_FLAGS = /* @__PURE__ */ new Set(["help", "--help", "-h"]);
|
|
43967
43967
|
var COMMANDS = /* @__PURE__ */ new Set(["chat", "help"]);
|
|
43968
43968
|
function parseCliInvocation(args) {
|
|
@@ -44014,6 +44014,16 @@ function parseCliInvocation(args) {
|
|
|
44014
44014
|
initialPrompt: positionals.join(" ").trim() || void 0
|
|
44015
44015
|
};
|
|
44016
44016
|
}
|
|
44017
|
+
function parseRepeatedFlag(args, flag) {
|
|
44018
|
+
const values = [];
|
|
44019
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
44020
|
+
if (args[i] === flag && args[i + 1]) {
|
|
44021
|
+
values.push(args[i + 1]);
|
|
44022
|
+
i += 1;
|
|
44023
|
+
}
|
|
44024
|
+
}
|
|
44025
|
+
return values;
|
|
44026
|
+
}
|
|
44017
44027
|
|
|
44018
44028
|
// src/debug/file-logger.ts
|
|
44019
44029
|
import * as fs from "fs";
|
|
@@ -69594,6 +69604,17 @@ var CliMissingApiKeyError = class extends Error {
|
|
|
69594
69604
|
this.name = "CliMissingApiKeyError";
|
|
69595
69605
|
}
|
|
69596
69606
|
};
|
|
69607
|
+
var CliSessionResumeError = class extends Error {
|
|
69608
|
+
constructor(sessionId, code, message = code === "session_not_found" ? `Session not found: ${sessionId}` : `Session could not be recovered: ${sessionId}`) {
|
|
69609
|
+
super(message);
|
|
69610
|
+
this.sessionId = sessionId;
|
|
69611
|
+
this.code = code;
|
|
69612
|
+
this.name = "CliSessionResumeError";
|
|
69613
|
+
}
|
|
69614
|
+
sessionId;
|
|
69615
|
+
code;
|
|
69616
|
+
recoverable = true;
|
|
69617
|
+
};
|
|
69597
69618
|
function getCliRuntimePaths() {
|
|
69598
69619
|
const configDir = getConfigDir();
|
|
69599
69620
|
const sessionsDir = getSessionsDir();
|
|
@@ -69666,10 +69687,17 @@ async function composeCliRuntime(params) {
|
|
|
69666
69687
|
const cwd = params.cwd ?? process.cwd();
|
|
69667
69688
|
const sessionManager = createSessionManager({ sessionsDir: paths.sessionsDir });
|
|
69668
69689
|
if (params.explicitSessionId) {
|
|
69690
|
+
const sessionFileExists = params.requireExistingSession ? await sessionManager.hasSession(params.explicitSessionId) : false;
|
|
69669
69691
|
const loaded = await sessionManager.loadSession(params.explicitSessionId, {
|
|
69670
69692
|
warnIfMissing: params.warnIfExplicitSessionMissing
|
|
69671
69693
|
});
|
|
69672
69694
|
if (!loaded) {
|
|
69695
|
+
if (params.requireExistingSession) {
|
|
69696
|
+
throw new CliSessionResumeError(
|
|
69697
|
+
params.explicitSessionId,
|
|
69698
|
+
sessionFileExists ? "session_unrecoverable" : "session_not_found"
|
|
69699
|
+
);
|
|
69700
|
+
}
|
|
69673
69701
|
await sessionManager.createSession(void 0, void 0, params.explicitSessionId);
|
|
69674
69702
|
} else {
|
|
69675
69703
|
const restored = restoreSessionModelState({
|
|
@@ -70487,6 +70515,25 @@ async function runJsonEventsMode(params) {
|
|
|
70487
70515
|
display(chunk);
|
|
70488
70516
|
}
|
|
70489
70517
|
}
|
|
70518
|
+
function failureDetail(detail) {
|
|
70519
|
+
if (!detail) return { error: "turn failed" };
|
|
70520
|
+
if (typeof detail === "string") return { error: detail };
|
|
70521
|
+
return {
|
|
70522
|
+
error: detail.message,
|
|
70523
|
+
code: detail.code,
|
|
70524
|
+
recoverable: detail.recoverable
|
|
70525
|
+
};
|
|
70526
|
+
}
|
|
70527
|
+
function errorToFailureDetail(error) {
|
|
70528
|
+
if (error instanceof CliSessionResumeError) {
|
|
70529
|
+
return {
|
|
70530
|
+
message: error.message,
|
|
70531
|
+
code: error.code,
|
|
70532
|
+
recoverable: error.recoverable
|
|
70533
|
+
};
|
|
70534
|
+
}
|
|
70535
|
+
return error instanceof Error ? error.message : String(error);
|
|
70536
|
+
}
|
|
70490
70537
|
function finalize(kind, detail) {
|
|
70491
70538
|
const turn = activeTurn;
|
|
70492
70539
|
if (!turn || turn.finalized) return;
|
|
@@ -70500,10 +70547,10 @@ async function runJsonEventsMode(params) {
|
|
|
70500
70547
|
};
|
|
70501
70548
|
switch (kind) {
|
|
70502
70549
|
case "completed":
|
|
70503
|
-
writeEvent({ type: "turn.completed", ...base, summary: (detail
|
|
70550
|
+
writeEvent({ type: "turn.completed", ...base, summary: (typeof detail === "string" ? detail : turn.summary).trim() });
|
|
70504
70551
|
break;
|
|
70505
70552
|
case "failed":
|
|
70506
|
-
writeEvent({ type: "turn.failed", ...base,
|
|
70553
|
+
writeEvent({ type: "turn.failed", ...base, ...failureDetail(detail) });
|
|
70507
70554
|
break;
|
|
70508
70555
|
case "cancelled":
|
|
70509
70556
|
writeEvent({ type: "turn.cancelled", ...base, reason: detail || "interrupted" });
|
|
@@ -70926,7 +70973,7 @@ async function runJsonEventsMode(params) {
|
|
|
70926
70973
|
try {
|
|
70927
70974
|
await ensureRuntime(message.cwd);
|
|
70928
70975
|
} catch (error) {
|
|
70929
|
-
finalize("failed",
|
|
70976
|
+
finalize("failed", errorToFailureDetail(error));
|
|
70930
70977
|
if (activeTurn === turn) emitSettled(turn);
|
|
70931
70978
|
if (activeTurn === turn) activeTurn = null;
|
|
70932
70979
|
return;
|
|
@@ -71194,6 +71241,7 @@ Print Mode Options:
|
|
|
71194
71241
|
--json-output Print structured JSON in non-interactive mode
|
|
71195
71242
|
--json-events Run JSONL protocol mode over stdin/stdout
|
|
71196
71243
|
--session-id Reuse or create a specific session in non-interactive mode
|
|
71244
|
+
--resume-required In JSON-events mode, fail if --session-id cannot be resumed
|
|
71197
71245
|
--extension-path Add an extra extension search directory (repeatable)
|
|
71198
71246
|
--no-builtin-extensions Skip built-in extensions (keep user/project ones)
|
|
71199
71247
|
--no-extensions Skip all discovered extensions (keeps --extension-path)
|
|
@@ -71273,16 +71321,6 @@ async function runModelsCommand(args) {
|
|
|
71273
71321
|
pie models init [--path <path>] [--force] [--stdout]
|
|
71274
71322
|
pie models validate [--path <path>] [--probe web_search] [--json]`);
|
|
71275
71323
|
}
|
|
71276
|
-
function parseRepeatedFlag(args, flag) {
|
|
71277
|
-
const values = [];
|
|
71278
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
71279
|
-
if (args[i] === flag && args[i + 1]) {
|
|
71280
|
-
values.push(args[i + 1]);
|
|
71281
|
-
i += 1;
|
|
71282
|
-
}
|
|
71283
|
-
}
|
|
71284
|
-
return values;
|
|
71285
|
-
}
|
|
71286
71324
|
async function runWithJsonEventsConsoleIsolation(fn) {
|
|
71287
71325
|
const originalLog = console.log;
|
|
71288
71326
|
const originalInfo = console.info;
|
|
@@ -71307,6 +71345,7 @@ async function startChat(initialPrompt, testCommand) {
|
|
|
71307
71345
|
const rawOutput = process.argv.includes("--raw-output");
|
|
71308
71346
|
const jsonOutput = process.argv.includes("--json-output");
|
|
71309
71347
|
const jsonEvents = process.argv.includes("--json-events");
|
|
71348
|
+
const resumeRequired = process.argv.includes("--resume-required");
|
|
71310
71349
|
const sessionIdFlagIndex = process.argv.indexOf("--session-id");
|
|
71311
71350
|
const explicitSessionId = sessionIdFlagIndex >= 0 ? process.argv[sessionIdFlagIndex + 1] : void 0;
|
|
71312
71351
|
const extensionPaths = parseRepeatedFlag(process.argv, "--extension-path");
|
|
@@ -71316,19 +71355,22 @@ async function startChat(initialPrompt, testCommand) {
|
|
|
71316
71355
|
if (process.env.PIE_TEST_MOCK_RESPONSE !== void 0) {
|
|
71317
71356
|
await runJsonEventsMode({
|
|
71318
71357
|
explicitSessionId,
|
|
71358
|
+
resumeRequired,
|
|
71319
71359
|
mockResponse: process.env.PIE_TEST_MOCK_RESPONSE
|
|
71320
71360
|
});
|
|
71321
71361
|
return;
|
|
71322
71362
|
}
|
|
71323
71363
|
await runJsonEventsMode({
|
|
71324
71364
|
explicitSessionId,
|
|
71365
|
+
resumeRequired,
|
|
71325
71366
|
streamFn: await createCliTestStreamFnFromEnv(),
|
|
71326
71367
|
createRuntime: async ({ cwd, sessionId }) => composeCliRuntime({
|
|
71327
71368
|
explicitSessionId: explicitSessionId ?? sessionId,
|
|
71328
71369
|
extensionPaths,
|
|
71329
71370
|
extensionFlags,
|
|
71330
71371
|
cwd,
|
|
71331
|
-
warnIfExplicitSessionMissing: false
|
|
71372
|
+
warnIfExplicitSessionMissing: false,
|
|
71373
|
+
requireExistingSession: resumeRequired && !!explicitSessionId
|
|
71332
71374
|
})
|
|
71333
71375
|
});
|
|
71334
71376
|
});
|