@cydm/pie 1.0.34 → 1.0.36

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.
@@ -5,6 +5,28 @@ import {
5
5
  import "./chunk-TG2EQLX2.js";
6
6
 
7
7
  // src/app/test-stream.ts
8
+ function parseSystemPromptExpectations(value) {
9
+ if (!value) return [];
10
+ const parsed = JSON.parse(value);
11
+ const normalize = (item) => {
12
+ if (typeof item === "string") return [item];
13
+ if (Array.isArray(item) && item.every((entry) => typeof entry === "string")) return item;
14
+ throw new Error("PIE_TEST_EXPECT_SYSTEM_PROMPT_INCLUDES entries must be strings");
15
+ };
16
+ if (typeof parsed === "string" || Array.isArray(parsed) && parsed.every((entry) => typeof entry === "string")) {
17
+ return [normalize(parsed)];
18
+ }
19
+ if (!Array.isArray(parsed)) throw new Error("PIE_TEST_EXPECT_SYSTEM_PROMPT_INCLUDES must be JSON");
20
+ return parsed.map(normalize);
21
+ }
22
+ function assertSystemPromptIncludes(systemPrompt, callIndex) {
23
+ const expectations = parseSystemPromptExpectations(process.env.PIE_TEST_EXPECT_SYSTEM_PROMPT_INCLUDES);
24
+ for (const expected of expectations[Math.min(callIndex, Math.max(0, expectations.length - 1))] ?? []) {
25
+ if (!systemPrompt.includes(expected)) {
26
+ throw new Error(`Expected system prompt to include ${JSON.stringify(expected)}`);
27
+ }
28
+ }
29
+ }
8
30
  function createAssistantMessage(model, text, stopReason = "stop", errorMessage) {
9
31
  return {
10
32
  role: "assistant",
@@ -68,8 +90,9 @@ function createTestStreamFnFromSequenceEnv(value = process.env.PIE_TEST_MOCK_STR
68
90
  }
69
91
  const steps = parseMockStreamSequence(value);
70
92
  let callIndex = 0;
71
- return async (model) => {
93
+ return async (model, context) => {
72
94
  const step = steps[Math.min(callIndex, steps.length - 1)];
95
+ assertSystemPromptIncludes(context.systemPrompt, callIndex);
73
96
  callIndex += 1;
74
97
  const stream = new EventStream(
75
98
  (event) => event.type === "done" || event.type === "error",
package/dist/cli.js CHANGED
@@ -985,15 +985,15 @@ var require_route = __commonJS({
985
985
  };
986
986
  }
987
987
  function wrapConversion(toModel, graph) {
988
- const path30 = [graph[toModel].parent, toModel];
988
+ const path31 = [graph[toModel].parent, toModel];
989
989
  let fn = conversions[graph[toModel].parent][toModel];
990
990
  let cur = graph[toModel].parent;
991
991
  while (graph[cur].parent) {
992
- path30.unshift(graph[cur].parent);
992
+ path31.unshift(graph[cur].parent);
993
993
  fn = link(conversions[graph[cur].parent][cur], fn);
994
994
  cur = graph[cur].parent;
995
995
  }
996
- fn.conversion = path30;
996
+ fn.conversion = path31;
997
997
  return fn;
998
998
  }
999
999
  module.exports = function(fromModel) {
@@ -43957,12 +43957,12 @@ var require_dist = __commonJS({
43957
43957
  });
43958
43958
 
43959
43959
  // src/cli.ts
43960
- import * as fs26 from "fs";
43961
- import * as path29 from "path";
43960
+ import * as fs27 from "fs";
43961
+ import * as path30 from "path";
43962
43962
 
43963
43963
  // src/cli-args.ts
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"]);
43964
+ var FLAGS_WITH_VALUES = /* @__PURE__ */ new Set(["--session-id", "--extension-path", "--developer-instructions", "--developer-instructions-file"]);
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";
@@ -44551,7 +44561,7 @@ async function acquireRemoteRefreshLock(modelsPath) {
44551
44561
  throw lockError;
44552
44562
  }
44553
44563
  if (Date.now() >= deadline) throw new Error(`timed out waiting for remote catalog refresh lock: ${lockPath}`);
44554
- await new Promise((resolve5) => setTimeout(resolve5, 25));
44564
+ await new Promise((resolve6) => setTimeout(resolve6, 25));
44555
44565
  }
44556
44566
  }
44557
44567
  }
@@ -46871,15 +46881,15 @@ function activePathEntries(data) {
46871
46881
  }
46872
46882
  function pathToEntry(data, entryId) {
46873
46883
  const byId = new Map(data.entries.map((entry) => [entry.id, entry]));
46874
- const path30 = [];
46884
+ const path31 = [];
46875
46885
  let current = entryId;
46876
46886
  while (current) {
46877
46887
  const entry = byId.get(current);
46878
46888
  if (!entry) return [];
46879
- path30.unshift(entry);
46889
+ path31.unshift(entry);
46880
46890
  current = entry.parentId;
46881
46891
  }
46882
- return path30;
46892
+ return path31;
46883
46893
  }
46884
46894
  function resolveBeforeCursor(events, cursor) {
46885
46895
  if (!cursor) return events.length;
@@ -46942,19 +46952,19 @@ var CommandTree = class {
46942
46952
  * register(["session", "new"], { description, handler })
46943
46953
  * register(["tools", "subagent", "spawn", "local"], { description, handler })
46944
46954
  */
46945
- register(path30, info) {
46946
- if (path30.length === 0) {
46955
+ register(path31, info) {
46956
+ if (path31.length === 0) {
46947
46957
  throw new Error("Command path cannot be empty");
46948
46958
  }
46949
46959
  let current = this.root;
46950
46960
  const fullPath = [];
46951
- for (let i = 0; i < path30.length; i++) {
46952
- const segment = path30[i];
46961
+ for (let i = 0; i < path31.length; i++) {
46962
+ const segment = path31[i];
46953
46963
  fullPath.push(segment);
46954
46964
  if (!current.children) {
46955
46965
  current.children = [];
46956
46966
  }
46957
- const isLast = i === path30.length - 1;
46967
+ const isLast = i === path31.length - 1;
46958
46968
  let node = current.children.find((n) => n.name === segment);
46959
46969
  if (!node) {
46960
46970
  node = {
@@ -46984,31 +46994,31 @@ var CommandTree = class {
46984
46994
  /**
46985
46995
  * Find a node by path
46986
46996
  */
46987
- find(path30) {
46988
- if (path30.length === 0) {
46997
+ find(path31) {
46998
+ if (path31.length === 0) {
46989
46999
  return this.root;
46990
47000
  }
46991
- const key = path30.join("/");
47001
+ const key = path31.join("/");
46992
47002
  return this.pathCache.get(key) || null;
46993
47003
  }
46994
47004
  /**
46995
47005
  * Get children of a path
46996
47006
  */
46997
- getChildren(path30) {
46998
- const node = this.find(path30);
47007
+ getChildren(path31) {
47008
+ const node = this.find(path31);
46999
47009
  return (node?.children || []).filter((child) => !child.hidden);
47000
47010
  }
47001
47011
  /**
47002
47012
  * Check if a path exists (as category or command)
47003
47013
  */
47004
- exists(path30) {
47005
- return this.find(path30) !== null;
47014
+ exists(path31) {
47015
+ return this.find(path31) !== null;
47006
47016
  }
47007
47017
  /**
47008
47018
  * Check if path is a category (has children)
47009
47019
  */
47010
- isCategory(path30) {
47011
- const node = this.find(path30);
47020
+ isCategory(path31) {
47021
+ const node = this.find(path31);
47012
47022
  return node?.isCategory || false;
47013
47023
  }
47014
47024
  /**
@@ -47087,8 +47097,8 @@ var CommandTree = class {
47087
47097
  * Supports dot notation: "tools.subagent.spawn.local"
47088
47098
  */
47089
47099
  registerFromPath(pathStr, info) {
47090
- const path30 = pathStr.split(/[./]/).filter(Boolean);
47091
- this.register(path30, info);
47100
+ const path31 = pathStr.split(/[./]/).filter(Boolean);
47101
+ this.register(path31, info);
47092
47102
  }
47093
47103
  };
47094
47104
  var commandTree = new CommandTree();
@@ -54378,7 +54388,7 @@ var ProcessTerminal = class {
54378
54388
  const timeLeft = endTime - now;
54379
54389
  if (timeLeft <= 0) break;
54380
54390
  if (now - lastDataTime >= idleMs) break;
54381
- await new Promise((resolve5) => setTimeout(resolve5, Math.min(idleMs, timeLeft)));
54391
+ await new Promise((resolve6) => setTimeout(resolve6, Math.min(idleMs, timeLeft)));
54382
54392
  }
54383
54393
  } finally {
54384
54394
  process.stdin.removeListener("data", onData);
@@ -54912,10 +54922,10 @@ var KeybindingsManager = class _KeybindingsManager {
54912
54922
  static inMemory(config = {}) {
54913
54923
  return new _KeybindingsManager(config);
54914
54924
  }
54915
- static loadFromFile(path30) {
54916
- if (!existsSync7(path30)) return {};
54925
+ static loadFromFile(path31) {
54926
+ if (!existsSync7(path31)) return {};
54917
54927
  try {
54918
- return JSON.parse(readFileSync6(path30, "utf-8"));
54928
+ return JSON.parse(readFileSync6(path31, "utf-8"));
54919
54929
  } catch {
54920
54930
  return {};
54921
54931
  }
@@ -57625,11 +57635,11 @@ var FileCache = class _FileCache {
57625
57635
  // Hash Computation
57626
57636
  // ============================================================================
57627
57637
  async computeHash(filePath) {
57628
- return new Promise((resolve5, reject) => {
57638
+ return new Promise((resolve6, reject) => {
57629
57639
  const hash = crypto.createHash("sha256");
57630
57640
  const stream = fs16.createReadStream(filePath);
57631
57641
  stream.on("data", (chunk) => hash.update(chunk));
57632
- stream.on("end", () => resolve5(hash.digest("hex")));
57642
+ stream.on("end", () => resolve6(hash.digest("hex")));
57633
57643
  stream.on("error", reject);
57634
57644
  });
57635
57645
  }
@@ -58339,17 +58349,17 @@ var FFmpegProcessor = class {
58339
58349
  // Detection
58340
58350
  // ============================================================================
58341
58351
  async checkAvailability() {
58342
- return new Promise((resolve5) => {
58352
+ return new Promise((resolve6) => {
58343
58353
  const proc = spawn(this.ffmpegPath, ["-version"]);
58344
- proc.on("error", () => resolve5(false));
58345
- proc.on("exit", (code) => resolve5(code === 0));
58354
+ proc.on("error", () => resolve6(false));
58355
+ proc.on("exit", (code) => resolve6(code === 0));
58346
58356
  });
58347
58357
  }
58348
58358
  // ============================================================================
58349
58359
  // Video Analysis
58350
58360
  // ============================================================================
58351
58361
  async analyzeVideo(videoPath) {
58352
- return new Promise((resolve5, reject) => {
58362
+ return new Promise((resolve6, reject) => {
58353
58363
  const args = [
58354
58364
  "-v",
58355
58365
  "error",
@@ -58378,7 +58388,7 @@ var FFmpegProcessor = class {
58378
58388
  }
58379
58389
  try {
58380
58390
  const info = this.parseProbeOutput(stdout, videoPath);
58381
- resolve5(info);
58391
+ resolve6(info);
58382
58392
  } catch (err) {
58383
58393
  reject(err);
58384
58394
  }
@@ -58573,7 +58583,7 @@ var FFmpegProcessor = class {
58573
58583
  // FFmpeg Execution
58574
58584
  // ============================================================================
58575
58585
  runFFmpeg(args) {
58576
- return new Promise((resolve5, reject) => {
58586
+ return new Promise((resolve6, reject) => {
58577
58587
  const proc = spawn(this.ffmpegPath, args);
58578
58588
  let stderr = "";
58579
58589
  proc.stderr.on("data", (data) => {
@@ -58588,7 +58598,7 @@ var FFmpegProcessor = class {
58588
58598
  )
58589
58599
  );
58590
58600
  } else {
58591
- resolve5();
58601
+ resolve6();
58592
58602
  }
58593
58603
  });
58594
58604
  proc.on("error", (err) => {
@@ -58605,7 +58615,7 @@ var FFmpegProcessor = class {
58605
58615
  // Progress Monitoring (for future use)
58606
58616
  // ============================================================================
58607
58617
  async runWithProgress(args, onProgress) {
58608
- return new Promise((resolve5, reject) => {
58618
+ return new Promise((resolve6, reject) => {
58609
58619
  const progressArgs = [
58610
58620
  ...args,
58611
58621
  "-progress",
@@ -58635,7 +58645,7 @@ var FFmpegProcessor = class {
58635
58645
  )
58636
58646
  );
58637
58647
  } else {
58638
- resolve5();
58648
+ resolve6();
58639
58649
  }
58640
58650
  });
58641
58651
  });
@@ -59625,7 +59635,7 @@ async function waitForReady(params) {
59625
59635
  if (status.status === "error" || status.status === "expired") {
59626
59636
  throw new Error(`Uploaded file is not ready: ${status.status}${status.error ? ` (${status.error})` : ""}`);
59627
59637
  }
59628
- await new Promise((resolve5) => setTimeout(resolve5, 1500));
59638
+ await new Promise((resolve6) => setTimeout(resolve6, 1500));
59629
59639
  }
59630
59640
  throw new Error("Timed out waiting for uploaded file to become ready");
59631
59641
  }
@@ -59721,8 +59731,8 @@ function createIsolatedRegexSession(pattern, ignoreCase) {
59721
59731
  let initError;
59722
59732
  let readyResolve;
59723
59733
  let readyReject;
59724
- const ready = new Promise((resolve5, reject) => {
59725
- readyResolve = resolve5;
59734
+ const ready = new Promise((resolve6, reject) => {
59735
+ readyResolve = resolve6;
59726
59736
  readyReject = reject;
59727
59737
  });
59728
59738
  void ready.catch(() => void 0);
@@ -59744,7 +59754,7 @@ function createIsolatedRegexSession(pattern, ignoreCase) {
59744
59754
  if (initError) throw initError;
59745
59755
  if (signal?.aborted) throw new Error("Operation aborted");
59746
59756
  const id = nextId++;
59747
- return new Promise((resolve5, reject) => {
59757
+ return new Promise((resolve6, reject) => {
59748
59758
  let settled = false;
59749
59759
  const finish = (error, matches) => {
59750
59760
  if (settled) return;
@@ -59754,7 +59764,7 @@ function createIsolatedRegexSession(pattern, ignoreCase) {
59754
59764
  worker.off("message", onMessage);
59755
59765
  worker.off("error", onWorkerError);
59756
59766
  if (error) reject(error);
59757
- else resolve5(matches ?? []);
59767
+ else resolve6(matches ?? []);
59758
59768
  };
59759
59769
  const terminate = (error) => {
59760
59770
  disposed = true;
@@ -60982,7 +60992,7 @@ async function handleCacheTest(host) {
60982
60992
  host.chatContainer.addChild(new Text(theme.fg("dim", ` ${summarizeUsage(result1.usage)}`), 1, 0));
60983
60993
  host.chatContainer.addChild(new Text(theme.fg("dim", " Waiting 2s before replaying identical request..."), 1, 0));
60984
60994
  host.ui.requestRender();
60985
- await new Promise((resolve5) => setTimeout(resolve5, 2e3));
60995
+ await new Promise((resolve6) => setTimeout(resolve6, 2e3));
60986
60996
  host.chatContainer.addChild(new Text(theme.fg("accent", "Request 2/2: replaying identical request..."), 1, 0));
60987
60997
  host.ui.requestRender();
60988
60998
  result2 = await completeSimple(model, context, options);
@@ -61972,16 +61982,16 @@ var Diff = class {
61972
61982
  }
61973
61983
  }
61974
61984
  }
61975
- addToPath(path30, added, removed, oldPosInc, options) {
61976
- const last = path30.lastComponent;
61985
+ addToPath(path31, added, removed, oldPosInc, options) {
61986
+ const last = path31.lastComponent;
61977
61987
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
61978
61988
  return {
61979
- oldPos: path30.oldPos + oldPosInc,
61989
+ oldPos: path31.oldPos + oldPosInc,
61980
61990
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
61981
61991
  };
61982
61992
  } else {
61983
61993
  return {
61984
- oldPos: path30.oldPos + oldPosInc,
61994
+ oldPos: path31.oldPos + oldPosInc,
61985
61995
  lastComponent: { count: 1, added, removed, previousComponent: last }
61986
61996
  };
61987
61997
  }
@@ -62429,13 +62439,13 @@ function formatSize2(bytes) {
62429
62439
  }
62430
62440
  var DEFAULT_MAX_BYTES = 102400;
62431
62441
  var DEFAULT_MAX_LINES = 100;
62432
- function shortenPath(path30) {
62433
- if (typeof path30 !== "string") return "";
62442
+ function shortenPath(path31) {
62443
+ if (typeof path31 !== "string") return "";
62434
62444
  const home = os4.homedir();
62435
- if (path30.startsWith(home)) {
62436
- return `~${path30.slice(home.length)}`;
62445
+ if (path31.startsWith(home)) {
62446
+ return `~${path31.slice(home.length)}`;
62437
62447
  }
62438
- return path30;
62448
+ return path31;
62439
62449
  }
62440
62450
  function replaceTabs(text) {
62441
62451
  return text.replace(/\t/g, " ");
@@ -62516,14 +62526,14 @@ ${renderManageTodoListResult(this.result, { expanded: this.expanded }, theme)}`;
62516
62526
  }
62517
62527
  } else if (this.toolName === "read_file") {
62518
62528
  const rawPath = str(this.args?.file_path ?? this.args?.path);
62519
- const path30 = rawPath !== null ? shortenPath(rawPath) : null;
62529
+ const path31 = rawPath !== null ? shortenPath(rawPath) : null;
62520
62530
  const offset = typeof this.args?.offset === "number" ? this.args.offset : void 0;
62521
62531
  const limit = typeof this.args?.limit === "number" ? this.args.limit : void 0;
62522
62532
  let pathDisplay;
62523
- if (path30 === null) {
62533
+ if (path31 === null) {
62524
62534
  pathDisplay = invalidArg;
62525
- } else if (path30) {
62526
- pathDisplay = theme.fg("accent", path30);
62535
+ } else if (path31) {
62536
+ pathDisplay = theme.fg("accent", path31);
62527
62537
  } else {
62528
62538
  const partialPath = partialStr(this.args?.file_path ?? this.args?.path);
62529
62539
  pathDisplay = theme.fg("toolOutput", partialPath);
@@ -62570,12 +62580,12 @@ ${renderManageTodoListResult(this.result, { expanded: this.expanded }, theme)}`;
62570
62580
  } else if (this.toolName === "write_file") {
62571
62581
  const rawPath = str(this.args?.file_path ?? this.args?.path);
62572
62582
  const fileContent = str(this.args?.content);
62573
- const path30 = rawPath !== null ? shortenPath(rawPath) : null;
62583
+ const path31 = rawPath !== null ? shortenPath(rawPath) : null;
62574
62584
  let pathDisplay;
62575
- if (path30 === null) {
62585
+ if (path31 === null) {
62576
62586
  pathDisplay = invalidArg;
62577
- } else if (path30) {
62578
- pathDisplay = theme.fg("accent", path30);
62587
+ } else if (path31) {
62588
+ pathDisplay = theme.fg("accent", path31);
62579
62589
  } else {
62580
62590
  const partialPath = partialStr(this.args?.file_path ?? this.args?.path);
62581
62591
  pathDisplay = theme.fg("toolOutput", partialPath);
@@ -62612,12 +62622,12 @@ ${theme.fg("error", errorText)}`;
62612
62622
  }
62613
62623
  } else if (this.toolName === "edit_file") {
62614
62624
  const rawPath = str(this.args?.file_path ?? this.args?.path);
62615
- const path30 = rawPath !== null ? shortenPath(rawPath) : null;
62625
+ const path31 = rawPath !== null ? shortenPath(rawPath) : null;
62616
62626
  let pathDisplay;
62617
- if (path30 === null) {
62627
+ if (path31 === null) {
62618
62628
  pathDisplay = invalidArg;
62619
- } else if (path30) {
62620
- pathDisplay = theme.fg("accent", path30);
62629
+ } else if (path31) {
62630
+ pathDisplay = theme.fg("accent", path31);
62621
62631
  } else {
62622
62632
  const partialPath = partialStr(this.args?.file_path ?? this.args?.path);
62623
62633
  pathDisplay = theme.fg("toolOutput", partialPath);
@@ -62642,7 +62652,7 @@ ${theme.fg("error", errorText)}`;
62642
62652
  const diff = this.result.details.diff;
62643
62653
  const firstChangedLine = this.result.details.firstChangedLine;
62644
62654
  if (firstChangedLine) {
62645
- text = `${theme.fg("toolTitle", theme.bold("edit_file"))} ${theme.fg("accent", path30 || rawPath)}${theme.fg("warning", `:${firstChangedLine}`)}`;
62655
+ text = `${theme.fg("toolTitle", theme.bold("edit_file"))} ${theme.fg("accent", path31 || rawPath)}${theme.fg("warning", `:${firstChangedLine}`)}`;
62646
62656
  }
62647
62657
  const lines = diff.split("\n");
62648
62658
  const maxLines = this.expanded ? lines.length : 15;
@@ -62662,7 +62672,7 @@ ${theme.fg("error", errorText)}`;
62662
62672
  const diff = generateEditDiff(oldText, newText, rawPath);
62663
62673
  const firstChangedLine = findFirstChangedLine(oldText, newText);
62664
62674
  if (firstChangedLine) {
62665
- text = `${theme.fg("toolTitle", theme.bold("edit_file"))} ${theme.fg("accent", path30 || rawPath)}${theme.fg("warning", `:${firstChangedLine}`)}`;
62675
+ text = `${theme.fg("toolTitle", theme.bold("edit_file"))} ${theme.fg("accent", path31 || rawPath)}${theme.fg("warning", `:${firstChangedLine}`)}`;
62666
62676
  }
62667
62677
  const lines = diff.split("\n");
62668
62678
  const maxLines = this.expanded ? lines.length : 15;
@@ -62681,9 +62691,9 @@ ${theme.fg("error", errorText)}`;
62681
62691
  }
62682
62692
  } else if (this.toolName === "list_dir") {
62683
62693
  const rawPath = str(this.args?.path);
62684
- const path30 = rawPath !== null ? shortenPath(rawPath || ".") : null;
62694
+ const path31 = rawPath !== null ? shortenPath(rawPath || ".") : null;
62685
62695
  const limit = this.args?.limit;
62686
- text = `${theme.fg("toolTitle", theme.bold("list_dir"))} ${path30 === null ? invalidArg : theme.fg("accent", path30)}`;
62696
+ text = `${theme.fg("toolTitle", theme.bold("list_dir"))} ${path31 === null ? invalidArg : theme.fg("accent", path31)}`;
62687
62697
  if (limit !== void 0) {
62688
62698
  text += theme.fg("toolOutput", ` (limit ${limit})`);
62689
62699
  }
@@ -62719,9 +62729,9 @@ ${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
62719
62729
  } else if (this.toolName === "find_files") {
62720
62730
  const pattern = str(this.args?.pattern);
62721
62731
  const rawPath = str(this.args?.path);
62722
- const path30 = rawPath !== null ? shortenPath(rawPath || ".") : null;
62732
+ const path31 = rawPath !== null ? shortenPath(rawPath || ".") : null;
62723
62733
  const limit = this.args?.limit;
62724
- text = theme.fg("toolTitle", theme.bold("find_files")) + " " + (pattern === null ? invalidArg : theme.fg("accent", pattern || "")) + theme.fg("toolOutput", ` in ${path30 === null ? invalidArg : path30}`);
62734
+ text = theme.fg("toolTitle", theme.bold("find_files")) + " " + (pattern === null ? invalidArg : theme.fg("accent", pattern || "")) + theme.fg("toolOutput", ` in ${path31 === null ? invalidArg : path31}`);
62725
62735
  if (limit !== void 0) {
62726
62736
  text += theme.fg("toolOutput", ` (limit ${limit})`);
62727
62737
  }
@@ -62757,10 +62767,10 @@ ${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
62757
62767
  } else if (this.toolName === "grep_text") {
62758
62768
  const pattern = str(this.args?.pattern);
62759
62769
  const rawPath = str(this.args?.path);
62760
- const path30 = rawPath !== null ? shortenPath(rawPath || ".") : null;
62770
+ const path31 = rawPath !== null ? shortenPath(rawPath || ".") : null;
62761
62771
  const glob = str(this.args?.glob);
62762
62772
  const limit = this.args?.limit;
62763
- text = theme.fg("toolTitle", theme.bold("grep_text")) + " " + (pattern === null ? invalidArg : theme.fg("accent", `/${pattern || ""}/`)) + theme.fg("toolOutput", ` in ${path30 === null ? invalidArg : path30}`);
62773
+ text = theme.fg("toolTitle", theme.bold("grep_text")) + " " + (pattern === null ? invalidArg : theme.fg("accent", `/${pattern || ""}/`)) + theme.fg("toolOutput", ` in ${path31 === null ? invalidArg : path31}`);
62764
62774
  if (glob) {
62765
62775
  text += theme.fg("toolOutput", ` (${glob})`);
62766
62776
  }
@@ -63214,8 +63224,8 @@ async function forkAtEntry(host, entryId) {
63214
63224
  host.showError("Failed to branch at entry");
63215
63225
  return;
63216
63226
  }
63217
- const path30 = host.sessionManager.getPathToEntry(entryId);
63218
- const pathNames = path30.map((e) => e.message?.role || "entry").join(" \u2192 ");
63227
+ const path31 = host.sessionManager.getPathToEntry(entryId);
63228
+ const pathNames = path31.map((e) => e.message?.role || "entry").join(" \u2192 ");
63219
63229
  const messages = host.sessionManager.getMessages();
63220
63230
  host.syncAgentFromActiveSession(messages);
63221
63231
  await host.syncSessionScopedState(messages);
@@ -63228,7 +63238,7 @@ async function forkAtEntry(host, entryId) {
63228
63238
  host.updatePendingMessagesDisplay();
63229
63239
  host.renderMessageHistory(messages);
63230
63240
  await host.sessionManager.save();
63231
- host.showStatus(`Branched at: ${pathNames} (${path30.length} messages). Continue to add to this branch.`);
63241
+ host.showStatus(`Branched at: ${pathNames} (${path31.length} messages). Continue to add to this branch.`);
63232
63242
  } catch (error) {
63233
63243
  host.showError(
63234
63244
  `Failed to branch: ${error instanceof Error ? error.message : String(error)}`
@@ -63256,10 +63266,10 @@ async function navigateToEntry(host, entryId) {
63256
63266
  host.sessionManager.save().catch((err) => {
63257
63267
  console.error("[Session] Save after navigation failed:", err);
63258
63268
  });
63259
- const path30 = host.sessionManager.getPathToEntry(entryId);
63269
+ const path31 = host.sessionManager.getPathToEntry(entryId);
63260
63270
  const entry = host.sessionManager.getEntry(entryId);
63261
63271
  const role = entry?.message?.role || "entry";
63262
- host.showStatus(`Switched to branch: ${role} (${path30.length} messages in path)`);
63272
+ host.showStatus(`Switched to branch: ${role} (${path31.length} messages in path)`);
63263
63273
  } catch (error) {
63264
63274
  host.showError(
63265
63275
  `Failed to navigate: ${error instanceof Error ? error.message : String(error)}`
@@ -65049,7 +65059,7 @@ function setupInteractiveEditorSubmitHandler(host) {
65049
65059
  host.chatContainer.addChild(userMsg);
65050
65060
  host.editor.setText("");
65051
65061
  host.ui.requestRender();
65052
- await new Promise((resolve5) => setImmediate(resolve5));
65062
+ await new Promise((resolve6) => setImmediate(resolve6));
65053
65063
  let finalContent = messageContent;
65054
65064
  const reminderPrefix = host.executionReminder;
65055
65065
  const combinedPrefix = [reminderPrefix].filter((value) => Boolean(value)).join("");
@@ -67703,11 +67713,11 @@ var HierarchicalSelectorComponent = class extends Container {
67703
67713
  // src/runtime/interactive-ui-helpers.ts
67704
67714
  function showHierarchicalMenu(host, initialPath = []) {
67705
67715
  const basePath = [...initialPath];
67706
- const showAtPath = (path30) => {
67716
+ const showAtPath = (path31) => {
67707
67717
  host.showSelector((done) => {
67708
67718
  const selector = new HierarchicalSelectorComponent({
67709
67719
  tree: commandTree,
67710
- path: path30,
67720
+ path: path31,
67711
67721
  basePath,
67712
67722
  onNavigate: (newPath) => {
67713
67723
  done();
@@ -67715,7 +67725,7 @@ function showHierarchicalMenu(host, initialPath = []) {
67715
67725
  },
67716
67726
  onSelect: async (selectedPath, node, searchArgs) => {
67717
67727
  if (node.handler) {
67718
- const args = searchArgs || (selectedPath.length > path30.length ? selectedPath.slice(path30.length).join(" ") : void 0);
67728
+ const args = searchArgs || (selectedPath.length > path31.length ? selectedPath.slice(path31.length).join(" ") : void 0);
67719
67729
  const commandPath = "/" + selectedPath.join("/");
67720
67730
  if (!args && host.isInteractiveCommand(commandPath)) {
67721
67731
  done();
@@ -68394,7 +68404,7 @@ async function handleDirectBash(host, command) {
68394
68404
  child.stderr.on("data", (data) => {
68395
68405
  output.append(data.toString());
68396
68406
  });
68397
- return new Promise((resolve5) => {
68407
+ return new Promise((resolve6) => {
68398
68408
  let settled = false;
68399
68409
  const finish = (code) => {
68400
68410
  if (settled) return;
@@ -68407,7 +68417,7 @@ async function handleDirectBash(host, command) {
68407
68417
  }
68408
68418
  host.chatContainer.addChild(new Spacer(1));
68409
68419
  host.ui.requestRender();
68410
- resolve5();
68420
+ resolve6();
68411
68421
  };
68412
68422
  child.on("error", (error) => {
68413
68423
  output.append(error.message);
@@ -68450,11 +68460,11 @@ function installInteractiveInteractionHandler(host) {
68450
68460
  if (!("timeoutMs" in request) || !request.timeoutMs || request.timeoutMs <= 0) {
68451
68461
  return { value: await promise, timedOut: false };
68452
68462
  }
68453
- return await new Promise((resolve5, reject) => {
68454
- const timer = setTimeout(() => resolve5({ timedOut: true }), request.timeoutMs);
68463
+ return await new Promise((resolve6, reject) => {
68464
+ const timer = setTimeout(() => resolve6({ timedOut: true }), request.timeoutMs);
68455
68465
  promise.then((value) => {
68456
68466
  clearTimeout(timer);
68457
- resolve5({ value, timedOut: false });
68467
+ resolve6({ value, timedOut: false });
68458
68468
  }).catch((error) => {
68459
68469
  clearTimeout(timer);
68460
68470
  reject(error);
@@ -68554,15 +68564,15 @@ function showExtensionNotification(host, message, type = "info") {
68554
68564
  host.ui.requestRender();
68555
68565
  }
68556
68566
  function showExtensionSelector2(host, title, options, opts) {
68557
- return new Promise((resolve5) => {
68567
+ return new Promise((resolve6) => {
68558
68568
  host.showStatus(`Waiting for selection: ${title}`);
68559
68569
  if (opts?.signal?.aborted) {
68560
- resolve5(void 0);
68570
+ resolve6(void 0);
68561
68571
  return;
68562
68572
  }
68563
68573
  const onAbort = () => {
68564
68574
  host.restoreEditor();
68565
- resolve5(void 0);
68575
+ resolve6(void 0);
68566
68576
  };
68567
68577
  opts?.signal?.addEventListener("abort", onAbort, { once: true });
68568
68578
  const selector = new ExtensionSelectorComponent(
@@ -68571,12 +68581,12 @@ function showExtensionSelector2(host, title, options, opts) {
68571
68581
  (option) => {
68572
68582
  opts?.signal?.removeEventListener("abort", onAbort);
68573
68583
  host.restoreEditor();
68574
- resolve5(option);
68584
+ resolve6(option);
68575
68585
  },
68576
68586
  () => {
68577
68587
  opts?.signal?.removeEventListener("abort", onAbort);
68578
68588
  host.restoreEditor();
68579
- resolve5(void 0);
68589
+ resolve6(void 0);
68580
68590
  }
68581
68591
  );
68582
68592
  host.editorContainer.clear();
@@ -68592,15 +68602,15 @@ ${message}`, ["Yes", "No"], opts);
68592
68602
  return result === "Yes";
68593
68603
  }
68594
68604
  function showExtensionInput(host, title, placeholder, opts) {
68595
- return new Promise((resolve5) => {
68605
+ return new Promise((resolve6) => {
68596
68606
  host.showStatus(`Waiting for input: ${title}`);
68597
68607
  if (opts?.signal?.aborted) {
68598
- resolve5(void 0);
68608
+ resolve6(void 0);
68599
68609
  return;
68600
68610
  }
68601
68611
  const onAbort = () => {
68602
68612
  host.restoreEditor();
68603
- resolve5(void 0);
68613
+ resolve6(void 0);
68604
68614
  };
68605
68615
  opts?.signal?.addEventListener("abort", onAbort, { once: true });
68606
68616
  const input = new ExtensionInputComponent(
@@ -68609,12 +68619,12 @@ function showExtensionInput(host, title, placeholder, opts) {
68609
68619
  (value) => {
68610
68620
  opts?.signal?.removeEventListener("abort", onAbort);
68611
68621
  host.restoreEditor();
68612
- resolve5(value);
68622
+ resolve6(value);
68613
68623
  },
68614
68624
  () => {
68615
68625
  opts?.signal?.removeEventListener("abort", onAbort);
68616
68626
  host.restoreEditor();
68617
- resolve5(void 0);
68627
+ resolve6(void 0);
68618
68628
  }
68619
68629
  );
68620
68630
  host.editorContainer.clear();
@@ -68625,7 +68635,7 @@ function showExtensionInput(host, title, placeholder, opts) {
68625
68635
  });
68626
68636
  }
68627
68637
  function showExtensionEditor(host, title, prefill) {
68628
- return new Promise((resolve5) => {
68638
+ return new Promise((resolve6) => {
68629
68639
  host.showStatus(`Waiting for input: ${title}`);
68630
68640
  const container = new Container();
68631
68641
  container.addChild(new Text(theme.bold(theme.fg("accent", title)), 0, 0));
@@ -68647,12 +68657,12 @@ function showExtensionEditor(host, title, prefill) {
68647
68657
  preview: value.slice(0, 120)
68648
68658
  });
68649
68659
  host.restoreEditor();
68650
- resolve5(value);
68660
+ resolve6(value);
68651
68661
  };
68652
68662
  editor.onEscape = () => {
68653
68663
  host.logDebug("extension:editor:cancel", { title });
68654
68664
  host.restoreEditor();
68655
- resolve5(void 0);
68665
+ resolve6(void 0);
68656
68666
  };
68657
68667
  container.addChild(editor);
68658
68668
  container.addChild(new Spacer(1));
@@ -68666,14 +68676,14 @@ function showExtensionEditor(host, title, prefill) {
68666
68676
  }
68667
68677
  function showExtensionCustom(host, factory, options) {
68668
68678
  const savedText = host.editor.getText();
68669
- return new Promise((resolve5, reject) => {
68679
+ return new Promise((resolve6, reject) => {
68670
68680
  let closed = false;
68671
68681
  const close = (result) => {
68672
68682
  if (closed) return;
68673
68683
  closed = true;
68674
68684
  host.restoreEditor();
68675
68685
  host.editor.setText(savedText);
68676
- resolve5(result);
68686
+ resolve6(result);
68677
68687
  };
68678
68688
  Promise.resolve(factory(host.ui, theme, close)).then((component) => {
68679
68689
  if (closed) return;
@@ -68885,8 +68895,8 @@ async function loadInteractiveExtensions(host) {
68885
68895
  );
68886
68896
  host.extensionRunner.setUIContext(host.extensionUIContext);
68887
68897
  if (process.env.PIE_VERBOSE) {
68888
- for (const { path: path30, error } of errors) {
68889
- console.error(`[Extension] Failed to load ${path30}: ${error}`);
68898
+ for (const { path: path31, error } of errors) {
68899
+ console.error(`[Extension] Failed to load ${path31}: ${error}`);
68890
68900
  }
68891
68901
  }
68892
68902
  const extensionTools = convertExtensionTools(extensions);
@@ -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({
@@ -70368,7 +70396,7 @@ async function runJsonEventsMode(params) {
70368
70396
  return typeof message.sessionId === "string" && message.sessionId !== sessionId;
70369
70397
  }
70370
70398
  function delay(ms) {
70371
- return new Promise((resolve5) => setTimeout(resolve5, Math.max(0, ms)));
70399
+ return new Promise((resolve6) => setTimeout(resolve6, Math.max(0, ms)));
70372
70400
  }
70373
70401
  async function waitForActiveController(timeoutMs = 1e3) {
70374
70402
  const deadline = Date.now() + timeoutMs;
@@ -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 ?? turn.summary).trim() });
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, error: detail || "turn failed" });
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" });
@@ -70736,6 +70783,7 @@ async function runJsonEventsMode(params) {
70736
70783
  cwd: runtime.cwd,
70737
70784
  skillsSection: runtime.skillsSection,
70738
70785
  knowledgeSection: runtime.knowledgeSection,
70786
+ appendSystemPrompt: params.developerInstructions,
70739
70787
  tools: tools.map((tool) => ({ name: tool.name, description: tool.description }))
70740
70788
  });
70741
70789
  agent = new AgentClass({
@@ -70926,7 +70974,7 @@ async function runJsonEventsMode(params) {
70926
70974
  try {
70927
70975
  await ensureRuntime(message.cwd);
70928
70976
  } catch (error) {
70929
- finalize("failed", error instanceof Error ? error.message : String(error));
70977
+ finalize("failed", errorToFailureDetail(error));
70930
70978
  if (activeTurn === turn) emitSettled(turn);
70931
70979
  if (activeTurn === turn) activeTurn = null;
70932
70980
  return;
@@ -71142,20 +71190,44 @@ async function runJsonEventsMode(params) {
71142
71190
  await disposeRuntime();
71143
71191
  }
71144
71192
 
71145
- // src/cli.ts
71146
- enableEarlyLogBuffer();
71147
- var logError = (msg, err) => {
71148
- const logPath = getRuntimeLogPath();
71149
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
71150
- const stack = err instanceof Error ? err.stack || "" : "";
71151
- fs26.mkdirSync(path29.dirname(logPath), { recursive: true });
71152
- fs26.appendFileSync(logPath, `[${timestamp}] ${msg}
71153
- ${stack}
71193
+ // src/developer-instructions.ts
71194
+ import * as fs26 from "fs";
71195
+ import * as path29 from "path";
71196
+ var MAX_DEVELOPER_INSTRUCTIONS_CHARS = 64e3;
71197
+ function readTextFileBounded(filePath) {
71198
+ const resolved = path29.resolve(filePath);
71199
+ const stat2 = fs26.statSync(resolved);
71200
+ if (!stat2.isFile()) {
71201
+ throw new Error(`Developer instructions file is not a regular file: ${filePath}`);
71202
+ }
71203
+ if (stat2.size > MAX_DEVELOPER_INSTRUCTIONS_CHARS * 4) {
71204
+ throw new Error(`Developer instructions file is too large: ${filePath}`);
71205
+ }
71206
+ return fs26.readFileSync(resolved, "utf8");
71207
+ }
71208
+ function collectFlagValues(args, flag) {
71209
+ const values = [];
71210
+ for (let i = 0; i < args.length; i += 1) {
71211
+ if (args[i] === flag && args[i + 1]) {
71212
+ values.push(args[i + 1]);
71213
+ i += 1;
71214
+ }
71215
+ }
71216
+ return values;
71217
+ }
71218
+ function resolveDeveloperInstructionsFromArgs(args) {
71219
+ const direct = collectFlagValues(args, "--developer-instructions");
71220
+ const files = collectFlagValues(args, "--developer-instructions-file").map(readTextFileBounded);
71221
+ const parts = [...direct, ...files].map((part) => part.trim()).filter(Boolean);
71222
+ if (parts.length === 0) return void 0;
71223
+ const combined = parts.join("\n\n");
71224
+ if (combined.length > MAX_DEVELOPER_INSTRUCTIONS_CHARS) {
71225
+ throw new Error(`Developer instructions exceed ${MAX_DEVELOPER_INSTRUCTIONS_CHARS} characters`);
71226
+ }
71227
+ return combined;
71228
+ }
71154
71229
 
71155
- `);
71156
- };
71157
- setupGlobalErrorHandlers(logError);
71158
- migrateConfigFromAgentDir();
71230
+ // src/cli-help.ts
71159
71231
  function showHelp() {
71160
71232
  console.log(`
71161
71233
  Pie AI Agent CLI
@@ -71194,11 +71266,37 @@ Print Mode Options:
71194
71266
  --json-output Print structured JSON in non-interactive mode
71195
71267
  --json-events Run JSONL protocol mode over stdin/stdout
71196
71268
  --session-id Reuse or create a specific session in non-interactive mode
71269
+ --resume-required In JSON-events mode, fail if --session-id cannot be resumed
71270
+ --developer-instructions <text> Append stable host/developer instructions in JSON-events mode
71271
+ --developer-instructions-file <path> Read stable host/developer instructions from a file
71197
71272
  --extension-path Add an extra extension search directory (repeatable)
71198
71273
  --no-builtin-extensions Skip built-in extensions (keep user/project ones)
71199
71274
  --no-extensions Skip all discovered extensions (keeps --extension-path)
71200
71275
  `);
71201
71276
  }
71277
+
71278
+ // src/cli.ts
71279
+ enableEarlyLogBuffer();
71280
+ var logError = (msg, err) => {
71281
+ const logPath = getRuntimeLogPath();
71282
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
71283
+ const stack = err instanceof Error ? err.stack || "" : "";
71284
+ fs27.mkdirSync(path30.dirname(logPath), { recursive: true });
71285
+ fs27.appendFileSync(logPath, `[${timestamp}] ${msg}
71286
+ ${stack}
71287
+
71288
+ `);
71289
+ };
71290
+ setupGlobalErrorHandlers(logError);
71291
+ migrateConfigFromAgentDir();
71292
+ var STABLE_CLI_COMMANDS = {
71293
+ chat: "chat",
71294
+ doctor: "doctor",
71295
+ models: "models",
71296
+ sessions: "sessions",
71297
+ extensions: "extensions",
71298
+ permissions: "permissions"
71299
+ };
71202
71300
  async function runDoctorCommand(args) {
71203
71301
  const json = args.includes("--json");
71204
71302
  const report = await runDoctor();
@@ -71273,16 +71371,6 @@ async function runModelsCommand(args) {
71273
71371
  pie models init [--path <path>] [--force] [--stdout]
71274
71372
  pie models validate [--path <path>] [--probe web_search] [--json]`);
71275
71373
  }
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
71374
  async function runWithJsonEventsConsoleIsolation(fn) {
71287
71375
  const originalLog = console.log;
71288
71376
  const originalInfo = console.info;
@@ -71301,34 +71389,47 @@ async function runWithJsonEventsConsoleIsolation(fn) {
71301
71389
  }
71302
71390
  async function createCliTestStreamFnFromEnv() {
71303
71391
  if (!process.env.PIE_TEST_MOCK_STREAM_SEQUENCE) return void 0;
71304
- return (await import("./chunks/test-stream-A7JSM2UM.js")).createTestStreamFnFromSequenceEnv();
71392
+ return (await import("./chunks/test-stream-L4PUYWQQ.js")).createTestStreamFnFromSequenceEnv();
71305
71393
  }
71306
71394
  async function startChat(initialPrompt, testCommand) {
71307
71395
  const rawOutput = process.argv.includes("--raw-output");
71308
71396
  const jsonOutput = process.argv.includes("--json-output");
71309
71397
  const jsonEvents = process.argv.includes("--json-events");
71398
+ const resumeRequired = process.argv.includes("--resume-required");
71310
71399
  const sessionIdFlagIndex = process.argv.indexOf("--session-id");
71311
71400
  const explicitSessionId = sessionIdFlagIndex >= 0 ? process.argv[sessionIdFlagIndex + 1] : void 0;
71312
71401
  const extensionPaths = parseRepeatedFlag(process.argv, "--extension-path");
71313
71402
  const extensionFlags = parseExtensionFlags(process.argv);
71314
71403
  if (jsonEvents) {
71404
+ let developerInstructions;
71405
+ try {
71406
+ developerInstructions = resolveDeveloperInstructionsFromArgs(process.argv);
71407
+ } catch (error) {
71408
+ console.error(error instanceof Error ? `Error: ${error.message}` : String(error));
71409
+ process.exit(1);
71410
+ }
71315
71411
  await runWithJsonEventsConsoleIsolation(async () => {
71316
71412
  if (process.env.PIE_TEST_MOCK_RESPONSE !== void 0) {
71317
71413
  await runJsonEventsMode({
71318
71414
  explicitSessionId,
71415
+ resumeRequired,
71416
+ developerInstructions,
71319
71417
  mockResponse: process.env.PIE_TEST_MOCK_RESPONSE
71320
71418
  });
71321
71419
  return;
71322
71420
  }
71323
71421
  await runJsonEventsMode({
71324
71422
  explicitSessionId,
71423
+ resumeRequired,
71424
+ developerInstructions,
71325
71425
  streamFn: await createCliTestStreamFnFromEnv(),
71326
71426
  createRuntime: async ({ cwd, sessionId }) => composeCliRuntime({
71327
71427
  explicitSessionId: explicitSessionId ?? sessionId,
71328
71428
  extensionPaths,
71329
71429
  extensionFlags,
71330
71430
  cwd,
71331
- warnIfExplicitSessionMissing: false
71431
+ warnIfExplicitSessionMissing: false,
71432
+ requireExistingSession: resumeRequired && !!explicitSessionId
71332
71433
  })
71333
71434
  });
71334
71435
  });
@@ -71383,9 +71484,9 @@ async function startChat(initialPrompt, testCommand) {
71383
71484
  flushEarlyLogs();
71384
71485
  if (testCommand) {
71385
71486
  console.log(`[TEST] Auto-executing command: ${testCommand}`);
71386
- await new Promise((resolve5) => setTimeout(resolve5, 500));
71487
+ await new Promise((resolve6) => setTimeout(resolve6, 500));
71387
71488
  await interactive.executeCommand(testCommand);
71388
- await new Promise((resolve5) => setTimeout(resolve5, 2e3));
71489
+ await new Promise((resolve6) => setTimeout(resolve6, 2e3));
71389
71490
  console.log("[TEST] Command executed, exiting...");
71390
71491
  process.exit(0);
71391
71492
  return;
@@ -71406,11 +71507,11 @@ async function main() {
71406
71507
  console.log(VERSION);
71407
71508
  return;
71408
71509
  }
71409
- if (args[0] === "doctor") {
71510
+ if (args[0] === STABLE_CLI_COMMANDS.doctor) {
71410
71511
  await runDoctorCommand(args.slice(1));
71411
71512
  return;
71412
71513
  }
71413
- if (args[0] === "models") {
71514
+ if (args[0] === STABLE_CLI_COMMANDS.models) {
71414
71515
  try {
71415
71516
  await runModelsCommand(args.slice(1));
71416
71517
  } catch (error) {
@@ -71419,15 +71520,15 @@ async function main() {
71419
71520
  }
71420
71521
  return;
71421
71522
  }
71422
- if (args[0] === "sessions") {
71523
+ if (args[0] === STABLE_CLI_COMMANDS.sessions) {
71423
71524
  await runSessionsCommand(args.slice(1));
71424
71525
  return;
71425
71526
  }
71426
- if (args[0] === "extensions") {
71527
+ if (args[0] === STABLE_CLI_COMMANDS.extensions) {
71427
71528
  await runExtensionsCommand(args.slice(1));
71428
71529
  return;
71429
71530
  }
71430
- if (args[0] === "permissions") {
71531
+ if (args[0] === STABLE_CLI_COMMANDS.permissions) {
71431
71532
  console.log(formatPermissionsHelp());
71432
71533
  return;
71433
71534
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cydm/pie",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "description": "Pie AI Agent CLI",
5
5
  "type": "module",
6
6
  "bin": {