@codex-infinity/pi-infinity 0.60.1 → 0.60.2

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 (36) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/core/agent-session.d.ts +14 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +57 -3
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/exec.d.ts.map +1 -1
  7. package/dist/core/exec.js +7 -3
  8. package/dist/core/exec.js.map +1 -1
  9. package/dist/core/slash-commands.d.ts.map +1 -1
  10. package/dist/core/slash-commands.js +2 -1
  11. package/dist/core/slash-commands.js.map +1 -1
  12. package/dist/core/tools/bash.d.ts.map +1 -1
  13. package/dist/core/tools/bash.js +12 -10
  14. package/dist/core/tools/bash.js.map +1 -1
  15. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  16. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  17. package/dist/modes/interactive/interactive-mode.js +55 -5
  18. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  19. package/dist/utils/child-process.d.ts +11 -0
  20. package/dist/utils/child-process.d.ts.map +1 -0
  21. package/dist/utils/child-process.js +78 -0
  22. package/dist/utils/child-process.js.map +1 -0
  23. package/dist/utils/clipboard-native.d.ts +1 -0
  24. package/dist/utils/clipboard-native.d.ts.map +1 -1
  25. package/dist/utils/clipboard-native.js.map +1 -1
  26. package/dist/utils/clipboard.d.ts +1 -1
  27. package/dist/utils/clipboard.d.ts.map +1 -1
  28. package/dist/utils/clipboard.js +11 -1
  29. package/dist/utils/clipboard.js.map +1 -1
  30. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  31. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  32. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  33. package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
  34. package/examples/extensions/with-deps/package-lock.json +2 -2
  35. package/examples/extensions/with-deps/package.json +1 -1
  36. package/package.json +4 -4
@@ -12,8 +12,8 @@
12
12
  *
13
13
  * Modes use this class and add their own I/O layer on top.
14
14
  */
15
- import { readFileSync } from "node:fs";
16
- import { basename, dirname, join } from "node:path";
15
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
16
+ import { basename, dirname, join, resolve } from "node:path";
17
17
  import { isContextOverflow, modelsAreEqual, resetApiProviders, supportsXhigh } from "@mariozechner/pi-ai";
18
18
  import { getDocsPath } from "../config.js";
19
19
  import { theme } from "../modes/interactive/theme/theme.js";
@@ -26,7 +26,7 @@ import { exportSessionToHtml } from "./export-html/index.js";
26
26
  import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
27
27
  import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
28
28
  import { expandPromptTemplate } from "./prompt-templates.js";
29
- import { getLatestCompactionEntry } from "./session-manager.js";
29
+ import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
30
30
  import { BUILTIN_SLASH_COMMANDS } from "./slash-commands.js";
31
31
  import { buildSystemPrompt } from "./system-prompt.js";
32
32
  import { createAllTools } from "./tools/index.js";
@@ -2558,6 +2558,60 @@ export class AgentSession {
2558
2558
  toolRenderer,
2559
2559
  });
2560
2560
  }
2561
+ /**
2562
+ * Export the current session branch to a JSONL file.
2563
+ * Writes the session header followed by all entries on the current branch path.
2564
+ * @param outputPath Target file path. If omitted, generates a timestamped file in cwd.
2565
+ * @returns The resolved output file path.
2566
+ */
2567
+ exportToJsonl(outputPath) {
2568
+ const filePath = resolve(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`);
2569
+ const dir = dirname(filePath);
2570
+ if (!existsSync(dir)) {
2571
+ mkdirSync(dir, { recursive: true });
2572
+ }
2573
+ const header = {
2574
+ type: "session",
2575
+ version: CURRENT_SESSION_VERSION,
2576
+ id: this.sessionManager.getSessionId(),
2577
+ timestamp: new Date().toISOString(),
2578
+ cwd: this.sessionManager.getCwd(),
2579
+ };
2580
+ const branchEntries = this.sessionManager.getBranch();
2581
+ const lines = [JSON.stringify(header)];
2582
+ // Re-chain parentIds to form a linear sequence
2583
+ let prevId = null;
2584
+ for (const entry of branchEntries) {
2585
+ const linear = { ...entry, parentId: prevId };
2586
+ lines.push(JSON.stringify(linear));
2587
+ prevId = entry.id;
2588
+ }
2589
+ writeFileSync(filePath, `${lines.join("\n")}\n`);
2590
+ return filePath;
2591
+ }
2592
+ /**
2593
+ * Import a JSONL session file.
2594
+ * Copies the file into the session directory and switches to it (like /resume).
2595
+ * @param inputPath Path to the JSONL file to import.
2596
+ * @returns true if the session was switched successfully.
2597
+ */
2598
+ async importFromJsonl(inputPath) {
2599
+ const resolved = resolve(inputPath);
2600
+ if (!existsSync(resolved)) {
2601
+ throw new Error(`File not found: ${resolved}`);
2602
+ }
2603
+ // Copy into the session directory so we don't modify the original
2604
+ const sessionDir = this.sessionManager.getSessionDir();
2605
+ if (!existsSync(sessionDir)) {
2606
+ mkdirSync(sessionDir, { recursive: true });
2607
+ }
2608
+ const destPath = join(sessionDir, basename(resolved));
2609
+ // Avoid overwriting if source and destination are the same file
2610
+ if (resolve(destPath) !== resolved) {
2611
+ copyFileSync(resolved, destPath);
2612
+ }
2613
+ return this.switchSession(destPath);
2614
+ }
2561
2615
  // =========================================================================
2562
2616
  // Utilities
2563
2617
  // =========================================================================