continuum-task-server-bundle 1.0.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.
Files changed (90) hide show
  1. continuum_task_server_bundle/__init__.py +1 -0
  2. continuum_task_server_bundle/daytona/__init__.py +4 -0
  3. continuum_task_server_bundle/daytona/common.py +534 -0
  4. continuum_task_server_bundle/daytona/create_sandbox.py +166 -0
  5. continuum_task_server_bundle/daytona/dispatch.py +125 -0
  6. continuum_task_server_bundle/daytona/execute_sandbox.py +243 -0
  7. continuum_task_server_bundle/daytona/filesystem.py +330 -0
  8. continuum_task_server_bundle/daytona/fs_edit.py +127 -0
  9. continuum_task_server_bundle/daytona/git_ops.py +585 -0
  10. continuum_task_server_bundle/daytona/github_app.py +207 -0
  11. continuum_task_server_bundle/daytona/manage_sandbox.py +104 -0
  12. continuum_task_server_bundle/daytona/plugin.py +18 -0
  13. continuum_task_server_bundle/daytona/s3_transfer.py +207 -0
  14. continuum_task_server_bundle/discord/__init__.py +4 -0
  15. continuum_task_server_bundle/discord/attachment_registry_db.py +127 -0
  16. continuum_task_server_bundle/discord/attachment_resolve.py +213 -0
  17. continuum_task_server_bundle/discord/await_cleanup.py +105 -0
  18. continuum_task_server_bundle/discord/discord_ready.py +39 -0
  19. continuum_task_server_bundle/discord/message_await_apply.py +143 -0
  20. continuum_task_server_bundle/discord/message_await_db.py +197 -0
  21. continuum_task_server_bundle/discord/message_await_inbound.py +54 -0
  22. continuum_task_server_bundle/discord/message_await_logic.py +133 -0
  23. continuum_task_server_bundle/discord/message_await_poller.py +122 -0
  24. continuum_task_server_bundle/discord/message_chunking.py +45 -0
  25. continuum_task_server_bundle/discord/methods.py +408 -0
  26. continuum_task_server_bundle/discord/plugin.py +105 -0
  27. continuum_task_server_bundle/discord/reaction_await_apply.py +238 -0
  28. continuum_task_server_bundle/discord/reaction_await_db.py +174 -0
  29. continuum_task_server_bundle/discord/reaction_await_inbound.py +47 -0
  30. continuum_task_server_bundle/discord/reaction_await_logic.py +118 -0
  31. continuum_task_server_bundle/discord/reaction_await_poller.py +131 -0
  32. continuum_task_server_bundle/discord/s3_attachment_config.py +25 -0
  33. continuum_task_server_bundle/discord/s3_message_attachments.py +139 -0
  34. continuum_task_server_bundle/discord/sql/001_message_awaits.sql +112 -0
  35. continuum_task_server_bundle/discord/sql/002_reaction_awaits.sql +61 -0
  36. continuum_task_server_bundle/github/__init__.py +4 -0
  37. continuum_task_server_bundle/github/awaits/__init__.py +1 -0
  38. continuum_task_server_bundle/github/awaits/apply.py +92 -0
  39. continuum_task_server_bundle/github/awaits/cleanup.py +94 -0
  40. continuum_task_server_bundle/github/awaits/db.py +220 -0
  41. continuum_task_server_bundle/github/awaits/evaluators.py +325 -0
  42. continuum_task_server_bundle/github/awaits/fetch.py +192 -0
  43. continuum_task_server_bundle/github/awaits/poller.py +82 -0
  44. continuum_task_server_bundle/github/awaits/register.py +37 -0
  45. continuum_task_server_bundle/github/ci_status.py +70 -0
  46. continuum_task_server_bundle/github/comment_normalize.py +76 -0
  47. continuum_task_server_bundle/github/errors.py +52 -0
  48. continuum_task_server_bundle/github/github_app.py +291 -0
  49. continuum_task_server_bundle/github/github_http.py +377 -0
  50. continuum_task_server_bundle/github/methods/__init__.py +90 -0
  51. continuum_task_server_bundle/github/methods/_common.py +183 -0
  52. continuum_task_server_bundle/github/methods/awaits.py +107 -0
  53. continuum_task_server_bundle/github/methods/ci.py +158 -0
  54. continuum_task_server_bundle/github/methods/comments.py +214 -0
  55. continuum_task_server_bundle/github/methods/credentials.py +59 -0
  56. continuum_task_server_bundle/github/methods/issues.py +131 -0
  57. continuum_task_server_bundle/github/methods/pulls.py +329 -0
  58. continuum_task_server_bundle/github/methods/repos.py +424 -0
  59. continuum_task_server_bundle/github/methods/search.py +109 -0
  60. continuum_task_server_bundle/github/plugin.py +91 -0
  61. continuum_task_server_bundle/github/sql/001_github_awaits.sql +65 -0
  62. continuum_task_server_bundle/github/webhook_server.py +126 -0
  63. continuum_task_server_bundle/jira/__init__.py +4 -0
  64. continuum_task_server_bundle/jira/await_poller.py +236 -0
  65. continuum_task_server_bundle/jira/await_store.py +271 -0
  66. continuum_task_server_bundle/jira/config.py +68 -0
  67. continuum_task_server_bundle/jira/jira_client.py +382 -0
  68. continuum_task_server_bundle/jira/methods.py +246 -0
  69. continuum_task_server_bundle/jira/plugin.py +86 -0
  70. continuum_task_server_bundle/jira/sql/001_jira_issue_comment_waits.sql +19 -0
  71. continuum_task_server_bundle/jira/webhook.py +70 -0
  72. continuum_task_server_bundle/openrouter/__init__.py +4 -0
  73. continuum_task_server_bundle/openrouter/chat_service.py +1037 -0
  74. continuum_task_server_bundle/openrouter/chat_store.py +849 -0
  75. continuum_task_server_bundle/openrouter/environment.py +29 -0
  76. continuum_task_server_bundle/openrouter/handler.py +59 -0
  77. continuum_task_server_bundle/openrouter/image_context.py +207 -0
  78. continuum_task_server_bundle/openrouter/openrouter_client.py +324 -0
  79. continuum_task_server_bundle/openrouter/plugin.py +37 -0
  80. continuum_task_server_bundle/openrouter/prompt_projection.py +417 -0
  81. continuum_task_server_bundle/openrouter/sql/chat.sql +50 -0
  82. continuum_task_server_bundle/openrouter/sql/migrate_prune_then_chunk_v1.sql +11 -0
  83. continuum_task_server_bundle/roblox/__init__.py +4 -0
  84. continuum_task_server_bundle/roblox/open_cloud.py +335 -0
  85. continuum_task_server_bundle/roblox/plugin.py +30 -0
  86. continuum_task_server_bundle/roblox/storage_s3.py +55 -0
  87. continuum_task_server_bundle-1.0.0.dist-info/METADATA +109 -0
  88. continuum_task_server_bundle-1.0.0.dist-info/RECORD +90 -0
  89. continuum_task_server_bundle-1.0.0.dist-info/WHEEL +5 -0
  90. continuum_task_server_bundle-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,214 @@
1
+ """Issue and pull request comments.
2
+
3
+ ``comment`` can embed an idempotency key as an HTML comment so a retry of the
4
+ same queue item does not post a second copy (for example the run-id note).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import re
10
+ from typing import Any
11
+
12
+ from continuum_task_server_bundle.github.comment_normalize import (
13
+ normalize_issue_comment,
14
+ normalize_review,
15
+ normalize_review_comment,
16
+ review_is_public,
17
+ )
18
+ from continuum_task_server_bundle.github.errors import InputError
19
+ from continuum_task_server_bundle.github.methods._common import Call, opt_int, parse_time, require_number, require_repo, require_str
20
+
21
+ _KEY_RE = re.compile(r"^[A-Za-z0-9_.:\-]{1,200}$")
22
+ _MAX_IDEMPOTENCY_PAGES = 10
23
+
24
+
25
+ def marker_for(key: str) -> str:
26
+ if not _KEY_RE.fullmatch(key):
27
+ raise InputError("idempotency_key must be 1-200 characters from [A-Za-z0-9_.:-]")
28
+ return f"<!-- continuum:key={key} -->"
29
+
30
+
31
+ def body_has_key(body: str | None, key: str) -> bool:
32
+ return marker_for(key) in (body or "")
33
+
34
+
35
+ def comment(call: Call) -> dict[str, Any]:
36
+ owner, name = require_repo(call.data)
37
+ number = require_number(call.data, "number", "pr_number", "issue_number")
38
+ text = call.data.get("body", call.data.get("text"))
39
+ if not isinstance(text, str) or not text.strip():
40
+ raise InputError("body is required")
41
+ repo = f"{owner}/{name}"
42
+ key = call.data.get("idempotency_key")
43
+ payload_body = text
44
+ if key is not None:
45
+ marker = marker_for(str(key))
46
+ existing = _find_comment_with_marker(call, owner, name, number, marker)
47
+ if existing is not None:
48
+ return {
49
+ "success": True,
50
+ "comment_id": existing.get("id"),
51
+ "html_url": existing.get("html_url"),
52
+ "idempotent": True,
53
+ }
54
+ payload_body = f"{text}\n\n{marker}"
55
+ created = call.app.rest(
56
+ "POST",
57
+ f"/repos/{owner}/{name}/issues/{number}/comments",
58
+ repo=repo,
59
+ json_body={"body": payload_body},
60
+ ).data or {}
61
+ return {
62
+ "success": True,
63
+ "comment_id": created.get("id"),
64
+ "html_url": created.get("html_url"),
65
+ "idempotent": False,
66
+ }
67
+
68
+
69
+ def list_comments(call: Call) -> dict[str, Any]:
70
+ owner, name = require_repo(call.data)
71
+ number = require_number(call.data, "number", "pr_number", "issue_number")
72
+ include = call.data.get("include") or ["issue_comment", "review_comment", "review"]
73
+ if isinstance(include, str):
74
+ include = [include]
75
+ comments = _load_comments(call, owner, name, number, include=set(include), since=call.data.get("since"))
76
+ after_id = call.data.get("after_id")
77
+ if after_id is not None:
78
+ comments = [item for item in comments if not _id_leq(item.get("id"), after_id)]
79
+ since = parse_time(call.data.get("since")) if call.data.get("since") else None
80
+ if since is not None:
81
+ comments = [
82
+ item
83
+ for item in comments
84
+ if (created := parse_time(item.get("created_at"))) is not None and created > since
85
+ ]
86
+ comments.sort(key=lambda item: (str(item.get("created_at") or ""), str(item.get("kind")), str(item.get("id"))))
87
+ limit = opt_int(call.data, "limit", default=100)
88
+ return {"success": True, "comments": comments[: max(1, limit)]}
89
+
90
+
91
+ def edit_comment(call: Call) -> dict[str, Any]:
92
+ owner, name = require_repo(call.data)
93
+ comment_id = require_number(call.data, "comment_id")
94
+ body = require_str(call.data, "body")
95
+ kind = str(call.data.get("kind") or "issue_comment")
96
+ repo = f"{owner}/{name}"
97
+ if kind == "review_comment":
98
+ path = f"/repos/{owner}/{name}/pulls/comments/{comment_id}"
99
+ elif kind == "issue_comment":
100
+ path = f"/repos/{owner}/{name}/issues/comments/{comment_id}"
101
+ else:
102
+ raise InputError("kind must be issue_comment or review_comment")
103
+ updated = call.app.rest("PATCH", path, repo=repo, json_body={"body": body}).data or {}
104
+ return {"success": True, "comment_id": updated.get("id") or comment_id, "html_url": updated.get("html_url")}
105
+
106
+
107
+ def reply_to_review_comment(call: Call) -> dict[str, Any]:
108
+ owner, name = require_repo(call.data)
109
+ number = require_number(call.data, "number", "pr_number")
110
+ comment_id = require_number(call.data, "comment_id", "in_reply_to")
111
+ body = require_str(call.data, "body")
112
+ repo = f"{owner}/{name}"
113
+ created = call.app.rest(
114
+ "POST",
115
+ f"/repos/{owner}/{name}/pulls/{number}/comments",
116
+ repo=repo,
117
+ json_body={"body": body, "in_reply_to": comment_id},
118
+ ).data or {}
119
+ return {"success": True, "comment_id": created.get("id"), "html_url": created.get("html_url")}
120
+
121
+
122
+ def add_reaction(call: Call) -> dict[str, Any]:
123
+ owner, name = require_repo(call.data)
124
+ content = require_str(call.data, "content")
125
+ kind = str(call.data.get("kind") or "issue_comment")
126
+ repo = f"{owner}/{name}"
127
+ if kind == "issue":
128
+ number = require_number(call.data, "number", "pr_number", "issue_number")
129
+ path = f"/repos/{owner}/{name}/issues/{number}/reactions"
130
+ elif kind == "review_comment":
131
+ comment_id = require_number(call.data, "comment_id")
132
+ path = f"/repos/{owner}/{name}/pulls/comments/{comment_id}/reactions"
133
+ elif kind == "issue_comment":
134
+ comment_id = require_number(call.data, "comment_id")
135
+ path = f"/repos/{owner}/{name}/issues/comments/{comment_id}/reactions"
136
+ else:
137
+ raise InputError("kind must be issue_comment, review_comment, or issue")
138
+ created = call.app.rest("POST", path, repo=repo, json_body={"content": content}).data or {}
139
+ return {"success": True, "reaction_id": created.get("id"), "content": created.get("content") or content}
140
+
141
+
142
+ def _find_comment_with_marker(call: Call, owner: str, name: str, number: int, marker: str) -> dict[str, Any] | None:
143
+ repo = f"{owner}/{name}"
144
+ page = 1
145
+ while page <= _MAX_IDEMPOTENCY_PAGES:
146
+ batch = call.app.rest(
147
+ "GET",
148
+ f"/repos/{owner}/{name}/issues/{number}/comments",
149
+ repo=repo,
150
+ params={"per_page": 100, "page": page},
151
+ ).data or []
152
+ if not isinstance(batch, list) or not batch:
153
+ return None
154
+ for item in batch:
155
+ if marker in (item.get("body") or ""):
156
+ return item
157
+ if len(batch) < 100:
158
+ return None
159
+ page += 1
160
+ return None
161
+
162
+
163
+ def _load_comments(
164
+ call: Call,
165
+ owner: str,
166
+ name: str,
167
+ number: int,
168
+ *,
169
+ include: set[str],
170
+ since: Any,
171
+ ) -> list[dict[str, Any]]:
172
+ repo = f"{owner}/{name}"
173
+ comments: list[dict[str, Any]] = []
174
+ if "issue_comment" in include:
175
+ issue_comments = call.app.rest(
176
+ "GET",
177
+ f"/repos/{owner}/{name}/issues/{number}/comments",
178
+ repo=repo,
179
+ params={"per_page": 100, "since": since},
180
+ paginate=True,
181
+ max_pages=5,
182
+ ).data or []
183
+ if isinstance(issue_comments, list):
184
+ comments.extend(normalize_issue_comment(item) for item in issue_comments)
185
+ if "review_comment" in include:
186
+ review_comments = call.app.rest(
187
+ "GET",
188
+ f"/repos/{owner}/{name}/pulls/{number}/comments",
189
+ repo=repo,
190
+ params={"per_page": 100, "since": since},
191
+ paginate=True,
192
+ max_pages=5,
193
+ ).data or []
194
+ if isinstance(review_comments, list):
195
+ comments.extend(normalize_review_comment(item) for item in review_comments)
196
+ if "review" in include:
197
+ reviews = call.app.rest(
198
+ "GET",
199
+ f"/repos/{owner}/{name}/pulls/{number}/reviews",
200
+ repo=repo,
201
+ params={"per_page": 100},
202
+ paginate=True,
203
+ max_pages=5,
204
+ ).data or []
205
+ if isinstance(reviews, list):
206
+ comments.extend(normalize_review(item) for item in reviews if review_is_public(item))
207
+ return comments
208
+
209
+
210
+ def _id_leq(comment_id: Any, after_id: Any) -> bool:
211
+ try:
212
+ return int(str(comment_id)) <= int(str(after_id))
213
+ except (TypeError, ValueError):
214
+ return str(comment_id) <= str(after_id)
@@ -0,0 +1,59 @@
1
+ """Installation tokens for deterministic workflows.
2
+
3
+ The guard layer must not expose ``get_installation_token`` to agents. The token
4
+ can clone and push as the GitHub App.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from os import getenv
10
+ from typing import Any
11
+
12
+ from continuum_task_server_bundle.github.errors import InputError
13
+ from continuum_task_server_bundle.github.methods._common import Call, as_bool, git_clone_url, repo_names, require_repo
14
+
15
+
16
+ def get_installation_token(call: Call) -> dict[str, Any]:
17
+ data = call.data
18
+ repositories = data.get("repositories")
19
+ permissions = data.get("permissions")
20
+ if repositories is not None and not isinstance(repositories, list):
21
+ raise InputError("repositories must be a list of repo names")
22
+ if permissions is not None and not isinstance(permissions, dict):
23
+ raise InputError("permissions must be an object of permission name to access level")
24
+
25
+ repo_names_only = repo_names([str(item) for item in repositories]) if repositories else None
26
+ perm_map = {str(key): str(value) for key, value in permissions.items()} if permissions else None
27
+
28
+ clone_url = None
29
+ if data.get("repo"):
30
+ owner, name = require_repo(data)
31
+ installation_id = call.app.installation_id_for_repo(owner, name)
32
+ token, expires_at = call.app.installation_token(
33
+ installation_id,
34
+ repositories=repo_names_only,
35
+ permissions=perm_map,
36
+ )
37
+ if as_bool(data.get("include_clone_url"), default=True):
38
+ clone_url = git_clone_url(owner, name, token)
39
+ else:
40
+ owner_raw = data.get("owner") or getenv("GITHUB_DEFAULT_OWNER")
41
+ if not owner_raw or not isinstance(owner_raw, str):
42
+ raise InputError("repo or owner is required")
43
+ owner = owner_raw.strip()
44
+ installation_id = call.app.installation_id_for_owner(owner)
45
+ token, expires_at = call.app.installation_token(
46
+ installation_id,
47
+ repositories=repo_names_only,
48
+ permissions=perm_map,
49
+ )
50
+ if repo_names_only and len(repo_names_only) == 1 and as_bool(data.get("include_clone_url"), default=False):
51
+ clone_url = git_clone_url(owner, repo_names_only[0], token)
52
+
53
+ return {
54
+ "success": True,
55
+ "token": token,
56
+ "expires_at": expires_at.isoformat(),
57
+ "installation_id": installation_id,
58
+ "git_clone_url": clone_url,
59
+ }
@@ -0,0 +1,131 @@
1
+ """Issue methods. Pull requests share issue numbers, so these work on either."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+ from urllib.parse import quote
7
+
8
+ from continuum_task_server_bundle.github.errors import InputError
9
+ from continuum_task_server_bundle.github.methods._common import Call, opt_int, require_number, require_repo, require_str
10
+
11
+
12
+ def create_issue(call: Call) -> dict[str, Any]:
13
+ owner, name = require_repo(call.data)
14
+ title = require_str(call.data, "title")
15
+ repo = f"{owner}/{name}"
16
+ body: dict[str, Any] = {"title": title}
17
+ if call.data.get("body") is not None:
18
+ body["body"] = call.data["body"]
19
+ if call.data.get("labels") is not None:
20
+ body["labels"] = call.data["labels"]
21
+ if call.data.get("assignees") is not None:
22
+ body["assignees"] = call.data["assignees"]
23
+ created = call.app.rest("POST", f"/repos/{owner}/{name}/issues", repo=repo, json_body=body).data or {}
24
+ return {"success": True, "issue": _trim_issue(created)}
25
+
26
+
27
+ def get_issue(call: Call) -> dict[str, Any]:
28
+ owner, name = require_repo(call.data)
29
+ number = require_number(call.data, "number", "issue_number")
30
+ repo = f"{owner}/{name}"
31
+ issue = call.app.rest("GET", f"/repos/{owner}/{name}/issues/{number}", repo=repo).data or {}
32
+ return {"success": True, "issue": _trim_issue(issue)}
33
+
34
+
35
+ def list_issues(call: Call) -> dict[str, Any]:
36
+ owner, name = require_repo(call.data)
37
+ repo = f"{owner}/{name}"
38
+ per_page = min(100, max(1, opt_int(call.data, "per_page", "limit", default=30)))
39
+ issues = call.app.rest(
40
+ "GET",
41
+ f"/repos/{owner}/{name}/issues",
42
+ repo=repo,
43
+ params={
44
+ "state": call.data.get("state") or "open",
45
+ "labels": call.data.get("labels"),
46
+ "since": call.data.get("since"),
47
+ "per_page": per_page,
48
+ },
49
+ ).data or []
50
+ if isinstance(issues, dict):
51
+ issues = []
52
+ include_pulls = call.data.get("include_pull_requests")
53
+ if include_pulls is None or include_pulls is False:
54
+ issues = [issue for issue in issues if "pull_request" not in issue]
55
+ return {"success": True, "issues": [_trim_issue(issue) for issue in issues]}
56
+
57
+
58
+ def update_issue(call: Call) -> dict[str, Any]:
59
+ owner, name = require_repo(call.data)
60
+ number = require_number(call.data, "number", "issue_number")
61
+ repo = f"{owner}/{name}"
62
+ body: dict[str, Any] = {}
63
+ for key in ("title", "body", "state", "assignees", "labels"):
64
+ if call.data.get(key) is not None:
65
+ body[key] = call.data[key]
66
+ if not body:
67
+ raise InputError("one of title, body, state, assignees, or labels is required")
68
+ if "state" in body and body["state"] not in ("open", "closed"):
69
+ raise InputError("state must be open or closed")
70
+ updated = call.app.rest(
71
+ "PATCH",
72
+ f"/repos/{owner}/{name}/issues/{number}",
73
+ repo=repo,
74
+ json_body=body,
75
+ ).data or {}
76
+ return {"success": True, "issue": _trim_issue(updated)}
77
+
78
+
79
+ def add_labels(call: Call) -> dict[str, Any]:
80
+ owner, name = require_repo(call.data)
81
+ number = require_number(call.data, "number", "issue_number", "pr_number")
82
+ labels = call.data.get("labels")
83
+ if not isinstance(labels, list) or not labels:
84
+ raise InputError("labels must be a non-empty list")
85
+ repo = f"{owner}/{name}"
86
+ updated = call.app.rest(
87
+ "POST",
88
+ f"/repos/{owner}/{name}/issues/{number}/labels",
89
+ repo=repo,
90
+ json_body={"labels": labels},
91
+ ).data or []
92
+ names = [item.get("name") for item in updated if isinstance(item, dict)]
93
+ return {"success": True, "labels": names}
94
+
95
+
96
+ def remove_label(call: Call) -> dict[str, Any]:
97
+ owner, name = require_repo(call.data)
98
+ number = require_number(call.data, "number", "issue_number", "pr_number")
99
+ label = require_str(call.data, "label")
100
+ repo = f"{owner}/{name}"
101
+ call.app.rest(
102
+ "DELETE",
103
+ f"/repos/{owner}/{name}/issues/{number}/labels/{quote(label, safe='')}",
104
+ repo=repo,
105
+ )
106
+ return {"success": True, "label": label}
107
+
108
+
109
+ def _trim_issue(issue: dict[str, Any]) -> dict[str, Any]:
110
+ user = issue.get("user") or {}
111
+ labels = issue.get("labels") or []
112
+ label_names = []
113
+ for label in labels:
114
+ if isinstance(label, dict):
115
+ label_names.append(label.get("name"))
116
+ else:
117
+ label_names.append(label)
118
+ assignees = [item.get("login") for item in (issue.get("assignees") or []) if isinstance(item, dict)]
119
+ return {
120
+ "number": issue.get("number"),
121
+ "title": issue.get("title"),
122
+ "body": issue.get("body"),
123
+ "state": issue.get("state"),
124
+ "html_url": issue.get("html_url"),
125
+ "user_login": user.get("login") if isinstance(user, dict) else None,
126
+ "labels": label_names,
127
+ "assignees": assignees,
128
+ "is_pull_request": issue.get("pull_request") is not None,
129
+ "created_at": issue.get("created_at"),
130
+ "updated_at": issue.get("updated_at"),
131
+ }