@turri-dev/cli 0.4.2 → 0.4.3-next.4908c8d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/banner.js +259 -0
- package/dist/capture-cli.js +77 -0
- package/dist/capture-view.js +99 -0
- package/dist/chat-commands.js +9 -63
- package/dist/chat-models.js +17 -15
- package/dist/chat-tab-header.js +90 -0
- package/dist/chat-tabs.js +100 -0
- package/dist/chat-terminal.js +170 -61
- package/dist/chat-waiting.js +7 -24
- package/dist/cli-options.js +11 -7
- package/dist/cli-root.js +141 -0
- package/dist/cli.js +48 -36
- package/dist/conform-cli.js +4 -6
- package/dist/cultivate-cli.js +65 -97
- package/dist/doctor-cli.js +99 -0
- package/dist/drift-cli.js +2 -7
- package/dist/entry-renderers.js +107 -0
- package/dist/extension.js +14 -3211
- package/dist/init-config-cli.js +209 -0
- package/dist/launch-cli.js +55 -91
- package/dist/lineage-cli.js +2 -4
- package/dist/loop-cli.js +118 -233
- package/dist/panel-view.js +409 -0
- package/dist/parse-cli.js +5 -2
- package/dist/pi-launch.js +43 -13
- package/dist/pi-themes.js +21 -0
- package/dist/plain-code-blocks.js +56 -0
- package/dist/pointer-hover.js +48 -0
- package/dist/print-mode.js +20 -0
- package/dist/question-dialog.js +26 -3
- package/dist/quiet.js +7 -106
- package/dist/regenerate/diff-view.js +6 -87
- package/dist/regenerate/jobs-tree.js +7 -18
- package/dist/regenerate/side-panel.js +158 -22
- package/dist/regenerate/spec-map-view.js +25 -70
- package/dist/regenerate-cli.js +7 -11
- package/dist/reopen.js +80 -0
- package/dist/resume-line.js +5 -2
- package/dist/skill-progress.js +25 -0
- package/dist/skill-report.js +52 -0
- package/dist/terminal-marks.js +21 -0
- package/dist/terminal-notifications.js +219 -0
- package/dist/terminal-view.js +275 -0
- package/dist/turri-versions.js +64 -6
- package/docs/README.md +4 -2
- package/docs/capture.md +227 -0
- package/docs/chats.md +14 -10
- package/docs/claude-subscription.md +1 -1
- package/docs/config.md +23 -8
- package/docs/development.md +30 -61
- package/docs/headless.md +3 -1
- package/docs/hosting.md +3 -251
- package/docs/installation.md +5 -3
- package/docs/launch.md +3 -3
- package/docs/regenerating.md +1 -1
- package/docs/sandbox.md +4 -2
- package/docs/sentinel.md +13 -13
- package/docs/theming.md +3 -3
- package/docs/using.md +14 -6
- package/package.json +15 -33
- package/dist/ask.d.ts +0 -90
- package/dist/ask.js +0 -170
- package/dist/background-skills.d.ts +0 -53
- package/dist/background-skills.js +0 -121
- package/dist/bedrock-region.d.ts +0 -66
- package/dist/bedrock-region.js +0 -144
- package/dist/brand.d.ts +0 -13
- package/dist/btw.d.ts +0 -69
- package/dist/btw.js +0 -174
- package/dist/chat-commands.d.ts +0 -25
- package/dist/chat-idle.d.ts +0 -7
- package/dist/chat-idle.js +0 -20
- package/dist/chat-models.d.ts +0 -22
- package/dist/chat-records.d.ts +0 -50
- package/dist/chat-records.js +0 -107
- package/dist/chat-scope.d.ts +0 -14
- package/dist/chat-scope.js +0 -15
- package/dist/chat-skills.d.ts +0 -17
- package/dist/chat-skills.js +0 -18
- package/dist/chat-terminal.d.ts +0 -24
- package/dist/chat-ui.d.ts +0 -33
- package/dist/chat-waiting.d.ts +0 -64
- package/dist/chats.d.ts +0 -338
- package/dist/chats.js +0 -996
- package/dist/cli-options.d.ts +0 -24
- package/dist/cli.d.ts +0 -9
- package/dist/config-edit.d.ts +0 -83
- package/dist/config-edit.js +0 -390
- package/dist/config.d.ts +0 -415
- package/dist/config.js +0 -757
- package/dist/conform-cli.d.ts +0 -1
- package/dist/conformance-switch.d.ts +0 -25
- package/dist/conformance-switch.js +0 -86
- package/dist/cultivate-cli.d.ts +0 -1
- package/dist/doctor-tool.d.ts +0 -11
- package/dist/doctor-tool.js +0 -33
- package/dist/drift-cli.d.ts +0 -1
- package/dist/environment.d.ts +0 -37
- package/dist/environment.js +0 -109
- package/dist/extension.d.ts +0 -208
- package/dist/genome.d.ts +0 -77
- package/dist/genome.js +0 -288
- package/dist/graph.d.ts +0 -52
- package/dist/graph.js +0 -247
- package/dist/host-session.d.ts +0 -112
- package/dist/host-session.js +0 -103
- package/dist/host.d.ts +0 -40
- package/dist/host.js +0 -54
- package/dist/identity.d.ts +0 -7
- package/dist/identity.js +0 -74
- package/dist/init-config.d.ts +0 -169
- package/dist/init-config.js +0 -840
- package/dist/installed-providers.d.ts +0 -40
- package/dist/installed-providers.js +0 -98
- package/dist/jellyfish.d.ts +0 -40
- package/dist/judge.d.ts +0 -25
- package/dist/judge.js +0 -62
- package/dist/launch-agent.d.ts +0 -62
- package/dist/launch-agent.js +0 -339
- package/dist/launch-cli.d.ts +0 -1
- package/dist/launch-session.d.ts +0 -68
- package/dist/launch-session.js +0 -225
- package/dist/launch-tools.d.ts +0 -28
- package/dist/launch-tools.js +0 -72
- package/dist/launch-track.d.ts +0 -175
- package/dist/launch-track.js +0 -497
- package/dist/lineage-cli.d.ts +0 -1
- package/dist/loop-cli.d.ts +0 -35
- package/dist/loop-tools.d.ts +0 -103
- package/dist/loop-tools.js +0 -357
- package/dist/model-check.d.ts +0 -72
- package/dist/model-check.js +0 -162
- package/dist/module-report.d.ts +0 -9
- package/dist/new-project.d.ts +0 -5
- package/dist/new-project.js +0 -31
- package/dist/notice.d.ts +0 -115
- package/dist/notice.js +0 -61
- package/dist/parse-cli.d.ts +0 -1
- package/dist/parse-tool.d.ts +0 -9
- package/dist/parse-tool.js +0 -33
- package/dist/pi-launch.d.ts +0 -1
- package/dist/pi-settings.d.ts +0 -4
- package/dist/pi.d.ts +0 -248
- package/dist/pi.js +0 -889
- package/dist/picture-row.d.ts +0 -10
- package/dist/plain/check.d.ts +0 -63
- package/dist/plain/check.js +0 -236
- package/dist/plain/concepts.d.ts +0 -37
- package/dist/plain/concepts.js +0 -283
- package/dist/plain/cycles.d.ts +0 -21
- package/dist/plain/cycles.js +0 -190
- package/dist/plain/errors.d.ts +0 -26
- package/dist/plain/errors.js +0 -50
- package/dist/plain/files.d.ts +0 -47
- package/dist/plain/files.js +0 -161
- package/dist/plain/graph.d.ts +0 -107
- package/dist/plain/graph.js +0 -194
- package/dist/plain/highlight.d.ts +0 -43
- package/dist/plain/highlight.js +0 -196
- package/dist/plain/index.d.ts +0 -18
- package/dist/plain/index.js +0 -18
- package/dist/plain/liquid.d.ts +0 -22
- package/dist/plain/liquid.js +0 -124
- package/dist/plain/markdown.d.ts +0 -103
- package/dist/plain/markdown.js +0 -330
- package/dist/plain/module-concepts.d.ts +0 -32
- package/dist/plain/module-concepts.js +0 -80
- package/dist/plain/parser.d.ts +0 -163
- package/dist/plain/parser.js +0 -930
- package/dist/plain/plain.tmLanguage.json +0 -150
- package/dist/plain/project.d.ts +0 -48
- package/dist/plain/project.js +0 -155
- package/dist/plain/spec.d.ts +0 -152
- package/dist/plain/spec.js +0 -265
- package/dist/plain/stdlib.d.ts +0 -16
- package/dist/plain/stdlib.js +0 -48
- package/dist/plain/test-plain-file.d.ts +0 -59
- package/dist/plain/test-plain-file.js +0 -232
- package/dist/plain-files.d.ts +0 -21
- package/dist/plain-files.js +0 -156
- package/dist/question-dialog.d.ts +0 -55
- package/dist/questioning.d.ts +0 -55
- package/dist/questioning.js +0 -109
- package/dist/quiet.d.ts +0 -34
- package/dist/regenerate/activity.d.ts +0 -227
- package/dist/regenerate/activity.js +0 -250
- package/dist/regenerate/agent-env.d.ts +0 -51
- package/dist/regenerate/agent-env.js +0 -311
- package/dist/regenerate/agent-shell.d.ts +0 -54
- package/dist/regenerate/agent-shell.js +0 -121
- package/dist/regenerate/arbiter.d.ts +0 -68
- package/dist/regenerate/arbiter.js +0 -133
- package/dist/regenerate/audit.d.ts +0 -69
- package/dist/regenerate/audit.js +0 -212
- package/dist/regenerate/base-folder.d.ts +0 -70
- package/dist/regenerate/base-folder.js +0 -186
- package/dist/regenerate/cases.d.ts +0 -12
- package/dist/regenerate/cases.js +0 -149
- package/dist/regenerate/change-view.d.ts +0 -23
- package/dist/regenerate/change-view.js +0 -153
- package/dist/regenerate/chunk-plan.d.ts +0 -217
- package/dist/regenerate/chunk-plan.js +0 -937
- package/dist/regenerate/codebase.d.ts +0 -21
- package/dist/regenerate/codebase.js +0 -75
- package/dist/regenerate/command-check.d.ts +0 -66
- package/dist/regenerate/command-check.js +0 -508
- package/dist/regenerate/compaction.d.ts +0 -13
- package/dist/regenerate/compaction.js +0 -20
- package/dist/regenerate/confine.d.ts +0 -69
- package/dist/regenerate/confine.js +0 -311
- package/dist/regenerate/conform.d.ts +0 -66
- package/dist/regenerate/conform.js +0 -132
- package/dist/regenerate/conformance-agents.d.ts +0 -388
- package/dist/regenerate/conformance-agents.js +0 -1162
- package/dist/regenerate/conformance.d.ts +0 -191
- package/dist/regenerate/conformance.js +0 -1035
- package/dist/regenerate/conversation-writes.d.ts +0 -10
- package/dist/regenerate/conversation-writes.js +0 -100
- package/dist/regenerate/credentials.d.ts +0 -18
- package/dist/regenerate/credentials.js +0 -88
- package/dist/regenerate/debug-log.d.ts +0 -56
- package/dist/regenerate/debug-log.js +0 -236
- package/dist/regenerate/debugger.d.ts +0 -36
- package/dist/regenerate/debugger.js +0 -133
- package/dist/regenerate/delivery.d.ts +0 -2
- package/dist/regenerate/diagnose-job.d.ts +0 -2
- package/dist/regenerate/diagnose-job.js +0 -40
- package/dist/regenerate/diagnose.d.ts +0 -46
- package/dist/regenerate/diagnose.js +0 -92
- package/dist/regenerate/diff-view.d.ts +0 -64
- package/dist/regenerate/drift.d.ts +0 -120
- package/dist/regenerate/drift.js +0 -285
- package/dist/regenerate/environment-error.d.ts +0 -167
- package/dist/regenerate/environment-error.js +0 -342
- package/dist/regenerate/failure-reports.d.ts +0 -28
- package/dist/regenerate/failure-reports.js +0 -79
- package/dist/regenerate/job-log.d.ts +0 -30
- package/dist/regenerate/job-log.js +0 -105
- package/dist/regenerate/job-panel.d.ts +0 -122
- package/dist/regenerate/job-panel.js +0 -339
- package/dist/regenerate/jobs-tree.d.ts +0 -75
- package/dist/regenerate/jobs.d.ts +0 -231
- package/dist/regenerate/jobs.js +0 -522
- package/dist/regenerate/lanes.d.ts +0 -16
- package/dist/regenerate/lanes.js +0 -32
- package/dist/regenerate/launch.d.ts +0 -256
- package/dist/regenerate/launch.js +0 -689
- package/dist/regenerate/ledger-view.d.ts +0 -87
- package/dist/regenerate/ledger-view.js +0 -325
- package/dist/regenerate/ledger.d.ts +0 -368
- package/dist/regenerate/ledger.js +0 -357
- package/dist/regenerate/lineage.d.ts +0 -105
- package/dist/regenerate/lineage.js +0 -485
- package/dist/regenerate/list-arguments.d.ts +0 -21
- package/dist/regenerate/list-arguments.js +0 -121
- package/dist/regenerate/loop.d.ts +0 -423
- package/dist/regenerate/loop.js +0 -2079
- package/dist/regenerate/masking.d.ts +0 -19
- package/dist/regenerate/masking.js +0 -95
- package/dist/regenerate/model-names.d.ts +0 -33
- package/dist/regenerate/model-names.js +0 -92
- package/dist/regenerate/notes.d.ts +0 -159
- package/dist/regenerate/notes.js +0 -446
- package/dist/regenerate/os-sandbox.d.ts +0 -93
- package/dist/regenerate/os-sandbox.js +0 -283
- package/dist/regenerate/panel-dock.d.ts +0 -23
- package/dist/regenerate/paths.d.ts +0 -110
- package/dist/regenerate/paths.js +0 -190
- package/dist/regenerate/plain-palette.d.ts +0 -34
- package/dist/regenerate/prompt.d.ts +0 -230
- package/dist/regenerate/prompt.js +0 -741
- package/dist/regenerate/pulse-files.d.ts +0 -14
- package/dist/regenerate/pulse-files.js +0 -63
- package/dist/regenerate/records.d.ts +0 -132
- package/dist/regenerate/records.js +0 -327
- package/dist/regenerate/regenerate.d.ts +0 -106
- package/dist/regenerate/regenerate.js +0 -660
- package/dist/regenerate/regression.d.ts +0 -58
- package/dist/regenerate/regression.js +0 -188
- package/dist/regenerate/renames.d.ts +0 -42
- package/dist/regenerate/renames.js +0 -185
- package/dist/regenerate/requires.d.ts +0 -117
- package/dist/regenerate/requires.js +0 -377
- package/dist/regenerate/resources.d.ts +0 -57
- package/dist/regenerate/resources.js +0 -162
- package/dist/regenerate/scripts-being-written.d.ts +0 -19
- package/dist/regenerate/scripts-being-written.js +0 -30
- package/dist/regenerate/self-check.d.ts +0 -29
- package/dist/regenerate/self-check.js +0 -119
- package/dist/regenerate/services.d.ts +0 -28
- package/dist/regenerate/services.js +0 -158
- package/dist/regenerate/shell.d.ts +0 -91
- package/dist/regenerate/shell.js +0 -320
- package/dist/regenerate/side-panel.d.ts +0 -59
- package/dist/regenerate/spec-map-view.d.ts +0 -139
- package/dist/regenerate/spec-map.d.ts +0 -160
- package/dist/regenerate/spec-map.js +0 -596
- package/dist/regenerate/spec-steps.d.ts +0 -180
- package/dist/regenerate/spec-steps.js +0 -729
- package/dist/regenerate/standing.d.ts +0 -28
- package/dist/regenerate/standing.js +0 -30
- package/dist/regenerate/state.d.ts +0 -21
- package/dist/regenerate/state.js +0 -10
- package/dist/regenerate/steering.d.ts +0 -56
- package/dist/regenerate/steering.js +0 -119
- package/dist/regenerate/stop-report.d.ts +0 -43
- package/dist/regenerate/stop-report.js +0 -160
- package/dist/regenerate/submit-work.d.ts +0 -44
- package/dist/regenerate/submit-work.js +0 -76
- package/dist/regenerate/test-kinds.d.ts +0 -85
- package/dist/regenerate/test-kinds.js +0 -171
- package/dist/regenerate/test-scripts.d.ts +0 -235
- package/dist/regenerate/test-scripts.js +0 -843
- package/dist/regenerate/testing-steps.d.ts +0 -52
- package/dist/regenerate/testing-steps.js +0 -129
- package/dist/regenerate/testing.d.ts +0 -150
- package/dist/regenerate/testing.js +0 -438
- package/dist/regenerate/transcript-view.d.ts +0 -21
- package/dist/regenerate/unit-gate.d.ts +0 -27
- package/dist/regenerate/unit-gate.js +0 -20
- package/dist/regenerate/unit-review.d.ts +0 -152
- package/dist/regenerate/unit-review.js +0 -361
- package/dist/regenerate/web.d.ts +0 -61
- package/dist/regenerate/web.js +0 -256
- package/dist/regenerate/workspace.d.ts +0 -12
- package/dist/regenerate/workspace.js +0 -99
- package/dist/regenerate-cli.d.ts +0 -1
- package/dist/resume-line.d.ts +0 -2
- package/dist/review/live.d.ts +0 -72
- package/dist/review/live.js +0 -166
- package/dist/rules.d.ts +0 -20
- package/dist/rules.js +0 -47
- package/dist/run-report.d.ts +0 -88
- package/dist/run-report.js +0 -338
- package/dist/screen-padding.d.ts +0 -28
- package/dist/self-invocation.d.ts +0 -36
- package/dist/self-invocation.js +0 -137
- package/dist/sentinel-chat.d.ts +0 -19
- package/dist/sentinel-chat.js +0 -221
- package/dist/sentinel-check.d.ts +0 -36
- package/dist/sentinel-check.js +0 -78
- package/dist/sentinel.d.ts +0 -107
- package/dist/sentinel.js +0 -599
- package/dist/settings.d.ts +0 -45
- package/dist/settings.js +0 -378
- package/dist/setup.d.ts +0 -97
- package/dist/setup.js +0 -428
- package/dist/skill-progress.d.ts +0 -46
- package/dist/skill.d.ts +0 -102
- package/dist/skill.js +0 -147
- package/dist/skills.d.ts +0 -54
- package/dist/skills.js +0 -111
- package/dist/spawn-async.d.ts +0 -18
- package/dist/spawn-async.js +0 -35
- package/dist/stack.d.ts +0 -80
- package/dist/stack.js +0 -206
- package/dist/stdlib.d.ts +0 -43
- package/dist/stdlib.js +0 -118
- package/dist/surface.d.ts +0 -5
- package/dist/surface.js +0 -18
- package/dist/terminal-images.d.ts +0 -2
- package/dist/test-plain-files.d.ts +0 -41
- package/dist/test-plain-files.js +0 -172
- package/dist/tools.d.ts +0 -101
- package/dist/tools.js +0 -242
- package/dist/turri-versions.d.ts +0 -71
- package/genome/rules/bullet-continuation.md +0 -61
- package/genome/rules/concise-specs-examples.md +0 -460
- package/genome/rules/concise-specs-integration-examples.md +0 -281
- package/genome/rules/concise-specs.md +0 -80
- package/genome/rules/definitions.md +0 -107
- package/genome/rules/examples/integration-embedded-testing/run_conformance_tests_java.sh +0 -161
- package/genome/rules/examples/integration-embedded-testing/run_unittests_java.sh +0 -50
- package/genome/rules/exported-concepts.md +0 -39
- package/genome/rules/func-specs.md +0 -164
- package/genome/rules/impl-reqs.md +0 -68
- package/genome/rules/import-modules.md +0 -49
- package/genome/rules/integration-embedded-testing.md +0 -273
- package/genome/rules/integration-embedded.md +0 -171
- package/genome/rules/integration-standalone.md +0 -135
- package/genome/rules/integrations.md +0 -136
- package/genome/rules/linked-resources.md +0 -76
- package/genome/rules/module-structure.md +0 -112
- package/genome/rules/project-model.md +0 -69
- package/genome/rules/required-concepts.md +0 -44
- package/genome/rules/requires-modules.md +0 -81
- package/genome/rules/semantic-ids.md +0 -49
- package/genome/rules/stdlib.md +0 -37
- package/genome/rules/test-plain-files.md +0 -138
- package/genome/rules/test-reqs.md +0 -57
- package/genome/rules/turri-regeneration.md +0 -66
- package/genome/skills/analyze-2-func-specs/SKILL.md +0 -116
- package/genome/skills/analyze-func-specs/SKILL.md +0 -137
- package/genome/skills/break-down-func-spec/SKILL.md +0 -229
- package/genome/skills/consolidate-concepts/SKILL.md +0 -192
- package/genome/skills/convert-old-syntax/SKILL.md +0 -68
- package/genome/skills/convert-old-syntax/references/rubric.md +0 -11
- package/genome/skills/debug-specs/SKILL.md +0 -194
- package/genome/skills/implement-conformance-testing-script/SKILL.md +0 -247
- package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_cypress.ps1 +0 -337
- package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_golang.ps1 +0 -111
- package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +0 -151
- package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.ps1 +0 -103
- package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +0 -146
- package/genome/skills/implement-unit-testing-script/SKILL.md +0 -171
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_flutter.ps1 +0 -87
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_golang.ps1 +0 -73
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +0 -82
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.ps1 +0 -81
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +0 -102
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_react.ps1 +0 -87
- package/genome/skills/refactor-module/SKILL.md +0 -218
- package/genome/skills/resolve-section-ownership/SKILL.md +0 -64
- package/genome/skills/resolve-spec-conflict/SKILL.md +0 -102
- package/stdlib/backend/common.plain +0 -25
- package/stdlib/backend/conformance/common.plain +0 -12
- package/stdlib/backend/conformance/go-gin.plain +0 -9
- package/stdlib/backend/conformance/go-nethttp.plain +0 -9
- package/stdlib/backend/conformance/java-springboot.plain +0 -9
- package/stdlib/backend/conformance/python-django.plain +0 -9
- package/stdlib/backend/conformance/python-fastapi.plain +0 -9
- package/stdlib/backend/conformance/python-flask.plain +0 -9
- package/stdlib/backend/conformance/rust-axum.plain +0 -9
- package/stdlib/backend/conformance/typescript-express.plain +0 -9
- package/stdlib/backend/conformance/typescript-fastify.plain +0 -9
- package/stdlib/backend/conformance/typescript-nestjs.plain +0 -9
- package/stdlib/backend/go-gin.plain +0 -18
- package/stdlib/backend/go-nethttp.plain +0 -18
- package/stdlib/backend/java-springboot.plain +0 -19
- package/stdlib/backend/python-django.plain +0 -19
- package/stdlib/backend/python-fastapi.plain +0 -23
- package/stdlib/backend/python-flask.plain +0 -23
- package/stdlib/backend/rust-axum.plain +0 -17
- package/stdlib/backend/typescript-express.plain +0 -19
- package/stdlib/backend/typescript-fastify.plain +0 -19
- package/stdlib/backend/typescript-nestjs.plain +0 -19
- package/stdlib/cli/common.plain +0 -17
- package/stdlib/cli/conformance/common.plain +0 -11
- package/stdlib/cli/conformance/go-cobra.plain +0 -9
- package/stdlib/cli/conformance/go-flag.plain +0 -9
- package/stdlib/cli/conformance/java-picocli.plain +0 -9
- package/stdlib/cli/conformance/python-argparse.plain +0 -9
- package/stdlib/cli/conformance/python-click.plain +0 -9
- package/stdlib/cli/conformance/python-typer.plain +0 -9
- package/stdlib/cli/conformance/rust-clap.plain +0 -9
- package/stdlib/cli/conformance/typescript-commander.plain +0 -9
- package/stdlib/cli/go-cobra.plain +0 -14
- package/stdlib/cli/go-flag.plain +0 -14
- package/stdlib/cli/java-picocli.plain +0 -15
- package/stdlib/cli/python-argparse.plain +0 -18
- package/stdlib/cli/python-click.plain +0 -16
- package/stdlib/cli/python-typer.plain +0 -16
- package/stdlib/cli/rust-clap.plain +0 -14
- package/stdlib/cli/typescript-commander.plain +0 -17
- package/stdlib/frontend/angular.plain +0 -17
- package/stdlib/frontend/common.plain +0 -17
- package/stdlib/frontend/conformance/angular.plain +0 -5
- package/stdlib/frontend/conformance/common.plain +0 -11
- package/stdlib/frontend/conformance/react-vite.plain +0 -5
- package/stdlib/frontend/conformance/sveltekit-spa.plain +0 -5
- package/stdlib/frontend/conformance/vue-vite.plain +0 -5
- package/stdlib/frontend/react-vite.plain +0 -16
- package/stdlib/frontend/sveltekit-spa.plain +0 -16
- package/stdlib/frontend/vue-vite.plain +0 -16
- package/stdlib/lang/go.plain +0 -13
- package/stdlib/lang/java.plain +0 -12
- package/stdlib/lang/python.plain +0 -18
- package/stdlib/lang/rust.plain +0 -12
- package/stdlib/lang/typescript.plain +0 -13
- package/stdlib/library/common.plain +0 -15
- package/stdlib/library/conformance/common.plain +0 -9
- package/stdlib/library/conformance/go.plain +0 -9
- package/stdlib/library/conformance/java-gradle.plain +0 -9
- package/stdlib/library/conformance/java-maven.plain +0 -9
- package/stdlib/library/conformance/python.plain +0 -9
- package/stdlib/library/conformance/rust.plain +0 -9
- package/stdlib/library/conformance/typescript.plain +0 -9
- package/stdlib/library/go.plain +0 -12
- package/stdlib/library/java-gradle.plain +0 -13
- package/stdlib/library/java-maven.plain +0 -13
- package/stdlib/library/python.plain +0 -13
- package/stdlib/library/rust.plain +0 -12
- package/stdlib/library/typescript.plain +0 -15
package/dist/regenerate/loop.js
DELETED
|
@@ -1,2079 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, join, posix, relative, resolve } from "node:path";
|
|
3
|
-
import { plainFileParser, withParseCache } from "../plain/parser.js";
|
|
4
|
-
import { STDLIB_ROOT } from "../plain/stdlib.js";
|
|
5
|
-
import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS, TEST_PLAIN_FILES, TEST_REQUIREMENTS } from "../plain/spec.js";
|
|
6
|
-
import { testPlainFilesOf } from "../test-plain-files.js";
|
|
7
|
-
import { reportActivity, reportStage } from "./activity.js";
|
|
8
|
-
import { llmChunkAgents, MAX_LINES_PER_JOB, MAX_SPECS_PER_JOB, planChunks, stepsOf } from "./chunk-plan.js";
|
|
9
|
-
import { commitNotes, landWork, lastCommit, recordHistory, resetToLastCommit } from "./lineage.js";
|
|
10
|
-
import { firstLine, record } from "./ledger.js";
|
|
11
|
-
import { NOTES_FILE, recordPulse } from "./notes.js";
|
|
12
|
-
import { formatDuration } from "./jobs.js";
|
|
13
|
-
import { moduleLanes } from "./lanes.js";
|
|
14
|
-
import { adoptDigests, chainTree, codeTree, conformanceTarget, CONFORM_AGAIN, marksTestsAgain, REGENERATE_AGAIN, inheritedRecord, isOldRecord, notBuilt, readRecord, RECORD_FILE, withResourceDigests, writeCodeRecord, writeTestsRecord, hasScenarios, identityOf, testedFuncIds, } from "./records.js";
|
|
15
|
-
import { describeSpecDiffConformance, renderSpecDiffConformance } from "./conform.js";
|
|
16
|
-
import { conformanceDirFor } from "./conformance.js";
|
|
17
|
-
import { modulesRoot, projectRootOf } from "./paths.js";
|
|
18
|
-
import { configForSpec, configModuleFor, moduleConfigFile, moduleConfigsOf, testDirOf, withConfigModule } from "../config.js";
|
|
19
|
-
import { describeSpecChange } from "./prompt.js";
|
|
20
|
-
import { resolveTemplateDirs } from "./paths.js";
|
|
21
|
-
import { builtTips, copyRequiredCode, copyRequiredTests, importingModules, isImportModule, newlyRequired, resolveRequiresChain, startFromScratch } from "./requires.js";
|
|
22
|
-
import { describeSpecDiff, renderSpecDiff, specFilesOf } from "./regenerate.js";
|
|
23
|
-
import { locateDiffLines } from "./diff-view.js";
|
|
24
|
-
import { agentChanges, changeDiffInFiles } from "./change-view.js";
|
|
25
|
-
import { createSteering, MAX_STEERS, markTold, steer, waitingSteer } from "./steering.js";
|
|
26
|
-
import { isWithin, projectDirOf, slashed } from "./paths.js";
|
|
27
|
-
import { changesBetween, parseTree, serializeTree } from "./spec-steps.js";
|
|
28
|
-
import { hasFiles } from "./testing.js";
|
|
29
|
-
import { makeRenames, pureRenames, renameText } from "./renames.js";
|
|
30
|
-
import { casesOf, codeWork, stillWanted, whyNotWanted } from "./drift.js";
|
|
31
|
-
import { stepsToScenarios, testingGap } from "./testing-steps.js";
|
|
32
|
-
import { baseFolderDrift, baseOfCodebase, seedFromBaseFolder } from "./base-folder.js";
|
|
33
|
-
import { BASE_RECORD_FILE } from "./paths.js";
|
|
34
|
-
import { onScriptRunEnded, scriptBeingWritten } from "./scripts-being-written.js";
|
|
35
|
-
import { conformanceTestsOn } from "../conformance-switch.js";
|
|
36
|
-
import { findTestScripts, projectRootFor } from "./test-scripts.js";
|
|
37
|
-
/** What is left to regenerate, as the conversation and the command line read it. */
|
|
38
|
-
export function describeDrift(reports) {
|
|
39
|
-
if (reports.length === 0)
|
|
40
|
-
return "Nothing to look at: no module of that spec.";
|
|
41
|
-
const cases = (work) => casesText(work);
|
|
42
|
-
// Fully regenerated: in every codebase the code - and its conformance tests, where there are any - regenerated from
|
|
43
|
-
// the spec as it is, nothing regenerating or waiting, and nothing holding the codebase back. A pulse that did not
|
|
44
|
-
// land leaves its work undone, so it shows as drift.
|
|
45
|
-
// conformance: null is no drift, undefined none written here - either is regenerated; a case list is work left.
|
|
46
|
-
const regenerated = reports.every((report) => report.code === null && (report.conformance === null || report.conformance === undefined) && (report.renames ?? []).length === 0);
|
|
47
|
-
const settled = reports.every((report) => report.running === undefined && report.why === undefined && report.startOver === undefined);
|
|
48
|
-
const verdict = regenerated && settled ? "\nFully regenerated: every codebase is regenerated from the spec as it is, and nothing is regenerating." : "";
|
|
49
|
-
return reports
|
|
50
|
-
.map((report) => {
|
|
51
|
-
const lines = [`${report.module} (${basename(report.plainFile)}):`];
|
|
52
|
-
if (report.code === null)
|
|
53
|
-
lines.push(" code: regenerated from the spec as it is - no drift");
|
|
54
|
-
else if (report.code !== undefined)
|
|
55
|
-
lines.push(` code: drifted from the spec - to regenerate: ${cases(report.code)}`);
|
|
56
|
-
if (report.conformance === null)
|
|
57
|
-
lines.push(" conformance tests: written for what is built - no drift");
|
|
58
|
-
else if (report.conformance !== undefined) {
|
|
59
|
-
lines.push(report.conformanceOnly !== undefined
|
|
60
|
-
? ` conformance tests: to write or change - conform asked for ${report.conformanceOnly.join(", ")} alone: the others wait for conform with no names, or the module asked for again`
|
|
61
|
-
: " conformance tests: to write or change - written once the code is built, or now with conform", ...conformanceLines(report.module, report.conformance));
|
|
62
|
-
}
|
|
63
|
-
else
|
|
64
|
-
lines.push(report.conformanceOff === true ? " conformance tests: off (conformance-tests: false) - none written or run" : " conformance tests: none written here");
|
|
65
|
-
for (const rename of report.renames ?? [])
|
|
66
|
-
lines.push(` renames ${rename} - the records and the tests' labels only, nothing regenerated`);
|
|
67
|
-
if (report.baseFolder !== undefined)
|
|
68
|
-
lines.push(` ${report.baseFolder}`);
|
|
69
|
-
if (report.running !== undefined)
|
|
70
|
-
lines.push(` regenerating now: pulse ${report.running.jobId} - ${report.running.title}`);
|
|
71
|
-
if (report.why !== undefined)
|
|
72
|
-
lines.push(` ${report.why}`);
|
|
73
|
-
if (report.startOver !== undefined) {
|
|
74
|
-
lines.push(report.startOver.old === true
|
|
75
|
-
? ` it has to be regenerated from scratch, with its whole chain, before anything more is regenerated there: ${OLD_RECORDS_WHY(report.startOver.codebases)}`
|
|
76
|
-
: ` it has to be regenerated from scratch on ${report.startOver.requires.join(", ")} before anything more is regenerated there`);
|
|
77
|
-
}
|
|
78
|
-
return lines.join("\n");
|
|
79
|
-
})
|
|
80
|
-
.join("\n") + verdict;
|
|
81
|
-
}
|
|
82
|
-
const tipOf = (chain) => chain.at(-1);
|
|
83
|
-
/** When a file was last written, as a key - none when it is not there. */
|
|
84
|
-
const modifiedAt = (path) => {
|
|
85
|
-
try {
|
|
86
|
-
return String(statSync(path).mtimeMs);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return "-";
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
/** Whether a module's codebase has been started: code in it, or a record. */
|
|
93
|
-
const started = (entry) => readRecord(entry.buildDir) !== null || hasFiles(entry.buildDir);
|
|
94
|
-
/** The spec a codebase is built from, as the .plain files have it now: its whole requires chain's. */
|
|
95
|
-
export function chainSpec(chain) {
|
|
96
|
-
// Each module's linked resources hashed where its links point: what a file holds is part of the spec.
|
|
97
|
-
const trees = chain.map((entry) => {
|
|
98
|
-
const dirs = resolveTemplateDirs(entry.plainFile);
|
|
99
|
-
// Its test plain files bound to it: each functional spec with its scenarios, and every one of them with a test plain file.
|
|
100
|
-
return { module: entry.moduleName, tree: withResourceDigests(plainFileParser(basename(entry.plainFile), dirs, { allowNoFunctionalities: true, testDir: testDirOf(entry.plainFile) })[1], dirs) };
|
|
101
|
-
});
|
|
102
|
-
const tip = tipOf(chain);
|
|
103
|
-
return { moduleName: tip.moduleName, plainFile: tip.plainFile, tree: chainTree(trees), chain };
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* The chains a request for `plainFile` brings up: where its module's code lives - every built tip whose
|
|
107
|
-
* chain holds it, one per branch - or, with none, its own chain. Each from its furthest-built module on:
|
|
108
|
-
* the codebases below that are left as they are.
|
|
109
|
-
*/
|
|
110
|
-
function chainsFor(plainFile) {
|
|
111
|
-
const tips = builtTips(plainFile);
|
|
112
|
-
return tips.length > 0 ? tips : [resolveRequiresChain(plainFile, [], undefined, { allowNoFunctionalities: true })];
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The modules a .plain file is built as: itself - or, an import module, the modules importing it whose code is started.
|
|
116
|
-
* An import module is no codebase; one no started module imports has nothing to build yet - its reqs are built with the
|
|
117
|
-
* first module that imports it.
|
|
118
|
-
*/
|
|
119
|
-
function codebasesOf(plainFile) {
|
|
120
|
-
if (!isImportModule(plainFile))
|
|
121
|
-
return [plainFile];
|
|
122
|
-
return importingModules(plainFile).filter((file) => {
|
|
123
|
-
try {
|
|
124
|
-
return builtTips(file).length > 0 || started(resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true }).at(-1));
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
/** How many functional specs of its own a codebase has built - none when it was only started from the code below it. */
|
|
132
|
-
function ownBuilt(entry) {
|
|
133
|
-
return (readRecord(entry.buildDir)?.[FUNCTIONAL_REQUIREMENTS] ?? []).length;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* The functional specs of a spec's whole requires chain, completed or not, in the codebase each chain delivers: its
|
|
137
|
-
* furthest-built module's code - which holds the code of every module below it. A functional spec is completed when that
|
|
138
|
-
* codebase's code record, as last committed, holds it as the spec has it now - the same text, the linked files it uses
|
|
139
|
-
* holding the same, no definition it uses changed, not marked to regenerate again. A record moves only when a pulse
|
|
140
|
-
* lands, its unit tests passing (and its conformance tests, when they are on), so completed is landed and passing.
|
|
141
|
-
* The modules above the delivered codebase have nothing completed. One entry per chain; planning nothing, calling no model.
|
|
142
|
-
*/
|
|
143
|
-
export function functionalityCompletion(plainFile) {
|
|
144
|
-
return withParseCache(() => chainsFor(resolve(plainFile)).map((chain) => codebaseCompletion(chain)));
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* The functional specs of a chain, completed or not, in the codebase it delivers: its furthest-built module's - see
|
|
148
|
-
* `functionalityCompletion`. A module's own chain (`resolveRequiresChain`) gives what its own codebase holds.
|
|
149
|
-
*/
|
|
150
|
-
export function codebaseCompletion(chain) {
|
|
151
|
-
return withParseCache(() => {
|
|
152
|
-
let delivered = -1;
|
|
153
|
-
chain.forEach((entry, index) => {
|
|
154
|
-
if (readRecord(entry.buildDir) !== null)
|
|
155
|
-
delivered = index;
|
|
156
|
-
});
|
|
157
|
-
// Of each module's functional specs, those with scenarios: what "tested of specified" counts over.
|
|
158
|
-
let whole;
|
|
159
|
-
try {
|
|
160
|
-
whole = chainSpec(chain).tree;
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
whole = undefined;
|
|
164
|
-
}
|
|
165
|
-
const ownItems = (tree, module, own) => (tree?.[own ? FUNCTIONAL_REQUIREMENTS : REQUIRED_FUNCTIONAL_SPECS] ?? []).filter((item) => own || item.module === module);
|
|
166
|
-
const counts = chain.map((entry, index) => ({
|
|
167
|
-
module: entry.moduleName,
|
|
168
|
-
specified: entry.funcIds.length,
|
|
169
|
-
withScenarios: ownItems(whole, entry.moduleName, index === chain.length - 1).filter(hasScenarios).length,
|
|
170
|
-
completed: 0,
|
|
171
|
-
conformanceTested: 0,
|
|
172
|
-
tested: [],
|
|
173
|
-
incomplete: [...entry.funcIds],
|
|
174
|
-
}));
|
|
175
|
-
if (delivered === -1)
|
|
176
|
-
return { codebase: tipOf(chain).buildDir, modules: counts };
|
|
177
|
-
const codebase = chain.slice(0, delivered + 1);
|
|
178
|
-
const tip = tipOf(codebase);
|
|
179
|
-
const spec = chainSpec(codebase).tree;
|
|
180
|
-
const record = readRecord(tip.buildDir);
|
|
181
|
-
const changes = codeWork(record, spec);
|
|
182
|
-
// Its own: what the work loop would regenerate - new, changed, a concept it uses changed, or marked again.
|
|
183
|
-
const cases = casesOf(codeTree(record ?? {}), changes, { module: tip.moduleName });
|
|
184
|
-
const touched = new Set([...cases.add, ...cases.patch, ...cases.again].map((spec) => `${spec.module ?? tip.moduleName}:${spec.funcId}`));
|
|
185
|
-
// The modules' below it: an item the record does not have as the spec has it.
|
|
186
|
-
for (const change of changes) {
|
|
187
|
-
if (change.section !== REQUIRED_FUNCTIONAL_SPECS || change.after === undefined)
|
|
188
|
-
continue;
|
|
189
|
-
try {
|
|
190
|
-
const item = JSON.parse(change.after);
|
|
191
|
-
if (item.module !== undefined && item.id !== undefined)
|
|
192
|
-
touched.add(`${item.module}:${item.id}`);
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
/* not an item */
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// A functional spec as the tests are written for it: its text and its scenarios.
|
|
199
|
-
const reads = (item) => {
|
|
200
|
-
if (item === undefined)
|
|
201
|
-
return undefined;
|
|
202
|
-
const scenarios = (key) => (item[key] ?? []).map((scenario) => [scenario.id, scenario.text]);
|
|
203
|
-
return JSON.stringify([String(item.markdown ?? "").trim(), scenarios(CONFORMANCE_TESTS), scenarios(ACCEPTANCE_TESTS)]);
|
|
204
|
-
};
|
|
205
|
-
const specText = (module, funcId) => reads(ownItems(spec, module, module === tip.moduleName).find((item) => item.id === funcId));
|
|
206
|
-
// What the conformance tests are written for, in the same codebase: its suite holds the chain's.
|
|
207
|
-
const testsRecord = readRecord(conformanceDirFor(tip.moduleName, modulesRoot(projectDirOf(tip.plainFile))));
|
|
208
|
-
codebase.forEach((entry, index) => {
|
|
209
|
-
const count = counts[index];
|
|
210
|
-
const completed = entry.funcIds.filter((funcId) => !touched.has(`${entry.moduleName}:${funcId}`));
|
|
211
|
-
// Tests marked to regenerate again were written against code since replaced, and those marked to be written again
|
|
212
|
-
// are to be written anew: not conformance tested until rewritten.
|
|
213
|
-
const tested = ownItems(testsRecord ?? undefined, entry.moduleName, entry.moduleName === tip.moduleName).filter((item) => item.id !== undefined && !marksTestsAgain(item) && reads(item) === specText(entry.moduleName, item.id));
|
|
214
|
-
count.completed = completed.length;
|
|
215
|
-
count.tested = completed.filter((funcId) => tested.some((item) => item.id === funcId));
|
|
216
|
-
count.conformanceTested = count.tested.length;
|
|
217
|
-
count.incomplete = entry.funcIds.filter((funcId) => !completed.includes(funcId));
|
|
218
|
-
});
|
|
219
|
-
return { codebase: tip.buildDir, modules: counts };
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
/** The modules of a chain to build: its furthest-built one, and those above it - or, none built, all of it. */
|
|
223
|
-
function toBuild(chain) {
|
|
224
|
-
let from = 0;
|
|
225
|
-
chain.forEach((entry, index) => {
|
|
226
|
-
if (started(entry))
|
|
227
|
-
from = index;
|
|
228
|
-
});
|
|
229
|
-
return chain.slice(from);
|
|
230
|
-
}
|
|
231
|
-
export function createWorkLoop(options) {
|
|
232
|
-
const modules = new Map();
|
|
233
|
-
const order = [];
|
|
234
|
-
const run = options.run ?? defaultRunner;
|
|
235
|
-
const runConformance = options.runConformance ?? defaultConformanceRunner;
|
|
236
|
-
// One tick at a time: each reads the records and the spec, and decides.
|
|
237
|
-
let ticking = Promise.resolve();
|
|
238
|
-
const tipEntry = (state) => tipOf(state.chain);
|
|
239
|
-
/** Where what the loop decides for a module is recorded: its tip's project, the module and the pulse it is about. */
|
|
240
|
-
const loopPlace = (state, job) => {
|
|
241
|
-
const tip = tipEntry(state);
|
|
242
|
-
return { project: projectRootOf(tip.buildDir), module: tip.moduleName, job };
|
|
243
|
-
};
|
|
244
|
-
/** `work` with the codebase's config pinned - its module's own file, or one it requires - once it is worked out. */
|
|
245
|
-
const withModuleConfig = (state, work) => (state.configModule !== undefined ? withConfigModule(state.configModule.name, work) : work());
|
|
246
|
-
const keyOf = (spec) => serializeTree(codeTree(spec.tree));
|
|
247
|
-
/** What a codebase is built from: its record, or - nothing built - what it starts from, the code of the module it requires. */
|
|
248
|
-
const builtOf = (state) => {
|
|
249
|
-
const tip = tipEntry(state);
|
|
250
|
-
const record = readRecord(tip.buildDir);
|
|
251
|
-
if (record !== null)
|
|
252
|
-
return codeTree(record);
|
|
253
|
-
const below = state.chain.find((entry) => entry.moduleName === tip.requires);
|
|
254
|
-
const source = below === undefined ? null : readRecord(below.buildDir);
|
|
255
|
-
return source === null ? {} : codeTree(inheritedRecord(source, below.moduleName));
|
|
256
|
-
};
|
|
257
|
-
/** Where a codebase's conformance tests are: the module's tests folder. */
|
|
258
|
-
const testsDirOf = (state) => {
|
|
259
|
-
const tip = tipEntry(state);
|
|
260
|
-
return conformanceDirFor(tip.moduleName, modulesRoot(projectDirOf(tip.plainFile)));
|
|
261
|
-
};
|
|
262
|
-
/** What the conformance tests are written for, by their record - nothing, when there is none. */
|
|
263
|
-
const testedOf = (state) => readRecord(testsDirOf(state)) ?? {};
|
|
264
|
-
/** What the code is built from, as a key: a conformance plan made against other code is made again. */
|
|
265
|
-
const codeKeyOf = (state) => serializeTree(readRecord(tipEntry(state).buildDir) ?? {});
|
|
266
|
-
/**
|
|
267
|
-
* What the conformance tests are to be written for now: of what the code is built from, the functional specs with
|
|
268
|
-
* scenarios, with the test reqs as the spec has them. `from`: the tests the work starts from - what a running pulse will land, when the work
|
|
269
|
-
* after it is planned ahead - else the tests record as it is. Read from the record alone, a pulse still writing a
|
|
270
|
-
* functional spec's tests would not count them: one whose code is behind the spec would be planned out, its tests
|
|
271
|
-
* taken out again once they landed.
|
|
272
|
-
*/
|
|
273
|
-
const conformanceOf = (state, spec, from, narrowed = true) => {
|
|
274
|
-
const tests = from ?? readRecord(testsDirOf(state));
|
|
275
|
-
const whole = conformanceTarget(readRecord(tipEntry(state).buildDir), tests, spec.tree);
|
|
276
|
-
const target = narrowed ? onlyNamed(state, whole, tests, spec.tree) : whole;
|
|
277
|
-
// No functional spec to test, and none tested: nothing to write - the reqs alone are no conformance job.
|
|
278
|
-
const specsIn = (tree) => (tree?.[FUNCTIONAL_REQUIREMENTS] ?? []).length + (tree?.[REQUIRED_FUNCTIONAL_SPECS] ?? []).length;
|
|
279
|
-
return specsIn(target) === 0 && specsIn(tests) === 0 ? (tests ?? {}) : target;
|
|
280
|
-
};
|
|
281
|
-
/**
|
|
282
|
-
* Whether a codebase's conformance tests are written: with test reqs to write them by, and code to test. What they are
|
|
283
|
-
* written for is the functional specs with scenarios (conformanceOf): a scenario added, changed or taken out, the
|
|
284
|
-
* functional spec's text changed, regenerated again or taken out - the tests of each are behind, and are written.
|
|
285
|
-
*/
|
|
286
|
-
const conformanceWanted = (state, spec) => conformanceTestsOn(tipEntry(state).plainFile) &&
|
|
287
|
-
(spec.tree[TEST_REQUIREMENTS] ?? []).length > 0 && readRecord(tipEntry(state).buildDir) !== null && gapOf(state, spec) === undefined;
|
|
288
|
-
/**
|
|
289
|
-
* The step of adding tests a codebase skipped - its functional specs have scenarios, and it has no test reqs or no
|
|
290
|
-
* conformance testing script: no conformance pulse of it starts, in the loop or from conform, and it
|
|
291
|
-
* waits on that step until the spec or the scripts change.
|
|
292
|
-
*/
|
|
293
|
-
const gapOf = (state, spec) => {
|
|
294
|
-
const tip = tipEntry(state);
|
|
295
|
-
return testingGap({ moduleName: tip.moduleName, plainFile: tip.plainFile, tree: spec.tree, buildDir: tip.buildDir });
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Whether a testing script of this kind is being written for a codebase now - one it lacks, or one written over: it waits
|
|
299
|
-
* for it, rather than fail for want of it or run against the old one, and is looked at again once the run ends.
|
|
300
|
-
*/
|
|
301
|
-
const awaitsScript = (state, kind) => {
|
|
302
|
-
const tip = tipEntry(state);
|
|
303
|
-
const root = projectRootFor(tip.plainFile, tip.buildDir);
|
|
304
|
-
// Lacking the script, or with one being written over: a pulse started now would run without it, or against the old one.
|
|
305
|
-
return scriptBeingWritten(root, kind, configModuleFor(tip.plainFile));
|
|
306
|
-
};
|
|
307
|
-
/**
|
|
308
|
-
* Why a codebase waits for a unit testing script of its own, or undefined: the project's modules name their scripts in
|
|
309
|
-
* config files of their own - each its own stack's - and none applies to it, nor names a script it could run. Its
|
|
310
|
-
* script is still to come: a pulse started now would stop for want of one. Looked at again when a script run ends, or
|
|
311
|
-
* the module is asked for again.
|
|
312
|
-
*/
|
|
313
|
-
const lacksOwnScript = (state) => {
|
|
314
|
-
const tip = tipEntry(state);
|
|
315
|
-
const root = projectRootFor(tip.plainFile, tip.buildDir);
|
|
316
|
-
if (configModuleFor(tip.plainFile) !== undefined || moduleConfigsOf(root).length === 0)
|
|
317
|
-
return undefined;
|
|
318
|
-
const found = withModuleConfig(state, () => findTestScripts(root, tip.plainFile, tip.buildDir));
|
|
319
|
-
return found.unit !== undefined ? undefined : `${NO_OWN_SCRIPT}${found.notes?.unit !== undefined ? ` ${found.notes.unit}` : ""}`;
|
|
320
|
-
};
|
|
321
|
-
/**
|
|
322
|
-
* The base folder a codebase started from, as its status says it. Counting the files still there looks at each, and the
|
|
323
|
-
* status is read often: so it is read again only when the base record or the code record moved - a pulse landed.
|
|
324
|
-
*/
|
|
325
|
-
const baseOfState = (state) => {
|
|
326
|
-
const dir = tipEntry(state).buildDir;
|
|
327
|
-
const at = [BASE_RECORD_FILE, RECORD_FILE].map((name) => modifiedAt(join(dir, name))).join(":");
|
|
328
|
-
if (state.base?.at !== at) {
|
|
329
|
-
const started = baseOfCodebase(dir);
|
|
330
|
-
state.base = { at, base: started !== undefined ? { folder: started.folder, files: started.files.length } : undefined };
|
|
331
|
-
}
|
|
332
|
-
return state.base.base;
|
|
333
|
-
};
|
|
334
|
-
/**
|
|
335
|
-
* What the conformance tests are to be written for, as conform narrowed it to the functional specs it named: every other
|
|
336
|
-
* functional spec as the tests are written for it now - its tests neither written, changed nor taken out. One whose text
|
|
337
|
-
* or scenarios changed since joins those named: a change to it is work again.
|
|
338
|
-
*/
|
|
339
|
-
const onlyNamed = (state, target, tests, tree) => {
|
|
340
|
-
const only = state.conformanceOnly;
|
|
341
|
-
if (only === undefined)
|
|
342
|
-
return target;
|
|
343
|
-
for (const section of [FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS]) {
|
|
344
|
-
for (const item of tree[section] ?? []) {
|
|
345
|
-
const key = identityOf(item);
|
|
346
|
-
if (!only.specs.has(key) && only.read.get(key) !== JSON.stringify(item))
|
|
347
|
-
only.specs.add(key);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
const narrowed = { ...target };
|
|
351
|
-
for (const section of [FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS]) {
|
|
352
|
-
const tested = new Map(((tests?.[section] ?? [])).map((item) => [identityOf(item), item]));
|
|
353
|
-
const wanted = (target[section] ?? []).flatMap((item) => {
|
|
354
|
-
if (only.specs.has(identityOf(item)))
|
|
355
|
-
return [item];
|
|
356
|
-
// Not named: as its tests are written for it now, or - none written - not at all.
|
|
357
|
-
const kept = tested.get(identityOf(item));
|
|
358
|
-
return kept !== undefined ? [kept] : [];
|
|
359
|
-
});
|
|
360
|
-
// Taken out of the target and not named: its tests are kept, as they are.
|
|
361
|
-
const inTarget = new Set(wanted.map(identityOf));
|
|
362
|
-
for (const [key, item] of tested)
|
|
363
|
-
if (!only.specs.has(key) && !inTarget.has(key))
|
|
364
|
-
wanted.push(item);
|
|
365
|
-
if (wanted.length > 0)
|
|
366
|
-
narrowed[section] = wanted;
|
|
367
|
-
else
|
|
368
|
-
delete narrowed[section];
|
|
369
|
-
}
|
|
370
|
-
return narrowed;
|
|
371
|
-
};
|
|
372
|
-
/**
|
|
373
|
-
* The functional specs conform named - func-ids of `module` - and every functional spec as it reads now, to tell a
|
|
374
|
-
* change to one after. In a codebase built on `module`, they are among the functional specs it requires.
|
|
375
|
-
*/
|
|
376
|
-
const namedOnly = (state, funcIds, module) => {
|
|
377
|
-
const tree = chainSpec(state.chain).tree;
|
|
378
|
-
const read = new Map();
|
|
379
|
-
for (const section of [FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS]) {
|
|
380
|
-
for (const item of tree[section] ?? [])
|
|
381
|
-
read.set(identityOf(item), JSON.stringify(item));
|
|
382
|
-
}
|
|
383
|
-
const own = tipEntry(state).moduleName === module;
|
|
384
|
-
return { specs: new Set(funcIds.map((id) => identityOf(own ? { id } : { id, module }))), read };
|
|
385
|
-
};
|
|
386
|
-
/**
|
|
387
|
-
* Conformance tests written already, to be written again as conform names them - their code untouched: the functional
|
|
388
|
-
* specs named, func-ids of `self`, marked in the tests record of every codebase where its code lives - the tips of its
|
|
389
|
-
* chains, whose suite holds the chain's tests, among the functional specs required there for a module below - each
|
|
390
|
-
* committed. Refused while a pulse runs in one it marks. Says which functional specs were marked.
|
|
391
|
-
*/
|
|
392
|
-
const conformAgain = (file, self, funcIds) => {
|
|
393
|
-
const codebases = [...new Map(chainsFor(file).map(tipOf).map((entry) => [entry.buildDir, entry])).values()];
|
|
394
|
-
// What is marked, worked out before anything is: a codebase that has none of them is not touched, nor refused.
|
|
395
|
-
const touching = codebases.flatMap((entry) => {
|
|
396
|
-
const testsDir = conformanceDirFor(entry.moduleName, modulesRoot(projectDirOf(entry.plainFile)));
|
|
397
|
-
const tests = readRecord(testsDir);
|
|
398
|
-
if (tests === null)
|
|
399
|
-
return [];
|
|
400
|
-
const section = entry.moduleName === self.moduleName ? FUNCTIONAL_REQUIREMENTS : REQUIRED_FUNCTIONAL_SPECS;
|
|
401
|
-
const items = tests[section] ?? [];
|
|
402
|
-
const funcIdOf = (item) => (section === FUNCTIONAL_REQUIREMENTS || item.module === self.moduleName ? (item.id ?? "") : "");
|
|
403
|
-
const taken = items.flatMap((item) => (funcIds.includes(funcIdOf(item)) ? [funcIdOf(item)] : []));
|
|
404
|
-
if (taken.length === 0)
|
|
405
|
-
return [];
|
|
406
|
-
const marked = items.map((item) => (funcIds.includes(funcIdOf(item)) ? { ...item, [CONFORM_AGAIN]: true } : item));
|
|
407
|
-
return [{ entry, testsDir, taken, record: { ...tests, [section]: marked } }];
|
|
408
|
-
});
|
|
409
|
-
for (const { entry } of touching) {
|
|
410
|
-
if (modules.get(entry.buildDir)?.running !== undefined)
|
|
411
|
-
throw new Error(`${entry.moduleName} has a pulse running: halt it, or ask again once it is done. Nothing was started.`);
|
|
412
|
-
}
|
|
413
|
-
const found = new Set();
|
|
414
|
-
for (const { entry, testsDir, taken, record } of touching) {
|
|
415
|
-
writeTestsRecord(testsDir, record);
|
|
416
|
-
recordHistory(entry.buildDir, `the conformance tests of ${namesOf(self.moduleName, taken)} to write again`);
|
|
417
|
-
for (const funcId of taken)
|
|
418
|
-
found.add(funcId);
|
|
419
|
-
const state = modules.get(entry.buildDir);
|
|
420
|
-
if (state === undefined)
|
|
421
|
-
continue;
|
|
422
|
-
state.conformancePlan = undefined;
|
|
423
|
-
state.conformanceHalted = undefined;
|
|
424
|
-
}
|
|
425
|
-
return [...found];
|
|
426
|
-
};
|
|
427
|
-
/**
|
|
428
|
-
* A module's conformance tests from scratch, where its code lives - the tip of each chain it is built in, as
|
|
429
|
-
* `fromScratch` regenerates its code there, never a codebase in the middle - the code untouched: each tip's tests folder
|
|
430
|
-
* taken out whole, committed so its history keeps it; then, `fromBelow`, the tests of the module the tip requires copied
|
|
431
|
-
* in, as the codebase started from them - its own tests written anew on them, those it inherits brought up to date.
|
|
432
|
-
* Without, nothing: every functional spec of the chain is written anew there. Nothing below a tip is touched. Refused
|
|
433
|
-
* while a pulse runs in one. Says which codebases' tests were taken out.
|
|
434
|
-
*/
|
|
435
|
-
const testsFromScratch = (file, fromBelow) => {
|
|
436
|
-
const chains = chainsFor(file);
|
|
437
|
-
const tips = [...new Map(chains.map((chain) => [tipOf(chain).buildDir, chain])).values()].flatMap((chain) => {
|
|
438
|
-
const tip = tipOf(chain);
|
|
439
|
-
const testsDir = conformanceDirFor(tip.moduleName, modulesRoot(projectDirOf(tip.plainFile)));
|
|
440
|
-
// Nothing built and no tests: there is nothing to start again - they are written once the code is.
|
|
441
|
-
return started(tip) || existsSync(testsDir) ? [{ chain, tip, testsDir }] : [];
|
|
442
|
-
});
|
|
443
|
-
for (const { tip } of tips) {
|
|
444
|
-
if (modules.get(tip.buildDir)?.running !== undefined)
|
|
445
|
-
throw new Error(`${tip.moduleName} has a pulse running: halt it, or ask again once it is done. Nothing was started.`);
|
|
446
|
-
}
|
|
447
|
-
for (const { chain, tip, testsDir } of tips) {
|
|
448
|
-
rmSync(testsDir, { recursive: true, force: true });
|
|
449
|
-
const below = fromBelow ? chain.find((entry) => entry.moduleName === tip.requires) : undefined;
|
|
450
|
-
if (below !== undefined)
|
|
451
|
-
copyRequiredTests(below.buildDir, tip.buildDir, below.moduleName);
|
|
452
|
-
const why = below !== undefined ? `asked to be written again from scratch, starting from ${below.moduleName}'s` : "asked to be written again from scratch, with its whole chain's";
|
|
453
|
-
recordHistory(tip.buildDir, `conformance tests from scratch: ${why}`);
|
|
454
|
-
reportActivity(` ${tip.moduleName}: its conformance tests are taken out${below !== undefined ? `, and ${below.moduleName}'s copied in` : ""} - ${why}`);
|
|
455
|
-
const state = modules.get(tip.buildDir);
|
|
456
|
-
if (state === undefined)
|
|
457
|
-
continue;
|
|
458
|
-
state.conformancePlan = undefined;
|
|
459
|
-
state.conformanceHalted = undefined;
|
|
460
|
-
}
|
|
461
|
-
return tips.map(({ tip }) => tip.moduleName);
|
|
462
|
-
};
|
|
463
|
-
/** The work of a track, from where it is built from to what it is to be - for the conformance tests, as conform narrowed them unless `narrowed` is false. */
|
|
464
|
-
const workOf = (track, from, state, spec, narrowed = true) => track === "code" ? codeWork(from, spec.tree) : changesBetween(serializeTree(from), serializeTree(conformanceOf(state, spec, from, narrowed)));
|
|
465
|
-
/** The codebases brought up in this look: one left behind is never waited for. */
|
|
466
|
-
let looking = new Set();
|
|
467
|
-
/**
|
|
468
|
-
* The module below this one that it waits for, and why: one with a job running, code left to build, or conformance
|
|
469
|
-
* tests wanted and not yet written and passing - a codebase starts from the code and the conformance tests below it,
|
|
470
|
-
* so they pass before anything is built on them. Conformance tests below that did not pass hold it until they do.
|
|
471
|
-
*/
|
|
472
|
-
const waitingOn = (state) => {
|
|
473
|
-
for (const entry of state.chain.slice(0, -1)) {
|
|
474
|
-
const below = modules.get(entry.buildDir);
|
|
475
|
-
if (below === undefined || (!looking.has(below) && below.running === undefined))
|
|
476
|
-
continue;
|
|
477
|
-
const waiting = (why) => ({ module: entry.moduleName, why: `waiting for ${entry.moduleName}: ${why}` });
|
|
478
|
-
if (below.running !== undefined)
|
|
479
|
-
return waiting(below.running.planned.track === "conformance" ? "its conformance tests are being written" : "the code it is built on is not built yet");
|
|
480
|
-
if (below.held !== undefined)
|
|
481
|
-
return waiting("you halted it - nothing is built on it until it is asked for again");
|
|
482
|
-
const spec = chainSpec(below.chain);
|
|
483
|
-
if (codeWork(builtOf(below), spec.tree).length > 0)
|
|
484
|
-
return waiting("the code it is built on is not built yet");
|
|
485
|
-
if (below.conformanceHalted !== undefined)
|
|
486
|
-
return waiting(`its conformance tests did not pass - ${below.conformanceHalted.why}`);
|
|
487
|
-
if (conformanceWanted(below, spec) && workOf("conformance", testedOf(below), below, spec).length > 0)
|
|
488
|
-
return waiting("its conformance tests are not written yet");
|
|
489
|
-
}
|
|
490
|
-
return undefined;
|
|
491
|
-
};
|
|
492
|
-
/**
|
|
493
|
-
* Steer the running code job when the spec moved on inside what it regenerates: its target moved to the spec as it
|
|
494
|
-
* now is there, its agent told - now, in its turn, or when the step it is at ends - its view in the panel moved too.
|
|
495
|
-
* Whatever else changed is the next job's. True when it was steered: not a third time, unless into a steer still
|
|
496
|
-
* waiting.
|
|
497
|
-
*/
|
|
498
|
-
const trySteer = (state, spec, own, work) => {
|
|
499
|
-
const running = state.running;
|
|
500
|
-
const steering = running?.steering;
|
|
501
|
-
if (running === undefined || steering === undefined || running.planned.track !== "code")
|
|
502
|
-
return false;
|
|
503
|
-
const waiting = waitingSteer(steering) !== undefined;
|
|
504
|
-
if (steering.steers >= MAX_STEERS && !waiting)
|
|
505
|
-
return false;
|
|
506
|
-
const moved = steer(steering, running.from, own, (tree) => workOf("code", tree, state, spec));
|
|
507
|
-
if (moved === undefined)
|
|
508
|
-
return false;
|
|
509
|
-
// Steered, everything it regenerates is wanted - else something it regenerates was taken out, and that is no steer.
|
|
510
|
-
if (!stillWanted(changesBetween(serializeTree(running.from), serializeTree(moved.target)), work))
|
|
511
|
-
return false;
|
|
512
|
-
const why = whyNotWanted(own, work);
|
|
513
|
-
steering.target = moved.target;
|
|
514
|
-
steering.agent = moved.agent;
|
|
515
|
-
if (!waiting)
|
|
516
|
-
steering.steers += 1;
|
|
517
|
-
steering.notes.push(why);
|
|
518
|
-
running.after = moved.target;
|
|
519
|
-
const text = waitingSteer(steering);
|
|
520
|
-
if (text !== undefined && steering.deliver?.(text) === true)
|
|
521
|
-
markTold(steering);
|
|
522
|
-
const tip = tipEntry(state);
|
|
523
|
-
const job = options.registry.get(running.jobId);
|
|
524
|
-
if (job !== undefined) {
|
|
525
|
-
const shown = changeDiffInFiles(agentChanges(changesBetween(serializeTree(running.from), serializeTree(steering.agent)), "code"), relative(projectDirOf(tip.plainFile), tip.plainFile) || basename(tip.plainFile), (diff) => whereInFiles(diff, state.chain));
|
|
526
|
-
options.registry.setDiff(job.id, shown.diff, shown.where);
|
|
527
|
-
}
|
|
528
|
-
reportActivity(` ⇢ steered pulse ${running.jobId} (${steering.steers} of ${MAX_STEERS}): ${why}`);
|
|
529
|
-
return true;
|
|
530
|
-
};
|
|
531
|
-
const plan = async (state, spec, from, track = "code") => {
|
|
532
|
-
const tip = tipEntry(state);
|
|
533
|
-
const current = track === "code" ? codeTree(spec.tree) : conformanceOf(state, spec, from);
|
|
534
|
-
const specFile = slashed(relative(options.cwd, tip.plainFile));
|
|
535
|
-
let specText = "";
|
|
536
|
-
try {
|
|
537
|
-
specText = readFileSync(tip.plainFile, "utf8");
|
|
538
|
-
}
|
|
539
|
-
catch {
|
|
540
|
-
/* the layout is only for how the diffs read */
|
|
541
|
-
}
|
|
542
|
-
const separately = track === "conformance" && state.conformanceSeparately === true;
|
|
543
|
-
// How big a pulse may be: the module's config, else the defaults.
|
|
544
|
-
const config = configForSpec(tip.plainFile);
|
|
545
|
-
const limits = { specs: config.maxSpecsPerPulse ?? MAX_SPECS_PER_JOB, lines: config.maxLinesPerPulse ?? MAX_LINES_PER_JOB };
|
|
546
|
-
const testPlainPath = track === "conformance" ? testPlainPathOf(spec.tree, tip.moduleName, tip.plainFile, dirname(specFile)) : undefined;
|
|
547
|
-
// A pure rename is turri's to make before the next pulse, not a delete and an add: the work is planned from the code as renamed.
|
|
548
|
-
const renamed = track === "code" ? pureRenames(from, readRecord(testsDirOf(state)), spec.tree, tip.moduleName) : undefined;
|
|
549
|
-
const base = renamed !== undefined && renamed.renames.length > 0 && renamed.code !== null ? codeTree(renamed.code) : from;
|
|
550
|
-
const input = { base, current, specFile, specText, track, moduleName: tip.moduleName, limits, ...(separately ? { separately } : {}), ...(testPlainPath !== undefined ? { testPlainPath } : {}) };
|
|
551
|
-
const model = typeof options.plannerModel === "function" ? options.plannerModel() : options.plannerModel;
|
|
552
|
-
const agents = options.planner === false ? undefined : (options.planner ?? llmChunkAgents({ cwd: options.cwd, model: model ?? state.model, label: `${basename(tip.plainFile)} planner` }));
|
|
553
|
-
reportStage(`${tip.moduleName}: planning the ${track === "code" ? "work" : "conformance tests"} into pulses`);
|
|
554
|
-
const notes = [];
|
|
555
|
-
const draft = await planChunks(input, agents, notes);
|
|
556
|
-
const fresh = tip.requires === null && (track === "code" ? !started(tip) : readRecord(testsDirOf(state)) === null);
|
|
557
|
-
const jobs = stepsOf(input, draft).map((job, index) => {
|
|
558
|
-
// Its cases from its own change: the spec before it to the spec after it - the plan's changes are numbered from where the plan starts.
|
|
559
|
-
const cases = casesOf(parseTree(job.step.before), changesBetween(job.step.before, job.step.after), { fresh: fresh && index === 0, module: tip.moduleName });
|
|
560
|
-
return { title: job.title, reason: job.reason, cases, step: job.step, track };
|
|
561
|
-
});
|
|
562
|
-
return { jobs, notes };
|
|
563
|
-
};
|
|
564
|
-
/** Plan a track: while the planner works, the codebase says so rather than showing nothing - or, a job running, the old plan. */
|
|
565
|
-
const planIdle = async (state, spec, from, track) => {
|
|
566
|
-
state.planning = track;
|
|
567
|
-
state.planningSince = Date.now();
|
|
568
|
-
// Planning takes a while - the planner is an agent: what shows the work says so at once, not when the first pulse starts.
|
|
569
|
-
options.registry.notify?.();
|
|
570
|
-
try {
|
|
571
|
-
return await plan(state, spec, from, track);
|
|
572
|
-
}
|
|
573
|
-
finally {
|
|
574
|
-
state.planning = undefined;
|
|
575
|
-
state.planningSince = undefined;
|
|
576
|
-
options.registry.notify?.();
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
const startJob = (state, spec, from, planned) => {
|
|
580
|
-
// Halted while it was being planned: the plan is made, nothing starts.
|
|
581
|
-
if (state.held !== undefined) {
|
|
582
|
-
state.why = state.held.why;
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
// Looked ahead: the plan is kept, and its first pulse waits for the module to be asked for.
|
|
586
|
-
if (state.lookedAhead === true) {
|
|
587
|
-
state.why = LOOKED_AHEAD;
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
const tip = tipEntry(state);
|
|
591
|
-
const conformance = planned.track === "conformance";
|
|
592
|
-
// A code job can be steered while it regenerates: its target moves with the spec, inside what it regenerates.
|
|
593
|
-
const steering = conformance ? undefined : createSteering(planned.step.tree, tip.moduleName);
|
|
594
|
-
// Shown as its agent is given it: the job's own items, from whichever file they are written in - its imports too, and
|
|
595
|
-
// for the conformance tests the test plain files of the functional specs whose scenarios it carries out.
|
|
596
|
-
const moduleFile = slashed(relative(projectDirOf(tip.plainFile), tip.plainFile)) || basename(tip.plainFile);
|
|
597
|
-
const shown = changeDiffInFiles(agentChanges(planned.step.changes, planned.track), moduleFile, (diff) => whereInFiles(diff, state.chain), conformance ? { module: tip.moduleName, pathOf: testPlainPathOf(spec.tree, tip.moduleName, tip.plainFile, dirname(moduleFile)) } : undefined);
|
|
598
|
-
const job = options.registry.start({
|
|
599
|
-
kind: conformance ? "conformance" : "regenerate",
|
|
600
|
-
summary: `${basename(tip.plainFile)} ${conformance ? "conformance: " : ""}${planned.title}`,
|
|
601
|
-
module: tip.moduleName,
|
|
602
|
-
// Numbered as regen numbers it: the module's pulses this session, from 1.
|
|
603
|
-
pulse: (state.pulses ?? 0) + 1,
|
|
604
|
-
title: planned.title,
|
|
605
|
-
diff: shown.diff,
|
|
606
|
-
// Its lines where they are written: the module's .plain file, those it imports, and those of the modules below it.
|
|
607
|
-
diffWhere: shown.where,
|
|
608
|
-
// The functional specs it covers, by case - its own module's, and those of modules below it.
|
|
609
|
-
cases: pulseCases(planned.cases, tip.moduleName),
|
|
610
|
-
...(state.model !== undefined ? { model: state.model } : {}),
|
|
611
|
-
lanes: [...moduleLanes(tip.plainFile)],
|
|
612
|
-
rerun: `turri regenerate ${relative(options.cwd, tip.plainFile) || basename(tip.plainFile)}`,
|
|
613
|
-
run: async (onDelta) => {
|
|
614
|
-
// The guardrail: a conformance job tests only code that is built - the code record, read as the job starts, has every functional spec it tests as it tests it.
|
|
615
|
-
if (conformance) {
|
|
616
|
-
const testing = [...planned.cases.add, ...planned.cases.patch, ...planned.cases.again];
|
|
617
|
-
const missing = notBuilt(readRecord(tip.buildDir), planned.step.tree, testing, tip.moduleName);
|
|
618
|
-
if (missing.length > 0) {
|
|
619
|
-
const record = relative(options.cwd, join(tip.buildDir, RECORD_FILE));
|
|
620
|
-
const notBuiltText = `${refsOf(tip.moduleName, missing)} ${missing.length === 1 ? "is" : "are"} not built`;
|
|
621
|
-
return {
|
|
622
|
-
report: `Not started: this conformance pulse is to test ${refsOf(tip.moduleName, testing)}, and ${notBuiltText} - ` +
|
|
623
|
-
`${record} does not have ${missing.length === 1 ? "it" : "them"} as the spec has ${missing.length === 1 ? "it" : "them"}. ` +
|
|
624
|
-
"No conformance test is written for code that is not built. Tell the user, and see with drift which code pulse regenerates it.",
|
|
625
|
-
details: { passed: false, landed: false, notBuilt: notBuiltText },
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
// Nothing here yet: the codebase starts as a copy of the one it is built on, recorded as what it inherits.
|
|
630
|
-
if (tip.requires !== null && !started(tip)) {
|
|
631
|
-
const below = state.chain.find((entry) => entry.moduleName === tip.requires);
|
|
632
|
-
const source = below === undefined ? null : readRecord(below.buildDir);
|
|
633
|
-
if (below !== undefined && source !== null) {
|
|
634
|
-
// Its conformance tests come with the code, and what they are written for, as what it inherits.
|
|
635
|
-
copyRequiredCode(below.buildDir, tip.buildDir, tip.moduleName, below.moduleName);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
// Nothing here yet, and nothing below: the codebase starts from its base folder, when the config names one.
|
|
639
|
-
if (tip.requires === null && !started(tip))
|
|
640
|
-
withModuleConfig(state, () => seedFromBaseFolder(tip.buildDir, tip.plainFile, tip.moduleName));
|
|
641
|
-
// A conformance job is shown the spec whole - its test reqs and scenarios are its to write from.
|
|
642
|
-
const result = await (conformance ? runConformance : run)({
|
|
643
|
-
plainFile: tip.plainFile,
|
|
644
|
-
moduleName: tip.moduleName,
|
|
645
|
-
buildDir: tip.buildDir,
|
|
646
|
-
spec: conformance ? spec : { ...spec, tree: planned.step.tree },
|
|
647
|
-
planned,
|
|
648
|
-
model: state.model,
|
|
649
|
-
cwd: options.cwd,
|
|
650
|
-
...(steering !== undefined ? { steering } : {}),
|
|
651
|
-
}, onDelta);
|
|
652
|
-
return {
|
|
653
|
-
report: result.report,
|
|
654
|
-
details: {
|
|
655
|
-
passed: result.landed,
|
|
656
|
-
landed: result.landed,
|
|
657
|
-
...(result.story !== undefined ? { story: result.story } : {}),
|
|
658
|
-
// The spec gaps its agents met, for a headless run to say - in the chat the report puts them to the person.
|
|
659
|
-
...(result.specGaps !== undefined && result.specGaps.length > 0 ? { specGaps: result.specGaps } : {}),
|
|
660
|
-
},
|
|
661
|
-
};
|
|
662
|
-
},
|
|
663
|
-
});
|
|
664
|
-
state.pulses = (state.pulses ?? 0) + 1;
|
|
665
|
-
state.running = { jobId: job.id, number: state.pulses, planned, from, after: planned.step.tree, ...(steering !== undefined ? { steering } : {}) };
|
|
666
|
-
void options.registry.wait(job.id).then((settled) => settle(state, settled), () => settle(state, undefined));
|
|
667
|
-
};
|
|
668
|
-
/** A pulse as a halt keeps it: its number, and the trees it went between. */
|
|
669
|
-
// A codebase taken back to nothing, and what the loop held of it - plans, halts - with it: built again from the start.
|
|
670
|
-
const startAgain = (entry, why) => {
|
|
671
|
-
startFromScratch(entry, why);
|
|
672
|
-
const state = modules.get(entry.buildDir);
|
|
673
|
-
if (state === undefined)
|
|
674
|
-
return;
|
|
675
|
-
state.plan = undefined;
|
|
676
|
-
state.conformancePlan = undefined;
|
|
677
|
-
state.halted = undefined;
|
|
678
|
-
state.conformanceHalted = undefined;
|
|
679
|
-
state.startOver = undefined;
|
|
680
|
-
};
|
|
681
|
-
// A codebase built on a module whose conformance tests the person asked for: disposable - deleted whole, its history with
|
|
682
|
-
// it - and what the loop held of it, so it is regenerated from the start, on the module once its tests pass.
|
|
683
|
-
const discard = (entry, why) => {
|
|
684
|
-
rmSync(dirname(entry.buildDir), { recursive: true, force: true });
|
|
685
|
-
reportActivity(` ${entry.moduleName}: its codebase is deleted - ${why}`);
|
|
686
|
-
const state = modules.get(entry.buildDir);
|
|
687
|
-
if (state === undefined)
|
|
688
|
-
return;
|
|
689
|
-
state.plan = undefined;
|
|
690
|
-
state.conformancePlan = undefined;
|
|
691
|
-
state.halted = undefined;
|
|
692
|
-
state.conformanceHalted = undefined;
|
|
693
|
-
state.startOver = undefined;
|
|
694
|
-
};
|
|
695
|
-
const pulseOf = (running) => ({ number: running.number, before: serializeTree(running.from), after: serializeTree(running.after) });
|
|
696
|
-
// What went wrong in a pulse that did not land, in a few words: the tests it stopped at, else its error's first line.
|
|
697
|
-
const causeOf = (job) => {
|
|
698
|
-
const stoppedAt = job?.details?.stoppedAt;
|
|
699
|
-
if (stoppedAt === "unit tests" || stoppedAt === "conformance" || stoppedAt === "regression") {
|
|
700
|
-
return { cause: stoppedAt === "unit tests" ? "its unit tests never passed" : stoppedAt === "conformance" ? "its conformance tests never passed" : "the whole conformance suite never passed" };
|
|
701
|
-
}
|
|
702
|
-
const error = job?.error?.split("\n").find((line) => line.trim() !== "")?.trim();
|
|
703
|
-
return error !== undefined ? { cause: error } : {};
|
|
704
|
-
};
|
|
705
|
-
const settle = (state, settled) => {
|
|
706
|
-
const running = state.running;
|
|
707
|
-
state.running = undefined;
|
|
708
|
-
const landed = settled?.status === "succeeded" && settled.details?.landed === true;
|
|
709
|
-
if (running !== undefined && !landed && running.planned.track === "conformance") {
|
|
710
|
-
// Conformance tests that did not pass - nor the code fixes they made - are gone, and they halt: the code goes on.
|
|
711
|
-
resetToLastCommit(tipEntry(state).buildDir);
|
|
712
|
-
state.conformancePlan = undefined;
|
|
713
|
-
if (running.stopping !== true) {
|
|
714
|
-
const unbuilt = settled?.details?.notBuilt;
|
|
715
|
-
const why = settled?.status === "stopped"
|
|
716
|
-
? `pulse ${running.jobId} was stopped`
|
|
717
|
-
: unbuilt !== undefined
|
|
718
|
-
? `conformance pulse ${running.jobId} ("${running.planned.title}") did not start: ${unbuilt}`
|
|
719
|
-
: `conformance pulse ${running.jobId} ("${running.planned.title}") did not pass`;
|
|
720
|
-
state.conformanceHalted = { why: `${why} - its conformance tests are written again once the spec or the code changes, or they are asked for again`, key: conformanceKey(state) };
|
|
721
|
-
// Nothing more is built on code whose conformance tests did not pass: its code halts too, and what is above waits.
|
|
722
|
-
let key = "";
|
|
723
|
-
try {
|
|
724
|
-
key = keyOf(chainSpec(state.chain));
|
|
725
|
-
}
|
|
726
|
-
catch {
|
|
727
|
-
/* a spec that does not parse halts it all the same */
|
|
728
|
-
}
|
|
729
|
-
state.halted = { why: `${why} - nothing more is built on it until its conformance tests pass`, specKey: key, pulse: pulseOf(running), ...(settled?.status === "stopped" ? {} : causeOf(settled)) };
|
|
730
|
-
record({ kind: "loop.halted", why: firstLine(state.halted.why, 300), track: "conformance" }, loopPlace(state, running.jobId));
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
else if (running !== undefined && !landed) {
|
|
734
|
-
// What it wrote and never committed is gone: code, tests and record agree again.
|
|
735
|
-
resetToLastCommit(tipEntry(state).buildDir);
|
|
736
|
-
state.plan = undefined;
|
|
737
|
-
// Stopped for the conformance tests of a module below: the codebase is deleted, and regenerated from it after.
|
|
738
|
-
if (running.discard !== undefined)
|
|
739
|
-
discard(tipEntry(state), running.discard);
|
|
740
|
-
if (running.stopping !== true) {
|
|
741
|
-
let key = "";
|
|
742
|
-
try {
|
|
743
|
-
key = keyOf(chainSpec(state.chain));
|
|
744
|
-
}
|
|
745
|
-
catch {
|
|
746
|
-
/* a spec that does not parse halts it all the same */
|
|
747
|
-
}
|
|
748
|
-
const why = settled?.status === "stopped" ? `pulse ${running.jobId} was stopped` : `pulse ${running.jobId} ("${running.planned.title}") did not land`;
|
|
749
|
-
state.halted = { why: `${why} - it runs again once the spec changes, or the module is asked for again`, specKey: key, pulse: pulseOf(running), ...(settled?.status === "stopped" ? {} : causeOf(settled)) };
|
|
750
|
-
record({ kind: "loop.halted", why: firstLine(state.halted.why, 300), track: "code" }, loopPlace(state, running.jobId));
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
else {
|
|
754
|
-
const own = running?.planned.track === "conformance" ? state.conformancePlan : state.plan;
|
|
755
|
-
if (own !== undefined) {
|
|
756
|
-
own.jobs.shift();
|
|
757
|
-
if (running !== undefined)
|
|
758
|
-
own.from = serializeTree(running.after);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
// What it did, in the notes every agent after reads - once anything it did not land is rolled back, so the line stays.
|
|
762
|
-
if (running !== undefined)
|
|
763
|
-
notePulse(state, running, settled, landed);
|
|
764
|
-
// Landed: the commit it ends on, its line in the notes amended in - told before the codebase's next pulse starts.
|
|
765
|
-
if (running !== undefined && settled !== undefined && landed) {
|
|
766
|
-
const tip = tipEntry(state);
|
|
767
|
-
const commit = lastCommit(tip.buildDir);
|
|
768
|
-
if (commit !== undefined) {
|
|
769
|
-
settled.details = { ...settled.details, commit };
|
|
770
|
-
try {
|
|
771
|
-
options.landed?.({ job: settled, plainFile: tip.plainFile, moduleName: tip.moduleName, commit, title: running.planned.title });
|
|
772
|
-
}
|
|
773
|
-
catch {
|
|
774
|
-
/* what is done with a landing is not the loop's to fail on */
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
void tick();
|
|
779
|
-
};
|
|
780
|
-
/**
|
|
781
|
-
* A pulse's line in the notes, written as it ends: what it regenerated, whether it landed, how it went - the rounds,
|
|
782
|
-
* the test runs, what the debugger found - and where its log is, for whoever wants the whole of it. Committed
|
|
783
|
-
* with it.
|
|
784
|
-
*/
|
|
785
|
-
const notePulse = (state, running, settled, landed) => {
|
|
786
|
-
const tip = tipEntry(state);
|
|
787
|
-
const details = settled?.details;
|
|
788
|
-
const outcome = landed
|
|
789
|
-
? "landed"
|
|
790
|
-
: settled?.status === "stopped" || running.stopping === true
|
|
791
|
-
? "stopped - rolled back"
|
|
792
|
-
: details?.notBuilt !== undefined
|
|
793
|
-
? `did not start: ${details.notBuilt}`
|
|
794
|
-
: "did not pass - rolled back";
|
|
795
|
-
const log = settled?.logFile !== undefined ? ` · log ${relative(projectDirOf(tip.plainFile), settled.logFile)}` : "";
|
|
796
|
-
const took = settled !== undefined ? ` · ${formatDuration(settled)}${settled.usage.cost > 0 ? ` · $${settled.usage.cost.toFixed(2)}` : ""}` : "";
|
|
797
|
-
const what = `${running.planned.track === "conformance" ? "conformance tests: " : ""}${running.planned.title}`;
|
|
798
|
-
// A conformance pulse's line is the tests' notes', beside them: the coding agents never read of the black-box tests.
|
|
799
|
-
const notesDir = running.planned.track === "conformance" ? testsDirOf(state) : tip.buildDir;
|
|
800
|
-
recordPulse(notesDir, `${what} - ${outcome}${details?.story !== undefined ? `; ${details.story}` : ""}${took}${log}`, `${tip.moduleName} pulse ${running.number}`);
|
|
801
|
-
commitNotes(notesDir, NOTES_FILE, `pulse ${running.number} ${landed ? "landed" : "rolled back"}: ${what}`, landed ? (settled?.startedAt ?? Date.now()) : undefined);
|
|
802
|
-
};
|
|
803
|
-
/**
|
|
804
|
-
* A record written before linked resources were hashed has the hashes of the files as they are now - committed, with
|
|
805
|
-
* nothing running there - so the code is taken to be built from them, rather than everything linking one built again.
|
|
806
|
-
*/
|
|
807
|
-
const hashResources = (state, spec) => {
|
|
808
|
-
// A look ahead only reads.
|
|
809
|
-
if (state.lookedAhead === true)
|
|
810
|
-
return;
|
|
811
|
-
const code = tipEntry(state).buildDir;
|
|
812
|
-
for (const dir of [code, testsDirOf(state)]) {
|
|
813
|
-
const record = readRecord(dir);
|
|
814
|
-
const hashed = adoptDigests(record, spec.tree);
|
|
815
|
-
if (record === null || hashed === null || serializeTree(hashed) === serializeTree(record))
|
|
816
|
-
continue;
|
|
817
|
-
(dir === code ? writeCodeRecord : writeTestsRecord)(dir, hashed);
|
|
818
|
-
recordHistory(dir, "the record's linked resources hashed, as their files are now");
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
/** What a conformance halt holds for: the spec and what the code is built from, as they are. */
|
|
822
|
-
const conformanceKey = (state) => {
|
|
823
|
-
try {
|
|
824
|
-
return `${serializeTree(chainSpec(state.chain).tree)}\n${serializeTree(readRecord(tipEntry(state).buildDir) ?? {})}`;
|
|
825
|
-
}
|
|
826
|
-
catch {
|
|
827
|
-
return "";
|
|
828
|
-
}
|
|
829
|
-
};
|
|
830
|
-
/** Look at every codebase once, bottom of each chain first, and start what can start. */
|
|
831
|
-
const tick = () => {
|
|
832
|
-
ticking = ticking
|
|
833
|
-
.then(() => withParseCache(() => lookAll()))
|
|
834
|
-
.catch((error) => reportActivity(` the work loop: ${error instanceof Error ? error.message : String(error)}`));
|
|
835
|
-
return ticking;
|
|
836
|
-
};
|
|
837
|
-
// A testing script written in the background, or not: what waited for it is looked at again - started, or failed for want of it.
|
|
838
|
-
onScriptRunEnded(() => {
|
|
839
|
-
if (asked.size > 0 || ahead.size > 0)
|
|
840
|
-
void tick();
|
|
841
|
-
});
|
|
842
|
-
/** The files asked for, each with how: what the loop brings up, worked out again each look. */
|
|
843
|
-
const asked = new Map();
|
|
844
|
-
/** The files looked ahead at and not asked for since: their codebases are looked at, their pulses held. */
|
|
845
|
-
const ahead = new Map();
|
|
846
|
-
/** The codebases a look ahead is planning now: the only looks that plan a codebase held for one. */
|
|
847
|
-
const planningAhead = new Set();
|
|
848
|
-
/**
|
|
849
|
-
* The modules asked for whose plan is not made yet - their code being deleted, what is left being worked out, the
|
|
850
|
-
* planner not started - by name, with since when: each shows as being planned from the moment it is asked for, not
|
|
851
|
-
* only once the planner runs, so the person never looks at nothing.
|
|
852
|
-
*/
|
|
853
|
-
const preparing = new Map();
|
|
854
|
-
const preparingFor = async (plainFile, work) => {
|
|
855
|
-
const name = basename(plainFile).replace(/\.plain$/, "");
|
|
856
|
-
if (preparing.has(name))
|
|
857
|
-
return work();
|
|
858
|
-
preparing.set(name, { since: Date.now(), plainFile: resolve(options.cwd, plainFile) });
|
|
859
|
-
options.registry.notify?.();
|
|
860
|
-
// A frame to draw it in before what follows: deleting a codebase and committing it hold the event loop.
|
|
861
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
862
|
-
try {
|
|
863
|
-
return await work();
|
|
864
|
-
}
|
|
865
|
-
finally {
|
|
866
|
-
preparing.delete(name);
|
|
867
|
-
options.registry.notify?.();
|
|
868
|
-
}
|
|
869
|
-
};
|
|
870
|
-
/**
|
|
871
|
-
* The codebases the requests bring up now - where each module's code lives, and what is to be built on it - those
|
|
872
|
-
* asked for and, unless `requests` names others, those looked ahead at.
|
|
873
|
-
*/
|
|
874
|
-
const active = (requests = [...asked, ...ahead]) => {
|
|
875
|
-
const states = new Set();
|
|
876
|
-
for (const [file, request] of requests) {
|
|
877
|
-
let chains;
|
|
878
|
-
try {
|
|
879
|
-
chains = chainsFor(file);
|
|
880
|
-
}
|
|
881
|
-
catch {
|
|
882
|
-
continue;
|
|
883
|
-
}
|
|
884
|
-
for (const chain of chains)
|
|
885
|
-
for (const entry of toBuild(chain))
|
|
886
|
-
states.add(track(chain.slice(0, chain.indexOf(entry) + 1), request));
|
|
887
|
-
}
|
|
888
|
-
return states;
|
|
889
|
-
};
|
|
890
|
-
/** A codebase the loop no longer looks after: nothing of it is shown, planned or waited for. */
|
|
891
|
-
const forget = (state) => {
|
|
892
|
-
const key = tipEntry(state).buildDir;
|
|
893
|
-
modules.delete(key);
|
|
894
|
-
order.splice(order.indexOf(key), 1);
|
|
895
|
-
};
|
|
896
|
-
const lookAll = async () => {
|
|
897
|
-
// A .plain file taken out of the project is asked for no more, and a codebase whose module's file is gone is
|
|
898
|
-
// forgotten - nothing running there - rather than shown waiting for a plan it will never have.
|
|
899
|
-
for (const file of [...asked.keys()])
|
|
900
|
-
if (!existsSync(file))
|
|
901
|
-
asked.delete(file);
|
|
902
|
-
for (const file of [...ahead.keys()])
|
|
903
|
-
if (!existsSync(file))
|
|
904
|
-
ahead.delete(file);
|
|
905
|
-
for (const key of [...order]) {
|
|
906
|
-
const state = modules.get(key);
|
|
907
|
-
if (state.running === undefined && !existsSync(tipEntry(state).plainFile))
|
|
908
|
-
forget(state);
|
|
909
|
-
}
|
|
910
|
-
const now = active();
|
|
911
|
-
looking = now;
|
|
912
|
-
// Why each codebase stands as it does, before this look: one that changed is told, as a plan that changed is - a
|
|
913
|
-
// module that starts or stops waiting moves no job, and would otherwise go unseen until something else did.
|
|
914
|
-
const whyBefore = new Map([...modules.values()].map((state) => [state, state.why]));
|
|
915
|
-
try {
|
|
916
|
-
for (const key of order) {
|
|
917
|
-
const state = modules.get(key);
|
|
918
|
-
// A codebase left behind - built on since - is not looked at, unless a job of it is still running; what it had
|
|
919
|
-
// planned, or waited for, is no longer shown.
|
|
920
|
-
if (now.has(state) || state.running !== undefined)
|
|
921
|
-
await withModuleConfig(state, () => look(state));
|
|
922
|
-
else {
|
|
923
|
-
state.why = "left behind: the code is built on further up the chain, where changes to it are made";
|
|
924
|
-
state.waitsFor = undefined;
|
|
925
|
-
state.plan = undefined;
|
|
926
|
-
state.conformancePlan = undefined;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
finally {
|
|
931
|
-
if ([...modules.values()].some((state) => state.why !== whyBefore.get(state)))
|
|
932
|
-
options.registry.notify?.();
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
const look = async (state) => {
|
|
936
|
-
const tip = tipEntry(state);
|
|
937
|
-
let spec;
|
|
938
|
-
try {
|
|
939
|
-
spec = chainSpec(state.chain);
|
|
940
|
-
}
|
|
941
|
-
catch (error) {
|
|
942
|
-
state.why = `its spec does not parse: ${error instanceof Error ? error.message : String(error)}`;
|
|
943
|
-
// Not planned from a spec that does not parse: what it waited for, and the plan, were the spec's before.
|
|
944
|
-
state.waitsFor = undefined;
|
|
945
|
-
if (state.running === undefined) {
|
|
946
|
-
state.plan = undefined;
|
|
947
|
-
state.conformancePlan = undefined;
|
|
948
|
-
}
|
|
949
|
-
return;
|
|
950
|
-
}
|
|
951
|
-
const specKey = keyOf(spec);
|
|
952
|
-
state.seen = spec;
|
|
953
|
-
if (state.running !== undefined) {
|
|
954
|
-
if (state.running.stopping === true)
|
|
955
|
-
return;
|
|
956
|
-
// The stop rule: every change the running job makes is still part of the work, measured from the same record.
|
|
957
|
-
const track = state.running.planned.track;
|
|
958
|
-
const own = changesBetween(serializeTree(state.running.from), serializeTree(state.running.after));
|
|
959
|
-
let work = workOf(track, state.running.from, state, spec);
|
|
960
|
-
// A change inside what it regenerates steers it, rather than stopping it or leaving it to the next job.
|
|
961
|
-
if (!stillWanted(own, work) && trySteer(state, spec, own, work))
|
|
962
|
-
work = workOf(track, state.running.from, state, spec);
|
|
963
|
-
const ownNow = changesBetween(serializeTree(state.running.from), serializeTree(state.running.after));
|
|
964
|
-
if (!stillWanted(ownNow, work)) {
|
|
965
|
-
const why = whyNotWanted(ownNow, work);
|
|
966
|
-
// The project may have it run to its end instead: what it lands, the next job regenerates the change on top of.
|
|
967
|
-
if (configForSpec(tip.plainFile).allowToStopJobs === false) {
|
|
968
|
-
if (state.running.keptDespite !== why) {
|
|
969
|
-
state.running.keptDespite = why;
|
|
970
|
-
reportActivity(` ${tip.moduleName}: pulse ${state.running.jobId} runs on although ${why} - allow-to-stop-jobs is false: the change is regenerated on top of what it lands`);
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
else {
|
|
974
|
-
state.running.stopping = true;
|
|
975
|
-
state.why = `pulse ${state.running.jobId} was stopped: ${why}, which it was regenerating from`;
|
|
976
|
-
record({ kind: "loop.stopped", why: firstLine(why, 300) }, loopPlace(state, state.running.jobId));
|
|
977
|
-
reportActivity(` ${tip.moduleName}: ${state.why}`);
|
|
978
|
-
options.registry.stop(state.running.jobId, `Stopped by turri, not by you: ${why}, which it was regenerating from. What it had done is rolled back, and the spec as it is now is regenerated instead. To have a running pulse finish first and the change regenerated on top of it, set allow-to-stop-jobs: false in config.turri.yaml.`);
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
// Still wanted: what comes after it is planned now, from what it will land - not once it has.
|
|
983
|
-
const planOf = track === "code" ? state.plan : state.conformancePlan;
|
|
984
|
-
if (planOf === undefined || planOf.specKey !== specKey) {
|
|
985
|
-
const running = state.running;
|
|
986
|
-
// Shown as being planned on the regeneration; the status goes on showing the running job.
|
|
987
|
-
const rest = workOf(track, running.after, state, spec).length === 0 ? { jobs: [], notes: [] } : await planIdle(state, spec, running.after, track);
|
|
988
|
-
const next = { specKey, from: serializeTree(running.from), jobs: [running.planned, ...rest.jobs] };
|
|
989
|
-
if (state.running === running) {
|
|
990
|
-
if (track === "code")
|
|
991
|
-
state.plan = { ...next, notes: rest.notes };
|
|
992
|
-
else
|
|
993
|
-
state.conformancePlan = { ...next, codeKey: codeKeyOf(state) };
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
hashResources(state, spec);
|
|
999
|
-
if (state.held !== undefined) {
|
|
1000
|
-
state.why = state.held.why;
|
|
1001
|
-
state.waitsFor = undefined;
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
if (state.halted !== undefined) {
|
|
1005
|
-
if (state.halted.specKey === specKey) {
|
|
1006
|
-
state.why = state.halted.why;
|
|
1007
|
-
return;
|
|
1008
|
-
}
|
|
1009
|
-
state.halted = undefined;
|
|
1010
|
-
}
|
|
1011
|
-
state.startOver = undefined;
|
|
1012
|
-
// Built when functional specs were numbered, before func-ids: nothing is built on it - its chain starts over.
|
|
1013
|
-
const old = oldCodebases(state.chain);
|
|
1014
|
-
if (old.length > 0) {
|
|
1015
|
-
state.startOver = { requires: [], codebases: old.map((entry) => entry.moduleName), old: true };
|
|
1016
|
-
state.why = OLD_RECORDS_WHY(old.map((entry) => entry.moduleName));
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
|
-
const fresh = newlyRequired(state.chain);
|
|
1020
|
-
if (fresh !== undefined && fresh.rebuild.some((entry) => entry.buildDir === tip.buildDir)) {
|
|
1021
|
-
const codebases = fresh.rebuild.map((entry) => entry.moduleName);
|
|
1022
|
-
state.startOver = { requires: fresh.modules, codebases };
|
|
1023
|
-
state.why =
|
|
1024
|
-
`it now requires ${fresh.modules.join(", ")}, which its code was not built on: it is built only once ` +
|
|
1025
|
-
`${codebases.join(", ")} ${codebases.length === 1 ? "is" : "are"} started over - code and conformance tests taken out, kept in the history, and built again on ${fresh.modules.join(", ")}`;
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
|
-
const below = waitingOn(state);
|
|
1029
|
-
state.waitsFor = below?.module;
|
|
1030
|
-
if (below !== undefined) {
|
|
1031
|
-
state.why = below.why;
|
|
1032
|
-
return;
|
|
1033
|
-
}
|
|
1034
|
-
// A func-id or a scenario-id renamed, and nothing else with it: turri renames it in the records and relabels the tests
|
|
1035
|
-
// itself, as one unit of work - no pulse, the code untouched. Failing, it is rolled back whole, and the codebase halts
|
|
1036
|
-
// rather than build the functional spec anew.
|
|
1037
|
-
// Looked ahead, they are not made - a look ahead writes nothing - and the code is planned from as they would leave it.
|
|
1038
|
-
const renamed = readRecord(tip.buildDir) === null ? undefined : pureRenames(readRecord(tip.buildDir), readRecord(testsDirOf(state)), spec.tree, tip.moduleName);
|
|
1039
|
-
const pending = state.lookedAhead === true && renamed !== undefined && renamed.renames.length > 0 && renamed.code !== null ? renamed.code : undefined;
|
|
1040
|
-
if (renamed !== undefined && renamed.renames.length > 0 && state.lookedAhead !== true) {
|
|
1041
|
-
const made = makeRenames({ buildDir: tip.buildDir, testsDir: testsDirOf(state), moduleName: tip.moduleName, renamed, place: { project: projectRootOf(tip.buildDir), module: tip.moduleName } });
|
|
1042
|
-
if (!made) {
|
|
1043
|
-
state.halted = { why: `renaming ${renamed.renames.map(renameText).join(", ")} failed, and was rolled back - it is tried again once the spec changes, or the module is asked for again`, specKey };
|
|
1044
|
-
state.why = state.halted.why;
|
|
1045
|
-
record({ kind: "loop.halted", why: firstLine(state.halted.why, 300), track: "code" }, { project: projectRootOf(tip.buildDir), module: tip.moduleName });
|
|
1046
|
-
return;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
// The module's code first, every job of it; then its conformance tests - once, for the module as built, with one
|
|
1050
|
-
// explorer and one run of the whole suite - and only then is anything built on it (waitingOn).
|
|
1051
|
-
const from = pending !== undefined ? codeTree(pending) : builtOf(state);
|
|
1052
|
-
const codeLeft = codeWork(from, spec.tree).length > 0;
|
|
1053
|
-
// Held for a look ahead, a codebase is planned by a look ahead alone: a plan that no longer fits is dropped, not made again.
|
|
1054
|
-
const mayPlan = state.lookedAhead !== true || planningAhead.has(state);
|
|
1055
|
-
if (state.conformanceHalted !== undefined && state.conformanceHalted.key !== conformanceKey(state))
|
|
1056
|
-
state.conformanceHalted = undefined;
|
|
1057
|
-
if (!codeLeft && conformanceWanted(state, spec) && state.conformanceHalted === undefined) {
|
|
1058
|
-
const tested = testedOf(state);
|
|
1059
|
-
if (workOf("conformance", tested, state, spec).length > 0) {
|
|
1060
|
-
const testedKey = serializeTree(tested);
|
|
1061
|
-
const existing = state.conformancePlan;
|
|
1062
|
-
// Made again when the spec, the tests or the code it was planned against moved: what the tests are written for
|
|
1063
|
-
// follows the code, and a plan made before a code pulse landed would test it as it was.
|
|
1064
|
-
if (existing === undefined || existing.specKey !== specKey || existing.from !== testedKey || existing.codeKey !== codeKeyOf(state) || existing.jobs.length === 0) {
|
|
1065
|
-
if (!mayPlan) {
|
|
1066
|
-
state.conformancePlan = undefined;
|
|
1067
|
-
state.why = LOOK_AGAIN;
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
state.conformancePlan = { specKey, from: testedKey, codeKey: codeKeyOf(state), jobs: (await planIdle(state, spec, tested, "conformance")).jobs };
|
|
1071
|
-
}
|
|
1072
|
-
const next = state.conformancePlan.jobs[0];
|
|
1073
|
-
if (next !== undefined) {
|
|
1074
|
-
state.why = undefined;
|
|
1075
|
-
startJob(state, spec, tested, next);
|
|
1076
|
-
return;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
else {
|
|
1080
|
-
state.conformancePlan = undefined;
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
if (!codeLeft) {
|
|
1084
|
-
state.plan = undefined;
|
|
1085
|
-
// Its scenarios untested for a step of adding tests it skipped: no conformance pulse starts - it waits on that step.
|
|
1086
|
-
const gap = state.conformanceHalted === undefined && readRecord(tip.buildDir) !== null ? gapOf(state, spec) : undefined;
|
|
1087
|
-
state.why =
|
|
1088
|
-
state.conformanceHalted?.why ??
|
|
1089
|
-
(gap === undefined
|
|
1090
|
-
? UP_TO_DATE
|
|
1091
|
-
: gap.step === "conformance testing script" && awaitsScript(state, "conformance")
|
|
1092
|
-
? SCRIPT_BEING_WRITTEN("conformance testing script")
|
|
1093
|
-
: `waiting for its ${gap.step}: ${gap.text}`);
|
|
1094
|
-
return;
|
|
1095
|
-
}
|
|
1096
|
-
const fromKey = serializeTree(from);
|
|
1097
|
-
if (state.plan === undefined || state.plan.specKey !== specKey || state.plan.from !== fromKey || state.plan.jobs.length === 0) {
|
|
1098
|
-
if (!mayPlan) {
|
|
1099
|
-
state.plan = undefined;
|
|
1100
|
-
state.why = LOOK_AGAIN;
|
|
1101
|
-
return;
|
|
1102
|
-
}
|
|
1103
|
-
const { jobs, notes } = await planIdle(state, spec, from, "code");
|
|
1104
|
-
state.plan = { specKey, from: fromKey, jobs, notes };
|
|
1105
|
-
if (jobs.length === 0) {
|
|
1106
|
-
state.why = NO_PLAN;
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
if (awaitsScript(state, "unit")) {
|
|
1111
|
-
state.why = SCRIPT_BEING_WRITTEN("unit testing script");
|
|
1112
|
-
return;
|
|
1113
|
-
}
|
|
1114
|
-
const lacking = lacksOwnScript(state);
|
|
1115
|
-
if (lacking !== undefined) {
|
|
1116
|
-
state.why = lacking;
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
state.why = undefined;
|
|
1120
|
-
startJob(state, spec, from, state.plan.jobs[0]);
|
|
1121
|
-
};
|
|
1122
|
-
const statusOf = (state) => describe(state).status;
|
|
1123
|
-
/** A planned row's codebase and its place there, from its id - `planned-<module>-N`, the longest module name it starts with, as a name may hold a hyphen. */
|
|
1124
|
-
const rowOf = (rowId) => {
|
|
1125
|
-
const state = order
|
|
1126
|
-
.map((key) => modules.get(key))
|
|
1127
|
-
.filter((candidate) => rowId.startsWith(`planned-${tipEntry(candidate).moduleName}-`))
|
|
1128
|
-
.sort((a, b) => tipEntry(b).moduleName.length - tipEntry(a).moduleName.length)[0];
|
|
1129
|
-
if (state === undefined)
|
|
1130
|
-
return undefined;
|
|
1131
|
-
const rest = rowId.slice(`planned-${tipEntry(state).moduleName}-`.length);
|
|
1132
|
-
return /^[1-9]\d*$/.test(rest) ? { state, index: Number(rest) } : undefined;
|
|
1133
|
-
};
|
|
1134
|
-
/** The modules asked for that the loop holds nothing of yet - turri just opened, say: their code being planned all the same. */
|
|
1135
|
-
const preparingAlone = () => {
|
|
1136
|
-
const held = new Set(order.map((key) => tipEntry(modules.get(key)).moduleName));
|
|
1137
|
-
return [...preparing]
|
|
1138
|
-
.filter(([name]) => !held.has(name))
|
|
1139
|
-
.map(([name, { since, plainFile }]) => ({
|
|
1140
|
-
module: name,
|
|
1141
|
-
plainFile,
|
|
1142
|
-
planned: [{ title: "the work", cases: { fresh: false, add: [], patch: [], again: [], delete: [], mechanical: false }, track: "code", planning: true }],
|
|
1143
|
-
since,
|
|
1144
|
-
}));
|
|
1145
|
-
};
|
|
1146
|
-
/** A codebase's status, and beside each job it lists as planned, the planned job it is - none for one being planned or scheduled. */
|
|
1147
|
-
const describe = (state) => withModuleConfig(state, () => describeIn(state));
|
|
1148
|
-
const describeIn = (state) => {
|
|
1149
|
-
// What runs next: the code's jobs, then the conformance tests' - the module's, once its code is built - the running job first.
|
|
1150
|
-
const running = state.running?.planned;
|
|
1151
|
-
const own = (jobs) => (jobs ?? []).filter((job) => job !== running);
|
|
1152
|
-
// A track being planned again shows as that, not as its plan before - and a module asked for, from that moment, as
|
|
1153
|
-
// its code being planned: its code deleted, what is left worked out, before the planner runs.
|
|
1154
|
-
const planningTrack = state.running === undefined ? (state.planning ?? (preparing.has(tipEntry(state).moduleName) ? "code" : undefined)) : undefined;
|
|
1155
|
-
const replanning = planningTrack;
|
|
1156
|
-
const jobs = [
|
|
1157
|
-
...(running !== undefined ? [running] : []),
|
|
1158
|
-
...(replanning === "code" ? [] : own(state.plan?.jobs)),
|
|
1159
|
-
...(replanning === "conformance" ? [] : own(state.conformancePlan?.jobs)),
|
|
1160
|
-
];
|
|
1161
|
-
const lastCode = jobs.findLastIndex((job) => job.track === "code");
|
|
1162
|
-
const planningNow = planningTrack !== undefined
|
|
1163
|
-
? [
|
|
1164
|
-
{
|
|
1165
|
-
title: planningTrack === "conformance" ? "the conformance tests" : "the work",
|
|
1166
|
-
cases: { fresh: false, add: [], patch: [], again: [], delete: [], mechanical: false },
|
|
1167
|
-
track: planningTrack,
|
|
1168
|
-
planning: true,
|
|
1169
|
-
},
|
|
1170
|
-
]
|
|
1171
|
-
: [];
|
|
1172
|
-
// The conformance tests that follow the code still to build - of its functional specs with scenarios whose tests
|
|
1173
|
-
// are not written for them as they read now: planned once the code is built, shown now.
|
|
1174
|
-
const codeToBuild = lastCode !== -1 || planningTrack === "code";
|
|
1175
|
-
const seen = state.seen?.tree;
|
|
1176
|
-
// Not with a step of adding tests skipped: they are not planned until it is taken.
|
|
1177
|
-
const testReqs = (seen?.[TEST_REQUIREMENTS] ?? []).length > 0 &&
|
|
1178
|
-
codeToBuild &&
|
|
1179
|
-
testingGap({ moduleName: tipEntry(state).moduleName, plainFile: tipEntry(state).plainFile, tree: seen, buildDir: tipEntry(state).buildDir }) === undefined;
|
|
1180
|
-
// Those of the modules below too: the tip's suite holds the chain's.
|
|
1181
|
-
const tested = testedOf(state);
|
|
1182
|
-
const sections = [REQUIRED_FUNCTIONAL_SPECS, FUNCTIONAL_REQUIREMENTS];
|
|
1183
|
-
const written = new Set(sections.flatMap((section) => (tested[section] ?? []).map((item) => JSON.stringify(item))));
|
|
1184
|
-
const behind = sections.flatMap((section) => (seen?.[section] ?? []).filter((item) => hasScenarios(item) && !written.has(JSON.stringify(item))));
|
|
1185
|
-
const afterCode = codeToBuild && testReqs && behind.length > 0 && state.conformanceHalted === undefined && !jobs.some((job) => job.track === "conformance")
|
|
1186
|
-
? [{ title: "conformance tests", cases: { fresh: false, add: [], patch: [], again: [], delete: [], mechanical: false }, track: "conformance", afterCode: true, specs: behind.map((item) => `${item.module ?? tipEntry(state).moduleName}:${item.id}`) }]
|
|
1187
|
-
: [];
|
|
1188
|
-
const listed = [
|
|
1189
|
-
...planningNow.map((entry) => ({ entry })),
|
|
1190
|
-
...jobs.map((job) => ({ entry: { title: job.title, cases: job.cases, track: job.track }, job })),
|
|
1191
|
-
...afterCode.map((entry) => ({ entry })),
|
|
1192
|
-
];
|
|
1193
|
-
const planned = listed.map((item) => item.entry);
|
|
1194
|
-
const tip = tipEntry(state);
|
|
1195
|
-
// While a pulse runs, the renames made once it ends: shown as renames, never as a functional spec taken out and one added.
|
|
1196
|
-
const renames = state.running !== undefined && state.running.planned.track === "code" && seen !== undefined ? pureRenames(readRecord(tip.buildDir), readRecord(testsDirOf(state)), seen, tip.moduleName).renames : [];
|
|
1197
|
-
const base = baseOfState(state);
|
|
1198
|
-
const status = {
|
|
1199
|
-
module: tip.moduleName,
|
|
1200
|
-
plainFile: tip.plainFile,
|
|
1201
|
-
...(base !== undefined ? { base } : {}),
|
|
1202
|
-
...(renames.length > 0 ? { renames: renames.map(renameText) } : {}),
|
|
1203
|
-
...(state.configModule?.name !== undefined ? { configModule: state.configModule.name } : {}),
|
|
1204
|
-
...(state.running !== undefined
|
|
1205
|
-
? {
|
|
1206
|
-
running: {
|
|
1207
|
-
jobId: state.running.jobId,
|
|
1208
|
-
title: state.running.planned.title,
|
|
1209
|
-
...(state.running.steering !== undefined && state.running.steering.steers > 0 ? { steered: [...state.running.steering.notes] } : {}),
|
|
1210
|
-
},
|
|
1211
|
-
}
|
|
1212
|
-
: {}),
|
|
1213
|
-
planned: state.running !== undefined ? planned.slice(1) : planned,
|
|
1214
|
-
...(replanning !== "code" && (state.plan?.notes.length ?? 0) > 0 ? { planNotes: [...state.plan.notes] } : {}),
|
|
1215
|
-
...(state.running === undefined && state.why !== undefined ? { why: state.why } : {}),
|
|
1216
|
-
...(state.running === undefined && state.startOver !== undefined ? { startOver: state.startOver } : {}),
|
|
1217
|
-
};
|
|
1218
|
-
const shown = state.running !== undefined ? listed.slice(1) : listed;
|
|
1219
|
-
return { status, jobs: shown.map((item) => item.job), ahead: shown.map((item) => (item.entry.afterCode === true ? { title: item.entry.title, specs: item.entry.specs ?? [] } : undefined)) };
|
|
1220
|
-
};
|
|
1221
|
-
/**
|
|
1222
|
-
* Look after a codebase - its chain up to it - from now on; says its state. Its config is worked out again - its tip's
|
|
1223
|
-
* (`configModuleFor`): `asked`, one that cannot be told refuses the ask; otherwise it keeps the one it had.
|
|
1224
|
-
*/
|
|
1225
|
-
const track = (chain, request, asked = false) => {
|
|
1226
|
-
const tip = tipOf(chain);
|
|
1227
|
-
let state = modules.get(tip.buildDir);
|
|
1228
|
-
if (state === undefined) {
|
|
1229
|
-
state = { chain };
|
|
1230
|
-
modules.set(tip.buildDir, state);
|
|
1231
|
-
// Bottom of the chain first: a codebase is looked at after those it is built on.
|
|
1232
|
-
const at = order.findIndex((key) => modules.get(key).chain.some((entry) => entry.buildDir === tip.buildDir));
|
|
1233
|
-
if (at === -1)
|
|
1234
|
-
order.push(tip.buildDir);
|
|
1235
|
-
else
|
|
1236
|
-
order.splice(at, 0, tip.buildDir);
|
|
1237
|
-
}
|
|
1238
|
-
state.chain = chain;
|
|
1239
|
-
try {
|
|
1240
|
-
state.configModule = { name: configModuleFor(tip.plainFile) };
|
|
1241
|
-
}
|
|
1242
|
-
catch (error) {
|
|
1243
|
-
if (asked)
|
|
1244
|
-
throw error;
|
|
1245
|
-
}
|
|
1246
|
-
// Its model as its config has it: a module's own file can name a coding model of its own.
|
|
1247
|
-
const model = request.model ?? withModuleConfig(state, () => options.modelFor?.(tip.plainFile));
|
|
1248
|
-
if (model !== undefined)
|
|
1249
|
-
state.model = model;
|
|
1250
|
-
return state;
|
|
1251
|
-
};
|
|
1252
|
-
const loop = {
|
|
1253
|
-
async bringUp(plainFile, given = {}) {
|
|
1254
|
-
// Asked for, it shows as being planned at once.
|
|
1255
|
-
return preparingFor(plainFile, async () => {
|
|
1256
|
-
const files = codebasesOf(resolve(options.cwd, plainFile));
|
|
1257
|
-
for (const file of files) {
|
|
1258
|
-
asked.set(file, { ...ahead.get(file), ...asked.get(file), ...given });
|
|
1259
|
-
ahead.delete(file);
|
|
1260
|
-
}
|
|
1261
|
-
// Asked for, its config is worked out - its own file, or one of a module it requires - and pinned to its pulses.
|
|
1262
|
-
const states = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), given, true)))));
|
|
1263
|
-
// Asked again, a halted codebase is tried again - one the person halted too. Looked ahead at, its kept plan starts.
|
|
1264
|
-
for (const state of states) {
|
|
1265
|
-
state.halted = undefined;
|
|
1266
|
-
state.held = undefined;
|
|
1267
|
-
state.lookedAhead = undefined;
|
|
1268
|
-
// Asked for again: its conformance tests are written for every functional spec with scenarios, not only those conform named.
|
|
1269
|
-
state.conformanceOnly = undefined;
|
|
1270
|
-
}
|
|
1271
|
-
await tick();
|
|
1272
|
-
return [...new Set(states)].map(statusOf);
|
|
1273
|
-
});
|
|
1274
|
-
},
|
|
1275
|
-
async lookAhead(plainFile, given = {}) {
|
|
1276
|
-
// Being planned, it shows so at once; what is planned is said once it is - not as being planned.
|
|
1277
|
-
const states = await preparingFor(plainFile, async () => {
|
|
1278
|
-
const files = codebasesOf(resolve(options.cwd, plainFile));
|
|
1279
|
-
for (const file of files)
|
|
1280
|
-
if (!asked.has(file))
|
|
1281
|
-
ahead.set(file, { ...ahead.get(file), ...given });
|
|
1282
|
-
// Its config pinned as an ask pins it: the plan is made, and its pulses run, with the config regenerate would use.
|
|
1283
|
-
const tracked = withParseCache(() => files.flatMap((file) => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), given, true)))));
|
|
1284
|
-
// A chain with a pulse running is being built as asked, and goes on; every other codebase is held - one asked for
|
|
1285
|
-
// earlier too, which would otherwise start the work the look ahead plans.
|
|
1286
|
-
const building = (state) => state.chain.some((entry) => modules.get(entry.buildDir)?.running !== undefined);
|
|
1287
|
-
for (const state of tracked) {
|
|
1288
|
-
if (!building(state))
|
|
1289
|
-
state.lookedAhead = true;
|
|
1290
|
-
planningAhead.add(state);
|
|
1291
|
-
}
|
|
1292
|
-
try {
|
|
1293
|
-
await tick();
|
|
1294
|
-
}
|
|
1295
|
-
finally {
|
|
1296
|
-
for (const state of tracked)
|
|
1297
|
-
planningAhead.delete(state);
|
|
1298
|
-
}
|
|
1299
|
-
return tracked;
|
|
1300
|
-
});
|
|
1301
|
-
return [...new Set(states)].map(statusOf);
|
|
1302
|
-
},
|
|
1303
|
-
async plannedPulse(rowId) {
|
|
1304
|
-
const found = rowOf(rowId);
|
|
1305
|
-
if (found === undefined)
|
|
1306
|
-
return undefined;
|
|
1307
|
-
const { state, index } = found;
|
|
1308
|
-
const { status, jobs } = describe(state);
|
|
1309
|
-
const entry = status.planned[index - 1];
|
|
1310
|
-
if (entry === undefined)
|
|
1311
|
-
return undefined;
|
|
1312
|
-
const tip = tipEntry(state);
|
|
1313
|
-
const pulse = { id: rowId, module: tip.moduleName, plainFile: tip.plainFile, title: entry.title, track: entry.track, cases: entry.cases, index, lookedAhead: state.lookedAhead === true };
|
|
1314
|
-
const job = jobs[index - 1];
|
|
1315
|
-
const why = (text) => ({ ...pulse, why: text });
|
|
1316
|
-
if (entry.planning === true)
|
|
1317
|
-
return why("It is being planned now: its prompt is built once the plan is made.");
|
|
1318
|
-
if (entry.afterCode === true || job === undefined)
|
|
1319
|
-
return why("It is not planned yet: the conformance tests are planned into pulses once the module's code is built, and their prompt is built from that code.");
|
|
1320
|
-
if (state.running !== undefined)
|
|
1321
|
-
return why(`Pulse ${state.running.jobId} is running in this codebase: what this pulse is given depends on what that one lands.`);
|
|
1322
|
-
if (index > 1)
|
|
1323
|
-
return why(`It follows ${index - 1} planned pulse${index === 2 ? "" : "s"} here: its prompt depends on what ${index === 2 ? "that one lands" : "they land"}, and is built when it starts.`);
|
|
1324
|
-
if (job.track === "conformance")
|
|
1325
|
-
return why("A conformance pulse's prompt is built from what the code it tests holds once it is built: it is not shown before.");
|
|
1326
|
-
// The plan as kept, and only while it fits the ***plain as it is now - else regenerate would plan again.
|
|
1327
|
-
let spec;
|
|
1328
|
-
try {
|
|
1329
|
-
spec = chainSpec(state.chain);
|
|
1330
|
-
}
|
|
1331
|
-
catch (error) {
|
|
1332
|
-
return why(`Its ***plain does not parse now: ${error instanceof Error ? error.message : String(error)}`);
|
|
1333
|
-
}
|
|
1334
|
-
if (state.plan === undefined || !state.plan.jobs.includes(job) || state.plan.specKey !== keyOf(spec)) {
|
|
1335
|
-
return why("The ***plain changed since it was planned: regenerate would plan it again. Look ahead again to see the new plan.");
|
|
1336
|
-
}
|
|
1337
|
-
const task = await withModuleConfig(state, () => promptOf({ plainFile: tip.plainFile, spec: { ...spec, tree: job.step.tree }, planned: job }));
|
|
1338
|
-
return task !== undefined ? { ...pulse, task } : why("It has no prompt to show.");
|
|
1339
|
-
},
|
|
1340
|
-
async regenerateAgain(plainFile, given, request = {}) {
|
|
1341
|
-
return preparingFor(plainFile, async () => {
|
|
1342
|
-
const asked = resolve(options.cwd, plainFile);
|
|
1343
|
-
const own = resolveRequiresChain(asked, [], undefined, { allowNoFunctionalities: true });
|
|
1344
|
-
const module = tipOf(own).moduleName;
|
|
1345
|
-
const funcIds = funcIdsNamed(module, [...new Set(Array.isArray(given) ? given : [given])]);
|
|
1346
|
-
const chains = chainsFor(asked);
|
|
1347
|
-
for (const chain of chains) {
|
|
1348
|
-
const tip = tipOf(chain);
|
|
1349
|
-
if (modules.get(tip.buildDir)?.running !== undefined)
|
|
1350
|
-
throw new Error(`${tip.moduleName} has a pulse running: ask again once it is done.`);
|
|
1351
|
-
}
|
|
1352
|
-
const found = new Set();
|
|
1353
|
-
for (const chain of chains) {
|
|
1354
|
-
const tip = tipOf(chain);
|
|
1355
|
-
const record = readRecord(tip.buildDir);
|
|
1356
|
-
if (record === null)
|
|
1357
|
-
continue;
|
|
1358
|
-
const section = tip.moduleName === module ? FUNCTIONAL_REQUIREMENTS : REQUIRED_FUNCTIONAL_SPECS;
|
|
1359
|
-
const items = record[section] ?? [];
|
|
1360
|
-
const named = (item) => (section === FUNCTIONAL_REQUIREMENTS || item.module === module ? (item.id ?? "") : "");
|
|
1361
|
-
const taken = items.flatMap((item) => (funcIds.includes(named(item)) ? [named(item)] : []));
|
|
1362
|
-
if (taken.length === 0)
|
|
1363
|
-
continue;
|
|
1364
|
-
for (const funcId of taken)
|
|
1365
|
-
found.add(funcId);
|
|
1366
|
-
const marked = items.map((item) => (funcIds.includes(named(item)) ? { ...item, [REGENERATE_AGAIN]: true } : item));
|
|
1367
|
-
writeCodeRecord(tip.buildDir, { ...record, [section]: marked });
|
|
1368
|
-
// Its conformance tests were written against the code being replaced: marked with it, in the tests record of the
|
|
1369
|
-
// same codebase - the tip's suite holds the chain's - they are written again, checked against the new code, and
|
|
1370
|
-
// rewritten where they relied on what the old code chose, once it lands.
|
|
1371
|
-
const testsDir = conformanceDirFor(tip.moduleName, modulesRoot(projectDirOf(tip.plainFile)));
|
|
1372
|
-
const tests = readRecord(testsDir);
|
|
1373
|
-
const tested = tests?.[section] ?? [];
|
|
1374
|
-
if (tested.some((item) => taken.includes(named(item)))) {
|
|
1375
|
-
const again = tested.map((item) => (taken.includes(named(item)) ? { ...item, [REGENERATE_AGAIN]: true } : item));
|
|
1376
|
-
writeTestsRecord(testsDir, { ...tests, [section]: again });
|
|
1377
|
-
}
|
|
1378
|
-
recordHistory(tip.buildDir, `${namesOf(module, taken)} to regenerate again`);
|
|
1379
|
-
}
|
|
1380
|
-
const missing = funcIds.filter((funcId) => !found.has(funcId));
|
|
1381
|
-
if (found.size === 0)
|
|
1382
|
-
throw new Error(`${namesOf(module, missing)} ${missing.length === 1 ? "is" : "are"} not built anywhere, so there is nothing to regenerate again: regenerate builds what is not built.`);
|
|
1383
|
-
const statuses = await loop.bringUp(plainFile, request);
|
|
1384
|
-
if (missing.length > 0)
|
|
1385
|
-
reportActivity(` ${namesOf(module, missing)} ${missing.length === 1 ? "is" : "are"} not built anywhere - nothing to regenerate again there`);
|
|
1386
|
-
return statuses;
|
|
1387
|
-
});
|
|
1388
|
-
},
|
|
1389
|
-
drift(plainFile) {
|
|
1390
|
-
const file = resolve(options.cwd, plainFile);
|
|
1391
|
-
return withParseCache(() => chainsFor(file).flatMap((chain) => toBuild(chain).map((entry) => {
|
|
1392
|
-
const codebase = chain.slice(0, chain.indexOf(entry) + 1);
|
|
1393
|
-
const tip = tipOf(codebase);
|
|
1394
|
-
// The codebase as the loop knows it, or - never asked for - as its records have it.
|
|
1395
|
-
const state = modules.get(tip.buildDir) ?? { chain: codebase };
|
|
1396
|
-
return withModuleConfig(state, () => {
|
|
1397
|
-
const report = { module: tip.moduleName, plainFile: tip.plainFile, code: undefined, conformance: undefined, ...(conformanceTestsOn(tip.plainFile) ? {} : { conformanceOff: true }) };
|
|
1398
|
-
let spec;
|
|
1399
|
-
try {
|
|
1400
|
-
spec = chainSpec(codebase);
|
|
1401
|
-
}
|
|
1402
|
-
catch (error) {
|
|
1403
|
-
return { ...report, why: `its spec does not parse: ${error instanceof Error ? error.message : String(error)}` };
|
|
1404
|
-
}
|
|
1405
|
-
// A pure rename is no work: shown as one, and the work worked out as though it were made.
|
|
1406
|
-
const record = readRecord(tip.buildDir);
|
|
1407
|
-
const renamed = record === null ? undefined : pureRenames(record, readRecord(testsDirOf(state)), spec.tree, tip.moduleName);
|
|
1408
|
-
if (renamed !== undefined && renamed.renames.length > 0)
|
|
1409
|
-
report.renames = renamed.renames.map(renameText);
|
|
1410
|
-
const from = renamed?.code !== undefined && renamed.code !== null ? codeTree(renamed.code) : builtOf(state);
|
|
1411
|
-
const fresh = tip.requires === null && !started(tip);
|
|
1412
|
-
// A codebase that requires nothing starts from its base folder: one changed since, or missing, is said.
|
|
1413
|
-
const base = tip.requires === null ? baseFolderDrift(tip.buildDir, tip.plainFile) : undefined;
|
|
1414
|
-
if (base !== undefined)
|
|
1415
|
-
report.baseFolder = base;
|
|
1416
|
-
const code = codeWork(from, spec.tree);
|
|
1417
|
-
report.code = code.length === 0 ? null : casesOf(from, code, { fresh, module: tip.moduleName });
|
|
1418
|
-
if (conformanceWanted(state, spec)) {
|
|
1419
|
-
const tested = renamed?.tests ?? testedOf(state);
|
|
1420
|
-
// Against the code record as renamed, when a rename is to be made: the tests follow it.
|
|
1421
|
-
const tests = renamed !== undefined && renamed.renames.length > 0
|
|
1422
|
-
? changesBetween(serializeTree(tested), serializeTree(conformanceTarget(renamed.code, tested, spec.tree)))
|
|
1423
|
-
: workOf("conformance", tested, state, spec, false);
|
|
1424
|
-
report.conformance = tests.length === 0 ? null : casesOf(tested, tests, { module: tip.moduleName });
|
|
1425
|
-
// Narrowed by conform to the functional specs it named: the others wait, and why is said.
|
|
1426
|
-
const only = state.conformanceOnly;
|
|
1427
|
-
if (only !== undefined && tests.length > 0)
|
|
1428
|
-
report.conformanceOnly = [...only.specs].map((key) => (key.startsWith(":") ? `${tip.moduleName}${key}` : key));
|
|
1429
|
-
}
|
|
1430
|
-
if (state.running !== undefined)
|
|
1431
|
-
report.running = { jobId: state.running.jobId, title: state.running.planned.title };
|
|
1432
|
-
const halted = state.held?.why ?? state.halted?.why ?? state.conformanceHalted?.why;
|
|
1433
|
-
if (halted !== undefined)
|
|
1434
|
-
report.why = halted;
|
|
1435
|
-
else {
|
|
1436
|
-
// Its scenarios untested for a step of adding tests it skipped: said, as the loop says it.
|
|
1437
|
-
const gap = gapOf(state, spec);
|
|
1438
|
-
if (gap !== undefined)
|
|
1439
|
-
report.why = `waiting for its ${gap.step}: ${gap.text}`;
|
|
1440
|
-
}
|
|
1441
|
-
if (state.startOver !== undefined)
|
|
1442
|
-
report.startOver = state.startOver;
|
|
1443
|
-
const old = oldCodebases(codebase);
|
|
1444
|
-
if (old.length > 0)
|
|
1445
|
-
report.startOver = { requires: [], codebases: old.map((entry) => entry.moduleName), old: true };
|
|
1446
|
-
return report;
|
|
1447
|
-
});
|
|
1448
|
-
})));
|
|
1449
|
-
},
|
|
1450
|
-
async conformance(plainFile, request = {}) {
|
|
1451
|
-
const file = resolve(options.cwd, plainFile);
|
|
1452
|
-
asked.set(file, { ...ahead.get(file), ...asked.get(file), ...(request.model !== undefined ? { model: request.model } : {}) });
|
|
1453
|
-
ahead.delete(file);
|
|
1454
|
-
const own = resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true });
|
|
1455
|
-
const self = tipOf(own);
|
|
1456
|
-
// What the person asks for comes first. Its tests are written in its own codebase, before anything is built on it:
|
|
1457
|
-
// a codebase built on it - by a module above - is disposable, and is deleted, a pulse running there stopped first;
|
|
1458
|
-
// the module above is regenerated from it once they pass. Only when there are tests to write: asked again for tests
|
|
1459
|
-
// it has, nothing is touched.
|
|
1460
|
-
if (!conformanceTestsOn(self.plainFile)) {
|
|
1461
|
-
throw new Error(`Conformance tests are off for ${self.moduleName} (conformance-tests: false, or unset): nothing is conformance tested. ` +
|
|
1462
|
-
"/conform in the chat turns them on, or conformance-tests: true in config.turri.yaml. Nothing was started.");
|
|
1463
|
-
}
|
|
1464
|
-
// Refused before anything is touched: a functional spec not there, nothing to test, or a step of adding tests skipped.
|
|
1465
|
-
const { named, spec: ownSpec, withScenarios } = conformanceAskedIn(own, request.funcIds);
|
|
1466
|
-
const scratch = request.fromScratch;
|
|
1467
|
-
if (scratch !== undefined && named !== undefined && named.length > 0) {
|
|
1468
|
-
throw new Error("Name functional specs or ask for the conformance tests from scratch, not both: from scratch writes every one of them again. Nothing was started.");
|
|
1469
|
-
}
|
|
1470
|
-
// Written already, and asked for again: the named ones written anew where they are tested; from scratch, the module's
|
|
1471
|
-
// tests folder taken out - and started again from the module it requires, unless the whole chain's are asked for.
|
|
1472
|
-
const again = named !== undefined && named.length > 0 ? conformAgain(file, self, named) : [];
|
|
1473
|
-
if (scratch !== undefined)
|
|
1474
|
-
testsFromScratch(file, scratch === "module");
|
|
1475
|
-
const tested = new Set((readRecord(conformanceDirFor(self.moduleName, modulesRoot(projectDirOf(self.plainFile))))?.[FUNCTIONAL_REQUIREMENTS] ?? []).map((item) => item.id));
|
|
1476
|
-
const toWrite = (named !== undefined && named.length > 0 ? named : withScenarios).some((funcId) => !tested.has(funcId));
|
|
1477
|
-
let wentBack = false;
|
|
1478
|
-
// From scratch, the tests are written again at the tips, where they were: nothing built on the module is touched.
|
|
1479
|
-
if (scratch === undefined && readRecord(self.buildDir) !== null && toWrite) {
|
|
1480
|
-
const why = `${self.moduleName}'s conformance tests were asked for, and they come before anything is built on it`;
|
|
1481
|
-
for (const chain of builtTips(file)) {
|
|
1482
|
-
const above = chain.slice(chain.findIndex((entry) => entry.buildDir === self.buildDir) + 1);
|
|
1483
|
-
if (above.length === 0)
|
|
1484
|
-
continue;
|
|
1485
|
-
wentBack = true;
|
|
1486
|
-
for (const entry of above) {
|
|
1487
|
-
const running = modules.get(entry.buildDir)?.running;
|
|
1488
|
-
if (running === undefined) {
|
|
1489
|
-
if (started(entry))
|
|
1490
|
-
discard(entry, why);
|
|
1491
|
-
continue;
|
|
1492
|
-
}
|
|
1493
|
-
if (running.stopping === true && running.discard !== undefined)
|
|
1494
|
-
continue;
|
|
1495
|
-
running.stopping = true;
|
|
1496
|
-
running.discard = why;
|
|
1497
|
-
reportActivity(` ${entry.moduleName}: pulse ${running.jobId} is stopped and its codebase deleted - ${why}`);
|
|
1498
|
-
options.registry.stop(running.jobId, `Stopped because you asked for ${self.moduleName}'s conformance tests: they come before anything is built on it. ` +
|
|
1499
|
-
`${entry.moduleName}'s codebase is deleted, and it is regenerated from ${self.moduleName} once they pass.`);
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
const tracked = withParseCache(() => (wentBack ? [own] : chainsFor(file)).flatMap((chain) => toBuild(chain).map((entry) => track(chain.slice(0, chain.indexOf(entry) + 1), request, true))));
|
|
1504
|
-
// The module asked for, in its own codebase - and those below it: never the codebases built on it.
|
|
1505
|
-
const asking = tracked.find((state) => tipEntry(state).buildDir === self.buildDir);
|
|
1506
|
-
const states = asking !== undefined ? tracked.filter((state) => own.some((entry) => entry.buildDir === tipEntry(state).buildDir)) : tracked;
|
|
1507
|
-
const tip = asking ?? states.at(-1);
|
|
1508
|
-
// Asked for: what a look ahead held here goes on - the modules below with it, or the module waits for them for ever.
|
|
1509
|
-
for (const state of tracked)
|
|
1510
|
-
state.lookedAhead = undefined;
|
|
1511
|
-
const asks = named !== undefined && named.length > 0 ? named : undefined;
|
|
1512
|
-
// Its tests are written already, and a codebase built on it holds its code: nothing to write, nothing touched.
|
|
1513
|
-
if (asking === undefined && asks !== undefined && tip !== undefined && again.length === 0) {
|
|
1514
|
-
throw new Error(`${self.moduleName}'s conformance tests for ${namesOf(self.moduleName, asks)} are written already. Nothing was started.`);
|
|
1515
|
-
}
|
|
1516
|
-
// Only the module asked for: one job for all of its tests, or one a functional spec, as this request asks; a halt cleared.
|
|
1517
|
-
for (const state of tip !== undefined ? [tip] : []) {
|
|
1518
|
-
const separately = request.separately === true;
|
|
1519
|
-
if ((state.conformanceSeparately === true) !== separately)
|
|
1520
|
-
state.conformancePlan = undefined;
|
|
1521
|
-
state.conformanceSeparately = separately;
|
|
1522
|
-
// Named: their tests alone - the others left as they are until the module is asked for again, or conform names none.
|
|
1523
|
-
state.conformanceOnly = asks !== undefined ? namedOnly(state, asks, self.moduleName) : undefined;
|
|
1524
|
-
state.conformancePlan = undefined;
|
|
1525
|
-
state.conformanceHalted = undefined;
|
|
1526
|
-
state.halted = undefined;
|
|
1527
|
-
state.held = undefined;
|
|
1528
|
-
}
|
|
1529
|
-
await tick();
|
|
1530
|
-
return [...new Set(states)].map((state) => {
|
|
1531
|
-
const status = statusOf(state);
|
|
1532
|
-
const writing = status.running !== undefined || status.planned.some((job) => job.track === "conformance");
|
|
1533
|
-
if (state !== tip || writing)
|
|
1534
|
-
return status;
|
|
1535
|
-
return {
|
|
1536
|
-
...status,
|
|
1537
|
-
conformanceNote: asks !== undefined
|
|
1538
|
-
? `the conformance tests of ${namesOf(status.module, asks)} are written for ${asks.length === 1 ? "it" : "them"} as built: there is nothing to write`
|
|
1539
|
-
: `the conformance tests of ${status.module} are written for every functional spec with scenarios, as built: there is nothing to write`,
|
|
1540
|
-
};
|
|
1541
|
-
});
|
|
1542
|
-
},
|
|
1543
|
-
async startOver(plainFile, request = {}) {
|
|
1544
|
-
const file = resolve(options.cwd, plainFile);
|
|
1545
|
-
const own = resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true });
|
|
1546
|
-
const rebuild = new Map();
|
|
1547
|
-
for (const chain of [...chainsFor(file), own]) {
|
|
1548
|
-
const fresh = newlyRequired(chain);
|
|
1549
|
-
for (const entry of fresh?.rebuild ?? [])
|
|
1550
|
-
rebuild.set(entry.buildDir, { entry, requires: fresh.modules });
|
|
1551
|
-
}
|
|
1552
|
-
if (rebuild.size === 0) {
|
|
1553
|
-
// Built when functional specs were numbered: the whole chain is regenerated from scratch.
|
|
1554
|
-
if ([...chainsFor(file), own].some((chain) => oldCodebases(chain).length > 0))
|
|
1555
|
-
return loop.fromScratch(plainFile, { ...request, chain: true });
|
|
1556
|
-
throw new Error(`Nothing of ${tipOf(own).moduleName} has to be started over: its code is built on every module it requires.`);
|
|
1557
|
-
}
|
|
1558
|
-
for (const { entry } of rebuild.values()) {
|
|
1559
|
-
if (modules.get(entry.buildDir)?.running !== undefined)
|
|
1560
|
-
throw new Error(`${entry.moduleName} has a pulse running: ask again once it is done.`);
|
|
1561
|
-
}
|
|
1562
|
-
for (const { entry, requires } of rebuild.values())
|
|
1563
|
-
startAgain(entry, `it now requires ${requires.join(", ")}, which its code was not built on`);
|
|
1564
|
-
return loop.bringUp(plainFile, request);
|
|
1565
|
-
},
|
|
1566
|
-
async fromScratch(plainFile, { chain, ...request } = {}) {
|
|
1567
|
-
return preparingFor(plainFile, async () => {
|
|
1568
|
-
const file = resolve(options.cwd, plainFile);
|
|
1569
|
-
// Where its code lives: the tips its module is built in, or - none built yet - its own codebase. The whole chain:
|
|
1570
|
-
// every codebase in those chains, bottom first - a tip taken back to nothing is otherwise started from a copy of
|
|
1571
|
-
// the code below it.
|
|
1572
|
-
const chains = chainsFor(file);
|
|
1573
|
-
const codebases = [...new Map((chain === true ? chains.flat() : chains.map(tipOf)).map((entry) => [entry.buildDir, entry])).values()];
|
|
1574
|
-
for (const entry of codebases) {
|
|
1575
|
-
if (modules.get(entry.buildDir)?.running !== undefined)
|
|
1576
|
-
throw new Error(`${entry.moduleName} has a pulse running: halt it, or ask again once it is done.`);
|
|
1577
|
-
}
|
|
1578
|
-
const why = chain === true ? "asked to be regenerated from scratch, with its whole chain" : "asked to be regenerated from scratch";
|
|
1579
|
-
for (const entry of codebases)
|
|
1580
|
-
if (started(entry))
|
|
1581
|
-
startAgain(entry, why);
|
|
1582
|
-
return loop.bringUp(plainFile, request);
|
|
1583
|
-
});
|
|
1584
|
-
},
|
|
1585
|
-
halt(target, reason) {
|
|
1586
|
-
const named = target.trim();
|
|
1587
|
-
// A planned row's module - the longest name its id starts with, as a name may hold a hyphen - or a module by its name.
|
|
1588
|
-
const state = order
|
|
1589
|
-
.map((key) => modules.get(key))
|
|
1590
|
-
.filter((candidate) => {
|
|
1591
|
-
const name = tipEntry(candidate).moduleName;
|
|
1592
|
-
return named === name || named.startsWith(`planned-${name}-`);
|
|
1593
|
-
})
|
|
1594
|
-
.sort((a, b) => tipEntry(b).moduleName.length - tipEntry(a).moduleName.length)[0];
|
|
1595
|
-
if (state === undefined)
|
|
1596
|
-
return undefined;
|
|
1597
|
-
const tip = tipEntry(state);
|
|
1598
|
-
if (state.running === undefined && !existsSync(tip.plainFile)) {
|
|
1599
|
-
forget(state);
|
|
1600
|
-
asked.delete(tip.plainFile);
|
|
1601
|
-
return `${tip.moduleName} is no longer in the project - ${basename(tip.plainFile)} is gone - so nothing was to be built there: it is dropped from the regeneration.`;
|
|
1602
|
-
}
|
|
1603
|
-
const planned = statusOf(state).planned.length;
|
|
1604
|
-
const said = reason !== undefined && reason.trim() !== "" ? ` (${reason.trim()})` : "";
|
|
1605
|
-
state.held = { why: `you halted it${said} - nothing runs here until it is asked for again` };
|
|
1606
|
-
state.why = state.held.why;
|
|
1607
|
-
state.waitsFor = undefined;
|
|
1608
|
-
state.plan = undefined;
|
|
1609
|
-
state.conformancePlan = undefined;
|
|
1610
|
-
const running = state.running;
|
|
1611
|
-
if (running !== undefined && running.stopping !== true) {
|
|
1612
|
-
running.stopping = true;
|
|
1613
|
-
options.registry.stop(running.jobId, `Halted by you${said}: what it had done is rolled back, and nothing more runs in ${tip.moduleName} until it is asked for again.`);
|
|
1614
|
-
}
|
|
1615
|
-
const above = order
|
|
1616
|
-
.map((key) => modules.get(key))
|
|
1617
|
-
.filter((other) => other !== state && looking.has(other) && other.chain.some((entry) => entry.buildDir === tip.buildDir))
|
|
1618
|
-
.map((other) => tipEntry(other).moduleName);
|
|
1619
|
-
void tick();
|
|
1620
|
-
return [
|
|
1621
|
-
`Halted ${tip.moduleName}${said}:`,
|
|
1622
|
-
running !== undefined ? ` its running pulse ${running.jobId} is being stopped, and what it had done rolled back;` : "",
|
|
1623
|
-
planned > 0 ? ` its ${planned} planned pulse${planned === 1 ? "" : "s"} will not start.` : " nothing more is planned there.",
|
|
1624
|
-
" Pulses that landed stay.",
|
|
1625
|
-
above.length > 0 ? ` ${above.join(", ")} ${above.length === 1 ? "waits" : "wait"} for it.` : "",
|
|
1626
|
-
` It runs again only when asked for - regenerate ${basename(tip.plainFile)} - a spec change does not start it.`,
|
|
1627
|
-
].join("");
|
|
1628
|
-
},
|
|
1629
|
-
status() {
|
|
1630
|
-
return [...order.map((key) => statusOf(modules.get(key))), ...preparingAlone().map(({ since: _since, ...status }) => status)];
|
|
1631
|
-
},
|
|
1632
|
-
planned() {
|
|
1633
|
-
const now = Date.now();
|
|
1634
|
-
let sequence = Number.MAX_SAFE_INTEGER;
|
|
1635
|
-
// The last job - running or planned - of each module, by name: what a module waiting for it waits behind.
|
|
1636
|
-
const lastOf = new Map();
|
|
1637
|
-
// A module asked for that the loop holds nothing of yet: being planned, from the moment it was asked for.
|
|
1638
|
-
const early = preparingAlone().map(({ module: name, since }) => ({
|
|
1639
|
-
id: `planned-${name}-preparing`,
|
|
1640
|
-
kind: "regenerate",
|
|
1641
|
-
summary: `${name}.plain - being planned`,
|
|
1642
|
-
module: name,
|
|
1643
|
-
note: "Being planned into pulses now. The first starts as soon as the plan is made.",
|
|
1644
|
-
status: "queued",
|
|
1645
|
-
sequence: sequence--,
|
|
1646
|
-
queuedAt: since,
|
|
1647
|
-
startedAt: since,
|
|
1648
|
-
waitingOn: [],
|
|
1649
|
-
tail: "",
|
|
1650
|
-
activity: [],
|
|
1651
|
-
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 },
|
|
1652
|
-
agents: [],
|
|
1653
|
-
transcript: [],
|
|
1654
|
-
planning: { since },
|
|
1655
|
-
}));
|
|
1656
|
-
return [...early, ...order.flatMap((key) => {
|
|
1657
|
-
const state = modules.get(key);
|
|
1658
|
-
const tip = tipEntry(state);
|
|
1659
|
-
const status = statusOf(state);
|
|
1660
|
-
let before = status.running?.jobId;
|
|
1661
|
-
if (before !== undefined)
|
|
1662
|
-
lastOf.set(tip.moduleName, before);
|
|
1663
|
-
// Looked ahead at: every row of it says it waits for the module to be asked for.
|
|
1664
|
-
const held = state.lookedAhead === true && state.running === undefined;
|
|
1665
|
-
const row = (id, summary, note, waitingOn, conformance = false) => ({
|
|
1666
|
-
id,
|
|
1667
|
-
kind: conformance ? "conformance" : "regenerate",
|
|
1668
|
-
summary,
|
|
1669
|
-
module: tip.moduleName,
|
|
1670
|
-
note: held ? `${LOOKED_AHEAD_NOTE} ${note}` : note,
|
|
1671
|
-
...(held ? { lookedAhead: true } : {}),
|
|
1672
|
-
...(state.model !== undefined ? { model: state.model } : {}),
|
|
1673
|
-
status: "queued",
|
|
1674
|
-
sequence: sequence--,
|
|
1675
|
-
queuedAt: now,
|
|
1676
|
-
startedAt: now,
|
|
1677
|
-
waitingOn,
|
|
1678
|
-
tail: "",
|
|
1679
|
-
activity: [],
|
|
1680
|
-
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 },
|
|
1681
|
-
agents: [],
|
|
1682
|
-
transcript: [],
|
|
1683
|
-
});
|
|
1684
|
-
// Waiting for the module below it: not planned yet, but in the queue all the same - behind what it waits for.
|
|
1685
|
-
if (state.running === undefined && state.waitsFor !== undefined) {
|
|
1686
|
-
const behind = lastOf.get(state.waitsFor);
|
|
1687
|
-
const id = `planned-${tip.moduleName}-waiting`;
|
|
1688
|
-
lastOf.set(tip.moduleName, id);
|
|
1689
|
-
return [
|
|
1690
|
-
row(id, `${basename(tip.plainFile)} - waits for ${state.waitsFor}`, `Not planned yet: its work is planned into pulses once ${state.waitsFor} is built - the code it is built on.`, behind !== undefined ? [behind] : []),
|
|
1691
|
-
];
|
|
1692
|
-
}
|
|
1693
|
-
return status.planned.map((job, index) => {
|
|
1694
|
-
const planned = row(`planned-${tip.moduleName}-${index + 1}`, `${basename(tip.plainFile)} ${job.track === "conformance" ? "conformance: " : ""}${job.title}`, job.afterCode === true
|
|
1695
|
-
? `Not planned yet: the conformance tests${job.specs !== undefined && job.specs.length > 0 ? ` of ${job.specs.join(", ")}` : ""} are planned into pulses once the module's code is built.`
|
|
1696
|
-
: job.planning === true
|
|
1697
|
-
? `Being planned into pulses now: ${job.title}. The first starts as soon as the plan is made.`
|
|
1698
|
-
: `Planned, not started: ${casesText(job.cases)}. It is planned again whenever the spec changes or a pulse before it ends.`, before !== undefined ? [before] : [], job.track === "conformance");
|
|
1699
|
-
if (job.planning === true)
|
|
1700
|
-
planned.planning = { since: state.planningSince ?? preparing.get(tip.moduleName)?.since ?? now };
|
|
1701
|
-
before = planned.id;
|
|
1702
|
-
lastOf.set(tip.moduleName, planned.id);
|
|
1703
|
-
return planned;
|
|
1704
|
-
});
|
|
1705
|
-
})];
|
|
1706
|
-
},
|
|
1707
|
-
mapPlan() {
|
|
1708
|
-
return {
|
|
1709
|
-
files: [...asked.keys(), ...[...ahead.keys()].filter((file) => !asked.has(file))],
|
|
1710
|
-
codebases: order.map((key) => {
|
|
1711
|
-
const state = modules.get(key);
|
|
1712
|
-
const tip = tipEntry(state);
|
|
1713
|
-
const { jobs, ahead } = describe(state);
|
|
1714
|
-
const running = state.running;
|
|
1715
|
-
let next = running?.number ?? state.pulses ?? 0;
|
|
1716
|
-
const pulses = [
|
|
1717
|
-
...(running !== undefined
|
|
1718
|
-
? [{ number: running.number, title: running.planned.title, track: running.planned.track, running: true, rowId: running.jobId, before: serializeTree(running.from), after: serializeTree(running.after) }]
|
|
1719
|
-
: []),
|
|
1720
|
-
...jobs.flatMap((job, index) => {
|
|
1721
|
-
const rowId = `planned-${tip.moduleName}-${index + 1}`;
|
|
1722
|
-
// The conformance tests that follow the code still to build: numbered among the rest, their functional specs by name.
|
|
1723
|
-
const following = ahead[index];
|
|
1724
|
-
if (following !== undefined)
|
|
1725
|
-
return [{ number: (next += 1), title: following.title, track: "conformance", running: false, rowId, before: "", after: "", specs: following.specs }];
|
|
1726
|
-
return job === undefined ? [] : [{ number: (next += 1), title: job.title, track: job.track, running: false, rowId, before: job.step.before, after: job.step.after }];
|
|
1727
|
-
}),
|
|
1728
|
-
];
|
|
1729
|
-
const gaveUp = running === undefined && state.why === NO_PLAN ? { why: NO_PLAN } : undefined;
|
|
1730
|
-
const stuck = running === undefined && state.halted !== undefined ? { why: state.halted.why, ...(state.halted.pulse !== undefined ? { pulse: state.halted.pulse } : {}), ...(state.halted.cause !== undefined ? { cause: state.halted.cause } : {}) } : gaveUp;
|
|
1731
|
-
return {
|
|
1732
|
-
module: tip.moduleName,
|
|
1733
|
-
plainFile: tip.plainFile,
|
|
1734
|
-
buildDir: tip.buildDir,
|
|
1735
|
-
pulses,
|
|
1736
|
-
conformance: testedFuncIds(state.seen?.tree).length > 0,
|
|
1737
|
-
...(state.planning !== undefined ? { planning: state.planning } : {}),
|
|
1738
|
-
...(running === undefined && state.waitsFor !== undefined ? { waitsFor: state.waitsFor } : {}),
|
|
1739
|
-
...(running === undefined && state.why !== undefined ? { why: state.why } : {}),
|
|
1740
|
-
...(stuck !== undefined ? { stuck } : {}),
|
|
1741
|
-
};
|
|
1742
|
-
}),
|
|
1743
|
-
};
|
|
1744
|
-
},
|
|
1745
|
-
async drain() {
|
|
1746
|
-
for (;;) {
|
|
1747
|
-
// A pulse that settles meanwhile ticks again: its next pulse is started by that tick, so it is waited for too.
|
|
1748
|
-
const looking = ticking;
|
|
1749
|
-
await looking;
|
|
1750
|
-
if (looking !== ticking)
|
|
1751
|
-
continue;
|
|
1752
|
-
const running = order.map((key) => modules.get(key).running?.jobId).filter((id) => id !== undefined);
|
|
1753
|
-
if (running.length === 0)
|
|
1754
|
-
return;
|
|
1755
|
-
await Promise.all(running.map((id) => options.registry.wait(id).catch(() => undefined)));
|
|
1756
|
-
// Its settling ticks: let it start what comes next before looking again.
|
|
1757
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1758
|
-
}
|
|
1759
|
-
},
|
|
1760
|
-
};
|
|
1761
|
-
return loop;
|
|
1762
|
-
}
|
|
1763
|
-
/** The codebases of a chain built when functional specs were numbered, before func-ids: their code or tests record is old. */
|
|
1764
|
-
function oldCodebases(chain) {
|
|
1765
|
-
return chain.filter((entry) => isOldRecord(readRecord(entry.buildDir)) || isOldRecord(readRecord(conformanceDirFor(entry.moduleName, modulesRoot(projectDirOf(entry.plainFile))))));
|
|
1766
|
-
}
|
|
1767
|
-
/** Why nothing is built on codebases with old records. */
|
|
1768
|
-
const OLD_RECORDS_WHY = (codebases) => `${codebases.join(", ")} ${codebases.length === 1 ? "was" : "were"} built when functional specs were numbered, before they had func-ids: nothing more is built on ${codebases.length === 1 ? "it" : "them"} - the whole chain is regenerated from scratch once you agree`;
|
|
1769
|
-
/** Why nothing runs in a codebase whose code - and conformance tests, where they are wanted - is built from its spec as it is. */
|
|
1770
|
-
export const UP_TO_DATE = "built from the ***plain as it is";
|
|
1771
|
-
/** Why nothing starts in a codebase a look ahead planned: its pulses wait for the module to be asked for. */
|
|
1772
|
-
const LOOKED_AHEAD = "looked ahead - planned, and nothing starts until regenerate, conform or /regenerate asks for it";
|
|
1773
|
-
/** What a planned row of a codebase a look ahead planned says first. */
|
|
1774
|
-
const LOOKED_AHEAD_NOTE = "Planned by a look ahead: it waits for regenerate, conform or /regenerate to start it.";
|
|
1775
|
-
/** Why a codebase held for a look ahead has no plan: its ***plain moved since, and only a look ahead plans it. */
|
|
1776
|
-
const LOOK_AGAIN = "looked ahead, and the ***plain changed since - look ahead again to plan it, or regenerate it";
|
|
1777
|
-
/** Why a codebase with work left has no plan: the planner found none. */
|
|
1778
|
-
/** Why a codebase waits for a testing script being written in the background. */
|
|
1779
|
-
const SCRIPT_BEING_WRITTEN = (what) => `waiting for its ${what}, which is being written`;
|
|
1780
|
-
/** Why a codebase waits where modules name their testing scripts in files of their own and it has none: the note says which file names which. */
|
|
1781
|
-
const NO_OWN_SCRIPT = "waiting for a unit testing script of its own - write one for its stack (implement-unit-testing-script), named in its own config file.";
|
|
1782
|
-
const NO_PLAN = "the planner found no way to cut the work into pulses that hold together";
|
|
1783
|
-
/**
|
|
1784
|
-
* Where the functional specs' test plain files of a module's chain are, by func-id and module - the module's own when none
|
|
1785
|
-
* is named - under `base`, the folder the module's file is named in: as the parse bound them, else where one is to be,
|
|
1786
|
-
* `<test-dir>/<module>/<func-id>.plain`.
|
|
1787
|
-
*/
|
|
1788
|
-
function testPlainPathOf(tree, moduleName, plainFile, base) {
|
|
1789
|
-
const bound = Object.entries(tree[TEST_PLAIN_FILES] ?? {});
|
|
1790
|
-
// Named as the parser names a test plain file, with `/`: the names go into a diff, beside the parser's.
|
|
1791
|
-
const fallback = slashed(relative(dirname(plainFile), testDirOf(plainFile)));
|
|
1792
|
-
return (funcId, module = moduleName) => {
|
|
1793
|
-
const name = bound.find(([, binding]) => binding.module === module && binding.func_id === funcId)?.[0] ?? posix.join(fallback, module, `${funcId}.plain`);
|
|
1794
|
-
return posix.join(base, name);
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
/** A diff's lines placed in the .plain files of a chain - the tip's first - named as they are from the project. */
|
|
1798
|
-
function whereInFiles(diff, chain) {
|
|
1799
|
-
try {
|
|
1800
|
-
// The test plain files too: a conformance pulse's diff has their lines.
|
|
1801
|
-
const files = [...chain].reverse().flatMap((entry) => [...specFilesOf(entry.plainFile), ...testPlainFilesOf(entry.plainFile)]);
|
|
1802
|
-
// A standard library template by its import path, not by where turri happens to be.
|
|
1803
|
-
const nameOf = (path) => slashed(isWithin(path, join(STDLIB_ROOT, "stdlib")) ? relative(STDLIB_ROOT, path) : relative(projectDirOf(chain.at(-1).plainFile), path) || basename(path));
|
|
1804
|
-
const unique = [...new Set(files)].map((path) => ({ name: nameOf(path), text: readFileSync(path, "utf8") }));
|
|
1805
|
-
return locateDiffLines(diff, unique);
|
|
1806
|
-
}
|
|
1807
|
-
catch {
|
|
1808
|
-
return {};
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
/**
|
|
1812
|
-
* The conformance tests' work, a line a functional spec, each with its scenarios counted by case and why else its tests
|
|
1813
|
-
* are behind: "todo:add-task 1 added, 1 changed". What a case is follows from the tests record, by scenario-id: a
|
|
1814
|
-
* scenario added there is new to the tests, one changed reads otherwise, one removed is taken out - and a functional spec
|
|
1815
|
-
* whose code changed under scenarios unchanged has their tests run on the new code.
|
|
1816
|
-
*/
|
|
1817
|
-
function conformanceLines(module, cases) {
|
|
1818
|
-
const name = (touched) => `${touched.module ?? module}:${touched.funcId}`;
|
|
1819
|
-
const why = { text: "its code changed", again: "its code was regenerated again", concept: "a concept it uses changed" };
|
|
1820
|
-
const counted = (spec) => {
|
|
1821
|
-
const parts = [
|
|
1822
|
-
...(spec.added.length > 0 ? [`${spec.added.length} added`] : []),
|
|
1823
|
-
...(spec.changed.length > 0 ? [`${spec.changed.length} changed`] : []),
|
|
1824
|
-
...(spec.removed.length > 0 ? [`${spec.removed.length} removed`] : []),
|
|
1825
|
-
...(spec.rewritten.length > 0 ? [`written again from scratch - ${spec.rewritten.length} to write anew`] : []),
|
|
1826
|
-
...(spec.codeChanged !== undefined ? [`${why[spec.codeChanged]} - ${spec.unchanged.length} to run on it`] : []),
|
|
1827
|
-
];
|
|
1828
|
-
return parts.length > 0 ? parts.join(", ") : "its text changed";
|
|
1829
|
-
};
|
|
1830
|
-
const rows = cases.scenarios !== undefined
|
|
1831
|
-
? cases.scenarios.map((spec) => [name(spec), cases.delete.some((gone) => name(gone) === name(spec)) ? `taken out - its tests go (${spec.removed.length} removed)` : counted(spec)])
|
|
1832
|
-
: [
|
|
1833
|
-
...cases.add.map((touched) => [name(touched), "scenarios to write tests for"]),
|
|
1834
|
-
...cases.patch.map((touched) => [name(touched), "its text or its scenarios changed"]),
|
|
1835
|
-
...cases.again.map((touched) => [name(touched), "its code was regenerated again"]),
|
|
1836
|
-
...cases.delete.map((touched) => [name(touched), "taken out - its tests go"]),
|
|
1837
|
-
];
|
|
1838
|
-
if (rows.length === 0)
|
|
1839
|
-
return [" the test reqs or what they are written against changed"];
|
|
1840
|
-
const width = Math.max(...rows.map(([name]) => name.length));
|
|
1841
|
-
return rows.map(([name, why]) => ` ${name.padEnd(width)} ${why}`);
|
|
1842
|
-
}
|
|
1843
|
-
/** Functional specs as a person names them: `module:func-id`, each. */
|
|
1844
|
-
export function namesOf(module, funcIds) {
|
|
1845
|
-
return funcIds.map((funcId) => `${module}:${funcId}`).join(", ");
|
|
1846
|
-
}
|
|
1847
|
-
/** Functional specs of a chain as a person names them: `module:func-id`, each - the codebase's own with `module`. */
|
|
1848
|
-
function refsOf(module, specs) {
|
|
1849
|
-
return specs.map((spec) => `${spec.module ?? module}:${spec.funcId}`).join(", ");
|
|
1850
|
-
}
|
|
1851
|
-
/**
|
|
1852
|
-
* The func-ids a person names in a module, each as `module:func-id` - a bare func-id, or another module's, is refused:
|
|
1853
|
-
* a func-id is unique in its module only.
|
|
1854
|
-
*/
|
|
1855
|
-
export function funcIdsNamed(module, names) {
|
|
1856
|
-
return names.map((name) => {
|
|
1857
|
-
const at = name.lastIndexOf(":");
|
|
1858
|
-
if (at === -1)
|
|
1859
|
-
throw new Error(`Name the functional spec as ${module}:${name} - a func-id with its module. Nothing was done.`);
|
|
1860
|
-
const [named, funcId] = [name.slice(0, at), name.slice(at + 1)];
|
|
1861
|
-
if (named !== module)
|
|
1862
|
-
throw new Error(`${name} is not a functional spec of ${module}: name ${named}'s .plain file for it. Nothing was done.`);
|
|
1863
|
-
return funcId;
|
|
1864
|
-
});
|
|
1865
|
-
}
|
|
1866
|
-
/**
|
|
1867
|
-
* Why conform starts nothing when a step of adding tests is still to take - the test reqs, the conformance testing
|
|
1868
|
-
* script, the scenarios: not a failure but what conform needs first, each step one the chat takes itself.
|
|
1869
|
-
*/
|
|
1870
|
-
export class TestingStepsMissing extends Error {
|
|
1871
|
-
}
|
|
1872
|
-
/**
|
|
1873
|
-
* What conform is asked for in a module, checked from its ***plain alone - quick, before anything is said or touched: the
|
|
1874
|
-
* functional specs named, as func-ids, and the module's spec and those of its functional specs with scenarios. Throws,
|
|
1875
|
-
* saying why nothing was started, when a functional spec named is not there or has no scenarios, when none has any, or
|
|
1876
|
-
* when a step of adding tests is skipped - no test reqs, no conformance testing script. Conformance tests off are not
|
|
1877
|
-
* checked: the conform tool is refused for that, and /conform turns them on.
|
|
1878
|
-
*/
|
|
1879
|
-
function conformanceAskedIn(own, funcIds) {
|
|
1880
|
-
const self = tipOf(own);
|
|
1881
|
-
const named = funcIds === undefined ? undefined : funcIdsNamed(self.moduleName, [...new Set(funcIds)]);
|
|
1882
|
-
const spec = chainSpec(own).tree;
|
|
1883
|
-
const withScenarios = testedFuncIds(spec);
|
|
1884
|
-
// No scenarios: the steps still to take, from the first one missing - the test reqs and the script come before them.
|
|
1885
|
-
const toScenarios = () => stepsToScenarios({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
|
|
1886
|
-
if (withScenarios.length === 0) {
|
|
1887
|
-
throw new TestingStepsMissing(`No functional spec of ${self.moduleName} has scenarios - none has a test plain file - so there is nothing to test. ${toScenarios()} ` +
|
|
1888
|
-
"Their tests are written once the code is built. Nothing was started.");
|
|
1889
|
-
}
|
|
1890
|
-
if (named !== undefined && named.length > 0) {
|
|
1891
|
-
const items = spec[FUNCTIONAL_REQUIREMENTS] ?? [];
|
|
1892
|
-
const unknown = named.filter((funcId) => !items.some((item) => item.id === funcId));
|
|
1893
|
-
if (unknown.length > 0)
|
|
1894
|
-
throw new Error(`${self.moduleName} has no functional spec ${namesOf(self.moduleName, unknown)}. Nothing was started.`);
|
|
1895
|
-
const untested = named.filter((funcId) => !hasScenarios(items.find((item) => item.id === funcId)));
|
|
1896
|
-
if (untested.length > 0) {
|
|
1897
|
-
throw new TestingStepsMissing(`${namesOf(self.moduleName, untested)} ${untested.length === 1 ? "has" : "have"} no scenarios - no test plain file - so there is nothing to test. ${toScenarios()} ` +
|
|
1898
|
-
"Their tests are written once the code is built. Nothing was started.");
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
// A step of adding tests skipped - its test reqs, or the conformance testing script: refused, naming it.
|
|
1902
|
-
const gap = testingGap({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
|
|
1903
|
-
if (gap !== undefined)
|
|
1904
|
-
throw new TestingStepsMissing(`${gap.text} Nothing was started.`);
|
|
1905
|
-
return { named, spec, withScenarios };
|
|
1906
|
-
}
|
|
1907
|
-
/**
|
|
1908
|
-
* Why conform would start nothing for a module, from its ***plain alone (`conformanceAskedIn`): undefined when it would
|
|
1909
|
-
* go on. What /conform checks before it says anything. `stepsMissing`: what is missing is a step of adding tests - the
|
|
1910
|
-
* test reqs, the conformance testing script, the scenarios - guidance for the chat, not an error for the person.
|
|
1911
|
-
*/
|
|
1912
|
-
export function conformanceRefusal(plainFile, funcIds) {
|
|
1913
|
-
try {
|
|
1914
|
-
conformanceAskedIn(resolveRequiresChain(resolve(plainFile), [], undefined, { allowNoFunctionalities: true }), funcIds);
|
|
1915
|
-
return undefined;
|
|
1916
|
-
}
|
|
1917
|
-
catch (error) {
|
|
1918
|
-
return { text: error instanceof Error ? error.message : String(error), stepsMissing: error instanceof TestingStepsMissing };
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
/** What a job does, in a few words: its cases, each functional spec by its func-id - with its module, a module below's. */
|
|
1922
|
-
function casesText(cases) {
|
|
1923
|
-
const named = (specs) => specs.map((spec) => (spec.module !== undefined ? `${spec.module}:${spec.funcId}` : spec.funcId)).join(", ");
|
|
1924
|
-
const parts = [
|
|
1925
|
-
...(cases.fresh ? ["sets the project up"] : []),
|
|
1926
|
-
...(cases.add.length > 0 ? [`adds ${named(cases.add)}`] : []),
|
|
1927
|
-
...(cases.patch.length > 0 ? [`changes ${named(cases.patch)}`] : []),
|
|
1928
|
-
...(cases.again.length > 0 ? [`regenerates ${named(cases.again)} again`] : []),
|
|
1929
|
-
...(cases.delete.length > 0 ? [`takes out ${named(cases.delete)}`] : []),
|
|
1930
|
-
];
|
|
1931
|
-
return parts.length > 0 ? parts.join(", ") : "no functional spec - reqs or definitions only";
|
|
1932
|
-
}
|
|
1933
|
-
/**
|
|
1934
|
-
* The coding agent's task for a planned code pulse, built as the pulse builds it - with `spec` the ***plain the pulse
|
|
1935
|
-
* would be given - and all it did rolled back. Not for a conformance pulse: its prompt is built from what the code holds
|
|
1936
|
-
* once it is built.
|
|
1937
|
-
*/
|
|
1938
|
-
async function promptOf(next) {
|
|
1939
|
-
if (next.planned.track !== "code")
|
|
1940
|
-
return undefined;
|
|
1941
|
-
const result = await renderSpecDiff({
|
|
1942
|
-
plainFile: next.plainFile,
|
|
1943
|
-
diff: next.planned.step.textDiff,
|
|
1944
|
-
applied: "already applied",
|
|
1945
|
-
spec: next.spec,
|
|
1946
|
-
cases: next.planned.cases,
|
|
1947
|
-
dryRun: true,
|
|
1948
|
-
});
|
|
1949
|
-
return result.task;
|
|
1950
|
-
}
|
|
1951
|
-
/** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
|
|
1952
|
-
export function isUpToDate(status) {
|
|
1953
|
-
return status.why === UP_TO_DATE && status.running === undefined && status.planned.length === 0 && status.startOver === undefined;
|
|
1954
|
-
}
|
|
1955
|
-
export function describeModules(statuses, options = {}) {
|
|
1956
|
-
if (statuses.length === 0)
|
|
1957
|
-
return "Nothing is being built.";
|
|
1958
|
-
const startOver = (status) => {
|
|
1959
|
-
if (status.startOver === undefined)
|
|
1960
|
-
return [];
|
|
1961
|
-
const { requires, codebases } = status.startOver;
|
|
1962
|
-
if (status.startOver.old === true) {
|
|
1963
|
-
return options.for === "command line"
|
|
1964
|
-
? [` turri regenerate ${basename(status.plainFile)} --start-over regenerates it from scratch, with its whole chain`]
|
|
1965
|
-
: [
|
|
1966
|
-
` Ask the user whether to regenerate ${status.module} from scratch, with its whole chain, and say why: ${codebases.join(", ")} ` +
|
|
1967
|
-
`${codebases.length === 1 ? "was" : "were"} built when functional specs were numbered, before they had func-ids, so nothing more ` +
|
|
1968
|
-
"can be built on it - its code and conformance tests are taken out, kept in its history, and every module of the chain " +
|
|
1969
|
-
`is built again from the bottom. Only if they agree, call regenerate with ${basename(status.plainFile)} and from_scratch: "chain".`,
|
|
1970
|
-
];
|
|
1971
|
-
}
|
|
1972
|
-
return options.for === "command line"
|
|
1973
|
-
? [` turri regenerate ${basename(status.plainFile)} --start-over starts ${codebases.join(", ")} over`]
|
|
1974
|
-
: [
|
|
1975
|
-
` Ask the user whether to start ${codebases.join(", ")} over, and say why: ${codebases.join(", ")} was built without ` +
|
|
1976
|
-
`${requires.join(", ")}, so no change to its code can bring ${requires.join(", ")} in - its code and conformance ` +
|
|
1977
|
-
"tests are taken out, kept in its history, and built again from the bottom of the chain. Only if they agree, " +
|
|
1978
|
-
`call regenerate with ${basename(status.plainFile)} and from_scratch: "module".`,
|
|
1979
|
-
];
|
|
1980
|
-
};
|
|
1981
|
-
return statuses
|
|
1982
|
-
.map((status) => {
|
|
1983
|
-
// Nothing to do there: said in a sentence, not as a status.
|
|
1984
|
-
if (isUpToDate(status))
|
|
1985
|
-
return `${status.module} is up to date: its code is built from the ***plain as it is now in ${basename(status.plainFile)}, so there is nothing to regenerate.`;
|
|
1986
|
-
const lines = [`${status.module} (${basename(status.plainFile)}${status.configModule !== undefined ? `, built with ${moduleConfigFile(status.configModule)}` : ""}):`];
|
|
1987
|
-
if (status.running !== undefined) {
|
|
1988
|
-
lines.push(` running: pulse ${status.running.jobId} - ${status.running.title}`);
|
|
1989
|
-
// Steered, not stopped or planned again: what changed went to its agent.
|
|
1990
|
-
for (const why of status.running.steered ?? [])
|
|
1991
|
-
lines.push(` ⇢ steered: ${why} - its agent was told, and it lands the ***plain as it is now there`);
|
|
1992
|
-
}
|
|
1993
|
-
for (const rename of status.renames ?? [])
|
|
1994
|
-
lines.push(` renames ${rename} once the running pulse ends - the records and the tests' labels, nothing regenerated`);
|
|
1995
|
-
status.planned.forEach((job, index) => lines.push(job.afterCode === true
|
|
1996
|
-
? ` ${index + 1}. conformance tests${job.specs !== undefined && job.specs.length > 0 ? ` of ${job.specs.join(", ")}` : ""} - planned once the code is built`
|
|
1997
|
-
: job.planning === true
|
|
1998
|
-
? ` ${index + 1}. ${job.track === "conformance" ? "conformance tests: " : ""}${job.title} - being planned into pulses`
|
|
1999
|
-
: ` ${index + 1}. ${job.track === "conformance" ? "conformance tests: " : ""}${job.title} - ${casesText(job.cases)}`));
|
|
2000
|
-
if (status.planNotes !== undefined)
|
|
2001
|
-
lines.push(" where the plan fell back:", ...status.planNotes.map((note) => ` - ${note}`));
|
|
2002
|
-
// A look ahead from the command line keeps its plan only while the process lives: the run that starts it plans again.
|
|
2003
|
-
if (status.why !== undefined)
|
|
2004
|
-
lines.push(options.for === "command line" && status.why === LOOKED_AHEAD
|
|
2005
|
-
? ` looked ahead - planned, nothing started: turri regenerate ${basename(status.plainFile)} runs it, planning it again as it starts`
|
|
2006
|
-
: ` ${status.why}`);
|
|
2007
|
-
if (status.conformanceNote !== undefined)
|
|
2008
|
-
lines.push(` ${status.conformanceNote}`);
|
|
2009
|
-
lines.push(...startOver(status));
|
|
2010
|
-
return lines.join("\n");
|
|
2011
|
-
})
|
|
2012
|
-
.join("\n");
|
|
2013
|
-
}
|
|
2014
|
-
/**
|
|
2015
|
-
* A conformance job: its tests written and run for its change - a failure judged, the test or the code fixed - then the
|
|
2016
|
-
* whole suite, the tests the module inherits with it. Passing, what the tests are written for is recorded and committed;
|
|
2017
|
-
* otherwise all of it - the code's fixes too - is undone.
|
|
2018
|
-
*/
|
|
2019
|
-
const defaultConformanceRunner = async (job, onDelta) => {
|
|
2020
|
-
const result = await renderSpecDiffConformance({
|
|
2021
|
-
plainFile: job.plainFile,
|
|
2022
|
-
diff: job.planned.step.textDiff,
|
|
2023
|
-
change: describeSpecChange(job.planned.step.changes, job.moduleName),
|
|
2024
|
-
cwd: job.cwd,
|
|
2025
|
-
applied: "already applied",
|
|
2026
|
-
spec: job.spec,
|
|
2027
|
-
cases: job.planned.cases,
|
|
2028
|
-
recorded: job.planned.step.tree,
|
|
2029
|
-
...(job.model !== undefined ? { model: job.model } : {}),
|
|
2030
|
-
onDelta,
|
|
2031
|
-
});
|
|
2032
|
-
if (result.passed) {
|
|
2033
|
-
writeTestsRecord(result.conformanceDir, job.planned.step.tree);
|
|
2034
|
-
landWork(job.buildDir, `conformance tests: ${job.planned.title}`);
|
|
2035
|
-
}
|
|
2036
|
-
return { landed: result.passed, report: describeSpecDiffConformance(result), ...(result.specGaps !== undefined ? { specGaps: result.specGaps } : {}) };
|
|
2037
|
-
};
|
|
2038
|
-
/** The functional specs a pulse covers, by case, each with the module whose spec it is: a host's to light and mark. */
|
|
2039
|
-
export function pulseCases(cases, moduleName) {
|
|
2040
|
-
const of = (specs) => specs.map((spec) => ({ module: spec.module ?? moduleName, funcId: spec.funcId }));
|
|
2041
|
-
return { add: of(cases.add), patch: of(cases.patch), again: of(cases.again), delete: of(cases.delete) };
|
|
2042
|
-
}
|
|
2043
|
-
/**
|
|
2044
|
-
* A module's first pulse when it builds one functional spec - the project set up and the smallest thing that runs: it lands on its
|
|
2045
|
-
* unit tests alone, with no review. A reviewer, and an arbiter after it, on a scaffold is time spent before anything can
|
|
2046
|
-
* be tried.
|
|
2047
|
-
*/
|
|
2048
|
-
export function skipsReview(cases) {
|
|
2049
|
-
return cases.fresh && cases.add.length <= 1 && cases.patch.length === 0 && cases.again.length === 0 && cases.delete.length === 0;
|
|
2050
|
-
}
|
|
2051
|
-
/** A job as a spec diff render, landed on its unit tests: conformance is a track of its own. */
|
|
2052
|
-
const defaultRunner = async (job, onDelta) => {
|
|
2053
|
-
const result = await renderSpecDiff({
|
|
2054
|
-
plainFile: job.plainFile,
|
|
2055
|
-
diff: job.planned.step.textDiff,
|
|
2056
|
-
cwd: job.cwd,
|
|
2057
|
-
applied: "already applied",
|
|
2058
|
-
spec: job.spec,
|
|
2059
|
-
cases: job.planned.cases,
|
|
2060
|
-
...(skipsReview(job.planned.cases) ? { unitReview: false } : {}),
|
|
2061
|
-
...(job.model !== undefined ? { model: job.model } : {}),
|
|
2062
|
-
...(job.steering !== undefined ? { steering: job.steering } : {}),
|
|
2063
|
-
onDelta,
|
|
2064
|
-
});
|
|
2065
|
-
// Landed code can be tried.
|
|
2066
|
-
return { landed: result.passed, report: describeSpecDiff(result), story: codeStory(result),
|
|
2067
|
-
...(result.specGaps !== undefined ? { specGaps: result.specGaps } : {}),
|
|
2068
|
-
};
|
|
2069
|
-
};
|
|
2070
|
-
/** How a code pulse went, for its line in the notes: the rounds it took, its test runs, what the debugger found. */
|
|
2071
|
-
export function codeStory(result) {
|
|
2072
|
-
if (result.restructured === true)
|
|
2073
|
-
return "only restructured, nothing regenerated";
|
|
2074
|
-
const attempts = result.attempts ?? 0;
|
|
2075
|
-
const runs = result.runs?.length ?? 0;
|
|
2076
|
-
const rounds = `${attempts} round${attempts === 1 ? "" : "s"} of the unit tests, ${runs} test run${runs === 1 ? "" : "s"}`;
|
|
2077
|
-
const found = (result.diagnosed ?? []).map((cause) => `the debugger: ${cause}`);
|
|
2078
|
-
return [rounds, ...found].join("; ");
|
|
2079
|
-
}
|