dsh-seal-scripts 0.5.1 → 0.6.0
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/README.en.md +185 -165
- package/README.md +179 -184
- package/lib/client.js +818 -7
- package/lib/core/assembly.js +8 -8
- package/lib/core/host-limits.js +5 -5
- package/lib/core/index.js +38 -31
- package/lib/core/inject.js +1 -1
- package/lib/core/lang.js +418 -75
- package/lib/core/locale.js +1 -1
- package/lib/core/memory-file.js +2 -5
- package/lib/core/migrate.js +1 -1
- package/lib/core/path-guard.js +4 -4
- package/lib/core/schema-runner.js +10 -10
- package/lib/core/schema-tools.js +88 -88
- package/lib/core/schema.js +49 -61
- package/lib/core/search.js +1 -1
- package/lib/core/settings.js +1 -1
- package/lib/core/store.js +1 -1
- package/lib/core/tool-transfer.js +14 -14
- package/lib/core/tool.js +71 -71
- package/lib/core/zip.js +35 -35
- package/lib/core/zstd-js.js +50 -50
- package/lib/core/zstd.js +1 -1
- package/lib/host/capabilities.js +3 -3
- package/lib/host/compact-delete.js +191 -27
- package/lib/host/delete.js +48 -20
- package/lib/host/host-contract.js +2 -2
- package/lib/host/http-util.js +1 -1
- package/lib/host/lifecycle.js +2 -2
- package/lib/host/register.js +3 -3
- package/lib/host/routes/memories.js +7 -7
- package/lib/host/routes/sessions.js +8 -8
- package/lib/host/routes/tools.js +6 -6
- package/package.json +4 -3
package/lib/core/schema.js
CHANGED
|
@@ -20,6 +20,7 @@ import fsp from 'node:fs/promises'
|
|
|
20
20
|
import path from 'node:path'
|
|
21
21
|
import crypto from 'node:crypto'
|
|
22
22
|
import { DSH_DEFAULTS } from './host-limits.js'
|
|
23
|
+
import { catalogPhrases } from './lang.js'
|
|
23
24
|
|
|
24
25
|
/** 工具组目录名(在记忆根下,和 session-memory/<工作区 key>/ 平级)。 */
|
|
25
26
|
export const TOOL_SEQUENCE_DIR = 'toolSequence'
|
|
@@ -51,7 +52,7 @@ export const RUN_EXT = {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/** 执行方式的中文名(报错与 README 用)。 */
|
|
54
|
-
export const RUN_LABEL = { bash: 'bash
|
|
55
|
+
export const RUN_LABEL = { bash: 'bash script', node: 'node script', ps1: 'PowerShell script', cmd: 'batch file' }
|
|
55
56
|
|
|
56
57
|
/*
|
|
57
58
|
* 0.4.11:单脚本 64 KB、整包 512 KB、清单 24 行 / 1600 字这四个死数全部删掉。
|
|
@@ -110,7 +111,7 @@ export function runsDir(dshHome) {
|
|
|
110
111
|
export function assertToolScriptId(id) {
|
|
111
112
|
const s = String(id ?? '').trim()
|
|
112
113
|
if (!BUNDLE_ID_RE.test(s)) {
|
|
113
|
-
throw new Error('toolScript.id
|
|
114
|
+
throw new Error('toolScript.id must be a short lowercase name starting with a letter (a-z 0-9 - only; no paths, no leading dot): ' + (s || '(empty)'))
|
|
114
115
|
}
|
|
115
116
|
return s
|
|
116
117
|
}
|
|
@@ -122,7 +123,7 @@ export function assertToolScriptId(id) {
|
|
|
122
123
|
*/
|
|
123
124
|
export function assertFileName(name) {
|
|
124
125
|
const s = String(name ?? '').trim()
|
|
125
|
-
if (!FILE_NAME_RE.test(s)) throw new Error('
|
|
126
|
+
if (!FILE_NAME_RE.test(s)) throw new Error('invalid script file name (letters, digits, . _ - only; no paths): ' + (s || '(empty)'))
|
|
126
127
|
return s
|
|
127
128
|
}
|
|
128
129
|
|
|
@@ -133,11 +134,11 @@ export function assertFileName(name) {
|
|
|
133
134
|
* @returns {string}
|
|
134
135
|
*/
|
|
135
136
|
export function assertRunMatches(name, run) {
|
|
136
|
-
if (!RUN_EXT[run]) throw new Error('run
|
|
137
|
+
if (!RUN_EXT[run]) throw new Error('run accepts only bash / node / ps1 / cmd: ' + String(run))
|
|
137
138
|
const ext = path.extname(name).toLowerCase()
|
|
138
139
|
if (!RUN_EXT[run].includes(ext)) {
|
|
139
|
-
throw new Error(name + '
|
|
140
|
-
'
|
|
140
|
+
throw new Error(name + ' has extension ' + (ext || '(none)') + ', which does not match run=' + run +
|
|
141
|
+
'; expected ' + RUN_EXT[run].join(' / '))
|
|
141
142
|
}
|
|
142
143
|
return run
|
|
143
144
|
}
|
|
@@ -155,12 +156,12 @@ export function sha256OfFile(file) {
|
|
|
155
156
|
*/
|
|
156
157
|
export function resolveInside(dir, rel) {
|
|
157
158
|
const raw = String(rel ?? '').trim()
|
|
158
|
-
if (raw === '') throw new Error('
|
|
159
|
+
if (raw === '') throw new Error('file name is empty')
|
|
159
160
|
const base = path.resolve(dir)
|
|
160
161
|
const abs = path.resolve(base, raw)
|
|
161
162
|
const r = path.relative(base, abs)
|
|
162
163
|
if (r === '' || r.startsWith('..') || path.isAbsolute(r)) {
|
|
163
|
-
throw new Error('
|
|
164
|
+
throw new Error('only files inside this toolScript directory can be touched: ' + raw)
|
|
164
165
|
}
|
|
165
166
|
return abs
|
|
166
167
|
}
|
|
@@ -199,17 +200,17 @@ export async function readIndexStrict(dshHome) {
|
|
|
199
200
|
raw = await fsp.readFile(file, 'utf8')
|
|
200
201
|
} catch (err) {
|
|
201
202
|
if (err && err.code === 'ENOENT') return { version: INDEX_VERSION, toolScripts: {} }
|
|
202
|
-
throw new Error('
|
|
203
|
+
throw new Error('cannot read the toolSequence index: ' + file + ' (' + (err?.message ?? err) + ')')
|
|
203
204
|
}
|
|
204
205
|
let parsed
|
|
205
206
|
try {
|
|
206
207
|
parsed = JSON.parse(raw)
|
|
207
208
|
} catch {
|
|
208
|
-
throw new Error('
|
|
209
|
-
'
|
|
209
|
+
throw new Error('the toolSequence index is broken (not valid JSON): ' + file + '. ' +
|
|
210
|
+
'It is not meant to be hand-edited — delete it and reinstall any toolScript to rebuild it.')
|
|
210
211
|
}
|
|
211
212
|
if (!parsed || typeof parsed !== 'object' || !parsed.toolScripts || typeof parsed.toolScripts !== 'object') {
|
|
212
|
-
throw new Error('
|
|
213
|
+
throw new Error('the toolSequence index has the wrong shape (missing toolScripts): ' + file + '. Delete it and reinstall any toolScript to rebuild it.')
|
|
213
214
|
}
|
|
214
215
|
return { version: parsed.version ?? INDEX_VERSION, toolScripts: parsed.toolScripts }
|
|
215
216
|
}
|
|
@@ -282,11 +283,11 @@ export async function loadToolScript(dshHome, id) {
|
|
|
282
283
|
try {
|
|
283
284
|
raw = await fsp.readFile(path.join(dir, TOOL_SCRIPT_FILE), 'utf8')
|
|
284
285
|
} catch {
|
|
285
|
-
throw new Error('
|
|
286
|
+
throw new Error('no such toolScript: ' + clean + ' (call session_tool_call with no arguments to list installed ones)')
|
|
286
287
|
}
|
|
287
288
|
let manifest
|
|
288
|
-
try { manifest = JSON.parse(raw) } catch { throw new Error('
|
|
289
|
-
if (!manifest || typeof manifest !== 'object') throw new Error('
|
|
289
|
+
try { manifest = JSON.parse(raw) } catch { throw new Error('this toolScript\'s toolScript.json is broken: ' + clean) }
|
|
290
|
+
if (!manifest || typeof manifest !== 'object') throw new Error('this toolScript\'s toolScript.json is not an object: ' + clean)
|
|
290
291
|
return { manifest, dir }
|
|
291
292
|
}
|
|
292
293
|
|
|
@@ -296,47 +297,47 @@ export async function loadToolScript(dshHome, id) {
|
|
|
296
297
|
* @returns {object} 规范化后的工具脚本规格
|
|
297
298
|
*/
|
|
298
299
|
export function normalizeToolScript(spec) {
|
|
299
|
-
if (spec === null || typeof spec !== 'object' || Array.isArray(spec)) throw new Error('toolScript
|
|
300
|
+
if (spec === null || typeof spec !== 'object' || Array.isArray(spec)) throw new Error('toolScript must be an object')
|
|
300
301
|
const id = assertToolScriptId(spec.id)
|
|
301
302
|
const title = String(spec.title ?? '').trim()
|
|
302
|
-
if (title === '') throw new Error('toolScript.title
|
|
303
|
+
if (title === '') throw new Error('toolScript.title must not be empty: one line saying what this toolScript is called')
|
|
303
304
|
const purpose = String(spec.purpose ?? '').trim()
|
|
304
|
-
if (purpose === '') throw new Error('toolScript.purpose
|
|
305
|
+
if (purpose === '') throw new Error('toolScript.purpose must not be empty: one line saying what this toolScript does')
|
|
305
306
|
|
|
306
307
|
const scriptsIn = Array.isArray(spec.scripts) ? spec.scripts : []
|
|
307
308
|
const docsIn = Array.isArray(spec.docs) ? spec.docs : []
|
|
308
|
-
if (scriptsIn.length === 0) throw new Error('toolScript.scripts
|
|
309
|
+
if (scriptsIn.length === 0) throw new Error('toolScript.scripts must not be empty: at least one runnable script is required')
|
|
309
310
|
|
|
310
311
|
const seen = new Set()
|
|
311
312
|
const scripts = scriptsIn.map((s, i) => {
|
|
312
|
-
if (s === null || typeof s !== 'object' || Array.isArray(s)) throw new Error('scripts[' + i + ']
|
|
313
|
+
if (s === null || typeof s !== 'object' || Array.isArray(s)) throw new Error('scripts[' + i + '] must be an object')
|
|
313
314
|
const name = assertFileName(s.name)
|
|
314
315
|
const run = assertRunMatches(name, s.run)
|
|
315
316
|
const content = String(s.content ?? '')
|
|
316
|
-
if (content.trim() === '') throw new Error(name + '
|
|
317
|
-
if (content.includes('<!--ovr:')) throw new Error(name + '
|
|
318
|
-
if (seen.has(name)) throw new Error('
|
|
317
|
+
if (content.trim() === '') throw new Error(name + ' has empty content')
|
|
318
|
+
if (content.includes('<!--ovr:')) throw new Error(name + ' contains the review section marker <!--ovr:, which would corrupt parsing; remove it')
|
|
319
|
+
if (seen.has(name)) throw new Error('the same script name appears twice: ' + name)
|
|
319
320
|
seen.add(name)
|
|
320
321
|
return { name, run, content, params: Array.isArray(s.params) ? s.params.map(String) : [] }
|
|
321
322
|
})
|
|
322
323
|
const docSeen = new Set()
|
|
323
324
|
const docs = docsIn.map((d, i) => {
|
|
324
|
-
if (d === null || typeof d !== 'object' || Array.isArray(d)) throw new Error('docs[' + i + ']
|
|
325
|
+
if (d === null || typeof d !== 'object' || Array.isArray(d)) throw new Error('docs[' + i + '] must be an object')
|
|
325
326
|
const name = assertFileName(d.name)
|
|
326
|
-
if (path.extname(name).toLowerCase() !== '.md') throw new Error(name + '
|
|
327
|
+
if (path.extname(name).toLowerCase() !== '.md') throw new Error(name + ' is a notes file; its extension must be .md')
|
|
327
328
|
if (name.toLowerCase() === 'readme.md') {
|
|
328
|
-
throw new Error(name + '
|
|
329
|
+
throw new Error(name + ' collides with the README.md generated on install and would be silently overwritten; pick another name (for example ' + (i === 0 ? 'notes.md' : 'notes-' + i + '.md') + ')')
|
|
329
330
|
}
|
|
330
|
-
if (docSeen.has(name)) throw new Error('docs
|
|
331
|
+
if (docSeen.has(name)) throw new Error('the same name appears twice in docs: ' + name + ' (the second would overwrite the first)')
|
|
331
332
|
docSeen.add(name)
|
|
332
333
|
const content = String(d.content ?? '')
|
|
333
|
-
if (content.trim() === '') throw new Error(name + '
|
|
334
|
+
if (content.trim() === '') throw new Error(name + ' has empty content')
|
|
334
335
|
return { name, content }
|
|
335
336
|
})
|
|
336
337
|
const entry = assertFileName(spec.entry ?? scripts[0].name)
|
|
337
|
-
if (!seen.has(entry)) throw new Error('toolScript.entry
|
|
338
|
+
if (!seen.has(entry)) throw new Error('toolScript.entry must be one of the files in scripts: ' + entry)
|
|
338
339
|
const steps = (Array.isArray(spec.steps) ? spec.steps : []).map((s) => assertFileName(s))
|
|
339
|
-
for (const s of steps) if (!seen.has(s)) throw new Error('toolScript.steps
|
|
340
|
+
for (const s of steps) if (!seen.has(s)) throw new Error('toolScript.steps lists ' + s + ', which is not in scripts')
|
|
340
341
|
|
|
341
342
|
// 0.4.11:清单里的超时只收正数,天花板交给宿主的 maxTimeoutMs(运行时夹,见 host-limits.js)。
|
|
342
343
|
// 装工具脚本这一步不该依赖终端设置读没读到,所以这里既不夹、也不比宿主更严。
|
|
@@ -344,7 +345,7 @@ export function normalizeToolScript(spec) {
|
|
|
344
345
|
// 以前这里写死 DSH_DEFAULTS.timeoutMs(120000),会让设置页改的超时对新封存的工具不生效。
|
|
345
346
|
const timeoutMs = spec.timeoutMs === undefined ? undefined : Number(spec.timeoutMs)
|
|
346
347
|
if (timeoutMs !== undefined && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) {
|
|
347
|
-
throw new Error('toolScript.timeoutMs
|
|
348
|
+
throw new Error('toolScript.timeoutMs must be a positive number (ms); at run time it is also clamped to DSH\'s maxTimeoutMs')
|
|
348
349
|
}
|
|
349
350
|
|
|
350
351
|
const provenance = spec.provenance && typeof spec.provenance === 'object'
|
|
@@ -373,18 +374,18 @@ export function renderToolScriptReadme(manifest) {
|
|
|
373
374
|
'',
|
|
374
375
|
manifest.purpose,
|
|
375
376
|
'',
|
|
376
|
-
'-
|
|
377
|
-
...(manifest.params.length > 0 ? ['-
|
|
378
|
-
...(manifest.steps.length > 0 ? ['-
|
|
379
|
-
...(manifest.provenance.memory ? ['-
|
|
380
|
-
'-
|
|
377
|
+
'- entry: ' + manifest.entry,
|
|
378
|
+
...(manifest.params.length > 0 ? ['- args: ' + manifest.params.join(', ')] : []),
|
|
379
|
+
...(manifest.steps.length > 0 ? ['- steps: ' + manifest.steps.join(' → ')] : []),
|
|
380
|
+
...(manifest.provenance.memory ? ['- provenance: ' + manifest.provenance.memory + (manifest.provenance.line ? (' line ' + manifest.provenance.line) : '')] : []),
|
|
381
|
+
'- verified: ' + (manifest.verified && manifest.verified.at ? (manifest.verified.at + ' exit ' + manifest.verified.exitCode) : 'not run yet'),
|
|
381
382
|
'',
|
|
382
|
-
'##
|
|
383
|
+
'## Files',
|
|
383
384
|
''
|
|
384
385
|
]
|
|
385
386
|
for (const s of manifest.scripts) lines.push('- ' + s.name + '(' + RUN_LABEL[s.run] + ')')
|
|
386
|
-
for (const d of manifest.docs) lines.push('- ' + d.name + '
|
|
387
|
-
lines.push('', '
|
|
387
|
+
for (const d of manifest.docs) lines.push('- ' + d.name + ' (notes, never executed)')
|
|
388
|
+
lines.push('', 'Run it with session_tool_call: pass toolScript "' + manifest.id + '"; add dryRun: true to see the argv first.')
|
|
388
389
|
return lines.join('\n') + '\n'
|
|
389
390
|
}
|
|
390
391
|
|
|
@@ -402,8 +403,8 @@ export async function installToolScript({ dshHome, spec, replace = false }) {
|
|
|
402
403
|
if (exists && !replace) {
|
|
403
404
|
const abs = path.join(dir, TOOL_SCRIPT_FILE)
|
|
404
405
|
const sha = fs.existsSync(abs) ? sha256OfFile(abs) : ''
|
|
405
|
-
throw new Error('
|
|
406
|
-
'
|
|
406
|
+
throw new Error('this toolScript is already installed: ' + manifest.id + ' (' + dir + (sha ? ', manifest sha256 ' + sha.slice(0, 12) : '') +
|
|
407
|
+
'); pass replace: true to reinstall, and the old directory is kept as .bak-<timestamp>')
|
|
407
408
|
}
|
|
408
409
|
|
|
409
410
|
const stage = path.join(root, manifest.id + '.tmp-' + process.pid + '-' + Math.random().toString(36).slice(2, 8))
|
|
@@ -470,35 +471,22 @@ export async function installToolScript({ dshHome, spec, replace = false }) {
|
|
|
470
471
|
* @returns {string}
|
|
471
472
|
*/
|
|
472
473
|
export function catalogText(dshHome, lang = 'zh') {
|
|
474
|
+
const P = catalogPhrases(lang)
|
|
473
475
|
const { toolScripts } = readIndexSync(dshHome)
|
|
474
476
|
const entries = Object.entries(toolScripts)
|
|
475
477
|
.filter(([, m]) => m && typeof m === 'object')
|
|
476
478
|
.sort((a, b) => String(a[0]).localeCompare(String(b[0])))
|
|
477
|
-
|
|
478
|
-
//
|
|
479
|
-
// 而不是某个工具的描述——0.3.6 的新句放进了 create_write 描述里,实测仍未被采纳。
|
|
480
|
-
const runHint = en ? 'Look before running: pass "dryRun": true to session_tool_call. ' : '跑之前想看命令,就给 session_tool_call 加 dryRun: true。'
|
|
481
|
-
const guide = en
|
|
482
|
-
? 'When the user asks to turn a working setup into a reusable procedure (summarize it into a toolScript / seal it as a workflow / do it this way next time), the artifact is a toolScript — the exact commands to run again, not a markdown note and not a skill that only states a method. Write it with session_tool_create_write: from the steps you just ran, from a recall original via session_tool_create_read, or from material already in the workspace. Call session_tool_create_write only with a script that already ran clean, never a draft; editing after installing re-sends the whole context.'
|
|
483
|
-
: '用户说「把那套总结成工具 / 封装成流程 / 以后照这个做」时,要的产物就是工具脚本——能直接跑的脚本,不是 md 笔记,也不是教方法的 skill。用 session_tool_create_write 写下来:命令来自刚跑通的步骤、经 session_tool_create_read 翻出的回顾原文,或工作区里现成的材料。调用 session_tool_create_write 之前,脚本必须已经跑通;写进去的就是跑通的那一份,不是装好再改的草稿。装完再改,等于把整段上下文重发一遍。'
|
|
479
|
+
// 「自创工具 = 工具脚本」的词表桥接(0.5.2:8 种语言各一套,见 lang.js 的 CATALOG)。
|
|
480
|
+
// 模型在决定「产物该是什么」时看的是这一段,而不是某个工具的描述。
|
|
484
481
|
// 空工具组也要留一句:否则模型根本不知道有写侧工具,更不会把工具脚本当成候选产物。
|
|
485
|
-
if (entries.length === 0)
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
const lines = []
|
|
489
|
-
lines.push(en
|
|
490
|
-
? '【ToolSequence · ' + entries.length + ' toolScript(s)】Whole scripts, sealed: the exact commands from paths that worked. Run them with session_tool_call — do not rewrite them, do not re-derive commands.'
|
|
491
|
-
: '【工具组 · ' + entries.length + ' 个工具脚本】已经固化好的脚本,直接用 session_tool_call 跑;不用自己写代码,也不用重新找命令。')
|
|
492
|
-
// 指引紧跟标题、排在工具脚本条目之前。
|
|
493
|
-
lines.push(runHint + guide)
|
|
482
|
+
if (entries.length === 0) return P.empty + P.guide
|
|
483
|
+
const lines = [P.header(entries.length), P.runHint + P.guide]
|
|
494
484
|
// 0.4.11:不再有「还有 N 个」和 78 字截断——多少条都列全,purpose 原样显示。
|
|
495
485
|
for (const [id, m] of entries) {
|
|
496
486
|
const title = String(m.title ?? id)
|
|
497
487
|
const purpose = String(m.purpose ?? '').replace(/\s+/g, ' ')
|
|
498
|
-
const params = Array.isArray(m.params) && m.params.length > 0 ? '|' +
|
|
499
|
-
lines.push(
|
|
500
|
-
? '· ' + id + ' (' + title + '): ' + purpose + '|entry ' + String(m.entry ?? '') + params
|
|
501
|
-
: '· ' + id + '(' + title + '):' + purpose + '|入口 ' + String(m.entry ?? '') + params)
|
|
488
|
+
const params = Array.isArray(m.params) && m.params.length > 0 ? '|' + P.args + m.params.join(' ') : ''
|
|
489
|
+
lines.push(P.entry(id, title, purpose, String(m.entry ?? ''), params))
|
|
502
490
|
}
|
|
503
491
|
return lines.join('\n')
|
|
504
492
|
}
|
package/lib/core/search.js
CHANGED
|
@@ -160,7 +160,7 @@ const LEVEL_RANK = { keywords: 0, sum: 1, body: 2 }
|
|
|
160
160
|
*/
|
|
161
161
|
export function termsOf(need) {
|
|
162
162
|
const raw = String(need === undefined || need === null ? '' : need).trim()
|
|
163
|
-
if (raw === '') throw new Error('need
|
|
163
|
+
if (raw === '') throw new Error('need must not be empty')
|
|
164
164
|
const out = new Set([raw.toLowerCase()])
|
|
165
165
|
for (const part of raw.split(/[\s,,。、;;::!!??()()【】\[\]"'“”‘’·…\-—_/\\|]+/)) {
|
|
166
166
|
const t = part.trim().toLowerCase()
|
package/lib/core/settings.js
CHANGED
|
@@ -149,7 +149,7 @@ export function readOptionsSync(dshHome) {
|
|
|
149
149
|
* @returns {Promise<object>} 落盘后的生效选项
|
|
150
150
|
*/
|
|
151
151
|
export async function writeOptions(dshHome, patch) {
|
|
152
|
-
if (typeof dshHome !== 'string' || dshHome.trim() === '') throw new Error('
|
|
152
|
+
if (typeof dshHome !== 'string' || dshHome.trim() === '') throw new Error('no dshHome, cannot write options')
|
|
153
153
|
const merged = { ...readStoredSync(dshHome), ...(patch !== null && typeof patch === 'object' ? patch : {}) }
|
|
154
154
|
const next = normalizeOptions(merged)
|
|
155
155
|
await fsPromises.mkdir(path.dirname(optionsPath(dshHome)), { recursive: true })
|
package/lib/core/store.js
CHANGED
|
@@ -360,7 +360,7 @@ export async function captureCompaction({ dshHome, cwd, session, event, lang = '
|
|
|
360
360
|
|
|
361
361
|
// 一条新内容都不剩:不写空壳文件,也不往载入文件里加条目。
|
|
362
362
|
if (cut > 0 && keptSpans.every((sp) => sp.count === 0)) {
|
|
363
|
-
const why = branchFrom === null ? '
|
|
363
|
+
const why = branchFrom === null ? 'content already recorded' : ('content up to ' + branchFrom.file + ' line ' + branchFrom.line + ' is already recorded')
|
|
364
364
|
return { file: null, dir, skipped: true, reason: why, branchFrom, covered: cut, bytes: 0 }
|
|
365
365
|
}
|
|
366
366
|
|
|
@@ -79,12 +79,12 @@ async function collect(dir, prefix, out) {
|
|
|
79
79
|
*/
|
|
80
80
|
export async function exportToolSequence({ dshHome, dir }) {
|
|
81
81
|
const target = String(dir === undefined || dir === null ? '' : dir).trim()
|
|
82
|
-
if (target === '') throw new Error('
|
|
83
|
-
if (!path.isAbsolute(target)) throw new Error('
|
|
82
|
+
if (target === '') throw new Error('no target workspace folder given for the export')
|
|
83
|
+
if (!path.isAbsolute(target)) throw new Error('the workspace directory must be an absolute path: ' + target)
|
|
84
84
|
let st
|
|
85
|
-
try { st = await fsp.stat(target) } catch { throw new Error('
|
|
86
|
-
if (!st.isDirectory()) throw new Error('
|
|
87
|
-
if (path.parse(target).root === target) throw new Error('
|
|
85
|
+
try { st = await fsp.stat(target) } catch { throw new Error('workspace directory does not exist: ' + target) }
|
|
86
|
+
if (!st.isDirectory()) throw new Error('not a directory: ' + target)
|
|
87
|
+
if (path.parse(target).root === target) throw new Error('refusing to write into a drive root: ' + target)
|
|
88
88
|
|
|
89
89
|
const root = toolSequenceRoot(dshHome)
|
|
90
90
|
const entries = []
|
|
@@ -173,12 +173,12 @@ function planEntry(rawName) {
|
|
|
173
173
|
const parts = safe.split('/')
|
|
174
174
|
const top = parts[0]
|
|
175
175
|
if (parts.length === 1 && top === INDEX_FILE) {
|
|
176
|
-
return { skip: '
|
|
176
|
+
return { skip: 'the local index is rebuilt from the files on disk; _index.json inside the package is not trusted' }
|
|
177
177
|
}
|
|
178
|
-
if (parts.length < 2) return { skip: '
|
|
179
|
-
if (top === RUNS_DIR) return { skip: '
|
|
180
|
-
if (!BUNDLE_ID_RE.test(top)) return { skip: '
|
|
181
|
-
if (isTransientName(parts[1])) return { skip: '
|
|
178
|
+
if (parts.length < 2) return { skip: 'not inside any toolScript directory' }
|
|
179
|
+
if (top === RUNS_DIR) return { skip: 'run spill directory, not taken' }
|
|
180
|
+
if (!BUNDLE_ID_RE.test(top)) return { skip: 'directory name is not a valid toolScript id' }
|
|
181
|
+
if (isTransientName(parts[1])) return { skip: 'backup/temp directory, not taken' }
|
|
182
182
|
return { id: top, rel: parts.slice(1).join('/') }
|
|
183
183
|
}
|
|
184
184
|
|
|
@@ -229,8 +229,8 @@ export async function importToolSequence({ dshHome, buffer, file, dryRun = false
|
|
|
229
229
|
const probeDir = fs.existsSync(root) ? root : dshHome
|
|
230
230
|
const free = await freeBytesOf(probeDir)
|
|
231
231
|
if (free !== null && need + DISK_RESERVE_BYTES > free) {
|
|
232
|
-
throw new Error('
|
|
233
|
-
DISK_RESERVE_BYTES + '
|
|
232
|
+
throw new Error('not enough room: needs ' + need + ' bytes unpacked, disk has only ' + free + ' bytes free (reserve ' +
|
|
233
|
+
DISK_RESERVE_BYTES + ' bytes); free some space and import again')
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
const cut = wrapperPrefix(names)
|
|
@@ -280,7 +280,7 @@ export async function importToolSequence({ dshHome, buffer, file, dryRun = false
|
|
|
280
280
|
const target = path.join(stage, plan.rel)
|
|
281
281
|
const rel = path.relative(stage, target)
|
|
282
282
|
if (rel === '' || rel === '..' || rel.startsWith('..' + path.sep) || path.isAbsolute(rel)) {
|
|
283
|
-
throw new Error('
|
|
283
|
+
throw new Error('out-of-range path: ' + plan.rel)
|
|
284
284
|
}
|
|
285
285
|
await fsp.mkdir(path.dirname(target), { recursive: true })
|
|
286
286
|
await writeBody(target)
|
|
@@ -308,7 +308,7 @@ export async function importToolSequence({ dshHome, buffer, file, dryRun = false
|
|
|
308
308
|
if (imported.length === 0) {
|
|
309
309
|
const why = skipped.length > 0 ? ('(' + skipped.slice(0, 3).map((s) => s.name + ':' + s.reason).join(';') + ')') : ''
|
|
310
310
|
for (const stage of stages.values()) await fsp.rm(stage, { recursive: true, force: true }).catch(() => {})
|
|
311
|
-
throw new Error('
|
|
311
|
+
throw new Error('this package has no toolScript directories' + why)
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
if (dryRun === true) return { dryRun: true, imported, overwritten, skipped }
|