surgent 0.7.0-alpha.3 → 0.7.1-alpha.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.
package/README.md CHANGED
@@ -76,7 +76,7 @@ npm uninstall -g surgent # remove
76
76
 
77
77
  ## Optimizer package
78
78
 
79
- surgent includes [`pi-context-optimizer`](https://www.npmjs.com/package/pi-context-optimizer), a standalone Pi extension for structural code navigation and automatic context cleanup. Install it separately when using Pi without surgent; package page covers features and setup.
79
+ surgent includes [`pi-optimizer`](https://www.npmjs.com/package/pi-optimizer), a standalone Pi extension for structural code navigation and automatic context cleanup. Install it separately when using Pi without surgent; package page covers features and setup.
80
80
 
81
81
  ## Connect a model
82
82
 
@@ -1,4 +1,4 @@
1
- # pi-context-optimizer
1
+ # pi-optimizer
2
2
 
3
3
  Context optimization extension for [Pi](https://github.com/earendil-works/pi). It gives coding agents more useful context by improving code navigation and reducing repeated or noisy tool output. It is also built into [surgent](https://github.com/thien2218/surgent).
4
4
 
@@ -6,7 +6,7 @@ Context optimization extension for [Pi](https://github.com/earendil-works/pi). I
6
6
 
7
7
  Long coding sessions accumulate large tool results, repeated file content, and output that no longer helps with current task. That context costs tokens and can distract model from relevant code.
8
8
 
9
- `pi-context-optimizer` keeps useful evidence while removing avoidable noise. It works automatically after installation and adds structural tools for reading only code needed for current task.
9
+ `pi-optimizer` keeps useful evidence while removing avoidable noise. It works automatically after installation and adds structural tools for reading only code needed for current task.
10
10
 
11
11
  ## What it does
12
12
 
@@ -30,7 +30,7 @@ These changes reduce context growth, improve prompt-cache reuse, and leave more
30
30
  Install package through Pi:
31
31
 
32
32
  ```bash
33
- pi install npm:pi-context-optimizer
33
+ pi install npm:pi-optimizer
34
34
  ```
35
35
 
36
36
  Confirm installation:
@@ -423,13 +423,12 @@ import { statSync } from "node:fs";
423
423
  import {
424
424
  createBashToolDefinition,
425
425
  createGrepToolDefinition,
426
+ createLocalBashOperations,
426
427
  isGrepToolResult
427
428
  } from "@earendil-works/pi-coding-agent";
428
429
 
429
430
  // src/optimizer/compactor/bash.ts
430
431
  import { stripVTControlCharacters } from "node:util";
431
- import { createLocalBashOperations } from "@earendil-works/pi-coding-agent";
432
- var localBash = createLocalBashOperations();
433
432
  var MIN_SIMILAR_LENGTH = 10;
434
433
  var SIMILARITY_THRESHOLD = 0.8;
435
434
  function isSimilarLine(previousLine, nextLine) {
@@ -545,21 +544,6 @@ var BashResultCompactor = class {
545
544
  this.hasPendingLine = false;
546
545
  }
547
546
  };
548
- function createCompactingBashOperations(filter) {
549
- return {
550
- async exec(command, cwd, options) {
551
- const compactor = new BashResultCompactor(options.onData);
552
- try {
553
- return await localBash.exec(command, cwd, {
554
- ...options,
555
- onData: (data) => compactor.append(data)
556
- });
557
- } finally {
558
- compactor.finish();
559
- }
560
- }
561
- };
562
- }
563
547
 
564
548
  // src/optimizer/compactor/grep.ts
565
549
  import {
@@ -604,7 +588,7 @@ function extractGrepSummary(contentText) {
604
588
  ${notice}` : "");
605
589
  }
606
590
  function rewriteTailWithSummaries(sessionFile, offset, summaries) {
607
- if (summaries.size === 0) return;
591
+ if (summaries.size === 0 || !existsSync2(sessionFile)) return;
608
592
  const sessionBuffer = readFileSync2(sessionFile);
609
593
  if (offset > sessionBuffer.length) return;
610
594
  const prefixBuffer = sessionBuffer.subarray(0, offset);
@@ -673,12 +657,25 @@ function formatGrepResult(content) {
673
657
 
674
658
  // src/optimizer/compactor/index.ts
675
659
  import Type from "typebox";
660
+ var localBash = createLocalBashOperations();
676
661
  function compactor_default(pi) {
677
662
  let writeStartOffset = 0;
678
663
  const store = /* @__PURE__ */ new Map();
679
664
  const grepTool = createGrepToolDefinition(process.cwd());
680
665
  const bashTool = createBashToolDefinition(process.cwd(), {
681
- operations: createCompactingBashOperations()
666
+ operations: {
667
+ async exec(command, cwd, options) {
668
+ const compactor = new BashResultCompactor(options.onData);
669
+ try {
670
+ return await localBash.exec(command, cwd, {
671
+ ...options,
672
+ onData: (data) => compactor.append(data)
673
+ });
674
+ } finally {
675
+ compactor.finish();
676
+ }
677
+ }
678
+ }
682
679
  });
683
680
  pi.registerTool({
684
681
  ...grepTool,
@@ -783,7 +780,7 @@ import { Type as Type2 } from "typebox";
783
780
  import picomatch from "picomatch";
784
781
  var SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set([".git", ".pi", "build", "coverage", "dist", "node_modules"]);
785
782
  function normalizePath(pathValue) {
786
- const normalizedPath = pathValue.replaceAll("\\", "/");
783
+ const normalizedPath = pathValue.replaceAll("\\", "/").replace(/\/+$/, "");
787
784
  return normalizedPath.startsWith("./") ? normalizedPath.slice(2) : normalizedPath;
788
785
  }
789
786
  async function rgFiles(projectPath, globTargets, signal) {