@xiangyixie/dsh-superagent 0.9.1 → 0.9.3
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/CHANGELOG.md +281 -244
- package/LICENSE +21 -21
- package/README.md +600 -556
- package/bin/report.js +79 -79
- package/bin/watch.js +57 -57
- package/cordis.patch.yml +9 -9
- package/lib/control.js +494 -494
- package/lib/errors.js +199 -199
- package/lib/index.js +822 -822
- package/lib/orchestrator.js +1464 -1464
- package/lib/report.js +733 -733
- package/lib/store.js +385 -385
- package/lib/usage.js +152 -152
- package/lib/watch.js +458 -458
- package/package.json +67 -67
package/lib/errors.js
CHANGED
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Readable error messages for tool results.
|
|
3
|
-
*
|
|
4
|
-
* Host errors reach the plugin as raw strings: SDK messages, filesystem codes,
|
|
5
|
-
* sandbox launcher output, provider HTTP text. A user cannot act on
|
|
6
|
-
* `Cannot read properties of undefined (reading 'maxDepth')`. This module maps
|
|
7
|
-
* the known shapes to one sentence plus a next step, and always keeps the
|
|
8
|
-
* original text so nothing is hidden.
|
|
9
|
-
*
|
|
10
|
-
* @module dsh-superagent/errors
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const RULES = [
|
|
14
|
-
{
|
|
15
|
-
id: 'sandbox',
|
|
16
|
-
test: /windows-acl-run|--temp is not an existing directory|sandbox.*(acl|launch)/i,
|
|
17
|
-
summary: 'the Windows file sandbox could not start a child process, so that subtask never reached the model',
|
|
18
|
-
hint: 'this is a host sandbox failure, not your goal and not your API key. The subtask is retried once. '
|
|
19
|
-
+ 'If it repeats: restart the host, or disable the Windows ACL sandbox in the profile, '
|
|
20
|
-
+ 'then run the diagnose-windows-sandbox-acl skill before retrying the run.',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: 'quota',
|
|
24
|
-
test: /quota exceeded/i,
|
|
25
|
-
summary: 'the run was not started because the active-run limit is already in use',
|
|
26
|
-
hint: 'wait for a running run with superagent_status, stop one with superagent_cancel, '
|
|
27
|
-
+ 'or raise maxActiveRuns in the superagent config and restart the host.',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
id: 'budget',
|
|
31
|
-
test: /budget exceeded|budget reached/i,
|
|
32
|
-
summary: 'the run stopped because it reached its spending cap',
|
|
33
|
-
hint: 'read the partial report first; raise maxModelCallsPerRun or maxTokensPerRun only if this spend was expected.',
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
id: 'corrupt',
|
|
37
|
-
test: /not valid json|state file .*damaged|unexpected end of json/i,
|
|
38
|
-
summary: 'a saved run file is damaged, so that run cannot be read',
|
|
39
|
-
hint: 'the original file is kept next to it with a .corrupt- suffix. Inspect it, then delete it; '
|
|
40
|
-
+ 'other runs and new runs are unaffected.',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
id: 'unknown-run',
|
|
44
|
-
test: /unknown run/i,
|
|
45
|
-
summary: 'no run with that id is recorded in this state directory',
|
|
46
|
-
hint: 'call superagent_list to see recorded run ids. If the run was started with a different DSH_HOME or stateDir, '
|
|
47
|
-
+ 'point this host at the same directory.',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
id: 'missing-credential',
|
|
51
|
-
test: /missing_credential|no api key for provider route|missing api key|api key (is )?not (set|configured)/i,
|
|
52
|
-
summary: 'the model route has no API key in the environment that started the host',
|
|
53
|
-
hint: 'the detail line names the provider route (for example deepseek-official). Set that route\'s key in the '
|
|
54
|
-
+ 'environment that starts the host — the default profile uses DEEPSEEK_API_KEY — then restart. '
|
|
55
|
-
+ 'The plugin never stores a key.',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
id: 'unknown-model',
|
|
59
|
-
test: /unknown model|model .*not found|no such model|unsupported model|invalid model|model .*does not exist/i,
|
|
60
|
-
summary: 'the model or provider route named in the config does not exist in this profile',
|
|
61
|
-
hint: 'check childProvider and childModel against the routes in the profile config; the default route is '
|
|
62
|
-
+ 'deepseek-official/deepseek-flash. Remove the override to inherit the session\'s model.',
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: 'auth',
|
|
66
|
-
test: /\b401\b|\b403\b|unauthori[sz]ed|invalid api key|incorrect api key|authentication failed|invalid_api_key/i,
|
|
67
|
-
summary: 'the model provider rejected the API key',
|
|
68
|
-
hint: 'the key is read from the environment variable of the route the profile uses (DEEPSEEK_API_KEY for the '
|
|
69
|
-
+ 'default deepseek-official route; DASHSCOPE_API_KEY only if you added a DashScope route). Set it in the '
|
|
70
|
-
+ 'environment that starts the host, then restart. The key is never stored in the plugin config.',
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
id: 'context',
|
|
74
|
-
test: /context length|context window|too many tokens|maximum context|token limit/i,
|
|
75
|
-
summary: 'the model refused the request because the prompt is too long',
|
|
76
|
-
hint: 'lower maxSubtasks so each worker prompt is smaller, or configure a model with a larger context window.',
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
id: 'network',
|
|
80
|
-
test: /fetch failed|econnrefused|econnreset|etimedout|enotfound|eai_again|socket hang up|network error|\b50[234]\b/i,
|
|
81
|
-
summary: 'the model provider could not be reached',
|
|
82
|
-
hint: 'check network or proxy access to the provider. The subtask was retried; superagent_resume will retry it again '
|
|
83
|
-
+ 'without re-running the subtasks that already finished.',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
id: 'filesystem',
|
|
87
|
-
test: /\bEPERM\b|\bEACCES\b|\bEBUSY\b|\bENOSPC\b|\bENOENT\b|\bENOTDIR\b|no space left|read-only file system|permission denied|state directory/i,
|
|
88
|
-
summary: 'the plugin could not read or write its state directory',
|
|
89
|
-
hint: 'make sure stateDir (default $DSH_HOME/state/superagent) exists and is writable by the user running the host. '
|
|
90
|
-
+ 'If DSH_HOME points somewhere that disappeared, fix it and restart; runs in the old directory are not lost, '
|
|
91
|
-
+ 'point the same stateDir at them to read them. On Windows, antivirus and synced folders such as OneDrive can lock these files.',
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: 'host-api',
|
|
95
|
-
test: /reading 'maxDepth'|reading "maxDepth"|cannot read properties of undefined|is not a function|startActivation/i,
|
|
96
|
-
summary: 'the harness API did not match what this plugin expects, so the child agent could not be created',
|
|
97
|
-
hint: 'check that the harness version satisfies the plugin engines field (dsh >=0.2.2-rc.1 <0.3.0). '
|
|
98
|
-
+ 'This is a version mismatch, not a problem with the goal.',
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
id: 'child-guard',
|
|
102
|
-
test: /cannot enforce maxsubagentdepth|does not support independent agent presets|childpreset .* cannot be applied/i,
|
|
103
|
-
summary: 'the configured child-agent guard cannot be enforced by this subagent provider',
|
|
104
|
-
hint: 'keep provider: spawn (it supports maxDepth and presets), or set maxSubagentDepth: provider-managed and put the '
|
|
105
|
-
+ 'tool restriction in a preset named by childPreset.',
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
id: 'run-owned',
|
|
109
|
-
test: /already being started by|still owned by a live process|still active in this process/i,
|
|
110
|
-
summary: 'another live process already owns this run',
|
|
111
|
-
hint: 'two profiles can share one state directory, and only one process may run a given run. Read it with '
|
|
112
|
-
+ 'superagent_status, cancel it with superagent_cancel, or wait for it to finish.',
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
id: 'no-goal',
|
|
116
|
-
test: /goal is required/i,
|
|
117
|
-
summary: 'superagent_start was called without a goal',
|
|
118
|
-
hint: 'pass a concrete goal string, for example "compare X and Y and return a table of prices".',
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
id: 'no-session',
|
|
122
|
-
test: /session_id is required|session .* is not open in this host/i,
|
|
123
|
-
summary: 'the request did not name a live session that can own the run',
|
|
124
|
-
hint: 'pass session_id of a session that is open in the host process running the control plane; '
|
|
125
|
-
+ 'a run needs a live parent agent to create its child agents. Read the discovery file for the URL and token.',
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
id: 'no-agent',
|
|
129
|
-
test: /no live agent|live parent agent/i,
|
|
130
|
-
summary: 'the tool was called outside a live session',
|
|
131
|
-
hint: 'start runs from an interactive session; a run needs a parent agent to own its children.',
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
id: 'no-subagents',
|
|
135
|
-
test: /subagent service is unavailable/i,
|
|
136
|
-
summary: 'this profile has no subagent service, so the plugin cannot spawn workers',
|
|
137
|
-
hint: 'enable the subagents service in the profile or use a bundle that includes it.',
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
id: 'recursion',
|
|
141
|
-
test: /^refused:/i,
|
|
142
|
-
summary: 'a superagent worker tried to start, resume, or cancel a run, which is blocked',
|
|
143
|
-
hint: 'workers must finish their own subtask; only the top-level agent manages runs.',
|
|
144
|
-
},
|
|
145
|
-
]
|
|
146
|
-
|
|
147
|
-
function rawOf(input) {
|
|
148
|
-
if (input === null || input === undefined) return ''
|
|
149
|
-
const text = typeof input === 'string' ? input : input.message ?? String(input)
|
|
150
|
-
return String(text).trim()
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function shorten(text, limit) {
|
|
154
|
-
if (text.length <= limit) return text
|
|
155
|
-
return `${text.slice(0, limit - 1).trimEnd()}…`
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Classify one error message.
|
|
160
|
-
* @param {unknown} input - Error, message, or diagnostic string.
|
|
161
|
-
* @returns {{ id: string, summary: string, hint: string, detail: string }}
|
|
162
|
-
*/
|
|
163
|
-
export function classifyError(input) {
|
|
164
|
-
const detail = rawOf(input) || 'unknown error'
|
|
165
|
-
for (const rule of RULES) {
|
|
166
|
-
if (rule.test.test(detail)) return { id: rule.id, summary: rule.summary, hint: rule.hint, detail }
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
id: 'unclassified',
|
|
170
|
-
summary: shorten(detail, 300),
|
|
171
|
-
hint: 'this is the untouched message from the host. If it is not actionable, call superagent_list to check '
|
|
172
|
-
+ 'state, then retry once; the failure is recorded, so superagent_resume will retry only the failed subtasks.',
|
|
173
|
-
detail,
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* One-line form used inside run listings and subtask rows.
|
|
179
|
-
* @param {unknown} input - Error, message, or diagnostic string.
|
|
180
|
-
* @returns {string} summary sentence.
|
|
181
|
-
*/
|
|
182
|
-
export function summarizeError(input) {
|
|
183
|
-
const { summary } = classifyError(input)
|
|
184
|
-
return summary.endsWith('.') ? summary.slice(0, -1) : summary
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Full form used as a tool result.
|
|
189
|
-
* @param {unknown} input - Error, message, or diagnostic string.
|
|
190
|
-
* @returns {string} `[error]` block with hint and untouched detail.
|
|
191
|
-
*/
|
|
192
|
-
export function describeError(input) {
|
|
193
|
-
const { summary, hint, detail } = classifyError(input)
|
|
194
|
-
return [
|
|
195
|
-
`[error] ${summary}`,
|
|
196
|
-
`hint: ${hint}`,
|
|
197
|
-
`detail: ${detail}`,
|
|
198
|
-
].join('\n')
|
|
199
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Readable error messages for tool results.
|
|
3
|
+
*
|
|
4
|
+
* Host errors reach the plugin as raw strings: SDK messages, filesystem codes,
|
|
5
|
+
* sandbox launcher output, provider HTTP text. A user cannot act on
|
|
6
|
+
* `Cannot read properties of undefined (reading 'maxDepth')`. This module maps
|
|
7
|
+
* the known shapes to one sentence plus a next step, and always keeps the
|
|
8
|
+
* original text so nothing is hidden.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-superagent/errors
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const RULES = [
|
|
14
|
+
{
|
|
15
|
+
id: 'sandbox',
|
|
16
|
+
test: /windows-acl-run|--temp is not an existing directory|sandbox.*(acl|launch)/i,
|
|
17
|
+
summary: 'the Windows file sandbox could not start a child process, so that subtask never reached the model',
|
|
18
|
+
hint: 'this is a host sandbox failure, not your goal and not your API key. The subtask is retried once. '
|
|
19
|
+
+ 'If it repeats: restart the host, or disable the Windows ACL sandbox in the profile, '
|
|
20
|
+
+ 'then run the diagnose-windows-sandbox-acl skill before retrying the run.',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'quota',
|
|
24
|
+
test: /quota exceeded/i,
|
|
25
|
+
summary: 'the run was not started because the active-run limit is already in use',
|
|
26
|
+
hint: 'wait for a running run with superagent_status, stop one with superagent_cancel, '
|
|
27
|
+
+ 'or raise maxActiveRuns in the superagent config and restart the host.',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'budget',
|
|
31
|
+
test: /budget exceeded|budget reached/i,
|
|
32
|
+
summary: 'the run stopped because it reached its spending cap',
|
|
33
|
+
hint: 'read the partial report first; raise maxModelCallsPerRun or maxTokensPerRun only if this spend was expected.',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'corrupt',
|
|
37
|
+
test: /not valid json|state file .*damaged|unexpected end of json/i,
|
|
38
|
+
summary: 'a saved run file is damaged, so that run cannot be read',
|
|
39
|
+
hint: 'the original file is kept next to it with a .corrupt- suffix. Inspect it, then delete it; '
|
|
40
|
+
+ 'other runs and new runs are unaffected.',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'unknown-run',
|
|
44
|
+
test: /unknown run/i,
|
|
45
|
+
summary: 'no run with that id is recorded in this state directory',
|
|
46
|
+
hint: 'call superagent_list to see recorded run ids. If the run was started with a different DSH_HOME or stateDir, '
|
|
47
|
+
+ 'point this host at the same directory.',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'missing-credential',
|
|
51
|
+
test: /missing_credential|no api key for provider route|missing api key|api key (is )?not (set|configured)/i,
|
|
52
|
+
summary: 'the model route has no API key in the environment that started the host',
|
|
53
|
+
hint: 'the detail line names the provider route (for example deepseek-official). Set that route\'s key in the '
|
|
54
|
+
+ 'environment that starts the host — the default profile uses DEEPSEEK_API_KEY — then restart. '
|
|
55
|
+
+ 'The plugin never stores a key.',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'unknown-model',
|
|
59
|
+
test: /unknown model|model .*not found|no such model|unsupported model|invalid model|model .*does not exist/i,
|
|
60
|
+
summary: 'the model or provider route named in the config does not exist in this profile',
|
|
61
|
+
hint: 'check childProvider and childModel against the routes in the profile config; the default route is '
|
|
62
|
+
+ 'deepseek-official/deepseek-flash. Remove the override to inherit the session\'s model.',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'auth',
|
|
66
|
+
test: /\b401\b|\b403\b|unauthori[sz]ed|invalid api key|incorrect api key|authentication failed|invalid_api_key/i,
|
|
67
|
+
summary: 'the model provider rejected the API key',
|
|
68
|
+
hint: 'the key is read from the environment variable of the route the profile uses (DEEPSEEK_API_KEY for the '
|
|
69
|
+
+ 'default deepseek-official route; DASHSCOPE_API_KEY only if you added a DashScope route). Set it in the '
|
|
70
|
+
+ 'environment that starts the host, then restart. The key is never stored in the plugin config.',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'context',
|
|
74
|
+
test: /context length|context window|too many tokens|maximum context|token limit/i,
|
|
75
|
+
summary: 'the model refused the request because the prompt is too long',
|
|
76
|
+
hint: 'lower maxSubtasks so each worker prompt is smaller, or configure a model with a larger context window.',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'network',
|
|
80
|
+
test: /fetch failed|econnrefused|econnreset|etimedout|enotfound|eai_again|socket hang up|network error|\b50[234]\b/i,
|
|
81
|
+
summary: 'the model provider could not be reached',
|
|
82
|
+
hint: 'check network or proxy access to the provider. The subtask was retried; superagent_resume will retry it again '
|
|
83
|
+
+ 'without re-running the subtasks that already finished.',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'filesystem',
|
|
87
|
+
test: /\bEPERM\b|\bEACCES\b|\bEBUSY\b|\bENOSPC\b|\bENOENT\b|\bENOTDIR\b|no space left|read-only file system|permission denied|state directory/i,
|
|
88
|
+
summary: 'the plugin could not read or write its state directory',
|
|
89
|
+
hint: 'make sure stateDir (default $DSH_HOME/state/superagent) exists and is writable by the user running the host. '
|
|
90
|
+
+ 'If DSH_HOME points somewhere that disappeared, fix it and restart; runs in the old directory are not lost, '
|
|
91
|
+
+ 'point the same stateDir at them to read them. On Windows, antivirus and synced folders such as OneDrive can lock these files.',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'host-api',
|
|
95
|
+
test: /reading 'maxDepth'|reading "maxDepth"|cannot read properties of undefined|is not a function|startActivation/i,
|
|
96
|
+
summary: 'the harness API did not match what this plugin expects, so the child agent could not be created',
|
|
97
|
+
hint: 'check that the harness version satisfies the plugin engines field (dsh >=0.2.2-rc.1 <0.3.0). '
|
|
98
|
+
+ 'This is a version mismatch, not a problem with the goal.',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'child-guard',
|
|
102
|
+
test: /cannot enforce maxsubagentdepth|does not support independent agent presets|childpreset .* cannot be applied/i,
|
|
103
|
+
summary: 'the configured child-agent guard cannot be enforced by this subagent provider',
|
|
104
|
+
hint: 'keep provider: spawn (it supports maxDepth and presets), or set maxSubagentDepth: provider-managed and put the '
|
|
105
|
+
+ 'tool restriction in a preset named by childPreset.',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: 'run-owned',
|
|
109
|
+
test: /already being started by|still owned by a live process|still active in this process/i,
|
|
110
|
+
summary: 'another live process already owns this run',
|
|
111
|
+
hint: 'two profiles can share one state directory, and only one process may run a given run. Read it with '
|
|
112
|
+
+ 'superagent_status, cancel it with superagent_cancel, or wait for it to finish.',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 'no-goal',
|
|
116
|
+
test: /goal is required/i,
|
|
117
|
+
summary: 'superagent_start was called without a goal',
|
|
118
|
+
hint: 'pass a concrete goal string, for example "compare X and Y and return a table of prices".',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 'no-session',
|
|
122
|
+
test: /session_id is required|session .* is not open in this host/i,
|
|
123
|
+
summary: 'the request did not name a live session that can own the run',
|
|
124
|
+
hint: 'pass session_id of a session that is open in the host process running the control plane; '
|
|
125
|
+
+ 'a run needs a live parent agent to create its child agents. Read the discovery file for the URL and token.',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 'no-agent',
|
|
129
|
+
test: /no live agent|live parent agent/i,
|
|
130
|
+
summary: 'the tool was called outside a live session',
|
|
131
|
+
hint: 'start runs from an interactive session; a run needs a parent agent to own its children.',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: 'no-subagents',
|
|
135
|
+
test: /subagent service is unavailable/i,
|
|
136
|
+
summary: 'this profile has no subagent service, so the plugin cannot spawn workers',
|
|
137
|
+
hint: 'enable the subagents service in the profile or use a bundle that includes it.',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: 'recursion',
|
|
141
|
+
test: /^refused:/i,
|
|
142
|
+
summary: 'a superagent worker tried to start, resume, or cancel a run, which is blocked',
|
|
143
|
+
hint: 'workers must finish their own subtask; only the top-level agent manages runs.',
|
|
144
|
+
},
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
function rawOf(input) {
|
|
148
|
+
if (input === null || input === undefined) return ''
|
|
149
|
+
const text = typeof input === 'string' ? input : input.message ?? String(input)
|
|
150
|
+
return String(text).trim()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function shorten(text, limit) {
|
|
154
|
+
if (text.length <= limit) return text
|
|
155
|
+
return `${text.slice(0, limit - 1).trimEnd()}…`
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Classify one error message.
|
|
160
|
+
* @param {unknown} input - Error, message, or diagnostic string.
|
|
161
|
+
* @returns {{ id: string, summary: string, hint: string, detail: string }}
|
|
162
|
+
*/
|
|
163
|
+
export function classifyError(input) {
|
|
164
|
+
const detail = rawOf(input) || 'unknown error'
|
|
165
|
+
for (const rule of RULES) {
|
|
166
|
+
if (rule.test.test(detail)) return { id: rule.id, summary: rule.summary, hint: rule.hint, detail }
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
id: 'unclassified',
|
|
170
|
+
summary: shorten(detail, 300),
|
|
171
|
+
hint: 'this is the untouched message from the host. If it is not actionable, call superagent_list to check '
|
|
172
|
+
+ 'state, then retry once; the failure is recorded, so superagent_resume will retry only the failed subtasks.',
|
|
173
|
+
detail,
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* One-line form used inside run listings and subtask rows.
|
|
179
|
+
* @param {unknown} input - Error, message, or diagnostic string.
|
|
180
|
+
* @returns {string} summary sentence.
|
|
181
|
+
*/
|
|
182
|
+
export function summarizeError(input) {
|
|
183
|
+
const { summary } = classifyError(input)
|
|
184
|
+
return summary.endsWith('.') ? summary.slice(0, -1) : summary
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Full form used as a tool result.
|
|
189
|
+
* @param {unknown} input - Error, message, or diagnostic string.
|
|
190
|
+
* @returns {string} `[error]` block with hint and untouched detail.
|
|
191
|
+
*/
|
|
192
|
+
export function describeError(input) {
|
|
193
|
+
const { summary, hint, detail } = classifyError(input)
|
|
194
|
+
return [
|
|
195
|
+
`[error] ${summary}`,
|
|
196
|
+
`hint: ${hint}`,
|
|
197
|
+
`detail: ${detail}`,
|
|
198
|
+
].join('\n')
|
|
199
|
+
}
|