@cotal-ai/cli 0.90.0 → 0.91.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 +17 -0
- package/dist/chat/chat-view.d.ts.map +1 -0
- package/dist/chat/chat-view.js +179 -0
- package/dist/chat/chat-view.js.map +1 -0
- package/dist/chat/controller.d.ts +19 -0
- package/dist/chat/controller.d.ts.map +1 -0
- package/dist/chat/controller.js +116 -0
- package/dist/chat/controller.js.map +1 -0
- package/dist/chat/engine.d.ts +108 -0
- package/dist/chat/engine.d.ts.map +1 -0
- package/dist/chat/engine.js +226 -0
- package/dist/chat/engine.js.map +1 -0
- package/dist/chat/frontend.d.ts +35 -0
- package/dist/chat/frontend.d.ts.map +1 -0
- package/dist/chat/frontend.js +151 -0
- package/dist/chat/frontend.js.map +1 -0
- package/dist/chat/native-session.d.ts +71 -0
- package/dist/chat/native-session.d.ts.map +1 -0
- package/dist/chat/native-session.js +348 -0
- package/dist/chat/native-session.js.map +1 -0
- package/dist/chat/open-session.d.ts +8 -0
- package/dist/chat/open-session.d.ts.map +1 -0
- package/dist/chat/open-session.js +120 -0
- package/dist/chat/open-session.js.map +1 -0
- package/dist/chat/picker.d.ts +34 -0
- package/dist/chat/picker.d.ts.map +1 -0
- package/dist/chat/picker.js +97 -0
- package/dist/chat/picker.js.map +1 -0
- package/dist/chat/plain.d.ts +15 -0
- package/dist/chat/plain.d.ts.map +1 -0
- package/dist/chat/plain.js +242 -0
- package/dist/chat/plain.js.map +1 -0
- package/dist/chat/session.d.ts +217 -0
- package/dist/chat/session.d.ts.map +1 -0
- package/dist/chat/session.js +2 -0
- package/dist/chat/session.js.map +1 -0
- package/dist/chat/static-session.d.ts +61 -0
- package/dist/chat/static-session.d.ts.map +1 -0
- package/dist/chat/static-session.js +212 -0
- package/dist/chat/static-session.js.map +1 -0
- package/dist/chat/stdio-io.d.ts +34 -0
- package/dist/chat/stdio-io.d.ts.map +1 -0
- package/dist/chat/stdio-io.js +175 -0
- package/dist/chat/stdio-io.js.map +1 -0
- package/dist/chat/stdio.d.ts +173 -0
- package/dist/chat/stdio.d.ts.map +1 -0
- package/dist/chat/stdio.js +400 -0
- package/dist/chat/stdio.js.map +1 -0
- package/dist/chat/user-session.d.ts +21 -0
- package/dist/chat/user-session.d.ts.map +1 -0
- package/dist/chat/user-session.js +180 -0
- package/dist/chat/user-session.js.map +1 -0
- package/dist/chat/view.d.ts +186 -0
- package/dist/chat/view.d.ts.map +1 -0
- package/dist/chat/view.js +386 -0
- package/dist/chat/view.js.map +1 -0
- package/dist/command.d.ts +11 -3
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +392 -147
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts +103 -11
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +501 -251
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/app-identity.d.ts.map +1 -1
- package/dist/commands/app-identity.js +10 -1
- package/dist/commands/app-identity.js.map +1 -1
- package/dist/commands/backup-maintenance.d.ts +4 -0
- package/dist/commands/backup-maintenance.d.ts.map +1 -0
- package/dist/commands/backup-maintenance.js +92 -0
- package/dist/commands/backup-maintenance.js.map +1 -0
- package/dist/commands/backup-read.d.ts +4 -0
- package/dist/commands/backup-read.d.ts.map +1 -0
- package/dist/commands/backup-read.js +27 -0
- package/dist/commands/backup-read.js.map +1 -0
- package/dist/commands/backup-restore.d.ts +7 -0
- package/dist/commands/backup-restore.d.ts.map +1 -0
- package/dist/commands/backup-restore.js +81 -0
- package/dist/commands/backup-restore.js.map +1 -0
- package/dist/commands/backup.d.ts +2 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +102 -24
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/channel-members.d.ts +8 -0
- package/dist/commands/channel-members.d.ts.map +1 -0
- package/dist/commands/channel-members.js +144 -0
- package/dist/commands/channel-members.js.map +1 -0
- package/dist/commands/channels.d.ts +75 -22
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +181 -100
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/chat.d.ts +109 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +227 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/clean.d.ts +43 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +90 -47
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/completion.d.ts +39 -1
- package/dist/commands/completion.d.ts.map +1 -1
- package/dist/commands/completion.js +211 -87
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/config.d.ts +33 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +159 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/console.d.ts.map +1 -1
- package/dist/commands/console.js +25 -7
- package/dist/commands/console.js.map +1 -1
- package/dist/commands/describe.d.ts +63 -31
- package/dist/commands/describe.d.ts.map +1 -1
- package/dist/commands/describe.js +264 -136
- package/dist/commands/describe.js.map +1 -1
- package/dist/commands/doctor.d.ts +11 -6
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +195 -288
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down-services.d.ts +29 -0
- package/dist/commands/down-services.d.ts.map +1 -0
- package/dist/commands/down-services.js +129 -0
- package/dist/commands/down-services.js.map +1 -0
- package/dist/commands/down.d.ts +37 -11
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +276 -115
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/endpoint-authoring.d.ts +4 -0
- package/dist/commands/endpoint-authoring.d.ts.map +1 -0
- package/dist/commands/endpoint-authoring.js +125 -0
- package/dist/commands/endpoint-authoring.js.map +1 -0
- package/dist/commands/endpoint-deregister.d.ts +5 -0
- package/dist/commands/endpoint-deregister.d.ts.map +1 -0
- package/dist/commands/endpoint-deregister.js +70 -0
- package/dist/commands/endpoint-deregister.js.map +1 -0
- package/dist/commands/endpoint.d.ts +118 -0
- package/dist/commands/endpoint.d.ts.map +1 -0
- package/dist/commands/endpoint.js +177 -0
- package/dist/commands/endpoint.js.map +1 -0
- package/dist/commands/endpoints.d.ts +27 -1
- package/dist/commands/endpoints.d.ts.map +1 -1
- package/dist/commands/endpoints.js +42 -30
- package/dist/commands/endpoints.js.map +1 -1
- package/dist/commands/ext.d.ts +38 -1
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +84 -49
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/feedback.d.ts +58 -1
- package/dist/commands/feedback.d.ts.map +1 -1
- package/dist/commands/feedback.js +119 -47
- package/dist/commands/feedback.js.map +1 -1
- package/dist/commands/help.d.ts +20 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +52 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/history-clear.d.ts +14 -0
- package/dist/commands/history-clear.d.ts.map +1 -0
- package/dist/commands/history-clear.js +73 -0
- package/dist/commands/history-clear.js.map +1 -0
- package/dist/commands/history.d.ts +146 -4
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +443 -19
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +7 -3
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/meshes-add.d.ts +3 -0
- package/dist/commands/meshes-add.d.ts.map +1 -1
- package/dist/commands/meshes-add.js +41 -34
- package/dist/commands/meshes-add.js.map +1 -1
- package/dist/commands/meshes-wizard.js +3 -3
- package/dist/commands/meshes-wizard.js.map +1 -1
- package/dist/commands/mint-endpoint-caller.d.ts +5 -0
- package/dist/commands/mint-endpoint-caller.d.ts.map +1 -0
- package/dist/commands/mint-endpoint-caller.js +130 -0
- package/dist/commands/mint-endpoint-caller.js.map +1 -0
- package/dist/commands/mint.d.ts +2 -37
- package/dist/commands/mint.d.ts.map +1 -1
- package/dist/commands/mint.js +142 -325
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/models.d.ts +30 -8
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +72 -41
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/persona-remote.d.ts +5 -0
- package/dist/commands/persona-remote.d.ts.map +1 -0
- package/dist/commands/persona-remote.js +237 -0
- package/dist/commands/persona-remote.js.map +1 -0
- package/dist/commands/persona.d.ts +91 -0
- package/dist/commands/persona.d.ts.map +1 -0
- package/dist/commands/persona.js +200 -0
- package/dist/commands/persona.js.map +1 -0
- package/dist/commands/personas.d.ts.map +1 -1
- package/dist/commands/personas.js +16 -59
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/reset-space-apply.d.ts +5 -0
- package/dist/commands/reset-space-apply.d.ts.map +1 -0
- package/dist/commands/reset-space-apply.js +140 -0
- package/dist/commands/reset-space-apply.js.map +1 -0
- package/dist/commands/reset-store-apply.d.ts +11 -0
- package/dist/commands/reset-store-apply.d.ts.map +1 -0
- package/dist/commands/reset-store-apply.js +154 -0
- package/dist/commands/reset-store-apply.js.map +1 -0
- package/dist/commands/reset.d.ts +26 -0
- package/dist/commands/reset.d.ts.map +1 -0
- package/dist/commands/reset.js +143 -0
- package/dist/commands/reset.js.map +1 -0
- package/dist/commands/runtimes.d.ts +26 -1
- package/dist/commands/runtimes.d.ts.map +1 -1
- package/dist/commands/runtimes.js +68 -32
- package/dist/commands/runtimes.js.map +1 -1
- package/dist/commands/send.d.ts +91 -6
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +180 -106
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-actions.d.ts +6 -0
- package/dist/commands/service-actions.d.ts.map +1 -0
- package/dist/commands/service-actions.js +405 -0
- package/dist/commands/service-actions.js.map +1 -0
- package/dist/commands/service-log-follow.d.ts +5 -0
- package/dist/commands/service-log-follow.d.ts.map +1 -0
- package/dist/commands/service-log-follow.js +106 -0
- package/dist/commands/service-log-follow.js.map +1 -0
- package/dist/commands/service-registry.d.ts +67 -0
- package/dist/commands/service-registry.d.ts.map +1 -0
- package/dist/commands/service-registry.js +275 -0
- package/dist/commands/service-registry.js.map +1 -0
- package/dist/commands/service-set-stop.d.ts +6 -0
- package/dist/commands/service-set-stop.d.ts.map +1 -0
- package/dist/commands/service-set-stop.js +161 -0
- package/dist/commands/service-set-stop.js.map +1 -0
- package/dist/commands/service-unit-entry.d.ts +5 -0
- package/dist/commands/service-unit-entry.d.ts.map +1 -0
- package/dist/commands/service-unit-entry.js +113 -0
- package/dist/commands/service-unit-entry.js.map +1 -0
- package/dist/commands/setup-start.d.ts +21 -0
- package/dist/commands/setup-start.d.ts.map +1 -0
- package/dist/commands/setup-start.js +95 -0
- package/dist/commands/setup-start.js.map +1 -0
- package/dist/commands/setup.d.ts +86 -100
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +766 -487
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-delete.d.ts +3 -0
- package/dist/commands/space-delete.d.ts.map +1 -0
- package/dist/commands/space-delete.js +341 -0
- package/dist/commands/space-delete.js.map +1 -0
- package/dist/commands/space-registration.d.ts +92 -0
- package/dist/commands/space-registration.d.ts.map +1 -0
- package/dist/commands/space-registration.js +388 -0
- package/dist/commands/space-registration.js.map +1 -0
- package/dist/commands/space.d.ts +128 -0
- package/dist/commands/space.d.ts.map +1 -0
- package/dist/commands/space.js +230 -0
- package/dist/commands/space.js.map +1 -0
- package/dist/commands/spawn-manifest.d.ts.map +1 -1
- package/dist/commands/spawn-manifest.js +2 -2
- package/dist/commands/spawn-manifest.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts +9 -0
- package/dist/commands/spawn-preview.d.ts.map +1 -0
- package/dist/commands/spawn-preview.js +68 -0
- package/dist/commands/spawn-preview.js.map +1 -0
- package/dist/commands/spawn.d.ts +78 -18
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +236 -96
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.d.ts +6 -0
- package/dist/commands/stack-down.d.ts.map +1 -0
- package/dist/commands/stack-down.js +206 -0
- package/dist/commands/stack-down.js.map +1 -0
- package/dist/commands/stack-up.d.ts +149 -0
- package/dist/commands/stack-up.d.ts.map +1 -0
- package/dist/commands/stack-up.js +459 -0
- package/dist/commands/stack-up.js.map +1 -0
- package/dist/commands/stack-user-auth.d.ts +52 -0
- package/dist/commands/stack-user-auth.d.ts.map +1 -0
- package/dist/commands/stack-user-auth.js +128 -0
- package/dist/commands/stack-user-auth.js.map +1 -0
- package/dist/commands/status.d.ts +232 -5
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +989 -406
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts +23 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +69 -17
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/team-agent-apply.d.ts +5 -0
- package/dist/commands/team-agent-apply.d.ts.map +1 -0
- package/dist/commands/team-agent-apply.js +204 -0
- package/dist/commands/team-agent-apply.js.map +1 -0
- package/dist/commands/team-agent-remove.d.ts +87 -0
- package/dist/commands/team-agent-remove.d.ts.map +1 -0
- package/dist/commands/team-agent-remove.js +348 -0
- package/dist/commands/team-agent-remove.js.map +1 -0
- package/dist/commands/team-boot-controller.d.ts +11 -0
- package/dist/commands/team-boot-controller.d.ts.map +1 -0
- package/dist/commands/team-boot-controller.js +176 -0
- package/dist/commands/team-boot-controller.js.map +1 -0
- package/dist/commands/team-channel-remove.d.ts +167 -0
- package/dist/commands/team-channel-remove.d.ts.map +1 -0
- package/dist/commands/team-channel-remove.js +486 -0
- package/dist/commands/team-channel-remove.js.map +1 -0
- package/dist/commands/team-deploy-apply.d.ts +11 -0
- package/dist/commands/team-deploy-apply.d.ts.map +1 -0
- package/dist/commands/team-deploy-apply.js +320 -0
- package/dist/commands/team-deploy-apply.js.map +1 -0
- package/dist/commands/team-mixed-remove.d.ts +8 -0
- package/dist/commands/team-mixed-remove.d.ts.map +1 -0
- package/dist/commands/team-mixed-remove.js +207 -0
- package/dist/commands/team-mixed-remove.js.map +1 -0
- package/dist/commands/team.d.ts +51 -0
- package/dist/commands/team.d.ts.map +1 -0
- package/dist/commands/team.js +727 -0
- package/dist/commands/team.js.map +1 -0
- package/dist/commands/topology.d.ts +4 -0
- package/dist/commands/topology.d.ts.map +1 -1
- package/dist/commands/topology.js +8 -0
- package/dist/commands/topology.js.map +1 -1
- package/dist/commands/up.d.ts +144 -5
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +1015 -124
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update.d.ts +11 -0
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +72 -15
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/use.d.ts +16 -3
- package/dist/commands/use.d.ts.map +1 -1
- package/dist/commands/use.js +45 -19
- package/dist/commands/use.js.map +1 -1
- package/dist/commands/watch.d.ts +37 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +106 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/commands/who.d.ts +79 -0
- package/dist/commands/who.d.ts.map +1 -0
- package/dist/commands/who.js +193 -0
- package/dist/commands/who.js.map +1 -0
- package/dist/commands/whoami.d.ts +56 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +106 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/console/app.d.ts.map +1 -1
- package/dist/console/app.js +8 -4
- package/dist/console/app.js.map +1 -1
- package/dist/console/commands.d.ts.map +1 -1
- package/dist/console/commands.js +12 -6
- package/dist/console/commands.js.map +1 -1
- package/dist/exec-endpoint/definition.d.ts +15 -0
- package/dist/exec-endpoint/definition.d.ts.map +1 -0
- package/dist/exec-endpoint/definition.js +56 -0
- package/dist/exec-endpoint/definition.js.map +1 -0
- package/dist/exec-endpoint/handler.d.ts +13 -0
- package/dist/exec-endpoint/handler.d.ts.map +1 -0
- package/dist/exec-endpoint/handler.js +155 -0
- package/dist/exec-endpoint/handler.js.map +1 -0
- package/dist/exec-endpoint/registration.d.ts +34 -0
- package/dist/exec-endpoint/registration.d.ts.map +1 -0
- package/dist/exec-endpoint/registration.js +148 -0
- package/dist/exec-endpoint/registration.js.map +1 -0
- package/dist/exec-endpoint/serve.d.ts +8 -0
- package/dist/exec-endpoint/serve.d.ts.map +1 -0
- package/dist/exec-endpoint/serve.js +159 -0
- package/dist/exec-endpoint/serve.js.map +1 -0
- package/dist/exec-endpoint/service-adapter.d.ts +6 -0
- package/dist/exec-endpoint/service-adapter.d.ts.map +1 -0
- package/dist/exec-endpoint/service-adapter.js +110 -0
- package/dist/exec-endpoint/service-adapter.js.map +1 -0
- package/dist/ext-loader.d.ts +10 -0
- package/dist/ext-loader.d.ts.map +1 -1
- package/dist/ext-loader.js +61 -13
- package/dist/ext-loader.js.map +1 -1
- package/dist/help.d.ts +18 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +256 -0
- package/dist/help.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +444 -118
- package/dist/index.js.map +1 -1
- package/dist/lib/assist.d.ts.map +1 -1
- package/dist/lib/assist.js +3 -2
- package/dist/lib/assist.js.map +1 -1
- package/dist/lib/attach-client.d.ts +7 -6
- package/dist/lib/attach-client.d.ts.map +1 -1
- package/dist/lib/attach-client.js +14 -15
- package/dist/lib/attach-client.js.map +1 -1
- package/dist/lib/auth-proc.d.ts +3 -3
- package/dist/lib/auth-proc.d.ts.map +1 -1
- package/dist/lib/auth-proc.js +8 -8
- package/dist/lib/auth-proc.js.map +1 -1
- package/dist/lib/backup-artifact.d.ts +34 -1
- package/dist/lib/backup-artifact.d.ts.map +1 -1
- package/dist/lib/backup-artifact.js +67 -17
- package/dist/lib/backup-artifact.js.map +1 -1
- package/dist/lib/broker-service.d.ts +10 -0
- package/dist/lib/broker-service.d.ts.map +1 -0
- package/dist/lib/broker-service.js +329 -0
- package/dist/lib/broker-service.js.map +1 -0
- package/dist/lib/cancel.js +1 -1
- package/dist/lib/cancel.js.map +1 -1
- package/dist/lib/choose-target.d.ts +10 -0
- package/dist/lib/choose-target.d.ts.map +1 -0
- package/dist/lib/choose-target.js +42 -0
- package/dist/lib/choose-target.js.map +1 -0
- package/dist/lib/command-path.d.ts +13 -0
- package/dist/lib/command-path.d.ts.map +1 -0
- package/dist/lib/command-path.js +40 -0
- package/dist/lib/command-path.js.map +1 -0
- package/dist/lib/completion-install.d.ts +29 -0
- package/dist/lib/completion-install.d.ts.map +1 -0
- package/dist/lib/completion-install.js +369 -0
- package/dist/lib/completion-install.js.map +1 -0
- package/dist/lib/completion-scripts.d.ts +4 -0
- package/dist/lib/completion-scripts.d.ts.map +1 -0
- package/dist/lib/completion-scripts.js +15 -0
- package/dist/lib/completion-scripts.js.map +1 -0
- package/dist/lib/completion.d.ts.map +1 -1
- package/dist/lib/completion.js +4 -1
- package/dist/lib/completion.js.map +1 -1
- package/dist/lib/control.d.ts +65 -6
- package/dist/lib/control.d.ts.map +1 -1
- package/dist/lib/control.js +121 -27
- package/dist/lib/control.js.map +1 -1
- package/dist/lib/controller-preserve.d.ts +12 -0
- package/dist/lib/controller-preserve.d.ts.map +1 -0
- package/dist/lib/controller-preserve.js +373 -0
- package/dist/lib/controller-preserve.js.map +1 -0
- package/dist/lib/controller-restore.d.ts +38 -0
- package/dist/lib/controller-restore.d.ts.map +1 -0
- package/dist/lib/controller-restore.js +205 -0
- package/dist/lib/controller-restore.js.map +1 -0
- package/dist/lib/controller-resume.d.ts +92 -0
- package/dist/lib/controller-resume.d.ts.map +1 -0
- package/dist/lib/controller-resume.js +300 -0
- package/dist/lib/controller-resume.js.map +1 -0
- package/dist/lib/credential-authority.d.ts +17 -0
- package/dist/lib/credential-authority.d.ts.map +1 -0
- package/dist/lib/credential-authority.js +28 -0
- package/dist/lib/credential-authority.js.map +1 -0
- package/dist/lib/default-persona.d.ts +38 -0
- package/dist/lib/default-persona.d.ts.map +1 -0
- package/dist/lib/default-persona.js +85 -0
- package/dist/lib/default-persona.js.map +1 -0
- package/dist/lib/delivery-proc.d.ts +9 -9
- package/dist/lib/delivery-proc.d.ts.map +1 -1
- package/dist/lib/delivery-proc.js +9 -19
- package/dist/lib/delivery-proc.js.map +1 -1
- package/dist/lib/endpoint-capability-gates.d.ts +10 -0
- package/dist/lib/endpoint-capability-gates.d.ts.map +1 -0
- package/dist/lib/endpoint-capability-gates.js +70 -0
- package/dist/lib/endpoint-capability-gates.js.map +1 -0
- package/dist/lib/endpoint-client.d.ts +20 -0
- package/dist/lib/endpoint-client.d.ts.map +1 -0
- package/dist/lib/endpoint-client.js +42 -0
- package/dist/lib/endpoint-client.js.map +1 -0
- package/dist/lib/endpoint-errors.d.ts +11 -0
- package/dist/lib/endpoint-errors.d.ts.map +1 -0
- package/dist/lib/endpoint-errors.js +30 -0
- package/dist/lib/endpoint-errors.js.map +1 -0
- package/dist/lib/endpoint-goal.d.ts +19 -0
- package/dist/lib/endpoint-goal.d.ts.map +1 -0
- package/dist/lib/endpoint-goal.js +31 -0
- package/dist/lib/endpoint-goal.js.map +1 -0
- package/dist/lib/endpoint-inventory.d.ts +30 -0
- package/dist/lib/endpoint-inventory.d.ts.map +1 -0
- package/dist/lib/endpoint-inventory.js +79 -0
- package/dist/lib/endpoint-inventory.js.map +1 -0
- package/dist/lib/endpoint-references.d.ts +22 -0
- package/dist/lib/endpoint-references.d.ts.map +1 -0
- package/dist/lib/endpoint-references.js +44 -0
- package/dist/lib/endpoint-references.js.map +1 -0
- package/dist/lib/endpoint-scatter.d.ts +57 -0
- package/dist/lib/endpoint-scatter.d.ts.map +1 -0
- package/dist/lib/endpoint-scatter.js +75 -0
- package/dist/lib/endpoint-scatter.js.map +1 -0
- package/dist/lib/endpoint-selection.d.ts +35 -0
- package/dist/lib/endpoint-selection.d.ts.map +1 -0
- package/dist/lib/endpoint-selection.js +80 -0
- package/dist/lib/endpoint-selection.js.map +1 -0
- package/dist/lib/install-umask.d.ts +6 -0
- package/dist/lib/install-umask.d.ts.map +1 -0
- package/dist/lib/install-umask.js +15 -0
- package/dist/lib/install-umask.js.map +1 -0
- package/dist/lib/isolated-broker.d.ts.map +1 -1
- package/dist/lib/isolated-broker.js +9 -5
- package/dist/lib/isolated-broker.js.map +1 -1
- package/dist/lib/local-process-stop.d.ts.map +1 -1
- package/dist/lib/local-process-stop.js +7 -1
- package/dist/lib/local-process-stop.js.map +1 -1
- package/dist/lib/manager-proc.d.ts +11 -5
- package/dist/lib/manager-proc.d.ts.map +1 -1
- package/dist/lib/manager-proc.js +12 -17
- package/dist/lib/manager-proc.js.map +1 -1
- package/dist/lib/manifest/apply.d.ts +4 -1
- package/dist/lib/manifest/apply.d.ts.map +1 -1
- package/dist/lib/manifest/apply.js +1 -1
- package/dist/lib/manifest/apply.js.map +1 -1
- package/dist/lib/manifest/ledger.d.ts +3 -1
- package/dist/lib/manifest/ledger.d.ts.map +1 -1
- package/dist/lib/manifest/ledger.js +16 -3
- package/dist/lib/manifest/ledger.js.map +1 -1
- package/dist/lib/manifest/schema.d.ts +1 -117
- package/dist/lib/manifest/schema.d.ts.map +1 -1
- package/dist/lib/manifest/schema.js +1 -95
- package/dist/lib/manifest/schema.js.map +1 -1
- package/dist/lib/offline-recipient.d.ts +5 -0
- package/dist/lib/offline-recipient.d.ts.map +1 -0
- package/dist/lib/offline-recipient.js +7 -0
- package/dist/lib/offline-recipient.js.map +1 -0
- package/dist/lib/onboard.js +3 -3
- package/dist/lib/onboard.js.map +1 -1
- package/dist/lib/persona-files.d.ts +29 -0
- package/dist/lib/persona-files.d.ts.map +1 -0
- package/dist/lib/persona-files.js +154 -0
- package/dist/lib/persona-files.js.map +1 -0
- package/dist/lib/personas.d.ts +3 -0
- package/dist/lib/personas.d.ts.map +1 -1
- package/dist/lib/personas.js +14 -2
- package/dist/lib/personas.js.map +1 -1
- package/dist/lib/prompts.d.ts +16 -0
- package/dist/lib/prompts.d.ts.map +1 -0
- package/dist/lib/prompts.js +35 -0
- package/dist/lib/prompts.js.map +1 -0
- package/dist/lib/protected-records.d.ts +2 -0
- package/dist/lib/protected-records.d.ts.map +1 -0
- package/dist/lib/protected-records.js +3 -0
- package/dist/lib/protected-records.js.map +1 -0
- package/dist/lib/registry-errors.d.ts +4 -0
- package/dist/lib/registry-errors.d.ts.map +1 -0
- package/dist/lib/registry-errors.js +6 -0
- package/dist/lib/registry-errors.js.map +1 -0
- package/dist/lib/reset-space-plan.d.ts +36 -0
- package/dist/lib/reset-space-plan.d.ts.map +1 -0
- package/dist/lib/reset-space-plan.js +181 -0
- package/dist/lib/reset-space-plan.js.map +1 -0
- package/dist/lib/restore.d.ts +3 -1
- package/dist/lib/restore.d.ts.map +1 -1
- package/dist/lib/restore.js +38 -10
- package/dist/lib/restore.js.map +1 -1
- package/dist/lib/seat-resume.d.ts +4 -1
- package/dist/lib/seat-resume.d.ts.map +1 -1
- package/dist/lib/seat-resume.js +7 -4
- package/dist/lib/seat-resume.js.map +1 -1
- package/dist/lib/service-adapters.d.ts +32 -0
- package/dist/lib/service-adapters.d.ts.map +1 -0
- package/dist/lib/service-adapters.js +55 -0
- package/dist/lib/service-adapters.js.map +1 -0
- package/dist/lib/service-census.d.ts +73 -0
- package/dist/lib/service-census.d.ts.map +1 -0
- package/dist/lib/service-census.js +42 -0
- package/dist/lib/service-census.js.map +1 -0
- package/dist/lib/service-definitions.d.ts +49 -0
- package/dist/lib/service-definitions.d.ts.map +1 -0
- package/dist/lib/service-definitions.js +61 -0
- package/dist/lib/service-definitions.js.map +1 -0
- package/dist/lib/service-install-intent.d.ts +48 -0
- package/dist/lib/service-install-intent.d.ts.map +1 -0
- package/dist/lib/service-install-intent.js +95 -0
- package/dist/lib/service-install-intent.js.map +1 -0
- package/dist/lib/service-instances.d.ts +143 -0
- package/dist/lib/service-instances.d.ts.map +1 -0
- package/dist/lib/service-instances.js +193 -0
- package/dist/lib/service-instances.js.map +1 -0
- package/dist/lib/service-journal.d.ts +38 -0
- package/dist/lib/service-journal.d.ts.map +1 -0
- package/dist/lib/service-journal.js +210 -0
- package/dist/lib/service-journal.js.map +1 -0
- package/dist/lib/service-launchd-plan.d.ts +21 -0
- package/dist/lib/service-launchd-plan.d.ts.map +1 -0
- package/dist/lib/service-launchd-plan.js +69 -0
- package/dist/lib/service-launchd-plan.js.map +1 -0
- package/dist/lib/service-launchd-unit.d.ts +20 -0
- package/dist/lib/service-launchd-unit.d.ts.map +1 -0
- package/dist/lib/service-launchd-unit.js +66 -0
- package/dist/lib/service-launchd-unit.js.map +1 -0
- package/dist/lib/service-presets.d.ts +17 -0
- package/dist/lib/service-presets.d.ts.map +1 -0
- package/dist/lib/service-presets.js +138 -0
- package/dist/lib/service-presets.js.map +1 -0
- package/dist/lib/service-private-seed.d.ts +7 -0
- package/dist/lib/service-private-seed.d.ts.map +1 -0
- package/dist/lib/service-private-seed.js +64 -0
- package/dist/lib/service-private-seed.js.map +1 -0
- package/dist/lib/service-private-tree.d.ts +6 -0
- package/dist/lib/service-private-tree.d.ts.map +1 -0
- package/dist/lib/service-private-tree.js +100 -0
- package/dist/lib/service-private-tree.js.map +1 -0
- package/dist/lib/service-process.d.ts +121 -0
- package/dist/lib/service-process.d.ts.map +1 -0
- package/dist/lib/service-process.js +742 -0
- package/dist/lib/service-process.js.map +1 -0
- package/dist/lib/service-stopped-allocation.d.ts +6 -0
- package/dist/lib/service-stopped-allocation.d.ts.map +1 -0
- package/dist/lib/service-stopped-allocation.js +42 -0
- package/dist/lib/service-stopped-allocation.js.map +1 -0
- package/dist/lib/service-supervision.d.ts +59 -0
- package/dist/lib/service-supervision.d.ts.map +1 -0
- package/dist/lib/service-supervision.js +71 -0
- package/dist/lib/service-supervision.js.map +1 -0
- package/dist/lib/service-systemd-attempt-read.d.ts +40 -0
- package/dist/lib/service-systemd-attempt-read.d.ts.map +1 -0
- package/dist/lib/service-systemd-attempt-read.js +80 -0
- package/dist/lib/service-systemd-attempt-read.js.map +1 -0
- package/dist/lib/service-systemd-control.d.ts +38 -0
- package/dist/lib/service-systemd-control.d.ts.map +1 -0
- package/dist/lib/service-systemd-control.js +141 -0
- package/dist/lib/service-systemd-control.js.map +1 -0
- package/dist/lib/service-systemd-files.d.ts +8 -0
- package/dist/lib/service-systemd-files.d.ts.map +1 -0
- package/dist/lib/service-systemd-files.js +63 -0
- package/dist/lib/service-systemd-files.js.map +1 -0
- package/dist/lib/service-systemd-install.d.ts +17 -0
- package/dist/lib/service-systemd-install.d.ts.map +1 -0
- package/dist/lib/service-systemd-install.js +146 -0
- package/dist/lib/service-systemd-install.js.map +1 -0
- package/dist/lib/service-systemd-plan.d.ts +28 -0
- package/dist/lib/service-systemd-plan.d.ts.map +1 -0
- package/dist/lib/service-systemd-plan.js +56 -0
- package/dist/lib/service-systemd-plan.js.map +1 -0
- package/dist/lib/service-systemd-reseed.d.ts +16 -0
- package/dist/lib/service-systemd-reseed.d.ts.map +1 -0
- package/dist/lib/service-systemd-reseed.js +106 -0
- package/dist/lib/service-systemd-reseed.js.map +1 -0
- package/dist/lib/service-systemd-uninstall-plan.d.ts +29 -0
- package/dist/lib/service-systemd-uninstall-plan.d.ts.map +1 -0
- package/dist/lib/service-systemd-uninstall-plan.js +56 -0
- package/dist/lib/service-systemd-uninstall-plan.js.map +1 -0
- package/dist/lib/service-systemd-uninstall.d.ts +17 -0
- package/dist/lib/service-systemd-uninstall.d.ts.map +1 -0
- package/dist/lib/service-systemd-uninstall.js +106 -0
- package/dist/lib/service-systemd-uninstall.js.map +1 -0
- package/dist/lib/service-systemd-unit.d.ts +28 -0
- package/dist/lib/service-systemd-unit.d.ts.map +1 -0
- package/dist/lib/service-systemd-unit.js +73 -0
- package/dist/lib/service-systemd-unit.js.map +1 -0
- package/dist/lib/service-systemd.d.ts +49 -0
- package/dist/lib/service-systemd.d.ts.map +1 -0
- package/dist/lib/service-systemd.js +134 -0
- package/dist/lib/service-systemd.js.map +1 -0
- package/dist/lib/service-uninstall-intent.d.ts +38 -0
- package/dist/lib/service-uninstall-intent.d.ts.map +1 -0
- package/dist/lib/service-uninstall-intent.js +74 -0
- package/dist/lib/service-uninstall-intent.js.map +1 -0
- package/dist/lib/service-unit-action.d.ts +24 -0
- package/dist/lib/service-unit-action.d.ts.map +1 -0
- package/dist/lib/service-unit-action.js +61 -0
- package/dist/lib/service-unit-action.js.map +1 -0
- package/dist/lib/setup-log.d.ts +5 -4
- package/dist/lib/setup-log.d.ts.map +1 -1
- package/dist/lib/setup-log.js +18 -9
- package/dist/lib/setup-log.js.map +1 -1
- package/dist/lib/space-schema-inspection.d.ts +73 -0
- package/dist/lib/space-schema-inspection.d.ts.map +1 -0
- package/dist/lib/space-schema-inspection.js +118 -0
- package/dist/lib/space-schema-inspection.js.map +1 -0
- package/dist/lib/space-schema-report.d.ts +82 -0
- package/dist/lib/space-schema-report.d.ts.map +1 -0
- package/dist/lib/space-schema-report.js +109 -0
- package/dist/lib/space-schema-report.js.map +1 -0
- package/dist/lib/spawn-defaults.d.ts +14 -0
- package/dist/lib/spawn-defaults.d.ts.map +1 -0
- package/dist/lib/spawn-defaults.js +20 -0
- package/dist/lib/spawn-defaults.js.map +1 -0
- package/dist/lib/stack-journal.d.ts +92 -0
- package/dist/lib/stack-journal.d.ts.map +1 -0
- package/dist/lib/stack-journal.js +199 -0
- package/dist/lib/stack-journal.js.map +1 -0
- package/dist/lib/stack-resume.d.ts +35 -0
- package/dist/lib/stack-resume.d.ts.map +1 -0
- package/dist/lib/stack-resume.js +123 -0
- package/dist/lib/stack-resume.js.map +1 -0
- package/dist/lib/status.d.ts +19 -20
- package/dist/lib/status.d.ts.map +1 -1
- package/dist/lib/status.js +41 -40
- package/dist/lib/status.js.map +1 -1
- package/dist/lib/steps.d.ts.map +1 -1
- package/dist/lib/steps.js +3 -2
- package/dist/lib/steps.js.map +1 -1
- package/dist/lib/systemd-supervision.d.ts +11 -4
- package/dist/lib/systemd-supervision.d.ts.map +1 -1
- package/dist/lib/systemd-supervision.js +19 -8
- package/dist/lib/systemd-supervision.js.map +1 -1
- package/dist/lib/team-additive-attempt.d.ts +286 -0
- package/dist/lib/team-additive-attempt.d.ts.map +1 -0
- package/dist/lib/team-additive-attempt.js +387 -0
- package/dist/lib/team-additive-attempt.js.map +1 -0
- package/dist/lib/team-additive-native.d.ts +17 -0
- package/dist/lib/team-additive-native.d.ts.map +1 -0
- package/dist/lib/team-additive-native.js +29 -0
- package/dist/lib/team-additive-native.js.map +1 -0
- package/dist/lib/team-agent-removal.d.ts +104 -0
- package/dist/lib/team-agent-removal.d.ts.map +1 -0
- package/dist/lib/team-agent-removal.js +121 -0
- package/dist/lib/team-agent-removal.js.map +1 -0
- package/dist/lib/team-channel-removal.d.ts +220 -0
- package/dist/lib/team-channel-removal.d.ts.map +1 -0
- package/dist/lib/team-channel-removal.js +258 -0
- package/dist/lib/team-channel-removal.js.map +1 -0
- package/dist/lib/team-deploy-inspection.d.ts +59 -0
- package/dist/lib/team-deploy-inspection.d.ts.map +1 -0
- package/dist/lib/team-deploy-inspection.js +177 -0
- package/dist/lib/team-deploy-inspection.js.map +1 -0
- package/dist/lib/team-fresh.d.ts +73 -0
- package/dist/lib/team-fresh.d.ts.map +1 -0
- package/dist/lib/team-fresh.js +207 -0
- package/dist/lib/team-fresh.js.map +1 -0
- package/dist/lib/team-removal-reconcile.d.ts +118 -0
- package/dist/lib/team-removal-reconcile.d.ts.map +1 -0
- package/dist/lib/team-removal-reconcile.js +90 -0
- package/dist/lib/team-removal-reconcile.js.map +1 -0
- package/dist/lib/team-removal-record.d.ts +7 -0
- package/dist/lib/team-removal-record.d.ts.map +1 -0
- package/dist/lib/team-removal-record.js +46 -0
- package/dist/lib/team-removal-record.js.map +1 -0
- package/dist/lib/team-retained.d.ts +33 -0
- package/dist/lib/team-retained.d.ts.map +1 -0
- package/dist/lib/team-retained.js +55 -0
- package/dist/lib/team-retained.js.map +1 -0
- package/dist/lib/theme.d.ts.map +1 -1
- package/dist/lib/theme.js +9 -8
- package/dist/lib/theme.js.map +1 -1
- package/dist/lib/transient.d.ts +14 -9
- package/dist/lib/transient.d.ts.map +1 -1
- package/dist/lib/transient.js +25 -18
- package/dist/lib/transient.js.map +1 -1
- package/dist/lib/up-report.d.ts +1 -0
- package/dist/lib/up-report.d.ts.map +1 -1
- package/dist/lib/up-report.js +2 -1
- package/dist/lib/up-report.js.map +1 -1
- package/dist/lib/version.d.ts +8 -2
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +16 -9
- package/dist/lib/version.js.map +1 -1
- package/dist/seed/paths.d.ts +1 -1
- package/dist/seed/paths.js +1 -1
- package/dist/seed/reconcile.d.ts.map +1 -1
- package/dist/seed/reconcile.js +19 -3
- package/dist/seed/reconcile.js.map +1 -1
- package/dist/ui.d.ts +6 -0
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +12 -1
- package/dist/ui.js.map +1 -1
- package/dist/watch-data.d.ts +15 -0
- package/dist/watch-data.d.ts.map +1 -0
- package/dist/watch-data.js +66 -0
- package/dist/watch-data.js.map +1 -0
- package/dist/watch-json.d.ts +5 -0
- package/dist/watch-json.d.ts.map +1 -0
- package/dist/watch-json.js +131 -0
- package/dist/watch-json.js.map +1 -0
- package/dist/watch-view.d.ts +8 -0
- package/dist/watch-view.d.ts.map +1 -0
- package/dist/watch-view.js +65 -0
- package/dist/watch-view.js.map +1 -0
- package/package.json +8 -5
- package/dist/commands/service.d.ts +0 -17
- package/dist/commands/service.d.ts.map +0 -1
- package/dist/commands/service.js +0 -589
- package/dist/commands/service.js.map +0 -1
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
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, resolveNativeServiceTarget, resolveOnPath, serviceAdapterReadiness, serviceMetadataDigest, spaceKey, serviceAdapterKernelStopPlan, serviceAdapterKernelStopResult, serviceAdapterStopPlan, serviceAdapterStopResult, isWorkspaceTargetError, targetErrorCode, workspaceErrorParts } from "@cotal-ai/workspace";
|
|
6
|
+
import { refuseRecordedSupervisor } from "./service-supervision.js";
|
|
7
|
+
import { serviceInstallIntents } from "./service-install-intent.js";
|
|
8
|
+
import { serviceUninstallIntents } from "./service-uninstall-intent.js";
|
|
9
|
+
import { serviceUnitActionStore } from "./service-unit-action.js";
|
|
10
|
+
import { selfArgv } from "./self-exec.js";
|
|
11
|
+
import { loadServiceAdapter, resolveServiceAdapter, sameServiceAdapterPin } from "./service-adapters.js";
|
|
12
|
+
import { serviceDefinitionStore, validateServiceDefinition } from "./service-definitions.js";
|
|
13
|
+
import { instanceProjection, observeServiceProcess, processServiceHost, requireProcessIdentity, serviceInstances, serviceInstanceStore } from "./service-instances.js";
|
|
14
|
+
import { maintenanceStackView } from "./stack-journal.js";
|
|
15
|
+
export const PROCESS_SERVICE_CAPABILITIES = Object.freeze({ multiInstance: true, foreground: true, logs: true, install: false });
|
|
16
|
+
const delay = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
17
|
+
const gone = (state) => state === "gone" || state === "previous-boot" || state === "foreign-pid";
|
|
18
|
+
/** A record with no creation pin whose own state says no child exists: its launch failed before
|
|
19
|
+
* a process did. There is nothing to stop. */
|
|
20
|
+
const neverLaunched = (value) => !value.process && gone(observeServiceProcess(value));
|
|
21
|
+
export function selectServiceInstance(rows, id, allowMissing = false) {
|
|
22
|
+
if (id !== undefined) {
|
|
23
|
+
const found = rows.find((row) => row.name === id);
|
|
24
|
+
if (!found)
|
|
25
|
+
throw new CommandFailure("refused", "TARGET_NOT_FOUND", "the full instance ID does not belong to this selected definition and space");
|
|
26
|
+
return found;
|
|
27
|
+
}
|
|
28
|
+
if (!rows.length) {
|
|
29
|
+
if (allowMissing)
|
|
30
|
+
return undefined;
|
|
31
|
+
throw new CommandFailure("refused", "TARGET_NOT_FOUND", "no instance is recorded for this service definition");
|
|
32
|
+
}
|
|
33
|
+
if (rows.length !== 1)
|
|
34
|
+
throw new CommandFailure("refused", "TARGET_AMBIGUOUS", `this definition has several instance records; choose --instance with one full ID:\n${rows.map((row) => row.name).join("\n")}`, { target: { candidates: rows.map((row) => row.name) } });
|
|
35
|
+
return rows[0];
|
|
36
|
+
}
|
|
37
|
+
function sameIncarnation(before, after) {
|
|
38
|
+
return before.instanceId === after.instanceId && before.definitionRevision === after.definitionRevision && before.process?.pid === after.process?.pid && before.process?.token === after.process?.token;
|
|
39
|
+
}
|
|
40
|
+
function transition(row, change) {
|
|
41
|
+
const store = serviceInstanceStore(row.record.value.space);
|
|
42
|
+
const current = store.read(row.name);
|
|
43
|
+
if (!current || !sameIncarnation(row.record.value, current.record.value))
|
|
44
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the service incarnation changed while its operation was in flight; the successor was not overwritten", { target: { instanceId: row.name, requestId: row.record.value.requestId } });
|
|
45
|
+
store.commit(row.name, current, { ...current.record.value, ...change, ...(change.readiness === "not-checked" ? { adapterReadiness: undefined } : {}), updatedAt: new Date().toISOString() });
|
|
46
|
+
return store.read(row.name);
|
|
47
|
+
}
|
|
48
|
+
function executable(definition) {
|
|
49
|
+
if (definition.launch.type !== "process")
|
|
50
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this driver accepts process definitions, not adapter options");
|
|
51
|
+
const source = definition.launch.executable;
|
|
52
|
+
const found = isAbsolute(source) ? source : /[\\/]/.test(source) ? resolve(definition.launch.cwd, source) : resolveOnPath(source);
|
|
53
|
+
if (!found)
|
|
54
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the declared executable is unavailable; no instance was allocated");
|
|
55
|
+
return found;
|
|
56
|
+
}
|
|
57
|
+
function environment(definition) {
|
|
58
|
+
const env = {};
|
|
59
|
+
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"])
|
|
60
|
+
if (process.env[key] !== undefined)
|
|
61
|
+
env[key] = process.env[key];
|
|
62
|
+
for (const [destination, source] of Object.entries(definition.envRefs ?? {})) {
|
|
63
|
+
if (process.env[source] === undefined)
|
|
64
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "a selected host environment reference is unavailable; no environment value was printed and no process was launched");
|
|
65
|
+
env[destination] = process.env[source];
|
|
66
|
+
}
|
|
67
|
+
if (definition.credentialRef)
|
|
68
|
+
env.COTAL_CREDS = definition.credentialRef.path;
|
|
69
|
+
return env;
|
|
70
|
+
}
|
|
71
|
+
export function serviceLogPath(space, id, create = false) {
|
|
72
|
+
const dir = serviceInstanceStore(space).directory(create);
|
|
73
|
+
return dir ? join(dir, `${spaceKey(id)}.log`) : undefined;
|
|
74
|
+
}
|
|
75
|
+
/** Both absent, or the same attempt and inventory digest. */
|
|
76
|
+
function samePreserved(a, b) {
|
|
77
|
+
return a === undefined ? b === undefined : b !== undefined && a.attemptId === b.attemptId && a.inventorySha256 === b.inventorySha256;
|
|
78
|
+
}
|
|
79
|
+
function ownedMetadata(value) {
|
|
80
|
+
const freeze = (input) => {
|
|
81
|
+
if (input && typeof input === "object") {
|
|
82
|
+
for (const child of Object.values(input))
|
|
83
|
+
freeze(child);
|
|
84
|
+
Object.freeze(input);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const copy = structuredClone(value);
|
|
88
|
+
freeze(copy);
|
|
89
|
+
return copy;
|
|
90
|
+
}
|
|
91
|
+
function adapterContext(definition, instance, cliInvocation, attempt, stack) {
|
|
92
|
+
const value = definition.record.value;
|
|
93
|
+
if (value.launch.type !== "adapter")
|
|
94
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a process definition has no adapter context");
|
|
95
|
+
const options = ownedMetadata(value.launch.options);
|
|
96
|
+
const stateDirectory = serviceInstanceStore(value.space).directory();
|
|
97
|
+
if (!stateDirectory)
|
|
98
|
+
throw new CommandFailure("refused", "CONFLICT", "the reserved service state directory disappeared");
|
|
99
|
+
return Object.freeze({ space: value.space, definition: definition.name, definitionRevision: definition.record.revision, instanceId: instance.instanceId, launchRequestId: instance.launchRequestId, stateDirectory, ...(cliInvocation ? { cliInvocation: Object.freeze([...cliInvocation]) } : {}), options, ...(value.credentialRef ? { credentialRef: Object.freeze({ ...value.credentialRef }) } : {}), ...(attempt ? { attempt: ownedMetadata(attempt) } : {}), ...(stack ? { stack: ownedMetadata(stack) } : {}) });
|
|
100
|
+
}
|
|
101
|
+
/** A deadline bounds our observation, not the provider's work. No timed-out hook is retried. */
|
|
102
|
+
async function adapterCall(call, timeoutMs) {
|
|
103
|
+
const controller = new AbortController();
|
|
104
|
+
let timer;
|
|
105
|
+
try {
|
|
106
|
+
return await Promise.race([
|
|
107
|
+
Promise.resolve().then(() => call(controller.signal)),
|
|
108
|
+
new Promise((_, reject) => { timer = setTimeout(() => { controller.abort(); reject(new CommandFailure("unknown", "OPERATION_UNKNOWN", "the adapter did not complete its bounded observation; it was not retried")); }, Math.max(1, timeoutMs)); }),
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
if (timer !== undefined)
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
controller.abort();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export async function serviceReadiness(row, definition, adapter) {
|
|
118
|
+
const deadline = Date.now() + definition.readiness.timeoutMs;
|
|
119
|
+
do {
|
|
120
|
+
const state = observeServiceProcess(row.record.value);
|
|
121
|
+
if (gone(state))
|
|
122
|
+
throw new CommandFailure("failed", "OPERATION_FAILED", "the owned service process exited before readiness was established", { target: { instanceId: row.name, requestId: row.record.value.requestId } });
|
|
123
|
+
if (state !== "running")
|
|
124
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "service process ownership could not be re-established while observing readiness; no replacement was launched", { target: { instanceId: row.name, requestId: row.record.value.requestId } });
|
|
125
|
+
if (definition.readiness.type === "process")
|
|
126
|
+
return transition(row, { state: "running", readiness: "process-running" });
|
|
127
|
+
if (definition.readiness.type === "adapter") {
|
|
128
|
+
if (!adapter || !row.record.value.process || !sameServiceAdapterPin(row.record.value.adapter, adapter.provider.pin))
|
|
129
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the service readiness has no matching pinned adapter; no provider was substituted", { target: instanceProjection(row) });
|
|
130
|
+
const began = Date.now();
|
|
131
|
+
let observation;
|
|
132
|
+
try {
|
|
133
|
+
observation = serviceAdapterReadiness(await adapterCall((signal) => adapter.provider.readiness({ ...adapter.context, process: { ...row.record.value.process }, signal }), deadline - Date.now()));
|
|
134
|
+
if (observation.state === "ready") {
|
|
135
|
+
const process = row.record.value.process, observedAt = Date.parse(observation.observedAt);
|
|
136
|
+
if (observation.process.pid !== process.pid || observation.process.token !== process.token || observedAt < began - 1000 || observedAt > Date.now() + 1000 || (adapter.provider.declaration.readiness === "endpoint") !== (observation.native !== undefined) || (adapter.provider.declaration.readiness === "listener") !== (observation.listener !== undefined))
|
|
137
|
+
throw new Error("unattributed adapter observation");
|
|
138
|
+
if (observeServiceProcess(row.record.value) !== "running")
|
|
139
|
+
throw new Error("process changed during adapter observation");
|
|
140
|
+
return transition(row, { state: "running", readiness: observation.native ? "endpoint-serving" : observation.listener ? "broker-listener-reported" : "adapter-process-running", adapterReadiness: observation });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
const uncertain = transition(row, { state: "unknown", readiness: "not-checked" });
|
|
145
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the adapter did not establish current readiness for the owned process before its deadline, or returned mismatched evidence; no hook or launch was retried", { target: instanceProjection(uncertain), remedy: "inspect the original full instance and its launch request before another start" });
|
|
146
|
+
}
|
|
147
|
+
await delay(Math.min(100, Math.max(0, deadline - Date.now())));
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const response = await fetch(definition.readiness.url, { redirect: "manual", credentials: "omit", signal: AbortSignal.timeout(Math.max(1, Math.min(1000, deadline - Date.now()))) });
|
|
152
|
+
await response.body?.cancel();
|
|
153
|
+
if (response.status === definition.readiness.expectedStatus && observeServiceProcess(row.record.value) === "running")
|
|
154
|
+
return transition(row, { state: "running", readiness: "http-reachable" });
|
|
155
|
+
}
|
|
156
|
+
catch { /* A failed bounded HTTP read is not proof of process death or listener ownership. */ }
|
|
157
|
+
await delay(Math.min(100, Math.max(0, deadline - Date.now())));
|
|
158
|
+
} while (Date.now() < deadline);
|
|
159
|
+
const uncertain = transition(row, { state: "unknown", readiness: "not-checked" });
|
|
160
|
+
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" });
|
|
161
|
+
}
|
|
162
|
+
/** A target the adapter could not resolve, as the refusal its code and remedy name. */
|
|
163
|
+
function targetRefusal(error) {
|
|
164
|
+
const { message, remedy } = workspaceErrorParts({ kind: "target", error });
|
|
165
|
+
return new CommandFailure("refused", targetErrorCode(error.code), message, remedy ? { remedy } : {});
|
|
166
|
+
}
|
|
167
|
+
export function prepareProcessService(definition) {
|
|
168
|
+
processServiceHost();
|
|
169
|
+
validateServiceDefinition(definition.record.value, definition.record.value.space);
|
|
170
|
+
const launch = definition.record.value.launch;
|
|
171
|
+
const program = launch.type === "process" ? executable(definition.record.value) : undefined;
|
|
172
|
+
if (launch.type === "process" && commandIsCotalSupervisor([program, ...launch.args].join(" ")))
|
|
173
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a native manager needs its service adapter and agent-impact guards, not generic process control; no instance was allocated");
|
|
174
|
+
const adapter = launch.type === "adapter" ? resolveServiceAdapter(launch.adapter, launch.options) : undefined;
|
|
175
|
+
let cliInvocation;
|
|
176
|
+
if (adapter?.declaration.requiresCli) {
|
|
177
|
+
try {
|
|
178
|
+
cliInvocation = selfArgv();
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this native adapter requires the verified cotal binary entry; an arbitrary library entry was not re-executed");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return { program, adapter, cliInvocation, env: environment(definition.record.value), launcher: requireProcessIdentity(process.pid) };
|
|
185
|
+
}
|
|
186
|
+
/** A restart stops before it starts, and its start carries no maintenance attempt. Under a
|
|
187
|
+
* maintenance journal the broker and manager adapters admit such a start only through
|
|
188
|
+
* `maintenanceAdmitsStackWork`, so a restart either would refuse is refused here, before any stop
|
|
189
|
+
* is prepared or made. It only reads; a journal written after it can still refuse the start. */
|
|
190
|
+
export function assertRestartAdmitted(definition) {
|
|
191
|
+
const value = definition.record.value;
|
|
192
|
+
if (value.launch.type !== "adapter" || !["nats-broker", "manager-service"].includes(value.launch.adapter))
|
|
193
|
+
return;
|
|
194
|
+
const options = value.launch.options, root = canonicalRoot(String(options.root));
|
|
195
|
+
if (!readMaintenanceJournal(root))
|
|
196
|
+
return;
|
|
197
|
+
const server = value.launch.adapter === "nats-broker" ? String(options.server) : resolveNativeServiceTarget(root, value.space, options.server).server;
|
|
198
|
+
if (!maintenanceAdmitsStackWork(root, value.space, server, maintenanceStackView(root, value.space)))
|
|
199
|
+
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 } });
|
|
200
|
+
}
|
|
201
|
+
export async function startProcessService(definition, options, held) {
|
|
202
|
+
const value = definition.record.value;
|
|
203
|
+
if (options.attempt && (value.launch.type !== "adapter" || options.foreground))
|
|
204
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a maintenance attempt reaches only an adapter launch in the background; no launch was allocated");
|
|
205
|
+
// Only the broker and manager adapters read an attempt; every other adapter refuses it.
|
|
206
|
+
if (options.attempt && value.launch.type === "adapter" && !["nats-broker", "manager-service"].includes(value.launch.adapter))
|
|
207
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this adapter accepts no maintenance attempt; no launch was allocated");
|
|
208
|
+
// A controller attempt whose cut broker is retired starts the new broker
|
|
209
|
+
// instance its maintenance journal names, with the journal's own IDs. The broker adapter admits
|
|
210
|
+
// only that exact pair, and only while every other record of the definition is retired.
|
|
211
|
+
if (options.brokerInstance && (!options.attempt || value.launch.type !== "adapter" || value.launch.adapter !== "nats-broker" || options.newInstance || options.instance !== undefined))
|
|
212
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a journaled broker instance is started only by its own controller attempt; no launch was allocated");
|
|
213
|
+
const { program, adapter: declaredAdapter, cliInvocation, env, launcher } = prepareProcessService(definition);
|
|
214
|
+
if (declaredAdapter && (options.newInstance && !declaredAdapter.declaration.capabilities.multiInstance || options.foreground && !declaredAdapter.declaration.capabilities.foreground))
|
|
215
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "the selected adapter does not declare this multi-instance or foreground capability; no launch was allocated");
|
|
216
|
+
const hold = held ?? serviceDefinitionStore(value.space).pin(definition);
|
|
217
|
+
let child;
|
|
218
|
+
try {
|
|
219
|
+
assertNoServiceUnitAttempts(value.space, definition.name);
|
|
220
|
+
const rows = serviceInstances(value.space, definition.name);
|
|
221
|
+
if (options.brokerInstance) {
|
|
222
|
+
if (rows.some((row) => row.name === options.brokerInstance.instanceId))
|
|
223
|
+
throw new CommandFailure("refused", "CONFLICT", "the journaled broker instance already has a record; no second launch was allocated");
|
|
224
|
+
if (rows.some((row) => row.record.value.state !== "stopped" || !row.record.value.kernelStop || !gone(observeServiceProcess(row.record.value))))
|
|
225
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "another record of this broker definition is not a stopped one with its own kernel-exit receipt; no new broker instance was allocated");
|
|
226
|
+
}
|
|
227
|
+
const selected = options.newInstance || options.brokerInstance ? undefined : selectServiceInstance(rows, options.instance, true);
|
|
228
|
+
if (selected && selected.record.value.definitionRevision !== definition.record.revision)
|
|
229
|
+
throw new CommandFailure("refused", "CONFLICT", "this instance belongs to another definition revision; it was not adopted");
|
|
230
|
+
if (selected && !sameServiceAdapterPin(selected.record.value.adapter, declaredAdapter?.pin))
|
|
231
|
+
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) });
|
|
232
|
+
if (selected) {
|
|
233
|
+
refuseRecordedSupervisor(selected.record.value, "start");
|
|
234
|
+
const state = observeServiceProcess(selected.record.value);
|
|
235
|
+
if (state === "running") {
|
|
236
|
+
if (options.foreground)
|
|
237
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an existing live instance cannot be converted into this terminal's foreground process; stop it explicitly before a foreground start", { target: instanceProjection(selected) });
|
|
238
|
+
const adapter = declaredAdapter && value.launch.type === "adapter" ? { provider: await loadServiceAdapter(declaredAdapter, value.launch.options), context: adapterContext(definition, selected.record.value, cliInvocation) } : undefined;
|
|
239
|
+
return { instance: await serviceReadiness(selected, value, adapter), noOp: true, child: undefined, exit: undefined };
|
|
240
|
+
}
|
|
241
|
+
if (!gone(state))
|
|
242
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an unresolved or foreign service incarnation is retained; no second launch was allocated", { target: instanceProjection(selected), remedy: "inspect the original full instance with service status/logs; do not discard an unresolved launch receipt" });
|
|
243
|
+
if (declaredAdapter?.declaration.stop === "native" && selected.record.value.process && !(selected.record.value.state === "stopped" && selected.record.value.nativeStop))
|
|
244
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the original native service disappeared without its recorded terminal stop; no replacement was launched", { target: instanceProjection(selected) });
|
|
245
|
+
if (declaredAdapter?.declaration.stop === "kernel-exit" && selected.record.value.process && !(selected.record.value.state === "stopped" && selected.record.value.kernelStop))
|
|
246
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the original broker process disappeared without this controller's recorded exact-exit stop; no replacement listener was launched over its store", { target: instanceProjection(selected) });
|
|
247
|
+
}
|
|
248
|
+
hold.check();
|
|
249
|
+
const now = new Date().toISOString(), id = options.brokerInstance?.instanceId ?? selected?.name ?? randomUUID(), launchRequestId = options.brokerInstance?.launchRequestId ?? randomUUID();
|
|
250
|
+
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 };
|
|
251
|
+
const store = serviceInstanceStore(value.space);
|
|
252
|
+
store.commit(id, selected, instance);
|
|
253
|
+
let row = store.read(id);
|
|
254
|
+
let adapter;
|
|
255
|
+
let launch;
|
|
256
|
+
try {
|
|
257
|
+
if (value.launch.type === "process")
|
|
258
|
+
launch = { program: program, args: value.launch.args, cwd: value.launch.cwd };
|
|
259
|
+
else {
|
|
260
|
+
// The manager adapter reads no stack journal, so its launch carries the facts it admits a settled restore against.
|
|
261
|
+
const stack = value.launch.adapter === "manager-service" && typeof value.launch.options.root === "string" ? maintenanceStackView(value.launch.options.root, value.space) : undefined;
|
|
262
|
+
const context = adapterContext(definition, instance, cliInvocation, options.attempt, stack);
|
|
263
|
+
const provider = await loadServiceAdapter(declaredAdapter, value.launch.options);
|
|
264
|
+
hold.check();
|
|
265
|
+
const plan = await adapterCall(() => provider.build(context), Math.min(10000, value.readiness.timeoutMs));
|
|
266
|
+
const validated = validateServiceDefinition({ ...value, launch: { type: "process", ...plan }, readiness: { type: "process", timeoutMs: value.readiness.timeoutMs } }, value.space);
|
|
267
|
+
if (validated.launch.type !== "process")
|
|
268
|
+
throw new Error("invalid adapter launch plan");
|
|
269
|
+
const executablePath = executable(validated);
|
|
270
|
+
if (provider.declaration.stop !== "native" && commandIsCotalSupervisor([executablePath, ...validated.launch.args].join(" ")))
|
|
271
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "the direct-process adapter ABI cannot bypass native manager agent-impact guards");
|
|
272
|
+
launch = { program: executablePath, args: validated.launch.args, cwd: validated.launch.cwd };
|
|
273
|
+
adapter = { provider, context };
|
|
274
|
+
}
|
|
275
|
+
hold.check();
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
const failure = isCommandFailure(error) ? error : isWorkspaceTargetError(error) ? targetRefusal(error) : undefined;
|
|
279
|
+
// No child is spawned above this point, so this incarnation has no process: the record is
|
|
280
|
+
// failed either way. Only the provider's own work stays unattributed on an unknown error.
|
|
281
|
+
row = transition(row, { state: "failed", readiness: "not-checked" });
|
|
282
|
+
if (failure?.outcome === "refused")
|
|
283
|
+
throw new CommandFailure("refused", failure.code, `service preparation was refused before a child launch: ${failure.message}`, { target: instanceProjection(row), native: { code: failure.code, outcome: failure.outcome, detail: failure.message }, remedy: failure.remedy });
|
|
284
|
+
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) });
|
|
285
|
+
}
|
|
286
|
+
const path = serviceLogPath(value.space, id, true);
|
|
287
|
+
let log;
|
|
288
|
+
let exitCode = null, exitSignal = null;
|
|
289
|
+
let exited = false;
|
|
290
|
+
let done;
|
|
291
|
+
const exit = new Promise((resolve) => { done = resolve; });
|
|
292
|
+
try {
|
|
293
|
+
if (!options.foreground) {
|
|
294
|
+
log = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW | constants.O_NONBLOCK, 0o600);
|
|
295
|
+
const info = fstatSync(log);
|
|
296
|
+
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
|
|
297
|
+
throw new Error("unprotected log target");
|
|
298
|
+
}
|
|
299
|
+
child = spawn(launch.program, [...launch.args], { cwd: launch.cwd, env, shell: false, detached: !options.foreground, stdio: options.foreground ? "inherit" : ["ignore", log, log] });
|
|
300
|
+
if (!options.foreground)
|
|
301
|
+
child.unref();
|
|
302
|
+
child.once("exit", (code, signal) => { exited = true; exitCode = code; exitSignal = signal; done(); });
|
|
303
|
+
await new Promise((resolve, reject) => { child.once("spawn", resolve); child.once("error", reject); });
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
row = transition(row, { state: "failed", readiness: "not-checked" });
|
|
307
|
+
throw new CommandFailure("failed", "OPERATION_FAILED", "the native process launch failed before a service child was established; its instance receipt was retained", { target: instanceProjection(row) });
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
if (log !== undefined)
|
|
311
|
+
closeSync(log);
|
|
312
|
+
}
|
|
313
|
+
if (!child.pid)
|
|
314
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the launch has no confirmed process ID; its instance intent was retained and no retry was made", { target: instanceProjection(row) });
|
|
315
|
+
let identity;
|
|
316
|
+
try {
|
|
317
|
+
identity = requireProcessIdentity(child.pid);
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
if (!exited)
|
|
321
|
+
child.kill("SIGTERM");
|
|
322
|
+
await Promise.race([exit, delay(3000)]);
|
|
323
|
+
row = transition(row, { state: exited ? "failed" : "unknown", ...(exited ? { exit: { code: exitCode, signal: exitSignal } } : {}) });
|
|
324
|
+
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) });
|
|
325
|
+
}
|
|
326
|
+
row = transition(row, { process: identity });
|
|
327
|
+
const running = await serviceReadiness(row, value, adapter);
|
|
328
|
+
return { instance: running, noOp: false, child, exit: { done: exit, observed: () => exited, result: () => ({ code: exitCode, signal: exitSignal }) } };
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
if (!held)
|
|
332
|
+
hold.release();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/** Native preview imports only the pinned provider and performs its caller-scoped read. No
|
|
336
|
+
* process signal, request publication or reservation is part of this pre-confirmation step. */
|
|
337
|
+
export async function prepareNativeServiceStop(definition, selected, withAgents = false, preserved) {
|
|
338
|
+
if (preserved && withAgents)
|
|
339
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "a preserved-exit stop retains agents; --with-agents cannot be combined with it");
|
|
340
|
+
const value = definition.record.value;
|
|
341
|
+
const declared = value.launch.type === "adapter" ? resolveServiceAdapter(value.launch.adapter, value.launch.options) : undefined;
|
|
342
|
+
if (declared?.declaration.stop !== "native") {
|
|
343
|
+
if (withAgents)
|
|
344
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "--with-agents requires a declared native stop policy; generic descendant signals were not substituted");
|
|
345
|
+
if (preserved)
|
|
346
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a preserved-exit stop requires a declared native stop policy");
|
|
347
|
+
return undefined;
|
|
348
|
+
}
|
|
349
|
+
if (!sameServiceAdapterPin(selected.record.value.adapter, declared.pin) || selected.record.value.definitionRevision !== definition.record.revision)
|
|
350
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected native service pins another definition or adapter revision");
|
|
351
|
+
if (selected.record.value.state === "stopped" && selected.record.value.nativeStop && gone(observeServiceProcess(selected.record.value)))
|
|
352
|
+
return undefined;
|
|
353
|
+
if (neverLaunched(selected.record.value))
|
|
354
|
+
return undefined;
|
|
355
|
+
if (observeServiceProcess(selected.record.value) !== "running" || !selected.record.value.process)
|
|
356
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service has no live attributable process for an impact read; no completed stop was inferred from disappearance", { target: instanceProjection(selected) });
|
|
357
|
+
const provider = await loadServiceAdapter(declared, value.launch.type === "adapter" ? value.launch.options : {});
|
|
358
|
+
const began = Date.now();
|
|
359
|
+
const plan = ownedMetadata(serviceAdapterStopPlan(await adapterCall((signal) => provider.prepareStop({ ...adapterContext(definition, selected.record.value), process: { ...selected.record.value.process }, withAgents, ...(preserved ? { preserved: { ...preserved } } : {}), signal }), 15000), selected.record.value.process));
|
|
360
|
+
if (plan.withAgents !== withAgents || !samePreserved(plan.preserved, preserved) || Date.parse(plan.observedAt) < began - 1000 || Date.parse(plan.observedAt) > Date.now() + 1000)
|
|
361
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native stop preview did not establish the requested current policy");
|
|
362
|
+
return plan;
|
|
363
|
+
}
|
|
364
|
+
/** Kernel-exit preview imports only the pinned provider and reads its exact binding and dependant
|
|
365
|
+
* guards. No signal, reservation or record write is part of this pre-confirmation step. */
|
|
366
|
+
export async function prepareKernelServiceStop(definition, selected) {
|
|
367
|
+
const value = definition.record.value;
|
|
368
|
+
const declared = value.launch.type === "adapter" ? resolveServiceAdapter(value.launch.adapter, value.launch.options) : undefined;
|
|
369
|
+
if (declared?.declaration.stop !== "kernel-exit")
|
|
370
|
+
return undefined;
|
|
371
|
+
if (!sameServiceAdapterPin(selected.record.value.adapter, declared.pin) || selected.record.value.definitionRevision !== definition.record.revision || selected.record.value.kernelStopRequired !== true)
|
|
372
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected broker pins another definition, adapter revision or stop policy");
|
|
373
|
+
if (selected.record.value.state === "stopped" && selected.record.value.kernelStop && gone(observeServiceProcess(selected.record.value)))
|
|
374
|
+
return undefined;
|
|
375
|
+
if (neverLaunched(selected.record.value))
|
|
376
|
+
return undefined;
|
|
377
|
+
if (selected.record.value.state === "stopping")
|
|
378
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "an earlier broker stop request is retained without its exact-exit receipt; it was not resubmitted", { target: instanceProjection(selected) });
|
|
379
|
+
if (observeServiceProcess(selected.record.value) !== "running" || !selected.record.value.process)
|
|
380
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker has no live attributable process for a stop scope; disappearance was not treated as a completed stop", { target: instanceProjection(selected) });
|
|
381
|
+
const provider = await loadServiceAdapter(declared, value.launch.type === "adapter" ? value.launch.options : {});
|
|
382
|
+
const began = Date.now();
|
|
383
|
+
const plan = ownedMetadata(serviceAdapterKernelStopPlan(await adapterCall((signal) => provider.prepareKernelStop({ ...adapterContext(definition, selected.record.value), process: { ...selected.record.value.process }, signal }), 15000)));
|
|
384
|
+
if (Date.parse(plan.observedAt) < began - 1000 || Date.parse(plan.observedAt) > Date.now() + 1000)
|
|
385
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker stop scope was not observed now");
|
|
386
|
+
return plan;
|
|
387
|
+
}
|
|
388
|
+
/** Whole-set eligibility read before any member is stopped. The actual stop retains its own
|
|
389
|
+
* per-effect checks: a cooperative definition reservation does not freeze a live process. */
|
|
390
|
+
export function preflightProcessServiceStop(definition, selected) {
|
|
391
|
+
assertNoServiceUnitAttempts(selected.record.value.space, definition.name);
|
|
392
|
+
const current = serviceInstanceStore(selected.record.value.space).read(selected.name);
|
|
393
|
+
if (!current || current.record.revision !== selected.record.revision || current.hash !== selected.hash)
|
|
394
|
+
throw new CommandFailure("refused", "CONFLICT", "a selected service instance changed during set preflight; no service was stopped");
|
|
395
|
+
refuseRecordedSupervisor(current.record.value, "stop");
|
|
396
|
+
const value = current.record.value, state = observeServiceProcess(value), launch = definition.record.value.launch;
|
|
397
|
+
if (neverLaunched(value))
|
|
398
|
+
return;
|
|
399
|
+
const declared = launch.type === "adapter" ? resolveServiceAdapter(launch.adapter, launch.options) : undefined;
|
|
400
|
+
if (declared?.declaration.stop === "native") {
|
|
401
|
+
if (!sameServiceAdapterPin(value.adapter, declared.pin) || value.definitionRevision !== definition.record.revision)
|
|
402
|
+
throw new CommandFailure("refused", "CONFLICT", "a selected native incarnation pins another definition or adapter; no service was stopped");
|
|
403
|
+
if (gone(state) && value.state === "stopped" && value.nativeStop)
|
|
404
|
+
return;
|
|
405
|
+
if (state !== "running" || !value.process)
|
|
406
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "a selected native service has no attributable live process or retained returned stop; no new stop was submitted");
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (value.nativeStopRequired)
|
|
410
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a selected instance requires its original native stop policy; a set stop cannot replace it with process signals");
|
|
411
|
+
if (value.kernelStopRequired || declared?.declaration.stop === "kernel-exit")
|
|
412
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a selected broker requires its exact kernel-exit stop and dependant scope; a named service set does not integrate that policy, so no service was stopped", { remedy: "stop the broker alone with cotal service stop <name> --instance <full-id> after its dependants are stopped" });
|
|
413
|
+
if (gone(state))
|
|
414
|
+
return;
|
|
415
|
+
if (state !== "running" || !value.process)
|
|
416
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a selected service process is foreign, unreadable or unresolved; no service was stopped");
|
|
417
|
+
const command = readProcessCommand(value.process.pid);
|
|
418
|
+
if (command.kind !== "command" || commandIsCotalSupervisor(command.command))
|
|
419
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a selected process has an unreadable or manager-supervisor role; no generic set stop bypassed its native impact policy");
|
|
420
|
+
}
|
|
421
|
+
/** Only the stored creation-pinned process is signalled. Every escalation rechecks its identity. */
|
|
422
|
+
export async function stopProcessService(definition, selected, held, native, kernel) {
|
|
423
|
+
const hold = held ?? serviceDefinitionStore(definition.record.value.space).pin(definition);
|
|
424
|
+
try {
|
|
425
|
+
assertNoServiceUnitAttempts(selected.record.value.space, definition.name);
|
|
426
|
+
const store = serviceInstanceStore(selected.record.value.space), current = store.read(selected.name);
|
|
427
|
+
if (!current || current.record.revision !== selected.record.revision || current.hash !== selected.hash)
|
|
428
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected instance changed before stop; no process was signalled");
|
|
429
|
+
let row = current;
|
|
430
|
+
refuseRecordedSupervisor(row.record.value, "stop");
|
|
431
|
+
const initial = observeServiceProcess(row.record.value);
|
|
432
|
+
const launch = definition.record.value.launch;
|
|
433
|
+
const declared = launch.type === "adapter" ? resolveServiceAdapter(launch.adapter, launch.options) : undefined;
|
|
434
|
+
if (declared?.declaration.stop === "native") {
|
|
435
|
+
if (!sameServiceAdapterPin(row.record.value.adapter, declared.pin) || row.record.value.definitionRevision !== definition.record.revision)
|
|
436
|
+
throw new CommandFailure("refused", "CONFLICT", "the native service incarnation pins another definition or adapter; it was not controlled");
|
|
437
|
+
if (gone(initial) && row.record.value.state === "stopped" && row.record.value.nativeStop)
|
|
438
|
+
return { instance: row, noOp: true, nativeStop: row.record.value.nativeStop };
|
|
439
|
+
if (neverLaunched(row.record.value))
|
|
440
|
+
return { instance: row, noOp: true };
|
|
441
|
+
if (initial !== "running" || !row.record.value.process)
|
|
442
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "native stop has no current attributable process or retained returned receipt; disappearance was not treated as completion", { target: instanceProjection(row) });
|
|
443
|
+
if (!native?.plan)
|
|
444
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "native service stop requires its current caller-scoped impact and explicit confirmation; generic signals were not used");
|
|
445
|
+
const plan = serviceAdapterStopPlan(native.plan, row.record.value.process);
|
|
446
|
+
if (plan.withAgents !== native.withAgents || !samePreserved(plan.preserved, native.preserved))
|
|
447
|
+
throw new CommandFailure("refused", "CONFLICT", "the confirmed native stop policy differs from the submitted policy");
|
|
448
|
+
const provider = await loadServiceAdapter(declared, launch.type === "adapter" ? launch.options : {});
|
|
449
|
+
hold.check();
|
|
450
|
+
// A preserved-exit caller journals its attempt first and passes that attempt's request ID.
|
|
451
|
+
if (native.preserved && !native.requestId)
|
|
452
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "a preserved-exit stop needs its journaled attempt's request ID; no request was published");
|
|
453
|
+
const requestId = native.requestId ?? randomUUID(), target = { ...row.record.value.process }, began = Date.now();
|
|
454
|
+
row = transition(row, { state: "stopping", requestId });
|
|
455
|
+
let returned = false;
|
|
456
|
+
try {
|
|
457
|
+
const raw = await adapterCall((signal) => provider.stop({ ...adapterContext(definition, row.record.value), process: target, withAgents: native.withAgents, ...(native.preserved ? { preserved: { ...native.preserved } } : {}), requestId, plan, signal }), 45000);
|
|
458
|
+
returned = true;
|
|
459
|
+
const result = serviceAdapterStopResult(raw);
|
|
460
|
+
// The terminal kind must answer the submitted request: a preserved stop returns only
|
|
461
|
+
// `preserved-exit-returned`, an ordinary stop only `returned`.
|
|
462
|
+
if (result.nativeStop !== (native.preserved ? "preserved-exit-returned" : "returned") || result.requestId !== requestId || result.scopeSha256 !== plan.scopeSha256 || result.process.pid !== target.pid || result.process.token !== target.token || Date.parse(result.observedAt) < began - 1000 || Date.parse(result.observedAt) > Date.now() + 1000 || !gone(observeServiceProcess(row.record.value)))
|
|
463
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service did not confirm both its original returned stop and the exact process exit");
|
|
464
|
+
return { instance: transition(row, { state: "stopped", readiness: "not-checked", nativeStop: result }), noOp: false, nativeStop: result };
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
const refused = !returned && isCommandFailure(error) && error.outcome === "refused";
|
|
468
|
+
row = transition(row, { state: refused && observeServiceProcess(row.record.value) === "running" ? "running" : "unknown", readiness: "not-checked" });
|
|
469
|
+
if (isCommandFailure(error) && (!returned || error.outcome !== "refused"))
|
|
470
|
+
throw error;
|
|
471
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service stop did not confirm its original terminal receipt; no signal escalation or restart was attempted", { target: instanceProjection(row) });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (declared?.declaration.stop === "kernel-exit")
|
|
475
|
+
return await stopKernelService(definition, row, hold, declared, initial, native, kernel);
|
|
476
|
+
if (row.record.value.nativeStopRequired)
|
|
477
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "the retained instance requires its original native stop policy; no generic signal path was substituted");
|
|
478
|
+
if (row.record.value.kernelStopRequired)
|
|
479
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "the retained instance requires its exact kernel-exit stop policy from its pinned adapter; no generic signal path was substituted");
|
|
480
|
+
if (native?.withAgents)
|
|
481
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "generic process stop does not accept an agent-reap policy");
|
|
482
|
+
if (gone(initial))
|
|
483
|
+
return { instance: transition(row, { state: "stopped", readiness: "not-checked" }), noOp: true };
|
|
484
|
+
if (initial !== "running" || !row.record.value.process)
|
|
485
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "the selected process is foreign, unreadable or unresolved; it was not signalled", { target: instanceProjection(row) });
|
|
486
|
+
const command = readProcessCommand(row.record.value.process.pid);
|
|
487
|
+
if (command.kind !== "command" || commandIsCotalSupervisor(command.command))
|
|
488
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "generic process stop cannot bypass manager agent-impact guards or an unreadable process role; use its supported service adapter. No signal was sent", { target: instanceProjection(row) });
|
|
489
|
+
row = transition(row, { state: "stopping", requestId: randomUUID() });
|
|
490
|
+
// The receipt names the last signal this call itself delivered to the pinned process. A process
|
|
491
|
+
// that was already gone before any delivery gets no receipt: absence is not a stop.
|
|
492
|
+
let delivered;
|
|
493
|
+
const signal = (name) => {
|
|
494
|
+
const state = observeServiceProcess(row.record.value);
|
|
495
|
+
if (gone(state))
|
|
496
|
+
return;
|
|
497
|
+
if (state !== "running")
|
|
498
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "service ownership became uncertain before signalling; its record was retained", { target: instanceProjection(row) });
|
|
499
|
+
const role = readProcessCommand(row.record.value.process.pid);
|
|
500
|
+
if (role.kind !== "command" || commandIsCotalSupervisor(role.command))
|
|
501
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the process role changed or became unreadable before signalling; manager impact guards were not bypassed", { target: instanceProjection(row) });
|
|
502
|
+
const identity = assertRecordIdentity(row.record.value.process);
|
|
503
|
+
if (identity.kind !== "match")
|
|
504
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the exact process incarnation changed before a signal; no successor was signalled", { target: instanceProjection(row) });
|
|
505
|
+
try {
|
|
506
|
+
process.kill(row.record.value.process.pid, name);
|
|
507
|
+
delivered = name;
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
if (error.code !== "ESRCH")
|
|
511
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the exact process signal was not confirmed; its record was retained", { target: instanceProjection(row) });
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
signal("SIGTERM");
|
|
515
|
+
for (const [timeout, escalation] of [[15000, "SIGKILL"], [3000, undefined]]) {
|
|
516
|
+
const deadline = Date.now() + timeout;
|
|
517
|
+
while (Date.now() < deadline) {
|
|
518
|
+
const state = observeServiceProcess(row.record.value);
|
|
519
|
+
if (gone(state))
|
|
520
|
+
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 };
|
|
521
|
+
if (state !== "running")
|
|
522
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the service exit could not be established; its identity and stop receipt were retained", { target: instanceProjection(row) });
|
|
523
|
+
await delay(100);
|
|
524
|
+
}
|
|
525
|
+
if (escalation)
|
|
526
|
+
signal(escalation);
|
|
527
|
+
}
|
|
528
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the selected service process did not confirm exit; its record was retained and no restart was attempted", { target: instanceProjection(row) });
|
|
529
|
+
}
|
|
530
|
+
finally {
|
|
531
|
+
if (!held)
|
|
532
|
+
hold.release();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/** The broker's exact kernel-exit stop. It signals only the creation-pinned child after the
|
|
536
|
+
* confirmed scope is recomputed unchanged, waits for that exact process to exit and records the
|
|
537
|
+
* observed exit. A retained `stopping` request, an exit this call did not cause, or an exit not
|
|
538
|
+
* observed before the deadline stays unknown: no SIGKILL, resubmission or restart follows. */
|
|
539
|
+
async function stopKernelService(definition, current, hold, declared, initial, native, kernel) {
|
|
540
|
+
let row = current;
|
|
541
|
+
const value = row.record.value, launch = definition.record.value.launch;
|
|
542
|
+
if (native?.withAgents)
|
|
543
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "a broker kernel-exit stop has no agent policy; --with-agents belongs to the exact manager instance");
|
|
544
|
+
if (!sameServiceAdapterPin(value.adapter, declared.pin) || value.definitionRevision !== definition.record.revision || value.kernelStopRequired !== true)
|
|
545
|
+
throw new CommandFailure("refused", "CONFLICT", "the broker incarnation pins another definition, adapter or stop policy; it was not controlled", { target: instanceProjection(row) });
|
|
546
|
+
if (gone(initial) && value.state === "stopped" && value.kernelStop)
|
|
547
|
+
return { instance: row, noOp: true, kernelStop: value.kernelStop };
|
|
548
|
+
if (neverLaunched(value))
|
|
549
|
+
return { instance: row, noOp: true };
|
|
550
|
+
if (value.state === "stopping")
|
|
551
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "an earlier broker stop request is retained without its exact-exit receipt; it was not resubmitted", { target: instanceProjection(row) });
|
|
552
|
+
if (initial !== "running" || !value.process)
|
|
553
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker has no current attributable process or retained exact-exit receipt; disappearance was not treated as a completed stop", { target: instanceProjection(row) });
|
|
554
|
+
if (!kernel?.plan)
|
|
555
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a broker stop requires its current exact scope and explicit confirmation; no signal was sent");
|
|
556
|
+
const confirmed = serviceAdapterKernelStopPlan(kernel.plan);
|
|
557
|
+
const provider = await loadServiceAdapter(declared, launch.type === "adapter" ? launch.options : {});
|
|
558
|
+
hold.check();
|
|
559
|
+
const target = { ...value.process };
|
|
560
|
+
const fresh = serviceAdapterKernelStopPlan(await adapterCall((signal) => provider.prepareKernelStop({ ...adapterContext(definition, value), process: target, signal }), 15000));
|
|
561
|
+
if (fresh.scopeSha256 !== confirmed.scopeSha256 || serviceMetadataDigest(fresh.binding) !== serviceMetadataDigest(confirmed.binding))
|
|
562
|
+
throw new CommandFailure("refused", "CONFLICT", "the broker binding or dependant scope changed after confirmation; no signal was sent", { target: instanceProjection(row) });
|
|
563
|
+
hold.check();
|
|
564
|
+
const role = readProcessCommand(target.pid);
|
|
565
|
+
if (role.kind !== "command" || commandIsCotalSupervisor(role.command) || assertRecordIdentity(target).kind !== "match")
|
|
566
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "the broker process identity or role could not be re-established immediately before the signal; no signal was sent", { target: instanceProjection(row) });
|
|
567
|
+
const requestId = randomUUID();
|
|
568
|
+
row = transition(row, { state: "stopping", requestId });
|
|
569
|
+
try {
|
|
570
|
+
if (assertRecordIdentity(target).kind !== "match")
|
|
571
|
+
throw new Error("identity changed");
|
|
572
|
+
process.kill(target.pid, "SIGTERM");
|
|
573
|
+
}
|
|
574
|
+
catch {
|
|
575
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the exact broker signal was not confirmed delivered to the pinned process; its stop request was retained and no exit was attributed to it", { target: instanceProjection(row) });
|
|
576
|
+
}
|
|
577
|
+
const deadline = Date.now() + 30000;
|
|
578
|
+
while (Date.now() < deadline) {
|
|
579
|
+
const state = observeServiceProcess(row.record.value);
|
|
580
|
+
if (gone(state)) {
|
|
581
|
+
let trace = "ports-file-retained";
|
|
582
|
+
try {
|
|
583
|
+
trace = provider.observeKernelStop({ ...adapterContext(definition, row.record.value), process: target });
|
|
584
|
+
}
|
|
585
|
+
catch { /* The observed exit stands; an unreadable trace is reported as retained, never removed. */ }
|
|
586
|
+
const kernelStop = serviceAdapterKernelStopResult({ kind: "kernel-exit", requestId, scopeSha256: confirmed.scopeSha256, process: target, observation: "exact-process-exit", brokerShutdownTrace: trace, cleanup: "not-checked", observedAt: new Date().toISOString() });
|
|
587
|
+
return { instance: transition(row, { state: "stopped", readiness: "not-checked", kernelStop }), noOp: false, kernelStop };
|
|
588
|
+
}
|
|
589
|
+
if (state !== "running")
|
|
590
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker exit could not be attributed; its stop request was retained", { target: instanceProjection(row) });
|
|
591
|
+
await delay(100);
|
|
592
|
+
}
|
|
593
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker did not exit within its stop window; the request was retained without force kill or restart", { target: instanceProjection(row), remedy: "inspect the exact broker instance before another action; a later stop of this instance is refused until it is reconciled" });
|
|
594
|
+
}
|
|
595
|
+
export function assertNoServiceUnitAttempts(space, name) {
|
|
596
|
+
const pending = [...serviceInstallIntents(space), ...serviceUninstallIntents(space)].filter((row) => row.record.value.definition === name);
|
|
597
|
+
const nativeActions = serviceUnitActionStore(space).list();
|
|
598
|
+
if (nativeActions.some((row) => row.name !== row.record.value.instanceId))
|
|
599
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", "a native action filename differs from its full instance ID; no process effect was submitted");
|
|
600
|
+
const actions = nativeActions.filter((row) => row.record.value.definition === name);
|
|
601
|
+
if (pending.length || actions.length)
|
|
602
|
+
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 })) } });
|
|
603
|
+
}
|
|
604
|
+
export function removableServiceInstances(space, name) {
|
|
605
|
+
const pending = [...serviceInstallIntents(space), ...serviceUninstallIntents(space)].filter((row) => row.record.value.definition === name);
|
|
606
|
+
if (pending.length)
|
|
607
|
+
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" });
|
|
608
|
+
const nativeActions = serviceUnitActionStore(space).list();
|
|
609
|
+
if (nativeActions.some((row) => row.name !== row.record.value.instanceId))
|
|
610
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", "a native action filename differs from its full instance ID; no definition was removed");
|
|
611
|
+
const actions = nativeActions.filter((row) => row.record.value.definition === name);
|
|
612
|
+
if (actions.length)
|
|
613
|
+
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 })) } });
|
|
614
|
+
const rows = serviceInstances(space, name);
|
|
615
|
+
for (const row of rows)
|
|
616
|
+
refuseRecordedSupervisor(row.record.value, "remove");
|
|
617
|
+
for (const row of rows)
|
|
618
|
+
if (!gone(observeServiceProcess(row.record.value)))
|
|
619
|
+
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` });
|
|
620
|
+
for (const row of rows)
|
|
621
|
+
if (row.record.value.nativeStopRequired && row.record.value.process && !row.record.value.nativeStop)
|
|
622
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service has no confirmed terminal stop; its launch and unknown request cannot be forgotten merely because the process disappeared", { target: instanceProjection(row) });
|
|
623
|
+
for (const row of rows)
|
|
624
|
+
if (row.record.value.kernelStopRequired && row.record.value.process && !row.record.value.kernelStop)
|
|
625
|
+
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) });
|
|
626
|
+
return rows;
|
|
627
|
+
}
|
|
628
|
+
/** Called under the definition writer lock, after stopped/host/supervisor checks for every row. */
|
|
629
|
+
export function removeStoppedInstanceRecords(space, name) {
|
|
630
|
+
const rows = removableServiceInstances(space, name), removed = [];
|
|
631
|
+
try {
|
|
632
|
+
for (const row of rows) {
|
|
633
|
+
serviceInstanceStore(space).commit(row.name, row, undefined);
|
|
634
|
+
removed.push(row.name);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
catch (error) {
|
|
638
|
+
if (!removed.length)
|
|
639
|
+
throw error;
|
|
640
|
+
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" });
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
/** Read only bounded regular-file bytes; log data is not promised to be secret-redacted. */
|
|
644
|
+
export function readServiceLog(space, id, tail) {
|
|
645
|
+
const path = serviceLogPath(space, id);
|
|
646
|
+
if (!path)
|
|
647
|
+
return { lines: [], omittedBytes: 0, path: null };
|
|
648
|
+
let fd;
|
|
649
|
+
try {
|
|
650
|
+
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
651
|
+
}
|
|
652
|
+
catch (error) {
|
|
653
|
+
if (error.code === "ENOENT")
|
|
654
|
+
return { lines: [], omittedBytes: 0, path };
|
|
655
|
+
throw error;
|
|
656
|
+
}
|
|
657
|
+
try {
|
|
658
|
+
const info = fstatSync(fd);
|
|
659
|
+
if (![info.size, info.dev, info.ino].every((number) => Number.isSafeInteger(number) && number >= 0))
|
|
660
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this log's native file coordinates cannot be represented safely; no approximate byte offsets were reported");
|
|
661
|
+
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
|
|
662
|
+
throw new CommandFailure("refused", "PERMISSION_DENIED", "the service log is not an owned private regular file");
|
|
663
|
+
const length = Math.min(info.size, 1024 * 1024), start = info.size - length;
|
|
664
|
+
const buffer = Buffer.alloc(length);
|
|
665
|
+
let offset = 0;
|
|
666
|
+
while (offset < length) {
|
|
667
|
+
const count = readSync(fd, buffer, offset, length - offset, start + offset);
|
|
668
|
+
if (!count)
|
|
669
|
+
break;
|
|
670
|
+
offset += count;
|
|
671
|
+
}
|
|
672
|
+
let text = buffer.subarray(0, offset).toString("utf8");
|
|
673
|
+
if (start)
|
|
674
|
+
text = text.includes("\n") ? text.slice(text.indexOf("\n") + 1) : "";
|
|
675
|
+
const all = text.replace(/\n$/, "").split("\n");
|
|
676
|
+
return { lines: text ? all.slice(-tail) : [], omittedBytes: start, path };
|
|
677
|
+
}
|
|
678
|
+
finally {
|
|
679
|
+
closeSync(fd);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/** One bounded raw log slice. File identity and byte offsets are local file facts, not global sequences. */
|
|
683
|
+
export function serviceLogSlice(space, id, position, tail) {
|
|
684
|
+
const path = serviceLogPath(space, id);
|
|
685
|
+
if (!path)
|
|
686
|
+
return undefined;
|
|
687
|
+
let fd;
|
|
688
|
+
try {
|
|
689
|
+
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
690
|
+
}
|
|
691
|
+
catch (error) {
|
|
692
|
+
if (error.code === "ENOENT")
|
|
693
|
+
return undefined;
|
|
694
|
+
throw error;
|
|
695
|
+
}
|
|
696
|
+
try {
|
|
697
|
+
const info = fstatSync(fd);
|
|
698
|
+
if (![info.size, info.dev, info.ino].every((number) => Number.isSafeInteger(number) && number >= 0))
|
|
699
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this log's native file coordinates cannot be represented safely; no approximate byte offsets were reported");
|
|
700
|
+
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
|
|
701
|
+
throw new CommandFailure("refused", "PERMISSION_DENIED", "the selected service log is not an owned private regular file");
|
|
702
|
+
const replaced = position !== undefined && (position.dev !== info.dev || position.ino !== info.ino);
|
|
703
|
+
const truncated = position !== undefined && !replaced && info.size < position.offset;
|
|
704
|
+
let offset = position && !replaced && !truncated ? position.offset : 0;
|
|
705
|
+
let omittedBytes = 0;
|
|
706
|
+
if (!position || replaced || truncated) {
|
|
707
|
+
const length = Math.min(info.size, 1024 * 1024), start = info.size - length;
|
|
708
|
+
const sample = Buffer.alloc(length);
|
|
709
|
+
let read = 0;
|
|
710
|
+
while (read < length) {
|
|
711
|
+
const count = readSync(fd, sample, read, length - read, start + read);
|
|
712
|
+
if (!count)
|
|
713
|
+
break;
|
|
714
|
+
read += count;
|
|
715
|
+
}
|
|
716
|
+
let cursor = read && sample[read - 1] === 10 ? read - 1 : read;
|
|
717
|
+
for (let count = 0; count < tail; count++) {
|
|
718
|
+
if (cursor <= 0) {
|
|
719
|
+
cursor = -1;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
cursor = sample.lastIndexOf(10, cursor - 1);
|
|
723
|
+
if (cursor < 0)
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
offset = start + cursor + 1;
|
|
727
|
+
omittedBytes = offset;
|
|
728
|
+
}
|
|
729
|
+
else if (info.size - offset > 1024 * 1024) {
|
|
730
|
+
const next = info.size - 1024 * 1024;
|
|
731
|
+
omittedBytes = next - offset;
|
|
732
|
+
offset = next;
|
|
733
|
+
}
|
|
734
|
+
const buffer = Buffer.alloc(Math.min(16_384, Math.max(0, info.size - offset)));
|
|
735
|
+
const count = buffer.length ? readSync(fd, buffer, 0, buffer.length, offset) : 0;
|
|
736
|
+
return { file: { dev: info.dev, ino: info.ino }, fromOffset: offset, toOffset: offset + count, sizeAtRead: info.size, bytes: buffer.subarray(0, count), omittedBytes, replaced, truncated };
|
|
737
|
+
}
|
|
738
|
+
finally {
|
|
739
|
+
closeSync(fd);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
//# sourceMappingURL=service-process.js.map
|