@apralabs/apra-fleet 0.3.5 → 0.4.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/README.md +245 -257
- package/dist/agents/backlog-groomer.md +287 -0
- package/dist/agents/deployer.md +52 -11
- package/dist/agents/doer.md +32 -7
- package/dist/agents/integ-test-runner.md +151 -61
- package/dist/agents/plan-reviewer.md +74 -17
- package/dist/agents/planner.md +94 -14
- package/dist/agents/regression-test-runner.md +216 -0
- package/dist/agents/reviewer.md +21 -6
- package/dist/agents/schemas/backlog-groomer-input.json +35 -0
- package/dist/agents/schemas/backlog-groomer-output.json +164 -0
- package/dist/agents/schemas/integ-test-runner-output.json +34 -0
- package/dist/agents/schemas/regression-test-runner-input.json +15 -0
- package/dist/agents/schemas/regression-test-runner-output.json +50 -0
- package/dist/agents/schemas/reviewer-output.json +4 -0
- package/dist/cli/agent-transform.d.ts +1 -0
- package/dist/cli/agent-transform.d.ts.map +1 -1
- package/dist/cli/agent-transform.js +77 -0
- package/dist/cli/agent-transform.js.map +1 -1
- package/dist/cli/auth.d.ts +3 -0
- package/dist/cli/auth.d.ts.map +1 -1
- package/dist/cli/auth.js +181 -5
- package/dist/cli/auth.js.map +1 -1
- package/dist/cli/config.d.ts +5 -1
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +7 -1
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/dolt-install.d.ts +91 -0
- package/dist/cli/dolt-install.d.ts.map +1 -0
- package/dist/cli/dolt-install.js +334 -0
- package/dist/cli/dolt-install.js.map +1 -0
- package/dist/cli/install-guard.d.ts +29 -0
- package/dist/cli/install-guard.d.ts.map +1 -0
- package/dist/cli/install-guard.js +153 -0
- package/dist/cli/install-guard.js.map +1 -0
- package/dist/cli/install.d.ts +44 -3
- package/dist/cli/install.d.ts.map +1 -1
- package/dist/cli/install.js +604 -108
- package/dist/cli/install.js.map +1 -1
- package/dist/cli/join.d.ts +12 -0
- package/dist/cli/join.d.ts.map +1 -0
- package/dist/cli/join.js +87 -0
- package/dist/cli/join.js.map +1 -0
- package/dist/cli/register-member.d.ts +2 -0
- package/dist/cli/register-member.d.ts.map +1 -0
- package/dist/cli/register-member.js +193 -0
- package/dist/cli/register-member.js.map +1 -0
- package/dist/cli/restart.d.ts +2 -0
- package/dist/cli/restart.d.ts.map +1 -0
- package/dist/cli/restart.js +7 -0
- package/dist/cli/restart.js.map +1 -0
- package/dist/cli/secret.js +8 -2
- package/dist/cli/secret.js.map +1 -1
- package/dist/cli/spoke.d.ts +35 -0
- package/dist/cli/spoke.d.ts.map +1 -0
- package/dist/cli/spoke.js +212 -0
- package/dist/cli/spoke.js.map +1 -0
- package/dist/cli/start.d.ts +2 -0
- package/dist/cli/start.d.ts.map +1 -0
- package/dist/cli/start.js +92 -0
- package/dist/cli/start.js.map +1 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.d.ts.map +1 -0
- package/dist/cli/status.js +83 -0
- package/dist/cli/status.js.map +1 -0
- package/dist/cli/stop.d.ts +2 -0
- package/dist/cli/stop.d.ts.map +1 -0
- package/dist/cli/stop.js +51 -0
- package/dist/cli/stop.js.map +1 -0
- package/dist/cli/uninstall.d.ts.map +1 -1
- package/dist/cli/uninstall.js +109 -9
- package/dist/cli/uninstall.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +10 -1
- package/dist/cli/update.js.map +1 -1
- package/dist/cli/workflow-assets.d.ts +37 -0
- package/dist/cli/workflow-assets.d.ts.map +1 -0
- package/dist/cli/workflow-assets.js +144 -0
- package/dist/cli/workflow-assets.js.map +1 -0
- package/dist/cli/workflow.d.ts +75 -0
- package/dist/cli/workflow.d.ts.map +1 -0
- package/dist/cli/workflow.js +397 -0
- package/dist/cli/workflow.js.map +1 -0
- package/dist/hub-service/activity.d.ts +30 -0
- package/dist/hub-service/activity.d.ts.map +1 -0
- package/dist/hub-service/activity.js +20 -0
- package/dist/hub-service/activity.js.map +1 -0
- package/dist/hub-service/audit-log.d.ts +19 -0
- package/dist/hub-service/audit-log.d.ts.map +1 -0
- package/dist/hub-service/audit-log.js +13 -0
- package/dist/hub-service/audit-log.js.map +1 -0
- package/dist/hub-service/db/pool.d.ts +19 -0
- package/dist/hub-service/db/pool.d.ts.map +1 -0
- package/dist/hub-service/db/pool.js +53 -0
- package/dist/hub-service/db/pool.js.map +1 -0
- package/dist/hub-service/enrollment.d.ts +29 -0
- package/dist/hub-service/enrollment.d.ts.map +1 -0
- package/dist/hub-service/enrollment.js +48 -0
- package/dist/hub-service/enrollment.js.map +1 -0
- package/dist/hub-service/envelope-routes.d.ts +46 -0
- package/dist/hub-service/envelope-routes.d.ts.map +1 -0
- package/dist/hub-service/envelope-routes.js +94 -0
- package/dist/hub-service/envelope-routes.js.map +1 -0
- package/dist/hub-service/handlers/installers.d.ts +14 -0
- package/dist/hub-service/handlers/installers.d.ts.map +1 -0
- package/dist/hub-service/handlers/installers.js +8 -0
- package/dist/hub-service/handlers/installers.js.map +1 -0
- package/dist/hub-service/http-server.d.ts +31 -0
- package/dist/hub-service/http-server.d.ts.map +1 -0
- package/dist/hub-service/http-server.js +711 -0
- package/dist/hub-service/http-server.js.map +1 -0
- package/dist/hub-service/hub-jwt.d.ts +30 -0
- package/dist/hub-service/hub-jwt.d.ts.map +1 -0
- package/dist/hub-service/hub-jwt.js +105 -0
- package/dist/hub-service/hub-jwt.js.map +1 -0
- package/dist/hub-service/jwt-revocation.d.ts +20 -0
- package/dist/hub-service/jwt-revocation.d.ts.map +1 -0
- package/dist/hub-service/jwt-revocation.js +18 -0
- package/dist/hub-service/jwt-revocation.js.map +1 -0
- package/dist/hub-service/machines.d.ts +16 -0
- package/dist/hub-service/machines.d.ts.map +1 -0
- package/dist/hub-service/machines.js +14 -0
- package/dist/hub-service/machines.js.map +1 -0
- package/dist/hub-service/main.d.ts +3 -0
- package/dist/hub-service/main.d.ts.map +1 -0
- package/dist/hub-service/main.js +64 -0
- package/dist/hub-service/main.js.map +1 -0
- package/dist/hub-service/member-tokens.d.ts +11 -0
- package/dist/hub-service/member-tokens.d.ts.map +1 -0
- package/dist/hub-service/member-tokens.js +49 -0
- package/dist/hub-service/member-tokens.js.map +1 -0
- package/dist/hub-service/member-view.d.ts +20 -0
- package/dist/hub-service/member-view.d.ts.map +1 -0
- package/dist/hub-service/member-view.js +76 -0
- package/dist/hub-service/member-view.js.map +1 -0
- package/dist/hub-service/members.d.ts +44 -0
- package/dist/hub-service/members.d.ts.map +1 -0
- package/dist/hub-service/members.js +25 -0
- package/dist/hub-service/members.js.map +1 -0
- package/dist/hub-service/presence.d.ts +40 -0
- package/dist/hub-service/presence.d.ts.map +1 -0
- package/dist/hub-service/presence.js +44 -0
- package/dist/hub-service/presence.js.map +1 -0
- package/dist/hub-service/project-view.d.ts +12 -0
- package/dist/hub-service/project-view.d.ts.map +1 -0
- package/dist/hub-service/project-view.js +34 -0
- package/dist/hub-service/project-view.js.map +1 -0
- package/dist/hub-service/projects.d.ts +48 -0
- package/dist/hub-service/projects.d.ts.map +1 -0
- package/dist/hub-service/projects.js +80 -0
- package/dist/hub-service/projects.js.map +1 -0
- package/dist/hub-service/relay-queue.d.ts +115 -0
- package/dist/hub-service/relay-queue.d.ts.map +1 -0
- package/dist/hub-service/relay-queue.js +148 -0
- package/dist/hub-service/relay-queue.js.map +1 -0
- package/dist/hub-service/session-jwt.d.ts +10 -0
- package/dist/hub-service/session-jwt.d.ts.map +1 -0
- package/dist/hub-service/session-jwt.js +69 -0
- package/dist/hub-service/session-jwt.js.map +1 -0
- package/dist/hub-service/usage.d.ts +40 -0
- package/dist/hub-service/usage.d.ts.map +1 -0
- package/dist/hub-service/usage.js +25 -0
- package/dist/hub-service/usage.js.map +1 -0
- package/dist/hub-service/users.d.ts +56 -0
- package/dist/hub-service/users.d.ts.map +1 -0
- package/dist/hub-service/users.js +72 -0
- package/dist/hub-service/users.js.map +1 -0
- package/dist/hub-service/workspaces.d.ts +20 -0
- package/dist/hub-service/workspaces.d.ts.map +1 -0
- package/dist/hub-service/workspaces.js +10 -0
- package/dist/hub-service/workspaces.js.map +1 -0
- package/dist/index.js +179 -132
- package/dist/index.js.map +1 -1
- package/dist/os/linux.d.ts +13 -0
- package/dist/os/linux.d.ts.map +1 -1
- package/dist/os/linux.js +62 -3
- package/dist/os/linux.js.map +1 -1
- package/dist/os/os-commands.d.ts +10 -0
- package/dist/os/os-commands.d.ts.map +1 -1
- package/dist/os/windows.d.ts +1 -0
- package/dist/os/windows.d.ts.map +1 -1
- package/dist/os/windows.js +21 -1
- package/dist/os/windows.js.map +1 -1
- package/dist/paths.d.ts +23 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +29 -0
- package/dist/paths.js.map +1 -1
- package/dist/providers/agy.d.ts +9 -2
- package/dist/providers/agy.d.ts.map +1 -1
- package/dist/providers/agy.js +127 -14
- package/dist/providers/agy.js.map +1 -1
- package/dist/providers/claude.d.ts +6 -2
- package/dist/providers/claude.d.ts.map +1 -1
- package/dist/providers/claude.js +248 -9
- package/dist/providers/claude.js.map +1 -1
- package/dist/providers/codex.d.ts +3 -2
- package/dist/providers/codex.d.ts.map +1 -1
- package/dist/providers/codex.js +7 -0
- package/dist/providers/codex.js.map +1 -1
- package/dist/providers/copilot.d.ts +3 -2
- package/dist/providers/copilot.d.ts.map +1 -1
- package/dist/providers/copilot.js +8 -1
- package/dist/providers/copilot.js.map +1 -1
- package/dist/providers/gemini.d.ts +3 -2
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +11 -1
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +3 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/none.d.ts +51 -0
- package/dist/providers/none.d.ts.map +1 -0
- package/dist/providers/none.js +103 -0
- package/dist/providers/none.js.map +1 -0
- package/dist/providers/opencode.d.ts +4 -2
- package/dist/providers/opencode.d.ts.map +1 -1
- package/dist/providers/opencode.js +49 -0
- package/dist/providers/opencode.js.map +1 -1
- package/dist/providers/provider.d.ts +79 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/provider.js +10 -0
- package/dist/providers/provider.js.map +1 -1
- package/dist/services/agent-provisioner.d.ts +3 -3
- package/dist/services/agent-provisioner.d.ts.map +1 -1
- package/dist/services/agent-provisioner.js +12 -5
- package/dist/services/agent-provisioner.js.map +1 -1
- package/dist/services/auth-socket.d.ts.map +1 -1
- package/dist/services/auth-socket.js +2 -0
- package/dist/services/auth-socket.js.map +1 -1
- package/dist/services/budget-awareness.d.ts +130 -0
- package/dist/services/budget-awareness.d.ts.map +1 -0
- package/dist/services/budget-awareness.js +129 -0
- package/dist/services/budget-awareness.js.map +1 -0
- package/dist/services/cloud-sync.d.ts +35 -0
- package/dist/services/cloud-sync.d.ts.map +1 -0
- package/dist/services/cloud-sync.js +90 -0
- package/dist/services/cloud-sync.js.map +1 -0
- package/dist/services/context-admission.d.ts +82 -0
- package/dist/services/context-admission.d.ts.map +1 -0
- package/dist/services/context-admission.js +136 -0
- package/dist/services/context-admission.js.map +1 -0
- package/dist/services/event-bus.d.ts +27 -0
- package/dist/services/event-bus.d.ts.map +1 -0
- package/dist/services/event-bus.js +20 -0
- package/dist/services/event-bus.js.map +1 -0
- package/dist/services/file-chunker.d.ts +38 -0
- package/dist/services/file-chunker.d.ts.map +1 -0
- package/dist/services/file-chunker.js +63 -0
- package/dist/services/file-chunker.js.map +1 -0
- package/dist/services/file-transfer-relay.d.ts +55 -0
- package/dist/services/file-transfer-relay.d.ts.map +1 -0
- package/dist/services/file-transfer-relay.js +115 -0
- package/dist/services/file-transfer-relay.js.map +1 -0
- package/dist/services/github-app.d.ts.map +1 -1
- package/dist/services/github-app.js +1 -0
- package/dist/services/github-app.js.map +1 -1
- package/dist/services/http-transport.d.ts +25 -0
- package/dist/services/http-transport.d.ts.map +1 -0
- package/dist/services/http-transport.js +371 -0
- package/dist/services/http-transport.js.map +1 -0
- package/dist/services/hub-client.d.ts +69 -0
- package/dist/services/hub-client.d.ts.map +1 -0
- package/dist/services/hub-client.js +217 -0
- package/dist/services/hub-client.js.map +1 -0
- package/dist/services/jwt.d.ts +17 -0
- package/dist/services/jwt.d.ts.map +1 -0
- package/dist/services/jwt.js +70 -0
- package/dist/services/jwt.js.map +1 -0
- package/dist/services/known-sessions.d.ts +8 -0
- package/dist/services/known-sessions.d.ts.map +1 -0
- package/dist/services/known-sessions.js +40 -0
- package/dist/services/known-sessions.js.map +1 -0
- package/dist/services/model-pricing.d.ts +36 -0
- package/dist/services/model-pricing.d.ts.map +1 -0
- package/dist/services/model-pricing.js +108 -0
- package/dist/services/model-pricing.js.map +1 -0
- package/dist/services/orphan-recovery.d.ts +56 -0
- package/dist/services/orphan-recovery.d.ts.map +1 -0
- package/dist/services/orphan-recovery.js +111 -0
- package/dist/services/orphan-recovery.js.map +1 -0
- package/dist/services/pending-responses.d.ts +23 -0
- package/dist/services/pending-responses.d.ts.map +1 -0
- package/dist/services/pending-responses.js +52 -0
- package/dist/services/pending-responses.js.map +1 -0
- package/dist/services/registry.d.ts +4 -1
- package/dist/services/registry.d.ts.map +1 -1
- package/dist/services/registry.js +3 -0
- package/dist/services/registry.js.map +1 -1
- package/dist/services/relay-context.d.ts +23 -0
- package/dist/services/relay-context.d.ts.map +1 -0
- package/dist/services/relay-context.js +8 -0
- package/dist/services/relay-context.js.map +1 -0
- package/dist/services/relay-executor.d.ts +68 -0
- package/dist/services/relay-executor.d.ts.map +1 -0
- package/dist/services/relay-executor.js +70 -0
- package/dist/services/relay-executor.js.map +1 -0
- package/dist/services/relay-request.d.ts +65 -0
- package/dist/services/relay-request.d.ts.map +1 -0
- package/dist/services/relay-request.js +129 -0
- package/dist/services/relay-request.js.map +1 -0
- package/dist/services/relay-strategy.d.ts +19 -0
- package/dist/services/relay-strategy.d.ts.map +1 -0
- package/dist/services/relay-strategy.js +111 -0
- package/dist/services/relay-strategy.js.map +1 -0
- package/dist/services/service-manager/index.d.ts +5 -0
- package/dist/services/service-manager/index.d.ts.map +1 -0
- package/dist/services/service-manager/index.js +66 -0
- package/dist/services/service-manager/index.js.map +1 -0
- package/dist/services/service-manager/linux.d.ts +10 -0
- package/dist/services/service-manager/linux.d.ts.map +1 -0
- package/dist/services/service-manager/linux.js +97 -0
- package/dist/services/service-manager/linux.js.map +1 -0
- package/dist/services/service-manager/macos.d.ts +10 -0
- package/dist/services/service-manager/macos.d.ts.map +1 -0
- package/dist/services/service-manager/macos.js +94 -0
- package/dist/services/service-manager/macos.js.map +1 -0
- package/dist/services/service-manager/types.d.ts +18 -0
- package/dist/services/service-manager/types.d.ts.map +1 -0
- package/dist/services/service-manager/types.js +5 -0
- package/dist/services/service-manager/types.js.map +1 -0
- package/dist/services/service-manager/windows.d.ts +10 -0
- package/dist/services/service-manager/windows.d.ts.map +1 -0
- package/dist/services/service-manager/windows.js +73 -0
- package/dist/services/service-manager/windows.js.map +1 -0
- package/dist/services/session-registry.d.ts +70 -0
- package/dist/services/session-registry.d.ts.map +1 -0
- package/dist/services/session-registry.js +91 -0
- package/dist/services/session-registry.js.map +1 -0
- package/dist/services/singleton.d.ts +15 -0
- package/dist/services/singleton.d.ts.map +1 -0
- package/dist/services/singleton.js +98 -0
- package/dist/services/singleton.js.map +1 -0
- package/dist/services/sprint-coordination.d.ts +168 -0
- package/dist/services/sprint-coordination.d.ts.map +1 -0
- package/dist/services/sprint-coordination.js +564 -0
- package/dist/services/sprint-coordination.js.map +1 -0
- package/dist/services/ssh.d.ts.map +1 -1
- package/dist/services/ssh.js +70 -3
- package/dist/services/ssh.js.map +1 -1
- package/dist/services/stall/log-path-resolver.d.ts.map +1 -1
- package/dist/services/stall/log-path-resolver.js +8 -1
- package/dist/services/stall/log-path-resolver.js.map +1 -1
- package/dist/services/stall/stall-detector.d.ts.map +1 -1
- package/dist/services/stall/stall-detector.js +39 -7
- package/dist/services/stall/stall-detector.js.map +1 -1
- package/dist/services/stall/stall-poller.d.ts +16 -0
- package/dist/services/stall/stall-poller.d.ts.map +1 -1
- package/dist/services/stall/stall-poller.js +136 -18
- package/dist/services/stall/stall-poller.js.map +1 -1
- package/dist/services/strategy.d.ts.map +1 -1
- package/dist/services/strategy.js +55 -5
- package/dist/services/strategy.js.map +1 -1
- package/dist/services/substitution-engine.d.ts +20 -0
- package/dist/services/substitution-engine.d.ts.map +1 -0
- package/dist/services/substitution-engine.js +92 -0
- package/dist/services/substitution-engine.js.map +1 -0
- package/dist/services/task-cleanup.d.ts.map +1 -1
- package/dist/services/task-cleanup.js +1 -9
- package/dist/services/task-cleanup.js.map +1 -1
- package/dist/services/token-issuer.d.ts +47 -0
- package/dist/services/token-issuer.d.ts.map +1 -0
- package/dist/services/token-issuer.js +63 -0
- package/dist/services/token-issuer.js.map +1 -0
- package/dist/services/tool-registry.d.ts +3 -0
- package/dist/services/tool-registry.d.ts.map +1 -0
- package/dist/services/tool-registry.js +139 -0
- package/dist/services/tool-registry.js.map +1 -0
- package/dist/services/user-config.d.ts +14 -0
- package/dist/services/user-config.d.ts.map +1 -1
- package/dist/services/user-config.js +55 -0
- package/dist/services/user-config.js.map +1 -1
- package/dist/services/vcs/types.d.ts +44 -0
- package/dist/services/vcs/types.d.ts.map +1 -1
- package/dist/skills/fleet-sprint-cli/SKILL.md +103 -0
- package/dist/skills/pm/cost.md +3 -0
- package/dist/skills/pm/doer-reviewer-loop.md +3 -0
- package/dist/tools/check-status.d.ts.map +1 -1
- package/dist/tools/check-status.js +8 -2
- package/dist/tools/check-status.js.map +1 -1
- package/dist/tools/child-id-allocator.d.ts +45 -0
- package/dist/tools/child-id-allocator.d.ts.map +1 -0
- package/dist/tools/child-id-allocator.js +62 -0
- package/dist/tools/child-id-allocator.js.map +1 -0
- package/dist/tools/cloud-control.d.ts +2 -2
- package/dist/tools/compose-permissions.d.ts +12 -4
- package/dist/tools/compose-permissions.d.ts.map +1 -1
- package/dist/tools/compose-permissions.js +55 -4
- package/dist/tools/compose-permissions.js.map +1 -1
- package/dist/tools/dolt-push-mutex.d.ts +44 -0
- package/dist/tools/dolt-push-mutex.d.ts.map +1 -0
- package/dist/tools/dolt-push-mutex.js +83 -0
- package/dist/tools/dolt-push-mutex.js.map +1 -0
- package/dist/tools/execute-command.d.ts +11 -1
- package/dist/tools/execute-command.d.ts.map +1 -1
- package/dist/tools/execute-command.js +22 -5
- package/dist/tools/execute-command.js.map +1 -1
- package/dist/tools/execute-prompt.d.ts +72 -12
- package/dist/tools/execute-prompt.d.ts.map +1 -1
- package/dist/tools/execute-prompt.js +962 -71
- package/dist/tools/execute-prompt.js.map +1 -1
- package/dist/tools/get-member-model-pricing.d.ts +21 -0
- package/dist/tools/get-member-model-pricing.d.ts.map +1 -0
- package/dist/tools/get-member-model-pricing.js +29 -0
- package/dist/tools/get-member-model-pricing.js.map +1 -0
- package/dist/tools/list-members.d.ts.map +1 -1
- package/dist/tools/list-members.js +39 -7
- package/dist/tools/list-members.js.map +1 -1
- package/dist/tools/member-detail.d.ts +1 -1
- package/dist/tools/member-detail.d.ts.map +1 -1
- package/dist/tools/member-detail.js +8 -2
- package/dist/tools/member-detail.js.map +1 -1
- package/dist/tools/member-reservation.d.ts +29 -0
- package/dist/tools/member-reservation.d.ts.map +1 -0
- package/dist/tools/member-reservation.js +71 -0
- package/dist/tools/member-reservation.js.map +1 -0
- package/dist/tools/provision-vcs-auth.d.ts +7 -7
- package/dist/tools/provision-vcs-auth.js +1 -1
- package/dist/tools/provision-vcs-auth.js.map +1 -1
- package/dist/tools/register-member.d.ts +17 -5
- package/dist/tools/register-member.d.ts.map +1 -1
- package/dist/tools/register-member.js +144 -5
- package/dist/tools/register-member.js.map +1 -1
- package/dist/tools/remove-member.d.ts +1 -1
- package/dist/tools/report-status.d.ts +33 -0
- package/dist/tools/report-status.d.ts.map +1 -0
- package/dist/tools/report-status.js +44 -0
- package/dist/tools/report-status.js.map +1 -0
- package/dist/tools/respond-to-message.d.ts +21 -0
- package/dist/tools/respond-to-message.d.ts.map +1 -0
- package/dist/tools/respond-to-message.js +23 -0
- package/dist/tools/respond-to-message.js.map +1 -0
- package/dist/tools/send-files.d.ts +3 -0
- package/dist/tools/send-files.d.ts.map +1 -1
- package/dist/tools/send-files.js +88 -8
- package/dist/tools/send-files.js.map +1 -1
- package/dist/tools/send-message.d.ts +27 -0
- package/dist/tools/send-message.d.ts.map +1 -0
- package/dist/tools/send-message.js +46 -0
- package/dist/tools/send-message.js.map +1 -0
- package/dist/tools/shutdown-server.d.ts +2 -0
- package/dist/tools/shutdown-server.d.ts.map +1 -1
- package/dist/tools/shutdown-server.js +19 -0
- package/dist/tools/shutdown-server.js.map +1 -1
- package/dist/tools/update-member.d.ts +8 -8
- package/dist/tools/update-member.d.ts.map +1 -1
- package/dist/tools/update-member.js +11 -1
- package/dist/tools/update-member.js.map +1 -1
- package/dist/types.d.ts +15 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/agent-helpers.d.ts +2 -1
- package/dist/utils/agent-helpers.d.ts.map +1 -1
- package/dist/utils/agent-helpers.js +7 -2
- package/dist/utils/agent-helpers.js.map +1 -1
- package/dist/utils/pid-helpers.d.ts +15 -0
- package/dist/utils/pid-helpers.d.ts.map +1 -1
- package/dist/utils/pid-helpers.js +23 -0
- package/dist/utils/pid-helpers.js.map +1 -1
- package/dist/utils/process-utils.d.ts +3 -0
- package/dist/utils/process-utils.d.ts.map +1 -0
- package/dist/utils/process-utils.js +42 -0
- package/dist/utils/process-utils.js.map +1 -0
- package/dist/utils/prompt-errors.d.ts +2 -1
- package/dist/utils/prompt-errors.d.ts.map +1 -1
- package/dist/utils/prompt-errors.js +13 -3
- package/dist/utils/prompt-errors.js.map +1 -1
- package/dist/utils/workspace-trust.d.ts +24 -0
- package/dist/utils/workspace-trust.d.ts.map +1 -0
- package/dist/utils/workspace-trust.js +35 -0
- package/dist/utils/workspace-trust.js.map +1 -0
- package/dist/workflows/auto-sprint.js +450 -87
- package/package.json +35 -7
- package/packages/apra-fleet-client/package.json +26 -0
- package/packages/apra-fleet-client/src/client/api.mjs +396 -0
- package/packages/apra-fleet-client/src/client/client.mjs +146 -0
- package/packages/apra-fleet-client/src/client/errors.mjs +71 -0
- package/packages/apra-fleet-client/src/client/factory.mjs +65 -0
- package/packages/apra-fleet-client/src/client/server-resolution.mjs +265 -0
- package/packages/apra-fleet-client/src/client/transport.mjs +327 -0
- package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +287 -0
- package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +89 -0
- package/packages/apra-fleet-se/apra-pm/agents/deployer.md +139 -0
- package/packages/apra-fleet-se/apra-pm/agents/doer.md +225 -0
- package/packages/apra-fleet-se/apra-pm/agents/harvester.md +169 -0
- package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +316 -0
- package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +188 -0
- package/packages/apra-fleet-se/apra-pm/agents/planner.md +239 -0
- package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +216 -0
- package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +174 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/backlog-groomer-input.json +35 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/backlog-groomer-output.json +164 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/ci-watcher-input.json +26 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/ci-watcher-output.json +18 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-input.json +19 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +17 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-input.json +25 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +22 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/harvester-input.json +31 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/harvester-output.json +18 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-input.json +20 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-output.json +61 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/plan-reviewer-input.json +15 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/plan-reviewer-output.json +30 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/regression-test-runner-input.json +15 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/regression-test-runner-output.json +50 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-input.json +25 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +38 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/SKILL.md +402 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/beads.md +142 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +157 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/doer-reviewer-loop.md +300 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +121 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/simple-sprint.md +65 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +327 -0
- package/packages/apra-fleet-se/apra-pm/skills/pm/worktrees.md +92 -0
- package/packages/apra-fleet-se/apra-pm/version.json +3 -0
- package/packages/apra-fleet-se/bin/cli.mjs +857 -0
- package/packages/apra-fleet-se/bin/serve.mjs +383 -0
- package/packages/apra-fleet-se/fleet-sprint/conflict-ladder.mjs +178 -0
- package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +914 -0
- package/packages/apra-fleet-se/fleet-sprint/dispatch-safety-guard.mjs +177 -0
- package/packages/apra-fleet-se/fleet-sprint/docs/README.md +191 -0
- package/packages/apra-fleet-se/fleet-sprint/docs/coach-role-design.md +151 -0
- package/packages/apra-fleet-se/fleet-sprint/docs/dolt-tier2-runbook.md +127 -0
- package/packages/apra-fleet-se/fleet-sprint/docs/fleet-sprint-diagram.md +94 -0
- package/packages/apra-fleet-se/fleet-sprint/docs/stabilization-log.md +1125 -0
- package/packages/apra-fleet-se/fleet-sprint/dolt-literal-guard.mjs +72 -0
- package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-path-b.mjs +339 -0
- package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-tier2.mjs +360 -0
- package/packages/apra-fleet-se/fleet-sprint/dolt-recovery.mjs +363 -0
- package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +1244 -0
- package/packages/apra-fleet-se/fleet-sprint/errors.mjs +572 -0
- package/packages/apra-fleet-se/fleet-sprint/full-db-fetch-guard.mjs +118 -0
- package/packages/apra-fleet-se/fleet-sprint/runner.js +9447 -0
- package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +103 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-lock.mjs +140 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-module.mjs +435 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/azure-devops.mjs +68 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +53 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/dolt.mjs +146 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/generic-git.mjs +176 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +222 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +218 -0
- package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +882 -0
- package/packages/apra-fleet-se/package.json +28 -0
- package/packages/apra-fleet-se/workflow.json +1 -0
- package/packages/apra-fleet-workflow/package.json +30 -0
- package/packages/apra-fleet-workflow/src/viewer/command-output-cap.mjs +112 -0
- package/packages/apra-fleet-workflow/src/viewer/debounced-writer.mjs +153 -0
- package/packages/apra-fleet-workflow/src/viewer/html-utils.mjs +31 -0
- package/packages/apra-fleet-workflow/src/viewer/index.mjs +1325 -0
- package/packages/apra-fleet-workflow/src/viewer/lean-state.mjs +237 -0
- package/packages/apra-fleet-workflow/src/viewer/run-state-paths.mjs +130 -0
- package/packages/apra-fleet-workflow/src/viewer/sprint-state-paths.mjs +29 -0
- package/packages/apra-fleet-workflow/src/workflow/engine.mjs +200 -0
- package/packages/apra-fleet-workflow/src/workflow/errors.mjs +146 -0
- package/packages/apra-fleet-workflow/src/workflow/index.mjs +1723 -0
- package/packages/apra-fleet-workflow/src/workflow/journal.mjs +291 -0
- package/packages/apra-fleet-workflow/src/workflow/pricing.mjs +99 -0
- package/packages/apra-fleet-workflow/src/workflow/vetting.mjs +111 -0
- package/scripts/agy-transcript-reader.js +1 -0
- package/scripts/fleet-statusline.sh +17 -13
- package/skills/fleet/SKILL.md +37 -2
- package/skills/fleet/beads.md +14 -7
- package/skills/fleet/permissions.md +50 -0
- package/skills/fleet/profiles/base-dev.json +1 -0
- package/skills/fleet/profiles/base-reviewer.json +1 -0
- package/skills/fleet/profiles/node.json +2 -2
- package/version.json +1 -1
- package/scripts/agy-settings-merge.js +0 -27
- /package/{dist → packages/apra-fleet-se/apra-pm}/agents/_shared/GRAPH-SEMANTICS.md +0 -0
|
@@ -0,0 +1,1325 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { randomUUID } from 'crypto';
|
|
5
|
+
import { escapeHtml } from './html-utils.mjs';
|
|
6
|
+
import { DebouncedStateWriter, DEFAULT_DEBOUNCE_MS, writeJsonFileAtomic } from './debounced-writer.mjs';
|
|
7
|
+
import { getRunningRunStatePath, getTerminalRunStatePath } from './run-state-paths.mjs';
|
|
8
|
+
import { buildListStatePayload, resolveStringRefs } from './lean-state.mjs';
|
|
9
|
+
import { capCommandActivityMeta, getFullOutput } from './command-output-cap.mjs';
|
|
10
|
+
|
|
11
|
+
// apra-fleet-eft.6.5: the SAME template serves both the live view and the
|
|
12
|
+
// process-free History view -- `opts.history` (true) feeds a FROZEN state
|
|
13
|
+
// object directly into the page instead of the live view's
|
|
14
|
+
// fetch('/state') + EventSource('/events') polling loop, and hides the Save
|
|
15
|
+
// / Stop controls (there is no live workflow left to save/stop, and nothing
|
|
16
|
+
// to stream: a finished run's child process, and therefore those
|
|
17
|
+
// endpoints, no longer exists). `opts.state` is embedded as a JSON literal;
|
|
18
|
+
// any literal `</script>`-like sequence inside it is escaped so it can never
|
|
19
|
+
// terminate the embedding <script> tag early.
|
|
20
|
+
const HTML_TEMPLATE = (dashboardExtensions, opts = {}) => {
|
|
21
|
+
const isHistory = !!opts.history;
|
|
22
|
+
const frozenStateLiteral = isHistory
|
|
23
|
+
? JSON.stringify(opts.state ?? null).replace(/</g, '\\u003c')
|
|
24
|
+
: 'null';
|
|
25
|
+
return `<!DOCTYPE html>
|
|
26
|
+
<html lang="en">
|
|
27
|
+
<head>
|
|
28
|
+
<meta charset="UTF-8">
|
|
29
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
30
|
+
<title>Workflow Dashboard</title>
|
|
31
|
+
<style>
|
|
32
|
+
:root {
|
|
33
|
+
--bg: #09090b; --bg-glass: rgba(24, 24, 27, 0.6); --border: rgba(255, 255, 255, 0.1);
|
|
34
|
+
--text: #e4e4e7; --text-muted: #a1a1aa; --accent: #3b82f6; --accent-glow: rgba(59, 130, 246, 0.2);
|
|
35
|
+
--success: #10b981; --warning: #f59e0b; --danger: #ef4444;
|
|
36
|
+
}
|
|
37
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
38
|
+
/* apra-fleet-eft.43 (measured live, Chrome, 799px window): without an
|
|
39
|
+
explicit height on <html>, and with only overflow: hidden on <body>,
|
|
40
|
+
the whole page grew to fit every activity (documentElement.scrollHeight
|
|
41
|
+
ended up EQUAL to clientHeight -- the window itself could never scroll,
|
|
42
|
+
body's overflow: hidden made sure of that -- while #stream-list's own
|
|
43
|
+
scrollHeight/clientHeight were also equal, because ITS height was
|
|
44
|
+
unbounded too: nothing above it in the ancestor chain actually pinned
|
|
45
|
+
it to the viewport). html,body height: 100% plus body's own 100dvh
|
|
46
|
+
(falls back to 100vh in browsers that predate dvh) is what makes the
|
|
47
|
+
flex-column layout below a fixed-size box in the first place -- only
|
|
48
|
+
then does #stream-list's flex: 1; min-height: 0; overflow-y: auto
|
|
49
|
+
actually have a bounded parent to scroll inside of. */
|
|
50
|
+
html, body { height: 100%; }
|
|
51
|
+
body { background: var(--bg); color: var(--text); font-family: sans-serif; height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
|
|
52
|
+
.header { flex-shrink: 0; display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--bg-glass); border-bottom: 1px solid var(--border); }
|
|
53
|
+
.header h1 { font-size: 16px; font-weight: 600; margin: 0; }
|
|
54
|
+
.header-actions { display: flex; gap: 12px; align-items: center; }
|
|
55
|
+
|
|
56
|
+
.stats-banner { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); background: rgba(0,0,0,0.3); padding: 4px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.05); }
|
|
57
|
+
.stats-banner span strong { color: var(--text); font-weight: 600; }
|
|
58
|
+
.stats-banner span strong.spent { color: var(--success); }
|
|
59
|
+
|
|
60
|
+
.btn { padding: 4px 12px; font-size: 12px; border-radius: 4px; border: none; cursor: pointer; font-weight: 600; transition: opacity 0.2s; }
|
|
61
|
+
.btn:hover { opacity: 0.8; }
|
|
62
|
+
.btn-save { background: var(--accent); color: #fff; }
|
|
63
|
+
.btn-stop { background: var(--danger); color: #fff; }
|
|
64
|
+
.btn-secondary { background: rgba(255,255,255,0.1); color: var(--text); }
|
|
65
|
+
|
|
66
|
+
/* min-height: 0 on every rung of the flex chain: a flex item's default
|
|
67
|
+
min-height is content-sized, which lets a tall Activity list push the
|
|
68
|
+
panel past its parent instead of the inner .stream-list scrolling.
|
|
69
|
+
overflow: hidden alone is not reliable across the nested flex levels
|
|
70
|
+
here -- without the explicit 0, large runs ended up with a clipped,
|
|
71
|
+
unscrollable activity widget. */
|
|
72
|
+
.main-content { display: flex; flex: 1; overflow: hidden; min-height: 0; }
|
|
73
|
+
|
|
74
|
+
.content-area { flex: 1; padding: 20px; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
|
|
75
|
+
.panel { background: var(--bg-glass); border: 1px solid var(--border); border-radius: 6px; display: flex; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }
|
|
76
|
+
.panel-header { flex-shrink: 0; padding: 10px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); background: rgba(255,255,255,0.02); text-transform: uppercase; letter-spacing: 0.5px; }
|
|
77
|
+
|
|
78
|
+
.stream-list { flex: 1; min-height: 0; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; background: #000; }
|
|
79
|
+
|
|
80
|
+
/* Tree Group */
|
|
81
|
+
/* apra-fleet-7lk / apra-fleet-eft.43: .tree-group and .tree-phase are
|
|
82
|
+
both flex ITEMS of an ancestor display: flex; flex-direction: column
|
|
83
|
+
container (#stream-list, .group-body) with no explicit height of their
|
|
84
|
+
own -- a flex item's default flex-shrink: 1 lets the browser squish it
|
|
85
|
+
below its content's natural size whenever the column tries to fit more
|
|
86
|
+
rows than its bounded parent has room for, instead of just letting the
|
|
87
|
+
(already scrollable, overflow-y: auto) ancestor grow past the fold and
|
|
88
|
+
scroll. flex-shrink: 0 pins each row to its content size so the bounded
|
|
89
|
+
pane scrolls, rather than crushing its children to fit. */
|
|
90
|
+
.tree-group { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
|
|
91
|
+
.group-header { padding: 12px 16px; background: rgba(0,0,0,0.4); cursor: pointer; display: flex; justify-content: space-between; align-items: center; user-select: none; outline: none; list-style: none; }
|
|
92
|
+
.group-header h3 { font-size: 14px; font-weight: 700; color: var(--accent); margin: 0; }
|
|
93
|
+
.group-header:hover { background: rgba(0,0,0,0.6); }
|
|
94
|
+
.group-header::-webkit-details-marker { display: none; }
|
|
95
|
+
.group-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
|
|
96
|
+
|
|
97
|
+
/* Tree Phase */
|
|
98
|
+
.tree-phase { background: rgba(0,0,0,0.2); border: 1px solid rgba(255,255,255,0.05); border-radius: 6px; overflow: hidden; flex-shrink: 0; }
|
|
99
|
+
.phase-header { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; user-select: none; border-bottom: 1px solid rgba(255,255,255,0.02); outline: none; list-style: none; }
|
|
100
|
+
.phase-header h4 { font-size: 13px; font-weight: 600; color: #e4e4e7; margin: 0; }
|
|
101
|
+
.phase-header:hover { background: rgba(255,255,255,0.05); }
|
|
102
|
+
.phase-header::-webkit-details-marker { display: none; }
|
|
103
|
+
/* apra-fleet-eft.53.2: mirrors .activity-meta -- the single flex item on
|
|
104
|
+
the right-hand side of the header's space-between row, so the phase
|
|
105
|
+
duration always sits flush right next to the toggle icon exactly like
|
|
106
|
+
an activity row's duration sits next to its status badge. */
|
|
107
|
+
.phase-meta { display: flex; gap: 12px; align-items: center; font-size: 11px; color: #a1a1aa; flex-shrink: 0; }
|
|
108
|
+
.phase-body { padding: 8px; display: flex; flex-direction: column; gap: 4px; }
|
|
109
|
+
|
|
110
|
+
.event-log { display: flex; gap: 8px; font-family: monospace; font-size: 12px; color: #d4d4d8; padding: 2px 4px; border-radius: 4px; }
|
|
111
|
+
.event-log:hover { background: rgba(255,255,255,0.05); }
|
|
112
|
+
.log-time { color: #52525b; width: 60px; flex-shrink: 0; user-select: none; }
|
|
113
|
+
.log-msg { white-space: pre-wrap; word-break: break-word; }
|
|
114
|
+
|
|
115
|
+
details.event-activity { border: 1px solid rgba(255,255,255,0.05); border-radius: 4px; background: rgba(255,255,255,0.02); font-family: monospace; margin: 2px 0; }
|
|
116
|
+
details.event-activity.log-multiline { border-color: rgba(255,255,255,0.02); background: transparent; }
|
|
117
|
+
details.event-activity.log-multiline summary { padding: 4px 8px; }
|
|
118
|
+
|
|
119
|
+
summary.activity-header { display: flex; align-items: center; padding: 6px 8px; font-size: 12px; gap: 8px; cursor: pointer; user-select: none; list-style: none; outline: none; }
|
|
120
|
+
summary.activity-header::-webkit-details-marker { display: none; }
|
|
121
|
+
summary.activity-header:hover { background: rgba(255,255,255,0.04); }
|
|
122
|
+
|
|
123
|
+
.activity-title { flex: 1; color: #e4e4e7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
124
|
+
.activity-title .muted { color: #a1a1aa; font-weight: normal; font-size: 11px; margin-left: 6px; }
|
|
125
|
+
.activity-meta { display: flex; gap: 12px; align-items: center; font-size: 11px; color: #a1a1aa; flex-shrink: 0; }
|
|
126
|
+
|
|
127
|
+
.toggle-icon { margin-left: 8px; font-family: monospace; font-size: 14px; color: var(--text-muted); width: 14px; text-align: center; }
|
|
128
|
+
details:not([open]) > summary .toggle-icon::after { content: "+"; }
|
|
129
|
+
details[open] > summary .toggle-icon::after { content: "-"; }
|
|
130
|
+
|
|
131
|
+
.activity-body { padding: 0; background: #050505; border-top: 1px solid rgba(255,255,255,0.05); }
|
|
132
|
+
.activity-child { padding: 12px; font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; }
|
|
133
|
+
.activity-child.output { color: #a1a1aa; border-left: 2px solid var(--accent); }
|
|
134
|
+
.activity-child.error { background: rgba(239, 68, 68, 0.05); color: var(--danger); border-left: 2px solid var(--danger); }
|
|
135
|
+
|
|
136
|
+
/* apra-fleet-eft.38: on-demand full-output button for a capped command
|
|
137
|
+
activity (GET /activities/:id/output, wired up in eft.27.4 but never
|
|
138
|
+
surfaced client-side until now). Deliberately its own small element,
|
|
139
|
+
never the activity's summary/header -- headers/titles stay a plain
|
|
140
|
+
expand/collapse toggle only. */
|
|
141
|
+
.more-btn { margin-left: 8px; padding: 1px 8px; font-size: 11px; font-family: sans-serif; border-radius: 4px; border: 1px solid var(--border); background: rgba(255,255,255,0.06); color: var(--accent); cursor: pointer; }
|
|
142
|
+
.more-btn:hover { background: rgba(255,255,255,0.12); }
|
|
143
|
+
.more-btn:disabled { cursor: default; opacity: 0.6; }
|
|
144
|
+
|
|
145
|
+
.status-badge { padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
|
|
146
|
+
.status-running { background: var(--accent-glow); color: var(--accent); animation: pulse 2s infinite; }
|
|
147
|
+
.status-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
|
|
148
|
+
.status-error { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
|
|
149
|
+
.status-offline { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
|
|
150
|
+
|
|
151
|
+
.status-live-indicator { display: inline-flex; align-items: center; gap: 6px; color: var(--success); font-weight: 700; letter-spacing: 0.5px; }
|
|
152
|
+
.led { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px var(--success); animation: pulse 2s infinite; }
|
|
153
|
+
|
|
154
|
+
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.6; } 100% { opacity: 1; } }
|
|
155
|
+
|
|
156
|
+
.tab-bar { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 8px; }
|
|
157
|
+
.tab-btn { background: transparent; color: #a1a1aa; border: none; padding: 6px 12px; cursor: pointer; border-radius: 4px; font-size: 13px; }
|
|
158
|
+
.tab-btn:hover { background: rgba(255,255,255,0.05); }
|
|
159
|
+
.tab-btn.active { color: #fff; background: rgba(255,255,255,0.1); }
|
|
160
|
+
.tab-content { display: none; }
|
|
161
|
+
/* apra-fleet-m0c: both #tab-core and #tab-beads also carry .panel
|
|
162
|
+
(flex column, flex:1, overflow:hidden), which is what lets
|
|
163
|
+
.stream-list's flex:1 + overflow-y:auto bound its height and scroll
|
|
164
|
+
on its own. A plain block display here had higher specificity
|
|
165
|
+
(.tab-content.active = 2 classes vs .panel = 1) and silently
|
|
166
|
+
overrode that to a plain block, so the whole page grew to fit every
|
|
167
|
+
activity instead of the inner list scrolling -- collapsing items was
|
|
168
|
+
the only way to shrink total height. Flex here still wins on
|
|
169
|
+
specificity but no longer conflicts with .panel's own flex layout. */
|
|
170
|
+
.tab-content.active { display: flex; min-height: 0; }
|
|
171
|
+
</style>
|
|
172
|
+
</head>
|
|
173
|
+
<body data-view="${isHistory ? 'history' : 'live'}">
|
|
174
|
+
<div class="header">
|
|
175
|
+
<h1><span id="workflow-name">Loading...</span></h1>
|
|
176
|
+
<div class="header-actions">
|
|
177
|
+
<!-- apra-fleet-eft.37.3: generic, workflow-agnostic display of
|
|
178
|
+
state.result's top-level SCALAR fields -- populated (or hidden,
|
|
179
|
+
when empty) by renderState() below. Core never knows what keys
|
|
180
|
+
live inside 'result'; any richer, workflow-specific rendering
|
|
181
|
+
(e.g. auto-sprint's verdict badge/PR link) is layered on by a
|
|
182
|
+
dashboard extension's own js, not here. -->
|
|
183
|
+
<div class="stats-banner" id="result-strip" style="display: none;"></div>
|
|
184
|
+
<div class="stats-banner" id="stats-banner"></div>
|
|
185
|
+
<div id="status-indicator" style="font-size: 12px; font-weight: 600; min-width: 70px; text-align: center;"></div>
|
|
186
|
+
${isHistory ? '' : '<button class="btn btn-save" onclick="saveState()">Save</button>'}
|
|
187
|
+
${isHistory ? '' : '<button class="btn btn-stop" onclick="stopWorkflow()">Stop</button>'}
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
<div class="main-content">
|
|
191
|
+
<div class="content-area">
|
|
192
|
+
<div class="tab-bar" id="tab-bar">
|
|
193
|
+
<button class="tab-btn active" onclick="switchTab('core')">Activity Tree</button>
|
|
194
|
+
${dashboardExtensions.map(ext => `<button class="tab-btn" onclick="switchTab('${ext.id}')">${ext.title}</button>`).join('\\n')}
|
|
195
|
+
</div>
|
|
196
|
+
<div id="tab-core" class="tab-content active panel">
|
|
197
|
+
<div class="panel-header" style="display: flex; justify-content: space-between; align-items: center;">
|
|
198
|
+
<span>Activity</span>
|
|
199
|
+
<button id="btn-toggle-all" onclick="toggleAllGlobal()" style="background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-family: monospace; font-size: 14px; font-weight: bold; transition: color 0.2s;">[+]</button>
|
|
200
|
+
</div>
|
|
201
|
+
<div class="stream-list" id="stream-list"></div>
|
|
202
|
+
</div>
|
|
203
|
+
${dashboardExtensions.map(ext => `
|
|
204
|
+
<div id="tab-${ext.id}" class="tab-content panel">
|
|
205
|
+
<div class="panel-header">${ext.title}</div>
|
|
206
|
+
<div id="extension-${ext.id}" style="flex: 1; min-height: 0; padding: 12px; overflow-y: auto;"></div>
|
|
207
|
+
</div>
|
|
208
|
+
`).join('\\n')}
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
${dashboardExtensions.map(ext => `<script>\n${ext.js}\n</script>`).join('\\n')}
|
|
212
|
+
<script>
|
|
213
|
+
let globalState = null;
|
|
214
|
+
function switchTab(id) {
|
|
215
|
+
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
|
216
|
+
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
|
217
|
+
event.currentTarget.classList.add('active');
|
|
218
|
+
document.getElementById('tab-' + id).classList.add('active');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function formatTime(ms) {
|
|
222
|
+
if (!ms) return '-';
|
|
223
|
+
return (ms / 1000).toFixed(1) + 's';
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function formatUptime(ms) {
|
|
227
|
+
if (!ms || ms < 0) return '0s';
|
|
228
|
+
let secs = Math.floor(ms / 1000);
|
|
229
|
+
let mins = Math.floor(secs / 60);
|
|
230
|
+
let hrs = Math.floor(mins / 60);
|
|
231
|
+
secs = secs % 60;
|
|
232
|
+
mins = mins % 60;
|
|
233
|
+
|
|
234
|
+
let out = [];
|
|
235
|
+
if (hrs > 0) out.push(hrs + 'hr');
|
|
236
|
+
if (mins > 0) out.push(mins + 'm');
|
|
237
|
+
out.push(secs + 's');
|
|
238
|
+
return out.join(' ');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Shared with dashboard extensions -- see src/viewer/html-utils.mjs for
|
|
242
|
+
// why this is embedded via escapeHtml.toString() instead of duplicated.
|
|
243
|
+
${escapeHtml.toString()}
|
|
244
|
+
|
|
245
|
+
// apra-fleet-eft.27.1: GET /state's lean list-state payload dedupes
|
|
246
|
+
// repeated strings into a shared \`_strings\` table (see
|
|
247
|
+
// src/viewer/lean-state.mjs) -- this is that module's resolveStringRefs()
|
|
248
|
+
// embedded verbatim (same .toString() pattern as escapeHtml above) so the
|
|
249
|
+
// browser can undo the same transform before rendering. Safe to run on
|
|
250
|
+
// ANY state object, including a History view's frozen literal that never
|
|
251
|
+
// went through dedupeStrings(): with no \`{ $ref }\` markers present it's a
|
|
252
|
+
// no-op pass-through.
|
|
253
|
+
${resolveStringRefs.toString()}
|
|
254
|
+
|
|
255
|
+
function saveState() {
|
|
256
|
+
if (!globalState) return;
|
|
257
|
+
const blob = new Blob([JSON.stringify(globalState, null, 2)], { type: "application/json" });
|
|
258
|
+
const url = URL.createObjectURL(blob);
|
|
259
|
+
const a = document.createElement('a');
|
|
260
|
+
a.href = url;
|
|
261
|
+
a.download = 'workflow-state.json';
|
|
262
|
+
a.click();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function stopWorkflow() {
|
|
266
|
+
if (confirm('Are you sure you want to forcibly stop the workflow?')) {
|
|
267
|
+
await fetch('/stop', { method: 'POST' });
|
|
268
|
+
alert('Stop signal sent.');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let allExpanded = true;
|
|
273
|
+
function toggleAllGlobal() {
|
|
274
|
+
allExpanded = !allExpanded;
|
|
275
|
+
document.querySelectorAll('details').forEach(d => {
|
|
276
|
+
if (allExpanded) d.setAttribute('open', '');
|
|
277
|
+
else d.removeAttribute('open');
|
|
278
|
+
});
|
|
279
|
+
const btn = document.getElementById('btn-toggle-all');
|
|
280
|
+
btn.textContent = allExpanded ? '[-]' : '[+]';
|
|
281
|
+
btn.style.color = allExpanded ? 'var(--text)' : 'var(--text-muted)';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
let isAutoScrolling = true;
|
|
285
|
+
const streamEl = document.getElementById('stream-list');
|
|
286
|
+
|
|
287
|
+
streamEl.addEventListener('scroll', () => {
|
|
288
|
+
isAutoScrolling = (streamEl.scrollTop + streamEl.clientHeight >= streamEl.scrollHeight - 30);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// apra-fleet-eft.38: on-demand full-output fetch for a capped command
|
|
292
|
+
// activity's 'more...' button (see fieldBlock() above). Delegated on
|
|
293
|
+
// streamEl (not one listener per button) since renderTreeIncremental()
|
|
294
|
+
// keeps appending new activity elements as the run progresses.
|
|
295
|
+
// Deliberately scoped to .more-btn clicks only -- never the activity's
|
|
296
|
+
// own <summary> header, which keeps its native <details> expand/collapse
|
|
297
|
+
// behavior untouched.
|
|
298
|
+
let expandedMoreBtn = null;
|
|
299
|
+
function collapseMoreBtn(btn) {
|
|
300
|
+
if (!btn) return;
|
|
301
|
+
const span = btn.previousElementSibling;
|
|
302
|
+
if (span && span.dataset.truncatedText !== undefined) {
|
|
303
|
+
span.textContent = span.dataset.truncatedText;
|
|
304
|
+
}
|
|
305
|
+
btn.dataset.state = '';
|
|
306
|
+
btn.disabled = false;
|
|
307
|
+
btn.textContent = btn.dataset.label || 'more...';
|
|
308
|
+
if (expandedMoreBtn === btn) expandedMoreBtn = null;
|
|
309
|
+
}
|
|
310
|
+
streamEl.addEventListener('click', async (e) => {
|
|
311
|
+
const btn = e.target.closest('.more-btn');
|
|
312
|
+
if (!btn) return;
|
|
313
|
+
const span = btn.previousElementSibling;
|
|
314
|
+
if (!span) return;
|
|
315
|
+
|
|
316
|
+
if (btn.dataset.state === 'expanded') {
|
|
317
|
+
// Toggle back to the capped preview -- no re-fetch needed.
|
|
318
|
+
collapseMoreBtn(btn);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (btn.dataset.state === 'loading') return;
|
|
322
|
+
|
|
323
|
+
// apra-fleet-eft.38: only ONE activity's full output is ever held
|
|
324
|
+
// expanded in the DOM at a time. Fetched command output can run to
|
|
325
|
+
// many MB, and keeping several fully expanded simultaneously is
|
|
326
|
+
// exactly the kind of unbounded-DOM growth apra-fleet-eft.27/27.4
|
|
327
|
+
// already fixed for the initial render -- a new 'more...' click
|
|
328
|
+
// collapses whichever block was previously expanded back to its
|
|
329
|
+
// capped preview first.
|
|
330
|
+
if (expandedMoreBtn && expandedMoreBtn !== btn) {
|
|
331
|
+
collapseMoreBtn(expandedMoreBtn);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (span.dataset.truncatedText === undefined) {
|
|
335
|
+
span.dataset.truncatedText = span.textContent;
|
|
336
|
+
}
|
|
337
|
+
const activityId = btn.dataset.activityId;
|
|
338
|
+
const field = btn.dataset.field;
|
|
339
|
+
btn.dataset.state = 'loading';
|
|
340
|
+
btn.disabled = true;
|
|
341
|
+
btn.textContent = 'loading...';
|
|
342
|
+
try {
|
|
343
|
+
const res = await fetch('/activities/' + encodeURIComponent(activityId) + '/output');
|
|
344
|
+
if (!res.ok) throw new Error('request failed: ' + res.status);
|
|
345
|
+
const data = await res.json();
|
|
346
|
+
const full = data[field];
|
|
347
|
+
if (typeof full !== 'string') throw new Error('missing ' + field + ' in response');
|
|
348
|
+
span.textContent = full;
|
|
349
|
+
btn.dataset.state = 'expanded';
|
|
350
|
+
btn.disabled = false;
|
|
351
|
+
btn.textContent = 'less';
|
|
352
|
+
expandedMoreBtn = btn;
|
|
353
|
+
} catch (err) {
|
|
354
|
+
btn.dataset.state = '';
|
|
355
|
+
btn.disabled = false;
|
|
356
|
+
btn.textContent = 'failed to load (retry?)';
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
${isHistory ? '' : `
|
|
361
|
+
// Coalesce SSE-triggered refreshes: a busy run broadcasts one event
|
|
362
|
+
// per log line / activity tick, and refetching + re-rendering the full
|
|
363
|
+
// (potentially multi-MB) /state payload for each of them is what made
|
|
364
|
+
// large runs sluggish. One trailing refresh per window is enough --
|
|
365
|
+
// renderState() always paints the latest snapshot, not a delta.
|
|
366
|
+
const POLL_COALESCE_MS = 400;
|
|
367
|
+
let pollTimer = null;
|
|
368
|
+
function schedulePoll() {
|
|
369
|
+
if (pollTimer) return;
|
|
370
|
+
pollTimer = setTimeout(() => { pollTimer = null; poll(); }, POLL_COALESCE_MS);
|
|
371
|
+
}
|
|
372
|
+
const source = new EventSource('/events');
|
|
373
|
+
source.onmessage = (e) => {
|
|
374
|
+
const ev = JSON.parse(e.data);
|
|
375
|
+
if (ev.type === 'state') {
|
|
376
|
+
const extEvent = new CustomEvent('workflow:state:' + ev.payload.namespace, { detail: ev.payload.data });
|
|
377
|
+
document.dispatchEvent(extEvent);
|
|
378
|
+
}
|
|
379
|
+
schedulePoll();
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// apra-fleet-36l.1: during a quiet period (no SSE messages at all --
|
|
383
|
+
// e.g. a long-running agent activity with no intermediate log/activity
|
|
384
|
+
// events) the EventSource-driven schedulePoll() above never fires, so
|
|
385
|
+
// the dashboard can sit on a stale /state snapshot indefinitely with no
|
|
386
|
+
// visible sign it's still alive. This client-side heartbeat interval is
|
|
387
|
+
// a second, independent trigger for the SAME schedulePoll()/poll() path
|
|
388
|
+
// (not a separate fetch), so it naturally coalesces with -- and never
|
|
389
|
+
// double-fires alongside -- a real event-driven poll: schedulePoll()'s
|
|
390
|
+
// own pollTimer guard (POLL_COALESCE_MS above) already no-ops if a poll
|
|
391
|
+
// is already scheduled/in flight when the heartbeat tick lands.
|
|
392
|
+
const HEARTBEAT_INTERVAL_MS = 7000;
|
|
393
|
+
setInterval(() => { schedulePoll(); }, HEARTBEAT_INTERVAL_MS);
|
|
394
|
+
`}
|
|
395
|
+
|
|
396
|
+
function renderTreeIncremental(tree) {
|
|
397
|
+
tree.forEach((group, gIdx) => {
|
|
398
|
+
let groupEl = document.getElementById('group-' + gIdx);
|
|
399
|
+
if (!groupEl) {
|
|
400
|
+
groupEl = document.createElement('details');
|
|
401
|
+
groupEl.id = 'group-' + gIdx;
|
|
402
|
+
groupEl.className = 'tree-group';
|
|
403
|
+
groupEl.open = true;
|
|
404
|
+
groupEl.innerHTML = \`<summary class="group-header"><h3>\${escapeHtml(group.title)}</h3><span class="toggle-icon"></span></summary><div class="group-body"></div>\`;
|
|
405
|
+
streamEl.appendChild(groupEl);
|
|
406
|
+
}
|
|
407
|
+
const groupBody = groupEl.querySelector('.group-body');
|
|
408
|
+
|
|
409
|
+
group.phases.forEach((phase, pIdx) => {
|
|
410
|
+
const phaseId = \`phase-\${gIdx}-\${pIdx}\`;
|
|
411
|
+
let phaseEl = document.getElementById(phaseId);
|
|
412
|
+
if (!phaseEl) {
|
|
413
|
+
phaseEl = document.createElement('details');
|
|
414
|
+
phaseEl.id = phaseId;
|
|
415
|
+
phaseEl.className = 'tree-phase';
|
|
416
|
+
phaseEl.open = true;
|
|
417
|
+
phaseEl.innerHTML = \`<summary class="phase-header"><h4>\${escapeHtml(phase.title)}</h4><div class="phase-meta"><span class="phase-duration"></span><span class="toggle-icon"></span></div></summary><div class="phase-body"></div>\`;
|
|
418
|
+
groupBody.appendChild(phaseEl);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// apra-fleet-eft.53.2: phase-header duration, mirroring the
|
|
422
|
+
// activity-duration convention (eft.45.1) -- while the phase
|
|
423
|
+
// is LIVE (phaseStartedAt set, no phaseEndedAt yet) show
|
|
424
|
+
// elapsed-since-start via formatUptime, recomputed from
|
|
425
|
+
// Date.now() on every renderTreeIncremental() call so it
|
|
426
|
+
// ticks forward on the normal refresh/SSE cadence with no
|
|
427
|
+
// dedicated timer. Once the phase EXITS (phaseEndedAt set)
|
|
428
|
+
// the frozen total is rendered via formatTime exactly like a
|
|
429
|
+
// completed activity's duration, and dataset.rendered is set
|
|
430
|
+
// so later re-renders (including of earlier-cycle phases
|
|
431
|
+
// after a resume/reload) never recompute it again.
|
|
432
|
+
const phaseDurationEl = phaseEl.querySelector('.phase-duration');
|
|
433
|
+
if (phaseDurationEl && phaseDurationEl.dataset.rendered !== 'done') {
|
|
434
|
+
let phaseDurationHtml = '';
|
|
435
|
+
if (phase.phaseEndedAt) {
|
|
436
|
+
phaseDurationHtml = formatTime(new Date(phase.phaseEndedAt).getTime() - new Date(phase.phaseStartedAt).getTime());
|
|
437
|
+
phaseDurationEl.dataset.rendered = 'done';
|
|
438
|
+
} else if (phase.phaseStartedAt) {
|
|
439
|
+
phaseDurationHtml = formatUptime(Date.now() - new Date(phase.phaseStartedAt).getTime());
|
|
440
|
+
}
|
|
441
|
+
phaseDurationEl.textContent = phaseDurationHtml;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const phaseBody = phaseEl.querySelector('.phase-body');
|
|
445
|
+
|
|
446
|
+
phase.events.forEach((ev, eIdx) => {
|
|
447
|
+
const evId = \`ev-\${gIdx}-\${pIdx}-\${eIdx}\`;
|
|
448
|
+
let evEl = document.getElementById(evId);
|
|
449
|
+
|
|
450
|
+
if (ev.type === 'log') {
|
|
451
|
+
if (!evEl) {
|
|
452
|
+
evEl = document.createElement('div');
|
|
453
|
+
evEl.id = evId;
|
|
454
|
+
const dateObj = new Date(ev.time || Date.now());
|
|
455
|
+
const t = isNaN(dateObj.getTime()) ? '-' : dateObj.toLocaleTimeString([], { hour12: false });
|
|
456
|
+
|
|
457
|
+
// apra-fleet-aqq: a log message needs truncation
|
|
458
|
+
// + drill-down whenever it would run past one row
|
|
459
|
+
// -- not just multiline ones. A single-line
|
|
460
|
+
// JSON.stringify'd verdict (e.g. the Plan
|
|
461
|
+
// Reviewer's) has no '\\n' at all but can easily
|
|
462
|
+
// run past a thousand characters, and used to
|
|
463
|
+
// render via the plain .log-msg path below, which
|
|
464
|
+
// has no length cap and just wraps across many
|
|
465
|
+
// rows with the full text always visible inline
|
|
466
|
+
// (no truncation, but also nothing to "drill
|
|
467
|
+
// into" -- it was simply always fully expanded).
|
|
468
|
+
// Both cases now share the same truncate-with-
|
|
469
|
+
// ellipsis + expandable-details treatment; only
|
|
470
|
+
// how the preview/full-text split is computed
|
|
471
|
+
// differs (by line vs. by character count).
|
|
472
|
+
const LOG_PREVIEW_CHARS = 200;
|
|
473
|
+
const isMultiline = ev.msg && ev.msg.includes('\\n');
|
|
474
|
+
const isLongSingleLine = ev.msg && !isMultiline && ev.msg.length > LOG_PREVIEW_CHARS;
|
|
475
|
+
if (isMultiline || isLongSingleLine) {
|
|
476
|
+
let firstLine, rest;
|
|
477
|
+
if (isMultiline) {
|
|
478
|
+
const lines = ev.msg.split('\\n');
|
|
479
|
+
firstLine = lines[0];
|
|
480
|
+
rest = lines.slice(1).join('\\n');
|
|
481
|
+
} else {
|
|
482
|
+
firstLine = ev.msg.slice(0, LOG_PREVIEW_CHARS);
|
|
483
|
+
rest = ev.msg.slice(LOG_PREVIEW_CHARS);
|
|
484
|
+
}
|
|
485
|
+
evEl.innerHTML = \`<details class="event-activity log-multiline">
|
|
486
|
+
<summary class="activity-header">
|
|
487
|
+
<span class="log-time">\${t}</span>
|
|
488
|
+
<span class="activity-title" style="font-family:monospace; font-size:12px; color:#d4d4d8; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
|
|
489
|
+
\${escapeHtml(firstLine)} <em style="color:#a1a1aa">...</em>
|
|
490
|
+
</span>
|
|
491
|
+
<div class="activity-meta"><span class="toggle-icon"></span></div>
|
|
492
|
+
</summary>
|
|
493
|
+
<div class="activity-body">
|
|
494
|
+
<div class="activity-child" style="color:#d4d4d8;">\${escapeHtml(isMultiline ? rest : ev.msg)}</div>
|
|
495
|
+
</div>
|
|
496
|
+
</details>\`;
|
|
497
|
+
} else {
|
|
498
|
+
evEl.className = 'event-log';
|
|
499
|
+
evEl.innerHTML = \`<span class="log-time">\${t}</span><span class="log-msg">\${escapeHtml(ev.msg)}</span>\`;
|
|
500
|
+
}
|
|
501
|
+
phaseBody.appendChild(evEl);
|
|
502
|
+
}
|
|
503
|
+
} else if (ev.type === 'activity') {
|
|
504
|
+
const act = ev.data;
|
|
505
|
+
if (!evEl) {
|
|
506
|
+
evEl = document.createElement('details');
|
|
507
|
+
evEl.id = evId;
|
|
508
|
+
evEl.className = 'event-activity';
|
|
509
|
+
if (act.isRunning) {
|
|
510
|
+
evEl.open = true;
|
|
511
|
+
}
|
|
512
|
+
phaseBody.appendChild(evEl);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// A finished activity's data never changes again
|
|
516
|
+
// (activity:end merges its meta exactly once), so
|
|
517
|
+
// re-render it exactly once. Rewriting every
|
|
518
|
+
// activity's innerHTML on every tick -- thousands of
|
|
519
|
+
// DOM subtrees, some holding megabyte agent outputs
|
|
520
|
+
// -- is the other half of what made large runs
|
|
521
|
+
// sluggish, and the constant churn also fought the
|
|
522
|
+
// user's own scrolling and text selection.
|
|
523
|
+
if (evEl.dataset.rendered === 'done') return;
|
|
524
|
+
|
|
525
|
+
// Update contents every tick to catch status changes
|
|
526
|
+
const dateObj = new Date(act.startTime || Date.now());
|
|
527
|
+
const t = isNaN(dateObj.getTime()) ? '-' : dateObj.toLocaleTimeString([], { hour12: false });
|
|
528
|
+
|
|
529
|
+
let badge = '';
|
|
530
|
+
if (act.isRunning) badge = '<span class="status-badge status-running">Running</span>';
|
|
531
|
+
else if (act.success) badge = '<span class="status-badge status-success">Success</span>';
|
|
532
|
+
else badge = '<span class="status-badge status-error">Failed</span>';
|
|
533
|
+
|
|
534
|
+
let childrenHtml = '';
|
|
535
|
+
if (!act.isRunning) {
|
|
536
|
+
// apra-fleet-eft.69.1: THE UNIFORM COMMAND/AGENT
|
|
537
|
+
// ROW-BODY RULE (bug item 3 -- "some command rows
|
|
538
|
+
// carry details in the body while many others
|
|
539
|
+
// show only a title; make the rule uniform and
|
|
540
|
+
// documented"). There is exactly ONE rule, and it
|
|
541
|
+
// is keyed ONLY on the two generic fields every
|
|
542
|
+
// completed activity may carry -- never on
|
|
543
|
+
// act.type, act.label, act.member, or any
|
|
544
|
+
// role/phase name (the HARD CONSTRAINT from
|
|
545
|
+
// apra-fleet-eft.69: no auto-sprint-specific
|
|
546
|
+
// special-casing in viewer code):
|
|
547
|
+
// 1. hasField('error') true -> render the error
|
|
548
|
+
// block (plus Output: underneath, if any).
|
|
549
|
+
// 2. else hasField('output') true -> render the
|
|
550
|
+
// output block.
|
|
551
|
+
// 3. else -> no body at all; the row is title
|
|
552
|
+
// only.
|
|
553
|
+
// hasField() below is true when the field is
|
|
554
|
+
// either a non-empty inline string OR carries the
|
|
555
|
+
// <field>Truncated/<field>ByteLength markers
|
|
556
|
+
// (lean-state.mjs / command-output-cap.mjs). This
|
|
557
|
+
// applies IDENTICALLY to every activity type --
|
|
558
|
+
// 'agent', 'command', 'transform', or any future
|
|
559
|
+
// generic type -- so a command that legitimately
|
|
560
|
+
// produced no output and no error (e.g. a plain
|
|
561
|
+
// 'git add', a successful 'bd update --claim')
|
|
562
|
+
// showing only its title is the CORRECT,
|
|
563
|
+
// consistent result of this one rule applied to
|
|
564
|
+
// different data, not a special case or a bug --
|
|
565
|
+
// the same command with real output/error would
|
|
566
|
+
// render a body exactly the same way an agent
|
|
567
|
+
// dispatch does. (The full invoked command text
|
|
568
|
+
// itself is NOT part of this rule -- it lives in
|
|
569
|
+
// the row's title/label, capped to 60 chars at
|
|
570
|
+
// dispatch time; the runner.js command() caller
|
|
571
|
+
// is responsible for choosing a diagnostic label
|
|
572
|
+
// when the command text alone would not be, same
|
|
573
|
+
// as agent()'s label.)
|
|
574
|
+
//
|
|
575
|
+
// apra-fleet-eft.38 (reopened): a REAL capped
|
|
576
|
+
// activity ships NO inline text field at all --
|
|
577
|
+
// only the markers (\${field}Truncated + the TRUE
|
|
578
|
+
// original \${field}ByteLength) plus a short
|
|
579
|
+
// \`summary\` string (see command-output-cap.mjs for
|
|
580
|
+
// \`command\` activities, and lean-state.mjs's
|
|
581
|
+
// summarizeHeavyFields() for every other activity
|
|
582
|
+
// type, e.g. \`agent\`). The previous version of this
|
|
583
|
+
// fix keyed the button on act.output/act.error
|
|
584
|
+
// being truthy, which a real capped payload never
|
|
585
|
+
// is -- 0 buttons ever rendered. hasField()/
|
|
586
|
+
// fieldBlock() below key on the MARKERS instead:
|
|
587
|
+
// present inline text wins as the preview when
|
|
588
|
+
// available (e.g. an uncapped History-view state),
|
|
589
|
+
// otherwise the leaned \`summary\` is the preview,
|
|
590
|
+
// and the 'more...' button (never on the
|
|
591
|
+
// activity's own summary/header, which stays a
|
|
592
|
+
// plain expand/collapse toggle only) fetches the
|
|
593
|
+
// full text on demand from GET
|
|
594
|
+
// /activities/:id/output.
|
|
595
|
+
const hasField = (field) =>
|
|
596
|
+
typeof act[field] === 'string' ||
|
|
597
|
+
act[field + 'Truncated'] ||
|
|
598
|
+
act[field + 'ByteLength'] !== undefined;
|
|
599
|
+
const fieldBlock = (prefix, field) => {
|
|
600
|
+
const truncated = act[field + 'Truncated'];
|
|
601
|
+
const bytes = act[field + 'ByteLength'];
|
|
602
|
+
const text = typeof act[field] === 'string'
|
|
603
|
+
? act[field]
|
|
604
|
+
: (typeof act.summary === 'string' ? act.summary : '');
|
|
605
|
+
const label = truncated
|
|
606
|
+
? \`more... (\${(bytes || 0).toLocaleString()} bytes total)\`
|
|
607
|
+
: '';
|
|
608
|
+
const btn = truncated
|
|
609
|
+
? \` <button type="button" class="more-btn" data-activity-id="\${escapeHtml(String(act.id))}" data-field="\${field}" data-label="\${escapeHtml(label)}">\${escapeHtml(label)}</button>\`
|
|
610
|
+
: '';
|
|
611
|
+
return \`\${prefix}<span class="output-text" data-field="\${field}">\${escapeHtml(text)}</span>\${btn}\`;
|
|
612
|
+
};
|
|
613
|
+
if (hasField('error')) {
|
|
614
|
+
childrenHtml = \`<div class="activity-child error">\${fieldBlock('', 'error')}\\n\\n\${act.input ? 'Input:\\n' + escapeHtml(act.input) + '\\n\\n' : ''}\${hasField('output') ? fieldBlock('Output:\\n', 'output') : ''}</div>\`;
|
|
615
|
+
} else if (hasField('output')) {
|
|
616
|
+
childrenHtml = \`<div class="activity-child output">\${act.input && act.type === 'transform' ? 'Input:\\n' + escapeHtml(act.input) + '\\n\\nOutput:\\n' : ''}\${fieldBlock('', 'output')}</div>\`;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// Token count and model tier are two DISTINCT pieces of
|
|
621
|
+
// information -- previously only tokensHtml existed,
|
|
622
|
+
// so a finished agent activity with no usage data (see
|
|
623
|
+
// apra-fleet-13o) rendered a bare "n/a" that was easy
|
|
624
|
+
// to misread as a missing model tier, when the model
|
|
625
|
+
// tier was never displayed at all. modelHtml surfaces
|
|
626
|
+
// act.model (e.g. "premium"/"standard", already
|
|
627
|
+
// present on every agent activity) explicitly.
|
|
628
|
+
let tokensHtml = act.usage ? \`<span style="color:var(--text-muted)">\${act.usage.total_tokens.toLocaleString()} tkns</span>\` : (act.type === 'agent' && !act.isRunning ? \`<span style="color:var(--text-muted)">n/a</span>\` : '');
|
|
629
|
+
const modelHtml = (act.type === 'agent' && act.model) ? \`<span style="color:var(--text-muted)">[\${escapeHtml(act.model)}]</span>\` : '';
|
|
630
|
+
const memberDisplay = act.member ? escapeHtml(act.member) : (act.type === 'transform' ? 'js' : '');
|
|
631
|
+
const memberHtml = memberDisplay ? \`<span class="muted">(\${memberDisplay})</span>\` : '';
|
|
632
|
+
|
|
633
|
+
// apra-fleet-eft.45.1: while an activity is still
|
|
634
|
+
// running (isRunning true, no final act.duration
|
|
635
|
+
// yet), render elapsed-since-start at the same right-
|
|
636
|
+
// edge slot the final duration occupies, using the
|
|
637
|
+
// same short-form ('0s'/'5s'/'1m 20s') as
|
|
638
|
+
// formatUptime -- not formatTime's '1.5s' decimal
|
|
639
|
+
// form, which is reserved for the completed-duration
|
|
640
|
+
// label. Recomputed from act.startTime on every
|
|
641
|
+
// render call, so each poll/refresh naturally ticks
|
|
642
|
+
// it forward without a dedicated timer (out of scope
|
|
643
|
+
// per eft.45). On completion this branch stops
|
|
644
|
+
// firing (act.isRunning goes false) and the existing
|
|
645
|
+
// act.duration branch below takes over unchanged.
|
|
646
|
+
let durationHtml = '';
|
|
647
|
+
if (act.isRunning) {
|
|
648
|
+
if (act.startTime) durationHtml = formatUptime(Date.now() - act.startTime);
|
|
649
|
+
} else if (act.duration) {
|
|
650
|
+
durationHtml = formatTime(act.duration);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
evEl.innerHTML = \`
|
|
654
|
+
<summary class="activity-header">
|
|
655
|
+
<span class="log-time">\${t}</span>
|
|
656
|
+
<span class="activity-title"><strong>\${escapeHtml(act.type.toUpperCase())}</strong>: \${escapeHtml(act.label)} \${memberHtml}</span>
|
|
657
|
+
<div class="activity-meta">
|
|
658
|
+
\${modelHtml}
|
|
659
|
+
\${tokensHtml}
|
|
660
|
+
\${durationHtml} \${badge}
|
|
661
|
+
<span class="toggle-icon"></span>
|
|
662
|
+
</div>
|
|
663
|
+
</summary>
|
|
664
|
+
\${childrenHtml ? \`<div class="activity-body">\${childrenHtml}</div>\` : ''}
|
|
665
|
+
\`;
|
|
666
|
+
if (!act.isRunning) evEl.dataset.rendered = 'done';
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// apra-fleet-eft.6.5: the DOM-update half of what used to be poll()'s try
|
|
674
|
+
// block, factored out so the History view can feed it a FROZEN state
|
|
675
|
+
// object directly (see the bottom of this script) without ever calling
|
|
676
|
+
// fetch('/state') itself -- poll() (live view only) still drives it from
|
|
677
|
+
// the network.
|
|
678
|
+
function renderState(state) {
|
|
679
|
+
globalState = state;
|
|
680
|
+
|
|
681
|
+
document.getElementById('workflow-name').textContent = state.workflowName;
|
|
682
|
+
|
|
683
|
+
const ind = document.getElementById('status-indicator');
|
|
684
|
+
if (state.status === 'running') { ind.innerHTML = '<div class="status-live-indicator"><div class="led"></div> LIVE</div>'; }
|
|
685
|
+
else if (state.status === 'success') { ind.innerHTML = '<span style="color:var(--success)">DONE</span>'; }
|
|
686
|
+
else if (state.status === 'cancelled') { ind.innerHTML = '<span style="color:var(--warning)">CANCELLED</span>'; }
|
|
687
|
+
else { ind.innerHTML = '<span style="color:var(--danger)">FAILED</span>'; }
|
|
688
|
+
|
|
689
|
+
const dur = state.status === 'running' ? Date.now() - state.stats.startTime : state.stats.durationMs;
|
|
690
|
+
const unknownCostSuffix = state.stats.unknownCostCount > 0 ? \` <span style="color:var(--warning)">(+\${state.stats.unknownCostCount} unknown)</span>\` : '';
|
|
691
|
+
document.getElementById('stats-banner').innerHTML =
|
|
692
|
+
\`<span><strong>\${state.stats.activitiesCount}</strong> Activities</span>
|
|
693
|
+
<span><strong class="spent">$\${state.stats.totalCost.toFixed(3)}</strong> Spent\${unknownCostSuffix}</span>
|
|
694
|
+
<span><strong>\${state.stats.totalTokens.toLocaleString()}</strong> Tokens</span>
|
|
695
|
+
<span><strong>\${formatUptime(dur)}</strong> Uptime</span>\`;
|
|
696
|
+
|
|
697
|
+
// apra-fleet-eft.37.3: generic Result strip -- every workflow gets
|
|
698
|
+
// its terminal result's top-level SCALAR (string/number/boolean/
|
|
699
|
+
// null) fields rendered as a plain key/value strip, no per-workflow
|
|
700
|
+
// registration needed. Core does not know or care what these keys
|
|
701
|
+
// mean; it only knows how to display a scalar. \`workflow:result\`
|
|
702
|
+
// is also dispatched (below) so a dashboard extension can layer
|
|
703
|
+
// richer, workflow-specific rendering (e.g. auto-sprint's verdict
|
|
704
|
+
// badge/PR link) on top of the same \`state.result\` object.
|
|
705
|
+
const resultStrip = document.getElementById('result-strip');
|
|
706
|
+
if (resultStrip) {
|
|
707
|
+
const result = state.result;
|
|
708
|
+
const scalarEntries = (result && typeof result === 'object' && !Array.isArray(result))
|
|
709
|
+
? Object.entries(result).filter(([, v]) => v === null || ['string', 'number', 'boolean'].includes(typeof v))
|
|
710
|
+
: [];
|
|
711
|
+
if (scalarEntries.length > 0) {
|
|
712
|
+
resultStrip.innerHTML = scalarEntries
|
|
713
|
+
.map(([k, v]) => \`<span><strong>\${escapeHtml(k)}</strong>: \${escapeHtml(String(v))}</span>\`)
|
|
714
|
+
.join('');
|
|
715
|
+
resultStrip.style.display = 'flex';
|
|
716
|
+
} else {
|
|
717
|
+
resultStrip.innerHTML = '';
|
|
718
|
+
resultStrip.style.display = 'none';
|
|
719
|
+
}
|
|
720
|
+
document.dispatchEvent(new CustomEvent('workflow:result', { detail: result ?? null }));
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
renderTreeIncremental(state.tree);
|
|
724
|
+
|
|
725
|
+
if (state.extensions) {
|
|
726
|
+
for (const [ns, data] of Object.entries(state.extensions)) {
|
|
727
|
+
const extEvent = new CustomEvent('workflow:state:' + ns, { detail: data });
|
|
728
|
+
document.dispatchEvent(extEvent);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
if (isAutoScrolling) {
|
|
733
|
+
streamEl.scrollTop = streamEl.scrollHeight;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
async function poll() {
|
|
738
|
+
try {
|
|
739
|
+
const res = await fetch('/state?_t=' + Date.now(), { cache: 'no-store' });
|
|
740
|
+
const raw = await res.json();
|
|
741
|
+
// apra-fleet-eft.27.1: undo the server's string-table dedup before
|
|
742
|
+
// handing the state to renderState()/renderTreeIncremental(), which
|
|
743
|
+
// both expect plain, already-resolved strings.
|
|
744
|
+
const state = resolveStringRefs(raw, raw._strings || []);
|
|
745
|
+
renderState(state);
|
|
746
|
+
} catch(e) {
|
|
747
|
+
console.error("Poll Error:", e);
|
|
748
|
+
if (globalState && (globalState.status === 'success' || globalState.status === 'failed' || globalState.status === 'cancelled')) {
|
|
749
|
+
// already done, ignore
|
|
750
|
+
} else {
|
|
751
|
+
document.getElementById('status-indicator').innerHTML = '<span class="status-badge status-offline">OFFLINE</span>';
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
${isHistory
|
|
757
|
+
? `// History view: render the frozen state ONCE, directly -- no
|
|
758
|
+
// fetch('/state') and no EventSource('/events') (asserted: zero polling
|
|
759
|
+
// requests for a finished run with zero running processes).
|
|
760
|
+
renderState(${frozenStateLiteral});`
|
|
761
|
+
: 'poll();'}
|
|
762
|
+
</script>
|
|
763
|
+
</body>
|
|
764
|
+
</html>`;
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
// apra-fleet-eft.37.4 (M3, docs/workflow-core-boundary-refactoring.md): the
|
|
768
|
+
// on-demand FULL-TEXT lookup used to live here as findBeadById(), a
|
|
769
|
+
// core function that reached into `state.extensions.beads.sprintTasks/
|
|
770
|
+
// backlogTasks` by name -- the one deliberate domain leak the eft.27.2
|
|
771
|
+
// comment it replaced used to call out explicitly. Core has no business
|
|
772
|
+
// knowing an extension's internal shape, so that function moved verbatim
|
|
773
|
+
// into the beads extension module itself
|
|
774
|
+
// (packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs, as
|
|
775
|
+
// `beadsExtension.detailLookup`). Core now only knows the GENERIC hook
|
|
776
|
+
// surface: any dashboard extension may register
|
|
777
|
+
// `detailLookup?: (state, id) => {text, updatedAt} | null`, and core serves
|
|
778
|
+
// GET /extensions/:extId/detail/:itemId (route below) by delegating to
|
|
779
|
+
// whichever extension's `id` matches `:extId` -- a template-method default
|
|
780
|
+
// of "no such extension/no hook -> 404", never a crash, for extensions that
|
|
781
|
+
// don't opt in.
|
|
782
|
+
|
|
783
|
+
// apra-fleet-eft.38 (reopened): fallback lookup for GET /activities/:id/output
|
|
784
|
+
// (see the route below) when command-output-cap.mjs's own store has nothing
|
|
785
|
+
// for the id -- true for every activity type it never caps (most notably
|
|
786
|
+
// `agent`: its full LLM response text is never trimmed at storage time, only
|
|
787
|
+
// at GET /state's wire-shaping stage by lean-state.mjs's summarizeHeavyFields(),
|
|
788
|
+
// which now stamps the same <field>Truncated markers on it -- see that
|
|
789
|
+
// module). Reads from the LIVE, full-fidelity in-memory `state.tree` (never
|
|
790
|
+
// the leaned /state payload), which is where an uncapped activity's complete
|
|
791
|
+
// output/error text still lives.
|
|
792
|
+
function findActivityById(state, id) {
|
|
793
|
+
for (const g of state.tree || []) {
|
|
794
|
+
for (const p of g.phases || []) {
|
|
795
|
+
const ev = (p.events || []).find((e) => e.type === 'activity' && String(e.id) === String(id));
|
|
796
|
+
if (ev) return ev.data;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// apra-fleet-eft.6.5: exported so the supervisor's process-free History view
|
|
803
|
+
// (packages/apra-fleet-se/src/supervisor/history-view.mjs) can render a
|
|
804
|
+
// finished run's persisted terminal state through the SAME template the
|
|
805
|
+
// live viewer serves, fed a frozen state object (opts.history / opts.state)
|
|
806
|
+
// instead of standing up a whole createDashboardViewer() (which owns a live
|
|
807
|
+
// http.createServer + workflow event wiring this read-only view has no use
|
|
808
|
+
// for).
|
|
809
|
+
export { HTML_TEMPLATE };
|
|
810
|
+
|
|
811
|
+
export function createDashboardViewer(workflow, opts = {}) {
|
|
812
|
+
const port = (typeof opts.port === 'number') ? opts.port : 8080;
|
|
813
|
+
const dashboardExtensions = opts.dashboardExtensions || [];
|
|
814
|
+
|
|
815
|
+
// apra-fleet-eft.2.3 (renamed under eft.37.1): stable per-run id, NOT an
|
|
816
|
+
// HHMMSS-style clock key (see run-state-paths.mjs) -- this is what
|
|
817
|
+
// running/<id>.json / old_runs/<id>.json are keyed by, so two runs started
|
|
818
|
+
// in the same second on different days never collide. Callers that already
|
|
819
|
+
// know a meaningful id (e.g. the auto-sprint runner's own runId) can pass
|
|
820
|
+
// opts.runId; otherwise one is generated here.
|
|
821
|
+
const env = opts.env || process.env;
|
|
822
|
+
// BOUNDARY-COMPAT: opts.sprintId is the pre-rename alias for opts.runId.
|
|
823
|
+
// Accept it for one release with a deprecation warning so callers migrate
|
|
824
|
+
// to opts.runId without a flag day; sprintId appears in core code only on
|
|
825
|
+
// this line. Remove this shim one release after the se consumers pass
|
|
826
|
+
// opts.runId directly.
|
|
827
|
+
const legacyRunId = opts.sprintId;
|
|
828
|
+
if (legacyRunId !== undefined && opts.runId === undefined) {
|
|
829
|
+
console.warn('[Viewer] opts.sprintId is deprecated; pass opts.runId instead.');
|
|
830
|
+
}
|
|
831
|
+
const runId = opts.runId || legacyRunId || randomUUID();
|
|
832
|
+
|
|
833
|
+
// apra-fleet-eft.2.3: the debounced writer's target defaults to
|
|
834
|
+
// <serviceDataDir>/running/<runId>.json (outside the repo checkout --
|
|
835
|
+
// see getFleetDataDir()/APRA_FLEET_DATA_DIR), NOT the snapshot dir. Only
|
|
836
|
+
// when a caller passes an explicit opts.debouncedStatePath (tests, or a
|
|
837
|
+
// future caller with its own layout) do we skip the running/-> old_runs/
|
|
838
|
+
// move-on-completion below, since we can no longer assume that path lives
|
|
839
|
+
// under a running/ directory we're allowed to rename out of.
|
|
840
|
+
const usingDefaultStatePath = !opts.debouncedStatePath;
|
|
841
|
+
const runningStatePath = opts.debouncedStatePath || getRunningRunStatePath(runId, env);
|
|
842
|
+
|
|
843
|
+
const nowIso = () => new Date().toISOString();
|
|
844
|
+
const startedAtIso = nowIso();
|
|
845
|
+
|
|
846
|
+
const state = {
|
|
847
|
+
workflowName: opts.name || 'Apra Fleet Workflow',
|
|
848
|
+
status: 'running',
|
|
849
|
+
// apra-fleet-eft.2.2: fields enriching the persisted state file
|
|
850
|
+
// beyond the terminal-only crash-net snapshot -- populated (where
|
|
851
|
+
// known) from construction, and updated as the run progresses so
|
|
852
|
+
// a mid-run read of the file shows in-progress state, not just
|
|
853
|
+
// the terminal shape.
|
|
854
|
+
runId,
|
|
855
|
+
args: opts.launchArgs ?? null,
|
|
856
|
+
// apra-fleet-eft.37.3: `result` is the workflow script's own return
|
|
857
|
+
// value, stored WHOLESALE and OPAQUELY -- core never inspects or
|
|
858
|
+
// mints individual keys inside it (that used to be `verdict`/`prUrl`,
|
|
859
|
+
// auto-sprint domain concepts that have no business in the generic
|
|
860
|
+
// engine). Null until the run ends; see the 'end' handler below and
|
|
861
|
+
// the generic Result-strip renderer in HTML_TEMPLATE's client script.
|
|
862
|
+
result: null,
|
|
863
|
+
terminalReason: null,
|
|
864
|
+
startedAt: startedAtIso,
|
|
865
|
+
updatedAt: startedAtIso,
|
|
866
|
+
endedAt: null,
|
|
867
|
+
stats: {
|
|
868
|
+
activitiesCount: 0,
|
|
869
|
+
totalTokens: 0,
|
|
870
|
+
totalCost: 0,
|
|
871
|
+
// apra-fleet-unw.4: count of completed activities whose usage/
|
|
872
|
+
// cost could not be determined (fleet result lacked usage, or
|
|
873
|
+
// calculateCost() couldn't price the model). These are excluded
|
|
874
|
+
// from totalCost/totalTokens rather than fabricated.
|
|
875
|
+
unknownCostCount: 0,
|
|
876
|
+
startTime: Date.now(),
|
|
877
|
+
durationMs: 0
|
|
878
|
+
},
|
|
879
|
+
tree: [],
|
|
880
|
+
extensions: {}
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
// Note: group/phase tracking is single-run by design (single-tenant usage).
|
|
884
|
+
let currentGroup = { title: 'Workflow', phases: [] };
|
|
885
|
+
// apra-fleet-eft.53.1: every phase entry is stamped with phaseStartedAt on
|
|
886
|
+
// entry and phaseEndedAt (initially null) on exit, so the dashboard can
|
|
887
|
+
// render a live elapsed-time tick for the in-progress phase and a frozen
|
|
888
|
+
// duration for exited ones (apra-fleet-eft.53.2). Both fields live
|
|
889
|
+
// directly on the plain phase object pushed into state.tree, so they are
|
|
890
|
+
// written to disk unchanged by the existing debounced/terminal
|
|
891
|
+
// persistence paths (debounced-writer.mjs / persistState() below) and
|
|
892
|
+
// survive a reload/History-view replay for free -- no separate
|
|
893
|
+
// persistence wiring needed.
|
|
894
|
+
let currentPhase = { title: 'Initialization', phaseStartedAt: startedAtIso, phaseEndedAt: null, events: [] };
|
|
895
|
+
currentGroup.phases.push(currentPhase);
|
|
896
|
+
state.tree.push(currentGroup);
|
|
897
|
+
|
|
898
|
+
const clients = new Set();
|
|
899
|
+
const broadcast = (data) => {
|
|
900
|
+
const msg = `data: ${JSON.stringify(data)}\n\n`;
|
|
901
|
+
clients.forEach(c => c.write(msg));
|
|
902
|
+
// apra-fleet-eft.2.2: every event that already drives the SSE
|
|
903
|
+
// broadcast (group:start, phase, activity:start/end, log, state)
|
|
904
|
+
// also schedules a debounced state write and bumps updatedAt, so a
|
|
905
|
+
// mid-run read of the persisted file reflects in-progress state
|
|
906
|
+
// rather than only the terminal snapshot.
|
|
907
|
+
state.updatedAt = nowIso();
|
|
908
|
+
debouncedWriter.schedule();
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
// apra-fleet-eft.2.1/2.3: debounced writer, additive to persistState()
|
|
912
|
+
// above -- that write-once-on-end path (the terminal snapshot dir's
|
|
913
|
+
// run_<HHMMSS>.json) stays exactly as-is as the child crash-safety net.
|
|
914
|
+
// This one coalesces bursts of rapid state changes into a single write
|
|
915
|
+
// per debounce window (default DEFAULT_DEBOUNCE_MS, configurable via
|
|
916
|
+
// opts.debounceMs, must be within 200-500ms), is flushed synchronously
|
|
917
|
+
// on every exit path below, and (apra-fleet-eft.2.3) targets
|
|
918
|
+
// running/<runId>.json under the service data directory by default --
|
|
919
|
+
// never the repo checkout.
|
|
920
|
+
const debouncedWriter = new DebouncedStateWriter({
|
|
921
|
+
getState: () => state,
|
|
922
|
+
filePath: runningStatePath,
|
|
923
|
+
debounceMs: opts.debounceMs || DEFAULT_DEBOUNCE_MS
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
// apra-fleet-eft.27.4: configurable head/tail cap applied to a `command`
|
|
927
|
+
// activity's captured output/error BEFORE it's ever stored into
|
|
928
|
+
// state.tree (command-output-cap.mjs) -- undefined fields fall back to
|
|
929
|
+
// that module's own defaults.
|
|
930
|
+
const commandOutputCapOpts = {
|
|
931
|
+
headChars: opts.commandOutputHeadChars,
|
|
932
|
+
tailChars: opts.commandOutputTailChars
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
// apra-fleet-eft.2.3: on terminal completion, move (not copy) the live
|
|
936
|
+
// running/<runId>.json to old_runs/<runId>.json so "is this run live" is a
|
|
937
|
+
// directory-membership check, never a stale field on the state object
|
|
938
|
+
// itself. Only applies to the default path layout -- see
|
|
939
|
+
// usingDefaultStatePath above.
|
|
940
|
+
function moveStateToOldRuns() {
|
|
941
|
+
if (!usingDefaultStatePath) return;
|
|
942
|
+
try {
|
|
943
|
+
if (!fs.existsSync(runningStatePath)) return;
|
|
944
|
+
const oldPath = getTerminalRunStatePath(runId, env);
|
|
945
|
+
fs.mkdirSync(path.dirname(oldPath), { recursive: true });
|
|
946
|
+
fs.renameSync(runningStatePath, oldPath);
|
|
947
|
+
} catch (e) {
|
|
948
|
+
// Must never crash or block the run's own normal exit behavior --
|
|
949
|
+
// log and move on, same contract as persistState() and the
|
|
950
|
+
// debounced writer itself.
|
|
951
|
+
console.warn(`[Viewer] Warning: failed to move run state to old_runs/: ${e.message}`);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// Server-side persistence of the dashboard `state` object to
|
|
956
|
+
// <stateSnapshotDir>/<stateSnapshotPrefix><HHMMSS>.json on every
|
|
957
|
+
// run-ending event (normal finish, cooperative /stop-triggered
|
|
958
|
+
// cancellation, or the CLI process itself being interrupted). This is the
|
|
959
|
+
// server-side equivalent of the client-side saveState() button
|
|
960
|
+
// (HTML_TEMPLATE above) -- that one only works if a human has the
|
|
961
|
+
// dashboard open in a browser; this one runs unconditionally so a run's
|
|
962
|
+
// final state is never lost just because nobody was watching. `saved`
|
|
963
|
+
// guards against writing twice for the same run (e.g. 'end' fires, then a
|
|
964
|
+
// SIGINT arrives moments later during the bin/cli.mjs failure grace-period
|
|
965
|
+
// wait).
|
|
966
|
+
//
|
|
967
|
+
// apra-fleet-eft.37.1: the crash-net snapshot location is configurable so
|
|
968
|
+
// core stays domain-neutral -- opts.stateSnapshotDir (default
|
|
969
|
+
// `workflow-logs`, resolved under process.cwd() when relative) and
|
|
970
|
+
// opts.stateSnapshotPrefix (default `run_`, giving `run_<HHMMSS>.json`).
|
|
971
|
+
// auto-sprint passes `sprint-logs`/`sprint_` explicitly so its user-facing
|
|
972
|
+
// convention is unchanged.
|
|
973
|
+
const stateSnapshotDir = opts.stateSnapshotDir || 'workflow-logs';
|
|
974
|
+
const stateSnapshotPrefix = opts.stateSnapshotPrefix || 'run_';
|
|
975
|
+
let saved = false;
|
|
976
|
+
function persistState() {
|
|
977
|
+
if (saved) return;
|
|
978
|
+
saved = true;
|
|
979
|
+
try {
|
|
980
|
+
const dir = path.isAbsolute(stateSnapshotDir)
|
|
981
|
+
? stateSnapshotDir
|
|
982
|
+
: path.join(process.cwd(), stateSnapshotDir);
|
|
983
|
+
const now = new Date();
|
|
984
|
+
const pad2 = (n) => String(n).padStart(2, '0');
|
|
985
|
+
const hhmmss = `${pad2(now.getHours())}${pad2(now.getMinutes())}${pad2(now.getSeconds())}`;
|
|
986
|
+
const filePath = path.join(dir, `${stateSnapshotPrefix}${hhmmss}.json`);
|
|
987
|
+
// apra-fleet-eft.20.1: route through the same single-pass
|
|
988
|
+
// JSON.stringify + atomic temp-file-then-rename primitive the
|
|
989
|
+
// debounced writer uses (writeJsonFileAtomic, debounced-writer.mjs)
|
|
990
|
+
// instead of a direct writeFileSync, so this terminal snapshot can
|
|
991
|
+
// never be observed half-written and its bytes always round-trip
|
|
992
|
+
// through JSON.parse().
|
|
993
|
+
writeJsonFileAtomic(filePath, state);
|
|
994
|
+
console.log(`[Viewer] Run state saved to ${filePath}`);
|
|
995
|
+
} catch (e) {
|
|
996
|
+
// A failed save must never crash or block the run's own normal
|
|
997
|
+
// exit behavior -- log and move on.
|
|
998
|
+
console.warn(`[Viewer] Warning: failed to save run state: ${e.message}`);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// Covers reason 3 (CLI process interrupted): SIGINT/SIGTERM had NO
|
|
1003
|
+
// handler at all today for a still-running or successfully-finished
|
|
1004
|
+
// run (bin/cli.mjs only registers a SIGINT handler inside its
|
|
1005
|
+
// failure-grace-window Promise). Registering a listener here removes
|
|
1006
|
+
// Node's default immediate-exit behavior for the signal, so the handler
|
|
1007
|
+
// must explicitly call process.exit() itself after the best-effort save
|
|
1008
|
+
// to preserve that same "the process ultimately terminates" contract --
|
|
1009
|
+
// it does not swallow the signal or turn it into a no-op.
|
|
1010
|
+
// NOTE: signal listeners registered via process.on('SIGINT'/'SIGTERM', fn)
|
|
1011
|
+
// do NOT receive the signal name as an argument (unlike a manually
|
|
1012
|
+
// dispatched process.emit(name, ...args)), so a single shared handler
|
|
1013
|
+
// can't tell them apart -- hence two small wrappers instead of one
|
|
1014
|
+
// handler branching on an argument that would never actually arrive.
|
|
1015
|
+
const handleSigint = () => {
|
|
1016
|
+
// apra-fleet-eft.53.1: same close-out as the normal 'end' path -- a
|
|
1017
|
+
// SIGINT-interrupted run must not leave its final phase's
|
|
1018
|
+
// phaseEndedAt dangling null in the persisted snapshot.
|
|
1019
|
+
if (currentPhase && currentPhase.phaseEndedAt == null) {
|
|
1020
|
+
currentPhase.phaseEndedAt = nowIso();
|
|
1021
|
+
}
|
|
1022
|
+
state.endedAt = nowIso();
|
|
1023
|
+
state.terminalReason = state.terminalReason || 'SIGINT';
|
|
1024
|
+
persistState();
|
|
1025
|
+
// apra-fleet-eft.2.1: flush any coalesced-but-not-yet-written
|
|
1026
|
+
// debounced state synchronously before the process actually exits,
|
|
1027
|
+
// so at most one debounce window of progress is ever lost.
|
|
1028
|
+
debouncedWriter.flushSync();
|
|
1029
|
+
// apra-fleet-eft.2.3: SIGINT/SIGTERM are a graceful (not hard-kill)
|
|
1030
|
+
// shutdown path, so the file is still moved to old_runs/ here --
|
|
1031
|
+
// it's only an unhandled SIGKILL/OOM that leaves it behind in
|
|
1032
|
+
// running/ (that gap is what apra-fleet-eft.2.4's hard-kill test
|
|
1033
|
+
// covers).
|
|
1034
|
+
moveStateToOldRuns();
|
|
1035
|
+
process.exit(130);
|
|
1036
|
+
};
|
|
1037
|
+
const handleSigterm = () => {
|
|
1038
|
+
// apra-fleet-eft.53.1: see handleSigint's identical stamp above.
|
|
1039
|
+
if (currentPhase && currentPhase.phaseEndedAt == null) {
|
|
1040
|
+
currentPhase.phaseEndedAt = nowIso();
|
|
1041
|
+
}
|
|
1042
|
+
state.endedAt = nowIso();
|
|
1043
|
+
state.terminalReason = state.terminalReason || 'SIGTERM';
|
|
1044
|
+
persistState();
|
|
1045
|
+
debouncedWriter.flushSync();
|
|
1046
|
+
moveStateToOldRuns();
|
|
1047
|
+
process.exit(143);
|
|
1048
|
+
};
|
|
1049
|
+
process.on('SIGINT', handleSigint);
|
|
1050
|
+
process.on('SIGTERM', handleSigterm);
|
|
1051
|
+
|
|
1052
|
+
workflow.on('group:start', (data) => {
|
|
1053
|
+
currentGroup = { title: data.title, phases: [] };
|
|
1054
|
+
state.tree.push(currentGroup);
|
|
1055
|
+
broadcast({ type: 'update' });
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
workflow.on('phase', (title) => {
|
|
1059
|
+
// apra-fleet-eft.53.1: stamp phaseEndedAt on the phase being exited
|
|
1060
|
+
// (guarded so an already-ended phase -- e.g. one closed by the 'end'
|
|
1061
|
+
// handler below -- is never overwritten) before starting the new one.
|
|
1062
|
+
if (currentPhase && currentPhase.phaseEndedAt == null) {
|
|
1063
|
+
currentPhase.phaseEndedAt = nowIso();
|
|
1064
|
+
}
|
|
1065
|
+
currentPhase = { title, phaseStartedAt: nowIso(), phaseEndedAt: null, events: [] };
|
|
1066
|
+
if (!currentGroup) {
|
|
1067
|
+
currentGroup = { title: 'Workflow', phases: [] };
|
|
1068
|
+
state.tree.push(currentGroup);
|
|
1069
|
+
}
|
|
1070
|
+
currentGroup.phases.push(currentPhase);
|
|
1071
|
+
broadcast({ type: 'update' });
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
workflow.on('activity:start', (meta) => {
|
|
1075
|
+
state.stats.activitiesCount++;
|
|
1076
|
+
currentPhase.events.push({ type: 'activity', id: meta.id, data: { ...meta, isRunning: true } });
|
|
1077
|
+
broadcast({ type: 'update' });
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
workflow.on('activity:end', (meta) => {
|
|
1081
|
+
// apra-fleet-eft.27.4: cap a `command` activity's output/error to a
|
|
1082
|
+
// head+tail excerpt + byte count BEFORE it lands in state.tree --
|
|
1083
|
+
// this is the object persisted (debounced running/<runId>.json,
|
|
1084
|
+
// terminal snapshot) and read by GET /state's
|
|
1085
|
+
// buildListStatePayload() transform, so an uncapped multi-MB command
|
|
1086
|
+
// dump written here bloats all three regardless of that transform.
|
|
1087
|
+
// Returns the SAME `meta` reference unchanged when there's nothing
|
|
1088
|
+
// to cap (non-command activities, or output already under the cap),
|
|
1089
|
+
// and never mutates the original `meta` object -- other
|
|
1090
|
+
// `activity:end` listeners (e.g. journal.mjs's replay cache) still
|
|
1091
|
+
// need the complete, uncapped text.
|
|
1092
|
+
const storedMeta = capCommandActivityMeta(meta, commandOutputCapOpts);
|
|
1093
|
+
for (const g of state.tree) {
|
|
1094
|
+
for (const p of g.phases) {
|
|
1095
|
+
const ev = p.events.find(e => e.type === 'activity' && e.id === meta.id);
|
|
1096
|
+
if (ev) {
|
|
1097
|
+
ev.data = { ...ev.data, ...storedMeta, isRunning: false };
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
if (meta.usage?.total_tokens) state.stats.totalTokens += meta.usage.total_tokens;
|
|
1102
|
+
// apra-fleet-unw.4: `cost` is only added to the running total when
|
|
1103
|
+
// it's a known number. When agent() explicitly reported cost: null
|
|
1104
|
+
// (fleet result had no usage, or the model wasn't in the pricing
|
|
1105
|
+
// table), tally it separately instead of fabricating a total.
|
|
1106
|
+
if (typeof meta.cost === 'number') {
|
|
1107
|
+
state.stats.totalCost += meta.cost;
|
|
1108
|
+
} else if (meta.type === 'agent' && Object.prototype.hasOwnProperty.call(meta, 'cost') && meta.cost === null) {
|
|
1109
|
+
state.stats.unknownCostCount++;
|
|
1110
|
+
}
|
|
1111
|
+
broadcast({ type: 'update' });
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
workflow.on('log', (entry) => {
|
|
1115
|
+
currentPhase.events.push({ type: 'log', time: entry.time || Date.now(), msg: entry.msg });
|
|
1116
|
+
broadcast({ type: 'update' });
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
workflow.on('state', (stateData) => {
|
|
1120
|
+
state.extensions[stateData.namespace] = stateData.data;
|
|
1121
|
+
broadcast({ type: 'state', payload: stateData });
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
workflow.on('end', (res) => {
|
|
1125
|
+
// apra-fleet-eft.53.1: the run's final phase never gets a 'phase'
|
|
1126
|
+
// event to close it out -- stamp its phaseEndedAt here so no phase
|
|
1127
|
+
// entry is left with a dangling null once the run has actually
|
|
1128
|
+
// ended.
|
|
1129
|
+
if (currentPhase && currentPhase.phaseEndedAt == null) {
|
|
1130
|
+
currentPhase.phaseEndedAt = nowIso();
|
|
1131
|
+
}
|
|
1132
|
+
state.status = res.status;
|
|
1133
|
+
state.stats.durationMs = Date.now() - state.stats.startTime;
|
|
1134
|
+
// apra-fleet-eft.2.2/eft.37.3: enrich the terminal state with
|
|
1135
|
+
// whatever the workflow script's own return value surfaced --
|
|
1136
|
+
// stored WHOLESALE and opaquely as `state.result` (core never reads
|
|
1137
|
+
// or names individual keys inside it; a non-se workflow may return
|
|
1138
|
+
// anything JSON-shaped here, or nothing at all).
|
|
1139
|
+
state.result = (res.result !== undefined) ? res.result : state.result;
|
|
1140
|
+
state.endedAt = nowIso();
|
|
1141
|
+
state.terminalReason = res.error
|
|
1142
|
+
? (res.error.message || res.error.name || res.status)
|
|
1143
|
+
: res.status;
|
|
1144
|
+
broadcast({ type: 'update' });
|
|
1145
|
+
persistState();
|
|
1146
|
+
// apra-fleet-eft.2.1: synchronous flush-on-exit -- a run ending is
|
|
1147
|
+
// one of the process-exit-adjacent paths this writer must never
|
|
1148
|
+
// lose more than one debounce window against.
|
|
1149
|
+
debouncedWriter.flushSync();
|
|
1150
|
+
// apra-fleet-eft.2.3: terminal completion -- move running/<id>.json
|
|
1151
|
+
// to old_runs/<id>.json (directory membership, not a stale field,
|
|
1152
|
+
// is what makes "is this run live" authoritative).
|
|
1153
|
+
moveStateToOldRuns();
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
const server = http.createServer((req, res) => {
|
|
1157
|
+
if (req.url === '/') {
|
|
1158
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
1159
|
+
res.end(HTML_TEMPLATE(dashboardExtensions));
|
|
1160
|
+
} else if (req.url === '/events') {
|
|
1161
|
+
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache' });
|
|
1162
|
+
clients.add(res);
|
|
1163
|
+
req.on('close', () => clients.delete(res));
|
|
1164
|
+
} else if (req.url.startsWith('/state')) {
|
|
1165
|
+
// apra-fleet-eft.27.1: GET /state is the RECURRING poll endpoint
|
|
1166
|
+
// (every ~250ms-400ms while a run is live) -- it must never
|
|
1167
|
+
// serve the full in-memory `state` object as-is. That object
|
|
1168
|
+
// accumulates one entry per activity for the run's entire
|
|
1169
|
+
// history, and each entry can embed multi-KB command/agent
|
|
1170
|
+
// output; on a real 449-activity sprint this endpoint measured a
|
|
1171
|
+
// 116 MB payload per poll (apra-fleet-eft.27). buildListStatePayload()
|
|
1172
|
+
// (src/viewer/lean-state.mjs) strips descriptions/transcripts
|
|
1173
|
+
// down to short summaries and dedupes any remaining repeated
|
|
1174
|
+
// strings -- `state` itself (the source of truth persisted to
|
|
1175
|
+
// the configured snapshot dir and running/<runId>.json, and what
|
|
1176
|
+
// the process-free History view embeds) is never mutated by this.
|
|
1177
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate' });
|
|
1178
|
+
res.end(JSON.stringify(buildListStatePayload(state)));
|
|
1179
|
+
} else if (req.method === 'GET' && /^\/extensions\/[^/]+\/detail\/[^/]+$/.test(req.url)) {
|
|
1180
|
+
// apra-fleet-eft.37.4 (M3): the GENERIC on-demand-detail route.
|
|
1181
|
+
// Any dashboard extension may register a `detailLookup(state, id)`
|
|
1182
|
+
// hook; this is the only route that calls it, and it is
|
|
1183
|
+
// extension-agnostic -- core never names a specific extension or
|
|
1184
|
+
// reaches into its data shape. Fetched only when a user expands
|
|
1185
|
+
// an on-demand row in SOME extension's UI (e.g. the beads
|
|
1186
|
+
// extension's "more..." control, apra-fleet-eft.27) -- never
|
|
1187
|
+
// during normal polling -- against the LIVE, full-fidelity
|
|
1188
|
+
// `state` object (never the leaned /state projection).
|
|
1189
|
+
const match = req.url.match(/^\/extensions\/([^/]+)\/detail\/([^/]+)$/);
|
|
1190
|
+
const extId = decodeURIComponent(match[1]);
|
|
1191
|
+
const itemId = decodeURIComponent(match[2]);
|
|
1192
|
+
const ext = dashboardExtensions.find((e) => e.id === extId);
|
|
1193
|
+
const detail = (ext && typeof ext.detailLookup === 'function')
|
|
1194
|
+
? ext.detailLookup(state, itemId)
|
|
1195
|
+
: null;
|
|
1196
|
+
if (!detail) {
|
|
1197
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
1198
|
+
res.end(JSON.stringify({ error: 'detail not found', id: itemId }));
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
1202
|
+
res.end(JSON.stringify({
|
|
1203
|
+
id: itemId,
|
|
1204
|
+
text: detail.text || '',
|
|
1205
|
+
updatedAt: detail.updatedAt ?? null
|
|
1206
|
+
}));
|
|
1207
|
+
} else if (req.method === 'GET' && /^\/beads\/[^/]+\/description$/.test(req.url)) {
|
|
1208
|
+
// BOUNDARY-COMPAT (apra-fleet-eft.37.4, one release only, then
|
|
1209
|
+
// dies per docs/workflow-core-boundary-refactoring.md M3): the
|
|
1210
|
+
// pre-M3 route name. The extension js that used to call it
|
|
1211
|
+
// (packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs) has
|
|
1212
|
+
// already moved to the generic route above; this alias exists
|
|
1213
|
+
// only for anything still pointed at the old URL (e.g. a stale
|
|
1214
|
+
// cached client). A dumb redirect, not a second implementation --
|
|
1215
|
+
// it never touches `state` itself.
|
|
1216
|
+
const id = req.url.slice('/beads/'.length, req.url.length - '/description'.length);
|
|
1217
|
+
res.writeHead(302, { Location: '/extensions/beads/detail/' + id });
|
|
1218
|
+
res.end();
|
|
1219
|
+
} else if (req.method === 'GET' && /^\/activities\/[^/]+\/output$/.test(req.url)) {
|
|
1220
|
+
// apra-fleet-eft.27.4 / apra-fleet-eft.38 (reopened): on-demand
|
|
1221
|
+
// full-output endpoint. First checks command-output-cap.mjs's
|
|
1222
|
+
// dedicated store (a `command` activity whose stdout/error was
|
|
1223
|
+
// capped to a head+tail excerpt before being stored in state.tree
|
|
1224
|
+
// -- see the activity:end handler above). Every OTHER activity
|
|
1225
|
+
// type that GET /state's lean-state.mjs may have marked
|
|
1226
|
+
// <field>Truncated (most notably `agent`: its full LLM response
|
|
1227
|
+
// text is never capped at storage time, so it's never in that
|
|
1228
|
+
// store) falls back to the LIVE, full-fidelity in-memory
|
|
1229
|
+
// state.tree instead, via findActivityById() -- that object still
|
|
1230
|
+
// holds the complete, uncapped text for anything not routed
|
|
1231
|
+
// through command-output-cap.mjs. Fetched only when a user
|
|
1232
|
+
// expands a truncated activity in the dashboard -- never during
|
|
1233
|
+
// normal polling. 404s (not a crash) for an unknown id, or one
|
|
1234
|
+
// with nothing to fetch beyond what's already inline.
|
|
1235
|
+
const id = decodeURIComponent(req.url.slice('/activities/'.length, req.url.length - '/output'.length));
|
|
1236
|
+
let full = getFullOutput(id);
|
|
1237
|
+
if (!full) {
|
|
1238
|
+
const act = findActivityById(state, id);
|
|
1239
|
+
if (act) {
|
|
1240
|
+
const fromState = {};
|
|
1241
|
+
if (typeof act.output === 'string') fromState.output = act.output;
|
|
1242
|
+
if (typeof act.error === 'string') fromState.error = act.error;
|
|
1243
|
+
if (Object.keys(fromState).length > 0) full = fromState;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
if (!full) {
|
|
1247
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
1248
|
+
res.end(JSON.stringify({ error: 'activity output not found', id }));
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
1252
|
+
res.end(JSON.stringify({ id, ...full }));
|
|
1253
|
+
} else if (req.url === '/stop' && req.method === 'POST') {
|
|
1254
|
+
// (apra-fleet-unw.10) Cooperative stop -- no process.exit(). The
|
|
1255
|
+
// old handler killed the whole Node process immediately, with no
|
|
1256
|
+
// state flush and any mid-dispatch agent() /command() call left
|
|
1257
|
+
// orphaned (its promise simply never settles because the process
|
|
1258
|
+
// is gone). Instead, ask the workflow to cancel itself: this
|
|
1259
|
+
// aborts the active run's AbortController (FleetWorkflow
|
|
1260
|
+
// .requestStop(), src/workflow/index.mjs), which rejects every
|
|
1261
|
+
// in-flight and future agent()/command() dispatch for that run
|
|
1262
|
+
// via the apra-fleet-unw.5 client-side signal plumbing with a
|
|
1263
|
+
// typed CancelledError. The run then unwinds normally and
|
|
1264
|
+
// WorkflowEngine.executeFile() emits 'end' with status
|
|
1265
|
+
// 'cancelled' from its own finally block, same as any other
|
|
1266
|
+
// failure path -- the viewer transitions to CANCELLED/FAILED and
|
|
1267
|
+
// closes after the usual grace period, and the Node process
|
|
1268
|
+
// stays alive throughout.
|
|
1269
|
+
//
|
|
1270
|
+
// NOTE: this is local/client-side cancellation only. A remote
|
|
1271
|
+
// fleet member that already accepted a job may keep running to
|
|
1272
|
+
// completion even after this run unwinds as cancelled --
|
|
1273
|
+
// true server-side cancellation would require changes to the
|
|
1274
|
+
// external apra-fleet MCP server (apra-fleet.exe) and is out of
|
|
1275
|
+
// scope here.
|
|
1276
|
+
console.log('[Viewer] Stop signal received -- requesting cooperative cancellation.');
|
|
1277
|
+
if (typeof workflow.requestStop === 'function') {
|
|
1278
|
+
workflow.requestStop('Stop requested via dashboard /stop endpoint');
|
|
1279
|
+
}
|
|
1280
|
+
// apra-fleet-eft.2.1: /stop is one of the required flush-on-exit
|
|
1281
|
+
// paths -- the workflow itself unwinds asynchronously afterward
|
|
1282
|
+
// (and its own 'end' handler above will flush again once it
|
|
1283
|
+
// fires), but flush eagerly here too so the debounced state
|
|
1284
|
+
// file reflects the stop request itself without waiting on that
|
|
1285
|
+
// unwind.
|
|
1286
|
+
debouncedWriter.flushSync();
|
|
1287
|
+
res.writeHead(200);
|
|
1288
|
+
res.end();
|
|
1289
|
+
} else if (req.url === '/save_logs' && req.method === 'POST') {
|
|
1290
|
+
// Manual/scriptable trigger for the same server-side save that
|
|
1291
|
+
// 'end' and SIGINT/SIGTERM already perform (persistState() above)
|
|
1292
|
+
// -- e.g. a future dashboard button, curl, or another tool. Shares
|
|
1293
|
+
// the same idempotency guard (`saved`), so this is a no-op if the
|
|
1294
|
+
// run has already been persisted (by 'end', a signal, or a prior
|
|
1295
|
+
// call to this endpoint).
|
|
1296
|
+
console.log('[Viewer] /save_logs requested -- persisting current dashboard state.');
|
|
1297
|
+
persistState();
|
|
1298
|
+
res.writeHead(200);
|
|
1299
|
+
res.end();
|
|
1300
|
+
} else {
|
|
1301
|
+
res.writeHead(404);
|
|
1302
|
+
res.end();
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
server.listen(port, () => {
|
|
1307
|
+
console.log(`[Viewer] Workflow Dashboard live at http://localhost:${server.address().port}`);
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
workflow.on('end', () => {
|
|
1311
|
+
setTimeout(() => {
|
|
1312
|
+
try { server.close(); } catch(e) {}
|
|
1313
|
+
}, 5000);
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
// Avoid leaking process-level signal listeners: each createDashboardViewer()
|
|
1317
|
+
// call (one per test, one per real workflow run) adds its own SIGINT/SIGTERM
|
|
1318
|
+
// handler above; remove it once this viewer's server is done.
|
|
1319
|
+
server.on('close', () => {
|
|
1320
|
+
process.removeListener('SIGINT', handleSigint);
|
|
1321
|
+
process.removeListener('SIGTERM', handleSigterm);
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
return server;
|
|
1325
|
+
}
|