codex-autorunner 0.1.2__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codex_autorunner/__init__.py +12 -1
- codex_autorunner/__main__.py +4 -0
- codex_autorunner/agents/codex/harness.py +1 -1
- codex_autorunner/agents/opencode/client.py +68 -35
- codex_autorunner/agents/opencode/constants.py +3 -0
- codex_autorunner/agents/opencode/harness.py +6 -1
- codex_autorunner/agents/opencode/logging.py +21 -5
- codex_autorunner/agents/opencode/run_prompt.py +1 -0
- codex_autorunner/agents/opencode/runtime.py +176 -47
- codex_autorunner/agents/opencode/supervisor.py +36 -48
- codex_autorunner/agents/registry.py +155 -8
- codex_autorunner/api.py +25 -0
- codex_autorunner/bootstrap.py +22 -37
- codex_autorunner/cli.py +5 -1156
- codex_autorunner/codex_cli.py +20 -84
- codex_autorunner/core/__init__.py +4 -0
- codex_autorunner/core/about_car.py +49 -32
- codex_autorunner/core/adapter_utils.py +21 -0
- codex_autorunner/core/app_server_ids.py +59 -0
- codex_autorunner/core/app_server_logging.py +7 -3
- codex_autorunner/core/app_server_prompts.py +27 -260
- codex_autorunner/core/app_server_threads.py +26 -28
- codex_autorunner/core/app_server_utils.py +165 -0
- codex_autorunner/core/archive.py +349 -0
- codex_autorunner/core/codex_runner.py +12 -2
- codex_autorunner/core/config.py +587 -103
- codex_autorunner/core/docs.py +10 -2
- codex_autorunner/core/drafts.py +136 -0
- codex_autorunner/core/engine.py +1531 -866
- codex_autorunner/core/exceptions.py +4 -0
- codex_autorunner/core/flows/__init__.py +25 -0
- codex_autorunner/core/flows/controller.py +202 -0
- codex_autorunner/core/flows/definition.py +82 -0
- codex_autorunner/core/flows/models.py +88 -0
- codex_autorunner/core/flows/reasons.py +52 -0
- codex_autorunner/core/flows/reconciler.py +131 -0
- codex_autorunner/core/flows/runtime.py +382 -0
- codex_autorunner/core/flows/store.py +568 -0
- codex_autorunner/core/flows/transition.py +138 -0
- codex_autorunner/core/flows/ux_helpers.py +257 -0
- codex_autorunner/core/flows/worker_process.py +242 -0
- codex_autorunner/core/git_utils.py +62 -0
- codex_autorunner/core/hub.py +136 -16
- codex_autorunner/core/locks.py +4 -0
- codex_autorunner/core/notifications.py +14 -2
- codex_autorunner/core/ports/__init__.py +28 -0
- codex_autorunner/core/ports/agent_backend.py +150 -0
- codex_autorunner/core/ports/backend_orchestrator.py +41 -0
- codex_autorunner/core/ports/run_event.py +91 -0
- codex_autorunner/core/prompt.py +15 -7
- codex_autorunner/core/redaction.py +29 -0
- codex_autorunner/core/review_context.py +5 -8
- codex_autorunner/core/run_index.py +6 -0
- codex_autorunner/core/runner_process.py +5 -2
- codex_autorunner/core/state.py +0 -88
- codex_autorunner/core/state_roots.py +57 -0
- codex_autorunner/core/supervisor_protocol.py +15 -0
- codex_autorunner/core/supervisor_utils.py +67 -0
- codex_autorunner/core/text_delta_coalescer.py +54 -0
- codex_autorunner/core/ticket_linter_cli.py +201 -0
- codex_autorunner/core/ticket_manager_cli.py +432 -0
- codex_autorunner/core/update.py +24 -16
- codex_autorunner/core/update_paths.py +28 -0
- codex_autorunner/core/update_runner.py +2 -0
- codex_autorunner/core/usage.py +164 -12
- codex_autorunner/core/utils.py +120 -11
- codex_autorunner/discovery.py +2 -4
- codex_autorunner/flows/review/__init__.py +17 -0
- codex_autorunner/{core/review.py → flows/review/service.py} +15 -10
- codex_autorunner/flows/ticket_flow/__init__.py +3 -0
- codex_autorunner/flows/ticket_flow/definition.py +98 -0
- codex_autorunner/integrations/agents/__init__.py +17 -0
- codex_autorunner/integrations/agents/backend_orchestrator.py +284 -0
- codex_autorunner/integrations/agents/codex_adapter.py +90 -0
- codex_autorunner/integrations/agents/codex_backend.py +448 -0
- codex_autorunner/integrations/agents/opencode_adapter.py +108 -0
- codex_autorunner/integrations/agents/opencode_backend.py +598 -0
- codex_autorunner/integrations/agents/runner.py +91 -0
- codex_autorunner/integrations/agents/wiring.py +271 -0
- codex_autorunner/integrations/app_server/client.py +583 -152
- codex_autorunner/integrations/app_server/env.py +2 -107
- codex_autorunner/{core/app_server_events.py → integrations/app_server/event_buffer.py} +15 -8
- codex_autorunner/integrations/app_server/supervisor.py +59 -33
- codex_autorunner/integrations/telegram/adapter.py +204 -165
- codex_autorunner/integrations/telegram/api_schemas.py +120 -0
- codex_autorunner/integrations/telegram/config.py +221 -0
- codex_autorunner/integrations/telegram/constants.py +17 -2
- codex_autorunner/integrations/telegram/dispatch.py +17 -0
- codex_autorunner/integrations/telegram/doctor.py +47 -0
- codex_autorunner/integrations/telegram/handlers/callbacks.py +7 -4
- codex_autorunner/integrations/telegram/handlers/commands/__init__.py +2 -0
- codex_autorunner/integrations/telegram/handlers/commands/execution.py +53 -57
- codex_autorunner/integrations/telegram/handlers/commands/files.py +2 -6
- codex_autorunner/integrations/telegram/handlers/commands/flows.py +1364 -0
- codex_autorunner/integrations/telegram/handlers/commands/formatting.py +1 -1
- codex_autorunner/integrations/telegram/handlers/commands/github.py +41 -582
- codex_autorunner/integrations/telegram/handlers/commands/workspace.py +8 -8
- codex_autorunner/integrations/telegram/handlers/commands_runtime.py +137 -478
- codex_autorunner/integrations/telegram/handlers/commands_spec.py +17 -4
- codex_autorunner/integrations/telegram/handlers/messages.py +121 -9
- codex_autorunner/integrations/telegram/handlers/selections.py +61 -1
- codex_autorunner/integrations/telegram/helpers.py +111 -16
- codex_autorunner/integrations/telegram/outbox.py +208 -37
- codex_autorunner/integrations/telegram/progress_stream.py +3 -10
- codex_autorunner/integrations/telegram/service.py +221 -42
- codex_autorunner/integrations/telegram/state.py +100 -2
- codex_autorunner/integrations/telegram/ticket_flow_bridge.py +611 -0
- codex_autorunner/integrations/telegram/transport.py +39 -4
- codex_autorunner/integrations/telegram/trigger_mode.py +53 -0
- codex_autorunner/manifest.py +2 -0
- codex_autorunner/plugin_api.py +22 -0
- codex_autorunner/routes/__init__.py +37 -67
- codex_autorunner/routes/agents.py +2 -137
- codex_autorunner/routes/analytics.py +3 -0
- codex_autorunner/routes/app_server.py +2 -131
- codex_autorunner/routes/base.py +2 -624
- codex_autorunner/routes/file_chat.py +7 -0
- codex_autorunner/routes/flows.py +7 -0
- codex_autorunner/routes/messages.py +7 -0
- codex_autorunner/routes/repos.py +2 -196
- codex_autorunner/routes/review.py +2 -147
- codex_autorunner/routes/sessions.py +2 -175
- codex_autorunner/routes/settings.py +2 -168
- codex_autorunner/routes/shared.py +2 -275
- codex_autorunner/routes/system.py +4 -188
- codex_autorunner/routes/usage.py +3 -0
- codex_autorunner/routes/voice.py +2 -119
- codex_autorunner/routes/workspace.py +3 -0
- codex_autorunner/server.py +3 -2
- codex_autorunner/static/agentControls.js +41 -11
- codex_autorunner/static/agentEvents.js +248 -0
- codex_autorunner/static/app.js +35 -24
- codex_autorunner/static/archive.js +826 -0
- codex_autorunner/static/archiveApi.js +37 -0
- codex_autorunner/static/autoRefresh.js +36 -8
- codex_autorunner/static/bootstrap.js +1 -0
- codex_autorunner/static/bus.js +1 -0
- codex_autorunner/static/cache.js +1 -0
- codex_autorunner/static/constants.js +20 -4
- codex_autorunner/static/dashboard.js +344 -325
- codex_autorunner/static/diffRenderer.js +37 -0
- codex_autorunner/static/docChatCore.js +324 -0
- codex_autorunner/static/docChatStorage.js +65 -0
- codex_autorunner/static/docChatVoice.js +65 -0
- codex_autorunner/static/docEditor.js +133 -0
- codex_autorunner/static/env.js +1 -0
- codex_autorunner/static/eventSummarizer.js +166 -0
- codex_autorunner/static/fileChat.js +182 -0
- codex_autorunner/static/health.js +155 -0
- codex_autorunner/static/hub.js +126 -185
- codex_autorunner/static/index.html +839 -863
- codex_autorunner/static/liveUpdates.js +1 -0
- codex_autorunner/static/loader.js +1 -0
- codex_autorunner/static/messages.js +873 -0
- codex_autorunner/static/mobileCompact.js +2 -1
- codex_autorunner/static/preserve.js +17 -0
- codex_autorunner/static/settings.js +149 -217
- codex_autorunner/static/smartRefresh.js +52 -0
- codex_autorunner/static/styles.css +8850 -3876
- codex_autorunner/static/tabs.js +175 -11
- codex_autorunner/static/terminal.js +32 -0
- codex_autorunner/static/terminalManager.js +34 -59
- codex_autorunner/static/ticketChatActions.js +333 -0
- codex_autorunner/static/ticketChatEvents.js +16 -0
- codex_autorunner/static/ticketChatStorage.js +16 -0
- codex_autorunner/static/ticketChatStream.js +264 -0
- codex_autorunner/static/ticketEditor.js +844 -0
- codex_autorunner/static/ticketVoice.js +9 -0
- codex_autorunner/static/tickets.js +1988 -0
- codex_autorunner/static/utils.js +43 -3
- codex_autorunner/static/voice.js +1 -0
- codex_autorunner/static/workspace.js +765 -0
- codex_autorunner/static/workspaceApi.js +53 -0
- codex_autorunner/static/workspaceFileBrowser.js +504 -0
- codex_autorunner/surfaces/__init__.py +5 -0
- codex_autorunner/surfaces/cli/__init__.py +6 -0
- codex_autorunner/surfaces/cli/cli.py +1224 -0
- codex_autorunner/surfaces/cli/codex_cli.py +20 -0
- codex_autorunner/surfaces/telegram/__init__.py +3 -0
- codex_autorunner/surfaces/web/__init__.py +1 -0
- codex_autorunner/surfaces/web/app.py +2019 -0
- codex_autorunner/surfaces/web/hub_jobs.py +192 -0
- codex_autorunner/surfaces/web/middleware.py +587 -0
- codex_autorunner/surfaces/web/pty_session.py +370 -0
- codex_autorunner/surfaces/web/review.py +6 -0
- codex_autorunner/surfaces/web/routes/__init__.py +78 -0
- codex_autorunner/surfaces/web/routes/agents.py +138 -0
- codex_autorunner/surfaces/web/routes/analytics.py +277 -0
- codex_autorunner/surfaces/web/routes/app_server.py +132 -0
- codex_autorunner/surfaces/web/routes/archive.py +357 -0
- codex_autorunner/surfaces/web/routes/base.py +615 -0
- codex_autorunner/surfaces/web/routes/file_chat.py +836 -0
- codex_autorunner/surfaces/web/routes/flows.py +1164 -0
- codex_autorunner/surfaces/web/routes/messages.py +459 -0
- codex_autorunner/surfaces/web/routes/repos.py +197 -0
- codex_autorunner/surfaces/web/routes/review.py +148 -0
- codex_autorunner/surfaces/web/routes/sessions.py +176 -0
- codex_autorunner/surfaces/web/routes/settings.py +169 -0
- codex_autorunner/surfaces/web/routes/shared.py +280 -0
- codex_autorunner/surfaces/web/routes/system.py +196 -0
- codex_autorunner/surfaces/web/routes/usage.py +89 -0
- codex_autorunner/surfaces/web/routes/voice.py +120 -0
- codex_autorunner/surfaces/web/routes/workspace.py +271 -0
- codex_autorunner/surfaces/web/runner_manager.py +25 -0
- codex_autorunner/surfaces/web/schemas.py +417 -0
- codex_autorunner/surfaces/web/static_assets.py +490 -0
- codex_autorunner/surfaces/web/static_refresh.py +86 -0
- codex_autorunner/surfaces/web/terminal_sessions.py +78 -0
- codex_autorunner/tickets/__init__.py +27 -0
- codex_autorunner/tickets/agent_pool.py +399 -0
- codex_autorunner/tickets/files.py +89 -0
- codex_autorunner/tickets/frontmatter.py +55 -0
- codex_autorunner/tickets/lint.py +102 -0
- codex_autorunner/tickets/models.py +97 -0
- codex_autorunner/tickets/outbox.py +244 -0
- codex_autorunner/tickets/replies.py +179 -0
- codex_autorunner/tickets/runner.py +881 -0
- codex_autorunner/tickets/spec_ingest.py +77 -0
- codex_autorunner/web/__init__.py +5 -1
- codex_autorunner/web/app.py +2 -1771
- codex_autorunner/web/hub_jobs.py +2 -191
- codex_autorunner/web/middleware.py +2 -587
- codex_autorunner/web/pty_session.py +2 -369
- codex_autorunner/web/runner_manager.py +2 -24
- codex_autorunner/web/schemas.py +2 -396
- codex_autorunner/web/static_assets.py +4 -484
- codex_autorunner/web/static_refresh.py +2 -85
- codex_autorunner/web/terminal_sessions.py +2 -77
- codex_autorunner/workspace/__init__.py +40 -0
- codex_autorunner/workspace/paths.py +335 -0
- codex_autorunner-1.1.0.dist-info/METADATA +154 -0
- codex_autorunner-1.1.0.dist-info/RECORD +308 -0
- {codex_autorunner-0.1.2.dist-info → codex_autorunner-1.1.0.dist-info}/WHEEL +1 -1
- codex_autorunner/agents/execution/policy.py +0 -292
- codex_autorunner/agents/factory.py +0 -52
- codex_autorunner/agents/orchestrator.py +0 -358
- codex_autorunner/core/doc_chat.py +0 -1446
- codex_autorunner/core/snapshot.py +0 -580
- codex_autorunner/integrations/github/chatops.py +0 -268
- codex_autorunner/integrations/github/pr_flow.py +0 -1314
- codex_autorunner/routes/docs.py +0 -381
- codex_autorunner/routes/github.py +0 -327
- codex_autorunner/routes/runs.py +0 -250
- codex_autorunner/spec_ingest.py +0 -812
- codex_autorunner/static/docChatActions.js +0 -287
- codex_autorunner/static/docChatEvents.js +0 -300
- codex_autorunner/static/docChatRender.js +0 -205
- codex_autorunner/static/docChatStream.js +0 -361
- codex_autorunner/static/docs.js +0 -20
- codex_autorunner/static/docsClipboard.js +0 -69
- codex_autorunner/static/docsCrud.js +0 -257
- codex_autorunner/static/docsDocUpdates.js +0 -62
- codex_autorunner/static/docsDrafts.js +0 -16
- codex_autorunner/static/docsElements.js +0 -69
- codex_autorunner/static/docsInit.js +0 -285
- codex_autorunner/static/docsParse.js +0 -160
- codex_autorunner/static/docsSnapshot.js +0 -87
- codex_autorunner/static/docsSpecIngest.js +0 -263
- codex_autorunner/static/docsState.js +0 -127
- codex_autorunner/static/docsThreadRegistry.js +0 -44
- codex_autorunner/static/docsUi.js +0 -153
- codex_autorunner/static/docsVoice.js +0 -56
- codex_autorunner/static/github.js +0 -504
- codex_autorunner/static/logs.js +0 -678
- codex_autorunner/static/review.js +0 -157
- codex_autorunner/static/runs.js +0 -418
- codex_autorunner/static/snapshot.js +0 -124
- codex_autorunner/static/state.js +0 -94
- codex_autorunner/static/todoPreview.js +0 -27
- codex_autorunner/workspace.py +0 -16
- codex_autorunner-0.1.2.dist-info/METADATA +0 -249
- codex_autorunner-0.1.2.dist-info/RECORD +0 -222
- /codex_autorunner/{routes → surfaces/web/routes}/terminal_images.py +0 -0
- {codex_autorunner-0.1.2.dist-info → codex_autorunner-1.1.0.dist-info}/entry_points.txt +0 -0
- {codex_autorunner-0.1.2.dist-info → codex_autorunner-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {codex_autorunner-0.1.2.dist-info → codex_autorunner-1.1.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// GENERATED FILE - do not edit directly. Source: static_src/
|
|
2
|
+
import { api, resolvePath } from "./utils.js";
|
|
3
|
+
export async function fetchWorkspace() {
|
|
4
|
+
return (await api("/api/workspace"));
|
|
5
|
+
}
|
|
6
|
+
export async function writeWorkspace(kind, content) {
|
|
7
|
+
return (await api(`/api/workspace/${kind}`, {
|
|
8
|
+
method: "PUT",
|
|
9
|
+
body: { content },
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
export async function listWorkspaceFiles() {
|
|
13
|
+
const res = (await api("/api/workspace/files"));
|
|
14
|
+
if (Array.isArray(res))
|
|
15
|
+
return res;
|
|
16
|
+
return res.files ?? [];
|
|
17
|
+
}
|
|
18
|
+
export async function ingestSpecToTickets() {
|
|
19
|
+
return (await api("/api/workspace/spec/ingest", { method: "POST" }));
|
|
20
|
+
}
|
|
21
|
+
export async function listTickets() {
|
|
22
|
+
return (await api("/api/flows/ticket_flow/tickets"));
|
|
23
|
+
}
|
|
24
|
+
export async function fetchWorkspaceTree() {
|
|
25
|
+
const res = (await api("/api/workspace/tree"));
|
|
26
|
+
return res.tree || [];
|
|
27
|
+
}
|
|
28
|
+
export async function uploadWorkspaceFiles(files, subdir) {
|
|
29
|
+
const fd = new FormData();
|
|
30
|
+
Array.from(files).forEach((file) => fd.append("files", file));
|
|
31
|
+
if (subdir)
|
|
32
|
+
fd.append("subdir", subdir);
|
|
33
|
+
return api("/api/workspace/upload", { method: "POST", body: fd });
|
|
34
|
+
}
|
|
35
|
+
export function downloadWorkspaceFile(path) {
|
|
36
|
+
const url = resolvePath(`/api/workspace/download?path=${encodeURIComponent(path)}`);
|
|
37
|
+
window.location.href = url;
|
|
38
|
+
}
|
|
39
|
+
export function downloadWorkspaceZip(path) {
|
|
40
|
+
const url = path
|
|
41
|
+
? resolvePath(`/api/workspace/download-zip?path=${encodeURIComponent(path)}`)
|
|
42
|
+
: resolvePath("/api/workspace/download-zip");
|
|
43
|
+
window.location.href = url;
|
|
44
|
+
}
|
|
45
|
+
export async function createWorkspaceFolder(path) {
|
|
46
|
+
await api(`/api/workspace/folder?path=${encodeURIComponent(path)}`, { method: "POST" });
|
|
47
|
+
}
|
|
48
|
+
export async function deleteWorkspaceFile(path) {
|
|
49
|
+
await api(`/api/workspace/file?path=${encodeURIComponent(path)}`, { method: "DELETE" });
|
|
50
|
+
}
|
|
51
|
+
export async function deleteWorkspaceFolder(path) {
|
|
52
|
+
await api(`/api/workspace/folder?path=${encodeURIComponent(path)}`, { method: "DELETE" });
|
|
53
|
+
}
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
// GENERATED FILE - do not edit directly. Source: static_src/
|
|
2
|
+
import { deleteWorkspaceFile, deleteWorkspaceFolder, downloadWorkspaceFile, downloadWorkspaceZip } from "./workspaceApi.js";
|
|
3
|
+
import { flash } from "./utils.js";
|
|
4
|
+
export class WorkspaceFileBrowser {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.tree = [];
|
|
7
|
+
this.currentPath = "";
|
|
8
|
+
this.selectedPath = null;
|
|
9
|
+
this.container = options.container;
|
|
10
|
+
this.selectEl = options.selectEl ?? null;
|
|
11
|
+
this.breadcrumbsEl = options.breadcrumbsEl ?? null;
|
|
12
|
+
this.onSelect = options.onSelect;
|
|
13
|
+
this.onPathChange = options.onPathChange;
|
|
14
|
+
this.onRefresh = options.onRefresh ?? (() => { });
|
|
15
|
+
this.onConfirm = options.onConfirm;
|
|
16
|
+
this.fileBtnEl = document.getElementById("workspace-file-pill");
|
|
17
|
+
this.fileBtnNameEl = document.getElementById("workspace-file-pill-name");
|
|
18
|
+
this.modalEl = document.getElementById("file-picker-modal");
|
|
19
|
+
this.modalBodyEl = document.getElementById("file-picker-body");
|
|
20
|
+
this.modalCloseEl = document.getElementById("file-picker-close");
|
|
21
|
+
this.initFilePicker();
|
|
22
|
+
}
|
|
23
|
+
setTree(tree, defaultPath) {
|
|
24
|
+
this.tree = tree || [];
|
|
25
|
+
const next = this.pickInitialSelection(defaultPath);
|
|
26
|
+
const shouldTrigger = !!next && next !== this.selectedPath;
|
|
27
|
+
const didSelect = next ? this.select(next, shouldTrigger) : false;
|
|
28
|
+
if (!didSelect)
|
|
29
|
+
this.render();
|
|
30
|
+
}
|
|
31
|
+
getCurrentPath() {
|
|
32
|
+
return this.currentPath;
|
|
33
|
+
}
|
|
34
|
+
navigateTo(path) {
|
|
35
|
+
this.currentPath = path;
|
|
36
|
+
if (this.onPathChange)
|
|
37
|
+
this.onPathChange(this.currentPath);
|
|
38
|
+
this.render();
|
|
39
|
+
this.renderModal();
|
|
40
|
+
}
|
|
41
|
+
select(path, trigger = true) {
|
|
42
|
+
const node = this.findNode(path);
|
|
43
|
+
if (!node || node.type !== "file") {
|
|
44
|
+
this.render();
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
this.selectedPath = path;
|
|
48
|
+
this.currentPath = this.parentPath(path);
|
|
49
|
+
if (this.onPathChange)
|
|
50
|
+
this.onPathChange(this.currentPath);
|
|
51
|
+
this.updateFileName(node.name);
|
|
52
|
+
this.updateSelect(path);
|
|
53
|
+
this.render();
|
|
54
|
+
if (trigger)
|
|
55
|
+
this.onSelect(node);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
refresh() {
|
|
59
|
+
this.render();
|
|
60
|
+
this.renderModal();
|
|
61
|
+
}
|
|
62
|
+
pickInitialSelection(defaultPath) {
|
|
63
|
+
if (defaultPath && this.findNode(defaultPath))
|
|
64
|
+
return defaultPath;
|
|
65
|
+
if (this.selectedPath && this.findNode(this.selectedPath)) {
|
|
66
|
+
return this.selectedPath;
|
|
67
|
+
}
|
|
68
|
+
const firstFile = this.flattenFiles(this.tree).find((n) => n.type === "file");
|
|
69
|
+
return firstFile ? firstFile.path : null;
|
|
70
|
+
}
|
|
71
|
+
parentPath(path) {
|
|
72
|
+
const parts = path.split("/").filter(Boolean);
|
|
73
|
+
if (parts.length <= 1)
|
|
74
|
+
return "";
|
|
75
|
+
parts.pop();
|
|
76
|
+
return parts.join("/");
|
|
77
|
+
}
|
|
78
|
+
flattenFiles(nodes) {
|
|
79
|
+
const acc = [];
|
|
80
|
+
const walk = (list) => {
|
|
81
|
+
list.forEach((n) => {
|
|
82
|
+
if (n.type === "file")
|
|
83
|
+
acc.push(n);
|
|
84
|
+
if (n.children?.length)
|
|
85
|
+
walk(n.children);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
walk(nodes);
|
|
89
|
+
return acc;
|
|
90
|
+
}
|
|
91
|
+
findNode(path, nodes) {
|
|
92
|
+
const list = nodes || this.tree;
|
|
93
|
+
for (const node of list) {
|
|
94
|
+
if (node.path === path)
|
|
95
|
+
return node;
|
|
96
|
+
if (node.children?.length) {
|
|
97
|
+
const found = this.findNode(path, node.children);
|
|
98
|
+
if (found)
|
|
99
|
+
return found;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
getChildren(path) {
|
|
105
|
+
if (!path)
|
|
106
|
+
return this.tree;
|
|
107
|
+
const node = this.findNode(path);
|
|
108
|
+
return node?.children || [];
|
|
109
|
+
}
|
|
110
|
+
updateFileName(name) {
|
|
111
|
+
if (this.fileBtnNameEl)
|
|
112
|
+
this.fileBtnNameEl.textContent = name || "Select file";
|
|
113
|
+
}
|
|
114
|
+
updateSelect(path) {
|
|
115
|
+
if (!this.selectEl)
|
|
116
|
+
return;
|
|
117
|
+
const options = this.flattenFiles(this.tree);
|
|
118
|
+
this.selectEl.innerHTML = "";
|
|
119
|
+
options.forEach((node) => {
|
|
120
|
+
const opt = document.createElement("option");
|
|
121
|
+
opt.value = node.path;
|
|
122
|
+
opt.textContent = node.name;
|
|
123
|
+
this.selectEl.appendChild(opt);
|
|
124
|
+
});
|
|
125
|
+
this.selectEl.value = path;
|
|
126
|
+
this.selectEl.onchange = () => this.select(this.selectEl.value);
|
|
127
|
+
}
|
|
128
|
+
renderBreadcrumbs() {
|
|
129
|
+
if (!this.breadcrumbsEl)
|
|
130
|
+
return;
|
|
131
|
+
this.breadcrumbsEl.innerHTML = "";
|
|
132
|
+
const nav = document.createElement("div");
|
|
133
|
+
nav.className = "workspace-breadcrumbs-inner";
|
|
134
|
+
const rootBtn = document.createElement("button");
|
|
135
|
+
rootBtn.type = "button";
|
|
136
|
+
rootBtn.textContent = "Workspace";
|
|
137
|
+
rootBtn.addEventListener("click", () => this.navigateTo(""));
|
|
138
|
+
nav.appendChild(rootBtn);
|
|
139
|
+
const parts = this.currentPath ? this.currentPath.split("/") : [];
|
|
140
|
+
let accum = "";
|
|
141
|
+
parts.forEach((part) => {
|
|
142
|
+
const sep = document.createElement("span");
|
|
143
|
+
sep.textContent = " / ";
|
|
144
|
+
nav.appendChild(sep);
|
|
145
|
+
accum = accum ? `${accum}/${part}` : part;
|
|
146
|
+
const btn = document.createElement("button");
|
|
147
|
+
btn.type = "button";
|
|
148
|
+
btn.textContent = part;
|
|
149
|
+
const target = accum;
|
|
150
|
+
btn.addEventListener("click", () => this.navigateTo(target));
|
|
151
|
+
nav.appendChild(btn);
|
|
152
|
+
});
|
|
153
|
+
this.breadcrumbsEl.appendChild(nav);
|
|
154
|
+
}
|
|
155
|
+
render() {
|
|
156
|
+
this.container.innerHTML = "";
|
|
157
|
+
this.renderBreadcrumbs();
|
|
158
|
+
const nodes = this.getChildren(this.currentPath);
|
|
159
|
+
const renderNodes = (list) => {
|
|
160
|
+
if (this.currentPath) {
|
|
161
|
+
const upRow = document.createElement("div");
|
|
162
|
+
upRow.className = "workspace-tree-row workspace-folder-row";
|
|
163
|
+
const label = document.createElement("div");
|
|
164
|
+
label.className = "workspace-tree-label";
|
|
165
|
+
const main = document.createElement("div");
|
|
166
|
+
main.className = "workspace-tree-main";
|
|
167
|
+
const caret = document.createElement("span");
|
|
168
|
+
caret.className = "workspace-tree-caret";
|
|
169
|
+
caret.textContent = "◂";
|
|
170
|
+
main.appendChild(caret);
|
|
171
|
+
const name = document.createElement("button");
|
|
172
|
+
name.type = "button";
|
|
173
|
+
name.className = "workspace-tree-name";
|
|
174
|
+
name.textContent = "Up one level";
|
|
175
|
+
const navigateUp = () => this.navigateTo(this.parentPath(this.currentPath));
|
|
176
|
+
name.addEventListener("click", navigateUp);
|
|
177
|
+
main.appendChild(name);
|
|
178
|
+
label.appendChild(main);
|
|
179
|
+
upRow.appendChild(label);
|
|
180
|
+
upRow.addEventListener("click", (evt) => {
|
|
181
|
+
const target = evt.target;
|
|
182
|
+
if (target?.closest("button"))
|
|
183
|
+
return;
|
|
184
|
+
navigateUp();
|
|
185
|
+
});
|
|
186
|
+
this.container.appendChild(upRow);
|
|
187
|
+
}
|
|
188
|
+
list.forEach((node) => {
|
|
189
|
+
const row = document.createElement("div");
|
|
190
|
+
row.className = `workspace-tree-row ${node.type === "folder" ? "workspace-folder-row" : "workspace-file-row"}`;
|
|
191
|
+
if (node.path === this.selectedPath)
|
|
192
|
+
row.classList.add("active");
|
|
193
|
+
row.dataset.path = node.path;
|
|
194
|
+
row.tabIndex = 0;
|
|
195
|
+
const label = document.createElement("div");
|
|
196
|
+
label.className = "workspace-tree-label";
|
|
197
|
+
const main = document.createElement("div");
|
|
198
|
+
main.className = "workspace-tree-main";
|
|
199
|
+
if (node.type === "folder") {
|
|
200
|
+
const caret = document.createElement("span");
|
|
201
|
+
caret.className = "workspace-tree-caret";
|
|
202
|
+
caret.textContent = "▸";
|
|
203
|
+
main.appendChild(caret);
|
|
204
|
+
}
|
|
205
|
+
const name = document.createElement("button");
|
|
206
|
+
name.type = "button";
|
|
207
|
+
name.className = "workspace-tree-name";
|
|
208
|
+
name.textContent = node.name;
|
|
209
|
+
if (node.is_pinned)
|
|
210
|
+
name.classList.add("pinned");
|
|
211
|
+
const activateNode = () => {
|
|
212
|
+
if (node.type === "folder") {
|
|
213
|
+
this.currentPath = node.path;
|
|
214
|
+
this.render();
|
|
215
|
+
this.renderModal();
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
this.select(node.path);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
if (node.type === "folder") {
|
|
222
|
+
name.addEventListener("click", activateNode);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
name.addEventListener("click", activateNode);
|
|
226
|
+
}
|
|
227
|
+
main.appendChild(name);
|
|
228
|
+
label.appendChild(main);
|
|
229
|
+
const meta = document.createElement("span");
|
|
230
|
+
meta.className = "workspace-tree-meta";
|
|
231
|
+
if (node.type === "file" && node.size != null) {
|
|
232
|
+
meta.textContent = this.prettySize(node.size);
|
|
233
|
+
}
|
|
234
|
+
else if (node.type === "folder" && node.children) {
|
|
235
|
+
const count = node.children.filter((c) => c.type === "file").length;
|
|
236
|
+
meta.textContent = count ? `${count} file${count === 1 ? "" : "s"}` : "";
|
|
237
|
+
}
|
|
238
|
+
if (meta.textContent)
|
|
239
|
+
label.appendChild(meta);
|
|
240
|
+
const actions = document.createElement("div");
|
|
241
|
+
actions.className = "workspace-item-actions";
|
|
242
|
+
// Download button for files
|
|
243
|
+
if (node.type === "file") {
|
|
244
|
+
const dlBtn = document.createElement("button");
|
|
245
|
+
dlBtn.type = "button";
|
|
246
|
+
dlBtn.className = "ghost sm workspace-download-btn";
|
|
247
|
+
dlBtn.textContent = "⬇";
|
|
248
|
+
dlBtn.title = `Download ${node.name}`;
|
|
249
|
+
dlBtn.addEventListener("click", (evt) => {
|
|
250
|
+
evt.stopPropagation();
|
|
251
|
+
downloadWorkspaceFile(node.path);
|
|
252
|
+
});
|
|
253
|
+
actions.appendChild(dlBtn);
|
|
254
|
+
}
|
|
255
|
+
// Download as ZIP button for folders
|
|
256
|
+
if (node.type === "folder") {
|
|
257
|
+
const dlBtn = document.createElement("button");
|
|
258
|
+
dlBtn.type = "button";
|
|
259
|
+
dlBtn.className = "ghost sm workspace-download-btn";
|
|
260
|
+
dlBtn.textContent = "⬇";
|
|
261
|
+
dlBtn.title = `Download ${node.name} as ZIP`;
|
|
262
|
+
dlBtn.addEventListener("click", (evt) => {
|
|
263
|
+
evt.stopPropagation();
|
|
264
|
+
downloadWorkspaceZip(node.path);
|
|
265
|
+
});
|
|
266
|
+
actions.appendChild(dlBtn);
|
|
267
|
+
}
|
|
268
|
+
// Delete button for files (non-pinned)
|
|
269
|
+
if (node.type === "file" && !node.is_pinned) {
|
|
270
|
+
const delBtn = document.createElement("button");
|
|
271
|
+
delBtn.type = "button";
|
|
272
|
+
delBtn.className = "ghost sm danger";
|
|
273
|
+
delBtn.textContent = "✕";
|
|
274
|
+
delBtn.title = "Delete file";
|
|
275
|
+
delBtn.addEventListener("click", async (evt) => {
|
|
276
|
+
evt.stopPropagation();
|
|
277
|
+
const ok = this.onConfirm ? await this.onConfirm(`Delete ${node.name}?`) : confirm(`Delete ${node.name}?`);
|
|
278
|
+
if (!ok)
|
|
279
|
+
return;
|
|
280
|
+
try {
|
|
281
|
+
await deleteWorkspaceFile(node.path);
|
|
282
|
+
if (this.selectedPath === node.path) {
|
|
283
|
+
this.selectedPath = null;
|
|
284
|
+
}
|
|
285
|
+
await this.onRefresh();
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
flash(err.message || "Failed to delete file", "error");
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
actions.appendChild(delBtn);
|
|
292
|
+
}
|
|
293
|
+
// Delete button for folders
|
|
294
|
+
if (node.type === "folder") {
|
|
295
|
+
const delBtn = document.createElement("button");
|
|
296
|
+
delBtn.type = "button";
|
|
297
|
+
delBtn.className = "ghost sm danger";
|
|
298
|
+
delBtn.textContent = "✕";
|
|
299
|
+
delBtn.title = "Delete folder";
|
|
300
|
+
delBtn.addEventListener("click", async (evt) => {
|
|
301
|
+
evt.stopPropagation();
|
|
302
|
+
const ok = this.onConfirm
|
|
303
|
+
? await this.onConfirm(`Delete folder ${node.name}? (must be empty)`)
|
|
304
|
+
: confirm(`Delete folder ${node.name}? (must be empty)`);
|
|
305
|
+
if (!ok)
|
|
306
|
+
return;
|
|
307
|
+
try {
|
|
308
|
+
await deleteWorkspaceFolder(node.path);
|
|
309
|
+
await this.onRefresh();
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
flash(err.message || "Failed to delete folder", "error");
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
actions.appendChild(delBtn);
|
|
316
|
+
}
|
|
317
|
+
row.appendChild(label);
|
|
318
|
+
if (actions.childElementCount)
|
|
319
|
+
row.appendChild(actions);
|
|
320
|
+
row.addEventListener("click", (evt) => {
|
|
321
|
+
const target = evt.target;
|
|
322
|
+
if (target?.closest(".workspace-item-actions"))
|
|
323
|
+
return;
|
|
324
|
+
if (target?.closest("button"))
|
|
325
|
+
return;
|
|
326
|
+
activateNode();
|
|
327
|
+
});
|
|
328
|
+
row.addEventListener("keydown", (evt) => {
|
|
329
|
+
if (evt.target !== row)
|
|
330
|
+
return;
|
|
331
|
+
if (evt.key === "Enter" || evt.key === " ") {
|
|
332
|
+
evt.preventDefault();
|
|
333
|
+
activateNode();
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
this.container.appendChild(row);
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
renderNodes(nodes);
|
|
340
|
+
}
|
|
341
|
+
renderModal() {
|
|
342
|
+
if (!this.modalBodyEl)
|
|
343
|
+
return;
|
|
344
|
+
this.modalBodyEl.innerHTML = "";
|
|
345
|
+
const crumbs = document.createElement("div");
|
|
346
|
+
crumbs.className = "file-picker-crumbs";
|
|
347
|
+
const root = document.createElement("button");
|
|
348
|
+
root.type = "button";
|
|
349
|
+
root.textContent = "Workspace";
|
|
350
|
+
root.addEventListener("click", () => {
|
|
351
|
+
this.currentPath = "";
|
|
352
|
+
this.render();
|
|
353
|
+
this.renderModal();
|
|
354
|
+
});
|
|
355
|
+
crumbs.appendChild(root);
|
|
356
|
+
const parts = this.currentPath ? this.currentPath.split("/") : [];
|
|
357
|
+
let accum = "";
|
|
358
|
+
parts.forEach((part) => {
|
|
359
|
+
const sep = document.createElement("span");
|
|
360
|
+
sep.textContent = " / ";
|
|
361
|
+
crumbs.appendChild(sep);
|
|
362
|
+
accum = accum ? `${accum}/${part}` : part;
|
|
363
|
+
const btn = document.createElement("button");
|
|
364
|
+
btn.type = "button";
|
|
365
|
+
btn.textContent = part;
|
|
366
|
+
const target = accum;
|
|
367
|
+
btn.addEventListener("click", () => {
|
|
368
|
+
this.currentPath = target;
|
|
369
|
+
this.render();
|
|
370
|
+
this.renderModal();
|
|
371
|
+
});
|
|
372
|
+
crumbs.appendChild(btn);
|
|
373
|
+
});
|
|
374
|
+
this.modalBodyEl.appendChild(crumbs);
|
|
375
|
+
const nodes = this.getChildren(this.currentPath);
|
|
376
|
+
if (!nodes.length) {
|
|
377
|
+
const empty = document.createElement("div");
|
|
378
|
+
empty.className = "file-picker-empty";
|
|
379
|
+
empty.textContent = "Empty folder";
|
|
380
|
+
this.modalBodyEl.appendChild(empty);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
nodes.forEach((node) => {
|
|
384
|
+
const item = document.createElement("button");
|
|
385
|
+
item.type = "button";
|
|
386
|
+
item.className = "file-picker-item";
|
|
387
|
+
item.dataset.path = node.path;
|
|
388
|
+
const label = document.createElement("span");
|
|
389
|
+
label.className = "file-picker-name";
|
|
390
|
+
label.textContent = node.name;
|
|
391
|
+
item.appendChild(label);
|
|
392
|
+
const actions = document.createElement("span");
|
|
393
|
+
actions.className = "file-picker-actions";
|
|
394
|
+
// Download button
|
|
395
|
+
const dlBtn = document.createElement("button");
|
|
396
|
+
dlBtn.type = "button";
|
|
397
|
+
dlBtn.className = "ghost sm workspace-download-btn";
|
|
398
|
+
dlBtn.textContent = "⬇";
|
|
399
|
+
dlBtn.title = node.type === "folder" ? `Download ${node.name} as ZIP` : `Download ${node.name}`;
|
|
400
|
+
dlBtn.addEventListener("click", (e) => {
|
|
401
|
+
e.stopPropagation();
|
|
402
|
+
if (node.type === "folder") {
|
|
403
|
+
downloadWorkspaceZip(node.path);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
downloadWorkspaceFile(node.path);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
actions.appendChild(dlBtn);
|
|
410
|
+
// Delete button (for non-pinned items)
|
|
411
|
+
if (!(node.type === "file" && node.is_pinned)) {
|
|
412
|
+
const delBtn = document.createElement("button");
|
|
413
|
+
delBtn.type = "button";
|
|
414
|
+
delBtn.className = "ghost sm danger";
|
|
415
|
+
delBtn.textContent = "✕";
|
|
416
|
+
delBtn.title = `Delete ${node.type}`;
|
|
417
|
+
delBtn.addEventListener("click", async (e) => {
|
|
418
|
+
e.stopPropagation();
|
|
419
|
+
const ok = this.onConfirm
|
|
420
|
+
? await this.onConfirm(`Delete ${node.name}${node.type === "folder" ? " (must be empty)" : ""}?`)
|
|
421
|
+
: confirm(`Delete ${node.name}${node.type === "folder" ? " (must be empty)" : ""}?`);
|
|
422
|
+
if (!ok)
|
|
423
|
+
return;
|
|
424
|
+
try {
|
|
425
|
+
if (node.type === "folder") {
|
|
426
|
+
await deleteWorkspaceFolder(node.path);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
await deleteWorkspaceFile(node.path);
|
|
430
|
+
if (this.selectedPath === node.path)
|
|
431
|
+
this.selectedPath = null;
|
|
432
|
+
}
|
|
433
|
+
await this.onRefresh();
|
|
434
|
+
this.render();
|
|
435
|
+
this.renderModal();
|
|
436
|
+
}
|
|
437
|
+
catch (err) {
|
|
438
|
+
flash(err.message || "Failed to delete", "error");
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
actions.appendChild(delBtn);
|
|
442
|
+
}
|
|
443
|
+
item.appendChild(actions);
|
|
444
|
+
if (node.type === "folder") {
|
|
445
|
+
item.classList.add("folder");
|
|
446
|
+
item.addEventListener("click", () => {
|
|
447
|
+
this.currentPath = node.path;
|
|
448
|
+
this.render();
|
|
449
|
+
this.renderModal();
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
item.classList.add("file");
|
|
454
|
+
item.classList.toggle("active", node.path === this.selectedPath);
|
|
455
|
+
item.addEventListener("click", () => {
|
|
456
|
+
this.select(node.path);
|
|
457
|
+
this.closeModal();
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
this.modalBodyEl.appendChild(item);
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
openModal() {
|
|
464
|
+
if (!this.modalEl)
|
|
465
|
+
return;
|
|
466
|
+
this.renderModal();
|
|
467
|
+
this.modalEl.hidden = false;
|
|
468
|
+
this.modalBodyEl?.querySelector(".file-picker-item")?.focus();
|
|
469
|
+
}
|
|
470
|
+
closeModal() {
|
|
471
|
+
if (this.modalEl)
|
|
472
|
+
this.modalEl.hidden = true;
|
|
473
|
+
}
|
|
474
|
+
initFilePicker() {
|
|
475
|
+
if (this.fileBtnEl) {
|
|
476
|
+
this.fileBtnEl.addEventListener("click", (e) => {
|
|
477
|
+
e.stopPropagation();
|
|
478
|
+
this.openModal();
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (this.modalCloseEl) {
|
|
482
|
+
this.modalCloseEl.addEventListener("click", () => this.closeModal());
|
|
483
|
+
}
|
|
484
|
+
if (this.modalEl) {
|
|
485
|
+
this.modalEl.addEventListener("click", (e) => {
|
|
486
|
+
if (e.target === this.modalEl)
|
|
487
|
+
this.closeModal();
|
|
488
|
+
});
|
|
489
|
+
document.addEventListener("keydown", (e) => {
|
|
490
|
+
if (e.key === "Escape" && !this.modalEl.hidden)
|
|
491
|
+
this.closeModal();
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
prettySize(bytes) {
|
|
496
|
+
if (bytes < 1024)
|
|
497
|
+
return `${bytes} B`;
|
|
498
|
+
const kb = bytes / 1024;
|
|
499
|
+
if (kb < 1024)
|
|
500
|
+
return `${kb.toFixed(1)} KB`;
|
|
501
|
+
const mb = kb / 1024;
|
|
502
|
+
return `${mb.toFixed(1)} MB`;
|
|
503
|
+
}
|
|
504
|
+
}
|