utilitas 2001.1.94 → 2001.1.99

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/lib/alan.mjs CHANGED
@@ -30,8 +30,9 @@ Guidelines for specific kinds of tasks (apply only to the relevant tasks):
30
30
 
31
31
  General inquiries, writing, translation, and common knowledge:
32
32
  - Uses a friendly, concise, and easy-to-understand tone to provides accurate and comprehensive answers.
33
+ - To maintain Chain of Thought, I will provide the previous reasoning details so you can understand the context. However, avoid excessive or redundant thinking. You should determine the appropriate depth of reasoning based on the specific problem rather than pursuing continuity and depth at all costs. Overthinking will slow down response times and waste inference resources and costs.
34
+ - Remember to respond in simple Markdown format unless explicitly requested, avoid complex nested formatting. Especially in conversational scenarios, you should maintain Markdown format rather than outputting HTML or JSON. However, you may output or insert any necessary formats if the task is explicitly for coding or if the user specifically requests it.
33
35
  - Avoid overusing the \`;\`' symbol, as it is a common mistake made by LLMs.
34
- - Use simple Markdown formatting, avoid complex nested formats.
35
36
  - Based on the context, user instructions, and other factors, determine the language for the response. If the language cannot be determined, default to English.
36
37
 
37
38
  Issues related to computers, programming, code, mathematics, science and engineering:
@@ -938,7 +939,7 @@ const promptOpenRouter = async (aiId, content, options = {}) => {
938
939
  delteReasoning && delteReasoning === resultReasoning
939
940
  && (delteReasoning = `${result ? '\n\n' : ''}${THINK_STR}\n${delteReasoning}`);
940
941
  resultReasoning && (deltaText || delta.tool_calls?.length) && !reasoningEnd && (
941
- reasoningEnd = delteReasoning = `${delteReasoning}${THINK_END}\n\n`
942
+ reasoningEnd = delteReasoning = `${delteReasoning}\n${THINK_END}\n\n`
942
943
  );
943
944
  deltaText = delteReasoning + deltaText;
944
945
  result += deltaText;
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.94",
4
+ "version": "2001.1.99",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/shell.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { exec as _exec } from 'child_process';
1
+ import { spawn } from 'child_process';
2
2
  import { log as _log } from './utilitas.mjs';
3
3
 
4
4
  const log = (content) => _log(content, import.meta.url);
@@ -8,21 +8,44 @@ const exist = (bin) => { assertCommand(bin); return which(bin); };
8
8
 
9
9
  const exec = async (command, options = {}) => {
10
10
  assertCommand(command);
11
+ const limit = options?.limit || 3000;
11
12
  return new Promise((resolve, reject) => {
12
- const child = (_exec || vF)(command, (error, stdout, stderr) => {
13
- if (error && !options?.acceptError) { return reject(error); }
14
- try {
15
- assert(options?.acceptError || !stderr, stderr, 500);
16
- } catch (e) {
17
- return reject(e);
13
+ const child = (spawn || vF)(command, { ...options || {}, shell: true });
14
+ const buf = { stdout: { lines: [], p: '' }, stderr: { lines: [], p: '' } };
15
+ const collect = (k, d) => {
16
+ if (options?.stream) { options.stream(d); }
17
+ const p = (buf[k].p + d).split(/\r?\n/);
18
+ buf[k].p = p.pop();
19
+ buf[k].lines = buf[k].lines.concat(p);
20
+ if (buf[k].lines.length > limit) {
21
+ buf[k].lines = buf[k].lines.slice(-limit);
18
22
  }
19
- resolve(options?.acceptError
20
- ? [stdout, stderr].map(x => x.trim()).filter(x => x).join('\n')
21
- : stdout.trim());
22
- });
23
- if (options?.stream && child?.stdout) {
24
- child.stdout.on('data', options.stream);
25
- child.stderr.on('data', options.stream);
23
+ };
24
+ const getBuf = (k) => {
25
+ const c = buf[k].lines.join('\n');
26
+ return c + (c && buf[k].p ? '\n' : '') + buf[k].p;
27
+ };
28
+ if (child?.stdout) {
29
+ child.stdout.on('data', d => collect('stdout', d));
30
+ child.stderr.on('data', d => collect('stderr', d));
31
+ child.on('close', code => {
32
+ const stdout = getBuf('stdout');
33
+ const stderr = getBuf('stderr');
34
+ if (code && !options?.acceptError) {
35
+ const err = new Error(stderr || `Command failed: ${command}\n${stdout}`);
36
+ err.code = code;
37
+ return reject(err);
38
+ }
39
+ try {
40
+ assert(options?.acceptError || !stderr, stderr, 500);
41
+ } catch (e) { return reject(e); }
42
+ resolve(options?.acceptError
43
+ ? [stdout, stderr].map(x => x.trim()).filter(x => x).join('\n')
44
+ : stdout.trim());
45
+ });
46
+ child.on('error', reject);
47
+ } else {
48
+ vF(command, resolve);
26
49
  }
27
50
  });
28
51
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.94",
4
+ "version": "2001.1.99",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",