waymark-cli 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.
- waymark/__init__.py +3 -0
- waymark/__main__.py +8 -0
- waymark/adapters/__init__.py +102 -0
- waymark/adapters/claude_code.py +238 -0
- waymark/assets/__init__.py +43 -0
- waymark/assets/agents/wm-implementer.md +45 -0
- waymark/assets/agents/wm-reviewer.md +43 -0
- waymark/assets/skills/wm-apply/SKILL.md +58 -0
- waymark/assets/skills/wm-archive/SKILL.md +32 -0
- waymark/assets/skills/wm-explore/SKILL.md +34 -0
- waymark/assets/skills/wm-kickoff/SKILL.md +34 -0
- waymark/assets/skills/wm-onboard/SKILL.md +27 -0
- waymark/assets/skills/wm-pr/SKILL.md +24 -0
- waymark/assets/skills/wm-propose/SKILL.md +32 -0
- waymark/assets/skills/wm-update/SKILL.md +31 -0
- waymark/cli.py +537 -0
- waymark/hooks/__init__.py +6 -0
- waymark/hooks/commands.py +190 -0
- waymark/hooks/decide.py +314 -0
- waymark/hooks/events.py +79 -0
- waymark/py.typed +0 -0
- waymark/record/__init__.py +5 -0
- waymark/record/atlas.py +156 -0
- waymark/record/changes.py +202 -0
- waymark/record/charter.py +75 -0
- waymark/record/commits.py +78 -0
- waymark/record/config.py +215 -0
- waymark/record/deltas.py +318 -0
- waymark/record/design.py +80 -0
- waymark/record/edits.py +95 -0
- waymark/record/evidence.py +58 -0
- waymark/record/explorations.py +66 -0
- waymark/record/files.py +75 -0
- waymark/record/fingerprint.py +73 -0
- waymark/record/git.py +167 -0
- waymark/record/githooks.py +106 -0
- waymark/record/links.py +104 -0
- waymark/record/milestones.py +84 -0
- waymark/record/moves.py +60 -0
- waymark/record/names.py +39 -0
- waymark/record/outline.py +144 -0
- waymark/record/pointer.py +56 -0
- waymark/record/problems.py +20 -0
- waymark/record/project.py +118 -0
- waymark/record/proposal.py +171 -0
- waymark/record/record.py +340 -0
- waymark/record/registry.py +158 -0
- waymark/record/specs.py +227 -0
- waymark/record/state.py +472 -0
- waymark/record/store.py +88 -0
- waymark/record/tasks.py +415 -0
- waymark/record/templates/charter.md +45 -0
- waymark/record/templates/ci-workflow.yml +29 -0
- waymark/record/templates/config-atlas.toml +8 -0
- waymark/record/templates/config.toml +19 -0
- waymark/record/templates/delta.md +29 -0
- waymark/record/templates/design.md +20 -0
- waymark/record/templates/exploration.md +22 -0
- waymark/record/templates/goal.md +13 -0
- waymark/record/templates/hook-commit-msg +8 -0
- waymark/record/templates/hook-pre-commit +8 -0
- waymark/record/templates/proposal.md +18 -0
- waymark/record/templates/roadmap.md +4 -0
- waymark/record/templates/tasks.md +10 -0
- waymark/record/templates.py +30 -0
- waymark/record/terms.py +51 -0
- waymark/record/text.py +197 -0
- waymark/services/__init__.py +1 -0
- waymark/services/atlas.py +162 -0
- waymark/services/check.py +129 -0
- waymark/services/ci.py +44 -0
- waymark/services/common.py +154 -0
- waymark/services/context.py +296 -0
- waymark/services/doctor.py +367 -0
- waymark/services/githooks.py +132 -0
- waymark/services/instructions.py +304 -0
- waymark/services/integration.py +170 -0
- waymark/services/lifecycle.py +454 -0
- waymark/services/migrations.py +90 -0
- waymark/services/pr.py +177 -0
- waymark/services/references.py +27 -0
- waymark/services/setup.py +127 -0
- waymark/views/__init__.py +5 -0
- waymark/views/payloads.py +568 -0
- waymark/views/render.py +506 -0
- waymark/views/schemas.py +413 -0
- waymark/views/style.py +102 -0
- waymark_cli-0.1.0.dist-info/METADATA +313 -0
- waymark_cli-0.1.0.dist-info/RECORD +92 -0
- waymark_cli-0.1.0.dist-info/WHEEL +4 -0
- waymark_cli-0.1.0.dist-info/entry_points.txt +2 -0
- waymark_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"""Instructions: what an agent does at one step of a change.
|
|
2
|
+
|
|
3
|
+
For the step asked about (by default the change's next step) this gives the
|
|
4
|
+
file to write and its template, the project's rules for that step, what to
|
|
5
|
+
read first, the commands to run and what the step unlocks. Everything comes
|
|
6
|
+
from the files; nothing depends on an earlier conversation.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from waymark.record import templates
|
|
12
|
+
from waymark.record.changes import DESIGN_FILE, PROPOSAL_FILE, SPECS_DIR, TASKS_FILE, Change
|
|
13
|
+
from waymark.record.charter import CHARTER_FILE
|
|
14
|
+
from waymark.record.project import RECORD_DIR
|
|
15
|
+
from waymark.record.record import SPECS, Record
|
|
16
|
+
from waymark.record.state import AcceptanceState, ChangeState, StepKind
|
|
17
|
+
from waymark.record.terms import Layout, ReviewLevel, Step
|
|
18
|
+
from waymark.services.common import Refusal, find_change, state_of
|
|
19
|
+
|
|
20
|
+
INSTRUCTIONS_VERSION = 1
|
|
21
|
+
EXPLORE = "explore"
|
|
22
|
+
|
|
23
|
+
_RANK = {
|
|
24
|
+
StepKind.PROPOSE: 0,
|
|
25
|
+
StepKind.SPECS: 1,
|
|
26
|
+
StepKind.DESIGN: 2,
|
|
27
|
+
StepKind.TASKS: 3,
|
|
28
|
+
StepKind.RESOLVE_CONFLICT: 4,
|
|
29
|
+
StepKind.ACCEPT: 4,
|
|
30
|
+
StepKind.APPLY: 5,
|
|
31
|
+
StepKind.REVIEW: 5,
|
|
32
|
+
StepKind.RESOLVE_ITEMS: 5,
|
|
33
|
+
StepKind.ARCHIVE: 6,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
_UNLOCKS = {
|
|
37
|
+
StepKind.PROPOSE: "The specs step: the deltas against the living specs.",
|
|
38
|
+
StepKind.SPECS: "The design step, or the tasks step on the short path.",
|
|
39
|
+
StepKind.DESIGN: "The tasks step.",
|
|
40
|
+
StepKind.TASKS: "Acceptance by the human; nothing is built before it.",
|
|
41
|
+
StepKind.RESOLVE_CONFLICT: "Acceptance by the human.",
|
|
42
|
+
StepKind.ACCEPT: "Applying the items.",
|
|
43
|
+
StepKind.APPLY: "The item's review.",
|
|
44
|
+
StepKind.REVIEW: "The next item; after the last one, archiving.",
|
|
45
|
+
StepKind.RESOLVE_ITEMS: "Applying the item again.",
|
|
46
|
+
StepKind.ARCHIVE: "The living specs take the deltas, and the change moves to the archive.",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
_RISK_SIGNALS = (
|
|
50
|
+
"the item modifies or removes an existing requirement",
|
|
51
|
+
"it touches security, data integrity or money",
|
|
52
|
+
"it is being redone after a failed review",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _path(relative: str) -> str:
|
|
57
|
+
"""A record file's path from the project's top folder."""
|
|
58
|
+
return f"{RECORD_DIR}/{relative}"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _output(record: Record, relative: str, template: str | None) -> dict[str, Any]:
|
|
62
|
+
exists = "<" not in relative and record.files.is_file(relative)
|
|
63
|
+
return {"path": _path(relative), "exists": exists, "template": template}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _existing(record: Record, change: Change, *names: str) -> list[str]:
|
|
67
|
+
return [
|
|
68
|
+
_path(f"{change.path}/{name}")
|
|
69
|
+
for name in names
|
|
70
|
+
if record.files.is_file(f"{change.path}/{name}")
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _deltas(change: Change) -> list[str]:
|
|
75
|
+
return [_path(delta.doc.path) for _, delta in sorted(change.deltas.items())]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _specs(record: Record) -> list[str]:
|
|
79
|
+
return [_path(f"{SPECS}/{name}.md") for name in sorted(record.specs)]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _tasks_template(record: Record) -> str:
|
|
83
|
+
text = templates.render(templates.TASKS)
|
|
84
|
+
if record.layout is Layout.ATLAS:
|
|
85
|
+
repos = " | ".join(sorted(record.config.repo_names)) if record.config else ""
|
|
86
|
+
text = text.replace(
|
|
87
|
+
" - Verify: <how to check it>\n",
|
|
88
|
+
f" - Verify: <how to check it>\n - Repo: <{repos or 'repo'}>\n",
|
|
89
|
+
)
|
|
90
|
+
return text
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _drafting(
|
|
94
|
+
record: Record, change: Change, step: StepKind
|
|
95
|
+
) -> tuple[list[dict[str, Any]], list[str], list[str]]:
|
|
96
|
+
"""The outputs, reading list and guidance for a step that drafts an artifact."""
|
|
97
|
+
folder = change.path
|
|
98
|
+
charter = _path(CHARTER_FILE)
|
|
99
|
+
default = record.default_review.value
|
|
100
|
+
if step is StepKind.PROPOSE:
|
|
101
|
+
outputs = [_output(record, f"{folder}/{PROPOSAL_FILE}", None)]
|
|
102
|
+
guidance = [
|
|
103
|
+
"Fill in every section of the proposal; leave the Owner line as it is.",
|
|
104
|
+
'Under Impact, name the specs the change touches, or write "No spec changes".',
|
|
105
|
+
"Don't write the Accepted line or the Outcome section; wm writes the first, and "
|
|
106
|
+
"the second comes at archive.",
|
|
107
|
+
]
|
|
108
|
+
return outputs, [charter, *_specs(record)], guidance
|
|
109
|
+
if step is StepKind.SPECS:
|
|
110
|
+
outputs = [
|
|
111
|
+
_output(record, f"{folder}/{SPECS_DIR}/<domain>.md", templates.render(templates.DELTA))
|
|
112
|
+
]
|
|
113
|
+
guidance = [
|
|
114
|
+
"Write one delta file per spec the change touches, named after the spec.",
|
|
115
|
+
"A modified requirement is written out in full under its existing heading; "
|
|
116
|
+
"a removed one gives a reason; a rename is a removal plus an addition.",
|
|
117
|
+
"A delta that creates a spec needs a Purpose section.",
|
|
118
|
+
"Every requirement states what the system SHALL do and has at least one scenario.",
|
|
119
|
+
]
|
|
120
|
+
return (
|
|
121
|
+
outputs,
|
|
122
|
+
[charter, *_existing(record, change, PROPOSAL_FILE), *_specs(record)],
|
|
123
|
+
guidance,
|
|
124
|
+
)
|
|
125
|
+
if step is StepKind.DESIGN:
|
|
126
|
+
outputs = [_output(record, f"{folder}/{DESIGN_FILE}", templates.render(templates.DESIGN))]
|
|
127
|
+
guidance = [
|
|
128
|
+
"Say how the change will be built, not what it does; the deltas say that.",
|
|
129
|
+
"Record each decision with its options, the choice and why.",
|
|
130
|
+
]
|
|
131
|
+
read = [charter, *_existing(record, change, PROPOSAL_FILE), *_deltas(change)]
|
|
132
|
+
return outputs, read, guidance
|
|
133
|
+
outputs = [_output(record, f"{folder}/{TASKS_FILE}", _tasks_template(record))]
|
|
134
|
+
guidance = [
|
|
135
|
+
"Give every item criteria that can be checked, and say how to verify it.",
|
|
136
|
+
"Number items by section and never renumber; append new items at the end.",
|
|
137
|
+
f"The default review level is {default}. Tag an item only when its level differs, "
|
|
138
|
+
"and suggest independent review for risky items: " + "; ".join(_RISK_SIGNALS) + ".",
|
|
139
|
+
"Don't tick items or write Blocked, Spec gap or review lines; wm writes those.",
|
|
140
|
+
]
|
|
141
|
+
if record.layout is Layout.ATLAS:
|
|
142
|
+
guidance.append("Give every item a Repo line naming the repo it works in.")
|
|
143
|
+
if change.short_path:
|
|
144
|
+
guidance.append("This change is on the short path: no item may need independent review.")
|
|
145
|
+
read = [
|
|
146
|
+
charter,
|
|
147
|
+
*_existing(record, change, PROPOSAL_FILE, DESIGN_FILE),
|
|
148
|
+
*_deltas(change),
|
|
149
|
+
]
|
|
150
|
+
return outputs, read, guidance
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _working( # noqa: PLR0911 - one return per step
|
|
154
|
+
change: Change, state: ChangeState, step: StepKind
|
|
155
|
+
) -> tuple[list[str], list[str]]:
|
|
156
|
+
"""The guidance and commands for a step that works on an accepted change."""
|
|
157
|
+
name = change.name
|
|
158
|
+
item = state.next_step.item if state.next_step.kind is step else None
|
|
159
|
+
number = item or "<item>"
|
|
160
|
+
if step is StepKind.APPLY:
|
|
161
|
+
guidance = [
|
|
162
|
+
f"Start an implementer for item {number} with the change and item and nothing else.",
|
|
163
|
+
"The implementer begins from its context pack and ends with a RESULT line.",
|
|
164
|
+
"If the tool has no isolated agents, build the item yourself from the same pack.",
|
|
165
|
+
]
|
|
166
|
+
commands = [f"wm context {name} {number} --for implement"]
|
|
167
|
+
if state.next_step.reason:
|
|
168
|
+
commands.insert(0, f"wm reopen {name} {number}")
|
|
169
|
+
return guidance, commands
|
|
170
|
+
if step is StepKind.REVIEW:
|
|
171
|
+
level = next((i.level for i in state.items if i.number == item), None)
|
|
172
|
+
if level is ReviewLevel.INDEPENDENT:
|
|
173
|
+
guidance = [
|
|
174
|
+
f"Start a reviewer for item {number} with the change and item and nothing else.",
|
|
175
|
+
"The reviewer begins from its context pack and ends with a VERDICT line.",
|
|
176
|
+
"Without isolated agents, record the verdict yourself with the verdict command.",
|
|
177
|
+
]
|
|
178
|
+
commands = [
|
|
179
|
+
f"wm context {name} {number} --for review",
|
|
180
|
+
f'wm verdict {name} {number} pass|changes|spec-gap "<reasons>"',
|
|
181
|
+
]
|
|
182
|
+
return guidance, commands
|
|
183
|
+
guidance = [
|
|
184
|
+
f"Check item {number} against its criteria and the scenarios it serves: is it "
|
|
185
|
+
"complete, correct and coherent with the rest?",
|
|
186
|
+
"Then record the self-review. Commit once the review is recorded.",
|
|
187
|
+
]
|
|
188
|
+
return guidance, [f'wm review {name} {number} --self "<summary>"']
|
|
189
|
+
if step is StepKind.ARCHIVE:
|
|
190
|
+
guidance = [
|
|
191
|
+
"Archiving is the human's call: it comes after the code is merged.",
|
|
192
|
+
"Say in the outcome what was built and anything that differs from the proposal.",
|
|
193
|
+
]
|
|
194
|
+
return guidance, [f'wm archive {name} --outcome "<what came of it>"']
|
|
195
|
+
if step is StepKind.ACCEPT:
|
|
196
|
+
guidance = [
|
|
197
|
+
"Only the human accepts a change. Summarize the proposal, the deltas, the design "
|
|
198
|
+
"and the review levels, and ask them to run the command.",
|
|
199
|
+
]
|
|
200
|
+
return guidance, [f"wm accept {name}"]
|
|
201
|
+
if step is StepKind.RESOLVE_CONFLICT:
|
|
202
|
+
guidance = [
|
|
203
|
+
"A delta no longer applies to its spec. Revise the delta against the spec as it "
|
|
204
|
+
"now reads; the human then accepts the change again.",
|
|
205
|
+
]
|
|
206
|
+
return guidance, [f"wm show {name}"]
|
|
207
|
+
guidance = [
|
|
208
|
+
"These items wait on the human: bring each blocker, spec gap or verdict to them.",
|
|
209
|
+
"Once they have decided, record the decision; the item returns to apply.",
|
|
210
|
+
]
|
|
211
|
+
return guidance, [f'wm resolve {name} {number} "<what was decided>"', "wm inbox"]
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _explore(record: Record) -> dict[str, Any]:
|
|
215
|
+
charter = record.charter
|
|
216
|
+
return {
|
|
217
|
+
"schema": "wm.instructions",
|
|
218
|
+
"version": INSTRUCTIONS_VERSION,
|
|
219
|
+
"change": None,
|
|
220
|
+
"step": EXPLORE,
|
|
221
|
+
"item": None,
|
|
222
|
+
"ready": True,
|
|
223
|
+
"reason": "",
|
|
224
|
+
"outputs": [],
|
|
225
|
+
"rules": charter.rules.get(Step.EXPLORE, "") if charter else "",
|
|
226
|
+
"context": charter.context if charter else "",
|
|
227
|
+
"read": [_path(CHARTER_FILE)],
|
|
228
|
+
"guidance": [
|
|
229
|
+
"Think the idea through with the human from the context pack. Write nothing.",
|
|
230
|
+
"At the end, offer to do nothing, save an exploration, start a proposal, "
|
|
231
|
+
"or start a milestone.",
|
|
232
|
+
],
|
|
233
|
+
"commands": [
|
|
234
|
+
"wm context --for explore",
|
|
235
|
+
"wm new exploration <name>",
|
|
236
|
+
"wm new change <name>",
|
|
237
|
+
"wm new milestone <name>",
|
|
238
|
+
],
|
|
239
|
+
"unlocks": "A saved exploration, a proposal or a milestone, if the human asks for one.",
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _pick_change(record: Record, name: str | None) -> Change:
|
|
244
|
+
if name is not None:
|
|
245
|
+
return find_change(record, name)
|
|
246
|
+
if len(record.changes) == 1:
|
|
247
|
+
return next(iter(record.changes.values()))
|
|
248
|
+
active = ", ".join(sorted(record.changes)) or "none"
|
|
249
|
+
raise Refusal(
|
|
250
|
+
f"Say which change with --change <name>. Active changes: {active}."
|
|
251
|
+
if record.changes
|
|
252
|
+
else 'There is no active change. Create one with "wm new change <name>".'
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def instructions(record: Record, step: str | None, change_name: str | None) -> dict[str, Any]:
|
|
257
|
+
"""What to do at a step of a change; without a step, at the change's next step."""
|
|
258
|
+
if step == EXPLORE:
|
|
259
|
+
return _explore(record)
|
|
260
|
+
change = _pick_change(record, change_name)
|
|
261
|
+
state = state_of(record, change)
|
|
262
|
+
current = state.next_step
|
|
263
|
+
kind = StepKind(step) if step is not None else current.kind
|
|
264
|
+
|
|
265
|
+
ready = _RANK[kind] <= _RANK[current.kind]
|
|
266
|
+
reason = current.reason if kind is current.kind else ""
|
|
267
|
+
if kind is StepKind.DESIGN and change.short_path:
|
|
268
|
+
ready = False
|
|
269
|
+
reason = "This change is on the short path, which has no design."
|
|
270
|
+
elif not ready:
|
|
271
|
+
reason = (
|
|
272
|
+
f'The change is at "{current.kind.value}", which comes first. {current.reason}'.strip()
|
|
273
|
+
)
|
|
274
|
+
elif _RANK[kind] < _RANK[StepKind.ACCEPT] and state.acceptance is AcceptanceState.VALID:
|
|
275
|
+
reason = "The change is accepted: editing this artifact withdraws its acceptance."
|
|
276
|
+
|
|
277
|
+
outputs: list[dict[str, Any]] = []
|
|
278
|
+
read: list[str] = [_path(CHARTER_FILE), *_existing(record, change, PROPOSAL_FILE, TASKS_FILE)]
|
|
279
|
+
commands: list[str] = []
|
|
280
|
+
if _RANK[kind] <= _RANK[StepKind.TASKS]:
|
|
281
|
+
outputs, read, guidance = _drafting(record, change, kind)
|
|
282
|
+
else:
|
|
283
|
+
guidance, commands = _working(change, state, kind)
|
|
284
|
+
|
|
285
|
+
charter = record.charter
|
|
286
|
+
rules = ""
|
|
287
|
+
if charter and kind.value in set(Step):
|
|
288
|
+
rules = charter.rules.get(Step(kind.value), "")
|
|
289
|
+
return {
|
|
290
|
+
"schema": "wm.instructions",
|
|
291
|
+
"version": INSTRUCTIONS_VERSION,
|
|
292
|
+
"change": change.name,
|
|
293
|
+
"step": kind.value,
|
|
294
|
+
"item": current.item if kind is current.kind else None,
|
|
295
|
+
"ready": ready,
|
|
296
|
+
"reason": reason,
|
|
297
|
+
"outputs": outputs,
|
|
298
|
+
"rules": rules,
|
|
299
|
+
"context": charter.context if charter else "",
|
|
300
|
+
"read": read,
|
|
301
|
+
"guidance": guidance,
|
|
302
|
+
"commands": commands,
|
|
303
|
+
"unlocks": _UNLOCKS[kind],
|
|
304
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Installing and updating the files Waymark owns in a project's agent tool folders.
|
|
2
|
+
|
|
3
|
+
The skills are rendered once to ``.agents/skills/`` and each tool's adapter
|
|
4
|
+
adds its own copies and settings. Files are copied, never linked. Only files
|
|
5
|
+
Waymark owns are written; nothing else in a tool's folder is touched.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from waymark import adapters, assets
|
|
14
|
+
from waymark.record import git
|
|
15
|
+
from waymark.record.files import RecordFiles
|
|
16
|
+
from waymark.record.project import RECORD_DIR
|
|
17
|
+
from waymark.record.record import Record
|
|
18
|
+
from waymark.record.store import Transaction
|
|
19
|
+
from waymark.services import ci, githooks, migrations
|
|
20
|
+
from waymark.services.common import (
|
|
21
|
+
Done,
|
|
22
|
+
Refusal,
|
|
23
|
+
commit,
|
|
24
|
+
open_record,
|
|
25
|
+
repo_locations,
|
|
26
|
+
require_pinned,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
SHARED_SKILLS = ".agents/skills"
|
|
30
|
+
"""Where the skills are rendered once, for every tool that reads the shared folder."""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True)
|
|
34
|
+
class FileChange:
|
|
35
|
+
"""One file Waymark owns, and what installing did to it."""
|
|
36
|
+
|
|
37
|
+
path: str
|
|
38
|
+
status: str
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def require_tools(tools: tuple[str, ...]) -> None:
|
|
42
|
+
"""Refuse a tool that has no adapter."""
|
|
43
|
+
for tool in tools:
|
|
44
|
+
if tool not in adapters.names():
|
|
45
|
+
known = ", ".join(adapters.names())
|
|
46
|
+
raise Refusal(
|
|
47
|
+
f'"{tool}" is not an agent tool wm knows. Known tools: {known}. Fix the '
|
|
48
|
+
f'"agent_tools" list in {RECORD_DIR}/config.toml.'
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def integration_files(files: RecordFiles, tools: tuple[str, ...]) -> dict[str, str]:
|
|
53
|
+
"""Every file Waymark owns for the given tools, with its full text."""
|
|
54
|
+
require_tools(tools)
|
|
55
|
+
rendered = {
|
|
56
|
+
f"{SHARED_SKILLS}/{name}/{assets.SKILL_FILE}": assets.skill(name) for name in assets.SKILLS
|
|
57
|
+
}
|
|
58
|
+
for tool in tools:
|
|
59
|
+
adapter = adapters.get(tool)
|
|
60
|
+
existing = {
|
|
61
|
+
path: files.read(path, []) if files.is_file(path) else None for path in adapter.reads
|
|
62
|
+
}
|
|
63
|
+
try:
|
|
64
|
+
rendered.update(adapter.files(existing))
|
|
65
|
+
except (ValueError, json.JSONDecodeError) as error:
|
|
66
|
+
raise Refusal(
|
|
67
|
+
f"{adapter.reads[0]} can't be read as settings ({error}), so wm can't add its "
|
|
68
|
+
"part without risking yours. Fix the file, then run this command again."
|
|
69
|
+
) from error
|
|
70
|
+
return rendered
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def stage(transaction: Transaction, files: RecordFiles, tools: tuple[str, ...]) -> list[FileChange]:
|
|
74
|
+
"""Stage the integration files, and say which are new, changed or already current."""
|
|
75
|
+
changes: list[FileChange] = []
|
|
76
|
+
for path, text in sorted(integration_files(files, tools).items()):
|
|
77
|
+
current = files.read(path, []) if files.is_file(path) else None
|
|
78
|
+
if current == text:
|
|
79
|
+
changes.append(FileChange(path, "unchanged"))
|
|
80
|
+
else:
|
|
81
|
+
transaction.write(path, text)
|
|
82
|
+
changes.append(FileChange(path, "created" if current is None else "updated"))
|
|
83
|
+
return changes
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def local_files(
|
|
87
|
+
files: RecordFiles, tools: tuple[str, ...], folders: Sequence[Path]
|
|
88
|
+
) -> dict[str, str]:
|
|
89
|
+
"""The per-machine files that attach an atlas's code repos to each tool's sessions."""
|
|
90
|
+
require_tools(tools)
|
|
91
|
+
rendered: dict[str, str] = {}
|
|
92
|
+
for tool in tools:
|
|
93
|
+
adapter = adapters.get(tool)
|
|
94
|
+
existing = {
|
|
95
|
+
path: files.read(path, []) if files.is_file(path) else None
|
|
96
|
+
for path in adapter.local_reads
|
|
97
|
+
}
|
|
98
|
+
try:
|
|
99
|
+
rendered.update(adapter.local_files(existing, folders))
|
|
100
|
+
except (ValueError, json.JSONDecodeError) as error:
|
|
101
|
+
raise Refusal(
|
|
102
|
+
f"{adapter.local_reads[0]} can't be read as settings ({error}), so wm can't "
|
|
103
|
+
"attach the code repos without risking yours. Fix the file, then run this "
|
|
104
|
+
"command again."
|
|
105
|
+
) from error
|
|
106
|
+
return rendered
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def stage_local(
|
|
110
|
+
transaction: Transaction, files: RecordFiles, tools: tuple[str, ...], folders: Sequence[Path]
|
|
111
|
+
) -> list[FileChange]:
|
|
112
|
+
"""Stage the per-machine files, and say which are new, changed or already current."""
|
|
113
|
+
changes: list[FileChange] = []
|
|
114
|
+
for path, text in sorted(local_files(files, tools, folders).items()):
|
|
115
|
+
current = files.read(path, []) if files.is_file(path) else None
|
|
116
|
+
if current == text:
|
|
117
|
+
changes.append(FileChange(path, "unchanged"))
|
|
118
|
+
else:
|
|
119
|
+
transaction.write(path, text)
|
|
120
|
+
changes.append(FileChange(path, "created" if current is None else "updated"))
|
|
121
|
+
return changes
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def keep_local(root: Path, changes: Sequence[FileChange]) -> None:
|
|
125
|
+
"""Keep per-machine files out of the project's commits, through the clone's exclude file."""
|
|
126
|
+
for change in changes:
|
|
127
|
+
if not git.is_ignored(root, change.path):
|
|
128
|
+
git.exclude(root, change.path)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def located_folders(record: Record) -> list[Path]:
|
|
132
|
+
"""The folders of the atlas's code repos found on this machine, in settings order."""
|
|
133
|
+
return [
|
|
134
|
+
location.folder
|
|
135
|
+
for location in repo_locations(record).values()
|
|
136
|
+
if location.folder is not None
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def update(start: Path) -> Done:
|
|
141
|
+
"""Migrate the record to this version's format and regenerate the files Waymark owns."""
|
|
142
|
+
record = open_record(start)
|
|
143
|
+
require_pinned(record)
|
|
144
|
+
migrated = migrations.migrate(record.files)
|
|
145
|
+
record = open_record(start, writing=True)
|
|
146
|
+
assert record.config is not None
|
|
147
|
+
project_files = RecordFiles(record.project.root)
|
|
148
|
+
transaction = Transaction(project_files)
|
|
149
|
+
changes = stage(transaction, project_files, record.config.agent_tools)
|
|
150
|
+
local = stage_local(
|
|
151
|
+
transaction, project_files, record.config.agent_tools, located_folders(record)
|
|
152
|
+
)
|
|
153
|
+
workflow = ci.stage_workflow(transaction, project_files, only_if_present=True)
|
|
154
|
+
commit(transaction)
|
|
155
|
+
keep_local(record.project.root, local)
|
|
156
|
+
changes += local
|
|
157
|
+
if workflow != "absent":
|
|
158
|
+
changes.append(FileChange(ci.WORKFLOW, workflow))
|
|
159
|
+
hooks = githooks.install(record.project.root)
|
|
160
|
+
lines = [f"Migrated the record: {step}." for step in migrated]
|
|
161
|
+
lines += [
|
|
162
|
+
f"{change.status}: {change.path}" for change in changes if change.status != "unchanged"
|
|
163
|
+
]
|
|
164
|
+
lines += hooks
|
|
165
|
+
untouched = sum(1 for change in changes if change.status == "unchanged")
|
|
166
|
+
if not migrated and not hooks and untouched == len(changes):
|
|
167
|
+
lines.append("Everything is up to date.")
|
|
168
|
+
else:
|
|
169
|
+
lines.append(f"{untouched} file(s) already current. Review the changes and commit them.")
|
|
170
|
+
return Done("\n".join(lines), transaction.paths)
|