dknowc-dsh 2.3.0 → 2.3.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 (133) hide show
  1. package/README.md +3 -47
  2. package/package.json +2 -2
  3. package/skills/dknowc-official-doc-writer/README.md +23 -14
  4. package/skills/dknowc-official-doc-writer/SKILL.md +4 -3
  5. package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +1 -1
  6. package/skills/dknowc-official-doc-writer/reference/initialization.md +19 -16
  7. package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +7 -7
  8. package/skills/dknowc-official-doc-writer/reference/materials_pipeline.md +1 -1
  9. package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +42 -31
  10. package/skills/dknowc-official-doc-writer/reference/output_guide.md +10 -11
  11. package/skills/dknowc-official-doc-writer/reference/research_notes.md +1 -1
  12. package/skills/dknowc-official-doc-writer/reference/review_checklist.md +2 -2
  13. package/skills/dknowc-official-doc-writer/reference/revision_workflow.md +2 -2
  14. package/skills/dknowc-official-doc-writer/reference/search_guide.md +7 -7
  15. package/skills/dknowc-official-doc-writer/reference/search_intro.md +4 -4
  16. package/skills/dknowc-official-doc-writer/reference/standards/00_index.md +63 -77
  17. package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +0 -1
  18. package/skills/dknowc-official-doc-writer/reference/task_router.md +2 -2
  19. package/skills/dknowc-official-doc-writer/reference/working_principles.md +1 -1
  20. package/skills/dknowc-official-doc-writer/reference/writing_rules.md +1 -1
  21. package/skills/dknowc-official-doc-writer/scripts/api_key.py +9 -2
  22. package/skills/dknowc-official-doc-writer/scripts/attribution.py +1 -1
  23. package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +11 -9
  24. package/skills/dknowc-official-doc-writer/scripts/check_materials.py +8 -5
  25. package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +4 -4
  26. package/skills/dknowc-official-doc-writer/scripts/deep_query.py +1 -1
  27. package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +3 -2
  28. package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -1
  29. package/skills/dknowc-official-doc-writer/scripts/format_document.py +30 -13
  30. package/skills/dknowc-official-doc-writer/scripts/initialize.py +15 -7
  31. package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +2 -3
  32. package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +13 -6
  33. package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +1 -1
  34. package/skills/dknowc-official-doc-writer/scripts/prose_lint.py +7 -2
  35. package/skills/dknowc-official-doc-writer/scripts/register.mjs +538 -205
  36. package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +10 -10
  37. package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -1
  38. package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +3 -3
  39. package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -1
  40. package/skills/dknowc-ppt-assistant/README.md +21 -7
  41. package/skills/dknowc-ppt-assistant/SKILL.md +5 -5
  42. package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +3 -2
  43. package/skills/dknowc-ppt-assistant/references/initialization.md +45 -6
  44. package/skills/dknowc-ppt-assistant/references/material_usage.md +7 -7
  45. package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +48 -17
  46. package/skills/dknowc-ppt-assistant/references/svg-authoring.md +1 -1
  47. package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +2 -0
  48. package/skills/dknowc-ppt-assistant/scripts/api_key.py +7 -0
  49. package/skills/dknowc-ppt-assistant/scripts/attribution.py +2 -2
  50. package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +1 -1
  51. package/skills/dknowc-ppt-assistant/scripts/config.py +9 -9
  52. package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +1 -2
  53. package/skills/dknowc-ppt-assistant/scripts/error_helper.py +3 -3
  54. package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +1 -1
  55. package/skills/dknowc-ppt-assistant/scripts/initialize.py +11 -13
  56. package/skills/dknowc-ppt-assistant/scripts/language_tags.py +1 -1
  57. package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +17 -15
  58. package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +3 -2
  59. package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +1 -1
  60. package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +1 -1
  61. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +1 -1
  62. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +1 -1
  63. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +1 -1
  64. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +1 -1
  65. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +1 -1
  66. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +2 -2
  67. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +1 -1
  68. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +3 -3
  69. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +1 -1
  70. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +1 -1
  71. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +2 -2
  72. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +2 -2
  73. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +2 -2
  74. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +2 -2
  75. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +1 -1
  76. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +1 -1
  77. package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +2 -2
  78. package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +2 -2
  79. package/skills/dknowc-ppt-assistant/scripts/project_utils.py +2 -2
  80. package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +710 -322
  81. package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +9 -9
  82. package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +1 -1
  83. package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +2 -2
  84. package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +1 -1
  85. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +2 -9
  86. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +1 -1
  87. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +3 -3
  88. package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +2 -2
  89. package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +9 -10
  90. package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +4 -4
  91. package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +2 -2
  92. package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +1 -1
  93. package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +1 -1
  94. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +2 -2
  95. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +1 -1
  96. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +1 -1
  97. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +1 -1
  98. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +2 -2
  99. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +1 -1
  100. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +2 -2
  101. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +2 -2
  102. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2 -2
  103. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +1 -1
  104. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +1 -1
  105. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +2 -2
  106. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +9 -11
  107. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +7 -5
  108. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +1 -1
  109. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1 -1
  110. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +1 -1
  111. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +2 -2
  112. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +2 -2
  113. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +1 -1
  114. package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +22 -5
  115. package/skills/dknowc-ppt-assistant/scripts/update_spec.py +25 -1
  116. package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +11 -9
  117. package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
  118. package/skills/dknowc-trusted-search/README.md +8 -8
  119. package/skills/dknowc-trusted-search/SKILL.md +74 -56
  120. package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +40 -15
  121. package/skills/dknowc-trusted-search/scripts/api_key.py +11 -26
  122. package/skills/dknowc-trusted-search/scripts/attribution.py +1 -1
  123. package/skills/dknowc-trusted-search/scripts/deep_query.py +1 -1
  124. package/skills/dknowc-trusted-search/scripts/initialize.py +10 -10
  125. package/skills/dknowc-trusted-search/scripts/mcp_direct.py +3 -2
  126. package/skills/dknowc-trusted-search/scripts/register_key.mjs +617 -275
  127. package/skills/dknowc-trusted-search/scripts/render_trace_html.py +4 -4
  128. package/skills/dknowc-trusted-search/scripts/trusted_search.py +2 -2
  129. package/skills/dknowc-official-doc-writer/scripts/mcp_convert.py +0 -287
  130. package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +0 -842
  131. package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +0 -507
  132. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +0 -346
  133. package/skills/dknowc-trusted-search/scripts/mcp_convert.py +0 -198
@@ -1,346 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- PPT Master - Legacy SVG Rounded Rectangle Diagnostic
4
-
5
- Historical diagnostic that converts <rect> elements with rx/ry to equivalent
6
- <path> elements. It is not part of finalize_svg.py or the supported export
7
- workflow; PowerPoint's manual "Convert to Shape" behavior is not supported.
8
-
9
- Usage:
10
- python3 scripts/svg_finalize/svg_rect_to_path.py <SVG file or directory>
11
- python3 scripts/svg_finalize/svg_rect_to_path.py <project_path> -s output
12
- python3 scripts/svg_finalize/svg_rect_to_path.py <project_path> -s final -o svg_rounded
13
-
14
- Examples:
15
- python3 scripts/svg_finalize/svg_rect_to_path.py examples/ppt169_demo
16
- python3 scripts/svg_finalize/svg_rect_to_path.py examples/ppt169_demo/svg_output/01_cover.svg
17
-
18
- Output:
19
- - Directory mode: outputs to svg_rounded/ subdirectory
20
- - File mode: outputs to <filename>_rounded.svg
21
- """
22
-
23
- import sys
24
- import re
25
- import argparse
26
- from pathlib import Path
27
- from typing import Any, Tuple
28
- from xml.etree import ElementTree as ET
29
-
30
- _SCRIPTS_DIR = Path(__file__).resolve().parents[1]
31
- if str(_SCRIPTS_DIR) not in sys.path:
32
- sys.path.insert(0, str(_SCRIPTS_DIR))
33
-
34
- from console_encoding import configure_utf8_stdio # noqa: E402
35
-
36
- configure_utf8_stdio()
37
-
38
-
39
- def rect_to_rounded_path(
40
- x: float,
41
- y: float,
42
- width: float,
43
- height: float,
44
- rx: float,
45
- ry: float,
46
- ) -> str:
47
- """
48
- Convert a rounded rectangle to an SVG path string.
49
- Uses elliptical arc commands to draw rounded corners.
50
- """
51
- # Limit corner radius to half of width/height
52
- rx = min(rx, width / 2)
53
- ry = min(ry, height / 2)
54
-
55
- # Calculate key points
56
- x1 = x + rx
57
- x2 = x + width - rx
58
- y1 = y + ry
59
- y2 = y + height - ry
60
-
61
- # Build path
62
- path = (
63
- f"M{x1:.2f},{y:.2f} "
64
- f"H{x2:.2f} "
65
- f"A{rx:.2f},{ry:.2f} 0 0 1 {x + width:.2f},{y1:.2f} "
66
- f"V{y2:.2f} "
67
- f"A{rx:.2f},{ry:.2f} 0 0 1 {x2:.2f},{y + height:.2f} "
68
- f"H{x1:.2f} "
69
- f"A{rx:.2f},{ry:.2f} 0 0 1 {x:.2f},{y2:.2f} "
70
- f"V{y1:.2f} "
71
- f"A{rx:.2f},{ry:.2f} 0 0 1 {x1:.2f},{y:.2f} "
72
- f"Z"
73
- )
74
-
75
- # Clean up excess decimals
76
- path = re.sub(r'\.00(?=\s|,|[A-Za-z]|$)', '', path)
77
-
78
- return path
79
-
80
-
81
- def parse_float(val: str, default: float = 0.0) -> float:
82
- """Safely parse a float value."""
83
- if not val:
84
- return default
85
- try:
86
- # Remove units
87
- val = re.sub(r'(px|pt|em|%|rem)$', '', val.strip())
88
- return float(val)
89
- except ValueError:
90
- return default
91
-
92
-
93
- def process_svg(content: str, verbose: bool = False) -> Tuple[str, int]:
94
- """
95
- Process SVG content, converting rounded rectangles to paths.
96
- Returns (processed content, conversion count).
97
- """
98
- converted_count = 0
99
-
100
- # Save original XML declaration
101
- xml_declaration = ''
102
- if content.strip().startswith('<?xml'):
103
- match = re.match(r'(<\?xml[^?]*\?>)', content)
104
- if match:
105
- xml_declaration = match.group(1) + '\n'
106
-
107
- # Register SVG namespaces
108
- ET.register_namespace('', 'http://www.w3.org/2000/svg')
109
- ET.register_namespace('xlink', 'http://www.w3.org/1999/xlink')
110
-
111
- try:
112
- root = ET.fromstring(content)
113
- except ET.ParseError as e:
114
- if verbose:
115
- print(f" XML parse error: {e}")
116
- return content, 0
117
-
118
- # Get default namespace
119
- ns = ''
120
- if root.tag.startswith('{'):
121
- ns = root.tag.split('}')[0] + '}'
122
-
123
- def get_tag_name(tag: str) -> str:
124
- """Get tag name without namespace."""
125
- if tag.startswith('{'):
126
- return tag.split('}')[1]
127
- return tag
128
-
129
- def process_element(elem: ET.Element) -> None:
130
- """Process a single element."""
131
- nonlocal converted_count
132
- tag_name = get_tag_name(elem.tag)
133
-
134
- # Process rounded rectangles
135
- if tag_name == 'rect':
136
- rx = parse_float(elem.get('rx', '0'))
137
- ry = parse_float(elem.get('ry', '0'))
138
-
139
- # If only one is specified, the other takes the same value
140
- if rx == 0 and ry > 0:
141
- rx = ry
142
- elif ry == 0 and rx > 0:
143
- ry = rx
144
-
145
- if rx > 0 or ry > 0:
146
- x = parse_float(elem.get('x', '0'))
147
- y = parse_float(elem.get('y', '0'))
148
- width = parse_float(elem.get('width', '0'))
149
- height = parse_float(elem.get('height', '0'))
150
-
151
- if width > 0 and height > 0:
152
- # Generate path
153
- path_d = rect_to_rounded_path(x, y, width, height, rx, ry)
154
-
155
- # rect-specific attributes
156
- rect_attrs = {'x', 'y', 'width', 'height', 'rx', 'ry'}
157
-
158
- # Change element to path
159
- elem.tag = ns + 'path' if ns else 'path'
160
- elem.set('d', path_d)
161
-
162
- # Remove rect-specific attributes
163
- for attr in rect_attrs:
164
- if attr in elem.attrib:
165
- del elem.attrib[attr]
166
-
167
- converted_count += 1
168
- if verbose:
169
- print(f" Converted rounded rect: rx={rx}, ry={ry}")
170
-
171
- # Recursively process child elements
172
- for child in elem:
173
- process_element(child)
174
-
175
- # Process all elements
176
- process_element(root)
177
-
178
- # Convert back to string
179
- result = ET.tostring(root, encoding='unicode')
180
-
181
- # Add XML declaration (if originally present)
182
- if xml_declaration:
183
- result = xml_declaration + result
184
-
185
- return result, converted_count
186
-
187
-
188
- def process_svg_file(input_path: Path, output_path: Path, verbose: bool = False) -> tuple[bool, int]:
189
- """Process a single SVG file."""
190
- try:
191
- with open(input_path, 'r', encoding='utf-8') as f:
192
- content = f.read()
193
-
194
- processed, count = process_svg(content, verbose)
195
-
196
- # Ensure output directory exists
197
- output_path.parent.mkdir(parents=True, exist_ok=True)
198
-
199
- with open(output_path, 'w', encoding='utf-8') as f:
200
- f.write(processed)
201
-
202
- return True, count
203
-
204
- except Exception as e:
205
- if verbose:
206
- print(f" Error: {e}")
207
- return False, 0
208
-
209
-
210
- def find_svg_files(project_path: Path, source: str = 'output') -> tuple[list[Path], str]:
211
- """Find SVG files in a project."""
212
- dir_map = {
213
- 'output': 'svg_output',
214
- 'final': 'svg_final',
215
- 'flat': 'svg_output_flattext',
216
- 'final_flat': 'svg_final_flattext',
217
- }
218
-
219
- dir_name = dir_map.get(source, source)
220
- svg_dir = project_path / dir_name
221
-
222
- if not svg_dir.exists():
223
- if (project_path / 'svg_output').exists():
224
- dir_name = 'svg_output'
225
- svg_dir = project_path / dir_name
226
- elif project_path.is_dir():
227
- svg_dir = project_path
228
- dir_name = project_path.name
229
-
230
- if not svg_dir.exists():
231
- return [], ''
232
-
233
- return sorted(svg_dir.glob('*.svg')), dir_name
234
-
235
-
236
- def main() -> None:
237
- """Run the CLI entry point."""
238
- parser = argparse.ArgumentParser(
239
- description='PPT Master - Legacy SVG Rounded Rectangle Diagnostic',
240
- formatter_class=argparse.RawDescriptionHelpFormatter,
241
- epilog='''
242
- Examples:
243
- %(prog)s examples/ppt169_demo
244
- %(prog)s examples/ppt169_demo -s final
245
- %(prog)s examples/ppt169_demo/svg_output/01_cover.svg
246
-
247
- What it does:
248
- Converts <rect> elements with rx/ry to equivalent <path> elements.
249
- Legacy diagnostic only; the standard pipeline preserves SVG rounded rectangles.
250
- '''
251
- )
252
-
253
- parser.add_argument('path', type=str, help='SVG file or project directory path')
254
- parser.add_argument('-s', '--source', type=str, default='output',
255
- help='SVG source: output/final/flat/final_flat or subdirectory name (default: output)')
256
- parser.add_argument('-o', '--output', type=str, default='svg_rounded',
257
- help='Output directory name (default: svg_rounded)')
258
- parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output')
259
- parser.add_argument('-q', '--quiet', action='store_true', help='Quiet mode')
260
-
261
- args = parser.parse_args()
262
-
263
- input_path = Path(args.path)
264
-
265
- if not input_path.exists():
266
- print(f"Error: Path not found: {input_path}")
267
- sys.exit(1)
268
-
269
- verbose = args.verbose and not args.quiet
270
- quiet = args.quiet
271
-
272
- if not quiet:
273
- print("PPT Master - Legacy SVG Rounded Rectangle Diagnostic")
274
- print("=" * 50)
275
-
276
- total_converted = 0
277
-
278
- if input_path.is_file() and input_path.suffix.lower() == '.svg':
279
- # Single file mode
280
- output_path = input_path.with_stem(input_path.stem + '_rounded')
281
-
282
- if not quiet:
283
- print(f" Input: {input_path}")
284
- print(f" Output: {output_path}")
285
- print()
286
-
287
- success, count = process_svg_file(input_path, output_path, verbose)
288
- total_converted = count
289
-
290
- if success:
291
- if not quiet:
292
- print(f"[DONE] Saved: {output_path}")
293
- else:
294
- print(f"[FAIL] Processing failed")
295
- sys.exit(1)
296
-
297
- else:
298
- # Directory/project mode
299
- svg_files, source_dir = find_svg_files(input_path, args.source)
300
-
301
- if not svg_files:
302
- print("Error: No SVG files found")
303
- sys.exit(1)
304
-
305
- output_dir = input_path / args.output
306
-
307
- if not quiet:
308
- print(f" Project path: {input_path}")
309
- print(f" SVG source: {source_dir}")
310
- print(f" Output directory: {args.output}")
311
- print(f" File count: {len(svg_files)}")
312
- print()
313
-
314
- success_count = 0
315
- for i, svg_file in enumerate(svg_files, 1):
316
- output_path = output_dir / svg_file.name
317
-
318
- if verbose:
319
- print(f" [{i}/{len(svg_files)}] {svg_file.name}")
320
-
321
- success, count = process_svg_file(svg_file, output_path, verbose)
322
-
323
- if success:
324
- success_count += 1
325
- total_converted += count
326
- if not verbose and not quiet:
327
- print(f" [{i}/{len(svg_files)}] {svg_file.name} OK")
328
- else:
329
- if not quiet:
330
- print(f" [{i}/{len(svg_files)}] {svg_file.name} FAILED")
331
-
332
- if not quiet:
333
- print()
334
- print(f"[DONE] Succeeded: {success_count}/{len(svg_files)}")
335
- print(f" Output directory: {output_dir}")
336
-
337
- # Show statistics
338
- if not quiet:
339
- print()
340
- print(f"Conversion stats: rounded rect -> path: {total_converted}")
341
-
342
- sys.exit(0)
343
-
344
-
345
- if __name__ == '__main__':
346
- main()
@@ -1,198 +0,0 @@
1
- #!/usr/bin/env python3
2
- """把 MCP「深知可信工作台」trusted_search(include_details=true 形态)的返回
3
- 转换成深知可信搜索 REST 接口的原始响应形态,供本 Skill 全部下游流程复用。
4
-
5
- 背景(搜索版 1.3.4 起):检测到宿主已连接 MCP「深知可信工作台」时,搜索走 MCP 通道
6
- (免 API Key)。模型在对话层调用 MCP 工具后,把完整返回 JSON 保存到
7
- official-docs/search-results/,再运行本脚本转换——转换产物与 trusted_search.py
8
- 直调 REST 的输出同构(content.data.检索文章 / policyFiles / knowledgeBase /
9
- search_meta),答案自检、核验报告生成与可视化全部按现有流程执行。
10
-
11
- 字段映射:
12
- title → 文章标题 source → 数据源 date → 发布日期
13
- url → 源网址 date_confidence → 发布日期可信度
14
- snapshot → screenShotPath
15
- segments[{title,content}] → 段落[{标题,内容}](段落标题为标题链数据源;
16
- segments 缺失时用 paragraph 兜底构造无标题单段)
17
- doc_number → 反向构造 policyFiles[{title, writtenText}](渲染器的
18
- 文号匹配按现有逻辑工作;MCP 侧已完成变体匹配,直接复用其结果)
19
- 内容中的 &lt;/&gt;/&amp;/&quot; HTML 实体顺手反转义(MCP 透传未清洗)。
20
-
21
- 用法:
22
- python3 scripts/mcp_convert.py official-docs/search-results/mcp_raw.json \
23
- --area 北京市 --purpose "搜索目的" \
24
- --output official-docs/search-results/result_xxx.json
25
- """
26
-
27
- from __future__ import annotations
28
-
29
- import argparse
30
- import json
31
- import sys
32
- import unicodedata
33
- from pathlib import Path
34
-
35
- SKILL_ROOT = Path(__file__).resolve().parent.parent
36
- # 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
37
- import os as _os
38
- _ws = _os.environ.get("DKNWOC_WS_ROOT")
39
- if not _ws:
40
- # dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/,
41
- # 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
42
- _sid = _os.environ.get("DSH_SESSION_ID", "")
43
- _ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
44
- WS_ROOT = Path(_ws).resolve()
45
- SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
46
-
47
- HTML_ENTITIES = (("&lt;", "<"), ("&gt;", ">"), ("&amp;", "&"), ("&quot;", '"'),
48
- ("&lt;", "<"), ("&gt;", ">"), ("&amp;", "&"), ("&quot;", '"'))
49
-
50
-
51
- def clean_text(text: str) -> str:
52
- """反转义 MCP 透传内容中的 HTML 实体(全角/半角形式)并去首尾空白。"""
53
- out = str(text or "")
54
- for a, b in HTML_ENTITIES:
55
- out = out.replace(a, b)
56
- return out.strip()
57
-
58
-
59
- def first_value(item: dict, *keys: str) -> str:
60
- for key in keys:
61
- value = item.get(key)
62
- if value not in (None, "", [], {}):
63
- return str(value)
64
- return ""
65
-
66
-
67
- def parse_segments(material: dict) -> list:
68
- """segments → 段落[{标题,内容}]。兼容数组与(历史)字符串形态;缺失时用 paragraph 兜底。"""
69
- segments = material.get("segments")
70
- if isinstance(segments, str) and segments.strip().startswith("["):
71
- try: # 历史形态容错:repr 字符串
72
- import ast
73
- segments = ast.literal_eval(segments)
74
- except (ValueError, SyntaxError):
75
- segments = None
76
- paragraphs = []
77
- if isinstance(segments, list) and segments:
78
- for seg in segments:
79
- if not isinstance(seg, dict):
80
- continue
81
- title = clean_text(first_value(seg, "title", "标题"))
82
- content = clean_text(first_value(seg, "content", "内容"))
83
- if content:
84
- paragraphs.append({"标题": title, "内容": content})
85
- if not paragraphs:
86
- fallback = clean_text(first_value(material, "paragraph"))
87
- if fallback:
88
- paragraphs.append({"标题": "", "内容": fallback})
89
- return paragraphs
90
-
91
-
92
- def convert(data: dict, area: str, purpose: str) -> dict:
93
- materials = data.get("materials") or []
94
- articles, policy_files = [], []
95
- seen_pf = set()
96
- for material in materials:
97
- if not isinstance(material, dict):
98
- continue
99
- title = clean_text(first_value(material, "title", "文章标题"))
100
- if not title:
101
- continue
102
- article = {
103
- "文章标题": title,
104
- "数据源": clean_text(first_value(material, "source", "数据源")),
105
- "发布日期": clean_text(first_value(material, "date", "发布日期")),
106
- "发布日期可信度": clean_text(first_value(material, "date_confidence", "发布日期可信度")),
107
- "源网址": clean_text(first_value(material, "url", "源网址")),
108
- "段落": parse_segments(material),
109
- }
110
- snapshot = clean_text(first_value(material, "snapshot", "screenShotPath", "快照链接"))
111
- if snapshot:
112
- article["screenShotPath"] = snapshot
113
- doc_number = clean_text(first_value(material, "doc_number", "文号"))
114
- if doc_number:
115
- # 文号同时写入文章级(整理材料时直接复制,免跨文件翻 policyFiles——
116
- # 实测模型做跨文件标题匹配会跳过,2026-09-21 中医药轮 34 条现成文号取 0)
117
- article["文号"] = doc_number
118
- articles.append(article)
119
- if doc_number and title not in seen_pf:
120
- seen_pf.add(title)
121
- policy_files.append({"title": title, "writtenText": doc_number,
122
- "sourceUrl": article["源网址"] or None,
123
- "createDate": article["发布日期"] or None,
124
- "createDateReliability": article["发布日期可信度"] or None})
125
-
126
- mcp_meta = data.get("search_meta") if isinstance(data.get("search_meta"), dict) else {}
127
- payload = {
128
- "query": first_value(data, "query") or mcp_meta.get("query", ""),
129
- "eff_time": [mcp_meta.get("eff_time", "")],
130
- "service_area": [area or first_value(data, "service_area")],
131
- "knowBase": bool(mcp_meta.get("know_base", True)),
132
- "policy": True,
133
- "return_full_content": False,
134
- "segmentCount": int(mcp_meta.get("segment_count", 2) or 2),
135
- "simplified": bool(mcp_meta.get("simplified", False)),
136
- }
137
- knowledge_base = first_value(data, "knowledge_base_url", "knowledgeBase")
138
- content = {"data": {"检索文章": articles, "policyFiles": policy_files,
139
- "办理地域": area, "用户问题": payload["query"]}}
140
- if knowledge_base:
141
- content["knowledgeBase"] = knowledge_base
142
- return {
143
- "search_meta": {
144
- "query": payload["query"], "area": area, "time": mcp_meta.get("eff_time", ""),
145
- "requested_time": "", "time_ignored": False, "policy": True, "full": False,
146
- "clean": False, "segmentCount": payload["segmentCount"],
147
- "simplified": payload["simplified"], "MaterialLength": "",
148
- "searchType": [], "searchChannel": [], "purpose": purpose,
149
- "channel": "mcp",
150
- "knowledgeBase": knowledge_base,
151
- },
152
- "knowledgeBase": knowledge_base,
153
- "content": content,
154
- "request_body": payload,
155
- }
156
-
157
-
158
- def main() -> None:
159
- if hasattr(sys.stdout, "reconfigure"):
160
- sys.stdout.reconfigure(encoding="utf-8")
161
- parser = argparse.ArgumentParser(description="MCP trusted_search 返回 → REST 原始形态(供全下游流程复用)")
162
- parser.add_argument("input", help="MCP trusted_search 完整返回 JSON 文件(materials 形态)")
163
- parser.add_argument("--area", default="", help="本次检索地域(写入 search_meta.area)")
164
- parser.add_argument("--purpose", default="", help="搜索方案中的搜索目的(内部字段,不向用户展示)")
165
- parser.add_argument("--output", "-o", help="输出文件名,默认写入 official-docs/search-results/")
166
- args = parser.parse_args()
167
-
168
- raw = Path(args.input).expanduser()
169
- if not raw.is_absolute():
170
- raw = (SEARCH_RESULTS_DIR / raw).resolve()
171
- try:
172
- raw.relative_to(SEARCH_RESULTS_DIR.resolve())
173
- except ValueError:
174
- raise SystemExit(f"错误:输入文件必须位于 {SEARCH_RESULTS_DIR}") from None
175
- if not raw.is_file():
176
- raise SystemExit(f"错误:输入文件不存在: {raw}")
177
- data = json.loads(raw.read_text(encoding="utf-8"))
178
-
179
- out_name = args.output or (raw.stem + "_converted.json")
180
- out = Path(out_name).expanduser()
181
- if not out.is_absolute():
182
- out = (SEARCH_RESULTS_DIR / out.name).resolve()
183
- try:
184
- out.relative_to(SEARCH_RESULTS_DIR.resolve())
185
- except ValueError:
186
- raise SystemExit(f"错误:输出文件必须位于 {SEARCH_RESULTS_DIR}") from None
187
-
188
- converted = convert(data, args.area, args.purpose)
189
- articles = converted["content"]["data"]["检索文章"]
190
- out.write_text(json.dumps(converted, ensure_ascii=False, indent=2), encoding="utf-8")
191
- with_doc = sum(1 for a in articles if a["段落"])
192
- print(f"✓ 转换完成:{len(articles)} 篇材料({with_doc} 篇带段落)、"
193
- f"{len(converted['content']['data']['policyFiles'])} 条文号 → {out}")
194
- print(" 转换产物与 trusted_search.py 直调 REST 同构,答案/自检/核验报告按现有流程执行。")
195
-
196
-
197
- if __name__ == "__main__":
198
- main()