@vietor/agent-core 0.7.5 → 0.7.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,6 @@
1
1
  import { formatRipgrepOutput, ripgrepResultSummary, runRipgrepLines } from "../util/ripgrep.js";
2
2
  import { NO_MATCHES } from "../util/constants.js";
3
- import { resolveOptionalPath } from "../util/file.js";
3
+ import { resolveSearchPath } from "../util/file.js";
4
4
  const DESCRIPTION = "List files under a directory, optionally filtered by a glob pattern (e.g. **/*.ts). Skips node_modules and .git.";
5
5
  export const globTool = {
6
6
  name: "Glob",
@@ -15,12 +15,12 @@ export const globTool = {
15
15
  required: [],
16
16
  },
17
17
  async execute(args, ctx) {
18
- const cwd = resolveOptionalPath(args, ctx.cwd);
18
+ const { cwd, target } = resolveSearchPath(args, ctx.cwd);
19
19
  const rgArgs = ["--files"];
20
20
  const pattern = args.pattern;
21
21
  if (pattern)
22
22
  rgArgs.push("-g", pattern);
23
- rgArgs.push(".");
23
+ rgArgs.push(target);
24
24
  const { lines, truncated } = await runRipgrepLines(rgArgs, cwd, ctx.signal);
25
25
  return { content: formatRipgrepOutput(lines, truncated, NO_MATCHES) };
26
26
  },
@@ -1,6 +1,6 @@
1
1
  import { formatRipgrepOutput, ripgrepResultSummary, runRipgrepLines } from "../util/ripgrep.js";
2
2
  import { DEFAULT_GREP_LIMIT, NO_MATCHES } from "../util/constants.js";
3
- import { resolveOptionalPath } from "../util/file.js";
3
+ import { resolveSearchPath } from "../util/file.js";
4
4
  const DESCRIPTION = `Search file contents recursively for a regex pattern (RE2 syntax). Skips node_modules and .git. Returns path:line:content, capped at ${DEFAULT_GREP_LIMIT} lines. For large codebases, use output_mode=files_with_matches first, or narrow with glob/type, or raise head_limit.`;
5
5
  export const grepTool = {
6
6
  name: "Grep",
@@ -10,7 +10,7 @@ export const grepTool = {
10
10
  type: "object",
11
11
  properties: {
12
12
  pattern: { type: "string" },
13
- path: { type: "string", description: "root directory, defaults to cwd" },
13
+ path: { type: "string", description: "file or directory, defaults to cwd" },
14
14
  glob: { type: "string", description: "filter files, e.g. *.ts" },
15
15
  type: { type: "string", description: "file type, e.g. ts, js, py" },
16
16
  output_mode: { type: "string", enum: ["content", "files_with_matches", "count"], description: "defaults to content" },
@@ -25,7 +25,7 @@ export const grepTool = {
25
25
  required: ["pattern"],
26
26
  },
27
27
  async execute(args, ctx) {
28
- const cwd = resolveOptionalPath(args, ctx.cwd);
28
+ const { cwd, target } = resolveSearchPath(args, ctx.cwd);
29
29
  const rgArgs = ["--line-number", "--with-filename", "--no-heading"];
30
30
  if (args.ignore_case)
31
31
  rgArgs.push("-i");
@@ -56,7 +56,7 @@ export const grepTool = {
56
56
  rgArgs.push("-c");
57
57
  else
58
58
  rgArgs.push("-m", String(headLimit));
59
- rgArgs.push("--", args.pattern, ".");
59
+ rgArgs.push("--", args.pattern, target);
60
60
  const { lines, truncated } = await runRipgrepLines(rgArgs, cwd, ctx.signal, headLimit);
61
61
  return { content: formatRipgrepOutput(lines, truncated, NO_MATCHES) };
62
62
  },
@@ -1,5 +1,7 @@
1
1
  import { NOT_EXECUTED_PREFIX } from "../util/constants.js";
2
+ import { summarizeText } from "../util/text.js";
2
3
  import { toolError } from "./types.js";
4
+ const MAX_LABEL_LENGTH = 50;
3
5
  export const SUB_AGENT_GUIDANCE = '- Consider delegating to the SubAgent tool when the task matches an agent type, when you have independent work to run in parallel, or when answering would mean reading across several files — delegate and keep the conclusion, not the file dumps. type: "explore" — read-only search agent for broad fan-out searches (state the search breadth in the task); type: "plan" — software architect producing implementation plans. For a single-fact lookup where you already know the file, symbol, or value, search directly. Once you have delegated a search, do not also run it yourself — wait for the result. Issue at most 2 SubAgent calls per turn; multiple calls in the same turn run concurrently. Sub-agents are read-only and return only their final report, not intermediate steps — verify important results yourself. For large workloads with many independent items that would exceed the turn budget, split the items into chunks sized so each sub-agent can complete its chunk within its own loop budget, delegate one SubAgent per chunk, and run the remaining chunks in the following turns as results return. Instruct each sub-agent to report results per item in structured lines so you can consolidate.';
4
6
  const EXPLORE_PROMPT = [
5
7
  "You are the Explore sub-agent — a read-only search agent for broad fan-out searches. Use it when answering means sweeping many files, directories, or naming conventions and the parent needs only the conclusion, not the file dumps. You read excerpts rather than whole files, so you locate code — you do not review or audit it. You are read-only: you must not modify any files.",
@@ -51,11 +53,21 @@ export function createSubAgentTool(deps) {
51
53
  enum: SUB_AGENT_DEFS.map((d) => d.type),
52
54
  description: 'The sub-agent type to invoke: "explore" (read-only fan-out search) or "plan" (implementation plan).',
53
55
  },
56
+ label: {
57
+ type: "string",
58
+ maxLength: MAX_LABEL_LENGTH,
59
+ description: `Short label (max ${MAX_LABEL_LENGTH} characters) for this sub-agent run, shown in the UI.`,
60
+ },
54
61
  task: { type: "string", description: "The task or question for the sub-agent, as a self-contained description." },
55
62
  },
56
63
  required: ["type", "task"],
57
64
  },
58
- argSummaryKeys: ["type"],
65
+ summarizeArgs: (args) => {
66
+ const type = args.type;
67
+ const label = typeof args.label === "string" ? summarizeText(args.label, MAX_LABEL_LENGTH) : "";
68
+ const def = SUB_AGENT_DEFS.find((d) => d.type === type);
69
+ return (def?.name || type) + (label ? ` ${label}` : "");
70
+ },
59
71
  async execute(args, ctx) {
60
72
  const type = args.type;
61
73
  const task = (args.task ?? "").trim();
@@ -80,7 +92,7 @@ export function createSubAgentTool(deps) {
80
92
  }
81
93
  }
82
94
  const suffix = stallReason ? ` ${stallReason}` : "";
83
- return { content: `Sub-agent "${type}" ended with status ${status}.${suffix}\n\n${reply}`, isError: true };
95
+ return { content: `Sub-agent "${def.name}" ended with status ${status}.${suffix}\n\n${reply}`, isError: true };
84
96
  },
85
97
  };
86
98
  }
@@ -11,7 +11,7 @@ export function isAbortError(e) {
11
11
  return name === "AbortError" || name === "APIUserAbortError";
12
12
  }
13
13
  export function backoffDelay(attempt) {
14
- return 1000 * 2 ** attempt;
14
+ return Math.min(2000 * 2 ** attempt, 60_000);
15
15
  }
16
16
  export async function withRetry(fn, opts) {
17
17
  for (let attempt = 0;; attempt++) {
@@ -1,3 +1,6 @@
1
1
  export declare function tryReadFileText(path: string): string | undefined;
2
2
  export declare function resolveRequiredPath(args: Record<string, unknown>, cwd: string): string;
3
- export declare function resolveOptionalPath(args: Record<string, unknown>, cwd: string): string;
3
+ export declare function resolveSearchPath(args: Record<string, unknown>, cwd: string): {
4
+ cwd: string;
5
+ target: string;
6
+ };
package/dist/util/file.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync } from "node:fs";
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  export function tryReadFileText(path) {
4
4
  if (existsSync(path)) {
@@ -14,6 +14,10 @@ export function resolveRequiredPath(args, cwd) {
14
14
  throw new Error("path is required");
15
15
  return resolve(cwd, path);
16
16
  }
17
- export function resolveOptionalPath(args, cwd) {
18
- return resolve(cwd, args.path || "");
17
+ export function resolveSearchPath(args, cwd) {
18
+ const path = resolve(cwd, args.path || "");
19
+ if (existsSync(path) && !statSync(path).isDirectory()) {
20
+ return { cwd, target: path };
21
+ }
22
+ return { cwd: path, target: "." };
19
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vietor/agent-core",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",