@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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
|
|
4
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
5
|
-
import { CommandFailure, assertRecordIdentity, canonicalRoot, commandIsCotalSupervisor, isCommandFailure, maintenanceAdmitsStackWork, readMaintenanceJournal, readProcessCommand, readServiceStopRequest, resolveNativeServiceTarget,
|
|
3
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, renameSync, unlinkSync } from "node:fs";
|
|
4
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { CommandFailure, assertRecordIdentity, shellPath, boundedValue, canonicalRoot, commandIsCotalSupervisor, isCommandFailure, maintenanceAdmitsStackWork, readMaintenanceJournal, readProcessCommand, readServiceStopRequest, resolveNativeServiceTarget, loopbackListeners, processGroupMembers, processGroupOf, serviceAdapterReadiness, serviceMetadataDigest, spaceKey, serviceAdapterKernelStopPlan, serviceAdapterKernelStopResult, serviceAdapterStopPlan, serviceAdapterStopAbandonment, serviceAdapterStopRefusal, serviceAdapterStopResult, isWorkspaceTargetError, oneLine, targetErrorCode, workspaceErrorParts } from "@cotal-ai/workspace";
|
|
6
6
|
import { refuseRecordedSupervisor } from "./service-supervision.js";
|
|
7
7
|
import { serviceInstallIntents } from "./service-install-intent.js";
|
|
8
8
|
import { serviceUninstallIntents } from "./service-uninstall-intent.js";
|
|
@@ -11,9 +11,11 @@ import { selfArgv } from "./self-exec.js";
|
|
|
11
11
|
import { loadServiceAdapter, resolveServiceAdapter, sameServiceAdapterPin } from "./service-adapters.js";
|
|
12
12
|
import { serviceDefinitionStore, validateServiceDefinition } from "./service-definitions.js";
|
|
13
13
|
import { instanceProjection, observeServiceProcess, processServiceHost, requireProcessIdentity, serviceInstances, serviceInstanceStore } from "./service-instances.js";
|
|
14
|
-
import { maintenanceStackView } from "./stack-journal.js";
|
|
14
|
+
import { maintenanceStackView, STACK_DEFINITION, stackMemberRecord } from "./stack-journal.js";
|
|
15
15
|
export const PROCESS_SERVICE_CAPABILITIES = Object.freeze({ multiInstance: true, foreground: true, logs: true, install: false });
|
|
16
16
|
const delay = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
17
|
+
/** How long a launch with process readiness waits for an immediate exit before it reports the process running. */
|
|
18
|
+
const PROCESS_SETTLE_MS = 1000;
|
|
17
19
|
const gone = (state) => state === "gone" || state === "previous-boot" || state === "foreign-pid";
|
|
18
20
|
/** A record with no creation pin whose own state says no child exists: its launch failed before
|
|
19
21
|
* a process did. There is nothing to stop. */
|
|
@@ -80,14 +82,17 @@ export function retainedStopRequest(value) {
|
|
|
80
82
|
* it has removed the request and released the reservation, and the record returns to what its
|
|
81
83
|
* process shows, as after a refusal within the call. A record left `stopping` by a stopper that
|
|
82
84
|
* exited before it published a request handed the child nothing, so it also returns to what its
|
|
83
|
-
* process shows, as a stop that published nothing does within its call.
|
|
84
|
-
*
|
|
85
|
+
* process shows, as a stop that published nothing does within its call. A signal stop whose
|
|
86
|
+
* exact process still runs (see {@link resumableSignalStop}) returns to `running`. Any other record,
|
|
87
|
+
* including one whose adapter confirms less, is returned unchanged. */
|
|
85
88
|
export async function settleRetainedNativeStop(definition, row) {
|
|
86
89
|
const value = row.record.value, launch = definition.record.value.launch, retained = retainedStopRequest(value);
|
|
87
90
|
if (value.nativeStopRequired && value.process && value.state === "stopping" && !retained) {
|
|
88
91
|
const observed = observeServiceProcess(value);
|
|
89
92
|
return transition(row, { state: observed === "running" ? "running" : gone(observed) ? "failed" : "unknown", readiness: "not-checked" });
|
|
90
93
|
}
|
|
94
|
+
if (resumableSignalStop(value))
|
|
95
|
+
return transition(row, { state: "running", readiness: "not-checked" });
|
|
91
96
|
if (!retained || retained.publication !== "published" || launch.type !== "adapter" || !value.process)
|
|
92
97
|
return row;
|
|
93
98
|
const declared = resolveServiceAdapter(launch.adapter, launch.options);
|
|
@@ -108,6 +113,13 @@ export async function settleRetainedNativeStop(definition, row) {
|
|
|
108
113
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the adapter's settlement did not answer the retained request and its exact process exit; the record was kept", { target: instanceProjection(row) });
|
|
109
114
|
return transition(row, { state: "stopped", requestId: retained.requestId, readiness: "not-checked", nativeStop: result });
|
|
110
115
|
}
|
|
116
|
+
/** Whether {@link settleRetainedNativeStop} may change this record before a classification reads it:
|
|
117
|
+
* a native `stopping` record that published no request, a signal stop whose process still runs, or a
|
|
118
|
+
* published native stop, which only its adapter's receipts decide. */
|
|
119
|
+
export function retainedStopMaySettle(value) {
|
|
120
|
+
const retained = retainedStopRequest(value);
|
|
121
|
+
return value.nativeStopRequired && value.process !== undefined && value.state === "stopping" && !retained || resumableSignalStop(value) || retained?.publication === "published";
|
|
122
|
+
}
|
|
111
123
|
/** Abandon the native stop `requestId` this record retains, on an operator's explicit request. The
|
|
112
124
|
* caller holds the definition's writer lock. The adapter refuses unless no receipt settles the
|
|
113
125
|
* request and its exact process and the stopper that published it have both exited; it then removes
|
|
@@ -133,6 +145,14 @@ export async function abandonRetainedNativeStop(definition, row, requestId) {
|
|
|
133
145
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the adapter's abandonment did not retire the request of an exited process; the record was kept", { target });
|
|
134
146
|
return { row: transition(row, { state: "failed", readiness: "not-checked" }), abandonment };
|
|
135
147
|
}
|
|
148
|
+
/** A broker's kernel-exit stop or a generic process stop that its stopper left `stopping` while that
|
|
149
|
+
* exact process still runs. Such a stop records `stopping` before it signals, so a stopper cut off
|
|
150
|
+
* in between signalled nothing, and no exit was observed as its own either way. Under the
|
|
151
|
+
* definition's writer lock its stopper has exited, so the record returns to `running` and the next
|
|
152
|
+
* stop signals the process again. */
|
|
153
|
+
export function resumableSignalStop(value) {
|
|
154
|
+
return !value.nativeStopRequired && value.state === "stopping" && value.process !== undefined && observeServiceProcess(value) === "running";
|
|
155
|
+
}
|
|
136
156
|
/** A broker's kernel-exit stop or a generic process stop that its stopper left `stopping` when it
|
|
137
157
|
* exited before it observed the exit, once that exact process is gone. Only an operator abandons it. */
|
|
138
158
|
export function abandonableSignalStop(value) {
|
|
@@ -150,6 +170,26 @@ export function abandonRetainedSignalStop(row, requestId) {
|
|
|
150
170
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "the process this stop request names still runs; nothing was abandoned", { target });
|
|
151
171
|
return transition(row, { state: "failed", readiness: "not-checked" });
|
|
152
172
|
}
|
|
173
|
+
/** Record `failed`, on an operator's explicit request, a launch whose record names no process: its
|
|
174
|
+
* launcher ended after it recorded the launch and before it recorded the child. The caller holds the
|
|
175
|
+
* definition's writer lock, which that launcher held, so it has exited. A child it spawned without
|
|
176
|
+
* recording is not excluded, and nothing here looks for one. */
|
|
177
|
+
export function abandonUnresolvedLaunch(row) {
|
|
178
|
+
if (observeServiceProcess(row.record.value) !== "unresolved-launch")
|
|
179
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "this instance's launch is not unresolved: its record names a process or a settled state; nothing was abandoned", { target: instanceProjection(row) });
|
|
180
|
+
return transition(row, { state: "failed", readiness: "not-checked" });
|
|
181
|
+
}
|
|
182
|
+
/** What an interrupt records for each launch this process recorded and has not yet pinned to its child. */
|
|
183
|
+
const unpinnedLaunches = new Set();
|
|
184
|
+
/** For a command that ends itself on an interrupt: record each launch it has not yet pinned to its
|
|
185
|
+
* child. One with no spawned child is recorded `failed`. One whose child was spawned is recorded with
|
|
186
|
+
* that child's identity; when that cannot be read, it is recorded `failed` with the exit once the
|
|
187
|
+
* child has exited and `unknown` before, as a failed pin is. Without this, the record names no
|
|
188
|
+
* process, and only `down --abandon-launch` resolves it. */
|
|
189
|
+
export function settleInterruptedLaunches() {
|
|
190
|
+
for (const settle of unpinnedLaunches)
|
|
191
|
+
settle();
|
|
192
|
+
}
|
|
153
193
|
/** The refusal for a retained native stop, made before any readiness probe, stop request or record
|
|
154
194
|
* write. This command has no effect, so it is refused; only the earlier stop's outcome is unknown. A
|
|
155
195
|
* request file that does not read as this launch's own is named an unknown publication. */
|
|
@@ -182,8 +222,18 @@ export function selectServiceInstance(rows, id, allowMissing = false) {
|
|
|
182
222
|
return undefined;
|
|
183
223
|
throw new CommandFailure("refused", "TARGET_NOT_FOUND", "no instance is recorded for this service definition");
|
|
184
224
|
}
|
|
185
|
-
if (rows.length !== 1)
|
|
186
|
-
|
|
225
|
+
if (rows.length !== 1) {
|
|
226
|
+
// Each record is named with its state, and one whose process is gone with the command that
|
|
227
|
+
// clears it. A record still marked running after its process exited reads as exited.
|
|
228
|
+
const { definition, space } = rows[0].record.value;
|
|
229
|
+
const ended = (row) => gone(observeServiceProcess(row.record.value));
|
|
230
|
+
const state = (row) => ended(row) && UNSETTLED_RUN.includes(row.record.value.state) ? "exited" : row.record.value.state;
|
|
231
|
+
const clear = rows.filter(ended).map((row) => `cotal service remove ${definition} --instance ${row.name} --space ${space} --yes`);
|
|
232
|
+
throw new CommandFailure("refused", "TARGET_AMBIGUOUS", `this definition has several instance records; choose --instance with one full ID: ${rows.map((row) => row.name).join(", ")}`, {
|
|
233
|
+
target: { candidates: rows.map((row) => row.name) },
|
|
234
|
+
remedy: `pass --instance with one of ${rows.map((row) => `${row.name} (${state(row)})`).join(", ")}${clear.length ? `; clear a stopped record you no longer need with ${clear.join("; ")}` : ""}`,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
187
237
|
return rows[0];
|
|
188
238
|
}
|
|
189
239
|
function sameIncarnation(before, after) {
|
|
@@ -201,21 +251,24 @@ function executable(definition) {
|
|
|
201
251
|
if (definition.launch.type !== "process")
|
|
202
252
|
throw new CommandFailure("refused", "UNSUPPORTED", "this driver accepts process definitions, not adapter options");
|
|
203
253
|
const source = definition.launch.executable;
|
|
204
|
-
|
|
205
|
-
if (!found)
|
|
206
|
-
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the declared executable is unavailable; no instance was allocated");
|
|
207
|
-
return found;
|
|
254
|
+
return isAbsolute(source) ? source : resolve(definition.launch.cwd, source);
|
|
208
255
|
}
|
|
209
256
|
function environment(definition) {
|
|
210
257
|
const env = {};
|
|
211
258
|
for (const key of ["PATH", "HOME", "USER", "LOGNAME", "TMPDIR", "LANG", "LC_ALL", "TERM", "COLORTERM", "NO_COLOR", "FORCE_COLOR", "COTAL_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_CACHE_HOME", "XDG_RUNTIME_DIR"])
|
|
212
259
|
if (process.env[key] !== undefined)
|
|
213
260
|
env[key] = process.env[key];
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
261
|
+
// Variable names are not secrets, so a missing one is named with the child variable it feeds.
|
|
262
|
+
const missing = Object.entries(definition.envRefs ?? {}).filter(([, source]) => process.env[source] === undefined);
|
|
263
|
+
if (missing.length) {
|
|
264
|
+
const sources = missing.map(([, source]) => source);
|
|
265
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `the environment this command runs in does not set ${missing.map(([destination, source]) => `${source} (passed to the service as ${destination})`).join(", ")}; no environment value was printed and no process was launched`, {
|
|
266
|
+
target: { missing: missing.map(([destination, source]) => ({ variable: source, as: destination })) },
|
|
267
|
+
remedy: `set ${sources.join(" and ")} in the shell that runs cotal, then run the command again`,
|
|
268
|
+
});
|
|
218
269
|
}
|
|
270
|
+
for (const [destination, source] of Object.entries(definition.envRefs ?? {}))
|
|
271
|
+
env[destination] = process.env[source];
|
|
219
272
|
if (definition.credentialRef)
|
|
220
273
|
env.COTAL_CREDS = definition.credentialRef.path;
|
|
221
274
|
return env;
|
|
@@ -224,6 +277,47 @@ export function serviceLogPath(space, id, create = false) {
|
|
|
224
277
|
const dir = serviceInstanceStore(space).directory(create);
|
|
225
278
|
return dir ? join(dir, `${spaceKey(id)}.log`) : undefined;
|
|
226
279
|
}
|
|
280
|
+
/** The size at which a background launch moves the instance's log aside before it starts. */
|
|
281
|
+
const LOG_ROTATE_BYTES = 16 * 1024 * 1024;
|
|
282
|
+
/** Move a log that reached {@link LOG_ROTATE_BYTES} to `<log>.1`, replacing an earlier one, so the
|
|
283
|
+
* launch starts a fresh file. Only a start or restart rotates, so a running service's log grows
|
|
284
|
+
* until its next start. */
|
|
285
|
+
function rotateServiceLog(path) {
|
|
286
|
+
let info;
|
|
287
|
+
try {
|
|
288
|
+
info = lstatSync(path);
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
if (error.code === "ENOENT")
|
|
292
|
+
return;
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
|
|
296
|
+
throw new Error("unprotected log target");
|
|
297
|
+
if (info.size >= LOG_ROTATE_BYTES)
|
|
298
|
+
renameSync(path, `${path}.1`);
|
|
299
|
+
}
|
|
300
|
+
/** Delete the instances' logs, `<log>` and the rotated `<log>.1`, and return the paths deleted. */
|
|
301
|
+
export function removeServiceLogs(space, ids) {
|
|
302
|
+
const removed = [];
|
|
303
|
+
for (const id of ids) {
|
|
304
|
+
const path = serviceLogPath(space, id);
|
|
305
|
+
if (!path)
|
|
306
|
+
continue;
|
|
307
|
+
for (const file of [path, `${path}.1`]) {
|
|
308
|
+
try {
|
|
309
|
+
unlinkSync(file);
|
|
310
|
+
removed.push(file);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
if (error.code === "ENOENT")
|
|
314
|
+
continue;
|
|
315
|
+
throw new CommandFailure("partial", "OPERATION_PARTIAL", `the definition and its stopped instance records were removed, but the log ${file} was not deleted: ${error.message}`, { target: { space, instanceId: id }, changed: removed.map((log) => ({ kind: "service-log", path: log })), remedy: `delete ${file} yourself` });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return removed;
|
|
320
|
+
}
|
|
227
321
|
/** Both absent, or the same attempt and inventory digest. */
|
|
228
322
|
function samePreserved(a, b) {
|
|
229
323
|
return a === undefined ? b === undefined : b !== undefined && a.attemptId === b.attemptId && a.inventorySha256 === b.inventorySha256;
|
|
@@ -266,8 +360,71 @@ async function adapterCall(call, timeoutMs) {
|
|
|
266
360
|
controller.abort();
|
|
267
361
|
}
|
|
268
362
|
}
|
|
363
|
+
/** What a failed bounded readiness request saw, in words. No response body or header is kept. */
|
|
364
|
+
function httpReadinessFailure(error) {
|
|
365
|
+
const code = error?.cause?.code;
|
|
366
|
+
if (code === "ECONNREFUSED")
|
|
367
|
+
return "connection refused, so nothing listened there";
|
|
368
|
+
if (error?.name === "TimeoutError")
|
|
369
|
+
return "no answer before the request timed out";
|
|
370
|
+
return typeof code === "string" ? `the request failed with ${code}` : "the request failed";
|
|
371
|
+
}
|
|
372
|
+
/** Whether something already answers `url` before a child is launched: any HTTP answer there would
|
|
373
|
+
* then not be the new process's. A refused, failed or unanswered request is not an answer. */
|
|
374
|
+
async function readinessAddressAnswers(url) {
|
|
375
|
+
try {
|
|
376
|
+
const response = await fetch(url, { redirect: "manual", credentials: "omit", signal: AbortSignal.timeout(1000) });
|
|
377
|
+
await response.body?.cancel();
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/** The processes of this account that listen on `url`'s loopback address, each as its PID and
|
|
385
|
+
* program name. */
|
|
386
|
+
function addressHolders(url) {
|
|
387
|
+
return loopbackListeners(url).map((pid) => {
|
|
388
|
+
const command = readProcessCommand(pid);
|
|
389
|
+
return command.kind === "command" ? `${pid} (${basename(command.command.split(" ")[0])})` : String(pid);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
/** A warning for each saved service of `space`, or of those of `names`, whose HTTP readiness address
|
|
393
|
+
* still answers while none of its instances runs, as a descendant that outlived a stop, or left the
|
|
394
|
+
* service's process group, can. It names the address and the processes of this account that listen
|
|
395
|
+
* there. Saved services that cannot be read give one warning saying no address was checked. */
|
|
396
|
+
export async function readinessAddressSurvivors(space, names) {
|
|
397
|
+
const idle = [];
|
|
398
|
+
try {
|
|
399
|
+
for (const row of serviceDefinitionStore(space).list()) {
|
|
400
|
+
const { readiness } = row.record.value;
|
|
401
|
+
if (readiness.type !== "http" || (names && !names.includes(row.name)))
|
|
402
|
+
continue;
|
|
403
|
+
if (!serviceInstances(space, row.name).some((instance) => observeServiceProcess(instance.record.value) === "running"))
|
|
404
|
+
idle.push({ name: row.name, url: readiness.url });
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
// The command this reports for has already done its work, so an unreadable record is named here.
|
|
409
|
+
if (!(error instanceof CommandFailure))
|
|
410
|
+
throw error;
|
|
411
|
+
return [{ code: "SERVICE_ADDRESS_NOT_CHECKED", target: { space }, message: `the saved services could not be read (${error.message}), so no address a stopped one may still hold was checked` }];
|
|
412
|
+
}
|
|
413
|
+
const warnings = [];
|
|
414
|
+
for (const { name, url } of idle) {
|
|
415
|
+
if (!await readinessAddressAnswers(url))
|
|
416
|
+
continue;
|
|
417
|
+
const address = new URL(url).host;
|
|
418
|
+
const holders = addressHolders(url);
|
|
419
|
+
warnings.push({ code: "SERVICE_ADDRESS_HELD", target: { space, definition: name, address }, message: `something still answers ${address}, where ${name}'s HTTP readiness is checked, and no instance of ${name} runs${holders.length ? `; process ${holders.join(", ")} of this account listens there` : ""}` });
|
|
420
|
+
}
|
|
421
|
+
return warnings;
|
|
422
|
+
}
|
|
269
423
|
export async function serviceReadiness(row, definition, adapter) {
|
|
270
424
|
const deadline = Date.now() + definition.readiness.timeoutMs;
|
|
425
|
+
// The last HTTP readiness observation, named when the deadline passes first: the status the
|
|
426
|
+
// service answered with, or what a failed request saw.
|
|
427
|
+
let seen;
|
|
271
428
|
do {
|
|
272
429
|
const state = observeServiceProcess(row.record.value);
|
|
273
430
|
if (gone(state))
|
|
@@ -304,11 +461,27 @@ export async function serviceReadiness(row, definition, adapter) {
|
|
|
304
461
|
await response.body?.cancel();
|
|
305
462
|
if (response.status === definition.readiness.expectedStatus && observeServiceProcess(row.record.value) === "running")
|
|
306
463
|
return transition(row, { state: "running", readiness: "http-reachable" });
|
|
464
|
+
seen = { status: response.status };
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
// A failed bounded HTTP read is not proof of process death or listener ownership.
|
|
468
|
+
seen = { failure: httpReadinessFailure(error) };
|
|
307
469
|
}
|
|
308
|
-
catch { /* A failed bounded HTTP read is not proof of process death or listener ownership. */ }
|
|
309
470
|
await delay(Math.min(100, Math.max(0, deadline - Date.now())));
|
|
310
471
|
} while (Date.now() < deadline);
|
|
311
472
|
const uncertain = transition(row, { state: "unknown", readiness: "not-checked" });
|
|
473
|
+
if (definition.readiness.type === "http") {
|
|
474
|
+
// The address alone is named: a definition's URL is kept out of reports, and its path may carry a token.
|
|
475
|
+
const { definition: name, instanceId, space } = uncertain.record.value, host = new URL(definition.readiness.url).host;
|
|
476
|
+
const inspect = `read its output with cotal service logs ${name} --instance ${instanceId} --space ${space}, and stop it with cotal service stop ${name} --instance ${instanceId} --space ${space} --yes before another start`;
|
|
477
|
+
// A service that answered with another status said it is not ready, so the start failed.
|
|
478
|
+
if (seen && "status" in seen)
|
|
479
|
+
throw new CommandFailure("failed", "OPERATION_FAILED", `the owned process answered its HTTP readiness check on ${host} with status ${seen.status}, not ${definition.readiness.expectedStatus}, until its ${definition.readiness.timeoutMs} ms deadline passed. The process was left running, not relaunched or killed`, { target: instanceProjection(uncertain), remedy: inspect });
|
|
480
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", `the owned process did not answer its HTTP readiness check on ${host} with status ${definition.readiness.expectedStatus} within ${definition.readiness.timeoutMs} ms; the last check saw ${seen?.failure ?? "no completed request"}. The process was left running, not relaunched or killed`, {
|
|
481
|
+
target: instanceProjection(uncertain),
|
|
482
|
+
remedy: `${inspect}; cotal service show ${name} --space ${space} shows the readiness deadline it missed`,
|
|
483
|
+
});
|
|
484
|
+
}
|
|
312
485
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the owned process did not establish its declared readiness before the deadline; it was not relaunched or automatically killed", { target: instanceProjection(uncertain), remedy: "inspect service status/logs with the original full instance ID before another start" });
|
|
313
486
|
}
|
|
314
487
|
/** A target the adapter could not resolve, as the refusal its code and remedy name. */
|
|
@@ -318,7 +491,7 @@ function targetRefusal(error) {
|
|
|
318
491
|
}
|
|
319
492
|
export function prepareProcessService(definition) {
|
|
320
493
|
processServiceHost();
|
|
321
|
-
validateServiceDefinition(definition.record.value, definition.record.value.space);
|
|
494
|
+
validateServiceDefinition(definition.record.value, definition.record.value.space, true, false, definition.name);
|
|
322
495
|
const launch = definition.record.value.launch;
|
|
323
496
|
const program = launch.type === "process" ? executable(definition.record.value) : undefined;
|
|
324
497
|
if (launch.type === "process" && commandIsCotalSupervisor([program, ...launch.args].join(" ")))
|
|
@@ -350,6 +523,17 @@ export function assertRestartAdmitted(definition) {
|
|
|
350
523
|
if (!maintenanceAdmitsStackWork(root, value.space, server, maintenanceStackView(root, value.space)))
|
|
351
524
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "this root retains a maintenance or recovery attempt, under which the replacement start would be refused; nothing was stopped", { target: { space: value.space, definition: definition.name } });
|
|
352
525
|
}
|
|
526
|
+
/** The refusal for a start that selects an instance of an earlier revision, as one a definition moved
|
|
527
|
+
* aside and added again leaves. Nothing adopts or removes it: an added service's Next stops it if it
|
|
528
|
+
* still runs, then forgets its record, so the next start launches the current revision. A stack
|
|
529
|
+
* member's records stay with its stack, so its refusal names no command. */
|
|
530
|
+
function staleRevisionInstance(definition, selected) {
|
|
531
|
+
const { name } = definition, { space } = definition.record.value, id = selected.name;
|
|
532
|
+
const forget = `forget its record with cotal service remove ${name} --instance ${id} --space ${space} --yes, then run cotal service start ${name} --space ${space} again`;
|
|
533
|
+
const remedy = Object.values(STACK_DEFINITION).includes(name) ? undefined
|
|
534
|
+
: gone(observeServiceProcess(selected.record.value)) ? forget : `stop it with cotal service stop ${name} --instance ${id} --space ${space} --yes, ${forget}`;
|
|
535
|
+
return new CommandFailure("refused", "CONFLICT", "this instance belongs to another definition revision; it was not adopted", { target: instanceProjection(selected), remedy });
|
|
536
|
+
}
|
|
353
537
|
export async function startProcessService(definition, options, held) {
|
|
354
538
|
const value = definition.record.value;
|
|
355
539
|
if (options.attempt && (value.launch.type !== "adapter" || options.foreground))
|
|
@@ -370,7 +554,7 @@ export async function startProcessService(definition, options, held) {
|
|
|
370
554
|
if (declaredAdapter && (options.newInstance && !declaredAdapter.declaration.capabilities.multiInstance || options.foreground && !declaredAdapter.declaration.capabilities.foreground))
|
|
371
555
|
throw new CommandFailure("refused", "UNSUPPORTED", "the selected adapter does not declare this multi-instance or foreground capability; no launch was allocated");
|
|
372
556
|
const hold = held ?? serviceDefinitionStore(value.space).pin(definition);
|
|
373
|
-
let child;
|
|
557
|
+
let child, unpinned;
|
|
374
558
|
try {
|
|
375
559
|
assertNoServiceUnitAttempts(value.space, definition.name);
|
|
376
560
|
const rows = serviceInstances(value.space, definition.name);
|
|
@@ -391,7 +575,7 @@ export async function startProcessService(definition, options, held) {
|
|
|
391
575
|
// A crash or failed start is settled from its own evidence before the relaunch checks below.
|
|
392
576
|
const selected = chosen && settleExitedInstance(chosen);
|
|
393
577
|
if (selected && selected.record.value.definitionRevision !== definition.record.revision)
|
|
394
|
-
throw
|
|
578
|
+
throw staleRevisionInstance(definition, selected);
|
|
395
579
|
if (selected && !sameServiceAdapterPin(selected.record.value.adapter, declaredAdapter?.pin))
|
|
396
580
|
throw new CommandFailure("refused", "CONFLICT", "the recorded instance pins a different adapter declaration or package version; stop and explicitly remove its retained records before choosing a different provider", { target: instanceProjection(selected) });
|
|
397
581
|
if (selected) {
|
|
@@ -413,12 +597,44 @@ export async function startProcessService(definition, options, held) {
|
|
|
413
597
|
if (declaredAdapter?.declaration.stop === "kernel-exit" && selected.record.value.process && !settledExit && !(selected.record.value.state === "stopped" && selected.record.value.kernelStop))
|
|
414
598
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the original broker process disappeared during its retained stop request, without this controller's recorded exact-exit stop; no replacement listener was launched over its store", { target: instanceProjection(selected), remedy: `inspect the original request with cotal service status ${definition.name} --instance ${selected.name} --space ${value.space}` });
|
|
415
599
|
}
|
|
600
|
+
// HTTP readiness proves only that something answers, so an address that answers before the
|
|
601
|
+
// launch could pass a child that never listened, such as a second instance on the first one's port.
|
|
602
|
+
if (value.readiness.type === "http" && await readinessAddressAnswers(value.readiness.url)) {
|
|
603
|
+
const host = new URL(value.readiness.url).host, live = rows.find((row) => observeServiceProcess(row.record.value) === "running");
|
|
604
|
+
// Another listener, such as a server that left a stopped instance's process group, is named as
|
|
605
|
+
// SERVICE_ADDRESS_HELD names it. It is not signalled: no instance of this service owns it.
|
|
606
|
+
const holders = live ? [] : addressHolders(value.readiness.url);
|
|
607
|
+
throw new CommandFailure("refused", "CONFLICT", `something already answers ${host}, where ${definition.name}'s HTTP readiness is checked, so a new process's readiness could not be told from it${holders.length ? `; process ${holders.join(", ")} of this account listens there` : ""}; nothing was launched`, {
|
|
608
|
+
target: { space: value.space, definition: definition.name, address: host, ...(live ? { instanceId: live.name } : {}) },
|
|
609
|
+
remedy: live ? `instance ${live.name} of ${definition.name} answers there; give another instance its own port, or stop that one with cotal service stop ${definition.name} --instance ${live.name} --space ${value.space} --yes first`
|
|
610
|
+
: holders.length ? `stop process ${holders.join(", ")}, which is not an instance of ${definition.name}, then run the command again` : `stop what listens on ${host}, then run the command again`,
|
|
611
|
+
});
|
|
612
|
+
}
|
|
416
613
|
hold.check();
|
|
417
614
|
const now = new Date().toISOString(), id = options.brokerInstance?.instanceId ?? options.replacement?.instanceId ?? selected?.name ?? randomUUID(), launchRequestId = options.brokerInstance?.launchRequestId ?? options.replacement?.launchRequestId ?? randomUUID();
|
|
418
615
|
const instance = { schemaVersion: 1, instanceId: id, definition: definition.name, definitionRevision: definition.record.revision, space: value.space, host: processServiceHost(), requestId: launchRequestId, launchRequestId, state: "starting", launcher, readiness: "not-checked", supervisor: "none", ...(options.attempt ? { attempt: { attemptId: options.attempt.attemptId } } : {}), ...(declaredAdapter ? { adapter: declaredAdapter.pin, ...(declaredAdapter.declaration.stop === "native" ? { nativeStopRequired: true } : declaredAdapter.declaration.stop === "kernel-exit" ? { kernelStopRequired: true } : {}) } : {}), foreground: options.foreground === true, createdAt: selected?.record.value.createdAt ?? now, updatedAt: now };
|
|
419
616
|
const store = serviceInstanceStore(value.space);
|
|
420
617
|
store.commit(id, selected, instance);
|
|
421
618
|
let row = store.read(id);
|
|
619
|
+
// Until the child's identity is recorded, an interrupt records this launch on its way out.
|
|
620
|
+
unpinned = () => {
|
|
621
|
+
if (child?.pid === undefined) {
|
|
622
|
+
row = transition(row, { state: "failed", readiness: "not-checked" });
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
let identity;
|
|
626
|
+
try {
|
|
627
|
+
identity = requireProcessIdentity(child.pid);
|
|
628
|
+
}
|
|
629
|
+
catch {
|
|
630
|
+
identity = undefined;
|
|
631
|
+
}
|
|
632
|
+
row = transition(row, identity ? { process: identity } : { state: exited ? "failed" : "unknown", ...(exited ? { exit: { code: exitCode, signal: exitSignal } } : {}) });
|
|
633
|
+
};
|
|
634
|
+
unpinnedLaunches.add(unpinned);
|
|
635
|
+
// Smoke only: hold a recorded launch before its child exists, so a signal can land in that window.
|
|
636
|
+
if (process.env.COTAL_SMOKE_HOLD_AFTER_LAUNCH_RECORD === "1")
|
|
637
|
+
await delay(60_000);
|
|
422
638
|
let adapter;
|
|
423
639
|
let launch;
|
|
424
640
|
try {
|
|
@@ -431,7 +647,7 @@ export async function startProcessService(definition, options, held) {
|
|
|
431
647
|
const provider = await loadServiceAdapter(declaredAdapter, value.launch.options);
|
|
432
648
|
hold.check();
|
|
433
649
|
const plan = await adapterCall(() => provider.build(context), Math.min(10000, value.readiness.timeoutMs));
|
|
434
|
-
const validated = validateServiceDefinition({ ...value, launch: { type: "process", ...plan }, readiness: { type: "process", timeoutMs: value.readiness.timeoutMs } }, value.space);
|
|
650
|
+
const validated = validateServiceDefinition({ ...value, launch: { type: "process", ...plan }, readiness: { type: "process", timeoutMs: value.readiness.timeoutMs } }, value.space, true, true);
|
|
435
651
|
if (validated.launch.type !== "process")
|
|
436
652
|
throw new Error("invalid adapter launch plan");
|
|
437
653
|
const executablePath = executable(validated);
|
|
@@ -447,22 +663,34 @@ export async function startProcessService(definition, options, held) {
|
|
|
447
663
|
// No child is spawned above this point, so this incarnation has no process: the record is
|
|
448
664
|
// failed either way. Only the provider's own work stays unattributed on an unknown error.
|
|
449
665
|
row = transition(row, { state: "failed", readiness: "not-checked" });
|
|
450
|
-
if (failure?.outcome === "refused")
|
|
451
|
-
|
|
666
|
+
if (failure?.outcome === "refused") {
|
|
667
|
+
// A record the adapter refused on, whose process a member of this space's stack runs, is
|
|
668
|
+
// named with that member, as `up` names a service it does not replace.
|
|
669
|
+
const path = failure.target?.path;
|
|
670
|
+
const member = typeof path === "string" ? stackMemberRecord(value.space, path) : undefined;
|
|
671
|
+
throw new CommandFailure("refused", failure.code, member
|
|
672
|
+
? `service preparation was refused before a child launch: the ${member.definition} member of this space's controller stack runs the process recorded at ${path} (pid ${member.pid}, instance ${member.instanceId}), so ${definition.name} does not start beside it`
|
|
673
|
+
: `service preparation was refused before a child launch: ${failure.message}`, { target: instanceProjection(row), native: { code: failure.code, outcome: failure.outcome, detail: failure.message },
|
|
674
|
+
remedy: member ? `stop it with \`cotal down ${member.definition} --instance ${member.instanceId} --space ${value.space} --yes\`, then run \`cotal service start ${definition.name} --space ${value.space}\` again` : failure.remedy });
|
|
675
|
+
}
|
|
452
676
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "service preparation did not establish an accepted direct-child launch plan; no child was launched, and no provider or launch was retried", { target: instanceProjection(row) });
|
|
453
677
|
}
|
|
454
678
|
const path = serviceLogPath(value.space, id, true);
|
|
455
679
|
let log;
|
|
680
|
+
// Where this launch's own log lines start, so a failure quotes this launch and not an earlier one.
|
|
681
|
+
let logFrom;
|
|
456
682
|
let exitCode = null, exitSignal = null;
|
|
457
683
|
let exited = false;
|
|
458
684
|
let done;
|
|
459
685
|
const exit = new Promise((resolve) => { done = resolve; });
|
|
460
686
|
try {
|
|
461
687
|
if (!options.foreground) {
|
|
688
|
+
rotateServiceLog(path);
|
|
462
689
|
log = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW | constants.O_NONBLOCK, 0o600);
|
|
463
690
|
const info = fstatSync(log);
|
|
464
691
|
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
|
|
465
692
|
throw new Error("unprotected log target");
|
|
693
|
+
logFrom = info.size;
|
|
466
694
|
}
|
|
467
695
|
child = spawn(launch.program, [...launch.args], { cwd: launch.cwd, env, shell: false, detached: !options.foreground, stdio: options.foreground ? "inherit" : ["ignore", log, log] });
|
|
468
696
|
if (!options.foreground)
|
|
@@ -492,21 +720,29 @@ export async function startProcessService(definition, options, held) {
|
|
|
492
720
|
throw new CommandFailure(exited ? "failed" : "unknown", exited ? "OPERATION_FAILED" : "OPERATION_UNKNOWN", "the child could not be creation-pinned; its native child handle was asked to exit, and no replacement was launched", { target: instanceProjection(row) });
|
|
493
721
|
}
|
|
494
722
|
row = transition(row, { process: identity });
|
|
723
|
+
unpinnedLaunches.delete(unpinned);
|
|
724
|
+
// A process that exits at once never ran: process readiness first gives it a moment to do so,
|
|
725
|
+
// and that exit is then settled below with the code this parent observed.
|
|
726
|
+
if (value.readiness.type === "process")
|
|
727
|
+
await Promise.race([exit, delay(Math.min(PROCESS_SETTLE_MS, value.readiness.timeoutMs))]);
|
|
495
728
|
let running;
|
|
496
729
|
try {
|
|
497
730
|
running = await serviceReadiness(row, value, adapter);
|
|
498
731
|
}
|
|
499
732
|
catch (error) {
|
|
500
733
|
// Only an exit of the pinned child itself is settled here, with the exit this parent observed.
|
|
501
|
-
if (!isCommandFailure(error) || error.code !== "OPERATION_FAILED")
|
|
734
|
+
if (!isCommandFailure(error) || error.code !== "OPERATION_FAILED" || observeServiceProcess(row.record.value) === "running")
|
|
502
735
|
throw error;
|
|
503
736
|
await Promise.race([exit, delay(1000)]);
|
|
504
737
|
const failed = transition(row, { state: "failed", readiness: "not-checked", ...(exited ? { exit: { code: exitCode, signal: exitSignal } } : {}) });
|
|
505
|
-
|
|
738
|
+
const last = logFrom === undefined ? undefined : lastLoggedLine(path, logFrom);
|
|
739
|
+
throw new CommandFailure("failed", "OPERATION_FAILED", `the owned service process exited before readiness was established${exited ? ` (exit code ${exitCode ?? "none"}, signal ${exitSignal ?? "none"})` : ""}; ${last ? `the last line it logged is: ${last}` : "its log records the cause"}`, { target: instanceProjection(failed), remedy: `read its log with cotal service logs ${definition.name} --instance ${id} --space ${value.space}` });
|
|
506
740
|
}
|
|
507
741
|
return { instance: running, noOp: false, child, exit: { done: exit, observed: () => exited, result: () => ({ code: exitCode, signal: exitSignal }) } };
|
|
508
742
|
}
|
|
509
743
|
finally {
|
|
744
|
+
if (unpinned)
|
|
745
|
+
unpinnedLaunches.delete(unpinned);
|
|
510
746
|
if (!held)
|
|
511
747
|
hold.release();
|
|
512
748
|
}
|
|
@@ -601,6 +837,8 @@ export function preflightProcessServiceStop(definition, selected) {
|
|
|
601
837
|
if (command.kind !== "command" || commandIsCotalSupervisor(command.command))
|
|
602
838
|
throw new CommandFailure("refused", "UNSUPPORTED", "a selected process has an unreadable or manager-supervisor role; no generic set stop bypassed its native impact policy");
|
|
603
839
|
}
|
|
840
|
+
/** How long a process stop waits after SIGTERM before it sends SIGKILL. */
|
|
841
|
+
export const PROCESS_STOP_GRACE_MS = 15_000;
|
|
604
842
|
/** Only the stored creation-pinned process is signalled. Every escalation rechecks its identity. */
|
|
605
843
|
export async function stopProcessService(definition, selected, held, native, kernel) {
|
|
606
844
|
const hold = held ?? serviceDefinitionStore(definition.record.value.space).pin(definition);
|
|
@@ -681,10 +919,28 @@ export async function stopProcessService(definition, selected, held, native, ker
|
|
|
681
919
|
// The receipt names the last signal this call itself delivered to the pinned process. A process
|
|
682
920
|
// that was already gone before any delivery gets no receipt: absence is not a stop.
|
|
683
921
|
let delivered;
|
|
922
|
+
// A background start leads its own process group, so the stop signals that group and waits for
|
|
923
|
+
// it to empty: a descendant such as a backgrounded server goes with the process. A foreground
|
|
924
|
+
// start shares the command's group and is signalled alone. A group ID is not reused while a
|
|
925
|
+
// member lives, so after its leader exits the group is signalled only while members remain.
|
|
926
|
+
const pid = row.record.value.process.pid;
|
|
927
|
+
let group = false;
|
|
928
|
+
const members = () => (group ? processGroupMembers(pid) : []);
|
|
684
929
|
const signal = (name) => {
|
|
685
930
|
const state = observeServiceProcess(row.record.value);
|
|
686
|
-
if (gone(state))
|
|
931
|
+
if (gone(state)) {
|
|
932
|
+
if (!members().length)
|
|
933
|
+
return;
|
|
934
|
+
try {
|
|
935
|
+
process.kill(-pid, name);
|
|
936
|
+
delivered = name;
|
|
937
|
+
}
|
|
938
|
+
catch (error) {
|
|
939
|
+
if (error.code !== "ESRCH")
|
|
940
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the signal to the service's remaining process group was not confirmed; its record was retained", { target: instanceProjection(row) });
|
|
941
|
+
}
|
|
687
942
|
return;
|
|
943
|
+
}
|
|
688
944
|
if (state !== "running")
|
|
689
945
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "service ownership became uncertain before signalling; its record was retained", { target: instanceProjection(row) });
|
|
690
946
|
const role = readProcessCommand(row.record.value.process.pid);
|
|
@@ -693,8 +949,9 @@ export async function stopProcessService(definition, selected, held, native, ker
|
|
|
693
949
|
const identity = assertRecordIdentity(row.record.value.process);
|
|
694
950
|
if (identity.kind !== "match")
|
|
695
951
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the exact process incarnation changed before a signal; no successor was signalled", { target: instanceProjection(row) });
|
|
952
|
+
group ||= processGroupOf(pid) === pid;
|
|
696
953
|
try {
|
|
697
|
-
process.kill(
|
|
954
|
+
process.kill(group ? -pid : pid, name);
|
|
698
955
|
delivered = name;
|
|
699
956
|
}
|
|
700
957
|
catch (error) {
|
|
@@ -703,20 +960,20 @@ export async function stopProcessService(definition, selected, held, native, ker
|
|
|
703
960
|
}
|
|
704
961
|
};
|
|
705
962
|
signal("SIGTERM");
|
|
706
|
-
for (const [timeout, escalation] of [[
|
|
963
|
+
for (const [timeout, escalation] of [[PROCESS_STOP_GRACE_MS, "SIGKILL"], [3000, undefined]]) {
|
|
707
964
|
const deadline = Date.now() + timeout;
|
|
708
965
|
while (Date.now() < deadline) {
|
|
709
966
|
const state = observeServiceProcess(row.record.value);
|
|
710
|
-
if (gone(state))
|
|
967
|
+
if (gone(state) && !members().length)
|
|
711
968
|
return { instance: transition(row, { state: "stopped", readiness: "not-checked", ...(delivered ? { processStop: { kind: "process-exit", requestId: row.record.value.requestId, process: { ...row.record.value.process }, signal: delivered, observedAt: new Date().toISOString() } } : {}) }), noOp: false };
|
|
712
|
-
if (state !== "running")
|
|
969
|
+
if (!gone(state) && state !== "running")
|
|
713
970
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the service exit could not be established; its identity and stop receipt were retained", { target: instanceProjection(row) });
|
|
714
971
|
await delay(100);
|
|
715
972
|
}
|
|
716
973
|
if (escalation)
|
|
717
974
|
signal(escalation);
|
|
718
975
|
}
|
|
719
|
-
throw new CommandFailure("unknown", "OPERATION_UNKNOWN",
|
|
976
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", `the selected service process${members().length ? ` group, with process ${members().join(", ")},` : ""} did not confirm exit; its record was retained and no restart was attempted`, { target: instanceProjection(row) });
|
|
720
977
|
}
|
|
721
978
|
finally {
|
|
722
979
|
if (!held)
|
|
@@ -794,22 +1051,25 @@ export function assertNoServiceUnitAttempts(space, name) {
|
|
|
794
1051
|
if (pending.length || actions.length)
|
|
795
1052
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a retained native installation, removal or unit action names this definition; no direct process effect was substituted", { target: { space, name, attempts: [...pending, ...actions].map((row) => ({ instanceId: row.name, attemptId: row.record.value.attemptId })) } });
|
|
796
1053
|
}
|
|
797
|
-
export function removableServiceInstances(space, name) {
|
|
798
|
-
const
|
|
1054
|
+
export function removableServiceInstances(space, name, instanceId) {
|
|
1055
|
+
const named = (row) => instanceId === undefined || row.name === instanceId;
|
|
1056
|
+
const pending = [...serviceInstallIntents(space), ...serviceUninstallIntents(space)].filter((row) => row.record.value.definition === name && named(row));
|
|
799
1057
|
if (pending.length)
|
|
800
1058
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service remove cannot discard a definition while an installation or removal attempt may still own a unit, private store or enable link", { target: { space, name, attempts: pending.map((row) => ({ instanceId: row.name, attemptId: row.record.value.attemptId, step: row.record.value.step, position: row.record.value.position })) }, remedy: "inspect and reconcile every retained native unit attempt before removing this definition" });
|
|
801
1059
|
const nativeActions = serviceUnitActionStore(space).list();
|
|
802
1060
|
if (nativeActions.some((row) => row.name !== row.record.value.instanceId))
|
|
803
1061
|
throw new CommandFailure("refused", "SCHEMA_INVALID", "a native action filename differs from its full instance ID; no definition was removed");
|
|
804
|
-
const actions = nativeActions.filter((row) => row.record.value.definition === name);
|
|
1062
|
+
const actions = nativeActions.filter((row) => row.record.value.definition === name && named(row));
|
|
805
1063
|
if (actions.length)
|
|
806
1064
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service remove cannot discard a definition while an exact native action is retained", { target: { space, name, attempts: actions.map((row) => ({ instanceId: row.name, attemptId: row.record.value.attemptId, operation: row.record.value.operation, position: row.record.value.position })) } });
|
|
807
|
-
const rows = serviceInstances(space, name);
|
|
1065
|
+
const rows = serviceInstances(space, name).filter(named);
|
|
1066
|
+
if (instanceId !== undefined && !rows.length)
|
|
1067
|
+
throw new CommandFailure("refused", "TARGET_NOT_FOUND", "the full instance ID does not belong to this selected definition and space", { target: { space, name, instanceId } });
|
|
808
1068
|
for (const row of rows)
|
|
809
1069
|
refuseRecordedSupervisor(row.record.value, "remove");
|
|
810
1070
|
for (const row of rows)
|
|
811
1071
|
if (!gone(observeServiceProcess(row.record.value)))
|
|
812
|
-
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service remove requires every recorded owned instance stopped and its supervisor uninstalled", { target: instanceProjection(row), remedy: `use cotal service stop ${name} --instance ${row.name} before removing its definition` });
|
|
1072
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service remove requires every recorded owned instance stopped and its supervisor uninstalled", { target: instanceProjection(row), remedy: `use cotal service stop ${name} --instance ${row.name} before removing ${instanceId === undefined ? "its definition" : "its record"}` });
|
|
813
1073
|
// A settled exit is a record of evidence, not an unknown request. An unsettled one is settled by
|
|
814
1074
|
// the named stop, which signals nothing when the process is already gone.
|
|
815
1075
|
const settle = (row) => row.record.value.state === "stopping" || retainedStopRequest(row.record.value) ? { remedy: `inspect the original request with cotal service status ${name} --instance ${row.name} --space ${space}` }
|
|
@@ -822,7 +1082,21 @@ export function removableServiceInstances(space, name) {
|
|
|
822
1082
|
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker has no recorded exact-exit stop from this controller; its launch cannot be forgotten merely because the process disappeared", { target: instanceProjection(row), ...settle(row) });
|
|
823
1083
|
return rows;
|
|
824
1084
|
}
|
|
825
|
-
/**
|
|
1085
|
+
/** Forget one stopped instance record of a kept definition, under the definition writer lock and
|
|
1086
|
+
* after the checks `service remove` makes for each record. Its logs stay. */
|
|
1087
|
+
export function removeStoppedInstanceRecord(definition, instanceId) {
|
|
1088
|
+
const space = definition.record.value.space;
|
|
1089
|
+
const hold = serviceDefinitionStore(space).pin(definition);
|
|
1090
|
+
try {
|
|
1091
|
+
const [row] = removableServiceInstances(space, definition.name, instanceId);
|
|
1092
|
+
serviceInstanceStore(space).commit(row.name, row, undefined);
|
|
1093
|
+
}
|
|
1094
|
+
finally {
|
|
1095
|
+
hold.release();
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
/** Called under the definition writer lock, after stopped/host/supervisor checks for every row.
|
|
1099
|
+
* Returns the full IDs whose records it removed. */
|
|
826
1100
|
export function removeStoppedInstanceRecords(space, name) {
|
|
827
1101
|
const rows = removableServiceInstances(space, name), removed = [];
|
|
828
1102
|
try {
|
|
@@ -836,19 +1110,34 @@ export function removeStoppedInstanceRecords(space, name) {
|
|
|
836
1110
|
throw error;
|
|
837
1111
|
throw new CommandFailure("partial", "OPERATION_PARTIAL", "some stopped instance records were removed, but the definition was kept after another record changed", { target: { space, name }, changed: removed.map((instanceId) => ({ kind: "stopped-instance-record", instanceId })), remedy: "inspect the remaining records before another removal; no process was signalled and logs were retained" });
|
|
838
1112
|
}
|
|
1113
|
+
return removed;
|
|
839
1114
|
}
|
|
1115
|
+
/** The most a finite tail reads back from the end of a log, the size at which a start rotates it. */
|
|
1116
|
+
const LOG_TAIL_BYTES = LOG_ROTATE_BYTES;
|
|
840
1117
|
/** Read only bounded regular-file bytes; log data is not promised to be secret-redacted. */
|
|
841
1118
|
export function readServiceLog(space, id, tail) {
|
|
842
1119
|
const path = serviceLogPath(space, id);
|
|
843
1120
|
if (!path)
|
|
844
1121
|
return { lines: [], omittedBytes: 0, path: null };
|
|
1122
|
+
return readOwnedLogTail(path, tail);
|
|
1123
|
+
}
|
|
1124
|
+
/** The refusal for a log this account cannot open, with the step that gives its owner read and write back. */
|
|
1125
|
+
function unreadableLog(path, code) {
|
|
1126
|
+
return new CommandFailure("refused", "PERMISSION_DENIED", `the log ${path} cannot be read by this account (${code}); nothing was read or changed`, { target: { path }, remedy: `make it readable by you, for example with chmod u+rw ${shellPath(path)}` });
|
|
1127
|
+
}
|
|
1128
|
+
/** The last `tail` lines of an owned private log file, from at most its last 1 MiB. A log this
|
|
1129
|
+
* account cannot read is refused with the step that gives its owner read and write back. */
|
|
1130
|
+
export function readOwnedLogTail(path, tail) {
|
|
845
1131
|
let fd;
|
|
846
1132
|
try {
|
|
847
1133
|
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
848
1134
|
}
|
|
849
1135
|
catch (error) {
|
|
850
|
-
|
|
1136
|
+
const code = error.code;
|
|
1137
|
+
if (code === "ENOENT")
|
|
851
1138
|
return { lines: [], omittedBytes: 0, path };
|
|
1139
|
+
if (code === "EACCES" || code === "EPERM")
|
|
1140
|
+
throw unreadableLog(path, code);
|
|
852
1141
|
throw error;
|
|
853
1142
|
}
|
|
854
1143
|
try {
|
|
@@ -857,16 +1146,28 @@ export function readServiceLog(space, id, tail) {
|
|
|
857
1146
|
throw new CommandFailure("refused", "UNSUPPORTED", "this log's native file coordinates cannot be represented safely; no approximate byte offsets were reported");
|
|
858
1147
|
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
|
|
859
1148
|
throw new CommandFailure("refused", "PERMISSION_DENIED", "the service log is not an owned private regular file");
|
|
860
|
-
|
|
861
|
-
const
|
|
862
|
-
let
|
|
863
|
-
while (
|
|
864
|
-
const
|
|
865
|
-
|
|
1149
|
+
// Read back 1 MiB at a time until the bytes hold `tail` whole lines, the file's start or the bound.
|
|
1150
|
+
const limit = Math.min(info.size, LOG_TAIL_BYTES), chunks = [];
|
|
1151
|
+
let start = info.size, newlines = 0;
|
|
1152
|
+
while (info.size - start < limit && (start === info.size || newlines < tail)) {
|
|
1153
|
+
const length = Math.min(1024 * 1024, limit - (info.size - start)), chunk = Buffer.alloc(length);
|
|
1154
|
+
let offset = 0;
|
|
1155
|
+
while (offset < length) {
|
|
1156
|
+
const count = readSync(fd, chunk, offset, length - offset, start - length + offset);
|
|
1157
|
+
if (!count)
|
|
1158
|
+
break;
|
|
1159
|
+
offset += count;
|
|
1160
|
+
}
|
|
1161
|
+
if (offset < length)
|
|
866
1162
|
break;
|
|
867
|
-
|
|
1163
|
+
chunks.unshift(chunk);
|
|
1164
|
+
start -= length;
|
|
1165
|
+
for (let at = chunk.indexOf(10); at !== -1; at = chunk.indexOf(10, at + 1))
|
|
1166
|
+
newlines++;
|
|
1167
|
+
if (start + length === info.size && chunk[length - 1] === 10)
|
|
1168
|
+
newlines--;
|
|
868
1169
|
}
|
|
869
|
-
let text =
|
|
1170
|
+
let text = Buffer.concat(chunks).toString("utf8");
|
|
870
1171
|
if (start)
|
|
871
1172
|
text = text.includes("\n") ? text.slice(text.indexOf("\n") + 1) : "";
|
|
872
1173
|
const all = text.replace(/\n$/, "").split("\n");
|
|
@@ -876,7 +1177,40 @@ export function readServiceLog(space, id, tail) {
|
|
|
876
1177
|
closeSync(fd);
|
|
877
1178
|
}
|
|
878
1179
|
}
|
|
879
|
-
/**
|
|
1180
|
+
/** The last line an owned private log holds past byte `from`, as one bounded line of operator output,
|
|
1181
|
+
* or undefined when nothing was logged there or the log cannot be read as an owned file. */
|
|
1182
|
+
function lastLoggedLine(path, from) {
|
|
1183
|
+
let fd;
|
|
1184
|
+
try {
|
|
1185
|
+
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
1186
|
+
}
|
|
1187
|
+
catch {
|
|
1188
|
+
return undefined;
|
|
1189
|
+
}
|
|
1190
|
+
try {
|
|
1191
|
+
const info = fstatSync(fd);
|
|
1192
|
+
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0 || info.size <= from)
|
|
1193
|
+
return undefined;
|
|
1194
|
+
const length = Math.min(info.size - from, 8192), bytes = Buffer.alloc(length);
|
|
1195
|
+
let read = 0;
|
|
1196
|
+
while (read < length) {
|
|
1197
|
+
const count = readSync(fd, bytes, read, length - read, info.size - length + read);
|
|
1198
|
+
if (!count)
|
|
1199
|
+
break;
|
|
1200
|
+
read += count;
|
|
1201
|
+
}
|
|
1202
|
+
const line = bytes.subarray(0, read).toString("utf8").split("\n").map((text) => text.trim()).filter(Boolean).pop();
|
|
1203
|
+
return line ? oneLine(boundedValue(line, 400)) : undefined;
|
|
1204
|
+
}
|
|
1205
|
+
catch {
|
|
1206
|
+
return undefined;
|
|
1207
|
+
}
|
|
1208
|
+
finally {
|
|
1209
|
+
closeSync(fd);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
/** One bounded raw log slice. File identity and byte offsets are local file facts, not global sequences.
|
|
1213
|
+
* A log this account cannot read is refused as `readOwnedLogTail` refuses it. */
|
|
880
1214
|
export function serviceLogSlice(space, id, position, tail) {
|
|
881
1215
|
const path = serviceLogPath(space, id);
|
|
882
1216
|
if (!path)
|
|
@@ -886,8 +1220,11 @@ export function serviceLogSlice(space, id, position, tail) {
|
|
|
886
1220
|
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
887
1221
|
}
|
|
888
1222
|
catch (error) {
|
|
889
|
-
|
|
1223
|
+
const code = error.code;
|
|
1224
|
+
if (code === "ENOENT")
|
|
890
1225
|
return undefined;
|
|
1226
|
+
if (code === "EACCES" || code === "EPERM")
|
|
1227
|
+
throw unreadableLog(path, code);
|
|
891
1228
|
throw error;
|
|
892
1229
|
}
|
|
893
1230
|
try {
|