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.
- continuum_task_server_bundle/__init__.py +1 -0
- continuum_task_server_bundle/daytona/__init__.py +4 -0
- continuum_task_server_bundle/daytona/common.py +534 -0
- continuum_task_server_bundle/daytona/create_sandbox.py +166 -0
- continuum_task_server_bundle/daytona/dispatch.py +125 -0
- continuum_task_server_bundle/daytona/execute_sandbox.py +243 -0
- continuum_task_server_bundle/daytona/filesystem.py +330 -0
- continuum_task_server_bundle/daytona/fs_edit.py +127 -0
- continuum_task_server_bundle/daytona/git_ops.py +585 -0
- continuum_task_server_bundle/daytona/github_app.py +207 -0
- continuum_task_server_bundle/daytona/manage_sandbox.py +104 -0
- continuum_task_server_bundle/daytona/plugin.py +18 -0
- continuum_task_server_bundle/daytona/s3_transfer.py +207 -0
- continuum_task_server_bundle/discord/__init__.py +4 -0
- continuum_task_server_bundle/discord/attachment_registry_db.py +127 -0
- continuum_task_server_bundle/discord/attachment_resolve.py +213 -0
- continuum_task_server_bundle/discord/await_cleanup.py +105 -0
- continuum_task_server_bundle/discord/discord_ready.py +39 -0
- continuum_task_server_bundle/discord/message_await_apply.py +143 -0
- continuum_task_server_bundle/discord/message_await_db.py +197 -0
- continuum_task_server_bundle/discord/message_await_inbound.py +54 -0
- continuum_task_server_bundle/discord/message_await_logic.py +133 -0
- continuum_task_server_bundle/discord/message_await_poller.py +122 -0
- continuum_task_server_bundle/discord/message_chunking.py +45 -0
- continuum_task_server_bundle/discord/methods.py +408 -0
- continuum_task_server_bundle/discord/plugin.py +105 -0
- continuum_task_server_bundle/discord/reaction_await_apply.py +238 -0
- continuum_task_server_bundle/discord/reaction_await_db.py +174 -0
- continuum_task_server_bundle/discord/reaction_await_inbound.py +47 -0
- continuum_task_server_bundle/discord/reaction_await_logic.py +118 -0
- continuum_task_server_bundle/discord/reaction_await_poller.py +131 -0
- continuum_task_server_bundle/discord/s3_attachment_config.py +25 -0
- continuum_task_server_bundle/discord/s3_message_attachments.py +139 -0
- continuum_task_server_bundle/discord/sql/001_message_awaits.sql +112 -0
- continuum_task_server_bundle/discord/sql/002_reaction_awaits.sql +61 -0
- continuum_task_server_bundle/github/__init__.py +4 -0
- continuum_task_server_bundle/github/awaits/__init__.py +1 -0
- continuum_task_server_bundle/github/awaits/apply.py +92 -0
- continuum_task_server_bundle/github/awaits/cleanup.py +94 -0
- continuum_task_server_bundle/github/awaits/db.py +220 -0
- continuum_task_server_bundle/github/awaits/evaluators.py +325 -0
- continuum_task_server_bundle/github/awaits/fetch.py +192 -0
- continuum_task_server_bundle/github/awaits/poller.py +82 -0
- continuum_task_server_bundle/github/awaits/register.py +37 -0
- continuum_task_server_bundle/github/ci_status.py +70 -0
- continuum_task_server_bundle/github/comment_normalize.py +76 -0
- continuum_task_server_bundle/github/errors.py +52 -0
- continuum_task_server_bundle/github/github_app.py +291 -0
- continuum_task_server_bundle/github/github_http.py +377 -0
- continuum_task_server_bundle/github/methods/__init__.py +90 -0
- continuum_task_server_bundle/github/methods/_common.py +183 -0
- continuum_task_server_bundle/github/methods/awaits.py +107 -0
- continuum_task_server_bundle/github/methods/ci.py +158 -0
- continuum_task_server_bundle/github/methods/comments.py +214 -0
- continuum_task_server_bundle/github/methods/credentials.py +59 -0
- continuum_task_server_bundle/github/methods/issues.py +131 -0
- continuum_task_server_bundle/github/methods/pulls.py +329 -0
- continuum_task_server_bundle/github/methods/repos.py +424 -0
- continuum_task_server_bundle/github/methods/search.py +109 -0
- continuum_task_server_bundle/github/plugin.py +91 -0
- continuum_task_server_bundle/github/sql/001_github_awaits.sql +65 -0
- continuum_task_server_bundle/github/webhook_server.py +126 -0
- continuum_task_server_bundle/jira/__init__.py +4 -0
- continuum_task_server_bundle/jira/await_poller.py +236 -0
- continuum_task_server_bundle/jira/await_store.py +271 -0
- continuum_task_server_bundle/jira/config.py +68 -0
- continuum_task_server_bundle/jira/jira_client.py +382 -0
- continuum_task_server_bundle/jira/methods.py +246 -0
- continuum_task_server_bundle/jira/plugin.py +86 -0
- continuum_task_server_bundle/jira/sql/001_jira_issue_comment_waits.sql +19 -0
- continuum_task_server_bundle/jira/webhook.py +70 -0
- continuum_task_server_bundle/openrouter/__init__.py +4 -0
- continuum_task_server_bundle/openrouter/chat_service.py +1037 -0
- continuum_task_server_bundle/openrouter/chat_store.py +849 -0
- continuum_task_server_bundle/openrouter/environment.py +29 -0
- continuum_task_server_bundle/openrouter/handler.py +59 -0
- continuum_task_server_bundle/openrouter/image_context.py +207 -0
- continuum_task_server_bundle/openrouter/openrouter_client.py +324 -0
- continuum_task_server_bundle/openrouter/plugin.py +37 -0
- continuum_task_server_bundle/openrouter/prompt_projection.py +417 -0
- continuum_task_server_bundle/openrouter/sql/chat.sql +50 -0
- continuum_task_server_bundle/openrouter/sql/migrate_prune_then_chunk_v1.sql +11 -0
- continuum_task_server_bundle/roblox/__init__.py +4 -0
- continuum_task_server_bundle/roblox/open_cloud.py +335 -0
- continuum_task_server_bundle/roblox/plugin.py +30 -0
- continuum_task_server_bundle/roblox/storage_s3.py +55 -0
- continuum_task_server_bundle-1.0.0.dist-info/METADATA +109 -0
- continuum_task_server_bundle-1.0.0.dist-info/RECORD +90 -0
- continuum_task_server_bundle-1.0.0.dist-info/WHEEL +5 -0
- continuum_task_server_bundle-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from daytona import Daytona, DaytonaError
|
|
4
|
+
|
|
5
|
+
from continuum_task_server_bundle.daytona import github_app
|
|
6
|
+
from continuum_task_server_bundle.daytona.common import (
|
|
7
|
+
HandlerError,
|
|
8
|
+
effective_limit,
|
|
9
|
+
enum_value,
|
|
10
|
+
get_running_sandbox,
|
|
11
|
+
map_daytona,
|
|
12
|
+
optional_bool,
|
|
13
|
+
optional_int,
|
|
14
|
+
optional_str,
|
|
15
|
+
require_path,
|
|
16
|
+
require_str,
|
|
17
|
+
resolve_timeout,
|
|
18
|
+
success,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
_GIT_USERNAME = "x-access-token"
|
|
22
|
+
_STALE_TOKEN_RE = re.compile(
|
|
23
|
+
r"not found|authentication|unauthorized|forbidden|401|403|permission denied|write access",
|
|
24
|
+
re.IGNORECASE,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
RESET_MODES = {"soft", "mixed", "hard", "merge", "keep"}
|
|
28
|
+
CONFIG_SCOPES = {"global", "local", "system"}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def git_operation(fn):
|
|
32
|
+
def wrapped(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
33
|
+
github_app.require_configured()
|
|
34
|
+
for key in ("username", "password"):
|
|
35
|
+
if key in input_data and input_data[key] is not None:
|
|
36
|
+
raise HandlerError(
|
|
37
|
+
"git credentials are issued by the server; do not pass username or password"
|
|
38
|
+
)
|
|
39
|
+
return fn(daytona, definition, input_data)
|
|
40
|
+
|
|
41
|
+
wrapped.__name__ = fn.__name__
|
|
42
|
+
return wrapped
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@git_operation
|
|
46
|
+
def git_clone(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
47
|
+
url = github_app.https_repo_url(_require_text(input_data, "url"))
|
|
48
|
+
path = require_path(input_data)
|
|
49
|
+
branch = optional_str(input_data, "branch")
|
|
50
|
+
commit_id = optional_str(input_data, "commit_id")
|
|
51
|
+
depth = optional_int(input_data, "depth", min_value=1)
|
|
52
|
+
insecure_skip_tls = optional_bool(input_data, "insecure_skip_tls")
|
|
53
|
+
timeout = _timeout(definition, input_data)
|
|
54
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
55
|
+
_call_with_token(
|
|
56
|
+
url,
|
|
57
|
+
lambda password: sandbox.git.clone(
|
|
58
|
+
url=url,
|
|
59
|
+
path=path,
|
|
60
|
+
branch=branch,
|
|
61
|
+
commit_id=commit_id,
|
|
62
|
+
username=_GIT_USERNAME,
|
|
63
|
+
password=password,
|
|
64
|
+
insecure_skip_tls=insecure_skip_tls,
|
|
65
|
+
depth=depth,
|
|
66
|
+
request_timeout=timeout,
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
return success(
|
|
70
|
+
{
|
|
71
|
+
"url": url,
|
|
72
|
+
"path": path,
|
|
73
|
+
"branch": branch,
|
|
74
|
+
"commit_id": commit_id,
|
|
75
|
+
"depth": depth,
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@git_operation
|
|
81
|
+
def git_status(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
82
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
83
|
+
path = require_path(input_data)
|
|
84
|
+
timeout = _timeout(definition, input_data)
|
|
85
|
+
status = _invoke(lambda: sandbox.git.status(path, request_timeout=timeout))
|
|
86
|
+
max_entries = effective_limit(definition, "max_list_entries")
|
|
87
|
+
files = [_file_status(item) for item in getattr(status, "file_status", None) or []]
|
|
88
|
+
truncated = len(files) > max_entries
|
|
89
|
+
if truncated:
|
|
90
|
+
files = files[:max_entries]
|
|
91
|
+
return success(
|
|
92
|
+
{
|
|
93
|
+
"path": path,
|
|
94
|
+
"current_branch": getattr(status, "current_branch", None),
|
|
95
|
+
"ahead": getattr(status, "ahead", None),
|
|
96
|
+
"behind": getattr(status, "behind", None),
|
|
97
|
+
"branch_published": getattr(status, "branch_published", None),
|
|
98
|
+
"detached": getattr(status, "detached", None),
|
|
99
|
+
"upstream": getattr(status, "upstream", None),
|
|
100
|
+
"file_status": files,
|
|
101
|
+
"count": len(files),
|
|
102
|
+
"truncated": truncated,
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@git_operation
|
|
108
|
+
def git_branches(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
109
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
110
|
+
path = require_path(input_data)
|
|
111
|
+
timeout = _timeout(definition, input_data)
|
|
112
|
+
response = _invoke(lambda: sandbox.git.branches(path, request_timeout=timeout))
|
|
113
|
+
max_entries = effective_limit(definition, "max_list_entries")
|
|
114
|
+
branches = [item for item in (getattr(response, "branches", None) or [])]
|
|
115
|
+
truncated = len(branches) > max_entries
|
|
116
|
+
if truncated:
|
|
117
|
+
branches = branches[:max_entries]
|
|
118
|
+
return success(
|
|
119
|
+
{
|
|
120
|
+
"path": path,
|
|
121
|
+
"branches": branches,
|
|
122
|
+
"current": getattr(response, "current", None),
|
|
123
|
+
"count": len(branches),
|
|
124
|
+
"truncated": truncated,
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@git_operation
|
|
130
|
+
def git_checkout(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
131
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
132
|
+
path = require_path(input_data)
|
|
133
|
+
branch = _require_text(input_data, "branch")
|
|
134
|
+
timeout = _timeout(definition, input_data)
|
|
135
|
+
_invoke(
|
|
136
|
+
lambda: sandbox.git.checkout_branch(path, branch, request_timeout=timeout)
|
|
137
|
+
)
|
|
138
|
+
return success({"path": path, "branch": branch})
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@git_operation
|
|
142
|
+
def git_create_branch(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
143
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
144
|
+
path = require_path(input_data)
|
|
145
|
+
name = _require_text(input_data, "name")
|
|
146
|
+
timeout = _timeout(definition, input_data)
|
|
147
|
+
_invoke(lambda: sandbox.git.create_branch(path, name, request_timeout=timeout))
|
|
148
|
+
return success({"path": path, "name": name})
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@git_operation
|
|
152
|
+
def git_delete_branch(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
153
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
154
|
+
path = require_path(input_data)
|
|
155
|
+
name = _require_text(input_data, "name")
|
|
156
|
+
timeout = _timeout(definition, input_data)
|
|
157
|
+
_invoke(lambda: sandbox.git.delete_branch(path, name, request_timeout=timeout))
|
|
158
|
+
return success({"path": path, "name": name, "deleted": True})
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@git_operation
|
|
162
|
+
def git_add(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
163
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
164
|
+
path = require_path(input_data)
|
|
165
|
+
files = _str_list(input_data, "files", required=True, definition=definition)
|
|
166
|
+
timeout = _timeout(definition, input_data)
|
|
167
|
+
_invoke(lambda: sandbox.git.add(path, files, request_timeout=timeout))
|
|
168
|
+
return success({"path": path, "files": files})
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@git_operation
|
|
172
|
+
def git_commit(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
173
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
174
|
+
path = require_path(input_data)
|
|
175
|
+
message = _require_text(input_data, "message")
|
|
176
|
+
author = _require_text(input_data, "author")
|
|
177
|
+
email = _require_text(input_data, "email")
|
|
178
|
+
allow_empty = optional_bool(input_data, "allow_empty") or False
|
|
179
|
+
timeout = _timeout(definition, input_data)
|
|
180
|
+
response = _invoke(
|
|
181
|
+
lambda: sandbox.git.commit(
|
|
182
|
+
path=path,
|
|
183
|
+
message=message,
|
|
184
|
+
author=author,
|
|
185
|
+
email=email,
|
|
186
|
+
allow_empty=allow_empty,
|
|
187
|
+
request_timeout=timeout,
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
return success(
|
|
191
|
+
{
|
|
192
|
+
"path": path,
|
|
193
|
+
"sha": getattr(response, "sha", None),
|
|
194
|
+
"message": message,
|
|
195
|
+
"author": author,
|
|
196
|
+
"email": email,
|
|
197
|
+
"allow_empty": allow_empty,
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
@git_operation
|
|
203
|
+
def git_push(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
204
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
205
|
+
path = require_path(input_data)
|
|
206
|
+
branch = optional_str(input_data, "branch")
|
|
207
|
+
remote = optional_str(input_data, "remote")
|
|
208
|
+
set_upstream = optional_bool(input_data, "set_upstream") or False
|
|
209
|
+
timeout = _timeout(definition, input_data)
|
|
210
|
+
remote_url = _remote_url(sandbox, path, remote, timeout)
|
|
211
|
+
_call_with_token(
|
|
212
|
+
remote_url,
|
|
213
|
+
lambda password: sandbox.git.push(
|
|
214
|
+
path=path,
|
|
215
|
+
username=_GIT_USERNAME,
|
|
216
|
+
password=password,
|
|
217
|
+
branch=branch,
|
|
218
|
+
remote=remote,
|
|
219
|
+
set_upstream=set_upstream,
|
|
220
|
+
request_timeout=timeout,
|
|
221
|
+
),
|
|
222
|
+
)
|
|
223
|
+
return success(
|
|
224
|
+
{
|
|
225
|
+
"path": path,
|
|
226
|
+
"branch": branch,
|
|
227
|
+
"remote": remote,
|
|
228
|
+
"set_upstream": set_upstream,
|
|
229
|
+
}
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@git_operation
|
|
234
|
+
def git_pull(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
235
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
236
|
+
path = require_path(input_data)
|
|
237
|
+
branch = optional_str(input_data, "branch")
|
|
238
|
+
remote = optional_str(input_data, "remote")
|
|
239
|
+
timeout = _timeout(definition, input_data)
|
|
240
|
+
remote_url = _remote_url(sandbox, path, remote, timeout)
|
|
241
|
+
_call_with_token(
|
|
242
|
+
remote_url,
|
|
243
|
+
lambda password: sandbox.git.pull(
|
|
244
|
+
path=path,
|
|
245
|
+
username=_GIT_USERNAME,
|
|
246
|
+
password=password,
|
|
247
|
+
branch=branch,
|
|
248
|
+
remote=remote,
|
|
249
|
+
request_timeout=timeout,
|
|
250
|
+
),
|
|
251
|
+
)
|
|
252
|
+
return success(
|
|
253
|
+
{
|
|
254
|
+
"path": path,
|
|
255
|
+
"branch": branch,
|
|
256
|
+
"remote": remote,
|
|
257
|
+
}
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@git_operation
|
|
262
|
+
def git_init(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
263
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
264
|
+
path = require_path(input_data)
|
|
265
|
+
bare = optional_bool(input_data, "bare") or False
|
|
266
|
+
initial_branch = optional_str(input_data, "initial_branch")
|
|
267
|
+
timeout = _timeout(definition, input_data)
|
|
268
|
+
_invoke(
|
|
269
|
+
lambda: sandbox.git.init(
|
|
270
|
+
path,
|
|
271
|
+
bare=bare,
|
|
272
|
+
initial_branch=initial_branch,
|
|
273
|
+
request_timeout=timeout,
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
return success({"path": path, "bare": bare, "initial_branch": initial_branch})
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
@git_operation
|
|
280
|
+
def git_reset(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
281
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
282
|
+
path = require_path(input_data)
|
|
283
|
+
mode = optional_str(input_data, "mode")
|
|
284
|
+
if mode is not None:
|
|
285
|
+
mode = mode.lower()
|
|
286
|
+
if mode not in RESET_MODES:
|
|
287
|
+
raise HandlerError("mode must be soft, mixed, hard, merge, or keep")
|
|
288
|
+
target = optional_str(input_data, "target")
|
|
289
|
+
files = _str_list(input_data, "files", required=False, definition=definition)
|
|
290
|
+
timeout = _timeout(definition, input_data)
|
|
291
|
+
_invoke(
|
|
292
|
+
lambda: sandbox.git.reset(
|
|
293
|
+
path,
|
|
294
|
+
mode=mode,
|
|
295
|
+
target=target,
|
|
296
|
+
files=files,
|
|
297
|
+
request_timeout=timeout,
|
|
298
|
+
)
|
|
299
|
+
)
|
|
300
|
+
return success({"path": path, "mode": mode, "target": target, "files": files})
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
@git_operation
|
|
304
|
+
def git_restore(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
305
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
306
|
+
path = require_path(input_data)
|
|
307
|
+
files = _str_list(input_data, "files", required=True, definition=definition)
|
|
308
|
+
staged = optional_bool(input_data, "staged")
|
|
309
|
+
worktree = optional_bool(input_data, "worktree")
|
|
310
|
+
source = optional_str(input_data, "source")
|
|
311
|
+
timeout = _timeout(definition, input_data)
|
|
312
|
+
_invoke(
|
|
313
|
+
lambda: sandbox.git.restore(
|
|
314
|
+
path,
|
|
315
|
+
files,
|
|
316
|
+
staged=staged,
|
|
317
|
+
worktree=worktree,
|
|
318
|
+
source=source,
|
|
319
|
+
request_timeout=timeout,
|
|
320
|
+
)
|
|
321
|
+
)
|
|
322
|
+
return success(
|
|
323
|
+
{
|
|
324
|
+
"path": path,
|
|
325
|
+
"files": files,
|
|
326
|
+
"staged": staged,
|
|
327
|
+
"worktree": worktree,
|
|
328
|
+
"source": source,
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
@git_operation
|
|
334
|
+
def git_remote_add(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
335
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
336
|
+
path = require_path(input_data)
|
|
337
|
+
name = _require_text(input_data, "name")
|
|
338
|
+
url = _require_text(input_data, "url")
|
|
339
|
+
fetch = optional_bool(input_data, "fetch") or False
|
|
340
|
+
overwrite = optional_bool(input_data, "overwrite") or False
|
|
341
|
+
timeout = _timeout(definition, input_data)
|
|
342
|
+
_invoke(
|
|
343
|
+
lambda: sandbox.git.remote_add(
|
|
344
|
+
path,
|
|
345
|
+
name,
|
|
346
|
+
url,
|
|
347
|
+
fetch=fetch,
|
|
348
|
+
overwrite=overwrite,
|
|
349
|
+
request_timeout=timeout,
|
|
350
|
+
)
|
|
351
|
+
)
|
|
352
|
+
return success(
|
|
353
|
+
{
|
|
354
|
+
"path": path,
|
|
355
|
+
"name": name,
|
|
356
|
+
"url": url,
|
|
357
|
+
"fetch": fetch,
|
|
358
|
+
"overwrite": overwrite,
|
|
359
|
+
}
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
@git_operation
|
|
364
|
+
def git_remotes(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
365
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
366
|
+
path = require_path(input_data)
|
|
367
|
+
timeout = _timeout(definition, input_data)
|
|
368
|
+
response = _invoke(lambda: sandbox.git.remotes(path, request_timeout=timeout))
|
|
369
|
+
max_entries = effective_limit(definition, "max_list_entries")
|
|
370
|
+
remotes = [
|
|
371
|
+
{"name": getattr(item, "name", None), "url": getattr(item, "url", None)}
|
|
372
|
+
for item in (getattr(response, "remotes", None) or [])
|
|
373
|
+
]
|
|
374
|
+
truncated = len(remotes) > max_entries
|
|
375
|
+
if truncated:
|
|
376
|
+
remotes = remotes[:max_entries]
|
|
377
|
+
return success(
|
|
378
|
+
{
|
|
379
|
+
"path": path,
|
|
380
|
+
"remotes": remotes,
|
|
381
|
+
"count": len(remotes),
|
|
382
|
+
"truncated": truncated,
|
|
383
|
+
}
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
@git_operation
|
|
388
|
+
def git_remote_get(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
389
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
390
|
+
path = require_path(input_data)
|
|
391
|
+
name = _require_text(input_data, "name")
|
|
392
|
+
timeout = _timeout(definition, input_data)
|
|
393
|
+
url = _invoke(lambda: sandbox.git.remote_get(path, name, request_timeout=timeout))
|
|
394
|
+
return success({"path": path, "name": name, "url": url})
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
@git_operation
|
|
398
|
+
def git_set_config(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
399
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
400
|
+
key = _require_text(input_data, "key")
|
|
401
|
+
value = _require_text(input_data, "value")
|
|
402
|
+
scope, path = _config_location(input_data)
|
|
403
|
+
timeout = _timeout(definition, input_data)
|
|
404
|
+
_invoke(
|
|
405
|
+
lambda: sandbox.git.set_config(
|
|
406
|
+
key,
|
|
407
|
+
value,
|
|
408
|
+
scope=scope,
|
|
409
|
+
path=path,
|
|
410
|
+
request_timeout=timeout,
|
|
411
|
+
)
|
|
412
|
+
)
|
|
413
|
+
return success({"key": key, "value": value, "scope": scope, "path": path})
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
@git_operation
|
|
417
|
+
def git_get_config(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
418
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
419
|
+
key = _require_text(input_data, "key")
|
|
420
|
+
scope, path = _config_location(input_data)
|
|
421
|
+
timeout = _timeout(definition, input_data)
|
|
422
|
+
value = _invoke(
|
|
423
|
+
lambda: sandbox.git.get_config(
|
|
424
|
+
key,
|
|
425
|
+
scope=scope,
|
|
426
|
+
path=path,
|
|
427
|
+
request_timeout=timeout,
|
|
428
|
+
)
|
|
429
|
+
)
|
|
430
|
+
return success({"key": key, "value": value, "scope": scope, "path": path})
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
@git_operation
|
|
434
|
+
def git_configure_user(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
435
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
436
|
+
name = _require_text(input_data, "name")
|
|
437
|
+
email = _require_text(input_data, "email")
|
|
438
|
+
scope, path = _config_location(input_data)
|
|
439
|
+
timeout = _timeout(definition, input_data)
|
|
440
|
+
_invoke(
|
|
441
|
+
lambda: sandbox.git.configure_user(
|
|
442
|
+
name,
|
|
443
|
+
email,
|
|
444
|
+
scope=scope,
|
|
445
|
+
path=path,
|
|
446
|
+
request_timeout=timeout,
|
|
447
|
+
)
|
|
448
|
+
)
|
|
449
|
+
return success({"name": name, "email": email, "scope": scope, "path": path})
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
@git_operation
|
|
453
|
+
def git_authenticate(daytona: Daytona, definition: dict, input_data: dict) -> dict:
|
|
454
|
+
sandbox = get_running_sandbox(daytona, input_data, definition)
|
|
455
|
+
path = require_path(input_data)
|
|
456
|
+
remote = optional_str(input_data, "remote")
|
|
457
|
+
timeout = _timeout(definition, input_data)
|
|
458
|
+
remote_url = _remote_url(sandbox, path, remote, timeout)
|
|
459
|
+
_call_with_token(
|
|
460
|
+
remote_url,
|
|
461
|
+
lambda password: sandbox.git.dangerously_authenticate(
|
|
462
|
+
_GIT_USERNAME,
|
|
463
|
+
password,
|
|
464
|
+
host="github.com",
|
|
465
|
+
protocol="https",
|
|
466
|
+
request_timeout=timeout,
|
|
467
|
+
),
|
|
468
|
+
)
|
|
469
|
+
return success(
|
|
470
|
+
{
|
|
471
|
+
"path": path,
|
|
472
|
+
"remote": remote or "origin",
|
|
473
|
+
"host": "github.com",
|
|
474
|
+
"protocol": "https",
|
|
475
|
+
"authenticated": True,
|
|
476
|
+
}
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def _timeout(definition: dict, input_data: dict) -> int:
|
|
481
|
+
return resolve_timeout(
|
|
482
|
+
input_data,
|
|
483
|
+
definition,
|
|
484
|
+
ceiling_key="max_exec_timeout",
|
|
485
|
+
default=effective_limit(definition, "max_exec_timeout"),
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
def _invoke(action, *, password: str | None = None):
|
|
490
|
+
try:
|
|
491
|
+
return action()
|
|
492
|
+
except DaytonaError as exc:
|
|
493
|
+
mapped = map_daytona(exc)
|
|
494
|
+
if password and password in mapped.message:
|
|
495
|
+
mapped = HandlerError(
|
|
496
|
+
mapped.message.replace(password, "[redacted]"),
|
|
497
|
+
mapped.code,
|
|
498
|
+
)
|
|
499
|
+
raise mapped from exc
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def _call_with_token(url: str, action):
|
|
503
|
+
owner, repo = github_app.parse_github_repo(url)
|
|
504
|
+
password = github_app.installation_token(owner, repo)
|
|
505
|
+
try:
|
|
506
|
+
return _invoke(lambda: action(password), password=password)
|
|
507
|
+
except HandlerError as exc:
|
|
508
|
+
if not _stale_token(exc):
|
|
509
|
+
raise
|
|
510
|
+
github_app.invalidate_token(owner, repo)
|
|
511
|
+
password = github_app.installation_token(owner, repo)
|
|
512
|
+
return _invoke(lambda: action(password), password=password)
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def _stale_token(exc: HandlerError) -> bool:
|
|
516
|
+
if exc.code in {"not_found", "forbidden"}:
|
|
517
|
+
return True
|
|
518
|
+
return exc.code == "daytona_error" and _STALE_TOKEN_RE.search(exc.message) is not None
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def _remote_url(sandbox, path: str, remote: str | None, timeout: int) -> str:
|
|
522
|
+
remote_name = remote or "origin"
|
|
523
|
+
url = _invoke(
|
|
524
|
+
lambda: sandbox.git.remote_get(path, remote_name, request_timeout=timeout)
|
|
525
|
+
)
|
|
526
|
+
if not isinstance(url, str) or not url.strip():
|
|
527
|
+
raise HandlerError(f"remote {remote_name} was not found")
|
|
528
|
+
if not url.strip().startswith("https://"):
|
|
529
|
+
raise HandlerError(
|
|
530
|
+
"git remotes must use https://github.com for GitHub App authentication"
|
|
531
|
+
)
|
|
532
|
+
return url.strip()
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
def _require_text(data: dict, key: str) -> str:
|
|
536
|
+
value = require_str(data, key)
|
|
537
|
+
if "\x00" in value:
|
|
538
|
+
raise HandlerError(f"{key} contains NUL")
|
|
539
|
+
return value
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def _config_location(data: dict) -> tuple[str, str | None]:
|
|
543
|
+
scope = (optional_str(data, "scope") or "global").lower()
|
|
544
|
+
if scope not in CONFIG_SCOPES:
|
|
545
|
+
raise HandlerError("scope must be global, local, or system")
|
|
546
|
+
if scope == "local":
|
|
547
|
+
return scope, require_path(data)
|
|
548
|
+
if "path" not in data or data["path"] is None:
|
|
549
|
+
return scope, None
|
|
550
|
+
return scope, require_path(data)
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
def _str_list(data: dict, key: str, *, required: bool, definition: dict) -> list[str] | None:
|
|
554
|
+
if key not in data or data[key] is None:
|
|
555
|
+
if required:
|
|
556
|
+
raise HandlerError(f"{key} is required")
|
|
557
|
+
return None
|
|
558
|
+
value = data[key]
|
|
559
|
+
if not isinstance(value, list):
|
|
560
|
+
raise HandlerError(f"{key} must be a list")
|
|
561
|
+
if not value:
|
|
562
|
+
raise HandlerError(f"{key} must not be empty")
|
|
563
|
+
max_items = effective_limit(definition, "max_list_entries")
|
|
564
|
+
if len(value) > max_items:
|
|
565
|
+
raise HandlerError(
|
|
566
|
+
f"{key} has {len(value)} entries, which exceeds max_list_entries={max_items}",
|
|
567
|
+
"limit_exceeded",
|
|
568
|
+
)
|
|
569
|
+
items: list[str] = []
|
|
570
|
+
for index, item in enumerate(value):
|
|
571
|
+
if not isinstance(item, str) or not item.strip():
|
|
572
|
+
raise HandlerError(f"{key}[{index}] must be a non-empty string")
|
|
573
|
+
if "\x00" in item:
|
|
574
|
+
raise HandlerError(f"{key}[{index}] contains NUL")
|
|
575
|
+
items.append(item.strip())
|
|
576
|
+
return items
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def _file_status(item) -> dict:
|
|
580
|
+
return {
|
|
581
|
+
"name": getattr(item, "name", None),
|
|
582
|
+
"extra": getattr(item, "extra", None),
|
|
583
|
+
"staging": enum_value(getattr(item, "staging", None)),
|
|
584
|
+
"worktree": enum_value(getattr(item, "worktree", None)),
|
|
585
|
+
}
|