@molecule/api-ai-tools 1.4.0 → 1.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAoB9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA+BnE;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,MAAM,EAAE,CA+wCxF"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAoB9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA+BnE;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,MAAM,EAAE,CAqzCxF"}
package/dist/tools.js CHANGED
@@ -379,6 +379,13 @@ export function buildTools(backend, config) {
379
379
  // reads in one imported-app build were misses on files that never existed). Return
380
380
  // ground truth in the SAME result — what the parent directory actually contains — so
381
381
  // the next read uses a real name instead of another guess.
382
+ // A package's docs are one tool call away wherever node_modules happens to live.
383
+ const moleculePkg = /node_modules\/(@molecule\/[^/]+)\//.exec(path)?.[1];
384
+ if (moleculePkg && /No such file or directory/i.test(message)) {
385
+ return {
386
+ error: `No such file: ${path}. Read ${moleculePkg}'s documentation with read_molecule_doc("${moleculePkg}") instead of looking for it in node_modules.`,
387
+ };
388
+ }
382
389
  if (/No such file or directory/i.test(message)) {
383
390
  const parent = path.replace(/\/[^/]*$/, '') || '/';
384
391
  let listing;
@@ -413,7 +420,26 @@ export function buildTools(backend, config) {
413
420
  return { path, entries: entries.map((e) => ({ name: e.name, type: e.type })) };
414
421
  }
415
422
  catch (e) {
416
- return { error: `Failed to list ${path}: ${e.message}` };
423
+ const message = e.message;
424
+ // Same ground-truth answer as read_file's miss: a guessed path gets the parent's
425
+ // real contents back, so the next call names something that exists.
426
+ if (/No such file or directory|cannot access/i.test(message)) {
427
+ const parent = path.replace(/\/[^/]*$/, '') || '/';
428
+ try {
429
+ const siblings = await backend.readDir(parent);
430
+ return {
431
+ error: `No such directory: ${path}. ${parent} contains: ${siblings
432
+ .slice(0, 40)
433
+ .map((s) => s.name + (s.type === 'directory' ? '/' : ''))
434
+ .join(', ') || '(nothing)'}${siblings.length > 40 ? ', …' : ''}.`,
435
+ };
436
+ }
437
+ catch (_parentErr) {
438
+ // The parent is missing too; the plain message below says so.
439
+ return { error: `No such directory: ${path} (and ${parent} does not exist either).` };
440
+ }
441
+ }
442
+ return { error: `Failed to list ${path}: ${message}` };
417
443
  }
418
444
  },
419
445
  async read_file(input) {
@@ -664,10 +690,15 @@ export function buildTools(backend, config) {
664
690
  `indentation — or include more surrounding context to make it unique.`,
665
691
  };
666
692
  }
667
- if (count > 1)
693
+ if (count > 1) {
694
+ // Say WHERE, so the retry can widen old_string around the one it means.
695
+ const lines = [];
696
+ for (let at = content.indexOf(oldString); at >= 0 && lines.length < 10; at = content.indexOf(oldString, at + 1))
697
+ lines.push(content.slice(0, at).split('\n').length);
668
698
  return {
669
- error: `old_string found ${count} times in ${path} — must be unique. Include more surrounding context.`,
699
+ error: `old_string found ${count} times in ${path} (starting at lines ${lines.join(', ')}${count > lines.length ? ', …' : ''}) — must be unique. Include more surrounding context from the one you mean, or make one edit per occurrence.`,
670
700
  };
701
+ }
671
702
  // Splice by index rather than `content.replace(oldString, newString)`:
672
703
  // String.replace treats `$&`, `$$`, `` $` ``, `$'` in the REPLACEMENT as
673
704
  // special patterns, so a new_string containing regex-replacement code
@@ -937,11 +968,11 @@ export function buildTools(backend, config) {
937
968
  ? `This command asks for ${declaredSeconds}s, more than this tool's ${ceilingSeconds}s, and its ` +
938
969
  'output only appears when it ends — so it was started in the background instead. '
939
970
  : '') +
940
- `Started in the background. Its output is being written to ${log} — read it with ` +
941
- `read_file (use offset/limit to follow a long one). When it finishes, ${exitFile} ` +
942
- `appears and holds the exit code. If you have other work, do it and check back. If ` +
943
- `you need this result before you can continue, call wait_for_task with this taskId — ` +
944
- `never sleep and read the log by hand.`,
971
+ `Started in the background. Its output is written to ${log} and comes back as the ` +
972
+ `stdout of wait_for_task when the command finishes (read_file cannot reach /tmp — ` +
973
+ `to peek mid-run, exec_command: tail ${log}). If you have other work, do it and ` +
974
+ `check back. If you need this result before you can continue, call wait_for_task ` +
975
+ `with this taskId — never sleep and read the log by hand.`,
945
976
  };
946
977
  }
947
978
  catch (e) {
@@ -1122,7 +1153,8 @@ export function buildTools(backend, config) {
1122
1153
  status: 'stuck',
1123
1154
  waitedMs: waitedBefore + waitedMs,
1124
1155
  note: `${Math.round((waitedBefore + waitedMs) / 1000)}s of waiting and it has not exited — it is ` +
1125
- `stuck, not slow. Read /tmp/${taskId}.log for what it printed, kill it (exec_command: ` +
1156
+ `stuck, not slow. See what it printed with exec_command (tail /tmp/${taskId}.log — ` +
1157
+ `read_file cannot reach /tmp), kill it (exec_command: ` +
1126
1158
  `kill $(cat /tmp/${taskId}.pid) 2>/dev/null; pkill -f ${taskId}.sh) and move on; do not wait on it again.`,
1127
1159
  };
1128
1160
  }
@@ -1131,7 +1163,8 @@ export function buildTools(backend, config) {
1131
1163
  status: 'running',
1132
1164
  waitedMs,
1133
1165
  note: `Still running after ${Math.round(waitedMs / 1000)}s. Call wait_for_task again to ` +
1134
- `keep waiting, or read ${log} for its output so far.`,
1166
+ `keep waiting — its result carries the log output. To peek at the output so far, ` +
1167
+ `exec_command: tail ${log} (read_file cannot reach /tmp).`,
1135
1168
  };
1136
1169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BAAkB,KAAK,CAAA;AACpC,wBAAwB;AACxB,eAAO,MAAM,gBAAgB,MAAM,CAAA;AAEnC;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,mHAW/B,CAAA;AAEV;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAmBnE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,CAsCf;AAED,qEAAqE;AACrE,eAAO,MAAM,eAAe,QAA0C,CAAA;AAEtE;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU7D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,MAAM,GAAG,IAAI,CAKhB"}
package/dist/utilities.js CHANGED
@@ -223,7 +223,8 @@ export function checkBlockedCommand(command) {
223
223
  const envDumpSteer = ' You do NOT need to dump it: the managed service values (DATABASE_URL, etc.) are already ' +
224
224
  'in the process environment — read them IN CODE via process.env / your config loader, or ' +
225
225
  "check the project's provisioned env file to see WHICH services exist. Printing them only " +
226
- 'leaks secrets into the transcript.';
226
+ 'leaks secrets into the transcript. To check whether ONE variable is set without printing ' +
227
+ 'it: `test -n "$NAME" && echo set || echo missing`.';
227
228
  if (BLOCKED_COMMANDS.test(command))
228
229
  return `Command blocked: dumping environment variables is not allowed.${envDumpSteer}`;
229
230
  if (BLOCKED_PROC_REDIRECT.test(command))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-ai-tools",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Shared AI agent tools with backend abstraction for sandbox and local execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",