formwork-kit 0.1.0__py3-none-any.whl
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.
- formwork_cli/__init__.py +326 -0
- formwork_cli/kit/COSTS.md +111 -0
- formwork_cli/kit/adapters/claude-code/README.md +53 -0
- formwork_cli/kit/adapters/claude-code/settings.json +46 -0
- formwork_cli/kit/adapters/codex/README.md +43 -0
- formwork_cli/kit/adapters/cursor/README.md +45 -0
- formwork_cli/kit/adapters/gemini-cli/README.md +47 -0
- formwork_cli/kit/build +410 -0
- formwork_cli/kit/check/checks/config-shape +123 -0
- formwork_cli/kit/check/checks/decision-ids +159 -0
- formwork_cli/kit/check/checks/doc-links +133 -0
- formwork_cli/kit/check/checks/generated-current +74 -0
- formwork_cli/kit/check/checks/guard-wired +139 -0
- formwork_cli/kit/check/checks/kit-integrity +199 -0
- formwork_cli/kit/check/checks/predictions-first +127 -0
- formwork_cli/kit/check/checks/role-shape +172 -0
- formwork_cli/kit/check/checks/rule-labels +135 -0
- formwork_cli/kit/check/fixtures/config-shape/must-fail/documents-a-section-that-does-not-exist/.formwork.toml +5 -0
- formwork_cli/kit/check/fixtures/config-shape/must-fail/documents-a-section-that-does-not-exist/formwork/guide.md +13 -0
- formwork_cli/kit/check/fixtures/config-shape/must-fail/rules-as-a-switchboard/.formwork.toml +8 -0
- formwork_cli/kit/check/fixtures/config-shape/must-pass/layers-kept-apart/.formwork.toml +5 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-fail/a-placeholder-shipped/docs/decisions/0003-still-pending.md +7 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-fail/superseded-by-nothing/docs/decisions/0002-old.md +6 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-fail/two-decisions-one-number/docs/decisions/0007-first.md +6 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-fail/two-decisions-one-number/docs/decisions/0007-second.md +6 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-pass/clean-numbering/docs/decisions/0001-the-first.md +6 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-pass/clean-numbering/docs/decisions/0002-the-second.md +6 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-pass/clean-numbering/docs/decisions/0003-the-third.md +6 -0
- formwork_cli/kit/check/fixtures/decision-ids/must-pass/nothing-recorded-yet/docs/decisions/README.md +3 -0
- formwork_cli/kit/check/fixtures/doc-links/must-fail/never-written/index.md +7 -0
- formwork_cli/kit/check/fixtures/doc-links/must-fail/renamed-file/architecture-notes.md +3 -0
- formwork_cli/kit/check/fixtures/doc-links/must-fail/renamed-file/guide.md +8 -0
- formwork_cli/kit/check/fixtures/doc-links/must-pass/links-resolve/architecture-notes.md +1 -0
- formwork_cli/kit/check/fixtures/doc-links/must-pass/links-resolve/guide.md +5 -0
- formwork_cli/kit/check/fixtures/generated-current/must-fail/a-generated-file-was-edited/.claude/agents/sample.md +22 -0
- formwork_cli/kit/check/fixtures/generated-current/must-fail/a-generated-file-was-edited/.codex/agents/sample.toml +22 -0
- formwork_cli/kit/check/fixtures/generated-current/must-fail/a-generated-file-was-edited/.formwork.toml +1 -0
- formwork_cli/kit/check/fixtures/generated-current/must-fail/a-generated-file-was-edited/.gemini/agents/sample.md +23 -0
- formwork_cli/kit/check/fixtures/generated-current/must-fail/a-generated-file-was-edited/formwork/build +349 -0
- formwork_cli/kit/check/fixtures/generated-current/must-fail/a-generated-file-was-edited/formwork/roles/method/sample.md +18 -0
- formwork_cli/kit/check/fixtures/generated-current/must-pass/generated-and-current/.claude/agents/sample.md +20 -0
- formwork_cli/kit/check/fixtures/generated-current/must-pass/generated-and-current/.codex/agents/sample.toml +22 -0
- formwork_cli/kit/check/fixtures/generated-current/must-pass/generated-and-current/.formwork.toml +1 -0
- formwork_cli/kit/check/fixtures/generated-current/must-pass/generated-and-current/.gemini/agents/sample.md +23 -0
- formwork_cli/kit/check/fixtures/generated-current/must-pass/generated-and-current/formwork/build +349 -0
- formwork_cli/kit/check/fixtures/generated-current/must-pass/generated-and-current/formwork/roles/method/sample.md +18 -0
- formwork_cli/kit/check/fixtures/generated-current/must-pass/nothing-is-generated-here/README.md +3 -0
- formwork_cli/kit/check/fixtures/guard-wired/must-fail/declared-but-no-file/.formwork.toml +1 -0
- formwork_cli/kit/check/fixtures/guard-wired/must-fail/file-but-not-wired/.claude/settings.json +1 -0
- formwork_cli/kit/check/fixtures/guard-wired/must-fail/file-but-not-wired/.formwork.toml +1 -0
- formwork_cli/kit/check/fixtures/guard-wired/must-pass/declared-and-wired/.claude/settings.json +1 -0
- formwork_cli/kit/check/fixtures/guard-wired/must-pass/declared-and-wired/.formwork.toml +1 -0
- formwork_cli/kit/check/fixtures/guard-wired/must-pass/nothing-declared/README.md +1 -0
- formwork_cli/kit/check/fixtures/kit-integrity/must-fail/a-check-went-missing/formwork/check/checks/still-here +2 -0
- formwork_cli/kit/check/fixtures/kit-integrity/must-fail/a-check-went-missing/state/fingerprints.txt +2 -0
- formwork_cli/kit/check/fixtures/kit-integrity/must-fail/a-guard-was-altered/formwork/guard/git-boundary +3 -0
- formwork_cli/kit/check/fixtures/kit-integrity/must-fail/a-guard-was-altered/state/fingerprints.txt +1 -0
- formwork_cli/kit/check/fixtures/kit-integrity/must-pass/everything-matches/formwork/guard/git-boundary +2 -0
- formwork_cli/kit/check/fixtures/kit-integrity/must-pass/everything-matches/state/fingerprints.txt +1 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-fail/argued-with-no-predictions/docs/rounds/0004-the-storage-question/architect.md +3 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-fail/argued-with-no-predictions/docs/rounds/0004-the-storage-question/researcher.md +3 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-fail/argued-with-no-predictions/docs/rounds/0004-the-storage-question/round.md +4 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-pass/a-round-that-has-not-argued-yet/docs/rounds/0006-not-started/round.md +3 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-pass/no-rounds-at-all/docs/README.md +3 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-pass/predictions-on-record/docs/rounds/0005-the-shape-of-a-brief/architect.md +3 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-pass/predictions-on-record/docs/rounds/0005-the-shape-of-a-brief/predictions.md +4 -0
- formwork_cli/kit/check/fixtures/predictions-first/must-pass/predictions-on-record/docs/rounds/0005-the-shape-of-a-brief/researcher.md +3 -0
- formwork_cli/kit/check/fixtures/role-shape/must-fail/claims-a-grant-binds-everywhere/formwork/roles/README.md +6 -0
- formwork_cli/kit/check/fixtures/role-shape/must-fail/claims-a-grant-binds-everywhere/formwork/roles/complete.md +18 -0
- formwork_cli/kit/check/fixtures/role-shape/must-fail/missing-a-section/formwork/roles/vague.md +16 -0
- formwork_cli/kit/check/fixtures/role-shape/must-fail/spawn-without-being-lead/formwork/roles/eager.md +18 -0
- formwork_cli/kit/check/fixtures/role-shape/must-fail/two-roles-one-job/formwork/roles/first.md +18 -0
- formwork_cli/kit/check/fixtures/role-shape/must-fail/two-roles-one-job/formwork/roles/second.md +18 -0
- formwork_cli/kit/check/fixtures/role-shape/must-pass/well-formed/formwork/roles/complete.md +18 -0
- formwork_cli/kit/check/fixtures/rule-labels/must-fail/claims-enforcement-that-does-not-exist/formwork/rules/core.md +9 -0
- formwork_cli/kit/check/fixtures/rule-labels/must-fail/no-catches/formwork/rules/core.md +9 -0
- formwork_cli/kit/check/fixtures/rule-labels/must-fail/unlabelled/formwork/rules/core.md +7 -0
- formwork_cli/kit/check/fixtures/rule-labels/must-pass/well-formed/formwork/rules/core.md +10 -0
- formwork_cli/kit/check/run +340 -0
- formwork_cli/kit/check/test_gate.py +222 -0
- formwork_cli/kit/first-run.md +204 -0
- formwork_cli/kit/fw +121 -0
- formwork_cli/kit/glossary.md +160 -0
- formwork_cli/kit/guard/git-boundary +627 -0
- formwork_cli/kit/guard/protected-files +748 -0
- formwork_cli/kit/guard/quality-gate +260 -0
- formwork_cli/kit/guard/test_boundary.py +273 -0
- formwork_cli/kit/guard/test_protection.py +254 -0
- formwork_cli/kit/guard/test_quality_gate.py +156 -0
- formwork_cli/kit/install +395 -0
- formwork_cli/kit/limits.md +141 -0
- formwork_cli/kit/loop.md +82 -0
- formwork_cli/kit/roles/HOW-TO-ADD-A-ROLE.md +105 -0
- formwork_cli/kit/roles/TEMPLATE.md +26 -0
- formwork_cli/kit/roles/method/architect.md +269 -0
- formwork_cli/kit/roles/method/challenger.md +243 -0
- formwork_cli/kit/roles/method/lead.md +280 -0
- formwork_cli/kit/roles/method/record-keeper.md +206 -0
- formwork_cli/kit/roles/method/researcher.md +246 -0
- formwork_cli/kit/roles/method/reviewer.md +207 -0
- formwork_cli/kit/roles/packs/accessibility.md +236 -0
- formwork_cli/kit/roles/packs/ai.md +248 -0
- formwork_cli/kit/roles/packs/analyst.md +233 -0
- formwork_cli/kit/roles/packs/backend.md +425 -0
- formwork_cli/kit/roles/packs/brainstormer.md +190 -0
- formwork_cli/kit/roles/packs/data.md +212 -0
- formwork_cli/kit/roles/packs/devops.md +203 -0
- formwork_cli/kit/roles/packs/frontend.md +224 -0
- formwork_cli/kit/roles/packs/integrations.md +215 -0
- formwork_cli/kit/roles/packs/legal.md +251 -0
- formwork_cli/kit/roles/packs/marketing.md +206 -0
- formwork_cli/kit/roles/packs/mobile.md +202 -0
- formwork_cli/kit/roles/packs/performance.md +192 -0
- formwork_cli/kit/roles/packs/product.md +217 -0
- formwork_cli/kit/roles/packs/security.md +267 -0
- formwork_cli/kit/roles/packs/sre.md +203 -0
- formwork_cli/kit/roles/packs/tester.md +246 -0
- formwork_cli/kit/roles/packs/user-researcher.md +218 -0
- formwork_cli/kit/roles/packs/ux.md +205 -0
- formwork_cli/kit/roles/packs/visual.md +199 -0
- formwork_cli/kit/roles/packs/writer.md +198 -0
- formwork_cli/kit/round.md +131 -0
- formwork_cli/kit/rules/core.md +195 -0
- formwork_cli/kit/rules/full.md +493 -0
- formwork_cli/kit/templates/brief.md +68 -0
- formwork_cli/kit/templates/decision.md +93 -0
- formwork_cli/kit/templates/predictions.md +54 -0
- formwork_cli/kit/templates/report.md +52 -0
- formwork_cli/kit/templates/round.md +77 -0
- formwork_cli/kit/test_install.py +165 -0
- formwork_cli/kit/troubleshooting.md +247 -0
- formwork_cli/kit-page/FORMWORK.md +182 -0
- formwork_kit-0.1.0.dist-info/METADATA +308 -0
- formwork_kit-0.1.0.dist-info/RECORD +137 -0
- formwork_kit-0.1.0.dist-info/WHEEL +4 -0
- formwork_kit-0.1.0.dist-info/entry_points.txt +2 -0
- formwork_kit-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Generate each runtime's role files from one source.
|
|
3
|
+
|
|
4
|
+
formwork/build write files for the runtime in .formwork.toml
|
|
5
|
+
formwork/build --all write files for every runtime
|
|
6
|
+
formwork/build --runtime codex just that one
|
|
7
|
+
formwork/build --check regenerate in memory and compare. Change nothing
|
|
8
|
+
|
|
9
|
+
Exit status:
|
|
10
|
+
0 done, or --check found everything current
|
|
11
|
+
1 --check found a generated file that is stale or hand-edited
|
|
12
|
+
2 could not run
|
|
13
|
+
|
|
14
|
+
WHY GENERATE AT ALL
|
|
15
|
+
-------------------
|
|
16
|
+
Four runtimes want role definitions in four shapes. Keeping four hand-written
|
|
17
|
+
copies of twenty-seven roles is the duplication that drifts — one gets updated
|
|
18
|
+
and the others quietly do not, and nothing announces it.
|
|
19
|
+
|
|
20
|
+
One source, generated outward, with a check that regeneration produces
|
|
21
|
+
identical bytes. A hand-edit to a generated file then fails the gate instead of
|
|
22
|
+
surviving.
|
|
23
|
+
|
|
24
|
+
WHAT EACH RUNTIME GETS, AND WHY CURSOR GETS NOTHING
|
|
25
|
+
---------------------------------------------------
|
|
26
|
+
claude-code .claude/agents/<name>.md markdown, tools by name
|
|
27
|
+
gemini-cli .gemini/agents/<name>.md markdown, tools by name
|
|
28
|
+
codex .codex/agents/<name>.toml TOML, no tool list at all
|
|
29
|
+
cursor nothing is written
|
|
30
|
+
|
|
31
|
+
Cursor's own documentation names `.claude/agents/` as a location it reads. So
|
|
32
|
+
the Claude Code output serves it directly, and generating a second identical
|
|
33
|
+
tree would be duplication for its own sake.
|
|
34
|
+
|
|
35
|
+
THE TOOL GRANT DOES NOT SURVIVE EVERY TRANSLATION
|
|
36
|
+
-------------------------------------------------
|
|
37
|
+
Claude Code and Gemini CLI take a named list and enforce it. Cursor has one
|
|
38
|
+
boolean. Codex has a sandbox mode, which is not a tool list.
|
|
39
|
+
|
|
40
|
+
This generator writes the grant where it can be expressed and **says in the
|
|
41
|
+
generated file where it cannot**, rather than emitting something that looks
|
|
42
|
+
like a restriction and is not. That was decided deliberately; the two rejected
|
|
43
|
+
alternatives are recorded in docs/role-formats.md.
|
|
44
|
+
|
|
45
|
+
Python 3, standard library only, no dependencies.
|
|
46
|
+
"""
|
|
47
|
+
import os
|
|
48
|
+
import re
|
|
49
|
+
import sys
|
|
50
|
+
|
|
51
|
+
CLEAN, STALE, CANNOT_RUN = 0, 1, 2
|
|
52
|
+
|
|
53
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
54
|
+
ROOT = os.path.dirname(HERE)
|
|
55
|
+
ROLES = os.path.join(HERE, "roles")
|
|
56
|
+
|
|
57
|
+
BANNER = ("GENERATED FROM %s — DO NOT EDIT.\n"
|
|
58
|
+
"Change the source and run formwork/build. A hand-edit here fails "
|
|
59
|
+
"the gate.")
|
|
60
|
+
|
|
61
|
+
# The kit's five abstract grants, mapped to what each runtime actually calls
|
|
62
|
+
# them. None means the name is not established, and the generator will not
|
|
63
|
+
# invent one.
|
|
64
|
+
TOOL_NAMES = {
|
|
65
|
+
"claude-code": {
|
|
66
|
+
"read": ["Read", "Glob", "Grep"],
|
|
67
|
+
"write": ["Write", "Edit"],
|
|
68
|
+
"run": ["Bash"],
|
|
69
|
+
"web": ["WebFetch", "WebSearch"],
|
|
70
|
+
"spawn": ["Task"],
|
|
71
|
+
},
|
|
72
|
+
"gemini-cli": {
|
|
73
|
+
"read": ["read_file", "grep_search"],
|
|
74
|
+
"run": ["run_shell_command"],
|
|
75
|
+
# Established from the publisher's own example. The name of the
|
|
76
|
+
# file-writing tool is NOT among the documented examples, and guessing
|
|
77
|
+
# it would produce an allowlist that silently omits a tool the role
|
|
78
|
+
# needs. See docs/role-formats.md.
|
|
79
|
+
"write": None,
|
|
80
|
+
"web": None,
|
|
81
|
+
"spawn": None,
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# Runtimes that can hold a role to its grant at all.
|
|
86
|
+
ENFORCES = {"claude-code", "gemini-cli"}
|
|
87
|
+
|
|
88
|
+
TARGETS = {
|
|
89
|
+
"claude-code": (os.path.join(".claude", "agents"), ".md"),
|
|
90
|
+
"gemini-cli": (os.path.join(".gemini", "agents"), ".md"),
|
|
91
|
+
"codex": (os.path.join(".codex", "agents"), ".toml"),
|
|
92
|
+
}
|
|
93
|
+
ALL_RUNTIMES = tuple(sorted(TARGETS)) + ("cursor",)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def read_roles():
|
|
97
|
+
out = []
|
|
98
|
+
for sub in ("method", "packs", "project"):
|
|
99
|
+
d = os.path.join(ROLES, sub)
|
|
100
|
+
if not os.path.isdir(d):
|
|
101
|
+
continue
|
|
102
|
+
for fn in sorted(os.listdir(d)):
|
|
103
|
+
if not fn.endswith(".md") or fn.upper().startswith(("TEMPLATE",
|
|
104
|
+
"HOW-TO",
|
|
105
|
+
"README")):
|
|
106
|
+
continue
|
|
107
|
+
out.append(os.path.join(d, fn))
|
|
108
|
+
return out
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def parse(path):
|
|
112
|
+
text = open(path, encoding="utf-8").read()
|
|
113
|
+
m = re.match(r"^---\n(.*?)\n---\n(.*)$", text, re.S)
|
|
114
|
+
if not m:
|
|
115
|
+
return None
|
|
116
|
+
meta = {}
|
|
117
|
+
for line in m.group(1).split("\n"):
|
|
118
|
+
if ":" in line:
|
|
119
|
+
k, v = line.split(":", 1)
|
|
120
|
+
meta[k.strip()] = v.strip()
|
|
121
|
+
body = m.group(2).lstrip("\n")
|
|
122
|
+
# Accept both `tools: ["read", "write"]` and `tools: [read, write]`.
|
|
123
|
+
# Reading only the quoted form meant an unquoted list parsed as NO grants,
|
|
124
|
+
# which emitted frontmatter with no tools key at all — and in Claude Code
|
|
125
|
+
# that grants every tool. The safest-looking role got the widest grant.
|
|
126
|
+
raw = meta.get("tools", "")
|
|
127
|
+
tools = re.findall(r'"([a-z]+)"', raw) or re.findall(r"\b([a-z]+)\b", raw)
|
|
128
|
+
owns = re.search(r"^\*\*Owns\.\*\*\s*(.+?)(?:\n\n|\Z)", body, re.S | re.M)
|
|
129
|
+
description = " ".join(owns.group(1).split()) if owns else meta.get("name", "")
|
|
130
|
+
if len(description) > 300:
|
|
131
|
+
description = description[:297].rsplit(" ", 1)[0] + "…"
|
|
132
|
+
return {"name": meta.get("name", ""), "pack": meta.get("pack", ""),
|
|
133
|
+
"owns": meta.get("owns", ""), "tools": tools,
|
|
134
|
+
"description": description, "body": body,
|
|
135
|
+
"source": os.path.relpath(path, ROOT)}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def resolve_tools(runtime, grants):
|
|
139
|
+
"""(names, unmapped). names is None when the list cannot be completed."""
|
|
140
|
+
table = TOOL_NAMES.get(runtime)
|
|
141
|
+
if table is None:
|
|
142
|
+
return None, list(grants)
|
|
143
|
+
names, unmapped = [], []
|
|
144
|
+
for g in grants:
|
|
145
|
+
got = table.get(g)
|
|
146
|
+
if got is None:
|
|
147
|
+
unmapped.append(g)
|
|
148
|
+
else:
|
|
149
|
+
names.extend(got)
|
|
150
|
+
if unmapped:
|
|
151
|
+
return None, unmapped
|
|
152
|
+
return names, []
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def render_markdown(role, runtime):
|
|
156
|
+
names, unmapped = resolve_tools(runtime, role["tools"])
|
|
157
|
+
if not role["tools"]:
|
|
158
|
+
# No grant could be read at all. Emitting frontmatter without a tools
|
|
159
|
+
# key means "every tool" on some runtimes, so say so instead.
|
|
160
|
+
unmapped = ["(the grant could not be read from the source)"]
|
|
161
|
+
lines = ["---", "name: %s" % role["name"],
|
|
162
|
+
"description: %s" % role["description"]]
|
|
163
|
+
if runtime == "gemini-cli":
|
|
164
|
+
lines.append("kind: local")
|
|
165
|
+
if names:
|
|
166
|
+
if runtime == "claude-code":
|
|
167
|
+
lines.append("tools: %s" % ", ".join(names))
|
|
168
|
+
else:
|
|
169
|
+
lines.append("tools:")
|
|
170
|
+
lines += [" - %s" % n for n in names]
|
|
171
|
+
lines.append("---")
|
|
172
|
+
lines.append("")
|
|
173
|
+
for line in (BANNER % role["source"]).split("\n"):
|
|
174
|
+
lines.append("<!-- %s -->" % line)
|
|
175
|
+
lines.append("")
|
|
176
|
+
if unmapped:
|
|
177
|
+
lines.append("> **This role's tool grant is not expressed here.** It "
|
|
178
|
+
"asks for %s, and %s does not have a documented name for "
|
|
179
|
+
"%s. An incomplete allowlist would quietly remove a tool "
|
|
180
|
+
"the role needs, so none is written. The grant is advice "
|
|
181
|
+
"on this runtime."
|
|
182
|
+
% (", ".join("`%s`" % t for t in role["tools"]),
|
|
183
|
+
runtime, " and ".join("`%s`" % u for u in unmapped)))
|
|
184
|
+
lines.append("")
|
|
185
|
+
lines.append(role["body"].rstrip())
|
|
186
|
+
lines.append("")
|
|
187
|
+
return "\n".join(lines)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def toml_escape(s):
|
|
191
|
+
return s.replace("\\", "\\\\").replace('"', '\\"')
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def render_toml(role):
|
|
195
|
+
banner = (BANNER % role["source"]).split("\n")
|
|
196
|
+
out = ["# %s" % b for b in banner]
|
|
197
|
+
out.append("")
|
|
198
|
+
out.append('name = "%s"' % toml_escape(role["name"]))
|
|
199
|
+
out.append('description = "%s"' % toml_escape(role["description"]))
|
|
200
|
+
out.append("")
|
|
201
|
+
out.append("# This runtime has a sandbox mode rather than a tool list, so")
|
|
202
|
+
out.append("# the grant %s is not expressed here. It is advice on Codex."
|
|
203
|
+
% ", ".join(role["tools"]))
|
|
204
|
+
out.append("")
|
|
205
|
+
out.append('developer_instructions = """')
|
|
206
|
+
out.append(role["body"].rstrip().replace('"""', '\\"\\"\\"'))
|
|
207
|
+
out.append('"""')
|
|
208
|
+
out.append("")
|
|
209
|
+
return "\n".join(out)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def existing_targets():
|
|
213
|
+
"""Runtimes whose generated tree is already present in this project.
|
|
214
|
+
|
|
215
|
+
A fork that uses one runtime should not be made to generate files for
|
|
216
|
+
three. But a tree that exists must stay current, or a stale agent
|
|
217
|
+
definition survives unnoticed — which is the whole reason this generator
|
|
218
|
+
exists.
|
|
219
|
+
"""
|
|
220
|
+
out = []
|
|
221
|
+
for runtime, (folder, _ext) in sorted(TARGETS.items()):
|
|
222
|
+
if os.path.isdir(os.path.join(ROOT, folder)):
|
|
223
|
+
out.append(runtime)
|
|
224
|
+
return out
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def orphans(files, runtimes):
|
|
228
|
+
"""Generated files with no source, in the trees we generate into.
|
|
229
|
+
|
|
230
|
+
An agent definition added by hand, or one left behind after its source was
|
|
231
|
+
deleted, used to pass unnoticed: --check only compared files the source
|
|
232
|
+
produces. A hand-written agent with every tool granted is exactly what
|
|
233
|
+
this kit exists to prevent.
|
|
234
|
+
"""
|
|
235
|
+
expected = set(files)
|
|
236
|
+
found = []
|
|
237
|
+
for runtime in runtimes:
|
|
238
|
+
if runtime == "cursor":
|
|
239
|
+
continue
|
|
240
|
+
folder, ext = TARGETS[runtime]
|
|
241
|
+
d = os.path.join(ROOT, folder)
|
|
242
|
+
if not os.path.isdir(d):
|
|
243
|
+
continue
|
|
244
|
+
for fn in sorted(os.listdir(d)):
|
|
245
|
+
if not fn.endswith(ext):
|
|
246
|
+
continue
|
|
247
|
+
rel = os.path.join(folder, fn)
|
|
248
|
+
if rel not in expected:
|
|
249
|
+
found.append(rel)
|
|
250
|
+
return found
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def outputs(runtimes):
|
|
254
|
+
"""{path: contents} for every runtime asked for."""
|
|
255
|
+
files = {}
|
|
256
|
+
roles = [parse(p) for p in read_roles()]
|
|
257
|
+
roles = [r for r in roles if r and r["name"]]
|
|
258
|
+
if not roles:
|
|
259
|
+
return None
|
|
260
|
+
for runtime in runtimes:
|
|
261
|
+
if runtime == "cursor":
|
|
262
|
+
continue # reads .claude/agents/ directly
|
|
263
|
+
folder, ext = TARGETS[runtime]
|
|
264
|
+
for role in roles:
|
|
265
|
+
rel = os.path.join(folder, role["name"] + ext)
|
|
266
|
+
if ext == ".toml":
|
|
267
|
+
files[rel] = render_toml(role)
|
|
268
|
+
else:
|
|
269
|
+
files[rel] = render_markdown(role, runtime)
|
|
270
|
+
return files
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def configured_runtime():
|
|
274
|
+
config = os.path.join(ROOT, ".formwork.toml")
|
|
275
|
+
if os.path.exists(config):
|
|
276
|
+
text = open(config, encoding="utf-8", errors="ignore").read()
|
|
277
|
+
m = re.search(r'^\s*runtime\s*=\s*["\']([^"\']+)["\']', text, re.M)
|
|
278
|
+
if m and m.group(1) in ALL_RUNTIMES:
|
|
279
|
+
return m.group(1)
|
|
280
|
+
return "claude-code"
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def main(argv):
|
|
284
|
+
check_only = "--check" in argv
|
|
285
|
+
if "--all" in argv:
|
|
286
|
+
runtimes = [r for r in ALL_RUNTIMES if r != "cursor"]
|
|
287
|
+
elif check_only and "--runtime" not in argv:
|
|
288
|
+
# Check the configured runtime, plus any tree already present. A fork
|
|
289
|
+
# using one runtime is not made to generate files for three, and a
|
|
290
|
+
# tree that does exist is still held to being current.
|
|
291
|
+
runtimes = sorted(set([configured_runtime()] + existing_targets())
|
|
292
|
+
- {"cursor"})
|
|
293
|
+
if not runtimes:
|
|
294
|
+
runtimes = ["claude-code"]
|
|
295
|
+
elif "--runtime" in argv:
|
|
296
|
+
i = argv.index("--runtime")
|
|
297
|
+
if i + 1 >= len(argv) or argv[i + 1] not in ALL_RUNTIMES:
|
|
298
|
+
print("ERROR: --runtime needs one of: %s" % ", ".join(ALL_RUNTIMES),
|
|
299
|
+
file=sys.stderr)
|
|
300
|
+
return CANNOT_RUN
|
|
301
|
+
runtimes = [argv[i + 1]]
|
|
302
|
+
else:
|
|
303
|
+
runtimes = [configured_runtime()]
|
|
304
|
+
|
|
305
|
+
if runtimes == ["cursor"]:
|
|
306
|
+
print("cursor reads .claude/agents/, so nothing is generated for it")
|
|
307
|
+
runtimes = ["claude-code"]
|
|
308
|
+
|
|
309
|
+
files = outputs(runtimes)
|
|
310
|
+
if files is None:
|
|
311
|
+
print("ERROR: no roles found under %s" % ROLES, file=sys.stderr)
|
|
312
|
+
return CANNOT_RUN
|
|
313
|
+
|
|
314
|
+
if check_only:
|
|
315
|
+
stale = ["%s — generated, but nothing in formwork/roles/ produces it"
|
|
316
|
+
% o for o in orphans(files, runtimes)]
|
|
317
|
+
for rel, content in sorted(files.items()):
|
|
318
|
+
full = os.path.join(ROOT, rel)
|
|
319
|
+
if not os.path.exists(full):
|
|
320
|
+
stale.append("%s — missing" % rel)
|
|
321
|
+
elif open(full, encoding="utf-8").read() != content:
|
|
322
|
+
stale.append("%s — differs from what the source produces" % rel)
|
|
323
|
+
if stale:
|
|
324
|
+
print("%d generated file(s) are not current:" % len(stale))
|
|
325
|
+
for s in stale:
|
|
326
|
+
print(" %s" % s)
|
|
327
|
+
print(" Run formwork/build. If you edited one by hand, that edit "
|
|
328
|
+
"is about to be lost — move it to the source first.")
|
|
329
|
+
return STALE
|
|
330
|
+
print("%d generated file(s), all current" % len(files))
|
|
331
|
+
return CLEAN
|
|
332
|
+
|
|
333
|
+
written = 0
|
|
334
|
+
for rel, content in sorted(files.items()):
|
|
335
|
+
full = os.path.join(ROOT, rel)
|
|
336
|
+
os.makedirs(os.path.dirname(full), exist_ok=True)
|
|
337
|
+
existing = None
|
|
338
|
+
if os.path.exists(full):
|
|
339
|
+
existing = open(full, encoding="utf-8").read()
|
|
340
|
+
if existing != content:
|
|
341
|
+
open(full, "w", encoding="utf-8").write(content)
|
|
342
|
+
written += 1
|
|
343
|
+
print("%d role file(s) considered, %d written, for: %s"
|
|
344
|
+
% (len(files), written, ", ".join(runtimes)))
|
|
345
|
+
return CLEAN
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
if __name__ == "__main__":
|
|
349
|
+
sys.exit(main(sys.argv))
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sample
|
|
3
|
+
pack: method
|
|
4
|
+
owns: a-sample-job
|
|
5
|
+
tools: ["read"]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Sample
|
|
9
|
+
|
|
10
|
+
**Owns.** One clearly stated thing.
|
|
11
|
+
|
|
12
|
+
**Does not own.** Something else.
|
|
13
|
+
|
|
14
|
+
**Tools.** Reading.
|
|
15
|
+
|
|
16
|
+
**Stops when.** It reaches the edge.
|
|
17
|
+
|
|
18
|
+
**Would be wrong if.** It carried on.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sample
|
|
3
|
+
description: One clearly stated thing.
|
|
4
|
+
tools: Read, Glob, Grep
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<!-- GENERATED FROM formwork/roles/method/sample.md — DO NOT EDIT. -->
|
|
8
|
+
<!-- Change the source and run formwork/build. A hand-edit here fails the gate. -->
|
|
9
|
+
|
|
10
|
+
# Sample
|
|
11
|
+
|
|
12
|
+
**Owns.** One clearly stated thing.
|
|
13
|
+
|
|
14
|
+
**Does not own.** Something else.
|
|
15
|
+
|
|
16
|
+
**Tools.** Reading.
|
|
17
|
+
|
|
18
|
+
**Stops when.** It reaches the edge.
|
|
19
|
+
|
|
20
|
+
**Would be wrong if.** It carried on.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# GENERATED FROM formwork/roles/method/sample.md — DO NOT EDIT.
|
|
2
|
+
# Change the source and run formwork/build. A hand-edit here fails the gate.
|
|
3
|
+
|
|
4
|
+
name = "sample"
|
|
5
|
+
description = "One clearly stated thing."
|
|
6
|
+
|
|
7
|
+
# This runtime has a sandbox mode rather than a tool list, so
|
|
8
|
+
# the grant read is not expressed here. It is advice on Codex.
|
|
9
|
+
|
|
10
|
+
developer_instructions = """
|
|
11
|
+
# Sample
|
|
12
|
+
|
|
13
|
+
**Owns.** One clearly stated thing.
|
|
14
|
+
|
|
15
|
+
**Does not own.** Something else.
|
|
16
|
+
|
|
17
|
+
**Tools.** Reading.
|
|
18
|
+
|
|
19
|
+
**Stops when.** It reaches the edge.
|
|
20
|
+
|
|
21
|
+
**Would be wrong if.** It carried on.
|
|
22
|
+
"""
|
formwork_cli/kit/check/fixtures/generated-current/must-pass/generated-and-current/.formwork.toml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
runtime = "claude-code"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sample
|
|
3
|
+
description: One clearly stated thing.
|
|
4
|
+
kind: local
|
|
5
|
+
tools:
|
|
6
|
+
- read_file
|
|
7
|
+
- grep_search
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<!-- GENERATED FROM formwork/roles/method/sample.md — DO NOT EDIT. -->
|
|
11
|
+
<!-- Change the source and run formwork/build. A hand-edit here fails the gate. -->
|
|
12
|
+
|
|
13
|
+
# Sample
|
|
14
|
+
|
|
15
|
+
**Owns.** One clearly stated thing.
|
|
16
|
+
|
|
17
|
+
**Does not own.** Something else.
|
|
18
|
+
|
|
19
|
+
**Tools.** Reading.
|
|
20
|
+
|
|
21
|
+
**Stops when.** It reaches the edge.
|
|
22
|
+
|
|
23
|
+
**Would be wrong if.** It carried on.
|