arkaos 3.50.0 → 3.51.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.
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.51.0
|
|
@@ -59,6 +59,13 @@ const links = [[{
|
|
|
59
59
|
onSelect: () => {
|
|
60
60
|
open.value = false
|
|
61
61
|
}
|
|
62
|
+
}, {
|
|
63
|
+
label: 'Terminal',
|
|
64
|
+
icon: 'i-lucide-terminal',
|
|
65
|
+
to: '/terminal',
|
|
66
|
+
onSelect: () => {
|
|
67
|
+
open.value = false
|
|
68
|
+
}
|
|
62
69
|
}, {
|
|
63
70
|
label: 'Workflows',
|
|
64
71
|
icon: 'i-lucide-workflow',
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// PR95a v3.51.0 — Dashboard terminal (allowlist mode).
|
|
3
|
+
//
|
|
4
|
+
// Operator picks one of the allowlisted commands; backend runs it via
|
|
5
|
+
// subprocess.run (no shell). Output streams into the history block.
|
|
6
|
+
//
|
|
7
|
+
// Note: vue-termui is for building Vue TUI apps that RUN in a terminal,
|
|
8
|
+
// not for embedding an arbitrary shell in a browser. The dashboard
|
|
9
|
+
// instead ships a controlled command runner with allowlist + capped
|
|
10
|
+
// output. xterm.js-style PTY can be a later upgrade if needed.
|
|
11
|
+
|
|
12
|
+
interface CommandEntry {
|
|
13
|
+
id: string
|
|
14
|
+
label: string
|
|
15
|
+
description: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ExecResult {
|
|
19
|
+
stdout: string
|
|
20
|
+
stderr: string
|
|
21
|
+
exit_code: number
|
|
22
|
+
duration_ms: number
|
|
23
|
+
command: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface HistoryEntry {
|
|
27
|
+
id: string
|
|
28
|
+
label: string
|
|
29
|
+
result: ExecResult
|
|
30
|
+
ts: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { fetchApi, apiBase } = useApi()
|
|
34
|
+
const toast = useToast()
|
|
35
|
+
|
|
36
|
+
const { data: cmdData, status } = await fetchApi<{ commands: CommandEntry[] }>(
|
|
37
|
+
'/api/terminal/commands',
|
|
38
|
+
)
|
|
39
|
+
const commands = computed<CommandEntry[]>(() => cmdData.value?.commands ?? [])
|
|
40
|
+
|
|
41
|
+
const running = ref<string | null>(null)
|
|
42
|
+
const history = ref<HistoryEntry[]>([])
|
|
43
|
+
|
|
44
|
+
async function run(cmd: CommandEntry) {
|
|
45
|
+
running.value = cmd.id
|
|
46
|
+
try {
|
|
47
|
+
const res = await $fetch<ExecResult & { error?: string }>(
|
|
48
|
+
`${apiBase}/api/terminal/exec`,
|
|
49
|
+
{ method: 'POST', body: { command_id: cmd.id } },
|
|
50
|
+
)
|
|
51
|
+
if (res.error) throw new Error(res.error)
|
|
52
|
+
history.value = [
|
|
53
|
+
{
|
|
54
|
+
id: cmd.id,
|
|
55
|
+
label: cmd.label,
|
|
56
|
+
result: res,
|
|
57
|
+
ts: new Date().toISOString(),
|
|
58
|
+
},
|
|
59
|
+
...history.value,
|
|
60
|
+
].slice(0, 20)
|
|
61
|
+
if (res.exit_code === 0) {
|
|
62
|
+
toast.add({
|
|
63
|
+
title: `${cmd.label} · ok`,
|
|
64
|
+
description: `${res.duration_ms}ms`,
|
|
65
|
+
color: 'success',
|
|
66
|
+
icon: 'i-lucide-check',
|
|
67
|
+
})
|
|
68
|
+
} else {
|
|
69
|
+
toast.add({
|
|
70
|
+
title: `${cmd.label} · exit ${res.exit_code}`,
|
|
71
|
+
description: `${res.duration_ms}ms · ${res.stderr.slice(0, 80) || 'no stderr'}`,
|
|
72
|
+
color: 'warning',
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
toast.add({
|
|
77
|
+
title: 'Run failed',
|
|
78
|
+
description: err instanceof Error ? err.message : 'unknown error',
|
|
79
|
+
color: 'error',
|
|
80
|
+
})
|
|
81
|
+
} finally {
|
|
82
|
+
running.value = null
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function copyOutput(entry: HistoryEntry) {
|
|
87
|
+
if (typeof navigator === 'undefined' || !navigator.clipboard) return
|
|
88
|
+
const body = entry.result.stdout || entry.result.stderr
|
|
89
|
+
void navigator.clipboard.writeText(body)
|
|
90
|
+
toast.add({ title: 'Copied to clipboard', color: 'success', icon: 'i-lucide-clipboard-check' })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function clearHistory() {
|
|
94
|
+
history.value = []
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function relative(iso: string): string {
|
|
98
|
+
const ts = Date.parse(iso)
|
|
99
|
+
if (Number.isNaN(ts)) return iso
|
|
100
|
+
const diff = Date.now() - ts
|
|
101
|
+
const s = Math.floor(diff / 1000)
|
|
102
|
+
if (s < 60) return `${s}s ago`
|
|
103
|
+
const m = Math.floor(s / 60)
|
|
104
|
+
if (m < 60) return `${m}m ago`
|
|
105
|
+
return `${Math.floor(m / 60)}h ago`
|
|
106
|
+
}
|
|
107
|
+
</script>
|
|
108
|
+
|
|
109
|
+
<template>
|
|
110
|
+
<UDashboardPanel id="terminal">
|
|
111
|
+
<template #header>
|
|
112
|
+
<UDashboardNavbar title="Terminal">
|
|
113
|
+
<template #leading>
|
|
114
|
+
<UDashboardSidebarCollapse />
|
|
115
|
+
</template>
|
|
116
|
+
<template #trailing>
|
|
117
|
+
<UBadge label="Allowlist mode" variant="subtle" color="primary" size="sm" />
|
|
118
|
+
</template>
|
|
119
|
+
</UDashboardNavbar>
|
|
120
|
+
</template>
|
|
121
|
+
|
|
122
|
+
<template #body>
|
|
123
|
+
<DashboardState
|
|
124
|
+
:status="status"
|
|
125
|
+
:empty="commands.length === 0"
|
|
126
|
+
empty-title="No allowlisted commands"
|
|
127
|
+
empty-description="The backend exposes no terminal commands. Add to TERMINAL_ALLOWLIST."
|
|
128
|
+
empty-icon="i-lucide-terminal"
|
|
129
|
+
>
|
|
130
|
+
<div class="space-y-5 max-w-4xl">
|
|
131
|
+
<UCard>
|
|
132
|
+
<template #header>
|
|
133
|
+
<div>
|
|
134
|
+
<h3 class="text-lg font-bold">Commands</h3>
|
|
135
|
+
<p class="text-xs text-muted mt-0.5">
|
|
136
|
+
Server-enforced allowlist. Each command runs via
|
|
137
|
+
<code class="font-mono">subprocess.run</code> with explicit argv —
|
|
138
|
+
no shell, no globbing, no pipes. Cap: 15s timeout, 20K chars per stream.
|
|
139
|
+
</p>
|
|
140
|
+
</div>
|
|
141
|
+
</template>
|
|
142
|
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
|
|
143
|
+
<UButton
|
|
144
|
+
v-for="cmd in commands"
|
|
145
|
+
:key="cmd.id"
|
|
146
|
+
:label="cmd.label"
|
|
147
|
+
:description="cmd.description"
|
|
148
|
+
icon="i-lucide-terminal"
|
|
149
|
+
variant="soft"
|
|
150
|
+
color="primary"
|
|
151
|
+
size="sm"
|
|
152
|
+
block
|
|
153
|
+
class="justify-start"
|
|
154
|
+
:loading="running === cmd.id"
|
|
155
|
+
:disabled="running !== null && running !== cmd.id"
|
|
156
|
+
@click="run(cmd)"
|
|
157
|
+
/>
|
|
158
|
+
</div>
|
|
159
|
+
</UCard>
|
|
160
|
+
|
|
161
|
+
<UCard v-if="history.length > 0">
|
|
162
|
+
<template #header>
|
|
163
|
+
<div class="flex items-center justify-between gap-3">
|
|
164
|
+
<div>
|
|
165
|
+
<h3 class="text-lg font-bold">Recent runs</h3>
|
|
166
|
+
<p class="text-xs text-muted mt-0.5">
|
|
167
|
+
Last {{ history.length }} commands · most recent first
|
|
168
|
+
</p>
|
|
169
|
+
</div>
|
|
170
|
+
<UButton label="Clear" variant="ghost" size="xs" @click="clearHistory" />
|
|
171
|
+
</div>
|
|
172
|
+
</template>
|
|
173
|
+
<ul class="space-y-4">
|
|
174
|
+
<li
|
|
175
|
+
v-for="entry in history"
|
|
176
|
+
:key="`${entry.ts}-${entry.id}`"
|
|
177
|
+
class="rounded-lg border border-default overflow-hidden"
|
|
178
|
+
>
|
|
179
|
+
<div class="px-3 py-2 bg-elevated/30 flex items-center justify-between gap-3 text-xs">
|
|
180
|
+
<div class="min-w-0 flex items-center gap-2">
|
|
181
|
+
<UBadge
|
|
182
|
+
:label="entry.result.exit_code === 0 ? 'ok' : `exit ${entry.result.exit_code}`"
|
|
183
|
+
:color="entry.result.exit_code === 0 ? 'success' : 'warning'"
|
|
184
|
+
variant="subtle"
|
|
185
|
+
size="xs"
|
|
186
|
+
/>
|
|
187
|
+
<span class="font-mono truncate">{{ entry.result.command }}</span>
|
|
188
|
+
</div>
|
|
189
|
+
<div class="flex items-center gap-2 shrink-0">
|
|
190
|
+
<span class="text-muted font-mono">{{ entry.result.duration_ms }}ms</span>
|
|
191
|
+
<span class="text-muted">{{ relative(entry.ts) }}</span>
|
|
192
|
+
<UButton
|
|
193
|
+
icon="i-lucide-clipboard-copy"
|
|
194
|
+
variant="ghost"
|
|
195
|
+
size="xs"
|
|
196
|
+
aria-label="Copy output"
|
|
197
|
+
@click="copyOutput(entry)"
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
<pre
|
|
202
|
+
v-if="entry.result.stdout"
|
|
203
|
+
class="p-3 text-xs font-mono whitespace-pre overflow-x-auto"
|
|
204
|
+
>{{ entry.result.stdout }}</pre>
|
|
205
|
+
<pre
|
|
206
|
+
v-if="entry.result.stderr"
|
|
207
|
+
class="p-3 text-xs font-mono whitespace-pre overflow-x-auto text-rose-500 border-t border-default"
|
|
208
|
+
>{{ entry.result.stderr }}</pre>
|
|
209
|
+
</li>
|
|
210
|
+
</ul>
|
|
211
|
+
</UCard>
|
|
212
|
+
|
|
213
|
+
<p class="text-xs text-muted">
|
|
214
|
+
Want a different command? Add it to
|
|
215
|
+
<code class="font-mono">TERMINAL_ALLOWLIST</code> in
|
|
216
|
+
<code class="font-mono">scripts/dashboard-api.py</code> and
|
|
217
|
+
restart the backend. Arbitrary shell execution from the
|
|
218
|
+
dashboard is intentionally not supported.
|
|
219
|
+
</p>
|
|
220
|
+
</div>
|
|
221
|
+
</DashboardState>
|
|
222
|
+
</template>
|
|
223
|
+
</UDashboardPanel>
|
|
224
|
+
</template>
|
package/package.json
CHANGED
package/pyproject.toml
CHANGED
|
Binary file
|
package/scripts/dashboard-api.py
CHANGED
|
@@ -1894,6 +1894,120 @@ def _iso_duration_s(start_iso: str, end_iso: str) -> Optional[int]:
|
|
|
1894
1894
|
return None
|
|
1895
1895
|
|
|
1896
1896
|
|
|
1897
|
+
# --- Terminal command runner (PR95a v3.51.0) ---
|
|
1898
|
+
|
|
1899
|
+
# Allowlist of commands the dashboard terminal can run. Each entry is
|
|
1900
|
+
# {id, label, cmd, description}. Server-side enforcement: any request
|
|
1901
|
+
# whose `command_id` isn't in this list is rejected. No shell expansion,
|
|
1902
|
+
# no globbing, no pipes — subprocess.run with explicit argv only.
|
|
1903
|
+
TERMINAL_ALLOWLIST: list[dict] = [
|
|
1904
|
+
{
|
|
1905
|
+
"id": "arka-status",
|
|
1906
|
+
"label": "ArkaOS status",
|
|
1907
|
+
"cmd": ["arkaos", "status"],
|
|
1908
|
+
"description": "System status (version, departments, agents, projects).",
|
|
1909
|
+
},
|
|
1910
|
+
{
|
|
1911
|
+
"id": "git-status",
|
|
1912
|
+
"label": "git status",
|
|
1913
|
+
"cmd": ["git", "status", "--short"],
|
|
1914
|
+
"description": "Working tree status in short form.",
|
|
1915
|
+
},
|
|
1916
|
+
{
|
|
1917
|
+
"id": "git-log",
|
|
1918
|
+
"label": "git log (10)",
|
|
1919
|
+
"cmd": ["git", "log", "-10", "--oneline"],
|
|
1920
|
+
"description": "Most recent 10 commits.",
|
|
1921
|
+
},
|
|
1922
|
+
{
|
|
1923
|
+
"id": "npm-version",
|
|
1924
|
+
"label": "npm view arkaos version",
|
|
1925
|
+
"cmd": ["npm", "view", "arkaos", "version"],
|
|
1926
|
+
"description": "Latest published ArkaOS version on npm.",
|
|
1927
|
+
},
|
|
1928
|
+
{
|
|
1929
|
+
"id": "pytest-collect",
|
|
1930
|
+
"label": "pytest --collect-only",
|
|
1931
|
+
"cmd": ["python3", "-m", "pytest", "--collect-only", "-q", "tests/python/"],
|
|
1932
|
+
"description": "List every Python test without running.",
|
|
1933
|
+
},
|
|
1934
|
+
{
|
|
1935
|
+
"id": "ls",
|
|
1936
|
+
"label": "ls",
|
|
1937
|
+
"cmd": ["ls", "-la"],
|
|
1938
|
+
"description": "List files in the project root.",
|
|
1939
|
+
},
|
|
1940
|
+
]
|
|
1941
|
+
|
|
1942
|
+
_TERMINAL_TIMEOUT_S = 15
|
|
1943
|
+
_TERMINAL_MAX_OUTPUT = 20_000 # chars — both stdout and stderr capped
|
|
1944
|
+
|
|
1945
|
+
|
|
1946
|
+
@app.get("/api/terminal/commands")
|
|
1947
|
+
def terminal_commands():
|
|
1948
|
+
"""List allowlisted commands the dashboard terminal may run."""
|
|
1949
|
+
return {
|
|
1950
|
+
"commands": [
|
|
1951
|
+
{"id": c["id"], "label": c["label"], "description": c["description"]}
|
|
1952
|
+
for c in TERMINAL_ALLOWLIST
|
|
1953
|
+
],
|
|
1954
|
+
"total": len(TERMINAL_ALLOWLIST),
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
|
|
1958
|
+
@app.post("/api/terminal/exec")
|
|
1959
|
+
def terminal_exec(body: dict):
|
|
1960
|
+
"""PR95a v3.51.0 — run an allowlisted command and return the output.
|
|
1961
|
+
|
|
1962
|
+
Body: ``{"command_id": "<id>"}``. Unknown ids are rejected.
|
|
1963
|
+
Returns ``{stdout, stderr, exit_code, duration_ms, command}``.
|
|
1964
|
+
Output is capped at ``_TERMINAL_MAX_OUTPUT`` chars per stream.
|
|
1965
|
+
"""
|
|
1966
|
+
if not isinstance(body, dict):
|
|
1967
|
+
return {"error": "body must be an object"}
|
|
1968
|
+
cid = (body.get("command_id") or "").strip()
|
|
1969
|
+
if not cid:
|
|
1970
|
+
return {"error": "command_id is required"}
|
|
1971
|
+
entry = next((c for c in TERMINAL_ALLOWLIST if c["id"] == cid), None)
|
|
1972
|
+
if entry is None:
|
|
1973
|
+
return {"error": f"command '{cid}' is not on the allowlist"}
|
|
1974
|
+
import time
|
|
1975
|
+
started = time.monotonic()
|
|
1976
|
+
try:
|
|
1977
|
+
result = subprocess.run(
|
|
1978
|
+
entry["cmd"],
|
|
1979
|
+
cwd=str(ARKAOS_ROOT),
|
|
1980
|
+
capture_output=True,
|
|
1981
|
+
text=True,
|
|
1982
|
+
timeout=_TERMINAL_TIMEOUT_S,
|
|
1983
|
+
shell=False,
|
|
1984
|
+
)
|
|
1985
|
+
except subprocess.TimeoutExpired:
|
|
1986
|
+
return {
|
|
1987
|
+
"stdout": "",
|
|
1988
|
+
"stderr": f"command timed out after {_TERMINAL_TIMEOUT_S}s",
|
|
1989
|
+
"exit_code": -1,
|
|
1990
|
+
"duration_ms": int(_TERMINAL_TIMEOUT_S * 1000),
|
|
1991
|
+
"command": " ".join(entry["cmd"]),
|
|
1992
|
+
}
|
|
1993
|
+
except OSError as exc:
|
|
1994
|
+
return {
|
|
1995
|
+
"stdout": "",
|
|
1996
|
+
"stderr": f"command failed to launch: {exc}",
|
|
1997
|
+
"exit_code": -1,
|
|
1998
|
+
"duration_ms": int((time.monotonic() - started) * 1000),
|
|
1999
|
+
"command": " ".join(entry["cmd"]),
|
|
2000
|
+
}
|
|
2001
|
+
duration_ms = int((time.monotonic() - started) * 1000)
|
|
2002
|
+
return {
|
|
2003
|
+
"stdout": (result.stdout or "")[:_TERMINAL_MAX_OUTPUT],
|
|
2004
|
+
"stderr": (result.stderr or "")[:_TERMINAL_MAX_OUTPUT],
|
|
2005
|
+
"exit_code": result.returncode,
|
|
2006
|
+
"duration_ms": duration_ms,
|
|
2007
|
+
"command": " ".join(entry["cmd"]),
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
|
|
1897
2011
|
@app.put("/api/workflows/{workflow_id}/yaml")
|
|
1898
2012
|
def workflow_update_yaml(workflow_id: str, body: dict):
|
|
1899
2013
|
"""PR94d v3.50.0 — overwrite a workflow's YAML file in place.
|