sdtk-code-kit 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/README.md +1 -1
  2. package/assets/manifest/toolkit-bundle.manifest.json +69 -14
  3. package/assets/manifest/toolkit-bundle.sha256.txt +19 -8
  4. package/assets/toolkit/toolkit/AGENTS.md +2 -1
  5. package/assets/toolkit/toolkit/SDTKCODE_TOOLKIT.md +2 -2
  6. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +4 -4
  7. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +4 -4
  8. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +2 -2
  9. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +2 -2
  10. package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +4 -1
  11. package/assets/toolkit/toolkit/skills/code-issue/SKILL.md +75 -0
  12. package/assets/toolkit/toolkit/skills/code-issue/references/MODE_FIX.md +31 -0
  13. package/assets/toolkit/toolkit/skills/code-issue/references/MODE_PICK.md +19 -0
  14. package/assets/toolkit/toolkit/skills/code-issue/references/MODE_PLAN.md +23 -0
  15. package/assets/toolkit/toolkit/skills/code-issue/references/MODE_REVIEW.md +21 -0
  16. package/assets/toolkit/toolkit/skills/code-issue/references/PROFILE_TEMPLATE.md +53 -0
  17. package/assets/toolkit/toolkit/skills/code-issue/references/RECORDS.md +39 -0
  18. package/assets/toolkit/toolkit/skills/code-issue/scripts/test_tracker.py +283 -0
  19. package/assets/toolkit/toolkit/skills/code-issue/scripts/tracker.py +465 -0
  20. package/assets/toolkit/toolkit/skills/code-review/SKILL.md +2 -1
  21. package/assets/toolkit/toolkit/skills/code-review/references/lead-review-lessons.md +30 -0
  22. package/assets/toolkit/toolkit/skills/code-review/references/lead-review.md +120 -0
  23. package/package.json +1 -1
  24. package/src/lib/scope.js +1 -0
@@ -0,0 +1,283 @@
1
+ # -*- coding: utf-8 -*-
2
+ """tracker.py against a local stub server for each tracker kind. No network beyond 127.0.0.1."""
3
+ from __future__ import annotations
4
+
5
+ import contextlib
6
+ import io
7
+ import json
8
+ import os
9
+ import shutil
10
+ import sys
11
+ import tempfile
12
+ import threading
13
+ import time
14
+ import unittest
15
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
16
+ from urllib.parse import parse_qs, urlparse
17
+
18
+ HERE = os.path.dirname(os.path.abspath(__file__))
19
+ sys.path.insert(0, HERE)
20
+ import tracker # noqa: E402
21
+
22
+ TOKEN = "s3cr3t-token-value"
23
+
24
+ GITHUB_ISSUES = [
25
+ {"number": 7, "title": "[ORD] Total is wrong after discount", "state": "open", "assignees": [{"login": "dev1"}],
26
+ "labels": [{"name": "P2"}], "created_at": "2026-01-03T00:00:00Z", "updated_at": "2026-01-05T00:00:00Z",
27
+ "html_url": "https://example.invalid/7"},
28
+ {"number": 8, "title": "[ORD] Export fails on empty list", "state": "open", "assignees": [{"login": "dev1"}],
29
+ "labels": [{"name": "P1"}], "created_at": "2026-01-04T00:00:00Z", "updated_at": "2026-01-04T00:00:00Z",
30
+ "html_url": "https://example.invalid/8"},
31
+ {"number": 9, "title": "Login button misaligned", "state": "open", "assignees": [{"login": "dev1"}],
32
+ "labels": [{"name": "P1"}], "created_at": "2026-01-02T00:00:00Z", "updated_at": "2026-01-02T00:00:00Z",
33
+ "html_url": "https://example.invalid/9"},
34
+ {"number": 10, "title": "[INV] Waits for the tax table", "state": "open", "assignees": [{"login": "dev1"}],
35
+ "labels": [{"name": "P1"}, {"name": "blocked"}], "created_at": "2026-01-01T00:00:00Z",
36
+ "updated_at": "2026-01-01T00:00:00Z", "html_url": "https://example.invalid/10"},
37
+ {"number": 11, "title": "a pull request", "state": "open", "assignees": [], "labels": [], "pull_request": {},
38
+ "created_at": "2026-01-01T00:00:00Z", "updated_at": "2026-01-01T00:00:00Z", "html_url": "x"},
39
+ ]
40
+
41
+ REDMINE_ISSUES = [
42
+ {"id": 101, "subject": "[ORD] Rounding", "status": {"name": "New"}, "assigned_to": {"name": "Dev One"},
43
+ "priority": {"id": 3, "name": "High"}, "created_on": "2026-01-02", "updated_on": "2026-01-02",
44
+ "relations": [{"issue_id": 99, "issue_to_id": 101, "relation_type": "blocks"}]},
45
+ {"id": 102, "subject": "[ORD] Paging", "status": {"name": "New"}, "assigned_to": {"name": "Dev One"},
46
+ "priority": {"id": 2, "name": "Normal"}, "created_on": "2026-01-01", "updated_on": "2026-01-01",
47
+ "relations": [{"issue_id": 102, "issue_to_id": 103, "relation_type": "blocks"}]},
48
+ ]
49
+
50
+ JIRA_ISSUES = [{"key": "ACME-5", "fields": {
51
+ "summary": "[ORD] Crash on save", "status": {"name": "To Do"}, "assignee": {"displayName": "Dev One"},
52
+ "priority": {"name": "High"}, "created": "2026-01-01", "updated": "2026-01-02", "labels": [],
53
+ "issuelinks": [{"type": {"name": "Blocks"},
54
+ "inwardIssue": {"key": "ACME-1", "fields": {"status": {"statusCategory": {"key": "done"}}}}}],
55
+ "description": "Steps: open, save.", "comment": {"comments": [{"author": {"displayName": "QA"},
56
+ "created": "2026-01-02", "body": "Still fails."}]},
57
+ "attachment": [{"filename": "log.txt"}]}}]
58
+
59
+
60
+ class Stub(BaseHTTPRequestHandler):
61
+ calls: list = []
62
+ delay = 0.0
63
+
64
+ def log_message(self, *a):
65
+ pass
66
+
67
+ def reply(self, data, code=200):
68
+ raw = json.dumps(data).encode()
69
+ self.send_response(code)
70
+ self.send_header("Content-Type", "application/json")
71
+ self.send_header("Content-Length", str(len(raw)))
72
+ self.end_headers()
73
+ self.wfile.write(raw)
74
+
75
+ def handle_any(self):
76
+ if Stub.delay:
77
+ time.sleep(Stub.delay)
78
+ length = int(self.headers.get("Content-Length") or 0)
79
+ body = json.loads(self.rfile.read(length)) if length else None
80
+ u = urlparse(self.path)
81
+ Stub.calls.append({"method": self.command, "path": u.path, "query": parse_qs(u.query), "body": body,
82
+ "headers": dict(self.headers)})
83
+ p = u.path
84
+ if p == "/repos/acme/shop/issues":
85
+ return self.reply(GITHUB_ISSUES)
86
+ if p == "/repos/acme/shop/issues/7":
87
+ return self.reply(dict(GITHUB_ISSUES[0], body="Discount 10% gives 89.99"))
88
+ if p == "/repos/acme/shop/issues/7/comments":
89
+ return self.reply([{"user": {"login": "qa"}, "created_at": "2026-01-06", "body": "repro attached"}]
90
+ if self.command == "GET" else {"id": 1})
91
+ if p.startswith("/repos/acme/shop/issues/7/"):
92
+ return self.reply({})
93
+ if p == "/issues.json":
94
+ return self.reply({"issues": REDMINE_ISSUES})
95
+ if p.startswith("/issues/"):
96
+ return self.reply({"issue": REDMINE_ISSUES[0]} if self.command == "GET" else {})
97
+ if p == "/rest/api/2/search":
98
+ return self.reply({"issues": JIRA_ISSUES})
99
+ if p == "/rest/api/2/issue/ACME-5":
100
+ return self.reply(JIRA_ISSUES[0])
101
+ if p == "/rest/api/2/issue/ACME-5/transitions":
102
+ return self.reply({"transitions": [{"id": "31", "name": "Resolve", "to": {"name": "Resolved"}}]}
103
+ if self.command == "GET" else {})
104
+ return self.reply({"error": "no route " + p}, 404)
105
+
106
+ do_GET = do_POST = do_PUT = do_PATCH = handle_any
107
+
108
+
109
+ class TrackerTests(unittest.TestCase):
110
+ @classmethod
111
+ def setUpClass(cls):
112
+ cls.server = ThreadingHTTPServer(("127.0.0.1", 0), Stub)
113
+ cls.base = "http://127.0.0.1:%d" % cls.server.server_address[1]
114
+ threading.Thread(target=cls.server.serve_forever, daemon=True).start()
115
+
116
+ @classmethod
117
+ def tearDownClass(cls):
118
+ cls.server.shutdown()
119
+
120
+ def setUp(self):
121
+ Stub.calls.clear()
122
+ Stub.delay = 0.0
123
+ self.tmp = tempfile.mkdtemp()
124
+ self.env = dict(os.environ)
125
+ os.environ["ISSUE_TRACKER_TOKEN"] = TOKEN
126
+ os.environ["ISSUE_TRACKER_USER"] = "dev1@example.invalid"
127
+
128
+ def tearDown(self):
129
+ os.environ.clear()
130
+ os.environ.update(self.env)
131
+ shutil.rmtree(self.tmp, ignore_errors=True)
132
+
133
+ def profile(self, kind, **extra):
134
+ prof = {"tracker": kind, "base_url": self.base, "me": "dev1", "title_pattern": r"^\[(?P<feature>[A-Z]+)\]",
135
+ "features": {"ORD": "Order management"},
136
+ "project": {"github": "acme/shop", "redmine": "shop", "jira": "ACME"}[kind],
137
+ "priority_order": ["P1", "P2"] if kind == "github" else ["High", "Normal"],
138
+ "priority_labels": ["P1", "P2"], "blocked_labels": ["blocked"],
139
+ "statuses": {"resolved": {"github": "closed", "redmine": 3, "jira": "Resolved"}[kind],
140
+ "review": "in review"}}
141
+ prof.update(extra)
142
+ os.makedirs(os.path.join(self.tmp, "docs"), exist_ok=True)
143
+ path = os.path.join(self.tmp, "docs", "issue_profile.json")
144
+ with open(path, "w", encoding="utf-8") as f:
145
+ json.dump(prof, f)
146
+ return path
147
+
148
+ def cli(self, *argv):
149
+ out, err = io.StringIO(), io.StringIO()
150
+ with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
151
+ code = tracker.main(list(argv))
152
+ return code, out.getvalue(), err.getvalue()
153
+
154
+ # ---- profile
155
+ def test_profile_is_found_upward_and_validated(self):
156
+ path = self.profile("github")
157
+ deep = os.path.join(self.tmp, "src", "a")
158
+ os.makedirs(deep)
159
+ self.assertEqual(tracker.find_profile(deep), path)
160
+ with open(path, "w", encoding="utf-8") as f:
161
+ json.dump({"tracker": "trello", "title_pattern": "(x"}, f)
162
+ with self.assertRaises(tracker.TrackerError) as ctx:
163
+ tracker.load_profile(path)
164
+ self.assertIn("tracker must be one of", str(ctx.exception))
165
+ self.assertIn("project is required", str(ctx.exception))
166
+ self.assertIn("not a valid regular expression", str(ctx.exception))
167
+
168
+ def test_credentials_from_dotenv_beside_the_profile_and_never_printed(self):
169
+ path = self.profile("redmine")
170
+ del os.environ["ISSUE_TRACKER_TOKEN"]
171
+ with open(os.path.join(os.path.dirname(path), ".env"), "w", encoding="utf-8") as f:
172
+ f.write("# local only\nISSUE_TRACKER_TOKEN=%s\n" % TOKEN)
173
+ code, out, _ = self.cli("--profile", path, "check")
174
+ self.assertEqual(code, 0)
175
+ self.assertIn("credentials: ok", out)
176
+ self.assertNotIn(TOKEN, out)
177
+ code, out, _ = self.cli("--profile", path, "comment", "101", "--body-file", path)
178
+ self.assertNotIn(TOKEN, out)
179
+
180
+ def test_dotenv_at_the_repository_root_is_found_and_the_nearest_wins(self):
181
+ path = self.profile("redmine") # <tmp>/docs/issue_profile.json
182
+ del os.environ["ISSUE_TRACKER_TOKEN"]
183
+ os.makedirs(os.path.join(self.tmp, ".git"))
184
+ with open(os.path.join(self.tmp, ".env"), "w", encoding="utf-8") as f:
185
+ f.write("ISSUE_TRACKER_TOKEN=root-value\n")
186
+ self.assertEqual(tracker.credentials(tracker.load_profile(path))["token"], "root-value")
187
+ with open(os.path.join(self.tmp, "docs", ".env"), "w", encoding="utf-8") as f:
188
+ f.write("ISSUE_TRACKER_TOKEN=near-value\n")
189
+ self.assertEqual(tracker.credentials(tracker.load_profile(path))["token"], "near-value")
190
+
191
+ def test_missing_credential_is_named(self):
192
+ path = self.profile("jira")
193
+ del os.environ["ISSUE_TRACKER_USER"]
194
+ code, out, _ = self.cli("--profile", path, "check")
195
+ self.assertEqual(code, 2)
196
+ self.assertIn("missing ISSUE_TRACKER_USER", out)
197
+
198
+ # ---- reads
199
+ def test_github_pick_drops_blocked_and_prs_ranks_and_flags_titles(self):
200
+ path = self.profile("github")
201
+ code, out, _ = self.cli("--profile", path, "pick", "--json")
202
+ self.assertEqual(code, 0)
203
+ picked = json.loads(out)
204
+ self.assertEqual([i["id"] for i in picked["candidates"]], ["9", "8", "7"]) # P1 old, P1 newer, P2
205
+ self.assertEqual([i["id"] for i in picked["blocked"]], ["10"])
206
+ self.assertFalse(picked["candidates"][0]["title_ok"])
207
+ self.assertEqual(picked["candidates"][1]["feature"], "ORD")
208
+ self.assertEqual(Stub.calls[0]["query"]["assignee"], ["dev1"])
209
+ self.assertEqual(Stub.calls[0]["headers"]["Authorization"], "Bearer " + TOKEN)
210
+ code, text, _ = self.cli("--profile", path, "pick")
211
+ self.assertIn("? title does not follow the convention", text)
212
+ self.assertIn("ORD (Order management)", text)
213
+ self.assertIn("Nothing was started", text)
214
+ self.assertTrue(all(c["method"] == "GET" for c in Stub.calls))
215
+
216
+ def test_redmine_blocked_relation_and_show(self):
217
+ path = self.profile("redmine")
218
+ picked = json.loads(self.cli("--profile", path, "pick", "--json")[1])
219
+ self.assertEqual([i["id"] for i in picked["candidates"]], ["102"]) # 101 is blocked by 99
220
+ self.assertEqual(Stub.calls[0]["headers"]["X-Redmine-Api-Key"], TOKEN)
221
+ data = json.loads(self.cli("--profile", path, "show", "101", "--json")[1])
222
+ self.assertIn("journals", Stub.calls[-1]["query"]["include"][0])
223
+ self.assertTrue(data["blocked"])
224
+
225
+ def test_jira_show_reads_comments_attachments_and_done_blockers_do_not_block(self):
226
+ path = self.profile("jira")
227
+ data = json.loads(self.cli("--profile", path, "show", "ACME-5", "--json")[1])
228
+ self.assertFalse(data["blocked"])
229
+ self.assertEqual(data["comments"][0]["body"], "Still fails.")
230
+ self.assertEqual(data["attachments"], ["log.txt"])
231
+ self.assertTrue(Stub.calls[0]["headers"]["Authorization"].startswith("Basic "))
232
+ self.cli("--profile", path, "list")
233
+ self.assertIn("currentUser()", Stub.calls[-1]["query"]["jql"][0])
234
+
235
+ # ---- writes
236
+ def test_writes_are_dry_run_unless_applied(self):
237
+ path = self.profile("github")
238
+ body = os.path.join(self.tmp, "c.md")
239
+ with open(body, "w", encoding="utf-8") as f:
240
+ f.write("Fixed in PR #12. Root cause: discount applied twice.")
241
+ code, out, _ = self.cli("--profile", path, "comment", "7", "--body-file", body)
242
+ self.assertEqual(code, 0)
243
+ self.assertIn("POST /repos/acme/shop/issues/7/comments", out)
244
+ self.assertIn("Dry run: nothing was sent", out)
245
+ self.assertEqual(Stub.calls, [])
246
+ self.cli("--profile", path, "comment", "7", "--body-file", body, "--apply")
247
+ self.assertEqual(Stub.calls[-1]["method"], "POST")
248
+ self.assertEqual(Stub.calls[-1]["body"], {"body": "Fixed in PR #12. Root cause: discount applied twice."})
249
+
250
+ def test_transitions_per_tracker(self):
251
+ self.cli("--profile", self.profile("github"), "transition", "7", "--to", "review", "--assign", "qa1", "--apply")
252
+ self.assertEqual([(c["method"], c["path"], c["body"]) for c in Stub.calls],
253
+ [("POST", "/repos/acme/shop/issues/7/labels", {"labels": ["in review"]}),
254
+ ("POST", "/repos/acme/shop/issues/7/assignees", {"assignees": ["qa1"]})])
255
+ Stub.calls.clear()
256
+ self.cli("--profile", self.profile("redmine"), "transition", "101", "--to", "resolved", "--apply")
257
+ self.assertEqual(Stub.calls[-1]["body"], {"issue": {"status_id": 3}})
258
+ Stub.calls.clear()
259
+ code, out, _ = self.cli("--profile", self.profile("jira"), "transition", "ACME-5", "--to", "resolved")
260
+ self.assertEqual([c["method"] for c in Stub.calls], ["GET"]) # reads transitions, sends nothing
261
+ self.assertIn('"id": "31"', out)
262
+ code, _, err = self.cli("--profile", self.profile("jira"), "transition", "ACME-5", "--to", "nope")
263
+ self.assertEqual(code, 1)
264
+ self.assertIn("not in the profile's statuses", err)
265
+
266
+ # ---- network hygiene
267
+ def test_slow_tracker_times_out_instead_of_hanging(self):
268
+ path = self.profile("redmine")
269
+ Stub.delay = 2.0
270
+ start = time.time()
271
+ code, _, err = self.cli("--profile", path, "--timeout", "0.3", "list")
272
+ self.assertEqual(code, 1)
273
+ self.assertLess(time.time() - start, 1.8)
274
+ self.assertIn("timeout 0.3s", err)
275
+
276
+ def test_child_processes_never_prompt(self):
277
+ self.cli("--profile", self.profile("github"), "check")
278
+ self.assertEqual(os.environ.get("GIT_TERMINAL_PROMPT"), "0")
279
+ self.assertEqual(os.environ.get("GH_PROMPT_DISABLED"), "1")
280
+
281
+
282
+ if __name__ == "__main__":
283
+ unittest.main()