@tothemax/tasking 0.0.0-stage → 0.6.16

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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +121 -2
  3. package/README.zh-CN.md +122 -0
  4. package/assets/skills/install-glab/SKILL.md +70 -0
  5. package/assets/skills/land/SKILL.md +63 -0
  6. package/assets/skills/land/land_watch.py +312 -0
  7. package/assets/skills/openspec-archive-change/SKILL.md +114 -0
  8. package/assets/skills/opsx-grill-with-docs/SKILL.md +193 -0
  9. package/assets/skills/opsx-implement/SKILL.md +258 -0
  10. package/assets/skills/opsx-propose-with-tdd/SKILL.md +271 -0
  11. package/assets/workflows/WORKFLOW.code-mr.en.md.example +345 -0
  12. package/assets/workflows/WORKFLOW.code-mr.md.example +339 -0
  13. package/assets/workflows/WORKFLOW.feishu-direct.en.md.example +267 -0
  14. package/assets/workflows/WORKFLOW.feishu-direct.md.example +258 -0
  15. package/assets/workflows/WORKFLOW.grill-openspec.en.md.example +362 -0
  16. package/assets/workflows/WORKFLOW.grill-openspec.md.example +356 -0
  17. package/assets/workflows/WORKFLOW.minimal.en.md.example +296 -0
  18. package/assets/workflows/WORKFLOW.minimal.md.example +289 -0
  19. package/dist/adapters/feishu/events.d.ts +55 -0
  20. package/dist/adapters/feishu/events.d.ts.map +1 -0
  21. package/dist/adapters/feishu/events.js +184 -0
  22. package/dist/adapters/feishu/events.js.map +1 -0
  23. package/dist/adapters/feishu/index.d.ts +2 -0
  24. package/dist/adapters/feishu/index.d.ts.map +1 -0
  25. package/dist/adapters/feishu/index.js +2 -0
  26. package/dist/adapters/feishu/index.js.map +1 -0
  27. package/dist/adapters/feishu/probe.d.ts +31 -0
  28. package/dist/adapters/feishu/probe.d.ts.map +1 -0
  29. package/dist/adapters/feishu/probe.js +179 -0
  30. package/dist/adapters/feishu/probe.js.map +1 -0
  31. package/dist/adapters/feishu/source.d.ts +124 -0
  32. package/dist/adapters/feishu/source.d.ts.map +1 -0
  33. package/dist/adapters/feishu/source.js +715 -0
  34. package/dist/adapters/feishu/source.js.map +1 -0
  35. package/dist/adapters/jira/index.d.ts +2 -0
  36. package/dist/adapters/jira/index.d.ts.map +1 -0
  37. package/dist/adapters/jira/index.js +2 -0
  38. package/dist/adapters/jira/index.js.map +1 -0
  39. package/dist/adapters/jira/tracker.d.ts +63 -0
  40. package/dist/adapters/jira/tracker.d.ts.map +1 -0
  41. package/dist/adapters/jira/tracker.js +402 -0
  42. package/dist/adapters/jira/tracker.js.map +1 -0
  43. package/dist/bridge/binding-store.d.ts +93 -0
  44. package/dist/bridge/binding-store.d.ts.map +1 -0
  45. package/dist/bridge/binding-store.js +365 -0
  46. package/dist/bridge/binding-store.js.map +1 -0
  47. package/dist/bridge/commands.d.ts +45 -0
  48. package/dist/bridge/commands.d.ts.map +1 -0
  49. package/dist/bridge/commands.js +197 -0
  50. package/dist/bridge/commands.js.map +1 -0
  51. package/dist/bridge/comment-bridge.d.ts +116 -0
  52. package/dist/bridge/comment-bridge.d.ts.map +1 -0
  53. package/dist/bridge/comment-bridge.js +1473 -0
  54. package/dist/bridge/comment-bridge.js.map +1 -0
  55. package/dist/cli/daemon-info.d.ts +17 -0
  56. package/dist/cli/daemon-info.d.ts.map +1 -0
  57. package/dist/cli/daemon-info.js +64 -0
  58. package/dist/cli/daemon-info.js.map +1 -0
  59. package/dist/cli/daemon.d.ts +27 -0
  60. package/dist/cli/daemon.d.ts.map +1 -0
  61. package/dist/cli/daemon.js +77 -0
  62. package/dist/cli/daemon.js.map +1 -0
  63. package/dist/cli/doctor.d.ts +7 -0
  64. package/dist/cli/doctor.d.ts.map +1 -0
  65. package/dist/cli/doctor.js +156 -0
  66. package/dist/cli/doctor.js.map +1 -0
  67. package/dist/cli/event-channel.d.ts +16 -0
  68. package/dist/cli/event-channel.d.ts.map +1 -0
  69. package/dist/cli/event-channel.js +51 -0
  70. package/dist/cli/event-channel.js.map +1 -0
  71. package/dist/cli/help.d.ts +3 -0
  72. package/dist/cli/help.d.ts.map +1 -0
  73. package/dist/cli/help.js +155 -0
  74. package/dist/cli/help.js.map +1 -0
  75. package/dist/cli/index.d.ts +3 -0
  76. package/dist/cli/index.d.ts.map +1 -0
  77. package/dist/cli/index.js +774 -0
  78. package/dist/cli/index.js.map +1 -0
  79. package/dist/cli/init.d.ts +64 -0
  80. package/dist/cli/init.d.ts.map +1 -0
  81. package/dist/cli/init.js +1296 -0
  82. package/dist/cli/init.js.map +1 -0
  83. package/dist/cli/instance-lock.d.ts +13 -0
  84. package/dist/cli/instance-lock.d.ts.map +1 -0
  85. package/dist/cli/instance-lock.js +53 -0
  86. package/dist/cli/instance-lock.js.map +1 -0
  87. package/dist/cli/prompts.d.ts +13 -0
  88. package/dist/cli/prompts.d.ts.map +1 -0
  89. package/dist/cli/prompts.js +26 -0
  90. package/dist/cli/prompts.js.map +1 -0
  91. package/dist/cli/style.d.ts +26 -0
  92. package/dist/cli/style.d.ts.map +1 -0
  93. package/dist/cli/style.js +58 -0
  94. package/dist/cli/style.js.map +1 -0
  95. package/dist/cli/tui-helpers.d.ts +5 -0
  96. package/dist/cli/tui-helpers.d.ts.map +1 -0
  97. package/dist/cli/tui-helpers.js +124 -0
  98. package/dist/cli/tui-helpers.js.map +1 -0
  99. package/dist/cli/workflow-path.d.ts +12 -0
  100. package/dist/cli/workflow-path.d.ts.map +1 -0
  101. package/dist/cli/workflow-path.js +37 -0
  102. package/dist/cli/workflow-path.js.map +1 -0
  103. package/dist/config/config-types.d.ts +180 -0
  104. package/dist/config/config-types.d.ts.map +1 -0
  105. package/dist/config/config-types.js +71 -0
  106. package/dist/config/config-types.js.map +1 -0
  107. package/dist/config/dotenv.d.ts +2 -0
  108. package/dist/config/dotenv.d.ts.map +1 -0
  109. package/dist/config/dotenv.js +10 -0
  110. package/dist/config/dotenv.js.map +1 -0
  111. package/dist/config/index.d.ts +6 -0
  112. package/dist/config/index.d.ts.map +1 -0
  113. package/dist/config/index.js +6 -0
  114. package/dist/config/index.js.map +1 -0
  115. package/dist/config/loader.d.ts +5 -0
  116. package/dist/config/loader.d.ts.map +1 -0
  117. package/dist/config/loader.js +304 -0
  118. package/dist/config/loader.js.map +1 -0
  119. package/dist/config/manager.d.ts +31 -0
  120. package/dist/config/manager.d.ts.map +1 -0
  121. package/dist/config/manager.js +110 -0
  122. package/dist/config/manager.js.map +1 -0
  123. package/dist/config/resolver.d.ts +6 -0
  124. package/dist/config/resolver.d.ts.map +1 -0
  125. package/dist/config/resolver.js +267 -0
  126. package/dist/config/resolver.js.map +1 -0
  127. package/dist/config/validator.d.ts +9 -0
  128. package/dist/config/validator.d.ts.map +1 -0
  129. package/dist/config/validator.js +70 -0
  130. package/dist/config/validator.js.map +1 -0
  131. package/dist/direct/card.d.ts +49 -0
  132. package/dist/direct/card.d.ts.map +1 -0
  133. package/dist/direct/card.js +274 -0
  134. package/dist/direct/card.js.map +1 -0
  135. package/dist/direct/command.d.ts +12 -0
  136. package/dist/direct/command.d.ts.map +1 -0
  137. package/dist/direct/command.js +23 -0
  138. package/dist/direct/command.js.map +1 -0
  139. package/dist/direct/manager.d.ts +159 -0
  140. package/dist/direct/manager.d.ts.map +1 -0
  141. package/dist/direct/manager.js +1862 -0
  142. package/dist/direct/manager.js.map +1 -0
  143. package/dist/mcp/inject.d.ts +5 -0
  144. package/dist/mcp/inject.d.ts.map +1 -0
  145. package/dist/mcp/inject.js +51 -0
  146. package/dist/mcp/inject.js.map +1 -0
  147. package/dist/mcp/jira-server.d.ts +29 -0
  148. package/dist/mcp/jira-server.d.ts.map +1 -0
  149. package/dist/mcp/jira-server.js +288 -0
  150. package/dist/mcp/jira-server.js.map +1 -0
  151. package/dist/observability/activity-store.d.ts +29 -0
  152. package/dist/observability/activity-store.d.ts.map +1 -0
  153. package/dist/observability/activity-store.js +32 -0
  154. package/dist/observability/activity-store.js.map +1 -0
  155. package/dist/observability/config-view.d.ts +19 -0
  156. package/dist/observability/config-view.d.ts.map +1 -0
  157. package/dist/observability/config-view.js +61 -0
  158. package/dist/observability/config-view.js.map +1 -0
  159. package/dist/observability/http-dashboard.d.ts +36 -0
  160. package/dist/observability/http-dashboard.d.ts.map +1 -0
  161. package/dist/observability/http-dashboard.js +297 -0
  162. package/dist/observability/http-dashboard.js.map +1 -0
  163. package/dist/observability/log-buffer.d.ts +21 -0
  164. package/dist/observability/log-buffer.d.ts.map +1 -0
  165. package/dist/observability/log-buffer.js +69 -0
  166. package/dist/observability/log-buffer.js.map +1 -0
  167. package/dist/observability/logger.d.ts +37 -0
  168. package/dist/observability/logger.d.ts.map +1 -0
  169. package/dist/observability/logger.js +114 -0
  170. package/dist/observability/logger.js.map +1 -0
  171. package/dist/observability/snapshot.d.ts +11 -0
  172. package/dist/observability/snapshot.d.ts.map +1 -0
  173. package/dist/observability/snapshot.js +59 -0
  174. package/dist/observability/snapshot.js.map +1 -0
  175. package/dist/observability/terminal-dashboard.d.ts +155 -0
  176. package/dist/observability/terminal-dashboard.d.ts.map +1 -0
  177. package/dist/observability/terminal-dashboard.js +1598 -0
  178. package/dist/observability/terminal-dashboard.js.map +1 -0
  179. package/dist/observability/wrap.d.ts +4 -0
  180. package/dist/observability/wrap.d.ts.map +1 -0
  181. package/dist/observability/wrap.js +80 -0
  182. package/dist/observability/wrap.js.map +1 -0
  183. package/dist/scheduler/index.d.ts +2 -0
  184. package/dist/scheduler/index.d.ts.map +1 -0
  185. package/dist/scheduler/index.js +2 -0
  186. package/dist/scheduler/index.js.map +1 -0
  187. package/dist/scheduler/scheduler.d.ts +52 -0
  188. package/dist/scheduler/scheduler.d.ts.map +1 -0
  189. package/dist/scheduler/scheduler.js +535 -0
  190. package/dist/scheduler/scheduler.js.map +1 -0
  191. package/dist/shared/agent-resolver.d.ts +11 -0
  192. package/dist/shared/agent-resolver.d.ts.map +1 -0
  193. package/dist/shared/agent-resolver.js +20 -0
  194. package/dist/shared/agent-resolver.js.map +1 -0
  195. package/dist/shared/errors.d.ts +14 -0
  196. package/dist/shared/errors.d.ts.map +1 -0
  197. package/dist/shared/errors.js +24 -0
  198. package/dist/shared/errors.js.map +1 -0
  199. package/dist/shared/index.d.ts +4 -0
  200. package/dist/shared/index.d.ts.map +1 -0
  201. package/dist/shared/index.js +4 -0
  202. package/dist/shared/index.js.map +1 -0
  203. package/dist/shared/info-card.d.ts +24 -0
  204. package/dist/shared/info-card.d.ts.map +1 -0
  205. package/dist/shared/info-card.js +46 -0
  206. package/dist/shared/info-card.js.map +1 -0
  207. package/dist/shared/types.d.ts +148 -0
  208. package/dist/shared/types.d.ts.map +1 -0
  209. package/dist/shared/types.js +15 -0
  210. package/dist/shared/types.js.map +1 -0
  211. package/dist/translate/card.d.ts +2 -0
  212. package/dist/translate/card.d.ts.map +1 -0
  213. package/dist/translate/card.js +17 -0
  214. package/dist/translate/card.js.map +1 -0
  215. package/dist/translate/dict.d.ts +7 -0
  216. package/dist/translate/dict.d.ts.map +1 -0
  217. package/dist/translate/dict.js +895 -0
  218. package/dist/translate/dict.js.map +1 -0
  219. package/dist/translate/locale.d.ts +8 -0
  220. package/dist/translate/locale.d.ts.map +1 -0
  221. package/dist/translate/locale.js +75 -0
  222. package/dist/translate/locale.js.map +1 -0
  223. package/dist/translate/normalize.d.ts +4 -0
  224. package/dist/translate/normalize.d.ts.map +1 -0
  225. package/dist/translate/normalize.js +38 -0
  226. package/dist/translate/normalize.js.map +1 -0
  227. package/dist/translate/output.d.ts +3 -0
  228. package/dist/translate/output.d.ts.map +1 -0
  229. package/dist/translate/output.js +16 -0
  230. package/dist/translate/output.js.map +1 -0
  231. package/dist/worker/prompt.d.ts +11 -0
  232. package/dist/worker/prompt.d.ts.map +1 -0
  233. package/dist/worker/prompt.js +153 -0
  234. package/dist/worker/prompt.js.map +1 -0
  235. package/dist/worker/runner.d.ts +101 -0
  236. package/dist/worker/runner.d.ts.map +1 -0
  237. package/dist/worker/runner.js +448 -0
  238. package/dist/worker/runner.js.map +1 -0
  239. package/dist/workspace/index.d.ts +2 -0
  240. package/dist/workspace/index.d.ts.map +1 -0
  241. package/dist/workspace/index.js +2 -0
  242. package/dist/workspace/index.js.map +1 -0
  243. package/dist/workspace/manager.d.ts +37 -0
  244. package/dist/workspace/manager.d.ts.map +1 -0
  245. package/dist/workspace/manager.js +157 -0
  246. package/dist/workspace/manager.js.map +1 -0
  247. package/package.json +70 -4
@@ -0,0 +1,312 @@
1
+ #!/usr/bin/env python3
2
+ """GitLab MR watch helper for the land skill.
3
+
4
+ Monitors CI pipelines, review discussions, and MR head changes in parallel.
5
+ Exits with a code indicating the action the agent should take.
6
+
7
+ Exit codes:
8
+ 0: CI green, no outstanding review → merge
9
+ 2: Review comments detected → address feedback
10
+ 3: CI checks failed → fix and re-run
11
+ 4: MR head updated → pull/amend/force-push to retrigger CI
12
+ 5: Merge conflicts → resolve before proceeding
13
+ """
14
+ import asyncio
15
+ import json
16
+ import random
17
+ import re
18
+ from dataclasses import dataclass
19
+ from datetime import datetime
20
+ from typing import Any
21
+
22
+ POLL_SECONDS = 10
23
+ CHECKS_APPEAR_TIMEOUT_SECONDS = 120
24
+ MAX_GLAB_RETRIES = 5
25
+ BASE_GLAB_BACKOFF_SECONDS = 2
26
+
27
+
28
+ @dataclass
29
+ class MrInfo:
30
+ number: int
31
+ iid: int
32
+ project_id: int
33
+ head_sha: str
34
+ merge_status: str | None
35
+ has_conflicts: bool
36
+
37
+
38
+ class RateLimitError(RuntimeError):
39
+ pass
40
+
41
+
42
+ def is_rate_limit_error(error: str) -> bool:
43
+ return "HTTP 429" in error or "rate limit" in error.lower()
44
+
45
+
46
+ async def run_glab(*args: str) -> str:
47
+ max_delay = BASE_GLAB_BACKOFF_SECONDS * (2 ** (MAX_GLAB_RETRIES - 1))
48
+ delay_seconds = BASE_GLAB_BACKOFF_SECONDS
49
+ last_error = "glab command failed"
50
+ for attempt in range(1, MAX_GLAB_RETRIES + 1):
51
+ proc = await asyncio.create_subprocess_exec(
52
+ "glab",
53
+ *args,
54
+ stdout=asyncio.subprocess.PIPE,
55
+ stderr=asyncio.subprocess.PIPE,
56
+ )
57
+ stdout, stderr = await proc.communicate()
58
+ if proc.returncode == 0:
59
+ return stdout.decode()
60
+ error = stderr.decode().strip() or "glab command failed"
61
+ if not is_rate_limit_error(error):
62
+ raise RuntimeError(error)
63
+ last_error = error
64
+ if attempt >= MAX_GLAB_RETRIES:
65
+ break
66
+ jitter = random.uniform(0, delay_seconds)
67
+ await asyncio.sleep(min(delay_seconds + jitter, max_delay))
68
+ delay_seconds = min(delay_seconds * 2, max_delay)
69
+ raise RateLimitError(last_error)
70
+
71
+
72
+ async def get_mr_info() -> MrInfo:
73
+ data = await run_glab("mr", "view", "--output", "json")
74
+ parsed = json.loads(data)
75
+ return MrInfo(
76
+ number=parsed.get("id", 0),
77
+ iid=parsed.get("iid", 0),
78
+ project_id=parsed.get("project_id", 0),
79
+ head_sha=parsed.get("sha", ""),
80
+ merge_status=parsed.get("detailed_merge_status") or parsed.get("merge_status"),
81
+ has_conflicts=parsed.get("has_conflicts", False),
82
+ )
83
+
84
+
85
+ async def get_paginated_list(endpoint: str) -> list[dict[str, Any]]:
86
+ page = 1
87
+ items: list[dict[str, Any]] = []
88
+ while True:
89
+ data = await run_glab("api", endpoint, "-f", f"per_page=100", "-f", f"page={page}")
90
+ batch = json.loads(data)
91
+ if not batch:
92
+ break
93
+ items.extend(batch)
94
+ page += 1
95
+ return items
96
+
97
+
98
+ async def get_discussions(mr_iid: int) -> list[dict[str, Any]]:
99
+ return await get_paginated_list(f"projects/:id/merge_requests/{mr_iid}/discussions")
100
+
101
+
102
+ async def get_pipelines(mr_iid: int) -> list[dict[str, Any]]:
103
+ return await get_paginated_list(f"projects/:id/merge_requests/{mr_iid}/pipelines")
104
+
105
+
106
+ async def get_approvals(mr_iid: int) -> dict[str, Any]:
107
+ data = await run_glab("api", f"projects/:id/merge_requests/{mr_iid}/approvals")
108
+ return json.loads(data)
109
+
110
+
111
+ def parse_time(value: str) -> datetime:
112
+ normalized = value.replace("Z", "+00:00")
113
+ return datetime.fromisoformat(normalized)
114
+
115
+
116
+ CONTROL_CHARS_RE = re.compile(r"[\x00-\x08\x0b-\x1f\x7f-\x9f]")
117
+
118
+
119
+ def sanitize_terminal_output(value: str) -> str:
120
+ return CONTROL_CHARS_RE.sub("", value)
121
+
122
+
123
+ def pipeline_timestamp(pipeline: dict[str, Any]) -> datetime | None:
124
+ for key in ("finished_at", "started_at", "created_at"):
125
+ value = pipeline.get(key)
126
+ if value:
127
+ return parse_time(value)
128
+ return None
129
+
130
+
131
+ def dedupe_pipelines(pipelines: list[dict[str, Any]]) -> list[dict[str, Any]]:
132
+ latest_by_name: dict[str, dict[str, Any]] = {}
133
+ for pipeline in pipelines:
134
+ name = pipeline.get("name", pipeline.get("id", "unknown"))
135
+ timestamp = pipeline_timestamp(pipeline)
136
+ if name not in latest_by_name:
137
+ latest_by_name[name] = pipeline
138
+ continue
139
+ existing = latest_by_name[name]
140
+ existing_timestamp = pipeline_timestamp(existing)
141
+ if timestamp is None:
142
+ continue
143
+ if existing_timestamp is None or timestamp > existing_timestamp:
144
+ latest_by_name[name] = pipeline
145
+ return list(latest_by_name.values())
146
+
147
+
148
+ def summarize_pipelines(pipelines: list[dict[str, Any]]) -> tuple[bool, bool, list[str]]:
149
+ if not pipelines:
150
+ return True, False, ["no pipelines reported"]
151
+ pipelines = dedupe_pipelines(pipelines)
152
+ pending = False
153
+ failed = False
154
+ failures: list[str] = []
155
+ for pipeline in pipelines:
156
+ status = pipeline.get("status")
157
+ name = pipeline.get("name", pipeline.get("id", "unknown"))
158
+ if status not in ("success", "skipped"):
159
+ pending = True
160
+ if status not in ("success", "skipped", "running", "pending"):
161
+ failed = True
162
+ failures.append(f"{name}: {status}")
163
+ return pending, failed, failures
164
+
165
+
166
+ def comment_time(comment: dict[str, Any]) -> datetime | None:
167
+ timestamp = comment.get("updated_at") or comment.get("created_at")
168
+ if not timestamp:
169
+ return None
170
+ return parse_time(timestamp)
171
+
172
+
173
+ def is_bot_user(user: dict[str, Any]) -> bool:
174
+ login = user.get("username") or ""
175
+ if user.get("type") == "Bot":
176
+ return True
177
+ return login.endswith("[bot]") or login.endswith("_bot")
178
+
179
+
180
+ def filter_human_discussions(
181
+ discussions: list[dict[str, Any]],
182
+ latest_agent_reply_at: datetime | None,
183
+ ) -> list[dict[str, Any]]:
184
+ filtered: list[dict[str, Any]] = []
185
+ for discussion in discussions:
186
+ notes = discussion.get("notes", [])
187
+ if not notes:
188
+ continue
189
+ for note in notes:
190
+ user = note.get("author", {})
191
+ if is_bot_user(user):
192
+ continue
193
+ body = (note.get("body") or "").strip()
194
+ if not body:
195
+ continue
196
+ created_time = comment_time(note)
197
+ if (
198
+ latest_agent_reply_at is not None
199
+ and created_time is not None
200
+ and created_time <= latest_agent_reply_at
201
+ ):
202
+ continue
203
+ filtered.append(note)
204
+ return filtered
205
+
206
+
207
+ def latest_agent_reply_time(discussions: list[dict[str, Any]]) -> datetime | None:
208
+ latest: datetime | None = None
209
+ for discussion in discussions:
210
+ notes = discussion.get("notes", [])
211
+ for note in notes:
212
+ user = note.get("author", {})
213
+ if is_bot_user(user):
214
+ continue
215
+ body = (note.get("body") or "").strip()
216
+ created_time = comment_time(note)
217
+ if created_time is None:
218
+ continue
219
+ if latest is None or created_time > latest:
220
+ latest = created_time
221
+ return latest
222
+
223
+
224
+ def is_merge_conflicting(mr: MrInfo) -> bool:
225
+ return mr.has_conflicts or mr.merge_status in ("conflict", "cannot_merge")
226
+
227
+
228
+ async def wait_for_review(mr_iid: int, checks_done: asyncio.Event) -> None:
229
+ print("Waiting for review feedback...", flush=True)
230
+ while True:
231
+ discussions = await get_discussions(mr_iid)
232
+ latest_reply = latest_agent_reply_time(discussions)
233
+ human_comments = filter_human_discussions(discussions, latest_reply)
234
+ if human_comments:
235
+ print("Review comments detected. Address before merge.")
236
+ for comment in human_comments:
237
+ body = sanitize_terminal_output(comment.get("body") or "").strip()
238
+ if body:
239
+ print(f"- {body}")
240
+ raise SystemExit(2)
241
+ if checks_done.is_set():
242
+ return
243
+ await asyncio.sleep(POLL_SECONDS)
244
+
245
+
246
+ async def wait_for_checks(mr_iid: int, checks_done: asyncio.Event) -> None:
247
+ print("Waiting for CI pipelines...", flush=True)
248
+ empty_seconds = 0
249
+ while True:
250
+ pipelines = await get_pipelines(mr_iid)
251
+ if not pipelines:
252
+ empty_seconds += POLL_SECONDS
253
+ if empty_seconds >= CHECKS_APPEAR_TIMEOUT_SECONDS:
254
+ print("No pipelines detected after 120s; check CI configuration")
255
+ raise SystemExit(3)
256
+ await asyncio.sleep(POLL_SECONDS)
257
+ continue
258
+ empty_seconds = 0
259
+ pending, failed, failures = summarize_pipelines(pipelines)
260
+ if failed:
261
+ print("Pipelines failed:")
262
+ for failure in failures:
263
+ print(f"- {failure}")
264
+ raise SystemExit(3)
265
+ if not pending:
266
+ print("Pipelines passed")
267
+ checks_done.set()
268
+ return
269
+ await asyncio.sleep(POLL_SECONDS)
270
+
271
+
272
+ async def watch_mr() -> None:
273
+ mr = await get_mr_info()
274
+ if is_merge_conflicting(mr):
275
+ print("MR has merge conflicts. Resolve/rebase against main and push before running land_watch again.")
276
+ raise SystemExit(5)
277
+ head_sha = mr.head_sha
278
+ checks_done = asyncio.Event()
279
+ review_task = asyncio.create_task(wait_for_review(mr.iid, checks_done))
280
+ checks_task = asyncio.create_task(wait_for_checks(mr.iid, checks_done))
281
+
282
+ async def head_monitor() -> None:
283
+ while True:
284
+ current = await get_mr_info()
285
+ if is_merge_conflicting(current):
286
+ print("MR has merge conflicts. Resolve/rebase against main and push before running land_watch again.")
287
+ raise SystemExit(5)
288
+ if current.head_sha != head_sha:
289
+ print("MR head updated; pull/amend/force-push to retrigger CI")
290
+ raise SystemExit(4)
291
+ await asyncio.sleep(POLL_SECONDS)
292
+
293
+ monitor_task = asyncio.create_task(head_monitor())
294
+ success_task = asyncio.gather(review_task, checks_task)
295
+
296
+ done, pending = await asyncio.wait(
297
+ [monitor_task, success_task],
298
+ return_when=asyncio.FIRST_COMPLETED,
299
+ )
300
+ for task in pending:
301
+ task.cancel()
302
+ for task in done:
303
+ exc = task.exception()
304
+ if exc:
305
+ raise exc
306
+
307
+
308
+ if __name__ == "__main__":
309
+ try:
310
+ asyncio.run(watch_mr())
311
+ except SystemExit as exc:
312
+ raise SystemExit(exc.code) from None
@@ -0,0 +1,114 @@
1
+ ---
2
+ name: openspec-archive-change
3
+ description: Archive a completed change in the experimental workflow. Use when the user wants to finalize and archive a change after implementation is complete.
4
+ license: MIT
5
+ compatibility: Requires openspec CLI.
6
+ metadata:
7
+ author: openspec
8
+ version: "1.0"
9
+ generatedBy: "1.3.1"
10
+ ---
11
+
12
+ Archive a completed change in the experimental workflow.
13
+
14
+ **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
15
+
16
+ **Steps**
17
+
18
+ 1. **If no change name provided, prompt for selection**
19
+
20
+ Run `openspec list --json` to get available changes. Use the **AskUserQuestion tool** to let the user select.
21
+
22
+ Show only active changes (not already archived).
23
+ Include the schema used for each change if available.
24
+
25
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
26
+
27
+ 2. **Check artifact completion status**
28
+
29
+ Run `openspec status --change "<name>" --json` to check artifact completion.
30
+
31
+ Parse the JSON to understand:
32
+ - `schemaName`: The workflow being used
33
+ - `artifacts`: List of artifacts with their status (`done` or other)
34
+
35
+ **If any artifacts are not `done`:**
36
+ - Display warning listing incomplete artifacts
37
+ - Use **AskUserQuestion tool** to confirm user wants to proceed
38
+ - Proceed if user confirms
39
+
40
+ 3. **Check task completion status**
41
+
42
+ Read the tasks file (typically `tasks.md`) to check for incomplete tasks.
43
+
44
+ Count tasks marked with `- [ ]` (incomplete) vs `- [x]` (complete).
45
+
46
+ **If incomplete tasks found:**
47
+ - Display warning showing count of incomplete tasks
48
+ - Use **AskUserQuestion tool** to confirm user wants to proceed
49
+ - Proceed if user confirms
50
+
51
+ **If no tasks file exists:** Proceed without task-related warning.
52
+
53
+ 4. **Assess delta spec sync state**
54
+
55
+ Check for delta specs at `openspec/changes/<name>/specs/`. If none exist, proceed without sync prompt.
56
+
57
+ **If delta specs exist:**
58
+ - Compare each delta spec with its corresponding main spec at `openspec/specs/<capability>/spec.md`
59
+ - Determine what changes would be applied (adds, modifications, removals, renames)
60
+ - Show a combined summary before prompting
61
+
62
+ **Prompt options:**
63
+ - If changes needed: "Sync now (recommended)", "Archive without syncing"
64
+ - If already synced: "Archive now", "Sync anyway", "Cancel"
65
+
66
+ If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
67
+
68
+ 5. **Perform the archive**
69
+
70
+ Create the archive directory if it doesn't exist:
71
+ ```bash
72
+ mkdir -p openspec/changes/archive
73
+ ```
74
+
75
+ Generate target name using current date: `YYYY-MM-DD-<change-name>`
76
+
77
+ **Check if target already exists:**
78
+ - If yes: Fail with error, suggest renaming existing archive or using different date
79
+ - If no: Move the change directory to archive
80
+
81
+ ```bash
82
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
83
+ ```
84
+
85
+ 6. **Display summary**
86
+
87
+ Show archive completion summary including:
88
+ - Change name
89
+ - Schema that was used
90
+ - Archive location
91
+ - Whether specs were synced (if applicable)
92
+ - Note about any warnings (incomplete artifacts/tasks)
93
+
94
+ **Output On Success**
95
+
96
+ ```
97
+ ## Archive Complete
98
+
99
+ **Change:** <change-name>
100
+ **Schema:** <schema-name>
101
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
102
+ **Specs:** ✓ Synced to main specs (or "No delta specs" or "Sync skipped")
103
+
104
+ All artifacts complete. All tasks complete.
105
+ ```
106
+
107
+ **Guardrails**
108
+ - Always prompt for change selection if not provided
109
+ - Use artifact graph (openspec status --json) for completion checking
110
+ - Don't block archive on warnings - just inform and confirm
111
+ - Preserve .openspec.yaml when moving to archive (it moves with the directory)
112
+ - Show clear summary of what happened
113
+ - If sync is requested, use openspec-sync-specs approach (agent-driven)
114
+ - If delta specs exist, always run the sync assessment and show the combined summary before prompting
@@ -0,0 +1,193 @@
1
+ ---
2
+ name: opsx-grill-with-docs
3
+ description: A relentless interview to sharpen a plan or design, which also creates docs (ADR's and glossary) as we go.
4
+ ---
5
+
6
+ Interview me relentlessly about every aspect of this until we reach a shared understanding. Walk down each branch of the decision tree, resolving dependencies between decisions one-by-one. For each question, provide your recommended answer.
7
+
8
+ Ask the questions one at a time, waiting for feedback on each question before continuing. Asking multiple questions at once is bewildering.
9
+
10
+ If a *fact* can be found by exploring the environment (filesystem, tools, etc.), look it up rather than asking me. The *decisions*, though, are mine — put each one to me and wait for my answer.
11
+
12
+ Do not act on it until I confirm we have reached a shared understanding.
13
+
14
+ When the proposal can be made(After reaching a consensus), run /opsx-propose-with-tdd.
15
+
16
+ # Domain Modeling
17
+
18
+ Actively build and sharpen the project's domain model as you design. This is the *active* discipline — challenging terms, inventing edge-case scenarios, and writing the glossary and decisions down the moment they crystallise. (Merely *reading* `CONTEXT.md` for vocabulary is not this skill — that's a one-line habit any skill can do. This skill is for when you're changing the model, not just consuming it.)
19
+
20
+ ## File structure
21
+
22
+ Most repos have a single context:
23
+
24
+ ```
25
+ /
26
+ ├── CONTEXT.md
27
+ ├── docs/
28
+ │ └── adr/
29
+ │ ├── 0001-event-sourced-orders.md
30
+ │ └── 0002-postgres-for-write-model.md
31
+ └── src/
32
+ ```
33
+
34
+ If a `CONTEXT-MAP.md` exists at the root, the repo has multiple contexts. The map points to where each one lives:
35
+
36
+ ```
37
+ /
38
+ ├── CONTEXT-MAP.md
39
+ ├── docs/
40
+ │ └── adr/ ← system-wide decisions
41
+ ├── src/
42
+ │ ├── ordering/
43
+ │ │ ├── CONTEXT.md
44
+ │ │ └── docs/adr/ ← context-specific decisions
45
+ │ └── billing/
46
+ │ ├── CONTEXT.md
47
+ │ └── docs/adr/
48
+ ```
49
+
50
+ Create files lazily — only when you have something to write. If no `CONTEXT.md` exists, create one when the first term is resolved. If no `docs/adr/` exists, create it when the first ADR is needed.
51
+
52
+ ## During the session
53
+
54
+ ### Challenge against the glossary
55
+
56
+ When the user uses a term that conflicts with the existing language in `CONTEXT.md`, call it out immediately. "Your glossary defines 'cancellation' as X, but you seem to mean Y — which is it?"
57
+
58
+ ### Sharpen fuzzy language
59
+
60
+ When the user uses vague or overloaded terms, propose a precise canonical term. "You're saying 'account' — do you mean the Customer or the User? Those are different things."
61
+
62
+ ### Discuss concrete scenarios
63
+
64
+ When domain relationships are being discussed, stress-test them with specific scenarios. Invent scenarios that probe edge cases and force the user to be precise about the boundaries between concepts.
65
+
66
+ ### Cross-reference with code
67
+
68
+ When the user states how something works, check whether the code agrees. If you find a contradiction, surface it: "Your code cancels entire Orders, but you just said partial cancellation is possible — which is right?"
69
+
70
+ ### Update CONTEXT.md inline
71
+
72
+ When a term is resolved, update `CONTEXT.md` right there. Don't batch these up — capture them as they happen. Use the format below.
73
+
74
+ `CONTEXT.md` should be totally devoid of implementation details. Do not treat `CONTEXT.md` as a spec, a scratch pad, or a repository for implementation decisions. It is a glossary and nothing else.
75
+
76
+ ### Offer ADRs sparingly
77
+
78
+ Only offer to create an ADR when all three are true:
79
+
80
+ 1. **Hard to reverse** — the cost of changing your mind later is meaningful
81
+ 2. **Surprising without context** — a future reader will wonder "why did they do it this way?"
82
+ 3. **The result of a real trade-off** — there were genuine alternatives and you picked one for specific reasons
83
+
84
+ If any of the three is missing, skip the ADR. Use the format below.
85
+
86
+ # CONTEXT.md Format
87
+
88
+ ## Structure
89
+
90
+ ```md
91
+ # {Context Name}
92
+
93
+ {One or two sentence description of what this context is and why it exists.}
94
+
95
+ ## Language
96
+
97
+ **Order**:
98
+ {A one or two sentence description of the term}
99
+ _Avoid_: Purchase, transaction
100
+
101
+ **Invoice**:
102
+ A request for payment sent to a customer after delivery.
103
+ _Avoid_: Bill, payment request
104
+
105
+ **Customer**:
106
+ A person or organization that places orders.
107
+ _Avoid_: Client, buyer, account
108
+ ```
109
+
110
+ ## Rules
111
+
112
+ - **Be opinionated.** When multiple words exist for the same concept, pick the best one and list the others under `_Avoid_`.
113
+ - **Keep definitions tight.** One or two sentences max. Define what it IS, not what it does.
114
+ - **Only include terms specific to this project's context.** General programming concepts (timeouts, error types, utility patterns) don't belong even if the project uses them extensively. Before adding a term, ask: is this a concept unique to this context, or a general programming concept? Only the former belongs.
115
+ - **Group terms under subheadings** when natural clusters emerge. If all terms belong to a single cohesive area, a flat list is fine.
116
+
117
+ ## Single vs multi-context repos
118
+
119
+ **Single context (most repos):** One `CONTEXT.md` at the repo root.
120
+
121
+ **Multiple contexts:** A `CONTEXT-MAP.md` at the repo root lists the contexts, where they live, and how they relate to each other:
122
+
123
+ ```md
124
+ # Context Map
125
+
126
+ ## Contexts
127
+
128
+ - [Ordering](./src/ordering/CONTEXT.md) — receives and tracks customer orders
129
+ - [Billing](./src/billing/CONTEXT.md) — generates invoices and processes payments
130
+ - [Fulfillment](./src/fulfillment/CONTEXT.md) — manages warehouse picking and shipping
131
+
132
+ ## Relationships
133
+
134
+ - **Ordering → Fulfillment**: Ordering emits `OrderPlaced` events; Fulfillment consumes them to start picking
135
+ - **Fulfillment → Billing**: Fulfillment emits `ShipmentDispatched` events; Billing consumes them to generate invoices
136
+ - **Ordering ↔ Billing**: Shared types for `CustomerId` and `Money`
137
+ ```
138
+
139
+ The skill infers which structure applies:
140
+
141
+ - If `CONTEXT-MAP.md` exists, read it to find contexts
142
+ - If only a root `CONTEXT.md` exists, single context
143
+ - If neither exists, create a root `CONTEXT.md` lazily when the first term is resolved
144
+
145
+ When multiple contexts exist, infer which one the current topic relates to. If unclear, ask.
146
+
147
+ # ADR Format
148
+
149
+ ADRs live in `docs/adr/` and use sequential numbering: `0001-slug.md`, `0002-slug.md`, etc.
150
+
151
+ Create the `docs/adr/` directory lazily — only when the first ADR is needed.
152
+
153
+ ## Template
154
+
155
+ ```md
156
+ # {Short title of the decision}
157
+
158
+ {1-3 sentences: what's the context, what did we decide, and why.}
159
+ ```
160
+
161
+ That's it. An ADR can be a single paragraph. The value is in recording *that* a decision was made and *why* — not in filling out sections.
162
+
163
+ ## Optional sections
164
+
165
+ Only include these when they add genuine value. Most ADRs won't need them.
166
+
167
+ - **Status** frontmatter (`proposed | accepted | deprecated | superseded by ADR-NNNN`) — useful when decisions are revisited
168
+ - **Considered Options** — only when the rejected alternatives are worth remembering
169
+ - **Consequences** — only when non-obvious downstream effects need to be called out
170
+
171
+ ## Numbering
172
+
173
+ Scan `docs/adr/` for the highest existing number and increment by one.
174
+
175
+ ## When to offer an ADR
176
+
177
+ All three of these must be true:
178
+
179
+ 1. **Hard to reverse** — the cost of changing your mind later is meaningful
180
+ 2. **Surprising without context** — a future reader will look at the code and wonder "why on earth did they do it this way?"
181
+ 3. **The result of a real trade-off** — there were genuine alternatives and you picked one for specific reasons
182
+
183
+ If a decision is easy to reverse, skip it — you'll just reverse it. If it's not surprising, nobody will wonder why. If there was no real alternative, there's nothing to record beyond "we did the obvious thing."
184
+
185
+ ### What qualifies
186
+
187
+ - **Architectural shape.** "We're using a monorepo." "The write model is event-sourced, the read model is projected into Postgres."
188
+ - **Integration patterns between contexts.** "Ordering and Billing communicate via domain events, not synchronous HTTP."
189
+ - **Technology choices that carry lock-in.** Database, message bus, auth provider, deployment target. Not every library — just the ones that would take a quarter to swap out.
190
+ - **Boundary and scope decisions.** "Customer data is owned by the Customer context; other contexts reference it by ID only." The explicit no-s are as valuable as the yes-s.
191
+ - **Deliberate deviations from the obvious path.** "We're using manual SQL instead of an ORM because X." Anything where a reasonable reader would assume the opposite. These stop the next engineer from "fixing" something that was deliberate.
192
+ - **Constraints not visible in the code.** "We can't use AWS because of compliance requirements." "Response times must be under 200ms because of the partner API contract."
193
+ - **Rejected alternatives when the rejection is non-obvious.** If you considered GraphQL and picked REST for subtle reasons, record it — otherwise someone will suggest GraphQL again in six months.