dsh-maoying 0.1.6 → 0.1.7

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.
Files changed (2) hide show
  1. package/index.mjs +35 -0
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -818,11 +818,46 @@ export async function registerCreatorRoutes(ctx) {
818
818
  const dbg = readHostVersionDebug(home)
819
819
  let shape = null
820
820
  try { shape = composeManagedRows(home, ctx.logger).shape } catch { /* 诊断信息尽力而为 */ }
821
+ // 预设注册表内窥:每张 preset 的激活诊断只有注册表自己知道,防御式
822
+ // 探测其服务面(方法名在宿主版本间可能变动,全部吞错尽力而为)。
823
+ const jsonSafe = (v, depth = 0) => {
824
+ if (depth > 4) return '…'
825
+ try {
826
+ if (v === null || v === undefined) return v
827
+ if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') return v
828
+ if (typeof v === 'function') return `[fn ${v.name || 'anon'}]`
829
+ if (Array.isArray(v)) return v.slice(0, 50).map((x) => jsonSafe(x, depth + 1))
830
+ if (v instanceof Map) return { __map: [...v.keys()].slice(0, 50) }
831
+ if (v instanceof Set) return { __set: [...v].slice(0, 50).map((x) => jsonSafe(x, depth + 1)) }
832
+ const out = {}
833
+ for (const k of Object.keys(v).slice(0, 80)) out[k] = jsonSafe(v[k], depth + 1)
834
+ return out
835
+ } catch { return '[unserializable]' }
836
+ }
837
+ const registryDump = {}
838
+ for (const svcName of ['agent-preset-registry', 'agentPresets', 'presets']) {
839
+ try {
840
+ const svc = typeof ctx.get === 'function' ? ctx.get(svcName) : null
841
+ if (!svc) continue
842
+ const entry = { __type: typeof svc, __keys: Object.keys(svc).slice(0, 60) }
843
+ for (const m of ['list', 'read', 'all', 'definitions', 'inventory', 'entries']) {
844
+ if (typeof svc[m] === 'function') {
845
+ try {
846
+ const r = svc[m]()
847
+ entry[m] = r && typeof r.then === 'function' ? '[async]' : jsonSafe(r)
848
+ } catch (e) { entry[m] = `throw: ${e?.message ?? e}` }
849
+ }
850
+ }
851
+ registryDump[svcName] = entry
852
+ } catch { /* 逐个吞错 */ }
853
+ }
821
854
  json(res, 200, {
822
855
  ok: true,
823
856
  hostVersion: dbg.version,
824
857
  trace: dbg.trace,
825
858
  shape,
859
+ registry: registryDump,
860
+ ctxKeys: (() => { try { return Object.keys(ctx).slice(0, 80) } catch { return [] } })(),
826
861
  runtime: {
827
862
  argv: process.argv,
828
863
  execPath: process.execPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-maoying",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "毛颖 — DSH 网文创作辅助插件:主编 + 五帮手编排(大纲/写手/审校/设定/考据),novel/ 结构化文件为数据库",
5
5
  "type": "module",
6
6
  "license": "MIT",