Skip to content

Commit 0bbece3

Browse files
feat(persephone): expose owner integration inventory
1 parent 09ead0a commit 0bbece3

7 files changed

Lines changed: 190 additions & 4 deletions

‎routes/ulysses_routes.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,16 @@ async def get_persephone_workspace(
675675
except PersephoneWorkspaceError as exc:
676676
raise HTTPException(503, str(exc)) from exc
677677

678+
@router.get("/persephone/integrations")
679+
async def get_persephone_integrations(request: Request) -> dict:
680+
require_admin(request)
681+
try:
682+
return await run_in_threadpool(
683+
persephone_control_factory().integrations,
684+
)
685+
except PersephoneWorkspaceError as exc:
686+
raise HTTPException(503, str(exc)) from exc
687+
678688
@router.get("/persephone/queue/{kind}/{record_id}")
679689
async def get_persephone_queue_record(
680690
request: Request,

‎src/diogenes_persephone_workspace.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
WORKSPACE_SCHEMA = "persephone.workspace.v1"
2020
WORKSPACE_LOG_SCHEMA = "persephone.workspace-logs.v1"
21+
INTEGRATION_INVENTORY_SCHEMA = "persephone.integration-inventory.v1"
2122
MUTATION_ACTIONS = {
2223
"configuration.replace",
2324
"schedule.put",
@@ -31,6 +32,7 @@
3132
"initialize",
3233
"integrate",
3334
"doctor",
35+
"reconcile",
3436
"start",
3537
"stop",
3638
"restart",
@@ -95,6 +97,19 @@ def logs(self, *, lines: int = 200) -> dict[str, Any]:
9597
raise PersephoneWorkspaceError("Persephone returned an unsupported log schema")
9698
return result
9799

100+
def integrations(self) -> dict[str, Any]:
101+
result = self._owner_json(["integrations"], timeout=120)
102+
if result.get("schemaVersion") != INTEGRATION_INVENTORY_SCHEMA:
103+
raise PersephoneWorkspaceError(
104+
"Persephone returned an unsupported integration inventory schema"
105+
)
106+
for field in ("profiles", "integrations", "ompReconciliation"):
107+
if not isinstance(result.get(field), list):
108+
raise PersephoneWorkspaceError(
109+
f"Persephone integration inventory is missing {field}"
110+
)
111+
return result
112+
98113
def create_lifecycle_plan(self, *, action: str) -> tuple[dict[str, Any], str]:
99114
if action not in LIFECYCLE_ACTIONS:
100115
raise PersephoneWorkspaceError("Unsupported Persephone lifecycle action")
@@ -126,6 +141,22 @@ def create_lifecycle_plan(self, *, action: str) -> tuple[dict[str, Any], str]:
126141
"AUDIT PERSEPHONE",
127142
[{"label": "Run the owner health audit", "argv": [cli, "doctor"], "timeout": 900}],
128143
),
144+
"reconcile": (
145+
"Restore Persephone-owned OMP settings",
146+
"RECONCILE PERSEPHONE OMP",
147+
[
148+
{
149+
"label": "Apply OMP settings maintained by Persephone",
150+
"argv": [cli, "reconcile"],
151+
"timeout": 900,
152+
},
153+
{
154+
"label": "Audit integration state",
155+
"argv": [cli, "doctor", "--integration-only"],
156+
"timeout": 900,
157+
},
158+
],
159+
),
129160
"start": (
130161
"Start the Persephone user service",
131162
"START PERSEPHONE",

‎static/js/persephoneWorkspace.js‎

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { makeWindowDraggable } from './windowDrag.js';
44

55
const MODAL_ID = 'diogenes-persephone-workspace-modal';
66
const TERMINAL = new Set(['succeeded', 'failed', 'cancelled']);
7-
const VIEWS = ['overview', 'connectors', 'routes', 'runtime', 'queues', 'schedules', 'settings', 'setup'];
7+
const VIEWS = ['overview', 'connectors', 'routes', 'runtime', 'queues', 'schedules', 'integrations', 'settings', 'setup'];
88
const ICON = `<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor"
99
stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
1010
<path d="M12 3a4 4 0 0 0-4 4v2H6a2 2 0 0 0-2 2v8h16v-8a2 2 0 0 0-2-2h-2V7a4 4 0 0 0-4-4z"/>
@@ -24,6 +24,9 @@ let scheduleDraft = null;
2424
let dispatchDraft = { channel: 'api', peerId: 'owner', message: '' };
2525
let runtimeLogs = null;
2626
let runtimeLogsLoading = false;
27+
let integrationInventory = null;
28+
let integrationLoading = false;
29+
let integrationError = '';
2730
let approvalValues = {};
2831
let busy = '';
2932
let error = '';
@@ -77,7 +80,7 @@ function ensureModal() {
7780
});
7881
Modals.injectMinimizeButton(modal, MODAL_ID);
7982
modal.querySelector('.close-btn')?.addEventListener('click', () => Modals.close(MODAL_ID));
80-
modal.querySelector('[data-pers-refresh]')?.addEventListener('click', () => loadWorkspace(true));
83+
modal.querySelector('[data-pers-refresh]')?.addEventListener('click', refreshCurrent);
8184
const body = modal.querySelector('.dio-persephone-body');
8285
body?.addEventListener('click', onClick);
8386
body?.addEventListener('input', onInput);
@@ -109,8 +112,10 @@ function onClick(event) {
109112
if (tab) {
110113
view = VIEWS.includes(tab.dataset.persView) ? tab.dataset.persView : 'overview';
111114
render();
115+
if (view === 'integrations' && !integrationInventory) void loadIntegrations();
112116
return;
113117
}
118+
if (event.target.closest('[data-pers-integrations-refresh]')) { loadIntegrations(true); return; }
114119
const lifecycle = event.target.closest('[data-pers-lifecycle]');
115120
if (lifecycle) { runLifecycle(lifecycle.dataset.persLifecycle); return; }
116121
if (event.target.closest('[data-pers-config-save]')) { saveConfiguration(); return; }
@@ -217,6 +222,7 @@ function renderView() {
217222
if (view === 'runtime') return renderRuntime();
218223
if (view === 'queues') return renderQueues();
219224
if (view === 'schedules') return renderSchedules();
225+
if (view === 'integrations') return renderIntegrations();
220226
if (view === 'settings') return renderSettings();
221227
if (view === 'setup') return renderSetup();
222228
return renderOverview();
@@ -511,6 +517,65 @@ function renderSettings() {
511517
</div>${configFooter()}`;
512518
}
513519

520+
function renderIntegrations() {
521+
const inventory = integrationInventory;
522+
const entries = inventory?.integrations || [];
523+
const checks = inventory?.ompReconciliation || [];
524+
const profiles = inventory?.profiles || [];
525+
const readyOwners = entries.filter((entry) => entry.configured && entry.ownerContractPresent).length;
526+
const passingChecks = checks.filter((entry) => entry.ok).length;
527+
return `${sectionHeading(
528+
'Integrations',
529+
'Inspect the repositories Persephone maintains and the OMP settings it will restore after upgrades.',
530+
integrationLoading ? 'Checking…' : 'Check again',
531+
'data-pers-integrations-refresh',
532+
)}
533+
${integrationError ? `<div class="dio-persephone-inline-error">${esc(integrationError)}</div>` : ''}
534+
${integrationLoading && !inventory ? panelMessage('Reading owner inventory…', 'Persephone is checking its configured repositories and OMP profiles.') : ''}
535+
${inventory ? `
536+
<section class="dio-persephone-actions">
537+
<button type="button" data-pers-lifecycle="reconcile" ${busy ? 'disabled' : ''}>${busy === 'lifecycle:reconcile' ? 'Working…' : 'Review OMP repair'}</button>
538+
<button type="button" data-pers-lifecycle="integrate" ${busy ? 'disabled' : ''}>${busy === 'lifecycle:integrate' ? 'Working…' : 'Review full integration'}</button>
539+
</section>
540+
<section class="dio-persephone-metrics integrations">
541+
${metric('Owners', readyOwners, `${entries.length} configured`)}
542+
${metric('OMP checks', passingChecks, `${checks.length - passingChecks} need repair`)}
543+
${metric('Profiles', profiles.length, 'discovered by owner')}
544+
${metric('Session repair', inventory.reconcileOnSessionStart ? 1 : 0, inventory.reconcileOnSessionStart ? 'enabled' : 'disabled')}
545+
</section>
546+
<div class="dio-persephone-integration-grid">
547+
<section class="dio-persephone-integration-list">
548+
${entries.length ? entries.map(renderIntegrationOwner).join('') : panelMessage('No integrations configured')}
549+
</section>
550+
<section class="dio-persephone-integration-side">
551+
<article class="dio-persephone-card">
552+
<header><div><small>OMP RECONCILIATION</small><h3>Maintained settings</h3><p>Read from Persephone; no repair runs until you review and confirm it.</p></div>${badge(passingChecks === checks.length ? 'ready' : 'incomplete')}</header>
553+
<div class="dio-persephone-reconcile-list">${checks.map((entry) => `<div class="${entry.ok ? 'ok' : 'failed'}"><i></i><span><strong>${esc(entry.check)}</strong><small>${esc(entry.detail)}</small></span></div>`).join('')}</div>
554+
</article>
555+
<article class="dio-persephone-card">
556+
<header><div><small>OMP PROFILES</small><h3>Discovered agents</h3></div></header>
557+
<div class="dio-persephone-profile-list">${profiles.map((profile) => `<div><strong>${esc(profile.profile)}</strong><code>${esc(profile.agentDir)}</code></div>`).join('')}</div>
558+
</article>
559+
</section>
560+
</div>` : (!integrationLoading ? panelMessage('Inventory not loaded', 'Use Check again to ask Persephone for its current owner inventory.') : '')}`;
561+
}
562+
563+
function renderIntegrationOwner(entry) {
564+
const ready = Boolean(entry.configured && entry.ownerContractPresent);
565+
return `<article class="dio-persephone-card dio-persephone-integration-owner">
566+
<header><div><small>${esc(entry.key)}</small><h3>${esc(entry.label)}</h3></div>${badge(ready ? 'ready' : (entry.configured ? 'missing' : 'disabled'))}</header>
567+
<dl>
568+
<div><dt>Repository</dt><dd><code>${esc(entry.directory)}</code></dd></div>
569+
<div><dt>Owner contract</dt><dd><code>${esc(entry.ownerContract)}</code></dd></div>
570+
</dl>
571+
<div class="dio-persephone-integration-meta">
572+
<span>MCP ${esc((entry.mcpNames || []).join(', ') || 'none')}</span>
573+
<span>${(entry.activeProfiles || []).length} active profile${(entry.activeProfiles || []).length === 1 ? '' : 's'}</span>
574+
</div>
575+
<div class="dio-persephone-profile-chips">${(entry.activeProfiles || []).map((profile) => `<span>${esc(profile)}</span>`).join('')}</div>
576+
</article>`;
577+
}
578+
514579
function renderSetup() {
515580
const guides = workspace.setup || {};
516581
return `${sectionHeading('Setup', 'Provider-side steps and copy-ready values generated by the owner repository.')}
@@ -600,6 +665,28 @@ async function loadWorkspace(force = false) {
600665
}
601666
}
602667

668+
async function loadIntegrations(force = false) {
669+
if (integrationLoading) return;
670+
integrationLoading = true;
671+
if (force) integrationError = '';
672+
render();
673+
try {
674+
integrationInventory = await request('/api/odysseus/persephone/integrations');
675+
integrationError = '';
676+
} catch (caught) {
677+
integrationError = caught?.message || String(caught);
678+
if (force) integrationInventory = null;
679+
} finally {
680+
integrationLoading = false;
681+
render();
682+
}
683+
}
684+
685+
async function refreshCurrent() {
686+
await loadWorkspace(true);
687+
if (view === 'integrations') await loadIntegrations(true);
688+
}
689+
603690
async function loadQueue(kind, id) {
604691
busy = `queue:${kind}:${id}`;
605692
error = '';
@@ -790,6 +877,7 @@ async function refreshAfterJob() {
790877
} catch (caught) {
791878
error = caught?.message || String(caught);
792879
}
880+
if (integrationInventory || view === 'integrations') await loadIntegrations(true);
793881
}
794882

795883
async function copyText(value) {
@@ -824,14 +912,15 @@ function panelMessage(title, detail = '') {
824912
}
825913

826914
function navLabel(name) {
827-
return ({ overview: 'Overview', connectors: 'Connectors', routes: 'Routes', runtime: 'Runtime', queues: 'Queues', schedules: 'Schedules', settings: 'Settings', setup: 'Setup guide' })[name] || titleCase(name);
915+
return ({ overview: 'Overview', connectors: 'Connectors', routes: 'Routes', runtime: 'Runtime', queues: 'Queues', schedules: 'Schedules', integrations: 'Integrations', settings: 'Settings', setup: 'Setup guide' })[name] || titleCase(name);
828916
}
829917

830918
function navCount(name) {
831919
if (name === 'routes') return `<em>${(workspace.routes || []).length}</em>`;
832920
if (name === 'runtime') return `<em>${(workspace.approvals || []).filter((entry) => entry.status === 'pending').length}</em>`;
833921
if (name === 'queues') return `<em>${(workspace.inbox || []).length + (workspace.outbox || []).length}</em>`;
834922
if (name === 'schedules') return `<em>${(workspace.schedules || []).length}</em>`;
923+
if (name === 'integrations' && integrationInventory) return `<em>${(integrationInventory.integrations || []).length}</em>`;
835924
return '';
836925
}
837926

‎static/style.css‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18853,6 +18853,30 @@ body:not(.email-doc-split-active) #email-lib-modal.email-lib-fullscreen:not(.mod
1885318853
.dio-persephone-connectors { grid-template-columns: repeat(3, minmax(270px, 1fr)); align-items: start; }
1885418854
.dio-persephone-settings { grid-template-columns: repeat(2, minmax(320px, 1fr)); }
1885518855
.dio-persephone-setup-grid { grid-template-columns: repeat(3, minmax(280px, 1fr)); align-items: start; }
18856+
.dio-persephone-integration-grid { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr); gap: 12px; align-items: start; }
18857+
.dio-persephone-integration-list,
18858+
.dio-persephone-integration-side { display: flex; flex-direction: column; gap: 12px; }
18859+
.dio-persephone-integration-owner dl { margin: 0; display: grid; gap: 8px; }
18860+
.dio-persephone-integration-owner dl > div { min-width: 0; padding: 8px; border: 1px solid var(--pers-line); border-radius: 7px; }
18861+
.dio-persephone-integration-owner dt { color: var(--text-muted, #777); font-size: 7px; letter-spacing: .08em; text-transform: uppercase; }
18862+
.dio-persephone-integration-owner dd { min-width: 0; margin: 4px 0 0; }
18863+
.dio-persephone-integration-owner code,
18864+
.dio-persephone-profile-list code { display: block; overflow-wrap: anywhere; color: color-mix(in srgb, var(--pers-accent) 72%, var(--text-color, #ddd)); font-size: 8px; }
18865+
.dio-persephone-integration-meta { margin: 10px 0 7px; display: flex; justify-content: space-between; gap: 8px; color: var(--text-muted, #888); font-size: 8px; }
18866+
.dio-persephone-profile-chips { display: flex; flex-wrap: wrap; gap: 5px; }
18867+
.dio-persephone-profile-chips span { padding: 3px 6px; border: 1px solid var(--pers-line); border-radius: 999px; color: var(--text-muted, #999); font-size: 7px; }
18868+
.dio-persephone-reconcile-list,
18869+
.dio-persephone-profile-list { max-height: 420px; display: flex; flex-direction: column; gap: 6px; overflow: auto; scrollbar-gutter: stable; }
18870+
.dio-persephone-reconcile-list > div,
18871+
.dio-persephone-profile-list > div { min-width: 0; padding: 8px; display: flex; align-items: flex-start; gap: 8px; border: 1px solid var(--pers-line); border-radius: 7px; }
18872+
.dio-persephone-reconcile-list i { width: 6px; height: 6px; margin-top: 3px; flex: 0 0 auto; border-radius: 50%; background: #b77c71; }
18873+
.dio-persephone-reconcile-list .ok i { background: #66c79a; }
18874+
.dio-persephone-reconcile-list span,
18875+
.dio-persephone-profile-list > div { min-width: 0; flex: 1; }
18876+
.dio-persephone-reconcile-list strong,
18877+
.dio-persephone-profile-list strong { display: block; overflow-wrap: anywhere; font-size: 8px; }
18878+
.dio-persephone-reconcile-list small { display: block; margin-top: 3px; overflow-wrap: anywhere; color: var(--text-muted, #777); font-size: 7px; }
18879+
.dio-persephone-metrics.integrations { grid-template-columns: repeat(4, minmax(110px, 1fr)); }
1885618880

1885718881
.dio-persephone-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
1885818882
.dio-persephone-form-grid .wide { grid-column: 1 / -1; }
@@ -19033,6 +19057,7 @@ button.dio-persephone-row.queue.active { border-color: color-mix(in srgb, var(--
1903319057
.dio-persephone-runtime-grid.lower,
1903419058
.dio-persephone-queue-layout,
1903519059
.dio-persephone-schedule-layout { grid-template-columns: 1fr; }
19060+
.dio-persephone-integration-grid { grid-template-columns: 1fr; }
1903619061
.dio-persephone-queue-detail,
1903719062
.dio-persephone-schedule-editor,
1903819063
.dio-persephone-schedule-help { position: static; }
@@ -19054,6 +19079,7 @@ button.dio-persephone-row.queue.active { border-color: color-mix(in srgb, var(--
1905419079
.dio-persephone-runtime-grid.lower,
1905519080
.dio-persephone-queue-layout,
1905619081
.dio-persephone-schedule-layout { grid-template-columns: 1fr; }
19082+
.dio-persephone-integration-grid { grid-template-columns: 1fr; }
1905719083
.dio-persephone-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1905819084
.dio-persephone-queue-detail,
1905919085
.dio-persephone-schedule-editor,

‎tests/test_diogenes_persephone_workspace.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def run(argv, **kwargs):
3434
"lines": 25,
3535
"text": "owner log\n",
3636
}
37+
elif argv[1:] == ["integrations"]:
38+
value = {
39+
"schemaVersion": "persephone.integration-inventory.v1",
40+
"profiles": [],
41+
"integrations": [{"key": "localflame"}],
42+
"ompReconciliation": [],
43+
}
3744
else:
3845
value = {
3946
"schemaVersion": "persephone.workspace.v1",
@@ -46,13 +53,16 @@ def run(argv, **kwargs):
4653
report = control.observe(limit=12)
4754
record = control.queue_record(kind="inbox", record_id=7)
4855
logs = control.logs(lines=25)
56+
integrations = control.integrations()
4957

5058
assert report["schemaVersion"] == "persephone.workspace.v1"
5159
assert record == {"kind": "inbox", "id": 7, "body": "hello"}
5260
assert logs["text"] == "owner log\n"
61+
assert integrations["integrations"] == [{"key": "localflame"}]
5362
assert calls[0][0][1:] == ["workspace", "show", "--limit", "12"]
5463
assert calls[1][0][1:] == ["workspace", "queue", "inbox", "7"]
5564
assert calls[2][0][1:] == ["workspace", "logs", "--lines", "25"]
65+
assert calls[3][0][1:] == ["integrations"]
5666
assert "VIRTUAL_ENV" not in calls[0][1]["env"]
5767

5868
with pytest.raises(PersephoneWorkspaceError):
@@ -87,5 +97,10 @@ def test_lifecycle_plans_are_fixed_owner_cli_actions(tmp_path) -> None:
8797
["restart"],
8898
["status"],
8999
]
100+
reconcile, _token = control.create_lifecycle_plan(action="reconcile")
101+
assert [step["argv"][1:] for step in reconcile["steps"]] == [
102+
["reconcile"],
103+
["doctor", "--integration-only"],
104+
]
90105
with pytest.raises(PersephoneWorkspaceError):
91106
control.create_lifecycle_plan(action="shell")

‎tests/test_ulysses_routes.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ def observe(self, *, limit=50):
238238
"schedules": [],
239239
}
240240

241+
def integrations(self):
242+
self.calls.append(("integrations",))
243+
return {
244+
"schemaVersion": "persephone.integration-inventory.v1",
245+
"profiles": [],
246+
"integrations": [{"key": "localflame"}],
247+
"ompReconciliation": [],
248+
}
249+
241250
def queue_record(self, *, kind, record_id):
242251
self.calls.append(("queue", kind, record_id))
243252
return {"kind": kind, "id": record_id, "body": "full body"}
@@ -616,6 +625,7 @@ def test_persephone_workspace_routes_delegate_to_owner_cli_contract(monkeypatch)
616625
)
617626

618627
report = client.get("/api/odysseus/persephone/workspace", params={"limit": 17})
628+
integrations = client.get("/api/odysseus/persephone/integrations")
619629
record = client.get("/api/odysseus/persephone/queue/inbox/9")
620630
logs = client.get("/api/odysseus/persephone/logs", params={"lines": 33})
621631
lifecycle = client.post(
@@ -636,12 +646,14 @@ def test_persephone_workspace_routes_delegate_to_owner_cli_contract(monkeypatch)
636646

637647
assert report.status_code == 200
638648
assert report.json()["schemaVersion"] == "persephone.workspace.v1"
649+
assert integrations.json()["integrations"] == [{"key": "localflame"}]
639650
assert record.json()["body"] == "full body"
640651
assert logs.json()["text"] == "owner log\n"
641652
assert lifecycle.json()["confirmation_token"] == "persephone-lifecycle-token"
642653
assert mutation.json()["job"]["action"] == "queue.retry"
643654
assert owner.calls == [
644655
("observe", 17),
656+
("integrations",),
645657
("queue", "inbox", 9),
646658
("logs", 33),
647659
("lifecycle", "restart"),

0 commit comments

Comments
 (0)