dal-code 1.0.40 → 1.0.42

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 (145) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/NOTICE +76 -1
  3. package/PRIVACY.md +68 -2
  4. package/dist/cli/startup-ui.js +1 -1
  5. package/dist/core/agent-session.d.ts +3 -0
  6. package/dist/core/agent-session.js +6 -6
  7. package/dist/core/bug-report.js +5 -5
  8. package/dist/core/settings-manager.d.ts +0 -5
  9. package/dist/core/settings-manager.js +1 -1
  10. package/dist/dal/manifest.js +1 -1
  11. package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
  12. package/dist/modes/interactive/components/status-indicator.js +1 -1
  13. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  14. package/dist/modes/interactive/interactive-mode.js +2 -2
  15. package/dist/modes/print-mode.d.ts +1 -1
  16. package/dist/modes/print-mode.js +7 -6
  17. package/dist/modes/rpc/rpc-client.d.ts +5 -1
  18. package/dist/modes/rpc/rpc-client.js +3 -3
  19. package/dist/modes/rpc/rpc-mode.js +1 -1
  20. package/dist/modes/rpc/rpc-types.d.ts +25 -0
  21. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  22. package/dist/node_modules/@dalcode/dal-advisor/src/index.js +9 -8
  23. package/dist/node_modules/@dalcode/dal-awake/LICENSE +21 -0
  24. package/dist/node_modules/@dalcode/dal-awake/package.json +31 -0
  25. package/dist/node_modules/@dalcode/dal-awake/src/index.js +3 -0
  26. package/dist/node_modules/@dalcode/dal-awake/src/inhibitor.js +1 -0
  27. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  28. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  29. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  30. package/dist/node_modules/@dalcode/dal-compat/src/at-imports.js +3 -0
  31. package/dist/node_modules/@dalcode/dal-compat/src/index.js +7 -5
  32. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  33. package/dist/node_modules/@dalcode/dal-dap/src/install.js +2 -2
  34. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  35. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  36. package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
  37. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor-core.js +22 -21
  38. package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor.js +4 -4
  39. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  40. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  41. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  42. package/dist/node_modules/@dalcode/dal-learn/package.json +5 -2
  43. package/dist/node_modules/@dalcode/dal-learn/src/index.js +10 -10
  44. package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +3 -3
  45. package/dist/node_modules/@dalcode/dal-learn/src/patches.js +10 -0
  46. package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
  47. package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
  48. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  49. package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +1 -0
  50. package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
  51. package/dist/node_modules/@dalcode/dal-office/src/render/deck-source.d.ts +10 -0
  52. package/dist/node_modules/@dalcode/dal-office/src/render/deck-source.js +2 -0
  53. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +3 -3
  54. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +3 -3
  55. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  56. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +3 -3
  57. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
  58. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  59. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  60. package/dist/node_modules/@dalcode/dal-review/src/core.d.ts +1 -0
  61. package/dist/node_modules/@dalcode/dal-review/src/core.js +1 -1
  62. package/dist/node_modules/@dalcode/dal-review/src/findings.js +2 -2
  63. package/dist/node_modules/@dalcode/dal-review/src/index.js +1 -1
  64. package/dist/node_modules/@dalcode/dal-review/src/prompt.d.ts +1 -1
  65. package/dist/node_modules/@dalcode/dal-review/src/prompt.js +3 -2
  66. package/dist/node_modules/@dalcode/dal-review/src/runner.d.ts +2 -1
  67. package/dist/node_modules/@dalcode/dal-review/src/runner.js +2 -2
  68. package/dist/node_modules/@dalcode/dal-review/src/simplify.d.ts +5 -0
  69. package/dist/node_modules/@dalcode/dal-review/src/simplify.js +30 -0
  70. package/dist/node_modules/@dalcode/dal-review/src/types.d.ts +5 -0
  71. package/dist/node_modules/@dalcode/dal-review/src/types.js +1 -1
  72. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  73. package/dist/node_modules/@dalcode/dal-router/package.json +4 -4
  74. package/dist/node_modules/@dalcode/dal-rtk/LICENSE +21 -0
  75. package/dist/node_modules/@dalcode/dal-rtk/package.json +31 -0
  76. package/dist/node_modules/@dalcode/dal-rtk/src/index.js +2 -0
  77. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  78. package/dist/node_modules/@dalcode/dal-skills/src/bundled/bounded-code-repair/SKILL.md +45 -0
  79. package/dist/node_modules/@dalcode/dal-skills/src/bundled/evidence-first-retrieval/SKILL.md +43 -0
  80. package/dist/node_modules/@dalcode/dal-skills/src/bundled/validated-structured-output/SKILL.md +36 -0
  81. package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -1
  82. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  83. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  84. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  85. package/dist/node_modules/@dalcode/dal-subagent/src/index.js +21 -21
  86. package/dist/node_modules/@dalcode/dal-telemetry/package.json +8 -2
  87. package/dist/node_modules/@dalcode/dal-telemetry/src/config.js +3 -2
  88. package/dist/node_modules/@dalcode/dal-telemetry/src/consent.js +1 -0
  89. package/dist/node_modules/@dalcode/dal-telemetry/src/failure-queue.js +4 -0
  90. package/dist/node_modules/@dalcode/dal-telemetry/src/failure-reporting.js +5 -0
  91. package/dist/node_modules/@dalcode/dal-telemetry/src/failures.js +2 -0
  92. package/dist/node_modules/@dalcode/dal-telemetry/src/index.js +4 -3
  93. package/dist/node_modules/@dalcode/dal-telemetry/src/reporter.js +1 -1
  94. package/dist/node_modules/@dalcode/dal-telemetry/src/repro.js +1 -0
  95. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  96. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  97. package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
  98. package/dist/node_modules/@dalcode/dal-tool-catalog/src/path-hint.js +1 -0
  99. package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair-hook.js +2 -1
  100. package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair.js +1 -1
  101. package/dist/node_modules/@dalcode/dal-tool-catalog/src/tool-name.js +1 -0
  102. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  103. package/dist/node_modules/@dalcode/dal-usage/src/index.d.ts +1 -0
  104. package/dist/node_modules/@dalcode/dal-usage/src/index.js +2 -2
  105. package/dist/node_modules/@dalcode/dal-usage/src/time-limit.d.ts +4 -0
  106. package/dist/node_modules/@dalcode/dal-usage/src/time-limit.js +2 -0
  107. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  108. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  109. package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
  110. package/dist/node_modules/@dalcode/dal-workflow/src/lean-code.js +1 -1
  111. package/dist/node_modules/@dalcode/dal-workflow/src/working-contract.js +1 -0
  112. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  113. package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
  114. package/dist/node_modules/@earendil-works/chord/package.json +1 -1
  115. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  116. package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
  117. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  118. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  119. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  120. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  121. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  122. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  123. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +1 -0
  124. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
  125. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  126. package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
  127. package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
  128. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  129. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  130. package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
  131. package/dist/node_modules/@earendil-works/pi-server/package.json +3 -3
  132. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  133. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  134. package/dist/sdk/index.d.ts +1 -1
  135. package/dist/sdk/office.d.ts +1 -1
  136. package/dist/sdk/office.js +1 -1
  137. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  138. package/examples/extensions/gondolin/package-lock.json +2 -2
  139. package/examples/extensions/gondolin/package.json +1 -1
  140. package/examples/extensions/sandbox/package-lock.json +2 -2
  141. package/examples/extensions/sandbox/package.json +1 -1
  142. package/examples/extensions/with-deps/package-lock.json +2 -2
  143. package/examples/extensions/with-deps/package.json +1 -1
  144. package/npm-shrinkwrap.json +2 -2
  145. package/package.json +1 -1
@@ -1,17 +1,17 @@
1
- var ju=Object.defineProperty;var C=(u,s)=>ju(u,"name",{value:s,configurable:!0});var Lu=Object.defineProperty,d=C((u,s)=>Lu(u,"name",{value:s,configurable:!0}),"d");import{existsSync as Iu,readFileSync as q,realpathSync as Su}from"node:fs";import{dirname as Tu,isAbsolute as Pu,join as M,resolve as Fu,sep as z}from"node:path";import{t as e}from"@dalcode/dal-pi-kit";import{CONFIG_DIR_NAME as Ru,getAgentDir as Q,stripFrontmatter as Ou}from"@earendil-works/pi-coding-agent";import{DEFAULT_DAILY_CAP as Nu,Learner as Mu}from"./engine.js";import{approveLesson as Ku,isHarmful as Wu,readLessons as K,undoLesson as Uu,updateLessons as Hu}from"./lessons.js";import{readProcedures as lu,updateProcedures as Vu}from"./procedures.js";import{readMap as cu,renderMapSection as du,viewMap as pu}from"./project-map.js";import{acceptProposal as Yu,exportProjectSkill as Gu,keepSupplement as Ju,learnedProjectSkillsDir as qu,undoProposal as zu}from"./skill-actions.js";import{applyPatches as Qu,isEditable as Xu,listRecords as Eu,noteConflicts as Zu,readRecord as ue,skillKey as ee}from"./skill-evolution.js";import{readUsage as te}from"./store.js";const Du="learned_lessons",Au="learn_skill_proposal",W="learn_skill_resolved",fu="learn_skill_reverted",mu="learn_skill_conflict",Cu="dal-learn-task-note",se=Symbol.for("dalcode.skills.search"),ne=Symbol.for("dalcode.skills.textTransform");function U(){return globalThis[se]}C(U,"X"),d(U,"skillSearch");function S(u){try{return Su(u)}catch{return Fu(u)}}C(S,"O"),d(S,"real");function X(u,s){const a=S(s);return u===a||u.startsWith(a.endsWith(z)?a:`${a}${z}`)}C(X,"ce"),d(X,"under");function Z(u,s,a){const i=S(u),g=M(a,"projects");if(X(i,g)){const h=i.slice(S(g).length+1).split(z);if(h.length>=3&&h[1]==="skills")return{origin:"learned-project",projectKey:h[0]}}return X(i,M(Q(),"skills"))?{origin:"user"}:/[\\/]dal-skills[\\/]src[\\/]bundled[\\/]/.test(i)?{origin:"bundled"}:s.origin==="package"?{origin:"package"}:s.scope==="project"?{origin:"project"}:{origin:"other"}}C(Z,"Ye"),d(Z,"classifySkill");const Bu="learned_project_map",ie="learned_experience";function hu(){const u={enabled:process.env.DAL_LEARN!=="0",dailyCap:Nu};try{const s=JSON.parse(q(M(Q(),"settings.json"),"utf8")).dalLearn;s?.enabled===!1&&(u.enabled=!1),typeof s?.dailyCap=="number"&&s.dailyCap>=0&&(u.dailyCap=Math.floor(s.dailyCap)),typeof s?.model=="string"&&s.model.includes("/")&&(u.model=s.model)}catch{}return u}C(hu,"Xe"),d(hu,"readSettings");function F(u,s){return u.replace(/\{(\w+)\}/g,(a,i)=>i in s?String(s[i]):a)}C(F,"a"),d(F,"fill");function H(u){const s=u.cost;return(s?.input??0)+(s?.output??0)}C(H,"z"),d(H,"cost");function uu(u,s){const a=u.modelRegistry,i=d(h=>!a.hasConfiguredAuth||a.hasConfiguredAuth(h),"usable");if(s){const h=s.indexOf("/"),v=a.find(s.slice(0,h),s.slice(h+1));if(v&&i(v))return v}let g=[];try{g=a.getAvailable().filter(i)}catch{g=[]}return g.filter(h=>H(h)>0).sort((h,v)=>H(h)-H(v))[0]??u.model}C(uu,"ze"),d(uu,"pickDraftingModel");function ku(){return globalThis[Symbol.for("dalcode.budget.gate")]?.remaining()}C(ku,"Qe"),d(ku,"budgetRemaining");function gu(u,s,a){return async(i,g)=>{if(ku()===0)return;const h=uu(s,a);if(!h)return;const v=await s.modelRegistry.complete(h,{systemPrompt:i,messages:[{role:"user",content:[{type:"text",text:g}],timestamp:Date.now()}]},{cacheRetention:"none",maxTokens:1200});if(v.usage)try{u.appendUsage(v.usage,{kind:"learn",provider:h.provider,model:h.id})}catch{}return v.stopReason==="error"||v.stopReason==="aborted"?void 0:{text:v.content.filter(T=>T.type==="text").map(T=>T.text).join(`
2
- `),inputTokens:v.usage?.input,outputTokens:v.usage?.output}}}C(gu,"Ze"),d(gu,"completeWith");function vu(u){const s=u?.content;return typeof s=="string"?s:Array.isArray(s)?s.filter(a=>a&&typeof a=="object"&&a.type==="text").map(a=>a.text).join(`
3
- `):""}C(vu,"en"),d(vu,"textOf");const eu={deletion:"\u5220\u9664",permissions:"\u6743\u9650",credentials:"\u51ED\u636E",network:"\u7F51\u7EDC",publishing:"\u53D1\u5E03"};function tu(u){return u.risk.map(s=>e(eu[s]??s)).join(e("\u3001"))}C(tu,"ue"),d(tu,"riskText");function yu(u){switch(u.status){case"active":return e("\u5DF2\u542F\u7528");case"candidate":return e("\u89C2\u5BDF\u4E2D");case"awaiting_user":return e("\u5F85\u4F60\u786E\u8BA4");case"retired":return e("\u5DF2\u9000\u5F79");case"undone":return e("\u5DF2\u64A4\u9500");case"expired":return e("\u5DF2\u8FC7\u671F")}}C(yu,"nn"),d(yu,"statusLabel");function V(u){switch(u.activatedBy){case"sessions":return F(e("{n} \u4E2A\u4F1A\u8BDD\u5370\u8BC1"),{n:u.sessions.length});case"proof":return e("\u68C0\u67E5\u901A\u8FC7\u5370\u8BC1");case"user":return e("\u4F60\u786E\u8BA4");case"import":return e("\u4ECE DAL Code \u5BFC\u5165");default:return""}}C(V,"Z"),d(V,"activatedText");function Y(u){const s=u.lesson;switch(u.kind){case"activated":return s?F(e("\u5B66\u5230\u4E00\u6761\u7ECF\u9A8C\u5E76\u5DF2\u542F\u7528 [{id}]\uFF1A{content}\uFF08{why}\uFF1B\u64A4\u9500\uFF1A/lessons undo {id}\uFF09"),{id:s.id,content:s.content,why:V(s)}):void 0;case"awaiting_user":return s?F(e("\u6709\u4E00\u6761\u6D89\u53CA{risk}\u7684\u7ECF\u9A8C\u9700\u8981\u4F60\u786E\u8BA4\u540E\u624D\u4F1A\u542F\u7528 [{id}]\uFF1A{content}\uFF08\u542F\u7528\uFF1A/lessons approve {id}\uFF1B\u4E0D\u8981\uFF1A/lessons undo {id}\uFF09"),{id:s.id,content:s.content,risk:tu(s)}):void 0;case"retired":return s?F(e("\u7ECF\u9A8C [{id}] \u5DF2\u9000\u5F79\uFF1A{why}"),{id:s.id,why:s.retiredReason==="harmful"?e("\u5E2E\u5012\u5FD9\u591A\u4E8E\u5E2E\u5FD9"):e("\u957F\u671F\u6CA1\u6709\u7528\u4E0A")}):void 0;case"skill_proposed":return u.draft?xu(u.draft):void 0;case"skill_reverted":return F(e("\u6280\u80FD\u300C{name}\u300D\u91C7\u7EB3\u6539\u52A8\u540E\u7684 {total} \u6B21\u4F7F\u7528\u91CC\u6709 {bad} \u6B21\u88AB\u7EA0\u6B63\u6216\u5931\u8D25\uFF0C\u6BD4\u6539\u52A8\u524D\u5DEE\uFF0C\u5DF2\u81EA\u52A8\u9000\u56DE\u4E0A\u4E00\u7248\uFF08{id}\uFF09\u3002"),{name:u.skill??"",total:u.uses?.total??0,bad:u.uses?.bad??0,id:u.draft?.id??""});case"imported":return F(e("\u5DF2\u5BFC\u5165 DAL Code \u4E2D\u4FDD\u7559\u7684 {n} \u6761\u7ECF\u9A8C"),{n:u.count??0})}}C(Y,"ee"),d(Y,"noticeText");function su(u){return u.scope==="project"?e("\u9879\u76EE\u6280\u80FD"):e("\u4E2A\u4EBA\u6280\u80FD")}C(su,"pe"),d(su,"scopeLabel");function xu(u){const s={name:u.name,id:u.id,scope:su(u),reason:u.scopeReason??""};switch(u.kind){case"improve":return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF0C\u5BF9\u5DF2\u6709\u6280\u80FD\u300C{name}\u300D\u63D0\u4E86\u4E00\u5904\u8865\u5145\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\u6539\u52A8\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),s);case"split":return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF1B\u76F8\u5173\u6280\u80FD\u5DF2\u7ECF\u5F88\u957F\uFF0C\u5EFA\u8BAE\u628A\u8865\u5145\u62C6\u6210\u65B0\u6280\u80FD\u300C{name}\u300D\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),s);default:return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF0C\u8D77\u8349\u4E86\u6280\u80FD\u300C{name}\u300D\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),s)}}C(xu,"tn"),d(xu,"proposalNotice");const re={new:"\u65B0\u6280\u80FD",improve:"\u6539\u8FDB\u5DF2\u6709\u6280\u80FD",split:"\u62C6\u5206"};function wu(u){const s=u.kind??"new",a=[`[${u.id}] ${e(re[s]??s)} \xB7 ${u.name} \xB7 ${su(u)}${u.scopeReason?`\uFF08${u.scopeReason}\uFF09`:""}`];return u.risk&&u.risk.length>0&&a.push(F(e(" \u6D89\u53CA{risk}\uFF0C\u91C7\u7528\u65F6\u9700\u8981\u786E\u8BA4"),{risk:u.risk.map(i=>e(eu[i]??i)).join(e("\u3001"))})),u.evidence&&u.evidence.length>0&&a.push(e(" \u4F9D\u636E\uFF1A"),...u.evidence.map(i=>` ${i.at.slice(0,16).replace("T"," ")} ${i.sessionId.slice(-8)} ${i.note}`)),a.push(u.diff?u.diff:u.content),a.join(`
4
- `)}C(wu,"on"),d(wu,"proposalBlock");const oe=new Set(["active","awaiting_user","candidate"]);function nu(u){const s=u.filter(a=>oe.has(a.status));return{inUse:s,count:d(a=>u.filter(i=>i.status===a).length,"count"),helpful:s.reduce((a,i)=>a+i.helpful,0),harmful:s.reduce((a,i)=>a+i.harmful,0)}}C(nu,"fe"),d(nu,"tallyLessons");function _u(u){const s=u.helpful+u.harmful>0?` \xB7 +${u.helpful}/-${u.harmful}`:"",a=u.scope==="user"?e("\u4E2A\u4EBA"):e("\u9879\u76EE");let i="";return u.status==="active"?i=V(u)?` \xB7 ${V(u)}`:"":u.status==="candidate"?i=` \xB7 ${F(e("{n}/2 \u4E2A\u4F1A\u8BDD"),{n:u.sessions.length})}`:u.status==="awaiting_user"&&(i=` \xB7 ${F(e("\u6D89\u53CA{risk}"),{risk:tu(u)})}`),`[${u.id}] ${a} \xB7 ${yu(u)}${i}${s}
5
- ${u.content}`}C(_u,"an"),d(_u,"lessonLine");function iu(u={}){return d(function(s){const a=hu(),i=new Mu({...u,dailyCap:u.dailyCap??a.dailyCap});let g,h,v=Promise.resolve();const T={flush:d(()=>v,"flush"),learner:i,sections:d(()=>g?.sections,"sections")};u.onReady?.(T);const P=d((n,t,r="info")=>{n.hasUI&&n.ui.notify(t,r)},"say"),R=d(()=>s.getCommands().filter(n=>n.source==="skill"&&n.name.startsWith("skill:")).map(n=>({name:n.name.slice(6),description:n.description??"",filePath:n.sourceInfo.path,...Z(n.sourceInfo.path,n.sourceInfo,i.root)})),"hostSkills"),ru=d(n=>({list:R,search:d(t=>(U()?.search(t,n,6)??[]).filter(r=>r.source!=="local").map(r=>({name:r.name,description:r.description,origin:"cloud"})),"search"),text:d(async t=>{if(t.filePath)try{return q(t.filePath,"utf8")}catch{return}return U()?.load(t.name)},"text")}),"catalog"),ou=d(n=>{const t=S(n);return R().find(r=>r.filePath&&S(r.filePath)===t)},"refByPath"),G=d((n,t,r)=>{if(Xu(n))return;const k=ee(n),B=ue(i.root,k);if(!B||B.kind!=="overlay"||B.patches.length===0)return;const D=i.project(r.cwd).key,f=Qu(t,B.patches,{marker:!0,projectKey:D}),$=Zu(i.root,k,f.conflicts,i.now());for(const l of $){const c=B.patches.find(m=>m.id===l.patchId)?.proposalId??l.patchId;P(r,F(e("\u6280\u80FD\u300C{name}\u300D\u5DF2\u66F4\u65B0\uFF0C\u672C\u673A\u8865\u5145\u9488\u5BF9\u7684\u300C{section}\u300D\u4E00\u6BB5\u53D8\u4E86\uFF0C\u8FD9\u6761\u8865\u5145\u6682\u4E0D\u751F\u6548\uFF08{id}\uFF09\u3002\u4FDD\u7559\u5E76\u8DDF\u968F\u65B0\u7248\uFF1A/lessons skill keep {id}\uFF1B\u4E0D\u8981\u4E86\uFF1A/lessons undo {id}"),{name:n.name,section:l.section,id:c}),"warning"),s.emitHostEvent(mu,{id:c,skill:n.name,section:l.section,reason:l.reason})}return f.applied.length>0?f.text:void 0},"mergeSupplements");s.on("resources_discover",n=>{if(a.enabled)try{const t=qu(i.projectDir(i.project(n.cwd)));return Iu(t)?{skillPaths:[t]}:void 0}catch{return}});let J;const O=new Set;globalThis[ne]=((n,t)=>{if(!a.enabled||!J)return t;O.add(n.name);const r=n.source==="local"&&n.path?ou(n.path):{name:n.name,description:"",origin:"cloud"};return(r&&G(r,t,J))??t}),s.on("tool_result",(n,t)=>{if(!a.enabled||n.isError)return;const r=n.content.length===1&&n.content[0].type==="text"?n.content[0].text:void 0;if(r===void 0)return;let k;if(n.toolName==="read"){const D=n.input;if(typeof D.path!="string"||D.offset!==void 0||D.limit!==void 0||/\n\n\[(?:Showing lines|\d+ more lines)/.test(r))return;k=ou(Pu(D.path)?D.path:Fu(t.cwd,D.path))}if(!k)return;const B=G(k,r,t);return B?{content:[{type:"text",text:B}]}:void 0}),s.on("input",(n,t)=>{if(!a.enabled||!n.text.startsWith("/skill:"))return{action:"continue"};const r=n.text.indexOf(" "),k=r===-1?n.text.slice(7):n.text.slice(7,r),B=r===-1?"":n.text.slice(r+1).trim(),D=R().find(c=>c.name===k);if(!D?.filePath)return{action:"continue"};let f;try{f=Ou(q(D.filePath,"utf8")).trim()}catch{return{action:"continue"}}const $=G(D,f,t);if(!$)return{action:"continue"};const l=`<skill name="${D.name}" location="${D.filePath}">
6
- References are relative to ${Tu(D.filePath)}.
1
+ var ju=Object.defineProperty;var C=(u,n)=>ju(u,"name",{value:n,configurable:!0});var Lu=Object.defineProperty,d=C((u,n)=>Lu(u,"name",{value:n,configurable:!0}),"d");import{existsSync as Iu,readFileSync as z,realpathSync as Su}from"node:fs";import{dirname as Pu,isAbsolute as Tu,join as M,resolve as Fu,sep as Q}from"node:path";import{t as e}from"@dalcode/dal-pi-kit";import{CONFIG_DIR_NAME as Ru,getAgentDir as K,stripFrontmatter as Ou}from"@earendil-works/pi-coding-agent";import{DEFAULT_DAILY_CAP as Nu,Learner as Mu}from"./engine.js";import{approveLesson as Ku,isHarmful as Wu,readLessons as W,undoLesson as Uu,updateLessons as Hu}from"./lessons.js";import{registerEvolvePatches as Vu}from"./patches.js";import{readProcedures as lu,updateProcedures as Yu}from"./procedures.js";import{readMap as cu,renderMapSection as du,viewMap as pu}from"./project-map.js";import{acceptProposal as Gu,exportProjectSkill as Ju,keepSupplement as qu,learnedProjectSkillsDir as zu,undoProposal as Qu}from"./skill-actions.js";import{applyPatches as Xu,isEditable as Zu,listRecords as Eu,noteConflicts as ue,readRecord as ee,skillKey as te}from"./skill-evolution.js";import{readUsage as ne}from"./store.js";const Du="learned_lessons",Au="learn_skill_proposal",U="learn_skill_resolved",fu="learn_skill_reverted",mu="learn_skill_conflict",Cu="dal-learn-task-note",se=Symbol.for("dalcode.skills.search"),ie=Symbol.for("dalcode.skills.textTransform");function H(){return globalThis[se]}C(H,"X"),d(H,"skillSearch");function S(u){try{return Su(u)}catch{return Fu(u)}}C(S,"O"),d(S,"real");function X(u,n){const a=S(n);return u===a||u.startsWith(a.endsWith(Q)?a:`${a}${Q}`)}C(X,"ce"),d(X,"under");function Z(u,n,a){const i=S(u),g=M(a,"projects");if(X(i,g)){const h=i.slice(S(g).length+1).split(Q);if(h.length>=3&&h[1]==="skills")return{origin:"learned-project",projectKey:h[0]}}return X(i,M(K(),"skills"))?{origin:"user"}:/[\\/]dal-skills[\\/]src[\\/]bundled[\\/]/.test(i)?{origin:"bundled"}:n.origin==="package"?{origin:"package"}:n.scope==="project"?{origin:"project"}:{origin:"other"}}C(Z,"Ge"),d(Z,"classifySkill");const Bu="learned_project_map",re="learned_experience";function hu(){const u={enabled:process.env.DAL_LEARN!=="0",dailyCap:Nu};try{const n=JSON.parse(z(M(K(),"settings.json"),"utf8")).dalLearn;n?.enabled===!1&&(u.enabled=!1),typeof n?.dailyCap=="number"&&n.dailyCap>=0&&(u.dailyCap=Math.floor(n.dailyCap)),typeof n?.model=="string"&&n.model.includes("/")&&(u.model=n.model)}catch{}return u}C(hu,"ze"),d(hu,"readSettings");function F(u,n){return u.replace(/\{(\w+)\}/g,(a,i)=>i in n?String(n[i]):a)}C(F,"a"),d(F,"fill");function V(u){const n=u.cost;return(n?.input??0)+(n?.output??0)}C(V,"z"),d(V,"cost");function uu(u,n){const a=u.modelRegistry,i=d(h=>!a.hasConfiguredAuth||a.hasConfiguredAuth(h),"usable");if(n){const h=n.indexOf("/"),v=a.find(n.slice(0,h),n.slice(h+1));if(v&&i(v))return v}let g=[];try{g=a.getAvailable().filter(i)}catch{g=[]}return g.filter(h=>V(h)>0).sort((h,v)=>V(h)-V(v))[0]??u.model}C(uu,"Qe"),d(uu,"pickDraftingModel");function ku(){return globalThis[Symbol.for("dalcode.budget.gate")]?.remaining()}C(ku,"Ze"),d(ku,"budgetRemaining");function gu(u,n,a){return async(i,g)=>{if(ku()===0)return;const h=uu(n,a);if(!h)return;const v=await n.modelRegistry.complete(h,{systemPrompt:i,messages:[{role:"user",content:[{type:"text",text:g}],timestamp:Date.now()}]},{cacheRetention:"none",maxTokens:1200});if(v.usage)try{u.appendUsage(v.usage,{kind:"learn",provider:h.provider,model:h.id})}catch{}return v.stopReason==="error"||v.stopReason==="aborted"?void 0:{text:v.content.filter(P=>P.type==="text").map(P=>P.text).join(`
2
+ `),inputTokens:v.usage?.input,outputTokens:v.usage?.output}}}C(gu,"en"),d(gu,"completeWith");function vu(u){const n=u?.content;return typeof n=="string"?n:Array.isArray(n)?n.filter(a=>a&&typeof a=="object"&&a.type==="text").map(a=>a.text).join(`
3
+ `):""}C(vu,"nn"),d(vu,"textOf");const eu={deletion:"\u5220\u9664",permissions:"\u6743\u9650",credentials:"\u51ED\u636E",network:"\u7F51\u7EDC",publishing:"\u53D1\u5E03"};function tu(u){return u.risk.map(n=>e(eu[n]??n)).join(e("\u3001"))}C(tu,"ue"),d(tu,"riskText");function yu(u){switch(u.status){case"active":return e("\u5DF2\u542F\u7528");case"candidate":return e("\u89C2\u5BDF\u4E2D");case"awaiting_user":return e("\u5F85\u4F60\u786E\u8BA4");case"retired":return e("\u5DF2\u9000\u5F79");case"undone":return e("\u5DF2\u64A4\u9500");case"expired":return e("\u5DF2\u8FC7\u671F")}}C(yu,"tn"),d(yu,"statusLabel");function Y(u){switch(u.activatedBy){case"sessions":return F(e("{n} \u4E2A\u4F1A\u8BDD\u5370\u8BC1"),{n:u.sessions.length});case"proof":return e("\u68C0\u67E5\u901A\u8FC7\u5370\u8BC1");case"user":return e("\u4F60\u786E\u8BA4");case"import":return e("\u4ECE DAL Code \u5BFC\u5165");default:return""}}C(Y,"Z"),d(Y,"activatedText");function G(u){const n=u.lesson;switch(u.kind){case"activated":return n?F(e("\u5B66\u5230\u4E00\u6761\u7ECF\u9A8C\u5E76\u5DF2\u542F\u7528 [{id}]\uFF1A{content}\uFF08{why}\uFF1B\u64A4\u9500\uFF1A/lessons undo {id}\uFF09"),{id:n.id,content:n.content,why:Y(n)}):void 0;case"awaiting_user":return n?F(e("\u6709\u4E00\u6761\u6D89\u53CA{risk}\u7684\u7ECF\u9A8C\u9700\u8981\u4F60\u786E\u8BA4\u540E\u624D\u4F1A\u542F\u7528 [{id}]\uFF1A{content}\uFF08\u542F\u7528\uFF1A/lessons approve {id}\uFF1B\u4E0D\u8981\uFF1A/lessons undo {id}\uFF09"),{id:n.id,content:n.content,risk:tu(n)}):void 0;case"retired":return n?F(e("\u7ECF\u9A8C [{id}] \u5DF2\u9000\u5F79\uFF1A{why}"),{id:n.id,why:n.retiredReason==="harmful"?e("\u5E2E\u5012\u5FD9\u591A\u4E8E\u5E2E\u5FD9"):e("\u957F\u671F\u6CA1\u6709\u7528\u4E0A")}):void 0;case"skill_proposed":return u.draft?xu(u.draft):void 0;case"skill_reverted":return F(e("\u6280\u80FD\u300C{name}\u300D\u91C7\u7EB3\u6539\u52A8\u540E\u7684 {total} \u6B21\u4F7F\u7528\u91CC\u6709 {bad} \u6B21\u88AB\u7EA0\u6B63\u6216\u5931\u8D25\uFF0C\u6BD4\u6539\u52A8\u524D\u5DEE\uFF0C\u5DF2\u81EA\u52A8\u9000\u56DE\u4E0A\u4E00\u7248\uFF08{id}\uFF09\u3002"),{name:u.skill??"",total:u.uses?.total??0,bad:u.uses?.bad??0,id:u.draft?.id??""});case"imported":return F(e("\u5DF2\u5BFC\u5165 DAL Code \u4E2D\u4FDD\u7559\u7684 {n} \u6761\u7ECF\u9A8C"),{n:u.count??0})}}C(G,"ee"),d(G,"noticeText");function nu(u){return u.scope==="project"?e("\u9879\u76EE\u6280\u80FD"):e("\u4E2A\u4EBA\u6280\u80FD")}C(nu,"pe"),d(nu,"scopeLabel");function xu(u){const n={name:u.name,id:u.id,scope:nu(u),reason:u.scopeReason??""};switch(u.kind){case"improve":return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF0C\u5BF9\u5DF2\u6709\u6280\u80FD\u300C{name}\u300D\u63D0\u4E86\u4E00\u5904\u8865\u5145\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\u6539\u52A8\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),n);case"split":return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF1B\u76F8\u5173\u6280\u80FD\u5DF2\u7ECF\u5F88\u957F\uFF0C\u5EFA\u8BAE\u628A\u8865\u5145\u62C6\u6210\u65B0\u6280\u80FD\u300C{name}\u300D\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),n);default:return F(e("\u540C\u4E00\u5957\u6B65\u9AA4\u5DF2\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u51FA\u73B0\uFF0C\u8D77\u8349\u4E86\u6280\u80FD\u300C{name}\u300D\uFF08{scope}\uFF1A{reason}\uFF09\u3002\u67E5\u770B\uFF1A/lessons skills\uFF1B\u91C7\u7528\uFF1A/lessons skill accept {id}"),n)}}C(xu,"sn"),d(xu,"proposalNotice");const oe={new:"\u65B0\u6280\u80FD",improve:"\u6539\u8FDB\u5DF2\u6709\u6280\u80FD",split:"\u62C6\u5206"};function wu(u){const n=u.kind??"new",a=[`[${u.id}] ${e(oe[n]??n)} \xB7 ${u.name} \xB7 ${nu(u)}${u.scopeReason?`\uFF08${u.scopeReason}\uFF09`:""}`];return u.risk&&u.risk.length>0&&a.push(F(e(" \u6D89\u53CA{risk}\uFF0C\u91C7\u7528\u65F6\u9700\u8981\u786E\u8BA4"),{risk:u.risk.map(i=>e(eu[i]??i)).join(e("\u3001"))})),u.evidence&&u.evidence.length>0&&a.push(e(" \u4F9D\u636E\uFF1A"),...u.evidence.map(i=>` ${i.at.slice(0,16).replace("T"," ")} ${i.sessionId.slice(-8)} ${i.note}`)),a.push(u.diff?u.diff:u.content),a.join(`
4
+ `)}C(wu,"rn"),d(wu,"proposalBlock");const ae=new Set(["active","awaiting_user","candidate"]);function su(u){const n=u.filter(a=>ae.has(a.status));return{inUse:n,count:d(a=>u.filter(i=>i.status===a).length,"count"),helpful:n.reduce((a,i)=>a+i.helpful,0),harmful:n.reduce((a,i)=>a+i.harmful,0)}}C(su,"fe"),d(su,"tallyLessons");function _u(u){const n=u.helpful+u.harmful>0?` \xB7 +${u.helpful}/-${u.harmful}`:"",a=u.scope==="user"?e("\u4E2A\u4EBA"):e("\u9879\u76EE");let i="";return u.status==="active"?i=Y(u)?` \xB7 ${Y(u)}`:"":u.status==="candidate"?i=` \xB7 ${F(e("{n}/2 \u4E2A\u4F1A\u8BDD"),{n:u.sessions.length})}`:u.status==="awaiting_user"&&(i=` \xB7 ${F(e("\u6D89\u53CA{risk}"),{risk:tu(u)})}`),`[${u.id}] ${a} \xB7 ${yu(u)}${i}${n}
5
+ ${u.content}`}C(_u,"ln"),d(_u,"lessonLine");function iu(u={}){return d(function(n){Vu(n,u.evolveAgentDir??K());const a=hu(),i=new Mu({...u,dailyCap:u.dailyCap??a.dailyCap});let g,h,v=Promise.resolve();const P={flush:d(()=>v,"flush"),learner:i,sections:d(()=>g?.sections,"sections")};u.onReady?.(P);const T=d((s,t,r="info")=>{s.hasUI&&s.ui.notify(t,r)},"say"),R=d(()=>n.getCommands().filter(s=>s.source==="skill"&&s.name.startsWith("skill:")).map(s=>({name:s.name.slice(6),description:s.description??"",filePath:s.sourceInfo.path,...Z(s.sourceInfo.path,s.sourceInfo,i.root)})),"hostSkills"),ru=d(s=>({list:R,search:d(t=>(H()?.search(t,s,6)??[]).filter(r=>r.source!=="local").map(r=>({name:r.name,description:r.description,origin:"cloud"})),"search"),text:d(async t=>{if(t.filePath)try{return z(t.filePath,"utf8")}catch{return}return H()?.load(t.name)},"text")}),"catalog"),ou=d(s=>{const t=S(s);return R().find(r=>r.filePath&&S(r.filePath)===t)},"refByPath"),J=d((s,t,r)=>{if(Zu(s))return;const k=te(s),B=ee(i.root,k);if(!B||B.kind!=="overlay"||B.patches.length===0)return;const D=i.project(r.cwd).key,f=Xu(t,B.patches,{marker:!0,projectKey:D}),$=ue(i.root,k,f.conflicts,i.now());for(const l of $){const c=B.patches.find(m=>m.id===l.patchId)?.proposalId??l.patchId;T(r,F(e("\u6280\u80FD\u300C{name}\u300D\u5DF2\u66F4\u65B0\uFF0C\u672C\u673A\u8865\u5145\u9488\u5BF9\u7684\u300C{section}\u300D\u4E00\u6BB5\u53D8\u4E86\uFF0C\u8FD9\u6761\u8865\u5145\u6682\u4E0D\u751F\u6548\uFF08{id}\uFF09\u3002\u4FDD\u7559\u5E76\u8DDF\u968F\u65B0\u7248\uFF1A/lessons skill keep {id}\uFF1B\u4E0D\u8981\u4E86\uFF1A/lessons undo {id}"),{name:s.name,section:l.section,id:c}),"warning"),n.emitHostEvent(mu,{id:c,skill:s.name,section:l.section,reason:l.reason})}return f.applied.length>0?f.text:void 0},"mergeSupplements");n.on("resources_discover",s=>{if(a.enabled)try{const t=zu(i.projectDir(i.project(s.cwd)));return Iu(t)?{skillPaths:[t]}:void 0}catch{return}});let q;const O=new Set;globalThis[ie]=((s,t)=>{if(!a.enabled||!q)return t;O.add(s.name);const r=s.source==="local"&&s.path?ou(s.path):{name:s.name,description:"",origin:"cloud"};return(r&&J(r,t,q))??t}),n.on("tool_result",(s,t)=>{if(!a.enabled||s.isError)return;const r=s.content.length===1&&s.content[0].type==="text"?s.content[0].text:void 0;if(r===void 0)return;let k;if(s.toolName==="read"){const D=s.input;if(typeof D.path!="string"||D.offset!==void 0||D.limit!==void 0||/\n\n\[(?:Showing lines|\d+ more lines)/.test(r))return;k=ou(Tu(D.path)?D.path:Fu(t.cwd,D.path))}if(!k)return;const B=J(k,r,t);return B?{content:[{type:"text",text:B}]}:void 0}),n.on("input",(s,t)=>{if(!a.enabled||!s.text.startsWith("/skill:"))return{action:"continue"};const r=s.text.indexOf(" "),k=r===-1?s.text.slice(7):s.text.slice(7,r),B=r===-1?"":s.text.slice(r+1).trim(),D=R().find(c=>c.name===k);if(!D?.filePath)return{action:"continue"};let f;try{f=Ou(z(D.filePath,"utf8")).trim()}catch{return{action:"continue"}}const $=J(D,f,t);if(!$)return{action:"continue"};const l=`<skill name="${D.name}" location="${D.filePath}">
6
+ References are relative to ${Pu(D.filePath)}.
7
7
 
8
8
  ${$.trim()}
9
9
  </skill>`;return{action:"transform",text:B?`${l}
10
10
 
11
- ${B}`:l}}),s.on("session_start",(n,t)=>{g=void 0,h=void 0,J=t,O.clear()}),s.on("before_agent_start",(n,t)=>{if(!a.enabled)return;const r=t.sessionManager.getSessionId();if(!g||g.sessionId!==r)try{const D=i.startSession(t.cwd,{hostHasLearnedSection:!!n.systemPromptOptions.sections[ie]});if(g={sessionId:r,sections:D},D.imported>0){const f=Y({kind:"imported",count:D.imported});f&&P(t,f)}for(const f of D.retired){if(f.to!=="retired")continue;const $=Y({kind:"retired",lesson:f.lesson});$&&P(t,$)}}catch{g={sessionId:r,sections:{project:i.project(t.cwd),lessonIds:[],lessonTokens:0,mapTokens:0,imported:0,retired:[]}}}const{lessons:k,map:B}=g.sections;k&&(n.systemPromptOptions.sections[Du]=k),B&&(n.systemPromptOptions.sections[Bu]=B)}),s.on("agent_end",(n,t)=>{if(!a.enabled)return;const r=t.sessionManager.getSessionId(),k=g?.sessionId===r?g.sections.lessonIds:[],B=h,D=n.messages,f=D.filter(p=>p.role==="assistant").map(vu).filter(Boolean).at(-1);f&&(h=f);const $=t.cwd,l=gu(s,t,a.model),c=ru($),m=[...O];O.clear();const y=d(async()=>{const p=await i.onRunEnd(D,{cwd:$,sessionId:r,injected:k,previousAssistant:B,complete:l,skills:c,loadedSkills:m});for(const E of p.notices){const _=Y(E);_&&P(t,_,E.kind==="awaiting_user"||E.kind==="skill_reverted"?"warning":"info"),$u(E)}for(const E of p.taskNotes)s.appendEntry(Cu,{content:E.content,section:E.section,at:new Date().toISOString()})},"work");v=v.then(y,y).catch(()=>{})}),s.on("session_shutdown",async()=>{await Promise.race([v,new Promise(n=>setTimeout(n,5e3).unref?.())])});const $u=d(n=>{const t=n.draft;n.kind==="skill_proposed"&&t?s.emitHostEvent(Au,{id:t.id,kind:t.kind??"new",skill:t.name,scope:t.scope??"user",scopeReason:t.scopeReason??"",diff:t.diff??t.content,evidence:t.evidence??[],risk:t.risk??[]}):n.kind==="skill_reverted"&&s.emitHostEvent(fu,{id:t?.id??"",skill:n.skill??"",uses:n.uses??{total:0,bad:0}})},"emitSkillEvent"),au=d(async n=>{try{await n.reload()}catch{}},"reloadSkills"),A=d((n,t)=>{n.hasUI?n.ui.notify(t,"info"):process.stdout.write(`${t}
12
- `)},"print");s.registerCommand("lessons",{description:e("\u5B66\u5230\u7684\u7ECF\u9A8C\uFF1A\u5217\u8868\u3001\u7EDF\u8BA1\u3001\u64A4\u9500\u3001\u786E\u8BA4\u3001\u9879\u76EE\u5730\u56FE\u3001\u6280\u80FD\u8349\u7A3F\uFF08/lessons stats|map|skills|undo|approve\uFF09"),getArgumentCompletions:d(n=>{const t=["stats","map","skills","undo ","approve ","skill accept ","skill discard ","skill keep ","skill export "].filter(r=>r.startsWith(n.trimStart()));return t.length>0?t.map(r=>({value:r,label:r.trim()})):null},"getArgumentCompletions"),handler:d(async(n,t)=>{await v;const[r="",...k]=n.trim().split(/\s+/).filter(Boolean),B=i.project(t.cwd),D=i.projectDir(B),f=i.now(),$=d(l=>l.startsWith("u-")?i.userDir():D,"findTarget");if(r===""||r==="list"){const l=[...K(i.userDir()).lessons,...K(D).lessons],c=nu(l),m=c.inUse,y={retired:c.count("retired"),undone:c.count("undone"),expired:c.count("expired")},p=y.retired+y.undone+y.expired>0?[F(e("\u53E6\u6709\u5DF2\u9000\u5F79 {retired} \xB7 \u5DF2\u64A4\u9500 {undone} \xB7 \u5DF2\u8FC7\u671F {expired}\uFF0C\u4E0D\u518D\u4F7F\u7528\uFF08/lessons stats \u67E5\u770B\uFF09"),y)]:[];if(m.length===0){if(p.length>0){A(t,[e("\u6CA1\u6709\u5728\u7528\u7684\u7ECF\u9A8C\u3002"),...p].join(`
11
+ ${B}`:l}}),n.on("session_start",(s,t)=>{g=void 0,h=void 0,q=t,O.clear()}),n.on("before_agent_start",(s,t)=>{if(!a.enabled)return;const r=t.sessionManager.getSessionId();if(!g||g.sessionId!==r)try{const D=i.startSession(t.cwd,{hostHasLearnedSection:!!s.systemPromptOptions.sections[re]});if(g={sessionId:r,sections:D},D.imported>0){const f=G({kind:"imported",count:D.imported});f&&T(t,f)}for(const f of D.retired){if(f.to!=="retired")continue;const $=G({kind:"retired",lesson:f.lesson});$&&T(t,$)}}catch{g={sessionId:r,sections:{project:i.project(t.cwd),lessonIds:[],lessonTokens:0,mapTokens:0,imported:0,retired:[]}}}const{lessons:k,map:B}=g.sections;k&&(s.systemPromptOptions.sections[Du]=k),B&&(s.systemPromptOptions.sections[Bu]=B)}),n.on("agent_end",(s,t)=>{if(!a.enabled)return;const r=t.sessionManager.getSessionId(),k=g?.sessionId===r?g.sections.lessonIds:[],B=h,D=s.messages,f=D.filter(p=>p.role==="assistant").map(vu).filter(Boolean).at(-1);f&&(h=f);const $=t.cwd,l=gu(n,t,a.model),c=ru($),m=[...O];O.clear();const y=d(async()=>{const p=await i.onRunEnd(D,{cwd:$,sessionId:r,injected:k,previousAssistant:B,complete:l,skills:c,loadedSkills:m});for(const E of p.notices){const _=G(E);_&&T(t,_,E.kind==="awaiting_user"||E.kind==="skill_reverted"?"warning":"info"),$u(E)}for(const E of p.taskNotes)n.appendEntry(Cu,{content:E.content,section:E.section,at:new Date().toISOString()})},"work");v=v.then(y,y).catch(()=>{})}),n.on("session_shutdown",async()=>{await Promise.race([v,new Promise(s=>setTimeout(s,5e3).unref?.())])});const $u=d(s=>{const t=s.draft;s.kind==="skill_proposed"&&t?n.emitHostEvent(Au,{id:t.id,kind:t.kind??"new",skill:t.name,scope:t.scope??"user",scopeReason:t.scopeReason??"",diff:t.diff??t.content,evidence:t.evidence??[],risk:t.risk??[]}):s.kind==="skill_reverted"&&n.emitHostEvent(fu,{id:t?.id??"",skill:s.skill??"",uses:s.uses??{total:0,bad:0}})},"emitSkillEvent"),au=d(async s=>{try{await s.reload()}catch{}},"reloadSkills"),A=d((s,t)=>{s.hasUI?s.ui.notify(t,"info"):process.stdout.write(`${t}
12
+ `)},"print");n.registerCommand("lessons",{description:e("\u5B66\u5230\u7684\u7ECF\u9A8C\uFF1A\u5217\u8868\u3001\u7EDF\u8BA1\u3001\u64A4\u9500\u3001\u786E\u8BA4\u3001\u9879\u76EE\u5730\u56FE\u3001\u6280\u80FD\u8349\u7A3F\uFF08/lessons stats|map|skills|undo|approve\uFF09"),getArgumentCompletions:d(s=>{const t=["stats","map","skills","undo ","approve ","skill accept ","skill discard ","skill keep ","skill export "].filter(r=>r.startsWith(s.trimStart()));return t.length>0?t.map(r=>({value:r,label:r.trim()})):null},"getArgumentCompletions"),handler:d(async(s,t)=>{await v;const[r="",...k]=s.trim().split(/\s+/).filter(Boolean),B=i.project(t.cwd),D=i.projectDir(B),f=i.now(),$=d(l=>l.startsWith("u-")?i.userDir():D,"findTarget");if(r===""||r==="list"){const l=[...W(i.userDir()).lessons,...W(D).lessons],c=su(l),m=c.inUse,y={retired:c.count("retired"),undone:c.count("undone"),expired:c.count("expired")},p=y.retired+y.undone+y.expired>0?[F(e("\u53E6\u6709\u5DF2\u9000\u5F79 {retired} \xB7 \u5DF2\u64A4\u9500 {undone} \xB7 \u5DF2\u8FC7\u671F {expired}\uFF0C\u4E0D\u518D\u4F7F\u7528\uFF08/lessons stats \u67E5\u770B\uFF09"),y)]:[];if(m.length===0){if(p.length>0){A(t,[e("\u6CA1\u6709\u5728\u7528\u7684\u7ECF\u9A8C\u3002"),...p].join(`
13
13
  `));return}A(t,e("\u8FD8\u6CA1\u6709\u5B66\u5230\u7ECF\u9A8C\u3002\u51FA\u73B0\u5931\u8D25\u540E\u4FEE\u597D\u3001\u4F60\u7EA0\u6B63\u52A9\u624B\u3001\u6216\u53CD\u590D\u7ED5\u8DEF\u65F6\uFF0C\u4F1A\u81EA\u52A8\u8BB0\u4E0B\u3002"));return}const E={awaiting_user:0,active:1,candidate:2};m.sort((_,j)=>(E[_.status]??3)-(E[j.status]??3)||_.id.localeCompare(j.id)),A(t,[e("\u5B66\u5230\u7684\u7ECF\u9A8C\uFF08\u5DF2\u542F\u7528\u7684\u4F1A\u5728\u6BCF\u4E2A\u65B0\u4F1A\u8BDD\u5F00\u5934\u4EA4\u7ED9\u52A9\u624B\uFF09\uFF1A"),...m.map(_u),...p,e("\u64A4\u9500\uFF1A/lessons undo <id> \xB7 \u786E\u8BA4\uFF1A/lessons approve <id> \xB7 \u7EDF\u8BA1\uFF1A/lessons stats")].join(`
14
- `));return}if(r==="undo"&&/^s-\d{4,6}$/.test(k[0]??"")){const l=k[0],c=zu(i.root,D,l,f);if(c.kind==="not_latest"){A(t,F(e("\u8FD9\u4E2A\u6280\u80FD\u4E4B\u540E\u8FD8\u6709\u6539\u52A8 {newer}\uFF0C\u5148\u64A4\u9500\u5B83\uFF1A/lessons undo {newer}"),{newer:c.newer}));return}if(c.kind==="changed_outside"){A(t,F(e("\u6280\u80FD\u300C{name}\u300D\u5728\u91C7\u7528\u4E4B\u540E\u88AB\u624B\u52A8\u6539\u8FC7\uFF0C\u4E3A\u4E86\u4E0D\u8986\u76D6\u4F60\u7684\u4FEE\u6539\uFF0C\u6CA1\u6709\u64A4\u9500\u3002"),{name:c.skill}));return}if(c.kind==="not_found"){A(t,F(e("\u6CA1\u6709\u5DF2\u91C7\u7528\u7684\u6280\u80FD\u6539\u52A8 {id}"),{id:l}));return}s.emitHostEvent(W,{id:l,status:"undone",skill:c.draft.name}),A(t,F(e("\u5DF2\u64A4\u9500\u6280\u80FD\u6539\u52A8 [{id}]\uFF0C\u6280\u80FD\u56DE\u5230\u91C7\u7528\u4E4B\u524D\u7684\u7248\u672C\u3002"),{id:l})),c.draft.kind!=="improve"&&await au(t);return}if(r==="undo"||r==="approve"){const l=k[0]??"";if(!/^[lu]-\d{4,6}$/.test(l)){A(t,F(e("\u7528\u6CD5\uFF1A/lessons {sub} <id>\uFF08\u4F8B\u5982 l-0001\uFF09"),{sub:r}));return}const c=$(l);let m;if(Hu(c,y=>{const p=r==="undo"?Uu(y,l,f):Ku(y,l,f);return m=p.lesson,p.lesson?p.doc:void 0}),!m){A(t,F(e("\u6CA1\u6709\u627E\u5230\u7ECF\u9A8C {id}"),{id:l}));return}A(t,r==="undo"?F(e("\u5DF2\u64A4\u9500\u7ECF\u9A8C [{id}]\uFF0C\u4ECE\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u8D77\u4E0D\u518D\u4F7F\u7528\uFF0C\u4E5F\u4E0D\u4F1A\u518D\u6B21\u63D0\u8BAE\u3002"),{id:l}):F(e("\u5DF2\u542F\u7528\u7ECF\u9A8C [{id}]\uFF0C\u4ECE\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u8D77\u4EA4\u7ED9\u52A9\u624B\u3002"),{id:l}));return}if(r==="stats"){const l=[...K(i.userDir()).lessons,...K(D).lessons],{count:c,helpful:m,harmful:y}=nu(l),p=te(i.root,f),E=pu(cu(D),B.root,f),_=du(E),j=g?.sections??i.preview(t.cwd),L=l.filter(o=>o.status==="active"&&o.helpful>0).sort((o,x)=>x.helpful-o.helpful).slice(0,3),w=l.filter(o=>o.status==="active"&&o.harmful>0&&!Wu(o)),b=[F(e("\u7ECF\u9A8C\uFF1A\u5DF2\u542F\u7528 {active} \xB7 \u5F85\u786E\u8BA4 {awaiting} \xB7 \u89C2\u5BDF\u4E2D {candidate} \xB7 \u5DF2\u9000\u5F79 {retired} \xB7 \u5DF2\u64A4\u9500 {undone} \xB7 \u5DF2\u8FC7\u671F {expired}"),{expired:c("expired"),active:c("active"),awaiting:c("awaiting_user"),candidate:c("candidate"),retired:c("retired"),undone:c("undone")}),F(e("\u6548\u679C\uFF08\u5728\u7528\u7684\u7ECF\u9A8C\uFF09\uFF1A\u5E2E\u4E0A\u5FD9 {helpful} \u6B21 \xB7 \u5E2E\u5012\u5FD9 {harmful} \u6B21"),{helpful:m,harmful:y}),F(e("\u9879\u76EE\u5730\u56FE\uFF1A{facts} \u6761\u4E8B\u5B9E\u53EF\u7528 \xB7 {stale} \u6761\u5DF2\u8FC7\u65F6\u5F85\u5237\u65B0"),{facts:_.facts,stale:E.stale.length}),F(e("\u672C\u4F1A\u8BDD\u6CE8\u5165\uFF1A\u7ECF\u9A8C\u7EA6 {lt} tokens \xB7 \u9879\u76EE\u5730\u56FE\u7EA6 {mt} tokens"),{lt:j?.lessonTokens??0,mt:j?.mapTokens??0}),F(e("\u4ECA\u5929\u7684\u63D0\u70BC\u8C03\u7528\uFF1A{runs}/{cap}\uFF08\u8F93\u5165 {input} \xB7 \u8F93\u51FA {output} tokens\uFF09"),{runs:p.runs,cap:i.dailyCap,input:p.inputTokens,output:p.outputTokens}),...L.length>0?[e("\u6700\u6709\u7528\uFF1A"),...L.map(o=>` [${o.id}] +${o.helpful} ${o.content}`)]:[],...w.length>0?[e("\u7559\u610F\uFF08\u5E2E\u5012\u5FD9\u8FC7\uFF09\uFF1A"),...w.map(o=>` [${o.id}] -${o.harmful} ${o.content}`)]:[]],N=l.filter(o=>o.status==="retired");N.length>0&&b.push(e("\u5DF2\u9000\u5F79\uFF1A"),...N.map(o=>` [${o.id}] ${o.retiredReason==="harmful"?e("\u5E2E\u5012\u5FD9\u591A\u4E8E\u5E2E\u5FD9"):e("\u957F\u671F\u6CA1\u6709\u7528\u4E0A")} \xB7 +${o.helpful}/-${o.harmful} \xB7 ${o.content}`)),A(t,b.join(`
14
+ `));return}if(r==="undo"&&/^s-\d{4,6}$/.test(k[0]??"")){const l=k[0],c=Qu(i.root,D,l,f);if(c.kind==="not_latest"){A(t,F(e("\u8FD9\u4E2A\u6280\u80FD\u4E4B\u540E\u8FD8\u6709\u6539\u52A8 {newer}\uFF0C\u5148\u64A4\u9500\u5B83\uFF1A/lessons undo {newer}"),{newer:c.newer}));return}if(c.kind==="changed_outside"){A(t,F(e("\u6280\u80FD\u300C{name}\u300D\u5728\u91C7\u7528\u4E4B\u540E\u88AB\u624B\u52A8\u6539\u8FC7\uFF0C\u4E3A\u4E86\u4E0D\u8986\u76D6\u4F60\u7684\u4FEE\u6539\uFF0C\u6CA1\u6709\u64A4\u9500\u3002"),{name:c.skill}));return}if(c.kind==="not_found"){A(t,F(e("\u6CA1\u6709\u5DF2\u91C7\u7528\u7684\u6280\u80FD\u6539\u52A8 {id}"),{id:l}));return}n.emitHostEvent(U,{id:l,status:"undone",skill:c.draft.name}),A(t,F(e("\u5DF2\u64A4\u9500\u6280\u80FD\u6539\u52A8 [{id}]\uFF0C\u6280\u80FD\u56DE\u5230\u91C7\u7528\u4E4B\u524D\u7684\u7248\u672C\u3002"),{id:l})),c.draft.kind!=="improve"&&await au(t);return}if(r==="undo"||r==="approve"){const l=k[0]??"";if(!/^[lu]-\d{4,6}$/.test(l)){A(t,F(e("\u7528\u6CD5\uFF1A/lessons {sub} <id>\uFF08\u4F8B\u5982 l-0001\uFF09"),{sub:r}));return}const c=$(l);let m;if(Hu(c,y=>{const p=r==="undo"?Uu(y,l,f):Ku(y,l,f);return m=p.lesson,p.lesson?p.doc:void 0}),!m){A(t,F(e("\u6CA1\u6709\u627E\u5230\u7ECF\u9A8C {id}"),{id:l}));return}A(t,r==="undo"?F(e("\u5DF2\u64A4\u9500\u7ECF\u9A8C [{id}]\uFF0C\u4ECE\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u8D77\u4E0D\u518D\u4F7F\u7528\uFF0C\u4E5F\u4E0D\u4F1A\u518D\u6B21\u63D0\u8BAE\u3002"),{id:l}):F(e("\u5DF2\u542F\u7528\u7ECF\u9A8C [{id}]\uFF0C\u4ECE\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u8D77\u4EA4\u7ED9\u52A9\u624B\u3002"),{id:l}));return}if(r==="stats"){const l=[...W(i.userDir()).lessons,...W(D).lessons],{count:c,helpful:m,harmful:y}=su(l),p=ne(i.root,f),E=pu(cu(D),B.root,f),_=du(E),j=g?.sections??i.preview(t.cwd),L=l.filter(o=>o.status==="active"&&o.helpful>0).sort((o,x)=>x.helpful-o.helpful).slice(0,3),w=l.filter(o=>o.status==="active"&&o.harmful>0&&!Wu(o)),b=[F(e("\u7ECF\u9A8C\uFF1A\u5DF2\u542F\u7528 {active} \xB7 \u5F85\u786E\u8BA4 {awaiting} \xB7 \u89C2\u5BDF\u4E2D {candidate} \xB7 \u5DF2\u9000\u5F79 {retired} \xB7 \u5DF2\u64A4\u9500 {undone} \xB7 \u5DF2\u8FC7\u671F {expired}"),{expired:c("expired"),active:c("active"),awaiting:c("awaiting_user"),candidate:c("candidate"),retired:c("retired"),undone:c("undone")}),F(e("\u6548\u679C\uFF08\u5728\u7528\u7684\u7ECF\u9A8C\uFF09\uFF1A\u5E2E\u4E0A\u5FD9 {helpful} \u6B21 \xB7 \u5E2E\u5012\u5FD9 {harmful} \u6B21"),{helpful:m,harmful:y}),F(e("\u9879\u76EE\u5730\u56FE\uFF1A{facts} \u6761\u4E8B\u5B9E\u53EF\u7528 \xB7 {stale} \u6761\u5DF2\u8FC7\u65F6\u5F85\u5237\u65B0"),{facts:_.facts,stale:E.stale.length}),F(e("\u672C\u4F1A\u8BDD\u6CE8\u5165\uFF1A\u7ECF\u9A8C\u7EA6 {lt} tokens \xB7 \u9879\u76EE\u5730\u56FE\u7EA6 {mt} tokens"),{lt:j?.lessonTokens??0,mt:j?.mapTokens??0}),F(e("\u4ECA\u5929\u7684\u63D0\u70BC\u8C03\u7528\uFF1A{runs}/{cap}\uFF08\u8F93\u5165 {input} \xB7 \u8F93\u51FA {output} tokens\uFF09"),{runs:p.runs,cap:i.dailyCap,input:p.inputTokens,output:p.outputTokens}),...L.length>0?[e("\u6700\u6709\u7528\uFF1A"),...L.map(o=>` [${o.id}] +${o.helpful} ${o.content}`)]:[],...w.length>0?[e("\u7559\u610F\uFF08\u5E2E\u5012\u5FD9\u8FC7\uFF09\uFF1A"),...w.map(o=>` [${o.id}] -${o.harmful} ${o.content}`)]:[]],N=l.filter(o=>o.status==="retired");N.length>0&&b.push(e("\u5DF2\u9000\u5F79\uFF1A"),...N.map(o=>` [${o.id}] ${o.retiredReason==="harmful"?e("\u5E2E\u5012\u5FD9\u591A\u4E8E\u5E2E\u5FD9"):e("\u957F\u671F\u6CA1\u6709\u7528\u4E0A")} \xB7 +${o.helpful}/-${o.harmful} \xB7 ${o.content}`)),A(t,b.join(`
15
15
  `));return}if(r==="map"){const l=pu(cu(D),B.root,f),c=[du(l).text??e("\u9879\u76EE\u5730\u56FE\u8FD8\u662F\u7A7A\u7684\uFF1A\u6210\u529F\u8FD0\u884C\u6D4B\u8BD5/\u6784\u5EFA\u547D\u4EE4\u3001\u67E5\u627E\u5E76\u6253\u5F00\u6587\u4EF6\u540E\u4F1A\u81EA\u52A8\u8BB0\u4E0B\u3002")];l.stale.length>0&&c.push(e("\u5DF2\u8FC7\u65F6\uFF08\u4E0B\u6B21\u6210\u529F\u540E\u5237\u65B0\uFF09\uFF1A"),...l.stale.map(m=>` ${m.fact}`)),A(t,c.join(`
16
16
  `));return}if(r==="skills"){const l=lu(D).drafts.filter(p=>p.status==="proposed"),c=Eu(i.root).flatMap(p=>p.conflicts.map(E=>({record:p,conflict:E}))),m=Eu(i.root).filter(p=>p.tracking&&!p.tracking.settled);if(l.length===0&&c.length===0&&m.length===0){A(t,e("\u6CA1\u6709\u5F85\u91C7\u7528\u7684\u6280\u80FD\u63D0\u8BAE\u3002\u540C\u4E00\u5957\u6B65\u9AA4\u5728 3 \u4E2A\u4F1A\u8BDD\u91CC\u91CD\u590D\u540E\uFF0C\u4F1A\u6539\u8FDB\u76F8\u5173\u6280\u80FD\u6216\u8D77\u8349\u65B0\u6280\u80FD\u3002"));return}const y=l.map(wu);c.length>0&&y.push(e("\u672C\u673A\u8865\u5145\u4E0E\u539F\u6280\u80FD\u7684\u65B0\u7248\u51B2\u7A81\uFF08\u6682\u4E0D\u751F\u6548\uFF09\uFF1A"),...c.map(({record:p,conflict:E})=>` [${p.patches.find(_=>_.id===E.patchId)?.proposalId??E.patchId}] ${p.name} \xB7 ${E.section}`),e("\u4FDD\u7559\u5E76\u8DDF\u968F\u65B0\u7248\uFF1A/lessons skill keep <id> \xB7 \u4E0D\u8981\u4E86\uFF1A/lessons undo <id>")),m.length>0&&y.push(e("\u89C2\u5BDF\u6548\u679C\u4E2D\uFF08\u53D8\u5DEE\u4F1A\u81EA\u52A8\u9000\u56DE\u4E0A\u4E00\u7248\uFF09\uFF1A"),...m.map(p=>{const E=p.tracking?.uses??[],_=E.filter(j=>j.outcome!=="success").length;return` [${p.tracking?.proposalId}] ${p.name} \xB7 ${F(e("\u5DF2\u7528 {n} \u6B21\uFF0C{bad} \u6B21\u4E0D\u987A"),{n:E.length,bad:_})} \xB7 ${F(e("{n} \u4E2A\u7248\u672C"),{n:p.versions.length})}`})),y.push(e("\u91C7\u7528\uFF1A/lessons skill accept <id> [\u540D\u5B57] [--scope project|user] \xB7 \u4E22\u5F03\uFF1A/lessons skill discard <id> \xB7 \u64A4\u9500\u5DF2\u91C7\u7528\u7684\uFF1A/lessons undo <id>")),A(t,y.join(`
17
- `));return}if(r==="skill"){const l=k.filter(o=>o.startsWith("--")),c=k.indexOf("--scope"),m=c>=0?k[c+1]:void 0,y=k.filter((o,x)=>!o.startsWith("--")&&!(c>=0&&x===c+1)),[p="",E="",_]=y,j=M(Q(),"skills");if(p==="keep"){const o=await Ju(i.root,E,async x=>{const I=R().find(bu=>bu.name===x.name);return I?ru(t.cwd).text(I):U()?.load(x.name)},f);A(t,o.kind==="kept"?F(e("\u5DF2\u4FDD\u7559 {id} \u7684\u8865\u5145\uFF0C\u8DDF\u968F\u6280\u80FD\u300C{name}\u300D\u7684\u65B0\u7248\u751F\u6548\u3002"),{id:E,name:o.skill}):o.kind==="unreadable"?F(e("\u8BFB\u4E0D\u5230\u6280\u80FD\u300C{name}\u300D\u7684\u5F53\u524D\u5185\u5BB9\uFF0C\u7A0D\u540E\u518D\u8BD5\u3002"),{name:o.skill}):F(e("\u6CA1\u6709\u51B2\u7A81\u4E2D\u7684\u8865\u5145 {id}"),{id:E}));return}if(p==="export"){const o=(E||"").toLowerCase(),x=Gu(D,B.root,Ru,o,t.isProjectTrusted()),I={exported:F(e("\u5DF2\u628A\u9879\u76EE\u6280\u80FD {name} \u5BFC\u51FA\u5230\u9879\u76EE\u91CC\uFF1A{path}\uFF08\u53EF\u4EE5\u63D0\u4EA4\u8FDB\u4ED3\u5E93\u7ED9\u56E2\u961F\u7528\uFF09"),{name:o,path:x.kind==="exported"?x.path:""}),exists:F(e("\u9879\u76EE\u91CC\u5DF2\u6709\u540C\u540D\u6280\u80FD\uFF1A{path}"),{path:x.kind==="exists"?x.path:""}),untrusted:e("\u8FD9\u4E2A\u9879\u76EE\u8FD8\u6CA1\u6709\u88AB\u4FE1\u4EFB\uFF0C\u9879\u76EE\u91CC\u7684\u6280\u80FD\u4E0D\u4F1A\u52A0\u8F7D\uFF1B\u5148\u4FE1\u4EFB\u9879\u76EE\u518D\u5BFC\u51FA\u3002"),not_found:F(e("\u6CA1\u6709 DAL \u4E3A\u672C\u9879\u76EE\u4FDD\u5B58\u7684\u6280\u80FD {name}"),{name:o})};A(t,I[x.kind]);return}const L=lu(D).drafts.find(o=>o.id===E&&o.status==="proposed");if(!L||p!=="accept"&&p!=="discard"){A(t,e("\u7528\u6CD5\uFF1A/lessons skill accept|discard <id> [\u540D\u5B57] [--scope project|user] \xB7 keep <id> \xB7 export <\u540D\u5B57>\uFF08id \u89C1 /lessons skills\uFF09"));return}if(p==="discard"){Vu(D,o=>({...o,drafts:o.drafts.map(x=>x.id===E?{...x,status:"discarded"}:x)})),s.emitHostEvent(W,{id:E,status:"discarded",skill:L.name}),A(t,F(e("\u5DF2\u4E22\u5F03\u6280\u80FD\u8349\u7A3F {id}"),{id:E}));return}if(m!==void 0&&m!=="project"&&m!=="user"){A(t,e("\u8303\u56F4\u53EA\u80FD\u662F project \u6216 user"));return}if(L.risk&&L.risk.length>0&&!l.includes("--confirm")){const o=L.risk.map(I=>e(eu[I]??I)).join(e("\u3001")),x=F(e("\u8FD9\u4E2A\u6280\u80FD\u6539\u52A8\u6D89\u53CA{risk}\uFF0C\u786E\u5B9A\u91C7\u7528\u5417\uFF1F"),{risk:o});if(!(t.hasUI&&await t.ui.confirm(e("\u786E\u8BA4\u91C7\u7528"),x))){A(t,F(e("\u6D89\u53CA{risk}\uFF0C\u9700\u8981\u786E\u8BA4\uFF1A/lessons skill accept {id} --confirm"),{risk:o,id:E}));return}}const w=Yu({root:i.root,projectDir:D,projectKey:B.key,userSkillsDir:j,id:E,..._?{name:_}:{},...m?{scope:m}:{},now:f});if(w.kind==="bad_name"){A(t,e("\u6280\u80FD\u540D\u79F0\u65E0\u6548\uFF08\u4EC5\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u3001-\uFF0C\u226464 \u5B57\u7B26\uFF09\uFF1A"));return}if(w.kind==="name_taken"){A(t,F(e("\u6280\u80FD {name} \u5DF2\u5B58\u5728\uFF0C\u6362\u4E2A\u540D\u5B57\uFF1A/lessons skill accept {id} <\u540D\u5B57>"),{name:w.name,id:E}));return}if(w.kind==="stale"){A(t,F(e("\u6280\u80FD\u300C{name}\u300D\u5728\u63D0\u8BAE\u4E4B\u540E\u88AB\u6539\u8FC7\uFF0C\u8FD9\u6761\u6539\u52A8\u5BF9\u4E0D\u4E0A\u4E86\uFF1B\u4E22\u5F03\u5B83\uFF0C\u4E0B\u6B21\u4F1A\u6309\u65B0\u5185\u5BB9\u91CD\u65B0\u63D0\u8BAE\u3002"),{name:w.skill}));return}if(w.kind==="invalid"){A(t,F(e("\u6539\u52A8\u540E\u7684\u6280\u80FD\u300C{name}\u300D\u65E0\u6CD5\u6B63\u5E38\u52A0\u8F7D\uFF08{reason}\uFF09\uFF0C\u6CA1\u6709\u5199\u5165\u3002"),{name:w.skill,reason:w.reason}));return}if(w.kind==="not_found"){A(t,F(e("\u6CA1\u6709\u627E\u5230\u6280\u80FD\u63D0\u8BAE {id}"),{id:E}));return}s.emitHostEvent(W,{id:E,status:"accepted",skill:w.draft.name,paths:w.paths});const b=w.draft,N=b.kind==="improve"&&!b.target?.editable?e("\u4F5C\u4E3A\u672C\u673A\u8865\u5145\uFF0C\u539F\u6280\u80FD\u6587\u4EF6\u4E0D\u53D8"):w.paths.join("\u3001");A(t,b.kind==="improve"?F(e("\u5DF2\u91C7\u7528\u5BF9\u6280\u80FD\u300C{name}\u300D\u7684\u6539\u8FDB\uFF08{where}\uFF09\u3002\u4E4B\u540E\u4F1A\u89C2\u5BDF\u6548\u679C\uFF0C\u53D8\u5DEE\u4F1A\u81EA\u52A8\u9000\u56DE\uFF1B\u64A4\u9500\uFF1A/lessons undo {id}"),{name:b.target?.name??b.name,where:N,id:E}):F(e("\u5DF2\u91C7\u7528\u6280\u80FD {name}\uFF1A{path}"),{name:(_??b.name).toLowerCase(),path:w.paths.at(-1)??""})),(b.kind!=="improve"||b.target?.editable)&&await au(t);return}A(t,e("\u7528\u6CD5\uFF1A/lessons [stats|map|skills|undo <id>|approve <id>|skill accept|discard <id>]"))},"handler")})},"dalLearn")}C(iu,"ln"),d(iu,"createDalLearn");var ae=iu();export{Du as LESSONS_SECTION,Bu as MAP_SECTION,mu as SKILL_CONFLICT_EVENT,Au as SKILL_PROPOSAL_EVENT,W as SKILL_RESOLVED_EVENT,fu as SKILL_REVERTED_EVENT,Cu as TASK_NOTE_ENTRY,Z as classifySkill,iu as createDalLearn,ae as default,uu as pickDraftingModel};
17
+ `));return}if(r==="skill"){const l=k.filter(o=>o.startsWith("--")),c=k.indexOf("--scope"),m=c>=0?k[c+1]:void 0,y=k.filter((o,x)=>!o.startsWith("--")&&!(c>=0&&x===c+1)),[p="",E="",_]=y,j=M(K(),"skills");if(p==="keep"){const o=await qu(i.root,E,async x=>{const I=R().find(bu=>bu.name===x.name);return I?ru(t.cwd).text(I):H()?.load(x.name)},f);A(t,o.kind==="kept"?F(e("\u5DF2\u4FDD\u7559 {id} \u7684\u8865\u5145\uFF0C\u8DDF\u968F\u6280\u80FD\u300C{name}\u300D\u7684\u65B0\u7248\u751F\u6548\u3002"),{id:E,name:o.skill}):o.kind==="unreadable"?F(e("\u8BFB\u4E0D\u5230\u6280\u80FD\u300C{name}\u300D\u7684\u5F53\u524D\u5185\u5BB9\uFF0C\u7A0D\u540E\u518D\u8BD5\u3002"),{name:o.skill}):F(e("\u6CA1\u6709\u51B2\u7A81\u4E2D\u7684\u8865\u5145 {id}"),{id:E}));return}if(p==="export"){const o=(E||"").toLowerCase(),x=Ju(D,B.root,Ru,o,t.isProjectTrusted()),I={exported:F(e("\u5DF2\u628A\u9879\u76EE\u6280\u80FD {name} \u5BFC\u51FA\u5230\u9879\u76EE\u91CC\uFF1A{path}\uFF08\u53EF\u4EE5\u63D0\u4EA4\u8FDB\u4ED3\u5E93\u7ED9\u56E2\u961F\u7528\uFF09"),{name:o,path:x.kind==="exported"?x.path:""}),exists:F(e("\u9879\u76EE\u91CC\u5DF2\u6709\u540C\u540D\u6280\u80FD\uFF1A{path}"),{path:x.kind==="exists"?x.path:""}),untrusted:e("\u8FD9\u4E2A\u9879\u76EE\u8FD8\u6CA1\u6709\u88AB\u4FE1\u4EFB\uFF0C\u9879\u76EE\u91CC\u7684\u6280\u80FD\u4E0D\u4F1A\u52A0\u8F7D\uFF1B\u5148\u4FE1\u4EFB\u9879\u76EE\u518D\u5BFC\u51FA\u3002"),not_found:F(e("\u6CA1\u6709 DAL \u4E3A\u672C\u9879\u76EE\u4FDD\u5B58\u7684\u6280\u80FD {name}"),{name:o})};A(t,I[x.kind]);return}const L=lu(D).drafts.find(o=>o.id===E&&o.status==="proposed");if(!L||p!=="accept"&&p!=="discard"){A(t,e("\u7528\u6CD5\uFF1A/lessons skill accept|discard <id> [\u540D\u5B57] [--scope project|user] \xB7 keep <id> \xB7 export <\u540D\u5B57>\uFF08id \u89C1 /lessons skills\uFF09"));return}if(p==="discard"){Yu(D,o=>({...o,drafts:o.drafts.map(x=>x.id===E?{...x,status:"discarded"}:x)})),n.emitHostEvent(U,{id:E,status:"discarded",skill:L.name}),A(t,F(e("\u5DF2\u4E22\u5F03\u6280\u80FD\u8349\u7A3F {id}"),{id:E}));return}if(m!==void 0&&m!=="project"&&m!=="user"){A(t,e("\u8303\u56F4\u53EA\u80FD\u662F project \u6216 user"));return}if(L.risk&&L.risk.length>0&&!l.includes("--confirm")){const o=L.risk.map(I=>e(eu[I]??I)).join(e("\u3001")),x=F(e("\u8FD9\u4E2A\u6280\u80FD\u6539\u52A8\u6D89\u53CA{risk}\uFF0C\u786E\u5B9A\u91C7\u7528\u5417\uFF1F"),{risk:o});if(!(t.hasUI&&await t.ui.confirm(e("\u786E\u8BA4\u91C7\u7528"),x))){A(t,F(e("\u6D89\u53CA{risk}\uFF0C\u9700\u8981\u786E\u8BA4\uFF1A/lessons skill accept {id} --confirm"),{risk:o,id:E}));return}}const w=Gu({root:i.root,projectDir:D,projectKey:B.key,userSkillsDir:j,id:E,..._?{name:_}:{},...m?{scope:m}:{},now:f});if(w.kind==="bad_name"){A(t,e("\u6280\u80FD\u540D\u79F0\u65E0\u6548\uFF08\u4EC5\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u3001-\uFF0C\u226464 \u5B57\u7B26\uFF09\uFF1A"));return}if(w.kind==="name_taken"){A(t,F(e("\u6280\u80FD {name} \u5DF2\u5B58\u5728\uFF0C\u6362\u4E2A\u540D\u5B57\uFF1A/lessons skill accept {id} <\u540D\u5B57>"),{name:w.name,id:E}));return}if(w.kind==="stale"){A(t,F(e("\u6280\u80FD\u300C{name}\u300D\u5728\u63D0\u8BAE\u4E4B\u540E\u88AB\u6539\u8FC7\uFF0C\u8FD9\u6761\u6539\u52A8\u5BF9\u4E0D\u4E0A\u4E86\uFF1B\u4E22\u5F03\u5B83\uFF0C\u4E0B\u6B21\u4F1A\u6309\u65B0\u5185\u5BB9\u91CD\u65B0\u63D0\u8BAE\u3002"),{name:w.skill}));return}if(w.kind==="invalid"){A(t,F(e("\u6539\u52A8\u540E\u7684\u6280\u80FD\u300C{name}\u300D\u65E0\u6CD5\u6B63\u5E38\u52A0\u8F7D\uFF08{reason}\uFF09\uFF0C\u6CA1\u6709\u5199\u5165\u3002"),{name:w.skill,reason:w.reason}));return}if(w.kind==="not_found"){A(t,F(e("\u6CA1\u6709\u627E\u5230\u6280\u80FD\u63D0\u8BAE {id}"),{id:E}));return}n.emitHostEvent(U,{id:E,status:"accepted",skill:w.draft.name,paths:w.paths});const b=w.draft,N=b.kind==="improve"&&!b.target?.editable?e("\u4F5C\u4E3A\u672C\u673A\u8865\u5145\uFF0C\u539F\u6280\u80FD\u6587\u4EF6\u4E0D\u53D8"):w.paths.join("\u3001");A(t,b.kind==="improve"?F(e("\u5DF2\u91C7\u7528\u5BF9\u6280\u80FD\u300C{name}\u300D\u7684\u6539\u8FDB\uFF08{where}\uFF09\u3002\u4E4B\u540E\u4F1A\u89C2\u5BDF\u6548\u679C\uFF0C\u53D8\u5DEE\u4F1A\u81EA\u52A8\u9000\u56DE\uFF1B\u64A4\u9500\uFF1A/lessons undo {id}"),{name:b.target?.name??b.name,where:N,id:E}):F(e("\u5DF2\u91C7\u7528\u6280\u80FD {name}\uFF1A{path}"),{name:(_??b.name).toLowerCase(),path:w.paths.at(-1)??""})),(b.kind!=="improve"||b.target?.editable)&&await au(t);return}A(t,e("\u7528\u6CD5\uFF1A/lessons [stats|map|skills|undo <id>|approve <id>|skill accept|discard <id>]"))},"handler")})},"dalLearn")}C(iu,"dn"),d(iu,"createDalLearn");var Fe=iu();export{Du as LESSONS_SECTION,Bu as MAP_SECTION,mu as SKILL_CONFLICT_EVENT,Au as SKILL_PROPOSAL_EVENT,U as SKILL_RESOLVED_EVENT,fu as SKILL_REVERTED_EVENT,Cu as TASK_NOTE_ENTRY,Z as classifySkill,iu as createDalLearn,Fe as default,uu as pickDraftingModel};
@@ -1,3 +1,3 @@
1
- var V=Object.defineProperty;var c=(s,t)=>V(s,"name",{value:t,configurable:!0});var W=Object.defineProperty,f=c((s,t)=>W(s,"name",{value:t,configurable:!0}),"c");import{join as Z}from"node:path";import{riskOf as q}from"./safety.js";import{estimateTokens as A,num as k,readDoc as J,records as y,str as d,strList as L,updateDoc as Q}from"./store.js";const E=2,R=60,T=30,N=700,O=6,j=12,C=20,$=864e5,ss=["candidate","active","awaiting_user","retired","undone","expired"],es=["failure_then_fix","user_correction","repeated_detour","guard_denial","imported"],ts=["deletion","permissions","credentials","network","publishing"];function h(s){return Z(s,"lessons.json")}c(h,"D"),f(h,"lessonsPath");function H(s){const t=d(s.id,16),i=d(s.content,400);if(!/^[lu]-\d{4,6}$/.test(t)||!i)return;const n=ss.includes(s.status)?s.status:"candidate",e=s.fix,o=s.proof,r=s.origin;return{...s,id:t,scope:s.scope==="user"?"user":"project",section:d(s.section,40)||"general",content:i,rootCause:d(s.rootCause,400),...d(s.signature,300)?{signature:d(s.signature,300)}:{},...e&&typeof e.good=="string"?{fix:{intent:d(e.intent,20),bad:d(e.bad,200),good:d(e.good,200)}}:{},status:n,risk:L(s.risk,5,20).filter(a=>ts.includes(a)),sessions:L(s.sessions,j,80),evidence:y(s.evidence).map(a=>({sessionId:d(a.sessionId,80),at:d(a.at,32),signal:es.includes(a.signal)?a.signal:"user_correction",note:d(a.note,300)})).slice(-O),...o&&typeof o.at=="string"?{proof:{kind:o.kind==="outcome"?"outcome":"test",at:d(o.at,32),sessionId:d(o.sessionId,80),note:d(o.note,300)}}:{},helpful:k(s.helpful),harmful:k(s.harmful),feedback:y(s.feedback).filter(a=>a.tag==="helpful"||a.tag==="harmful").map(a=>({sessionId:d(a.sessionId,80),tag:a.tag,at:d(a.at,32),why:d(a.why,200)})).slice(-C),created:d(s.created,32),updated:d(s.updated,32),...d(s.activatedAt,32)?{activatedAt:d(s.activatedAt,32)}:{},...["sessions","proof","user","import"].includes(s.activatedBy)?{activatedBy:s.activatedBy}:{},...d(s.lastHelpfulAt,32)?{lastHelpfulAt:d(s.lastHelpfulAt,32)}:{},...d(s.retiredAt,32)?{retiredAt:d(s.retiredAt,32)}:{},...["harmful","unused","user"].includes(s.retiredReason)?{retiredReason:s.retiredReason}:{},...r&&r.kind==="desktop"?{origin:{kind:"desktop",projectId:d(r.projectId,32),ruleId:d(r.ruleId,16)}}:{}}}c(H,"z"),f(H,"parseLesson");function v(s){const t=y(s?.lessons).map(H).filter(o=>o!==void 0),i=t.reduce((o,r)=>Math.max(o,Number(r.id.slice(2))),0),n={},e=s?.imported;if(e&&typeof e=="object"&&!Array.isArray(e))for(const[o,r]of Object.entries(e))n[o]=L(r,1e3,16);return{nextId:Math.max(k(s?.nextId),i+1,1),lessons:t,imported:n}}c(v,"I"),f(v,"parseLessonsDoc");function M(s){return J(h(s),v).value}c(M,"W"),f(M,"readLessons");function B(s,t){return Q(h(s),v,t)}c(B,"Z"),f(B,"updateLessons");function I(s){return s.toLowerCase().replace(/[\s\p{P}\p{S}]+/gu,"")}c(I,"S"),f(I,"normalizeText");function b(s){const t=I(s),i=new Set;for(let n=0;n<t.length-1;n++)i.add(t.slice(n,n+2));return i}c(b,"R"),f(b,"bigrams");function x(s,t){const i=b(s),n=b(t);if(i.size===0||n.size===0)return I(s)===I(t)?1:0;let e=0;for(const o of i)n.has(o)&&e++;return 2*e/(i.size+n.size)}c(x,"U"),f(x,"similarity");const z=.72;function S(s,t){if(t.signature){const e=s.lessons.find(o=>o.signature===t.signature);if(e)return e}let i,n=0;for(const e of s.lessons){const o=x(e.content,t.content);o>n&&(i=e,n=o)}return n>=z?i:void 0}c(S,"Y"),f(S,"findMatch");function u(s){return new Date(s).toISOString()}c(u,"u"),f(u,"iso");function _(s,t){if(s.status!=="candidate")return s;const i=s.sessions.length>=E,n=s.proof!==void 0;return!i&&!n?s:s.risk.length>0?{...s,status:"awaiting_user",updated:u(t)}:{...s,status:"active",activatedAt:u(t),activatedBy:n&&!i?"proof":"sessions",updated:u(t)}}c(_,"_"),f(_,"promote");function F(s,t,i,n){const e=(t.confirms?s.lessons.find(a=>a.id===t.confirms):void 0)??S(s,t),o={sessionId:i,at:u(n),signal:t.signal,note:t.note.slice(0,300)};if(e){if(e.status==="undone"||e.status==="retired")return{doc:s,outcome:{kind:"suppressed",lesson:e}};const a=!e.sessions.includes(i);let l={...e,status:e.status==="expired"?"candidate":e.status,sessions:a?[...e.sessions,i].slice(-j):e.sessions,evidence:[...e.evidence,o].slice(-O),...t.proof&&!e.proof?{proof:{...t.proof,at:u(n),sessionId:i}}:{},updated:u(n)};l=_(l,n);const p=s.lessons.map(m=>m.id===e.id?l:m);return{doc:{...s,lessons:p},outcome:{kind:a?"confirmed":"repeated",lesson:l},...e.status!==l.status?{transition:{lesson:l,from:e.status,to:l.status}}:{}}}let r={id:`${t.scope==="user"?"u":"l"}-${String(s.nextId).padStart(4,"0")}`,scope:t.scope,section:t.section||"general",content:t.content,rootCause:t.rootCause,...t.signature?{signature:t.signature}:{},...t.fix?{fix:t.fix}:{},status:"candidate",risk:q(`${t.content}
2
- ${t.fix?.good??""}`),sessions:[i],evidence:[o],...t.proof?{proof:{...t.proof,at:u(n),sessionId:i}}:{},helpful:0,harmful:0,feedback:[],created:u(n),updated:u(n)};return r=_(r,n),{doc:{...s,nextId:s.nextId+1,lessons:[...s.lessons,r]},outcome:{kind:"created",lesson:r},...r.status!=="candidate"?{transition:{lesson:r,from:"candidate",to:r.status}}:{}}}c(F,"w"),f(F,"proposeLesson");function P(s,t,i){const n=s.lessons.find(o=>o.id===t);if(!n||n.status==="active")return{doc:s,lesson:n};const e={...n,status:"active",activatedAt:u(i),activatedBy:"user",updated:u(i)};return delete e.retiredAt,delete e.retiredReason,{doc:{...s,lessons:s.lessons.map(o=>o.id===t?e:o)},lesson:e}}c(P,"ee"),f(P,"approveLesson");function U(s,t,i){const n=s.lessons.find(o=>o.id===t);if(!n||n.status==="undone")return{doc:s,lesson:n};const e={...n,status:"undone",retiredAt:u(i),retiredReason:"user",updated:u(i)};return{doc:{...s,lessons:s.lessons.map(o=>o.id===t?e:o)},lesson:e}}c(U,"se"),f(U,"undoLesson");function Y(s,t,i,n){let e=0;const o=s.lessons.map(r=>{let a=r;for(const l of t.filter(p=>p.id===r.id))a.feedback.some(p=>p.sessionId===i&&p.tag===l.tag)||(e++,a={...a,helpful:a.helpful+(l.tag==="helpful"?1:0),harmful:a.harmful+(l.tag==="harmful"?1:0),feedback:[...a.feedback,{sessionId:i,tag:l.tag,at:u(n),why:l.why.slice(0,200)}].slice(-C),...l.tag==="helpful"?{lastHelpfulAt:u(n)}:{},updated:u(n)});return a});return{doc:e>0?{...s,lessons:o}:s,changed:e}}c(Y,"te"),f(Y,"applyFeedback");function w(s){return s.harmful>=2&&s.harmful>s.helpful}c(w,"G"),f(w,"isHarmful");function G(s,t){const i=[],n=s.lessons.map(e=>{let o;if(e.status==="active"&&w(e))o={...e,status:"retired",retiredAt:u(t),retiredReason:"harmful",updated:u(t)};else if(e.status==="active"){const r=Date.parse(e.lastHelpfulAt??e.activatedAt??e.created);Number.isFinite(r)&&t-r>R*$&&(o={...e,status:"retired",retiredAt:u(t),retiredReason:"unused",updated:u(t)})}else if(e.status==="candidate"){const r=Date.parse(e.updated||e.created);Number.isFinite(r)&&t-r>T*$&&(o={...e,status:"expired",updated:u(t)})}return o?(i.push({lesson:o,from:e.status,to:o.status}),o):e});return{doc:i.length>0?{...s,lessons:n}:s,transitions:i}}c(G,"ne"),f(G,"retireLessons");const K="Lessons learned from earlier sessions, applied automatically on evidence (two sessions or a passing check) or confirmed by the user. Apply one when the situation matches; the user's instructions and every protection come first. If a lesson is wrong here, say so and name its id.";function X(s,t=N){const i=[K],n=[];let e=A(K);for(const o of s){const r=o.lessons.filter(m=>m.status==="active").sort((m,g)=>m.id.localeCompare(g.id));if(r.length===0)continue;const a=`${o.label}:`,l=[];let p=A(a);for(const m of r){const g=`- [${m.id}] ${m.content.replace(/\s+/g," ")}`,D=A(g)+1;if(e+p+D>t)break;l.push(g),p+=D,n.push(m.id)}l.length!==0&&(i.push(a,...l),e+=p)}return n.length===0?{ids:n,tokens:0}:{text:i.join(`
3
- `),ids:n,tokens:e}}c(X,"oe"),f(X,"renderLessonsSection");export{T as CANDIDATE_EXPIRE_DAYS,E as CONFIRMATIONS_TO_ACTIVATE,N as LESSONS_TOKEN_BUDGET,z as SAME_LESSON_SIMILARITY,R as UNUSED_RETIRE_DAYS,Y as applyFeedback,P as approveLesson,S as findMatch,w as isHarmful,h as lessonsPath,v as parseLessonsDoc,F as proposeLesson,M as readLessons,X as renderLessonsSection,G as retireLessons,x as similarity,U as undoLesson,B as updateLessons};
1
+ var Q=Object.defineProperty;var c=(s,t)=>Q(s,"name",{value:t,configurable:!0});var V=Object.defineProperty,f=c((s,t)=>V(s,"name",{value:t,configurable:!0}),"c");import{join as W}from"node:path";import{riskOf as Z}from"./safety.js";import{estimateTokens as A,num as k,readDoc as q,records as y,str as d,strList as L,updateDoc as J}from"./store.js";const E=2,R=60,T=30,N=700,O=6,j=12,C=20,$=864e5,ss=["candidate","active","awaiting_user","retired","undone","expired"],es=["failure_then_fix","user_correction","repeated_detour","guard_denial","imported"],ts=["deletion","permissions","credentials","network","publishing"];function g(s){return W(s,"lessons.json")}c(g,"D"),f(g,"lessonsPath");function H(s){const t=d(s.id,16),r=d(s.content,400);if(!/^[lu]-\d{4,6}$/.test(t)||!r)return;const n=ss.includes(s.status)?s.status:"candidate",e=s.fix,o=s.proof,a=s.origin;return{...s,id:t,scope:s.scope==="user"?"user":"project",section:d(s.section,40)||"general",content:r,rootCause:d(s.rootCause,400),...d(s.signature,300)?{signature:d(s.signature,300)}:{},...e&&typeof e.good=="string"?{fix:{intent:d(e.intent,20),bad:d(e.bad,200),good:d(e.good,200)}}:{},status:n,risk:L(s.risk,5,20).filter(i=>ts.includes(i)),sessions:L(s.sessions,j,80),evidence:y(s.evidence).map(i=>({sessionId:d(i.sessionId,80),at:d(i.at,32),signal:es.includes(i.signal)?i.signal:"user_correction",note:d(i.note,300)})).slice(-O),...o&&typeof o.at=="string"?{proof:{kind:o.kind==="outcome"?"outcome":"test",at:d(o.at,32),sessionId:d(o.sessionId,80),note:d(o.note,300)}}:{},helpful:k(s.helpful),harmful:k(s.harmful),feedback:y(s.feedback).filter(i=>i.tag==="helpful"||i.tag==="harmful").map(i=>({sessionId:d(i.sessionId,80),tag:i.tag,at:d(i.at,32),why:d(i.why,200)})).slice(-C),created:d(s.created,32),updated:d(s.updated,32),...d(s.activatedAt,32)?{activatedAt:d(s.activatedAt,32)}:{},...["sessions","proof","user","import"].includes(s.activatedBy)?{activatedBy:s.activatedBy}:{},...d(s.lastHelpfulAt,32)?{lastHelpfulAt:d(s.lastHelpfulAt,32)}:{},...d(s.retiredAt,32)?{retiredAt:d(s.retiredAt,32)}:{},...["harmful","unused","user"].includes(s.retiredReason)?{retiredReason:s.retiredReason}:{},...a&&a.kind==="desktop"?{origin:{kind:"desktop",projectId:d(a.projectId,32),ruleId:d(a.ruleId,16)}}:{}}}c(H,"z"),f(H,"parseLesson");function v(s){const t=y(s?.lessons).map(H).filter(o=>o!==void 0),r=t.reduce((o,a)=>Math.max(o,Number(a.id.slice(2))),0),n={},e=s?.imported;if(e&&typeof e=="object"&&!Array.isArray(e))for(const[o,a]of Object.entries(e))n[o]=L(a,1e3,16);return{nextId:Math.max(k(s?.nextId),r+1,1),lessons:t,imported:n}}c(v,"I"),f(v,"parseLessonsDoc");function M(s){return q(g(s),v).value}c(M,"Q"),f(M,"readLessons");function B(s,t){return J(g(s),v,t)}c(B,"Z"),f(B,"updateLessons");function I(s){return s.toLowerCase().replace(/[\s\p{P}\p{S}]+/gu,"")}c(I,"S"),f(I,"normalizeText");function b(s){const t=I(s),r=new Set;for(let n=0;n<t.length-1;n++)r.add(t.slice(n,n+2));return r}c(b,"R"),f(b,"bigrams");function x(s,t){const r=b(s),n=b(t);if(r.size===0||n.size===0)return I(s)===I(t)?1:0;let e=0;for(const o of r)n.has(o)&&e++;return 2*e/(r.size+n.size)}c(x,"U"),f(x,"similarity");const z=.72;function S(s,t){if(t.signature){const e=s.lessons.find(o=>o.signature===t.signature);if(e)return e}let r,n=0;for(const e of s.lessons){const o=x(e.content,t.content);o>n&&(r=e,n=o)}return n>=z?r:void 0}c(S,"Y"),f(S,"findMatch");function u(s){return new Date(s).toISOString()}c(u,"u"),f(u,"iso");function _(s,t){if(s.status!=="candidate")return s;const r=s.sessions.length>=E,n=s.proof!==void 0;return!r&&!n?s:s.risk.length>0?{...s,status:"awaiting_user",updated:u(t)}:{...s,status:"active",activatedAt:u(t),activatedBy:n&&!r?"proof":"sessions",updated:u(t)}}c(_,"_"),f(_,"promote");function F(s,t,r,n){const e=(t.confirms?s.lessons.find(i=>i.id===t.confirms):void 0)??S(s,t),o={sessionId:r,at:u(n),signal:t.signal,note:t.note.slice(0,300)};if(e){if(e.status==="undone"||e.status==="retired")return{doc:s,outcome:{kind:"suppressed",lesson:e}};const i=!e.sessions.includes(r);let l={...e,status:e.status==="expired"?"candidate":e.status,sessions:i?[...e.sessions,r].slice(-j):e.sessions,evidence:[...e.evidence,o].slice(-O),...t.proof&&!e.proof?{proof:{...t.proof,at:u(n),sessionId:r}}:{},updated:u(n)};l=_(l,n);const p=s.lessons.map(m=>m.id===e.id?l:m);return{doc:{...s,lessons:p},outcome:{kind:i?"confirmed":"repeated",lesson:l},...e.status!==l.status?{transition:{lesson:l,from:e.status,to:l.status}}:{}}}let a={id:`${t.scope==="user"?"u":"l"}-${String(s.nextId).padStart(4,"0")}`,scope:t.scope,section:t.section||"general",content:t.content,rootCause:t.rootCause,...t.signature?{signature:t.signature}:{},...t.fix?{fix:t.fix}:{},status:"candidate",risk:Z(`${t.content}
2
+ ${t.fix?.good??""}`),sessions:[r],evidence:[o],...t.proof?{proof:{...t.proof,at:u(n),sessionId:r}}:{},helpful:0,harmful:0,feedback:[],created:u(n),updated:u(n)};return a=_(a,n),{doc:{...s,nextId:s.nextId+1,lessons:[...s.lessons,a]},outcome:{kind:"created",lesson:a},...a.status!=="candidate"?{transition:{lesson:a,from:"candidate",to:a.status}}:{}}}c(F,"w"),f(F,"proposeLesson");function P(s,t,r){const n=s.lessons.find(o=>o.id===t);if(!n||n.status==="active")return{doc:s,lesson:n};const e={...n,status:"active",activatedAt:u(r),activatedBy:"user",updated:u(r)};return delete e.retiredAt,delete e.retiredReason,{doc:{...s,lessons:s.lessons.map(o=>o.id===t?e:o)},lesson:e}}c(P,"ee"),f(P,"approveLesson");function U(s,t,r){const n=s.lessons.find(o=>o.id===t);if(!n||n.status==="undone")return{doc:s,lesson:n};const e={...n,status:"undone",retiredAt:u(r),retiredReason:"user",updated:u(r)};return{doc:{...s,lessons:s.lessons.map(o=>o.id===t?e:o)},lesson:e}}c(U,"se"),f(U,"undoLesson");function Y(s,t,r,n){let e=0;const o=s.lessons.map(a=>{let i=a;for(const l of t.filter(p=>p.id===a.id))i.feedback.some(p=>p.sessionId===r&&p.tag===l.tag)||(e++,i={...i,helpful:i.helpful+(l.tag==="helpful"?1:0),harmful:i.harmful+(l.tag==="harmful"?1:0),feedback:[...i.feedback,{sessionId:r,tag:l.tag,at:u(n),why:l.why.slice(0,200)}].slice(-C),...l.tag==="helpful"?{lastHelpfulAt:u(n)}:{},updated:u(n)});return i});return{doc:e>0?{...s,lessons:o}:s,changed:e}}c(Y,"te"),f(Y,"applyFeedback");function w(s){return s.harmful>=2&&s.harmful>s.helpful}c(w,"G"),f(w,"isHarmful");function G(s,t){const r=[],n=s.lessons.map(e=>{let o;if(e.status==="active"&&w(e))o={...e,status:"retired",retiredAt:u(t),retiredReason:"harmful",updated:u(t)};else if(e.status==="active"){const a=Date.parse(e.lastHelpfulAt??e.activatedAt??e.created);Number.isFinite(a)&&t-a>R*$&&(o={...e,status:"retired",retiredAt:u(t),retiredReason:"unused",updated:u(t)})}else if(e.status==="candidate"){const a=Date.parse(e.updated||e.created);Number.isFinite(a)&&t-a>T*$&&(o={...e,status:"expired",updated:u(t)})}return o?(r.push({lesson:o,from:e.status,to:o.status}),o):e});return{doc:r.length>0?{...s,lessons:n}:s,transitions:r}}c(G,"ne"),f(G,"retireLessons");const K="Lessons learned from earlier sessions, applied automatically on evidence (two sessions or a passing check) or confirmed by the user. Apply one when the situation matches; the user's instructions and every protection come first. If a lesson is wrong here, say so and name its id. When a lesson contradicts what the repository or the user shows now, trust the repository and the user: the lesson is outdated.";function X(s,t=N){const r=[K],n=[];let e=A(K);for(const o of s){const a=o.lessons.filter(m=>m.status==="active").sort((m,h)=>m.id.localeCompare(h.id));if(a.length===0)continue;const i=`${o.label}:`,l=[];let p=A(i);for(const m of a){const h=`- [${m.id}] ${m.content.replace(/\s+/g," ")}`,D=A(h)+1;if(e+p+D>t)break;l.push(h),p+=D,n.push(m.id)}l.length!==0&&(r.push(i,...l),e+=p)}return n.length===0?{ids:n,tokens:0}:{text:r.join(`
3
+ `),ids:n,tokens:e}}c(X,"oe"),f(X,"renderLessonsSection");export{T as CANDIDATE_EXPIRE_DAYS,E as CONFIRMATIONS_TO_ACTIVATE,N as LESSONS_TOKEN_BUDGET,z as SAME_LESSON_SIMILARITY,R as UNUSED_RETIRE_DAYS,Y as applyFeedback,P as approveLesson,S as findMatch,w as isHarmful,g as lessonsPath,v as parseLessonsDoc,F as proposeLesson,M as readLessons,X as renderLessonsSection,G as retireLessons,x as similarity,U as undoLesson,B as updateLessons};
@@ -0,0 +1,10 @@
1
+ var V=Object.defineProperty;var c=(n,o)=>V(n,"name",{value:o,configurable:!0});var x=Object.defineProperty,a=c((n,o)=>x(n,"name",{value:o,configurable:!0}),"a");import{existsSync as j,mkdirSync as O,readdirSync as $,readFileSync as g,rmSync as H,writeFileSync as B}from"node:fs";import{dirname as C,join as p}from"node:path";import{fileURLToPath as J}from"node:url";import{t as d}from"@dalcode/dal-pi-kit";const z="dal.evolve-patch/v1",L="evolved_rules",M=/^[a-z0-9][a-z0-9-]{2,63}$/,T=/^[a-z][a-z0-9_]{0,63}$/,I=1200,R=15e3,U=4e3;function b(n){const o=[];if(!n||typeof n!="object"||Array.isArray(n))return["not an object"];const t=n;switch(t.schema!==z&&o.push("schema"),(typeof t.id!="string"||!M.test(t.id))&&o.push("id"),(typeof t.title!="string"||!t.title.trim())&&o.push("title"),(!Array.isArray(t.targets)||t.targets.some(e=>typeof e!="string"))&&o.push("targets"),t.kind){case"rule":(typeof t.rule!="string"||!t.rule.trim()||t.rule.length>I)&&o.push("rule");break;case"skill":{const e=t.skill;(!e||typeof e.name!="string"||!/^[a-z0-9][a-z0-9-]{1,63}$/.test(e.name)||typeof e.description!="string"||!e.description.trim()||typeof e.body!="string"||e.body.length>R)&&o.push("skill");break}case"tool-description":(!t.tool||!T.test(t.tool.name??"")||typeof t.tool.description!="string"||!t.tool.description.trim()||t.tool.description.length>U)&&o.push("tool");break;case"tool-param":{const e=t.tool?.defaults;(!t.tool||!T.test(t.tool.name??"")||!e||typeof e!="object"||Object.keys(e).length===0||Object.entries(e).some(([r,i])=>!/^[a-zA-Z_][a-zA-Z0-9_]{0,40}$/.test(r)||!["string","number","boolean"].includes(typeof i)))&&o.push("tool");break}default:o.push("kind")}return o}c(b,"N"),a(b,"validatePatch");const K=p(C(J(import.meta.url)),"evolve-patches");function E(n){return p(n,"evolve","patches")}c(E,"D"),a(E,"userPatchesDir");function v(n){return p(n,"evolve","state.json")}c(v,"m"),a(v,"statePath");function F(n){try{const o=JSON.parse(g(v(n),"utf8"));return{overrides:o.overrides&&typeof o.overrides=="object"?o.overrides:{}}}catch{return{overrides:{}}}}c(F,"L"),a(F,"readState");function k(n,o,t){const e=F(n);e.overrides[o]=t,O(C(v(n)),{recursive:!0}),B(v(n),`${JSON.stringify(e,null," ")}
2
+ `)}c(k,"H"),a(k,"setPatchEnabled");function D(n,o){if(!j(n))return[];const t=[];for(const e of $(n).sort())if(e.endsWith(".json"))try{const r=JSON.parse(g(p(n,e),"utf8"));b(r).length===0&&t.push({patch:r,source:o})}catch{}return t}c(D,"A"),a(D,"readDir");function y(n,o={}){const t=F(n),e=new Map;for(const r of D(o.bundledDir??K,"bundled"))e.set(r.patch.id,r);for(const r of D(E(n),"user"))e.set(r.patch.id,r);return[...e.values()].map(r=>({...r,enabled:t.overrides[r.patch.id]??r.patch.enabled!==!1}))}c(y,"y"),a(y,"loadPatches");function S(n){const o=n.filter(t=>t.enabled&&t.patch.kind==="rule").map(t=>t.patch.rule);if(o.length!==0)return o.map(t=>`- ${t.trim().replace(/\n+/g," ")}`).join(`
3
+ `)}c(S,"V"),a(S,"rulesSection");function A(n,o){const t=new Map;for(const s of o)s.enabled&&s.patch.kind==="tool-description"&&s.patch.tool?.description&&t.set(s.patch.tool.name,s.patch.tool.description);const e=n;if(t.size===0||!e||!Array.isArray(e.tools))return;let r=!1;const i=e.tools.map(s=>{const u=s.function?.name;return u&&t.has(u)?(r=!0,{...s,function:{...s.function,description:t.get(u)}}):s.name&&t.has(s.name)?(r=!0,{...s,description:t.get(s.name)}):s});return r?{...e,tools:i}:void 0}c(A,"J"),a(A,"applyToolDescriptions");function P(n,o,t){const e=[];for(const r of t)if(!(!r.enabled||r.patch.kind!=="tool-param"||r.patch.tool?.name!==n))for(const[i,s]of Object.entries(r.patch.tool.defaults??{}))o[i]===void 0&&(o[i]=s,e.push(i));return e}c(P,"K"),a(P,"applyToolDefaults");function _(n,o){const t=o.filter(i=>i.enabled&&i.patch.kind==="skill"),e=p(n,"evolve","skills"),r=new Set(t.map(i=>i.patch.skill.name));if(j(e))for(const i of $(e))r.has(i)||H(p(e,i),{recursive:!0,force:!0});if(t.length!==0){for(const i of t){const s=i.patch.skill,u=p(e,s.name);O(u,{recursive:!0});const f=`---
4
+ name: ${s.name}
5
+ description: ${JSON.stringify(s.description)}
6
+ ---
7
+
8
+ ${s.body.trim()}
9
+ `,l=p(u,"SKILL.md");let h;try{h=g(l,"utf8")}catch{h=void 0}h!==f&&B(l,f)}return e}}c(_,"U"),a(_,"materializeSkills");const w=a((n,o)=>n.replace(/\{(\w+)\}/g,(t,e)=>e in o?String(o[e]):t),"fill");function N(n,o,t=process.env){const e=a(()=>t.DAL_EVOLVE_PATCHES==="off"||t.DAL_EVOLVE_PATCHES==="0","off");let r=[];const i=a(()=>{r=e()?[]:y(o)},"reload");i(),n.on("resources_discover",()=>{if(!e())try{const s=_(o,r);return s?{skillPaths:[s]}:void 0}catch{return}}),n.on("before_agent_start",s=>{const u=S(r);u&&(s.systemPromptOptions.sections[L]=u)}),n.on("before_provider_request",s=>A(s.payload,r)),n.on("tool_call",s=>{r.length&&P(s.toolName,s.input,r)}),n.registerCommand("evolve",{description:d("\u67E5\u770B\u6216\u5F00\u5173\u7ECF\u5BA1\u6838\u7684\u6539\u8FDB\u8865\u4E01\uFF08on|off <id>\uFF09"),handler:a(async(s,u)=>{const[f,l]=s.trim().split(/\s+/);if((f==="on"||f==="off")&&l){if(!y(o).some(m=>m.patch.id===l)){u.ui.notify(w(d("\u6CA1\u6709\u8FD9\u4E2A\u8865\u4E01\uFF1A{id}"),{id:l}),"warning");return}k(o,l,f==="on"),i(),u.ui.notify(w(f==="on"?d("\u5DF2\u5F00\u542F\u8865\u4E01 {id}\uFF0C\u4E0B\u4E00\u8F6E\u5BF9\u8BDD\u751F\u6548\u3002"):d("\u5DF2\u5173\u95ED\u8865\u4E01 {id}\uFF0C\u4E0B\u4E00\u8F6E\u5BF9\u8BDD\u751F\u6548\u3002"),{id:l}),"info");return}const h=y(o);if(h.length===0){u.ui.notify(d("\u6CA1\u6709\u5DF2\u5B89\u88C5\u7684\u6539\u8FDB\u8865\u4E01\u3002"),"info");return}u.ui.notify(h.map(m=>`[${m.patch.id}] ${m.enabled?d("\u5F00\u542F"):d("\u5173\u95ED")} \xB7 ${m.patch.kind} \xB7 ${m.patch.title}`).join(`
10
+ `),"info")},"handler")})}c(N,"W"),a(N,"registerEvolvePatches");export{L as EVOLVED_RULES_SECTION,z as PATCH_SCHEMA,P as applyToolDefaults,A as applyToolDescriptions,y as loadPatches,_ as materializeSkills,N as registerEvolvePatches,S as rulesSection,k as setPatchEnabled,E as userPatchesDir,b as validatePatch};
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-lsp",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -20,8 +20,8 @@
20
20
  ]
21
21
  },
22
22
  "dependencies": {
23
- "@dalcode/dal-bridge": "1.0.40",
24
- "@dalcode/dal-pi-kit": "1.0.40",
23
+ "@dalcode/dal-bridge": "1.0.42",
24
+ "@dalcode/dal-pi-kit": "1.0.42",
25
25
  "cross-spawn": "7.0.6",
26
26
  "typebox": "1.3.7",
27
27
  "typescript": "5.9.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-mcp",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -27,10 +27,10 @@
27
27
  ]
28
28
  },
29
29
  "dependencies": {
30
- "@dalcode/dal-bridge": "1.0.40",
31
- "@dalcode/dal-guard": "1.0.40",
32
- "@dalcode/dal-pi-kit": "1.0.40",
33
- "@dalcode/deepailab": "1.0.40",
30
+ "@dalcode/dal-bridge": "1.0.42",
31
+ "@dalcode/dal-guard": "1.0.42",
32
+ "@dalcode/dal-pi-kit": "1.0.42",
33
+ "@dalcode/deepailab": "1.0.42",
34
34
  "cross-spawn": "7.0.6"
35
35
  },
36
36
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-office",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -17,7 +17,7 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@dalcode/dal-pi-kit": "1.0.40",
20
+ "@dalcode/dal-pi-kit": "1.0.42",
21
21
  "docx": "9.7.1",
22
22
  "echarts": "6.1.0",
23
23
  "exceljs": "4.4.0",
@@ -5,6 +5,7 @@ export { detectDelimiter, parseDelimited } from "./extract/csv.js";
5
5
  export { sanitizeFilename } from "./paths.js";
6
6
  export { buildChartOption, chartHtml, renderChartSvg } from "./render/chart.js";
7
7
  export { CHART_FONT_FAMILY, CHART_TOKENS, type ChartThemeMode, echartsTheme } from "./render/chart-theme.js";
8
+ export { DECK_SOURCE_PROPERTY, type DeckSource, readDeckSource, writeDeckSource } from "./render/deck-source.js";
8
9
  export { type DocOutputInput, type DocSectionInput, type DocStyle, type DocTableInput, renderDocx, } from "./render/docx.js";
9
10
  export { applyDiagramStyle, DIAGRAM_ROLES, styleDiagramCell } from "./render/drawio-style.js";
10
11
  export { type ChartSpec, layoutSlides, renderPptx, resolveLayout, type ShapeSpec, type SlideElement, type TableSpec, type TextSpec, themeThumbnailSvg, } from "./render/pptx.js";
@@ -1 +1 @@
1
- var o=Object.defineProperty;var s=(e,a)=>o(e,"name",{value:a,configurable:!0});var m=Object.defineProperty,n=s((e,a)=>m(e,"name",{value:a,configurable:!0}),"n");import{THUMBNAIL_CHANNEL as l,thumbnailSvg as p}from"./render/thumbnails.js";import{clearPresentationPlan as f}from"./scratchpad.js";import{registerChartGenerate as d}from"./tools/chart-generate.js";import{registerDocGenerate as g}from"./tools/doc-generate.js";import{registerDocxEdit as S}from"./tools/docx-edit.js";import{registerDrawioGenerate as h}from"./tools/drawio-generate.js";import{registerMdGenerate as T}from"./tools/md-generate.js";import{registerPptGenerate as c}from"./tools/ppt-generate.js";import{registerPptPlan as y}from"./tools/ppt-plan.js";import{registerPptxEdit as u}from"./tools/pptx-edit.js";import{registerReadFile as E}from"./tools/read-file.js";import{registerSheetGenerate as A}from"./tools/sheet-generate.js";import{registerXlsxEdit as D}from"./tools/xlsx-edit.js";import{default as v}from"exceljs";import{default as _}from"jszip";import{detectDelimiter as N,parseDelimited as x}from"./extract/csv.js";import{sanitizeFilename as C}from"./paths.js";import{buildChartOption as H,chartHtml as L,renderChartSvg as M}from"./render/chart.js";import{CHART_FONT_FAMILY as P,CHART_TOKENS as I,echartsTheme as b}from"./render/chart-theme.js";import{renderDocx as O}from"./render/docx.js";import{applyDiagramStyle as R,DIAGRAM_ROLES as G,styleDiagramCell as F}from"./render/drawio-style.js";import{layoutSlides as Y,renderPptx as U,resolveLayout as w,themeThumbnailSvg as z}from"./render/pptx.js";import{THUMBNAIL_CHANNEL as B,thumbnailSvg as J}from"./render/thumbnails.js";import{renderXlsx as K}from"./render/xlsx.js";import{designTheme as X,inferStyle as Z,resolveStyle as j,STYLE_IDS as q,THEME_NAMES as Q,themePalettes as V}from"./themes.js";function i(e){y(e),c(e),g(e),T(e),A(e),d(e),h(e),E(e),S(e),u(e),D(e),e.events.on(l,a=>{const r=a;if(typeof r.ref!="string"||typeof r.reply!="function")return;const t=p(r.ref,r.title);t!==void 0&&r.reply(t)}),e.on("session_shutdown",async(a,r)=>{f(r.sessionManager.getSessionId())})}s(i,"T"),n(i,"officeExtension");export{P as CHART_FONT_FAMILY,I as CHART_TOKENS,G as DIAGRAM_ROLES,v as ExcelJS,_ as JSZip,q as STYLE_IDS,Q as THEME_NAMES,B as THUMBNAIL_CHANNEL,R as applyDiagramStyle,H as buildChartOption,L as chartHtml,i as default,X as designTheme,N as detectDelimiter,b as echartsTheme,Z as inferStyle,Y as layoutSlides,x as parseDelimited,M as renderChartSvg,O as renderDocx,U as renderPptx,K as renderXlsx,w as resolveLayout,j as resolveStyle,C as sanitizeFilename,F as styleDiagramCell,V as themePalettes,z as themeThumbnailSvg,J as thumbnailSvg};
1
+ var o=Object.defineProperty;var s=(e,a)=>o(e,"name",{value:a,configurable:!0});var m=Object.defineProperty,l=s((e,a)=>m(e,"name",{value:a,configurable:!0}),"n");import{THUMBNAIL_CHANNEL as n,thumbnailSvg as p}from"./render/thumbnails.js";import{clearPresentationPlan as f}from"./scratchpad.js";import{registerChartGenerate as S}from"./tools/chart-generate.js";import{registerDocGenerate as d}from"./tools/doc-generate.js";import{registerDocxEdit as c}from"./tools/docx-edit.js";import{registerDrawioGenerate as g}from"./tools/drawio-generate.js";import{registerMdGenerate as E}from"./tools/md-generate.js";import{registerPptGenerate as u}from"./tools/ppt-generate.js";import{registerPptPlan as h}from"./tools/ppt-plan.js";import{registerPptxEdit as T}from"./tools/pptx-edit.js";import{registerReadFile as D}from"./tools/read-file.js";import{registerSheetGenerate as y}from"./tools/sheet-generate.js";import{registerXlsxEdit as _}from"./tools/xlsx-edit.js";import{default as C}from"exceljs";import{default as A}from"jszip";import{detectDelimiter as v,parseDelimited as P}from"./extract/csv.js";import{sanitizeFilename as N}from"./paths.js";import{buildChartOption as R,chartHtml as x,renderChartSvg as H}from"./render/chart.js";import{CHART_FONT_FAMILY as L,CHART_TOKENS as M,echartsTheme as O}from"./render/chart-theme.js";import{DECK_SOURCE_PROPERTY as I,readDeckSource as b,writeDeckSource as G}from"./render/deck-source.js";import{renderDocx as F}from"./render/docx.js";import{applyDiagramStyle as Y,DIAGRAM_ROLES as U,styleDiagramCell as k}from"./render/drawio-style.js";import{layoutSlides as w,renderPptx as K,resolveLayout as X,themeThumbnailSvg as z}from"./render/pptx.js";import{THUMBNAIL_CHANNEL as B,thumbnailSvg as J}from"./render/thumbnails.js";import{renderXlsx as Z}from"./render/xlsx.js";import{designTheme as j,inferStyle as Q,resolveStyle as V,STYLE_IDS as W,THEME_NAMES as q,themePalettes as $}from"./themes.js";function i(e){h(e),u(e),d(e),E(e),y(e),S(e),g(e),D(e),c(e),T(e),_(e),e.events.on(n,a=>{const r=a;if(typeof r.ref!="string"||typeof r.reply!="function")return;const t=p(r.ref,r.title);t!==void 0&&r.reply(t)}),e.on("session_shutdown",async(a,r)=>{f(r.sessionManager.getSessionId())})}s(i,"T"),l(i,"officeExtension");export{L as CHART_FONT_FAMILY,M as CHART_TOKENS,I as DECK_SOURCE_PROPERTY,U as DIAGRAM_ROLES,C as ExcelJS,A as JSZip,W as STYLE_IDS,q as THEME_NAMES,B as THUMBNAIL_CHANNEL,Y as applyDiagramStyle,R as buildChartOption,x as chartHtml,i as default,j as designTheme,v as detectDelimiter,O as echartsTheme,Q as inferStyle,w as layoutSlides,P as parseDelimited,b as readDeckSource,H as renderChartSvg,F as renderDocx,K as renderPptx,Z as renderXlsx,X as resolveLayout,V as resolveStyle,N as sanitizeFilename,k as styleDiagramCell,$ as themePalettes,z as themeThumbnailSvg,J as thumbnailSvg,G as writeDeckSource};
@@ -0,0 +1,10 @@
1
+ import type JSZip from "jszip";
2
+ import type { OfficePresentationPlan } from "../scratchpad.js";
3
+ export declare const DECK_SOURCE_PROPERTY = "DalOfficeDeckSource";
4
+ export interface DeckSource {
5
+ readonly version: 1;
6
+ readonly style: string;
7
+ readonly plan: OfficePresentationPlan;
8
+ }
9
+ export declare function writeDeckSource(zip: JSZip, source: DeckSource): Promise<void>;
10
+ export declare function readDeckSource(zip: JSZip): Promise<DeckSource | undefined>;
@@ -0,0 +1,2 @@
1
+ var g=Object.defineProperty;var c=(e,t)=>g(e,"name",{value:t,configurable:!0});var $=Object.defineProperty,n=c((e,t)=>$(e,"name",{value:t,configurable:!0}),"i");const l="DalOfficeDeckSource",a="docProps/custom.xml",x="application/vnd.openxmlformats-officedocument.custom-properties+xml",f="http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",P="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",h="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes",D="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}",S=n(e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),"escapeXml"),v=n(e=>e.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g,(t,r)=>r.startsWith("#x")?String.fromCodePoint(Number.parseInt(r.slice(2),16)):r.startsWith("#")?String.fromCodePoint(Number.parseInt(r.slice(1),10)):{amp:"&",lt:"<",gt:">",quot:'"',apos:"'"}[r]??t),"decodeXml");async function u(e,t){const r=n(o=>`<property fmtid="${D}" pid="${o}" name="${l}"><vt:lpwstr>${S(JSON.stringify(t))}</vt:lpwstr></property>`,"property"),s=await e.file(a)?.async("string");let m;if(s){const o=s.replace(new RegExp(`<property\\b[^>]*name="${l}"[^>]*>[\\s\\S]*?</property>`),""),i=[...o.matchAll(/\bpid="(\d+)"/g)].map(y=>Number(y[1])),p=r(Math.max(1,...i)+1);m=/<\/Properties>\s*$/.test(o)?o.replace(/<\/Properties>\s*$/,`${p}</Properties>`):o.replace(/<Properties\b([^>]*)\/>/,`<Properties$1>${p}</Properties>`)}else{m=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <Properties xmlns="${P}" xmlns:vt="${h}">${r(2)}</Properties>`;const o=await e.file("[Content_Types].xml")?.async("string")??"";o.includes(`PartName="/${a}"`)||e.file("[Content_Types].xml",o.replace(/<\/Types>\s*$/,`<Override PartName="/${a}" ContentType="${x}"/></Types>`));const i=await e.file("_rels/.rels")?.async("string")??"";if(!i.includes(f)){let p=1;for(;i.includes(`Id="rIdDalSrc${p}"`);)p++;e.file("_rels/.rels",i.replace(/<\/Relationships>\s*$/,`<Relationship Id="rIdDalSrc${p}" Type="${f}" Target="${a}"/></Relationships>`))}}e.file(a,m)}c(u,"h"),n(u,"writeDeckSource");async function d(e){const t=await e.file(a)?.async("string");if(!t)return;const r=new RegExp(`<property\\b[^>]*name="${l}"[^>]*>\\s*<vt:lpwstr>([\\s\\S]*?)</vt:lpwstr>`).exec(t);if(r)try{const s=JSON.parse(v(r[1]));return s&&s.version===1&&typeof s.style=="string"&&s.plan&&typeof s.plan.title=="string"&&Array.isArray(s.plan.slides)?s:void 0}catch{return}}c(d,"D"),n(d,"readDeckSource");export{l as DECK_SOURCE_PROPERTY,d as readDeckSource,u as writeDeckSource};
@@ -1,3 +1,3 @@
1
- var Pe=Object.defineProperty;var p=(e,t)=>Pe(e,"name",{value:t,configurable:!0});var Ye=Object.defineProperty,f=p((e,t)=>Ye(e,"name",{value:t,configurable:!0}),"u");import Ie from"jszip";import*as re from"pptxgenjs";import{designTheme as se}from"../themes.js";const ce=re.default??re,Oe=ce.default??ce,S=13.33,R=7.5,y=.75,g=S-2*y,De=.62,O=1.62,L=6.55,_="zzHeadFace",E="zzBodyFace",he="[\u5F85\u586B\u5199]";function D(e){return"content"in e}p(D,"X"),f(D,"isText");function G(e){return"chartType"in e}p(G,"K"),f(G,"isChart");function q(e){return"headers"in e&&"rows"in e}p(q,"Q"),f(q,"isTable");function Ge(e){return e}p(Ge,"Xe"),f(Ge,"text");function qe(e){return e}p(qe,"Ke"),f(qe,"shape");function W(e){return String(e).padStart(2,"0")}p(W,"R"),f(W,"marker");function v(e){return e?.trim()||void 0}p(v,"w"),f(v,"filled");function T(e,t){return(e??[]).map(n=>n.trim()).filter(n=>n.length>0).slice(0,t)}p(T,"M"),f(T,"cleanList");function ue(e){return/[⺀-鿿豈-﫿＀-￯ -〿]/u.test(e)?1:/[A-Z]/.test(e)?.72:/[0-9]/.test(e)?.58:e==="%"?.9:e===" "?.3:.56}p(ue,"fe"),f(ue,"charEm");function j(e){let t=0;for(const n of e)t+=ue(n);return t}p(j,"B"),f(j,"textEm");function P(e,t,n){const o=n*72/t*.96;return e.split(`
2
- `).reduce((i,a)=>i+Math.max(1,Math.ceil(j(a)/o)),0)}p(P,"_"),f(P,"wrappedLines");function $(e,t,n,o,i,a=1.2){for(let s=o;s>i;s-=1)if(P(e,s,t)*s*a*1.12/72<=n)return s;return i}p($,"z"),f($,"fitSize");function F(e,t,n,o,i,a=1.2){return e.reduce((s,r)=>Math.min(s,$(r,t,n,o,i,a)),o)}p(F,"E"),f(F,"fitAll");function k(e,t,n,o){const i=Math.max(j(e),1);return Math.max(o,Math.min(n,Math.floor(t*72/i)))}p(k,"C"),f(k,"fitLine");function Q(e){const t=/^(.{1,18}?)[::]\s*(.+)$/u.exec(e);if(t)return{lead:t[1].trim(),detail:t[2].trim()}}p(Q,"Z"),f(Q,"splitLead");function Y(e){const t=e.map(Q);return t.every(n=>n!==void 0)?t:void 0}p(Y,"D"),f(Y,"allLeads");const Ne=/^[-+约~≈]?[¥$¥€]?\d[\d,]*(\.\d+)?\s*(%|×|x|倍|pp|个百分点|万亿|亿元|万元|亿|万|千|元|k|m|b|天|小时|人|家|个|项|次|分)?\+?$/iu,Ve=/^(\d{4}(\s*年)?(\s*(Q[1-4]|H[12]|\d{1,2}\s*月))?|Q[1-4]|H[12]|\d{1,2}\s*月|第[一二三四五六七八九十\d]+(阶段|期|周|月|季度|年|步)|阶段\s*[一二三四五六七八九十\d]+|phase\s*\d+|M\d+|W\d+|day\s*\d+|D\d+|(近期|中期|远期|短期|长期)(\s*[((].*[))])?|本周|下周|本月|下月|本季度|下季度)$/iu;function U(e){if(e.length<2||e.length>4)return;const t=Y(e);if(!(!t||!t.every(n=>Ne.test(n.lead))))return t.map(n=>({value:n.lead,label:n.detail}))}p(U,"ee"),f(U,"inferStats");function X(e){if(e.length<2||e.length>6)return;const t=Y(e);return t?.every(n=>Ve.test(n.lead))?t:void 0}p(X,"te"),f(X,"inferTimeline");function K(e){if(e.length<4||e.length>9)return;const t=Y(e);if(!t)return;const n=[],o=new Map;for(const i of t){if(i.lead.length>10)return;o.has(i.lead)||(o.set(i.lead,[]),n.push(i.lead)),o.get(i.lead).push(i.detail)}if(!(n.length<2||n.length>3)&&!n.some(i=>o.get(i).length<2))return n.map(i=>({heading:i,points:o.get(i)}))}p(K,"ne"),f(K,"inferColumns");const _e=/^(.{1,14}?)[\s::]+[约~≈]?(-?\d[\d,]*(?:\.\d+)?)\s*(%|亿元|万元|元|亿|万|个|家|人|台|次|件|吨|天)?\s*([((].{0,12}[))])?$/u;function I(e){if(e.length<3||e.length>8)return;const t=e.map(i=>_e.exec(i));if(t.some(i=>i===null))return;const n=t,o=n[0][3]??"";if(!n.some(i=>(i[3]??"")!==o))return{type:"bar",categories:n.map(i=>i[1].trim()+(i[4]?i[4].replace(/[(())]/g,""):"")),series:[{name:"",values:n.map(i=>Number(i[2].replace(/,/g,"")))}],...o?{unit:o}:{}}}p(I,"I"),f(I,"inferChart");function de(e){if(!e||e.categories.length===0)return;const t=e.series.filter(n=>n.values.length===e.categories.length&&n.values.every(o=>Number.isFinite(o)));return t.length>0?{...e,series:t}:void 0}p(de,"ye"),f(de,"validChart");function pe(e){const t=(e??[]).filter(n=>n.value.trim()&&n.label.trim()).slice(0,4);return t.length>0?t:void 0}p(pe,"be"),f(pe,"validStats");function fe(e){const t=(e??[]).filter(n=>n.heading.trim()).slice(0,3);return t.length>=2?t:void 0}p(fe,"Se"),f(fe,"validColumns");function ye(e){if(!(!e||e.headers.length===0||e.rows.length===0))return{headers:e.headers.slice(0,8),rows:e.rows.slice(0,12).map(t=>t.slice(0,8))}}p(ye,"xe"),f(ye,"validTable");const Qe=/^(目录|目 录|议程|大纲|contents?|agenda|outline)$/iu,Ue=/(谢谢|感谢|致谢|thank|q\s*&\s*a|问答|结束)/iu,Xe=/^[“"「『].+[”"」』]$/u;function Z(e,t,n){const o=T(e.points,9),i=de(e.chart),a=pe(e.stats),s=fe(e.columns),r=ye(e.table),c=e.layout;if(c==="title"||t===0&&c===void 0)return{layout:"title"};switch(c){case"section":case"agenda":case"quote":case"closing":case"content":case"two-column":return{layout:c};case"chart":{const m=i??I(o);return m?{layout:"chart",chart:m}:{layout:"content"}}case"stats":{const m=a??U(o);return m?{layout:"stats",stats:m}:{layout:"content"}}case"comparison":{const m=s??K(o);return m?{layout:"comparison",columns:m}:{layout:"two-column"}}case"timeline":{const m=X(o)??(o.length>=2?o.map((x,w)=>({lead:W(w+1),detail:x})):void 0);return m?{layout:"timeline",timeline:m}:{layout:"content"}}case"table":return r?{layout:"table",table:r}:{layout:"content"}}if(i)return{layout:"chart",chart:i};if(a)return{layout:"stats",stats:a};if(s)return{layout:"comparison",columns:s};if(r)return{layout:"table",table:r};if(Qe.test(e.title.trim()))return{layout:"agenda"};const u=U(o);if(u)return{layout:"stats",stats:u};const h=X(o);if(h)return{layout:"timeline",timeline:h};const l=K(o);if(l)return{layout:"comparison",columns:l};const d=I(o);return d?{layout:"chart",chart:d}:o.length===0&&Xe.test(e.title.trim())?{layout:"quote"}:t===n-1&&t>0&&Ue.test(e.title)?{layout:"closing"}:{layout:"content"}}p(Z,"Ee"),f(Z,"resolveLayout");function C(e){return{x:0,y:0,w:S,h:R,fill:e,shape:"rect"}}p(C,"F"),f(C,"background");function A(e,t){const{t:n,slide:o}=e;t.push(C(n.bg)),n.topBand&&t.push({x:0,y:0,w:S,h:.16,fill:n.primary,shape:"rect"},{x:0,y:.16,w:S,h:.035,fill:n.accent,shape:"rect"}),e.tracker&&t.push({x:y,y:.34,w:8,h:.26,content:e.tracker,fontSize:11,color:n.primary,bold:!0,charSpacing:1});const i=.92,a=$(o.title,g,i,n.titleSize,18,1.15);t.push({x:y,y:De,w:g,h:i,content:o.title,fontSize:a,color:n.ink,bold:!0,valign:"middle",lineSpacingMultiple:1.05,font:"head"}),n.titleRule&&t.push({x:y,y:O,w:g,h:0,fill:n.line,shape:"line",lineWidth:.75});let s=O+.33;const r=v(o.subtitle);r&&(t.push({x:y,y:O+.2,w:g,h:.42,content:r,fontSize:k(r,g,16,12),color:n.muted,valign:"middle"}),s=O+.82);const c=v(o.source);return c&&t.push({x:y,y:6.95,w:g-1.2,h:.3,content:c,fontSize:9,color:n.muted,valign:"middle"}),t.push({x:S-y-1,y:6.95,w:1,h:.3,content:String(e.index+1),fontSize:10,color:n.muted,align:"right",valign:"middle"}),s}p(A,"L"),f(A,"contentChrome");function B(e,t,n){if(!t)return L;const o=L-.62;return n.push({x:y,y:o,w:g,h:.62,fill:e.surface,shape:e.radius>0?"roundRect":"rect",rectRadius:e.radius},{x:y+.25,y:o+.24,w:.14,h:.14,fill:e.accent,shape:"rect"},{x:y+.55,y:o,w:g-.8,h:.62,content:t,fontSize:k(t,g-.8,16,12),color:e.ink,bold:!0,valign:"middle"}),o-.25}p(B,"O"),f(B,"takeawayBand");function ge(e,t,n,o=1.4){return P(e,t,n)*t*o/72}p(ge,"ke"),f(ge,"blockHeight");function N(e,t,n,o){const i=k(e,n*.96,o,28),a=i>=o*.75?i:$(e,n,2.2,o,28,1.35),s=ge(e,a,n,1.4)+.05,r=3.45-(.3+s+(t?.3+.5:0))/2;return{size:a,top:r,titleY:r+.3,titleH:s,subtitleY:r+.3+s+.3}}p(N,"Y"),f(N,"coverGroup");function me(e){const{t,slide:n}=e,o=v(n.subtitle),i=[];switch(t.cover){case"dark-center":{i.push(C(t.inverseBg));const a=N(n.title,o,11.2,54);return i.push({x:1.06,y:a.titleY,w:11.2,h:a.titleH,content:n.title,fontSize:a.size,color:t.inverseInk,bold:!0,align:"center",lineSpacingMultiple:1.05,font:"head"},{x:S/2-.3,y:a.titleY+a.titleH+.08,w:.6,h:.04,fill:t.primary,shape:"rect"}),o&&i.push({x:1.06,y:a.subtitleY+.1,w:11.2,h:.6,content:o,fontSize:k(o,11.2,20,13),color:t.inverseMuted,align:"center"}),i}case"white-left":case"panel-right":{const a=t.cover==="panel-right",s=a?7.7:10.8;i.push(C(t.bg)),a?i.push({x:9,y:0,w:S-9,h:R,fill:t.inverseBg,shape:"rect"},{x:10.35,y:4.35,w:2.4,h:2.4,fill:t.accent,shape:"ellipse"},{x:9.55,y:1,w:1.1,h:1.1,fill:t.inverseMuted,shape:"ellipse",transparency:55}):i.push({x:y,y:6.7,w:g,h:0,fill:t.ink,shape:"line",lineWidth:1});const r=N(n.title,o,s,a?42:48);return i.push({x:y,y:r.top,w:.8,h:.08,fill:t.accent,shape:"rect"},{x:y,y:r.titleY,w:s,h:r.titleH,content:n.title,fontSize:r.size,color:t.ink,bold:!0,valign:"top",lineSpacingMultiple:1.05,font:"head"}),o&&i.push({x:y,y:r.subtitleY,w:s,h:.9,content:o,fontSize:$(o,s,.9,20,12),color:a?t.body:t.muted}),i}case"gov-band":return i.push(C(t.bg)),i.push({x:0,y:0,w:S,h:1.1,fill:t.primary,shape:"rect"},{x:0,y:1.1,w:S,h:.06,fill:t.accent,shape:"rect"},{x:0,y:R-.4,w:S,h:.4,fill:t.primary,shape:"rect"},{x:0,y:R-.46,w:S,h:.06,fill:t.accent,shape:"rect"}),i.push({x:y,y:2.3,w:g,h:1.8,content:n.title,fontSize:$(n.title,g,1.8,44,28,1.1),color:t.primary,bold:!0,align:"center",valign:"bottom",lineSpacingMultiple:1.05,font:"head"}),i.push({x:S/2-1.6,y:4.3,w:3.2,h:0,fill:t.accent,shape:"line",lineWidth:1.5}),o&&i.push({x:y,y:4.5,w:g,h:.6,content:o,fontSize:k(o,g,20,13),color:t.body,align:"center"}),i;default:{i.push(C(t.inverseBg));const a=N(n.title,o,10.6,48);return i.push({x:y,y:a.top,w:.9,h:.07,fill:t.accent,shape:"rect"},{x:y,y:a.titleY,w:10.6,h:a.titleH,content:n.title,fontSize:a.size,color:t.inverseInk,bold:!0,lineSpacingMultiple:1.05,font:"head"}),o&&i.push({x:y,y:a.subtitleY,w:10.6,h:.9,content:o,fontSize:$(o,10.6,.9,20,12),color:t.inverseMuted}),i.push({x:y,y:6.75,w:g,h:0,fill:t.inverseMuted,shape:"line",lineWidth:.75}),i}}}p(me,"Ce"),f(me,"coverElements");function xe(e){const{t,slide:n}=e,o=v(n.subtitle),i=[C(t.inverseBg)];return t.topBand&&i.push({x:0,y:R-.5,w:S,h:.06,fill:t.accent,shape:"rect"}),i.push({x:y,y:1.7,w:4,h:1.2,content:W(e.sectionOrdinal),fontSize:66,color:t.accent,bold:!0,font:"head"},{x:y+.05,y:3.1,w:1.2,h:.05,fill:t.accent,shape:"rect"},{x:y,y:3.35,w:10.8,h:1.3,content:n.title,fontSize:$(n.title,10.8,1.3,40,26,1.1),color:t.inverseInk,bold:!0,font:"head"}),o&&i.push({x:y,y:4.75,w:10.8,h:.6,content:o,fontSize:k(o,10.8,18,12),color:t.inverseMuted}),i}p(xe,"Te"),f(xe,"sectionElements");function we(e){const{t}=e,n=[],o=A(e,n),i=T(e.slide.points,8),a=i.length>0?i:e.sections.slice(0,8);if(a.length===0)return n.push({x:y,y:o,w:g,h:.6,content:he,fontSize:18,color:t.muted}),n;const s=Math.min(.82,(L-o)/a.length),r=y+1.6,c=g-1.6,u=F(a,c-1.1,s-.12,22,14);return a.forEach((h,l)=>{const d=o+l*s;n.push({x:r,y:d,w:.9,h:s,content:W(l+1),fontSize:u+2,color:t.primary,bold:!0,valign:"middle",font:"head"},{x:r+1.1,y:d,w:c-1.1,h:s,content:h,fontSize:u,color:t.ink,valign:"middle"},{x:r,y:d+s,w:c,h:0,fill:t.line,shape:"line",lineWidth:.75})}),n}p(we,"$e"),f(we,"agendaElements");function J(e,t,n=!1){const o=Q(e),i=n?t.inverseInk:t.ink,a=n?t.inverseMuted:t.body;return o?[{text:`${o.lead}\uFF1A`,options:{color:i,bold:!0}},{text:o.detail,options:{color:a}}]:[{text:e,options:{color:n?t.inverseInk:t.body}}]}p(J,"ie"),f(J,"pointRuns");function H(e,t,n,o,i,a,s,r=20){const c=Math.min(1.15,(a-o)/e.length),u=F(e,i-.45,c-.18,r,12,1.25);e.forEach((h,l)=>{const d=o+l*c,m=P(h,u,i-.45)*u*1.25/72,x=d+(c-m)/2+u*1.25/72/2;s.push({x:n,y:x-.055,w:.11,h:.11,fill:t.primary,shape:"rect"},{x:n+.35,y:d,w:i-.35,h:c,content:J(h,t),fontSize:u,valign:"middle",lineSpacingMultiple:1.15}),l<e.length-1&&s.push({x:n,y:d+c,w:i,h:0,fill:t.line,shape:"line",lineWidth:.5})})}p(H,"W"),f(H,"pointList");function ee(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i)+.1,s=B(n,v(o.takeaway),i),r=T(o.points,8);if(r.length===0)return i.push({x:y,y:a,w:g,h:.6,content:he,fontSize:18,color:n.muted}),i;const c=Y(r),u=s-a;if(!t&&c&&r.length>=2&&r.length<=3){const h=(g-.5*(r.length-1))/r.length,l=F(c.map(w=>w.lead),h,.95,26,16,1.15),d=F(c.map(w=>w.detail),h,u-1.75,19,12,1.35),m=Math.max(...c.map(w=>P(w.detail,d,h)*d*1.35/72)),x=a+Math.max(0,(u-1.75-m-.2)/3);return c.forEach((w,z)=>{const M=y+z*(h+.5);i.push({x:M,y:x+.1,w:h,h:.05,fill:z===0?n.primary:n.line,shape:"rect"},{x:M,y:x+.3,w:h,h:.4,content:W(z+1),fontSize:15,color:n.primary,bold:!0,font:"head"},{x:M,y:x+.75,w:h,h:.95,content:w.lead,fontSize:l,color:n.ink,bold:!0,lineSpacingMultiple:1.05,font:"head"},{x:M,y:x+1.75,w:h,h:s-x-1.75,content:w.detail,fontSize:d,color:n.body,lineSpacingMultiple:1.25})}),i}if(!t&&c&&r.length===4){const h=(g-.6)/2,l=(u-.3)/2,d=F(c.map(x=>x.lead),h-.9,.5,20,14),m=F(c.map(x=>x.detail),h-.9,l-.8,16,11,1.3);return i.push({x:y+h+.3,y:a,w:0,h:u,fill:n.line,shape:"line",lineWidth:.75},{x:y,y:a+l+.15,w:g,h:0,fill:n.line,shape:"line",lineWidth:.75}),c.forEach((x,w)=>{const z=y+w%2*(h+.6),M=a+Math.floor(w/2)*(l+.3)+.1;i.push({x:z,y:M,w:.8,h:.55,content:W(w+1),fontSize:24,color:n.primary,bold:!0,font:"head"},{x:z+.9,y:M,w:h-.9,h:.55,content:x.lead,fontSize:d,color:n.ink,bold:!0,valign:"middle",font:"head"},{x:z+.9,y:M+.65,w:h-.9,h:l-.8,content:x.detail,fontSize:m,color:n.body,lineSpacingMultiple:1.2})}),i}if(t||r.length>5){const h=Math.ceil(r.length/2),l=(g-.6)/2;return H(r.slice(0,h),n,y,a,l,s,i,18),r.length>h&&H(r.slice(h),n,y+l+.6,a,l,s,i,18),i}return H(r,n,y,a,g*.86,s,i),i}p(ee,"oe"),f(ee,"contentElements");function be(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),s=B(n,v(o.takeaway),i),r=g/t.length,c=2.7,u=a+Math.max(.2,(s-a-c)/2),h=Math.min(...t.map(d=>k(d.value,r-.5,t.length<=2?80:64,28))),l=F(t.map(d=>d.label),r-.5,.8,18,12);return t.forEach((d,m)=>{const x=y+m*r;m>0&&i.push({x,y:u,w:0,h:c,fill:n.line,shape:"line",lineWidth:.75});const w=m>0?.4:0;i.push({x:x+w,y:u,w:r-w-.1,h:1.35,content:d.value,fontSize:h,color:m===0?n.primary:n.ink,bold:!0,valign:"bottom",font:"head"},{x:x+w,y:u+1.5,w:r-w-.3,h:.8,content:d.label,fontSize:l,color:n.ink,bold:!0});const z=v(d.note);z&&i.push({x:x+w,y:u+2.3,w:r-w-.3,h:.4,content:z,fontSize:12,color:n.muted})}),i}p(be,"Fe"),f(be,"statsElements");function ve(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),s=v(o.takeaway),r=T(o.points,8),c=s||I(r)?[]:r.slice(0,3),u=s!==void 0||c.length>0,h=u?g*.64:g;let l=a;t.unit&&(i.push({x:y,y:a-.05,w:4,h:.3,content:`${/[\u3400-\u9fff]/u.test(o.title)?"\u5355\u4F4D\uFF1A":"Unit: "}${t.unit}`,fontSize:11,color:n.muted}),l+=.3);const d=t.type==="pie"||t.type==="doughnut",m=Math.max(...t.categories.map(x=>j(x)))>6||t.categories.length>8;if(i.push({x:y-.1,y:l,w:h,h:L-l,chartType:t.type,categories:t.categories,series:t.series,colors:d||t.series.length>1?n.chart:[n.primary],labelColor:n.muted,valueColor:n.ink,gridColor:n.line,horizontal:!d&&t.type!=="line"&&m}),u){const x=y+g*.69,w=g*.31;i.push({x:x-.3,y:a,w:0,h:L-a,fill:n.line,shape:"line",lineWidth:.75}),s?i.push({x,y:a+.1,w:.5,h:.05,fill:n.accent,shape:"rect"},{x,y:a+.35,w,h:L-a-.5,content:s,fontSize:$(s,w,L-a-.5,22,14,1.3),color:n.ink,bold:!0,lineSpacingMultiple:1.2,font:"head"}):H(c,n,x,a,w,Math.min(L,a+c.length*1.1),i,16)}return i}p(ve,"Me"),f(ve,"chartElements");function Se(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i)+.05,s=B(n,v(o.takeaway),i),r=.4,c=(g-r*(t.length-1))/t.length,u=.62;return t.forEach((h,l)=>{const d=y+l*(c+r),m=l===t.length-1;i.push({x:d,y:a,w:c,h:u,fill:m?n.primary:n.surface,shape:n.radius>0?"roundRect":"rect",rectRadius:n.radius},{x:d+.3,y:a,w:c-.6,h:u,content:h.heading,fontSize:k(h.heading,c-.6,20,13),color:m?n.inverseInk:n.ink,bold:!0,valign:"middle",font:"head"});const x=T(h.points,5);x.length>0&&H(x,n,d+.15,a+u+.15,c-.15,s,i,18)}),i}p(Se,"Le"),f(Se,"comparisonElements");function ze(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),s=B(n,v(o.takeaway),i),r=g/t.length,c=a+Math.max(1.35,(s-a)*.4);i.push({x:y,y:c,w:g,h:0,fill:n.line,shape:"line",lineWidth:1.5});const u=F(t.map(l=>l.lead),r-.2,.6,26,14),h=F(t.map(l=>l.detail),r-.3,s-c-.5,19,11,1.3);return t.forEach((l,d)=>{const m=y+r*(d+.5),x=d===t.length-1;i.push({x:m-r/2+.1,y:c-1,w:r-.2,h:.6,content:l.lead,fontSize:u,color:x?n.accent:n.primary,bold:!0,align:"center",valign:"bottom",font:"head"},{x:m-.14,y:c-.14,w:.28,h:.28,fill:x?n.accent:n.primary,shape:"ellipse"},{x:m-r/2+.15,y:c+.4,w:r-.3,h:s-c-.5,content:l.detail,fontSize:h,color:n.body,align:"center",lineSpacingMultiple:1.2})}),i}p(ze,"Pe"),f(ze,"timelineElements");function $e(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),s=B(n,v(o.takeaway),i),r=t.rows.length,c=r<=5?15:r<=8?13:11,u=Math.min(.55,(s-a)/(r+1));return i.push({x:y,y:a,w:g,h:u*(r+1),headers:t.headers,rows:t.rows,fontSize:c,headerFill:n.primary,headerColor:n.inverseInk,stripeFill:n.surface,bodyColor:n.body,lineColor:n.line}),i}p($e,"Re"),f($e,"tableElements");function Fe(e){const{t,slide:n}=e,o=n.title.trim().replace(/^[“"「『]|[”"」』]$/gu,""),i=v(n.subtitle),a=[C(t.bg)];return t.topBand&&a.push({x:0,y:0,w:S,h:.16,fill:t.primary,shape:"rect"}),a.push({x:y+.6,y:.9,w:2,h:1.6,content:"\u201C",fontSize:140,color:t.accent,bold:!0,font:"head"},{x:y+1,y:2.35,w:g-2,h:2.6,content:o,fontSize:$(o,g-2,2.6,34,20,1.3),color:t.ink,bold:!0,lineSpacingMultiple:1.2,font:"head"}),i&&a.push({x:y+1,y:5.3,w:.5,h:.04,fill:t.primary,shape:"rect"},{x:y+1,y:5.45,w:g-2,h:.5,content:i,fontSize:16,color:t.muted}),a}p(Fe,"He"),f(Fe,"quoteElements");function Me(e){const{t,slide:n}=e,o=T(n.points,5),i=[C(t.inverseBg)];if(o.length===0){i.push({x:y,y:2.6,w:g,h:1.6,content:n.title,fontSize:$(n.title,g,1.6,54,28,1.1),color:t.inverseInk,bold:!0,align:"center",valign:"middle",font:"head"});const c=v(n.subtitle);return c&&i.push({x:y,y:4.3,w:g,h:.6,content:c,fontSize:k(c,g,18,12),color:t.inverseMuted,align:"center"}),i}i.push({x:y,y:.85,w:.9,h:.07,fill:t.accent,shape:"rect"},{x:y,y:1.05,w:g,h:1.4,content:n.title,fontSize:$(n.title,g,1.4,34,22,1.15),color:t.inverseInk,bold:!0,lineSpacingMultiple:1.1,font:"head"});const a=2.95,s=Math.min(.85,(6.7-a)/o.length),r=F(o,g-1.1,s-.15,20,13);return o.forEach((c,u)=>{const h=a+u*s;i.push({x:y,y:h,w:.9,h:s,content:W(u+1),fontSize:r+2,color:t.accent,bold:!0,valign:"middle",font:"head"},{x:y+1,y:h,w:g-1,h:s,content:J(c,t,!0),fontSize:r,valign:"middle"},{x:y,y:h+s,w:g,h:0,fill:t.inverseMuted,shape:"line",lineWidth:.5,transparency:50})}),i}p(Me,"Oe"),f(Me,"closingElements");function te(e,t,n=""){const o=se(t,`${e.title} ${n}`),i=e.slides.length,a=e.slides.map((u,h)=>Z(u,h,i)),s=e.slides.filter((u,h)=>a[h].layout==="section").map(u=>u.title.trim());let r,c=0;return{slides:e.slides.map((u,h)=>{const l=a[h];l.layout==="section"&&(c+=1,r=u.title.trim());const d={t:o,slide:u,deckTitle:e.title,index:h,total:i,tracker:r,sections:s,sectionOrdinal:c};switch(l.layout){case"title":return me(d);case"section":return xe(d);case"agenda":return we({...d,tracker:void 0});case"stats":return be(d,l.stats);case"chart":return ve(d,l.chart);case"comparison":return Se(d,l.columns);case"timeline":return ze(d,l.timeline);case"table":return $e(d,l.table);case"quote":return Fe(d);case"closing":return Me(d);case"two-column":return ee(d,!0);default:return ee(d,!1)}}),layouts:a}}p(te,"re"),f(te,"layoutDeck");function ne(e,t,n=""){return te(e,t,n).slides}p(ne,"We"),f(ne,"layoutSlides");function ke(e,t){const n=T(e.points,20);return n.length===0?[]:e.stats||e.chart||e.columns||e.table?t.layout==="chart"&&!v(e.takeaway)&&!I(n)?n.slice(3):["stats","chart","comparison","table"].includes(t.layout)?n:[]:[]}p(ke,"Ae"),f(ke,"displacedPoints");function Ce(e){if(e.chartType==="pie"||e.chartType==="doughnut"){const t=e.series[0];return[{name:t.name,labels:e.categories,values:t.values}]}return e.series.map(t=>({name:t.name||" ",labels:e.categories,values:t.values}))}p(Ce,"Be"),f(Ce,"chartData");function Le(e){const t={x:e.x,y:e.y,w:e.w,h:e.h,chartColors:e.colors,catAxisLabelColor:e.labelColor,valAxisLabelColor:e.labelColor,catAxisLabelFontFace:E,valAxisLabelFontFace:E,dataLabelFontFace:E,legendFontFace:E,catAxisLabelFontSize:12,valAxisLabelFontSize:11,dataLabelFontSize:12,legendFontSize:12,legendColor:e.labelColor,dataLabelColor:e.valueColor,showLegend:e.series.length>1,legendPos:"t",showTitle:!1};switch(e.chartType){case"pie":case"doughnut":return{...t,holeSize:62,showLegend:!0,legendPos:"r",legendFontSize:16,showPercent:!0,showValue:!1,dataLabelColor:"FFFFFF",dataLabelFontSize:13,dataLabelFontBold:!0,dataBorder:{pt:1.5,color:"FFFFFF"}};case"line":return{...t,lineSize:3,lineDataSymbol:"circle",lineDataSymbolSize:8,showValue:e.series.length===1&&e.categories.length<=8,dataLabelPosition:"t",valGridLine:{color:e.gridColor,style:"solid",size:.5},catGridLine:{style:"none"},catAxisLineColor:e.gridColor,valAxisHidden:!1,valAxisLineShow:!1};default:return{...t,barDir:e.horizontal?"bar":"col",barGrouping:e.chartType==="stacked"?"stacked":"clustered",barGapWidthPct:55,showValue:!0,dataLabelPosition:e.chartType==="stacked"?"ctr":"outEnd",dataLabelFormatCode:"#,##0.##",valAxisHidden:!0,valGridLine:{style:"none"},catGridLine:{style:"none"},catAxisLineColor:e.gridColor,catAxisOrientation:e.horizontal?"maxMin":"minMax"}}}p(Le,"_e"),f(Le,"chartOptions");function Ee(e){return e==="line"?"line":e==="pie"?"pie":e==="doughnut"?"doughnut":"bar"}p(Ee,"De"),f(Ee,"chartKind");const Ke=/^[-+]?[¥$¥€]?\d[\d,]*(\.\d+)?\s*(%|pp|万|亿|元|万元|亿元)?$/u;function Te(e){const t=f(i=>[{type:"none"},{type:"none"},{pt:.75,color:i},{type:"none"}],"border"),n=e.headers.map((i,a)=>({text:i,options:{bold:!0,color:e.headerColor,fill:{color:e.headerFill},align:a===0?"left":"center",border:t(e.headerFill)}})),o=e.rows.map((i,a)=>e.headers.map((s,r)=>{const c=i[r]??"";return{text:c,options:{color:e.bodyColor,fill:{color:a%2===1?e.stripeFill:"FFFFFF"},align:r>0&&Ke.test(c.trim())?"right":"left",border:t(e.lineColor)}}}));return[n,...o]}p(Te,"Ne"),f(Te,"tableRows");async function Ae(e,t){const n=await Ie.loadAsync(e),o={[_]:t.headFont,[E]:t.bodyFont},i=new RegExp(`<a:(latin|ea|cs) typeface="(${_}|${E})"`,"g"),a=Object.keys(n.files).filter(r=>/^ppt\/(slides|charts|notesSlides)\/[^/]+\.xml$/.test(r));for(const r of a){const c=await n.file(r).async("string"),u=c.replace(i,(h,l,d)=>{const m=o[d];return`<a:${l} typeface="${l==="ea"?m.ea:m.latin}"`});u!==c&&n.file(r,u)}const s=Object.keys(n.files).filter(r=>/^ppt\/theme\/theme\d+\.xml$/.test(r));for(const r of s){const c=await n.file(r).async("string"),u=f((l,d)=>l.replace(/<a:latin typeface="[^"]*"/,`<a:latin typeface="${d.latin}"`).replace(/<a:ea typeface="[^"]*"/,`<a:ea typeface="${d.ea}"`).replace(/<a:font script="Hans" typeface="[^"]*"/,`<a:font script="Hans" typeface="${d.ea}"`),"patchScheme"),h=c.replace(/<a:majorFont>[\s\S]*?<\/a:majorFont>/,l=>u(l,t.headFont)).replace(/<a:minorFont>[\s\S]*?<\/a:minorFont>/,l=>u(l,t.bodyFont));n.file(r,h)}return n.generateAsync({type:"nodebuffer",compression:"DEFLATE"})}p(Ae,"Ye"),f(Ae,"applyFonts");async function We(e,t,n=""){const o=se(t,`${e.title} ${n}`),i=new Oe;i.defineLayout({name:"W16x9",width:13.333,height:7.5}),i.layout="W16x9",i.title=e.title,i.subject="",i.author="",i.company="",i.theme={headFontFace:o.headFont.latin,bodyFontFace:o.bodyFont.latin};const a=te(e,t,n);e.slides.forEach((r,c)=>{const u=i.addSlide();for(const l of a.slides[c])if(D(l))u.addText(l.content,{x:l.x,y:l.y,w:l.w,h:l.h,fontSize:l.fontSize,fontFace:l.font==="head"?_:E,...l.color!==void 0?{color:l.color}:{},bold:l.bold??!1,align:l.align??"left",valign:l.valign??"top",margin:0,...l.transparency!==void 0?{transparency:l.transparency}:{},...l.charSpacing!==void 0?{charSpacing:l.charSpacing}:{},...l.lineSpacingMultiple!==void 0?{lineSpacingMultiple:l.lineSpacingMultiple}:{}});else if(G(l))u.addChart(Ee(l.chartType),Ce(l),Le(l));else if(q(l))u.addTable(Te(l),{x:l.x,y:l.y,w:l.w,rowH:l.h/(l.rows.length+1),fontSize:l.fontSize,fontFace:E,valign:"middle",margin:[0,.12,0,.12]});else{const d={x:l.x,y:l.y,w:l.w,h:l.h,fill:{color:l.fill,...l.transparency!==void 0?{transparency:l.transparency}:{}}};l.shape==="line"&&(d.line={color:l.fill,width:l.lineWidth??1,...l.transparency!==void 0?{transparency:l.transparency}:{}}),l.rectRadius!==void 0&&(d.rectRadius=l.rectRadius),l.shadowOpacity!==void 0&&l.shadowOpacity>0&&(d.shadow={type:"outer",angle:90,blur:14,offset:4,color:"0F172A",opacity:l.shadowOpacity}),u.addShape(l.shape,d)}const h=[v(r.goal),v(r.visual),...ke(r,a.layouts[c])].filter(l=>l!==void 0);h.length>0&&u.addNotes(h.join(`
3
- `))});const s=await i.write({outputType:"nodebuffer"});return Ae(s,o)}p(We,"Qe"),f(We,"renderPptx");const ie=320,Be=180,Ze=20*1024;function He(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}p(He,"Ge"),f(He,"escapeXml");function b(e){return String(Math.round(e*100)/100)}p(b,"S"),f(b,"svgNumber");function oe(e,t){return j(e)*t}p(oe,"ae"),f(oe,"estimateTextWidth");function Re(e,t,n){if(oe(e,t)<=n)return e;const o=[...e];for(;o.length>0&&oe(`${o.join("")}\u2026`,t)>n;)o.pop();return`${o.join("")}\u2026`}p(Re,"je"),f(Re,"fitText");function V(e,t){return e===void 0?"":` ${t}="${b(1-e/100)}"`}p(V,"j"),f(V,"opacityAttr");function le(e,t,n,o,i){return`<rect x="${b(e)}" y="${b(t)}" width="${b(n)}" height="${b(o)}" fill="#${i}"/>`}p(le,"se"),f(le,"rectSvg");function ae(e){const t=ie/S,n=[];for(const o of e){const i=o.x*t,a=o.y*t,s=o.w*t,r=o.h*t;if(G(o)){const u=o.series[0]?.values??[],h=Math.max(...u,1),l=s/Math.max(u.length,1);u.forEach((d,m)=>{const x=Math.max(d,0)/h*r*.85;n.push(le(i+m*l+l*.2,a+r-x,l*.6,x,o.colors[m%o.colors.length]))});continue}if(q(o)){const u=r/(o.rows.length+1);n.push(le(i,a,s,u,o.headerFill));for(let h=1;h<=o.rows.length;h++)n.push(`<line x1="${b(i)}" y1="${b(a+u*(h+1))}" x2="${b(i+s)}" y2="${b(a+u*(h+1))}" stroke="#${o.lineColor}" stroke-width="0.5"/>`);continue}if(D(o)){const u=(typeof o.content=="string"?o.content:o.content.map(M=>M.text).join("")).replace(/\s+/g," ").trim();if(u.length===0)continue;const h=o.fontSize/72*t,l=Re(u,h,Math.max(s,h)),d=o.align==="right"?"end":o.align==="center"?"middle":"start",m=d==="end"?i+s:d==="middle"?i+s/2:i,x=o.valign==="middle"?a+r/2+h*.35:o.valign==="bottom"?a+r-h*.25:a+h*.9,w=typeof o.content=="string"?void 0:o.content[0]?.options?.color,z=o.color??w??"333333";n.push(`<text x="${b(m)}" y="${b(x)}" font-size="${b(h)}" fill="#${z}"${o.bold?' font-weight="700"':""} text-anchor="${d}"${V(o.transparency,"fill-opacity")}>${He(l)}</text>`);continue}const c=`#${o.fill}`;switch(o.shape){case"ellipse":n.push(`<ellipse cx="${b(i+s/2)}" cy="${b(a+r/2)}" rx="${b(s/2)}" ry="${b(r/2)}" fill="${c}"${V(o.transparency,"fill-opacity")}/>`);break;case"line":n.push(`<line x1="${b(i)}" y1="${b(a)}" x2="${b(i+s)}" y2="${b(a+r)}" stroke="${c}" stroke-width="${b(Math.max((o.lineWidth??1)/72*t,.5))}"/>`);break;default:{const u=o.shape==="roundRect"?` rx="${b((o.rectRadius??.1)*t)}"`:"";n.push(`<rect x="${b(i)}" y="${b(a)}" width="${b(s)}" height="${b(r)}"${u} fill="${c}"${V(o.transparency,"fill-opacity")}/>`)}}}return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${ie} ${Be}" width="${ie}" height="${Be}" font-family="Microsoft YaHei, PingFang SC, sans-serif">${n.join("")}</svg>`}p(ae,"Ue"),f(ae,"slideElementsSvg");function je(e,t,n){const[o]=ne({title:t,slides:[{title:t,layout:"title",...n?{subtitle:n}:{}}]},e);return ae(o)}p(je,"et"),f(je,"themeThumbnailSvg");export{Ze as MAX_THUMBNAIL_SVG_BYTES,G as isChart,q as isTable,D as isText,ne as layoutSlides,We as renderPptx,Z as resolveLayout,ae as slideElementsSvg,je as themeThumbnailSvg};
1
+ var Pe=Object.defineProperty;var d=(e,t)=>Pe(e,"name",{value:t,configurable:!0});var Ye=Object.defineProperty,p=d((e,t)=>Ye(e,"name",{value:t,configurable:!0}),"f");import De from"jszip";import*as re from"pptxgenjs";import{designTheme as se,resolveStyle as Ie}from"../themes.js";import{writeDeckSource as Oe}from"./deck-source.js";const ce=re.default??re,Ge=ce.default??ce,S=13.33,R=7.5,y=.75,m=S-2*y,qe=.62,I=1.62,L=6.55,_="zzHeadFace",E="zzBodyFace",he="[\u5F85\u586B\u5199]";function O(e){return"content"in e}d(O,"X"),p(O,"isText");function G(e){return"chartType"in e}d(G,"K"),p(G,"isChart");function q(e){return"headers"in e&&"rows"in e}d(q,"Q"),p(q,"isTable");function Ne(e){return e}d(Ne,"Ze"),p(Ne,"text");function Ve(e){return e}d(Ve,"et"),p(Ve,"shape");function W(e){return String(e).padStart(2,"0")}d(W,"R"),p(W,"marker");function v(e){return e?.trim()||void 0}d(v,"w"),p(v,"filled");function T(e,t){return(e??[]).map(n=>n.trim()).filter(n=>n.length>0).slice(0,t)}d(T,"M"),p(T,"cleanList");function ue(e){return/[⺀-鿿豈-﫿＀-￯ -〿]/u.test(e)?1:/[A-Z]/.test(e)?.72:/[0-9]/.test(e)?.58:e==="%"?.9:e===" "?.3:.56}d(ue,"ge"),p(ue,"charEm");function j(e){let t=0;for(const n of e)t+=ue(n);return t}d(j,"B"),p(j,"textEm");function P(e,t,n){const o=n*72/t*.96;return e.split(`
2
+ `).reduce((i,a)=>i+Math.max(1,Math.ceil(j(a)/o)),0)}d(P,"D"),p(P,"wrappedLines");function z(e,t,n,o,i,a=1.2){for(let c=o;c>i;c-=1)if(P(e,c,t)*c*a*1.12/72<=n)return c;return i}d(z,"z"),p(z,"fitSize");function F(e,t,n,o,i,a=1.2){return e.reduce((c,r)=>Math.min(c,z(r,t,n,o,i,a)),o)}d(F,"k"),p(F,"fitAll");function k(e,t,n,o){const i=Math.max(j(e),1);return Math.max(o,Math.min(n,Math.floor(t*72/i)))}d(k,"C"),p(k,"fitLine");function U(e){const t=/^(.{1,18}?)[::]\s*(.+)$/u.exec(e);if(t)return{lead:t[1].trim(),detail:t[2].trim()}}d(U,"Z"),p(U,"splitLead");function Y(e){const t=e.map(U);return t.every(n=>n!==void 0)?t:void 0}d(Y,"_"),p(Y,"allLeads");const _e=/^[-+约~≈]?[¥$¥€]?\d[\d,]*(\.\d+)?\s*(%|×|x|倍|pp|个百分点|万亿|亿元|万元|亿|万|千|元|k|m|b|天|小时|人|家|个|项|次|分)?\+?$/iu,Ue=/^(\d{4}(\s*年)?(\s*(Q[1-4]|H[12]|\d{1,2}\s*月))?|Q[1-4]|H[12]|\d{1,2}\s*月|第[一二三四五六七八九十\d]+(阶段|期|周|月|季度|年|步)|阶段\s*[一二三四五六七八九十\d]+|phase\s*\d+|M\d+|W\d+|day\s*\d+|D\d+|(近期|中期|远期|短期|长期)(\s*[((].*[))])?|本周|下周|本月|下月|本季度|下季度)$/iu;function Q(e){if(e.length<2||e.length>4)return;const t=Y(e);if(!(!t||!t.every(n=>_e.test(n.lead))))return t.map(n=>({value:n.lead,label:n.detail}))}d(Q,"ee"),p(Q,"inferStats");function X(e){if(e.length<2||e.length>6)return;const t=Y(e);return t?.every(n=>Ue.test(n.lead))?t:void 0}d(X,"te"),p(X,"inferTimeline");function Z(e){if(e.length<4||e.length>9)return;const t=Y(e);if(!t)return;const n=[],o=new Map;for(const i of t){if(i.lead.length>10)return;o.has(i.lead)||(o.set(i.lead,[]),n.push(i.lead)),o.get(i.lead).push(i.detail)}if(!(n.length<2||n.length>3)&&!n.some(i=>o.get(i).length<2))return n.map(i=>({heading:i,points:o.get(i)}))}d(Z,"ne"),p(Z,"inferColumns");const Qe=/^(.{1,14}?)[\s::]+[约~≈]?(-?\d[\d,]*(?:\.\d+)?)\s*(%|亿元|万元|元|亿|万|个|家|人|台|次|件|吨|天)?\s*([((].{0,12}[))])?$/u;function D(e){if(e.length<3||e.length>8)return;const t=e.map(i=>Qe.exec(i));if(t.some(i=>i===null))return;const n=t,o=n[0][3]??"";if(!n.some(i=>(i[3]??"")!==o))return{type:"bar",categories:n.map(i=>i[1].trim()+(i[4]?i[4].replace(/[(())]/g,""):"")),series:[{name:"",values:n.map(i=>Number(i[2].replace(/,/g,"")))}],...o?{unit:o}:{}}}d(D,"I"),p(D,"inferChart");function de(e){if(!e||e.categories.length===0)return;const t=e.series.filter(n=>n.values.length===e.categories.length&&n.values.every(o=>Number.isFinite(o)));return t.length>0?{...e,series:t}:void 0}d(de,"Se"),p(de,"validChart");function pe(e){const t=(e??[]).filter(n=>n.value.trim()&&n.label.trim()).slice(0,4);return t.length>0?t:void 0}d(pe,"xe"),p(pe,"validStats");function fe(e){const t=(e??[]).filter(n=>n.heading.trim()).slice(0,3);return t.length>=2?t:void 0}d(fe,"we"),p(fe,"validColumns");function ye(e){if(!(!e||e.headers.length===0||e.rows.length===0))return{headers:e.headers.slice(0,8),rows:e.rows.slice(0,12).map(t=>t.slice(0,8))}}d(ye,"ve"),p(ye,"validTable");const Xe=/^(目录|目 录|议程|大纲|contents?|agenda|outline)$/iu,Ze=/(谢谢|感谢|致谢|thank|q\s*&\s*a|问答|结束)/iu,Je=/^[“"「『].+[”"」』]$/u;function J(e,t,n){const o=T(e.points,9),i=de(e.chart),a=pe(e.stats),c=fe(e.columns),r=ye(e.table),s=e.layout;if(s==="title"||t===0&&s===void 0)return{layout:"title"};switch(s){case"section":case"agenda":case"quote":case"closing":case"content":case"two-column":return{layout:s};case"chart":{const g=i??D(o);return g?{layout:"chart",chart:g}:{layout:"content"}}case"stats":{const g=a??Q(o);return g?{layout:"stats",stats:g}:{layout:"content"}}case"comparison":{const g=c??Z(o);return g?{layout:"comparison",columns:g}:{layout:"two-column"}}case"timeline":{const g=X(o)??(o.length>=2?o.map((x,w)=>({lead:W(w+1),detail:x})):void 0);return g?{layout:"timeline",timeline:g}:{layout:"content"}}case"table":return r?{layout:"table",table:r}:{layout:"content"}}if(i)return{layout:"chart",chart:i};if(a)return{layout:"stats",stats:a};if(c)return{layout:"comparison",columns:c};if(r)return{layout:"table",table:r};if(Xe.test(e.title.trim()))return{layout:"agenda"};const u=Q(o);if(u)return{layout:"stats",stats:u};const h=X(o);if(h)return{layout:"timeline",timeline:h};const f=Z(o);if(f)return{layout:"comparison",columns:f};const l=D(o);return l?{layout:"chart",chart:l}:o.length===0&&Je.test(e.title.trim())?{layout:"quote"}:t===n-1&&t>0&&Ze.test(e.title)?{layout:"closing"}:{layout:"content"}}d(J,"Ce"),p(J,"resolveLayout");function C(e){return{x:0,y:0,w:S,h:R,fill:e,shape:"rect"}}d(C,"F"),p(C,"background");function A(e,t){const{t:n,slide:o}=e;t.push(C(n.bg)),n.topBand&&t.push({x:0,y:0,w:S,h:.16,fill:n.primary,shape:"rect"},{x:0,y:.16,w:S,h:.035,fill:n.accent,shape:"rect"}),e.tracker&&t.push({x:y,y:.34,w:8,h:.26,content:e.tracker,fontSize:11,color:n.primary,bold:!0,charSpacing:1});const i=.92,a=z(o.title,m,i,n.titleSize,18,1.15);t.push({x:y,y:qe,w:m,h:i,content:o.title,fontSize:a,color:n.ink,bold:!0,valign:"middle",lineSpacingMultiple:1.05,font:"head"}),n.titleRule&&t.push({x:y,y:I,w:m,h:0,fill:n.line,shape:"line",lineWidth:.75});let c=I+.33;const r=v(o.subtitle);r&&(t.push({x:y,y:I+.2,w:m,h:.42,content:r,fontSize:k(r,m,16,12),color:n.muted,valign:"middle"}),c=I+.82);const s=v(o.source);return s&&t.push({x:y,y:6.95,w:m-1.2,h:.3,content:s,fontSize:9,color:n.muted,valign:"middle"}),t.push({x:S-y-1,y:6.95,w:1,h:.3,content:String(e.index+1),fontSize:10,color:n.muted,align:"right",valign:"middle"}),c}d(A,"L"),p(A,"contentChrome");function B(e,t,n){if(!t)return L;const o=L-.62;return n.push({x:y,y:o,w:m,h:.62,fill:e.surface,shape:e.radius>0?"roundRect":"rect",rectRadius:e.radius},{x:y+.25,y:o+.24,w:.14,h:.14,fill:e.accent,shape:"rect"},{x:y+.55,y:o,w:m-.8,h:.62,content:t,fontSize:k(t,m-.8,16,12),color:e.ink,bold:!0,valign:"middle"}),o-.25}d(B,"O"),p(B,"takeawayBand");function ge(e,t,n,o=1.4){return P(e,t,n)*t*o/72}d(ge,"$e"),p(ge,"blockHeight");function N(e,t,n,o){const i=k(e,n*.96,o,28),a=i>=o*.75?i:z(e,n,2.2,o,28,1.35),c=ge(e,a,n,1.4)+.05,r=3.45-(.3+c+(t?.3+.5:0))/2;return{size:a,top:r,titleY:r+.3,titleH:c,subtitleY:r+.3+c+.3}}d(N,"Y"),p(N,"coverGroup");function me(e){const{t,slide:n}=e,o=v(n.subtitle),i=[];switch(t.cover){case"dark-center":{i.push(C(t.inverseBg));const a=N(n.title,o,11.2,54);return i.push({x:1.06,y:a.titleY,w:11.2,h:a.titleH,content:n.title,fontSize:a.size,color:t.inverseInk,bold:!0,align:"center",lineSpacingMultiple:1.05,font:"head"},{x:S/2-.3,y:a.titleY+a.titleH+.08,w:.6,h:.04,fill:t.primary,shape:"rect"}),o&&i.push({x:1.06,y:a.subtitleY+.1,w:11.2,h:.6,content:o,fontSize:k(o,11.2,20,13),color:t.inverseMuted,align:"center"}),i}case"white-left":case"panel-right":{const a=t.cover==="panel-right",c=a?7.7:10.8;i.push(C(t.bg)),a?i.push({x:9,y:0,w:S-9,h:R,fill:t.inverseBg,shape:"rect"},{x:10.35,y:4.35,w:2.4,h:2.4,fill:t.accent,shape:"ellipse"},{x:9.55,y:1,w:1.1,h:1.1,fill:t.inverseMuted,shape:"ellipse",transparency:55}):i.push({x:y,y:6.7,w:m,h:0,fill:t.ink,shape:"line",lineWidth:1});const r=N(n.title,o,c,a?42:48);return i.push({x:y,y:r.top,w:.8,h:.08,fill:t.accent,shape:"rect"},{x:y,y:r.titleY,w:c,h:r.titleH,content:n.title,fontSize:r.size,color:t.ink,bold:!0,valign:"top",lineSpacingMultiple:1.05,font:"head"}),o&&i.push({x:y,y:r.subtitleY,w:c,h:.9,content:o,fontSize:z(o,c,.9,20,12),color:a?t.body:t.muted}),i}case"gov-band":return i.push(C(t.bg)),i.push({x:0,y:0,w:S,h:1.1,fill:t.primary,shape:"rect"},{x:0,y:1.1,w:S,h:.06,fill:t.accent,shape:"rect"},{x:0,y:R-.4,w:S,h:.4,fill:t.primary,shape:"rect"},{x:0,y:R-.46,w:S,h:.06,fill:t.accent,shape:"rect"}),i.push({x:y,y:2.3,w:m,h:1.8,content:n.title,fontSize:z(n.title,m,1.8,44,28,1.1),color:t.primary,bold:!0,align:"center",valign:"bottom",lineSpacingMultiple:1.05,font:"head"}),i.push({x:S/2-1.6,y:4.3,w:3.2,h:0,fill:t.accent,shape:"line",lineWidth:1.5}),o&&i.push({x:y,y:4.5,w:m,h:.6,content:o,fontSize:k(o,m,20,13),color:t.body,align:"center"}),i;default:{i.push(C(t.inverseBg));const a=N(n.title,o,10.6,48);return i.push({x:y,y:a.top,w:.9,h:.07,fill:t.accent,shape:"rect"},{x:y,y:a.titleY,w:10.6,h:a.titleH,content:n.title,fontSize:a.size,color:t.inverseInk,bold:!0,lineSpacingMultiple:1.05,font:"head"}),o&&i.push({x:y,y:a.subtitleY,w:10.6,h:.9,content:o,fontSize:z(o,10.6,.9,20,12),color:t.inverseMuted}),i.push({x:y,y:6.75,w:m,h:0,fill:t.inverseMuted,shape:"line",lineWidth:.75}),i}}}d(me,"Te"),p(me,"coverElements");function xe(e){const{t,slide:n}=e,o=v(n.subtitle),i=[C(t.inverseBg)];return t.topBand&&i.push({x:0,y:R-.5,w:S,h:.06,fill:t.accent,shape:"rect"}),i.push({x:y,y:1.7,w:4,h:1.2,content:W(e.sectionOrdinal),fontSize:66,color:t.accent,bold:!0,font:"head"},{x:y+.05,y:3.1,w:1.2,h:.05,fill:t.accent,shape:"rect"},{x:y,y:3.35,w:10.8,h:1.3,content:n.title,fontSize:z(n.title,10.8,1.3,40,26,1.1),color:t.inverseInk,bold:!0,font:"head"}),o&&i.push({x:y,y:4.75,w:10.8,h:.6,content:o,fontSize:k(o,10.8,18,12),color:t.inverseMuted}),i}d(xe,"Fe"),p(xe,"sectionElements");function we(e){const{t}=e,n=[],o=A(e,n),i=T(e.slide.points,8),a=i.length>0?i:e.sections.slice(0,8);if(a.length===0)return n.push({x:y,y:o,w:m,h:.6,content:he,fontSize:18,color:t.muted}),n;const c=Math.min(.82,(L-o)/a.length),r=y+1.6,s=m-1.6,u=F(a,s-1.1,c-.12,22,14);return a.forEach((h,f)=>{const l=o+f*c;n.push({x:r,y:l,w:.9,h:c,content:W(f+1),fontSize:u+2,color:t.primary,bold:!0,valign:"middle",font:"head"},{x:r+1.1,y:l,w:s-1.1,h:c,content:h,fontSize:u,color:t.ink,valign:"middle"},{x:r,y:l+c,w:s,h:0,fill:t.line,shape:"line",lineWidth:.75})}),n}d(we,"Me"),p(we,"agendaElements");function K(e,t,n=!1){const o=U(e),i=n?t.inverseInk:t.ink,a=n?t.inverseMuted:t.body;return o?[{text:`${o.lead}\uFF1A`,options:{color:i,bold:!0}},{text:o.detail,options:{color:a}}]:[{text:e,options:{color:n?t.inverseInk:t.body}}]}d(K,"ie"),p(K,"pointRuns");function H(e,t,n,o,i,a,c,r=20){const s=Math.min(1.15,(a-o)/e.length),u=F(e,i-.45,s-.18,r,12,1.25);e.forEach((h,f)=>{const l=o+f*s,g=P(h,u,i-.45)*u*1.25/72,x=l+(s-g)/2+u*1.25/72/2;c.push({x:n,y:x-.055,w:.11,h:.11,fill:t.primary,shape:"rect"},{x:n+.35,y:l,w:i-.35,h:s,content:K(h,t),fontSize:u,valign:"middle",lineSpacingMultiple:1.15}),f<e.length-1&&c.push({x:n,y:l+s,w:i,h:0,fill:t.line,shape:"line",lineWidth:.5})})}d(H,"W"),p(H,"pointList");function ee(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i)+.1,c=B(n,v(o.takeaway),i),r=T(o.points,8);if(r.length===0)return i.push({x:y,y:a,w:m,h:.6,content:he,fontSize:18,color:n.muted}),i;const s=Y(r),u=c-a;if(!t&&s&&r.length>=2&&r.length<=3){const h=(m-.5*(r.length-1))/r.length,f=F(s.map(w=>w.lead),h,.95,26,16,1.15),l=F(s.map(w=>w.detail),h,u-1.75,19,12,1.35),g=Math.max(...s.map(w=>P(w.detail,l,h)*l*1.35/72)),x=a+Math.max(0,(u-1.75-g-.2)/3);return s.forEach((w,$)=>{const M=y+$*(h+.5);i.push({x:M,y:x+.1,w:h,h:.05,fill:$===0?n.primary:n.line,shape:"rect"},{x:M,y:x+.3,w:h,h:.4,content:W($+1),fontSize:15,color:n.primary,bold:!0,font:"head"},{x:M,y:x+.75,w:h,h:.95,content:w.lead,fontSize:f,color:n.ink,bold:!0,lineSpacingMultiple:1.05,font:"head"},{x:M,y:x+1.75,w:h,h:c-x-1.75,content:w.detail,fontSize:l,color:n.body,lineSpacingMultiple:1.25})}),i}if(!t&&s&&r.length===4){const h=(m-.6)/2,f=(u-.3)/2,l=F(s.map(x=>x.lead),h-.9,.5,20,14),g=F(s.map(x=>x.detail),h-.9,f-.8,16,11,1.3);return i.push({x:y+h+.3,y:a,w:0,h:u,fill:n.line,shape:"line",lineWidth:.75},{x:y,y:a+f+.15,w:m,h:0,fill:n.line,shape:"line",lineWidth:.75}),s.forEach((x,w)=>{const $=y+w%2*(h+.6),M=a+Math.floor(w/2)*(f+.3)+.1;i.push({x:$,y:M,w:.8,h:.55,content:W(w+1),fontSize:24,color:n.primary,bold:!0,font:"head"},{x:$+.9,y:M,w:h-.9,h:.55,content:x.lead,fontSize:l,color:n.ink,bold:!0,valign:"middle",font:"head"},{x:$+.9,y:M+.65,w:h-.9,h:f-.8,content:x.detail,fontSize:g,color:n.body,lineSpacingMultiple:1.2})}),i}if(t||r.length>5){const h=Math.ceil(r.length/2),f=(m-.6)/2;return H(r.slice(0,h),n,y,a,f,c,i,18),r.length>h&&H(r.slice(h),n,y+f+.6,a,f,c,i,18),i}return H(r,n,y,a,m*.86,c,i),i}d(ee,"oe"),p(ee,"contentElements");function be(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),c=B(n,v(o.takeaway),i),r=m/t.length,s=2.7,u=a+Math.max(.2,(c-a-s)/2),h=Math.min(...t.map(l=>k(l.value,r-.5,t.length<=2?80:64,28))),f=F(t.map(l=>l.label),r-.5,.8,18,12);return t.forEach((l,g)=>{const x=y+g*r;g>0&&i.push({x,y:u,w:0,h:s,fill:n.line,shape:"line",lineWidth:.75});const w=g>0?.4:0;i.push({x:x+w,y:u,w:r-w-.1,h:1.35,content:l.value,fontSize:h,color:g===0?n.primary:n.ink,bold:!0,valign:"bottom",font:"head"},{x:x+w,y:u+1.5,w:r-w-.3,h:.8,content:l.label,fontSize:f,color:n.ink,bold:!0});const $=v(l.note);$&&i.push({x:x+w,y:u+2.3,w:r-w-.3,h:.4,content:$,fontSize:12,color:n.muted})}),i}d(be,"Le"),p(be,"statsElements");function ve(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),c=v(o.takeaway),r=T(o.points,8),s=c||D(r)?[]:r.slice(0,3),u=c!==void 0||s.length>0,h=u?m*.64:m;let f=a;t.unit&&(i.push({x:y,y:a-.05,w:4,h:.3,content:`${/[\u3400-\u9fff]/u.test(o.title)?"\u5355\u4F4D\uFF1A":"Unit: "}${t.unit}`,fontSize:11,color:n.muted}),f+=.3);const l=t.type==="pie"||t.type==="doughnut",g=Math.max(...t.categories.map(x=>j(x)))>6||t.categories.length>8;if(i.push({x:y-.1,y:f,w:h,h:L-f,chartType:t.type,categories:t.categories,series:t.series,colors:l||t.series.length>1?n.chart:[n.primary],labelColor:n.muted,valueColor:n.ink,gridColor:n.line,horizontal:!l&&t.type!=="line"&&g}),u){const x=y+m*.69,w=m*.31;i.push({x:x-.3,y:a,w:0,h:L-a,fill:n.line,shape:"line",lineWidth:.75}),c?i.push({x,y:a+.1,w:.5,h:.05,fill:n.accent,shape:"rect"},{x,y:a+.35,w,h:L-a-.5,content:c,fontSize:z(c,w,L-a-.5,22,14,1.3),color:n.ink,bold:!0,lineSpacingMultiple:1.2,font:"head"}):H(s,n,x,a,w,Math.min(L,a+s.length*1.1),i,16)}return i}d(ve,"Pe"),p(ve,"chartElements");function Se(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i)+.05,c=B(n,v(o.takeaway),i),r=.4,s=(m-r*(t.length-1))/t.length,u=.62;return t.forEach((h,f)=>{const l=y+f*(s+r),g=f===t.length-1;i.push({x:l,y:a,w:s,h:u,fill:g?n.primary:n.surface,shape:n.radius>0?"roundRect":"rect",rectRadius:n.radius},{x:l+.3,y:a,w:s-.6,h:u,content:h.heading,fontSize:k(h.heading,s-.6,20,13),color:g?n.inverseInk:n.ink,bold:!0,valign:"middle",font:"head"});const x=T(h.points,5);x.length>0&&H(x,n,l+.15,a+u+.15,s-.15,c,i,18)}),i}d(Se,"Re"),p(Se,"comparisonElements");function $e(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),c=B(n,v(o.takeaway),i),r=m/t.length,s=a+Math.max(1.35,(c-a)*.4);i.push({x:y,y:s,w:m,h:0,fill:n.line,shape:"line",lineWidth:1.5});const u=F(t.map(f=>f.lead),r-.2,.6,26,14),h=F(t.map(f=>f.detail),r-.3,c-s-.5,19,11,1.3);return t.forEach((f,l)=>{const g=y+r*(l+.5),x=l===t.length-1;i.push({x:g-r/2+.1,y:s-1,w:r-.2,h:.6,content:f.lead,fontSize:u,color:x?n.accent:n.primary,bold:!0,align:"center",valign:"bottom",font:"head"},{x:g-.14,y:s-.14,w:.28,h:.28,fill:x?n.accent:n.primary,shape:"ellipse"},{x:g-r/2+.15,y:s+.4,w:r-.3,h:c-s-.5,content:f.detail,fontSize:h,color:n.body,align:"center",lineSpacingMultiple:1.2})}),i}d($e,"He"),p($e,"timelineElements");function ze(e,t){const{t:n,slide:o}=e,i=[],a=A(e,i),c=B(n,v(o.takeaway),i),r=t.rows.length,s=r<=5?15:r<=8?13:11,u=Math.min(.55,(c-a)/(r+1));return i.push({x:y,y:a,w:m,h:u*(r+1),headers:t.headers,rows:t.rows,fontSize:s,headerFill:n.primary,headerColor:n.inverseInk,stripeFill:n.surface,bodyColor:n.body,lineColor:n.line}),i}d(ze,"Oe"),p(ze,"tableElements");function Fe(e){const{t,slide:n}=e,o=n.title.trim().replace(/^[“"「『]|[”"」』]$/gu,""),i=v(n.subtitle),a=[C(t.bg)];return t.topBand&&a.push({x:0,y:0,w:S,h:.16,fill:t.primary,shape:"rect"}),a.push({x:y+.6,y:.9,w:2,h:1.6,content:"\u201C",fontSize:140,color:t.accent,bold:!0,font:"head"},{x:y+1,y:2.35,w:m-2,h:2.6,content:o,fontSize:z(o,m-2,2.6,34,20,1.3),color:t.ink,bold:!0,lineSpacingMultiple:1.2,font:"head"}),i&&a.push({x:y+1,y:5.3,w:.5,h:.04,fill:t.primary,shape:"rect"},{x:y+1,y:5.45,w:m-2,h:.5,content:i,fontSize:16,color:t.muted}),a}d(Fe,"We"),p(Fe,"quoteElements");function Me(e){const{t,slide:n}=e,o=T(n.points,5),i=[C(t.inverseBg)];if(o.length===0){i.push({x:y,y:2.6,w:m,h:1.6,content:n.title,fontSize:z(n.title,m,1.6,54,28,1.1),color:t.inverseInk,bold:!0,align:"center",valign:"middle",font:"head"});const s=v(n.subtitle);return s&&i.push({x:y,y:4.3,w:m,h:.6,content:s,fontSize:k(s,m,18,12),color:t.inverseMuted,align:"center"}),i}i.push({x:y,y:.85,w:.9,h:.07,fill:t.accent,shape:"rect"},{x:y,y:1.05,w:m,h:1.4,content:n.title,fontSize:z(n.title,m,1.4,34,22,1.15),color:t.inverseInk,bold:!0,lineSpacingMultiple:1.1,font:"head"});const a=2.95,c=Math.min(.85,(6.7-a)/o.length),r=F(o,m-1.1,c-.15,20,13);return o.forEach((s,u)=>{const h=a+u*c;i.push({x:y,y:h,w:.9,h:c,content:W(u+1),fontSize:r+2,color:t.accent,bold:!0,valign:"middle",font:"head"},{x:y+1,y:h,w:m-1,h:c,content:K(s,t,!0),fontSize:r,valign:"middle"},{x:y,y:h+c,w:m,h:0,fill:t.inverseMuted,shape:"line",lineWidth:.5,transparency:50})}),i}d(Me,"Ae"),p(Me,"closingElements");function te(e,t,n=""){const o=se(t,`${e.title} ${n}`),i=e.slides.length,a=e.slides.map((u,h)=>J(u,h,i)),c=e.slides.filter((u,h)=>a[h].layout==="section").map(u=>u.title.trim());let r,s=0;return{slides:e.slides.map((u,h)=>{const f=a[h];f.layout==="section"&&(s+=1,r=u.title.trim());const l={t:o,slide:u,deckTitle:e.title,index:h,total:i,tracker:r,sections:c,sectionOrdinal:s};switch(f.layout){case"title":return me(l);case"section":return xe(l);case"agenda":return we({...l,tracker:void 0});case"stats":return be(l,f.stats);case"chart":return ve(l,f.chart);case"comparison":return Se(l,f.columns);case"timeline":return $e(l,f.timeline);case"table":return ze(l,f.table);case"quote":return Fe(l);case"closing":return Me(l);case"two-column":return ee(l,!0);default:return ee(l,!1)}}),layouts:a}}d(te,"re"),p(te,"layoutDeck");function ne(e,t,n=""){return te(e,t,n).slides}d(ne,"Be"),p(ne,"layoutSlides");function ke(e,t){const n=T(e.points,20);return n.length===0?[]:e.stats||e.chart||e.columns||e.table?t.layout==="chart"&&!v(e.takeaway)&&!D(n)?n.slice(3):["stats","chart","comparison","table"].includes(t.layout)?n:[]:[]}d(ke,"De"),p(ke,"displacedPoints");function Ce(e){if(e.chartType==="pie"||e.chartType==="doughnut"){const t=e.series[0];return[{name:t.name,labels:e.categories,values:t.values}]}return e.series.map(t=>({name:t.name||" ",labels:e.categories,values:t.values}))}d(Ce,"_e"),p(Ce,"chartData");function Le(e){const t={x:e.x,y:e.y,w:e.w,h:e.h,chartColors:e.colors,catAxisLabelColor:e.labelColor,valAxisLabelColor:e.labelColor,catAxisLabelFontFace:E,valAxisLabelFontFace:E,dataLabelFontFace:E,legendFontFace:E,catAxisLabelFontSize:12,valAxisLabelFontSize:11,dataLabelFontSize:12,legendFontSize:12,legendColor:e.labelColor,dataLabelColor:e.valueColor,showLegend:e.series.length>1,legendPos:"t",showTitle:!1};switch(e.chartType){case"pie":case"doughnut":return{...t,holeSize:62,showLegend:!0,legendPos:"r",legendFontSize:16,showPercent:!0,showValue:!1,dataLabelColor:"FFFFFF",dataLabelFontSize:13,dataLabelFontBold:!0,dataBorder:{pt:1.5,color:"FFFFFF"}};case"line":return{...t,lineSize:3,lineDataSymbol:"circle",lineDataSymbolSize:8,showValue:e.series.length===1&&e.categories.length<=8,dataLabelPosition:"t",valGridLine:{color:e.gridColor,style:"solid",size:.5},catGridLine:{style:"none"},catAxisLineColor:e.gridColor,valAxisHidden:!1,valAxisLineShow:!1};default:return{...t,barDir:e.horizontal?"bar":"col",barGrouping:e.chartType==="stacked"?"stacked":"clustered",barGapWidthPct:55,showValue:!0,dataLabelPosition:e.chartType==="stacked"?"ctr":"outEnd",dataLabelFormatCode:"#,##0.##",valAxisHidden:!0,valGridLine:{style:"none"},catGridLine:{style:"none"},catAxisLineColor:e.gridColor,catAxisOrientation:e.horizontal?"maxMin":"minMax"}}}d(Le,"Ie"),p(Le,"chartOptions");function Ee(e){return e==="line"?"line":e==="pie"?"pie":e==="doughnut"?"doughnut":"bar"}d(Ee,"Ne"),p(Ee,"chartKind");const Ke=/^[-+]?[¥$¥€]?\d[\d,]*(\.\d+)?\s*(%|pp|万|亿|元|万元|亿元)?$/u;function Te(e){const t=p(i=>[{type:"none"},{type:"none"},{pt:.75,color:i},{type:"none"}],"border"),n=e.headers.map((i,a)=>({text:i,options:{bold:!0,color:e.headerColor,fill:{color:e.headerFill},align:a===0?"left":"center",border:t(e.headerFill)}})),o=e.rows.map((i,a)=>e.headers.map((c,r)=>{const s=i[r]??"";return{text:s,options:{color:e.bodyColor,fill:{color:a%2===1?e.stripeFill:"FFFFFF"},align:r>0&&Ke.test(s.trim())?"right":"left",border:t(e.lineColor)}}}));return[n,...o]}d(Te,"Ge"),p(Te,"tableRows");async function Ae(e,t,n){const o=await De.loadAsync(e),i={[_]:t.headFont,[E]:t.bodyFont},a=new RegExp(`<a:(latin|ea|cs) typeface="(${_}|${E})"`,"g"),c=Object.keys(o.files).filter(s=>/^ppt\/(slides|charts|notesSlides)\/[^/]+\.xml$/.test(s));for(const s of c){const u=await o.file(s).async("string"),h=u.replace(a,(f,l,g)=>{const x=i[g];return`<a:${l} typeface="${l==="ea"?x.ea:x.latin}"`});h!==u&&o.file(s,h)}const r=Object.keys(o.files).filter(s=>/^ppt\/theme\/theme\d+\.xml$/.test(s));for(const s of r){const u=await o.file(s).async("string"),h=p((l,g)=>l.replace(/<a:latin typeface="[^"]*"/,`<a:latin typeface="${g.latin}"`).replace(/<a:ea typeface="[^"]*"/,`<a:ea typeface="${g.ea}"`).replace(/<a:font script="Hans" typeface="[^"]*"/,`<a:font script="Hans" typeface="${g.ea}"`),"patchScheme"),f=u.replace(/<a:majorFont>[\s\S]*?<\/a:majorFont>/,l=>h(l,t.headFont)).replace(/<a:minorFont>[\s\S]*?<\/a:minorFont>/,l=>h(l,t.bodyFont));o.file(s,f)}return await Oe(o,n),o.generateAsync({type:"nodebuffer",compression:"DEFLATE"})}d(Ae,"je"),p(Ae,"finishDeck");async function We(e,t,n=""){const o=se(t,`${e.title} ${n}`),i=new Ge;i.defineLayout({name:"W16x9",width:13.333,height:7.5}),i.layout="W16x9",i.title=e.title,i.subject="",i.author="",i.company="",i.theme={headFontFace:o.headFont.latin,bodyFontFace:o.bodyFont.latin};const a=te(e,t,n);e.slides.forEach((s,u)=>{const h=i.addSlide();for(const l of a.slides[u])if(O(l))h.addText(l.content,{x:l.x,y:l.y,w:l.w,h:l.h,fontSize:l.fontSize,fontFace:l.font==="head"?_:E,...l.color!==void 0?{color:l.color}:{},bold:l.bold??!1,align:l.align??"left",valign:l.valign??"top",margin:0,...l.transparency!==void 0?{transparency:l.transparency}:{},...l.charSpacing!==void 0?{charSpacing:l.charSpacing}:{},...l.lineSpacingMultiple!==void 0?{lineSpacingMultiple:l.lineSpacingMultiple}:{}});else if(G(l))h.addChart(Ee(l.chartType),Ce(l),Le(l));else if(q(l))h.addTable(Te(l),{x:l.x,y:l.y,w:l.w,rowH:l.h/(l.rows.length+1),fontSize:l.fontSize,fontFace:E,valign:"middle",margin:[0,.12,0,.12]});else{const g={x:l.x,y:l.y,w:l.w,h:l.h,fill:{color:l.fill,...l.transparency!==void 0?{transparency:l.transparency}:{}}};l.shape==="line"&&(g.line={color:l.fill,width:l.lineWidth??1,...l.transparency!==void 0?{transparency:l.transparency}:{}}),l.rectRadius!==void 0&&(g.rectRadius=l.rectRadius),l.shadowOpacity!==void 0&&l.shadowOpacity>0&&(g.shadow={type:"outer",angle:90,blur:14,offset:4,color:"0F172A",opacity:l.shadowOpacity}),h.addShape(l.shape,g)}const f=[v(s.goal),v(s.visual),...ke(s,a.layouts[u])].filter(l=>l!==void 0);f.length>0&&h.addNotes(f.join(`
3
+ `))});const c=await i.write({outputType:"nodebuffer"}),r=Ie(t,`${e.title} ${n}`);return Ae(c,o,{version:1,style:r,plan:e})}d(We,"tt"),p(We,"renderPptx");const ie=320,Be=180,et=20*1024;function He(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}d(He,"Ue"),p(He,"escapeXml");function b(e){return String(Math.round(e*100)/100)}d(b,"S"),p(b,"svgNumber");function oe(e,t){return j(e)*t}d(oe,"se"),p(oe,"estimateTextWidth");function Re(e,t,n){if(oe(e,t)<=n)return e;const o=[...e];for(;o.length>0&&oe(`${o.join("")}\u2026`,t)>n;)o.pop();return`${o.join("")}\u2026`}d(Re,"qe"),p(Re,"fitText");function V(e,t){return e===void 0?"":` ${t}="${b(1-e/100)}"`}d(V,"j"),p(V,"opacityAttr");function le(e,t,n,o,i){return`<rect x="${b(e)}" y="${b(t)}" width="${b(n)}" height="${b(o)}" fill="#${i}"/>`}d(le,"ae"),p(le,"rectSvg");function ae(e){const t=ie/S,n=[];for(const o of e){const i=o.x*t,a=o.y*t,c=o.w*t,r=o.h*t;if(G(o)){const u=o.series[0]?.values??[],h=Math.max(...u,1),f=c/Math.max(u.length,1);u.forEach((l,g)=>{const x=Math.max(l,0)/h*r*.85;n.push(le(i+g*f+f*.2,a+r-x,f*.6,x,o.colors[g%o.colors.length]))});continue}if(q(o)){const u=r/(o.rows.length+1);n.push(le(i,a,c,u,o.headerFill));for(let h=1;h<=o.rows.length;h++)n.push(`<line x1="${b(i)}" y1="${b(a+u*(h+1))}" x2="${b(i+c)}" y2="${b(a+u*(h+1))}" stroke="#${o.lineColor}" stroke-width="0.5"/>`);continue}if(O(o)){const u=(typeof o.content=="string"?o.content:o.content.map(M=>M.text).join("")).replace(/\s+/g," ").trim();if(u.length===0)continue;const h=o.fontSize/72*t,f=Re(u,h,Math.max(c,h)),l=o.align==="right"?"end":o.align==="center"?"middle":"start",g=l==="end"?i+c:l==="middle"?i+c/2:i,x=o.valign==="middle"?a+r/2+h*.35:o.valign==="bottom"?a+r-h*.25:a+h*.9,w=typeof o.content=="string"?void 0:o.content[0]?.options?.color,$=o.color??w??"333333";n.push(`<text x="${b(g)}" y="${b(x)}" font-size="${b(h)}" fill="#${$}"${o.bold?' font-weight="700"':""} text-anchor="${l}"${V(o.transparency,"fill-opacity")}>${He(f)}</text>`);continue}const s=`#${o.fill}`;switch(o.shape){case"ellipse":n.push(`<ellipse cx="${b(i+c/2)}" cy="${b(a+r/2)}" rx="${b(c/2)}" ry="${b(r/2)}" fill="${s}"${V(o.transparency,"fill-opacity")}/>`);break;case"line":n.push(`<line x1="${b(i)}" y1="${b(a)}" x2="${b(i+c)}" y2="${b(a+r)}" stroke="${s}" stroke-width="${b(Math.max((o.lineWidth??1)/72*t,.5))}"/>`);break;default:{const u=o.shape==="roundRect"?` rx="${b((o.rectRadius??.1)*t)}"`:"";n.push(`<rect x="${b(i)}" y="${b(a)}" width="${b(c)}" height="${b(r)}"${u} fill="${s}"${V(o.transparency,"fill-opacity")}/>`)}}}return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${ie} ${Be}" width="${ie}" height="${Be}" font-family="Microsoft YaHei, PingFang SC, sans-serif">${n.join("")}</svg>`}d(ae,"Je"),p(ae,"slideElementsSvg");function je(e,t,n){const[o]=ne({title:t,slides:[{title:t,layout:"title",...n?{subtitle:n}:{}}]},e);return ae(o)}d(je,"it"),p(je,"themeThumbnailSvg");export{et as MAX_THUMBNAIL_SVG_BYTES,G as isChart,q as isTable,O as isText,ne as layoutSlides,We as renderPptx,J as resolveLayout,ae as slideElementsSvg,je as themeThumbnailSvg};