@gavinmo1/skills 0.1.0 → 0.2.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.
- package/README.md +35 -15
- package/bin/cli.mjs +15 -2
- package/package.json +1 -2
- package/skills/ai-explore-inline/SKILL.md +227 -0
- package/skills/ai-explore-inline/references/output-template.md +94 -0
- package/skills/ai-explore-inline/references/questioner-guide.md +156 -0
- package/skills/deep-generate/SKILL.md +124 -0
- package/skills/deep-generate/references/delivery-checklist.md +20 -0
- package/skills/deep-generate/references/error-handling.md +21 -0
- package/skills/deep-generate/references/output-templates.md +68 -0
- package/skills/deep-generate/references/research-protocol.md +34 -0
- package/skills/deep-generate/references/scoring-rubric.md +41 -0
- package/skills/deep-generate/references/self-check-list.md +37 -0
- package/skills/deep-generate/references/state-protocol.md +78 -0
- package/skills/deep-generate/scripts/check-state.py +253 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Read-only state-v2 checks. Requires Python 3.9+. See state-protocol.md."""
|
|
3
|
+
import argparse
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Check:
|
|
11
|
+
def __init__(self, root, final=False):
|
|
12
|
+
self.root = root.resolve()
|
|
13
|
+
self.final = final
|
|
14
|
+
self.result = {"passed": [], "failed": [], "unchecked": []}
|
|
15
|
+
|
|
16
|
+
def add(self, level, at, message):
|
|
17
|
+
self.result[level].append({"at": at, "message": message})
|
|
18
|
+
|
|
19
|
+
def require(self, condition, at, message):
|
|
20
|
+
if not condition:
|
|
21
|
+
self.add("failed", at, message)
|
|
22
|
+
return condition
|
|
23
|
+
|
|
24
|
+
def obj(self, value, at):
|
|
25
|
+
return value if self.require(isinstance(value, dict), at, "必须为对象") else {}
|
|
26
|
+
|
|
27
|
+
def seq(self, value, at):
|
|
28
|
+
return value if self.require(isinstance(value, list), at, "必须为数组") else []
|
|
29
|
+
|
|
30
|
+
def text(self, value, at):
|
|
31
|
+
return self.require(isinstance(value, str) and bool(value.strip()), at, "必须为非空字符串")
|
|
32
|
+
|
|
33
|
+
def sha(self, value, at):
|
|
34
|
+
return self.require(isinstance(value, str) and bool(re.fullmatch(r"[0-9a-f]{64}", value)), at, "必须为64位小写SHA256")
|
|
35
|
+
|
|
36
|
+
def path(self, value, at):
|
|
37
|
+
if not self.text(value, at):
|
|
38
|
+
return None
|
|
39
|
+
if not self.require("\\" not in value and not re.match(r"^[A-Za-z]:", value) and not Path(value).is_absolute(), at, "必须使用主题根目录下的相对/路径"):
|
|
40
|
+
return None
|
|
41
|
+
path = (self.root / value).resolve()
|
|
42
|
+
return path if self.require(path.is_relative_to(self.root), at, "路径越出主题目录") else None
|
|
43
|
+
|
|
44
|
+
def blob(self, data, at):
|
|
45
|
+
data = self.obj(data, at)
|
|
46
|
+
path = self.path(data.get("path"), at + ".path")
|
|
47
|
+
valid = self.sha(data.get("sha256"), at + ".sha256")
|
|
48
|
+
if path is None or not self.require(path.is_file(), at, "文件不存在"):
|
|
49
|
+
return
|
|
50
|
+
raw = path.read_bytes()
|
|
51
|
+
self.require(bool(raw.strip()), at, "文件为空")
|
|
52
|
+
if valid:
|
|
53
|
+
self.require(hashlib.sha256(raw).hexdigest() == data["sha256"], at, "实际文件哈希与登记不符")
|
|
54
|
+
|
|
55
|
+
def actor(self, actor, at):
|
|
56
|
+
if not self.require(isinstance(actor, str) and actor in self.actors, at, "执行实体未登记"):
|
|
57
|
+
return None
|
|
58
|
+
self.require("identity" in self.actors[actor], at, "缺少identity字段")
|
|
59
|
+
identity = self.actors[actor].get("identity")
|
|
60
|
+
if identity is None:
|
|
61
|
+
self.add("unchecked", at, "实体身份未知")
|
|
62
|
+
return None
|
|
63
|
+
return identity if self.text(identity, at + ".identity") else None
|
|
64
|
+
|
|
65
|
+
def run(self, state):
|
|
66
|
+
state = self.obj(state, "state")
|
|
67
|
+
self.require(type(state.get("schema_version")) is int and state["schema_version"] == 2, "schema_version", "需要版本2;旧版须依据历史迁移")
|
|
68
|
+
for key in ("run_id", "next_action"):
|
|
69
|
+
self.text(state.get(key), key)
|
|
70
|
+
limit = state.get("revision_limit")
|
|
71
|
+
valid_limit = self.require(type(limit) is int and limit >= 0, "revision_limit", "必须为非负整数")
|
|
72
|
+
self.actors = self.obj(state.get("actors"), "actors")
|
|
73
|
+
self.actors = {k: self.obj(v, "actors." + k) for k, v in self.actors.items()}
|
|
74
|
+
files = self.obj(state.get("files"), "files")
|
|
75
|
+
files = {k: self.obj(v, "files." + k) for k, v in files.items()}
|
|
76
|
+
self.require(bool(files), "files", "没有登记文件")
|
|
77
|
+
people, paths = {}, set()
|
|
78
|
+
for fid, item in files.items():
|
|
79
|
+
at = "files." + fid
|
|
80
|
+
self.require(item.get("kind") in ("chapter", "guide", "source", "shared"), at, "无效文件类型")
|
|
81
|
+
path = self.path(item.get("path"), at + ".path")
|
|
82
|
+
if path is not None:
|
|
83
|
+
self.require(path not in paths, at, "不同ID指向同一文件")
|
|
84
|
+
paths.add(path)
|
|
85
|
+
self.require("sha256" in item, at, "缺少sha256字段")
|
|
86
|
+
current = item.get("sha256")
|
|
87
|
+
if current is None:
|
|
88
|
+
self.add("unchecked", at, "尚未产出或登记版本")
|
|
89
|
+
else:
|
|
90
|
+
self.blob(item, at)
|
|
91
|
+
self.require("owner" in item, at, "缺少owner字段")
|
|
92
|
+
if item.get("owner") is not None:
|
|
93
|
+
self.actor(item["owner"], at + ".owner")
|
|
94
|
+
elif self.final:
|
|
95
|
+
self.add("unchecked", at, "未分配负责人")
|
|
96
|
+
identities, outputs = set(), set()
|
|
97
|
+
for n, entry in enumerate(self.seq(item.get("contributors"), at + ".contributors")):
|
|
98
|
+
loc = f"{at}.contributors[{n}]"
|
|
99
|
+
entry = self.obj(entry, loc)
|
|
100
|
+
identity = self.actor(entry.get("actor"), loc)
|
|
101
|
+
identities.add(identity)
|
|
102
|
+
if self.sha(entry.get("sha256"), loc):
|
|
103
|
+
outputs.add(entry["sha256"])
|
|
104
|
+
if current is not None:
|
|
105
|
+
self.require(current in outputs, at, "当前版本缺少作者或修改者登记")
|
|
106
|
+
people[fid] = identities
|
|
107
|
+
if item.get("kind") != "chapter":
|
|
108
|
+
continue
|
|
109
|
+
if item.get("revisions") is None:
|
|
110
|
+
self.add("unchecked", at, "修订历史缺失或未知")
|
|
111
|
+
continue
|
|
112
|
+
revisions = self.seq(item["revisions"], at + ".revisions")
|
|
113
|
+
seen = set()
|
|
114
|
+
for n, revision in enumerate(revisions):
|
|
115
|
+
loc = f"{at}.revisions[{n}]"
|
|
116
|
+
revision = self.obj(revision, loc)
|
|
117
|
+
rid = revision.get("id")
|
|
118
|
+
if self.text(rid, loc):
|
|
119
|
+
self.require(rid not in seen, loc, "同一提交重复计数")
|
|
120
|
+
seen.add(rid)
|
|
121
|
+
output = revision.get("output_sha256")
|
|
122
|
+
if self.sha(output, loc):
|
|
123
|
+
self.require(output in outputs, loc, "修订输出未登记贡献版本")
|
|
124
|
+
record = self.path(revision.get("record"), loc + ".record")
|
|
125
|
+
if record is not None:
|
|
126
|
+
self.require(record.is_file() and bool(record.read_bytes().strip()), loc, "处理记录缺失或为空")
|
|
127
|
+
if valid_limit:
|
|
128
|
+
self.require(len(revisions) <= limit, at, "实际修订超过当前预算,需核对授权与登记")
|
|
129
|
+
|
|
130
|
+
review_ids, readers, passes = set(), {}, set()
|
|
131
|
+
for n, review in enumerate(self.seq(state.get("reviews"), "reviews")):
|
|
132
|
+
at = f"reviews[{n}]"
|
|
133
|
+
review = self.obj(review, at)
|
|
134
|
+
rid = review.get("id")
|
|
135
|
+
valid_id = self.text(rid, at + ".id")
|
|
136
|
+
if valid_id:
|
|
137
|
+
self.require(rid not in review_ids, at, "重复评审ID")
|
|
138
|
+
review_ids.add(rid)
|
|
139
|
+
kind = review.get("kind")
|
|
140
|
+
self.require(kind in ("content", "reader"), at, "无效评审类型")
|
|
141
|
+
identity = self.actor(review.get("actor"), at)
|
|
142
|
+
self.blob(review.get("report"), at + ".report")
|
|
143
|
+
coverage = self.seq(review.get("coverage"), at + ".coverage")
|
|
144
|
+
self.require(bool(coverage), at, "评审无覆盖目标")
|
|
145
|
+
targets, reader_entries = set(), []
|
|
146
|
+
for j, entry in enumerate(coverage):
|
|
147
|
+
loc = f"{at}.coverage[{j}]"
|
|
148
|
+
entry = self.obj(entry, loc)
|
|
149
|
+
target = entry.get("target")
|
|
150
|
+
if not self.require(isinstance(target, str) and target in files, loc, "目标未登记"):
|
|
151
|
+
continue
|
|
152
|
+
self.require(target not in targets, loc, "重复覆盖目标")
|
|
153
|
+
targets.add(target)
|
|
154
|
+
self.text(entry.get("scope"), loc + ".scope")
|
|
155
|
+
app, status = entry.get("applicability"), entry.get("status")
|
|
156
|
+
self.require(app in ("current", "pending", "historical"), loc, "无效适用状态")
|
|
157
|
+
allowed = ("通过", "待修订", "待核实", "未评审") if kind == "content" else ("已完成", "部分覆盖", "未完成")
|
|
158
|
+
self.require(status in allowed, loc, "无效结论状态")
|
|
159
|
+
issues = self.seq(entry.get("issues"), loc + ".issues")
|
|
160
|
+
for issue in issues:
|
|
161
|
+
self.text(issue, loc + ".issues")
|
|
162
|
+
if status == "通过":
|
|
163
|
+
self.require(not issues, loc, "通过与未决必要问题冲突")
|
|
164
|
+
inputs, matches = set(), True
|
|
165
|
+
for k, value in enumerate(self.seq(entry.get("inputs"), loc + ".inputs")):
|
|
166
|
+
point = f"{loc}.inputs[{k}]"
|
|
167
|
+
value = self.obj(value, point)
|
|
168
|
+
fid = value.get("file_id")
|
|
169
|
+
if not self.require(isinstance(fid, str) and fid in files, point, "输入未登记"):
|
|
170
|
+
matches = False
|
|
171
|
+
continue
|
|
172
|
+
self.require(fid not in inputs, point, "重复输入")
|
|
173
|
+
inputs.add(fid)
|
|
174
|
+
self.sha(value.get("sha256"), point)
|
|
175
|
+
matches = matches and value.get("sha256") == files[fid].get("sha256")
|
|
176
|
+
if "snapshot" in value:
|
|
177
|
+
self.blob({"path": value["snapshot"], "sha256": value.get("sha256")}, point + ".snapshot")
|
|
178
|
+
snapshot_path = self.path(value["snapshot"], point + ".snapshot.path")
|
|
179
|
+
current_path = self.path(files[fid].get("path"), point + ".current.path")
|
|
180
|
+
self.require(snapshot_path is None or snapshot_path != current_path, point, "快照不能是当前正文")
|
|
181
|
+
self.require(target in inputs, loc, "输入未包含目标")
|
|
182
|
+
matches = matches and target in inputs
|
|
183
|
+
if app == "current":
|
|
184
|
+
self.require(matches, loc, "评审输入已变化,需确认适用性")
|
|
185
|
+
if identity is None or not people[target] or None in people[target]:
|
|
186
|
+
self.add("unchecked", loc, "无法核实实体是否重合")
|
|
187
|
+
else:
|
|
188
|
+
self.require(identity not in people[target], loc, "评审者也是目标作者或修改者")
|
|
189
|
+
if kind == "content":
|
|
190
|
+
if status == "通过" and not issues and matches:
|
|
191
|
+
passes.add(target)
|
|
192
|
+
else:
|
|
193
|
+
self.add("unchecked", loc, "当前内容尚无通过结论")
|
|
194
|
+
elif app == "pending":
|
|
195
|
+
self.add("unchecked", loc, "评审适用性待确认")
|
|
196
|
+
reader_entries.append((app, status, matches))
|
|
197
|
+
if kind == "reader" and valid_id:
|
|
198
|
+
readers[rid] = reader_entries
|
|
199
|
+
reading = self.obj(state.get("reading"), "reading")
|
|
200
|
+
status = reading.get("status")
|
|
201
|
+
self.require(status in ("计划中", "已完成", "部分覆盖", "未完成", "跳过"), "reading", "无效试读状态")
|
|
202
|
+
self.text(reading.get("reason"), "reading.reason")
|
|
203
|
+
links = self.seq(reading.get("review_ids"), "reading.review_ids")
|
|
204
|
+
for rid in links:
|
|
205
|
+
valid = isinstance(rid, str) and rid in readers
|
|
206
|
+
self.require(valid, "reading", "读者报告引用无效")
|
|
207
|
+
if valid and status in ("已完成", "部分覆盖"):
|
|
208
|
+
entries = readers[rid]
|
|
209
|
+
self.require(bool(entries) and all(a == "current" and m and st in ("已完成", "部分覆盖") for a, st, m in entries), "reading", "报告未完成或不适用当前版本")
|
|
210
|
+
if status == "已完成":
|
|
211
|
+
self.require(all(st == "已完成" for _, st, _ in entries), "reading", "部分覆盖不能证明完成")
|
|
212
|
+
if status in ("已完成", "部分覆盖"):
|
|
213
|
+
self.require(bool(links), "reading", "缺少支持试读结论的报告")
|
|
214
|
+
if self.final:
|
|
215
|
+
for fid, item in files.items():
|
|
216
|
+
if item.get("kind") != "shared" and fid not in passes:
|
|
217
|
+
self.add("unchecked", "files." + fid, "缺少当前内容通过记录")
|
|
218
|
+
if status not in ("已完成", "跳过"):
|
|
219
|
+
self.add("unchecked", "reading", "试读未完成或仅部分覆盖")
|
|
220
|
+
if not self.result["failed"]:
|
|
221
|
+
self.add("passed", "scope", "已实现的机械约束未发现冲突;未检查项另列")
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def unique_keys(pairs):
|
|
225
|
+
result = {}
|
|
226
|
+
for key, value in pairs:
|
|
227
|
+
if key in result:
|
|
228
|
+
raise ValueError("重复JSON键: " + key)
|
|
229
|
+
result[key] = value
|
|
230
|
+
return result
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def main():
|
|
234
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
235
|
+
parser.add_argument("--root", type=Path, required=True)
|
|
236
|
+
parser.add_argument("--state", type=Path, required=True)
|
|
237
|
+
parser.add_argument("--final", action="store_true")
|
|
238
|
+
args = parser.parse_args()
|
|
239
|
+
check = Check(args.root, args.final)
|
|
240
|
+
try:
|
|
241
|
+
if not args.root.is_dir() or not args.state.resolve().is_relative_to(args.root.resolve()):
|
|
242
|
+
raise ValueError("主题目录不存在或清单越出目录")
|
|
243
|
+
state = json.loads(args.state.read_text(encoding="utf-8-sig"), object_pairs_hook=unique_keys)
|
|
244
|
+
check.run(state)
|
|
245
|
+
except (OSError, ValueError, TypeError, RecursionError) as exc:
|
|
246
|
+
check.add("failed", "state", str(exc))
|
|
247
|
+
check.result["limits"] = "只检查机械一致性;不证明来源、范围完整性、上下文隔离、实际体验或链接锚点正确。"
|
|
248
|
+
print(json.dumps(check.result, ensure_ascii=False, indent=2))
|
|
249
|
+
return 1 if check.result["failed"] else 2 if check.result["unchecked"] else 0
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
if __name__ == "__main__":
|
|
253
|
+
raise SystemExit(main())
|