@cotal-ai/cli 0.100.1 → 0.101.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/dist/chat/chat-view.d.ts.map +1 -1
- package/dist/chat/chat-view.js +5 -1
- package/dist/chat/chat-view.js.map +1 -1
- package/dist/chat/engine.d.ts +2 -1
- package/dist/chat/engine.d.ts.map +1 -1
- package/dist/chat/engine.js +2 -1
- package/dist/chat/engine.js.map +1 -1
- package/dist/chat/frontend.d.ts.map +1 -1
- package/dist/chat/frontend.js +13 -7
- package/dist/chat/frontend.js.map +1 -1
- package/dist/chat/native-session.d.ts +22 -3
- package/dist/chat/native-session.d.ts.map +1 -1
- package/dist/chat/native-session.js +91 -19
- package/dist/chat/native-session.js.map +1 -1
- package/dist/chat/open-session.d.ts +1 -0
- package/dist/chat/open-session.d.ts.map +1 -1
- package/dist/chat/open-session.js +1 -1
- package/dist/chat/open-session.js.map +1 -1
- package/dist/chat/picker.d.ts +5 -0
- package/dist/chat/picker.d.ts.map +1 -1
- package/dist/chat/picker.js +23 -10
- package/dist/chat/picker.js.map +1 -1
- package/dist/chat/plain.d.ts.map +1 -1
- package/dist/chat/plain.js +36 -10
- package/dist/chat/plain.js.map +1 -1
- package/dist/chat/session.d.ts +5 -0
- package/dist/chat/session.d.ts.map +1 -1
- package/dist/chat/static-session.d.ts +1 -0
- package/dist/chat/static-session.d.ts.map +1 -1
- package/dist/chat/static-session.js +24 -8
- package/dist/chat/static-session.js.map +1 -1
- package/dist/chat/stdio-io.d.ts +2 -0
- package/dist/chat/stdio-io.d.ts.map +1 -1
- package/dist/chat/stdio-io.js +6 -6
- package/dist/chat/stdio-io.js.map +1 -1
- package/dist/chat/stdio.d.ts +3 -2
- package/dist/chat/stdio.d.ts.map +1 -1
- package/dist/chat/stdio.js +26 -25
- package/dist/chat/stdio.js.map +1 -1
- package/dist/chat/user-session.d.ts +1 -0
- package/dist/chat/user-session.d.ts.map +1 -1
- package/dist/chat/user-session.js +1 -1
- package/dist/chat/user-session.js.map +1 -1
- package/dist/chat/view.d.ts +5 -4
- package/dist/chat/view.d.ts.map +1 -1
- package/dist/chat/view.js +10 -8
- package/dist/chat/view.js.map +1 -1
- package/dist/command.d.ts +5 -0
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +295 -82
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts +29 -5
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +100 -35
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/backup-maintenance.d.ts.map +1 -1
- package/dist/commands/backup-maintenance.js +54 -21
- package/dist/commands/backup-maintenance.js.map +1 -1
- package/dist/commands/backup-read.d.ts.map +1 -1
- package/dist/commands/backup-read.js +13 -16
- package/dist/commands/backup-read.js.map +1 -1
- package/dist/commands/backup-restore.d.ts.map +1 -1
- package/dist/commands/backup-restore.js +20 -4
- package/dist/commands/backup-restore.js.map +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +157 -29
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/channel-members.d.ts +1 -1
- package/dist/commands/channel-members.d.ts.map +1 -1
- package/dist/commands/channel-members.js +115 -29
- package/dist/commands/channel-members.js.map +1 -1
- package/dist/commands/channels.d.ts +11 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +109 -20
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/chat.d.ts +11 -3
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +50 -22
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/clean.d.ts +10 -5
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +245 -42
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/completion.d.ts +15 -2
- package/dist/commands/completion.d.ts.map +1 -1
- package/dist/commands/completion.js +91 -26
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/config.d.ts +24 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +91 -15
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/console.d.ts.map +1 -1
- package/dist/commands/console.js +5 -4
- package/dist/commands/console.js.map +1 -1
- package/dist/commands/describe.d.ts +4 -2
- package/dist/commands/describe.d.ts.map +1 -1
- package/dist/commands/describe.js +4 -4
- package/dist/commands/describe.js.map +1 -1
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +261 -34
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down-manifest.d.ts.map +1 -1
- package/dist/commands/down-manifest.js +9 -6
- package/dist/commands/down-manifest.js.map +1 -1
- package/dist/commands/down-services.d.ts +17 -16
- package/dist/commands/down-services.d.ts.map +1 -1
- package/dist/commands/down-services.js +29 -53
- package/dist/commands/down-services.js.map +1 -1
- package/dist/commands/down.d.ts +2 -2
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +96 -67
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/endpoint-deregister.d.ts.map +1 -1
- package/dist/commands/endpoint-deregister.js +2 -2
- package/dist/commands/endpoint-deregister.js.map +1 -1
- package/dist/commands/endpoint.d.ts +2 -1
- package/dist/commands/endpoint.d.ts.map +1 -1
- package/dist/commands/endpoint.js +2 -2
- package/dist/commands/endpoint.js.map +1 -1
- package/dist/commands/endpoints.d.ts +1 -0
- package/dist/commands/endpoints.d.ts.map +1 -1
- package/dist/commands/endpoints.js +20 -5
- package/dist/commands/endpoints.js.map +1 -1
- package/dist/commands/feedback.d.ts.map +1 -1
- package/dist/commands/feedback.js +40 -2
- package/dist/commands/feedback.js.map +1 -1
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +2 -1
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history-clear.d.ts.map +1 -1
- package/dist/commands/history-clear.js +67 -51
- package/dist/commands/history-clear.js.map +1 -1
- package/dist/commands/history.d.ts +17 -2
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +221 -34
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.d.ts +2 -0
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +132 -80
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/meshes-add.d.ts +19 -4
- package/dist/commands/meshes-add.d.ts.map +1 -1
- package/dist/commands/meshes-add.js +114 -15
- package/dist/commands/meshes-add.js.map +1 -1
- package/dist/commands/meshes-wizard.d.ts +1 -0
- package/dist/commands/meshes-wizard.d.ts.map +1 -1
- package/dist/commands/meshes-wizard.js +45 -13
- package/dist/commands/meshes-wizard.js.map +1 -1
- package/dist/commands/meshes.d.ts +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +76 -47
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/mint.d.ts.map +1 -1
- package/dist/commands/mint.js +212 -19
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/models.d.ts +5 -1
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +21 -13
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/persona-remote.d.ts.map +1 -1
- package/dist/commands/persona-remote.js +38 -19
- package/dist/commands/persona-remote.js.map +1 -1
- package/dist/commands/persona.d.ts +1 -1
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +92 -23
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/personas.d.ts.map +1 -1
- package/dist/commands/personas.js +59 -40
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/reset-space-apply.d.ts.map +1 -1
- package/dist/commands/reset-space-apply.js +69 -17
- package/dist/commands/reset-space-apply.js.map +1 -1
- package/dist/commands/reset-store-apply.d.ts +16 -0
- package/dist/commands/reset-store-apply.d.ts.map +1 -1
- package/dist/commands/reset-store-apply.js +122 -23
- package/dist/commands/reset-store-apply.js.map +1 -1
- package/dist/commands/reset.d.ts.map +1 -1
- package/dist/commands/reset.js +8 -7
- package/dist/commands/reset.js.map +1 -1
- package/dist/commands/revoke-credential.d.ts +5 -0
- package/dist/commands/revoke-credential.d.ts.map +1 -0
- package/dist/commands/revoke-credential.js +128 -0
- package/dist/commands/revoke-credential.js.map +1 -0
- package/dist/commands/send.d.ts +11 -3
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +284 -47
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-actions.d.ts +2 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +117 -21
- package/dist/commands/service-actions.js.map +1 -1
- package/dist/commands/service-log-follow.js +1 -1
- package/dist/commands/service-log-follow.js.map +1 -1
- package/dist/commands/service-registry.d.ts +1 -1
- package/dist/commands/service-registry.d.ts.map +1 -1
- package/dist/commands/service-registry.js +74 -30
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/service-set-stop.d.ts.map +1 -1
- package/dist/commands/service-set-stop.js +3 -2
- package/dist/commands/service-set-stop.js.map +1 -1
- package/dist/commands/setup-start.d.ts.map +1 -1
- package/dist/commands/setup-start.js +46 -5
- package/dist/commands/setup-start.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +28 -13
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-delete.d.ts.map +1 -1
- package/dist/commands/space-delete.js +130 -41
- package/dist/commands/space-delete.js.map +1 -1
- package/dist/commands/space-registration.d.ts +13 -6
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +167 -46
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts +15 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +66 -24
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts.map +1 -1
- package/dist/commands/spawn-preview.js +48 -10
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts +36 -13
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +263 -129
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.d.ts +9 -3
- package/dist/commands/stack-down.d.ts.map +1 -1
- package/dist/commands/stack-down.js +344 -64
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-gone.d.ts +17 -0
- package/dist/commands/stack-gone.d.ts.map +1 -0
- package/dist/commands/stack-gone.js +218 -0
- package/dist/commands/stack-gone.js.map +1 -0
- package/dist/commands/stack-up.d.ts +64 -4
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +482 -55
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status.d.ts +76 -2
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +550 -112
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/team-agent-apply.d.ts.map +1 -1
- package/dist/commands/team-agent-apply.js +4 -3
- package/dist/commands/team-agent-apply.js.map +1 -1
- package/dist/commands/team-agent-remove.d.ts.map +1 -1
- package/dist/commands/team-agent-remove.js +4 -4
- package/dist/commands/team-agent-remove.js.map +1 -1
- package/dist/commands/team-boot-controller.d.ts.map +1 -1
- package/dist/commands/team-boot-controller.js +8 -2
- package/dist/commands/team-boot-controller.js.map +1 -1
- package/dist/commands/team-channel-remove.d.ts.map +1 -1
- package/dist/commands/team-channel-remove.js +26 -10
- package/dist/commands/team-channel-remove.js.map +1 -1
- package/dist/commands/team-deploy-apply.d.ts.map +1 -1
- package/dist/commands/team-deploy-apply.js +4 -3
- package/dist/commands/team-deploy-apply.js.map +1 -1
- package/dist/commands/team-mixed-remove.js +5 -5
- package/dist/commands/team-mixed-remove.js.map +1 -1
- package/dist/commands/team.d.ts.map +1 -1
- package/dist/commands/team.js +94 -32
- package/dist/commands/team.js.map +1 -1
- package/dist/commands/telemetry.d.ts +1 -1
- package/dist/commands/telemetry.d.ts.map +1 -1
- package/dist/commands/telemetry.js +5 -3
- package/dist/commands/telemetry.js.map +1 -1
- package/dist/commands/topology.d.ts.map +1 -1
- package/dist/commands/topology.js +11 -7
- package/dist/commands/topology.js.map +1 -1
- package/dist/commands/up.d.ts +6 -6
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +963 -240
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +9 -3
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/use.d.ts +5 -1
- package/dist/commands/use.d.ts.map +1 -1
- package/dist/commands/use.js +55 -12
- package/dist/commands/use.js.map +1 -1
- package/dist/commands/watch.d.ts +4 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +15 -3
- package/dist/commands/watch.js.map +1 -1
- package/dist/commands/who.d.ts +2 -0
- package/dist/commands/who.d.ts.map +1 -1
- package/dist/commands/who.js +18 -5
- package/dist/commands/who.js.map +1 -1
- package/dist/commands/whoami.d.ts +44 -5
- package/dist/commands/whoami.d.ts.map +1 -1
- package/dist/commands/whoami.js +168 -16
- package/dist/commands/whoami.js.map +1 -1
- package/dist/console/app.d.ts +1 -1
- package/dist/console/app.d.ts.map +1 -1
- package/dist/console/app.js +15 -9
- package/dist/console/app.js.map +1 -1
- package/dist/console/launch.d.ts +25 -0
- package/dist/console/launch.d.ts.map +1 -0
- package/dist/console/launch.js +56 -0
- package/dist/console/launch.js.map +1 -0
- package/dist/console/ui/CommandPalette.d.ts +5 -4
- package/dist/console/ui/CommandPalette.d.ts.map +1 -1
- package/dist/console/ui/CommandPalette.js +136 -45
- package/dist/console/ui/CommandPalette.js.map +1 -1
- package/dist/console/ui/Help.js +1 -1
- package/dist/console/ui/Help.js.map +1 -1
- package/dist/console/ui/Modal.d.ts +10 -0
- package/dist/console/ui/Modal.d.ts.map +1 -0
- package/dist/console/ui/Modal.js +8 -0
- package/dist/console/ui/Modal.js.map +1 -0
- package/dist/console/ui/NewAgent.d.ts +14 -0
- package/dist/console/ui/NewAgent.d.ts.map +1 -0
- package/dist/console/ui/NewAgent.js +114 -0
- package/dist/console/ui/NewAgent.js.map +1 -0
- package/dist/console/ui/StatusBar.d.ts +1 -2
- package/dist/console/ui/StatusBar.d.ts.map +1 -1
- package/dist/console/ui/StatusBar.js +6 -8
- package/dist/console/ui/StatusBar.js.map +1 -1
- package/dist/console/ui/topo/Map.d.ts.map +1 -1
- package/dist/console/ui/topo/Map.js +1 -2
- package/dist/console/ui/topo/Map.js.map +1 -1
- package/dist/console/ui/topo/Matrix.js +2 -2
- package/dist/console/ui/topo/Matrix.js.map +1 -1
- package/dist/console/ui/topo/Sequence.d.ts.map +1 -1
- package/dist/console/ui/topo/Sequence.js +5 -4
- package/dist/console/ui/topo/Sequence.js.map +1 -1
- package/dist/console/ui/topo/model.d.ts +2 -1
- package/dist/console/ui/topo/model.d.ts.map +1 -1
- package/dist/console/ui/topo/model.js +4 -3
- package/dist/console/ui/topo/model.js.map +1 -1
- package/dist/exec-endpoint/service-adapter.d.ts.map +1 -1
- package/dist/exec-endpoint/service-adapter.js +13 -3
- package/dist/exec-endpoint/service-adapter.js.map +1 -1
- package/dist/ext-loader.d.ts +4 -0
- package/dist/ext-loader.d.ts.map +1 -1
- package/dist/ext-loader.js +6 -0
- package/dist/ext-loader.js.map +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +44 -23
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -54
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-skills.d.ts.map +1 -1
- package/dist/lib/agent-skills.js +2 -1
- package/dist/lib/agent-skills.js.map +1 -1
- package/dist/lib/attach-client.js +2 -2
- package/dist/lib/attach-client.js.map +1 -1
- package/dist/lib/backup-artifact.d.ts +36 -8
- package/dist/lib/backup-artifact.d.ts.map +1 -1
- package/dist/lib/backup-artifact.js +156 -26
- package/dist/lib/backup-artifact.js.map +1 -1
- package/dist/lib/broker-service.d.ts +27 -3
- package/dist/lib/broker-service.d.ts.map +1 -1
- package/dist/lib/broker-service.js +135 -27
- package/dist/lib/broker-service.js.map +1 -1
- package/dist/lib/broker-store-health.d.ts +89 -0
- package/dist/lib/broker-store-health.d.ts.map +1 -0
- package/dist/lib/broker-store-health.js +171 -0
- package/dist/lib/broker-store-health.js.map +1 -0
- package/dist/lib/cancel.d.ts +4 -4
- package/dist/lib/cancel.d.ts.map +1 -1
- package/dist/lib/cancel.js +5 -5
- package/dist/lib/cancel.js.map +1 -1
- package/dist/lib/completion-install.d.ts +11 -2
- package/dist/lib/completion-install.d.ts.map +1 -1
- package/dist/lib/completion-install.js +79 -21
- package/dist/lib/completion-install.js.map +1 -1
- package/dist/lib/completion-scripts.d.ts.map +1 -1
- package/dist/lib/completion-scripts.js +2 -2
- package/dist/lib/completion-scripts.js.map +1 -1
- package/dist/lib/completion.d.ts +5 -1
- package/dist/lib/completion.d.ts.map +1 -1
- package/dist/lib/completion.js +10 -0
- package/dist/lib/completion.js.map +1 -1
- package/dist/lib/concrete-channel.d.ts +6 -0
- package/dist/lib/concrete-channel.d.ts.map +1 -0
- package/dist/lib/concrete-channel.js +17 -0
- package/dist/lib/concrete-channel.js.map +1 -0
- package/dist/lib/confirmation-required.d.ts +3 -12
- package/dist/lib/confirmation-required.d.ts.map +1 -1
- package/dist/lib/confirmation-required.js +9 -8
- package/dist/lib/confirmation-required.js.map +1 -1
- package/dist/lib/connect.d.ts +9 -0
- package/dist/lib/connect.d.ts.map +1 -1
- package/dist/lib/connect.js +27 -0
- package/dist/lib/connect.js.map +1 -1
- package/dist/lib/control.d.ts +42 -12
- package/dist/lib/control.d.ts.map +1 -1
- package/dist/lib/control.js +130 -31
- package/dist/lib/control.js.map +1 -1
- package/dist/lib/controller-restore.d.ts.map +1 -1
- package/dist/lib/controller-restore.js +12 -7
- package/dist/lib/controller-restore.js.map +1 -1
- package/dist/lib/credential-authority.d.ts.map +1 -1
- package/dist/lib/credential-authority.js +3 -0
- package/dist/lib/credential-authority.js.map +1 -1
- package/dist/lib/credential-exports.d.ts +17 -0
- package/dist/lib/credential-exports.d.ts.map +1 -0
- package/dist/lib/credential-exports.js +21 -0
- package/dist/lib/credential-exports.js.map +1 -0
- package/dist/lib/debug-flag.d.ts +4 -0
- package/dist/lib/debug-flag.d.ts.map +1 -0
- package/dist/lib/debug-flag.js +7 -0
- package/dist/lib/debug-flag.js.map +1 -0
- package/dist/lib/default-persona.d.ts +2 -0
- package/dist/lib/default-persona.d.ts.map +1 -1
- package/dist/lib/default-persona.js +2 -0
- package/dist/lib/default-persona.js.map +1 -1
- package/dist/lib/delivery-proc.d.ts +1 -1
- package/dist/lib/delivery-proc.d.ts.map +1 -1
- package/dist/lib/delivery-proc.js +5 -4
- package/dist/lib/delivery-proc.js.map +1 -1
- package/dist/lib/delivery-responder.d.ts +7 -3
- package/dist/lib/delivery-responder.d.ts.map +1 -1
- package/dist/lib/delivery-responder.js +8 -4
- package/dist/lib/delivery-responder.js.map +1 -1
- package/dist/lib/denied-write.d.ts +8 -0
- package/dist/lib/denied-write.d.ts.map +1 -0
- package/dist/lib/denied-write.js +24 -0
- package/dist/lib/denied-write.js.map +1 -0
- package/dist/lib/endpoint-capability-gates.js +2 -2
- package/dist/lib/endpoint-capability-gates.js.map +1 -1
- package/dist/lib/flag-value-refusal.d.ts +8 -0
- package/dist/lib/flag-value-refusal.d.ts.map +1 -0
- package/dist/lib/flag-value-refusal.js +10 -0
- package/dist/lib/flag-value-refusal.js.map +1 -0
- package/dist/lib/install-umask.d.ts +5 -0
- package/dist/lib/install-umask.d.ts.map +1 -1
- package/dist/lib/install-umask.js +25 -0
- package/dist/lib/install-umask.js.map +1 -1
- package/dist/lib/interrupt-notice.d.ts +23 -1
- package/dist/lib/interrupt-notice.d.ts.map +1 -1
- package/dist/lib/interrupt-notice.js +27 -6
- package/dist/lib/interrupt-notice.js.map +1 -1
- package/dist/lib/interrupt-report.d.ts +7 -0
- package/dist/lib/interrupt-report.d.ts.map +1 -0
- package/dist/lib/interrupt-report.js +24 -0
- package/dist/lib/interrupt-report.js.map +1 -0
- package/dist/lib/isolated-broker.d.ts +1 -1
- package/dist/lib/isolated-broker.d.ts.map +1 -1
- package/dist/lib/isolated-broker.js +17 -8
- package/dist/lib/isolated-broker.js.map +1 -1
- package/dist/lib/legacy-start.d.ts +8 -6
- package/dist/lib/legacy-start.d.ts.map +1 -1
- package/dist/lib/legacy-start.js +36 -36
- package/dist/lib/legacy-start.js.map +1 -1
- package/dist/lib/manager-choice.d.ts +45 -4
- package/dist/lib/manager-choice.d.ts.map +1 -1
- package/dist/lib/manager-choice.js +214 -24
- package/dist/lib/manager-choice.js.map +1 -1
- package/dist/lib/manager-proc.d.ts.map +1 -1
- package/dist/lib/manager-proc.js +7 -6
- package/dist/lib/manager-proc.js.map +1 -1
- package/dist/lib/manifest/index.d.ts +5 -1
- package/dist/lib/manifest/index.d.ts.map +1 -1
- package/dist/lib/manifest/index.js +50 -5
- package/dist/lib/manifest/index.js.map +1 -1
- package/dist/lib/manifest/preflight.d.ts +4 -0
- package/dist/lib/manifest/preflight.d.ts.map +1 -1
- package/dist/lib/manifest/preflight.js +18 -1
- package/dist/lib/manifest/preflight.js.map +1 -1
- package/dist/lib/manifest/resolve.d.ts +8 -0
- package/dist/lib/manifest/resolve.d.ts.map +1 -1
- package/dist/lib/manifest/resolve.js +104 -11
- package/dist/lib/manifest/resolve.js.map +1 -1
- package/dist/lib/missing-flags.js +1 -1
- package/dist/lib/missing-flags.js.map +1 -1
- package/dist/lib/nats-bin.d.ts +28 -5
- package/dist/lib/nats-bin.d.ts.map +1 -1
- package/dist/lib/nats-bin.js +85 -7
- package/dist/lib/nats-bin.js.map +1 -1
- package/dist/lib/nearest-word.d.ts +14 -0
- package/dist/lib/nearest-word.d.ts.map +1 -0
- package/dist/lib/nearest-word.js +76 -0
- package/dist/lib/nearest-word.js.map +1 -0
- package/dist/lib/no-expiry-record.d.ts +8 -0
- package/dist/lib/no-expiry-record.d.ts.map +1 -0
- package/dist/lib/no-expiry-record.js +27 -0
- package/dist/lib/no-expiry-record.js.map +1 -0
- package/dist/lib/paths.d.ts +31 -0
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +92 -2
- package/dist/lib/paths.js.map +1 -1
- package/dist/lib/persona-files.d.ts +29 -6
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +179 -36
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/personas.d.ts +18 -1
- package/dist/lib/personas.d.ts.map +1 -1
- package/dist/lib/personas.js +65 -6
- package/dist/lib/personas.js.map +1 -1
- package/dist/lib/prompts.d.ts +7 -1
- package/dist/lib/prompts.d.ts.map +1 -1
- package/dist/lib/prompts.js +43 -3
- package/dist/lib/prompts.js.map +1 -1
- package/dist/lib/registry-errors.d.ts +2 -1
- package/dist/lib/registry-errors.d.ts.map +1 -1
- package/dist/lib/registry-errors.js +6 -2
- package/dist/lib/registry-errors.js.map +1 -1
- package/dist/lib/reset-space-plan.d.ts +2 -0
- package/dist/lib/reset-space-plan.d.ts.map +1 -1
- package/dist/lib/reset-space-plan.js +1 -1
- package/dist/lib/reset-space-plan.js.map +1 -1
- package/dist/lib/restore.d.ts +45 -3
- package/dist/lib/restore.d.ts.map +1 -1
- package/dist/lib/restore.js +248 -35
- package/dist/lib/restore.js.map +1 -1
- package/dist/lib/rolled-back-runs.d.ts +36 -0
- package/dist/lib/rolled-back-runs.d.ts.map +1 -0
- package/dist/lib/rolled-back-runs.js +96 -0
- package/dist/lib/rolled-back-runs.js.map +1 -0
- package/dist/lib/service-definitions.d.ts +16 -3
- package/dist/lib/service-definitions.d.ts.map +1 -1
- package/dist/lib/service-definitions.js +99 -27
- package/dist/lib/service-definitions.js.map +1 -1
- package/dist/lib/service-instances.d.ts +13 -1
- package/dist/lib/service-instances.d.ts.map +1 -1
- package/dist/lib/service-instances.js +56 -12
- package/dist/lib/service-instances.js.map +1 -1
- package/dist/lib/service-presets.d.ts.map +1 -1
- package/dist/lib/service-presets.js +16 -0
- package/dist/lib/service-presets.js.map +1 -1
- package/dist/lib/service-process.d.ts +51 -8
- package/dist/lib/service-process.d.ts.map +1 -1
- package/dist/lib/service-process.js +385 -48
- package/dist/lib/service-process.js.map +1 -1
- package/dist/lib/space-streams.d.ts +18 -0
- package/dist/lib/space-streams.d.ts.map +1 -0
- package/dist/lib/space-streams.js +35 -0
- package/dist/lib/space-streams.js.map +1 -0
- package/dist/lib/spawn-defaults.d.ts +25 -1
- package/dist/lib/spawn-defaults.d.ts.map +1 -1
- package/dist/lib/spawn-defaults.js +37 -1
- package/dist/lib/spawn-defaults.js.map +1 -1
- package/dist/lib/stack-journal.d.ts +157 -14
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +406 -49
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/stack-listeners.d.ts +17 -0
- package/dist/lib/stack-listeners.d.ts.map +1 -0
- package/dist/lib/stack-listeners.js +54 -0
- package/dist/lib/stack-listeners.js.map +1 -0
- package/dist/lib/stack-members.d.ts +13 -0
- package/dist/lib/stack-members.d.ts.map +1 -0
- package/dist/lib/stack-members.js +24 -0
- package/dist/lib/stack-members.js.map +1 -0
- package/dist/lib/stack-resume.d.ts.map +1 -1
- package/dist/lib/stack-resume.js +5 -2
- package/dist/lib/stack-resume.js.map +1 -1
- package/dist/lib/stack-runs.d.ts +34 -0
- package/dist/lib/stack-runs.d.ts.map +1 -0
- package/dist/lib/stack-runs.js +75 -0
- package/dist/lib/stack-runs.js.map +1 -0
- package/dist/lib/status.d.ts +11 -0
- package/dist/lib/status.d.ts.map +1 -1
- package/dist/lib/status.js +4 -5
- package/dist/lib/status.js.map +1 -1
- package/dist/lib/stdout-owner.d.ts +12 -3
- package/dist/lib/stdout-owner.d.ts.map +1 -1
- package/dist/lib/stdout-owner.js +33 -5
- package/dist/lib/stdout-owner.js.map +1 -1
- package/dist/lib/store-dir.d.ts +68 -4
- package/dist/lib/store-dir.d.ts.map +1 -1
- package/dist/lib/store-dir.js +253 -17
- package/dist/lib/store-dir.js.map +1 -1
- package/dist/lib/team-additive-attempt.d.ts +1 -1
- package/dist/lib/team-channel-removal.d.ts.map +1 -1
- package/dist/lib/team-channel-removal.js +4 -0
- package/dist/lib/team-channel-removal.js.map +1 -1
- package/dist/lib/team-deploy-inspection.d.ts +13 -0
- package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
- package/dist/lib/team-deploy-inspection.js +12 -0
- package/dist/lib/team-deploy-inspection.js.map +1 -1
- package/dist/lib/team-text.d.ts +6 -0
- package/dist/lib/team-text.d.ts.map +1 -0
- package/dist/lib/team-text.js +36 -0
- package/dist/lib/team-text.js.map +1 -0
- package/dist/lib/transient.d.ts +14 -8
- package/dist/lib/transient.d.ts.map +1 -1
- package/dist/lib/transient.js +72 -11
- package/dist/lib/transient.js.map +1 -1
- package/dist/lib/unusable-file.d.ts +13 -0
- package/dist/lib/unusable-file.d.ts.map +1 -0
- package/dist/lib/unusable-file.js +12 -0
- package/dist/lib/unusable-file.js.map +1 -0
- package/dist/lib/up-report.d.ts +6 -0
- package/dist/lib/up-report.d.ts.map +1 -1
- package/dist/lib/up-report.js +13 -0
- package/dist/lib/up-report.js.map +1 -1
- package/dist/lib/verdict.d.ts +14 -0
- package/dist/lib/verdict.d.ts.map +1 -0
- package/dist/lib/verdict.js +15 -0
- package/dist/lib/verdict.js.map +1 -0
- package/dist/managed-handoff.d.ts +11 -6
- package/dist/managed-handoff.d.ts.map +1 -1
- package/dist/managed-handoff.js +27 -18
- package/dist/managed-handoff.js.map +1 -1
- package/dist/render.d.ts +5 -2
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +44 -10
- package/dist/render.js.map +1 -1
- package/dist/telemetry.d.ts +4 -3
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +14 -6
- package/dist/telemetry.js.map +1 -1
- package/dist/ui.d.ts +3 -2
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +6 -4
- package/dist/ui.js.map +1 -1
- package/dist/view/mesh-view.d.ts.map +1 -1
- package/dist/view/mesh-view.js +4 -1
- package/dist/view/mesh-view.js.map +1 -1
- package/dist/watch-data.d.ts +9 -1
- package/dist/watch-data.d.ts.map +1 -1
- package/dist/watch-data.js +17 -3
- package/dist/watch-data.js.map +1 -1
- package/dist/watch-json.js +4 -3
- package/dist/watch-json.js.map +1 -1
- package/package.json +5 -5
|
@@ -3,20 +3,35 @@
|
|
|
3
3
|
* `<root>/.cotal/stack-controller.json`. It is not a service record, unit receipt or team ledger,
|
|
4
4
|
* and it grants no stop authority by itself: every effect still rechecks the instance records. */
|
|
5
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
6
|
-
import { existsSync } from "node:fs";
|
|
7
|
-
import { isAbsolute, relative } from "node:path";
|
|
6
|
+
import { existsSync, rmdirSync } from "node:fs";
|
|
7
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
8
8
|
import { acquireLock, writeSecretFileAtomic } from "@cotal-ai/core";
|
|
9
|
-
import { CommandFailure, acquireMaintenanceLock, admittedControllerRestore, canonicalRoot, decodeLocalJson, isCommandFailure, isMaintenanceError, loadMeshes, localProcessPath, localProcessPathCandidates, localRecordObject, maintenancePaths, parsePid, probeLiveness, readContainedRecord, readLocalRecordSource, readMaintenanceJournal, readPidfile, recordedLocalProcessPaths, serviceOperationId, stackJournalPath } from "@cotal-ai/workspace";
|
|
9
|
+
import { CommandFailure, acquireMaintenanceLock, admittedControllerRestore, canonicalRoot, decodeLocalJson, isCommandFailure, isMaintenanceError, loadMeshes, localProcessPath, localProcessPathCandidates, localRecordObject, maintenancePaths, parsePid, probeLiveness, readContainedRecord, readLocalRecordSource, readMaintenanceJournal, readPidfile, recordedLocalProcessPaths, releaseMaintenanceLock, removePidPair, serviceOperationId, shellPath, stackJournalPath, maintenanceLockHolder, cotalDirLink, preparedSpaceAt, recordsMovedTo, stackAdoptionBlock, stackElsewhereRemedy, verifyIdentityPin } from "@cotal-ai/workspace";
|
|
10
10
|
import { localProcessSurface } from "../ext-loader.js";
|
|
11
11
|
import { serviceDefinitionStore } from "./service-definitions.js";
|
|
12
12
|
import { observeServiceProcess, serviceInstances } from "./service-instances.js";
|
|
13
|
-
import { abandonableSignalStop, abandonRetainedNativeStop, abandonRetainedSignalStop, removableServiceInstances, removeStoppedInstanceRecords, retainedStopRequest, settleExitedInstance, settleRetainedNativeStop } from "./service-process.js";
|
|
13
|
+
import { abandonableSignalStop, abandonRetainedNativeStop, abandonRetainedSignalStop, abandonUnresolvedLaunch, removableServiceInstances, removeStoppedInstanceRecords, resumableSignalStop, retainedStopMaySettle, retainedStopRequest, settleExitedInstance, settleRetainedNativeStop } from "./service-process.js";
|
|
14
|
+
import { stackRunsRecord } from "./stack-runs.js";
|
|
15
|
+
import { shellWord } from "./endpoint-errors.js";
|
|
14
16
|
export const STACK_ROLES = ["broker", "auth", "delivery", "manager"];
|
|
15
17
|
/** The fixed, root-bound definition names a controller stack owns. A custom definition with
|
|
16
18
|
* another name is never swept into the stack, whatever its adapter. */
|
|
17
19
|
export const STACK_DEFINITION = { broker: "stack-broker", auth: "stack-auth", delivery: "stack-delivery", manager: "stack-manager" };
|
|
18
20
|
export const STACK_ADAPTER = { broker: "nats-broker", auth: "auth-service", delivery: "delivery", manager: "manager-service" };
|
|
21
|
+
/** The way out a service command names for a saved definition at `path` that does not parse: one you
|
|
22
|
+
* added is moved aside and added again from its declaration. A stack member's definition is the
|
|
23
|
+
* stack's, so it keeps the plain refusal. */
|
|
24
|
+
export function addedDefinitionStep(name, path, space) {
|
|
25
|
+
if (Object.values(STACK_DEFINITION).includes(name))
|
|
26
|
+
return undefined;
|
|
27
|
+
return `move it aside, as mv ${shellPath(path)} ${shellPath(`${path}.old`)} does, then add the service again from its declaration with \`cotal service add ${name} --space ${space} --file <declaration>\``;
|
|
28
|
+
}
|
|
19
29
|
export const STACK_MODES = ["auth", "open", "user"];
|
|
30
|
+
/** The stack roles of `space` whose recorded processes run now. A signal handler reads it, so it
|
|
31
|
+
* only reads records and process state. */
|
|
32
|
+
export function runningStackRoles(space) {
|
|
33
|
+
return STACK_ROLES.filter((role) => serviceInstances(space, STACK_DEFINITION[role]).some((row) => observeServiceProcess(row.record.value) === "running"));
|
|
34
|
+
}
|
|
20
35
|
/** Which roles a mode can ever plan. An open stack has no delivery; only a user stack has an auth
|
|
21
36
|
* service. A role outside its mode stays `not-attempted` with no instance, and validation refuses
|
|
22
37
|
* any other shape. */
|
|
@@ -32,13 +47,45 @@ export { stackJournalPath };
|
|
|
32
47
|
function invalid(root) {
|
|
33
48
|
throw new CommandFailure("refused", "SCHEMA_INVALID", "the stack journal has an unsupported shape; no stack membership or stopped state was inferred", { remedy: `inspect ${stackJournalPath(root)} and the service instances it names; it was not reset` });
|
|
34
49
|
}
|
|
35
|
-
/** A well-formed journal that another folder recorded: this folder
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
/** A well-formed journal that another folder recorded: this folder's `.cotal` links to that folder's,
|
|
51
|
+
* or this folder was moved or copied after that stack started there. Its members and instances
|
|
52
|
+
* belong to that folder, so nothing here uses them. The next step is the one every command there names. */
|
|
53
|
+
function recordedElsewhere(root, recordedRoot, space, members) {
|
|
54
|
+
const link = cotalDirLink(root), remedy = stackElsewhereRemedy(root, recordedRoot, space, members);
|
|
55
|
+
if (link !== undefined)
|
|
56
|
+
throw new CommandFailure("refused", "CONFLICT", `${join(root, ".cotal")} is a link to ${link}, whose stack journal was recorded at ${recordedRoot}; a controller stack runs only from the folder it started in`, { target: { root, recordedRoot, space, link }, remedy });
|
|
57
|
+
if (recordsMovedTo(recordedRoot, root))
|
|
58
|
+
throw new CommandFailure("refused", "CONFLICT", `this folder's stack journal was recorded at ${recordedRoot}, whose .cotal is a link to this folder's .cotal, so these records were moved here from there; a controller stack runs only from the folder it started in`, { target: { root, recordedRoot, space, link: join(recordedRoot, ".cotal") }, remedy });
|
|
59
|
+
// The recorded root still holds its journal after a copy; after a move it does not, even where a
|
|
60
|
+
// running broker created empty folders at that path again.
|
|
61
|
+
const moved = !existsSync(stackJournalPath(recordedRoot));
|
|
62
|
+
throw new CommandFailure("refused", "CONFLICT", `this folder's stack journal was recorded at ${recordedRoot}, so this folder was ${moved ? "moved" : "copied"} from there; a controller stack runs only from the folder it started in`, { target: { root, recordedRoot, space }, remedy });
|
|
63
|
+
}
|
|
64
|
+
/** A journal whose bytes are not JSON, as an interrupted write or a full disk can leave it. Removing it
|
|
65
|
+
* is the way out once no member of its stack runs, so the remedy names any running member's stop
|
|
66
|
+
* first, from the service records of the spaces at this root. With no space recorded here, as after
|
|
67
|
+
* `space forget`, there are no saved definitions to start from either. */
|
|
68
|
+
function unreadable(root) {
|
|
69
|
+
const path = stackJournalPath(root);
|
|
70
|
+
let running, spaces = new Set();
|
|
71
|
+
try {
|
|
72
|
+
spaces = new Set([...loadMeshes().filter((mesh) => canonicalRoot(mesh.root) === root).map((mesh) => mesh.space), ...[preparedSpaceAt(root)?.space].filter((space) => space !== undefined)]);
|
|
73
|
+
running = [...spaces].flatMap((space) => [...STACK_ROLES].reverse().flatMap((role) => serviceInstances(space, STACK_DEFINITION[role])
|
|
74
|
+
.filter((row) => observeServiceProcess(row.record.value) === "running")
|
|
75
|
+
.map((row) => ({ space, name: STACK_DEFINITION[role], instanceId: row.record.value.instanceId }))));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
running = undefined;
|
|
79
|
+
}
|
|
80
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", `the stack journal ${path} is not valid JSON, as an interrupted write or a full disk can leave it; no stack membership or stopped state was inferred`, {
|
|
81
|
+
target: { root, path },
|
|
82
|
+
remedy: running === undefined
|
|
83
|
+
? `stop any running member of this stack with cotal service stop <name> --instance <id> --yes, manager first and broker last, then remove ${path} and run cotal up from ${root}`
|
|
84
|
+
: running.length === 0
|
|
85
|
+
? spaces.size
|
|
86
|
+
? `no member of this stack is running, so remove ${path}; the next cotal up from ${root} starts the stack again from its saved definitions`
|
|
87
|
+
: `no space is recorded at this root, so remove ${path} and run cotal up from ${root}`
|
|
88
|
+
: `stop its running members with ${running.map((row) => `cotal service stop ${row.name} --instance ${row.instanceId} --space ${row.space} --yes`).join(", then ")}, then remove ${path} and run cotal up from ${root}`,
|
|
42
89
|
});
|
|
43
90
|
}
|
|
44
91
|
function validate(input, root) {
|
|
@@ -69,7 +116,9 @@ function validate(input, root) {
|
|
|
69
116
|
invalid(root);
|
|
70
117
|
return member;
|
|
71
118
|
});
|
|
72
|
-
const operation = localRecordObject(value.operation, ["id", "kind", "phase", "recordedAt", "withAgents", "maintenanceAttemptId"]);
|
|
119
|
+
const operation = localRecordObject(value.operation, ["id", "kind", "phase", "recordedAt", "withAgents", "maintenanceAttemptId", "runs"]);
|
|
120
|
+
if (operation.runs !== undefined && (operation.kind !== "down" || stackRunsRecord(operation.runs) === undefined))
|
|
121
|
+
invalid(root);
|
|
73
122
|
try {
|
|
74
123
|
serviceOperationId(operation.id);
|
|
75
124
|
}
|
|
@@ -83,7 +132,7 @@ function validate(input, root) {
|
|
|
83
132
|
invalid(root);
|
|
84
133
|
const broker = value.broker === undefined ? undefined : brokerInputs(value.broker, root);
|
|
85
134
|
if (value.root !== root)
|
|
86
|
-
recordedElsewhere(root, value.root, value.space);
|
|
135
|
+
recordedElsewhere(root, value.root, value.space, members);
|
|
87
136
|
const { broker: _broker, ...rest } = value;
|
|
88
137
|
return { ...rest, members, ...(broker ? { broker } : {}), operation: operation };
|
|
89
138
|
}
|
|
@@ -113,7 +162,77 @@ export function readStackJournal(root) {
|
|
|
113
162
|
const bytes = readLocalRecordSource(stackJournalPath(canonical), LIMIT, true);
|
|
114
163
|
if (!bytes)
|
|
115
164
|
return undefined;
|
|
116
|
-
|
|
165
|
+
let input;
|
|
166
|
+
try {
|
|
167
|
+
input = decodeLocalJson(bytes);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (isCommandFailure(error))
|
|
171
|
+
unreadable(canonical);
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
return { journal: validate(input, canonical), sha256: createHash("sha256").update(bytes).digest("hex") };
|
|
175
|
+
}
|
|
176
|
+
/** The stack journal at `root` that another folder recorded, as a copy or a moved folder keeps it, with
|
|
177
|
+
* that folder. Undefined when `root` has no journal or recorded it itself. */
|
|
178
|
+
export function journalRecordedElsewhere(root) {
|
|
179
|
+
const canonical = canonicalRoot(root);
|
|
180
|
+
const bytes = readLocalRecordSource(stackJournalPath(canonical), LIMIT, true);
|
|
181
|
+
if (!bytes)
|
|
182
|
+
return undefined;
|
|
183
|
+
let input;
|
|
184
|
+
try {
|
|
185
|
+
input = decodeLocalJson(bytes);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (isCommandFailure(error))
|
|
189
|
+
unreadable(canonical);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
const recordedRoot = input?.root;
|
|
193
|
+
if (typeof recordedRoot !== "string" || recordedRoot === canonical)
|
|
194
|
+
return undefined;
|
|
195
|
+
// Validated as if recorded here, so a shape refusal names this folder's journal.
|
|
196
|
+
return { journal: validate({ ...input, root: canonical }, canonical), recordedRoot, sha256: createHash("sha256").update(bytes).digest("hex") };
|
|
197
|
+
}
|
|
198
|
+
/** Why `space create --adopt` would refuse the journal {@link journalRecordedElsewhere} found at
|
|
199
|
+
* `root`, as the message and the next step; undefined when it would adopt it. */
|
|
200
|
+
export function adoptionRefusal(root, found) {
|
|
201
|
+
return stackAdoptionBlock(canonicalRoot(root), found.recordedRoot, found.journal.space, found.journal.members);
|
|
202
|
+
}
|
|
203
|
+
/** `space create --adopt`: rewrite, at `root`, the stack journal another folder recorded, as a copy
|
|
204
|
+
* from another machine or a folder moved after its stack stopped keeps it, so it names this root.
|
|
205
|
+
* It refuses as {@link stackAdoptionBlock} says. The adopted journal keeps the space, address, mode and
|
|
206
|
+
* broker inputs, with a store that lay under the recorded root moved under this one, and records an
|
|
207
|
+
* up refused before any member started, as a stack that never ran here. Returns the recorded root. */
|
|
208
|
+
export function adoptStackJournal(root, space) {
|
|
209
|
+
const canonical = canonicalRoot(root), path = stackJournalPath(canonical);
|
|
210
|
+
const lock = acquireLock(`${path}.lock`, { label: "stack journal", onTimeout: () => new CommandFailure("refused", "CONFLICT", "another writer holds the stack journal") });
|
|
211
|
+
try {
|
|
212
|
+
const found = journalRecordedElsewhere(canonical);
|
|
213
|
+
if (!found)
|
|
214
|
+
throw new CommandFailure("refused", "TARGET_NOT_FOUND", `${canonical} holds no stack journal another folder recorded, so there is nothing to adopt; nothing was written`, { target: { root: canonical, space }, remedy: `run cotal space create ${space} --root ${shellWord(canonical)} without --adopt` });
|
|
215
|
+
if (found.journal.space !== space)
|
|
216
|
+
throw new CommandFailure("refused", "CONFLICT", `the stack journal in ${canonical} is for "${found.journal.space}", not "${space}"; nothing was written`, { target: { root: canonical, space, journalSpace: found.journal.space }, remedy: `adopt it with cotal space create ${found.journal.space} --adopt --root ${canonical}` });
|
|
217
|
+
const block = stackAdoptionBlock(canonical, found.recordedRoot, space, found.journal.members);
|
|
218
|
+
if (block)
|
|
219
|
+
throw new CommandFailure("refused", "CONFLICT", `${block.message}; it was not adopted and nothing was written`, { target: { root: canonical, recordedRoot: found.recordedRoot, space }, remedy: block.remedy });
|
|
220
|
+
const under = (path) => { const rest = relative(found.recordedRoot, path); return rest !== "" && !rest.startsWith("..") && !isAbsolute(rest) ? join(canonical, rest) : path; };
|
|
221
|
+
const now = new Date().toISOString();
|
|
222
|
+
const next = {
|
|
223
|
+
schemaVersion: 1, kind: "cotal-stack-controller", root: canonical, space, server: found.journal.server, mode: found.journal.mode,
|
|
224
|
+
members: STACK_ROLES.map((role) => ({ role, definition: STACK_DEFINITION[role], instanceId: null, state: "not-attempted" })),
|
|
225
|
+
...(found.journal.broker ? { broker: { ...found.journal.broker, storeDir: under(found.journal.broker.storeDir) } } : {}),
|
|
226
|
+
operation: { id: randomUUID(), kind: "up", phase: "refused", recordedAt: now, withAgents: false },
|
|
227
|
+
updatedAt: now,
|
|
228
|
+
};
|
|
229
|
+
validate(next, canonical);
|
|
230
|
+
writeSecretFileAtomic(path, JSON.stringify(next, null, 2) + "\n");
|
|
231
|
+
return found.recordedRoot;
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
lock.release();
|
|
235
|
+
}
|
|
117
236
|
}
|
|
118
237
|
/** A controller-owned stack cannot be preserved in this release, so its preserve, and the backup and
|
|
119
238
|
* restore that need a preserved cut, refuse while validating, before the seed or any effect. A
|
|
@@ -128,8 +247,8 @@ export function refuseControllerCut(root, action) {
|
|
|
128
247
|
: `${action} needs a preserved cut, and a controller-owned stack cannot be preserved in this release; nothing was written`, {
|
|
129
248
|
target: { root: recorded.journal.root, space: recorded.journal.space },
|
|
130
249
|
remedy: preserve
|
|
131
|
-
? "stop the stack with plain `cotal down`, which keeps its store, channels and history for the next `cotal up
|
|
132
|
-
: "plain `cotal down` and `cotal up` keep this stack's store, channels and history; backup and restore of a controller-owned stack return in a later release",
|
|
250
|
+
? "stop the stack with plain `cotal down`, which keeps its store, channels and history for the next `cotal up`, but on a full store `cotal down` refuses and names how to stop the stack with or without purging that history; preserve on a controller-owned stack returns in a later release"
|
|
251
|
+
: "plain `cotal down` and `cotal up` keep this stack's store, channels and history, but on a full store `cotal down` refuses and names how to stop the stack with or without purging that history; backup and restore of a controller-owned stack return in a later release",
|
|
133
252
|
});
|
|
134
253
|
}
|
|
135
254
|
/** Compare-and-replace under a private lock beside the journal. A changed journal refuses. */
|
|
@@ -181,23 +300,53 @@ export function maintenanceStackView(root, space) {
|
|
|
181
300
|
}
|
|
182
301
|
/** Take the root's maintenance lock for one whole-stack operation. Every whole-stack operation
|
|
183
302
|
* holds it for its whole run, and a dead holder is reclaimed only when its PID is proven dead. A
|
|
184
|
-
* live holder is a known refusal that names its PID; nothing was read or changed.
|
|
185
|
-
|
|
303
|
+
* live holder is a known refusal that names its PID; nothing was read or changed. `operation`, such
|
|
304
|
+
* as `restore`, is recorded in the lock so another command it refuses can say what holds the root.
|
|
305
|
+
* Taking the lock creates the root's `.cotal/maintenance` folders when they are missing. A command
|
|
306
|
+
* that then ends refused or failed releases the lock if it still holds it, and removes the folders
|
|
307
|
+
* the lock created while they are still empty, so a refusal leaves the folder as it found it. */
|
|
308
|
+
export function acquireStackOperationLock(root, operation) {
|
|
309
|
+
const paths = maintenancePaths(root);
|
|
310
|
+
const created = [paths.versionDir, paths.maintenanceDir, paths.cotalDir].filter((dir) => !existsSync(dir));
|
|
311
|
+
let lock;
|
|
186
312
|
try {
|
|
187
|
-
|
|
313
|
+
lock = acquireMaintenanceLock(root, operation ? { operation } : {});
|
|
188
314
|
}
|
|
189
315
|
catch (error) {
|
|
190
316
|
if (!isMaintenanceError(error) || error.code !== "lock-held")
|
|
191
317
|
throw error;
|
|
192
318
|
let holder;
|
|
193
319
|
try {
|
|
194
|
-
holder = decodeLocalJson(readLocalRecordSource(
|
|
320
|
+
holder = decodeLocalJson(readLocalRecordSource(paths.lock, 64 * 1024) ?? Buffer.from("null"))?.owner?.pid;
|
|
195
321
|
}
|
|
196
322
|
catch {
|
|
197
323
|
holder = undefined;
|
|
198
324
|
}
|
|
199
325
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", `another whole-stack or maintenance operation holds this root${Number.isSafeInteger(holder) ? ` (pid ${holder})` : ""}; nothing was changed`, { target: { root, ...(Number.isSafeInteger(holder) ? { holderPid: holder } : {}) }, remedy: "run the command again after that operation exits; a foreground cotal up holds the root only while it starts" });
|
|
200
326
|
}
|
|
327
|
+
// An exit through process.exit skips the caller's release, so the lock is checked here as well.
|
|
328
|
+
process.once("exit", (code) => {
|
|
329
|
+
if (code === 0)
|
|
330
|
+
return;
|
|
331
|
+
try {
|
|
332
|
+
const held = decodeLocalJson(readLocalRecordSource(lock.path, 64 * 1024) ?? Buffer.from("null"))?.token === lock.token;
|
|
333
|
+
if (held)
|
|
334
|
+
releaseMaintenanceLock(lock);
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
// Deepest first. A folder that holds anything else was written by the command, and it stays.
|
|
340
|
+
for (const dir of created) {
|
|
341
|
+
try {
|
|
342
|
+
rmdirSync(dir);
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return lock;
|
|
201
350
|
}
|
|
202
351
|
const UNSETTLED_PHASES = ["planned", "applying", "unknown"];
|
|
203
352
|
/** Whether the journal's last operation has no recorded outcome. */
|
|
@@ -242,16 +391,57 @@ function classifyStackMember(journal, role, settle) {
|
|
|
242
391
|
if (gone && !stopRetained && (["failed", "stopped"].includes(value.state) || !settle && value.process !== undefined && ["starting", "running", "unknown"].includes(value.state)))
|
|
243
392
|
return { role, instanceId: row.name, process: "gone" };
|
|
244
393
|
// Nothing was changed by this command, so its own outcome is a known refusal.
|
|
394
|
+
const route = memberStopRoute(value);
|
|
245
395
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", !stopRetained
|
|
246
396
|
? "a stack member's process is neither live nor proven gone, so the earlier whole-stack operation cannot be settled from evidence; nothing was retried"
|
|
247
397
|
: retained?.publication === "unknown"
|
|
248
398
|
? "a stack member's stop request file does not read as its own, so whether a stop was published is unknown and the earlier whole-stack operation cannot be settled from evidence; nothing was retried"
|
|
249
|
-
: "a stack member retains an unconfirmed stop request, so the earlier whole-stack operation cannot be settled from evidence; nothing was retried", { target: { ...target, instanceId: row.name, recordedState: value.state, process: observed, ...(stopRetained ? { requestId: retained?.requestId ?? value.requestId, ...(retained ? { stopPublication: retained.publication } : {}) } : {}) }, remedy:
|
|
399
|
+
: "a stack member retains an unconfirmed stop request, so the earlier whole-stack operation cannot be settled from evidence; nothing was retried", { target: { ...target, instanceId: row.name, recordedState: value.state, process: observed, ...(stopRetained ? { requestId: retained?.requestId ?? value.requestId, ...(retained ? { stopPublication: retained.publication } : {}) } : {}) }, remedy: route.kind === "abandon" ? `${inspect(row.name)}; ${abandonRemedy(route.requestId)}` : route.kind === "resume" ? `${inspect(row.name)}; ${RESUME_REMEDY}` : observed === "unresolved-launch" ? `${inspect(row.name)}; ${abandonLaunchRemedy(row.name)}` : inspect(row.name) });
|
|
250
400
|
}
|
|
251
401
|
finally {
|
|
252
402
|
hold?.release();
|
|
253
403
|
}
|
|
254
404
|
}
|
|
405
|
+
/** The way out a refusal of `value` names: abandon the stop it retains, signal its process again, or
|
|
406
|
+
* only inspect it. */
|
|
407
|
+
function memberStopRoute(value) {
|
|
408
|
+
const retained = retainedStopRequest(value);
|
|
409
|
+
if (retained?.publication === "published")
|
|
410
|
+
return { kind: "abandon", requestId: retained.requestId };
|
|
411
|
+
if (abandonableSignalStop(value))
|
|
412
|
+
return { kind: "abandon", requestId: value.requestId };
|
|
413
|
+
return { kind: resumableSignalStop(value) ? "resume" : "inspect" };
|
|
414
|
+
}
|
|
415
|
+
/** What keeps `up` and `down` from settling this journal's operation, which ended with no recorded
|
|
416
|
+
* outcome: the member their refusal names, why, and the way out it names. Read as `down --dry-run`
|
|
417
|
+
* reads it, with nothing written. Undefined when the operation is settled or settles from its
|
|
418
|
+
* members' processes, and when a member's retained stop may settle before they classify it, which
|
|
419
|
+
* for a native stop only its adapter's receipts decide. */
|
|
420
|
+
export function stackOperationBlock(journal) {
|
|
421
|
+
try {
|
|
422
|
+
previewStackSettlement(journal);
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
const target = isCommandFailure(error) && error.code === "LIFECYCLE_BLOCKED" ? error.target : undefined;
|
|
427
|
+
if (typeof target?.definition !== "string" || typeof target.instanceId !== "string")
|
|
428
|
+
throw error;
|
|
429
|
+
const row = serviceInstances(journal.space, target.definition).find((item) => item.name === target.instanceId);
|
|
430
|
+
if (!row)
|
|
431
|
+
throw error;
|
|
432
|
+
const value = row.record.value, route = memberStopRoute(value);
|
|
433
|
+
if (retainedStopMaySettle(value) || route.kind === "resume")
|
|
434
|
+
return undefined;
|
|
435
|
+
const operation = `the earlier ${journal.operation.kind === "down" ? "whole-stack stop" : journal.operation.kind} ${journal.operation.id}`;
|
|
436
|
+
return {
|
|
437
|
+
operation: { id: journal.operation.id, kind: journal.operation.kind },
|
|
438
|
+
definition: target.definition, instanceId: target.instanceId, route,
|
|
439
|
+
reason: route.kind === "abandon"
|
|
440
|
+
? `${operation} asked ${target.definition} to stop and ended before it saw the process exit, and the process is gone, so up and down refuse until the stop is abandoned`
|
|
441
|
+
: `${operation} ended with no recorded outcome, and ${target.definition} is neither proven running nor proven stopped, so up and down refuse until it is inspected`,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
}
|
|
255
445
|
/** Settle each member's retained native stop from its adapter's own receipt, under that member's
|
|
256
446
|
* definition lock, before an `up` or `down` classifies the members. The caller holds the root's
|
|
257
447
|
* maintenance lock. A member whose adapter confirms less keeps its stop, and the classification
|
|
@@ -274,8 +464,34 @@ export async function settleRetainedStackStops(journal) {
|
|
|
274
464
|
}
|
|
275
465
|
}
|
|
276
466
|
}
|
|
467
|
+
/** The step for a member stop whose process still runs after the command that sent it exited. */
|
|
468
|
+
export const RESUME_REMEDY = "once the command that sent the stop has exited, `cotal down --yes` signals the process again";
|
|
277
469
|
/** The remedy a refusal over a retained, published member stop names. */
|
|
278
470
|
export const abandonRemedy = (requestId) => `once its process and the down that sent the request have exited, \`cotal down --abandon-stop ${requestId} --yes\` abandons it`;
|
|
471
|
+
/** The remedy a refusal over a member launch whose record names no process names. */
|
|
472
|
+
export const abandonLaunchRemedy = (instanceId) => `once the up that launched it has exited, \`cotal down --abandon-launch ${instanceId} --yes\` records it failed; a process that launch started without recording it is not excluded`;
|
|
473
|
+
/** Record `failed`, on an operator's explicit request, the member launch `instanceId` whose record
|
|
474
|
+
* names no process, under that member's definition lock, before a `down` classifies the members.
|
|
475
|
+
* The caller holds the root's maintenance lock. No member with that instance refuses
|
|
476
|
+
* `TARGET_NOT_FOUND`, and nothing is written. */
|
|
477
|
+
export function abandonUnresolvedStackLaunch(journal, instanceId) {
|
|
478
|
+
const store = serviceDefinitionStore(journal.space);
|
|
479
|
+
for (const role of STACK_ROLES.filter((entry) => stackRoleApplies(journal.mode, entry))) {
|
|
480
|
+
const definition = store.read(STACK_DEFINITION[role]), launch = definition?.record.value.launch;
|
|
481
|
+
if (!definition || launch?.type !== "adapter" || launch.adapter !== STACK_ADAPTER[role] || launch.options.root !== journal.root)
|
|
482
|
+
continue;
|
|
483
|
+
const hold = store.pin(definition);
|
|
484
|
+
try {
|
|
485
|
+
const row = serviceInstances(journal.space, definition.name).find((entry) => entry.name === instanceId);
|
|
486
|
+
if (row)
|
|
487
|
+
return { role, row: abandonUnresolvedLaunch(row) };
|
|
488
|
+
}
|
|
489
|
+
finally {
|
|
490
|
+
hold.release();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
throw new CommandFailure("refused", "TARGET_NOT_FOUND", "no member of this stack has an instance with that ID; nothing was abandoned", { target: { root: journal.root, space: journal.space, instanceId }, remedy: `run \`cotal down --dry-run\` to see what blocks the stop, or \`cotal service status <definition> --space ${journal.space}\` for a member's instances` });
|
|
494
|
+
}
|
|
279
495
|
/** Abandon the one member stop that retains `requestId`, on an operator's explicit request, under that
|
|
280
496
|
* member's definition lock, before a `down` classifies the members. The caller holds the root's
|
|
281
497
|
* maintenance lock. A native stop is abandoned through its adapter, and a broker's or another
|
|
@@ -318,9 +534,11 @@ export function settleStackOperation(lock, snapshot) {
|
|
|
318
534
|
return { snapshot };
|
|
319
535
|
if (lock.root !== journal.root)
|
|
320
536
|
throw new CommandFailure("refused", "CONFLICT", "the held maintenance lock belongs to another root; the earlier operation was not settled", { target: { root: journal.root } });
|
|
321
|
-
const
|
|
322
|
-
const
|
|
323
|
-
|
|
537
|
+
const roles = STACK_ROLES.filter((role) => stackRoleApplies(journal.mode, role));
|
|
538
|
+
const members = roles.flatMap((role) => classifyStackMember(journal, role, true) ?? []);
|
|
539
|
+
const settlement = { operation, members, unstarted: attemptedRoles(journal).filter((role) => !members.some((member) => member.role === role)) };
|
|
540
|
+
const settled = writeStackJournal(journal.root, snapshot, { ...journal, members: withSettledMembers(journal, settlement).members.map((row) => row.state !== "planned" && row.state !== "unknown" ? row : members.some((member) => member.role === row.role) ? { ...row, state: "unknown", code: "OPERATION_UNKNOWN" } : { ...row, state: "not-attempted", code: undefined }), operation: { ...operation, phase: "failed" }, updatedAt: new Date().toISOString() });
|
|
541
|
+
return { snapshot: settled, settled: settlement };
|
|
324
542
|
}
|
|
325
543
|
/** The journal with each journaled replacement resolved, and each member row that has no recorded
|
|
326
544
|
* instance given the one the settlement classified under that member's stack definition. An `up`
|
|
@@ -356,16 +574,76 @@ function resolveReplacement(journal, row) {
|
|
|
356
574
|
export function previewStackSettlement(journal) {
|
|
357
575
|
if (!stackOperationUnsettled(journal) || journal.operation.kind !== "up" && journal.operation.kind !== "down")
|
|
358
576
|
return undefined;
|
|
359
|
-
|
|
577
|
+
const roles = STACK_ROLES.filter((role) => stackRoleApplies(journal.mode, role));
|
|
578
|
+
const members = roles.flatMap((role) => classifyStackMember(journal, role, false) ?? []);
|
|
579
|
+
return { operation: journal.operation, members, unstarted: attemptedRoles(journal).filter((role) => !members.some((member) => member.role === role)) };
|
|
580
|
+
}
|
|
581
|
+
/** The members the journal's operation planned, as a `--no-manager` up plans no manager. */
|
|
582
|
+
function attemptedRoles(journal) {
|
|
583
|
+
return STACK_ROLES.filter((role) => stackRoleApplies(journal.mode, role) && journal.members.some((row) => row.role === role && row.state !== "not-attempted"));
|
|
584
|
+
}
|
|
585
|
+
/** An earlier `up` that ended with no recorded outcome before every member it planned started, or
|
|
586
|
+
* a `down` that ended so before every member stopped, with the members on each side as their
|
|
587
|
+
* processes show. A member with no instance record counts as stopped, and `noManager` says the up
|
|
588
|
+
* planned no manager, as `up --no-manager` does. Read-only. Undefined when the last
|
|
589
|
+
* operation settled, when it reached its end anyway, or when a member's process is neither running
|
|
590
|
+
* nor proven gone. */
|
|
591
|
+
export function unfinishedStackOperation(journal) {
|
|
592
|
+
const { kind, id } = journal.operation;
|
|
593
|
+
if (!stackOperationUnsettled(journal) || kind !== "up" && kind !== "down")
|
|
594
|
+
return undefined;
|
|
595
|
+
const running = [], stopped = [];
|
|
596
|
+
for (const role of attemptedRoles(journal)) {
|
|
597
|
+
const observed = serviceInstances(journal.space, STACK_DEFINITION[role]).map((row) => observeServiceProcess(row.record.value));
|
|
598
|
+
if (observed.includes("running"))
|
|
599
|
+
running.push(role);
|
|
600
|
+
else if (observed.every(processGone))
|
|
601
|
+
stopped.push(role);
|
|
602
|
+
else
|
|
603
|
+
return undefined;
|
|
604
|
+
}
|
|
605
|
+
if (kind === "up" ? !stopped.length : !running.length)
|
|
606
|
+
return undefined;
|
|
607
|
+
return { kind, id, running, stopped, noManager: kind === "up" && stackRoleApplies(journal.mode, "manager") && !running.includes("manager") && !stopped.includes("manager") };
|
|
360
608
|
}
|
|
361
609
|
/** The one-line notice a command prints after it settled an earlier operation. */
|
|
362
610
|
export function stackSettlementNotice(settled) {
|
|
363
611
|
const gone = settled.members.filter((row) => row.process === "gone").map((row) => row.role), running = settled.members.filter((row) => row.process === "running").map((row) => row.role);
|
|
364
|
-
|
|
612
|
+
const { kind, id } = settled.operation;
|
|
613
|
+
// An up whose members all run, or a down whose members are all gone, reached its end anyway.
|
|
614
|
+
if (kind === "up" && !gone.length && !settled.unstarted.length)
|
|
615
|
+
return `the earlier up ${id} was interrupted before it recorded an outcome; every member is running (${running.join(", ")})`;
|
|
616
|
+
if (kind === "down" && !running.length)
|
|
617
|
+
return `the earlier down ${id} was interrupted before it recorded an outcome; every member is stopped`;
|
|
618
|
+
return `the earlier ${kind} ${id} had no recorded outcome; it was recorded as failed from its members' processes (gone: ${gone.join(", ") || "none"}; running: ${running.join(", ") || "none"}${settled.unstarted.length ? `; not started: ${settled.unstarted.join(", ")}` : ""})`;
|
|
365
619
|
}
|
|
366
620
|
export function newStackOperation(kind, withAgents = false) {
|
|
367
621
|
return { id: randomUUID(), kind, phase: "planned", recordedAt: new Date().toISOString(), withAgents };
|
|
368
622
|
}
|
|
623
|
+
/** Whether the stack's last `up` completed with its manager not attempted, as `up --no-manager`
|
|
624
|
+
* records it, so the stack runs no manager by choice. */
|
|
625
|
+
export function stackStartedWithoutManager(journal) {
|
|
626
|
+
return journal.operation.kind === "up" && journal.operation.phase === "completed" && journal.members.some((row) => row.role === "manager" && row.state === "not-attempted");
|
|
627
|
+
}
|
|
628
|
+
/** Whether the stack's last `up` ended with no recorded outcome and planned no manager, as
|
|
629
|
+
* `up --no-manager` does. */
|
|
630
|
+
export function interruptedUpLeftManagerOut(journal) {
|
|
631
|
+
return journal.operation.kind === "up" && stackOperationUnsettled(journal) && journal.members.some((row) => row.role === "manager" && row.state === "not-attempted");
|
|
632
|
+
}
|
|
633
|
+
/** Whether an `up` on this root is starting the stack's manager for `space` now: the journal records
|
|
634
|
+
* an unsettled `up` that planned the manager, and a live process holds the root's maintenance lock,
|
|
635
|
+
* as every whole-stack operation does for its whole run. An `up` that died there is not starting. */
|
|
636
|
+
export function stackManagerStarting(root, space) {
|
|
637
|
+
try {
|
|
638
|
+
const journal = readStackJournal(root)?.journal;
|
|
639
|
+
if (journal?.space !== space || journal.operation.kind !== "up" || !stackOperationUnsettled(journal))
|
|
640
|
+
return false;
|
|
641
|
+
return journal.members.some((row) => row.role === "manager" && row.state === "planned") && maintenanceLockHolder(root) === "alive";
|
|
642
|
+
}
|
|
643
|
+
catch {
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
369
647
|
/** Whether this root records a controller stack for `space` with no live manager instance. False
|
|
370
648
|
* when it records none, or an unreadable one, so a remote or legacy mesh keeps its own answer. */
|
|
371
649
|
export function stackManagerAbsent(root, space) {
|
|
@@ -378,6 +656,18 @@ export function stackManagerAbsent(root, space) {
|
|
|
378
656
|
return false;
|
|
379
657
|
}
|
|
380
658
|
}
|
|
659
|
+
/** The pid of this root's running stack manager for `space`, so a read it did not answer can name
|
|
660
|
+
* it. Undefined when the root records no stack for `space` or its records cannot be read. */
|
|
661
|
+
export function runningStackManagerPid(root, space) {
|
|
662
|
+
try {
|
|
663
|
+
if (readStackJournal(root)?.journal.space !== space)
|
|
664
|
+
return undefined;
|
|
665
|
+
return serviceInstances(space, STACK_DEFINITION.manager).find((row) => observeServiceProcess(row.record.value) === "running")?.record.value.process?.pid;
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
return undefined;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
381
671
|
/** The controller stack definition a legacy component name stands for in `space`, when that
|
|
382
672
|
* definition is saved there. A controller stack names its members stack-<role>. */
|
|
383
673
|
export function stackMemberFor(space, name) {
|
|
@@ -399,6 +689,20 @@ export function stackDefinitionsAt(space, root) {
|
|
|
399
689
|
return row && launch?.type === "adapter" && launch.adapter === STACK_ADAPTER[role] && launch.options.root === root ? [row] : [];
|
|
400
690
|
});
|
|
401
691
|
}
|
|
692
|
+
/** The folder `space`'s saved stack broker starts in, when that folder is gone: it holds neither its
|
|
693
|
+
* stack journal nor the broker configuration the definition names, whatever a still-running broker
|
|
694
|
+
* wrote back into it. Undefined otherwise, or when the definition cannot be read. */
|
|
695
|
+
export function goneStackRoot(space) {
|
|
696
|
+
try {
|
|
697
|
+
const launch = serviceDefinitionStore(space).read(STACK_DEFINITION.broker)?.record.value.launch;
|
|
698
|
+
if (launch?.type !== "adapter" || launch.adapter !== STACK_ADAPTER.broker || typeof launch.options.root !== "string" || typeof launch.options.config !== "string")
|
|
699
|
+
return undefined;
|
|
700
|
+
return existsSync(stackJournalPath(launch.options.root)) || existsSync(launch.options.config) ? undefined : launch.options.root;
|
|
701
|
+
}
|
|
702
|
+
catch {
|
|
703
|
+
return undefined;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
402
706
|
/** Remove the controller stack definitions saved for `space` at `root`, with their stopped instance
|
|
403
707
|
* records, as `service remove` does, so that another folder can start a stack under the same name.
|
|
404
708
|
* A definition saved for another root is left alone. Nothing is removed while the root holds
|
|
@@ -429,8 +733,9 @@ export function releaseStackDefinitions(root, space) {
|
|
|
429
733
|
removableServiceInstances(space, row.name);
|
|
430
734
|
}
|
|
431
735
|
catch (error) {
|
|
432
|
-
const route =
|
|
433
|
-
:
|
|
736
|
+
const route = goneStackRoot(space) === root ? `its folder is gone; cotal down --space ${space} --yes stops the stack and removes them`
|
|
737
|
+
: existsSync(root) ? `stop the stack with cotal down --yes in ${root}, then run cotal space forget ${space} again`
|
|
738
|
+
: isCommandFailure(error) && error.remedy || `inspect them with cotal service --space ${space}`;
|
|
434
739
|
return { released: [], kept: { names, why: `${error.message}; ${route}` } };
|
|
435
740
|
}
|
|
436
741
|
const store = serviceDefinitionStore(space), released = [];
|
|
@@ -447,28 +752,76 @@ export function releaseStackDefinitions(root, space) {
|
|
|
447
752
|
}
|
|
448
753
|
return { released };
|
|
449
754
|
}
|
|
450
|
-
/**
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
export function
|
|
755
|
+
/** The legacy pidfile records under the root, excluding the settled records the stack's own
|
|
756
|
+
* controller children publish for themselves: a record counts as owned only when its PID is the
|
|
757
|
+
* live creation-pinned process of a stack member instance. Read only: nothing is adopted. */
|
|
758
|
+
export function localRecords(root, space) {
|
|
454
759
|
const owned = new Set();
|
|
455
760
|
for (const name of Object.values(STACK_DEFINITION))
|
|
456
761
|
for (const row of serviceInstances(space, name))
|
|
457
762
|
if (row.record.value.process && observeServiceProcess(row.record.value) === "running")
|
|
458
763
|
owned.add(row.record.value.process.pid);
|
|
459
|
-
const
|
|
764
|
+
const records = [];
|
|
460
765
|
for (const component of localProcessSurface()) {
|
|
461
|
-
const
|
|
766
|
+
const path = localProcessPath(component.pidFile, { root, space });
|
|
767
|
+
const raw = readPidfile(path);
|
|
462
768
|
if (!raw)
|
|
463
769
|
continue;
|
|
464
770
|
const pid = parsePid(raw);
|
|
465
771
|
if (pid !== undefined && owned.has(pid))
|
|
466
772
|
continue;
|
|
467
|
-
|
|
468
|
-
|
|
773
|
+
const pin = pid === undefined ? undefined : verifyIdentityPin(path).kind;
|
|
774
|
+
records.push({ name: component.name, path: relative(root, path), raw, ...(pid === undefined ? {} : { pid }), state: pin === "gone" ? "gone" : pin === "mismatch" ? "reused" : "live" });
|
|
469
775
|
}
|
|
470
|
-
return
|
|
776
|
+
return records;
|
|
471
777
|
}
|
|
778
|
+
/** How a refusal lists one record: `<name> at <path>, pid <pid>`. */
|
|
779
|
+
export const localRecordLine = (row) => `${row.name} at ${row.path}, ${row.pid === undefined ? "unattributable record" : `pid ${row.pid}`}`;
|
|
780
|
+
/** Legacy pidfile records under the root that may front a process, as `up` refuses them: every
|
|
781
|
+
* record whose process is not gone. */
|
|
782
|
+
export function foreignLocalProcesses(root, space) {
|
|
783
|
+
return localRecords(root, space).filter((row) => row.state !== "gone").map((row) => `${row.name}${row.pid === undefined ? " (unattributable record)" : ` (pid ${row.pid})`}`);
|
|
784
|
+
}
|
|
785
|
+
/** The live records under the root whose process is a running service instance of the space outside
|
|
786
|
+
* its stack, as the manager record of a `manager` preset service started at the root is. Read only:
|
|
787
|
+
* nothing is adopted. */
|
|
788
|
+
export function serviceHeldRecords(root, space) {
|
|
789
|
+
const stack = new Set(Object.values(STACK_DEFINITION));
|
|
790
|
+
const byPid = new Map();
|
|
791
|
+
for (const row of serviceInstances(space)) {
|
|
792
|
+
const value = row.record.value;
|
|
793
|
+
if (!stack.has(value.definition) && value.process && observeServiceProcess(value) === "running")
|
|
794
|
+
byPid.set(value.process.pid, { definition: value.definition, instanceId: row.name });
|
|
795
|
+
}
|
|
796
|
+
return localRecords(root, space).flatMap((record) => {
|
|
797
|
+
const held = record.state === "live" && record.pid !== undefined ? byPid.get(record.pid) : undefined;
|
|
798
|
+
return held ? [{ record, ...held }] : [];
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
/** The member of `space`'s controller stack whose running process the pidfile at `path` names, by
|
|
802
|
+
* the member's own recorded process, as {@link localRecords} leaves out a record the stack owns.
|
|
803
|
+
* Read only: nothing is adopted. */
|
|
804
|
+
export function stackMemberRecord(space, path) {
|
|
805
|
+
const raw = readPidfile(path);
|
|
806
|
+
const pid = raw ? parsePid(raw) : undefined;
|
|
807
|
+
if (pid === undefined)
|
|
808
|
+
return undefined;
|
|
809
|
+
for (const definition of Object.values(STACK_DEFINITION))
|
|
810
|
+
for (const row of serviceInstances(space, definition))
|
|
811
|
+
if (row.record.value.process?.pid === pid && observeServiceProcess(row.record.value) === "running")
|
|
812
|
+
return { definition, instanceId: row.name, pid };
|
|
813
|
+
return undefined;
|
|
814
|
+
}
|
|
815
|
+
/** Remove the records under the root that front no process, `gone` and `reused` ones, and return
|
|
816
|
+
* them. Each is removed with its pin, only while its pidfile still reads as it did. */
|
|
817
|
+
export function removeStaleLocalRecords(root, space) {
|
|
818
|
+
const stale = localRecords(root, space).filter((row) => row.state !== "live");
|
|
819
|
+
for (const row of stale)
|
|
820
|
+
removePidPair(join(root, row.path), row.raw);
|
|
821
|
+
return stale;
|
|
822
|
+
}
|
|
823
|
+
/** What a stop says about a stale record it removed, or for a preview, one it would remove. */
|
|
824
|
+
export const staleRecordNotice = (row, preview = false) => `${preview ? "the stop removes" : "removed"} the stale ${row.name} record ${row.path}: ${row.state === "reused" ? `pid ${row.pid} was reused by another process` : `its process, pid ${row.pid}, is gone`}`;
|
|
472
825
|
/** How a refusal lists one record: `<name> at <path> (<note>)`. */
|
|
473
826
|
export const recordedProcessLine = (row) => `${row.name} at ${row.path} (${row.note})`;
|
|
474
827
|
/** Every local-process record under the root that may still front a process. Each descriptor's
|
|
@@ -518,28 +871,32 @@ export function recordedProcessesUnder(root, spaces) {
|
|
|
518
871
|
}
|
|
519
872
|
return found;
|
|
520
873
|
}
|
|
521
|
-
/** No member of this stack ever launched: no member row names an instance or a replacement, and
|
|
522
|
-
* stack definition in its space
|
|
523
|
-
*
|
|
874
|
+
/** No member of this stack ever launched: no member row names an instance or a replacement, and every
|
|
875
|
+
* instance record of a stack definition in its space failed before its child was spawned, as a
|
|
876
|
+
* broker start refused at an address another program holds does. No process of it runs and no
|
|
877
|
+
* broker of it wrote a store, so its journal pins nothing for the next up and a down has nothing to stop. */
|
|
524
878
|
export function stackNeverStarted(journal) {
|
|
525
879
|
return journal.members.every((row) => row.instanceId === null && row.replacement === undefined)
|
|
526
|
-
&& STACK_ROLES.every((role) => serviceInstances(journal.space, STACK_DEFINITION[role]).
|
|
880
|
+
&& STACK_ROLES.every((role) => serviceInstances(journal.space, STACK_DEFINITION[role]).every((row) => row.record.value.state === "failed" && row.record.value.process === undefined));
|
|
527
881
|
}
|
|
528
882
|
/** An observed process state that counts as stopped for a whole-stack stop. */
|
|
529
883
|
export const processGone = (state) => state === "gone" || state === "previous-boot" || state === "foreign-pid";
|
|
530
884
|
/** What stopping the stack's broker would cut off outside its recorded members refuses before the
|
|
531
|
-
* first signal: another live or unresolved service instance in the space, a legacy pidfile
|
|
532
|
-
* under the root, or another registration that names the same broker
|
|
533
|
-
* `down --preserve-state` both run it; `next` is the command to run once
|
|
534
|
-
* stopped. */
|
|
885
|
+
* first signal: another live or unresolved service instance in the space, a legacy pidfile record
|
|
886
|
+
* under the root that may front a process, or another registration that names the same broker
|
|
887
|
+
* address. Bare `down` and `down --preserve-state` both run it; `next` is the command to run once
|
|
888
|
+
* the named dependants are stopped. */
|
|
535
889
|
export function stackScopeRefusals(journal, next) {
|
|
536
890
|
const memberIds = new Set(journal.members.flatMap((row) => row.instanceId === null ? [] : [row.instanceId]));
|
|
537
891
|
const others = serviceInstances(journal.space).filter((row) => !memberIds.has(row.name) && (!processGone(observeServiceProcess(row.record.value)) || ["starting", "stopping", "unknown"].includes(row.record.value.state)));
|
|
538
892
|
if (others.length)
|
|
539
|
-
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "other service instances in this space are live or unresolved and depend on its broker; the broker was not stopped under them", { target: { space: journal.space, dependants: others.map((row) => ({ definition: row.record.value.definition, instanceId: row.name })) }, remedy: `stop ${
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
893
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "other service instances in this space are live or unresolved and depend on its broker; the broker was not stopped under them", { target: { space: journal.space, dependants: others.map((row) => ({ definition: row.record.value.definition, instanceId: row.name })) }, remedy: `stop each with ${others.map((row) => `\`cotal svc stop ${row.record.value.definition} --instance ${row.name} --space ${journal.space} --yes\``).join("; ")}, then run ${next}` });
|
|
894
|
+
// A record whose process is gone, or whose pid now runs another start, fronts nothing.
|
|
895
|
+
const legacy = localRecords(journal.root, journal.space).filter((row) => row.state === "live");
|
|
896
|
+
if (legacy.length) {
|
|
897
|
+
const lines = legacy.map(localRecordLine), checks = legacy.map((row) => row.pid === undefined ? row.path : `pid ${row.pid} at ${row.path}`);
|
|
898
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", `legacy pidfile-owned processes under this root may depend on the broker (${lines.join("; ")}); they were neither adopted nor stopped`, { target: { root: journal.root, processes: lines }, remedy: `check ${checks.join(", ")}; stop each process where it was started, or remove a record whose process is gone, then run ${next}` });
|
|
899
|
+
}
|
|
543
900
|
const sharing = loadMeshes().filter((mesh) => mesh.space !== journal.space && mesh.server === journal.server);
|
|
544
901
|
if (sharing.length)
|
|
545
902
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "another registration names this stack's exact broker address; a shared broker is not stopped in this cut", { target: { server: journal.server, spaces: sharing.map((mesh) => mesh.space) } });
|