@link-assistant/agent 0.25.4 → 0.25.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/LICENSE +24 -0
- package/package.json +10 -12
- package/src/cli/cmd/run.ts +5 -1
- package/src/cli/continuous-mode.js +3 -0
- package/src/cli/event-handler.js +5 -1
- package/src/index.js +3 -0
- package/src/provider/retry-fetch.ts +9 -2
- package/src/util/error-text.ts +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@link-assistant/agent",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.6",
|
|
4
4
|
"description": "A minimal, public domain AI CLI agent compatible with OpenCode's JSON interface. Bun-only runtime.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"agent": "
|
|
8
|
+
"agent": "src/index.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"dev": "bun run src/index.js",
|
|
12
|
-
"test": "bun test ./tests/*.js ./tests/*.ts",
|
|
12
|
+
"test": "bun test --timeout 30000 ./tests/*.js ./tests/*.ts",
|
|
13
13
|
"test:integration": "bun test ./tests/integration/basic.js",
|
|
14
|
-
"lint": "eslint .",
|
|
15
|
-
"lint:
|
|
16
|
-
"
|
|
17
|
-
"format
|
|
14
|
+
"lint": "eslint . && npm run lint:scripts",
|
|
15
|
+
"lint:scripts": "cd ../scripts && eslint . --config ./eslint.config.mjs",
|
|
16
|
+
"lint:fix": "eslint . --fix && cd ../scripts && eslint . --config ./eslint.config.mjs --fix",
|
|
17
|
+
"format": "prettier --write . ../scripts",
|
|
18
|
+
"format:check": "prettier --check . ../scripts",
|
|
18
19
|
"check:file-size": "node ../scripts/check-file-size.mjs",
|
|
19
20
|
"check": "npm run lint && npm run format:check && npm run check:file-size",
|
|
20
21
|
"prepare": "cd .. && husky || true",
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
},
|
|
29
30
|
"repository": {
|
|
30
31
|
"type": "git",
|
|
31
|
-
"url": "https://github.com/link-assistant/agent"
|
|
32
|
+
"url": "git+https://github.com/link-assistant/agent.git"
|
|
32
33
|
},
|
|
33
34
|
"keywords": [
|
|
34
35
|
"ai",
|
|
@@ -46,10 +47,7 @@
|
|
|
46
47
|
"src/",
|
|
47
48
|
"package.json",
|
|
48
49
|
"README.md",
|
|
49
|
-
"
|
|
50
|
-
"../TOOLS.md",
|
|
51
|
-
"../EXAMPLES.md",
|
|
52
|
-
"../LICENSE"
|
|
50
|
+
"LICENSE"
|
|
53
51
|
],
|
|
54
52
|
"dependencies": {
|
|
55
53
|
"@actions/core": "^1.11.1",
|
package/src/cli/cmd/run.ts
CHANGED
|
@@ -264,7 +264,11 @@ export const RunCommand = cmd({
|
|
|
264
264
|
err = String(props.error.data.message);
|
|
265
265
|
}
|
|
266
266
|
errorMsg = errorMsg ? errorMsg + EOL + err : err;
|
|
267
|
-
|
|
267
|
+
// Always include the human-readable string alongside the
|
|
268
|
+
// machine-readable object so consumers never print
|
|
269
|
+
// "[object Object]" (#289).
|
|
270
|
+
if (outputJsonEvent('error', { message: err, error: props.error }))
|
|
271
|
+
continue;
|
|
268
272
|
UI.error(err);
|
|
269
273
|
}
|
|
270
274
|
|
|
@@ -11,6 +11,7 @@ import { SessionPrompt } from '../session/prompt.ts';
|
|
|
11
11
|
import { createEventHandler, serializeOutput } from '../json-standard/index.ts';
|
|
12
12
|
import { createContinuousStdinReader } from './input-queue.js';
|
|
13
13
|
import { outputBusEvent } from './event-handler.js';
|
|
14
|
+
import { errorText } from '../util/error-text.ts';
|
|
14
15
|
import { Permission } from '../permission/index.ts';
|
|
15
16
|
import { Log } from '../util/log.ts';
|
|
16
17
|
import { config } from '../config/config.ts';
|
|
@@ -385,6 +386,7 @@ export async function runContinuousServerMode(
|
|
|
385
386
|
type: 'error',
|
|
386
387
|
timestamp: Date.now(),
|
|
387
388
|
sessionID,
|
|
389
|
+
message: errorText(error),
|
|
388
390
|
error: error instanceof Error ? error.message : String(error),
|
|
389
391
|
});
|
|
390
392
|
});
|
|
@@ -598,6 +600,7 @@ export async function runContinuousDirectMode(
|
|
|
598
600
|
type: 'error',
|
|
599
601
|
timestamp: Date.now(),
|
|
600
602
|
sessionID,
|
|
603
|
+
message: errorText(error),
|
|
601
604
|
error: error instanceof Error ? error.message : String(error),
|
|
602
605
|
});
|
|
603
606
|
});
|
package/src/cli/event-handler.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Bus } from '../bus/index.ts';
|
|
7
|
+
import { errorText } from '../util/error-text.ts';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Create a subscription for session bus events that outputs events in the selected JSON format.
|
|
@@ -90,11 +91,13 @@ export function outputBusEvent({
|
|
|
90
91
|
|
|
91
92
|
// If tool failed, also output an error event
|
|
92
93
|
if (part.state?.status === 'error') {
|
|
94
|
+
const stateError = part.state.error;
|
|
93
95
|
eventHandler.output({
|
|
94
96
|
type: 'error',
|
|
95
97
|
timestamp: Date.now(),
|
|
96
98
|
sessionID,
|
|
97
|
-
|
|
99
|
+
message: errorText(stateError, 'Tool execution failed'),
|
|
100
|
+
error: stateError || 'Tool execution failed',
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
}
|
|
@@ -145,6 +148,7 @@ export function outputBusEvent({
|
|
|
145
148
|
type: 'error',
|
|
146
149
|
timestamp: Date.now(),
|
|
147
150
|
sessionID,
|
|
151
|
+
message: errorText(props.error),
|
|
148
152
|
error: props.error,
|
|
149
153
|
});
|
|
150
154
|
}
|
package/src/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { McpCommand } from './cli/cmd/mcp.ts';
|
|
|
27
27
|
import { AuthCommand } from './cli/cmd/auth.ts';
|
|
28
28
|
import { FormatError } from './cli/error.ts';
|
|
29
29
|
import { UI } from './cli/ui.ts';
|
|
30
|
+
import { errorText } from './util/error-text.ts';
|
|
30
31
|
import {
|
|
31
32
|
createVerboseFetch,
|
|
32
33
|
registerPendingStreamLogExitHandler,
|
|
@@ -520,6 +521,7 @@ async function runServerMode(
|
|
|
520
521
|
type: 'error',
|
|
521
522
|
timestamp: Date.now(),
|
|
522
523
|
sessionID,
|
|
524
|
+
message: errorText(error),
|
|
523
525
|
error: error instanceof Error ? error.message : String(error),
|
|
524
526
|
});
|
|
525
527
|
});
|
|
@@ -605,6 +607,7 @@ async function runDirectMode(
|
|
|
605
607
|
type: 'error',
|
|
606
608
|
timestamp: Date.now(),
|
|
607
609
|
sessionID,
|
|
610
|
+
message: errorText(error),
|
|
608
611
|
error: error instanceof Error ? error.message : String(error),
|
|
609
612
|
});
|
|
610
613
|
});
|
|
@@ -183,9 +183,16 @@ export namespace RetryFetch {
|
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
// The timer is deliberately NOT unref'd. Every caller awaits this
|
|
187
|
+
// promise, so an unref'd timer is the only pending work while a retry
|
|
188
|
+
// wait is in flight: the runtime is then free to stop waiting on it,
|
|
189
|
+
// which drops the retry instead of performing it. On Bun for Windows
|
|
190
|
+
// this showed up as `tests/retry-fetch.ts > retries on 429 and succeeds
|
|
191
|
+
// on second attempt` never resuming, burning the whole job timeout.
|
|
192
|
+
// See https://github.com/link-assistant/agent/issues/287.
|
|
193
|
+
// The abort path below clears the timer, so a cancelled wait still lets
|
|
194
|
+
// the process exit immediately (the concern behind #213).
|
|
186
195
|
const timeout = setTimeout(resolve, ms);
|
|
187
|
-
// Prevent sleep timer from keeping event loop alive (#213)
|
|
188
|
-
if (timeout.unref) timeout.unref();
|
|
189
196
|
|
|
190
197
|
if (signal) {
|
|
191
198
|
const abortHandler = () => {
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable rendering of arbitrary error values (issue #289).
|
|
3
|
+
*
|
|
4
|
+
* JSON `error` events used to carry only the machine-readable
|
|
5
|
+
* `NamedError.toObject()` shape (`{name, data: {message}}`), so consumers doing
|
|
6
|
+
* `` `${record.error}` `` published `[object Object]` and the real cause was
|
|
7
|
+
* lost. Every emitted `error` event now also carries a `message` string
|
|
8
|
+
* produced by `stringifyErrorValue`.
|
|
9
|
+
*
|
|
10
|
+
* The renderer is circular-safe and depth-limited, and never invents a
|
|
11
|
+
* placeholder: when nothing readable can be derived it returns an empty
|
|
12
|
+
* string so the caller can pick its own fallback.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const MAX_DEPTH = 5;
|
|
16
|
+
|
|
17
|
+
function fromParts(name: string | undefined, message: string | undefined) {
|
|
18
|
+
if (name && message) return `${name}: ${message}`;
|
|
19
|
+
return message || name || '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function render(value: unknown, depth: number, seen: Set<object>): string {
|
|
23
|
+
if (value === null || value === undefined) return '';
|
|
24
|
+
if (typeof value === 'string') return value.trim();
|
|
25
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
26
|
+
return String(value);
|
|
27
|
+
if (typeof value !== 'object') return '';
|
|
28
|
+
|
|
29
|
+
const object = value as Record<string, unknown>;
|
|
30
|
+
if (seen.has(object)) return '';
|
|
31
|
+
if (depth >= MAX_DEPTH) return '';
|
|
32
|
+
seen.add(object);
|
|
33
|
+
|
|
34
|
+
if (Array.isArray(object)) {
|
|
35
|
+
const rendered = object
|
|
36
|
+
.map((item) => render(item, depth + 1, seen))
|
|
37
|
+
.filter((item) => item.length > 0);
|
|
38
|
+
return rendered.join('; ');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (object instanceof Error) {
|
|
42
|
+
return fromParts(object.name, object.message) || String(object);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// NamedError.toObject(): { name, data: { message, ... } }
|
|
46
|
+
const name = typeof object.name === 'string' ? object.name : undefined;
|
|
47
|
+
const data = object.data;
|
|
48
|
+
if (data && typeof data === 'object') {
|
|
49
|
+
const dataMessage = render(
|
|
50
|
+
(data as Record<string, unknown>).message,
|
|
51
|
+
depth + 1,
|
|
52
|
+
seen
|
|
53
|
+
);
|
|
54
|
+
if (dataMessage) return fromParts(name, dataMessage);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const message = render(object.message, depth + 1, seen);
|
|
58
|
+
if (message) return fromParts(name, message);
|
|
59
|
+
|
|
60
|
+
// Envelope shapes: { error: … }, { cause: … }
|
|
61
|
+
const nested =
|
|
62
|
+
render(object.error, depth + 1, seen) ||
|
|
63
|
+
render(object.cause, depth + 1, seen);
|
|
64
|
+
if (nested) return name ? fromParts(name, nested) : nested;
|
|
65
|
+
|
|
66
|
+
return name || '';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Render any error-ish value as a human-readable string.
|
|
71
|
+
* Returns an empty string when nothing readable can be derived.
|
|
72
|
+
*/
|
|
73
|
+
export function stringifyErrorValue(value: unknown): string {
|
|
74
|
+
return render(value, 0, new Set<object>());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Same as {@link stringifyErrorValue} but guarantees a non-empty string.
|
|
79
|
+
*/
|
|
80
|
+
export function errorText(value: unknown, fallback = 'Unknown error'): string {
|
|
81
|
+
return stringifyErrorValue(value) || fallback;
|
|
82
|
+
}
|