@ouro.bot/cli 0.1.0-alpha.827 → 0.1.0-alpha.828
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/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.828",
|
|
6
|
+
"changes": [
|
|
7
|
+
"The media MCP's deterministic core (download-state and diagnosis) is now a tested, importable seam instead of only being verifiable in production."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.827",
|
|
6
12
|
"changes": [
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// Protocol: JSON-RPC 2.0 over stdio, newline framed, MCP 2024-11-05.
|
|
11
11
|
|
|
12
12
|
import { readFileSync } from "node:fs"
|
|
13
|
+
import { pathToFileURL } from "node:url"
|
|
13
14
|
|
|
14
15
|
const CRED_PATH = process.env.SANCTUARY_MEDIA_CREDENTIALS ?? "/home/ouro/AgentBundles/sanctuary.ouro/mcp/media-credentials.json"
|
|
15
16
|
|
|
@@ -425,31 +426,43 @@ async function mediaRequestStatus(a) {
|
|
|
425
426
|
last_grab_title: grabs[0]?.sourceTitle ?? null,
|
|
426
427
|
monitored: entity ? Boolean(entity.monitored) : null,
|
|
427
428
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
429
|
+
result.download = computeDownloadState(queueRecs, Date.now())
|
|
430
|
+
|
|
431
|
+
const chain = await chainHealth()
|
|
432
|
+
result.chain = chain
|
|
433
|
+
result.diagnosis = diagnose({ shelf, result, chain, entity, kind })
|
|
434
|
+
return result
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// The deterministic core, split out so it can be tested without a live
|
|
438
|
+
// Sonarr/Radarr. `computeDownloadState` and `diagnose` are the whole reason the
|
|
439
|
+
// media surface can answer "why hasn't this downloaded" without the agent
|
|
440
|
+
// guessing, and D-013 (a stalled download read as progress) shipped verified
|
|
441
|
+
// only in production because there was no seam to test them through.
|
|
442
|
+
//
|
|
443
|
+
// A season pack shows up as one queue row per episode, all sharing one
|
|
444
|
+
// downloadId. Summing rows would report a 45 GB pack as 450 GB, so size and
|
|
445
|
+
// "how many downloads" are counted per distinct download, not per row. A
|
|
446
|
+
// torrent that has not moved a byte since it was grabbed is dead, not slow:
|
|
447
|
+
// Radarr reports trackedDownloadStatus "ok" for these indefinitely, so
|
|
448
|
+
// progress is measured against age rather than trusted from the row.
|
|
449
|
+
export function computeDownloadState(queueRecs, nowMs) {
|
|
431
450
|
const byDownload = new Map()
|
|
432
451
|
for (const r of queueRecs) byDownload.set(r.downloadId ?? `row:${r.id}`, r)
|
|
433
452
|
const downloads = [...byDownload.values()]
|
|
434
453
|
const sizeLeft = downloads.reduce((s, r) => s + (r.sizeleft ?? 0), 0)
|
|
435
454
|
const sizeTotal = downloads.reduce((s, r) => s + (r.size ?? 0), 0)
|
|
436
|
-
// A torrent that has not moved a byte since it was grabbed is not slow, it is
|
|
437
|
-
// dead: no seeders, or a release the client cannot fetch. Radarr goes on
|
|
438
|
-
// reporting trackedDownloadStatus "ok" for these indefinitely, so a queue row
|
|
439
|
-
// on its own reads as healthy and any answer built from it reassures instead
|
|
440
|
-
// of acting. Measuring progress against age is what separates the two.
|
|
441
|
-
const now = Date.now()
|
|
442
455
|
const stalledItems = downloads
|
|
443
456
|
.filter((r) => (r.size ?? 0) > 0 && (r.sizeleft ?? 0) >= (r.size ?? 0) && r.added
|
|
444
|
-
&& (
|
|
457
|
+
&& (nowMs - Date.parse(r.added)) / 3_600_000 >= STALL_AFTER_HOURS)
|
|
445
458
|
.map((r) => ({
|
|
446
459
|
title: r.title ?? null,
|
|
447
460
|
added_at: r.added ?? null,
|
|
448
|
-
age_hours: Math.round((
|
|
461
|
+
age_hours: Math.round((nowMs - Date.parse(r.added)) / 3_600_000),
|
|
449
462
|
size_gb: Number(((r.size ?? 0) / 1073741824).toFixed(2)),
|
|
450
463
|
queue_id: r.id ?? null,
|
|
451
464
|
}))
|
|
452
|
-
|
|
465
|
+
return {
|
|
453
466
|
active_downloads: downloads.length,
|
|
454
467
|
active_items: queueRecs.length,
|
|
455
468
|
states: [...new Set(downloads.map((r) => r.status))],
|
|
@@ -461,15 +474,10 @@ async function mediaRequestStatus(a) {
|
|
|
461
474
|
stalled: stalledItems.length > 0,
|
|
462
475
|
stalled_items: stalledItems,
|
|
463
476
|
}
|
|
464
|
-
|
|
465
|
-
const chain = await chainHealth()
|
|
466
|
-
result.chain = chain
|
|
467
|
-
result.diagnosis = diagnose({ shelf, result, chain, entity, kind })
|
|
468
|
-
return result
|
|
469
477
|
}
|
|
470
478
|
|
|
471
479
|
// The deterministic core. The agent must never have to work this out itself.
|
|
472
|
-
function diagnose({ shelf, result, chain, entity, kind }) {
|
|
480
|
+
export function diagnose({ shelf, result, chain, entity, kind }) {
|
|
473
481
|
const file = result.file ?? {}
|
|
474
482
|
const onShelf = kind === "series" ? (file.episodes_on_disk ?? 0) > 0 : Boolean(file.on_shelf)
|
|
475
483
|
const complete = kind === "series" ? (file.episodes_on_disk ?? 0) >= (file.episodes_total ?? Infinity) : onShelf
|
|
@@ -759,22 +767,29 @@ function exitWhenIdle() {
|
|
|
759
767
|
if (stdinClosed && inFlight === 0) process.exit(0)
|
|
760
768
|
}
|
|
761
769
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
.
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
770
|
+
// Only run the stdio server when invoked directly (node media-mcp.mjs, exactly
|
|
771
|
+
// how agent.json launches it). Guarding this lets the test suite import the
|
|
772
|
+
// module for computeDownloadState/diagnose without attaching to stdin or exiting
|
|
773
|
+
// the test process. The launch is a plain node <abs-path>, so argv[1] is the
|
|
774
|
+
// file's own path and this comparison holds.
|
|
775
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
776
|
+
process.stdin.setEncoding("utf8")
|
|
777
|
+
process.stdin.on("data", (chunk) => {
|
|
778
|
+
buf += chunk
|
|
779
|
+
let nl
|
|
780
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
781
|
+
const line = buf.slice(0, nl).trim()
|
|
782
|
+
buf = buf.slice(nl + 1)
|
|
783
|
+
if (!line) continue
|
|
784
|
+
let msg
|
|
785
|
+
try { msg = JSON.parse(line) } catch { continue }
|
|
786
|
+
inFlight += 1
|
|
787
|
+
handle(msg)
|
|
788
|
+
.catch((e) => {
|
|
789
|
+
if (msg.id !== undefined) send({ jsonrpc: "2.0", id: msg.id, error: { code: -32603, message: e.message } })
|
|
790
|
+
})
|
|
791
|
+
.finally(() => { inFlight -= 1; exitWhenIdle() })
|
|
792
|
+
}
|
|
793
|
+
})
|
|
794
|
+
process.stdin.on("end", () => { stdinClosed = true; exitWhenIdle() })
|
|
795
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.828</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.828",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.828",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@azure/identity": "^4.13.0",
|