dsh-seal-scripts 0.4.11 → 0.4.12
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/core/schema-tools.js +14 -0
- package/lib/core/schema.js +35 -8
- package/package.json +1 -1
package/lib/core/schema-tools.js
CHANGED
|
@@ -434,6 +434,7 @@ export function buildToolCreateWriteDefinition({ dshHome, logger }) {
|
|
|
434
434
|
'- Copy what ran, do not invent it. Seal only what repeats: the whole repeated chain, not only its tail.',
|
|
435
435
|
'- Fixed parts into scripts; per-run choices into params argv; secrets never into a script, read at run time.',
|
|
436
436
|
'- Keep scripts quiet: one conclusion line, the platform error text on failure.',
|
|
437
|
+
'- Exit code is the verdict: a failing script must exit non-zero.',
|
|
437
438
|
'Pass only a script that already ran clean, never a draft: retries re-send the whole context.',
|
|
438
439
|
'Installs immediately.'
|
|
439
440
|
].join(' '),
|
|
@@ -817,6 +818,19 @@ export function buildToolCallToolDefinition({ dshHome, logger }) {
|
|
|
817
818
|
if (!ok && !background && stopOnError) stopped = true
|
|
818
819
|
}
|
|
819
820
|
|
|
821
|
+
// 0.4.12:脚本自己跑失败(非零退出码)也算失败——整次调用抛错(红)。
|
|
822
|
+
// 但输出一个字都不丢:异常正文里带上每条的 ✔/✗、exit code、stdout、stderr。
|
|
823
|
+
// 「超时转后台」不算失败:那是还没跑完,pid 与日志路径照常回传。
|
|
824
|
+
const crashed = runs.filter((r) => r.status === 'fail')
|
|
825
|
+
if (crashed.length > 0) {
|
|
826
|
+
const names = crashed.map((r) => r.toolScript + ' / ' + r.step +
|
|
827
|
+
'(exit ' + (r.exitCode === null ? 'null' : r.exitCode) + (r.timedOut ? ',超时被终止' : '') + ')').join('、')
|
|
828
|
+
throw new Error(
|
|
829
|
+
'【这次调用没成功】' + crashed.length + ' 条没跑成:' + names + '\n\n' +
|
|
830
|
+
renderRuns({ runs, dryRun: false, skipped })
|
|
831
|
+
)
|
|
832
|
+
}
|
|
833
|
+
|
|
820
834
|
const failed = runs.filter((r) => r.status === 'fail' || r.status === 'error').length
|
|
821
835
|
const background = runs.filter((r) => r.status === 'background').length
|
|
822
836
|
return jsonSafe({
|
package/lib/core/schema.js
CHANGED
|
@@ -183,15 +183,41 @@ export function readIndexSync(dshHome) {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* 严格读索引:**文件在但读不出来 / 解析不了就抛错**,不再静默当成「一个工具都没装」。
|
|
188
|
+
*
|
|
189
|
+
* 区分两件事:文件不存在 = 还没装过(空索引,正常);文件在却坏了 = 坏(抛)。
|
|
190
|
+
* 只有名单路径用严格版(用户/模型点开名单时该看见「索引坏了」);系统提示词那条同步路径
|
|
191
|
+
* 仍用宽松版 readIndexSync —— 索引坏了不能让整场会话装配崩掉。
|
|
192
|
+
* @param {string} dshHome
|
|
193
|
+
* @returns {Promise<{version:number, toolScripts:Record<string, object>}>}
|
|
194
|
+
*/
|
|
195
|
+
export async function readIndexStrict(dshHome) {
|
|
196
|
+
const file = indexPath(dshHome)
|
|
197
|
+
let raw
|
|
198
|
+
try {
|
|
199
|
+
raw = await fsp.readFile(file, 'utf8')
|
|
200
|
+
} catch (err) {
|
|
201
|
+
if (err && err.code === 'ENOENT') return { version: INDEX_VERSION, toolScripts: {} }
|
|
202
|
+
throw new Error('工具组索引读不出来:' + file + '(' + (err?.message ?? err) + ')')
|
|
203
|
+
}
|
|
204
|
+
let parsed
|
|
205
|
+
try {
|
|
206
|
+
parsed = JSON.parse(raw)
|
|
207
|
+
} catch {
|
|
208
|
+
throw new Error('工具组索引坏了(不是合法 JSON):' + file + '。' +
|
|
209
|
+
'它不是手改的文件——把它删掉,再重装任意一个工具脚本即可重建。')
|
|
210
|
+
}
|
|
211
|
+
if (!parsed || typeof parsed !== 'object' || !parsed.toolScripts || typeof parsed.toolScripts !== 'object') {
|
|
212
|
+
throw new Error('工具组索引格式不对(缺 toolScripts):' + file + '。删掉它,再重装任意一个工具脚本即可重建。')
|
|
213
|
+
}
|
|
214
|
+
return { version: parsed.version ?? INDEX_VERSION, toolScripts: parsed.toolScripts }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** 宽松读索引(安装/导出等路径用):坏了就当空,绝不抛。严格版见 readIndexStrict。 */
|
|
187
218
|
export async function readIndex(dshHome) {
|
|
188
219
|
try {
|
|
189
|
-
|
|
190
|
-
const parsed = JSON.parse(raw)
|
|
191
|
-
if (!parsed || typeof parsed !== 'object' || !parsed.toolScripts || typeof parsed.toolScripts !== 'object') {
|
|
192
|
-
return { version: INDEX_VERSION, toolScripts: {} }
|
|
193
|
-
}
|
|
194
|
-
return { version: parsed.version ?? INDEX_VERSION, toolScripts: parsed.toolScripts }
|
|
220
|
+
return await readIndexStrict(dshHome)
|
|
195
221
|
} catch {
|
|
196
222
|
return { version: INDEX_VERSION, toolScripts: {} }
|
|
197
223
|
}
|
|
@@ -226,7 +252,8 @@ export async function writeIndex(dshHome, index) {
|
|
|
226
252
|
* @returns {Promise<Array<{id:string,title:string,purpose:string,entry:string,params:string[],steps:string[]}>>}
|
|
227
253
|
*/
|
|
228
254
|
export async function listToolScripts(dshHome) {
|
|
229
|
-
|
|
255
|
+
// 0.4.12:名单是用户/模型看得见的那一屏——索引坏了必须报红,不能显示成「工具组还是空的」。
|
|
256
|
+
const { toolScripts } = await readIndexStrict(dshHome)
|
|
230
257
|
const out = []
|
|
231
258
|
for (const [id, meta] of Object.entries(toolScripts)) {
|
|
232
259
|
if (!meta || typeof meta !== 'object') continue
|