@hoknie/aip 0.1.0 → 0.2.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/app/agents.js +2 -0
- package/dist/app/agents.js.map +1 -1
- package/dist/app/application.js +34 -2
- package/dist/app/application.js.map +1 -1
- package/dist/app/lifecycle.js +5 -1
- package/dist/app/lifecycle.js.map +1 -1
- package/dist/app/timings.js +1 -0
- package/dist/app/timings.js.map +1 -1
- package/dist/app/wiring.js +1 -0
- package/dist/app/wiring.js.map +1 -1
- package/dist/cli/main.js +0 -0
- package/dist/feature/agents/clients/agy/runtime.js +1 -0
- package/dist/feature/agents/clients/agy/runtime.js.map +1 -1
- package/dist/feature/agents/clients/claude/index.js +1 -0
- package/dist/feature/agents/clients/claude/index.js.map +1 -1
- package/dist/feature/agents/clients/claude/models.js +8 -0
- package/dist/feature/agents/clients/claude/models.js.map +1 -0
- package/dist/feature/agents/clients/claude/parser.js +8 -0
- package/dist/feature/agents/clients/claude/parser.js.map +1 -1
- package/dist/feature/agents/clients/claude/runtime.js +2 -0
- package/dist/feature/agents/clients/claude/runtime.js.map +1 -1
- package/dist/feature/agents/clients/opencode/index.js +1 -0
- package/dist/feature/agents/clients/opencode/index.js.map +1 -1
- package/dist/feature/agents/clients/opencode/models.js +38 -0
- package/dist/feature/agents/clients/opencode/models.js.map +1 -0
- package/dist/feature/agents/clients/opencode/runtime.js +2 -0
- package/dist/feature/agents/clients/opencode/runtime.js.map +1 -1
- package/dist/feature/agents/ports/command.js +2 -0
- package/dist/feature/agents/ports/command.js.map +1 -0
- package/dist/feature/agents/services/agents.js +42 -1
- package/dist/feature/agents/services/agents.js.map +1 -1
- package/dist/feature/agents/services/catalog.js +1 -1
- package/dist/feature/agents/services/catalog.js.map +1 -1
- package/dist/feature/agents/types/index.js +1 -0
- package/dist/feature/agents/types/index.js.map +1 -1
- package/dist/feature/agents/types/message.js +1 -0
- package/dist/feature/agents/types/message.js.map +1 -1
- package/dist/feature/agents/types/models.js +2 -0
- package/dist/feature/agents/types/models.js.map +1 -0
- package/dist/feature/agents/types/runtime.js.map +1 -1
- package/dist/feature/agents/types/worker-tools.js +2 -0
- package/dist/feature/agents/types/worker-tools.js.map +1 -1
- package/dist/feature/network/ports/changed.js +2 -0
- package/dist/feature/network/ports/changed.js.map +1 -0
- package/dist/feature/network/ports/index.js +2 -0
- package/dist/feature/network/ports/index.js.map +1 -0
- package/dist/feature/network/services/create.js +5 -0
- package/dist/feature/network/services/create.js.map +1 -0
- package/dist/feature/network/services/index.js +3 -0
- package/dist/feature/network/services/index.js.map +1 -0
- package/dist/feature/network/services/monitor.js +140 -0
- package/dist/feature/network/services/monitor.js.map +1 -0
- package/dist/feature/network/types/index.js +4 -0
- package/dist/feature/network/types/index.js.map +1 -0
- package/dist/feature/network/types/network.js +8 -0
- package/dist/feature/network/types/network.js.map +1 -0
- package/dist/feature/network/types/proxy.js +95 -0
- package/dist/feature/network/types/proxy.js.map +1 -0
- package/dist/feature/network/types/state.js +36 -0
- package/dist/feature/network/types/state.js.map +1 -0
- package/dist/feature/observers/repositories/observers.js +7 -1
- package/dist/feature/observers/repositories/observers.js.map +1 -1
- package/dist/feature/observers/services/observers.js +14 -4
- package/dist/feature/observers/services/observers.js.map +1 -1
- package/dist/feature/observers/services/settings-check.js +1 -7
- package/dist/feature/observers/services/settings-check.js.map +1 -1
- package/dist/feature/observers/types/plan-repairs.js +14 -7
- package/dist/feature/observers/types/plan-repairs.js.map +1 -1
- package/dist/feature/observers/types/settings.js +0 -1
- package/dist/feature/observers/types/settings.js.map +1 -1
- package/dist/feature/queue/services/control.js +23 -7
- package/dist/feature/queue/services/control.js.map +1 -1
- package/dist/feature/queue/types/advance.js +26 -11
- package/dist/feature/queue/types/advance.js.map +1 -1
- package/dist/feature/queue/types/returns.js +18 -3
- package/dist/feature/queue/types/returns.js.map +1 -1
- package/dist/feature/runs/machine/exits.js +23 -1
- package/dist/feature/runs/machine/exits.js.map +1 -1
- package/dist/feature/runs/machine/plan.js +38 -16
- package/dist/feature/runs/machine/plan.js.map +1 -1
- package/dist/feature/runs/machine/repair.js +5 -2
- package/dist/feature/runs/machine/repair.js.map +1 -1
- package/dist/feature/runs/machine/scheduler.js +10 -3
- package/dist/feature/runs/machine/scheduler.js.map +1 -1
- package/dist/feature/runs/machine/steps.js +7 -7
- package/dist/feature/runs/machine/steps.js.map +1 -1
- package/dist/feature/runs/machine/transition.js +5 -1
- package/dist/feature/runs/machine/transition.js.map +1 -1
- package/dist/feature/runs/repositories/finished-runs.js +14 -10
- package/dist/feature/runs/repositories/finished-runs.js.map +1 -1
- package/dist/feature/runs/services/create.js +1 -0
- package/dist/feature/runs/services/create.js.map +1 -1
- package/dist/feature/runs/services/effects/actions.js +3 -2
- package/dist/feature/runs/services/effects/actions.js.map +1 -1
- package/dist/feature/runs/services/effects/attempts.js +44 -4
- package/dist/feature/runs/services/effects/attempts.js.map +1 -1
- package/dist/feature/runs/services/effects/context.js.map +1 -1
- package/dist/feature/runs/services/effects/naming.js +4 -1
- package/dist/feature/runs/services/effects/naming.js.map +1 -1
- package/dist/feature/runs/services/effects/proxy.js +5 -0
- package/dist/feature/runs/services/effects/proxy.js.map +1 -0
- package/dist/feature/runs/services/engine.js +14 -5
- package/dist/feature/runs/services/engine.js.map +1 -1
- package/dist/feature/runs/services/index.js.map +1 -1
- package/dist/feature/runs/services/reads.js +40 -1
- package/dist/feature/runs/services/reads.js.map +1 -1
- package/dist/feature/runs/services/states.js +2 -2
- package/dist/feature/runs/services/states.js.map +1 -1
- package/dist/feature/runs/types/attempt.js +4 -0
- package/dist/feature/runs/types/attempt.js.map +1 -1
- package/dist/feature/runs/types/group.js.map +1 -1
- package/dist/feature/runs/types/input.js +33 -0
- package/dist/feature/runs/types/input.js.map +1 -1
- package/dist/feature/runs/types/limits.js +13 -1
- package/dist/feature/runs/types/limits.js.map +1 -1
- package/dist/feature/stats/repositories/index.js +4 -0
- package/dist/feature/stats/repositories/index.js.map +1 -0
- package/dist/feature/stats/repositories/meta.js +19 -0
- package/dist/feature/stats/repositories/meta.js.map +1 -0
- package/dist/feature/stats/repositories/records.js +46 -0
- package/dist/feature/stats/repositories/records.js.map +1 -0
- package/dist/feature/stats/repositories/report.js +105 -0
- package/dist/feature/stats/repositories/report.js.map +1 -0
- package/dist/feature/stats/services/create.js +44 -0
- package/dist/feature/stats/services/create.js.map +1 -0
- package/dist/feature/stats/services/index.js +4 -0
- package/dist/feature/stats/services/index.js.map +1 -0
- package/dist/feature/stats/services/ledger.js +137 -0
- package/dist/feature/stats/services/ledger.js.map +1 -0
- package/dist/feature/stats/services/report.js +56 -0
- package/dist/feature/stats/services/report.js.map +1 -0
- package/dist/feature/stats/types/aggregate.js +179 -0
- package/dist/feature/stats/types/aggregate.js.map +1 -0
- package/dist/feature/stats/types/capture.js +79 -0
- package/dist/feature/stats/types/capture.js.map +1 -0
- package/dist/feature/stats/types/index.js +6 -0
- package/dist/feature/stats/types/index.js.map +1 -0
- package/dist/feature/stats/types/records.js +5 -0
- package/dist/feature/stats/types/records.js.map +1 -0
- package/dist/feature/stats/types/report.js +25 -0
- package/dist/feature/stats/types/report.js.map +1 -0
- package/dist/feature/stats/types/settings.js +2 -0
- package/dist/feature/stats/types/settings.js.map +1 -0
- package/dist/feature/swarm-config/services/assemble.js +1 -1
- package/dist/feature/swarm-config/services/assemble.js.map +1 -1
- package/dist/feature/swarm-config/services/index.js +3 -2
- package/dist/feature/swarm-config/services/index.js.map +1 -1
- package/dist/feature/swarm-config/services/load.js +17 -2
- package/dist/feature/swarm-config/services/load.js.map +1 -1
- package/dist/feature/swarm-config/services/sections/stats.js +28 -0
- package/dist/feature/swarm-config/services/sections/stats.js.map +1 -0
- package/dist/feature/swarm-config/services/settings.js +23 -1
- package/dist/feature/swarm-config/services/settings.js.map +1 -1
- package/dist/feature/swarm-config/services/validate-actions.js +9 -1
- package/dist/feature/swarm-config/services/validate-actions.js.map +1 -1
- package/dist/feature/swarm-config/services/validate-runtimes.js +3 -1
- package/dist/feature/swarm-config/services/validate-runtimes.js.map +1 -1
- package/dist/feature/swarm-config/services/validate-settings.js +65 -0
- package/dist/feature/swarm-config/services/validate-settings.js.map +1 -1
- package/dist/feature/swarm-config/services/validate.js +17 -2
- package/dist/feature/swarm-config/services/validate.js.map +1 -1
- package/dist/feature/swarm-config/types/action.js +9 -0
- package/dist/feature/swarm-config/types/action.js.map +1 -1
- package/dist/feature/swarm-config/types/settings.js +35 -5
- package/dist/feature/swarm-config/types/settings.js.map +1 -1
- package/dist/feature/swarm-edit/services/config-edits.js +14 -1
- package/dist/feature/swarm-edit/services/config-edits.js.map +1 -1
- package/dist/feature/swarm-edit/services/editor-settings.js +36 -7
- package/dist/feature/swarm-edit/services/editor-settings.js.map +1 -1
- package/dist/feature/swarm-edit/services/plan-settings.js +3 -1
- package/dist/feature/swarm-edit/services/plan-settings.js.map +1 -1
- package/dist/feature/swarm-edit/types/editor.js.map +1 -1
- package/dist/feature/swarm-edit/types/setting-fields.js +12 -0
- package/dist/feature/swarm-edit/types/setting-fields.js.map +1 -1
- package/dist/platform/git/delivery.js +1 -1
- package/dist/platform/git/delivery.js.map +1 -1
- package/dist/platform/network/index.js +4 -0
- package/dist/platform/network/index.js.map +1 -0
- package/dist/platform/network/interfaces.js +7 -0
- package/dist/platform/network/interfaces.js.map +1 -0
- package/dist/platform/network/probe.js +128 -0
- package/dist/platform/network/probe.js.map +1 -0
- package/dist/platform/network/tunnel.js +87 -0
- package/dist/platform/network/tunnel.js.map +1 -0
- package/dist/platform/process/command.js +23 -0
- package/dist/platform/process/command.js.map +1 -0
- package/dist/platform/process/index.js +1 -0
- package/dist/platform/process/index.js.map +1 -1
- package/dist/platform/sqlite/migrations.js +2 -0
- package/dist/platform/sqlite/migrations.js.map +1 -1
- package/dist/platform/sqlite/stats-migration.js +42 -0
- package/dist/platform/sqlite/stats-migration.js.map +1 -0
- package/dist/presentation/cli/commands/stats.js +41 -0
- package/dist/presentation/cli/commands/stats.js.map +1 -0
- package/dist/presentation/cli/help.js +1 -1
- package/dist/presentation/cli/help.js.map +1 -1
- package/dist/presentation/cli/local/config-check.js +23 -5
- package/dist/presentation/cli/local/config-check.js.map +1 -1
- package/dist/presentation/cli/program.js +2 -0
- package/dist/presentation/cli/program.js.map +1 -1
- package/dist/presentation/format/index.js +1 -0
- package/dist/presentation/format/index.js.map +1 -1
- package/dist/presentation/format/queue.js +1 -1
- package/dist/presentation/format/queue.js.map +1 -1
- package/dist/presentation/format/runs.js +8 -1
- package/dist/presentation/format/runs.js.map +1 -1
- package/dist/presentation/format/stats.js +79 -0
- package/dist/presentation/format/stats.js.map +1 -0
- package/dist/presentation/ipc/contract/agents.js +18 -0
- package/dist/presentation/ipc/contract/agents.js.map +1 -1
- package/dist/presentation/ipc/contract/config.js +4 -0
- package/dist/presentation/ipc/contract/config.js.map +1 -1
- package/dist/presentation/ipc/contract/envelope.js +4 -1
- package/dist/presentation/ipc/contract/envelope.js.map +1 -1
- package/dist/presentation/ipc/contract/groups.js +9 -0
- package/dist/presentation/ipc/contract/groups.js.map +1 -1
- package/dist/presentation/ipc/contract/index.js +1 -0
- package/dist/presentation/ipc/contract/index.js.map +1 -1
- package/dist/presentation/ipc/contract/panel.js +11 -0
- package/dist/presentation/ipc/contract/panel.js.map +1 -1
- package/dist/presentation/ipc/contract/responses/index.js +1 -0
- package/dist/presentation/ipc/contract/responses/index.js.map +1 -1
- package/dist/presentation/ipc/contract/responses/stats.js +67 -0
- package/dist/presentation/ipc/contract/responses/stats.js.map +1 -0
- package/dist/presentation/ipc/contract/runs.js +6 -0
- package/dist/presentation/ipc/contract/runs.js.map +1 -1
- package/dist/presentation/ipc/contract/stats/stats.js +20 -0
- package/dist/presentation/ipc/contract/stats/stats.js.map +1 -0
- package/dist/presentation/ipc/handlers/config.js +1 -0
- package/dist/presentation/ipc/handlers/config.js.map +1 -1
- package/dist/presentation/ipc/handlers/groups.js +8 -0
- package/dist/presentation/ipc/handlers/groups.js.map +1 -1
- package/dist/presentation/ipc/handlers/runs.js +1 -1
- package/dist/presentation/ipc/handlers/runs.js.map +1 -1
- package/dist/presentation/ipc/handlers/stats.js +17 -0
- package/dist/presentation/ipc/handlers/stats.js.map +1 -0
- package/dist/presentation/ipc/handlers/system.js +2 -0
- package/dist/presentation/ipc/handlers/system.js.map +1 -1
- package/dist/presentation/ipc/handlers/table.js +2 -0
- package/dist/presentation/ipc/handlers/table.js.map +1 -1
- package/dist/presentation/ipc/publisher.js +1 -0
- package/dist/presentation/ipc/publisher.js.map +1 -1
- package/dist/presentation/ipc/views/catalog.js +3 -3
- package/dist/presentation/ipc/views/catalog.js.map +1 -1
- package/dist/presentation/ipc/views/index.js +1 -0
- package/dist/presentation/ipc/views/index.js.map +1 -1
- package/dist/presentation/ipc/views/queue.js +5 -1
- package/dist/presentation/ipc/views/queue.js.map +1 -1
- package/dist/presentation/ipc/views/runs.js +1 -1
- package/dist/presentation/ipc/views/runs.js.map +1 -1
- package/dist/presentation/ipc/views/stats.js +5 -0
- package/dist/presentation/ipc/views/stats.js.map +1 -0
- package/dist/presentation/mcp/worker-extra.js +2 -2
- package/dist/presentation/mcp/worker-extra.js.map +1 -1
- package/dist/presentation/mcp/worker-read.js +45 -0
- package/dist/presentation/mcp/worker-read.js.map +1 -0
- package/dist/presentation/mcp/worker.js +2 -0
- package/dist/presentation/mcp/worker.js.map +1 -1
- package/dist/presentation/web/hub.js +4 -0
- package/dist/presentation/web/hub.js.map +1 -1
- package/dist/presentation/web/panel/directories.js +1 -1
- package/dist/presentation/web/panel/directories.js.map +1 -1
- package/dist/presentation/web/panel/system.js +1 -0
- package/dist/presentation/web/panel/system.js.map +1 -1
- package/dist/presentation/web/request.js +28 -1
- package/dist/presentation/web/request.js.map +1 -1
- package/dist/presentation/web/routes/config.js +5 -0
- package/dist/presentation/web/routes/config.js.map +1 -1
- package/dist/presentation/web/routes/runs.js.map +1 -1
- package/dist/presentation/web/routes/stats/stats.js +22 -0
- package/dist/presentation/web/routes/stats/stats.js.map +1 -0
- package/dist/presentation/web/server.js +3 -1
- package/dist/presentation/web/server.js.map +1 -1
- package/dist/web/assets/FilterColumn-BCMp-JO4.js +1 -0
- package/dist/web/assets/SharedPipelinesGroup-DJRGFtzx.js +1 -0
- package/dist/web/assets/badge-C_7kALlW.js +1 -0
- package/dist/web/assets/{card-DkikoTxR.js → card-C9eXOVuF.js} +1 -1
- package/dist/web/assets/empty-ACC2KkXk.js +41 -0
- package/dist/web/assets/index-CsVQUXJH.js +21 -0
- package/dist/web/assets/index-Ds1nt_qm.css +2 -0
- package/dist/web/assets/locales-fB1w2oER.js +1 -0
- package/dist/web/assets/pipelines-DQglwIkL.js +10 -0
- package/dist/web/assets/queue-CAuAo--6.js +16 -0
- package/dist/web/assets/select-BSqaxwh1.js +1 -0
- package/dist/web/assets/settingFields-DVg9TQK2.js +1 -0
- package/dist/web/assets/settings-6eHKYbS7.js +2 -0
- package/dist/web/assets/skeleton-CfLYGtNX.js +1 -0
- package/dist/web/assets/specialists-Durm0DgK.js +1 -0
- package/dist/web/assets/stats-67akPa3A.js +1 -0
- package/dist/web/assets/topology-DQu3su19.js +1 -0
- package/dist/web/assets/trash-ChYI9ms1.js +1 -0
- package/dist/web/assets/useListDrag-0GPS1X83.js +1 -0
- package/dist/web/index.html +7 -6
- package/integrations/claude-code/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/dist/cli/clean.js +0 -71
- package/dist/cli/clean.js.map +0 -1
- package/dist/cli/commands.js +0 -963
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/config-check.js +0 -173
- package/dist/cli/config-check.js.map +0 -1
- package/dist/cli/daemon.js +0 -199
- package/dist/cli/daemon.js.map +0 -1
- package/dist/cli/help.js +0 -50
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/init.js +0 -43
- package/dist/cli/init.js.map +0 -1
- package/dist/cli/io.js +0 -13
- package/dist/cli/io.js.map +0 -1
- package/dist/cli/probe.js +0 -12
- package/dist/cli/probe.js.map +0 -1
- package/dist/cli/program.js +0 -48
- package/dist/cli/program.js.map +0 -1
- package/dist/cli/setup.js +0 -406
- package/dist/cli/setup.js.map +0 -1
- package/dist/cli/version.js +0 -6
- package/dist/cli/version.js.map +0 -1
- package/dist/cli/watch.js +0 -24
- package/dist/cli/watch.js.map +0 -1
- package/dist/cli/web/daemon-panel.js +0 -185
- package/dist/cli/web/daemon-panel.js.map +0 -1
- package/dist/cli/web/default-repository.js +0 -12
- package/dist/cli/web/default-repository.js.map +0 -1
- package/dist/cli/web/errors.js +0 -60
- package/dist/cli/web/errors.js.map +0 -1
- package/dist/cli/web/open.js +0 -12
- package/dist/cli/web/open.js.map +0 -1
- package/dist/cli/web/page.js +0 -465
- package/dist/cli/web/page.js.map +0 -1
- package/dist/cli/web/server.js +0 -1191
- package/dist/cli/web/server.js.map +0 -1
- package/dist/cli/web/standby.js +0 -119
- package/dist/cli/web/standby.js.map +0 -1
- package/dist/cli/web/state.js +0 -69
- package/dist/cli/web/state.js.map +0 -1
- package/dist/cli/web/system.js +0 -66
- package/dist/cli/web/system.js.map +0 -1
- package/dist/cli/web-control.js +0 -173
- package/dist/cli/web-control.js.map +0 -1
- package/dist/config/discover.js +0 -25
- package/dist/config/discover.js.map +0 -1
- package/dist/config/duration.js +0 -17
- package/dist/config/duration.js.map +0 -1
- package/dist/config/edit.js +0 -966
- package/dist/config/edit.js.map +0 -1
- package/dist/config/errors.js +0 -29
- package/dist/config/errors.js.map +0 -1
- package/dist/config/index.js +0 -14
- package/dist/config/index.js.map +0 -1
- package/dist/config/load.js +0 -412
- package/dist/config/load.js.map +0 -1
- package/dist/config/merge.js +0 -45
- package/dist/config/merge.js.map +0 -1
- package/dist/config/model.js +0 -171
- package/dist/config/model.js.map +0 -1
- package/dist/config/paths.js +0 -31
- package/dist/config/paths.js.map +0 -1
- package/dist/config/prompt.js +0 -33
- package/dist/config/prompt.js.map +0 -1
- package/dist/config/shared-pipelines.js +0 -71
- package/dist/config/shared-pipelines.js.map +0 -1
- package/dist/config/shared-specialists.js +0 -68
- package/dist/config/shared-specialists.js.map +0 -1
- package/dist/config/shared-workflows.js +0 -71
- package/dist/config/shared-workflows.js.map +0 -1
- package/dist/config/specialist-tags.js +0 -214
- package/dist/config/specialist-tags.js.map +0 -1
- package/dist/config/tag-names.js +0 -43
- package/dist/config/tag-names.js.map +0 -1
- package/dist/config/validate.js +0 -872
- package/dist/config/validate.js.map +0 -1
- package/dist/core/artifacts.js +0 -37
- package/dist/core/artifacts.js.map +0 -1
- package/dist/core/create.js +0 -75
- package/dist/core/create.js.map +0 -1
- package/dist/core/delivery.js +0 -366
- package/dist/core/delivery.js.map +0 -1
- package/dist/core/errors.js +0 -7
- package/dist/core/errors.js.map +0 -1
- package/dist/core/ids.js +0 -99
- package/dist/core/ids.js.map +0 -1
- package/dist/core/index.js +0 -21
- package/dist/core/index.js.map +0 -1
- package/dist/core/input.js +0 -45
- package/dist/core/input.js.map +0 -1
- package/dist/core/machine.js +0 -1021
- package/dist/core/machine.js.map +0 -1
- package/dist/core/model.js +0 -460
- package/dist/core/model.js.map +0 -1
- package/dist/core/observer.js +0 -193
- package/dist/core/observer.js.map +0 -1
- package/dist/core/occupancy.js +0 -63
- package/dist/core/occupancy.js.map +0 -1
- package/dist/core/permissions.js +0 -222
- package/dist/core/permissions.js.map +0 -1
- package/dist/core/plan.js +0 -99
- package/dist/core/plan.js.map +0 -1
- package/dist/core/progress.js +0 -43
- package/dist/core/progress.js.map +0 -1
- package/dist/core/questions.js +0 -19
- package/dist/core/questions.js.map +0 -1
- package/dist/core/queue.js +0 -859
- package/dist/core/queue.js.map +0 -1
- package/dist/core/retryable.js +0 -8
- package/dist/core/retryable.js.map +0 -1
- package/dist/core/scheduler.js +0 -160
- package/dist/core/scheduler.js.map +0 -1
- package/dist/core/skip.js +0 -109
- package/dist/core/skip.js.map +0 -1
- package/dist/core/stages.js +0 -304
- package/dist/core/stages.js.map +0 -1
- package/dist/core/summary.js +0 -35
- package/dist/core/summary.js.map +0 -1
- package/dist/core/tags.js +0 -184
- package/dist/core/tags.js.map +0 -1
- package/dist/core/topology.js +0 -162
- package/dist/core/topology.js.map +0 -1
- package/dist/daemon/artifacts.js +0 -84
- package/dist/daemon/artifacts.js.map +0 -1
- package/dist/daemon/daemon.js +0 -1442
- package/dist/daemon/daemon.js.map +0 -1
- package/dist/daemon/executor.js +0 -749
- package/dist/daemon/executor.js.map +0 -1
- package/dist/daemon/helpers.js +0 -38
- package/dist/daemon/helpers.js.map +0 -1
- package/dist/daemon/index.js +0 -4
- package/dist/daemon/index.js.map +0 -1
- package/dist/daemon/logs.js +0 -69
- package/dist/daemon/logs.js.map +0 -1
- package/dist/daemon/observers.js +0 -93
- package/dist/daemon/observers.js.map +0 -1
- package/dist/daemon/patches.js +0 -76
- package/dist/daemon/patches.js.map +0 -1
- package/dist/daemon/ports.js +0 -2
- package/dist/daemon/ports.js.map +0 -1
- package/dist/daemon/processes.js +0 -98
- package/dist/daemon/processes.js.map +0 -1
- package/dist/daemon/repositories.js +0 -2
- package/dist/daemon/repositories.js.map +0 -1
- package/dist/daemon/server.js +0 -164
- package/dist/daemon/server.js.map +0 -1
- package/dist/daemon/supervisor.js +0 -140
- package/dist/daemon/supervisor.js.map +0 -1
- package/dist/daemon/timings.js +0 -23
- package/dist/daemon/timings.js.map +0 -1
- package/dist/git/delivery.js +0 -284
- package/dist/git/delivery.js.map +0 -1
- package/dist/git/index.js +0 -4
- package/dist/git/index.js.map +0 -1
- package/dist/git/runner.js +0 -60
- package/dist/git/runner.js.map +0 -1
- package/dist/git/workspace.js +0 -366
- package/dist/git/workspace.js.map +0 -1
- package/dist/mcp/host.js +0 -401
- package/dist/mcp/host.js.map +0 -1
- package/dist/mcp/index.js +0 -3
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/tools.js +0 -19
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/version.js +0 -5
- package/dist/mcp/version.js.map +0 -1
- package/dist/mcp/worker.js +0 -230
- package/dist/mcp/worker.js.map +0 -1
- package/dist/presentation/web/routes/directories.js +0 -60
- package/dist/presentation/web/routes/directories.js.map +0 -1
- package/dist/protocol/autostart.js +0 -171
- package/dist/protocol/autostart.js.map +0 -1
- package/dist/protocol/build.js +0 -38
- package/dist/protocol/build.js.map +0 -1
- package/dist/protocol/catalog.js +0 -18
- package/dist/protocol/catalog.js.map +0 -1
- package/dist/protocol/client.js +0 -83
- package/dist/protocol/client.js.map +0 -1
- package/dist/protocol/format.js +0 -477
- package/dist/protocol/format.js.map +0 -1
- package/dist/protocol/index.js +0 -11
- package/dist/protocol/index.js.map +0 -1
- package/dist/protocol/messages.js +0 -598
- package/dist/protocol/messages.js.map +0 -1
- package/dist/protocol/style.js +0 -81
- package/dist/protocol/style.js.map +0 -1
- package/dist/protocol/transcript.js +0 -49
- package/dist/protocol/transcript.js.map +0 -1
- package/dist/protocol/views.js +0 -696
- package/dist/protocol/views.js.map +0 -1
- package/dist/runtime/catalog.js +0 -117
- package/dist/runtime/catalog.js.map +0 -1
- package/dist/runtime/claude.js +0 -399
- package/dist/runtime/claude.js.map +0 -1
- package/dist/runtime/index.js +0 -34
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/message.js +0 -48
- package/dist/runtime/message.js.map +0 -1
- package/dist/runtime/naming.js +0 -69
- package/dist/runtime/naming.js.map +0 -1
- package/dist/runtime/opencode.js +0 -189
- package/dist/runtime/opencode.js.map +0 -1
- package/dist/runtime/skills.js +0 -17
- package/dist/runtime/skills.js.map +0 -1
- package/dist/runtime/transcript.js +0 -227
- package/dist/runtime/transcript.js.map +0 -1
- package/dist/runtime/types.js +0 -12
- package/dist/runtime/types.js.map +0 -1
- package/dist/runtime/which.js +0 -21
- package/dist/runtime/which.js.map +0 -1
- package/dist/store/index.js +0 -3
- package/dist/store/index.js.map +0 -1
- package/dist/store/schema.js +0 -286
- package/dist/store/schema.js.map +0 -1
- package/dist/store/store.js +0 -491
- package/dist/store/store.js.map +0 -1
- package/dist/web/assets/EntryList-CnfGgjEY.js +0 -1
- package/dist/web/assets/FilePath-C0X8-keS.js +0 -1
- package/dist/web/assets/SettingsForm-BcyBWJbn.js +0 -1
- package/dist/web/assets/SharedPipelinesGroup-a368-IQ0.js +0 -1
- package/dist/web/assets/index-B-oJ93zH.js +0 -22
- package/dist/web/assets/index-BZE36gYR.css +0 -2
- package/dist/web/assets/locales-DtRrxYzg.js +0 -1
- package/dist/web/assets/pipelines-D48ggDNe.js +0 -1
- package/dist/web/assets/queue-D8_RY4IY.js +0 -16
- package/dist/web/assets/select-J4oIrmYh.js +0 -1
- package/dist/web/assets/settings-B0-0Vaia.js +0 -2
- package/dist/web/assets/skeleton-CCKCQF5n.js +0 -1
- package/dist/web/assets/specialists-DH8tyluO.js +0 -1
- package/dist/web/assets/switch-CWFAgxG1.js +0 -41
- package/dist/web/assets/topology-CNQ28AB2.js +0 -7
- /package/dist/web/assets/{topology-DLioOiRN.css → pipelines-DLioOiRN.css} +0 -0
package/dist/daemon/daemon.js
DELETED
|
@@ -1,1442 +0,0 @@
|
|
|
1
|
-
import { randomInt, randomUUID } from 'node:crypto';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
-
import { open, realpath, stat } from 'node:fs/promises';
|
|
5
|
-
import { isAbsolute, join, resolve, sep } from 'node:path';
|
|
6
|
-
import { ConfigEditError, } from '../feature/swarm-edit/types/index.js';
|
|
7
|
-
import { ConfigLoadError, findSpecialist, findPipeline, pipelineNameOf, } from '../feature/swarm-config/types/index.js';
|
|
8
|
-
import { commitEdit, commitEdits, tagFolder, planImport, planTagRemove, planTagRename, planTagsSet, draftConfig, editorView, planEdit, planSettings, sharedSpecialistUsage, sharedPipelineUsage, } from '../feature/swarm-edit/services/index.js';
|
|
9
|
-
import { configPaths, loadConfig, validateObserverProfile, } from '../feature/swarm-config/services/index.js';
|
|
10
|
-
import { addItem, advance, autopilotAnswers, dependencyTags, checkReturnedPatch, checkPosition, checkDependencies, editItem, spreadTags, emptyQueue, itemFailed, itemStarted, pauseQueue, acknowledgeRun, adoptRun, problemKeys, returnRun, pauseRun, claimPlace, canReturn, dismissRun, returnItemOf, queueWakeAt, queueItemId, removeItem, setParallel, setQueueSettings, startQueue, } from '../feature/queue/types/index.js';
|
|
11
|
-
import { checkSkip, stepStates, runName, allGroups, createRun, retryableGroups, limitHolds, findGroup, attemptStepLabel, groupRef, isRunFinished, groupsFromTask, runId, runRef, pipelineTopologies, pipelineTopology, specialistName, splitInstructionText, MESSAGE_INSTRUCTIONS, RESOLVE_INSTRUCTIONS, isServiceGroup, isSplitGroup, REPAIR_GROUP, } from '../feature/runs/types/index.js';
|
|
12
|
-
import { tagsOfRepository, autoTagName, knownTags, mergeTags, removeTag, keepLinkedTags, linkedTagOf, parseParentRef, withoutLinkedTags, resolveManualTags, resolveTags, } from '../feature/tags/types/index.js';
|
|
13
|
-
import { dispatch, transition, planDispatch, waitKey, } from '../feature/runs/machine/index.js';
|
|
14
|
-
import { ARTIFACTS_PER_GROUP, ARTIFACT_FILE_LIMIT, artifactPreview, artifactTitle, } from '../feature/artifacts/types/index.js';
|
|
15
|
-
import { permissionsOf, specialistsOf, } from '../feature/agents/types/index.js';
|
|
16
|
-
import { defaultObserverSettings, planRepairs, repairAdmitted, repairIncidents, } from '../feature/observers/types/index.js';
|
|
17
|
-
import { changedPathsBetween, changedPathsSince, readFileAt, diffStat, excludeWorkspace, fileDiff, git, prepareRunBranch, rangePatch, refExists, repositoryRoot, workspaceRoot, } from '../platform/git/index.js';
|
|
18
|
-
import { catalogView, observersView, groupView, pickSpecChange, queueView, repositoryViews, runView, withQueue, } from '../presentation/ipc/views/index.js';
|
|
19
|
-
import { currentBuild } from '../platform/build/index.js';
|
|
20
|
-
import { runTitle } from '../feature/runs/types/index.js';
|
|
21
|
-
import { readLines, readTail, readTimes, timesPath, } from '../feature/agents/services/index.js';
|
|
22
|
-
import { currentPermissions, currentSpecialists, } from '../feature/runs/services/index.js';
|
|
23
|
-
import { checkObserverSettings } from './observers.js';
|
|
24
|
-
import { describePath, itemParams, queueSignature } from './helpers.js';
|
|
25
|
-
import { isRejected, rejected } from '../platform/errors/index.js';
|
|
26
|
-
const NO_PANEL = 'this daemon serves no web panel';
|
|
27
|
-
/** The longest delay `setTimeout` keeps. */
|
|
28
|
-
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
29
|
-
/** The delivery of a group without the commit message, which only the actions after delivery need. */
|
|
30
|
-
function deliveryOutcome(delivery) {
|
|
31
|
-
const { message: _message, ...rest } = delivery;
|
|
32
|
-
return rest;
|
|
33
|
-
}
|
|
34
|
-
export class Daemon {
|
|
35
|
-
database;
|
|
36
|
-
repositories;
|
|
37
|
-
socket;
|
|
38
|
-
environment;
|
|
39
|
-
now;
|
|
40
|
-
build;
|
|
41
|
-
agents;
|
|
42
|
-
panel;
|
|
43
|
-
runStates;
|
|
44
|
-
engine;
|
|
45
|
-
effects;
|
|
46
|
-
runRequests;
|
|
47
|
-
runReads;
|
|
48
|
-
subscribers = new Set();
|
|
49
|
-
diffs;
|
|
50
|
-
patches;
|
|
51
|
-
delivery;
|
|
52
|
-
artifacts;
|
|
53
|
-
seq = 0;
|
|
54
|
-
queues = new Map();
|
|
55
|
-
advanceRequested = new Set();
|
|
56
|
-
observers = defaultObserverSettings();
|
|
57
|
-
observeRequested = false;
|
|
58
|
-
/** Incidents subscribers were told about, as `<run>:<incident key>`. */
|
|
59
|
-
incidentsSent = new Set();
|
|
60
|
-
observersJson = '';
|
|
61
|
-
queueRuns = new Map();
|
|
62
|
-
/** Per repository: return item of each returned run, as subscribers last saw it. */
|
|
63
|
-
returnItems = new Map();
|
|
64
|
-
registry;
|
|
65
|
-
repositoriesJson = '';
|
|
66
|
-
tags;
|
|
67
|
-
config;
|
|
68
|
-
edits;
|
|
69
|
-
shared;
|
|
70
|
-
processes;
|
|
71
|
-
timings;
|
|
72
|
-
/** The ports the services of the features call, until their own providers take them. */
|
|
73
|
-
ports = {
|
|
74
|
-
lookup: (id) => this.lookupState(id),
|
|
75
|
-
agentRoots: () => this.effects.agentRoots(),
|
|
76
|
-
// runs: the queue, the observers, the publication, the diffs and the processes
|
|
77
|
-
runChanged: (state) => this.queueRunChanged(state),
|
|
78
|
-
wakeMoments: () => [...this.queues.values()].flatMap((queue) => queueWakeAt(queue) ?? []),
|
|
79
|
-
wake: () => this.wakeQueues(),
|
|
80
|
-
onLimitOf: (repository) => this.onLimitOf(repository),
|
|
81
|
-
request: () => this.requestObserve(),
|
|
82
|
-
runSaved: (state) => {
|
|
83
|
-
this.broadcast(state);
|
|
84
|
-
this.publishRepositories();
|
|
85
|
-
},
|
|
86
|
-
waitsChanged: (states, repositories) => this.waitsChanged(states, repositories),
|
|
87
|
-
broadcast: (state) => this.broadcast(state),
|
|
88
|
-
repositoriesChanged: () => this.publishRepositories(),
|
|
89
|
-
tagsChanged: (repository) => this.tagsChanged(repository),
|
|
90
|
-
configChanged: (repository) => this.republishQueue(repository),
|
|
91
|
-
hasSubscribers: () => this.subscribers.size > 0,
|
|
92
|
-
processesChanged: (payload) => this.publishProcesses(payload),
|
|
93
|
-
};
|
|
94
|
-
constructor(options, parts) {
|
|
95
|
-
this.database = parts.database;
|
|
96
|
-
this.repositories = parts.repositories;
|
|
97
|
-
this.socket = parts.socket;
|
|
98
|
-
this.diffs = parts.delivery.diffs;
|
|
99
|
-
this.patches = parts.delivery.patches;
|
|
100
|
-
this.delivery = parts.delivery.deliver;
|
|
101
|
-
this.artifacts = parts.artifacts;
|
|
102
|
-
this.environment = parts.environment;
|
|
103
|
-
this.agents = parts.agents;
|
|
104
|
-
this.registry = parts.registry;
|
|
105
|
-
this.tags = parts.tags;
|
|
106
|
-
this.config = parts.config;
|
|
107
|
-
this.edits = parts.edits;
|
|
108
|
-
this.shared = parts.shared;
|
|
109
|
-
this.processes = parts.processes;
|
|
110
|
-
this.now = options.now ?? Date.now;
|
|
111
|
-
this.build = options.build ?? currentBuild();
|
|
112
|
-
this.panel = options.panel;
|
|
113
|
-
this.timings = parts.timings;
|
|
114
|
-
this.runStates = parts.runs.states;
|
|
115
|
-
this.engine = parts.runs.engine;
|
|
116
|
-
this.effects = parts.runs.effects;
|
|
117
|
-
this.runRequests = parts.runs.requests;
|
|
118
|
-
this.runReads = parts.runs.reads;
|
|
119
|
-
}
|
|
120
|
-
async start() {
|
|
121
|
-
await this.patches.sweep();
|
|
122
|
-
await this.artifacts.sweep();
|
|
123
|
-
await this.serial(async () => {
|
|
124
|
-
const recovered = this.runStates.recover();
|
|
125
|
-
const { queues, observers } = this.repositories;
|
|
126
|
-
for (const queue of queues.queues())
|
|
127
|
-
this.queues.set(queue.repository, queue);
|
|
128
|
-
this.tags.load();
|
|
129
|
-
this.registry.load();
|
|
130
|
-
this.observers = observers.loadObservers();
|
|
131
|
-
// A delivery cut off by the restart starts again.
|
|
132
|
-
for (const { state, effects } of recovered)
|
|
133
|
-
await this.effects.perform(state, effects);
|
|
134
|
-
await this.schedule();
|
|
135
|
-
for (const queue of [...this.queues.values()]) {
|
|
136
|
-
if (queue.status === 'running' ||
|
|
137
|
-
queue.runs.length > 0 ||
|
|
138
|
-
queue.skipped.length > 0 ||
|
|
139
|
-
queue.stop?.kind === 'limit') {
|
|
140
|
-
await this.advanceQueue(queue.repository);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// Incidents from before the start, in finished runs too.
|
|
144
|
-
await this.observe(true);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
/** A run was saved: the queue of its repository looks at it when it holds or waits for it. */
|
|
148
|
-
queueRunChanged(state) {
|
|
149
|
-
const queue = this.queues.get(state.run.repository);
|
|
150
|
-
if (queue &&
|
|
151
|
-
(queue.runs.length > 0 ||
|
|
152
|
-
queue.skipped.includes(state.run.id) ||
|
|
153
|
-
queue.items.some((item) => item.after.includes(state.run.id)))) {
|
|
154
|
-
this.requestAdvance(state.run.repository);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
waitsChanged(states, repositories) {
|
|
158
|
-
for (const state of states)
|
|
159
|
-
this.broadcast(state);
|
|
160
|
-
for (const repository of repositories) {
|
|
161
|
-
const queue = this.queues.get(repository);
|
|
162
|
-
if (queue && this.queueRuns.get(repository) !== queueSignature(this.queueSnapshot(queue))) {
|
|
163
|
-
this.publishQueue(queue);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/** Looks at the incidents of the runs once, however many changes arrive meanwhile. */
|
|
168
|
-
requestObserve() {
|
|
169
|
-
if (this.engine.stopping || this.observeRequested)
|
|
170
|
-
return;
|
|
171
|
-
this.observeRequested = true;
|
|
172
|
-
void this.serial(async () => {
|
|
173
|
-
this.observeRequested = false;
|
|
174
|
-
if (!this.engine.stopping)
|
|
175
|
-
await this.observe();
|
|
176
|
-
}).catch(() => undefined);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Tells subscribers about new incidents and lets observers take the oldest ones. Runs of a
|
|
180
|
-
* repository with a queue look pending are left for after it: the autopilot answers first.
|
|
181
|
-
* `full` also looks at the recent finished runs, which the daemon does not keep in memory.
|
|
182
|
-
*/
|
|
183
|
-
async observe(full = false) {
|
|
184
|
-
if (this.engine.stopping)
|
|
185
|
-
return;
|
|
186
|
-
const settings = this.observers;
|
|
187
|
-
const pool = new Map();
|
|
188
|
-
if (full) {
|
|
189
|
-
for (const stored of this.runStates.recent()) {
|
|
190
|
-
// Through `state`, so the run lives in memory and `apply` changes the one that is kept.
|
|
191
|
-
pool.set(stored.run.id, this.state(stored.run.id));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
for (const state of this.runStates.all())
|
|
195
|
-
pool.set(state.run.id, state);
|
|
196
|
-
const all = [...pool.values()];
|
|
197
|
-
const states = all.filter((state) => !this.advanceRequested.has(state.run.repository));
|
|
198
|
-
for (const state of states) {
|
|
199
|
-
for (const incident of repairIncidents(state, settings)) {
|
|
200
|
-
const key = `${state.run.id}:${incident.key}`;
|
|
201
|
-
if (this.incidentsSent.has(key))
|
|
202
|
-
continue;
|
|
203
|
-
this.incidentsSent.add(key);
|
|
204
|
-
if (this.subscribers.size === 0)
|
|
205
|
-
continue;
|
|
206
|
-
this.seq += 1;
|
|
207
|
-
const line = JSON.stringify({
|
|
208
|
-
event: 'incident',
|
|
209
|
-
seq: this.seq,
|
|
210
|
-
runId: state.run.id,
|
|
211
|
-
repository: state.run.repository,
|
|
212
|
-
incident,
|
|
213
|
-
});
|
|
214
|
-
for (const send of this.subscribers)
|
|
215
|
-
send(line);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const profile = validateObserverProfile(settings.specialist);
|
|
219
|
-
const specialist = profile.errors.length === 0 ? profile.specialist : null;
|
|
220
|
-
if (specialist) {
|
|
221
|
-
// Over all runs, so the repairs of the waiting repositories count against the workers.
|
|
222
|
-
const holds = limitHolds(all, this.now());
|
|
223
|
-
for (const { state, incident } of planRepairs(settings, all, holds)) {
|
|
224
|
-
if (this.advanceRequested.has(state.run.repository))
|
|
225
|
-
continue;
|
|
226
|
-
try {
|
|
227
|
-
await this.apply(state, { kind: 'repair_start', incident, specialist });
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
if (!isRejected(error))
|
|
231
|
-
throw error;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
this.publishObservers();
|
|
236
|
-
}
|
|
237
|
-
/** The observers as the settings page shows them. */
|
|
238
|
-
observersSnapshot() {
|
|
239
|
-
return observersView(this.observers, this.runStates.all());
|
|
240
|
-
}
|
|
241
|
-
publishObservers() {
|
|
242
|
-
if (this.subscribers.size === 0)
|
|
243
|
-
return;
|
|
244
|
-
const view = this.observersSnapshot();
|
|
245
|
-
const text = JSON.stringify(view);
|
|
246
|
-
if (text === this.observersJson)
|
|
247
|
-
return;
|
|
248
|
-
this.observersJson = text;
|
|
249
|
-
this.seq += 1;
|
|
250
|
-
const line = JSON.stringify({ event: 'observers', seq: this.seq, observers: view });
|
|
251
|
-
for (const send of this.subscribers)
|
|
252
|
-
send(line);
|
|
253
|
-
}
|
|
254
|
-
/** Looks at the queue of the repository once, however many changes arrive meanwhile. */
|
|
255
|
-
requestAdvance(repository) {
|
|
256
|
-
if (this.engine.stopping || this.advanceRequested.has(repository))
|
|
257
|
-
return;
|
|
258
|
-
this.advanceRequested.add(repository);
|
|
259
|
-
void this.serial(async () => {
|
|
260
|
-
this.advanceRequested.delete(repository);
|
|
261
|
-
if (!this.engine.stopping)
|
|
262
|
-
await this.advanceQueue(repository);
|
|
263
|
-
}).catch(() => undefined);
|
|
264
|
-
}
|
|
265
|
-
/** What a usage limit does to the groups of the repository's runs: the queue's setting. */
|
|
266
|
-
onLimitOf(repository) {
|
|
267
|
-
return this.queueFor(repository).onLimit;
|
|
268
|
-
}
|
|
269
|
-
queueFor(repository) {
|
|
270
|
-
const cached = this.queues.get(repository);
|
|
271
|
-
if (cached)
|
|
272
|
-
return cached;
|
|
273
|
-
const { queues } = this.repositories;
|
|
274
|
-
const next = Math.max(this.runStates.maxNumber(repository), queues.maxItemNumber(repository)) + 1;
|
|
275
|
-
const queue = queues.loadQueue(repository) ?? emptyQueue(repository, this.now(), next);
|
|
276
|
-
this.queues.set(repository, queue);
|
|
277
|
-
return queue;
|
|
278
|
-
}
|
|
279
|
-
lookupState(id) {
|
|
280
|
-
return this.runStates.lookup(id);
|
|
281
|
-
}
|
|
282
|
-
queueSnapshot(queue) {
|
|
283
|
-
const delivery = this.deliverySettings(queue.repository);
|
|
284
|
-
return queueView(queue, (id) => this.lookupState(id), delivery.auto, this.catalogOf(queue.repository), delivery.mode, this.engine.waitOf, delivery.names);
|
|
285
|
-
}
|
|
286
|
-
deliverySettings(repository) {
|
|
287
|
-
return this.config.delivery(repository);
|
|
288
|
-
}
|
|
289
|
-
/** Configuration may change `delivery.auto`, which the queue view shows. */
|
|
290
|
-
republishQueue(repository) {
|
|
291
|
-
const queue = this.queues.get(repository);
|
|
292
|
-
if (queue)
|
|
293
|
-
this.publishQueue(queue);
|
|
294
|
-
}
|
|
295
|
-
saveQueue(queue) {
|
|
296
|
-
this.repositories.queues.saveQueue(queue);
|
|
297
|
-
return this.publishQueue(queue);
|
|
298
|
-
}
|
|
299
|
-
/** Sends the `queue` event and remembers which runs subscribers have seen. */
|
|
300
|
-
publishQueue(queue) {
|
|
301
|
-
const view = this.queueSnapshot(queue);
|
|
302
|
-
this.queueRuns.set(queue.repository, queueSignature(view));
|
|
303
|
-
if (this.subscribers.size > 0) {
|
|
304
|
-
this.seq += 1;
|
|
305
|
-
const line = JSON.stringify({ event: 'queue', seq: this.seq, queue: view });
|
|
306
|
-
for (const send of this.subscribers)
|
|
307
|
-
send(line);
|
|
308
|
-
}
|
|
309
|
-
this.publishRepositories();
|
|
310
|
-
this.publishReturned(queue);
|
|
311
|
-
return view;
|
|
312
|
-
}
|
|
313
|
-
/** Sends a `run` event to every run whose return item appeared, changed or went away. */
|
|
314
|
-
publishReturned(queue) {
|
|
315
|
-
const before = this.returnItems.get(queue.repository) ?? new Map();
|
|
316
|
-
const after = new Map();
|
|
317
|
-
for (const item of queue.items)
|
|
318
|
-
if (item.run !== null)
|
|
319
|
-
after.set(item.run, item.id);
|
|
320
|
-
this.returnItems.set(queue.repository, after);
|
|
321
|
-
for (const run of new Set([...before.keys(), ...after.keys()])) {
|
|
322
|
-
if (before.get(run) === after.get(run))
|
|
323
|
-
continue;
|
|
324
|
-
const state = this.lookupState(run);
|
|
325
|
-
if (state)
|
|
326
|
-
this.broadcast(state);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
repositoryList() {
|
|
330
|
-
return repositoryViews(this.registry.entries(), this.runStates.all(), [...this.queues.values()], this.environment.HOME || homedir());
|
|
331
|
-
}
|
|
332
|
-
/** Publishes the registry when its counters or entries differ from what subscribers last saw. */
|
|
333
|
-
publishRepositories() {
|
|
334
|
-
if (this.subscribers.size === 0)
|
|
335
|
-
return;
|
|
336
|
-
const repositories = this.repositoryList();
|
|
337
|
-
const text = JSON.stringify(repositories);
|
|
338
|
-
if (text === this.repositoriesJson)
|
|
339
|
-
return;
|
|
340
|
-
this.repositoriesJson = text;
|
|
341
|
-
this.seq += 1;
|
|
342
|
-
const line = JSON.stringify({ event: 'repositories', seq: this.seq, repositories });
|
|
343
|
-
for (const send of this.subscribers)
|
|
344
|
-
send(line);
|
|
345
|
-
}
|
|
346
|
-
rootOf(path) {
|
|
347
|
-
return this.registry.rootOf(path);
|
|
348
|
-
}
|
|
349
|
-
async repositoryRemove(path) {
|
|
350
|
-
let root;
|
|
351
|
-
try {
|
|
352
|
-
root = await repositoryRoot(path);
|
|
353
|
-
}
|
|
354
|
-
catch {
|
|
355
|
-
root = resolve(path);
|
|
356
|
-
}
|
|
357
|
-
if (!this.registry.has(root))
|
|
358
|
-
throw rejected(`unknown repository ${root}`);
|
|
359
|
-
const unfinished = this.runStates
|
|
360
|
-
.all()
|
|
361
|
-
.filter((state) => state.run.repository === root && !isRunFinished(state)).length;
|
|
362
|
-
if (unfinished > 0)
|
|
363
|
-
throw rejected(`repository has unfinished runs: ${unfinished}`);
|
|
364
|
-
const queue = this.queues.get(root);
|
|
365
|
-
if (queue && (queue.status === 'running' || queue.items.length > 0)) {
|
|
366
|
-
throw rejected('repository queue is not empty or running');
|
|
367
|
-
}
|
|
368
|
-
if (this.observers.projects.some((project) => project.repository === root)) {
|
|
369
|
-
this.observers = {
|
|
370
|
-
...this.observers,
|
|
371
|
-
projects: this.observers.projects.filter((project) => project.repository !== root),
|
|
372
|
-
};
|
|
373
|
-
this.repositories.observers.saveObservers(this.observers);
|
|
374
|
-
this.publishObservers();
|
|
375
|
-
}
|
|
376
|
-
this.registry.forget(root);
|
|
377
|
-
return this.repositoryList();
|
|
378
|
-
}
|
|
379
|
-
async advanceQueue(repository) {
|
|
380
|
-
const started = new Map();
|
|
381
|
-
const queue = this.queueFor(repository);
|
|
382
|
-
const fingerprint = () => JSON.stringify({ ...queue, updatedAt: 0 });
|
|
383
|
-
const before = fingerprint();
|
|
384
|
-
const states = queue.runs.flatMap((id) => {
|
|
385
|
-
const state = this.lookupState(id);
|
|
386
|
-
return state ? [state] : [];
|
|
387
|
-
});
|
|
388
|
-
// An incident an observer takes does not stop the queue.
|
|
389
|
-
for (const state of states) {
|
|
390
|
-
if (repairAdmitted(state, this.observers) &&
|
|
391
|
-
repairIncidents(state, this.observers).length > 0) {
|
|
392
|
-
acknowledgeRun(queue, state);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
const { take, freeze } = advance(queue, states, (id) => this.lookupState(id), this.now());
|
|
396
|
-
let changed = fingerprint() !== before;
|
|
397
|
-
for (const id of freeze)
|
|
398
|
-
await this.freezeRun(id);
|
|
399
|
-
const current = queue.runs.flatMap((id) => this.lookupState(id) ?? []);
|
|
400
|
-
for (const answer of autopilotAnswers(queue, current)) {
|
|
401
|
-
const state = this.lookupState(answer.run);
|
|
402
|
-
if (!state)
|
|
403
|
-
continue;
|
|
404
|
-
try {
|
|
405
|
-
await this.apply(state, {
|
|
406
|
-
kind: 'answer',
|
|
407
|
-
group: answer.group,
|
|
408
|
-
answer: answer.answer,
|
|
409
|
-
by: 'autopilot',
|
|
410
|
-
permissions: this.currentPermissions(state),
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
catch (error) {
|
|
414
|
-
if (!isRejected(error))
|
|
415
|
-
throw error;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
let failed = false;
|
|
419
|
-
for (const item of take) {
|
|
420
|
-
try {
|
|
421
|
-
if (item.run !== null) {
|
|
422
|
-
await this.takeReturned(queue, item);
|
|
423
|
-
this.repositories.queues.saveQueue(queue);
|
|
424
|
-
changed = true;
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
const created = await this.createRun(itemParams(queue, item), knownTags(this.catalogOf(queue.repository), item.tags), item);
|
|
428
|
-
itemStarted(queue, item.id, created.runId, this.now());
|
|
429
|
-
started.set(item.id, created);
|
|
430
|
-
this.repositories.queues.saveQueue(queue);
|
|
431
|
-
}
|
|
432
|
-
catch (error) {
|
|
433
|
-
itemFailed(queue, item.id, error.message, this.now());
|
|
434
|
-
changed = true;
|
|
435
|
-
if (!queue.skipFailed)
|
|
436
|
-
break;
|
|
437
|
-
failed = true;
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
changed = true;
|
|
441
|
-
}
|
|
442
|
-
if (changed)
|
|
443
|
-
this.saveQueue(queue);
|
|
444
|
-
else if (this.queueRuns.get(repository) !== queueSignature(this.queueSnapshot(queue))) {
|
|
445
|
-
this.publishQueue(queue);
|
|
446
|
-
}
|
|
447
|
-
if ((take.length > 0 && queue.runs.length > 0) || (failed && queue.status === 'running')) {
|
|
448
|
-
this.requestAdvance(repository);
|
|
449
|
-
}
|
|
450
|
-
this.armWake();
|
|
451
|
-
// After the autopilot: the incidents it did not answer are the observers'.
|
|
452
|
-
this.requestObserve();
|
|
453
|
-
return started;
|
|
454
|
-
}
|
|
455
|
-
/** Sets `hold: frozen` on a run the queue has taken off its places for a priority run. */
|
|
456
|
-
async freezeRun(id) {
|
|
457
|
-
const state = this.lookupState(id);
|
|
458
|
-
if (!state)
|
|
459
|
-
return;
|
|
460
|
-
try {
|
|
461
|
-
await this.apply(state, { kind: 'hold', hold: 'frozen' });
|
|
462
|
-
}
|
|
463
|
-
catch (error) {
|
|
464
|
-
if (!isRejected(error))
|
|
465
|
-
throw error;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/** A priority action: the run takes a place, and the last run that took one may be frozen. */
|
|
469
|
-
async claimPlaceFor(queue, run) {
|
|
470
|
-
const now = this.now();
|
|
471
|
-
const states = queue.runs.flatMap((id) => this.lookupState(id) ?? []);
|
|
472
|
-
const frozen = claimPlace(queue, states, run, queueItemId(now, randomInt(36 ** 3)), now);
|
|
473
|
-
if (frozen !== null)
|
|
474
|
-
await this.freezeRun(frozen);
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Takes a returned run: retries its failed and cancelled groups, and the run holds a place in
|
|
478
|
-
* the queue instead of the item.
|
|
479
|
-
*/
|
|
480
|
-
async takeReturned(queue, item) {
|
|
481
|
-
const id = item.run;
|
|
482
|
-
const state = this.lookupState(id);
|
|
483
|
-
if (!state)
|
|
484
|
-
throw rejected(`unknown run \`${id}\``);
|
|
485
|
-
const held = state.run.hold !== null;
|
|
486
|
-
if (held)
|
|
487
|
-
await this.apply(state, { kind: 'hold', hold: null });
|
|
488
|
-
const groups = retryableGroups(state);
|
|
489
|
-
if (groups.length === 0 && !held) {
|
|
490
|
-
throw rejected('run has no failed or cancelled groups');
|
|
491
|
-
}
|
|
492
|
-
for (const group of groups) {
|
|
493
|
-
await this.apply(state, {
|
|
494
|
-
kind: 'retry',
|
|
495
|
-
group,
|
|
496
|
-
permissions: this.currentPermissions(state),
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
acknowledgeRun(queue, state);
|
|
500
|
-
itemStarted(queue, item.id, id, this.now());
|
|
501
|
-
return {
|
|
502
|
-
runId: id,
|
|
503
|
-
number: state.run.number,
|
|
504
|
-
branch: state.run.branch,
|
|
505
|
-
groups: state.groups.map((group) => ({ slug: group.slug, title: group.title })),
|
|
506
|
-
split: state.split !== null,
|
|
507
|
-
warnings: [],
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
/** `queue_return`: the run goes back to the queue as its first item. */
|
|
511
|
-
returnToQueue(params) {
|
|
512
|
-
return this.serial(async () => {
|
|
513
|
-
const state = this.state(params.runId);
|
|
514
|
-
if (params.repository !== undefined) {
|
|
515
|
-
const root = await this.rootOf(params.repository);
|
|
516
|
-
if (root !== state.run.repository) {
|
|
517
|
-
throw rejected('run belongs to another repository');
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
const queue = this.queueFor(state.run.repository);
|
|
521
|
-
const now = this.now();
|
|
522
|
-
const item = returnRun(queue, state, queueItemId(now, randomInt(36 ** 3)), now);
|
|
523
|
-
this.saveQueue(queue);
|
|
524
|
-
await this.advanceQueue(state.run.repository);
|
|
525
|
-
return { ...this.queueSnapshot(queue), item: item.id };
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* `run_pause`: the run keeps `hold: paused` and becomes the last item of the queue; the running
|
|
530
|
-
* agents are stopped by the `hold` event, and after run-now the step continues in the same session.
|
|
531
|
-
*/
|
|
532
|
-
pauseRunRequest(params) {
|
|
533
|
-
return this.serial(async () => {
|
|
534
|
-
const state = this.state(params.runId);
|
|
535
|
-
if (params.repository !== undefined) {
|
|
536
|
-
const root = await this.rootOf(params.repository);
|
|
537
|
-
if (root !== state.run.repository) {
|
|
538
|
-
throw rejected('run belongs to another repository');
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
const queue = this.queueFor(state.run.repository);
|
|
542
|
-
const now = this.now();
|
|
543
|
-
const item = pauseRun(queue, state, queueItemId(now, randomInt(36 ** 3)), now);
|
|
544
|
-
await this.apply(state, { kind: 'hold', hold: 'paused' });
|
|
545
|
-
this.saveQueue(queue);
|
|
546
|
-
await this.advanceQueue(state.run.repository);
|
|
547
|
-
return { ...this.queueSnapshot(queue), item: item.id };
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
/** `queue_dismiss`: a skipped run leaves the skipped list. */
|
|
551
|
-
dismissFromQueue(params) {
|
|
552
|
-
return this.serial(async () => {
|
|
553
|
-
const state = this.state(params.runId);
|
|
554
|
-
if (params.repository !== undefined) {
|
|
555
|
-
const root = await this.rootOf(params.repository);
|
|
556
|
-
if (root !== state.run.repository) {
|
|
557
|
-
throw rejected('run belongs to another repository');
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
const queue = this.queueFor(state.run.repository);
|
|
561
|
-
dismissRun(queue, state, this.now());
|
|
562
|
-
this.saveQueue(queue);
|
|
563
|
-
await this.advanceQueue(state.run.repository);
|
|
564
|
-
return this.queueSnapshot(queue);
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
/** Rejects an unknown pipeline or a `skip` that does not fit it. */
|
|
568
|
-
async ensureItem(repository, pipeline, skip = []) {
|
|
569
|
-
const config = loadConfig(configPaths(repository, this.environment.XDG_CONFIG_HOME, this.environment.HOME));
|
|
570
|
-
if (!findPipeline(config, pipeline)) {
|
|
571
|
-
const known = config.pipelines.map((candidate) => candidate.id).join(', ') || 'none';
|
|
572
|
-
throw rejected(`unknown pipeline \`${pipeline}\`; known: ${known}`);
|
|
573
|
-
}
|
|
574
|
-
const error = checkSkip(config, pipeline, skip);
|
|
575
|
-
if (error !== null)
|
|
576
|
-
throw rejected(error);
|
|
577
|
-
}
|
|
578
|
-
queueRequest(request) {
|
|
579
|
-
return this.serial(async () => {
|
|
580
|
-
const repository = await this.rootOf(request.params.repository);
|
|
581
|
-
const queue = this.queueFor(repository);
|
|
582
|
-
const now = this.now();
|
|
583
|
-
switch (request.method) {
|
|
584
|
-
case 'queue':
|
|
585
|
-
return this.queueSnapshot(queue);
|
|
586
|
-
case 'queue_add':
|
|
587
|
-
return this.addQueueItem(repository, request.params);
|
|
588
|
-
case 'queue_edit': {
|
|
589
|
-
const { item, pipeline, task, groups, title, position, autoDeliver, deliveryMode, postponed, } = request.params;
|
|
590
|
-
let skip = request.params.skip;
|
|
591
|
-
const returned = queue.items.find((candidate) => candidate.id === item);
|
|
592
|
-
const parentParam = request.params.parent;
|
|
593
|
-
if (returned?.run && parentParam !== undefined) {
|
|
594
|
-
throw rejected('a returned run keeps its own task');
|
|
595
|
-
}
|
|
596
|
-
const parentState = parentParam === undefined || parentParam === null
|
|
597
|
-
? null
|
|
598
|
-
: this.resolveParent(repository, parentParam);
|
|
599
|
-
if (returned?.run && skip !== undefined) {
|
|
600
|
-
// A returned run has no item-level skip: the steps are skipped in the run itself.
|
|
601
|
-
checkReturnedPatch({
|
|
602
|
-
pipeline,
|
|
603
|
-
task,
|
|
604
|
-
groups,
|
|
605
|
-
title,
|
|
606
|
-
tags: request.params.tags,
|
|
607
|
-
autoDeliver,
|
|
608
|
-
deliveryMode,
|
|
609
|
-
postponed,
|
|
610
|
-
skip,
|
|
611
|
-
}, true);
|
|
612
|
-
const state = this.lookupState(returned.run);
|
|
613
|
-
if (!state)
|
|
614
|
-
throw rejected(`unknown run \`${returned.run}\``);
|
|
615
|
-
const wanted = new Set(skip);
|
|
616
|
-
const current = new Set(state.run.skippedSteps);
|
|
617
|
-
const skipError = checkSkip(state.run.config, state.run.pipeline, [...wanted]);
|
|
618
|
-
if (skipError !== null)
|
|
619
|
-
throw rejected(skipError);
|
|
620
|
-
const changes = [
|
|
621
|
-
...[...current].filter((step) => !wanted.has(step)).map((step) => [step, false]),
|
|
622
|
-
...[...wanted].filter((step) => !current.has(step)).map((step) => [step, true]),
|
|
623
|
-
];
|
|
624
|
-
for (const [step] of changes) {
|
|
625
|
-
if (stepStates(state).find((entry) => entry.id === step)?.state === 'done') {
|
|
626
|
-
throw rejected(`step \`${step}\` is already passed by every group`);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
if (position !== undefined)
|
|
630
|
-
checkPosition(queue, position);
|
|
631
|
-
if (request.params.after !== undefined) {
|
|
632
|
-
checkDependencies(queue, item, [
|
|
633
|
-
...new Set(this.resolveDependencies(queue, request.params.after)),
|
|
634
|
-
]);
|
|
635
|
-
}
|
|
636
|
-
for (const [step, on] of changes) {
|
|
637
|
-
await this.apply(state, { kind: 'step_skip', step, skip: on });
|
|
638
|
-
}
|
|
639
|
-
skip = undefined;
|
|
640
|
-
}
|
|
641
|
-
if (pipeline !== undefined || skip !== undefined) {
|
|
642
|
-
const current = queue.items.find((candidate) => candidate.id === item);
|
|
643
|
-
if (current) {
|
|
644
|
-
await this.ensureItem(repository, pipeline ?? current.pipeline, skip ?? current.skip);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
const after = request.params.after === undefined
|
|
648
|
-
? undefined
|
|
649
|
-
: this.resolveDependencies(queue, request.params.after);
|
|
650
|
-
let tags = request.params.tags === undefined
|
|
651
|
-
? undefined
|
|
652
|
-
: resolveManualTags(this.catalogOf(repository), request.params.tags);
|
|
653
|
-
const existing = queue.items.find((candidate) => candidate.id === item);
|
|
654
|
-
const before = existing?.tags ?? [];
|
|
655
|
-
if (existing && tags !== undefined) {
|
|
656
|
-
const catalog = this.catalogOf(repository);
|
|
657
|
-
tags = keepLinkedTags(catalog, knownTags(catalog, existing.tags), tags);
|
|
658
|
-
}
|
|
659
|
-
const parentPending = existing !== undefined && parentParam !== undefined;
|
|
660
|
-
const patch = {
|
|
661
|
-
pipeline,
|
|
662
|
-
task,
|
|
663
|
-
groups,
|
|
664
|
-
title,
|
|
665
|
-
position,
|
|
666
|
-
autoDeliver,
|
|
667
|
-
deliveryMode,
|
|
668
|
-
skip,
|
|
669
|
-
after,
|
|
670
|
-
postponed,
|
|
671
|
-
};
|
|
672
|
-
// Every check of the edit runs on a copy before the tag of the parent is created.
|
|
673
|
-
if (existing && parentState)
|
|
674
|
-
editItem(structuredClone(queue), item, patch, now);
|
|
675
|
-
if (existing && parentPending) {
|
|
676
|
-
const parentTag = parentState ? await this.parentTagFor(repository, parentState) : null;
|
|
677
|
-
const rest = withoutLinkedTags(this.catalogOf(repository), tags ?? existing.tags);
|
|
678
|
-
tags = mergeTags(parentTag ? [parentTag.id] : [], rest);
|
|
679
|
-
}
|
|
680
|
-
if (existing && after !== undefined) {
|
|
681
|
-
const fresh = after.filter((ref) => !existing.after.includes(ref));
|
|
682
|
-
const inherited = knownTags(this.catalogOf(repository), dependencyTags(queue, fresh, (id) => this.lookupState(id)?.run.tags));
|
|
683
|
-
if (inherited.length > 0)
|
|
684
|
-
tags = mergeTags(tags ?? existing.tags, inherited);
|
|
685
|
-
}
|
|
686
|
-
editItem(queue, item, { ...patch, tags }, now);
|
|
687
|
-
const edited = queue.items.find((candidate) => candidate.id === item);
|
|
688
|
-
if (edited) {
|
|
689
|
-
spreadTags(queue, item, edited.tags.filter((id) => !before.includes(id)), now);
|
|
690
|
-
}
|
|
691
|
-
this.saveQueue(queue);
|
|
692
|
-
await this.advanceQueue(repository);
|
|
693
|
-
return this.queueSnapshot(queue);
|
|
694
|
-
}
|
|
695
|
-
case 'queue_remove': {
|
|
696
|
-
const removed = queue.items.find((candidate) => candidate.id === request.params.item);
|
|
697
|
-
removeItem(queue, request.params.item, now, (id) => this.lookupState(id));
|
|
698
|
-
const held = removed?.run ? this.lookupState(removed.run) : undefined;
|
|
699
|
-
if (held && held.run.hold !== null)
|
|
700
|
-
await this.apply(held, { kind: 'hold', hold: null });
|
|
701
|
-
return this.saveQueue(queue);
|
|
702
|
-
}
|
|
703
|
-
case 'queue_start': {
|
|
704
|
-
if (request.params.parallel !== undefined) {
|
|
705
|
-
setParallel(queue, request.params.parallel, now);
|
|
706
|
-
}
|
|
707
|
-
startQueue(queue, queue.runs.flatMap((id) => this.lookupState(id) ?? []), now);
|
|
708
|
-
this.saveQueue(queue);
|
|
709
|
-
await this.advanceQueue(repository);
|
|
710
|
-
return this.queueSnapshot(queue);
|
|
711
|
-
}
|
|
712
|
-
case 'queue_pause':
|
|
713
|
-
pauseQueue(queue, now);
|
|
714
|
-
return this.saveQueue(queue);
|
|
715
|
-
case 'queue_settings': {
|
|
716
|
-
const { parallel, autopilot, autoAnswer, skipFailed, autopilotAnswer } = request.params;
|
|
717
|
-
const onLimit = request.params.onLimit;
|
|
718
|
-
const enablesAutopilot = autopilot === true && !queue.autopilot;
|
|
719
|
-
setQueueSettings(queue, { parallel, autopilot, autoAnswer, skipFailed, autopilotAnswer, onLimit }, now);
|
|
720
|
-
if (enablesAutopilot && queue.status === 'stopped' && queue.stop === null) {
|
|
721
|
-
startQueue(queue, queue.runs.flatMap((id) => this.lookupState(id) ?? []), now);
|
|
722
|
-
}
|
|
723
|
-
this.saveQueue(queue);
|
|
724
|
-
await this.advanceQueue(repository);
|
|
725
|
-
return this.queueSnapshot(queue);
|
|
726
|
-
}
|
|
727
|
-
case 'queue_run_now': {
|
|
728
|
-
const item = queue.items.find((candidate) => candidate.id === request.params.item);
|
|
729
|
-
if (!item)
|
|
730
|
-
throw rejected('unknown queue item');
|
|
731
|
-
if (item.run !== null) {
|
|
732
|
-
const target = this.lookupState(item.run);
|
|
733
|
-
if (!target)
|
|
734
|
-
throw rejected(`unknown run \`${item.run}\``);
|
|
735
|
-
if (target.run.hold === null && retryableGroups(target).length === 0) {
|
|
736
|
-
throw rejected('run has no failed or cancelled groups');
|
|
737
|
-
}
|
|
738
|
-
await this.claimPlaceFor(queue, item.run);
|
|
739
|
-
const resumed = await this.takeReturned(queue, item);
|
|
740
|
-
this.saveQueue(queue);
|
|
741
|
-
return resumed;
|
|
742
|
-
}
|
|
743
|
-
const created = await this.createRun(itemParams(queue, item), knownTags(this.catalogOf(queue.repository), item.tags), item);
|
|
744
|
-
await this.claimPlaceFor(queue, created.runId);
|
|
745
|
-
itemStarted(queue, item.id, created.runId, this.now());
|
|
746
|
-
this.saveQueue(queue);
|
|
747
|
-
return created;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
broadcast(state) {
|
|
753
|
-
if (this.subscribers.size === 0)
|
|
754
|
-
return;
|
|
755
|
-
this.seq += 1;
|
|
756
|
-
const line = JSON.stringify({ event: 'run', seq: this.seq, run: this.view(state) });
|
|
757
|
-
for (const send of this.subscribers)
|
|
758
|
-
send(line);
|
|
759
|
-
}
|
|
760
|
-
view(state, now = this.now()) {
|
|
761
|
-
this.ensureDiffs(state);
|
|
762
|
-
const view = runView(state, now, (slug) => this.diffs.diffOf(state.run.id, slug), this.catalogOf(state.run.repository), this.engine.waitOf, this.artifacts.counts(state.run.id), this.observers);
|
|
763
|
-
const queue = this.queues.get(state.run.repository);
|
|
764
|
-
const item = queue ? returnItemOf(queue, state.run.id) : null;
|
|
765
|
-
return withQueue({ ...view, returnable: this.returnable(state) }, item?.id ?? null);
|
|
766
|
-
}
|
|
767
|
-
/** Whether `queue_return` would take the run: something to retry, and not in its queue yet. */
|
|
768
|
-
returnable(state) {
|
|
769
|
-
const queue = this.queues.get(state.run.repository);
|
|
770
|
-
if (!queue)
|
|
771
|
-
return retryableGroups(state).length > 0;
|
|
772
|
-
return canReturn(queue, state);
|
|
773
|
-
}
|
|
774
|
-
ensureDiffs(state) {
|
|
775
|
-
this.diffs.ensure(state);
|
|
776
|
-
}
|
|
777
|
-
refreshDiff(state, slug) {
|
|
778
|
-
return this.diffs.refresh(state, slug);
|
|
779
|
-
}
|
|
780
|
-
savePatch(state) {
|
|
781
|
-
return this.patches.save(state);
|
|
782
|
-
}
|
|
783
|
-
subscribe(send) {
|
|
784
|
-
this.seq += 1;
|
|
785
|
-
const runs = this.runStates.recent().map((state) => this.view(state));
|
|
786
|
-
const queues = [...this.queues.values()]
|
|
787
|
-
.filter((queue) => queue.items.length > 0 ||
|
|
788
|
-
queue.status === 'running' ||
|
|
789
|
-
queue.runs.length > 0 ||
|
|
790
|
-
queue.stop !== null)
|
|
791
|
-
.map((queue) => this.queueSnapshot(queue));
|
|
792
|
-
const repositories = this.repositoryList();
|
|
793
|
-
this.repositoriesJson = JSON.stringify(repositories);
|
|
794
|
-
send(JSON.stringify({
|
|
795
|
-
event: 'snapshot',
|
|
796
|
-
seq: this.seq,
|
|
797
|
-
runs,
|
|
798
|
-
queues,
|
|
799
|
-
repositories,
|
|
800
|
-
tags: catalogView(this.tags.all()),
|
|
801
|
-
}));
|
|
802
|
-
const processes = this.processes.lastSent();
|
|
803
|
-
if (processes !== null) {
|
|
804
|
-
this.seq += 1;
|
|
805
|
-
send(JSON.stringify({ event: 'processes', seq: this.seq, processes }));
|
|
806
|
-
}
|
|
807
|
-
this.subscribers.add(send);
|
|
808
|
-
this.processes.watch();
|
|
809
|
-
return () => {
|
|
810
|
-
this.subscribers.delete(send);
|
|
811
|
-
if (this.subscribers.size === 0)
|
|
812
|
-
this.processes.unwatch();
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
publishProcesses(payload) {
|
|
816
|
-
if (this.subscribers.size === 0)
|
|
817
|
-
return;
|
|
818
|
-
this.seq += 1;
|
|
819
|
-
const line = JSON.stringify({ event: 'processes', seq: this.seq, ...payload });
|
|
820
|
-
for (const send of this.subscribers)
|
|
821
|
-
send(line);
|
|
822
|
-
}
|
|
823
|
-
/** Starts the queues that resume after a usage limit. */
|
|
824
|
-
async wakeQueues() {
|
|
825
|
-
for (const queue of [...this.queues.values()]) {
|
|
826
|
-
if (queue.stop?.kind === 'limit')
|
|
827
|
-
await this.advanceQueue(queue.repository);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
async stop() {
|
|
831
|
-
this.engine.halt();
|
|
832
|
-
this.processes.stop();
|
|
833
|
-
await this.engine.drain();
|
|
834
|
-
this.database.close();
|
|
835
|
-
}
|
|
836
|
-
/** An agent runs (a step or the naming of a run) or a group merges. */
|
|
837
|
-
busy() {
|
|
838
|
-
return this.engine.busy();
|
|
839
|
-
}
|
|
840
|
-
serial(work) {
|
|
841
|
-
return this.engine.serial(work);
|
|
842
|
-
}
|
|
843
|
-
state(runIdentifier) {
|
|
844
|
-
return this.runStates.get(runIdentifier);
|
|
845
|
-
}
|
|
846
|
-
apply(state, event) {
|
|
847
|
-
return this.engine.apply(state, event);
|
|
848
|
-
}
|
|
849
|
-
schedule() {
|
|
850
|
-
return this.engine.schedule();
|
|
851
|
-
}
|
|
852
|
-
save(state) {
|
|
853
|
-
this.engine.save(state);
|
|
854
|
-
}
|
|
855
|
-
armWake() {
|
|
856
|
-
this.engine.armWake();
|
|
857
|
-
}
|
|
858
|
-
handle(request) {
|
|
859
|
-
switch (request.method) {
|
|
860
|
-
case 'ping':
|
|
861
|
-
return Promise.resolve({
|
|
862
|
-
pong: true,
|
|
863
|
-
pid: process.pid,
|
|
864
|
-
build: this.build,
|
|
865
|
-
busy: this.busy(),
|
|
866
|
-
});
|
|
867
|
-
case 'shutdown':
|
|
868
|
-
return Promise.resolve({ stopping: true });
|
|
869
|
-
case 'shutdown_idle':
|
|
870
|
-
// After the work already queued, so the check and the stop are one step.
|
|
871
|
-
return this.serial(() => {
|
|
872
|
-
if (this.engine.stopping || this.busy())
|
|
873
|
-
return Promise.resolve({ stopping: false });
|
|
874
|
-
// Stopping now keeps the scheduler from starting an agent before the daemon closes.
|
|
875
|
-
this.engine.halt();
|
|
876
|
-
return Promise.resolve({ stopping: true });
|
|
877
|
-
});
|
|
878
|
-
case 'subscribe':
|
|
879
|
-
return Promise.reject(rejected('subscribe is served on its own connection'));
|
|
880
|
-
case 'observers':
|
|
881
|
-
return Promise.resolve(this.observersSnapshot());
|
|
882
|
-
case 'observers_set':
|
|
883
|
-
return this.serial(() => this.observersSet(request.params.settings));
|
|
884
|
-
case 'run_observer':
|
|
885
|
-
return this.event(request.params.runId, {
|
|
886
|
-
kind: 'repair_allowed',
|
|
887
|
-
allowed: request.params.enabled,
|
|
888
|
-
});
|
|
889
|
-
case 'repair_action':
|
|
890
|
-
return this.repairAction(request.params);
|
|
891
|
-
case 'processes':
|
|
892
|
-
return this.processes.list();
|
|
893
|
-
case 'process_kill':
|
|
894
|
-
return this.processes.kill(request.params.pid);
|
|
895
|
-
case 'web_status':
|
|
896
|
-
return Promise.resolve(this.panel?.status() ?? {
|
|
897
|
-
running: false,
|
|
898
|
-
host: null,
|
|
899
|
-
port: null,
|
|
900
|
-
auth: null,
|
|
901
|
-
url: null,
|
|
902
|
-
reason: NO_PANEL,
|
|
903
|
-
stopped: false,
|
|
904
|
-
});
|
|
905
|
-
case 'web_start':
|
|
906
|
-
return this.panel ? this.panel.start(request.params) : Promise.reject(rejected(NO_PANEL));
|
|
907
|
-
case 'web_stop':
|
|
908
|
-
return this.panel ? this.panel.stop() : Promise.reject(rejected(NO_PANEL));
|
|
909
|
-
case 'repositories':
|
|
910
|
-
return Promise.resolve(this.repositoryList());
|
|
911
|
-
case 'repository_add':
|
|
912
|
-
return this.serial(async () => {
|
|
913
|
-
await this.rootOf(request.params.path);
|
|
914
|
-
return this.repositoryList();
|
|
915
|
-
});
|
|
916
|
-
case 'repository_remove':
|
|
917
|
-
return this.serial(() => this.repositoryRemove(request.params.path));
|
|
918
|
-
case 'run':
|
|
919
|
-
return this.serial(() => this.enqueueRun(request.params));
|
|
920
|
-
case 'status':
|
|
921
|
-
return Promise.resolve(this.status(request.params.runId));
|
|
922
|
-
case 'finished_runs':
|
|
923
|
-
return Promise.resolve(this.finishedRuns(request.params));
|
|
924
|
-
case 'group':
|
|
925
|
-
return Promise.resolve(this.group(request.params));
|
|
926
|
-
case 'group_spec':
|
|
927
|
-
return this.diffs.spec(request.params.runId, request.params.group);
|
|
928
|
-
case 'group_file_diff':
|
|
929
|
-
return this.diffs.fileDiff(request.params);
|
|
930
|
-
case 'run_patch':
|
|
931
|
-
return this.patches.runPatch(request.params.runId);
|
|
932
|
-
case 'group_artifacts':
|
|
933
|
-
return Promise.resolve().then(() => this.artifacts.list(request.params));
|
|
934
|
-
case 'artifact':
|
|
935
|
-
return this.artifacts.content(request.params);
|
|
936
|
-
case 'artifact_publish':
|
|
937
|
-
return this.artifacts.publish(request.params);
|
|
938
|
-
case 'transcript':
|
|
939
|
-
return Promise.resolve(this.transcript(request.params));
|
|
940
|
-
case 'pipelines':
|
|
941
|
-
return this.edits.pipelines(request.params.repository);
|
|
942
|
-
case 'system_stages':
|
|
943
|
-
return this.edits.systemStages(request.params.repository);
|
|
944
|
-
case 'config':
|
|
945
|
-
return this.edits.view(request.params.repository);
|
|
946
|
-
case 'config_catalog':
|
|
947
|
-
return this.edits.catalog(request.params.repository);
|
|
948
|
-
case 'config_write':
|
|
949
|
-
return this.edits.edit(request.params.repository, {
|
|
950
|
-
kind: request.params.kind,
|
|
951
|
-
id: request.params.id,
|
|
952
|
-
value: request.params.value,
|
|
953
|
-
revision: request.params.revision,
|
|
954
|
-
level: request.params.level ?? 'project',
|
|
955
|
-
});
|
|
956
|
-
case 'config_setting':
|
|
957
|
-
return this.edits.settings({
|
|
958
|
-
repository: request.params.repository,
|
|
959
|
-
values: { [request.params.path]: request.params.value },
|
|
960
|
-
revision: request.params.revision,
|
|
961
|
-
level: request.params.level,
|
|
962
|
-
});
|
|
963
|
-
case 'config_settings':
|
|
964
|
-
return this.edits.settings(request.params);
|
|
965
|
-
case 'config_preview':
|
|
966
|
-
return this.edits.preview(request.params);
|
|
967
|
-
case 'specialist_tags':
|
|
968
|
-
return Promise.resolve(this.shared.specialistTags());
|
|
969
|
-
case 'shared_specialists':
|
|
970
|
-
return Promise.resolve(this.shared.specialists());
|
|
971
|
-
case 'specialist_tags_set': {
|
|
972
|
-
const { repository, slug, tags, revision } = request.params;
|
|
973
|
-
return Promise.resolve().then(() => this.shared.setTags(repository, slug, tags, revision));
|
|
974
|
-
}
|
|
975
|
-
case 'specialist_tag_rename': {
|
|
976
|
-
const { repository, from, to } = request.params;
|
|
977
|
-
return Promise.resolve().then(() => this.shared.renameTag(repository, from, to));
|
|
978
|
-
}
|
|
979
|
-
case 'specialist_tag_remove': {
|
|
980
|
-
const { repository, tag } = request.params;
|
|
981
|
-
return Promise.resolve().then(() => this.shared.removeTag(repository, tag));
|
|
982
|
-
}
|
|
983
|
-
case 'shared_pipelines':
|
|
984
|
-
return Promise.resolve(this.shared.pipelines());
|
|
985
|
-
case 'pipelines_import':
|
|
986
|
-
return Promise.resolve().then(() => this.shared.importPipelines(request.params));
|
|
987
|
-
case 'specialists_import':
|
|
988
|
-
return Promise.resolve().then(() => this.shared.importSpecialists(request.params));
|
|
989
|
-
case 'config_delete':
|
|
990
|
-
return this.edits.edit(request.params.repository, {
|
|
991
|
-
kind: request.params.kind,
|
|
992
|
-
id: request.params.id,
|
|
993
|
-
value: null,
|
|
994
|
-
revision: request.params.revision,
|
|
995
|
-
level: request.params.level ?? 'project',
|
|
996
|
-
});
|
|
997
|
-
case 'cancel':
|
|
998
|
-
return this.event(request.params.runId, {
|
|
999
|
-
kind: 'cancel',
|
|
1000
|
-
group: request.params.group ?? null,
|
|
1001
|
-
});
|
|
1002
|
-
case 'retry':
|
|
1003
|
-
return this.retryGroup(request.params);
|
|
1004
|
-
case 'run_skip':
|
|
1005
|
-
return this.event(request.params.runId, {
|
|
1006
|
-
kind: 'step_skip',
|
|
1007
|
-
step: request.params.step,
|
|
1008
|
-
skip: request.params.skip,
|
|
1009
|
-
});
|
|
1010
|
-
case 'answer': {
|
|
1011
|
-
const { runId: id, group, answer } = request.params;
|
|
1012
|
-
return this.event(id, (state) => ({
|
|
1013
|
-
kind: 'answer',
|
|
1014
|
-
group,
|
|
1015
|
-
answer,
|
|
1016
|
-
permissions: this.currentPermissions(state),
|
|
1017
|
-
}));
|
|
1018
|
-
}
|
|
1019
|
-
case 'message': {
|
|
1020
|
-
const { runId: id, group, seq, text } = request.params;
|
|
1021
|
-
return this.event(id, { kind: 'message', group, seq, text });
|
|
1022
|
-
}
|
|
1023
|
-
case 'report':
|
|
1024
|
-
return this.workerEvent(request.params.token, (key) => ({
|
|
1025
|
-
kind: 'report',
|
|
1026
|
-
group: key.group,
|
|
1027
|
-
seq: key.seq,
|
|
1028
|
-
report: {
|
|
1029
|
-
verdict: request.params.verdict,
|
|
1030
|
-
summary: request.params.summary,
|
|
1031
|
-
feedback: request.params.feedback ?? null,
|
|
1032
|
-
questions: request.params.questions ?? null,
|
|
1033
|
-
...(request.params.human_only === true ? { humanOnly: true } : {}),
|
|
1034
|
-
},
|
|
1035
|
-
}));
|
|
1036
|
-
case 'split':
|
|
1037
|
-
return this.workerEvent(request.params.token, (key) => ({
|
|
1038
|
-
kind: 'split_proposed',
|
|
1039
|
-
seq: key.seq,
|
|
1040
|
-
groups: request.params.groups,
|
|
1041
|
-
}));
|
|
1042
|
-
case 'apply':
|
|
1043
|
-
return this.delivery.deliver(request.params);
|
|
1044
|
-
case 'run_mark_delivered':
|
|
1045
|
-
return this.delivery.markDelivered(request.params);
|
|
1046
|
-
case 'tags':
|
|
1047
|
-
return this.tags.catalogFor(request.params.repository).then(catalogView);
|
|
1048
|
-
case 'tag_add':
|
|
1049
|
-
return this.serial(() => this.tagAdd(request.params));
|
|
1050
|
-
case 'tag_edit':
|
|
1051
|
-
return this.serial(() => this.tagEdit(request.params));
|
|
1052
|
-
case 'tag_remove':
|
|
1053
|
-
return this.serial(() => this.tagRemove(request.params));
|
|
1054
|
-
case 'run_title':
|
|
1055
|
-
return this.serial(() => this.runTitle(request.params));
|
|
1056
|
-
case 'run_tags':
|
|
1057
|
-
return this.serial(() => this.runTags(request.params));
|
|
1058
|
-
case 'worker_queue_add':
|
|
1059
|
-
return this.workerQueueAdd(request.params);
|
|
1060
|
-
case 'queue':
|
|
1061
|
-
case 'queue_add':
|
|
1062
|
-
case 'queue_edit':
|
|
1063
|
-
case 'queue_remove':
|
|
1064
|
-
case 'queue_start':
|
|
1065
|
-
case 'queue_pause':
|
|
1066
|
-
case 'queue_settings':
|
|
1067
|
-
case 'queue_run_now':
|
|
1068
|
-
return this.queueRequest(request);
|
|
1069
|
-
case 'queue_return':
|
|
1070
|
-
return this.returnToQueue(request.params);
|
|
1071
|
-
case 'queue_dismiss':
|
|
1072
|
-
return this.dismissFromQueue(request.params);
|
|
1073
|
-
case 'run_pause':
|
|
1074
|
-
return this.pauseRunRequest(request.params);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
event(runIdentifier, event) {
|
|
1078
|
-
return this.runRequests.event(runIdentifier, event).then((state) => this.view(state));
|
|
1079
|
-
}
|
|
1080
|
-
/** A direct retry works at once, and the revived run holds a place in the queue. */
|
|
1081
|
-
retryGroup(params) {
|
|
1082
|
-
return this.serial(() => this.retryNow(this.state(params.runId), params));
|
|
1083
|
-
}
|
|
1084
|
-
/** The retry itself, for callers that already run inside `serial`. */
|
|
1085
|
-
async retryNow(state, params) {
|
|
1086
|
-
const keys = problemKeys(state);
|
|
1087
|
-
// Loaded before the event: a broken configuration refuses the retry with nothing changed.
|
|
1088
|
-
const refresh = params.refreshConfig === true
|
|
1089
|
-
? { specialists: this.currentSpecialists(state) }
|
|
1090
|
-
: { permissions: this.currentPermissions(state) };
|
|
1091
|
-
// A rejected retry leaves the hold in place; the hold is released only after it succeeds.
|
|
1092
|
-
await this.apply(state, { kind: 'retry', group: params.group, ...refresh });
|
|
1093
|
-
if (state.run.hold !== null)
|
|
1094
|
-
await this.apply(state, { kind: 'hold', hold: null });
|
|
1095
|
-
const queue = this.queueFor(state.run.repository);
|
|
1096
|
-
const now = this.now();
|
|
1097
|
-
const adopted = adoptRun(queue, state, keys, now, {
|
|
1098
|
-
states: queue.runs.flatMap((id) => this.lookupState(id) ?? []),
|
|
1099
|
-
itemId: queueItemId(now, randomInt(36 ** 3)),
|
|
1100
|
-
});
|
|
1101
|
-
if (adopted) {
|
|
1102
|
-
if (adopted.frozen !== null)
|
|
1103
|
-
await this.freezeRun(adopted.frozen);
|
|
1104
|
-
this.saveQueue(queue);
|
|
1105
|
-
this.requestAdvance(state.run.repository);
|
|
1106
|
-
}
|
|
1107
|
-
return this.view(state);
|
|
1108
|
-
}
|
|
1109
|
-
/** `observers_set`: new settings replace the old ones only when every value is right. */
|
|
1110
|
-
observersSet(settings) {
|
|
1111
|
-
const checked = checkObserverSettings(settings, this.observers, new Set(this.registry.paths()));
|
|
1112
|
-
if (checked.settings === null)
|
|
1113
|
-
return Promise.resolve({ ok: false, errors: checked.errors });
|
|
1114
|
-
this.observers = checked.settings;
|
|
1115
|
-
this.repositories.observers.saveObservers(this.observers);
|
|
1116
|
-
// The state `repair` of every run depends on the settings: send the runs again.
|
|
1117
|
-
for (const state of this.runStates.all())
|
|
1118
|
-
this.broadcast(state);
|
|
1119
|
-
return this.observe(true).then(() => {
|
|
1120
|
-
this.publishObservers();
|
|
1121
|
-
return { ok: true, observers: this.observersSnapshot() };
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
/** An action of an observer: only on its own run, by the rules of a person. */
|
|
1125
|
-
repairAction(params) {
|
|
1126
|
-
return this.serial(async () => {
|
|
1127
|
-
const key = this.effects.attemptFor(params.token);
|
|
1128
|
-
if (!key || key.group !== REPAIR_GROUP)
|
|
1129
|
-
throw rejected('unknown or expired report token');
|
|
1130
|
-
const state = this.state(key.run);
|
|
1131
|
-
const attempt = state.repair?.attempts.find((candidate) => candidate.seq === key.seq);
|
|
1132
|
-
if (!attempt || attempt.status !== 'running') {
|
|
1133
|
-
throw rejected('unknown or expired report token');
|
|
1134
|
-
}
|
|
1135
|
-
const target = (slug) => {
|
|
1136
|
-
const group = findGroup(state, slug);
|
|
1137
|
-
if (!group)
|
|
1138
|
-
throw rejected(`unknown group \`${slug}\` in run ${state.run.id}`);
|
|
1139
|
-
if (isServiceGroup(group) && !isSplitGroup(group)) {
|
|
1140
|
-
throw rejected(`group \`${slug}\` is a service group; observers do not touch it`);
|
|
1141
|
-
}
|
|
1142
|
-
return group;
|
|
1143
|
-
};
|
|
1144
|
-
switch (params.action) {
|
|
1145
|
-
case 'answer': {
|
|
1146
|
-
const group = target(params.group);
|
|
1147
|
-
if (group.humanOnly !== null && !this.observers.answerHumanOnly) {
|
|
1148
|
-
throw rejected(`the question of group \`${group.slug}\` is for a person only`);
|
|
1149
|
-
}
|
|
1150
|
-
await this.apply(state, {
|
|
1151
|
-
kind: 'answer',
|
|
1152
|
-
group: group.slug,
|
|
1153
|
-
answer: params.answer,
|
|
1154
|
-
by: 'observer',
|
|
1155
|
-
permissions: this.currentPermissions(state),
|
|
1156
|
-
});
|
|
1157
|
-
break;
|
|
1158
|
-
}
|
|
1159
|
-
case 'retry': {
|
|
1160
|
-
const group = target(params.group);
|
|
1161
|
-
if (group.status === 'cancelled') {
|
|
1162
|
-
throw rejected(`group \`${group.slug}\` was cancelled; observers do not restart it`);
|
|
1163
|
-
}
|
|
1164
|
-
await this.retryNow(state, { group: group.slug, refreshConfig: params.refreshConfig });
|
|
1165
|
-
break;
|
|
1166
|
-
}
|
|
1167
|
-
case 'cancel': {
|
|
1168
|
-
const group = params.group === undefined ? null : target(params.group);
|
|
1169
|
-
await this.apply(state, {
|
|
1170
|
-
kind: 'cancel',
|
|
1171
|
-
group: group?.slug ?? null,
|
|
1172
|
-
reason: params.reason,
|
|
1173
|
-
});
|
|
1174
|
-
break;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
return { recorded: true };
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
/** The tags of one repository; names are unique and resolved inside it only. */
|
|
1181
|
-
catalogOf(repository) {
|
|
1182
|
-
return this.tags.of(repository);
|
|
1183
|
-
}
|
|
1184
|
-
/** Publishes all tags and returns the catalog of the changed repository. */
|
|
1185
|
-
publishTags(repository) {
|
|
1186
|
-
this.tagsChanged(repository);
|
|
1187
|
-
return catalogView(this.catalogOf(repository));
|
|
1188
|
-
}
|
|
1189
|
-
tagsChanged(repository) {
|
|
1190
|
-
if (this.subscribers.size === 0)
|
|
1191
|
-
return;
|
|
1192
|
-
this.seq += 1;
|
|
1193
|
-
const line = JSON.stringify({
|
|
1194
|
-
event: 'tags',
|
|
1195
|
-
seq: this.seq,
|
|
1196
|
-
repository,
|
|
1197
|
-
tags: catalogView(this.tags.all()),
|
|
1198
|
-
});
|
|
1199
|
-
for (const send of this.subscribers)
|
|
1200
|
-
send(line);
|
|
1201
|
-
}
|
|
1202
|
-
async tagAdd(params) {
|
|
1203
|
-
return catalogView(this.catalogOf(await this.tags.add(params)));
|
|
1204
|
-
}
|
|
1205
|
-
async tagEdit(params) {
|
|
1206
|
-
return catalogView(this.catalogOf(await this.tags.edit(params)));
|
|
1207
|
-
}
|
|
1208
|
-
/** Takes the tag off every run and queue item, in memory and in the database, then publishes. */
|
|
1209
|
-
async tagRemove(params) {
|
|
1210
|
-
const repository = await this.rootOf(params.repository);
|
|
1211
|
-
const { id } = removeTag(this.catalogOf(repository), params.tag);
|
|
1212
|
-
// Three tables, one transaction: the scenario is opened here, each repository changes its own.
|
|
1213
|
-
this.database.transaction(() => {
|
|
1214
|
-
this.tags.deleteStored(repository, id);
|
|
1215
|
-
this.runStates.dropStoredTag(repository, id);
|
|
1216
|
-
this.repositories.queues.dropItemTag(repository, id);
|
|
1217
|
-
});
|
|
1218
|
-
this.tags.forget(id);
|
|
1219
|
-
for (const state of this.runStates.all()) {
|
|
1220
|
-
if (state.run.repository === repository && state.run.tags.includes(id)) {
|
|
1221
|
-
await this.apply(state, {
|
|
1222
|
-
kind: 'tags_set',
|
|
1223
|
-
tags: state.run.tags.filter((tag) => tag !== id),
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
for (const queue of this.queues.values()) {
|
|
1228
|
-
if (queue.repository !== repository)
|
|
1229
|
-
continue;
|
|
1230
|
-
if (!queue.items.some((item) => item.tags.includes(id)))
|
|
1231
|
-
continue;
|
|
1232
|
-
for (const item of queue.items)
|
|
1233
|
-
item.tags = item.tags.filter((tag) => tag !== id);
|
|
1234
|
-
queue.updatedAt = this.now();
|
|
1235
|
-
this.saveQueue(queue);
|
|
1236
|
-
}
|
|
1237
|
-
return this.publishTags(repository);
|
|
1238
|
-
}
|
|
1239
|
-
/** Own tags plus the tags of the predecessors in `after`, only those still in the catalog. */
|
|
1240
|
-
inheritTags(queue, own, after) {
|
|
1241
|
-
const inherited = dependencyTags(queue, after, (id) => this.lookupState(id)?.run.tags);
|
|
1242
|
-
return knownTags(this.catalogOf(queue.repository), mergeTags(own, inherited));
|
|
1243
|
-
}
|
|
1244
|
-
async runTitle(params) {
|
|
1245
|
-
return this.view(await this.runRequests.setTitle(params.runId, params.title));
|
|
1246
|
-
}
|
|
1247
|
-
async runTags(params) {
|
|
1248
|
-
const state = this.state(params.runId);
|
|
1249
|
-
const catalog = this.catalogOf(state.run.repository);
|
|
1250
|
-
const add = resolveManualTags(catalog, params.add ?? []);
|
|
1251
|
-
const remove = new Set(resolveTags(catalog, params.remove ?? []));
|
|
1252
|
-
const current = knownTags(catalog, state.run.tags).filter((id) => !remove.has(id));
|
|
1253
|
-
const tags = [...current, ...add.filter((id) => !current.includes(id) && !remove.has(id))];
|
|
1254
|
-
await this.apply(state, { kind: 'tags_set', tags });
|
|
1255
|
-
const added = tags.filter((id) => !current.includes(id));
|
|
1256
|
-
if (added.length > 0) {
|
|
1257
|
-
const queue = this.queueFor(state.run.repository);
|
|
1258
|
-
if (spreadTags(queue, state.run.id, added, this.now()).length > 0)
|
|
1259
|
-
this.saveQueue(queue);
|
|
1260
|
-
}
|
|
1261
|
-
return this.view(state);
|
|
1262
|
-
}
|
|
1263
|
-
/** `run`: the task goes to the end of the queue, a stopped queue is started, then the queue advances. */
|
|
1264
|
-
async enqueueRun(params) {
|
|
1265
|
-
const repository = await this.rootOf(params.repository);
|
|
1266
|
-
const queue = this.queueFor(repository);
|
|
1267
|
-
const now = this.now();
|
|
1268
|
-
const { pipeline, task, groups, title, autoDeliver, deliveryMode, skip } = params;
|
|
1269
|
-
await this.ensureItem(repository, pipeline, skip);
|
|
1270
|
-
const after = this.resolveDependencies(queue, params.after ?? []);
|
|
1271
|
-
const manual = resolveManualTags(this.catalogOf(repository), params.tags ?? []);
|
|
1272
|
-
const parent = params.parent === undefined ? null : this.resolveParent(repository, params.parent);
|
|
1273
|
-
if (parent) {
|
|
1274
|
-
this.checkNewItem(queue, { pipeline, task, groups, title, autoDeliver, deliveryMode, skip, after }, now);
|
|
1275
|
-
}
|
|
1276
|
-
const parentTag = parent ? await this.parentTagFor(repository, parent) : null;
|
|
1277
|
-
const tags = this.inheritTags(queue, mergeTags(parentTag ? [parentTag.id] : [], manual), after);
|
|
1278
|
-
const item = addItem(queue, { pipeline, task, groups, title, autoDeliver, deliveryMode, tags, skip, after }, queueItemId(now, randomInt(36 ** 3)), now);
|
|
1279
|
-
if (queue.status === 'stopped') {
|
|
1280
|
-
startQueue(queue, queue.runs.flatMap((id) => this.lookupState(id) ?? []), now);
|
|
1281
|
-
}
|
|
1282
|
-
this.saveQueue(queue);
|
|
1283
|
-
const started = await this.advanceQueue(repository);
|
|
1284
|
-
const run = started.get(item.id) ?? null;
|
|
1285
|
-
if (!run && queue.stop?.kind === 'item' && queue.stop.item === item.id) {
|
|
1286
|
-
throw rejected(queue.stop.error);
|
|
1287
|
-
}
|
|
1288
|
-
return { item: item.id, number: item.number, run, queue: this.queueSnapshot(queue) };
|
|
1289
|
-
}
|
|
1290
|
-
async addQueueItem(repository, params, inherited) {
|
|
1291
|
-
const { pipeline, task, groups, title, autoDeliver, deliveryMode, skip, postponed } = params;
|
|
1292
|
-
const queue = this.queueFor(repository);
|
|
1293
|
-
const now = this.now();
|
|
1294
|
-
await this.ensureItem(repository, pipeline, skip);
|
|
1295
|
-
const after = this.resolveDependencies(queue, params.after ?? []);
|
|
1296
|
-
let own = inherited ?? resolveManualTags(this.catalogOf(repository), params.tags ?? []);
|
|
1297
|
-
if (params.parent !== undefined) {
|
|
1298
|
-
const parent = this.resolveParent(repository, params.parent);
|
|
1299
|
-
this.checkNewItem(queue, { pipeline, task, groups, title, autoDeliver, deliveryMode, skip, after, postponed }, now);
|
|
1300
|
-
const parentTag = await this.parentTagFor(repository, parent);
|
|
1301
|
-
own = mergeTags(parentTag ? [parentTag.id] : [], own);
|
|
1302
|
-
}
|
|
1303
|
-
const tags = this.inheritTags(queue, own, after);
|
|
1304
|
-
const item = addItem(queue, { pipeline, task, groups, title, autoDeliver, deliveryMode, tags, skip, after, postponed }, queueItemId(now, randomInt(36 ** 3)), now);
|
|
1305
|
-
this.saveQueue(queue);
|
|
1306
|
-
await this.advanceQueue(repository);
|
|
1307
|
-
return { ...this.queueSnapshot(queue), item: item.id };
|
|
1308
|
-
}
|
|
1309
|
-
/** Runs the checks of `addItem` on a copy of the queue: nothing changes. */
|
|
1310
|
-
checkNewItem(queue, fields, now) {
|
|
1311
|
-
addItem(structuredClone(queue), fields, queueItemId(now, 0), now);
|
|
1312
|
-
}
|
|
1313
|
-
/** The run a `parent` refers to: a run id first, then a task number of the repository. */
|
|
1314
|
-
resolveParent(repository, ref) {
|
|
1315
|
-
const parsed = parseParentRef(ref);
|
|
1316
|
-
if (parsed.id !== null) {
|
|
1317
|
-
const state = this.lookupState(parsed.id);
|
|
1318
|
-
if (state)
|
|
1319
|
-
return state;
|
|
1320
|
-
}
|
|
1321
|
-
if (parsed.number !== null) {
|
|
1322
|
-
const id = this.runStates.idByNumber(repository, parsed.number);
|
|
1323
|
-
const state = id === null ? undefined : this.lookupState(id);
|
|
1324
|
-
if (state)
|
|
1325
|
-
return state;
|
|
1326
|
-
}
|
|
1327
|
-
throw rejected(`unknown parent \`${ref}\``);
|
|
1328
|
-
}
|
|
1329
|
-
/**
|
|
1330
|
-
* The linked task tag of a parent for a task of `repository`. A parent from another
|
|
1331
|
-
* repository gives no tag: the catalogs are per repository, and nothing is created there.
|
|
1332
|
-
*/
|
|
1333
|
-
async parentTagFor(repository, parent) {
|
|
1334
|
-
return parent.run.repository === repository ? this.linkedTagFor(parent) : null;
|
|
1335
|
-
}
|
|
1336
|
-
/**
|
|
1337
|
-
* The linked task tag of the run: the existing one or a new one named after the run.
|
|
1338
|
-
* The tag goes to the run itself too (first), and to the items that wait for it.
|
|
1339
|
-
*/
|
|
1340
|
-
async linkedTagFor(state) {
|
|
1341
|
-
const run = state.run;
|
|
1342
|
-
const catalog = this.catalogOf(run.repository);
|
|
1343
|
-
let tag = linkedTagOf(catalog, run.id);
|
|
1344
|
-
if (!tag) {
|
|
1345
|
-
const base = run.name ?? (run.title ? runName(run.title) : run.id);
|
|
1346
|
-
tag = this.tags.create({
|
|
1347
|
-
repository: run.repository,
|
|
1348
|
-
name: autoTagName(catalog, base),
|
|
1349
|
-
task: { run: run.id, number: run.number },
|
|
1350
|
-
});
|
|
1351
|
-
this.publishTags(run.repository);
|
|
1352
|
-
}
|
|
1353
|
-
const own = knownTags(this.catalogOf(run.repository), run.tags);
|
|
1354
|
-
if (!own.includes(tag.id)) {
|
|
1355
|
-
await this.apply(state, { kind: 'tags_set', tags: [tag.id, ...own] });
|
|
1356
|
-
const queue = this.queueFor(run.repository);
|
|
1357
|
-
if (spreadTags(queue, run.id, [tag.id], this.now()).length > 0)
|
|
1358
|
-
this.saveQueue(queue);
|
|
1359
|
-
}
|
|
1360
|
-
return tag;
|
|
1361
|
-
}
|
|
1362
|
-
/** A task from a specialist with `queue: true` goes to the queue of the repository of its run. */
|
|
1363
|
-
workerQueueAdd(params) {
|
|
1364
|
-
return this.serial(async () => {
|
|
1365
|
-
const key = this.effects.attemptFor(params.token);
|
|
1366
|
-
if (!key)
|
|
1367
|
-
throw rejected('unknown or expired report token');
|
|
1368
|
-
const state = this.state(key.run);
|
|
1369
|
-
const attempt = state.groups
|
|
1370
|
-
.find((group) => group.slug === key.group)
|
|
1371
|
-
?.attempts.find((candidate) => candidate.seq === key.seq);
|
|
1372
|
-
if (!attempt || attempt.status !== 'running') {
|
|
1373
|
-
throw rejected('unknown or expired report token');
|
|
1374
|
-
}
|
|
1375
|
-
if (findSpecialist(state.run.config, attempt.specialist)?.queue !== true) {
|
|
1376
|
-
throw rejected(`specialist \`${attempt.specialist}\` may not add tasks to the queue`);
|
|
1377
|
-
}
|
|
1378
|
-
// Every task carries the linked task tag of its run, then the other tags of the run.
|
|
1379
|
-
const repository = state.run.repository;
|
|
1380
|
-
await this.ensureItem(repository, params.pipeline, params.skip);
|
|
1381
|
-
const queue = this.queueFor(repository);
|
|
1382
|
-
const after = this.resolveDependencies(queue, params.after ?? []);
|
|
1383
|
-
const { pipeline, task, groups, title, autoDeliver, deliveryMode, skip } = params;
|
|
1384
|
-
this.checkNewItem(queue, { pipeline, task, groups, title, autoDeliver, deliveryMode, skip, after }, this.now());
|
|
1385
|
-
const tag = await this.linkedTagFor(state);
|
|
1386
|
-
return this.addQueueItem(repository, params, mergeTags([tag.id], knownTags(this.catalogOf(repository), state.run.tags)));
|
|
1387
|
-
});
|
|
1388
|
-
}
|
|
1389
|
-
workerEvent(token, build) {
|
|
1390
|
-
return this.runRequests.workerEvent(token, build);
|
|
1391
|
-
}
|
|
1392
|
-
/**
|
|
1393
|
-
* Turns the ids a task waits for into ids of queue items or runs of the repository.
|
|
1394
|
-
* An item that already became a run is replaced by that run.
|
|
1395
|
-
*/
|
|
1396
|
-
resolveDependencies(queue, ids) {
|
|
1397
|
-
return [...new Set(ids)].map((id) => {
|
|
1398
|
-
if (queue.items.some((item) => item.id === id))
|
|
1399
|
-
return id;
|
|
1400
|
-
const own = this.lookupState(id);
|
|
1401
|
-
if (own?.run.repository === queue.repository)
|
|
1402
|
-
return id;
|
|
1403
|
-
const started = this.runStates.runOfQueueItem(queue.repository, id);
|
|
1404
|
-
if (started)
|
|
1405
|
-
return started.run.id;
|
|
1406
|
-
throw rejected(`unknown dependency \`${id}\``);
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
createRun(params, tagIds, queueItem) {
|
|
1410
|
-
return this.runRequests.create(params, tagIds, queueItem);
|
|
1411
|
-
}
|
|
1412
|
-
status(runIdentifier) {
|
|
1413
|
-
const now = this.now();
|
|
1414
|
-
if (runIdentifier)
|
|
1415
|
-
return this.view(this.state(runIdentifier), now);
|
|
1416
|
-
return this.runStates.recent().map((state) => this.view(state, now));
|
|
1417
|
-
}
|
|
1418
|
-
/** A page of finished runs after the cursor `<created_at>.<id>`; `next` is null at the end. */
|
|
1419
|
-
finishedRuns(params) {
|
|
1420
|
-
const now = this.now();
|
|
1421
|
-
const page = this.runStates.page(params.limit, params.before);
|
|
1422
|
-
return { runs: page.runs.map((state) => this.view(state, now)), next: page.next };
|
|
1423
|
-
}
|
|
1424
|
-
currentSpecialists(state) {
|
|
1425
|
-
return currentSpecialists(this.config, state);
|
|
1426
|
-
}
|
|
1427
|
-
currentPermissions(state) {
|
|
1428
|
-
return currentPermissions(this.config, state);
|
|
1429
|
-
}
|
|
1430
|
-
configPathsOf(repository) {
|
|
1431
|
-
return this.config.pathsOf(repository);
|
|
1432
|
-
}
|
|
1433
|
-
transcript(params) {
|
|
1434
|
-
return this.runReads.transcript(params);
|
|
1435
|
-
}
|
|
1436
|
-
group(params) {
|
|
1437
|
-
const { state, group, worktree, log } = this.runReads.group(params.runId, params.group, params.tailLines);
|
|
1438
|
-
this.ensureDiffs(state);
|
|
1439
|
-
return groupView(state, group, worktree, log, this.now(), this.diffs.diffOf(state.run.id, group.slug), this.engine.waitOf);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
//# sourceMappingURL=daemon.js.map
|