@@ -4,7 +4,7 @@ import { makeWindowDraggable } from './windowDrag.js';
44
55const MODAL_ID = 'diogenes-persephone-workspace-modal' ;
66const TERMINAL = new Set ( [ 'succeeded' , 'failed' , 'cancelled' ] ) ;
7- const VIEWS = [ 'overview' , 'connectors' , 'routes' , 'queues' , 'schedules' , 'settings' , 'setup' ] ;
7+ const VIEWS = [ 'overview' , 'connectors' , 'routes' , 'runtime' , ' queues', 'schedules' , 'settings' , 'setup' ] ;
88const 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"/>
@@ -22,6 +22,9 @@ let queueKind = 'inbox';
2222let selectedQueue = null ;
2323let scheduleDraft = null ;
2424let dispatchDraft = { channel : 'api' , peerId : 'owner' , message : '' } ;
25+ let runtimeLogs = null ;
26+ let runtimeLogsLoading = false ;
27+ let approvalValues = { } ;
2528let busy = '' ;
2629let error = '' ;
2730let notice = '' ;
@@ -92,6 +95,7 @@ function onInput(event) {
9295 }
9396 if ( target . matches ( '[data-pers-schedule]' ) ) updateScheduleValue ( target ) ;
9497 if ( target . matches ( '[data-pers-dispatch]' ) ) dispatchDraft [ target . dataset . persDispatch ] = target . value ;
98+ if ( target . matches ( '[data-pers-approval-value]' ) ) approvalValues [ target . dataset . persApprovalValue ] = target . value ;
9599}
96100
97101function onChange ( event ) {
@@ -131,6 +135,13 @@ function onClick(event) {
131135 copyText ( selectedQueue ?. body || '' ) ;
132136 return ;
133137 }
138+ if ( event . target . closest ( '[data-pers-logs-load]' ) ) { loadRuntimeLogs ( ) ; return ; }
139+ if ( event . target . closest ( '[data-pers-copy-logs]' ) ) { copyText ( runtimeLogs ?. text || '' ) ; return ; }
140+ const approvalAction = event . target . closest ( '[data-pers-approval-action]' ) ;
141+ if ( approvalAction ) {
142+ resolveApproval ( Number ( approvalAction . dataset . persApprovalId ) , approvalAction . dataset . persApprovalAction ) ;
143+ return ;
144+ }
134145 const kind = event . target . closest ( '[data-pers-queue-kind]' ) ;
135146 if ( kind ) { queueKind = kind . dataset . persQueueKind ; selectedQueue = null ; render ( ) ; return ; }
136147 const queue = event . target . closest ( '[data-pers-queue-open]' ) ;
@@ -203,6 +214,7 @@ function render() {
203214function renderView ( ) {
204215 if ( view === 'connectors' ) return renderConnectors ( ) ;
205216 if ( view === 'routes' ) return renderRoutes ( ) ;
217+ if ( view === 'runtime' ) return renderRuntime ( ) ;
206218 if ( view === 'queues' ) return renderQueues ( ) ;
207219 if ( view === 'schedules' ) return renderSchedules ( ) ;
208220 if ( view === 'settings' ) return renderSettings ( ) ;
@@ -338,6 +350,69 @@ function renderRoutes() {
338350 </div>` ;
339351}
340352
353+ function renderRuntime ( ) {
354+ const runtime = workspace . runtime || { } ;
355+ const loops = Object . entries ( runtime . loops || { } ) ;
356+ const liveWorkers = Array . isArray ( runtime . workerState ) ? runtime . workerState : [ ] ;
357+ const workers = workspace . workers || [ ] ;
358+ const approvals = workspace . approvals || [ ] ;
359+ return `${ sectionHeading ( 'Runtime' , 'Inspect daemon loops, OMP workers, pending approvals, and an on-demand service log snapshot.' ) }
360+ <div class="dio-persephone-runtime-grid">
361+ <article class="dio-persephone-card dio-persephone-runtime-card">
362+ <header><div><small>DAEMON</small><h3>Loops</h3><p>${ runtime . ok ? `${ formatDuration ( runtime . uptimeSeconds ) } · PID ${ esc ( runtime . pid || '—' ) } ` : 'Service status is unavailable.' } </p></div>${ badge ( runtime . ok ? 'running' : 'stopped' ) } </header>
363+ <div class="dio-persephone-loop-grid">
364+ ${ loops . length ? loops . map ( ( [ name , state ] ) => `<div>
365+ <header><strong>${ esc ( titleCase ( name ) ) } </strong>${ badge ( state . running ? 'running' : 'stopped' ) } </header>
366+ <span>${ Number ( state . starts ) || 0 } start${ Number ( state . starts ) === 1 ? '' : 's' } · ${ Number ( state . failures ) || 0 } failure${ Number ( state . failures ) === 1 ? '' : 's' } </span>
367+ <small>${ state . lastError ? esc ( state . lastError ) : `started ${ formatTime ( state . lastStartedAt ) } ` } </small>
368+ </div>` ) . join ( '' ) : panelMessage ( 'No loop status' , 'Start Persephone to populate daemon loop state.' ) }
369+ </div>
370+ <dl class="dio-persephone-runtime-stats">
371+ <div><dt>Active routes</dt><dd>${ Number ( runtime . routing ?. activeRoutes ) || 0 } </dd></div>
372+ <div><dt>Queued messages</dt><dd>${ Number ( runtime . routing ?. inFlightAndQueuedMessages ) || 0 } </dd></div>
373+ <div><dt>Queued behind active</dt><dd>${ Number ( runtime . routing ?. queuedBehindActive ) || 0 } </dd></div>
374+ </dl>
375+ </article>
376+ <article class="dio-persephone-card dio-persephone-runtime-card">
377+ <header><div><small>WORKERS</small><h3>Processes and sessions</h3><p>${ liveWorkers . length } live · ${ workers . length } persisted</p></div></header>
378+ <div class="dio-persephone-worker-list">
379+ ${ liveWorkers . length ? liveWorkers . map ( ( worker ) => `<div><header><strong>${ esc ( worker . key || 'worker' ) } </strong>${ badge ( worker . occupied ? 'busy' : ( worker . alive ? 'ready' : 'stopped' ) ) } </header><code>PID ${ esc ( worker . pid || '—' ) } · ${ esc ( worker . sessionPath || 'session pending' ) } </code>${ worker . nativeSwarm ? `<small>${ esc ( typeof worker . nativeSwarm === 'string' ? worker . nativeSwarm : JSON . stringify ( worker . nativeSwarm ) ) } </small>` : '' } </div>` ) . join ( '' ) : '<small class="dio-persephone-muted">No live worker processes.</small>' }
380+ ${ workers . map ( ( worker ) => `<div class="persisted"><header><strong>${ esc ( worker . workerKey ) } </strong>${ badge ( worker . status ) } </header><span>${ esc ( worker . profile ) } · PID ${ esc ( worker . pid || '—' ) } </span><code>${ esc ( worker . sessionPath || 'session pending' ) } </code><small>${ esc ( worker . cwd ) } · seen ${ formatTime ( worker . lastSeen ) } </small></div>` ) . join ( '' ) }
381+ </div>
382+ </article>
383+ </div>
384+ <div class="dio-persephone-runtime-grid lower">
385+ <article class="dio-persephone-card dio-persephone-runtime-card approvals">
386+ <header><div><small>APPROVALS</small><h3>OMP requests</h3><p>Responses travel through the same conversation route that received the request.</p></div><span>${ approvals . filter ( ( entry ) => entry . status === 'pending' ) . length } pending</span></header>
387+ <div class="dio-persephone-approval-list">
388+ ${ approvals . length ? approvals . map ( ( approval ) => renderApproval ( approval ) ) . join ( '' ) : panelMessage ( 'No approvals' , 'OMP approval requests will appear here.' ) }
389+ </div>
390+ </article>
391+ <article class="dio-persephone-card dio-persephone-runtime-card logs">
392+ <header><div><small>SERVICE</small><h3>Journal</h3><p>Loaded only when requested; output is bounded by Persephone.</p></div><div class="dio-persephone-row-actions"><button type="button" data-pers-logs-load ${ runtimeLogsLoading ? 'disabled' : '' } >${ runtimeLogsLoading ? 'Loading…' : ( runtimeLogs ? 'Reload' : 'Load logs' ) } </button>${ runtimeLogs ?. text ? '<button type="button" data-pers-copy-logs>Copy</button>' : '' } </div></header>
393+ ${ renderRuntimeLogs ( ) }
394+ </article>
395+ </div>` ;
396+ }
397+
398+ function renderApproval ( approval ) {
399+ const pending = approval . status === 'pending' ;
400+ const needsValue = pending && approval . method !== 'confirm' ;
401+ return `<div class="dio-persephone-approval">
402+ <header><strong>#${ esc ( approval . id ) } · ${ esc ( approval . title || approval . method ) } </strong>${ badge ( approval . status ) } </header>
403+ <p>${ esc ( approval . message || '' ) } </p>
404+ <small>${ esc ( approval . channel ) } :${ esc ( approval . peerId ) } · ${ esc ( approval . method ) } · expires ${ formatTime ( approval . expiresAt ) } </small>
405+ ${ pending ? `<div class="dio-persephone-approval-actions">${ needsValue ? `<input data-pers-approval-value="${ esc ( approval . id ) } " value="${ esc ( approvalValues [ approval . id ] || '' ) } " placeholder="Approval value">` : '' } <button type="button" data-pers-approval-action="approve" data-pers-approval-id="${ esc ( approval . id ) } " ${ busy ? 'disabled' : '' } >Approve</button><button type="button" class="danger" data-pers-approval-action="deny" data-pers-approval-id="${ esc ( approval . id ) } " ${ busy ? 'disabled' : '' } >Deny</button></div>` : '' }
406+ </div>` ;
407+ }
408+
409+ function renderRuntimeLogs ( ) {
410+ if ( runtimeLogsLoading ) return panelMessage ( 'Reading service journal…' , 'Persephone is requesting a bounded user-unit snapshot.' ) ;
411+ if ( ! runtimeLogs ) return panelMessage ( 'Logs are not loaded' , 'Use Load logs when diagnostics are needed. No polling occurs.' ) ;
412+ if ( ! runtimeLogs . available && ! runtimeLogs . text ) return panelMessage ( 'Journal unavailable' , runtimeLogs . error || 'The owner could not read its user service journal.' ) ;
413+ return `${ runtimeLogs . error ? `<div class="dio-persephone-inline-error">${ esc ( runtimeLogs . error ) } </div>` : '' } <div class="dio-persephone-log-meta"><span>${ esc ( runtimeLogs . lines ) } requested lines</span><span>${ runtimeLogs . truncated ? 'character limit applied' : 'complete snapshot' } </span><span>${ formatTime ( runtimeLogs . generatedAt ) } </span></div><pre class="dio-persephone-service-log">${ esc ( runtimeLogs . text || '' ) } </pre>` ;
414+ }
415+
341416function renderQueues ( ) {
342417 const records = workspace [ queueKind ] || [ ] ;
343418 return `${ sectionHeading ( 'Queues' , 'Inspect bounded previews, open a complete record, or retry a failed delivery.' ) }
@@ -445,7 +520,9 @@ function renderSetup() {
445520 return `<article class="dio-persephone-card setup">
446521 <header><div class="dio-persephone-brand ${ name } ">${ name === 'slack' ? '#' : name [ 0 ] . toUpperCase ( ) } </div><div><h3>${ esc ( guide . title || titleCase ( name ) ) } </h3><p>${ esc ( guide . summary || '' ) } </p></div></header>
447522 <ol>${ ( guide . steps || [ ] ) . map ( ( step ) => `<li>${ esc ( step ) } </li>` ) . join ( '' ) } </ol>
523+ <div class="dio-persephone-validation">${ ( guide . validation || [ ] ) . map ( ( item ) => `<div class="${ item . ok ? 'ok' : '' } "><i></i><span>${ esc ( item . label ) } </span><strong>${ item . ok ? 'ready' : 'needed' } </strong></div>` ) . join ( '' ) } </div>
448524 <div class="dio-persephone-copy-list">${ ( guide . copy || [ ] ) . map ( ( item ) => `<div><span>${ esc ( item . label ) } </span><code>${ esc ( item . value ) } </code><button type="button" data-pers-copy="${ esc ( item . value ) } ">Copy</button></div>` ) . join ( '' ) } </div>
525+ ${ ( guide . resources || [ ] ) . length ? `<div class="dio-persephone-resources">${ guide . resources . map ( ( item ) => `<a href="${ esc ( item . url ) } " target="_blank" rel="noopener noreferrer">${ esc ( item . label ) } </a>` ) . join ( '' ) } </div>` : '' }
449526 </article>` ;
450527 } ) . join ( '' ) }
451528 </div>` ;
@@ -537,6 +614,22 @@ async function loadQueue(kind, id) {
537614 }
538615}
539616
617+ async function loadRuntimeLogs ( ) {
618+ if ( runtimeLogsLoading ) return ;
619+ runtimeLogsLoading = true ;
620+ error = '' ;
621+ render ( ) ;
622+ try {
623+ runtimeLogs = await request ( '/api/odysseus/persephone/logs?lines=300' ) ;
624+ } catch ( caught ) {
625+ runtimeLogs = null ;
626+ error = caught ?. message || String ( caught ) ;
627+ } finally {
628+ runtimeLogsLoading = false ;
629+ render ( ) ;
630+ }
631+ }
632+
540633async function saveConfiguration ( ) {
541634 if ( busy || ! configDraft ) return ;
542635 await runMutation ( {
@@ -589,6 +682,26 @@ async function dispatchPrompt() {
589682 if ( completed ) dispatchDraft . message = '' ;
590683}
591684
685+ async function resolveApproval ( id , decision ) {
686+ const approval = ( workspace ?. approvals || [ ] ) . find ( ( entry ) => Number ( entry . id ) === id ) ;
687+ if ( ! approval || approval . status !== 'pending' || ! [ 'approve' , 'deny' ] . includes ( decision ) ) return ;
688+ const value = String ( approvalValues [ id ] || '' ) . trim ( ) ;
689+ if ( decision === 'approve' && approval . method !== 'confirm' && ! value ) {
690+ error = `Approval #${ id } needs a value.` ;
691+ render ( ) ;
692+ return ;
693+ }
694+ const suffix = decision === 'approve' && value ? ` ${ value } ` : '' ;
695+ const completed = await runMutation ( {
696+ version : 1 ,
697+ action : 'prompt.enqueue' ,
698+ channel : approval . channel ,
699+ peerId : approval . peerId ,
700+ message : `/${ decision } ${ id } ${ suffix } ` ,
701+ } , `approval:${ id } ` , `Queued /${ decision } for approval #${ id } .` , decision === 'deny' ) ;
702+ if ( completed ) delete approvalValues [ id ] ;
703+ }
704+
592705async function runMutation ( mutation , busyKey , successMessage , danger = false ) {
593706 if ( busy ) return false ;
594707 busy = busyKey ;
@@ -711,11 +824,12 @@ function panelMessage(title, detail = '') {
711824}
712825
713826function navLabel ( name ) {
714- return ( { overview : 'Overview' , connectors : 'Connectors' , routes : 'Routes' , queues : 'Queues' , schedules : 'Schedules' , settings : 'Settings' , setup : 'Setup guide' } ) [ name ] || titleCase ( name ) ;
827+ return ( { overview : 'Overview' , connectors : 'Connectors' , routes : 'Routes' , runtime : 'Runtime' , queues : 'Queues' , schedules : 'Schedules' , settings : 'Settings' , setup : 'Setup guide' } ) [ name ] || titleCase ( name ) ;
715828}
716829
717830function navCount ( name ) {
718831 if ( name === 'routes' ) return `<em>${ ( workspace . routes || [ ] ) . length } </em>` ;
832+ if ( name === 'runtime' ) return `<em>${ ( workspace . approvals || [ ] ) . filter ( ( entry ) => entry . status === 'pending' ) . length } </em>` ;
719833 if ( name === 'queues' ) return `<em>${ ( workspace . inbox || [ ] ) . length + ( workspace . outbox || [ ] ) . length } </em>` ;
720834 if ( name === 'schedules' ) return `<em>${ ( workspace . schedules || [ ] ) . length } </em>` ;
721835 return '' ;
@@ -733,9 +847,10 @@ function formatDuration(seconds) {
733847}
734848
735849function formatTime ( value ) {
736- const number = Number ( value ) ;
737- if ( ! number ) return 'never' ;
738- try { return new Date ( number ) . toLocaleString ( ) ; } catch ( _ ) { return String ( value ) ; }
850+ if ( value === null || value === undefined || value === '' ) return 'never' ;
851+ const text = String ( value ) ;
852+ const date = / ^ \d + $ / . test ( text ) ? new Date ( Number ( text ) ) : new Date ( text ) ;
853+ return Number . isNaN ( date . getTime ( ) ) ? text : date . toLocaleString ( ) ;
739854}
740855
741856function blankSchedule ( ) {
0 commit comments