@runappsai/agent 0.1.5 → 0.1.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.
package/dist/chat.js CHANGED
@@ -783,6 +783,7 @@ function parseAttachLine(line) {
783
783
  const typedOf = (m) => m?.typed;
784
784
  /** Added to the agent's instructions when it has a directory: how to hand a file to the user. */
785
785
  const linksHint = (uploads) => `When you create or change a file for the user, name its absolute path in backticks (for example \`/index.html\`); in the chat that path becomes a link that opens the file. Files the user attaches arrive under ${uploads}.`;
786
+ const attachHint = (uploads) => `Files the user attaches arrive under ${uploads}.`;
786
787
  const filesHint = (uploads) => `The user can browse, edit and download every file of the directory from the chat's Files panel. When you create or change a file for the user, name its absolute path in backticks (for example \`${uploads}/report.csv\`); in the chat that path becomes a link that opens the file, with a download button. Files the user attaches arrive under ${uploads}.`;
787
788
  /** Text when the type or extension says so, or when the first 8 KB hold no NUL byte and decode as UTF-8. */
788
789
  function decodeText(file, bytes) {
@@ -4083,8 +4084,11 @@ export function renderChat(target, opts) {
4083
4084
  const workspace = typeof wsOpt === "function" ? await wsOpt(sid) : wsOpt ?? null;
4084
4085
  // The host's instructions may be a function (re-read every turn): the hint joins whatever it returns.
4085
4086
  const base = agentOpts.instructions;
4086
- const hint = filesOpt === false ? linksHint(uploadsDir) : filesHint(uploadsDir);
4087
- const instructions = !workspace ? base : typeof base === "function" ? () => [base(), hint].filter(Boolean).join("\n\n") : [base, hint].filter(Boolean).join("\n\n");
4087
+ // Only about what the model can do: no file tools, nothing about files (attachments then go into the message); read-only, only where attachments land.
4088
+ const fileOpt = agentOpts.fileTools;
4089
+ const writes = fileOpt === undefined || fileOpt === true || (Array.isArray(fileOpt) && (fileOpt.includes("write_file") || fileOpt.includes("edit_file")));
4090
+ const hint = fileOpt === false ? "" : !writes ? attachHint(uploadsDir) : filesOpt === false ? linksHint(uploadsDir) : filesHint(uploadsDir);
4091
+ const instructions = !workspace || !hint ? base : typeof base === "function" ? () => [base(), hint].filter(Boolean).join("\n\n") : [base, hint].filter(Boolean).join("\n\n");
4088
4092
  const over = {};
4089
4093
  if (userSettings.model)
4090
4094
  over.model = userSettings.model;
package/dist/context.js CHANGED
@@ -25,16 +25,25 @@ export function buildSystemPrompt(input) {
25
25
  rules.push("For arithmetic, dates, counting, parsing or any other computation, run run_js instead of working it out in your head, and report the computed result.");
26
26
  }
27
27
  out.push("# How to work\n" + rules.map((r) => `- ${r}`).join("\n"));
28
+ // Only what the model can really call: a tool it does not have costs a failed turn.
29
+ const has = (name) => input.tools.some((t) => t.name === name);
28
30
  if (input.workspaceDescription) {
31
+ const look = ["list_files", "read_file"].filter(has);
32
+ const uses = [
33
+ look.length ? `${look.join(" and ")} to look around` : "",
34
+ has("edit_file") ? "edit_file for small changes (each oldText must match exactly once)" : "",
35
+ has("write_file") ? "write_file for new files or rewrites" : "",
36
+ ].filter(Boolean);
29
37
  out.push("# Workspace\nYou have a file tree (absolute POSIX paths).\n" + input.workspaceDescription +
30
- "\nUse list_files and read_file to look around, edit_file for small changes (each oldText must match exactly once), write_file for new files or rewrites. A reply has an output limit: a file longer than you can emit in one call is written in parts — write_file the first part, then edit_file to append the rest (oldText = the last lines written) — never one huge write_file." +
38
+ (uses.length ? `\nUse ${uses.join(", ")}.` : "") +
39
+ (has("write_file") && has("edit_file") ? " A reply has an output limit: a file longer than you can emit in one call is written in parts — write_file the first part, then edit_file to append the rest (oldText = the last lines written) — never one huge write_file." : "") +
31
40
  (input.canWrite && input.memoryPath ? `\nTo remember something for later conversations (a preference, a decision, a fact about the user's project), append a short line to ${input.memoryPath}; it is shown to you at the start of every conversation.` : ""));
32
41
  }
33
42
  if (input.memory?.trim()) {
34
43
  out.push(`# Memory\nYour notes from earlier conversations (${input.memoryPath ?? "/memory/notes.md"}):\n` + input.memory.trim());
35
44
  }
36
45
  const visible = input.skills.filter((s) => !s.disableModelInvocation);
37
- if (visible.length) {
46
+ if (visible.length && has("read_file")) {
38
47
  const esc = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
39
48
  out.push("# Skills\nThe following skills provide specialized instructions for specific tasks.\nUse read_file to load a skill's file when the task matches its description.\nWhen a skill file references a relative path, resolve it against the skill directory (the folder of SKILL.md) and use that absolute path in tool calls." +
40
49
  (input.hasSandbox
package/dist/index.cjs CHANGED
@@ -293,9 +293,17 @@ ${input.agentsMd.trim()}
293
293
  rules.push("For arithmetic, dates, counting, parsing or any other computation, run run_js instead of working it out in your head, and report the computed result.");
294
294
  }
295
295
  out.push("# How to work\n" + rules.map((r) => `- ${r}`).join("\n"));
296
+ const has = (name) => input.tools.some((t) => t.name === name);
296
297
  if (input.workspaceDescription) {
298
+ const look = ["list_files", "read_file"].filter(has);
299
+ const uses = [
300
+ look.length ? `${look.join(" and ")} to look around` : "",
301
+ has("edit_file") ? "edit_file for small changes (each oldText must match exactly once)" : "",
302
+ has("write_file") ? "write_file for new files or rewrites" : ""
303
+ ].filter(Boolean);
297
304
  out.push(
298
- "# Workspace\nYou have a file tree (absolute POSIX paths).\n" + input.workspaceDescription + "\nUse list_files and read_file to look around, edit_file for small changes (each oldText must match exactly once), write_file for new files or rewrites. A reply has an output limit: a file longer than you can emit in one call is written in parts \u2014 write_file the first part, then edit_file to append the rest (oldText = the last lines written) \u2014 never one huge write_file." + (input.canWrite && input.memoryPath ? `
305
+ "# Workspace\nYou have a file tree (absolute POSIX paths).\n" + input.workspaceDescription + (uses.length ? `
306
+ Use ${uses.join(", ")}.` : "") + (has("write_file") && has("edit_file") ? " A reply has an output limit: a file longer than you can emit in one call is written in parts \u2014 write_file the first part, then edit_file to append the rest (oldText = the last lines written) \u2014 never one huge write_file." : "") + (input.canWrite && input.memoryPath ? `
299
307
  To remember something for later conversations (a preference, a decision, a fact about the user's project), append a short line to ${input.memoryPath}; it is shown to you at the start of every conversation.` : "")
300
308
  );
301
309
  }
@@ -305,7 +313,7 @@ Your notes from earlier conversations (${input.memoryPath ?? "/memory/notes.md"}
305
313
  ` + input.memory.trim());
306
314
  }
307
315
  const visible = input.skills.filter((s) => !s.disableModelInvocation);
308
- if (visible.length) {
316
+ if (visible.length && has("read_file")) {
309
317
  const esc = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
310
318
  out.push(
311
319
  "# Skills\nThe following skills provide specialized instructions for specific tasks.\nUse read_file to load a skill's file when the task matches its description.\nWhen a skill file references a relative path, resolve it against the skill directory (the folder of SKILL.md) and use that absolute path in tool calls." + (input.hasSandbox ? "\nThe only runtime here is run_js (JavaScript in a sandbox: no shell, no Python, no network). A skill's scripts written for another language (Python, shell, Ruby\u2026) cannot be run as they are: read the script, port its logic to JavaScript and run that with run_js, keeping the same inputs, outputs and behaviour (fs.read for files the script reads; browser-safe APIs only \u2014 no npm imports, no subprocesses, no network); tell the user it was ported. If a script truly needs what the sandbox lacks (a binary, a network service), say so and do the part that can be done." : "\nThere is no runtime for scripts here: a skill's scripts (Python, shell, JavaScript\u2026) cannot be executed; follow their logic by hand where feasible and say so, or tell the user what cannot be done.") + "\n\n<available_skills>\n" + visible.map((s) => ` <skill>
@@ -3539,6 +3547,7 @@ function withoutMedia(messages, media, model) {
3539
3547
  var emptyUsage = () => ({ total_cost: 0, prompt_tokens: 0, completion_tokens: 0, calls: 0 });
3540
3548
  var abortedResult = () => ({ runId: "", reason: "aborted", text: "", usage: emptyUsage() });
3541
3549
  var SKIPPED_STOP = "Skipped: the user stopped the run.";
3550
+ var FILE_TOOL_NAMES = /* @__PURE__ */ new Set(["read_file", "list_files", "search_files", "write_file", "edit_file", "move_file", "copy_file", "delete_file"]);
3542
3551
  var balanceError = () => new ProviderError(402, "The reply was cut short because the balance could not cover a full answer; top up to continue", { code: "insufficient_balance" });
3543
3552
  function raceAbort(p, signal) {
3544
3553
  if (signal.aborted) {
@@ -4139,7 +4148,8 @@ var Agent = class {
4139
4148
  appName: this.opts.appName,
4140
4149
  instructions: typeof this.opts.instructions === "function" ? this.opts.instructions() : this.opts.instructions,
4141
4150
  tools,
4142
- workspaceDescription: ws ? ws.describe() : void 0,
4151
+ // run_js reaches the files too; with neither, the directory is only where the session is kept.
4152
+ workspaceDescription: ws && tools.some((t) => FILE_TOOL_NAMES.has(t.name) || t.name === "run_js") ? ws.describe() : void 0,
4143
4153
  skills: ws ? await ws.skills() : [],
4144
4154
  hasSandbox: tools.some((t) => t.name === "run_js"),
4145
4155
  hasAskUser: tools.some((t) => t.name === "ask_user"),
package/dist/ui.cjs CHANGED
@@ -3104,6 +3104,7 @@ function parseAttachLine(line) {
3104
3104
  }
3105
3105
  var typedOf = (m) => m?.typed;
3106
3106
  var linksHint = (uploads) => `When you create or change a file for the user, name its absolute path in backticks (for example \`/index.html\`); in the chat that path becomes a link that opens the file. Files the user attaches arrive under ${uploads}.`;
3107
+ var attachHint = (uploads) => `Files the user attaches arrive under ${uploads}.`;
3107
3108
  var filesHint = (uploads) => `The user can browse, edit and download every file of the directory from the chat's Files panel. When you create or change a file for the user, name its absolute path in backticks (for example \`${uploads}/report.csv\`); in the chat that path becomes a link that opens the file, with a download button. Files the user attaches arrive under ${uploads}.`;
3108
3109
  function decodeText(file, bytes) {
3109
3110
  const typed = /^text\//.test(file.type) || /json|xml|javascript|yaml|csv|svg/.test(file.type) || TEXT_EXT.test(file.name);
@@ -6154,8 +6155,10 @@ ${c.text}` })));
6154
6155
  const sid = id ?? newId();
6155
6156
  const workspace = typeof wsOpt === "function" ? await wsOpt(sid) : wsOpt ?? null;
6156
6157
  const base = agentOpts.instructions;
6157
- const hint2 = filesOpt === false ? linksHint(uploadsDir) : filesHint(uploadsDir);
6158
- const instructions = !workspace ? base : typeof base === "function" ? () => [base(), hint2].filter(Boolean).join("\n\n") : [base, hint2].filter(Boolean).join("\n\n");
6158
+ const fileOpt = agentOpts.fileTools;
6159
+ const writes = fileOpt === void 0 || fileOpt === true || Array.isArray(fileOpt) && (fileOpt.includes("write_file") || fileOpt.includes("edit_file"));
6160
+ const hint2 = fileOpt === false ? "" : !writes ? attachHint(uploadsDir) : filesOpt === false ? linksHint(uploadsDir) : filesHint(uploadsDir);
6161
+ const instructions = !workspace || !hint2 ? base : typeof base === "function" ? () => [base(), hint2].filter(Boolean).join("\n\n") : [base, hint2].filter(Boolean).join("\n\n");
6159
6162
  const over = {};
6160
6163
  if (userSettings.model) over.model = userSettings.model;
6161
6164
  if (userSettings.maxTurns) over.maxTurns = userSettings.maxTurns;
package/docs/tools.md CHANGED
@@ -249,6 +249,6 @@ The agent does not change a file from a stale or partial view of it — the user
249
249
 
250
250
  New files can always be written, and the model's own writes count as read. `fs.read` in `run_js` counts as reading. A file's version is its modified time, size and a fingerprint of its content (files over 4 MB: time and size), so even a same-size change in the same instant shows. What the model has read is forgotten when the conversation is compacted or rewound, since it no longer has those contents. Turn it all off with `readBeforeWrite: false`.
251
251
 
252
- The file tools come with a workspace; `fileTools: ["read_file", "list_files", "search_files"]` gives a read-only agent, `fileTools: false` none.
252
+ The file tools come with a workspace; `fileTools: ["read_file", "list_files", "search_files"]` gives a read-only agent, `fileTools: false` none. The system prompt mentions only the file tools the model has; with none (and no `run_js`) it says nothing about the directory or its skills.
253
253
 
254
254
  `sandboxTool(workspace, options)` and `runInSandbox(workspace, code, input)` are exported if you want the sandbox on its own.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runappsai/agent",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "Agent harness: the model ↔ tool loop with a workspace, skills, sessions, compaction, a sandbox and a chat UI. Bring any OpenAI-compatible model provider (RunApps included); no runtime dependencies.",
6
6
  "license": "MIT",