dsh-ppt 0.31.0 → 0.32.1
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 +20 -0
- package/README.en.md +2 -1
- package/README.md +2 -1
- package/docs/USAGE.en.md +1 -0
- package/docs/USAGE.md +1 -0
- package/docs/VALIDATION.md +4 -0
- package/lib/client.js +35 -198
- package/lib/execution.d.ts +7 -0
- package/lib/execution.js +21 -0
- package/lib/tools.js +30 -2
- package/lib/types.d.ts +17 -0
- package/lib/workbench.js +16 -5
- package/package.json +3 -3
- package/skills/dsh-ppt/SKILL.md +11 -5
- package/skills/dsh-ppt/package.json +1 -1
- package/skills/dsh-ppt/references/research-plan.md +133 -0
- package/skills/dsh-ppt/scripts/build-deck.mjs +23 -3
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +21 -3
- package/skills/dsh-ppt/scripts/deck-core.mjs +5 -0
- package/skills/dsh-ppt/scripts/deck-delivery.mjs +4 -0
- package/skills/dsh-ppt/scripts/deck-evidence.mjs +628 -0
- package/skills/dsh-ppt/scripts/deck-exemplars.mjs +15 -6
- package/skills/dsh-ppt/scripts/deck-store.mjs +18 -0
- package/skills/dsh-ppt/scripts/deck-taste.mjs +12 -7
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
* 把“自由设计 PPT”降维为“按标杆槽位精准填空”。
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { existsSync,
|
|
11
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
12
12
|
import { basename, extname, join, resolve } from 'node:path'
|
|
13
13
|
import { GITHUB_DISTILLED_EXEMPLARS, getExemplarFewShotSlides } from './deck-exemplars-corpus.mjs'
|
|
14
|
+
import { writeWorkspaceJson } from './deck-store.mjs'
|
|
14
15
|
|
|
15
16
|
export { GITHUB_DISTILLED_EXEMPLARS, getExemplarFewShotSlides }
|
|
16
17
|
|
|
@@ -252,11 +253,13 @@ export const CURATED_EXEMPLAR_IDS = Object.freeze(Object.keys(CURATED_EXEMPLARS)
|
|
|
252
253
|
/**
|
|
253
254
|
* 读取工作区 .dsh-ppt/exemplars.json 中通过真实优质 .pptx 吸收持久化的标杆范本。
|
|
254
255
|
*/
|
|
255
|
-
|
|
256
|
+
function readWorkspaceExemplars(cwd, strict = false) {
|
|
256
257
|
const filePath = resolve(cwd, EXEMPLAR_STORE_REL)
|
|
257
258
|
if (!existsSync(filePath)) return {}
|
|
258
259
|
try {
|
|
259
260
|
const raw = JSON.parse(readFileSync(filePath, 'utf8'))
|
|
261
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('Invalid exemplar store')
|
|
262
|
+
if (Object.hasOwn(raw, 'exemplars') && !Array.isArray(raw.exemplars)) throw new Error('Invalid exemplar entries')
|
|
260
263
|
const list = Array.isArray(raw?.exemplars) ? raw.exemplars : (raw && typeof raw === 'object' ? Object.values(raw) : [])
|
|
261
264
|
const map = {}
|
|
262
265
|
for (const item of list) {
|
|
@@ -264,11 +267,14 @@ export function loadWorkspaceExemplars(cwd = '.') {
|
|
|
264
267
|
map[String(item.id)] = item
|
|
265
268
|
}
|
|
266
269
|
return map
|
|
267
|
-
} catch {
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (strict) throw new Error('dsh-ppt:范本库格式无效或无法读取,已保留原文件,请备份并修复后重试', { cause: error })
|
|
268
272
|
return {}
|
|
269
273
|
}
|
|
270
274
|
}
|
|
271
275
|
|
|
276
|
+
export function loadWorkspaceExemplars(cwd = '.') { return readWorkspaceExemplars(cwd) }
|
|
277
|
+
|
|
272
278
|
/**
|
|
273
279
|
* 持久化单份吸收自外部优质 .pptx 的标杆范本至工作区 .dsh-ppt/exemplars.json。
|
|
274
280
|
*/
|
|
@@ -309,12 +315,11 @@ export function saveWorkspaceExemplar(cwd = '.', exemplar) {
|
|
|
309
315
|
savedAt: new Date().toISOString(),
|
|
310
316
|
}
|
|
311
317
|
|
|
312
|
-
const existing =
|
|
318
|
+
const existing = readWorkspaceExemplars(cwd, true)
|
|
313
319
|
existing[id] = normalized
|
|
314
320
|
const trimmed = Object.values(existing).slice(-MAX_WORKSPACE_EXEMPLARS)
|
|
315
321
|
const outPath = resolve(cwd, EXEMPLAR_STORE_REL)
|
|
316
|
-
|
|
317
|
-
writeFileSync(outPath, JSON.stringify({ schemaVersion: 1, exemplars: trimmed }, null, 2) + '\n', 'utf8')
|
|
322
|
+
writeWorkspaceJson(outPath, { schemaVersion: 1, exemplars: trimmed })
|
|
318
323
|
return { exemplar: normalized, path: outPath }
|
|
319
324
|
}
|
|
320
325
|
|
|
@@ -435,6 +440,7 @@ export function extractExemplarFromAbsorbed(absorbed, options = {}) {
|
|
|
435
440
|
* 批量扫描并吸收指定目录下的优质 .pptx 语料,统一写入 .dsh-ppt/exemplars.json 与 .dsh-ppt/taste-recipes.json。
|
|
436
441
|
*/
|
|
437
442
|
export async function ingestExemplarDirectory({ dirPath, cwd = '.', limit = 20, absorbFn, saveTasteFn, signal }) {
|
|
443
|
+
signal?.throwIfAborted()
|
|
438
444
|
if (!dirPath || typeof dirPath !== 'string') {
|
|
439
445
|
throw new Error('dsh-ppt:请提供包含 .pptx 文件的目录路径 dirPath')
|
|
440
446
|
}
|
|
@@ -451,9 +457,11 @@ export async function ingestExemplarDirectory({ dirPath, cwd = '.', limit = 20,
|
|
|
451
457
|
const absorbedList = []
|
|
452
458
|
const failed = []
|
|
453
459
|
for (const file of files) {
|
|
460
|
+
signal?.throwIfAborted()
|
|
454
461
|
const fullPath = join(absDir, file)
|
|
455
462
|
try {
|
|
456
463
|
const absorbed = await absorbFn({ pptxPath: fullPath, cwd: absDir, extractLogo: true, signal })
|
|
464
|
+
signal?.throwIfAborted()
|
|
457
465
|
const exemplar = extractExemplarFromAbsorbed(absorbed)
|
|
458
466
|
const savedEx = saveWorkspaceExemplar(cwd, exemplar)
|
|
459
467
|
let tastePath = ''
|
|
@@ -473,6 +481,7 @@ export async function ingestExemplarDirectory({ dirPath, cwd = '.', limit = 20,
|
|
|
473
481
|
tastePath,
|
|
474
482
|
})
|
|
475
483
|
} catch (err) {
|
|
484
|
+
signal?.throwIfAborted()
|
|
476
485
|
failed.push({ file, error: err instanceof Error ? err.message : String(err) })
|
|
477
486
|
}
|
|
478
487
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Replace workspace metadata only after its complete new JSON is written. */
|
|
2
|
+
import { lstatSync, mkdirSync, writeFileSync, renameSync, unlinkSync } from 'node:fs'
|
|
3
|
+
import { dirname } from 'node:path'
|
|
4
|
+
import { randomUUID } from 'node:crypto'
|
|
5
|
+
|
|
6
|
+
export function writeWorkspaceJson(file, value) {
|
|
7
|
+
const existing = lstatSync(file, { throwIfNoEntry: false })
|
|
8
|
+
if (existing && (!existing.isFile() || existing.isSymbolicLink())) throw new Error('dsh-ppt:存储文件不是普通文件,已保留原文件')
|
|
9
|
+
const bytes = JSON.stringify(value, null, 2) + '\n'
|
|
10
|
+
const temporary = file + '.tmp-' + randomUUID()
|
|
11
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
12
|
+
try {
|
|
13
|
+
writeFileSync(temporary, bytes, { flag: 'wx', mode: 0o600 })
|
|
14
|
+
renameSync(temporary, file)
|
|
15
|
+
} finally {
|
|
16
|
+
try { unlinkSync(temporary) } catch (error) { if (error.code !== 'ENOENT') throw error }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* 零外部运行时依赖,仅使用 Node 内置模块。
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { existsSync,
|
|
12
|
-
import {
|
|
11
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
12
|
+
import { join, resolve } from 'node:path'
|
|
13
|
+
import { writeWorkspaceJson } from './deck-store.mjs'
|
|
13
14
|
|
|
14
15
|
export const CARD_MATERIALS = Object.freeze(['solid', 'frameless', 'glass', 'editorial-rule'])
|
|
15
16
|
export const COVER_VARIANTS = Object.freeze([
|
|
@@ -282,11 +283,13 @@ export function sanitizeCustomTasteRecipe(raw) {
|
|
|
282
283
|
/**
|
|
283
284
|
* 读取工作区持久化的用户品味配方库(.dsh-ppt/taste-recipes.json)。
|
|
284
285
|
*/
|
|
285
|
-
|
|
286
|
+
function readWorkspaceTasteRecipes(cwd, strict = false) {
|
|
286
287
|
const storePath = resolve(cwd, '.dsh-ppt', 'taste-recipes.json')
|
|
287
288
|
if (!existsSync(storePath)) return {}
|
|
288
289
|
try {
|
|
289
290
|
const parsed = JSON.parse(readFileSync(storePath, 'utf8'))
|
|
291
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new Error('Invalid taste store')
|
|
292
|
+
if (Object.hasOwn(parsed, 'recipes') && (!parsed.recipes || typeof parsed.recipes !== 'object' || Array.isArray(parsed.recipes))) throw new Error('Invalid taste recipes')
|
|
290
293
|
const rawMap = parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
291
294
|
? (parsed.recipes && typeof parsed.recipes === 'object' ? parsed.recipes : parsed)
|
|
292
295
|
: {}
|
|
@@ -296,11 +299,14 @@ export function loadWorkspaceTasteRecipes(cwd = process.cwd()) {
|
|
|
296
299
|
if (clean) out[clean.id.toLowerCase()] = clean
|
|
297
300
|
}
|
|
298
301
|
return out
|
|
299
|
-
} catch {
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (strict) throw new Error('dsh-ppt:品味配方库格式无效或无法读取,已保留原文件,请备份并修复后重试', { cause: error })
|
|
300
304
|
return {}
|
|
301
305
|
}
|
|
302
306
|
}
|
|
303
307
|
|
|
308
|
+
export function loadWorkspaceTasteRecipes(cwd = process.cwd()) { return readWorkspaceTasteRecipes(cwd) }
|
|
309
|
+
|
|
304
310
|
/**
|
|
305
311
|
* 将从优质 .pptx 吸收提炼的品味配方持久化到工作区(.dsh-ppt/taste-recipes.json),供后续所有新稿一键复用。
|
|
306
312
|
*/
|
|
@@ -308,13 +314,12 @@ export function saveWorkspaceTasteRecipe(recipe, cwd = process.cwd()) {
|
|
|
308
314
|
const clean = sanitizeCustomTasteRecipe(recipe)
|
|
309
315
|
if (!clean) throw new Error('dsh-ppt:无效的品味配方对象')
|
|
310
316
|
const storePath = resolve(cwd, '.dsh-ppt', 'taste-recipes.json')
|
|
311
|
-
const existing =
|
|
317
|
+
const existing = readWorkspaceTasteRecipes(cwd, true)
|
|
312
318
|
existing[clean.id.toLowerCase()] = {
|
|
313
319
|
...clean,
|
|
314
320
|
absorbedAt: clean.absorbedAt || new Date().toISOString(),
|
|
315
321
|
}
|
|
316
|
-
|
|
317
|
-
writeFileSync(storePath, JSON.stringify({ version: 1, recipes: existing }, null, 2) + '\n', 'utf8')
|
|
322
|
+
writeWorkspaceJson(storePath, { version: 1, recipes: existing })
|
|
318
323
|
return { path: storePath, recipe: existing[clean.id.toLowerCase()], totalSaved: Object.keys(existing).length }
|
|
319
324
|
}
|
|
320
325
|
|