@cydm/pie 4.4.2 → 4.5.0

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.
Files changed (48) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +6 -6
  2. package/dist/builtin/extensions/changelog/index.js +1 -1
  3. package/dist/builtin/extensions/cron/index.js +55 -7
  4. package/dist/builtin/extensions/document-attachments/index.js +1 -1
  5. package/dist/builtin/extensions/herdr-agent-state/index.js +1 -1
  6. package/dist/builtin/extensions/im-forward/README.md +3 -1
  7. package/dist/builtin/extensions/im-forward/index.js +364 -118
  8. package/dist/builtin/extensions/init/index.js +1 -1
  9. package/dist/builtin/extensions/mcp-adapter/index.js +2 -2
  10. package/dist/builtin/extensions/memory/index.js +9 -11
  11. package/dist/builtin/extensions/pie-ipc/index.js +70 -19
  12. package/dist/builtin/extensions/pie-proc/index.js +27 -13
  13. package/dist/builtin/extensions/plan-mode/index.js +6 -6
  14. package/dist/builtin/extensions/subagent/index.js +9 -11
  15. package/dist/builtin/extensions/todo/index.js +6 -6
  16. package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +24 -1
  17. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +86 -21
  18. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +6 -1
  19. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
  20. package/dist/builtin/skills/chrome-devtools-axi/{cli-CHC7XYFU.js → cli-NLPMVDGG.js} +32 -4
  21. package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +220 -22
  22. package/dist/chunks/{auth-storage-RABPRJ6T.js → auth-storage-C3FZMT7J.js} +3 -3
  23. package/dist/chunks/{chunk-OFLKAWI4.js → chunk-2CJIENLY.js} +90 -100
  24. package/dist/chunks/{chunk-R7VO46EK.js → chunk-3W3SXVPB.js} +5 -4
  25. package/dist/chunks/{chunk-IPLMGAML.js → chunk-5KI4Y4LA.js} +1 -1
  26. package/dist/chunks/{chunk-YNTIOWCD.js → chunk-BLDI2GRF.js} +5 -5
  27. package/dist/chunks/{chunk-UCKOXAME.js → chunk-CBDQJMUI.js} +9 -44
  28. package/dist/chunks/chunk-CGSFBWOM.js +100 -0
  29. package/dist/chunks/{chunk-7LTQLJJF.js → chunk-LAJXWOKS.js} +15 -10
  30. package/dist/chunks/{chunk-RZGYXAJU.js → chunk-LZQXQOPJ.js} +1 -12
  31. package/dist/chunks/{chunk-EQOI6RZV.js → chunk-NHV2CALB.js} +3 -5
  32. package/dist/chunks/{chunk-OV7SLSHR.js → chunk-SW2E33UL.js} +2 -4
  33. package/dist/chunks/{chunk-BPSCGGVF.js → chunk-XXGYUYXI.js} +1 -1
  34. package/dist/chunks/{chunk-XO3NM7BB.js → chunk-Y3I2UV5Y.js} +3 -3
  35. package/dist/chunks/{chunk-IZDNZW3S.js → chunk-Z2FKA2ZH.js} +8 -8
  36. package/dist/chunks/chunk-ZPJ3BNQB.js +126 -0
  37. package/dist/chunks/{config-HF2PDLN5.js → config-4EOI5NOU.js} +2 -4
  38. package/dist/chunks/{manager-cli-BYCF4RKN.js → manager-cli-2ATPC47M.js} +35 -5
  39. package/dist/chunks/manager-upgrade-5CPKTRJ7.js +562 -0
  40. package/dist/chunks/{model-registry-7FNIUYPF.js → model-registry-3XAHXXTA.js} +5 -5
  41. package/dist/chunks/{src-OVWRBWKU.js → src-B44QWSGM.js} +4 -4
  42. package/dist/chunks/{src-A5YI46OD.js → src-CLE5ILN4.js} +6 -6
  43. package/dist/chunks/{src-OA3TP6DS.js → src-EGXFJ3WA.js} +5 -5
  44. package/dist/chunks/{src-TF2RAGRU.js → src-Q7LU27C2.js} +3 -3
  45. package/dist/chunks/{test-stream-7YZDGBPO.js → test-stream-OR3EJBNF.js} +3 -3
  46. package/dist/cli.js +173 -136
  47. package/package.json +3 -3
  48. package/dist/chunks/chunk-7KLWHWZD.js +0 -164
package/dist/cli.js CHANGED
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from "node:module"; const require =
3
3
  import {
4
4
  AuthStorage,
5
5
  FileAuthStorageBackend
6
- } from "./chunks/chunk-OV7SLSHR.js";
6
+ } from "./chunks/chunk-SW2E33UL.js";
7
7
  import {
8
8
  ModelRegistry
9
- } from "./chunks/chunk-EQOI6RZV.js";
9
+ } from "./chunks/chunk-NHV2CALB.js";
10
10
  import {
11
11
  distillWorkerLogPath,
12
12
  readDistillWorkerLog,
@@ -14,10 +14,11 @@ import {
14
14
  runDistillWorkerMain,
15
15
  spawnDistillAutoWorker,
16
16
  spawnDistillWorker
17
- } from "./chunks/chunk-IZDNZW3S.js";
17
+ } from "./chunks/chunk-Z2FKA2ZH.js";
18
18
  import {
19
+ SessionOwnershipLifecycle,
19
20
  claimSessionOwnership
20
- } from "./chunks/chunk-7KLWHWZD.js";
21
+ } from "./chunks/chunk-CGSFBWOM.js";
21
22
  import {
22
23
  CLI_RETRY_MAX_RETRIES,
23
24
  classifyCliFailure,
@@ -34,7 +35,7 @@ import {
34
35
  logTransportLifecycle,
35
36
  setYoloGrantListener,
36
37
  truncateHeadTail
37
- } from "./chunks/chunk-7LTQLJJF.js";
38
+ } from "./chunks/chunk-LAJXWOKS.js";
38
39
  import {
39
40
  VERSION,
40
41
  getAgentDir,
@@ -48,9 +49,8 @@ import {
48
49
  getSessionsDir,
49
50
  getSettingsPath,
50
51
  getThemesDir,
51
- init_config,
52
52
  migrateConfigFromAgentDir
53
- } from "./chunks/chunk-UCKOXAME.js";
53
+ } from "./chunks/chunk-CBDQJMUI.js";
54
54
  import {
55
55
  BUILTIN_TOOL_CAPABILITY_METADATA,
56
56
  MemoryStore,
@@ -80,7 +80,7 @@ import {
80
80
  shouldPreserveExecutionStateForUserText,
81
81
  supersedeExecutionState,
82
82
  todayKey
83
- } from "./chunks/chunk-YNTIOWCD.js";
83
+ } from "./chunks/chunk-BLDI2GRF.js";
84
84
  import {
85
85
  AGENTS_CONTEXT_FILE_NAME,
86
86
  AgentSessionController,
@@ -120,8 +120,8 @@ import {
120
120
  setEnablementInMap,
121
121
  setExtensionEnabledInSettings,
122
122
  verifyPreparedCompactionCommit
123
- } from "./chunks/chunk-XO3NM7BB.js";
124
- import "./chunks/chunk-IPLMGAML.js";
123
+ } from "./chunks/chunk-Y3I2UV5Y.js";
124
+ import "./chunks/chunk-5KI4Y4LA.js";
125
125
  import {
126
126
  Deref,
127
127
  Errors,
@@ -140,7 +140,7 @@ import {
140
140
  setLogger,
141
141
  streamSimple,
142
142
  type_exports
143
- } from "./chunks/chunk-R7VO46EK.js";
143
+ } from "./chunks/chunk-3W3SXVPB.js";
144
144
  import {
145
145
  IsArray,
146
146
  IsBigInt,
@@ -154,10 +154,11 @@ import {
154
154
  Type,
155
155
  TypeBoxError,
156
156
  TypeSystemPolicy
157
- } from "./chunks/chunk-BPSCGGVF.js";
157
+ } from "./chunks/chunk-XXGYUYXI.js";
158
158
  import {
159
159
  readImageFormat
160
160
  } from "./chunks/chunk-F7EBZTZO.js";
161
+ import "./chunks/chunk-ZPJ3BNQB.js";
161
162
  import {
162
163
  resolveCliProjectRoot
163
164
  } from "./chunks/chunk-WLFOBECN.js";
@@ -165,7 +166,7 @@ import {
165
166
  __commonJS,
166
167
  __require,
167
168
  __toESM
168
- } from "./chunks/chunk-RZGYXAJU.js";
169
+ } from "./chunks/chunk-LZQXQOPJ.js";
169
170
 
170
171
  // ../../node_modules/color-name/index.js
171
172
  var require_color_name = __commonJS({
@@ -51396,11 +51397,7 @@ function parseRepeatedFlag(args, flag) {
51396
51397
  return values;
51397
51398
  }
51398
51399
 
51399
- // src/cli.ts
51400
- init_config();
51401
-
51402
51400
  // src/debug/file-logger.ts
51403
- init_config();
51404
51401
  import * as fs from "fs";
51405
51402
  import * as path from "path";
51406
51403
  var FileLogger = class {
@@ -51756,7 +51753,6 @@ import { delimiter } from "node:path";
51756
51753
  // src/core/settings-manager.ts
51757
51754
  import * as fs2 from "fs";
51758
51755
  import * as path2 from "path";
51759
- init_config();
51760
51756
  function getDisabledToolNames(settingsManager) {
51761
51757
  const disabled = new Set(typeof settingsManager?.getDisabledTools === "function" ? settingsManager.getDisabledTools() : []);
51762
51758
  if (disabled.has("bash") || disabled.has("shell")) {
@@ -52160,7 +52156,6 @@ var SettingsManager = class {
52160
52156
  };
52161
52157
 
52162
52158
  // src/doctor.ts
52163
- init_config();
52164
52159
  var require2 = createRequire(import.meta.url);
52165
52160
  var UNITY_INSTANCE_MAX_AGE_SEC = 120;
52166
52161
  function checkStatus(checks) {
@@ -52644,7 +52639,6 @@ Disable or narrow capabilities:
52644
52639
  }
52645
52640
 
52646
52641
  // src/commands/models-config.ts
52647
- init_config();
52648
52642
  import * as fs4 from "node:fs";
52649
52643
  import * as path4 from "node:path";
52650
52644
  function getDefaultModelsPath() {
@@ -53332,7 +53326,6 @@ function truncateText(text, maxChars) {
53332
53326
  }
53333
53327
 
53334
53328
  // src/capabilities.ts
53335
- init_config();
53336
53329
  function buildCapabilitiesReport() {
53337
53330
  return {
53338
53331
  name: "pie",
@@ -53557,7 +53550,6 @@ function runCapabilitiesCommand(args) {
53557
53550
  }
53558
53551
 
53559
53552
  // src/commands/memory-cli.ts
53560
- init_config();
53561
53553
  import * as fs5 from "node:fs";
53562
53554
  import * as path5 from "node:path";
53563
53555
  import { pathToFileURL } from "node:url";
@@ -53724,7 +53716,13 @@ async function cronStore() {
53724
53716
  function managedMemoryCommand() {
53725
53717
  const entry = process.argv[1] ? path5.resolve(process.argv[1]) : null;
53726
53718
  if (!entry) throw new Error("cannot determine the CLI entrypoint for the managed schedule");
53727
- const loaderArgs = process.execArgv.filter((a) => a.startsWith("--import") || a.startsWith("--loader"));
53719
+ const loaderArgs = [];
53720
+ for (let i = 0; i < process.execArgv.length; i++) {
53721
+ const arg = process.execArgv[i];
53722
+ if (/^--(?:import|loader|experimental-loader)=/.test(arg)) loaderArgs.push(arg);
53723
+ else if (/^--(?:import|loader|experimental-loader)$/.test(arg) && i + 1 < process.execArgv.length)
53724
+ loaderArgs.push(arg, process.execArgv[++i]);
53725
+ }
53728
53726
  return [process.execPath, ...loaderArgs, entry, "memory", "distill", "--worker", "--auto", "--memory-root", path5.join(getConfigDir(), "memory")];
53729
53727
  }
53730
53728
  function timeToCron(value) {
@@ -53771,10 +53769,6 @@ async function runScheduleCommand(rest) {
53771
53769
  } catch (error) {
53772
53770
  die(String(error instanceof Error ? error.message : error));
53773
53771
  }
53774
- try {
53775
- fs5.rmSync(path5.join(getConfigDir(), "cron", "memory-disabled"), { force: true });
53776
- } catch {
53777
- }
53778
53772
  console.log(`memory schedule on: daily at ${time} local (${cron.cron} UTC; fixed-UTC \u2014 DST shifts the local time). Runs: ${command.join(" ")}`);
53779
53773
  if (replacedBefore && replacedBefore.id !== job.id && (replacedBefore.state === "blocked" || replacedBefore.enabled === false)) {
53780
53774
  console.log(`note: replaced an existing ${replacedBefore.state === "blocked" ? "BLOCKED" : "paused"} job (was id ${replacedBefore.id.slice(0, 8)}); its pending review record is reset.`);
@@ -53783,17 +53777,16 @@ async function runScheduleCommand(rest) {
53783
53777
  return;
53784
53778
  }
53785
53779
  if (action === "off") {
53786
- const existing = store.findProcess(MEMORY_MANAGER);
53780
+ let removed;
53787
53781
  try {
53788
- fs5.writeFileSync(path5.join(getConfigDir(), "cron", "memory-disabled"), (/* @__PURE__ */ new Date()).toISOString());
53789
- } catch {
53782
+ removed = store.disableProcess(MEMORY_MANAGER);
53783
+ } catch (error) {
53784
+ die(String(error instanceof Error ? error.message : error));
53790
53785
  }
53791
- if (!existing) {
53786
+ if (!removed) {
53792
53787
  console.log("memory schedule off: no managed job found (already off).");
53793
53788
  return;
53794
53789
  }
53795
- if (existing.state === "running") die("the managed job is currently running; try again after it finishes");
53796
- store.change(existing.id, "remove");
53797
53790
  console.log("memory schedule off: managed job removed.");
53798
53791
  return;
53799
53792
  }
@@ -53826,7 +53819,6 @@ function yesterdayKey() {
53826
53819
  }
53827
53820
 
53828
53821
  // src/commands/session-resume-restart.ts
53829
- init_config();
53830
53822
  import { spawn } from "node:child_process";
53831
53823
  import * as fs6 from "node:fs";
53832
53824
  import * as path6 from "node:path";
@@ -54076,7 +54068,6 @@ async function performResumeRestart(decision, onSpawnFailure) {
54076
54068
 
54077
54069
  // src/commands/sessions.ts
54078
54070
  import fs8 from "node:fs";
54079
- init_config();
54080
54071
 
54081
54072
  // src/session-control.ts
54082
54073
  import fs7 from "fs";
@@ -54968,7 +54959,6 @@ import * as fs9 from "node:fs";
54968
54959
  import * as os2 from "os";
54969
54960
  import * as path8 from "path";
54970
54961
  import { pathToFileURL as pathToFileURL2 } from "node:url";
54971
- init_config();
54972
54962
 
54973
54963
  // src/extensions/types.ts
54974
54964
  function interactiveHostCapabilities() {
@@ -64415,7 +64405,6 @@ function restoreInteractiveSessionState(options) {
64415
64405
  }
64416
64406
 
64417
64407
  // src/keybindings.ts
64418
- init_config();
64419
64408
  import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
64420
64409
  import { join as join7 } from "path";
64421
64410
  var DEFAULT_APP_KEYBINDINGS = {
@@ -65181,7 +65170,6 @@ var TypeCompiler;
65181
65170
  // src/theme/theme.ts
65182
65171
  var import_chalk = __toESM(require_source(), 1);
65183
65172
  var import_cli_highlight = __toESM(require_dist(), 1);
65184
- init_config();
65185
65173
  var ColorValueSchema = Type.Union([
65186
65174
  Type.String(),
65187
65175
  // hex "#ff0000", var ref "primary", or empty ""
@@ -74489,9 +74477,6 @@ async function handleSubagentCommand(host, args) {
74489
74477
  }
74490
74478
  }
74491
74479
 
74492
- // src/commands/interactive-skill-commands.ts
74493
- init_config();
74494
-
74495
74480
  // src/components/extension-input.ts
74496
74481
  var ExtensionInputComponent = class extends Container {
74497
74482
  input;
@@ -79477,7 +79462,7 @@ function setupInteractiveKeybindings(host) {
79477
79462
 
79478
79463
  // src/clipboard/read-clipboard-image.ts
79479
79464
  import { spawn as spawn4 } from "node:child_process";
79480
- import { chmodSync, closeSync as closeSync2, existsSync as existsSync16, fchmodSync, mkdtempSync, openSync as openSync2, readFileSync as readFileSync17, rmdirSync, statSync as statSync12, unlinkSync as unlinkSync5, writeFileSync as writeFileSync10 } from "node:fs";
79465
+ import { chmodSync, closeSync as closeSync2, existsSync as existsSync16, fchmodSync, mkdtempSync, openSync as openSync2, readFileSync as readFileSync17, rmdirSync, statSync as statSync12, unlinkSync as unlinkSync5, writeFileSync as writeFileSync9 } from "node:fs";
79481
79466
  import { tmpdir } from "node:os";
79482
79467
  import { join as join19 } from "node:path";
79483
79468
  var MAX_IMAGE_BYTES = 50 * 1024 * 1024;
@@ -79786,7 +79771,7 @@ function writeImageBytes(bytes, declaredMime, mkTempPath) {
79786
79771
  const mimeType = detectMimeFromMagic(bytes) ?? declaredMime;
79787
79772
  const targetPath = mkTempPath(extensionForMime(mimeType));
79788
79773
  try {
79789
- writeFileSync10(targetPath, bytes, { flag: "r+", mode: 384 });
79774
+ writeFileSync9(targetPath, bytes, { flag: "r+", mode: 384 });
79790
79775
  } catch (err) {
79791
79776
  return { ok: false, kind: "failed", message: `Failed to write temp image: ${errorMessage4(err)}` };
79792
79777
  }
@@ -79857,7 +79842,7 @@ function formatBytes2(bytes) {
79857
79842
  }
79858
79843
 
79859
79844
  // src/input/image-paste.ts
79860
- import { mkdtempSync as mkdtempSync2, writeFileSync as writeFileSync11, rmSync as rmSync4 } from "node:fs";
79845
+ import { mkdtempSync as mkdtempSync2, writeFileSync as writeFileSync10, rmSync as rmSync3 } from "node:fs";
79861
79846
  import { tmpdir as tmpdir2 } from "node:os";
79862
79847
  import { join as join20 } from "node:path";
79863
79848
  var pastingHosts = /* @__PURE__ */ new WeakSet();
@@ -79886,14 +79871,14 @@ function terminalResultToClipboardResult(result) {
79886
79871
  try {
79887
79872
  dir = mkdtempSync2(join20(tmpdir2(), "pie-osc5522-"));
79888
79873
  const path35 = join20(dir, formatPastedImageName(/* @__PURE__ */ new Date(), ext));
79889
- writeFileSync11(path35, result.bytes);
79874
+ writeFileSync10(path35, result.bytes);
79890
79875
  return {
79891
79876
  ok: true,
79892
79877
  path: path35,
79893
79878
  mimeType: result.mimeType,
79894
79879
  cleanup: () => {
79895
79880
  try {
79896
- rmSync4(dir, { recursive: true, force: true });
79881
+ rmSync3(dir, { recursive: true, force: true });
79897
79882
  } catch {
79898
79883
  }
79899
79884
  }
@@ -79901,7 +79886,7 @@ function terminalResultToClipboardResult(result) {
79901
79886
  } catch (err) {
79902
79887
  if (dir) {
79903
79888
  try {
79904
- rmSync4(dir, { recursive: true, force: true });
79889
+ rmSync3(dir, { recursive: true, force: true });
79905
79890
  } catch {
79906
79891
  }
79907
79892
  }
@@ -81328,7 +81313,6 @@ function scheduleContinuationTimeout(host) {
81328
81313
  }
81329
81314
 
81330
81315
  // src/runtime/interactive-controller-setup.ts
81331
- init_config();
81332
81316
  async function prepareAgentTurn(host, context) {
81333
81317
  let messages = context.messages;
81334
81318
  if (context.source === "interactive" && context.streamingBehavior && host.tryBuildAttachmentContentFromExtensions) {
@@ -82818,7 +82802,6 @@ async function loadInteractiveExtensions(host) {
82818
82802
 
82819
82803
  // src/extensions/interactive-runtime-reload.ts
82820
82804
  import { AsyncLocalStorage } from "async_hooks";
82821
- init_config();
82822
82805
  import * as os8 from "os";
82823
82806
  import * as path30 from "path";
82824
82807
  var runtimeReloadContext = new AsyncLocalStorage();
@@ -83241,7 +83224,7 @@ var InteractiveMode = class {
83241
83224
  async init() {
83242
83225
  const activeSession = this.sessionManager.getActiveSession();
83243
83226
  this.thinkingLevel = resolveInitialThinkingLevel({ session: activeSession, settingsManager: this.options.settingsManager });
83244
- const { Agent } = await import("./chunks/src-OVWRBWKU.js");
83227
+ const { Agent } = await import("./chunks/src-B44QWSGM.js");
83245
83228
  this.agent = new Agent({
83246
83229
  initialState: {
83247
83230
  systemPrompt: this.buildSystemPrompt(),
@@ -83282,7 +83265,6 @@ var InteractiveMode = class {
83282
83265
  await this.syncSessionScopedState();
83283
83266
  void this.emitExtensionEvent({ type: "agent:start" });
83284
83267
  this.setupAutocomplete();
83285
- this.registerExtensionShortcuts();
83286
83268
  await this.initializeFileManager();
83287
83269
  if (!this.options.sessionModelFallback) this.syncSessionModelMetadata();
83288
83270
  if (!this.hasConfiguredModel()) {
@@ -83326,8 +83308,6 @@ var InteractiveMode = class {
83326
83308
  showHierarchicalMenu(initialPath = []) {
83327
83309
  return showHierarchicalMenu(this.uiHelperHost, initialPath);
83328
83310
  }
83329
- registerExtensionShortcuts() {
83330
- }
83331
83311
  async loadExtensions() {
83332
83312
  this.extensionUIContext = createInteractiveExtensionUIContext(this);
83333
83313
  installInteractiveInteractionHandler(this);
@@ -83500,32 +83480,18 @@ var InteractiveMode = class {
83500
83480
  async loadSession(sessionId) {
83501
83481
  return loadSession(this, sessionId);
83502
83482
  }
83503
- /** 4.4.1 session write ownership: the TUI holds at most one claim (the
83504
- * active resumed session); switching releases the previous one.
83505
- * adoptSessionOwnership transfers a STARTUP composition claim into this
83506
- * same lifecycle (r3-P1) so switch-away/shutdown releases it too. */
83507
- sessionOwnershipHandle;
83508
- adoptedRelease;
83483
+ sessionOwnership = new SessionOwnershipLifecycle();
83509
83484
  adoptSessionOwnership(releaseFn) {
83510
- this.adoptedRelease = releaseFn;
83485
+ this.sessionOwnership.adopt(releaseFn);
83511
83486
  }
83512
83487
  setSessionOwnershipHandle(handle) {
83513
- this.adoptedRelease?.();
83514
- this.adoptedRelease = void 0;
83515
- this.sessionOwnershipHandle = handle;
83488
+ this.sessionOwnership.set(handle);
83516
83489
  }
83517
83490
  releaseSessionOwnership() {
83518
- this.adoptedRelease?.();
83519
- this.adoptedRelease = void 0;
83520
- this.sessionOwnershipHandle?.release();
83521
- this.sessionOwnershipHandle = void 0;
83491
+ this.sessionOwnership.release();
83522
83492
  }
83523
- /** r2-review: /clear creates a fresh active session — claim it under the
83524
- * same single-writer lifecycle. */
83525
83493
  claimSessionOwnershipFor(sessionId) {
83526
- if (!sessionId) return;
83527
- const claim = claimSessionOwnership(sessionId, process.env.PIE_IPC_DISPLAY_NAME || `tui-pid-${process.pid}`);
83528
- if ("handle" in claim) this.sessionOwnershipHandle = claim.handle;
83494
+ this.sessionOwnership.claim(sessionId);
83529
83495
  }
83530
83496
  updateTerminalTitle() {
83531
83497
  return updateTerminalTitle(this);
@@ -83740,15 +83706,10 @@ function applyManagerServiceBootstrapEnv() {
83740
83706
  // src/app/runtime-composition.ts
83741
83707
  import { randomUUID as randomUUID2 } from "crypto";
83742
83708
  import * as path32 from "path";
83743
- init_config();
83744
- var CliMissingApiKeyError = class extends Error {
83745
- constructor(message) {
83746
- super(message);
83747
- this.name = "CliMissingApiKeyError";
83748
- }
83749
- };
83709
+
83710
+ // src/app/initial-session.ts
83750
83711
  var CliSessionResumeError = class extends Error {
83751
- constructor(sessionId, code, message = code === "session_not_found" ? `Session not found: ${sessionId}` : code === "session_busy" ? `Session is owned by another live host: ${sessionId} (close it first, or wait \u2014 a crashed holder's lock goes stale in 20s)` : `Session could not be recovered: ${sessionId}`) {
83712
+ constructor(sessionId, code, message = code === "session_not_found" ? `Session not found: ${sessionId}` : code === "session_busy" ? `Session is owned by another live host: ${sessionId} (close it first; only confirmed process death permits recovery)` : `Session could not be recovered: ${sessionId}`) {
83752
83713
  super(message);
83753
83714
  this.sessionId = sessionId;
83754
83715
  this.code = code;
@@ -83758,6 +83719,42 @@ var CliSessionResumeError = class extends Error {
83758
83719
  code;
83759
83720
  recoverable = true;
83760
83721
  };
83722
+ async function createInitialSession(sessionManager) {
83723
+ await sessionManager.createSession();
83724
+ const sessionId = sessionManager.getActiveSessionId();
83725
+ if (!sessionId) return void 0;
83726
+ const claim = claimSessionOwnership(sessionId, process.env.PIE_IPC_DISPLAY_NAME || `pid-${process.pid}`);
83727
+ if ("holder" in claim) throw new CliSessionResumeError(sessionId, "session_busy");
83728
+ return claim.handle;
83729
+ }
83730
+ async function loadInitialExplicitSession(sessionManager, sessionId, options) {
83731
+ const sessionFileExists = options.requireExistingSession ? await sessionManager.hasSession(sessionId) : false;
83732
+ const claim = claimSessionOwnership(sessionId, process.env.PIE_IPC_DISPLAY_NAME || `pid-${process.pid}`);
83733
+ if ("holder" in claim) throw new CliSessionResumeError(sessionId, "session_busy");
83734
+ try {
83735
+ const loaded = await sessionManager.loadSession(sessionId, {
83736
+ warnIfMissing: options.warnIfExplicitSessionMissing
83737
+ });
83738
+ if (!loaded) {
83739
+ if (options.requireExistingSession) {
83740
+ throw new CliSessionResumeError(sessionId, sessionFileExists ? "session_unrecoverable" : "session_not_found");
83741
+ }
83742
+ await sessionManager.createSession(void 0, void 0, sessionId);
83743
+ }
83744
+ return { handle: claim.handle, createdNewSession: !loaded };
83745
+ } catch (error) {
83746
+ claim.handle.release();
83747
+ throw error;
83748
+ }
83749
+ }
83750
+
83751
+ // src/app/runtime-composition.ts
83752
+ var CliMissingApiKeyError = class extends Error {
83753
+ constructor(message) {
83754
+ super(message);
83755
+ this.name = "CliMissingApiKeyError";
83756
+ }
83757
+ };
83761
83758
  function getCliRuntimePaths() {
83762
83759
  const configDir = getConfigDir();
83763
83760
  const sessionsDir = getSessionsDir();
@@ -83833,28 +83830,8 @@ async function composeCliRuntime(params) {
83833
83830
  if (params.explicitSessionId) {
83834
83831
  const ref = settingsManager.getManagerScopedModelRef();
83835
83832
  const managerScopedSelection = !!ref && !!model && model.id === ref.modelId && normalizeProviderName(model.provider) === normalizeProviderName(ref.provider);
83836
- const sessionFileExists = params.requireExistingSession ? await sessionManager.hasSession(params.explicitSessionId) : false;
83837
- const claim = claimSessionOwnership(params.explicitSessionId, process.env.PIE_IPC_DISPLAY_NAME || `pid-${process.pid}`);
83838
- if ("holder" in claim) {
83839
- if (params.requireExistingSession) {
83840
- throw new CliSessionResumeError(params.explicitSessionId, "session_busy");
83841
- }
83842
- throw new CliSessionResumeError(params.explicitSessionId, "session_busy");
83843
- }
83844
- const loaded = await sessionManager.loadSession(params.explicitSessionId, {
83845
- warnIfMissing: params.warnIfExplicitSessionMissing
83846
- });
83847
- if (!loaded) {
83848
- if (params.requireExistingSession) {
83849
- claim.handle.release();
83850
- throw new CliSessionResumeError(
83851
- params.explicitSessionId,
83852
- sessionFileExists ? "session_unrecoverable" : "session_not_found"
83853
- );
83854
- }
83855
- await sessionManager.createSession(void 0, void 0, params.explicitSessionId);
83856
- createdNewSession = true;
83857
- }
83833
+ const claim = await loadInitialExplicitSession(sessionManager, params.explicitSessionId, params);
83834
+ createdNewSession = claim.createdNewSession;
83858
83835
  {
83859
83836
  sessionOwnership = claim.handle;
83860
83837
  const restored = restoreSessionModelState({
@@ -83876,13 +83853,8 @@ async function composeCliRuntime(params) {
83876
83853
  }
83877
83854
  }
83878
83855
  } else {
83879
- await sessionManager.createSession();
83856
+ sessionOwnership = await createInitialSession(sessionManager);
83880
83857
  createdNewSession = true;
83881
- const created = sessionManager.getActiveSessionId();
83882
- if (created) {
83883
- const claimNew = claimSessionOwnership(created, process.env.PIE_IPC_DISPLAY_NAME || `pid-${process.pid}`);
83884
- if ("handle" in claimNew) sessionOwnership = claimNew.handle;
83885
- }
83886
83858
  }
83887
83859
  const activeSession = sessionManager.getActiveSession();
83888
83860
  syncSessionModelMetadata(sessionManager, model, resolveInitialThinkingLevel({ session: activeSession, settingsManager }), { isFallback: restoredViaFallback });
@@ -84093,7 +84065,7 @@ function createPrintModeCompactionHandler(params) {
84093
84065
  };
84094
84066
  }
84095
84067
 
84096
- // src/app/print-mode.ts
84068
+ // src/app/print-mode-extensions.ts
84097
84069
  function createNoOpExtensionUIContext() {
84098
84070
  return {
84099
84071
  notify: () => {
@@ -84105,9 +84077,6 @@ function createNoOpExtensionUIContext() {
84105
84077
  custom: async () => void 0
84106
84078
  };
84107
84079
  }
84108
- function readAssistantError(message) {
84109
- return message.role === "assistant" ? message.errorMessage || "assistant response failed" : "";
84110
- }
84111
84080
  async function loadPrintModeExtensions(params) {
84112
84081
  const uiContext = createNoOpExtensionUIContext();
84113
84082
  const executionState = new ExecutionStateManager();
@@ -84209,8 +84178,48 @@ async function loadPrintModeExtensions(params) {
84209
84178
  extensionTools
84210
84179
  };
84211
84180
  }
84181
+
84182
+ // src/app/print-mode.ts
84183
+ function readAssistantError(message) {
84184
+ return message.role === "assistant" ? message.errorMessage || "assistant response failed" : "";
84185
+ }
84212
84186
  async function runPrintMode(params) {
84213
84187
  const { runtime } = params;
84188
+ const turnTimeoutMs = Number(process.env.PIE_PRINT_TURN_TIMEOUT_MS);
84189
+ const watchdogArmed = Number.isFinite(turnTimeoutMs) && turnTimeoutMs > 0 && turnTimeoutMs <= 2147483647;
84190
+ const deadline = watchdogArmed ? Date.now() + turnTimeoutMs : Number.POSITIVE_INFINITY;
84191
+ let turnTimer;
84192
+ let hardTimer;
84193
+ let abortAgent;
84194
+ const disarmWatchdog = () => {
84195
+ if (turnTimer) clearTimeout(turnTimer);
84196
+ if (hardTimer) clearTimeout(hardTimer);
84197
+ turnTimer = void 0;
84198
+ hardTimer = void 0;
84199
+ };
84200
+ const fireHardExit = () => {
84201
+ console.error(`Error: print-mode turn watchdog hard exit (${Math.round(turnTimeoutMs / 1e3)}s deadline + grace elapsed).`);
84202
+ process.exit(1);
84203
+ };
84204
+ const fireWatchdog = () => {
84205
+ if (abortAgent) {
84206
+ console.error(`Error: print-mode turn watchdog fired after ${Math.round(turnTimeoutMs / 1e3)}s; aborting.`);
84207
+ try {
84208
+ abortAgent();
84209
+ } catch {
84210
+ }
84211
+ hardTimer = setTimeout(fireHardExit, 15e3);
84212
+ hardTimer.unref?.();
84213
+ } else {
84214
+ fireHardExit();
84215
+ }
84216
+ };
84217
+ const armWatchdog = () => {
84218
+ if (!watchdogArmed || turnTimer) return;
84219
+ turnTimer = setTimeout(fireWatchdog, Math.max(0, deadline - Date.now()));
84220
+ turnTimer.unref?.();
84221
+ };
84222
+ armWatchdog();
84214
84223
  if (runtime.initialModel.unconfigured) {
84215
84224
  const errorText = runtime.initialModel.warning || "No models are configured. Add one in ~/.pie/models.json before sending messages.";
84216
84225
  if (params.jsonOutput) {
@@ -84226,7 +84235,7 @@ async function runPrintMode(params) {
84226
84235
  `);
84227
84236
  console.log("Assistant: ");
84228
84237
  }
84229
- const { Agent: AgentClass } = await import("./chunks/src-OVWRBWKU.js");
84238
+ const { Agent: AgentClass } = await import("./chunks/src-B44QWSGM.js");
84230
84239
  let agent;
84231
84240
  const printModeExtensions = await loadPrintModeExtensions({
84232
84241
  cwd: runtime.cwd,
@@ -84346,6 +84355,8 @@ async function runPrintMode(params) {
84346
84355
  attachAgentEventsToSessionTrace({ agent, trace: sessionTrace });
84347
84356
  agent.setTools(wrapToolsWithExtensions(agent.state.tools, printModeExtensions.runner));
84348
84357
  agentSessionController.updateRuntimeContext({ tools: agent.state.tools });
84358
+ abortAgent = () => agent.abort();
84359
+ sessionTrace.noteRuntimeEvent("turn_watchdog_armed", { timeoutMs: turnTimeoutMs });
84349
84360
  try {
84350
84361
  sessionTrace.noteDispatchStart({ mode: "print" });
84351
84362
  await agentSessionController.prompt(params.initialPrompt, { source: "print" });
@@ -84410,6 +84421,7 @@ async function runPrintMode(params) {
84410
84421
  );
84411
84422
  }
84412
84423
  console.error("Error:", errorMessage5);
84424
+ if (turnTimer) sessionTrace.noteRuntimeEvent("turn_watchdog_cleared_by_throw", {});
84413
84425
  }
84414
84426
  try {
84415
84427
  if (!params.rawOutput && !params.jsonOutput) console.log("");
@@ -84423,12 +84435,49 @@ async function runPrintMode(params) {
84423
84435
  });
84424
84436
  cleanupBashOutputArtifacts();
84425
84437
  }
84438
+ disarmWatchdog();
84426
84439
  }
84427
84440
 
84428
84441
  // src/app/json-events-mode.ts
84429
84442
  import readline from "node:readline";
84430
84443
  import * as fs29 from "node:fs";
84431
- init_config();
84444
+
84445
+ // src/app/jsonl-writer.ts
84446
+ function createJsonlWriter(io) {
84447
+ let asyncOnly = false;
84448
+ let broken = false;
84449
+ return (line) => {
84450
+ if (broken) return;
84451
+ const buffer = Buffer.from(line, "utf8");
84452
+ const enqueue = (offset2) => {
84453
+ asyncOnly = true;
84454
+ try {
84455
+ io.writeAsync(buffer.subarray(offset2));
84456
+ } catch {
84457
+ broken = true;
84458
+ }
84459
+ };
84460
+ if (asyncOnly || io.isTTY()) {
84461
+ enqueue(0);
84462
+ return;
84463
+ }
84464
+ let offset = 0;
84465
+ while (offset < buffer.length) {
84466
+ try {
84467
+ const written = io.writeSync(buffer, offset);
84468
+ if (written <= 0) {
84469
+ enqueue(offset);
84470
+ return;
84471
+ }
84472
+ offset += written;
84473
+ } catch (error) {
84474
+ if (error.code === "EAGAIN") enqueue(offset);
84475
+ else broken = true;
84476
+ return;
84477
+ }
84478
+ }
84479
+ };
84480
+ }
84432
84481
 
84433
84482
  // src/app/host-idle.ts
84434
84483
  var PENDING_RECOVERY = /* @__PURE__ */ new Set([
@@ -84474,6 +84523,11 @@ process.stdout.on("error", (error) => {
84474
84523
  if (error.code === "EPIPE") return;
84475
84524
  throw error;
84476
84525
  });
84526
+ var writeJsonl = createJsonlWriter({
84527
+ isTTY: () => !!process.stdout.isTTY,
84528
+ writeSync: (buffer, offset) => fs29.writeSync(1, buffer, offset, buffer.length - offset),
84529
+ writeAsync: (buffer) => process.stdout.write(buffer)
84530
+ });
84477
84531
  function writeEvent(event) {
84478
84532
  const line = `${JSON.stringify(event)}
84479
84533
  `;
@@ -84481,24 +84535,7 @@ function writeEvent(event) {
84481
84535
  eventSinkOverride(line);
84482
84536
  return;
84483
84537
  }
84484
- if (process.stdout.isTTY) {
84485
- process.stdout.write(line);
84486
- return;
84487
- }
84488
- const buffer = Buffer.from(line, "utf8");
84489
- let offset = 0;
84490
- while (offset < buffer.length) {
84491
- try {
84492
- offset += fs29.writeSync(1, buffer, offset, buffer.length - offset);
84493
- } catch (error) {
84494
- const code = error?.code;
84495
- if (code === "EAGAIN") {
84496
- process.stdout.write(buffer.subarray(offset));
84497
- return;
84498
- }
84499
- return;
84500
- }
84501
- }
84538
+ writeJsonl(line);
84502
84539
  }
84503
84540
  var eventSinkOverride;
84504
84541
  function toJsonValue(value, depth = 0, cap = MAX_EVENT_STRING_LENGTH) {
@@ -85492,7 +85529,7 @@ async function runJsonEventsMode(params) {
85492
85529
  const sideTrace = trace;
85493
85530
  const sideApiKey = runtime.apiKey;
85494
85531
  const snapshot = structuredClone(parent.state.messages);
85495
- const { Agent: AgentClass } = await import("./chunks/src-OVWRBWKU.js");
85532
+ const { Agent: AgentClass } = await import("./chunks/src-B44QWSGM.js");
85496
85533
  const sideAgent = new AgentClass({
85497
85534
  initialState: {
85498
85535
  systemPrompt: parent.state.systemPrompt,
@@ -86082,7 +86119,7 @@ async function runJsonEventsMode(params) {
86082
86119
  }
86083
86120
  return;
86084
86121
  }
86085
- const { Agent: AgentClass } = await import("./chunks/src-OVWRBWKU.js");
86122
+ const { Agent: AgentClass } = await import("./chunks/src-B44QWSGM.js");
86086
86123
  if (runtimeClosing) return;
86087
86124
  const compositionRegistry = createCliHostEnvelopeRegistry();
86088
86125
  const jsonModeExtensions = await loadJsonModeExtensions({
@@ -87029,7 +87066,7 @@ async function runWithJsonEventsConsoleIsolation(fn) {
87029
87066
  }
87030
87067
  async function createCliTestStreamFnFromEnv() {
87031
87068
  if (!process.env.PIE_TEST_MOCK_STREAM_SEQUENCE) return void 0;
87032
- return (await import("./chunks/test-stream-7YZDGBPO.js")).createTestStreamFnFromSequenceEnv();
87069
+ return (await import("./chunks/test-stream-OR3EJBNF.js")).createTestStreamFnFromSequenceEnv();
87033
87070
  }
87034
87071
  function resolveJsonEventsDetailFlag() {
87035
87072
  for (let index = 0; index < process.argv.length; index += 1) {
@@ -87226,7 +87263,7 @@ async function main() {
87226
87263
  return;
87227
87264
  }
87228
87265
  if (args[0] === STABLE_CLI_COMMANDS.manager) {
87229
- const { runManagerCommand } = await import("./chunks/manager-cli-BYCF4RKN.js");
87266
+ const { runManagerCommand } = await import("./chunks/manager-cli-2ATPC47M.js");
87230
87267
  try {
87231
87268
  await runManagerCommand(args.slice(1));
87232
87269
  } catch (error) {