@lunagerm-studio/video-cut-skill 0.0.0-stage → 1.0.0

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 (146) hide show
  1. package/README.md +13 -2
  2. package/package.json +12 -4
  3. package/skills/ai-video-opening/SKILL.md +62 -0
  4. package/skills/ai-video-opening/references/export-and-validation.md +9 -0
  5. package/skills/ai-video-opening/references/motion-and-layout.md +7 -0
  6. package/skills/ai-video-opening/references/series-cases.md +7 -0
  7. package/skills/blue-white-ui-motion/SKILL.md +30 -0
  8. package/skills/blue-white-ui-motion/agents/openai.yaml +2 -0
  9. package/skills/blue-white-ui-motion/references/review.md +25 -0
  10. package/skills/chengfeng-videocut-skills/LICENSE +201 -0
  11. package/skills/chengfeng-videocut-skills/NOTICE.md +27 -0
  12. package/skills/chengfeng-videocut-skills/README.md +265 -0
  13. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/SKILL.md +37 -0
  14. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/agents/openai.yaml +2 -0
  15. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/cut_video.sh +182 -0
  16. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/detect_en_stutter.js +49 -0
  17. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/generate_review.js +1484 -0
  18. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/generate_srt_for_video.sh +75 -0
  19. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/generate_subtitles.js +141 -0
  20. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/review_server.js +381 -0
  21. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/volcengine_transcribe.sh +224 -0
  22. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/watch_cut_done.js +86 -0
  23. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/1-/346/240/270/345/277/203/345/216/237/345/210/231.md +56 -0
  24. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/10-/345/210/240/351/231/244/351/243/216/351/231/251/345/210/206/345/261/202.md +44 -0
  25. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/11-/345/217/243/346/222/255/347/250/277/345/257/271/351/275/220.md +40 -0
  26. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/2-/350/257/255/346/260/224/350/257/215/346/243/200/346/265/213.md +30 -0
  27. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/3-/351/235/231/351/237/263/346/256/265/345/244/204/347/220/206.md +56 -0
  28. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/4-/351/207/215/345/244/215/346/243/200/346/265/213.md +77 -0
  29. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/5-/345/215/241/351/241/277/350/257/215.md +48 -0
  30. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/7-/350/277/236/347/273/255/350/257/255/346/260/224/350/257/215.md +32 -0
  31. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/9-/346/256/213/345/217/245/346/243/200/346/265/213.md +79 -0
  32. package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/README.md +35 -0
  33. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/SKILL.md +32 -0
  34. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/agents/openai.yaml +2 -0
  35. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/references/artifact-contracts.md +168 -0
  36. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/animation_style.cjs +53 -0
  37. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/export_final_video.cjs +200 -0
  38. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/serve_range_preview.cjs +128 -0
  39. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/user_config.cjs +80 -0
  40. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/write_render_mode.cjs +149 -0
  41. package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207//347/224/250/346/210/267/351/205/215/347/275/256/default.json +4 -0
  42. package/skills/chengfeng-videocut-skills//350/207/252/350/277/233/345/214/226/README.md +23 -0
  43. package/skills/chengfeng-videocut-skills//350/207/252/350/277/233/345/214/226/SKILL.md +126 -0
  44. package/skills/continuous-collage-motion/SKILL.md +30 -0
  45. package/skills/continuous-collage-motion/agents/openai.yaml +4 -0
  46. package/skills/continuous-collage-motion/references/reference-motion.md +32 -0
  47. package/skills/continuous-collage-motion/references/shot-plan.md +31 -0
  48. package/skills/continuous-collage-motion/references/style-check.md +17 -0
  49. package/skills/table-video/LICENSES/ATTRIBUTION.md +31 -0
  50. package/skills/table-video/LICENSES/CC-BY-4.0.txt +396 -0
  51. package/skills/table-video/LICENSES/MIT.txt +21 -0
  52. package/skills/table-video/SKILL.md +32 -0
  53. package/skills/table-video/SOURCES.md +61 -0
  54. package/skills/table-video/agents/openai.yaml +2 -0
  55. package/skills/table-video/references/complete-motion.md +97 -0
  56. package/skills/table-video/references/examples/01_/344/270/244/346/256/265/346/274/224/347/244/272.md +73 -0
  57. package/skills/table-video/references/examples/02_/347/224/237/345/233/276/347/224/237/350/247/206/351/242/221/346/217/220/347/244/272/350/257/215/347/244/272/344/276/213.md +50 -0
  58. package/skills/table-video/references/examples/03_DESIGN/345/241/253/345/206/231/347/244/272/344/276/213.md +333 -0
  59. package/skills/table-video/references/examples/04_/350/277/236/347/273/255MG/346/255/243/345/217/215/350/277/207/347/250/213.md +101 -0
  60. package/skills/table-video/references/examples/05_/345/256/214/346/225/264/350/277/207/347/250/213/346/272/220/347/240/201.md +55 -0
  61. package/skills/table-video/references/examples/05_/346/205/242/351/225/234/345/244/264/344/270/216/345/220/214/346/236/204/345/233/276/345/233/236/345/275/222.md +35 -0
  62. package/skills/table-video/references/experience//345/255/227/345/271/225/344/270/216/345/260/201/351/235/242.md +30 -0
  63. package/skills/table-video/references/experience//345/275/225/345/261/217/345/211/252/350/276/221.md +31 -0
  64. package/skills/table-video/references/experience//346/211/213/345/212/250/347/224/237/345/233/276/347/224/237/350/247/206/351/242/221.md +53 -0
  65. package/skills/table-video/references/experience//350/247/206/350/247/211/345/217/231/344/272/213/344/270/216/350/277/236/347/273/255MG.md +102 -0
  66. package/skills/table-video/references/experience//351/225/234/345/244/264/346/216/250/350/277/233/344/270/216/350/275/254/345/234/272.md +178 -0
  67. package/skills/table-video/references/intake.md +84 -0
  68. package/skills/table-video/references/library.md +26 -0
  69. package/skills/table-video/references/motion-check-method.md +147 -0
  70. package/skills/table-video/references/planning.md +62 -0
  71. package/skills/table-video/references/production.md +70 -0
  72. package/skills/table-video/references/project-rules.md +26 -0
  73. package/skills/table-video/references/review-and-repair.md +64 -0
  74. package/skills/table-video/references/self-diagnosis.md +46 -0
  75. package/skills/table-video/references/sop/01_/345/277/253/351/200/237/345/274/200/345/247/213.md +55 -0
  76. package/skills/table-video/references/sop/02_/345/210/266/344/275/234SOP.md +77 -0
  77. package/skills/table-video/references/sop/03_/347/233/256/345/275/225/344/270/216/345/271/266/350/241/214/345/215/217/344/275/234.md +72 -0
  78. package/skills/table-video/references/sop/04_/351/252/214/346/224/266/344/270/216/350/277/224/344/277/256.md +146 -0
  79. package/skills/table-video/references/sop/05_/346/226/207/346/241/210/346/243/200/346/237/245_/345/217/257/351/200/211.md +55 -0
  80. package/skills/table-video/references/sop/06_/351/237/263/346/225/210/344/270/216/351/205/215/344/271/220_/345/217/257/351/200/211.md +138 -0
  81. package/skills/table-video/references/sop/07_/345/267/245/345/205/267/344/270/216/347/216/257/345/242/203.md +52 -0
  82. package/skills/table-video/references/sop/08_/346/235/245/346/272/220/344/270/216/350/256/270/345/217/257.md +36 -0
  83. package/skills/table-video/references/sop/09_DESIGN/345/273/272/347/253/213/344/270/216/346/240/241/351/252/214.md +52 -0
  84. package/skills/table-video/references/state-contract.md +267 -0
  85. package/skills/table-video/references/style-and-motion.md +163 -0
  86. package/skills/table-video/schemas/request.schema.json +44 -0
  87. package/skills/table-video/schemas/state.schema.json +140 -0
  88. package/skills/table-video/scripts/cli.mjs +35 -0
  89. package/skills/table-video/scripts/core.mjs +977 -0
  90. package/skills/table-video/scripts/gain-proof.mjs +48 -0
  91. package/skills/table-video/scripts/init-project.mjs +7 -0
  92. package/skills/table-video/scripts/motion-audit.mjs +589 -0
  93. package/skills/table-video/scripts/motion-check.mjs +345 -0
  94. package/skills/table-video/scripts/motion-gates.mjs +997 -0
  95. package/skills/table-video/scripts/motion-observation.cjs +204 -0
  96. package/skills/table-video/scripts/preflight.mjs +24 -0
  97. package/skills/table-video/scripts/process-locate.mjs +57 -0
  98. package/skills/table-video/scripts/render-motion-example.mjs +143 -0
  99. package/skills/table-video/scripts/save-reference-image.mjs +249 -0
  100. package/skills/table-video/scripts/schema.mjs +71 -0
  101. package/skills/table-video/scripts/stillness.mjs +386 -0
  102. package/skills/table-video/scripts/storage.mjs +328 -0
  103. package/skills/table-video/scripts/workflow.mjs +24 -0
  104. package/skills/talking-head-motion-workflow/SKILL.md +36 -0
  105. package/skills/talking-head-motion-workflow/agents/openai.yaml +4 -0
  106. package/skills/talking-head-motion-workflow/references/cinematic-motion-and-sync.md +72 -0
  107. package/skills/talking-head-motion-workflow/references/classic-ui.md +11 -0
  108. package/skills/talking-head-motion-workflow/references/history-coverage.md +50 -0
  109. package/skills/talking-head-motion-workflow/references/layered-assets-and-characters.md +39 -0
  110. package/skills/talking-head-motion-workflow/references/layout-references.md +41 -0
  111. package/skills/talking-head-motion-workflow/references/lens-shot-selection.md +138 -0
  112. package/skills/talking-head-motion-workflow/references/live-interface-motion.md +69 -0
  113. package/skills/talking-head-motion-workflow/references/motion-recipes.md +40 -0
  114. package/skills/talking-head-motion-workflow/references/mouse-meter2-case.md +113 -0
  115. package/skills/talking-head-motion-workflow/references/pop-collage.md +61 -0
  116. package/skills/talking-head-motion-workflow/references/portable-production.md +32 -0
  117. package/skills/talking-head-motion-workflow/references/production-requirements.md +85 -0
  118. package/skills/talking-head-motion-workflow/references/reference-library.md +41 -0
  119. package/skills/talking-head-motion-workflow/references/safe-areas-and-sound.md +47 -0
  120. package/skills/talking-head-motion-workflow/references/scene-illustrations.md +19 -0
  121. package/skills/talking-head-motion-workflow/references/sfx-presets.md +57 -0
  122. package/skills/talking-head-motion-workflow/references/style-13-github-production.md +33 -0
  123. package/skills/talking-head-motion-workflow/references/style-13-scene-performance.md +76 -0
  124. package/skills/talking-head-motion-workflow/references/style-presets.md +111 -0
  125. package/skills/talking-head-motion-workflow/references/table-video-spatial-mg.md +36 -0
  126. package/skills/talking-head-motion-workflow/scripts/extract_docx.py +19 -0
  127. package/skills/talking-head-motion-workflow/scripts/generate_foley.py +93 -0
  128. package/skills/talking-head-motion-workflow/scripts/render_sfx.py +135 -0
  129. package/skills/video-production-review/SKILL.md +30 -0
  130. package/skills/video-production-review/agents/openai.yaml +2 -0
  131. package/skills/video-production-review/references/episode-review-desk.md +30 -0
  132. package/skills/video-production-review/references/motion-adjustment-review.md +21 -0
  133. package/skills/video-production-workflow/SKILL.md +76 -0
  134. package/skills/video-production-workflow/agents/openai.yaml +2 -0
  135. package/skills/video-production-workflow/references/table-video-ep09.md +17 -0
  136. package/skills/video-production-workflow/scripts/check_motion_project.py +83 -0
  137. package/skills/video-reference-analysis/SKILL.md +32 -0
  138. package/skills/video-reference-analysis/agents/openai.yaml +2 -0
  139. package/skills/video-reference-analysis/references/case-format.md +95 -0
  140. package/skills/video-reference-analysis/references/production-method.md +21 -0
  141. package/skills/video-reference-analysis/scripts/library.py +371 -0
  142. package/skills/video-resource-access/SKILL.md +35 -0
  143. package/skills/video-resource-access/online.enabled +1 -0
  144. package/skills/video-resource-access/scripts/asset_client.py +159 -0
  145. package/skills/video-resource-access/scripts/remote_library.py +50 -0
  146. package//345/256/211/350/243/205/350/257/264/346/230/216.txt +5 -0
@@ -0,0 +1,371 @@
1
+ """Rebuild and search a local library of timecoded video analyses."""
2
+
3
+ import argparse
4
+ import os
5
+ from difflib import SequenceMatcher
6
+ import json
7
+ import re
8
+ import sys
9
+ import tempfile
10
+ import unicodedata
11
+ from pathlib import Path
12
+
13
+
14
+ INDEX_NAME = "index.json"
15
+
16
+
17
+ def read_json(path):
18
+ return json.loads(path.read_text(encoding="utf-8-sig"))
19
+
20
+
21
+ def read_case(path, library):
22
+ case = read_json(path)
23
+ if case.get("schema_version") != 1 or case.get("case_id") != path.parent.name:
24
+ raise ValueError("expected schema_version 1 and matching case_id")
25
+ source = case["source"]
26
+ if not re.fullmatch(r"[a-f0-9]{64}", source["sha256"], flags=re.IGNORECASE):
27
+ raise ValueError("expected a SHA-256 in source.sha256")
28
+ evidence = {
29
+ frame["id"]: {
30
+ **frame,
31
+ "path": (Path(case["case_id"]) / frame["path"]).as_posix(),
32
+ }
33
+ for frame in case["evidence"]
34
+ }
35
+ assets = []
36
+ extracted_assets = case.get("assets", [])
37
+ if not isinstance(extracted_assets, list):
38
+ raise ValueError("expected assets to be a list")
39
+ for asset in extracted_assets:
40
+ asset_path = Path(asset["path"])
41
+ if asset_path.anchor or ".." in asset_path.parts:
42
+ raise ValueError(f"expected case-relative asset path: {asset_path}")
43
+ if not (path.parent / asset_path).is_file():
44
+ raise ValueError(f"asset file does not exist: {asset_path}")
45
+ assets.append({**asset, "path": (Path(case["case_id"]) / asset_path).as_posix()})
46
+ return {
47
+ "case_id": case["case_id"],
48
+ "title": case["title"],
49
+ "summary": case["summary"],
50
+ "tags": case["tags"],
51
+ "analysis": path.relative_to(library).as_posix(),
52
+ "source": source,
53
+ "timeline": case["timeline"],
54
+ "patterns": case["patterns"],
55
+ "assets": assets,
56
+ "production_method_analysis": case.get("production_method_analysis", {}),
57
+ "evidence": evidence,
58
+ }
59
+
60
+
61
+ def refresh_index(library):
62
+ if not library.is_dir():
63
+ raise ValueError(f"Library directory does not exist: {library}")
64
+ cases = []
65
+ duplicates = []
66
+ case_by_hash = {}
67
+ for path in sorted(library.glob("*/analysis.json")):
68
+ try:
69
+ case = read_case(path, library)
70
+ except (ValueError, KeyError, TypeError, AttributeError) as exc:
71
+ raise ValueError(f"Cannot index {path}: {exc}") from exc
72
+ digest = case["source"]["sha256"].lower()
73
+ if digest in case_by_hash:
74
+ duplicates.append({
75
+ "case_id": case["case_id"],
76
+ "indexed_case_id": case_by_hash[digest],
77
+ })
78
+ continue
79
+ case_by_hash[digest] = case["case_id"]
80
+ cases.append(case)
81
+
82
+ index = {"schema_version": 1, "cases": cases, "duplicates": duplicates}
83
+ destination = library / INDEX_NAME
84
+ with tempfile.NamedTemporaryFile(dir=library, delete=False) as temp_file:
85
+ temp_path = Path(temp_file.name)
86
+ try:
87
+ temp_path.write_text(json.dumps(index, ensure_ascii=False, indent=2) + "\n",
88
+ encoding="utf-8")
89
+ temp_path.replace(destination)
90
+ finally:
91
+ temp_path.unlink(missing_ok=True)
92
+ return {
93
+ "index": str(destination),
94
+ "cases": len(cases),
95
+ "patterns": sum(len(case["patterns"]) for case in cases),
96
+ "assets": sum(len(case["assets"]) for case in cases),
97
+ "duplicates": duplicates,
98
+ }
99
+
100
+
101
+ def normalize(value):
102
+ return unicodedata.normalize("NFKC", value).casefold()
103
+
104
+
105
+ def relevance(terms, value):
106
+ value = normalize(value)
107
+ score = 0
108
+ for term in terms:
109
+ if term in value:
110
+ score += 3 + len(term)
111
+ elif re.fullmatch(r"[\u3400-\u9fff]{3,}", term):
112
+ fragments = {term[offset:offset + 2] for offset in range(len(term) - 1)}
113
+ score += sum(fragment in value for fragment in fragments)
114
+ return score
115
+
116
+
117
+ def search_hits(library, query, limit, kind_filter=None, case_filter=None):
118
+ index = read_json(library / INDEX_NAME)
119
+ terms = re.findall(r"\w+", normalize(query))
120
+ if not terms:
121
+ raise ValueError("Search query needs at least one word or character")
122
+ hits = []
123
+ for case in index["cases"]:
124
+ if case_filter is not None and case["case_id"] != case_filter:
125
+ continue
126
+ case_info = {
127
+ key: case[key] for key in ("case_id", "title", "analysis", "source")
128
+ }
129
+ methods = case.get("production_method_analysis", {})
130
+ entries_by_kind = (
131
+ ("pattern", case["patterns"]),
132
+ ("timeline", case["timeline"]),
133
+ ("asset", case.get("assets", [])),
134
+ ("method", methods.get("findings", [])),
135
+ )
136
+ for kind, entries in entries_by_kind:
137
+ if kind_filter is not None and kind_filter != kind:
138
+ continue
139
+ for entry in entries:
140
+ fields = {k: v for k, v in entry.items() if k not in {
141
+ "id", "start_s", "end_s", "status", "evidence_refs", "public_source_refs",
142
+ }}
143
+ score = relevance(terms, json.dumps(fields, ensure_ascii=False))
144
+ if kind == "asset":
145
+ asset_labels = [entry.get("title", ""), entry.get("tags", [])]
146
+ score += relevance(terms, json.dumps(asset_labels, ensure_ascii=False))
147
+ if not score:
148
+ continue
149
+ references = entry.get("evidence_refs")
150
+ if references is None and kind == "timeline":
151
+ references = [
152
+ frame["id"] for frame in case["evidence"].values()
153
+ if entry["start_s"] <= frame["time_s"] < entry["end_s"]
154
+ ]
155
+ evidence = [
156
+ case["evidence"][key]
157
+ for key in references or []
158
+ if key in case["evidence"]
159
+ ]
160
+ hit = {
161
+ **case_info, "kind": kind, "score": score,
162
+ "entry": entry, "evidence": evidence,
163
+ }
164
+ if kind == "asset":
165
+ hit["file"] = (library / entry["path"]).as_posix()
166
+ if kind == "method":
167
+ sources = methods.get("public_sources", {})
168
+ hit["public_sources"] = [
169
+ sources[key] for key in entry.get("public_source_refs", []) if key in sources
170
+ ]
171
+ hits.append(hit)
172
+ hits.sort(key=lambda hit: (
173
+ -hit["score"],
174
+ hit["entry"].get("status") != "adopted",
175
+ hit["kind"] != "pattern",
176
+ ))
177
+ return {"library": str(library), "query": query, "hits": hits[:limit]}
178
+
179
+
180
+ def indexed_file(library, relative_path):
181
+ """Return a usable file path inside the library, or None for missing files."""
182
+ path = (library / relative_path).resolve()
183
+ try:
184
+ path.relative_to(library)
185
+ except ValueError:
186
+ raise ValueError(f"Expected a path inside the library: {relative_path}") from None
187
+ return path.as_posix() if path.is_file() else None
188
+
189
+
190
+ def build_handoff(library, case_id, pattern_id, asset_ids):
191
+ if not pattern_id and not asset_ids:
192
+ raise ValueError("Select a pattern or one or more assets")
193
+ index = read_json(library / INDEX_NAME)
194
+ case = next((item for item in index["cases"] if item["case_id"] == case_id), None)
195
+ if case is None:
196
+ raise ValueError(f"Case not found: {case_id}")
197
+
198
+ patterns = {item["id"]: item for item in case["patterns"]}
199
+ if pattern_id and pattern_id not in patterns:
200
+ raise ValueError(f"Pattern not found in {case_id}: {pattern_id}")
201
+ pattern = patterns.get(pattern_id)
202
+ reuse = pattern.get("reuse", {}) if pattern else {}
203
+ roles = {binding["id"]: binding.get("role") for binding in reuse.get("asset_refs", [])}
204
+ by_asset_id = {item["id"]: item for item in case.get("assets", [])}
205
+ for asset_id in asset_ids:
206
+ if asset_id not in by_asset_id:
207
+ raise ValueError(f"Asset not found in {case_id}: {asset_id}")
208
+ roles.setdefault(asset_id, None)
209
+
210
+ assets = []
211
+ missing_asset_ids = []
212
+ for asset_id, role in roles.items():
213
+ asset = by_asset_id.get(asset_id)
214
+ if asset is None:
215
+ missing_asset_ids.append(asset_id)
216
+ continue
217
+ file = indexed_file(library, asset["path"])
218
+ if file is None:
219
+ missing_asset_ids.append(asset_id)
220
+ assets.append({**asset, "file": file, "role": role})
221
+
222
+ evidence_refs = list(pattern.get("evidence_refs", [])) if pattern else []
223
+ evidence_refs.extend(point["evidence_ref"] for point in reuse.get("match_points", []))
224
+ for asset in assets:
225
+ evidence_refs.extend(asset.get("evidence_refs", []))
226
+
227
+ methods = case.get("production_method_analysis", {})
228
+ sources = methods.get("public_sources", {})
229
+ related = []
230
+ selected_evidence = set(evidence_refs)
231
+ for finding in methods.get("findings", []):
232
+ finding_refs = finding.get("evidence_refs", [])
233
+ if selected_evidence.intersection(finding_refs):
234
+ related.append({
235
+ **finding,
236
+ "public_sources": [
237
+ sources[key] for key in finding.get("public_source_refs", []) if key in sources
238
+ ],
239
+ })
240
+ evidence_refs.extend(finding_refs)
241
+
242
+ evidence = [
243
+ {**frame, "file": indexed_file(library, frame["path"])}
244
+ for ref in dict.fromkeys(evidence_refs)
245
+ if (frame := case["evidence"].get(ref)) is not None
246
+ ]
247
+ source_path = case["source"].get("path")
248
+ source_file = Path(source_path) if source_path else None
249
+ if source_file is not None and not source_file.is_absolute():
250
+ source_file = library / Path(case["analysis"]).parent / source_file
251
+
252
+ return {
253
+ "library": str(library),
254
+ "case": {
255
+ "case_id": case_id,
256
+ "title": case["title"],
257
+ "analysis": indexed_file(library, case["analysis"]),
258
+ "report": indexed_file(library, Path(case["analysis"]).with_name("report.md")),
259
+ "source": case["source"],
260
+ },
261
+ "source_file": source_file.as_posix() if source_file is not None and source_file.is_file() else None,
262
+ "pattern": pattern,
263
+ "assets": assets,
264
+ "missing_asset_ids": missing_asset_ids,
265
+ "evidence": evidence,
266
+ "methods": related,
267
+ }
268
+
269
+
270
+ def match_motion(library, query, limit, case_filter):
271
+ """Rank reusable motion templates by the action the narration describes."""
272
+ question = normalize(query).strip()
273
+ hits = []
274
+ for case in read_json(library / INDEX_NAME)["cases"]:
275
+ if case_filter and case["case_id"] != case_filter:
276
+ continue
277
+ assets = {asset["id"]: asset for asset in case["assets"]}
278
+ for pattern in case["patterns"]:
279
+ reuse = pattern.get("reuse", {})
280
+ match = reuse.get("retrieval", {})
281
+ if not match:
282
+ continue
283
+ labels = [pattern["title"], match["intent"], *match["keywords"], *match["phrases"]]
284
+ scores = []
285
+ for label in dict.fromkeys(labels):
286
+ key = normalize(label).strip()
287
+ if not key:
288
+ continue
289
+ if key in question:
290
+ scores.append((12 + min(len(key), 16), label))
291
+ elif len(question) >= 2 and question in key:
292
+ scores.append((6 + min(len(question), 12), label))
293
+ else:
294
+ run = SequenceMatcher(None, key, question, autojunk=False).find_longest_match().size
295
+ if run >= 4 and run >= len(key) * 0.6:
296
+ scores.append((run, label))
297
+ exact = question == normalize(pattern["id"]) or question == normalize(pattern["title"])
298
+ if not scores and not exact:
299
+ continue
300
+ scores.sort(reverse=True)
301
+ score = (100 if exact else 0) + sum(value / (i + 1) for i, (value, _) in enumerate(scores[:3]))
302
+ files = {}
303
+ for role, asset_id in match["assets"].items():
304
+ asset = assets.get(asset_id)
305
+ files[role] = indexed_file(library, asset["path"]) if asset else None
306
+ hits.append(dict(case_id=case["case_id"], pattern_id=pattern["id"], title=pattern["title"],
307
+ intent=match["intent"], matched=[label for _, label in scores[:3]],
308
+ score=round(score, 2), files=files, source_spans=reuse.get("source_spans", [])))
309
+ hits.sort(key=lambda hit: -hit["score"])
310
+ return {"query": query, "hits": hits[:limit]}
311
+
312
+
313
+ def main():
314
+ # server-assets adapter: source users can keep the original local workflow.
315
+ local = '--local' in sys.argv
316
+ if local:
317
+ sys.argv.remove('--local')
318
+ shared = Path(__file__).resolve().parents[2] / 'video-resource-access'
319
+ remote = '--remote' in sys.argv or os.getenv('LUNAGREM_SKILL_TOKEN') or (shared / 'online.enabled').is_file()
320
+ if not local and remote:
321
+ sys.path.insert(0, str(shared / 'scripts'))
322
+ from remote_library import main as remote_main
323
+ return remote_main(sys.argv[1:])
324
+ parser = argparse.ArgumentParser(description=__doc__)
325
+ commands = parser.add_subparsers(dest="command", required=True)
326
+ refresh = commands.add_parser("refresh", help="Save a fresh index.json")
327
+ search = commands.add_parser("search", help="Find patterns, timecoded segments, assets and production methods")
328
+ handoff = commands.add_parser("handoff", help="Resolve a case pattern and its source assets for production")
329
+ for command in (refresh, search, handoff):
330
+ command.add_argument("--library", required=True, type=Path)
331
+ match = commands.add_parser("match", help="Match narration or keywords to editable motion assets")
332
+ match.add_argument("--query", required=True)
333
+ match.add_argument("--case")
334
+ match.add_argument("--limit", type=int, default=3)
335
+ match.add_argument("--library", type=Path)
336
+ search.add_argument("--query", required=True)
337
+ search.add_argument("--limit", type=int, default=8)
338
+ search.add_argument("--kind", choices=("asset", "pattern", "timeline", "method"))
339
+ search.add_argument("--case", help="Limit results to an exact case ID")
340
+ handoff.add_argument("--case", required=True)
341
+ handoff.add_argument("--pattern")
342
+ handoff.add_argument("--asset", action="append", default=[], help="Include a specific asset ID")
343
+ args = parser.parse_args()
344
+ if args.library is None:
345
+ locations = [p / "reference-analysis" for p in (Path.cwd(), *Path.cwd().parents)]
346
+ locations.append(Path.home() / ".cache/lunagrem/reference-analysis")
347
+ args.library = next((p for p in locations if (p / INDEX_NAME).is_file()), locations[-1])
348
+ library = args.library.resolve()
349
+ try:
350
+ if args.command == "refresh":
351
+ result = refresh_index(library)
352
+ else:
353
+ if not (library / INDEX_NAME).is_file():
354
+ raise ValueError(f"No index in {library}. Run refresh first.")
355
+ if args.command == "handoff":
356
+ result = build_handoff(library, args.case, args.pattern, args.asset)
357
+ else:
358
+ if args.limit < 1:
359
+ raise ValueError("Search limit must be positive")
360
+ if args.command == "match":
361
+ result = match_motion(library, args.query, args.limit, args.case)
362
+ else:
363
+ result = search_hits(library, args.query, args.limit, args.kind, args.case)
364
+ except (OSError, ValueError, KeyError, TypeError) as exc:
365
+ parser.exit(1, f"{exc}\n")
366
+ sys.stdout.reconfigure(encoding="utf-8")
367
+ print(json.dumps(result, ensure_ascii=False, indent=2))
368
+
369
+
370
+ if __name__ == "__main__":
371
+ main()
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: video-resource-access
3
+ description: 为剪辑和动效制作按台词、用途或组件编号检索工具站素材,并按需取回一个组件及依赖。用于线上剪辑 Skill 的素材交接。
4
+ ---
5
+
6
+ # 在线素材交接
7
+
8
+ 素材库保存在工具站服务器,本地只提供剪辑方法与客户端。不要枚举、镜像或打包素材库;不要打开素材库首页、内部案例预览、封面或参考原片。检索结果是供制作选择的文字元数据。用户明确要求看本次制作结果时,可以预览本次输出的成片。
9
+
10
+ ## 连接
11
+
12
+ 用户登录工具站的 Skill 详情页,使用收到的 SC 激活码绑定当前账号,激活成功后再生成自己的素材凭证,并在启动 AI 工具前设置环境变量 `LUNAGREM_SKILL_TOKEN`。缺少凭证时提示用户在自己的终端填写,重启或重新加载 AI 工具后再用;不要让用户把凭证发进对话,不要把它写入 Skill 或成片工程。默认站点为 `https://lunagerm.com`,测试时可设置 `LUNAGREM_API_ORIGIN`。
13
+
14
+ ## 按需使用
15
+
16
+ 下面的命令均以本 Skill 所在目录为工作目录。先用短用途词、原台词的关键动作或已知组件编号检索:
17
+
18
+ ```text
19
+ python scripts/asset_client.py search "分流"
20
+ python scripts/asset_client.py search "motion-13"
21
+ ```
22
+
23
+ 从结果中选中需要的 `id`,只取本镜所需组件:
24
+
25
+ ```text
26
+ python scripts/asset_client.py fetch vc_检索返回的实际ID
27
+ ```
28
+
29
+ 返回值中的 `entry` 是已校验的本地模板路径,`files` 是该组件的本地依赖。将这些路径交给实际剪辑或渲染模块;模板与依赖的相对目录已经保留。不要猜测原作者的磁盘路径,不要尝试打开本地不存在的整库目录。取回文件不会自动执行代码或打开浏览器;先把组件复制到当前项目,保留相对目录并保持缓存原样,读取实现后再按当前任务修改、运行。
30
+
31
+ 客户端默认缓存在用户目录 `.cache/lunagrem-video-assets`;可用 `LUNAGREM_ASSET_CACHE` 修改。素材更新后校验值变化会自动生成新缓存。搜索无结果就更换具体关键词;仍没有时,用用户的素材自行制作,并说明没有找到现成组件,不编造素材路径。
32
+
33
+ 原有 `video-reference-analysis/scripts/library.py` 也支持 `--remote` 的 search/match/handoff。线上发布包默认远程模式;源码工作区无凭证时保留原本地模式。不要用线上接口代替本地参考视频分析、反向工程或整库 refresh。
34
+
35
+ 401 时重新获取凭证;403 时检查账号和素材授权是否已激活、到期或停用;429 时停止重复下载、稍后再试;503 时提示联系管理员核对素材发布。只返回需要用户处理的问题,不打印请求头或凭证。剪辑、FFmpeg、Remotion 等依旧在本机运行,按所选制作模块准备对应环境。
@@ -0,0 +1,159 @@
1
+ """Small authenticated adapter for an existing local video-editing Skill."""
2
+ import argparse
3
+ import hashlib
4
+ import json
5
+ import os
6
+ from pathlib import Path
7
+ import re
8
+ import tempfile
9
+ import shutil
10
+ from pathlib import PurePosixPath
11
+ from zipfile import ZipFile
12
+ from urllib.error import HTTPError, URLError
13
+ from urllib.parse import urlsplit
14
+ from urllib.request import Request, build_opener, HTTPRedirectHandler
15
+
16
+ class NoRedirect(HTTPRedirectHandler):
17
+ def redirect_request(self, *args, **kwargs):
18
+ return None
19
+
20
+ def config():
21
+ base = os.getenv('LUNAGREM_API_ORIGIN', 'https://lunagerm.com').rstrip('/')
22
+ url = urlsplit(base)
23
+ if url.username or url.password or url.query or url.fragment or url.path or not url.hostname or (
24
+ url.scheme != 'https' and not (url.scheme == 'http' and url.hostname in ('127.0.0.1', 'localhost'))):
25
+ raise ValueError('API origin must be HTTPS, without a path or credentials')
26
+ token = os.environ.get('LUNAGREM_SKILL_TOKEN', '')
27
+ if not re.fullmatch(r'sr_[A-Za-z0-9_-]{43}', token):
28
+ raise ValueError('请先登录 Skill 页面、激活授权码并生成个人素材凭证,再设置 LUNAGREM_SKILL_TOKEN')
29
+ return base + '/api/public/skill-resources/video-cut/v1', token
30
+
31
+ def call(path, body=None):
32
+ base, token = config()
33
+ data = json.dumps(body).encode() if body is not None else None
34
+ return build_opener(NoRedirect()).open(Request(base + path, data=data,
35
+ headers={'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}), timeout=30)
36
+
37
+ def search(query, kind=None, mode='search', limit=10):
38
+ with call('/search', {'query': query, 'kind': kind, 'mode':mode, 'limit':limit}) as response:
39
+ return json.load(response)
40
+
41
+ def metadata(asset_id):
42
+ if not re.fullmatch(r'[A-Za-z0-9_-]{1,80}', asset_id):
43
+ raise ValueError('Invalid resource id')
44
+ with call('/assets/' + asset_id + '/metadata') as response:
45
+ return json.load(response)
46
+
47
+ def checksum(path):
48
+ digest = hashlib.sha256()
49
+ with path.open('rb') as source:
50
+ while chunk := source.read(1024 * 1024):
51
+ digest.update(chunk)
52
+ return digest.hexdigest()
53
+
54
+ def download(asset_id, sha256, directory):
55
+ if not re.fullmatch(r'[A-Za-z0-9_-]{1,80}', asset_id) or not re.fullmatch(r'[a-f0-9]{64}', sha256):
56
+ raise ValueError('Use an asset id and SHA256 returned by search')
57
+ directory = Path(directory).expanduser().resolve()
58
+ directory.mkdir(parents=True, exist_ok=True)
59
+ target = directory / (asset_id + '-' + sha256[:16])
60
+ if target.is_file() and checksum(target) == sha256:
61
+ return target
62
+ temporary = None
63
+ try:
64
+ with call('/assets/' + asset_id) as response, tempfile.NamedTemporaryFile(dir=directory, delete=False) as out:
65
+ temporary = Path(out.name)
66
+ digest = hashlib.sha256()
67
+ size = 0
68
+ while chunk := response.read(1024 * 1024):
69
+ size += len(chunk)
70
+ if size > 1024 * 1024 * 1024:
71
+ raise ValueError('Asset exceeds 1 GB client limit')
72
+ digest.update(chunk)
73
+ out.write(chunk)
74
+ if digest.hexdigest() != sha256:
75
+ raise ValueError('Asset checksum mismatch; incomplete file discarded')
76
+ temporary.replace(target)
77
+ return target
78
+ finally:
79
+ if temporary and temporary.exists():
80
+ temporary.unlink()
81
+
82
+ def fetch(asset_id, directory=None):
83
+ """Fetch exactly one component and its dependencies; never open a preview."""
84
+ item = metadata(asset_id)
85
+ if item.get('format') != 'component-zip':
86
+ raise ValueError('This resource is not a component package')
87
+ directory = Path(directory or os.getenv('LUNAGREM_ASSET_CACHE') or
88
+ Path.home() / '.cache/lunagrem-video-assets').expanduser().resolve()
89
+ archive_path = download(asset_id, item['sha256'], directory)
90
+ target = directory / (archive_path.name + '-files')
91
+ if not target.exists():
92
+ staging = Path(tempfile.mkdtemp(prefix='.component-', dir=directory))
93
+ try:
94
+ with ZipFile(archive_path) as archive:
95
+ if len(archive.infolist()) > 801 or sum(e.file_size for e in archive.infolist()) > 512 * 1024 * 1024:
96
+ raise ValueError('Component package exceeds extraction limits')
97
+ seen = set()
98
+ for entry in archive.infolist():
99
+ relative = PurePosixPath(entry.filename)
100
+ if (entry.is_dir() or relative.is_absolute() or '..' in relative.parts or
101
+ '\\' in entry.filename or ':' in entry.filename or entry.filename in seen or
102
+ (entry.external_attr >> 16) & 0o170000 == 0o120000):
103
+ raise ValueError('Invalid component package path')
104
+ seen.add(entry.filename)
105
+ destination = staging.joinpath(*relative.parts)
106
+ destination.parent.mkdir(parents=True, exist_ok=True)
107
+ with archive.open(entry) as source, destination.open('xb') as output:
108
+ shutil.copyfileobj(source, output)
109
+ # Validate before making the cache visible to concurrent callers.
110
+ component_paths(staging)
111
+ try:
112
+ staging.rename(target)
113
+ except OSError:
114
+ if not target.is_dir():
115
+ raise
116
+ finally:
117
+ shutil.rmtree(staging, ignore_errors=True)
118
+ entry, files = component_paths(target)
119
+ return {'resource_id':asset_id, 'name':item['name'], 'entry':str(entry),
120
+ 'files':[str(p) for p in files], 'sha256':item['sha256']}
121
+
122
+ def component_paths(root):
123
+ root = root.resolve()
124
+ document = json.loads((root / 'resource.json').read_text('utf-8'))
125
+ def within(value):
126
+ relative = PurePosixPath(value)
127
+ if relative.is_absolute() or '..' in relative.parts or '\\' in value or ':' in value:
128
+ raise ValueError('Invalid component entry')
129
+ path = root.joinpath(*relative.parts).resolve()
130
+ if not path.is_relative_to(root) or not path.is_file():
131
+ raise ValueError('Incomplete component cache; remove this cached component and fetch again')
132
+ return path
133
+ return within(document['entry']), [within(value) for value in document['files']]
134
+
135
+ if __name__ == '__main__':
136
+ parser = argparse.ArgumentParser(description='LunaGrem private video-cut materials')
137
+ sub = parser.add_subparsers(dest='action', required=True)
138
+ find = sub.add_parser('search');find.add_argument('query');find.add_argument('--kind', choices=['video','image','audio','template'])
139
+ get = sub.add_parser('download');get.add_argument('id');get.add_argument('--sha256', required=True);get.add_argument('--cache', default='./.skill-assets')
140
+ use = sub.add_parser('fetch');use.add_argument('id');use.add_argument('--cache')
141
+ args = parser.parse_args()
142
+ try:
143
+ if args.action == 'search':
144
+ print(json.dumps(search(args.query, args.kind), ensure_ascii=False, indent=2))
145
+ elif args.action == 'download':
146
+ print(download(args.id, args.sha256, args.cache))
147
+ else:
148
+ print(json.dumps(fetch(args.id, args.cache), ensure_ascii=False, indent=2))
149
+ except HTTPError as error:
150
+ try:
151
+ message = json.loads(error.read(8192)).get('detail')
152
+ except (ValueError, OSError):
153
+ message = None
154
+ parser.exit(1, f'素材服务返回 {error.code}:{message or "请检查凭证、服务配置和额度"}\n')
155
+ except URLError:
156
+ parser.exit(1, '素材服务连接失败,请检查网络和网站是否可用。\n')
157
+ except Exception as error:
158
+ # Never print request headers or the personal credential.
159
+ parser.exit(1, f'Material request failed: {error}\n')
@@ -0,0 +1,50 @@
1
+ """Compatibility entry for the existing library.py search/match/handoff commands."""
2
+ import argparse
3
+ import json
4
+ import sys
5
+ from asset_client import search, fetch
6
+
7
+
8
+ def main(arguments):
9
+ parser = argparse.ArgumentParser(description='工具站按需取材,不浏览整库')
10
+ parser.add_argument('command', choices=('search','match','handoff','refresh'))
11
+ parser.add_argument('--remote', action='store_true')
12
+ parser.add_argument('--library')
13
+ parser.add_argument('--query')
14
+ parser.add_argument('--case')
15
+ parser.add_argument('--pattern')
16
+ parser.add_argument('--asset', action='append', default=[])
17
+ parser.add_argument('--kind', choices=('asset','pattern','timeline','method'))
18
+ parser.add_argument('--limit', type=int, default=8)
19
+ args = parser.parse_args(arguments)
20
+ try:
21
+ if args.command == 'refresh':
22
+ raise ValueError('线上素材索引由管理员更新;用户端不能导出或重建整库')
23
+ if not 1 <= args.limit <= 20:
24
+ raise ValueError('limit 范围是 1–20')
25
+ if args.command == 'handoff':
26
+ ids = args.asset or ([args.pattern] if (args.pattern or '').startswith('vc_') else [])
27
+ if not ids and args.pattern:
28
+ matches = search(' '.join(filter(None, (args.case, args.pattern))))['items']
29
+ matches = [item for item in matches if item.get('component_id') == args.pattern and
30
+ (not args.case or args.case in (item.get('case_id'), item.get('project')))]
31
+ if len(matches) == 1:
32
+ ids = [matches[0]['id']]
33
+ if not ids:
34
+ raise ValueError('先 search/match,再用返回的 resource_id:handoff --asset vc_...')
35
+ result = {'assets':[fetch(resource_id) for resource_id in ids]}
36
+ else:
37
+ if not args.query:
38
+ raise ValueError('请给出 --query 台词、用途或组件编号')
39
+ if args.kind in ('timeline','method'):
40
+ raise ValueError('线上接口仅检索已发布的制作组件,不提供参考原片、时码证据或内部方法库')
41
+ data = search(args.query, kind='template' if args.kind == 'pattern' else None,
42
+ mode='match' if args.command == 'match' else 'search', limit=args.limit)
43
+ rows = [item for item in data['items'] if not args.case or args.case in (item.get('case_id'), item.get('project'))]
44
+ result = {'version':data['version'], 'hits':[
45
+ {'resource_id':item['id'], 'case_id':item.get('case_id', item.get('project')), 'pattern_id':item.get('component_id'),
46
+ 'title':item['name'], 'kind':item['kind'], 'tags':item.get('tags',[])} for item in rows]}
47
+ sys.stdout.reconfigure(encoding='utf-8')
48
+ print(json.dumps(result, ensure_ascii=False, indent=2))
49
+ except Exception as error:
50
+ parser.exit(1, f'取材失败:{error}\n')
@@ -0,0 +1,5 @@
1
+ 这是线上素材版 Skill,不含素材库。
2
+ 将 skills 下各文件夹安装到 AI 工具的技能目录。
3
+ 先阅读 video-resource-access/SKILL.md。登录工具站的 Skill 详情页,输入收到的 SC 激活码绑定账号,再生成个人凭证,在启动 AI 工具前设置 LUNAGREM_SKILL_TOKEN。
4
+ 使用剪辑流程统筹入口:video-production-workflow/SKILL.md。
5
+ 素材按需传输到本地缓存;不会自动打开库内预览。剪辑渲染仍在本机运行。