dknowc-dsh 2.3.1 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +11 -3
  2. package/cordis.patch.yml +1 -1
  3. package/package.json +7 -4
  4. package/skills/dk-trace-report/SKILL.md +288 -0
  5. package/skills/dk-trace-report/config/examples/doc.json +56 -0
  6. package/skills/dk-trace-report/config/examples/legal.json +51 -0
  7. package/skills/dk-trace-report/config/examples/ppt.json +47 -0
  8. package/skills/dk-trace-report/config/examples/tax.json +46 -0
  9. package/skills/dk-trace-report/config/examples/trusted.json +122 -0
  10. package/skills/dk-trace-report/reference/sample_input.json +60 -0
  11. package/skills/dk-trace-report/resources/ECHARTS-NOTICE.txt +10 -0
  12. package/skills/dk-trace-report/resources/echarts.custom.min.js +48 -0
  13. package/skills/dk-trace-report/scripts/build_report_input.py +333 -0
  14. package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/chart_embed.py +4 -1
  15. package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/render_trace_html.py +1071 -536
  16. package/skills/dk-trace-report/scripts/run_paths.py +95 -0
  17. package/skills/dk-trace-report/scripts/trust_digest.py +77 -0
  18. package/skills/dknowc-legal-assistant/README.md +95 -0
  19. package/skills/dknowc-legal-assistant/SKILL.md +122 -0
  20. package/skills/dknowc-legal-assistant/attribution.json +5 -0
  21. package/skills/dknowc-legal-assistant/reference/answer-and-report.md +221 -0
  22. package/skills/dknowc-legal-assistant/reference/capability-layer.md +143 -0
  23. package/skills/dknowc-legal-assistant/reference/legal_claims.example.json +96 -0
  24. package/skills/dknowc-legal-assistant/reference/onboarding_scripts.md +198 -0
  25. package/skills/dknowc-legal-assistant/reference/policy_tags.json +2002 -0
  26. package/skills/dknowc-legal-assistant/reference/retrieval-statute.md +81 -0
  27. package/skills/dknowc-legal-assistant/reference/retrieval-v2.md +133 -0
  28. package/skills/dknowc-legal-assistant/reference/sample_search_result.md +33 -0
  29. package/skills/dknowc-legal-assistant/reference/sample_trace_report.html +940 -0
  30. package/skills/dknowc-legal-assistant/reference/tags.md +53 -0
  31. package/skills/dknowc-legal-assistant/reference/troubleshooting.md +50 -0
  32. package/skills/dknowc-legal-assistant/reference/verification-pass.md +59 -0
  33. package/skills/dknowc-legal-assistant/resources/echarts.custom.min.js +48 -0
  34. package/skills/dknowc-legal-assistant/scripts/api_key.py +68 -0
  35. package/skills/dknowc-legal-assistant/scripts/attribution.py +61 -0
  36. package/skills/dknowc-legal-assistant/scripts/calc_legal.py +375 -0
  37. package/skills/dknowc-legal-assistant/scripts/calc_period.py +155 -0
  38. package/skills/dknowc-legal-assistant/scripts/check_answer.py +664 -0
  39. package/skills/dknowc-legal-assistant/scripts/initialize.py +188 -0
  40. package/skills/dknowc-legal-assistant/scripts/legal_client.py +208 -0
  41. package/skills/dknowc-legal-assistant/scripts/legal_search.py +1059 -0
  42. package/skills/dknowc-legal-assistant/scripts/merge_search_results.py +630 -0
  43. package/skills/dknowc-legal-assistant/scripts/path_guard.py +92 -0
  44. package/skills/dknowc-legal-assistant/scripts/question_profile.py +215 -0
  45. package/skills/dknowc-legal-assistant/scripts/register_key.mjs +1152 -0
  46. package/skills/dknowc-legal-assistant/scripts/run_eval.py +109 -0
  47. package/skills/dknowc-legal-assistant/scripts/source_cards.py +321 -0
  48. package/skills/dknowc-legal-assistant/scripts/tag_catalog.py +162 -0
  49. package/skills/dknowc-legal-assistant/scripts/trace_report.config.json +66 -0
  50. package/skills/dknowc-legal-assistant/scripts/verify_claims.py +448 -0
  51. package/skills/dknowc-legal-assistant/scripts/websearch_convert.py +396 -0
  52. package/skills/dknowc-official-doc-writer/README.md +32 -21
  53. package/skills/dknowc-official-doc-writer/SKILL.md +28 -15
  54. package/skills/dknowc-official-doc-writer/config/trace_report.config.json +56 -0
  55. package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +14 -2
  56. package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +4 -0
  57. package/skills/dknowc-official-doc-writer/reference/genre_writing_notes.md +4 -0
  58. package/skills/dknowc-official-doc-writer/reference/initialization.md +13 -8
  59. package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +7 -7
  60. package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +21 -0
  61. package/skills/dknowc-official-doc-writer/reference/materials_pipeline.md +64 -7
  62. package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +1 -1
  63. package/skills/dknowc-official-doc-writer/reference/outline_rules.md +1 -1
  64. package/skills/dknowc-official-doc-writer/reference/output_guide.md +13 -13
  65. package/skills/dknowc-official-doc-writer/reference/research_notes.md +5 -3
  66. package/skills/dknowc-official-doc-writer/reference/review_checklist.md +6 -2
  67. package/skills/dknowc-official-doc-writer/reference/search_guide.md +44 -32
  68. package/skills/dknowc-official-doc-writer/reference/search_policy.md +63 -36
  69. package/skills/dknowc-official-doc-writer/reference/standards/01_report.md +3 -3
  70. package/skills/dknowc-official-doc-writer/reference/standards/02_qingshi.md +6 -3
  71. package/skills/dknowc-official-doc-writer/reference/standards/03_pifu.md +2 -2
  72. package/skills/dknowc-official-doc-writer/reference/standards/04_tongzhi.md +12 -3
  73. package/skills/dknowc-official-doc-writer/reference/standards/05_yijian.md +8 -2
  74. package/skills/dknowc-official-doc-writer/reference/standards/06_han.md +2 -2
  75. package/skills/dknowc-official-doc-writer/reference/standards/08_tongbao.md +2 -2
  76. package/skills/dknowc-official-doc-writer/reference/standards/09_tonggao.md +2 -2
  77. package/skills/dknowc-official-doc-writer/reference/standards/10_gonggao.md +2 -2
  78. package/skills/dknowc-official-doc-writer/reference/standards/11_fuhan_approve.md +2 -2
  79. package/skills/dknowc-official-doc-writer/reference/standards/12_fuhan_objection.md +2 -2
  80. package/skills/dknowc-official-doc-writer/reference/standards/13_reminder.md +3 -3
  81. package/skills/dknowc-official-doc-writer/reference/standards/14_generic.md +1 -1
  82. package/skills/dknowc-official-doc-writer/reference/standards/16_decision.md +2 -2
  83. package/skills/dknowc-official-doc-writer/reference/standards/18_order.md +1 -1
  84. package/skills/dknowc-official-doc-writer/reference/standards/19_gazette.md +1 -1
  85. package/skills/dknowc-official-doc-writer/reference/standards/20_motion.md +2 -2
  86. package/skills/dknowc-official-doc-writer/reference/standards/22_application.md +2 -2
  87. package/skills/dknowc-official-doc-writer/reference/standards/23_publicity.md +1 -1
  88. package/skills/dknowc-official-doc-writer/reference/standards/25_plan.md +2 -1
  89. package/skills/dknowc-official-doc-writer/reference/standards/26_summary.md +7 -1
  90. package/skills/dknowc-official-doc-writer/reference/standards/27_speech.md +4 -1
  91. package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +1 -1
  92. package/skills/dknowc-official-doc-writer/reference/task_router.md +4 -4
  93. package/skills/dknowc-official-doc-writer/reference/working_principles.md +4 -4
  94. package/skills/dknowc-official-doc-writer/reference/writing_method.md +166 -0
  95. package/skills/dknowc-official-doc-writer/reference/writing_rules.md +10 -4
  96. package/skills/dknowc-official-doc-writer/scripts/api_key.py +24 -25
  97. package/skills/dknowc-official-doc-writer/scripts/attribution.py +1 -1
  98. package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +205 -13
  99. package/skills/dknowc-official-doc-writer/scripts/check_materials.py +367 -22
  100. package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +5 -0
  101. package/skills/dknowc-official-doc-writer/scripts/deep_query.py +2 -1
  102. package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +20 -7
  103. package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -0
  104. package/skills/dknowc-official-doc-writer/scripts/format_document.py +88 -30
  105. package/skills/dknowc-official-doc-writer/scripts/initialize.py +232 -6
  106. package/skills/dknowc-official-doc-writer/scripts/local_memory.py +2 -6
  107. package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +100 -7
  108. package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +2 -1
  109. package/skills/dknowc-official-doc-writer/scripts/register.mjs +265 -32
  110. package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -0
  111. package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +117 -10
  112. package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -0
  113. package/skills/dknowc-official-doc-writer/scripts/update_skill.py +339 -0
  114. package/skills/dknowc-official-doc-writer/scripts/websearch_convert.py +326 -0
  115. package/skills/dknowc-ppt-assistant/README.md +7 -9
  116. package/skills/dknowc-ppt-assistant/SKILL.md +28 -19
  117. package/skills/dknowc-ppt-assistant/config/trace_report.config.json +65 -0
  118. package/skills/dknowc-ppt-assistant/references/initialization.md +20 -8
  119. package/skills/dknowc-ppt-assistant/references/material_usage.md +46 -9
  120. package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +7 -5
  121. package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +372 -920
  122. package/skills/dknowc-ppt-assistant/references/search_intro.md +2 -2
  123. package/skills/dknowc-ppt-assistant/references/svg-authoring.md +2 -2
  124. package/skills/dknowc-ppt-assistant/scripts/api_key.py +5 -28
  125. package/skills/dknowc-ppt-assistant/scripts/build_trace_input.py +188 -0
  126. package/skills/dknowc-ppt-assistant/scripts/initialize.py +238 -3
  127. package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +1 -10
  128. package/skills/dknowc-ppt-assistant/scripts/merge_search_results.py +604 -0
  129. package/skills/dknowc-ppt-assistant/scripts/preview_slide_html.py +4 -11
  130. package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +224 -63
  131. package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +29 -12
  132. package/skills/dknowc-ppt-assistant/scripts/update_skill.py +314 -0
  133. package/skills/dknowc-ppt-assistant/scripts/websearch_convert.py +326 -0
  134. package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +92 -29
  135. package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
  136. package/skills/dknowc-tax-assistant/README.md +54 -0
  137. package/skills/dknowc-tax-assistant/SKILL.md +99 -0
  138. package/skills/dknowc-tax-assistant/attribution.json +5 -0
  139. package/skills/dknowc-tax-assistant/reference/answer-and-report.md +100 -0
  140. package/skills/dknowc-tax-assistant/reference/capability-layer.md +205 -0
  141. package/skills/dknowc-tax-assistant/reference/onboarding_scripts.md +68 -0
  142. package/skills/dknowc-tax-assistant/reference/policy_tags.json +2002 -0
  143. package/skills/dknowc-tax-assistant/reference/retrieval-policy.md +43 -0
  144. package/skills/dknowc-tax-assistant/reference/retrieval-v2.md +58 -0
  145. package/skills/dknowc-tax-assistant/reference/tags.md +53 -0
  146. package/skills/dknowc-tax-assistant/reference/tax_claims.example.json +76 -0
  147. package/skills/dknowc-tax-assistant/reference/trace_report.config.json +46 -0
  148. package/skills/dknowc-tax-assistant/reference/troubleshooting.md +70 -0
  149. package/skills/dknowc-tax-assistant/reference/websearch-fallback.md +59 -0
  150. package/skills/dknowc-tax-assistant/resources/THIRD_PARTY_NOTICES.md +9 -0
  151. package/skills/dknowc-tax-assistant/resources/echarts.custom.min.js +48 -0
  152. package/skills/dknowc-tax-assistant/scripts/api_key.py +60 -0
  153. package/skills/dknowc-tax-assistant/scripts/attribution.py +61 -0
  154. package/skills/dknowc-tax-assistant/scripts/calc_period.py +156 -0
  155. package/skills/dknowc-tax-assistant/scripts/calc_tax.py +179 -0
  156. package/skills/dknowc-tax-assistant/scripts/check_answer.py +210 -0
  157. package/skills/dknowc-tax-assistant/scripts/initialize.py +208 -0
  158. package/skills/dknowc-tax-assistant/scripts/merge_search_results.py +631 -0
  159. package/skills/dknowc-tax-assistant/scripts/path_guard.py +23 -0
  160. package/skills/dknowc-tax-assistant/scripts/question_profile.py +444 -0
  161. package/skills/dknowc-tax-assistant/scripts/register_key.mjs +1173 -0
  162. package/skills/dknowc-tax-assistant/scripts/run_dir.py +149 -0
  163. package/skills/dknowc-tax-assistant/scripts/source_cards.py +372 -0
  164. package/skills/dknowc-tax-assistant/scripts/tag_catalog.py +164 -0
  165. package/skills/dknowc-tax-assistant/scripts/tax_client.py +218 -0
  166. package/skills/dknowc-tax-assistant/scripts/tax_search.py +403 -0
  167. package/skills/dknowc-tax-assistant/scripts/verify_claims.py +587 -0
  168. package/skills/dknowc-tax-assistant/scripts/websearch_convert.py +352 -0
  169. package/skills/dknowc-trusted-search/README.md +25 -19
  170. package/skills/dknowc-trusted-search/SKILL.md +205 -73
  171. package/skills/dknowc-trusted-search/config/trace_report.config.json +119 -0
  172. package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +3 -3
  173. package/skills/dknowc-trusted-search/reference/sample_trace_report.html +286 -191
  174. package/skills/dknowc-trusted-search/resources/ECHARTS-NOTICE.txt +10 -0
  175. package/skills/dknowc-trusted-search/scripts/api_key.py +0 -1
  176. package/skills/dknowc-trusted-search/scripts/attribution.py +1 -1
  177. package/skills/dknowc-trusted-search/scripts/build_trace_input.py +173 -0
  178. package/skills/dknowc-trusted-search/scripts/deep_convert.py +79 -30
  179. package/skills/dknowc-trusted-search/scripts/deep_query.py +22 -33
  180. package/skills/dknowc-trusted-search/scripts/initialize.py +343 -2
  181. package/skills/dknowc-trusted-search/scripts/merge_search_results.py +222 -35
  182. package/skills/dknowc-trusted-search/scripts/register_key.mjs +241 -29
  183. package/skills/dknowc-trusted-search/scripts/source_display.py +59 -0
  184. package/skills/dknowc-trusted-search/scripts/trusted_search.py +67 -34
  185. package/skills/dknowc-trusted-search/scripts/update_skill.py +300 -0
  186. package/skills/dknowc-trusted-search/scripts/websearch_convert.py +328 -0
  187. package/src/index.js +18 -2
  188. package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +0 -2574
  189. package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
  190. package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
  191. package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +0 -2642
  192. package/skills/dknowc-trusted-search/official-docs/output/.gitkeep +0 -0
  193. package/skills/dknowc-trusted-search/official-docs/search-results/.gitkeep +0 -0
@@ -0,0 +1,444 @@
1
+ #!/usr/bin/env python3
2
+ """问题画像:把税务问题转成可校验的结构化字段。
3
+
4
+ 不是"全自动理解税务问题",而是给 Agent 一个固定落点:
5
+ - jurisdiction:地域(全国 / 省 / 省市县)
6
+ - as_of:截至日期
7
+ - domain:税务 / 社会保险
8
+ - tax_types:税种(增值税、企业所得税、个人所得税……)
9
+ - taxpayer_types:纳税人身份(小规模、一般纳税人、小型微利、个体工商户……)
10
+ - incentives:优惠事项(免征、减按、加计扣除、减半、留抵退税……)
11
+ - filing:申报/征期(按月、按季、年度汇算、预缴……)
12
+ - policy_years:问题里点名的年度
13
+ - entities:文件全名、引用短语、关键名词
14
+ - requested:用户要什么(税率/标准、适用条件、申报期限、计算、是否、最新……)
15
+
16
+ Agent 可以手写 profile 后用 --input 校验;也可以用 --question 做启发式初稿,
17
+ 再人工/模型修正。source_cards.py / verify_claims.py 都读这个文件。
18
+
19
+ 用法:
20
+ python3 scripts/question_profile.py \
21
+ --question "2026年北京市小规模纳税人月销售额10万元以下还免增值税吗?" \
22
+ --as-of 2026-11-10 \
23
+ --output tax_question_profile.json
24
+
25
+ python3 scripts/question_profile.py --input profile.json --output normalized.json
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import argparse
31
+ import json
32
+ import re
33
+ import sys
34
+ from datetime import date
35
+ from typing import Any, Dict, List
36
+
37
+ import run_dir
38
+
39
+ PROVINCES = (
40
+ "北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省", "吉林省",
41
+ "黑龙江省", "上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省",
42
+ "山东省", "河南省", "湖北省", "湖南省", "广东省", "广西壮族自治区",
43
+ "海南省", "重庆市", "四川省", "贵州省", "云南省", "西藏自治区",
44
+ "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区",
45
+ "香港特别行政区", "澳门特别行政区", "台湾省",
46
+ )
47
+
48
+ MUNICIPALITIES = {"北京市", "天津市", "上海市", "重庆市"}
49
+
50
+ PROVINCE_SHORT = {
51
+ p.replace("省", "").replace("市", "").replace("自治区", "").replace("特别行政区", ""): p
52
+ for p in PROVINCES
53
+ }
54
+
55
+ # 税务/社保问题最常见的地市与直辖市辖区:只用于把"大兴区""深圳市"归到省份,
56
+ # 不做行政区划全集。命中即映射到省级,问题本身仍保留区县名。
57
+ CITY_PROVINCE = {
58
+ # 直辖市辖区
59
+ "东城": "北京市", "西城": "北京市", "朝阳": "北京市", "海淀": "北京市",
60
+ "丰台": "北京市", "石景山": "北京市", "门头沟": "北京市", "房山": "北京市",
61
+ "通州": "北京市", "顺义": "北京市", "昌平": "北京市", "大兴": "北京市",
62
+ "怀柔": "北京市", "平谷": "北京市", "密云": "北京市", "延庆": "北京市",
63
+ "黄浦": "上海市", "徐汇": "上海市", "长宁": "上海市", "静安": "上海市",
64
+ "普陀": "上海市", "虹口": "上海市", "杨浦": "上海市", "闵行": "上海市",
65
+ "宝山": "上海市", "嘉定": "上海市", "浦东": "上海市", "金山": "上海市",
66
+ "松江": "上海市", "青浦": "上海市", "奉贤": "上海市", "崇明": "上海市",
67
+ "和平": "天津市", "河东": "天津市", "河西": "天津市", "南开": "天津市",
68
+ "红桥": "天津市", "东丽": "天津市", "西青": "天津市", "津南": "天津市",
69
+ "北辰": "天津市", "武清": "天津市", "宝坻": "天津市", "滨海新区": "天津市",
70
+ "宁河": "天津市", "静海": "天津市", "蓟州": "天津市",
71
+ "渝中": "重庆市", "江北": "重庆市", "沙坪坝": "重庆市", "九龙坡": "重庆市",
72
+ "南岸": "重庆市", "北碚": "重庆市", "渝北": "重庆市", "巴南": "重庆市",
73
+ "两江新区": "重庆市",
74
+ # 地市
75
+ "石家庄": "河北省", "唐山": "河北省", "廊坊": "河北省", "保定": "河北省",
76
+ "邯郸": "河北省", "秦皇岛": "河北省", "张家口": "河北省", "承德": "河北省",
77
+ "沧州": "河北省", "邢台": "河北省", "衡水": "河北省",
78
+ "太原": "山西省", "大同": "山西省", "运城": "山西省",
79
+ "呼和浩特": "内蒙古自治区", "包头": "内蒙古自治区", "鄂尔多斯": "内蒙古自治区",
80
+ "沈阳": "辽宁省", "大连": "辽宁省", "鞍山": "辽宁省",
81
+ "长春": "吉林省", "吉林市": "吉林省", "延边": "吉林省",
82
+ "哈尔滨": "黑龙江省", "大庆": "黑龙江省", "齐齐哈尔": "黑龙江省",
83
+ "南京": "江苏省", "苏州": "江苏省", "无锡": "江苏省", "常州": "江苏省",
84
+ "南通": "江苏省", "徐州": "江苏省", "扬州": "江苏省", "镇江": "江苏省",
85
+ "泰州": "江苏省", "盐城": "江苏省", "淮安": "江苏省", "连云港": "江苏省",
86
+ "宿迁": "江苏省",
87
+ "杭州": "浙江省", "宁波": "浙江省", "温州": "浙江省", "嘉兴": "浙江省",
88
+ "湖州": "浙江省", "绍兴": "浙江省", "金华": "浙江省", "衢州": "浙江省",
89
+ "舟山": "浙江省", "台州": "浙江省", "丽水": "浙江省",
90
+ "合肥": "安徽省", "芜湖": "安徽省", "蚌埠": "安徽省", "安庆": "安徽省",
91
+ "福州": "福建省", "厦门": "福建省", "泉州": "福建省", "漳州": "福建省",
92
+ "莆田": "福建省", "三明": "福建省", "南平": "福建省", "龙岩": "福建省",
93
+ "宁德": "福建省", "晋江": "福建省", "安溪": "福建省", "石狮": "福建省",
94
+ "南昌": "江西省", "赣州": "江西省", "九江": "江西省", "上饶": "江西省",
95
+ "济南": "山东省", "青岛": "山东省", "烟台": "山东省", "潍坊": "山东省",
96
+ "临沂": "山东省", "淄博": "山东省", "济宁": "山东省", "威海": "山东省",
97
+ "郑州": "河南省", "洛阳": "河南省", "开封": "河南省", "新乡": "河南省",
98
+ "武汉": "湖北省", "宜昌": "湖北省", "襄阳": "湖北省", "黄石": "湖北省",
99
+ "长沙": "湖南省", "株洲": "湖南省", "湘潭": "湖南省", "岳阳": "湖南省",
100
+ "广州": "广东省", "深圳": "广东省", "珠海": "广东省", "汕头": "广东省",
101
+ "佛山": "广东省", "韶关": "广东省", "湛江": "广东省", "肇庆": "广东省",
102
+ "江门": "广东省", "茂名": "广东省", "惠州": "广东省", "梅州": "广东省",
103
+ "汕尾": "广东省", "河源": "广东省", "阳江": "广东省", "清远": "广东省",
104
+ "东莞": "广东省", "中山": "广东省", "潮州": "广东省", "揭阳": "广东省",
105
+ "云浮": "广东省", "鹤山": "广东省", "普宁": "广东省",
106
+ "南宁": "广西壮族自治区", "柳州": "广西壮族自治区", "桂林": "广西壮族自治区",
107
+ "海口": "海南省", "三亚": "海南省", "儋州": "海南省",
108
+ "成都": "四川省", "绵阳": "四川省", "德阳": "四川省", "宜宾": "四川省",
109
+ "贵阳": "贵州省", "遵义": "贵州省", "六盘水": "贵州省",
110
+ "昆明": "云南省", "大理": "云南省", "曲靖": "云南省",
111
+ "拉萨": "西藏自治区", "日喀则": "西藏自治区", "林芝": "西藏自治区",
112
+ "西安": "陕西省", "咸阳": "陕西省", "宝鸡": "陕西省", "榆林": "陕西省",
113
+ "兰州": "甘肃省", "天水": "甘肃省", "酒泉": "甘肃省",
114
+ "西宁": "青海省", "海东": "青海省",
115
+ "银川": "宁夏回族自治区", "石嘴山": "宁夏回族自治区",
116
+ "乌鲁木齐": "新疆维吾尔自治区", "喀什": "新疆维吾尔自治区", "伊犁": "新疆维吾尔自治区",
117
+ }
118
+
119
+ TAX_TYPES = {
120
+ "个人所得税": (
121
+ "个人所得税", "个税", "工资薪金", "综合所得", "经营所得", "劳务报酬",
122
+ "年终奖", "全年一次性奖金", "专项附加扣除", "累计预扣", "汇算清缴",
123
+ ),
124
+ "增值税": (
125
+ "增值税", "小规模纳税人", "一般纳税人", "征收率", "进项税额", "销项税额",
126
+ "留抵退税", "专用发票", "普通发票", "销售额",
127
+ ),
128
+ "企业所得税": (
129
+ "企业所得税", "小型微利", "研发费用加计", "加计扣除", "税前扣除",
130
+ "应纳税所得额", "弥补亏损", "预缴",
131
+ ),
132
+ "消费税": ("消费税",),
133
+ "房产税": ("房产税",),
134
+ "城镇土地使用税": ("城镇土地使用税", "土地使用税"),
135
+ "车辆购置税": ("车辆购置税", "车购税", "购置税"),
136
+ "车船税": ("车船税",),
137
+ "印花税": ("印花税",),
138
+ "契税": ("契税",),
139
+ "资源税": ("资源税",),
140
+ "城市维护建设税": ("城市维护建设税", "城建税"),
141
+ "土地增值税": ("土地增值税",),
142
+ "关税": ("关税", "进出口税"),
143
+ "烟叶税": ("烟叶税",),
144
+ "环境保护税": ("环境保护税", "环保税"),
145
+ "耕地占用税": ("耕地占用税",),
146
+ "船舶吨税": ("船舶吨税",),
147
+ "社会保险费": (
148
+ "社保", "社会保险", "养老保险", "医疗保险", "失业保险", "工伤保险",
149
+ "生育保险", "缴费基数", "灵活就业",
150
+ ),
151
+ }
152
+
153
+ TAXPAYER_TYPES = {
154
+ "小规模纳税人": ("小规模纳税人", "小规模"),
155
+ "一般纳税人": ("一般纳税人",),
156
+ "小型微利企业": ("小型微利", "小微企业"),
157
+ "个体工商户": ("个体工商户", "个体户"),
158
+ "自然人": ("自然人", "个人"),
159
+ "居民企业": ("居民企业",),
160
+ "非居民企业": ("非居民企业", "非居民"),
161
+ "灵活就业人员": ("灵活就业",),
162
+ "高新技术企业": ("高新技术企业",),
163
+ "境外单位或个人": ("境外单位", "境外个人", "外国企业"),
164
+ }
165
+
166
+ INCENTIVES = {
167
+ "免征": ("免征", "免税", "不征"),
168
+ "减征": ("减征", "减半", "减按"),
169
+ "加计扣除": ("加计扣除", "加计抵减"),
170
+ "留抵退税": ("留抵退税", "留抵"),
171
+ "即征即退": ("即征即退",),
172
+ "先征后返": ("先征后返", "先征后退"),
173
+ "困难减免": ("困难减免", "减免税"),
174
+ "税额抵免": ("税额抵免", "投资抵免"),
175
+ "加速折旧": ("加速折旧", "一次性扣除"),
176
+ "税收返还": ("税收返还", "财政返还"),
177
+ }
178
+
179
+ FILING_TERMS = {
180
+ "按月申报": ("按月申报", "按月"),
181
+ "按季申报": ("按季申报", "按季"),
182
+ "年度汇算": ("年度汇算", "汇算清缴", "综合所得汇算"),
183
+ "预缴": ("预缴", "预扣预缴"),
184
+ "申报期限": ("申报期限", "申报期", "征期", "截止日期", "次月"),
185
+ "纳税义务发生时间": ("纳税义务发生时间", "纳税义务时间"),
186
+ }
187
+
188
+ REQUESTED_TERMS = {
189
+ "税率/标准": ("税率", "征收率", "标准", "多少", "比例", "扣除标准", "上限", "下限", "基数"),
190
+ "适用条件": ("条件", "资格", "适用", "能不能", "可不可以", "是否", "有没有", "属不属于"),
191
+ "申报期限": ("申报期限", "申报期", "征期", "截止", "什么时候申报", "按月", "按季"),
192
+ "计算": ("怎么算", "计算", "算一下", "滞纳金", "税额", "应纳", "减免额", "算例"),
193
+ "政策依据": ("依据", "哪个文件", "什么文件", "文号", "出处", "第几条"),
194
+ "最新/现行": ("最新", "现行", "还有效", "延续", "到期", "2026", "2027"),
195
+ "办理流程": ("怎么办理", "申请", "备案", "流程", "资料", "提交"),
196
+ "优惠资格": ("优惠", "减免", "免征", "减半", "加计", "留抵"),
197
+ "逐项": ("逐项", "分别", "列举", "几项", "各是多少"),
198
+ }
199
+
200
+ DOC_TYPE_TERMS = {
201
+ "法律": ("法律", "税法"),
202
+ "行政法规": ("条例", "暂行条例"),
203
+ "部门规章": ("部门规章", "部令", "总局令", "令第"),
204
+ "规范性文件": ("公告", "通知", "办法", "规定", "批复", "意见", "实施细则"),
205
+ "政策解读": ("解读", "问答", "答记者问", "一图读懂"),
206
+ "新闻报道": ("新闻", "报道"),
207
+ }
208
+
209
+ OUT_OF_SCOPE_TERMS = (
210
+ "香港", "澳门", "台湾", "境外", "国外", "外国", "美国", "英国", "新加坡",
211
+ "日本", "韩国", "德国", "法国", "欧盟", "跨境税收协定",
212
+ )
213
+
214
+ DATE_RE = re.compile(r"(20\d{2}[-年/]\d{1,2}[-月/]\d{1,2}日?)")
215
+ YEAR_RE = re.compile(r"(?<!\d)((?:19|20)\d{2})(?!\d)")
216
+ LOCALITY_RE = re.compile(r"([一-龥]{2,10}(?:县|区|市|旗|盟|州))")
217
+ DOC_RE = re.compile(r"《[^》]{2,80}》")
218
+ QUOTED_RE = re.compile(r"[“\"]([^”\"]{2,40})[”\"]")
219
+
220
+
221
+ def _uniq(values: List[str]) -> List[str]:
222
+ out: List[str] = []
223
+ for value in values:
224
+ value = (value or "").strip()
225
+ if value and value not in out:
226
+ out.append(value)
227
+ return out
228
+
229
+
230
+ def _norm_date(value: str) -> str:
231
+ text = (value or "").strip()
232
+ if not text:
233
+ return date.today().isoformat()
234
+ text = text.replace("年", "-").replace("月", "-").replace("日", "")
235
+ text = text.replace("/", "-")
236
+ parts = [p for p in text.split("-") if p]
237
+ if len(parts) >= 3:
238
+ try:
239
+ return date(int(parts[0]), int(parts[1]), int(parts[2])).isoformat()
240
+ except ValueError:
241
+ pass
242
+ if len(parts) == 1 and re.fullmatch(r"(?:19|20)\d{2}", parts[0]):
243
+ return f"{parts[0]}-01-01"
244
+ return text
245
+
246
+
247
+ def _find_province(text: str) -> str:
248
+ province = next((p for p in PROVINCES if p in text), "")
249
+ if province:
250
+ return province
251
+ # 短名按长度倒序,避免"吉林"先命中"吉林市"以外的无关词。
252
+ for short in sorted(PROVINCE_SHORT, key=len, reverse=True):
253
+ if short and short in text:
254
+ return PROVINCE_SHORT[short]
255
+ return ""
256
+
257
+
258
+ def _find_city_province(text: str) -> str:
259
+ for city in sorted(CITY_PROVINCE, key=len, reverse=True):
260
+ if city in text:
261
+ return CITY_PROVINCE[city]
262
+ return ""
263
+
264
+
265
+ def _extract_jurisdiction(question: str, explicit: str = "") -> str:
266
+ if explicit.strip():
267
+ return explicit.strip()
268
+ province = _find_province(question)
269
+ rest = question
270
+ if province:
271
+ idx = question.find(province)
272
+ if idx >= 0:
273
+ rest = question[idx + len(province):]
274
+ match = LOCALITY_RE.search(rest)
275
+ locality = match.group(1) if match else ""
276
+ if locality in {"本市", "该市", "全市", "各县", "市区", "当地", "本省", "全省", "全国"}:
277
+ locality = ""
278
+ if province and locality:
279
+ return province + locality
280
+ if province:
281
+ return province
282
+ if locality:
283
+ return _find_city_province(locality) or locality
284
+ city_province = _find_city_province(question)
285
+ if city_province:
286
+ return city_province
287
+ # 税务问题绝大多数默认全国口径;地方口径会在标题/机构里体现,由 source_cards 再核。
288
+ return "全国"
289
+
290
+
291
+ def _match_terms(question: str, mapping: Dict[str, tuple]) -> List[str]:
292
+ return [name for name, terms in mapping.items() if any(t in question for t in terms)]
293
+
294
+
295
+ def _extract_tax_types(question: str) -> List[str]:
296
+ return _match_terms(question, TAX_TYPES)
297
+
298
+
299
+ def _extract_taxpayer_types(question: str) -> List[str]:
300
+ found = _match_terms(question, TAXPAYER_TYPES)
301
+ # "个人"是高频泛词;已经命中具体身份时不再单列"自然人"。
302
+ if "自然人" in found and len(found) > 1 and "境外单位或个人" not in question:
303
+ found = [x for x in found if x != "自然人"]
304
+ return found
305
+
306
+
307
+ def _extract_incentives(question: str) -> List[str]:
308
+ return _match_terms(question, INCENTIVES)
309
+
310
+
311
+ def _extract_filing(question: str) -> List[str]:
312
+ return _match_terms(question, FILING_TERMS)
313
+
314
+
315
+ def _extract_domains(question: str, tax_types: List[str]) -> List[str]:
316
+ domains: List[str] = []
317
+ if any(t not in ("社会保险费",) for t in tax_types) or any(
318
+ term in question for term in ("税", "纳税", "发票", "申报", "滞纳金", "税务")
319
+ ):
320
+ domains.append("税务")
321
+ if "社会保险费" in tax_types:
322
+ domains.append("社会保险")
323
+ return domains or ["税务"]
324
+
325
+
326
+ def _extract_doc_types(question: str) -> List[str]:
327
+ return _match_terms(question, DOC_TYPE_TERMS)
328
+
329
+
330
+ def _extract_requested(question: str) -> List[str]:
331
+ return _match_terms(question, REQUESTED_TERMS)
332
+
333
+
334
+ def _extract_entities(question: str, tax_types: List[str], taxpayer_types: List[str],
335
+ incentives: List[str]) -> List[str]:
336
+ entities: List[str] = []
337
+ entities.extend(DOC_RE.findall(question))
338
+ entities.extend(QUOTED_RE.findall(question))
339
+ entities.extend(tax_types)
340
+ entities.extend(taxpayer_types)
341
+ entities.extend(incentives)
342
+ for term in (
343
+ "专项附加扣除", "全年一次性奖金", "月销售额10万元", "月销售额", "季度销售额",
344
+ "起征点", "免征额", "税率表", "速算扣除数", "滞纳金", "纳税义务发生时间",
345
+ "缴费基数", "上下限", "汇算清缴", "预扣预缴", "留抵退税", "加计扣除",
346
+ ):
347
+ if term in question:
348
+ entities.append(term)
349
+ if not entities and question:
350
+ entities.append("税务")
351
+ return _uniq(entities)
352
+
353
+
354
+ def build_profile(question: str, as_of: str = "", jurisdiction: str = "") -> Dict[str, Any]:
355
+ question = (question or "").strip()
356
+ date_match = DATE_RE.search(question)
357
+ tax_types = _extract_tax_types(question)
358
+ taxpayer_types = _extract_taxpayer_types(question)
359
+ incentives = _extract_incentives(question)
360
+ out_of_scope = [term for term in OUT_OF_SCOPE_TERMS if term in question]
361
+ return {
362
+ "question": question,
363
+ "jurisdiction": _extract_jurisdiction(question, jurisdiction),
364
+ "as_of": _norm_date(as_of or (date_match.group(1) if date_match else "")),
365
+ "domain": _extract_domains(question, tax_types),
366
+ "tax_types": tax_types,
367
+ "taxpayer_types": taxpayer_types,
368
+ "incentives": incentives,
369
+ "filing": _extract_filing(question),
370
+ "policy_years": _uniq(YEAR_RE.findall(question)),
371
+ "doc_types": _extract_doc_types(question),
372
+ "entities": _extract_entities(question, tax_types, taxpayer_types, incentives),
373
+ "requested": _extract_requested(question),
374
+ "scope_notice": (
375
+ "本 Skill 只覆盖中国大陆税务;涉港澳台/外国税制只答内地一侧义务,域外规则不展开"
376
+ if out_of_scope else ""
377
+ ),
378
+ "out_of_scope": bool(out_of_scope),
379
+ }
380
+
381
+
382
+ def validate_profile(profile: Dict[str, Any]) -> List[str]:
383
+ issues: List[str] = []
384
+ if not isinstance(profile, dict):
385
+ return ["profile 必须是 JSON 对象"]
386
+ if not str(profile.get("question") or "").strip():
387
+ issues.append("缺少 question(原始问题)")
388
+ if not str(profile.get("jurisdiction") or "").strip():
389
+ issues.append("缺少 jurisdiction(问题地域);无法确定时必须写“全国”或具体省市县")
390
+ if not str(profile.get("as_of") or "").strip():
391
+ issues.append("缺少 as_of(截至日期)")
392
+ if not isinstance(profile.get("entities"), list) or not profile.get("entities"):
393
+ issues.append("entities 必须是非空数组")
394
+ if not isinstance(profile.get("requested"), list) or not profile.get("requested"):
395
+ issues.append("requested 必须是非空数组")
396
+ if not isinstance(profile.get("tax_types"), list):
397
+ issues.append("tax_types 必须是数组(可为空,但字段要在)")
398
+ if not isinstance(profile.get("taxpayer_types"), list):
399
+ issues.append("taxpayer_types 必须是数组(可为空,但字段要在)")
400
+ return issues
401
+
402
+
403
+ def main() -> int:
404
+ parser = argparse.ArgumentParser(description="生成/校验税务问题画像")
405
+ parser.add_argument("--question", help="用户原始问题")
406
+ parser.add_argument("--as-of", default="", help="截至日期 YYYY-MM-DD")
407
+ parser.add_argument("--jurisdiction", default="", help="问题地域,如“北京市大兴区”")
408
+ parser.add_argument("--input", help="已有 profile JSON,校验并规范化")
409
+ parser.add_argument("--out", help="运行目录(会话工作区);与 --output 文件名一起用")
410
+ parser.add_argument("--output", default="tax_question_profile.json",
411
+ help="输出文件名(配合 --out)或显式输出路径(不得指向 Skill 安装目录)")
412
+ args = parser.parse_args()
413
+
414
+ if args.input:
415
+ try:
416
+ profile = json.loads(
417
+ run_dir.resolve_run_input(args.input, args.out).read_text(encoding="utf-8")
418
+ )
419
+ except (OSError, json.JSONDecodeError, ValueError) as exc:
420
+ parser.error(f"profile 不可读:{exc}")
421
+ else:
422
+ if not args.question:
423
+ parser.error("必须提供 --question 或 --input")
424
+ profile = build_profile(args.question, args.as_of, args.jurisdiction)
425
+
426
+ issues = validate_profile(profile)
427
+ if issues:
428
+ print("问题画像不完整:", file=sys.stderr)
429
+ for issue in issues:
430
+ print(f" - {issue}", file=sys.stderr)
431
+ return 1
432
+
433
+ try:
434
+ out = run_dir.resolve_write_target(args.output, args.out)
435
+ except ValueError as exc:
436
+ parser.error(str(exc))
437
+ out.parent.mkdir(parents=True, exist_ok=True)
438
+ out.write_text(json.dumps(profile, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
439
+ print(json.dumps({"output": str(out), "profile": profile}, ensure_ascii=False, indent=2))
440
+ return 0
441
+
442
+
443
+ if __name__ == "__main__":
444
+ raise SystemExit(main())