agent-sh 0.12.4 → 0.12.6

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.
@@ -1,6 +1,7 @@
1
1
  import * as fs from "node:fs/promises";
2
2
  import * as path from "node:path";
3
3
  import { computeEditDiff } from "../../utils/diff.js";
4
+ import { expandHome } from "./expand-home.js";
4
5
  /**
5
6
  * Find the closest matching region in the file content to help diagnose
6
7
  * why an exact match failed. Returns a hint string.
@@ -75,7 +76,7 @@ export function createEditFileTool(getCwd) {
75
76
  return m ? { summary: m[1] } : {};
76
77
  },
77
78
  async execute(args, onChunk) {
78
- const filePath = args.path;
79
+ const filePath = expandHome(args.path);
79
80
  const oldText = args.old_text;
80
81
  const newText = args.new_text;
81
82
  const replaceAll = args.replace_all ?? false;
@@ -0,0 +1 @@
1
+ export declare function expandHome(p: string): string;
@@ -0,0 +1,8 @@
1
+ import * as os from "node:os";
2
+ export function expandHome(p) {
3
+ if (p === "~")
4
+ return os.homedir();
5
+ if (p.startsWith("~/"))
6
+ return os.homedir() + p.slice(1);
7
+ return p;
8
+ }
@@ -1,6 +1,7 @@
1
1
  import * as fs from "node:fs/promises";
2
2
  import * as path from "node:path";
3
3
  import { executeCommand } from "../../executor.js";
4
+ import { expandHome } from "./expand-home.js";
4
5
  export function createGlobTool(getCwd) {
5
6
  return {
6
7
  name: "glob",
@@ -39,7 +40,7 @@ export function createGlobTool(getCwd) {
39
40
  }),
40
41
  async execute(args) {
41
42
  const pattern = args.pattern;
42
- const searchPath = args.path ?? ".";
43
+ const searchPath = expandHome(args.path ?? ".");
43
44
  // Use ripgrep for correct glob matching + .gitignore awareness
44
45
  const shellEsc = (s) => "'" + s.replace(/'/g, "'\\''") + "'";
45
46
  const parts = [
@@ -1,4 +1,5 @@
1
1
  import { executeCommand } from "../../executor.js";
2
+ import { expandHome } from "./expand-home.js";
2
3
  export function createGrepTool(getCwd) {
3
4
  return {
4
5
  name: "grep",
@@ -80,7 +81,7 @@ export function createGrepTool(getCwd) {
80
81
  }),
81
82
  async execute(args) {
82
83
  const pattern = args.pattern;
83
- const searchPath = args.path ?? ".";
84
+ const searchPath = expandHome(args.path ?? ".");
84
85
  const include = args.include;
85
86
  const mode = args.output_mode ?? "files_with_matches";
86
87
  const caseInsensitive = args.case_insensitive;
@@ -1,5 +1,6 @@
1
1
  import * as fs from "node:fs/promises";
2
2
  import * as path from "node:path";
3
+ import { expandHome } from "./expand-home.js";
3
4
  function formatSize(bytes) {
4
5
  if (bytes < 1024)
5
6
  return `${bytes}B`;
@@ -38,7 +39,7 @@ export function createLsTool(getCwd) {
38
39
  return { summary: `${lines.length} entries` };
39
40
  },
40
41
  async execute(args) {
41
- const dirPath = args.path ?? ".";
42
+ const dirPath = expandHome(args.path ?? ".");
42
43
  const absPath = path.resolve(getCwd(), dirPath);
43
44
  try {
44
45
  const entries = await fs.readdir(absPath, {
@@ -1,5 +1,6 @@
1
1
  import * as fs from "node:fs/promises";
2
2
  import * as path from "node:path";
3
+ import { expandHome } from "./expand-home.js";
3
4
  export function createReadFileTool(getCwd, cache) {
4
5
  return {
5
6
  name: "read_file",
@@ -39,7 +40,7 @@ export function createReadFileTool(getCwd, cache) {
39
40
  return { summary: `${lines.length} lines` };
40
41
  },
41
42
  async execute(args) {
42
- const filePath = args.path;
43
+ const filePath = expandHome(args.path);
43
44
  const absPath = path.resolve(getCwd(), filePath);
44
45
  const reqOffset = args.offset ?? 1;
45
46
  const reqLimit = args.limit;
@@ -1,6 +1,7 @@
1
1
  import * as fs from "node:fs/promises";
2
2
  import * as path from "node:path";
3
3
  import { computeDiff } from "../../utils/diff.js";
4
+ import { expandHome } from "./expand-home.js";
4
5
  export function createWriteFileTool(getCwd) {
5
6
  return {
6
7
  name: "write_file",
@@ -35,7 +36,7 @@ export function createWriteFileTool(getCwd) {
35
36
  return m ? { summary: m[1] } : {};
36
37
  },
37
38
  async execute(args, onChunk) {
38
- const filePath = args.path;
39
+ const filePath = expandHome(args.path);
39
40
  const content = args.content;
40
41
  const absPath = path.resolve(getCwd(), filePath);
41
42
  try {
@@ -124,7 +124,10 @@ export class ContextManager {
124
124
  return null;
125
125
  const lastSeq = this.exchanges[this.exchanges.length - 1].id;
126
126
  // Outputs already carry head+tail+spillPath stubs from capture time.
127
- const body = fresh.map((ex) => this.formatExchangeTruncated(ex)).join("\n");
127
+ const parts = fresh.map((ex) => this.formatExchangeTruncated(ex)).filter((s) => s.length > 0);
128
+ if (parts.length === 0)
129
+ return null;
130
+ const body = parts.join("\n");
128
131
  return {
129
132
  text: `<shell-events>\n${body}</shell-events>`,
130
133
  lastSeq,
@@ -171,7 +174,9 @@ export class ContextManager {
171
174
  return s;
172
175
  }
173
176
  case "agent_query":
174
- return `#${ex.id} [you] > ${ex.query}\n`;
177
+ // Suppress: query already appears as the turn's user message.
178
+ // Kept in `exchanges` so search() can find it by id.
179
+ return "";
175
180
  }
176
181
  }
177
182
  formatExchangeFull(ex) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-sh",
3
- "version": "0.12.4",
3
+ "version": "0.12.6",
4
4
  "description": "A shell-first terminal where AI is one keystroke away",
5
5
  "type": "module",
6
6
  "main": "dist/core.js",